Context
stringlengths
285
157k
file_name
stringlengths
21
79
start
int64
14
3.67k
end
int64
18
3.69k
theorem
stringlengths
25
2.71k
proof
stringlengths
5
10.6k
/- Copyright (c) 2020 Aaron Anderson, Jalex Stark, Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Jalex Stark, Kyle Miller, Alena Gusakov -/ import Mathlib.Algebra.Order.Ring.Defs import Mathlib.Combinatorics.SimpleGraph.Basic import Mathlib.Data.Sym.Card /-! # Definitions for finite and locally finite graphs This file defines finite versions of `edgeSet`, `neighborSet` and `incidenceSet` and proves some of their basic properties. It also defines the notion of a locally finite graph, which is one whose vertices have finite degree. The design for finiteness is that each definition takes the smallest finiteness assumption necessary. For example, `SimpleGraph.neighborFinset v` only requires that `v` have finitely many neighbors. ## Main definitions * `SimpleGraph.edgeFinset` is the `Finset` of edges in a graph, if `edgeSet` is finite * `SimpleGraph.neighborFinset` is the `Finset` of vertices adjacent to a given vertex, if `neighborSet` is finite * `SimpleGraph.incidenceFinset` is the `Finset` of edges containing a given vertex, if `incidenceSet` is finite ## Naming conventions If the vertex type of a graph is finite, we refer to its cardinality as `CardVerts` or `card_verts`. ## Implementation notes * A locally finite graph is one with instances `Π v, Fintype (G.neighborSet v)`. * Given instances `DecidableRel G.Adj` and `Fintype V`, then the graph is locally finite, too. -/ open Finset Function namespace SimpleGraph variable {V : Type*} (G : SimpleGraph V) {e : Sym2 V} section EdgeFinset variable {G₁ G₂ : SimpleGraph V} [Fintype G.edgeSet] [Fintype G₁.edgeSet] [Fintype G₂.edgeSet] /-- The `edgeSet` of the graph as a `Finset`. -/ abbrev edgeFinset : Finset (Sym2 V) := Set.toFinset G.edgeSet #align simple_graph.edge_finset SimpleGraph.edgeFinset @[norm_cast] theorem coe_edgeFinset : (G.edgeFinset : Set (Sym2 V)) = G.edgeSet := Set.coe_toFinset _ #align simple_graph.coe_edge_finset SimpleGraph.coe_edgeFinset variable {G} theorem mem_edgeFinset : e ∈ G.edgeFinset ↔ e ∈ G.edgeSet := Set.mem_toFinset #align simple_graph.mem_edge_finset SimpleGraph.mem_edgeFinset theorem not_isDiag_of_mem_edgeFinset : e ∈ G.edgeFinset → ¬e.IsDiag := not_isDiag_of_mem_edgeSet _ ∘ mem_edgeFinset.1 #align simple_graph.not_is_diag_of_mem_edge_finset SimpleGraph.not_isDiag_of_mem_edgeFinset theorem edgeFinset_inj : G₁.edgeFinset = G₂.edgeFinset ↔ G₁ = G₂ := by simp #align simple_graph.edge_finset_inj SimpleGraph.edgeFinset_inj theorem edgeFinset_subset_edgeFinset : G₁.edgeFinset ⊆ G₂.edgeFinset ↔ G₁ ≤ G₂ := by simp #align simple_graph.edge_finset_subset_edge_finset SimpleGraph.edgeFinset_subset_edgeFinset theorem edgeFinset_ssubset_edgeFinset : G₁.edgeFinset ⊂ G₂.edgeFinset ↔ G₁ < G₂ := by simp #align simple_graph.edge_finset_ssubset_edge_finset SimpleGraph.edgeFinset_ssubset_edgeFinset @[gcongr] alias ⟨_, edgeFinset_mono⟩ := edgeFinset_subset_edgeFinset #align simple_graph.edge_finset_mono SimpleGraph.edgeFinset_mono alias ⟨_, edgeFinset_strict_mono⟩ := edgeFinset_ssubset_edgeFinset #align simple_graph.edge_finset_strict_mono SimpleGraph.edgeFinset_strict_mono attribute [mono] edgeFinset_mono edgeFinset_strict_mono @[simp] theorem edgeFinset_bot : (⊥ : SimpleGraph V).edgeFinset = ∅ := by simp [edgeFinset] #align simple_graph.edge_finset_bot SimpleGraph.edgeFinset_bot @[simp] theorem edgeFinset_sup [Fintype (edgeSet (G₁ ⊔ G₂))] [DecidableEq V] : (G₁ ⊔ G₂).edgeFinset = G₁.edgeFinset ∪ G₂.edgeFinset := by simp [edgeFinset] #align simple_graph.edge_finset_sup SimpleGraph.edgeFinset_sup @[simp] theorem edgeFinset_inf [DecidableEq V] : (G₁ ⊓ G₂).edgeFinset = G₁.edgeFinset ∩ G₂.edgeFinset := by simp [edgeFinset] #align simple_graph.edge_finset_inf SimpleGraph.edgeFinset_inf @[simp] theorem edgeFinset_sdiff [DecidableEq V] : (G₁ \ G₂).edgeFinset = G₁.edgeFinset \ G₂.edgeFinset := by simp [edgeFinset] #align simple_graph.edge_finset_sdiff SimpleGraph.edgeFinset_sdiff theorem edgeFinset_card : G.edgeFinset.card = Fintype.card G.edgeSet := Set.toFinset_card _ #align simple_graph.edge_finset_card SimpleGraph.edgeFinset_card @[simp] theorem edgeSet_univ_card : (univ : Finset G.edgeSet).card = G.edgeFinset.card := Fintype.card_of_subtype G.edgeFinset fun _ => mem_edgeFinset #align simple_graph.edge_set_univ_card SimpleGraph.edgeSet_univ_card variable [Fintype V] @[simp] theorem edgeFinset_top [DecidableEq V] : (⊤ : SimpleGraph V).edgeFinset = univ.filter fun e => ¬e.IsDiag := by rw [← coe_inj]; simp /-- The complete graph on `n` vertices has `n.choose 2` edges. -/ theorem card_edgeFinset_top_eq_card_choose_two [DecidableEq V] : (⊤ : SimpleGraph V).edgeFinset.card = (Fintype.card V).choose 2 := by simp_rw [Set.toFinset_card, edgeSet_top, Set.coe_setOf, ← Sym2.card_subtype_not_diag] /-- Any graph on `n` vertices has at most `n.choose 2` edges. -/ theorem card_edgeFinset_le_card_choose_two : G.edgeFinset.card ≤ (Fintype.card V).choose 2 := by classical rw [← card_edgeFinset_top_eq_card_choose_two] exact card_le_card (edgeFinset_mono le_top) end EdgeFinset theorem edgeFinset_deleteEdges [DecidableEq V] [Fintype G.edgeSet] (s : Finset (Sym2 V)) [Fintype (G.deleteEdges s).edgeSet] : (G.deleteEdges s).edgeFinset = G.edgeFinset \ s := by ext e simp [edgeSet_deleteEdges] #align simple_graph.edge_finset_delete_edges SimpleGraph.edgeFinset_deleteEdges section DeleteFar -- Porting note: added `Fintype (Sym2 V)` argument. variable {𝕜 : Type*} [OrderedRing 𝕜] [Fintype V] [Fintype (Sym2 V)] [Fintype G.edgeSet] {p : SimpleGraph V → Prop} {r r₁ r₂ : 𝕜} /-- A graph is `r`-*delete-far* from a property `p` if we must delete at least `r` edges from it to get a graph with the property `p`. -/ def DeleteFar (p : SimpleGraph V → Prop) (r : 𝕜) : Prop := ∀ ⦃s⦄, s ⊆ G.edgeFinset → p (G.deleteEdges s) → r ≤ s.card #align simple_graph.delete_far SimpleGraph.DeleteFar variable {G} theorem deleteFar_iff : G.DeleteFar p r ↔ ∀ ⦃H : SimpleGraph _⦄ [DecidableRel H.Adj], H ≤ G → p H → r ≤ G.edgeFinset.card - H.edgeFinset.card := by classical refine ⟨fun h H _ hHG hH ↦ ?_, fun h s hs hG ↦ ?_⟩ · have := h (sdiff_subset (t := H.edgeFinset)) simp only [deleteEdges_sdiff_eq_of_le hHG, edgeFinset_mono hHG, card_sdiff, card_le_card, coe_sdiff, coe_edgeFinset, Nat.cast_sub] at this exact this hH · classical simpa [card_sdiff hs, edgeFinset_deleteEdges, -Set.toFinset_card, Nat.cast_sub, card_le_card hs] using h (G.deleteEdges_le s) hG #align simple_graph.delete_far_iff SimpleGraph.deleteFar_iff alias ⟨DeleteFar.le_card_sub_card, _⟩ := deleteFar_iff #align simple_graph.delete_far.le_card_sub_card SimpleGraph.DeleteFar.le_card_sub_card theorem DeleteFar.mono (h : G.DeleteFar p r₂) (hr : r₁ ≤ r₂) : G.DeleteFar p r₁ := fun _ hs hG => hr.trans <| h hs hG #align simple_graph.delete_far.mono SimpleGraph.DeleteFar.mono end DeleteFar section FiniteAt /-! ## Finiteness at a vertex This section contains definitions and lemmas concerning vertices that have finitely many adjacent vertices. We denote this condition by `Fintype (G.neighborSet v)`. We define `G.neighborFinset v` to be the `Finset` version of `G.neighborSet v`. Use `neighborFinset_eq_filter` to rewrite this definition as a `Finset.filter` expression. -/ variable (v) [Fintype (G.neighborSet v)] /-- `G.neighbors v` is the `Finset` version of `G.Adj v` in case `G` is locally finite at `v`. -/ def neighborFinset : Finset V := (G.neighborSet v).toFinset #align simple_graph.neighbor_finset SimpleGraph.neighborFinset theorem neighborFinset_def : G.neighborFinset v = (G.neighborSet v).toFinset := rfl #align simple_graph.neighbor_finset_def SimpleGraph.neighborFinset_def @[simp] theorem mem_neighborFinset (w : V) : w ∈ G.neighborFinset v ↔ G.Adj v w := Set.mem_toFinset #align simple_graph.mem_neighbor_finset SimpleGraph.mem_neighborFinset theorem not_mem_neighborFinset_self : v ∉ G.neighborFinset v := by simp #align simple_graph.not_mem_neighbor_finset_self SimpleGraph.not_mem_neighborFinset_self theorem neighborFinset_disjoint_singleton : Disjoint (G.neighborFinset v) {v} := Finset.disjoint_singleton_right.mpr <| not_mem_neighborFinset_self _ _ #align simple_graph.neighbor_finset_disjoint_singleton SimpleGraph.neighborFinset_disjoint_singleton theorem singleton_disjoint_neighborFinset : Disjoint {v} (G.neighborFinset v) := Finset.disjoint_singleton_left.mpr <| not_mem_neighborFinset_self _ _ #align simple_graph.singleton_disjoint_neighbor_finset SimpleGraph.singleton_disjoint_neighborFinset /-- `G.degree v` is the number of vertices adjacent to `v`. -/ def degree : ℕ := (G.neighborFinset v).card #align simple_graph.degree SimpleGraph.degree -- Porting note: in Lean 3 we could do `simp [← degree]`, but that gives -- "invalid '←' modifier, 'SimpleGraph.degree' is a declaration name to be unfolded". -- In any case, having this lemma is good since there's no guarantee we won't still change -- the definition of `degree`. @[simp] theorem card_neighborFinset_eq_degree : (G.neighborFinset v).card = G.degree v := rfl @[simp] theorem card_neighborSet_eq_degree : Fintype.card (G.neighborSet v) = G.degree v := (Set.toFinset_card _).symm #align simple_graph.card_neighbor_set_eq_degree SimpleGraph.card_neighborSet_eq_degree theorem degree_pos_iff_exists_adj : 0 < G.degree v ↔ ∃ w, G.Adj v w := by simp only [degree, card_pos, Finset.Nonempty, mem_neighborFinset] #align simple_graph.degree_pos_iff_exists_adj SimpleGraph.degree_pos_iff_exists_adj theorem degree_compl [Fintype (Gᶜ.neighborSet v)] [Fintype V] : Gᶜ.degree v = Fintype.card V - 1 - G.degree v := by classical rw [← card_neighborSet_union_compl_neighborSet G v, Set.toFinset_union] simp [card_union_of_disjoint (Set.disjoint_toFinset.mpr (compl_neighborSet_disjoint G v))] #align simple_graph.degree_compl SimpleGraph.degree_compl instance incidenceSetFintype [DecidableEq V] : Fintype (G.incidenceSet v) := Fintype.ofEquiv (G.neighborSet v) (G.incidenceSetEquivNeighborSet v).symm #align simple_graph.incidence_set_fintype SimpleGraph.incidenceSetFintype /-- This is the `Finset` version of `incidenceSet`. -/ def incidenceFinset [DecidableEq V] : Finset (Sym2 V) := (G.incidenceSet v).toFinset #align simple_graph.incidence_finset SimpleGraph.incidenceFinset @[simp] theorem card_incidenceSet_eq_degree [DecidableEq V] : Fintype.card (G.incidenceSet v) = G.degree v := by rw [Fintype.card_congr (G.incidenceSetEquivNeighborSet v)] simp #align simple_graph.card_incidence_set_eq_degree SimpleGraph.card_incidenceSet_eq_degree @[simp] theorem card_incidenceFinset_eq_degree [DecidableEq V] : (G.incidenceFinset v).card = G.degree v := by rw [← G.card_incidenceSet_eq_degree] apply Set.toFinset_card #align simple_graph.card_incidence_finset_eq_degree SimpleGraph.card_incidenceFinset_eq_degree @[simp] theorem mem_incidenceFinset [DecidableEq V] (e : Sym2 V) : e ∈ G.incidenceFinset v ↔ e ∈ G.incidenceSet v := Set.mem_toFinset #align simple_graph.mem_incidence_finset SimpleGraph.mem_incidenceFinset theorem incidenceFinset_eq_filter [DecidableEq V] [Fintype G.edgeSet] : G.incidenceFinset v = G.edgeFinset.filter (Membership.mem v) := by ext e refine Sym2.ind (fun x y => ?_) e simp [mk'_mem_incidenceSet_iff] #align simple_graph.incidence_finset_eq_filter SimpleGraph.incidenceFinset_eq_filter end FiniteAt section LocallyFinite /-- A graph is locally finite if every vertex has a finite neighbor set. -/ abbrev LocallyFinite := ∀ v : V, Fintype (G.neighborSet v) #align simple_graph.locally_finite SimpleGraph.LocallyFinite variable [LocallyFinite G] /-- A locally finite simple graph is regular of degree `d` if every vertex has degree `d`. -/ def IsRegularOfDegree (d : ℕ) : Prop := ∀ v : V, G.degree v = d #align simple_graph.is_regular_of_degree SimpleGraph.IsRegularOfDegree variable {G} theorem IsRegularOfDegree.degree_eq {d : ℕ} (h : G.IsRegularOfDegree d) (v : V) : G.degree v = d := h v #align simple_graph.is_regular_of_degree.degree_eq SimpleGraph.IsRegularOfDegree.degree_eq theorem IsRegularOfDegree.compl [Fintype V] [DecidableEq V] {G : SimpleGraph V} [DecidableRel G.Adj] {k : ℕ} (h : G.IsRegularOfDegree k) : Gᶜ.IsRegularOfDegree (Fintype.card V - 1 - k) := by intro v rw [degree_compl, h v] #align simple_graph.is_regular_of_degree.compl SimpleGraph.IsRegularOfDegree.compl end LocallyFinite section Finite variable [Fintype V] instance neighborSetFintype [DecidableRel G.Adj] (v : V) : Fintype (G.neighborSet v) := @Subtype.fintype _ _ (by simp_rw [mem_neighborSet] infer_instance) _ #align simple_graph.neighbor_set_fintype SimpleGraph.neighborSetFintype theorem neighborFinset_eq_filter {v : V} [DecidableRel G.Adj] : G.neighborFinset v = Finset.univ.filter (G.Adj v) := by ext simp #align simple_graph.neighbor_finset_eq_filter SimpleGraph.neighborFinset_eq_filter theorem neighborFinset_compl [DecidableEq V] [DecidableRel G.Adj] (v : V) : Gᶜ.neighborFinset v = (G.neighborFinset v)ᶜ \ {v} := by simp only [neighborFinset, neighborSet_compl, Set.toFinset_diff, Set.toFinset_compl, Set.toFinset_singleton] #align simple_graph.neighbor_finset_compl SimpleGraph.neighborFinset_compl @[simp] theorem complete_graph_degree [DecidableEq V] (v : V) : (⊤ : SimpleGraph V).degree v = Fintype.card V - 1 := by erw [degree, neighborFinset_eq_filter, filter_ne, card_erase_of_mem (mem_univ v), card_univ] #align simple_graph.complete_graph_degree SimpleGraph.complete_graph_degree theorem bot_degree (v : V) : (⊥ : SimpleGraph V).degree v = 0 := by erw [degree, neighborFinset_eq_filter, filter_False] exact Finset.card_empty #align simple_graph.bot_degree SimpleGraph.bot_degree theorem IsRegularOfDegree.top [DecidableEq V] : (⊤ : SimpleGraph V).IsRegularOfDegree (Fintype.card V - 1) := by intro v simp #align simple_graph.is_regular_of_degree.top SimpleGraph.IsRegularOfDegree.top /-- The minimum degree of all vertices (and `0` if there are no vertices). The key properties of this are given in `exists_minimal_degree_vertex`, `minDegree_le_degree` and `le_minDegree_of_forall_le_degree`. -/ def minDegree [DecidableRel G.Adj] : ℕ := WithTop.untop' 0 (univ.image fun v => G.degree v).min #align simple_graph.min_degree SimpleGraph.minDegree /-- There exists a vertex of minimal degree. Note the assumption of being nonempty is necessary, as the lemma implies there exists a vertex. -/ theorem exists_minimal_degree_vertex [DecidableRel G.Adj] [Nonempty V] : ∃ v, G.minDegree = G.degree v := by obtain ⟨t, ht : _ = _⟩ := min_of_nonempty (univ_nonempty.image fun v => G.degree v) obtain ⟨v, _, rfl⟩ := mem_image.mp (mem_of_min ht) exact ⟨v, by simp [minDegree, ht]⟩ #align simple_graph.exists_minimal_degree_vertex SimpleGraph.exists_minimal_degree_vertex /-- The minimum degree in the graph is at most the degree of any particular vertex. -/
Mathlib/Combinatorics/SimpleGraph/Finite.lean
374
377
theorem minDegree_le_degree [DecidableRel G.Adj] (v : V) : G.minDegree ≤ G.degree v := by
obtain ⟨t, ht⟩ := Finset.min_of_mem (mem_image_of_mem (fun v => G.degree v) (mem_univ v)) have := Finset.min_le_of_eq (mem_image_of_mem _ (mem_univ v)) ht rwa [minDegree, ht]
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Andrew Zipperer, Haitao Zhang, Minchao Wu, Yury Kudryashov -/ import Mathlib.Data.Set.Prod import Mathlib.Logic.Function.Conjugate #align_import data.set.function from "leanprover-community/mathlib"@"996b0ff959da753a555053a480f36e5f264d4207" /-! # Functions over sets ## Main definitions ### Predicate * `Set.EqOn f₁ f₂ s` : functions `f₁` and `f₂` are equal at every point of `s`; * `Set.MapsTo f s t` : `f` sends every point of `s` to a point of `t`; * `Set.InjOn f s` : restriction of `f` to `s` is injective; * `Set.SurjOn f s t` : every point in `s` has a preimage in `s`; * `Set.BijOn f s t` : `f` is a bijection between `s` and `t`; * `Set.LeftInvOn f' f s` : for every `x ∈ s` we have `f' (f x) = x`; * `Set.RightInvOn f' f t` : for every `y ∈ t` we have `f (f' y) = y`; * `Set.InvOn f' f s t` : `f'` is a two-side inverse of `f` on `s` and `t`, i.e. we have `Set.LeftInvOn f' f s` and `Set.RightInvOn f' f t`. ### Functions * `Set.restrict f s` : restrict the domain of `f` to the set `s`; * `Set.codRestrict f s h` : given `h : ∀ x, f x ∈ s`, restrict the codomain of `f` to the set `s`; * `Set.MapsTo.restrict f s t h`: given `h : MapsTo f s t`, restrict the domain of `f` to `s` and the codomain to `t`. -/ variable {α β γ : Type*} {ι : Sort*} {π : α → Type*} open Equiv Equiv.Perm Function namespace Set /-! ### Restrict -/ section restrict /-- Restrict domain of a function `f` to a set `s`. Same as `Subtype.restrict` but this version takes an argument `↥s` instead of `Subtype s`. -/ def restrict (s : Set α) (f : ∀ a : α, π a) : ∀ a : s, π a := fun x => f x #align set.restrict Set.restrict theorem restrict_eq (f : α → β) (s : Set α) : s.restrict f = f ∘ Subtype.val := rfl #align set.restrict_eq Set.restrict_eq @[simp] theorem restrict_apply (f : α → β) (s : Set α) (x : s) : s.restrict f x = f x := rfl #align set.restrict_apply Set.restrict_apply theorem restrict_eq_iff {f : ∀ a, π a} {s : Set α} {g : ∀ a : s, π a} : restrict s f = g ↔ ∀ (a) (ha : a ∈ s), f a = g ⟨a, ha⟩ := funext_iff.trans Subtype.forall #align set.restrict_eq_iff Set.restrict_eq_iff theorem eq_restrict_iff {s : Set α} {f : ∀ a : s, π a} {g : ∀ a, π a} : f = restrict s g ↔ ∀ (a) (ha : a ∈ s), f ⟨a, ha⟩ = g a := funext_iff.trans Subtype.forall #align set.eq_restrict_iff Set.eq_restrict_iff @[simp] theorem range_restrict (f : α → β) (s : Set α) : Set.range (s.restrict f) = f '' s := (range_comp _ _).trans <| congr_arg (f '' ·) Subtype.range_coe #align set.range_restrict Set.range_restrict theorem image_restrict (f : α → β) (s t : Set α) : s.restrict f '' (Subtype.val ⁻¹' t) = f '' (t ∩ s) := by rw [restrict_eq, image_comp, image_preimage_eq_inter_range, Subtype.range_coe] #align set.image_restrict Set.image_restrict @[simp] theorem restrict_dite {s : Set α} [∀ x, Decidable (x ∈ s)] (f : ∀ a ∈ s, β) (g : ∀ a ∉ s, β) : (s.restrict fun a => if h : a ∈ s then f a h else g a h) = (fun a : s => f a a.2) := funext fun a => dif_pos a.2 #align set.restrict_dite Set.restrict_dite @[simp] theorem restrict_dite_compl {s : Set α} [∀ x, Decidable (x ∈ s)] (f : ∀ a ∈ s, β) (g : ∀ a ∉ s, β) : (sᶜ.restrict fun a => if h : a ∈ s then f a h else g a h) = (fun a : (sᶜ : Set α) => g a a.2) := funext fun a => dif_neg a.2 #align set.restrict_dite_compl Set.restrict_dite_compl @[simp] theorem restrict_ite (f g : α → β) (s : Set α) [∀ x, Decidable (x ∈ s)] : (s.restrict fun a => if a ∈ s then f a else g a) = s.restrict f := restrict_dite _ _ #align set.restrict_ite Set.restrict_ite @[simp] theorem restrict_ite_compl (f g : α → β) (s : Set α) [∀ x, Decidable (x ∈ s)] : (sᶜ.restrict fun a => if a ∈ s then f a else g a) = sᶜ.restrict g := restrict_dite_compl _ _ #align set.restrict_ite_compl Set.restrict_ite_compl @[simp] theorem restrict_piecewise (f g : α → β) (s : Set α) [∀ x, Decidable (x ∈ s)] : s.restrict (piecewise s f g) = s.restrict f := restrict_ite _ _ _ #align set.restrict_piecewise Set.restrict_piecewise @[simp] theorem restrict_piecewise_compl (f g : α → β) (s : Set α) [∀ x, Decidable (x ∈ s)] : sᶜ.restrict (piecewise s f g) = sᶜ.restrict g := restrict_ite_compl _ _ _ #align set.restrict_piecewise_compl Set.restrict_piecewise_compl theorem restrict_extend_range (f : α → β) (g : α → γ) (g' : β → γ) : (range f).restrict (extend f g g') = fun x => g x.coe_prop.choose := by classical exact restrict_dite _ _ #align set.restrict_extend_range Set.restrict_extend_range @[simp] theorem restrict_extend_compl_range (f : α → β) (g : α → γ) (g' : β → γ) : (range f)ᶜ.restrict (extend f g g') = g' ∘ Subtype.val := by classical exact restrict_dite_compl _ _ #align set.restrict_extend_compl_range Set.restrict_extend_compl_range theorem range_extend_subset (f : α → β) (g : α → γ) (g' : β → γ) : range (extend f g g') ⊆ range g ∪ g' '' (range f)ᶜ := by classical rintro _ ⟨y, rfl⟩ rw [extend_def] split_ifs with h exacts [Or.inl (mem_range_self _), Or.inr (mem_image_of_mem _ h)] #align set.range_extend_subset Set.range_extend_subset theorem range_extend {f : α → β} (hf : Injective f) (g : α → γ) (g' : β → γ) : range (extend f g g') = range g ∪ g' '' (range f)ᶜ := by refine (range_extend_subset _ _ _).antisymm ?_ rintro z (⟨x, rfl⟩ | ⟨y, hy, rfl⟩) exacts [⟨f x, hf.extend_apply _ _ _⟩, ⟨y, extend_apply' _ _ _ hy⟩] #align set.range_extend Set.range_extend /-- Restrict codomain of a function `f` to a set `s`. Same as `Subtype.coind` but this version has codomain `↥s` instead of `Subtype s`. -/ def codRestrict (f : ι → α) (s : Set α) (h : ∀ x, f x ∈ s) : ι → s := fun x => ⟨f x, h x⟩ #align set.cod_restrict Set.codRestrict @[simp] theorem val_codRestrict_apply (f : ι → α) (s : Set α) (h : ∀ x, f x ∈ s) (x : ι) : (codRestrict f s h x : α) = f x := rfl #align set.coe_cod_restrict_apply Set.val_codRestrict_apply @[simp] theorem restrict_comp_codRestrict {f : ι → α} {g : α → β} {b : Set α} (h : ∀ x, f x ∈ b) : b.restrict g ∘ b.codRestrict f h = g ∘ f := rfl #align set.restrict_comp_cod_restrict Set.restrict_comp_codRestrict @[simp] theorem injective_codRestrict {f : ι → α} {s : Set α} (h : ∀ x, f x ∈ s) : Injective (codRestrict f s h) ↔ Injective f := by simp only [Injective, Subtype.ext_iff, val_codRestrict_apply] #align set.injective_cod_restrict Set.injective_codRestrict alias ⟨_, _root_.Function.Injective.codRestrict⟩ := injective_codRestrict #align function.injective.cod_restrict Function.Injective.codRestrict end restrict /-! ### Equality on a set -/ section equality variable {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {p : Set γ} {f f₁ f₂ f₃ : α → β} {g g₁ g₂ : β → γ} {f' f₁' f₂' : β → α} {g' : γ → β} {a : α} {b : β} @[simp] theorem eqOn_empty (f₁ f₂ : α → β) : EqOn f₁ f₂ ∅ := fun _ => False.elim #align set.eq_on_empty Set.eqOn_empty @[simp] theorem eqOn_singleton : Set.EqOn f₁ f₂ {a} ↔ f₁ a = f₂ a := by simp [Set.EqOn] #align set.eq_on_singleton Set.eqOn_singleton @[simp] theorem eqOn_univ (f₁ f₂ : α → β) : EqOn f₁ f₂ univ ↔ f₁ = f₂ := by simp [EqOn, funext_iff] @[simp] theorem restrict_eq_restrict_iff : restrict s f₁ = restrict s f₂ ↔ EqOn f₁ f₂ s := restrict_eq_iff #align set.restrict_eq_restrict_iff Set.restrict_eq_restrict_iff @[symm] theorem EqOn.symm (h : EqOn f₁ f₂ s) : EqOn f₂ f₁ s := fun _ hx => (h hx).symm #align set.eq_on.symm Set.EqOn.symm theorem eqOn_comm : EqOn f₁ f₂ s ↔ EqOn f₂ f₁ s := ⟨EqOn.symm, EqOn.symm⟩ #align set.eq_on_comm Set.eqOn_comm -- This can not be tagged as `@[refl]` with the current argument order. -- See note below at `EqOn.trans`. theorem eqOn_refl (f : α → β) (s : Set α) : EqOn f f s := fun _ _ => rfl #align set.eq_on_refl Set.eqOn_refl -- Note: this was formerly tagged with `@[trans]`, and although the `trans` attribute accepted it -- the `trans` tactic could not use it. -- An update to the trans tactic coming in mathlib4#7014 will reject this attribute. -- It can be restored by changing the argument order from `EqOn f₁ f₂ s` to `EqOn s f₁ f₂`. -- This change will be made separately: [zulip](https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Reordering.20arguments.20of.20.60Set.2EEqOn.60/near/390467581). theorem EqOn.trans (h₁ : EqOn f₁ f₂ s) (h₂ : EqOn f₂ f₃ s) : EqOn f₁ f₃ s := fun _ hx => (h₁ hx).trans (h₂ hx) #align set.eq_on.trans Set.EqOn.trans theorem EqOn.image_eq (heq : EqOn f₁ f₂ s) : f₁ '' s = f₂ '' s := image_congr heq #align set.eq_on.image_eq Set.EqOn.image_eq /-- Variant of `EqOn.image_eq`, for one function being the identity. -/ theorem EqOn.image_eq_self {f : α → α} (h : Set.EqOn f id s) : f '' s = s := by rw [h.image_eq, image_id] theorem EqOn.inter_preimage_eq (heq : EqOn f₁ f₂ s) (t : Set β) : s ∩ f₁ ⁻¹' t = s ∩ f₂ ⁻¹' t := ext fun x => and_congr_right_iff.2 fun hx => by rw [mem_preimage, mem_preimage, heq hx] #align set.eq_on.inter_preimage_eq Set.EqOn.inter_preimage_eq theorem EqOn.mono (hs : s₁ ⊆ s₂) (hf : EqOn f₁ f₂ s₂) : EqOn f₁ f₂ s₁ := fun _ hx => hf (hs hx) #align set.eq_on.mono Set.EqOn.mono @[simp] theorem eqOn_union : EqOn f₁ f₂ (s₁ ∪ s₂) ↔ EqOn f₁ f₂ s₁ ∧ EqOn f₁ f₂ s₂ := forall₂_or_left #align set.eq_on_union Set.eqOn_union theorem EqOn.union (h₁ : EqOn f₁ f₂ s₁) (h₂ : EqOn f₁ f₂ s₂) : EqOn f₁ f₂ (s₁ ∪ s₂) := eqOn_union.2 ⟨h₁, h₂⟩ #align set.eq_on.union Set.EqOn.union theorem EqOn.comp_left (h : s.EqOn f₁ f₂) : s.EqOn (g ∘ f₁) (g ∘ f₂) := fun _ ha => congr_arg _ <| h ha #align set.eq_on.comp_left Set.EqOn.comp_left @[simp] theorem eqOn_range {ι : Sort*} {f : ι → α} {g₁ g₂ : α → β} : EqOn g₁ g₂ (range f) ↔ g₁ ∘ f = g₂ ∘ f := forall_mem_range.trans <| funext_iff.symm #align set.eq_on_range Set.eqOn_range alias ⟨EqOn.comp_eq, _⟩ := eqOn_range #align set.eq_on.comp_eq Set.EqOn.comp_eq end equality /-! ### Congruence lemmas for monotonicity and antitonicity -/ section Order variable {s : Set α} {f₁ f₂ : α → β} [Preorder α] [Preorder β] theorem _root_.MonotoneOn.congr (h₁ : MonotoneOn f₁ s) (h : s.EqOn f₁ f₂) : MonotoneOn f₂ s := by intro a ha b hb hab rw [← h ha, ← h hb] exact h₁ ha hb hab #align monotone_on.congr MonotoneOn.congr theorem _root_.AntitoneOn.congr (h₁ : AntitoneOn f₁ s) (h : s.EqOn f₁ f₂) : AntitoneOn f₂ s := h₁.dual_right.congr h #align antitone_on.congr AntitoneOn.congr theorem _root_.StrictMonoOn.congr (h₁ : StrictMonoOn f₁ s) (h : s.EqOn f₁ f₂) : StrictMonoOn f₂ s := by intro a ha b hb hab rw [← h ha, ← h hb] exact h₁ ha hb hab #align strict_mono_on.congr StrictMonoOn.congr theorem _root_.StrictAntiOn.congr (h₁ : StrictAntiOn f₁ s) (h : s.EqOn f₁ f₂) : StrictAntiOn f₂ s := h₁.dual_right.congr h #align strict_anti_on.congr StrictAntiOn.congr theorem EqOn.congr_monotoneOn (h : s.EqOn f₁ f₂) : MonotoneOn f₁ s ↔ MonotoneOn f₂ s := ⟨fun h₁ => h₁.congr h, fun h₂ => h₂.congr h.symm⟩ #align set.eq_on.congr_monotone_on Set.EqOn.congr_monotoneOn theorem EqOn.congr_antitoneOn (h : s.EqOn f₁ f₂) : AntitoneOn f₁ s ↔ AntitoneOn f₂ s := ⟨fun h₁ => h₁.congr h, fun h₂ => h₂.congr h.symm⟩ #align set.eq_on.congr_antitone_on Set.EqOn.congr_antitoneOn theorem EqOn.congr_strictMonoOn (h : s.EqOn f₁ f₂) : StrictMonoOn f₁ s ↔ StrictMonoOn f₂ s := ⟨fun h₁ => h₁.congr h, fun h₂ => h₂.congr h.symm⟩ #align set.eq_on.congr_strict_mono_on Set.EqOn.congr_strictMonoOn theorem EqOn.congr_strictAntiOn (h : s.EqOn f₁ f₂) : StrictAntiOn f₁ s ↔ StrictAntiOn f₂ s := ⟨fun h₁ => h₁.congr h, fun h₂ => h₂.congr h.symm⟩ #align set.eq_on.congr_strict_anti_on Set.EqOn.congr_strictAntiOn end Order /-! ### Monotonicity lemmas-/ section Mono variable {s s₁ s₂ : Set α} {f f₁ f₂ : α → β} [Preorder α] [Preorder β] theorem _root_.MonotoneOn.mono (h : MonotoneOn f s) (h' : s₂ ⊆ s) : MonotoneOn f s₂ := fun _ hx _ hy => h (h' hx) (h' hy) #align monotone_on.mono MonotoneOn.mono theorem _root_.AntitoneOn.mono (h : AntitoneOn f s) (h' : s₂ ⊆ s) : AntitoneOn f s₂ := fun _ hx _ hy => h (h' hx) (h' hy) #align antitone_on.mono AntitoneOn.mono theorem _root_.StrictMonoOn.mono (h : StrictMonoOn f s) (h' : s₂ ⊆ s) : StrictMonoOn f s₂ := fun _ hx _ hy => h (h' hx) (h' hy) #align strict_mono_on.mono StrictMonoOn.mono theorem _root_.StrictAntiOn.mono (h : StrictAntiOn f s) (h' : s₂ ⊆ s) : StrictAntiOn f s₂ := fun _ hx _ hy => h (h' hx) (h' hy) #align strict_anti_on.mono StrictAntiOn.mono protected theorem _root_.MonotoneOn.monotone (h : MonotoneOn f s) : Monotone (f ∘ Subtype.val : s → β) := fun x y hle => h x.coe_prop y.coe_prop hle #align monotone_on.monotone MonotoneOn.monotone protected theorem _root_.AntitoneOn.monotone (h : AntitoneOn f s) : Antitone (f ∘ Subtype.val : s → β) := fun x y hle => h x.coe_prop y.coe_prop hle #align antitone_on.monotone AntitoneOn.monotone protected theorem _root_.StrictMonoOn.strictMono (h : StrictMonoOn f s) : StrictMono (f ∘ Subtype.val : s → β) := fun x y hlt => h x.coe_prop y.coe_prop hlt #align strict_mono_on.strict_mono StrictMonoOn.strictMono protected theorem _root_.StrictAntiOn.strictAnti (h : StrictAntiOn f s) : StrictAnti (f ∘ Subtype.val : s → β) := fun x y hlt => h x.coe_prop y.coe_prop hlt #align strict_anti_on.strict_anti StrictAntiOn.strictAnti end Mono variable {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {p : Set γ} {f f₁ f₂ f₃ : α → β} {g g₁ g₂ : β → γ} {f' f₁' f₂' : β → α} {g' : γ → β} {a : α} {b : β} section MapsTo theorem MapsTo.restrict_commutes (f : α → β) (s : Set α) (t : Set β) (h : MapsTo f s t) : Subtype.val ∘ h.restrict f s t = f ∘ Subtype.val := rfl @[simp] theorem MapsTo.val_restrict_apply (h : MapsTo f s t) (x : s) : (h.restrict f s t x : β) = f x := rfl #align set.maps_to.coe_restrict_apply Set.MapsTo.val_restrict_apply theorem MapsTo.coe_iterate_restrict {f : α → α} (h : MapsTo f s s) (x : s) (k : ℕ) : h.restrict^[k] x = f^[k] x := by induction' k with k ih; · simp simp only [iterate_succ', comp_apply, val_restrict_apply, ih] /-- Restricting the domain and then the codomain is the same as `MapsTo.restrict`. -/ @[simp] theorem codRestrict_restrict (h : ∀ x : s, f x ∈ t) : codRestrict (s.restrict f) t h = MapsTo.restrict f s t fun x hx => h ⟨x, hx⟩ := rfl #align set.cod_restrict_restrict Set.codRestrict_restrict /-- Reverse of `Set.codRestrict_restrict`. -/ theorem MapsTo.restrict_eq_codRestrict (h : MapsTo f s t) : h.restrict f s t = codRestrict (s.restrict f) t fun x => h x.2 := rfl #align set.maps_to.restrict_eq_cod_restrict Set.MapsTo.restrict_eq_codRestrict theorem MapsTo.coe_restrict (h : Set.MapsTo f s t) : Subtype.val ∘ h.restrict f s t = s.restrict f := rfl #align set.maps_to.coe_restrict Set.MapsTo.coe_restrict theorem MapsTo.range_restrict (f : α → β) (s : Set α) (t : Set β) (h : MapsTo f s t) : range (h.restrict f s t) = Subtype.val ⁻¹' (f '' s) := Set.range_subtype_map f h #align set.maps_to.range_restrict Set.MapsTo.range_restrict theorem mapsTo_iff_exists_map_subtype : MapsTo f s t ↔ ∃ g : s → t, ∀ x : s, f x = g x := ⟨fun h => ⟨h.restrict f s t, fun _ => rfl⟩, fun ⟨g, hg⟩ x hx => by erw [hg ⟨x, hx⟩] apply Subtype.coe_prop⟩ #align set.maps_to_iff_exists_map_subtype Set.mapsTo_iff_exists_map_subtype theorem mapsTo' : MapsTo f s t ↔ f '' s ⊆ t := image_subset_iff.symm #align set.maps_to' Set.mapsTo' theorem mapsTo_prod_map_diagonal : MapsTo (Prod.map f f) (diagonal α) (diagonal β) := diagonal_subset_iff.2 fun _ => rfl #align set.maps_to_prod_map_diagonal Set.mapsTo_prod_map_diagonal theorem MapsTo.subset_preimage {f : α → β} {s : Set α} {t : Set β} (hf : MapsTo f s t) : s ⊆ f ⁻¹' t := hf #align set.maps_to.subset_preimage Set.MapsTo.subset_preimage @[simp] theorem mapsTo_singleton {x : α} : MapsTo f {x} t ↔ f x ∈ t := singleton_subset_iff #align set.maps_to_singleton Set.mapsTo_singleton theorem mapsTo_empty (f : α → β) (t : Set β) : MapsTo f ∅ t := empty_subset _ #align set.maps_to_empty Set.mapsTo_empty @[simp] theorem mapsTo_empty_iff : MapsTo f s ∅ ↔ s = ∅ := by simp [mapsTo', subset_empty_iff] /-- If `f` maps `s` to `t` and `s` is non-empty, `t` is non-empty. -/ theorem MapsTo.nonempty (h : MapsTo f s t) (hs : s.Nonempty) : t.Nonempty := (hs.image f).mono (mapsTo'.mp h) theorem MapsTo.image_subset (h : MapsTo f s t) : f '' s ⊆ t := mapsTo'.1 h #align set.maps_to.image_subset Set.MapsTo.image_subset theorem MapsTo.congr (h₁ : MapsTo f₁ s t) (h : EqOn f₁ f₂ s) : MapsTo f₂ s t := fun _ hx => h hx ▸ h₁ hx #align set.maps_to.congr Set.MapsTo.congr theorem EqOn.comp_right (hg : t.EqOn g₁ g₂) (hf : s.MapsTo f t) : s.EqOn (g₁ ∘ f) (g₂ ∘ f) := fun _ ha => hg <| hf ha #align set.eq_on.comp_right Set.EqOn.comp_right theorem EqOn.mapsTo_iff (H : EqOn f₁ f₂ s) : MapsTo f₁ s t ↔ MapsTo f₂ s t := ⟨fun h => h.congr H, fun h => h.congr H.symm⟩ #align set.eq_on.maps_to_iff Set.EqOn.mapsTo_iff theorem MapsTo.comp (h₁ : MapsTo g t p) (h₂ : MapsTo f s t) : MapsTo (g ∘ f) s p := fun _ h => h₁ (h₂ h) #align set.maps_to.comp Set.MapsTo.comp theorem mapsTo_id (s : Set α) : MapsTo id s s := fun _ => id #align set.maps_to_id Set.mapsTo_id theorem MapsTo.iterate {f : α → α} {s : Set α} (h : MapsTo f s s) : ∀ n, MapsTo f^[n] s s | 0 => fun _ => id | n + 1 => (MapsTo.iterate h n).comp h #align set.maps_to.iterate Set.MapsTo.iterate theorem MapsTo.iterate_restrict {f : α → α} {s : Set α} (h : MapsTo f s s) (n : ℕ) : (h.restrict f s s)^[n] = (h.iterate n).restrict _ _ _ := by funext x rw [Subtype.ext_iff, MapsTo.val_restrict_apply] induction' n with n ihn generalizing x · rfl · simp [Nat.iterate, ihn] #align set.maps_to.iterate_restrict Set.MapsTo.iterate_restrict lemma mapsTo_of_subsingleton' [Subsingleton β] (f : α → β) (h : s.Nonempty → t.Nonempty) : MapsTo f s t := fun a ha ↦ Subsingleton.mem_iff_nonempty.2 <| h ⟨a, ha⟩ #align set.maps_to_of_subsingleton' Set.mapsTo_of_subsingleton' lemma mapsTo_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : MapsTo f s s := mapsTo_of_subsingleton' _ id #align set.maps_to_of_subsingleton Set.mapsTo_of_subsingleton theorem MapsTo.mono (hf : MapsTo f s₁ t₁) (hs : s₂ ⊆ s₁) (ht : t₁ ⊆ t₂) : MapsTo f s₂ t₂ := fun _ hx => ht (hf <| hs hx) #align set.maps_to.mono Set.MapsTo.mono theorem MapsTo.mono_left (hf : MapsTo f s₁ t) (hs : s₂ ⊆ s₁) : MapsTo f s₂ t := fun _ hx => hf (hs hx) #align set.maps_to.mono_left Set.MapsTo.mono_left theorem MapsTo.mono_right (hf : MapsTo f s t₁) (ht : t₁ ⊆ t₂) : MapsTo f s t₂ := fun _ hx => ht (hf hx) #align set.maps_to.mono_right Set.MapsTo.mono_right theorem MapsTo.union_union (h₁ : MapsTo f s₁ t₁) (h₂ : MapsTo f s₂ t₂) : MapsTo f (s₁ ∪ s₂) (t₁ ∪ t₂) := fun _ hx => hx.elim (fun hx => Or.inl <| h₁ hx) fun hx => Or.inr <| h₂ hx #align set.maps_to.union_union Set.MapsTo.union_union theorem MapsTo.union (h₁ : MapsTo f s₁ t) (h₂ : MapsTo f s₂ t) : MapsTo f (s₁ ∪ s₂) t := union_self t ▸ h₁.union_union h₂ #align set.maps_to.union Set.MapsTo.union @[simp] theorem mapsTo_union : MapsTo f (s₁ ∪ s₂) t ↔ MapsTo f s₁ t ∧ MapsTo f s₂ t := ⟨fun h => ⟨h.mono subset_union_left (Subset.refl t), h.mono subset_union_right (Subset.refl t)⟩, fun h => h.1.union h.2⟩ #align set.maps_to_union Set.mapsTo_union theorem MapsTo.inter (h₁ : MapsTo f s t₁) (h₂ : MapsTo f s t₂) : MapsTo f s (t₁ ∩ t₂) := fun _ hx => ⟨h₁ hx, h₂ hx⟩ #align set.maps_to.inter Set.MapsTo.inter theorem MapsTo.inter_inter (h₁ : MapsTo f s₁ t₁) (h₂ : MapsTo f s₂ t₂) : MapsTo f (s₁ ∩ s₂) (t₁ ∩ t₂) := fun _ hx => ⟨h₁ hx.1, h₂ hx.2⟩ #align set.maps_to.inter_inter Set.MapsTo.inter_inter @[simp] theorem mapsTo_inter : MapsTo f s (t₁ ∩ t₂) ↔ MapsTo f s t₁ ∧ MapsTo f s t₂ := ⟨fun h => ⟨h.mono (Subset.refl s) inter_subset_left, h.mono (Subset.refl s) inter_subset_right⟩, fun h => h.1.inter h.2⟩ #align set.maps_to_inter Set.mapsTo_inter theorem mapsTo_univ (f : α → β) (s : Set α) : MapsTo f s univ := fun _ _ => trivial #align set.maps_to_univ Set.mapsTo_univ theorem mapsTo_range (f : α → β) (s : Set α) : MapsTo f s (range f) := (mapsTo_image f s).mono (Subset.refl s) (image_subset_range _ _) #align set.maps_to_range Set.mapsTo_range @[simp] theorem mapsTo_image_iff {f : α → β} {g : γ → α} {s : Set γ} {t : Set β} : MapsTo f (g '' s) t ↔ MapsTo (f ∘ g) s t := ⟨fun h c hc => h ⟨c, hc, rfl⟩, fun h _ ⟨_, hc⟩ => hc.2 ▸ h hc.1⟩ #align set.maps_image_to Set.mapsTo_image_iff @[deprecated (since := "2023-12-25")] lemma maps_image_to (f : α → β) (g : γ → α) (s : Set γ) (t : Set β) : MapsTo f (g '' s) t ↔ MapsTo (f ∘ g) s t := mapsTo_image_iff lemma MapsTo.comp_left (g : β → γ) (hf : MapsTo f s t) : MapsTo (g ∘ f) s (g '' t) := fun x hx ↦ ⟨f x, hf hx, rfl⟩ #align set.maps_to.comp_left Set.MapsTo.comp_left lemma MapsTo.comp_right {s : Set β} {t : Set γ} (hg : MapsTo g s t) (f : α → β) : MapsTo (g ∘ f) (f ⁻¹' s) t := fun _ hx ↦ hg hx #align set.maps_to.comp_right Set.MapsTo.comp_right @[simp] lemma mapsTo_univ_iff : MapsTo f univ t ↔ ∀ x, f x ∈ t := ⟨fun h _ => h (mem_univ _), fun h x _ => h x⟩ @[deprecated (since := "2023-12-25")] theorem maps_univ_to (f : α → β) (s : Set β) : MapsTo f univ s ↔ ∀ a, f a ∈ s := mapsTo_univ_iff #align set.maps_univ_to Set.maps_univ_to @[simp] lemma mapsTo_range_iff {g : ι → α} : MapsTo f (range g) t ↔ ∀ i, f (g i) ∈ t := forall_mem_range @[deprecated mapsTo_range_iff (since := "2023-12-25")] theorem maps_range_to (f : α → β) (g : γ → α) (s : Set β) : MapsTo f (range g) s ↔ MapsTo (f ∘ g) univ s := by rw [← image_univ, mapsTo_image_iff] #align set.maps_range_to Set.maps_range_to theorem surjective_mapsTo_image_restrict (f : α → β) (s : Set α) : Surjective ((mapsTo_image f s).restrict f s (f '' s)) := fun ⟨_, x, hs, hxy⟩ => ⟨⟨x, hs⟩, Subtype.ext hxy⟩ #align set.surjective_maps_to_image_restrict Set.surjective_mapsTo_image_restrict theorem MapsTo.mem_iff (h : MapsTo f s t) (hc : MapsTo f sᶜ tᶜ) {x} : f x ∈ t ↔ x ∈ s := ⟨fun ht => by_contra fun hs => hc hs ht, fun hx => h hx⟩ #align set.maps_to.mem_iff Set.MapsTo.mem_iff end MapsTo /-! ### Restriction onto preimage -/ section variable (t) variable (f s) in theorem image_restrictPreimage : t.restrictPreimage f '' (Subtype.val ⁻¹' s) = Subtype.val ⁻¹' (f '' s) := by delta Set.restrictPreimage rw [← (Subtype.coe_injective).image_injective.eq_iff, ← image_comp, MapsTo.restrict_commutes, image_comp, Subtype.image_preimage_coe, Subtype.image_preimage_coe, image_preimage_inter] variable (f) in theorem range_restrictPreimage : range (t.restrictPreimage f) = Subtype.val ⁻¹' range f := by simp only [← image_univ, ← image_restrictPreimage, preimage_univ] #align set.range_restrict_preimage Set.range_restrictPreimage variable {U : ι → Set β} lemma restrictPreimage_injective (hf : Injective f) : Injective (t.restrictPreimage f) := fun _ _ e => Subtype.coe_injective <| hf <| Subtype.mk.inj e #align set.restrict_preimage_injective Set.restrictPreimage_injective lemma restrictPreimage_surjective (hf : Surjective f) : Surjective (t.restrictPreimage f) := fun x => ⟨⟨_, ((hf x).choose_spec.symm ▸ x.2 : _ ∈ t)⟩, Subtype.ext (hf x).choose_spec⟩ #align set.restrict_preimage_surjective Set.restrictPreimage_surjective lemma restrictPreimage_bijective (hf : Bijective f) : Bijective (t.restrictPreimage f) := ⟨t.restrictPreimage_injective hf.1, t.restrictPreimage_surjective hf.2⟩ #align set.restrict_preimage_bijective Set.restrictPreimage_bijective alias _root_.Function.Injective.restrictPreimage := Set.restrictPreimage_injective alias _root_.Function.Surjective.restrictPreimage := Set.restrictPreimage_surjective alias _root_.Function.Bijective.restrictPreimage := Set.restrictPreimage_bijective #align function.bijective.restrict_preimage Function.Bijective.restrictPreimage #align function.surjective.restrict_preimage Function.Surjective.restrictPreimage #align function.injective.restrict_preimage Function.Injective.restrictPreimage end /-! ### Injectivity on a set -/ section injOn theorem Subsingleton.injOn (hs : s.Subsingleton) (f : α → β) : InjOn f s := fun _ hx _ hy _ => hs hx hy #align set.subsingleton.inj_on Set.Subsingleton.injOn @[simp] theorem injOn_empty (f : α → β) : InjOn f ∅ := subsingleton_empty.injOn f #align set.inj_on_empty Set.injOn_empty @[simp] theorem injOn_singleton (f : α → β) (a : α) : InjOn f {a} := subsingleton_singleton.injOn f #align set.inj_on_singleton Set.injOn_singleton @[simp] lemma injOn_pair {b : α} : InjOn f {a, b} ↔ f a = f b → a = b := by unfold InjOn; aesop theorem InjOn.eq_iff {x y} (h : InjOn f s) (hx : x ∈ s) (hy : y ∈ s) : f x = f y ↔ x = y := ⟨h hx hy, fun h => h ▸ rfl⟩ #align set.inj_on.eq_iff Set.InjOn.eq_iff theorem InjOn.ne_iff {x y} (h : InjOn f s) (hx : x ∈ s) (hy : y ∈ s) : f x ≠ f y ↔ x ≠ y := (h.eq_iff hx hy).not #align set.inj_on.ne_iff Set.InjOn.ne_iff alias ⟨_, InjOn.ne⟩ := InjOn.ne_iff #align set.inj_on.ne Set.InjOn.ne theorem InjOn.congr (h₁ : InjOn f₁ s) (h : EqOn f₁ f₂ s) : InjOn f₂ s := fun _ hx _ hy => h hx ▸ h hy ▸ h₁ hx hy #align set.inj_on.congr Set.InjOn.congr theorem EqOn.injOn_iff (H : EqOn f₁ f₂ s) : InjOn f₁ s ↔ InjOn f₂ s := ⟨fun h => h.congr H, fun h => h.congr H.symm⟩ #align set.eq_on.inj_on_iff Set.EqOn.injOn_iff theorem InjOn.mono (h : s₁ ⊆ s₂) (ht : InjOn f s₂) : InjOn f s₁ := fun _ hx _ hy H => ht (h hx) (h hy) H #align set.inj_on.mono Set.InjOn.mono theorem injOn_union (h : Disjoint s₁ s₂) : InjOn f (s₁ ∪ s₂) ↔ InjOn f s₁ ∧ InjOn f s₂ ∧ ∀ x ∈ s₁, ∀ y ∈ s₂, f x ≠ f y := by refine ⟨fun H => ⟨H.mono subset_union_left, H.mono subset_union_right, ?_⟩, ?_⟩ · intro x hx y hy hxy obtain rfl : x = y := H (Or.inl hx) (Or.inr hy) hxy exact h.le_bot ⟨hx, hy⟩ · rintro ⟨h₁, h₂, h₁₂⟩ rintro x (hx | hx) y (hy | hy) hxy exacts [h₁ hx hy hxy, (h₁₂ _ hx _ hy hxy).elim, (h₁₂ _ hy _ hx hxy.symm).elim, h₂ hx hy hxy] #align set.inj_on_union Set.injOn_union theorem injOn_insert {f : α → β} {s : Set α} {a : α} (has : a ∉ s) : Set.InjOn f (insert a s) ↔ Set.InjOn f s ∧ f a ∉ f '' s := by rw [← union_singleton, injOn_union (disjoint_singleton_right.2 has)] simp #align set.inj_on_insert Set.injOn_insert theorem injective_iff_injOn_univ : Injective f ↔ InjOn f univ := ⟨fun h _ _ _ _ hxy => h hxy, fun h _ _ heq => h trivial trivial heq⟩ #align set.injective_iff_inj_on_univ Set.injective_iff_injOn_univ theorem injOn_of_injective (h : Injective f) {s : Set α} : InjOn f s := fun _ _ _ _ hxy => h hxy #align set.inj_on_of_injective Set.injOn_of_injective alias _root_.Function.Injective.injOn := injOn_of_injective #align function.injective.inj_on Function.Injective.injOn -- A specialization of `injOn_of_injective` for `Subtype.val`. theorem injOn_subtype_val {s : Set { x // p x }} : Set.InjOn Subtype.val s := Subtype.coe_injective.injOn lemma injOn_id (s : Set α) : InjOn id s := injective_id.injOn #align set.inj_on_id Set.injOn_id theorem InjOn.comp (hg : InjOn g t) (hf : InjOn f s) (h : MapsTo f s t) : InjOn (g ∘ f) s := fun _ hx _ hy heq => hf hx hy <| hg (h hx) (h hy) heq #align set.inj_on.comp Set.InjOn.comp lemma InjOn.image_of_comp (h : InjOn (g ∘ f) s) : InjOn g (f '' s) := forall_mem_image.2 fun _x hx ↦ forall_mem_image.2 fun _y hy heq ↦ congr_arg f <| h hx hy heq lemma InjOn.iterate {f : α → α} {s : Set α} (h : InjOn f s) (hf : MapsTo f s s) : ∀ n, InjOn f^[n] s | 0 => injOn_id _ | (n + 1) => (h.iterate hf n).comp h hf #align set.inj_on.iterate Set.InjOn.iterate lemma injOn_of_subsingleton [Subsingleton α] (f : α → β) (s : Set α) : InjOn f s := (injective_of_subsingleton _).injOn #align set.inj_on_of_subsingleton Set.injOn_of_subsingleton theorem _root_.Function.Injective.injOn_range (h : Injective (g ∘ f)) : InjOn g (range f) := by rintro _ ⟨x, rfl⟩ _ ⟨y, rfl⟩ H exact congr_arg f (h H) #align function.injective.inj_on_range Function.Injective.injOn_range theorem injOn_iff_injective : InjOn f s ↔ Injective (s.restrict f) := ⟨fun H a b h => Subtype.eq <| H a.2 b.2 h, fun H a as b bs h => congr_arg Subtype.val <| @H ⟨a, as⟩ ⟨b, bs⟩ h⟩ #align set.inj_on_iff_injective Set.injOn_iff_injective alias ⟨InjOn.injective, _⟩ := Set.injOn_iff_injective #align set.inj_on.injective Set.InjOn.injective theorem MapsTo.restrict_inj (h : MapsTo f s t) : Injective (h.restrict f s t) ↔ InjOn f s := by rw [h.restrict_eq_codRestrict, injective_codRestrict, injOn_iff_injective] #align set.maps_to.restrict_inj Set.MapsTo.restrict_inj theorem exists_injOn_iff_injective [Nonempty β] : (∃ f : α → β, InjOn f s) ↔ ∃ f : s → β, Injective f := ⟨fun ⟨f, hf⟩ => ⟨_, hf.injective⟩, fun ⟨f, hf⟩ => by lift f to α → β using trivial exact ⟨f, injOn_iff_injective.2 hf⟩⟩ #align set.exists_inj_on_iff_injective Set.exists_injOn_iff_injective theorem injOn_preimage {B : Set (Set β)} (hB : B ⊆ 𝒫 range f) : InjOn (preimage f) B := fun s hs t ht hst => (preimage_eq_preimage' (@hB s hs) (@hB t ht)).1 hst -- Porting note: is there a semi-implicit variable problem with `⊆`? #align set.inj_on_preimage Set.injOn_preimage theorem InjOn.mem_of_mem_image {x} (hf : InjOn f s) (hs : s₁ ⊆ s) (h : x ∈ s) (h₁ : f x ∈ f '' s₁) : x ∈ s₁ := let ⟨_, h', Eq⟩ := h₁ hf (hs h') h Eq ▸ h' #align set.inj_on.mem_of_mem_image Set.InjOn.mem_of_mem_image theorem InjOn.mem_image_iff {x} (hf : InjOn f s) (hs : s₁ ⊆ s) (hx : x ∈ s) : f x ∈ f '' s₁ ↔ x ∈ s₁ := ⟨hf.mem_of_mem_image hs hx, mem_image_of_mem f⟩ #align set.inj_on.mem_image_iff Set.InjOn.mem_image_iff theorem InjOn.preimage_image_inter (hf : InjOn f s) (hs : s₁ ⊆ s) : f ⁻¹' (f '' s₁) ∩ s = s₁ := ext fun _ => ⟨fun ⟨h₁, h₂⟩ => hf.mem_of_mem_image hs h₂ h₁, fun h => ⟨mem_image_of_mem _ h, hs h⟩⟩ #align set.inj_on.preimage_image_inter Set.InjOn.preimage_image_inter theorem EqOn.cancel_left (h : s.EqOn (g ∘ f₁) (g ∘ f₂)) (hg : t.InjOn g) (hf₁ : s.MapsTo f₁ t) (hf₂ : s.MapsTo f₂ t) : s.EqOn f₁ f₂ := fun _ ha => hg (hf₁ ha) (hf₂ ha) (h ha) #align set.eq_on.cancel_left Set.EqOn.cancel_left theorem InjOn.cancel_left (hg : t.InjOn g) (hf₁ : s.MapsTo f₁ t) (hf₂ : s.MapsTo f₂ t) : s.EqOn (g ∘ f₁) (g ∘ f₂) ↔ s.EqOn f₁ f₂ := ⟨fun h => h.cancel_left hg hf₁ hf₂, EqOn.comp_left⟩ #align set.inj_on.cancel_left Set.InjOn.cancel_left lemma InjOn.image_inter {s t u : Set α} (hf : u.InjOn f) (hs : s ⊆ u) (ht : t ⊆ u) : f '' (s ∩ t) = f '' s ∩ f '' t := by apply Subset.antisymm (image_inter_subset _ _ _) intro x ⟨⟨y, ys, hy⟩, ⟨z, zt, hz⟩⟩ have : y = z := by apply hf (hs ys) (ht zt) rwa [← hz] at hy rw [← this] at zt exact ⟨y, ⟨ys, zt⟩, hy⟩ #align set.inj_on.image_inter Set.InjOn.image_inter lemma InjOn.image (h : s.InjOn f) : s.powerset.InjOn (image f) := fun s₁ hs₁ s₂ hs₂ h' ↦ by rw [← h.preimage_image_inter hs₁, h', h.preimage_image_inter hs₂] theorem InjOn.image_eq_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) : f '' s₁ = f '' s₂ ↔ s₁ = s₂ := h.image.eq_iff h₁ h₂ lemma InjOn.image_subset_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) : f '' s₁ ⊆ f '' s₂ ↔ s₁ ⊆ s₂ := by refine' ⟨fun h' ↦ _, image_subset _⟩ rw [← h.preimage_image_inter h₁, ← h.preimage_image_inter h₂] exact inter_subset_inter_left _ (preimage_mono h') lemma InjOn.image_ssubset_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) : f '' s₁ ⊂ f '' s₂ ↔ s₁ ⊂ s₂ := by simp_rw [ssubset_def, h.image_subset_image_iff h₁ h₂, h.image_subset_image_iff h₂ h₁] -- TODO: can this move to a better place? theorem _root_.Disjoint.image {s t u : Set α} {f : α → β} (h : Disjoint s t) (hf : u.InjOn f) (hs : s ⊆ u) (ht : t ⊆ u) : Disjoint (f '' s) (f '' t) := by rw [disjoint_iff_inter_eq_empty] at h ⊢ rw [← hf.image_inter hs ht, h, image_empty] #align disjoint.image Disjoint.image lemma InjOn.image_diff {t : Set α} (h : s.InjOn f) : f '' (s \ t) = f '' s \ f '' (s ∩ t) := by refine subset_antisymm (subset_diff.2 ⟨image_subset f diff_subset, ?_⟩) (diff_subset_iff.2 (by rw [← image_union, inter_union_diff])) exact Disjoint.image disjoint_sdiff_inter h diff_subset inter_subset_left lemma InjOn.image_diff_subset {f : α → β} {t : Set α} (h : InjOn f s) (hst : t ⊆ s) : f '' (s \ t) = f '' s \ f '' t := by rw [h.image_diff, inter_eq_self_of_subset_right hst] theorem InjOn.imageFactorization_injective (h : InjOn f s) : Injective (s.imageFactorization f) := fun ⟨x, hx⟩ ⟨y, hy⟩ h' ↦ by simpa [imageFactorization, h.eq_iff hx hy] using h' @[simp] theorem imageFactorization_injective_iff : Injective (s.imageFactorization f) ↔ InjOn f s := ⟨fun h x hx y hy _ ↦ by simpa using @h ⟨x, hx⟩ ⟨y, hy⟩ (by simpa [imageFactorization]), InjOn.imageFactorization_injective⟩ end injOn section graphOn @[simp] lemma graphOn_empty (f : α → β) : graphOn f ∅ = ∅ := image_empty _ @[simp] lemma graphOn_union (f : α → β) (s t : Set α) : graphOn f (s ∪ t) = graphOn f s ∪ graphOn f t := image_union .. @[simp] lemma graphOn_singleton (f : α → β) (x : α) : graphOn f {x} = {(x, f x)} := image_singleton .. @[simp] lemma graphOn_insert (f : α → β) (x : α) (s : Set α) : graphOn f (insert x s) = insert (x, f x) (graphOn f s) := image_insert_eq .. @[simp] lemma image_fst_graphOn (f : α → β) (s : Set α) : Prod.fst '' graphOn f s = s := by simp [graphOn, image_image] lemma exists_eq_graphOn_image_fst [Nonempty β] {s : Set (α × β)} : (∃ f : α → β, s = graphOn f (Prod.fst '' s)) ↔ InjOn Prod.fst s := by refine ⟨?_, fun h ↦ ?_⟩ · rintro ⟨f, hf⟩ rw [hf] exact InjOn.image_of_comp <| injOn_id _ · have : ∀ x ∈ Prod.fst '' s, ∃ y, (x, y) ∈ s := forall_mem_image.2 fun (x, y) h ↦ ⟨y, h⟩ choose! f hf using this rw [forall_mem_image] at hf use f rw [graphOn, image_image, EqOn.image_eq_self] exact fun x hx ↦ h (hf hx) hx rfl lemma exists_eq_graphOn [Nonempty β] {s : Set (α × β)} : (∃ f t, s = graphOn f t) ↔ InjOn Prod.fst s := .trans ⟨fun ⟨f, t, hs⟩ ↦ ⟨f, by rw [hs, image_fst_graphOn]⟩, fun ⟨f, hf⟩ ↦ ⟨f, _, hf⟩⟩ exists_eq_graphOn_image_fst end graphOn /-! ### Surjectivity on a set -/ section surjOn theorem SurjOn.subset_range (h : SurjOn f s t) : t ⊆ range f := Subset.trans h <| image_subset_range f s #align set.surj_on.subset_range Set.SurjOn.subset_range theorem surjOn_iff_exists_map_subtype : SurjOn f s t ↔ ∃ (t' : Set β) (g : s → t'), t ⊆ t' ∧ Surjective g ∧ ∀ x : s, f x = g x := ⟨fun h => ⟨_, (mapsTo_image f s).restrict f s _, h, surjective_mapsTo_image_restrict _ _, fun _ => rfl⟩, fun ⟨t', g, htt', hg, hfg⟩ y hy => let ⟨x, hx⟩ := hg ⟨y, htt' hy⟩ ⟨x, x.2, by rw [hfg, hx, Subtype.coe_mk]⟩⟩ #align set.surj_on_iff_exists_map_subtype Set.surjOn_iff_exists_map_subtype theorem surjOn_empty (f : α → β) (s : Set α) : SurjOn f s ∅ := empty_subset _ #align set.surj_on_empty Set.surjOn_empty @[simp] theorem surjOn_empty_iff : SurjOn f ∅ t ↔ t = ∅ := by simp [SurjOn, subset_empty_iff] @[simp] lemma surjOn_singleton : SurjOn f s {b} ↔ b ∈ f '' s := singleton_subset_iff #align set.surj_on_singleton Set.surjOn_singleton theorem surjOn_image (f : α → β) (s : Set α) : SurjOn f s (f '' s) := Subset.rfl #align set.surj_on_image Set.surjOn_image theorem SurjOn.comap_nonempty (h : SurjOn f s t) (ht : t.Nonempty) : s.Nonempty := (ht.mono h).of_image #align set.surj_on.comap_nonempty Set.SurjOn.comap_nonempty theorem SurjOn.congr (h : SurjOn f₁ s t) (H : EqOn f₁ f₂ s) : SurjOn f₂ s t := by rwa [SurjOn, ← H.image_eq] #align set.surj_on.congr Set.SurjOn.congr theorem EqOn.surjOn_iff (h : EqOn f₁ f₂ s) : SurjOn f₁ s t ↔ SurjOn f₂ s t := ⟨fun H => H.congr h, fun H => H.congr h.symm⟩ #align set.eq_on.surj_on_iff Set.EqOn.surjOn_iff theorem SurjOn.mono (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) (hf : SurjOn f s₁ t₂) : SurjOn f s₂ t₁ := Subset.trans ht <| Subset.trans hf <| image_subset _ hs #align set.surj_on.mono Set.SurjOn.mono theorem SurjOn.union (h₁ : SurjOn f s t₁) (h₂ : SurjOn f s t₂) : SurjOn f s (t₁ ∪ t₂) := fun _ hx => hx.elim (fun hx => h₁ hx) fun hx => h₂ hx #align set.surj_on.union Set.SurjOn.union theorem SurjOn.union_union (h₁ : SurjOn f s₁ t₁) (h₂ : SurjOn f s₂ t₂) : SurjOn f (s₁ ∪ s₂) (t₁ ∪ t₂) := (h₁.mono subset_union_left (Subset.refl _)).union (h₂.mono subset_union_right (Subset.refl _)) #align set.surj_on.union_union Set.SurjOn.union_union theorem SurjOn.inter_inter (h₁ : SurjOn f s₁ t₁) (h₂ : SurjOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) : SurjOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := by intro y hy rcases h₁ hy.1 with ⟨x₁, hx₁, rfl⟩ rcases h₂ hy.2 with ⟨x₂, hx₂, heq⟩ obtain rfl : x₁ = x₂ := h (Or.inl hx₁) (Or.inr hx₂) heq.symm exact mem_image_of_mem f ⟨hx₁, hx₂⟩ #align set.surj_on.inter_inter Set.SurjOn.inter_inter theorem SurjOn.inter (h₁ : SurjOn f s₁ t) (h₂ : SurjOn f s₂ t) (h : InjOn f (s₁ ∪ s₂)) : SurjOn f (s₁ ∩ s₂) t := inter_self t ▸ h₁.inter_inter h₂ h #align set.surj_on.inter Set.SurjOn.inter -- Porting note: Why does `simp` not call `refl` by itself? lemma surjOn_id (s : Set α) : SurjOn id s s := by simp [SurjOn, subset_rfl] #align set.surj_on_id Set.surjOn_id theorem SurjOn.comp (hg : SurjOn g t p) (hf : SurjOn f s t) : SurjOn (g ∘ f) s p := Subset.trans hg <| Subset.trans (image_subset g hf) <| image_comp g f s ▸ Subset.refl _ #align set.surj_on.comp Set.SurjOn.comp lemma SurjOn.iterate {f : α → α} {s : Set α} (h : SurjOn f s s) : ∀ n, SurjOn f^[n] s s | 0 => surjOn_id _ | (n + 1) => (h.iterate n).comp h #align set.surj_on.iterate Set.SurjOn.iterate lemma SurjOn.comp_left (hf : SurjOn f s t) (g : β → γ) : SurjOn (g ∘ f) s (g '' t) := by rw [SurjOn, image_comp g f]; exact image_subset _ hf #align set.surj_on.comp_left Set.SurjOn.comp_left lemma SurjOn.comp_right {s : Set β} {t : Set γ} (hf : Surjective f) (hg : SurjOn g s t) : SurjOn (g ∘ f) (f ⁻¹' s) t := by rwa [SurjOn, image_comp g f, image_preimage_eq _ hf] #align set.surj_on.comp_right Set.SurjOn.comp_right lemma surjOn_of_subsingleton' [Subsingleton β] (f : α → β) (h : t.Nonempty → s.Nonempty) : SurjOn f s t := fun _ ha ↦ Subsingleton.mem_iff_nonempty.2 <| (h ⟨_, ha⟩).image _ #align set.surj_on_of_subsingleton' Set.surjOn_of_subsingleton' lemma surjOn_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : SurjOn f s s := surjOn_of_subsingleton' _ id #align set.surj_on_of_subsingleton Set.surjOn_of_subsingleton theorem surjective_iff_surjOn_univ : Surjective f ↔ SurjOn f univ univ := by simp [Surjective, SurjOn, subset_def] #align set.surjective_iff_surj_on_univ Set.surjective_iff_surjOn_univ theorem surjOn_iff_surjective : SurjOn f s univ ↔ Surjective (s.restrict f) := ⟨fun H b => let ⟨a, as, e⟩ := @H b trivial ⟨⟨a, as⟩, e⟩, fun H b _ => let ⟨⟨a, as⟩, e⟩ := H b ⟨a, as, e⟩⟩ #align set.surj_on_iff_surjective Set.surjOn_iff_surjective @[simp] theorem MapsTo.restrict_surjective_iff (h : MapsTo f s t) : Surjective (MapsTo.restrict _ _ _ h) ↔ SurjOn f s t := by refine ⟨fun h' b hb ↦ ?_, fun h' ⟨b, hb⟩ ↦ ?_⟩ · obtain ⟨⟨a, ha⟩, ha'⟩ := h' ⟨b, hb⟩ replace ha' : f a = b := by simpa [Subtype.ext_iff] using ha' rw [← ha'] exact mem_image_of_mem f ha · obtain ⟨a, ha, rfl⟩ := h' hb exact ⟨⟨a, ha⟩, rfl⟩ theorem SurjOn.image_eq_of_mapsTo (h₁ : SurjOn f s t) (h₂ : MapsTo f s t) : f '' s = t := eq_of_subset_of_subset h₂.image_subset h₁ #align set.surj_on.image_eq_of_maps_to Set.SurjOn.image_eq_of_mapsTo theorem image_eq_iff_surjOn_mapsTo : f '' s = t ↔ s.SurjOn f t ∧ s.MapsTo f t := by refine ⟨?_, fun h => h.1.image_eq_of_mapsTo h.2⟩ rintro rfl exact ⟨s.surjOn_image f, s.mapsTo_image f⟩ #align set.image_eq_iff_surj_on_maps_to Set.image_eq_iff_surjOn_mapsTo lemma SurjOn.image_preimage (h : Set.SurjOn f s t) (ht : t₁ ⊆ t) : f '' (f ⁻¹' t₁) = t₁ := image_preimage_eq_iff.2 fun _ hx ↦ mem_range_of_mem_image f s <| h <| ht hx theorem SurjOn.mapsTo_compl (h : SurjOn f s t) (h' : Injective f) : MapsTo f sᶜ tᶜ := fun _ hs ht => let ⟨_, hx', HEq⟩ := h ht hs <| h' HEq ▸ hx' #align set.surj_on.maps_to_compl Set.SurjOn.mapsTo_compl theorem MapsTo.surjOn_compl (h : MapsTo f s t) (h' : Surjective f) : SurjOn f sᶜ tᶜ := h'.forall.2 fun _ ht => (mem_image_of_mem _) fun hs => ht (h hs) #align set.maps_to.surj_on_compl Set.MapsTo.surjOn_compl theorem EqOn.cancel_right (hf : s.EqOn (g₁ ∘ f) (g₂ ∘ f)) (hf' : s.SurjOn f t) : t.EqOn g₁ g₂ := by intro b hb obtain ⟨a, ha, rfl⟩ := hf' hb exact hf ha #align set.eq_on.cancel_right Set.EqOn.cancel_right theorem SurjOn.cancel_right (hf : s.SurjOn f t) (hf' : s.MapsTo f t) : s.EqOn (g₁ ∘ f) (g₂ ∘ f) ↔ t.EqOn g₁ g₂ := ⟨fun h => h.cancel_right hf, fun h => h.comp_right hf'⟩ #align set.surj_on.cancel_right Set.SurjOn.cancel_right theorem eqOn_comp_right_iff : s.EqOn (g₁ ∘ f) (g₂ ∘ f) ↔ (f '' s).EqOn g₁ g₂ := (s.surjOn_image f).cancel_right <| s.mapsTo_image f #align set.eq_on_comp_right_iff Set.eqOn_comp_right_iff theorem SurjOn.forall {p : β → Prop} (hf : s.SurjOn f t) (hf' : s.MapsTo f t) : (∀ y ∈ t, p y) ↔ (∀ x ∈ s, p (f x)) := ⟨fun H x hx ↦ H (f x) (hf' hx), fun H _y hy ↦ let ⟨x, hx, hxy⟩ := hf hy; hxy ▸ H x hx⟩ end surjOn /-! ### Bijectivity -/ section bijOn theorem BijOn.mapsTo (h : BijOn f s t) : MapsTo f s t := h.left #align set.bij_on.maps_to Set.BijOn.mapsTo theorem BijOn.injOn (h : BijOn f s t) : InjOn f s := h.right.left #align set.bij_on.inj_on Set.BijOn.injOn theorem BijOn.surjOn (h : BijOn f s t) : SurjOn f s t := h.right.right #align set.bij_on.surj_on Set.BijOn.surjOn theorem BijOn.mk (h₁ : MapsTo f s t) (h₂ : InjOn f s) (h₃ : SurjOn f s t) : BijOn f s t := ⟨h₁, h₂, h₃⟩ #align set.bij_on.mk Set.BijOn.mk theorem bijOn_empty (f : α → β) : BijOn f ∅ ∅ := ⟨mapsTo_empty f ∅, injOn_empty f, surjOn_empty f ∅⟩ #align set.bij_on_empty Set.bijOn_empty @[simp] theorem bijOn_empty_iff_left : BijOn f s ∅ ↔ s = ∅ := ⟨fun h ↦ by simpa using h.mapsTo, by rintro rfl; exact bijOn_empty f⟩ @[simp] theorem bijOn_empty_iff_right : BijOn f ∅ t ↔ t = ∅ := ⟨fun h ↦ by simpa using h.surjOn, by rintro rfl; exact bijOn_empty f⟩ @[simp] lemma bijOn_singleton : BijOn f {a} {b} ↔ f a = b := by simp [BijOn, eq_comm] #align set.bij_on_singleton Set.bijOn_singleton theorem BijOn.inter_mapsTo (h₁ : BijOn f s₁ t₁) (h₂ : MapsTo f s₂ t₂) (h₃ : s₁ ∩ f ⁻¹' t₂ ⊆ s₂) : BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := ⟨h₁.mapsTo.inter_inter h₂, h₁.injOn.mono inter_subset_left, fun _ hy => let ⟨x, hx, hxy⟩ := h₁.surjOn hy.1 ⟨x, ⟨hx, h₃ ⟨hx, hxy.symm.subst hy.2⟩⟩, hxy⟩⟩ #align set.bij_on.inter_maps_to Set.BijOn.inter_mapsTo theorem MapsTo.inter_bijOn (h₁ : MapsTo f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h₃ : s₂ ∩ f ⁻¹' t₁ ⊆ s₁) : BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := inter_comm s₂ s₁ ▸ inter_comm t₂ t₁ ▸ h₂.inter_mapsTo h₁ h₃ #align set.maps_to.inter_bij_on Set.MapsTo.inter_bijOn theorem BijOn.inter (h₁ : BijOn f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) : BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := ⟨h₁.mapsTo.inter_inter h₂.mapsTo, h₁.injOn.mono inter_subset_left, h₁.surjOn.inter_inter h₂.surjOn h⟩ #align set.bij_on.inter Set.BijOn.inter theorem BijOn.union (h₁ : BijOn f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) : BijOn f (s₁ ∪ s₂) (t₁ ∪ t₂) := ⟨h₁.mapsTo.union_union h₂.mapsTo, h, h₁.surjOn.union_union h₂.surjOn⟩ #align set.bij_on.union Set.BijOn.union theorem BijOn.subset_range (h : BijOn f s t) : t ⊆ range f := h.surjOn.subset_range #align set.bij_on.subset_range Set.BijOn.subset_range theorem InjOn.bijOn_image (h : InjOn f s) : BijOn f s (f '' s) := BijOn.mk (mapsTo_image f s) h (Subset.refl _) #align set.inj_on.bij_on_image Set.InjOn.bijOn_image theorem BijOn.congr (h₁ : BijOn f₁ s t) (h : EqOn f₁ f₂ s) : BijOn f₂ s t := BijOn.mk (h₁.mapsTo.congr h) (h₁.injOn.congr h) (h₁.surjOn.congr h) #align set.bij_on.congr Set.BijOn.congr theorem EqOn.bijOn_iff (H : EqOn f₁ f₂ s) : BijOn f₁ s t ↔ BijOn f₂ s t := ⟨fun h => h.congr H, fun h => h.congr H.symm⟩ #align set.eq_on.bij_on_iff Set.EqOn.bijOn_iff theorem BijOn.image_eq (h : BijOn f s t) : f '' s = t := h.surjOn.image_eq_of_mapsTo h.mapsTo #align set.bij_on.image_eq Set.BijOn.image_eq lemma BijOn.forall {p : β → Prop} (hf : BijOn f s t) : (∀ b ∈ t, p b) ↔ ∀ a ∈ s, p (f a) where mp h a ha := h _ $ hf.mapsTo ha mpr h b hb := by obtain ⟨a, ha, rfl⟩ := hf.surjOn hb; exact h _ ha lemma BijOn.exists {p : β → Prop} (hf : BijOn f s t) : (∃ b ∈ t, p b) ↔ ∃ a ∈ s, p (f a) where mp := by rintro ⟨b, hb, h⟩; obtain ⟨a, ha, rfl⟩ := hf.surjOn hb; exact ⟨a, ha, h⟩ mpr := by rintro ⟨a, ha, h⟩; exact ⟨f a, hf.mapsTo ha, h⟩ lemma _root_.Equiv.image_eq_iff_bijOn (e : α ≃ β) : e '' s = t ↔ BijOn e s t := ⟨fun h ↦ ⟨(mapsTo_image e s).mono_right h.subset, e.injective.injOn, h ▸ surjOn_image e s⟩, BijOn.image_eq⟩ lemma bijOn_id (s : Set α) : BijOn id s s := ⟨s.mapsTo_id, s.injOn_id, s.surjOn_id⟩ #align set.bij_on_id Set.bijOn_id theorem BijOn.comp (hg : BijOn g t p) (hf : BijOn f s t) : BijOn (g ∘ f) s p := BijOn.mk (hg.mapsTo.comp hf.mapsTo) (hg.injOn.comp hf.injOn hf.mapsTo) (hg.surjOn.comp hf.surjOn) #align set.bij_on.comp Set.BijOn.comp lemma BijOn.iterate {f : α → α} {s : Set α} (h : BijOn f s s) : ∀ n, BijOn f^[n] s s | 0 => s.bijOn_id | (n + 1) => (h.iterate n).comp h #align set.bij_on.iterate Set.BijOn.iterate lemma bijOn_of_subsingleton' [Subsingleton α] [Subsingleton β] (f : α → β) (h : s.Nonempty ↔ t.Nonempty) : BijOn f s t := ⟨mapsTo_of_subsingleton' _ h.1, injOn_of_subsingleton _ _, surjOn_of_subsingleton' _ h.2⟩ #align set.bij_on_of_subsingleton' Set.bijOn_of_subsingleton' lemma bijOn_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : BijOn f s s := bijOn_of_subsingleton' _ Iff.rfl #align set.bij_on_of_subsingleton Set.bijOn_of_subsingleton theorem BijOn.bijective (h : BijOn f s t) : Bijective (h.mapsTo.restrict f s t) := ⟨fun x y h' => Subtype.ext <| h.injOn x.2 y.2 <| Subtype.ext_iff.1 h', fun ⟨_, hy⟩ => let ⟨x, hx, hxy⟩ := h.surjOn hy ⟨⟨x, hx⟩, Subtype.eq hxy⟩⟩ #align set.bij_on.bijective Set.BijOn.bijective theorem bijective_iff_bijOn_univ : Bijective f ↔ BijOn f univ univ := Iff.intro (fun h => let ⟨inj, surj⟩ := h ⟨mapsTo_univ f _, inj.injOn, Iff.mp surjective_iff_surjOn_univ surj⟩) fun h => let ⟨_map, inj, surj⟩ := h ⟨Iff.mpr injective_iff_injOn_univ inj, Iff.mpr surjective_iff_surjOn_univ surj⟩ #align set.bijective_iff_bij_on_univ Set.bijective_iff_bijOn_univ alias ⟨_root_.Function.Bijective.bijOn_univ, _⟩ := bijective_iff_bijOn_univ #align function.bijective.bij_on_univ Function.Bijective.bijOn_univ theorem BijOn.compl (hst : BijOn f s t) (hf : Bijective f) : BijOn f sᶜ tᶜ := ⟨hst.surjOn.mapsTo_compl hf.1, hf.1.injOn, hst.mapsTo.surjOn_compl hf.2⟩ #align set.bij_on.compl Set.BijOn.compl theorem BijOn.subset_right {r : Set β} (hf : BijOn f s t) (hrt : r ⊆ t) : BijOn f (s ∩ f ⁻¹' r) r := by refine ⟨inter_subset_right, hf.injOn.mono inter_subset_left, fun x hx ↦ ?_⟩ obtain ⟨y, hy, rfl⟩ := hf.surjOn (hrt hx) exact ⟨y, ⟨hy, hx⟩, rfl⟩ theorem BijOn.subset_left {r : Set α} (hf : BijOn f s t) (hrs : r ⊆ s) : BijOn f r (f '' r) := (hf.injOn.mono hrs).bijOn_image end bijOn /-! ### left inverse -/ namespace LeftInvOn theorem eqOn (h : LeftInvOn f' f s) : EqOn (f' ∘ f) id s := h #align set.left_inv_on.eq_on Set.LeftInvOn.eqOn theorem eq (h : LeftInvOn f' f s) {x} (hx : x ∈ s) : f' (f x) = x := h hx #align set.left_inv_on.eq Set.LeftInvOn.eq theorem congr_left (h₁ : LeftInvOn f₁' f s) {t : Set β} (h₁' : MapsTo f s t) (heq : EqOn f₁' f₂' t) : LeftInvOn f₂' f s := fun _ hx => heq (h₁' hx) ▸ h₁ hx #align set.left_inv_on.congr_left Set.LeftInvOn.congr_left theorem congr_right (h₁ : LeftInvOn f₁' f₁ s) (heq : EqOn f₁ f₂ s) : LeftInvOn f₁' f₂ s := fun _ hx => heq hx ▸ h₁ hx #align set.left_inv_on.congr_right Set.LeftInvOn.congr_right theorem injOn (h : LeftInvOn f₁' f s) : InjOn f s := fun x₁ h₁ x₂ h₂ heq => calc x₁ = f₁' (f x₁) := Eq.symm <| h h₁ _ = f₁' (f x₂) := congr_arg f₁' heq _ = x₂ := h h₂ #align set.left_inv_on.inj_on Set.LeftInvOn.injOn theorem surjOn (h : LeftInvOn f' f s) (hf : MapsTo f s t) : SurjOn f' t s := fun x hx => ⟨f x, hf hx, h hx⟩ #align set.left_inv_on.surj_on Set.LeftInvOn.surjOn theorem mapsTo (h : LeftInvOn f' f s) (hf : SurjOn f s t) : MapsTo f' t s := fun y hy => by let ⟨x, hs, hx⟩ := hf hy rwa [← hx, h hs] #align set.left_inv_on.maps_to Set.LeftInvOn.mapsTo lemma _root_.Set.leftInvOn_id (s : Set α) : LeftInvOn id id s := fun _ _ ↦ rfl #align set.left_inv_on_id Set.leftInvOn_id theorem comp (hf' : LeftInvOn f' f s) (hg' : LeftInvOn g' g t) (hf : MapsTo f s t) : LeftInvOn (f' ∘ g') (g ∘ f) s := fun x h => calc (f' ∘ g') ((g ∘ f) x) = f' (f x) := congr_arg f' (hg' (hf h)) _ = x := hf' h #align set.left_inv_on.comp Set.LeftInvOn.comp theorem mono (hf : LeftInvOn f' f s) (ht : s₁ ⊆ s) : LeftInvOn f' f s₁ := fun _ hx => hf (ht hx) #align set.left_inv_on.mono Set.LeftInvOn.mono theorem image_inter' (hf : LeftInvOn f' f s) : f '' (s₁ ∩ s) = f' ⁻¹' s₁ ∩ f '' s := by apply Subset.antisymm · rintro _ ⟨x, ⟨h₁, h⟩, rfl⟩ exact ⟨by rwa [mem_preimage, hf h], mem_image_of_mem _ h⟩ · rintro _ ⟨h₁, ⟨x, h, rfl⟩⟩ exact mem_image_of_mem _ ⟨by rwa [← hf h], h⟩ #align set.left_inv_on.image_inter' Set.LeftInvOn.image_inter' theorem image_inter (hf : LeftInvOn f' f s) : f '' (s₁ ∩ s) = f' ⁻¹' (s₁ ∩ s) ∩ f '' s := by rw [hf.image_inter'] refine Subset.antisymm ?_ (inter_subset_inter_left _ (preimage_mono inter_subset_left)) rintro _ ⟨h₁, x, hx, rfl⟩; exact ⟨⟨h₁, by rwa [hf hx]⟩, mem_image_of_mem _ hx⟩ #align set.left_inv_on.image_inter Set.LeftInvOn.image_inter theorem image_image (hf : LeftInvOn f' f s) : f' '' (f '' s) = s := by rw [Set.image_image, image_congr hf, image_id'] #align set.left_inv_on.image_image Set.LeftInvOn.image_image theorem image_image' (hf : LeftInvOn f' f s) (hs : s₁ ⊆ s) : f' '' (f '' s₁) = s₁ := (hf.mono hs).image_image #align set.left_inv_on.image_image' Set.LeftInvOn.image_image' end LeftInvOn /-! ### Right inverse -/ section RightInvOn namespace RightInvOn theorem eqOn (h : RightInvOn f' f t) : EqOn (f ∘ f') id t := h #align set.right_inv_on.eq_on Set.RightInvOn.eqOn theorem eq (h : RightInvOn f' f t) {y} (hy : y ∈ t) : f (f' y) = y := h hy #align set.right_inv_on.eq Set.RightInvOn.eq theorem _root_.Set.LeftInvOn.rightInvOn_image (h : LeftInvOn f' f s) : RightInvOn f' f (f '' s) := fun _y ⟨_x, hx, heq⟩ => heq ▸ (congr_arg f <| h.eq hx) #align set.left_inv_on.right_inv_on_image Set.LeftInvOn.rightInvOn_image theorem congr_left (h₁ : RightInvOn f₁' f t) (heq : EqOn f₁' f₂' t) : RightInvOn f₂' f t := h₁.congr_right heq #align set.right_inv_on.congr_left Set.RightInvOn.congr_left theorem congr_right (h₁ : RightInvOn f' f₁ t) (hg : MapsTo f' t s) (heq : EqOn f₁ f₂ s) : RightInvOn f' f₂ t := LeftInvOn.congr_left h₁ hg heq #align set.right_inv_on.congr_right Set.RightInvOn.congr_right theorem surjOn (hf : RightInvOn f' f t) (hf' : MapsTo f' t s) : SurjOn f s t := LeftInvOn.surjOn hf hf' #align set.right_inv_on.surj_on Set.RightInvOn.surjOn theorem mapsTo (h : RightInvOn f' f t) (hf : SurjOn f' t s) : MapsTo f s t := LeftInvOn.mapsTo h hf #align set.right_inv_on.maps_to Set.RightInvOn.mapsTo lemma _root_.Set.rightInvOn_id (s : Set α) : RightInvOn id id s := fun _ _ ↦ rfl #align set.right_inv_on_id Set.rightInvOn_id theorem comp (hf : RightInvOn f' f t) (hg : RightInvOn g' g p) (g'pt : MapsTo g' p t) : RightInvOn (f' ∘ g') (g ∘ f) p := LeftInvOn.comp hg hf g'pt #align set.right_inv_on.comp Set.RightInvOn.comp theorem mono (hf : RightInvOn f' f t) (ht : t₁ ⊆ t) : RightInvOn f' f t₁ := LeftInvOn.mono hf ht #align set.right_inv_on.mono Set.RightInvOn.mono end RightInvOn theorem InjOn.rightInvOn_of_leftInvOn (hf : InjOn f s) (hf' : LeftInvOn f f' t) (h₁ : MapsTo f s t) (h₂ : MapsTo f' t s) : RightInvOn f f' s := fun _ h => hf (h₂ <| h₁ h) h (hf' (h₁ h)) #align set.inj_on.right_inv_on_of_left_inv_on Set.InjOn.rightInvOn_of_leftInvOn theorem eqOn_of_leftInvOn_of_rightInvOn (h₁ : LeftInvOn f₁' f s) (h₂ : RightInvOn f₂' f t) (h : MapsTo f₂' t s) : EqOn f₁' f₂' t := fun y hy => calc f₁' y = (f₁' ∘ f ∘ f₂') y := congr_arg f₁' (h₂ hy).symm _ = f₂' y := h₁ (h hy) #align set.eq_on_of_left_inv_on_of_right_inv_on Set.eqOn_of_leftInvOn_of_rightInvOn theorem SurjOn.leftInvOn_of_rightInvOn (hf : SurjOn f s t) (hf' : RightInvOn f f' s) : LeftInvOn f f' t := fun y hy => by let ⟨x, hx, heq⟩ := hf hy rw [← heq, hf' hx] #align set.surj_on.left_inv_on_of_right_inv_on Set.SurjOn.leftInvOn_of_rightInvOn end RightInvOn /-! ### Two-side inverses -/ namespace InvOn lemma _root_.Set.invOn_id (s : Set α) : InvOn id id s s := ⟨s.leftInvOn_id, s.rightInvOn_id⟩ #align set.inv_on_id Set.invOn_id lemma comp (hf : InvOn f' f s t) (hg : InvOn g' g t p) (fst : MapsTo f s t) (g'pt : MapsTo g' p t) : InvOn (f' ∘ g') (g ∘ f) s p := ⟨hf.1.comp hg.1 fst, hf.2.comp hg.2 g'pt⟩ #align set.inv_on.comp Set.InvOn.comp @[symm] theorem symm (h : InvOn f' f s t) : InvOn f f' t s := ⟨h.right, h.left⟩ #align set.inv_on.symm Set.InvOn.symm theorem mono (h : InvOn f' f s t) (hs : s₁ ⊆ s) (ht : t₁ ⊆ t) : InvOn f' f s₁ t₁ := ⟨h.1.mono hs, h.2.mono ht⟩ #align set.inv_on.mono Set.InvOn.mono /-- If functions `f'` and `f` are inverse on `s` and `t`, `f` maps `s` into `t`, and `f'` maps `t` into `s`, then `f` is a bijection between `s` and `t`. The `mapsTo` arguments can be deduced from `surjOn` statements using `LeftInvOn.mapsTo` and `RightInvOn.mapsTo`. -/ theorem bijOn (h : InvOn f' f s t) (hf : MapsTo f s t) (hf' : MapsTo f' t s) : BijOn f s t := ⟨hf, h.left.injOn, h.right.surjOn hf'⟩ #align set.inv_on.bij_on Set.InvOn.bijOn end InvOn end Set /-! ### `invFunOn` is a left/right inverse -/ namespace Function variable [Nonempty α] {s : Set α} {f : α → β} {a : α} {b : β} attribute [local instance] Classical.propDecidable /-- Construct the inverse for a function `f` on domain `s`. This function is a right inverse of `f` on `f '' s`. For a computable version, see `Function.Embedding.invOfMemRange`. -/ noncomputable def invFunOn (f : α → β) (s : Set α) (b : β) : α := if h : ∃ a, a ∈ s ∧ f a = b then Classical.choose h else Classical.choice ‹Nonempty α› #align function.inv_fun_on Function.invFunOn theorem invFunOn_pos (h : ∃ a ∈ s, f a = b) : invFunOn f s b ∈ s ∧ f (invFunOn f s b) = b := by rw [invFunOn, dif_pos h] exact Classical.choose_spec h #align function.inv_fun_on_pos Function.invFunOn_pos theorem invFunOn_mem (h : ∃ a ∈ s, f a = b) : invFunOn f s b ∈ s := (invFunOn_pos h).left #align function.inv_fun_on_mem Function.invFunOn_mem theorem invFunOn_eq (h : ∃ a ∈ s, f a = b) : f (invFunOn f s b) = b := (invFunOn_pos h).right #align function.inv_fun_on_eq Function.invFunOn_eq theorem invFunOn_neg (h : ¬∃ a ∈ s, f a = b) : invFunOn f s b = Classical.choice ‹Nonempty α› := by rw [invFunOn, dif_neg h] #align function.inv_fun_on_neg Function.invFunOn_neg @[simp] theorem invFunOn_apply_mem (h : a ∈ s) : invFunOn f s (f a) ∈ s := invFunOn_mem ⟨a, h, rfl⟩ #align function.inv_fun_on_apply_mem Function.invFunOn_apply_mem theorem invFunOn_apply_eq (h : a ∈ s) : f (invFunOn f s (f a)) = f a := invFunOn_eq ⟨a, h, rfl⟩ #align function.inv_fun_on_apply_eq Function.invFunOn_apply_eq end Function open Function namespace Set variable {s s₁ s₂ : Set α} {t : Set β} {f : α → β} theorem InjOn.leftInvOn_invFunOn [Nonempty α] (h : InjOn f s) : LeftInvOn (invFunOn f s) f s := fun _a ha => h (invFunOn_apply_mem ha) ha (invFunOn_apply_eq ha) #align set.inj_on.left_inv_on_inv_fun_on Set.InjOn.leftInvOn_invFunOn theorem InjOn.invFunOn_image [Nonempty α] (h : InjOn f s₂) (ht : s₁ ⊆ s₂) : invFunOn f s₂ '' (f '' s₁) = s₁ := h.leftInvOn_invFunOn.image_image' ht #align set.inj_on.inv_fun_on_image Set.InjOn.invFunOn_image theorem _root_.Function.leftInvOn_invFunOn_of_subset_image_image [Nonempty α] (h : s ⊆ (invFunOn f s) '' (f '' s)) : LeftInvOn (invFunOn f s) f s := fun x hx ↦ by obtain ⟨-, ⟨x, hx', rfl⟩, rfl⟩ := h hx rw [invFunOn_apply_eq (f := f) hx'] theorem injOn_iff_invFunOn_image_image_eq_self [Nonempty α] : InjOn f s ↔ (invFunOn f s) '' (f '' s) = s := ⟨fun h ↦ h.invFunOn_image Subset.rfl, fun h ↦ (Function.leftInvOn_invFunOn_of_subset_image_image h.symm.subset).injOn⟩ theorem _root_.Function.invFunOn_injOn_image [Nonempty α] (f : α → β) (s : Set α) : Set.InjOn (invFunOn f s) (f '' s) := by rintro _ ⟨x, hx, rfl⟩ _ ⟨x', hx', rfl⟩ he rw [← invFunOn_apply_eq (f := f) hx, he, invFunOn_apply_eq (f := f) hx'] theorem _root_.Function.invFunOn_image_image_subset [Nonempty α] (f : α → β) (s : Set α) : (invFunOn f s) '' (f '' s) ⊆ s := by rintro _ ⟨_, ⟨x,hx,rfl⟩, rfl⟩; exact invFunOn_apply_mem hx theorem SurjOn.rightInvOn_invFunOn [Nonempty α] (h : SurjOn f s t) : RightInvOn (invFunOn f s) f t := fun _y hy => invFunOn_eq <| h hy #align set.surj_on.right_inv_on_inv_fun_on Set.SurjOn.rightInvOn_invFunOn theorem BijOn.invOn_invFunOn [Nonempty α] (h : BijOn f s t) : InvOn (invFunOn f s) f s t := ⟨h.injOn.leftInvOn_invFunOn, h.surjOn.rightInvOn_invFunOn⟩ #align set.bij_on.inv_on_inv_fun_on Set.BijOn.invOn_invFunOn theorem SurjOn.invOn_invFunOn [Nonempty α] (h : SurjOn f s t) : InvOn (invFunOn f s) f (invFunOn f s '' t) t := by refine ⟨?_, h.rightInvOn_invFunOn⟩ rintro _ ⟨y, hy, rfl⟩ rw [h.rightInvOn_invFunOn hy] #align set.surj_on.inv_on_inv_fun_on Set.SurjOn.invOn_invFunOn theorem SurjOn.mapsTo_invFunOn [Nonempty α] (h : SurjOn f s t) : MapsTo (invFunOn f s) t s := fun _y hy => mem_preimage.2 <| invFunOn_mem <| h hy #align set.surj_on.maps_to_inv_fun_on Set.SurjOn.mapsTo_invFunOn /-- This lemma is a special case of `rightInvOn_invFunOn.image_image'`; it may make more sense to use the other lemma directly in an application. -/ theorem SurjOn.image_invFunOn_image_of_subset [Nonempty α] {r : Set β} (hf : SurjOn f s t) (hrt : r ⊆ t) : f '' (f.invFunOn s '' r) = r := hf.rightInvOn_invFunOn.image_image' hrt /-- This lemma is a special case of `rightInvOn_invFunOn.image_image`; it may make more sense to use the other lemma directly in an application. -/ theorem SurjOn.image_invFunOn_image [Nonempty α] (hf : SurjOn f s t) : f '' (f.invFunOn s '' t) = t := hf.rightInvOn_invFunOn.image_image theorem SurjOn.bijOn_subset [Nonempty α] (h : SurjOn f s t) : BijOn f (invFunOn f s '' t) t := by refine h.invOn_invFunOn.bijOn ?_ (mapsTo_image _ _) rintro _ ⟨y, hy, rfl⟩ rwa [h.rightInvOn_invFunOn hy] #align set.surj_on.bij_on_subset Set.SurjOn.bijOn_subset theorem surjOn_iff_exists_bijOn_subset : SurjOn f s t ↔ ∃ s' ⊆ s, BijOn f s' t := by constructor · rcases eq_empty_or_nonempty t with (rfl | ht) · exact fun _ => ⟨∅, empty_subset _, bijOn_empty f⟩ · intro h haveI : Nonempty α := ⟨Classical.choose (h.comap_nonempty ht)⟩ exact ⟨_, h.mapsTo_invFunOn.image_subset, h.bijOn_subset⟩ · rintro ⟨s', hs', hfs'⟩ exact hfs'.surjOn.mono hs' (Subset.refl _) #align set.surj_on_iff_exists_bij_on_subset Set.surjOn_iff_exists_bijOn_subset alias ⟨SurjOn.exists_bijOn_subset, _⟩ := Set.surjOn_iff_exists_bijOn_subset variable (f s) lemma exists_subset_bijOn : ∃ s' ⊆ s, BijOn f s' (f '' s) := surjOn_iff_exists_bijOn_subset.mp (surjOn_image f s) lemma exists_image_eq_and_injOn : ∃ u, f '' u = f '' s ∧ InjOn f u := let ⟨u, _, hfu⟩ := exists_subset_bijOn s f ⟨u, hfu.image_eq, hfu.injOn⟩ variable {f s} lemma exists_image_eq_injOn_of_subset_range (ht : t ⊆ range f) : ∃ s, f '' s = t ∧ InjOn f s := image_preimage_eq_of_subset ht ▸ exists_image_eq_and_injOn _ _ theorem preimage_invFun_of_mem [n : Nonempty α] {f : α → β} (hf : Injective f) {s : Set α} (h : Classical.choice n ∈ s) : invFun f ⁻¹' s = f '' s ∪ (range f)ᶜ := by ext x rcases em (x ∈ range f) with (⟨a, rfl⟩ | hx) · simp only [mem_preimage, mem_union, mem_compl_iff, mem_range_self, not_true, or_false, leftInverse_invFun hf _, hf.mem_set_image] · simp only [mem_preimage, invFun_neg hx, h, hx, mem_union, mem_compl_iff, not_false_iff, or_true] #align set.preimage_inv_fun_of_mem Set.preimage_invFun_of_mem theorem preimage_invFun_of_not_mem [n : Nonempty α] {f : α → β} (hf : Injective f) {s : Set α} (h : Classical.choice n ∉ s) : invFun f ⁻¹' s = f '' s := by ext x rcases em (x ∈ range f) with (⟨a, rfl⟩ | hx) · rw [mem_preimage, leftInverse_invFun hf, hf.mem_set_image] · have : x ∉ f '' s := fun h' => hx (image_subset_range _ _ h') simp only [mem_preimage, invFun_neg hx, h, this] #align set.preimage_inv_fun_of_not_mem Set.preimage_invFun_of_not_mem lemma BijOn.symm {g : β → α} (h : InvOn f g t s) (hf : BijOn f s t) : BijOn g t s := ⟨h.2.mapsTo hf.surjOn, h.1.injOn, h.2.surjOn hf.mapsTo⟩ #align set.bij_on.symm Set.BijOn.symm lemma bijOn_comm {g : β → α} (h : InvOn f g t s) : BijOn f s t ↔ BijOn g t s := ⟨BijOn.symm h, BijOn.symm h.symm⟩ #align set.bij_on_comm Set.bijOn_comm end Set /-! ### Monotone -/ namespace Monotone variable [Preorder α] [Preorder β] {f : α → β} protected theorem restrict (h : Monotone f) (s : Set α) : Monotone (s.restrict f) := fun _ _ hxy => h hxy #align monotone.restrict Monotone.restrict protected theorem codRestrict (h : Monotone f) {s : Set β} (hs : ∀ x, f x ∈ s) : Monotone (s.codRestrict f hs) := h #align monotone.cod_restrict Monotone.codRestrict protected theorem rangeFactorization (h : Monotone f) : Monotone (Set.rangeFactorization f) := h #align monotone.range_factorization Monotone.rangeFactorization end Monotone /-! ### Piecewise defined function -/ namespace Set variable {δ : α → Sort*} (s : Set α) (f g : ∀ i, δ i) @[simp]
Mathlib/Data/Set/Function.lean
1,531
1,533
theorem piecewise_empty [∀ i : α, Decidable (i ∈ (∅ : Set α))] : piecewise ∅ f g = g := by
ext i simp [piecewise]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Sébastien Gouëzel, Patrick Massot -/ import Mathlib.Topology.UniformSpace.Cauchy import Mathlib.Topology.UniformSpace.Separation import Mathlib.Topology.DenseEmbedding #align_import topology.uniform_space.uniform_embedding from "leanprover-community/mathlib"@"195fcd60ff2bfe392543bceb0ec2adcdb472db4c" /-! # Uniform embeddings of uniform spaces. Extension of uniform continuous functions. -/ open Filter Function Set Uniformity Topology section universe u v w variable {α : Type u} {β : Type v} {γ : Type w} [UniformSpace α] [UniformSpace β] [UniformSpace γ] /-! ### Uniform inducing maps -/ /-- A map `f : α → β` between uniform spaces is called *uniform inducing* if the uniformity filter on `α` is the pullback of the uniformity filter on `β` under `Prod.map f f`. If `α` is a separated space, then this implies that `f` is injective, hence it is a `UniformEmbedding`. -/ @[mk_iff] structure UniformInducing (f : α → β) : Prop where /-- The uniformity filter on the domain is the pullback of the uniformity filter on the codomain under `Prod.map f f`. -/ comap_uniformity : comap (fun x : α × α => (f x.1, f x.2)) (𝓤 β) = 𝓤 α #align uniform_inducing UniformInducing #align uniform_inducing_iff uniformInducing_iff lemma uniformInducing_iff_uniformSpace {f : α → β} : UniformInducing f ↔ ‹UniformSpace β›.comap f = ‹UniformSpace α› := by rw [uniformInducing_iff, UniformSpace.ext_iff, Filter.ext_iff] rfl protected alias ⟨UniformInducing.comap_uniformSpace, _⟩ := uniformInducing_iff_uniformSpace #align uniform_inducing.comap_uniform_space UniformInducing.comap_uniformSpace lemma uniformInducing_iff' {f : α → β} : UniformInducing f ↔ UniformContinuous f ∧ comap (Prod.map f f) (𝓤 β) ≤ 𝓤 α := by rw [uniformInducing_iff, UniformContinuous, tendsto_iff_comap, le_antisymm_iff, and_comm]; rfl #align uniform_inducing_iff' uniformInducing_iff' protected lemma Filter.HasBasis.uniformInducing_iff {ι ι'} {p : ι → Prop} {p' : ι' → Prop} {s s'} (h : (𝓤 α).HasBasis p s) (h' : (𝓤 β).HasBasis p' s') {f : α → β} : UniformInducing f ↔ (∀ i, p' i → ∃ j, p j ∧ ∀ x y, (x, y) ∈ s j → (f x, f y) ∈ s' i) ∧ (∀ j, p j → ∃ i, p' i ∧ ∀ x y, (f x, f y) ∈ s' i → (x, y) ∈ s j) := by simp [uniformInducing_iff', h.uniformContinuous_iff h', (h'.comap _).le_basis_iff h, subset_def] #align filter.has_basis.uniform_inducing_iff Filter.HasBasis.uniformInducing_iff theorem UniformInducing.mk' {f : α → β} (h : ∀ s, s ∈ 𝓤 α ↔ ∃ t ∈ 𝓤 β, ∀ x y : α, (f x, f y) ∈ t → (x, y) ∈ s) : UniformInducing f := ⟨by simp [eq_comm, Filter.ext_iff, subset_def, h]⟩ #align uniform_inducing.mk' UniformInducing.mk' theorem uniformInducing_id : UniformInducing (@id α) := ⟨by rw [← Prod.map_def, Prod.map_id, comap_id]⟩ #align uniform_inducing_id uniformInducing_id theorem UniformInducing.comp {g : β → γ} (hg : UniformInducing g) {f : α → β} (hf : UniformInducing f) : UniformInducing (g ∘ f) := ⟨by rw [← hf.1, ← hg.1, comap_comap]; rfl⟩ #align uniform_inducing.comp UniformInducing.comp theorem UniformInducing.of_comp_iff {g : β → γ} (hg : UniformInducing g) {f : α → β} : UniformInducing (g ∘ f) ↔ UniformInducing f := by refine ⟨fun h ↦ ?_, hg.comp⟩ rw [uniformInducing_iff, ← hg.comap_uniformity, comap_comap, ← h.comap_uniformity, Function.comp, Function.comp] theorem UniformInducing.basis_uniformity {f : α → β} (hf : UniformInducing f) {ι : Sort*} {p : ι → Prop} {s : ι → Set (β × β)} (H : (𝓤 β).HasBasis p s) : (𝓤 α).HasBasis p fun i => Prod.map f f ⁻¹' s i := hf.1 ▸ H.comap _ #align uniform_inducing.basis_uniformity UniformInducing.basis_uniformity theorem UniformInducing.cauchy_map_iff {f : α → β} (hf : UniformInducing f) {F : Filter α} : Cauchy (map f F) ↔ Cauchy F := by simp only [Cauchy, map_neBot_iff, prod_map_map_eq, map_le_iff_le_comap, ← hf.comap_uniformity] #align uniform_inducing.cauchy_map_iff UniformInducing.cauchy_map_iff theorem uniformInducing_of_compose {f : α → β} {g : β → γ} (hf : UniformContinuous f) (hg : UniformContinuous g) (hgf : UniformInducing (g ∘ f)) : UniformInducing f := by refine ⟨le_antisymm ?_ hf.le_comap⟩ rw [← hgf.1, ← Prod.map_def, ← Prod.map_def, ← Prod.map_comp_map f f g g, ← comap_comap] exact comap_mono hg.le_comap #align uniform_inducing_of_compose uniformInducing_of_compose theorem UniformInducing.uniformContinuous {f : α → β} (hf : UniformInducing f) : UniformContinuous f := (uniformInducing_iff'.1 hf).1 #align uniform_inducing.uniform_continuous UniformInducing.uniformContinuous theorem UniformInducing.uniformContinuous_iff {f : α → β} {g : β → γ} (hg : UniformInducing g) : UniformContinuous f ↔ UniformContinuous (g ∘ f) := by dsimp only [UniformContinuous, Tendsto] rw [← hg.comap_uniformity, ← map_le_iff_le_comap, Filter.map_map]; rfl #align uniform_inducing.uniform_continuous_iff UniformInducing.uniformContinuous_iff theorem UniformInducing.uniformContinuousOn_iff {f : α → β} {g : β → γ} {S : Set α} (hg : UniformInducing g) : UniformContinuousOn f S ↔ UniformContinuousOn (g ∘ f) S := by dsimp only [UniformContinuousOn, Tendsto] rw [← hg.comap_uniformity, ← map_le_iff_le_comap, Filter.map_map, comp_def, comp_def]
Mathlib/Topology/UniformSpace/UniformEmbedding.lean
116
118
theorem UniformInducing.inducing {f : α → β} (h : UniformInducing f) : Inducing f := by
obtain rfl := h.comap_uniformSpace exact inducing_induced f
/- Copyright (c) 2019 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Lu-Ming Zhang -/ import Mathlib.Data.Matrix.Invertible import Mathlib.LinearAlgebra.Matrix.Adjugate import Mathlib.LinearAlgebra.FiniteDimensional #align_import linear_algebra.matrix.nonsingular_inverse from "leanprover-community/mathlib"@"722b3b152ddd5e0cf21c0a29787c76596cb6b422" /-! # Nonsingular inverses In this file, we define an inverse for square matrices of invertible determinant. For matrices that are not square or not of full rank, there is a more general notion of pseudoinverses which we do not consider here. The definition of inverse used in this file is the adjugate divided by the determinant. We show that dividing the adjugate by `det A` (if possible), giving a matrix `A⁻¹` (`nonsing_inv`), will result in a multiplicative inverse to `A`. Note that there are at least three different inverses in mathlib: * `A⁻¹` (`Inv.inv`): alone, this satisfies no properties, although it is usually used in conjunction with `Group` or `GroupWithZero`. On matrices, this is defined to be zero when no inverse exists. * `⅟A` (`invOf`): this is only available in the presence of `[Invertible A]`, which guarantees an inverse exists. * `Ring.inverse A`: this is defined on any `MonoidWithZero`, and just like `⁻¹` on matrices, is defined to be zero when no inverse exists. We start by working with `Invertible`, and show the main results: * `Matrix.invertibleOfDetInvertible` * `Matrix.detInvertibleOfInvertible` * `Matrix.isUnit_iff_isUnit_det` * `Matrix.mul_eq_one_comm` After this we define `Matrix.inv` and show it matches `⅟A` and `Ring.inverse A`. The rest of the results in the file are then about `A⁻¹` ## References * https://en.wikipedia.org/wiki/Cramer's_rule#Finding_inverse_matrix ## Tags matrix inverse, cramer, cramer's rule, adjugate -/ namespace Matrix universe u u' v variable {l : Type*} {m : Type u} {n : Type u'} {α : Type v} open Matrix Equiv Equiv.Perm Finset /-! ### Matrices are `Invertible` iff their determinants are -/ section Invertible variable [Fintype n] [DecidableEq n] [CommRing α] variable (A : Matrix n n α) (B : Matrix n n α) /-- If `A.det` has a constructive inverse, produce one for `A`. -/ def invertibleOfDetInvertible [Invertible A.det] : Invertible A where invOf := ⅟ A.det • A.adjugate mul_invOf_self := by rw [mul_smul_comm, mul_adjugate, smul_smul, invOf_mul_self, one_smul] invOf_mul_self := by rw [smul_mul_assoc, adjugate_mul, smul_smul, invOf_mul_self, one_smul] #align matrix.invertible_of_det_invertible Matrix.invertibleOfDetInvertible
Mathlib/LinearAlgebra/Matrix/NonsingularInverse.lean
79
81
theorem invOf_eq [Invertible A.det] [Invertible A] : ⅟ A = ⅟ A.det • A.adjugate := by
letI := invertibleOfDetInvertible A convert (rfl : ⅟ A = _)
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl -/ import Mathlib.MeasureTheory.Constructions.BorelSpace.Order #align_import measure_theory.function.simple_func from "leanprover-community/mathlib"@"bf6a01357ff5684b1ebcd0f1a13be314fc82c0bf" /-! # Simple functions A function `f` from a measurable space to any type is called *simple*, if every preimage `f ⁻¹' {x}` is measurable, and the range is finite. In this file, we define simple functions and establish their basic properties; and we construct a sequence of simple functions approximating an arbitrary Borel measurable function `f : α → ℝ≥0∞`. The theorem `Measurable.ennreal_induction` shows that in order to prove something for an arbitrary measurable function into `ℝ≥0∞`, it is sufficient to show that the property holds for (multiples of) characteristic functions and is closed under addition and supremum of increasing sequences of functions. -/ noncomputable section open Set hiding restrict restrict_apply open Filter ENNReal open Function (support) open scoped Classical open Topology NNReal ENNReal MeasureTheory namespace MeasureTheory variable {α β γ δ : Type*} /-- A function `f` from a measurable space to any type is called *simple*, if every preimage `f ⁻¹' {x}` is measurable, and the range is finite. This structure bundles a function with these properties. -/ structure SimpleFunc.{u, v} (α : Type u) [MeasurableSpace α] (β : Type v) where toFun : α → β measurableSet_fiber' : ∀ x, MeasurableSet (toFun ⁻¹' {x}) finite_range' : (Set.range toFun).Finite #align measure_theory.simple_func MeasureTheory.SimpleFunc #align measure_theory.simple_func.to_fun MeasureTheory.SimpleFunc.toFun #align measure_theory.simple_func.measurable_set_fiber' MeasureTheory.SimpleFunc.measurableSet_fiber' #align measure_theory.simple_func.finite_range' MeasureTheory.SimpleFunc.finite_range' local infixr:25 " →ₛ " => SimpleFunc namespace SimpleFunc section Measurable variable [MeasurableSpace α] attribute [coe] toFun instance instCoeFun : CoeFun (α →ₛ β) fun _ => α → β := ⟨toFun⟩ #align measure_theory.simple_func.has_coe_to_fun MeasureTheory.SimpleFunc.instCoeFun theorem coe_injective ⦃f g : α →ₛ β⦄ (H : (f : α → β) = g) : f = g := by cases f; cases g; congr #align measure_theory.simple_func.coe_injective MeasureTheory.SimpleFunc.coe_injective @[ext] theorem ext {f g : α →ₛ β} (H : ∀ a, f a = g a) : f = g := coe_injective <| funext H #align measure_theory.simple_func.ext MeasureTheory.SimpleFunc.ext theorem finite_range (f : α →ₛ β) : (Set.range f).Finite := f.finite_range' #align measure_theory.simple_func.finite_range MeasureTheory.SimpleFunc.finite_range theorem measurableSet_fiber (f : α →ₛ β) (x : β) : MeasurableSet (f ⁻¹' {x}) := f.measurableSet_fiber' x #align measure_theory.simple_func.measurable_set_fiber MeasureTheory.SimpleFunc.measurableSet_fiber -- @[simp] -- Porting note (#10618): simp can prove this theorem apply_mk (f : α → β) (h h') (x : α) : SimpleFunc.mk f h h' x = f x := rfl #align measure_theory.simple_func.apply_mk MeasureTheory.SimpleFunc.apply_mk /-- Simple function defined on a finite type. -/ def ofFinite [Finite α] [MeasurableSingletonClass α] (f : α → β) : α →ₛ β where toFun := f measurableSet_fiber' x := (toFinite (f ⁻¹' {x})).measurableSet finite_range' := Set.finite_range f @[deprecated (since := "2024-02-05")] alias ofFintype := ofFinite /-- Simple function defined on the empty type. -/ def ofIsEmpty [IsEmpty α] : α →ₛ β := ofFinite isEmptyElim #align measure_theory.simple_func.of_is_empty MeasureTheory.SimpleFunc.ofIsEmpty /-- Range of a simple function `α →ₛ β` as a `Finset β`. -/ protected def range (f : α →ₛ β) : Finset β := f.finite_range.toFinset #align measure_theory.simple_func.range MeasureTheory.SimpleFunc.range @[simp] theorem mem_range {f : α →ₛ β} {b} : b ∈ f.range ↔ b ∈ range f := Finite.mem_toFinset _ #align measure_theory.simple_func.mem_range MeasureTheory.SimpleFunc.mem_range theorem mem_range_self (f : α →ₛ β) (x : α) : f x ∈ f.range := mem_range.2 ⟨x, rfl⟩ #align measure_theory.simple_func.mem_range_self MeasureTheory.SimpleFunc.mem_range_self @[simp] theorem coe_range (f : α →ₛ β) : (↑f.range : Set β) = Set.range f := f.finite_range.coe_toFinset #align measure_theory.simple_func.coe_range MeasureTheory.SimpleFunc.coe_range theorem mem_range_of_measure_ne_zero {f : α →ₛ β} {x : β} {μ : Measure α} (H : μ (f ⁻¹' {x}) ≠ 0) : x ∈ f.range := let ⟨a, ha⟩ := nonempty_of_measure_ne_zero H mem_range.2 ⟨a, ha⟩ #align measure_theory.simple_func.mem_range_of_measure_ne_zero MeasureTheory.SimpleFunc.mem_range_of_measure_ne_zero theorem forall_mem_range {f : α →ₛ β} {p : β → Prop} : (∀ y ∈ f.range, p y) ↔ ∀ x, p (f x) := by simp only [mem_range, Set.forall_mem_range] #align measure_theory.simple_func.forall_mem_range MeasureTheory.SimpleFunc.forall_mem_range theorem exists_range_iff {f : α →ₛ β} {p : β → Prop} : (∃ y ∈ f.range, p y) ↔ ∃ x, p (f x) := by simpa only [mem_range, exists_prop] using Set.exists_range_iff #align measure_theory.simple_func.exists_range_iff MeasureTheory.SimpleFunc.exists_range_iff theorem preimage_eq_empty_iff (f : α →ₛ β) (b : β) : f ⁻¹' {b} = ∅ ↔ b ∉ f.range := preimage_singleton_eq_empty.trans <| not_congr mem_range.symm #align measure_theory.simple_func.preimage_eq_empty_iff MeasureTheory.SimpleFunc.preimage_eq_empty_iff theorem exists_forall_le [Nonempty β] [Preorder β] [IsDirected β (· ≤ ·)] (f : α →ₛ β) : ∃ C, ∀ x, f x ≤ C := f.range.exists_le.imp fun _ => forall_mem_range.1 #align measure_theory.simple_func.exists_forall_le MeasureTheory.SimpleFunc.exists_forall_le /-- Constant function as a `SimpleFunc`. -/ def const (α) {β} [MeasurableSpace α] (b : β) : α →ₛ β := ⟨fun _ => b, fun _ => MeasurableSet.const _, finite_range_const⟩ #align measure_theory.simple_func.const MeasureTheory.SimpleFunc.const instance instInhabited [Inhabited β] : Inhabited (α →ₛ β) := ⟨const _ default⟩ #align measure_theory.simple_func.inhabited MeasureTheory.SimpleFunc.instInhabited theorem const_apply (a : α) (b : β) : (const α b) a = b := rfl #align measure_theory.simple_func.const_apply MeasureTheory.SimpleFunc.const_apply @[simp] theorem coe_const (b : β) : ⇑(const α b) = Function.const α b := rfl #align measure_theory.simple_func.coe_const MeasureTheory.SimpleFunc.coe_const @[simp] theorem range_const (α) [MeasurableSpace α] [Nonempty α] (b : β) : (const α b).range = {b} := Finset.coe_injective <| by simp (config := { unfoldPartialApp := true }) [Function.const] #align measure_theory.simple_func.range_const MeasureTheory.SimpleFunc.range_const theorem range_const_subset (α) [MeasurableSpace α] (b : β) : (const α b).range ⊆ {b} := Finset.coe_subset.1 <| by simp #align measure_theory.simple_func.range_const_subset MeasureTheory.SimpleFunc.range_const_subset theorem simpleFunc_bot {α} (f : @SimpleFunc α ⊥ β) [Nonempty β] : ∃ c, ∀ x, f x = c := by have hf_meas := @SimpleFunc.measurableSet_fiber α _ ⊥ f simp_rw [MeasurableSpace.measurableSet_bot_iff] at hf_meas exact (exists_eq_const_of_preimage_singleton hf_meas).imp fun c hc ↦ congr_fun hc #align measure_theory.simple_func.simple_func_bot MeasureTheory.SimpleFunc.simpleFunc_bot theorem simpleFunc_bot' {α} [Nonempty β] (f : @SimpleFunc α ⊥ β) : ∃ c, f = @SimpleFunc.const α _ ⊥ c := letI : MeasurableSpace α := ⊥; (simpleFunc_bot f).imp fun _ ↦ ext #align measure_theory.simple_func.simple_func_bot' MeasureTheory.SimpleFunc.simpleFunc_bot' theorem measurableSet_cut (r : α → β → Prop) (f : α →ₛ β) (h : ∀ b, MeasurableSet { a | r a b }) : MeasurableSet { a | r a (f a) } := by have : { a | r a (f a) } = ⋃ b ∈ range f, { a | r a b } ∩ f ⁻¹' {b} := by ext a suffices r a (f a) ↔ ∃ i, r a (f i) ∧ f a = f i by simpa exact ⟨fun h => ⟨a, ⟨h, rfl⟩⟩, fun ⟨a', ⟨h', e⟩⟩ => e.symm ▸ h'⟩ rw [this] exact MeasurableSet.biUnion f.finite_range.countable fun b _ => MeasurableSet.inter (h b) (f.measurableSet_fiber _) #align measure_theory.simple_func.measurable_set_cut MeasureTheory.SimpleFunc.measurableSet_cut @[measurability] theorem measurableSet_preimage (f : α →ₛ β) (s) : MeasurableSet (f ⁻¹' s) := measurableSet_cut (fun _ b => b ∈ s) f fun b => MeasurableSet.const (b ∈ s) #align measure_theory.simple_func.measurable_set_preimage MeasureTheory.SimpleFunc.measurableSet_preimage /-- A simple function is measurable -/ @[measurability] protected theorem measurable [MeasurableSpace β] (f : α →ₛ β) : Measurable f := fun s _ => measurableSet_preimage f s #align measure_theory.simple_func.measurable MeasureTheory.SimpleFunc.measurable @[measurability] protected theorem aemeasurable [MeasurableSpace β] {μ : Measure α} (f : α →ₛ β) : AEMeasurable f μ := f.measurable.aemeasurable #align measure_theory.simple_func.ae_measurable MeasureTheory.SimpleFunc.aemeasurable protected theorem sum_measure_preimage_singleton (f : α →ₛ β) {μ : Measure α} (s : Finset β) : (∑ y ∈ s, μ (f ⁻¹' {y})) = μ (f ⁻¹' ↑s) := sum_measure_preimage_singleton _ fun _ _ => f.measurableSet_fiber _ #align measure_theory.simple_func.sum_measure_preimage_singleton MeasureTheory.SimpleFunc.sum_measure_preimage_singleton theorem sum_range_measure_preimage_singleton (f : α →ₛ β) (μ : Measure α) : (∑ y ∈ f.range, μ (f ⁻¹' {y})) = μ univ := by rw [f.sum_measure_preimage_singleton, coe_range, preimage_range] #align measure_theory.simple_func.sum_range_measure_preimage_singleton MeasureTheory.SimpleFunc.sum_range_measure_preimage_singleton /-- If-then-else as a `SimpleFunc`. -/ def piecewise (s : Set α) (hs : MeasurableSet s) (f g : α →ₛ β) : α →ₛ β := ⟨s.piecewise f g, fun _ => letI : MeasurableSpace β := ⊤ f.measurable.piecewise hs g.measurable trivial, (f.finite_range.union g.finite_range).subset range_ite_subset⟩ #align measure_theory.simple_func.piecewise MeasureTheory.SimpleFunc.piecewise @[simp] theorem coe_piecewise {s : Set α} (hs : MeasurableSet s) (f g : α →ₛ β) : ⇑(piecewise s hs f g) = s.piecewise f g := rfl #align measure_theory.simple_func.coe_piecewise MeasureTheory.SimpleFunc.coe_piecewise theorem piecewise_apply {s : Set α} (hs : MeasurableSet s) (f g : α →ₛ β) (a) : piecewise s hs f g a = if a ∈ s then f a else g a := rfl #align measure_theory.simple_func.piecewise_apply MeasureTheory.SimpleFunc.piecewise_apply @[simp] theorem piecewise_compl {s : Set α} (hs : MeasurableSet sᶜ) (f g : α →ₛ β) : piecewise sᶜ hs f g = piecewise s hs.of_compl g f := coe_injective <| by set_option tactic.skipAssignedInstances false in simp [hs]; convert Set.piecewise_compl s f g #align measure_theory.simple_func.piecewise_compl MeasureTheory.SimpleFunc.piecewise_compl @[simp] theorem piecewise_univ (f g : α →ₛ β) : piecewise univ MeasurableSet.univ f g = f := coe_injective <| by set_option tactic.skipAssignedInstances false in simp; convert Set.piecewise_univ f g #align measure_theory.simple_func.piecewise_univ MeasureTheory.SimpleFunc.piecewise_univ @[simp] theorem piecewise_empty (f g : α →ₛ β) : piecewise ∅ MeasurableSet.empty f g = g := coe_injective <| by set_option tactic.skipAssignedInstances false in simp; convert Set.piecewise_empty f g #align measure_theory.simple_func.piecewise_empty MeasureTheory.SimpleFunc.piecewise_empty @[simp] theorem piecewise_same (f : α →ₛ β) {s : Set α} (hs : MeasurableSet s) : piecewise s hs f f = f := coe_injective <| Set.piecewise_same _ _ theorem support_indicator [Zero β] {s : Set α} (hs : MeasurableSet s) (f : α →ₛ β) : Function.support (f.piecewise s hs (SimpleFunc.const α 0)) = s ∩ Function.support f := Set.support_indicator #align measure_theory.simple_func.support_indicator MeasureTheory.SimpleFunc.support_indicator theorem range_indicator {s : Set α} (hs : MeasurableSet s) (hs_nonempty : s.Nonempty) (hs_ne_univ : s ≠ univ) (x y : β) : (piecewise s hs (const α x) (const α y)).range = {x, y} := by simp only [← Finset.coe_inj, coe_range, coe_piecewise, range_piecewise, coe_const, Finset.coe_insert, Finset.coe_singleton, hs_nonempty.image_const, (nonempty_compl.2 hs_ne_univ).image_const, singleton_union, Function.const] #align measure_theory.simple_func.range_indicator MeasureTheory.SimpleFunc.range_indicator theorem measurable_bind [MeasurableSpace γ] (f : α →ₛ β) (g : β → α → γ) (hg : ∀ b, Measurable (g b)) : Measurable fun a => g (f a) a := fun s hs => f.measurableSet_cut (fun a b => g b a ∈ s) fun b => hg b hs #align measure_theory.simple_func.measurable_bind MeasureTheory.SimpleFunc.measurable_bind /-- If `f : α →ₛ β` is a simple function and `g : β → α →ₛ γ` is a family of simple functions, then `f.bind g` binds the first argument of `g` to `f`. In other words, `f.bind g a = g (f a) a`. -/ def bind (f : α →ₛ β) (g : β → α →ₛ γ) : α →ₛ γ := ⟨fun a => g (f a) a, fun c => f.measurableSet_cut (fun a b => g b a = c) fun b => (g b).measurableSet_preimage {c}, (f.finite_range.biUnion fun b _ => (g b).finite_range).subset <| by rintro _ ⟨a, rfl⟩; simp⟩ #align measure_theory.simple_func.bind MeasureTheory.SimpleFunc.bind @[simp] theorem bind_apply (f : α →ₛ β) (g : β → α →ₛ γ) (a) : f.bind g a = g (f a) a := rfl #align measure_theory.simple_func.bind_apply MeasureTheory.SimpleFunc.bind_apply /-- Given a function `g : β → γ` and a simple function `f : α →ₛ β`, `f.map g` return the simple function `g ∘ f : α →ₛ γ` -/ def map (g : β → γ) (f : α →ₛ β) : α →ₛ γ := bind f (const α ∘ g) #align measure_theory.simple_func.map MeasureTheory.SimpleFunc.map theorem map_apply (g : β → γ) (f : α →ₛ β) (a) : f.map g a = g (f a) := rfl #align measure_theory.simple_func.map_apply MeasureTheory.SimpleFunc.map_apply theorem map_map (g : β → γ) (h : γ → δ) (f : α →ₛ β) : (f.map g).map h = f.map (h ∘ g) := rfl #align measure_theory.simple_func.map_map MeasureTheory.SimpleFunc.map_map @[simp] theorem coe_map (g : β → γ) (f : α →ₛ β) : (f.map g : α → γ) = g ∘ f := rfl #align measure_theory.simple_func.coe_map MeasureTheory.SimpleFunc.coe_map @[simp] theorem range_map [DecidableEq γ] (g : β → γ) (f : α →ₛ β) : (f.map g).range = f.range.image g := Finset.coe_injective <| by simp only [coe_range, coe_map, Finset.coe_image, range_comp] #align measure_theory.simple_func.range_map MeasureTheory.SimpleFunc.range_map @[simp] theorem map_const (g : β → γ) (b : β) : (const α b).map g = const α (g b) := rfl #align measure_theory.simple_func.map_const MeasureTheory.SimpleFunc.map_const theorem map_preimage (f : α →ₛ β) (g : β → γ) (s : Set γ) : f.map g ⁻¹' s = f ⁻¹' ↑(f.range.filter fun b => g b ∈ s) := by simp only [coe_range, sep_mem_eq, coe_map, Finset.coe_filter, ← mem_preimage, inter_comm, preimage_inter_range, ← Finset.mem_coe] exact preimage_comp #align measure_theory.simple_func.map_preimage MeasureTheory.SimpleFunc.map_preimage theorem map_preimage_singleton (f : α →ₛ β) (g : β → γ) (c : γ) : f.map g ⁻¹' {c} = f ⁻¹' ↑(f.range.filter fun b => g b = c) := map_preimage _ _ _ #align measure_theory.simple_func.map_preimage_singleton MeasureTheory.SimpleFunc.map_preimage_singleton /-- Composition of a `SimpleFun` and a measurable function is a `SimpleFunc`. -/ def comp [MeasurableSpace β] (f : β →ₛ γ) (g : α → β) (hgm : Measurable g) : α →ₛ γ where toFun := f ∘ g finite_range' := f.finite_range.subset <| Set.range_comp_subset_range _ _ measurableSet_fiber' z := hgm (f.measurableSet_fiber z) #align measure_theory.simple_func.comp MeasureTheory.SimpleFunc.comp @[simp] theorem coe_comp [MeasurableSpace β] (f : β →ₛ γ) {g : α → β} (hgm : Measurable g) : ⇑(f.comp g hgm) = f ∘ g := rfl #align measure_theory.simple_func.coe_comp MeasureTheory.SimpleFunc.coe_comp theorem range_comp_subset_range [MeasurableSpace β] (f : β →ₛ γ) {g : α → β} (hgm : Measurable g) : (f.comp g hgm).range ⊆ f.range := Finset.coe_subset.1 <| by simp only [coe_range, coe_comp, Set.range_comp_subset_range] #align measure_theory.simple_func.range_comp_subset_range MeasureTheory.SimpleFunc.range_comp_subset_range /-- Extend a `SimpleFunc` along a measurable embedding: `f₁.extend g hg f₂` is the function `F : β →ₛ γ` such that `F ∘ g = f₁` and `F y = f₂ y` whenever `y ∉ range g`. -/ def extend [MeasurableSpace β] (f₁ : α →ₛ γ) (g : α → β) (hg : MeasurableEmbedding g) (f₂ : β →ₛ γ) : β →ₛ γ where toFun := Function.extend g f₁ f₂ finite_range' := (f₁.finite_range.union <| f₂.finite_range.subset (image_subset_range _ _)).subset (range_extend_subset _ _ _) measurableSet_fiber' := by letI : MeasurableSpace γ := ⊤; haveI : MeasurableSingletonClass γ := ⟨fun _ => trivial⟩ exact fun x => hg.measurable_extend f₁.measurable f₂.measurable (measurableSet_singleton _) #align measure_theory.simple_func.extend MeasureTheory.SimpleFunc.extend @[simp] theorem extend_apply [MeasurableSpace β] (f₁ : α →ₛ γ) {g : α → β} (hg : MeasurableEmbedding g) (f₂ : β →ₛ γ) (x : α) : (f₁.extend g hg f₂) (g x) = f₁ x := hg.injective.extend_apply _ _ _ #align measure_theory.simple_func.extend_apply MeasureTheory.SimpleFunc.extend_apply @[simp] theorem extend_apply' [MeasurableSpace β] (f₁ : α →ₛ γ) {g : α → β} (hg : MeasurableEmbedding g) (f₂ : β →ₛ γ) {y : β} (h : ¬∃ x, g x = y) : (f₁.extend g hg f₂) y = f₂ y := Function.extend_apply' _ _ _ h #align measure_theory.simple_func.extend_apply' MeasureTheory.SimpleFunc.extend_apply' @[simp] theorem extend_comp_eq' [MeasurableSpace β] (f₁ : α →ₛ γ) {g : α → β} (hg : MeasurableEmbedding g) (f₂ : β →ₛ γ) : f₁.extend g hg f₂ ∘ g = f₁ := funext fun _ => extend_apply _ _ _ _ #align measure_theory.simple_func.extend_comp_eq' MeasureTheory.SimpleFunc.extend_comp_eq' @[simp] theorem extend_comp_eq [MeasurableSpace β] (f₁ : α →ₛ γ) {g : α → β} (hg : MeasurableEmbedding g) (f₂ : β →ₛ γ) : (f₁.extend g hg f₂).comp g hg.measurable = f₁ := coe_injective <| extend_comp_eq' _ hg _ #align measure_theory.simple_func.extend_comp_eq MeasureTheory.SimpleFunc.extend_comp_eq /-- If `f` is a simple function taking values in `β → γ` and `g` is another simple function with the same domain and codomain `β`, then `f.seq g = f a (g a)`. -/ def seq (f : α →ₛ β → γ) (g : α →ₛ β) : α →ₛ γ := f.bind fun f => g.map f #align measure_theory.simple_func.seq MeasureTheory.SimpleFunc.seq @[simp] theorem seq_apply (f : α →ₛ β → γ) (g : α →ₛ β) (a : α) : f.seq g a = f a (g a) := rfl #align measure_theory.simple_func.seq_apply MeasureTheory.SimpleFunc.seq_apply /-- Combine two simple functions `f : α →ₛ β` and `g : α →ₛ β` into `fun a => (f a, g a)`. -/ def pair (f : α →ₛ β) (g : α →ₛ γ) : α →ₛ β × γ := (f.map Prod.mk).seq g #align measure_theory.simple_func.pair MeasureTheory.SimpleFunc.pair @[simp] theorem pair_apply (f : α →ₛ β) (g : α →ₛ γ) (a) : pair f g a = (f a, g a) := rfl #align measure_theory.simple_func.pair_apply MeasureTheory.SimpleFunc.pair_apply theorem pair_preimage (f : α →ₛ β) (g : α →ₛ γ) (s : Set β) (t : Set γ) : pair f g ⁻¹' s ×ˢ t = f ⁻¹' s ∩ g ⁻¹' t := rfl #align measure_theory.simple_func.pair_preimage MeasureTheory.SimpleFunc.pair_preimage -- A special form of `pair_preimage` theorem pair_preimage_singleton (f : α →ₛ β) (g : α →ₛ γ) (b : β) (c : γ) : pair f g ⁻¹' {(b, c)} = f ⁻¹' {b} ∩ g ⁻¹' {c} := by rw [← singleton_prod_singleton] exact pair_preimage _ _ _ _ #align measure_theory.simple_func.pair_preimage_singleton MeasureTheory.SimpleFunc.pair_preimage_singleton theorem bind_const (f : α →ₛ β) : f.bind (const α) = f := by ext; simp #align measure_theory.simple_func.bind_const MeasureTheory.SimpleFunc.bind_const @[to_additive] instance instOne [One β] : One (α →ₛ β) := ⟨const α 1⟩ #align measure_theory.simple_func.has_one MeasureTheory.SimpleFunc.instOne #align measure_theory.simple_func.has_zero MeasureTheory.SimpleFunc.instZero @[to_additive] instance instMul [Mul β] : Mul (α →ₛ β) := ⟨fun f g => (f.map (· * ·)).seq g⟩ #align measure_theory.simple_func.has_mul MeasureTheory.SimpleFunc.instMul #align measure_theory.simple_func.has_add MeasureTheory.SimpleFunc.instAdd @[to_additive] instance instDiv [Div β] : Div (α →ₛ β) := ⟨fun f g => (f.map (· / ·)).seq g⟩ #align measure_theory.simple_func.has_div MeasureTheory.SimpleFunc.instDiv #align measure_theory.simple_func.has_sub MeasureTheory.SimpleFunc.instSub @[to_additive] instance instInv [Inv β] : Inv (α →ₛ β) := ⟨fun f => f.map Inv.inv⟩ #align measure_theory.simple_func.has_inv MeasureTheory.SimpleFunc.instInv #align measure_theory.simple_func.has_neg MeasureTheory.SimpleFunc.instNeg instance instSup [Sup β] : Sup (α →ₛ β) := ⟨fun f g => (f.map (· ⊔ ·)).seq g⟩ #align measure_theory.simple_func.has_sup MeasureTheory.SimpleFunc.instSup instance instInf [Inf β] : Inf (α →ₛ β) := ⟨fun f g => (f.map (· ⊓ ·)).seq g⟩ #align measure_theory.simple_func.has_inf MeasureTheory.SimpleFunc.instInf instance instLE [LE β] : LE (α →ₛ β) := ⟨fun f g => ∀ a, f a ≤ g a⟩ #align measure_theory.simple_func.has_le MeasureTheory.SimpleFunc.instLE @[to_additive (attr := simp)] theorem const_one [One β] : const α (1 : β) = 1 := rfl #align measure_theory.simple_func.const_one MeasureTheory.SimpleFunc.const_one #align measure_theory.simple_func.const_zero MeasureTheory.SimpleFunc.const_zero @[to_additive (attr := simp, norm_cast)] theorem coe_one [One β] : ⇑(1 : α →ₛ β) = 1 := rfl #align measure_theory.simple_func.coe_one MeasureTheory.SimpleFunc.coe_one #align measure_theory.simple_func.coe_zero MeasureTheory.SimpleFunc.coe_zero @[to_additive (attr := simp, norm_cast)] theorem coe_mul [Mul β] (f g : α →ₛ β) : ⇑(f * g) = ⇑f * ⇑g := rfl #align measure_theory.simple_func.coe_mul MeasureTheory.SimpleFunc.coe_mul #align measure_theory.simple_func.coe_add MeasureTheory.SimpleFunc.coe_add @[to_additive (attr := simp, norm_cast)] theorem coe_inv [Inv β] (f : α →ₛ β) : ⇑(f⁻¹) = (⇑f)⁻¹ := rfl #align measure_theory.simple_func.coe_inv MeasureTheory.SimpleFunc.coe_inv #align measure_theory.simple_func.coe_neg MeasureTheory.SimpleFunc.coe_neg @[to_additive (attr := simp, norm_cast)] theorem coe_div [Div β] (f g : α →ₛ β) : ⇑(f / g) = ⇑f / ⇑g := rfl #align measure_theory.simple_func.coe_div MeasureTheory.SimpleFunc.coe_div #align measure_theory.simple_func.coe_sub MeasureTheory.SimpleFunc.coe_sub @[simp, norm_cast] theorem coe_le [Preorder β] {f g : α →ₛ β} : (f : α → β) ≤ g ↔ f ≤ g := Iff.rfl #align measure_theory.simple_func.coe_le MeasureTheory.SimpleFunc.coe_le @[simp, norm_cast] theorem coe_sup [Sup β] (f g : α →ₛ β) : ⇑(f ⊔ g) = ⇑f ⊔ ⇑g := rfl #align measure_theory.simple_func.coe_sup MeasureTheory.SimpleFunc.coe_sup @[simp, norm_cast] theorem coe_inf [Inf β] (f g : α →ₛ β) : ⇑(f ⊓ g) = ⇑f ⊓ ⇑g := rfl #align measure_theory.simple_func.coe_inf MeasureTheory.SimpleFunc.coe_inf @[to_additive] theorem mul_apply [Mul β] (f g : α →ₛ β) (a : α) : (f * g) a = f a * g a := rfl #align measure_theory.simple_func.mul_apply MeasureTheory.SimpleFunc.mul_apply #align measure_theory.simple_func.add_apply MeasureTheory.SimpleFunc.add_apply @[to_additive] theorem div_apply [Div β] (f g : α →ₛ β) (x : α) : (f / g) x = f x / g x := rfl #align measure_theory.simple_func.div_apply MeasureTheory.SimpleFunc.div_apply #align measure_theory.simple_func.sub_apply MeasureTheory.SimpleFunc.sub_apply @[to_additive] theorem inv_apply [Inv β] (f : α →ₛ β) (x : α) : f⁻¹ x = (f x)⁻¹ := rfl #align measure_theory.simple_func.inv_apply MeasureTheory.SimpleFunc.inv_apply #align measure_theory.simple_func.neg_apply MeasureTheory.SimpleFunc.neg_apply theorem sup_apply [Sup β] (f g : α →ₛ β) (a : α) : (f ⊔ g) a = f a ⊔ g a := rfl #align measure_theory.simple_func.sup_apply MeasureTheory.SimpleFunc.sup_apply theorem inf_apply [Inf β] (f g : α →ₛ β) (a : α) : (f ⊓ g) a = f a ⊓ g a := rfl #align measure_theory.simple_func.inf_apply MeasureTheory.SimpleFunc.inf_apply @[to_additive (attr := simp)] theorem range_one [Nonempty α] [One β] : (1 : α →ₛ β).range = {1} := Finset.ext fun x => by simp [eq_comm] #align measure_theory.simple_func.range_one MeasureTheory.SimpleFunc.range_one #align measure_theory.simple_func.range_zero MeasureTheory.SimpleFunc.range_zero @[simp] theorem range_eq_empty_of_isEmpty {β} [hα : IsEmpty α] (f : α →ₛ β) : f.range = ∅ := by rw [← Finset.not_nonempty_iff_eq_empty] by_contra h obtain ⟨y, hy_mem⟩ := h rw [SimpleFunc.mem_range, Set.mem_range] at hy_mem obtain ⟨x, hxy⟩ := hy_mem rw [isEmpty_iff] at hα exact hα x #align measure_theory.simple_func.range_eq_empty_of_is_empty MeasureTheory.SimpleFunc.range_eq_empty_of_isEmpty theorem eq_zero_of_mem_range_zero [Zero β] : ∀ {y : β}, y ∈ (0 : α →ₛ β).range → y = 0 := @(forall_mem_range.2 fun _ => rfl) #align measure_theory.simple_func.eq_zero_of_mem_range_zero MeasureTheory.SimpleFunc.eq_zero_of_mem_range_zero @[to_additive] theorem mul_eq_map₂ [Mul β] (f g : α →ₛ β) : f * g = (pair f g).map fun p : β × β => p.1 * p.2 := rfl #align measure_theory.simple_func.mul_eq_map₂ MeasureTheory.SimpleFunc.mul_eq_map₂ #align measure_theory.simple_func.add_eq_map₂ MeasureTheory.SimpleFunc.add_eq_map₂ theorem sup_eq_map₂ [Sup β] (f g : α →ₛ β) : f ⊔ g = (pair f g).map fun p : β × β => p.1 ⊔ p.2 := rfl #align measure_theory.simple_func.sup_eq_map₂ MeasureTheory.SimpleFunc.sup_eq_map₂ @[to_additive] theorem const_mul_eq_map [Mul β] (f : α →ₛ β) (b : β) : const α b * f = f.map fun a => b * a := rfl #align measure_theory.simple_func.const_mul_eq_map MeasureTheory.SimpleFunc.const_mul_eq_map #align measure_theory.simple_func.const_add_eq_map MeasureTheory.SimpleFunc.const_add_eq_map @[to_additive] theorem map_mul [Mul β] [Mul γ] {g : β → γ} (hg : ∀ x y, g (x * y) = g x * g y) (f₁ f₂ : α →ₛ β) : (f₁ * f₂).map g = f₁.map g * f₂.map g := ext fun _ => hg _ _ #align measure_theory.simple_func.map_mul MeasureTheory.SimpleFunc.map_mul #align measure_theory.simple_func.map_add MeasureTheory.SimpleFunc.map_add variable {K : Type*} @[to_additive] instance instSMul [SMul K β] : SMul K (α →ₛ β) := ⟨fun k f => f.map (k • ·)⟩ #align measure_theory.simple_func.has_smul MeasureTheory.SimpleFunc.instSMul @[to_additive (attr := simp)] theorem coe_smul [SMul K β] (c : K) (f : α →ₛ β) : ⇑(c • f) = c • ⇑f := rfl #align measure_theory.simple_func.coe_smul MeasureTheory.SimpleFunc.coe_smul @[to_additive (attr := simp)] theorem smul_apply [SMul K β] (k : K) (f : α →ₛ β) (a : α) : (k • f) a = k • f a := rfl #align measure_theory.simple_func.smul_apply MeasureTheory.SimpleFunc.smul_apply instance hasNatSMul [AddMonoid β] : SMul ℕ (α →ₛ β) := inferInstance @[to_additive existing hasNatSMul] instance hasNatPow [Monoid β] : Pow (α →ₛ β) ℕ := ⟨fun f n => f.map (· ^ n)⟩ #align measure_theory.simple_func.has_nat_pow MeasureTheory.SimpleFunc.hasNatPow @[simp] theorem coe_pow [Monoid β] (f : α →ₛ β) (n : ℕ) : ⇑(f ^ n) = (⇑f) ^ n := rfl #align measure_theory.simple_func.coe_pow MeasureTheory.SimpleFunc.coe_pow theorem pow_apply [Monoid β] (n : ℕ) (f : α →ₛ β) (a : α) : (f ^ n) a = f a ^ n := rfl #align measure_theory.simple_func.pow_apply MeasureTheory.SimpleFunc.pow_apply instance hasIntPow [DivInvMonoid β] : Pow (α →ₛ β) ℤ := ⟨fun f n => f.map (· ^ n)⟩ #align measure_theory.simple_func.has_int_pow MeasureTheory.SimpleFunc.hasIntPow @[simp] theorem coe_zpow [DivInvMonoid β] (f : α →ₛ β) (z : ℤ) : ⇑(f ^ z) = (⇑f) ^ z := rfl #align measure_theory.simple_func.coe_zpow MeasureTheory.SimpleFunc.coe_zpow theorem zpow_apply [DivInvMonoid β] (z : ℤ) (f : α →ₛ β) (a : α) : (f ^ z) a = f a ^ z := rfl #align measure_theory.simple_func.zpow_apply MeasureTheory.SimpleFunc.zpow_apply -- TODO: work out how to generate these instances with `to_additive`, which gets confused by the -- argument order swap between `coe_smul` and `coe_pow`. section Additive instance instAddMonoid [AddMonoid β] : AddMonoid (α →ₛ β) := Function.Injective.addMonoid (fun f => show α → β from f) coe_injective coe_zero coe_add fun _ _ => coe_smul _ _ #align measure_theory.simple_func.add_monoid MeasureTheory.SimpleFunc.instAddMonoid instance instAddCommMonoid [AddCommMonoid β] : AddCommMonoid (α →ₛ β) := Function.Injective.addCommMonoid (fun f => show α → β from f) coe_injective coe_zero coe_add fun _ _ => coe_smul _ _ #align measure_theory.simple_func.add_comm_monoid MeasureTheory.SimpleFunc.instAddCommMonoid instance instAddGroup [AddGroup β] : AddGroup (α →ₛ β) := Function.Injective.addGroup (fun f => show α → β from f) coe_injective coe_zero coe_add coe_neg coe_sub (fun _ _ => coe_smul _ _) fun _ _ => coe_smul _ _ #align measure_theory.simple_func.add_group MeasureTheory.SimpleFunc.instAddGroup instance instAddCommGroup [AddCommGroup β] : AddCommGroup (α →ₛ β) := Function.Injective.addCommGroup (fun f => show α → β from f) coe_injective coe_zero coe_add coe_neg coe_sub (fun _ _ => coe_smul _ _) fun _ _ => coe_smul _ _ #align measure_theory.simple_func.add_comm_group MeasureTheory.SimpleFunc.instAddCommGroup end Additive @[to_additive existing] instance instMonoid [Monoid β] : Monoid (α →ₛ β) := Function.Injective.monoid (fun f => show α → β from f) coe_injective coe_one coe_mul coe_pow #align measure_theory.simple_func.monoid MeasureTheory.SimpleFunc.instMonoid @[to_additive existing] instance instCommMonoid [CommMonoid β] : CommMonoid (α →ₛ β) := Function.Injective.commMonoid (fun f => show α → β from f) coe_injective coe_one coe_mul coe_pow #align measure_theory.simple_func.comm_monoid MeasureTheory.SimpleFunc.instCommMonoid @[to_additive existing] instance instGroup [Group β] : Group (α →ₛ β) := Function.Injective.group (fun f => show α → β from f) coe_injective coe_one coe_mul coe_inv coe_div coe_pow coe_zpow #align measure_theory.simple_func.group MeasureTheory.SimpleFunc.instGroup @[to_additive existing] instance instCommGroup [CommGroup β] : CommGroup (α →ₛ β) := Function.Injective.commGroup (fun f => show α → β from f) coe_injective coe_one coe_mul coe_inv coe_div coe_pow coe_zpow #align measure_theory.simple_func.comm_group MeasureTheory.SimpleFunc.instCommGroup instance instModule [Semiring K] [AddCommMonoid β] [Module K β] : Module K (α →ₛ β) := Function.Injective.module K ⟨⟨fun f => show α → β from f, coe_zero⟩, coe_add⟩ coe_injective coe_smul #align measure_theory.simple_func.module MeasureTheory.SimpleFunc.instModule theorem smul_eq_map [SMul K β] (k : K) (f : α →ₛ β) : k • f = f.map (k • ·) := rfl #align measure_theory.simple_func.smul_eq_map MeasureTheory.SimpleFunc.smul_eq_map instance instPreorder [Preorder β] : Preorder (α →ₛ β) := { SimpleFunc.instLE with le_refl := fun f a => le_rfl le_trans := fun f g h hfg hgh a => le_trans (hfg _) (hgh a) } #align measure_theory.simple_func.preorder MeasureTheory.SimpleFunc.instPreorder instance instPartialOrder [PartialOrder β] : PartialOrder (α →ₛ β) := { SimpleFunc.instPreorder with le_antisymm := fun _f _g hfg hgf => ext fun a => le_antisymm (hfg a) (hgf a) } #align measure_theory.simple_func.partial_order MeasureTheory.SimpleFunc.instPartialOrder instance instOrderBot [LE β] [OrderBot β] : OrderBot (α →ₛ β) where bot := const α ⊥ bot_le _ _ := bot_le #align measure_theory.simple_func.order_bot MeasureTheory.SimpleFunc.instOrderBot instance instOrderTop [LE β] [OrderTop β] : OrderTop (α →ₛ β) where top := const α ⊤ le_top _ _ := le_top #align measure_theory.simple_func.order_top MeasureTheory.SimpleFunc.instOrderTop instance instSemilatticeInf [SemilatticeInf β] : SemilatticeInf (α →ₛ β) := { SimpleFunc.instPartialOrder with inf := (· ⊓ ·) inf_le_left := fun _ _ _ => inf_le_left inf_le_right := fun _ _ _ => inf_le_right le_inf := fun _f _g _h hfh hgh a => le_inf (hfh a) (hgh a) } #align measure_theory.simple_func.semilattice_inf MeasureTheory.SimpleFunc.instSemilatticeInf instance instSemilatticeSup [SemilatticeSup β] : SemilatticeSup (α →ₛ β) := { SimpleFunc.instPartialOrder with sup := (· ⊔ ·) le_sup_left := fun _ _ _ => le_sup_left le_sup_right := fun _ _ _ => le_sup_right sup_le := fun _f _g _h hfh hgh a => sup_le (hfh a) (hgh a) } #align measure_theory.simple_func.semilattice_sup MeasureTheory.SimpleFunc.instSemilatticeSup instance instLattice [Lattice β] : Lattice (α →ₛ β) := { SimpleFunc.instSemilatticeSup, SimpleFunc.instSemilatticeInf with } #align measure_theory.simple_func.lattice MeasureTheory.SimpleFunc.instLattice instance instBoundedOrder [LE β] [BoundedOrder β] : BoundedOrder (α →ₛ β) := { SimpleFunc.instOrderBot, SimpleFunc.instOrderTop with } #align measure_theory.simple_func.bounded_order MeasureTheory.SimpleFunc.instBoundedOrder theorem finset_sup_apply [SemilatticeSup β] [OrderBot β] {f : γ → α →ₛ β} (s : Finset γ) (a : α) : s.sup f a = s.sup fun c => f c a := by refine Finset.induction_on s rfl ?_ intro a s _ ih rw [Finset.sup_insert, Finset.sup_insert, sup_apply, ih] #align measure_theory.simple_func.finset_sup_apply MeasureTheory.SimpleFunc.finset_sup_apply section Restrict variable [Zero β] /-- Restrict a simple function `f : α →ₛ β` to a set `s`. If `s` is measurable, then `f.restrict s a = if a ∈ s then f a else 0`, otherwise `f.restrict s = const α 0`. -/ def restrict (f : α →ₛ β) (s : Set α) : α →ₛ β := if hs : MeasurableSet s then piecewise s hs f 0 else 0 #align measure_theory.simple_func.restrict MeasureTheory.SimpleFunc.restrict theorem restrict_of_not_measurable {f : α →ₛ β} {s : Set α} (hs : ¬MeasurableSet s) : restrict f s = 0 := dif_neg hs #align measure_theory.simple_func.restrict_of_not_measurable MeasureTheory.SimpleFunc.restrict_of_not_measurable @[simp] theorem coe_restrict (f : α →ₛ β) {s : Set α} (hs : MeasurableSet s) : ⇑(restrict f s) = indicator s f := by rw [restrict, dif_pos hs, coe_piecewise, coe_zero, piecewise_eq_indicator] #align measure_theory.simple_func.coe_restrict MeasureTheory.SimpleFunc.coe_restrict @[simp] theorem restrict_univ (f : α →ₛ β) : restrict f univ = f := by simp [restrict] #align measure_theory.simple_func.restrict_univ MeasureTheory.SimpleFunc.restrict_univ @[simp] theorem restrict_empty (f : α →ₛ β) : restrict f ∅ = 0 := by simp [restrict] #align measure_theory.simple_func.restrict_empty MeasureTheory.SimpleFunc.restrict_empty theorem map_restrict_of_zero [Zero γ] {g : β → γ} (hg : g 0 = 0) (f : α →ₛ β) (s : Set α) : (f.restrict s).map g = (f.map g).restrict s := ext fun x => if hs : MeasurableSet s then by simp [hs, Set.indicator_comp_of_zero hg] else by simp [restrict_of_not_measurable hs, hg] #align measure_theory.simple_func.map_restrict_of_zero MeasureTheory.SimpleFunc.map_restrict_of_zero theorem map_coe_ennreal_restrict (f : α →ₛ ℝ≥0) (s : Set α) : (f.restrict s).map ((↑) : ℝ≥0 → ℝ≥0∞) = (f.map (↑)).restrict s := map_restrict_of_zero ENNReal.coe_zero _ _ #align measure_theory.simple_func.map_coe_ennreal_restrict MeasureTheory.SimpleFunc.map_coe_ennreal_restrict theorem map_coe_nnreal_restrict (f : α →ₛ ℝ≥0) (s : Set α) : (f.restrict s).map ((↑) : ℝ≥0 → ℝ) = (f.map (↑)).restrict s := map_restrict_of_zero NNReal.coe_zero _ _ #align measure_theory.simple_func.map_coe_nnreal_restrict MeasureTheory.SimpleFunc.map_coe_nnreal_restrict theorem restrict_apply (f : α →ₛ β) {s : Set α} (hs : MeasurableSet s) (a) : restrict f s a = indicator s f a := by simp only [f.coe_restrict hs] #align measure_theory.simple_func.restrict_apply MeasureTheory.SimpleFunc.restrict_apply theorem restrict_preimage (f : α →ₛ β) {s : Set α} (hs : MeasurableSet s) {t : Set β} (ht : (0 : β) ∉ t) : restrict f s ⁻¹' t = s ∩ f ⁻¹' t := by simp [hs, indicator_preimage_of_not_mem _ _ ht, inter_comm] #align measure_theory.simple_func.restrict_preimage MeasureTheory.SimpleFunc.restrict_preimage theorem restrict_preimage_singleton (f : α →ₛ β) {s : Set α} (hs : MeasurableSet s) {r : β} (hr : r ≠ 0) : restrict f s ⁻¹' {r} = s ∩ f ⁻¹' {r} := f.restrict_preimage hs hr.symm #align measure_theory.simple_func.restrict_preimage_singleton MeasureTheory.SimpleFunc.restrict_preimage_singleton theorem mem_restrict_range {r : β} {s : Set α} {f : α →ₛ β} (hs : MeasurableSet s) : r ∈ (restrict f s).range ↔ r = 0 ∧ s ≠ univ ∨ r ∈ f '' s := by rw [← Finset.mem_coe, coe_range, coe_restrict _ hs, mem_range_indicator] #align measure_theory.simple_func.mem_restrict_range MeasureTheory.SimpleFunc.mem_restrict_range theorem mem_image_of_mem_range_restrict {r : β} {s : Set α} {f : α →ₛ β} (hr : r ∈ (restrict f s).range) (h0 : r ≠ 0) : r ∈ f '' s := if hs : MeasurableSet s then by simpa [mem_restrict_range hs, h0, -mem_range] using hr else by rw [restrict_of_not_measurable hs] at hr exact (h0 <| eq_zero_of_mem_range_zero hr).elim #align measure_theory.simple_func.mem_image_of_mem_range_restrict MeasureTheory.SimpleFunc.mem_image_of_mem_range_restrict @[mono] theorem restrict_mono [Preorder β] (s : Set α) {f g : α →ₛ β} (H : f ≤ g) : f.restrict s ≤ g.restrict s := if hs : MeasurableSet s then fun x => by simp only [coe_restrict _ hs, indicator_le_indicator (H x)] else by simp only [restrict_of_not_measurable hs, le_refl] #align measure_theory.simple_func.restrict_mono MeasureTheory.SimpleFunc.restrict_mono end Restrict section Approx section variable [SemilatticeSup β] [OrderBot β] [Zero β] /-- Fix a sequence `i : ℕ → β`. Given a function `α → β`, its `n`-th approximation by simple functions is defined so that in case `β = ℝ≥0∞` it sends each `a` to the supremum of the set `{i k | k ≤ n ∧ i k ≤ f a}`, see `approx_apply` and `iSup_approx_apply` for details. -/ def approx (i : ℕ → β) (f : α → β) (n : ℕ) : α →ₛ β := (Finset.range n).sup fun k => restrict (const α (i k)) { a : α | i k ≤ f a } #align measure_theory.simple_func.approx MeasureTheory.SimpleFunc.approx theorem approx_apply [TopologicalSpace β] [OrderClosedTopology β] [MeasurableSpace β] [OpensMeasurableSpace β] {i : ℕ → β} {f : α → β} {n : ℕ} (a : α) (hf : Measurable f) : (approx i f n : α →ₛ β) a = (Finset.range n).sup fun k => if i k ≤ f a then i k else 0 := by dsimp only [approx] rw [finset_sup_apply] congr funext k rw [restrict_apply] · simp only [coe_const, mem_setOf_eq, indicator_apply, Function.const_apply] · exact hf measurableSet_Ici #align measure_theory.simple_func.approx_apply MeasureTheory.SimpleFunc.approx_apply theorem monotone_approx (i : ℕ → β) (f : α → β) : Monotone (approx i f) := fun _ _ h => Finset.sup_mono <| Finset.range_subset.2 h #align measure_theory.simple_func.monotone_approx MeasureTheory.SimpleFunc.monotone_approx theorem approx_comp [TopologicalSpace β] [OrderClosedTopology β] [MeasurableSpace β] [OpensMeasurableSpace β] [MeasurableSpace γ] {i : ℕ → β} {f : γ → β} {g : α → γ} {n : ℕ} (a : α) (hf : Measurable f) (hg : Measurable g) : (approx i (f ∘ g) n : α →ₛ β) a = (approx i f n : γ →ₛ β) (g a) := by rw [approx_apply _ hf, approx_apply _ (hf.comp hg), Function.comp_apply] #align measure_theory.simple_func.approx_comp MeasureTheory.SimpleFunc.approx_comp end theorem iSup_approx_apply [TopologicalSpace β] [CompleteLattice β] [OrderClosedTopology β] [Zero β] [MeasurableSpace β] [OpensMeasurableSpace β] (i : ℕ → β) (f : α → β) (a : α) (hf : Measurable f) (h_zero : (0 : β) = ⊥) : ⨆ n, (approx i f n : α →ₛ β) a = ⨆ (k) (_ : i k ≤ f a), i k := by refine le_antisymm (iSup_le fun n => ?_) (iSup_le fun k => iSup_le fun hk => ?_) · rw [approx_apply a hf, h_zero] refine Finset.sup_le fun k _ => ?_ split_ifs with h · exact le_iSup_of_le k (le_iSup (fun _ : i k ≤ f a => i k) h) · exact bot_le · refine le_iSup_of_le (k + 1) ?_ rw [approx_apply a hf] have : k ∈ Finset.range (k + 1) := Finset.mem_range.2 (Nat.lt_succ_self _) refine le_trans (le_of_eq ?_) (Finset.le_sup this) rw [if_pos hk] #align measure_theory.simple_func.supr_approx_apply MeasureTheory.SimpleFunc.iSup_approx_apply end Approx section EApprox /-- A sequence of `ℝ≥0∞`s such that its range is the set of non-negative rational numbers. -/ def ennrealRatEmbed (n : ℕ) : ℝ≥0∞ := ENNReal.ofReal ((Encodable.decode (α := ℚ) n).getD (0 : ℚ)) #align measure_theory.simple_func.ennreal_rat_embed MeasureTheory.SimpleFunc.ennrealRatEmbed
Mathlib/MeasureTheory/Function/SimpleFunc.lean
882
884
theorem ennrealRatEmbed_encode (q : ℚ) : ennrealRatEmbed (Encodable.encode q) = Real.toNNReal q := by
rw [ennrealRatEmbed, Encodable.encodek]; rfl
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Michael Stoll -/ import Mathlib.Data.Nat.Squarefree import Mathlib.NumberTheory.Zsqrtd.QuadraticReciprocity import Mathlib.Tactic.LinearCombination #align_import number_theory.sum_two_squares from "leanprover-community/mathlib"@"5b2fe80501ff327b9109fb09b7cc8c325cd0d7d9" /-! # Sums of two squares Fermat's theorem on the sum of two squares. Every prime `p` congruent to 1 mod 4 is the sum of two squares; see `Nat.Prime.sq_add_sq` (which has the weaker assumption `p % 4 ≠ 3`). We also give the result that characterizes the (positive) natural numbers that are sums of two squares as those numbers `n` such that for every prime `q` congruent to 3 mod 4, the exponent of the largest power of `q` dividing `n` is even; see `Nat.eq_sq_add_sq_iff`. There is an alternative characterization as the numbers of the form `a^2 * b`, where `b` is a natural number such that `-1` is a square modulo `b`; see `Nat.eq_sq_add_sq_iff_eq_sq_mul`. -/ section Fermat open GaussianInt /-- **Fermat's theorem on the sum of two squares**. Every prime not congruent to 3 mod 4 is the sum of two squares. Also known as **Fermat's Christmas theorem**. -/ theorem Nat.Prime.sq_add_sq {p : ℕ} [Fact p.Prime] (hp : p % 4 ≠ 3) : ∃ a b : ℕ, a ^ 2 + b ^ 2 = p := by apply sq_add_sq_of_nat_prime_of_not_irreducible p rwa [_root_.irreducible_iff_prime, prime_iff_mod_four_eq_three_of_nat_prime p] #align nat.prime.sq_add_sq Nat.Prime.sq_add_sq end Fermat /-! ### Generalities on sums of two squares -/ section General /-- The set of sums of two squares is closed under multiplication in any commutative ring. See also `sq_add_sq_mul_sq_add_sq`. -/ theorem sq_add_sq_mul {R} [CommRing R] {a b x y u v : R} (ha : a = x ^ 2 + y ^ 2) (hb : b = u ^ 2 + v ^ 2) : ∃ r s : R, a * b = r ^ 2 + s ^ 2 := ⟨x * u - y * v, x * v + y * u, by rw [ha, hb]; ring⟩ #align sq_add_sq_mul sq_add_sq_mul /-- The set of natural numbers that are sums of two squares is closed under multiplication. -/ theorem Nat.sq_add_sq_mul {a b x y u v : ℕ} (ha : a = x ^ 2 + y ^ 2) (hb : b = u ^ 2 + v ^ 2) : ∃ r s : ℕ, a * b = r ^ 2 + s ^ 2 := by zify at ha hb ⊢ obtain ⟨r, s, h⟩ := _root_.sq_add_sq_mul ha hb refine ⟨r.natAbs, s.natAbs, ?_⟩ simpa only [Int.natCast_natAbs, sq_abs] #align nat.sq_add_sq_mul Nat.sq_add_sq_mul end General /-! ### Results on when -1 is a square modulo a natural number -/ section NegOneSquare -- This could be formulated for a general integer `a` in place of `-1`, -- but it would not directly specialize to `-1`, -- because `((-1 : ℤ) : ZMod n)` is not the same as `(-1 : ZMod n)`. /-- If `-1` is a square modulo `n` and `m` divides `n`, then `-1` is also a square modulo `m`. -/ theorem ZMod.isSquare_neg_one_of_dvd {m n : ℕ} (hd : m ∣ n) (hs : IsSquare (-1 : ZMod n)) : IsSquare (-1 : ZMod m) := by let f : ZMod n →+* ZMod m := ZMod.castHom hd _ rw [← RingHom.map_one f, ← RingHom.map_neg] exact hs.map f #align zmod.is_square_neg_one_of_dvd ZMod.isSquare_neg_one_of_dvd /-- If `-1` is a square modulo coprime natural numbers `m` and `n`, then `-1` is also a square modulo `m*n`. -/ theorem ZMod.isSquare_neg_one_mul {m n : ℕ} (hc : m.Coprime n) (hm : IsSquare (-1 : ZMod m)) (hn : IsSquare (-1 : ZMod n)) : IsSquare (-1 : ZMod (m * n)) := by have : IsSquare (-1 : ZMod m × ZMod n) := by rw [show (-1 : ZMod m × ZMod n) = ((-1 : ZMod m), (-1 : ZMod n)) from rfl] obtain ⟨x, hx⟩ := hm obtain ⟨y, hy⟩ := hn rw [hx, hy] exact ⟨(x, y), rfl⟩ simpa only [RingEquiv.map_neg_one] using this.map (ZMod.chineseRemainder hc).symm #align zmod.is_square_neg_one_mul ZMod.isSquare_neg_one_mul /-- If a prime `p` divides `n` such that `-1` is a square modulo `n`, then `p % 4 ≠ 3`. -/ theorem Nat.Prime.mod_four_ne_three_of_dvd_isSquare_neg_one {p n : ℕ} (hpp : p.Prime) (hp : p ∣ n) (hs : IsSquare (-1 : ZMod n)) : p % 4 ≠ 3 := by obtain ⟨y, h⟩ := ZMod.isSquare_neg_one_of_dvd hp hs rw [← sq, eq_comm, show (-1 : ZMod p) = -1 ^ 2 by ring] at h haveI : Fact p.Prime := ⟨hpp⟩ exact ZMod.mod_four_ne_three_of_sq_eq_neg_sq' one_ne_zero h #align nat.prime.mod_four_ne_three_of_dvd_is_square_neg_one Nat.Prime.mod_four_ne_three_of_dvd_isSquare_neg_one /-- If `n` is a squarefree natural number, then `-1` is a square modulo `n` if and only if `n` is not divisible by a prime `q` such that `q % 4 = 3`. -/ theorem ZMod.isSquare_neg_one_iff {n : ℕ} (hn : Squarefree n) : IsSquare (-1 : ZMod n) ↔ ∀ {q : ℕ}, q.Prime → q ∣ n → q % 4 ≠ 3 := by refine ⟨fun H q hqp hqd => hqp.mod_four_ne_three_of_dvd_isSquare_neg_one hqd H, fun H => ?_⟩ induction' n using induction_on_primes with p n hpp ih · exact False.elim (hn.ne_zero rfl) · exact ⟨0, by simp only [mul_zero, eq_iff_true_of_subsingleton]⟩ · haveI : Fact p.Prime := ⟨hpp⟩ have hcp : p.Coprime n := by by_contra hc exact hpp.not_unit (hn p <| mul_dvd_mul_left p <| hpp.dvd_iff_not_coprime.mpr hc) have hp₁ := ZMod.exists_sq_eq_neg_one_iff.mpr (H hpp (dvd_mul_right p n)) exact ZMod.isSquare_neg_one_mul hcp hp₁ (ih hn.of_mul_right fun hqp hqd => H hqp <| dvd_mul_of_dvd_right hqd _) #align zmod.is_square_neg_one_iff ZMod.isSquare_neg_one_iff /-- If `n` is a squarefree natural number, then `-1` is a square modulo `n` if and only if `n` has no divisor `q` that is `≡ 3 mod 4`. -/ theorem ZMod.isSquare_neg_one_iff' {n : ℕ} (hn : Squarefree n) : IsSquare (-1 : ZMod n) ↔ ∀ {q : ℕ}, q ∣ n → q % 4 ≠ 3 := by have help : ∀ a b : ZMod 4, a ≠ 3 → b ≠ 3 → a * b ≠ 3 := by decide rw [ZMod.isSquare_neg_one_iff hn] refine ⟨?_, fun H q _ => H⟩ intro H refine @induction_on_primes _ ?_ ?_ (fun p q hp hq hpq => ?_) · exact fun _ => by norm_num · exact fun _ => by norm_num · replace hp := H hp (dvd_of_mul_right_dvd hpq) replace hq := hq (dvd_of_mul_left_dvd hpq) rw [show 3 = 3 % 4 by norm_num, Ne, ← ZMod.natCast_eq_natCast_iff'] at hp hq ⊢ rw [Nat.cast_mul] exact help p q hp hq #align zmod.is_square_neg_one_iff' ZMod.isSquare_neg_one_iff' /-! ### Relation to sums of two squares -/ /-- If `-1` is a square modulo the natural number `n`, then `n` is a sum of two squares. -/ theorem Nat.eq_sq_add_sq_of_isSquare_mod_neg_one {n : ℕ} (h : IsSquare (-1 : ZMod n)) : ∃ x y : ℕ, n = x ^ 2 + y ^ 2 := by induction' n using induction_on_primes with p n hpp ih · exact ⟨0, 0, rfl⟩ · exact ⟨0, 1, rfl⟩ · haveI : Fact p.Prime := ⟨hpp⟩ have hp : IsSquare (-1 : ZMod p) := ZMod.isSquare_neg_one_of_dvd ⟨n, rfl⟩ h obtain ⟨u, v, huv⟩ := Nat.Prime.sq_add_sq (ZMod.exists_sq_eq_neg_one_iff.mp hp) obtain ⟨x, y, hxy⟩ := ih (ZMod.isSquare_neg_one_of_dvd ⟨p, mul_comm _ _⟩ h) exact Nat.sq_add_sq_mul huv.symm hxy #align nat.eq_sq_add_sq_of_is_square_mod_neg_one Nat.eq_sq_add_sq_of_isSquare_mod_neg_one /-- If the integer `n` is a sum of two squares of coprime integers, then `-1` is a square modulo `n`. -/
Mathlib/NumberTheory/SumTwoSquares.lean
161
172
theorem ZMod.isSquare_neg_one_of_eq_sq_add_sq_of_isCoprime {n x y : ℤ} (h : n = x ^ 2 + y ^ 2) (hc : IsCoprime x y) : IsSquare (-1 : ZMod n.natAbs) := by
obtain ⟨u, v, huv⟩ : IsCoprime x n := by have hc2 : IsCoprime (x ^ 2) (y ^ 2) := hc.pow rw [show y ^ 2 = n + -1 * x ^ 2 by rw [h]; ring] at hc2 exact (IsCoprime.pow_left_iff zero_lt_two).mp hc2.of_add_mul_right_right have H : u * y * (u * y) - -1 = n * (-v ^ 2 * n + u ^ 2 + 2 * v) := by linear_combination -u ^ 2 * h + (n * v - u * x - 1) * huv refine ⟨u * y, ?_⟩ conv_rhs => tactic => norm_cast rw [(by norm_cast : (-1 : ZMod n.natAbs) = (-1 : ℤ))] exact (ZMod.intCast_eq_intCast_iff_dvd_sub _ _ _).mpr (Int.natAbs_dvd.mpr ⟨_, H⟩)
/- Copyright (c) 2018 Ellen Arlt. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ellen Arlt, Blair Shi, Sean Leather, Mario Carneiro, Johan Commelin, Lu-Ming Zhang -/ import Mathlib.Algebra.Algebra.Opposite import Mathlib.Algebra.Algebra.Pi import Mathlib.Algebra.BigOperators.Pi import Mathlib.Algebra.BigOperators.Ring import Mathlib.Algebra.BigOperators.RingEquiv import Mathlib.Algebra.Module.LinearMap.Basic import Mathlib.Algebra.Module.Pi import Mathlib.Algebra.Star.BigOperators import Mathlib.Algebra.Star.Module import Mathlib.Algebra.Star.Pi import Mathlib.Data.Fintype.BigOperators import Mathlib.GroupTheory.GroupAction.BigOperators #align_import data.matrix.basic from "leanprover-community/mathlib"@"eba5bb3155cab51d80af00e8d7d69fa271b1302b" /-! # Matrices This file defines basic properties of matrices. Matrices with rows indexed by `m`, columns indexed by `n`, and entries of type `α` are represented with `Matrix m n α`. For the typical approach of counting rows and columns, `Matrix (Fin m) (Fin n) α` can be used. ## Notation The locale `Matrix` gives the following notation: * `⬝ᵥ` for `Matrix.dotProduct` * `*ᵥ` for `Matrix.mulVec` * `ᵥ*` for `Matrix.vecMul` * `ᵀ` for `Matrix.transpose` * `ᴴ` for `Matrix.conjTranspose` ## Implementation notes For convenience, `Matrix m n α` is defined as `m → n → α`, as this allows elements of the matrix to be accessed with `A i j`. However, it is not advisable to _construct_ matrices using terms of the form `fun i j ↦ _` or even `(fun i j ↦ _ : Matrix m n α)`, as these are not recognized by Lean as having the right type. Instead, `Matrix.of` should be used. ## TODO Under various conditions, multiplication of infinite matrices makes sense. These have not yet been implemented. -/ universe u u' v w /-- `Matrix m n R` is the type of matrices with entries in `R`, whose rows are indexed by `m` and whose columns are indexed by `n`. -/ def Matrix (m : Type u) (n : Type u') (α : Type v) : Type max u u' v := m → n → α #align matrix Matrix variable {l m n o : Type*} {m' : o → Type*} {n' : o → Type*} variable {R : Type*} {S : Type*} {α : Type v} {β : Type w} {γ : Type*} namespace Matrix section Ext variable {M N : Matrix m n α} theorem ext_iff : (∀ i j, M i j = N i j) ↔ M = N := ⟨fun h => funext fun i => funext <| h i, fun h => by simp [h]⟩ #align matrix.ext_iff Matrix.ext_iff @[ext] theorem ext : (∀ i j, M i j = N i j) → M = N := ext_iff.mp #align matrix.ext Matrix.ext end Ext /-- Cast a function into a matrix. The two sides of the equivalence are definitionally equal types. We want to use an explicit cast to distinguish the types because `Matrix` has different instances to pi types (such as `Pi.mul`, which performs elementwise multiplication, vs `Matrix.mul`). If you are defining a matrix, in terms of its entries, use `of (fun i j ↦ _)`. The purpose of this approach is to ensure that terms of the form `(fun i j ↦ _) * (fun i j ↦ _)` do not appear, as the type of `*` can be misleading. Porting note: In Lean 3, it is also safe to use pattern matching in a definition as `| i j := _`, which can only be unfolded when fully-applied. leanprover/lean4#2042 means this does not (currently) work in Lean 4. -/ def of : (m → n → α) ≃ Matrix m n α := Equiv.refl _ #align matrix.of Matrix.of @[simp] theorem of_apply (f : m → n → α) (i j) : of f i j = f i j := rfl #align matrix.of_apply Matrix.of_apply @[simp] theorem of_symm_apply (f : Matrix m n α) (i j) : of.symm f i j = f i j := rfl #align matrix.of_symm_apply Matrix.of_symm_apply /-- `M.map f` is the matrix obtained by applying `f` to each entry of the matrix `M`. This is available in bundled forms as: * `AddMonoidHom.mapMatrix` * `LinearMap.mapMatrix` * `RingHom.mapMatrix` * `AlgHom.mapMatrix` * `Equiv.mapMatrix` * `AddEquiv.mapMatrix` * `LinearEquiv.mapMatrix` * `RingEquiv.mapMatrix` * `AlgEquiv.mapMatrix` -/ def map (M : Matrix m n α) (f : α → β) : Matrix m n β := of fun i j => f (M i j) #align matrix.map Matrix.map @[simp] theorem map_apply {M : Matrix m n α} {f : α → β} {i : m} {j : n} : M.map f i j = f (M i j) := rfl #align matrix.map_apply Matrix.map_apply @[simp] theorem map_id (M : Matrix m n α) : M.map id = M := by ext rfl #align matrix.map_id Matrix.map_id @[simp] theorem map_id' (M : Matrix m n α) : M.map (·) = M := map_id M @[simp] theorem map_map {M : Matrix m n α} {β γ : Type*} {f : α → β} {g : β → γ} : (M.map f).map g = M.map (g ∘ f) := by ext rfl #align matrix.map_map Matrix.map_map theorem map_injective {f : α → β} (hf : Function.Injective f) : Function.Injective fun M : Matrix m n α => M.map f := fun _ _ h => ext fun i j => hf <| ext_iff.mpr h i j #align matrix.map_injective Matrix.map_injective /-- The transpose of a matrix. -/ def transpose (M : Matrix m n α) : Matrix n m α := of fun x y => M y x #align matrix.transpose Matrix.transpose -- TODO: set as an equation lemma for `transpose`, see mathlib4#3024 @[simp] theorem transpose_apply (M : Matrix m n α) (i j) : transpose M i j = M j i := rfl #align matrix.transpose_apply Matrix.transpose_apply @[inherit_doc] scoped postfix:1024 "ᵀ" => Matrix.transpose /-- The conjugate transpose of a matrix defined in term of `star`. -/ def conjTranspose [Star α] (M : Matrix m n α) : Matrix n m α := M.transpose.map star #align matrix.conj_transpose Matrix.conjTranspose @[inherit_doc] scoped postfix:1024 "ᴴ" => Matrix.conjTranspose instance inhabited [Inhabited α] : Inhabited (Matrix m n α) := inferInstanceAs <| Inhabited <| m → n → α -- Porting note: new, Lean3 found this automatically instance decidableEq [DecidableEq α] [Fintype m] [Fintype n] : DecidableEq (Matrix m n α) := Fintype.decidablePiFintype instance {n m} [Fintype m] [DecidableEq m] [Fintype n] [DecidableEq n] (α) [Fintype α] : Fintype (Matrix m n α) := inferInstanceAs (Fintype (m → n → α)) instance {n m} [Finite m] [Finite n] (α) [Finite α] : Finite (Matrix m n α) := inferInstanceAs (Finite (m → n → α)) instance add [Add α] : Add (Matrix m n α) := Pi.instAdd instance addSemigroup [AddSemigroup α] : AddSemigroup (Matrix m n α) := Pi.addSemigroup instance addCommSemigroup [AddCommSemigroup α] : AddCommSemigroup (Matrix m n α) := Pi.addCommSemigroup instance zero [Zero α] : Zero (Matrix m n α) := Pi.instZero instance addZeroClass [AddZeroClass α] : AddZeroClass (Matrix m n α) := Pi.addZeroClass instance addMonoid [AddMonoid α] : AddMonoid (Matrix m n α) := Pi.addMonoid instance addCommMonoid [AddCommMonoid α] : AddCommMonoid (Matrix m n α) := Pi.addCommMonoid instance neg [Neg α] : Neg (Matrix m n α) := Pi.instNeg instance sub [Sub α] : Sub (Matrix m n α) := Pi.instSub instance addGroup [AddGroup α] : AddGroup (Matrix m n α) := Pi.addGroup instance addCommGroup [AddCommGroup α] : AddCommGroup (Matrix m n α) := Pi.addCommGroup instance unique [Unique α] : Unique (Matrix m n α) := Pi.unique instance subsingleton [Subsingleton α] : Subsingleton (Matrix m n α) := inferInstanceAs <| Subsingleton <| m → n → α instance nonempty [Nonempty m] [Nonempty n] [Nontrivial α] : Nontrivial (Matrix m n α) := Function.nontrivial instance smul [SMul R α] : SMul R (Matrix m n α) := Pi.instSMul instance smulCommClass [SMul R α] [SMul S α] [SMulCommClass R S α] : SMulCommClass R S (Matrix m n α) := Pi.smulCommClass instance isScalarTower [SMul R S] [SMul R α] [SMul S α] [IsScalarTower R S α] : IsScalarTower R S (Matrix m n α) := Pi.isScalarTower instance isCentralScalar [SMul R α] [SMul Rᵐᵒᵖ α] [IsCentralScalar R α] : IsCentralScalar R (Matrix m n α) := Pi.isCentralScalar instance mulAction [Monoid R] [MulAction R α] : MulAction R (Matrix m n α) := Pi.mulAction _ instance distribMulAction [Monoid R] [AddMonoid α] [DistribMulAction R α] : DistribMulAction R (Matrix m n α) := Pi.distribMulAction _ instance module [Semiring R] [AddCommMonoid α] [Module R α] : Module R (Matrix m n α) := Pi.module _ _ _ -- Porting note (#10756): added the following section with simp lemmas because `simp` fails -- to apply the corresponding lemmas in the namespace `Pi`. -- (e.g. `Pi.zero_apply` used on `OfNat.ofNat 0 i j`) section @[simp] theorem zero_apply [Zero α] (i : m) (j : n) : (0 : Matrix m n α) i j = 0 := rfl @[simp] theorem add_apply [Add α] (A B : Matrix m n α) (i : m) (j : n) : (A + B) i j = (A i j) + (B i j) := rfl @[simp] theorem smul_apply [SMul β α] (r : β) (A : Matrix m n α) (i : m) (j : n) : (r • A) i j = r • (A i j) := rfl @[simp] theorem sub_apply [Sub α] (A B : Matrix m n α) (i : m) (j : n) : (A - B) i j = (A i j) - (B i j) := rfl @[simp] theorem neg_apply [Neg α] (A : Matrix m n α) (i : m) (j : n) : (-A) i j = -(A i j) := rfl end /-! simp-normal form pulls `of` to the outside. -/ @[simp] theorem of_zero [Zero α] : of (0 : m → n → α) = 0 := rfl #align matrix.of_zero Matrix.of_zero @[simp] theorem of_add_of [Add α] (f g : m → n → α) : of f + of g = of (f + g) := rfl #align matrix.of_add_of Matrix.of_add_of @[simp] theorem of_sub_of [Sub α] (f g : m → n → α) : of f - of g = of (f - g) := rfl #align matrix.of_sub_of Matrix.of_sub_of @[simp] theorem neg_of [Neg α] (f : m → n → α) : -of f = of (-f) := rfl #align matrix.neg_of Matrix.neg_of @[simp] theorem smul_of [SMul R α] (r : R) (f : m → n → α) : r • of f = of (r • f) := rfl #align matrix.smul_of Matrix.smul_of @[simp] protected theorem map_zero [Zero α] [Zero β] (f : α → β) (h : f 0 = 0) : (0 : Matrix m n α).map f = 0 := by ext simp [h] #align matrix.map_zero Matrix.map_zero protected theorem map_add [Add α] [Add β] (f : α → β) (hf : ∀ a₁ a₂, f (a₁ + a₂) = f a₁ + f a₂) (M N : Matrix m n α) : (M + N).map f = M.map f + N.map f := ext fun _ _ => hf _ _ #align matrix.map_add Matrix.map_add protected theorem map_sub [Sub α] [Sub β] (f : α → β) (hf : ∀ a₁ a₂, f (a₁ - a₂) = f a₁ - f a₂) (M N : Matrix m n α) : (M - N).map f = M.map f - N.map f := ext fun _ _ => hf _ _ #align matrix.map_sub Matrix.map_sub theorem map_smul [SMul R α] [SMul R β] (f : α → β) (r : R) (hf : ∀ a, f (r • a) = r • f a) (M : Matrix m n α) : (r • M).map f = r • M.map f := ext fun _ _ => hf _ #align matrix.map_smul Matrix.map_smul /-- The scalar action via `Mul.toSMul` is transformed by the same map as the elements of the matrix, when `f` preserves multiplication. -/ theorem map_smul' [Mul α] [Mul β] (f : α → β) (r : α) (A : Matrix n n α) (hf : ∀ a₁ a₂, f (a₁ * a₂) = f a₁ * f a₂) : (r • A).map f = f r • A.map f := ext fun _ _ => hf _ _ #align matrix.map_smul' Matrix.map_smul' /-- The scalar action via `mul.toOppositeSMul` is transformed by the same map as the elements of the matrix, when `f` preserves multiplication. -/ theorem map_op_smul' [Mul α] [Mul β] (f : α → β) (r : α) (A : Matrix n n α) (hf : ∀ a₁ a₂, f (a₁ * a₂) = f a₁ * f a₂) : (MulOpposite.op r • A).map f = MulOpposite.op (f r) • A.map f := ext fun _ _ => hf _ _ #align matrix.map_op_smul' Matrix.map_op_smul' theorem _root_.IsSMulRegular.matrix [SMul R S] {k : R} (hk : IsSMulRegular S k) : IsSMulRegular (Matrix m n S) k := IsSMulRegular.pi fun _ => IsSMulRegular.pi fun _ => hk #align is_smul_regular.matrix IsSMulRegular.matrix theorem _root_.IsLeftRegular.matrix [Mul α] {k : α} (hk : IsLeftRegular k) : IsSMulRegular (Matrix m n α) k := hk.isSMulRegular.matrix #align is_left_regular.matrix IsLeftRegular.matrix instance subsingleton_of_empty_left [IsEmpty m] : Subsingleton (Matrix m n α) := ⟨fun M N => by ext i exact isEmptyElim i⟩ #align matrix.subsingleton_of_empty_left Matrix.subsingleton_of_empty_left instance subsingleton_of_empty_right [IsEmpty n] : Subsingleton (Matrix m n α) := ⟨fun M N => by ext i j exact isEmptyElim j⟩ #align matrix.subsingleton_of_empty_right Matrix.subsingleton_of_empty_right end Matrix open Matrix namespace Matrix section Diagonal variable [DecidableEq n] /-- `diagonal d` is the square matrix such that `(diagonal d) i i = d i` and `(diagonal d) i j = 0` if `i ≠ j`. Note that bundled versions exist as: * `Matrix.diagonalAddMonoidHom` * `Matrix.diagonalLinearMap` * `Matrix.diagonalRingHom` * `Matrix.diagonalAlgHom` -/ def diagonal [Zero α] (d : n → α) : Matrix n n α := of fun i j => if i = j then d i else 0 #align matrix.diagonal Matrix.diagonal -- TODO: set as an equation lemma for `diagonal`, see mathlib4#3024 theorem diagonal_apply [Zero α] (d : n → α) (i j) : diagonal d i j = if i = j then d i else 0 := rfl #align matrix.diagonal_apply Matrix.diagonal_apply @[simp] theorem diagonal_apply_eq [Zero α] (d : n → α) (i : n) : (diagonal d) i i = d i := by simp [diagonal] #align matrix.diagonal_apply_eq Matrix.diagonal_apply_eq @[simp] theorem diagonal_apply_ne [Zero α] (d : n → α) {i j : n} (h : i ≠ j) : (diagonal d) i j = 0 := by simp [diagonal, h] #align matrix.diagonal_apply_ne Matrix.diagonal_apply_ne theorem diagonal_apply_ne' [Zero α] (d : n → α) {i j : n} (h : j ≠ i) : (diagonal d) i j = 0 := diagonal_apply_ne d h.symm #align matrix.diagonal_apply_ne' Matrix.diagonal_apply_ne' @[simp] theorem diagonal_eq_diagonal_iff [Zero α] {d₁ d₂ : n → α} : diagonal d₁ = diagonal d₂ ↔ ∀ i, d₁ i = d₂ i := ⟨fun h i => by simpa using congr_arg (fun m : Matrix n n α => m i i) h, fun h => by rw [show d₁ = d₂ from funext h]⟩ #align matrix.diagonal_eq_diagonal_iff Matrix.diagonal_eq_diagonal_iff theorem diagonal_injective [Zero α] : Function.Injective (diagonal : (n → α) → Matrix n n α) := fun d₁ d₂ h => funext fun i => by simpa using Matrix.ext_iff.mpr h i i #align matrix.diagonal_injective Matrix.diagonal_injective @[simp] theorem diagonal_zero [Zero α] : (diagonal fun _ => 0 : Matrix n n α) = 0 := by ext simp [diagonal] #align matrix.diagonal_zero Matrix.diagonal_zero @[simp] theorem diagonal_transpose [Zero α] (v : n → α) : (diagonal v)ᵀ = diagonal v := by ext i j by_cases h : i = j · simp [h, transpose] · simp [h, transpose, diagonal_apply_ne' _ h] #align matrix.diagonal_transpose Matrix.diagonal_transpose @[simp] theorem diagonal_add [AddZeroClass α] (d₁ d₂ : n → α) : diagonal d₁ + diagonal d₂ = diagonal fun i => d₁ i + d₂ i := by ext i j by_cases h : i = j <;> simp [h] #align matrix.diagonal_add Matrix.diagonal_add @[simp] theorem diagonal_smul [Zero α] [SMulZeroClass R α] (r : R) (d : n → α) : diagonal (r • d) = r • diagonal d := by ext i j by_cases h : i = j <;> simp [h] #align matrix.diagonal_smul Matrix.diagonal_smul @[simp] theorem diagonal_neg [NegZeroClass α] (d : n → α) : -diagonal d = diagonal fun i => -d i := by ext i j by_cases h : i = j <;> simp [h] #align matrix.diagonal_neg Matrix.diagonal_neg @[simp] theorem diagonal_sub [SubNegZeroMonoid α] (d₁ d₂ : n → α) : diagonal d₁ - diagonal d₂ = diagonal fun i => d₁ i - d₂ i := by ext i j by_cases h : i = j <;> simp [h] instance [Zero α] [NatCast α] : NatCast (Matrix n n α) where natCast m := diagonal fun _ => m @[norm_cast] theorem diagonal_natCast [Zero α] [NatCast α] (m : ℕ) : diagonal (fun _ : n => (m : α)) = m := rfl @[norm_cast] theorem diagonal_natCast' [Zero α] [NatCast α] (m : ℕ) : diagonal ((m : n → α)) = m := rfl -- See note [no_index around OfNat.ofNat] theorem diagonal_ofNat [Zero α] [NatCast α] (m : ℕ) [m.AtLeastTwo] : diagonal (fun _ : n => no_index (OfNat.ofNat m : α)) = OfNat.ofNat m := rfl -- See note [no_index around OfNat.ofNat] theorem diagonal_ofNat' [Zero α] [NatCast α] (m : ℕ) [m.AtLeastTwo] : diagonal (no_index (OfNat.ofNat m : n → α)) = OfNat.ofNat m := rfl instance [Zero α] [IntCast α] : IntCast (Matrix n n α) where intCast m := diagonal fun _ => m @[norm_cast] theorem diagonal_intCast [Zero α] [IntCast α] (m : ℤ) : diagonal (fun _ : n => (m : α)) = m := rfl @[norm_cast] theorem diagonal_intCast' [Zero α] [IntCast α] (m : ℤ) : diagonal ((m : n → α)) = m := rfl variable (n α) /-- `Matrix.diagonal` as an `AddMonoidHom`. -/ @[simps] def diagonalAddMonoidHom [AddZeroClass α] : (n → α) →+ Matrix n n α where toFun := diagonal map_zero' := diagonal_zero map_add' x y := (diagonal_add x y).symm #align matrix.diagonal_add_monoid_hom Matrix.diagonalAddMonoidHom variable (R) /-- `Matrix.diagonal` as a `LinearMap`. -/ @[simps] def diagonalLinearMap [Semiring R] [AddCommMonoid α] [Module R α] : (n → α) →ₗ[R] Matrix n n α := { diagonalAddMonoidHom n α with map_smul' := diagonal_smul } #align matrix.diagonal_linear_map Matrix.diagonalLinearMap variable {n α R} @[simp] theorem diagonal_map [Zero α] [Zero β] {f : α → β} (h : f 0 = 0) {d : n → α} : (diagonal d).map f = diagonal fun m => f (d m) := by ext simp only [diagonal_apply, map_apply] split_ifs <;> simp [h] #align matrix.diagonal_map Matrix.diagonal_map @[simp] theorem diagonal_conjTranspose [AddMonoid α] [StarAddMonoid α] (v : n → α) : (diagonal v)ᴴ = diagonal (star v) := by rw [conjTranspose, diagonal_transpose, diagonal_map (star_zero _)] rfl #align matrix.diagonal_conj_transpose Matrix.diagonal_conjTranspose section One variable [Zero α] [One α] instance one : One (Matrix n n α) := ⟨diagonal fun _ => 1⟩ @[simp] theorem diagonal_one : (diagonal fun _ => 1 : Matrix n n α) = 1 := rfl #align matrix.diagonal_one Matrix.diagonal_one theorem one_apply {i j} : (1 : Matrix n n α) i j = if i = j then 1 else 0 := rfl #align matrix.one_apply Matrix.one_apply @[simp] theorem one_apply_eq (i) : (1 : Matrix n n α) i i = 1 := diagonal_apply_eq _ i #align matrix.one_apply_eq Matrix.one_apply_eq @[simp] theorem one_apply_ne {i j} : i ≠ j → (1 : Matrix n n α) i j = 0 := diagonal_apply_ne _ #align matrix.one_apply_ne Matrix.one_apply_ne theorem one_apply_ne' {i j} : j ≠ i → (1 : Matrix n n α) i j = 0 := diagonal_apply_ne' _ #align matrix.one_apply_ne' Matrix.one_apply_ne' @[simp] theorem map_one [Zero β] [One β] (f : α → β) (h₀ : f 0 = 0) (h₁ : f 1 = 1) : (1 : Matrix n n α).map f = (1 : Matrix n n β) := by ext simp only [one_apply, map_apply] split_ifs <;> simp [h₀, h₁] #align matrix.map_one Matrix.map_one -- Porting note: added implicit argument `(f := fun_ => α)`, why is that needed? theorem one_eq_pi_single {i j} : (1 : Matrix n n α) i j = Pi.single (f := fun _ => α) i 1 j := by simp only [one_apply, Pi.single_apply, eq_comm] #align matrix.one_eq_pi_single Matrix.one_eq_pi_single lemma zero_le_one_elem [Preorder α] [ZeroLEOneClass α] (i j : n) : 0 ≤ (1 : Matrix n n α) i j := by by_cases hi : i = j <;> simp [hi] lemma zero_le_one_row [Preorder α] [ZeroLEOneClass α] (i : n) : 0 ≤ (1 : Matrix n n α) i := zero_le_one_elem i end One instance instAddMonoidWithOne [AddMonoidWithOne α] : AddMonoidWithOne (Matrix n n α) where natCast_zero := show diagonal _ = _ by rw [Nat.cast_zero, diagonal_zero] natCast_succ n := show diagonal _ = diagonal _ + _ by rw [Nat.cast_succ, ← diagonal_add, diagonal_one] instance instAddGroupWithOne [AddGroupWithOne α] : AddGroupWithOne (Matrix n n α) where intCast_ofNat n := show diagonal _ = diagonal _ by rw [Int.cast_natCast] intCast_negSucc n := show diagonal _ = -(diagonal _) by rw [Int.cast_negSucc, diagonal_neg] __ := addGroup __ := instAddMonoidWithOne instance instAddCommMonoidWithOne [AddCommMonoidWithOne α] : AddCommMonoidWithOne (Matrix n n α) where __ := addCommMonoid __ := instAddMonoidWithOne instance instAddCommGroupWithOne [AddCommGroupWithOne α] : AddCommGroupWithOne (Matrix n n α) where __ := addCommGroup __ := instAddGroupWithOne section Numeral set_option linter.deprecated false @[deprecated, simp] theorem bit0_apply [Add α] (M : Matrix m m α) (i : m) (j : m) : (bit0 M) i j = bit0 (M i j) := rfl #align matrix.bit0_apply Matrix.bit0_apply variable [AddZeroClass α] [One α] @[deprecated] theorem bit1_apply (M : Matrix n n α) (i : n) (j : n) : (bit1 M) i j = if i = j then bit1 (M i j) else bit0 (M i j) := by dsimp [bit1] by_cases h : i = j <;> simp [h] #align matrix.bit1_apply Matrix.bit1_apply @[deprecated, simp] theorem bit1_apply_eq (M : Matrix n n α) (i : n) : (bit1 M) i i = bit1 (M i i) := by simp [bit1_apply] #align matrix.bit1_apply_eq Matrix.bit1_apply_eq @[deprecated, simp] theorem bit1_apply_ne (M : Matrix n n α) {i j : n} (h : i ≠ j) : (bit1 M) i j = bit0 (M i j) := by simp [bit1_apply, h] #align matrix.bit1_apply_ne Matrix.bit1_apply_ne end Numeral end Diagonal section Diag /-- The diagonal of a square matrix. -/ -- @[simp] -- Porting note: simpNF does not like this. def diag (A : Matrix n n α) (i : n) : α := A i i #align matrix.diag Matrix.diag -- Porting note: new, because of removed `simp` above. -- TODO: set as an equation lemma for `diag`, see mathlib4#3024 @[simp] theorem diag_apply (A : Matrix n n α) (i) : diag A i = A i i := rfl @[simp] theorem diag_diagonal [DecidableEq n] [Zero α] (a : n → α) : diag (diagonal a) = a := funext <| @diagonal_apply_eq _ _ _ _ a #align matrix.diag_diagonal Matrix.diag_diagonal @[simp] theorem diag_transpose (A : Matrix n n α) : diag Aᵀ = diag A := rfl #align matrix.diag_transpose Matrix.diag_transpose @[simp] theorem diag_zero [Zero α] : diag (0 : Matrix n n α) = 0 := rfl #align matrix.diag_zero Matrix.diag_zero @[simp] theorem diag_add [Add α] (A B : Matrix n n α) : diag (A + B) = diag A + diag B := rfl #align matrix.diag_add Matrix.diag_add @[simp] theorem diag_sub [Sub α] (A B : Matrix n n α) : diag (A - B) = diag A - diag B := rfl #align matrix.diag_sub Matrix.diag_sub @[simp] theorem diag_neg [Neg α] (A : Matrix n n α) : diag (-A) = -diag A := rfl #align matrix.diag_neg Matrix.diag_neg @[simp] theorem diag_smul [SMul R α] (r : R) (A : Matrix n n α) : diag (r • A) = r • diag A := rfl #align matrix.diag_smul Matrix.diag_smul @[simp] theorem diag_one [DecidableEq n] [Zero α] [One α] : diag (1 : Matrix n n α) = 1 := diag_diagonal _ #align matrix.diag_one Matrix.diag_one variable (n α) /-- `Matrix.diag` as an `AddMonoidHom`. -/ @[simps] def diagAddMonoidHom [AddZeroClass α] : Matrix n n α →+ n → α where toFun := diag map_zero' := diag_zero map_add' := diag_add #align matrix.diag_add_monoid_hom Matrix.diagAddMonoidHom variable (R) /-- `Matrix.diag` as a `LinearMap`. -/ @[simps] def diagLinearMap [Semiring R] [AddCommMonoid α] [Module R α] : Matrix n n α →ₗ[R] n → α := { diagAddMonoidHom n α with map_smul' := diag_smul } #align matrix.diag_linear_map Matrix.diagLinearMap variable {n α R} theorem diag_map {f : α → β} {A : Matrix n n α} : diag (A.map f) = f ∘ diag A := rfl #align matrix.diag_map Matrix.diag_map @[simp] theorem diag_conjTranspose [AddMonoid α] [StarAddMonoid α] (A : Matrix n n α) : diag Aᴴ = star (diag A) := rfl #align matrix.diag_conj_transpose Matrix.diag_conjTranspose @[simp] theorem diag_list_sum [AddMonoid α] (l : List (Matrix n n α)) : diag l.sum = (l.map diag).sum := map_list_sum (diagAddMonoidHom n α) l #align matrix.diag_list_sum Matrix.diag_list_sum @[simp] theorem diag_multiset_sum [AddCommMonoid α] (s : Multiset (Matrix n n α)) : diag s.sum = (s.map diag).sum := map_multiset_sum (diagAddMonoidHom n α) s #align matrix.diag_multiset_sum Matrix.diag_multiset_sum @[simp] theorem diag_sum {ι} [AddCommMonoid α] (s : Finset ι) (f : ι → Matrix n n α) : diag (∑ i ∈ s, f i) = ∑ i ∈ s, diag (f i) := map_sum (diagAddMonoidHom n α) f s #align matrix.diag_sum Matrix.diag_sum end Diag section DotProduct variable [Fintype m] [Fintype n] /-- `dotProduct v w` is the sum of the entrywise products `v i * w i` -/ def dotProduct [Mul α] [AddCommMonoid α] (v w : m → α) : α := ∑ i, v i * w i #align matrix.dot_product Matrix.dotProduct /- The precedence of 72 comes immediately after ` • ` for `SMul.smul`, so that `r₁ • a ⬝ᵥ r₂ • b` is parsed as `(r₁ • a) ⬝ᵥ (r₂ • b)` here. -/ @[inherit_doc] scoped infixl:72 " ⬝ᵥ " => Matrix.dotProduct theorem dotProduct_assoc [NonUnitalSemiring α] (u : m → α) (w : n → α) (v : Matrix m n α) : (fun j => u ⬝ᵥ fun i => v i j) ⬝ᵥ w = u ⬝ᵥ fun i => v i ⬝ᵥ w := by simpa [dotProduct, Finset.mul_sum, Finset.sum_mul, mul_assoc] using Finset.sum_comm #align matrix.dot_product_assoc Matrix.dotProduct_assoc theorem dotProduct_comm [AddCommMonoid α] [CommSemigroup α] (v w : m → α) : v ⬝ᵥ w = w ⬝ᵥ v := by simp_rw [dotProduct, mul_comm] #align matrix.dot_product_comm Matrix.dotProduct_comm @[simp] theorem dotProduct_pUnit [AddCommMonoid α] [Mul α] (v w : PUnit → α) : v ⬝ᵥ w = v ⟨⟩ * w ⟨⟩ := by simp [dotProduct] #align matrix.dot_product_punit Matrix.dotProduct_pUnit section MulOneClass variable [MulOneClass α] [AddCommMonoid α] theorem dotProduct_one (v : n → α) : v ⬝ᵥ 1 = ∑ i, v i := by simp [(· ⬝ᵥ ·)] #align matrix.dot_product_one Matrix.dotProduct_one theorem one_dotProduct (v : n → α) : 1 ⬝ᵥ v = ∑ i, v i := by simp [(· ⬝ᵥ ·)] #align matrix.one_dot_product Matrix.one_dotProduct end MulOneClass section NonUnitalNonAssocSemiring variable [NonUnitalNonAssocSemiring α] (u v w : m → α) (x y : n → α) @[simp] theorem dotProduct_zero : v ⬝ᵥ 0 = 0 := by simp [dotProduct] #align matrix.dot_product_zero Matrix.dotProduct_zero @[simp] theorem dotProduct_zero' : (v ⬝ᵥ fun _ => 0) = 0 := dotProduct_zero v #align matrix.dot_product_zero' Matrix.dotProduct_zero' @[simp] theorem zero_dotProduct : 0 ⬝ᵥ v = 0 := by simp [dotProduct] #align matrix.zero_dot_product Matrix.zero_dotProduct @[simp] theorem zero_dotProduct' : (fun _ => (0 : α)) ⬝ᵥ v = 0 := zero_dotProduct v #align matrix.zero_dot_product' Matrix.zero_dotProduct' @[simp] theorem add_dotProduct : (u + v) ⬝ᵥ w = u ⬝ᵥ w + v ⬝ᵥ w := by simp [dotProduct, add_mul, Finset.sum_add_distrib] #align matrix.add_dot_product Matrix.add_dotProduct @[simp] theorem dotProduct_add : u ⬝ᵥ (v + w) = u ⬝ᵥ v + u ⬝ᵥ w := by simp [dotProduct, mul_add, Finset.sum_add_distrib] #align matrix.dot_product_add Matrix.dotProduct_add @[simp] theorem sum_elim_dotProduct_sum_elim : Sum.elim u x ⬝ᵥ Sum.elim v y = u ⬝ᵥ v + x ⬝ᵥ y := by simp [dotProduct] #align matrix.sum_elim_dot_product_sum_elim Matrix.sum_elim_dotProduct_sum_elim /-- Permuting a vector on the left of a dot product can be transferred to the right. -/ @[simp] theorem comp_equiv_symm_dotProduct (e : m ≃ n) : u ∘ e.symm ⬝ᵥ x = u ⬝ᵥ x ∘ e := (e.sum_comp _).symm.trans <| Finset.sum_congr rfl fun _ _ => by simp only [Function.comp, Equiv.symm_apply_apply] #align matrix.comp_equiv_symm_dot_product Matrix.comp_equiv_symm_dotProduct /-- Permuting a vector on the right of a dot product can be transferred to the left. -/ @[simp] theorem dotProduct_comp_equiv_symm (e : n ≃ m) : u ⬝ᵥ x ∘ e.symm = u ∘ e ⬝ᵥ x := by simpa only [Equiv.symm_symm] using (comp_equiv_symm_dotProduct u x e.symm).symm #align matrix.dot_product_comp_equiv_symm Matrix.dotProduct_comp_equiv_symm /-- Permuting vectors on both sides of a dot product is a no-op. -/ @[simp] theorem comp_equiv_dotProduct_comp_equiv (e : m ≃ n) : x ∘ e ⬝ᵥ y ∘ e = x ⬝ᵥ y := by -- Porting note: was `simp only` with all three lemmas rw [← dotProduct_comp_equiv_symm]; simp only [Function.comp, Equiv.apply_symm_apply] #align matrix.comp_equiv_dot_product_comp_equiv Matrix.comp_equiv_dotProduct_comp_equiv end NonUnitalNonAssocSemiring section NonUnitalNonAssocSemiringDecidable variable [DecidableEq m] [NonUnitalNonAssocSemiring α] (u v w : m → α) @[simp] theorem diagonal_dotProduct (i : m) : diagonal v i ⬝ᵥ w = v i * w i := by have : ∀ j ≠ i, diagonal v i j * w j = 0 := fun j hij => by simp [diagonal_apply_ne' _ hij] convert Finset.sum_eq_single i (fun j _ => this j) _ using 1 <;> simp #align matrix.diagonal_dot_product Matrix.diagonal_dotProduct @[simp] theorem dotProduct_diagonal (i : m) : v ⬝ᵥ diagonal w i = v i * w i := by have : ∀ j ≠ i, v j * diagonal w i j = 0 := fun j hij => by simp [diagonal_apply_ne' _ hij] convert Finset.sum_eq_single i (fun j _ => this j) _ using 1 <;> simp #align matrix.dot_product_diagonal Matrix.dotProduct_diagonal @[simp] theorem dotProduct_diagonal' (i : m) : (v ⬝ᵥ fun j => diagonal w j i) = v i * w i := by have : ∀ j ≠ i, v j * diagonal w j i = 0 := fun j hij => by simp [diagonal_apply_ne _ hij] convert Finset.sum_eq_single i (fun j _ => this j) _ using 1 <;> simp #align matrix.dot_product_diagonal' Matrix.dotProduct_diagonal' @[simp] theorem single_dotProduct (x : α) (i : m) : Pi.single i x ⬝ᵥ v = x * v i := by -- Porting note: (implicit arg) added `(f := fun _ => α)` have : ∀ j ≠ i, Pi.single (f := fun _ => α) i x j * v j = 0 := fun j hij => by simp [Pi.single_eq_of_ne hij] convert Finset.sum_eq_single i (fun j _ => this j) _ using 1 <;> simp #align matrix.single_dot_product Matrix.single_dotProduct @[simp] theorem dotProduct_single (x : α) (i : m) : v ⬝ᵥ Pi.single i x = v i * x := by -- Porting note: (implicit arg) added `(f := fun _ => α)` have : ∀ j ≠ i, v j * Pi.single (f := fun _ => α) i x j = 0 := fun j hij => by simp [Pi.single_eq_of_ne hij] convert Finset.sum_eq_single i (fun j _ => this j) _ using 1 <;> simp #align matrix.dot_product_single Matrix.dotProduct_single end NonUnitalNonAssocSemiringDecidable section NonAssocSemiring variable [NonAssocSemiring α] @[simp] theorem one_dotProduct_one : (1 : n → α) ⬝ᵥ 1 = Fintype.card n := by simp [dotProduct] #align matrix.one_dot_product_one Matrix.one_dotProduct_one end NonAssocSemiring section NonUnitalNonAssocRing variable [NonUnitalNonAssocRing α] (u v w : m → α) @[simp] theorem neg_dotProduct : -v ⬝ᵥ w = -(v ⬝ᵥ w) := by simp [dotProduct] #align matrix.neg_dot_product Matrix.neg_dotProduct @[simp] theorem dotProduct_neg : v ⬝ᵥ -w = -(v ⬝ᵥ w) := by simp [dotProduct] #align matrix.dot_product_neg Matrix.dotProduct_neg lemma neg_dotProduct_neg : -v ⬝ᵥ -w = v ⬝ᵥ w := by rw [neg_dotProduct, dotProduct_neg, neg_neg] @[simp] theorem sub_dotProduct : (u - v) ⬝ᵥ w = u ⬝ᵥ w - v ⬝ᵥ w := by simp [sub_eq_add_neg] #align matrix.sub_dot_product Matrix.sub_dotProduct @[simp] theorem dotProduct_sub : u ⬝ᵥ (v - w) = u ⬝ᵥ v - u ⬝ᵥ w := by simp [sub_eq_add_neg] #align matrix.dot_product_sub Matrix.dotProduct_sub end NonUnitalNonAssocRing section DistribMulAction variable [Monoid R] [Mul α] [AddCommMonoid α] [DistribMulAction R α] @[simp] theorem smul_dotProduct [IsScalarTower R α α] (x : R) (v w : m → α) : x • v ⬝ᵥ w = x • (v ⬝ᵥ w) := by simp [dotProduct, Finset.smul_sum, smul_mul_assoc] #align matrix.smul_dot_product Matrix.smul_dotProduct @[simp] theorem dotProduct_smul [SMulCommClass R α α] (x : R) (v w : m → α) : v ⬝ᵥ x • w = x • (v ⬝ᵥ w) := by simp [dotProduct, Finset.smul_sum, mul_smul_comm] #align matrix.dot_product_smul Matrix.dotProduct_smul end DistribMulAction section StarRing variable [NonUnitalSemiring α] [StarRing α] (v w : m → α) theorem star_dotProduct_star : star v ⬝ᵥ star w = star (w ⬝ᵥ v) := by simp [dotProduct] #align matrix.star_dot_product_star Matrix.star_dotProduct_star theorem star_dotProduct : star v ⬝ᵥ w = star (star w ⬝ᵥ v) := by simp [dotProduct] #align matrix.star_dot_product Matrix.star_dotProduct theorem dotProduct_star : v ⬝ᵥ star w = star (w ⬝ᵥ star v) := by simp [dotProduct] #align matrix.dot_product_star Matrix.dotProduct_star end StarRing end DotProduct open Matrix /-- `M * N` is the usual product of matrices `M` and `N`, i.e. we have that `(M * N) i k` is the dot product of the `i`-th row of `M` by the `k`-th column of `N`. This is currently only defined when `m` is finite. -/ -- We want to be lower priority than `instHMul`, but without this we can't have operands with -- implicit dimensions. @[default_instance 100] instance [Fintype m] [Mul α] [AddCommMonoid α] : HMul (Matrix l m α) (Matrix m n α) (Matrix l n α) where hMul M N := fun i k => (fun j => M i j) ⬝ᵥ fun j => N j k #align matrix.mul HMul.hMul theorem mul_apply [Fintype m] [Mul α] [AddCommMonoid α] {M : Matrix l m α} {N : Matrix m n α} {i k} : (M * N) i k = ∑ j, M i j * N j k := rfl #align matrix.mul_apply Matrix.mul_apply instance [Fintype n] [Mul α] [AddCommMonoid α] : Mul (Matrix n n α) where mul M N := M * N #noalign matrix.mul_eq_mul theorem mul_apply' [Fintype m] [Mul α] [AddCommMonoid α] {M : Matrix l m α} {N : Matrix m n α} {i k} : (M * N) i k = (fun j => M i j) ⬝ᵥ fun j => N j k := rfl #align matrix.mul_apply' Matrix.mul_apply' theorem sum_apply [AddCommMonoid α] (i : m) (j : n) (s : Finset β) (g : β → Matrix m n α) : (∑ c ∈ s, g c) i j = ∑ c ∈ s, g c i j := (congr_fun (s.sum_apply i g) j).trans (s.sum_apply j _) #align matrix.sum_apply Matrix.sum_apply theorem two_mul_expl {R : Type*} [CommRing R] (A B : Matrix (Fin 2) (Fin 2) R) : (A * B) 0 0 = A 0 0 * B 0 0 + A 0 1 * B 1 0 ∧ (A * B) 0 1 = A 0 0 * B 0 1 + A 0 1 * B 1 1 ∧ (A * B) 1 0 = A 1 0 * B 0 0 + A 1 1 * B 1 0 ∧ (A * B) 1 1 = A 1 0 * B 0 1 + A 1 1 * B 1 1 := by refine ⟨?_, ?_, ?_, ?_⟩ <;> · rw [Matrix.mul_apply, Finset.sum_fin_eq_sum_range, Finset.sum_range_succ, Finset.sum_range_succ] simp #align matrix.two_mul_expl Matrix.two_mul_expl section AddCommMonoid variable [AddCommMonoid α] [Mul α] @[simp] theorem smul_mul [Fintype n] [Monoid R] [DistribMulAction R α] [IsScalarTower R α α] (a : R) (M : Matrix m n α) (N : Matrix n l α) : (a • M) * N = a • (M * N) := by ext apply smul_dotProduct a #align matrix.smul_mul Matrix.smul_mul @[simp] theorem mul_smul [Fintype n] [Monoid R] [DistribMulAction R α] [SMulCommClass R α α] (M : Matrix m n α) (a : R) (N : Matrix n l α) : M * (a • N) = a • (M * N) := by ext apply dotProduct_smul #align matrix.mul_smul Matrix.mul_smul end AddCommMonoid section NonUnitalNonAssocSemiring variable [NonUnitalNonAssocSemiring α] @[simp] protected theorem mul_zero [Fintype n] (M : Matrix m n α) : M * (0 : Matrix n o α) = 0 := by ext apply dotProduct_zero #align matrix.mul_zero Matrix.mul_zero @[simp] protected theorem zero_mul [Fintype m] (M : Matrix m n α) : (0 : Matrix l m α) * M = 0 := by ext apply zero_dotProduct #align matrix.zero_mul Matrix.zero_mul protected theorem mul_add [Fintype n] (L : Matrix m n α) (M N : Matrix n o α) : L * (M + N) = L * M + L * N := by ext apply dotProduct_add #align matrix.mul_add Matrix.mul_add protected theorem add_mul [Fintype m] (L M : Matrix l m α) (N : Matrix m n α) : (L + M) * N = L * N + M * N := by ext apply add_dotProduct #align matrix.add_mul Matrix.add_mul instance nonUnitalNonAssocSemiring [Fintype n] : NonUnitalNonAssocSemiring (Matrix n n α) := { Matrix.addCommMonoid with mul_zero := Matrix.mul_zero zero_mul := Matrix.zero_mul left_distrib := Matrix.mul_add right_distrib := Matrix.add_mul } @[simp] theorem diagonal_mul [Fintype m] [DecidableEq m] (d : m → α) (M : Matrix m n α) (i j) : (diagonal d * M) i j = d i * M i j := diagonal_dotProduct _ _ _ #align matrix.diagonal_mul Matrix.diagonal_mul @[simp] theorem mul_diagonal [Fintype n] [DecidableEq n] (d : n → α) (M : Matrix m n α) (i j) : (M * diagonal d) i j = M i j * d j := by rw [← diagonal_transpose] apply dotProduct_diagonal #align matrix.mul_diagonal Matrix.mul_diagonal @[simp] theorem diagonal_mul_diagonal [Fintype n] [DecidableEq n] (d₁ d₂ : n → α) : diagonal d₁ * diagonal d₂ = diagonal fun i => d₁ i * d₂ i := by ext i j by_cases h : i = j <;> simp [h] #align matrix.diagonal_mul_diagonal Matrix.diagonal_mul_diagonal theorem diagonal_mul_diagonal' [Fintype n] [DecidableEq n] (d₁ d₂ : n → α) : diagonal d₁ * diagonal d₂ = diagonal fun i => d₁ i * d₂ i := diagonal_mul_diagonal _ _ #align matrix.diagonal_mul_diagonal' Matrix.diagonal_mul_diagonal' theorem smul_eq_diagonal_mul [Fintype m] [DecidableEq m] (M : Matrix m n α) (a : α) : a • M = (diagonal fun _ => a) * M := by ext simp #align matrix.smul_eq_diagonal_mul Matrix.smul_eq_diagonal_mul theorem op_smul_eq_mul_diagonal [Fintype n] [DecidableEq n] (M : Matrix m n α) (a : α) : MulOpposite.op a • M = M * (diagonal fun _ : n => a) := by ext simp /-- Left multiplication by a matrix, as an `AddMonoidHom` from matrices to matrices. -/ @[simps] def addMonoidHomMulLeft [Fintype m] (M : Matrix l m α) : Matrix m n α →+ Matrix l n α where toFun x := M * x map_zero' := Matrix.mul_zero _ map_add' := Matrix.mul_add _ #align matrix.add_monoid_hom_mul_left Matrix.addMonoidHomMulLeft /-- Right multiplication by a matrix, as an `AddMonoidHom` from matrices to matrices. -/ @[simps] def addMonoidHomMulRight [Fintype m] (M : Matrix m n α) : Matrix l m α →+ Matrix l n α where toFun x := x * M map_zero' := Matrix.zero_mul _ map_add' _ _ := Matrix.add_mul _ _ _ #align matrix.add_monoid_hom_mul_right Matrix.addMonoidHomMulRight protected theorem sum_mul [Fintype m] (s : Finset β) (f : β → Matrix l m α) (M : Matrix m n α) : (∑ a ∈ s, f a) * M = ∑ a ∈ s, f a * M := map_sum (addMonoidHomMulRight M) f s #align matrix.sum_mul Matrix.sum_mul protected theorem mul_sum [Fintype m] (s : Finset β) (f : β → Matrix m n α) (M : Matrix l m α) : (M * ∑ a ∈ s, f a) = ∑ a ∈ s, M * f a := map_sum (addMonoidHomMulLeft M) f s #align matrix.mul_sum Matrix.mul_sum /-- This instance enables use with `smul_mul_assoc`. -/ instance Semiring.isScalarTower [Fintype n] [Monoid R] [DistribMulAction R α] [IsScalarTower R α α] : IsScalarTower R (Matrix n n α) (Matrix n n α) := ⟨fun r m n => Matrix.smul_mul r m n⟩ #align matrix.semiring.is_scalar_tower Matrix.Semiring.isScalarTower /-- This instance enables use with `mul_smul_comm`. -/ instance Semiring.smulCommClass [Fintype n] [Monoid R] [DistribMulAction R α] [SMulCommClass R α α] : SMulCommClass R (Matrix n n α) (Matrix n n α) := ⟨fun r m n => (Matrix.mul_smul m r n).symm⟩ #align matrix.semiring.smul_comm_class Matrix.Semiring.smulCommClass end NonUnitalNonAssocSemiring section NonAssocSemiring variable [NonAssocSemiring α] @[simp] protected theorem one_mul [Fintype m] [DecidableEq m] (M : Matrix m n α) : (1 : Matrix m m α) * M = M := by ext rw [← diagonal_one, diagonal_mul, one_mul] #align matrix.one_mul Matrix.one_mul @[simp] protected theorem mul_one [Fintype n] [DecidableEq n] (M : Matrix m n α) : M * (1 : Matrix n n α) = M := by ext rw [← diagonal_one, mul_diagonal, mul_one] #align matrix.mul_one Matrix.mul_one instance nonAssocSemiring [Fintype n] [DecidableEq n] : NonAssocSemiring (Matrix n n α) := { Matrix.nonUnitalNonAssocSemiring, Matrix.instAddCommMonoidWithOne with one := 1 one_mul := Matrix.one_mul mul_one := Matrix.mul_one } @[simp] theorem map_mul [Fintype n] {L : Matrix m n α} {M : Matrix n o α} [NonAssocSemiring β] {f : α →+* β} : (L * M).map f = L.map f * M.map f := by ext simp [mul_apply, map_sum] #align matrix.map_mul Matrix.map_mul theorem smul_one_eq_diagonal [DecidableEq m] (a : α) : a • (1 : Matrix m m α) = diagonal fun _ => a := by simp_rw [← diagonal_one, ← diagonal_smul, Pi.smul_def, smul_eq_mul, mul_one] theorem op_smul_one_eq_diagonal [DecidableEq m] (a : α) : MulOpposite.op a • (1 : Matrix m m α) = diagonal fun _ => a := by simp_rw [← diagonal_one, ← diagonal_smul, Pi.smul_def, op_smul_eq_mul, one_mul] variable (α n) /-- `Matrix.diagonal` as a `RingHom`. -/ @[simps] def diagonalRingHom [Fintype n] [DecidableEq n] : (n → α) →+* Matrix n n α := { diagonalAddMonoidHom n α with toFun := diagonal map_one' := diagonal_one map_mul' := fun _ _ => (diagonal_mul_diagonal' _ _).symm } #align matrix.diagonal_ring_hom Matrix.diagonalRingHom end NonAssocSemiring section NonUnitalSemiring variable [NonUnitalSemiring α] [Fintype m] [Fintype n] protected theorem mul_assoc (L : Matrix l m α) (M : Matrix m n α) (N : Matrix n o α) : L * M * N = L * (M * N) := by ext apply dotProduct_assoc #align matrix.mul_assoc Matrix.mul_assoc instance nonUnitalSemiring : NonUnitalSemiring (Matrix n n α) := { Matrix.nonUnitalNonAssocSemiring with mul_assoc := Matrix.mul_assoc } end NonUnitalSemiring section Semiring variable [Semiring α] instance semiring [Fintype n] [DecidableEq n] : Semiring (Matrix n n α) := { Matrix.nonUnitalSemiring, Matrix.nonAssocSemiring with } end Semiring section NonUnitalNonAssocRing variable [NonUnitalNonAssocRing α] [Fintype n] @[simp] protected theorem neg_mul (M : Matrix m n α) (N : Matrix n o α) : (-M) * N = -(M * N) := by ext apply neg_dotProduct #align matrix.neg_mul Matrix.neg_mul @[simp] protected theorem mul_neg (M : Matrix m n α) (N : Matrix n o α) : M * (-N) = -(M * N) := by ext apply dotProduct_neg #align matrix.mul_neg Matrix.mul_neg protected theorem sub_mul (M M' : Matrix m n α) (N : Matrix n o α) : (M - M') * N = M * N - M' * N := by rw [sub_eq_add_neg, Matrix.add_mul, Matrix.neg_mul, sub_eq_add_neg] #align matrix.sub_mul Matrix.sub_mul protected theorem mul_sub (M : Matrix m n α) (N N' : Matrix n o α) : M * (N - N') = M * N - M * N' := by rw [sub_eq_add_neg, Matrix.mul_add, Matrix.mul_neg, sub_eq_add_neg] #align matrix.mul_sub Matrix.mul_sub instance nonUnitalNonAssocRing : NonUnitalNonAssocRing (Matrix n n α) := { Matrix.nonUnitalNonAssocSemiring, Matrix.addCommGroup with } end NonUnitalNonAssocRing instance instNonUnitalRing [Fintype n] [NonUnitalRing α] : NonUnitalRing (Matrix n n α) := { Matrix.nonUnitalSemiring, Matrix.addCommGroup with } #align matrix.non_unital_ring Matrix.instNonUnitalRing instance instNonAssocRing [Fintype n] [DecidableEq n] [NonAssocRing α] : NonAssocRing (Matrix n n α) := { Matrix.nonAssocSemiring, Matrix.instAddCommGroupWithOne with } #align matrix.non_assoc_ring Matrix.instNonAssocRing instance instRing [Fintype n] [DecidableEq n] [Ring α] : Ring (Matrix n n α) := { Matrix.semiring, Matrix.instAddCommGroupWithOne with } #align matrix.ring Matrix.instRing section Semiring variable [Semiring α] theorem diagonal_pow [Fintype n] [DecidableEq n] (v : n → α) (k : ℕ) : diagonal v ^ k = diagonal (v ^ k) := (map_pow (diagonalRingHom n α) v k).symm #align matrix.diagonal_pow Matrix.diagonal_pow @[simp] theorem mul_mul_left [Fintype n] (M : Matrix m n α) (N : Matrix n o α) (a : α) : (of fun i j => a * M i j) * N = a • (M * N) := smul_mul a M N #align matrix.mul_mul_left Matrix.mul_mul_left /-- The ring homomorphism `α →+* Matrix n n α` sending `a` to the diagonal matrix with `a` on the diagonal. -/ def scalar (n : Type u) [DecidableEq n] [Fintype n] : α →+* Matrix n n α := (diagonalRingHom n α).comp <| Pi.constRingHom n α #align matrix.scalar Matrix.scalar section Scalar variable [DecidableEq n] [Fintype n] @[simp] theorem scalar_apply (a : α) : scalar n a = diagonal fun _ => a := rfl #align matrix.coe_scalar Matrix.scalar_applyₓ #noalign matrix.scalar_apply_eq #noalign matrix.scalar_apply_ne theorem scalar_inj [Nonempty n] {r s : α} : scalar n r = scalar n s ↔ r = s := (diagonal_injective.comp Function.const_injective).eq_iff #align matrix.scalar_inj Matrix.scalar_inj theorem scalar_commute_iff {r : α} {M : Matrix n n α} : Commute (scalar n r) M ↔ r • M = MulOpposite.op r • M := by simp_rw [Commute, SemiconjBy, scalar_apply, ← smul_eq_diagonal_mul, ← op_smul_eq_mul_diagonal] theorem scalar_commute (r : α) (hr : ∀ r', Commute r r') (M : Matrix n n α) : Commute (scalar n r) M := scalar_commute_iff.2 <| ext fun _ _ => hr _ #align matrix.scalar.commute Matrix.scalar_commuteₓ end Scalar end Semiring section CommSemiring variable [CommSemiring α] theorem smul_eq_mul_diagonal [Fintype n] [DecidableEq n] (M : Matrix m n α) (a : α) : a • M = M * diagonal fun _ => a := by ext simp [mul_comm] #align matrix.smul_eq_mul_diagonal Matrix.smul_eq_mul_diagonal @[simp] theorem mul_mul_right [Fintype n] (M : Matrix m n α) (N : Matrix n o α) (a : α) : (M * of fun i j => a * N i j) = a • (M * N) := mul_smul M a N #align matrix.mul_mul_right Matrix.mul_mul_right end CommSemiring section Algebra variable [Fintype n] [DecidableEq n] variable [CommSemiring R] [Semiring α] [Semiring β] [Algebra R α] [Algebra R β] instance instAlgebra : Algebra R (Matrix n n α) where toRingHom := (Matrix.scalar n).comp (algebraMap R α) commutes' r x := scalar_commute _ (fun r' => Algebra.commutes _ _) _ smul_def' r x := by ext; simp [Matrix.scalar, Algebra.smul_def r] #align matrix.algebra Matrix.instAlgebra theorem algebraMap_matrix_apply {r : R} {i j : n} : algebraMap R (Matrix n n α) r i j = if i = j then algebraMap R α r else 0 := by dsimp [algebraMap, Algebra.toRingHom, Matrix.scalar] split_ifs with h <;> simp [h, Matrix.one_apply_ne] #align matrix.algebra_map_matrix_apply Matrix.algebraMap_matrix_apply theorem algebraMap_eq_diagonal (r : R) : algebraMap R (Matrix n n α) r = diagonal (algebraMap R (n → α) r) := rfl #align matrix.algebra_map_eq_diagonal Matrix.algebraMap_eq_diagonal #align matrix.algebra_map_eq_smul Algebra.algebraMap_eq_smul_one theorem algebraMap_eq_diagonalRingHom : algebraMap R (Matrix n n α) = (diagonalRingHom n α).comp (algebraMap R _) := rfl #align matrix.algebra_map_eq_diagonal_ring_hom Matrix.algebraMap_eq_diagonalRingHom @[simp] theorem map_algebraMap (r : R) (f : α → β) (hf : f 0 = 0) (hf₂ : f (algebraMap R α r) = algebraMap R β r) : (algebraMap R (Matrix n n α) r).map f = algebraMap R (Matrix n n β) r := by rw [algebraMap_eq_diagonal, algebraMap_eq_diagonal, diagonal_map hf] -- Porting note: (congr) the remaining proof was -- ``` -- congr 1 -- simp only [hf₂, Pi.algebraMap_apply] -- ``` -- But some `congr 1` doesn't quite work. simp only [Pi.algebraMap_apply, diagonal_eq_diagonal_iff] intro rw [hf₂] #align matrix.map_algebra_map Matrix.map_algebraMap variable (R) /-- `Matrix.diagonal` as an `AlgHom`. -/ @[simps] def diagonalAlgHom : (n → α) →ₐ[R] Matrix n n α := { diagonalRingHom n α with toFun := diagonal commutes' := fun r => (algebraMap_eq_diagonal r).symm } #align matrix.diagonal_alg_hom Matrix.diagonalAlgHom end Algebra end Matrix /-! ### Bundled versions of `Matrix.map` -/ namespace Equiv /-- The `Equiv` between spaces of matrices induced by an `Equiv` between their coefficients. This is `Matrix.map` as an `Equiv`. -/ @[simps apply] def mapMatrix (f : α ≃ β) : Matrix m n α ≃ Matrix m n β where toFun M := M.map f invFun M := M.map f.symm left_inv _ := Matrix.ext fun _ _ => f.symm_apply_apply _ right_inv _ := Matrix.ext fun _ _ => f.apply_symm_apply _ #align equiv.map_matrix Equiv.mapMatrix @[simp] theorem mapMatrix_refl : (Equiv.refl α).mapMatrix = Equiv.refl (Matrix m n α) := rfl #align equiv.map_matrix_refl Equiv.mapMatrix_refl @[simp] theorem mapMatrix_symm (f : α ≃ β) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m n β ≃ _) := rfl #align equiv.map_matrix_symm Equiv.mapMatrix_symm @[simp] theorem mapMatrix_trans (f : α ≃ β) (g : β ≃ γ) : f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m n α ≃ _) := rfl #align equiv.map_matrix_trans Equiv.mapMatrix_trans end Equiv namespace AddMonoidHom variable [AddZeroClass α] [AddZeroClass β] [AddZeroClass γ] /-- The `AddMonoidHom` between spaces of matrices induced by an `AddMonoidHom` between their coefficients. This is `Matrix.map` as an `AddMonoidHom`. -/ @[simps] def mapMatrix (f : α →+ β) : Matrix m n α →+ Matrix m n β where toFun M := M.map f map_zero' := Matrix.map_zero f f.map_zero map_add' := Matrix.map_add f f.map_add #align add_monoid_hom.map_matrix AddMonoidHom.mapMatrix @[simp] theorem mapMatrix_id : (AddMonoidHom.id α).mapMatrix = AddMonoidHom.id (Matrix m n α) := rfl #align add_monoid_hom.map_matrix_id AddMonoidHom.mapMatrix_id @[simp] theorem mapMatrix_comp (f : β →+ γ) (g : α →+ β) : f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m n α →+ _) := rfl #align add_monoid_hom.map_matrix_comp AddMonoidHom.mapMatrix_comp end AddMonoidHom namespace AddEquiv variable [Add α] [Add β] [Add γ] /-- The `AddEquiv` between spaces of matrices induced by an `AddEquiv` between their coefficients. This is `Matrix.map` as an `AddEquiv`. -/ @[simps apply] def mapMatrix (f : α ≃+ β) : Matrix m n α ≃+ Matrix m n β := { f.toEquiv.mapMatrix with toFun := fun M => M.map f invFun := fun M => M.map f.symm map_add' := Matrix.map_add f f.map_add } #align add_equiv.map_matrix AddEquiv.mapMatrix @[simp] theorem mapMatrix_refl : (AddEquiv.refl α).mapMatrix = AddEquiv.refl (Matrix m n α) := rfl #align add_equiv.map_matrix_refl AddEquiv.mapMatrix_refl @[simp] theorem mapMatrix_symm (f : α ≃+ β) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m n β ≃+ _) := rfl #align add_equiv.map_matrix_symm AddEquiv.mapMatrix_symm @[simp] theorem mapMatrix_trans (f : α ≃+ β) (g : β ≃+ γ) : f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m n α ≃+ _) := rfl #align add_equiv.map_matrix_trans AddEquiv.mapMatrix_trans end AddEquiv namespace LinearMap variable [Semiring R] [AddCommMonoid α] [AddCommMonoid β] [AddCommMonoid γ] variable [Module R α] [Module R β] [Module R γ] /-- The `LinearMap` between spaces of matrices induced by a `LinearMap` between their coefficients. This is `Matrix.map` as a `LinearMap`. -/ @[simps] def mapMatrix (f : α →ₗ[R] β) : Matrix m n α →ₗ[R] Matrix m n β where toFun M := M.map f map_add' := Matrix.map_add f f.map_add map_smul' r := Matrix.map_smul f r (f.map_smul r) #align linear_map.map_matrix LinearMap.mapMatrix @[simp] theorem mapMatrix_id : LinearMap.id.mapMatrix = (LinearMap.id : Matrix m n α →ₗ[R] _) := rfl #align linear_map.map_matrix_id LinearMap.mapMatrix_id @[simp] theorem mapMatrix_comp (f : β →ₗ[R] γ) (g : α →ₗ[R] β) : f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m n α →ₗ[R] _) := rfl #align linear_map.map_matrix_comp LinearMap.mapMatrix_comp end LinearMap namespace LinearEquiv variable [Semiring R] [AddCommMonoid α] [AddCommMonoid β] [AddCommMonoid γ] variable [Module R α] [Module R β] [Module R γ] /-- The `LinearEquiv` between spaces of matrices induced by a `LinearEquiv` between their coefficients. This is `Matrix.map` as a `LinearEquiv`. -/ @[simps apply] def mapMatrix (f : α ≃ₗ[R] β) : Matrix m n α ≃ₗ[R] Matrix m n β := { f.toEquiv.mapMatrix, f.toLinearMap.mapMatrix with toFun := fun M => M.map f invFun := fun M => M.map f.symm } #align linear_equiv.map_matrix LinearEquiv.mapMatrix @[simp] theorem mapMatrix_refl : (LinearEquiv.refl R α).mapMatrix = LinearEquiv.refl R (Matrix m n α) := rfl #align linear_equiv.map_matrix_refl LinearEquiv.mapMatrix_refl @[simp] theorem mapMatrix_symm (f : α ≃ₗ[R] β) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m n β ≃ₗ[R] _) := rfl #align linear_equiv.map_matrix_symm LinearEquiv.mapMatrix_symm @[simp] theorem mapMatrix_trans (f : α ≃ₗ[R] β) (g : β ≃ₗ[R] γ) : f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m n α ≃ₗ[R] _) := rfl #align linear_equiv.map_matrix_trans LinearEquiv.mapMatrix_trans end LinearEquiv namespace RingHom variable [Fintype m] [DecidableEq m] variable [NonAssocSemiring α] [NonAssocSemiring β] [NonAssocSemiring γ] /-- The `RingHom` between spaces of square matrices induced by a `RingHom` between their coefficients. This is `Matrix.map` as a `RingHom`. -/ @[simps] def mapMatrix (f : α →+* β) : Matrix m m α →+* Matrix m m β := { f.toAddMonoidHom.mapMatrix with toFun := fun M => M.map f map_one' := by simp map_mul' := fun L M => Matrix.map_mul } #align ring_hom.map_matrix RingHom.mapMatrix @[simp] theorem mapMatrix_id : (RingHom.id α).mapMatrix = RingHom.id (Matrix m m α) := rfl #align ring_hom.map_matrix_id RingHom.mapMatrix_id @[simp] theorem mapMatrix_comp (f : β →+* γ) (g : α →+* β) : f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m m α →+* _) := rfl #align ring_hom.map_matrix_comp RingHom.mapMatrix_comp end RingHom namespace RingEquiv variable [Fintype m] [DecidableEq m] variable [NonAssocSemiring α] [NonAssocSemiring β] [NonAssocSemiring γ] /-- The `RingEquiv` between spaces of square matrices induced by a `RingEquiv` between their coefficients. This is `Matrix.map` as a `RingEquiv`. -/ @[simps apply] def mapMatrix (f : α ≃+* β) : Matrix m m α ≃+* Matrix m m β := { f.toRingHom.mapMatrix, f.toAddEquiv.mapMatrix with toFun := fun M => M.map f invFun := fun M => M.map f.symm } #align ring_equiv.map_matrix RingEquiv.mapMatrix @[simp] theorem mapMatrix_refl : (RingEquiv.refl α).mapMatrix = RingEquiv.refl (Matrix m m α) := rfl #align ring_equiv.map_matrix_refl RingEquiv.mapMatrix_refl @[simp] theorem mapMatrix_symm (f : α ≃+* β) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m m β ≃+* _) := rfl #align ring_equiv.map_matrix_symm RingEquiv.mapMatrix_symm @[simp] theorem mapMatrix_trans (f : α ≃+* β) (g : β ≃+* γ) : f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m m α ≃+* _) := rfl #align ring_equiv.map_matrix_trans RingEquiv.mapMatrix_trans end RingEquiv namespace AlgHom variable [Fintype m] [DecidableEq m] variable [CommSemiring R] [Semiring α] [Semiring β] [Semiring γ] variable [Algebra R α] [Algebra R β] [Algebra R γ] /-- The `AlgHom` between spaces of square matrices induced by an `AlgHom` between their coefficients. This is `Matrix.map` as an `AlgHom`. -/ @[simps] def mapMatrix (f : α →ₐ[R] β) : Matrix m m α →ₐ[R] Matrix m m β := { f.toRingHom.mapMatrix with toFun := fun M => M.map f commutes' := fun r => Matrix.map_algebraMap r f f.map_zero (f.commutes r) } #align alg_hom.map_matrix AlgHom.mapMatrix @[simp] theorem mapMatrix_id : (AlgHom.id R α).mapMatrix = AlgHom.id R (Matrix m m α) := rfl #align alg_hom.map_matrix_id AlgHom.mapMatrix_id @[simp] theorem mapMatrix_comp (f : β →ₐ[R] γ) (g : α →ₐ[R] β) : f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m m α →ₐ[R] _) := rfl #align alg_hom.map_matrix_comp AlgHom.mapMatrix_comp end AlgHom namespace AlgEquiv variable [Fintype m] [DecidableEq m] variable [CommSemiring R] [Semiring α] [Semiring β] [Semiring γ] variable [Algebra R α] [Algebra R β] [Algebra R γ] /-- The `AlgEquiv` between spaces of square matrices induced by an `AlgEquiv` between their coefficients. This is `Matrix.map` as an `AlgEquiv`. -/ @[simps apply] def mapMatrix (f : α ≃ₐ[R] β) : Matrix m m α ≃ₐ[R] Matrix m m β := { f.toAlgHom.mapMatrix, f.toRingEquiv.mapMatrix with toFun := fun M => M.map f invFun := fun M => M.map f.symm } #align alg_equiv.map_matrix AlgEquiv.mapMatrix @[simp] theorem mapMatrix_refl : AlgEquiv.refl.mapMatrix = (AlgEquiv.refl : Matrix m m α ≃ₐ[R] _) := rfl #align alg_equiv.map_matrix_refl AlgEquiv.mapMatrix_refl @[simp] theorem mapMatrix_symm (f : α ≃ₐ[R] β) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m m β ≃ₐ[R] _) := rfl #align alg_equiv.map_matrix_symm AlgEquiv.mapMatrix_symm @[simp] theorem mapMatrix_trans (f : α ≃ₐ[R] β) (g : β ≃ₐ[R] γ) : f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m m α ≃ₐ[R] _) := rfl #align alg_equiv.map_matrix_trans AlgEquiv.mapMatrix_trans end AlgEquiv open Matrix namespace Matrix /-- For two vectors `w` and `v`, `vecMulVec w v i j` is defined to be `w i * v j`. Put another way, `vecMulVec w v` is exactly `col w * row v`. -/ def vecMulVec [Mul α] (w : m → α) (v : n → α) : Matrix m n α := of fun x y => w x * v y #align matrix.vec_mul_vec Matrix.vecMulVec -- TODO: set as an equation lemma for `vecMulVec`, see mathlib4#3024 theorem vecMulVec_apply [Mul α] (w : m → α) (v : n → α) (i j) : vecMulVec w v i j = w i * v j := rfl #align matrix.vec_mul_vec_apply Matrix.vecMulVec_apply section NonUnitalNonAssocSemiring variable [NonUnitalNonAssocSemiring α] /-- `M *ᵥ v` (notation for `mulVec M v`) is the matrix-vector product of matrix `M` and vector `v`, where `v` is seen as a column vector. Put another way, `M *ᵥ v` is the vector whose entries are those of `M * col v` (see `col_mulVec`). The notation has precedence 73, which comes immediately before ` ⬝ᵥ ` for `Matrix.dotProduct`, so that `A *ᵥ v ⬝ᵥ B *ᵥ w` is parsed as `(A *ᵥ v) ⬝ᵥ (B *ᵥ w)`. -/ def mulVec [Fintype n] (M : Matrix m n α) (v : n → α) : m → α | i => (fun j => M i j) ⬝ᵥ v #align matrix.mul_vec Matrix.mulVec @[inherit_doc] scoped infixr:73 " *ᵥ " => Matrix.mulVec /-- `v ᵥ* M` (notation for `vecMul v M`) is the vector-matrix product of vector `v` and matrix `M`, where `v` is seen as a row vector. Put another way, `v ᵥ* M` is the vector whose entries are those of `row v * M` (see `row_vecMul`). The notation has precedence 73, which comes immediately before ` ⬝ᵥ ` for `Matrix.dotProduct`, so that `v ᵥ* A ⬝ᵥ w ᵥ* B` is parsed as `(v ᵥ* A) ⬝ᵥ (w ᵥ* B)`. -/ def vecMul [Fintype m] (v : m → α) (M : Matrix m n α) : n → α | j => v ⬝ᵥ fun i => M i j #align matrix.vec_mul Matrix.vecMul @[inherit_doc] scoped infixl:73 " ᵥ* " => Matrix.vecMul /-- Left multiplication by a matrix, as an `AddMonoidHom` from vectors to vectors. -/ @[simps] def mulVec.addMonoidHomLeft [Fintype n] (v : n → α) : Matrix m n α →+ m → α where toFun M := M *ᵥ v map_zero' := by ext simp [mulVec] map_add' x y := by ext m apply add_dotProduct #align matrix.mul_vec.add_monoid_hom_left Matrix.mulVec.addMonoidHomLeft /-- The `i`th row of the multiplication is the same as the `vecMul` with the `i`th row of `A`. -/ theorem mul_apply_eq_vecMul [Fintype n] (A : Matrix m n α) (B : Matrix n o α) (i : m) : (A * B) i = A i ᵥ* B := rfl theorem mulVec_diagonal [Fintype m] [DecidableEq m] (v w : m → α) (x : m) : (diagonal v *ᵥ w) x = v x * w x := diagonal_dotProduct v w x #align matrix.mul_vec_diagonal Matrix.mulVec_diagonal theorem vecMul_diagonal [Fintype m] [DecidableEq m] (v w : m → α) (x : m) : (v ᵥ* diagonal w) x = v x * w x := dotProduct_diagonal' v w x #align matrix.vec_mul_diagonal Matrix.vecMul_diagonal /-- Associate the dot product of `mulVec` to the left. -/ theorem dotProduct_mulVec [Fintype n] [Fintype m] [NonUnitalSemiring R] (v : m → R) (A : Matrix m n R) (w : n → R) : v ⬝ᵥ A *ᵥ w = v ᵥ* A ⬝ᵥ w := by simp only [dotProduct, vecMul, mulVec, Finset.mul_sum, Finset.sum_mul, mul_assoc] exact Finset.sum_comm #align matrix.dot_product_mul_vec Matrix.dotProduct_mulVec @[simp] theorem mulVec_zero [Fintype n] (A : Matrix m n α) : A *ᵥ 0 = 0 := by ext simp [mulVec] #align matrix.mul_vec_zero Matrix.mulVec_zero @[simp] theorem zero_vecMul [Fintype m] (A : Matrix m n α) : 0 ᵥ* A = 0 := by ext simp [vecMul] #align matrix.zero_vec_mul Matrix.zero_vecMul @[simp] theorem zero_mulVec [Fintype n] (v : n → α) : (0 : Matrix m n α) *ᵥ v = 0 := by ext simp [mulVec] #align matrix.zero_mul_vec Matrix.zero_mulVec @[simp] theorem vecMul_zero [Fintype m] (v : m → α) : v ᵥ* (0 : Matrix m n α) = 0 := by ext simp [vecMul] #align matrix.vec_mul_zero Matrix.vecMul_zero theorem smul_mulVec_assoc [Fintype n] [Monoid R] [DistribMulAction R α] [IsScalarTower R α α] (a : R) (A : Matrix m n α) (b : n → α) : (a • A) *ᵥ b = a • A *ᵥ b := by ext apply smul_dotProduct #align matrix.smul_mul_vec_assoc Matrix.smul_mulVec_assoc theorem mulVec_add [Fintype n] (A : Matrix m n α) (x y : n → α) : A *ᵥ (x + y) = A *ᵥ x + A *ᵥ y := by ext apply dotProduct_add #align matrix.mul_vec_add Matrix.mulVec_add theorem add_mulVec [Fintype n] (A B : Matrix m n α) (x : n → α) : (A + B) *ᵥ x = A *ᵥ x + B *ᵥ x := by ext apply add_dotProduct #align matrix.add_mul_vec Matrix.add_mulVec theorem vecMul_add [Fintype m] (A B : Matrix m n α) (x : m → α) : x ᵥ* (A + B) = x ᵥ* A + x ᵥ* B := by ext apply dotProduct_add #align matrix.vec_mul_add Matrix.vecMul_add theorem add_vecMul [Fintype m] (A : Matrix m n α) (x y : m → α) : (x + y) ᵥ* A = x ᵥ* A + y ᵥ* A := by ext apply add_dotProduct #align matrix.add_vec_mul Matrix.add_vecMul theorem vecMul_smul [Fintype n] [Monoid R] [NonUnitalNonAssocSemiring S] [DistribMulAction R S] [IsScalarTower R S S] (M : Matrix n m S) (b : R) (v : n → S) : (b • v) ᵥ* M = b • v ᵥ* M := by ext i simp only [vecMul, dotProduct, Finset.smul_sum, Pi.smul_apply, smul_mul_assoc] #align matrix.vec_mul_smul Matrix.vecMul_smul theorem mulVec_smul [Fintype n] [Monoid R] [NonUnitalNonAssocSemiring S] [DistribMulAction R S] [SMulCommClass R S S] (M : Matrix m n S) (b : R) (v : n → S) : M *ᵥ (b • v) = b • M *ᵥ v := by ext i simp only [mulVec, dotProduct, Finset.smul_sum, Pi.smul_apply, mul_smul_comm] #align matrix.mul_vec_smul Matrix.mulVec_smul @[simp] theorem mulVec_single [Fintype n] [DecidableEq n] [NonUnitalNonAssocSemiring R] (M : Matrix m n R) (j : n) (x : R) : M *ᵥ Pi.single j x = fun i => M i j * x := funext fun _ => dotProduct_single _ _ _ #align matrix.mul_vec_single Matrix.mulVec_single @[simp] theorem single_vecMul [Fintype m] [DecidableEq m] [NonUnitalNonAssocSemiring R] (M : Matrix m n R) (i : m) (x : R) : Pi.single i x ᵥ* M = fun j => x * M i j := funext fun _ => single_dotProduct _ _ _ #align matrix.single_vec_mul Matrix.single_vecMul -- @[simp] -- Porting note: not in simpNF theorem diagonal_mulVec_single [Fintype n] [DecidableEq n] [NonUnitalNonAssocSemiring R] (v : n → R) (j : n) (x : R) : diagonal v *ᵥ Pi.single j x = Pi.single j (v j * x) := by ext i rw [mulVec_diagonal] exact Pi.apply_single (fun i x => v i * x) (fun i => mul_zero _) j x i #align matrix.diagonal_mul_vec_single Matrix.diagonal_mulVec_single -- @[simp] -- Porting note: not in simpNF theorem single_vecMul_diagonal [Fintype n] [DecidableEq n] [NonUnitalNonAssocSemiring R] (v : n → R) (j : n) (x : R) : (Pi.single j x) ᵥ* (diagonal v) = Pi.single j (x * v j) := by ext i rw [vecMul_diagonal] exact Pi.apply_single (fun i x => x * v i) (fun i => zero_mul _) j x i #align matrix.single_vec_mul_diagonal Matrix.single_vecMul_diagonal end NonUnitalNonAssocSemiring section NonUnitalSemiring variable [NonUnitalSemiring α] @[simp] theorem vecMul_vecMul [Fintype n] [Fintype m] (v : m → α) (M : Matrix m n α) (N : Matrix n o α) : v ᵥ* M ᵥ* N = v ᵥ* (M * N) := by ext apply dotProduct_assoc #align matrix.vec_mul_vec_mul Matrix.vecMul_vecMul @[simp] theorem mulVec_mulVec [Fintype n] [Fintype o] (v : o → α) (M : Matrix m n α) (N : Matrix n o α) : M *ᵥ N *ᵥ v = (M * N) *ᵥ v := by ext symm apply dotProduct_assoc #align matrix.mul_vec_mul_vec Matrix.mulVec_mulVec theorem star_mulVec [Fintype n] [StarRing α] (M : Matrix m n α) (v : n → α) : star (M *ᵥ v) = star v ᵥ* Mᴴ := funext fun _ => (star_dotProduct_star _ _).symm #align matrix.star_mul_vec Matrix.star_mulVec theorem star_vecMul [Fintype m] [StarRing α] (M : Matrix m n α) (v : m → α) : star (v ᵥ* M) = Mᴴ *ᵥ star v := funext fun _ => (star_dotProduct_star _ _).symm #align matrix.star_vec_mul Matrix.star_vecMul theorem mulVec_conjTranspose [Fintype m] [StarRing α] (A : Matrix m n α) (x : m → α) : Aᴴ *ᵥ x = star (star x ᵥ* A) := funext fun _ => star_dotProduct _ _ #align matrix.mul_vec_conj_transpose Matrix.mulVec_conjTranspose theorem vecMul_conjTranspose [Fintype n] [StarRing α] (A : Matrix m n α) (x : n → α) : x ᵥ* Aᴴ = star (A *ᵥ star x) := funext fun _ => dotProduct_star _ _ #align matrix.vec_mul_conj_transpose Matrix.vecMul_conjTranspose theorem mul_mul_apply [Fintype n] (A B C : Matrix n n α) (i j : n) : (A * B * C) i j = A i ⬝ᵥ B *ᵥ (Cᵀ j) := by rw [Matrix.mul_assoc] simp only [mul_apply, dotProduct, mulVec] rfl #align matrix.mul_mul_apply Matrix.mul_mul_apply end NonUnitalSemiring section NonAssocSemiring variable [NonAssocSemiring α] theorem mulVec_one [Fintype n] (A : Matrix m n α) : A *ᵥ 1 = fun i => ∑ j, A i j := by ext; simp [mulVec, dotProduct] #align matrix.mul_vec_one Matrix.mulVec_one theorem vec_one_mul [Fintype m] (A : Matrix m n α) : 1 ᵥ* A = fun j => ∑ i, A i j := by ext; simp [vecMul, dotProduct] #align matrix.vec_one_mul Matrix.vec_one_mul variable [Fintype m] [Fintype n] [DecidableEq m] @[simp] theorem one_mulVec (v : m → α) : 1 *ᵥ v = v := by ext rw [← diagonal_one, mulVec_diagonal, one_mul] #align matrix.one_mul_vec Matrix.one_mulVec @[simp] theorem vecMul_one (v : m → α) : v ᵥ* 1 = v := by ext rw [← diagonal_one, vecMul_diagonal, mul_one] #align matrix.vec_mul_one Matrix.vecMul_one @[simp] theorem diagonal_const_mulVec (x : α) (v : m → α) : (diagonal fun _ => x) *ᵥ v = x • v := by ext; simp [mulVec_diagonal] @[simp] theorem vecMul_diagonal_const (x : α) (v : m → α) : v ᵥ* (diagonal fun _ => x) = MulOpposite.op x • v := by ext; simp [vecMul_diagonal] @[simp] theorem natCast_mulVec (x : ℕ) (v : m → α) : x *ᵥ v = (x : α) • v := diagonal_const_mulVec _ _ @[simp] theorem vecMul_natCast (x : ℕ) (v : m → α) : v ᵥ* x = MulOpposite.op (x : α) • v := vecMul_diagonal_const _ _ -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_mulVec (x : ℕ) [x.AtLeastTwo] (v : m → α) : OfNat.ofNat (no_index x) *ᵥ v = (OfNat.ofNat x : α) • v := natCast_mulVec _ _ -- See note [no_index around OfNat.ofNat] @[simp] theorem vecMul_ofNat (x : ℕ) [x.AtLeastTwo] (v : m → α) : v ᵥ* OfNat.ofNat (no_index x) = MulOpposite.op (OfNat.ofNat x : α) • v := vecMul_natCast _ _ end NonAssocSemiring section NonUnitalNonAssocRing variable [NonUnitalNonAssocRing α] theorem neg_vecMul [Fintype m] (v : m → α) (A : Matrix m n α) : (-v) ᵥ* A = - (v ᵥ* A) := by ext apply neg_dotProduct #align matrix.neg_vec_mul Matrix.neg_vecMul theorem vecMul_neg [Fintype m] (v : m → α) (A : Matrix m n α) : v ᵥ* (-A) = - (v ᵥ* A) := by ext apply dotProduct_neg #align matrix.vec_mul_neg Matrix.vecMul_neg lemma neg_vecMul_neg [Fintype m] (v : m → α) (A : Matrix m n α) : (-v) ᵥ* (-A) = v ᵥ* A := by rw [vecMul_neg, neg_vecMul, neg_neg] theorem neg_mulVec [Fintype n] (v : n → α) (A : Matrix m n α) : (-A) *ᵥ v = - (A *ᵥ v) := by ext apply neg_dotProduct #align matrix.neg_mul_vec Matrix.neg_mulVec theorem mulVec_neg [Fintype n] (v : n → α) (A : Matrix m n α) : A *ᵥ (-v) = - (A *ᵥ v) := by ext apply dotProduct_neg #align matrix.mul_vec_neg Matrix.mulVec_neg lemma neg_mulVec_neg [Fintype n] (v : n → α) (A : Matrix m n α) : (-A) *ᵥ (-v) = A *ᵥ v := by rw [mulVec_neg, neg_mulVec, neg_neg] theorem mulVec_sub [Fintype n] (A : Matrix m n α) (x y : n → α) : A *ᵥ (x - y) = A *ᵥ x - A *ᵥ y := by ext apply dotProduct_sub theorem sub_mulVec [Fintype n] (A B : Matrix m n α) (x : n → α) : (A - B) *ᵥ x = A *ᵥ x - B *ᵥ x := by simp [sub_eq_add_neg, add_mulVec, neg_mulVec] #align matrix.sub_mul_vec Matrix.sub_mulVec theorem vecMul_sub [Fintype m] (A B : Matrix m n α) (x : m → α) : x ᵥ* (A - B) = x ᵥ* A - x ᵥ* B := by simp [sub_eq_add_neg, vecMul_add, vecMul_neg] #align matrix.vec_mul_sub Matrix.vecMul_sub theorem sub_vecMul [Fintype m] (A : Matrix m n α) (x y : m → α) : (x - y) ᵥ* A = x ᵥ* A - y ᵥ* A := by ext apply sub_dotProduct end NonUnitalNonAssocRing section NonUnitalCommSemiring variable [NonUnitalCommSemiring α] theorem mulVec_transpose [Fintype m] (A : Matrix m n α) (x : m → α) : Aᵀ *ᵥ x = x ᵥ* A := by ext apply dotProduct_comm #align matrix.mul_vec_transpose Matrix.mulVec_transpose theorem vecMul_transpose [Fintype n] (A : Matrix m n α) (x : n → α) : x ᵥ* Aᵀ = A *ᵥ x := by ext apply dotProduct_comm #align matrix.vec_mul_transpose Matrix.vecMul_transpose theorem mulVec_vecMul [Fintype n] [Fintype o] (A : Matrix m n α) (B : Matrix o n α) (x : o → α) : A *ᵥ (x ᵥ* B) = (A * Bᵀ) *ᵥ x := by rw [← mulVec_mulVec, mulVec_transpose] #align matrix.mul_vec_vec_mul Matrix.mulVec_vecMul theorem vecMul_mulVec [Fintype m] [Fintype n] (A : Matrix m n α) (B : Matrix m o α) (x : n → α) : (A *ᵥ x) ᵥ* B = x ᵥ* (Aᵀ * B) := by rw [← vecMul_vecMul, vecMul_transpose] #align matrix.vec_mul_mul_vec Matrix.vecMul_mulVec end NonUnitalCommSemiring section CommSemiring variable [CommSemiring α] theorem mulVec_smul_assoc [Fintype n] (A : Matrix m n α) (b : n → α) (a : α) : A *ᵥ (a • b) = a • A *ᵥ b := by ext apply dotProduct_smul #align matrix.mul_vec_smul_assoc Matrix.mulVec_smul_assoc end CommSemiring section NonAssocRing variable [NonAssocRing α] variable [Fintype m] [DecidableEq m] @[simp] theorem intCast_mulVec (x : ℤ) (v : m → α) : x *ᵥ v = (x : α) • v := diagonal_const_mulVec _ _ @[simp] theorem vecMul_intCast (x : ℤ) (v : m → α) : v ᵥ* x = MulOpposite.op (x : α) • v := vecMul_diagonal_const _ _ end NonAssocRing section Transpose open Matrix @[simp] theorem transpose_transpose (M : Matrix m n α) : Mᵀᵀ = M := by ext rfl #align matrix.transpose_transpose Matrix.transpose_transpose theorem transpose_injective : Function.Injective (transpose : Matrix m n α → Matrix n m α) := fun _ _ h => ext fun i j => ext_iff.2 h j i @[simp] theorem transpose_inj {A B : Matrix m n α} : Aᵀ = Bᵀ ↔ A = B := transpose_injective.eq_iff @[simp] theorem transpose_zero [Zero α] : (0 : Matrix m n α)ᵀ = 0 := by ext rfl #align matrix.transpose_zero Matrix.transpose_zero @[simp] theorem transpose_eq_zero [Zero α] {M : Matrix m n α} : Mᵀ = 0 ↔ M = 0 := transpose_inj @[simp] theorem transpose_one [DecidableEq n] [Zero α] [One α] : (1 : Matrix n n α)ᵀ = 1 := by ext i j rw [transpose_apply, ← diagonal_one] by_cases h : i = j · simp only [h, diagonal_apply_eq] · simp only [diagonal_apply_ne _ h, diagonal_apply_ne' _ h] #align matrix.transpose_one Matrix.transpose_one @[simp] theorem transpose_eq_one [DecidableEq n] [Zero α] [One α] {M : Matrix n n α} : Mᵀ = 1 ↔ M = 1 := (Function.Involutive.eq_iff transpose_transpose).trans <| by rw [transpose_one] @[simp] theorem transpose_add [Add α] (M : Matrix m n α) (N : Matrix m n α) : (M + N)ᵀ = Mᵀ + Nᵀ := by ext simp #align matrix.transpose_add Matrix.transpose_add @[simp] theorem transpose_sub [Sub α] (M : Matrix m n α) (N : Matrix m n α) : (M - N)ᵀ = Mᵀ - Nᵀ := by ext simp #align matrix.transpose_sub Matrix.transpose_sub @[simp] theorem transpose_mul [AddCommMonoid α] [CommSemigroup α] [Fintype n] (M : Matrix m n α) (N : Matrix n l α) : (M * N)ᵀ = Nᵀ * Mᵀ := by ext apply dotProduct_comm #align matrix.transpose_mul Matrix.transpose_mul @[simp] theorem transpose_smul {R : Type*} [SMul R α] (c : R) (M : Matrix m n α) : (c • M)ᵀ = c • Mᵀ := by ext rfl #align matrix.transpose_smul Matrix.transpose_smul @[simp]
Mathlib/Data/Matrix/Basic.lean
2,099
2,101
theorem transpose_neg [Neg α] (M : Matrix m n α) : (-M)ᵀ = -Mᵀ := by
ext rfl
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Amelia Livingston, Yury Kudryashov, Neil Strickland, Aaron Anderson -/ import Mathlib.Algebra.GroupWithZero.Units.Basic import Mathlib.Algebra.Divisibility.Units #align_import algebra.group_with_zero.divisibility from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3" /-! # Divisibility in groups with zero. Lemmas about divisibility in groups and monoids with zero. -/ assert_not_exists DenselyOrdered variable {α : Type*} section SemigroupWithZero variable [SemigroupWithZero α] {a : α} theorem eq_zero_of_zero_dvd (h : 0 ∣ a) : a = 0 := Dvd.elim h fun c H' => H'.trans (zero_mul c) #align eq_zero_of_zero_dvd eq_zero_of_zero_dvd /-- Given an element `a` of a commutative semigroup with zero, there exists another element whose product with zero equals `a` iff `a` equals zero. -/ @[simp] theorem zero_dvd_iff : 0 ∣ a ↔ a = 0 := ⟨eq_zero_of_zero_dvd, fun h => by rw [h] exact ⟨0, by simp⟩⟩ #align zero_dvd_iff zero_dvd_iff @[simp] theorem dvd_zero (a : α) : a ∣ 0 := Dvd.intro 0 (by simp) #align dvd_zero dvd_zero end SemigroupWithZero /-- Given two elements `b`, `c` of a `CancelMonoidWithZero` and a nonzero element `a`, `a*b` divides `a*c` iff `b` divides `c`. -/ theorem mul_dvd_mul_iff_left [CancelMonoidWithZero α] {a b c : α} (ha : a ≠ 0) : a * b ∣ a * c ↔ b ∣ c := exists_congr fun d => by rw [mul_assoc, mul_right_inj' ha] #align mul_dvd_mul_iff_left mul_dvd_mul_iff_left /-- Given two elements `a`, `b` of a commutative `CancelMonoidWithZero` and a nonzero element `c`, `a*c` divides `b*c` iff `a` divides `b`. -/ theorem mul_dvd_mul_iff_right [CancelCommMonoidWithZero α] {a b c : α} (hc : c ≠ 0) : a * c ∣ b * c ↔ a ∣ b := exists_congr fun d => by rw [mul_right_comm, mul_left_inj' hc] #align mul_dvd_mul_iff_right mul_dvd_mul_iff_right section CommMonoidWithZero variable [CommMonoidWithZero α] /-- `DvdNotUnit a b` expresses that `a` divides `b` "strictly", i.e. that `b` divided by `a` is not a unit. -/ def DvdNotUnit (a b : α) : Prop := a ≠ 0 ∧ ∃ x, ¬IsUnit x ∧ b = a * x #align dvd_not_unit DvdNotUnit theorem dvdNotUnit_of_dvd_of_not_dvd {a b : α} (hd : a ∣ b) (hnd : ¬b ∣ a) : DvdNotUnit a b := by constructor · rintro rfl exact hnd (dvd_zero _) · rcases hd with ⟨c, rfl⟩ refine ⟨c, ?_, rfl⟩ rintro ⟨u, rfl⟩ simp at hnd #align dvd_not_unit_of_dvd_of_not_dvd dvdNotUnit_of_dvd_of_not_dvd variable {x y : α} theorem isRelPrime_zero_left : IsRelPrime 0 x ↔ IsUnit x := ⟨(· (dvd_zero _) dvd_rfl), IsUnit.isRelPrime_right⟩ theorem isRelPrime_zero_right : IsRelPrime x 0 ↔ IsUnit x := isRelPrime_comm.trans isRelPrime_zero_left theorem not_isRelPrime_zero_zero [Nontrivial α] : ¬IsRelPrime (0 : α) 0 := mt isRelPrime_zero_right.mp not_isUnit_zero theorem IsRelPrime.ne_zero_or_ne_zero [Nontrivial α] (h : IsRelPrime x y) : x ≠ 0 ∨ y ≠ 0 := not_or_of_imp <| by rintro rfl rfl; exact not_isRelPrime_zero_zero h end CommMonoidWithZero theorem isRelPrime_of_no_nonunits_factors [MonoidWithZero α] {x y : α} (nonzero : ¬(x = 0 ∧ y = 0)) (H : ∀ z, ¬ IsUnit z → z ≠ 0 → z ∣ x → ¬z ∣ y) : IsRelPrime x y := by refine fun z hx hy ↦ by_contra fun h ↦ H z h ?_ hx hy rintro rfl; exact nonzero ⟨zero_dvd_iff.1 hx, zero_dvd_iff.1 hy⟩ theorem dvd_and_not_dvd_iff [CancelCommMonoidWithZero α] {x y : α} : x ∣ y ∧ ¬y ∣ x ↔ DvdNotUnit x y := ⟨fun ⟨⟨d, hd⟩, hyx⟩ => ⟨fun hx0 => by simp [hx0] at hyx, ⟨d, mt isUnit_iff_dvd_one.1 fun ⟨e, he⟩ => hyx ⟨e, by rw [hd, mul_assoc, ← he, mul_one]⟩, hd⟩⟩, fun ⟨hx0, d, hdu, hdx⟩ => ⟨⟨d, hdx⟩, fun ⟨e, he⟩ => hdu (isUnit_of_dvd_one ⟨e, mul_left_cancel₀ hx0 <| by conv => lhs rw [he, hdx] simp [mul_assoc]⟩)⟩⟩ #align dvd_and_not_dvd_iff dvd_and_not_dvd_iff section MonoidWithZero variable [MonoidWithZero α] theorem ne_zero_of_dvd_ne_zero {p q : α} (h₁ : q ≠ 0) (h₂ : p ∣ q) : p ≠ 0 := by rcases h₂ with ⟨u, rfl⟩ exact left_ne_zero_of_mul h₁ #align ne_zero_of_dvd_ne_zero ne_zero_of_dvd_ne_zero theorem isPrimal_zero : IsPrimal (0 : α) := fun a b h ↦ ⟨a, b, dvd_rfl, dvd_rfl, (zero_dvd_iff.mp h).symm⟩ theorem IsPrimal.mul {α} [CancelCommMonoidWithZero α] {m n : α} (hm : IsPrimal m) (hn : IsPrimal n) : IsPrimal (m * n) := by obtain rfl | h0 := eq_or_ne m 0; · rwa [zero_mul] intro b c h obtain ⟨a₁, a₂, ⟨b, rfl⟩, ⟨c, rfl⟩, rfl⟩ := hm (dvd_of_mul_right_dvd h) rw [mul_mul_mul_comm, mul_dvd_mul_iff_left h0] at h obtain ⟨a₁', a₂', h₁, h₂, rfl⟩ := hn h exact ⟨a₁ * a₁', a₂ * a₂', mul_dvd_mul_left _ h₁, mul_dvd_mul_left _ h₂, mul_mul_mul_comm _ _ _ _⟩ end MonoidWithZero section CancelCommMonoidWithZero variable [CancelCommMonoidWithZero α] [Subsingleton αˣ] {a b : α} {m n : ℕ}
Mathlib/Algebra/GroupWithZero/Divisibility.lean
145
148
theorem dvd_antisymm : a ∣ b → b ∣ a → a = b := by
rintro ⟨c, rfl⟩ ⟨d, hcd⟩ rw [mul_assoc, eq_comm, mul_right_eq_self₀, mul_eq_one] at hcd obtain ⟨rfl, -⟩ | rfl := hcd <;> simp
/- Copyright (c) 2021 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Gabriel Ebner -/ import Batteries.Data.List.Lemmas import Batteries.Data.Array.Basic import Batteries.Tactic.SeqFocus import Batteries.Util.ProofWanted namespace Array theorem forIn_eq_data_forIn [Monad m] (as : Array α) (b : β) (f : α → β → m (ForInStep β)) : forIn as b f = forIn as.data b f := by let rec loop : ∀ {i h b j}, j + i = as.size → Array.forIn.loop as f i h b = forIn (as.data.drop j) b f | 0, _, _, _, rfl => by rw [List.drop_length]; rfl | i+1, _, _, j, ij => by simp only [forIn.loop, Nat.add] have j_eq : j = size as - 1 - i := by simp [← ij, ← Nat.add_assoc] have : as.size - 1 - i < as.size := j_eq ▸ ij ▸ Nat.lt_succ_of_le (Nat.le_add_right ..) have : as[size as - 1 - i] :: as.data.drop (j + 1) = as.data.drop j := by rw [j_eq]; exact List.get_cons_drop _ ⟨_, this⟩ simp only [← this, List.forIn_cons]; congr; funext x; congr; funext b rw [loop (i := i)]; rw [← ij, Nat.succ_add]; rfl conv => lhs; simp only [forIn, Array.forIn] rw [loop (Nat.zero_add _)]; rfl /-! ### zipWith / zip -/ theorem zipWith_eq_zipWith_data (f : α → β → γ) (as : Array α) (bs : Array β) : (as.zipWith bs f).data = as.data.zipWith f bs.data := by let rec loop : ∀ (i : Nat) cs, i ≤ as.size → i ≤ bs.size → (zipWithAux f as bs i cs).data = cs.data ++ (as.data.drop i).zipWith f (bs.data.drop i) := by intro i cs hia hib unfold zipWithAux by_cases h : i = as.size ∨ i = bs.size case pos => have : ¬(i < as.size) ∨ ¬(i < bs.size) := by cases h <;> simp_all only [Nat.not_lt, Nat.le_refl, true_or, or_true] -- Cleaned up aesop output below simp_all only [Nat.not_lt] cases h <;> [(cases this); (cases this)] · simp_all only [Nat.le_refl, Nat.lt_irrefl, dite_false, List.drop_length, List.zipWith_nil_left, List.append_nil] · simp_all only [Nat.le_refl, Nat.lt_irrefl, dite_false, List.drop_length, List.zipWith_nil_left, List.append_nil] · simp_all only [Nat.le_refl, Nat.lt_irrefl, dite_false, List.drop_length, List.zipWith_nil_right, List.append_nil] split <;> simp_all only [Nat.not_lt] · simp_all only [Nat.le_refl, Nat.lt_irrefl, dite_false, List.drop_length, List.zipWith_nil_right, List.append_nil] split <;> simp_all only [Nat.not_lt] case neg => rw [not_or] at h have has : i < as.size := Nat.lt_of_le_of_ne hia h.1 have hbs : i < bs.size := Nat.lt_of_le_of_ne hib h.2 simp only [has, hbs, dite_true] rw [loop (i+1) _ has hbs, Array.push_data] have h₁ : [f as[i] bs[i]] = List.zipWith f [as[i]] [bs[i]] := rfl let i_as : Fin as.data.length := ⟨i, has⟩ let i_bs : Fin bs.data.length := ⟨i, hbs⟩ rw [h₁, List.append_assoc] congr rw [← List.zipWith_append (h := by simp), getElem_eq_data_get, getElem_eq_data_get] show List.zipWith f ((List.get as.data i_as) :: List.drop (i_as + 1) as.data) ((List.get bs.data i_bs) :: List.drop (i_bs + 1) bs.data) = List.zipWith f (List.drop i as.data) (List.drop i bs.data) simp only [List.get_cons_drop] termination_by as.size - i simp [zipWith, loop 0 #[] (by simp) (by simp)] theorem size_zipWith (as : Array α) (bs : Array β) (f : α → β → γ) : (as.zipWith bs f).size = min as.size bs.size := by rw [size_eq_length_data, zipWith_eq_zipWith_data, List.length_zipWith] theorem zip_eq_zip_data (as : Array α) (bs : Array β) : (as.zip bs).data = as.data.zip bs.data := zipWith_eq_zipWith_data Prod.mk as bs theorem size_zip (as : Array α) (bs : Array β) : (as.zip bs).size = min as.size bs.size := as.size_zipWith bs Prod.mk /-! ### filter -/ theorem size_filter_le (p : α → Bool) (l : Array α) : (l.filter p).size ≤ l.size := by simp only [← data_length, filter_data] apply List.length_filter_le /-! ### join -/ @[simp] theorem join_data {l : Array (Array α)} : l.join.data = (l.data.map data).join := by dsimp [join] simp only [foldl_eq_foldl_data] generalize l.data = l have : ∀ a : Array α, (List.foldl ?_ a l).data = a.data ++ ?_ := ?_ exact this #[] induction l with | nil => simp | cons h => induction h.data <;> simp [*] theorem mem_join : ∀ {L : Array (Array α)}, a ∈ L.join ↔ ∃ l, l ∈ L ∧ a ∈ l := by simp only [mem_def, join_data, List.mem_join, List.mem_map] intro l constructor · rintro ⟨_, ⟨s, m, rfl⟩, h⟩ exact ⟨s, m, h⟩ · rintro ⟨s, h₁, h₂⟩ refine ⟨s.data, ⟨⟨s, h₁, rfl⟩, h₂⟩⟩ /-! ### erase -/ @[simp] proof_wanted erase_data [BEq α] {l : Array α} {a : α} : (l.erase a).data = l.data.erase a /-! ### shrink -/ theorem size_shrink_loop (a : Array α) (n) : (shrink.loop n a).size = a.size - n := by induction n generalizing a with simp[shrink.loop] | succ n ih => simp[ih] omega
.lake/packages/batteries/Batteries/Data/Array/Lemmas.lean
127
129
theorem size_shrink (a : Array α) (n) : (a.shrink n).size = min a.size n := by
simp [shrink, size_shrink_loop] omega
/- Copyright (c) 2021 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies [`data.finset.sym`@`98e83c3d541c77cdb7da20d79611a780ff8e7d90`..`02ba8949f486ebecf93fe7460f1ed0564b5e442c`](https://leanprover-community.github.io/mathlib-port-status/file/data/finset/sym?range=98e83c3d541c77cdb7da20d79611a780ff8e7d90..02ba8949f486ebecf93fe7460f1ed0564b5e442c) -/ import Mathlib.Data.Finset.Lattice import Mathlib.Data.Fintype.Vector import Mathlib.Data.Multiset.Sym #align_import data.finset.sym from "leanprover-community/mathlib"@"02ba8949f486ebecf93fe7460f1ed0564b5e442c" /-! # Symmetric powers of a finset This file defines the symmetric powers of a finset as `Finset (Sym α n)` and `Finset (Sym2 α)`. ## Main declarations * `Finset.sym`: The symmetric power of a finset. `s.sym n` is all the multisets of cardinality `n` whose elements are in `s`. * `Finset.sym2`: The symmetric square of a finset. `s.sym2` is all the pairs whose elements are in `s`. * A `Fintype (Sym2 α)` instance that does not require `DecidableEq α`. ## TODO `Finset.sym` forms a Galois connection between `Finset α` and `Finset (Sym α n)`. Similar for `Finset.sym2`. -/ namespace Finset variable {α : Type*} /-- `s.sym2` is the finset of all unordered pairs of elements from `s`. It is the image of `s ×ˢ s` under the quotient `α × α → Sym2 α`. -/ @[simps] protected def sym2 (s : Finset α) : Finset (Sym2 α) := ⟨s.1.sym2, s.2.sym2⟩ #align finset.sym2 Finset.sym2 section variable {s t : Finset α} {a b : α} theorem mk_mem_sym2_iff : s(a, b) ∈ s.sym2 ↔ a ∈ s ∧ b ∈ s := by rw [mem_mk, sym2_val, Multiset.mk_mem_sym2_iff, mem_mk, mem_mk] #align finset.mk_mem_sym2_iff Finset.mk_mem_sym2_iff @[simp] theorem mem_sym2_iff {m : Sym2 α} : m ∈ s.sym2 ↔ ∀ a ∈ m, a ∈ s := by rw [mem_mk, sym2_val, Multiset.mem_sym2_iff] simp only [mem_val] #align finset.mem_sym2_iff Finset.mem_sym2_iff instance _root_.Sym2.instFintype [Fintype α] : Fintype (Sym2 α) where elems := Finset.univ.sym2 complete := fun x ↦ by rw [mem_sym2_iff]; exact (fun a _ ↦ mem_univ a) -- Note(kmill): Using a default argument to make this simp lemma more general. @[simp] theorem sym2_univ [Fintype α] (inst : Fintype (Sym2 α) := Sym2.instFintype) : (univ : Finset α).sym2 = univ := by ext simp only [mem_sym2_iff, mem_univ, implies_true] #align finset.sym2_univ Finset.sym2_univ @[simp, mono] theorem sym2_mono (h : s ⊆ t) : s.sym2 ⊆ t.sym2 := by rw [← val_le_iff, sym2_val, sym2_val] apply Multiset.sym2_mono rwa [val_le_iff] #align finset.sym2_mono Finset.sym2_mono theorem monotone_sym2 : Monotone (Finset.sym2 : Finset α → _) := fun _ _ => sym2_mono theorem injective_sym2 : Function.Injective (Finset.sym2 : Finset α → _) := by intro s t h ext x simpa using congr(s(x, x) ∈ $h) theorem strictMono_sym2 : StrictMono (Finset.sym2 : Finset α → _) := monotone_sym2.strictMono_of_injective injective_sym2 theorem sym2_toFinset [DecidableEq α] (m : Multiset α) : m.toFinset.sym2 = m.sym2.toFinset := by ext z refine z.ind fun x y ↦ ?_ simp only [mk_mem_sym2_iff, Multiset.mem_toFinset, Multiset.mk_mem_sym2_iff] @[simp] theorem sym2_empty : (∅ : Finset α).sym2 = ∅ := rfl #align finset.sym2_empty Finset.sym2_empty @[simp] theorem sym2_eq_empty : s.sym2 = ∅ ↔ s = ∅ := by rw [← val_eq_zero, sym2_val, Multiset.sym2_eq_zero_iff, val_eq_zero] #align finset.sym2_eq_empty Finset.sym2_eq_empty @[simp, aesop safe apply (rule_sets := [finsetNonempty])]
Mathlib/Data/Finset/Sym.lean
101
103
theorem sym2_nonempty : s.sym2.Nonempty ↔ s.Nonempty := by
rw [← not_iff_not] simp_rw [not_nonempty_iff_eq_empty, sym2_eq_empty]
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.MeasureTheory.Function.StronglyMeasurable.Lp import Mathlib.MeasureTheory.Integral.Bochner import Mathlib.Order.Filter.IndicatorFunction import Mathlib.MeasureTheory.Function.StronglyMeasurable.Inner import Mathlib.MeasureTheory.Function.LpSeminorm.Trim #align_import measure_theory.function.conditional_expectation.ae_measurable from "leanprover-community/mathlib"@"d8bbb04e2d2a44596798a9207ceefc0fb236e41e" /-! # Functions a.e. measurable with respect to a sub-σ-algebra A function `f` verifies `AEStronglyMeasurable' m f μ` if it is `μ`-a.e. equal to an `m`-strongly measurable function. This is similar to `AEStronglyMeasurable`, but the `MeasurableSpace` structures used for the measurability statement and for the measure are different. We define `lpMeas F 𝕜 m p μ`, the subspace of `Lp F p μ` containing functions `f` verifying `AEStronglyMeasurable' m f μ`, i.e. functions which are `μ`-a.e. equal to an `m`-strongly measurable function. ## Main statements We define an `IsometryEquiv` between `lpMeasSubgroup` and the `Lp` space corresponding to the measure `μ.trim hm`. As a consequence, the completeness of `Lp` implies completeness of `lpMeas`. `Lp.induction_stronglyMeasurable` (see also `Memℒp.induction_stronglyMeasurable`): To prove something for an `Lp` function a.e. strongly measurable with respect to a sub-σ-algebra `m` in a normed space, it suffices to show that * the property holds for (multiples of) characteristic functions which are measurable w.r.t. `m`; * is closed under addition; * the set of functions in `Lp` strongly measurable w.r.t. `m` for which the property holds is closed. -/ set_option linter.uppercaseLean3 false open TopologicalSpace Filter open scoped ENNReal MeasureTheory namespace MeasureTheory /-- A function `f` verifies `AEStronglyMeasurable' m f μ` if it is `μ`-a.e. equal to an `m`-strongly measurable function. This is similar to `AEStronglyMeasurable`, but the `MeasurableSpace` structures used for the measurability statement and for the measure are different. -/ def AEStronglyMeasurable' {α β} [TopologicalSpace β] (m : MeasurableSpace α) {_ : MeasurableSpace α} (f : α → β) (μ : Measure α) : Prop := ∃ g : α → β, StronglyMeasurable[m] g ∧ f =ᵐ[μ] g #align measure_theory.ae_strongly_measurable' MeasureTheory.AEStronglyMeasurable' namespace AEStronglyMeasurable' variable {α β 𝕜 : Type*} {m m0 : MeasurableSpace α} {μ : Measure α} [TopologicalSpace β] {f g : α → β} theorem congr (hf : AEStronglyMeasurable' m f μ) (hfg : f =ᵐ[μ] g) : AEStronglyMeasurable' m g μ := by obtain ⟨f', hf'_meas, hff'⟩ := hf; exact ⟨f', hf'_meas, hfg.symm.trans hff'⟩ #align measure_theory.ae_strongly_measurable'.congr MeasureTheory.AEStronglyMeasurable'.congr theorem mono {m'} (hf : AEStronglyMeasurable' m f μ) (hm : m ≤ m') : AEStronglyMeasurable' m' f μ := let ⟨f', hf'_meas, hff'⟩ := hf; ⟨f', hf'_meas.mono hm, hff'⟩ theorem add [Add β] [ContinuousAdd β] (hf : AEStronglyMeasurable' m f μ) (hg : AEStronglyMeasurable' m g μ) : AEStronglyMeasurable' m (f + g) μ := by rcases hf with ⟨f', h_f'_meas, hff'⟩ rcases hg with ⟨g', h_g'_meas, hgg'⟩ exact ⟨f' + g', h_f'_meas.add h_g'_meas, hff'.add hgg'⟩ #align measure_theory.ae_strongly_measurable'.add MeasureTheory.AEStronglyMeasurable'.add
Mathlib/MeasureTheory/Function/ConditionalExpectation/AEMeasurable.lean
78
83
theorem neg [AddGroup β] [TopologicalAddGroup β] {f : α → β} (hfm : AEStronglyMeasurable' m f μ) : AEStronglyMeasurable' m (-f) μ := by
rcases hfm with ⟨f', hf'_meas, hf_ae⟩ refine ⟨-f', hf'_meas.neg, hf_ae.mono fun x hx => ?_⟩ simp_rw [Pi.neg_apply] rw [hx]
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Algebra.Polynomial.Degree.Definitions import Mathlib.Algebra.Polynomial.Induction #align_import data.polynomial.eval from "leanprover-community/mathlib"@"728baa2f54e6062c5879a3e397ac6bac323e506f" /-! # Theory of univariate polynomials The main defs here are `eval₂`, `eval`, and `map`. We give several lemmas about their interaction with each other and with module operations. -/ set_option linter.uppercaseLean3 false noncomputable section open Finset AddMonoidAlgebra open Polynomial namespace Polynomial universe u v w y variable {R : Type u} {S : Type v} {T : Type w} {ι : Type y} {a b : R} {m n : ℕ} section Semiring variable [Semiring R] {p q r : R[X]} section variable [Semiring S] variable (f : R →+* S) (x : S) /-- Evaluate a polynomial `p` given a ring hom `f` from the scalar ring to the target and a value `x` for the variable in the target -/ irreducible_def eval₂ (p : R[X]) : S := p.sum fun e a => f a * x ^ e #align polynomial.eval₂ Polynomial.eval₂ theorem eval₂_eq_sum {f : R →+* S} {x : S} : p.eval₂ f x = p.sum fun e a => f a * x ^ e := by rw [eval₂_def] #align polynomial.eval₂_eq_sum Polynomial.eval₂_eq_sum theorem eval₂_congr {R S : Type*} [Semiring R] [Semiring S] {f g : R →+* S} {s t : S} {φ ψ : R[X]} : f = g → s = t → φ = ψ → eval₂ f s φ = eval₂ g t ψ := by rintro rfl rfl rfl; rfl #align polynomial.eval₂_congr Polynomial.eval₂_congr @[simp] theorem eval₂_at_zero : p.eval₂ f 0 = f (coeff p 0) := by simp (config := { contextual := true }) only [eval₂_eq_sum, zero_pow_eq, mul_ite, mul_zero, mul_one, sum, Classical.not_not, mem_support_iff, sum_ite_eq', ite_eq_left_iff, RingHom.map_zero, imp_true_iff, eq_self_iff_true] #align polynomial.eval₂_at_zero Polynomial.eval₂_at_zero @[simp] theorem eval₂_zero : (0 : R[X]).eval₂ f x = 0 := by simp [eval₂_eq_sum] #align polynomial.eval₂_zero Polynomial.eval₂_zero @[simp] theorem eval₂_C : (C a).eval₂ f x = f a := by simp [eval₂_eq_sum] #align polynomial.eval₂_C Polynomial.eval₂_C @[simp] theorem eval₂_X : X.eval₂ f x = x := by simp [eval₂_eq_sum] #align polynomial.eval₂_X Polynomial.eval₂_X @[simp] theorem eval₂_monomial {n : ℕ} {r : R} : (monomial n r).eval₂ f x = f r * x ^ n := by simp [eval₂_eq_sum] #align polynomial.eval₂_monomial Polynomial.eval₂_monomial @[simp] theorem eval₂_X_pow {n : ℕ} : (X ^ n).eval₂ f x = x ^ n := by rw [X_pow_eq_monomial] convert eval₂_monomial f x (n := n) (r := 1) simp #align polynomial.eval₂_X_pow Polynomial.eval₂_X_pow @[simp] theorem eval₂_add : (p + q).eval₂ f x = p.eval₂ f x + q.eval₂ f x := by simp only [eval₂_eq_sum] apply sum_add_index <;> simp [add_mul] #align polynomial.eval₂_add Polynomial.eval₂_add @[simp] theorem eval₂_one : (1 : R[X]).eval₂ f x = 1 := by rw [← C_1, eval₂_C, f.map_one] #align polynomial.eval₂_one Polynomial.eval₂_one set_option linter.deprecated false in @[simp] theorem eval₂_bit0 : (bit0 p).eval₂ f x = bit0 (p.eval₂ f x) := by rw [bit0, eval₂_add, bit0] #align polynomial.eval₂_bit0 Polynomial.eval₂_bit0 set_option linter.deprecated false in @[simp] theorem eval₂_bit1 : (bit1 p).eval₂ f x = bit1 (p.eval₂ f x) := by rw [bit1, eval₂_add, eval₂_bit0, eval₂_one, bit1] #align polynomial.eval₂_bit1 Polynomial.eval₂_bit1 @[simp] theorem eval₂_smul (g : R →+* S) (p : R[X]) (x : S) {s : R} : eval₂ g x (s • p) = g s * eval₂ g x p := by have A : p.natDegree < p.natDegree.succ := Nat.lt_succ_self _ have B : (s • p).natDegree < p.natDegree.succ := (natDegree_smul_le _ _).trans_lt A rw [eval₂_eq_sum, eval₂_eq_sum, sum_over_range' _ _ _ A, sum_over_range' _ _ _ B] <;> simp [mul_sum, mul_assoc] #align polynomial.eval₂_smul Polynomial.eval₂_smul @[simp] theorem eval₂_C_X : eval₂ C X p = p := Polynomial.induction_on' p (fun p q hp hq => by simp [hp, hq]) fun n x => by rw [eval₂_monomial, ← smul_X_eq_monomial, C_mul'] #align polynomial.eval₂_C_X Polynomial.eval₂_C_X /-- `eval₂AddMonoidHom (f : R →+* S) (x : S)` is the `AddMonoidHom` from `R[X]` to `S` obtained by evaluating the pushforward of `p` along `f` at `x`. -/ @[simps] def eval₂AddMonoidHom : R[X] →+ S where toFun := eval₂ f x map_zero' := eval₂_zero _ _ map_add' _ _ := eval₂_add _ _ #align polynomial.eval₂_add_monoid_hom Polynomial.eval₂AddMonoidHom #align polynomial.eval₂_add_monoid_hom_apply Polynomial.eval₂AddMonoidHom_apply @[simp] theorem eval₂_natCast (n : ℕ) : (n : R[X]).eval₂ f x = n := by induction' n with n ih -- Porting note: `Nat.zero_eq` is required. · simp only [eval₂_zero, Nat.cast_zero, Nat.zero_eq] · rw [n.cast_succ, eval₂_add, ih, eval₂_one, n.cast_succ] #align polynomial.eval₂_nat_cast Polynomial.eval₂_natCast @[deprecated (since := "2024-04-17")] alias eval₂_nat_cast := eval₂_natCast -- See note [no_index around OfNat.ofNat] @[simp] lemma eval₂_ofNat {S : Type*} [Semiring S] (n : ℕ) [n.AtLeastTwo] (f : R →+* S) (a : S) : (no_index (OfNat.ofNat n : R[X])).eval₂ f a = OfNat.ofNat n := by simp [OfNat.ofNat] variable [Semiring T] theorem eval₂_sum (p : T[X]) (g : ℕ → T → R[X]) (x : S) : (p.sum g).eval₂ f x = p.sum fun n a => (g n a).eval₂ f x := by let T : R[X] →+ S := { toFun := eval₂ f x map_zero' := eval₂_zero _ _ map_add' := fun p q => eval₂_add _ _ } have A : ∀ y, eval₂ f x y = T y := fun y => rfl simp only [A] rw [sum, map_sum, sum] #align polynomial.eval₂_sum Polynomial.eval₂_sum theorem eval₂_list_sum (l : List R[X]) (x : S) : eval₂ f x l.sum = (l.map (eval₂ f x)).sum := map_list_sum (eval₂AddMonoidHom f x) l #align polynomial.eval₂_list_sum Polynomial.eval₂_list_sum theorem eval₂_multiset_sum (s : Multiset R[X]) (x : S) : eval₂ f x s.sum = (s.map (eval₂ f x)).sum := map_multiset_sum (eval₂AddMonoidHom f x) s #align polynomial.eval₂_multiset_sum Polynomial.eval₂_multiset_sum theorem eval₂_finset_sum (s : Finset ι) (g : ι → R[X]) (x : S) : (∑ i ∈ s, g i).eval₂ f x = ∑ i ∈ s, (g i).eval₂ f x := map_sum (eval₂AddMonoidHom f x) _ _ #align polynomial.eval₂_finset_sum Polynomial.eval₂_finset_sum theorem eval₂_ofFinsupp {f : R →+* S} {x : S} {p : R[ℕ]} : eval₂ f x (⟨p⟩ : R[X]) = liftNC (↑f) (powersHom S x) p := by simp only [eval₂_eq_sum, sum, toFinsupp_sum, support, coeff] rfl #align polynomial.eval₂_of_finsupp Polynomial.eval₂_ofFinsupp theorem eval₂_mul_noncomm (hf : ∀ k, Commute (f <| q.coeff k) x) : eval₂ f x (p * q) = eval₂ f x p * eval₂ f x q := by rcases p with ⟨p⟩; rcases q with ⟨q⟩ simp only [coeff] at hf simp only [← ofFinsupp_mul, eval₂_ofFinsupp] exact liftNC_mul _ _ p q fun {k n} _hn => (hf k).pow_right n #align polynomial.eval₂_mul_noncomm Polynomial.eval₂_mul_noncomm @[simp] theorem eval₂_mul_X : eval₂ f x (p * X) = eval₂ f x p * x := by refine _root_.trans (eval₂_mul_noncomm _ _ fun k => ?_) (by rw [eval₂_X]) rcases em (k = 1) with (rfl | hk) · simp · simp [coeff_X_of_ne_one hk] #align polynomial.eval₂_mul_X Polynomial.eval₂_mul_X @[simp] theorem eval₂_X_mul : eval₂ f x (X * p) = eval₂ f x p * x := by rw [X_mul, eval₂_mul_X] #align polynomial.eval₂_X_mul Polynomial.eval₂_X_mul theorem eval₂_mul_C' (h : Commute (f a) x) : eval₂ f x (p * C a) = eval₂ f x p * f a := by rw [eval₂_mul_noncomm, eval₂_C] intro k by_cases hk : k = 0 · simp only [hk, h, coeff_C_zero, coeff_C_ne_zero] · simp only [coeff_C_ne_zero hk, RingHom.map_zero, Commute.zero_left] #align polynomial.eval₂_mul_C' Polynomial.eval₂_mul_C' theorem eval₂_list_prod_noncomm (ps : List R[X]) (hf : ∀ p ∈ ps, ∀ (k), Commute (f <| coeff p k) x) : eval₂ f x ps.prod = (ps.map (Polynomial.eval₂ f x)).prod := by induction' ps using List.reverseRecOn with ps p ihp · simp · simp only [List.forall_mem_append, List.forall_mem_singleton] at hf simp [eval₂_mul_noncomm _ _ hf.2, ihp hf.1] #align polynomial.eval₂_list_prod_noncomm Polynomial.eval₂_list_prod_noncomm /-- `eval₂` as a `RingHom` for noncommutative rings -/ @[simps] def eval₂RingHom' (f : R →+* S) (x : S) (hf : ∀ a, Commute (f a) x) : R[X] →+* S where toFun := eval₂ f x map_add' _ _ := eval₂_add _ _ map_zero' := eval₂_zero _ _ map_mul' _p q := eval₂_mul_noncomm f x fun k => hf <| coeff q k map_one' := eval₂_one _ _ #align polynomial.eval₂_ring_hom' Polynomial.eval₂RingHom' end /-! We next prove that eval₂ is multiplicative as long as target ring is commutative (even if the source ring is not). -/ section Eval₂ section variable [Semiring S] (f : R →+* S) (x : S) theorem eval₂_eq_sum_range : p.eval₂ f x = ∑ i ∈ Finset.range (p.natDegree + 1), f (p.coeff i) * x ^ i := _root_.trans (congr_arg _ p.as_sum_range) (_root_.trans (eval₂_finset_sum f _ _ x) (congr_arg _ (by simp))) #align polynomial.eval₂_eq_sum_range Polynomial.eval₂_eq_sum_range theorem eval₂_eq_sum_range' (f : R →+* S) {p : R[X]} {n : ℕ} (hn : p.natDegree < n) (x : S) : eval₂ f x p = ∑ i ∈ Finset.range n, f (p.coeff i) * x ^ i := by rw [eval₂_eq_sum, p.sum_over_range' _ _ hn] intro i rw [f.map_zero, zero_mul] #align polynomial.eval₂_eq_sum_range' Polynomial.eval₂_eq_sum_range' end section variable [CommSemiring S] (f : R →+* S) (x : S) @[simp] theorem eval₂_mul : (p * q).eval₂ f x = p.eval₂ f x * q.eval₂ f x := eval₂_mul_noncomm _ _ fun _k => Commute.all _ _ #align polynomial.eval₂_mul Polynomial.eval₂_mul theorem eval₂_mul_eq_zero_of_left (q : R[X]) (hp : p.eval₂ f x = 0) : (p * q).eval₂ f x = 0 := by rw [eval₂_mul f x] exact mul_eq_zero_of_left hp (q.eval₂ f x) #align polynomial.eval₂_mul_eq_zero_of_left Polynomial.eval₂_mul_eq_zero_of_left theorem eval₂_mul_eq_zero_of_right (p : R[X]) (hq : q.eval₂ f x = 0) : (p * q).eval₂ f x = 0 := by rw [eval₂_mul f x] exact mul_eq_zero_of_right (p.eval₂ f x) hq #align polynomial.eval₂_mul_eq_zero_of_right Polynomial.eval₂_mul_eq_zero_of_right /-- `eval₂` as a `RingHom` -/ def eval₂RingHom (f : R →+* S) (x : S) : R[X] →+* S := { eval₂AddMonoidHom f x with map_one' := eval₂_one _ _ map_mul' := fun _ _ => eval₂_mul _ _ } #align polynomial.eval₂_ring_hom Polynomial.eval₂RingHom @[simp] theorem coe_eval₂RingHom (f : R →+* S) (x) : ⇑(eval₂RingHom f x) = eval₂ f x := rfl #align polynomial.coe_eval₂_ring_hom Polynomial.coe_eval₂RingHom theorem eval₂_pow (n : ℕ) : (p ^ n).eval₂ f x = p.eval₂ f x ^ n := (eval₂RingHom _ _).map_pow _ _ #align polynomial.eval₂_pow Polynomial.eval₂_pow theorem eval₂_dvd : p ∣ q → eval₂ f x p ∣ eval₂ f x q := (eval₂RingHom f x).map_dvd #align polynomial.eval₂_dvd Polynomial.eval₂_dvd theorem eval₂_eq_zero_of_dvd_of_eval₂_eq_zero (h : p ∣ q) (h0 : eval₂ f x p = 0) : eval₂ f x q = 0 := zero_dvd_iff.mp (h0 ▸ eval₂_dvd f x h) #align polynomial.eval₂_eq_zero_of_dvd_of_eval₂_eq_zero Polynomial.eval₂_eq_zero_of_dvd_of_eval₂_eq_zero theorem eval₂_list_prod (l : List R[X]) (x : S) : eval₂ f x l.prod = (l.map (eval₂ f x)).prod := map_list_prod (eval₂RingHom f x) l #align polynomial.eval₂_list_prod Polynomial.eval₂_list_prod end end Eval₂ section Eval variable {x : R} /-- `eval x p` is the evaluation of the polynomial `p` at `x` -/ def eval : R → R[X] → R := eval₂ (RingHom.id _) #align polynomial.eval Polynomial.eval theorem eval_eq_sum : p.eval x = p.sum fun e a => a * x ^ e := by rw [eval, eval₂_eq_sum] rfl #align polynomial.eval_eq_sum Polynomial.eval_eq_sum theorem eval_eq_sum_range {p : R[X]} (x : R) : p.eval x = ∑ i ∈ Finset.range (p.natDegree + 1), p.coeff i * x ^ i := by rw [eval_eq_sum, sum_over_range]; simp #align polynomial.eval_eq_sum_range Polynomial.eval_eq_sum_range theorem eval_eq_sum_range' {p : R[X]} {n : ℕ} (hn : p.natDegree < n) (x : R) : p.eval x = ∑ i ∈ Finset.range n, p.coeff i * x ^ i := by rw [eval_eq_sum, p.sum_over_range' _ _ hn]; simp #align polynomial.eval_eq_sum_range' Polynomial.eval_eq_sum_range' @[simp] theorem eval₂_at_apply {S : Type*} [Semiring S] (f : R →+* S) (r : R) : p.eval₂ f (f r) = f (p.eval r) := by rw [eval₂_eq_sum, eval_eq_sum, sum, sum, map_sum f] simp only [f.map_mul, f.map_pow] #align polynomial.eval₂_at_apply Polynomial.eval₂_at_apply @[simp] theorem eval₂_at_one {S : Type*} [Semiring S] (f : R →+* S) : p.eval₂ f 1 = f (p.eval 1) := by convert eval₂_at_apply (p := p) f 1 simp #align polynomial.eval₂_at_one Polynomial.eval₂_at_one @[simp] theorem eval₂_at_natCast {S : Type*} [Semiring S] (f : R →+* S) (n : ℕ) : p.eval₂ f n = f (p.eval n) := by convert eval₂_at_apply (p := p) f n simp #align polynomial.eval₂_at_nat_cast Polynomial.eval₂_at_natCast @[deprecated (since := "2024-04-17")] alias eval₂_at_nat_cast := eval₂_at_natCast -- See note [no_index around OfNat.ofNat] @[simp] theorem eval₂_at_ofNat {S : Type*} [Semiring S] (f : R →+* S) (n : ℕ) [n.AtLeastTwo] : p.eval₂ f (no_index (OfNat.ofNat n)) = f (p.eval (OfNat.ofNat n)) := by simp [OfNat.ofNat] @[simp] theorem eval_C : (C a).eval x = a := eval₂_C _ _ #align polynomial.eval_C Polynomial.eval_C @[simp] theorem eval_natCast {n : ℕ} : (n : R[X]).eval x = n := by simp only [← C_eq_natCast, eval_C] #align polynomial.eval_nat_cast Polynomial.eval_natCast @[deprecated (since := "2024-04-17")] alias eval_nat_cast := eval_natCast -- See note [no_index around OfNat.ofNat] @[simp] lemma eval_ofNat (n : ℕ) [n.AtLeastTwo] (a : R) : (no_index (OfNat.ofNat n : R[X])).eval a = OfNat.ofNat n := by simp only [OfNat.ofNat, eval_natCast] @[simp] theorem eval_X : X.eval x = x := eval₂_X _ _ #align polynomial.eval_X Polynomial.eval_X @[simp] theorem eval_monomial {n a} : (monomial n a).eval x = a * x ^ n := eval₂_monomial _ _ #align polynomial.eval_monomial Polynomial.eval_monomial @[simp] theorem eval_zero : (0 : R[X]).eval x = 0 := eval₂_zero _ _ #align polynomial.eval_zero Polynomial.eval_zero @[simp] theorem eval_add : (p + q).eval x = p.eval x + q.eval x := eval₂_add _ _ #align polynomial.eval_add Polynomial.eval_add @[simp] theorem eval_one : (1 : R[X]).eval x = 1 := eval₂_one _ _ #align polynomial.eval_one Polynomial.eval_one set_option linter.deprecated false in @[simp] theorem eval_bit0 : (bit0 p).eval x = bit0 (p.eval x) := eval₂_bit0 _ _ #align polynomial.eval_bit0 Polynomial.eval_bit0 set_option linter.deprecated false in @[simp] theorem eval_bit1 : (bit1 p).eval x = bit1 (p.eval x) := eval₂_bit1 _ _ #align polynomial.eval_bit1 Polynomial.eval_bit1 @[simp] theorem eval_smul [Monoid S] [DistribMulAction S R] [IsScalarTower S R R] (s : S) (p : R[X]) (x : R) : (s • p).eval x = s • p.eval x := by rw [← smul_one_smul R s p, eval, eval₂_smul, RingHom.id_apply, smul_one_mul] #align polynomial.eval_smul Polynomial.eval_smul @[simp] theorem eval_C_mul : (C a * p).eval x = a * p.eval x := by induction p using Polynomial.induction_on' with | h_add p q ph qh => simp only [mul_add, eval_add, ph, qh] | h_monomial n b => simp only [mul_assoc, C_mul_monomial, eval_monomial] #align polynomial.eval_C_mul Polynomial.eval_C_mul /-- A reformulation of the expansion of (1 + y)^d: $$(d + 1) (1 + y)^d - (d + 1)y^d = \sum_{i = 0}^d {d + 1 \choose i} \cdot i \cdot y^{i - 1}.$$ -/ theorem eval_monomial_one_add_sub [CommRing S] (d : ℕ) (y : S) : eval (1 + y) (monomial d (d + 1 : S)) - eval y (monomial d (d + 1 : S)) = ∑ x_1 ∈ range (d + 1), ↑((d + 1).choose x_1) * (↑x_1 * y ^ (x_1 - 1)) := by have cast_succ : (d + 1 : S) = ((d.succ : ℕ) : S) := by simp only [Nat.cast_succ] rw [cast_succ, eval_monomial, eval_monomial, add_comm, add_pow] -- Porting note: `apply_congr` hadn't been ported yet, so `congr` & `ext` is used. conv_lhs => congr · congr · skip · congr · skip · ext rw [one_pow, mul_one, mul_comm] rw [sum_range_succ, mul_add, Nat.choose_self, Nat.cast_one, one_mul, add_sub_cancel_right, mul_sum, sum_range_succ', Nat.cast_zero, zero_mul, mul_zero, add_zero] refine sum_congr rfl fun y _hy => ?_ rw [← mul_assoc, ← mul_assoc, ← Nat.cast_mul, Nat.succ_mul_choose_eq, Nat.cast_mul, Nat.add_sub_cancel] #align polynomial.eval_monomial_one_add_sub Polynomial.eval_monomial_one_add_sub /-- `Polynomial.eval` as linear map -/ @[simps] def leval {R : Type*} [Semiring R] (r : R) : R[X] →ₗ[R] R where toFun f := f.eval r map_add' _f _g := eval_add map_smul' c f := eval_smul c f r #align polynomial.leval Polynomial.leval #align polynomial.leval_apply Polynomial.leval_apply @[simp] theorem eval_natCast_mul {n : ℕ} : ((n : R[X]) * p).eval x = n * p.eval x := by rw [← C_eq_natCast, eval_C_mul] #align polynomial.eval_nat_cast_mul Polynomial.eval_natCast_mul @[deprecated (since := "2024-04-17")] alias eval_nat_cast_mul := eval_natCast_mul @[simp] theorem eval_mul_X : (p * X).eval x = p.eval x * x := by induction p using Polynomial.induction_on' with | h_add p q ph qh => simp only [add_mul, eval_add, ph, qh] | h_monomial n a => simp only [← monomial_one_one_eq_X, monomial_mul_monomial, eval_monomial, mul_one, pow_succ, mul_assoc] #align polynomial.eval_mul_X Polynomial.eval_mul_X @[simp] theorem eval_mul_X_pow {k : ℕ} : (p * X ^ k).eval x = p.eval x * x ^ k := by induction' k with k ih · simp · simp [pow_succ, ← mul_assoc, ih] #align polynomial.eval_mul_X_pow Polynomial.eval_mul_X_pow theorem eval_sum (p : R[X]) (f : ℕ → R → R[X]) (x : R) : (p.sum f).eval x = p.sum fun n a => (f n a).eval x := eval₂_sum _ _ _ _ #align polynomial.eval_sum Polynomial.eval_sum theorem eval_finset_sum (s : Finset ι) (g : ι → R[X]) (x : R) : (∑ i ∈ s, g i).eval x = ∑ i ∈ s, (g i).eval x := eval₂_finset_sum _ _ _ _ #align polynomial.eval_finset_sum Polynomial.eval_finset_sum /-- `IsRoot p x` implies `x` is a root of `p`. The evaluation of `p` at `x` is zero -/ def IsRoot (p : R[X]) (a : R) : Prop := p.eval a = 0 #align polynomial.is_root Polynomial.IsRoot instance IsRoot.decidable [DecidableEq R] : Decidable (IsRoot p a) := by unfold IsRoot; infer_instance #align polynomial.is_root.decidable Polynomial.IsRoot.decidable @[simp] theorem IsRoot.def : IsRoot p a ↔ p.eval a = 0 := Iff.rfl #align polynomial.is_root.def Polynomial.IsRoot.def theorem IsRoot.eq_zero (h : IsRoot p x) : eval x p = 0 := h #align polynomial.is_root.eq_zero Polynomial.IsRoot.eq_zero theorem coeff_zero_eq_eval_zero (p : R[X]) : coeff p 0 = p.eval 0 := calc coeff p 0 = coeff p 0 * 0 ^ 0 := by simp _ = p.eval 0 := by symm rw [eval_eq_sum] exact Finset.sum_eq_single _ (fun b _ hb => by simp [zero_pow hb]) (by simp) #align polynomial.coeff_zero_eq_eval_zero Polynomial.coeff_zero_eq_eval_zero theorem zero_isRoot_of_coeff_zero_eq_zero {p : R[X]} (hp : p.coeff 0 = 0) : IsRoot p 0 := by rwa [coeff_zero_eq_eval_zero] at hp #align polynomial.zero_is_root_of_coeff_zero_eq_zero Polynomial.zero_isRoot_of_coeff_zero_eq_zero theorem IsRoot.dvd {R : Type*} [CommSemiring R] {p q : R[X]} {x : R} (h : p.IsRoot x) (hpq : p ∣ q) : q.IsRoot x := by rwa [IsRoot, eval, eval₂_eq_zero_of_dvd_of_eval₂_eq_zero _ _ hpq] #align polynomial.is_root.dvd Polynomial.IsRoot.dvd theorem not_isRoot_C (r a : R) (hr : r ≠ 0) : ¬IsRoot (C r) a := by simpa using hr #align polynomial.not_is_root_C Polynomial.not_isRoot_C theorem eval_surjective (x : R) : Function.Surjective <| eval x := fun y => ⟨C y, eval_C⟩ #align polynomial.eval_surjective Polynomial.eval_surjective end Eval section Comp /-- The composition of polynomials as a polynomial. -/ def comp (p q : R[X]) : R[X] := p.eval₂ C q #align polynomial.comp Polynomial.comp theorem comp_eq_sum_left : p.comp q = p.sum fun e a => C a * q ^ e := by rw [comp, eval₂_eq_sum] #align polynomial.comp_eq_sum_left Polynomial.comp_eq_sum_left @[simp] theorem comp_X : p.comp X = p := by simp only [comp, eval₂_def, C_mul_X_pow_eq_monomial] exact sum_monomial_eq _ #align polynomial.comp_X Polynomial.comp_X @[simp] theorem X_comp : X.comp p = p := eval₂_X _ _ #align polynomial.X_comp Polynomial.X_comp @[simp] theorem comp_C : p.comp (C a) = C (p.eval a) := by simp [comp, map_sum (C : R →+* _)] #align polynomial.comp_C Polynomial.comp_C @[simp] theorem C_comp : (C a).comp p = C a := eval₂_C _ _ #align polynomial.C_comp Polynomial.C_comp @[simp] theorem natCast_comp {n : ℕ} : (n : R[X]).comp p = n := by rw [← C_eq_natCast, C_comp] #align polynomial.nat_cast_comp Polynomial.natCast_comp @[deprecated (since := "2024-04-17")] alias nat_cast_comp := natCast_comp -- Porting note (#10756): new theorem @[simp] theorem ofNat_comp (n : ℕ) [n.AtLeastTwo] : (no_index (OfNat.ofNat n) : R[X]).comp p = n := natCast_comp @[simp] theorem comp_zero : p.comp (0 : R[X]) = C (p.eval 0) := by rw [← C_0, comp_C] #align polynomial.comp_zero Polynomial.comp_zero @[simp] theorem zero_comp : comp (0 : R[X]) p = 0 := by rw [← C_0, C_comp] #align polynomial.zero_comp Polynomial.zero_comp @[simp] theorem comp_one : p.comp 1 = C (p.eval 1) := by rw [← C_1, comp_C] #align polynomial.comp_one Polynomial.comp_one @[simp] theorem one_comp : comp (1 : R[X]) p = 1 := by rw [← C_1, C_comp] #align polynomial.one_comp Polynomial.one_comp @[simp] theorem add_comp : (p + q).comp r = p.comp r + q.comp r := eval₂_add _ _ #align polynomial.add_comp Polynomial.add_comp @[simp] theorem monomial_comp (n : ℕ) : (monomial n a).comp p = C a * p ^ n := eval₂_monomial _ _ #align polynomial.monomial_comp Polynomial.monomial_comp @[simp] theorem mul_X_comp : (p * X).comp r = p.comp r * r := by induction p using Polynomial.induction_on' with | h_add p q hp hq => simp only [hp, hq, add_mul, add_comp] | h_monomial n b => simp only [pow_succ, mul_assoc, monomial_mul_X, monomial_comp] #align polynomial.mul_X_comp Polynomial.mul_X_comp @[simp] theorem X_pow_comp {k : ℕ} : (X ^ k).comp p = p ^ k := by induction' k with k ih · simp · simp [pow_succ, mul_X_comp, ih] #align polynomial.X_pow_comp Polynomial.X_pow_comp @[simp] theorem mul_X_pow_comp {k : ℕ} : (p * X ^ k).comp r = p.comp r * r ^ k := by induction' k with k ih · simp · simp [ih, pow_succ, ← mul_assoc, mul_X_comp] #align polynomial.mul_X_pow_comp Polynomial.mul_X_pow_comp @[simp] theorem C_mul_comp : (C a * p).comp r = C a * p.comp r := by induction p using Polynomial.induction_on' with | h_add p q hp hq => simp [hp, hq, mul_add] | h_monomial n b => simp [mul_assoc] #align polynomial.C_mul_comp Polynomial.C_mul_comp @[simp] theorem natCast_mul_comp {n : ℕ} : ((n : R[X]) * p).comp r = n * p.comp r := by rw [← C_eq_natCast, C_mul_comp] #align polynomial.nat_cast_mul_comp Polynomial.natCast_mul_comp @[deprecated (since := "2024-04-17")] alias nat_cast_mul_comp := natCast_mul_comp theorem mul_X_add_natCast_comp {n : ℕ} : (p * (X + (n : R[X]))).comp q = p.comp q * (q + n) := by rw [mul_add, add_comp, mul_X_comp, ← Nat.cast_comm, natCast_mul_comp, Nat.cast_comm, mul_add] set_option linter.uppercaseLean3 false in #align polynomial.mul_X_add_nat_cast_comp Polynomial.mul_X_add_natCast_comp @[deprecated (since := "2024-04-17")] alias mul_X_add_nat_cast_comp := mul_X_add_natCast_comp @[simp] theorem mul_comp {R : Type*} [CommSemiring R] (p q r : R[X]) : (p * q).comp r = p.comp r * q.comp r := eval₂_mul _ _ #align polynomial.mul_comp Polynomial.mul_comp @[simp] theorem pow_comp {R : Type*} [CommSemiring R] (p q : R[X]) (n : ℕ) : (p ^ n).comp q = p.comp q ^ n := (MonoidHom.mk (OneHom.mk (fun r : R[X] => r.comp q) one_comp) fun r s => mul_comp r s q).map_pow p n #align polynomial.pow_comp Polynomial.pow_comp set_option linter.deprecated false in @[simp] theorem bit0_comp : comp (bit0 p : R[X]) q = bit0 (p.comp q) := by simp only [bit0, add_comp] #align polynomial.bit0_comp Polynomial.bit0_comp set_option linter.deprecated false in @[simp] theorem bit1_comp : comp (bit1 p : R[X]) q = bit1 (p.comp q) := by simp only [bit1, add_comp, bit0_comp, one_comp] #align polynomial.bit1_comp Polynomial.bit1_comp @[simp] theorem smul_comp [Monoid S] [DistribMulAction S R] [IsScalarTower S R R] (s : S) (p q : R[X]) : (s • p).comp q = s • p.comp q := by rw [← smul_one_smul R s p, comp, comp, eval₂_smul, ← smul_eq_C_mul, smul_assoc, one_smul] #align polynomial.smul_comp Polynomial.smul_comp theorem comp_assoc {R : Type*} [CommSemiring R] (φ ψ χ : R[X]) : (φ.comp ψ).comp χ = φ.comp (ψ.comp χ) := by refine Polynomial.induction_on φ ?_ ?_ ?_ <;> · intros simp_all only [add_comp, mul_comp, C_comp, X_comp, pow_succ, ← mul_assoc] #align polynomial.comp_assoc Polynomial.comp_assoc theorem coeff_comp_degree_mul_degree (hqd0 : natDegree q ≠ 0) : coeff (p.comp q) (natDegree p * natDegree q) = leadingCoeff p * leadingCoeff q ^ natDegree p := by rw [comp, eval₂_def, coeff_sum] -- Porting note: `convert` → `refine` refine Eq.trans (Finset.sum_eq_single p.natDegree ?h₀ ?h₁) ?h₂ case h₂ => simp only [coeff_natDegree, coeff_C_mul, coeff_pow_mul_natDegree] case h₀ => intro b hbs hbp refine coeff_eq_zero_of_natDegree_lt (natDegree_mul_le.trans_lt ?_) rw [natDegree_C, zero_add] refine natDegree_pow_le.trans_lt ((mul_lt_mul_right (pos_iff_ne_zero.mpr hqd0)).mpr ?_) exact lt_of_le_of_ne (le_natDegree_of_mem_supp _ hbs) hbp case h₁ => simp (config := { contextual := true }) #align polynomial.coeff_comp_degree_mul_degree Polynomial.coeff_comp_degree_mul_degree @[simp] lemma sum_comp (s : Finset ι) (p : ι → R[X]) (q : R[X]) : (∑ i ∈ s, p i).comp q = ∑ i ∈ s, (p i).comp q := Polynomial.eval₂_finset_sum _ _ _ _ end Comp section Map variable [Semiring S] variable (f : R →+* S) /-- `map f p` maps a polynomial `p` across a ring hom `f` -/ def map : R[X] → S[X] := eval₂ (C.comp f) X #align polynomial.map Polynomial.map @[simp] theorem map_C : (C a).map f = C (f a) := eval₂_C _ _ #align polynomial.map_C Polynomial.map_C @[simp] theorem map_X : X.map f = X := eval₂_X _ _ #align polynomial.map_X Polynomial.map_X @[simp] theorem map_monomial {n a} : (monomial n a).map f = monomial n (f a) := by dsimp only [map] rw [eval₂_monomial, ← C_mul_X_pow_eq_monomial]; rfl #align polynomial.map_monomial Polynomial.map_monomial @[simp] protected theorem map_zero : (0 : R[X]).map f = 0 := eval₂_zero _ _ #align polynomial.map_zero Polynomial.map_zero @[simp] protected theorem map_add : (p + q).map f = p.map f + q.map f := eval₂_add _ _ #align polynomial.map_add Polynomial.map_add @[simp] protected theorem map_one : (1 : R[X]).map f = 1 := eval₂_one _ _ #align polynomial.map_one Polynomial.map_one @[simp] protected theorem map_mul : (p * q).map f = p.map f * q.map f := by rw [map, eval₂_mul_noncomm] exact fun k => (commute_X _).symm #align polynomial.map_mul Polynomial.map_mul @[simp] protected theorem map_smul (r : R) : (r • p).map f = f r • p.map f := by rw [map, eval₂_smul, RingHom.comp_apply, C_mul'] #align polynomial.map_smul Polynomial.map_smul -- `map` is a ring-hom unconditionally, and theoretically the definition could be replaced, -- but this turns out not to be easy because `p.map f` does not resolve to `Polynomial.map` -- if `map` is a `RingHom` instead of a plain function; the elaborator does not try to coerce -- to a function before trying field (dot) notation (this may be technically infeasible); -- the relevant code is (both lines): https://github.com/leanprover-community/ -- lean/blob/487ac5d7e9b34800502e1ddf3c7c806c01cf9d51/src/frontends/lean/elaborator.cpp#L1876-L1913 /-- `Polynomial.map` as a `RingHom`. -/ def mapRingHom (f : R →+* S) : R[X] →+* S[X] where toFun := Polynomial.map f map_add' _ _ := Polynomial.map_add f map_zero' := Polynomial.map_zero f map_mul' _ _ := Polynomial.map_mul f map_one' := Polynomial.map_one f #align polynomial.map_ring_hom Polynomial.mapRingHom @[simp] theorem coe_mapRingHom (f : R →+* S) : ⇑(mapRingHom f) = map f := rfl #align polynomial.coe_map_ring_hom Polynomial.coe_mapRingHom -- This is protected to not clash with the global `map_natCast`. @[simp] protected theorem map_natCast (n : ℕ) : (n : R[X]).map f = n := map_natCast (mapRingHom f) n #align polynomial.map_nat_cast Polynomial.map_natCast @[deprecated (since := "2024-04-17")] alias map_nat_cast := map_natCast -- Porting note (#10756): new theorem -- See note [no_index around OfNat.ofNat] @[simp] protected theorem map_ofNat (n : ℕ) [n.AtLeastTwo] : (no_index (OfNat.ofNat n) : R[X]).map f = OfNat.ofNat n := show (n : R[X]).map f = n by rw [Polynomial.map_natCast] #noalign polynomial.map_bit0 #noalign polynomial.map_bit1 --TODO rename to `map_dvd_map` theorem map_dvd (f : R →+* S) {x y : R[X]} : x ∣ y → x.map f ∣ y.map f := (mapRingHom f).map_dvd #align polynomial.map_dvd Polynomial.map_dvd @[simp] theorem coeff_map (n : ℕ) : coeff (p.map f) n = f (coeff p n) := by rw [map, eval₂_def, coeff_sum, sum] conv_rhs => rw [← sum_C_mul_X_pow_eq p, coeff_sum, sum, map_sum] refine Finset.sum_congr rfl fun x _hx => ?_ simp only [RingHom.coe_comp, Function.comp, coeff_C_mul_X_pow] split_ifs <;> simp [f.map_zero] #align polynomial.coeff_map Polynomial.coeff_map /-- If `R` and `S` are isomorphic, then so are their polynomial rings. -/ @[simps!] def mapEquiv (e : R ≃+* S) : R[X] ≃+* S[X] := RingEquiv.ofHomInv (mapRingHom (e : R →+* S)) (mapRingHom (e.symm : S →+* R)) (by ext <;> simp) (by ext <;> simp) #align polynomial.map_equiv Polynomial.mapEquiv #align polynomial.map_equiv_apply Polynomial.mapEquiv_apply #align polynomial.map_equiv_symm_apply Polynomial.mapEquiv_symm_apply theorem map_map [Semiring T] (g : S →+* T) (p : R[X]) : (p.map f).map g = p.map (g.comp f) := ext (by simp [coeff_map]) #align polynomial.map_map Polynomial.map_map @[simp] theorem map_id : p.map (RingHom.id _) = p := by simp [Polynomial.ext_iff, coeff_map] #align polynomial.map_id Polynomial.map_id /-- The polynomial ring over a finite product of rings is isomorphic to the product of polynomial rings over individual rings. -/ def piEquiv {ι} [Finite ι] (R : ι → Type*) [∀ i, Semiring (R i)] : (∀ i, R i)[X] ≃+* ∀ i, (R i)[X] := .ofBijective (Pi.ringHom fun i ↦ mapRingHom (Pi.evalRingHom R i)) ⟨fun p q h ↦ by ext n i; simpa using congr_arg (fun p ↦ coeff (p i) n) h, fun p ↦ ⟨.ofFinsupp (.ofSupportFinite (fun n i ↦ coeff (p i) n) <| (Set.finite_iUnion fun i ↦ (p i).support.finite_toSet).subset fun n hn ↦ by simp only [Set.mem_iUnion, Finset.mem_coe, mem_support_iff, Function.mem_support] at hn ⊢ contrapose! hn; exact funext hn), by ext i n; exact coeff_map _ _⟩⟩ theorem eval₂_eq_eval_map {x : S} : p.eval₂ f x = (p.map f).eval x := by induction p using Polynomial.induction_on' with | h_add p q hp hq => simp [hp, hq] | h_monomial n r => simp #align polynomial.eval₂_eq_eval_map Polynomial.eval₂_eq_eval_map theorem map_injective (hf : Function.Injective f) : Function.Injective (map f) := fun p q h => ext fun m => hf <| by rw [← coeff_map f, ← coeff_map f, h] #align polynomial.map_injective Polynomial.map_injective theorem map_surjective (hf : Function.Surjective f) : Function.Surjective (map f) := fun p => Polynomial.induction_on' p (fun p q hp hq => let ⟨p', hp'⟩ := hp let ⟨q', hq'⟩ := hq ⟨p' + q', by rw [Polynomial.map_add f, hp', hq']⟩) fun n s => let ⟨r, hr⟩ := hf s ⟨monomial n r, by rw [map_monomial f, hr]⟩ #align polynomial.map_surjective Polynomial.map_surjective theorem degree_map_le (p : R[X]) : degree (p.map f) ≤ degree p := by refine (degree_le_iff_coeff_zero _ _).2 fun m hm => ?_ rw [degree_lt_iff_coeff_zero] at hm simp [hm m le_rfl] #align polynomial.degree_map_le Polynomial.degree_map_le theorem natDegree_map_le (p : R[X]) : natDegree (p.map f) ≤ natDegree p := natDegree_le_natDegree (degree_map_le f p) #align polynomial.nat_degree_map_le Polynomial.natDegree_map_le variable {f} protected theorem map_eq_zero_iff (hf : Function.Injective f) : p.map f = 0 ↔ p = 0 := map_eq_zero_iff (mapRingHom f) (map_injective f hf) #align polynomial.map_eq_zero_iff Polynomial.map_eq_zero_iff protected theorem map_ne_zero_iff (hf : Function.Injective f) : p.map f ≠ 0 ↔ p ≠ 0 := (Polynomial.map_eq_zero_iff hf).not #align polynomial.map_ne_zero_iff Polynomial.map_ne_zero_iff theorem map_monic_eq_zero_iff (hp : p.Monic) : p.map f = 0 ↔ ∀ x, f x = 0 := ⟨fun hfp x => calc f x = f x * f p.leadingCoeff := by simp only [mul_one, hp.leadingCoeff, f.map_one] _ = f x * (p.map f).coeff p.natDegree := congr_arg _ (coeff_map _ _).symm _ = 0 := by simp only [hfp, mul_zero, coeff_zero] , fun h => ext fun n => by simp only [h, coeff_map, coeff_zero]⟩ #align polynomial.map_monic_eq_zero_iff Polynomial.map_monic_eq_zero_iff theorem map_monic_ne_zero (hp : p.Monic) [Nontrivial S] : p.map f ≠ 0 := fun h => f.map_one_ne_zero ((map_monic_eq_zero_iff hp).mp h _) #align polynomial.map_monic_ne_zero Polynomial.map_monic_ne_zero theorem degree_map_eq_of_leadingCoeff_ne_zero (f : R →+* S) (hf : f (leadingCoeff p) ≠ 0) : degree (p.map f) = degree p := le_antisymm (degree_map_le f _) <| by have hp0 : p ≠ 0 := leadingCoeff_ne_zero.mp fun hp0 => hf (_root_.trans (congr_arg _ hp0) f.map_zero) rw [degree_eq_natDegree hp0] refine le_degree_of_ne_zero ?_ rw [coeff_map] exact hf #align polynomial.degree_map_eq_of_leading_coeff_ne_zero Polynomial.degree_map_eq_of_leadingCoeff_ne_zero theorem natDegree_map_of_leadingCoeff_ne_zero (f : R →+* S) (hf : f (leadingCoeff p) ≠ 0) : natDegree (p.map f) = natDegree p := natDegree_eq_of_degree_eq (degree_map_eq_of_leadingCoeff_ne_zero f hf) #align polynomial.nat_degree_map_of_leading_coeff_ne_zero Polynomial.natDegree_map_of_leadingCoeff_ne_zero theorem leadingCoeff_map_of_leadingCoeff_ne_zero (f : R →+* S) (hf : f (leadingCoeff p) ≠ 0) : leadingCoeff (p.map f) = f (leadingCoeff p) := by unfold leadingCoeff rw [coeff_map, natDegree_map_of_leadingCoeff_ne_zero f hf] #align polynomial.leading_coeff_map_of_leading_coeff_ne_zero Polynomial.leadingCoeff_map_of_leadingCoeff_ne_zero variable (f) @[simp] theorem mapRingHom_id : mapRingHom (RingHom.id R) = RingHom.id R[X] := RingHom.ext fun _x => map_id #align polynomial.map_ring_hom_id Polynomial.mapRingHom_id @[simp] theorem mapRingHom_comp [Semiring T] (f : S →+* T) (g : R →+* S) : (mapRingHom f).comp (mapRingHom g) = mapRingHom (f.comp g) := RingHom.ext <| Polynomial.map_map g f #align polynomial.map_ring_hom_comp Polynomial.mapRingHom_comp protected theorem map_list_prod (L : List R[X]) : L.prod.map f = (L.map <| map f).prod := Eq.symm <| List.prod_hom _ (mapRingHom f).toMonoidHom #align polynomial.map_list_prod Polynomial.map_list_prod @[simp] protected theorem map_pow (n : ℕ) : (p ^ n).map f = p.map f ^ n := (mapRingHom f).map_pow _ _ #align polynomial.map_pow Polynomial.map_pow theorem mem_map_rangeS {p : S[X]} : p ∈ (mapRingHom f).rangeS ↔ ∀ n, p.coeff n ∈ f.rangeS := by constructor · rintro ⟨p, rfl⟩ n rw [coe_mapRingHom, coeff_map] exact Set.mem_range_self _ · intro h rw [p.as_sum_range_C_mul_X_pow] refine (mapRingHom f).rangeS.sum_mem ?_ intro i _hi rcases h i with ⟨c, hc⟩ use C c * X ^ i rw [coe_mapRingHom, Polynomial.map_mul, map_C, hc, Polynomial.map_pow, map_X] #align polynomial.mem_map_srange Polynomial.mem_map_rangeS theorem mem_map_range {R S : Type*} [Ring R] [Ring S] (f : R →+* S) {p : S[X]} : p ∈ (mapRingHom f).range ↔ ∀ n, p.coeff n ∈ f.range := mem_map_rangeS f #align polynomial.mem_map_range Polynomial.mem_map_range theorem eval₂_map [Semiring T] (g : S →+* T) (x : T) : (p.map f).eval₂ g x = p.eval₂ (g.comp f) x := by rw [eval₂_eq_eval_map, eval₂_eq_eval_map, map_map] #align polynomial.eval₂_map Polynomial.eval₂_map theorem eval_map (x : S) : (p.map f).eval x = p.eval₂ f x := (eval₂_eq_eval_map f).symm #align polynomial.eval_map Polynomial.eval_map protected theorem map_sum {ι : Type*} (g : ι → R[X]) (s : Finset ι) : (∑ i ∈ s, g i).map f = ∑ i ∈ s, (g i).map f := map_sum (mapRingHom f) _ _ #align polynomial.map_sum Polynomial.map_sum theorem map_comp (p q : R[X]) : map f (p.comp q) = (map f p).comp (map f q) := Polynomial.induction_on p (by simp only [map_C, forall_const, C_comp, eq_self_iff_true]) (by simp (config := { contextual := true }) only [Polynomial.map_add, add_comp, forall_const, imp_true_iff, eq_self_iff_true]) (by simp (config := { contextual := true }) only [pow_succ, ← mul_assoc, comp, forall_const, eval₂_mul_X, imp_true_iff, eq_self_iff_true, map_X, Polynomial.map_mul]) #align polynomial.map_comp Polynomial.map_comp @[simp] theorem eval_zero_map (f : R →+* S) (p : R[X]) : (p.map f).eval 0 = f (p.eval 0) := by simp [← coeff_zero_eq_eval_zero] #align polynomial.eval_zero_map Polynomial.eval_zero_map @[simp] theorem eval_one_map (f : R →+* S) (p : R[X]) : (p.map f).eval 1 = f (p.eval 1) := by induction p using Polynomial.induction_on' with | h_add p q hp hq => simp only [hp, hq, Polynomial.map_add, RingHom.map_add, eval_add] | h_monomial n r => simp only [one_pow, mul_one, eval_monomial, map_monomial] #align polynomial.eval_one_map Polynomial.eval_one_map @[simp] theorem eval_natCast_map (f : R →+* S) (p : R[X]) (n : ℕ) : (p.map f).eval (n : S) = f (p.eval n) := by induction p using Polynomial.induction_on' with | h_add p q hp hq => simp only [hp, hq, Polynomial.map_add, RingHom.map_add, eval_add] | h_monomial n r => simp only [map_natCast f, eval_monomial, map_monomial, f.map_pow, f.map_mul] #align polynomial.eval_nat_cast_map Polynomial.eval_natCast_map @[deprecated (since := "2024-04-17")] alias eval_nat_cast_map := eval_natCast_map @[simp] theorem eval_intCast_map {R S : Type*} [Ring R] [Ring S] (f : R →+* S) (p : R[X]) (i : ℤ) : (p.map f).eval (i : S) = f (p.eval i) := by induction p using Polynomial.induction_on' with | h_add p q hp hq => simp only [hp, hq, Polynomial.map_add, RingHom.map_add, eval_add] | h_monomial n r => simp only [map_intCast, eval_monomial, map_monomial, map_pow, map_mul] #align polynomial.eval_int_cast_map Polynomial.eval_intCast_map @[deprecated (since := "2024-04-17")] alias eval_int_cast_map := eval_intCast_map end Map /-! we have made `eval₂` irreducible from the start. Perhaps we can make also `eval`, `comp`, and `map` irreducible too? -/ section HomEval₂ variable [Semiring S] [Semiring T] (f : R →+* S) (g : S →+* T) (p) theorem hom_eval₂ (x : S) : g (p.eval₂ f x) = p.eval₂ (g.comp f) (g x) := by rw [← eval₂_map, eval₂_at_apply, eval_map] #align polynomial.hom_eval₂ Polynomial.hom_eval₂ end HomEval₂ end Semiring section CommSemiring section Eval section variable [Semiring R] {p q : R[X]} {x : R} [Semiring S] (f : R →+* S) theorem eval₂_hom (x : R) : p.eval₂ f (f x) = f (p.eval x) := RingHom.comp_id f ▸ (hom_eval₂ p (RingHom.id R) f x).symm #align polynomial.eval₂_hom Polynomial.eval₂_hom end section variable [Semiring R] {p q : R[X]} {x : R} [CommSemiring S] (f : R →+* S) theorem eval₂_comp {x : S} : eval₂ f x (p.comp q) = eval₂ f (eval₂ f x q) p := by rw [comp, p.as_sum_range]; simp [eval₂_finset_sum, eval₂_pow] #align polynomial.eval₂_comp Polynomial.eval₂_comp @[simp] theorem iterate_comp_eval₂ (k : ℕ) (t : S) : eval₂ f t (p.comp^[k] q) = (fun x => eval₂ f x p)^[k] (eval₂ f t q) := by induction' k with k IH · simp · rw [Function.iterate_succ_apply', Function.iterate_succ_apply', eval₂_comp, IH] #align polynomial.iterate_comp_eval₂ Polynomial.iterate_comp_eval₂ end section Algebra variable [CommSemiring R] [Semiring S] [Algebra R S] (x : S) (p q : R[X]) @[simp] theorem eval₂_mul' : (p * q).eval₂ (algebraMap R S) x = p.eval₂ (algebraMap R S) x * q.eval₂ (algebraMap R S) x := by exact eval₂_mul_noncomm _ _ fun k => Algebra.commute_algebraMap_left (coeff q k) x @[simp] theorem eval₂_pow' (n : ℕ) : (p ^ n).eval₂ (algebraMap R S) x = (p.eval₂ (algebraMap R S) x) ^ n := by induction n with | zero => simp only [Nat.zero_eq, pow_zero, eval₂_one] | succ n ih => rw [pow_succ, pow_succ, eval₂_mul', ih] @[simp] theorem eval₂_comp' : eval₂ (algebraMap R S) x (p.comp q) = eval₂ (algebraMap R S) (eval₂ (algebraMap R S) x q) p := by induction p using Polynomial.induction_on' with | h_add r s hr hs => simp only [add_comp, eval₂_add, hr, hs] | h_monomial n a => simp only [monomial_comp, eval₂_mul', eval₂_C, eval₂_monomial, eval₂_pow'] end Algebra section variable [CommSemiring R] {p q : R[X]} {x : R} [CommSemiring S] (f : R →+* S) @[simp] theorem eval_mul : (p * q).eval x = p.eval x * q.eval x := eval₂_mul _ _ #align polynomial.eval_mul Polynomial.eval_mul /-- `eval r`, regarded as a ring homomorphism from `R[X]` to `R`. -/ def evalRingHom : R → R[X] →+* R := eval₂RingHom (RingHom.id _) #align polynomial.eval_ring_hom Polynomial.evalRingHom @[simp] theorem coe_evalRingHom (r : R) : (evalRingHom r : R[X] → R) = eval r := rfl #align polynomial.coe_eval_ring_hom Polynomial.coe_evalRingHom theorem evalRingHom_zero : evalRingHom 0 = constantCoeff := DFunLike.ext _ _ fun p => p.coeff_zero_eq_eval_zero.symm #align polynomial.eval_ring_hom_zero Polynomial.evalRingHom_zero @[simp] theorem eval_pow (n : ℕ) : (p ^ n).eval x = p.eval x ^ n := eval₂_pow _ _ _ #align polynomial.eval_pow Polynomial.eval_pow @[simp] theorem eval_comp : (p.comp q).eval x = p.eval (q.eval x) := by induction p using Polynomial.induction_on' with | h_add r s hr hs => simp [add_comp, hr, hs] | h_monomial n a => simp #align polynomial.eval_comp Polynomial.eval_comp @[simp] theorem iterate_comp_eval : ∀ (k : ℕ) (t : R), (p.comp^[k] q).eval t = (fun x => p.eval x)^[k] (q.eval t) := iterate_comp_eval₂ _ #align polynomial.iterate_comp_eval Polynomial.iterate_comp_eval lemma isRoot_comp {R} [CommSemiring R] {p q : R[X]} {r : R} : (p.comp q).IsRoot r ↔ p.IsRoot (q.eval r) := by simp_rw [IsRoot, eval_comp] /-- `comp p`, regarded as a ring homomorphism from `R[X]` to itself. -/ def compRingHom : R[X] → R[X] →+* R[X] := eval₂RingHom C #align polynomial.comp_ring_hom Polynomial.compRingHom @[simp] theorem coe_compRingHom (q : R[X]) : (compRingHom q : R[X] → R[X]) = fun p => comp p q := rfl #align polynomial.coe_comp_ring_hom Polynomial.coe_compRingHom theorem coe_compRingHom_apply (p q : R[X]) : (compRingHom q : R[X] → R[X]) p = comp p q := rfl #align polynomial.coe_comp_ring_hom_apply Polynomial.coe_compRingHom_apply theorem root_mul_left_of_isRoot (p : R[X]) {q : R[X]} : IsRoot q a → IsRoot (p * q) a := fun H => by rw [IsRoot, eval_mul, IsRoot.def.1 H, mul_zero] #align polynomial.root_mul_left_of_is_root Polynomial.root_mul_left_of_isRoot theorem root_mul_right_of_isRoot {p : R[X]} (q : R[X]) : IsRoot p a → IsRoot (p * q) a := fun H => by rw [IsRoot, eval_mul, IsRoot.def.1 H, zero_mul] #align polynomial.root_mul_right_of_is_root Polynomial.root_mul_right_of_isRoot theorem eval₂_multiset_prod (s : Multiset R[X]) (x : S) : eval₂ f x s.prod = (s.map (eval₂ f x)).prod := map_multiset_prod (eval₂RingHom f x) s #align polynomial.eval₂_multiset_prod Polynomial.eval₂_multiset_prod theorem eval₂_finset_prod (s : Finset ι) (g : ι → R[X]) (x : S) : (∏ i ∈ s, g i).eval₂ f x = ∏ i ∈ s, (g i).eval₂ f x := map_prod (eval₂RingHom f x) _ _ #align polynomial.eval₂_finset_prod Polynomial.eval₂_finset_prod /-- Polynomial evaluation commutes with `List.prod` -/ theorem eval_list_prod (l : List R[X]) (x : R) : eval x l.prod = (l.map (eval x)).prod := map_list_prod (evalRingHom x) l #align polynomial.eval_list_prod Polynomial.eval_list_prod /-- Polynomial evaluation commutes with `Multiset.prod` -/ theorem eval_multiset_prod (s : Multiset R[X]) (x : R) : eval x s.prod = (s.map (eval x)).prod := (evalRingHom x).map_multiset_prod s #align polynomial.eval_multiset_prod Polynomial.eval_multiset_prod /-- Polynomial evaluation commutes with `Finset.prod` -/ theorem eval_prod {ι : Type*} (s : Finset ι) (p : ι → R[X]) (x : R) : eval x (∏ j ∈ s, p j) = ∏ j ∈ s, eval x (p j) := map_prod (evalRingHom x) _ _ #align polynomial.eval_prod Polynomial.eval_prod theorem list_prod_comp (l : List R[X]) (q : R[X]) : l.prod.comp q = (l.map fun p : R[X] => p.comp q).prod := map_list_prod (compRingHom q) _ #align polynomial.list_prod_comp Polynomial.list_prod_comp theorem multiset_prod_comp (s : Multiset R[X]) (q : R[X]) : s.prod.comp q = (s.map fun p : R[X] => p.comp q).prod := map_multiset_prod (compRingHom q) _ #align polynomial.multiset_prod_comp Polynomial.multiset_prod_comp theorem prod_comp {ι : Type*} (s : Finset ι) (p : ι → R[X]) (q : R[X]) : (∏ j ∈ s, p j).comp q = ∏ j ∈ s, (p j).comp q := map_prod (compRingHom q) _ _ #align polynomial.prod_comp Polynomial.prod_comp theorem isRoot_prod {R} [CommRing R] [IsDomain R] {ι : Type*} (s : Finset ι) (p : ι → R[X]) (x : R) : IsRoot (∏ j ∈ s, p j) x ↔ ∃ i ∈ s, IsRoot (p i) x := by simp only [IsRoot, eval_prod, Finset.prod_eq_zero_iff] #align polynomial.is_root_prod Polynomial.isRoot_prod theorem eval_dvd : p ∣ q → eval x p ∣ eval x q := eval₂_dvd _ _ #align polynomial.eval_dvd Polynomial.eval_dvd theorem eval_eq_zero_of_dvd_of_eval_eq_zero : p ∣ q → eval x p = 0 → eval x q = 0 := eval₂_eq_zero_of_dvd_of_eval₂_eq_zero _ _ #align polynomial.eval_eq_zero_of_dvd_of_eval_eq_zero Polynomial.eval_eq_zero_of_dvd_of_eval_eq_zero @[simp] theorem eval_geom_sum {R} [CommSemiring R] {n : ℕ} {x : R} : eval x (∑ i ∈ range n, X ^ i) = ∑ i ∈ range n, x ^ i := by simp [eval_finset_sum] #align polynomial.eval_geom_sum Polynomial.eval_geom_sum end end Eval section Map theorem support_map_subset [Semiring R] [Semiring S] (f : R →+* S) (p : R[X]) : (map f p).support ⊆ p.support := by intro x contrapose! simp (config := { contextual := true }) #align polynomial.support_map_subset Polynomial.support_map_subset
Mathlib/Algebra/Polynomial/Eval.lean
1,263
1,266
theorem support_map_of_injective [Semiring R] [Semiring S] (p : R[X]) {f : R →+* S} (hf : Function.Injective f) : (map f p).support = p.support := by
simp_rw [Finset.ext_iff, mem_support_iff, coeff_map, ← map_zero f, hf.ne_iff, forall_const]
/- Copyright (c) 2022 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import Mathlib.Analysis.InnerProductSpace.Dual import Mathlib.Analysis.InnerProductSpace.Orientation import Mathlib.Data.Complex.Orientation import Mathlib.Tactic.LinearCombination #align_import analysis.inner_product_space.two_dim from "leanprover-community/mathlib"@"cd8fafa2fac98e1a67097e8a91ad9901cfde48af" /-! # Oriented two-dimensional real inner product spaces This file defines constructions specific to the geometry of an oriented two-dimensional real inner product space `E`. ## Main declarations * `Orientation.areaForm`: an antisymmetric bilinear form `E →ₗ[ℝ] E →ₗ[ℝ] ℝ` (usual notation `ω`). Morally, when `ω` is evaluated on two vectors, it gives the oriented area of the parallelogram they span. (But mathlib does not yet have a construction of oriented area, and in fact the construction of oriented area should pass through `ω`.) * `Orientation.rightAngleRotation`: an isometric automorphism `E ≃ₗᵢ[ℝ] E` (usual notation `J`). This automorphism squares to -1. In a later file, rotations (`Orientation.rotation`) are defined, in such a way that this automorphism is equal to rotation by 90 degrees. * `Orientation.basisRightAngleRotation`: for a nonzero vector `x` in `E`, the basis `![x, J x]` for `E`. * `Orientation.kahler`: a complex-valued real-bilinear map `E →ₗ[ℝ] E →ₗ[ℝ] ℂ`. Its real part is the inner product and its imaginary part is `Orientation.areaForm`. For vectors `x` and `y` in `E`, the complex number `o.kahler x y` has modulus `‖x‖ * ‖y‖`. In a later file, oriented angles (`Orientation.oangle`) are defined, in such a way that the argument of `o.kahler x y` is the oriented angle from `x` to `y`. ## Main results * `Orientation.rightAngleRotation_rightAngleRotation`: the identity `J (J x) = - x` * `Orientation.nonneg_inner_and_areaForm_eq_zero_iff_sameRay`: `x`, `y` are in the same ray, if and only if `0 ≤ ⟪x, y⟫` and `ω x y = 0` * `Orientation.kahler_mul`: the identity `o.kahler x a * o.kahler a y = ‖a‖ ^ 2 * o.kahler x y` * `Complex.areaForm`, `Complex.rightAngleRotation`, `Complex.kahler`: the concrete interpretations of `areaForm`, `rightAngleRotation`, `kahler` for the oriented real inner product space `ℂ` * `Orientation.areaForm_map_complex`, `Orientation.rightAngleRotation_map_complex`, `Orientation.kahler_map_complex`: given an orientation-preserving isometry from `E` to `ℂ`, expressions for `areaForm`, `rightAngleRotation`, `kahler` as the pullback of their concrete interpretations on `ℂ` ## Implementation notes Notation `ω` for `Orientation.areaForm` and `J` for `Orientation.rightAngleRotation` should be defined locally in each file which uses them, since otherwise one would need a more cumbersome notation which mentions the orientation explicitly (something like `ω[o]`). Write ``` local notation "ω" => o.areaForm local notation "J" => o.rightAngleRotation ``` -/ noncomputable section open scoped RealInnerProductSpace ComplexConjugate open FiniteDimensional lemma FiniteDimensional.of_fact_finrank_eq_two {K V : Type*} [DivisionRing K] [AddCommGroup V] [Module K V] [Fact (finrank K V = 2)] : FiniteDimensional K V := .of_fact_finrank_eq_succ 1 attribute [local instance] FiniteDimensional.of_fact_finrank_eq_two @[deprecated (since := "2024-02-02")] alias FiniteDimensional.finiteDimensional_of_fact_finrank_eq_two := FiniteDimensional.of_fact_finrank_eq_two variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [Fact (finrank ℝ E = 2)] (o : Orientation ℝ E (Fin 2)) namespace Orientation /-- An antisymmetric bilinear form on an oriented real inner product space of dimension 2 (usual notation `ω`). When evaluated on two vectors, it gives the oriented area of the parallelogram they span. -/ irreducible_def areaForm : E →ₗ[ℝ] E →ₗ[ℝ] ℝ := by let z : E [⋀^Fin 0]→ₗ[ℝ] ℝ ≃ₗ[ℝ] ℝ := AlternatingMap.constLinearEquivOfIsEmpty.symm let y : E [⋀^Fin 1]→ₗ[ℝ] ℝ →ₗ[ℝ] E →ₗ[ℝ] ℝ := LinearMap.llcomp ℝ E (E [⋀^Fin 0]→ₗ[ℝ] ℝ) ℝ z ∘ₗ AlternatingMap.curryLeftLinearMap exact y ∘ₗ AlternatingMap.curryLeftLinearMap (R' := ℝ) o.volumeForm #align orientation.area_form Orientation.areaForm local notation "ω" => o.areaForm theorem areaForm_to_volumeForm (x y : E) : ω x y = o.volumeForm ![x, y] := by simp [areaForm] #align orientation.area_form_to_volume_form Orientation.areaForm_to_volumeForm @[simp] theorem areaForm_apply_self (x : E) : ω x x = 0 := by rw [areaForm_to_volumeForm] refine o.volumeForm.map_eq_zero_of_eq ![x, x] ?_ (?_ : (0 : Fin 2) ≠ 1) · simp · norm_num #align orientation.area_form_apply_self Orientation.areaForm_apply_self theorem areaForm_swap (x y : E) : ω x y = -ω y x := by simp only [areaForm_to_volumeForm] convert o.volumeForm.map_swap ![y, x] (_ : (0 : Fin 2) ≠ 1) · ext i fin_cases i <;> rfl · norm_num #align orientation.area_form_swap Orientation.areaForm_swap @[simp] theorem areaForm_neg_orientation : (-o).areaForm = -o.areaForm := by ext x y simp [areaForm_to_volumeForm] #align orientation.area_form_neg_orientation Orientation.areaForm_neg_orientation /-- Continuous linear map version of `Orientation.areaForm`, useful for calculus. -/ def areaForm' : E →L[ℝ] E →L[ℝ] ℝ := LinearMap.toContinuousLinearMap (↑(LinearMap.toContinuousLinearMap : (E →ₗ[ℝ] ℝ) ≃ₗ[ℝ] E →L[ℝ] ℝ) ∘ₗ o.areaForm) #align orientation.area_form' Orientation.areaForm' @[simp] theorem areaForm'_apply (x : E) : o.areaForm' x = LinearMap.toContinuousLinearMap (o.areaForm x) := rfl #align orientation.area_form'_apply Orientation.areaForm'_apply theorem abs_areaForm_le (x y : E) : |ω x y| ≤ ‖x‖ * ‖y‖ := by simpa [areaForm_to_volumeForm, Fin.prod_univ_succ] using o.abs_volumeForm_apply_le ![x, y] #align orientation.abs_area_form_le Orientation.abs_areaForm_le theorem areaForm_le (x y : E) : ω x y ≤ ‖x‖ * ‖y‖ := by simpa [areaForm_to_volumeForm, Fin.prod_univ_succ] using o.volumeForm_apply_le ![x, y] #align orientation.area_form_le Orientation.areaForm_le theorem abs_areaForm_of_orthogonal {x y : E} (h : ⟪x, y⟫ = 0) : |ω x y| = ‖x‖ * ‖y‖ := by rw [o.areaForm_to_volumeForm, o.abs_volumeForm_apply_of_pairwise_orthogonal] · simp [Fin.prod_univ_succ] intro i j hij fin_cases i <;> fin_cases j · simp_all · simpa using h · simpa [real_inner_comm] using h · simp_all #align orientation.abs_area_form_of_orthogonal Orientation.abs_areaForm_of_orthogonal theorem areaForm_map {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] [hF : Fact (finrank ℝ F = 2)] (φ : E ≃ₗᵢ[ℝ] F) (x y : F) : (Orientation.map (Fin 2) φ.toLinearEquiv o).areaForm x y = o.areaForm (φ.symm x) (φ.symm y) := by have : φ.symm ∘ ![x, y] = ![φ.symm x, φ.symm y] := by ext i fin_cases i <;> rfl simp [areaForm_to_volumeForm, volumeForm_map, this] #align orientation.area_form_map Orientation.areaForm_map /-- The area form is invariant under pullback by a positively-oriented isometric automorphism. -/ theorem areaForm_comp_linearIsometryEquiv (φ : E ≃ₗᵢ[ℝ] E) (hφ : 0 < LinearMap.det (φ.toLinearEquiv : E →ₗ[ℝ] E)) (x y : E) : o.areaForm (φ x) (φ y) = o.areaForm x y := by convert o.areaForm_map φ (φ x) (φ y) · symm rwa [← o.map_eq_iff_det_pos φ.toLinearEquiv] at hφ rw [@Fact.out (finrank ℝ E = 2), Fintype.card_fin] · simp · simp #align orientation.area_form_comp_linear_isometry_equiv Orientation.areaForm_comp_linearIsometryEquiv /-- Auxiliary construction for `Orientation.rightAngleRotation`, rotation by 90 degrees in an oriented real inner product space of dimension 2. -/ irreducible_def rightAngleRotationAux₁ : E →ₗ[ℝ] E := let to_dual : E ≃ₗ[ℝ] E →ₗ[ℝ] ℝ := (InnerProductSpace.toDual ℝ E).toLinearEquiv ≪≫ₗ LinearMap.toContinuousLinearMap.symm ↑to_dual.symm ∘ₗ ω #align orientation.right_angle_rotation_aux₁ Orientation.rightAngleRotationAux₁ @[simp] theorem inner_rightAngleRotationAux₁_left (x y : E) : ⟪o.rightAngleRotationAux₁ x, y⟫ = ω x y := by -- Porting note: split `simp only` for greater proof control simp only [rightAngleRotationAux₁, LinearEquiv.trans_symm, LinearIsometryEquiv.toLinearEquiv_symm, LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, LinearEquiv.trans_apply, LinearIsometryEquiv.coe_toLinearEquiv] rw [InnerProductSpace.toDual_symm_apply] norm_cast #align orientation.inner_right_angle_rotation_aux₁_left Orientation.inner_rightAngleRotationAux₁_left @[simp] theorem inner_rightAngleRotationAux₁_right (x y : E) : ⟪x, o.rightAngleRotationAux₁ y⟫ = -ω x y := by rw [real_inner_comm] simp [o.areaForm_swap y x] #align orientation.inner_right_angle_rotation_aux₁_right Orientation.inner_rightAngleRotationAux₁_right /-- Auxiliary construction for `Orientation.rightAngleRotation`, rotation by 90 degrees in an oriented real inner product space of dimension 2. -/ def rightAngleRotationAux₂ : E →ₗᵢ[ℝ] E := { o.rightAngleRotationAux₁ with norm_map' := fun x => by dsimp refine le_antisymm ?_ ?_ · cases' eq_or_lt_of_le (norm_nonneg (o.rightAngleRotationAux₁ x)) with h h · rw [← h] positivity refine le_of_mul_le_mul_right ?_ h rw [← real_inner_self_eq_norm_mul_norm, o.inner_rightAngleRotationAux₁_left] exact o.areaForm_le x (o.rightAngleRotationAux₁ x) · let K : Submodule ℝ E := ℝ ∙ x have : Nontrivial Kᗮ := by apply @FiniteDimensional.nontrivial_of_finrank_pos ℝ have : finrank ℝ K ≤ Finset.card {x} := by rw [← Set.toFinset_singleton] exact finrank_span_le_card ({x} : Set E) have : Finset.card {x} = 1 := Finset.card_singleton x have : finrank ℝ K + finrank ℝ Kᗮ = finrank ℝ E := K.finrank_add_finrank_orthogonal have : finrank ℝ E = 2 := Fact.out linarith obtain ⟨w, hw₀⟩ : ∃ w : Kᗮ, w ≠ 0 := exists_ne 0 have hw' : ⟪x, (w : E)⟫ = 0 := Submodule.mem_orthogonal_singleton_iff_inner_right.mp w.2 have hw : (w : E) ≠ 0 := fun h => hw₀ (Submodule.coe_eq_zero.mp h) refine le_of_mul_le_mul_right ?_ (by rwa [norm_pos_iff] : 0 < ‖(w : E)‖) rw [← o.abs_areaForm_of_orthogonal hw'] rw [← o.inner_rightAngleRotationAux₁_left x w] exact abs_real_inner_le_norm (o.rightAngleRotationAux₁ x) w } #align orientation.right_angle_rotation_aux₂ Orientation.rightAngleRotationAux₂ @[simp] theorem rightAngleRotationAux₁_rightAngleRotationAux₁ (x : E) : o.rightAngleRotationAux₁ (o.rightAngleRotationAux₁ x) = -x := by apply ext_inner_left ℝ intro y have : ⟪o.rightAngleRotationAux₁ y, o.rightAngleRotationAux₁ x⟫ = ⟪y, x⟫ := LinearIsometry.inner_map_map o.rightAngleRotationAux₂ y x rw [o.inner_rightAngleRotationAux₁_right, ← o.inner_rightAngleRotationAux₁_left, this, inner_neg_right] #align orientation.right_angle_rotation_aux₁_right_angle_rotation_aux₁ Orientation.rightAngleRotationAux₁_rightAngleRotationAux₁ /-- An isometric automorphism of an oriented real inner product space of dimension 2 (usual notation `J`). This automorphism squares to -1. We will define rotations in such a way that this automorphism is equal to rotation by 90 degrees. -/ irreducible_def rightAngleRotation : E ≃ₗᵢ[ℝ] E := LinearIsometryEquiv.ofLinearIsometry o.rightAngleRotationAux₂ (-o.rightAngleRotationAux₁) (by ext; simp [rightAngleRotationAux₂]) (by ext; simp [rightAngleRotationAux₂]) #align orientation.right_angle_rotation Orientation.rightAngleRotation local notation "J" => o.rightAngleRotation @[simp] theorem inner_rightAngleRotation_left (x y : E) : ⟪J x, y⟫ = ω x y := by rw [rightAngleRotation] exact o.inner_rightAngleRotationAux₁_left x y #align orientation.inner_right_angle_rotation_left Orientation.inner_rightAngleRotation_left @[simp] theorem inner_rightAngleRotation_right (x y : E) : ⟪x, J y⟫ = -ω x y := by rw [rightAngleRotation] exact o.inner_rightAngleRotationAux₁_right x y #align orientation.inner_right_angle_rotation_right Orientation.inner_rightAngleRotation_right @[simp] theorem rightAngleRotation_rightAngleRotation (x : E) : J (J x) = -x := by rw [rightAngleRotation] exact o.rightAngleRotationAux₁_rightAngleRotationAux₁ x #align orientation.right_angle_rotation_right_angle_rotation Orientation.rightAngleRotation_rightAngleRotation @[simp] theorem rightAngleRotation_symm : LinearIsometryEquiv.symm J = LinearIsometryEquiv.trans J (LinearIsometryEquiv.neg ℝ) := by rw [rightAngleRotation] exact LinearIsometryEquiv.toLinearIsometry_injective rfl #align orientation.right_angle_rotation_symm Orientation.rightAngleRotation_symm -- @[simp] -- Porting note (#10618): simp already proves this theorem inner_rightAngleRotation_self (x : E) : ⟪J x, x⟫ = 0 := by simp #align orientation.inner_right_angle_rotation_self Orientation.inner_rightAngleRotation_self theorem inner_rightAngleRotation_swap (x y : E) : ⟪x, J y⟫ = -⟪J x, y⟫ := by simp #align orientation.inner_right_angle_rotation_swap Orientation.inner_rightAngleRotation_swap theorem inner_rightAngleRotation_swap' (x y : E) : ⟪J x, y⟫ = -⟪x, J y⟫ := by simp [o.inner_rightAngleRotation_swap x y] #align orientation.inner_right_angle_rotation_swap' Orientation.inner_rightAngleRotation_swap' theorem inner_comp_rightAngleRotation (x y : E) : ⟪J x, J y⟫ = ⟪x, y⟫ := LinearIsometryEquiv.inner_map_map J x y #align orientation.inner_comp_right_angle_rotation Orientation.inner_comp_rightAngleRotation @[simp] theorem areaForm_rightAngleRotation_left (x y : E) : ω (J x) y = -⟪x, y⟫ := by rw [← o.inner_comp_rightAngleRotation, o.inner_rightAngleRotation_right, neg_neg] #align orientation.area_form_right_angle_rotation_left Orientation.areaForm_rightAngleRotation_left @[simp] theorem areaForm_rightAngleRotation_right (x y : E) : ω x (J y) = ⟪x, y⟫ := by rw [← o.inner_rightAngleRotation_left, o.inner_comp_rightAngleRotation] #align orientation.area_form_right_angle_rotation_right Orientation.areaForm_rightAngleRotation_right -- @[simp] -- Porting note (#10618): simp already proves this theorem areaForm_comp_rightAngleRotation (x y : E) : ω (J x) (J y) = ω x y := by simp #align orientation.area_form_comp_right_angle_rotation Orientation.areaForm_comp_rightAngleRotation @[simp] theorem rightAngleRotation_trans_rightAngleRotation : LinearIsometryEquiv.trans J J = LinearIsometryEquiv.neg ℝ := by ext; simp #align orientation.right_angle_rotation_trans_right_angle_rotation Orientation.rightAngleRotation_trans_rightAngleRotation theorem rightAngleRotation_neg_orientation (x : E) : (-o).rightAngleRotation x = -o.rightAngleRotation x := by apply ext_inner_right ℝ intro y rw [inner_rightAngleRotation_left] simp #align orientation.right_angle_rotation_neg_orientation Orientation.rightAngleRotation_neg_orientation @[simp] theorem rightAngleRotation_trans_neg_orientation : (-o).rightAngleRotation = o.rightAngleRotation.trans (LinearIsometryEquiv.neg ℝ) := LinearIsometryEquiv.ext <| o.rightAngleRotation_neg_orientation #align orientation.right_angle_rotation_trans_neg_orientation Orientation.rightAngleRotation_trans_neg_orientation theorem rightAngleRotation_map {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] [hF : Fact (finrank ℝ F = 2)] (φ : E ≃ₗᵢ[ℝ] F) (x : F) : (Orientation.map (Fin 2) φ.toLinearEquiv o).rightAngleRotation x = φ (o.rightAngleRotation (φ.symm x)) := by apply ext_inner_right ℝ intro y rw [inner_rightAngleRotation_left] trans ⟪J (φ.symm x), φ.symm y⟫ · simp [o.areaForm_map] trans ⟪φ (J (φ.symm x)), φ (φ.symm y)⟫ · rw [φ.inner_map_map] · simp #align orientation.right_angle_rotation_map Orientation.rightAngleRotation_map /-- `J` commutes with any positively-oriented isometric automorphism. -/ theorem linearIsometryEquiv_comp_rightAngleRotation (φ : E ≃ₗᵢ[ℝ] E) (hφ : 0 < LinearMap.det (φ.toLinearEquiv : E →ₗ[ℝ] E)) (x : E) : φ (J x) = J (φ x) := by convert (o.rightAngleRotation_map φ (φ x)).symm · simp · symm rwa [← o.map_eq_iff_det_pos φ.toLinearEquiv] at hφ rw [@Fact.out (finrank ℝ E = 2), Fintype.card_fin] #align orientation.linear_isometry_equiv_comp_right_angle_rotation Orientation.linearIsometryEquiv_comp_rightAngleRotation theorem rightAngleRotation_map' {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] [Fact (finrank ℝ F = 2)] (φ : E ≃ₗᵢ[ℝ] F) : (Orientation.map (Fin 2) φ.toLinearEquiv o).rightAngleRotation = (φ.symm.trans o.rightAngleRotation).trans φ := LinearIsometryEquiv.ext <| o.rightAngleRotation_map φ #align orientation.right_angle_rotation_map' Orientation.rightAngleRotation_map' /-- `J` commutes with any positively-oriented isometric automorphism. -/ theorem linearIsometryEquiv_comp_rightAngleRotation' (φ : E ≃ₗᵢ[ℝ] E) (hφ : 0 < LinearMap.det (φ.toLinearEquiv : E →ₗ[ℝ] E)) : LinearIsometryEquiv.trans J φ = φ.trans J := LinearIsometryEquiv.ext <| o.linearIsometryEquiv_comp_rightAngleRotation φ hφ #align orientation.linear_isometry_equiv_comp_right_angle_rotation' Orientation.linearIsometryEquiv_comp_rightAngleRotation' /-- For a nonzero vector `x` in an oriented two-dimensional real inner product space `E`, `![x, J x]` forms an (orthogonal) basis for `E`. -/ def basisRightAngleRotation (x : E) (hx : x ≠ 0) : Basis (Fin 2) ℝ E := @basisOfLinearIndependentOfCardEqFinrank ℝ _ _ _ _ _ _ _ ![x, J x] (linearIndependent_of_ne_zero_of_inner_eq_zero (fun i => by fin_cases i <;> simp [hx]) (by intro i j hij fin_cases i <;> fin_cases j <;> simp_all)) (@Fact.out (finrank ℝ E = 2)).symm #align orientation.basis_right_angle_rotation Orientation.basisRightAngleRotation @[simp] theorem coe_basisRightAngleRotation (x : E) (hx : x ≠ 0) : ⇑(o.basisRightAngleRotation x hx) = ![x, J x] := coe_basisOfLinearIndependentOfCardEqFinrank _ _ #align orientation.coe_basis_right_angle_rotation Orientation.coe_basisRightAngleRotation /-- For vectors `a x y : E`, the identity `⟪a, x⟫ * ⟪a, y⟫ + ω a x * ω a y = ‖a‖ ^ 2 * ⟪x, y⟫`. (See `Orientation.inner_mul_inner_add_areaForm_mul_areaForm` for the "applied" form.)-/ theorem inner_mul_inner_add_areaForm_mul_areaForm' (a x : E) : ⟪a, x⟫ • innerₛₗ ℝ a + ω a x • ω a = ‖a‖ ^ 2 • innerₛₗ ℝ x := by by_cases ha : a = 0 · simp [ha] apply (o.basisRightAngleRotation a ha).ext intro i fin_cases i · simp only [Fin.mk_zero, coe_basisRightAngleRotation, Matrix.cons_val_zero, LinearMap.add_apply, LinearMap.smul_apply, innerₛₗ_apply, real_inner_self_eq_norm_sq, smul_eq_mul, areaForm_apply_self, mul_zero, add_zero, Real.rpow_two, real_inner_comm] ring · simp only [Fin.mk_one, coe_basisRightAngleRotation, Matrix.cons_val_one, Matrix.head_cons, LinearMap.add_apply, LinearMap.smul_apply, innerₛₗ_apply, inner_rightAngleRotation_right, areaForm_apply_self, neg_zero, smul_eq_mul, mul_zero, areaForm_rightAngleRotation_right, real_inner_self_eq_norm_sq, zero_add, Real.rpow_two, mul_neg] rw [o.areaForm_swap] ring #align orientation.inner_mul_inner_add_area_form_mul_area_form' Orientation.inner_mul_inner_add_areaForm_mul_areaForm' /-- For vectors `a x y : E`, the identity `⟪a, x⟫ * ⟪a, y⟫ + ω a x * ω a y = ‖a‖ ^ 2 * ⟪x, y⟫`. -/ theorem inner_mul_inner_add_areaForm_mul_areaForm (a x y : E) : ⟪a, x⟫ * ⟪a, y⟫ + ω a x * ω a y = ‖a‖ ^ 2 * ⟪x, y⟫ := congr_arg (fun f : E →ₗ[ℝ] ℝ => f y) (o.inner_mul_inner_add_areaForm_mul_areaForm' a x) #align orientation.inner_mul_inner_add_area_form_mul_area_form Orientation.inner_mul_inner_add_areaForm_mul_areaForm theorem inner_sq_add_areaForm_sq (a b : E) : ⟪a, b⟫ ^ 2 + ω a b ^ 2 = ‖a‖ ^ 2 * ‖b‖ ^ 2 := by simpa [sq, real_inner_self_eq_norm_sq] using o.inner_mul_inner_add_areaForm_mul_areaForm a b b #align orientation.inner_sq_add_area_form_sq Orientation.inner_sq_add_areaForm_sq /-- For vectors `a x y : E`, the identity `⟪a, x⟫ * ω a y - ω a x * ⟪a, y⟫ = ‖a‖ ^ 2 * ω x y`. (See `Orientation.inner_mul_areaForm_sub` for the "applied" form.) -/ theorem inner_mul_areaForm_sub' (a x : E) : ⟪a, x⟫ • ω a - ω a x • innerₛₗ ℝ a = ‖a‖ ^ 2 • ω x := by by_cases ha : a = 0 · simp [ha] apply (o.basisRightAngleRotation a ha).ext intro i fin_cases i · simp only [o.areaForm_swap a x, neg_smul, sub_neg_eq_add, Fin.mk_zero, coe_basisRightAngleRotation, Matrix.cons_val_zero, LinearMap.add_apply, LinearMap.smul_apply, areaForm_apply_self, smul_eq_mul, mul_zero, innerₛₗ_apply, real_inner_self_eq_norm_sq, zero_add, Real.rpow_two] ring · simp only [Fin.mk_one, coe_basisRightAngleRotation, Matrix.cons_val_one, Matrix.head_cons, LinearMap.sub_apply, LinearMap.smul_apply, areaForm_rightAngleRotation_right, real_inner_self_eq_norm_sq, smul_eq_mul, innerₛₗ_apply, inner_rightAngleRotation_right, areaForm_apply_self, neg_zero, mul_zero, sub_zero, Real.rpow_two, real_inner_comm] ring #align orientation.inner_mul_area_form_sub' Orientation.inner_mul_areaForm_sub' /-- For vectors `a x y : E`, the identity `⟪a, x⟫ * ω a y - ω a x * ⟪a, y⟫ = ‖a‖ ^ 2 * ω x y`. -/ theorem inner_mul_areaForm_sub (a x y : E) : ⟪a, x⟫ * ω a y - ω a x * ⟪a, y⟫ = ‖a‖ ^ 2 * ω x y := congr_arg (fun f : E →ₗ[ℝ] ℝ => f y) (o.inner_mul_areaForm_sub' a x) #align orientation.inner_mul_area_form_sub Orientation.inner_mul_areaForm_sub theorem nonneg_inner_and_areaForm_eq_zero_iff_sameRay (x y : E) : 0 ≤ ⟪x, y⟫ ∧ ω x y = 0 ↔ SameRay ℝ x y := by by_cases hx : x = 0 · simp [hx] constructor · let a : ℝ := (o.basisRightAngleRotation x hx).repr y 0 let b : ℝ := (o.basisRightAngleRotation x hx).repr y 1 suffices ↑0 ≤ a * ‖x‖ ^ 2 ∧ b * ‖x‖ ^ 2 = 0 → SameRay ℝ x (a • x + b • J x) by rw [← (o.basisRightAngleRotation x hx).sum_repr y] simp only [Fin.sum_univ_succ, coe_basisRightAngleRotation, Matrix.cons_val_zero, Fin.succ_zero_eq_one', Finset.univ_eq_empty, Finset.sum_empty, areaForm_apply_self, map_smul, map_add, real_inner_smul_right, inner_add_right, Matrix.cons_val_one, Matrix.head_cons, Algebra.id.smul_eq_mul, areaForm_rightAngleRotation_right, mul_zero, add_zero, zero_add, neg_zero, inner_rightAngleRotation_right, real_inner_self_eq_norm_sq, zero_smul, one_smul] exact this rintro ⟨ha, hb⟩ have hx' : 0 < ‖x‖ := by simpa using hx have ha' : 0 ≤ a := nonneg_of_mul_nonneg_left ha (by positivity) have hb' : b = 0 := eq_zero_of_ne_zero_of_mul_right_eq_zero (pow_ne_zero 2 hx'.ne') hb exact (SameRay.sameRay_nonneg_smul_right x ha').add_right $ by simp [hb'] · intro h obtain ⟨r, hr, rfl⟩ := h.exists_nonneg_left hx simp only [inner_smul_right, real_inner_self_eq_norm_sq, LinearMap.map_smulₛₗ, areaForm_apply_self, Algebra.id.smul_eq_mul, mul_zero, eq_self_iff_true, and_true_iff] positivity #align orientation.nonneg_inner_and_area_form_eq_zero_iff_same_ray Orientation.nonneg_inner_and_areaForm_eq_zero_iff_sameRay /-- A complex-valued real-bilinear map on an oriented real inner product space of dimension 2. Its real part is the inner product and its imaginary part is `Orientation.areaForm`. On `ℂ` with the standard orientation, `kahler w z = conj w * z`; see `Complex.kahler`. -/ def kahler : E →ₗ[ℝ] E →ₗ[ℝ] ℂ := LinearMap.llcomp ℝ E ℝ ℂ Complex.ofRealCLM ∘ₗ innerₛₗ ℝ + LinearMap.llcomp ℝ E ℝ ℂ ((LinearMap.lsmul ℝ ℂ).flip Complex.I) ∘ₗ ω #align orientation.kahler Orientation.kahler theorem kahler_apply_apply (x y : E) : o.kahler x y = ⟪x, y⟫ + ω x y • Complex.I := rfl #align orientation.kahler_apply_apply Orientation.kahler_apply_apply theorem kahler_swap (x y : E) : o.kahler x y = conj (o.kahler y x) := by have : ∀ r : ℝ, Complex.ofReal' r = @RCLike.ofReal ℂ _ r := fun r => rfl simp only [kahler_apply_apply] rw [real_inner_comm, areaForm_swap] simp [this] #align orientation.kahler_swap Orientation.kahler_swap @[simp] theorem kahler_apply_self (x : E) : o.kahler x x = ‖x‖ ^ 2 := by simp [kahler_apply_apply, real_inner_self_eq_norm_sq] #align orientation.kahler_apply_self Orientation.kahler_apply_self @[simp] theorem kahler_rightAngleRotation_left (x y : E) : o.kahler (J x) y = -Complex.I * o.kahler x y := by simp only [o.areaForm_rightAngleRotation_left, o.inner_rightAngleRotation_left, o.kahler_apply_apply, Complex.ofReal_neg, Complex.real_smul] linear_combination ω x y * Complex.I_sq #align orientation.kahler_right_angle_rotation_left Orientation.kahler_rightAngleRotation_left @[simp] theorem kahler_rightAngleRotation_right (x y : E) : o.kahler x (J y) = Complex.I * o.kahler x y := by simp only [o.areaForm_rightAngleRotation_right, o.inner_rightAngleRotation_right, o.kahler_apply_apply, Complex.ofReal_neg, Complex.real_smul] linear_combination -ω x y * Complex.I_sq #align orientation.kahler_right_angle_rotation_right Orientation.kahler_rightAngleRotation_right -- @[simp] -- Porting note: simp normal form is `kahler_comp_rightAngleRotation'` theorem kahler_comp_rightAngleRotation (x y : E) : o.kahler (J x) (J y) = o.kahler x y := by simp only [kahler_rightAngleRotation_left, kahler_rightAngleRotation_right] linear_combination -o.kahler x y * Complex.I_sq #align orientation.kahler_comp_right_angle_rotation Orientation.kahler_comp_rightAngleRotation theorem kahler_comp_rightAngleRotation' (x y : E) : -(Complex.I * (Complex.I * o.kahler x y)) = o.kahler x y := by linear_combination -o.kahler x y * Complex.I_sq @[simp] theorem kahler_neg_orientation (x y : E) : (-o).kahler x y = conj (o.kahler x y) := by have : ∀ r : ℝ, Complex.ofReal' r = @RCLike.ofReal ℂ _ r := fun r => rfl simp [kahler_apply_apply, this] #align orientation.kahler_neg_orientation Orientation.kahler_neg_orientation theorem kahler_mul (a x y : E) : o.kahler x a * o.kahler a y = ‖a‖ ^ 2 * o.kahler x y := by trans ((‖a‖ ^ 2 :) : ℂ) * o.kahler x y · apply Complex.ext · simp only [o.kahler_apply_apply, Complex.add_im, Complex.add_re, Complex.I_im, Complex.I_re, Complex.mul_im, Complex.mul_re, Complex.ofReal_im, Complex.ofReal_re, Complex.real_smul] rw [real_inner_comm a x, o.areaForm_swap x a] linear_combination o.inner_mul_inner_add_areaForm_mul_areaForm a x y · simp only [o.kahler_apply_apply, Complex.add_im, Complex.add_re, Complex.I_im, Complex.I_re, Complex.mul_im, Complex.mul_re, Complex.ofReal_im, Complex.ofReal_re, Complex.real_smul] rw [real_inner_comm a x, o.areaForm_swap x a] linear_combination o.inner_mul_areaForm_sub a x y · norm_cast #align orientation.kahler_mul Orientation.kahler_mul theorem normSq_kahler (x y : E) : Complex.normSq (o.kahler x y) = ‖x‖ ^ 2 * ‖y‖ ^ 2 := by simpa [kahler_apply_apply, Complex.normSq, sq] using o.inner_sq_add_areaForm_sq x y #align orientation.norm_sq_kahler Orientation.normSq_kahler theorem abs_kahler (x y : E) : Complex.abs (o.kahler x y) = ‖x‖ * ‖y‖ := by rw [← sq_eq_sq, Complex.sq_abs] · linear_combination o.normSq_kahler x y · positivity · positivity #align orientation.abs_kahler Orientation.abs_kahler theorem norm_kahler (x y : E) : ‖o.kahler x y‖ = ‖x‖ * ‖y‖ := by simpa using o.abs_kahler x y #align orientation.norm_kahler Orientation.norm_kahler
Mathlib/Analysis/InnerProductSpace/TwoDim.lean
559
565
theorem eq_zero_or_eq_zero_of_kahler_eq_zero {x y : E} (hx : o.kahler x y = 0) : x = 0 ∨ y = 0 := by
have : ‖x‖ * ‖y‖ = 0 := by simpa [hx] using (o.norm_kahler x y).symm cases' eq_zero_or_eq_zero_of_mul_eq_zero this with h h · left simpa using h · right simpa using h
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, Scott Morrison -/ import Mathlib.CategoryTheory.Subobject.Lattice #align_import category_theory.subobject.limits from "leanprover-community/mathlib"@"956af7c76589f444f2e1313911bad16366ea476d" /-! # Specific subobjects We define `equalizerSubobject`, `kernelSubobject` and `imageSubobject`, which are the subobjects represented by the equalizer, kernel and image of (a pair of) morphism(s) and provide conditions for `P.factors f`, where `P` is one of these special subobjects. TODO: Add conditions for when `P` is a pullback subobject. TODO: an iff characterisation of `(imageSubobject f).Factors h` -/ universe v u noncomputable section open CategoryTheory CategoryTheory.Category CategoryTheory.Limits CategoryTheory.Subobject Opposite variable {C : Type u} [Category.{v} C] {X Y Z : C} namespace CategoryTheory namespace Limits section Equalizer variable (f g : X ⟶ Y) [HasEqualizer f g] /-- The equalizer of morphisms `f g : X ⟶ Y` as a `Subobject X`. -/ abbrev equalizerSubobject : Subobject X := Subobject.mk (equalizer.ι f g) #align category_theory.limits.equalizer_subobject CategoryTheory.Limits.equalizerSubobject /-- The underlying object of `equalizerSubobject f g` is (up to isomorphism!) the same as the chosen object `equalizer f g`. -/ def equalizerSubobjectIso : (equalizerSubobject f g : C) ≅ equalizer f g := Subobject.underlyingIso (equalizer.ι f g) #align category_theory.limits.equalizer_subobject_iso CategoryTheory.Limits.equalizerSubobjectIso @[reassoc (attr := simp)] theorem equalizerSubobject_arrow : (equalizerSubobjectIso f g).hom ≫ equalizer.ι f g = (equalizerSubobject f g).arrow := by simp [equalizerSubobjectIso] #align category_theory.limits.equalizer_subobject_arrow CategoryTheory.Limits.equalizerSubobject_arrow @[reassoc (attr := simp)] theorem equalizerSubobject_arrow' : (equalizerSubobjectIso f g).inv ≫ (equalizerSubobject f g).arrow = equalizer.ι f g := by simp [equalizerSubobjectIso] #align category_theory.limits.equalizer_subobject_arrow' CategoryTheory.Limits.equalizerSubobject_arrow' @[reassoc] theorem equalizerSubobject_arrow_comp : (equalizerSubobject f g).arrow ≫ f = (equalizerSubobject f g).arrow ≫ g := by rw [← equalizerSubobject_arrow, Category.assoc, Category.assoc, equalizer.condition] #align category_theory.limits.equalizer_subobject_arrow_comp CategoryTheory.Limits.equalizerSubobject_arrow_comp theorem equalizerSubobject_factors {W : C} (h : W ⟶ X) (w : h ≫ f = h ≫ g) : (equalizerSubobject f g).Factors h := ⟨equalizer.lift h w, by simp⟩ #align category_theory.limits.equalizer_subobject_factors CategoryTheory.Limits.equalizerSubobject_factors theorem equalizerSubobject_factors_iff {W : C} (h : W ⟶ X) : (equalizerSubobject f g).Factors h ↔ h ≫ f = h ≫ g := ⟨fun w => by rw [← Subobject.factorThru_arrow _ _ w, Category.assoc, equalizerSubobject_arrow_comp, Category.assoc], equalizerSubobject_factors f g h⟩ #align category_theory.limits.equalizer_subobject_factors_iff CategoryTheory.Limits.equalizerSubobject_factors_iff end Equalizer section Kernel variable [HasZeroMorphisms C] (f : X ⟶ Y) [HasKernel f] /-- The kernel of a morphism `f : X ⟶ Y` as a `Subobject X`. -/ abbrev kernelSubobject : Subobject X := Subobject.mk (kernel.ι f) #align category_theory.limits.kernel_subobject CategoryTheory.Limits.kernelSubobject /-- The underlying object of `kernelSubobject f` is (up to isomorphism!) the same as the chosen object `kernel f`. -/ def kernelSubobjectIso : (kernelSubobject f : C) ≅ kernel f := Subobject.underlyingIso (kernel.ι f) #align category_theory.limits.kernel_subobject_iso CategoryTheory.Limits.kernelSubobjectIso @[reassoc (attr := simp), elementwise (attr := simp)] theorem kernelSubobject_arrow : (kernelSubobjectIso f).hom ≫ kernel.ι f = (kernelSubobject f).arrow := by simp [kernelSubobjectIso] #align category_theory.limits.kernel_subobject_arrow CategoryTheory.Limits.kernelSubobject_arrow @[reassoc (attr := simp), elementwise (attr := simp)] theorem kernelSubobject_arrow' : (kernelSubobjectIso f).inv ≫ (kernelSubobject f).arrow = kernel.ι f := by simp [kernelSubobjectIso] #align category_theory.limits.kernel_subobject_arrow' CategoryTheory.Limits.kernelSubobject_arrow' @[reassoc (attr := simp), elementwise (attr := simp)] theorem kernelSubobject_arrow_comp : (kernelSubobject f).arrow ≫ f = 0 := by rw [← kernelSubobject_arrow] simp only [Category.assoc, kernel.condition, comp_zero] #align category_theory.limits.kernel_subobject_arrow_comp CategoryTheory.Limits.kernelSubobject_arrow_comp theorem kernelSubobject_factors {W : C} (h : W ⟶ X) (w : h ≫ f = 0) : (kernelSubobject f).Factors h := ⟨kernel.lift _ h w, by simp⟩ #align category_theory.limits.kernel_subobject_factors CategoryTheory.Limits.kernelSubobject_factors theorem kernelSubobject_factors_iff {W : C} (h : W ⟶ X) : (kernelSubobject f).Factors h ↔ h ≫ f = 0 := ⟨fun w => by rw [← Subobject.factorThru_arrow _ _ w, Category.assoc, kernelSubobject_arrow_comp, comp_zero], kernelSubobject_factors f h⟩ #align category_theory.limits.kernel_subobject_factors_iff CategoryTheory.Limits.kernelSubobject_factors_iff /-- A factorisation of `h : W ⟶ X` through `kernelSubobject f`, assuming `h ≫ f = 0`. -/ def factorThruKernelSubobject {W : C} (h : W ⟶ X) (w : h ≫ f = 0) : W ⟶ kernelSubobject f := (kernelSubobject f).factorThru h (kernelSubobject_factors f h w) #align category_theory.limits.factor_thru_kernel_subobject CategoryTheory.Limits.factorThruKernelSubobject @[simp] theorem factorThruKernelSubobject_comp_arrow {W : C} (h : W ⟶ X) (w : h ≫ f = 0) : factorThruKernelSubobject f h w ≫ (kernelSubobject f).arrow = h := by dsimp [factorThruKernelSubobject] simp #align category_theory.limits.factor_thru_kernel_subobject_comp_arrow CategoryTheory.Limits.factorThruKernelSubobject_comp_arrow @[simp] theorem factorThruKernelSubobject_comp_kernelSubobjectIso {W : C} (h : W ⟶ X) (w : h ≫ f = 0) : factorThruKernelSubobject f h w ≫ (kernelSubobjectIso f).hom = kernel.lift f h w := (cancel_mono (kernel.ι f)).1 <| by simp #align category_theory.limits.factor_thru_kernel_subobject_comp_kernel_subobject_iso CategoryTheory.Limits.factorThruKernelSubobject_comp_kernelSubobjectIso section variable {f} {X' Y' : C} {f' : X' ⟶ Y'} [HasKernel f'] /-- A commuting square induces a morphism between the kernel subobjects. -/ def kernelSubobjectMap (sq : Arrow.mk f ⟶ Arrow.mk f') : (kernelSubobject f : C) ⟶ (kernelSubobject f' : C) := Subobject.factorThru _ ((kernelSubobject f).arrow ≫ sq.left) (kernelSubobject_factors _ _ (by simp [sq.w])) #align category_theory.limits.kernel_subobject_map CategoryTheory.Limits.kernelSubobjectMap @[reassoc (attr := simp), elementwise (attr := simp)] theorem kernelSubobjectMap_arrow (sq : Arrow.mk f ⟶ Arrow.mk f') : kernelSubobjectMap sq ≫ (kernelSubobject f').arrow = (kernelSubobject f).arrow ≫ sq.left := by simp [kernelSubobjectMap] #align category_theory.limits.kernel_subobject_map_arrow CategoryTheory.Limits.kernelSubobjectMap_arrow @[simp] theorem kernelSubobjectMap_id : kernelSubobjectMap (𝟙 (Arrow.mk f)) = 𝟙 _ := by aesop_cat #align category_theory.limits.kernel_subobject_map_id CategoryTheory.Limits.kernelSubobjectMap_id @[simp] theorem kernelSubobjectMap_comp {X'' Y'' : C} {f'' : X'' ⟶ Y''} [HasKernel f''] (sq : Arrow.mk f ⟶ Arrow.mk f') (sq' : Arrow.mk f' ⟶ Arrow.mk f'') : kernelSubobjectMap (sq ≫ sq') = kernelSubobjectMap sq ≫ kernelSubobjectMap sq' := by aesop_cat #align category_theory.limits.kernel_subobject_map_comp CategoryTheory.Limits.kernelSubobjectMap_comp @[reassoc] theorem kernel_map_comp_kernelSubobjectIso_inv (sq : Arrow.mk f ⟶ Arrow.mk f') : kernel.map f f' sq.1 sq.2 sq.3.symm ≫ (kernelSubobjectIso _).inv = (kernelSubobjectIso _).inv ≫ kernelSubobjectMap sq := by aesop_cat #align category_theory.limits.kernel_map_comp_kernel_subobject_iso_inv CategoryTheory.Limits.kernel_map_comp_kernelSubobjectIso_inv @[reassoc] theorem kernelSubobjectIso_comp_kernel_map (sq : Arrow.mk f ⟶ Arrow.mk f') : (kernelSubobjectIso _).hom ≫ kernel.map f f' sq.1 sq.2 sq.3.symm = kernelSubobjectMap sq ≫ (kernelSubobjectIso _).hom := by simp [← Iso.comp_inv_eq, kernel_map_comp_kernelSubobjectIso_inv] #align category_theory.limits.kernel_subobject_iso_comp_kernel_map CategoryTheory.Limits.kernelSubobjectIso_comp_kernel_map end @[simp] theorem kernelSubobject_zero {A B : C} : kernelSubobject (0 : A ⟶ B) = ⊤ := (isIso_iff_mk_eq_top _).mp (by infer_instance) #align category_theory.limits.kernel_subobject_zero CategoryTheory.Limits.kernelSubobject_zero instance isIso_kernelSubobject_zero_arrow : IsIso (kernelSubobject (0 : X ⟶ Y)).arrow := (isIso_arrow_iff_eq_top _).mpr kernelSubobject_zero #align category_theory.limits.is_iso_kernel_subobject_zero_arrow CategoryTheory.Limits.isIso_kernelSubobject_zero_arrow theorem le_kernelSubobject (A : Subobject X) (h : A.arrow ≫ f = 0) : A ≤ kernelSubobject f := Subobject.le_mk_of_comm (kernel.lift f A.arrow h) (by simp) #align category_theory.limits.le_kernel_subobject CategoryTheory.Limits.le_kernelSubobject /-- The isomorphism between the kernel of `f ≫ g` and the kernel of `g`, when `f` is an isomorphism. -/ def kernelSubobjectIsoComp {X' : C} (f : X' ⟶ X) [IsIso f] (g : X ⟶ Y) [HasKernel g] : (kernelSubobject (f ≫ g) : C) ≅ (kernelSubobject g : C) := kernelSubobjectIso _ ≪≫ kernelIsIsoComp f g ≪≫ (kernelSubobjectIso _).symm #align category_theory.limits.kernel_subobject_iso_comp CategoryTheory.Limits.kernelSubobjectIsoComp @[simp] theorem kernelSubobjectIsoComp_hom_arrow {X' : C} (f : X' ⟶ X) [IsIso f] (g : X ⟶ Y) [HasKernel g] : (kernelSubobjectIsoComp f g).hom ≫ (kernelSubobject g).arrow = (kernelSubobject (f ≫ g)).arrow ≫ f := by simp [kernelSubobjectIsoComp] #align category_theory.limits.kernel_subobject_iso_comp_hom_arrow CategoryTheory.Limits.kernelSubobjectIsoComp_hom_arrow @[simp] theorem kernelSubobjectIsoComp_inv_arrow {X' : C} (f : X' ⟶ X) [IsIso f] (g : X ⟶ Y) [HasKernel g] : (kernelSubobjectIsoComp f g).inv ≫ (kernelSubobject (f ≫ g)).arrow = (kernelSubobject g).arrow ≫ inv f := by simp [kernelSubobjectIsoComp] #align category_theory.limits.kernel_subobject_iso_comp_inv_arrow CategoryTheory.Limits.kernelSubobjectIsoComp_inv_arrow /-- The kernel of `f` is always a smaller subobject than the kernel of `f ≫ h`. -/ theorem kernelSubobject_comp_le (f : X ⟶ Y) [HasKernel f] {Z : C} (h : Y ⟶ Z) [HasKernel (f ≫ h)] : kernelSubobject f ≤ kernelSubobject (f ≫ h) := le_kernelSubobject _ _ (by simp) #align category_theory.limits.kernel_subobject_comp_le CategoryTheory.Limits.kernelSubobject_comp_le /-- Postcomposing by a monomorphism does not change the kernel subobject. -/ @[simp] theorem kernelSubobject_comp_mono (f : X ⟶ Y) [HasKernel f] {Z : C} (h : Y ⟶ Z) [Mono h] : kernelSubobject (f ≫ h) = kernelSubobject f := le_antisymm (le_kernelSubobject _ _ ((cancel_mono h).mp (by simp))) (kernelSubobject_comp_le f h) #align category_theory.limits.kernel_subobject_comp_mono CategoryTheory.Limits.kernelSubobject_comp_mono instance kernelSubobject_comp_mono_isIso (f : X ⟶ Y) [HasKernel f] {Z : C} (h : Y ⟶ Z) [Mono h] : IsIso (Subobject.ofLE _ _ (kernelSubobject_comp_le f h)) := by rw [ofLE_mk_le_mk_of_comm (kernelCompMono f h).inv] · infer_instance · simp #align category_theory.limits.kernel_subobject_comp_mono_is_iso CategoryTheory.Limits.kernelSubobject_comp_mono_isIso /-- Taking cokernels is an order-reversing map from the subobjects of `X` to the quotient objects of `X`. -/ @[simps] def cokernelOrderHom [HasCokernels C] (X : C) : Subobject X →o (Subobject (op X))ᵒᵈ where toFun := Subobject.lift (fun A f _ => Subobject.mk (cokernel.π f).op) (by rintro A B f g hf hg i rfl refine Subobject.mk_eq_mk_of_comm _ _ (Iso.op ?_) (Quiver.Hom.unop_inj ?_) · exact (IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) (isCokernelEpiComp (colimit.isColimit _) i.hom rfl)).symm · simp only [Iso.comp_inv_eq, Iso.op_hom, Iso.symm_hom, unop_comp, Quiver.Hom.unop_op, colimit.comp_coconePointUniqueUpToIso_hom, Cofork.ofπ_ι_app, coequalizer.cofork_π]) monotone' := Subobject.ind₂ _ <| by intro A B f g hf hg h dsimp only [Subobject.lift_mk] refine Subobject.mk_le_mk_of_comm (cokernel.desc f (cokernel.π g) ?_).op ?_ · rw [← Subobject.ofMkLEMk_comp h, Category.assoc, cokernel.condition, comp_zero] · exact Quiver.Hom.unop_inj (cokernel.π_desc _ _ _) #align category_theory.limits.cokernel_order_hom CategoryTheory.Limits.cokernelOrderHom /-- Taking kernels is an order-reversing map from the quotient objects of `X` to the subobjects of `X`. -/ @[simps] def kernelOrderHom [HasKernels C] (X : C) : (Subobject (op X))ᵒᵈ →o Subobject X where toFun := Subobject.lift (fun A f _ => Subobject.mk (kernel.ι f.unop)) (by rintro A B f g hf hg i rfl refine Subobject.mk_eq_mk_of_comm _ _ ?_ ?_ · exact IsLimit.conePointUniqueUpToIso (limit.isLimit _) (isKernelCompMono (limit.isLimit (parallelPair g.unop 0)) i.unop.hom rfl) · dsimp simp only [← Iso.eq_inv_comp, limit.conePointUniqueUpToIso_inv_comp, Fork.ofι_π_app]) monotone' := Subobject.ind₂ _ <| by intro A B f g hf hg h dsimp only [Subobject.lift_mk] refine Subobject.mk_le_mk_of_comm (kernel.lift g.unop (kernel.ι f.unop) ?_) ?_ · rw [← Subobject.ofMkLEMk_comp h, unop_comp, kernel.condition_assoc, zero_comp] · exact Quiver.Hom.op_inj (by simp) #align category_theory.limits.kernel_order_hom CategoryTheory.Limits.kernelOrderHom end Kernel section Image variable (f : X ⟶ Y) [HasImage f] /-- The image of a morphism `f g : X ⟶ Y` as a `Subobject Y`. -/ abbrev imageSubobject : Subobject Y := Subobject.mk (image.ι f) #align category_theory.limits.image_subobject CategoryTheory.Limits.imageSubobject /-- The underlying object of `imageSubobject f` is (up to isomorphism!) the same as the chosen object `image f`. -/ def imageSubobjectIso : (imageSubobject f : C) ≅ image f := Subobject.underlyingIso (image.ι f) #align category_theory.limits.image_subobject_iso CategoryTheory.Limits.imageSubobjectIso @[reassoc (attr := simp)] theorem imageSubobject_arrow : (imageSubobjectIso f).hom ≫ image.ι f = (imageSubobject f).arrow := by simp [imageSubobjectIso] #align category_theory.limits.image_subobject_arrow CategoryTheory.Limits.imageSubobject_arrow @[reassoc (attr := simp)] theorem imageSubobject_arrow' : (imageSubobjectIso f).inv ≫ (imageSubobject f).arrow = image.ι f := by simp [imageSubobjectIso] #align category_theory.limits.image_subobject_arrow' CategoryTheory.Limits.imageSubobject_arrow' /-- A factorisation of `f : X ⟶ Y` through `imageSubobject f`. -/ def factorThruImageSubobject : X ⟶ imageSubobject f := factorThruImage f ≫ (imageSubobjectIso f).inv #align category_theory.limits.factor_thru_image_subobject CategoryTheory.Limits.factorThruImageSubobject instance [HasEqualizers C] : Epi (factorThruImageSubobject f) := by dsimp [factorThruImageSubobject] apply epi_comp @[reassoc (attr := simp), elementwise (attr := simp)] theorem imageSubobject_arrow_comp : factorThruImageSubobject f ≫ (imageSubobject f).arrow = f := by simp [factorThruImageSubobject, imageSubobject_arrow] #align category_theory.limits.image_subobject_arrow_comp CategoryTheory.Limits.imageSubobject_arrow_comp theorem imageSubobject_arrow_comp_eq_zero [HasZeroMorphisms C] {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} [HasImage f] [Epi (factorThruImageSubobject f)] (h : f ≫ g = 0) : (imageSubobject f).arrow ≫ g = 0 := zero_of_epi_comp (factorThruImageSubobject f) <| by simp [h] #align category_theory.limits.image_subobject_arrow_comp_eq_zero CategoryTheory.Limits.imageSubobject_arrow_comp_eq_zero theorem imageSubobject_factors_comp_self {W : C} (k : W ⟶ X) : (imageSubobject f).Factors (k ≫ f) := ⟨k ≫ factorThruImage f, by simp⟩ #align category_theory.limits.image_subobject_factors_comp_self CategoryTheory.Limits.imageSubobject_factors_comp_self @[simp] theorem factorThruImageSubobject_comp_self {W : C} (k : W ⟶ X) (h) : (imageSubobject f).factorThru (k ≫ f) h = k ≫ factorThruImageSubobject f := by ext simp #align category_theory.limits.factor_thru_image_subobject_comp_self CategoryTheory.Limits.factorThruImageSubobject_comp_self @[simp] theorem factorThruImageSubobject_comp_self_assoc {W W' : C} (k : W ⟶ W') (k' : W' ⟶ X) (h) : (imageSubobject f).factorThru (k ≫ k' ≫ f) h = k ≫ k' ≫ factorThruImageSubobject f := by ext simp #align category_theory.limits.factor_thru_image_subobject_comp_self_assoc CategoryTheory.Limits.factorThruImageSubobject_comp_self_assoc /-- The image of `h ≫ f` is always a smaller subobject than the image of `f`. -/ theorem imageSubobject_comp_le {X' : C} (h : X' ⟶ X) (f : X ⟶ Y) [HasImage f] [HasImage (h ≫ f)] : imageSubobject (h ≫ f) ≤ imageSubobject f := Subobject.mk_le_mk_of_comm (image.preComp h f) (by simp) #align category_theory.limits.image_subobject_comp_le CategoryTheory.Limits.imageSubobject_comp_le section open ZeroObject variable [HasZeroMorphisms C] [HasZeroObject C] @[simp] theorem imageSubobject_zero_arrow : (imageSubobject (0 : X ⟶ Y)).arrow = 0 := by rw [← imageSubobject_arrow] simp #align category_theory.limits.image_subobject_zero_arrow CategoryTheory.Limits.imageSubobject_zero_arrow @[simp] theorem imageSubobject_zero {A B : C} : imageSubobject (0 : A ⟶ B) = ⊥ := Subobject.eq_of_comm (imageSubobjectIso _ ≪≫ imageZero ≪≫ Subobject.botCoeIsoZero.symm) (by simp) #align category_theory.limits.image_subobject_zero CategoryTheory.Limits.imageSubobject_zero end section variable [HasEqualizers C] attribute [local instance] epi_comp /-- The morphism `imageSubobject (h ≫ f) ⟶ imageSubobject f` is an epimorphism when `h` is an epimorphism. In general this does not imply that `imageSubobject (h ≫ f) = imageSubobject f`, although it will when the ambient category is abelian. -/ instance imageSubobject_comp_le_epi_of_epi {X' : C} (h : X' ⟶ X) [Epi h] (f : X ⟶ Y) [HasImage f] [HasImage (h ≫ f)] : Epi (Subobject.ofLE _ _ (imageSubobject_comp_le h f)) := by rw [ofLE_mk_le_mk_of_comm (image.preComp h f)] · infer_instance · simp #align category_theory.limits.image_subobject_comp_le_epi_of_epi CategoryTheory.Limits.imageSubobject_comp_le_epi_of_epi end section variable [HasEqualizers C] /-- Postcomposing by an isomorphism gives an isomorphism between image subobjects. -/ def imageSubobjectCompIso (f : X ⟶ Y) [HasImage f] {Y' : C} (h : Y ⟶ Y') [IsIso h] : (imageSubobject (f ≫ h) : C) ≅ (imageSubobject f : C) := imageSubobjectIso _ ≪≫ (image.compIso _ _).symm ≪≫ (imageSubobjectIso _).symm #align category_theory.limits.image_subobject_comp_iso CategoryTheory.Limits.imageSubobjectCompIso @[reassoc (attr := simp)] theorem imageSubobjectCompIso_hom_arrow (f : X ⟶ Y) [HasImage f] {Y' : C} (h : Y ⟶ Y') [IsIso h] : (imageSubobjectCompIso f h).hom ≫ (imageSubobject f).arrow = (imageSubobject (f ≫ h)).arrow ≫ inv h := by simp [imageSubobjectCompIso] #align category_theory.limits.image_subobject_comp_iso_hom_arrow CategoryTheory.Limits.imageSubobjectCompIso_hom_arrow @[reassoc (attr := simp)]
Mathlib/CategoryTheory/Subobject/Limits.lean
419
422
theorem imageSubobjectCompIso_inv_arrow (f : X ⟶ Y) [HasImage f] {Y' : C} (h : Y ⟶ Y') [IsIso h] : (imageSubobjectCompIso f h).inv ≫ (imageSubobject (f ≫ h)).arrow = (imageSubobject f).arrow ≫ h := by
simp [imageSubobjectCompIso]
/- Copyright (c) 2020 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.Algebra.GCDMonoid.Finset import Mathlib.Algebra.Polynomial.CancelLeads import Mathlib.Algebra.Polynomial.EraseLead import Mathlib.Algebra.Polynomial.FieldDivision #align_import ring_theory.polynomial.content from "leanprover-community/mathlib"@"7a030ab8eb5d99f05a891dccc49c5b5b90c947d3" /-! # GCD structures on polynomials Definitions and basic results about polynomials over GCD domains, particularly their contents and primitive polynomials. ## Main Definitions Let `p : R[X]`. - `p.content` is the `gcd` of the coefficients of `p`. - `p.IsPrimitive` indicates that `p.content = 1`. ## Main Results - `Polynomial.content_mul`: If `p q : R[X]`, then `(p * q).content = p.content * q.content`. - `Polynomial.NormalizedGcdMonoid`: The polynomial ring of a GCD domain is itself a GCD domain. -/ namespace Polynomial open Polynomial section Primitive variable {R : Type*} [CommSemiring R] /-- A polynomial is primitive when the only constant polynomials dividing it are units -/ def IsPrimitive (p : R[X]) : Prop := ∀ r : R, C r ∣ p → IsUnit r #align polynomial.is_primitive Polynomial.IsPrimitive theorem isPrimitive_iff_isUnit_of_C_dvd {p : R[X]} : p.IsPrimitive ↔ ∀ r : R, C r ∣ p → IsUnit r := Iff.rfl set_option linter.uppercaseLean3 false in #align polynomial.is_primitive_iff_is_unit_of_C_dvd Polynomial.isPrimitive_iff_isUnit_of_C_dvd @[simp] theorem isPrimitive_one : IsPrimitive (1 : R[X]) := fun _ h => isUnit_C.mp (isUnit_of_dvd_one h) #align polynomial.is_primitive_one Polynomial.isPrimitive_one theorem Monic.isPrimitive {p : R[X]} (hp : p.Monic) : p.IsPrimitive := by rintro r ⟨q, h⟩ exact isUnit_of_mul_eq_one r (q.coeff p.natDegree) (by rwa [← coeff_C_mul, ← h]) #align polynomial.monic.is_primitive Polynomial.Monic.isPrimitive theorem IsPrimitive.ne_zero [Nontrivial R] {p : R[X]} (hp : p.IsPrimitive) : p ≠ 0 := by rintro rfl exact (hp 0 (dvd_zero (C 0))).ne_zero rfl #align polynomial.is_primitive.ne_zero Polynomial.IsPrimitive.ne_zero theorem isPrimitive_of_dvd {p q : R[X]} (hp : IsPrimitive p) (hq : q ∣ p) : IsPrimitive q := fun a ha => isPrimitive_iff_isUnit_of_C_dvd.mp hp a (dvd_trans ha hq) #align polynomial.is_primitive_of_dvd Polynomial.isPrimitive_of_dvd end Primitive variable {R : Type*} [CommRing R] [IsDomain R] section NormalizedGCDMonoid variable [NormalizedGCDMonoid R] /-- `p.content` is the `gcd` of the coefficients of `p`. -/ def content (p : R[X]) : R := p.support.gcd p.coeff #align polynomial.content Polynomial.content theorem content_dvd_coeff {p : R[X]} (n : ℕ) : p.content ∣ p.coeff n := by by_cases h : n ∈ p.support · apply Finset.gcd_dvd h rw [mem_support_iff, Classical.not_not] at h rw [h] apply dvd_zero #align polynomial.content_dvd_coeff Polynomial.content_dvd_coeff @[simp] theorem content_C {r : R} : (C r).content = normalize r := by rw [content] by_cases h0 : r = 0 · simp [h0] have h : (C r).support = {0} := support_monomial _ h0 simp [h] set_option linter.uppercaseLean3 false in #align polynomial.content_C Polynomial.content_C @[simp] theorem content_zero : content (0 : R[X]) = 0 := by rw [← C_0, content_C, normalize_zero] #align polynomial.content_zero Polynomial.content_zero @[simp] theorem content_one : content (1 : R[X]) = 1 := by rw [← C_1, content_C, normalize_one] #align polynomial.content_one Polynomial.content_one theorem content_X_mul {p : R[X]} : content (X * p) = content p := by rw [content, content, Finset.gcd_def, Finset.gcd_def] refine congr rfl ?_ have h : (X * p).support = p.support.map ⟨Nat.succ, Nat.succ_injective⟩ := by ext a simp only [exists_prop, Finset.mem_map, Function.Embedding.coeFn_mk, Ne, mem_support_iff] cases' a with a · simp [coeff_X_mul_zero, Nat.succ_ne_zero] rw [mul_comm, coeff_mul_X] constructor · intro h use a · rintro ⟨b, ⟨h1, h2⟩⟩ rw [← Nat.succ_injective h2] apply h1 rw [h] simp only [Finset.map_val, Function.comp_apply, Function.Embedding.coeFn_mk, Multiset.map_map] refine congr (congr rfl ?_) rfl ext a rw [mul_comm] simp [coeff_mul_X] set_option linter.uppercaseLean3 false in #align polynomial.content_X_mul Polynomial.content_X_mul @[simp] theorem content_X_pow {k : ℕ} : content ((X : R[X]) ^ k) = 1 := by induction' k with k hi · simp rw [pow_succ', content_X_mul, hi] set_option linter.uppercaseLean3 false in #align polynomial.content_X_pow Polynomial.content_X_pow @[simp] theorem content_X : content (X : R[X]) = 1 := by rw [← mul_one X, content_X_mul, content_one] set_option linter.uppercaseLean3 false in #align polynomial.content_X Polynomial.content_X theorem content_C_mul (r : R) (p : R[X]) : (C r * p).content = normalize r * p.content := by by_cases h0 : r = 0; · simp [h0] rw [content]; rw [content]; rw [← Finset.gcd_mul_left] refine congr (congr rfl ?_) ?_ <;> ext <;> simp [h0, mem_support_iff] set_option linter.uppercaseLean3 false in #align polynomial.content_C_mul Polynomial.content_C_mul @[simp] theorem content_monomial {r : R} {k : ℕ} : content (monomial k r) = normalize r := by rw [← C_mul_X_pow_eq_monomial, content_C_mul, content_X_pow, mul_one] #align polynomial.content_monomial Polynomial.content_monomial theorem content_eq_zero_iff {p : R[X]} : content p = 0 ↔ p = 0 := by rw [content, Finset.gcd_eq_zero_iff] constructor <;> intro h · ext n by_cases h0 : n ∈ p.support · rw [h n h0, coeff_zero] · rw [mem_support_iff] at h0 push_neg at h0 simp [h0] · intro x simp [h] #align polynomial.content_eq_zero_iff Polynomial.content_eq_zero_iff -- Porting note: this reduced with simp so created `normUnit_content` and put simp on it theorem normalize_content {p : R[X]} : normalize p.content = p.content := Finset.normalize_gcd #align polynomial.normalize_content Polynomial.normalize_content @[simp] theorem normUnit_content {p : R[X]} : normUnit (content p) = 1 := by by_cases hp0 : p.content = 0 · simp [hp0] · ext apply mul_left_cancel₀ hp0 erw [← normalize_apply, normalize_content, mul_one] theorem content_eq_gcd_range_of_lt (p : R[X]) (n : ℕ) (h : p.natDegree < n) : p.content = (Finset.range n).gcd p.coeff := by apply dvd_antisymm_of_normalize_eq normalize_content Finset.normalize_gcd · rw [Finset.dvd_gcd_iff] intro i _ apply content_dvd_coeff _ · apply Finset.gcd_mono intro i simp only [Nat.lt_succ_iff, mem_support_iff, Ne, Finset.mem_range] contrapose! intro h1 apply coeff_eq_zero_of_natDegree_lt (lt_of_lt_of_le h h1) #align polynomial.content_eq_gcd_range_of_lt Polynomial.content_eq_gcd_range_of_lt theorem content_eq_gcd_range_succ (p : R[X]) : p.content = (Finset.range p.natDegree.succ).gcd p.coeff := content_eq_gcd_range_of_lt _ _ (Nat.lt_succ_self _) #align polynomial.content_eq_gcd_range_succ Polynomial.content_eq_gcd_range_succ theorem content_eq_gcd_leadingCoeff_content_eraseLead (p : R[X]) : p.content = GCDMonoid.gcd p.leadingCoeff (eraseLead p).content := by by_cases h : p = 0 · simp [h] rw [← leadingCoeff_eq_zero, leadingCoeff, ← Ne, ← mem_support_iff] at h rw [content, ← Finset.insert_erase h, Finset.gcd_insert, leadingCoeff, content, eraseLead_support] refine congr rfl (Finset.gcd_congr rfl fun i hi => ?_) rw [Finset.mem_erase] at hi rw [eraseLead_coeff, if_neg hi.1] #align polynomial.content_eq_gcd_leading_coeff_content_erase_lead Polynomial.content_eq_gcd_leadingCoeff_content_eraseLead theorem dvd_content_iff_C_dvd {p : R[X]} {r : R} : r ∣ p.content ↔ C r ∣ p := by rw [C_dvd_iff_dvd_coeff] constructor · intro h i apply h.trans (content_dvd_coeff _) · intro h rw [content, Finset.dvd_gcd_iff] intro i _ apply h i set_option linter.uppercaseLean3 false in #align polynomial.dvd_content_iff_C_dvd Polynomial.dvd_content_iff_C_dvd theorem C_content_dvd (p : R[X]) : C p.content ∣ p := dvd_content_iff_C_dvd.1 dvd_rfl set_option linter.uppercaseLean3 false in #align polynomial.C_content_dvd Polynomial.C_content_dvd theorem isPrimitive_iff_content_eq_one {p : R[X]} : p.IsPrimitive ↔ p.content = 1 := by rw [← normalize_content, normalize_eq_one, IsPrimitive] simp_rw [← dvd_content_iff_C_dvd] exact ⟨fun h => h p.content (dvd_refl p.content), fun h r hdvd => isUnit_of_dvd_unit hdvd h⟩ #align polynomial.is_primitive_iff_content_eq_one Polynomial.isPrimitive_iff_content_eq_one theorem IsPrimitive.content_eq_one {p : R[X]} (hp : p.IsPrimitive) : p.content = 1 := isPrimitive_iff_content_eq_one.mp hp #align polynomial.is_primitive.content_eq_one Polynomial.IsPrimitive.content_eq_one section PrimPart /-- The primitive part of a polynomial `p` is the primitive polynomial gained by dividing `p` by `p.content`. If `p = 0`, then `p.primPart = 1`. -/ noncomputable def primPart (p : R[X]) : R[X] := letI := Classical.decEq R if p = 0 then 1 else Classical.choose (C_content_dvd p) #align polynomial.prim_part Polynomial.primPart theorem eq_C_content_mul_primPart (p : R[X]) : p = C p.content * p.primPart := by by_cases h : p = 0; · simp [h] rw [primPart, if_neg h, ← Classical.choose_spec (C_content_dvd p)] set_option linter.uppercaseLean3 false in #align polynomial.eq_C_content_mul_prim_part Polynomial.eq_C_content_mul_primPart @[simp] theorem primPart_zero : primPart (0 : R[X]) = 1 := if_pos rfl #align polynomial.prim_part_zero Polynomial.primPart_zero theorem isPrimitive_primPart (p : R[X]) : p.primPart.IsPrimitive := by by_cases h : p = 0; · simp [h] rw [← content_eq_zero_iff] at h rw [isPrimitive_iff_content_eq_one] apply mul_left_cancel₀ h conv_rhs => rw [p.eq_C_content_mul_primPart, mul_one, content_C_mul, normalize_content] #align polynomial.is_primitive_prim_part Polynomial.isPrimitive_primPart theorem content_primPart (p : R[X]) : p.primPart.content = 1 := p.isPrimitive_primPart.content_eq_one #align polynomial.content_prim_part Polynomial.content_primPart theorem primPart_ne_zero (p : R[X]) : p.primPart ≠ 0 := p.isPrimitive_primPart.ne_zero #align polynomial.prim_part_ne_zero Polynomial.primPart_ne_zero theorem natDegree_primPart (p : R[X]) : p.primPart.natDegree = p.natDegree := by by_cases h : C p.content = 0 · rw [C_eq_zero, content_eq_zero_iff] at h simp [h] conv_rhs => rw [p.eq_C_content_mul_primPart, natDegree_mul h p.primPart_ne_zero, natDegree_C, zero_add] #align polynomial.nat_degree_prim_part Polynomial.natDegree_primPart @[simp] theorem IsPrimitive.primPart_eq {p : R[X]} (hp : p.IsPrimitive) : p.primPart = p := by rw [← one_mul p.primPart, ← C_1, ← hp.content_eq_one, ← p.eq_C_content_mul_primPart] #align polynomial.is_primitive.prim_part_eq Polynomial.IsPrimitive.primPart_eq theorem isUnit_primPart_C (r : R) : IsUnit (C r).primPart := by by_cases h0 : r = 0 · simp [h0] unfold IsUnit refine ⟨⟨C ↑(normUnit r)⁻¹, C ↑(normUnit r), by rw [← RingHom.map_mul, Units.inv_mul, C_1], by rw [← RingHom.map_mul, Units.mul_inv, C_1]⟩, ?_⟩ rw [← normalize_eq_zero, ← C_eq_zero] at h0 apply mul_left_cancel₀ h0 conv_rhs => rw [← content_C, ← (C r).eq_C_content_mul_primPart] simp only [Units.val_mk, normalize_apply, RingHom.map_mul] rw [mul_assoc, ← RingHom.map_mul, Units.mul_inv, C_1, mul_one] set_option linter.uppercaseLean3 false in #align polynomial.is_unit_prim_part_C Polynomial.isUnit_primPart_C theorem primPart_dvd (p : R[X]) : p.primPart ∣ p := Dvd.intro_left (C p.content) p.eq_C_content_mul_primPart.symm #align polynomial.prim_part_dvd Polynomial.primPart_dvd theorem aeval_primPart_eq_zero {S : Type*} [Ring S] [IsDomain S] [Algebra R S] [NoZeroSMulDivisors R S] {p : R[X]} {s : S} (hpzero : p ≠ 0) (hp : aeval s p = 0) : aeval s p.primPart = 0 := by rw [eq_C_content_mul_primPart p, map_mul, aeval_C] at hp have hcont : p.content ≠ 0 := fun h => hpzero (content_eq_zero_iff.1 h) replace hcont := Function.Injective.ne (NoZeroSMulDivisors.algebraMap_injective R S) hcont rw [map_zero] at hcont exact eq_zero_of_ne_zero_of_mul_left_eq_zero hcont hp #align polynomial.aeval_prim_part_eq_zero Polynomial.aeval_primPart_eq_zero theorem eval₂_primPart_eq_zero {S : Type*} [CommRing S] [IsDomain S] {f : R →+* S} (hinj : Function.Injective f) {p : R[X]} {s : S} (hpzero : p ≠ 0) (hp : eval₂ f s p = 0) : eval₂ f s p.primPart = 0 := by rw [eq_C_content_mul_primPart p, eval₂_mul, eval₂_C] at hp have hcont : p.content ≠ 0 := fun h => hpzero (content_eq_zero_iff.1 h) replace hcont := Function.Injective.ne hinj hcont rw [map_zero] at hcont exact eq_zero_of_ne_zero_of_mul_left_eq_zero hcont hp #align polynomial.eval₂_prim_part_eq_zero Polynomial.eval₂_primPart_eq_zero end PrimPart theorem gcd_content_eq_of_dvd_sub {a : R} {p q : R[X]} (h : C a ∣ p - q) : GCDMonoid.gcd a p.content = GCDMonoid.gcd a q.content := by rw [content_eq_gcd_range_of_lt p (max p.natDegree q.natDegree).succ (lt_of_le_of_lt (le_max_left _ _) (Nat.lt_succ_self _))] rw [content_eq_gcd_range_of_lt q (max p.natDegree q.natDegree).succ (lt_of_le_of_lt (le_max_right _ _) (Nat.lt_succ_self _))] apply Finset.gcd_eq_of_dvd_sub intro x _ cases' h with w hw use w.coeff x rw [← coeff_sub, hw, coeff_C_mul] #align polynomial.gcd_content_eq_of_dvd_sub Polynomial.gcd_content_eq_of_dvd_sub theorem content_mul_aux {p q : R[X]} : GCDMonoid.gcd (p * q).eraseLead.content p.leadingCoeff = GCDMonoid.gcd (p.eraseLead * q).content p.leadingCoeff := by rw [gcd_comm (content _) _, gcd_comm (content _) _] apply gcd_content_eq_of_dvd_sub rw [← self_sub_C_mul_X_pow, ← self_sub_C_mul_X_pow, sub_mul, sub_sub, add_comm, sub_add, sub_sub_cancel, leadingCoeff_mul, RingHom.map_mul, mul_assoc, mul_assoc] apply dvd_sub (Dvd.intro _ rfl) (Dvd.intro _ rfl) #align polynomial.content_mul_aux Polynomial.content_mul_aux @[simp] theorem content_mul {p q : R[X]} : (p * q).content = p.content * q.content := by classical suffices h : ∀ (n : ℕ) (p q : R[X]), (p * q).degree < n → (p * q).content = p.content * q.content by apply h apply lt_of_le_of_lt degree_le_natDegree (WithBot.coe_lt_coe.2 (Nat.lt_succ_self _)) intro n induction' n with n ih · intro p q hpq rw [Nat.cast_zero, Nat.WithBot.lt_zero_iff, degree_eq_bot, mul_eq_zero] at hpq rcases hpq with (rfl | rfl) <;> simp intro p q hpq by_cases p0 : p = 0 · simp [p0] by_cases q0 : q = 0 · simp [q0] rw [degree_eq_natDegree (mul_ne_zero p0 q0), Nat.cast_lt, Nat.lt_succ_iff_lt_or_eq, ← Nat.cast_lt (α := WithBot ℕ), ← degree_eq_natDegree (mul_ne_zero p0 q0), natDegree_mul p0 q0] at hpq rcases hpq with (hlt | heq) · apply ih _ _ hlt rw [← p.natDegree_primPart, ← q.natDegree_primPart, ← Nat.cast_inj (R := WithBot ℕ), Nat.cast_add, ← degree_eq_natDegree p.primPart_ne_zero, ← degree_eq_natDegree q.primPart_ne_zero] at heq rw [p.eq_C_content_mul_primPart, q.eq_C_content_mul_primPart] suffices h : (q.primPart * p.primPart).content = 1 by rw [mul_assoc, content_C_mul, content_C_mul, mul_comm p.primPart, mul_assoc, content_C_mul, content_C_mul, h, mul_one, content_primPart, content_primPart, mul_one, mul_one] rw [← normalize_content, normalize_eq_one, isUnit_iff_dvd_one, content_eq_gcd_leadingCoeff_content_eraseLead, leadingCoeff_mul, gcd_comm] apply (gcd_mul_dvd_mul_gcd _ _ _).trans rw [content_mul_aux, ih, content_primPart, mul_one, gcd_comm, ← content_eq_gcd_leadingCoeff_content_eraseLead, content_primPart, one_mul, mul_comm q.primPart, content_mul_aux, ih, content_primPart, mul_one, gcd_comm, ← content_eq_gcd_leadingCoeff_content_eraseLead, content_primPart] · rw [← heq, degree_mul, WithBot.add_lt_add_iff_right] · apply degree_erase_lt p.primPart_ne_zero · rw [Ne, degree_eq_bot] apply q.primPart_ne_zero · rw [mul_comm, ← heq, degree_mul, WithBot.add_lt_add_iff_left] · apply degree_erase_lt q.primPart_ne_zero · rw [Ne, degree_eq_bot] apply p.primPart_ne_zero #align polynomial.content_mul Polynomial.content_mul theorem IsPrimitive.mul {p q : R[X]} (hp : p.IsPrimitive) (hq : q.IsPrimitive) : (p * q).IsPrimitive := by rw [isPrimitive_iff_content_eq_one, content_mul, hp.content_eq_one, hq.content_eq_one, mul_one] #align polynomial.is_primitive.mul Polynomial.IsPrimitive.mul @[simp] theorem primPart_mul {p q : R[X]} (h0 : p * q ≠ 0) : (p * q).primPart = p.primPart * q.primPart := by rw [Ne, ← content_eq_zero_iff, ← C_eq_zero] at h0 apply mul_left_cancel₀ h0 conv_lhs => rw [← (p * q).eq_C_content_mul_primPart, p.eq_C_content_mul_primPart, q.eq_C_content_mul_primPart] rw [content_mul, RingHom.map_mul] ring #align polynomial.prim_part_mul Polynomial.primPart_mul theorem IsPrimitive.dvd_primPart_iff_dvd {p q : R[X]} (hp : p.IsPrimitive) (hq : q ≠ 0) : p ∣ q.primPart ↔ p ∣ q := by refine ⟨fun h => h.trans (Dvd.intro_left _ q.eq_C_content_mul_primPart.symm), fun h => ?_⟩ rcases h with ⟨r, rfl⟩ apply Dvd.intro _ rw [primPart_mul hq, hp.primPart_eq] #align polynomial.is_primitive.dvd_prim_part_iff_dvd Polynomial.IsPrimitive.dvd_primPart_iff_dvd theorem exists_primitive_lcm_of_isPrimitive {p q : R[X]} (hp : p.IsPrimitive) (hq : q.IsPrimitive) : ∃ r : R[X], r.IsPrimitive ∧ ∀ s : R[X], p ∣ s ∧ q ∣ s ↔ r ∣ s := by classical have h : ∃ (n : ℕ) (r : R[X]), r.natDegree = n ∧ r.IsPrimitive ∧ p ∣ r ∧ q ∣ r := ⟨(p * q).natDegree, p * q, rfl, hp.mul hq, dvd_mul_right _ _, dvd_mul_left _ _⟩ rcases Nat.find_spec h with ⟨r, rdeg, rprim, pr, qr⟩ refine ⟨r, rprim, fun s => ⟨?_, fun rs => ⟨pr.trans rs, qr.trans rs⟩⟩⟩ suffices hs : ∀ (n : ℕ) (s : R[X]), s.natDegree = n → p ∣ s ∧ q ∣ s → r ∣ s from hs s.natDegree s rfl clear s by_contra! con rcases Nat.find_spec con with ⟨s, sdeg, ⟨ps, qs⟩, rs⟩ have s0 : s ≠ 0 := by contrapose! rs simp [rs] have hs := Nat.find_min' h ⟨_, s.natDegree_primPart, s.isPrimitive_primPart, (hp.dvd_primPart_iff_dvd s0).2 ps, (hq.dvd_primPart_iff_dvd s0).2 qs⟩ rw [← rdeg] at hs by_cases sC : s.natDegree ≤ 0 · rw [eq_C_of_natDegree_le_zero (le_trans hs sC), isPrimitive_iff_content_eq_one, content_C, normalize_eq_one] at rprim rw [eq_C_of_natDegree_le_zero (le_trans hs sC), ← dvd_content_iff_C_dvd] at rs apply rs rprim.dvd have hcancel := natDegree_cancelLeads_lt_of_natDegree_le_natDegree hs (lt_of_not_ge sC) rw [sdeg] at hcancel apply Nat.find_min con hcancel refine ⟨_, rfl, ⟨dvd_cancelLeads_of_dvd_of_dvd pr ps, dvd_cancelLeads_of_dvd_of_dvd qr qs⟩, fun rcs => rs ?_⟩ rw [← rprim.dvd_primPart_iff_dvd s0] rw [cancelLeads, tsub_eq_zero_iff_le.mpr hs, pow_zero, mul_one] at rcs have h := dvd_add rcs (Dvd.intro_left (C (leadingCoeff s) * X ^ (natDegree s - natDegree r)) rfl) have hC0 := rprim.ne_zero rw [Ne, ← leadingCoeff_eq_zero, ← C_eq_zero] at hC0 rw [sub_add_cancel, ← rprim.dvd_primPart_iff_dvd (mul_ne_zero hC0 s0)] at h rcases isUnit_primPart_C r.leadingCoeff with ⟨u, hu⟩ apply h.trans (Associated.symm ⟨u, _⟩).dvd rw [primPart_mul (mul_ne_zero hC0 s0), hu, mul_comm] #align polynomial.exists_primitive_lcm_of_is_primitive Polynomial.exists_primitive_lcm_of_isPrimitive theorem dvd_iff_content_dvd_content_and_primPart_dvd_primPart {p q : R[X]} (hq : q ≠ 0) : p ∣ q ↔ p.content ∣ q.content ∧ p.primPart ∣ q.primPart := by constructor <;> intro h · rcases h with ⟨r, rfl⟩ rw [content_mul, p.isPrimitive_primPart.dvd_primPart_iff_dvd hq] exact ⟨Dvd.intro _ rfl, p.primPart_dvd.trans (Dvd.intro _ rfl)⟩ · rw [p.eq_C_content_mul_primPart, q.eq_C_content_mul_primPart] exact mul_dvd_mul (RingHom.map_dvd C h.1) h.2 #align polynomial.dvd_iff_content_dvd_content_and_prim_part_dvd_prim_part Polynomial.dvd_iff_content_dvd_content_and_primPart_dvd_primPart noncomputable instance (priority := 100) normalizedGcdMonoid : NormalizedGCDMonoid R[X] := letI := Classical.decEq R normalizedGCDMonoidOfExistsLCM fun p q => by rcases exists_primitive_lcm_of_isPrimitive p.isPrimitive_primPart q.isPrimitive_primPart with ⟨r, rprim, hr⟩ refine ⟨C (lcm p.content q.content) * r, fun s => ?_⟩ by_cases hs : s = 0 · simp [hs] by_cases hpq : C (lcm p.content q.content) = 0 · rw [C_eq_zero, lcm_eq_zero_iff, content_eq_zero_iff, content_eq_zero_iff] at hpq rcases hpq with (hpq | hpq) <;> simp [hpq, hs] iterate 3 rw [dvd_iff_content_dvd_content_and_primPart_dvd_primPart hs] rw [content_mul, rprim.content_eq_one, mul_one, content_C, normalize_lcm, lcm_dvd_iff, primPart_mul (mul_ne_zero hpq rprim.ne_zero), rprim.primPart_eq, (isUnit_primPart_C (lcm p.content q.content)).mul_left_dvd, ← hr s.primPart] tauto #align polynomial.normalized_gcd_monoid Polynomial.normalizedGcdMonoid theorem degree_gcd_le_left {p : R[X]} (hp : p ≠ 0) (q) : (gcd p q).degree ≤ p.degree := by have := natDegree_le_iff_degree_le.mp (natDegree_le_of_dvd (gcd_dvd_left p q) hp) rwa [degree_eq_natDegree hp] #align polynomial.degree_gcd_le_left Polynomial.degree_gcd_le_left
Mathlib/RingTheory/Polynomial/Content.lean
505
507
theorem degree_gcd_le_right (p) {q : R[X]} (hq : q ≠ 0) : (gcd p q).degree ≤ q.degree := by
rw [gcd_comm] exact degree_gcd_le_left hq p
/- Copyright (c) 2022 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.MeasureTheory.Constructions.BorelSpace.ContinuousLinearMap import Mathlib.MeasureTheory.Covering.BesicovitchVectorSpace import Mathlib.MeasureTheory.Measure.Lebesgue.EqHaar import Mathlib.Analysis.NormedSpace.Pointwise import Mathlib.MeasureTheory.Constructions.Polish import Mathlib.Analysis.Calculus.InverseFunctionTheorem.ApproximatesLinearOn #align_import measure_theory.function.jacobian from "leanprover-community/mathlib"@"b84aee748341da06a6d78491367e2c0e9f15e8a5" /-! # Change of variables in higher-dimensional integrals Let `μ` be a Lebesgue measure on a finite-dimensional real vector space `E`. Let `f : E → E` be a function which is injective and differentiable on a measurable set `s`, with derivative `f'`. Then we prove that `f '' s` is measurable, and its measure is given by the formula `μ (f '' s) = ∫⁻ x in s, |(f' x).det| ∂μ` (where `(f' x).det` is almost everywhere measurable, but not Borel-measurable in general). This formula is proved in `lintegral_abs_det_fderiv_eq_addHaar_image`. We deduce the change of variables formula for the Lebesgue and Bochner integrals, in `lintegral_image_eq_lintegral_abs_det_fderiv_mul` and `integral_image_eq_integral_abs_det_fderiv_smul` respectively. ## Main results * `addHaar_image_eq_zero_of_differentiableOn_of_addHaar_eq_zero`: if `f` is differentiable on a set `s` with zero measure, then `f '' s` also has zero measure. * `addHaar_image_eq_zero_of_det_fderivWithin_eq_zero`: if `f` is differentiable on a set `s`, and its derivative is never invertible, then `f '' s` has zero measure (a version of Sard's lemma). * `aemeasurable_fderivWithin`: if `f` is differentiable on a measurable set `s`, then `f'` is almost everywhere measurable on `s`. For the next statements, `s` is a measurable set and `f` is differentiable on `s` (with a derivative `f'`) and injective on `s`. * `measurable_image_of_fderivWithin`: the image `f '' s` is measurable. * `measurableEmbedding_of_fderivWithin`: the function `s.restrict f` is a measurable embedding. * `lintegral_abs_det_fderiv_eq_addHaar_image`: the image measure is given by `μ (f '' s) = ∫⁻ x in s, |(f' x).det| ∂μ`. * `lintegral_image_eq_lintegral_abs_det_fderiv_mul`: for `g : E → ℝ≥0∞`, one has `∫⁻ x in f '' s, g x ∂μ = ∫⁻ x in s, ENNReal.ofReal |(f' x).det| * g (f x) ∂μ`. * `integral_image_eq_integral_abs_det_fderiv_smul`: for `g : E → F`, one has `∫ x in f '' s, g x ∂μ = ∫ x in s, |(f' x).det| • g (f x) ∂μ`. * `integrableOn_image_iff_integrableOn_abs_det_fderiv_smul`: for `g : E → F`, the function `g` is integrable on `f '' s` if and only if `|(f' x).det| • g (f x))` is integrable on `s`. ## Implementation Typical versions of these results in the literature have much stronger assumptions: `s` would typically be open, and the derivative `f' x` would depend continuously on `x` and be invertible everywhere, to have the local inverse theorem at our disposal. The proof strategy under our weaker assumptions is more involved. We follow [Fremlin, *Measure Theory* (volume 2)][fremlin_vol2]. The first remark is that, if `f` is sufficiently well approximated by a linear map `A` on a set `s`, then `f` expands the volume of `s` by at least `A.det - ε` and at most `A.det + ε`, where the closeness condition depends on `A` in a non-explicit way (see `addHaar_image_le_mul_of_det_lt` and `mul_le_addHaar_image_of_lt_det`). This fact holds for balls by a simple inclusion argument, and follows for general sets using the Besicovitch covering theorem to cover the set by balls with measures adding up essentially to `μ s`. When `f` is differentiable on `s`, one may partition `s` into countably many subsets `s ∩ t n` (where `t n` is measurable), on each of which `f` is well approximated by a linear map, so that the above results apply. See `exists_partition_approximatesLinearOn_of_hasFDerivWithinAt`, which follows from the pointwise differentiability (in a non-completely trivial way, as one should ensure a form of uniformity on the sets of the partition). Combining the above two results would give the conclusion, except for two difficulties: it is not obvious why `f '' s` and `f'` should be measurable, which prevents us from using countable additivity for the measure and the integral. It turns out that `f '' s` is indeed measurable, and that `f'` is almost everywhere measurable, which is enough to recover countable additivity. The measurability of `f '' s` follows from the deep Lusin-Souslin theorem ensuring that, in a Polish space, a continuous injective image of a measurable set is measurable. The key point to check the almost everywhere measurability of `f'` is that, if `f` is approximated up to `δ` by a linear map on a set `s`, then `f'` is within `δ` of `A` on a full measure subset of `s` (namely, its density points). With the above approximation argument, it follows that `f'` is the almost everywhere limit of a sequence of measurable functions (which are constant on the pieces of the good discretization), and is therefore almost everywhere measurable. ## Tags Change of variables in integrals ## References [Fremlin, *Measure Theory* (volume 2)][fremlin_vol2] -/ open MeasureTheory MeasureTheory.Measure Metric Filter Set FiniteDimensional Asymptotics TopologicalSpace open scoped NNReal ENNReal Topology Pointwise variable {E F : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] {s : Set E} {f : E → E} {f' : E → E →L[ℝ] E} /-! ### Decomposition lemmas We state lemmas ensuring that a differentiable function can be approximated, on countably many measurable pieces, by linear maps (with a prescribed precision depending on the linear map). -/ /-- Assume that a function `f` has a derivative at every point of a set `s`. Then one may cover `s` with countably many closed sets `t n` on which `f` is well approximated by linear maps `A n`. -/ theorem exists_closed_cover_approximatesLinearOn_of_hasFDerivWithinAt [SecondCountableTopology F] (f : E → F) (s : Set E) (f' : E → E →L[ℝ] F) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (r : (E →L[ℝ] F) → ℝ≥0) (rpos : ∀ A, r A ≠ 0) : ∃ (t : ℕ → Set E) (A : ℕ → E →L[ℝ] F), (∀ n, IsClosed (t n)) ∧ (s ⊆ ⋃ n, t n) ∧ (∀ n, ApproximatesLinearOn f (A n) (s ∩ t n) (r (A n))) ∧ (s.Nonempty → ∀ n, ∃ y ∈ s, A n = f' y) := by /- Choose countably many linear maps `f' z`. For every such map, if `f` has a derivative at `x` close enough to `f' z`, then `f y - f x` is well approximated by `f' z (y - x)` for `y` close enough to `x`, say on a ball of radius `r` (or even `u n` for some `n`, where `u` is a fixed sequence tending to `0`). Let `M n z` be the points where this happens. Then this set is relatively closed inside `s`, and moreover in every closed ball of radius `u n / 3` inside it the map is well approximated by `f' z`. Using countably many closed balls to split `M n z` into small diameter subsets `K n z p`, one obtains the desired sets `t q` after reindexing. -/ -- exclude the trivial case where `s` is empty rcases eq_empty_or_nonempty s with (rfl | hs) · refine ⟨fun _ => ∅, fun _ => 0, ?_, ?_, ?_, ?_⟩ <;> simp -- we will use countably many linear maps. Select these from all the derivatives since the -- space of linear maps is second-countable obtain ⟨T, T_count, hT⟩ : ∃ T : Set s, T.Countable ∧ ⋃ x ∈ T, ball (f' (x : E)) (r (f' x)) = ⋃ x : s, ball (f' x) (r (f' x)) := TopologicalSpace.isOpen_iUnion_countable _ fun x => isOpen_ball -- fix a sequence `u` of positive reals tending to zero. obtain ⟨u, _, u_pos, u_lim⟩ : ∃ u : ℕ → ℝ, StrictAnti u ∧ (∀ n : ℕ, 0 < u n) ∧ Tendsto u atTop (𝓝 0) := exists_seq_strictAnti_tendsto (0 : ℝ) -- `M n z` is the set of points `x` such that `f y - f x` is close to `f' z (y - x)` for `y` -- in the ball of radius `u n` around `x`. let M : ℕ → T → Set E := fun n z => {x | x ∈ s ∧ ∀ y ∈ s ∩ ball x (u n), ‖f y - f x - f' z (y - x)‖ ≤ r (f' z) * ‖y - x‖} -- As `f` is differentiable everywhere on `s`, the sets `M n z` cover `s` by design. have s_subset : ∀ x ∈ s, ∃ (n : ℕ) (z : T), x ∈ M n z := by intro x xs obtain ⟨z, zT, hz⟩ : ∃ z ∈ T, f' x ∈ ball (f' (z : E)) (r (f' z)) := by have : f' x ∈ ⋃ z ∈ T, ball (f' (z : E)) (r (f' z)) := by rw [hT] refine mem_iUnion.2 ⟨⟨x, xs⟩, ?_⟩ simpa only [mem_ball, Subtype.coe_mk, dist_self] using (rpos (f' x)).bot_lt rwa [mem_iUnion₂, bex_def] at this obtain ⟨ε, εpos, hε⟩ : ∃ ε : ℝ, 0 < ε ∧ ‖f' x - f' z‖ + ε ≤ r (f' z) := by refine ⟨r (f' z) - ‖f' x - f' z‖, ?_, le_of_eq (by abel)⟩ simpa only [sub_pos] using mem_ball_iff_norm.mp hz obtain ⟨δ, δpos, hδ⟩ : ∃ (δ : ℝ), 0 < δ ∧ ball x δ ∩ s ⊆ {y | ‖f y - f x - (f' x) (y - x)‖ ≤ ε * ‖y - x‖} := Metric.mem_nhdsWithin_iff.1 ((hf' x xs).isLittleO.def εpos) obtain ⟨n, hn⟩ : ∃ n, u n < δ := ((tendsto_order.1 u_lim).2 _ δpos).exists refine ⟨n, ⟨z, zT⟩, ⟨xs, ?_⟩⟩ intro y hy calc ‖f y - f x - (f' z) (y - x)‖ = ‖f y - f x - (f' x) (y - x) + (f' x - f' z) (y - x)‖ := by congr 1 simp only [ContinuousLinearMap.coe_sub', map_sub, Pi.sub_apply] abel _ ≤ ‖f y - f x - (f' x) (y - x)‖ + ‖(f' x - f' z) (y - x)‖ := norm_add_le _ _ _ ≤ ε * ‖y - x‖ + ‖f' x - f' z‖ * ‖y - x‖ := by refine add_le_add (hδ ?_) (ContinuousLinearMap.le_opNorm _ _) rw [inter_comm] exact inter_subset_inter_right _ (ball_subset_ball hn.le) hy _ ≤ r (f' z) * ‖y - x‖ := by rw [← add_mul, add_comm] gcongr -- the sets `M n z` are relatively closed in `s`, as all the conditions defining it are clearly -- closed have closure_M_subset : ∀ n z, s ∩ closure (M n z) ⊆ M n z := by rintro n z x ⟨xs, hx⟩ refine ⟨xs, fun y hy => ?_⟩ obtain ⟨a, aM, a_lim⟩ : ∃ a : ℕ → E, (∀ k, a k ∈ M n z) ∧ Tendsto a atTop (𝓝 x) := mem_closure_iff_seq_limit.1 hx have L1 : Tendsto (fun k : ℕ => ‖f y - f (a k) - (f' z) (y - a k)‖) atTop (𝓝 ‖f y - f x - (f' z) (y - x)‖) := by apply Tendsto.norm have L : Tendsto (fun k => f (a k)) atTop (𝓝 (f x)) := by apply (hf' x xs).continuousWithinAt.tendsto.comp apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ a_lim exact eventually_of_forall fun k => (aM k).1 apply Tendsto.sub (tendsto_const_nhds.sub L) exact ((f' z).continuous.tendsto _).comp (tendsto_const_nhds.sub a_lim) have L2 : Tendsto (fun k : ℕ => (r (f' z) : ℝ) * ‖y - a k‖) atTop (𝓝 (r (f' z) * ‖y - x‖)) := (tendsto_const_nhds.sub a_lim).norm.const_mul _ have I : ∀ᶠ k in atTop, ‖f y - f (a k) - (f' z) (y - a k)‖ ≤ r (f' z) * ‖y - a k‖ := by have L : Tendsto (fun k => dist y (a k)) atTop (𝓝 (dist y x)) := tendsto_const_nhds.dist a_lim filter_upwards [(tendsto_order.1 L).2 _ hy.2] intro k hk exact (aM k).2 y ⟨hy.1, hk⟩ exact le_of_tendsto_of_tendsto L1 L2 I -- choose a dense sequence `d p` rcases TopologicalSpace.exists_dense_seq E with ⟨d, hd⟩ -- split `M n z` into subsets `K n z p` of small diameters by intersecting with the ball -- `closedBall (d p) (u n / 3)`. let K : ℕ → T → ℕ → Set E := fun n z p => closure (M n z) ∩ closedBall (d p) (u n / 3) -- on the sets `K n z p`, the map `f` is well approximated by `f' z` by design. have K_approx : ∀ (n) (z : T) (p), ApproximatesLinearOn f (f' z) (s ∩ K n z p) (r (f' z)) := by intro n z p x hx y hy have yM : y ∈ M n z := closure_M_subset _ _ ⟨hy.1, hy.2.1⟩ refine yM.2 _ ⟨hx.1, ?_⟩ calc dist x y ≤ dist x (d p) + dist y (d p) := dist_triangle_right _ _ _ _ ≤ u n / 3 + u n / 3 := add_le_add hx.2.2 hy.2.2 _ < u n := by linarith [u_pos n] -- the sets `K n z p` are also closed, again by design. have K_closed : ∀ (n) (z : T) (p), IsClosed (K n z p) := fun n z p => isClosed_closure.inter isClosed_ball -- reindex the sets `K n z p`, to let them only depend on an integer parameter `q`. obtain ⟨F, hF⟩ : ∃ F : ℕ → ℕ × T × ℕ, Function.Surjective F := by haveI : Encodable T := T_count.toEncodable have : Nonempty T := by rcases hs with ⟨x, xs⟩ rcases s_subset x xs with ⟨n, z, _⟩ exact ⟨z⟩ inhabit ↥T exact ⟨_, Encodable.surjective_decode_iget (ℕ × T × ℕ)⟩ -- these sets `t q = K n z p` will do refine ⟨fun q => K (F q).1 (F q).2.1 (F q).2.2, fun q => f' (F q).2.1, fun n => K_closed _ _ _, fun x xs => ?_, fun q => K_approx _ _ _, fun _ q => ⟨(F q).2.1, (F q).2.1.1.2, rfl⟩⟩ -- the only fact that needs further checking is that they cover `s`. -- we already know that any point `x ∈ s` belongs to a set `M n z`. obtain ⟨n, z, hnz⟩ : ∃ (n : ℕ) (z : T), x ∈ M n z := s_subset x xs -- by density, it also belongs to a ball `closedBall (d p) (u n / 3)`. obtain ⟨p, hp⟩ : ∃ p : ℕ, x ∈ closedBall (d p) (u n / 3) := by have : Set.Nonempty (ball x (u n / 3)) := by simp only [nonempty_ball]; linarith [u_pos n] obtain ⟨p, hp⟩ : ∃ p : ℕ, d p ∈ ball x (u n / 3) := hd.exists_mem_open isOpen_ball this exact ⟨p, (mem_ball'.1 hp).le⟩ -- choose `q` for which `t q = K n z p`. obtain ⟨q, hq⟩ : ∃ q, F q = (n, z, p) := hF _ -- then `x` belongs to `t q`. apply mem_iUnion.2 ⟨q, _⟩ simp (config := { zeta := false }) only [K, hq, mem_inter_iff, hp, and_true] exact subset_closure hnz #align exists_closed_cover_approximates_linear_on_of_has_fderiv_within_at exists_closed_cover_approximatesLinearOn_of_hasFDerivWithinAt variable [MeasurableSpace E] [BorelSpace E] (μ : Measure E) [IsAddHaarMeasure μ] /-- Assume that a function `f` has a derivative at every point of a set `s`. Then one may partition `s` into countably many disjoint relatively measurable sets (i.e., intersections of `s` with measurable sets `t n`) on which `f` is well approximated by linear maps `A n`. -/ theorem exists_partition_approximatesLinearOn_of_hasFDerivWithinAt [SecondCountableTopology F] (f : E → F) (s : Set E) (f' : E → E →L[ℝ] F) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (r : (E →L[ℝ] F) → ℝ≥0) (rpos : ∀ A, r A ≠ 0) : ∃ (t : ℕ → Set E) (A : ℕ → E →L[ℝ] F), Pairwise (Disjoint on t) ∧ (∀ n, MeasurableSet (t n)) ∧ (s ⊆ ⋃ n, t n) ∧ (∀ n, ApproximatesLinearOn f (A n) (s ∩ t n) (r (A n))) ∧ (s.Nonempty → ∀ n, ∃ y ∈ s, A n = f' y) := by rcases exists_closed_cover_approximatesLinearOn_of_hasFDerivWithinAt f s f' hf' r rpos with ⟨t, A, t_closed, st, t_approx, ht⟩ refine ⟨disjointed t, A, disjoint_disjointed _, MeasurableSet.disjointed fun n => (t_closed n).measurableSet, ?_, ?_, ht⟩ · rw [iUnion_disjointed]; exact st · intro n; exact (t_approx n).mono_set (inter_subset_inter_right _ (disjointed_subset _ _)) #align exists_partition_approximates_linear_on_of_has_fderiv_within_at exists_partition_approximatesLinearOn_of_hasFDerivWithinAt namespace MeasureTheory /-! ### Local lemmas We check that a function which is well enough approximated by a linear map expands the volume essentially like this linear map, and that its derivative (if it exists) is almost everywhere close to the approximating linear map. -/ /-- Let `f` be a function which is sufficiently close (in the Lipschitz sense) to a given linear map `A`. Then it expands the volume of any set by at most `m` for any `m > det A`. -/ theorem addHaar_image_le_mul_of_det_lt (A : E →L[ℝ] E) {m : ℝ≥0} (hm : ENNReal.ofReal |A.det| < m) : ∀ᶠ δ in 𝓝[>] (0 : ℝ≥0), ∀ (s : Set E) (f : E → E), ApproximatesLinearOn f A s δ → μ (f '' s) ≤ m * μ s := by apply nhdsWithin_le_nhds let d := ENNReal.ofReal |A.det| -- construct a small neighborhood of `A '' (closedBall 0 1)` with measure comparable to -- the determinant of `A`. obtain ⟨ε, hε, εpos⟩ : ∃ ε : ℝ, μ (closedBall 0 ε + A '' closedBall 0 1) < m * μ (closedBall 0 1) ∧ 0 < ε := by have HC : IsCompact (A '' closedBall 0 1) := (ProperSpace.isCompact_closedBall _ _).image A.continuous have L0 : Tendsto (fun ε => μ (cthickening ε (A '' closedBall 0 1))) (𝓝[>] 0) (𝓝 (μ (A '' closedBall 0 1))) := by apply Tendsto.mono_left _ nhdsWithin_le_nhds exact tendsto_measure_cthickening_of_isCompact HC have L1 : Tendsto (fun ε => μ (closedBall 0 ε + A '' closedBall 0 1)) (𝓝[>] 0) (𝓝 (μ (A '' closedBall 0 1))) := by apply L0.congr' _ filter_upwards [self_mem_nhdsWithin] with r hr rw [← HC.add_closedBall_zero (le_of_lt hr), add_comm] have L2 : Tendsto (fun ε => μ (closedBall 0 ε + A '' closedBall 0 1)) (𝓝[>] 0) (𝓝 (d * μ (closedBall 0 1))) := by convert L1 exact (addHaar_image_continuousLinearMap _ _ _).symm have I : d * μ (closedBall 0 1) < m * μ (closedBall 0 1) := (ENNReal.mul_lt_mul_right (measure_closedBall_pos μ _ zero_lt_one).ne' measure_closedBall_lt_top.ne).2 hm have H : ∀ᶠ b : ℝ in 𝓝[>] 0, μ (closedBall 0 b + A '' closedBall 0 1) < m * μ (closedBall 0 1) := (tendsto_order.1 L2).2 _ I exact (H.and self_mem_nhdsWithin).exists have : Iio (⟨ε, εpos.le⟩ : ℝ≥0) ∈ 𝓝 (0 : ℝ≥0) := by apply Iio_mem_nhds; exact εpos filter_upwards [this] -- fix a function `f` which is close enough to `A`. intro δ hδ s f hf simp only [mem_Iio, ← NNReal.coe_lt_coe, NNReal.coe_mk] at hδ -- This function expands the volume of any ball by at most `m` have I : ∀ x r, x ∈ s → 0 ≤ r → μ (f '' (s ∩ closedBall x r)) ≤ m * μ (closedBall x r) := by intro x r xs r0 have K : f '' (s ∩ closedBall x r) ⊆ A '' closedBall 0 r + closedBall (f x) (ε * r) := by rintro y ⟨z, ⟨zs, zr⟩, rfl⟩ rw [mem_closedBall_iff_norm] at zr apply Set.mem_add.2 ⟨A (z - x), _, f z - f x - A (z - x) + f x, _, _⟩ · apply mem_image_of_mem simpa only [dist_eq_norm, mem_closedBall, mem_closedBall_zero_iff, sub_zero] using zr · rw [mem_closedBall_iff_norm, add_sub_cancel_right] calc ‖f z - f x - A (z - x)‖ ≤ δ * ‖z - x‖ := hf _ zs _ xs _ ≤ ε * r := by gcongr · simp only [map_sub, Pi.sub_apply] abel have : A '' closedBall 0 r + closedBall (f x) (ε * r) = {f x} + r • (A '' closedBall 0 1 + closedBall 0 ε) := by rw [smul_add, ← add_assoc, add_comm {f x}, add_assoc, smul_closedBall _ _ εpos.le, smul_zero, singleton_add_closedBall_zero, ← image_smul_set ℝ E E A, smul_closedBall _ _ zero_le_one, smul_zero, Real.norm_eq_abs, abs_of_nonneg r0, mul_one, mul_comm] rw [this] at K calc μ (f '' (s ∩ closedBall x r)) ≤ μ ({f x} + r • (A '' closedBall 0 1 + closedBall 0 ε)) := measure_mono K _ = ENNReal.ofReal (r ^ finrank ℝ E) * μ (A '' closedBall 0 1 + closedBall 0 ε) := by simp only [abs_of_nonneg r0, addHaar_smul, image_add_left, abs_pow, singleton_add, measure_preimage_add] _ ≤ ENNReal.ofReal (r ^ finrank ℝ E) * (m * μ (closedBall 0 1)) := by rw [add_comm]; gcongr _ = m * μ (closedBall x r) := by simp only [addHaar_closedBall' μ _ r0]; ring -- covering `s` by closed balls with total measure very close to `μ s`, one deduces that the -- measure of `f '' s` is at most `m * (μ s + a)` for any positive `a`. have J : ∀ᶠ a in 𝓝[>] (0 : ℝ≥0∞), μ (f '' s) ≤ m * (μ s + a) := by filter_upwards [self_mem_nhdsWithin] with a ha rw [mem_Ioi] at ha obtain ⟨t, r, t_count, ts, rpos, st, μt⟩ : ∃ (t : Set E) (r : E → ℝ), t.Countable ∧ t ⊆ s ∧ (∀ x : E, x ∈ t → 0 < r x) ∧ (s ⊆ ⋃ x ∈ t, closedBall x (r x)) ∧ (∑' x : ↥t, μ (closedBall (↑x) (r ↑x))) ≤ μ s + a := Besicovitch.exists_closedBall_covering_tsum_measure_le μ ha.ne' (fun _ => Ioi 0) s fun x _ δ δpos => ⟨δ / 2, by simp [half_pos δpos, δpos]⟩ haveI : Encodable t := t_count.toEncodable calc μ (f '' s) ≤ μ (⋃ x : t, f '' (s ∩ closedBall x (r x))) := by rw [biUnion_eq_iUnion] at st apply measure_mono rw [← image_iUnion, ← inter_iUnion] exact image_subset _ (subset_inter (Subset.refl _) st) _ ≤ ∑' x : t, μ (f '' (s ∩ closedBall x (r x))) := measure_iUnion_le _ _ ≤ ∑' x : t, m * μ (closedBall x (r x)) := (ENNReal.tsum_le_tsum fun x => I x (r x) (ts x.2) (rpos x x.2).le) _ ≤ m * (μ s + a) := by rw [ENNReal.tsum_mul_left]; gcongr -- taking the limit in `a`, one obtains the conclusion have L : Tendsto (fun a => (m : ℝ≥0∞) * (μ s + a)) (𝓝[>] 0) (𝓝 (m * (μ s + 0))) := by apply Tendsto.mono_left _ nhdsWithin_le_nhds apply ENNReal.Tendsto.const_mul (tendsto_const_nhds.add tendsto_id) simp only [ENNReal.coe_ne_top, Ne, or_true_iff, not_false_iff] rw [add_zero] at L exact ge_of_tendsto L J #align measure_theory.add_haar_image_le_mul_of_det_lt MeasureTheory.addHaar_image_le_mul_of_det_lt /-- Let `f` be a function which is sufficiently close (in the Lipschitz sense) to a given linear map `A`. Then it expands the volume of any set by at least `m` for any `m < det A`. -/ theorem mul_le_addHaar_image_of_lt_det (A : E →L[ℝ] E) {m : ℝ≥0} (hm : (m : ℝ≥0∞) < ENNReal.ofReal |A.det|) : ∀ᶠ δ in 𝓝[>] (0 : ℝ≥0), ∀ (s : Set E) (f : E → E), ApproximatesLinearOn f A s δ → (m : ℝ≥0∞) * μ s ≤ μ (f '' s) := by apply nhdsWithin_le_nhds -- The assumption `hm` implies that `A` is invertible. If `f` is close enough to `A`, it is also -- invertible. One can then pass to the inverses, and deduce the estimate from -- `addHaar_image_le_mul_of_det_lt` applied to `f⁻¹` and `A⁻¹`. -- exclude first the trivial case where `m = 0`. rcases eq_or_lt_of_le (zero_le m) with (rfl | mpos) · filter_upwards simp only [forall_const, zero_mul, imp_true_iff, zero_le, ENNReal.coe_zero] have hA : A.det ≠ 0 := by intro h; simp only [h, ENNReal.not_lt_zero, ENNReal.ofReal_zero, abs_zero] at hm -- let `B` be the continuous linear equiv version of `A`. let B := A.toContinuousLinearEquivOfDetNeZero hA -- the determinant of `B.symm` is bounded by `m⁻¹` have I : ENNReal.ofReal |(B.symm : E →L[ℝ] E).det| < (m⁻¹ : ℝ≥0) := by simp only [ENNReal.ofReal, abs_inv, Real.toNNReal_inv, ContinuousLinearEquiv.det_coe_symm, ContinuousLinearMap.coe_toContinuousLinearEquivOfDetNeZero, ENNReal.coe_lt_coe] at hm ⊢ exact NNReal.inv_lt_inv mpos.ne' hm -- therefore, we may apply `addHaar_image_le_mul_of_det_lt` to `B.symm` and `m⁻¹`. obtain ⟨δ₀, δ₀pos, hδ₀⟩ : ∃ δ : ℝ≥0, 0 < δ ∧ ∀ (t : Set E) (g : E → E), ApproximatesLinearOn g (B.symm : E →L[ℝ] E) t δ → μ (g '' t) ≤ ↑m⁻¹ * μ t := by have : ∀ᶠ δ : ℝ≥0 in 𝓝[>] 0, ∀ (t : Set E) (g : E → E), ApproximatesLinearOn g (B.symm : E →L[ℝ] E) t δ → μ (g '' t) ≤ ↑m⁻¹ * μ t := addHaar_image_le_mul_of_det_lt μ B.symm I rcases (this.and self_mem_nhdsWithin).exists with ⟨δ₀, h, h'⟩ exact ⟨δ₀, h', h⟩ -- record smallness conditions for `δ` that will be needed to apply `hδ₀` below. have L1 : ∀ᶠ δ in 𝓝 (0 : ℝ≥0), Subsingleton E ∨ δ < ‖(B.symm : E →L[ℝ] E)‖₊⁻¹ := by by_cases h : Subsingleton E · simp only [h, true_or_iff, eventually_const] simp only [h, false_or_iff] apply Iio_mem_nhds simpa only [h, false_or_iff, inv_pos] using B.subsingleton_or_nnnorm_symm_pos have L2 : ∀ᶠ δ in 𝓝 (0 : ℝ≥0), ‖(B.symm : E →L[ℝ] E)‖₊ * (‖(B.symm : E →L[ℝ] E)‖₊⁻¹ - δ)⁻¹ * δ < δ₀ := by have : Tendsto (fun δ => ‖(B.symm : E →L[ℝ] E)‖₊ * (‖(B.symm : E →L[ℝ] E)‖₊⁻¹ - δ)⁻¹ * δ) (𝓝 0) (𝓝 (‖(B.symm : E →L[ℝ] E)‖₊ * (‖(B.symm : E →L[ℝ] E)‖₊⁻¹ - 0)⁻¹ * 0)) := by rcases eq_or_ne ‖(B.symm : E →L[ℝ] E)‖₊ 0 with (H | H) · simpa only [H, zero_mul] using tendsto_const_nhds refine Tendsto.mul (tendsto_const_nhds.mul ?_) tendsto_id refine (Tendsto.sub tendsto_const_nhds tendsto_id).inv₀ ?_ simpa only [tsub_zero, inv_eq_zero, Ne] using H simp only [mul_zero] at this exact (tendsto_order.1 this).2 δ₀ δ₀pos -- let `δ` be small enough, and `f` approximated by `B` up to `δ`. filter_upwards [L1, L2] intro δ h1δ h2δ s f hf have hf' : ApproximatesLinearOn f (B : E →L[ℝ] E) s δ := by convert hf let F := hf'.toPartialEquiv h1δ -- the condition to be checked can be reformulated in terms of the inverse maps suffices H : μ (F.symm '' F.target) ≤ (m⁻¹ : ℝ≥0) * μ F.target by change (m : ℝ≥0∞) * μ F.source ≤ μ F.target rwa [← F.symm_image_target_eq_source, mul_comm, ← ENNReal.le_div_iff_mul_le, div_eq_mul_inv, mul_comm, ← ENNReal.coe_inv mpos.ne'] · apply Or.inl simpa only [ENNReal.coe_eq_zero, Ne] using mpos.ne' · simp only [ENNReal.coe_ne_top, true_or_iff, Ne, not_false_iff] -- as `f⁻¹` is well approximated by `B⁻¹`, the conclusion follows from `hδ₀` -- and our choice of `δ`. exact hδ₀ _ _ ((hf'.to_inv h1δ).mono_num h2δ.le) #align measure_theory.mul_le_add_haar_image_of_lt_det MeasureTheory.mul_le_addHaar_image_of_lt_det /-- If a differentiable function `f` is approximated by a linear map `A` on a set `s`, up to `δ`, then at almost every `x` in `s` one has `‖f' x - A‖ ≤ δ`. -/ theorem _root_.ApproximatesLinearOn.norm_fderiv_sub_le {A : E →L[ℝ] E} {δ : ℝ≥0} (hf : ApproximatesLinearOn f A s δ) (hs : MeasurableSet s) (f' : E → E →L[ℝ] E) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) : ∀ᵐ x ∂μ.restrict s, ‖f' x - A‖₊ ≤ δ := by /- The conclusion will hold at the Lebesgue density points of `s` (which have full measure). At such a point `x`, for any `z` and any `ε > 0` one has for small `r` that `{x} + r • closedBall z ε` intersects `s`. At a point `y` in the intersection, `f y - f x` is close both to `f' x (r z)` (by differentiability) and to `A (r z)` (by linear approximation), so these two quantities are close, i.e., `(f' x - A) z` is small. -/ filter_upwards [Besicovitch.ae_tendsto_measure_inter_div μ s, ae_restrict_mem hs] -- start from a Lebesgue density point `x`, belonging to `s`. intro x hx xs -- consider an arbitrary vector `z`. apply ContinuousLinearMap.opNorm_le_bound _ δ.2 fun z => ?_ -- to show that `‖(f' x - A) z‖ ≤ δ ‖z‖`, it suffices to do it up to some error that vanishes -- asymptotically in terms of `ε > 0`. suffices H : ∀ ε, 0 < ε → ‖(f' x - A) z‖ ≤ (δ + ε) * (‖z‖ + ε) + ‖f' x - A‖ * ε by have : Tendsto (fun ε : ℝ => ((δ : ℝ) + ε) * (‖z‖ + ε) + ‖f' x - A‖ * ε) (𝓝[>] 0) (𝓝 ((δ + 0) * (‖z‖ + 0) + ‖f' x - A‖ * 0)) := Tendsto.mono_left (Continuous.tendsto (by continuity) 0) nhdsWithin_le_nhds simp only [add_zero, mul_zero] at this apply le_of_tendsto_of_tendsto tendsto_const_nhds this filter_upwards [self_mem_nhdsWithin] exact H -- fix a positive `ε`. intro ε εpos -- for small enough `r`, the rescaled ball `r • closedBall z ε` intersects `s`, as `x` is a -- density point have B₁ : ∀ᶠ r in 𝓝[>] (0 : ℝ), (s ∩ ({x} + r • closedBall z ε)).Nonempty := eventually_nonempty_inter_smul_of_density_one μ s x hx _ measurableSet_closedBall (measure_closedBall_pos μ z εpos).ne' obtain ⟨ρ, ρpos, hρ⟩ : ∃ ρ > 0, ball x ρ ∩ s ⊆ {y : E | ‖f y - f x - (f' x) (y - x)‖ ≤ ε * ‖y - x‖} := mem_nhdsWithin_iff.1 ((hf' x xs).isLittleO.def εpos) -- for small enough `r`, the rescaled ball `r • closedBall z ε` is included in the set where -- `f y - f x` is well approximated by `f' x (y - x)`. have B₂ : ∀ᶠ r in 𝓝[>] (0 : ℝ), {x} + r • closedBall z ε ⊆ ball x ρ := by apply nhdsWithin_le_nhds exact eventually_singleton_add_smul_subset isBounded_closedBall (ball_mem_nhds x ρpos) -- fix a small positive `r` satisfying the above properties, as well as a corresponding `y`. obtain ⟨r, ⟨y, ⟨ys, hy⟩⟩, rρ, rpos⟩ : ∃ r : ℝ, (s ∩ ({x} + r • closedBall z ε)).Nonempty ∧ {x} + r • closedBall z ε ⊆ ball x ρ ∧ 0 < r := (B₁.and (B₂.and self_mem_nhdsWithin)).exists -- write `y = x + r a` with `a ∈ closedBall z ε`. obtain ⟨a, az, ya⟩ : ∃ a, a ∈ closedBall z ε ∧ y = x + r • a := by simp only [mem_smul_set, image_add_left, mem_preimage, singleton_add] at hy rcases hy with ⟨a, az, ha⟩ exact ⟨a, az, by simp only [ha, add_neg_cancel_left]⟩ have norm_a : ‖a‖ ≤ ‖z‖ + ε := calc ‖a‖ = ‖z + (a - z)‖ := by simp only [add_sub_cancel] _ ≤ ‖z‖ + ‖a - z‖ := norm_add_le _ _ _ ≤ ‖z‖ + ε := add_le_add_left (mem_closedBall_iff_norm.1 az) _ -- use the approximation properties to control `(f' x - A) a`, and then `(f' x - A) z` as `z` is -- close to `a`. have I : r * ‖(f' x - A) a‖ ≤ r * (δ + ε) * (‖z‖ + ε) := calc r * ‖(f' x - A) a‖ = ‖(f' x - A) (r • a)‖ := by simp only [ContinuousLinearMap.map_smul, norm_smul, Real.norm_eq_abs, abs_of_nonneg rpos.le] _ = ‖f y - f x - A (y - x) - (f y - f x - (f' x) (y - x))‖ := by congr 1 simp only [ya, add_sub_cancel_left, sub_sub_sub_cancel_left, ContinuousLinearMap.coe_sub', eq_self_iff_true, sub_left_inj, Pi.sub_apply, ContinuousLinearMap.map_smul, smul_sub] _ ≤ ‖f y - f x - A (y - x)‖ + ‖f y - f x - (f' x) (y - x)‖ := norm_sub_le _ _ _ ≤ δ * ‖y - x‖ + ε * ‖y - x‖ := (add_le_add (hf _ ys _ xs) (hρ ⟨rρ hy, ys⟩)) _ = r * (δ + ε) * ‖a‖ := by simp only [ya, add_sub_cancel_left, norm_smul, Real.norm_eq_abs, abs_of_nonneg rpos.le] ring _ ≤ r * (δ + ε) * (‖z‖ + ε) := by gcongr calc ‖(f' x - A) z‖ = ‖(f' x - A) a + (f' x - A) (z - a)‖ := by congr 1 simp only [ContinuousLinearMap.coe_sub', map_sub, Pi.sub_apply] abel _ ≤ ‖(f' x - A) a‖ + ‖(f' x - A) (z - a)‖ := norm_add_le _ _ _ ≤ (δ + ε) * (‖z‖ + ε) + ‖f' x - A‖ * ‖z - a‖ := by apply add_le_add · rw [mul_assoc] at I; exact (mul_le_mul_left rpos).1 I · apply ContinuousLinearMap.le_opNorm _ ≤ (δ + ε) * (‖z‖ + ε) + ‖f' x - A‖ * ε := by rw [mem_closedBall_iff_norm'] at az gcongr #align approximates_linear_on.norm_fderiv_sub_le ApproximatesLinearOn.norm_fderiv_sub_le /-! ### Measure zero of the image, over non-measurable sets If a set has measure `0`, then its image under a differentiable map has measure zero. This doesn't require the set to be measurable. In the same way, if `f` is differentiable on a set `s` with non-invertible derivative everywhere, then `f '' s` has measure `0`, again without measurability assumptions. -/ /-- A differentiable function maps sets of measure zero to sets of measure zero. -/ theorem addHaar_image_eq_zero_of_differentiableOn_of_addHaar_eq_zero (hf : DifferentiableOn ℝ f s) (hs : μ s = 0) : μ (f '' s) = 0 := by refine le_antisymm ?_ (zero_le _) have : ∀ A : E →L[ℝ] E, ∃ δ : ℝ≥0, 0 < δ ∧ ∀ (t : Set E), ApproximatesLinearOn f A t δ → μ (f '' t) ≤ (Real.toNNReal |A.det| + 1 : ℝ≥0) * μ t := by intro A let m : ℝ≥0 := Real.toNNReal |A.det| + 1 have I : ENNReal.ofReal |A.det| < m := by simp only [m, ENNReal.ofReal, lt_add_iff_pos_right, zero_lt_one, ENNReal.coe_lt_coe] rcases ((addHaar_image_le_mul_of_det_lt μ A I).and self_mem_nhdsWithin).exists with ⟨δ, h, h'⟩ exact ⟨δ, h', fun t ht => h t f ht⟩ choose δ hδ using this obtain ⟨t, A, _, _, t_cover, ht, -⟩ : ∃ (t : ℕ → Set E) (A : ℕ → E →L[ℝ] E), Pairwise (Disjoint on t) ∧ (∀ n : ℕ, MeasurableSet (t n)) ∧ (s ⊆ ⋃ n : ℕ, t n) ∧ (∀ n : ℕ, ApproximatesLinearOn f (A n) (s ∩ t n) (δ (A n))) ∧ (s.Nonempty → ∀ n, ∃ y ∈ s, A n = fderivWithin ℝ f s y) := exists_partition_approximatesLinearOn_of_hasFDerivWithinAt f s (fderivWithin ℝ f s) (fun x xs => (hf x xs).hasFDerivWithinAt) δ fun A => (hδ A).1.ne' calc μ (f '' s) ≤ μ (⋃ n, f '' (s ∩ t n)) := by apply measure_mono rw [← image_iUnion, ← inter_iUnion] exact image_subset f (subset_inter Subset.rfl t_cover) _ ≤ ∑' n, μ (f '' (s ∩ t n)) := measure_iUnion_le _ _ ≤ ∑' n, (Real.toNNReal |(A n).det| + 1 : ℝ≥0) * μ (s ∩ t n) := by apply ENNReal.tsum_le_tsum fun n => ?_ apply (hδ (A n)).2 exact ht n _ ≤ ∑' n, ((Real.toNNReal |(A n).det| + 1 : ℝ≥0) : ℝ≥0∞) * 0 := by refine ENNReal.tsum_le_tsum fun n => mul_le_mul_left' ?_ _ exact le_trans (measure_mono inter_subset_left) (le_of_eq hs) _ = 0 := by simp only [tsum_zero, mul_zero] #align measure_theory.add_haar_image_eq_zero_of_differentiable_on_of_add_haar_eq_zero MeasureTheory.addHaar_image_eq_zero_of_differentiableOn_of_addHaar_eq_zero /-- A version of **Sard's lemma** in fixed dimension: given a differentiable function from `E` to `E` and a set where the differential is not invertible, then the image of this set has zero measure. Here, we give an auxiliary statement towards this result. -/ theorem addHaar_image_eq_zero_of_det_fderivWithin_eq_zero_aux (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (R : ℝ) (hs : s ⊆ closedBall 0 R) (ε : ℝ≥0) (εpos : 0 < ε) (h'f' : ∀ x ∈ s, (f' x).det = 0) : μ (f '' s) ≤ ε * μ (closedBall 0 R) := by rcases eq_empty_or_nonempty s with (rfl | h's); · simp only [measure_empty, zero_le, image_empty] have : ∀ A : E →L[ℝ] E, ∃ δ : ℝ≥0, 0 < δ ∧ ∀ (t : Set E), ApproximatesLinearOn f A t δ → μ (f '' t) ≤ (Real.toNNReal |A.det| + ε : ℝ≥0) * μ t := by intro A let m : ℝ≥0 := Real.toNNReal |A.det| + ε have I : ENNReal.ofReal |A.det| < m := by simp only [m, ENNReal.ofReal, lt_add_iff_pos_right, εpos, ENNReal.coe_lt_coe] rcases ((addHaar_image_le_mul_of_det_lt μ A I).and self_mem_nhdsWithin).exists with ⟨δ, h, h'⟩ exact ⟨δ, h', fun t ht => h t f ht⟩ choose δ hδ using this obtain ⟨t, A, t_disj, t_meas, t_cover, ht, Af'⟩ : ∃ (t : ℕ → Set E) (A : ℕ → E →L[ℝ] E), Pairwise (Disjoint on t) ∧ (∀ n : ℕ, MeasurableSet (t n)) ∧ (s ⊆ ⋃ n : ℕ, t n) ∧ (∀ n : ℕ, ApproximatesLinearOn f (A n) (s ∩ t n) (δ (A n))) ∧ (s.Nonempty → ∀ n, ∃ y ∈ s, A n = f' y) := exists_partition_approximatesLinearOn_of_hasFDerivWithinAt f s f' hf' δ fun A => (hδ A).1.ne' calc μ (f '' s) ≤ μ (⋃ n, f '' (s ∩ t n)) := by rw [← image_iUnion, ← inter_iUnion] gcongr exact subset_inter Subset.rfl t_cover _ ≤ ∑' n, μ (f '' (s ∩ t n)) := measure_iUnion_le _ _ ≤ ∑' n, (Real.toNNReal |(A n).det| + ε : ℝ≥0) * μ (s ∩ t n) := by gcongr exact (hδ (A _)).2 _ (ht _) _ = ∑' n, ε * μ (s ∩ t n) := by congr with n rcases Af' h's n with ⟨y, ys, hy⟩ simp only [hy, h'f' y ys, Real.toNNReal_zero, abs_zero, zero_add] _ ≤ ε * ∑' n, μ (closedBall 0 R ∩ t n) := by rw [ENNReal.tsum_mul_left] gcongr _ = ε * μ (⋃ n, closedBall 0 R ∩ t n) := by rw [measure_iUnion] · exact pairwise_disjoint_mono t_disj fun n => inter_subset_right · intro n exact measurableSet_closedBall.inter (t_meas n) _ ≤ ε * μ (closedBall 0 R) := by rw [← inter_iUnion] exact mul_le_mul_left' (measure_mono inter_subset_left) _ #align measure_theory.add_haar_image_eq_zero_of_det_fderiv_within_eq_zero_aux MeasureTheory.addHaar_image_eq_zero_of_det_fderivWithin_eq_zero_aux /-- A version of Sard lemma in fixed dimension: given a differentiable function from `E` to `E` and a set where the differential is not invertible, then the image of this set has zero measure. -/ theorem addHaar_image_eq_zero_of_det_fderivWithin_eq_zero (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (h'f' : ∀ x ∈ s, (f' x).det = 0) : μ (f '' s) = 0 := by suffices H : ∀ R, μ (f '' (s ∩ closedBall 0 R)) = 0 by apply le_antisymm _ (zero_le _) rw [← iUnion_inter_closedBall_nat s 0] calc μ (f '' ⋃ n : ℕ, s ∩ closedBall 0 n) ≤ ∑' n : ℕ, μ (f '' (s ∩ closedBall 0 n)) := by rw [image_iUnion]; exact measure_iUnion_le _ _ ≤ 0 := by simp only [H, tsum_zero, nonpos_iff_eq_zero] intro R have A : ∀ (ε : ℝ≥0), 0 < ε → μ (f '' (s ∩ closedBall 0 R)) ≤ ε * μ (closedBall 0 R) := fun ε εpos => addHaar_image_eq_zero_of_det_fderivWithin_eq_zero_aux μ (fun x hx => (hf' x hx.1).mono inter_subset_left) R inter_subset_right ε εpos fun x hx => h'f' x hx.1 have B : Tendsto (fun ε : ℝ≥0 => (ε : ℝ≥0∞) * μ (closedBall 0 R)) (𝓝[>] 0) (𝓝 0) := by have : Tendsto (fun ε : ℝ≥0 => (ε : ℝ≥0∞) * μ (closedBall 0 R)) (𝓝 0) (𝓝 (((0 : ℝ≥0) : ℝ≥0∞) * μ (closedBall 0 R))) := ENNReal.Tendsto.mul_const (ENNReal.tendsto_coe.2 tendsto_id) (Or.inr measure_closedBall_lt_top.ne) simp only [zero_mul, ENNReal.coe_zero] at this exact Tendsto.mono_left this nhdsWithin_le_nhds apply le_antisymm _ (zero_le _) apply ge_of_tendsto B filter_upwards [self_mem_nhdsWithin] exact A #align measure_theory.add_haar_image_eq_zero_of_det_fderiv_within_eq_zero MeasureTheory.addHaar_image_eq_zero_of_det_fderivWithin_eq_zero /-! ### Weak measurability statements We show that the derivative of a function on a set is almost everywhere measurable, and that the image `f '' s` is measurable if `f` is injective on `s`. The latter statement follows from the Lusin-Souslin theorem. -/ /-- The derivative of a function on a measurable set is almost everywhere measurable on this set with respect to Lebesgue measure. Note that, in general, it is not genuinely measurable there, as `f'` is not unique (but only on a set of measure `0`, as the argument shows). -/ theorem aemeasurable_fderivWithin (hs : MeasurableSet s) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) : AEMeasurable f' (μ.restrict s) := by /- It suffices to show that `f'` can be uniformly approximated by a measurable function. Fix `ε > 0`. Thanks to `exists_partition_approximatesLinearOn_of_hasFDerivWithinAt`, one can find a countable measurable partition of `s` into sets `s ∩ t n` on which `f` is well approximated by linear maps `A n`. On almost all of `s ∩ t n`, it follows from `ApproximatesLinearOn.norm_fderiv_sub_le` that `f'` is uniformly approximated by `A n`, which gives the conclusion. -/ -- fix a precision `ε` refine aemeasurable_of_unif_approx fun ε εpos => ?_ let δ : ℝ≥0 := ⟨ε, le_of_lt εpos⟩ have δpos : 0 < δ := εpos -- partition `s` into sets `s ∩ t n` on which `f` is approximated by linear maps `A n`. obtain ⟨t, A, t_disj, t_meas, t_cover, ht, _⟩ : ∃ (t : ℕ → Set E) (A : ℕ → E →L[ℝ] E), Pairwise (Disjoint on t) ∧ (∀ n : ℕ, MeasurableSet (t n)) ∧ (s ⊆ ⋃ n : ℕ, t n) ∧ (∀ n : ℕ, ApproximatesLinearOn f (A n) (s ∩ t n) δ) ∧ (s.Nonempty → ∀ n, ∃ y ∈ s, A n = f' y) := exists_partition_approximatesLinearOn_of_hasFDerivWithinAt f s f' hf' (fun _ => δ) fun _ => δpos.ne' -- define a measurable function `g` which coincides with `A n` on `t n`. obtain ⟨g, g_meas, hg⟩ : ∃ g : E → E →L[ℝ] E, Measurable g ∧ ∀ (n : ℕ) (x : E), x ∈ t n → g x = A n := exists_measurable_piecewise t t_meas (fun n _ => A n) (fun n => measurable_const) <| t_disj.mono fun i j h => by simp only [h.inter_eq, eqOn_empty] refine ⟨g, g_meas.aemeasurable, ?_⟩ -- reduce to checking that `f'` and `g` are close on almost all of `s ∩ t n`, for all `n`. suffices H : ∀ᵐ x : E ∂sum fun n ↦ μ.restrict (s ∩ t n), dist (g x) (f' x) ≤ ε by have : μ.restrict s ≤ sum fun n => μ.restrict (s ∩ t n) := by have : s = ⋃ n, s ∩ t n := by rw [← inter_iUnion] exact Subset.antisymm (subset_inter Subset.rfl t_cover) inter_subset_left conv_lhs => rw [this] exact restrict_iUnion_le exact ae_mono this H -- fix such an `n`. refine ae_sum_iff.2 fun n => ?_ -- on almost all `s ∩ t n`, `f' x` is close to `A n` thanks to -- `ApproximatesLinearOn.norm_fderiv_sub_le`. have E₁ : ∀ᵐ x : E ∂μ.restrict (s ∩ t n), ‖f' x - A n‖₊ ≤ δ := (ht n).norm_fderiv_sub_le μ (hs.inter (t_meas n)) f' fun x hx => (hf' x hx.1).mono inter_subset_left -- moreover, `g x` is equal to `A n` there. have E₂ : ∀ᵐ x : E ∂μ.restrict (s ∩ t n), g x = A n := by suffices H : ∀ᵐ x : E ∂μ.restrict (t n), g x = A n from ae_mono (restrict_mono inter_subset_right le_rfl) H filter_upwards [ae_restrict_mem (t_meas n)] exact hg n -- putting these two properties together gives the conclusion. filter_upwards [E₁, E₂] with x hx1 hx2 rw [← nndist_eq_nnnorm] at hx1 rw [hx2, dist_comm] exact hx1 #align measure_theory.ae_measurable_fderiv_within MeasureTheory.aemeasurable_fderivWithin theorem aemeasurable_ofReal_abs_det_fderivWithin (hs : MeasurableSet s) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) : AEMeasurable (fun x => ENNReal.ofReal |(f' x).det|) (μ.restrict s) := by apply ENNReal.measurable_ofReal.comp_aemeasurable refine continuous_abs.measurable.comp_aemeasurable ?_ refine ContinuousLinearMap.continuous_det.measurable.comp_aemeasurable ?_ exact aemeasurable_fderivWithin μ hs hf' #align measure_theory.ae_measurable_of_real_abs_det_fderiv_within MeasureTheory.aemeasurable_ofReal_abs_det_fderivWithin
Mathlib/MeasureTheory/Function/Jacobian.lean
760
766
theorem aemeasurable_toNNReal_abs_det_fderivWithin (hs : MeasurableSet s) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) : AEMeasurable (fun x => |(f' x).det|.toNNReal) (μ.restrict s) := by
apply measurable_real_toNNReal.comp_aemeasurable refine continuous_abs.measurable.comp_aemeasurable ?_ refine ContinuousLinearMap.continuous_det.measurable.comp_aemeasurable ?_ exact aemeasurable_fderivWithin μ hs hf'
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.MeasureTheory.Function.LpSeminorm.Basic import Mathlib.MeasureTheory.Integral.MeanInequalities #align_import measure_theory.function.lp_seminorm from "leanprover-community/mathlib"@"c4015acc0a223449d44061e27ddac1835a3852b9" /-! # Triangle inequality for `Lp`-seminorm In this file we prove several versions of the triangle inequality for the `Lp` seminorm, as well as simple corollaries. -/ open Filter open scoped ENNReal Topology namespace MeasureTheory variable {α E : Type*} {m : MeasurableSpace α} [NormedAddCommGroup E] {p : ℝ≥0∞} {q : ℝ} {μ : Measure α} {f g : α → E} theorem snorm'_add_le {f g : α → E} (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ) (hq1 : 1 ≤ q) : snorm' (f + g) q μ ≤ snorm' f q μ + snorm' g q μ := calc (∫⁻ a, (‖(f + g) a‖₊ : ℝ≥0∞) ^ q ∂μ) ^ (1 / q) ≤ (∫⁻ a, ((fun a => (‖f a‖₊ : ℝ≥0∞)) + fun a => (‖g a‖₊ : ℝ≥0∞)) a ^ q ∂μ) ^ (1 / q) := by gcongr with a simp only [Pi.add_apply, ← ENNReal.coe_add, ENNReal.coe_le_coe, nnnorm_add_le] _ ≤ snorm' f q μ + snorm' g q μ := ENNReal.lintegral_Lp_add_le hf.ennnorm hg.ennnorm hq1 #align measure_theory.snorm'_add_le MeasureTheory.snorm'_add_le
Mathlib/MeasureTheory/Function/LpSeminorm/TriangleInequality.lean
36
44
theorem snorm'_add_le_of_le_one {f g : α → E} (hf : AEStronglyMeasurable f μ) (hq0 : 0 ≤ q) (hq1 : q ≤ 1) : snorm' (f + g) q μ ≤ (2 : ℝ≥0∞) ^ (1 / q - 1) * (snorm' f q μ + snorm' g q μ) := calc (∫⁻ a, (‖(f + g) a‖₊ : ℝ≥0∞) ^ q ∂μ) ^ (1 / q) ≤ (∫⁻ a, ((fun a => (‖f a‖₊ : ℝ≥0∞)) + fun a => (‖g a‖₊ : ℝ≥0∞)) a ^ q ∂μ) ^ (1 / q) := by
gcongr with a simp only [Pi.add_apply, ← ENNReal.coe_add, ENNReal.coe_le_coe, nnnorm_add_le] _ ≤ (2 : ℝ≥0∞) ^ (1 / q - 1) * (snorm' f q μ + snorm' g q μ) := ENNReal.lintegral_Lp_add_le_of_le_one hf.ennnorm hq0 hq1
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad, Minchao Wu, Mario Carneiro -/ import Mathlib.Data.Finset.Attr import Mathlib.Data.Multiset.FinsetOps import Mathlib.Logic.Equiv.Set import Mathlib.Order.Directed import Mathlib.Order.Interval.Set.Basic #align_import data.finset.basic from "leanprover-community/mathlib"@"442a83d738cb208d3600056c489be16900ba701d" /-! # Finite sets Terms of type `Finset α` are one way of talking about finite subsets of `α` in mathlib. Below, `Finset α` is defined as a structure with 2 fields: 1. `val` is a `Multiset α` of elements; 2. `nodup` is a proof that `val` has no duplicates. Finsets in Lean are constructive in that they have an underlying `List` that enumerates their elements. In particular, any function that uses the data of the underlying list cannot depend on its ordering. This is handled on the `Multiset` level by multiset API, so in most cases one needn't worry about it explicitly. Finsets give a basic foundation for defining finite sums and products over types: 1. `∑ i ∈ (s : Finset α), f i`; 2. `∏ i ∈ (s : Finset α), f i`. Lean refers to these operations as big operators. More information can be found in `Mathlib.Algebra.BigOperators.Group.Finset`. Finsets are directly used to define fintypes in Lean. A `Fintype α` instance for a type `α` consists of a universal `Finset α` containing every term of `α`, called `univ`. See `Mathlib.Data.Fintype.Basic`. There is also `univ'`, the noncomputable partner to `univ`, which is defined to be `α` as a finset if `α` is finite, and the empty finset otherwise. See `Mathlib.Data.Fintype.Basic`. `Finset.card`, the size of a finset is defined in `Mathlib.Data.Finset.Card`. This is then used to define `Fintype.card`, the size of a type. ## Main declarations ### Main definitions * `Finset`: Defines a type for the finite subsets of `α`. Constructing a `Finset` requires two pieces of data: `val`, a `Multiset α` of elements, and `nodup`, a proof that `val` has no duplicates. * `Finset.instMembershipFinset`: Defines membership `a ∈ (s : Finset α)`. * `Finset.instCoeTCFinsetSet`: Provides a coercion `s : Finset α` to `s : Set α`. * `Finset.instCoeSortFinsetType`: Coerce `s : Finset α` to the type of all `x ∈ s`. * `Finset.induction_on`: Induction on finsets. To prove a proposition about an arbitrary `Finset α`, it suffices to prove it for the empty finset, and to show that if it holds for some `Finset α`, then it holds for the finset obtained by inserting a new element. * `Finset.choose`: Given a proof `h` of existence and uniqueness of a certain element satisfying a predicate, `choose s h` returns the element of `s` satisfying that predicate. ### Finset constructions * `Finset.instSingletonFinset`: Denoted by `{a}`; the finset consisting of one element. * `Finset.empty`: Denoted by `∅`. The finset associated to any type consisting of no elements. * `Finset.range`: For any `n : ℕ`, `range n` is equal to `{0, 1, ... , n - 1} ⊆ ℕ`. This convention is consistent with other languages and normalizes `card (range n) = n`. Beware, `n` is not in `range n`. * `Finset.attach`: Given `s : Finset α`, `attach s` forms a finset of elements of the subtype `{a // a ∈ s}`; in other words, it attaches elements to a proof of membership in the set. ### Finsets from functions * `Finset.filter`: Given a decidable predicate `p : α → Prop`, `s.filter p` is the finset consisting of those elements in `s` satisfying the predicate `p`. ### The lattice structure on subsets of finsets There is a natural lattice structure on the subsets of a set. In Lean, we use lattice notation to talk about things involving unions and intersections. See `Mathlib.Order.Lattice`. For the lattice structure on finsets, `⊥` is called `bot` with `⊥ = ∅` and `⊤` is called `top` with `⊤ = univ`. * `Finset.instHasSubsetFinset`: Lots of API about lattices, otherwise behaves as one would expect. * `Finset.instUnionFinset`: Defines `s ∪ t` (or `s ⊔ t`) as the union of `s` and `t`. See `Finset.sup`/`Finset.biUnion` for finite unions. * `Finset.instInterFinset`: Defines `s ∩ t` (or `s ⊓ t`) as the intersection of `s` and `t`. See `Finset.inf` for finite intersections. ### Operations on two or more finsets * `insert` and `Finset.cons`: For any `a : α`, `insert s a` returns `s ∪ {a}`. `cons s a h` returns the same except that it requires a hypothesis stating that `a` is not already in `s`. This does not require decidable equality on the type `α`. * `Finset.instUnionFinset`: see "The lattice structure on subsets of finsets" * `Finset.instInterFinset`: see "The lattice structure on subsets of finsets" * `Finset.erase`: For any `a : α`, `erase s a` returns `s` with the element `a` removed. * `Finset.instSDiffFinset`: Defines the set difference `s \ t` for finsets `s` and `t`. * `Finset.product`: Given finsets of `α` and `β`, defines finsets of `α × β`. For arbitrary dependent products, see `Mathlib.Data.Finset.Pi`. ### Predicates on finsets * `Disjoint`: defined via the lattice structure on finsets; two sets are disjoint if their intersection is empty. * `Finset.Nonempty`: A finset is nonempty if it has elements. This is equivalent to saying `s ≠ ∅`. ### Equivalences between finsets * The `Mathlib.Data.Equiv` files describe a general type of equivalence, so look in there for any lemmas. There is some API for rewriting sums and products from `s` to `t` given that `s ≃ t`. TODO: examples ## Tags finite sets, finset -/ -- Assert that we define `Finset` without the material on `List.sublists`. -- Note that we cannot use `List.sublists` itself as that is defined very early. assert_not_exists List.sublistsLen assert_not_exists Multiset.Powerset assert_not_exists CompleteLattice open Multiset Subtype Nat Function universe u variable {α : Type*} {β : Type*} {γ : Type*} /-- `Finset α` is the type of finite sets of elements of `α`. It is implemented as a multiset (a list up to permutation) which has no duplicate elements. -/ structure Finset (α : Type*) where /-- The underlying multiset -/ val : Multiset α /-- `val` contains no duplicates -/ nodup : Nodup val #align finset Finset instance Multiset.canLiftFinset {α} : CanLift (Multiset α) (Finset α) Finset.val Multiset.Nodup := ⟨fun m hm => ⟨⟨m, hm⟩, rfl⟩⟩ #align multiset.can_lift_finset Multiset.canLiftFinset namespace Finset theorem eq_of_veq : ∀ {s t : Finset α}, s.1 = t.1 → s = t | ⟨s, _⟩, ⟨t, _⟩, h => by cases h; rfl #align finset.eq_of_veq Finset.eq_of_veq theorem val_injective : Injective (val : Finset α → Multiset α) := fun _ _ => eq_of_veq #align finset.val_injective Finset.val_injective @[simp] theorem val_inj {s t : Finset α} : s.1 = t.1 ↔ s = t := val_injective.eq_iff #align finset.val_inj Finset.val_inj @[simp] theorem dedup_eq_self [DecidableEq α] (s : Finset α) : dedup s.1 = s.1 := s.2.dedup #align finset.dedup_eq_self Finset.dedup_eq_self instance decidableEq [DecidableEq α] : DecidableEq (Finset α) | _, _ => decidable_of_iff _ val_inj #align finset.has_decidable_eq Finset.decidableEq /-! ### membership -/ instance : Membership α (Finset α) := ⟨fun a s => a ∈ s.1⟩ theorem mem_def {a : α} {s : Finset α} : a ∈ s ↔ a ∈ s.1 := Iff.rfl #align finset.mem_def Finset.mem_def @[simp] theorem mem_val {a : α} {s : Finset α} : a ∈ s.1 ↔ a ∈ s := Iff.rfl #align finset.mem_val Finset.mem_val @[simp] theorem mem_mk {a : α} {s nd} : a ∈ @Finset.mk α s nd ↔ a ∈ s := Iff.rfl #align finset.mem_mk Finset.mem_mk instance decidableMem [_h : DecidableEq α] (a : α) (s : Finset α) : Decidable (a ∈ s) := Multiset.decidableMem _ _ #align finset.decidable_mem Finset.decidableMem @[simp] lemma forall_mem_not_eq {s : Finset α} {a : α} : (∀ b ∈ s, ¬ a = b) ↔ a ∉ s := by aesop @[simp] lemma forall_mem_not_eq' {s : Finset α} {a : α} : (∀ b ∈ s, ¬ b = a) ↔ a ∉ s := by aesop /-! ### set coercion -/ -- Porting note (#11445): new definition /-- Convert a finset to a set in the natural way. -/ @[coe] def toSet (s : Finset α) : Set α := { a | a ∈ s } /-- Convert a finset to a set in the natural way. -/ instance : CoeTC (Finset α) (Set α) := ⟨toSet⟩ @[simp, norm_cast] theorem mem_coe {a : α} {s : Finset α} : a ∈ (s : Set α) ↔ a ∈ (s : Finset α) := Iff.rfl #align finset.mem_coe Finset.mem_coe @[simp] theorem setOf_mem {α} {s : Finset α} : { a | a ∈ s } = s := rfl #align finset.set_of_mem Finset.setOf_mem @[simp] theorem coe_mem {s : Finset α} (x : (s : Set α)) : ↑x ∈ s := x.2 #align finset.coe_mem Finset.coe_mem -- Porting note (#10618): @[simp] can prove this theorem mk_coe {s : Finset α} (x : (s : Set α)) {h} : (⟨x, h⟩ : (s : Set α)) = x := Subtype.coe_eta _ _ #align finset.mk_coe Finset.mk_coe instance decidableMem' [DecidableEq α] (a : α) (s : Finset α) : Decidable (a ∈ (s : Set α)) := s.decidableMem _ #align finset.decidable_mem' Finset.decidableMem' /-! ### extensionality -/ theorem ext_iff {s₁ s₂ : Finset α} : s₁ = s₂ ↔ ∀ a, a ∈ s₁ ↔ a ∈ s₂ := val_inj.symm.trans <| s₁.nodup.ext s₂.nodup #align finset.ext_iff Finset.ext_iff @[ext] theorem ext {s₁ s₂ : Finset α} : (∀ a, a ∈ s₁ ↔ a ∈ s₂) → s₁ = s₂ := ext_iff.2 #align finset.ext Finset.ext @[simp, norm_cast] theorem coe_inj {s₁ s₂ : Finset α} : (s₁ : Set α) = s₂ ↔ s₁ = s₂ := Set.ext_iff.trans ext_iff.symm #align finset.coe_inj Finset.coe_inj theorem coe_injective {α} : Injective ((↑) : Finset α → Set α) := fun _s _t => coe_inj.1 #align finset.coe_injective Finset.coe_injective /-! ### type coercion -/ /-- Coercion from a finset to the corresponding subtype. -/ instance {α : Type u} : CoeSort (Finset α) (Type u) := ⟨fun s => { x // x ∈ s }⟩ -- Porting note (#10618): @[simp] can prove this protected theorem forall_coe {α : Type*} (s : Finset α) (p : s → Prop) : (∀ x : s, p x) ↔ ∀ (x : α) (h : x ∈ s), p ⟨x, h⟩ := Subtype.forall #align finset.forall_coe Finset.forall_coe -- Porting note (#10618): @[simp] can prove this protected theorem exists_coe {α : Type*} (s : Finset α) (p : s → Prop) : (∃ x : s, p x) ↔ ∃ (x : α) (h : x ∈ s), p ⟨x, h⟩ := Subtype.exists #align finset.exists_coe Finset.exists_coe instance PiFinsetCoe.canLift (ι : Type*) (α : ι → Type*) [_ne : ∀ i, Nonempty (α i)] (s : Finset ι) : CanLift (∀ i : s, α i) (∀ i, α i) (fun f i => f i) fun _ => True := PiSubtype.canLift ι α (· ∈ s) #align finset.pi_finset_coe.can_lift Finset.PiFinsetCoe.canLift instance PiFinsetCoe.canLift' (ι α : Type*) [_ne : Nonempty α] (s : Finset ι) : CanLift (s → α) (ι → α) (fun f i => f i) fun _ => True := PiFinsetCoe.canLift ι (fun _ => α) s #align finset.pi_finset_coe.can_lift' Finset.PiFinsetCoe.canLift' instance FinsetCoe.canLift (s : Finset α) : CanLift α s (↑) fun a => a ∈ s where prf a ha := ⟨⟨a, ha⟩, rfl⟩ #align finset.finset_coe.can_lift Finset.FinsetCoe.canLift @[simp, norm_cast] theorem coe_sort_coe (s : Finset α) : ((s : Set α) : Sort _) = s := rfl #align finset.coe_sort_coe Finset.coe_sort_coe /-! ### Subset and strict subset relations -/ section Subset variable {s t : Finset α} instance : HasSubset (Finset α) := ⟨fun s t => ∀ ⦃a⦄, a ∈ s → a ∈ t⟩ instance : HasSSubset (Finset α) := ⟨fun s t => s ⊆ t ∧ ¬t ⊆ s⟩ instance partialOrder : PartialOrder (Finset α) where le := (· ⊆ ·) lt := (· ⊂ ·) le_refl s a := id le_trans s t u hst htu a ha := htu <| hst ha le_antisymm s t hst hts := ext fun a => ⟨@hst _, @hts _⟩ instance : IsRefl (Finset α) (· ⊆ ·) := show IsRefl (Finset α) (· ≤ ·) by infer_instance instance : IsTrans (Finset α) (· ⊆ ·) := show IsTrans (Finset α) (· ≤ ·) by infer_instance instance : IsAntisymm (Finset α) (· ⊆ ·) := show IsAntisymm (Finset α) (· ≤ ·) by infer_instance instance : IsIrrefl (Finset α) (· ⊂ ·) := show IsIrrefl (Finset α) (· < ·) by infer_instance instance : IsTrans (Finset α) (· ⊂ ·) := show IsTrans (Finset α) (· < ·) by infer_instance instance : IsAsymm (Finset α) (· ⊂ ·) := show IsAsymm (Finset α) (· < ·) by infer_instance instance : IsNonstrictStrictOrder (Finset α) (· ⊆ ·) (· ⊂ ·) := ⟨fun _ _ => Iff.rfl⟩ theorem subset_def : s ⊆ t ↔ s.1 ⊆ t.1 := Iff.rfl #align finset.subset_def Finset.subset_def theorem ssubset_def : s ⊂ t ↔ s ⊆ t ∧ ¬t ⊆ s := Iff.rfl #align finset.ssubset_def Finset.ssubset_def @[simp] theorem Subset.refl (s : Finset α) : s ⊆ s := Multiset.Subset.refl _ #align finset.subset.refl Finset.Subset.refl protected theorem Subset.rfl {s : Finset α} : s ⊆ s := Subset.refl _ #align finset.subset.rfl Finset.Subset.rfl protected theorem subset_of_eq {s t : Finset α} (h : s = t) : s ⊆ t := h ▸ Subset.refl _ #align finset.subset_of_eq Finset.subset_of_eq theorem Subset.trans {s₁ s₂ s₃ : Finset α} : s₁ ⊆ s₂ → s₂ ⊆ s₃ → s₁ ⊆ s₃ := Multiset.Subset.trans #align finset.subset.trans Finset.Subset.trans theorem Superset.trans {s₁ s₂ s₃ : Finset α} : s₁ ⊇ s₂ → s₂ ⊇ s₃ → s₁ ⊇ s₃ := fun h' h => Subset.trans h h' #align finset.superset.trans Finset.Superset.trans theorem mem_of_subset {s₁ s₂ : Finset α} {a : α} : s₁ ⊆ s₂ → a ∈ s₁ → a ∈ s₂ := Multiset.mem_of_subset #align finset.mem_of_subset Finset.mem_of_subset theorem not_mem_mono {s t : Finset α} (h : s ⊆ t) {a : α} : a ∉ t → a ∉ s := mt <| @h _ #align finset.not_mem_mono Finset.not_mem_mono theorem Subset.antisymm {s₁ s₂ : Finset α} (H₁ : s₁ ⊆ s₂) (H₂ : s₂ ⊆ s₁) : s₁ = s₂ := ext fun a => ⟨@H₁ a, @H₂ a⟩ #align finset.subset.antisymm Finset.Subset.antisymm theorem subset_iff {s₁ s₂ : Finset α} : s₁ ⊆ s₂ ↔ ∀ ⦃x⦄, x ∈ s₁ → x ∈ s₂ := Iff.rfl #align finset.subset_iff Finset.subset_iff @[simp, norm_cast] theorem coe_subset {s₁ s₂ : Finset α} : (s₁ : Set α) ⊆ s₂ ↔ s₁ ⊆ s₂ := Iff.rfl #align finset.coe_subset Finset.coe_subset @[simp] theorem val_le_iff {s₁ s₂ : Finset α} : s₁.1 ≤ s₂.1 ↔ s₁ ⊆ s₂ := le_iff_subset s₁.2 #align finset.val_le_iff Finset.val_le_iff theorem Subset.antisymm_iff {s₁ s₂ : Finset α} : s₁ = s₂ ↔ s₁ ⊆ s₂ ∧ s₂ ⊆ s₁ := le_antisymm_iff #align finset.subset.antisymm_iff Finset.Subset.antisymm_iff theorem not_subset : ¬s ⊆ t ↔ ∃ x ∈ s, x ∉ t := by simp only [← coe_subset, Set.not_subset, mem_coe] #align finset.not_subset Finset.not_subset @[simp] theorem le_eq_subset : ((· ≤ ·) : Finset α → Finset α → Prop) = (· ⊆ ·) := rfl #align finset.le_eq_subset Finset.le_eq_subset @[simp] theorem lt_eq_subset : ((· < ·) : Finset α → Finset α → Prop) = (· ⊂ ·) := rfl #align finset.lt_eq_subset Finset.lt_eq_subset theorem le_iff_subset {s₁ s₂ : Finset α} : s₁ ≤ s₂ ↔ s₁ ⊆ s₂ := Iff.rfl #align finset.le_iff_subset Finset.le_iff_subset theorem lt_iff_ssubset {s₁ s₂ : Finset α} : s₁ < s₂ ↔ s₁ ⊂ s₂ := Iff.rfl #align finset.lt_iff_ssubset Finset.lt_iff_ssubset @[simp, norm_cast] theorem coe_ssubset {s₁ s₂ : Finset α} : (s₁ : Set α) ⊂ s₂ ↔ s₁ ⊂ s₂ := show (s₁ : Set α) ⊂ s₂ ↔ s₁ ⊆ s₂ ∧ ¬s₂ ⊆ s₁ by simp only [Set.ssubset_def, Finset.coe_subset] #align finset.coe_ssubset Finset.coe_ssubset @[simp] theorem val_lt_iff {s₁ s₂ : Finset α} : s₁.1 < s₂.1 ↔ s₁ ⊂ s₂ := and_congr val_le_iff <| not_congr val_le_iff #align finset.val_lt_iff Finset.val_lt_iff lemma val_strictMono : StrictMono (val : Finset α → Multiset α) := fun _ _ ↦ val_lt_iff.2 theorem ssubset_iff_subset_ne {s t : Finset α} : s ⊂ t ↔ s ⊆ t ∧ s ≠ t := @lt_iff_le_and_ne _ _ s t #align finset.ssubset_iff_subset_ne Finset.ssubset_iff_subset_ne theorem ssubset_iff_of_subset {s₁ s₂ : Finset α} (h : s₁ ⊆ s₂) : s₁ ⊂ s₂ ↔ ∃ x ∈ s₂, x ∉ s₁ := Set.ssubset_iff_of_subset h #align finset.ssubset_iff_of_subset Finset.ssubset_iff_of_subset theorem ssubset_of_ssubset_of_subset {s₁ s₂ s₃ : Finset α} (hs₁s₂ : s₁ ⊂ s₂) (hs₂s₃ : s₂ ⊆ s₃) : s₁ ⊂ s₃ := Set.ssubset_of_ssubset_of_subset hs₁s₂ hs₂s₃ #align finset.ssubset_of_ssubset_of_subset Finset.ssubset_of_ssubset_of_subset theorem ssubset_of_subset_of_ssubset {s₁ s₂ s₃ : Finset α} (hs₁s₂ : s₁ ⊆ s₂) (hs₂s₃ : s₂ ⊂ s₃) : s₁ ⊂ s₃ := Set.ssubset_of_subset_of_ssubset hs₁s₂ hs₂s₃ #align finset.ssubset_of_subset_of_ssubset Finset.ssubset_of_subset_of_ssubset theorem exists_of_ssubset {s₁ s₂ : Finset α} (h : s₁ ⊂ s₂) : ∃ x ∈ s₂, x ∉ s₁ := Set.exists_of_ssubset h #align finset.exists_of_ssubset Finset.exists_of_ssubset instance isWellFounded_ssubset : IsWellFounded (Finset α) (· ⊂ ·) := Subrelation.isWellFounded (InvImage _ _) val_lt_iff.2 #align finset.is_well_founded_ssubset Finset.isWellFounded_ssubset instance wellFoundedLT : WellFoundedLT (Finset α) := Finset.isWellFounded_ssubset #align finset.is_well_founded_lt Finset.wellFoundedLT end Subset -- TODO: these should be global attributes, but this will require fixing other files attribute [local trans] Subset.trans Superset.trans /-! ### Order embedding from `Finset α` to `Set α` -/ /-- Coercion to `Set α` as an `OrderEmbedding`. -/ def coeEmb : Finset α ↪o Set α := ⟨⟨(↑), coe_injective⟩, coe_subset⟩ #align finset.coe_emb Finset.coeEmb @[simp] theorem coe_coeEmb : ⇑(coeEmb : Finset α ↪o Set α) = ((↑) : Finset α → Set α) := rfl #align finset.coe_coe_emb Finset.coe_coeEmb /-! ### Nonempty -/ /-- The property `s.Nonempty` expresses the fact that the finset `s` is not empty. It should be used in theorem assumptions instead of `∃ x, x ∈ s` or `s ≠ ∅` as it gives access to a nice API thanks to the dot notation. -/ protected def Nonempty (s : Finset α) : Prop := ∃ x : α, x ∈ s #align finset.nonempty Finset.Nonempty -- Porting note: Much longer than in Lean3 instance decidableNonempty {s : Finset α} : Decidable s.Nonempty := Quotient.recOnSubsingleton (motive := fun s : Multiset α => Decidable (∃ a, a ∈ s)) s.1 (fun l : List α => match l with | [] => isFalse <| by simp | a::l => isTrue ⟨a, by simp⟩) #align finset.decidable_nonempty Finset.decidableNonempty @[simp, norm_cast] theorem coe_nonempty {s : Finset α} : (s : Set α).Nonempty ↔ s.Nonempty := Iff.rfl #align finset.coe_nonempty Finset.coe_nonempty -- Porting note: Left-hand side simplifies @[simp] theorem nonempty_coe_sort {s : Finset α} : Nonempty (s : Type _) ↔ s.Nonempty := nonempty_subtype #align finset.nonempty_coe_sort Finset.nonempty_coe_sort alias ⟨_, Nonempty.to_set⟩ := coe_nonempty #align finset.nonempty.to_set Finset.Nonempty.to_set alias ⟨_, Nonempty.coe_sort⟩ := nonempty_coe_sort #align finset.nonempty.coe_sort Finset.Nonempty.coe_sort theorem Nonempty.exists_mem {s : Finset α} (h : s.Nonempty) : ∃ x : α, x ∈ s := h #align finset.nonempty.bex Finset.Nonempty.exists_mem @[deprecated (since := "2024-03-23")] alias Nonempty.bex := Nonempty.exists_mem theorem Nonempty.mono {s t : Finset α} (hst : s ⊆ t) (hs : s.Nonempty) : t.Nonempty := Set.Nonempty.mono hst hs #align finset.nonempty.mono Finset.Nonempty.mono theorem Nonempty.forall_const {s : Finset α} (h : s.Nonempty) {p : Prop} : (∀ x ∈ s, p) ↔ p := let ⟨x, hx⟩ := h ⟨fun h => h x hx, fun h _ _ => h⟩ #align finset.nonempty.forall_const Finset.Nonempty.forall_const theorem Nonempty.to_subtype {s : Finset α} : s.Nonempty → Nonempty s := nonempty_coe_sort.2 #align finset.nonempty.to_subtype Finset.Nonempty.to_subtype theorem Nonempty.to_type {s : Finset α} : s.Nonempty → Nonempty α := fun ⟨x, _hx⟩ => ⟨x⟩ #align finset.nonempty.to_type Finset.Nonempty.to_type /-! ### empty -/ section Empty variable {s : Finset α} /-- The empty finset -/ protected def empty : Finset α := ⟨0, nodup_zero⟩ #align finset.empty Finset.empty instance : EmptyCollection (Finset α) := ⟨Finset.empty⟩ instance inhabitedFinset : Inhabited (Finset α) := ⟨∅⟩ #align finset.inhabited_finset Finset.inhabitedFinset @[simp] theorem empty_val : (∅ : Finset α).1 = 0 := rfl #align finset.empty_val Finset.empty_val @[simp] theorem not_mem_empty (a : α) : a ∉ (∅ : Finset α) := by -- Porting note: was `id`. `a ∈ List.nil` is no longer definitionally equal to `False` simp only [mem_def, empty_val, not_mem_zero, not_false_iff] #align finset.not_mem_empty Finset.not_mem_empty @[simp] theorem not_nonempty_empty : ¬(∅ : Finset α).Nonempty := fun ⟨x, hx⟩ => not_mem_empty x hx #align finset.not_nonempty_empty Finset.not_nonempty_empty @[simp] theorem mk_zero : (⟨0, nodup_zero⟩ : Finset α) = ∅ := rfl #align finset.mk_zero Finset.mk_zero theorem ne_empty_of_mem {a : α} {s : Finset α} (h : a ∈ s) : s ≠ ∅ := fun e => not_mem_empty a <| e ▸ h #align finset.ne_empty_of_mem Finset.ne_empty_of_mem theorem Nonempty.ne_empty {s : Finset α} (h : s.Nonempty) : s ≠ ∅ := (Exists.elim h) fun _a => ne_empty_of_mem #align finset.nonempty.ne_empty Finset.Nonempty.ne_empty @[simp] theorem empty_subset (s : Finset α) : ∅ ⊆ s := zero_subset _ #align finset.empty_subset Finset.empty_subset theorem eq_empty_of_forall_not_mem {s : Finset α} (H : ∀ x, x ∉ s) : s = ∅ := eq_of_veq (eq_zero_of_forall_not_mem H) #align finset.eq_empty_of_forall_not_mem Finset.eq_empty_of_forall_not_mem theorem eq_empty_iff_forall_not_mem {s : Finset α} : s = ∅ ↔ ∀ x, x ∉ s := -- Porting note: used `id` ⟨by rintro rfl x; apply not_mem_empty, fun h => eq_empty_of_forall_not_mem h⟩ #align finset.eq_empty_iff_forall_not_mem Finset.eq_empty_iff_forall_not_mem @[simp] theorem val_eq_zero {s : Finset α} : s.1 = 0 ↔ s = ∅ := @val_inj _ s ∅ #align finset.val_eq_zero Finset.val_eq_zero theorem subset_empty {s : Finset α} : s ⊆ ∅ ↔ s = ∅ := subset_zero.trans val_eq_zero #align finset.subset_empty Finset.subset_empty @[simp] theorem not_ssubset_empty (s : Finset α) : ¬s ⊂ ∅ := fun h => let ⟨_, he, _⟩ := exists_of_ssubset h -- Porting note: was `he` not_mem_empty _ he #align finset.not_ssubset_empty Finset.not_ssubset_empty theorem nonempty_of_ne_empty {s : Finset α} (h : s ≠ ∅) : s.Nonempty := exists_mem_of_ne_zero (mt val_eq_zero.1 h) #align finset.nonempty_of_ne_empty Finset.nonempty_of_ne_empty theorem nonempty_iff_ne_empty {s : Finset α} : s.Nonempty ↔ s ≠ ∅ := ⟨Nonempty.ne_empty, nonempty_of_ne_empty⟩ #align finset.nonempty_iff_ne_empty Finset.nonempty_iff_ne_empty @[simp] theorem not_nonempty_iff_eq_empty {s : Finset α} : ¬s.Nonempty ↔ s = ∅ := nonempty_iff_ne_empty.not.trans not_not #align finset.not_nonempty_iff_eq_empty Finset.not_nonempty_iff_eq_empty theorem eq_empty_or_nonempty (s : Finset α) : s = ∅ ∨ s.Nonempty := by_cases Or.inl fun h => Or.inr (nonempty_of_ne_empty h) #align finset.eq_empty_or_nonempty Finset.eq_empty_or_nonempty @[simp, norm_cast] theorem coe_empty : ((∅ : Finset α) : Set α) = ∅ := Set.ext <| by simp #align finset.coe_empty Finset.coe_empty @[simp, norm_cast] theorem coe_eq_empty {s : Finset α} : (s : Set α) = ∅ ↔ s = ∅ := by rw [← coe_empty, coe_inj] #align finset.coe_eq_empty Finset.coe_eq_empty -- Porting note: Left-hand side simplifies @[simp] theorem isEmpty_coe_sort {s : Finset α} : IsEmpty (s : Type _) ↔ s = ∅ := by simpa using @Set.isEmpty_coe_sort α s #align finset.is_empty_coe_sort Finset.isEmpty_coe_sort instance instIsEmpty : IsEmpty (∅ : Finset α) := isEmpty_coe_sort.2 rfl /-- A `Finset` for an empty type is empty. -/ theorem eq_empty_of_isEmpty [IsEmpty α] (s : Finset α) : s = ∅ := Finset.eq_empty_of_forall_not_mem isEmptyElim #align finset.eq_empty_of_is_empty Finset.eq_empty_of_isEmpty instance : OrderBot (Finset α) where bot := ∅ bot_le := empty_subset @[simp] theorem bot_eq_empty : (⊥ : Finset α) = ∅ := rfl #align finset.bot_eq_empty Finset.bot_eq_empty @[simp] theorem empty_ssubset : ∅ ⊂ s ↔ s.Nonempty := (@bot_lt_iff_ne_bot (Finset α) _ _ _).trans nonempty_iff_ne_empty.symm #align finset.empty_ssubset Finset.empty_ssubset alias ⟨_, Nonempty.empty_ssubset⟩ := empty_ssubset #align finset.nonempty.empty_ssubset Finset.Nonempty.empty_ssubset end Empty /-! ### singleton -/ section Singleton variable {s : Finset α} {a b : α} /-- `{a} : Finset a` is the set `{a}` containing `a` and nothing else. This differs from `insert a ∅` in that it does not require a `DecidableEq` instance for `α`. -/ instance : Singleton α (Finset α) := ⟨fun a => ⟨{a}, nodup_singleton a⟩⟩ @[simp] theorem singleton_val (a : α) : ({a} : Finset α).1 = {a} := rfl #align finset.singleton_val Finset.singleton_val @[simp] theorem mem_singleton {a b : α} : b ∈ ({a} : Finset α) ↔ b = a := Multiset.mem_singleton #align finset.mem_singleton Finset.mem_singleton theorem eq_of_mem_singleton {x y : α} (h : x ∈ ({y} : Finset α)) : x = y := mem_singleton.1 h #align finset.eq_of_mem_singleton Finset.eq_of_mem_singleton theorem not_mem_singleton {a b : α} : a ∉ ({b} : Finset α) ↔ a ≠ b := not_congr mem_singleton #align finset.not_mem_singleton Finset.not_mem_singleton theorem mem_singleton_self (a : α) : a ∈ ({a} : Finset α) := -- Porting note: was `Or.inl rfl` mem_singleton.mpr rfl #align finset.mem_singleton_self Finset.mem_singleton_self @[simp] theorem val_eq_singleton_iff {a : α} {s : Finset α} : s.val = {a} ↔ s = {a} := by rw [← val_inj] rfl #align finset.val_eq_singleton_iff Finset.val_eq_singleton_iff theorem singleton_injective : Injective (singleton : α → Finset α) := fun _a _b h => mem_singleton.1 (h ▸ mem_singleton_self _) #align finset.singleton_injective Finset.singleton_injective @[simp] theorem singleton_inj : ({a} : Finset α) = {b} ↔ a = b := singleton_injective.eq_iff #align finset.singleton_inj Finset.singleton_inj @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem singleton_nonempty (a : α) : ({a} : Finset α).Nonempty := ⟨a, mem_singleton_self a⟩ #align finset.singleton_nonempty Finset.singleton_nonempty @[simp] theorem singleton_ne_empty (a : α) : ({a} : Finset α) ≠ ∅ := (singleton_nonempty a).ne_empty #align finset.singleton_ne_empty Finset.singleton_ne_empty theorem empty_ssubset_singleton : (∅ : Finset α) ⊂ {a} := (singleton_nonempty _).empty_ssubset #align finset.empty_ssubset_singleton Finset.empty_ssubset_singleton @[simp, norm_cast] theorem coe_singleton (a : α) : (({a} : Finset α) : Set α) = {a} := by ext simp #align finset.coe_singleton Finset.coe_singleton @[simp, norm_cast] theorem coe_eq_singleton {s : Finset α} {a : α} : (s : Set α) = {a} ↔ s = {a} := by rw [← coe_singleton, coe_inj] #align finset.coe_eq_singleton Finset.coe_eq_singleton @[norm_cast] lemma coe_subset_singleton : (s : Set α) ⊆ {a} ↔ s ⊆ {a} := by rw [← coe_subset, coe_singleton] @[norm_cast] lemma singleton_subset_coe : {a} ⊆ (s : Set α) ↔ {a} ⊆ s := by rw [← coe_subset, coe_singleton] theorem eq_singleton_iff_unique_mem {s : Finset α} {a : α} : s = {a} ↔ a ∈ s ∧ ∀ x ∈ s, x = a := by constructor <;> intro t · rw [t] exact ⟨Finset.mem_singleton_self _, fun _ => Finset.mem_singleton.1⟩ · ext rw [Finset.mem_singleton] exact ⟨t.right _, fun r => r.symm ▸ t.left⟩ #align finset.eq_singleton_iff_unique_mem Finset.eq_singleton_iff_unique_mem theorem eq_singleton_iff_nonempty_unique_mem {s : Finset α} {a : α} : s = {a} ↔ s.Nonempty ∧ ∀ x ∈ s, x = a := by constructor · rintro rfl simp · rintro ⟨hne, h_uniq⟩ rw [eq_singleton_iff_unique_mem] refine ⟨?_, h_uniq⟩ rw [← h_uniq hne.choose hne.choose_spec] exact hne.choose_spec #align finset.eq_singleton_iff_nonempty_unique_mem Finset.eq_singleton_iff_nonempty_unique_mem theorem nonempty_iff_eq_singleton_default [Unique α] {s : Finset α} : s.Nonempty ↔ s = {default} := by simp [eq_singleton_iff_nonempty_unique_mem, eq_iff_true_of_subsingleton] #align finset.nonempty_iff_eq_singleton_default Finset.nonempty_iff_eq_singleton_default alias ⟨Nonempty.eq_singleton_default, _⟩ := nonempty_iff_eq_singleton_default #align finset.nonempty.eq_singleton_default Finset.Nonempty.eq_singleton_default theorem singleton_iff_unique_mem (s : Finset α) : (∃ a, s = {a}) ↔ ∃! a, a ∈ s := by simp only [eq_singleton_iff_unique_mem, ExistsUnique] #align finset.singleton_iff_unique_mem Finset.singleton_iff_unique_mem theorem singleton_subset_set_iff {s : Set α} {a : α} : ↑({a} : Finset α) ⊆ s ↔ a ∈ s := by rw [coe_singleton, Set.singleton_subset_iff] #align finset.singleton_subset_set_iff Finset.singleton_subset_set_iff @[simp] theorem singleton_subset_iff {s : Finset α} {a : α} : {a} ⊆ s ↔ a ∈ s := singleton_subset_set_iff #align finset.singleton_subset_iff Finset.singleton_subset_iff @[simp] theorem subset_singleton_iff {s : Finset α} {a : α} : s ⊆ {a} ↔ s = ∅ ∨ s = {a} := by rw [← coe_subset, coe_singleton, Set.subset_singleton_iff_eq, coe_eq_empty, coe_eq_singleton] #align finset.subset_singleton_iff Finset.subset_singleton_iff theorem singleton_subset_singleton : ({a} : Finset α) ⊆ {b} ↔ a = b := by simp #align finset.singleton_subset_singleton Finset.singleton_subset_singleton protected theorem Nonempty.subset_singleton_iff {s : Finset α} {a : α} (h : s.Nonempty) : s ⊆ {a} ↔ s = {a} := subset_singleton_iff.trans <| or_iff_right h.ne_empty #align finset.nonempty.subset_singleton_iff Finset.Nonempty.subset_singleton_iff theorem subset_singleton_iff' {s : Finset α} {a : α} : s ⊆ {a} ↔ ∀ b ∈ s, b = a := forall₂_congr fun _ _ => mem_singleton #align finset.subset_singleton_iff' Finset.subset_singleton_iff' @[simp] theorem ssubset_singleton_iff {s : Finset α} {a : α} : s ⊂ {a} ↔ s = ∅ := by rw [← coe_ssubset, coe_singleton, Set.ssubset_singleton_iff, coe_eq_empty] #align finset.ssubset_singleton_iff Finset.ssubset_singleton_iff theorem eq_empty_of_ssubset_singleton {s : Finset α} {x : α} (hs : s ⊂ {x}) : s = ∅ := ssubset_singleton_iff.1 hs #align finset.eq_empty_of_ssubset_singleton Finset.eq_empty_of_ssubset_singleton /-- A finset is nontrivial if it has at least two elements. -/ protected abbrev Nontrivial (s : Finset α) : Prop := (s : Set α).Nontrivial #align finset.nontrivial Finset.Nontrivial @[simp] theorem not_nontrivial_empty : ¬ (∅ : Finset α).Nontrivial := by simp [Finset.Nontrivial] #align finset.not_nontrivial_empty Finset.not_nontrivial_empty @[simp] theorem not_nontrivial_singleton : ¬ ({a} : Finset α).Nontrivial := by simp [Finset.Nontrivial] #align finset.not_nontrivial_singleton Finset.not_nontrivial_singleton theorem Nontrivial.ne_singleton (hs : s.Nontrivial) : s ≠ {a} := by rintro rfl; exact not_nontrivial_singleton hs #align finset.nontrivial.ne_singleton Finset.Nontrivial.ne_singleton nonrec lemma Nontrivial.exists_ne (hs : s.Nontrivial) (a : α) : ∃ b ∈ s, b ≠ a := hs.exists_ne _ theorem eq_singleton_or_nontrivial (ha : a ∈ s) : s = {a} ∨ s.Nontrivial := by rw [← coe_eq_singleton]; exact Set.eq_singleton_or_nontrivial ha #align finset.eq_singleton_or_nontrivial Finset.eq_singleton_or_nontrivial theorem nontrivial_iff_ne_singleton (ha : a ∈ s) : s.Nontrivial ↔ s ≠ {a} := ⟨Nontrivial.ne_singleton, (eq_singleton_or_nontrivial ha).resolve_left⟩ #align finset.nontrivial_iff_ne_singleton Finset.nontrivial_iff_ne_singleton theorem Nonempty.exists_eq_singleton_or_nontrivial : s.Nonempty → (∃ a, s = {a}) ∨ s.Nontrivial := fun ⟨a, ha⟩ => (eq_singleton_or_nontrivial ha).imp_left <| Exists.intro a #align finset.nonempty.exists_eq_singleton_or_nontrivial Finset.Nonempty.exists_eq_singleton_or_nontrivial instance instNontrivial [Nonempty α] : Nontrivial (Finset α) := ‹Nonempty α›.elim fun a => ⟨⟨{a}, ∅, singleton_ne_empty _⟩⟩ #align finset.nontrivial' Finset.instNontrivial instance [IsEmpty α] : Unique (Finset α) where default := ∅ uniq _ := eq_empty_of_forall_not_mem isEmptyElim instance (i : α) : Unique ({i} : Finset α) where default := ⟨i, mem_singleton_self i⟩ uniq j := Subtype.ext <| mem_singleton.mp j.2 @[simp] lemma default_singleton (i : α) : ((default : ({i} : Finset α)) : α) = i := rfl end Singleton /-! ### cons -/ section Cons variable {s t : Finset α} {a b : α} /-- `cons a s h` is the set `{a} ∪ s` containing `a` and the elements of `s`. It is the same as `insert a s` when it is defined, but unlike `insert a s` it does not require `DecidableEq α`, and the union is guaranteed to be disjoint. -/ def cons (a : α) (s : Finset α) (h : a ∉ s) : Finset α := ⟨a ::ₘ s.1, nodup_cons.2 ⟨h, s.2⟩⟩ #align finset.cons Finset.cons @[simp] theorem mem_cons {h} : b ∈ s.cons a h ↔ b = a ∨ b ∈ s := Multiset.mem_cons #align finset.mem_cons Finset.mem_cons theorem mem_cons_of_mem {a b : α} {s : Finset α} {hb : b ∉ s} (ha : a ∈ s) : a ∈ cons b s hb := Multiset.mem_cons_of_mem ha -- Porting note (#10618): @[simp] can prove this theorem mem_cons_self (a : α) (s : Finset α) {h} : a ∈ cons a s h := Multiset.mem_cons_self _ _ #align finset.mem_cons_self Finset.mem_cons_self @[simp] theorem cons_val (h : a ∉ s) : (cons a s h).1 = a ::ₘ s.1 := rfl #align finset.cons_val Finset.cons_val theorem forall_mem_cons (h : a ∉ s) (p : α → Prop) : (∀ x, x ∈ cons a s h → p x) ↔ p a ∧ ∀ x, x ∈ s → p x := by simp only [mem_cons, or_imp, forall_and, forall_eq] #align finset.forall_mem_cons Finset.forall_mem_cons /-- Useful in proofs by induction. -/ theorem forall_of_forall_cons {p : α → Prop} {h : a ∉ s} (H : ∀ x, x ∈ cons a s h → p x) (x) (h : x ∈ s) : p x := H _ <| mem_cons.2 <| Or.inr h #align finset.forall_of_forall_cons Finset.forall_of_forall_cons @[simp] theorem mk_cons {s : Multiset α} (h : (a ::ₘ s).Nodup) : (⟨a ::ₘ s, h⟩ : Finset α) = cons a ⟨s, (nodup_cons.1 h).2⟩ (nodup_cons.1 h).1 := rfl #align finset.mk_cons Finset.mk_cons @[simp] theorem cons_empty (a : α) : cons a ∅ (not_mem_empty _) = {a} := rfl #align finset.cons_empty Finset.cons_empty @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem nonempty_cons (h : a ∉ s) : (cons a s h).Nonempty := ⟨a, mem_cons.2 <| Or.inl rfl⟩ #align finset.nonempty_cons Finset.nonempty_cons @[simp] theorem nonempty_mk {m : Multiset α} {hm} : (⟨m, hm⟩ : Finset α).Nonempty ↔ m ≠ 0 := by induction m using Multiset.induction_on <;> simp #align finset.nonempty_mk Finset.nonempty_mk @[simp] theorem coe_cons {a s h} : (@cons α a s h : Set α) = insert a (s : Set α) := by ext simp #align finset.coe_cons Finset.coe_cons theorem subset_cons (h : a ∉ s) : s ⊆ s.cons a h := Multiset.subset_cons _ _ #align finset.subset_cons Finset.subset_cons theorem ssubset_cons (h : a ∉ s) : s ⊂ s.cons a h := Multiset.ssubset_cons h #align finset.ssubset_cons Finset.ssubset_cons theorem cons_subset {h : a ∉ s} : s.cons a h ⊆ t ↔ a ∈ t ∧ s ⊆ t := Multiset.cons_subset #align finset.cons_subset Finset.cons_subset @[simp] theorem cons_subset_cons {hs ht} : s.cons a hs ⊆ t.cons a ht ↔ s ⊆ t := by rwa [← coe_subset, coe_cons, coe_cons, Set.insert_subset_insert_iff, coe_subset] #align finset.cons_subset_cons Finset.cons_subset_cons theorem ssubset_iff_exists_cons_subset : s ⊂ t ↔ ∃ (a : _) (h : a ∉ s), s.cons a h ⊆ t := by refine ⟨fun h => ?_, fun ⟨a, ha, h⟩ => ssubset_of_ssubset_of_subset (ssubset_cons _) h⟩ obtain ⟨a, hs, ht⟩ := not_subset.1 h.2 exact ⟨a, ht, cons_subset.2 ⟨hs, h.subset⟩⟩ #align finset.ssubset_iff_exists_cons_subset Finset.ssubset_iff_exists_cons_subset end Cons /-! ### disjoint -/ section Disjoint variable {f : α → β} {s t u : Finset α} {a b : α} theorem disjoint_left : Disjoint s t ↔ ∀ ⦃a⦄, a ∈ s → a ∉ t := ⟨fun h a hs ht => not_mem_empty a <| singleton_subset_iff.mp (h (singleton_subset_iff.mpr hs) (singleton_subset_iff.mpr ht)), fun h _ hs ht _ ha => (h (hs ha) (ht ha)).elim⟩ #align finset.disjoint_left Finset.disjoint_left theorem disjoint_right : Disjoint s t ↔ ∀ ⦃a⦄, a ∈ t → a ∉ s := by rw [_root_.disjoint_comm, disjoint_left] #align finset.disjoint_right Finset.disjoint_right theorem disjoint_iff_ne : Disjoint s t ↔ ∀ a ∈ s, ∀ b ∈ t, a ≠ b := by simp only [disjoint_left, imp_not_comm, forall_eq'] #align finset.disjoint_iff_ne Finset.disjoint_iff_ne @[simp] theorem disjoint_val : s.1.Disjoint t.1 ↔ Disjoint s t := disjoint_left.symm #align finset.disjoint_val Finset.disjoint_val theorem _root_.Disjoint.forall_ne_finset (h : Disjoint s t) (ha : a ∈ s) (hb : b ∈ t) : a ≠ b := disjoint_iff_ne.1 h _ ha _ hb #align disjoint.forall_ne_finset Disjoint.forall_ne_finset theorem not_disjoint_iff : ¬Disjoint s t ↔ ∃ a, a ∈ s ∧ a ∈ t := disjoint_left.not.trans <| not_forall.trans <| exists_congr fun _ => by rw [Classical.not_imp, not_not] #align finset.not_disjoint_iff Finset.not_disjoint_iff theorem disjoint_of_subset_left (h : s ⊆ u) (d : Disjoint u t) : Disjoint s t := disjoint_left.2 fun _x m₁ => (disjoint_left.1 d) (h m₁) #align finset.disjoint_of_subset_left Finset.disjoint_of_subset_left theorem disjoint_of_subset_right (h : t ⊆ u) (d : Disjoint s u) : Disjoint s t := disjoint_right.2 fun _x m₁ => (disjoint_right.1 d) (h m₁) #align finset.disjoint_of_subset_right Finset.disjoint_of_subset_right @[simp] theorem disjoint_empty_left (s : Finset α) : Disjoint ∅ s := disjoint_bot_left #align finset.disjoint_empty_left Finset.disjoint_empty_left @[simp] theorem disjoint_empty_right (s : Finset α) : Disjoint s ∅ := disjoint_bot_right #align finset.disjoint_empty_right Finset.disjoint_empty_right @[simp] theorem disjoint_singleton_left : Disjoint (singleton a) s ↔ a ∉ s := by simp only [disjoint_left, mem_singleton, forall_eq] #align finset.disjoint_singleton_left Finset.disjoint_singleton_left @[simp] theorem disjoint_singleton_right : Disjoint s (singleton a) ↔ a ∉ s := disjoint_comm.trans disjoint_singleton_left #align finset.disjoint_singleton_right Finset.disjoint_singleton_right -- Porting note: Left-hand side simplifies @[simp] theorem disjoint_singleton : Disjoint ({a} : Finset α) {b} ↔ a ≠ b := by rw [disjoint_singleton_left, mem_singleton] #align finset.disjoint_singleton Finset.disjoint_singleton theorem disjoint_self_iff_empty (s : Finset α) : Disjoint s s ↔ s = ∅ := disjoint_self #align finset.disjoint_self_iff_empty Finset.disjoint_self_iff_empty @[simp, norm_cast] theorem disjoint_coe : Disjoint (s : Set α) t ↔ Disjoint s t := by simp only [Finset.disjoint_left, Set.disjoint_left, mem_coe] #align finset.disjoint_coe Finset.disjoint_coe @[simp, norm_cast] theorem pairwiseDisjoint_coe {ι : Type*} {s : Set ι} {f : ι → Finset α} : s.PairwiseDisjoint (fun i => f i : ι → Set α) ↔ s.PairwiseDisjoint f := forall₅_congr fun _ _ _ _ _ => disjoint_coe #align finset.pairwise_disjoint_coe Finset.pairwiseDisjoint_coe end Disjoint /-! ### disjoint union -/ /-- `disjUnion s t h` is the set such that `a ∈ disjUnion s t h` iff `a ∈ s` or `a ∈ t`. It is the same as `s ∪ t`, but it does not require decidable equality on the type. The hypothesis ensures that the sets are disjoint. -/ def disjUnion (s t : Finset α) (h : Disjoint s t) : Finset α := ⟨s.1 + t.1, Multiset.nodup_add.2 ⟨s.2, t.2, disjoint_val.2 h⟩⟩ #align finset.disj_union Finset.disjUnion @[simp] theorem mem_disjUnion {α s t h a} : a ∈ @disjUnion α s t h ↔ a ∈ s ∨ a ∈ t := by rcases s with ⟨⟨s⟩⟩; rcases t with ⟨⟨t⟩⟩; apply List.mem_append #align finset.mem_disj_union Finset.mem_disjUnion @[simp, norm_cast] theorem coe_disjUnion {s t : Finset α} (h : Disjoint s t) : (disjUnion s t h : Set α) = (s : Set α) ∪ t := Set.ext <| by simp theorem disjUnion_comm (s t : Finset α) (h : Disjoint s t) : disjUnion s t h = disjUnion t s h.symm := eq_of_veq <| add_comm _ _ #align finset.disj_union_comm Finset.disjUnion_comm @[simp] theorem empty_disjUnion (t : Finset α) (h : Disjoint ∅ t := disjoint_bot_left) : disjUnion ∅ t h = t := eq_of_veq <| zero_add _ #align finset.empty_disj_union Finset.empty_disjUnion @[simp] theorem disjUnion_empty (s : Finset α) (h : Disjoint s ∅ := disjoint_bot_right) : disjUnion s ∅ h = s := eq_of_veq <| add_zero _ #align finset.disj_union_empty Finset.disjUnion_empty theorem singleton_disjUnion (a : α) (t : Finset α) (h : Disjoint {a} t) : disjUnion {a} t h = cons a t (disjoint_singleton_left.mp h) := eq_of_veq <| Multiset.singleton_add _ _ #align finset.singleton_disj_union Finset.singleton_disjUnion theorem disjUnion_singleton (s : Finset α) (a : α) (h : Disjoint s {a}) : disjUnion s {a} h = cons a s (disjoint_singleton_right.mp h) := by rw [disjUnion_comm, singleton_disjUnion] #align finset.disj_union_singleton Finset.disjUnion_singleton /-! ### insert -/ section Insert variable [DecidableEq α] {s t u v : Finset α} {a b : α} /-- `insert a s` is the set `{a} ∪ s` containing `a` and the elements of `s`. -/ instance : Insert α (Finset α) := ⟨fun a s => ⟨_, s.2.ndinsert a⟩⟩ theorem insert_def (a : α) (s : Finset α) : insert a s = ⟨_, s.2.ndinsert a⟩ := rfl #align finset.insert_def Finset.insert_def @[simp] theorem insert_val (a : α) (s : Finset α) : (insert a s).1 = ndinsert a s.1 := rfl #align finset.insert_val Finset.insert_val theorem insert_val' (a : α) (s : Finset α) : (insert a s).1 = dedup (a ::ₘ s.1) := by rw [dedup_cons, dedup_eq_self]; rfl #align finset.insert_val' Finset.insert_val' theorem insert_val_of_not_mem {a : α} {s : Finset α} (h : a ∉ s) : (insert a s).1 = a ::ₘ s.1 := by rw [insert_val, ndinsert_of_not_mem h] #align finset.insert_val_of_not_mem Finset.insert_val_of_not_mem @[simp] theorem mem_insert : a ∈ insert b s ↔ a = b ∨ a ∈ s := mem_ndinsert #align finset.mem_insert Finset.mem_insert theorem mem_insert_self (a : α) (s : Finset α) : a ∈ insert a s := mem_ndinsert_self a s.1 #align finset.mem_insert_self Finset.mem_insert_self theorem mem_insert_of_mem (h : a ∈ s) : a ∈ insert b s := mem_ndinsert_of_mem h #align finset.mem_insert_of_mem Finset.mem_insert_of_mem theorem mem_of_mem_insert_of_ne (h : b ∈ insert a s) : b ≠ a → b ∈ s := (mem_insert.1 h).resolve_left #align finset.mem_of_mem_insert_of_ne Finset.mem_of_mem_insert_of_ne theorem eq_of_not_mem_of_mem_insert (ha : b ∈ insert a s) (hb : b ∉ s) : b = a := (mem_insert.1 ha).resolve_right hb #align finset.eq_of_not_mem_of_mem_insert Finset.eq_of_not_mem_of_mem_insert /-- A version of `LawfulSingleton.insert_emptyc_eq` that works with `dsimp`. -/ @[simp, nolint simpNF] lemma insert_empty : insert a (∅ : Finset α) = {a} := rfl @[simp] theorem cons_eq_insert (a s h) : @cons α a s h = insert a s := ext fun a => by simp #align finset.cons_eq_insert Finset.cons_eq_insert @[simp, norm_cast] theorem coe_insert (a : α) (s : Finset α) : ↑(insert a s) = (insert a s : Set α) := Set.ext fun x => by simp only [mem_coe, mem_insert, Set.mem_insert_iff] #align finset.coe_insert Finset.coe_insert theorem mem_insert_coe {s : Finset α} {x y : α} : x ∈ insert y s ↔ x ∈ insert y (s : Set α) := by simp #align finset.mem_insert_coe Finset.mem_insert_coe instance : LawfulSingleton α (Finset α) := ⟨fun a => by ext; simp⟩ @[simp] theorem insert_eq_of_mem (h : a ∈ s) : insert a s = s := eq_of_veq <| ndinsert_of_mem h #align finset.insert_eq_of_mem Finset.insert_eq_of_mem @[simp] theorem insert_eq_self : insert a s = s ↔ a ∈ s := ⟨fun h => h ▸ mem_insert_self _ _, insert_eq_of_mem⟩ #align finset.insert_eq_self Finset.insert_eq_self theorem insert_ne_self : insert a s ≠ s ↔ a ∉ s := insert_eq_self.not #align finset.insert_ne_self Finset.insert_ne_self -- Porting note (#10618): @[simp] can prove this theorem pair_eq_singleton (a : α) : ({a, a} : Finset α) = {a} := insert_eq_of_mem <| mem_singleton_self _ #align finset.pair_eq_singleton Finset.pair_eq_singleton theorem Insert.comm (a b : α) (s : Finset α) : insert a (insert b s) = insert b (insert a s) := ext fun x => by simp only [mem_insert, or_left_comm] #align finset.insert.comm Finset.Insert.comm -- Porting note (#10618): @[simp] can prove this @[norm_cast] theorem coe_pair {a b : α} : (({a, b} : Finset α) : Set α) = {a, b} := by ext simp #align finset.coe_pair Finset.coe_pair @[simp, norm_cast] theorem coe_eq_pair {s : Finset α} {a b : α} : (s : Set α) = {a, b} ↔ s = {a, b} := by rw [← coe_pair, coe_inj] #align finset.coe_eq_pair Finset.coe_eq_pair theorem pair_comm (a b : α) : ({a, b} : Finset α) = {b, a} := Insert.comm a b ∅ #align finset.pair_comm Finset.pair_comm -- Porting note (#10618): @[simp] can prove this theorem insert_idem (a : α) (s : Finset α) : insert a (insert a s) = insert a s := ext fun x => by simp only [mem_insert, ← or_assoc, or_self_iff] #align finset.insert_idem Finset.insert_idem @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem insert_nonempty (a : α) (s : Finset α) : (insert a s).Nonempty := ⟨a, mem_insert_self a s⟩ #align finset.insert_nonempty Finset.insert_nonempty @[simp] theorem insert_ne_empty (a : α) (s : Finset α) : insert a s ≠ ∅ := (insert_nonempty a s).ne_empty #align finset.insert_ne_empty Finset.insert_ne_empty -- Porting note: explicit universe annotation is no longer required. instance (i : α) (s : Finset α) : Nonempty ((insert i s : Finset α) : Set α) := (Finset.coe_nonempty.mpr (s.insert_nonempty i)).to_subtype theorem ne_insert_of_not_mem (s t : Finset α) {a : α} (h : a ∉ s) : s ≠ insert a t := by contrapose! h simp [h] #align finset.ne_insert_of_not_mem Finset.ne_insert_of_not_mem theorem insert_subset_iff : insert a s ⊆ t ↔ a ∈ t ∧ s ⊆ t := by simp only [subset_iff, mem_insert, forall_eq, or_imp, forall_and] #align finset.insert_subset Finset.insert_subset_iff theorem insert_subset (ha : a ∈ t) (hs : s ⊆ t) : insert a s ⊆ t := insert_subset_iff.mpr ⟨ha,hs⟩ @[simp] theorem subset_insert (a : α) (s : Finset α) : s ⊆ insert a s := fun _b => mem_insert_of_mem #align finset.subset_insert Finset.subset_insert @[gcongr] theorem insert_subset_insert (a : α) {s t : Finset α} (h : s ⊆ t) : insert a s ⊆ insert a t := insert_subset_iff.2 ⟨mem_insert_self _ _, Subset.trans h (subset_insert _ _)⟩ #align finset.insert_subset_insert Finset.insert_subset_insert @[simp] lemma insert_subset_insert_iff (ha : a ∉ s) : insert a s ⊆ insert a t ↔ s ⊆ t := by simp_rw [← coe_subset]; simp [-coe_subset, ha] theorem insert_inj (ha : a ∉ s) : insert a s = insert b s ↔ a = b := ⟨fun h => eq_of_not_mem_of_mem_insert (h.subst <| mem_insert_self _ _) ha, congr_arg (insert · s)⟩ #align finset.insert_inj Finset.insert_inj theorem insert_inj_on (s : Finset α) : Set.InjOn (fun a => insert a s) sᶜ := fun _ h _ _ => (insert_inj h).1 #align finset.insert_inj_on Finset.insert_inj_on theorem ssubset_iff : s ⊂ t ↔ ∃ a ∉ s, insert a s ⊆ t := mod_cast @Set.ssubset_iff_insert α s t #align finset.ssubset_iff Finset.ssubset_iff theorem ssubset_insert (h : a ∉ s) : s ⊂ insert a s := ssubset_iff.mpr ⟨a, h, Subset.rfl⟩ #align finset.ssubset_insert Finset.ssubset_insert @[elab_as_elim] theorem cons_induction {α : Type*} {p : Finset α → Prop} (empty : p ∅) (cons : ∀ (a : α) (s : Finset α) (h : a ∉ s), p s → p (cons a s h)) : ∀ s, p s | ⟨s, nd⟩ => by induction s using Multiset.induction with | empty => exact empty | cons a s IH => rw [mk_cons nd] exact cons a _ _ (IH _) #align finset.cons_induction Finset.cons_induction @[elab_as_elim] theorem cons_induction_on {α : Type*} {p : Finset α → Prop} (s : Finset α) (h₁ : p ∅) (h₂ : ∀ ⦃a : α⦄ {s : Finset α} (h : a ∉ s), p s → p (cons a s h)) : p s := cons_induction h₁ h₂ s #align finset.cons_induction_on Finset.cons_induction_on @[elab_as_elim] protected theorem induction {α : Type*} {p : Finset α → Prop} [DecidableEq α] (empty : p ∅) (insert : ∀ ⦃a : α⦄ {s : Finset α}, a ∉ s → p s → p (insert a s)) : ∀ s, p s := cons_induction empty fun a s ha => (s.cons_eq_insert a ha).symm ▸ insert ha #align finset.induction Finset.induction /-- To prove a proposition about an arbitrary `Finset α`, it suffices to prove it for the empty `Finset`, and to show that if it holds for some `Finset α`, then it holds for the `Finset` obtained by inserting a new element. -/ @[elab_as_elim] protected theorem induction_on {α : Type*} {p : Finset α → Prop} [DecidableEq α] (s : Finset α) (empty : p ∅) (insert : ∀ ⦃a : α⦄ {s : Finset α}, a ∉ s → p s → p (insert a s)) : p s := Finset.induction empty insert s #align finset.induction_on Finset.induction_on /-- To prove a proposition about `S : Finset α`, it suffices to prove it for the empty `Finset`, and to show that if it holds for some `Finset α ⊆ S`, then it holds for the `Finset` obtained by inserting a new element of `S`. -/ @[elab_as_elim] theorem induction_on' {α : Type*} {p : Finset α → Prop} [DecidableEq α] (S : Finset α) (h₁ : p ∅) (h₂ : ∀ {a s}, a ∈ S → s ⊆ S → a ∉ s → p s → p (insert a s)) : p S := @Finset.induction_on α (fun T => T ⊆ S → p T) _ S (fun _ => h₁) (fun _ _ has hqs hs => let ⟨hS, sS⟩ := Finset.insert_subset_iff.1 hs h₂ hS sS has (hqs sS)) (Finset.Subset.refl S) #align finset.induction_on' Finset.induction_on' /-- To prove a proposition about a nonempty `s : Finset α`, it suffices to show it holds for all singletons and that if it holds for nonempty `t : Finset α`, then it also holds for the `Finset` obtained by inserting an element in `t`. -/ @[elab_as_elim] theorem Nonempty.cons_induction {α : Type*} {p : ∀ s : Finset α, s.Nonempty → Prop} (singleton : ∀ a, p {a} (singleton_nonempty _)) (cons : ∀ a s (h : a ∉ s) (hs), p s hs → p (Finset.cons a s h) (nonempty_cons h)) {s : Finset α} (hs : s.Nonempty) : p s hs := by induction s using Finset.cons_induction with | empty => exact (not_nonempty_empty hs).elim | cons a t ha h => obtain rfl | ht := t.eq_empty_or_nonempty · exact singleton a · exact cons a t ha ht (h ht) #align finset.nonempty.cons_induction Finset.Nonempty.cons_induction lemma Nonempty.exists_cons_eq (hs : s.Nonempty) : ∃ t a ha, cons a t ha = s := hs.cons_induction (fun a ↦ ⟨∅, a, _, cons_empty _⟩) fun _ _ _ _ _ ↦ ⟨_, _, _, rfl⟩ /-- Inserting an element to a finite set is equivalent to the option type. -/ def subtypeInsertEquivOption {t : Finset α} {x : α} (h : x ∉ t) : { i // i ∈ insert x t } ≃ Option { i // i ∈ t } where toFun y := if h : ↑y = x then none else some ⟨y, (mem_insert.mp y.2).resolve_left h⟩ invFun y := (y.elim ⟨x, mem_insert_self _ _⟩) fun z => ⟨z, mem_insert_of_mem z.2⟩ left_inv y := by by_cases h : ↑y = x · simp only [Subtype.ext_iff, h, Option.elim, dif_pos, Subtype.coe_mk] · simp only [h, Option.elim, dif_neg, not_false_iff, Subtype.coe_eta, Subtype.coe_mk] right_inv := by rintro (_ | y) · simp only [Option.elim, dif_pos] · have : ↑y ≠ x := by rintro ⟨⟩ exact h y.2 simp only [this, Option.elim, Subtype.eta, dif_neg, not_false_iff, Subtype.coe_mk] #align finset.subtype_insert_equiv_option Finset.subtypeInsertEquivOption @[simp] theorem disjoint_insert_left : Disjoint (insert a s) t ↔ a ∉ t ∧ Disjoint s t := by simp only [disjoint_left, mem_insert, or_imp, forall_and, forall_eq] #align finset.disjoint_insert_left Finset.disjoint_insert_left @[simp] theorem disjoint_insert_right : Disjoint s (insert a t) ↔ a ∉ s ∧ Disjoint s t := disjoint_comm.trans <| by rw [disjoint_insert_left, _root_.disjoint_comm] #align finset.disjoint_insert_right Finset.disjoint_insert_right end Insert /-! ### Lattice structure -/ section Lattice variable [DecidableEq α] {s s₁ s₂ t t₁ t₂ u v : Finset α} {a b : α} /-- `s ∪ t` is the set such that `a ∈ s ∪ t` iff `a ∈ s` or `a ∈ t`. -/ instance : Union (Finset α) := ⟨fun s t => ⟨_, t.2.ndunion s.1⟩⟩ /-- `s ∩ t` is the set such that `a ∈ s ∩ t` iff `a ∈ s` and `a ∈ t`. -/ instance : Inter (Finset α) := ⟨fun s t => ⟨_, s.2.ndinter t.1⟩⟩ instance : Lattice (Finset α) := { Finset.partialOrder with sup := (· ∪ ·) sup_le := fun _ _ _ hs ht _ ha => (mem_ndunion.1 ha).elim (fun h => hs h) fun h => ht h le_sup_left := fun _ _ _ h => mem_ndunion.2 <| Or.inl h le_sup_right := fun _ _ _ h => mem_ndunion.2 <| Or.inr h inf := (· ∩ ·) le_inf := fun _ _ _ ht hu _ h => mem_ndinter.2 ⟨ht h, hu h⟩ inf_le_left := fun _ _ _ h => (mem_ndinter.1 h).1 inf_le_right := fun _ _ _ h => (mem_ndinter.1 h).2 } @[simp] theorem sup_eq_union : (Sup.sup : Finset α → Finset α → Finset α) = Union.union := rfl #align finset.sup_eq_union Finset.sup_eq_union @[simp] theorem inf_eq_inter : (Inf.inf : Finset α → Finset α → Finset α) = Inter.inter := rfl #align finset.inf_eq_inter Finset.inf_eq_inter theorem disjoint_iff_inter_eq_empty : Disjoint s t ↔ s ∩ t = ∅ := disjoint_iff #align finset.disjoint_iff_inter_eq_empty Finset.disjoint_iff_inter_eq_empty instance decidableDisjoint (U V : Finset α) : Decidable (Disjoint U V) := decidable_of_iff _ disjoint_left.symm #align finset.decidable_disjoint Finset.decidableDisjoint /-! #### union -/ theorem union_val_nd (s t : Finset α) : (s ∪ t).1 = ndunion s.1 t.1 := rfl #align finset.union_val_nd Finset.union_val_nd @[simp] theorem union_val (s t : Finset α) : (s ∪ t).1 = s.1 ∪ t.1 := ndunion_eq_union s.2 #align finset.union_val Finset.union_val @[simp] theorem mem_union : a ∈ s ∪ t ↔ a ∈ s ∨ a ∈ t := mem_ndunion #align finset.mem_union Finset.mem_union @[simp] theorem disjUnion_eq_union (s t h) : @disjUnion α s t h = s ∪ t := ext fun a => by simp #align finset.disj_union_eq_union Finset.disjUnion_eq_union theorem mem_union_left (t : Finset α) (h : a ∈ s) : a ∈ s ∪ t := mem_union.2 <| Or.inl h #align finset.mem_union_left Finset.mem_union_left theorem mem_union_right (s : Finset α) (h : a ∈ t) : a ∈ s ∪ t := mem_union.2 <| Or.inr h #align finset.mem_union_right Finset.mem_union_right theorem forall_mem_union {p : α → Prop} : (∀ a ∈ s ∪ t, p a) ↔ (∀ a ∈ s, p a) ∧ ∀ a ∈ t, p a := ⟨fun h => ⟨fun a => h a ∘ mem_union_left _, fun b => h b ∘ mem_union_right _⟩, fun h _ab hab => (mem_union.mp hab).elim (h.1 _) (h.2 _)⟩ #align finset.forall_mem_union Finset.forall_mem_union theorem not_mem_union : a ∉ s ∪ t ↔ a ∉ s ∧ a ∉ t := by rw [mem_union, not_or] #align finset.not_mem_union Finset.not_mem_union @[simp, norm_cast] theorem coe_union (s₁ s₂ : Finset α) : ↑(s₁ ∪ s₂) = (s₁ ∪ s₂ : Set α) := Set.ext fun _ => mem_union #align finset.coe_union Finset.coe_union theorem union_subset (hs : s ⊆ u) : t ⊆ u → s ∪ t ⊆ u := sup_le <| le_iff_subset.2 hs #align finset.union_subset Finset.union_subset theorem subset_union_left {s₁ s₂ : Finset α} : s₁ ⊆ s₁ ∪ s₂ := fun _x => mem_union_left _ #align finset.subset_union_left Finset.subset_union_left theorem subset_union_right {s₁ s₂ : Finset α} : s₂ ⊆ s₁ ∪ s₂ := fun _x => mem_union_right _ #align finset.subset_union_right Finset.subset_union_right @[gcongr] theorem union_subset_union (hsu : s ⊆ u) (htv : t ⊆ v) : s ∪ t ⊆ u ∪ v := sup_le_sup (le_iff_subset.2 hsu) htv #align finset.union_subset_union Finset.union_subset_union @[gcongr] theorem union_subset_union_left (h : s₁ ⊆ s₂) : s₁ ∪ t ⊆ s₂ ∪ t := union_subset_union h Subset.rfl #align finset.union_subset_union_left Finset.union_subset_union_left @[gcongr] theorem union_subset_union_right (h : t₁ ⊆ t₂) : s ∪ t₁ ⊆ s ∪ t₂ := union_subset_union Subset.rfl h #align finset.union_subset_union_right Finset.union_subset_union_right theorem union_comm (s₁ s₂ : Finset α) : s₁ ∪ s₂ = s₂ ∪ s₁ := sup_comm _ _ #align finset.union_comm Finset.union_comm instance : Std.Commutative (α := Finset α) (· ∪ ·) := ⟨union_comm⟩ @[simp] theorem union_assoc (s₁ s₂ s₃ : Finset α) : s₁ ∪ s₂ ∪ s₃ = s₁ ∪ (s₂ ∪ s₃) := sup_assoc _ _ _ #align finset.union_assoc Finset.union_assoc instance : Std.Associative (α := Finset α) (· ∪ ·) := ⟨union_assoc⟩ @[simp] theorem union_idempotent (s : Finset α) : s ∪ s = s := sup_idem _ #align finset.union_idempotent Finset.union_idempotent instance : Std.IdempotentOp (α := Finset α) (· ∪ ·) := ⟨union_idempotent⟩ theorem union_subset_left (h : s ∪ t ⊆ u) : s ⊆ u := subset_union_left.trans h #align finset.union_subset_left Finset.union_subset_left theorem union_subset_right {s t u : Finset α} (h : s ∪ t ⊆ u) : t ⊆ u := Subset.trans subset_union_right h #align finset.union_subset_right Finset.union_subset_right theorem union_left_comm (s t u : Finset α) : s ∪ (t ∪ u) = t ∪ (s ∪ u) := ext fun _ => by simp only [mem_union, or_left_comm] #align finset.union_left_comm Finset.union_left_comm theorem union_right_comm (s t u : Finset α) : s ∪ t ∪ u = s ∪ u ∪ t := ext fun x => by simp only [mem_union, or_assoc, @or_comm (x ∈ t)] #align finset.union_right_comm Finset.union_right_comm theorem union_self (s : Finset α) : s ∪ s = s := union_idempotent s #align finset.union_self Finset.union_self @[simp] theorem union_empty (s : Finset α) : s ∪ ∅ = s := ext fun x => mem_union.trans <| by simp #align finset.union_empty Finset.union_empty @[simp] theorem empty_union (s : Finset α) : ∅ ∪ s = s := ext fun x => mem_union.trans <| by simp #align finset.empty_union Finset.empty_union @[aesop unsafe apply (rule_sets := [finsetNonempty])] theorem Nonempty.inl {s t : Finset α} (h : s.Nonempty) : (s ∪ t).Nonempty := h.mono subset_union_left @[aesop unsafe apply (rule_sets := [finsetNonempty])] theorem Nonempty.inr {s t : Finset α} (h : t.Nonempty) : (s ∪ t).Nonempty := h.mono subset_union_right theorem insert_eq (a : α) (s : Finset α) : insert a s = {a} ∪ s := rfl #align finset.insert_eq Finset.insert_eq @[simp] theorem insert_union (a : α) (s t : Finset α) : insert a s ∪ t = insert a (s ∪ t) := by simp only [insert_eq, union_assoc] #align finset.insert_union Finset.insert_union @[simp] theorem union_insert (a : α) (s t : Finset α) : s ∪ insert a t = insert a (s ∪ t) := by simp only [insert_eq, union_left_comm] #align finset.union_insert Finset.union_insert theorem insert_union_distrib (a : α) (s t : Finset α) : insert a (s ∪ t) = insert a s ∪ insert a t := by simp only [insert_union, union_insert, insert_idem] #align finset.insert_union_distrib Finset.insert_union_distrib @[simp] lemma union_eq_left : s ∪ t = s ↔ t ⊆ s := sup_eq_left #align finset.union_eq_left_iff_subset Finset.union_eq_left @[simp] lemma left_eq_union : s = s ∪ t ↔ t ⊆ s := by rw [eq_comm, union_eq_left] #align finset.left_eq_union_iff_subset Finset.left_eq_union @[simp] lemma union_eq_right : s ∪ t = t ↔ s ⊆ t := sup_eq_right #align finset.union_eq_right_iff_subset Finset.union_eq_right @[simp] lemma right_eq_union : s = t ∪ s ↔ t ⊆ s := by rw [eq_comm, union_eq_right] #align finset.right_eq_union_iff_subset Finset.right_eq_union -- Porting note: replaced `⊔` in RHS theorem union_congr_left (ht : t ⊆ s ∪ u) (hu : u ⊆ s ∪ t) : s ∪ t = s ∪ u := sup_congr_left ht hu #align finset.union_congr_left Finset.union_congr_left theorem union_congr_right (hs : s ⊆ t ∪ u) (ht : t ⊆ s ∪ u) : s ∪ u = t ∪ u := sup_congr_right hs ht #align finset.union_congr_right Finset.union_congr_right theorem union_eq_union_iff_left : s ∪ t = s ∪ u ↔ t ⊆ s ∪ u ∧ u ⊆ s ∪ t := sup_eq_sup_iff_left #align finset.union_eq_union_iff_left Finset.union_eq_union_iff_left theorem union_eq_union_iff_right : s ∪ u = t ∪ u ↔ s ⊆ t ∪ u ∧ t ⊆ s ∪ u := sup_eq_sup_iff_right #align finset.union_eq_union_iff_right Finset.union_eq_union_iff_right @[simp] theorem disjoint_union_left : Disjoint (s ∪ t) u ↔ Disjoint s u ∧ Disjoint t u := by simp only [disjoint_left, mem_union, or_imp, forall_and] #align finset.disjoint_union_left Finset.disjoint_union_left @[simp] theorem disjoint_union_right : Disjoint s (t ∪ u) ↔ Disjoint s t ∧ Disjoint s u := by simp only [disjoint_right, mem_union, or_imp, forall_and] #align finset.disjoint_union_right Finset.disjoint_union_right /-- To prove a relation on pairs of `Finset X`, it suffices to show that it is * symmetric, * it holds when one of the `Finset`s is empty, * it holds for pairs of singletons, * if it holds for `[a, c]` and for `[b, c]`, then it holds for `[a ∪ b, c]`. -/ theorem induction_on_union (P : Finset α → Finset α → Prop) (symm : ∀ {a b}, P a b → P b a) (empty_right : ∀ {a}, P a ∅) (singletons : ∀ {a b}, P {a} {b}) (union_of : ∀ {a b c}, P a c → P b c → P (a ∪ b) c) : ∀ a b, P a b := by intro a b refine Finset.induction_on b empty_right fun x s _xs hi => symm ?_ rw [Finset.insert_eq] apply union_of _ (symm hi) refine Finset.induction_on a empty_right fun a t _ta hi => symm ?_ rw [Finset.insert_eq] exact union_of singletons (symm hi) #align finset.induction_on_union Finset.induction_on_union /-! #### inter -/ theorem inter_val_nd (s₁ s₂ : Finset α) : (s₁ ∩ s₂).1 = ndinter s₁.1 s₂.1 := rfl #align finset.inter_val_nd Finset.inter_val_nd @[simp] theorem inter_val (s₁ s₂ : Finset α) : (s₁ ∩ s₂).1 = s₁.1 ∩ s₂.1 := ndinter_eq_inter s₁.2 #align finset.inter_val Finset.inter_val @[simp] theorem mem_inter {a : α} {s₁ s₂ : Finset α} : a ∈ s₁ ∩ s₂ ↔ a ∈ s₁ ∧ a ∈ s₂ := mem_ndinter #align finset.mem_inter Finset.mem_inter theorem mem_of_mem_inter_left {a : α} {s₁ s₂ : Finset α} (h : a ∈ s₁ ∩ s₂) : a ∈ s₁ := (mem_inter.1 h).1 #align finset.mem_of_mem_inter_left Finset.mem_of_mem_inter_left theorem mem_of_mem_inter_right {a : α} {s₁ s₂ : Finset α} (h : a ∈ s₁ ∩ s₂) : a ∈ s₂ := (mem_inter.1 h).2 #align finset.mem_of_mem_inter_right Finset.mem_of_mem_inter_right theorem mem_inter_of_mem {a : α} {s₁ s₂ : Finset α} : a ∈ s₁ → a ∈ s₂ → a ∈ s₁ ∩ s₂ := and_imp.1 mem_inter.2 #align finset.mem_inter_of_mem Finset.mem_inter_of_mem theorem inter_subset_left {s₁ s₂ : Finset α} : s₁ ∩ s₂ ⊆ s₁ := fun _a => mem_of_mem_inter_left #align finset.inter_subset_left Finset.inter_subset_left theorem inter_subset_right {s₁ s₂ : Finset α} : s₁ ∩ s₂ ⊆ s₂ := fun _a => mem_of_mem_inter_right #align finset.inter_subset_right Finset.inter_subset_right theorem subset_inter {s₁ s₂ u : Finset α} : s₁ ⊆ s₂ → s₁ ⊆ u → s₁ ⊆ s₂ ∩ u := by simp (config := { contextual := true }) [subset_iff, mem_inter] #align finset.subset_inter Finset.subset_inter @[simp, norm_cast] theorem coe_inter (s₁ s₂ : Finset α) : ↑(s₁ ∩ s₂) = (s₁ ∩ s₂ : Set α) := Set.ext fun _ => mem_inter #align finset.coe_inter Finset.coe_inter @[simp] theorem union_inter_cancel_left {s t : Finset α} : (s ∪ t) ∩ s = s := by rw [← coe_inj, coe_inter, coe_union, Set.union_inter_cancel_left] #align finset.union_inter_cancel_left Finset.union_inter_cancel_left @[simp] theorem union_inter_cancel_right {s t : Finset α} : (s ∪ t) ∩ t = t := by rw [← coe_inj, coe_inter, coe_union, Set.union_inter_cancel_right] #align finset.union_inter_cancel_right Finset.union_inter_cancel_right theorem inter_comm (s₁ s₂ : Finset α) : s₁ ∩ s₂ = s₂ ∩ s₁ := ext fun _ => by simp only [mem_inter, and_comm] #align finset.inter_comm Finset.inter_comm @[simp] theorem inter_assoc (s₁ s₂ s₃ : Finset α) : s₁ ∩ s₂ ∩ s₃ = s₁ ∩ (s₂ ∩ s₃) := ext fun _ => by simp only [mem_inter, and_assoc] #align finset.inter_assoc Finset.inter_assoc theorem inter_left_comm (s₁ s₂ s₃ : Finset α) : s₁ ∩ (s₂ ∩ s₃) = s₂ ∩ (s₁ ∩ s₃) := ext fun _ => by simp only [mem_inter, and_left_comm] #align finset.inter_left_comm Finset.inter_left_comm theorem inter_right_comm (s₁ s₂ s₃ : Finset α) : s₁ ∩ s₂ ∩ s₃ = s₁ ∩ s₃ ∩ s₂ := ext fun _ => by simp only [mem_inter, and_right_comm] #align finset.inter_right_comm Finset.inter_right_comm @[simp] theorem inter_self (s : Finset α) : s ∩ s = s := ext fun _ => mem_inter.trans <| and_self_iff #align finset.inter_self Finset.inter_self @[simp] theorem inter_empty (s : Finset α) : s ∩ ∅ = ∅ := ext fun _ => mem_inter.trans <| by simp #align finset.inter_empty Finset.inter_empty @[simp] theorem empty_inter (s : Finset α) : ∅ ∩ s = ∅ := ext fun _ => mem_inter.trans <| by simp #align finset.empty_inter Finset.empty_inter @[simp] theorem inter_union_self (s t : Finset α) : s ∩ (t ∪ s) = s := by rw [inter_comm, union_inter_cancel_right] #align finset.inter_union_self Finset.inter_union_self @[simp] theorem insert_inter_of_mem {s₁ s₂ : Finset α} {a : α} (h : a ∈ s₂) : insert a s₁ ∩ s₂ = insert a (s₁ ∩ s₂) := ext fun x => by have : x = a ∨ x ∈ s₂ ↔ x ∈ s₂ := or_iff_right_of_imp <| by rintro rfl; exact h simp only [mem_inter, mem_insert, or_and_left, this] #align finset.insert_inter_of_mem Finset.insert_inter_of_mem @[simp] theorem inter_insert_of_mem {s₁ s₂ : Finset α} {a : α} (h : a ∈ s₁) : s₁ ∩ insert a s₂ = insert a (s₁ ∩ s₂) := by rw [inter_comm, insert_inter_of_mem h, inter_comm] #align finset.inter_insert_of_mem Finset.inter_insert_of_mem @[simp] theorem insert_inter_of_not_mem {s₁ s₂ : Finset α} {a : α} (h : a ∉ s₂) : insert a s₁ ∩ s₂ = s₁ ∩ s₂ := ext fun x => by have : ¬(x = a ∧ x ∈ s₂) := by rintro ⟨rfl, H⟩; exact h H simp only [mem_inter, mem_insert, or_and_right, this, false_or_iff] #align finset.insert_inter_of_not_mem Finset.insert_inter_of_not_mem @[simp] theorem inter_insert_of_not_mem {s₁ s₂ : Finset α} {a : α} (h : a ∉ s₁) : s₁ ∩ insert a s₂ = s₁ ∩ s₂ := by rw [inter_comm, insert_inter_of_not_mem h, inter_comm] #align finset.inter_insert_of_not_mem Finset.inter_insert_of_not_mem @[simp] theorem singleton_inter_of_mem {a : α} {s : Finset α} (H : a ∈ s) : {a} ∩ s = {a} := show insert a ∅ ∩ s = insert a ∅ by rw [insert_inter_of_mem H, empty_inter] #align finset.singleton_inter_of_mem Finset.singleton_inter_of_mem @[simp] theorem singleton_inter_of_not_mem {a : α} {s : Finset α} (H : a ∉ s) : {a} ∩ s = ∅ := eq_empty_of_forall_not_mem <| by simp only [mem_inter, mem_singleton]; rintro x ⟨rfl, h⟩; exact H h #align finset.singleton_inter_of_not_mem Finset.singleton_inter_of_not_mem @[simp] theorem inter_singleton_of_mem {a : α} {s : Finset α} (h : a ∈ s) : s ∩ {a} = {a} := by rw [inter_comm, singleton_inter_of_mem h] #align finset.inter_singleton_of_mem Finset.inter_singleton_of_mem @[simp] theorem inter_singleton_of_not_mem {a : α} {s : Finset α} (h : a ∉ s) : s ∩ {a} = ∅ := by rw [inter_comm, singleton_inter_of_not_mem h] #align finset.inter_singleton_of_not_mem Finset.inter_singleton_of_not_mem @[mono, gcongr] theorem inter_subset_inter {x y s t : Finset α} (h : x ⊆ y) (h' : s ⊆ t) : x ∩ s ⊆ y ∩ t := by intro a a_in rw [Finset.mem_inter] at a_in ⊢ exact ⟨h a_in.1, h' a_in.2⟩ #align finset.inter_subset_inter Finset.inter_subset_inter @[gcongr] theorem inter_subset_inter_left (h : t ⊆ u) : s ∩ t ⊆ s ∩ u := inter_subset_inter Subset.rfl h #align finset.inter_subset_inter_left Finset.inter_subset_inter_left @[gcongr] theorem inter_subset_inter_right (h : s ⊆ t) : s ∩ u ⊆ t ∩ u := inter_subset_inter h Subset.rfl #align finset.inter_subset_inter_right Finset.inter_subset_inter_right theorem inter_subset_union : s ∩ t ⊆ s ∪ t := le_iff_subset.1 inf_le_sup #align finset.inter_subset_union Finset.inter_subset_union instance : DistribLattice (Finset α) := { le_sup_inf := fun a b c => by simp (config := { contextual := true }) only [sup_eq_union, inf_eq_inter, le_eq_subset, subset_iff, mem_inter, mem_union, and_imp, or_imp, true_or_iff, imp_true_iff, true_and_iff, or_true_iff] } @[simp] theorem union_left_idem (s t : Finset α) : s ∪ (s ∪ t) = s ∪ t := sup_left_idem _ _ #align finset.union_left_idem Finset.union_left_idem -- Porting note (#10618): @[simp] can prove this theorem union_right_idem (s t : Finset α) : s ∪ t ∪ t = s ∪ t := sup_right_idem _ _ #align finset.union_right_idem Finset.union_right_idem @[simp] theorem inter_left_idem (s t : Finset α) : s ∩ (s ∩ t) = s ∩ t := inf_left_idem _ _ #align finset.inter_left_idem Finset.inter_left_idem -- Porting note (#10618): @[simp] can prove this theorem inter_right_idem (s t : Finset α) : s ∩ t ∩ t = s ∩ t := inf_right_idem _ _ #align finset.inter_right_idem Finset.inter_right_idem theorem inter_union_distrib_left (s t u : Finset α) : s ∩ (t ∪ u) = s ∩ t ∪ s ∩ u := inf_sup_left _ _ _ #align finset.inter_distrib_left Finset.inter_union_distrib_left theorem union_inter_distrib_right (s t u : Finset α) : (s ∪ t) ∩ u = s ∩ u ∪ t ∩ u := inf_sup_right _ _ _ #align finset.inter_distrib_right Finset.union_inter_distrib_right theorem union_inter_distrib_left (s t u : Finset α) : s ∪ t ∩ u = (s ∪ t) ∩ (s ∪ u) := sup_inf_left _ _ _ #align finset.union_distrib_left Finset.union_inter_distrib_left theorem inter_union_distrib_right (s t u : Finset α) : s ∩ t ∪ u = (s ∪ u) ∩ (t ∪ u) := sup_inf_right _ _ _ #align finset.union_distrib_right Finset.inter_union_distrib_right -- 2024-03-22 @[deprecated] alias inter_distrib_left := inter_union_distrib_left @[deprecated] alias inter_distrib_right := union_inter_distrib_right @[deprecated] alias union_distrib_left := union_inter_distrib_left @[deprecated] alias union_distrib_right := inter_union_distrib_right theorem union_union_distrib_left (s t u : Finset α) : s ∪ (t ∪ u) = s ∪ t ∪ (s ∪ u) := sup_sup_distrib_left _ _ _ #align finset.union_union_distrib_left Finset.union_union_distrib_left theorem union_union_distrib_right (s t u : Finset α) : s ∪ t ∪ u = s ∪ u ∪ (t ∪ u) := sup_sup_distrib_right _ _ _ #align finset.union_union_distrib_right Finset.union_union_distrib_right theorem inter_inter_distrib_left (s t u : Finset α) : s ∩ (t ∩ u) = s ∩ t ∩ (s ∩ u) := inf_inf_distrib_left _ _ _ #align finset.inter_inter_distrib_left Finset.inter_inter_distrib_left theorem inter_inter_distrib_right (s t u : Finset α) : s ∩ t ∩ u = s ∩ u ∩ (t ∩ u) := inf_inf_distrib_right _ _ _ #align finset.inter_inter_distrib_right Finset.inter_inter_distrib_right theorem union_union_union_comm (s t u v : Finset α) : s ∪ t ∪ (u ∪ v) = s ∪ u ∪ (t ∪ v) := sup_sup_sup_comm _ _ _ _ #align finset.union_union_union_comm Finset.union_union_union_comm theorem inter_inter_inter_comm (s t u v : Finset α) : s ∩ t ∩ (u ∩ v) = s ∩ u ∩ (t ∩ v) := inf_inf_inf_comm _ _ _ _ #align finset.inter_inter_inter_comm Finset.inter_inter_inter_comm lemma union_eq_empty : s ∪ t = ∅ ↔ s = ∅ ∧ t = ∅ := sup_eq_bot_iff #align finset.union_eq_empty_iff Finset.union_eq_empty theorem union_subset_iff : s ∪ t ⊆ u ↔ s ⊆ u ∧ t ⊆ u := (sup_le_iff : s ⊔ t ≤ u ↔ s ≤ u ∧ t ≤ u) #align finset.union_subset_iff Finset.union_subset_iff theorem subset_inter_iff : s ⊆ t ∩ u ↔ s ⊆ t ∧ s ⊆ u := (le_inf_iff : s ≤ t ⊓ u ↔ s ≤ t ∧ s ≤ u) #align finset.subset_inter_iff Finset.subset_inter_iff @[simp] lemma inter_eq_left : s ∩ t = s ↔ s ⊆ t := inf_eq_left #align finset.inter_eq_left_iff_subset_iff_subset Finset.inter_eq_left @[simp] lemma inter_eq_right : t ∩ s = s ↔ s ⊆ t := inf_eq_right #align finset.inter_eq_right_iff_subset Finset.inter_eq_right theorem inter_congr_left (ht : s ∩ u ⊆ t) (hu : s ∩ t ⊆ u) : s ∩ t = s ∩ u := inf_congr_left ht hu #align finset.inter_congr_left Finset.inter_congr_left theorem inter_congr_right (hs : t ∩ u ⊆ s) (ht : s ∩ u ⊆ t) : s ∩ u = t ∩ u := inf_congr_right hs ht #align finset.inter_congr_right Finset.inter_congr_right theorem inter_eq_inter_iff_left : s ∩ t = s ∩ u ↔ s ∩ u ⊆ t ∧ s ∩ t ⊆ u := inf_eq_inf_iff_left #align finset.inter_eq_inter_iff_left Finset.inter_eq_inter_iff_left theorem inter_eq_inter_iff_right : s ∩ u = t ∩ u ↔ t ∩ u ⊆ s ∧ s ∩ u ⊆ t := inf_eq_inf_iff_right #align finset.inter_eq_inter_iff_right Finset.inter_eq_inter_iff_right theorem ite_subset_union (s s' : Finset α) (P : Prop) [Decidable P] : ite P s s' ⊆ s ∪ s' := ite_le_sup s s' P #align finset.ite_subset_union Finset.ite_subset_union theorem inter_subset_ite (s s' : Finset α) (P : Prop) [Decidable P] : s ∩ s' ⊆ ite P s s' := inf_le_ite s s' P #align finset.inter_subset_ite Finset.inter_subset_ite theorem not_disjoint_iff_nonempty_inter : ¬Disjoint s t ↔ (s ∩ t).Nonempty := not_disjoint_iff.trans <| by simp [Finset.Nonempty] #align finset.not_disjoint_iff_nonempty_inter Finset.not_disjoint_iff_nonempty_inter alias ⟨_, Nonempty.not_disjoint⟩ := not_disjoint_iff_nonempty_inter #align finset.nonempty.not_disjoint Finset.Nonempty.not_disjoint theorem disjoint_or_nonempty_inter (s t : Finset α) : Disjoint s t ∨ (s ∩ t).Nonempty := by rw [← not_disjoint_iff_nonempty_inter] exact em _ #align finset.disjoint_or_nonempty_inter Finset.disjoint_or_nonempty_inter end Lattice instance isDirected_le : IsDirected (Finset α) (· ≤ ·) := by classical infer_instance instance isDirected_subset : IsDirected (Finset α) (· ⊆ ·) := isDirected_le /-! ### erase -/ section Erase variable [DecidableEq α] {s t u v : Finset α} {a b : α} /-- `erase s a` is the set `s - {a}`, that is, the elements of `s` which are not equal to `a`. -/ def erase (s : Finset α) (a : α) : Finset α := ⟨_, s.2.erase a⟩ #align finset.erase Finset.erase @[simp] theorem erase_val (s : Finset α) (a : α) : (erase s a).1 = s.1.erase a := rfl #align finset.erase_val Finset.erase_val @[simp] theorem mem_erase {a b : α} {s : Finset α} : a ∈ erase s b ↔ a ≠ b ∧ a ∈ s := s.2.mem_erase_iff #align finset.mem_erase Finset.mem_erase theorem not_mem_erase (a : α) (s : Finset α) : a ∉ erase s a := s.2.not_mem_erase #align finset.not_mem_erase Finset.not_mem_erase -- While this can be solved by `simp`, this lemma is eligible for `dsimp` @[nolint simpNF, simp] theorem erase_empty (a : α) : erase ∅ a = ∅ := rfl #align finset.erase_empty Finset.erase_empty protected lemma Nontrivial.erase_nonempty (hs : s.Nontrivial) : (s.erase a).Nonempty := (hs.exists_ne a).imp $ by aesop @[simp] lemma erase_nonempty (ha : a ∈ s) : (s.erase a).Nonempty ↔ s.Nontrivial := by simp only [Finset.Nonempty, mem_erase, and_comm (b := _ ∈ _)] refine ⟨?_, fun hs ↦ hs.exists_ne a⟩ rintro ⟨b, hb, hba⟩ exact ⟨_, hb, _, ha, hba⟩ @[simp] theorem erase_singleton (a : α) : ({a} : Finset α).erase a = ∅ := by ext x simp #align finset.erase_singleton Finset.erase_singleton theorem ne_of_mem_erase : b ∈ erase s a → b ≠ a := fun h => (mem_erase.1 h).1 #align finset.ne_of_mem_erase Finset.ne_of_mem_erase theorem mem_of_mem_erase : b ∈ erase s a → b ∈ s := Multiset.mem_of_mem_erase #align finset.mem_of_mem_erase Finset.mem_of_mem_erase theorem mem_erase_of_ne_of_mem : a ≠ b → a ∈ s → a ∈ erase s b := by simp only [mem_erase]; exact And.intro #align finset.mem_erase_of_ne_of_mem Finset.mem_erase_of_ne_of_mem /-- An element of `s` that is not an element of `erase s a` must be`a`. -/ theorem eq_of_mem_of_not_mem_erase (hs : b ∈ s) (hsa : b ∉ s.erase a) : b = a := by rw [mem_erase, not_and] at hsa exact not_imp_not.mp hsa hs #align finset.eq_of_mem_of_not_mem_erase Finset.eq_of_mem_of_not_mem_erase @[simp] theorem erase_eq_of_not_mem {a : α} {s : Finset α} (h : a ∉ s) : erase s a = s := eq_of_veq <| erase_of_not_mem h #align finset.erase_eq_of_not_mem Finset.erase_eq_of_not_mem @[simp] theorem erase_eq_self : s.erase a = s ↔ a ∉ s := ⟨fun h => h ▸ not_mem_erase _ _, erase_eq_of_not_mem⟩ #align finset.erase_eq_self Finset.erase_eq_self @[simp] theorem erase_insert_eq_erase (s : Finset α) (a : α) : (insert a s).erase a = s.erase a := ext fun x => by simp (config := { contextual := true }) only [mem_erase, mem_insert, and_congr_right_iff, false_or_iff, iff_self_iff, imp_true_iff] #align finset.erase_insert_eq_erase Finset.erase_insert_eq_erase theorem erase_insert {a : α} {s : Finset α} (h : a ∉ s) : erase (insert a s) a = s := by rw [erase_insert_eq_erase, erase_eq_of_not_mem h] #align finset.erase_insert Finset.erase_insert theorem erase_insert_of_ne {a b : α} {s : Finset α} (h : a ≠ b) : erase (insert a s) b = insert a (erase s b) := ext fun x => by have : x ≠ b ∧ x = a ↔ x = a := and_iff_right_of_imp fun hx => hx.symm ▸ h simp only [mem_erase, mem_insert, and_or_left, this] #align finset.erase_insert_of_ne Finset.erase_insert_of_ne theorem erase_cons_of_ne {a b : α} {s : Finset α} (ha : a ∉ s) (hb : a ≠ b) : erase (cons a s ha) b = cons a (erase s b) fun h => ha <| erase_subset _ _ h := by simp only [cons_eq_insert, erase_insert_of_ne hb] #align finset.erase_cons_of_ne Finset.erase_cons_of_ne @[simp] theorem insert_erase (h : a ∈ s) : insert a (erase s a) = s := ext fun x => by simp only [mem_insert, mem_erase, or_and_left, dec_em, true_and_iff] apply or_iff_right_of_imp rintro rfl exact h #align finset.insert_erase Finset.insert_erase lemma erase_eq_iff_eq_insert (hs : a ∈ s) (ht : a ∉ t) : erase s a = t ↔ s = insert a t := by aesop lemma insert_erase_invOn : Set.InvOn (insert a) (fun s ↦ erase s a) {s : Finset α | a ∈ s} {s : Finset α | a ∉ s} := ⟨fun _s ↦ insert_erase, fun _s ↦ erase_insert⟩ theorem erase_subset_erase (a : α) {s t : Finset α} (h : s ⊆ t) : erase s a ⊆ erase t a := val_le_iff.1 <| erase_le_erase _ <| val_le_iff.2 h #align finset.erase_subset_erase Finset.erase_subset_erase theorem erase_subset (a : α) (s : Finset α) : erase s a ⊆ s := Multiset.erase_subset _ _ #align finset.erase_subset Finset.erase_subset theorem subset_erase {a : α} {s t : Finset α} : s ⊆ t.erase a ↔ s ⊆ t ∧ a ∉ s := ⟨fun h => ⟨h.trans (erase_subset _ _), fun ha => not_mem_erase _ _ (h ha)⟩, fun h _b hb => mem_erase.2 ⟨ne_of_mem_of_not_mem hb h.2, h.1 hb⟩⟩ #align finset.subset_erase Finset.subset_erase @[simp, norm_cast] theorem coe_erase (a : α) (s : Finset α) : ↑(erase s a) = (s \ {a} : Set α) := Set.ext fun _ => mem_erase.trans <| by rw [and_comm, Set.mem_diff, Set.mem_singleton_iff, mem_coe] #align finset.coe_erase Finset.coe_erase theorem erase_ssubset {a : α} {s : Finset α} (h : a ∈ s) : s.erase a ⊂ s := calc s.erase a ⊂ insert a (s.erase a) := ssubset_insert <| not_mem_erase _ _ _ = _ := insert_erase h #align finset.erase_ssubset Finset.erase_ssubset theorem ssubset_iff_exists_subset_erase {s t : Finset α} : s ⊂ t ↔ ∃ a ∈ t, s ⊆ t.erase a := by refine ⟨fun h => ?_, fun ⟨a, ha, h⟩ => ssubset_of_subset_of_ssubset h <| erase_ssubset ha⟩ obtain ⟨a, ht, hs⟩ := not_subset.1 h.2 exact ⟨a, ht, subset_erase.2 ⟨h.1, hs⟩⟩ #align finset.ssubset_iff_exists_subset_erase Finset.ssubset_iff_exists_subset_erase theorem erase_ssubset_insert (s : Finset α) (a : α) : s.erase a ⊂ insert a s := ssubset_iff_exists_subset_erase.2 ⟨a, mem_insert_self _ _, erase_subset_erase _ <| subset_insert _ _⟩ #align finset.erase_ssubset_insert Finset.erase_ssubset_insert theorem erase_ne_self : s.erase a ≠ s ↔ a ∈ s := erase_eq_self.not_left #align finset.erase_ne_self Finset.erase_ne_self theorem erase_cons {s : Finset α} {a : α} (h : a ∉ s) : (s.cons a h).erase a = s := by rw [cons_eq_insert, erase_insert_eq_erase, erase_eq_of_not_mem h] #align finset.erase_cons Finset.erase_cons theorem erase_idem {a : α} {s : Finset α} : erase (erase s a) a = erase s a := by simp #align finset.erase_idem Finset.erase_idem theorem erase_right_comm {a b : α} {s : Finset α} : erase (erase s a) b = erase (erase s b) a := by ext x simp only [mem_erase, ← and_assoc] rw [@and_comm (x ≠ a)] #align finset.erase_right_comm Finset.erase_right_comm theorem subset_insert_iff {a : α} {s t : Finset α} : s ⊆ insert a t ↔ erase s a ⊆ t := by simp only [subset_iff, or_iff_not_imp_left, mem_erase, mem_insert, and_imp] exact forall_congr' fun x => forall_swap #align finset.subset_insert_iff Finset.subset_insert_iff theorem erase_insert_subset (a : α) (s : Finset α) : erase (insert a s) a ⊆ s := subset_insert_iff.1 <| Subset.rfl #align finset.erase_insert_subset Finset.erase_insert_subset theorem insert_erase_subset (a : α) (s : Finset α) : s ⊆ insert a (erase s a) := subset_insert_iff.2 <| Subset.rfl #align finset.insert_erase_subset Finset.insert_erase_subset theorem subset_insert_iff_of_not_mem (h : a ∉ s) : s ⊆ insert a t ↔ s ⊆ t := by rw [subset_insert_iff, erase_eq_of_not_mem h] #align finset.subset_insert_iff_of_not_mem Finset.subset_insert_iff_of_not_mem theorem erase_subset_iff_of_mem (h : a ∈ t) : s.erase a ⊆ t ↔ s ⊆ t := by rw [← subset_insert_iff, insert_eq_of_mem h] #align finset.erase_subset_iff_of_mem Finset.erase_subset_iff_of_mem theorem erase_inj {x y : α} (s : Finset α) (hx : x ∈ s) : s.erase x = s.erase y ↔ x = y := by refine ⟨fun h => eq_of_mem_of_not_mem_erase hx ?_, congr_arg _⟩ rw [← h] simp #align finset.erase_inj Finset.erase_inj theorem erase_injOn (s : Finset α) : Set.InjOn s.erase s := fun _ _ _ _ => (erase_inj s ‹_›).mp #align finset.erase_inj_on Finset.erase_injOn theorem erase_injOn' (a : α) : { s : Finset α | a ∈ s }.InjOn fun s => erase s a := fun s hs t ht (h : s.erase a = _) => by rw [← insert_erase hs, ← insert_erase ht, h] #align finset.erase_inj_on' Finset.erase_injOn' end Erase lemma Nontrivial.exists_cons_eq {s : Finset α} (hs : s.Nontrivial) : ∃ t a ha b hb hab, (cons b t hb).cons a (mem_cons.not.2 <| not_or_intro hab ha) = s := by classical obtain ⟨a, ha, b, hb, hab⟩ := hs have : b ∈ s.erase a := mem_erase.2 ⟨hab.symm, hb⟩ refine ⟨(s.erase a).erase b, a, ?_, b, ?_, ?_, ?_⟩ <;> simp [insert_erase this, insert_erase ha, *] /-! ### sdiff -/ section Sdiff variable [DecidableEq α] {s t u v : Finset α} {a b : α} /-- `s \ t` is the set consisting of the elements of `s` that are not in `t`. -/ instance : SDiff (Finset α) := ⟨fun s₁ s₂ => ⟨s₁.1 - s₂.1, nodup_of_le tsub_le_self s₁.2⟩⟩ @[simp] theorem sdiff_val (s₁ s₂ : Finset α) : (s₁ \ s₂).val = s₁.val - s₂.val := rfl #align finset.sdiff_val Finset.sdiff_val @[simp] theorem mem_sdiff : a ∈ s \ t ↔ a ∈ s ∧ a ∉ t := mem_sub_of_nodup s.2 #align finset.mem_sdiff Finset.mem_sdiff @[simp] theorem inter_sdiff_self (s₁ s₂ : Finset α) : s₁ ∩ (s₂ \ s₁) = ∅ := eq_empty_of_forall_not_mem <| by simp only [mem_inter, mem_sdiff]; rintro x ⟨h, _, hn⟩; exact hn h #align finset.inter_sdiff_self Finset.inter_sdiff_self instance : GeneralizedBooleanAlgebra (Finset α) := { sup_inf_sdiff := fun x y => by simp only [ext_iff, mem_union, mem_sdiff, inf_eq_inter, sup_eq_union, mem_inter, ← and_or_left, em, and_true, implies_true] inf_inf_sdiff := fun x y => by simp only [ext_iff, inter_sdiff_self, inter_empty, inter_assoc, false_iff_iff, inf_eq_inter, not_mem_empty, bot_eq_empty, not_false_iff, implies_true] } theorem not_mem_sdiff_of_mem_right (h : a ∈ t) : a ∉ s \ t := by simp only [mem_sdiff, h, not_true, not_false_iff, and_false_iff] #align finset.not_mem_sdiff_of_mem_right Finset.not_mem_sdiff_of_mem_right theorem not_mem_sdiff_of_not_mem_left (h : a ∉ s) : a ∉ s \ t := by simp [h] #align finset.not_mem_sdiff_of_not_mem_left Finset.not_mem_sdiff_of_not_mem_left theorem union_sdiff_of_subset (h : s ⊆ t) : s ∪ t \ s = t := sup_sdiff_cancel_right h #align finset.union_sdiff_of_subset Finset.union_sdiff_of_subset theorem sdiff_union_of_subset {s₁ s₂ : Finset α} (h : s₁ ⊆ s₂) : s₂ \ s₁ ∪ s₁ = s₂ := (union_comm _ _).trans (union_sdiff_of_subset h) #align finset.sdiff_union_of_subset Finset.sdiff_union_of_subset lemma inter_sdiff_assoc (s t u : Finset α) : (s ∩ t) \ u = s ∩ (t \ u) := by ext x; simp [and_assoc] @[deprecated inter_sdiff_assoc (since := "2024-05-01")] theorem inter_sdiff (s t u : Finset α) : s ∩ (t \ u) = (s ∩ t) \ u := (inter_sdiff_assoc _ _ _).symm #align finset.inter_sdiff Finset.inter_sdiff @[simp] theorem sdiff_inter_self (s₁ s₂ : Finset α) : s₂ \ s₁ ∩ s₁ = ∅ := inf_sdiff_self_left #align finset.sdiff_inter_self Finset.sdiff_inter_self -- Porting note (#10618): @[simp] can prove this protected theorem sdiff_self (s₁ : Finset α) : s₁ \ s₁ = ∅ := _root_.sdiff_self #align finset.sdiff_self Finset.sdiff_self theorem sdiff_inter_distrib_right (s t u : Finset α) : s \ (t ∩ u) = s \ t ∪ s \ u := sdiff_inf #align finset.sdiff_inter_distrib_right Finset.sdiff_inter_distrib_right @[simp] theorem sdiff_inter_self_left (s t : Finset α) : s \ (s ∩ t) = s \ t := sdiff_inf_self_left _ _ #align finset.sdiff_inter_self_left Finset.sdiff_inter_self_left @[simp] theorem sdiff_inter_self_right (s t : Finset α) : s \ (t ∩ s) = s \ t := sdiff_inf_self_right _ _ #align finset.sdiff_inter_self_right Finset.sdiff_inter_self_right @[simp] theorem sdiff_empty : s \ ∅ = s := sdiff_bot #align finset.sdiff_empty Finset.sdiff_empty @[mono, gcongr] theorem sdiff_subset_sdiff (hst : s ⊆ t) (hvu : v ⊆ u) : s \ u ⊆ t \ v := sdiff_le_sdiff hst hvu #align finset.sdiff_subset_sdiff Finset.sdiff_subset_sdiff @[simp, norm_cast] theorem coe_sdiff (s₁ s₂ : Finset α) : ↑(s₁ \ s₂) = (s₁ \ s₂ : Set α) := Set.ext fun _ => mem_sdiff #align finset.coe_sdiff Finset.coe_sdiff @[simp] theorem union_sdiff_self_eq_union : s ∪ t \ s = s ∪ t := sup_sdiff_self_right _ _ #align finset.union_sdiff_self_eq_union Finset.union_sdiff_self_eq_union @[simp] theorem sdiff_union_self_eq_union : s \ t ∪ t = s ∪ t := sup_sdiff_self_left _ _ #align finset.sdiff_union_self_eq_union Finset.sdiff_union_self_eq_union theorem union_sdiff_left (s t : Finset α) : (s ∪ t) \ s = t \ s := sup_sdiff_left_self #align finset.union_sdiff_left Finset.union_sdiff_left theorem union_sdiff_right (s t : Finset α) : (s ∪ t) \ t = s \ t := sup_sdiff_right_self #align finset.union_sdiff_right Finset.union_sdiff_right theorem union_sdiff_cancel_left (h : Disjoint s t) : (s ∪ t) \ s = t := h.sup_sdiff_cancel_left #align finset.union_sdiff_cancel_left Finset.union_sdiff_cancel_left theorem union_sdiff_cancel_right (h : Disjoint s t) : (s ∪ t) \ t = s := h.sup_sdiff_cancel_right #align finset.union_sdiff_cancel_right Finset.union_sdiff_cancel_right theorem union_sdiff_symm : s ∪ t \ s = t ∪ s \ t := by simp [union_comm] #align finset.union_sdiff_symm Finset.union_sdiff_symm theorem sdiff_union_inter (s t : Finset α) : s \ t ∪ s ∩ t = s := sup_sdiff_inf _ _ #align finset.sdiff_union_inter Finset.sdiff_union_inter -- Porting note (#10618): @[simp] can prove this theorem sdiff_idem (s t : Finset α) : (s \ t) \ t = s \ t := _root_.sdiff_idem #align finset.sdiff_idem Finset.sdiff_idem theorem subset_sdiff : s ⊆ t \ u ↔ s ⊆ t ∧ Disjoint s u := le_iff_subset.symm.trans le_sdiff #align finset.subset_sdiff Finset.subset_sdiff @[simp] theorem sdiff_eq_empty_iff_subset : s \ t = ∅ ↔ s ⊆ t := sdiff_eq_bot_iff #align finset.sdiff_eq_empty_iff_subset Finset.sdiff_eq_empty_iff_subset theorem sdiff_nonempty : (s \ t).Nonempty ↔ ¬s ⊆ t := nonempty_iff_ne_empty.trans sdiff_eq_empty_iff_subset.not #align finset.sdiff_nonempty Finset.sdiff_nonempty @[simp] theorem empty_sdiff (s : Finset α) : ∅ \ s = ∅ := bot_sdiff #align finset.empty_sdiff Finset.empty_sdiff theorem insert_sdiff_of_not_mem (s : Finset α) {t : Finset α} {x : α} (h : x ∉ t) : insert x s \ t = insert x (s \ t) := by rw [← coe_inj, coe_insert, coe_sdiff, coe_sdiff, coe_insert] exact Set.insert_diff_of_not_mem _ h #align finset.insert_sdiff_of_not_mem Finset.insert_sdiff_of_not_mem theorem insert_sdiff_of_mem (s : Finset α) {x : α} (h : x ∈ t) : insert x s \ t = s \ t := by rw [← coe_inj, coe_sdiff, coe_sdiff, coe_insert] exact Set.insert_diff_of_mem _ h #align finset.insert_sdiff_of_mem Finset.insert_sdiff_of_mem @[simp] lemma insert_sdiff_cancel (ha : a ∉ s) : insert a s \ s = {a} := by rw [insert_sdiff_of_not_mem _ ha, Finset.sdiff_self, insert_emptyc_eq] @[simp] theorem insert_sdiff_insert (s t : Finset α) (x : α) : insert x s \ insert x t = s \ insert x t := insert_sdiff_of_mem _ (mem_insert_self _ _) #align finset.insert_sdiff_insert Finset.insert_sdiff_insert lemma insert_sdiff_insert' (hab : a ≠ b) (ha : a ∉ s) : insert a s \ insert b s = {a} := by ext; aesop lemma erase_sdiff_erase (hab : a ≠ b) (hb : b ∈ s) : s.erase a \ s.erase b = {b} := by ext; aesop lemma cons_sdiff_cons (hab : a ≠ b) (ha hb) : s.cons a ha \ s.cons b hb = {a} := by rw [cons_eq_insert, cons_eq_insert, insert_sdiff_insert' hab ha] theorem sdiff_insert_of_not_mem {x : α} (h : x ∉ s) (t : Finset α) : s \ insert x t = s \ t := by refine Subset.antisymm (sdiff_subset_sdiff (Subset.refl _) (subset_insert _ _)) fun y hy => ?_ simp only [mem_sdiff, mem_insert, not_or] at hy ⊢ exact ⟨hy.1, fun hxy => h <| hxy ▸ hy.1, hy.2⟩ #align finset.sdiff_insert_of_not_mem Finset.sdiff_insert_of_not_mem @[simp] theorem sdiff_subset {s t : Finset α} : s \ t ⊆ s := le_iff_subset.mp sdiff_le #align finset.sdiff_subset Finset.sdiff_subset theorem sdiff_ssubset (h : t ⊆ s) (ht : t.Nonempty) : s \ t ⊂ s := sdiff_lt (le_iff_subset.mpr h) ht.ne_empty #align finset.sdiff_ssubset Finset.sdiff_ssubset theorem union_sdiff_distrib (s₁ s₂ t : Finset α) : (s₁ ∪ s₂) \ t = s₁ \ t ∪ s₂ \ t := sup_sdiff #align finset.union_sdiff_distrib Finset.union_sdiff_distrib theorem sdiff_union_distrib (s t₁ t₂ : Finset α) : s \ (t₁ ∪ t₂) = s \ t₁ ∩ (s \ t₂) := sdiff_sup #align finset.sdiff_union_distrib Finset.sdiff_union_distrib theorem union_sdiff_self (s t : Finset α) : (s ∪ t) \ t = s \ t := sup_sdiff_right_self #align finset.union_sdiff_self Finset.union_sdiff_self -- TODO: Do we want to delete this lemma and `Finset.disjUnion_singleton`, -- or instead add `Finset.union_singleton`/`Finset.singleton_union`? theorem sdiff_singleton_eq_erase (a : α) (s : Finset α) : s \ singleton a = erase s a := by ext rw [mem_erase, mem_sdiff, mem_singleton, and_comm] #align finset.sdiff_singleton_eq_erase Finset.sdiff_singleton_eq_erase -- This lemma matches `Finset.insert_eq` in functionality. theorem erase_eq (s : Finset α) (a : α) : s.erase a = s \ {a} := (sdiff_singleton_eq_erase _ _).symm #align finset.erase_eq Finset.erase_eq theorem disjoint_erase_comm : Disjoint (s.erase a) t ↔ Disjoint s (t.erase a) := by simp_rw [erase_eq, disjoint_sdiff_comm] #align finset.disjoint_erase_comm Finset.disjoint_erase_comm lemma disjoint_insert_erase (ha : a ∉ t) : Disjoint (s.erase a) (insert a t) ↔ Disjoint s t := by rw [disjoint_erase_comm, erase_insert ha] lemma disjoint_erase_insert (ha : a ∉ s) : Disjoint (insert a s) (t.erase a) ↔ Disjoint s t := by rw [← disjoint_erase_comm, erase_insert ha] theorem disjoint_of_erase_left (ha : a ∉ t) (hst : Disjoint (s.erase a) t) : Disjoint s t := by rw [← erase_insert ha, ← disjoint_erase_comm, disjoint_insert_right] exact ⟨not_mem_erase _ _, hst⟩ #align finset.disjoint_of_erase_left Finset.disjoint_of_erase_left theorem disjoint_of_erase_right (ha : a ∉ s) (hst : Disjoint s (t.erase a)) : Disjoint s t := by rw [← erase_insert ha, disjoint_erase_comm, disjoint_insert_left] exact ⟨not_mem_erase _ _, hst⟩ #align finset.disjoint_of_erase_right Finset.disjoint_of_erase_right theorem inter_erase (a : α) (s t : Finset α) : s ∩ t.erase a = (s ∩ t).erase a := by simp only [erase_eq, inter_sdiff_assoc] #align finset.inter_erase Finset.inter_erase @[simp] theorem erase_inter (a : α) (s t : Finset α) : s.erase a ∩ t = (s ∩ t).erase a := by simpa only [inter_comm t] using inter_erase a t s #align finset.erase_inter Finset.erase_inter theorem erase_sdiff_comm (s t : Finset α) (a : α) : s.erase a \ t = (s \ t).erase a := by simp_rw [erase_eq, sdiff_right_comm] #align finset.erase_sdiff_comm Finset.erase_sdiff_comm theorem insert_union_comm (s t : Finset α) (a : α) : insert a s ∪ t = s ∪ insert a t := by rw [insert_union, union_insert] #align finset.insert_union_comm Finset.insert_union_comm theorem erase_inter_comm (s t : Finset α) (a : α) : s.erase a ∩ t = s ∩ t.erase a := by rw [erase_inter, inter_erase] #align finset.erase_inter_comm Finset.erase_inter_comm theorem erase_union_distrib (s t : Finset α) (a : α) : (s ∪ t).erase a = s.erase a ∪ t.erase a := by simp_rw [erase_eq, union_sdiff_distrib] #align finset.erase_union_distrib Finset.erase_union_distrib theorem insert_inter_distrib (s t : Finset α) (a : α) : insert a (s ∩ t) = insert a s ∩ insert a t := by simp_rw [insert_eq, union_inter_distrib_left] #align finset.insert_inter_distrib Finset.insert_inter_distrib theorem erase_sdiff_distrib (s t : Finset α) (a : α) : (s \ t).erase a = s.erase a \ t.erase a := by simp_rw [erase_eq, sdiff_sdiff, sup_sdiff_eq_sup le_rfl, sup_comm] #align finset.erase_sdiff_distrib Finset.erase_sdiff_distrib theorem erase_union_of_mem (ha : a ∈ t) (s : Finset α) : s.erase a ∪ t = s ∪ t := by rw [← insert_erase (mem_union_right s ha), erase_union_distrib, ← union_insert, insert_erase ha] #align finset.erase_union_of_mem Finset.erase_union_of_mem theorem union_erase_of_mem (ha : a ∈ s) (t : Finset α) : s ∪ t.erase a = s ∪ t := by rw [← insert_erase (mem_union_left t ha), erase_union_distrib, ← insert_union, insert_erase ha] #align finset.union_erase_of_mem Finset.union_erase_of_mem @[simp] theorem sdiff_singleton_eq_self (ha : a ∉ s) : s \ {a} = s := sdiff_eq_self_iff_disjoint.2 <| by simp [ha] #align finset.sdiff_singleton_eq_self Finset.sdiff_singleton_eq_self theorem Nontrivial.sdiff_singleton_nonempty {c : α} {s : Finset α} (hS : s.Nontrivial) : (s \ {c}).Nonempty := by rw [Finset.sdiff_nonempty, Finset.subset_singleton_iff] push_neg exact ⟨by rintro rfl; exact Finset.not_nontrivial_empty hS, hS.ne_singleton⟩ theorem sdiff_sdiff_left' (s t u : Finset α) : (s \ t) \ u = s \ t ∩ (s \ u) := _root_.sdiff_sdiff_left' #align finset.sdiff_sdiff_left' Finset.sdiff_sdiff_left' theorem sdiff_union_sdiff_cancel (hts : t ⊆ s) (hut : u ⊆ t) : s \ t ∪ t \ u = s \ u := sdiff_sup_sdiff_cancel hts hut #align finset.sdiff_union_sdiff_cancel Finset.sdiff_union_sdiff_cancel theorem sdiff_union_erase_cancel (hts : t ⊆ s) (ha : a ∈ t) : s \ t ∪ t.erase a = s.erase a := by simp_rw [erase_eq, sdiff_union_sdiff_cancel hts (singleton_subset_iff.2 ha)] #align finset.sdiff_union_erase_cancel Finset.sdiff_union_erase_cancel theorem sdiff_sdiff_eq_sdiff_union (h : u ⊆ s) : s \ (t \ u) = s \ t ∪ u := sdiff_sdiff_eq_sdiff_sup h #align finset.sdiff_sdiff_eq_sdiff_union Finset.sdiff_sdiff_eq_sdiff_union theorem sdiff_insert (s t : Finset α) (x : α) : s \ insert x t = (s \ t).erase x := by simp_rw [← sdiff_singleton_eq_erase, insert_eq, sdiff_sdiff_left', sdiff_union_distrib, inter_comm] #align finset.sdiff_insert Finset.sdiff_insert theorem sdiff_insert_insert_of_mem_of_not_mem {s t : Finset α} {x : α} (hxs : x ∈ s) (hxt : x ∉ t) : insert x (s \ insert x t) = s \ t := by rw [sdiff_insert, insert_erase (mem_sdiff.mpr ⟨hxs, hxt⟩)] #align finset.sdiff_insert_insert_of_mem_of_not_mem Finset.sdiff_insert_insert_of_mem_of_not_mem theorem sdiff_erase (h : a ∈ s) : s \ t.erase a = insert a (s \ t) := by rw [← sdiff_singleton_eq_erase, sdiff_sdiff_eq_sdiff_union (singleton_subset_iff.2 h), insert_eq, union_comm] #align finset.sdiff_erase Finset.sdiff_erase theorem sdiff_erase_self (ha : a ∈ s) : s \ s.erase a = {a} := by rw [sdiff_erase ha, Finset.sdiff_self, insert_emptyc_eq] #align finset.sdiff_erase_self Finset.sdiff_erase_self theorem sdiff_sdiff_self_left (s t : Finset α) : s \ (s \ t) = s ∩ t := sdiff_sdiff_right_self #align finset.sdiff_sdiff_self_left Finset.sdiff_sdiff_self_left theorem sdiff_sdiff_eq_self (h : t ⊆ s) : s \ (s \ t) = t := _root_.sdiff_sdiff_eq_self h #align finset.sdiff_sdiff_eq_self Finset.sdiff_sdiff_eq_self theorem sdiff_eq_sdiff_iff_inter_eq_inter {s t₁ t₂ : Finset α} : s \ t₁ = s \ t₂ ↔ s ∩ t₁ = s ∩ t₂ := sdiff_eq_sdiff_iff_inf_eq_inf #align finset.sdiff_eq_sdiff_iff_inter_eq_inter Finset.sdiff_eq_sdiff_iff_inter_eq_inter theorem union_eq_sdiff_union_sdiff_union_inter (s t : Finset α) : s ∪ t = s \ t ∪ t \ s ∪ s ∩ t := sup_eq_sdiff_sup_sdiff_sup_inf #align finset.union_eq_sdiff_union_sdiff_union_inter Finset.union_eq_sdiff_union_sdiff_union_inter theorem erase_eq_empty_iff (s : Finset α) (a : α) : s.erase a = ∅ ↔ s = ∅ ∨ s = {a} := by rw [← sdiff_singleton_eq_erase, sdiff_eq_empty_iff_subset, subset_singleton_iff] #align finset.erase_eq_empty_iff Finset.erase_eq_empty_iff --TODO@Yaël: Kill lemmas duplicate with `BooleanAlgebra` theorem sdiff_disjoint : Disjoint (t \ s) s := disjoint_left.2 fun _a ha => (mem_sdiff.1 ha).2 #align finset.sdiff_disjoint Finset.sdiff_disjoint theorem disjoint_sdiff : Disjoint s (t \ s) := sdiff_disjoint.symm #align finset.disjoint_sdiff Finset.disjoint_sdiff theorem disjoint_sdiff_inter (s t : Finset α) : Disjoint (s \ t) (s ∩ t) := disjoint_of_subset_right inter_subset_right sdiff_disjoint #align finset.disjoint_sdiff_inter Finset.disjoint_sdiff_inter theorem sdiff_eq_self_iff_disjoint : s \ t = s ↔ Disjoint s t := sdiff_eq_self_iff_disjoint' #align finset.sdiff_eq_self_iff_disjoint Finset.sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_of_disjoint (h : Disjoint s t) : s \ t = s := sdiff_eq_self_iff_disjoint.2 h #align finset.sdiff_eq_self_of_disjoint Finset.sdiff_eq_self_of_disjoint end Sdiff /-! ### Symmetric difference -/ section SymmDiff open scoped symmDiff variable [DecidableEq α] {s t : Finset α} {a b : α} theorem mem_symmDiff : a ∈ s ∆ t ↔ a ∈ s ∧ a ∉ t ∨ a ∈ t ∧ a ∉ s := by simp_rw [symmDiff, sup_eq_union, mem_union, mem_sdiff] #align finset.mem_symm_diff Finset.mem_symmDiff @[simp, norm_cast] theorem coe_symmDiff : (↑(s ∆ t) : Set α) = (s : Set α) ∆ t := Set.ext fun x => by simp [mem_symmDiff, Set.mem_symmDiff] #align finset.coe_symm_diff Finset.coe_symmDiff @[simp] lemma symmDiff_eq_empty : s ∆ t = ∅ ↔ s = t := symmDiff_eq_bot @[simp] lemma symmDiff_nonempty : (s ∆ t).Nonempty ↔ s ≠ t := nonempty_iff_ne_empty.trans symmDiff_eq_empty.not end SymmDiff /-! ### attach -/ /-- `attach s` takes the elements of `s` and forms a new set of elements of the subtype `{x // x ∈ s}`. -/ def attach (s : Finset α) : Finset { x // x ∈ s } := ⟨Multiset.attach s.1, nodup_attach.2 s.2⟩ #align finset.attach Finset.attach theorem sizeOf_lt_sizeOf_of_mem [SizeOf α] {x : α} {s : Finset α} (hx : x ∈ s) : SizeOf.sizeOf x < SizeOf.sizeOf s := by cases s dsimp [SizeOf.sizeOf, SizeOf.sizeOf, Multiset.sizeOf] rw [add_comm] refine lt_trans ?_ (Nat.lt_succ_self _) exact Multiset.sizeOf_lt_sizeOf_of_mem hx #align finset.sizeof_lt_sizeof_of_mem Finset.sizeOf_lt_sizeOf_of_mem @[simp] theorem attach_val (s : Finset α) : s.attach.1 = s.1.attach := rfl #align finset.attach_val Finset.attach_val @[simp] theorem mem_attach (s : Finset α) : ∀ x, x ∈ s.attach := Multiset.mem_attach _ #align finset.mem_attach Finset.mem_attach @[simp] theorem attach_empty : attach (∅ : Finset α) = ∅ := rfl #align finset.attach_empty Finset.attach_empty @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem attach_nonempty_iff {s : Finset α} : s.attach.Nonempty ↔ s.Nonempty := by simp [Finset.Nonempty] #align finset.attach_nonempty_iff Finset.attach_nonempty_iff protected alias ⟨_, Nonempty.attach⟩ := attach_nonempty_iff @[simp] theorem attach_eq_empty_iff {s : Finset α} : s.attach = ∅ ↔ s = ∅ := by simp [eq_empty_iff_forall_not_mem] #align finset.attach_eq_empty_iff Finset.attach_eq_empty_iff section DecidablePiExists variable {s : Finset α} instance decidableDforallFinset {p : ∀ a ∈ s, Prop} [_hp : ∀ (a) (h : a ∈ s), Decidable (p a h)] : Decidable (∀ (a) (h : a ∈ s), p a h) := Multiset.decidableDforallMultiset #align finset.decidable_dforall_finset Finset.decidableDforallFinset -- Porting note: In lean3, `decidableDforallFinset` was picked up when decidability of `s ⊆ t` was -- needed. In lean4 it seems this is not the case. instance instDecidableRelSubset [DecidableEq α] : @DecidableRel (Finset α) (· ⊆ ·) := fun _ _ ↦ decidableDforallFinset instance instDecidableRelSSubset [DecidableEq α] : @DecidableRel (Finset α) (· ⊂ ·) := fun _ _ ↦ instDecidableAnd instance instDecidableLE [DecidableEq α] : @DecidableRel (Finset α) (· ≤ ·) := instDecidableRelSubset instance instDecidableLT [DecidableEq α] : @DecidableRel (Finset α) (· < ·) := instDecidableRelSSubset instance decidableDExistsFinset {p : ∀ a ∈ s, Prop} [_hp : ∀ (a) (h : a ∈ s), Decidable (p a h)] : Decidable (∃ (a : _) (h : a ∈ s), p a h) := Multiset.decidableDexistsMultiset #align finset.decidable_dexists_finset Finset.decidableDExistsFinset instance decidableExistsAndFinset {p : α → Prop} [_hp : ∀ (a), Decidable (p a)] : Decidable (∃ a ∈ s, p a) := decidable_of_iff (∃ (a : _) (_ : a ∈ s), p a) (by simp) instance decidableExistsAndFinsetCoe {p : α → Prop} [DecidablePred p] : Decidable (∃ a ∈ (s : Set α), p a) := decidableExistsAndFinset /-- decidable equality for functions whose domain is bounded by finsets -/ instance decidableEqPiFinset {β : α → Type*} [_h : ∀ a, DecidableEq (β a)] : DecidableEq (∀ a ∈ s, β a) := Multiset.decidableEqPiMultiset #align finset.decidable_eq_pi_finset Finset.decidableEqPiFinset end DecidablePiExists /-! ### filter -/ section Filter variable (p q : α → Prop) [DecidablePred p] [DecidablePred q] {s : Finset α} /-- `Finset.filter p s` is the set of elements of `s` that satisfy `p`. For example, one can use `s.filter (· ∈ t)` to get the intersection of `s` with `t : Set α` as a `Finset α` (when a `DecidablePred (· ∈ t)` instance is available). -/ def filter (s : Finset α) : Finset α := ⟨_, s.2.filter p⟩ #align finset.filter Finset.filter @[simp] theorem filter_val (s : Finset α) : (filter p s).1 = s.1.filter p := rfl #align finset.filter_val Finset.filter_val @[simp] theorem filter_subset (s : Finset α) : s.filter p ⊆ s := Multiset.filter_subset _ _ #align finset.filter_subset Finset.filter_subset variable {p} @[simp] theorem mem_filter {s : Finset α} {a : α} : a ∈ s.filter p ↔ a ∈ s ∧ p a := Multiset.mem_filter #align finset.mem_filter Finset.mem_filter theorem mem_of_mem_filter {s : Finset α} (x : α) (h : x ∈ s.filter p) : x ∈ s := Multiset.mem_of_mem_filter h #align finset.mem_of_mem_filter Finset.mem_of_mem_filter theorem filter_ssubset {s : Finset α} : s.filter p ⊂ s ↔ ∃ x ∈ s, ¬p x := ⟨fun h => let ⟨x, hs, hp⟩ := Set.exists_of_ssubset h ⟨x, hs, mt (fun hp => mem_filter.2 ⟨hs, hp⟩) hp⟩, fun ⟨_, hs, hp⟩ => ⟨s.filter_subset _, fun h => hp (mem_filter.1 (h hs)).2⟩⟩ #align finset.filter_ssubset Finset.filter_ssubset variable (p) theorem filter_filter (s : Finset α) : (s.filter p).filter q = s.filter fun a => p a ∧ q a := ext fun a => by simp only [mem_filter, and_assoc, Bool.decide_and, Bool.decide_coe, Bool.and_eq_true] #align finset.filter_filter Finset.filter_filter theorem filter_comm (s : Finset α) : (s.filter p).filter q = (s.filter q).filter p := by simp_rw [filter_filter, and_comm] #align finset.filter_comm Finset.filter_comm -- We can replace an application of filter where the decidability is inferred in "the wrong way". theorem filter_congr_decidable (s : Finset α) (p : α → Prop) (h : DecidablePred p) [DecidablePred p] : @filter α p h s = s.filter p := by congr #align finset.filter_congr_decidable Finset.filter_congr_decidable @[simp] theorem filter_True {h} (s : Finset α) : @filter _ (fun _ => True) h s = s := by ext; simp #align finset.filter_true Finset.filter_True @[simp] theorem filter_False {h} (s : Finset α) : @filter _ (fun _ => False) h s = ∅ := by ext; simp #align finset.filter_false Finset.filter_False variable {p q} lemma filter_eq_self : s.filter p = s ↔ ∀ x ∈ s, p x := by simp [Finset.ext_iff] #align finset.filter_eq_self Finset.filter_eq_self theorem filter_eq_empty_iff : s.filter p = ∅ ↔ ∀ ⦃x⦄, x ∈ s → ¬p x := by simp [Finset.ext_iff] #align finset.filter_eq_empty_iff Finset.filter_eq_empty_iff theorem filter_nonempty_iff : (s.filter p).Nonempty ↔ ∃ a ∈ s, p a := by simp only [nonempty_iff_ne_empty, Ne, filter_eq_empty_iff, Classical.not_not, not_forall, exists_prop] #align finset.filter_nonempty_iff Finset.filter_nonempty_iff /-- If all elements of a `Finset` satisfy the predicate `p`, `s.filter p` is `s`. -/ theorem filter_true_of_mem (h : ∀ x ∈ s, p x) : s.filter p = s := filter_eq_self.2 h #align finset.filter_true_of_mem Finset.filter_true_of_mem /-- If all elements of a `Finset` fail to satisfy the predicate `p`, `s.filter p` is `∅`. -/ theorem filter_false_of_mem (h : ∀ x ∈ s, ¬p x) : s.filter p = ∅ := filter_eq_empty_iff.2 h #align finset.filter_false_of_mem Finset.filter_false_of_mem @[simp] theorem filter_const (p : Prop) [Decidable p] (s : Finset α) : (s.filter fun _a => p) = if p then s else ∅ := by split_ifs <;> simp [*] #align finset.filter_const Finset.filter_const theorem filter_congr {s : Finset α} (H : ∀ x ∈ s, p x ↔ q x) : filter p s = filter q s := eq_of_veq <| Multiset.filter_congr H #align finset.filter_congr Finset.filter_congr variable (p q) @[simp] theorem filter_empty : filter p ∅ = ∅ := subset_empty.1 <| filter_subset _ _ #align finset.filter_empty Finset.filter_empty @[gcongr] theorem filter_subset_filter {s t : Finset α} (h : s ⊆ t) : s.filter p ⊆ t.filter p := fun _a ha => mem_filter.2 ⟨h (mem_filter.1 ha).1, (mem_filter.1 ha).2⟩ #align finset.filter_subset_filter Finset.filter_subset_filter theorem monotone_filter_left : Monotone (filter p) := fun _ _ => filter_subset_filter p #align finset.monotone_filter_left Finset.monotone_filter_left -- TODO: `@[gcongr]` doesn't accept this lemma because of the `DecidablePred` arguments theorem monotone_filter_right (s : Finset α) ⦃p q : α → Prop⦄ [DecidablePred p] [DecidablePred q] (h : p ≤ q) : s.filter p ⊆ s.filter q := Multiset.subset_of_le (Multiset.monotone_filter_right s.val h) #align finset.monotone_filter_right Finset.monotone_filter_right @[simp, norm_cast] theorem coe_filter (s : Finset α) : ↑(s.filter p) = ({ x ∈ ↑s | p x } : Set α) := Set.ext fun _ => mem_filter #align finset.coe_filter Finset.coe_filter theorem subset_coe_filter_of_subset_forall (s : Finset α) {t : Set α} (h₁ : t ⊆ s) (h₂ : ∀ x ∈ t, p x) : t ⊆ s.filter p := fun x hx => (s.coe_filter p).symm ▸ ⟨h₁ hx, h₂ x hx⟩ #align finset.subset_coe_filter_of_subset_forall Finset.subset_coe_filter_of_subset_forall theorem filter_singleton (a : α) : filter p {a} = if p a then {a} else ∅ := by classical ext x simp only [mem_singleton, forall_eq, mem_filter] split_ifs with h <;> by_cases h' : x = a <;> simp [h, h'] #align finset.filter_singleton Finset.filter_singleton theorem filter_cons_of_pos (a : α) (s : Finset α) (ha : a ∉ s) (hp : p a) : filter p (cons a s ha) = cons a (filter p s) (mem_filter.not.mpr <| mt And.left ha) := eq_of_veq <| Multiset.filter_cons_of_pos s.val hp #align finset.filter_cons_of_pos Finset.filter_cons_of_pos theorem filter_cons_of_neg (a : α) (s : Finset α) (ha : a ∉ s) (hp : ¬p a) : filter p (cons a s ha) = filter p s := eq_of_veq <| Multiset.filter_cons_of_neg s.val hp #align finset.filter_cons_of_neg Finset.filter_cons_of_neg theorem disjoint_filter {s : Finset α} {p q : α → Prop} [DecidablePred p] [DecidablePred q] : Disjoint (s.filter p) (s.filter q) ↔ ∀ x ∈ s, p x → ¬q x := by constructor <;> simp (config := { contextual := true }) [disjoint_left] #align finset.disjoint_filter Finset.disjoint_filter theorem disjoint_filter_filter {s t : Finset α} {p q : α → Prop} [DecidablePred p] [DecidablePred q] : Disjoint s t → Disjoint (s.filter p) (t.filter q) := Disjoint.mono (filter_subset _ _) (filter_subset _ _) #align finset.disjoint_filter_filter Finset.disjoint_filter_filter theorem disjoint_filter_filter' (s t : Finset α) {p q : α → Prop} [DecidablePred p] [DecidablePred q] (h : Disjoint p q) : Disjoint (s.filter p) (t.filter q) := by simp_rw [disjoint_left, mem_filter] rintro a ⟨_, hp⟩ ⟨_, hq⟩ rw [Pi.disjoint_iff] at h simpa [hp, hq] using h a #align finset.disjoint_filter_filter' Finset.disjoint_filter_filter' theorem disjoint_filter_filter_neg (s t : Finset α) (p : α → Prop) [DecidablePred p] [∀ x, Decidable (¬p x)] : Disjoint (s.filter p) (t.filter fun a => ¬p a) := disjoint_filter_filter' s t disjoint_compl_right #align finset.disjoint_filter_filter_neg Finset.disjoint_filter_filter_neg theorem filter_disj_union (s : Finset α) (t : Finset α) (h : Disjoint s t) : filter p (disjUnion s t h) = (filter p s).disjUnion (filter p t) (disjoint_filter_filter h) := eq_of_veq <| Multiset.filter_add _ _ _ #align finset.filter_disj_union Finset.filter_disj_union lemma _root_.Set.pairwiseDisjoint_filter [DecidableEq β] (f : α → β) (s : Set β) (t : Finset α) : s.PairwiseDisjoint fun x ↦ t.filter (f · = x) := by rintro i - j - h u hi hj x hx obtain ⟨-, rfl⟩ : x ∈ t ∧ f x = i := by simpa using hi hx obtain ⟨-, rfl⟩ : x ∈ t ∧ f x = j := by simpa using hj hx contradiction theorem filter_cons {a : α} (s : Finset α) (ha : a ∉ s) : filter p (cons a s ha) = (if p a then {a} else ∅ : Finset α).disjUnion (filter p s) (by split_ifs · rw [disjoint_singleton_left] exact mem_filter.not.mpr <| mt And.left ha · exact disjoint_empty_left _) := by split_ifs with h · rw [filter_cons_of_pos _ _ _ ha h, singleton_disjUnion] · rw [filter_cons_of_neg _ _ _ ha h, empty_disjUnion] #align finset.filter_cons Finset.filter_cons variable [DecidableEq α] theorem filter_union (s₁ s₂ : Finset α) : (s₁ ∪ s₂).filter p = s₁.filter p ∪ s₂.filter p := ext fun _ => by simp only [mem_filter, mem_union, or_and_right] #align finset.filter_union Finset.filter_union theorem filter_union_right (s : Finset α) : s.filter p ∪ s.filter q = s.filter fun x => p x ∨ q x := ext fun x => by simp [mem_filter, mem_union, ← and_or_left] #align finset.filter_union_right Finset.filter_union_right theorem filter_mem_eq_inter {s t : Finset α} [∀ i, Decidable (i ∈ t)] : (s.filter fun i => i ∈ t) = s ∩ t := ext fun i => by simp [mem_filter, mem_inter] #align finset.filter_mem_eq_inter Finset.filter_mem_eq_inter theorem filter_inter_distrib (s t : Finset α) : (s ∩ t).filter p = s.filter p ∩ t.filter p := by ext simp [mem_filter, mem_inter, and_assoc] #align finset.filter_inter_distrib Finset.filter_inter_distrib theorem filter_inter (s t : Finset α) : filter p s ∩ t = filter p (s ∩ t) := by ext simp only [mem_inter, mem_filter, and_right_comm] #align finset.filter_inter Finset.filter_inter theorem inter_filter (s t : Finset α) : s ∩ filter p t = filter p (s ∩ t) := by rw [inter_comm, filter_inter, inter_comm] #align finset.inter_filter Finset.inter_filter theorem filter_insert (a : α) (s : Finset α) : filter p (insert a s) = if p a then insert a (filter p s) else filter p s := by ext x split_ifs with h <;> by_cases h' : x = a <;> simp [h, h'] #align finset.filter_insert Finset.filter_insert theorem filter_erase (a : α) (s : Finset α) : filter p (erase s a) = erase (filter p s) a := by ext x simp only [and_assoc, mem_filter, iff_self_iff, mem_erase] #align finset.filter_erase Finset.filter_erase theorem filter_or (s : Finset α) : (s.filter fun a => p a ∨ q a) = s.filter p ∪ s.filter q := ext fun _ => by simp [mem_filter, mem_union, and_or_left] #align finset.filter_or Finset.filter_or theorem filter_and (s : Finset α) : (s.filter fun a => p a ∧ q a) = s.filter p ∩ s.filter q := ext fun _ => by simp [mem_filter, mem_inter, and_comm, and_left_comm, and_self_iff, and_assoc] #align finset.filter_and Finset.filter_and theorem filter_not (s : Finset α) : (s.filter fun a => ¬p a) = s \ s.filter p := ext fun a => by simp only [Bool.decide_coe, Bool.not_eq_true', mem_filter, and_comm, mem_sdiff, not_and_or, Bool.not_eq_true, and_or_left, and_not_self, or_false] #align finset.filter_not Finset.filter_not lemma filter_and_not (s : Finset α) (p q : α → Prop) [DecidablePred p] [DecidablePred q] : s.filter (fun a ↦ p a ∧ ¬ q a) = s.filter p \ s.filter q := by rw [filter_and, filter_not, ← inter_sdiff_assoc, inter_eq_left.2 (filter_subset _ _)] theorem sdiff_eq_filter (s₁ s₂ : Finset α) : s₁ \ s₂ = filter (· ∉ s₂) s₁ := ext fun _ => by simp [mem_sdiff, mem_filter] #align finset.sdiff_eq_filter Finset.sdiff_eq_filter theorem sdiff_eq_self (s₁ s₂ : Finset α) : s₁ \ s₂ = s₁ ↔ s₁ ∩ s₂ ⊆ ∅ := by simp [Subset.antisymm_iff, disjoint_iff_inter_eq_empty] #align finset.sdiff_eq_self Finset.sdiff_eq_self theorem subset_union_elim {s : Finset α} {t₁ t₂ : Set α} (h : ↑s ⊆ t₁ ∪ t₂) : ∃ s₁ s₂ : Finset α, s₁ ∪ s₂ = s ∧ ↑s₁ ⊆ t₁ ∧ ↑s₂ ⊆ t₂ \ t₁ := by classical refine ⟨s.filter (· ∈ t₁), s.filter (· ∉ t₁), ?_, ?_, ?_⟩ · simp [filter_union_right, em] · intro x simp · intro x simp only [not_not, coe_filter, Set.mem_setOf_eq, Set.mem_diff, and_imp] intro hx hx₂ exact ⟨Or.resolve_left (h hx) hx₂, hx₂⟩ #align finset.subset_union_elim Finset.subset_union_elim section Classical open scoped Classical -- Porting note: The notation `{ x ∈ s | p x }` in Lean 4 is hardcoded to be about `Set`. -- So at the moment the whole `Sep`-class is useless, as it doesn't have notation. -- /-- The following instance allows us to write `{x ∈ s | p x}` for `Finset.filter p s`. -- We don't want to redo all lemmas of `Finset.filter` for `Sep.sep`, so we make sure that `simp` -- unfolds the notation `{x ∈ s | p x}` to `Finset.filter p s`. -- -/ -- noncomputable instance {α : Type*} : Sep α (Finset α) := -- ⟨fun p x => x.filter p⟩ -- -- @[simp] -- Porting note: not a simp-lemma until `Sep`-notation is fixed. -- theorem sep_def {α : Type*} (s : Finset α) (p : α → Prop) : { x ∈ s | p x } = s.filter p := by -- ext -- simp -- #align finset.sep_def Finset.sep_def end Classical -- This is not a good simp lemma, as it would prevent `Finset.mem_filter` from firing -- on, e.g. `x ∈ s.filter (Eq b)`. /-- After filtering out everything that does not equal a given value, at most that value remains. This is equivalent to `filter_eq'` with the equality the other way. -/ theorem filter_eq [DecidableEq β] (s : Finset β) (b : β) : s.filter (Eq b) = ite (b ∈ s) {b} ∅ := by split_ifs with h · ext simp only [mem_filter, mem_singleton, decide_eq_true_eq] refine ⟨fun h => h.2.symm, ?_⟩ rintro rfl exact ⟨h, rfl⟩ · ext simp only [mem_filter, not_and, iff_false_iff, not_mem_empty, decide_eq_true_eq] rintro m rfl exact h m #align finset.filter_eq Finset.filter_eq /-- After filtering out everything that does not equal a given value, at most that value remains. This is equivalent to `filter_eq` with the equality the other way. -/ theorem filter_eq' [DecidableEq β] (s : Finset β) (b : β) : (s.filter fun a => a = b) = ite (b ∈ s) {b} ∅ := _root_.trans (filter_congr fun _ _ => by simp_rw [@eq_comm _ b]) (filter_eq s b) #align finset.filter_eq' Finset.filter_eq' theorem filter_ne [DecidableEq β] (s : Finset β) (b : β) : (s.filter fun a => b ≠ a) = s.erase b := by ext simp only [mem_filter, mem_erase, Ne, decide_not, Bool.not_eq_true', decide_eq_false_iff_not] tauto #align finset.filter_ne Finset.filter_ne theorem filter_ne' [DecidableEq β] (s : Finset β) (b : β) : (s.filter fun a => a ≠ b) = s.erase b := _root_.trans (filter_congr fun _ _ => by simp_rw [@ne_comm _ b]) (filter_ne s b) #align finset.filter_ne' Finset.filter_ne' theorem filter_inter_filter_neg_eq (s t : Finset α) : (s.filter p ∩ t.filter fun a => ¬p a) = ∅ := by simpa using (disjoint_filter_filter_neg s t p).eq_bot #align finset.filter_inter_filter_neg_eq Finset.filter_inter_filter_neg_eq theorem filter_union_filter_of_codisjoint (s : Finset α) (h : Codisjoint p q) : s.filter p ∪ s.filter q = s := (filter_or _ _ _).symm.trans <| filter_true_of_mem fun x _ => h.top_le x trivial #align finset.filter_union_filter_of_codisjoint Finset.filter_union_filter_of_codisjoint theorem filter_union_filter_neg_eq [∀ x, Decidable (¬p x)] (s : Finset α) : (s.filter p ∪ s.filter fun a => ¬p a) = s := filter_union_filter_of_codisjoint _ _ _ <| @codisjoint_hnot_right _ _ p #align finset.filter_union_filter_neg_eq Finset.filter_union_filter_neg_eq end Filter /-! ### range -/ section Range variable {n m l : ℕ} /-- `range n` is the set of natural numbers less than `n`. -/ def range (n : ℕ) : Finset ℕ := ⟨_, nodup_range n⟩ #align finset.range Finset.range @[simp] theorem range_val (n : ℕ) : (range n).1 = Multiset.range n := rfl #align finset.range_val Finset.range_val @[simp] theorem mem_range : m ∈ range n ↔ m < n := Multiset.mem_range #align finset.mem_range Finset.mem_range @[simp, norm_cast] theorem coe_range (n : ℕ) : (range n : Set ℕ) = Set.Iio n := Set.ext fun _ => mem_range #align finset.coe_range Finset.coe_range @[simp] theorem range_zero : range 0 = ∅ := rfl #align finset.range_zero Finset.range_zero @[simp] theorem range_one : range 1 = {0} := rfl #align finset.range_one Finset.range_one theorem range_succ : range (succ n) = insert n (range n) := eq_of_veq <| (Multiset.range_succ n).trans <| (ndinsert_of_not_mem not_mem_range_self).symm #align finset.range_succ Finset.range_succ theorem range_add_one : range (n + 1) = insert n (range n) := range_succ #align finset.range_add_one Finset.range_add_one -- Porting note (#10618): @[simp] can prove this theorem not_mem_range_self : n ∉ range n := Multiset.not_mem_range_self #align finset.not_mem_range_self Finset.not_mem_range_self -- Porting note (#10618): @[simp] can prove this theorem self_mem_range_succ (n : ℕ) : n ∈ range (n + 1) := Multiset.self_mem_range_succ n #align finset.self_mem_range_succ Finset.self_mem_range_succ @[simp] theorem range_subset {n m} : range n ⊆ range m ↔ n ≤ m := Multiset.range_subset #align finset.range_subset Finset.range_subset theorem range_mono : Monotone range := fun _ _ => range_subset.2 #align finset.range_mono Finset.range_mono @[gcongr] alias ⟨_, _root_.GCongr.finset_range_subset_of_le⟩ := range_subset theorem mem_range_succ_iff {a b : ℕ} : a ∈ Finset.range b.succ ↔ a ≤ b := Finset.mem_range.trans Nat.lt_succ_iff #align finset.mem_range_succ_iff Finset.mem_range_succ_iff theorem mem_range_le {n x : ℕ} (hx : x ∈ range n) : x ≤ n := (mem_range.1 hx).le #align finset.mem_range_le Finset.mem_range_le theorem mem_range_sub_ne_zero {n x : ℕ} (hx : x ∈ range n) : n - x ≠ 0 := _root_.ne_of_gt <| Nat.sub_pos_of_lt <| mem_range.1 hx #align finset.mem_range_sub_ne_zero Finset.mem_range_sub_ne_zero @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem nonempty_range_iff : (range n).Nonempty ↔ n ≠ 0 := ⟨fun ⟨k, hk⟩ => (k.zero_le.trans_lt <| mem_range.1 hk).ne', fun h => ⟨0, mem_range.2 <| Nat.pos_iff_ne_zero.2 h⟩⟩ #align finset.nonempty_range_iff Finset.nonempty_range_iff @[simp] theorem range_eq_empty_iff : range n = ∅ ↔ n = 0 := by rw [← not_nonempty_iff_eq_empty, nonempty_range_iff, not_not] #align finset.range_eq_empty_iff Finset.range_eq_empty_iff theorem nonempty_range_succ : (range <| n + 1).Nonempty := nonempty_range_iff.2 n.succ_ne_zero #align finset.nonempty_range_succ Finset.nonempty_range_succ @[simp] theorem range_filter_eq {n m : ℕ} : (range n).filter (· = m) = if m < n then {m} else ∅ := by convert filter_eq (range n) m using 2 · ext rw [eq_comm] · simp #align finset.range_filter_eq Finset.range_filter_eq lemma range_nontrivial {n : ℕ} (hn : 1 < n) : (Finset.range n).Nontrivial := by rw [Finset.Nontrivial, Finset.coe_range] exact ⟨0, Nat.zero_lt_one.trans hn, 1, hn, zero_ne_one⟩ end Range -- useful rules for calculations with quantifiers theorem exists_mem_empty_iff (p : α → Prop) : (∃ x, x ∈ (∅ : Finset α) ∧ p x) ↔ False := by simp only [not_mem_empty, false_and_iff, exists_false] #align finset.exists_mem_empty_iff Finset.exists_mem_empty_iff theorem exists_mem_insert [DecidableEq α] (a : α) (s : Finset α) (p : α → Prop) : (∃ x, x ∈ insert a s ∧ p x) ↔ p a ∨ ∃ x, x ∈ s ∧ p x := by simp only [mem_insert, or_and_right, exists_or, exists_eq_left] #align finset.exists_mem_insert Finset.exists_mem_insert theorem forall_mem_empty_iff (p : α → Prop) : (∀ x, x ∈ (∅ : Finset α) → p x) ↔ True := iff_true_intro fun _ h => False.elim <| not_mem_empty _ h #align finset.forall_mem_empty_iff Finset.forall_mem_empty_iff theorem forall_mem_insert [DecidableEq α] (a : α) (s : Finset α) (p : α → Prop) : (∀ x, x ∈ insert a s → p x) ↔ p a ∧ ∀ x, x ∈ s → p x := by simp only [mem_insert, or_imp, forall_and, forall_eq] #align finset.forall_mem_insert Finset.forall_mem_insert /-- Useful in proofs by induction. -/ theorem forall_of_forall_insert [DecidableEq α] {p : α → Prop} {a : α} {s : Finset α} (H : ∀ x, x ∈ insert a s → p x) (x) (h : x ∈ s) : p x := H _ <| mem_insert_of_mem h #align finset.forall_of_forall_insert Finset.forall_of_forall_insert end Finset /-- Equivalence between the set of natural numbers which are `≥ k` and `ℕ`, given by `n → n - k`. -/ def notMemRangeEquiv (k : ℕ) : { n // n ∉ range k } ≃ ℕ where toFun i := i.1 - k invFun j := ⟨j + k, by simp⟩ left_inv j := by rw [Subtype.ext_iff_val] apply Nat.sub_add_cancel simpa using j.2 right_inv j := Nat.add_sub_cancel_right _ _ #align not_mem_range_equiv notMemRangeEquiv @[simp] theorem coe_notMemRangeEquiv (k : ℕ) : (notMemRangeEquiv k : { n // n ∉ range k } → ℕ) = fun (i : { n // n ∉ range k }) => i - k := rfl #align coe_not_mem_range_equiv coe_notMemRangeEquiv @[simp] theorem coe_notMemRangeEquiv_symm (k : ℕ) : ((notMemRangeEquiv k).symm : ℕ → { n // n ∉ range k }) = fun j => ⟨j + k, by simp⟩ := rfl #align coe_not_mem_range_equiv_symm coe_notMemRangeEquiv_symm /-! ### dedup on list and multiset -/ namespace Multiset variable [DecidableEq α] {s t : Multiset α} /-- `toFinset s` removes duplicates from the multiset `s` to produce a finset. -/ def toFinset (s : Multiset α) : Finset α := ⟨_, nodup_dedup s⟩ #align multiset.to_finset Multiset.toFinset @[simp] theorem toFinset_val (s : Multiset α) : s.toFinset.1 = s.dedup := rfl #align multiset.to_finset_val Multiset.toFinset_val theorem toFinset_eq {s : Multiset α} (n : Nodup s) : Finset.mk s n = s.toFinset := Finset.val_inj.1 n.dedup.symm #align multiset.to_finset_eq Multiset.toFinset_eq theorem Nodup.toFinset_inj {l l' : Multiset α} (hl : Nodup l) (hl' : Nodup l') (h : l.toFinset = l'.toFinset) : l = l' := by simpa [← toFinset_eq hl, ← toFinset_eq hl'] using h #align multiset.nodup.to_finset_inj Multiset.Nodup.toFinset_inj @[simp] theorem mem_toFinset {a : α} {s : Multiset α} : a ∈ s.toFinset ↔ a ∈ s := mem_dedup #align multiset.mem_to_finset Multiset.mem_toFinset @[simp] theorem toFinset_zero : toFinset (0 : Multiset α) = ∅ := rfl #align multiset.to_finset_zero Multiset.toFinset_zero @[simp] theorem toFinset_cons (a : α) (s : Multiset α) : toFinset (a ::ₘ s) = insert a (toFinset s) := Finset.eq_of_veq dedup_cons #align multiset.to_finset_cons Multiset.toFinset_cons @[simp] theorem toFinset_singleton (a : α) : toFinset ({a} : Multiset α) = {a} := by rw [← cons_zero, toFinset_cons, toFinset_zero, LawfulSingleton.insert_emptyc_eq] #align multiset.to_finset_singleton Multiset.toFinset_singleton @[simp] theorem toFinset_add (s t : Multiset α) : toFinset (s + t) = toFinset s ∪ toFinset t := Finset.ext <| by simp #align multiset.to_finset_add Multiset.toFinset_add @[simp] theorem toFinset_nsmul (s : Multiset α) : ∀ n ≠ 0, (n • s).toFinset = s.toFinset | 0, h => by contradiction | n + 1, _ => by by_cases h : n = 0 · rw [h, zero_add, one_nsmul] · rw [add_nsmul, toFinset_add, one_nsmul, toFinset_nsmul s n h, Finset.union_idempotent] #align multiset.to_finset_nsmul Multiset.toFinset_nsmul theorem toFinset_eq_singleton_iff (s : Multiset α) (a : α) : s.toFinset = {a} ↔ card s ≠ 0 ∧ s = card s • {a} := by refine ⟨fun H ↦ ⟨fun h ↦ ?_, ext' fun x ↦ ?_⟩, fun H ↦ ?_⟩ · rw [card_eq_zero.1 h, toFinset_zero] at H exact Finset.singleton_ne_empty _ H.symm · rw [count_nsmul, count_singleton] by_cases hx : x = a · simp_rw [hx, ite_true, mul_one, count_eq_card] intro y hy rw [← mem_toFinset, H, Finset.mem_singleton] at hy exact hy.symm have hx' : x ∉ s := fun h' ↦ hx <| by rwa [← mem_toFinset, H, Finset.mem_singleton] at h' simp_rw [count_eq_zero_of_not_mem hx', hx, ite_false, Nat.mul_zero] simpa only [toFinset_nsmul _ _ H.1, toFinset_singleton] using congr($(H.2).toFinset) @[simp] theorem toFinset_inter (s t : Multiset α) : toFinset (s ∩ t) = toFinset s ∩ toFinset t := Finset.ext <| by simp #align multiset.to_finset_inter Multiset.toFinset_inter @[simp] theorem toFinset_union (s t : Multiset α) : (s ∪ t).toFinset = s.toFinset ∪ t.toFinset := by ext; simp #align multiset.to_finset_union Multiset.toFinset_union @[simp] theorem toFinset_eq_empty {m : Multiset α} : m.toFinset = ∅ ↔ m = 0 := Finset.val_inj.symm.trans Multiset.dedup_eq_zero #align multiset.to_finset_eq_empty Multiset.toFinset_eq_empty @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem toFinset_nonempty : s.toFinset.Nonempty ↔ s ≠ 0 := by simp only [toFinset_eq_empty, Ne, Finset.nonempty_iff_ne_empty] #align multiset.to_finset_nonempty Multiset.toFinset_nonempty @[simp]
Mathlib/Data/Finset/Basic.lean
3,170
3,171
theorem toFinset_subset : s.toFinset ⊆ t.toFinset ↔ s ⊆ t := by
simp only [Finset.subset_iff, Multiset.subset_iff, Multiset.mem_toFinset]
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Algebra.GroupPower.IterateHom import Mathlib.Algebra.Polynomial.Eval import Mathlib.GroupTheory.GroupAction.Ring #align_import data.polynomial.derivative from "leanprover-community/mathlib"@"bbeb185db4ccee8ed07dc48449414ebfa39cb821" /-! # The derivative map on polynomials ## Main definitions * `Polynomial.derivative`: The formal derivative of polynomials, expressed as a linear map. -/ noncomputable section open Finset open Polynomial namespace Polynomial universe u v w y z variable {R : Type u} {S : Type v} {T : Type w} {ι : Type y} {A : Type z} {a b : R} {n : ℕ} section Derivative section Semiring variable [Semiring R] /-- `derivative p` is the formal derivative of the polynomial `p` -/ def derivative : R[X] →ₗ[R] R[X] where toFun p := p.sum fun n a => C (a * n) * X ^ (n - 1) map_add' p q := by dsimp only rw [sum_add_index] <;> simp only [add_mul, forall_const, RingHom.map_add, eq_self_iff_true, zero_mul, RingHom.map_zero] map_smul' a p := by dsimp; rw [sum_smul_index] <;> simp only [mul_sum, ← C_mul', mul_assoc, coeff_C_mul, RingHom.map_mul, forall_const, zero_mul, RingHom.map_zero, sum] #align polynomial.derivative Polynomial.derivative theorem derivative_apply (p : R[X]) : derivative p = p.sum fun n a => C (a * n) * X ^ (n - 1) := rfl #align polynomial.derivative_apply Polynomial.derivative_apply theorem coeff_derivative (p : R[X]) (n : ℕ) : coeff (derivative p) n = coeff p (n + 1) * (n + 1) := by rw [derivative_apply] simp only [coeff_X_pow, coeff_sum, coeff_C_mul] rw [sum, Finset.sum_eq_single (n + 1)] · simp only [Nat.add_succ_sub_one, add_zero, mul_one, if_true, eq_self_iff_true]; norm_cast · intro b cases b · intros rw [Nat.cast_zero, mul_zero, zero_mul] · intro _ H rw [Nat.add_one_sub_one, if_neg (mt (congr_arg Nat.succ) H.symm), mul_zero] · rw [if_pos (add_tsub_cancel_right n 1).symm, mul_one, Nat.cast_add, Nat.cast_one, mem_support_iff] intro h push_neg at h simp [h] #align polynomial.coeff_derivative Polynomial.coeff_derivative -- Porting note (#10618): removed `simp`: `simp` can prove it. theorem derivative_zero : derivative (0 : R[X]) = 0 := derivative.map_zero #align polynomial.derivative_zero Polynomial.derivative_zero theorem iterate_derivative_zero {k : ℕ} : derivative^[k] (0 : R[X]) = 0 := iterate_map_zero derivative k #align polynomial.iterate_derivative_zero Polynomial.iterate_derivative_zero @[simp] theorem derivative_monomial (a : R) (n : ℕ) : derivative (monomial n a) = monomial (n - 1) (a * n) := by rw [derivative_apply, sum_monomial_index, C_mul_X_pow_eq_monomial] simp #align polynomial.derivative_monomial Polynomial.derivative_monomial theorem derivative_C_mul_X (a : R) : derivative (C a * X) = C a := by simp [C_mul_X_eq_monomial, derivative_monomial, Nat.cast_one, mul_one] set_option linter.uppercaseLean3 false in #align polynomial.derivative_C_mul_X Polynomial.derivative_C_mul_X theorem derivative_C_mul_X_pow (a : R) (n : ℕ) : derivative (C a * X ^ n) = C (a * n) * X ^ (n - 1) := by rw [C_mul_X_pow_eq_monomial, C_mul_X_pow_eq_monomial, derivative_monomial] set_option linter.uppercaseLean3 false in #align polynomial.derivative_C_mul_X_pow Polynomial.derivative_C_mul_X_pow theorem derivative_C_mul_X_sq (a : R) : derivative (C a * X ^ 2) = C (a * 2) * X := by rw [derivative_C_mul_X_pow, Nat.cast_two, pow_one] set_option linter.uppercaseLean3 false in #align polynomial.derivative_C_mul_X_sq Polynomial.derivative_C_mul_X_sq @[simp] theorem derivative_X_pow (n : ℕ) : derivative (X ^ n : R[X]) = C (n : R) * X ^ (n - 1) := by convert derivative_C_mul_X_pow (1 : R) n <;> simp set_option linter.uppercaseLean3 false in #align polynomial.derivative_X_pow Polynomial.derivative_X_pow -- Porting note (#10618): removed `simp`: `simp` can prove it. theorem derivative_X_sq : derivative (X ^ 2 : R[X]) = C 2 * X := by rw [derivative_X_pow, Nat.cast_two, pow_one] set_option linter.uppercaseLean3 false in #align polynomial.derivative_X_sq Polynomial.derivative_X_sq @[simp] theorem derivative_C {a : R} : derivative (C a) = 0 := by simp [derivative_apply] set_option linter.uppercaseLean3 false in #align polynomial.derivative_C Polynomial.derivative_C theorem derivative_of_natDegree_zero {p : R[X]} (hp : p.natDegree = 0) : derivative p = 0 := by rw [eq_C_of_natDegree_eq_zero hp, derivative_C] #align polynomial.derivative_of_nat_degree_zero Polynomial.derivative_of_natDegree_zero @[simp] theorem derivative_X : derivative (X : R[X]) = 1 := (derivative_monomial _ _).trans <| by simp set_option linter.uppercaseLean3 false in #align polynomial.derivative_X Polynomial.derivative_X @[simp] theorem derivative_one : derivative (1 : R[X]) = 0 := derivative_C #align polynomial.derivative_one Polynomial.derivative_one #noalign polynomial.derivative_bit0 #noalign polynomial.derivative_bit1 -- Porting note (#10618): removed `simp`: `simp` can prove it. theorem derivative_add {f g : R[X]} : derivative (f + g) = derivative f + derivative g := derivative.map_add f g #align polynomial.derivative_add Polynomial.derivative_add -- Porting note (#10618): removed `simp`: `simp` can prove it. theorem derivative_X_add_C (c : R) : derivative (X + C c) = 1 := by rw [derivative_add, derivative_X, derivative_C, add_zero] set_option linter.uppercaseLean3 false in #align polynomial.derivative_X_add_C Polynomial.derivative_X_add_C -- Porting note (#10618): removed `simp`: `simp` can prove it. theorem derivative_sum {s : Finset ι} {f : ι → R[X]} : derivative (∑ b ∈ s, f b) = ∑ b ∈ s, derivative (f b) := map_sum .. #align polynomial.derivative_sum Polynomial.derivative_sum -- Porting note (#10618): removed `simp`: `simp` can prove it. theorem derivative_smul {S : Type*} [Monoid S] [DistribMulAction S R] [IsScalarTower S R R] (s : S) (p : R[X]) : derivative (s • p) = s • derivative p := derivative.map_smul_of_tower s p #align polynomial.derivative_smul Polynomial.derivative_smul @[simp] theorem iterate_derivative_smul {S : Type*} [Monoid S] [DistribMulAction S R] [IsScalarTower S R R] (s : S) (p : R[X]) (k : ℕ) : derivative^[k] (s • p) = s • derivative^[k] p := by induction' k with k ih generalizing p · simp · simp [ih] #align polynomial.iterate_derivative_smul Polynomial.iterate_derivative_smul @[simp] theorem iterate_derivative_C_mul (a : R) (p : R[X]) (k : ℕ) : derivative^[k] (C a * p) = C a * derivative^[k] p := by simp_rw [← smul_eq_C_mul, iterate_derivative_smul] set_option linter.uppercaseLean3 false in #align polynomial.iterate_derivative_C_mul Polynomial.iterate_derivative_C_mul theorem of_mem_support_derivative {p : R[X]} {n : ℕ} (h : n ∈ p.derivative.support) : n + 1 ∈ p.support := mem_support_iff.2 fun h1 : p.coeff (n + 1) = 0 => mem_support_iff.1 h <| show p.derivative.coeff n = 0 by rw [coeff_derivative, h1, zero_mul] #align polynomial.of_mem_support_derivative Polynomial.of_mem_support_derivative theorem degree_derivative_lt {p : R[X]} (hp : p ≠ 0) : p.derivative.degree < p.degree := (Finset.sup_lt_iff <| bot_lt_iff_ne_bot.2 <| mt degree_eq_bot.1 hp).2 fun n hp => lt_of_lt_of_le (WithBot.coe_lt_coe.2 n.lt_succ_self) <| Finset.le_sup <| of_mem_support_derivative hp #align polynomial.degree_derivative_lt Polynomial.degree_derivative_lt theorem degree_derivative_le {p : R[X]} : p.derivative.degree ≤ p.degree := letI := Classical.decEq R if H : p = 0 then le_of_eq <| by rw [H, derivative_zero] else (degree_derivative_lt H).le #align polynomial.degree_derivative_le Polynomial.degree_derivative_le theorem natDegree_derivative_lt {p : R[X]} (hp : p.natDegree ≠ 0) : p.derivative.natDegree < p.natDegree := by rcases eq_or_ne (derivative p) 0 with hp' | hp' · rw [hp', Polynomial.natDegree_zero] exact hp.bot_lt · rw [natDegree_lt_natDegree_iff hp'] exact degree_derivative_lt fun h => hp (h.symm ▸ natDegree_zero) #align polynomial.nat_degree_derivative_lt Polynomial.natDegree_derivative_lt theorem natDegree_derivative_le (p : R[X]) : p.derivative.natDegree ≤ p.natDegree - 1 := by by_cases p0 : p.natDegree = 0 · simp [p0, derivative_of_natDegree_zero] · exact Nat.le_sub_one_of_lt (natDegree_derivative_lt p0) #align polynomial.nat_degree_derivative_le Polynomial.natDegree_derivative_le theorem natDegree_iterate_derivative (p : R[X]) (k : ℕ) : (derivative^[k] p).natDegree ≤ p.natDegree - k := by induction k with | zero => rw [Function.iterate_zero_apply, Nat.sub_zero] | succ d hd => rw [Function.iterate_succ_apply', Nat.sub_succ'] exact (natDegree_derivative_le _).trans <| Nat.sub_le_sub_right hd 1 @[simp] theorem derivative_natCast {n : ℕ} : derivative (n : R[X]) = 0 := by rw [← map_natCast C n] exact derivative_C #align polynomial.derivative_nat_cast Polynomial.derivative_natCast @[deprecated (since := "2024-04-17")] alias derivative_nat_cast := derivative_natCast -- Porting note (#10756): new theorem @[simp] theorem derivative_ofNat (n : ℕ) [n.AtLeastTwo] : derivative (no_index (OfNat.ofNat n) : R[X]) = 0 := derivative_natCast theorem iterate_derivative_eq_zero {p : R[X]} {x : ℕ} (hx : p.natDegree < x) : Polynomial.derivative^[x] p = 0 := by induction' h : p.natDegree using Nat.strong_induction_on with _ ih generalizing p x subst h obtain ⟨t, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (pos_of_gt hx).ne' rw [Function.iterate_succ_apply] by_cases hp : p.natDegree = 0 · rw [derivative_of_natDegree_zero hp, iterate_derivative_zero] have := natDegree_derivative_lt hp exact ih _ this (this.trans_le <| Nat.le_of_lt_succ hx) rfl #align polynomial.iterate_derivative_eq_zero Polynomial.iterate_derivative_eq_zero @[simp] theorem iterate_derivative_C {k} (h : 0 < k) : derivative^[k] (C a : R[X]) = 0 := iterate_derivative_eq_zero <| (natDegree_C _).trans_lt h set_option linter.uppercaseLean3 false in #align polynomial.iterate_derivative_C Polynomial.iterate_derivative_C @[simp] theorem iterate_derivative_one {k} (h : 0 < k) : derivative^[k] (1 : R[X]) = 0 := iterate_derivative_C h #align polynomial.iterate_derivative_one Polynomial.iterate_derivative_one @[simp] theorem iterate_derivative_X {k} (h : 1 < k) : derivative^[k] (X : R[X]) = 0 := iterate_derivative_eq_zero <| natDegree_X_le.trans_lt h set_option linter.uppercaseLean3 false in #align polynomial.iterate_derivative_X Polynomial.iterate_derivative_X theorem natDegree_eq_zero_of_derivative_eq_zero [NoZeroSMulDivisors ℕ R] {f : R[X]} (h : derivative f = 0) : f.natDegree = 0 := by rcases eq_or_ne f 0 with (rfl | hf) · exact natDegree_zero rw [natDegree_eq_zero_iff_degree_le_zero] by_contra! f_nat_degree_pos rw [← natDegree_pos_iff_degree_pos] at f_nat_degree_pos let m := f.natDegree - 1 have hm : m + 1 = f.natDegree := tsub_add_cancel_of_le f_nat_degree_pos have h2 := coeff_derivative f m rw [Polynomial.ext_iff] at h rw [h m, coeff_zero, ← Nat.cast_add_one, ← nsmul_eq_mul', eq_comm, smul_eq_zero] at h2 replace h2 := h2.resolve_left m.succ_ne_zero rw [hm, ← leadingCoeff, leadingCoeff_eq_zero] at h2 exact hf h2 #align polynomial.nat_degree_eq_zero_of_derivative_eq_zero Polynomial.natDegree_eq_zero_of_derivative_eq_zero theorem eq_C_of_derivative_eq_zero [NoZeroSMulDivisors ℕ R] {f : R[X]} (h : derivative f = 0) : f = C (f.coeff 0) := eq_C_of_natDegree_eq_zero <| natDegree_eq_zero_of_derivative_eq_zero h set_option linter.uppercaseLean3 false in #align polynomial.eq_C_of_derivative_eq_zero Polynomial.eq_C_of_derivative_eq_zero @[simp] theorem derivative_mul {f g : R[X]} : derivative (f * g) = derivative f * g + f * derivative g := by induction f using Polynomial.induction_on' with | h_add => simp only [add_mul, map_add, add_assoc, add_left_comm, *] | h_monomial m a => induction g using Polynomial.induction_on' with | h_add => simp only [mul_add, map_add, add_assoc, add_left_comm, *] | h_monomial n b => simp only [monomial_mul_monomial, derivative_monomial] simp only [mul_assoc, (Nat.cast_commute _ _).eq, Nat.cast_add, mul_add, map_add] cases m with | zero => simp only [zero_add, Nat.cast_zero, mul_zero, map_zero] | succ m => cases n with | zero => simp only [add_zero, Nat.cast_zero, mul_zero, map_zero] | succ n => simp only [Nat.add_succ_sub_one, add_tsub_cancel_right] rw [add_assoc, add_comm n 1] #align polynomial.derivative_mul Polynomial.derivative_mul theorem derivative_eval (p : R[X]) (x : R) : p.derivative.eval x = p.sum fun n a => a * n * x ^ (n - 1) := by simp_rw [derivative_apply, eval_sum, eval_mul_X_pow, eval_C] #align polynomial.derivative_eval Polynomial.derivative_eval @[simp] theorem derivative_map [Semiring S] (p : R[X]) (f : R →+* S) : derivative (p.map f) = p.derivative.map f := by let n := max p.natDegree (map f p).natDegree rw [derivative_apply, derivative_apply] rw [sum_over_range' _ _ (n + 1) ((le_max_left _ _).trans_lt (lt_add_one _))] on_goal 1 => rw [sum_over_range' _ _ (n + 1) ((le_max_right _ _).trans_lt (lt_add_one _))] · simp only [Polynomial.map_sum, Polynomial.map_mul, Polynomial.map_C, map_mul, coeff_map, map_natCast, Polynomial.map_natCast, Polynomial.map_pow, map_X] all_goals intro n; rw [zero_mul, C_0, zero_mul] #align polynomial.derivative_map Polynomial.derivative_map @[simp] theorem iterate_derivative_map [Semiring S] (p : R[X]) (f : R →+* S) (k : ℕ) : Polynomial.derivative^[k] (p.map f) = (Polynomial.derivative^[k] p).map f := by induction' k with k ih generalizing p · simp · simp only [ih, Function.iterate_succ, Polynomial.derivative_map, Function.comp_apply] #align polynomial.iterate_derivative_map Polynomial.iterate_derivative_map theorem derivative_natCast_mul {n : ℕ} {f : R[X]} : derivative ((n : R[X]) * f) = n * derivative f := by simp #align polynomial.derivative_nat_cast_mul Polynomial.derivative_natCast_mul @[deprecated (since := "2024-04-17")] alias derivative_nat_cast_mul := derivative_natCast_mul @[simp] theorem iterate_derivative_natCast_mul {n k : ℕ} {f : R[X]} : derivative^[k] ((n : R[X]) * f) = n * derivative^[k] f := by induction' k with k ih generalizing f <;> simp [*] #align polynomial.iterate_derivative_nat_cast_mul Polynomial.iterate_derivative_natCast_mul @[deprecated (since := "2024-04-17")] alias iterate_derivative_nat_cast_mul := iterate_derivative_natCast_mul theorem mem_support_derivative [NoZeroSMulDivisors ℕ R] (p : R[X]) (n : ℕ) : n ∈ (derivative p).support ↔ n + 1 ∈ p.support := by suffices ¬p.coeff (n + 1) * (n + 1 : ℕ) = 0 ↔ coeff p (n + 1) ≠ 0 by simpa only [mem_support_iff, coeff_derivative, Ne, Nat.cast_succ] rw [← nsmul_eq_mul', smul_eq_zero] simp only [Nat.succ_ne_zero, false_or_iff] #align polynomial.mem_support_derivative Polynomial.mem_support_derivative @[simp] theorem degree_derivative_eq [NoZeroSMulDivisors ℕ R] (p : R[X]) (hp : 0 < natDegree p) : degree (derivative p) = (natDegree p - 1 : ℕ) := by apply le_antisymm · rw [derivative_apply] apply le_trans (degree_sum_le _ _) (Finset.sup_le _) intro n hn apply le_trans (degree_C_mul_X_pow_le _ _) (WithBot.coe_le_coe.2 (tsub_le_tsub_right _ _)) apply le_natDegree_of_mem_supp _ hn · refine le_sup ?_ rw [mem_support_derivative, tsub_add_cancel_of_le, mem_support_iff] · rw [coeff_natDegree, Ne, leadingCoeff_eq_zero] intro h rw [h, natDegree_zero] at hp exact hp.false exact hp #align polynomial.degree_derivative_eq Polynomial.degree_derivative_eq #noalign polynomial.coeff_iterate_derivative_as_prod_Ico #noalign polynomial.coeff_iterate_derivative_as_prod_range theorem coeff_iterate_derivative {k} (p : R[X]) (m : ℕ) : (derivative^[k] p).coeff m = (m + k).descFactorial k • p.coeff (m + k) := by induction k generalizing m with | zero => simp | succ k ih => calc (derivative^[k + 1] p).coeff m _ = Nat.descFactorial (Nat.succ (m + k)) k • p.coeff (m + k.succ) * (m + 1) := by rw [Function.iterate_succ_apply', coeff_derivative, ih m.succ, Nat.succ_add, Nat.add_succ] _ = ((m + 1) * Nat.descFactorial (Nat.succ (m + k)) k) • p.coeff (m + k.succ) := by rw [← Nat.cast_add_one, ← nsmul_eq_mul', smul_smul] _ = Nat.descFactorial (m.succ + k) k.succ • p.coeff (m + k.succ) := by rw [← Nat.succ_add, Nat.descFactorial_succ, add_tsub_cancel_right] _ = Nat.descFactorial (m + k.succ) k.succ • p.coeff (m + k.succ) := by rw [Nat.succ_add_eq_add_succ]
Mathlib/Algebra/Polynomial/Derivative.lean
395
435
theorem iterate_derivative_mul {n} (p q : R[X]) : derivative^[n] (p * q) = ∑ k ∈ range n.succ, (n.choose k • (derivative^[n - k] p * derivative^[k] q)) := by
induction' n with n IH · simp [Finset.range] calc derivative^[n + 1] (p * q) = derivative (∑ k ∈ range n.succ, n.choose k • (derivative^[n - k] p * derivative^[k] q)) := by rw [Function.iterate_succ_apply', IH] _ = (∑ k ∈ range n.succ, n.choose k • (derivative^[n - k + 1] p * derivative^[k] q)) + ∑ k ∈ range n.succ, n.choose k • (derivative^[n - k] p * derivative^[k + 1] q) := by simp_rw [derivative_sum, derivative_smul, derivative_mul, Function.iterate_succ_apply', smul_add, sum_add_distrib] _ = (∑ k ∈ range n.succ, n.choose k.succ • (derivative^[n - k] p * derivative^[k + 1] q)) + 1 • (derivative^[n + 1] p * derivative^[0] q) + ∑ k ∈ range n.succ, n.choose k • (derivative^[n - k] p * derivative^[k + 1] q) := ?_ _ = ((∑ k ∈ range n.succ, n.choose k • (derivative^[n - k] p * derivative^[k + 1] q)) + ∑ k ∈ range n.succ, n.choose k.succ • (derivative^[n - k] p * derivative^[k + 1] q)) + 1 • (derivative^[n + 1] p * derivative^[0] q) := by rw [add_comm, add_assoc] _ = (∑ i ∈ range n.succ, (n + 1).choose (i + 1) • (derivative^[n + 1 - (i + 1)] p * derivative^[i + 1] q)) + 1 • (derivative^[n + 1] p * derivative^[0] q) := by simp_rw [Nat.choose_succ_succ, Nat.succ_sub_succ, add_smul, sum_add_distrib] _ = ∑ k ∈ range n.succ.succ, n.succ.choose k • (derivative^[n.succ - k] p * derivative^[k] q) := by rw [sum_range_succ' _ n.succ, Nat.choose_zero_right, tsub_zero] congr refine (sum_range_succ' _ _).trans (congr_arg₂ (· + ·) ?_ ?_) · rw [sum_range_succ, Nat.choose_succ_self, zero_smul, add_zero] refine sum_congr rfl fun k hk => ?_ rw [mem_range] at hk congr omega · rw [Nat.choose_zero_right, tsub_zero]
/- Copyright (c) 2019 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp, François Dupuis -/ import Mathlib.Analysis.Convex.Basic import Mathlib.Order.Filter.Extr import Mathlib.Tactic.GCongr #align_import analysis.convex.function from "leanprover-community/mathlib"@"92ca63f0fb391a9ca5f22d2409a6080e786d99f7" /-! # Convex and concave functions This file defines convex and concave functions in vector spaces and proves the finite Jensen inequality. The integral version can be found in `Analysis.Convex.Integral`. A function `f : E → β` is `ConvexOn` a set `s` if `s` is itself a convex set, and for any two points `x y ∈ s`, the segment joining `(x, f x)` to `(y, f y)` is above the graph of `f`. Equivalently, `ConvexOn 𝕜 f s` means that the epigraph `{p : E × β | p.1 ∈ s ∧ f p.1 ≤ p.2}` is a convex set. ## Main declarations * `ConvexOn 𝕜 s f`: The function `f` is convex on `s` with scalars `𝕜`. * `ConcaveOn 𝕜 s f`: The function `f` is concave on `s` with scalars `𝕜`. * `StrictConvexOn 𝕜 s f`: The function `f` is strictly convex on `s` with scalars `𝕜`. * `StrictConcaveOn 𝕜 s f`: The function `f` is strictly concave on `s` with scalars `𝕜`. -/ open scoped Classical open LinearMap Set Convex Pointwise variable {𝕜 E F α β ι : Type*} section OrderedSemiring variable [OrderedSemiring 𝕜] section AddCommMonoid variable [AddCommMonoid E] [AddCommMonoid F] section OrderedAddCommMonoid variable [OrderedAddCommMonoid α] [OrderedAddCommMonoid β] section SMul variable (𝕜) [SMul 𝕜 E] [SMul 𝕜 α] [SMul 𝕜 β] (s : Set E) (f : E → β) {g : β → α} /-- Convexity of functions -/ def ConvexOn : Prop := Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → f (a • x + b • y) ≤ a • f x + b • f y #align convex_on ConvexOn /-- Concavity of functions -/ def ConcaveOn : Prop := Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → a • f x + b • f y ≤ f (a • x + b • y) #align concave_on ConcaveOn /-- Strict convexity of functions -/ def StrictConvexOn : Prop := Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x ≠ y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → f (a • x + b • y) < a • f x + b • f y #align strict_convex_on StrictConvexOn /-- Strict concavity of functions -/ def StrictConcaveOn : Prop := Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x ≠ y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • f x + b • f y < f (a • x + b • y) #align strict_concave_on StrictConcaveOn variable {𝕜 s f} open OrderDual (toDual ofDual) theorem ConvexOn.dual (hf : ConvexOn 𝕜 s f) : ConcaveOn 𝕜 s (toDual ∘ f) := hf #align convex_on.dual ConvexOn.dual theorem ConcaveOn.dual (hf : ConcaveOn 𝕜 s f) : ConvexOn 𝕜 s (toDual ∘ f) := hf #align concave_on.dual ConcaveOn.dual theorem StrictConvexOn.dual (hf : StrictConvexOn 𝕜 s f) : StrictConcaveOn 𝕜 s (toDual ∘ f) := hf #align strict_convex_on.dual StrictConvexOn.dual theorem StrictConcaveOn.dual (hf : StrictConcaveOn 𝕜 s f) : StrictConvexOn 𝕜 s (toDual ∘ f) := hf #align strict_concave_on.dual StrictConcaveOn.dual theorem convexOn_id {s : Set β} (hs : Convex 𝕜 s) : ConvexOn 𝕜 s _root_.id := ⟨hs, by intros rfl⟩ #align convex_on_id convexOn_id theorem concaveOn_id {s : Set β} (hs : Convex 𝕜 s) : ConcaveOn 𝕜 s _root_.id := ⟨hs, by intros rfl⟩ #align concave_on_id concaveOn_id theorem ConvexOn.subset {t : Set E} (hf : ConvexOn 𝕜 t f) (hst : s ⊆ t) (hs : Convex 𝕜 s) : ConvexOn 𝕜 s f := ⟨hs, fun _ hx _ hy => hf.2 (hst hx) (hst hy)⟩ #align convex_on.subset ConvexOn.subset theorem ConcaveOn.subset {t : Set E} (hf : ConcaveOn 𝕜 t f) (hst : s ⊆ t) (hs : Convex 𝕜 s) : ConcaveOn 𝕜 s f := ⟨hs, fun _ hx _ hy => hf.2 (hst hx) (hst hy)⟩ #align concave_on.subset ConcaveOn.subset theorem StrictConvexOn.subset {t : Set E} (hf : StrictConvexOn 𝕜 t f) (hst : s ⊆ t) (hs : Convex 𝕜 s) : StrictConvexOn 𝕜 s f := ⟨hs, fun _ hx _ hy => hf.2 (hst hx) (hst hy)⟩ #align strict_convex_on.subset StrictConvexOn.subset theorem StrictConcaveOn.subset {t : Set E} (hf : StrictConcaveOn 𝕜 t f) (hst : s ⊆ t) (hs : Convex 𝕜 s) : StrictConcaveOn 𝕜 s f := ⟨hs, fun _ hx _ hy => hf.2 (hst hx) (hst hy)⟩ #align strict_concave_on.subset StrictConcaveOn.subset theorem ConvexOn.comp (hg : ConvexOn 𝕜 (f '' s) g) (hf : ConvexOn 𝕜 s f) (hg' : MonotoneOn g (f '' s)) : ConvexOn 𝕜 s (g ∘ f) := ⟨hf.1, fun _ hx _ hy _ _ ha hb hab => (hg' (mem_image_of_mem f <| hf.1 hx hy ha hb hab) (hg.1 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha hb hab) <| hf.2 hx hy ha hb hab).trans <| hg.2 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha hb hab⟩ #align convex_on.comp ConvexOn.comp theorem ConcaveOn.comp (hg : ConcaveOn 𝕜 (f '' s) g) (hf : ConcaveOn 𝕜 s f) (hg' : MonotoneOn g (f '' s)) : ConcaveOn 𝕜 s (g ∘ f) := ⟨hf.1, fun _ hx _ hy _ _ ha hb hab => (hg.2 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha hb hab).trans <| hg' (hg.1 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha hb hab) (mem_image_of_mem f <| hf.1 hx hy ha hb hab) <| hf.2 hx hy ha hb hab⟩ #align concave_on.comp ConcaveOn.comp theorem ConvexOn.comp_concaveOn (hg : ConvexOn 𝕜 (f '' s) g) (hf : ConcaveOn 𝕜 s f) (hg' : AntitoneOn g (f '' s)) : ConvexOn 𝕜 s (g ∘ f) := hg.dual.comp hf hg' #align convex_on.comp_concave_on ConvexOn.comp_concaveOn theorem ConcaveOn.comp_convexOn (hg : ConcaveOn 𝕜 (f '' s) g) (hf : ConvexOn 𝕜 s f) (hg' : AntitoneOn g (f '' s)) : ConcaveOn 𝕜 s (g ∘ f) := hg.dual.comp hf hg' #align concave_on.comp_convex_on ConcaveOn.comp_convexOn theorem StrictConvexOn.comp (hg : StrictConvexOn 𝕜 (f '' s) g) (hf : StrictConvexOn 𝕜 s f) (hg' : StrictMonoOn g (f '' s)) (hf' : s.InjOn f) : StrictConvexOn 𝕜 s (g ∘ f) := ⟨hf.1, fun _ hx _ hy hxy _ _ ha hb hab => (hg' (mem_image_of_mem f <| hf.1 hx hy ha.le hb.le hab) (hg.1 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha.le hb.le hab) <| hf.2 hx hy hxy ha hb hab).trans <| hg.2 (mem_image_of_mem f hx) (mem_image_of_mem f hy) (mt (hf' hx hy) hxy) ha hb hab⟩ #align strict_convex_on.comp StrictConvexOn.comp theorem StrictConcaveOn.comp (hg : StrictConcaveOn 𝕜 (f '' s) g) (hf : StrictConcaveOn 𝕜 s f) (hg' : StrictMonoOn g (f '' s)) (hf' : s.InjOn f) : StrictConcaveOn 𝕜 s (g ∘ f) := ⟨hf.1, fun _ hx _ hy hxy _ _ ha hb hab => (hg.2 (mem_image_of_mem f hx) (mem_image_of_mem f hy) (mt (hf' hx hy) hxy) ha hb hab).trans <| hg' (hg.1 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha.le hb.le hab) (mem_image_of_mem f <| hf.1 hx hy ha.le hb.le hab) <| hf.2 hx hy hxy ha hb hab⟩ #align strict_concave_on.comp StrictConcaveOn.comp theorem StrictConvexOn.comp_strictConcaveOn (hg : StrictConvexOn 𝕜 (f '' s) g) (hf : StrictConcaveOn 𝕜 s f) (hg' : StrictAntiOn g (f '' s)) (hf' : s.InjOn f) : StrictConvexOn 𝕜 s (g ∘ f) := hg.dual.comp hf hg' hf' #align strict_convex_on.comp_strict_concave_on StrictConvexOn.comp_strictConcaveOn theorem StrictConcaveOn.comp_strictConvexOn (hg : StrictConcaveOn 𝕜 (f '' s) g) (hf : StrictConvexOn 𝕜 s f) (hg' : StrictAntiOn g (f '' s)) (hf' : s.InjOn f) : StrictConcaveOn 𝕜 s (g ∘ f) := hg.dual.comp hf hg' hf' #align strict_concave_on.comp_strict_convex_on StrictConcaveOn.comp_strictConvexOn end SMul section DistribMulAction variable [SMul 𝕜 E] [DistribMulAction 𝕜 β] {s : Set E} {f g : E → β} theorem ConvexOn.add (hf : ConvexOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) : ConvexOn 𝕜 s (f + g) := ⟨hf.1, fun x hx y hy a b ha hb hab => calc f (a • x + b • y) + g (a • x + b • y) ≤ a • f x + b • f y + (a • g x + b • g y) := add_le_add (hf.2 hx hy ha hb hab) (hg.2 hx hy ha hb hab) _ = a • (f x + g x) + b • (f y + g y) := by rw [smul_add, smul_add, add_add_add_comm] ⟩ #align convex_on.add ConvexOn.add theorem ConcaveOn.add (hf : ConcaveOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) : ConcaveOn 𝕜 s (f + g) := hf.dual.add hg #align concave_on.add ConcaveOn.add end DistribMulAction section Module variable [SMul 𝕜 E] [Module 𝕜 β] {s : Set E} {f : E → β} theorem convexOn_const (c : β) (hs : Convex 𝕜 s) : ConvexOn 𝕜 s fun _ : E => c := ⟨hs, fun _ _ _ _ _ _ _ _ hab => (Convex.combo_self hab c).ge⟩ #align convex_on_const convexOn_const theorem concaveOn_const (c : β) (hs : Convex 𝕜 s) : ConcaveOn 𝕜 s fun _ => c := convexOn_const (β := βᵒᵈ) _ hs #align concave_on_const concaveOn_const theorem convexOn_of_convex_epigraph (h : Convex 𝕜 { p : E × β | p.1 ∈ s ∧ f p.1 ≤ p.2 }) : ConvexOn 𝕜 s f := ⟨fun x hx y hy a b ha hb hab => (@h (x, f x) ⟨hx, le_rfl⟩ (y, f y) ⟨hy, le_rfl⟩ a b ha hb hab).1, fun x hx y hy a b ha hb hab => (@h (x, f x) ⟨hx, le_rfl⟩ (y, f y) ⟨hy, le_rfl⟩ a b ha hb hab).2⟩ #align convex_on_of_convex_epigraph convexOn_of_convex_epigraph theorem concaveOn_of_convex_hypograph (h : Convex 𝕜 { p : E × β | p.1 ∈ s ∧ p.2 ≤ f p.1 }) : ConcaveOn 𝕜 s f := convexOn_of_convex_epigraph (β := βᵒᵈ) h #align concave_on_of_convex_hypograph concaveOn_of_convex_hypograph end Module section OrderedSMul variable [SMul 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E} {f : E → β} theorem ConvexOn.convex_le (hf : ConvexOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | f x ≤ r }) := fun x hx y hy a b ha hb hab => ⟨hf.1 hx.1 hy.1 ha hb hab, calc f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx.1 hy.1 ha hb hab _ ≤ a • r + b • r := by gcongr · exact hx.2 · exact hy.2 _ = r := Convex.combo_self hab r ⟩ #align convex_on.convex_le ConvexOn.convex_le theorem ConcaveOn.convex_ge (hf : ConcaveOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | r ≤ f x }) := hf.dual.convex_le r #align concave_on.convex_ge ConcaveOn.convex_ge theorem ConvexOn.convex_epigraph (hf : ConvexOn 𝕜 s f) : Convex 𝕜 { p : E × β | p.1 ∈ s ∧ f p.1 ≤ p.2 } := by rintro ⟨x, r⟩ ⟨hx, hr⟩ ⟨y, t⟩ ⟨hy, ht⟩ a b ha hb hab refine ⟨hf.1 hx hy ha hb hab, ?_⟩ calc f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx hy ha hb hab _ ≤ a • r + b • t := by gcongr #align convex_on.convex_epigraph ConvexOn.convex_epigraph theorem ConcaveOn.convex_hypograph (hf : ConcaveOn 𝕜 s f) : Convex 𝕜 { p : E × β | p.1 ∈ s ∧ p.2 ≤ f p.1 } := hf.dual.convex_epigraph #align concave_on.convex_hypograph ConcaveOn.convex_hypograph theorem convexOn_iff_convex_epigraph : ConvexOn 𝕜 s f ↔ Convex 𝕜 { p : E × β | p.1 ∈ s ∧ f p.1 ≤ p.2 } := ⟨ConvexOn.convex_epigraph, convexOn_of_convex_epigraph⟩ #align convex_on_iff_convex_epigraph convexOn_iff_convex_epigraph theorem concaveOn_iff_convex_hypograph : ConcaveOn 𝕜 s f ↔ Convex 𝕜 { p : E × β | p.1 ∈ s ∧ p.2 ≤ f p.1 } := convexOn_iff_convex_epigraph (β := βᵒᵈ) #align concave_on_iff_convex_hypograph concaveOn_iff_convex_hypograph end OrderedSMul section Module variable [Module 𝕜 E] [SMul 𝕜 β] {s : Set E} {f : E → β} /-- Right translation preserves convexity. -/ theorem ConvexOn.translate_right (hf : ConvexOn 𝕜 s f) (c : E) : ConvexOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => c + z) := ⟨hf.1.translate_preimage_right _, fun x hx y hy a b ha hb hab => calc f (c + (a • x + b • y)) = f (a • (c + x) + b • (c + y)) := by rw [smul_add, smul_add, add_add_add_comm, Convex.combo_self hab] _ ≤ a • f (c + x) + b • f (c + y) := hf.2 hx hy ha hb hab ⟩ #align convex_on.translate_right ConvexOn.translate_right /-- Right translation preserves concavity. -/ theorem ConcaveOn.translate_right (hf : ConcaveOn 𝕜 s f) (c : E) : ConcaveOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => c + z) := hf.dual.translate_right _ #align concave_on.translate_right ConcaveOn.translate_right /-- Left translation preserves convexity. -/ theorem ConvexOn.translate_left (hf : ConvexOn 𝕜 s f) (c : E) : ConvexOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => z + c) := by simpa only [add_comm c] using hf.translate_right c #align convex_on.translate_left ConvexOn.translate_left /-- Left translation preserves concavity. -/ theorem ConcaveOn.translate_left (hf : ConcaveOn 𝕜 s f) (c : E) : ConcaveOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => z + c) := hf.dual.translate_left _ #align concave_on.translate_left ConcaveOn.translate_left end Module section Module variable [Module 𝕜 E] [Module 𝕜 β]
Mathlib/Analysis/Convex/Function.lean
315
328
theorem convexOn_iff_forall_pos {s : Set E} {f : E → β} : ConvexOn 𝕜 s f ↔ Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → f (a • x + b • y) ≤ a • f x + b • f y := by
refine and_congr_right' ⟨fun h x hx y hy a b ha hb hab => h hx hy ha.le hb.le hab, fun h x hx y hy a b ha hb hab => ?_⟩ obtain rfl | ha' := ha.eq_or_lt · rw [zero_add] at hab subst b simp_rw [zero_smul, zero_add, one_smul, le_rfl] obtain rfl | hb' := hb.eq_or_lt · rw [add_zero] at hab subst a simp_rw [zero_smul, add_zero, one_smul, le_rfl] exact h hx hy ha' hb' hab
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura -/ import Mathlib.Init.ZeroOne import Mathlib.Data.Set.Defs import Mathlib.Order.Basic import Mathlib.Order.SymmDiff import Mathlib.Tactic.Tauto import Mathlib.Tactic.ByContra import Mathlib.Util.Delaborators #align_import data.set.basic from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29" /-! # Basic properties of sets Sets in Lean are homogeneous; all their elements have the same type. Sets whose elements have type `X` are thus defined as `Set X := X → Prop`. Note that this function need not be decidable. The definition is in the core library. This file provides some basic definitions related to sets and functions not present in the core library, as well as extra lemmas for functions in the core library (empty set, univ, union, intersection, insert, singleton, set-theoretic difference, complement, and powerset). Note that a set is a term, not a type. There is a coercion from `Set α` to `Type*` sending `s` to the corresponding subtype `↥s`. See also the file `SetTheory/ZFC.lean`, which contains an encoding of ZFC set theory in Lean. ## Main definitions Notation used here: - `f : α → β` is a function, - `s : Set α` and `s₁ s₂ : Set α` are subsets of `α` - `t : Set β` is a subset of `β`. Definitions in the file: * `Nonempty s : Prop` : the predicate `s ≠ ∅`. Note that this is the preferred way to express the fact that `s` has an element (see the Implementation Notes). * `inclusion s₁ s₂ : ↥s₁ → ↥s₂` : the map `↥s₁ → ↥s₂` induced by an inclusion `s₁ ⊆ s₂`. ## Notation * `sᶜ` for the complement of `s` ## Implementation notes * `s.Nonempty` is to be preferred to `s ≠ ∅` or `∃ x, x ∈ s`. It has the advantage that the `s.Nonempty` dot notation can be used. * For `s : Set α`, do not use `Subtype s`. Instead use `↥s` or `(s : Type*)` or `s`. ## Tags set, sets, subset, subsets, union, intersection, insert, singleton, complement, powerset -/ /-! ### Set coercion to a type -/ open Function universe u v w x namespace Set variable {α : Type u} {s t : Set α} instance instBooleanAlgebraSet : BooleanAlgebra (Set α) := { (inferInstance : BooleanAlgebra (α → Prop)) with sup := (· ∪ ·), le := (· ≤ ·), lt := fun s t => s ⊆ t ∧ ¬t ⊆ s, inf := (· ∩ ·), bot := ∅, compl := (·ᶜ), top := univ, sdiff := (· \ ·) } instance : HasSSubset (Set α) := ⟨(· < ·)⟩ @[simp] theorem top_eq_univ : (⊤ : Set α) = univ := rfl #align set.top_eq_univ Set.top_eq_univ @[simp] theorem bot_eq_empty : (⊥ : Set α) = ∅ := rfl #align set.bot_eq_empty Set.bot_eq_empty @[simp] theorem sup_eq_union : ((· ⊔ ·) : Set α → Set α → Set α) = (· ∪ ·) := rfl #align set.sup_eq_union Set.sup_eq_union @[simp] theorem inf_eq_inter : ((· ⊓ ·) : Set α → Set α → Set α) = (· ∩ ·) := rfl #align set.inf_eq_inter Set.inf_eq_inter @[simp] theorem le_eq_subset : ((· ≤ ·) : Set α → Set α → Prop) = (· ⊆ ·) := rfl #align set.le_eq_subset Set.le_eq_subset @[simp] theorem lt_eq_ssubset : ((· < ·) : Set α → Set α → Prop) = (· ⊂ ·) := rfl #align set.lt_eq_ssubset Set.lt_eq_ssubset theorem le_iff_subset : s ≤ t ↔ s ⊆ t := Iff.rfl #align set.le_iff_subset Set.le_iff_subset theorem lt_iff_ssubset : s < t ↔ s ⊂ t := Iff.rfl #align set.lt_iff_ssubset Set.lt_iff_ssubset alias ⟨_root_.LE.le.subset, _root_.HasSubset.Subset.le⟩ := le_iff_subset #align has_subset.subset.le HasSubset.Subset.le alias ⟨_root_.LT.lt.ssubset, _root_.HasSSubset.SSubset.lt⟩ := lt_iff_ssubset #align has_ssubset.ssubset.lt HasSSubset.SSubset.lt instance PiSetCoe.canLift (ι : Type u) (α : ι → Type v) [∀ i, Nonempty (α i)] (s : Set ι) : CanLift (∀ i : s, α i) (∀ i, α i) (fun f i => f i) fun _ => True := PiSubtype.canLift ι α s #align set.pi_set_coe.can_lift Set.PiSetCoe.canLift instance PiSetCoe.canLift' (ι : Type u) (α : Type v) [Nonempty α] (s : Set ι) : CanLift (s → α) (ι → α) (fun f i => f i) fun _ => True := PiSetCoe.canLift ι (fun _ => α) s #align set.pi_set_coe.can_lift' Set.PiSetCoe.canLift' end Set section SetCoe variable {α : Type u} instance (s : Set α) : CoeTC s α := ⟨fun x => x.1⟩ theorem Set.coe_eq_subtype (s : Set α) : ↥s = { x // x ∈ s } := rfl #align set.coe_eq_subtype Set.coe_eq_subtype @[simp] theorem Set.coe_setOf (p : α → Prop) : ↥{ x | p x } = { x // p x } := rfl #align set.coe_set_of Set.coe_setOf -- Porting note (#10618): removed `simp` because `simp` can prove it theorem SetCoe.forall {s : Set α} {p : s → Prop} : (∀ x : s, p x) ↔ ∀ (x) (h : x ∈ s), p ⟨x, h⟩ := Subtype.forall #align set_coe.forall SetCoe.forall -- Porting note (#10618): removed `simp` because `simp` can prove it theorem SetCoe.exists {s : Set α} {p : s → Prop} : (∃ x : s, p x) ↔ ∃ (x : _) (h : x ∈ s), p ⟨x, h⟩ := Subtype.exists #align set_coe.exists SetCoe.exists theorem SetCoe.exists' {s : Set α} {p : ∀ x, x ∈ s → Prop} : (∃ (x : _) (h : x ∈ s), p x h) ↔ ∃ x : s, p x.1 x.2 := (@SetCoe.exists _ _ fun x => p x.1 x.2).symm #align set_coe.exists' SetCoe.exists' theorem SetCoe.forall' {s : Set α} {p : ∀ x, x ∈ s → Prop} : (∀ (x) (h : x ∈ s), p x h) ↔ ∀ x : s, p x.1 x.2 := (@SetCoe.forall _ _ fun x => p x.1 x.2).symm #align set_coe.forall' SetCoe.forall' @[simp] theorem set_coe_cast : ∀ {s t : Set α} (H' : s = t) (H : ↥s = ↥t) (x : s), cast H x = ⟨x.1, H' ▸ x.2⟩ | _, _, rfl, _, _ => rfl #align set_coe_cast set_coe_cast theorem SetCoe.ext {s : Set α} {a b : s} : (a : α) = b → a = b := Subtype.eq #align set_coe.ext SetCoe.ext theorem SetCoe.ext_iff {s : Set α} {a b : s} : (↑a : α) = ↑b ↔ a = b := Iff.intro SetCoe.ext fun h => h ▸ rfl #align set_coe.ext_iff SetCoe.ext_iff end SetCoe /-- See also `Subtype.prop` -/ theorem Subtype.mem {α : Type*} {s : Set α} (p : s) : (p : α) ∈ s := p.prop #align subtype.mem Subtype.mem /-- Duplicate of `Eq.subset'`, which currently has elaboration problems. -/ theorem Eq.subset {α} {s t : Set α} : s = t → s ⊆ t := fun h₁ _ h₂ => by rw [← h₁]; exact h₂ #align eq.subset Eq.subset namespace Set variable {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x} {a b : α} {s s₁ s₂ t t₁ t₂ u : Set α} instance : Inhabited (Set α) := ⟨∅⟩ theorem ext_iff {s t : Set α} : s = t ↔ ∀ x, x ∈ s ↔ x ∈ t := ⟨fun h x => by rw [h], ext⟩ #align set.ext_iff Set.ext_iff @[trans] theorem mem_of_mem_of_subset {x : α} {s t : Set α} (hx : x ∈ s) (h : s ⊆ t) : x ∈ t := h hx #align set.mem_of_mem_of_subset Set.mem_of_mem_of_subset theorem forall_in_swap {p : α → β → Prop} : (∀ a ∈ s, ∀ (b), p a b) ↔ ∀ (b), ∀ a ∈ s, p a b := by tauto #align set.forall_in_swap Set.forall_in_swap /-! ### Lemmas about `mem` and `setOf` -/ theorem mem_setOf {a : α} {p : α → Prop} : a ∈ { x | p x } ↔ p a := Iff.rfl #align set.mem_set_of Set.mem_setOf /-- If `h : a ∈ {x | p x}` then `h.out : p x`. These are definitionally equal, but this can nevertheless be useful for various reasons, e.g. to apply further projection notation or in an argument to `simp`. -/ theorem _root_.Membership.mem.out {p : α → Prop} {a : α} (h : a ∈ { x | p x }) : p a := h #align has_mem.mem.out Membership.mem.out theorem nmem_setOf_iff {a : α} {p : α → Prop} : a ∉ { x | p x } ↔ ¬p a := Iff.rfl #align set.nmem_set_of_iff Set.nmem_setOf_iff @[simp] theorem setOf_mem_eq {s : Set α} : { x | x ∈ s } = s := rfl #align set.set_of_mem_eq Set.setOf_mem_eq theorem setOf_set {s : Set α} : setOf s = s := rfl #align set.set_of_set Set.setOf_set theorem setOf_app_iff {p : α → Prop} {x : α} : { x | p x } x ↔ p x := Iff.rfl #align set.set_of_app_iff Set.setOf_app_iff theorem mem_def {a : α} {s : Set α} : a ∈ s ↔ s a := Iff.rfl #align set.mem_def Set.mem_def theorem setOf_bijective : Bijective (setOf : (α → Prop) → Set α) := bijective_id #align set.set_of_bijective Set.setOf_bijective theorem subset_setOf {p : α → Prop} {s : Set α} : s ⊆ setOf p ↔ ∀ x, x ∈ s → p x := Iff.rfl theorem setOf_subset {p : α → Prop} {s : Set α} : setOf p ⊆ s ↔ ∀ x, p x → x ∈ s := Iff.rfl @[simp] theorem setOf_subset_setOf {p q : α → Prop} : { a | p a } ⊆ { a | q a } ↔ ∀ a, p a → q a := Iff.rfl #align set.set_of_subset_set_of Set.setOf_subset_setOf theorem setOf_and {p q : α → Prop} : { a | p a ∧ q a } = { a | p a } ∩ { a | q a } := rfl #align set.set_of_and Set.setOf_and theorem setOf_or {p q : α → Prop} : { a | p a ∨ q a } = { a | p a } ∪ { a | q a } := rfl #align set.set_of_or Set.setOf_or /-! ### Subset and strict subset relations -/ instance : IsRefl (Set α) (· ⊆ ·) := show IsRefl (Set α) (· ≤ ·) by infer_instance instance : IsTrans (Set α) (· ⊆ ·) := show IsTrans (Set α) (· ≤ ·) by infer_instance instance : Trans ((· ⊆ ·) : Set α → Set α → Prop) (· ⊆ ·) (· ⊆ ·) := show Trans (· ≤ ·) (· ≤ ·) (· ≤ ·) by infer_instance instance : IsAntisymm (Set α) (· ⊆ ·) := show IsAntisymm (Set α) (· ≤ ·) by infer_instance instance : IsIrrefl (Set α) (· ⊂ ·) := show IsIrrefl (Set α) (· < ·) by infer_instance instance : IsTrans (Set α) (· ⊂ ·) := show IsTrans (Set α) (· < ·) by infer_instance instance : Trans ((· ⊂ ·) : Set α → Set α → Prop) (· ⊂ ·) (· ⊂ ·) := show Trans (· < ·) (· < ·) (· < ·) by infer_instance instance : Trans ((· ⊂ ·) : Set α → Set α → Prop) (· ⊆ ·) (· ⊂ ·) := show Trans (· < ·) (· ≤ ·) (· < ·) by infer_instance instance : Trans ((· ⊆ ·) : Set α → Set α → Prop) (· ⊂ ·) (· ⊂ ·) := show Trans (· ≤ ·) (· < ·) (· < ·) by infer_instance instance : IsAsymm (Set α) (· ⊂ ·) := show IsAsymm (Set α) (· < ·) by infer_instance instance : IsNonstrictStrictOrder (Set α) (· ⊆ ·) (· ⊂ ·) := ⟨fun _ _ => Iff.rfl⟩ -- TODO(Jeremy): write a tactic to unfold specific instances of generic notation? theorem subset_def : (s ⊆ t) = ∀ x, x ∈ s → x ∈ t := rfl #align set.subset_def Set.subset_def theorem ssubset_def : (s ⊂ t) = (s ⊆ t ∧ ¬t ⊆ s) := rfl #align set.ssubset_def Set.ssubset_def @[refl] theorem Subset.refl (a : Set α) : a ⊆ a := fun _ => id #align set.subset.refl Set.Subset.refl theorem Subset.rfl {s : Set α} : s ⊆ s := Subset.refl s #align set.subset.rfl Set.Subset.rfl @[trans] theorem Subset.trans {a b c : Set α} (ab : a ⊆ b) (bc : b ⊆ c) : a ⊆ c := fun _ h => bc <| ab h #align set.subset.trans Set.Subset.trans @[trans] theorem mem_of_eq_of_mem {x y : α} {s : Set α} (hx : x = y) (h : y ∈ s) : x ∈ s := hx.symm ▸ h #align set.mem_of_eq_of_mem Set.mem_of_eq_of_mem theorem Subset.antisymm {a b : Set α} (h₁ : a ⊆ b) (h₂ : b ⊆ a) : a = b := Set.ext fun _ => ⟨@h₁ _, @h₂ _⟩ #align set.subset.antisymm Set.Subset.antisymm theorem Subset.antisymm_iff {a b : Set α} : a = b ↔ a ⊆ b ∧ b ⊆ a := ⟨fun e => ⟨e.subset, e.symm.subset⟩, fun ⟨h₁, h₂⟩ => Subset.antisymm h₁ h₂⟩ #align set.subset.antisymm_iff Set.Subset.antisymm_iff -- an alternative name theorem eq_of_subset_of_subset {a b : Set α} : a ⊆ b → b ⊆ a → a = b := Subset.antisymm #align set.eq_of_subset_of_subset Set.eq_of_subset_of_subset theorem mem_of_subset_of_mem {s₁ s₂ : Set α} {a : α} (h : s₁ ⊆ s₂) : a ∈ s₁ → a ∈ s₂ := @h _ #align set.mem_of_subset_of_mem Set.mem_of_subset_of_mem theorem not_mem_subset (h : s ⊆ t) : a ∉ t → a ∉ s := mt <| mem_of_subset_of_mem h #align set.not_mem_subset Set.not_mem_subset theorem not_subset : ¬s ⊆ t ↔ ∃ a ∈ s, a ∉ t := by simp only [subset_def, not_forall, exists_prop] #align set.not_subset Set.not_subset lemma eq_of_forall_subset_iff (h : ∀ u, s ⊆ u ↔ t ⊆ u) : s = t := eq_of_forall_ge_iff h /-! ### Definition of strict subsets `s ⊂ t` and basic properties. -/ protected theorem eq_or_ssubset_of_subset (h : s ⊆ t) : s = t ∨ s ⊂ t := eq_or_lt_of_le h #align set.eq_or_ssubset_of_subset Set.eq_or_ssubset_of_subset theorem exists_of_ssubset {s t : Set α} (h : s ⊂ t) : ∃ x ∈ t, x ∉ s := not_subset.1 h.2 #align set.exists_of_ssubset Set.exists_of_ssubset protected theorem ssubset_iff_subset_ne {s t : Set α} : s ⊂ t ↔ s ⊆ t ∧ s ≠ t := @lt_iff_le_and_ne (Set α) _ s t #align set.ssubset_iff_subset_ne Set.ssubset_iff_subset_ne theorem ssubset_iff_of_subset {s t : Set α} (h : s ⊆ t) : s ⊂ t ↔ ∃ x ∈ t, x ∉ s := ⟨exists_of_ssubset, fun ⟨_, hxt, hxs⟩ => ⟨h, fun h => hxs <| h hxt⟩⟩ #align set.ssubset_iff_of_subset Set.ssubset_iff_of_subset protected theorem ssubset_of_ssubset_of_subset {s₁ s₂ s₃ : Set α} (hs₁s₂ : s₁ ⊂ s₂) (hs₂s₃ : s₂ ⊆ s₃) : s₁ ⊂ s₃ := ⟨Subset.trans hs₁s₂.1 hs₂s₃, fun hs₃s₁ => hs₁s₂.2 (Subset.trans hs₂s₃ hs₃s₁)⟩ #align set.ssubset_of_ssubset_of_subset Set.ssubset_of_ssubset_of_subset protected theorem ssubset_of_subset_of_ssubset {s₁ s₂ s₃ : Set α} (hs₁s₂ : s₁ ⊆ s₂) (hs₂s₃ : s₂ ⊂ s₃) : s₁ ⊂ s₃ := ⟨Subset.trans hs₁s₂ hs₂s₃.1, fun hs₃s₁ => hs₂s₃.2 (Subset.trans hs₃s₁ hs₁s₂)⟩ #align set.ssubset_of_subset_of_ssubset Set.ssubset_of_subset_of_ssubset theorem not_mem_empty (x : α) : ¬x ∈ (∅ : Set α) := id #align set.not_mem_empty Set.not_mem_empty -- Porting note (#10618): removed `simp` because `simp` can prove it theorem not_not_mem : ¬a ∉ s ↔ a ∈ s := not_not #align set.not_not_mem Set.not_not_mem /-! ### Non-empty sets -/ -- Porting note: we seem to need parentheses at `(↥s)`, -- even if we increase the right precedence of `↥` in `Mathlib.Tactic.Coe`. -- Porting note: removed `simp` as it is competing with `nonempty_subtype`. -- @[simp] theorem nonempty_coe_sort {s : Set α} : Nonempty (↥s) ↔ s.Nonempty := nonempty_subtype #align set.nonempty_coe_sort Set.nonempty_coe_sort alias ⟨_, Nonempty.coe_sort⟩ := nonempty_coe_sort #align set.nonempty.coe_sort Set.Nonempty.coe_sort theorem nonempty_def : s.Nonempty ↔ ∃ x, x ∈ s := Iff.rfl #align set.nonempty_def Set.nonempty_def theorem nonempty_of_mem {x} (h : x ∈ s) : s.Nonempty := ⟨x, h⟩ #align set.nonempty_of_mem Set.nonempty_of_mem theorem Nonempty.not_subset_empty : s.Nonempty → ¬s ⊆ ∅ | ⟨_, hx⟩, hs => hs hx #align set.nonempty.not_subset_empty Set.Nonempty.not_subset_empty /-- Extract a witness from `s.Nonempty`. This function might be used instead of case analysis on the argument. Note that it makes a proof depend on the `Classical.choice` axiom. -/ protected noncomputable def Nonempty.some (h : s.Nonempty) : α := Classical.choose h #align set.nonempty.some Set.Nonempty.some protected theorem Nonempty.some_mem (h : s.Nonempty) : h.some ∈ s := Classical.choose_spec h #align set.nonempty.some_mem Set.Nonempty.some_mem theorem Nonempty.mono (ht : s ⊆ t) (hs : s.Nonempty) : t.Nonempty := hs.imp ht #align set.nonempty.mono Set.Nonempty.mono theorem nonempty_of_not_subset (h : ¬s ⊆ t) : (s \ t).Nonempty := let ⟨x, xs, xt⟩ := not_subset.1 h ⟨x, xs, xt⟩ #align set.nonempty_of_not_subset Set.nonempty_of_not_subset theorem nonempty_of_ssubset (ht : s ⊂ t) : (t \ s).Nonempty := nonempty_of_not_subset ht.2 #align set.nonempty_of_ssubset Set.nonempty_of_ssubset theorem Nonempty.of_diff (h : (s \ t).Nonempty) : s.Nonempty := h.imp fun _ => And.left #align set.nonempty.of_diff Set.Nonempty.of_diff theorem nonempty_of_ssubset' (ht : s ⊂ t) : t.Nonempty := (nonempty_of_ssubset ht).of_diff #align set.nonempty_of_ssubset' Set.nonempty_of_ssubset' theorem Nonempty.inl (hs : s.Nonempty) : (s ∪ t).Nonempty := hs.imp fun _ => Or.inl #align set.nonempty.inl Set.Nonempty.inl theorem Nonempty.inr (ht : t.Nonempty) : (s ∪ t).Nonempty := ht.imp fun _ => Or.inr #align set.nonempty.inr Set.Nonempty.inr @[simp] theorem union_nonempty : (s ∪ t).Nonempty ↔ s.Nonempty ∨ t.Nonempty := exists_or #align set.union_nonempty Set.union_nonempty theorem Nonempty.left (h : (s ∩ t).Nonempty) : s.Nonempty := h.imp fun _ => And.left #align set.nonempty.left Set.Nonempty.left theorem Nonempty.right (h : (s ∩ t).Nonempty) : t.Nonempty := h.imp fun _ => And.right #align set.nonempty.right Set.Nonempty.right theorem inter_nonempty : (s ∩ t).Nonempty ↔ ∃ x, x ∈ s ∧ x ∈ t := Iff.rfl #align set.inter_nonempty Set.inter_nonempty theorem inter_nonempty_iff_exists_left : (s ∩ t).Nonempty ↔ ∃ x ∈ s, x ∈ t := by simp_rw [inter_nonempty] #align set.inter_nonempty_iff_exists_left Set.inter_nonempty_iff_exists_left theorem inter_nonempty_iff_exists_right : (s ∩ t).Nonempty ↔ ∃ x ∈ t, x ∈ s := by simp_rw [inter_nonempty, and_comm] #align set.inter_nonempty_iff_exists_right Set.inter_nonempty_iff_exists_right theorem nonempty_iff_univ_nonempty : Nonempty α ↔ (univ : Set α).Nonempty := ⟨fun ⟨x⟩ => ⟨x, trivial⟩, fun ⟨x, _⟩ => ⟨x⟩⟩ #align set.nonempty_iff_univ_nonempty Set.nonempty_iff_univ_nonempty @[simp] theorem univ_nonempty : ∀ [Nonempty α], (univ : Set α).Nonempty | ⟨x⟩ => ⟨x, trivial⟩ #align set.univ_nonempty Set.univ_nonempty theorem Nonempty.to_subtype : s.Nonempty → Nonempty (↥s) := nonempty_subtype.2 #align set.nonempty.to_subtype Set.Nonempty.to_subtype theorem Nonempty.to_type : s.Nonempty → Nonempty α := fun ⟨x, _⟩ => ⟨x⟩ #align set.nonempty.to_type Set.Nonempty.to_type instance univ.nonempty [Nonempty α] : Nonempty (↥(Set.univ : Set α)) := Set.univ_nonempty.to_subtype #align set.univ.nonempty Set.univ.nonempty theorem nonempty_of_nonempty_subtype [Nonempty (↥s)] : s.Nonempty := nonempty_subtype.mp ‹_› #align set.nonempty_of_nonempty_subtype Set.nonempty_of_nonempty_subtype /-! ### Lemmas about the empty set -/ theorem empty_def : (∅ : Set α) = { _x : α | False } := rfl #align set.empty_def Set.empty_def @[simp] theorem mem_empty_iff_false (x : α) : x ∈ (∅ : Set α) ↔ False := Iff.rfl #align set.mem_empty_iff_false Set.mem_empty_iff_false @[simp] theorem setOf_false : { _a : α | False } = ∅ := rfl #align set.set_of_false Set.setOf_false @[simp] theorem setOf_bot : { _x : α | ⊥ } = ∅ := rfl @[simp] theorem empty_subset (s : Set α) : ∅ ⊆ s := nofun #align set.empty_subset Set.empty_subset theorem subset_empty_iff {s : Set α} : s ⊆ ∅ ↔ s = ∅ := (Subset.antisymm_iff.trans <| and_iff_left (empty_subset _)).symm #align set.subset_empty_iff Set.subset_empty_iff theorem eq_empty_iff_forall_not_mem {s : Set α} : s = ∅ ↔ ∀ x, x ∉ s := subset_empty_iff.symm #align set.eq_empty_iff_forall_not_mem Set.eq_empty_iff_forall_not_mem theorem eq_empty_of_forall_not_mem (h : ∀ x, x ∉ s) : s = ∅ := subset_empty_iff.1 h #align set.eq_empty_of_forall_not_mem Set.eq_empty_of_forall_not_mem theorem eq_empty_of_subset_empty {s : Set α} : s ⊆ ∅ → s = ∅ := subset_empty_iff.1 #align set.eq_empty_of_subset_empty Set.eq_empty_of_subset_empty theorem eq_empty_of_isEmpty [IsEmpty α] (s : Set α) : s = ∅ := eq_empty_of_subset_empty fun x _ => isEmptyElim x #align set.eq_empty_of_is_empty Set.eq_empty_of_isEmpty /-- There is exactly one set of a type that is empty. -/ instance uniqueEmpty [IsEmpty α] : Unique (Set α) where default := ∅ uniq := eq_empty_of_isEmpty #align set.unique_empty Set.uniqueEmpty /-- See also `Set.nonempty_iff_ne_empty`. -/ theorem not_nonempty_iff_eq_empty {s : Set α} : ¬s.Nonempty ↔ s = ∅ := by simp only [Set.Nonempty, not_exists, eq_empty_iff_forall_not_mem] #align set.not_nonempty_iff_eq_empty Set.not_nonempty_iff_eq_empty /-- See also `Set.not_nonempty_iff_eq_empty`. -/ theorem nonempty_iff_ne_empty : s.Nonempty ↔ s ≠ ∅ := not_nonempty_iff_eq_empty.not_right #align set.nonempty_iff_ne_empty Set.nonempty_iff_ne_empty /-- See also `nonempty_iff_ne_empty'`. -/ theorem not_nonempty_iff_eq_empty' : ¬Nonempty s ↔ s = ∅ := by rw [nonempty_subtype, not_exists, eq_empty_iff_forall_not_mem] /-- See also `not_nonempty_iff_eq_empty'`. -/ theorem nonempty_iff_ne_empty' : Nonempty s ↔ s ≠ ∅ := not_nonempty_iff_eq_empty'.not_right alias ⟨Nonempty.ne_empty, _⟩ := nonempty_iff_ne_empty #align set.nonempty.ne_empty Set.Nonempty.ne_empty @[simp] theorem not_nonempty_empty : ¬(∅ : Set α).Nonempty := fun ⟨_, hx⟩ => hx #align set.not_nonempty_empty Set.not_nonempty_empty -- Porting note: removing `@[simp]` as it is competing with `isEmpty_subtype`. -- @[simp] theorem isEmpty_coe_sort {s : Set α} : IsEmpty (↥s) ↔ s = ∅ := not_iff_not.1 <| by simpa using nonempty_iff_ne_empty #align set.is_empty_coe_sort Set.isEmpty_coe_sort theorem eq_empty_or_nonempty (s : Set α) : s = ∅ ∨ s.Nonempty := or_iff_not_imp_left.2 nonempty_iff_ne_empty.2 #align set.eq_empty_or_nonempty Set.eq_empty_or_nonempty theorem subset_eq_empty {s t : Set α} (h : t ⊆ s) (e : s = ∅) : t = ∅ := subset_empty_iff.1 <| e ▸ h #align set.subset_eq_empty Set.subset_eq_empty theorem forall_mem_empty {p : α → Prop} : (∀ x ∈ (∅ : Set α), p x) ↔ True := iff_true_intro fun _ => False.elim #align set.ball_empty_iff Set.forall_mem_empty @[deprecated (since := "2024-03-23")] alias ball_empty_iff := forall_mem_empty instance (α : Type u) : IsEmpty.{u + 1} (↥(∅ : Set α)) := ⟨fun x => x.2⟩ @[simp] theorem empty_ssubset : ∅ ⊂ s ↔ s.Nonempty := (@bot_lt_iff_ne_bot (Set α) _ _ _).trans nonempty_iff_ne_empty.symm #align set.empty_ssubset Set.empty_ssubset alias ⟨_, Nonempty.empty_ssubset⟩ := empty_ssubset #align set.nonempty.empty_ssubset Set.Nonempty.empty_ssubset /-! ### Universal set. In Lean `@univ α` (or `univ : Set α`) is the set that contains all elements of type `α`. Mathematically it is the same as `α` but it has a different type. -/ @[simp] theorem setOf_true : { _x : α | True } = univ := rfl #align set.set_of_true Set.setOf_true @[simp] theorem setOf_top : { _x : α | ⊤ } = univ := rfl @[simp] theorem univ_eq_empty_iff : (univ : Set α) = ∅ ↔ IsEmpty α := eq_empty_iff_forall_not_mem.trans ⟨fun H => ⟨fun x => H x trivial⟩, fun H x _ => @IsEmpty.false α H x⟩ #align set.univ_eq_empty_iff Set.univ_eq_empty_iff theorem empty_ne_univ [Nonempty α] : (∅ : Set α) ≠ univ := fun e => not_isEmpty_of_nonempty α <| univ_eq_empty_iff.1 e.symm #align set.empty_ne_univ Set.empty_ne_univ @[simp] theorem subset_univ (s : Set α) : s ⊆ univ := fun _ _ => trivial #align set.subset_univ Set.subset_univ @[simp] theorem univ_subset_iff {s : Set α} : univ ⊆ s ↔ s = univ := @top_le_iff _ _ _ s #align set.univ_subset_iff Set.univ_subset_iff alias ⟨eq_univ_of_univ_subset, _⟩ := univ_subset_iff #align set.eq_univ_of_univ_subset Set.eq_univ_of_univ_subset theorem eq_univ_iff_forall {s : Set α} : s = univ ↔ ∀ x, x ∈ s := univ_subset_iff.symm.trans <| forall_congr' fun _ => imp_iff_right trivial #align set.eq_univ_iff_forall Set.eq_univ_iff_forall theorem eq_univ_of_forall {s : Set α} : (∀ x, x ∈ s) → s = univ := eq_univ_iff_forall.2 #align set.eq_univ_of_forall Set.eq_univ_of_forall theorem Nonempty.eq_univ [Subsingleton α] : s.Nonempty → s = univ := by rintro ⟨x, hx⟩ exact eq_univ_of_forall fun y => by rwa [Subsingleton.elim y x] #align set.nonempty.eq_univ Set.Nonempty.eq_univ theorem eq_univ_of_subset {s t : Set α} (h : s ⊆ t) (hs : s = univ) : t = univ := eq_univ_of_univ_subset <| (hs ▸ h : univ ⊆ t) #align set.eq_univ_of_subset Set.eq_univ_of_subset theorem exists_mem_of_nonempty (α) : ∀ [Nonempty α], ∃ x : α, x ∈ (univ : Set α) | ⟨x⟩ => ⟨x, trivial⟩ #align set.exists_mem_of_nonempty Set.exists_mem_of_nonempty theorem ne_univ_iff_exists_not_mem {α : Type*} (s : Set α) : s ≠ univ ↔ ∃ a, a ∉ s := by rw [← not_forall, ← eq_univ_iff_forall] #align set.ne_univ_iff_exists_not_mem Set.ne_univ_iff_exists_not_mem theorem not_subset_iff_exists_mem_not_mem {α : Type*} {s t : Set α} : ¬s ⊆ t ↔ ∃ x, x ∈ s ∧ x ∉ t := by simp [subset_def] #align set.not_subset_iff_exists_mem_not_mem Set.not_subset_iff_exists_mem_not_mem theorem univ_unique [Unique α] : @Set.univ α = {default} := Set.ext fun x => iff_of_true trivial <| Subsingleton.elim x default #align set.univ_unique Set.univ_unique theorem ssubset_univ_iff : s ⊂ univ ↔ s ≠ univ := lt_top_iff_ne_top #align set.ssubset_univ_iff Set.ssubset_univ_iff instance nontrivial_of_nonempty [Nonempty α] : Nontrivial (Set α) := ⟨⟨∅, univ, empty_ne_univ⟩⟩ #align set.nontrivial_of_nonempty Set.nontrivial_of_nonempty /-! ### Lemmas about union -/ theorem union_def {s₁ s₂ : Set α} : s₁ ∪ s₂ = { a | a ∈ s₁ ∨ a ∈ s₂ } := rfl #align set.union_def Set.union_def theorem mem_union_left {x : α} {a : Set α} (b : Set α) : x ∈ a → x ∈ a ∪ b := Or.inl #align set.mem_union_left Set.mem_union_left theorem mem_union_right {x : α} {b : Set α} (a : Set α) : x ∈ b → x ∈ a ∪ b := Or.inr #align set.mem_union_right Set.mem_union_right theorem mem_or_mem_of_mem_union {x : α} {a b : Set α} (H : x ∈ a ∪ b) : x ∈ a ∨ x ∈ b := H #align set.mem_or_mem_of_mem_union Set.mem_or_mem_of_mem_union theorem MemUnion.elim {x : α} {a b : Set α} {P : Prop} (H₁ : x ∈ a ∪ b) (H₂ : x ∈ a → P) (H₃ : x ∈ b → P) : P := Or.elim H₁ H₂ H₃ #align set.mem_union.elim Set.MemUnion.elim @[simp] theorem mem_union (x : α) (a b : Set α) : x ∈ a ∪ b ↔ x ∈ a ∨ x ∈ b := Iff.rfl #align set.mem_union Set.mem_union @[simp] theorem union_self (a : Set α) : a ∪ a = a := ext fun _ => or_self_iff #align set.union_self Set.union_self @[simp] theorem union_empty (a : Set α) : a ∪ ∅ = a := ext fun _ => or_false_iff _ #align set.union_empty Set.union_empty @[simp] theorem empty_union (a : Set α) : ∅ ∪ a = a := ext fun _ => false_or_iff _ #align set.empty_union Set.empty_union theorem union_comm (a b : Set α) : a ∪ b = b ∪ a := ext fun _ => or_comm #align set.union_comm Set.union_comm theorem union_assoc (a b c : Set α) : a ∪ b ∪ c = a ∪ (b ∪ c) := ext fun _ => or_assoc #align set.union_assoc Set.union_assoc instance union_isAssoc : Std.Associative (α := Set α) (· ∪ ·) := ⟨union_assoc⟩ #align set.union_is_assoc Set.union_isAssoc instance union_isComm : Std.Commutative (α := Set α) (· ∪ ·) := ⟨union_comm⟩ #align set.union_is_comm Set.union_isComm theorem union_left_comm (s₁ s₂ s₃ : Set α) : s₁ ∪ (s₂ ∪ s₃) = s₂ ∪ (s₁ ∪ s₃) := ext fun _ => or_left_comm #align set.union_left_comm Set.union_left_comm theorem union_right_comm (s₁ s₂ s₃ : Set α) : s₁ ∪ s₂ ∪ s₃ = s₁ ∪ s₃ ∪ s₂ := ext fun _ => or_right_comm #align set.union_right_comm Set.union_right_comm @[simp] theorem union_eq_left {s t : Set α} : s ∪ t = s ↔ t ⊆ s := sup_eq_left #align set.union_eq_left_iff_subset Set.union_eq_left @[simp] theorem union_eq_right {s t : Set α} : s ∪ t = t ↔ s ⊆ t := sup_eq_right #align set.union_eq_right_iff_subset Set.union_eq_right theorem union_eq_self_of_subset_left {s t : Set α} (h : s ⊆ t) : s ∪ t = t := union_eq_right.mpr h #align set.union_eq_self_of_subset_left Set.union_eq_self_of_subset_left theorem union_eq_self_of_subset_right {s t : Set α} (h : t ⊆ s) : s ∪ t = s := union_eq_left.mpr h #align set.union_eq_self_of_subset_right Set.union_eq_self_of_subset_right @[simp] theorem subset_union_left {s t : Set α} : s ⊆ s ∪ t := fun _ => Or.inl #align set.subset_union_left Set.subset_union_left @[simp] theorem subset_union_right {s t : Set α} : t ⊆ s ∪ t := fun _ => Or.inr #align set.subset_union_right Set.subset_union_right theorem union_subset {s t r : Set α} (sr : s ⊆ r) (tr : t ⊆ r) : s ∪ t ⊆ r := fun _ => Or.rec (@sr _) (@tr _) #align set.union_subset Set.union_subset @[simp] theorem union_subset_iff {s t u : Set α} : s ∪ t ⊆ u ↔ s ⊆ u ∧ t ⊆ u := (forall_congr' fun _ => or_imp).trans forall_and #align set.union_subset_iff Set.union_subset_iff @[gcongr] theorem union_subset_union {s₁ s₂ t₁ t₂ : Set α} (h₁ : s₁ ⊆ s₂) (h₂ : t₁ ⊆ t₂) : s₁ ∪ t₁ ⊆ s₂ ∪ t₂ := fun _ => Or.imp (@h₁ _) (@h₂ _) #align set.union_subset_union Set.union_subset_union @[gcongr] theorem union_subset_union_left {s₁ s₂ : Set α} (t) (h : s₁ ⊆ s₂) : s₁ ∪ t ⊆ s₂ ∪ t := union_subset_union h Subset.rfl #align set.union_subset_union_left Set.union_subset_union_left @[gcongr] theorem union_subset_union_right (s) {t₁ t₂ : Set α} (h : t₁ ⊆ t₂) : s ∪ t₁ ⊆ s ∪ t₂ := union_subset_union Subset.rfl h #align set.union_subset_union_right Set.union_subset_union_right theorem subset_union_of_subset_left {s t : Set α} (h : s ⊆ t) (u : Set α) : s ⊆ t ∪ u := h.trans subset_union_left #align set.subset_union_of_subset_left Set.subset_union_of_subset_left theorem subset_union_of_subset_right {s u : Set α} (h : s ⊆ u) (t : Set α) : s ⊆ t ∪ u := h.trans subset_union_right #align set.subset_union_of_subset_right Set.subset_union_of_subset_right -- Porting note: replaced `⊔` in RHS theorem union_congr_left (ht : t ⊆ s ∪ u) (hu : u ⊆ s ∪ t) : s ∪ t = s ∪ u := sup_congr_left ht hu #align set.union_congr_left Set.union_congr_left theorem union_congr_right (hs : s ⊆ t ∪ u) (ht : t ⊆ s ∪ u) : s ∪ u = t ∪ u := sup_congr_right hs ht #align set.union_congr_right Set.union_congr_right theorem union_eq_union_iff_left : s ∪ t = s ∪ u ↔ t ⊆ s ∪ u ∧ u ⊆ s ∪ t := sup_eq_sup_iff_left #align set.union_eq_union_iff_left Set.union_eq_union_iff_left theorem union_eq_union_iff_right : s ∪ u = t ∪ u ↔ s ⊆ t ∪ u ∧ t ⊆ s ∪ u := sup_eq_sup_iff_right #align set.union_eq_union_iff_right Set.union_eq_union_iff_right @[simp] theorem union_empty_iff {s t : Set α} : s ∪ t = ∅ ↔ s = ∅ ∧ t = ∅ := by simp only [← subset_empty_iff] exact union_subset_iff #align set.union_empty_iff Set.union_empty_iff @[simp] theorem union_univ (s : Set α) : s ∪ univ = univ := sup_top_eq _ #align set.union_univ Set.union_univ @[simp] theorem univ_union (s : Set α) : univ ∪ s = univ := top_sup_eq _ #align set.univ_union Set.univ_union /-! ### Lemmas about intersection -/ theorem inter_def {s₁ s₂ : Set α} : s₁ ∩ s₂ = { a | a ∈ s₁ ∧ a ∈ s₂ } := rfl #align set.inter_def Set.inter_def @[simp, mfld_simps] theorem mem_inter_iff (x : α) (a b : Set α) : x ∈ a ∩ b ↔ x ∈ a ∧ x ∈ b := Iff.rfl #align set.mem_inter_iff Set.mem_inter_iff theorem mem_inter {x : α} {a b : Set α} (ha : x ∈ a) (hb : x ∈ b) : x ∈ a ∩ b := ⟨ha, hb⟩ #align set.mem_inter Set.mem_inter theorem mem_of_mem_inter_left {x : α} {a b : Set α} (h : x ∈ a ∩ b) : x ∈ a := h.left #align set.mem_of_mem_inter_left Set.mem_of_mem_inter_left theorem mem_of_mem_inter_right {x : α} {a b : Set α} (h : x ∈ a ∩ b) : x ∈ b := h.right #align set.mem_of_mem_inter_right Set.mem_of_mem_inter_right @[simp] theorem inter_self (a : Set α) : a ∩ a = a := ext fun _ => and_self_iff #align set.inter_self Set.inter_self @[simp] theorem inter_empty (a : Set α) : a ∩ ∅ = ∅ := ext fun _ => and_false_iff _ #align set.inter_empty Set.inter_empty @[simp] theorem empty_inter (a : Set α) : ∅ ∩ a = ∅ := ext fun _ => false_and_iff _ #align set.empty_inter Set.empty_inter theorem inter_comm (a b : Set α) : a ∩ b = b ∩ a := ext fun _ => and_comm #align set.inter_comm Set.inter_comm theorem inter_assoc (a b c : Set α) : a ∩ b ∩ c = a ∩ (b ∩ c) := ext fun _ => and_assoc #align set.inter_assoc Set.inter_assoc instance inter_isAssoc : Std.Associative (α := Set α) (· ∩ ·) := ⟨inter_assoc⟩ #align set.inter_is_assoc Set.inter_isAssoc instance inter_isComm : Std.Commutative (α := Set α) (· ∩ ·) := ⟨inter_comm⟩ #align set.inter_is_comm Set.inter_isComm theorem inter_left_comm (s₁ s₂ s₃ : Set α) : s₁ ∩ (s₂ ∩ s₃) = s₂ ∩ (s₁ ∩ s₃) := ext fun _ => and_left_comm #align set.inter_left_comm Set.inter_left_comm theorem inter_right_comm (s₁ s₂ s₃ : Set α) : s₁ ∩ s₂ ∩ s₃ = s₁ ∩ s₃ ∩ s₂ := ext fun _ => and_right_comm #align set.inter_right_comm Set.inter_right_comm @[simp, mfld_simps] theorem inter_subset_left {s t : Set α} : s ∩ t ⊆ s := fun _ => And.left #align set.inter_subset_left Set.inter_subset_left @[simp] theorem inter_subset_right {s t : Set α} : s ∩ t ⊆ t := fun _ => And.right #align set.inter_subset_right Set.inter_subset_right theorem subset_inter {s t r : Set α} (rs : r ⊆ s) (rt : r ⊆ t) : r ⊆ s ∩ t := fun _ h => ⟨rs h, rt h⟩ #align set.subset_inter Set.subset_inter @[simp] theorem subset_inter_iff {s t r : Set α} : r ⊆ s ∩ t ↔ r ⊆ s ∧ r ⊆ t := (forall_congr' fun _ => imp_and).trans forall_and #align set.subset_inter_iff Set.subset_inter_iff @[simp] lemma inter_eq_left : s ∩ t = s ↔ s ⊆ t := inf_eq_left #align set.inter_eq_left_iff_subset Set.inter_eq_left @[simp] lemma inter_eq_right : s ∩ t = t ↔ t ⊆ s := inf_eq_right #align set.inter_eq_right_iff_subset Set.inter_eq_right @[simp] lemma left_eq_inter : s = s ∩ t ↔ s ⊆ t := left_eq_inf @[simp] lemma right_eq_inter : t = s ∩ t ↔ t ⊆ s := right_eq_inf theorem inter_eq_self_of_subset_left {s t : Set α} : s ⊆ t → s ∩ t = s := inter_eq_left.mpr #align set.inter_eq_self_of_subset_left Set.inter_eq_self_of_subset_left theorem inter_eq_self_of_subset_right {s t : Set α} : t ⊆ s → s ∩ t = t := inter_eq_right.mpr #align set.inter_eq_self_of_subset_right Set.inter_eq_self_of_subset_right theorem inter_congr_left (ht : s ∩ u ⊆ t) (hu : s ∩ t ⊆ u) : s ∩ t = s ∩ u := inf_congr_left ht hu #align set.inter_congr_left Set.inter_congr_left theorem inter_congr_right (hs : t ∩ u ⊆ s) (ht : s ∩ u ⊆ t) : s ∩ u = t ∩ u := inf_congr_right hs ht #align set.inter_congr_right Set.inter_congr_right theorem inter_eq_inter_iff_left : s ∩ t = s ∩ u ↔ s ∩ u ⊆ t ∧ s ∩ t ⊆ u := inf_eq_inf_iff_left #align set.inter_eq_inter_iff_left Set.inter_eq_inter_iff_left theorem inter_eq_inter_iff_right : s ∩ u = t ∩ u ↔ t ∩ u ⊆ s ∧ s ∩ u ⊆ t := inf_eq_inf_iff_right #align set.inter_eq_inter_iff_right Set.inter_eq_inter_iff_right @[simp, mfld_simps] theorem inter_univ (a : Set α) : a ∩ univ = a := inf_top_eq _ #align set.inter_univ Set.inter_univ @[simp, mfld_simps] theorem univ_inter (a : Set α) : univ ∩ a = a := top_inf_eq _ #align set.univ_inter Set.univ_inter @[gcongr] theorem inter_subset_inter {s₁ s₂ t₁ t₂ : Set α} (h₁ : s₁ ⊆ t₁) (h₂ : s₂ ⊆ t₂) : s₁ ∩ s₂ ⊆ t₁ ∩ t₂ := fun _ => And.imp (@h₁ _) (@h₂ _) #align set.inter_subset_inter Set.inter_subset_inter @[gcongr] theorem inter_subset_inter_left {s t : Set α} (u : Set α) (H : s ⊆ t) : s ∩ u ⊆ t ∩ u := inter_subset_inter H Subset.rfl #align set.inter_subset_inter_left Set.inter_subset_inter_left @[gcongr] theorem inter_subset_inter_right {s t : Set α} (u : Set α) (H : s ⊆ t) : u ∩ s ⊆ u ∩ t := inter_subset_inter Subset.rfl H #align set.inter_subset_inter_right Set.inter_subset_inter_right theorem union_inter_cancel_left {s t : Set α} : (s ∪ t) ∩ s = s := inter_eq_self_of_subset_right subset_union_left #align set.union_inter_cancel_left Set.union_inter_cancel_left theorem union_inter_cancel_right {s t : Set α} : (s ∪ t) ∩ t = t := inter_eq_self_of_subset_right subset_union_right #align set.union_inter_cancel_right Set.union_inter_cancel_right theorem inter_setOf_eq_sep (s : Set α) (p : α → Prop) : s ∩ {a | p a} = {a ∈ s | p a} := rfl #align set.inter_set_of_eq_sep Set.inter_setOf_eq_sep theorem setOf_inter_eq_sep (p : α → Prop) (s : Set α) : {a | p a} ∩ s = {a ∈ s | p a} := inter_comm _ _ #align set.set_of_inter_eq_sep Set.setOf_inter_eq_sep /-! ### Distributivity laws -/ theorem inter_union_distrib_left (s t u : Set α) : s ∩ (t ∪ u) = s ∩ t ∪ s ∩ u := inf_sup_left _ _ _ #align set.inter_distrib_left Set.inter_union_distrib_left theorem union_inter_distrib_right (s t u : Set α) : (s ∪ t) ∩ u = s ∩ u ∪ t ∩ u := inf_sup_right _ _ _ #align set.inter_distrib_right Set.union_inter_distrib_right theorem union_inter_distrib_left (s t u : Set α) : s ∪ t ∩ u = (s ∪ t) ∩ (s ∪ u) := sup_inf_left _ _ _ #align set.union_distrib_left Set.union_inter_distrib_left theorem inter_union_distrib_right (s t u : Set α) : s ∩ t ∪ u = (s ∪ u) ∩ (t ∪ u) := sup_inf_right _ _ _ #align set.union_distrib_right Set.inter_union_distrib_right -- 2024-03-22 @[deprecated] alias inter_distrib_left := inter_union_distrib_left @[deprecated] alias inter_distrib_right := union_inter_distrib_right @[deprecated] alias union_distrib_left := union_inter_distrib_left @[deprecated] alias union_distrib_right := inter_union_distrib_right theorem union_union_distrib_left (s t u : Set α) : s ∪ (t ∪ u) = s ∪ t ∪ (s ∪ u) := sup_sup_distrib_left _ _ _ #align set.union_union_distrib_left Set.union_union_distrib_left theorem union_union_distrib_right (s t u : Set α) : s ∪ t ∪ u = s ∪ u ∪ (t ∪ u) := sup_sup_distrib_right _ _ _ #align set.union_union_distrib_right Set.union_union_distrib_right theorem inter_inter_distrib_left (s t u : Set α) : s ∩ (t ∩ u) = s ∩ t ∩ (s ∩ u) := inf_inf_distrib_left _ _ _ #align set.inter_inter_distrib_left Set.inter_inter_distrib_left theorem inter_inter_distrib_right (s t u : Set α) : s ∩ t ∩ u = s ∩ u ∩ (t ∩ u) := inf_inf_distrib_right _ _ _ #align set.inter_inter_distrib_right Set.inter_inter_distrib_right theorem union_union_union_comm (s t u v : Set α) : s ∪ t ∪ (u ∪ v) = s ∪ u ∪ (t ∪ v) := sup_sup_sup_comm _ _ _ _ #align set.union_union_union_comm Set.union_union_union_comm theorem inter_inter_inter_comm (s t u v : Set α) : s ∩ t ∩ (u ∩ v) = s ∩ u ∩ (t ∩ v) := inf_inf_inf_comm _ _ _ _ #align set.inter_inter_inter_comm Set.inter_inter_inter_comm /-! ### Lemmas about `insert` `insert α s` is the set `{α} ∪ s`. -/ theorem insert_def (x : α) (s : Set α) : insert x s = { y | y = x ∨ y ∈ s } := rfl #align set.insert_def Set.insert_def @[simp] theorem subset_insert (x : α) (s : Set α) : s ⊆ insert x s := fun _ => Or.inr #align set.subset_insert Set.subset_insert theorem mem_insert (x : α) (s : Set α) : x ∈ insert x s := Or.inl rfl #align set.mem_insert Set.mem_insert theorem mem_insert_of_mem {x : α} {s : Set α} (y : α) : x ∈ s → x ∈ insert y s := Or.inr #align set.mem_insert_of_mem Set.mem_insert_of_mem theorem eq_or_mem_of_mem_insert {x a : α} {s : Set α} : x ∈ insert a s → x = a ∨ x ∈ s := id #align set.eq_or_mem_of_mem_insert Set.eq_or_mem_of_mem_insert theorem mem_of_mem_insert_of_ne : b ∈ insert a s → b ≠ a → b ∈ s := Or.resolve_left #align set.mem_of_mem_insert_of_ne Set.mem_of_mem_insert_of_ne theorem eq_of_not_mem_of_mem_insert : b ∈ insert a s → b ∉ s → b = a := Or.resolve_right #align set.eq_of_not_mem_of_mem_insert Set.eq_of_not_mem_of_mem_insert @[simp] theorem mem_insert_iff {x a : α} {s : Set α} : x ∈ insert a s ↔ x = a ∨ x ∈ s := Iff.rfl #align set.mem_insert_iff Set.mem_insert_iff @[simp] theorem insert_eq_of_mem {a : α} {s : Set α} (h : a ∈ s) : insert a s = s := ext fun _ => or_iff_right_of_imp fun e => e.symm ▸ h #align set.insert_eq_of_mem Set.insert_eq_of_mem theorem ne_insert_of_not_mem {s : Set α} (t : Set α) {a : α} : a ∉ s → s ≠ insert a t := mt fun e => e.symm ▸ mem_insert _ _ #align set.ne_insert_of_not_mem Set.ne_insert_of_not_mem @[simp] theorem insert_eq_self : insert a s = s ↔ a ∈ s := ⟨fun h => h ▸ mem_insert _ _, insert_eq_of_mem⟩ #align set.insert_eq_self Set.insert_eq_self theorem insert_ne_self : insert a s ≠ s ↔ a ∉ s := insert_eq_self.not #align set.insert_ne_self Set.insert_ne_self theorem insert_subset_iff : insert a s ⊆ t ↔ a ∈ t ∧ s ⊆ t := by simp only [subset_def, mem_insert_iff, or_imp, forall_and, forall_eq] #align set.insert_subset Set.insert_subset_iff theorem insert_subset (ha : a ∈ t) (hs : s ⊆ t) : insert a s ⊆ t := insert_subset_iff.mpr ⟨ha, hs⟩ theorem insert_subset_insert (h : s ⊆ t) : insert a s ⊆ insert a t := fun _ => Or.imp_right (@h _) #align set.insert_subset_insert Set.insert_subset_insert @[simp] theorem insert_subset_insert_iff (ha : a ∉ s) : insert a s ⊆ insert a t ↔ s ⊆ t := by refine ⟨fun h x hx => ?_, insert_subset_insert⟩ rcases h (subset_insert _ _ hx) with (rfl | hxt) exacts [(ha hx).elim, hxt] #align set.insert_subset_insert_iff Set.insert_subset_insert_iff theorem subset_insert_iff_of_not_mem (ha : a ∉ s) : s ⊆ insert a t ↔ s ⊆ t := forall₂_congr fun _ hb => or_iff_right <| ne_of_mem_of_not_mem hb ha #align set.subset_insert_iff_of_not_mem Set.subset_insert_iff_of_not_mem theorem ssubset_iff_insert {s t : Set α} : s ⊂ t ↔ ∃ a ∉ s, insert a s ⊆ t := by simp only [insert_subset_iff, exists_and_right, ssubset_def, not_subset] aesop #align set.ssubset_iff_insert Set.ssubset_iff_insert theorem ssubset_insert {s : Set α} {a : α} (h : a ∉ s) : s ⊂ insert a s := ssubset_iff_insert.2 ⟨a, h, Subset.rfl⟩ #align set.ssubset_insert Set.ssubset_insert theorem insert_comm (a b : α) (s : Set α) : insert a (insert b s) = insert b (insert a s) := ext fun _ => or_left_comm #align set.insert_comm Set.insert_comm -- Porting note (#10618): removing `simp` attribute because `simp` can prove it theorem insert_idem (a : α) (s : Set α) : insert a (insert a s) = insert a s := insert_eq_of_mem <| mem_insert _ _ #align set.insert_idem Set.insert_idem theorem insert_union : insert a s ∪ t = insert a (s ∪ t) := ext fun _ => or_assoc #align set.insert_union Set.insert_union @[simp] theorem union_insert : s ∪ insert a t = insert a (s ∪ t) := ext fun _ => or_left_comm #align set.union_insert Set.union_insert @[simp] theorem insert_nonempty (a : α) (s : Set α) : (insert a s).Nonempty := ⟨a, mem_insert a s⟩ #align set.insert_nonempty Set.insert_nonempty instance (a : α) (s : Set α) : Nonempty (insert a s : Set α) := (insert_nonempty a s).to_subtype theorem insert_inter_distrib (a : α) (s t : Set α) : insert a (s ∩ t) = insert a s ∩ insert a t := ext fun _ => or_and_left #align set.insert_inter_distrib Set.insert_inter_distrib theorem insert_union_distrib (a : α) (s t : Set α) : insert a (s ∪ t) = insert a s ∪ insert a t := ext fun _ => or_or_distrib_left #align set.insert_union_distrib Set.insert_union_distrib theorem insert_inj (ha : a ∉ s) : insert a s = insert b s ↔ a = b := ⟨fun h => eq_of_not_mem_of_mem_insert (h.subst <| mem_insert a s) ha, congr_arg (fun x => insert x s)⟩ #align set.insert_inj Set.insert_inj -- useful in proofs by induction theorem forall_of_forall_insert {P : α → Prop} {a : α} {s : Set α} (H : ∀ x, x ∈ insert a s → P x) (x) (h : x ∈ s) : P x := H _ (Or.inr h) #align set.forall_of_forall_insert Set.forall_of_forall_insert theorem forall_insert_of_forall {P : α → Prop} {a : α} {s : Set α} (H : ∀ x, x ∈ s → P x) (ha : P a) (x) (h : x ∈ insert a s) : P x := h.elim (fun e => e.symm ▸ ha) (H _) #align set.forall_insert_of_forall Set.forall_insert_of_forall /- Porting note: ∃ x ∈ insert a s, P x is parsed as ∃ x, x ∈ insert a s ∧ P x, where in Lean3 it was parsed as `∃ x, ∃ (h : x ∈ insert a s), P x` -/ theorem exists_mem_insert {P : α → Prop} {a : α} {s : Set α} : (∃ x ∈ insert a s, P x) ↔ (P a ∨ ∃ x ∈ s, P x) := by simp [mem_insert_iff, or_and_right, exists_and_left, exists_or] #align set.bex_insert_iff Set.exists_mem_insert @[deprecated (since := "2024-03-23")] alias bex_insert_iff := exists_mem_insert theorem forall_mem_insert {P : α → Prop} {a : α} {s : Set α} : (∀ x ∈ insert a s, P x) ↔ P a ∧ ∀ x ∈ s, P x := forall₂_or_left.trans <| and_congr_left' forall_eq #align set.ball_insert_iff Set.forall_mem_insert @[deprecated (since := "2024-03-23")] alias ball_insert_iff := forall_mem_insert /-! ### Lemmas about singletons -/ /- porting note: instance was in core in Lean3 -/ instance : LawfulSingleton α (Set α) := ⟨fun x => Set.ext fun a => by simp only [mem_empty_iff_false, mem_insert_iff, or_false] exact Iff.rfl⟩ theorem singleton_def (a : α) : ({a} : Set α) = insert a ∅ := (insert_emptyc_eq a).symm #align set.singleton_def Set.singleton_def @[simp] theorem mem_singleton_iff {a b : α} : a ∈ ({b} : Set α) ↔ a = b := Iff.rfl #align set.mem_singleton_iff Set.mem_singleton_iff @[simp] theorem setOf_eq_eq_singleton {a : α} : { n | n = a } = {a} := rfl #align set.set_of_eq_eq_singleton Set.setOf_eq_eq_singleton @[simp] theorem setOf_eq_eq_singleton' {a : α} : { x | a = x } = {a} := ext fun _ => eq_comm #align set.set_of_eq_eq_singleton' Set.setOf_eq_eq_singleton' -- TODO: again, annotation needed --Porting note (#11119): removed `simp` attribute theorem mem_singleton (a : α) : a ∈ ({a} : Set α) := @rfl _ _ #align set.mem_singleton Set.mem_singleton theorem eq_of_mem_singleton {x y : α} (h : x ∈ ({y} : Set α)) : x = y := h #align set.eq_of_mem_singleton Set.eq_of_mem_singleton @[simp] theorem singleton_eq_singleton_iff {x y : α} : {x} = ({y} : Set α) ↔ x = y := ext_iff.trans eq_iff_eq_cancel_left #align set.singleton_eq_singleton_iff Set.singleton_eq_singleton_iff theorem singleton_injective : Injective (singleton : α → Set α) := fun _ _ => singleton_eq_singleton_iff.mp #align set.singleton_injective Set.singleton_injective theorem mem_singleton_of_eq {x y : α} (H : x = y) : x ∈ ({y} : Set α) := H #align set.mem_singleton_of_eq Set.mem_singleton_of_eq theorem insert_eq (x : α) (s : Set α) : insert x s = ({x} : Set α) ∪ s := rfl #align set.insert_eq Set.insert_eq @[simp] theorem singleton_nonempty (a : α) : ({a} : Set α).Nonempty := ⟨a, rfl⟩ #align set.singleton_nonempty Set.singleton_nonempty @[simp] theorem singleton_ne_empty (a : α) : ({a} : Set α) ≠ ∅ := (singleton_nonempty _).ne_empty #align set.singleton_ne_empty Set.singleton_ne_empty --Porting note (#10618): removed `simp` attribute because `simp` can prove it theorem empty_ssubset_singleton : (∅ : Set α) ⊂ {a} := (singleton_nonempty _).empty_ssubset #align set.empty_ssubset_singleton Set.empty_ssubset_singleton @[simp] theorem singleton_subset_iff {a : α} {s : Set α} : {a} ⊆ s ↔ a ∈ s := forall_eq #align set.singleton_subset_iff Set.singleton_subset_iff theorem singleton_subset_singleton : ({a} : Set α) ⊆ {b} ↔ a = b := by simp #align set.singleton_subset_singleton Set.singleton_subset_singleton theorem set_compr_eq_eq_singleton {a : α} : { b | b = a } = {a} := rfl #align set.set_compr_eq_eq_singleton Set.set_compr_eq_eq_singleton @[simp] theorem singleton_union : {a} ∪ s = insert a s := rfl #align set.singleton_union Set.singleton_union @[simp] theorem union_singleton : s ∪ {a} = insert a s := union_comm _ _ #align set.union_singleton Set.union_singleton @[simp] theorem singleton_inter_nonempty : ({a} ∩ s).Nonempty ↔ a ∈ s := by simp only [Set.Nonempty, mem_inter_iff, mem_singleton_iff, exists_eq_left] #align set.singleton_inter_nonempty Set.singleton_inter_nonempty @[simp] theorem inter_singleton_nonempty : (s ∩ {a}).Nonempty ↔ a ∈ s := by rw [inter_comm, singleton_inter_nonempty] #align set.inter_singleton_nonempty Set.inter_singleton_nonempty @[simp] theorem singleton_inter_eq_empty : {a} ∩ s = ∅ ↔ a ∉ s := not_nonempty_iff_eq_empty.symm.trans singleton_inter_nonempty.not #align set.singleton_inter_eq_empty Set.singleton_inter_eq_empty @[simp] theorem inter_singleton_eq_empty : s ∩ {a} = ∅ ↔ a ∉ s := by rw [inter_comm, singleton_inter_eq_empty] #align set.inter_singleton_eq_empty Set.inter_singleton_eq_empty theorem nmem_singleton_empty {s : Set α} : s ∉ ({∅} : Set (Set α)) ↔ s.Nonempty := nonempty_iff_ne_empty.symm #align set.nmem_singleton_empty Set.nmem_singleton_empty instance uniqueSingleton (a : α) : Unique (↥({a} : Set α)) := ⟨⟨⟨a, mem_singleton a⟩⟩, fun ⟨_, h⟩ => Subtype.eq h⟩ #align set.unique_singleton Set.uniqueSingleton theorem eq_singleton_iff_unique_mem : s = {a} ↔ a ∈ s ∧ ∀ x ∈ s, x = a := Subset.antisymm_iff.trans <| and_comm.trans <| and_congr_left' singleton_subset_iff #align set.eq_singleton_iff_unique_mem Set.eq_singleton_iff_unique_mem theorem eq_singleton_iff_nonempty_unique_mem : s = {a} ↔ s.Nonempty ∧ ∀ x ∈ s, x = a := eq_singleton_iff_unique_mem.trans <| and_congr_left fun H => ⟨fun h' => ⟨_, h'⟩, fun ⟨x, h⟩ => H x h ▸ h⟩ #align set.eq_singleton_iff_nonempty_unique_mem Set.eq_singleton_iff_nonempty_unique_mem set_option backward.synthInstance.canonInstances false in -- See https://github.com/leanprover-community/mathlib4/issues/12532 -- while `simp` is capable of proving this, it is not capable of turning the LHS into the RHS. @[simp] theorem default_coe_singleton (x : α) : (default : ({x} : Set α)) = ⟨x, rfl⟩ := rfl #align set.default_coe_singleton Set.default_coe_singleton /-! ### Lemmas about sets defined as `{x ∈ s | p x}`. -/ section Sep variable {p q : α → Prop} {x : α} theorem mem_sep (xs : x ∈ s) (px : p x) : x ∈ { x ∈ s | p x } := ⟨xs, px⟩ #align set.mem_sep Set.mem_sep @[simp] theorem sep_mem_eq : { x ∈ s | x ∈ t } = s ∩ t := rfl #align set.sep_mem_eq Set.sep_mem_eq @[simp] theorem mem_sep_iff : x ∈ { x ∈ s | p x } ↔ x ∈ s ∧ p x := Iff.rfl #align set.mem_sep_iff Set.mem_sep_iff theorem sep_ext_iff : { x ∈ s | p x } = { x ∈ s | q x } ↔ ∀ x ∈ s, p x ↔ q x := by simp_rw [ext_iff, mem_sep_iff, and_congr_right_iff] #align set.sep_ext_iff Set.sep_ext_iff theorem sep_eq_of_subset (h : s ⊆ t) : { x ∈ t | x ∈ s } = s := inter_eq_self_of_subset_right h #align set.sep_eq_of_subset Set.sep_eq_of_subset @[simp] theorem sep_subset (s : Set α) (p : α → Prop) : { x ∈ s | p x } ⊆ s := fun _ => And.left #align set.sep_subset Set.sep_subset @[simp] theorem sep_eq_self_iff_mem_true : { x ∈ s | p x } = s ↔ ∀ x ∈ s, p x := by simp_rw [ext_iff, mem_sep_iff, and_iff_left_iff_imp] #align set.sep_eq_self_iff_mem_true Set.sep_eq_self_iff_mem_true @[simp] theorem sep_eq_empty_iff_mem_false : { x ∈ s | p x } = ∅ ↔ ∀ x ∈ s, ¬p x := by simp_rw [ext_iff, mem_sep_iff, mem_empty_iff_false, iff_false_iff, not_and] #align set.sep_eq_empty_iff_mem_false Set.sep_eq_empty_iff_mem_false --Porting note (#10618): removed `simp` attribute because `simp` can prove it theorem sep_true : { x ∈ s | True } = s := inter_univ s #align set.sep_true Set.sep_true --Porting note (#10618): removed `simp` attribute because `simp` can prove it theorem sep_false : { x ∈ s | False } = ∅ := inter_empty s #align set.sep_false Set.sep_false --Porting note (#10618): removed `simp` attribute because `simp` can prove it theorem sep_empty (p : α → Prop) : { x ∈ (∅ : Set α) | p x } = ∅ := empty_inter {x | p x} #align set.sep_empty Set.sep_empty --Porting note (#10618): removed `simp` attribute because `simp` can prove it theorem sep_univ : { x ∈ (univ : Set α) | p x } = { x | p x } := univ_inter {x | p x} #align set.sep_univ Set.sep_univ @[simp] theorem sep_union : { x | (x ∈ s ∨ x ∈ t) ∧ p x } = { x ∈ s | p x } ∪ { x ∈ t | p x } := union_inter_distrib_right { x | x ∈ s } { x | x ∈ t } p #align set.sep_union Set.sep_union @[simp] theorem sep_inter : { x | (x ∈ s ∧ x ∈ t) ∧ p x } = { x ∈ s | p x } ∩ { x ∈ t | p x } := inter_inter_distrib_right s t {x | p x} #align set.sep_inter Set.sep_inter @[simp] theorem sep_and : { x ∈ s | p x ∧ q x } = { x ∈ s | p x } ∩ { x ∈ s | q x } := inter_inter_distrib_left s {x | p x} {x | q x} #align set.sep_and Set.sep_and @[simp] theorem sep_or : { x ∈ s | p x ∨ q x } = { x ∈ s | p x } ∪ { x ∈ s | q x } := inter_union_distrib_left s p q #align set.sep_or Set.sep_or @[simp] theorem sep_setOf : { x ∈ { y | p y } | q x } = { x | p x ∧ q x } := rfl #align set.sep_set_of Set.sep_setOf end Sep @[simp] theorem subset_singleton_iff {α : Type*} {s : Set α} {x : α} : s ⊆ {x} ↔ ∀ y ∈ s, y = x := Iff.rfl #align set.subset_singleton_iff Set.subset_singleton_iff theorem subset_singleton_iff_eq {s : Set α} {x : α} : s ⊆ {x} ↔ s = ∅ ∨ s = {x} := by obtain rfl | hs := s.eq_empty_or_nonempty · exact ⟨fun _ => Or.inl rfl, fun _ => empty_subset _⟩ · simp [eq_singleton_iff_nonempty_unique_mem, hs, hs.ne_empty] #align set.subset_singleton_iff_eq Set.subset_singleton_iff_eq theorem Nonempty.subset_singleton_iff (h : s.Nonempty) : s ⊆ {a} ↔ s = {a} := subset_singleton_iff_eq.trans <| or_iff_right h.ne_empty #align set.nonempty.subset_singleton_iff Set.Nonempty.subset_singleton_iff theorem ssubset_singleton_iff {s : Set α} {x : α} : s ⊂ {x} ↔ s = ∅ := by rw [ssubset_iff_subset_ne, subset_singleton_iff_eq, or_and_right, and_not_self_iff, or_false_iff, and_iff_left_iff_imp] exact fun h => h ▸ (singleton_ne_empty _).symm #align set.ssubset_singleton_iff Set.ssubset_singleton_iff theorem eq_empty_of_ssubset_singleton {s : Set α} {x : α} (hs : s ⊂ {x}) : s = ∅ := ssubset_singleton_iff.1 hs #align set.eq_empty_of_ssubset_singleton Set.eq_empty_of_ssubset_singleton theorem eq_of_nonempty_of_subsingleton {α} [Subsingleton α] (s t : Set α) [Nonempty s] [Nonempty t] : s = t := nonempty_of_nonempty_subtype.eq_univ.trans nonempty_of_nonempty_subtype.eq_univ.symm theorem eq_of_nonempty_of_subsingleton' {α} [Subsingleton α] {s : Set α} (t : Set α) (hs : s.Nonempty) [Nonempty t] : s = t := have := hs.to_subtype; eq_of_nonempty_of_subsingleton s t set_option backward.synthInstance.canonInstances false in -- See https://github.com/leanprover-community/mathlib4/issues/12532 theorem Nonempty.eq_zero [Subsingleton α] [Zero α] {s : Set α} (h : s.Nonempty) : s = {0} := eq_of_nonempty_of_subsingleton' {0} h set_option backward.synthInstance.canonInstances false in -- See https://github.com/leanprover-community/mathlib4/issues/12532 theorem Nonempty.eq_one [Subsingleton α] [One α] {s : Set α} (h : s.Nonempty) : s = {1} := eq_of_nonempty_of_subsingleton' {1} h /-! ### Disjointness -/ protected theorem disjoint_iff : Disjoint s t ↔ s ∩ t ⊆ ∅ := disjoint_iff_inf_le #align set.disjoint_iff Set.disjoint_iff theorem disjoint_iff_inter_eq_empty : Disjoint s t ↔ s ∩ t = ∅ := disjoint_iff #align set.disjoint_iff_inter_eq_empty Set.disjoint_iff_inter_eq_empty theorem _root_.Disjoint.inter_eq : Disjoint s t → s ∩ t = ∅ := Disjoint.eq_bot #align disjoint.inter_eq Disjoint.inter_eq theorem disjoint_left : Disjoint s t ↔ ∀ ⦃a⦄, a ∈ s → a ∉ t := disjoint_iff_inf_le.trans <| forall_congr' fun _ => not_and #align set.disjoint_left Set.disjoint_left theorem disjoint_right : Disjoint s t ↔ ∀ ⦃a⦄, a ∈ t → a ∉ s := by rw [disjoint_comm, disjoint_left] #align set.disjoint_right Set.disjoint_right lemma not_disjoint_iff : ¬Disjoint s t ↔ ∃ x, x ∈ s ∧ x ∈ t := Set.disjoint_iff.not.trans <| not_forall.trans <| exists_congr fun _ ↦ not_not #align set.not_disjoint_iff Set.not_disjoint_iff lemma not_disjoint_iff_nonempty_inter : ¬ Disjoint s t ↔ (s ∩ t).Nonempty := not_disjoint_iff #align set.not_disjoint_iff_nonempty_inter Set.not_disjoint_iff_nonempty_inter alias ⟨_, Nonempty.not_disjoint⟩ := not_disjoint_iff_nonempty_inter #align set.nonempty.not_disjoint Set.Nonempty.not_disjoint lemma disjoint_or_nonempty_inter (s t : Set α) : Disjoint s t ∨ (s ∩ t).Nonempty := (em _).imp_right not_disjoint_iff_nonempty_inter.1 #align set.disjoint_or_nonempty_inter Set.disjoint_or_nonempty_inter lemma disjoint_iff_forall_ne : Disjoint s t ↔ ∀ ⦃a⦄, a ∈ s → ∀ ⦃b⦄, b ∈ t → a ≠ b := by simp only [Ne, disjoint_left, @imp_not_comm _ (_ = _), forall_eq'] #align set.disjoint_iff_forall_ne Set.disjoint_iff_forall_ne alias ⟨_root_.Disjoint.ne_of_mem, _⟩ := disjoint_iff_forall_ne #align disjoint.ne_of_mem Disjoint.ne_of_mem lemma disjoint_of_subset_left (h : s ⊆ u) (d : Disjoint u t) : Disjoint s t := d.mono_left h #align set.disjoint_of_subset_left Set.disjoint_of_subset_left lemma disjoint_of_subset_right (h : t ⊆ u) (d : Disjoint s u) : Disjoint s t := d.mono_right h #align set.disjoint_of_subset_right Set.disjoint_of_subset_right lemma disjoint_of_subset (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) (h : Disjoint s₂ t₂) : Disjoint s₁ t₁ := h.mono hs ht #align set.disjoint_of_subset Set.disjoint_of_subset @[simp] lemma disjoint_union_left : Disjoint (s ∪ t) u ↔ Disjoint s u ∧ Disjoint t u := disjoint_sup_left #align set.disjoint_union_left Set.disjoint_union_left @[simp] lemma disjoint_union_right : Disjoint s (t ∪ u) ↔ Disjoint s t ∧ Disjoint s u := disjoint_sup_right #align set.disjoint_union_right Set.disjoint_union_right @[simp] lemma disjoint_empty (s : Set α) : Disjoint s ∅ := disjoint_bot_right #align set.disjoint_empty Set.disjoint_empty @[simp] lemma empty_disjoint (s : Set α) : Disjoint ∅ s := disjoint_bot_left #align set.empty_disjoint Set.empty_disjoint @[simp] lemma univ_disjoint : Disjoint univ s ↔ s = ∅ := top_disjoint #align set.univ_disjoint Set.univ_disjoint @[simp] lemma disjoint_univ : Disjoint s univ ↔ s = ∅ := disjoint_top #align set.disjoint_univ Set.disjoint_univ lemma disjoint_sdiff_left : Disjoint (t \ s) s := disjoint_sdiff_self_left #align set.disjoint_sdiff_left Set.disjoint_sdiff_left lemma disjoint_sdiff_right : Disjoint s (t \ s) := disjoint_sdiff_self_right #align set.disjoint_sdiff_right Set.disjoint_sdiff_right -- TODO: prove this in terms of a lattice lemma theorem disjoint_sdiff_inter : Disjoint (s \ t) (s ∩ t) := disjoint_of_subset_right inter_subset_right disjoint_sdiff_left #align set.disjoint_sdiff_inter Set.disjoint_sdiff_inter theorem diff_union_diff_cancel (hts : t ⊆ s) (hut : u ⊆ t) : s \ t ∪ t \ u = s \ u := sdiff_sup_sdiff_cancel hts hut #align set.diff_union_diff_cancel Set.diff_union_diff_cancel theorem diff_diff_eq_sdiff_union (h : u ⊆ s) : s \ (t \ u) = s \ t ∪ u := sdiff_sdiff_eq_sdiff_sup h #align set.diff_diff_eq_sdiff_union Set.diff_diff_eq_sdiff_union @[simp default+1] lemma disjoint_singleton_left : Disjoint {a} s ↔ a ∉ s := by simp [Set.disjoint_iff, subset_def] #align set.disjoint_singleton_left Set.disjoint_singleton_left @[simp] lemma disjoint_singleton_right : Disjoint s {a} ↔ a ∉ s := disjoint_comm.trans disjoint_singleton_left #align set.disjoint_singleton_right Set.disjoint_singleton_right lemma disjoint_singleton : Disjoint ({a} : Set α) {b} ↔ a ≠ b := by simp #align set.disjoint_singleton Set.disjoint_singleton lemma subset_diff : s ⊆ t \ u ↔ s ⊆ t ∧ Disjoint s u := le_iff_subset.symm.trans le_sdiff #align set.subset_diff Set.subset_diff lemma ssubset_iff_sdiff_singleton : s ⊂ t ↔ ∃ a ∈ t, s ⊆ t \ {a} := by simp [ssubset_iff_insert, subset_diff, insert_subset_iff]; aesop theorem inter_diff_distrib_left (s t u : Set α) : s ∩ (t \ u) = (s ∩ t) \ (s ∩ u) := inf_sdiff_distrib_left _ _ _ #align set.inter_diff_distrib_left Set.inter_diff_distrib_left theorem inter_diff_distrib_right (s t u : Set α) : s \ t ∩ u = (s ∩ u) \ (t ∩ u) := inf_sdiff_distrib_right _ _ _ #align set.inter_diff_distrib_right Set.inter_diff_distrib_right /-! ### Lemmas about complement -/ theorem compl_def (s : Set α) : sᶜ = { x | x ∉ s } := rfl #align set.compl_def Set.compl_def theorem mem_compl {s : Set α} {x : α} (h : x ∉ s) : x ∈ sᶜ := h #align set.mem_compl Set.mem_compl theorem compl_setOf {α} (p : α → Prop) : { a | p a }ᶜ = { a | ¬p a } := rfl #align set.compl_set_of Set.compl_setOf theorem not_mem_of_mem_compl {s : Set α} {x : α} (h : x ∈ sᶜ) : x ∉ s := h #align set.not_mem_of_mem_compl Set.not_mem_of_mem_compl theorem not_mem_compl_iff {x : α} : x ∉ sᶜ ↔ x ∈ s := not_not #align set.not_mem_compl_iff Set.not_mem_compl_iff @[simp] theorem inter_compl_self (s : Set α) : s ∩ sᶜ = ∅ := inf_compl_eq_bot #align set.inter_compl_self Set.inter_compl_self @[simp] theorem compl_inter_self (s : Set α) : sᶜ ∩ s = ∅ := compl_inf_eq_bot #align set.compl_inter_self Set.compl_inter_self @[simp] theorem compl_empty : (∅ : Set α)ᶜ = univ := compl_bot #align set.compl_empty Set.compl_empty @[simp] theorem compl_union (s t : Set α) : (s ∪ t)ᶜ = sᶜ ∩ tᶜ := compl_sup #align set.compl_union Set.compl_union theorem compl_inter (s t : Set α) : (s ∩ t)ᶜ = sᶜ ∪ tᶜ := compl_inf #align set.compl_inter Set.compl_inter @[simp] theorem compl_univ : (univ : Set α)ᶜ = ∅ := compl_top #align set.compl_univ Set.compl_univ @[simp] theorem compl_empty_iff {s : Set α} : sᶜ = ∅ ↔ s = univ := compl_eq_bot #align set.compl_empty_iff Set.compl_empty_iff @[simp] theorem compl_univ_iff {s : Set α} : sᶜ = univ ↔ s = ∅ := compl_eq_top #align set.compl_univ_iff Set.compl_univ_iff theorem compl_ne_univ : sᶜ ≠ univ ↔ s.Nonempty := compl_univ_iff.not.trans nonempty_iff_ne_empty.symm #align set.compl_ne_univ Set.compl_ne_univ theorem nonempty_compl : sᶜ.Nonempty ↔ s ≠ univ := (ne_univ_iff_exists_not_mem s).symm #align set.nonempty_compl Set.nonempty_compl @[simp] lemma nonempty_compl_of_nontrivial [Nontrivial α] (x : α) : Set.Nonempty {x}ᶜ := by obtain ⟨y, hy⟩ := exists_ne x exact ⟨y, by simp [hy]⟩ theorem mem_compl_singleton_iff {a x : α} : x ∈ ({a} : Set α)ᶜ ↔ x ≠ a := Iff.rfl #align set.mem_compl_singleton_iff Set.mem_compl_singleton_iff theorem compl_singleton_eq (a : α) : ({a} : Set α)ᶜ = { x | x ≠ a } := rfl #align set.compl_singleton_eq Set.compl_singleton_eq @[simp] theorem compl_ne_eq_singleton (a : α) : ({ x | x ≠ a } : Set α)ᶜ = {a} := compl_compl _ #align set.compl_ne_eq_singleton Set.compl_ne_eq_singleton theorem union_eq_compl_compl_inter_compl (s t : Set α) : s ∪ t = (sᶜ ∩ tᶜ)ᶜ := ext fun _ => or_iff_not_and_not #align set.union_eq_compl_compl_inter_compl Set.union_eq_compl_compl_inter_compl theorem inter_eq_compl_compl_union_compl (s t : Set α) : s ∩ t = (sᶜ ∪ tᶜ)ᶜ := ext fun _ => and_iff_not_or_not #align set.inter_eq_compl_compl_union_compl Set.inter_eq_compl_compl_union_compl @[simp] theorem union_compl_self (s : Set α) : s ∪ sᶜ = univ := eq_univ_iff_forall.2 fun _ => em _ #align set.union_compl_self Set.union_compl_self @[simp] theorem compl_union_self (s : Set α) : sᶜ ∪ s = univ := by rw [union_comm, union_compl_self] #align set.compl_union_self Set.compl_union_self theorem compl_subset_comm : sᶜ ⊆ t ↔ tᶜ ⊆ s := @compl_le_iff_compl_le _ s _ _ #align set.compl_subset_comm Set.compl_subset_comm theorem subset_compl_comm : s ⊆ tᶜ ↔ t ⊆ sᶜ := @le_compl_iff_le_compl _ _ _ t #align set.subset_compl_comm Set.subset_compl_comm @[simp] theorem compl_subset_compl : sᶜ ⊆ tᶜ ↔ t ⊆ s := @compl_le_compl_iff_le (Set α) _ _ _ #align set.compl_subset_compl Set.compl_subset_compl @[gcongr] theorem compl_subset_compl_of_subset (h : t ⊆ s) : sᶜ ⊆ tᶜ := compl_subset_compl.2 h theorem subset_compl_iff_disjoint_left : s ⊆ tᶜ ↔ Disjoint t s := @le_compl_iff_disjoint_left (Set α) _ _ _ #align set.subset_compl_iff_disjoint_left Set.subset_compl_iff_disjoint_left theorem subset_compl_iff_disjoint_right : s ⊆ tᶜ ↔ Disjoint s t := @le_compl_iff_disjoint_right (Set α) _ _ _ #align set.subset_compl_iff_disjoint_right Set.subset_compl_iff_disjoint_right theorem disjoint_compl_left_iff_subset : Disjoint sᶜ t ↔ t ⊆ s := disjoint_compl_left_iff #align set.disjoint_compl_left_iff_subset Set.disjoint_compl_left_iff_subset theorem disjoint_compl_right_iff_subset : Disjoint s tᶜ ↔ s ⊆ t := disjoint_compl_right_iff #align set.disjoint_compl_right_iff_subset Set.disjoint_compl_right_iff_subset alias ⟨_, _root_.Disjoint.subset_compl_right⟩ := subset_compl_iff_disjoint_right #align disjoint.subset_compl_right Disjoint.subset_compl_right alias ⟨_, _root_.Disjoint.subset_compl_left⟩ := subset_compl_iff_disjoint_left #align disjoint.subset_compl_left Disjoint.subset_compl_left alias ⟨_, _root_.HasSubset.Subset.disjoint_compl_left⟩ := disjoint_compl_left_iff_subset #align has_subset.subset.disjoint_compl_left HasSubset.Subset.disjoint_compl_left alias ⟨_, _root_.HasSubset.Subset.disjoint_compl_right⟩ := disjoint_compl_right_iff_subset #align has_subset.subset.disjoint_compl_right HasSubset.Subset.disjoint_compl_right theorem subset_union_compl_iff_inter_subset {s t u : Set α} : s ⊆ t ∪ uᶜ ↔ s ∩ u ⊆ t := (@isCompl_compl _ u _).le_sup_right_iff_inf_left_le #align set.subset_union_compl_iff_inter_subset Set.subset_union_compl_iff_inter_subset theorem compl_subset_iff_union {s t : Set α} : sᶜ ⊆ t ↔ s ∪ t = univ := Iff.symm <| eq_univ_iff_forall.trans <| forall_congr' fun _ => or_iff_not_imp_left #align set.compl_subset_iff_union Set.compl_subset_iff_union @[simp] theorem subset_compl_singleton_iff {a : α} {s : Set α} : s ⊆ {a}ᶜ ↔ a ∉ s := subset_compl_comm.trans singleton_subset_iff #align set.subset_compl_singleton_iff Set.subset_compl_singleton_iff theorem inter_subset (a b c : Set α) : a ∩ b ⊆ c ↔ a ⊆ bᶜ ∪ c := forall_congr' fun _ => and_imp.trans <| imp_congr_right fun _ => imp_iff_not_or #align set.inter_subset Set.inter_subset theorem inter_compl_nonempty_iff {s t : Set α} : (s ∩ tᶜ).Nonempty ↔ ¬s ⊆ t := (not_subset.trans <| exists_congr fun x => by simp [mem_compl]).symm #align set.inter_compl_nonempty_iff Set.inter_compl_nonempty_iff /-! ### Lemmas about set difference -/ theorem not_mem_diff_of_mem {s t : Set α} {x : α} (hx : x ∈ t) : x ∉ s \ t := fun h => h.2 hx #align set.not_mem_diff_of_mem Set.not_mem_diff_of_mem theorem mem_of_mem_diff {s t : Set α} {x : α} (h : x ∈ s \ t) : x ∈ s := h.left #align set.mem_of_mem_diff Set.mem_of_mem_diff theorem not_mem_of_mem_diff {s t : Set α} {x : α} (h : x ∈ s \ t) : x ∉ t := h.right #align set.not_mem_of_mem_diff Set.not_mem_of_mem_diff theorem diff_eq_compl_inter {s t : Set α} : s \ t = tᶜ ∩ s := by rw [diff_eq, inter_comm] #align set.diff_eq_compl_inter Set.diff_eq_compl_inter theorem nonempty_diff {s t : Set α} : (s \ t).Nonempty ↔ ¬s ⊆ t := inter_compl_nonempty_iff #align set.nonempty_diff Set.nonempty_diff theorem diff_subset {s t : Set α} : s \ t ⊆ s := show s \ t ≤ s from sdiff_le #align set.diff_subset Set.diff_subset theorem diff_subset_compl (s t : Set α) : s \ t ⊆ tᶜ := diff_eq_compl_inter ▸ inter_subset_left theorem union_diff_cancel' {s t u : Set α} (h₁ : s ⊆ t) (h₂ : t ⊆ u) : t ∪ u \ s = u := sup_sdiff_cancel' h₁ h₂ #align set.union_diff_cancel' Set.union_diff_cancel' theorem union_diff_cancel {s t : Set α} (h : s ⊆ t) : s ∪ t \ s = t := sup_sdiff_cancel_right h #align set.union_diff_cancel Set.union_diff_cancel theorem union_diff_cancel_left {s t : Set α} (h : s ∩ t ⊆ ∅) : (s ∪ t) \ s = t := Disjoint.sup_sdiff_cancel_left <| disjoint_iff_inf_le.2 h #align set.union_diff_cancel_left Set.union_diff_cancel_left theorem union_diff_cancel_right {s t : Set α} (h : s ∩ t ⊆ ∅) : (s ∪ t) \ t = s := Disjoint.sup_sdiff_cancel_right <| disjoint_iff_inf_le.2 h #align set.union_diff_cancel_right Set.union_diff_cancel_right @[simp] theorem union_diff_left {s t : Set α} : (s ∪ t) \ s = t \ s := sup_sdiff_left_self #align set.union_diff_left Set.union_diff_left @[simp] theorem union_diff_right {s t : Set α} : (s ∪ t) \ t = s \ t := sup_sdiff_right_self #align set.union_diff_right Set.union_diff_right theorem union_diff_distrib {s t u : Set α} : (s ∪ t) \ u = s \ u ∪ t \ u := sup_sdiff #align set.union_diff_distrib Set.union_diff_distrib theorem inter_diff_assoc (a b c : Set α) : (a ∩ b) \ c = a ∩ (b \ c) := inf_sdiff_assoc #align set.inter_diff_assoc Set.inter_diff_assoc @[simp] theorem inter_diff_self (a b : Set α) : a ∩ (b \ a) = ∅ := inf_sdiff_self_right #align set.inter_diff_self Set.inter_diff_self @[simp] theorem inter_union_diff (s t : Set α) : s ∩ t ∪ s \ t = s := sup_inf_sdiff s t #align set.inter_union_diff Set.inter_union_diff @[simp] theorem diff_union_inter (s t : Set α) : s \ t ∪ s ∩ t = s := by rw [union_comm] exact sup_inf_sdiff _ _ #align set.diff_union_inter Set.diff_union_inter @[simp] theorem inter_union_compl (s t : Set α) : s ∩ t ∪ s ∩ tᶜ = s := inter_union_diff _ _ #align set.inter_union_compl Set.inter_union_compl @[gcongr] theorem diff_subset_diff {s₁ s₂ t₁ t₂ : Set α} : s₁ ⊆ s₂ → t₂ ⊆ t₁ → s₁ \ t₁ ⊆ s₂ \ t₂ := show s₁ ≤ s₂ → t₂ ≤ t₁ → s₁ \ t₁ ≤ s₂ \ t₂ from sdiff_le_sdiff #align set.diff_subset_diff Set.diff_subset_diff @[gcongr] theorem diff_subset_diff_left {s₁ s₂ t : Set α} (h : s₁ ⊆ s₂) : s₁ \ t ⊆ s₂ \ t := sdiff_le_sdiff_right ‹s₁ ≤ s₂› #align set.diff_subset_diff_left Set.diff_subset_diff_left @[gcongr] theorem diff_subset_diff_right {s t u : Set α} (h : t ⊆ u) : s \ u ⊆ s \ t := sdiff_le_sdiff_left ‹t ≤ u› #align set.diff_subset_diff_right Set.diff_subset_diff_right theorem compl_eq_univ_diff (s : Set α) : sᶜ = univ \ s := top_sdiff.symm #align set.compl_eq_univ_diff Set.compl_eq_univ_diff @[simp] theorem empty_diff (s : Set α) : (∅ \ s : Set α) = ∅ := bot_sdiff #align set.empty_diff Set.empty_diff theorem diff_eq_empty {s t : Set α} : s \ t = ∅ ↔ s ⊆ t := sdiff_eq_bot_iff #align set.diff_eq_empty Set.diff_eq_empty @[simp] theorem diff_empty {s : Set α} : s \ ∅ = s := sdiff_bot #align set.diff_empty Set.diff_empty @[simp] theorem diff_univ (s : Set α) : s \ univ = ∅ := diff_eq_empty.2 (subset_univ s) #align set.diff_univ Set.diff_univ theorem diff_diff {u : Set α} : (s \ t) \ u = s \ (t ∪ u) := sdiff_sdiff_left #align set.diff_diff Set.diff_diff -- the following statement contains parentheses to help the reader theorem diff_diff_comm {s t u : Set α} : (s \ t) \ u = (s \ u) \ t := sdiff_sdiff_comm #align set.diff_diff_comm Set.diff_diff_comm theorem diff_subset_iff {s t u : Set α} : s \ t ⊆ u ↔ s ⊆ t ∪ u := show s \ t ≤ u ↔ s ≤ t ∪ u from sdiff_le_iff #align set.diff_subset_iff Set.diff_subset_iff theorem subset_diff_union (s t : Set α) : s ⊆ s \ t ∪ t := show s ≤ s \ t ∪ t from le_sdiff_sup #align set.subset_diff_union Set.subset_diff_union theorem diff_union_of_subset {s t : Set α} (h : t ⊆ s) : s \ t ∪ t = s := Subset.antisymm (union_subset diff_subset h) (subset_diff_union _ _) #align set.diff_union_of_subset Set.diff_union_of_subset @[simp] theorem diff_singleton_subset_iff {x : α} {s t : Set α} : s \ {x} ⊆ t ↔ s ⊆ insert x t := by rw [← union_singleton, union_comm] apply diff_subset_iff #align set.diff_singleton_subset_iff Set.diff_singleton_subset_iff theorem subset_diff_singleton {x : α} {s t : Set α} (h : s ⊆ t) (hx : x ∉ s) : s ⊆ t \ {x} := subset_inter h <| subset_compl_comm.1 <| singleton_subset_iff.2 hx #align set.subset_diff_singleton Set.subset_diff_singleton theorem subset_insert_diff_singleton (x : α) (s : Set α) : s ⊆ insert x (s \ {x}) := by rw [← diff_singleton_subset_iff] #align set.subset_insert_diff_singleton Set.subset_insert_diff_singleton theorem diff_subset_comm {s t u : Set α} : s \ t ⊆ u ↔ s \ u ⊆ t := show s \ t ≤ u ↔ s \ u ≤ t from sdiff_le_comm #align set.diff_subset_comm Set.diff_subset_comm theorem diff_inter {s t u : Set α} : s \ (t ∩ u) = s \ t ∪ s \ u := sdiff_inf #align set.diff_inter Set.diff_inter theorem diff_inter_diff {s t u : Set α} : s \ t ∩ (s \ u) = s \ (t ∪ u) := sdiff_sup.symm #align set.diff_inter_diff Set.diff_inter_diff theorem diff_compl : s \ tᶜ = s ∩ t := sdiff_compl #align set.diff_compl Set.diff_compl theorem diff_diff_right {s t u : Set α} : s \ (t \ u) = s \ t ∪ s ∩ u := sdiff_sdiff_right' #align set.diff_diff_right Set.diff_diff_right @[simp] theorem insert_diff_of_mem (s) (h : a ∈ t) : insert a s \ t = s \ t := by ext constructor <;> simp (config := { contextual := true }) [or_imp, h] #align set.insert_diff_of_mem Set.insert_diff_of_mem theorem insert_diff_of_not_mem (s) (h : a ∉ t) : insert a s \ t = insert a (s \ t) := by classical ext x by_cases h' : x ∈ t · have : x ≠ a := by intro H rw [H] at h' exact h h' simp [h, h', this] · simp [h, h'] #align set.insert_diff_of_not_mem Set.insert_diff_of_not_mem theorem insert_diff_self_of_not_mem {a : α} {s : Set α} (h : a ∉ s) : insert a s \ {a} = s := by ext x simp [and_iff_left_of_imp fun hx : x ∈ s => show x ≠ a from fun hxa => h <| hxa ▸ hx] #align set.insert_diff_self_of_not_mem Set.insert_diff_self_of_not_mem @[simp] theorem insert_diff_eq_singleton {a : α} {s : Set α} (h : a ∉ s) : insert a s \ s = {a} := by ext rw [Set.mem_diff, Set.mem_insert_iff, Set.mem_singleton_iff, or_and_right, and_not_self_iff, or_false_iff, and_iff_left_iff_imp] rintro rfl exact h #align set.insert_diff_eq_singleton Set.insert_diff_eq_singleton theorem inter_insert_of_mem (h : a ∈ s) : s ∩ insert a t = insert a (s ∩ t) := by rw [insert_inter_distrib, insert_eq_of_mem h] #align set.inter_insert_of_mem Set.inter_insert_of_mem theorem insert_inter_of_mem (h : a ∈ t) : insert a s ∩ t = insert a (s ∩ t) := by rw [insert_inter_distrib, insert_eq_of_mem h] #align set.insert_inter_of_mem Set.insert_inter_of_mem theorem inter_insert_of_not_mem (h : a ∉ s) : s ∩ insert a t = s ∩ t := ext fun _ => and_congr_right fun hx => or_iff_right <| ne_of_mem_of_not_mem hx h #align set.inter_insert_of_not_mem Set.inter_insert_of_not_mem theorem insert_inter_of_not_mem (h : a ∉ t) : insert a s ∩ t = s ∩ t := ext fun _ => and_congr_left fun hx => or_iff_right <| ne_of_mem_of_not_mem hx h #align set.insert_inter_of_not_mem Set.insert_inter_of_not_mem @[simp] theorem union_diff_self {s t : Set α} : s ∪ t \ s = s ∪ t := sup_sdiff_self _ _ #align set.union_diff_self Set.union_diff_self @[simp] theorem diff_union_self {s t : Set α} : s \ t ∪ t = s ∪ t := sdiff_sup_self _ _ #align set.diff_union_self Set.diff_union_self @[simp] theorem diff_inter_self {a b : Set α} : b \ a ∩ a = ∅ := inf_sdiff_self_left #align set.diff_inter_self Set.diff_inter_self @[simp] theorem diff_inter_self_eq_diff {s t : Set α} : s \ (t ∩ s) = s \ t := sdiff_inf_self_right _ _ #align set.diff_inter_self_eq_diff Set.diff_inter_self_eq_diff @[simp] theorem diff_self_inter {s t : Set α} : s \ (s ∩ t) = s \ t := sdiff_inf_self_left _ _ #align set.diff_self_inter Set.diff_self_inter @[simp] theorem diff_singleton_eq_self {a : α} {s : Set α} (h : a ∉ s) : s \ {a} = s := sdiff_eq_self_iff_disjoint.2 <| by simp [h] #align set.diff_singleton_eq_self Set.diff_singleton_eq_self @[simp] theorem diff_singleton_sSubset {s : Set α} {a : α} : s \ {a} ⊂ s ↔ a ∈ s := sdiff_le.lt_iff_ne.trans <| sdiff_eq_left.not.trans <| by simp #align set.diff_singleton_ssubset Set.diff_singleton_sSubset @[simp] theorem insert_diff_singleton {a : α} {s : Set α} : insert a (s \ {a}) = insert a s := by simp [insert_eq, union_diff_self, -union_singleton, -singleton_union] #align set.insert_diff_singleton Set.insert_diff_singleton theorem insert_diff_singleton_comm (hab : a ≠ b) (s : Set α) : insert a (s \ {b}) = insert a s \ {b} := by simp_rw [← union_singleton, union_diff_distrib, diff_singleton_eq_self (mem_singleton_iff.not.2 hab.symm)] #align set.insert_diff_singleton_comm Set.insert_diff_singleton_comm --Porting note (#10618): removed `simp` attribute because `simp` can prove it theorem diff_self {s : Set α} : s \ s = ∅ := sdiff_self #align set.diff_self Set.diff_self theorem diff_diff_right_self (s t : Set α) : s \ (s \ t) = s ∩ t := sdiff_sdiff_right_self #align set.diff_diff_right_self Set.diff_diff_right_self theorem diff_diff_cancel_left {s t : Set α} (h : s ⊆ t) : t \ (t \ s) = s := sdiff_sdiff_eq_self h #align set.diff_diff_cancel_left Set.diff_diff_cancel_left theorem mem_diff_singleton {x y : α} {s : Set α} : x ∈ s \ {y} ↔ x ∈ s ∧ x ≠ y := Iff.rfl #align set.mem_diff_singleton Set.mem_diff_singleton theorem mem_diff_singleton_empty {t : Set (Set α)} : s ∈ t \ {∅} ↔ s ∈ t ∧ s.Nonempty := mem_diff_singleton.trans <| and_congr_right' nonempty_iff_ne_empty.symm #align set.mem_diff_singleton_empty Set.mem_diff_singleton_empty theorem subset_insert_iff {s t : Set α} {x : α} : s ⊆ insert x t ↔ s ⊆ t ∨ (x ∈ s ∧ s \ {x} ⊆ t) := by rw [← diff_singleton_subset_iff] by_cases hx : x ∈ s · rw [and_iff_right hx, or_iff_right_of_imp diff_subset.trans] rw [diff_singleton_eq_self hx, or_iff_left_of_imp And.right] theorem union_eq_diff_union_diff_union_inter (s t : Set α) : s ∪ t = s \ t ∪ t \ s ∪ s ∩ t := sup_eq_sdiff_sup_sdiff_sup_inf #align set.union_eq_diff_union_diff_union_inter Set.union_eq_diff_union_diff_union_inter /-! ### Lemmas about pairs -/ --Porting note (#10618): removed `simp` attribute because `simp` can prove it theorem pair_eq_singleton (a : α) : ({a, a} : Set α) = {a} := union_self _ #align set.pair_eq_singleton Set.pair_eq_singleton theorem pair_comm (a b : α) : ({a, b} : Set α) = {b, a} := union_comm _ _ #align set.pair_comm Set.pair_comm theorem pair_eq_pair_iff {x y z w : α} : ({x, y} : Set α) = {z, w} ↔ x = z ∧ y = w ∨ x = w ∧ y = z := by simp [subset_antisymm_iff, insert_subset_iff]; aesop #align set.pair_eq_pair_iff Set.pair_eq_pair_iff theorem pair_diff_left (hne : a ≠ b) : ({a, b} : Set α) \ {a} = {b} := by rw [insert_diff_of_mem _ (mem_singleton a), diff_singleton_eq_self (by simpa)] theorem pair_diff_right (hne : a ≠ b) : ({a, b} : Set α) \ {b} = {a} := by rw [pair_comm, pair_diff_left hne.symm] theorem pair_subset_iff : {a, b} ⊆ s ↔ a ∈ s ∧ b ∈ s := by rw [insert_subset_iff, singleton_subset_iff] theorem pair_subset (ha : a ∈ s) (hb : b ∈ s) : {a, b} ⊆ s := pair_subset_iff.2 ⟨ha,hb⟩ theorem subset_pair_iff : s ⊆ {a, b} ↔ ∀ x ∈ s, x = a ∨ x = b := by simp [subset_def] theorem subset_pair_iff_eq {x y : α} : s ⊆ {x, y} ↔ s = ∅ ∨ s = {x} ∨ s = {y} ∨ s = {x, y} := by refine ⟨?_, by rintro (rfl | rfl | rfl | rfl) <;> simp [pair_subset_iff]⟩ rw [subset_insert_iff, subset_singleton_iff_eq, subset_singleton_iff_eq, ← subset_empty_iff (s := s \ {x}), diff_subset_iff, union_empty, subset_singleton_iff_eq] have h : x ∈ s → {y} = s \ {x} → s = {x,y} := fun h₁ h₂ ↦ by simp [h₁, h₂] tauto theorem Nonempty.subset_pair_iff_eq (hs : s.Nonempty) : s ⊆ {a, b} ↔ s = {a} ∨ s = {b} ∨ s = {a, b} := by rw [Set.subset_pair_iff_eq, or_iff_right]; exact hs.ne_empty /-! ### Symmetric difference -/ section open scoped symmDiff theorem mem_symmDiff : a ∈ s ∆ t ↔ a ∈ s ∧ a ∉ t ∨ a ∈ t ∧ a ∉ s := Iff.rfl #align set.mem_symm_diff Set.mem_symmDiff protected theorem symmDiff_def (s t : Set α) : s ∆ t = s \ t ∪ t \ s := rfl #align set.symm_diff_def Set.symmDiff_def theorem symmDiff_subset_union : s ∆ t ⊆ s ∪ t := @symmDiff_le_sup (Set α) _ _ _ #align set.symm_diff_subset_union Set.symmDiff_subset_union @[simp] theorem symmDiff_eq_empty : s ∆ t = ∅ ↔ s = t := symmDiff_eq_bot #align set.symm_diff_eq_empty Set.symmDiff_eq_empty @[simp] theorem symmDiff_nonempty : (s ∆ t).Nonempty ↔ s ≠ t := nonempty_iff_ne_empty.trans symmDiff_eq_empty.not #align set.symm_diff_nonempty Set.symmDiff_nonempty theorem inter_symmDiff_distrib_left (s t u : Set α) : s ∩ t ∆ u = (s ∩ t) ∆ (s ∩ u) := inf_symmDiff_distrib_left _ _ _ #align set.inter_symm_diff_distrib_left Set.inter_symmDiff_distrib_left theorem inter_symmDiff_distrib_right (s t u : Set α) : s ∆ t ∩ u = (s ∩ u) ∆ (t ∩ u) := inf_symmDiff_distrib_right _ _ _ #align set.inter_symm_diff_distrib_right Set.inter_symmDiff_distrib_right theorem subset_symmDiff_union_symmDiff_left (h : Disjoint s t) : u ⊆ s ∆ u ∪ t ∆ u := h.le_symmDiff_sup_symmDiff_left #align set.subset_symm_diff_union_symm_diff_left Set.subset_symmDiff_union_symmDiff_left theorem subset_symmDiff_union_symmDiff_right (h : Disjoint t u) : s ⊆ s ∆ t ∪ s ∆ u := h.le_symmDiff_sup_symmDiff_right #align set.subset_symm_diff_union_symm_diff_right Set.subset_symmDiff_union_symmDiff_right end /-! ### Powerset -/ #align set.powerset Set.powerset theorem mem_powerset {x s : Set α} (h : x ⊆ s) : x ∈ 𝒫 s := @h #align set.mem_powerset Set.mem_powerset theorem subset_of_mem_powerset {x s : Set α} (h : x ∈ 𝒫 s) : x ⊆ s := @h #align set.subset_of_mem_powerset Set.subset_of_mem_powerset @[simp] theorem mem_powerset_iff (x s : Set α) : x ∈ 𝒫 s ↔ x ⊆ s := Iff.rfl #align set.mem_powerset_iff Set.mem_powerset_iff theorem powerset_inter (s t : Set α) : 𝒫(s ∩ t) = 𝒫 s ∩ 𝒫 t := ext fun _ => subset_inter_iff #align set.powerset_inter Set.powerset_inter @[simp] theorem powerset_mono : 𝒫 s ⊆ 𝒫 t ↔ s ⊆ t := ⟨fun h => @h _ (fun _ h => h), fun h _ hu _ ha => h (hu ha)⟩ #align set.powerset_mono Set.powerset_mono theorem monotone_powerset : Monotone (powerset : Set α → Set (Set α)) := fun _ _ => powerset_mono.2 #align set.monotone_powerset Set.monotone_powerset @[simp] theorem powerset_nonempty : (𝒫 s).Nonempty := ⟨∅, fun _ h => empty_subset s h⟩ #align set.powerset_nonempty Set.powerset_nonempty @[simp] theorem powerset_empty : 𝒫(∅ : Set α) = {∅} := ext fun _ => subset_empty_iff #align set.powerset_empty Set.powerset_empty @[simp] theorem powerset_univ : 𝒫(univ : Set α) = univ := eq_univ_of_forall subset_univ #align set.powerset_univ Set.powerset_univ /-- The powerset of a singleton contains only `∅` and the singleton itself. -/ theorem powerset_singleton (x : α) : 𝒫({x} : Set α) = {∅, {x}} := by ext y rw [mem_powerset_iff, subset_singleton_iff_eq, mem_insert_iff, mem_singleton_iff] #align set.powerset_singleton Set.powerset_singleton /-! ### Sets defined as an if-then-else -/ theorem mem_dite (p : Prop) [Decidable p] (s : p → Set α) (t : ¬ p → Set α) (x : α) : (x ∈ if h : p then s h else t h) ↔ (∀ h : p, x ∈ s h) ∧ ∀ h : ¬p, x ∈ t h := by split_ifs with hp · exact ⟨fun hx => ⟨fun _ => hx, fun hnp => (hnp hp).elim⟩, fun hx => hx.1 hp⟩ · exact ⟨fun hx => ⟨fun h => (hp h).elim, fun _ => hx⟩, fun hx => hx.2 hp⟩ theorem mem_dite_univ_right (p : Prop) [Decidable p] (t : p → Set α) (x : α) : (x ∈ if h : p then t h else univ) ↔ ∀ h : p, x ∈ t h := by split_ifs <;> simp_all #align set.mem_dite_univ_right Set.mem_dite_univ_right @[simp] theorem mem_ite_univ_right (p : Prop) [Decidable p] (t : Set α) (x : α) : x ∈ ite p t Set.univ ↔ p → x ∈ t := mem_dite_univ_right p (fun _ => t) x #align set.mem_ite_univ_right Set.mem_ite_univ_right theorem mem_dite_univ_left (p : Prop) [Decidable p] (t : ¬p → Set α) (x : α) : (x ∈ if h : p then univ else t h) ↔ ∀ h : ¬p, x ∈ t h := by split_ifs <;> simp_all #align set.mem_dite_univ_left Set.mem_dite_univ_left @[simp] theorem mem_ite_univ_left (p : Prop) [Decidable p] (t : Set α) (x : α) : x ∈ ite p Set.univ t ↔ ¬p → x ∈ t := mem_dite_univ_left p (fun _ => t) x #align set.mem_ite_univ_left Set.mem_ite_univ_left
Mathlib/Data/Set/Basic.lean
2,232
2,235
theorem mem_dite_empty_right (p : Prop) [Decidable p] (t : p → Set α) (x : α) : (x ∈ if h : p then t h else ∅) ↔ ∃ h : p, x ∈ t h := by
simp only [mem_dite, mem_empty_iff_false, imp_false, not_not] exact ⟨fun h => ⟨h.2, h.1 h.2⟩, fun ⟨h₁, h₂⟩ => ⟨fun _ => h₂, h₁⟩⟩
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Yury Kudryashov, David Loeffler -/ import Mathlib.Analysis.Calculus.MeanValue import Mathlib.Analysis.Convex.Slope /-! # Convexity of functions and derivatives Here we relate convexity of functions `ℝ → ℝ` to properties of their derivatives. ## Main results * `MonotoneOn.convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `ConvexOn.monotoneOn_deriv`: if a function is convex and differentiable, then its derivative is monotone. -/ open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ## Monotonicity of `f'` implies convexity of `f` -/ /-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is differentiable on its interior, and `f'` is monotone on the interior, then `f` is convex on `D`. -/ theorem MonotoneOn.convexOn_of_deriv {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : DifferentiableOn ℝ f (interior D)) (hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn ℝ D f := convexOn_of_slope_mono_adjacent hD (by intro x y z hx hz hxy hyz -- First we prove some trivial inclusions have hxzD : Icc x z ⊆ D := hD.ordConnected.out hx hz have hxyD : Icc x y ⊆ D := (Icc_subset_Icc_right hyz.le).trans hxzD have hxyD' : Ioo x y ⊆ interior D := subset_sUnion_of_mem ⟨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyD⟩ have hyzD : Icc y z ⊆ D := (Icc_subset_Icc_left hxy.le).trans hxzD have hyzD' : Ioo y z ⊆ interior D := subset_sUnion_of_mem ⟨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzD⟩ -- Then we apply MVT to both `[x, y]` and `[y, z]` obtain ⟨a, ⟨hxa, hay⟩, ha⟩ : ∃ a ∈ Ioo x y, deriv f a = (f y - f x) / (y - x) := exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD') obtain ⟨b, ⟨hyb, hbz⟩, hb⟩ : ∃ b ∈ Ioo y z, deriv f b = (f z - f y) / (z - y) := exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD') rw [← ha, ← hb] exact hf'_mono (hxyD' ⟨hxa, hay⟩) (hyzD' ⟨hyb, hbz⟩) (hay.trans hyb).le) #align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv /-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is differentiable on its interior, and `f'` is antitone on the interior, then `f` is concave on `D`. -/ theorem AntitoneOn.concaveOn_of_deriv {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : DifferentiableOn ℝ f (interior D)) (h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn ℝ D f := haveI : MonotoneOn (deriv (-f)) (interior D) := by simpa only [← deriv.neg] using h_anti.neg neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg) #align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : ℝ} {f : ℝ → ℝ} (hf : ContinuousOn f (Icc x y)) (hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : ∀ w ∈ Ioo x y, deriv f w ≠ 0) : ∃ a ∈ Ioo x y, (f y - f x) / (y - x) < deriv f a := by have A : DifferentiableOn ℝ f (Ioo x y) := fun w wmem => (differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt obtain ⟨a, ⟨hxa, hay⟩, ha⟩ : ∃ a ∈ Ioo x y, deriv f a = (f y - f x) / (y - x) := exists_deriv_eq_slope f hxy hf A rcases nonempty_Ioo.2 hay with ⟨b, ⟨hab, hby⟩⟩ refine ⟨b, ⟨hxa.trans hab, hby⟩, ?_⟩ rw [← ha] exact hf'_mono ⟨hxa, hay⟩ ⟨hxa.trans hab, hby⟩ hab #align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux theorem StrictMonoOn.exists_slope_lt_deriv {x y : ℝ} {f : ℝ → ℝ} (hf : ContinuousOn f (Icc x y)) (hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) : ∃ a ∈ Ioo x y, (f y - f x) / (y - x) < deriv f a := by by_cases h : ∀ w ∈ Ioo x y, deriv f w ≠ 0 · apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h · push_neg at h rcases h with ⟨w, ⟨hxw, hwy⟩, hw⟩ obtain ⟨a, ⟨hxa, haw⟩, ha⟩ : ∃ a ∈ Ioo x w, (f w - f x) / (w - x) < deriv f a := by apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _ · exact hf.mono (Icc_subset_Icc le_rfl hwy.le) · exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le) · intro z hz rw [← hw] apply ne_of_lt exact hf'_mono ⟨hz.1, hz.2.trans hwy⟩ ⟨hxw, hwy⟩ hz.2 obtain ⟨b, ⟨hwb, hby⟩, hb⟩ : ∃ b ∈ Ioo w y, (f y - f w) / (y - w) < deriv f b := by apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _ · refine hf.mono (Icc_subset_Icc hxw.le le_rfl) · exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl) · intro z hz rw [← hw] apply ne_of_gt exact hf'_mono ⟨hxw, hwy⟩ ⟨hxw.trans hz.1, hz.2⟩ hz.1 refine ⟨b, ⟨hxw.trans hwb, hby⟩, ?_⟩ simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb ⊢ have : deriv f a * (w - x) < deriv f b * (w - x) := by apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _ · exact hf'_mono ⟨hxa, haw.trans hwy⟩ ⟨hxw.trans hwb, hby⟩ (haw.trans hwb) · rw [← hw] exact (hf'_mono ⟨hxw, hwy⟩ ⟨hxw.trans hwb, hby⟩ hwb).le linarith #align strict_mono_on.exists_slope_lt_deriv StrictMonoOn.exists_slope_lt_deriv theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : ℝ} {f : ℝ → ℝ} (hf : ContinuousOn f (Icc x y)) (hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : ∀ w ∈ Ioo x y, deriv f w ≠ 0) : ∃ a ∈ Ioo x y, deriv f a < (f y - f x) / (y - x) := by have A : DifferentiableOn ℝ f (Ioo x y) := fun w wmem => (differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt obtain ⟨a, ⟨hxa, hay⟩, ha⟩ : ∃ a ∈ Ioo x y, deriv f a = (f y - f x) / (y - x) := exists_deriv_eq_slope f hxy hf A rcases nonempty_Ioo.2 hxa with ⟨b, ⟨hxb, hba⟩⟩ refine ⟨b, ⟨hxb, hba.trans hay⟩, ?_⟩ rw [← ha] exact hf'_mono ⟨hxb, hba.trans hay⟩ ⟨hxa, hay⟩ hba #align strict_mono_on.exists_deriv_lt_slope_aux StrictMonoOn.exists_deriv_lt_slope_aux theorem StrictMonoOn.exists_deriv_lt_slope {x y : ℝ} {f : ℝ → ℝ} (hf : ContinuousOn f (Icc x y)) (hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) : ∃ a ∈ Ioo x y, deriv f a < (f y - f x) / (y - x) := by by_cases h : ∀ w ∈ Ioo x y, deriv f w ≠ 0 · apply StrictMonoOn.exists_deriv_lt_slope_aux hf hxy hf'_mono h · push_neg at h rcases h with ⟨w, ⟨hxw, hwy⟩, hw⟩ obtain ⟨a, ⟨hxa, haw⟩, ha⟩ : ∃ a ∈ Ioo x w, deriv f a < (f w - f x) / (w - x) := by apply StrictMonoOn.exists_deriv_lt_slope_aux _ hxw _ _ · exact hf.mono (Icc_subset_Icc le_rfl hwy.le) · exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le) · intro z hz rw [← hw] apply ne_of_lt exact hf'_mono ⟨hz.1, hz.2.trans hwy⟩ ⟨hxw, hwy⟩ hz.2 obtain ⟨b, ⟨hwb, hby⟩, hb⟩ : ∃ b ∈ Ioo w y, deriv f b < (f y - f w) / (y - w) := by apply StrictMonoOn.exists_deriv_lt_slope_aux _ hwy _ _ · refine hf.mono (Icc_subset_Icc hxw.le le_rfl) · exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl) · intro z hz rw [← hw] apply ne_of_gt exact hf'_mono ⟨hxw, hwy⟩ ⟨hxw.trans hz.1, hz.2⟩ hz.1 refine ⟨a, ⟨hxa, haw.trans hwy⟩, ?_⟩ simp only [lt_div_iff, hxy, hxw, hwy, sub_pos] at ha hb ⊢ have : deriv f a * (y - w) < deriv f b * (y - w) := by apply mul_lt_mul _ le_rfl (sub_pos.2 hwy) _ · exact hf'_mono ⟨hxa, haw.trans hwy⟩ ⟨hxw.trans hwb, hby⟩ (haw.trans hwb) · rw [← hw] exact (hf'_mono ⟨hxw, hwy⟩ ⟨hxw.trans hwb, hby⟩ hwb).le linarith #align strict_mono_on.exists_deriv_lt_slope StrictMonoOn.exists_deriv_lt_slope /-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, and `f'` is strictly monotone on the interior, then `f` is strictly convex on `D`. Note that we don't require differentiability, since it is guaranteed at all but at most one point by the strict monotonicity of `f'`. -/ theorem StrictMonoOn.strictConvexOn_of_deriv {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : StrictMonoOn (deriv f) (interior D)) : StrictConvexOn ℝ D f := strictConvexOn_of_slope_strict_mono_adjacent hD fun {x y z} hx hz hxy hyz => by -- First we prove some trivial inclusions have hxzD : Icc x z ⊆ D := hD.ordConnected.out hx hz have hxyD : Icc x y ⊆ D := (Icc_subset_Icc_right hyz.le).trans hxzD have hxyD' : Ioo x y ⊆ interior D := subset_sUnion_of_mem ⟨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyD⟩ have hyzD : Icc y z ⊆ D := (Icc_subset_Icc_left hxy.le).trans hxzD have hyzD' : Ioo y z ⊆ interior D := subset_sUnion_of_mem ⟨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzD⟩ -- Then we get points `a` and `b` in each interval `[x, y]` and `[y, z]` where the derivatives -- can be compared to the slopes between `x, y` and `y, z` respectively. obtain ⟨a, ⟨hxa, hay⟩, ha⟩ : ∃ a ∈ Ioo x y, (f y - f x) / (y - x) < deriv f a := StrictMonoOn.exists_slope_lt_deriv (hf.mono hxyD) hxy (hf'.mono hxyD') obtain ⟨b, ⟨hyb, hbz⟩, hb⟩ : ∃ b ∈ Ioo y z, deriv f b < (f z - f y) / (z - y) := StrictMonoOn.exists_deriv_lt_slope (hf.mono hyzD) hyz (hf'.mono hyzD') apply ha.trans (lt_trans _ hb) exact hf' (hxyD' ⟨hxa, hay⟩) (hyzD' ⟨hyb, hbz⟩) (hay.trans hyb) #align strict_mono_on.strict_convex_on_of_deriv StrictMonoOn.strictConvexOn_of_deriv /-- If a function `f` is continuous on a convex set `D ⊆ ℝ` and `f'` is strictly antitone on the interior, then `f` is strictly concave on `D`. Note that we don't require differentiability, since it is guaranteed at all but at most one point by the strict antitonicity of `f'`. -/ theorem StrictAntiOn.strictConcaveOn_of_deriv {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (h_anti : StrictAntiOn (deriv f) (interior D)) : StrictConcaveOn ℝ D f := have : StrictMonoOn (deriv (-f)) (interior D) := by simpa only [← deriv.neg] using h_anti.neg neg_neg f ▸ (this.strictConvexOn_of_deriv hD hf.neg).neg #align strict_anti_on.strict_concave_on_of_deriv StrictAntiOn.strictConcaveOn_of_deriv /-- If a function `f` is differentiable and `f'` is monotone on `ℝ` then `f` is convex. -/ theorem Monotone.convexOn_univ_of_deriv {f : ℝ → ℝ} (hf : Differentiable ℝ f) (hf'_mono : Monotone (deriv f)) : ConvexOn ℝ univ f := (hf'_mono.monotoneOn _).convexOn_of_deriv convex_univ hf.continuous.continuousOn hf.differentiableOn #align monotone.convex_on_univ_of_deriv Monotone.convexOn_univ_of_deriv /-- If a function `f` is differentiable and `f'` is antitone on `ℝ` then `f` is concave. -/ theorem Antitone.concaveOn_univ_of_deriv {f : ℝ → ℝ} (hf : Differentiable ℝ f) (hf'_anti : Antitone (deriv f)) : ConcaveOn ℝ univ f := (hf'_anti.antitoneOn _).concaveOn_of_deriv convex_univ hf.continuous.continuousOn hf.differentiableOn #align antitone.concave_on_univ_of_deriv Antitone.concaveOn_univ_of_deriv /-- If a function `f` is continuous and `f'` is strictly monotone on `ℝ` then `f` is strictly convex. Note that we don't require differentiability, since it is guaranteed at all but at most one point by the strict monotonicity of `f'`. -/ theorem StrictMono.strictConvexOn_univ_of_deriv {f : ℝ → ℝ} (hf : Continuous f) (hf'_mono : StrictMono (deriv f)) : StrictConvexOn ℝ univ f := (hf'_mono.strictMonoOn _).strictConvexOn_of_deriv convex_univ hf.continuousOn #align strict_mono.strict_convex_on_univ_of_deriv StrictMono.strictConvexOn_univ_of_deriv /-- If a function `f` is continuous and `f'` is strictly antitone on `ℝ` then `f` is strictly concave. Note that we don't require differentiability, since it is guaranteed at all but at most one point by the strict antitonicity of `f'`. -/ theorem StrictAnti.strictConcaveOn_univ_of_deriv {f : ℝ → ℝ} (hf : Continuous f) (hf'_anti : StrictAnti (deriv f)) : StrictConcaveOn ℝ univ f := (hf'_anti.strictAntiOn _).strictConcaveOn_of_deriv convex_univ hf.continuousOn #align strict_anti.strict_concave_on_univ_of_deriv StrictAnti.strictConcaveOn_univ_of_deriv /-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is twice differentiable on its interior, and `f''` is nonnegative on the interior, then `f` is convex on `D`. -/ theorem convexOn_of_deriv2_nonneg {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : DifferentiableOn ℝ f (interior D)) (hf'' : DifferentiableOn ℝ (deriv f) (interior D)) (hf''_nonneg : ∀ x ∈ interior D, 0 ≤ deriv^[2] f x) : ConvexOn ℝ D f := (monotoneOn_of_deriv_nonneg hD.interior hf''.continuousOn (by rwa [interior_interior]) <| by rwa [interior_interior]).convexOn_of_deriv hD hf hf' #align convex_on_of_deriv2_nonneg convexOn_of_deriv2_nonneg /-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is twice differentiable on its interior, and `f''` is nonpositive on the interior, then `f` is concave on `D`. -/ theorem concaveOn_of_deriv2_nonpos {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : DifferentiableOn ℝ f (interior D)) (hf'' : DifferentiableOn ℝ (deriv f) (interior D)) (hf''_nonpos : ∀ x ∈ interior D, deriv^[2] f x ≤ 0) : ConcaveOn ℝ D f := (antitoneOn_of_deriv_nonpos hD.interior hf''.continuousOn (by rwa [interior_interior]) <| by rwa [interior_interior]).concaveOn_of_deriv hD hf hf' #align concave_on_of_deriv2_nonpos concaveOn_of_deriv2_nonpos /-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is twice differentiable on its interior, and `f''` is nonnegative on the interior, then `f` is convex on `D`. -/ lemma convexOn_of_hasDerivWithinAt2_nonneg {D : Set ℝ} (hD : Convex ℝ D) {f f' f'' : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : ∀ x ∈ interior D, HasDerivWithinAt f (f' x) (interior D) x) (hf'' : ∀ x ∈ interior D, HasDerivWithinAt f' (f'' x) (interior D) x) (hf''₀ : ∀ x ∈ interior D, 0 ≤ f'' x) : ConvexOn ℝ D f := by have : (interior D).EqOn (deriv f) f' := deriv_eqOn isOpen_interior hf' refine convexOn_of_deriv2_nonneg hD hf (fun x hx ↦ (hf' _ hx).differentiableWithinAt) ?_ ?_ · rw [differentiableOn_congr this] exact fun x hx ↦ (hf'' _ hx).differentiableWithinAt · rintro x hx convert hf''₀ _ hx using 1 dsimp rw [deriv_eqOn isOpen_interior (fun y hy ↦ ?_) hx] exact (hf'' _ hy).congr this $ by rw [this hy] /-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is twice differentiable on its interior, and `f''` is nonpositive on the interior, then `f` is concave on `D`. -/ lemma concaveOn_of_hasDerivWithinAt2_nonpos {D : Set ℝ} (hD : Convex ℝ D) {f f' f'' : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : ∀ x ∈ interior D, HasDerivWithinAt f (f' x) (interior D) x) (hf'' : ∀ x ∈ interior D, HasDerivWithinAt f' (f'' x) (interior D) x) (hf''₀ : ∀ x ∈ interior D, f'' x ≤ 0) : ConcaveOn ℝ D f := by have : (interior D).EqOn (deriv f) f' := deriv_eqOn isOpen_interior hf' refine concaveOn_of_deriv2_nonpos hD hf (fun x hx ↦ (hf' _ hx).differentiableWithinAt) ?_ ?_ · rw [differentiableOn_congr this] exact fun x hx ↦ (hf'' _ hx).differentiableWithinAt · rintro x hx convert hf''₀ _ hx using 1 dsimp rw [deriv_eqOn isOpen_interior (fun y hy ↦ ?_) hx] exact (hf'' _ hy).congr this $ by rw [this hy] /-- If a function `f` is continuous on a convex set `D ⊆ ℝ` and `f''` is strictly positive on the interior, then `f` is strictly convex on `D`. Note that we don't require twice differentiability explicitly as it is already implied by the second derivative being strictly positive, except at at most one point. -/ theorem strictConvexOn_of_deriv2_pos {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf'' : ∀ x ∈ interior D, 0 < (deriv^[2] f) x) : StrictConvexOn ℝ D f := ((strictMonoOn_of_deriv_pos hD.interior fun z hz => (differentiableAt_of_deriv_ne_zero (hf'' z hz).ne').differentiableWithinAt.continuousWithinAt) <| by rwa [interior_interior]).strictConvexOn_of_deriv hD hf #align strict_convex_on_of_deriv2_pos strictConvexOn_of_deriv2_pos /-- If a function `f` is continuous on a convex set `D ⊆ ℝ` and `f''` is strictly negative on the interior, then `f` is strictly concave on `D`. Note that we don't require twice differentiability explicitly as it already implied by the second derivative being strictly negative, except at at most one point. -/ theorem strictConcaveOn_of_deriv2_neg {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf'' : ∀ x ∈ interior D, deriv^[2] f x < 0) : StrictConcaveOn ℝ D f := ((strictAntiOn_of_deriv_neg hD.interior fun z hz => (differentiableAt_of_deriv_ne_zero (hf'' z hz).ne).differentiableWithinAt.continuousWithinAt) <| by rwa [interior_interior]).strictConcaveOn_of_deriv hD hf #align strict_concave_on_of_deriv2_neg strictConcaveOn_of_deriv2_neg /-- If a function `f` is twice differentiable on an open convex set `D ⊆ ℝ` and `f''` is nonnegative on `D`, then `f` is convex on `D`. -/ theorem convexOn_of_deriv2_nonneg' {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf' : DifferentiableOn ℝ f D) (hf'' : DifferentiableOn ℝ (deriv f) D) (hf''_nonneg : ∀ x ∈ D, 0 ≤ (deriv^[2] f) x) : ConvexOn ℝ D f := convexOn_of_deriv2_nonneg hD hf'.continuousOn (hf'.mono interior_subset) (hf''.mono interior_subset) fun x hx => hf''_nonneg x (interior_subset hx) #align convex_on_of_deriv2_nonneg' convexOn_of_deriv2_nonneg' /-- If a function `f` is twice differentiable on an open convex set `D ⊆ ℝ` and `f''` is nonpositive on `D`, then `f` is concave on `D`. -/ theorem concaveOn_of_deriv2_nonpos' {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf' : DifferentiableOn ℝ f D) (hf'' : DifferentiableOn ℝ (deriv f) D) (hf''_nonpos : ∀ x ∈ D, deriv^[2] f x ≤ 0) : ConcaveOn ℝ D f := concaveOn_of_deriv2_nonpos hD hf'.continuousOn (hf'.mono interior_subset) (hf''.mono interior_subset) fun x hx => hf''_nonpos x (interior_subset hx) #align concave_on_of_deriv2_nonpos' concaveOn_of_deriv2_nonpos' /-- If a function `f` is continuous on a convex set `D ⊆ ℝ` and `f''` is strictly positive on `D`, then `f` is strictly convex on `D`. Note that we don't require twice differentiability explicitly as it is already implied by the second derivative being strictly positive, except at at most one point. -/ theorem strictConvexOn_of_deriv2_pos' {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf'' : ∀ x ∈ D, 0 < (deriv^[2] f) x) : StrictConvexOn ℝ D f := strictConvexOn_of_deriv2_pos hD hf fun x hx => hf'' x (interior_subset hx) #align strict_convex_on_of_deriv2_pos' strictConvexOn_of_deriv2_pos' /-- If a function `f` is continuous on a convex set `D ⊆ ℝ` and `f''` is strictly negative on `D`, then `f` is strictly concave on `D`. Note that we don't require twice differentiability explicitly as it is already implied by the second derivative being strictly negative, except at at most one point. -/ theorem strictConcaveOn_of_deriv2_neg' {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf'' : ∀ x ∈ D, deriv^[2] f x < 0) : StrictConcaveOn ℝ D f := strictConcaveOn_of_deriv2_neg hD hf fun x hx => hf'' x (interior_subset hx) #align strict_concave_on_of_deriv2_neg' strictConcaveOn_of_deriv2_neg' /-- If a function `f` is twice differentiable on `ℝ`, and `f''` is nonnegative on `ℝ`, then `f` is convex on `ℝ`. -/ theorem convexOn_univ_of_deriv2_nonneg {f : ℝ → ℝ} (hf' : Differentiable ℝ f) (hf'' : Differentiable ℝ (deriv f)) (hf''_nonneg : ∀ x, 0 ≤ (deriv^[2] f) x) : ConvexOn ℝ univ f := convexOn_of_deriv2_nonneg' convex_univ hf'.differentiableOn hf''.differentiableOn fun x _ => hf''_nonneg x #align convex_on_univ_of_deriv2_nonneg convexOn_univ_of_deriv2_nonneg /-- If a function `f` is twice differentiable on `ℝ`, and `f''` is nonpositive on `ℝ`, then `f` is concave on `ℝ`. -/ theorem concaveOn_univ_of_deriv2_nonpos {f : ℝ → ℝ} (hf' : Differentiable ℝ f) (hf'' : Differentiable ℝ (deriv f)) (hf''_nonpos : ∀ x, deriv^[2] f x ≤ 0) : ConcaveOn ℝ univ f := concaveOn_of_deriv2_nonpos' convex_univ hf'.differentiableOn hf''.differentiableOn fun x _ => hf''_nonpos x #align concave_on_univ_of_deriv2_nonpos concaveOn_univ_of_deriv2_nonpos /-- If a function `f` is continuous on `ℝ`, and `f''` is strictly positive on `ℝ`, then `f` is strictly convex on `ℝ`. Note that we don't require twice differentiability explicitly as it is already implied by the second derivative being strictly positive, except at at most one point. -/ theorem strictConvexOn_univ_of_deriv2_pos {f : ℝ → ℝ} (hf : Continuous f) (hf'' : ∀ x, 0 < (deriv^[2] f) x) : StrictConvexOn ℝ univ f := strictConvexOn_of_deriv2_pos' convex_univ hf.continuousOn fun x _ => hf'' x #align strict_convex_on_univ_of_deriv2_pos strictConvexOn_univ_of_deriv2_pos /-- If a function `f` is continuous on `ℝ`, and `f''` is strictly negative on `ℝ`, then `f` is strictly concave on `ℝ`. Note that we don't require twice differentiability explicitly as it is already implied by the second derivative being strictly negative, except at at most one point. -/ theorem strictConcaveOn_univ_of_deriv2_neg {f : ℝ → ℝ} (hf : Continuous f) (hf'' : ∀ x, deriv^[2] f x < 0) : StrictConcaveOn ℝ univ f := strictConcaveOn_of_deriv2_neg' convex_univ hf.continuousOn fun x _ => hf'' x #align strict_concave_on_univ_of_deriv2_neg strictConcaveOn_univ_of_deriv2_neg /-! ## Convexity of `f` implies monotonicity of `f'` In this section we prove inequalities relating derivatives of convex functions to slopes of secant lines, and deduce that if `f` is convex then its derivative is monotone (and similarly for strict convexity / strict monotonicity). -/ namespace ConvexOn variable {S : Set ℝ} {f : ℝ → ℝ} {x y f' : ℝ} section left /-! ### Convex functions, derivative at left endpoint of secant -/ /-- If `f : ℝ → ℝ` is convex on `S` and right-differentiable at `x ∈ S`, then the slope of any secant line with left endpoint at `x` is bounded below by the right derivative of `f` at `x`. -/ lemma le_slope_of_hasDerivWithinAt_Ioi (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' (Ioi x) x) : f' ≤ slope f x y := by apply le_of_tendsto <| (hasDerivWithinAt_iff_tendsto_slope' not_mem_Ioi_self).mp hf' simp_rw [eventually_nhdsWithin_iff, slope_def_field] filter_upwards [eventually_lt_nhds hxy] with t ht (ht' : x < t) refine hfc.secant_mono hx (?_ : t ∈ S) hy ht'.ne' hxy.ne' ht.le exact hfc.1.ordConnected.out hx hy ⟨ht'.le, ht.le⟩ /-- Reformulation of `ConvexOn.le_slope_of_hasDerivWithinAt_Ioi` using `derivWithin`. -/ lemma right_deriv_le_slope (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableWithinAt ℝ f (Ioi x) x) : derivWithin f (Ioi x) x ≤ slope f x y := le_slope_of_hasDerivWithinAt_Ioi hfc hx hy hxy hfd.hasDerivWithinAt /-- If `f : ℝ → ℝ` is convex on `S` and differentiable within `S` at `x`, then the slope of any secant line with left endpoint at `x` is bounded below by the derivative of `f` within `S` at `x`. This is fractionally weaker than `ConvexOn.le_slope_of_hasDerivWithinAt_Ioi` but simpler to apply under a `DifferentiableOn S` hypothesis. -/ lemma le_slope_of_hasDerivWithinAt (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' S x) : f' ≤ slope f x y := by refine hfc.le_slope_of_hasDerivWithinAt_Ioi hx hy hxy (hf'.mono_of_mem ?_) rw [mem_nhdsWithin_Ioi_iff_exists_Ioc_subset] exact ⟨y, hxy, Ioc_subset_Icc_self.trans (hfc.1.ordConnected.out hx hy)⟩ /-- Reformulation of `ConvexOn.le_slope_of_hasDerivWithinAt` using `derivWithin`. -/ lemma derivWithin_le_slope (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableWithinAt ℝ f S x) : derivWithin f S x ≤ slope f x y := le_slope_of_hasDerivWithinAt hfc hx hy hxy hfd.hasDerivWithinAt /-- If `f : ℝ → ℝ` is convex on `S` and differentiable at `x ∈ S`, then the slope of any secant line with left endpoint at `x` is bounded below by the derivative of `f` at `x`. -/ lemma le_slope_of_hasDerivAt (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (ha : HasDerivAt f f' x) : f' ≤ slope f x y := hfc.le_slope_of_hasDerivWithinAt_Ioi hx hy hxy ha.hasDerivWithinAt /-- Reformulation of `ConvexOn.le_slope_of_hasDerivAt` using `deriv` -/ lemma deriv_le_slope (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableAt ℝ f x) : deriv f x ≤ slope f x y := le_slope_of_hasDerivAt hfc hx hy hxy hfd.hasDerivAt end left section right /-! ### Convex functions, derivative at right endpoint of secant -/ /-- If `f : ℝ → ℝ` is convex on `S` and left-differentiable at `y ∈ S`, then the slope of any secant line with right endpoint at `y` is bounded above by the left derivative of `f` at `y`. -/ lemma slope_le_of_hasDerivWithinAt_Iio (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' (Iio y) y) : slope f x y ≤ f' := by apply ge_of_tendsto <| (hasDerivWithinAt_iff_tendsto_slope' not_mem_Iio_self).mp hf' simp_rw [eventually_nhdsWithin_iff, slope_comm f x y, slope_def_field] filter_upwards [eventually_gt_nhds hxy] with t ht (ht' : t < y) refine hfc.secant_mono hy hx (?_ : t ∈ S) hxy.ne ht'.ne ht.le exact hfc.1.ordConnected.out hx hy ⟨ht.le, ht'.le⟩ /-- Reformulation of `ConvexOn.slope_le_of_hasDerivWithinAt_Iio` using `derivWithin`. -/ lemma slope_le_left_deriv (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableWithinAt ℝ f (Iio y) y) : slope f x y ≤ derivWithin f (Iio y) y := hfc.slope_le_of_hasDerivWithinAt_Iio hx hy hxy hfd.hasDerivWithinAt /-- If `f : ℝ → ℝ` is convex on `S` and differentiable within `S` at `y`, then the slope of any secant line with right endpoint at `y` is bounded above by the derivative of `f` within `S` at `y`. This is fractionally weaker than `ConvexOn.slope_le_of_hasDerivWithinAt_Iio` but simpler to apply under a `DifferentiableOn S` hypothesis. -/ lemma slope_le_of_hasDerivWithinAt (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' S y) : slope f x y ≤ f' := by refine hfc.slope_le_of_hasDerivWithinAt_Iio hx hy hxy (hf'.mono_of_mem ?_) rw [mem_nhdsWithin_Iio_iff_exists_Ico_subset] exact ⟨x, hxy, Ico_subset_Icc_self.trans (hfc.1.ordConnected.out hx hy)⟩ /-- Reformulation of `ConvexOn.slope_le_of_hasDerivWithinAt` using `derivWithin`. -/ lemma slope_le_derivWithin (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableWithinAt ℝ f S y) : slope f x y ≤ derivWithin f S y := hfc.slope_le_of_hasDerivWithinAt hx hy hxy hfd.hasDerivWithinAt /-- If `f : ℝ → ℝ` is convex on `S` and differentiable at `y ∈ S`, then the slope of any secant line with right endpoint at `y` is bounded above by the derivative of `f` at `y`. -/ lemma slope_le_of_hasDerivAt (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivAt f f' y) : slope f x y ≤ f' := hfc.slope_le_of_hasDerivWithinAt_Iio hx hy hxy hf'.hasDerivWithinAt /-- Reformulation of `ConvexOn.slope_le_of_hasDerivAt` using `deriv`. -/ lemma slope_le_deriv (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableAt ℝ f y) : slope f x y ≤ deriv f y := hfc.slope_le_of_hasDerivAt hx hy hxy hfd.hasDerivAt end right /-! ### Convex functions, monotonicity of derivative -/ /-- If `f` is convex on `S` and differentiable on `S`, then its derivative within `S` is monotone on `S`. -/ lemma monotoneOn_derivWithin (hfc : ConvexOn ℝ S f) (hfd : DifferentiableOn ℝ f S) : MonotoneOn (derivWithin f S) S := by intro x hx y hy hxy rcases eq_or_lt_of_le hxy with rfl | hxy' · rfl exact (hfc.derivWithin_le_slope hx hy hxy' (hfd x hx)).trans (hfc.slope_le_derivWithin hx hy hxy' (hfd y hy)) /-- If `f` is convex on `S` and differentiable at all points of `S`, then its derivative is monotone on `S`. -/
Mathlib/Analysis/Convex/Deriv.lean
512
517
theorem monotoneOn_deriv (hfc : ConvexOn ℝ S f) (hfd : ∀ x ∈ S, DifferentiableAt ℝ f x) : MonotoneOn (deriv f) S := by
intro x hx y hy hxy rcases eq_or_lt_of_le hxy with rfl | hxy' · rfl exact (hfc.deriv_le_slope hx hy hxy' (hfd x hx)).trans (hfc.slope_le_deriv hx hy hxy' (hfd y hy))
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.CategoryTheory.Adjunction.FullyFaithful import Mathlib.CategoryTheory.Adjunction.Limits import Mathlib.CategoryTheory.Limits.Shapes.CommSq import Mathlib.CategoryTheory.Limits.Shapes.StrictInitial import Mathlib.CategoryTheory.Limits.FunctorCategory import Mathlib.CategoryTheory.Limits.Constructions.FiniteProductsOfBinaryProducts #align_import category_theory.extensive from "leanprover-community/mathlib"@"178a32653e369dce2da68dc6b2694e385d484ef1" /-! # Universal colimits and van Kampen colimits ## Main definitions - `CategoryTheory.IsUniversalColimit`: A (colimit) cocone over a diagram `F : J ⥤ C` is universal if it is stable under pullbacks. - `CategoryTheory.IsVanKampenColimit`: A (colimit) cocone over a diagram `F : J ⥤ C` is van Kampen if for every cocone `c'` over the pullback of the diagram `F' : J ⥤ C'`, `c'` is colimiting iff `c'` is the pullback of `c`. ## References - https://ncatlab.org/nlab/show/van+Kampen+colimit - [Stephen Lack and Paweł Sobociński, Adhesive Categories][adhesive2004] -/ open CategoryTheory.Limits namespace CategoryTheory universe v' u' v u variable {J : Type v'} [Category.{u'} J] {C : Type u} [Category.{v} C] variable {K : Type*} [Category K] {D : Type*} [Category D] section NatTrans /-- A natural transformation is equifibered if every commutative square of the following form is a pullback. ``` F(X) → F(Y) ↓ ↓ G(X) → G(Y) ``` -/ def NatTrans.Equifibered {F G : J ⥤ C} (α : F ⟶ G) : Prop := ∀ ⦃i j : J⦄ (f : i ⟶ j), IsPullback (F.map f) (α.app i) (α.app j) (G.map f) #align category_theory.nat_trans.equifibered CategoryTheory.NatTrans.Equifibered theorem NatTrans.equifibered_of_isIso {F G : J ⥤ C} (α : F ⟶ G) [IsIso α] : Equifibered α := fun _ _ f => IsPullback.of_vert_isIso ⟨NatTrans.naturality _ f⟩ #align category_theory.nat_trans.equifibered_of_is_iso CategoryTheory.NatTrans.equifibered_of_isIso theorem NatTrans.Equifibered.comp {F G H : J ⥤ C} {α : F ⟶ G} {β : G ⟶ H} (hα : Equifibered α) (hβ : Equifibered β) : Equifibered (α ≫ β) := fun _ _ f => (hα f).paste_vert (hβ f) #align category_theory.nat_trans.equifibered.comp CategoryTheory.NatTrans.Equifibered.comp theorem NatTrans.Equifibered.whiskerRight {F G : J ⥤ C} {α : F ⟶ G} (hα : Equifibered α) (H : C ⥤ D) [∀ (i j : J) (f : j ⟶ i), PreservesLimit (cospan (α.app i) (G.map f)) H] : Equifibered (whiskerRight α H) := fun _ _ f => (hα f).map H #align category_theory.nat_trans.equifibered.whisker_right CategoryTheory.NatTrans.Equifibered.whiskerRight theorem NatTrans.Equifibered.whiskerLeft {K : Type*} [Category K] {F G : J ⥤ C} {α : F ⟶ G} (hα : Equifibered α) (H : K ⥤ J) : Equifibered (whiskerLeft H α) := fun _ _ f => hα (H.map f) theorem mapPair_equifibered {F F' : Discrete WalkingPair ⥤ C} (α : F ⟶ F') : NatTrans.Equifibered α := by rintro ⟨⟨⟩⟩ ⟨j⟩ ⟨⟨rfl : _ = j⟩⟩ all_goals dsimp; simp only [Discrete.functor_map_id] exact IsPullback.of_horiz_isIso ⟨by simp only [Category.comp_id, Category.id_comp]⟩ #align category_theory.map_pair_equifibered CategoryTheory.mapPair_equifibered theorem NatTrans.equifibered_of_discrete {ι : Type*} {F G : Discrete ι ⥤ C} (α : F ⟶ G) : NatTrans.Equifibered α := by rintro ⟨i⟩ ⟨j⟩ ⟨⟨rfl : i = j⟩⟩ simp only [Discrete.functor_map_id] exact IsPullback.of_horiz_isIso ⟨by rw [Category.id_comp, Category.comp_id]⟩ end NatTrans /-- A (colimit) cocone over a diagram `F : J ⥤ C` is universal if it is stable under pullbacks. -/ def IsUniversalColimit {F : J ⥤ C} (c : Cocone F) : Prop := ∀ ⦃F' : J ⥤ C⦄ (c' : Cocone F') (α : F' ⟶ F) (f : c'.pt ⟶ c.pt) (_ : α ≫ c.ι = c'.ι ≫ (Functor.const J).map f) (_ : NatTrans.Equifibered α), (∀ j : J, IsPullback (c'.ι.app j) (α.app j) f (c.ι.app j)) → Nonempty (IsColimit c') #align category_theory.is_universal_colimit CategoryTheory.IsUniversalColimit /-- A (colimit) cocone over a diagram `F : J ⥤ C` is van Kampen if for every cocone `c'` over the pullback of the diagram `F' : J ⥤ C'`, `c'` is colimiting iff `c'` is the pullback of `c`. TODO: Show that this is iff the functor `C ⥤ Catᵒᵖ` sending `x` to `C/x` preserves it. TODO: Show that this is iff the inclusion functor `C ⥤ Span(C)` preserves it. -/ def IsVanKampenColimit {F : J ⥤ C} (c : Cocone F) : Prop := ∀ ⦃F' : J ⥤ C⦄ (c' : Cocone F') (α : F' ⟶ F) (f : c'.pt ⟶ c.pt) (_ : α ≫ c.ι = c'.ι ≫ (Functor.const J).map f) (_ : NatTrans.Equifibered α), Nonempty (IsColimit c') ↔ ∀ j : J, IsPullback (c'.ι.app j) (α.app j) f (c.ι.app j) #align category_theory.is_van_kampen_colimit CategoryTheory.IsVanKampenColimit theorem IsVanKampenColimit.isUniversal {F : J ⥤ C} {c : Cocone F} (H : IsVanKampenColimit c) : IsUniversalColimit c := fun _ c' α f h hα => (H c' α f h hα).mpr #align category_theory.is_van_kampen_colimit.is_universal CategoryTheory.IsVanKampenColimit.isUniversal /-- A universal colimit is a colimit. -/ noncomputable def IsUniversalColimit.isColimit {F : J ⥤ C} {c : Cocone F} (h : IsUniversalColimit c) : IsColimit c := by refine ((h c (𝟙 F) (𝟙 c.pt : _) (by rw [Functor.map_id, Category.comp_id, Category.id_comp]) (NatTrans.equifibered_of_isIso _)) fun j => ?_).some haveI : IsIso (𝟙 c.pt) := inferInstance exact IsPullback.of_vert_isIso ⟨by erw [NatTrans.id_app, Category.comp_id, Category.id_comp]⟩ /-- A van Kampen colimit is a colimit. -/ noncomputable def IsVanKampenColimit.isColimit {F : J ⥤ C} {c : Cocone F} (h : IsVanKampenColimit c) : IsColimit c := h.isUniversal.isColimit #align category_theory.is_van_kampen_colimit.is_colimit CategoryTheory.IsVanKampenColimit.isColimit theorem IsInitial.isVanKampenColimit [HasStrictInitialObjects C] {X : C} (h : IsInitial X) : IsVanKampenColimit (asEmptyCocone X) := by intro F' c' α f hf hα have : F' = Functor.empty C := by apply Functor.hext <;> rintro ⟨⟨⟩⟩ subst this haveI := h.isIso_to f refine ⟨by rintro _ ⟨⟨⟩⟩, fun _ => ⟨IsColimit.ofIsoColimit h (Cocones.ext (asIso f).symm <| by rintro ⟨⟨⟩⟩)⟩⟩ #align category_theory.is_initial.is_van_kampen_colimit CategoryTheory.IsInitial.isVanKampenColimit section Functor theorem IsUniversalColimit.of_iso {F : J ⥤ C} {c c' : Cocone F} (hc : IsUniversalColimit c) (e : c ≅ c') : IsUniversalColimit c' := by intro F' c'' α f h hα H have : c'.ι ≫ (Functor.const J).map e.inv.hom = c.ι := by ext j exact e.inv.2 j apply hc c'' α (f ≫ e.inv.1) (by rw [Functor.map_comp, ← reassoc_of% h, this]) hα intro j rw [← Category.comp_id (α.app j)] have : IsIso e.inv.hom := Functor.map_isIso (Cocones.forget _) e.inv exact (H j).paste_vert (IsPullback.of_vert_isIso ⟨by simp⟩) theorem IsVanKampenColimit.of_iso {F : J ⥤ C} {c c' : Cocone F} (H : IsVanKampenColimit c) (e : c ≅ c') : IsVanKampenColimit c' := by intro F' c'' α f h hα have : c'.ι ≫ (Functor.const J).map e.inv.hom = c.ι := by ext j exact e.inv.2 j rw [H c'' α (f ≫ e.inv.1) (by rw [Functor.map_comp, ← reassoc_of% h, this]) hα] apply forall_congr' intro j conv_lhs => rw [← Category.comp_id (α.app j)] haveI : IsIso e.inv.hom := Functor.map_isIso (Cocones.forget _) e.inv exact (IsPullback.of_vert_isIso ⟨by simp⟩).paste_vert_iff (NatTrans.congr_app h j).symm #align category_theory.is_van_kampen_colimit.of_iso CategoryTheory.IsVanKampenColimit.of_iso theorem IsVanKampenColimit.precompose_isIso {F G : J ⥤ C} (α : F ⟶ G) [IsIso α] {c : Cocone G} (hc : IsVanKampenColimit c) : IsVanKampenColimit ((Cocones.precompose α).obj c) := by intros F' c' α' f e hα refine (hc c' (α' ≫ α) f ((Category.assoc _ _ _).trans e) (hα.comp (NatTrans.equifibered_of_isIso _))).trans ?_ apply forall_congr' intro j simp only [Functor.const_obj_obj, NatTrans.comp_app, Cocones.precompose_obj_pt, Cocones.precompose_obj_ι] have : IsPullback (α.app j ≫ c.ι.app j) (α.app j) (𝟙 _) (c.ι.app j) := IsPullback.of_vert_isIso ⟨Category.comp_id _⟩ rw [← IsPullback.paste_vert_iff this _, Category.comp_id] exact (congr_app e j).symm theorem IsUniversalColimit.precompose_isIso {F G : J ⥤ C} (α : F ⟶ G) [IsIso α] {c : Cocone G} (hc : IsUniversalColimit c) : IsUniversalColimit ((Cocones.precompose α).obj c) := by intros F' c' α' f e hα H apply (hc c' (α' ≫ α) f ((Category.assoc _ _ _).trans e) (hα.comp (NatTrans.equifibered_of_isIso _))) intro j simp only [Functor.const_obj_obj, NatTrans.comp_app, Cocones.precompose_obj_pt, Cocones.precompose_obj_ι] rw [← Category.comp_id f] exact (H j).paste_vert (IsPullback.of_vert_isIso ⟨Category.comp_id _⟩) theorem IsVanKampenColimit.precompose_isIso_iff {F G : J ⥤ C} (α : F ⟶ G) [IsIso α] {c : Cocone G} : IsVanKampenColimit ((Cocones.precompose α).obj c) ↔ IsVanKampenColimit c := ⟨fun hc ↦ IsVanKampenColimit.of_iso (IsVanKampenColimit.precompose_isIso (inv α) hc) (Cocones.ext (Iso.refl _) (by simp)), IsVanKampenColimit.precompose_isIso α⟩ theorem IsUniversalColimit.of_mapCocone (G : C ⥤ D) {F : J ⥤ C} {c : Cocone F} [PreservesLimitsOfShape WalkingCospan G] [ReflectsColimitsOfShape J G] (hc : IsUniversalColimit (G.mapCocone c)) : IsUniversalColimit c := fun F' c' α f h hα H ↦ ⟨ReflectsColimit.reflects (hc (G.mapCocone c') (whiskerRight α G) (G.map f) (by ext j; simpa using G.congr_map (NatTrans.congr_app h j)) (hα.whiskerRight G) (fun j ↦ (H j).map G)).some⟩ theorem IsVanKampenColimit.of_mapCocone (G : C ⥤ D) {F : J ⥤ C} {c : Cocone F} [∀ (i j : J) (X : C) (f : X ⟶ F.obj j) (g : i ⟶ j), PreservesLimit (cospan f (F.map g)) G] [∀ (i : J) (X : C) (f : X ⟶ c.pt), PreservesLimit (cospan f (c.ι.app i)) G] [ReflectsLimitsOfShape WalkingCospan G] [PreservesColimitsOfShape J G] [ReflectsColimitsOfShape J G] (H : IsVanKampenColimit (G.mapCocone c)) : IsVanKampenColimit c := by intro F' c' α f h hα refine (Iff.trans ?_ (H (G.mapCocone c') (whiskerRight α G) (G.map f) (by ext j; simpa using G.congr_map (NatTrans.congr_app h j)) (hα.whiskerRight G))).trans (forall_congr' fun j => ?_) · exact ⟨fun h => ⟨isColimitOfPreserves G h.some⟩, fun h => ⟨isColimitOfReflects G h.some⟩⟩ · exact IsPullback.map_iff G (NatTrans.congr_app h.symm j) #align category_theory.is_van_kampen_colimit.of_map CategoryTheory.IsVanKampenColimit.of_mapCocone theorem IsVanKampenColimit.mapCocone_iff (G : C ⥤ D) {F : J ⥤ C} {c : Cocone F} [G.IsEquivalence] : IsVanKampenColimit (G.mapCocone c) ↔ IsVanKampenColimit c := ⟨IsVanKampenColimit.of_mapCocone G, fun hc ↦ by let e : F ⋙ G ⋙ Functor.inv G ≅ F := NatIso.hcomp (Iso.refl F) G.asEquivalence.unitIso.symm apply IsVanKampenColimit.of_mapCocone G.inv apply (IsVanKampenColimit.precompose_isIso_iff e.inv).mp exact hc.of_iso (Cocones.ext (G.asEquivalence.unitIso.app c.pt) (fun j => (by simp [e])))⟩ theorem IsUniversalColimit.whiskerEquivalence {K : Type*} [Category K] (e : J ≌ K) {F : K ⥤ C} {c : Cocone F} (hc : IsUniversalColimit c) : IsUniversalColimit (c.whisker e.functor) := by intro F' c' α f e' hα H convert hc (c'.whisker e.inverse) (whiskerLeft e.inverse α ≫ (e.invFunIdAssoc F).hom) f ?_ ((hα.whiskerLeft _).comp (NatTrans.equifibered_of_isIso _)) ?_ using 1 · exact (IsColimit.whiskerEquivalenceEquiv e.symm).nonempty_congr · convert congr_arg (whiskerLeft e.inverse) e' ext simp · intro k rw [← Category.comp_id f] refine (H (e.inverse.obj k)).paste_vert ?_ have : IsIso (𝟙 (Cocone.whisker e.functor c).pt) := inferInstance exact IsPullback.of_vert_isIso ⟨by simp⟩ theorem IsUniversalColimit.whiskerEquivalence_iff {K : Type*} [Category K] (e : J ≌ K) {F : K ⥤ C} {c : Cocone F} : IsUniversalColimit (c.whisker e.functor) ↔ IsUniversalColimit c := ⟨fun hc ↦ ((hc.whiskerEquivalence e.symm).precompose_isIso (e.invFunIdAssoc F).inv).of_iso (Cocones.ext (Iso.refl _) (by simp)), IsUniversalColimit.whiskerEquivalence e⟩ theorem IsVanKampenColimit.whiskerEquivalence {K : Type*} [Category K] (e : J ≌ K) {F : K ⥤ C} {c : Cocone F} (hc : IsVanKampenColimit c) : IsVanKampenColimit (c.whisker e.functor) := by intro F' c' α f e' hα convert hc (c'.whisker e.inverse) (whiskerLeft e.inverse α ≫ (e.invFunIdAssoc F).hom) f ?_ ((hα.whiskerLeft _).comp (NatTrans.equifibered_of_isIso _)) using 1 · exact (IsColimit.whiskerEquivalenceEquiv e.symm).nonempty_congr · simp only [Functor.const_obj_obj, Functor.comp_obj, Cocone.whisker_pt, Cocone.whisker_ι, whiskerLeft_app, NatTrans.comp_app, Equivalence.invFunIdAssoc_hom_app, Functor.id_obj] constructor · intro H k rw [← Category.comp_id f] refine (H (e.inverse.obj k)).paste_vert ?_ have : IsIso (𝟙 (Cocone.whisker e.functor c).pt) := inferInstance exact IsPullback.of_vert_isIso ⟨by simp⟩ · intro H j have : α.app j = F'.map (e.unit.app _) ≫ α.app _ ≫ F.map (e.counit.app (e.functor.obj j)) := by simp [← Functor.map_comp] rw [← Category.id_comp f, this] refine IsPullback.paste_vert ?_ (H (e.functor.obj j)) exact IsPullback.of_vert_isIso ⟨by simp⟩ · ext k simpa using congr_app e' (e.inverse.obj k) theorem IsVanKampenColimit.whiskerEquivalence_iff {K : Type*} [Category K] (e : J ≌ K) {F : K ⥤ C} {c : Cocone F} : IsVanKampenColimit (c.whisker e.functor) ↔ IsVanKampenColimit c := ⟨fun hc ↦ ((hc.whiskerEquivalence e.symm).precompose_isIso (e.invFunIdAssoc F).inv).of_iso (Cocones.ext (Iso.refl _) (by simp)), IsVanKampenColimit.whiskerEquivalence e⟩ theorem isVanKampenColimit_of_evaluation [HasPullbacks D] [HasColimitsOfShape J D] (F : J ⥤ C ⥤ D) (c : Cocone F) (hc : ∀ x : C, IsVanKampenColimit (((evaluation C D).obj x).mapCocone c)) : IsVanKampenColimit c := by intro F' c' α f e hα have := fun x => hc x (((evaluation C D).obj x).mapCocone c') (whiskerRight α _) (((evaluation C D).obj x).map f) (by ext y dsimp exact NatTrans.congr_app (NatTrans.congr_app e y) x) (hα.whiskerRight _) constructor · rintro ⟨hc'⟩ j refine ⟨⟨(NatTrans.congr_app e j).symm⟩, ⟨evaluationJointlyReflectsLimits _ ?_⟩⟩ refine fun x => (isLimitMapConePullbackConeEquiv _ _).symm ?_ exact ((this x).mp ⟨PreservesColimit.preserves hc'⟩ _).isLimit · exact fun H => ⟨evaluationJointlyReflectsColimits _ fun x => ((this x).mpr fun j => (H j).map ((evaluation C D).obj x)).some⟩ #align category_theory.is_van_kampen_colimit_of_evaluation CategoryTheory.isVanKampenColimit_of_evaluation end Functor section reflective theorem IsUniversalColimit.map_reflective {Gl : C ⥤ D} {Gr : D ⥤ C} (adj : Gl ⊣ Gr) [Gr.Full] [Gr.Faithful] {F : J ⥤ D} {c : Cocone (F ⋙ Gr)} (H : IsUniversalColimit c) [∀ X (f : X ⟶ Gl.obj c.pt), HasPullback (Gr.map f) (adj.unit.app c.pt)] [∀ X (f : X ⟶ Gl.obj c.pt), PreservesLimit (cospan (Gr.map f) (adj.unit.app c.pt)) Gl] : IsUniversalColimit (Gl.mapCocone c) := by have := adj.rightAdjointPreservesLimits have : PreservesColimitsOfSize.{u', v'} Gl := adj.leftAdjointPreservesColimits intros F' c' α f h hα hc' have : HasPullback (Gl.map (Gr.map f)) (Gl.map (adj.unit.app c.pt)) := ⟨⟨_, isLimitPullbackConeMapOfIsLimit _ pullback.condition (IsPullback.of_hasPullback _ _).isLimit⟩⟩ let α' := α ≫ (Functor.associator _ _ _).hom ≫ whiskerLeft F adj.counit ≫ F.rightUnitor.hom have hα' : NatTrans.Equifibered α' := hα.comp (NatTrans.equifibered_of_isIso _) have hadj : ∀ X, Gl.map (adj.unit.app X) = inv (adj.counit.app _) := by intro X apply IsIso.eq_inv_of_inv_hom_id exact adj.left_triangle_components _ haveI : ∀ X, IsIso (Gl.map (adj.unit.app X)) := by simp_rw [hadj] infer_instance have hα'' : ∀ j, Gl.map (Gr.map <| α'.app j) = adj.counit.app _ ≫ α.app j := by intro j rw [← cancel_mono (adj.counit.app <| F.obj j)] dsimp [α'] simp only [Category.comp_id, Adjunction.counit_naturality_assoc, Category.id_comp, Adjunction.counit_naturality, Category.assoc, Functor.map_comp] have hc'' : ∀ j, α.app j ≫ Gl.map (c.ι.app j) = c'.ι.app j ≫ f := NatTrans.congr_app h let β := isoWhiskerLeft F' (asIso adj.counit) ≪≫ F'.rightUnitor let c'' : Cocone (F' ⋙ Gr) := by refine { pt := pullback (Gr.map f) (adj.unit.app _) ι := { app := fun j ↦ pullback.lift (Gr.map <| c'.ι.app j) (Gr.map (α'.app j) ≫ c.ι.app j) ?_ naturality := ?_ } } · rw [← Gr.map_comp, ← hc''] erw [← adj.unit_naturality] rw [Gl.map_comp, hα''] dsimp simp only [Category.assoc, Functor.map_comp, adj.right_triangle_components_assoc] · intros i j g dsimp [α'] ext all_goals simp only [Category.comp_id, Category.id_comp, Category.assoc, ← Functor.map_comp, pullback.lift_fst, pullback.lift_snd, ← Functor.map_comp_assoc] · congr 1 exact c'.w _ · rw [α.naturality_assoc] dsimp rw [adj.counit_naturality, ← Category.assoc, Gr.map_comp_assoc] congr 1 exact c.w _ let cf : (Cocones.precompose β.hom).obj c' ⟶ Gl.mapCocone c'' := by refine { hom := pullback.lift ?_ f ?_ ≫ (PreservesPullback.iso _ _ _).inv, w := ?_ } · exact inv <| adj.counit.app c'.pt · rw [IsIso.inv_comp_eq, ← adj.counit_naturality_assoc f, ← cancel_mono (adj.counit.app <| Gl.obj c.pt), Category.assoc, Category.assoc, adj.left_triangle_components] erw [Category.comp_id] rfl · intro j rw [← Category.assoc, Iso.comp_inv_eq] ext all_goals simp only [PreservesPullback.iso_hom_fst, PreservesPullback.iso_hom_snd, pullback.lift_fst, pullback.lift_snd, Category.assoc, Functor.mapCocone_ι_app, ← Gl.map_comp] · rw [IsIso.comp_inv_eq, adj.counit_naturality] dsimp [β] rw [Category.comp_id] · rw [Gl.map_comp, hα'', Category.assoc, hc''] dsimp [β] rw [Category.comp_id, Category.assoc] have : cf.hom ≫ (PreservesPullback.iso _ _ _).hom ≫ pullback.fst ≫ adj.counit.app _ = 𝟙 _ := by simp only [IsIso.inv_hom_id, Iso.inv_hom_id_assoc, Category.assoc, pullback.lift_fst_assoc] have : IsIso cf := by apply @Cocones.cocone_iso_of_hom_iso (i := ?_) rw [← IsIso.eq_comp_inv] at this rw [this] infer_instance have ⟨Hc''⟩ := H c'' (whiskerRight α' Gr) pullback.snd ?_ (hα'.whiskerRight Gr) ?_ · exact ⟨IsColimit.precomposeHomEquiv β c' <| (isColimitOfPreserves Gl Hc'').ofIsoColimit (asIso cf).symm⟩ · ext j dsimp simp only [Category.comp_id, Category.id_comp, Category.assoc, Functor.map_comp, pullback.lift_snd] · intro j apply IsPullback.of_right _ _ (IsPullback.of_hasPullback _ _) · dsimp [α'] simp only [Category.comp_id, Category.id_comp, Category.assoc, Functor.map_comp, pullback.lift_fst] rw [← Category.comp_id (Gr.map f)] refine ((hc' j).map Gr).paste_vert (IsPullback.of_vert_isIso ⟨?_⟩) rw [← adj.unit_naturality, Category.comp_id, ← Category.assoc, ← Category.id_comp (Gr.map ((Gl.mapCocone c).ι.app j))] congr 1 rw [← cancel_mono (Gr.map (adj.counit.app (F.obj j)))] dsimp simp only [Category.comp_id, Adjunction.right_triangle_components, Category.id_comp, Category.assoc] · dsimp simp only [Category.comp_id, Category.id_comp, Category.assoc, Functor.map_comp, pullback.lift_snd] theorem IsVanKampenColimit.map_reflective [HasColimitsOfShape J C] {Gl : C ⥤ D} {Gr : D ⥤ C} (adj : Gl ⊣ Gr) [Gr.Full] [Gr.Faithful] {F : J ⥤ D} {c : Cocone (F ⋙ Gr)} (H : IsVanKampenColimit c) [∀ X (f : X ⟶ Gl.obj c.pt), HasPullback (Gr.map f) (adj.unit.app c.pt)] [∀ X (f : X ⟶ Gl.obj c.pt), PreservesLimit (cospan (Gr.map f) (adj.unit.app c.pt)) Gl] [∀ X i (f : X ⟶ c.pt), PreservesLimit (cospan f (c.ι.app i)) Gl] : IsVanKampenColimit (Gl.mapCocone c) := by have := adj.rightAdjointPreservesLimits have : PreservesColimitsOfSize.{u', v'} Gl := adj.leftAdjointPreservesColimits intro F' c' α f h hα refine ⟨?_, H.isUniversal.map_reflective adj c' α f h hα⟩ intro ⟨hc'⟩ j let α' := α ≫ (Functor.associator _ _ _).hom ≫ whiskerLeft F adj.counit ≫ F.rightUnitor.hom have hα' : NatTrans.Equifibered α' := hα.comp (NatTrans.equifibered_of_isIso _) have hα'' : ∀ j, Gl.map (Gr.map <| α'.app j) = adj.counit.app _ ≫ α.app j := by intro j rw [← cancel_mono (adj.counit.app <| F.obj j)] dsimp [α'] simp only [Category.comp_id, Adjunction.counit_naturality_assoc, Category.id_comp, Adjunction.counit_naturality, Category.assoc, Functor.map_comp] let β := isoWhiskerLeft F' (asIso adj.counit) ≪≫ F'.rightUnitor let hl := (IsColimit.precomposeHomEquiv β c').symm hc' let hr := isColimitOfPreserves Gl (colimit.isColimit <| F' ⋙ Gr) have : α.app j = β.inv.app _ ≫ Gl.map (Gr.map <| α'.app j) := by rw [hα''] simp [β] rw [this] have : f = (hl.coconePointUniqueUpToIso hr).hom ≫ Gl.map (colimit.desc _ ⟨_, whiskerRight α' Gr ≫ c.2⟩) := by symm convert @IsColimit.coconePointUniqueUpToIso_hom_desc _ _ _ _ ((F' ⋙ Gr) ⋙ Gl) (Gl.mapCocone ⟨_, (whiskerRight α' Gr ≫ c.2 : _)⟩) _ _ hl hr using 2 · apply hr.hom_ext intro j rw [hr.fac, Functor.mapCocone_ι_app, ← Gl.map_comp, colimit.cocone_ι, colimit.ι_desc] rfl · clear_value α' apply hl.hom_ext intro j rw [hl.fac] dsimp [β] simp only [Category.comp_id, hα'', Category.assoc, Gl.map_comp] congr 1 exact (NatTrans.congr_app h j).symm rw [this] have := ((H (colimit.cocone <| F' ⋙ Gr) (whiskerRight α' Gr) (colimit.desc _ ⟨_, whiskerRight α' Gr ≫ c.2⟩) ?_ (hα'.whiskerRight Gr)).mp ⟨(getColimitCocone <| F' ⋙ Gr).2⟩ j).map Gl · convert IsPullback.paste_vert _ this refine IsPullback.of_vert_isIso ⟨?_⟩ rw [← IsIso.inv_comp_eq, ← Category.assoc, NatIso.inv_inv_app] exact IsColimit.comp_coconePointUniqueUpToIso_hom hl hr _ · clear_value α' ext j simp end reflective section Initial theorem hasStrictInitial_of_isUniversal [HasInitial C] (H : IsUniversalColimit (BinaryCofan.mk (𝟙 (⊥_ C)) (𝟙 (⊥_ C)))) : HasStrictInitialObjects C := hasStrictInitialObjects_of_initial_is_strict (by intro A f suffices IsColimit (BinaryCofan.mk (𝟙 A) (𝟙 A)) by obtain ⟨l, h₁, h₂⟩ := Limits.BinaryCofan.IsColimit.desc' this (f ≫ initial.to A) (𝟙 A) rcases(Category.id_comp _).symm.trans h₂ with rfl exact ⟨⟨_, ((Category.id_comp _).symm.trans h₁).symm, initialIsInitial.hom_ext _ _⟩⟩ refine (H (BinaryCofan.mk (𝟙 _) (𝟙 _)) (mapPair f f) f (by ext ⟨⟨⟩⟩ <;> dsimp <;> simp) (mapPair_equifibered _) ?_).some rintro ⟨⟨⟩⟩ <;> dsimp <;> exact IsPullback.of_horiz_isIso ⟨(Category.id_comp _).trans (Category.comp_id _).symm⟩) #align category_theory.has_strict_initial_of_is_universal CategoryTheory.hasStrictInitial_of_isUniversal theorem isVanKampenColimit_of_isEmpty [HasStrictInitialObjects C] [IsEmpty J] {F : J ⥤ C} (c : Cocone F) (hc : IsColimit c) : IsVanKampenColimit c := by have : IsInitial c.pt := by have := (IsColimit.precomposeInvEquiv (Functor.uniqueFromEmpty _) _).symm (hc.whiskerEquivalence (equivalenceOfIsEmpty (Discrete PEmpty.{1}) J)) exact IsColimit.ofIsoColimit this (Cocones.ext (Iso.refl c.pt) (fun {X} ↦ isEmptyElim X)) replace this := IsInitial.isVanKampenColimit this apply (IsVanKampenColimit.whiskerEquivalence_iff (equivalenceOfIsEmpty (Discrete PEmpty.{1}) J)).mp exact (this.precompose_isIso (Functor.uniqueFromEmpty ((equivalenceOfIsEmpty (Discrete PEmpty.{1}) J).functor ⋙ F)).hom).of_iso (Cocones.ext (Iso.refl _) (by simp)) end Initial section BinaryCoproduct variable {X Y : C} theorem BinaryCofan.isVanKampen_iff (c : BinaryCofan X Y) : IsVanKampenColimit c ↔ ∀ {X' Y' : C} (c' : BinaryCofan X' Y') (αX : X' ⟶ X) (αY : Y' ⟶ Y) (f : c'.pt ⟶ c.pt) (_ : αX ≫ c.inl = c'.inl ≫ f) (_ : αY ≫ c.inr = c'.inr ≫ f), Nonempty (IsColimit c') ↔ IsPullback c'.inl αX f c.inl ∧ IsPullback c'.inr αY f c.inr := by constructor · introv H hαX hαY rw [H c' (mapPair αX αY) f (by ext ⟨⟨⟩⟩ <;> dsimp <;> assumption) (mapPair_equifibered _)] constructor · intro H exact ⟨H _, H _⟩ · rintro H ⟨⟨⟩⟩ exacts [H.1, H.2] · introv H F' hα h let X' := F'.obj ⟨WalkingPair.left⟩ let Y' := F'.obj ⟨WalkingPair.right⟩ have : F' = pair X' Y' := by apply Functor.hext · rintro ⟨⟨⟩⟩ <;> rfl · rintro ⟨⟨⟩⟩ ⟨j⟩ ⟨⟨rfl : _ = j⟩⟩ <;> simp clear_value X' Y' subst this change BinaryCofan X' Y' at c' rw [H c' _ _ _ (NatTrans.congr_app hα ⟨WalkingPair.left⟩) (NatTrans.congr_app hα ⟨WalkingPair.right⟩)] constructor · rintro H ⟨⟨⟩⟩ exacts [H.1, H.2] · intro H exact ⟨H _, H _⟩ #align category_theory.binary_cofan.is_van_kampen_iff CategoryTheory.BinaryCofan.isVanKampen_iff theorem BinaryCofan.isVanKampen_mk {X Y : C} (c : BinaryCofan X Y) (cofans : ∀ X Y : C, BinaryCofan X Y) (colimits : ∀ X Y, IsColimit (cofans X Y)) (cones : ∀ {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z), PullbackCone f g) (limits : ∀ {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z), IsLimit (cones f g)) (h₁ : ∀ {X' Y' : C} (αX : X' ⟶ X) (αY : Y' ⟶ Y) (f : (cofans X' Y').pt ⟶ c.pt) (_ : αX ≫ c.inl = (cofans X' Y').inl ≫ f) (_ : αY ≫ c.inr = (cofans X' Y').inr ≫ f), IsPullback (cofans X' Y').inl αX f c.inl ∧ IsPullback (cofans X' Y').inr αY f c.inr) (h₂ : ∀ {Z : C} (f : Z ⟶ c.pt), IsColimit (BinaryCofan.mk (cones f c.inl).fst (cones f c.inr).fst)) : IsVanKampenColimit c := by rw [BinaryCofan.isVanKampen_iff] introv hX hY constructor · rintro ⟨h⟩ let e := h.coconePointUniqueUpToIso (colimits _ _) obtain ⟨hl, hr⟩ := h₁ αX αY (e.inv ≫ f) (by simp [e, hX]) (by simp [e, hY]) constructor · rw [← Category.id_comp αX, ← Iso.hom_inv_id_assoc e f] haveI : IsIso (𝟙 X') := inferInstance have : c'.inl ≫ e.hom = 𝟙 X' ≫ (cofans X' Y').inl := by dsimp [e] simp exact (IsPullback.of_vert_isIso ⟨this⟩).paste_vert hl · rw [← Category.id_comp αY, ← Iso.hom_inv_id_assoc e f] haveI : IsIso (𝟙 Y') := inferInstance have : c'.inr ≫ e.hom = 𝟙 Y' ≫ (cofans X' Y').inr := by dsimp [e] simp exact (IsPullback.of_vert_isIso ⟨this⟩).paste_vert hr · rintro ⟨H₁, H₂⟩ refine ⟨IsColimit.ofIsoColimit ?_ <| (isoBinaryCofanMk _).symm⟩ let e₁ : X' ≅ _ := H₁.isLimit.conePointUniqueUpToIso (limits _ _) let e₂ : Y' ≅ _ := H₂.isLimit.conePointUniqueUpToIso (limits _ _) have he₁ : c'.inl = e₁.hom ≫ (cones f c.inl).fst := by simp [e₁] have he₂ : c'.inr = e₂.hom ≫ (cones f c.inr).fst := by simp [e₂] rw [he₁, he₂] apply BinaryCofan.isColimitCompRightIso (BinaryCofan.mk _ _) apply BinaryCofan.isColimitCompLeftIso (BinaryCofan.mk _ _) exact h₂ f #align category_theory.binary_cofan.is_van_kampen_mk CategoryTheory.BinaryCofan.isVanKampen_mk theorem BinaryCofan.mono_inr_of_isVanKampen [HasInitial C] {X Y : C} {c : BinaryCofan X Y} (h : IsVanKampenColimit c) : Mono c.inr := by refine PullbackCone.mono_of_isLimitMkIdId _ (IsPullback.isLimit ?_) refine (h (BinaryCofan.mk (initial.to Y) (𝟙 Y)) (mapPair (initial.to X) (𝟙 Y)) c.inr ?_ (mapPair_equifibered _)).mp ⟨?_⟩ ⟨WalkingPair.right⟩ · ext ⟨⟨⟩⟩ <;> dsimp; simp · exact ((BinaryCofan.isColimit_iff_isIso_inr initialIsInitial _).mpr (by dsimp infer_instance)).some #align category_theory.binary_cofan.mono_inr_of_is_van_kampen CategoryTheory.BinaryCofan.mono_inr_of_isVanKampen theorem BinaryCofan.isPullback_initial_to_of_isVanKampen [HasInitial C] {c : BinaryCofan X Y} (h : IsVanKampenColimit c) : IsPullback (initial.to _) (initial.to _) c.inl c.inr := by refine ((h (BinaryCofan.mk (initial.to Y) (𝟙 Y)) (mapPair (initial.to X) (𝟙 Y)) c.inr ?_ (mapPair_equifibered _)).mp ⟨?_⟩ ⟨WalkingPair.left⟩).flip · ext ⟨⟨⟩⟩ <;> dsimp; simp · exact ((BinaryCofan.isColimit_iff_isIso_inr initialIsInitial _).mpr (by dsimp infer_instance)).some #align category_theory.binary_cofan.is_pullback_initial_to_of_is_van_kampen CategoryTheory.BinaryCofan.isPullback_initial_to_of_isVanKampen end BinaryCoproduct section FiniteCoproducts theorem isUniversalColimit_extendCofan {n : ℕ} (f : Fin (n + 1) → C) {c₁ : Cofan fun i : Fin n ↦ f i.succ} {c₂ : BinaryCofan (f 0) c₁.pt} (t₁ : IsUniversalColimit c₁) (t₂ : IsUniversalColimit c₂) [∀ {Z} (i : Z ⟶ c₂.pt), HasPullback c₂.inr i] : IsUniversalColimit (extendCofan c₁ c₂) := by intro F c α i e hα H let F' : Fin (n + 1) → C := F.obj ∘ Discrete.mk have : F = Discrete.functor F' := by apply Functor.hext · exact fun i ↦ rfl · rintro ⟨i⟩ ⟨j⟩ ⟨⟨rfl : i = j⟩⟩ simp [F'] have t₁' := @t₁ (Discrete.functor (fun j ↦ F.obj ⟨j.succ⟩)) (Cofan.mk (pullback c₂.inr i) fun j ↦ pullback.lift (α.app _ ≫ c₁.inj _) (c.ι.app _) ?_) (Discrete.natTrans fun i ↦ α.app _) pullback.fst ?_ (NatTrans.equifibered_of_discrete _) ?_ rotate_left · simpa only [Functor.const_obj_obj, pair_obj_right, Discrete.functor_obj, Category.assoc, extendCofan_pt, Functor.const_obj_obj, NatTrans.comp_app, extendCofan_ι_app, Fin.cases_succ, Functor.const_map_app] using congr_app e ⟨j.succ⟩ · ext j dsimp simp only [limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app, Cofan.inj] · intro j simp only [pair_obj_right, Functor.const_obj_obj, Discrete.functor_obj, id_eq, extendCofan_pt, eq_mpr_eq_cast, Cofan.mk_pt, Cofan.mk_ι_app, Discrete.natTrans_app] refine IsPullback.of_right ?_ ?_ (IsPullback.of_hasPullback (BinaryCofan.inr c₂) i).flip · simp only [Functor.const_obj_obj, pair_obj_right, limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app] exact H _ · simp only [limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app, Cofan.inj] obtain ⟨H₁⟩ := t₁' have t₂' := @t₂ (pair (F.obj ⟨0⟩) (pullback c₂.inr i)) (BinaryCofan.mk (c.ι.app ⟨0⟩) pullback.snd) (mapPair (α.app _) pullback.fst) i ?_ (mapPair_equifibered _) ?_ rotate_left · ext ⟨⟨⟩⟩ · simpa [mapPair] using congr_app e ⟨0⟩ · simpa using pullback.condition · rintro ⟨⟨⟩⟩ · simp only [pair_obj_right, Functor.const_obj_obj, pair_obj_left, BinaryCofan.mk_pt, BinaryCofan.ι_app_left, BinaryCofan.mk_inl, mapPair_left] exact H ⟨0⟩ · simp only [pair_obj_right, Functor.const_obj_obj, BinaryCofan.mk_pt, BinaryCofan.ι_app_right, BinaryCofan.mk_inr, mapPair_right] exact (IsPullback.of_hasPullback (BinaryCofan.inr c₂) i).flip obtain ⟨H₂⟩ := t₂' clear_value F' subst this refine ⟨IsColimit.ofIsoColimit (extendCofanIsColimit (fun i ↦ (Discrete.functor F').obj ⟨i⟩) H₁ H₂) <| Cocones.ext (Iso.refl _) ?_⟩ dsimp rintro ⟨j⟩ simp only [Discrete.functor_obj, limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app, Category.comp_id] induction' j using Fin.inductionOn · simp only [Fin.cases_zero] · simp only [Fin.cases_succ] theorem isVanKampenColimit_extendCofan {n : ℕ} (f : Fin (n + 1) → C) {c₁ : Cofan fun i : Fin n ↦ f i.succ} {c₂ : BinaryCofan (f 0) c₁.pt} (t₁ : IsVanKampenColimit c₁) (t₂ : IsVanKampenColimit c₂) [∀ {Z} (i : Z ⟶ c₂.pt), HasPullback c₂.inr i] [HasFiniteCoproducts C] : IsVanKampenColimit (extendCofan c₁ c₂) := by intro F c α i e hα refine ⟨?_, isUniversalColimit_extendCofan f t₁.isUniversal t₂.isUniversal c α i e hα⟩ intro ⟨Hc⟩ ⟨j⟩ have t₂' := (@t₂ (pair (F.obj ⟨0⟩) (∐ fun (j : Fin n) ↦ F.obj ⟨j.succ⟩)) (BinaryCofan.mk (P := c.pt) (c.ι.app _) (Sigma.desc fun b ↦ c.ι.app _)) (mapPair (α.app _) (Sigma.desc fun b ↦ α.app _ ≫ c₁.inj _)) i ?_ (mapPair_equifibered _)).mp ⟨?_⟩ rotate_left · ext ⟨⟨⟩⟩ · simpa only [pair_obj_left, Functor.const_obj_obj, pair_obj_right, Discrete.functor_obj, NatTrans.comp_app, mapPair_left, BinaryCofan.ι_app_left, BinaryCofan.mk_pt, BinaryCofan.mk_inl, Functor.const_map_app, extendCofan_pt, extendCofan_ι_app, Fin.cases_zero] using congr_app e ⟨0⟩ · dsimp ext j simpa only [colimit.ι_desc_assoc, Discrete.functor_obj, Cofan.mk_pt, Cofan.mk_ι_app, Category.assoc, extendCofan_pt, Functor.const_obj_obj, NatTrans.comp_app, extendCofan_ι_app, Fin.cases_succ, Functor.const_map_app] using congr_app e ⟨j.succ⟩ · let F' : Fin (n + 1) → C := F.obj ∘ Discrete.mk have : F = Discrete.functor F' := by apply Functor.hext · exact fun i ↦ rfl · rintro ⟨i⟩ ⟨j⟩ ⟨⟨rfl : i = j⟩⟩ simp [F'] clear_value F' subst this apply BinaryCofan.IsColimit.mk _ (fun {T} f₁ f₂ ↦ Hc.desc (Cofan.mk T (Fin.cases f₁ (fun i ↦ Sigma.ι (fun (j : Fin n) ↦ (Discrete.functor F').obj ⟨j.succ⟩) _ ≫ f₂)))) · intro T f₁ f₂ simp only [Discrete.functor_obj, pair_obj_left, BinaryCofan.mk_pt, Functor.const_obj_obj, BinaryCofan.ι_app_left, BinaryCofan.mk_inl, IsColimit.fac, Cofan.mk_pt, Cofan.mk_ι_app, Fin.cases_zero] · intro T f₁ f₂ simp only [Discrete.functor_obj, pair_obj_right, BinaryCofan.mk_pt, Functor.const_obj_obj, BinaryCofan.ι_app_right, BinaryCofan.mk_inr] ext j simp only [colimit.ι_desc_assoc, Discrete.functor_obj, Cofan.mk_pt, Cofan.mk_ι_app, IsColimit.fac, Fin.cases_succ] · intro T f₁ f₂ f₃ m₁ m₂ simp at m₁ m₂ ⊢ refine Hc.uniq (Cofan.mk T (Fin.cases f₁ (fun i ↦ Sigma.ι (fun (j : Fin n) ↦ (Discrete.functor F').obj ⟨j.succ⟩) _ ≫ f₂))) _ ?_ intro ⟨j⟩ simp only [Discrete.functor_obj, Cofan.mk_pt, Functor.const_obj_obj, Cofan.mk_ι_app] induction' j using Fin.inductionOn with j _ · simp only [Fin.cases_zero, m₁] · simp only [← m₂, colimit.ι_desc_assoc, Discrete.functor_obj, Cofan.mk_pt, Cofan.mk_ι_app, Fin.cases_succ] induction' j using Fin.inductionOn with j _ · exact t₂' ⟨WalkingPair.left⟩ · have t₁' := (@t₁ (Discrete.functor (fun j ↦ F.obj ⟨j.succ⟩)) (Cofan.mk _ _) (Discrete.natTrans fun i ↦ α.app _) (Sigma.desc (fun j ↦ α.app _ ≫ c₁.inj _)) ?_ (NatTrans.equifibered_of_discrete _)).mp ⟨coproductIsCoproduct _⟩ ⟨j⟩ rotate_left · ext ⟨j⟩ dsimp erw [colimit.ι_desc] -- Why? rfl simpa [Functor.const_obj_obj, Discrete.functor_obj, extendCofan_pt, extendCofan_ι_app, Fin.cases_succ, BinaryCofan.mk_pt, colimit.cocone_x, Cofan.mk_pt, Cofan.mk_ι_app, BinaryCofan.ι_app_right, BinaryCofan.mk_inr, colimit.ι_desc, Discrete.natTrans_app] using t₁'.paste_horiz (t₂' ⟨WalkingPair.right⟩) theorem isPullback_of_cofan_isVanKampen [HasInitial C] {ι : Type*} {X : ι → C} {c : Cofan X} (hc : IsVanKampenColimit c) (i j : ι) [DecidableEq ι] : IsPullback (P := (if j = i then X i else ⊥_ C)) (if h : j = i then eqToHom (if_pos h) else eqToHom (if_neg h) ≫ initial.to (X i)) (if h : j = i then eqToHom ((if_pos h).trans (congr_arg X h.symm)) else eqToHom (if_neg h) ≫ initial.to (X j)) (Cofan.inj c i) (Cofan.inj c j) := by refine (hc (Cofan.mk (X i) (f := fun k ↦ if k = i then X i else ⊥_ C) (fun k ↦ if h : k = i then (eqToHom <| if_pos h) else (eqToHom <| if_neg h) ≫ initial.to _)) (Discrete.natTrans (fun k ↦ if h : k.1 = i then (eqToHom <| (if_pos h).trans (congr_arg X h.symm)) else (eqToHom <| if_neg h) ≫ initial.to _)) (c.inj i) ?_ (NatTrans.equifibered_of_discrete _)).mp ⟨?_⟩ ⟨j⟩ · ext ⟨k⟩ simp only [Discrete.functor_obj, Functor.const_obj_obj, NatTrans.comp_app, Discrete.natTrans_app, Cofan.mk_pt, Cofan.mk_ι_app, Functor.const_map_app] split · subst ‹k = i›; rfl · simp · refine mkCofanColimit _ (fun t ↦ (eqToHom (if_pos rfl).symm) ≫ t.inj i) ?_ ?_ · intro t j simp only [Cofan.mk_pt, cofan_mk_inj] split · subst ‹j = i›; simp · rw [Category.assoc, ← IsIso.eq_inv_comp] exact initialIsInitial.hom_ext _ _ · intro t m hm simp [← hm i] theorem isPullback_initial_to_of_cofan_isVanKampen [HasInitial C] {ι : Type*} {F : Discrete ι ⥤ C} {c : Cocone F} (hc : IsVanKampenColimit c) (i j : Discrete ι) (hi : i ≠ j) : IsPullback (initial.to _) (initial.to _) (c.ι.app i) (c.ι.app j) := by classical let f : ι → C := F.obj ∘ Discrete.mk have : F = Discrete.functor f := Functor.hext (fun i ↦ rfl) (by rintro ⟨i⟩ ⟨j⟩ ⟨⟨rfl : i = j⟩⟩; simp [f]) clear_value f subst this have : ∀ i, Subsingleton (⊥_ C ⟶ (Discrete.functor f).obj i) := inferInstance convert isPullback_of_cofan_isVanKampen hc i.as j.as exact (if_neg (mt (Discrete.ext _ _) hi.symm)).symm
Mathlib/CategoryTheory/Limits/VanKampen.lean
770
784
theorem mono_of_cofan_isVanKampen [HasInitial C] {ι : Type*} {F : Discrete ι ⥤ C} {c : Cocone F} (hc : IsVanKampenColimit c) (i : Discrete ι) : Mono (c.ι.app i) := by
classical let f : ι → C := F.obj ∘ Discrete.mk have : F = Discrete.functor f := Functor.hext (fun i ↦ rfl) (by rintro ⟨i⟩ ⟨j⟩ ⟨⟨rfl : i = j⟩⟩; simp [f]) clear_value f subst this refine PullbackCone.mono_of_isLimitMkIdId _ (IsPullback.isLimit ?_) nth_rw 1 [← Category.id_comp (c.ι.app i)] convert IsPullback.paste_vert _ (isPullback_of_cofan_isVanKampen hc i.as i.as) swap · exact (eqToHom (if_pos rfl).symm) · simp · exact IsPullback.of_vert_isIso ⟨by simp⟩
/- Copyright (c) 2022 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.Analysis.Fourier.FourierTransform import Mathlib.Analysis.InnerProductSpace.Dual import Mathlib.Analysis.InnerProductSpace.EuclideanDist import Mathlib.MeasureTheory.Function.ContinuousMapDense import Mathlib.MeasureTheory.Group.Integral import Mathlib.MeasureTheory.Integral.SetIntegral import Mathlib.MeasureTheory.Measure.Haar.NormedSpace import Mathlib.Topology.EMetricSpace.Paracompact import Mathlib.MeasureTheory.Measure.Haar.Unique #align_import analysis.fourier.riemann_lebesgue_lemma from "leanprover-community/mathlib"@"fd5edc43dc4f10b85abfe544b88f82cf13c5f844" /-! # The Riemann-Lebesgue Lemma In this file we prove the Riemann-Lebesgue lemma, for functions on finite-dimensional real vector spaces `V`: if `f` is a function on `V` (valued in a complete normed space `E`), then the Fourier transform of `f`, viewed as a function on the dual space of `V`, tends to 0 along the cocompact filter. Here the Fourier transform is defined by `fun w : V →L[ℝ] ℝ ↦ ∫ (v : V), exp (↑(2 * π * w v) * I) • f v`. This is true for arbitrary functions, but is only interesting for `L¹` functions (if `f` is not integrable then the integral is zero for all `w`). This is proved first for continuous compactly-supported functions on inner-product spaces; then we pass to arbitrary functions using the density of continuous compactly-supported functions in `L¹` space. Finally we generalise from inner-product spaces to arbitrary finite-dimensional spaces, by choosing a continuous linear equivalence to an inner-product space. ## Main results - `tendsto_integral_exp_inner_smul_cocompact` : for `V` a finite-dimensional real inner product space and `f : V → E`, the function `fun w : V ↦ ∫ v : V, exp (2 * π * ⟪w, v⟫ * I) • f v` tends to 0 along `cocompact V`. - `tendsto_integral_exp_smul_cocompact` : for `V` a finite-dimensional real vector space (endowed with its unique Hausdorff topological vector space structure), and `W` the dual of `V`, the function `fun w : W ↦ ∫ v : V, exp (2 * π * w v * I) • f v` tends to along `cocompact W`. - `Real.tendsto_integral_exp_smul_cocompact`: special case of functions on `ℝ`. - `Real.zero_at_infty_fourierIntegral` and `Real.zero_at_infty_vector_fourierIntegral`: reformulations explicitly using the Fourier integral. -/ noncomputable section open MeasureTheory Filter Complex Set FiniteDimensional open scoped Filter Topology Real ENNReal FourierTransform RealInnerProductSpace NNReal variable {E V : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f : V → E} section InnerProductSpace variable [NormedAddCommGroup V] [MeasurableSpace V] [BorelSpace V] [InnerProductSpace ℝ V] [FiniteDimensional ℝ V] #align fourier_integrand_integrable Real.fourierIntegral_convergent_iff variable [CompleteSpace E] local notation3 "i" => fun (w : V) => (1 / (2 * ‖w‖ ^ 2) : ℝ) • w /-- Shifting `f` by `(1 / (2 * ‖w‖ ^ 2)) • w` negates the integral in the Riemann-Lebesgue lemma. -/ theorem fourierIntegral_half_period_translate {w : V} (hw : w ≠ 0) : (∫ v : V, 𝐞 (-⟪v, w⟫) • f (v + i w)) = -∫ v : V, 𝐞 (-⟪v, w⟫) • f v := by have hiw : ⟪i w, w⟫ = 1 / 2 := by rw [inner_smul_left, inner_self_eq_norm_sq_to_K, RCLike.ofReal_real_eq_id, id, RCLike.conj_to_real, ← div_div, div_mul_cancel₀] rwa [Ne, sq_eq_zero_iff, norm_eq_zero] have : (fun v : V => 𝐞 (-⟪v, w⟫) • f (v + i w)) = fun v : V => (fun x : V => -(𝐞 (-⟪x, w⟫) • f x)) (v + i w) := by ext1 v simp_rw [inner_add_left, hiw, Submonoid.smul_def, Real.fourierChar_apply, neg_add, mul_add, ofReal_add, add_mul, exp_add] have : 2 * π * -(1 / 2) = -π := by field_simp; ring rw [this, ofReal_neg, neg_mul, exp_neg, exp_pi_mul_I, inv_neg, inv_one, mul_neg_one, neg_smul, neg_neg] rw [this] -- Porting note: -- The next three lines had just been -- rw [integral_add_right_eq_self (fun (x : V) ↦ -(𝐞[-⟪x, w⟫]) • f x) -- ((fun w ↦ (1 / (2 * ‖w‖ ^ (2 : ℕ))) • w) w)] -- Unfortunately now we need to specify `volume`. have := integral_add_right_eq_self (μ := volume) (fun (x : V) ↦ -(𝐞 (-⟪x, w⟫) • f x)) ((fun w ↦ (1 / (2 * ‖w‖ ^ (2 : ℕ))) • w) w) rw [this] simp only [neg_smul, integral_neg] #align fourier_integral_half_period_translate fourierIntegral_half_period_translate /-- Rewrite the Fourier integral in a form that allows us to use uniform continuity. -/ theorem fourierIntegral_eq_half_sub_half_period_translate {w : V} (hw : w ≠ 0) (hf : Integrable f) : ∫ v : V, 𝐞 (-⟪v, w⟫) • f v = (1 / (2 : ℂ)) • ∫ v : V, 𝐞 (-⟪v, w⟫) • (f v - f (v + i w)) := by simp_rw [smul_sub] rw [integral_sub, fourierIntegral_half_period_translate hw, sub_eq_add_neg, neg_neg, ← two_smul ℂ _, ← @smul_assoc _ _ _ _ _ _ (IsScalarTower.left ℂ), smul_eq_mul] · norm_num exacts [(Real.fourierIntegral_convergent_iff w).2 hf, (Real.fourierIntegral_convergent_iff w).2 (hf.comp_add_right _)] #align fourier_integral_eq_half_sub_half_period_translate fourierIntegral_eq_half_sub_half_period_translate /-- Riemann-Lebesgue Lemma for continuous and compactly-supported functions: the integral `∫ v, exp (-2 * π * ⟪w, v⟫ * I) • f v` tends to 0 wrt `cocompact V`. Note that this is primarily of interest as a preparatory step for the more general result `tendsto_integral_exp_inner_smul_cocompact` in which `f` can be arbitrary. -/ theorem tendsto_integral_exp_inner_smul_cocompact_of_continuous_compact_support (hf1 : Continuous f) (hf2 : HasCompactSupport f) : Tendsto (fun w : V => ∫ v : V, 𝐞 (-⟪v, w⟫) • f v) (cocompact V) (𝓝 0) := by refine NormedAddCommGroup.tendsto_nhds_zero.mpr fun ε hε => ?_ suffices ∃ T : ℝ, ∀ w : V, T ≤ ‖w‖ → ‖∫ v : V, 𝐞 (-⟪v, w⟫) • f v‖ < ε by simp_rw [← comap_dist_left_atTop_eq_cocompact (0 : V), eventually_comap, eventually_atTop, dist_eq_norm', sub_zero] exact let ⟨T, hT⟩ := this ⟨T, fun b hb v hv => hT v (hv.symm ▸ hb)⟩ obtain ⟨R, -, hR_bd⟩ : ∃ R : ℝ, 0 < R ∧ ∀ x : V, R ≤ ‖x‖ → f x = 0 := hf2.exists_pos_le_norm let A := {v : V | ‖v‖ ≤ R + 1} have mA : MeasurableSet A := by suffices A = Metric.closedBall (0 : V) (R + 1) by rw [this] exact Metric.isClosed_ball.measurableSet simp_rw [Metric.closedBall, dist_eq_norm, sub_zero] obtain ⟨B, hB_pos, hB_vol⟩ : ∃ B : ℝ≥0, 0 < B ∧ volume A ≤ B := by have hc : IsCompact A := by simpa only [Metric.closedBall, dist_eq_norm, sub_zero] using isCompact_closedBall (0 : V) _ let B₀ := volume A replace hc : B₀ < ⊤ := hc.measure_lt_top refine ⟨B₀.toNNReal + 1, add_pos_of_nonneg_of_pos B₀.toNNReal.coe_nonneg one_pos, ?_⟩ rw [ENNReal.coe_add, ENNReal.coe_one, ENNReal.coe_toNNReal hc.ne] exact le_self_add --* Use uniform continuity to choose δ such that `‖x - y‖ < δ` implies `‖f x - f y‖ < ε / B`. obtain ⟨δ, hδ1, hδ2⟩ := Metric.uniformContinuous_iff.mp (hf2.uniformContinuous_of_continuous hf1) (ε / B) (div_pos hε hB_pos) refine ⟨1 / 2 + 1 / (2 * δ), fun w hw_bd => ?_⟩ have hw_ne : w ≠ 0 := by contrapose! hw_bd; rw [hw_bd, norm_zero] exact add_pos one_half_pos (one_div_pos.mpr <| mul_pos two_pos hδ1) have hw'_nm : ‖i w‖ = 1 / (2 * ‖w‖) := by rw [norm_smul, norm_div, Real.norm_of_nonneg (mul_nonneg two_pos.le <| sq_nonneg _), norm_one, sq, ← div_div, ← div_div, ← div_div, div_mul_cancel₀ _ (norm_eq_zero.not.mpr hw_ne)] --* Rewrite integral in terms of `f v - f (v + w')`. have : ‖(1 / 2 : ℂ)‖ = 2⁻¹ := by norm_num rw [fourierIntegral_eq_half_sub_half_period_translate hw_ne (hf1.integrable_of_hasCompactSupport hf2), norm_smul, this, inv_mul_eq_div, div_lt_iff' two_pos] refine lt_of_le_of_lt (norm_integral_le_integral_norm _) ?_ simp_rw [norm_circle_smul] --* Show integral can be taken over A only. have int_A : ∫ v : V, ‖f v - f (v + i w)‖ = ∫ v in A, ‖f v - f (v + i w)‖ := by refine (setIntegral_eq_integral_of_forall_compl_eq_zero fun v hv => ?_).symm dsimp only [A] at hv simp only [mem_setOf, not_le] at hv rw [hR_bd v _, hR_bd (v + i w) _, sub_zero, norm_zero] · rw [← sub_neg_eq_add] refine le_trans ?_ (norm_sub_norm_le _ _) rw [le_sub_iff_add_le, norm_neg] refine le_trans ?_ hv.le rw [add_le_add_iff_left, hw'_nm, ← div_div] refine (div_le_one <| norm_pos_iff.mpr hw_ne).mpr ?_ refine le_trans (le_add_of_nonneg_right <| one_div_nonneg.mpr <| ?_) hw_bd exact (mul_pos (zero_lt_two' ℝ) hδ1).le · exact (le_add_of_nonneg_right zero_le_one).trans hv.le rw [int_A]; clear int_A --* Bound integral using fact that `‖f v - f (v + w')‖` is small. have bdA : ∀ v : V, v ∈ A → ‖‖f v - f (v + i w)‖‖ ≤ ε / B := by simp_rw [norm_norm] simp_rw [dist_eq_norm] at hδ2 refine fun x _ => (hδ2 ?_).le rw [sub_add_cancel_left, norm_neg, hw'_nm, ← div_div, div_lt_iff (norm_pos_iff.mpr hw_ne), ← div_lt_iff' hδ1, div_div] exact (lt_add_of_pos_left _ one_half_pos).trans_le hw_bd have bdA2 := norm_setIntegral_le_of_norm_le_const (hB_vol.trans_lt ENNReal.coe_lt_top) bdA ?_ swap · apply Continuous.aestronglyMeasurable exact continuous_norm.comp <| Continuous.sub hf1 <| Continuous.comp hf1 <| continuous_id'.add continuous_const have : ‖_‖ = ∫ v : V in A, ‖f v - f (v + i w)‖ := Real.norm_of_nonneg (setIntegral_nonneg mA fun x _ => norm_nonneg _) rw [this] at bdA2 refine bdA2.trans_lt ?_ rw [div_mul_eq_mul_div, div_lt_iff (NNReal.coe_pos.mpr hB_pos), mul_comm (2 : ℝ), mul_assoc, mul_lt_mul_left hε] rw [← ENNReal.toReal_le_toReal] at hB_vol · refine hB_vol.trans_lt ?_ rw [(by rfl : (↑B : ENNReal).toReal = ↑B), two_mul] exact lt_add_of_pos_left _ hB_pos exacts [(hB_vol.trans_lt ENNReal.coe_lt_top).ne, ENNReal.coe_lt_top.ne] #align tendsto_integral_exp_inner_smul_cocompact_of_continuous_compact_support tendsto_integral_exp_inner_smul_cocompact_of_continuous_compact_support variable (f) /-- Riemann-Lebesgue lemma for functions on a real inner-product space: the integral `∫ v, exp (-2 * π * ⟪w, v⟫ * I) • f v` tends to 0 as `w → ∞`. -/ theorem tendsto_integral_exp_inner_smul_cocompact : Tendsto (fun w : V => ∫ v, 𝐞 (-⟪v, w⟫) • f v) (cocompact V) (𝓝 0) := by by_cases hfi : Integrable f; swap · convert tendsto_const_nhds (x := (0 : E)) with w apply integral_undef rwa [Real.fourierIntegral_convergent_iff] refine Metric.tendsto_nhds.mpr fun ε hε => ?_ obtain ⟨g, hg_supp, hfg, hg_cont, -⟩ := hfi.exists_hasCompactSupport_integral_sub_le (div_pos hε two_pos) refine ((Metric.tendsto_nhds.mp (tendsto_integral_exp_inner_smul_cocompact_of_continuous_compact_support hg_cont hg_supp)) _ (div_pos hε two_pos)).mp (eventually_of_forall fun w hI => ?_) rw [dist_eq_norm] at hI ⊢ have : ‖(∫ v, 𝐞 (-⟪v, w⟫) • f v) - ∫ v, 𝐞 (-⟪v, w⟫) • g v‖ ≤ ε / 2 := by refine le_trans ?_ hfg simp_rw [← integral_sub ((Real.fourierIntegral_convergent_iff w).2 hfi) ((Real.fourierIntegral_convergent_iff w).2 (hg_cont.integrable_of_hasCompactSupport hg_supp)), ← smul_sub, ← Pi.sub_apply] exact VectorFourier.norm_fourierIntegral_le_integral_norm 𝐞 _ bilinFormOfRealInner (f - g) w replace := add_lt_add_of_le_of_lt this hI rw [add_halves] at this refine ((le_of_eq ?_).trans (norm_add_le _ _)).trans_lt this simp only [sub_zero, sub_add_cancel] #align tendsto_integral_exp_inner_smul_cocompact tendsto_integral_exp_inner_smul_cocompact /-- The Riemann-Lebesgue lemma for functions on `ℝ`. -/ theorem Real.tendsto_integral_exp_smul_cocompact (f : ℝ → E) : Tendsto (fun w : ℝ => ∫ v : ℝ, 𝐞 (-(v * w)) • f v) (cocompact ℝ) (𝓝 0) := tendsto_integral_exp_inner_smul_cocompact f #align real.tendsto_integral_exp_smul_cocompact Real.tendsto_integral_exp_smul_cocompact /-- The Riemann-Lebesgue lemma for functions on `ℝ`, formulated via `Real.fourierIntegral`. -/ theorem Real.zero_at_infty_fourierIntegral (f : ℝ → E) : Tendsto (𝓕 f) (cocompact ℝ) (𝓝 0) := tendsto_integral_exp_inner_smul_cocompact f #align real.zero_at_infty_fourier_integral Real.zero_at_infty_fourierIntegral /-- Riemann-Lebesgue lemma for functions on a finite-dimensional inner-product space, formulated via dual space. **Do not use** -- it is only a stepping stone to `tendsto_integral_exp_smul_cocompact` where the inner-product-space structure isn't required. -/
Mathlib/Analysis/Fourier/RiemannLebesgueLemma.lean
243
256
theorem tendsto_integral_exp_smul_cocompact_of_inner_product (μ : Measure V) [μ.IsAddHaarMeasure] : Tendsto (fun w : V →L[ℝ] ℝ => ∫ v, 𝐞 (-w v) • f v ∂μ) (cocompact (V →L[ℝ] ℝ)) (𝓝 0) := by
rw [μ.isAddLeftInvariant_eq_smul volume] simp_rw [integral_smul_nnreal_measure] rw [← (smul_zero _ : Measure.addHaarScalarFactor μ volume • (0 : E) = 0)] apply Tendsto.const_smul let A := (InnerProductSpace.toDual ℝ V).symm have : (fun w : V →L[ℝ] ℝ ↦ ∫ v, 𝐞 (-w v) • f v) = (fun w : V ↦ ∫ v, 𝐞 (-⟪v, w⟫) • f v) ∘ A := by ext1 w congr 1 with v : 1 rw [← inner_conj_symm, RCLike.conj_to_real, InnerProductSpace.toDual_symm_apply] rw [this] exact (tendsto_integral_exp_inner_smul_cocompact f).comp A.toHomeomorph.toCocompactMap.cocompact_tendsto'
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.FormalMultilinearSeries import Mathlib.Analysis.SpecificLimits.Normed import Mathlib.Logic.Equiv.Fin import Mathlib.Topology.Algebra.InfiniteSum.Module #align_import analysis.analytic.basic from "leanprover-community/mathlib"@"32253a1a1071173b33dc7d6a218cf722c6feb514" /-! # Analytic functions A function is analytic in one dimension around `0` if it can be written as a converging power series `Σ pₙ zⁿ`. This definition can be extended to any dimension (even in infinite dimension) by requiring that `pₙ` is a continuous `n`-multilinear map. In general, `pₙ` is not unique (in two dimensions, taking `p₂ (x, y) (x', y') = x y'` or `y x'` gives the same map when applied to a vector `(x, y) (x, y)`). A way to guarantee uniqueness is to take a symmetric `pₙ`, but this is not always possible in nonzero characteristic (in characteristic 2, the previous example has no symmetric representative). Therefore, we do not insist on symmetry or uniqueness in the definition, and we only require the existence of a converging series. The general framework is important to say that the exponential map on bounded operators on a Banach space is analytic, as well as the inverse on invertible operators. ## Main definitions Let `p` be a formal multilinear series from `E` to `F`, i.e., `p n` is a multilinear map on `E^n` for `n : ℕ`. * `p.radius`: the largest `r : ℝ≥0∞` such that `‖p n‖ * r^n` grows subexponentially. * `p.le_radius_of_bound`, `p.le_radius_of_bound_nnreal`, `p.le_radius_of_isBigO`: if `‖p n‖ * r ^ n` is bounded above, then `r ≤ p.radius`; * `p.isLittleO_of_lt_radius`, `p.norm_mul_pow_le_mul_pow_of_lt_radius`, `p.isLittleO_one_of_lt_radius`, `p.norm_mul_pow_le_of_lt_radius`, `p.nnnorm_mul_pow_le_of_lt_radius`: if `r < p.radius`, then `‖p n‖ * r ^ n` tends to zero exponentially; * `p.lt_radius_of_isBigO`: if `r ≠ 0` and `‖p n‖ * r ^ n = O(a ^ n)` for some `-1 < a < 1`, then `r < p.radius`; * `p.partialSum n x`: the sum `∑_{i = 0}^{n-1} pᵢ xⁱ`. * `p.sum x`: the sum `∑'_{i = 0}^{∞} pᵢ xⁱ`. Additionally, let `f` be a function from `E` to `F`. * `HasFPowerSeriesOnBall f p x r`: on the ball of center `x` with radius `r`, `f (x + y) = ∑'_n pₙ yⁿ`. * `HasFPowerSeriesAt f p x`: on some ball of center `x` with positive radius, holds `HasFPowerSeriesOnBall f p x r`. * `AnalyticAt 𝕜 f x`: there exists a power series `p` such that holds `HasFPowerSeriesAt f p x`. * `AnalyticOn 𝕜 f s`: the function `f` is analytic at every point of `s`. We develop the basic properties of these notions, notably: * If a function admits a power series, it is continuous (see `HasFPowerSeriesOnBall.continuousOn` and `HasFPowerSeriesAt.continuousAt` and `AnalyticAt.continuousAt`). * In a complete space, the sum of a formal power series with positive radius is well defined on the disk of convergence, see `FormalMultilinearSeries.hasFPowerSeriesOnBall`. * If a function admits a power series in a ball, then it is analytic at any point `y` of this ball, and the power series there can be expressed in terms of the initial power series `p` as `p.changeOrigin y`. See `HasFPowerSeriesOnBall.changeOrigin`. It follows in particular that the set of points at which a given function is analytic is open, see `isOpen_analyticAt`. ## Implementation details We only introduce the radius of convergence of a power series, as `p.radius`. For a power series in finitely many dimensions, there is a finer (directional, coordinate-dependent) notion, describing the polydisk of convergence. This notion is more specific, and not necessary to build the general theory. We do not define it here. -/ noncomputable section variable {𝕜 E F G : Type*} open scoped Classical open Topology NNReal Filter ENNReal open Set Filter Asymptotics namespace FormalMultilinearSeries variable [Ring 𝕜] [AddCommGroup E] [AddCommGroup F] [Module 𝕜 E] [Module 𝕜 F] variable [TopologicalSpace E] [TopologicalSpace F] variable [TopologicalAddGroup E] [TopologicalAddGroup F] variable [ContinuousConstSMul 𝕜 E] [ContinuousConstSMul 𝕜 F] /-- Given a formal multilinear series `p` and a vector `x`, then `p.sum x` is the sum `Σ pₙ xⁿ`. A priori, it only behaves well when `‖x‖ < p.radius`. -/ protected def sum (p : FormalMultilinearSeries 𝕜 E F) (x : E) : F := ∑' n : ℕ, p n fun _ => x #align formal_multilinear_series.sum FormalMultilinearSeries.sum /-- Given a formal multilinear series `p` and a vector `x`, then `p.partialSum n x` is the sum `Σ pₖ xᵏ` for `k ∈ {0,..., n-1}`. -/ def partialSum (p : FormalMultilinearSeries 𝕜 E F) (n : ℕ) (x : E) : F := ∑ k ∈ Finset.range n, p k fun _ : Fin k => x #align formal_multilinear_series.partial_sum FormalMultilinearSeries.partialSum /-- The partial sums of a formal multilinear series are continuous. -/ theorem partialSum_continuous (p : FormalMultilinearSeries 𝕜 E F) (n : ℕ) : Continuous (p.partialSum n) := by unfold partialSum -- Porting note: added continuity #align formal_multilinear_series.partial_sum_continuous FormalMultilinearSeries.partialSum_continuous end FormalMultilinearSeries /-! ### The radius of a formal multilinear series -/ variable [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [NormedSpace 𝕜 F] [NormedAddCommGroup G] [NormedSpace 𝕜 G] namespace FormalMultilinearSeries variable (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0} /-- The radius of a formal multilinear series is the largest `r` such that the sum `Σ ‖pₙ‖ ‖y‖ⁿ` converges for all `‖y‖ < r`. This implies that `Σ pₙ yⁿ` converges for all `‖y‖ < r`, but these definitions are *not* equivalent in general. -/ def radius (p : FormalMultilinearSeries 𝕜 E F) : ℝ≥0∞ := ⨆ (r : ℝ≥0) (C : ℝ) (_ : ∀ n, ‖p n‖ * (r : ℝ) ^ n ≤ C), (r : ℝ≥0∞) #align formal_multilinear_series.radius FormalMultilinearSeries.radius /-- If `‖pₙ‖ rⁿ` is bounded in `n`, then the radius of `p` is at least `r`. -/ theorem le_radius_of_bound (C : ℝ) {r : ℝ≥0} (h : ∀ n : ℕ, ‖p n‖ * (r : ℝ) ^ n ≤ C) : (r : ℝ≥0∞) ≤ p.radius := le_iSup_of_le r <| le_iSup_of_le C <| le_iSup (fun _ => (r : ℝ≥0∞)) h #align formal_multilinear_series.le_radius_of_bound FormalMultilinearSeries.le_radius_of_bound /-- If `‖pₙ‖ rⁿ` is bounded in `n`, then the radius of `p` is at least `r`. -/ theorem le_radius_of_bound_nnreal (C : ℝ≥0) {r : ℝ≥0} (h : ∀ n : ℕ, ‖p n‖₊ * r ^ n ≤ C) : (r : ℝ≥0∞) ≤ p.radius := p.le_radius_of_bound C fun n => mod_cast h n #align formal_multilinear_series.le_radius_of_bound_nnreal FormalMultilinearSeries.le_radius_of_bound_nnreal /-- If `‖pₙ‖ rⁿ = O(1)`, as `n → ∞`, then the radius of `p` is at least `r`. -/ theorem le_radius_of_isBigO (h : (fun n => ‖p n‖ * (r : ℝ) ^ n) =O[atTop] fun _ => (1 : ℝ)) : ↑r ≤ p.radius := Exists.elim (isBigO_one_nat_atTop_iff.1 h) fun C hC => p.le_radius_of_bound C fun n => (le_abs_self _).trans (hC n) set_option linter.uppercaseLean3 false in #align formal_multilinear_series.le_radius_of_is_O FormalMultilinearSeries.le_radius_of_isBigO theorem le_radius_of_eventually_le (C) (h : ∀ᶠ n in atTop, ‖p n‖ * (r : ℝ) ^ n ≤ C) : ↑r ≤ p.radius := p.le_radius_of_isBigO <| IsBigO.of_bound C <| h.mono fun n hn => by simpa #align formal_multilinear_series.le_radius_of_eventually_le FormalMultilinearSeries.le_radius_of_eventually_le theorem le_radius_of_summable_nnnorm (h : Summable fun n => ‖p n‖₊ * r ^ n) : ↑r ≤ p.radius := p.le_radius_of_bound_nnreal (∑' n, ‖p n‖₊ * r ^ n) fun _ => le_tsum' h _ #align formal_multilinear_series.le_radius_of_summable_nnnorm FormalMultilinearSeries.le_radius_of_summable_nnnorm theorem le_radius_of_summable (h : Summable fun n => ‖p n‖ * (r : ℝ) ^ n) : ↑r ≤ p.radius := p.le_radius_of_summable_nnnorm <| by simp only [← coe_nnnorm] at h exact mod_cast h #align formal_multilinear_series.le_radius_of_summable FormalMultilinearSeries.le_radius_of_summable theorem radius_eq_top_of_forall_nnreal_isBigO (h : ∀ r : ℝ≥0, (fun n => ‖p n‖ * (r : ℝ) ^ n) =O[atTop] fun _ => (1 : ℝ)) : p.radius = ∞ := ENNReal.eq_top_of_forall_nnreal_le fun r => p.le_radius_of_isBigO (h r) set_option linter.uppercaseLean3 false in #align formal_multilinear_series.radius_eq_top_of_forall_nnreal_is_O FormalMultilinearSeries.radius_eq_top_of_forall_nnreal_isBigO theorem radius_eq_top_of_eventually_eq_zero (h : ∀ᶠ n in atTop, p n = 0) : p.radius = ∞ := p.radius_eq_top_of_forall_nnreal_isBigO fun r => (isBigO_zero _ _).congr' (h.mono fun n hn => by simp [hn]) EventuallyEq.rfl #align formal_multilinear_series.radius_eq_top_of_eventually_eq_zero FormalMultilinearSeries.radius_eq_top_of_eventually_eq_zero theorem radius_eq_top_of_forall_image_add_eq_zero (n : ℕ) (hn : ∀ m, p (m + n) = 0) : p.radius = ∞ := p.radius_eq_top_of_eventually_eq_zero <| mem_atTop_sets.2 ⟨n, fun _ hk => tsub_add_cancel_of_le hk ▸ hn _⟩ #align formal_multilinear_series.radius_eq_top_of_forall_image_add_eq_zero FormalMultilinearSeries.radius_eq_top_of_forall_image_add_eq_zero @[simp] theorem constFormalMultilinearSeries_radius {v : F} : (constFormalMultilinearSeries 𝕜 E v).radius = ⊤ := (constFormalMultilinearSeries 𝕜 E v).radius_eq_top_of_forall_image_add_eq_zero 1 (by simp [constFormalMultilinearSeries]) #align formal_multilinear_series.const_formal_multilinear_series_radius FormalMultilinearSeries.constFormalMultilinearSeries_radius /-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` tends to zero exponentially: for some `0 < a < 1`, `‖p n‖ rⁿ = o(aⁿ)`. -/ theorem isLittleO_of_lt_radius (h : ↑r < p.radius) : ∃ a ∈ Ioo (0 : ℝ) 1, (fun n => ‖p n‖ * (r : ℝ) ^ n) =o[atTop] (a ^ ·) := by have := (TFAE_exists_lt_isLittleO_pow (fun n => ‖p n‖ * (r : ℝ) ^ n) 1).out 1 4 rw [this] -- Porting note: was -- rw [(TFAE_exists_lt_isLittleO_pow (fun n => ‖p n‖ * (r : ℝ) ^ n) 1).out 1 4] simp only [radius, lt_iSup_iff] at h rcases h with ⟨t, C, hC, rt⟩ rw [ENNReal.coe_lt_coe, ← NNReal.coe_lt_coe] at rt have : 0 < (t : ℝ) := r.coe_nonneg.trans_lt rt rw [← div_lt_one this] at rt refine ⟨_, rt, C, Or.inr zero_lt_one, fun n => ?_⟩ calc |‖p n‖ * (r : ℝ) ^ n| = ‖p n‖ * (t : ℝ) ^ n * (r / t : ℝ) ^ n := by field_simp [mul_right_comm, abs_mul] _ ≤ C * (r / t : ℝ) ^ n := by gcongr; apply hC #align formal_multilinear_series.is_o_of_lt_radius FormalMultilinearSeries.isLittleO_of_lt_radius /-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ = o(1)`. -/ theorem isLittleO_one_of_lt_radius (h : ↑r < p.radius) : (fun n => ‖p n‖ * (r : ℝ) ^ n) =o[atTop] (fun _ => 1 : ℕ → ℝ) := let ⟨_, ha, hp⟩ := p.isLittleO_of_lt_radius h hp.trans <| (isLittleO_pow_pow_of_lt_left ha.1.le ha.2).congr (fun _ => rfl) one_pow #align formal_multilinear_series.is_o_one_of_lt_radius FormalMultilinearSeries.isLittleO_one_of_lt_radius /-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` tends to zero exponentially: for some `0 < a < 1` and `C > 0`, `‖p n‖ * r ^ n ≤ C * a ^ n`. -/ theorem norm_mul_pow_le_mul_pow_of_lt_radius (h : ↑r < p.radius) : ∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ n, ‖p n‖ * (r : ℝ) ^ n ≤ C * a ^ n := by -- Porting note: moved out of `rcases` have := ((TFAE_exists_lt_isLittleO_pow (fun n => ‖p n‖ * (r : ℝ) ^ n) 1).out 1 5).mp (p.isLittleO_of_lt_radius h) rcases this with ⟨a, ha, C, hC, H⟩ exact ⟨a, ha, C, hC, fun n => (le_abs_self _).trans (H n)⟩ #align formal_multilinear_series.norm_mul_pow_le_mul_pow_of_lt_radius FormalMultilinearSeries.norm_mul_pow_le_mul_pow_of_lt_radius /-- If `r ≠ 0` and `‖pₙ‖ rⁿ = O(aⁿ)` for some `-1 < a < 1`, then `r < p.radius`. -/ theorem lt_radius_of_isBigO (h₀ : r ≠ 0) {a : ℝ} (ha : a ∈ Ioo (-1 : ℝ) 1) (hp : (fun n => ‖p n‖ * (r : ℝ) ^ n) =O[atTop] (a ^ ·)) : ↑r < p.radius := by -- Porting note: moved out of `rcases` have := ((TFAE_exists_lt_isLittleO_pow (fun n => ‖p n‖ * (r : ℝ) ^ n) 1).out 2 5) rcases this.mp ⟨a, ha, hp⟩ with ⟨a, ha, C, hC, hp⟩ rw [← pos_iff_ne_zero, ← NNReal.coe_pos] at h₀ lift a to ℝ≥0 using ha.1.le have : (r : ℝ) < r / a := by simpa only [div_one] using (div_lt_div_left h₀ zero_lt_one ha.1).2 ha.2 norm_cast at this rw [← ENNReal.coe_lt_coe] at this refine this.trans_le (p.le_radius_of_bound C fun n => ?_) rw [NNReal.coe_div, div_pow, ← mul_div_assoc, div_le_iff (pow_pos ha.1 n)] exact (le_abs_self _).trans (hp n) set_option linter.uppercaseLean3 false in #align formal_multilinear_series.lt_radius_of_is_O FormalMultilinearSeries.lt_radius_of_isBigO /-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` is bounded. -/ theorem norm_mul_pow_le_of_lt_radius (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0} (h : (r : ℝ≥0∞) < p.radius) : ∃ C > 0, ∀ n, ‖p n‖ * (r : ℝ) ^ n ≤ C := let ⟨_, ha, C, hC, h⟩ := p.norm_mul_pow_le_mul_pow_of_lt_radius h ⟨C, hC, fun n => (h n).trans <| mul_le_of_le_one_right hC.lt.le (pow_le_one _ ha.1.le ha.2.le)⟩ #align formal_multilinear_series.norm_mul_pow_le_of_lt_radius FormalMultilinearSeries.norm_mul_pow_le_of_lt_radius /-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` is bounded. -/ theorem norm_le_div_pow_of_pos_of_lt_radius (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0} (h0 : 0 < r) (h : (r : ℝ≥0∞) < p.radius) : ∃ C > 0, ∀ n, ‖p n‖ ≤ C / (r : ℝ) ^ n := let ⟨C, hC, hp⟩ := p.norm_mul_pow_le_of_lt_radius h ⟨C, hC, fun n => Iff.mpr (le_div_iff (pow_pos h0 _)) (hp n)⟩ #align formal_multilinear_series.norm_le_div_pow_of_pos_of_lt_radius FormalMultilinearSeries.norm_le_div_pow_of_pos_of_lt_radius /-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` is bounded. -/ theorem nnnorm_mul_pow_le_of_lt_radius (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0} (h : (r : ℝ≥0∞) < p.radius) : ∃ C > 0, ∀ n, ‖p n‖₊ * r ^ n ≤ C := let ⟨C, hC, hp⟩ := p.norm_mul_pow_le_of_lt_radius h ⟨⟨C, hC.lt.le⟩, hC, mod_cast hp⟩ #align formal_multilinear_series.nnnorm_mul_pow_le_of_lt_radius FormalMultilinearSeries.nnnorm_mul_pow_le_of_lt_radius theorem le_radius_of_tendsto (p : FormalMultilinearSeries 𝕜 E F) {l : ℝ} (h : Tendsto (fun n => ‖p n‖ * (r : ℝ) ^ n) atTop (𝓝 l)) : ↑r ≤ p.radius := p.le_radius_of_isBigO (h.isBigO_one _) #align formal_multilinear_series.le_radius_of_tendsto FormalMultilinearSeries.le_radius_of_tendsto theorem le_radius_of_summable_norm (p : FormalMultilinearSeries 𝕜 E F) (hs : Summable fun n => ‖p n‖ * (r : ℝ) ^ n) : ↑r ≤ p.radius := p.le_radius_of_tendsto hs.tendsto_atTop_zero #align formal_multilinear_series.le_radius_of_summable_norm FormalMultilinearSeries.le_radius_of_summable_norm theorem not_summable_norm_of_radius_lt_nnnorm (p : FormalMultilinearSeries 𝕜 E F) {x : E} (h : p.radius < ‖x‖₊) : ¬Summable fun n => ‖p n‖ * ‖x‖ ^ n := fun hs => not_le_of_lt h (p.le_radius_of_summable_norm hs) #align formal_multilinear_series.not_summable_norm_of_radius_lt_nnnorm FormalMultilinearSeries.not_summable_norm_of_radius_lt_nnnorm theorem summable_norm_mul_pow (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0} (h : ↑r < p.radius) : Summable fun n : ℕ => ‖p n‖ * (r : ℝ) ^ n := by obtain ⟨a, ha : a ∈ Ioo (0 : ℝ) 1, C, - : 0 < C, hp⟩ := p.norm_mul_pow_le_mul_pow_of_lt_radius h exact .of_nonneg_of_le (fun n => mul_nonneg (norm_nonneg _) (pow_nonneg r.coe_nonneg _)) hp ((summable_geometric_of_lt_one ha.1.le ha.2).mul_left _) #align formal_multilinear_series.summable_norm_mul_pow FormalMultilinearSeries.summable_norm_mul_pow theorem summable_norm_apply (p : FormalMultilinearSeries 𝕜 E F) {x : E} (hx : x ∈ EMetric.ball (0 : E) p.radius) : Summable fun n : ℕ => ‖p n fun _ => x‖ := by rw [mem_emetric_ball_zero_iff] at hx refine .of_nonneg_of_le (fun _ ↦ norm_nonneg _) (fun n ↦ ((p n).le_opNorm _).trans_eq ?_) (p.summable_norm_mul_pow hx) simp #align formal_multilinear_series.summable_norm_apply FormalMultilinearSeries.summable_norm_apply theorem summable_nnnorm_mul_pow (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0} (h : ↑r < p.radius) : Summable fun n : ℕ => ‖p n‖₊ * r ^ n := by rw [← NNReal.summable_coe] push_cast exact p.summable_norm_mul_pow h #align formal_multilinear_series.summable_nnnorm_mul_pow FormalMultilinearSeries.summable_nnnorm_mul_pow protected theorem summable [CompleteSpace F] (p : FormalMultilinearSeries 𝕜 E F) {x : E} (hx : x ∈ EMetric.ball (0 : E) p.radius) : Summable fun n : ℕ => p n fun _ => x := (p.summable_norm_apply hx).of_norm #align formal_multilinear_series.summable FormalMultilinearSeries.summable theorem radius_eq_top_of_summable_norm (p : FormalMultilinearSeries 𝕜 E F) (hs : ∀ r : ℝ≥0, Summable fun n => ‖p n‖ * (r : ℝ) ^ n) : p.radius = ∞ := ENNReal.eq_top_of_forall_nnreal_le fun r => p.le_radius_of_summable_norm (hs r) #align formal_multilinear_series.radius_eq_top_of_summable_norm FormalMultilinearSeries.radius_eq_top_of_summable_norm theorem radius_eq_top_iff_summable_norm (p : FormalMultilinearSeries 𝕜 E F) : p.radius = ∞ ↔ ∀ r : ℝ≥0, Summable fun n => ‖p n‖ * (r : ℝ) ^ n := by constructor · intro h r obtain ⟨a, ha : a ∈ Ioo (0 : ℝ) 1, C, - : 0 < C, hp⟩ := p.norm_mul_pow_le_mul_pow_of_lt_radius (show (r : ℝ≥0∞) < p.radius from h.symm ▸ ENNReal.coe_lt_top) refine .of_norm_bounded (fun n ↦ (C : ℝ) * a ^ n) ((summable_geometric_of_lt_one ha.1.le ha.2).mul_left _) fun n ↦ ?_ specialize hp n rwa [Real.norm_of_nonneg (mul_nonneg (norm_nonneg _) (pow_nonneg r.coe_nonneg n))] · exact p.radius_eq_top_of_summable_norm #align formal_multilinear_series.radius_eq_top_iff_summable_norm FormalMultilinearSeries.radius_eq_top_iff_summable_norm /-- If the radius of `p` is positive, then `‖pₙ‖` grows at most geometrically. -/ theorem le_mul_pow_of_radius_pos (p : FormalMultilinearSeries 𝕜 E F) (h : 0 < p.radius) : ∃ (C r : _) (hC : 0 < C) (_ : 0 < r), ∀ n, ‖p n‖ ≤ C * r ^ n := by rcases ENNReal.lt_iff_exists_nnreal_btwn.1 h with ⟨r, r0, rlt⟩ have rpos : 0 < (r : ℝ) := by simp [ENNReal.coe_pos.1 r0] rcases norm_le_div_pow_of_pos_of_lt_radius p rpos rlt with ⟨C, Cpos, hCp⟩ refine ⟨C, r⁻¹, Cpos, by simp only [inv_pos, rpos], fun n => ?_⟩ -- Porting note: was `convert` rw [inv_pow, ← div_eq_mul_inv] exact hCp n #align formal_multilinear_series.le_mul_pow_of_radius_pos FormalMultilinearSeries.le_mul_pow_of_radius_pos /-- The radius of the sum of two formal series is at least the minimum of their two radii. -/ theorem min_radius_le_radius_add (p q : FormalMultilinearSeries 𝕜 E F) : min p.radius q.radius ≤ (p + q).radius := by refine ENNReal.le_of_forall_nnreal_lt fun r hr => ?_ rw [lt_min_iff] at hr have := ((p.isLittleO_one_of_lt_radius hr.1).add (q.isLittleO_one_of_lt_radius hr.2)).isBigO refine (p + q).le_radius_of_isBigO ((isBigO_of_le _ fun n => ?_).trans this) rw [← add_mul, norm_mul, norm_mul, norm_norm] exact mul_le_mul_of_nonneg_right ((norm_add_le _ _).trans (le_abs_self _)) (norm_nonneg _) #align formal_multilinear_series.min_radius_le_radius_add FormalMultilinearSeries.min_radius_le_radius_add @[simp] theorem radius_neg (p : FormalMultilinearSeries 𝕜 E F) : (-p).radius = p.radius := by simp only [radius, neg_apply, norm_neg] #align formal_multilinear_series.radius_neg FormalMultilinearSeries.radius_neg protected theorem hasSum [CompleteSpace F] (p : FormalMultilinearSeries 𝕜 E F) {x : E} (hx : x ∈ EMetric.ball (0 : E) p.radius) : HasSum (fun n : ℕ => p n fun _ => x) (p.sum x) := (p.summable hx).hasSum #align formal_multilinear_series.has_sum FormalMultilinearSeries.hasSum theorem radius_le_radius_continuousLinearMap_comp (p : FormalMultilinearSeries 𝕜 E F) (f : F →L[𝕜] G) : p.radius ≤ (f.compFormalMultilinearSeries p).radius := by refine ENNReal.le_of_forall_nnreal_lt fun r hr => ?_ apply le_radius_of_isBigO apply (IsBigO.trans_isLittleO _ (p.isLittleO_one_of_lt_radius hr)).isBigO refine IsBigO.mul (@IsBigOWith.isBigO _ _ _ _ _ ‖f‖ _ _ _ ?_) (isBigO_refl _ _) refine IsBigOWith.of_bound (eventually_of_forall fun n => ?_) simpa only [norm_norm] using f.norm_compContinuousMultilinearMap_le (p n) #align formal_multilinear_series.radius_le_radius_continuous_linear_map_comp FormalMultilinearSeries.radius_le_radius_continuousLinearMap_comp end FormalMultilinearSeries /-! ### Expanding a function as a power series -/ section variable {f g : E → F} {p pf pg : FormalMultilinearSeries 𝕜 E F} {x : E} {r r' : ℝ≥0∞} /-- Given a function `f : E → F` and a formal multilinear series `p`, we say that `f` has `p` as a power series on the ball of radius `r > 0` around `x` if `f (x + y) = ∑' pₙ yⁿ` for all `‖y‖ < r`. -/ structure HasFPowerSeriesOnBall (f : E → F) (p : FormalMultilinearSeries 𝕜 E F) (x : E) (r : ℝ≥0∞) : Prop where r_le : r ≤ p.radius r_pos : 0 < r hasSum : ∀ {y}, y ∈ EMetric.ball (0 : E) r → HasSum (fun n : ℕ => p n fun _ : Fin n => y) (f (x + y)) #align has_fpower_series_on_ball HasFPowerSeriesOnBall /-- Given a function `f : E → F` and a formal multilinear series `p`, we say that `f` has `p` as a power series around `x` if `f (x + y) = ∑' pₙ yⁿ` for all `y` in a neighborhood of `0`. -/ def HasFPowerSeriesAt (f : E → F) (p : FormalMultilinearSeries 𝕜 E F) (x : E) := ∃ r, HasFPowerSeriesOnBall f p x r #align has_fpower_series_at HasFPowerSeriesAt variable (𝕜) /-- Given a function `f : E → F`, we say that `f` is analytic at `x` if it admits a convergent power series expansion around `x`. -/ def AnalyticAt (f : E → F) (x : E) := ∃ p : FormalMultilinearSeries 𝕜 E F, HasFPowerSeriesAt f p x #align analytic_at AnalyticAt /-- Given a function `f : E → F`, we say that `f` is analytic on a set `s` if it is analytic around every point of `s`. -/ def AnalyticOn (f : E → F) (s : Set E) := ∀ x, x ∈ s → AnalyticAt 𝕜 f x #align analytic_on AnalyticOn variable {𝕜} theorem HasFPowerSeriesOnBall.hasFPowerSeriesAt (hf : HasFPowerSeriesOnBall f p x r) : HasFPowerSeriesAt f p x := ⟨r, hf⟩ #align has_fpower_series_on_ball.has_fpower_series_at HasFPowerSeriesOnBall.hasFPowerSeriesAt theorem HasFPowerSeriesAt.analyticAt (hf : HasFPowerSeriesAt f p x) : AnalyticAt 𝕜 f x := ⟨p, hf⟩ #align has_fpower_series_at.analytic_at HasFPowerSeriesAt.analyticAt theorem HasFPowerSeriesOnBall.analyticAt (hf : HasFPowerSeriesOnBall f p x r) : AnalyticAt 𝕜 f x := hf.hasFPowerSeriesAt.analyticAt #align has_fpower_series_on_ball.analytic_at HasFPowerSeriesOnBall.analyticAt theorem HasFPowerSeriesOnBall.congr (hf : HasFPowerSeriesOnBall f p x r) (hg : EqOn f g (EMetric.ball x r)) : HasFPowerSeriesOnBall g p x r := { r_le := hf.r_le r_pos := hf.r_pos hasSum := fun {y} hy => by convert hf.hasSum hy using 1 apply hg.symm simpa [edist_eq_coe_nnnorm_sub] using hy } #align has_fpower_series_on_ball.congr HasFPowerSeriesOnBall.congr /-- If a function `f` has a power series `p` around `x`, then the function `z ↦ f (z - y)` has the same power series around `x + y`. -/ theorem HasFPowerSeriesOnBall.comp_sub (hf : HasFPowerSeriesOnBall f p x r) (y : E) : HasFPowerSeriesOnBall (fun z => f (z - y)) p (x + y) r := { r_le := hf.r_le r_pos := hf.r_pos hasSum := fun {z} hz => by convert hf.hasSum hz using 2 abel } #align has_fpower_series_on_ball.comp_sub HasFPowerSeriesOnBall.comp_sub theorem HasFPowerSeriesOnBall.hasSum_sub (hf : HasFPowerSeriesOnBall f p x r) {y : E} (hy : y ∈ EMetric.ball x r) : HasSum (fun n : ℕ => p n fun _ => y - x) (f y) := by have : y - x ∈ EMetric.ball (0 : E) r := by simpa [edist_eq_coe_nnnorm_sub] using hy simpa only [add_sub_cancel] using hf.hasSum this #align has_fpower_series_on_ball.has_sum_sub HasFPowerSeriesOnBall.hasSum_sub theorem HasFPowerSeriesOnBall.radius_pos (hf : HasFPowerSeriesOnBall f p x r) : 0 < p.radius := lt_of_lt_of_le hf.r_pos hf.r_le #align has_fpower_series_on_ball.radius_pos HasFPowerSeriesOnBall.radius_pos theorem HasFPowerSeriesAt.radius_pos (hf : HasFPowerSeriesAt f p x) : 0 < p.radius := let ⟨_, hr⟩ := hf hr.radius_pos #align has_fpower_series_at.radius_pos HasFPowerSeriesAt.radius_pos theorem HasFPowerSeriesOnBall.mono (hf : HasFPowerSeriesOnBall f p x r) (r'_pos : 0 < r') (hr : r' ≤ r) : HasFPowerSeriesOnBall f p x r' := ⟨le_trans hr hf.1, r'_pos, fun hy => hf.hasSum (EMetric.ball_subset_ball hr hy)⟩ #align has_fpower_series_on_ball.mono HasFPowerSeriesOnBall.mono theorem HasFPowerSeriesAt.congr (hf : HasFPowerSeriesAt f p x) (hg : f =ᶠ[𝓝 x] g) : HasFPowerSeriesAt g p x := by rcases hf with ⟨r₁, h₁⟩ rcases EMetric.mem_nhds_iff.mp hg with ⟨r₂, h₂pos, h₂⟩ exact ⟨min r₁ r₂, (h₁.mono (lt_min h₁.r_pos h₂pos) inf_le_left).congr fun y hy => h₂ (EMetric.ball_subset_ball inf_le_right hy)⟩ #align has_fpower_series_at.congr HasFPowerSeriesAt.congr protected theorem HasFPowerSeriesAt.eventually (hf : HasFPowerSeriesAt f p x) : ∀ᶠ r : ℝ≥0∞ in 𝓝[>] 0, HasFPowerSeriesOnBall f p x r := let ⟨_, hr⟩ := hf mem_of_superset (Ioo_mem_nhdsWithin_Ioi (left_mem_Ico.2 hr.r_pos)) fun _ hr' => hr.mono hr'.1 hr'.2.le #align has_fpower_series_at.eventually HasFPowerSeriesAt.eventually theorem HasFPowerSeriesOnBall.eventually_hasSum (hf : HasFPowerSeriesOnBall f p x r) : ∀ᶠ y in 𝓝 0, HasSum (fun n : ℕ => p n fun _ : Fin n => y) (f (x + y)) := by filter_upwards [EMetric.ball_mem_nhds (0 : E) hf.r_pos] using fun _ => hf.hasSum #align has_fpower_series_on_ball.eventually_has_sum HasFPowerSeriesOnBall.eventually_hasSum theorem HasFPowerSeriesAt.eventually_hasSum (hf : HasFPowerSeriesAt f p x) : ∀ᶠ y in 𝓝 0, HasSum (fun n : ℕ => p n fun _ : Fin n => y) (f (x + y)) := let ⟨_, hr⟩ := hf hr.eventually_hasSum #align has_fpower_series_at.eventually_has_sum HasFPowerSeriesAt.eventually_hasSum theorem HasFPowerSeriesOnBall.eventually_hasSum_sub (hf : HasFPowerSeriesOnBall f p x r) : ∀ᶠ y in 𝓝 x, HasSum (fun n : ℕ => p n fun _ : Fin n => y - x) (f y) := by filter_upwards [EMetric.ball_mem_nhds x hf.r_pos] with y using hf.hasSum_sub #align has_fpower_series_on_ball.eventually_has_sum_sub HasFPowerSeriesOnBall.eventually_hasSum_sub theorem HasFPowerSeriesAt.eventually_hasSum_sub (hf : HasFPowerSeriesAt f p x) : ∀ᶠ y in 𝓝 x, HasSum (fun n : ℕ => p n fun _ : Fin n => y - x) (f y) := let ⟨_, hr⟩ := hf hr.eventually_hasSum_sub #align has_fpower_series_at.eventually_has_sum_sub HasFPowerSeriesAt.eventually_hasSum_sub theorem HasFPowerSeriesOnBall.eventually_eq_zero (hf : HasFPowerSeriesOnBall f (0 : FormalMultilinearSeries 𝕜 E F) x r) : ∀ᶠ z in 𝓝 x, f z = 0 := by filter_upwards [hf.eventually_hasSum_sub] with z hz using hz.unique hasSum_zero #align has_fpower_series_on_ball.eventually_eq_zero HasFPowerSeriesOnBall.eventually_eq_zero theorem HasFPowerSeriesAt.eventually_eq_zero (hf : HasFPowerSeriesAt f (0 : FormalMultilinearSeries 𝕜 E F) x) : ∀ᶠ z in 𝓝 x, f z = 0 := let ⟨_, hr⟩ := hf hr.eventually_eq_zero #align has_fpower_series_at.eventually_eq_zero HasFPowerSeriesAt.eventually_eq_zero theorem hasFPowerSeriesOnBall_const {c : F} {e : E} : HasFPowerSeriesOnBall (fun _ => c) (constFormalMultilinearSeries 𝕜 E c) e ⊤ := by refine ⟨by simp, WithTop.zero_lt_top, fun _ => hasSum_single 0 fun n hn => ?_⟩ simp [constFormalMultilinearSeries_apply hn] #align has_fpower_series_on_ball_const hasFPowerSeriesOnBall_const theorem hasFPowerSeriesAt_const {c : F} {e : E} : HasFPowerSeriesAt (fun _ => c) (constFormalMultilinearSeries 𝕜 E c) e := ⟨⊤, hasFPowerSeriesOnBall_const⟩ #align has_fpower_series_at_const hasFPowerSeriesAt_const theorem analyticAt_const {v : F} : AnalyticAt 𝕜 (fun _ => v) x := ⟨constFormalMultilinearSeries 𝕜 E v, hasFPowerSeriesAt_const⟩ #align analytic_at_const analyticAt_const theorem analyticOn_const {v : F} {s : Set E} : AnalyticOn 𝕜 (fun _ => v) s := fun _ _ => analyticAt_const #align analytic_on_const analyticOn_const theorem HasFPowerSeriesOnBall.add (hf : HasFPowerSeriesOnBall f pf x r) (hg : HasFPowerSeriesOnBall g pg x r) : HasFPowerSeriesOnBall (f + g) (pf + pg) x r := { r_le := le_trans (le_min_iff.2 ⟨hf.r_le, hg.r_le⟩) (pf.min_radius_le_radius_add pg) r_pos := hf.r_pos hasSum := fun hy => (hf.hasSum hy).add (hg.hasSum hy) } #align has_fpower_series_on_ball.add HasFPowerSeriesOnBall.add theorem HasFPowerSeriesAt.add (hf : HasFPowerSeriesAt f pf x) (hg : HasFPowerSeriesAt g pg x) : HasFPowerSeriesAt (f + g) (pf + pg) x := by rcases (hf.eventually.and hg.eventually).exists with ⟨r, hr⟩ exact ⟨r, hr.1.add hr.2⟩ #align has_fpower_series_at.add HasFPowerSeriesAt.add theorem AnalyticAt.congr (hf : AnalyticAt 𝕜 f x) (hg : f =ᶠ[𝓝 x] g) : AnalyticAt 𝕜 g x := let ⟨_, hpf⟩ := hf (hpf.congr hg).analyticAt theorem analyticAt_congr (h : f =ᶠ[𝓝 x] g) : AnalyticAt 𝕜 f x ↔ AnalyticAt 𝕜 g x := ⟨fun hf ↦ hf.congr h, fun hg ↦ hg.congr h.symm⟩ theorem AnalyticAt.add (hf : AnalyticAt 𝕜 f x) (hg : AnalyticAt 𝕜 g x) : AnalyticAt 𝕜 (f + g) x := let ⟨_, hpf⟩ := hf let ⟨_, hqf⟩ := hg (hpf.add hqf).analyticAt #align analytic_at.add AnalyticAt.add theorem HasFPowerSeriesOnBall.neg (hf : HasFPowerSeriesOnBall f pf x r) : HasFPowerSeriesOnBall (-f) (-pf) x r := { r_le := by rw [pf.radius_neg] exact hf.r_le r_pos := hf.r_pos hasSum := fun hy => (hf.hasSum hy).neg } #align has_fpower_series_on_ball.neg HasFPowerSeriesOnBall.neg theorem HasFPowerSeriesAt.neg (hf : HasFPowerSeriesAt f pf x) : HasFPowerSeriesAt (-f) (-pf) x := let ⟨_, hrf⟩ := hf hrf.neg.hasFPowerSeriesAt #align has_fpower_series_at.neg HasFPowerSeriesAt.neg theorem AnalyticAt.neg (hf : AnalyticAt 𝕜 f x) : AnalyticAt 𝕜 (-f) x := let ⟨_, hpf⟩ := hf hpf.neg.analyticAt #align analytic_at.neg AnalyticAt.neg theorem HasFPowerSeriesOnBall.sub (hf : HasFPowerSeriesOnBall f pf x r) (hg : HasFPowerSeriesOnBall g pg x r) : HasFPowerSeriesOnBall (f - g) (pf - pg) x r := by simpa only [sub_eq_add_neg] using hf.add hg.neg #align has_fpower_series_on_ball.sub HasFPowerSeriesOnBall.sub theorem HasFPowerSeriesAt.sub (hf : HasFPowerSeriesAt f pf x) (hg : HasFPowerSeriesAt g pg x) : HasFPowerSeriesAt (f - g) (pf - pg) x := by simpa only [sub_eq_add_neg] using hf.add hg.neg #align has_fpower_series_at.sub HasFPowerSeriesAt.sub theorem AnalyticAt.sub (hf : AnalyticAt 𝕜 f x) (hg : AnalyticAt 𝕜 g x) : AnalyticAt 𝕜 (f - g) x := by simpa only [sub_eq_add_neg] using hf.add hg.neg #align analytic_at.sub AnalyticAt.sub theorem AnalyticOn.mono {s t : Set E} (hf : AnalyticOn 𝕜 f t) (hst : s ⊆ t) : AnalyticOn 𝕜 f s := fun z hz => hf z (hst hz) #align analytic_on.mono AnalyticOn.mono theorem AnalyticOn.congr' {s : Set E} (hf : AnalyticOn 𝕜 f s) (hg : f =ᶠ[𝓝ˢ s] g) : AnalyticOn 𝕜 g s := fun z hz => (hf z hz).congr (mem_nhdsSet_iff_forall.mp hg z hz) theorem analyticOn_congr' {s : Set E} (h : f =ᶠ[𝓝ˢ s] g) : AnalyticOn 𝕜 f s ↔ AnalyticOn 𝕜 g s := ⟨fun hf => hf.congr' h, fun hg => hg.congr' h.symm⟩ theorem AnalyticOn.congr {s : Set E} (hs : IsOpen s) (hf : AnalyticOn 𝕜 f s) (hg : s.EqOn f g) : AnalyticOn 𝕜 g s := hf.congr' <| mem_nhdsSet_iff_forall.mpr (fun _ hz => eventuallyEq_iff_exists_mem.mpr ⟨s, hs.mem_nhds hz, hg⟩) theorem analyticOn_congr {s : Set E} (hs : IsOpen s) (h : s.EqOn f g) : AnalyticOn 𝕜 f s ↔ AnalyticOn 𝕜 g s := ⟨fun hf => hf.congr hs h, fun hg => hg.congr hs h.symm⟩ theorem AnalyticOn.add {s : Set E} (hf : AnalyticOn 𝕜 f s) (hg : AnalyticOn 𝕜 g s) : AnalyticOn 𝕜 (f + g) s := fun z hz => (hf z hz).add (hg z hz) #align analytic_on.add AnalyticOn.add theorem AnalyticOn.sub {s : Set E} (hf : AnalyticOn 𝕜 f s) (hg : AnalyticOn 𝕜 g s) : AnalyticOn 𝕜 (f - g) s := fun z hz => (hf z hz).sub (hg z hz) #align analytic_on.sub AnalyticOn.sub theorem HasFPowerSeriesOnBall.coeff_zero (hf : HasFPowerSeriesOnBall f pf x r) (v : Fin 0 → E) : pf 0 v = f x := by have v_eq : v = fun i => 0 := Subsingleton.elim _ _ have zero_mem : (0 : E) ∈ EMetric.ball (0 : E) r := by simp [hf.r_pos] have : ∀ i, i ≠ 0 → (pf i fun j => 0) = 0 := by intro i hi have : 0 < i := pos_iff_ne_zero.2 hi exact ContinuousMultilinearMap.map_coord_zero _ (⟨0, this⟩ : Fin i) rfl have A := (hf.hasSum zero_mem).unique (hasSum_single _ this) simpa [v_eq] using A.symm #align has_fpower_series_on_ball.coeff_zero HasFPowerSeriesOnBall.coeff_zero theorem HasFPowerSeriesAt.coeff_zero (hf : HasFPowerSeriesAt f pf x) (v : Fin 0 → E) : pf 0 v = f x := let ⟨_, hrf⟩ := hf hrf.coeff_zero v #align has_fpower_series_at.coeff_zero HasFPowerSeriesAt.coeff_zero /-- If a function `f` has a power series `p` on a ball and `g` is linear, then `g ∘ f` has the power series `g ∘ p` on the same ball. -/ theorem ContinuousLinearMap.comp_hasFPowerSeriesOnBall (g : F →L[𝕜] G) (h : HasFPowerSeriesOnBall f p x r) : HasFPowerSeriesOnBall (g ∘ f) (g.compFormalMultilinearSeries p) x r := { r_le := h.r_le.trans (p.radius_le_radius_continuousLinearMap_comp _) r_pos := h.r_pos hasSum := fun hy => by simpa only [ContinuousLinearMap.compFormalMultilinearSeries_apply, ContinuousLinearMap.compContinuousMultilinearMap_coe, Function.comp_apply] using g.hasSum (h.hasSum hy) } #align continuous_linear_map.comp_has_fpower_series_on_ball ContinuousLinearMap.comp_hasFPowerSeriesOnBall /-- If a function `f` is analytic on a set `s` and `g` is linear, then `g ∘ f` is analytic on `s`. -/ theorem ContinuousLinearMap.comp_analyticOn {s : Set E} (g : F →L[𝕜] G) (h : AnalyticOn 𝕜 f s) : AnalyticOn 𝕜 (g ∘ f) s := by rintro x hx rcases h x hx with ⟨p, r, hp⟩ exact ⟨g.compFormalMultilinearSeries p, r, g.comp_hasFPowerSeriesOnBall hp⟩ #align continuous_linear_map.comp_analytic_on ContinuousLinearMap.comp_analyticOn /-- If a function admits a power series expansion, then it is exponentially close to the partial sums of this power series on strict subdisks of the disk of convergence. This version provides an upper estimate that decreases both in `‖y‖` and `n`. See also `HasFPowerSeriesOnBall.uniform_geometric_approx` for a weaker version. -/ theorem HasFPowerSeriesOnBall.uniform_geometric_approx' {r' : ℝ≥0} (hf : HasFPowerSeriesOnBall f p x r) (h : (r' : ℝ≥0∞) < r) : ∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ y ∈ Metric.ball (0 : E) r', ∀ n, ‖f (x + y) - p.partialSum n y‖ ≤ C * (a * (‖y‖ / r')) ^ n := by obtain ⟨a, ha, C, hC, hp⟩ : ∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ n, ‖p n‖ * (r' : ℝ) ^ n ≤ C * a ^ n := p.norm_mul_pow_le_mul_pow_of_lt_radius (h.trans_le hf.r_le) refine ⟨a, ha, C / (1 - a), div_pos hC (sub_pos.2 ha.2), fun y hy n => ?_⟩ have yr' : ‖y‖ < r' := by rw [ball_zero_eq] at hy exact hy have hr'0 : 0 < (r' : ℝ) := (norm_nonneg _).trans_lt yr' have : y ∈ EMetric.ball (0 : E) r := by refine mem_emetric_ball_zero_iff.2 (lt_trans ?_ h) exact mod_cast yr' rw [norm_sub_rev, ← mul_div_right_comm] have ya : a * (‖y‖ / ↑r') ≤ a := mul_le_of_le_one_right ha.1.le (div_le_one_of_le yr'.le r'.coe_nonneg) suffices ‖p.partialSum n y - f (x + y)‖ ≤ C * (a * (‖y‖ / r')) ^ n / (1 - a * (‖y‖ / r')) by refine this.trans ?_ have : 0 < a := ha.1 gcongr apply_rules [sub_pos.2, ha.2] apply norm_sub_le_of_geometric_bound_of_hasSum (ya.trans_lt ha.2) _ (hf.hasSum this) intro n calc ‖(p n) fun _ : Fin n => y‖ _ ≤ ‖p n‖ * ∏ _i : Fin n, ‖y‖ := ContinuousMultilinearMap.le_opNorm _ _ _ = ‖p n‖ * (r' : ℝ) ^ n * (‖y‖ / r') ^ n := by field_simp [mul_right_comm] _ ≤ C * a ^ n * (‖y‖ / r') ^ n := by gcongr ?_ * _; apply hp _ ≤ C * (a * (‖y‖ / r')) ^ n := by rw [mul_pow, mul_assoc] #align has_fpower_series_on_ball.uniform_geometric_approx' HasFPowerSeriesOnBall.uniform_geometric_approx' /-- If a function admits a power series expansion, then it is exponentially close to the partial sums of this power series on strict subdisks of the disk of convergence. -/ theorem HasFPowerSeriesOnBall.uniform_geometric_approx {r' : ℝ≥0} (hf : HasFPowerSeriesOnBall f p x r) (h : (r' : ℝ≥0∞) < r) : ∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ y ∈ Metric.ball (0 : E) r', ∀ n, ‖f (x + y) - p.partialSum n y‖ ≤ C * a ^ n := by obtain ⟨a, ha, C, hC, hp⟩ : ∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ y ∈ Metric.ball (0 : E) r', ∀ n, ‖f (x + y) - p.partialSum n y‖ ≤ C * (a * (‖y‖ / r')) ^ n := hf.uniform_geometric_approx' h refine ⟨a, ha, C, hC, fun y hy n => (hp y hy n).trans ?_⟩ have yr' : ‖y‖ < r' := by rwa [ball_zero_eq] at hy have := ha.1.le -- needed to discharge a side goal on the next line gcongr exact mul_le_of_le_one_right ha.1.le (div_le_one_of_le yr'.le r'.coe_nonneg) #align has_fpower_series_on_ball.uniform_geometric_approx HasFPowerSeriesOnBall.uniform_geometric_approx /-- Taylor formula for an analytic function, `IsBigO` version. -/ theorem HasFPowerSeriesAt.isBigO_sub_partialSum_pow (hf : HasFPowerSeriesAt f p x) (n : ℕ) : (fun y : E => f (x + y) - p.partialSum n y) =O[𝓝 0] fun y => ‖y‖ ^ n := by rcases hf with ⟨r, hf⟩ rcases ENNReal.lt_iff_exists_nnreal_btwn.1 hf.r_pos with ⟨r', r'0, h⟩ obtain ⟨a, -, C, -, hp⟩ : ∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ y ∈ Metric.ball (0 : E) r', ∀ n, ‖f (x + y) - p.partialSum n y‖ ≤ C * (a * (‖y‖ / r')) ^ n := hf.uniform_geometric_approx' h refine isBigO_iff.2 ⟨C * (a / r') ^ n, ?_⟩ replace r'0 : 0 < (r' : ℝ) := mod_cast r'0 filter_upwards [Metric.ball_mem_nhds (0 : E) r'0] with y hy simpa [mul_pow, mul_div_assoc, mul_assoc, div_mul_eq_mul_div] using hp y hy n set_option linter.uppercaseLean3 false in #align has_fpower_series_at.is_O_sub_partial_sum_pow HasFPowerSeriesAt.isBigO_sub_partialSum_pow /-- If `f` has formal power series `∑ n, pₙ` on a ball of radius `r`, then for `y, z` in any smaller ball, the norm of the difference `f y - f z - p 1 (fun _ ↦ y - z)` is bounded above by `C * (max ‖y - x‖ ‖z - x‖) * ‖y - z‖`. This lemma formulates this property using `IsBigO` and `Filter.principal` on `E × E`. -/ theorem HasFPowerSeriesOnBall.isBigO_image_sub_image_sub_deriv_principal (hf : HasFPowerSeriesOnBall f p x r) (hr : r' < r) : (fun y : E × E => f y.1 - f y.2 - p 1 fun _ => y.1 - y.2) =O[𝓟 (EMetric.ball (x, x) r')] fun y => ‖y - (x, x)‖ * ‖y.1 - y.2‖ := by lift r' to ℝ≥0 using ne_top_of_lt hr rcases (zero_le r').eq_or_lt with (rfl | hr'0) · simp only [isBigO_bot, EMetric.ball_zero, principal_empty, ENNReal.coe_zero] obtain ⟨a, ha, C, hC : 0 < C, hp⟩ : ∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ n : ℕ, ‖p n‖ * (r' : ℝ) ^ n ≤ C * a ^ n := p.norm_mul_pow_le_mul_pow_of_lt_radius (hr.trans_le hf.r_le) simp only [← le_div_iff (pow_pos (NNReal.coe_pos.2 hr'0) _)] at hp set L : E × E → ℝ := fun y => C * (a / r') ^ 2 * (‖y - (x, x)‖ * ‖y.1 - y.2‖) * (a / (1 - a) ^ 2 + 2 / (1 - a)) have hL : ∀ y ∈ EMetric.ball (x, x) r', ‖f y.1 - f y.2 - p 1 fun _ => y.1 - y.2‖ ≤ L y := by intro y hy' have hy : y ∈ EMetric.ball x r ×ˢ EMetric.ball x r := by rw [EMetric.ball_prod_same] exact EMetric.ball_subset_ball hr.le hy' set A : ℕ → F := fun n => (p n fun _ => y.1 - x) - p n fun _ => y.2 - x have hA : HasSum (fun n => A (n + 2)) (f y.1 - f y.2 - p 1 fun _ => y.1 - y.2) := by convert (hasSum_nat_add_iff' 2).2 ((hf.hasSum_sub hy.1).sub (hf.hasSum_sub hy.2)) using 1 rw [Finset.sum_range_succ, Finset.sum_range_one, hf.coeff_zero, hf.coeff_zero, sub_self, zero_add, ← Subsingleton.pi_single_eq (0 : Fin 1) (y.1 - x), Pi.single, ← Subsingleton.pi_single_eq (0 : Fin 1) (y.2 - x), Pi.single, ← (p 1).map_sub, ← Pi.single, Subsingleton.pi_single_eq, sub_sub_sub_cancel_right] rw [EMetric.mem_ball, edist_eq_coe_nnnorm_sub, ENNReal.coe_lt_coe] at hy' set B : ℕ → ℝ := fun n => C * (a / r') ^ 2 * (‖y - (x, x)‖ * ‖y.1 - y.2‖) * ((n + 2) * a ^ n) have hAB : ∀ n, ‖A (n + 2)‖ ≤ B n := fun n => calc ‖A (n + 2)‖ ≤ ‖p (n + 2)‖ * ↑(n + 2) * ‖y - (x, x)‖ ^ (n + 1) * ‖y.1 - y.2‖ := by -- Porting note: `pi_norm_const` was `pi_norm_const (_ : E)` simpa only [Fintype.card_fin, pi_norm_const, Prod.norm_def, Pi.sub_def, Prod.fst_sub, Prod.snd_sub, sub_sub_sub_cancel_right] using (p <| n + 2).norm_image_sub_le (fun _ => y.1 - x) fun _ => y.2 - x _ = ‖p (n + 2)‖ * ‖y - (x, x)‖ ^ n * (↑(n + 2) * ‖y - (x, x)‖ * ‖y.1 - y.2‖) := by rw [pow_succ ‖y - (x, x)‖] ring -- Porting note: the two `↑` in `↑r'` are new, without them, Lean fails to synthesize -- instances `HDiv ℝ ℝ≥0 ?m` or `HMul ℝ ℝ≥0 ?m` _ ≤ C * a ^ (n + 2) / ↑r' ^ (n + 2) * ↑r' ^ n * (↑(n + 2) * ‖y - (x, x)‖ * ‖y.1 - y.2‖) := by have : 0 < a := ha.1 gcongr · apply hp · apply hy'.le _ = B n := by field_simp [B, pow_succ] simp only [mul_assoc, mul_comm, mul_left_comm] have hBL : HasSum B (L y) := by apply HasSum.mul_left simp only [add_mul] have : ‖a‖ < 1 := by simp only [Real.norm_eq_abs, abs_of_pos ha.1, ha.2] rw [div_eq_mul_inv, div_eq_mul_inv] exact (hasSum_coe_mul_geometric_of_norm_lt_one this).add -- Porting note: was `convert`! ((hasSum_geometric_of_norm_lt_one this).mul_left 2) exact hA.norm_le_of_bounded hBL hAB suffices L =O[𝓟 (EMetric.ball (x, x) r')] fun y => ‖y - (x, x)‖ * ‖y.1 - y.2‖ by refine (IsBigO.of_bound 1 (eventually_principal.2 fun y hy => ?_)).trans this rw [one_mul] exact (hL y hy).trans (le_abs_self _) simp_rw [L, mul_right_comm _ (_ * _)] exact (isBigO_refl _ _).const_mul_left _ set_option linter.uppercaseLean3 false in #align has_fpower_series_on_ball.is_O_image_sub_image_sub_deriv_principal HasFPowerSeriesOnBall.isBigO_image_sub_image_sub_deriv_principal /-- If `f` has formal power series `∑ n, pₙ` on a ball of radius `r`, then for `y, z` in any smaller ball, the norm of the difference `f y - f z - p 1 (fun _ ↦ y - z)` is bounded above by `C * (max ‖y - x‖ ‖z - x‖) * ‖y - z‖`. -/ theorem HasFPowerSeriesOnBall.image_sub_sub_deriv_le (hf : HasFPowerSeriesOnBall f p x r) (hr : r' < r) : ∃ C, ∀ᵉ (y ∈ EMetric.ball x r') (z ∈ EMetric.ball x r'), ‖f y - f z - p 1 fun _ => y - z‖ ≤ C * max ‖y - x‖ ‖z - x‖ * ‖y - z‖ := by simpa only [isBigO_principal, mul_assoc, norm_mul, norm_norm, Prod.forall, EMetric.mem_ball, Prod.edist_eq, max_lt_iff, and_imp, @forall_swap (_ < _) E] using hf.isBigO_image_sub_image_sub_deriv_principal hr #align has_fpower_series_on_ball.image_sub_sub_deriv_le HasFPowerSeriesOnBall.image_sub_sub_deriv_le /-- If `f` has formal power series `∑ n, pₙ` at `x`, then `f y - f z - p 1 (fun _ ↦ y - z) = O(‖(y, z) - (x, x)‖ * ‖y - z‖)` as `(y, z) → (x, x)`. In particular, `f` is strictly differentiable at `x`. -/ theorem HasFPowerSeriesAt.isBigO_image_sub_norm_mul_norm_sub (hf : HasFPowerSeriesAt f p x) : (fun y : E × E => f y.1 - f y.2 - p 1 fun _ => y.1 - y.2) =O[𝓝 (x, x)] fun y => ‖y - (x, x)‖ * ‖y.1 - y.2‖ := by rcases hf with ⟨r, hf⟩ rcases ENNReal.lt_iff_exists_nnreal_btwn.1 hf.r_pos with ⟨r', r'0, h⟩ refine (hf.isBigO_image_sub_image_sub_deriv_principal h).mono ?_ exact le_principal_iff.2 (EMetric.ball_mem_nhds _ r'0) set_option linter.uppercaseLean3 false in #align has_fpower_series_at.is_O_image_sub_norm_mul_norm_sub HasFPowerSeriesAt.isBigO_image_sub_norm_mul_norm_sub /-- If a function admits a power series expansion at `x`, then it is the uniform limit of the partial sums of this power series on strict subdisks of the disk of convergence, i.e., `f (x + y)` is the uniform limit of `p.partialSum n y` there. -/ theorem HasFPowerSeriesOnBall.tendstoUniformlyOn {r' : ℝ≥0} (hf : HasFPowerSeriesOnBall f p x r) (h : (r' : ℝ≥0∞) < r) : TendstoUniformlyOn (fun n y => p.partialSum n y) (fun y => f (x + y)) atTop (Metric.ball (0 : E) r') := by obtain ⟨a, ha, C, -, hp⟩ : ∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ y ∈ Metric.ball (0 : E) r', ∀ n, ‖f (x + y) - p.partialSum n y‖ ≤ C * a ^ n := hf.uniform_geometric_approx h refine Metric.tendstoUniformlyOn_iff.2 fun ε εpos => ?_ have L : Tendsto (fun n => (C : ℝ) * a ^ n) atTop (𝓝 ((C : ℝ) * 0)) := tendsto_const_nhds.mul (tendsto_pow_atTop_nhds_zero_of_lt_one ha.1.le ha.2) rw [mul_zero] at L refine (L.eventually (gt_mem_nhds εpos)).mono fun n hn y hy => ?_ rw [dist_eq_norm] exact (hp y hy n).trans_lt hn #align has_fpower_series_on_ball.tendsto_uniformly_on HasFPowerSeriesOnBall.tendstoUniformlyOn /-- If a function admits a power series expansion at `x`, then it is the locally uniform limit of the partial sums of this power series on the disk of convergence, i.e., `f (x + y)` is the locally uniform limit of `p.partialSum n y` there. -/ theorem HasFPowerSeriesOnBall.tendstoLocallyUniformlyOn (hf : HasFPowerSeriesOnBall f p x r) : TendstoLocallyUniformlyOn (fun n y => p.partialSum n y) (fun y => f (x + y)) atTop (EMetric.ball (0 : E) r) := by intro u hu x hx rcases ENNReal.lt_iff_exists_nnreal_btwn.1 hx with ⟨r', xr', hr'⟩ have : EMetric.ball (0 : E) r' ∈ 𝓝 x := IsOpen.mem_nhds EMetric.isOpen_ball xr' refine ⟨EMetric.ball (0 : E) r', mem_nhdsWithin_of_mem_nhds this, ?_⟩ simpa [Metric.emetric_ball_nnreal] using hf.tendstoUniformlyOn hr' u hu #align has_fpower_series_on_ball.tendsto_locally_uniformly_on HasFPowerSeriesOnBall.tendstoLocallyUniformlyOn /-- If a function admits a power series expansion at `x`, then it is the uniform limit of the partial sums of this power series on strict subdisks of the disk of convergence, i.e., `f y` is the uniform limit of `p.partialSum n (y - x)` there. -/
Mathlib/Analysis/Analytic/Basic.lean
855
861
theorem HasFPowerSeriesOnBall.tendstoUniformlyOn' {r' : ℝ≥0} (hf : HasFPowerSeriesOnBall f p x r) (h : (r' : ℝ≥0∞) < r) : TendstoUniformlyOn (fun n y => p.partialSum n (y - x)) f atTop (Metric.ball (x : E) r') := by
convert (hf.tendstoUniformlyOn h).comp fun y => y - x using 1 · simp [(· ∘ ·)] · ext z simp [dist_eq_norm]
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Kenny Lau, Scott Morrison -/ import Mathlib.Data.List.Chain import Mathlib.Data.List.Enum import Mathlib.Data.List.Nodup import Mathlib.Data.List.Pairwise import Mathlib.Data.List.Zip #align_import data.list.range from "leanprover-community/mathlib"@"7b78d1776212a91ecc94cf601f83bdcc46b04213" /-! # Ranges of naturals as lists This file shows basic results about `List.iota`, `List.range`, `List.range'` and defines `List.finRange`. `finRange n` is the list of elements of `Fin n`. `iota n = [n, n - 1, ..., 1]` and `range n = [0, ..., n - 1]` are basic list constructions used for tactics. `range' a b = [a, ..., a + b - 1]` is there to help prove properties about them. Actual maths should use `List.Ico` instead. -/ set_option autoImplicit true universe u open Nat namespace List variable {α : Type u} @[simp] theorem range'_one {step} : range' s 1 step = [s] := rfl #align list.length_range' List.length_range' #align list.range'_eq_nil List.range'_eq_nil #align list.mem_range' List.mem_range'_1 #align list.map_add_range' List.map_add_range' #align list.map_sub_range' List.map_sub_range' #align list.chain_succ_range' List.chain_succ_range' #align list.chain_lt_range' List.chain_lt_range' theorem pairwise_lt_range' : ∀ s n (step := 1) (_ : 0 < step := by simp), Pairwise (· < ·) (range' s n step) | _, 0, _, _ => Pairwise.nil | s, n + 1, _, h => chain_iff_pairwise.1 (chain_lt_range' s n h) #align list.pairwise_lt_range' List.pairwise_lt_range' theorem nodup_range' (s n : ℕ) (step := 1) (h : 0 < step := by simp) : Nodup (range' s n step) := (pairwise_lt_range' s n step h).imp _root_.ne_of_lt #align list.nodup_range' List.nodup_range' #align list.range'_append List.range'_append #align list.range'_sublist_right List.range'_sublist_right #align list.range'_subset_right List.range'_subset_right #align list.nth_range' List.get?_range' set_option linter.deprecated false in @[simp] theorem nthLe_range' {n m step} (i) (H : i < (range' n m step).length) : nthLe (range' n m step) i H = n + step * i := get_range' i H set_option linter.deprecated false in theorem nthLe_range'_1 {n m} (i) (H : i < (range' n m).length) : nthLe (range' n m) i H = n + i := by simp #align list.nth_le_range' List.nthLe_range'_1 #align list.range'_concat List.range'_concat #align list.range_core List.range.loop #align list.range_core_range' List.range_loop_range' #align list.range_eq_range' List.range_eq_range' #align list.range_succ_eq_map List.range_succ_eq_map #align list.range'_eq_map_range List.range'_eq_map_range #align list.length_range List.length_range #align list.range_eq_nil List.range_eq_nil theorem pairwise_lt_range (n : ℕ) : Pairwise (· < ·) (range n) := by simp (config := {decide := true}) only [range_eq_range', pairwise_lt_range'] #align list.pairwise_lt_range List.pairwise_lt_range theorem pairwise_le_range (n : ℕ) : Pairwise (· ≤ ·) (range n) := Pairwise.imp (@le_of_lt ℕ _) (pairwise_lt_range _) #align list.pairwise_le_range List.pairwise_le_range theorem take_range (m n : ℕ) : take m (range n) = range (min m n) := by apply List.ext_get · simp · simp (config := { contextual := true }) [← get_take, Nat.lt_min] theorem nodup_range (n : ℕ) : Nodup (range n) := by simp (config := {decide := true}) only [range_eq_range', nodup_range'] #align list.nodup_range List.nodup_range #align list.range_sublist List.range_sublist #align list.range_subset List.range_subset #align list.mem_range List.mem_range #align list.not_mem_range_self List.not_mem_range_self #align list.self_mem_range_succ List.self_mem_range_succ #align list.nth_range List.get?_range #align list.range_succ List.range_succ #align list.range_zero List.range_zero theorem chain'_range_succ (r : ℕ → ℕ → Prop) (n : ℕ) : Chain' r (range n.succ) ↔ ∀ m < n, r m m.succ := by rw [range_succ] induction' n with n hn · simp · rw [range_succ] simp only [append_assoc, singleton_append, chain'_append_cons_cons, chain'_singleton, and_true_iff] rw [hn, forall_lt_succ] #align list.chain'_range_succ List.chain'_range_succ theorem chain_range_succ (r : ℕ → ℕ → Prop) (n a : ℕ) : Chain r a (range n.succ) ↔ r a 0 ∧ ∀ m < n, r m m.succ := by rw [range_succ_eq_map, chain_cons, and_congr_right_iff, ← chain'_range_succ, range_succ_eq_map] exact fun _ => Iff.rfl #align list.chain_range_succ List.chain_range_succ #align list.range_add List.range_add #align list.iota_eq_reverse_range' List.iota_eq_reverse_range' #align list.length_iota List.length_iota theorem pairwise_gt_iota (n : ℕ) : Pairwise (· > ·) (iota n) := by simpa only [iota_eq_reverse_range', pairwise_reverse] using pairwise_lt_range' 1 n #align list.pairwise_gt_iota List.pairwise_gt_iota theorem nodup_iota (n : ℕ) : Nodup (iota n) := (pairwise_gt_iota n).imp _root_.ne_of_gt #align list.nodup_iota List.nodup_iota #align list.mem_iota List.mem_iota #align list.reverse_range' List.reverse_range' /-- All elements of `Fin n`, from `0` to `n-1`. The corresponding finset is `Finset.univ`. -/ def finRange (n : ℕ) : List (Fin n) := (range n).pmap Fin.mk fun _ => List.mem_range.1 #align list.fin_range List.finRange @[simp] theorem finRange_zero : finRange 0 = [] := rfl #align list.fin_range_zero List.finRange_zero @[simp] theorem mem_finRange {n : ℕ} (a : Fin n) : a ∈ finRange n := mem_pmap.2 ⟨a.1, mem_range.2 a.2, by cases a rfl⟩ #align list.mem_fin_range List.mem_finRange theorem nodup_finRange (n : ℕ) : (finRange n).Nodup := (Pairwise.pmap (nodup_range n) _) fun _ _ _ _ => @Fin.ne_of_vne _ ⟨_, _⟩ ⟨_, _⟩ #align list.nodup_fin_range List.nodup_finRange @[simp] theorem length_finRange (n : ℕ) : (finRange n).length = n := by rw [finRange, length_pmap, length_range] #align list.length_fin_range List.length_finRange @[simp] theorem finRange_eq_nil {n : ℕ} : finRange n = [] ↔ n = 0 := by rw [← length_eq_zero, length_finRange] #align list.fin_range_eq_nil List.finRange_eq_nil theorem pairwise_lt_finRange (n : ℕ) : Pairwise (· < ·) (finRange n) := (List.pairwise_lt_range n).pmap (by simp) (by simp) theorem pairwise_le_finRange (n : ℕ) : Pairwise (· ≤ ·) (finRange n) := (List.pairwise_le_range n).pmap (by simp) (by simp) #align list.enum_from_map_fst List.enumFrom_map_fst #align list.enum_map_fst List.enum_map_fst theorem enum_eq_zip_range (l : List α) : l.enum = (range l.length).zip l := zip_of_prod (enum_map_fst _) (enum_map_snd _) #align list.enum_eq_zip_range List.enum_eq_zip_range @[simp] theorem unzip_enum_eq_prod (l : List α) : l.enum.unzip = (range l.length, l) := by simp only [enum_eq_zip_range, unzip_zip, length_range] #align list.unzip_enum_eq_prod List.unzip_enum_eq_prod theorem enumFrom_eq_zip_range' (l : List α) {n : ℕ} : l.enumFrom n = (range' n l.length).zip l := zip_of_prod (enumFrom_map_fst _ _) (enumFrom_map_snd _ _) #align list.enum_from_eq_zip_range' List.enumFrom_eq_zip_range' @[simp]
Mathlib/Data/List/Range.lean
191
193
theorem unzip_enumFrom_eq_prod (l : List α) {n : ℕ} : (l.enumFrom n).unzip = (range' n l.length, l) := by
simp only [enumFrom_eq_zip_range', unzip_zip, length_range']
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.Group.Submonoid.Membership import Mathlib.Algebra.Order.BigOperators.Group.List import Mathlib.Data.Set.Pointwise.SMul import Mathlib.Order.WellFoundedSet #align_import group_theory.submonoid.pointwise from "leanprover-community/mathlib"@"2bbc7e3884ba234309d2a43b19144105a753292e" /-! # Pointwise instances on `Submonoid`s and `AddSubmonoid`s This file provides: * `Submonoid.inv` * `AddSubmonoid.neg` and the actions * `Submonoid.pointwiseMulAction` * `AddSubmonoid.pointwiseMulAction` which matches the action of `Set.mulActionSet`. These are all available in the `Pointwise` locale. Additionally, it provides various degrees of monoid structure: * `AddSubmonoid.one` * `AddSubmonoid.mul` * `AddSubmonoid.mulOneClass` * `AddSubmonoid.semigroup` * `AddSubmonoid.monoid` which is available globally to match the monoid structure implied by `Submodule.idemSemiring`. ## Implementation notes Most of the lemmas in this file are direct copies of lemmas from `Algebra/Pointwise.lean`. While the statements of these lemmas are defeq, we repeat them here due to them not being syntactically equal. Before adding new lemmas here, consider if they would also apply to the action on `Set`s. -/ open Set Pointwise variable {α : Type*} {G : Type*} {M : Type*} {R : Type*} {A : Type*} variable [Monoid M] [AddMonoid A] /-! Some lemmas about pointwise multiplication and submonoids. Ideally we put these in `GroupTheory.Submonoid.Basic`, but currently we cannot because that file is imported by this. -/ namespace Submonoid variable {s t u : Set M} @[to_additive] theorem mul_subset {S : Submonoid M} (hs : s ⊆ S) (ht : t ⊆ S) : s * t ⊆ S := mul_subset_iff.2 fun _x hx _y hy ↦ mul_mem (hs hx) (ht hy) #align submonoid.mul_subset Submonoid.mul_subset #align add_submonoid.add_subset AddSubmonoid.add_subset @[to_additive] theorem mul_subset_closure (hs : s ⊆ u) (ht : t ⊆ u) : s * t ⊆ Submonoid.closure u := mul_subset (Subset.trans hs Submonoid.subset_closure) (Subset.trans ht Submonoid.subset_closure) #align submonoid.mul_subset_closure Submonoid.mul_subset_closure #align add_submonoid.add_subset_closure AddSubmonoid.add_subset_closure @[to_additive] theorem coe_mul_self_eq (s : Submonoid M) : (s : Set M) * s = s := by ext x refine ⟨?_, fun h => ⟨x, h, 1, s.one_mem, mul_one x⟩⟩ rintro ⟨a, ha, b, hb, rfl⟩ exact s.mul_mem ha hb #align submonoid.coe_mul_self_eq Submonoid.coe_mul_self_eq #align add_submonoid.coe_add_self_eq AddSubmonoid.coe_add_self_eq @[to_additive] theorem closure_mul_le (S T : Set M) : closure (S * T) ≤ closure S ⊔ closure T := sInf_le fun _x ⟨_s, hs, _t, ht, hx⟩ => hx ▸ (closure S ⊔ closure T).mul_mem (SetLike.le_def.mp le_sup_left <| subset_closure hs) (SetLike.le_def.mp le_sup_right <| subset_closure ht) #align submonoid.closure_mul_le Submonoid.closure_mul_le #align add_submonoid.closure_add_le AddSubmonoid.closure_add_le @[to_additive] theorem sup_eq_closure_mul (H K : Submonoid M) : H ⊔ K = closure ((H : Set M) * (K : Set M)) := le_antisymm (sup_le (fun h hh => subset_closure ⟨h, hh, 1, K.one_mem, mul_one h⟩) fun k hk => subset_closure ⟨1, H.one_mem, k, hk, one_mul k⟩) ((closure_mul_le _ _).trans <| by rw [closure_eq, closure_eq]) #align submonoid.sup_eq_closure Submonoid.sup_eq_closure_mul #align add_submonoid.sup_eq_closure AddSubmonoid.sup_eq_closure_add @[to_additive] theorem pow_smul_mem_closure_smul {N : Type*} [CommMonoid N] [MulAction M N] [IsScalarTower M N N] (r : M) (s : Set N) {x : N} (hx : x ∈ closure s) : ∃ n : ℕ, r ^ n • x ∈ closure (r • s) := by refine @closure_induction N _ s (fun x : N => ∃ n : ℕ, r ^ n • x ∈ closure (r • s)) _ hx ?_ ?_ ?_ · intro x hx exact ⟨1, subset_closure ⟨_, hx, by rw [pow_one]⟩⟩ · exact ⟨0, by simpa using one_mem _⟩ · rintro x y ⟨nx, hx⟩ ⟨ny, hy⟩ use ny + nx rw [pow_add, mul_smul, ← smul_mul_assoc, mul_comm, ← smul_mul_assoc] exact mul_mem hy hx #align submonoid.pow_smul_mem_closure_smul Submonoid.pow_smul_mem_closure_smul #align add_submonoid.nsmul_vadd_mem_closure_vadd AddSubmonoid.nsmul_vadd_mem_closure_vadd variable [Group G] /-- The submonoid with every element inverted. -/ @[to_additive " The additive submonoid with every element negated. "] protected def inv : Inv (Submonoid G) where inv S := { carrier := (S : Set G)⁻¹ mul_mem' := fun ha hb => by rw [mem_inv, mul_inv_rev]; exact mul_mem hb ha one_mem' := mem_inv.2 <| by rw [inv_one]; exact S.one_mem' } #align submonoid.has_inv Submonoid.inv #align add_submonoid.has_neg AddSubmonoid.neg scoped[Pointwise] attribute [instance] Submonoid.inv AddSubmonoid.neg @[to_additive (attr := simp)] theorem coe_inv (S : Submonoid G) : ↑S⁻¹ = (S : Set G)⁻¹ := rfl #align submonoid.coe_inv Submonoid.coe_inv #align add_submonoid.coe_neg AddSubmonoid.coe_neg @[to_additive (attr := simp)] theorem mem_inv {g : G} {S : Submonoid G} : g ∈ S⁻¹ ↔ g⁻¹ ∈ S := Iff.rfl #align submonoid.mem_inv Submonoid.mem_inv #align add_submonoid.mem_neg AddSubmonoid.mem_neg /-- Inversion is involutive on submonoids. -/ @[to_additive "Inversion is involutive on additive submonoids."] def involutiveInv : InvolutiveInv (Submonoid G) := SetLike.coe_injective.involutiveInv _ fun _ => rfl scoped[Pointwise] attribute [instance] Submonoid.involutiveInv AddSubmonoid.involutiveNeg @[to_additive (attr := simp)] theorem inv_le_inv (S T : Submonoid G) : S⁻¹ ≤ T⁻¹ ↔ S ≤ T := SetLike.coe_subset_coe.symm.trans Set.inv_subset_inv #align submonoid.inv_le_inv Submonoid.inv_le_inv #align add_submonoid.neg_le_neg AddSubmonoid.neg_le_neg @[to_additive] theorem inv_le (S T : Submonoid G) : S⁻¹ ≤ T ↔ S ≤ T⁻¹ := SetLike.coe_subset_coe.symm.trans Set.inv_subset #align submonoid.inv_le Submonoid.inv_le #align add_submonoid.neg_le AddSubmonoid.neg_le /-- Pointwise inversion of submonoids as an order isomorphism. -/ @[to_additive (attr := simps!) "Pointwise negation of additive submonoids as an order isomorphism"] def invOrderIso : Submonoid G ≃o Submonoid G where toEquiv := Equiv.inv _ map_rel_iff' := inv_le_inv _ _ #align submonoid.inv_order_iso Submonoid.invOrderIso #align add_submonoid.neg_order_iso AddSubmonoid.negOrderIso @[to_additive] theorem closure_inv (s : Set G) : closure s⁻¹ = (closure s)⁻¹ := by apply le_antisymm · rw [closure_le, coe_inv, ← Set.inv_subset, inv_inv] exact subset_closure · rw [inv_le, closure_le, coe_inv, ← Set.inv_subset] exact subset_closure #align submonoid.closure_inv Submonoid.closure_inv #align add_submonoid.closure_neg AddSubmonoid.closure_neg @[to_additive (attr := simp)] theorem inv_inf (S T : Submonoid G) : (S ⊓ T)⁻¹ = S⁻¹ ⊓ T⁻¹ := SetLike.coe_injective Set.inter_inv #align submonoid.inv_inf Submonoid.inv_inf #align add_submonoid.neg_inf AddSubmonoid.neg_inf @[to_additive (attr := simp)] theorem inv_sup (S T : Submonoid G) : (S ⊔ T)⁻¹ = S⁻¹ ⊔ T⁻¹ := (invOrderIso : Submonoid G ≃o Submonoid G).map_sup S T #align submonoid.inv_sup Submonoid.inv_sup #align add_submonoid.neg_sup AddSubmonoid.neg_sup @[to_additive (attr := simp)] theorem inv_bot : (⊥ : Submonoid G)⁻¹ = ⊥ := SetLike.coe_injective <| (Set.inv_singleton 1).trans <| congr_arg _ inv_one #align submonoid.inv_bot Submonoid.inv_bot #align add_submonoid.neg_bot AddSubmonoid.neg_bot @[to_additive (attr := simp)] theorem inv_top : (⊤ : Submonoid G)⁻¹ = ⊤ := SetLike.coe_injective <| Set.inv_univ #align submonoid.inv_top Submonoid.inv_top #align add_submonoid.neg_top AddSubmonoid.neg_top @[to_additive (attr := simp)] theorem inv_iInf {ι : Sort*} (S : ι → Submonoid G) : (⨅ i, S i)⁻¹ = ⨅ i, (S i)⁻¹ := (invOrderIso : Submonoid G ≃o Submonoid G).map_iInf _ #align submonoid.inv_infi Submonoid.inv_iInf #align add_submonoid.neg_infi AddSubmonoid.neg_iInf @[to_additive (attr := simp)] theorem inv_iSup {ι : Sort*} (S : ι → Submonoid G) : (⨆ i, S i)⁻¹ = ⨆ i, (S i)⁻¹ := (invOrderIso : Submonoid G ≃o Submonoid G).map_iSup _ #align submonoid.inv_supr Submonoid.inv_iSup #align add_submonoid.neg_supr AddSubmonoid.neg_iSup end Submonoid namespace Submonoid section Monoid variable [Monoid α] [MulDistribMulAction α M] -- todo: add `to_additive`? /-- The action on a submonoid corresponding to applying the action to every element. This is available as an instance in the `Pointwise` locale. -/ protected def pointwiseMulAction : MulAction α (Submonoid M) where smul a S := S.map (MulDistribMulAction.toMonoidEnd _ M a) one_smul S := by change S.map _ = S simpa only [map_one] using S.map_id mul_smul a₁ a₂ S := (congr_arg (fun f : Monoid.End M => S.map f) (MonoidHom.map_mul _ _ _)).trans (S.map_map _ _).symm #align submonoid.pointwise_mul_action Submonoid.pointwiseMulAction scoped[Pointwise] attribute [instance] Submonoid.pointwiseMulAction @[simp] theorem coe_pointwise_smul (a : α) (S : Submonoid M) : ↑(a • S) = a • (S : Set M) := rfl #align submonoid.coe_pointwise_smul Submonoid.coe_pointwise_smul theorem smul_mem_pointwise_smul (m : M) (a : α) (S : Submonoid M) : m ∈ S → a • m ∈ a • S := (Set.smul_mem_smul_set : _ → _ ∈ a • (S : Set M)) #align submonoid.smul_mem_pointwise_smul Submonoid.smul_mem_pointwise_smul instance : CovariantClass α (Submonoid M) HSMul.hSMul LE.le := ⟨fun _ _ => image_subset _⟩ theorem mem_smul_pointwise_iff_exists (m : M) (a : α) (S : Submonoid M) : m ∈ a • S ↔ ∃ s : M, s ∈ S ∧ a • s = m := (Set.mem_smul_set : m ∈ a • (S : Set M) ↔ _) #align submonoid.mem_smul_pointwise_iff_exists Submonoid.mem_smul_pointwise_iff_exists @[simp] theorem smul_bot (a : α) : a • (⊥ : Submonoid M) = ⊥ := map_bot _ #align submonoid.smul_bot Submonoid.smul_bot theorem smul_sup (a : α) (S T : Submonoid M) : a • (S ⊔ T) = a • S ⊔ a • T := map_sup _ _ _ #align submonoid.smul_sup Submonoid.smul_sup theorem smul_closure (a : α) (s : Set M) : a • closure s = closure (a • s) := MonoidHom.map_mclosure _ _ #align submonoid.smul_closure Submonoid.smul_closure lemma pointwise_isCentralScalar [MulDistribMulAction αᵐᵒᵖ M] [IsCentralScalar α M] : IsCentralScalar α (Submonoid M) := ⟨fun _ S => (congr_arg fun f : Monoid.End M => S.map f) <| MonoidHom.ext <| op_smul_eq_smul _⟩ #align submonoid.pointwise_central_scalar Submonoid.pointwise_isCentralScalar scoped[Pointwise] attribute [instance] Submonoid.pointwise_isCentralScalar end Monoid section Group variable [Group α] [MulDistribMulAction α M] @[simp] theorem smul_mem_pointwise_smul_iff {a : α} {S : Submonoid M} {x : M} : a • x ∈ a • S ↔ x ∈ S := smul_mem_smul_set_iff #align submonoid.smul_mem_pointwise_smul_iff Submonoid.smul_mem_pointwise_smul_iff theorem mem_pointwise_smul_iff_inv_smul_mem {a : α} {S : Submonoid M} {x : M} : x ∈ a • S ↔ a⁻¹ • x ∈ S := mem_smul_set_iff_inv_smul_mem #align submonoid.mem_pointwise_smul_iff_inv_smul_mem Submonoid.mem_pointwise_smul_iff_inv_smul_mem theorem mem_inv_pointwise_smul_iff {a : α} {S : Submonoid M} {x : M} : x ∈ a⁻¹ • S ↔ a • x ∈ S := mem_inv_smul_set_iff #align submonoid.mem_inv_pointwise_smul_iff Submonoid.mem_inv_pointwise_smul_iff @[simp] theorem pointwise_smul_le_pointwise_smul_iff {a : α} {S T : Submonoid M} : a • S ≤ a • T ↔ S ≤ T := set_smul_subset_set_smul_iff #align submonoid.pointwise_smul_le_pointwise_smul_iff Submonoid.pointwise_smul_le_pointwise_smul_iff theorem pointwise_smul_subset_iff {a : α} {S T : Submonoid M} : a • S ≤ T ↔ S ≤ a⁻¹ • T := set_smul_subset_iff #align submonoid.pointwise_smul_subset_iff Submonoid.pointwise_smul_subset_iff theorem subset_pointwise_smul_iff {a : α} {S T : Submonoid M} : S ≤ a • T ↔ a⁻¹ • S ≤ T := subset_set_smul_iff #align submonoid.subset_pointwise_smul_iff Submonoid.subset_pointwise_smul_iff end Group section GroupWithZero variable [GroupWithZero α] [MulDistribMulAction α M] @[simp] theorem smul_mem_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) (S : Submonoid M) (x : M) : a • x ∈ a • S ↔ x ∈ S := smul_mem_smul_set_iff₀ ha (S : Set M) x #align submonoid.smul_mem_pointwise_smul_iff₀ Submonoid.smul_mem_pointwise_smul_iff₀ theorem mem_pointwise_smul_iff_inv_smul_mem₀ {a : α} (ha : a ≠ 0) (S : Submonoid M) (x : M) : x ∈ a • S ↔ a⁻¹ • x ∈ S := mem_smul_set_iff_inv_smul_mem₀ ha (S : Set M) x #align submonoid.mem_pointwise_smul_iff_inv_smul_mem₀ Submonoid.mem_pointwise_smul_iff_inv_smul_mem₀ theorem mem_inv_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) (S : Submonoid M) (x : M) : x ∈ a⁻¹ • S ↔ a • x ∈ S := mem_inv_smul_set_iff₀ ha (S : Set M) x #align submonoid.mem_inv_pointwise_smul_iff₀ Submonoid.mem_inv_pointwise_smul_iff₀ @[simp] theorem pointwise_smul_le_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) {S T : Submonoid M} : a • S ≤ a • T ↔ S ≤ T := set_smul_subset_set_smul_iff₀ ha #align submonoid.pointwise_smul_le_pointwise_smul_iff₀ Submonoid.pointwise_smul_le_pointwise_smul_iff₀ theorem pointwise_smul_le_iff₀ {a : α} (ha : a ≠ 0) {S T : Submonoid M} : a • S ≤ T ↔ S ≤ a⁻¹ • T := set_smul_subset_iff₀ ha #align submonoid.pointwise_smul_le_iff₀ Submonoid.pointwise_smul_le_iff₀ theorem le_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) {S T : Submonoid M} : S ≤ a • T ↔ a⁻¹ • S ≤ T := subset_set_smul_iff₀ ha #align submonoid.le_pointwise_smul_iff₀ Submonoid.le_pointwise_smul_iff₀ end GroupWithZero @[to_additive] theorem mem_closure_inv {G : Type*} [Group G] (S : Set G) (x : G) : x ∈ Submonoid.closure S⁻¹ ↔ x⁻¹ ∈ Submonoid.closure S := by rw [closure_inv, mem_inv] #align submonoid.mem_closure_inv Submonoid.mem_closure_inv #align add_submonoid.mem_closure_neg AddSubmonoid.mem_closure_neg end Submonoid namespace AddSubmonoid section Monoid variable [Monoid α] [DistribMulAction α A] /-- The action on an additive submonoid corresponding to applying the action to every element. This is available as an instance in the `Pointwise` locale. -/ protected def pointwiseMulAction : MulAction α (AddSubmonoid A) where smul a S := S.map (DistribMulAction.toAddMonoidEnd _ A a) one_smul S := (congr_arg (fun f : AddMonoid.End A => S.map f) (MonoidHom.map_one _)).trans S.map_id mul_smul _ _ S := (congr_arg (fun f : AddMonoid.End A => S.map f) (MonoidHom.map_mul _ _ _)).trans (S.map_map _ _).symm #align add_submonoid.pointwise_mul_action AddSubmonoid.pointwiseMulAction scoped[Pointwise] attribute [instance] AddSubmonoid.pointwiseMulAction @[simp] theorem coe_pointwise_smul (a : α) (S : AddSubmonoid A) : ↑(a • S) = a • (S : Set A) := rfl #align add_submonoid.coe_pointwise_smul AddSubmonoid.coe_pointwise_smul theorem smul_mem_pointwise_smul (m : A) (a : α) (S : AddSubmonoid A) : m ∈ S → a • m ∈ a • S := (Set.smul_mem_smul_set : _ → _ ∈ a • (S : Set A)) #align add_submonoid.smul_mem_pointwise_smul AddSubmonoid.smul_mem_pointwise_smul theorem mem_smul_pointwise_iff_exists (m : A) (a : α) (S : AddSubmonoid A) : m ∈ a • S ↔ ∃ s : A, s ∈ S ∧ a • s = m := (Set.mem_smul_set : m ∈ a • (S : Set A) ↔ _) #align add_submonoid.mem_smul_pointwise_iff_exists AddSubmonoid.mem_smul_pointwise_iff_exists @[simp] theorem smul_bot (a : α) : a • (⊥ : AddSubmonoid A) = ⊥ := map_bot _ #align add_submonoid.smul_bot AddSubmonoid.smul_bot theorem smul_sup (a : α) (S T : AddSubmonoid A) : a • (S ⊔ T) = a • S ⊔ a • T := map_sup _ _ _ #align add_submonoid.smul_sup AddSubmonoid.smul_sup @[simp] theorem smul_closure (a : α) (s : Set A) : a • closure s = closure (a • s) := AddMonoidHom.map_mclosure _ _ #align add_submonoid.smul_closure AddSubmonoid.smul_closure lemma pointwise_isCentralScalar [DistribMulAction αᵐᵒᵖ A] [IsCentralScalar α A] : IsCentralScalar α (AddSubmonoid A) := ⟨fun _ S => (congr_arg fun f : AddMonoid.End A => S.map f) <| AddMonoidHom.ext <| op_smul_eq_smul _⟩ #align add_submonoid.pointwise_central_scalar AddSubmonoid.pointwise_isCentralScalar scoped[Pointwise] attribute [instance] AddSubmonoid.pointwise_isCentralScalar end Monoid section Group variable [Group α] [DistribMulAction α A] @[simp] theorem smul_mem_pointwise_smul_iff {a : α} {S : AddSubmonoid A} {x : A} : a • x ∈ a • S ↔ x ∈ S := smul_mem_smul_set_iff #align add_submonoid.smul_mem_pointwise_smul_iff AddSubmonoid.smul_mem_pointwise_smul_iff theorem mem_pointwise_smul_iff_inv_smul_mem {a : α} {S : AddSubmonoid A} {x : A} : x ∈ a • S ↔ a⁻¹ • x ∈ S := mem_smul_set_iff_inv_smul_mem #align add_submonoid.mem_pointwise_smul_iff_inv_smul_mem AddSubmonoid.mem_pointwise_smul_iff_inv_smul_mem theorem mem_inv_pointwise_smul_iff {a : α} {S : AddSubmonoid A} {x : A} : x ∈ a⁻¹ • S ↔ a • x ∈ S := mem_inv_smul_set_iff #align add_submonoid.mem_inv_pointwise_smul_iff AddSubmonoid.mem_inv_pointwise_smul_iff @[simp] theorem pointwise_smul_le_pointwise_smul_iff {a : α} {S T : AddSubmonoid A} : a • S ≤ a • T ↔ S ≤ T := set_smul_subset_set_smul_iff #align add_submonoid.pointwise_smul_le_pointwise_smul_iff AddSubmonoid.pointwise_smul_le_pointwise_smul_iff theorem pointwise_smul_le_iff {a : α} {S T : AddSubmonoid A} : a • S ≤ T ↔ S ≤ a⁻¹ • T := set_smul_subset_iff #align add_submonoid.pointwise_smul_le_iff AddSubmonoid.pointwise_smul_le_iff theorem le_pointwise_smul_iff {a : α} {S T : AddSubmonoid A} : S ≤ a • T ↔ a⁻¹ • S ≤ T := subset_set_smul_iff #align add_submonoid.le_pointwise_smul_iff AddSubmonoid.le_pointwise_smul_iff end Group section GroupWithZero variable [GroupWithZero α] [DistribMulAction α A] @[simp] theorem smul_mem_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) (S : AddSubmonoid A) (x : A) : a • x ∈ a • S ↔ x ∈ S := smul_mem_smul_set_iff₀ ha (S : Set A) x #align add_submonoid.smul_mem_pointwise_smul_iff₀ AddSubmonoid.smul_mem_pointwise_smul_iff₀ theorem mem_pointwise_smul_iff_inv_smul_mem₀ {a : α} (ha : a ≠ 0) (S : AddSubmonoid A) (x : A) : x ∈ a • S ↔ a⁻¹ • x ∈ S := mem_smul_set_iff_inv_smul_mem₀ ha (S : Set A) x #align add_submonoid.mem_pointwise_smul_iff_inv_smul_mem₀ AddSubmonoid.mem_pointwise_smul_iff_inv_smul_mem₀ theorem mem_inv_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) (S : AddSubmonoid A) (x : A) : x ∈ a⁻¹ • S ↔ a • x ∈ S := mem_inv_smul_set_iff₀ ha (S : Set A) x #align add_submonoid.mem_inv_pointwise_smul_iff₀ AddSubmonoid.mem_inv_pointwise_smul_iff₀ @[simp] theorem pointwise_smul_le_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) {S T : AddSubmonoid A} : a • S ≤ a • T ↔ S ≤ T := set_smul_subset_set_smul_iff₀ ha #align add_submonoid.pointwise_smul_le_pointwise_smul_iff₀ AddSubmonoid.pointwise_smul_le_pointwise_smul_iff₀ theorem pointwise_smul_le_iff₀ {a : α} (ha : a ≠ 0) {S T : AddSubmonoid A} : a • S ≤ T ↔ S ≤ a⁻¹ • T := set_smul_subset_iff₀ ha #align add_submonoid.pointwise_smul_le_iff₀ AddSubmonoid.pointwise_smul_le_iff₀ theorem le_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) {S T : AddSubmonoid A} : S ≤ a • T ↔ a⁻¹ • S ≤ T := subset_set_smul_iff₀ ha #align add_submonoid.le_pointwise_smul_iff₀ AddSubmonoid.le_pointwise_smul_iff₀ end GroupWithZero end AddSubmonoid /-! ### Elementwise monoid structure of additive submonoids These definitions are a cut-down versions of the ones around `Submodule.mul`, as that API is usually more useful. -/ namespace AddSubmonoid section AddMonoidWithOne variable [AddMonoidWithOne R] /-- If `R` is an additive monoid with one (e.g., a semiring), then `1 : AddSubmonoid R` is the range of `Nat.cast : ℕ → R`. -/ protected def one : One (AddSubmonoid R) := ⟨AddMonoidHom.mrange (Nat.castAddMonoidHom R)⟩ scoped[Pointwise] attribute [instance] AddSubmonoid.one theorem one_eq_mrange : (1 : AddSubmonoid R) = AddMonoidHom.mrange (Nat.castAddMonoidHom R) := rfl #align add_submonoid.one_eq_mrange AddSubmonoid.one_eq_mrange theorem natCast_mem_one (n : ℕ) : (n : R) ∈ (1 : AddSubmonoid R) := ⟨_, rfl⟩ #align add_submonoid.nat_cast_mem_one AddSubmonoid.natCast_mem_one @[simp] theorem mem_one {x : R} : x ∈ (1 : AddSubmonoid R) ↔ ∃ n : ℕ, ↑n = x := Iff.rfl #align add_submonoid.mem_one AddSubmonoid.mem_one theorem one_eq_closure : (1 : AddSubmonoid R) = closure {1} := by rw [closure_singleton_eq, one_eq_mrange] congr 1 ext simp #align add_submonoid.one_eq_closure AddSubmonoid.one_eq_closure theorem one_eq_closure_one_set : (1 : AddSubmonoid R) = closure 1 := one_eq_closure #align add_submonoid.one_eq_closure_one_set AddSubmonoid.one_eq_closure_one_set end AddMonoidWithOne section NonUnitalNonAssocSemiring variable [NonUnitalNonAssocSemiring R] /-- Multiplication of additive submonoids of a semiring R. The additive submonoid `S * T` is the smallest R-submodule of `R` containing the elements `s * t` for `s ∈ S` and `t ∈ T`. -/ protected def mul : Mul (AddSubmonoid R) := ⟨fun M N => ⨆ s : M, N.map (AddMonoidHom.mul s.1)⟩ scoped[Pointwise] attribute [instance] AddSubmonoid.mul theorem mul_mem_mul {M N : AddSubmonoid R} {m n : R} (hm : m ∈ M) (hn : n ∈ N) : m * n ∈ M * N := (le_iSup _ ⟨m, hm⟩ : _ ≤ M * N) ⟨n, hn, by rfl⟩ #align add_submonoid.mul_mem_mul AddSubmonoid.mul_mem_mul theorem mul_le {M N P : AddSubmonoid R} : M * N ≤ P ↔ ∀ m ∈ M, ∀ n ∈ N, m * n ∈ P := ⟨fun H _m hm _n hn => H <| mul_mem_mul hm hn, fun H => iSup_le fun ⟨m, hm⟩ => map_le_iff_le_comap.2 fun n hn => H m hm n hn⟩ #align add_submonoid.mul_le AddSubmonoid.mul_le @[elab_as_elim] protected theorem mul_induction_on {M N : AddSubmonoid R} {C : R → Prop} {r : R} (hr : r ∈ M * N) (hm : ∀ m ∈ M, ∀ n ∈ N, C (m * n)) (ha : ∀ x y, C x → C y → C (x + y)) : C r := (@mul_le _ _ _ _ ⟨⟨setOf C, ha _ _⟩, by simpa only [zero_mul] using hm _ (zero_mem _) _ (zero_mem _)⟩).2 hm hr #align add_submonoid.mul_induction_on AddSubmonoid.mul_induction_on -- this proof is copied directly from `Submodule.span_mul_span` -- Porting note: proof rewritten
Mathlib/Algebra/Group/Submonoid/Pointwise.lean
553
564
theorem closure_mul_closure (S T : Set R) : closure S * closure T = closure (S * T) := by
apply le_antisymm · refine mul_le.2 fun a ha b hb => ?_ rw [← AddMonoidHom.mulRight_apply, ← AddSubmonoid.mem_comap] refine (closure_le.2 fun a' ha' => ?_) ha change b ∈ (closure (S * T)).comap (AddMonoidHom.mulLeft a') refine (closure_le.2 fun b' hb' => ?_) hb change a' * b' ∈ closure (S * T) exact subset_closure (Set.mul_mem_mul ha' hb') · rw [closure_le] rintro _ ⟨a, ha, b, hb, rfl⟩ exact mul_mem_mul (subset_closure ha) (subset_closure hb)
/- Copyright (c) 2018 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Mario Carneiro, Simon Hudon -/ import Mathlib.Data.Fin.Fin2 import Mathlib.Logic.Function.Basic import Mathlib.Tactic.Common #align_import data.typevec from "leanprover-community/mathlib"@"48fb5b5280e7c81672afc9524185ae994553ebf4" /-! # Tuples of types, and their categorical structure. ## Features * `TypeVec n` - n-tuples of types * `α ⟹ β` - n-tuples of maps * `f ⊚ g` - composition Also, support functions for operating with n-tuples of types, such as: * `append1 α β` - append type `β` to n-tuple `α` to obtain an (n+1)-tuple * `drop α` - drops the last element of an (n+1)-tuple * `last α` - returns the last element of an (n+1)-tuple * `appendFun f g` - appends a function g to an n-tuple of functions * `dropFun f` - drops the last function from an n+1-tuple * `lastFun f` - returns the last function of a tuple. Since e.g. `append1 α.drop α.last` is propositionally equal to `α` but not definitionally equal to it, we need support functions and lemmas to mediate between constructions. -/ universe u v w /-- n-tuples of types, as a category -/ @[pp_with_univ] def TypeVec (n : ℕ) := Fin2 n → Type* #align typevec TypeVec instance {n} : Inhabited (TypeVec.{u} n) := ⟨fun _ => PUnit⟩ namespace TypeVec variable {n : ℕ} /-- arrow in the category of `TypeVec` -/ def Arrow (α β : TypeVec n) := ∀ i : Fin2 n, α i → β i #align typevec.arrow TypeVec.Arrow @[inherit_doc] scoped[MvFunctor] infixl:40 " ⟹ " => TypeVec.Arrow open MvFunctor /-- Extensionality for arrows -/ @[ext] theorem Arrow.ext {α β : TypeVec n} (f g : α ⟹ β) : (∀ i, f i = g i) → f = g := by intro h; funext i; apply h instance Arrow.inhabited (α β : TypeVec n) [∀ i, Inhabited (β i)] : Inhabited (α ⟹ β) := ⟨fun _ _ => default⟩ #align typevec.arrow.inhabited TypeVec.Arrow.inhabited /-- identity of arrow composition -/ def id {α : TypeVec n} : α ⟹ α := fun _ x => x #align typevec.id TypeVec.id /-- arrow composition in the category of `TypeVec` -/ def comp {α β γ : TypeVec n} (g : β ⟹ γ) (f : α ⟹ β) : α ⟹ γ := fun i x => g i (f i x) #align typevec.comp TypeVec.comp @[inherit_doc] scoped[MvFunctor] infixr:80 " ⊚ " => TypeVec.comp -- type as \oo @[simp] theorem id_comp {α β : TypeVec n} (f : α ⟹ β) : id ⊚ f = f := rfl #align typevec.id_comp TypeVec.id_comp @[simp] theorem comp_id {α β : TypeVec n} (f : α ⟹ β) : f ⊚ id = f := rfl #align typevec.comp_id TypeVec.comp_id theorem comp_assoc {α β γ δ : TypeVec n} (h : γ ⟹ δ) (g : β ⟹ γ) (f : α ⟹ β) : (h ⊚ g) ⊚ f = h ⊚ g ⊚ f := rfl #align typevec.comp_assoc TypeVec.comp_assoc /-- Support for extending a `TypeVec` by one element. -/ def append1 (α : TypeVec n) (β : Type*) : TypeVec (n + 1) | Fin2.fs i => α i | Fin2.fz => β #align typevec.append1 TypeVec.append1 @[inherit_doc] infixl:67 " ::: " => append1 /-- retain only a `n-length` prefix of the argument -/ def drop (α : TypeVec.{u} (n + 1)) : TypeVec n := fun i => α i.fs #align typevec.drop TypeVec.drop /-- take the last value of a `(n+1)-length` vector -/ def last (α : TypeVec.{u} (n + 1)) : Type _ := α Fin2.fz #align typevec.last TypeVec.last instance last.inhabited (α : TypeVec (n + 1)) [Inhabited (α Fin2.fz)] : Inhabited (last α) := ⟨show α Fin2.fz from default⟩ #align typevec.last.inhabited TypeVec.last.inhabited theorem drop_append1 {α : TypeVec n} {β : Type*} {i : Fin2 n} : drop (append1 α β) i = α i := rfl #align typevec.drop_append1 TypeVec.drop_append1 theorem drop_append1' {α : TypeVec n} {β : Type*} : drop (append1 α β) = α := funext fun _ => drop_append1 #align typevec.drop_append1' TypeVec.drop_append1' theorem last_append1 {α : TypeVec n} {β : Type*} : last (append1 α β) = β := rfl #align typevec.last_append1 TypeVec.last_append1 @[simp] theorem append1_drop_last (α : TypeVec (n + 1)) : append1 (drop α) (last α) = α := funext fun i => by cases i <;> rfl #align typevec.append1_drop_last TypeVec.append1_drop_last /-- cases on `(n+1)-length` vectors -/ @[elab_as_elim] def append1Cases {C : TypeVec (n + 1) → Sort u} (H : ∀ α β, C (append1 α β)) (γ) : C γ := by rw [← @append1_drop_last _ γ]; apply H #align typevec.append1_cases TypeVec.append1Cases @[simp] theorem append1_cases_append1 {C : TypeVec (n + 1) → Sort u} (H : ∀ α β, C (append1 α β)) (α β) : @append1Cases _ C H (append1 α β) = H α β := rfl #align typevec.append1_cases_append1 TypeVec.append1_cases_append1 /-- append an arrow and a function for arbitrary source and target type vectors -/ def splitFun {α α' : TypeVec (n + 1)} (f : drop α ⟹ drop α') (g : last α → last α') : α ⟹ α' | Fin2.fs i => f i | Fin2.fz => g #align typevec.split_fun TypeVec.splitFun /-- append an arrow and a function as well as their respective source and target types / typevecs -/ def appendFun {α α' : TypeVec n} {β β' : Type*} (f : α ⟹ α') (g : β → β') : append1 α β ⟹ append1 α' β' := splitFun f g #align typevec.append_fun TypeVec.appendFun @[inherit_doc] infixl:0 " ::: " => appendFun /-- split off the prefix of an arrow -/ def dropFun {α β : TypeVec (n + 1)} (f : α ⟹ β) : drop α ⟹ drop β := fun i => f i.fs #align typevec.drop_fun TypeVec.dropFun /-- split off the last function of an arrow -/ def lastFun {α β : TypeVec (n + 1)} (f : α ⟹ β) : last α → last β := f Fin2.fz #align typevec.last_fun TypeVec.lastFun -- Porting note: Lean wasn't able to infer the motive in term mode /-- arrow in the category of `0-length` vectors -/ def nilFun {α : TypeVec 0} {β : TypeVec 0} : α ⟹ β := fun i => by apply Fin2.elim0 i #align typevec.nil_fun TypeVec.nilFun theorem eq_of_drop_last_eq {α β : TypeVec (n + 1)} {f g : α ⟹ β} (h₀ : dropFun f = dropFun g) (h₁ : lastFun f = lastFun g) : f = g := by -- Porting note: FIXME: congr_fun h₀ <;> ext1 ⟨⟩ <;> apply_assumption refine funext (fun x => ?_) cases x · apply h₁ · apply congr_fun h₀ #align typevec.eq_of_drop_last_eq TypeVec.eq_of_drop_last_eq @[simp] theorem dropFun_splitFun {α α' : TypeVec (n + 1)} (f : drop α ⟹ drop α') (g : last α → last α') : dropFun (splitFun f g) = f := rfl #align typevec.drop_fun_split_fun TypeVec.dropFun_splitFun /-- turn an equality into an arrow -/ def Arrow.mp {α β : TypeVec n} (h : α = β) : α ⟹ β | _ => Eq.mp (congr_fun h _) #align typevec.arrow.mp TypeVec.Arrow.mp /-- turn an equality into an arrow, with reverse direction -/ def Arrow.mpr {α β : TypeVec n} (h : α = β) : β ⟹ α | _ => Eq.mpr (congr_fun h _) #align typevec.arrow.mpr TypeVec.Arrow.mpr /-- decompose a vector into its prefix appended with its last element -/ def toAppend1DropLast {α : TypeVec (n + 1)} : α ⟹ (drop α ::: last α) := Arrow.mpr (append1_drop_last _) #align typevec.to_append1_drop_last TypeVec.toAppend1DropLast /-- stitch two bits of a vector back together -/ def fromAppend1DropLast {α : TypeVec (n + 1)} : (drop α ::: last α) ⟹ α := Arrow.mp (append1_drop_last _) #align typevec.from_append1_drop_last TypeVec.fromAppend1DropLast @[simp] theorem lastFun_splitFun {α α' : TypeVec (n + 1)} (f : drop α ⟹ drop α') (g : last α → last α') : lastFun (splitFun f g) = g := rfl #align typevec.last_fun_split_fun TypeVec.lastFun_splitFun @[simp] theorem dropFun_appendFun {α α' : TypeVec n} {β β' : Type*} (f : α ⟹ α') (g : β → β') : dropFun (f ::: g) = f := rfl #align typevec.drop_fun_append_fun TypeVec.dropFun_appendFun @[simp] theorem lastFun_appendFun {α α' : TypeVec n} {β β' : Type*} (f : α ⟹ α') (g : β → β') : lastFun (f ::: g) = g := rfl #align typevec.last_fun_append_fun TypeVec.lastFun_appendFun theorem split_dropFun_lastFun {α α' : TypeVec (n + 1)} (f : α ⟹ α') : splitFun (dropFun f) (lastFun f) = f := eq_of_drop_last_eq rfl rfl #align typevec.split_drop_fun_last_fun TypeVec.split_dropFun_lastFun theorem splitFun_inj {α α' : TypeVec (n + 1)} {f f' : drop α ⟹ drop α'} {g g' : last α → last α'} (H : splitFun f g = splitFun f' g') : f = f' ∧ g = g' := by rw [← dropFun_splitFun f g, H, ← lastFun_splitFun f g, H]; simp #align typevec.split_fun_inj TypeVec.splitFun_inj theorem appendFun_inj {α α' : TypeVec n} {β β' : Type*} {f f' : α ⟹ α'} {g g' : β → β'} : (f ::: g : (α ::: β) ⟹ _) = (f' ::: g' : (α ::: β) ⟹ _) → f = f' ∧ g = g' := splitFun_inj #align typevec.append_fun_inj TypeVec.appendFun_inj theorem splitFun_comp {α₀ α₁ α₂ : TypeVec (n + 1)} (f₀ : drop α₀ ⟹ drop α₁) (f₁ : drop α₁ ⟹ drop α₂) (g₀ : last α₀ → last α₁) (g₁ : last α₁ → last α₂) : splitFun (f₁ ⊚ f₀) (g₁ ∘ g₀) = splitFun f₁ g₁ ⊚ splitFun f₀ g₀ := eq_of_drop_last_eq rfl rfl #align typevec.split_fun_comp TypeVec.splitFun_comp theorem appendFun_comp_splitFun {α γ : TypeVec n} {β δ : Type*} {ε : TypeVec (n + 1)} (f₀ : drop ε ⟹ α) (f₁ : α ⟹ γ) (g₀ : last ε → β) (g₁ : β → δ) : appendFun f₁ g₁ ⊚ splitFun f₀ g₀ = splitFun (α' := γ.append1 δ) (f₁ ⊚ f₀) (g₁ ∘ g₀) := (splitFun_comp _ _ _ _).symm #align typevec.append_fun_comp_split_fun TypeVec.appendFun_comp_splitFun theorem appendFun_comp {α₀ α₁ α₂ : TypeVec n} {β₀ β₁ β₂ : Type*} (f₀ : α₀ ⟹ α₁) (f₁ : α₁ ⟹ α₂) (g₀ : β₀ → β₁) (g₁ : β₁ → β₂) : (f₁ ⊚ f₀ ::: g₁ ∘ g₀) = (f₁ ::: g₁) ⊚ (f₀ ::: g₀) := eq_of_drop_last_eq rfl rfl #align typevec.append_fun_comp TypeVec.appendFun_comp theorem appendFun_comp' {α₀ α₁ α₂ : TypeVec n} {β₀ β₁ β₂ : Type*} (f₀ : α₀ ⟹ α₁) (f₁ : α₁ ⟹ α₂) (g₀ : β₀ → β₁) (g₁ : β₁ → β₂) : (f₁ ::: g₁) ⊚ (f₀ ::: g₀) = (f₁ ⊚ f₀ ::: g₁ ∘ g₀) := eq_of_drop_last_eq rfl rfl #align typevec.append_fun_comp' TypeVec.appendFun_comp' theorem nilFun_comp {α₀ : TypeVec 0} (f₀ : α₀ ⟹ Fin2.elim0) : nilFun ⊚ f₀ = f₀ := funext fun x => by apply Fin2.elim0 x -- Porting note: `by apply` is necessary? #align typevec.nil_fun_comp TypeVec.nilFun_comp theorem appendFun_comp_id {α : TypeVec n} {β₀ β₁ β₂ : Type u} (g₀ : β₀ → β₁) (g₁ : β₁ → β₂) : (@id _ α ::: g₁ ∘ g₀) = (id ::: g₁) ⊚ (id ::: g₀) := eq_of_drop_last_eq rfl rfl #align typevec.append_fun_comp_id TypeVec.appendFun_comp_id @[simp] theorem dropFun_comp {α₀ α₁ α₂ : TypeVec (n + 1)} (f₀ : α₀ ⟹ α₁) (f₁ : α₁ ⟹ α₂) : dropFun (f₁ ⊚ f₀) = dropFun f₁ ⊚ dropFun f₀ := rfl #align typevec.drop_fun_comp TypeVec.dropFun_comp @[simp] theorem lastFun_comp {α₀ α₁ α₂ : TypeVec (n + 1)} (f₀ : α₀ ⟹ α₁) (f₁ : α₁ ⟹ α₂) : lastFun (f₁ ⊚ f₀) = lastFun f₁ ∘ lastFun f₀ := rfl #align typevec.last_fun_comp TypeVec.lastFun_comp theorem appendFun_aux {α α' : TypeVec n} {β β' : Type*} (f : (α ::: β) ⟹ (α' ::: β')) : (dropFun f ::: lastFun f) = f := eq_of_drop_last_eq rfl rfl #align typevec.append_fun_aux TypeVec.appendFun_aux theorem appendFun_id_id {α : TypeVec n} {β : Type*} : (@TypeVec.id n α ::: @_root_.id β) = TypeVec.id := eq_of_drop_last_eq rfl rfl #align typevec.append_fun_id_id TypeVec.appendFun_id_id instance subsingleton0 : Subsingleton (TypeVec 0) := ⟨fun a b => funext fun a => by apply Fin2.elim0 a⟩ -- Porting note: `by apply` necessary? #align typevec.subsingleton0 TypeVec.subsingleton0 -- Porting note: `simp` attribute `TypeVec` moved to file `Tactic/Attr/Register.lean` /-- cases distinction for 0-length type vector -/ protected def casesNil {β : TypeVec 0 → Sort*} (f : β Fin2.elim0) : ∀ v, β v := fun v => cast (by congr; funext i; cases i) f #align typevec.cases_nil TypeVec.casesNil /-- cases distinction for (n+1)-length type vector -/ protected def casesCons (n : ℕ) {β : TypeVec (n + 1) → Sort*} (f : ∀ (t) (v : TypeVec n), β (v ::: t)) : ∀ v, β v := fun v : TypeVec (n + 1) => cast (by simp) (f v.last v.drop) #align typevec.cases_cons TypeVec.casesCons protected theorem casesNil_append1 {β : TypeVec 0 → Sort*} (f : β Fin2.elim0) : TypeVec.casesNil f Fin2.elim0 = f := rfl #align typevec.cases_nil_append1 TypeVec.casesNil_append1 protected theorem casesCons_append1 (n : ℕ) {β : TypeVec (n + 1) → Sort*} (f : ∀ (t) (v : TypeVec n), β (v ::: t)) (v : TypeVec n) (α) : TypeVec.casesCons n f (v ::: α) = f α v := rfl #align typevec.cases_cons_append1 TypeVec.casesCons_append1 /-- cases distinction for an arrow in the category of 0-length type vectors -/ def typevecCasesNil₃ {β : ∀ v v' : TypeVec 0, v ⟹ v' → Sort*} (f : β Fin2.elim0 Fin2.elim0 nilFun) : ∀ v v' fs, β v v' fs := fun v v' fs => by refine cast ?_ f have eq₁ : v = Fin2.elim0 := by funext i; contradiction have eq₂ : v' = Fin2.elim0 := by funext i; contradiction have eq₃ : fs = nilFun := by funext i; contradiction cases eq₁; cases eq₂; cases eq₃; rfl #align typevec.typevec_cases_nil₃ TypeVec.typevecCasesNil₃ /-- cases distinction for an arrow in the category of (n+1)-length type vectors -/ def typevecCasesCons₃ (n : ℕ) {β : ∀ v v' : TypeVec (n + 1), v ⟹ v' → Sort*} (F : ∀ (t t') (f : t → t') (v v' : TypeVec n) (fs : v ⟹ v'), β (v ::: t) (v' ::: t') (fs ::: f)) : ∀ v v' fs, β v v' fs := by intro v v' rw [← append1_drop_last v, ← append1_drop_last v'] intro fs rw [← split_dropFun_lastFun fs] apply F #align typevec.typevec_cases_cons₃ TypeVec.typevecCasesCons₃ /-- specialized cases distinction for an arrow in the category of 0-length type vectors -/ def typevecCasesNil₂ {β : Fin2.elim0 ⟹ Fin2.elim0 → Sort*} (f : β nilFun) : ∀ f, β f := by intro g suffices g = nilFun by rwa [this] ext ⟨⟩ #align typevec.typevec_cases_nil₂ TypeVec.typevecCasesNil₂ /-- specialized cases distinction for an arrow in the category of (n+1)-length type vectors -/ def typevecCasesCons₂ (n : ℕ) (t t' : Type*) (v v' : TypeVec n) {β : (v ::: t) ⟹ (v' ::: t') → Sort*} (F : ∀ (f : t → t') (fs : v ⟹ v'), β (fs ::: f)) : ∀ fs, β fs := by intro fs rw [← split_dropFun_lastFun fs] apply F #align typevec.typevec_cases_cons₂ TypeVec.typevecCasesCons₂ theorem typevecCasesNil₂_appendFun {β : Fin2.elim0 ⟹ Fin2.elim0 → Sort*} (f : β nilFun) : typevecCasesNil₂ f nilFun = f := rfl #align typevec.typevec_cases_nil₂_append_fun TypeVec.typevecCasesNil₂_appendFun theorem typevecCasesCons₂_appendFun (n : ℕ) (t t' : Type*) (v v' : TypeVec n) {β : (v ::: t) ⟹ (v' ::: t') → Sort*} (F : ∀ (f : t → t') (fs : v ⟹ v'), β (fs ::: f)) (f fs) : typevecCasesCons₂ n t t' v v' F (fs ::: f) = F f fs := rfl #align typevec.typevec_cases_cons₂_append_fun TypeVec.typevecCasesCons₂_appendFun -- for lifting predicates and relations /-- `PredLast α p x` predicates `p` of the last element of `x : α.append1 β`. -/ def PredLast (α : TypeVec n) {β : Type*} (p : β → Prop) : ∀ ⦃i⦄, (α.append1 β) i → Prop | Fin2.fs _ => fun _ => True | Fin2.fz => p #align typevec.pred_last TypeVec.PredLast /-- `RelLast α r x y` says that `p` the last elements of `x y : α.append1 β` are related by `r` and all the other elements are equal. -/ def RelLast (α : TypeVec n) {β γ : Type u} (r : β → γ → Prop) : ∀ ⦃i⦄, (α.append1 β) i → (α.append1 γ) i → Prop | Fin2.fs _ => Eq | Fin2.fz => r #align typevec.rel_last TypeVec.RelLast section Liftp' open Nat /-- `repeat n t` is a `n-length` type vector that contains `n` occurrences of `t` -/ def «repeat» : ∀ (n : ℕ), Sort _ → TypeVec n | 0, _ => Fin2.elim0 | Nat.succ i, t => append1 («repeat» i t) t #align typevec.repeat TypeVec.repeat /-- `prod α β` is the pointwise product of the components of `α` and `β` -/ def prod : ∀ {n}, TypeVec.{u} n → TypeVec.{u} n → TypeVec n | 0, _, _ => Fin2.elim0 | n + 1, α, β => (@prod n (drop α) (drop β)) ::: (last α × last β) #align typevec.prod TypeVec.prod @[inherit_doc] scoped[MvFunctor] infixl:45 " ⊗ " => TypeVec.prod /- porting note: the order of universes in `const` is reversed w.r.t. mathlib3 -/ /-- `const x α` is an arrow that ignores its source and constructs a `TypeVec` that contains nothing but `x` -/ protected def const {β} (x : β) : ∀ {n} (α : TypeVec n), α ⟹ «repeat» _ β | succ _, α, Fin2.fs _ => TypeVec.const x (drop α) _ | succ _, _, Fin2.fz => fun _ => x #align typevec.const TypeVec.const open Function (uncurry) /-- vector of equality on a product of vectors -/ def repeatEq : ∀ {n} (α : TypeVec n), (α ⊗ α) ⟹ «repeat» _ Prop | 0, _ => nilFun | succ _, α => repeatEq (drop α) ::: uncurry Eq #align typevec.repeat_eq TypeVec.repeatEq theorem const_append1 {β γ} (x : γ) {n} (α : TypeVec n) : TypeVec.const x (α ::: β) = appendFun (TypeVec.const x α) fun _ => x := by ext i : 1; cases i <;> rfl #align typevec.const_append1 TypeVec.const_append1 theorem eq_nilFun {α β : TypeVec 0} (f : α ⟹ β) : f = nilFun := by ext x; cases x #align typevec.eq_nil_fun TypeVec.eq_nilFun theorem id_eq_nilFun {α : TypeVec 0} : @id _ α = nilFun := by ext x; cases x #align typevec.id_eq_nil_fun TypeVec.id_eq_nilFun
Mathlib/Data/TypeVec.lean
441
442
theorem const_nil {β} (x : β) (α : TypeVec 0) : TypeVec.const x α = nilFun := by
ext i : 1; cases i
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Kexing Ying -/ import Mathlib.LinearAlgebra.Matrix.Basis import Mathlib.LinearAlgebra.Matrix.Nondegenerate import Mathlib.LinearAlgebra.Matrix.NonsingularInverse import Mathlib.LinearAlgebra.Matrix.ToLinearEquiv import Mathlib.LinearAlgebra.BilinearForm.Properties import Mathlib.LinearAlgebra.Matrix.SesquilinearForm #align_import linear_algebra.matrix.bilinear_form from "leanprover-community/mathlib"@"075b3f7d19b9da85a0b54b3e33055a74fc388dec" /-! # Bilinear form This file defines the conversion between bilinear forms and matrices. ## Main definitions * `Matrix.toBilin` given a basis define a bilinear form * `Matrix.toBilin'` define the bilinear form on `n → R` * `BilinForm.toMatrix`: calculate the matrix coefficients of a bilinear form * `BilinForm.toMatrix'`: calculate the matrix coefficients of a bilinear form on `n → R` ## Notations In this file we use the following type variables: - `M`, `M'`, ... are modules over the commutative semiring `R`, - `M₁`, `M₁'`, ... are modules over the commutative ring `R₁`, - `M₂`, `M₂'`, ... are modules over the commutative semiring `R₂`, - `M₃`, `M₃'`, ... are modules over the commutative ring `R₃`, - `V`, ... is a vector space over the field `K`. ## Tags bilinear form, bilin form, BilinearForm, matrix, basis -/ open LinearMap (BilinForm) variable {R : Type*} {M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] variable {R₁ : Type*} {M₁ : Type*} [CommRing R₁] [AddCommGroup M₁] [Module R₁ M₁] variable {R₂ : Type*} {M₂ : Type*} [CommSemiring R₂] [AddCommMonoid M₂] [Module R₂ M₂] variable {R₃ : Type*} {M₃ : Type*} [CommRing R₃] [AddCommGroup M₃] [Module R₃ M₃] variable {V : Type*} {K : Type*} [Field K] [AddCommGroup V] [Module K V] variable {B : BilinForm R M} {B₁ : BilinForm R₁ M₁} {B₂ : BilinForm R₂ M₂} section Matrix variable {n o : Type*} open Finset LinearMap Matrix open Matrix /-- The map from `Matrix n n R` to bilinear forms on `n → R`. This is an auxiliary definition for the equivalence `Matrix.toBilin'`. -/ def Matrix.toBilin'Aux [Fintype n] (M : Matrix n n R₂) : BilinForm R₂ (n → R₂) := Matrix.toLinearMap₂'Aux _ _ M #align matrix.to_bilin'_aux Matrix.toBilin'Aux theorem Matrix.toBilin'Aux_stdBasis [Fintype n] [DecidableEq n] (M : Matrix n n R₂) (i j : n) : M.toBilin'Aux (LinearMap.stdBasis R₂ (fun _ => R₂) i 1) (LinearMap.stdBasis R₂ (fun _ => R₂) j 1) = M i j := Matrix.toLinearMap₂'Aux_stdBasis _ _ _ _ _ #align matrix.to_bilin'_aux_std_basis Matrix.toBilin'Aux_stdBasis /-- The linear map from bilinear forms to `Matrix n n R` given an `n`-indexed basis. This is an auxiliary definition for the equivalence `Matrix.toBilin'`. -/ def BilinForm.toMatrixAux (b : n → M₂) : BilinForm R₂ M₂ →ₗ[R₂] Matrix n n R₂ := LinearMap.toMatrix₂Aux b b #align bilin_form.to_matrix_aux BilinForm.toMatrixAux @[simp] theorem LinearMap.BilinForm.toMatrixAux_apply (B : BilinForm R₂ M₂) (b : n → M₂) (i j : n) : -- Porting note: had to hint the base ring even though it should be clear from context... BilinForm.toMatrixAux (R₂ := R₂) b B i j = B (b i) (b j) := LinearMap.toMatrix₂Aux_apply B _ _ _ _ #align bilin_form.to_matrix_aux_apply LinearMap.BilinForm.toMatrixAux_apply variable [Fintype n] [Fintype o] theorem toBilin'Aux_toMatrixAux [DecidableEq n] (B₂ : BilinForm R₂ (n → R₂)) : -- Porting note: had to hint the base ring even though it should be clear from context... Matrix.toBilin'Aux (BilinForm.toMatrixAux (R₂ := R₂) (fun j => stdBasis R₂ (fun _ => R₂) j 1) B₂) = B₂ := by rw [BilinForm.toMatrixAux, Matrix.toBilin'Aux, toLinearMap₂'Aux_toMatrix₂Aux] #align to_bilin'_aux_to_matrix_aux toBilin'Aux_toMatrixAux section ToMatrix' /-! ### `ToMatrix'` section This section deals with the conversion between matrices and bilinear forms on `n → R₂`. -/ variable [DecidableEq n] [DecidableEq o] /-- The linear equivalence between bilinear forms on `n → R` and `n × n` matrices -/ def LinearMap.BilinForm.toMatrix' : BilinForm R₂ (n → R₂) ≃ₗ[R₂] Matrix n n R₂ := LinearMap.toMatrix₂' #align bilin_form.to_matrix' LinearMap.BilinForm.toMatrix' @[simp] theorem LinearMap.BilinForm.toMatrixAux_stdBasis (B : BilinForm R₂ (n → R₂)) : -- Porting note: had to hint the base ring even though it should be clear from context... BilinForm.toMatrixAux (R₂ := R₂) (fun j => stdBasis R₂ (fun _ => R₂) j 1) B = BilinForm.toMatrix' B := rfl #align bilin_form.to_matrix_aux_std_basis LinearMap.BilinForm.toMatrixAux_stdBasis /-- The linear equivalence between `n × n` matrices and bilinear forms on `n → R` -/ def Matrix.toBilin' : Matrix n n R₂ ≃ₗ[R₂] BilinForm R₂ (n → R₂) := BilinForm.toMatrix'.symm #align matrix.to_bilin' Matrix.toBilin' @[simp] theorem Matrix.toBilin'Aux_eq (M : Matrix n n R₂) : Matrix.toBilin'Aux M = Matrix.toBilin' M := rfl #align matrix.to_bilin'_aux_eq Matrix.toBilin'Aux_eq theorem Matrix.toBilin'_apply (M : Matrix n n R₂) (x y : n → R₂) : Matrix.toBilin' M x y = ∑ i, ∑ j, x i * M i j * y j := Matrix.toLinearMap₂'_apply _ _ _ #align matrix.to_bilin'_apply Matrix.toBilin'_apply theorem Matrix.toBilin'_apply' (M : Matrix n n R₂) (v w : n → R₂) : Matrix.toBilin' M v w = Matrix.dotProduct v (M *ᵥ w) := Matrix.toLinearMap₂'_apply' _ _ _ #align matrix.to_bilin'_apply' Matrix.toBilin'_apply' @[simp] theorem Matrix.toBilin'_stdBasis (M : Matrix n n R₂) (i j : n) : Matrix.toBilin' M (LinearMap.stdBasis R₂ (fun _ => R₂) i 1) (LinearMap.stdBasis R₂ (fun _ => R₂) j 1) = M i j := Matrix.toLinearMap₂'_stdBasis _ _ _ #align matrix.to_bilin'_std_basis Matrix.toBilin'_stdBasis @[simp] theorem LinearMap.BilinForm.toMatrix'_symm : (BilinForm.toMatrix'.symm : Matrix n n R₂ ≃ₗ[R₂] _) = Matrix.toBilin' := rfl #align bilin_form.to_matrix'_symm LinearMap.BilinForm.toMatrix'_symm @[simp] theorem Matrix.toBilin'_symm : (Matrix.toBilin'.symm : _ ≃ₗ[R₂] Matrix n n R₂) = BilinForm.toMatrix' := BilinForm.toMatrix'.symm_symm #align matrix.to_bilin'_symm Matrix.toBilin'_symm @[simp] theorem Matrix.toBilin'_toMatrix' (B : BilinForm R₂ (n → R₂)) : Matrix.toBilin' (BilinForm.toMatrix' B) = B := Matrix.toBilin'.apply_symm_apply B #align matrix.to_bilin'_to_matrix' Matrix.toBilin'_toMatrix' namespace LinearMap @[simp] theorem BilinForm.toMatrix'_toBilin' (M : Matrix n n R₂) : BilinForm.toMatrix' (Matrix.toBilin' M) = M := LinearMap.toMatrix₂'.apply_symm_apply M #align bilin_form.to_matrix'_to_bilin' LinearMap.BilinForm.toMatrix'_toBilin' @[simp] theorem BilinForm.toMatrix'_apply (B : BilinForm R₂ (n → R₂)) (i j : n) : BilinForm.toMatrix' B i j = B (stdBasis R₂ (fun _ => R₂) i 1) (stdBasis R₂ (fun _ => R₂) j 1) := LinearMap.toMatrix₂'_apply _ _ _ #align bilin_form.to_matrix'_apply LinearMap.BilinForm.toMatrix'_apply -- Porting note: dot notation for bundled maps doesn't work in the rest of this section @[simp] theorem BilinForm.toMatrix'_comp (B : BilinForm R₂ (n → R₂)) (l r : (o → R₂) →ₗ[R₂] n → R₂) : BilinForm.toMatrix' (B.comp l r) = (LinearMap.toMatrix' l)ᵀ * BilinForm.toMatrix' B * LinearMap.toMatrix' r := LinearMap.toMatrix₂'_compl₁₂ B _ _ #align bilin_form.to_matrix'_comp LinearMap.BilinForm.toMatrix'_comp theorem BilinForm.toMatrix'_compLeft (B : BilinForm R₂ (n → R₂)) (f : (n → R₂) →ₗ[R₂] n → R₂) : BilinForm.toMatrix' (B.compLeft f) = (LinearMap.toMatrix' f)ᵀ * BilinForm.toMatrix' B := LinearMap.toMatrix₂'_comp B _ #align bilin_form.to_matrix'_comp_left LinearMap.BilinForm.toMatrix'_compLeft theorem BilinForm.toMatrix'_compRight (B : BilinForm R₂ (n → R₂)) (f : (n → R₂) →ₗ[R₂] n → R₂) : BilinForm.toMatrix' (B.compRight f) = BilinForm.toMatrix' B * LinearMap.toMatrix' f := LinearMap.toMatrix₂'_compl₂ B _ #align bilin_form.to_matrix'_comp_right LinearMap.BilinForm.toMatrix'_compRight theorem BilinForm.mul_toMatrix'_mul (B : BilinForm R₂ (n → R₂)) (M : Matrix o n R₂) (N : Matrix n o R₂) : M * BilinForm.toMatrix' B * N = BilinForm.toMatrix' (B.comp (Matrix.toLin' Mᵀ) (Matrix.toLin' N)) := LinearMap.mul_toMatrix₂'_mul B _ _ #align bilin_form.mul_to_matrix'_mul LinearMap.BilinForm.mul_toMatrix'_mul theorem BilinForm.mul_toMatrix' (B : BilinForm R₂ (n → R₂)) (M : Matrix n n R₂) : M * BilinForm.toMatrix' B = BilinForm.toMatrix' (B.compLeft (Matrix.toLin' Mᵀ)) := LinearMap.mul_toMatrix' B _ #align bilin_form.mul_to_matrix' LinearMap.BilinForm.mul_toMatrix' theorem BilinForm.toMatrix'_mul (B : BilinForm R₂ (n → R₂)) (M : Matrix n n R₂) : BilinForm.toMatrix' B * M = BilinForm.toMatrix' (B.compRight (Matrix.toLin' M)) := LinearMap.toMatrix₂'_mul B _ #align bilin_form.to_matrix'_mul LinearMap.BilinForm.toMatrix'_mul end LinearMap theorem Matrix.toBilin'_comp (M : Matrix n n R₂) (P Q : Matrix n o R₂) : M.toBilin'.comp (Matrix.toLin' P) (Matrix.toLin' Q) = Matrix.toBilin' (Pᵀ * M * Q) := BilinForm.toMatrix'.injective (by simp only [BilinForm.toMatrix'_comp, BilinForm.toMatrix'_toBilin', toMatrix'_toLin']) #align matrix.to_bilin'_comp Matrix.toBilin'_comp end ToMatrix' section ToMatrix /-! ### `ToMatrix` section This section deals with the conversion between matrices and bilinear forms on a module with a fixed basis. -/ variable [DecidableEq n] (b : Basis n R₂ M₂) /-- `BilinForm.toMatrix b` is the equivalence between `R`-bilinear forms on `M` and `n`-by-`n` matrices with entries in `R`, if `b` is an `R`-basis for `M`. -/ noncomputable def BilinForm.toMatrix : BilinForm R₂ M₂ ≃ₗ[R₂] Matrix n n R₂ := LinearMap.toMatrix₂ b b #align bilin_form.to_matrix BilinForm.toMatrix /-- `BilinForm.toMatrix b` is the equivalence between `R`-bilinear forms on `M` and `n`-by-`n` matrices with entries in `R`, if `b` is an `R`-basis for `M`. -/ noncomputable def Matrix.toBilin : Matrix n n R₂ ≃ₗ[R₂] BilinForm R₂ M₂ := (BilinForm.toMatrix b).symm #align matrix.to_bilin Matrix.toBilin @[simp] theorem BilinForm.toMatrix_apply (B : BilinForm R₂ M₂) (i j : n) : BilinForm.toMatrix b B i j = B (b i) (b j) := LinearMap.toMatrix₂_apply _ _ B _ _ #align bilin_form.to_matrix_apply BilinForm.toMatrix_apply @[simp] theorem Matrix.toBilin_apply (M : Matrix n n R₂) (x y : M₂) : Matrix.toBilin b M x y = ∑ i, ∑ j, b.repr x i * M i j * b.repr y j := Matrix.toLinearMap₂_apply _ _ _ _ _ #align matrix.to_bilin_apply Matrix.toBilin_apply -- Not a `simp` lemma since `BilinForm.toMatrix` needs an extra argument theorem BilinearForm.toMatrixAux_eq (B : BilinForm R₂ M₂) : BilinForm.toMatrixAux (R₂ := R₂) b B = BilinForm.toMatrix b B := LinearMap.toMatrix₂Aux_eq _ _ B #align bilinear_form.to_matrix_aux_eq BilinearForm.toMatrixAux_eq @[simp] theorem BilinForm.toMatrix_symm : (BilinForm.toMatrix b).symm = Matrix.toBilin b := rfl #align bilin_form.to_matrix_symm BilinForm.toMatrix_symm @[simp] theorem Matrix.toBilin_symm : (Matrix.toBilin b).symm = BilinForm.toMatrix b := (BilinForm.toMatrix b).symm_symm #align matrix.to_bilin_symm Matrix.toBilin_symm theorem Matrix.toBilin_basisFun : Matrix.toBilin (Pi.basisFun R₂ n) = Matrix.toBilin' := by ext M simp only [coe_comp, coe_single, Function.comp_apply, toBilin_apply, Pi.basisFun_repr, toBilin'_apply] #align matrix.to_bilin_basis_fun Matrix.toBilin_basisFun theorem BilinForm.toMatrix_basisFun : BilinForm.toMatrix (Pi.basisFun R₂ n) = BilinForm.toMatrix' := by rw [BilinForm.toMatrix, BilinForm.toMatrix', LinearMap.toMatrix₂_basisFun] #align bilin_form.to_matrix_basis_fun BilinForm.toMatrix_basisFun @[simp] theorem Matrix.toBilin_toMatrix (B : BilinForm R₂ M₂) : Matrix.toBilin b (BilinForm.toMatrix b B) = B := (Matrix.toBilin b).apply_symm_apply B #align matrix.to_bilin_to_matrix Matrix.toBilin_toMatrix @[simp] theorem BilinForm.toMatrix_toBilin (M : Matrix n n R₂) : BilinForm.toMatrix b (Matrix.toBilin b M) = M := (BilinForm.toMatrix b).apply_symm_apply M #align bilin_form.to_matrix_to_bilin BilinForm.toMatrix_toBilin variable {M₂' : Type*} [AddCommMonoid M₂'] [Module R₂ M₂'] variable (c : Basis o R₂ M₂') variable [DecidableEq o] -- Cannot be a `simp` lemma because `b` must be inferred. theorem BilinForm.toMatrix_comp (B : BilinForm R₂ M₂) (l r : M₂' →ₗ[R₂] M₂) : BilinForm.toMatrix c (B.comp l r) = (LinearMap.toMatrix c b l)ᵀ * BilinForm.toMatrix b B * LinearMap.toMatrix c b r := LinearMap.toMatrix₂_compl₁₂ _ _ _ _ B _ _ #align bilin_form.to_matrix_comp BilinForm.toMatrix_comp theorem BilinForm.toMatrix_compLeft (B : BilinForm R₂ M₂) (f : M₂ →ₗ[R₂] M₂) : BilinForm.toMatrix b (B.compLeft f) = (LinearMap.toMatrix b b f)ᵀ * BilinForm.toMatrix b B := LinearMap.toMatrix₂_comp _ _ _ B _ #align bilin_form.to_matrix_comp_left BilinForm.toMatrix_compLeft theorem BilinForm.toMatrix_compRight (B : BilinForm R₂ M₂) (f : M₂ →ₗ[R₂] M₂) : BilinForm.toMatrix b (B.compRight f) = BilinForm.toMatrix b B * LinearMap.toMatrix b b f := LinearMap.toMatrix₂_compl₂ _ _ _ B _ #align bilin_form.to_matrix_comp_right BilinForm.toMatrix_compRight @[simp] theorem BilinForm.toMatrix_mul_basis_toMatrix (c : Basis o R₂ M₂) (B : BilinForm R₂ M₂) : (b.toMatrix c)ᵀ * BilinForm.toMatrix b B * b.toMatrix c = BilinForm.toMatrix c B := LinearMap.toMatrix₂_mul_basis_toMatrix _ _ _ _ B #align bilin_form.to_matrix_mul_basis_to_matrix BilinForm.toMatrix_mul_basis_toMatrix theorem BilinForm.mul_toMatrix_mul (B : BilinForm R₂ M₂) (M : Matrix o n R₂) (N : Matrix n o R₂) : M * BilinForm.toMatrix b B * N = BilinForm.toMatrix c (B.comp (Matrix.toLin c b Mᵀ) (Matrix.toLin c b N)) := LinearMap.mul_toMatrix₂_mul _ _ _ _ B _ _ #align bilin_form.mul_to_matrix_mul BilinForm.mul_toMatrix_mul theorem BilinForm.mul_toMatrix (B : BilinForm R₂ M₂) (M : Matrix n n R₂) : M * BilinForm.toMatrix b B = BilinForm.toMatrix b (B.compLeft (Matrix.toLin b b Mᵀ)) := LinearMap.mul_toMatrix₂ _ _ _ B _ #align bilin_form.mul_to_matrix BilinForm.mul_toMatrix theorem BilinForm.toMatrix_mul (B : BilinForm R₂ M₂) (M : Matrix n n R₂) : BilinForm.toMatrix b B * M = BilinForm.toMatrix b (B.compRight (Matrix.toLin b b M)) := LinearMap.toMatrix₂_mul _ _ _ B _ #align bilin_form.to_matrix_mul BilinForm.toMatrix_mul
Mathlib/LinearAlgebra/Matrix/BilinearForm.lean
337
342
theorem Matrix.toBilin_comp (M : Matrix n n R₂) (P Q : Matrix n o R₂) : (Matrix.toBilin b M).comp (toLin c b P) (toLin c b Q) = Matrix.toBilin c (Pᵀ * M * Q) := by
ext x y rw [Matrix.toBilin, BilinForm.toMatrix, Matrix.toBilin, BilinForm.toMatrix, toMatrix₂_symm, toMatrix₂_symm, ← Matrix.toLinearMap₂_compl₁₂ b b c c] simp
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Fabian Glöckle, Kyle Miller -/ import Mathlib.LinearAlgebra.FiniteDimensional import Mathlib.LinearAlgebra.FreeModule.Finite.Basic import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition import Mathlib.LinearAlgebra.Projection import Mathlib.LinearAlgebra.SesquilinearForm import Mathlib.RingTheory.TensorProduct.Basic import Mathlib.RingTheory.Ideal.LocalRing #align_import linear_algebra.dual from "leanprover-community/mathlib"@"b1c017582e9f18d8494e5c18602a8cb4a6f843ac" /-! # Dual vector spaces The dual space of an $R$-module $M$ is the $R$-module of $R$-linear maps $M \to R$. ## Main definitions * Duals and transposes: * `Module.Dual R M` defines the dual space of the `R`-module `M`, as `M →ₗ[R] R`. * `Module.dualPairing R M` is the canonical pairing between `Dual R M` and `M`. * `Module.Dual.eval R M : M →ₗ[R] Dual R (Dual R)` is the canonical map to the double dual. * `Module.Dual.transpose` is the linear map from `M →ₗ[R] M'` to `Dual R M' →ₗ[R] Dual R M`. * `LinearMap.dualMap` is `Module.Dual.transpose` of a given linear map, for dot notation. * `LinearEquiv.dualMap` is for the dual of an equivalence. * Bases: * `Basis.toDual` produces the map `M →ₗ[R] Dual R M` associated to a basis for an `R`-module `M`. * `Basis.toDual_equiv` is the equivalence `M ≃ₗ[R] Dual R M` associated to a finite basis. * `Basis.dualBasis` is a basis for `Dual R M` given a finite basis for `M`. * `Module.dual_bases e ε` is the proposition that the families `e` of vectors and `ε` of dual vectors have the characteristic properties of a basis and a dual. * Submodules: * `Submodule.dualRestrict W` is the transpose `Dual R M →ₗ[R] Dual R W` of the inclusion map. * `Submodule.dualAnnihilator W` is the kernel of `W.dualRestrict`. That is, it is the submodule of `dual R M` whose elements all annihilate `W`. * `Submodule.dualRestrict_comap W'` is the dual annihilator of `W' : Submodule R (Dual R M)`, pulled back along `Module.Dual.eval R M`. * `Submodule.dualCopairing W` is the canonical pairing between `W.dualAnnihilator` and `M ⧸ W`. It is nondegenerate for vector spaces (`subspace.dualCopairing_nondegenerate`). * `Submodule.dualPairing W` is the canonical pairing between `Dual R M ⧸ W.dualAnnihilator` and `W`. It is nondegenerate for vector spaces (`Subspace.dualPairing_nondegenerate`). * Vector spaces: * `Subspace.dualLift W` is an arbitrary section (using choice) of `Submodule.dualRestrict W`. ## Main results * Bases: * `Module.dualBasis.basis` and `Module.dualBasis.coe_basis`: if `e` and `ε` form a dual pair, then `e` is a basis. * `Module.dualBasis.coe_dualBasis`: if `e` and `ε` form a dual pair, then `ε` is a basis. * Annihilators: * `Module.dualAnnihilator_gc R M` is the antitone Galois correspondence between `Submodule.dualAnnihilator` and `Submodule.dualConnihilator`. * `LinearMap.ker_dual_map_eq_dualAnnihilator_range` says that `f.dual_map.ker = f.range.dualAnnihilator` * `LinearMap.range_dual_map_eq_dualAnnihilator_ker_of_subtype_range_surjective` says that `f.dual_map.range = f.ker.dualAnnihilator`; this is specialized to vector spaces in `LinearMap.range_dual_map_eq_dualAnnihilator_ker`. * `Submodule.dualQuotEquivDualAnnihilator` is the equivalence `Dual R (M ⧸ W) ≃ₗ[R] W.dualAnnihilator` * `Submodule.quotDualCoannihilatorToDual` is the nondegenerate pairing `M ⧸ W.dualCoannihilator →ₗ[R] Dual R W`. It is an perfect pairing when `R` is a field and `W` is finite-dimensional. * Vector spaces: * `Subspace.dualAnnihilator_dualConnihilator_eq` says that the double dual annihilator, pulled back ground `Module.Dual.eval`, is the original submodule. * `Subspace.dualAnnihilator_gci` says that `module.dualAnnihilator_gc R M` is an antitone Galois coinsertion. * `Subspace.quotAnnihilatorEquiv` is the equivalence `Dual K V ⧸ W.dualAnnihilator ≃ₗ[K] Dual K W`. * `LinearMap.dualPairing_nondegenerate` says that `Module.dualPairing` is nondegenerate. * `Subspace.is_compl_dualAnnihilator` says that the dual annihilator carries complementary subspaces to complementary subspaces. * Finite-dimensional vector spaces: * `Module.evalEquiv` is the equivalence `V ≃ₗ[K] Dual K (Dual K V)` * `Module.mapEvalEquiv` is the order isomorphism between subspaces of `V` and subspaces of `Dual K (Dual K V)`. * `Subspace.orderIsoFiniteCodimDim` is the antitone order isomorphism between finite-codimensional subspaces of `V` and finite-dimensional subspaces of `Dual K V`. * `Subspace.orderIsoFiniteDimensional` is the antitone order isomorphism between subspaces of a finite-dimensional vector space `V` and subspaces of its dual. * `Subspace.quotDualEquivAnnihilator W` is the equivalence `(Dual K V ⧸ W.dualLift.range) ≃ₗ[K] W.dualAnnihilator`, where `W.dualLift.range` is a copy of `Dual K W` inside `Dual K V`. * `Subspace.quotEquivAnnihilator W` is the equivalence `(V ⧸ W) ≃ₗ[K] W.dualAnnihilator` * `Subspace.dualQuotDistrib W` is an equivalence `Dual K (V₁ ⧸ W) ≃ₗ[K] Dual K V₁ ⧸ W.dualLift.range` from an arbitrary choice of splitting of `V₁`. -/ noncomputable section namespace Module -- Porting note: max u v universe issues so name and specific below universe uR uA uM uM' uM'' variable (R : Type uR) (A : Type uA) (M : Type uM) variable [CommSemiring R] [AddCommMonoid M] [Module R M] /-- The dual space of an R-module M is the R-module of linear maps `M → R`. -/ abbrev Dual := M →ₗ[R] R #align module.dual Module.Dual /-- The canonical pairing of a vector space and its algebraic dual. -/ def dualPairing (R M) [CommSemiring R] [AddCommMonoid M] [Module R M] : Module.Dual R M →ₗ[R] M →ₗ[R] R := LinearMap.id #align module.dual_pairing Module.dualPairing @[simp] theorem dualPairing_apply (v x) : dualPairing R M v x = v x := rfl #align module.dual_pairing_apply Module.dualPairing_apply namespace Dual instance : Inhabited (Dual R M) := ⟨0⟩ /-- Maps a module M to the dual of the dual of M. See `Module.erange_coe` and `Module.evalEquiv`. -/ def eval : M →ₗ[R] Dual R (Dual R M) := LinearMap.flip LinearMap.id #align module.dual.eval Module.Dual.eval @[simp] theorem eval_apply (v : M) (a : Dual R M) : eval R M v a = a v := rfl #align module.dual.eval_apply Module.Dual.eval_apply variable {R M} {M' : Type uM'} variable [AddCommMonoid M'] [Module R M'] /-- The transposition of linear maps, as a linear map from `M →ₗ[R] M'` to `Dual R M' →ₗ[R] Dual R M`. -/ def transpose : (M →ₗ[R] M') →ₗ[R] Dual R M' →ₗ[R] Dual R M := (LinearMap.llcomp R M M' R).flip #align module.dual.transpose Module.Dual.transpose -- Porting note: with reducible def need to specify some parameters to transpose explicitly theorem transpose_apply (u : M →ₗ[R] M') (l : Dual R M') : transpose (R := R) u l = l.comp u := rfl #align module.dual.transpose_apply Module.Dual.transpose_apply variable {M'' : Type uM''} [AddCommMonoid M''] [Module R M''] -- Porting note: with reducible def need to specify some parameters to transpose explicitly theorem transpose_comp (u : M' →ₗ[R] M'') (v : M →ₗ[R] M') : transpose (R := R) (u.comp v) = (transpose (R := R) v).comp (transpose (R := R) u) := rfl #align module.dual.transpose_comp Module.Dual.transpose_comp end Dual section Prod variable (M' : Type uM') [AddCommMonoid M'] [Module R M'] /-- Taking duals distributes over products. -/ @[simps!] def dualProdDualEquivDual : (Module.Dual R M × Module.Dual R M') ≃ₗ[R] Module.Dual R (M × M') := LinearMap.coprodEquiv R #align module.dual_prod_dual_equiv_dual Module.dualProdDualEquivDual @[simp] theorem dualProdDualEquivDual_apply (φ : Module.Dual R M) (ψ : Module.Dual R M') : dualProdDualEquivDual R M M' (φ, ψ) = φ.coprod ψ := rfl #align module.dual_prod_dual_equiv_dual_apply Module.dualProdDualEquivDual_apply end Prod end Module section DualMap open Module universe u v v' variable {R : Type u} [CommSemiring R] {M₁ : Type v} {M₂ : Type v'} variable [AddCommMonoid M₁] [Module R M₁] [AddCommMonoid M₂] [Module R M₂] /-- Given a linear map `f : M₁ →ₗ[R] M₂`, `f.dualMap` is the linear map between the dual of `M₂` and `M₁` such that it maps the functional `φ` to `φ ∘ f`. -/ def LinearMap.dualMap (f : M₁ →ₗ[R] M₂) : Dual R M₂ →ₗ[R] Dual R M₁ := -- Porting note: with reducible def need to specify some parameters to transpose explicitly Module.Dual.transpose (R := R) f #align linear_map.dual_map LinearMap.dualMap lemma LinearMap.dualMap_eq_lcomp (f : M₁ →ₗ[R] M₂) : f.dualMap = f.lcomp R := rfl -- Porting note: with reducible def need to specify some parameters to transpose explicitly theorem LinearMap.dualMap_def (f : M₁ →ₗ[R] M₂) : f.dualMap = Module.Dual.transpose (R := R) f := rfl #align linear_map.dual_map_def LinearMap.dualMap_def theorem LinearMap.dualMap_apply' (f : M₁ →ₗ[R] M₂) (g : Dual R M₂) : f.dualMap g = g.comp f := rfl #align linear_map.dual_map_apply' LinearMap.dualMap_apply' @[simp] theorem LinearMap.dualMap_apply (f : M₁ →ₗ[R] M₂) (g : Dual R M₂) (x : M₁) : f.dualMap g x = g (f x) := rfl #align linear_map.dual_map_apply LinearMap.dualMap_apply @[simp] theorem LinearMap.dualMap_id : (LinearMap.id : M₁ →ₗ[R] M₁).dualMap = LinearMap.id := by ext rfl #align linear_map.dual_map_id LinearMap.dualMap_id theorem LinearMap.dualMap_comp_dualMap {M₃ : Type*} [AddCommGroup M₃] [Module R M₃] (f : M₁ →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) : f.dualMap.comp g.dualMap = (g.comp f).dualMap := rfl #align linear_map.dual_map_comp_dual_map LinearMap.dualMap_comp_dualMap /-- If a linear map is surjective, then its dual is injective. -/ theorem LinearMap.dualMap_injective_of_surjective {f : M₁ →ₗ[R] M₂} (hf : Function.Surjective f) : Function.Injective f.dualMap := by intro φ ψ h ext x obtain ⟨y, rfl⟩ := hf x exact congr_arg (fun g : Module.Dual R M₁ => g y) h #align linear_map.dual_map_injective_of_surjective LinearMap.dualMap_injective_of_surjective /-- The `Linear_equiv` version of `LinearMap.dualMap`. -/ def LinearEquiv.dualMap (f : M₁ ≃ₗ[R] M₂) : Dual R M₂ ≃ₗ[R] Dual R M₁ where __ := f.toLinearMap.dualMap invFun := f.symm.toLinearMap.dualMap left_inv φ := LinearMap.ext fun x ↦ congr_arg φ (f.right_inv x) right_inv φ := LinearMap.ext fun x ↦ congr_arg φ (f.left_inv x) #align linear_equiv.dual_map LinearEquiv.dualMap @[simp] theorem LinearEquiv.dualMap_apply (f : M₁ ≃ₗ[R] M₂) (g : Dual R M₂) (x : M₁) : f.dualMap g x = g (f x) := rfl #align linear_equiv.dual_map_apply LinearEquiv.dualMap_apply @[simp] theorem LinearEquiv.dualMap_refl : (LinearEquiv.refl R M₁).dualMap = LinearEquiv.refl R (Dual R M₁) := by ext rfl #align linear_equiv.dual_map_refl LinearEquiv.dualMap_refl @[simp] theorem LinearEquiv.dualMap_symm {f : M₁ ≃ₗ[R] M₂} : (LinearEquiv.dualMap f).symm = LinearEquiv.dualMap f.symm := rfl #align linear_equiv.dual_map_symm LinearEquiv.dualMap_symm theorem LinearEquiv.dualMap_trans {M₃ : Type*} [AddCommGroup M₃] [Module R M₃] (f : M₁ ≃ₗ[R] M₂) (g : M₂ ≃ₗ[R] M₃) : g.dualMap.trans f.dualMap = (f.trans g).dualMap := rfl #align linear_equiv.dual_map_trans LinearEquiv.dualMap_trans @[simp] lemma Dual.apply_one_mul_eq (f : Dual R R) (r : R) : f 1 * r = f r := by conv_rhs => rw [← mul_one r, ← smul_eq_mul] rw [map_smul, smul_eq_mul, mul_comm] @[simp] lemma LinearMap.range_dualMap_dual_eq_span_singleton (f : Dual R M₁) : range f.dualMap = R ∙ f := by ext m rw [Submodule.mem_span_singleton] refine ⟨fun ⟨r, hr⟩ ↦ ⟨r 1, ?_⟩, fun ⟨r, hr⟩ ↦ ⟨r • LinearMap.id, ?_⟩⟩ · ext; simp [dualMap_apply', ← hr] · ext; simp [dualMap_apply', ← hr] end DualMap namespace Basis universe u v w open Module Module.Dual Submodule LinearMap Cardinal Function universe uR uM uK uV uι variable {R : Type uR} {M : Type uM} {K : Type uK} {V : Type uV} {ι : Type uι} section CommSemiring variable [CommSemiring R] [AddCommMonoid M] [Module R M] [DecidableEq ι] variable (b : Basis ι R M) /-- The linear map from a vector space equipped with basis to its dual vector space, taking basis elements to corresponding dual basis elements. -/ def toDual : M →ₗ[R] Module.Dual R M := b.constr ℕ fun v => b.constr ℕ fun w => if w = v then (1 : R) else 0 #align basis.to_dual Basis.toDual theorem toDual_apply (i j : ι) : b.toDual (b i) (b j) = if i = j then 1 else 0 := by erw [constr_basis b, constr_basis b] simp only [eq_comm] #align basis.to_dual_apply Basis.toDual_apply @[simp] theorem toDual_total_left (f : ι →₀ R) (i : ι) : b.toDual (Finsupp.total ι M R b f) (b i) = f i := by rw [Finsupp.total_apply, Finsupp.sum, _root_.map_sum, LinearMap.sum_apply] simp_rw [LinearMap.map_smul, LinearMap.smul_apply, toDual_apply, smul_eq_mul, mul_boole, Finset.sum_ite_eq'] split_ifs with h · rfl · rw [Finsupp.not_mem_support_iff.mp h] #align basis.to_dual_total_left Basis.toDual_total_left @[simp] theorem toDual_total_right (f : ι →₀ R) (i : ι) : b.toDual (b i) (Finsupp.total ι M R b f) = f i := by rw [Finsupp.total_apply, Finsupp.sum, _root_.map_sum] simp_rw [LinearMap.map_smul, toDual_apply, smul_eq_mul, mul_boole, Finset.sum_ite_eq] split_ifs with h · rfl · rw [Finsupp.not_mem_support_iff.mp h] #align basis.to_dual_total_right Basis.toDual_total_right theorem toDual_apply_left (m : M) (i : ι) : b.toDual m (b i) = b.repr m i := by rw [← b.toDual_total_left, b.total_repr] #align basis.to_dual_apply_left Basis.toDual_apply_left theorem toDual_apply_right (i : ι) (m : M) : b.toDual (b i) m = b.repr m i := by rw [← b.toDual_total_right, b.total_repr] #align basis.to_dual_apply_right Basis.toDual_apply_right theorem coe_toDual_self (i : ι) : b.toDual (b i) = b.coord i := by ext apply toDual_apply_right #align basis.coe_to_dual_self Basis.coe_toDual_self /-- `h.toDual_flip v` is the linear map sending `w` to `h.toDual w v`. -/ def toDualFlip (m : M) : M →ₗ[R] R := b.toDual.flip m #align basis.to_dual_flip Basis.toDualFlip theorem toDualFlip_apply (m₁ m₂ : M) : b.toDualFlip m₁ m₂ = b.toDual m₂ m₁ := rfl #align basis.to_dual_flip_apply Basis.toDualFlip_apply theorem toDual_eq_repr (m : M) (i : ι) : b.toDual m (b i) = b.repr m i := b.toDual_apply_left m i #align basis.to_dual_eq_repr Basis.toDual_eq_repr theorem toDual_eq_equivFun [Finite ι] (m : M) (i : ι) : b.toDual m (b i) = b.equivFun m i := by rw [b.equivFun_apply, toDual_eq_repr] #align basis.to_dual_eq_equiv_fun Basis.toDual_eq_equivFun theorem toDual_injective : Injective b.toDual := fun x y h ↦ b.ext_elem_iff.mpr fun i ↦ by simp_rw [← toDual_eq_repr]; exact DFunLike.congr_fun h _ theorem toDual_inj (m : M) (a : b.toDual m = 0) : m = 0 := b.toDual_injective (by rwa [_root_.map_zero]) #align basis.to_dual_inj Basis.toDual_inj -- Porting note (#11036): broken dot notation lean4#1910 LinearMap.ker theorem toDual_ker : LinearMap.ker b.toDual = ⊥ := ker_eq_bot'.mpr b.toDual_inj #align basis.to_dual_ker Basis.toDual_ker -- Porting note (#11036): broken dot notation lean4#1910 LinearMap.range theorem toDual_range [Finite ι] : LinearMap.range b.toDual = ⊤ := by refine eq_top_iff'.2 fun f => ?_ let lin_comb : ι →₀ R := Finsupp.equivFunOnFinite.symm fun i => f (b i) refine ⟨Finsupp.total ι M R b lin_comb, b.ext fun i => ?_⟩ rw [b.toDual_eq_repr _ i, repr_total b] rfl #align basis.to_dual_range Basis.toDual_range end CommSemiring section variable [CommSemiring R] [AddCommMonoid M] [Module R M] [Fintype ι] variable (b : Basis ι R M) @[simp] theorem sum_dual_apply_smul_coord (f : Module.Dual R M) : (∑ x, f (b x) • b.coord x) = f := by ext m simp_rw [LinearMap.sum_apply, LinearMap.smul_apply, smul_eq_mul, mul_comm (f _), ← smul_eq_mul, ← f.map_smul, ← _root_.map_sum, Basis.coord_apply, Basis.sum_repr] #align basis.sum_dual_apply_smul_coord Basis.sum_dual_apply_smul_coord end section CommRing variable [CommRing R] [AddCommGroup M] [Module R M] [DecidableEq ι] variable (b : Basis ι R M) section Finite variable [Finite ι] /-- A vector space is linearly equivalent to its dual space. -/ def toDualEquiv : M ≃ₗ[R] Dual R M := LinearEquiv.ofBijective b.toDual ⟨ker_eq_bot.mp b.toDual_ker, range_eq_top.mp b.toDual_range⟩ #align basis.to_dual_equiv Basis.toDualEquiv -- `simps` times out when generating this @[simp] theorem toDualEquiv_apply (m : M) : b.toDualEquiv m = b.toDual m := rfl #align basis.to_dual_equiv_apply Basis.toDualEquiv_apply -- Not sure whether this is true for free modules over a commutative ring /-- A vector space over a field is isomorphic to its dual if and only if it is finite-dimensional: a consequence of the Erdős-Kaplansky theorem. -/ theorem linearEquiv_dual_iff_finiteDimensional [Field K] [AddCommGroup V] [Module K V] : Nonempty (V ≃ₗ[K] Dual K V) ↔ FiniteDimensional K V := by refine ⟨fun ⟨e⟩ ↦ ?_, fun h ↦ ⟨(Module.Free.chooseBasis K V).toDualEquiv⟩⟩ rw [FiniteDimensional, ← Module.rank_lt_alpeh0_iff] by_contra! apply (lift_rank_lt_rank_dual this).ne have := e.lift_rank_eq rwa [lift_umax.{uV,uK}, lift_id'.{uV,uK}] at this /-- Maps a basis for `V` to a basis for the dual space. -/ def dualBasis : Basis ι R (Dual R M) := b.map b.toDualEquiv #align basis.dual_basis Basis.dualBasis -- We use `j = i` to match `Basis.repr_self` theorem dualBasis_apply_self (i j : ι) : b.dualBasis i (b j) = if j = i then 1 else 0 := by convert b.toDual_apply i j using 2 rw [@eq_comm _ j i] #align basis.dual_basis_apply_self Basis.dualBasis_apply_self theorem total_dualBasis (f : ι →₀ R) (i : ι) : Finsupp.total ι (Dual R M) R b.dualBasis f (b i) = f i := by cases nonempty_fintype ι rw [Finsupp.total_apply, Finsupp.sum_fintype, LinearMap.sum_apply] · simp_rw [LinearMap.smul_apply, smul_eq_mul, dualBasis_apply_self, mul_boole, Finset.sum_ite_eq, if_pos (Finset.mem_univ i)] · intro rw [zero_smul] #align basis.total_dual_basis Basis.total_dualBasis theorem dualBasis_repr (l : Dual R M) (i : ι) : b.dualBasis.repr l i = l (b i) := by rw [← total_dualBasis b, Basis.total_repr b.dualBasis l] #align basis.dual_basis_repr Basis.dualBasis_repr theorem dualBasis_apply (i : ι) (m : M) : b.dualBasis i m = b.repr m i := b.toDual_apply_right i m #align basis.dual_basis_apply Basis.dualBasis_apply @[simp] theorem coe_dualBasis : ⇑b.dualBasis = b.coord := by ext i x apply dualBasis_apply #align basis.coe_dual_basis Basis.coe_dualBasis @[simp] theorem toDual_toDual : b.dualBasis.toDual.comp b.toDual = Dual.eval R M := by refine b.ext fun i => b.dualBasis.ext fun j => ?_ rw [LinearMap.comp_apply, toDual_apply_left, coe_toDual_self, ← coe_dualBasis, Dual.eval_apply, Basis.repr_self, Finsupp.single_apply, dualBasis_apply_self] #align basis.to_dual_to_dual Basis.toDual_toDual end Finite theorem dualBasis_equivFun [Finite ι] (l : Dual R M) (i : ι) : b.dualBasis.equivFun l i = l (b i) := by rw [Basis.equivFun_apply, dualBasis_repr] #align basis.dual_basis_equiv_fun Basis.dualBasis_equivFun theorem eval_ker {ι : Type*} (b : Basis ι R M) : LinearMap.ker (Dual.eval R M) = ⊥ := by rw [ker_eq_bot'] intro m hm simp_rw [LinearMap.ext_iff, Dual.eval_apply, zero_apply] at hm exact (Basis.forall_coord_eq_zero_iff _).mp fun i => hm (b.coord i) #align basis.eval_ker Basis.eval_ker -- Porting note (#11036): broken dot notation lean4#1910 LinearMap.range theorem eval_range {ι : Type*} [Finite ι] (b : Basis ι R M) : LinearMap.range (Dual.eval R M) = ⊤ := by classical cases nonempty_fintype ι rw [← b.toDual_toDual, range_comp, b.toDual_range, Submodule.map_top, toDual_range _] #align basis.eval_range Basis.eval_range section variable [Finite R M] [Free R M] instance dual_free : Free R (Dual R M) := Free.of_basis (Free.chooseBasis R M).dualBasis #align basis.dual_free Basis.dual_free instance dual_finite : Finite R (Dual R M) := Finite.of_basis (Free.chooseBasis R M).dualBasis #align basis.dual_finite Basis.dual_finite end end CommRing /-- `simp` normal form version of `total_dualBasis` -/ @[simp] theorem total_coord [CommRing R] [AddCommGroup M] [Module R M] [Finite ι] (b : Basis ι R M) (f : ι →₀ R) (i : ι) : Finsupp.total ι (Dual R M) R b.coord f (b i) = f i := by haveI := Classical.decEq ι rw [← coe_dualBasis, total_dualBasis] #align basis.total_coord Basis.total_coord theorem dual_rank_eq [CommRing K] [AddCommGroup V] [Module K V] [Finite ι] (b : Basis ι K V) : Cardinal.lift.{uK,uV} (Module.rank K V) = Module.rank K (Dual K V) := by classical rw [← lift_umax.{uV,uK}, b.toDualEquiv.lift_rank_eq, lift_id'.{uV,uK}] #align basis.dual_rank_eq Basis.dual_rank_eq end Basis namespace Module universe uK uV variable {K : Type uK} {V : Type uV} variable [CommRing K] [AddCommGroup V] [Module K V] [Module.Free K V] open Module Module.Dual Submodule LinearMap Cardinal Basis FiniteDimensional section variable (K) (V) -- Porting note (#11036): broken dot notation lean4#1910 LinearMap.ker theorem eval_ker : LinearMap.ker (eval K V) = ⊥ := by classical exact (Module.Free.chooseBasis K V).eval_ker #align module.eval_ker Module.eval_ker theorem map_eval_injective : (Submodule.map (eval K V)).Injective := by apply Submodule.map_injective_of_injective rw [← LinearMap.ker_eq_bot] exact eval_ker K V #align module.map_eval_injective Module.map_eval_injective theorem comap_eval_surjective : (Submodule.comap (eval K V)).Surjective := by apply Submodule.comap_surjective_of_injective rw [← LinearMap.ker_eq_bot] exact eval_ker K V #align module.comap_eval_surjective Module.comap_eval_surjective end section variable (K) theorem eval_apply_eq_zero_iff (v : V) : (eval K V) v = 0 ↔ v = 0 := by simpa only using SetLike.ext_iff.mp (eval_ker K V) v #align module.eval_apply_eq_zero_iff Module.eval_apply_eq_zero_iff theorem eval_apply_injective : Function.Injective (eval K V) := (injective_iff_map_eq_zero' (eval K V)).mpr (eval_apply_eq_zero_iff K) #align module.eval_apply_injective Module.eval_apply_injective theorem forall_dual_apply_eq_zero_iff (v : V) : (∀ φ : Module.Dual K V, φ v = 0) ↔ v = 0 := by rw [← eval_apply_eq_zero_iff K v, LinearMap.ext_iff] rfl #align module.forall_dual_apply_eq_zero_iff Module.forall_dual_apply_eq_zero_iff @[simp] theorem subsingleton_dual_iff : Subsingleton (Dual K V) ↔ Subsingleton V := by refine ⟨fun h ↦ ⟨fun v w ↦ ?_⟩, fun h ↦ ⟨fun f g ↦ ?_⟩⟩ · rw [← sub_eq_zero, ← forall_dual_apply_eq_zero_iff K (v - w)] intros f simp [Subsingleton.elim f 0] · ext v simp [Subsingleton.elim v 0] instance instSubsingletonDual [Subsingleton V] : Subsingleton (Dual K V) := (subsingleton_dual_iff K).mp inferInstance @[simp] theorem nontrivial_dual_iff : Nontrivial (Dual K V) ↔ Nontrivial V := by rw [← not_iff_not, not_nontrivial_iff_subsingleton, not_nontrivial_iff_subsingleton, subsingleton_dual_iff] instance instNontrivialDual [Nontrivial V] : Nontrivial (Dual K V) := (nontrivial_dual_iff K).mpr inferInstance theorem finite_dual_iff : Finite K (Dual K V) ↔ Finite K V := by constructor <;> intro h · obtain ⟨⟨ι, b⟩⟩ := Module.Free.exists_basis (R := K) (M := V) nontriviality K obtain ⟨⟨s, span_s⟩⟩ := h classical haveI := (b.linearIndependent.map' _ b.toDual_ker).finite_of_le_span_finite _ s ?_ · exact Finite.of_basis b · rw [span_s]; apply le_top · infer_instance end theorem dual_rank_eq [Module.Finite K V] : Cardinal.lift.{uK,uV} (Module.rank K V) = Module.rank K (Dual K V) := (Module.Free.chooseBasis K V).dual_rank_eq #align module.dual_rank_eq Module.dual_rank_eq -- Porting note (#11036): broken dot notation lean4#1910 LinearMap.range theorem erange_coe [Module.Finite K V] : LinearMap.range (eval K V) = ⊤ := (Module.Free.chooseBasis K V).eval_range #align module.erange_coe Module.erange_coe section IsReflexive open Function variable (R M N : Type*) [CommRing R] [AddCommGroup M] [AddCommGroup N] [Module R M] [Module R N] /-- A reflexive module is one for which the natural map to its double dual is a bijection. Any finitely-generated free module (and thus any finite-dimensional vector space) is reflexive. See `Module.IsReflexive.of_finite_of_free`. -/ class IsReflexive : Prop where /-- A reflexive module is one for which the natural map to its double dual is a bijection. -/ bijective_dual_eval' : Bijective (Dual.eval R M) lemma bijective_dual_eval [IsReflexive R M] : Bijective (Dual.eval R M) := IsReflexive.bijective_dual_eval' instance IsReflexive.of_finite_of_free [Finite R M] [Free R M] : IsReflexive R M where bijective_dual_eval' := ⟨LinearMap.ker_eq_bot.mp (Free.chooseBasis R M).eval_ker, LinearMap.range_eq_top.mp (Free.chooseBasis R M).eval_range⟩ variable [IsReflexive R M] /-- The bijection between a reflexive module and its double dual, bundled as a `LinearEquiv`. -/ def evalEquiv : M ≃ₗ[R] Dual R (Dual R M) := LinearEquiv.ofBijective _ (bijective_dual_eval R M) #align module.eval_equiv Module.evalEquiv @[simp] lemma evalEquiv_toLinearMap : evalEquiv R M = Dual.eval R M := rfl #align module.eval_equiv_to_linear_map Module.evalEquiv_toLinearMap @[simp] lemma evalEquiv_apply (m : M) : evalEquiv R M m = Dual.eval R M m := rfl @[simp] lemma apply_evalEquiv_symm_apply (f : Dual R M) (g : Dual R (Dual R M)) : f ((evalEquiv R M).symm g) = g f := by set m := (evalEquiv R M).symm g rw [← (evalEquiv R M).apply_symm_apply g, evalEquiv_apply, Dual.eval_apply] @[simp] lemma symm_dualMap_evalEquiv : (evalEquiv R M).symm.dualMap = Dual.eval R (Dual R M) := by ext; simp /-- The dual of a reflexive module is reflexive. -/ instance Dual.instIsReflecive : IsReflexive R (Dual R M) := ⟨by simpa only [← symm_dualMap_evalEquiv] using (evalEquiv R M).dualMap.symm.bijective⟩ /-- The isomorphism `Module.evalEquiv` induces an order isomorphism on subspaces. -/ def mapEvalEquiv : Submodule R M ≃o Submodule R (Dual R (Dual R M)) := Submodule.orderIsoMapComap (evalEquiv R M) #align module.map_eval_equiv Module.mapEvalEquiv @[simp] theorem mapEvalEquiv_apply (W : Submodule R M) : mapEvalEquiv R M W = W.map (Dual.eval R M) := rfl #align module.map_eval_equiv_apply Module.mapEvalEquiv_apply @[simp] theorem mapEvalEquiv_symm_apply (W'' : Submodule R (Dual R (Dual R M))) : (mapEvalEquiv R M).symm W'' = W''.comap (Dual.eval R M) := rfl #align module.map_eval_equiv_symm_apply Module.mapEvalEquiv_symm_apply instance _root_.Prod.instModuleIsReflexive [IsReflexive R N] : IsReflexive R (M × N) where bijective_dual_eval' := by let e : Dual R (Dual R (M × N)) ≃ₗ[R] Dual R (Dual R M) × Dual R (Dual R N) := (dualProdDualEquivDual R M N).dualMap.trans (dualProdDualEquivDual R (Dual R M) (Dual R N)).symm have : Dual.eval R (M × N) = e.symm.comp ((Dual.eval R M).prodMap (Dual.eval R N)) := by ext m f <;> simp [e] simp only [this, LinearEquiv.trans_symm, LinearEquiv.symm_symm, LinearEquiv.dualMap_symm, coe_comp, LinearEquiv.coe_coe, EquivLike.comp_bijective] exact (bijective_dual_eval R M).prodMap (bijective_dual_eval R N) variable {R M N} in lemma equiv (e : M ≃ₗ[R] N) : IsReflexive R N where bijective_dual_eval' := by let ed : Dual R (Dual R N) ≃ₗ[R] Dual R (Dual R M) := e.symm.dualMap.dualMap have : Dual.eval R N = ed.symm.comp ((Dual.eval R M).comp e.symm.toLinearMap) := by ext m f exact DFunLike.congr_arg f (e.apply_symm_apply m).symm simp only [this, LinearEquiv.trans_symm, LinearEquiv.symm_symm, LinearEquiv.dualMap_symm, coe_comp, LinearEquiv.coe_coe, EquivLike.comp_bijective] exact Bijective.comp (bijective_dual_eval R M) (LinearEquiv.bijective _) instance _root_.MulOpposite.instModuleIsReflexive : IsReflexive R (MulOpposite M) := equiv <| MulOpposite.opLinearEquiv _ instance _root_.ULift.instModuleIsReflexive.{w} : IsReflexive R (ULift.{w} M) := equiv ULift.moduleEquiv.symm end IsReflexive end Module namespace Submodule open Module variable {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] {p : Submodule R M} theorem exists_dual_map_eq_bot_of_nmem {x : M} (hx : x ∉ p) (hp' : Free R (M ⧸ p)) : ∃ f : Dual R M, f x ≠ 0 ∧ p.map f = ⊥ := by suffices ∃ f : Dual R (M ⧸ p), f (p.mkQ x) ≠ 0 by obtain ⟨f, hf⟩ := this; exact ⟨f.comp p.mkQ, hf, by simp [Submodule.map_comp]⟩ rwa [← Submodule.Quotient.mk_eq_zero, ← Submodule.mkQ_apply, ← forall_dual_apply_eq_zero_iff (K := R), not_forall] at hx
Mathlib/LinearAlgebra/Dual.lean
727
731
theorem exists_dual_map_eq_bot_of_lt_top (hp : p < ⊤) (hp' : Free R (M ⧸ p)) : ∃ f : Dual R M, f ≠ 0 ∧ p.map f = ⊥ := by
obtain ⟨x, hx⟩ : ∃ x : M, x ∉ p := by rw [lt_top_iff_ne_top] at hp; contrapose! hp; ext; simp [hp] obtain ⟨f, hf, hf'⟩ := p.exists_dual_map_eq_bot_of_nmem hx hp' exact ⟨f, by aesop, hf'⟩
/- Copyright (c) 2022 Cuma Kökmen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Cuma Kökmen, Yury Kudryashov -/ import Mathlib.MeasureTheory.Constructions.Prod.Integral import Mathlib.MeasureTheory.Integral.CircleIntegral #align_import measure_theory.integral.torus_integral from "leanprover-community/mathlib"@"fd5edc43dc4f10b85abfe544b88f82cf13c5f844" /-! # Integral over a torus in `ℂⁿ` In this file we define the integral of a function `f : ℂⁿ → E` over a torus `{z : ℂⁿ | ∀ i, z i ∈ Metric.sphere (c i) (R i)}`. In order to do this, we define `torusMap (c : ℂⁿ) (R θ : ℝⁿ)` to be the point in `ℂⁿ` given by $z_k=c_k+R_ke^{θ_ki}$, where $i$ is the imaginary unit, then define `torusIntegral f c R` as the integral over the cube $[0, (fun _ ↦ 2π)] = \{θ\|∀ k, 0 ≤ θ_k ≤ 2π\}$ of the Jacobian of the `torusMap` multiplied by `f (torusMap c R θ)`. We also define a predicate saying that `f ∘ torusMap c R` is integrable on the cube `[0, (fun _ ↦ 2π)]`. ## Main definitions * `torusMap c R`: the generalized multidimensional exponential map from `ℝⁿ` to `ℂⁿ` that sends $θ=(θ_0,…,θ_{n-1})$ to $z=(z_0,…,z_{n-1})$, where $z_k= c_k + R_ke^{θ_k i}$; * `TorusIntegrable f c R`: a function `f : ℂⁿ → E` is integrable over the generalized torus with center `c : ℂⁿ` and radius `R : ℝⁿ` if `f ∘ torusMap c R` is integrable on the closed cube `Icc (0 : ℝⁿ) (fun _ ↦ 2 * π)`; * `torusIntegral f c R`: the integral of a function `f : ℂⁿ → E` over a torus with center `c ∈ ℂⁿ` and radius `R ∈ ℝⁿ` defined as $\iiint_{[0, 2 * π]} (∏_{k = 1}^{n} i R_k e^{θ_k * i}) • f (c + Re^{θ_k i})\,dθ_0…dθ_{k-1}$. ## Main statements * `torusIntegral_dim0`, `torusIntegral_dim1`, `torusIntegral_succ`: formulas for `torusIntegral` in cases of dimension `0`, `1`, and `n + 1`. ## Notations - `ℝ⁰`, `ℝ¹`, `ℝⁿ`, `ℝⁿ⁺¹`: local notation for `Fin 0 → ℝ`, `Fin 1 → ℝ`, `Fin n → ℝ`, and `Fin (n + 1) → ℝ`, respectively; - `ℂ⁰`, `ℂ¹`, `ℂⁿ`, `ℂⁿ⁺¹`: local notation for `Fin 0 → ℂ`, `Fin 1 → ℂ`, `Fin n → ℂ`, and `Fin (n + 1) → ℂ`, respectively; - `∯ z in T(c, R), f z`: notation for `torusIntegral f c R`; - `∮ z in C(c, R), f z`: notation for `circleIntegral f c R`, defined elsewhere; - `∏ k, f k`: notation for `Finset.prod`, defined elsewhere; - `π`: notation for `Real.pi`, defined elsewhere. ## Tags integral, torus -/ variable {n : ℕ} variable {E : Type*} [NormedAddCommGroup E] noncomputable section open Complex Set MeasureTheory Function Filter TopologicalSpace open scoped Real -- Porting note: notation copied from `./DivergenceTheorem` local macro:arg t:term:max noWs "ⁿ⁺¹" : term => `(Fin (n + 1) → $t) local macro:arg t:term:max noWs "ⁿ" : term => `(Fin n → $t) local macro:arg t:term:max noWs "⁰" : term => `(Fin 0 → $t) local macro:arg t:term:max noWs "¹" : term => `(Fin 1 → $t) /-! ### `torusMap`, a parametrization of a torus -/ /-- The n dimensional exponential map $θ_i ↦ c + R e^{θ_i*I}, θ ∈ ℝⁿ$ representing a torus in `ℂⁿ` with center `c ∈ ℂⁿ` and generalized radius `R ∈ ℝⁿ`, so we can adjust it to every n axis. -/ def torusMap (c : ℂⁿ) (R : ℝⁿ) : ℝⁿ → ℂⁿ := fun θ i => c i + R i * exp (θ i * I) #align torus_map torusMap theorem torusMap_sub_center (c : ℂⁿ) (R : ℝⁿ) (θ : ℝⁿ) : torusMap c R θ - c = torusMap 0 R θ := by ext1 i; simp [torusMap] #align torus_map_sub_center torusMap_sub_center theorem torusMap_eq_center_iff {c : ℂⁿ} {R : ℝⁿ} {θ : ℝⁿ} : torusMap c R θ = c ↔ R = 0 := by simp [funext_iff, torusMap, exp_ne_zero] #align torus_map_eq_center_iff torusMap_eq_center_iff @[simp] theorem torusMap_zero_radius (c : ℂⁿ) : torusMap c 0 = const ℝⁿ c := funext fun _ ↦ torusMap_eq_center_iff.2 rfl #align torus_map_zero_radius torusMap_zero_radius /-! ### Integrability of a function on a generalized torus -/ /-- A function `f : ℂⁿ → E` is integrable on the generalized torus if the function `f ∘ torusMap c R θ` is integrable on `Icc (0 : ℝⁿ) (fun _ ↦ 2 * π)`. -/ def TorusIntegrable (f : ℂⁿ → E) (c : ℂⁿ) (R : ℝⁿ) : Prop := IntegrableOn (fun θ : ℝⁿ => f (torusMap c R θ)) (Icc (0 : ℝⁿ) fun _ => 2 * π) volume #align torus_integrable TorusIntegrable namespace TorusIntegrable -- Porting note (#11215): TODO: restore notation; `neg`, `add` etc fail if I use notation here variable {f g : (Fin n → ℂ) → E} {c : Fin n → ℂ} {R : Fin n → ℝ} /-- Constant functions are torus integrable -/ theorem torusIntegrable_const (a : E) (c : ℂⁿ) (R : ℝⁿ) : TorusIntegrable (fun _ => a) c R := by simp [TorusIntegrable, measure_Icc_lt_top] #align torus_integrable.torus_integrable_const TorusIntegrable.torusIntegrable_const /-- If `f` is torus integrable then `-f` is torus integrable. -/ protected nonrec theorem neg (hf : TorusIntegrable f c R) : TorusIntegrable (-f) c R := hf.neg #align torus_integrable.neg TorusIntegrable.neg /-- If `f` and `g` are two torus integrable functions, then so is `f + g`. -/ protected nonrec theorem add (hf : TorusIntegrable f c R) (hg : TorusIntegrable g c R) : TorusIntegrable (f + g) c R := hf.add hg #align torus_integrable.add TorusIntegrable.add /-- If `f` and `g` are two torus integrable functions, then so is `f - g`. -/ protected nonrec theorem sub (hf : TorusIntegrable f c R) (hg : TorusIntegrable g c R) : TorusIntegrable (f - g) c R := hf.sub hg #align torus_integrable.sub TorusIntegrable.sub theorem torusIntegrable_zero_radius {f : ℂⁿ → E} {c : ℂⁿ} : TorusIntegrable f c 0 := by rw [TorusIntegrable, torusMap_zero_radius] apply torusIntegrable_const (f c) c 0 #align torus_integrable.torus_integrable_zero_radius TorusIntegrable.torusIntegrable_zero_radius /-- The function given in the definition of `torusIntegral` is integrable. -/ theorem function_integrable [NormedSpace ℂ E] (hf : TorusIntegrable f c R) : IntegrableOn (fun θ : ℝⁿ => (∏ i, R i * exp (θ i * I) * I : ℂ) • f (torusMap c R θ)) (Icc (0 : ℝⁿ) fun _ => 2 * π) volume := by refine (hf.norm.const_mul (∏ i, |R i|)).mono' ?_ ?_ · refine (Continuous.aestronglyMeasurable ?_).smul hf.1; continuity simp [norm_smul, map_prod] #align torus_integrable.function_integrable TorusIntegrable.function_integrable end TorusIntegrable variable [NormedSpace ℂ E] [CompleteSpace E] {f g : (Fin n → ℂ) → E} {c : Fin n → ℂ} {R : Fin n → ℝ} /-- The integral over a generalized torus with center `c ∈ ℂⁿ` and radius `R ∈ ℝⁿ`, defined as the `•`-product of the derivative of `torusMap` and `f (torusMap c R θ)`-/ def torusIntegral (f : ℂⁿ → E) (c : ℂⁿ) (R : ℝⁿ) := ∫ θ : ℝⁿ in Icc (0 : ℝⁿ) fun _ => 2 * π, (∏ i, R i * exp (θ i * I) * I : ℂ) • f (torusMap c R θ) #align torus_integral torusIntegral @[inherit_doc torusIntegral] notation3"∯ "(...)" in ""T("c", "R")"", "r:(scoped f => torusIntegral f c R) => r theorem torusIntegral_radius_zero (hn : n ≠ 0) (f : ℂⁿ → E) (c : ℂⁿ) : (∯ x in T(c, 0), f x) = 0 := by simp only [torusIntegral, Pi.zero_apply, ofReal_zero, mul_zero, zero_mul, Fin.prod_const, zero_pow hn, zero_smul, integral_zero] #align torus_integral_radius_zero torusIntegral_radius_zero theorem torusIntegral_neg (f : ℂⁿ → E) (c : ℂⁿ) (R : ℝⁿ) : (∯ x in T(c, R), -f x) = -∯ x in T(c, R), f x := by simp [torusIntegral, integral_neg] #align torus_integral_neg torusIntegral_neg theorem torusIntegral_add (hf : TorusIntegrable f c R) (hg : TorusIntegrable g c R) : (∯ x in T(c, R), f x + g x) = (∯ x in T(c, R), f x) + ∯ x in T(c, R), g x := by simpa only [torusIntegral, smul_add, Pi.add_apply] using integral_add hf.function_integrable hg.function_integrable #align torus_integral_add torusIntegral_add theorem torusIntegral_sub (hf : TorusIntegrable f c R) (hg : TorusIntegrable g c R) : (∯ x in T(c, R), f x - g x) = (∯ x in T(c, R), f x) - ∯ x in T(c, R), g x := by simpa only [sub_eq_add_neg, ← torusIntegral_neg] using torusIntegral_add hf hg.neg #align torus_integral_sub torusIntegral_sub theorem torusIntegral_smul {𝕜 : Type*} [RCLike 𝕜] [NormedSpace 𝕜 E] [SMulCommClass 𝕜 ℂ E] (a : 𝕜) (f : ℂⁿ → E) (c : ℂⁿ) (R : ℝⁿ) : (∯ x in T(c, R), a • f x) = a • ∯ x in T(c, R), f x := by simp only [torusIntegral, integral_smul, ← smul_comm a (_ : ℂ) (_ : E)] #align torus_integral_smul torusIntegral_smul theorem torusIntegral_const_mul (a : ℂ) (f : ℂⁿ → ℂ) (c : ℂⁿ) (R : ℝⁿ) : (∯ x in T(c, R), a * f x) = a * ∯ x in T(c, R), f x := torusIntegral_smul a f c R #align torus_integral_const_mul torusIntegral_const_mul /-- If for all `θ : ℝⁿ`, `‖f (torusMap c R θ)‖` is less than or equal to a constant `C : ℝ`, then `‖∯ x in T(c, R), f x‖` is less than or equal to `(2 * π)^n * (∏ i, |R i|) * C`-/ theorem norm_torusIntegral_le_of_norm_le_const {C : ℝ} (hf : ∀ θ, ‖f (torusMap c R θ)‖ ≤ C) : ‖∯ x in T(c, R), f x‖ ≤ ((2 * π) ^ (n : ℕ) * ∏ i, |R i|) * C := calc ‖∯ x in T(c, R), f x‖ ≤ (∏ i, |R i|) * C * (volume (Icc (0 : ℝⁿ) fun _ => 2 * π)).toReal := norm_setIntegral_le_of_norm_le_const' measure_Icc_lt_top measurableSet_Icc fun θ _ => calc ‖(∏ i : Fin n, R i * exp (θ i * I) * I : ℂ) • f (torusMap c R θ)‖ = (∏ i : Fin n, |R i|) * ‖f (torusMap c R θ)‖ := by simp [norm_smul] _ ≤ (∏ i : Fin n, |R i|) * C := mul_le_mul_of_nonneg_left (hf _) <| by positivity _ = ((2 * π) ^ (n : ℕ) * ∏ i, |R i|) * C := by simp only [Pi.zero_def, Real.volume_Icc_pi_toReal fun _ => Real.two_pi_pos.le, sub_zero, Fin.prod_const, mul_assoc, mul_comm ((2 * π) ^ (n : ℕ))] #align norm_torus_integral_le_of_norm_le_const norm_torusIntegral_le_of_norm_le_const @[simp] theorem torusIntegral_dim0 (f : ℂ⁰ → E) (c : ℂ⁰) (R : ℝ⁰) : (∯ x in T(c, R), f x) = f c := by simp only [torusIntegral, Fin.prod_univ_zero, one_smul, Subsingleton.elim (fun _ : Fin 0 => 2 * π) 0, Icc_self, Measure.restrict_singleton, volume_pi, integral_smul_measure, integral_dirac, Measure.pi_of_empty (fun _ : Fin 0 ↦ volume) 0, Measure.dirac_apply_of_mem (mem_singleton _), Subsingleton.elim (torusMap c R 0) c] #align torus_integral_dim0 torusIntegral_dim0 /-- In dimension one, `torusIntegral` is the same as `circleIntegral` (up to the natural equivalence between `ℂ` and `Fin 1 → ℂ`). -/ theorem torusIntegral_dim1 (f : ℂ¹ → E) (c : ℂ¹) (R : ℝ¹) : (∯ x in T(c, R), f x) = ∮ z in C(c 0, R 0), f fun _ => z := by have H₁ : (((MeasurableEquiv.funUnique _ _).symm) ⁻¹' Icc 0 fun _ => 2 * π) = Icc 0 (2 * π) := (OrderIso.funUnique (Fin 1) ℝ).symm.preimage_Icc _ _ have H₂ : torusMap c R = fun θ _ ↦ circleMap (c 0) (R 0) (θ 0) := by ext θ i : 2 rw [Subsingleton.elim i 0]; rfl rw [torusIntegral, circleIntegral, intervalIntegral.integral_of_le Real.two_pi_pos.le, Measure.restrict_congr_set Ioc_ae_eq_Icc, ← ((volume_preserving_funUnique (Fin 1) ℝ).symm _).setIntegral_preimage_emb (MeasurableEquiv.measurableEmbedding _), H₁, H₂] simp [circleMap_zero] #align torus_integral_dim1 torusIntegral_dim1 /-- Recurrent formula for `torusIntegral`, see also `torusIntegral_succ`. -/
Mathlib/MeasureTheory/Integral/TorusIntegral.lean
232
253
theorem torusIntegral_succAbove {f : ℂⁿ⁺¹ → E} {c : ℂⁿ⁺¹} {R : ℝⁿ⁺¹} (hf : TorusIntegrable f c R) (i : Fin (n + 1)) : (∯ x in T(c, R), f x) = ∮ x in C(c i, R i), ∯ y in T(c ∘ i.succAbove, R ∘ i.succAbove), f (i.insertNth x y) := by
set e : ℝ × ℝⁿ ≃ᵐ ℝⁿ⁺¹ := (MeasurableEquiv.piFinSuccAbove (fun _ => ℝ) i).symm have hem : MeasurePreserving e := (volume_preserving_piFinSuccAbove (fun _ : Fin (n + 1) => ℝ) i).symm _ have heπ : (e ⁻¹' Icc 0 fun _ => 2 * π) = Icc 0 (2 * π) ×ˢ Icc (0 : ℝⁿ) fun _ => 2 * π := ((OrderIso.piFinSuccAboveIso (fun _ => ℝ) i).symm.preimage_Icc _ _).trans (Icc_prod_eq _ _) rw [torusIntegral, ← hem.map_eq, setIntegral_map_equiv, heπ, Measure.volume_eq_prod, setIntegral_prod, circleIntegral_def_Icc] · refine setIntegral_congr measurableSet_Icc fun θ _ => ?_ simp (config := { unfoldPartialApp := true }) only [e, torusIntegral, ← integral_smul, deriv_circleMap, i.prod_univ_succAbove _, smul_smul, torusMap, circleMap_zero] refine setIntegral_congr measurableSet_Icc fun Θ _ => ?_ simp only [MeasurableEquiv.piFinSuccAbove_symm_apply, i.insertNth_apply_same, i.insertNth_apply_succAbove, (· ∘ ·)] congr 2 simp only [funext_iff, i.forall_iff_succAbove, circleMap, Fin.insertNth_apply_same, eq_self_iff_true, Fin.insertNth_apply_succAbove, imp_true_iff, and_self_iff] · have := hf.function_integrable rwa [← hem.integrableOn_comp_preimage e.measurableEmbedding, heπ] at this
/- Copyright (c) 2020 Aaron Anderson, Jalex Stark, Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Jalex Stark, Kyle Miller, Alena Gusakov -/ import Mathlib.Algebra.Order.Ring.Defs import Mathlib.Combinatorics.SimpleGraph.Basic import Mathlib.Data.Sym.Card /-! # Definitions for finite and locally finite graphs This file defines finite versions of `edgeSet`, `neighborSet` and `incidenceSet` and proves some of their basic properties. It also defines the notion of a locally finite graph, which is one whose vertices have finite degree. The design for finiteness is that each definition takes the smallest finiteness assumption necessary. For example, `SimpleGraph.neighborFinset v` only requires that `v` have finitely many neighbors. ## Main definitions * `SimpleGraph.edgeFinset` is the `Finset` of edges in a graph, if `edgeSet` is finite * `SimpleGraph.neighborFinset` is the `Finset` of vertices adjacent to a given vertex, if `neighborSet` is finite * `SimpleGraph.incidenceFinset` is the `Finset` of edges containing a given vertex, if `incidenceSet` is finite ## Naming conventions If the vertex type of a graph is finite, we refer to its cardinality as `CardVerts` or `card_verts`. ## Implementation notes * A locally finite graph is one with instances `Π v, Fintype (G.neighborSet v)`. * Given instances `DecidableRel G.Adj` and `Fintype V`, then the graph is locally finite, too. -/ open Finset Function namespace SimpleGraph variable {V : Type*} (G : SimpleGraph V) {e : Sym2 V} section EdgeFinset variable {G₁ G₂ : SimpleGraph V} [Fintype G.edgeSet] [Fintype G₁.edgeSet] [Fintype G₂.edgeSet] /-- The `edgeSet` of the graph as a `Finset`. -/ abbrev edgeFinset : Finset (Sym2 V) := Set.toFinset G.edgeSet #align simple_graph.edge_finset SimpleGraph.edgeFinset @[norm_cast] theorem coe_edgeFinset : (G.edgeFinset : Set (Sym2 V)) = G.edgeSet := Set.coe_toFinset _ #align simple_graph.coe_edge_finset SimpleGraph.coe_edgeFinset variable {G} theorem mem_edgeFinset : e ∈ G.edgeFinset ↔ e ∈ G.edgeSet := Set.mem_toFinset #align simple_graph.mem_edge_finset SimpleGraph.mem_edgeFinset theorem not_isDiag_of_mem_edgeFinset : e ∈ G.edgeFinset → ¬e.IsDiag := not_isDiag_of_mem_edgeSet _ ∘ mem_edgeFinset.1 #align simple_graph.not_is_diag_of_mem_edge_finset SimpleGraph.not_isDiag_of_mem_edgeFinset theorem edgeFinset_inj : G₁.edgeFinset = G₂.edgeFinset ↔ G₁ = G₂ := by simp #align simple_graph.edge_finset_inj SimpleGraph.edgeFinset_inj theorem edgeFinset_subset_edgeFinset : G₁.edgeFinset ⊆ G₂.edgeFinset ↔ G₁ ≤ G₂ := by simp #align simple_graph.edge_finset_subset_edge_finset SimpleGraph.edgeFinset_subset_edgeFinset theorem edgeFinset_ssubset_edgeFinset : G₁.edgeFinset ⊂ G₂.edgeFinset ↔ G₁ < G₂ := by simp #align simple_graph.edge_finset_ssubset_edge_finset SimpleGraph.edgeFinset_ssubset_edgeFinset @[gcongr] alias ⟨_, edgeFinset_mono⟩ := edgeFinset_subset_edgeFinset #align simple_graph.edge_finset_mono SimpleGraph.edgeFinset_mono alias ⟨_, edgeFinset_strict_mono⟩ := edgeFinset_ssubset_edgeFinset #align simple_graph.edge_finset_strict_mono SimpleGraph.edgeFinset_strict_mono attribute [mono] edgeFinset_mono edgeFinset_strict_mono @[simp] theorem edgeFinset_bot : (⊥ : SimpleGraph V).edgeFinset = ∅ := by simp [edgeFinset] #align simple_graph.edge_finset_bot SimpleGraph.edgeFinset_bot @[simp] theorem edgeFinset_sup [Fintype (edgeSet (G₁ ⊔ G₂))] [DecidableEq V] : (G₁ ⊔ G₂).edgeFinset = G₁.edgeFinset ∪ G₂.edgeFinset := by simp [edgeFinset] #align simple_graph.edge_finset_sup SimpleGraph.edgeFinset_sup @[simp] theorem edgeFinset_inf [DecidableEq V] : (G₁ ⊓ G₂).edgeFinset = G₁.edgeFinset ∩ G₂.edgeFinset := by simp [edgeFinset] #align simple_graph.edge_finset_inf SimpleGraph.edgeFinset_inf @[simp] theorem edgeFinset_sdiff [DecidableEq V] : (G₁ \ G₂).edgeFinset = G₁.edgeFinset \ G₂.edgeFinset := by simp [edgeFinset] #align simple_graph.edge_finset_sdiff SimpleGraph.edgeFinset_sdiff theorem edgeFinset_card : G.edgeFinset.card = Fintype.card G.edgeSet := Set.toFinset_card _ #align simple_graph.edge_finset_card SimpleGraph.edgeFinset_card @[simp] theorem edgeSet_univ_card : (univ : Finset G.edgeSet).card = G.edgeFinset.card := Fintype.card_of_subtype G.edgeFinset fun _ => mem_edgeFinset #align simple_graph.edge_set_univ_card SimpleGraph.edgeSet_univ_card variable [Fintype V] @[simp] theorem edgeFinset_top [DecidableEq V] : (⊤ : SimpleGraph V).edgeFinset = univ.filter fun e => ¬e.IsDiag := by rw [← coe_inj]; simp /-- The complete graph on `n` vertices has `n.choose 2` edges. -/ theorem card_edgeFinset_top_eq_card_choose_two [DecidableEq V] : (⊤ : SimpleGraph V).edgeFinset.card = (Fintype.card V).choose 2 := by simp_rw [Set.toFinset_card, edgeSet_top, Set.coe_setOf, ← Sym2.card_subtype_not_diag] /-- Any graph on `n` vertices has at most `n.choose 2` edges. -/ theorem card_edgeFinset_le_card_choose_two : G.edgeFinset.card ≤ (Fintype.card V).choose 2 := by classical rw [← card_edgeFinset_top_eq_card_choose_two] exact card_le_card (edgeFinset_mono le_top) end EdgeFinset theorem edgeFinset_deleteEdges [DecidableEq V] [Fintype G.edgeSet] (s : Finset (Sym2 V)) [Fintype (G.deleteEdges s).edgeSet] : (G.deleteEdges s).edgeFinset = G.edgeFinset \ s := by ext e simp [edgeSet_deleteEdges] #align simple_graph.edge_finset_delete_edges SimpleGraph.edgeFinset_deleteEdges section DeleteFar -- Porting note: added `Fintype (Sym2 V)` argument. variable {𝕜 : Type*} [OrderedRing 𝕜] [Fintype V] [Fintype (Sym2 V)] [Fintype G.edgeSet] {p : SimpleGraph V → Prop} {r r₁ r₂ : 𝕜} /-- A graph is `r`-*delete-far* from a property `p` if we must delete at least `r` edges from it to get a graph with the property `p`. -/ def DeleteFar (p : SimpleGraph V → Prop) (r : 𝕜) : Prop := ∀ ⦃s⦄, s ⊆ G.edgeFinset → p (G.deleteEdges s) → r ≤ s.card #align simple_graph.delete_far SimpleGraph.DeleteFar variable {G} theorem deleteFar_iff : G.DeleteFar p r ↔ ∀ ⦃H : SimpleGraph _⦄ [DecidableRel H.Adj], H ≤ G → p H → r ≤ G.edgeFinset.card - H.edgeFinset.card := by classical refine ⟨fun h H _ hHG hH ↦ ?_, fun h s hs hG ↦ ?_⟩ · have := h (sdiff_subset (t := H.edgeFinset)) simp only [deleteEdges_sdiff_eq_of_le hHG, edgeFinset_mono hHG, card_sdiff, card_le_card, coe_sdiff, coe_edgeFinset, Nat.cast_sub] at this exact this hH · classical simpa [card_sdiff hs, edgeFinset_deleteEdges, -Set.toFinset_card, Nat.cast_sub, card_le_card hs] using h (G.deleteEdges_le s) hG #align simple_graph.delete_far_iff SimpleGraph.deleteFar_iff alias ⟨DeleteFar.le_card_sub_card, _⟩ := deleteFar_iff #align simple_graph.delete_far.le_card_sub_card SimpleGraph.DeleteFar.le_card_sub_card theorem DeleteFar.mono (h : G.DeleteFar p r₂) (hr : r₁ ≤ r₂) : G.DeleteFar p r₁ := fun _ hs hG => hr.trans <| h hs hG #align simple_graph.delete_far.mono SimpleGraph.DeleteFar.mono end DeleteFar section FiniteAt /-! ## Finiteness at a vertex This section contains definitions and lemmas concerning vertices that have finitely many adjacent vertices. We denote this condition by `Fintype (G.neighborSet v)`. We define `G.neighborFinset v` to be the `Finset` version of `G.neighborSet v`. Use `neighborFinset_eq_filter` to rewrite this definition as a `Finset.filter` expression. -/ variable (v) [Fintype (G.neighborSet v)] /-- `G.neighbors v` is the `Finset` version of `G.Adj v` in case `G` is locally finite at `v`. -/ def neighborFinset : Finset V := (G.neighborSet v).toFinset #align simple_graph.neighbor_finset SimpleGraph.neighborFinset theorem neighborFinset_def : G.neighborFinset v = (G.neighborSet v).toFinset := rfl #align simple_graph.neighbor_finset_def SimpleGraph.neighborFinset_def @[simp] theorem mem_neighborFinset (w : V) : w ∈ G.neighborFinset v ↔ G.Adj v w := Set.mem_toFinset #align simple_graph.mem_neighbor_finset SimpleGraph.mem_neighborFinset theorem not_mem_neighborFinset_self : v ∉ G.neighborFinset v := by simp #align simple_graph.not_mem_neighbor_finset_self SimpleGraph.not_mem_neighborFinset_self theorem neighborFinset_disjoint_singleton : Disjoint (G.neighborFinset v) {v} := Finset.disjoint_singleton_right.mpr <| not_mem_neighborFinset_self _ _ #align simple_graph.neighbor_finset_disjoint_singleton SimpleGraph.neighborFinset_disjoint_singleton theorem singleton_disjoint_neighborFinset : Disjoint {v} (G.neighborFinset v) := Finset.disjoint_singleton_left.mpr <| not_mem_neighborFinset_self _ _ #align simple_graph.singleton_disjoint_neighbor_finset SimpleGraph.singleton_disjoint_neighborFinset /-- `G.degree v` is the number of vertices adjacent to `v`. -/ def degree : ℕ := (G.neighborFinset v).card #align simple_graph.degree SimpleGraph.degree -- Porting note: in Lean 3 we could do `simp [← degree]`, but that gives -- "invalid '←' modifier, 'SimpleGraph.degree' is a declaration name to be unfolded". -- In any case, having this lemma is good since there's no guarantee we won't still change -- the definition of `degree`. @[simp] theorem card_neighborFinset_eq_degree : (G.neighborFinset v).card = G.degree v := rfl @[simp] theorem card_neighborSet_eq_degree : Fintype.card (G.neighborSet v) = G.degree v := (Set.toFinset_card _).symm #align simple_graph.card_neighbor_set_eq_degree SimpleGraph.card_neighborSet_eq_degree theorem degree_pos_iff_exists_adj : 0 < G.degree v ↔ ∃ w, G.Adj v w := by simp only [degree, card_pos, Finset.Nonempty, mem_neighborFinset] #align simple_graph.degree_pos_iff_exists_adj SimpleGraph.degree_pos_iff_exists_adj theorem degree_compl [Fintype (Gᶜ.neighborSet v)] [Fintype V] : Gᶜ.degree v = Fintype.card V - 1 - G.degree v := by classical rw [← card_neighborSet_union_compl_neighborSet G v, Set.toFinset_union] simp [card_union_of_disjoint (Set.disjoint_toFinset.mpr (compl_neighborSet_disjoint G v))] #align simple_graph.degree_compl SimpleGraph.degree_compl instance incidenceSetFintype [DecidableEq V] : Fintype (G.incidenceSet v) := Fintype.ofEquiv (G.neighborSet v) (G.incidenceSetEquivNeighborSet v).symm #align simple_graph.incidence_set_fintype SimpleGraph.incidenceSetFintype /-- This is the `Finset` version of `incidenceSet`. -/ def incidenceFinset [DecidableEq V] : Finset (Sym2 V) := (G.incidenceSet v).toFinset #align simple_graph.incidence_finset SimpleGraph.incidenceFinset @[simp] theorem card_incidenceSet_eq_degree [DecidableEq V] : Fintype.card (G.incidenceSet v) = G.degree v := by rw [Fintype.card_congr (G.incidenceSetEquivNeighborSet v)] simp #align simple_graph.card_incidence_set_eq_degree SimpleGraph.card_incidenceSet_eq_degree @[simp] theorem card_incidenceFinset_eq_degree [DecidableEq V] : (G.incidenceFinset v).card = G.degree v := by rw [← G.card_incidenceSet_eq_degree] apply Set.toFinset_card #align simple_graph.card_incidence_finset_eq_degree SimpleGraph.card_incidenceFinset_eq_degree @[simp] theorem mem_incidenceFinset [DecidableEq V] (e : Sym2 V) : e ∈ G.incidenceFinset v ↔ e ∈ G.incidenceSet v := Set.mem_toFinset #align simple_graph.mem_incidence_finset SimpleGraph.mem_incidenceFinset theorem incidenceFinset_eq_filter [DecidableEq V] [Fintype G.edgeSet] : G.incidenceFinset v = G.edgeFinset.filter (Membership.mem v) := by ext e refine Sym2.ind (fun x y => ?_) e simp [mk'_mem_incidenceSet_iff] #align simple_graph.incidence_finset_eq_filter SimpleGraph.incidenceFinset_eq_filter end FiniteAt section LocallyFinite /-- A graph is locally finite if every vertex has a finite neighbor set. -/ abbrev LocallyFinite := ∀ v : V, Fintype (G.neighborSet v) #align simple_graph.locally_finite SimpleGraph.LocallyFinite variable [LocallyFinite G] /-- A locally finite simple graph is regular of degree `d` if every vertex has degree `d`. -/ def IsRegularOfDegree (d : ℕ) : Prop := ∀ v : V, G.degree v = d #align simple_graph.is_regular_of_degree SimpleGraph.IsRegularOfDegree variable {G} theorem IsRegularOfDegree.degree_eq {d : ℕ} (h : G.IsRegularOfDegree d) (v : V) : G.degree v = d := h v #align simple_graph.is_regular_of_degree.degree_eq SimpleGraph.IsRegularOfDegree.degree_eq theorem IsRegularOfDegree.compl [Fintype V] [DecidableEq V] {G : SimpleGraph V} [DecidableRel G.Adj] {k : ℕ} (h : G.IsRegularOfDegree k) : Gᶜ.IsRegularOfDegree (Fintype.card V - 1 - k) := by intro v rw [degree_compl, h v] #align simple_graph.is_regular_of_degree.compl SimpleGraph.IsRegularOfDegree.compl end LocallyFinite section Finite variable [Fintype V] instance neighborSetFintype [DecidableRel G.Adj] (v : V) : Fintype (G.neighborSet v) := @Subtype.fintype _ _ (by simp_rw [mem_neighborSet] infer_instance) _ #align simple_graph.neighbor_set_fintype SimpleGraph.neighborSetFintype
Mathlib/Combinatorics/SimpleGraph/Finite.lean
328
331
theorem neighborFinset_eq_filter {v : V} [DecidableRel G.Adj] : G.neighborFinset v = Finset.univ.filter (G.Adj v) := by
ext simp
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad, Minchao Wu, Mario Carneiro -/ import Mathlib.Data.Finset.Attr import Mathlib.Data.Multiset.FinsetOps import Mathlib.Logic.Equiv.Set import Mathlib.Order.Directed import Mathlib.Order.Interval.Set.Basic #align_import data.finset.basic from "leanprover-community/mathlib"@"442a83d738cb208d3600056c489be16900ba701d" /-! # Finite sets Terms of type `Finset α` are one way of talking about finite subsets of `α` in mathlib. Below, `Finset α` is defined as a structure with 2 fields: 1. `val` is a `Multiset α` of elements; 2. `nodup` is a proof that `val` has no duplicates. Finsets in Lean are constructive in that they have an underlying `List` that enumerates their elements. In particular, any function that uses the data of the underlying list cannot depend on its ordering. This is handled on the `Multiset` level by multiset API, so in most cases one needn't worry about it explicitly. Finsets give a basic foundation for defining finite sums and products over types: 1. `∑ i ∈ (s : Finset α), f i`; 2. `∏ i ∈ (s : Finset α), f i`. Lean refers to these operations as big operators. More information can be found in `Mathlib.Algebra.BigOperators.Group.Finset`. Finsets are directly used to define fintypes in Lean. A `Fintype α` instance for a type `α` consists of a universal `Finset α` containing every term of `α`, called `univ`. See `Mathlib.Data.Fintype.Basic`. There is also `univ'`, the noncomputable partner to `univ`, which is defined to be `α` as a finset if `α` is finite, and the empty finset otherwise. See `Mathlib.Data.Fintype.Basic`. `Finset.card`, the size of a finset is defined in `Mathlib.Data.Finset.Card`. This is then used to define `Fintype.card`, the size of a type. ## Main declarations ### Main definitions * `Finset`: Defines a type for the finite subsets of `α`. Constructing a `Finset` requires two pieces of data: `val`, a `Multiset α` of elements, and `nodup`, a proof that `val` has no duplicates. * `Finset.instMembershipFinset`: Defines membership `a ∈ (s : Finset α)`. * `Finset.instCoeTCFinsetSet`: Provides a coercion `s : Finset α` to `s : Set α`. * `Finset.instCoeSortFinsetType`: Coerce `s : Finset α` to the type of all `x ∈ s`. * `Finset.induction_on`: Induction on finsets. To prove a proposition about an arbitrary `Finset α`, it suffices to prove it for the empty finset, and to show that if it holds for some `Finset α`, then it holds for the finset obtained by inserting a new element. * `Finset.choose`: Given a proof `h` of existence and uniqueness of a certain element satisfying a predicate, `choose s h` returns the element of `s` satisfying that predicate. ### Finset constructions * `Finset.instSingletonFinset`: Denoted by `{a}`; the finset consisting of one element. * `Finset.empty`: Denoted by `∅`. The finset associated to any type consisting of no elements. * `Finset.range`: For any `n : ℕ`, `range n` is equal to `{0, 1, ... , n - 1} ⊆ ℕ`. This convention is consistent with other languages and normalizes `card (range n) = n`. Beware, `n` is not in `range n`. * `Finset.attach`: Given `s : Finset α`, `attach s` forms a finset of elements of the subtype `{a // a ∈ s}`; in other words, it attaches elements to a proof of membership in the set. ### Finsets from functions * `Finset.filter`: Given a decidable predicate `p : α → Prop`, `s.filter p` is the finset consisting of those elements in `s` satisfying the predicate `p`. ### The lattice structure on subsets of finsets There is a natural lattice structure on the subsets of a set. In Lean, we use lattice notation to talk about things involving unions and intersections. See `Mathlib.Order.Lattice`. For the lattice structure on finsets, `⊥` is called `bot` with `⊥ = ∅` and `⊤` is called `top` with `⊤ = univ`. * `Finset.instHasSubsetFinset`: Lots of API about lattices, otherwise behaves as one would expect. * `Finset.instUnionFinset`: Defines `s ∪ t` (or `s ⊔ t`) as the union of `s` and `t`. See `Finset.sup`/`Finset.biUnion` for finite unions. * `Finset.instInterFinset`: Defines `s ∩ t` (or `s ⊓ t`) as the intersection of `s` and `t`. See `Finset.inf` for finite intersections. ### Operations on two or more finsets * `insert` and `Finset.cons`: For any `a : α`, `insert s a` returns `s ∪ {a}`. `cons s a h` returns the same except that it requires a hypothesis stating that `a` is not already in `s`. This does not require decidable equality on the type `α`. * `Finset.instUnionFinset`: see "The lattice structure on subsets of finsets" * `Finset.instInterFinset`: see "The lattice structure on subsets of finsets" * `Finset.erase`: For any `a : α`, `erase s a` returns `s` with the element `a` removed. * `Finset.instSDiffFinset`: Defines the set difference `s \ t` for finsets `s` and `t`. * `Finset.product`: Given finsets of `α` and `β`, defines finsets of `α × β`. For arbitrary dependent products, see `Mathlib.Data.Finset.Pi`. ### Predicates on finsets * `Disjoint`: defined via the lattice structure on finsets; two sets are disjoint if their intersection is empty. * `Finset.Nonempty`: A finset is nonempty if it has elements. This is equivalent to saying `s ≠ ∅`. ### Equivalences between finsets * The `Mathlib.Data.Equiv` files describe a general type of equivalence, so look in there for any lemmas. There is some API for rewriting sums and products from `s` to `t` given that `s ≃ t`. TODO: examples ## Tags finite sets, finset -/ -- Assert that we define `Finset` without the material on `List.sublists`. -- Note that we cannot use `List.sublists` itself as that is defined very early. assert_not_exists List.sublistsLen assert_not_exists Multiset.Powerset assert_not_exists CompleteLattice open Multiset Subtype Nat Function universe u variable {α : Type*} {β : Type*} {γ : Type*} /-- `Finset α` is the type of finite sets of elements of `α`. It is implemented as a multiset (a list up to permutation) which has no duplicate elements. -/ structure Finset (α : Type*) where /-- The underlying multiset -/ val : Multiset α /-- `val` contains no duplicates -/ nodup : Nodup val #align finset Finset instance Multiset.canLiftFinset {α} : CanLift (Multiset α) (Finset α) Finset.val Multiset.Nodup := ⟨fun m hm => ⟨⟨m, hm⟩, rfl⟩⟩ #align multiset.can_lift_finset Multiset.canLiftFinset namespace Finset theorem eq_of_veq : ∀ {s t : Finset α}, s.1 = t.1 → s = t | ⟨s, _⟩, ⟨t, _⟩, h => by cases h; rfl #align finset.eq_of_veq Finset.eq_of_veq theorem val_injective : Injective (val : Finset α → Multiset α) := fun _ _ => eq_of_veq #align finset.val_injective Finset.val_injective @[simp] theorem val_inj {s t : Finset α} : s.1 = t.1 ↔ s = t := val_injective.eq_iff #align finset.val_inj Finset.val_inj @[simp] theorem dedup_eq_self [DecidableEq α] (s : Finset α) : dedup s.1 = s.1 := s.2.dedup #align finset.dedup_eq_self Finset.dedup_eq_self instance decidableEq [DecidableEq α] : DecidableEq (Finset α) | _, _ => decidable_of_iff _ val_inj #align finset.has_decidable_eq Finset.decidableEq /-! ### membership -/ instance : Membership α (Finset α) := ⟨fun a s => a ∈ s.1⟩ theorem mem_def {a : α} {s : Finset α} : a ∈ s ↔ a ∈ s.1 := Iff.rfl #align finset.mem_def Finset.mem_def @[simp] theorem mem_val {a : α} {s : Finset α} : a ∈ s.1 ↔ a ∈ s := Iff.rfl #align finset.mem_val Finset.mem_val @[simp] theorem mem_mk {a : α} {s nd} : a ∈ @Finset.mk α s nd ↔ a ∈ s := Iff.rfl #align finset.mem_mk Finset.mem_mk instance decidableMem [_h : DecidableEq α] (a : α) (s : Finset α) : Decidable (a ∈ s) := Multiset.decidableMem _ _ #align finset.decidable_mem Finset.decidableMem @[simp] lemma forall_mem_not_eq {s : Finset α} {a : α} : (∀ b ∈ s, ¬ a = b) ↔ a ∉ s := by aesop @[simp] lemma forall_mem_not_eq' {s : Finset α} {a : α} : (∀ b ∈ s, ¬ b = a) ↔ a ∉ s := by aesop /-! ### set coercion -/ -- Porting note (#11445): new definition /-- Convert a finset to a set in the natural way. -/ @[coe] def toSet (s : Finset α) : Set α := { a | a ∈ s } /-- Convert a finset to a set in the natural way. -/ instance : CoeTC (Finset α) (Set α) := ⟨toSet⟩ @[simp, norm_cast] theorem mem_coe {a : α} {s : Finset α} : a ∈ (s : Set α) ↔ a ∈ (s : Finset α) := Iff.rfl #align finset.mem_coe Finset.mem_coe @[simp] theorem setOf_mem {α} {s : Finset α} : { a | a ∈ s } = s := rfl #align finset.set_of_mem Finset.setOf_mem @[simp] theorem coe_mem {s : Finset α} (x : (s : Set α)) : ↑x ∈ s := x.2 #align finset.coe_mem Finset.coe_mem -- Porting note (#10618): @[simp] can prove this theorem mk_coe {s : Finset α} (x : (s : Set α)) {h} : (⟨x, h⟩ : (s : Set α)) = x := Subtype.coe_eta _ _ #align finset.mk_coe Finset.mk_coe instance decidableMem' [DecidableEq α] (a : α) (s : Finset α) : Decidable (a ∈ (s : Set α)) := s.decidableMem _ #align finset.decidable_mem' Finset.decidableMem' /-! ### extensionality -/ theorem ext_iff {s₁ s₂ : Finset α} : s₁ = s₂ ↔ ∀ a, a ∈ s₁ ↔ a ∈ s₂ := val_inj.symm.trans <| s₁.nodup.ext s₂.nodup #align finset.ext_iff Finset.ext_iff @[ext] theorem ext {s₁ s₂ : Finset α} : (∀ a, a ∈ s₁ ↔ a ∈ s₂) → s₁ = s₂ := ext_iff.2 #align finset.ext Finset.ext @[simp, norm_cast] theorem coe_inj {s₁ s₂ : Finset α} : (s₁ : Set α) = s₂ ↔ s₁ = s₂ := Set.ext_iff.trans ext_iff.symm #align finset.coe_inj Finset.coe_inj theorem coe_injective {α} : Injective ((↑) : Finset α → Set α) := fun _s _t => coe_inj.1 #align finset.coe_injective Finset.coe_injective /-! ### type coercion -/ /-- Coercion from a finset to the corresponding subtype. -/ instance {α : Type u} : CoeSort (Finset α) (Type u) := ⟨fun s => { x // x ∈ s }⟩ -- Porting note (#10618): @[simp] can prove this protected theorem forall_coe {α : Type*} (s : Finset α) (p : s → Prop) : (∀ x : s, p x) ↔ ∀ (x : α) (h : x ∈ s), p ⟨x, h⟩ := Subtype.forall #align finset.forall_coe Finset.forall_coe -- Porting note (#10618): @[simp] can prove this protected theorem exists_coe {α : Type*} (s : Finset α) (p : s → Prop) : (∃ x : s, p x) ↔ ∃ (x : α) (h : x ∈ s), p ⟨x, h⟩ := Subtype.exists #align finset.exists_coe Finset.exists_coe instance PiFinsetCoe.canLift (ι : Type*) (α : ι → Type*) [_ne : ∀ i, Nonempty (α i)] (s : Finset ι) : CanLift (∀ i : s, α i) (∀ i, α i) (fun f i => f i) fun _ => True := PiSubtype.canLift ι α (· ∈ s) #align finset.pi_finset_coe.can_lift Finset.PiFinsetCoe.canLift instance PiFinsetCoe.canLift' (ι α : Type*) [_ne : Nonempty α] (s : Finset ι) : CanLift (s → α) (ι → α) (fun f i => f i) fun _ => True := PiFinsetCoe.canLift ι (fun _ => α) s #align finset.pi_finset_coe.can_lift' Finset.PiFinsetCoe.canLift' instance FinsetCoe.canLift (s : Finset α) : CanLift α s (↑) fun a => a ∈ s where prf a ha := ⟨⟨a, ha⟩, rfl⟩ #align finset.finset_coe.can_lift Finset.FinsetCoe.canLift @[simp, norm_cast] theorem coe_sort_coe (s : Finset α) : ((s : Set α) : Sort _) = s := rfl #align finset.coe_sort_coe Finset.coe_sort_coe /-! ### Subset and strict subset relations -/ section Subset variable {s t : Finset α} instance : HasSubset (Finset α) := ⟨fun s t => ∀ ⦃a⦄, a ∈ s → a ∈ t⟩ instance : HasSSubset (Finset α) := ⟨fun s t => s ⊆ t ∧ ¬t ⊆ s⟩ instance partialOrder : PartialOrder (Finset α) where le := (· ⊆ ·) lt := (· ⊂ ·) le_refl s a := id le_trans s t u hst htu a ha := htu <| hst ha le_antisymm s t hst hts := ext fun a => ⟨@hst _, @hts _⟩ instance : IsRefl (Finset α) (· ⊆ ·) := show IsRefl (Finset α) (· ≤ ·) by infer_instance instance : IsTrans (Finset α) (· ⊆ ·) := show IsTrans (Finset α) (· ≤ ·) by infer_instance instance : IsAntisymm (Finset α) (· ⊆ ·) := show IsAntisymm (Finset α) (· ≤ ·) by infer_instance instance : IsIrrefl (Finset α) (· ⊂ ·) := show IsIrrefl (Finset α) (· < ·) by infer_instance instance : IsTrans (Finset α) (· ⊂ ·) := show IsTrans (Finset α) (· < ·) by infer_instance instance : IsAsymm (Finset α) (· ⊂ ·) := show IsAsymm (Finset α) (· < ·) by infer_instance instance : IsNonstrictStrictOrder (Finset α) (· ⊆ ·) (· ⊂ ·) := ⟨fun _ _ => Iff.rfl⟩ theorem subset_def : s ⊆ t ↔ s.1 ⊆ t.1 := Iff.rfl #align finset.subset_def Finset.subset_def theorem ssubset_def : s ⊂ t ↔ s ⊆ t ∧ ¬t ⊆ s := Iff.rfl #align finset.ssubset_def Finset.ssubset_def @[simp] theorem Subset.refl (s : Finset α) : s ⊆ s := Multiset.Subset.refl _ #align finset.subset.refl Finset.Subset.refl protected theorem Subset.rfl {s : Finset α} : s ⊆ s := Subset.refl _ #align finset.subset.rfl Finset.Subset.rfl protected theorem subset_of_eq {s t : Finset α} (h : s = t) : s ⊆ t := h ▸ Subset.refl _ #align finset.subset_of_eq Finset.subset_of_eq theorem Subset.trans {s₁ s₂ s₃ : Finset α} : s₁ ⊆ s₂ → s₂ ⊆ s₃ → s₁ ⊆ s₃ := Multiset.Subset.trans #align finset.subset.trans Finset.Subset.trans theorem Superset.trans {s₁ s₂ s₃ : Finset α} : s₁ ⊇ s₂ → s₂ ⊇ s₃ → s₁ ⊇ s₃ := fun h' h => Subset.trans h h' #align finset.superset.trans Finset.Superset.trans theorem mem_of_subset {s₁ s₂ : Finset α} {a : α} : s₁ ⊆ s₂ → a ∈ s₁ → a ∈ s₂ := Multiset.mem_of_subset #align finset.mem_of_subset Finset.mem_of_subset theorem not_mem_mono {s t : Finset α} (h : s ⊆ t) {a : α} : a ∉ t → a ∉ s := mt <| @h _ #align finset.not_mem_mono Finset.not_mem_mono theorem Subset.antisymm {s₁ s₂ : Finset α} (H₁ : s₁ ⊆ s₂) (H₂ : s₂ ⊆ s₁) : s₁ = s₂ := ext fun a => ⟨@H₁ a, @H₂ a⟩ #align finset.subset.antisymm Finset.Subset.antisymm theorem subset_iff {s₁ s₂ : Finset α} : s₁ ⊆ s₂ ↔ ∀ ⦃x⦄, x ∈ s₁ → x ∈ s₂ := Iff.rfl #align finset.subset_iff Finset.subset_iff @[simp, norm_cast] theorem coe_subset {s₁ s₂ : Finset α} : (s₁ : Set α) ⊆ s₂ ↔ s₁ ⊆ s₂ := Iff.rfl #align finset.coe_subset Finset.coe_subset @[simp] theorem val_le_iff {s₁ s₂ : Finset α} : s₁.1 ≤ s₂.1 ↔ s₁ ⊆ s₂ := le_iff_subset s₁.2 #align finset.val_le_iff Finset.val_le_iff theorem Subset.antisymm_iff {s₁ s₂ : Finset α} : s₁ = s₂ ↔ s₁ ⊆ s₂ ∧ s₂ ⊆ s₁ := le_antisymm_iff #align finset.subset.antisymm_iff Finset.Subset.antisymm_iff
Mathlib/Data/Finset/Basic.lean
389
389
theorem not_subset : ¬s ⊆ t ↔ ∃ x ∈ s, x ∉ t := by
simp only [← coe_subset, Set.not_subset, mem_coe]
/- Copyright (c) 2022 Violeta Hernández Palacios. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Violeta Hernández Palacios -/ import Mathlib.Order.SuccPred.Basic import Mathlib.Order.BoundedOrder #align_import order.succ_pred.limit from "leanprover-community/mathlib"@"1e05171a5e8cf18d98d9cf7b207540acb044acae" /-! # Successor and predecessor limits We define the predicate `Order.IsSuccLimit` for "successor limits", values that don't cover any others. They are so named since they can't be the successors of anything smaller. We define `Order.IsPredLimit` analogously, and prove basic results. ## Todo The plan is to eventually replace `Ordinal.IsLimit` and `Cardinal.IsLimit` with the common predicate `Order.IsSuccLimit`. -/ variable {α : Type*} namespace Order open Function Set OrderDual /-! ### Successor limits -/ section LT variable [LT α] /-- A successor limit is a value that doesn't cover any other. It's so named because in a successor order, a successor limit can't be the successor of anything smaller. -/ def IsSuccLimit (a : α) : Prop := ∀ b, ¬b ⋖ a #align order.is_succ_limit Order.IsSuccLimit theorem not_isSuccLimit_iff_exists_covBy (a : α) : ¬IsSuccLimit a ↔ ∃ b, b ⋖ a := by simp [IsSuccLimit] #align order.not_is_succ_limit_iff_exists_covby Order.not_isSuccLimit_iff_exists_covBy @[simp] theorem isSuccLimit_of_dense [DenselyOrdered α] (a : α) : IsSuccLimit a := fun _ => not_covBy #align order.is_succ_limit_of_dense Order.isSuccLimit_of_dense end LT section Preorder variable [Preorder α] {a : α} protected theorem _root_.IsMin.isSuccLimit : IsMin a → IsSuccLimit a := fun h _ hab => not_isMin_of_lt hab.lt h #align is_min.is_succ_limit IsMin.isSuccLimit theorem isSuccLimit_bot [OrderBot α] : IsSuccLimit (⊥ : α) := IsMin.isSuccLimit isMin_bot #align order.is_succ_limit_bot Order.isSuccLimit_bot variable [SuccOrder α] protected theorem IsSuccLimit.isMax (h : IsSuccLimit (succ a)) : IsMax a := by by_contra H exact h a (covBy_succ_of_not_isMax H) #align order.is_succ_limit.is_max Order.IsSuccLimit.isMax theorem not_isSuccLimit_succ_of_not_isMax (ha : ¬IsMax a) : ¬IsSuccLimit (succ a) := by contrapose! ha exact ha.isMax #align order.not_is_succ_limit_succ_of_not_is_max Order.not_isSuccLimit_succ_of_not_isMax section NoMaxOrder variable [NoMaxOrder α] theorem IsSuccLimit.succ_ne (h : IsSuccLimit a) (b : α) : succ b ≠ a := by rintro rfl exact not_isMax _ h.isMax #align order.is_succ_limit.succ_ne Order.IsSuccLimit.succ_ne @[simp] theorem not_isSuccLimit_succ (a : α) : ¬IsSuccLimit (succ a) := fun h => h.succ_ne _ rfl #align order.not_is_succ_limit_succ Order.not_isSuccLimit_succ end NoMaxOrder section IsSuccArchimedean variable [IsSuccArchimedean α] theorem IsSuccLimit.isMin_of_noMax [NoMaxOrder α] (h : IsSuccLimit a) : IsMin a := fun b hb => by rcases hb.exists_succ_iterate with ⟨_ | n, rfl⟩ · exact le_rfl · rw [iterate_succ_apply'] at h exact (not_isSuccLimit_succ _ h).elim #align order.is_succ_limit.is_min_of_no_max Order.IsSuccLimit.isMin_of_noMax @[simp] theorem isSuccLimit_iff_of_noMax [NoMaxOrder α] : IsSuccLimit a ↔ IsMin a := ⟨IsSuccLimit.isMin_of_noMax, IsMin.isSuccLimit⟩ #align order.is_succ_limit_iff_of_no_max Order.isSuccLimit_iff_of_noMax theorem not_isSuccLimit_of_noMax [NoMinOrder α] [NoMaxOrder α] : ¬IsSuccLimit a := by simp #align order.not_is_succ_limit_of_no_max Order.not_isSuccLimit_of_noMax end IsSuccArchimedean end Preorder section PartialOrder variable [PartialOrder α] [SuccOrder α] {a b : α} {C : α → Sort*} theorem isSuccLimit_of_succ_ne (h : ∀ b, succ b ≠ a) : IsSuccLimit a := fun b hba => h b (CovBy.succ_eq hba) #align order.is_succ_limit_of_succ_ne Order.isSuccLimit_of_succ_ne theorem not_isSuccLimit_iff : ¬IsSuccLimit a ↔ ∃ b, ¬IsMax b ∧ succ b = a := by rw [not_isSuccLimit_iff_exists_covBy] refine exists_congr fun b => ⟨fun hba => ⟨hba.lt.not_isMax, (CovBy.succ_eq hba)⟩, ?_⟩ rintro ⟨h, rfl⟩ exact covBy_succ_of_not_isMax h #align order.not_is_succ_limit_iff Order.not_isSuccLimit_iff /-- See `not_isSuccLimit_iff` for a version that states that `a` is a successor of a value other than itself. -/ theorem mem_range_succ_of_not_isSuccLimit (h : ¬IsSuccLimit a) : a ∈ range (@succ α _ _) := by cases' not_isSuccLimit_iff.1 h with b hb exact ⟨b, hb.2⟩ #align order.mem_range_succ_of_not_is_succ_limit Order.mem_range_succ_of_not_isSuccLimit theorem isSuccLimit_of_succ_lt (H : ∀ a < b, succ a < b) : IsSuccLimit b := fun a hab => (H a hab.lt).ne (CovBy.succ_eq hab) #align order.is_succ_limit_of_succ_lt Order.isSuccLimit_of_succ_lt theorem IsSuccLimit.succ_lt (hb : IsSuccLimit b) (ha : a < b) : succ a < b := by by_cases h : IsMax a · rwa [h.succ_eq] · rw [lt_iff_le_and_ne, succ_le_iff_of_not_isMax h] refine ⟨ha, fun hab => ?_⟩ subst hab exact (h hb.isMax).elim #align order.is_succ_limit.succ_lt Order.IsSuccLimit.succ_lt theorem IsSuccLimit.succ_lt_iff (hb : IsSuccLimit b) : succ a < b ↔ a < b := ⟨fun h => (le_succ a).trans_lt h, hb.succ_lt⟩ #align order.is_succ_limit.succ_lt_iff Order.IsSuccLimit.succ_lt_iff theorem isSuccLimit_iff_succ_lt : IsSuccLimit b ↔ ∀ a < b, succ a < b := ⟨fun hb _ => hb.succ_lt, isSuccLimit_of_succ_lt⟩ #align order.is_succ_limit_iff_succ_lt Order.isSuccLimit_iff_succ_lt /-- A value can be built by building it on successors and successor limits. -/ @[elab_as_elim] noncomputable def isSuccLimitRecOn (b : α) (hs : ∀ a, ¬IsMax a → C (succ a)) (hl : ∀ a, IsSuccLimit a → C a) : C b := by by_cases hb : IsSuccLimit b · exact hl b hb · have H := Classical.choose_spec (not_isSuccLimit_iff.1 hb) rw [← H.2] exact hs _ H.1 #align order.is_succ_limit_rec_on Order.isSuccLimitRecOn theorem isSuccLimitRecOn_limit (hs : ∀ a, ¬IsMax a → C (succ a)) (hl : ∀ a, IsSuccLimit a → C a) (hb : IsSuccLimit b) : @isSuccLimitRecOn α _ _ C b hs hl = hl b hb := by classical exact dif_pos hb #align order.is_succ_limit_rec_on_limit Order.isSuccLimitRecOn_limit theorem isSuccLimitRecOn_succ' (hs : ∀ a, ¬IsMax a → C (succ a)) (hl : ∀ a, IsSuccLimit a → C a) {b : α} (hb : ¬IsMax b) : @isSuccLimitRecOn α _ _ C (succ b) hs hl = hs b hb := by have hb' := not_isSuccLimit_succ_of_not_isMax hb have H := Classical.choose_spec (not_isSuccLimit_iff.1 hb') rw [isSuccLimitRecOn] simp only [cast_eq_iff_heq, hb', not_false_iff, eq_mpr_eq_cast, dif_neg] congr 1 <;> first | exact (succ_eq_succ_iff_of_not_isMax H.left hb).mp H.right | exact proof_irrel_heq H.left hb #align order.is_succ_limit_rec_on_succ' Order.isSuccLimitRecOn_succ' section limitRecOn variable [WellFoundedLT α] (H_succ : ∀ a, ¬IsMax a → C a → C (succ a)) (H_lim : ∀ a, IsSuccLimit a → (∀ b < a, C b) → C a) open scoped Classical in variable (a) in /-- Recursion principle on a well-founded partial `SuccOrder`. -/ @[elab_as_elim] noncomputable def _root_.SuccOrder.limitRecOn : C a := wellFounded_lt.fix (fun a IH ↦ if h : IsSuccLimit a then H_lim a h IH else let x := Classical.indefiniteDescription _ (not_isSuccLimit_iff.mp h) x.2.2 ▸ H_succ x x.2.1 (IH x <| x.2.2.subst <| lt_succ_of_not_isMax x.2.1)) a @[simp] theorem _root_.SuccOrder.limitRecOn_succ (ha : ¬ IsMax a) : SuccOrder.limitRecOn (succ a) H_succ H_lim = H_succ a ha (SuccOrder.limitRecOn a H_succ H_lim) := by have h := not_isSuccLimit_succ_of_not_isMax ha rw [SuccOrder.limitRecOn, WellFounded.fix_eq, dif_neg h] have {b c hb hc} {x : ∀ a, C a} (h : b = c) : congr_arg succ h ▸ H_succ b hb (x b) = H_succ c hc (x c) := by subst h; rfl let x := Classical.indefiniteDescription _ (not_isSuccLimit_iff.mp h) exact this ((succ_eq_succ_iff_of_not_isMax x.2.1 ha).mp x.2.2) @[simp] theorem _root_.SuccOrder.limitRecOn_limit (ha : IsSuccLimit a) : SuccOrder.limitRecOn a H_succ H_lim = H_lim a ha fun x _ ↦ SuccOrder.limitRecOn x H_succ H_lim := by rw [SuccOrder.limitRecOn, WellFounded.fix_eq, dif_pos ha]; rfl end limitRecOn section NoMaxOrder variable [NoMaxOrder α] @[simp] theorem isSuccLimitRecOn_succ (hs : ∀ a, ¬IsMax a → C (succ a)) (hl : ∀ a, IsSuccLimit a → C a) (b : α) : @isSuccLimitRecOn α _ _ C (succ b) hs hl = hs b (not_isMax b) := isSuccLimitRecOn_succ' _ _ _ #align order.is_succ_limit_rec_on_succ Order.isSuccLimitRecOn_succ theorem isSuccLimit_iff_succ_ne : IsSuccLimit a ↔ ∀ b, succ b ≠ a := ⟨IsSuccLimit.succ_ne, isSuccLimit_of_succ_ne⟩ #align order.is_succ_limit_iff_succ_ne Order.isSuccLimit_iff_succ_ne theorem not_isSuccLimit_iff' : ¬IsSuccLimit a ↔ a ∈ range (@succ α _ _) := by simp_rw [isSuccLimit_iff_succ_ne, not_forall, not_ne_iff] rfl #align order.not_is_succ_limit_iff' Order.not_isSuccLimit_iff' end NoMaxOrder section IsSuccArchimedean variable [IsSuccArchimedean α] protected theorem IsSuccLimit.isMin (h : IsSuccLimit a) : IsMin a := fun b hb => by revert h refine Succ.rec (fun _ => le_rfl) (fun c _ H hc => ?_) hb have := hc.isMax.succ_eq rw [this] at hc ⊢ exact H hc #align order.is_succ_limit.is_min Order.IsSuccLimit.isMin @[simp] theorem isSuccLimit_iff : IsSuccLimit a ↔ IsMin a := ⟨IsSuccLimit.isMin, IsMin.isSuccLimit⟩ #align order.is_succ_limit_iff Order.isSuccLimit_iff theorem not_isSuccLimit [NoMinOrder α] : ¬IsSuccLimit a := by simp #align order.not_is_succ_limit Order.not_isSuccLimit end IsSuccArchimedean end PartialOrder /-! ### Predecessor limits -/ section LT variable [LT α] {a : α} /-- A predecessor limit is a value that isn't covered by any other. It's so named because in a predecessor order, a predecessor limit can't be the predecessor of anything greater. -/ def IsPredLimit (a : α) : Prop := ∀ b, ¬a ⋖ b #align order.is_pred_limit Order.IsPredLimit theorem not_isPredLimit_iff_exists_covBy (a : α) : ¬IsPredLimit a ↔ ∃ b, a ⋖ b := by simp [IsPredLimit] #align order.not_is_pred_limit_iff_exists_covby Order.not_isPredLimit_iff_exists_covBy theorem isPredLimit_of_dense [DenselyOrdered α] (a : α) : IsPredLimit a := fun _ => not_covBy #align order.is_pred_limit_of_dense Order.isPredLimit_of_dense @[simp] theorem isSuccLimit_toDual_iff : IsSuccLimit (toDual a) ↔ IsPredLimit a := by simp [IsSuccLimit, IsPredLimit] #align order.is_succ_limit_to_dual_iff Order.isSuccLimit_toDual_iff @[simp] theorem isPredLimit_toDual_iff : IsPredLimit (toDual a) ↔ IsSuccLimit a := by simp [IsSuccLimit, IsPredLimit] #align order.is_pred_limit_to_dual_iff Order.isPredLimit_toDual_iff alias ⟨_, isPredLimit.dual⟩ := isSuccLimit_toDual_iff #align order.is_pred_limit.dual Order.isPredLimit.dual alias ⟨_, isSuccLimit.dual⟩ := isPredLimit_toDual_iff #align order.is_succ_limit.dual Order.isSuccLimit.dual end LT section Preorder variable [Preorder α] {a : α} protected theorem _root_.IsMax.isPredLimit : IsMax a → IsPredLimit a := fun h _ hab => not_isMax_of_lt hab.lt h #align is_max.is_pred_limit IsMax.isPredLimit theorem isPredLimit_top [OrderTop α] : IsPredLimit (⊤ : α) := IsMax.isPredLimit isMax_top #align order.is_pred_limit_top Order.isPredLimit_top variable [PredOrder α] protected theorem IsPredLimit.isMin (h : IsPredLimit (pred a)) : IsMin a := by by_contra H exact h a (pred_covBy_of_not_isMin H) #align order.is_pred_limit.is_min Order.IsPredLimit.isMin theorem not_isPredLimit_pred_of_not_isMin (ha : ¬IsMin a) : ¬IsPredLimit (pred a) := by contrapose! ha exact ha.isMin #align order.not_is_pred_limit_pred_of_not_is_min Order.not_isPredLimit_pred_of_not_isMin section NoMinOrder variable [NoMinOrder α] theorem IsPredLimit.pred_ne (h : IsPredLimit a) (b : α) : pred b ≠ a := by rintro rfl exact not_isMin _ h.isMin #align order.is_pred_limit.pred_ne Order.IsPredLimit.pred_ne @[simp] theorem not_isPredLimit_pred (a : α) : ¬IsPredLimit (pred a) := fun h => h.pred_ne _ rfl #align order.not_is_pred_limit_pred Order.not_isPredLimit_pred end NoMinOrder section IsPredArchimedean variable [IsPredArchimedean α] protected theorem IsPredLimit.isMax_of_noMin [NoMinOrder α] (h : IsPredLimit a) : IsMax a := (isPredLimit.dual h).isMin_of_noMax #align order.is_pred_limit.is_max_of_no_min Order.IsPredLimit.isMax_of_noMin @[simp] theorem isPredLimit_iff_of_noMin [NoMinOrder α] : IsPredLimit a ↔ IsMax a := isSuccLimit_toDual_iff.symm.trans isSuccLimit_iff_of_noMax #align order.is_pred_limit_iff_of_no_min Order.isPredLimit_iff_of_noMin theorem not_isPredLimit_of_noMin [NoMinOrder α] [NoMaxOrder α] : ¬IsPredLimit a := by simp #align order.not_is_pred_limit_of_no_min Order.not_isPredLimit_of_noMin end IsPredArchimedean end Preorder section PartialOrder variable [PartialOrder α] [PredOrder α] {a b : α} {C : α → Sort*} theorem isPredLimit_of_pred_ne (h : ∀ b, pred b ≠ a) : IsPredLimit a := fun b hba => h b (CovBy.pred_eq hba) #align order.is_pred_limit_of_pred_ne Order.isPredLimit_of_pred_ne
Mathlib/Order/SuccPred/Limit.lean
375
377
theorem not_isPredLimit_iff : ¬IsPredLimit a ↔ ∃ b, ¬IsMin b ∧ pred b = a := by
rw [← isSuccLimit_toDual_iff] exact not_isSuccLimit_iff
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Set.Lattice import Mathlib.Logic.Small.Basic import Mathlib.Logic.Function.OfArity import Mathlib.Order.WellFounded #align_import set_theory.zfc.basic from "leanprover-community/mathlib"@"f0b3759a8ef0bd8239ecdaa5e1089add5feebe1a" /-! # A model of ZFC In this file, we model Zermelo-Fraenkel set theory (+ Choice) using Lean's underlying type theory. We do this in four main steps: * Define pre-sets inductively. * Define extensional equivalence on pre-sets and give it a `setoid` instance. * Define ZFC sets by quotienting pre-sets by extensional equivalence. * Define classes as sets of ZFC sets. Then the rest is usual set theory. ## The model * `PSet`: Pre-set. A pre-set is inductively defined by its indexing type and its members, which are themselves pre-sets. * `ZFSet`: ZFC set. Defined as `PSet` quotiented by `PSet.Equiv`, the extensional equivalence. * `Class`: Class. Defined as `Set ZFSet`. * `ZFSet.choice`: Axiom of choice. Proved from Lean's axiom of choice. ## Other definitions * `PSet.Type`: Underlying type of a pre-set. * `PSet.Func`: Underlying family of pre-sets of a pre-set. * `PSet.Equiv`: Extensional equivalence of pre-sets. Defined inductively. * `PSet.omega`, `ZFSet.omega`: The von Neumann ordinal `ω` as a `PSet`, as a `Set`. * `PSet.Arity.Equiv`: Extensional equivalence of `n`-ary `PSet`-valued functions. Extension of `PSet.Equiv`. * `PSet.Resp`: Collection of `n`-ary `PSet`-valued functions that respect extensional equivalence. * `PSet.eval`: Turns a `PSet`-valued function that respect extensional equivalence into a `ZFSet`-valued function. * `Classical.allDefinable`: All functions are classically definable. * `ZFSet.IsFunc` : Predicate that a ZFC set is a subset of `x × y` that can be considered as a ZFC function `x → y`. That is, each member of `x` is related by the ZFC set to exactly one member of `y`. * `ZFSet.funs`: ZFC set of ZFC functions `x → y`. * `ZFSet.Hereditarily p x`: Predicate that every set in the transitive closure of `x` has property `p`. * `Class.iota`: Definite description operator. ## Notes To avoid confusion between the Lean `Set` and the ZFC `Set`, docstrings in this file refer to them respectively as "`Set`" and "ZFC set". ## TODO Prove `ZFSet.mapDefinableAux` computably. -/ -- Porting note: Lean 3 uses `Set` for `ZFSet`. set_option linter.uppercaseLean3 false universe u v open Function (OfArity) /-- The type of pre-sets in universe `u`. A pre-set is a family of pre-sets indexed by a type in `Type u`. The ZFC universe is defined as a quotient of this to ensure extensionality. -/ inductive PSet : Type (u + 1) | mk (α : Type u) (A : α → PSet) : PSet #align pSet PSet namespace PSet /-- The underlying type of a pre-set -/ def «Type» : PSet → Type u | ⟨α, _⟩ => α #align pSet.type PSet.Type /-- The underlying pre-set family of a pre-set -/ def Func : ∀ x : PSet, x.Type → PSet | ⟨_, A⟩ => A #align pSet.func PSet.Func @[simp] theorem mk_type (α A) : «Type» ⟨α, A⟩ = α := rfl #align pSet.mk_type PSet.mk_type @[simp] theorem mk_func (α A) : Func ⟨α, A⟩ = A := rfl #align pSet.mk_func PSet.mk_func @[simp] theorem eta : ∀ x : PSet, mk x.Type x.Func = x | ⟨_, _⟩ => rfl #align pSet.eta PSet.eta /-- Two pre-sets are extensionally equivalent if every element of the first family is extensionally equivalent to some element of the second family and vice-versa. -/ def Equiv : PSet → PSet → Prop | ⟨_, A⟩, ⟨_, B⟩ => (∀ a, ∃ b, Equiv (A a) (B b)) ∧ (∀ b, ∃ a, Equiv (A a) (B b)) #align pSet.equiv PSet.Equiv theorem equiv_iff : ∀ {x y : PSet}, Equiv x y ↔ (∀ i, ∃ j, Equiv (x.Func i) (y.Func j)) ∧ ∀ j, ∃ i, Equiv (x.Func i) (y.Func j) | ⟨_, _⟩, ⟨_, _⟩ => Iff.rfl #align pSet.equiv_iff PSet.equiv_iff theorem Equiv.exists_left {x y : PSet} (h : Equiv x y) : ∀ i, ∃ j, Equiv (x.Func i) (y.Func j) := (equiv_iff.1 h).1 #align pSet.equiv.exists_left PSet.Equiv.exists_left theorem Equiv.exists_right {x y : PSet} (h : Equiv x y) : ∀ j, ∃ i, Equiv (x.Func i) (y.Func j) := (equiv_iff.1 h).2 #align pSet.equiv.exists_right PSet.Equiv.exists_right @[refl] protected theorem Equiv.refl : ∀ x, Equiv x x | ⟨_, _⟩ => ⟨fun a => ⟨a, Equiv.refl _⟩, fun a => ⟨a, Equiv.refl _⟩⟩ #align pSet.equiv.refl PSet.Equiv.refl protected theorem Equiv.rfl {x} : Equiv x x := Equiv.refl x #align pSet.equiv.rfl PSet.Equiv.rfl protected theorem Equiv.euc : ∀ {x y z}, Equiv x y → Equiv z y → Equiv x z | ⟨_, _⟩, ⟨_, _⟩, ⟨_, _⟩, ⟨αβ, βα⟩, ⟨γβ, βγ⟩ => ⟨ fun a => let ⟨b, ab⟩ := αβ a let ⟨c, bc⟩ := βγ b ⟨c, Equiv.euc ab bc⟩, fun c => let ⟨b, cb⟩ := γβ c let ⟨a, ba⟩ := βα b ⟨a, Equiv.euc ba cb⟩ ⟩ #align pSet.equiv.euc PSet.Equiv.euc @[symm] protected theorem Equiv.symm {x y} : Equiv x y → Equiv y x := (Equiv.refl y).euc #align pSet.equiv.symm PSet.Equiv.symm protected theorem Equiv.comm {x y} : Equiv x y ↔ Equiv y x := ⟨Equiv.symm, Equiv.symm⟩ #align pSet.equiv.comm PSet.Equiv.comm @[trans] protected theorem Equiv.trans {x y z} (h1 : Equiv x y) (h2 : Equiv y z) : Equiv x z := h1.euc h2.symm #align pSet.equiv.trans PSet.Equiv.trans protected theorem equiv_of_isEmpty (x y : PSet) [IsEmpty x.Type] [IsEmpty y.Type] : Equiv x y := equiv_iff.2 <| by simp #align pSet.equiv_of_is_empty PSet.equiv_of_isEmpty instance setoid : Setoid PSet := ⟨PSet.Equiv, Equiv.refl, Equiv.symm, Equiv.trans⟩ #align pSet.setoid PSet.setoid /-- A pre-set is a subset of another pre-set if every element of the first family is extensionally equivalent to some element of the second family. -/ protected def Subset (x y : PSet) : Prop := ∀ a, ∃ b, Equiv (x.Func a) (y.Func b) #align pSet.subset PSet.Subset instance : HasSubset PSet := ⟨PSet.Subset⟩ instance : IsRefl PSet (· ⊆ ·) := ⟨fun _ a => ⟨a, Equiv.refl _⟩⟩ instance : IsTrans PSet (· ⊆ ·) := ⟨fun x y z hxy hyz a => by cases' hxy a with b hb cases' hyz b with c hc exact ⟨c, hb.trans hc⟩⟩ theorem Equiv.ext : ∀ x y : PSet, Equiv x y ↔ x ⊆ y ∧ y ⊆ x | ⟨_, _⟩, ⟨_, _⟩ => ⟨fun ⟨αβ, βα⟩ => ⟨αβ, fun b => let ⟨a, h⟩ := βα b ⟨a, Equiv.symm h⟩⟩, fun ⟨αβ, βα⟩ => ⟨αβ, fun b => let ⟨a, h⟩ := βα b ⟨a, Equiv.symm h⟩⟩⟩ #align pSet.equiv.ext PSet.Equiv.ext theorem Subset.congr_left : ∀ {x y z : PSet}, Equiv x y → (x ⊆ z ↔ y ⊆ z) | ⟨_, _⟩, ⟨_, _⟩, ⟨_, _⟩, ⟨αβ, βα⟩ => ⟨fun αγ b => let ⟨a, ba⟩ := βα b let ⟨c, ac⟩ := αγ a ⟨c, (Equiv.symm ba).trans ac⟩, fun βγ a => let ⟨b, ab⟩ := αβ a let ⟨c, bc⟩ := βγ b ⟨c, Equiv.trans ab bc⟩⟩ #align pSet.subset.congr_left PSet.Subset.congr_left theorem Subset.congr_right : ∀ {x y z : PSet}, Equiv x y → (z ⊆ x ↔ z ⊆ y) | ⟨_, _⟩, ⟨_, _⟩, ⟨_, _⟩, ⟨αβ, βα⟩ => ⟨fun γα c => let ⟨a, ca⟩ := γα c let ⟨b, ab⟩ := αβ a ⟨b, ca.trans ab⟩, fun γβ c => let ⟨b, cb⟩ := γβ c let ⟨a, ab⟩ := βα b ⟨a, cb.trans (Equiv.symm ab)⟩⟩ #align pSet.subset.congr_right PSet.Subset.congr_right /-- `x ∈ y` as pre-sets if `x` is extensionally equivalent to a member of the family `y`. -/ protected def Mem (x y : PSet.{u}) : Prop := ∃ b, Equiv x (y.Func b) #align pSet.mem PSet.Mem instance : Membership PSet PSet := ⟨PSet.Mem⟩ theorem Mem.mk {α : Type u} (A : α → PSet) (a : α) : A a ∈ mk α A := ⟨a, Equiv.refl (A a)⟩ #align pSet.mem.mk PSet.Mem.mk theorem func_mem (x : PSet) (i : x.Type) : x.Func i ∈ x := by cases x apply Mem.mk #align pSet.func_mem PSet.func_mem theorem Mem.ext : ∀ {x y : PSet.{u}}, (∀ w : PSet.{u}, w ∈ x ↔ w ∈ y) → Equiv x y | ⟨_, A⟩, ⟨_, B⟩, h => ⟨fun a => (h (A a)).1 (Mem.mk A a), fun b => let ⟨a, ha⟩ := (h (B b)).2 (Mem.mk B b) ⟨a, ha.symm⟩⟩ #align pSet.mem.ext PSet.Mem.ext theorem Mem.congr_right : ∀ {x y : PSet.{u}}, Equiv x y → ∀ {w : PSet.{u}}, w ∈ x ↔ w ∈ y | ⟨_, _⟩, ⟨_, _⟩, ⟨αβ, βα⟩, _ => ⟨fun ⟨a, ha⟩ => let ⟨b, hb⟩ := αβ a ⟨b, ha.trans hb⟩, fun ⟨b, hb⟩ => let ⟨a, ha⟩ := βα b ⟨a, hb.euc ha⟩⟩ #align pSet.mem.congr_right PSet.Mem.congr_right theorem equiv_iff_mem {x y : PSet.{u}} : Equiv x y ↔ ∀ {w : PSet.{u}}, w ∈ x ↔ w ∈ y := ⟨Mem.congr_right, match x, y with | ⟨_, A⟩, ⟨_, B⟩ => fun h => ⟨fun a => h.1 (Mem.mk A a), fun b => let ⟨a, h⟩ := h.2 (Mem.mk B b) ⟨a, h.symm⟩⟩⟩ #align pSet.equiv_iff_mem PSet.equiv_iff_mem theorem Mem.congr_left : ∀ {x y : PSet.{u}}, Equiv x y → ∀ {w : PSet.{u}}, x ∈ w ↔ y ∈ w | _, _, h, ⟨_, _⟩ => ⟨fun ⟨a, ha⟩ => ⟨a, h.symm.trans ha⟩, fun ⟨a, ha⟩ => ⟨a, h.trans ha⟩⟩ #align pSet.mem.congr_left PSet.Mem.congr_left private theorem mem_wf_aux : ∀ {x y : PSet.{u}}, Equiv x y → Acc (· ∈ ·) y | ⟨α, A⟩, ⟨β, B⟩, H => ⟨_, by rintro ⟨γ, C⟩ ⟨b, hc⟩ cases' H.exists_right b with a ha have H := ha.trans hc.symm rw [mk_func] at H exact mem_wf_aux H⟩ theorem mem_wf : @WellFounded PSet (· ∈ ·) := ⟨fun x => mem_wf_aux <| Equiv.refl x⟩ #align pSet.mem_wf PSet.mem_wf instance : WellFoundedRelation PSet := ⟨_, mem_wf⟩ instance : IsAsymm PSet (· ∈ ·) := mem_wf.isAsymm instance : IsIrrefl PSet (· ∈ ·) := mem_wf.isIrrefl theorem mem_asymm {x y : PSet} : x ∈ y → y ∉ x := asymm #align pSet.mem_asymm PSet.mem_asymm theorem mem_irrefl (x : PSet) : x ∉ x := irrefl x #align pSet.mem_irrefl PSet.mem_irrefl /-- Convert a pre-set to a `Set` of pre-sets. -/ def toSet (u : PSet.{u}) : Set PSet.{u} := { x | x ∈ u } #align pSet.to_set PSet.toSet @[simp] theorem mem_toSet (a u : PSet.{u}) : a ∈ u.toSet ↔ a ∈ u := Iff.rfl #align pSet.mem_to_set PSet.mem_toSet /-- A nonempty set is one that contains some element. -/ protected def Nonempty (u : PSet) : Prop := u.toSet.Nonempty #align pSet.nonempty PSet.Nonempty theorem nonempty_def (u : PSet) : u.Nonempty ↔ ∃ x, x ∈ u := Iff.rfl #align pSet.nonempty_def PSet.nonempty_def theorem nonempty_of_mem {x u : PSet} (h : x ∈ u) : u.Nonempty := ⟨x, h⟩ #align pSet.nonempty_of_mem PSet.nonempty_of_mem @[simp] theorem nonempty_toSet_iff {u : PSet} : u.toSet.Nonempty ↔ u.Nonempty := Iff.rfl #align pSet.nonempty_to_set_iff PSet.nonempty_toSet_iff theorem nonempty_type_iff_nonempty {x : PSet} : Nonempty x.Type ↔ PSet.Nonempty x := ⟨fun ⟨i⟩ => ⟨_, func_mem _ i⟩, fun ⟨_, j, _⟩ => ⟨j⟩⟩ #align pSet.nonempty_type_iff_nonempty PSet.nonempty_type_iff_nonempty theorem nonempty_of_nonempty_type (x : PSet) [h : Nonempty x.Type] : PSet.Nonempty x := nonempty_type_iff_nonempty.1 h #align pSet.nonempty_of_nonempty_type PSet.nonempty_of_nonempty_type /-- Two pre-sets are equivalent iff they have the same members. -/ theorem Equiv.eq {x y : PSet} : Equiv x y ↔ toSet x = toSet y := equiv_iff_mem.trans Set.ext_iff.symm #align pSet.equiv.eq PSet.Equiv.eq instance : Coe PSet (Set PSet) := ⟨toSet⟩ /-- The empty pre-set -/ protected def empty : PSet := ⟨_, PEmpty.elim⟩ #align pSet.empty PSet.empty instance : EmptyCollection PSet := ⟨PSet.empty⟩ instance : Inhabited PSet := ⟨∅⟩ instance : IsEmpty («Type» ∅) := ⟨PEmpty.elim⟩ @[simp] theorem not_mem_empty (x : PSet.{u}) : x ∉ (∅ : PSet.{u}) := IsEmpty.exists_iff.1 #align pSet.not_mem_empty PSet.not_mem_empty @[simp] theorem toSet_empty : toSet ∅ = ∅ := by simp [toSet] #align pSet.to_set_empty PSet.toSet_empty @[simp] theorem empty_subset (x : PSet.{u}) : (∅ : PSet) ⊆ x := fun x => x.elim #align pSet.empty_subset PSet.empty_subset @[simp] theorem not_nonempty_empty : ¬PSet.Nonempty ∅ := by simp [PSet.Nonempty] #align pSet.not_nonempty_empty PSet.not_nonempty_empty protected theorem equiv_empty (x : PSet) [IsEmpty x.Type] : Equiv x ∅ := PSet.equiv_of_isEmpty x _ #align pSet.equiv_empty PSet.equiv_empty /-- Insert an element into a pre-set -/ protected def insert (x y : PSet) : PSet := ⟨Option y.Type, fun o => Option.casesOn o x y.Func⟩ #align pSet.insert PSet.insert instance : Insert PSet PSet := ⟨PSet.insert⟩ instance : Singleton PSet PSet := ⟨fun s => insert s ∅⟩ instance : LawfulSingleton PSet PSet := ⟨fun _ => rfl⟩ instance (x y : PSet) : Inhabited (insert x y).Type := inferInstanceAs (Inhabited <| Option y.Type) /-- The n-th von Neumann ordinal -/ def ofNat : ℕ → PSet | 0 => ∅ | n + 1 => insert (ofNat n) (ofNat n) #align pSet.of_nat PSet.ofNat /-- The von Neumann ordinal ω -/ def omega : PSet := ⟨ULift ℕ, fun n => ofNat n.down⟩ #align pSet.omega PSet.omega /-- The pre-set separation operation `{x ∈ a | p x}` -/ protected def sep (p : PSet → Prop) (x : PSet) : PSet := ⟨{ a // p (x.Func a) }, fun y => x.Func y.1⟩ #align pSet.sep PSet.sep instance : Sep PSet PSet := ⟨PSet.sep⟩ /-- The pre-set powerset operator -/ def powerset (x : PSet) : PSet := ⟨Set x.Type, fun p => ⟨{ a // p a }, fun y => x.Func y.1⟩⟩ #align pSet.powerset PSet.powerset @[simp] theorem mem_powerset : ∀ {x y : PSet}, y ∈ powerset x ↔ y ⊆ x | ⟨_, A⟩, ⟨_, B⟩ => ⟨fun ⟨_, e⟩ => (Subset.congr_left e).2 fun ⟨a, _⟩ => ⟨a, Equiv.refl (A a)⟩, fun βα => ⟨{ a | ∃ b, Equiv (B b) (A a) }, fun b => let ⟨a, ba⟩ := βα b ⟨⟨a, b, ba⟩, ba⟩, fun ⟨_, b, ba⟩ => ⟨b, ba⟩⟩⟩ #align pSet.mem_powerset PSet.mem_powerset /-- The pre-set union operator -/ def sUnion (a : PSet) : PSet := ⟨Σx, (a.Func x).Type, fun ⟨x, y⟩ => (a.Func x).Func y⟩ #align pSet.sUnion PSet.sUnion @[inherit_doc] prefix:110 "⋃₀ " => sUnion @[simp] theorem mem_sUnion : ∀ {x y : PSet.{u}}, y ∈ ⋃₀ x ↔ ∃ z ∈ x, y ∈ z | ⟨α, A⟩, y => ⟨fun ⟨⟨a, c⟩, (e : Equiv y ((A a).Func c))⟩ => have : Func (A a) c ∈ mk (A a).Type (A a).Func := Mem.mk (A a).Func c ⟨_, Mem.mk _ _, (Mem.congr_left e).2 (by rwa [eta] at this)⟩, fun ⟨⟨β, B⟩, ⟨a, (e : Equiv (mk β B) (A a))⟩, ⟨b, yb⟩⟩ => by rw [← eta (A a)] at e exact let ⟨βt, _⟩ := e let ⟨c, bc⟩ := βt b ⟨⟨a, c⟩, yb.trans bc⟩⟩ #align pSet.mem_sUnion PSet.mem_sUnion @[simp] theorem toSet_sUnion (x : PSet.{u}) : (⋃₀ x).toSet = ⋃₀ (toSet '' x.toSet) := by ext simp #align pSet.to_set_sUnion PSet.toSet_sUnion /-- The image of a function from pre-sets to pre-sets. -/ def image (f : PSet.{u} → PSet.{u}) (x : PSet.{u}) : PSet := ⟨x.Type, f ∘ x.Func⟩ #align pSet.image PSet.image -- Porting note: H arguments made explicit. theorem mem_image {f : PSet.{u} → PSet.{u}} (H : ∀ x y, Equiv x y → Equiv (f x) (f y)) : ∀ {x y : PSet.{u}}, y ∈ image f x ↔ ∃ z ∈ x, Equiv y (f z) | ⟨_, A⟩, _ => ⟨fun ⟨a, ya⟩ => ⟨A a, Mem.mk A a, ya⟩, fun ⟨_, ⟨a, za⟩, yz⟩ => ⟨a, yz.trans <| H _ _ za⟩⟩ #align pSet.mem_image PSet.mem_image /-- Universe lift operation -/ protected def Lift : PSet.{u} → PSet.{max u v} | ⟨α, A⟩ => ⟨ULift.{v, u} α, fun ⟨x⟩ => PSet.Lift (A x)⟩ #align pSet.lift PSet.Lift -- intended to be used with explicit universe parameters /-- Embedding of one universe in another -/ @[nolint checkUnivs] def embed : PSet.{max (u + 1) v} := ⟨ULift.{v, u + 1} PSet, fun ⟨x⟩ => PSet.Lift.{u, max (u + 1) v} x⟩ #align pSet.embed PSet.embed theorem lift_mem_embed : ∀ x : PSet.{u}, PSet.Lift.{u, max (u + 1) v} x ∈ embed.{u, v} := fun x => ⟨⟨x⟩, Equiv.rfl⟩ #align pSet.lift_mem_embed PSet.lift_mem_embed /-- Function equivalence is defined so that `f ~ g` iff `∀ x y, x ~ y → f x ~ g y`. This extends to equivalence of `n`-ary functions. -/ def Arity.Equiv : ∀ {n}, OfArity PSet.{u} PSet.{u} n → OfArity PSet.{u} PSet.{u} n → Prop | 0, a, b => PSet.Equiv a b | _ + 1, a, b => ∀ x y : PSet, PSet.Equiv x y → Arity.Equiv (a x) (b y) #align pSet.arity.equiv PSet.Arity.Equiv theorem Arity.equiv_const {a : PSet.{u}} : ∀ n, Arity.Equiv (OfArity.const PSet.{u} a n) (OfArity.const PSet.{u} a n) | 0 => Equiv.rfl | _ + 1 => fun _ _ _ => Arity.equiv_const _ #align pSet.arity.equiv_const PSet.Arity.equiv_const /-- `resp n` is the collection of n-ary functions on `PSet` that respect equivalence, i.e. when the inputs are equivalent the output is as well. -/ def Resp (n) := { x : OfArity PSet.{u} PSet.{u} n // Arity.Equiv x x } #align pSet.resp PSet.Resp instance Resp.inhabited {n} : Inhabited (Resp n) := ⟨⟨OfArity.const _ default _, Arity.equiv_const _⟩⟩ #align pSet.resp.inhabited PSet.Resp.inhabited /-- The `n`-ary image of a `(n + 1)`-ary function respecting equivalence as a function respecting equivalence. -/ def Resp.f {n} (f : Resp (n + 1)) (x : PSet) : Resp n := ⟨f.1 x, f.2 _ _ <| Equiv.refl x⟩ #align pSet.resp.f PSet.Resp.f /-- Function equivalence for functions respecting equivalence. See `PSet.Arity.Equiv`. -/ def Resp.Equiv {n} (a b : Resp n) : Prop := Arity.Equiv a.1 b.1 #align pSet.resp.equiv PSet.Resp.Equiv @[refl] protected theorem Resp.Equiv.refl {n} (a : Resp n) : Resp.Equiv a a := a.2 #align pSet.resp.equiv.refl PSet.Resp.Equiv.refl protected theorem Resp.Equiv.euc : ∀ {n} {a b c : Resp n}, Resp.Equiv a b → Resp.Equiv c b → Resp.Equiv a c | 0, _, _, _, hab, hcb => PSet.Equiv.euc hab hcb | n + 1, a, b, c, hab, hcb => fun x y h => @Resp.Equiv.euc n (a.f x) (b.f y) (c.f y) (hab _ _ h) (hcb _ _ <| PSet.Equiv.refl y) #align pSet.resp.equiv.euc PSet.Resp.Equiv.euc @[symm] protected theorem Resp.Equiv.symm {n} {a b : Resp n} : Resp.Equiv a b → Resp.Equiv b a := (Resp.Equiv.refl b).euc #align pSet.resp.equiv.symm PSet.Resp.Equiv.symm @[trans] protected theorem Resp.Equiv.trans {n} {x y z : Resp n} (h1 : Resp.Equiv x y) (h2 : Resp.Equiv y z) : Resp.Equiv x z := h1.euc h2.symm #align pSet.resp.equiv.trans PSet.Resp.Equiv.trans instance Resp.setoid {n} : Setoid (Resp n) := ⟨Resp.Equiv, Resp.Equiv.refl, Resp.Equiv.symm, Resp.Equiv.trans⟩ #align pSet.resp.setoid PSet.Resp.setoid end PSet /-- The ZFC universe of sets consists of the type of pre-sets, quotiented by extensional equivalence. -/ def ZFSet : Type (u + 1) := Quotient PSet.setoid.{u} #align Set ZFSet namespace PSet namespace Resp /-- Helper function for `PSet.eval`. -/ def evalAux : ∀ {n}, { f : Resp n → OfArity ZFSet.{u} ZFSet.{u} n // ∀ a b : Resp n, Resp.Equiv a b → f a = f b } | 0 => ⟨fun a => ⟦a.1⟧, fun _ _ h => Quotient.sound h⟩ | n + 1 => let F : Resp (n + 1) → OfArity ZFSet ZFSet (n + 1) := fun a => @Quotient.lift _ _ PSet.setoid (fun x => evalAux.1 (a.f x)) fun _ _ h => evalAux.2 _ _ (a.2 _ _ h) ⟨F, fun b c h => funext <| (@Quotient.ind _ _ fun q => F b q = F c q) fun z => evalAux.2 (Resp.f b z) (Resp.f c z) (h _ _ (PSet.Equiv.refl z))⟩ #align pSet.resp.eval_aux PSet.Resp.evalAux /-- An equivalence-respecting function yields an n-ary ZFC set function. -/ def eval (n) : Resp n → OfArity ZFSet.{u} ZFSet.{u} n := evalAux.1 #align pSet.resp.eval PSet.Resp.eval theorem eval_val {n f x} : (@eval (n + 1) f : ZFSet → OfArity ZFSet ZFSet n) ⟦x⟧ = eval n (Resp.f f x) := rfl #align pSet.resp.eval_val PSet.Resp.eval_val end Resp /-- A set function is "definable" if it is the image of some n-ary pre-set function. This isn't exactly definability, but is useful as a sufficient condition for functions that have a computable image. -/ class inductive Definable (n) : OfArity ZFSet.{u} ZFSet.{u} n → Type (u + 1) | mk (f) : Definable n (Resp.eval n f) #align pSet.definable PSet.Definable attribute [instance] Definable.mk /-- The evaluation of a function respecting equivalence is definable, by that same function. -/ def Definable.EqMk {n} (f) : ∀ {s : OfArity ZFSet.{u} ZFSet.{u} n} (_ : Resp.eval _ f = s), Definable n s | _, rfl => ⟨f⟩ #align pSet.definable.eq_mk PSet.Definable.EqMk /-- Turns a definable function into a function that respects equivalence. -/ def Definable.Resp {n} : ∀ (s : OfArity ZFSet.{u} ZFSet.{u} n) [Definable n s], Resp n | _, ⟨f⟩ => f #align pSet.definable.resp PSet.Definable.Resp theorem Definable.eq {n} : ∀ (s : OfArity ZFSet.{u} ZFSet.{u} n) [H : Definable n s], (@Definable.Resp n s H).eval _ = s | _, ⟨_⟩ => rfl #align pSet.definable.eq PSet.Definable.eq end PSet namespace Classical open PSet /-- All functions are classically definable. -/ noncomputable def allDefinable : ∀ {n} (F : OfArity ZFSet ZFSet n), Definable n F | 0, F => let p := @Quotient.exists_rep PSet _ F @Definable.EqMk 0 ⟨choose p, Equiv.rfl⟩ _ (choose_spec p) | n + 1, (F : OfArity ZFSet ZFSet (n + 1)) => by have I : (x : ZFSet) → Definable n (F x) := fun x => allDefinable (F x) refine @Definable.EqMk (n + 1) ⟨fun x : PSet => (@Definable.Resp _ _ (I ⟦x⟧)).1, ?_⟩ _ ?_ · dsimp [Arity.Equiv] intro x y h rw [@Quotient.sound PSet _ _ _ h] exact (Definable.Resp (F ⟦y⟧)).2 refine funext fun q => Quotient.inductionOn q fun x => ?_ simp_rw [Resp.eval_val, Resp.f] exact @Definable.eq _ (F ⟦x⟧) (I ⟦x⟧) #align classical.all_definable Classical.allDefinable end Classical namespace ZFSet open PSet /-- Turns a pre-set into a ZFC set. -/ def mk : PSet → ZFSet := Quotient.mk'' #align Set.mk ZFSet.mk @[simp] theorem mk_eq (x : PSet) : @Eq ZFSet ⟦x⟧ (mk x) := rfl #align Set.mk_eq ZFSet.mk_eq @[simp] theorem mk_out : ∀ x : ZFSet, mk x.out = x := Quotient.out_eq #align Set.mk_out ZFSet.mk_out theorem eq {x y : PSet} : mk x = mk y ↔ Equiv x y := Quotient.eq #align Set.eq ZFSet.eq theorem sound {x y : PSet} (h : PSet.Equiv x y) : mk x = mk y := Quotient.sound h #align Set.sound ZFSet.sound theorem exact {x y : PSet} : mk x = mk y → PSet.Equiv x y := Quotient.exact #align Set.exact ZFSet.exact @[simp] theorem eval_mk {n f x} : (@Resp.eval (n + 1) f : ZFSet → OfArity ZFSet ZFSet n) (mk x) = Resp.eval n (Resp.f f x) := rfl #align Set.eval_mk ZFSet.eval_mk /-- The membership relation for ZFC sets is inherited from the membership relation for pre-sets. -/ protected def Mem : ZFSet → ZFSet → Prop := Quotient.lift₂ PSet.Mem fun _ _ _ _ hx hy => propext ((Mem.congr_left hx).trans (Mem.congr_right hy)) #align Set.mem ZFSet.Mem instance : Membership ZFSet ZFSet := ⟨ZFSet.Mem⟩ @[simp] theorem mk_mem_iff {x y : PSet} : mk x ∈ mk y ↔ x ∈ y := Iff.rfl #align Set.mk_mem_iff ZFSet.mk_mem_iff /-- Convert a ZFC set into a `Set` of ZFC sets -/ def toSet (u : ZFSet.{u}) : Set ZFSet.{u} := { x | x ∈ u } #align Set.to_set ZFSet.toSet @[simp] theorem mem_toSet (a u : ZFSet.{u}) : a ∈ u.toSet ↔ a ∈ u := Iff.rfl #align Set.mem_to_set ZFSet.mem_toSet instance small_toSet (x : ZFSet.{u}) : Small.{u} x.toSet := Quotient.inductionOn x fun a => by let f : a.Type → (mk a).toSet := fun i => ⟨mk <| a.Func i, func_mem a i⟩ suffices Function.Surjective f by exact small_of_surjective this rintro ⟨y, hb⟩ induction y using Quotient.inductionOn cases' hb with i h exact ⟨i, Subtype.coe_injective (Quotient.sound h.symm)⟩ #align Set.small_to_set ZFSet.small_toSet /-- A nonempty set is one that contains some element. -/ protected def Nonempty (u : ZFSet) : Prop := u.toSet.Nonempty #align Set.nonempty ZFSet.Nonempty theorem nonempty_def (u : ZFSet) : u.Nonempty ↔ ∃ x, x ∈ u := Iff.rfl #align Set.nonempty_def ZFSet.nonempty_def theorem nonempty_of_mem {x u : ZFSet} (h : x ∈ u) : u.Nonempty := ⟨x, h⟩ #align Set.nonempty_of_mem ZFSet.nonempty_of_mem @[simp] theorem nonempty_toSet_iff {u : ZFSet} : u.toSet.Nonempty ↔ u.Nonempty := Iff.rfl #align Set.nonempty_to_set_iff ZFSet.nonempty_toSet_iff /-- `x ⊆ y` as ZFC sets means that all members of `x` are members of `y`. -/ protected def Subset (x y : ZFSet.{u}) := ∀ ⦃z⦄, z ∈ x → z ∈ y #align Set.subset ZFSet.Subset instance hasSubset : HasSubset ZFSet := ⟨ZFSet.Subset⟩ #align Set.has_subset ZFSet.hasSubset theorem subset_def {x y : ZFSet.{u}} : x ⊆ y ↔ ∀ ⦃z⦄, z ∈ x → z ∈ y := Iff.rfl #align Set.subset_def ZFSet.subset_def instance : IsRefl ZFSet (· ⊆ ·) := ⟨fun _ _ => id⟩ instance : IsTrans ZFSet (· ⊆ ·) := ⟨fun _ _ _ hxy hyz _ ha => hyz (hxy ha)⟩ @[simp] theorem subset_iff : ∀ {x y : PSet}, mk x ⊆ mk y ↔ x ⊆ y | ⟨_, A⟩, ⟨_, _⟩ => ⟨fun h a => @h ⟦A a⟧ (Mem.mk A a), fun h z => Quotient.inductionOn z fun _ ⟨a, za⟩ => let ⟨b, ab⟩ := h a ⟨b, za.trans ab⟩⟩ #align Set.subset_iff ZFSet.subset_iff @[simp] theorem toSet_subset_iff {x y : ZFSet} : x.toSet ⊆ y.toSet ↔ x ⊆ y := by simp [subset_def, Set.subset_def] #align Set.to_set_subset_iff ZFSet.toSet_subset_iff @[ext] theorem ext {x y : ZFSet.{u}} : (∀ z : ZFSet.{u}, z ∈ x ↔ z ∈ y) → x = y := Quotient.inductionOn₂ x y fun _ _ h => Quotient.sound (Mem.ext fun w => h ⟦w⟧) #align Set.ext ZFSet.ext theorem ext_iff {x y : ZFSet.{u}} : x = y ↔ ∀ z : ZFSet.{u}, z ∈ x ↔ z ∈ y := ⟨fun h => by simp [h], ext⟩ #align Set.ext_iff ZFSet.ext_iff theorem toSet_injective : Function.Injective toSet := fun _ _ h => ext <| Set.ext_iff.1 h #align Set.to_set_injective ZFSet.toSet_injective @[simp] theorem toSet_inj {x y : ZFSet} : x.toSet = y.toSet ↔ x = y := toSet_injective.eq_iff #align Set.to_set_inj ZFSet.toSet_inj instance : IsAntisymm ZFSet (· ⊆ ·) := ⟨fun _ _ hab hba => ext fun c => ⟨@hab c, @hba c⟩⟩ /-- The empty ZFC set -/ protected def empty : ZFSet := mk ∅ #align Set.empty ZFSet.empty instance : EmptyCollection ZFSet := ⟨ZFSet.empty⟩ instance : Inhabited ZFSet := ⟨∅⟩ @[simp] theorem not_mem_empty (x) : x ∉ (∅ : ZFSet.{u}) := Quotient.inductionOn x PSet.not_mem_empty #align Set.not_mem_empty ZFSet.not_mem_empty @[simp] theorem toSet_empty : toSet ∅ = ∅ := by simp [toSet] #align Set.to_set_empty ZFSet.toSet_empty @[simp] theorem empty_subset (x : ZFSet.{u}) : (∅ : ZFSet) ⊆ x := Quotient.inductionOn x fun y => subset_iff.2 <| PSet.empty_subset y #align Set.empty_subset ZFSet.empty_subset @[simp] theorem not_nonempty_empty : ¬ZFSet.Nonempty ∅ := by simp [ZFSet.Nonempty] #align Set.not_nonempty_empty ZFSet.not_nonempty_empty @[simp] theorem nonempty_mk_iff {x : PSet} : (mk x).Nonempty ↔ x.Nonempty := by refine ⟨?_, fun ⟨a, h⟩ => ⟨mk a, h⟩⟩ rintro ⟨a, h⟩ induction a using Quotient.inductionOn exact ⟨_, h⟩ #align Set.nonempty_mk_iff ZFSet.nonempty_mk_iff theorem eq_empty (x : ZFSet.{u}) : x = ∅ ↔ ∀ y : ZFSet.{u}, y ∉ x := by rw [ext_iff] simp #align Set.eq_empty ZFSet.eq_empty theorem eq_empty_or_nonempty (u : ZFSet) : u = ∅ ∨ u.Nonempty := by rw [eq_empty, ← not_exists] apply em' #align Set.eq_empty_or_nonempty ZFSet.eq_empty_or_nonempty /-- `Insert x y` is the set `{x} ∪ y` -/ protected def Insert : ZFSet → ZFSet → ZFSet := Resp.eval 2 ⟨PSet.insert, fun _ _ uv ⟨_, _⟩ ⟨_, _⟩ ⟨αβ, βα⟩ => ⟨fun o => match o with | some a => let ⟨b, hb⟩ := αβ a ⟨some b, hb⟩ | none => ⟨none, uv⟩, fun o => match o with | some b => let ⟨a, ha⟩ := βα b ⟨some a, ha⟩ | none => ⟨none, uv⟩⟩⟩ #align Set.insert ZFSet.Insert instance : Insert ZFSet ZFSet := ⟨ZFSet.Insert⟩ instance : Singleton ZFSet ZFSet := ⟨fun x => insert x ∅⟩ instance : LawfulSingleton ZFSet ZFSet := ⟨fun _ => rfl⟩ @[simp] theorem mem_insert_iff {x y z : ZFSet.{u}} : x ∈ insert y z ↔ x = y ∨ x ∈ z := Quotient.inductionOn₃ x y z fun x y ⟨α, A⟩ => show (x ∈ PSet.mk (Option α) fun o => Option.rec y A o) ↔ mk x = mk y ∨ x ∈ PSet.mk α A from ⟨fun m => match m with | ⟨some a, ha⟩ => Or.inr ⟨a, ha⟩ | ⟨none, h⟩ => Or.inl (Quotient.sound h), fun m => match m with | Or.inr ⟨a, ha⟩ => ⟨some a, ha⟩ | Or.inl h => ⟨none, Quotient.exact h⟩⟩ #align Set.mem_insert_iff ZFSet.mem_insert_iff theorem mem_insert (x y : ZFSet) : x ∈ insert x y := mem_insert_iff.2 <| Or.inl rfl #align Set.mem_insert ZFSet.mem_insert theorem mem_insert_of_mem {y z : ZFSet} (x) (h : z ∈ y) : z ∈ insert x y := mem_insert_iff.2 <| Or.inr h #align Set.mem_insert_of_mem ZFSet.mem_insert_of_mem @[simp] theorem toSet_insert (x y : ZFSet) : (insert x y).toSet = insert x y.toSet := by ext simp #align Set.to_set_insert ZFSet.toSet_insert @[simp] theorem mem_singleton {x y : ZFSet.{u}} : x ∈ @singleton ZFSet.{u} ZFSet.{u} _ y ↔ x = y := Iff.trans mem_insert_iff ⟨fun o => Or.rec (fun h => h) (fun n => absurd n (not_mem_empty _)) o, Or.inl⟩ #align Set.mem_singleton ZFSet.mem_singleton @[simp] theorem toSet_singleton (x : ZFSet) : ({x} : ZFSet).toSet = {x} := by ext simp #align Set.to_set_singleton ZFSet.toSet_singleton theorem insert_nonempty (u v : ZFSet) : (insert u v).Nonempty := ⟨u, mem_insert u v⟩ #align Set.insert_nonempty ZFSet.insert_nonempty theorem singleton_nonempty (u : ZFSet) : ZFSet.Nonempty {u} := insert_nonempty u ∅ #align Set.singleton_nonempty ZFSet.singleton_nonempty theorem mem_pair {x y z : ZFSet.{u}} : x ∈ ({y, z} : ZFSet) ↔ x = y ∨ x = z := by simp #align Set.mem_pair ZFSet.mem_pair /-- `omega` is the first infinite von Neumann ordinal -/ def omega : ZFSet := mk PSet.omega #align Set.omega ZFSet.omega @[simp] theorem omega_zero : ∅ ∈ omega := ⟨⟨0⟩, Equiv.rfl⟩ #align Set.omega_zero ZFSet.omega_zero @[simp] theorem omega_succ {n} : n ∈ omega.{u} → insert n n ∈ omega.{u} := Quotient.inductionOn n fun x ⟨⟨n⟩, h⟩ => ⟨⟨n + 1⟩, ZFSet.exact <| show insert (mk x) (mk x) = insert (mk <| ofNat n) (mk <| ofNat n) by rw [ZFSet.sound h] rfl⟩ #align Set.omega_succ ZFSet.omega_succ /-- `{x ∈ a | p x}` is the set of elements in `a` satisfying `p` -/ protected def sep (p : ZFSet → Prop) : ZFSet → ZFSet := Resp.eval 1 ⟨PSet.sep fun y => p (mk y), fun ⟨α, A⟩ ⟨β, B⟩ ⟨αβ, βα⟩ => ⟨fun ⟨a, pa⟩ => let ⟨b, hb⟩ := αβ a ⟨⟨b, by simpa only [mk_func, ← ZFSet.sound hb]⟩, hb⟩, fun ⟨b, pb⟩ => let ⟨a, ha⟩ := βα b ⟨⟨a, by simpa only [mk_func, ZFSet.sound ha]⟩, ha⟩⟩⟩ #align Set.sep ZFSet.sep -- Porting note: the { x | p x } notation appears to be disabled in Lean 4. instance : Sep ZFSet ZFSet := ⟨ZFSet.sep⟩ @[simp] theorem mem_sep {p : ZFSet.{u} → Prop} {x y : ZFSet.{u}} : y ∈ ZFSet.sep p x ↔ y ∈ x ∧ p y := Quotient.inductionOn₂ x y fun ⟨α, A⟩ y => ⟨fun ⟨⟨a, pa⟩, h⟩ => ⟨⟨a, h⟩, by rwa [@Quotient.sound PSet _ _ _ h]⟩, fun ⟨⟨a, h⟩, pa⟩ => ⟨⟨a, by rw [mk_func] at h rwa [mk_func, ← ZFSet.sound h]⟩, h⟩⟩ #align Set.mem_sep ZFSet.mem_sep @[simp] theorem toSet_sep (a : ZFSet) (p : ZFSet → Prop) : (ZFSet.sep p a).toSet = { x ∈ a.toSet | p x } := by ext simp #align Set.to_set_sep ZFSet.toSet_sep /-- The powerset operation, the collection of subsets of a ZFC set -/ def powerset : ZFSet → ZFSet := Resp.eval 1 ⟨PSet.powerset, fun ⟨_, A⟩ ⟨_, B⟩ ⟨αβ, βα⟩ => ⟨fun p => ⟨{ b | ∃ a, p a ∧ Equiv (A a) (B b) }, fun ⟨a, pa⟩ => let ⟨b, ab⟩ := αβ a ⟨⟨b, a, pa, ab⟩, ab⟩, fun ⟨_, a, pa, ab⟩ => ⟨⟨a, pa⟩, ab⟩⟩, fun q => ⟨{ a | ∃ b, q b ∧ Equiv (A a) (B b) }, fun ⟨_, b, qb, ab⟩ => ⟨⟨b, qb⟩, ab⟩, fun ⟨b, qb⟩ => let ⟨a, ab⟩ := βα b ⟨⟨a, b, qb, ab⟩, ab⟩⟩⟩⟩ #align Set.powerset ZFSet.powerset @[simp] theorem mem_powerset {x y : ZFSet.{u}} : y ∈ powerset x ↔ y ⊆ x := Quotient.inductionOn₂ x y fun ⟨α, A⟩ ⟨β, B⟩ => show (⟨β, B⟩ : PSet.{u}) ∈ PSet.powerset.{u} ⟨α, A⟩ ↔ _ by simp [mem_powerset, subset_iff] #align Set.mem_powerset ZFSet.mem_powerset theorem sUnion_lem {α β : Type u} (A : α → PSet) (B : β → PSet) (αβ : ∀ a, ∃ b, Equiv (A a) (B b)) : ∀ a, ∃ b, Equiv ((sUnion ⟨α, A⟩).Func a) ((sUnion ⟨β, B⟩).Func b) | ⟨a, c⟩ => by let ⟨b, hb⟩ := αβ a induction' ea : A a with γ Γ induction' eb : B b with δ Δ rw [ea, eb] at hb cases' hb with γδ δγ let c : (A a).Type := c let ⟨d, hd⟩ := γδ (by rwa [ea] at c) use ⟨b, Eq.ndrec d (Eq.symm eb)⟩ change PSet.Equiv ((A a).Func c) ((B b).Func (Eq.ndrec d eb.symm)) match A a, B b, ea, eb, c, d, hd with | _, _, rfl, rfl, _, _, hd => exact hd #align Set.sUnion_lem ZFSet.sUnion_lem /-- The union operator, the collection of elements of elements of a ZFC set -/ def sUnion : ZFSet → ZFSet := Resp.eval 1 ⟨PSet.sUnion, fun ⟨_, A⟩ ⟨_, B⟩ ⟨αβ, βα⟩ => ⟨sUnion_lem A B αβ, fun a => Exists.elim (sUnion_lem B A (fun b => Exists.elim (βα b) fun c hc => ⟨c, PSet.Equiv.symm hc⟩) a) fun b hb => ⟨b, PSet.Equiv.symm hb⟩⟩⟩ #align Set.sUnion ZFSet.sUnion @[inherit_doc] prefix:110 "⋃₀ " => ZFSet.sUnion /-- The intersection operator, the collection of elements in all of the elements of a ZFC set. We special-case `⋂₀ ∅ = ∅`. -/ noncomputable def sInter (x : ZFSet) : ZFSet := by classical exact if h : x.Nonempty then ZFSet.sep (fun y => ∀ z ∈ x, y ∈ z) h.some else ∅ #align Set.sInter ZFSet.sInter @[inherit_doc] prefix:110 "⋂₀ " => ZFSet.sInter @[simp] theorem mem_sUnion {x y : ZFSet.{u}} : y ∈ ⋃₀ x ↔ ∃ z ∈ x, y ∈ z := Quotient.inductionOn₂ x y fun _ _ => Iff.trans PSet.mem_sUnion ⟨fun ⟨z, h⟩ => ⟨⟦z⟧, h⟩, fun ⟨z, h⟩ => Quotient.inductionOn z (fun z h => ⟨z, h⟩) h⟩ #align Set.mem_sUnion ZFSet.mem_sUnion theorem mem_sInter {x y : ZFSet} (h : x.Nonempty) : y ∈ ⋂₀ x ↔ ∀ z ∈ x, y ∈ z := by rw [sInter, dif_pos h] simp only [mem_toSet, mem_sep, and_iff_right_iff_imp] exact fun H => H _ h.some_mem #align Set.mem_sInter ZFSet.mem_sInter @[simp] theorem sUnion_empty : ⋃₀ (∅ : ZFSet.{u}) = ∅ := by ext simp #align Set.sUnion_empty ZFSet.sUnion_empty @[simp] theorem sInter_empty : ⋂₀ (∅ : ZFSet) = ∅ := dif_neg <| by simp #align Set.sInter_empty ZFSet.sInter_empty theorem mem_of_mem_sInter {x y z : ZFSet} (hy : y ∈ ⋂₀ x) (hz : z ∈ x) : y ∈ z := by rcases eq_empty_or_nonempty x with (rfl | hx) · exact (not_mem_empty z hz).elim · exact (mem_sInter hx).1 hy z hz #align Set.mem_of_mem_sInter ZFSet.mem_of_mem_sInter theorem mem_sUnion_of_mem {x y z : ZFSet} (hy : y ∈ z) (hz : z ∈ x) : y ∈ ⋃₀ x := mem_sUnion.2 ⟨z, hz, hy⟩ #align Set.mem_sUnion_of_mem ZFSet.mem_sUnion_of_mem theorem not_mem_sInter_of_not_mem {x y z : ZFSet} (hy : ¬y ∈ z) (hz : z ∈ x) : ¬y ∈ ⋂₀ x := fun hx => hy <| mem_of_mem_sInter hx hz #align Set.not_mem_sInter_of_not_mem ZFSet.not_mem_sInter_of_not_mem @[simp] theorem sUnion_singleton {x : ZFSet.{u}} : ⋃₀ ({x} : ZFSet) = x := ext fun y => by simp_rw [mem_sUnion, mem_singleton, exists_eq_left] #align Set.sUnion_singleton ZFSet.sUnion_singleton @[simp] theorem sInter_singleton {x : ZFSet.{u}} : ⋂₀ ({x} : ZFSet) = x := ext fun y => by simp_rw [mem_sInter (singleton_nonempty x), mem_singleton, forall_eq] #align Set.sInter_singleton ZFSet.sInter_singleton @[simp] theorem toSet_sUnion (x : ZFSet.{u}) : (⋃₀ x).toSet = ⋃₀ (toSet '' x.toSet) := by ext simp #align Set.to_set_sUnion ZFSet.toSet_sUnion theorem toSet_sInter {x : ZFSet.{u}} (h : x.Nonempty) : (⋂₀ x).toSet = ⋂₀ (toSet '' x.toSet) := by ext simp [mem_sInter h] #align Set.to_set_sInter ZFSet.toSet_sInter theorem singleton_injective : Function.Injective (@singleton ZFSet ZFSet _) := fun x y H => by let this := congr_arg sUnion H rwa [sUnion_singleton, sUnion_singleton] at this #align Set.singleton_injective ZFSet.singleton_injective @[simp] theorem singleton_inj {x y : ZFSet} : ({x} : ZFSet) = {y} ↔ x = y := singleton_injective.eq_iff #align Set.singleton_inj ZFSet.singleton_inj /-- The binary union operation -/ protected def union (x y : ZFSet.{u}) : ZFSet.{u} := ⋃₀ {x, y} #align Set.union ZFSet.union /-- The binary intersection operation -/ protected def inter (x y : ZFSet.{u}) : ZFSet.{u} := ZFSet.sep (fun z => z ∈ y) x -- { z ∈ x | z ∈ y } #align Set.inter ZFSet.inter /-- The set difference operation -/ protected def diff (x y : ZFSet.{u}) : ZFSet.{u} := ZFSet.sep (fun z => z ∉ y) x -- { z ∈ x | z ∉ y } #align Set.diff ZFSet.diff instance : Union ZFSet := ⟨ZFSet.union⟩ instance : Inter ZFSet := ⟨ZFSet.inter⟩ instance : SDiff ZFSet := ⟨ZFSet.diff⟩ @[simp] theorem toSet_union (x y : ZFSet.{u}) : (x ∪ y).toSet = x.toSet ∪ y.toSet := by change (⋃₀ {x, y}).toSet = _ simp #align Set.to_set_union ZFSet.toSet_union @[simp] theorem toSet_inter (x y : ZFSet.{u}) : (x ∩ y).toSet = x.toSet ∩ y.toSet := by change (ZFSet.sep (fun z => z ∈ y) x).toSet = _ ext simp #align Set.to_set_inter ZFSet.toSet_inter @[simp] theorem toSet_sdiff (x y : ZFSet.{u}) : (x \ y).toSet = x.toSet \ y.toSet := by change (ZFSet.sep (fun z => z ∉ y) x).toSet = _ ext simp #align Set.to_set_sdiff ZFSet.toSet_sdiff @[simp] theorem mem_union {x y z : ZFSet.{u}} : z ∈ x ∪ y ↔ z ∈ x ∨ z ∈ y := by rw [← mem_toSet] simp #align Set.mem_union ZFSet.mem_union @[simp] theorem mem_inter {x y z : ZFSet.{u}} : z ∈ x ∩ y ↔ z ∈ x ∧ z ∈ y := @mem_sep (fun z : ZFSet.{u} => z ∈ y) x z #align Set.mem_inter ZFSet.mem_inter @[simp] theorem mem_diff {x y z : ZFSet.{u}} : z ∈ x \ y ↔ z ∈ x ∧ z ∉ y := @mem_sep (fun z : ZFSet.{u} => z ∉ y) x z #align Set.mem_diff ZFSet.mem_diff @[simp] theorem sUnion_pair {x y : ZFSet.{u}} : ⋃₀ ({x, y} : ZFSet.{u}) = x ∪ y := rfl #align Set.sUnion_pair ZFSet.sUnion_pair theorem mem_wf : @WellFounded ZFSet (· ∈ ·) := (wellFounded_lift₂_iff (H := fun a b c d hx hy => propext ((@Mem.congr_left a c hx).trans (@Mem.congr_right b d hy _)))).mpr PSet.mem_wf #align Set.mem_wf ZFSet.mem_wf /-- Induction on the `∈` relation. -/ @[elab_as_elim] theorem inductionOn {p : ZFSet → Prop} (x) (h : ∀ x, (∀ y ∈ x, p y) → p x) : p x := mem_wf.induction x h #align Set.induction_on ZFSet.inductionOn instance : WellFoundedRelation ZFSet := ⟨_, mem_wf⟩ instance : IsAsymm ZFSet (· ∈ ·) := mem_wf.isAsymm -- Porting note: this can't be inferred automatically for some reason. instance : IsIrrefl ZFSet (· ∈ ·) := mem_wf.isIrrefl theorem mem_asymm {x y : ZFSet} : x ∈ y → y ∉ x := asymm #align Set.mem_asymm ZFSet.mem_asymm theorem mem_irrefl (x : ZFSet) : x ∉ x := irrefl x #align Set.mem_irrefl ZFSet.mem_irrefl theorem regularity (x : ZFSet.{u}) (h : x ≠ ∅) : ∃ y ∈ x, x ∩ y = ∅ := by_contradiction fun ne => h <| (eq_empty x).2 fun y => @inductionOn (fun z => z ∉ x) y fun z IH zx => ne ⟨z, zx, (eq_empty _).2 fun w wxz => let ⟨wx, wz⟩ := mem_inter.1 wxz IH w wz wx⟩ #align Set.regularity ZFSet.regularity /-- The image of a (definable) ZFC set function -/ def image (f : ZFSet → ZFSet) [Definable 1 f] : ZFSet → ZFSet := let ⟨r, hr⟩ := @Definable.Resp 1 f _ Resp.eval 1 ⟨PSet.image r, fun _ _ e => Mem.ext fun _ => (mem_image hr).trans <| Iff.trans ⟨fun ⟨w, h1, h2⟩ => ⟨w, (Mem.congr_right e).1 h1, h2⟩, fun ⟨w, h1, h2⟩ => ⟨w, (Mem.congr_right e).2 h1, h2⟩⟩ <| (mem_image hr).symm⟩ #align Set.image ZFSet.image theorem image.mk : ∀ (f : ZFSet.{u} → ZFSet.{u}) [H : Definable 1 f] (x) {y} (_ : y ∈ x), f y ∈ @image f H x | _, ⟨F⟩, x, y => Quotient.inductionOn₂ x y fun ⟨_, _⟩ _ ⟨a, ya⟩ => ⟨a, F.2 _ _ ya⟩ #align Set.image.mk ZFSet.image.mk @[simp] theorem mem_image : ∀ {f : ZFSet.{u} → ZFSet.{u}} [H : Definable 1 f] {x y : ZFSet.{u}}, y ∈ @image f H x ↔ ∃ z ∈ x, f z = y | _, ⟨_⟩, x, y => Quotient.inductionOn₂ x y fun ⟨_, A⟩ _ => ⟨fun ⟨a, ya⟩ => ⟨⟦A a⟧, Mem.mk A a, Eq.symm <| Quotient.sound ya⟩, fun ⟨_, hz, e⟩ => e ▸ image.mk _ _ hz⟩ #align Set.mem_image ZFSet.mem_image @[simp] theorem toSet_image (f : ZFSet → ZFSet) [H : Definable 1 f] (x : ZFSet) : (image f x).toSet = f '' x.toSet := by ext simp #align Set.to_set_image ZFSet.toSet_image /-- The range of an indexed family of sets. The universes allow for a more general index type without manual use of `ULift`. -/ noncomputable def range {α : Type u} (f : α → ZFSet.{max u v}) : ZFSet.{max u v} := ⟦⟨ULift.{v} α, Quotient.out ∘ f ∘ ULift.down⟩⟧ #align Set.range ZFSet.range @[simp] theorem mem_range {α : Type u} {f : α → ZFSet.{max u v}} {x : ZFSet.{max u v}} : x ∈ range.{u, v} f ↔ x ∈ Set.range f := Quotient.inductionOn x fun y => by constructor · rintro ⟨z, hz⟩ exact ⟨z.down, Quotient.eq_mk_iff_out.2 hz.symm⟩ · rintro ⟨z, hz⟩ use ULift.up z simpa [hz] using PSet.Equiv.symm (Quotient.mk_out y) #align Set.mem_range ZFSet.mem_range @[simp] theorem toSet_range {α : Type u} (f : α → ZFSet.{max u v}) : (range.{u, v} f).toSet = Set.range f := by ext simp #align Set.to_set_range ZFSet.toSet_range /-- Kuratowski ordered pair -/ def pair (x y : ZFSet.{u}) : ZFSet.{u} := {{x}, {x, y}} #align Set.pair ZFSet.pair @[simp] theorem toSet_pair (x y : ZFSet.{u}) : (pair x y).toSet = {{x}, {x, y}} := by simp [pair] #align Set.to_set_pair ZFSet.toSet_pair /-- A subset of pairs `{(a, b) ∈ x × y | p a b}` -/ def pairSep (p : ZFSet.{u} → ZFSet.{u} → Prop) (x y : ZFSet.{u}) : ZFSet.{u} := ZFSet.sep (fun z => ∃ a ∈ x, ∃ b ∈ y, z = pair a b ∧ p a b) (powerset (powerset (x ∪ y))) #align Set.pair_sep ZFSet.pairSep @[simp] theorem mem_pairSep {p} {x y z : ZFSet.{u}} : z ∈ pairSep p x y ↔ ∃ a ∈ x, ∃ b ∈ y, z = pair a b ∧ p a b := by refine mem_sep.trans ⟨And.right, fun e => ⟨?_, e⟩⟩ rcases e with ⟨a, ax, b, bY, rfl, pab⟩ simp only [mem_powerset, subset_def, mem_union, pair, mem_pair] rintro u (rfl | rfl) v <;> simp only [mem_singleton, mem_pair] · rintro rfl exact Or.inl ax · rintro (rfl | rfl) <;> [left; right] <;> assumption #align Set.mem_pair_sep ZFSet.mem_pairSep theorem pair_injective : Function.Injective2 pair := fun x x' y y' H => by have ae := ext_iff.1 H simp only [pair, mem_pair] at ae obtain rfl : x = x' := by cases' (ae {x}).1 (by simp) with h h · exact singleton_injective h · have m : x' ∈ ({x} : ZFSet) := by simp [h] rw [mem_singleton.mp m] have he : x = y → y = y' := by rintro rfl cases' (ae {x, y'}).2 (by simp only [eq_self_iff_true, or_true_iff]) with xy'x xy'xx · rw [eq_comm, ← mem_singleton, ← xy'x, mem_pair] exact Or.inr rfl · simpa [eq_comm] using (ext_iff.1 xy'xx y').1 (by simp) obtain xyx | xyy' := (ae {x, y}).1 (by simp) · obtain rfl := mem_singleton.mp ((ext_iff.1 xyx y).1 <| by simp) simp [he rfl] · obtain rfl | yy' := mem_pair.mp ((ext_iff.1 xyy' y).1 <| by simp) · simp [he rfl] · simp [yy'] #align Set.pair_injective ZFSet.pair_injective @[simp] theorem pair_inj {x y x' y' : ZFSet} : pair x y = pair x' y' ↔ x = x' ∧ y = y' := pair_injective.eq_iff #align Set.pair_inj ZFSet.pair_inj /-- The cartesian product, `{(a, b) | a ∈ x, b ∈ y}` -/ def prod : ZFSet.{u} → ZFSet.{u} → ZFSet.{u} := pairSep fun _ _ => True #align Set.prod ZFSet.prod @[simp] theorem mem_prod {x y z : ZFSet.{u}} : z ∈ prod x y ↔ ∃ a ∈ x, ∃ b ∈ y, z = pair a b := by simp [prod] #align Set.mem_prod ZFSet.mem_prod theorem pair_mem_prod {x y a b : ZFSet.{u}} : pair a b ∈ prod x y ↔ a ∈ x ∧ b ∈ y := by simp #align Set.pair_mem_prod ZFSet.pair_mem_prod /-- `isFunc x y f` is the assertion that `f` is a subset of `x × y` which relates to each element of `x` a unique element of `y`, so that we can consider `f` as a ZFC function `x → y`. -/ def IsFunc (x y f : ZFSet.{u}) : Prop := f ⊆ prod x y ∧ ∀ z : ZFSet.{u}, z ∈ x → ∃! w, pair z w ∈ f #align Set.is_func ZFSet.IsFunc /-- `funs x y` is `y ^ x`, the set of all set functions `x → y` -/ def funs (x y : ZFSet.{u}) : ZFSet.{u} := ZFSet.sep (IsFunc x y) (powerset (prod x y)) #align Set.funs ZFSet.funs @[simp] theorem mem_funs {x y f : ZFSet.{u}} : f ∈ funs x y ↔ IsFunc x y f := by simp [funs, IsFunc] #align Set.mem_funs ZFSet.mem_funs -- TODO(Mario): Prove this computably /- Porting note: the `Definable` argument in `mapDefinableAux` is unused, though the TODO remark suggests it shouldn't be. -/ @[nolint unusedArguments] noncomputable instance mapDefinableAux (f : ZFSet → ZFSet) [Definable 1 f] : Definable 1 fun (y : ZFSet) => pair y (f y) := @Classical.allDefinable 1 _ #align Set.map_definable_aux ZFSet.mapDefinableAux /-- Graph of a function: `map f x` is the ZFC function which maps `a ∈ x` to `f a` -/ noncomputable def map (f : ZFSet → ZFSet) [Definable 1 f] : ZFSet → ZFSet := image fun y => pair y (f y) #align Set.map ZFSet.map @[simp] theorem mem_map {f : ZFSet → ZFSet} [Definable 1 f] {x y : ZFSet} : y ∈ map f x ↔ ∃ z ∈ x, pair z (f z) = y := mem_image #align Set.mem_map ZFSet.mem_map theorem map_unique {f : ZFSet.{u} → ZFSet.{u}} [H : Definable 1 f] {x z : ZFSet.{u}} (zx : z ∈ x) : ∃! w, pair z w ∈ map f x := ⟨f z, image.mk _ _ zx, fun y yx => by let ⟨w, _, we⟩ := mem_image.1 yx let ⟨wz, fy⟩ := pair_injective we rw [← fy, wz]⟩ #align Set.map_unique ZFSet.map_unique @[simp] theorem map_isFunc {f : ZFSet → ZFSet} [Definable 1 f] {x y : ZFSet} : IsFunc x y (map f x) ↔ ∀ z ∈ x, f z ∈ y := ⟨fun ⟨ss, h⟩ z zx => let ⟨_, t1, t2⟩ := h z zx (t2 (f z) (image.mk _ _ zx)).symm ▸ (pair_mem_prod.1 (ss t1)).right, fun h => ⟨fun _ yx => let ⟨z, zx, ze⟩ := mem_image.1 yx ze ▸ pair_mem_prod.2 ⟨zx, h z zx⟩, fun _ => map_unique⟩⟩ #align Set.map_is_func ZFSet.map_isFunc /-- Given a predicate `p` on ZFC sets. `Hereditarily p x` means that `x` has property `p` and the members of `x` are all `Hereditarily p`. -/ def Hereditarily (p : ZFSet → Prop) (x : ZFSet) : Prop := p x ∧ ∀ y ∈ x, Hereditarily p y termination_by x #align Set.hereditarily ZFSet.Hereditarily section Hereditarily variable {p : ZFSet.{u} → Prop} {x y : ZFSet.{u}} theorem hereditarily_iff : Hereditarily p x ↔ p x ∧ ∀ y ∈ x, Hereditarily p y := by rw [← Hereditarily] #align Set.hereditarily_iff ZFSet.hereditarily_iff alias ⟨Hereditarily.def, _⟩ := hereditarily_iff #align Set.hereditarily.def ZFSet.Hereditarily.def theorem Hereditarily.self (h : x.Hereditarily p) : p x := h.def.1 #align Set.hereditarily.self ZFSet.Hereditarily.self theorem Hereditarily.mem (h : x.Hereditarily p) (hy : y ∈ x) : y.Hereditarily p := h.def.2 _ hy #align Set.hereditarily.mem ZFSet.Hereditarily.mem theorem Hereditarily.empty : Hereditarily p x → p ∅ := by apply @ZFSet.inductionOn _ x intro y IH h rcases ZFSet.eq_empty_or_nonempty y with (rfl | ⟨a, ha⟩) · exact h.self · exact IH a ha (h.mem ha) #align Set.hereditarily.empty ZFSet.Hereditarily.empty end Hereditarily end ZFSet /-- The collection of all classes. We define `Class` as `Set ZFSet`, as this allows us to get many instances automatically. However, in practice, we treat it as (the definitionally equal) `ZFSet → Prop`. This means, the preferred way to state that `x : ZFSet` belongs to `A : Class` is to write `A x`. -/ def Class := Set ZFSet deriving HasSubset, EmptyCollection, Nonempty, Union, Inter, HasCompl, SDiff #align Class Class instance : Insert ZFSet Class := ⟨Set.insert⟩ namespace Class -- Porting note: this is no longer an automatically derived instance. /-- `{x ∈ A | p x}` is the class of elements in `A` satisfying `p` -/ protected def sep (p : ZFSet → Prop) (A : Class) : Class := {y | A y ∧ p y} @[ext] theorem ext {x y : Class.{u}} : (∀ z : ZFSet.{u}, x z ↔ y z) → x = y := Set.ext #align Class.ext Class.ext theorem ext_iff {x y : Class.{u}} : x = y ↔ ∀ z, x z ↔ y z := Set.ext_iff #align Class.ext_iff Class.ext_iff /-- Coerce a ZFC set into a class -/ @[coe] def ofSet (x : ZFSet.{u}) : Class.{u} := { y | y ∈ x } #align Class.of_Set Class.ofSet instance : Coe ZFSet Class := ⟨ofSet⟩ /-- The universal class -/ def univ : Class := Set.univ #align Class.univ Class.univ /-- Assert that `A` is a ZFC set satisfying `B` -/ def ToSet (B : Class.{u}) (A : Class.{u}) : Prop := ∃ x : ZFSet, ↑x = A ∧ B x #align Class.to_Set Class.ToSet /-- `A ∈ B` if `A` is a ZFC set which satisfies `B` -/ protected def Mem (A B : Class.{u}) : Prop := ToSet.{u} B A #align Class.mem Class.Mem instance : Membership Class Class := ⟨Class.Mem⟩ theorem mem_def (A B : Class.{u}) : A ∈ B ↔ ∃ x : ZFSet, ↑x = A ∧ B x := Iff.rfl #align Class.mem_def Class.mem_def @[simp] theorem not_mem_empty (x : Class.{u}) : x ∉ (∅ : Class.{u}) := fun ⟨_, _, h⟩ => h #align Class.not_mem_empty Class.not_mem_empty @[simp] theorem not_empty_hom (x : ZFSet.{u}) : ¬(∅ : Class.{u}) x := id #align Class.not_empty_hom Class.not_empty_hom @[simp] theorem mem_univ {A : Class.{u}} : A ∈ univ.{u} ↔ ∃ x : ZFSet.{u}, ↑x = A := exists_congr fun _ => and_true_iff _ #align Class.mem_univ Class.mem_univ @[simp] theorem mem_univ_hom (x : ZFSet.{u}) : univ.{u} x := trivial #align Class.mem_univ_hom Class.mem_univ_hom theorem eq_univ_iff_forall {A : Class.{u}} : A = univ ↔ ∀ x : ZFSet, A x := Set.eq_univ_iff_forall #align Class.eq_univ_iff_forall Class.eq_univ_iff_forall theorem eq_univ_of_forall {A : Class.{u}} : (∀ x : ZFSet, A x) → A = univ := Set.eq_univ_of_forall #align Class.eq_univ_of_forall Class.eq_univ_of_forall theorem mem_wf : @WellFounded Class.{u} (· ∈ ·) := ⟨by have H : ∀ x : ZFSet.{u}, @Acc Class.{u} (· ∈ ·) ↑x := by refine fun a => ZFSet.inductionOn a fun x IH => ⟨_, ?_⟩ rintro A ⟨z, rfl, hz⟩ exact IH z hz refine fun A => ⟨A, ?_⟩ rintro B ⟨x, rfl, _⟩ exact H x⟩ #align Class.mem_wf Class.mem_wf instance : WellFoundedRelation Class := ⟨_, mem_wf⟩ instance : IsAsymm Class (· ∈ ·) := mem_wf.isAsymm -- Porting note: this can't be inferred automatically for some reason. instance : IsIrrefl Class (· ∈ ·) := mem_wf.isIrrefl theorem mem_asymm {x y : Class} : x ∈ y → y ∉ x := asymm #align Class.mem_asymm Class.mem_asymm theorem mem_irrefl (x : Class) : x ∉ x := irrefl x #align Class.mem_irrefl Class.mem_irrefl /-- **There is no universal set.** This is stated as `univ ∉ univ`, meaning that `univ` (the class of all sets) is proper (does not belong to the class of all sets). -/ theorem univ_not_mem_univ : univ ∉ univ := mem_irrefl _ #align Class.univ_not_mem_univ Class.univ_not_mem_univ /-- Convert a conglomerate (a collection of classes) into a class -/ def congToClass (x : Set Class.{u}) : Class.{u} := { y | ↑y ∈ x } #align Class.Cong_to_Class Class.congToClass @[simp] theorem congToClass_empty : congToClass ∅ = ∅ := by ext z simp only [congToClass, not_empty_hom, iff_false_iff] exact Set.not_mem_empty z #align Class.Cong_to_Class_empty Class.congToClass_empty /-- Convert a class into a conglomerate (a collection of classes) -/ def classToCong (x : Class.{u}) : Set Class.{u} := { y | y ∈ x } #align Class.Class_to_Cong Class.classToCong @[simp] theorem classToCong_empty : classToCong ∅ = ∅ := by ext simp [classToCong] #align Class.Class_to_Cong_empty Class.classToCong_empty /-- The power class of a class is the class of all subclasses that are ZFC sets -/ def powerset (x : Class) : Class := congToClass (Set.powerset x) #align Class.powerset Class.powerset /-- The union of a class is the class of all members of ZFC sets in the class -/ def sUnion (x : Class) : Class := ⋃₀ classToCong x #align Class.sUnion Class.sUnion @[inherit_doc] prefix:110 "⋃₀ " => Class.sUnion /-- The intersection of a class is the class of all members of ZFC sets in the class -/ def sInter (x : Class) : Class := ⋂₀ classToCong x @[inherit_doc] prefix:110 "⋂₀ " => Class.sInter theorem ofSet.inj {x y : ZFSet.{u}} (h : (x : Class.{u}) = y) : x = y := ZFSet.ext fun z => by change (x : Class.{u}) z ↔ (y : Class.{u}) z rw [h] #align Class.of_Set.inj Class.ofSet.inj @[simp] theorem toSet_of_ZFSet (A : Class.{u}) (x : ZFSet.{u}) : ToSet A x ↔ A x := ⟨fun ⟨y, yx, py⟩ => by rwa [ofSet.inj yx] at py, fun px => ⟨x, rfl, px⟩⟩ #align Class.to_Set_of_Set Class.toSet_of_ZFSet @[simp, norm_cast] theorem coe_mem {x : ZFSet.{u}} {A : Class.{u}} : ↑x ∈ A ↔ A x := toSet_of_ZFSet _ _ #align Class.coe_mem Class.coe_mem @[simp] theorem coe_apply {x y : ZFSet.{u}} : (y : Class.{u}) x ↔ x ∈ y := Iff.rfl #align Class.coe_apply Class.coe_apply @[simp, norm_cast] theorem coe_subset (x y : ZFSet.{u}) : (x : Class.{u}) ⊆ y ↔ x ⊆ y := Iff.rfl #align Class.coe_subset Class.coe_subset @[simp, norm_cast] theorem coe_sep (p : Class.{u}) (x : ZFSet.{u}) : (ZFSet.sep p x : Class) = { y ∈ x | p y } := ext fun _ => ZFSet.mem_sep #align Class.coe_sep Class.coe_sep @[simp, norm_cast] theorem coe_empty : ↑(∅ : ZFSet.{u}) = (∅ : Class.{u}) := ext fun y => iff_false_iff.2 <| ZFSet.not_mem_empty y #align Class.coe_empty Class.coe_empty @[simp, norm_cast] theorem coe_insert (x y : ZFSet.{u}) : ↑(insert x y) = @insert ZFSet.{u} Class.{u} _ x y := ext fun _ => ZFSet.mem_insert_iff #align Class.coe_insert Class.coe_insert @[simp, norm_cast] theorem coe_union (x y : ZFSet.{u}) : ↑(x ∪ y) = (x : Class.{u}) ∪ y := ext fun _ => ZFSet.mem_union #align Class.coe_union Class.coe_union @[simp, norm_cast] theorem coe_inter (x y : ZFSet.{u}) : ↑(x ∩ y) = (x : Class.{u}) ∩ y := ext fun _ => ZFSet.mem_inter #align Class.coe_inter Class.coe_inter @[simp, norm_cast] theorem coe_diff (x y : ZFSet.{u}) : ↑(x \ y) = (x : Class.{u}) \ y := ext fun _ => ZFSet.mem_diff #align Class.coe_diff Class.coe_diff @[simp, norm_cast] theorem coe_powerset (x : ZFSet.{u}) : ↑x.powerset = powerset.{u} x := ext fun _ => ZFSet.mem_powerset #align Class.coe_powerset Class.coe_powerset @[simp] theorem powerset_apply {A : Class.{u}} {x : ZFSet.{u}} : powerset A x ↔ ↑x ⊆ A := Iff.rfl #align Class.powerset_apply Class.powerset_apply @[simp] theorem sUnion_apply {x : Class} {y : ZFSet} : (⋃₀ x) y ↔ ∃ z : ZFSet, x z ∧ y ∈ z := by constructor · rintro ⟨-, ⟨z, rfl, hxz⟩, hyz⟩ exact ⟨z, hxz, hyz⟩ · exact fun ⟨z, hxz, hyz⟩ => ⟨_, coe_mem.2 hxz, hyz⟩ #align Class.sUnion_apply Class.sUnion_apply @[simp, norm_cast] theorem coe_sUnion (x : ZFSet.{u}) : ↑(⋃₀ x : ZFSet) = ⋃₀ (x : Class.{u}) := ext fun y => ZFSet.mem_sUnion.trans (sUnion_apply.trans <| by rfl).symm #align Class.coe_sUnion Class.coe_sUnion @[simp] theorem mem_sUnion {x y : Class.{u}} : y ∈ ⋃₀ x ↔ ∃ z, z ∈ x ∧ y ∈ z := by constructor · rintro ⟨w, rfl, z, hzx, hwz⟩ exact ⟨z, hzx, coe_mem.2 hwz⟩ · rintro ⟨w, hwx, z, rfl, hwz⟩ exact ⟨z, rfl, w, hwx, hwz⟩ #align Class.mem_sUnion Class.mem_sUnion
Mathlib/SetTheory/ZFC/Basic.lean
1,661
1,664
theorem sInter_apply {x : Class.{u}} {y : ZFSet.{u}} : (⋂₀ x) y ↔ ∀ z : ZFSet.{u}, x z → y ∈ z := by
refine ⟨fun hxy z hxz => hxy _ ⟨z, rfl, hxz⟩, ?_⟩ rintro H - ⟨z, rfl, hxz⟩ exact H _ hxz
/- Copyright (c) 2022 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Floris van Doorn, Yury Kudryashov -/ import Mathlib.Order.Filter.Lift import Mathlib.Order.Filter.AtTopBot #align_import order.filter.small_sets from "leanprover-community/mathlib"@"8631e2d5ea77f6c13054d9151d82b83069680cb1" /-! # The filter of small sets This file defines the filter of small sets w.r.t. a filter `f`, which is the largest filter containing all powersets of members of `f`. `g` converges to `f.smallSets` if for all `s ∈ f`, eventually we have `g x ⊆ s`. An example usage is that if `f : ι → E → ℝ` is a family of nonnegative functions with integral 1, then saying that `fun i ↦ support (f i)` tendsto `(𝓝 0).smallSets` is a way of saying that `f` tends to the Dirac delta distribution. -/ open Filter open Filter Set variable {α β : Type*} {ι : Sort*} namespace Filter variable {l l' la : Filter α} {lb : Filter β} /-- The filter `l.smallSets` is the largest filter containing all powersets of members of `l`. -/ def smallSets (l : Filter α) : Filter (Set α) := l.lift' powerset #align filter.small_sets Filter.smallSets theorem smallSets_eq_generate {f : Filter α} : f.smallSets = generate (powerset '' f.sets) := by simp_rw [generate_eq_biInf, smallSets, iInf_image] rfl #align filter.small_sets_eq_generate Filter.smallSets_eq_generate -- TODO: get more properties from the adjunction? -- TODO: is there a general way to get a lower adjoint for the lift of an upper adjoint? theorem bind_smallSets_gc : GaloisConnection (fun L : Filter (Set α) ↦ L.bind principal) smallSets := by intro L l simp_rw [smallSets_eq_generate, le_generate_iff, image_subset_iff] rfl protected theorem HasBasis.smallSets {p : ι → Prop} {s : ι → Set α} (h : HasBasis l p s) : HasBasis l.smallSets p fun i => 𝒫 s i := h.lift' monotone_powerset #align filter.has_basis.small_sets Filter.HasBasis.smallSets theorem hasBasis_smallSets (l : Filter α) : HasBasis l.smallSets (fun t : Set α => t ∈ l) powerset := l.basis_sets.smallSets #align filter.has_basis_small_sets Filter.hasBasis_smallSets /-- `g` converges to `f.smallSets` if for all `s ∈ f`, eventually we have `g x ⊆ s`. -/ theorem tendsto_smallSets_iff {f : α → Set β} : Tendsto f la lb.smallSets ↔ ∀ t ∈ lb, ∀ᶠ x in la, f x ⊆ t := (hasBasis_smallSets lb).tendsto_right_iff #align filter.tendsto_small_sets_iff Filter.tendsto_smallSets_iff theorem eventually_smallSets {p : Set α → Prop} : (∀ᶠ s in l.smallSets, p s) ↔ ∃ s ∈ l, ∀ t, t ⊆ s → p t := eventually_lift'_iff monotone_powerset #align filter.eventually_small_sets Filter.eventually_smallSets theorem eventually_smallSets' {p : Set α → Prop} (hp : ∀ ⦃s t⦄, s ⊆ t → p t → p s) : (∀ᶠ s in l.smallSets, p s) ↔ ∃ s ∈ l, p s := eventually_smallSets.trans <| exists_congr fun s => Iff.rfl.and ⟨fun H => H s Subset.rfl, fun hs _t ht => hp ht hs⟩ #align filter.eventually_small_sets' Filter.eventually_smallSets' theorem frequently_smallSets {p : Set α → Prop} : (∃ᶠ s in l.smallSets, p s) ↔ ∀ t ∈ l, ∃ s, s ⊆ t ∧ p s := l.hasBasis_smallSets.frequently_iff #align filter.frequently_small_sets Filter.frequently_smallSets theorem frequently_smallSets_mem (l : Filter α) : ∃ᶠ s in l.smallSets, s ∈ l := frequently_smallSets.2 fun t ht => ⟨t, Subset.rfl, ht⟩ #align filter.frequently_small_sets_mem Filter.frequently_smallSets_mem @[simp] lemma tendsto_image_smallSets {f : α → β} : Tendsto (f '' ·) la.smallSets lb.smallSets ↔ Tendsto f la lb := by rw [tendsto_smallSets_iff] refine forall₂_congr fun u hu ↦ ?_ rw [eventually_smallSets' fun s t hst ht ↦ (image_subset _ hst).trans ht] simp only [image_subset_iff, exists_mem_subset_iff, mem_map] alias ⟨_, Tendsto.image_smallSets⟩ := tendsto_image_smallSets theorem HasAntitoneBasis.tendsto_smallSets {ι} [Preorder ι] {s : ι → Set α} (hl : l.HasAntitoneBasis s) : Tendsto s atTop l.smallSets := tendsto_smallSets_iff.2 fun _t ht => hl.eventually_subset ht #align filter.has_antitone_basis.tendsto_small_sets Filter.HasAntitoneBasis.tendsto_smallSets @[mono] theorem monotone_smallSets : Monotone (@smallSets α) := monotone_lift' monotone_id monotone_const #align filter.monotone_small_sets Filter.monotone_smallSets @[simp] theorem smallSets_bot : (⊥ : Filter α).smallSets = pure ∅ := by rw [smallSets, lift'_bot, powerset_empty, principal_singleton] exact monotone_powerset #align filter.small_sets_bot Filter.smallSets_bot @[simp] theorem smallSets_top : (⊤ : Filter α).smallSets = ⊤ := by rw [smallSets, lift'_top, powerset_univ, principal_univ] #align filter.small_sets_top Filter.smallSets_top @[simp] theorem smallSets_principal (s : Set α) : (𝓟 s).smallSets = 𝓟 (𝒫 s) := lift'_principal monotone_powerset #align filter.small_sets_principal Filter.smallSets_principal
Mathlib/Order/Filter/SmallSets.lean
125
128
theorem smallSets_comap_eq_comap_image (l : Filter β) (f : α → β) : (comap f l).smallSets = comap (image f) l.smallSets := by
refine (gc_map_comap _).u_comm_of_l_comm (gc_map_comap _) bind_smallSets_gc bind_smallSets_gc ?_ simp [Function.comp, map_bind, bind_map]
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl, Sander Dahmen, Scott Morrison -/ import Mathlib.Algebra.Module.Torsion import Mathlib.SetTheory.Cardinal.Cofinality import Mathlib.LinearAlgebra.FreeModule.Finite.Basic import Mathlib.LinearAlgebra.Dimension.StrongRankCondition #align_import linear_algebra.dimension from "leanprover-community/mathlib"@"47a5f8186becdbc826190ced4312f8199f9db6a5" /-! # Conditions for rank to be finite Also contains characterization for when rank equals zero or rank equals one. -/ noncomputable section universe u v v' w variable {R : Type u} {M M₁ : Type v} {M' : Type v'} {ι : Type w} variable [Ring R] [AddCommGroup M] [AddCommGroup M'] [AddCommGroup M₁] variable [Module R M] [Module R M'] [Module R M₁] attribute [local instance] nontrivial_of_invariantBasisNumber open Cardinal Basis Submodule Function Set FiniteDimensional
Mathlib/LinearAlgebra/Dimension/Finite.lean
34
40
theorem rank_le {n : ℕ} (H : ∀ s : Finset M, (LinearIndependent R fun i : s => (i : M)) → s.card ≤ n) : Module.rank R M ≤ n := by
rw [Module.rank_def] apply ciSup_le' rintro ⟨s, li⟩ exact linearIndependent_bounded_of_finset_linearIndependent_bounded H _ li
/- Copyright (c) 2022 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Order.Antichain import Mathlib.Order.UpperLower.Basic import Mathlib.Order.Interval.Set.Basic import Mathlib.Order.RelIso.Set #align_import order.minimal from "leanprover-community/mathlib"@"59694bd07f0a39c5beccba34bd9f413a160782bf" /-! # Minimal/maximal elements of a set This file defines minimal and maximal of a set with respect to an arbitrary relation. ## Main declarations * `maximals r s`: Maximal elements of `s` with respect to `r`. * `minimals r s`: Minimal elements of `s` with respect to `r`. ## TODO Do we need a `Finset` version? -/ open Function Set variable {α : Type*} (r r₁ r₂ : α → α → Prop) (s t : Set α) (a b : α) /-- Turns a set into an antichain by keeping only the "maximal" elements. -/ def maximals : Set α := { a ∈ s | ∀ ⦃b⦄, b ∈ s → r a b → r b a } #align maximals maximals /-- Turns a set into an antichain by keeping only the "minimal" elements. -/ def minimals : Set α := { a ∈ s | ∀ ⦃b⦄, b ∈ s → r b a → r a b } #align minimals minimals theorem maximals_subset : maximals r s ⊆ s := sep_subset _ _ #align maximals_subset maximals_subset theorem minimals_subset : minimals r s ⊆ s := sep_subset _ _ #align minimals_subset minimals_subset @[simp] theorem maximals_empty : maximals r ∅ = ∅ := sep_empty _ #align maximals_empty maximals_empty @[simp] theorem minimals_empty : minimals r ∅ = ∅ := sep_empty _ #align minimals_empty minimals_empty @[simp] theorem maximals_singleton : maximals r {a} = {a} := (maximals_subset _ _).antisymm <| singleton_subset_iff.2 <| ⟨rfl, by rintro b (rfl : b = a) exact id⟩ #align maximals_singleton maximals_singleton @[simp] theorem minimals_singleton : minimals r {a} = {a} := maximals_singleton _ _ #align minimals_singleton minimals_singleton theorem maximals_swap : maximals (swap r) s = minimals r s := rfl #align maximals_swap maximals_swap theorem minimals_swap : minimals (swap r) s = maximals r s := rfl #align minimals_swap minimals_swap section IsAntisymm variable {r s t a b} [IsAntisymm α r] theorem eq_of_mem_maximals (ha : a ∈ maximals r s) (hb : b ∈ s) (h : r a b) : a = b := antisymm h <| ha.2 hb h #align eq_of_mem_maximals eq_of_mem_maximals theorem eq_of_mem_minimals (ha : a ∈ minimals r s) (hb : b ∈ s) (h : r b a) : a = b := antisymm (ha.2 hb h) h #align eq_of_mem_minimals eq_of_mem_minimals set_option autoImplicit true theorem mem_maximals_iff : x ∈ maximals r s ↔ x ∈ s ∧ ∀ ⦃y⦄, y ∈ s → r x y → x = y := by simp only [maximals, Set.mem_sep_iff, and_congr_right_iff] refine fun _ ↦ ⟨fun h y hys hxy ↦ antisymm hxy (h hys hxy), fun h y hys hxy ↦ ?_⟩ convert hxy <;> rw [h hys hxy] theorem mem_maximals_setOf_iff : x ∈ maximals r (setOf P) ↔ P x ∧ ∀ ⦃y⦄, P y → r x y → x = y := mem_maximals_iff theorem mem_minimals_iff : x ∈ minimals r s ↔ x ∈ s ∧ ∀ ⦃y⦄, y ∈ s → r y x → x = y := @mem_maximals_iff _ _ _ (IsAntisymm.swap r) _ theorem mem_minimals_setOf_iff : x ∈ minimals r (setOf P) ↔ P x ∧ ∀ ⦃y⦄, P y → r y x → x = y := mem_minimals_iff /-- This theorem can't be used to rewrite without specifying `rlt`, since `rlt` would have to be guessed. See `mem_minimals_iff_forall_ssubset_not_mem` and `mem_minimals_iff_forall_lt_not_mem` for `⊆` and `≤` versions. -/ theorem mem_minimals_iff_forall_lt_not_mem' (rlt : α → α → Prop) [IsNonstrictStrictOrder α r rlt] : x ∈ minimals r s ↔ x ∈ s ∧ ∀ ⦃y⦄, rlt y x → y ∉ s := by simp [minimals, right_iff_left_not_left_of r rlt, not_imp_not, imp.swap (a := _ ∈ _)] theorem mem_maximals_iff_forall_lt_not_mem' (rlt : α → α → Prop) [IsNonstrictStrictOrder α r rlt] : x ∈ maximals r s ↔ x ∈ s ∧ ∀ ⦃y⦄, rlt x y → y ∉ s := by simp [maximals, right_iff_left_not_left_of r rlt, not_imp_not, imp.swap (a := _ ∈ _)] theorem minimals_eq_minimals_of_subset_of_forall [IsTrans α r] (hts : t ⊆ s) (h : ∀ x ∈ s, ∃ y ∈ t, r y x) : minimals r s = minimals r t := by refine Set.ext fun a ↦ ⟨fun ⟨has, hmin⟩ ↦ ⟨?_,fun b hbt ↦ hmin (hts hbt)⟩, fun ⟨hat, hmin⟩ ↦ ⟨hts hat, fun b hbs hba ↦ ?_⟩⟩ · obtain ⟨a', ha', haa'⟩ := h _ has rwa [antisymm (hmin (hts ha') haa') haa'] obtain ⟨b', hb't, hb'b⟩ := h b hbs rwa [antisymm (hmin hb't (Trans.trans hb'b hba)) (Trans.trans hb'b hba)] theorem maximals_eq_maximals_of_subset_of_forall [IsTrans α r] (hts : t ⊆ s) (h : ∀ x ∈ s, ∃ y ∈ t, r x y) : maximals r s = maximals r t := @minimals_eq_minimals_of_subset_of_forall _ _ _ _ (IsAntisymm.swap r) (IsTrans.swap r) hts h variable (r s) theorem maximals_antichain : IsAntichain r (maximals r s) := fun _a ha _b hb hab h => hab <| eq_of_mem_maximals ha hb.1 h #align maximals_antichain maximals_antichain theorem minimals_antichain : IsAntichain r (minimals r s) := haveI := IsAntisymm.swap r (maximals_antichain _ _).swap #align minimals_antichain minimals_antichain end IsAntisymm set_option autoImplicit true theorem mem_minimals_iff_forall_ssubset_not_mem (s : Set (Set α)) : x ∈ minimals (· ⊆ ·) s ↔ x ∈ s ∧ ∀ ⦃y⦄, y ⊂ x → y ∉ s := mem_minimals_iff_forall_lt_not_mem' (· ⊂ ·) theorem mem_minimals_iff_forall_lt_not_mem [PartialOrder α] {s : Set α} : x ∈ minimals (· ≤ ·) s ↔ x ∈ s ∧ ∀ ⦃y⦄, y < x → y ∉ s := mem_minimals_iff_forall_lt_not_mem' (· < ·) theorem mem_maximals_iff_forall_ssubset_not_mem {s : Set (Set α)} : x ∈ maximals (· ⊆ ·) s ↔ x ∈ s ∧ ∀ ⦃y⦄, x ⊂ y → y ∉ s := mem_maximals_iff_forall_lt_not_mem' (· ⊂ ·) theorem mem_maximals_iff_forall_lt_not_mem [PartialOrder α] {s : Set α} : x ∈ maximals (· ≤ ·) s ↔ x ∈ s ∧ ∀ ⦃y⦄, x < y → y ∉ s := mem_maximals_iff_forall_lt_not_mem' (· < ·) -- Porting note (#10756): new theorem theorem maximals_of_symm [IsSymm α r] : maximals r s = s := sep_eq_self_iff_mem_true.2 fun _ _ _ _ => symm -- Porting note (#10756): new theorem theorem minimals_of_symm [IsSymm α r] : minimals r s = s := sep_eq_self_iff_mem_true.2 fun _ _ _ _ => symm theorem maximals_eq_minimals [IsSymm α r] : maximals r s = minimals r s := by rw [minimals_of_symm, maximals_of_symm] #align maximals_eq_minimals maximals_eq_minimals variable {r r₁ r₂ s t a} -- Porting note (#11215): TODO: use `h.induction_on` theorem Set.Subsingleton.maximals_eq (h : s.Subsingleton) : maximals r s = s := by rcases h.eq_empty_or_singleton with (rfl | ⟨x, rfl⟩) exacts [minimals_empty _, maximals_singleton _ _] #align set.subsingleton.maximals_eq Set.Subsingleton.maximals_eq theorem Set.Subsingleton.minimals_eq (h : s.Subsingleton) : minimals r s = s := h.maximals_eq #align set.subsingleton.minimals_eq Set.Subsingleton.minimals_eq theorem maximals_mono [IsAntisymm α r₂] (h : ∀ a b, r₁ a b → r₂ a b) : maximals r₂ s ⊆ maximals r₁ s := fun a ha => ⟨ha.1, fun b hb hab => by have := eq_of_mem_maximals ha hb (h _ _ hab) subst this exact hab⟩ #align maximals_mono maximals_mono theorem minimals_mono [IsAntisymm α r₂] (h : ∀ a b, r₁ a b → r₂ a b) : minimals r₂ s ⊆ minimals r₁ s := fun a ha => ⟨ha.1, fun b hb hab => by have := eq_of_mem_minimals ha hb (h _ _ hab) subst this exact hab⟩ #align minimals_mono minimals_mono theorem maximals_union : maximals r (s ∪ t) ⊆ maximals r s ∪ maximals r t := by intro a ha obtain h | h := ha.1 · exact Or.inl ⟨h, fun b hb => ha.2 <| Or.inl hb⟩ · exact Or.inr ⟨h, fun b hb => ha.2 <| Or.inr hb⟩ #align maximals_union maximals_union theorem minimals_union : minimals r (s ∪ t) ⊆ minimals r s ∪ minimals r t := maximals_union #align minimals_union minimals_union theorem maximals_inter_subset : maximals r s ∩ t ⊆ maximals r (s ∩ t) := fun _a ha => ⟨⟨ha.1.1, ha.2⟩, fun _b hb => ha.1.2 hb.1⟩ #align maximals_inter_subset maximals_inter_subset theorem minimals_inter_subset : minimals r s ∩ t ⊆ minimals r (s ∩ t) := maximals_inter_subset #align minimals_inter_subset minimals_inter_subset theorem inter_maximals_subset : s ∩ maximals r t ⊆ maximals r (s ∩ t) := fun _a ha => ⟨⟨ha.1, ha.2.1⟩, fun _b hb => ha.2.2 hb.2⟩ #align inter_maximals_subset inter_maximals_subset theorem inter_minimals_subset : s ∩ minimals r t ⊆ minimals r (s ∩ t) := inter_maximals_subset #align inter_minimals_subset inter_minimals_subset theorem IsAntichain.maximals_eq (h : IsAntichain r s) : maximals r s = s := (maximals_subset _ _).antisymm fun a ha => ⟨ha, fun b hb hab => by obtain rfl := h.eq ha hb hab exact hab⟩ #align is_antichain.maximals_eq IsAntichain.maximals_eq theorem IsAntichain.minimals_eq (h : IsAntichain r s) : minimals r s = s := h.flip.maximals_eq #align is_antichain.minimals_eq IsAntichain.minimals_eq @[simp] theorem maximals_idem : maximals r (maximals r s) = maximals r s := (maximals_subset _ _).antisymm fun _a ha => ⟨ha, fun _b hb => ha.2 hb.1⟩ #align maximals_idem maximals_idem @[simp] theorem minimals_idem : minimals r (minimals r s) = minimals r s := maximals_idem #align minimals_idem minimals_idem /-- If `maximals r s` is included in but *shadows* the antichain `t`, then it is actually equal to `t`. -/ theorem IsAntichain.max_maximals (ht : IsAntichain r t) (h : maximals r s ⊆ t) (hs : ∀ ⦃a⦄, a ∈ t → ∃ b ∈ maximals r s, r b a) : maximals r s = t := by refine h.antisymm fun a ha => ?_ obtain ⟨b, hb, hr⟩ := hs ha rwa [of_not_not fun hab => ht (h hb) ha (Ne.symm hab) hr] #align is_antichain.max_maximals IsAntichain.max_maximals /-- If `minimals r s` is included in but *shadows* the antichain `t`, then it is actually equal to `t`. -/ theorem IsAntichain.max_minimals (ht : IsAntichain r t) (h : minimals r s ⊆ t) (hs : ∀ ⦃a⦄, a ∈ t → ∃ b ∈ minimals r s, r a b) : minimals r s = t := by refine h.antisymm fun a ha => ?_ obtain ⟨b, hb, hr⟩ := hs ha rwa [of_not_not fun hab => ht ha (h hb) hab hr] #align is_antichain.max_minimals IsAntichain.max_minimals variable [PartialOrder α] theorem IsLeast.mem_minimals (h : IsLeast s a) : a ∈ minimals (· ≤ ·) s := ⟨h.1, fun _b hb _ => h.2 hb⟩ #align is_least.mem_minimals IsLeast.mem_minimals theorem IsGreatest.mem_maximals (h : IsGreatest s a) : a ∈ maximals (· ≤ ·) s := ⟨h.1, fun _b hb _ => h.2 hb⟩ #align is_greatest.mem_maximals IsGreatest.mem_maximals theorem IsLeast.minimals_eq (h : IsLeast s a) : minimals (· ≤ ·) s = {a} := eq_singleton_iff_unique_mem.2 ⟨h.mem_minimals, fun _b hb => eq_of_mem_minimals hb h.1 <| h.2 hb.1⟩ #align is_least.minimals_eq IsLeast.minimals_eq theorem IsGreatest.maximals_eq (h : IsGreatest s a) : maximals (· ≤ ·) s = {a} := eq_singleton_iff_unique_mem.2 ⟨h.mem_maximals, fun _b hb => eq_of_mem_maximals hb h.1 <| h.2 hb.1⟩ #align is_greatest.maximals_eq IsGreatest.maximals_eq theorem IsAntichain.minimals_upperClosure (hs : IsAntichain (· ≤ ·) s) : minimals (· ≤ ·) (upperClosure s : Set α) = s := hs.max_minimals (fun a ⟨⟨b, hb, hba⟩, _⟩ => by rwa [eq_of_mem_minimals ‹a ∈ _› (subset_upperClosure hb) hba]) fun a ha => ⟨a, ⟨subset_upperClosure ha, fun b ⟨c, hc, hcb⟩ hba => by rwa [hs.eq' ha hc (hcb.trans hba)]⟩, le_rfl⟩ #align is_antichain.minimals_upper_closure IsAntichain.minimals_upperClosure theorem IsAntichain.maximals_lowerClosure (hs : IsAntichain (· ≤ ·) s) : maximals (· ≤ ·) (lowerClosure s : Set α) = s := hs.to_dual.minimals_upperClosure #align is_antichain.maximals_lower_closure IsAntichain.maximals_lowerClosure section Image variable {f : α → β} {r : α → α → Prop} {s : β → β → Prop} section variable {x : Set α} (hf : ∀ ⦃a a'⦄, a ∈ x → a' ∈ x → (r a a' ↔ s (f a) (f a'))) {a : α} theorem map_mem_minimals (ha : a ∈ minimals r x) : f a ∈ minimals s (f '' x) := ⟨⟨a, ha.1, rfl⟩, by rintro _ ⟨a', h', rfl⟩; rw [← hf ha.1 h', ← hf h' ha.1]; exact ha.2 h'⟩ theorem map_mem_maximals (ha : a ∈ maximals r x) : f a ∈ maximals s (f '' x) := map_mem_minimals (fun _ _ h₁ h₂ ↦ by exact hf h₂ h₁) ha theorem map_mem_minimals_iff (ha : a ∈ x) : f a ∈ minimals s (f '' x) ↔ a ∈ minimals r x := ⟨fun ⟨_, hmin⟩ ↦ ⟨ha, fun a' h' ↦ by simpa only [hf h' ha, hf ha h'] using hmin ⟨a', h', rfl⟩⟩, map_mem_minimals hf⟩ theorem map_mem_maximals_iff (ha : a ∈ x) : f a ∈ maximals s (f '' x) ↔ a ∈ maximals r x := map_mem_minimals_iff (fun _ _ h₁ h₂ ↦ by exact hf h₂ h₁) ha theorem image_minimals_of_rel_iff_rel : f '' minimals r x = minimals s (f '' x) := by ext b; refine ⟨?_, fun h ↦ ?_⟩ · rintro ⟨a, ha, rfl⟩; exact map_mem_minimals hf ha · obtain ⟨a, ha, rfl⟩ := h.1; exact ⟨a, (map_mem_minimals_iff hf ha).mp h, rfl⟩ theorem image_maximals_of_rel_iff_rel : f '' maximals r x = maximals s (f '' x) := image_minimals_of_rel_iff_rel fun _ _ h₁ h₂ ↦ hf h₂ h₁ end theorem RelEmbedding.image_minimals_eq (f : r ↪r s) (x : Set α) : f '' minimals r x = minimals s (f '' x) := by rw [image_minimals_of_rel_iff_rel]; simp [f.map_rel_iff] theorem RelEmbedding.image_maximals_eq (f : r ↪r s) (x : Set α) : f '' maximals r x = maximals s (f '' x) := f.swap.image_minimals_eq x section variable [LE α] [LE β] {s : Set α} {t : Set β} theorem image_minimals_univ : Subtype.val '' minimals (· ≤ ·) (univ : Set s) = minimals (· ≤ ·) s := by rw [image_minimals_of_rel_iff_rel, image_univ, Subtype.range_val]; intros; rfl theorem image_maximals_univ : Subtype.val '' maximals (· ≤ ·) (univ : Set s) = maximals (· ≤ ·) s := image_minimals_univ (α := αᵒᵈ) nonrec theorem OrderIso.map_mem_minimals (f : s ≃o t) {x : α} (hx : x ∈ minimals (· ≤ ·) s) : (f ⟨x, hx.1⟩).val ∈ minimals (· ≤ ·) t := by rw [← image_minimals_univ] at hx obtain ⟨x, h, rfl⟩ := hx convert map_mem_minimals (f := Subtype.val ∘ f) (fun _ _ _ _ ↦ f.map_rel_iff.symm) h rw [image_comp, image_univ, f.range_eq, image_univ, Subtype.range_val] theorem OrderIso.map_mem_maximals (f : s ≃o t) {x : α} (hx : x ∈ maximals (· ≤ ·) s) : (f ⟨x, hx.1⟩).val ∈ maximals (· ≤ ·) t := (show OrderDual.ofDual ⁻¹' s ≃o OrderDual.ofDual ⁻¹' t from f.dual).map_mem_minimals hx /-- If two sets are order isomorphic, their minimals are also order isomorphic. -/ def OrderIso.mapMinimals (f : s ≃o t) : minimals (· ≤ ·) s ≃o minimals (· ≤ ·) t where toFun x := ⟨f ⟨x, x.2.1⟩, f.map_mem_minimals x.2⟩ invFun x := ⟨f.symm ⟨x, x.2.1⟩, f.symm.map_mem_minimals x.2⟩ left_inv x := Subtype.ext (by apply congr_arg Subtype.val <| f.left_inv ⟨x, x.2.1⟩) right_inv x := Subtype.ext (by apply congr_arg Subtype.val <| f.right_inv ⟨x, x.2.1⟩) map_rel_iff' {_ _} := f.map_rel_iff /-- If two sets are order isomorphic, their maximals are also order isomorphic. -/ def OrderIso.mapMaximals (f : s ≃o t) : maximals (· ≤ ·) s ≃o maximals (· ≤ ·) t where toFun x := ⟨f ⟨x, x.2.1⟩, f.map_mem_maximals x.2⟩ invFun x := ⟨f.symm ⟨x, x.2.1⟩, f.symm.map_mem_maximals x.2⟩ __ := (show OrderDual.ofDual ⁻¹' s ≃o OrderDual.ofDual ⁻¹' t from f.dual).mapMinimals -- defeq abuse to fill in the proof fields. -- If OrderDual ever becomes a structure, just copy the last three lines from OrderIso.mapMinimals open OrderDual in /-- If two sets are antitonically order isomorphic, their minimals are too. -/ def OrderIso.minimalsIsoMaximals (f : s ≃o tᵒᵈ) : minimals (· ≤ ·) s ≃o (maximals (· ≤ ·) t)ᵒᵈ where toFun x := toDual ⟨↑(ofDual (f ⟨x, x.2.1⟩)), (show s ≃o ofDual ⁻¹' t from f).map_mem_minimals x.2⟩ invFun x := ⟨f.symm (toDual ⟨_, (ofDual x).2.1⟩), (show ofDual ⁻¹' t ≃o s from f.symm).map_mem_minimals x.2⟩ __ := (show s ≃o ofDual⁻¹' t from f).mapMinimals open OrderDual in /-- If two sets are antitonically order isomorphic, their minimals are too. -/ def OrderIso.maximalsIsoMinimals (f : s ≃o tᵒᵈ) : maximals (· ≤ ·) s ≃o (minimals (· ≤ ·) t)ᵒᵈ where toFun x := toDual ⟨↑(ofDual (f ⟨x, x.2.1⟩)), (show s ≃o ofDual ⁻¹' t from f).map_mem_maximals x.2⟩ invFun x := ⟨f.symm (toDual ⟨_, (ofDual x).2.1⟩), (show ofDual ⁻¹' t ≃o s from f.symm).map_mem_maximals x.2⟩ __ := (show s ≃o ofDual⁻¹' t from f).mapMaximals end theorem inter_minimals_preimage_inter_eq_of_rel_iff_rel_on (hf : ∀ ⦃a a'⦄, a ∈ x → a' ∈ x → (r a a' ↔ s (f a) (f a'))) (y : Set β) : x ∩ f ⁻¹' (minimals s ((f '' x) ∩ y)) = minimals r (x ∩ f ⁻¹' y) := by ext a simp only [minimals, mem_inter_iff, mem_image, and_imp, forall_exists_index, forall_apply_eq_imp_iff₂, preimage_setOf_eq, mem_setOf_eq, mem_preimage] exact ⟨fun ⟨hax,⟨_,hay⟩,h2⟩ ↦ ⟨⟨hax, hay⟩, fun a₁ ha₁ ha₁y ha₁a ↦ (hf hax ha₁).mpr (h2 _ ha₁ ha₁y ((hf ha₁ hax).mp ha₁a))⟩ , fun ⟨⟨hax,hay⟩,h⟩ ↦ ⟨hax, ⟨⟨_, hax, rfl⟩, hay⟩, fun a' ha' ha'y hsa' ↦ (hf hax ha').mp (h ha' ha'y ((hf ha' hax).mpr hsa'))⟩⟩ theorem inter_preimage_minimals_eq_of_rel_iff_rel_on_of_subset (hf : ∀ ⦃a a'⦄, a ∈ x → a' ∈ x → (r a a' ↔ s (f a) (f a'))) (hy : y ⊆ f '' x) : x ∩ f ⁻¹' (minimals s y) = minimals r (x ∩ f ⁻¹' y) := by rw [← inter_eq_self_of_subset_right hy, inter_minimals_preimage_inter_eq_of_rel_iff_rel_on hf, preimage_inter, ← inter_assoc, inter_eq_self_of_subset_left (subset_preimage_image f x)] theorem RelEmbedding.inter_preimage_minimals_eq (f : r ↪r s) (x : Set α) (y : Set β) : x ∩ f⁻¹' (minimals s ((f '' x) ∩ y)) = minimals r (x ∩ f ⁻¹' y) := inter_minimals_preimage_inter_eq_of_rel_iff_rel_on (by simp [f.map_rel_iff]) y theorem RelEmbedding.inter_preimage_minimals_eq_of_subset (f : r ↪r s) (h : y ⊆ f '' x) : x ∩ f ⁻¹' (minimals s y) = minimals r (x ∩ f ⁻¹' y) := by rw [inter_preimage_minimals_eq_of_rel_iff_rel_on_of_subset _ h]; simp [f.map_rel_iff] theorem RelEmbedding.minimals_preimage_eq (f : r ↪r s) (y : Set β) : minimals r (f ⁻¹' y) = f ⁻¹' minimals s (y ∩ range f) := by convert (f.inter_preimage_minimals_eq univ y).symm · simp [univ_inter] · simp [inter_comm] theorem RelIso.minimals_preimage_eq (f : r ≃r s) (y : Set β) : minimals r (f ⁻¹' y) = f ⁻¹' (minimals s y) := by convert f.toRelEmbedding.minimals_preimage_eq y; simp theorem RelIso.maximals_preimage_eq (f : r ≃r s) (y : Set β) : maximals r (f ⁻¹' y) = f ⁻¹' (maximals s y) := f.swap.minimals_preimage_eq y theorem inter_maximals_preimage_inter_eq_of_rel_iff_rel_on (hf : ∀ ⦃a a'⦄, a ∈ x → a' ∈ x → (r a a' ↔ s (f a) (f a'))) (y : Set β) : x ∩ f ⁻¹' (maximals s ((f '' x) ∩ y)) = maximals r (x ∩ f ⁻¹' y) := by apply inter_minimals_preimage_inter_eq_of_rel_iff_rel_on exact fun _ _ a b ↦ hf b a
Mathlib/Order/Minimal.lean
445
449
theorem inter_preimage_maximals_eq_of_rel_iff_rel_on_of_subset (hf : ∀ ⦃a a'⦄, a ∈ x → a' ∈ x → (r a a' ↔ s (f a) (f a'))) (hy : y ⊆ f '' x) : x ∩ f ⁻¹' (maximals s y) = maximals r (x ∩ f ⁻¹' y) := by
apply inter_preimage_minimals_eq_of_rel_iff_rel_on_of_subset _ hy exact fun _ _ a b ↦ hf b a
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Johan Commelin, Patrick Massot -/ import Mathlib.Algebra.Order.Group.Basic import Mathlib.Algebra.Order.Ring.Basic import Mathlib.RingTheory.Ideal.Maps import Mathlib.Tactic.TFAE #align_import ring_theory.valuation.basic from "leanprover-community/mathlib"@"2196ab363eb097c008d4497125e0dde23fb36db2" /-! # The basics of valuation theory. The basic theory of valuations (non-archimedean norms) on a commutative ring, following T. Wedhorn's unpublished notes “Adic Spaces” ([wedhorn_adic]). The definition of a valuation we use here is Definition 1.22 of [wedhorn_adic]. A valuation on a ring `R` is a monoid homomorphism `v` to a linearly ordered commutative monoid with zero, that in addition satisfies the following two axioms: * `v 0 = 0` * `∀ x y, v (x + y) ≤ max (v x) (v y)` `Valuation R Γ₀`is the type of valuations `R → Γ₀`, with a coercion to the underlying function. If `v` is a valuation from `R` to `Γ₀` then the induced group homomorphism `units(R) → Γ₀` is called `unit_map v`. The equivalence "relation" `IsEquiv v₁ v₂ : Prop` defined in 1.27 of [wedhorn_adic] is not strictly speaking a relation, because `v₁ : Valuation R Γ₁` and `v₂ : Valuation R Γ₂` might not have the same type. This corresponds in ZFC to the set-theoretic difficulty that the class of all valuations (as `Γ₀` varies) on a ring `R` is not a set. The "relation" is however reflexive, symmetric and transitive in the obvious sense. Note that we use 1.27(iii) of [wedhorn_adic] as the definition of equivalence. ## Main definitions * `Valuation R Γ₀`, the type of valuations on `R` with values in `Γ₀` * `Valuation.IsEquiv`, the heterogeneous equivalence relation on valuations * `Valuation.supp`, the support of a valuation * `AddValuation R Γ₀`, the type of additive valuations on `R` with values in a linearly ordered additive commutative group with a top element, `Γ₀`. ## Implementation Details `AddValuation R Γ₀` is implemented as `Valuation R (Multiplicative Γ₀)ᵒᵈ`. ## Notation In the `DiscreteValuation` locale: * `ℕₘ₀` is a shorthand for `WithZero (Multiplicative ℕ)` * `ℤₘ₀` is a shorthand for `WithZero (Multiplicative ℤ)` ## TODO If ever someone extends `Valuation`, we should fully comply to the `DFunLike` by migrating the boilerplate lemmas to `ValuationClass`. -/ open scoped Classical open Function Ideal noncomputable section variable {K F R : Type*} [DivisionRing K] section variable (F R) (Γ₀ : Type*) [LinearOrderedCommMonoidWithZero Γ₀] [Ring R] --porting note (#5171): removed @[nolint has_nonempty_instance] /-- The type of `Γ₀`-valued valuations on `R`. When you extend this structure, make sure to extend `ValuationClass`. -/ structure Valuation extends R →*₀ Γ₀ where /-- The valuation of a a sum is less that the sum of the valuations -/ map_add_le_max' : ∀ x y, toFun (x + y) ≤ max (toFun x) (toFun y) #align valuation Valuation /-- `ValuationClass F α β` states that `F` is a type of valuations. You should also extend this typeclass when you extend `Valuation`. -/ class ValuationClass (F) (R Γ₀ : outParam Type*) [LinearOrderedCommMonoidWithZero Γ₀] [Ring R] [FunLike F R Γ₀] extends MonoidWithZeroHomClass F R Γ₀ : Prop where /-- The valuation of a a sum is less that the sum of the valuations -/ map_add_le_max (f : F) (x y : R) : f (x + y) ≤ max (f x) (f y) #align valuation_class ValuationClass export ValuationClass (map_add_le_max) instance [FunLike F R Γ₀] [ValuationClass F R Γ₀] : CoeTC F (Valuation R Γ₀) := ⟨fun f => { toFun := f map_one' := map_one f map_zero' := map_zero f map_mul' := map_mul f map_add_le_max' := map_add_le_max f }⟩ end namespace Valuation variable {Γ₀ : Type*} variable {Γ'₀ : Type*} variable {Γ''₀ : Type*} [LinearOrderedCommMonoidWithZero Γ''₀] section Basic variable [Ring R] section Monoid variable [LinearOrderedCommMonoidWithZero Γ₀] [LinearOrderedCommMonoidWithZero Γ'₀] instance : FunLike (Valuation R Γ₀) R Γ₀ where coe f := f.toFun coe_injective' f g h := by obtain ⟨⟨⟨_,_⟩, _⟩, _⟩ := f congr instance : ValuationClass (Valuation R Γ₀) R Γ₀ where map_mul f := f.map_mul' map_one f := f.map_one' map_zero f := f.map_zero' map_add_le_max f := f.map_add_le_max' @[simp] theorem coe_mk (f : R →*₀ Γ₀) (h) : ⇑(Valuation.mk f h) = f := rfl theorem toFun_eq_coe (v : Valuation R Γ₀) : v.toFun = v := rfl #align valuation.to_fun_eq_coe Valuation.toFun_eq_coe @[simp] -- Porting note: requested by simpNF as toFun_eq_coe LHS simplifies theorem toMonoidWithZeroHom_coe_eq_coe (v : Valuation R Γ₀) : (v.toMonoidWithZeroHom : R → Γ₀) = v := rfl @[ext] theorem ext {v₁ v₂ : Valuation R Γ₀} (h : ∀ r, v₁ r = v₂ r) : v₁ = v₂ := DFunLike.ext _ _ h #align valuation.ext Valuation.ext variable (v : Valuation R Γ₀) {x y z : R} @[simp, norm_cast] theorem coe_coe : ⇑(v : R →*₀ Γ₀) = v := rfl #align valuation.coe_coe Valuation.coe_coe -- @[simp] Porting note (#10618): simp can prove this theorem map_zero : v 0 = 0 := v.map_zero' #align valuation.map_zero Valuation.map_zero -- @[simp] Porting note (#10618): simp can prove this theorem map_one : v 1 = 1 := v.map_one' #align valuation.map_one Valuation.map_one -- @[simp] Porting note (#10618): simp can prove this theorem map_mul : ∀ x y, v (x * y) = v x * v y := v.map_mul' #align valuation.map_mul Valuation.map_mul -- Porting note: LHS side simplified so created map_add' theorem map_add : ∀ x y, v (x + y) ≤ max (v x) (v y) := v.map_add_le_max' #align valuation.map_add Valuation.map_add @[simp] theorem map_add' : ∀ x y, v (x + y) ≤ v x ∨ v (x + y) ≤ v y := by intro x y rw [← le_max_iff, ← ge_iff_le] apply map_add theorem map_add_le {x y g} (hx : v x ≤ g) (hy : v y ≤ g) : v (x + y) ≤ g := le_trans (v.map_add x y) <| max_le hx hy #align valuation.map_add_le Valuation.map_add_le theorem map_add_lt {x y g} (hx : v x < g) (hy : v y < g) : v (x + y) < g := lt_of_le_of_lt (v.map_add x y) <| max_lt hx hy #align valuation.map_add_lt Valuation.map_add_lt theorem map_sum_le {ι : Type*} {s : Finset ι} {f : ι → R} {g : Γ₀} (hf : ∀ i ∈ s, v (f i) ≤ g) : v (∑ i ∈ s, f i) ≤ g := by refine Finset.induction_on s (fun _ => v.map_zero ▸ zero_le') (fun a s has ih hf => ?_) hf rw [Finset.forall_mem_insert] at hf; rw [Finset.sum_insert has] exact v.map_add_le hf.1 (ih hf.2) #align valuation.map_sum_le Valuation.map_sum_le theorem map_sum_lt {ι : Type*} {s : Finset ι} {f : ι → R} {g : Γ₀} (hg : g ≠ 0) (hf : ∀ i ∈ s, v (f i) < g) : v (∑ i ∈ s, f i) < g := by refine Finset.induction_on s (fun _ => v.map_zero ▸ (zero_lt_iff.2 hg)) (fun a s has ih hf => ?_) hf rw [Finset.forall_mem_insert] at hf; rw [Finset.sum_insert has] exact v.map_add_lt hf.1 (ih hf.2) #align valuation.map_sum_lt Valuation.map_sum_lt theorem map_sum_lt' {ι : Type*} {s : Finset ι} {f : ι → R} {g : Γ₀} (hg : 0 < g) (hf : ∀ i ∈ s, v (f i) < g) : v (∑ i ∈ s, f i) < g := v.map_sum_lt (ne_of_gt hg) hf #align valuation.map_sum_lt' Valuation.map_sum_lt' -- @[simp] Porting note (#10618): simp can prove this theorem map_pow : ∀ (x) (n : ℕ), v (x ^ n) = v x ^ n := v.toMonoidWithZeroHom.toMonoidHom.map_pow #align valuation.map_pow Valuation.map_pow /-- Deprecated. Use `DFunLike.ext_iff`. -/ -- @[deprecated] Porting note: using `DFunLike.ext_iff` is not viable below for now theorem ext_iff {v₁ v₂ : Valuation R Γ₀} : v₁ = v₂ ↔ ∀ r, v₁ r = v₂ r := DFunLike.ext_iff #align valuation.ext_iff Valuation.ext_iff -- The following definition is not an instance, because we have more than one `v` on a given `R`. -- In addition, type class inference would not be able to infer `v`. /-- A valuation gives a preorder on the underlying ring. -/ def toPreorder : Preorder R := Preorder.lift v #align valuation.to_preorder Valuation.toPreorder /-- If `v` is a valuation on a division ring then `v(x) = 0` iff `x = 0`. -/ -- @[simp] Porting note (#10618): simp can prove this theorem zero_iff [Nontrivial Γ₀] (v : Valuation K Γ₀) {x : K} : v x = 0 ↔ x = 0 := map_eq_zero v #align valuation.zero_iff Valuation.zero_iff theorem ne_zero_iff [Nontrivial Γ₀] (v : Valuation K Γ₀) {x : K} : v x ≠ 0 ↔ x ≠ 0 := map_ne_zero v #align valuation.ne_zero_iff Valuation.ne_zero_iff theorem unit_map_eq (u : Rˣ) : (Units.map (v : R →* Γ₀) u : Γ₀) = v u := rfl #align valuation.unit_map_eq Valuation.unit_map_eq /-- A ring homomorphism `S → R` induces a map `Valuation R Γ₀ → Valuation S Γ₀`. -/ def comap {S : Type*} [Ring S] (f : S →+* R) (v : Valuation R Γ₀) : Valuation S Γ₀ := { v.toMonoidWithZeroHom.comp f.toMonoidWithZeroHom with toFun := v ∘ f map_add_le_max' := fun x y => by simp only [comp_apply, map_add, f.map_add] } #align valuation.comap Valuation.comap @[simp] theorem comap_apply {S : Type*} [Ring S] (f : S →+* R) (v : Valuation R Γ₀) (s : S) : v.comap f s = v (f s) := rfl #align valuation.comap_apply Valuation.comap_apply @[simp] theorem comap_id : v.comap (RingHom.id R) = v := ext fun _r => rfl #align valuation.comap_id Valuation.comap_id theorem comap_comp {S₁ : Type*} {S₂ : Type*} [Ring S₁] [Ring S₂] (f : S₁ →+* S₂) (g : S₂ →+* R) : v.comap (g.comp f) = (v.comap g).comap f := ext fun _r => rfl #align valuation.comap_comp Valuation.comap_comp /-- A `≤`-preserving group homomorphism `Γ₀ → Γ'₀` induces a map `Valuation R Γ₀ → Valuation R Γ'₀`. -/ def map (f : Γ₀ →*₀ Γ'₀) (hf : Monotone f) (v : Valuation R Γ₀) : Valuation R Γ'₀ := { MonoidWithZeroHom.comp f v.toMonoidWithZeroHom with toFun := f ∘ v map_add_le_max' := fun r s => calc f (v (r + s)) ≤ f (max (v r) (v s)) := hf (v.map_add r s) _ = max (f (v r)) (f (v s)) := hf.map_max } #align valuation.map Valuation.map /-- Two valuations on `R` are defined to be equivalent if they induce the same preorder on `R`. -/ def IsEquiv (v₁ : Valuation R Γ₀) (v₂ : Valuation R Γ'₀) : Prop := ∀ r s, v₁ r ≤ v₁ s ↔ v₂ r ≤ v₂ s #align valuation.is_equiv Valuation.IsEquiv end Monoid section Group variable [LinearOrderedCommGroupWithZero Γ₀] (v : Valuation R Γ₀) {x y z : R} @[simp] theorem map_neg (x : R) : v (-x) = v x := v.toMonoidWithZeroHom.toMonoidHom.map_neg x #align valuation.map_neg Valuation.map_neg theorem map_sub_swap (x y : R) : v (x - y) = v (y - x) := v.toMonoidWithZeroHom.toMonoidHom.map_sub_swap x y #align valuation.map_sub_swap Valuation.map_sub_swap theorem map_sub (x y : R) : v (x - y) ≤ max (v x) (v y) := calc v (x - y) = v (x + -y) := by rw [sub_eq_add_neg] _ ≤ max (v x) (v <| -y) := v.map_add _ _ _ = max (v x) (v y) := by rw [map_neg] #align valuation.map_sub Valuation.map_sub theorem map_sub_le {x y g} (hx : v x ≤ g) (hy : v y ≤ g) : v (x - y) ≤ g := by rw [sub_eq_add_neg] exact v.map_add_le hx (le_trans (le_of_eq (v.map_neg y)) hy) #align valuation.map_sub_le Valuation.map_sub_le
Mathlib/RingTheory/Valuation/Basic.lean
308
320
theorem map_add_of_distinct_val (h : v x ≠ v y) : v (x + y) = max (v x) (v y) := by
suffices ¬v (x + y) < max (v x) (v y) from or_iff_not_imp_right.1 (le_iff_eq_or_lt.1 (v.map_add x y)) this intro h' wlog vyx : v y < v x generalizing x y · refine this h.symm ?_ (h.lt_or_lt.resolve_right vyx) rwa [add_comm, max_comm] rw [max_eq_left_of_lt vyx] at h' apply lt_irrefl (v x) calc v x = v (x + y - y) := by simp _ ≤ max (v <| x + y) (v y) := map_sub _ _ _ _ < v x := max_lt h' vyx
/- Copyright (c) 2022 Benjamin Davidson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Benjamin Davidson, Devon Tuma, Eric Rodriguez, Oliver Nash -/ import Mathlib.Data.Set.Pointwise.Interval import Mathlib.Topology.Algebra.Field import Mathlib.Topology.Algebra.Order.Group #align_import topology.algebra.order.field from "leanprover-community/mathlib"@"9a59dcb7a2d06bf55da57b9030169219980660cd" /-! # Topologies on linear ordered fields In this file we prove that a linear ordered field with order topology has continuous multiplication and division (apart from zero in the denominator). We also prove theorems like `Filter.Tendsto.mul_atTop`: if `f` tends to a positive number and `g` tends to positive infinity, then `f * g` tends to positive infinity. -/ open Set Filter TopologicalSpace Function open scoped Pointwise Topology open OrderDual (toDual ofDual) /-- If a (possibly non-unital and/or non-associative) ring `R` admits a submultiplicative nonnegative norm `norm : R → 𝕜`, where `𝕜` is a linear ordered field, and the open balls `{ x | norm x < ε }`, `ε > 0`, form a basis of neighborhoods of zero, then `R` is a topological ring. -/
Mathlib/Topology/Algebra/Order/Field.lean
30
51
theorem TopologicalRing.of_norm {R 𝕜 : Type*} [NonUnitalNonAssocRing R] [LinearOrderedField 𝕜] [TopologicalSpace R] [TopologicalAddGroup R] (norm : R → 𝕜) (norm_nonneg : ∀ x, 0 ≤ norm x) (norm_mul_le : ∀ x y, norm (x * y) ≤ norm x * norm y) (nhds_basis : (𝓝 (0 : R)).HasBasis ((0 : 𝕜) < ·) (fun ε ↦ { x | norm x < ε })) : TopologicalRing R := by
have h0 : ∀ f : R → R, ∀ c ≥ (0 : 𝕜), (∀ x, norm (f x) ≤ c * norm x) → Tendsto f (𝓝 0) (𝓝 0) := by refine fun f c c0 hf ↦ (nhds_basis.tendsto_iff nhds_basis).2 fun ε ε0 ↦ ?_ rcases exists_pos_mul_lt ε0 c with ⟨δ, δ0, hδ⟩ refine ⟨δ, δ0, fun x hx ↦ (hf _).trans_lt ?_⟩ exact (mul_le_mul_of_nonneg_left (le_of_lt hx) c0).trans_lt hδ apply TopologicalRing.of_addGroup_of_nhds_zero case hmul => refine ((nhds_basis.prod nhds_basis).tendsto_iff nhds_basis).2 fun ε ε0 ↦ ?_ refine ⟨(1, ε), ⟨one_pos, ε0⟩, fun (x, y) ⟨hx, hy⟩ => ?_⟩ simp only [sub_zero] at * calc norm (x * y) ≤ norm x * norm y := norm_mul_le _ _ _ < ε := mul_lt_of_le_one_of_lt_of_nonneg hx.le hy (norm_nonneg _) case hmul_left => exact fun x => h0 _ (norm x) (norm_nonneg _) (norm_mul_le x) case hmul_right => exact fun y => h0 (· * y) (norm y) (norm_nonneg y) fun x => (norm_mul_le x y).trans_eq (mul_comm _ _)
/- Copyright (c) 2023 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.Analysis.Convolution import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup import Mathlib.Analysis.Analytic.IsolatedZeros import Mathlib.Analysis.Complex.CauchyIntegral #align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090" /-! # The Beta function, and further properties of the Gamma function In this file we define the Beta integral, relate Beta and Gamma functions, and prove some refined properties of the Gamma function using these relations. ## Results on the Beta function * `Complex.betaIntegral`: the Beta function `Β(u, v)`, where `u`, `v` are complex with positive real part. * `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula `Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`. ## Results on the Gamma function * `Complex.Gamma_ne_zero`: for all `s : ℂ` with `s ∉ {-n : n ∈ ℕ}` we have `Γ s ≠ 0`. * `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n → ∞` of the sequence `n ↦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Γ(s)`. * `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula `Gamma s * Gamma (1 - s) = π / sin π s`. * `Complex.differentiable_one_div_Gamma`: the function `1 / Γ(s)` is differentiable everywhere. * `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula `Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * √π`. * `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`, `Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above. -/ noncomputable section set_option linter.uppercaseLean3 false open Filter intervalIntegral Set Real MeasureTheory open scoped Nat Topology Real section BetaIntegral /-! ## The Beta function -/ namespace Complex /-- The Beta function `Β (u, v)`, defined as `∫ x:ℝ in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/ noncomputable def betaIntegral (u v : ℂ) : ℂ := ∫ x : ℝ in (0)..1, (x : ℂ) ^ (u - 1) * (1 - (x : ℂ)) ^ (v - 1) #align complex.beta_integral Complex.betaIntegral /-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/ theorem betaIntegral_convergent_left {u : ℂ} (hu : 0 < re u) (v : ℂ) : IntervalIntegrable (fun x => (x : ℂ) ^ (u - 1) * (1 - (x : ℂ)) ^ (v - 1) : ℝ → ℂ) volume 0 (1 / 2) := by apply IntervalIntegrable.mul_continuousOn · refine intervalIntegral.intervalIntegrable_cpow' ?_ rwa [sub_re, one_re, ← zero_sub, sub_lt_sub_iff_right] · apply ContinuousAt.continuousOn intro x hx rw [uIcc_of_le (by positivity : (0 : ℝ) ≤ 1 / 2)] at hx apply ContinuousAt.cpow · exact (continuous_const.sub continuous_ofReal).continuousAt · exact continuousAt_const · norm_cast exact ofReal_mem_slitPlane.2 <| by linarith only [hx.2] #align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left /-- The Beta integral is convergent for all `u, v` of positive real part. -/ theorem betaIntegral_convergent {u v : ℂ} (hu : 0 < re u) (hv : 0 < re v) : IntervalIntegrable (fun x => (x : ℂ) ^ (u - 1) * (1 - (x : ℂ)) ^ (v - 1) : ℝ → ℂ) volume 0 1 := by refine (betaIntegral_convergent_left hu v).trans ?_ rw [IntervalIntegrable.iff_comp_neg] convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1 · ext1 x conv_lhs => rw [mul_comm] congr 2 <;> · push_cast; ring · norm_num · norm_num #align complex.beta_integral_convergent Complex.betaIntegral_convergent theorem betaIntegral_symm (u v : ℂ) : betaIntegral v u = betaIntegral u v := by rw [betaIntegral, betaIntegral] have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1) (fun x : ℝ => (x : ℂ) ^ (u - 1) * (1 - (x : ℂ)) ^ (v - 1)) neg_one_lt_zero.ne 1 rw [inv_neg, inv_one, neg_one_smul, ← intervalIntegral.integral_symm] at this simp? at this says simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel_right, neg_neg, mul_one, add_left_neg, mul_zero, zero_add] at this conv_lhs at this => arg 1; intro x; rw [add_comm, ← sub_eq_add_neg, mul_comm] exact this #align complex.beta_integral_symm Complex.betaIntegral_symm theorem betaIntegral_eval_one_right {u : ℂ} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by simp_rw [betaIntegral, sub_self, cpow_zero, mul_one] rw [integral_cpow (Or.inl _)] · rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel] rw [sub_add_cancel] contrapose! hu; rw [hu, zero_re] · rwa [sub_re, one_re, ← sub_pos, sub_neg_eq_add, sub_add_cancel] #align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right theorem betaIntegral_scaled (s t : ℂ) {a : ℝ} (ha : 0 < a) : ∫ x in (0)..a, (x : ℂ) ^ (s - 1) * ((a : ℂ) - x) ^ (t - 1) = (a : ℂ) ^ (s + t - 1) * betaIntegral s t := by have ha' : (a : ℂ) ≠ 0 := ofReal_ne_zero.mpr ha.ne' rw [betaIntegral] have A : (a : ℂ) ^ (s + t - 1) = a * ((a : ℂ) ^ (s - 1) * (a : ℂ) ^ (t - 1)) := by rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one, mul_assoc] rw [A, mul_assoc, ← intervalIntegral.integral_const_mul, ← real_smul, ← zero_div a, ← div_self ha.ne', ← intervalIntegral.integral_comp_div _ ha.ne', zero_div] simp_rw [intervalIntegral.integral_of_le ha.le] refine setIntegral_congr measurableSet_Ioc fun x hx => ?_ rw [mul_mul_mul_comm] congr 1 · rw [← mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel₀ _ ha'] · rw [(by norm_cast : (1 : ℂ) - ↑(x / a) = ↑(1 - x / a)), ← mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)] push_cast rw [mul_sub, mul_one, mul_div_cancel₀ _ ha'] #align complex.beta_integral_scaled Complex.betaIntegral_scaled /-- Relation between Beta integral and Gamma function. -/ theorem Gamma_mul_Gamma_eq_betaIntegral {s t : ℂ} (hs : 0 < re s) (ht : 0 < re t) : Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by -- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate -- this as a formula for the Beta function. have conv_int := integral_posConvolution (GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul ℝ ℂ) simp_rw [ContinuousLinearMap.mul_apply'] at conv_int have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral, GammaIntegral, GammaIntegral, ← conv_int, ← integral_mul_right (betaIntegral _ _)] refine setIntegral_congr measurableSet_Ioi fun x hx => ?_ rw [mul_assoc, ← betaIntegral_scaled s t hx, ← intervalIntegral.integral_const_mul] congr 1 with y : 1 push_cast suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring rw [← Complex.exp_add]; congr 1; abel #align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral /-- Recurrence formula for the Beta function. -/ theorem betaIntegral_recurrence {u v : ℂ} (hu : 0 < re u) (hv : 0 < re v) : u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by -- NB: If we knew `Gamma (u + v + 1) ≠ 0` this would be an easy consequence of -- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but -- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument. let F : ℝ → ℂ := fun x => (x : ℂ) ^ u * (1 - (x : ℂ)) ^ v have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity have hc : ContinuousOn F (Icc 0 1) := by refine (ContinuousAt.continuousOn fun x hx => ?_).mul (ContinuousAt.continuousOn fun x hx => ?_) · refine (continuousAt_cpow_const_of_re_pos (Or.inl ?_) hu).comp continuous_ofReal.continuousAt rw [ofReal_re]; exact hx.1 · refine (continuousAt_cpow_const_of_re_pos (Or.inl ?_) hv).comp (continuous_const.sub continuous_ofReal).continuousAt rw [sub_re, one_re, ofReal_re, sub_nonneg] exact hx.2 have hder : ∀ x : ℝ, x ∈ Ioo (0 : ℝ) 1 → HasDerivAt F (u * ((x : ℂ) ^ (u - 1) * (1 - (x : ℂ)) ^ v) - v * ((x : ℂ) ^ u * (1 - (x : ℂ)) ^ (v - 1))) x := by intro x hx have U : HasDerivAt (fun y : ℂ => y ^ u) (u * (x : ℂ) ^ (u - 1)) ↑x := by have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : ℂ)) (Or.inl ?_) · simp only [id_eq, mul_one] at this exact this · rw [id_eq, ofReal_re]; exact hx.1 have V : HasDerivAt (fun y : ℂ => (1 - y) ^ v) (-v * (1 - (x : ℂ)) ^ (v - 1)) ↑x := by have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : ℂ))) (Or.inl ?_) swap; · rw [id, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2 simp_rw [id] at A have B : HasDerivAt (fun y : ℂ => 1 - y) (-1) ↑x := by apply HasDerivAt.const_sub; apply hasDerivAt_id convert HasDerivAt.comp (↑x) A B using 1 ring convert (U.mul V).comp_ofReal using 1 ring have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub ((betaIntegral_convergent hu' hv).const_mul v) rw [add_sub_cancel_right, add_sub_cancel_right] at h_int have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int have hF0 : F 0 = 0 := by simp only [F, mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne, true_and_iff, sub_zero, one_cpow, one_ne_zero, or_false_iff] contrapose! hu; rw [hu, zero_re] have hF1 : F 1 = 0 := by simp only [F, mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff, eq_self_iff_true, Ne, true_and_iff, false_or_iff] contrapose! hv; rw [hv, zero_re] rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul, intervalIntegral.integral_const_mul] at int_ev · rw [betaIntegral, betaIntegral, ← sub_eq_zero] convert int_ev <;> ring · apply IntervalIntegrable.const_mul convert betaIntegral_convergent hu hv'; ring · apply IntervalIntegrable.const_mul convert betaIntegral_convergent hu' hv; ring #align complex.beta_integral_recurrence Complex.betaIntegral_recurrence /-- Explicit formula for the Beta function when second argument is a positive integer. -/ theorem betaIntegral_eval_nat_add_one_right {u : ℂ} (hu : 0 < re u) (n : ℕ) : betaIntegral u (n + 1) = n ! / ∏ j ∈ Finset.range (n + 1), (u + j) := by induction' n with n IH generalizing u · rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one] simp · have := betaIntegral_recurrence hu (?_ : 0 < re n.succ) swap; · rw [← ofReal_natCast, ofReal_re]; positivity rw [mul_comm u _, ← eq_div_iff] at this swap; · contrapose! hu; rw [hu, zero_re] rw [this, Finset.prod_range_succ', Nat.cast_succ, IH] swap; · rw [add_re, one_re]; positivity rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, ← mul_div_assoc, ← div_div] congr 3 with j : 1 push_cast; abel #align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right end Complex end BetaIntegral section LimitFormula /-! ## The Euler limit formula -/ namespace Complex /-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`. We will show that this tends to `Γ(s)` as `n → ∞`. -/ noncomputable def GammaSeq (s : ℂ) (n : ℕ) := (n : ℂ) ^ s * n ! / ∏ j ∈ Finset.range (n + 1), (s + j) #align complex.Gamma_seq Complex.GammaSeq theorem GammaSeq_eq_betaIntegral_of_re_pos {s : ℂ} (hs : 0 < re s) (n : ℕ) : GammaSeq s n = (n : ℂ) ^ s * betaIntegral s (n + 1) := by rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, ← mul_div_assoc] #align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos theorem GammaSeq_add_one_left (s : ℂ) {n : ℕ} (hn : n ≠ 0) : GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div] conv_rhs => rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, ← mul_assoc, ← mul_assoc, mul_comm _ (Finset.prod _ _)] congr 3 · rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm] · refine Finset.prod_congr (by rfl) fun x _ => ?_ push_cast; ring · abel #align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left theorem GammaSeq_eq_approx_Gamma_integral {s : ℂ} (hs : 0 < re s) {n : ℕ} (hn : n ≠ 0) : GammaSeq s n = ∫ x : ℝ in (0)..n, ↑((1 - x / n) ^ n) * (x : ℂ) ^ (s - 1) := by have : ∀ x : ℝ, x = x / n * n := by intro x; rw [div_mul_cancel₀]; exact Nat.cast_ne_zero.mpr hn conv_rhs => enter [1, x, 2, 1]; rw [this x] rw [GammaSeq_eq_betaIntegral_of_re_pos hs] have := intervalIntegral.integral_comp_div (a := 0) (b := n) (fun x => ↑((1 - x) ^ n) * ↑(x * ↑n) ^ (s - 1) : ℝ → ℂ) (Nat.cast_ne_zero.mpr hn) dsimp only at this rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel_right, ← intervalIntegral.integral_const_mul, ← intervalIntegral.integral_const_mul] swap; · exact Nat.cast_ne_zero.mpr hn simp_rw [intervalIntegral.integral_of_le zero_le_one] refine setIntegral_congr measurableSet_Ioc fun x hx => ?_ push_cast have hn' : (n : ℂ) ≠ 0 := Nat.cast_ne_zero.mpr hn have A : (n : ℂ) ^ s = (n : ℂ) ^ (s - 1) * n := by conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn'] simp have B : ((x : ℂ) * ↑n) ^ (s - 1) = (x : ℂ) ^ (s - 1) * (n : ℂ) ^ (s - 1) := by rw [← ofReal_natCast, mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le] rw [A, B, cpow_natCast]; ring #align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral /-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/ theorem approx_Gamma_integral_tendsto_Gamma_integral {s : ℂ} (hs : 0 < re s) : Tendsto (fun n : ℕ => ∫ x : ℝ in (0)..n, ((1 - x / n) ^ n : ℝ) * (x : ℂ) ^ (s - 1)) atTop (𝓝 <| Gamma s) := by rw [Gamma_eq_integral hs] -- We apply dominated convergence to the following function, which we will show is uniformly -- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`. let f : ℕ → ℝ → ℂ := fun n => indicator (Ioc 0 (n : ℝ)) fun x : ℝ => ((1 - x / n) ^ n : ℝ) * (x : ℂ) ^ (s - 1) -- integrability of f have f_ible : ∀ n : ℕ, Integrable (f n) (volume.restrict (Ioi 0)) := by intro n rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : ℝ) _)), IntegrableOn, Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, ← IntegrableOn, ← intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : ℝ) ≤ n)] apply IntervalIntegrable.continuousOn_mul · refine intervalIntegral.intervalIntegrable_cpow' ?_ rwa [sub_re, one_re, ← zero_sub, sub_lt_sub_iff_right] · apply Continuous.continuousOn exact RCLike.continuous_ofReal.comp -- Porting note: was `continuity` ((continuous_const.sub (continuous_id'.div_const ↑n)).pow n) -- pointwise limit of f have f_tends : ∀ x : ℝ, x ∈ Ioi (0 : ℝ) → Tendsto (fun n : ℕ => f n x) atTop (𝓝 <| ↑(Real.exp (-x)) * (x : ℂ) ^ (s - 1)) := by intro x hx apply Tendsto.congr' · show ∀ᶠ n : ℕ in atTop, ↑((1 - x / n) ^ n) * (x : ℂ) ^ (s - 1) = f n x filter_upwards [eventually_ge_atTop ⌈x⌉₊] with n hn rw [Nat.ceil_le] at hn dsimp only [f] rw [indicator_of_mem] exact ⟨hx, hn⟩ · simp_rw [mul_comm] refine (Tendsto.comp (continuous_ofReal.tendsto _) ?_).const_mul _ convert tendsto_one_plus_div_pow_exp (-x) using 1 ext1 n rw [neg_div, ← sub_eq_add_neg] -- let `convert` identify the remaining goals convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1) (Real.GammaIntegral_convergent hs) _ ((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1 -- limit of f is the integrand we want · ext1 n rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : ℝ) _)), intervalIntegral.integral_of_le (by positivity : 0 ≤ (n : ℝ)), Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self] -- f is uniformly bounded by the Gamma integrand · intro n rw [ae_restrict_iff' measurableSet_Ioi] filter_upwards with x hx dsimp only [f] rcases lt_or_le (n : ℝ) x with (hxn | hxn) · rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero, mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)] exact rpow_nonneg (le_of_lt hx) _ · rw [indicator_of_mem (mem_Ioc.mpr ⟨mem_Ioi.mp hx, hxn⟩), norm_mul, Complex.norm_eq_abs, Complex.abs_of_nonneg (pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _), Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re, mul_le_mul_right (rpow_pos_of_pos hx _)] exact one_sub_div_pow_le_exp_neg hxn #align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral /-- Euler's limit formula for the complex Gamma function. -/ theorem GammaSeq_tendsto_Gamma (s : ℂ) : Tendsto (GammaSeq s) atTop (𝓝 <| Gamma s) := by suffices ∀ m : ℕ, -↑m < re s → Tendsto (GammaSeq s) atTop (𝓝 <| GammaAux m s) by rw [Gamma] apply this rw [neg_lt] rcases lt_or_le 0 (re s) with (hs | hs) · exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _) · refine (Nat.lt_floor_add_one _).trans_le ?_ rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one] intro m induction' m with m IH generalizing s · -- Base case: `0 < re s`, so Gamma is given by the integral formula intro hs rw [Nat.cast_zero, neg_zero] at hs rw [← Gamma_eq_GammaAux] · refine Tendsto.congr' ?_ (approx_Gamma_integral_tendsto_Gamma_integral hs) refine (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_) exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm · rwa [Nat.cast_zero, neg_lt_zero] · -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq intro hs rw [Nat.cast_succ, neg_add, ← sub_eq_add_neg, sub_lt_iff_lt_add, ← one_re, ← add_re] at hs rw [GammaAux] have := @Tendsto.congr' _ _ _ ?_ _ _ ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s) pick_goal 3; · exact GammaSeq_add_one_left s hn -- doesn't work if inlined? conv at this => arg 1; intro n; rw [mul_comm] rwa [← mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' ℂ)] at this simp_rw [add_assoc] exact tendsto_natCast_div_add_atTop (1 + s) #align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma end Complex end LimitFormula section GammaReflection /-! ## The reflection formula -/ namespace Complex theorem GammaSeq_mul (z : ℂ) {n : ℕ} (hn : n ≠ 0) : GammaSeq z n * GammaSeq (1 - z) n = n / (n + ↑1 - z) * (↑1 / (z * ∏ j ∈ Finset.range n, (↑1 - z ^ 2 / ((j : ℂ) + 1) ^ 2))) := by -- also true for n = 0 but we don't need it have aux : ∀ a b c d : ℂ, a * b * (c * d) = a * c * (b * d) := by intros; ring rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, ← pow_two] have : (n : ℂ) ^ z * (n : ℂ) ^ (1 - z) = n := by rw [← cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel, cpow_one] rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, ← Finset.prod_mul_distrib, Nat.cast_zero, add_zero, add_comm (1 - z) n, ← add_sub_assoc] have : ∀ j : ℕ, (z + ↑(j + 1)) * (↑1 - z + ↑j) = ((j + 1) ^ 2 :) * (↑1 - z ^ 2 / ((j : ℂ) + 1) ^ 2) := by intro j push_cast have : (j : ℂ) + 1 ≠ 0 := by rw [← Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j field_simp; ring simp_rw [this] rw [Finset.prod_mul_distrib, ← Nat.cast_prod, Finset.prod_pow, Finset.prod_range_add_one_eq_factorial, Nat.cast_pow, (by intros; ring : ∀ a b c d : ℂ, a * b * (c * d) = a * (d * (b * c))), ← div_div, mul_div_cancel_right₀, ← div_div, mul_comm z _, mul_one_div] exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n) #align complex.Gamma_seq_mul Complex.GammaSeq_mul /-- Euler's reflection formula for the complex Gamma function. -/ theorem Gamma_mul_Gamma_one_sub (z : ℂ) : Gamma z * Gamma (1 - z) = π / sin (π * z) := by have pi_ne : (π : ℂ) ≠ 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero by_cases hs : sin (↑π * z) = 0 · -- first deal with silly case z = integer rw [hs, div_zero] rw [← neg_eq_zero, ← Complex.sin_neg, ← mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs obtain ⟨k, hk⟩ := hs rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff, neg_eq_iff_eq_neg] at hk rw [hk] cases k · rw [Int.ofNat_eq_coe, Int.cast_natCast, Complex.Gamma_neg_nat_eq_zero, zero_mul] · rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel_left, Complex.Gamma_neg_nat_eq_zero, mul_zero] refine tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) ?_ have : ↑π / sin (↑π * z) = 1 * (π / sin (π * z)) := by rw [one_mul] convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => (GammaSeq_mul z hn).symm)) (Tendsto.mul _ _) · convert tendsto_natCast_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc] · have : ↑π / sin (↑π * z) = 1 / (sin (π * z) / π) := by field_simp convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne) rw [← tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel₀ _ pi_ne] convert tendsto_euler_sin_prod z using 1 ext1 n; rw [mul_comm, ← mul_assoc] #align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub /-- The Gamma function does not vanish on `ℂ` (except at non-positive integers, where the function is mathematically undefined and we set it to `0` by convention). -/ theorem Gamma_ne_zero {s : ℂ} (hs : ∀ m : ℕ, s ≠ -m) : Gamma s ≠ 0 := by by_cases h_im : s.im = 0 · have : s = ↑s.re := by conv_lhs => rw [← Complex.re_add_im s] rw [h_im, ofReal_zero, zero_mul, add_zero] rw [this, Gamma_ofReal, ofReal_ne_zero] refine Real.Gamma_ne_zero fun n => ?_ specialize hs n contrapose! hs rwa [this, ← ofReal_natCast, ← ofReal_neg, ofReal_inj] · have : sin (↑π * s) ≠ 0 := by rw [Complex.sin_ne_zero_iff] intro k apply_fun im rw [im_ofReal_mul, ← ofReal_intCast, ← ofReal_mul, ofReal_im] exact mul_ne_zero Real.pi_pos.ne' h_im have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this rw [← Complex.Gamma_mul_Gamma_one_sub s, mul_ne_zero_iff] at A exact A.1 #align complex.Gamma_ne_zero Complex.Gamma_ne_zero theorem Gamma_eq_zero_iff (s : ℂ) : Gamma s = 0 ↔ ∃ m : ℕ, s = -m := by constructor · contrapose!; exact Gamma_ne_zero · rintro ⟨m, rfl⟩; exact Gamma_neg_nat_eq_zero m #align complex.Gamma_eq_zero_iff Complex.Gamma_eq_zero_iff /-- A weaker, but easier-to-apply, version of `Complex.Gamma_ne_zero`. -/
Mathlib/Analysis/SpecialFunctions/Gamma/Beta.lean
478
481
theorem Gamma_ne_zero_of_re_pos {s : ℂ} (hs : 0 < re s) : Gamma s ≠ 0 := by
refine Gamma_ne_zero fun m => ?_ contrapose! hs simpa only [hs, neg_re, ← ofReal_natCast, ofReal_re, neg_nonpos] using Nat.cast_nonneg _
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.RingTheory.Polynomial.Basic import Mathlib.RingTheory.Ideal.LocalRing #align_import data.polynomial.expand from "leanprover-community/mathlib"@"bbeb185db4ccee8ed07dc48449414ebfa39cb821" /-! # Expand a polynomial by a factor of p, so `∑ aₙ xⁿ` becomes `∑ aₙ xⁿᵖ`. ## Main definitions * `Polynomial.expand R p f`: expand the polynomial `f` with coefficients in a commutative semiring `R` by a factor of p, so `expand R p (∑ aₙ xⁿ)` is `∑ aₙ xⁿᵖ`. * `Polynomial.contract p f`: the opposite of `expand`, so it sends `∑ aₙ xⁿᵖ` to `∑ aₙ xⁿ`. -/ universe u v w open Polynomial open Finset namespace Polynomial section CommSemiring variable (R : Type u) [CommSemiring R] {S : Type v} [CommSemiring S] (p q : ℕ) /-- Expand the polynomial by a factor of p, so `∑ aₙ xⁿ` becomes `∑ aₙ xⁿᵖ`. -/ noncomputable def expand : R[X] →ₐ[R] R[X] := { (eval₂RingHom C (X ^ p) : R[X] →+* R[X]) with commutes' := fun _ => eval₂_C _ _ } #align polynomial.expand Polynomial.expand theorem coe_expand : (expand R p : R[X] → R[X]) = eval₂ C (X ^ p) := rfl #align polynomial.coe_expand Polynomial.coe_expand variable {R} theorem expand_eq_comp_X_pow {f : R[X]} : expand R p f = f.comp (X ^ p) := rfl theorem expand_eq_sum {f : R[X]} : expand R p f = f.sum fun e a => C a * (X ^ p) ^ e := by simp [expand, eval₂] #align polynomial.expand_eq_sum Polynomial.expand_eq_sum @[simp] theorem expand_C (r : R) : expand R p (C r) = C r := eval₂_C _ _ set_option linter.uppercaseLean3 false in #align polynomial.expand_C Polynomial.expand_C @[simp] theorem expand_X : expand R p X = X ^ p := eval₂_X _ _ set_option linter.uppercaseLean3 false in #align polynomial.expand_X Polynomial.expand_X @[simp] theorem expand_monomial (r : R) : expand R p (monomial q r) = monomial (q * p) r := by simp_rw [← smul_X_eq_monomial, AlgHom.map_smul, AlgHom.map_pow, expand_X, mul_comm, pow_mul] #align polynomial.expand_monomial Polynomial.expand_monomial theorem expand_expand (f : R[X]) : expand R p (expand R q f) = expand R (p * q) f := Polynomial.induction_on f (fun r => by simp_rw [expand_C]) (fun f g ihf ihg => by simp_rw [AlgHom.map_add, ihf, ihg]) fun n r _ => by simp_rw [AlgHom.map_mul, expand_C, AlgHom.map_pow, expand_X, AlgHom.map_pow, expand_X, pow_mul] #align polynomial.expand_expand Polynomial.expand_expand theorem expand_mul (f : R[X]) : expand R (p * q) f = expand R p (expand R q f) := (expand_expand p q f).symm #align polynomial.expand_mul Polynomial.expand_mul @[simp] theorem expand_zero (f : R[X]) : expand R 0 f = C (eval 1 f) := by simp [expand] #align polynomial.expand_zero Polynomial.expand_zero @[simp] theorem expand_one (f : R[X]) : expand R 1 f = f := Polynomial.induction_on f (fun r => by rw [expand_C]) (fun f g ihf ihg => by rw [AlgHom.map_add, ihf, ihg]) fun n r _ => by rw [AlgHom.map_mul, expand_C, AlgHom.map_pow, expand_X, pow_one] #align polynomial.expand_one Polynomial.expand_one theorem expand_pow (f : R[X]) : expand R (p ^ q) f = (expand R p)^[q] f := Nat.recOn q (by rw [pow_zero, expand_one, Function.iterate_zero, id]) fun n ih => by rw [Function.iterate_succ_apply', pow_succ', expand_mul, ih] #align polynomial.expand_pow Polynomial.expand_pow theorem derivative_expand (f : R[X]) : Polynomial.derivative (expand R p f) = expand R p (Polynomial.derivative f) * (p * (X ^ (p - 1) : R[X])) := by rw [coe_expand, derivative_eval₂_C, derivative_pow, C_eq_natCast, derivative_X, mul_one] #align polynomial.derivative_expand Polynomial.derivative_expand theorem coeff_expand {p : ℕ} (hp : 0 < p) (f : R[X]) (n : ℕ) : (expand R p f).coeff n = if p ∣ n then f.coeff (n / p) else 0 := by simp only [expand_eq_sum] simp_rw [coeff_sum, ← pow_mul, C_mul_X_pow_eq_monomial, coeff_monomial, sum] split_ifs with h · rw [Finset.sum_eq_single (n / p), Nat.mul_div_cancel' h, if_pos rfl] · intro b _ hb2 rw [if_neg] intro hb3 apply hb2 rw [← hb3, Nat.mul_div_cancel_left b hp] · intro hn rw [not_mem_support_iff.1 hn] split_ifs <;> rfl · rw [Finset.sum_eq_zero] intro k _ rw [if_neg] exact fun hkn => h ⟨k, hkn.symm⟩ #align polynomial.coeff_expand Polynomial.coeff_expand @[simp] theorem coeff_expand_mul {p : ℕ} (hp : 0 < p) (f : R[X]) (n : ℕ) : (expand R p f).coeff (n * p) = f.coeff n := by rw [coeff_expand hp, if_pos (dvd_mul_left _ _), Nat.mul_div_cancel _ hp] #align polynomial.coeff_expand_mul Polynomial.coeff_expand_mul @[simp] theorem coeff_expand_mul' {p : ℕ} (hp : 0 < p) (f : R[X]) (n : ℕ) : (expand R p f).coeff (p * n) = f.coeff n := by rw [mul_comm, coeff_expand_mul hp] #align polynomial.coeff_expand_mul' Polynomial.coeff_expand_mul' /-- Expansion is injective. -/ theorem expand_injective {n : ℕ} (hn : 0 < n) : Function.Injective (expand R n) := fun g g' H => ext fun k => by rw [← coeff_expand_mul hn, H, coeff_expand_mul hn] #align polynomial.expand_injective Polynomial.expand_injective theorem expand_inj {p : ℕ} (hp : 0 < p) {f g : R[X]} : expand R p f = expand R p g ↔ f = g := (expand_injective hp).eq_iff #align polynomial.expand_inj Polynomial.expand_inj theorem expand_eq_zero {p : ℕ} (hp : 0 < p) {f : R[X]} : expand R p f = 0 ↔ f = 0 := (expand_injective hp).eq_iff' (map_zero _) #align polynomial.expand_eq_zero Polynomial.expand_eq_zero theorem expand_ne_zero {p : ℕ} (hp : 0 < p) {f : R[X]} : expand R p f ≠ 0 ↔ f ≠ 0 := (expand_eq_zero hp).not #align polynomial.expand_ne_zero Polynomial.expand_ne_zero theorem expand_eq_C {p : ℕ} (hp : 0 < p) {f : R[X]} {r : R} : expand R p f = C r ↔ f = C r := by rw [← expand_C, expand_inj hp, expand_C] set_option linter.uppercaseLean3 false in #align polynomial.expand_eq_C Polynomial.expand_eq_C theorem natDegree_expand (p : ℕ) (f : R[X]) : (expand R p f).natDegree = f.natDegree * p := by rcases p.eq_zero_or_pos with hp | hp · rw [hp, coe_expand, pow_zero, mul_zero, ← C_1, eval₂_hom, natDegree_C] by_cases hf : f = 0 · rw [hf, AlgHom.map_zero, natDegree_zero, zero_mul] have hf1 : expand R p f ≠ 0 := mt (expand_eq_zero hp).1 hf rw [← WithBot.coe_eq_coe] convert (degree_eq_natDegree hf1).symm -- Porting note: was `rw [degree_eq_natDegree hf1]` symm refine le_antisymm ((degree_le_iff_coeff_zero _ _).2 fun n hn => ?_) ?_ · rw [coeff_expand hp] split_ifs with hpn · rw [coeff_eq_zero_of_natDegree_lt] contrapose! hn erw [WithBot.coe_le_coe, ← Nat.div_mul_cancel hpn] exact Nat.mul_le_mul_right p hn · rfl · refine le_degree_of_ne_zero ?_ erw [coeff_expand_mul hp, ← leadingCoeff] exact mt leadingCoeff_eq_zero.1 hf #align polynomial.nat_degree_expand Polynomial.natDegree_expand theorem leadingCoeff_expand {p : ℕ} {f : R[X]} (hp : 0 < p) : (expand R p f).leadingCoeff = f.leadingCoeff := by simp_rw [leadingCoeff, natDegree_expand, coeff_expand_mul hp] theorem monic_expand_iff {p : ℕ} {f : R[X]} (hp : 0 < p) : (expand R p f).Monic ↔ f.Monic := by simp only [Monic, leadingCoeff_expand hp] alias ⟨_, Monic.expand⟩ := monic_expand_iff #align polynomial.monic.expand Polynomial.Monic.expand theorem map_expand {p : ℕ} {f : R →+* S} {q : R[X]} : map f (expand R p q) = expand S p (map f q) := by by_cases hp : p = 0 · simp [hp] ext rw [coeff_map, coeff_expand (Nat.pos_of_ne_zero hp), coeff_expand (Nat.pos_of_ne_zero hp)] split_ifs <;> simp_all #align polynomial.map_expand Polynomial.map_expand @[simp] theorem expand_eval (p : ℕ) (P : R[X]) (r : R) : eval r (expand R p P) = eval (r ^ p) P := by refine Polynomial.induction_on P (fun a => by simp) (fun f g hf hg => ?_) fun n a _ => by simp rw [AlgHom.map_add, eval_add, eval_add, hf, hg] #align polynomial.expand_eval Polynomial.expand_eval @[simp] theorem expand_aeval {A : Type*} [Semiring A] [Algebra R A] (p : ℕ) (P : R[X]) (r : A) : aeval r (expand R p P) = aeval (r ^ p) P := by refine Polynomial.induction_on P (fun a => by simp) (fun f g hf hg => ?_) fun n a _ => by simp rw [AlgHom.map_add, aeval_add, aeval_add, hf, hg] #align polynomial.expand_aeval Polynomial.expand_aeval /-- The opposite of `expand`: sends `∑ aₙ xⁿᵖ` to `∑ aₙ xⁿ`. -/ noncomputable def contract (p : ℕ) (f : R[X]) : R[X] := ∑ n ∈ range (f.natDegree + 1), monomial n (f.coeff (n * p)) #align polynomial.contract Polynomial.contract theorem coeff_contract {p : ℕ} (hp : p ≠ 0) (f : R[X]) (n : ℕ) : (contract p f).coeff n = f.coeff (n * p) := by simp only [contract, coeff_monomial, sum_ite_eq', finset_sum_coeff, mem_range, not_lt, ite_eq_left_iff] intro hn apply (coeff_eq_zero_of_natDegree_lt _).symm calc f.natDegree < f.natDegree + 1 := Nat.lt_succ_self _ _ ≤ n * 1 := by simpa only [mul_one] using hn _ ≤ n * p := mul_le_mul_of_nonneg_left (show 1 ≤ p from hp.bot_lt) (zero_le n) #align polynomial.coeff_contract Polynomial.coeff_contract theorem map_contract {p : ℕ} (hp : p ≠ 0) {f : R →+* S} {q : R[X]} : (q.contract p).map f = (q.map f).contract p := ext fun n ↦ by simp only [coeff_map, coeff_contract hp] theorem contract_expand {f : R[X]} (hp : p ≠ 0) : contract p (expand R p f) = f := by ext simp [coeff_contract hp, coeff_expand hp.bot_lt, Nat.mul_div_cancel _ hp.bot_lt] #align polynomial.contract_expand Polynomial.contract_expand theorem contract_one {f : R[X]} : contract 1 f = f := ext fun n ↦ by rw [coeff_contract one_ne_zero, mul_one] section ExpChar theorem expand_contract [CharP R p] [NoZeroDivisors R] {f : R[X]} (hf : Polynomial.derivative f = 0) (hp : p ≠ 0) : expand R p (contract p f) = f := by ext n rw [coeff_expand hp.bot_lt, coeff_contract hp] split_ifs with h · rw [Nat.div_mul_cancel h] · cases' n with n · exact absurd (dvd_zero p) h have := coeff_derivative f n rw [hf, coeff_zero, zero_eq_mul] at this cases' this with h' · rw [h'] rename_i _ _ _ _ h' rw [← Nat.cast_succ, CharP.cast_eq_zero_iff R p] at h' exact absurd h' h #align polynomial.expand_contract Polynomial.expand_contract variable [ExpChar R p] theorem expand_contract' [NoZeroDivisors R] {f : R[X]} (hf : Polynomial.derivative f = 0) : expand R p (contract p f) = f := by obtain _ | @⟨_, hprime, hchar⟩ := ‹ExpChar R p› · rw [expand_one, contract_one] · haveI := Fact.mk hchar; exact expand_contract p hf hprime.ne_zero theorem expand_char (f : R[X]) : map (frobenius R p) (expand R p f) = f ^ p := by refine f.induction_on' (fun a b ha hb => ?_) fun n a => ?_ · rw [AlgHom.map_add, Polynomial.map_add, ha, hb, add_pow_expChar] · rw [expand_monomial, map_monomial, ← C_mul_X_pow_eq_monomial, ← C_mul_X_pow_eq_monomial, mul_pow, ← C.map_pow, frobenius_def] ring #align polynomial.expand_char Polynomial.expand_char theorem map_expand_pow_char (f : R[X]) (n : ℕ) : map (frobenius R p ^ n) (expand R (p ^ n) f) = f ^ p ^ n := by induction' n with _ n_ih · simp [RingHom.one_def] symm rw [pow_succ, pow_mul, ← n_ih, ← expand_char, pow_succ', RingHom.mul_def, ← map_map, mul_comm, expand_mul, ← map_expand] #align polynomial.map_expand_pow_char Polynomial.map_expand_pow_char end ExpChar end CommSemiring section rootMultiplicity variable {R : Type u} [CommRing R] {p n : ℕ} [ExpChar R p] {f : R[X]} {r : R}
Mathlib/Algebra/Polynomial/Expand.lean
288
295
theorem rootMultiplicity_expand_pow : (expand R (p ^ n) f).rootMultiplicity r = p ^ n * f.rootMultiplicity (r ^ p ^ n) := by
obtain rfl | h0 := eq_or_ne f 0; · simp obtain ⟨g, hg, ndvd⟩ := f.exists_eq_pow_rootMultiplicity_mul_and_not_dvd h0 (r ^ p ^ n) rw [dvd_iff_isRoot, ← eval_X (x := r), ← eval_pow, ← isRoot_comp, ← expand_eq_comp_X_pow] at ndvd conv_lhs => rw [hg, map_mul, map_pow, map_sub, expand_X, expand_C, map_pow, ← sub_pow_expChar_pow, ← pow_mul, mul_comm, rootMultiplicity_mul_X_sub_C_pow (expand_ne_zero (expChar_pow_pos R p n) |>.mpr <| right_ne_zero_of_mul <| hg ▸ h0), rootMultiplicity_eq_zero ndvd, zero_add]
/- Copyright (c) 2020 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import Mathlib.Algebra.GroupPower.IterateHom import Mathlib.Algebra.Ring.Divisibility.Basic import Mathlib.Data.List.Cycle import Mathlib.Data.Nat.Prime import Mathlib.Data.PNat.Basic import Mathlib.Dynamics.FixedPoints.Basic import Mathlib.GroupTheory.GroupAction.Group #align_import dynamics.periodic_pts from "leanprover-community/mathlib"@"d07245fd37786daa997af4f1a73a49fa3b748408" /-! # Periodic points A point `x : α` is a periodic point of `f : α → α` of period `n` if `f^[n] x = x`. ## Main definitions * `IsPeriodicPt f n x` : `x` is a periodic point of `f` of period `n`, i.e. `f^[n] x = x`. We do not require `n > 0` in the definition. * `ptsOfPeriod f n` : the set `{x | IsPeriodicPt f n x}`. Note that `n` is not required to be the minimal period of `x`. * `periodicPts f` : the set of all periodic points of `f`. * `minimalPeriod f x` : the minimal period of a point `x` under an endomorphism `f` or zero if `x` is not a periodic point of `f`. * `orbit f x`: the cycle `[x, f x, f (f x), ...]` for a periodic point. * `MulAction.period g x` : the minimal period of a point `x` under the multiplicative action of `g`; an equivalent `AddAction.period g x` is defined for additive actions. ## Main statements We provide “dot syntax”-style operations on terms of the form `h : IsPeriodicPt f n x` including arithmetic operations on `n` and `h.map (hg : SemiconjBy g f f')`. We also prove that `f` is bijective on each set `ptsOfPeriod f n` and on `periodicPts f`. Finally, we prove that `x` is a periodic point of `f` of period `n` if and only if `minimalPeriod f x | n`. ## References * https://en.wikipedia.org/wiki/Periodic_point -/ open Set namespace Function open Function (Commute) variable {α : Type*} {β : Type*} {f fa : α → α} {fb : β → β} {x y : α} {m n : ℕ} /-- A point `x` is a periodic point of `f : α → α` of period `n` if `f^[n] x = x`. Note that we do not require `0 < n` in this definition. Many theorems about periodic points need this assumption. -/ def IsPeriodicPt (f : α → α) (n : ℕ) (x : α) := IsFixedPt f^[n] x #align function.is_periodic_pt Function.IsPeriodicPt /-- A fixed point of `f` is a periodic point of `f` of any prescribed period. -/ theorem IsFixedPt.isPeriodicPt (hf : IsFixedPt f x) (n : ℕ) : IsPeriodicPt f n x := hf.iterate n #align function.is_fixed_pt.is_periodic_pt Function.IsFixedPt.isPeriodicPt /-- For the identity map, all points are periodic. -/ theorem is_periodic_id (n : ℕ) (x : α) : IsPeriodicPt id n x := (isFixedPt_id x).isPeriodicPt n #align function.is_periodic_id Function.is_periodic_id /-- Any point is a periodic point of period `0`. -/ theorem isPeriodicPt_zero (f : α → α) (x : α) : IsPeriodicPt f 0 x := isFixedPt_id x #align function.is_periodic_pt_zero Function.isPeriodicPt_zero namespace IsPeriodicPt instance [DecidableEq α] {f : α → α} {n : ℕ} {x : α} : Decidable (IsPeriodicPt f n x) := IsFixedPt.decidable protected theorem isFixedPt (hf : IsPeriodicPt f n x) : IsFixedPt f^[n] x := hf #align function.is_periodic_pt.is_fixed_pt Function.IsPeriodicPt.isFixedPt protected theorem map (hx : IsPeriodicPt fa n x) {g : α → β} (hg : Semiconj g fa fb) : IsPeriodicPt fb n (g x) := IsFixedPt.map hx (hg.iterate_right n) #align function.is_periodic_pt.map Function.IsPeriodicPt.map theorem apply_iterate (hx : IsPeriodicPt f n x) (m : ℕ) : IsPeriodicPt f n (f^[m] x) := hx.map <| Commute.iterate_self f m #align function.is_periodic_pt.apply_iterate Function.IsPeriodicPt.apply_iterate protected theorem apply (hx : IsPeriodicPt f n x) : IsPeriodicPt f n (f x) := hx.apply_iterate 1 #align function.is_periodic_pt.apply Function.IsPeriodicPt.apply protected theorem add (hn : IsPeriodicPt f n x) (hm : IsPeriodicPt f m x) : IsPeriodicPt f (n + m) x := by rw [IsPeriodicPt, iterate_add] exact hn.comp hm #align function.is_periodic_pt.add Function.IsPeriodicPt.add theorem left_of_add (hn : IsPeriodicPt f (n + m) x) (hm : IsPeriodicPt f m x) : IsPeriodicPt f n x := by rw [IsPeriodicPt, iterate_add] at hn exact hn.left_of_comp hm #align function.is_periodic_pt.left_of_add Function.IsPeriodicPt.left_of_add theorem right_of_add (hn : IsPeriodicPt f (n + m) x) (hm : IsPeriodicPt f n x) : IsPeriodicPt f m x := by rw [add_comm] at hn exact hn.left_of_add hm #align function.is_periodic_pt.right_of_add Function.IsPeriodicPt.right_of_add protected theorem sub (hm : IsPeriodicPt f m x) (hn : IsPeriodicPt f n x) : IsPeriodicPt f (m - n) x := by rcases le_total n m with h | h · refine left_of_add ?_ hn rwa [tsub_add_cancel_of_le h] · rw [tsub_eq_zero_iff_le.mpr h] apply isPeriodicPt_zero #align function.is_periodic_pt.sub Function.IsPeriodicPt.sub protected theorem mul_const (hm : IsPeriodicPt f m x) (n : ℕ) : IsPeriodicPt f (m * n) x := by simp only [IsPeriodicPt, iterate_mul, hm.isFixedPt.iterate n] #align function.is_periodic_pt.mul_const Function.IsPeriodicPt.mul_const protected theorem const_mul (hm : IsPeriodicPt f m x) (n : ℕ) : IsPeriodicPt f (n * m) x := by simp only [mul_comm n, hm.mul_const n] #align function.is_periodic_pt.const_mul Function.IsPeriodicPt.const_mul theorem trans_dvd (hm : IsPeriodicPt f m x) {n : ℕ} (hn : m ∣ n) : IsPeriodicPt f n x := let ⟨k, hk⟩ := hn hk.symm ▸ hm.mul_const k #align function.is_periodic_pt.trans_dvd Function.IsPeriodicPt.trans_dvd protected theorem iterate (hf : IsPeriodicPt f n x) (m : ℕ) : IsPeriodicPt f^[m] n x := by rw [IsPeriodicPt, ← iterate_mul, mul_comm, iterate_mul] exact hf.isFixedPt.iterate m #align function.is_periodic_pt.iterate Function.IsPeriodicPt.iterate theorem comp {g : α → α} (hco : Commute f g) (hf : IsPeriodicPt f n x) (hg : IsPeriodicPt g n x) : IsPeriodicPt (f ∘ g) n x := by rw [IsPeriodicPt, hco.comp_iterate] exact IsFixedPt.comp hf hg #align function.is_periodic_pt.comp Function.IsPeriodicPt.comp theorem comp_lcm {g : α → α} (hco : Commute f g) (hf : IsPeriodicPt f m x) (hg : IsPeriodicPt g n x) : IsPeriodicPt (f ∘ g) (Nat.lcm m n) x := (hf.trans_dvd <| Nat.dvd_lcm_left _ _).comp hco (hg.trans_dvd <| Nat.dvd_lcm_right _ _) #align function.is_periodic_pt.comp_lcm Function.IsPeriodicPt.comp_lcm theorem left_of_comp {g : α → α} (hco : Commute f g) (hfg : IsPeriodicPt (f ∘ g) n x) (hg : IsPeriodicPt g n x) : IsPeriodicPt f n x := by rw [IsPeriodicPt, hco.comp_iterate] at hfg exact hfg.left_of_comp hg #align function.is_periodic_pt.left_of_comp Function.IsPeriodicPt.left_of_comp theorem iterate_mod_apply (h : IsPeriodicPt f n x) (m : ℕ) : f^[m % n] x = f^[m] x := by conv_rhs => rw [← Nat.mod_add_div m n, iterate_add_apply, (h.mul_const _).eq] #align function.is_periodic_pt.iterate_mod_apply Function.IsPeriodicPt.iterate_mod_apply protected theorem mod (hm : IsPeriodicPt f m x) (hn : IsPeriodicPt f n x) : IsPeriodicPt f (m % n) x := (hn.iterate_mod_apply m).trans hm #align function.is_periodic_pt.mod Function.IsPeriodicPt.mod protected theorem gcd (hm : IsPeriodicPt f m x) (hn : IsPeriodicPt f n x) : IsPeriodicPt f (m.gcd n) x := by revert hm hn refine Nat.gcd.induction m n (fun n _ hn => ?_) fun m n _ ih hm hn => ?_ · rwa [Nat.gcd_zero_left] · rw [Nat.gcd_rec] exact ih (hn.mod hm) hm #align function.is_periodic_pt.gcd Function.IsPeriodicPt.gcd /-- If `f` sends two periodic points `x` and `y` of the same positive period to the same point, then `x = y`. For a similar statement about points of different periods see `eq_of_apply_eq`. -/ theorem eq_of_apply_eq_same (hx : IsPeriodicPt f n x) (hy : IsPeriodicPt f n y) (hn : 0 < n) (h : f x = f y) : x = y := by rw [← hx.eq, ← hy.eq, ← iterate_pred_comp_of_pos f hn, comp_apply, comp_apply, h] #align function.is_periodic_pt.eq_of_apply_eq_same Function.IsPeriodicPt.eq_of_apply_eq_same /-- If `f` sends two periodic points `x` and `y` of positive periods to the same point, then `x = y`. -/ theorem eq_of_apply_eq (hx : IsPeriodicPt f m x) (hy : IsPeriodicPt f n y) (hm : 0 < m) (hn : 0 < n) (h : f x = f y) : x = y := (hx.mul_const n).eq_of_apply_eq_same (hy.const_mul m) (mul_pos hm hn) h #align function.is_periodic_pt.eq_of_apply_eq Function.IsPeriodicPt.eq_of_apply_eq end IsPeriodicPt /-- The set of periodic points of a given (possibly non-minimal) period. -/ def ptsOfPeriod (f : α → α) (n : ℕ) : Set α := { x : α | IsPeriodicPt f n x } #align function.pts_of_period Function.ptsOfPeriod @[simp] theorem mem_ptsOfPeriod : x ∈ ptsOfPeriod f n ↔ IsPeriodicPt f n x := Iff.rfl #align function.mem_pts_of_period Function.mem_ptsOfPeriod theorem Semiconj.mapsTo_ptsOfPeriod {g : α → β} (h : Semiconj g fa fb) (n : ℕ) : MapsTo g (ptsOfPeriod fa n) (ptsOfPeriod fb n) := (h.iterate_right n).mapsTo_fixedPoints #align function.semiconj.maps_to_pts_of_period Function.Semiconj.mapsTo_ptsOfPeriod theorem bijOn_ptsOfPeriod (f : α → α) {n : ℕ} (hn : 0 < n) : BijOn f (ptsOfPeriod f n) (ptsOfPeriod f n) := ⟨(Commute.refl f).mapsTo_ptsOfPeriod n, fun x hx y hy hxy => hx.eq_of_apply_eq_same hy hn hxy, fun x hx => ⟨f^[n.pred] x, hx.apply_iterate _, by rw [← comp_apply (f := f), comp_iterate_pred_of_pos f hn, hx.eq]⟩⟩ #align function.bij_on_pts_of_period Function.bijOn_ptsOfPeriod theorem directed_ptsOfPeriod_pNat (f : α → α) : Directed (· ⊆ ·) fun n : ℕ+ => ptsOfPeriod f n := fun m n => ⟨m * n, fun _ hx => hx.mul_const n, fun _ hx => hx.const_mul m⟩ #align function.directed_pts_of_period_pnat Function.directed_ptsOfPeriod_pNat /-- The set of periodic points of a map `f : α → α`. -/ def periodicPts (f : α → α) : Set α := { x : α | ∃ n > 0, IsPeriodicPt f n x } #align function.periodic_pts Function.periodicPts theorem mk_mem_periodicPts (hn : 0 < n) (hx : IsPeriodicPt f n x) : x ∈ periodicPts f := ⟨n, hn, hx⟩ #align function.mk_mem_periodic_pts Function.mk_mem_periodicPts theorem mem_periodicPts : x ∈ periodicPts f ↔ ∃ n > 0, IsPeriodicPt f n x := Iff.rfl #align function.mem_periodic_pts Function.mem_periodicPts theorem isPeriodicPt_of_mem_periodicPts_of_isPeriodicPt_iterate (hx : x ∈ periodicPts f) (hm : IsPeriodicPt f m (f^[n] x)) : IsPeriodicPt f m x := by rcases hx with ⟨r, hr, hr'⟩ suffices n ≤ (n / r + 1) * r by -- Porting note: convert used to unfold IsPeriodicPt change _ = _ convert (hm.apply_iterate ((n / r + 1) * r - n)).eq <;> rw [← iterate_add_apply, Nat.sub_add_cancel this, iterate_mul, (hr'.iterate _).eq] rw [add_mul, one_mul] exact (Nat.lt_div_mul_add hr).le #align function.is_periodic_pt_of_mem_periodic_pts_of_is_periodic_pt_iterate Function.isPeriodicPt_of_mem_periodicPts_of_isPeriodicPt_iterate variable (f) theorem bUnion_ptsOfPeriod : ⋃ n > 0, ptsOfPeriod f n = periodicPts f := Set.ext fun x => by simp [mem_periodicPts] #align function.bUnion_pts_of_period Function.bUnion_ptsOfPeriod theorem iUnion_pNat_ptsOfPeriod : ⋃ n : ℕ+, ptsOfPeriod f n = periodicPts f := iSup_subtype.trans <| bUnion_ptsOfPeriod f #align function.Union_pnat_pts_of_period Function.iUnion_pNat_ptsOfPeriod theorem bijOn_periodicPts : BijOn f (periodicPts f) (periodicPts f) := iUnion_pNat_ptsOfPeriod f ▸ bijOn_iUnion_of_directed (directed_ptsOfPeriod_pNat f) fun i => bijOn_ptsOfPeriod f i.pos #align function.bij_on_periodic_pts Function.bijOn_periodicPts variable {f} theorem Semiconj.mapsTo_periodicPts {g : α → β} (h : Semiconj g fa fb) : MapsTo g (periodicPts fa) (periodicPts fb) := fun _ ⟨n, hn, hx⟩ => ⟨n, hn, hx.map h⟩ #align function.semiconj.maps_to_periodic_pts Function.Semiconj.mapsTo_periodicPts open scoped Classical noncomputable section /-- Minimal period of a point `x` under an endomorphism `f`. If `x` is not a periodic point of `f`, then `minimalPeriod f x = 0`. -/ def minimalPeriod (f : α → α) (x : α) := if h : x ∈ periodicPts f then Nat.find h else 0 #align function.minimal_period Function.minimalPeriod theorem isPeriodicPt_minimalPeriod (f : α → α) (x : α) : IsPeriodicPt f (minimalPeriod f x) x := by delta minimalPeriod split_ifs with hx · exact (Nat.find_spec hx).2 · exact isPeriodicPt_zero f x #align function.is_periodic_pt_minimal_period Function.isPeriodicPt_minimalPeriod @[simp] theorem iterate_minimalPeriod : f^[minimalPeriod f x] x = x := isPeriodicPt_minimalPeriod f x #align function.iterate_minimal_period Function.iterate_minimalPeriod @[simp] theorem iterate_add_minimalPeriod_eq : f^[n + minimalPeriod f x] x = f^[n] x := by rw [iterate_add_apply] congr exact isPeriodicPt_minimalPeriod f x #align function.iterate_add_minimal_period_eq Function.iterate_add_minimalPeriod_eq @[simp] theorem iterate_mod_minimalPeriod_eq : f^[n % minimalPeriod f x] x = f^[n] x := (isPeriodicPt_minimalPeriod f x).iterate_mod_apply n #align function.iterate_mod_minimal_period_eq Function.iterate_mod_minimalPeriod_eq theorem minimalPeriod_pos_of_mem_periodicPts (hx : x ∈ periodicPts f) : 0 < minimalPeriod f x := by simp only [minimalPeriod, dif_pos hx, (Nat.find_spec hx).1.lt] #align function.minimal_period_pos_of_mem_periodic_pts Function.minimalPeriod_pos_of_mem_periodicPts theorem minimalPeriod_eq_zero_of_nmem_periodicPts (hx : x ∉ periodicPts f) : minimalPeriod f x = 0 := by simp only [minimalPeriod, dif_neg hx] #align function.minimal_period_eq_zero_of_nmem_periodic_pts Function.minimalPeriod_eq_zero_of_nmem_periodicPts theorem IsPeriodicPt.minimalPeriod_pos (hn : 0 < n) (hx : IsPeriodicPt f n x) : 0 < minimalPeriod f x := minimalPeriod_pos_of_mem_periodicPts <| mk_mem_periodicPts hn hx #align function.is_periodic_pt.minimal_period_pos Function.IsPeriodicPt.minimalPeriod_pos theorem minimalPeriod_pos_iff_mem_periodicPts : 0 < minimalPeriod f x ↔ x ∈ periodicPts f := ⟨not_imp_not.1 fun h => by simp only [minimalPeriod, dif_neg h, lt_irrefl 0, not_false_iff], minimalPeriod_pos_of_mem_periodicPts⟩ #align function.minimal_period_pos_iff_mem_periodic_pts Function.minimalPeriod_pos_iff_mem_periodicPts theorem minimalPeriod_eq_zero_iff_nmem_periodicPts : minimalPeriod f x = 0 ↔ x ∉ periodicPts f := by rw [← minimalPeriod_pos_iff_mem_periodicPts, not_lt, nonpos_iff_eq_zero] #align function.minimal_period_eq_zero_iff_nmem_periodic_pts Function.minimalPeriod_eq_zero_iff_nmem_periodicPts theorem IsPeriodicPt.minimalPeriod_le (hn : 0 < n) (hx : IsPeriodicPt f n x) : minimalPeriod f x ≤ n := by rw [minimalPeriod, dif_pos (mk_mem_periodicPts hn hx)] exact Nat.find_min' (mk_mem_periodicPts hn hx) ⟨hn, hx⟩ #align function.is_periodic_pt.minimal_period_le Function.IsPeriodicPt.minimalPeriod_le theorem minimalPeriod_apply_iterate (hx : x ∈ periodicPts f) (n : ℕ) : minimalPeriod f (f^[n] x) = minimalPeriod f x := by apply (IsPeriodicPt.minimalPeriod_le (minimalPeriod_pos_of_mem_periodicPts hx) _).antisymm ((isPeriodicPt_of_mem_periodicPts_of_isPeriodicPt_iterate hx (isPeriodicPt_minimalPeriod f _)).minimalPeriod_le (minimalPeriod_pos_of_mem_periodicPts _)) · exact (isPeriodicPt_minimalPeriod f x).apply_iterate n · rcases hx with ⟨m, hm, hx⟩ exact ⟨m, hm, hx.apply_iterate n⟩ #align function.minimal_period_apply_iterate Function.minimalPeriod_apply_iterate theorem minimalPeriod_apply (hx : x ∈ periodicPts f) : minimalPeriod f (f x) = minimalPeriod f x := minimalPeriod_apply_iterate hx 1 #align function.minimal_period_apply Function.minimalPeriod_apply theorem le_of_lt_minimalPeriod_of_iterate_eq {m n : ℕ} (hm : m < minimalPeriod f x) (hmn : f^[m] x = f^[n] x) : m ≤ n := by by_contra! hmn' rw [← Nat.add_sub_of_le hmn'.le, add_comm, iterate_add_apply] at hmn exact ((IsPeriodicPt.minimalPeriod_le (tsub_pos_of_lt hmn') (isPeriodicPt_of_mem_periodicPts_of_isPeriodicPt_iterate (minimalPeriod_pos_iff_mem_periodicPts.1 ((zero_le m).trans_lt hm)) hmn)).trans (Nat.sub_le m n)).not_lt hm #align function.le_of_lt_minimal_period_of_iterate_eq Function.le_of_lt_minimalPeriod_of_iterate_eq theorem iterate_injOn_Iio_minimalPeriod : (Iio <| minimalPeriod f x).InjOn (f^[·] x) := fun _m hm _n hn hmn ↦ (le_of_lt_minimalPeriod_of_iterate_eq hm hmn).antisymm (le_of_lt_minimalPeriod_of_iterate_eq hn hmn.symm) #align function.eq_of_lt_minimal_period_of_iterate_eq Function.iterate_injOn_Iio_minimalPeriod theorem iterate_eq_iterate_iff_of_lt_minimalPeriod {m n : ℕ} (hm : m < minimalPeriod f x) (hn : n < minimalPeriod f x) : f^[m] x = f^[n] x ↔ m = n := iterate_injOn_Iio_minimalPeriod.eq_iff hm hn #align function.eq_iff_lt_minimal_period_of_iterate_eq Function.iterate_eq_iterate_iff_of_lt_minimalPeriod @[simp] theorem minimalPeriod_id : minimalPeriod id x = 1 := ((is_periodic_id _ _).minimalPeriod_le Nat.one_pos).antisymm (Nat.succ_le_of_lt ((is_periodic_id _ _).minimalPeriod_pos Nat.one_pos)) #align function.minimal_period_id Function.minimalPeriod_id theorem minimalPeriod_eq_one_iff_isFixedPt : minimalPeriod f x = 1 ↔ IsFixedPt f x := by refine ⟨fun h => ?_, fun h => ?_⟩ · rw [← iterate_one f] refine Function.IsPeriodicPt.isFixedPt ?_ rw [← h] exact isPeriodicPt_minimalPeriod f x · exact ((h.isPeriodicPt 1).minimalPeriod_le Nat.one_pos).antisymm (Nat.succ_le_of_lt ((h.isPeriodicPt 1).minimalPeriod_pos Nat.one_pos)) #align function.is_fixed_point_iff_minimal_period_eq_one Function.minimalPeriod_eq_one_iff_isFixedPt theorem IsPeriodicPt.eq_zero_of_lt_minimalPeriod (hx : IsPeriodicPt f n x) (hn : n < minimalPeriod f x) : n = 0 := Eq.symm <| (eq_or_lt_of_le <| n.zero_le).resolve_right fun hn0 => not_lt.2 (hx.minimalPeriod_le hn0) hn #align function.is_periodic_pt.eq_zero_of_lt_minimal_period Function.IsPeriodicPt.eq_zero_of_lt_minimalPeriod theorem not_isPeriodicPt_of_pos_of_lt_minimalPeriod : ∀ {n : ℕ} (_ : n ≠ 0) (_ : n < minimalPeriod f x), ¬IsPeriodicPt f n x | 0, n0, _ => (n0 rfl).elim | _ + 1, _, hn => fun hp => Nat.succ_ne_zero _ (hp.eq_zero_of_lt_minimalPeriod hn) #align function.not_is_periodic_pt_of_pos_of_lt_minimal_period Function.not_isPeriodicPt_of_pos_of_lt_minimalPeriod theorem IsPeriodicPt.minimalPeriod_dvd (hx : IsPeriodicPt f n x) : minimalPeriod f x ∣ n := (eq_or_lt_of_le <| n.zero_le).elim (fun hn0 => hn0 ▸ dvd_zero _) fun hn0 => -- Porting note: `Nat.dvd_iff_mod_eq_zero` gained explicit arguments (Nat.dvd_iff_mod_eq_zero _ _).2 <| (hx.mod <| isPeriodicPt_minimalPeriod f x).eq_zero_of_lt_minimalPeriod <| Nat.mod_lt _ <| hx.minimalPeriod_pos hn0 #align function.is_periodic_pt.minimal_period_dvd Function.IsPeriodicPt.minimalPeriod_dvd theorem isPeriodicPt_iff_minimalPeriod_dvd : IsPeriodicPt f n x ↔ minimalPeriod f x ∣ n := ⟨IsPeriodicPt.minimalPeriod_dvd, fun h => (isPeriodicPt_minimalPeriod f x).trans_dvd h⟩ #align function.is_periodic_pt_iff_minimal_period_dvd Function.isPeriodicPt_iff_minimalPeriod_dvd open Nat theorem minimalPeriod_eq_minimalPeriod_iff {g : β → β} {y : β} : minimalPeriod f x = minimalPeriod g y ↔ ∀ n, IsPeriodicPt f n x ↔ IsPeriodicPt g n y := by simp_rw [isPeriodicPt_iff_minimalPeriod_dvd, dvd_right_iff_eq] #align function.minimal_period_eq_minimal_period_iff Function.minimalPeriod_eq_minimalPeriod_iff theorem minimalPeriod_eq_prime {p : ℕ} [hp : Fact p.Prime] (hper : IsPeriodicPt f p x) (hfix : ¬IsFixedPt f x) : minimalPeriod f x = p := (hp.out.eq_one_or_self_of_dvd _ hper.minimalPeriod_dvd).resolve_left (mt minimalPeriod_eq_one_iff_isFixedPt.1 hfix) #align function.minimal_period_eq_prime Function.minimalPeriod_eq_prime theorem minimalPeriod_eq_prime_pow {p k : ℕ} [hp : Fact p.Prime] (hk : ¬IsPeriodicPt f (p ^ k) x) (hk1 : IsPeriodicPt f (p ^ (k + 1)) x) : minimalPeriod f x = p ^ (k + 1) := by apply Nat.eq_prime_pow_of_dvd_least_prime_pow hp.out <;> rwa [← isPeriodicPt_iff_minimalPeriod_dvd] #align function.minimal_period_eq_prime_pow Function.minimalPeriod_eq_prime_pow theorem Commute.minimalPeriod_of_comp_dvd_lcm {g : α → α} (h : Commute f g) : minimalPeriod (f ∘ g) x ∣ Nat.lcm (minimalPeriod f x) (minimalPeriod g x) := by rw [← isPeriodicPt_iff_minimalPeriod_dvd] exact (isPeriodicPt_minimalPeriod f x).comp_lcm h (isPeriodicPt_minimalPeriod g x) #align function.commute.minimal_period_of_comp_dvd_lcm Function.Commute.minimalPeriod_of_comp_dvd_lcm theorem Commute.minimalPeriod_of_comp_dvd_mul {g : α → α} (h : Commute f g) : minimalPeriod (f ∘ g) x ∣ minimalPeriod f x * minimalPeriod g x := dvd_trans h.minimalPeriod_of_comp_dvd_lcm (lcm_dvd_mul _ _) #align function.commute.minimal_period_of_comp_dvd_mul Function.Commute.minimalPeriod_of_comp_dvd_mul theorem Commute.minimalPeriod_of_comp_eq_mul_of_coprime {g : α → α} (h : Commute f g) (hco : Coprime (minimalPeriod f x) (minimalPeriod g x)) : minimalPeriod (f ∘ g) x = minimalPeriod f x * minimalPeriod g x := by apply h.minimalPeriod_of_comp_dvd_mul.antisymm suffices ∀ {f g : α → α}, Commute f g → Coprime (minimalPeriod f x) (minimalPeriod g x) → minimalPeriod f x ∣ minimalPeriod (f ∘ g) x from hco.mul_dvd_of_dvd_of_dvd (this h hco) (h.comp_eq.symm ▸ this h.symm hco.symm) intro f g h hco refine hco.dvd_of_dvd_mul_left (IsPeriodicPt.left_of_comp h ?_ ?_).minimalPeriod_dvd · exact (isPeriodicPt_minimalPeriod _ _).const_mul _ · exact (isPeriodicPt_minimalPeriod _ _).mul_const _ #align function.commute.minimal_period_of_comp_eq_mul_of_coprime Function.Commute.minimalPeriod_of_comp_eq_mul_of_coprime private theorem minimalPeriod_iterate_eq_div_gcd_aux (h : 0 < gcd (minimalPeriod f x) n) : minimalPeriod f^[n] x = minimalPeriod f x / Nat.gcd (minimalPeriod f x) n := by apply Nat.dvd_antisymm · apply IsPeriodicPt.minimalPeriod_dvd rw [IsPeriodicPt, IsFixedPt, ← iterate_mul, ← Nat.mul_div_assoc _ (gcd_dvd_left _ _), mul_comm, Nat.mul_div_assoc _ (gcd_dvd_right _ _), mul_comm, iterate_mul] exact (isPeriodicPt_minimalPeriod f x).iterate _ · apply Coprime.dvd_of_dvd_mul_right (coprime_div_gcd_div_gcd h) apply Nat.dvd_of_mul_dvd_mul_right h rw [Nat.div_mul_cancel (gcd_dvd_left _ _), mul_assoc, Nat.div_mul_cancel (gcd_dvd_right _ _), mul_comm] apply IsPeriodicPt.minimalPeriod_dvd rw [IsPeriodicPt, IsFixedPt, iterate_mul] exact isPeriodicPt_minimalPeriod _ _ theorem minimalPeriod_iterate_eq_div_gcd (h : n ≠ 0) : minimalPeriod f^[n] x = minimalPeriod f x / Nat.gcd (minimalPeriod f x) n := minimalPeriod_iterate_eq_div_gcd_aux <| gcd_pos_of_pos_right _ (Nat.pos_of_ne_zero h) #align function.minimal_period_iterate_eq_div_gcd Function.minimalPeriod_iterate_eq_div_gcd theorem minimalPeriod_iterate_eq_div_gcd' (h : x ∈ periodicPts f) : minimalPeriod f^[n] x = minimalPeriod f x / Nat.gcd (minimalPeriod f x) n := minimalPeriod_iterate_eq_div_gcd_aux <| gcd_pos_of_pos_left n (minimalPeriod_pos_iff_mem_periodicPts.mpr h) #align function.minimal_period_iterate_eq_div_gcd' Function.minimalPeriod_iterate_eq_div_gcd' /-- The orbit of a periodic point `x` of `f` is the cycle `[x, f x, f (f x), ...]`. Its length is the minimal period of `x`. If `x` is not a periodic point, then this is the empty (aka nil) cycle. -/ def periodicOrbit (f : α → α) (x : α) : Cycle α := (List.range (minimalPeriod f x)).map fun n => f^[n] x #align function.periodic_orbit Function.periodicOrbit /-- The definition of a periodic orbit, in terms of `List.map`. -/ theorem periodicOrbit_def (f : α → α) (x : α) : periodicOrbit f x = (List.range (minimalPeriod f x)).map fun n => f^[n] x := rfl #align function.periodic_orbit_def Function.periodicOrbit_def /-- The definition of a periodic orbit, in terms of `Cycle.map`. -/ theorem periodicOrbit_eq_cycle_map (f : α → α) (x : α) : periodicOrbit f x = (List.range (minimalPeriod f x) : Cycle ℕ).map fun n => f^[n] x := rfl #align function.periodic_orbit_eq_cycle_map Function.periodicOrbit_eq_cycle_map @[simp] theorem periodicOrbit_length : (periodicOrbit f x).length = minimalPeriod f x := by rw [periodicOrbit, Cycle.length_coe, List.length_map, List.length_range] #align function.periodic_orbit_length Function.periodicOrbit_length @[simp] theorem periodicOrbit_eq_nil_iff_not_periodic_pt : periodicOrbit f x = Cycle.nil ↔ x ∉ periodicPts f := by simp only [periodicOrbit.eq_1, Cycle.coe_eq_nil, List.map_eq_nil, List.range_eq_nil] exact minimalPeriod_eq_zero_iff_nmem_periodicPts #align function.periodic_orbit_eq_nil_iff_not_periodic_pt Function.periodicOrbit_eq_nil_iff_not_periodic_pt theorem periodicOrbit_eq_nil_of_not_periodic_pt (h : x ∉ periodicPts f) : periodicOrbit f x = Cycle.nil := periodicOrbit_eq_nil_iff_not_periodic_pt.2 h #align function.periodic_orbit_eq_nil_of_not_periodic_pt Function.periodicOrbit_eq_nil_of_not_periodic_pt @[simp] theorem mem_periodicOrbit_iff (hx : x ∈ periodicPts f) : y ∈ periodicOrbit f x ↔ ∃ n, f^[n] x = y := by simp only [periodicOrbit, Cycle.mem_coe_iff, List.mem_map, List.mem_range] use fun ⟨a, _, ha'⟩ => ⟨a, ha'⟩ rintro ⟨n, rfl⟩ use n % minimalPeriod f x, mod_lt _ (minimalPeriod_pos_of_mem_periodicPts hx) rw [iterate_mod_minimalPeriod_eq] #align function.mem_periodic_orbit_iff Function.mem_periodicOrbit_iff @[simp] theorem iterate_mem_periodicOrbit (hx : x ∈ periodicPts f) (n : ℕ) : f^[n] x ∈ periodicOrbit f x := (mem_periodicOrbit_iff hx).2 ⟨n, rfl⟩ #align function.iterate_mem_periodic_orbit Function.iterate_mem_periodicOrbit @[simp] theorem self_mem_periodicOrbit (hx : x ∈ periodicPts f) : x ∈ periodicOrbit f x := iterate_mem_periodicOrbit hx 0 #align function.self_mem_periodic_orbit Function.self_mem_periodicOrbit theorem nodup_periodicOrbit : (periodicOrbit f x).Nodup := by rw [periodicOrbit, Cycle.nodup_coe_iff, List.nodup_map_iff_inj_on (List.nodup_range _)] intro m hm n hn hmn rw [List.mem_range] at hm hn rwa [iterate_eq_iterate_iff_of_lt_minimalPeriod hm hn] at hmn #align function.nodup_periodic_orbit Function.nodup_periodicOrbit theorem periodicOrbit_apply_iterate_eq (hx : x ∈ periodicPts f) (n : ℕ) : periodicOrbit f (f^[n] x) = periodicOrbit f x := Eq.symm <| Cycle.coe_eq_coe.2 <| .intro n <| List.ext_get (by simp [minimalPeriod_apply_iterate hx]) fun m _ _ ↦ by simp [List.get_rotate, iterate_add_apply] #align function.periodic_orbit_apply_iterate_eq Function.periodicOrbit_apply_iterate_eq theorem periodicOrbit_apply_eq (hx : x ∈ periodicPts f) : periodicOrbit f (f x) = periodicOrbit f x := periodicOrbit_apply_iterate_eq hx 1 #align function.periodic_orbit_apply_eq Function.periodicOrbit_apply_eq theorem periodicOrbit_chain (r : α → α → Prop) {f : α → α} {x : α} : (periodicOrbit f x).Chain r ↔ ∀ n < minimalPeriod f x, r (f^[n] x) (f^[n + 1] x) := by by_cases hx : x ∈ periodicPts f · have hx' := minimalPeriod_pos_of_mem_periodicPts hx have hM := Nat.sub_add_cancel (succ_le_iff.2 hx') rw [periodicOrbit, ← Cycle.map_coe, Cycle.chain_map, ← hM, Cycle.chain_range_succ] refine ⟨?_, fun H => ⟨?_, fun m hm => H _ (hm.trans (Nat.lt_succ_self _))⟩⟩ · rintro ⟨hr, H⟩ n hn cases' eq_or_lt_of_le (Nat.lt_succ_iff.1 hn) with hM' hM' · rwa [hM', hM, iterate_minimalPeriod] · exact H _ hM' · rw [iterate_zero_apply] nth_rw 3 [← @iterate_minimalPeriod α f x] nth_rw 2 [← hM] exact H _ (Nat.lt_succ_self _) · rw [periodicOrbit_eq_nil_of_not_periodic_pt hx, minimalPeriod_eq_zero_of_nmem_periodicPts hx] simp #align function.periodic_orbit_chain Function.periodicOrbit_chain
Mathlib/Dynamics/PeriodicPts.lean
577
583
theorem periodicOrbit_chain' (r : α → α → Prop) {f : α → α} {x : α} (hx : x ∈ periodicPts f) : (periodicOrbit f x).Chain r ↔ ∀ n, r (f^[n] x) (f^[n + 1] x) := by
rw [periodicOrbit_chain r] refine ⟨fun H n => ?_, fun H n _ => H n⟩ rw [iterate_succ_apply, ← iterate_mod_minimalPeriod_eq, ← iterate_mod_minimalPeriod_eq (n := n), ← iterate_succ_apply, minimalPeriod_apply hx] exact H _ (mod_lt _ (minimalPeriod_pos_of_mem_periodicPts hx))
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Frédéric Dupuis -/ import Mathlib.Analysis.Convex.Cone.Basic import Mathlib.Data.Real.Archimedean import Mathlib.LinearAlgebra.LinearPMap #align_import analysis.convex.cone.basic from "leanprover-community/mathlib"@"915591b2bb3ea303648db07284a161a7f2a9e3d4" /-! # Extension theorems We prove two extension theorems: * `riesz_extension`: [M. Riesz extension theorem](https://en.wikipedia.org/wiki/M._Riesz_extension_theorem) says that if `s` is a convex cone in a real vector space `E`, `p` is a submodule of `E` such that `p + s = E`, and `f` is a linear function `p → ℝ` which is nonnegative on `p ∩ s`, then there exists a globally defined linear function `g : E → ℝ` that agrees with `f` on `p`, and is nonnegative on `s`. * `exists_extension_of_le_sublinear`: Hahn-Banach theorem: if `N : E → ℝ` is a sublinear map, `f` is a linear map defined on a subspace of `E`, and `f x ≤ N x` for all `x` in the domain of `f`, then `f` can be extended to the whole space to a linear map `g` such that `g x ≤ N x` for all `x` -/ open Set LinearMap variable {𝕜 E F G : Type*} /-! ### M. Riesz extension theorem Given a convex cone `s` in a vector space `E`, a submodule `p`, and a linear `f : p → ℝ`, assume that `f` is nonnegative on `p ∩ s` and `p + s = E`. Then there exists a globally defined linear function `g : E → ℝ` that agrees with `f` on `p`, and is nonnegative on `s`. We prove this theorem using Zorn's lemma. `RieszExtension.step` is the main part of the proof. It says that if the domain `p` of `f` is not the whole space, then `f` can be extended to a larger subspace `p ⊔ span ℝ {y}` without breaking the non-negativity condition. In `RieszExtension.exists_top` we use Zorn's lemma to prove that we can extend `f` to a linear map `g` on `⊤ : Submodule E`. Mathematically this is the same as a linear map on `E` but in Lean `⊤ : Submodule E` is isomorphic but is not equal to `E`. In `riesz_extension` we use this isomorphism to prove the theorem. -/ variable [AddCommGroup E] [Module ℝ E] namespace RieszExtension open Submodule variable (s : ConvexCone ℝ E) (f : E →ₗ.[ℝ] ℝ) /-- Induction step in M. Riesz extension theorem. Given a convex cone `s` in a vector space `E`, a partially defined linear map `f : f.domain → ℝ`, assume that `f` is nonnegative on `f.domain ∩ p` and `p + s = E`. If `f` is not defined on the whole `E`, then we can extend it to a larger submodule without breaking the non-negativity condition. -/ theorem step (nonneg : ∀ x : f.domain, (x : E) ∈ s → 0 ≤ f x) (dense : ∀ y, ∃ x : f.domain, (x : E) + y ∈ s) (hdom : f.domain ≠ ⊤) : ∃ g, f < g ∧ ∀ x : g.domain, (x : E) ∈ s → 0 ≤ g x := by obtain ⟨y, -, hy⟩ : ∃ y ∈ ⊤, y ∉ f.domain := SetLike.exists_of_lt (lt_top_iff_ne_top.2 hdom) obtain ⟨c, le_c, c_le⟩ : ∃ c, (∀ x : f.domain, -(x : E) - y ∈ s → f x ≤ c) ∧ ∀ x : f.domain, (x : E) + y ∈ s → c ≤ f x := by set Sp := f '' { x : f.domain | (x : E) + y ∈ s } set Sn := f '' { x : f.domain | -(x : E) - y ∈ s } suffices (upperBounds Sn ∩ lowerBounds Sp).Nonempty by simpa only [Set.Nonempty, upperBounds, lowerBounds, forall_mem_image] using this refine exists_between_of_forall_le (Nonempty.image f ?_) (Nonempty.image f (dense y)) ?_ · rcases dense (-y) with ⟨x, hx⟩ rw [← neg_neg x, NegMemClass.coe_neg, ← sub_eq_add_neg] at hx exact ⟨_, hx⟩ rintro a ⟨xn, hxn, rfl⟩ b ⟨xp, hxp, rfl⟩ have := s.add_mem hxp hxn rw [add_assoc, add_sub_cancel, ← sub_eq_add_neg, ← AddSubgroupClass.coe_sub] at this replace := nonneg _ this rwa [f.map_sub, sub_nonneg] at this -- Porting note: removed an unused `have` refine ⟨f.supSpanSingleton y (-c) hy, ?_, ?_⟩ · refine lt_iff_le_not_le.2 ⟨f.left_le_sup _ _, fun H => ?_⟩ replace H := LinearPMap.domain_mono.monotone H rw [LinearPMap.domain_supSpanSingleton, sup_le_iff, span_le, singleton_subset_iff] at H exact hy H.2 · rintro ⟨z, hz⟩ hzs rcases mem_sup.1 hz with ⟨x, hx, y', hy', rfl⟩ rcases mem_span_singleton.1 hy' with ⟨r, rfl⟩ simp only [Subtype.coe_mk] at hzs erw [LinearPMap.supSpanSingleton_apply_mk _ _ _ _ _ hx, smul_neg, ← sub_eq_add_neg, sub_nonneg] rcases lt_trichotomy r 0 with (hr | hr | hr) · have : -(r⁻¹ • x) - y ∈ s := by rwa [← s.smul_mem_iff (neg_pos.2 hr), smul_sub, smul_neg, neg_smul, neg_neg, smul_smul, mul_inv_cancel hr.ne, one_smul, sub_eq_add_neg, neg_smul, neg_neg] -- Porting note: added type annotation and `by exact` replace : f (r⁻¹ • ⟨x, hx⟩) ≤ c := le_c (r⁻¹ • ⟨x, hx⟩) (by exact this) rwa [← mul_le_mul_left (neg_pos.2 hr), neg_mul, neg_mul, neg_le_neg_iff, f.map_smul, smul_eq_mul, ← mul_assoc, mul_inv_cancel hr.ne, one_mul] at this · subst r simp only [zero_smul, add_zero] at hzs ⊢ apply nonneg exact hzs · have : r⁻¹ • x + y ∈ s := by rwa [← s.smul_mem_iff hr, smul_add, smul_smul, mul_inv_cancel hr.ne', one_smul] -- Porting note: added type annotation and `by exact` replace : c ≤ f (r⁻¹ • ⟨x, hx⟩) := c_le (r⁻¹ • ⟨x, hx⟩) (by exact this) rwa [← mul_le_mul_left hr, f.map_smul, smul_eq_mul, ← mul_assoc, mul_inv_cancel hr.ne', one_mul] at this #align riesz_extension.step RieszExtension.step
Mathlib/Analysis/Convex/Cone/Extension.lean
115
139
theorem exists_top (p : E →ₗ.[ℝ] ℝ) (hp_nonneg : ∀ x : p.domain, (x : E) ∈ s → 0 ≤ p x) (hp_dense : ∀ y, ∃ x : p.domain, (x : E) + y ∈ s) : ∃ q ≥ p, q.domain = ⊤ ∧ ∀ x : q.domain, (x : E) ∈ s → 0 ≤ q x := by
set S := { p : E →ₗ.[ℝ] ℝ | ∀ x : p.domain, (x : E) ∈ s → 0 ≤ p x } have hSc : ∀ c, c ⊆ S → IsChain (· ≤ ·) c → ∀ y ∈ c, ∃ ub ∈ S, ∀ z ∈ c, z ≤ ub := by intro c hcs c_chain y hy clear hp_nonneg hp_dense p have cne : c.Nonempty := ⟨y, hy⟩ have hcd : DirectedOn (· ≤ ·) c := c_chain.directedOn refine ⟨LinearPMap.sSup c hcd, ?_, fun _ ↦ LinearPMap.le_sSup hcd⟩ rintro ⟨x, hx⟩ hxs have hdir : DirectedOn (· ≤ ·) (LinearPMap.domain '' c) := directedOn_image.2 (hcd.mono LinearPMap.domain_mono.monotone) rcases (mem_sSup_of_directed (cne.image _) hdir).1 hx with ⟨_, ⟨f, hfc, rfl⟩, hfx⟩ have : f ≤ LinearPMap.sSup c hcd := LinearPMap.le_sSup _ hfc convert ← hcs hfc ⟨x, hfx⟩ hxs using 1 exact this.2 rfl obtain ⟨q, hqs, hpq, hq⟩ := zorn_nonempty_partialOrder₀ S hSc p hp_nonneg refine ⟨q, hpq, ?_, hqs⟩ contrapose! hq have hqd : ∀ y, ∃ x : q.domain, (x : E) + y ∈ s := fun y ↦ let ⟨x, hx⟩ := hp_dense y ⟨Submodule.inclusion hpq.left x, hx⟩ rcases step s q hqs hqd hq with ⟨r, hqr, hr⟩ exact ⟨r, hr, hqr.le, hqr.ne'⟩
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Topology.Compactness.SigmaCompact import Mathlib.Topology.Connected.TotallyDisconnected import Mathlib.Topology.Inseparable #align_import topology.separation from "leanprover-community/mathlib"@"d91e7f7a7f1c7e9f0e18fdb6bde4f652004c735d" /-! # Separation properties of topological spaces. This file defines the predicate `SeparatedNhds`, and common separation axioms (under the Kolmogorov classification). ## Main definitions * `SeparatedNhds`: Two `Set`s are separated by neighbourhoods if they are contained in disjoint open sets. * `T0Space`: A T₀/Kolmogorov space is a space where, for every two points `x ≠ y`, there is an open set that contains one, but not the other. * `R0Space`: An R₀ space (sometimes called a *symmetric space*) is a topological space such that the `Specializes` relation is symmetric. * `T1Space`: A T₁/Fréchet space is a space where every singleton set is closed. This is equivalent to, for every pair `x ≠ y`, there existing an open set containing `x` but not `y` (`t1Space_iff_exists_open` shows that these conditions are equivalent.) T₁ implies T₀ and R₀. * `R1Space`: An R₁/preregular space is a space where any two topologically distinguishable points have disjoint neighbourhoods. R₁ implies R₀. * `T2Space`: A T₂/Hausdorff space is a space where, for every two points `x ≠ y`, there is two disjoint open sets, one containing `x`, and the other `y`. T₂ implies T₁ and R₁. * `T25Space`: A T₂.₅/Urysohn space is a space where, for every two points `x ≠ y`, there is two open sets, one containing `x`, and the other `y`, whose closures are disjoint. T₂.₅ implies T₂. * `RegularSpace`: A regular space is one where, given any closed `C` and `x ∉ C`, there are disjoint open sets containing `x` and `C` respectively. Such a space is not necessarily Hausdorff. * `T3Space`: A T₃ space is a regular T₀ space. T₃ implies T₂.₅. * `NormalSpace`: A normal space, is one where given two disjoint closed sets, we can find two open sets that separate them. Such a space is not necessarily Hausdorff, even if it is T₀. * `T4Space`: A T₄ space is a normal T₁ space. T₄ implies T₃. * `CompletelyNormalSpace`: A completely normal space is one in which for any two sets `s`, `t` such that if both `closure s` is disjoint with `t`, and `s` is disjoint with `closure t`, then there exist disjoint neighbourhoods of `s` and `t`. `Embedding.completelyNormalSpace` allows us to conclude that this is equivalent to all subspaces being normal. Such a space is not necessarily Hausdorff or regular, even if it is T₀. * `T5Space`: A T₅ space is a completely normal T₁ space. T₅ implies T₄. Note that `mathlib` adopts the modern convention that `m ≤ n` if and only if `T_m → T_n`, but occasionally the literature swaps definitions for e.g. T₃ and regular. ## Main results ### T₀ spaces * `IsClosed.exists_closed_singleton`: Given a closed set `S` in a compact T₀ space, there is some `x ∈ S` such that `{x}` is closed. * `exists_isOpen_singleton_of_isOpen_finite`: Given an open finite set `S` in a T₀ space, there is some `x ∈ S` such that `{x}` is open. ### T₁ spaces * `isClosedMap_const`: The constant map is a closed map. * `discrete_of_t1_of_finite`: A finite T₁ space must have the discrete topology. ### T₂ spaces * `t2_iff_nhds`: A space is T₂ iff the neighbourhoods of distinct points generate the bottom filter. * `t2_iff_isClosed_diagonal`: A space is T₂ iff the `diagonal` of `X` (that is, the set of all points of the form `(a, a) : X × X`) is closed under the product topology. * `separatedNhds_of_finset_finset`: Any two disjoint finsets are `SeparatedNhds`. * Most topological constructions preserve Hausdorffness; these results are part of the typeclass inference system (e.g. `Embedding.t2Space`) * `Set.EqOn.closure`: If two functions are equal on some set `s`, they are equal on its closure. * `IsCompact.isClosed`: All compact sets are closed. * `WeaklyLocallyCompactSpace.locallyCompactSpace`: If a topological space is both weakly locally compact (i.e., each point has a compact neighbourhood) and is T₂, then it is locally compact. * `totallySeparatedSpace_of_t1_of_basis_clopen`: If `X` has a clopen basis, then it is a `TotallySeparatedSpace`. * `loc_compact_t2_tot_disc_iff_tot_sep`: A locally compact T₂ space is totally disconnected iff it is totally separated. * `t2Quotient`: the largest T2 quotient of a given topological space. If the space is also compact: * `normalOfCompactT2`: A compact T₂ space is a `NormalSpace`. * `connectedComponent_eq_iInter_isClopen`: The connected component of a point is the intersection of all its clopen neighbourhoods. * `compact_t2_tot_disc_iff_tot_sep`: Being a `TotallyDisconnectedSpace` is equivalent to being a `TotallySeparatedSpace`. * `ConnectedComponents.t2`: `ConnectedComponents X` is T₂ for `X` T₂ and compact. ### T₃ spaces * `disjoint_nested_nhds`: Given two points `x ≠ y`, we can find neighbourhoods `x ∈ V₁ ⊆ U₁` and `y ∈ V₂ ⊆ U₂`, with the `Vₖ` closed and the `Uₖ` open, such that the `Uₖ` are disjoint. ## References https://en.wikipedia.org/wiki/Separation_axiom -/ open Function Set Filter Topology TopologicalSpace open scoped Classical universe u v variable {X : Type*} {Y : Type*} [TopologicalSpace X] section Separation /-- `SeparatedNhds` is a predicate on pairs of sub`Set`s of a topological space. It holds if the two sub`Set`s are contained in disjoint open sets. -/ def SeparatedNhds : Set X → Set X → Prop := fun s t : Set X => ∃ U V : Set X, IsOpen U ∧ IsOpen V ∧ s ⊆ U ∧ t ⊆ V ∧ Disjoint U V #align separated_nhds SeparatedNhds theorem separatedNhds_iff_disjoint {s t : Set X} : SeparatedNhds s t ↔ Disjoint (𝓝ˢ s) (𝓝ˢ t) := by simp only [(hasBasis_nhdsSet s).disjoint_iff (hasBasis_nhdsSet t), SeparatedNhds, exists_prop, ← exists_and_left, and_assoc, and_comm, and_left_comm] #align separated_nhds_iff_disjoint separatedNhds_iff_disjoint alias ⟨SeparatedNhds.disjoint_nhdsSet, _⟩ := separatedNhds_iff_disjoint namespace SeparatedNhds variable {s s₁ s₂ t t₁ t₂ u : Set X} @[symm] theorem symm : SeparatedNhds s t → SeparatedNhds t s := fun ⟨U, V, oU, oV, aU, bV, UV⟩ => ⟨V, U, oV, oU, bV, aU, Disjoint.symm UV⟩ #align separated_nhds.symm SeparatedNhds.symm theorem comm (s t : Set X) : SeparatedNhds s t ↔ SeparatedNhds t s := ⟨symm, symm⟩ #align separated_nhds.comm SeparatedNhds.comm theorem preimage [TopologicalSpace Y] {f : X → Y} {s t : Set Y} (h : SeparatedNhds s t) (hf : Continuous f) : SeparatedNhds (f ⁻¹' s) (f ⁻¹' t) := let ⟨U, V, oU, oV, sU, tV, UV⟩ := h ⟨f ⁻¹' U, f ⁻¹' V, oU.preimage hf, oV.preimage hf, preimage_mono sU, preimage_mono tV, UV.preimage f⟩ #align separated_nhds.preimage SeparatedNhds.preimage protected theorem disjoint (h : SeparatedNhds s t) : Disjoint s t := let ⟨_, _, _, _, hsU, htV, hd⟩ := h; hd.mono hsU htV #align separated_nhds.disjoint SeparatedNhds.disjoint theorem disjoint_closure_left (h : SeparatedNhds s t) : Disjoint (closure s) t := let ⟨_U, _V, _, hV, hsU, htV, hd⟩ := h (hd.closure_left hV).mono (closure_mono hsU) htV #align separated_nhds.disjoint_closure_left SeparatedNhds.disjoint_closure_left theorem disjoint_closure_right (h : SeparatedNhds s t) : Disjoint s (closure t) := h.symm.disjoint_closure_left.symm #align separated_nhds.disjoint_closure_right SeparatedNhds.disjoint_closure_right @[simp] theorem empty_right (s : Set X) : SeparatedNhds s ∅ := ⟨_, _, isOpen_univ, isOpen_empty, fun a _ => mem_univ a, Subset.rfl, disjoint_empty _⟩ #align separated_nhds.empty_right SeparatedNhds.empty_right @[simp] theorem empty_left (s : Set X) : SeparatedNhds ∅ s := (empty_right _).symm #align separated_nhds.empty_left SeparatedNhds.empty_left theorem mono (h : SeparatedNhds s₂ t₂) (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : SeparatedNhds s₁ t₁ := let ⟨U, V, hU, hV, hsU, htV, hd⟩ := h ⟨U, V, hU, hV, hs.trans hsU, ht.trans htV, hd⟩ #align separated_nhds.mono SeparatedNhds.mono theorem union_left : SeparatedNhds s u → SeparatedNhds t u → SeparatedNhds (s ∪ t) u := by simpa only [separatedNhds_iff_disjoint, nhdsSet_union, disjoint_sup_left] using And.intro #align separated_nhds.union_left SeparatedNhds.union_left theorem union_right (ht : SeparatedNhds s t) (hu : SeparatedNhds s u) : SeparatedNhds s (t ∪ u) := (ht.symm.union_left hu.symm).symm #align separated_nhds.union_right SeparatedNhds.union_right end SeparatedNhds /-- A T₀ space, also known as a Kolmogorov space, is a topological space such that for every pair `x ≠ y`, there is an open set containing one but not the other. We formulate the definition in terms of the `Inseparable` relation. -/ class T0Space (X : Type u) [TopologicalSpace X] : Prop where /-- Two inseparable points in a T₀ space are equal. -/ t0 : ∀ ⦃x y : X⦄, Inseparable x y → x = y #align t0_space T0Space theorem t0Space_iff_inseparable (X : Type u) [TopologicalSpace X] : T0Space X ↔ ∀ x y : X, Inseparable x y → x = y := ⟨fun ⟨h⟩ => h, fun h => ⟨h⟩⟩ #align t0_space_iff_inseparable t0Space_iff_inseparable theorem t0Space_iff_not_inseparable (X : Type u) [TopologicalSpace X] : T0Space X ↔ Pairwise fun x y : X => ¬Inseparable x y := by simp only [t0Space_iff_inseparable, Ne, not_imp_not, Pairwise] #align t0_space_iff_not_inseparable t0Space_iff_not_inseparable theorem Inseparable.eq [T0Space X] {x y : X} (h : Inseparable x y) : x = y := T0Space.t0 h #align inseparable.eq Inseparable.eq /-- A topology `Inducing` map from a T₀ space is injective. -/ protected theorem Inducing.injective [TopologicalSpace Y] [T0Space X] {f : X → Y} (hf : Inducing f) : Injective f := fun _ _ h => (hf.inseparable_iff.1 <| .of_eq h).eq #align inducing.injective Inducing.injective /-- A topology `Inducing` map from a T₀ space is a topological embedding. -/ protected theorem Inducing.embedding [TopologicalSpace Y] [T0Space X] {f : X → Y} (hf : Inducing f) : Embedding f := ⟨hf, hf.injective⟩ #align inducing.embedding Inducing.embedding lemma embedding_iff_inducing [TopologicalSpace Y] [T0Space X] {f : X → Y} : Embedding f ↔ Inducing f := ⟨Embedding.toInducing, Inducing.embedding⟩ #align embedding_iff_inducing embedding_iff_inducing theorem t0Space_iff_nhds_injective (X : Type u) [TopologicalSpace X] : T0Space X ↔ Injective (𝓝 : X → Filter X) := t0Space_iff_inseparable X #align t0_space_iff_nhds_injective t0Space_iff_nhds_injective theorem nhds_injective [T0Space X] : Injective (𝓝 : X → Filter X) := (t0Space_iff_nhds_injective X).1 ‹_› #align nhds_injective nhds_injective theorem inseparable_iff_eq [T0Space X] {x y : X} : Inseparable x y ↔ x = y := nhds_injective.eq_iff #align inseparable_iff_eq inseparable_iff_eq @[simp] theorem nhds_eq_nhds_iff [T0Space X] {a b : X} : 𝓝 a = 𝓝 b ↔ a = b := nhds_injective.eq_iff #align nhds_eq_nhds_iff nhds_eq_nhds_iff @[simp] theorem inseparable_eq_eq [T0Space X] : Inseparable = @Eq X := funext₂ fun _ _ => propext inseparable_iff_eq #align inseparable_eq_eq inseparable_eq_eq theorem TopologicalSpace.IsTopologicalBasis.inseparable_iff {b : Set (Set X)} (hb : IsTopologicalBasis b) {x y : X} : Inseparable x y ↔ ∀ s ∈ b, (x ∈ s ↔ y ∈ s) := ⟨fun h s hs ↦ inseparable_iff_forall_open.1 h _ (hb.isOpen hs), fun h ↦ hb.nhds_hasBasis.eq_of_same_basis <| by convert hb.nhds_hasBasis using 2 exact and_congr_right (h _)⟩ theorem TopologicalSpace.IsTopologicalBasis.eq_iff [T0Space X] {b : Set (Set X)} (hb : IsTopologicalBasis b) {x y : X} : x = y ↔ ∀ s ∈ b, (x ∈ s ↔ y ∈ s) := inseparable_iff_eq.symm.trans hb.inseparable_iff theorem t0Space_iff_exists_isOpen_xor'_mem (X : Type u) [TopologicalSpace X] : T0Space X ↔ Pairwise fun x y => ∃ U : Set X, IsOpen U ∧ Xor' (x ∈ U) (y ∈ U) := by simp only [t0Space_iff_not_inseparable, xor_iff_not_iff, not_forall, exists_prop, inseparable_iff_forall_open, Pairwise] #align t0_space_iff_exists_is_open_xor_mem t0Space_iff_exists_isOpen_xor'_mem theorem exists_isOpen_xor'_mem [T0Space X] {x y : X} (h : x ≠ y) : ∃ U : Set X, IsOpen U ∧ Xor' (x ∈ U) (y ∈ U) := (t0Space_iff_exists_isOpen_xor'_mem X).1 ‹_› h #align exists_is_open_xor_mem exists_isOpen_xor'_mem /-- Specialization forms a partial order on a t0 topological space. -/ def specializationOrder (X) [TopologicalSpace X] [T0Space X] : PartialOrder X := { specializationPreorder X, PartialOrder.lift (OrderDual.toDual ∘ 𝓝) nhds_injective with } #align specialization_order specializationOrder instance SeparationQuotient.instT0Space : T0Space (SeparationQuotient X) := ⟨fun x y => Quotient.inductionOn₂' x y fun _ _ h => SeparationQuotient.mk_eq_mk.2 <| SeparationQuotient.inducing_mk.inseparable_iff.1 h⟩ theorem minimal_nonempty_closed_subsingleton [T0Space X] {s : Set X} (hs : IsClosed s) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsClosed t → t = s) : s.Subsingleton := by clear Y -- Porting note: added refine fun x hx y hy => of_not_not fun hxy => ?_ rcases exists_isOpen_xor'_mem hxy with ⟨U, hUo, hU⟩ wlog h : x ∈ U ∧ y ∉ U · refine this hs hmin y hy x hx (Ne.symm hxy) U hUo hU.symm (hU.resolve_left h) cases' h with hxU hyU have : s \ U = s := hmin (s \ U) diff_subset ⟨y, hy, hyU⟩ (hs.sdiff hUo) exact (this.symm.subset hx).2 hxU #align minimal_nonempty_closed_subsingleton minimal_nonempty_closed_subsingleton theorem minimal_nonempty_closed_eq_singleton [T0Space X] {s : Set X} (hs : IsClosed s) (hne : s.Nonempty) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsClosed t → t = s) : ∃ x, s = {x} := exists_eq_singleton_iff_nonempty_subsingleton.2 ⟨hne, minimal_nonempty_closed_subsingleton hs hmin⟩ #align minimal_nonempty_closed_eq_singleton minimal_nonempty_closed_eq_singleton /-- Given a closed set `S` in a compact T₀ space, there is some `x ∈ S` such that `{x}` is closed. -/ theorem IsClosed.exists_closed_singleton [T0Space X] [CompactSpace X] {S : Set X} (hS : IsClosed S) (hne : S.Nonempty) : ∃ x : X, x ∈ S ∧ IsClosed ({x} : Set X) := by obtain ⟨V, Vsub, Vne, Vcls, hV⟩ := hS.exists_minimal_nonempty_closed_subset hne rcases minimal_nonempty_closed_eq_singleton Vcls Vne hV with ⟨x, rfl⟩ exact ⟨x, Vsub (mem_singleton x), Vcls⟩ #align is_closed.exists_closed_singleton IsClosed.exists_closed_singleton theorem minimal_nonempty_open_subsingleton [T0Space X] {s : Set X} (hs : IsOpen s) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsOpen t → t = s) : s.Subsingleton := by clear Y -- Porting note: added refine fun x hx y hy => of_not_not fun hxy => ?_ rcases exists_isOpen_xor'_mem hxy with ⟨U, hUo, hU⟩ wlog h : x ∈ U ∧ y ∉ U · exact this hs hmin y hy x hx (Ne.symm hxy) U hUo hU.symm (hU.resolve_left h) cases' h with hxU hyU have : s ∩ U = s := hmin (s ∩ U) inter_subset_left ⟨x, hx, hxU⟩ (hs.inter hUo) exact hyU (this.symm.subset hy).2 #align minimal_nonempty_open_subsingleton minimal_nonempty_open_subsingleton theorem minimal_nonempty_open_eq_singleton [T0Space X] {s : Set X} (hs : IsOpen s) (hne : s.Nonempty) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsOpen t → t = s) : ∃ x, s = {x} := exists_eq_singleton_iff_nonempty_subsingleton.2 ⟨hne, minimal_nonempty_open_subsingleton hs hmin⟩ #align minimal_nonempty_open_eq_singleton minimal_nonempty_open_eq_singleton /-- Given an open finite set `S` in a T₀ space, there is some `x ∈ S` such that `{x}` is open. -/ theorem exists_isOpen_singleton_of_isOpen_finite [T0Space X] {s : Set X} (hfin : s.Finite) (hne : s.Nonempty) (ho : IsOpen s) : ∃ x ∈ s, IsOpen ({x} : Set X) := by lift s to Finset X using hfin induction' s using Finset.strongInductionOn with s ihs rcases em (∃ t, t ⊂ s ∧ t.Nonempty ∧ IsOpen (t : Set X)) with (⟨t, hts, htne, hto⟩ | ht) · rcases ihs t hts htne hto with ⟨x, hxt, hxo⟩ exact ⟨x, hts.1 hxt, hxo⟩ · -- Porting note: was `rcases minimal_nonempty_open_eq_singleton ho hne _ with ⟨x, hx⟩` -- https://github.com/leanprover/std4/issues/116 rsuffices ⟨x, hx⟩ : ∃ x, s.toSet = {x} · exact ⟨x, hx.symm ▸ rfl, hx ▸ ho⟩ refine minimal_nonempty_open_eq_singleton ho hne ?_ refine fun t hts htne hto => of_not_not fun hts' => ht ?_ lift t to Finset X using s.finite_toSet.subset hts exact ⟨t, ssubset_iff_subset_ne.2 ⟨hts, mt Finset.coe_inj.2 hts'⟩, htne, hto⟩ #align exists_open_singleton_of_open_finite exists_isOpen_singleton_of_isOpen_finite theorem exists_open_singleton_of_finite [T0Space X] [Finite X] [Nonempty X] : ∃ x : X, IsOpen ({x} : Set X) := let ⟨x, _, h⟩ := exists_isOpen_singleton_of_isOpen_finite (Set.toFinite _) univ_nonempty isOpen_univ ⟨x, h⟩ #align exists_open_singleton_of_fintype exists_open_singleton_of_finite theorem t0Space_of_injective_of_continuous [TopologicalSpace Y] {f : X → Y} (hf : Function.Injective f) (hf' : Continuous f) [T0Space Y] : T0Space X := ⟨fun _ _ h => hf <| (h.map hf').eq⟩ #align t0_space_of_injective_of_continuous t0Space_of_injective_of_continuous protected theorem Embedding.t0Space [TopologicalSpace Y] [T0Space Y] {f : X → Y} (hf : Embedding f) : T0Space X := t0Space_of_injective_of_continuous hf.inj hf.continuous #align embedding.t0_space Embedding.t0Space instance Subtype.t0Space [T0Space X] {p : X → Prop} : T0Space (Subtype p) := embedding_subtype_val.t0Space #align subtype.t0_space Subtype.t0Space theorem t0Space_iff_or_not_mem_closure (X : Type u) [TopologicalSpace X] : T0Space X ↔ Pairwise fun a b : X => a ∉ closure ({b} : Set X) ∨ b ∉ closure ({a} : Set X) := by simp only [t0Space_iff_not_inseparable, inseparable_iff_mem_closure, not_and_or] #align t0_space_iff_or_not_mem_closure t0Space_iff_or_not_mem_closure instance Prod.instT0Space [TopologicalSpace Y] [T0Space X] [T0Space Y] : T0Space (X × Y) := ⟨fun _ _ h => Prod.ext (h.map continuous_fst).eq (h.map continuous_snd).eq⟩ instance Pi.instT0Space {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, T0Space (X i)] : T0Space (∀ i, X i) := ⟨fun _ _ h => funext fun i => (h.map (continuous_apply i)).eq⟩ #align pi.t0_space Pi.instT0Space instance ULift.instT0Space [T0Space X] : T0Space (ULift X) := embedding_uLift_down.t0Space theorem T0Space.of_cover (h : ∀ x y, Inseparable x y → ∃ s : Set X, x ∈ s ∧ y ∈ s ∧ T0Space s) : T0Space X := by refine ⟨fun x y hxy => ?_⟩ rcases h x y hxy with ⟨s, hxs, hys, hs⟩ lift x to s using hxs; lift y to s using hys rw [← subtype_inseparable_iff] at hxy exact congr_arg Subtype.val hxy.eq #align t0_space.of_cover T0Space.of_cover theorem T0Space.of_open_cover (h : ∀ x, ∃ s : Set X, x ∈ s ∧ IsOpen s ∧ T0Space s) : T0Space X := T0Space.of_cover fun x _ hxy => let ⟨s, hxs, hso, hs⟩ := h x ⟨s, hxs, (hxy.mem_open_iff hso).1 hxs, hs⟩ #align t0_space.of_open_cover T0Space.of_open_cover /-- A topological space is called an R₀ space, if `Specializes` relation is symmetric. In other words, given two points `x y : X`, if every neighborhood of `y` contains `x`, then every neighborhood of `x` contains `y`. -/ @[mk_iff] class R0Space (X : Type u) [TopologicalSpace X] : Prop where /-- In an R₀ space, the `Specializes` relation is symmetric. -/ specializes_symmetric : Symmetric (Specializes : X → X → Prop) export R0Space (specializes_symmetric) section R0Space variable [R0Space X] {x y : X} /-- In an R₀ space, the `Specializes` relation is symmetric, dot notation version. -/ theorem Specializes.symm (h : x ⤳ y) : y ⤳ x := specializes_symmetric h #align specializes.symm Specializes.symm /-- In an R₀ space, the `Specializes` relation is symmetric, `Iff` version. -/ theorem specializes_comm : x ⤳ y ↔ y ⤳ x := ⟨Specializes.symm, Specializes.symm⟩ #align specializes_comm specializes_comm /-- In an R₀ space, `Specializes` is equivalent to `Inseparable`. -/ theorem specializes_iff_inseparable : x ⤳ y ↔ Inseparable x y := ⟨fun h ↦ h.antisymm h.symm, Inseparable.specializes⟩ #align specializes_iff_inseparable specializes_iff_inseparable /-- In an R₀ space, `Specializes` implies `Inseparable`. -/ alias ⟨Specializes.inseparable, _⟩ := specializes_iff_inseparable
Mathlib/Topology/Separation.lean
427
429
theorem Inducing.r0Space [TopologicalSpace Y] {f : Y → X} (hf : Inducing f) : R0Space Y where specializes_symmetric a b := by
simpa only [← hf.specializes_iff] using Specializes.symm
/- Copyright (c) 2021 Henry Swanson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Henry Swanson -/ import Mathlib.Dynamics.FixedPoints.Basic import Mathlib.GroupTheory.Perm.Option import Mathlib.Logic.Equiv.Defs import Mathlib.Logic.Equiv.Option #align_import combinatorics.derangements.basic from "leanprover-community/mathlib"@"9407b03373c8cd201df99d6bc5514fc2db44054f" /-! # Derangements on types In this file we define `derangements α`, the set of derangements on a type `α`. We also define some equivalences involving various subtypes of `Perm α` and `derangements α`: * `derangementsOptionEquivSigmaAtMostOneFixedPoint`: An equivalence between `derangements (Option α)` and the sigma-type `Σ a : α, {f : Perm α // fixed_points f ⊆ a}`. * `derangementsRecursionEquiv`: An equivalence between `derangements (Option α)` and the sigma-type `Σ a : α, (derangements (({a}ᶜ : Set α) : Type*) ⊕ derangements α)` which is later used to inductively count the number of derangements. In order to prove the above, we also prove some results about the effect of `Equiv.removeNone` on derangements: `RemoveNone.fiber_none` and `RemoveNone.fiber_some`. -/ open Equiv Function /-- A permutation is a derangement if it has no fixed points. -/ def derangements (α : Type*) : Set (Perm α) := { f : Perm α | ∀ x : α, f x ≠ x } #align derangements derangements variable {α β : Type*} theorem mem_derangements_iff_fixedPoints_eq_empty {f : Perm α} : f ∈ derangements α ↔ fixedPoints f = ∅ := Set.eq_empty_iff_forall_not_mem.symm #align mem_derangements_iff_fixed_points_eq_empty mem_derangements_iff_fixedPoints_eq_empty /-- If `α` is equivalent to `β`, then `derangements α` is equivalent to `derangements β`. -/ def Equiv.derangementsCongr (e : α ≃ β) : derangements α ≃ derangements β := e.permCongr.subtypeEquiv fun {f} => e.forall_congr <| by intro b; simp only [ne_eq, permCongr_apply, symm_apply_apply, EmbeddingLike.apply_eq_iff_eq] #align equiv.derangements_congr Equiv.derangementsCongr namespace derangements /-- Derangements on a subtype are equivalent to permutations on the original type where points are fixed iff they are not in the subtype. -/ protected def subtypeEquiv (p : α → Prop) [DecidablePred p] : derangements (Subtype p) ≃ { f : Perm α // ∀ a, ¬p a ↔ a ∈ fixedPoints f } := calc derangements (Subtype p) ≃ { f : { f : Perm α // ∀ a, ¬p a → a ∈ fixedPoints f } // ∀ a, a ∈ fixedPoints f → ¬p a } := by refine (Perm.subtypeEquivSubtypePerm p).subtypeEquiv fun f => ⟨fun hf a hfa ha => ?_, ?_⟩ · refine hf ⟨a, ha⟩ (Subtype.ext ?_) simp_rw [mem_fixedPoints, IsFixedPt, Perm.subtypeEquivSubtypePerm, Equiv.coe_fn_mk, Perm.ofSubtype_apply_of_mem _ ha] at hfa assumption rintro hf ⟨a, ha⟩ hfa refine hf _ ?_ ha simp only [Perm.subtypeEquivSubtypePerm_apply_coe, mem_fixedPoints] dsimp [IsFixedPt] simp_rw [Perm.ofSubtype_apply_of_mem _ ha, hfa] _ ≃ { f : Perm α // ∃ _h : ∀ a, ¬p a → a ∈ fixedPoints f, ∀ a, a ∈ fixedPoints f → ¬p a } := subtypeSubtypeEquivSubtypeExists _ _ _ ≃ { f : Perm α // ∀ a, ¬p a ↔ a ∈ fixedPoints f } := subtypeEquivRight fun f => by simp_rw [exists_prop, ← forall_and, ← iff_iff_implies_and_implies] #align derangements.subtype_equiv derangements.subtypeEquiv universe u /-- The set of permutations that fix either `a` or nothing is equivalent to the sum of: - derangements on `α` - derangements on `α` minus `a`. -/ def atMostOneFixedPointEquivSum_derangements [DecidableEq α] (a : α) : { f : Perm α // fixedPoints f ⊆ {a} } ≃ Sum (derangements ({a}ᶜ : Set α)) (derangements α) := calc { f : Perm α // fixedPoints f ⊆ {a} } ≃ Sum { f : { f : Perm α // fixedPoints f ⊆ {a} } // a ∈ fixedPoints f } { f : { f : Perm α // fixedPoints f ⊆ {a} } // a ∉ fixedPoints f } := (Equiv.sumCompl _).symm _ ≃ Sum { f : Perm α // fixedPoints f ⊆ {a} ∧ a ∈ fixedPoints f } { f : Perm α // fixedPoints f ⊆ {a} ∧ a ∉ fixedPoints f } := by -- Porting note: `subtypeSubtypeEquivSubtypeInter` no longer works with placeholder `_`s. refine Equiv.sumCongr ?_ ?_ · exact subtypeSubtypeEquivSubtypeInter (fun x : Perm α => fixedPoints x ⊆ {a}) (a ∈ fixedPoints ·) · exact subtypeSubtypeEquivSubtypeInter (fun x : Perm α => fixedPoints x ⊆ {a}) (¬a ∈ fixedPoints ·) _ ≃ Sum { f : Perm α // fixedPoints f = {a} } { f : Perm α // fixedPoints f = ∅ } := by refine Equiv.sumCongr (subtypeEquivRight fun f => ?_) (subtypeEquivRight fun f => ?_) · rw [Set.eq_singleton_iff_unique_mem, and_comm] rfl · rw [Set.eq_empty_iff_forall_not_mem] exact ⟨fun h x hx => h.2 (h.1 hx ▸ hx), fun h => ⟨fun x hx => (h _ hx).elim, h _⟩⟩ _ ≃ Sum (derangements ({a}ᶜ : Set α)) (derangements α) := by -- Porting note: was `subtypeEquiv _` but now needs the placeholder to be provided explicitly refine Equiv.sumCongr ((derangements.subtypeEquiv (· ∈ ({a}ᶜ : Set α))).trans <| subtypeEquivRight fun x => ?_).symm (subtypeEquivRight fun f => mem_derangements_iff_fixedPoints_eq_empty.symm) rw [eq_comm, Set.ext_iff] simp_rw [Set.mem_compl_iff, Classical.not_not] #align derangements.at_most_one_fixed_point_equiv_sum_derangements derangements.atMostOneFixedPointEquivSum_derangements namespace Equiv variable [DecidableEq α] /-- The set of permutations `f` such that the preimage of `(a, f)` under `Equiv.Perm.decomposeOption` is a derangement. -/ def RemoveNone.fiber (a : Option α) : Set (Perm α) := { f : Perm α | (a, f) ∈ Equiv.Perm.decomposeOption '' derangements (Option α) } #align derangements.equiv.remove_none.fiber derangements.Equiv.RemoveNone.fiber
Mathlib/Combinatorics/Derangements/Basic.lean
123
126
theorem RemoveNone.mem_fiber (a : Option α) (f : Perm α) : f ∈ RemoveNone.fiber a ↔ ∃ F : Perm (Option α), F ∈ derangements (Option α) ∧ F none = a ∧ removeNone F = f := by
simp [RemoveNone.fiber, derangements]
/- Copyright (c) 2020 Kenji Nakagawa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenji Nakagawa, Anne Baanen, Filippo A. E. Nuccio -/ import Mathlib.Algebra.Algebra.Subalgebra.Pointwise import Mathlib.AlgebraicGeometry.PrimeSpectrum.Maximal import Mathlib.AlgebraicGeometry.PrimeSpectrum.Noetherian import Mathlib.RingTheory.ChainOfDivisors import Mathlib.RingTheory.DedekindDomain.Basic import Mathlib.RingTheory.FractionalIdeal.Operations #align_import ring_theory.dedekind_domain.ideal from "leanprover-community/mathlib"@"2bbc7e3884ba234309d2a43b19144105a753292e" /-! # Dedekind domains and ideals In this file, we show a ring is a Dedekind domain iff all fractional ideals are invertible. Then we prove some results on the unique factorization monoid structure of the ideals. ## Main definitions - `IsDedekindDomainInv` alternatively defines a Dedekind domain as an integral domain where every nonzero fractional ideal is invertible. - `isDedekindDomainInv_iff` shows that this does note depend on the choice of field of fractions. - `IsDedekindDomain.HeightOneSpectrum` defines the type of nonzero prime ideals of `R`. ## Main results: - `isDedekindDomain_iff_isDedekindDomainInv` - `Ideal.uniqueFactorizationMonoid` ## Implementation notes The definitions that involve a field of fractions choose a canonical field of fractions, but are independent of that choice. The `..._iff` lemmas express this independence. Often, definitions assume that Dedekind domains are not fields. We found it more practical to add a `(h : ¬ IsField A)` assumption whenever this is explicitly needed. ## References * [D. Marcus, *Number Fields*][marcus1977number] * [J.W.S. Cassels, A. Frölich, *Algebraic Number Theory*][cassels1967algebraic] * [J. Neukirch, *Algebraic Number Theory*][Neukirch1992] ## Tags dedekind domain, dedekind ring -/ variable (R A K : Type*) [CommRing R] [CommRing A] [Field K] open scoped nonZeroDivisors Polynomial section Inverse namespace FractionalIdeal variable {R₁ : Type*} [CommRing R₁] [IsDomain R₁] [Algebra R₁ K] [IsFractionRing R₁ K] variable {I J : FractionalIdeal R₁⁰ K} noncomputable instance : Inv (FractionalIdeal R₁⁰ K) := ⟨fun I => 1 / I⟩ theorem inv_eq : I⁻¹ = 1 / I := rfl #align fractional_ideal.inv_eq FractionalIdeal.inv_eq theorem inv_zero' : (0 : FractionalIdeal R₁⁰ K)⁻¹ = 0 := div_zero #align fractional_ideal.inv_zero' FractionalIdeal.inv_zero' theorem inv_nonzero {J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) : J⁻¹ = ⟨(1 : FractionalIdeal R₁⁰ K) / J, fractional_div_of_nonzero h⟩ := div_nonzero h #align fractional_ideal.inv_nonzero FractionalIdeal.inv_nonzero theorem coe_inv_of_nonzero {J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) : (↑J⁻¹ : Submodule R₁ K) = IsLocalization.coeSubmodule K ⊤ / (J : Submodule R₁ K) := by simp_rw [inv_nonzero _ h, coe_one, coe_mk, IsLocalization.coeSubmodule_top] #align fractional_ideal.coe_inv_of_nonzero FractionalIdeal.coe_inv_of_nonzero variable {K} theorem mem_inv_iff (hI : I ≠ 0) {x : K} : x ∈ I⁻¹ ↔ ∀ y ∈ I, x * y ∈ (1 : FractionalIdeal R₁⁰ K) := mem_div_iff_of_nonzero hI #align fractional_ideal.mem_inv_iff FractionalIdeal.mem_inv_iff theorem inv_anti_mono (hI : I ≠ 0) (hJ : J ≠ 0) (hIJ : I ≤ J) : J⁻¹ ≤ I⁻¹ := by -- Porting note: in Lean3, introducing `x` would just give `x ∈ J⁻¹ → x ∈ I⁻¹`, but -- in Lean4, it goes all the way down to the subtypes intro x simp only [val_eq_coe, mem_coe, mem_inv_iff hJ, mem_inv_iff hI] exact fun h y hy => h y (hIJ hy) #align fractional_ideal.inv_anti_mono FractionalIdeal.inv_anti_mono theorem le_self_mul_inv {I : FractionalIdeal R₁⁰ K} (hI : I ≤ (1 : FractionalIdeal R₁⁰ K)) : I ≤ I * I⁻¹ := le_self_mul_one_div hI #align fractional_ideal.le_self_mul_inv FractionalIdeal.le_self_mul_inv variable (K) theorem coe_ideal_le_self_mul_inv (I : Ideal R₁) : (I : FractionalIdeal R₁⁰ K) ≤ I * (I : FractionalIdeal R₁⁰ K)⁻¹ := le_self_mul_inv coeIdeal_le_one #align fractional_ideal.coe_ideal_le_self_mul_inv FractionalIdeal.coe_ideal_le_self_mul_inv /-- `I⁻¹` is the inverse of `I` if `I` has an inverse. -/ theorem right_inverse_eq (I J : FractionalIdeal R₁⁰ K) (h : I * J = 1) : J = I⁻¹ := by have hI : I ≠ 0 := ne_zero_of_mul_eq_one I J h suffices h' : I * (1 / I) = 1 from congr_arg Units.inv <| @Units.ext _ _ (Units.mkOfMulEqOne _ _ h) (Units.mkOfMulEqOne _ _ h') rfl apply le_antisymm · apply mul_le.mpr _ intro x hx y hy rw [mul_comm] exact (mem_div_iff_of_nonzero hI).mp hy x hx rw [← h] apply mul_left_mono I apply (le_div_iff_of_nonzero hI).mpr _ intro y hy x hx rw [mul_comm] exact mul_mem_mul hx hy #align fractional_ideal.right_inverse_eq FractionalIdeal.right_inverse_eq theorem mul_inv_cancel_iff {I : FractionalIdeal R₁⁰ K} : I * I⁻¹ = 1 ↔ ∃ J, I * J = 1 := ⟨fun h => ⟨I⁻¹, h⟩, fun ⟨J, hJ⟩ => by rwa [← right_inverse_eq K I J hJ]⟩ #align fractional_ideal.mul_inv_cancel_iff FractionalIdeal.mul_inv_cancel_iff theorem mul_inv_cancel_iff_isUnit {I : FractionalIdeal R₁⁰ K} : I * I⁻¹ = 1 ↔ IsUnit I := (mul_inv_cancel_iff K).trans isUnit_iff_exists_inv.symm #align fractional_ideal.mul_inv_cancel_iff_is_unit FractionalIdeal.mul_inv_cancel_iff_isUnit variable {K' : Type*} [Field K'] [Algebra R₁ K'] [IsFractionRing R₁ K'] @[simp] theorem map_inv (I : FractionalIdeal R₁⁰ K) (h : K ≃ₐ[R₁] K') : I⁻¹.map (h : K →ₐ[R₁] K') = (I.map h)⁻¹ := by rw [inv_eq, map_div, map_one, inv_eq] #align fractional_ideal.map_inv FractionalIdeal.map_inv open Submodule Submodule.IsPrincipal @[simp] theorem spanSingleton_inv (x : K) : (spanSingleton R₁⁰ x)⁻¹ = spanSingleton _ x⁻¹ := one_div_spanSingleton x #align fractional_ideal.span_singleton_inv FractionalIdeal.spanSingleton_inv -- @[simp] -- Porting note: not in simpNF form theorem spanSingleton_div_spanSingleton (x y : K) : spanSingleton R₁⁰ x / spanSingleton R₁⁰ y = spanSingleton R₁⁰ (x / y) := by rw [div_spanSingleton, mul_comm, spanSingleton_mul_spanSingleton, div_eq_mul_inv] #align fractional_ideal.span_singleton_div_span_singleton FractionalIdeal.spanSingleton_div_spanSingleton theorem spanSingleton_div_self {x : K} (hx : x ≠ 0) : spanSingleton R₁⁰ x / spanSingleton R₁⁰ x = 1 := by rw [spanSingleton_div_spanSingleton, div_self hx, spanSingleton_one] #align fractional_ideal.span_singleton_div_self FractionalIdeal.spanSingleton_div_self theorem coe_ideal_span_singleton_div_self {x : R₁} (hx : x ≠ 0) : (Ideal.span ({x} : Set R₁) : FractionalIdeal R₁⁰ K) / Ideal.span ({x} : Set R₁) = 1 := by rw [coeIdeal_span_singleton, spanSingleton_div_self K <| (map_ne_zero_iff _ <| NoZeroSMulDivisors.algebraMap_injective R₁ K).mpr hx] #align fractional_ideal.coe_ideal_span_singleton_div_self FractionalIdeal.coe_ideal_span_singleton_div_self theorem spanSingleton_mul_inv {x : K} (hx : x ≠ 0) : spanSingleton R₁⁰ x * (spanSingleton R₁⁰ x)⁻¹ = 1 := by rw [spanSingleton_inv, spanSingleton_mul_spanSingleton, mul_inv_cancel hx, spanSingleton_one] #align fractional_ideal.span_singleton_mul_inv FractionalIdeal.spanSingleton_mul_inv theorem coe_ideal_span_singleton_mul_inv {x : R₁} (hx : x ≠ 0) : (Ideal.span ({x} : Set R₁) : FractionalIdeal R₁⁰ K) * (Ideal.span ({x} : Set R₁) : FractionalIdeal R₁⁰ K)⁻¹ = 1 := by rw [coeIdeal_span_singleton, spanSingleton_mul_inv K <| (map_ne_zero_iff _ <| NoZeroSMulDivisors.algebraMap_injective R₁ K).mpr hx] #align fractional_ideal.coe_ideal_span_singleton_mul_inv FractionalIdeal.coe_ideal_span_singleton_mul_inv theorem spanSingleton_inv_mul {x : K} (hx : x ≠ 0) : (spanSingleton R₁⁰ x)⁻¹ * spanSingleton R₁⁰ x = 1 := by rw [mul_comm, spanSingleton_mul_inv K hx] #align fractional_ideal.span_singleton_inv_mul FractionalIdeal.spanSingleton_inv_mul theorem coe_ideal_span_singleton_inv_mul {x : R₁} (hx : x ≠ 0) : (Ideal.span ({x} : Set R₁) : FractionalIdeal R₁⁰ K)⁻¹ * Ideal.span ({x} : Set R₁) = 1 := by rw [mul_comm, coe_ideal_span_singleton_mul_inv K hx] #align fractional_ideal.coe_ideal_span_singleton_inv_mul FractionalIdeal.coe_ideal_span_singleton_inv_mul theorem mul_generator_self_inv {R₁ : Type*} [CommRing R₁] [Algebra R₁ K] [IsLocalization R₁⁰ K] (I : FractionalIdeal R₁⁰ K) [Submodule.IsPrincipal (I : Submodule R₁ K)] (h : I ≠ 0) : I * spanSingleton _ (generator (I : Submodule R₁ K))⁻¹ = 1 := by -- Rewrite only the `I` that appears alone. conv_lhs => congr; rw [eq_spanSingleton_of_principal I] rw [spanSingleton_mul_spanSingleton, mul_inv_cancel, spanSingleton_one] intro generator_I_eq_zero apply h rw [eq_spanSingleton_of_principal I, generator_I_eq_zero, spanSingleton_zero] #align fractional_ideal.mul_generator_self_inv FractionalIdeal.mul_generator_self_inv theorem invertible_of_principal (I : FractionalIdeal R₁⁰ K) [Submodule.IsPrincipal (I : Submodule R₁ K)] (h : I ≠ 0) : I * I⁻¹ = 1 := mul_div_self_cancel_iff.mpr ⟨spanSingleton _ (generator (I : Submodule R₁ K))⁻¹, mul_generator_self_inv _ I h⟩ #align fractional_ideal.invertible_of_principal FractionalIdeal.invertible_of_principal theorem invertible_iff_generator_nonzero (I : FractionalIdeal R₁⁰ K) [Submodule.IsPrincipal (I : Submodule R₁ K)] : I * I⁻¹ = 1 ↔ generator (I : Submodule R₁ K) ≠ 0 := by constructor · intro hI hg apply ne_zero_of_mul_eq_one _ _ hI rw [eq_spanSingleton_of_principal I, hg, spanSingleton_zero] · intro hg apply invertible_of_principal rw [eq_spanSingleton_of_principal I] intro hI have := mem_spanSingleton_self R₁⁰ (generator (I : Submodule R₁ K)) rw [hI, mem_zero_iff] at this contradiction #align fractional_ideal.invertible_iff_generator_nonzero FractionalIdeal.invertible_iff_generator_nonzero theorem isPrincipal_inv (I : FractionalIdeal R₁⁰ K) [Submodule.IsPrincipal (I : Submodule R₁ K)] (h : I ≠ 0) : Submodule.IsPrincipal I⁻¹.1 := by rw [val_eq_coe, isPrincipal_iff] use (generator (I : Submodule R₁ K))⁻¹ have hI : I * spanSingleton _ (generator (I : Submodule R₁ K))⁻¹ = 1 := mul_generator_self_inv _ I h exact (right_inverse_eq _ I (spanSingleton _ (generator (I : Submodule R₁ K))⁻¹) hI).symm #align fractional_ideal.is_principal_inv FractionalIdeal.isPrincipal_inv noncomputable instance : InvOneClass (FractionalIdeal R₁⁰ K) := { inv_one := div_one } end FractionalIdeal section IsDedekindDomainInv variable [IsDomain A] /-- A Dedekind domain is an integral domain such that every fractional ideal has an inverse. This is equivalent to `IsDedekindDomain`. In particular we provide a `fractional_ideal.comm_group_with_zero` instance, assuming `IsDedekindDomain A`, which implies `IsDedekindDomainInv`. For **integral** ideals, `IsDedekindDomain`(`_inv`) implies only `Ideal.cancelCommMonoidWithZero`. -/ def IsDedekindDomainInv : Prop := ∀ I ≠ (⊥ : FractionalIdeal A⁰ (FractionRing A)), I * I⁻¹ = 1 #align is_dedekind_domain_inv IsDedekindDomainInv open FractionalIdeal variable {R A K} theorem isDedekindDomainInv_iff [Algebra A K] [IsFractionRing A K] : IsDedekindDomainInv A ↔ ∀ I ≠ (⊥ : FractionalIdeal A⁰ K), I * I⁻¹ = 1 := by let h : FractionalIdeal A⁰ (FractionRing A) ≃+* FractionalIdeal A⁰ K := FractionalIdeal.mapEquiv (FractionRing.algEquiv A K) refine h.toEquiv.forall_congr (fun {x} => ?_) rw [← h.toEquiv.apply_eq_iff_eq] simp [h, IsDedekindDomainInv] #align is_dedekind_domain_inv_iff isDedekindDomainInv_iff theorem FractionalIdeal.adjoinIntegral_eq_one_of_isUnit [Algebra A K] [IsFractionRing A K] (x : K) (hx : IsIntegral A x) (hI : IsUnit (adjoinIntegral A⁰ x hx)) : adjoinIntegral A⁰ x hx = 1 := by set I := adjoinIntegral A⁰ x hx have mul_self : I * I = I := by apply coeToSubmodule_injective; simp [I] convert congr_arg (· * I⁻¹) mul_self <;> simp only [(mul_inv_cancel_iff_isUnit K).mpr hI, mul_assoc, mul_one] #align fractional_ideal.adjoin_integral_eq_one_of_is_unit FractionalIdeal.adjoinIntegral_eq_one_of_isUnit namespace IsDedekindDomainInv variable [Algebra A K] [IsFractionRing A K] (h : IsDedekindDomainInv A) theorem mul_inv_eq_one {I : FractionalIdeal A⁰ K} (hI : I ≠ 0) : I * I⁻¹ = 1 := isDedekindDomainInv_iff.mp h I hI #align is_dedekind_domain_inv.mul_inv_eq_one IsDedekindDomainInv.mul_inv_eq_one theorem inv_mul_eq_one {I : FractionalIdeal A⁰ K} (hI : I ≠ 0) : I⁻¹ * I = 1 := (mul_comm _ _).trans (h.mul_inv_eq_one hI) #align is_dedekind_domain_inv.inv_mul_eq_one IsDedekindDomainInv.inv_mul_eq_one protected theorem isUnit {I : FractionalIdeal A⁰ K} (hI : I ≠ 0) : IsUnit I := isUnit_of_mul_eq_one _ _ (h.mul_inv_eq_one hI) #align is_dedekind_domain_inv.is_unit IsDedekindDomainInv.isUnit theorem isNoetherianRing : IsNoetherianRing A := by refine isNoetherianRing_iff.mpr ⟨fun I : Ideal A => ?_⟩ by_cases hI : I = ⊥ · rw [hI]; apply Submodule.fg_bot have hI : (I : FractionalIdeal A⁰ (FractionRing A)) ≠ 0 := coeIdeal_ne_zero.mpr hI exact I.fg_of_isUnit (IsFractionRing.injective A (FractionRing A)) (h.isUnit hI) #align is_dedekind_domain_inv.is_noetherian_ring IsDedekindDomainInv.isNoetherianRing theorem integrallyClosed : IsIntegrallyClosed A := by -- It suffices to show that for integral `x`, -- `A[x]` (which is a fractional ideal) is in fact equal to `A`. refine (isIntegrallyClosed_iff (FractionRing A)).mpr (fun {x hx} => ?_) rw [← Set.mem_range, ← Algebra.mem_bot, ← Subalgebra.mem_toSubmodule, Algebra.toSubmodule_bot, Submodule.one_eq_span, ← coe_spanSingleton A⁰ (1 : FractionRing A), spanSingleton_one, ← FractionalIdeal.adjoinIntegral_eq_one_of_isUnit x hx (h.isUnit _)] · exact mem_adjoinIntegral_self A⁰ x hx · exact fun h => one_ne_zero (eq_zero_iff.mp h 1 (Algebra.adjoin A {x}).one_mem) #align is_dedekind_domain_inv.integrally_closed IsDedekindDomainInv.integrallyClosed open Ring theorem dimensionLEOne : DimensionLEOne A := ⟨by -- We're going to show that `P` is maximal because any (maximal) ideal `M` -- that is strictly larger would be `⊤`. rintro P P_ne hP refine Ideal.isMaximal_def.mpr ⟨hP.ne_top, fun M hM => ?_⟩ -- We may assume `P` and `M` (as fractional ideals) are nonzero. have P'_ne : (P : FractionalIdeal A⁰ (FractionRing A)) ≠ 0 := coeIdeal_ne_zero.mpr P_ne have M'_ne : (M : FractionalIdeal A⁰ (FractionRing A)) ≠ 0 := coeIdeal_ne_zero.mpr hM.ne_bot -- In particular, we'll show `M⁻¹ * P ≤ P` suffices (M⁻¹ : FractionalIdeal A⁰ (FractionRing A)) * P ≤ P by rw [eq_top_iff, ← coeIdeal_le_coeIdeal (FractionRing A), coeIdeal_top] calc (1 : FractionalIdeal A⁰ (FractionRing A)) = _ * _ * _ := ?_ _ ≤ _ * _ := mul_right_mono ((P : FractionalIdeal A⁰ (FractionRing A))⁻¹ * M : FractionalIdeal A⁰ (FractionRing A)) this _ = M := ?_ · rw [mul_assoc, ← mul_assoc (P : FractionalIdeal A⁰ (FractionRing A)), h.mul_inv_eq_one P'_ne, one_mul, h.inv_mul_eq_one M'_ne] · rw [← mul_assoc (P : FractionalIdeal A⁰ (FractionRing A)), h.mul_inv_eq_one P'_ne, one_mul] -- Suppose we have `x ∈ M⁻¹ * P`, then in fact `x = algebraMap _ _ y` for some `y`. intro x hx have le_one : (M⁻¹ : FractionalIdeal A⁰ (FractionRing A)) * P ≤ 1 := by rw [← h.inv_mul_eq_one M'_ne] exact mul_left_mono _ ((coeIdeal_le_coeIdeal (FractionRing A)).mpr hM.le) obtain ⟨y, _hy, rfl⟩ := (mem_coeIdeal _).mp (le_one hx) -- Since `M` is strictly greater than `P`, let `z ∈ M \ P`. obtain ⟨z, hzM, hzp⟩ := SetLike.exists_of_lt hM -- We have `z * y ∈ M * (M⁻¹ * P) = P`. have zy_mem := mul_mem_mul (mem_coeIdeal_of_mem A⁰ hzM) hx rw [← RingHom.map_mul, ← mul_assoc, h.mul_inv_eq_one M'_ne, one_mul] at zy_mem obtain ⟨zy, hzy, zy_eq⟩ := (mem_coeIdeal A⁰).mp zy_mem rw [IsFractionRing.injective A (FractionRing A) zy_eq] at hzy -- But `P` is a prime ideal, so `z ∉ P` implies `y ∈ P`, as desired. exact mem_coeIdeal_of_mem A⁰ (Or.resolve_left (hP.mem_or_mem hzy) hzp)⟩ #align is_dedekind_domain_inv.dimension_le_one IsDedekindDomainInv.dimensionLEOne /-- Showing one side of the equivalence between the definitions `IsDedekindDomainInv` and `IsDedekindDomain` of Dedekind domains. -/ theorem isDedekindDomain : IsDedekindDomain A := { h.isNoetherianRing, h.dimensionLEOne, h.integrallyClosed with } #align is_dedekind_domain_inv.is_dedekind_domain IsDedekindDomainInv.isDedekindDomain end IsDedekindDomainInv end IsDedekindDomainInv variable [Algebra A K] [IsFractionRing A K] variable {A K}
Mathlib/RingTheory/DedekindDomain/Ideal.lean
357
362
theorem one_mem_inv_coe_ideal [IsDomain A] {I : Ideal A} (hI : I ≠ ⊥) : (1 : K) ∈ (I : FractionalIdeal A⁰ K)⁻¹ := by
rw [FractionalIdeal.mem_inv_iff (FractionalIdeal.coeIdeal_ne_zero.mpr hI)] intro y hy rw [one_mul] exact FractionalIdeal.coeIdeal_le_one hy
/- Copyright (c) 2022 Vincent Beffara. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Vincent Beffara -/ import Mathlib.Analysis.Analytic.Constructions import Mathlib.Analysis.Calculus.Dslope import Mathlib.Analysis.Calculus.FDeriv.Analytic import Mathlib.Analysis.Analytic.Uniqueness #align_import analysis.analytic.isolated_zeros from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090" /-! # Principle of isolated zeros This file proves the fact that the zeros of a non-constant analytic function of one variable are isolated. It also introduces a little bit of API in the `HasFPowerSeriesAt` namespace that is useful in this setup. ## Main results * `AnalyticAt.eventually_eq_zero_or_eventually_ne_zero` is the main statement that if a function is analytic at `z₀`, then either it is identically zero in a neighborhood of `z₀`, or it does not vanish in a punctured neighborhood of `z₀`. * `AnalyticOn.eqOn_of_preconnected_of_frequently_eq` is the identity theorem for analytic functions: if a function `f` is analytic on a connected set `U` and is zero on a set with an accumulation point in `U` then `f` is identically `0` on `U`. -/ open scoped Classical open Filter Function Nat FormalMultilinearSeries EMetric Set open scoped Topology variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {s : E} {p q : FormalMultilinearSeries 𝕜 𝕜 E} {f g : 𝕜 → E} {n : ℕ} {z z₀ : 𝕜} namespace HasSum variable {a : ℕ → E} theorem hasSum_at_zero (a : ℕ → E) : HasSum (fun n => (0 : 𝕜) ^ n • a n) (a 0) := by convert hasSum_single (α := E) 0 fun b h ↦ _ <;> simp [*] #align has_sum.has_sum_at_zero HasSum.hasSum_at_zero theorem exists_hasSum_smul_of_apply_eq_zero (hs : HasSum (fun m => z ^ m • a m) s) (ha : ∀ k < n, a k = 0) : ∃ t : E, z ^ n • t = s ∧ HasSum (fun m => z ^ m • a (m + n)) t := by obtain rfl | hn := n.eq_zero_or_pos · simpa by_cases h : z = 0 · have : s = 0 := hs.unique (by simpa [ha 0 hn, h] using hasSum_at_zero a) exact ⟨a n, by simp [h, hn.ne', this], by simpa [h] using hasSum_at_zero fun m => a (m + n)⟩ · refine ⟨(z ^ n)⁻¹ • s, by field_simp [smul_smul], ?_⟩ have h1 : ∑ i ∈ Finset.range n, z ^ i • a i = 0 := Finset.sum_eq_zero fun k hk => by simp [ha k (Finset.mem_range.mp hk)] have h2 : HasSum (fun m => z ^ (m + n) • a (m + n)) s := by simpa [h1] using (hasSum_nat_add_iff' n).mpr hs convert h2.const_smul (z⁻¹ ^ n) using 1 · field_simp [pow_add, smul_smul] · simp only [inv_pow] #align has_sum.exists_has_sum_smul_of_apply_eq_zero HasSum.exists_hasSum_smul_of_apply_eq_zero end HasSum namespace HasFPowerSeriesAt theorem has_fpower_series_dslope_fslope (hp : HasFPowerSeriesAt f p z₀) : HasFPowerSeriesAt (dslope f z₀) p.fslope z₀ := by have hpd : deriv f z₀ = p.coeff 1 := hp.deriv have hp0 : p.coeff 0 = f z₀ := hp.coeff_zero 1 simp only [hasFPowerSeriesAt_iff, apply_eq_pow_smul_coeff, coeff_fslope] at hp ⊢ refine hp.mono fun x hx => ?_ by_cases h : x = 0 · convert hasSum_single (α := E) 0 _ <;> intros <;> simp [*] · have hxx : ∀ n : ℕ, x⁻¹ * x ^ (n + 1) = x ^ n := fun n => by field_simp [h, _root_.pow_succ] suffices HasSum (fun n => x⁻¹ • x ^ (n + 1) • p.coeff (n + 1)) (x⁻¹ • (f (z₀ + x) - f z₀)) by simpa [dslope, slope, h, smul_smul, hxx] using this simpa [hp0] using ((hasSum_nat_add_iff' 1).mpr hx).const_smul x⁻¹ #align has_fpower_series_at.has_fpower_series_dslope_fslope HasFPowerSeriesAt.has_fpower_series_dslope_fslope theorem has_fpower_series_iterate_dslope_fslope (n : ℕ) (hp : HasFPowerSeriesAt f p z₀) : HasFPowerSeriesAt ((swap dslope z₀)^[n] f) (fslope^[n] p) z₀ := by induction' n with n ih generalizing f p · exact hp · simpa using ih (has_fpower_series_dslope_fslope hp) #align has_fpower_series_at.has_fpower_series_iterate_dslope_fslope HasFPowerSeriesAt.has_fpower_series_iterate_dslope_fslope theorem iterate_dslope_fslope_ne_zero (hp : HasFPowerSeriesAt f p z₀) (h : p ≠ 0) : (swap dslope z₀)^[p.order] f z₀ ≠ 0 := by rw [← coeff_zero (has_fpower_series_iterate_dslope_fslope p.order hp) 1] simpa [coeff_eq_zero] using apply_order_ne_zero h #align has_fpower_series_at.iterate_dslope_fslope_ne_zero HasFPowerSeriesAt.iterate_dslope_fslope_ne_zero theorem eq_pow_order_mul_iterate_dslope (hp : HasFPowerSeriesAt f p z₀) : ∀ᶠ z in 𝓝 z₀, f z = (z - z₀) ^ p.order • (swap dslope z₀)^[p.order] f z := by have hq := hasFPowerSeriesAt_iff'.mp (has_fpower_series_iterate_dslope_fslope p.order hp) filter_upwards [hq, hasFPowerSeriesAt_iff'.mp hp] with x hx1 hx2 have : ∀ k < p.order, p.coeff k = 0 := fun k hk => by simpa [coeff_eq_zero] using apply_eq_zero_of_lt_order hk obtain ⟨s, hs1, hs2⟩ := HasSum.exists_hasSum_smul_of_apply_eq_zero hx2 this convert hs1.symm simp only [coeff_iterate_fslope] at hx1 exact hx1.unique hs2 #align has_fpower_series_at.eq_pow_order_mul_iterate_dslope HasFPowerSeriesAt.eq_pow_order_mul_iterate_dslope theorem locally_ne_zero (hp : HasFPowerSeriesAt f p z₀) (h : p ≠ 0) : ∀ᶠ z in 𝓝[≠] z₀, f z ≠ 0 := by rw [eventually_nhdsWithin_iff] have h2 := (has_fpower_series_iterate_dslope_fslope p.order hp).continuousAt have h3 := h2.eventually_ne (iterate_dslope_fslope_ne_zero hp h) filter_upwards [eq_pow_order_mul_iterate_dslope hp, h3] with z e1 e2 e3 simpa [e1, e2, e3] using pow_ne_zero p.order (sub_ne_zero.mpr e3) #align has_fpower_series_at.locally_ne_zero HasFPowerSeriesAt.locally_ne_zero theorem locally_zero_iff (hp : HasFPowerSeriesAt f p z₀) : (∀ᶠ z in 𝓝 z₀, f z = 0) ↔ p = 0 := ⟨fun hf => hp.eq_zero_of_eventually hf, fun h => eventually_eq_zero (by rwa [h] at hp)⟩ #align has_fpower_series_at.locally_zero_iff HasFPowerSeriesAt.locally_zero_iff end HasFPowerSeriesAt namespace AnalyticAt /-- The *principle of isolated zeros* for an analytic function, local version: if a function is analytic at `z₀`, then either it is identically zero in a neighborhood of `z₀`, or it does not vanish in a punctured neighborhood of `z₀`. -/
Mathlib/Analysis/Analytic/IsolatedZeros.lean
127
132
theorem eventually_eq_zero_or_eventually_ne_zero (hf : AnalyticAt 𝕜 f z₀) : (∀ᶠ z in 𝓝 z₀, f z = 0) ∨ ∀ᶠ z in 𝓝[≠] z₀, f z ≠ 0 := by
rcases hf with ⟨p, hp⟩ by_cases h : p = 0 · exact Or.inl (HasFPowerSeriesAt.eventually_eq_zero (by rwa [h] at hp)) · exact Or.inr (hp.locally_ne_zero h)
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Finset.Image import Mathlib.Data.List.FinRange #align_import data.fintype.basic from "leanprover-community/mathlib"@"d78597269638367c3863d40d45108f52207e03cf" /-! # Finite types This file defines a typeclass to state that a type is finite. ## Main declarations * `Fintype α`: Typeclass saying that a type is finite. It takes as fields a `Finset` and a proof that all terms of type `α` are in it. * `Finset.univ`: The finset of all elements of a fintype. See `Data.Fintype.Card` for the cardinality of a fintype, the equivalence with `Fin (Fintype.card α)`, and pigeonhole principles. ## Instances Instances for `Fintype` for * `{x // p x}` are in this file as `Fintype.subtype` * `Option α` are in `Data.Fintype.Option` * `α × β` are in `Data.Fintype.Prod` * `α ⊕ β` are in `Data.Fintype.Sum` * `Σ (a : α), β a` are in `Data.Fintype.Sigma` These files also contain appropriate `Infinite` instances for these types. `Infinite` instances for `ℕ`, `ℤ`, `Multiset α`, and `List α` are in `Data.Fintype.Lattice`. Types which have a surjection from/an injection to a `Fintype` are themselves fintypes. See `Fintype.ofInjective` and `Fintype.ofSurjective`. -/ assert_not_exists MonoidWithZero assert_not_exists MulAction open Function open Nat universe u v variable {α β γ : Type*} /-- `Fintype α` means that `α` is finite, i.e. there are only finitely many distinct elements of type `α`. The evidence of this is a finset `elems` (a list up to permutation without duplicates), together with a proof that everything of type `α` is in the list. -/ class Fintype (α : Type*) where /-- The `Finset` containing all elements of a `Fintype` -/ elems : Finset α /-- A proof that `elems` contains every element of the type -/ complete : ∀ x : α, x ∈ elems #align fintype Fintype namespace Finset variable [Fintype α] {s t : Finset α} /-- `univ` is the universal finite set of type `Finset α` implied from the assumption `Fintype α`. -/ def univ : Finset α := @Fintype.elems α _ #align finset.univ Finset.univ @[simp] theorem mem_univ (x : α) : x ∈ (univ : Finset α) := Fintype.complete x #align finset.mem_univ Finset.mem_univ -- Porting note: removing @[simp], simp can prove it theorem mem_univ_val : ∀ x, x ∈ (univ : Finset α).1 := mem_univ #align finset.mem_univ_val Finset.mem_univ_val theorem eq_univ_iff_forall : s = univ ↔ ∀ x, x ∈ s := by simp [ext_iff] #align finset.eq_univ_iff_forall Finset.eq_univ_iff_forall theorem eq_univ_of_forall : (∀ x, x ∈ s) → s = univ := eq_univ_iff_forall.2 #align finset.eq_univ_of_forall Finset.eq_univ_of_forall @[simp, norm_cast] theorem coe_univ : ↑(univ : Finset α) = (Set.univ : Set α) := by ext; simp #align finset.coe_univ Finset.coe_univ @[simp, norm_cast] theorem coe_eq_univ : (s : Set α) = Set.univ ↔ s = univ := by rw [← coe_univ, coe_inj] #align finset.coe_eq_univ Finset.coe_eq_univ theorem Nonempty.eq_univ [Subsingleton α] : s.Nonempty → s = univ := by rintro ⟨x, hx⟩ exact eq_univ_of_forall fun y => by rwa [Subsingleton.elim y x] #align finset.nonempty.eq_univ Finset.Nonempty.eq_univ theorem univ_nonempty_iff : (univ : Finset α).Nonempty ↔ Nonempty α := by rw [← coe_nonempty, coe_univ, Set.nonempty_iff_univ_nonempty] #align finset.univ_nonempty_iff Finset.univ_nonempty_iff @[aesop unsafe apply (rule_sets := [finsetNonempty])] theorem univ_nonempty [Nonempty α] : (univ : Finset α).Nonempty := univ_nonempty_iff.2 ‹_› #align finset.univ_nonempty Finset.univ_nonempty
Mathlib/Data/Fintype/Basic.lean
113
114
theorem univ_eq_empty_iff : (univ : Finset α) = ∅ ↔ IsEmpty α := by
rw [← not_nonempty_iff, ← univ_nonempty_iff, not_nonempty_iff_eq_empty]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Sébastien Gouëzel, Patrick Massot -/ import Mathlib.Topology.UniformSpace.Cauchy import Mathlib.Topology.UniformSpace.Separation import Mathlib.Topology.DenseEmbedding #align_import topology.uniform_space.uniform_embedding from "leanprover-community/mathlib"@"195fcd60ff2bfe392543bceb0ec2adcdb472db4c" /-! # Uniform embeddings of uniform spaces. Extension of uniform continuous functions. -/ open Filter Function Set Uniformity Topology section universe u v w variable {α : Type u} {β : Type v} {γ : Type w} [UniformSpace α] [UniformSpace β] [UniformSpace γ] /-! ### Uniform inducing maps -/ /-- A map `f : α → β` between uniform spaces is called *uniform inducing* if the uniformity filter on `α` is the pullback of the uniformity filter on `β` under `Prod.map f f`. If `α` is a separated space, then this implies that `f` is injective, hence it is a `UniformEmbedding`. -/ @[mk_iff] structure UniformInducing (f : α → β) : Prop where /-- The uniformity filter on the domain is the pullback of the uniformity filter on the codomain under `Prod.map f f`. -/ comap_uniformity : comap (fun x : α × α => (f x.1, f x.2)) (𝓤 β) = 𝓤 α #align uniform_inducing UniformInducing #align uniform_inducing_iff uniformInducing_iff lemma uniformInducing_iff_uniformSpace {f : α → β} : UniformInducing f ↔ ‹UniformSpace β›.comap f = ‹UniformSpace α› := by rw [uniformInducing_iff, UniformSpace.ext_iff, Filter.ext_iff] rfl protected alias ⟨UniformInducing.comap_uniformSpace, _⟩ := uniformInducing_iff_uniformSpace #align uniform_inducing.comap_uniform_space UniformInducing.comap_uniformSpace lemma uniformInducing_iff' {f : α → β} : UniformInducing f ↔ UniformContinuous f ∧ comap (Prod.map f f) (𝓤 β) ≤ 𝓤 α := by rw [uniformInducing_iff, UniformContinuous, tendsto_iff_comap, le_antisymm_iff, and_comm]; rfl #align uniform_inducing_iff' uniformInducing_iff' protected lemma Filter.HasBasis.uniformInducing_iff {ι ι'} {p : ι → Prop} {p' : ι' → Prop} {s s'} (h : (𝓤 α).HasBasis p s) (h' : (𝓤 β).HasBasis p' s') {f : α → β} : UniformInducing f ↔ (∀ i, p' i → ∃ j, p j ∧ ∀ x y, (x, y) ∈ s j → (f x, f y) ∈ s' i) ∧ (∀ j, p j → ∃ i, p' i ∧ ∀ x y, (f x, f y) ∈ s' i → (x, y) ∈ s j) := by simp [uniformInducing_iff', h.uniformContinuous_iff h', (h'.comap _).le_basis_iff h, subset_def] #align filter.has_basis.uniform_inducing_iff Filter.HasBasis.uniformInducing_iff theorem UniformInducing.mk' {f : α → β} (h : ∀ s, s ∈ 𝓤 α ↔ ∃ t ∈ 𝓤 β, ∀ x y : α, (f x, f y) ∈ t → (x, y) ∈ s) : UniformInducing f := ⟨by simp [eq_comm, Filter.ext_iff, subset_def, h]⟩ #align uniform_inducing.mk' UniformInducing.mk' theorem uniformInducing_id : UniformInducing (@id α) := ⟨by rw [← Prod.map_def, Prod.map_id, comap_id]⟩ #align uniform_inducing_id uniformInducing_id theorem UniformInducing.comp {g : β → γ} (hg : UniformInducing g) {f : α → β} (hf : UniformInducing f) : UniformInducing (g ∘ f) := ⟨by rw [← hf.1, ← hg.1, comap_comap]; rfl⟩ #align uniform_inducing.comp UniformInducing.comp theorem UniformInducing.of_comp_iff {g : β → γ} (hg : UniformInducing g) {f : α → β} : UniformInducing (g ∘ f) ↔ UniformInducing f := by refine ⟨fun h ↦ ?_, hg.comp⟩ rw [uniformInducing_iff, ← hg.comap_uniformity, comap_comap, ← h.comap_uniformity, Function.comp, Function.comp] theorem UniformInducing.basis_uniformity {f : α → β} (hf : UniformInducing f) {ι : Sort*} {p : ι → Prop} {s : ι → Set (β × β)} (H : (𝓤 β).HasBasis p s) : (𝓤 α).HasBasis p fun i => Prod.map f f ⁻¹' s i := hf.1 ▸ H.comap _ #align uniform_inducing.basis_uniformity UniformInducing.basis_uniformity theorem UniformInducing.cauchy_map_iff {f : α → β} (hf : UniformInducing f) {F : Filter α} : Cauchy (map f F) ↔ Cauchy F := by simp only [Cauchy, map_neBot_iff, prod_map_map_eq, map_le_iff_le_comap, ← hf.comap_uniformity] #align uniform_inducing.cauchy_map_iff UniformInducing.cauchy_map_iff
Mathlib/Topology/UniformSpace/UniformEmbedding.lean
93
97
theorem uniformInducing_of_compose {f : α → β} {g : β → γ} (hf : UniformContinuous f) (hg : UniformContinuous g) (hgf : UniformInducing (g ∘ f)) : UniformInducing f := by
refine ⟨le_antisymm ?_ hf.le_comap⟩ rw [← hgf.1, ← Prod.map_def, ← Prod.map_def, ← Prod.map_comp_map f f g g, ← comap_comap] exact comap_mono hg.le_comap
/- Copyright (c) 2021 Stuart Presnell. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Stuart Presnell -/ import Mathlib.Data.Finsupp.Multiset import Mathlib.Data.Nat.GCD.BigOperators import Mathlib.Data.Nat.PrimeFin import Mathlib.NumberTheory.Padics.PadicVal import Mathlib.Order.Interval.Finset.Nat #align_import data.nat.factorization.basic from "leanprover-community/mathlib"@"f694c7dead66f5d4c80f446c796a5aad14707f0e" /-! # Prime factorizations `n.factorization` is the finitely supported function `ℕ →₀ ℕ` mapping each prime factor of `n` to its multiplicity in `n`. For example, since 2000 = 2^4 * 5^3, * `factorization 2000 2` is 4 * `factorization 2000 5` is 3 * `factorization 2000 k` is 0 for all other `k : ℕ`. ## TODO * As discussed in this Zulip thread: https://leanprover.zulipchat.com/#narrow/stream/217875/topic/Multiplicity.20in.20the.20naturals We have lots of disparate ways of talking about the multiplicity of a prime in a natural number, including `factors.count`, `padicValNat`, `multiplicity`, and the material in `Data/PNat/Factors`. Move some of this material to this file, prove results about the relationships between these definitions, and (where appropriate) choose a uniform canonical way of expressing these ideas. * Moreover, the results here should be generalised to an arbitrary unique factorization monoid with a normalization function, and then deduplicated. The basics of this have been started in `RingTheory/UniqueFactorizationDomain`. * Extend the inductions to any `NormalizationMonoid` with unique factorization. -/ -- Workaround for lean4#2038 attribute [-instance] instBEqNat open Nat Finset List Finsupp namespace Nat variable {a b m n p : ℕ} /-- `n.factorization` is the finitely supported function `ℕ →₀ ℕ` mapping each prime factor of `n` to its multiplicity in `n`. -/ def factorization (n : ℕ) : ℕ →₀ ℕ where support := n.primeFactors toFun p := if p.Prime then padicValNat p n else 0 mem_support_toFun := by simp [not_or]; aesop #align nat.factorization Nat.factorization /-- The support of `n.factorization` is exactly `n.primeFactors`. -/ @[simp] lemma support_factorization (n : ℕ) : (factorization n).support = n.primeFactors := rfl theorem factorization_def (n : ℕ) {p : ℕ} (pp : p.Prime) : n.factorization p = padicValNat p n := by simpa [factorization] using absurd pp #align nat.factorization_def Nat.factorization_def /-- We can write both `n.factorization p` and `n.factors.count p` to represent the power of `p` in the factorization of `n`: we declare the former to be the simp-normal form. -/ @[simp] theorem factors_count_eq {n p : ℕ} : n.factors.count p = n.factorization p := by rcases n.eq_zero_or_pos with (rfl | hn0) · simp [factorization, count] if pp : p.Prime then ?_ else rw [count_eq_zero_of_not_mem (mt prime_of_mem_factors pp)] simp [factorization, pp] simp only [factorization_def _ pp] apply _root_.le_antisymm · rw [le_padicValNat_iff_replicate_subperm_factors pp hn0.ne'] exact List.le_count_iff_replicate_sublist.mp le_rfl |>.subperm · rw [← lt_add_one_iff, lt_iff_not_ge, ge_iff_le, le_padicValNat_iff_replicate_subperm_factors pp hn0.ne'] intro h have := h.count_le p simp at this #align nat.factors_count_eq Nat.factors_count_eq theorem factorization_eq_factors_multiset (n : ℕ) : n.factorization = Multiset.toFinsupp (n.factors : Multiset ℕ) := by ext p simp #align nat.factorization_eq_factors_multiset Nat.factorization_eq_factors_multiset theorem multiplicity_eq_factorization {n p : ℕ} (pp : p.Prime) (hn : n ≠ 0) : multiplicity p n = n.factorization p := by simp [factorization, pp, padicValNat_def' pp.ne_one hn.bot_lt] #align nat.multiplicity_eq_factorization Nat.multiplicity_eq_factorization /-! ### Basic facts about factorization -/ @[simp] theorem factorization_prod_pow_eq_self {n : ℕ} (hn : n ≠ 0) : n.factorization.prod (· ^ ·) = n := by rw [factorization_eq_factors_multiset n] simp only [← prod_toMultiset, factorization, Multiset.prod_coe, Multiset.toFinsupp_toMultiset] exact prod_factors hn #align nat.factorization_prod_pow_eq_self Nat.factorization_prod_pow_eq_self theorem eq_of_factorization_eq {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) (h : ∀ p : ℕ, a.factorization p = b.factorization p) : a = b := eq_of_perm_factors ha hb (by simpa only [List.perm_iff_count, factors_count_eq] using h) #align nat.eq_of_factorization_eq Nat.eq_of_factorization_eq /-- Every nonzero natural number has a unique prime factorization -/ theorem factorization_inj : Set.InjOn factorization { x : ℕ | x ≠ 0 } := fun a ha b hb h => eq_of_factorization_eq ha hb fun p => by simp [h] #align nat.factorization_inj Nat.factorization_inj @[simp] theorem factorization_zero : factorization 0 = 0 := by ext; simp [factorization] #align nat.factorization_zero Nat.factorization_zero @[simp] theorem factorization_one : factorization 1 = 0 := by ext; simp [factorization] #align nat.factorization_one Nat.factorization_one #noalign nat.support_factorization #align nat.factor_iff_mem_factorization Nat.mem_primeFactors_iff_mem_factors #align nat.prime_of_mem_factorization Nat.prime_of_mem_primeFactors #align nat.pos_of_mem_factorization Nat.pos_of_mem_primeFactors #align nat.le_of_mem_factorization Nat.le_of_mem_primeFactors /-! ## Lemmas characterising when `n.factorization p = 0` -/ theorem factorization_eq_zero_iff (n p : ℕ) : n.factorization p = 0 ↔ ¬p.Prime ∨ ¬p ∣ n ∨ n = 0 := by simp_rw [← not_mem_support_iff, support_factorization, mem_primeFactors, not_and_or, not_ne_iff] #align nat.factorization_eq_zero_iff Nat.factorization_eq_zero_iff @[simp] theorem factorization_eq_zero_of_non_prime (n : ℕ) {p : ℕ} (hp : ¬p.Prime) : n.factorization p = 0 := by simp [factorization_eq_zero_iff, hp] #align nat.factorization_eq_zero_of_non_prime Nat.factorization_eq_zero_of_non_prime theorem factorization_eq_zero_of_not_dvd {n p : ℕ} (h : ¬p ∣ n) : n.factorization p = 0 := by simp [factorization_eq_zero_iff, h] #align nat.factorization_eq_zero_of_not_dvd Nat.factorization_eq_zero_of_not_dvd theorem factorization_eq_zero_of_lt {n p : ℕ} (h : n < p) : n.factorization p = 0 := Finsupp.not_mem_support_iff.mp (mt le_of_mem_primeFactors (not_le_of_lt h)) #align nat.factorization_eq_zero_of_lt Nat.factorization_eq_zero_of_lt @[simp] theorem factorization_zero_right (n : ℕ) : n.factorization 0 = 0 := factorization_eq_zero_of_non_prime _ not_prime_zero #align nat.factorization_zero_right Nat.factorization_zero_right @[simp] theorem factorization_one_right (n : ℕ) : n.factorization 1 = 0 := factorization_eq_zero_of_non_prime _ not_prime_one #align nat.factorization_one_right Nat.factorization_one_right theorem dvd_of_factorization_pos {n p : ℕ} (hn : n.factorization p ≠ 0) : p ∣ n := dvd_of_mem_factors <| mem_primeFactors_iff_mem_factors.1 <| mem_support_iff.2 hn #align nat.dvd_of_factorization_pos Nat.dvd_of_factorization_pos theorem Prime.factorization_pos_of_dvd {n p : ℕ} (hp : p.Prime) (hn : n ≠ 0) (h : p ∣ n) : 0 < n.factorization p := by rwa [← factors_count_eq, count_pos_iff_mem, mem_factors_iff_dvd hn hp] #align nat.prime.factorization_pos_of_dvd Nat.Prime.factorization_pos_of_dvd theorem factorization_eq_zero_of_remainder {p r : ℕ} (i : ℕ) (hr : ¬p ∣ r) : (p * i + r).factorization p = 0 := by apply factorization_eq_zero_of_not_dvd rwa [← Nat.dvd_add_iff_right (Dvd.intro i rfl)] #align nat.factorization_eq_zero_of_remainder Nat.factorization_eq_zero_of_remainder theorem factorization_eq_zero_iff_remainder {p r : ℕ} (i : ℕ) (pp : p.Prime) (hr0 : r ≠ 0) : ¬p ∣ r ↔ (p * i + r).factorization p = 0 := by refine ⟨factorization_eq_zero_of_remainder i, fun h => ?_⟩ rw [factorization_eq_zero_iff] at h contrapose! h refine ⟨pp, ?_, ?_⟩ · rwa [← Nat.dvd_add_iff_right (dvd_mul_right p i)] · contrapose! hr0 exact (add_eq_zero_iff.mp hr0).2 #align nat.factorization_eq_zero_iff_remainder Nat.factorization_eq_zero_iff_remainder /-- The only numbers with empty prime factorization are `0` and `1` -/ theorem factorization_eq_zero_iff' (n : ℕ) : n.factorization = 0 ↔ n = 0 ∨ n = 1 := by rw [factorization_eq_factors_multiset n] simp [factorization, AddEquiv.map_eq_zero_iff, Multiset.coe_eq_zero] #align nat.factorization_eq_zero_iff' Nat.factorization_eq_zero_iff' /-! ## Lemmas about factorizations of products and powers -/ /-- For nonzero `a` and `b`, the power of `p` in `a * b` is the sum of the powers in `a` and `b` -/ @[simp]
Mathlib/Data/Nat/Factorization/Basic.lean
198
202
theorem factorization_mul {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) : (a * b).factorization = a.factorization + b.factorization := by
ext p simp only [add_apply, ← factors_count_eq, perm_iff_count.mp (perm_factors_mul ha hb) p, count_append]
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Morenikeji Neri -/ import Mathlib.Algebra.EuclideanDomain.Instances import Mathlib.RingTheory.Ideal.Colon import Mathlib.RingTheory.UniqueFactorizationDomain #align_import ring_theory.principal_ideal_domain from "leanprover-community/mathlib"@"6010cf523816335f7bae7f8584cb2edaace73940" /-! # Principal ideal rings, principal ideal domains, and Bézout rings A principal ideal ring (PIR) is a ring in which all left ideals are principal. A principal ideal domain (PID) is an integral domain which is a principal ideal ring. # Main definitions Note that for principal ideal domains, one should use `[IsDomain R] [IsPrincipalIdealRing R]`. There is no explicit definition of a PID. Theorems about PID's are in the `principal_ideal_ring` namespace. - `IsPrincipalIdealRing`: a predicate on rings, saying that every left ideal is principal. - `IsBezout`: the predicate saying that every finitely generated left ideal is principal. - `generator`: a generator of a principal ideal (or more generally submodule) - `to_unique_factorization_monoid`: a PID is a unique factorization domain # Main results - `to_maximal_ideal`: a non-zero prime ideal in a PID is maximal. - `EuclideanDomain.to_principal_ideal_domain` : a Euclidean domain is a PID. - `IsBezout.nonemptyGCDMonoid`: Every Bézout domain is a GCD domain. -/ universe u v variable {R : Type u} {M : Type v} open Set Function open Submodule section variable [Ring R] [AddCommGroup M] [Module R M] instance bot_isPrincipal : (⊥ : Submodule R M).IsPrincipal := ⟨⟨0, by simp⟩⟩ #align bot_is_principal bot_isPrincipal instance top_isPrincipal : (⊤ : Submodule R R).IsPrincipal := ⟨⟨1, Ideal.span_singleton_one.symm⟩⟩ #align top_is_principal top_isPrincipal variable (R) /-- A Bézout ring is a ring whose finitely generated ideals are principal. -/ class IsBezout : Prop where /-- Any finitely generated ideal is principal. -/ isPrincipal_of_FG : ∀ I : Ideal R, I.FG → I.IsPrincipal #align is_bezout IsBezout instance (priority := 100) IsBezout.of_isPrincipalIdealRing [IsPrincipalIdealRing R] : IsBezout R := ⟨fun I _ => IsPrincipalIdealRing.principal I⟩ #align is_bezout.of_is_principal_ideal_ring IsBezout.of_isPrincipalIdealRing instance (priority := 100) DivisionRing.isPrincipalIdealRing (K : Type u) [DivisionRing K] : IsPrincipalIdealRing K where principal S := by rcases Ideal.eq_bot_or_top S with (rfl | rfl) · apply bot_isPrincipal · apply top_isPrincipal #align division_ring.is_principal_ideal_ring DivisionRing.isPrincipalIdealRing end namespace Submodule.IsPrincipal variable [AddCommGroup M] section Ring variable [Ring R] [Module R M] /-- `generator I`, if `I` is a principal submodule, is an `x ∈ M` such that `span R {x} = I` -/ noncomputable def generator (S : Submodule R M) [S.IsPrincipal] : M := Classical.choose (principal S) #align submodule.is_principal.generator Submodule.IsPrincipal.generator theorem span_singleton_generator (S : Submodule R M) [S.IsPrincipal] : span R {generator S} = S := Eq.symm (Classical.choose_spec (principal S)) #align submodule.is_principal.span_singleton_generator Submodule.IsPrincipal.span_singleton_generator @[simp] theorem _root_.Ideal.span_singleton_generator (I : Ideal R) [I.IsPrincipal] : Ideal.span ({generator I} : Set R) = I := Eq.symm (Classical.choose_spec (principal I)) #align ideal.span_singleton_generator Ideal.span_singleton_generator @[simp] theorem generator_mem (S : Submodule R M) [S.IsPrincipal] : generator S ∈ S := by conv_rhs => rw [← span_singleton_generator S] exact subset_span (mem_singleton _) #align submodule.is_principal.generator_mem Submodule.IsPrincipal.generator_mem theorem mem_iff_eq_smul_generator (S : Submodule R M) [S.IsPrincipal] {x : M} : x ∈ S ↔ ∃ s : R, x = s • generator S := by simp_rw [@eq_comm _ x, ← mem_span_singleton, span_singleton_generator] #align submodule.is_principal.mem_iff_eq_smul_generator Submodule.IsPrincipal.mem_iff_eq_smul_generator theorem eq_bot_iff_generator_eq_zero (S : Submodule R M) [S.IsPrincipal] : S = ⊥ ↔ generator S = 0 := by rw [← @span_singleton_eq_bot R M, span_singleton_generator] #align submodule.is_principal.eq_bot_iff_generator_eq_zero Submodule.IsPrincipal.eq_bot_iff_generator_eq_zero end Ring section CommRing variable [CommRing R] [Module R M] theorem associated_generator_span_self [IsPrincipalIdealRing R] [IsDomain R] (r : R) : Associated (generator <| Ideal.span {r}) r := by rw [← Ideal.span_singleton_eq_span_singleton] exact Ideal.span_singleton_generator _ theorem mem_iff_generator_dvd (S : Ideal R) [S.IsPrincipal] {x : R} : x ∈ S ↔ generator S ∣ x := (mem_iff_eq_smul_generator S).trans (exists_congr fun a => by simp only [mul_comm, smul_eq_mul]) #align submodule.is_principal.mem_iff_generator_dvd Submodule.IsPrincipal.mem_iff_generator_dvd theorem prime_generator_of_isPrime (S : Ideal R) [S.IsPrincipal] [is_prime : S.IsPrime] (ne_bot : S ≠ ⊥) : Prime (generator S) := ⟨fun h => ne_bot ((eq_bot_iff_generator_eq_zero S).2 h), fun h => is_prime.ne_top (S.eq_top_of_isUnit_mem (generator_mem S) h), fun _ _ => by simpa only [← mem_iff_generator_dvd S] using is_prime.2⟩ #align submodule.is_principal.prime_generator_of_is_prime Submodule.IsPrincipal.prime_generator_of_isPrime -- Note that the converse may not hold if `ϕ` is not injective. theorem generator_map_dvd_of_mem {N : Submodule R M} (ϕ : M →ₗ[R] R) [(N.map ϕ).IsPrincipal] {x : M} (hx : x ∈ N) : generator (N.map ϕ) ∣ ϕ x := by rw [← mem_iff_generator_dvd, Submodule.mem_map] exact ⟨x, hx, rfl⟩ #align submodule.is_principal.generator_map_dvd_of_mem Submodule.IsPrincipal.generator_map_dvd_of_mem -- Note that the converse may not hold if `ϕ` is not injective. theorem generator_submoduleImage_dvd_of_mem {N O : Submodule R M} (hNO : N ≤ O) (ϕ : O →ₗ[R] R) [(ϕ.submoduleImage N).IsPrincipal] {x : M} (hx : x ∈ N) : generator (ϕ.submoduleImage N) ∣ ϕ ⟨x, hNO hx⟩ := by rw [← mem_iff_generator_dvd, LinearMap.mem_submoduleImage_of_le hNO] exact ⟨x, hx, rfl⟩ #align submodule.is_principal.generator_submodule_image_dvd_of_mem Submodule.IsPrincipal.generator_submoduleImage_dvd_of_mem end CommRing end Submodule.IsPrincipal namespace IsBezout section variable [Ring R] instance span_pair_isPrincipal [IsBezout R] (x y : R) : (Ideal.span {x, y}).IsPrincipal := by classical exact isPrincipal_of_FG (Ideal.span {x, y}) ⟨{x, y}, by simp⟩ #align is_bezout.span_pair_is_principal IsBezout.span_pair_isPrincipal variable (x y : R) [(Ideal.span {x, y}).IsPrincipal] /-- A choice of gcd of two elements in a Bézout domain. Note that the choice is usually not unique. -/ noncomputable def gcd : R := Submodule.IsPrincipal.generator (Ideal.span {x, y}) #align is_bezout.gcd IsBezout.gcd theorem span_gcd : Ideal.span {gcd x y} = Ideal.span {x, y} := Ideal.span_singleton_generator _ #align is_bezout.span_gcd IsBezout.span_gcd end variable [CommRing R] (x y z : R) [(Ideal.span {x, y}).IsPrincipal] theorem gcd_dvd_left : gcd x y ∣ x := (Submodule.IsPrincipal.mem_iff_generator_dvd _).mp (Ideal.subset_span (by simp)) #align is_bezout.gcd_dvd_left IsBezout.gcd_dvd_left theorem gcd_dvd_right : gcd x y ∣ y := (Submodule.IsPrincipal.mem_iff_generator_dvd _).mp (Ideal.subset_span (by simp)) #align is_bezout.gcd_dvd_right IsBezout.gcd_dvd_right variable {x y z} in theorem dvd_gcd (hx : z ∣ x) (hy : z ∣ y) : z ∣ gcd x y := by rw [← Ideal.span_singleton_le_span_singleton] at hx hy ⊢ rw [span_gcd, Ideal.span_insert, sup_le_iff] exact ⟨hx, hy⟩ #align is_bezout.dvd_gcd IsBezout.dvd_gcd theorem gcd_eq_sum : ∃ a b : R, a * x + b * y = gcd x y := Ideal.mem_span_pair.mp (by rw [← span_gcd]; apply Ideal.subset_span; simp) #align is_bezout.gcd_eq_sum IsBezout.gcd_eq_sum variable {x y}
Mathlib/RingTheory/PrincipalIdealDomain.lean
206
209
theorem _root_.IsRelPrime.isCoprime (h : IsRelPrime x y) : IsCoprime x y := by
rw [← Ideal.isCoprime_span_singleton_iff, Ideal.isCoprime_iff_sup_eq, ← Ideal.span_union, Set.singleton_union, ← span_gcd, Ideal.span_singleton_eq_top] exact h (gcd_dvd_left x y) (gcd_dvd_right x y)
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.LinearAlgebra.FreeModule.PID import Mathlib.LinearAlgebra.Matrix.AbsoluteValue import Mathlib.NumberTheory.ClassNumber.AdmissibleAbsoluteValue import Mathlib.RingTheory.ClassGroup import Mathlib.RingTheory.DedekindDomain.IntegralClosure import Mathlib.RingTheory.Norm #align_import number_theory.class_number.finite from "leanprover-community/mathlib"@"ea0bcd84221246c801a6f8fbe8a4372f6d04b176" /-! # Class numbers of global fields In this file, we use the notion of "admissible absolute value" to prove finiteness of the class group for number fields and function fields. ## Main definitions - `ClassGroup.fintypeOfAdmissibleOfAlgebraic`: if `R` has an admissible absolute value, its integral closure has a finite class group -/ open scoped nonZeroDivisors namespace ClassGroup open Ring section EuclideanDomain variable {R S : Type*} (K L : Type*) [EuclideanDomain R] [CommRing S] [IsDomain S] variable [Field K] [Field L] variable [Algebra R K] [IsFractionRing R K] variable [Algebra K L] [FiniteDimensional K L] [IsSeparable K L] variable [algRL : Algebra R L] [IsScalarTower R K L] variable [Algebra R S] [Algebra S L] variable [ist : IsScalarTower R S L] [iic : IsIntegralClosure S R L] variable (abv : AbsoluteValue R ℤ) variable {ι : Type*} [DecidableEq ι] [Fintype ι] (bS : Basis ι R S) /-- If `b` is an `R`-basis of `S` of cardinality `n`, then `normBound abv b` is an integer such that for every `R`-integral element `a : S` with coordinates `≤ y`, we have algebra.norm a ≤ norm_bound abv b * y ^ n`. (See also `norm_le` and `norm_lt`). -/ noncomputable def normBound : ℤ := let n := Fintype.card ι let i : ι := Nonempty.some bS.index_nonempty let m : ℤ := Finset.max' (Finset.univ.image fun ijk : ι × ι × ι => abv (Algebra.leftMulMatrix bS (bS ijk.1) ijk.2.1 ijk.2.2)) ⟨_, Finset.mem_image.mpr ⟨⟨i, i, i⟩, Finset.mem_univ _, rfl⟩⟩ Nat.factorial n • (n • m) ^ n #align class_group.norm_bound ClassGroup.normBound theorem normBound_pos : 0 < normBound abv bS := by obtain ⟨i, j, k, hijk⟩ : ∃ i j k, Algebra.leftMulMatrix bS (bS i) j k ≠ 0 := by by_contra! h obtain ⟨i⟩ := bS.index_nonempty apply bS.ne_zero i apply (injective_iff_map_eq_zero (Algebra.leftMulMatrix bS)).mp (Algebra.leftMulMatrix_injective bS) ext j k simp [h, DMatrix.zero_apply] simp only [normBound, Algebra.smul_def, eq_natCast] apply mul_pos (Int.natCast_pos.mpr (Nat.factorial_pos _)) refine pow_pos (mul_pos (Int.natCast_pos.mpr (Fintype.card_pos_iff.mpr ⟨i⟩)) ?_) _ refine lt_of_lt_of_le (abv.pos hijk) (Finset.le_max' _ _ ?_) exact Finset.mem_image.mpr ⟨⟨i, j, k⟩, Finset.mem_univ _, rfl⟩ #align class_group.norm_bound_pos ClassGroup.normBound_pos /-- If the `R`-integral element `a : S` has coordinates `≤ y` with respect to some basis `b`, its norm is less than `normBound abv b * y ^ dim S`. -/ theorem norm_le (a : S) {y : ℤ} (hy : ∀ k, abv (bS.repr a k) ≤ y) : abv (Algebra.norm R a) ≤ normBound abv bS * y ^ Fintype.card ι := by conv_lhs => rw [← bS.sum_repr a] rw [Algebra.norm_apply, ← LinearMap.det_toMatrix bS] simp only [Algebra.norm_apply, AlgHom.map_sum, AlgHom.map_smul, map_sum, map_smul, Algebra.toMatrix_lmul_eq, normBound, smul_mul_assoc, ← mul_pow] convert Matrix.det_sum_smul_le Finset.univ _ hy using 3 · rw [Finset.card_univ, smul_mul_assoc, mul_comm] · intro i j k apply Finset.le_max' exact Finset.mem_image.mpr ⟨⟨i, j, k⟩, Finset.mem_univ _, rfl⟩ #align class_group.norm_le ClassGroup.norm_le /-- If the `R`-integral element `a : S` has coordinates `< y` with respect to some basis `b`, its norm is strictly less than `normBound abv b * y ^ dim S`. -/ theorem norm_lt {T : Type*} [LinearOrderedRing T] (a : S) {y : T} (hy : ∀ k, (abv (bS.repr a k) : T) < y) : (abv (Algebra.norm R a) : T) < normBound abv bS * y ^ Fintype.card ι := by obtain ⟨i⟩ := bS.index_nonempty have him : (Finset.univ.image fun k => abv (bS.repr a k)).Nonempty := ⟨_, Finset.mem_image.mpr ⟨i, Finset.mem_univ _, rfl⟩⟩ set y' : ℤ := Finset.max' _ him with y'_def have hy' : ∀ k, abv (bS.repr a k) ≤ y' := by intro k exact @Finset.le_max' ℤ _ _ _ (Finset.mem_image.mpr ⟨k, Finset.mem_univ _, rfl⟩) have : (y' : T) < y := by rw [y'_def, ← Finset.max'_image (show Monotone (_ : ℤ → T) from fun x y h => Int.cast_le.mpr h)] apply (Finset.max'_lt_iff _ (him.image _)).mpr simp only [Finset.mem_image, exists_prop] rintro _ ⟨x, ⟨k, -, rfl⟩, rfl⟩ exact hy k have y'_nonneg : 0 ≤ y' := le_trans (abv.nonneg _) (hy' i) apply (Int.cast_le.mpr (norm_le abv bS a hy')).trans_lt simp only [Int.cast_mul, Int.cast_pow] apply mul_lt_mul' le_rfl · exact pow_lt_pow_left this (Int.cast_nonneg.mpr y'_nonneg) (@Fintype.card_ne_zero _ _ ⟨i⟩) · exact pow_nonneg (Int.cast_nonneg.mpr y'_nonneg) _ · exact Int.cast_pos.mpr (normBound_pos abv bS) #align class_group.norm_lt ClassGroup.norm_lt /-- A nonzero ideal has an element of minimal norm. -/ theorem exists_min (I : (Ideal S)⁰) : ∃ b ∈ (I : Ideal S), b ≠ 0 ∧ ∀ c ∈ (I : Ideal S), abv (Algebra.norm R c) < abv (Algebra.norm R b) → c = (0 : S) := by obtain ⟨_, ⟨b, b_mem, b_ne_zero, rfl⟩, min⟩ := @Int.exists_least_of_bdd (fun a => ∃ b ∈ (I : Ideal S), b ≠ (0 : S) ∧ abv (Algebra.norm R b) = a) (by use 0 rintro _ ⟨b, _, _, rfl⟩ apply abv.nonneg) (by obtain ⟨b, b_mem, b_ne_zero⟩ := (I : Ideal S).ne_bot_iff.mp (nonZeroDivisors.coe_ne_zero I) exact ⟨_, ⟨b, b_mem, b_ne_zero, rfl⟩⟩) refine ⟨b, b_mem, b_ne_zero, ?_⟩ intro c hc lt contrapose! lt with c_ne_zero exact min _ ⟨c, hc, c_ne_zero, rfl⟩ #align class_group.exists_min ClassGroup.exists_min section IsAdmissible variable {abv} (adm : abv.IsAdmissible) /-- If we have a large enough set of elements in `R^ι`, then there will be a pair whose remainders are close together. We'll show that all sets of cardinality at least `cardM bS adm` elements satisfy this condition. The value of `cardM` is not at all optimal: for specific choices of `R`, the minimum cardinality can be exponentially smaller. -/ noncomputable def cardM : ℕ := adm.card (normBound abv bS ^ (-1 / Fintype.card ι : ℝ)) ^ Fintype.card ι set_option linter.uppercaseLean3 false in #align class_group.cardM ClassGroup.cardM variable [Infinite R] /-- In the following results, we need a large set of distinct elements of `R`. -/ noncomputable def distinctElems : Fin (cardM bS adm).succ ↪ R := Fin.valEmbedding.trans (Infinite.natEmbedding R) #align class_group.distinct_elems ClassGroup.distinctElems variable [DecidableEq R] /-- `finsetApprox` is a finite set such that each fractional ideal in the integral closure contains an element close to `finsetApprox`. -/ noncomputable def finsetApprox : Finset R := (Finset.univ.image fun xy : _ × _ => distinctElems bS adm xy.1 - distinctElems bS adm xy.2).erase 0 #align class_group.finset_approx ClassGroup.finsetApprox theorem finsetApprox.zero_not_mem : (0 : R) ∉ finsetApprox bS adm := Finset.not_mem_erase _ _ #align class_group.finset_approx.zero_not_mem ClassGroup.finsetApprox.zero_not_mem @[simp] theorem mem_finsetApprox {x : R} : x ∈ finsetApprox bS adm ↔ ∃ i j, i ≠ j ∧ distinctElems bS adm i - distinctElems bS adm j = x := by simp only [finsetApprox, Finset.mem_erase, Finset.mem_image] constructor · rintro ⟨hx, ⟨i, j⟩, _, rfl⟩ refine ⟨i, j, ?_, rfl⟩ rintro rfl simp at hx · rintro ⟨i, j, hij, rfl⟩ refine ⟨?_, ⟨i, j⟩, Finset.mem_univ _, rfl⟩ rw [Ne, sub_eq_zero] exact fun h => hij ((distinctElems bS adm).injective h) #align class_group.mem_finset_approx ClassGroup.mem_finsetApprox section Real open Real attribute [-instance] Real.decidableEq /-- We can approximate `a / b : L` with `q / r`, where `r` has finitely many options for `L`. -/
Mathlib/NumberTheory/ClassNumber/Finite.lean
197
247
theorem exists_mem_finsetApprox (a : S) {b} (hb : b ≠ (0 : R)) : ∃ q : S, ∃ r ∈ finsetApprox bS adm, abv (Algebra.norm R (r • a - b • q)) < abv (Algebra.norm R (algebraMap R S b)) := by
have dim_pos := Fintype.card_pos_iff.mpr bS.index_nonempty set ε : ℝ := normBound abv bS ^ (-1 / Fintype.card ι : ℝ) with ε_eq have hε : 0 < ε := Real.rpow_pos_of_pos (Int.cast_pos.mpr (normBound_pos abv bS)) _ have ε_le : (normBound abv bS : ℝ) * (abv b • ε) ^ (Fintype.card ι : ℝ) ≤ abv b ^ (Fintype.card ι : ℝ) := by have := normBound_pos abv bS have := abv.nonneg b rw [ε_eq, Algebra.smul_def, eq_intCast, mul_rpow, ← rpow_mul, div_mul_cancel₀, rpow_neg_one, mul_left_comm, mul_inv_cancel, mul_one, rpow_natCast] <;> try norm_cast; omega · exact Iff.mpr Int.cast_nonneg this · linarith set μ : Fin (cardM bS adm).succ ↪ R := distinctElems bS adm with hμ let s : ι →₀ R := bS.repr a have s_eq : ∀ i, s i = bS.repr a i := fun i => rfl let qs : Fin (cardM bS adm).succ → ι → R := fun j i => μ j * s i / b let rs : Fin (cardM bS adm).succ → ι → R := fun j i => μ j * s i % b have r_eq : ∀ j i, rs j i = μ j * s i % b := fun i j => rfl have μ_eq : ∀ i j, μ j * s i = b * qs j i + rs j i := by intro i j rw [r_eq, EuclideanDomain.div_add_mod] have μ_mul_a_eq : ∀ j, μ j • a = b • ∑ i, qs j i • bS i + ∑ i, rs j i • bS i := by intro j rw [← bS.sum_repr a] simp only [μ, qs, rs, Finset.smul_sum, ← Finset.sum_add_distrib] refine Finset.sum_congr rfl fun i _ => ?_ -- Porting note `← hμ, ← r_eq` and the final `← μ_eq` were not needed. rw [← hμ, ← r_eq, ← s_eq, ← mul_smul, μ_eq, add_smul, mul_smul, ← μ_eq] obtain ⟨j, k, j_ne_k, hjk⟩ := adm.exists_approx hε hb fun j i => μ j * s i have hjk' : ∀ i, (abv (rs k i - rs j i) : ℝ) < abv b • ε := by simpa only [r_eq] using hjk let q := ∑ i, (qs k i - qs j i) • bS i set r := μ k - μ j with r_eq refine ⟨q, r, (mem_finsetApprox bS adm).mpr ?_, ?_⟩ · exact ⟨k, j, j_ne_k.symm, rfl⟩ have : r • a - b • q = ∑ x : ι, (rs k x • bS x - rs j x • bS x) := by simp only [q, r_eq, sub_smul, μ_mul_a_eq, Finset.smul_sum, ← Finset.sum_add_distrib, ← Finset.sum_sub_distrib, smul_sub] refine Finset.sum_congr rfl fun x _ => ?_ ring rw [this, Algebra.norm_algebraMap_of_basis bS, abv.map_pow] refine Int.cast_lt.mp ((norm_lt abv bS _ fun i => lt_of_le_of_lt ?_ (hjk' i)).trans_le ?_) · apply le_of_eq congr simp_rw [map_sum, map_sub, map_smul, Finset.sum_apply', Finsupp.sub_apply, Finsupp.smul_apply, Finset.sum_sub_distrib, Basis.repr_self_apply, smul_eq_mul, mul_boole, Finset.sum_ite_eq', Finset.mem_univ, if_true] · exact mod_cast ε_le
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Sébastien Gouëzel, Heather Macbeth -/ import Mathlib.Analysis.InnerProductSpace.Projection import Mathlib.Analysis.NormedSpace.PiLp import Mathlib.LinearAlgebra.FiniteDimensional import Mathlib.LinearAlgebra.UnitaryGroup #align_import analysis.inner_product_space.pi_L2 from "leanprover-community/mathlib"@"13bce9a6b6c44f6b4c91ac1c1d2a816e2533d395" /-! # `L²` inner product space structure on finite products of inner product spaces The `L²` norm on a finite product of inner product spaces is compatible with an inner product $$ \langle x, y\rangle = \sum \langle x_i, y_i \rangle. $$ This is recorded in this file as an inner product space instance on `PiLp 2`. This file develops the notion of a finite dimensional Hilbert space over `𝕜 = ℂ, ℝ`, referred to as `E`. We define an `OrthonormalBasis 𝕜 ι E` as a linear isometric equivalence between `E` and `EuclideanSpace 𝕜 ι`. Then `stdOrthonormalBasis` shows that such an equivalence always exists if `E` is finite dimensional. We provide language for converting between a basis that is orthonormal and an orthonormal basis (e.g. `Basis.toOrthonormalBasis`). We show that orthonormal bases for each summand in a direct sum of spaces can be combined into an orthonormal basis for the whole sum in `DirectSum.IsInternal.subordinateOrthonormalBasis`. In the last section, various properties of matrices are explored. ## Main definitions - `EuclideanSpace 𝕜 n`: defined to be `PiLp 2 (n → 𝕜)` for any `Fintype n`, i.e., the space from functions to `n` to `𝕜` with the `L²` norm. We register several instances on it (notably that it is a finite-dimensional inner product space). - `OrthonormalBasis 𝕜 ι`: defined to be an isometry to Euclidean space from a given finite-dimensional inner product space, `E ≃ₗᵢ[𝕜] EuclideanSpace 𝕜 ι`. - `Basis.toOrthonormalBasis`: constructs an `OrthonormalBasis` for a finite-dimensional Euclidean space from a `Basis` which is `Orthonormal`. - `Orthonormal.exists_orthonormalBasis_extension`: provides an existential result of an `OrthonormalBasis` extending a given orthonormal set - `exists_orthonormalBasis`: provides an orthonormal basis on a finite dimensional vector space - `stdOrthonormalBasis`: provides an arbitrarily-chosen `OrthonormalBasis` of a given finite dimensional inner product space For consequences in infinite dimension (Hilbert bases, etc.), see the file `Analysis.InnerProductSpace.L2Space`. -/ set_option linter.uppercaseLean3 false open Real Set Filter RCLike Submodule Function Uniformity Topology NNReal ENNReal ComplexConjugate DirectSum noncomputable section variable {ι ι' 𝕜 : Type*} [RCLike 𝕜] variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] variable {E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] variable {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] variable {F' : Type*} [NormedAddCommGroup F'] [InnerProductSpace ℝ F'] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y /- If `ι` is a finite type and each space `f i`, `i : ι`, is an inner product space, then `Π i, f i` is an inner product space as well. Since `Π i, f i` is endowed with the sup norm, we use instead `PiLp 2 f` for the product space, which is endowed with the `L^2` norm. -/ instance PiLp.innerProductSpace {ι : Type*} [Fintype ι] (f : ι → Type*) [∀ i, NormedAddCommGroup (f i)] [∀ i, InnerProductSpace 𝕜 (f i)] : InnerProductSpace 𝕜 (PiLp 2 f) where inner x y := ∑ i, inner (x i) (y i) norm_sq_eq_inner x := by simp only [PiLp.norm_sq_eq_of_L2, map_sum, ← norm_sq_eq_inner, one_div] conj_symm := by intro x y unfold inner rw [map_sum] apply Finset.sum_congr rfl rintro z - apply inner_conj_symm add_left x y z := show (∑ i, inner (x i + y i) (z i)) = (∑ i, inner (x i) (z i)) + ∑ i, inner (y i) (z i) by simp only [inner_add_left, Finset.sum_add_distrib] smul_left x y r := show (∑ i : ι, inner (r • x i) (y i)) = conj r * ∑ i, inner (x i) (y i) by simp only [Finset.mul_sum, inner_smul_left] #align pi_Lp.inner_product_space PiLp.innerProductSpace @[simp] theorem PiLp.inner_apply {ι : Type*} [Fintype ι] {f : ι → Type*} [∀ i, NormedAddCommGroup (f i)] [∀ i, InnerProductSpace 𝕜 (f i)] (x y : PiLp 2 f) : ⟪x, y⟫ = ∑ i, ⟪x i, y i⟫ := rfl #align pi_Lp.inner_apply PiLp.inner_apply /-- The standard real/complex Euclidean space, functions on a finite type. For an `n`-dimensional space use `EuclideanSpace 𝕜 (Fin n)`. -/ abbrev EuclideanSpace (𝕜 : Type*) (n : Type*) : Type _ := PiLp 2 fun _ : n => 𝕜 #align euclidean_space EuclideanSpace theorem EuclideanSpace.nnnorm_eq {𝕜 : Type*} [RCLike 𝕜] {n : Type*} [Fintype n] (x : EuclideanSpace 𝕜 n) : ‖x‖₊ = NNReal.sqrt (∑ i, ‖x i‖₊ ^ 2) := PiLp.nnnorm_eq_of_L2 x #align euclidean_space.nnnorm_eq EuclideanSpace.nnnorm_eq
Mathlib/Analysis/InnerProductSpace/PiL2.lean
114
116
theorem EuclideanSpace.norm_eq {𝕜 : Type*} [RCLike 𝕜] {n : Type*} [Fintype n] (x : EuclideanSpace 𝕜 n) : ‖x‖ = √(∑ i, ‖x i‖ ^ 2) := by
simpa only [Real.coe_sqrt, NNReal.coe_sum] using congr_arg ((↑) : ℝ≥0 → ℝ) x.nnnorm_eq
/- Copyright (c) 2020 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.Algebra.Group.Conj import Mathlib.Algebra.Group.Pi.Lemmas import Mathlib.Algebra.Group.Subsemigroup.Operations import Mathlib.Algebra.Group.Submonoid.Operations import Mathlib.Algebra.Order.Group.Abs import Mathlib.Data.Set.Image import Mathlib.Order.Atoms import Mathlib.Tactic.ApplyFun #align_import group_theory.subgroup.basic from "leanprover-community/mathlib"@"4be589053caf347b899a494da75410deb55fb3ef" /-! # Subgroups This file defines multiplicative and additive subgroups as an extension of submonoids, in a bundled form (unbundled subgroups are in `Deprecated/Subgroups.lean`). We prove subgroups of a group form a complete lattice, and results about images and preimages of subgroups under group homomorphisms. The bundled subgroups use bundled monoid homomorphisms. There are also theorems about the subgroups generated by an element or a subset of a group, defined both inductively and as the infimum of the set of subgroups containing a given element/subset. Special thanks goes to Amelia Livingston and Yury Kudryashov for their help and inspiration. ## Main definitions Notation used here: - `G N` are `Group`s - `A` is an `AddGroup` - `H K` are `Subgroup`s of `G` or `AddSubgroup`s of `A` - `x` is an element of type `G` or type `A` - `f g : N →* G` are group homomorphisms - `s k` are sets of elements of type `G` Definitions in the file: * `Subgroup G` : the type of subgroups of a group `G` * `AddSubgroup A` : the type of subgroups of an additive group `A` * `CompleteLattice (Subgroup G)` : the subgroups of `G` form a complete lattice * `Subgroup.closure k` : the minimal subgroup that includes the set `k` * `Subgroup.subtype` : the natural group homomorphism from a subgroup of group `G` to `G` * `Subgroup.gi` : `closure` forms a Galois insertion with the coercion to set * `Subgroup.comap H f` : the preimage of a subgroup `H` along the group homomorphism `f` is also a subgroup * `Subgroup.map f H` : the image of a subgroup `H` along the group homomorphism `f` is also a subgroup * `Subgroup.prod H K` : the product of subgroups `H`, `K` of groups `G`, `N` respectively, `H × K` is a subgroup of `G × N` * `MonoidHom.range f` : the range of the group homomorphism `f` is a subgroup * `MonoidHom.ker f` : the kernel of a group homomorphism `f` is the subgroup of elements `x : G` such that `f x = 1` * `MonoidHom.eq_locus f g` : given group homomorphisms `f`, `g`, the elements of `G` such that `f x = g x` form a subgroup of `G` ## Implementation notes Subgroup inclusion is denoted `≤` rather than `⊆`, although `∈` is defined as membership of a subgroup's underlying set. ## Tags subgroup, subgroups -/ open Function open Int variable {G G' G'' : Type*} [Group G] [Group G'] [Group G''] variable {A : Type*} [AddGroup A] section SubgroupClass /-- `InvMemClass S G` states `S` is a type of subsets `s ⊆ G` closed under inverses. -/ class InvMemClass (S G : Type*) [Inv G] [SetLike S G] : Prop where /-- `s` is closed under inverses -/ inv_mem : ∀ {s : S} {x}, x ∈ s → x⁻¹ ∈ s #align inv_mem_class InvMemClass export InvMemClass (inv_mem) /-- `NegMemClass S G` states `S` is a type of subsets `s ⊆ G` closed under negation. -/ class NegMemClass (S G : Type*) [Neg G] [SetLike S G] : Prop where /-- `s` is closed under negation -/ neg_mem : ∀ {s : S} {x}, x ∈ s → -x ∈ s #align neg_mem_class NegMemClass export NegMemClass (neg_mem) /-- `SubgroupClass S G` states `S` is a type of subsets `s ⊆ G` that are subgroups of `G`. -/ class SubgroupClass (S G : Type*) [DivInvMonoid G] [SetLike S G] extends SubmonoidClass S G, InvMemClass S G : Prop #align subgroup_class SubgroupClass /-- `AddSubgroupClass S G` states `S` is a type of subsets `s ⊆ G` that are additive subgroups of `G`. -/ class AddSubgroupClass (S G : Type*) [SubNegMonoid G] [SetLike S G] extends AddSubmonoidClass S G, NegMemClass S G : Prop #align add_subgroup_class AddSubgroupClass attribute [to_additive] InvMemClass SubgroupClass attribute [aesop safe apply (rule_sets := [SetLike])] inv_mem neg_mem @[to_additive (attr := simp)] theorem inv_mem_iff {S G} [InvolutiveInv G] {_ : SetLike S G} [InvMemClass S G] {H : S} {x : G} : x⁻¹ ∈ H ↔ x ∈ H := ⟨fun h => inv_inv x ▸ inv_mem h, inv_mem⟩ #align inv_mem_iff inv_mem_iff #align neg_mem_iff neg_mem_iff @[simp] theorem abs_mem_iff {S G} [AddGroup G] [LinearOrder G] {_ : SetLike S G} [NegMemClass S G] {H : S} {x : G} : |x| ∈ H ↔ x ∈ H := by cases abs_choice x <;> simp [*] variable {M S : Type*} [DivInvMonoid M] [SetLike S M] [hSM : SubgroupClass S M] {H K : S} /-- A subgroup is closed under division. -/ @[to_additive (attr := aesop safe apply (rule_sets := [SetLike])) "An additive subgroup is closed under subtraction."] theorem div_mem {x y : M} (hx : x ∈ H) (hy : y ∈ H) : x / y ∈ H := by rw [div_eq_mul_inv]; exact mul_mem hx (inv_mem hy) #align div_mem div_mem #align sub_mem sub_mem @[to_additive (attr := aesop safe apply (rule_sets := [SetLike]))] theorem zpow_mem {x : M} (hx : x ∈ K) : ∀ n : ℤ, x ^ n ∈ K | (n : ℕ) => by rw [zpow_natCast] exact pow_mem hx n | -[n+1] => by rw [zpow_negSucc] exact inv_mem (pow_mem hx n.succ) #align zpow_mem zpow_mem #align zsmul_mem zsmul_mem variable [SetLike S G] [SubgroupClass S G] @[to_additive] theorem div_mem_comm_iff {a b : G} : a / b ∈ H ↔ b / a ∈ H := inv_div b a ▸ inv_mem_iff #align div_mem_comm_iff div_mem_comm_iff #align sub_mem_comm_iff sub_mem_comm_iff @[to_additive /-(attr := simp)-/] -- Porting note: `simp` cannot simplify LHS theorem exists_inv_mem_iff_exists_mem {P : G → Prop} : (∃ x : G, x ∈ H ∧ P x⁻¹) ↔ ∃ x ∈ H, P x := by constructor <;> · rintro ⟨x, x_in, hx⟩ exact ⟨x⁻¹, inv_mem x_in, by simp [hx]⟩ #align exists_inv_mem_iff_exists_mem exists_inv_mem_iff_exists_mem #align exists_neg_mem_iff_exists_mem exists_neg_mem_iff_exists_mem @[to_additive] theorem mul_mem_cancel_right {x y : G} (h : x ∈ H) : y * x ∈ H ↔ y ∈ H := ⟨fun hba => by simpa using mul_mem hba (inv_mem h), fun hb => mul_mem hb h⟩ #align mul_mem_cancel_right mul_mem_cancel_right #align add_mem_cancel_right add_mem_cancel_right @[to_additive] theorem mul_mem_cancel_left {x y : G} (h : x ∈ H) : x * y ∈ H ↔ y ∈ H := ⟨fun hab => by simpa using mul_mem (inv_mem h) hab, mul_mem h⟩ #align mul_mem_cancel_left mul_mem_cancel_left #align add_mem_cancel_left add_mem_cancel_left namespace InvMemClass /-- A subgroup of a group inherits an inverse. -/ @[to_additive "An additive subgroup of an `AddGroup` inherits an inverse."] instance inv {G : Type u_1} {S : Type u_2} [Inv G] [SetLike S G] [InvMemClass S G] {H : S} : Inv H := ⟨fun a => ⟨a⁻¹, inv_mem a.2⟩⟩ #align subgroup_class.has_inv InvMemClass.inv #align add_subgroup_class.has_neg NegMemClass.neg @[to_additive (attr := simp, norm_cast)] theorem coe_inv (x : H) : (x⁻¹).1 = x.1⁻¹ := rfl #align subgroup_class.coe_inv InvMemClass.coe_inv #align add_subgroup_class.coe_neg NegMemClass.coe_neg end InvMemClass namespace SubgroupClass @[to_additive (attr := deprecated (since := "2024-01-15"))] alias coe_inv := InvMemClass.coe_inv -- Here we assume H, K, and L are subgroups, but in fact any one of them -- could be allowed to be a subsemigroup. -- Counterexample where K and L are submonoids: H = ℤ, K = ℕ, L = -ℕ -- Counterexample where H and K are submonoids: H = {n | n = 0 ∨ 3 ≤ n}, K = 3ℕ + 4ℕ, L = 5ℤ @[to_additive] theorem subset_union {H K L : S} : (H : Set G) ⊆ K ∪ L ↔ H ≤ K ∨ H ≤ L := by refine ⟨fun h ↦ ?_, fun h x xH ↦ h.imp (· xH) (· xH)⟩ rw [or_iff_not_imp_left, SetLike.not_le_iff_exists] exact fun ⟨x, xH, xK⟩ y yH ↦ (h <| mul_mem xH yH).elim ((h yH).resolve_left fun yK ↦ xK <| (mul_mem_cancel_right yK).mp ·) (mul_mem_cancel_left <| (h xH).resolve_left xK).mp /-- A subgroup of a group inherits a division -/ @[to_additive "An additive subgroup of an `AddGroup` inherits a subtraction."] instance div {G : Type u_1} {S : Type u_2} [DivInvMonoid G] [SetLike S G] [SubgroupClass S G] {H : S} : Div H := ⟨fun a b => ⟨a / b, div_mem a.2 b.2⟩⟩ #align subgroup_class.has_div SubgroupClass.div #align add_subgroup_class.has_sub AddSubgroupClass.sub /-- An additive subgroup of an `AddGroup` inherits an integer scaling. -/ instance _root_.AddSubgroupClass.zsmul {M S} [SubNegMonoid M] [SetLike S M] [AddSubgroupClass S M] {H : S} : SMul ℤ H := ⟨fun n a => ⟨n • a.1, zsmul_mem a.2 n⟩⟩ #align add_subgroup_class.has_zsmul AddSubgroupClass.zsmul /-- A subgroup of a group inherits an integer power. -/ @[to_additive existing] instance zpow {M S} [DivInvMonoid M] [SetLike S M] [SubgroupClass S M] {H : S} : Pow H ℤ := ⟨fun a n => ⟨a.1 ^ n, zpow_mem a.2 n⟩⟩ #align subgroup_class.has_zpow SubgroupClass.zpow -- Porting note: additive align statement is given above @[to_additive (attr := simp, norm_cast)] theorem coe_div (x y : H) : (x / y).1 = x.1 / y.1 := rfl #align subgroup_class.coe_div SubgroupClass.coe_div #align add_subgroup_class.coe_sub AddSubgroupClass.coe_sub variable (H) -- Prefer subclasses of `Group` over subclasses of `SubgroupClass`. /-- A subgroup of a group inherits a group structure. -/ @[to_additive "An additive subgroup of an `AddGroup` inherits an `AddGroup` structure."] instance (priority := 75) toGroup : Group H := Subtype.coe_injective.group _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl #align subgroup_class.to_group SubgroupClass.toGroup #align add_subgroup_class.to_add_group AddSubgroupClass.toAddGroup -- Prefer subclasses of `CommGroup` over subclasses of `SubgroupClass`. /-- A subgroup of a `CommGroup` is a `CommGroup`. -/ @[to_additive "An additive subgroup of an `AddCommGroup` is an `AddCommGroup`."] instance (priority := 75) toCommGroup {G : Type*} [CommGroup G] [SetLike S G] [SubgroupClass S G] : CommGroup H := Subtype.coe_injective.commGroup _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl #align subgroup_class.to_comm_group SubgroupClass.toCommGroup #align add_subgroup_class.to_add_comm_group AddSubgroupClass.toAddCommGroup /-- The natural group hom from a subgroup of group `G` to `G`. -/ @[to_additive (attr := coe) "The natural group hom from an additive subgroup of `AddGroup` `G` to `G`."] protected def subtype : H →* G where toFun := ((↑) : H → G); map_one' := rfl; map_mul' := fun _ _ => rfl #align subgroup_class.subtype SubgroupClass.subtype #align add_subgroup_class.subtype AddSubgroupClass.subtype @[to_additive (attr := simp)] theorem coeSubtype : (SubgroupClass.subtype H : H → G) = ((↑) : H → G) := by rfl #align subgroup_class.coe_subtype SubgroupClass.coeSubtype #align add_subgroup_class.coe_subtype AddSubgroupClass.coeSubtype variable {H} @[to_additive (attr := simp, norm_cast)] theorem coe_pow (x : H) (n : ℕ) : ((x ^ n : H) : G) = (x : G) ^ n := rfl #align subgroup_class.coe_pow SubgroupClass.coe_pow #align add_subgroup_class.coe_smul AddSubgroupClass.coe_nsmul @[to_additive (attr := simp, norm_cast)] theorem coe_zpow (x : H) (n : ℤ) : ((x ^ n : H) : G) = (x : G) ^ n := rfl #align subgroup_class.coe_zpow SubgroupClass.coe_zpow #align add_subgroup_class.coe_zsmul AddSubgroupClass.coe_zsmul /-- The inclusion homomorphism from a subgroup `H` contained in `K` to `K`. -/ @[to_additive "The inclusion homomorphism from an additive subgroup `H` contained in `K` to `K`."] def inclusion {H K : S} (h : H ≤ K) : H →* K := MonoidHom.mk' (fun x => ⟨x, h x.prop⟩) fun _ _=> rfl #align subgroup_class.inclusion SubgroupClass.inclusion #align add_subgroup_class.inclusion AddSubgroupClass.inclusion @[to_additive (attr := simp)] theorem inclusion_self (x : H) : inclusion le_rfl x = x := by cases x rfl #align subgroup_class.inclusion_self SubgroupClass.inclusion_self #align add_subgroup_class.inclusion_self AddSubgroupClass.inclusion_self @[to_additive (attr := simp)] theorem inclusion_mk {h : H ≤ K} (x : G) (hx : x ∈ H) : inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ := rfl #align subgroup_class.inclusion_mk SubgroupClass.inclusion_mk #align add_subgroup_class.inclusion_mk AddSubgroupClass.inclusion_mk @[to_additive] theorem inclusion_right (h : H ≤ K) (x : K) (hx : (x : G) ∈ H) : inclusion h ⟨x, hx⟩ = x := by cases x rfl #align subgroup_class.inclusion_right SubgroupClass.inclusion_right #align add_subgroup_class.inclusion_right AddSubgroupClass.inclusion_right @[simp] theorem inclusion_inclusion {L : S} (hHK : H ≤ K) (hKL : K ≤ L) (x : H) : inclusion hKL (inclusion hHK x) = inclusion (hHK.trans hKL) x := by cases x rfl #align subgroup_class.inclusion_inclusion SubgroupClass.inclusion_inclusion @[to_additive (attr := simp)] theorem coe_inclusion {H K : S} {h : H ≤ K} (a : H) : (inclusion h a : G) = a := by cases a simp only [inclusion, MonoidHom.mk'_apply] #align subgroup_class.coe_inclusion SubgroupClass.coe_inclusion #align add_subgroup_class.coe_inclusion AddSubgroupClass.coe_inclusion @[to_additive (attr := simp)] theorem subtype_comp_inclusion {H K : S} (hH : H ≤ K) : (SubgroupClass.subtype K).comp (inclusion hH) = SubgroupClass.subtype H := by ext simp only [MonoidHom.comp_apply, coeSubtype, coe_inclusion] #align subgroup_class.subtype_comp_inclusion SubgroupClass.subtype_comp_inclusion #align add_subgroup_class.subtype_comp_inclusion AddSubgroupClass.subtype_comp_inclusion end SubgroupClass end SubgroupClass /-- A subgroup of a group `G` is a subset containing 1, closed under multiplication and closed under multiplicative inverse. -/ structure Subgroup (G : Type*) [Group G] extends Submonoid G where /-- `G` is closed under inverses -/ inv_mem' {x} : x ∈ carrier → x⁻¹ ∈ carrier #align subgroup Subgroup /-- An additive subgroup of an additive group `G` is a subset containing 0, closed under addition and additive inverse. -/ structure AddSubgroup (G : Type*) [AddGroup G] extends AddSubmonoid G where /-- `G` is closed under negation -/ neg_mem' {x} : x ∈ carrier → -x ∈ carrier #align add_subgroup AddSubgroup attribute [to_additive] Subgroup -- Porting note: Removed, translation already exists -- attribute [to_additive AddSubgroup.toAddSubmonoid] Subgroup.toSubmonoid /-- Reinterpret a `Subgroup` as a `Submonoid`. -/ add_decl_doc Subgroup.toSubmonoid #align subgroup.to_submonoid Subgroup.toSubmonoid /-- Reinterpret an `AddSubgroup` as an `AddSubmonoid`. -/ add_decl_doc AddSubgroup.toAddSubmonoid #align add_subgroup.to_add_submonoid AddSubgroup.toAddSubmonoid namespace Subgroup @[to_additive] instance : SetLike (Subgroup G) G where coe s := s.carrier coe_injective' p q h := by obtain ⟨⟨⟨hp,_⟩,_⟩,_⟩ := p obtain ⟨⟨⟨hq,_⟩,_⟩,_⟩ := q congr -- Porting note: Below can probably be written more uniformly @[to_additive] instance : SubgroupClass (Subgroup G) G where inv_mem := Subgroup.inv_mem' _ one_mem _ := (Subgroup.toSubmonoid _).one_mem' mul_mem := (Subgroup.toSubmonoid _).mul_mem' @[to_additive (attr := simp, nolint simpNF)] -- Porting note (#10675): dsimp can not prove this theorem mem_carrier {s : Subgroup G} {x : G} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl #align subgroup.mem_carrier Subgroup.mem_carrier #align add_subgroup.mem_carrier AddSubgroup.mem_carrier @[to_additive (attr := simp)] theorem mem_mk {s : Set G} {x : G} (h_one) (h_mul) (h_inv) : x ∈ mk ⟨⟨s, h_one⟩, h_mul⟩ h_inv ↔ x ∈ s := Iff.rfl #align subgroup.mem_mk Subgroup.mem_mk #align add_subgroup.mem_mk AddSubgroup.mem_mk @[to_additive (attr := simp, norm_cast)] theorem coe_set_mk {s : Set G} (h_one) (h_mul) (h_inv) : (mk ⟨⟨s, h_one⟩, h_mul⟩ h_inv : Set G) = s := rfl #align subgroup.coe_set_mk Subgroup.coe_set_mk #align add_subgroup.coe_set_mk AddSubgroup.coe_set_mk @[to_additive (attr := simp)] theorem mk_le_mk {s t : Set G} (h_one) (h_mul) (h_inv) (h_one') (h_mul') (h_inv') : mk ⟨⟨s, h_one⟩, h_mul⟩ h_inv ≤ mk ⟨⟨t, h_one'⟩, h_mul'⟩ h_inv' ↔ s ⊆ t := Iff.rfl #align subgroup.mk_le_mk Subgroup.mk_le_mk #align add_subgroup.mk_le_mk AddSubgroup.mk_le_mk initialize_simps_projections Subgroup (carrier → coe) initialize_simps_projections AddSubgroup (carrier → coe) @[to_additive (attr := simp)] theorem coe_toSubmonoid (K : Subgroup G) : (K.toSubmonoid : Set G) = K := rfl #align subgroup.coe_to_submonoid Subgroup.coe_toSubmonoid #align add_subgroup.coe_to_add_submonoid AddSubgroup.coe_toAddSubmonoid @[to_additive (attr := simp)] theorem mem_toSubmonoid (K : Subgroup G) (x : G) : x ∈ K.toSubmonoid ↔ x ∈ K := Iff.rfl #align subgroup.mem_to_submonoid Subgroup.mem_toSubmonoid #align add_subgroup.mem_to_add_submonoid AddSubgroup.mem_toAddSubmonoid @[to_additive] theorem toSubmonoid_injective : Function.Injective (toSubmonoid : Subgroup G → Submonoid G) := -- fun p q h => SetLike.ext'_iff.2 (show _ from SetLike.ext'_iff.1 h) fun p q h => by have := SetLike.ext'_iff.1 h rw [coe_toSubmonoid, coe_toSubmonoid] at this exact SetLike.ext'_iff.2 this #align subgroup.to_submonoid_injective Subgroup.toSubmonoid_injective #align add_subgroup.to_add_submonoid_injective AddSubgroup.toAddSubmonoid_injective @[to_additive (attr := simp)] theorem toSubmonoid_eq {p q : Subgroup G} : p.toSubmonoid = q.toSubmonoid ↔ p = q := toSubmonoid_injective.eq_iff #align subgroup.to_submonoid_eq Subgroup.toSubmonoid_eq #align add_subgroup.to_add_submonoid_eq AddSubgroup.toAddSubmonoid_eq @[to_additive (attr := mono)] theorem toSubmonoid_strictMono : StrictMono (toSubmonoid : Subgroup G → Submonoid G) := fun _ _ => id #align subgroup.to_submonoid_strict_mono Subgroup.toSubmonoid_strictMono #align add_subgroup.to_add_submonoid_strict_mono AddSubgroup.toAddSubmonoid_strictMono @[to_additive (attr := mono)] theorem toSubmonoid_mono : Monotone (toSubmonoid : Subgroup G → Submonoid G) := toSubmonoid_strictMono.monotone #align subgroup.to_submonoid_mono Subgroup.toSubmonoid_mono #align add_subgroup.to_add_submonoid_mono AddSubgroup.toAddSubmonoid_mono @[to_additive (attr := simp)] theorem toSubmonoid_le {p q : Subgroup G} : p.toSubmonoid ≤ q.toSubmonoid ↔ p ≤ q := Iff.rfl #align subgroup.to_submonoid_le Subgroup.toSubmonoid_le #align add_subgroup.to_add_submonoid_le AddSubgroup.toAddSubmonoid_le @[to_additive (attr := simp)] lemma coe_nonempty (s : Subgroup G) : (s : Set G).Nonempty := ⟨1, one_mem _⟩ end Subgroup /-! ### Conversion to/from `Additive`/`Multiplicative` -/ section mul_add /-- Subgroups of a group `G` are isomorphic to additive subgroups of `Additive G`. -/ @[simps!] def Subgroup.toAddSubgroup : Subgroup G ≃o AddSubgroup (Additive G) where toFun S := { Submonoid.toAddSubmonoid S.toSubmonoid with neg_mem' := S.inv_mem' } invFun S := { AddSubmonoid.toSubmonoid S.toAddSubmonoid with inv_mem' := S.neg_mem' } left_inv x := by cases x; rfl right_inv x := by cases x; rfl map_rel_iff' := Iff.rfl #align subgroup.to_add_subgroup Subgroup.toAddSubgroup #align subgroup.to_add_subgroup_symm_apply_coe Subgroup.toAddSubgroup_symm_apply_coe #align subgroup.to_add_subgroup_apply_coe Subgroup.toAddSubgroup_apply_coe /-- Additive subgroup of an additive group `Additive G` are isomorphic to subgroup of `G`. -/ abbrev AddSubgroup.toSubgroup' : AddSubgroup (Additive G) ≃o Subgroup G := Subgroup.toAddSubgroup.symm #align add_subgroup.to_subgroup' AddSubgroup.toSubgroup' /-- Additive subgroups of an additive group `A` are isomorphic to subgroups of `Multiplicative A`. -/ @[simps!] def AddSubgroup.toSubgroup : AddSubgroup A ≃o Subgroup (Multiplicative A) where toFun S := { AddSubmonoid.toSubmonoid S.toAddSubmonoid with inv_mem' := S.neg_mem' } invFun S := { Submonoid.toAddSubmonoid S.toSubmonoid with neg_mem' := S.inv_mem' } left_inv x := by cases x; rfl right_inv x := by cases x; rfl map_rel_iff' := Iff.rfl #align add_subgroup.to_subgroup AddSubgroup.toSubgroup #align add_subgroup.to_subgroup_apply_coe AddSubgroup.toSubgroup_apply_coe #align add_subgroup.to_subgroup_symm_apply_coe AddSubgroup.toSubgroup_symm_apply_coe /-- Subgroups of an additive group `Multiplicative A` are isomorphic to additive subgroups of `A`. -/ abbrev Subgroup.toAddSubgroup' : Subgroup (Multiplicative A) ≃o AddSubgroup A := AddSubgroup.toSubgroup.symm #align subgroup.to_add_subgroup' Subgroup.toAddSubgroup' end mul_add namespace Subgroup variable (H K : Subgroup G) /-- Copy of a subgroup with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ @[to_additive "Copy of an additive subgroup with a new `carrier` equal to the old one. Useful to fix definitional equalities"] protected def copy (K : Subgroup G) (s : Set G) (hs : s = K) : Subgroup G where carrier := s one_mem' := hs.symm ▸ K.one_mem' mul_mem' := hs.symm ▸ K.mul_mem' inv_mem' hx := by simpa [hs] using hx -- Porting note: `▸` didn't work here #align subgroup.copy Subgroup.copy #align add_subgroup.copy AddSubgroup.copy @[to_additive (attr := simp)] theorem coe_copy (K : Subgroup G) (s : Set G) (hs : s = ↑K) : (K.copy s hs : Set G) = s := rfl #align subgroup.coe_copy Subgroup.coe_copy #align add_subgroup.coe_copy AddSubgroup.coe_copy @[to_additive] theorem copy_eq (K : Subgroup G) (s : Set G) (hs : s = ↑K) : K.copy s hs = K := SetLike.coe_injective hs #align subgroup.copy_eq Subgroup.copy_eq #align add_subgroup.copy_eq AddSubgroup.copy_eq /-- Two subgroups are equal if they have the same elements. -/ @[to_additive (attr := ext) "Two `AddSubgroup`s are equal if they have the same elements."] theorem ext {H K : Subgroup G} (h : ∀ x, x ∈ H ↔ x ∈ K) : H = K := SetLike.ext h #align subgroup.ext Subgroup.ext #align add_subgroup.ext AddSubgroup.ext /-- A subgroup contains the group's 1. -/ @[to_additive "An `AddSubgroup` contains the group's 0."] protected theorem one_mem : (1 : G) ∈ H := one_mem _ #align subgroup.one_mem Subgroup.one_mem #align add_subgroup.zero_mem AddSubgroup.zero_mem /-- A subgroup is closed under multiplication. -/ @[to_additive "An `AddSubgroup` is closed under addition."] protected theorem mul_mem {x y : G} : x ∈ H → y ∈ H → x * y ∈ H := mul_mem #align subgroup.mul_mem Subgroup.mul_mem #align add_subgroup.add_mem AddSubgroup.add_mem /-- A subgroup is closed under inverse. -/ @[to_additive "An `AddSubgroup` is closed under inverse."] protected theorem inv_mem {x : G} : x ∈ H → x⁻¹ ∈ H := inv_mem #align subgroup.inv_mem Subgroup.inv_mem #align add_subgroup.neg_mem AddSubgroup.neg_mem /-- A subgroup is closed under division. -/ @[to_additive "An `AddSubgroup` is closed under subtraction."] protected theorem div_mem {x y : G} (hx : x ∈ H) (hy : y ∈ H) : x / y ∈ H := div_mem hx hy #align subgroup.div_mem Subgroup.div_mem #align add_subgroup.sub_mem AddSubgroup.sub_mem @[to_additive] protected theorem inv_mem_iff {x : G} : x⁻¹ ∈ H ↔ x ∈ H := inv_mem_iff #align subgroup.inv_mem_iff Subgroup.inv_mem_iff #align add_subgroup.neg_mem_iff AddSubgroup.neg_mem_iff @[to_additive] protected theorem div_mem_comm_iff {a b : G} : a / b ∈ H ↔ b / a ∈ H := div_mem_comm_iff #align subgroup.div_mem_comm_iff Subgroup.div_mem_comm_iff #align add_subgroup.sub_mem_comm_iff AddSubgroup.sub_mem_comm_iff @[to_additive] protected theorem exists_inv_mem_iff_exists_mem (K : Subgroup G) {P : G → Prop} : (∃ x : G, x ∈ K ∧ P x⁻¹) ↔ ∃ x ∈ K, P x := exists_inv_mem_iff_exists_mem #align subgroup.exists_inv_mem_iff_exists_mem Subgroup.exists_inv_mem_iff_exists_mem #align add_subgroup.exists_neg_mem_iff_exists_mem AddSubgroup.exists_neg_mem_iff_exists_mem @[to_additive] protected theorem mul_mem_cancel_right {x y : G} (h : x ∈ H) : y * x ∈ H ↔ y ∈ H := mul_mem_cancel_right h #align subgroup.mul_mem_cancel_right Subgroup.mul_mem_cancel_right #align add_subgroup.add_mem_cancel_right AddSubgroup.add_mem_cancel_right @[to_additive] protected theorem mul_mem_cancel_left {x y : G} (h : x ∈ H) : x * y ∈ H ↔ y ∈ H := mul_mem_cancel_left h #align subgroup.mul_mem_cancel_left Subgroup.mul_mem_cancel_left #align add_subgroup.add_mem_cancel_left AddSubgroup.add_mem_cancel_left @[to_additive] protected theorem pow_mem {x : G} (hx : x ∈ K) : ∀ n : ℕ, x ^ n ∈ K := pow_mem hx #align subgroup.pow_mem Subgroup.pow_mem #align add_subgroup.nsmul_mem AddSubgroup.nsmul_mem @[to_additive] protected theorem zpow_mem {x : G} (hx : x ∈ K) : ∀ n : ℤ, x ^ n ∈ K := zpow_mem hx #align subgroup.zpow_mem Subgroup.zpow_mem #align add_subgroup.zsmul_mem AddSubgroup.zsmul_mem /-- Construct a subgroup from a nonempty set that is closed under division. -/ @[to_additive "Construct a subgroup from a nonempty set that is closed under subtraction"] def ofDiv (s : Set G) (hsn : s.Nonempty) (hs : ∀ᵉ (x ∈ s) (y ∈ s), x * y⁻¹ ∈ s) : Subgroup G := have one_mem : (1 : G) ∈ s := by let ⟨x, hx⟩ := hsn simpa using hs x hx x hx have inv_mem : ∀ x, x ∈ s → x⁻¹ ∈ s := fun x hx => by simpa using hs 1 one_mem x hx { carrier := s one_mem' := one_mem inv_mem' := inv_mem _ mul_mem' := fun hx hy => by simpa using hs _ hx _ (inv_mem _ hy) } #align subgroup.of_div Subgroup.ofDiv #align add_subgroup.of_sub AddSubgroup.ofSub /-- A subgroup of a group inherits a multiplication. -/ @[to_additive "An `AddSubgroup` of an `AddGroup` inherits an addition."] instance mul : Mul H := H.toSubmonoid.mul #align subgroup.has_mul Subgroup.mul #align add_subgroup.has_add AddSubgroup.add /-- A subgroup of a group inherits a 1. -/ @[to_additive "An `AddSubgroup` of an `AddGroup` inherits a zero."] instance one : One H := H.toSubmonoid.one #align subgroup.has_one Subgroup.one #align add_subgroup.has_zero AddSubgroup.zero /-- A subgroup of a group inherits an inverse. -/ @[to_additive "An `AddSubgroup` of an `AddGroup` inherits an inverse."] instance inv : Inv H := ⟨fun a => ⟨a⁻¹, H.inv_mem a.2⟩⟩ #align subgroup.has_inv Subgroup.inv #align add_subgroup.has_neg AddSubgroup.neg /-- A subgroup of a group inherits a division -/ @[to_additive "An `AddSubgroup` of an `AddGroup` inherits a subtraction."] instance div : Div H := ⟨fun a b => ⟨a / b, H.div_mem a.2 b.2⟩⟩ #align subgroup.has_div Subgroup.div #align add_subgroup.has_sub AddSubgroup.sub /-- An `AddSubgroup` of an `AddGroup` inherits a natural scaling. -/ instance _root_.AddSubgroup.nsmul {G} [AddGroup G] {H : AddSubgroup G} : SMul ℕ H := ⟨fun n a => ⟨n • a, H.nsmul_mem a.2 n⟩⟩ #align add_subgroup.has_nsmul AddSubgroup.nsmul /-- A subgroup of a group inherits a natural power -/ @[to_additive existing] protected instance npow : Pow H ℕ := ⟨fun a n => ⟨a ^ n, H.pow_mem a.2 n⟩⟩ #align subgroup.has_npow Subgroup.npow /-- An `AddSubgroup` of an `AddGroup` inherits an integer scaling. -/ instance _root_.AddSubgroup.zsmul {G} [AddGroup G] {H : AddSubgroup G} : SMul ℤ H := ⟨fun n a => ⟨n • a, H.zsmul_mem a.2 n⟩⟩ #align add_subgroup.has_zsmul AddSubgroup.zsmul /-- A subgroup of a group inherits an integer power -/ @[to_additive existing] instance zpow : Pow H ℤ := ⟨fun a n => ⟨a ^ n, H.zpow_mem a.2 n⟩⟩ #align subgroup.has_zpow Subgroup.zpow @[to_additive (attr := simp, norm_cast)] theorem coe_mul (x y : H) : (↑(x * y) : G) = ↑x * ↑y := rfl #align subgroup.coe_mul Subgroup.coe_mul #align add_subgroup.coe_add AddSubgroup.coe_add @[to_additive (attr := simp, norm_cast)] theorem coe_one : ((1 : H) : G) = 1 := rfl #align subgroup.coe_one Subgroup.coe_one #align add_subgroup.coe_zero AddSubgroup.coe_zero @[to_additive (attr := simp, norm_cast)] theorem coe_inv (x : H) : ↑(x⁻¹ : H) = (x⁻¹ : G) := rfl #align subgroup.coe_inv Subgroup.coe_inv #align add_subgroup.coe_neg AddSubgroup.coe_neg @[to_additive (attr := simp, norm_cast)] theorem coe_div (x y : H) : (↑(x / y) : G) = ↑x / ↑y := rfl #align subgroup.coe_div Subgroup.coe_div #align add_subgroup.coe_sub AddSubgroup.coe_sub -- Porting note: removed simp, theorem has variable as head symbol @[to_additive (attr := norm_cast)] theorem coe_mk (x : G) (hx : x ∈ H) : ((⟨x, hx⟩ : H) : G) = x := rfl #align subgroup.coe_mk Subgroup.coe_mk #align add_subgroup.coe_mk AddSubgroup.coe_mk @[to_additive (attr := simp, norm_cast)] theorem coe_pow (x : H) (n : ℕ) : ((x ^ n : H) : G) = (x : G) ^ n := rfl #align subgroup.coe_pow Subgroup.coe_pow #align add_subgroup.coe_nsmul AddSubgroup.coe_nsmul @[to_additive (attr := norm_cast)] -- Porting note (#10685): dsimp can prove this theorem coe_zpow (x : H) (n : ℤ) : ((x ^ n : H) : G) = (x : G) ^ n := rfl #align subgroup.coe_zpow Subgroup.coe_zpow #align add_subgroup.coe_zsmul AddSubgroup.coe_zsmul @[to_additive] -- This can be proved by `Submonoid.mk_eq_one` theorem mk_eq_one {g : G} {h} : (⟨g, h⟩ : H) = 1 ↔ g = 1 := by simp #align subgroup.mk_eq_one_iff Subgroup.mk_eq_one #align add_subgroup.mk_eq_zero_iff AddSubgroup.mk_eq_zero /-- A subgroup of a group inherits a group structure. -/ @[to_additive "An `AddSubgroup` of an `AddGroup` inherits an `AddGroup` structure."] instance toGroup {G : Type*} [Group G] (H : Subgroup G) : Group H := Subtype.coe_injective.group _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl #align subgroup.to_group Subgroup.toGroup #align add_subgroup.to_add_group AddSubgroup.toAddGroup /-- A subgroup of a `CommGroup` is a `CommGroup`. -/ @[to_additive "An `AddSubgroup` of an `AddCommGroup` is an `AddCommGroup`."] instance toCommGroup {G : Type*} [CommGroup G] (H : Subgroup G) : CommGroup H := Subtype.coe_injective.commGroup _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl #align subgroup.to_comm_group Subgroup.toCommGroup #align add_subgroup.to_add_comm_group AddSubgroup.toAddCommGroup /-- The natural group hom from a subgroup of group `G` to `G`. -/ @[to_additive "The natural group hom from an `AddSubgroup` of `AddGroup` `G` to `G`."] protected def subtype : H →* G where toFun := ((↑) : H → G); map_one' := rfl; map_mul' _ _ := rfl #align subgroup.subtype Subgroup.subtype #align add_subgroup.subtype AddSubgroup.subtype @[to_additive (attr := simp)] theorem coeSubtype : ⇑ H.subtype = ((↑) : H → G) := rfl #align subgroup.coe_subtype Subgroup.coeSubtype #align add_subgroup.coe_subtype AddSubgroup.coeSubtype @[to_additive] theorem subtype_injective : Function.Injective (Subgroup.subtype H) := Subtype.coe_injective #align subgroup.subtype_injective Subgroup.subtype_injective #align add_subgroup.subtype_injective AddSubgroup.subtype_injective /-- The inclusion homomorphism from a subgroup `H` contained in `K` to `K`. -/ @[to_additive "The inclusion homomorphism from an additive subgroup `H` contained in `K` to `K`."] def inclusion {H K : Subgroup G} (h : H ≤ K) : H →* K := MonoidHom.mk' (fun x => ⟨x, h x.2⟩) fun _ _ => rfl #align subgroup.inclusion Subgroup.inclusion #align add_subgroup.inclusion AddSubgroup.inclusion @[to_additive (attr := simp)] theorem coe_inclusion {H K : Subgroup G} {h : H ≤ K} (a : H) : (inclusion h a : G) = a := by cases a simp only [inclusion, coe_mk, MonoidHom.mk'_apply] #align subgroup.coe_inclusion Subgroup.coe_inclusion #align add_subgroup.coe_inclusion AddSubgroup.coe_inclusion @[to_additive] theorem inclusion_injective {H K : Subgroup G} (h : H ≤ K) : Function.Injective <| inclusion h := Set.inclusion_injective h #align subgroup.inclusion_injective Subgroup.inclusion_injective #align add_subgroup.inclusion_injective AddSubgroup.inclusion_injective @[to_additive (attr := simp)] theorem subtype_comp_inclusion {H K : Subgroup G} (hH : H ≤ K) : K.subtype.comp (inclusion hH) = H.subtype := rfl #align subgroup.subtype_comp_inclusion Subgroup.subtype_comp_inclusion #align add_subgroup.subtype_comp_inclusion AddSubgroup.subtype_comp_inclusion /-- The subgroup `G` of the group `G`. -/ @[to_additive "The `AddSubgroup G` of the `AddGroup G`."] instance : Top (Subgroup G) := ⟨{ (⊤ : Submonoid G) with inv_mem' := fun _ => Set.mem_univ _ }⟩ /-- The top subgroup is isomorphic to the group. This is the group version of `Submonoid.topEquiv`. -/ @[to_additive (attr := simps!) "The top additive subgroup is isomorphic to the additive group. This is the additive group version of `AddSubmonoid.topEquiv`."] def topEquiv : (⊤ : Subgroup G) ≃* G := Submonoid.topEquiv #align subgroup.top_equiv Subgroup.topEquiv #align add_subgroup.top_equiv AddSubgroup.topEquiv #align subgroup.top_equiv_symm_apply_coe Subgroup.topEquiv_symm_apply_coe #align add_subgroup.top_equiv_symm_apply_coe AddSubgroup.topEquiv_symm_apply_coe #align add_subgroup.top_equiv_apply AddSubgroup.topEquiv_apply /-- The trivial subgroup `{1}` of a group `G`. -/ @[to_additive "The trivial `AddSubgroup` `{0}` of an `AddGroup` `G`."] instance : Bot (Subgroup G) := ⟨{ (⊥ : Submonoid G) with inv_mem' := by simp}⟩ @[to_additive] instance : Inhabited (Subgroup G) := ⟨⊥⟩ @[to_additive (attr := simp)] theorem mem_bot {x : G} : x ∈ (⊥ : Subgroup G) ↔ x = 1 := Iff.rfl #align subgroup.mem_bot Subgroup.mem_bot #align add_subgroup.mem_bot AddSubgroup.mem_bot @[to_additive (attr := simp)] theorem mem_top (x : G) : x ∈ (⊤ : Subgroup G) := Set.mem_univ x #align subgroup.mem_top Subgroup.mem_top #align add_subgroup.mem_top AddSubgroup.mem_top @[to_additive (attr := simp)] theorem coe_top : ((⊤ : Subgroup G) : Set G) = Set.univ := rfl #align subgroup.coe_top Subgroup.coe_top #align add_subgroup.coe_top AddSubgroup.coe_top @[to_additive (attr := simp)] theorem coe_bot : ((⊥ : Subgroup G) : Set G) = {1} := rfl #align subgroup.coe_bot Subgroup.coe_bot #align add_subgroup.coe_bot AddSubgroup.coe_bot @[to_additive] instance : Unique (⊥ : Subgroup G) := ⟨⟨1⟩, fun g => Subtype.ext g.2⟩ @[to_additive (attr := simp)] theorem top_toSubmonoid : (⊤ : Subgroup G).toSubmonoid = ⊤ := rfl #align subgroup.top_to_submonoid Subgroup.top_toSubmonoid #align add_subgroup.top_to_add_submonoid AddSubgroup.top_toAddSubmonoid @[to_additive (attr := simp)] theorem bot_toSubmonoid : (⊥ : Subgroup G).toSubmonoid = ⊥ := rfl #align subgroup.bot_to_submonoid Subgroup.bot_toSubmonoid #align add_subgroup.bot_to_add_submonoid AddSubgroup.bot_toAddSubmonoid @[to_additive] theorem eq_bot_iff_forall : H = ⊥ ↔ ∀ x ∈ H, x = (1 : G) := toSubmonoid_injective.eq_iff.symm.trans <| Submonoid.eq_bot_iff_forall _ #align subgroup.eq_bot_iff_forall Subgroup.eq_bot_iff_forall #align add_subgroup.eq_bot_iff_forall AddSubgroup.eq_bot_iff_forall @[to_additive] theorem eq_bot_of_subsingleton [Subsingleton H] : H = ⊥ := by rw [Subgroup.eq_bot_iff_forall] intro y hy rw [← Subgroup.coe_mk H y hy, Subsingleton.elim (⟨y, hy⟩ : H) 1, Subgroup.coe_one] #align subgroup.eq_bot_of_subsingleton Subgroup.eq_bot_of_subsingleton #align add_subgroup.eq_bot_of_subsingleton AddSubgroup.eq_bot_of_subsingleton @[to_additive (attr := simp, norm_cast)] theorem coe_eq_univ {H : Subgroup G} : (H : Set G) = Set.univ ↔ H = ⊤ := (SetLike.ext'_iff.trans (by rfl)).symm #align subgroup.coe_eq_univ Subgroup.coe_eq_univ #align add_subgroup.coe_eq_univ AddSubgroup.coe_eq_univ @[to_additive] theorem coe_eq_singleton {H : Subgroup G} : (∃ g : G, (H : Set G) = {g}) ↔ H = ⊥ := ⟨fun ⟨g, hg⟩ => haveI : Subsingleton (H : Set G) := by rw [hg] infer_instance H.eq_bot_of_subsingleton, fun h => ⟨1, SetLike.ext'_iff.mp h⟩⟩ #align subgroup.coe_eq_singleton Subgroup.coe_eq_singleton #align add_subgroup.coe_eq_singleton AddSubgroup.coe_eq_singleton @[to_additive] theorem nontrivial_iff_exists_ne_one (H : Subgroup G) : Nontrivial H ↔ ∃ x ∈ H, x ≠ (1 : G) := by rw [Subtype.nontrivial_iff_exists_ne (fun x => x ∈ H) (1 : H)] simp #align subgroup.nontrivial_iff_exists_ne_one Subgroup.nontrivial_iff_exists_ne_one #align add_subgroup.nontrivial_iff_exists_ne_zero AddSubgroup.nontrivial_iff_exists_ne_zero @[to_additive] theorem exists_ne_one_of_nontrivial (H : Subgroup G) [Nontrivial H] : ∃ x ∈ H, x ≠ 1 := by rwa [← Subgroup.nontrivial_iff_exists_ne_one] @[to_additive] theorem nontrivial_iff_ne_bot (H : Subgroup G) : Nontrivial H ↔ H ≠ ⊥ := by rw [nontrivial_iff_exists_ne_one, ne_eq, eq_bot_iff_forall] simp only [ne_eq, not_forall, exists_prop] /-- A subgroup is either the trivial subgroup or nontrivial. -/ @[to_additive "A subgroup is either the trivial subgroup or nontrivial."] theorem bot_or_nontrivial (H : Subgroup G) : H = ⊥ ∨ Nontrivial H := by have := nontrivial_iff_ne_bot H tauto #align subgroup.bot_or_nontrivial Subgroup.bot_or_nontrivial #align add_subgroup.bot_or_nontrivial AddSubgroup.bot_or_nontrivial /-- A subgroup is either the trivial subgroup or contains a non-identity element. -/ @[to_additive "A subgroup is either the trivial subgroup or contains a nonzero element."] theorem bot_or_exists_ne_one (H : Subgroup G) : H = ⊥ ∨ ∃ x ∈ H, x ≠ (1 : G) := by convert H.bot_or_nontrivial rw [nontrivial_iff_exists_ne_one] #align subgroup.bot_or_exists_ne_one Subgroup.bot_or_exists_ne_one #align add_subgroup.bot_or_exists_ne_zero AddSubgroup.bot_or_exists_ne_zero @[to_additive] lemma ne_bot_iff_exists_ne_one {H : Subgroup G} : H ≠ ⊥ ↔ ∃ a : ↥H, a ≠ 1 := by rw [← nontrivial_iff_ne_bot, nontrivial_iff_exists_ne_one] simp only [ne_eq, Subtype.exists, mk_eq_one, exists_prop] /-- The inf of two subgroups is their intersection. -/ @[to_additive "The inf of two `AddSubgroup`s is their intersection."] instance : Inf (Subgroup G) := ⟨fun H₁ H₂ => { H₁.toSubmonoid ⊓ H₂.toSubmonoid with inv_mem' := fun ⟨hx, hx'⟩ => ⟨H₁.inv_mem hx, H₂.inv_mem hx'⟩ }⟩ @[to_additive (attr := simp)] theorem coe_inf (p p' : Subgroup G) : ((p ⊓ p' : Subgroup G) : Set G) = (p : Set G) ∩ p' := rfl #align subgroup.coe_inf Subgroup.coe_inf #align add_subgroup.coe_inf AddSubgroup.coe_inf @[to_additive (attr := simp)] theorem mem_inf {p p' : Subgroup G} {x : G} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' := Iff.rfl #align subgroup.mem_inf Subgroup.mem_inf #align add_subgroup.mem_inf AddSubgroup.mem_inf @[to_additive] instance : InfSet (Subgroup G) := ⟨fun s => { (⨅ S ∈ s, Subgroup.toSubmonoid S).copy (⋂ S ∈ s, ↑S) (by simp) with inv_mem' := fun {x} hx => Set.mem_biInter fun i h => i.inv_mem (by apply Set.mem_iInter₂.1 hx i h) }⟩ @[to_additive (attr := simp, norm_cast)] theorem coe_sInf (H : Set (Subgroup G)) : ((sInf H : Subgroup G) : Set G) = ⋂ s ∈ H, ↑s := rfl #align subgroup.coe_Inf Subgroup.coe_sInf #align add_subgroup.coe_Inf AddSubgroup.coe_sInf @[to_additive (attr := simp)] theorem mem_sInf {S : Set (Subgroup G)} {x : G} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := Set.mem_iInter₂ #align subgroup.mem_Inf Subgroup.mem_sInf #align add_subgroup.mem_Inf AddSubgroup.mem_sInf @[to_additive] theorem mem_iInf {ι : Sort*} {S : ι → Subgroup G} {x : G} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by simp only [iInf, mem_sInf, Set.forall_mem_range] #align subgroup.mem_infi Subgroup.mem_iInf #align add_subgroup.mem_infi AddSubgroup.mem_iInf @[to_additive (attr := simp, norm_cast)] theorem coe_iInf {ι : Sort*} {S : ι → Subgroup G} : (↑(⨅ i, S i) : Set G) = ⋂ i, S i := by simp only [iInf, coe_sInf, Set.biInter_range] #align subgroup.coe_infi Subgroup.coe_iInf #align add_subgroup.coe_infi AddSubgroup.coe_iInf /-- Subgroups of a group form a complete lattice. -/ @[to_additive "The `AddSubgroup`s of an `AddGroup` form a complete lattice."] instance : CompleteLattice (Subgroup G) := { completeLatticeOfInf (Subgroup G) fun _s => IsGLB.of_image SetLike.coe_subset_coe isGLB_biInf with bot := ⊥ bot_le := fun S _x hx => (mem_bot.1 hx).symm ▸ S.one_mem top := ⊤ le_top := fun _S x _hx => mem_top x inf := (· ⊓ ·) le_inf := fun _a _b _c ha hb _x hx => ⟨ha hx, hb hx⟩ inf_le_left := fun _a _b _x => And.left inf_le_right := fun _a _b _x => And.right } @[to_additive] theorem mem_sup_left {S T : Subgroup G} : ∀ {x : G}, x ∈ S → x ∈ S ⊔ T := have : S ≤ S ⊔ T := le_sup_left; fun h ↦ this h #align subgroup.mem_sup_left Subgroup.mem_sup_left #align add_subgroup.mem_sup_left AddSubgroup.mem_sup_left @[to_additive] theorem mem_sup_right {S T : Subgroup G} : ∀ {x : G}, x ∈ T → x ∈ S ⊔ T := have : T ≤ S ⊔ T := le_sup_right; fun h ↦ this h #align subgroup.mem_sup_right Subgroup.mem_sup_right #align add_subgroup.mem_sup_right AddSubgroup.mem_sup_right @[to_additive] theorem mul_mem_sup {S T : Subgroup G} {x y : G} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T := (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy) #align subgroup.mul_mem_sup Subgroup.mul_mem_sup #align add_subgroup.add_mem_sup AddSubgroup.add_mem_sup @[to_additive] theorem mem_iSup_of_mem {ι : Sort*} {S : ι → Subgroup G} (i : ι) : ∀ {x : G}, x ∈ S i → x ∈ iSup S := have : S i ≤ iSup S := le_iSup _ _; fun h ↦ this h #align subgroup.mem_supr_of_mem Subgroup.mem_iSup_of_mem #align add_subgroup.mem_supr_of_mem AddSubgroup.mem_iSup_of_mem @[to_additive] theorem mem_sSup_of_mem {S : Set (Subgroup G)} {s : Subgroup G} (hs : s ∈ S) : ∀ {x : G}, x ∈ s → x ∈ sSup S := have : s ≤ sSup S := le_sSup hs; fun h ↦ this h #align subgroup.mem_Sup_of_mem Subgroup.mem_sSup_of_mem #align add_subgroup.mem_Sup_of_mem AddSubgroup.mem_sSup_of_mem @[to_additive (attr := simp)] theorem subsingleton_iff : Subsingleton (Subgroup G) ↔ Subsingleton G := ⟨fun h => ⟨fun x y => have : ∀ i : G, i = 1 := fun i => mem_bot.mp <| Subsingleton.elim (⊤ : Subgroup G) ⊥ ▸ mem_top i (this x).trans (this y).symm⟩, fun h => ⟨fun x y => Subgroup.ext fun i => Subsingleton.elim 1 i ▸ by simp [Subgroup.one_mem]⟩⟩ #align subgroup.subsingleton_iff Subgroup.subsingleton_iff #align add_subgroup.subsingleton_iff AddSubgroup.subsingleton_iff @[to_additive (attr := simp)] theorem nontrivial_iff : Nontrivial (Subgroup G) ↔ Nontrivial G := not_iff_not.mp ((not_nontrivial_iff_subsingleton.trans subsingleton_iff).trans not_nontrivial_iff_subsingleton.symm) #align subgroup.nontrivial_iff Subgroup.nontrivial_iff #align add_subgroup.nontrivial_iff AddSubgroup.nontrivial_iff @[to_additive] instance [Subsingleton G] : Unique (Subgroup G) := ⟨⟨⊥⟩, fun a => @Subsingleton.elim _ (subsingleton_iff.mpr ‹_›) a _⟩ @[to_additive] instance [Nontrivial G] : Nontrivial (Subgroup G) := nontrivial_iff.mpr ‹_› @[to_additive] theorem eq_top_iff' : H = ⊤ ↔ ∀ x : G, x ∈ H := eq_top_iff.trans ⟨fun h m => h <| mem_top m, fun h m _ => h m⟩ #align subgroup.eq_top_iff' Subgroup.eq_top_iff' #align add_subgroup.eq_top_iff' AddSubgroup.eq_top_iff' /-- The `Subgroup` generated by a set. -/ @[to_additive "The `AddSubgroup` generated by a set"] def closure (k : Set G) : Subgroup G := sInf { K | k ⊆ K } #align subgroup.closure Subgroup.closure #align add_subgroup.closure AddSubgroup.closure variable {k : Set G} @[to_additive] theorem mem_closure {x : G} : x ∈ closure k ↔ ∀ K : Subgroup G, k ⊆ K → x ∈ K := mem_sInf #align subgroup.mem_closure Subgroup.mem_closure #align add_subgroup.mem_closure AddSubgroup.mem_closure /-- The subgroup generated by a set includes the set. -/ @[to_additive (attr := simp, aesop safe 20 apply (rule_sets := [SetLike])) "The `AddSubgroup` generated by a set includes the set."] theorem subset_closure : k ⊆ closure k := fun _ hx => mem_closure.2 fun _ hK => hK hx #align subgroup.subset_closure Subgroup.subset_closure #align add_subgroup.subset_closure AddSubgroup.subset_closure @[to_additive] theorem not_mem_of_not_mem_closure {P : G} (hP : P ∉ closure k) : P ∉ k := fun h => hP (subset_closure h) #align subgroup.not_mem_of_not_mem_closure Subgroup.not_mem_of_not_mem_closure #align add_subgroup.not_mem_of_not_mem_closure AddSubgroup.not_mem_of_not_mem_closure open Set /-- A subgroup `K` includes `closure k` if and only if it includes `k`. -/ @[to_additive (attr := simp) "An additive subgroup `K` includes `closure k` if and only if it includes `k`"] theorem closure_le : closure k ≤ K ↔ k ⊆ K := ⟨Subset.trans subset_closure, fun h => sInf_le h⟩ #align subgroup.closure_le Subgroup.closure_le #align add_subgroup.closure_le AddSubgroup.closure_le @[to_additive] theorem closure_eq_of_le (h₁ : k ⊆ K) (h₂ : K ≤ closure k) : closure k = K := le_antisymm ((closure_le <| K).2 h₁) h₂ #align subgroup.closure_eq_of_le Subgroup.closure_eq_of_le #align add_subgroup.closure_eq_of_le AddSubgroup.closure_eq_of_le /-- An induction principle for closure membership. If `p` holds for `1` and all elements of `k`, and is preserved under multiplication and inverse, then `p` holds for all elements of the closure of `k`. -/ @[to_additive (attr := elab_as_elim) "An induction principle for additive closure membership. If `p` holds for `0` and all elements of `k`, and is preserved under addition and inverses, then `p` holds for all elements of the additive closure of `k`."] theorem closure_induction {p : G → Prop} {x} (h : x ∈ closure k) (mem : ∀ x ∈ k, p x) (one : p 1) (mul : ∀ x y, p x → p y → p (x * y)) (inv : ∀ x, p x → p x⁻¹) : p x := (@closure_le _ _ ⟨⟨⟨setOf p, fun {x y} ↦ mul x y⟩, one⟩, fun {x} ↦ inv x⟩ k).2 mem h #align subgroup.closure_induction Subgroup.closure_induction #align add_subgroup.closure_induction AddSubgroup.closure_induction /-- A dependent version of `Subgroup.closure_induction`. -/ @[to_additive (attr := elab_as_elim) "A dependent version of `AddSubgroup.closure_induction`. "] theorem closure_induction' {p : ∀ x, x ∈ closure k → Prop} (mem : ∀ (x) (h : x ∈ k), p x (subset_closure h)) (one : p 1 (one_mem _)) (mul : ∀ x hx y hy, p x hx → p y hy → p (x * y) (mul_mem hx hy)) (inv : ∀ x hx, p x hx → p x⁻¹ (inv_mem hx)) {x} (hx : x ∈ closure k) : p x hx := by refine Exists.elim ?_ fun (hx : x ∈ closure k) (hc : p x hx) => hc exact closure_induction hx (fun x hx => ⟨_, mem x hx⟩) ⟨_, one⟩ (fun x y ⟨hx', hx⟩ ⟨hy', hy⟩ => ⟨_, mul _ _ _ _ hx hy⟩) fun x ⟨hx', hx⟩ => ⟨_, inv _ _ hx⟩ #align subgroup.closure_induction' Subgroup.closure_induction' #align add_subgroup.closure_induction' AddSubgroup.closure_induction' /-- An induction principle for closure membership for predicates with two arguments. -/ @[to_additive (attr := elab_as_elim) "An induction principle for additive closure membership, for predicates with two arguments."] theorem closure_induction₂ {p : G → G → Prop} {x} {y : G} (hx : x ∈ closure k) (hy : y ∈ closure k) (Hk : ∀ x ∈ k, ∀ y ∈ k, p x y) (H1_left : ∀ x, p 1 x) (H1_right : ∀ x, p x 1) (Hmul_left : ∀ x₁ x₂ y, p x₁ y → p x₂ y → p (x₁ * x₂) y) (Hmul_right : ∀ x y₁ y₂, p x y₁ → p x y₂ → p x (y₁ * y₂)) (Hinv_left : ∀ x y, p x y → p x⁻¹ y) (Hinv_right : ∀ x y, p x y → p x y⁻¹) : p x y := closure_induction hx (fun x xk => closure_induction hy (Hk x xk) (H1_right x) (Hmul_right x) (Hinv_right x)) (H1_left y) (fun z z' => Hmul_left z z' y) fun z => Hinv_left z y #align subgroup.closure_induction₂ Subgroup.closure_induction₂ #align add_subgroup.closure_induction₂ AddSubgroup.closure_induction₂ @[to_additive (attr := simp)] theorem closure_closure_coe_preimage {k : Set G} : closure (((↑) : closure k → G) ⁻¹' k) = ⊤ := eq_top_iff.2 fun x => Subtype.recOn x fun x hx _ => by refine closure_induction' (fun g hg => ?_) ?_ (fun g₁ g₂ hg₁ hg₂ => ?_) (fun g hg => ?_) hx · exact subset_closure hg · exact one_mem _ · exact mul_mem · exact inv_mem #align subgroup.closure_closure_coe_preimage Subgroup.closure_closure_coe_preimage #align add_subgroup.closure_closure_coe_preimage AddSubgroup.closure_closure_coe_preimage /-- If all the elements of a set `s` commute, then `closure s` is a commutative group. -/ @[to_additive "If all the elements of a set `s` commute, then `closure s` is an additive commutative group."] def closureCommGroupOfComm {k : Set G} (hcomm : ∀ x ∈ k, ∀ y ∈ k, x * y = y * x) : CommGroup (closure k) := { (closure k).toGroup with mul_comm := fun x y => by ext simp only [Subgroup.coe_mul] refine closure_induction₂ x.prop y.prop hcomm (fun x => by simp only [mul_one, one_mul]) (fun x => by simp only [mul_one, one_mul]) (fun x y z h₁ h₂ => by rw [mul_assoc, h₂, ← mul_assoc, h₁, mul_assoc]) (fun x y z h₁ h₂ => by rw [← mul_assoc, h₁, mul_assoc, h₂, ← mul_assoc]) (fun x y h => by rw [inv_mul_eq_iff_eq_mul, ← mul_assoc, h, mul_assoc, mul_inv_self, mul_one]) fun x y h => by rw [mul_inv_eq_iff_eq_mul, mul_assoc, h, ← mul_assoc, inv_mul_self, one_mul] } #align subgroup.closure_comm_group_of_comm Subgroup.closureCommGroupOfComm #align add_subgroup.closure_add_comm_group_of_comm AddSubgroup.closureAddCommGroupOfComm variable (G) /-- `closure` forms a Galois insertion with the coercion to set. -/ @[to_additive "`closure` forms a Galois insertion with the coercion to set."] protected def gi : GaloisInsertion (@closure G _) (↑) where choice s _ := closure s gc s t := @closure_le _ _ t s le_l_u _s := subset_closure choice_eq _s _h := rfl #align subgroup.gi Subgroup.gi #align add_subgroup.gi AddSubgroup.gi variable {G} /-- Subgroup closure of a set is monotone in its argument: if `h ⊆ k`, then `closure h ≤ closure k`. -/ @[to_additive "Additive subgroup closure of a set is monotone in its argument: if `h ⊆ k`, then `closure h ≤ closure k`"] theorem closure_mono ⦃h k : Set G⦄ (h' : h ⊆ k) : closure h ≤ closure k := (Subgroup.gi G).gc.monotone_l h' #align subgroup.closure_mono Subgroup.closure_mono #align add_subgroup.closure_mono AddSubgroup.closure_mono /-- Closure of a subgroup `K` equals `K`. -/ @[to_additive (attr := simp) "Additive closure of an additive subgroup `K` equals `K`"] theorem closure_eq : closure (K : Set G) = K := (Subgroup.gi G).l_u_eq K #align subgroup.closure_eq Subgroup.closure_eq #align add_subgroup.closure_eq AddSubgroup.closure_eq @[to_additive (attr := simp)] theorem closure_empty : closure (∅ : Set G) = ⊥ := (Subgroup.gi G).gc.l_bot #align subgroup.closure_empty Subgroup.closure_empty #align add_subgroup.closure_empty AddSubgroup.closure_empty @[to_additive (attr := simp)] theorem closure_univ : closure (univ : Set G) = ⊤ := @coe_top G _ ▸ closure_eq ⊤ #align subgroup.closure_univ Subgroup.closure_univ #align add_subgroup.closure_univ AddSubgroup.closure_univ @[to_additive] theorem closure_union (s t : Set G) : closure (s ∪ t) = closure s ⊔ closure t := (Subgroup.gi G).gc.l_sup #align subgroup.closure_union Subgroup.closure_union #align add_subgroup.closure_union AddSubgroup.closure_union @[to_additive] theorem sup_eq_closure (H H' : Subgroup G) : H ⊔ H' = closure ((H : Set G) ∪ (H' : Set G)) := by simp_rw [closure_union, closure_eq] @[to_additive] theorem closure_iUnion {ι} (s : ι → Set G) : closure (⋃ i, s i) = ⨆ i, closure (s i) := (Subgroup.gi G).gc.l_iSup #align subgroup.closure_Union Subgroup.closure_iUnion #align add_subgroup.closure_Union AddSubgroup.closure_iUnion @[to_additive (attr := simp)] theorem closure_eq_bot_iff : closure k = ⊥ ↔ k ⊆ {1} := le_bot_iff.symm.trans <| closure_le _ #align subgroup.closure_eq_bot_iff Subgroup.closure_eq_bot_iff #align add_subgroup.closure_eq_bot_iff AddSubgroup.closure_eq_bot_iff @[to_additive] theorem iSup_eq_closure {ι : Sort*} (p : ι → Subgroup G) : ⨆ i, p i = closure (⋃ i, (p i : Set G)) := by simp_rw [closure_iUnion, closure_eq] #align subgroup.supr_eq_closure Subgroup.iSup_eq_closure #align add_subgroup.supr_eq_closure AddSubgroup.iSup_eq_closure /-- The subgroup generated by an element of a group equals the set of integer number powers of the element. -/ @[to_additive "The `AddSubgroup` generated by an element of an `AddGroup` equals the set of natural number multiples of the element."] theorem mem_closure_singleton {x y : G} : y ∈ closure ({x} : Set G) ↔ ∃ n : ℤ, x ^ n = y := by refine ⟨fun hy => closure_induction hy ?_ ?_ ?_ ?_, fun ⟨n, hn⟩ => hn ▸ zpow_mem (subset_closure <| mem_singleton x) n⟩ · intro y hy rw [eq_of_mem_singleton hy] exact ⟨1, zpow_one x⟩ · exact ⟨0, zpow_zero x⟩ · rintro _ _ ⟨n, rfl⟩ ⟨m, rfl⟩ exact ⟨n + m, zpow_add x n m⟩ rintro _ ⟨n, rfl⟩ exact ⟨-n, zpow_neg x n⟩ #align subgroup.mem_closure_singleton Subgroup.mem_closure_singleton #align add_subgroup.mem_closure_singleton AddSubgroup.mem_closure_singleton @[to_additive] theorem closure_singleton_one : closure ({1} : Set G) = ⊥ := by simp [eq_bot_iff_forall, mem_closure_singleton] #align subgroup.closure_singleton_one Subgroup.closure_singleton_one #align add_subgroup.closure_singleton_zero AddSubgroup.closure_singleton_zero @[to_additive] theorem le_closure_toSubmonoid (S : Set G) : Submonoid.closure S ≤ (closure S).toSubmonoid := Submonoid.closure_le.2 subset_closure #align subgroup.le_closure_to_submonoid Subgroup.le_closure_toSubmonoid #align add_subgroup.le_closure_to_add_submonoid AddSubgroup.le_closure_toAddSubmonoid @[to_additive] theorem closure_eq_top_of_mclosure_eq_top {S : Set G} (h : Submonoid.closure S = ⊤) : closure S = ⊤ := (eq_top_iff' _).2 fun _ => le_closure_toSubmonoid _ <| h.symm ▸ trivial #align subgroup.closure_eq_top_of_mclosure_eq_top Subgroup.closure_eq_top_of_mclosure_eq_top #align add_subgroup.closure_eq_top_of_mclosure_eq_top AddSubgroup.closure_eq_top_of_mclosure_eq_top @[to_additive] theorem mem_iSup_of_directed {ι} [hι : Nonempty ι] {K : ι → Subgroup G} (hK : Directed (· ≤ ·) K) {x : G} : x ∈ (iSup K : Subgroup G) ↔ ∃ i, x ∈ K i := by refine ⟨?_, fun ⟨i, hi⟩ ↦ le_iSup K i hi⟩ suffices x ∈ closure (⋃ i, (K i : Set G)) → ∃ i, x ∈ K i by simpa only [closure_iUnion, closure_eq (K _)] using this refine fun hx ↦ closure_induction hx (fun _ ↦ mem_iUnion.1) ?_ ?_ ?_ · exact hι.elim fun i ↦ ⟨i, (K i).one_mem⟩ · rintro x y ⟨i, hi⟩ ⟨j, hj⟩ rcases hK i j with ⟨k, hki, hkj⟩ exact ⟨k, mul_mem (hki hi) (hkj hj)⟩ · rintro _ ⟨i, hi⟩ exact ⟨i, inv_mem hi⟩ #align subgroup.mem_supr_of_directed Subgroup.mem_iSup_of_directed #align add_subgroup.mem_supr_of_directed AddSubgroup.mem_iSup_of_directed @[to_additive] theorem coe_iSup_of_directed {ι} [Nonempty ι] {S : ι → Subgroup G} (hS : Directed (· ≤ ·) S) : ((⨆ i, S i : Subgroup G) : Set G) = ⋃ i, S i := Set.ext fun x ↦ by simp [mem_iSup_of_directed hS] #align subgroup.coe_supr_of_directed Subgroup.coe_iSup_of_directed #align add_subgroup.coe_supr_of_directed AddSubgroup.coe_iSup_of_directed @[to_additive] theorem mem_sSup_of_directedOn {K : Set (Subgroup G)} (Kne : K.Nonempty) (hK : DirectedOn (· ≤ ·) K) {x : G} : x ∈ sSup K ↔ ∃ s ∈ K, x ∈ s := by haveI : Nonempty K := Kne.to_subtype simp only [sSup_eq_iSup', mem_iSup_of_directed hK.directed_val, SetCoe.exists, Subtype.coe_mk, exists_prop] #align subgroup.mem_Sup_of_directed_on Subgroup.mem_sSup_of_directedOn #align add_subgroup.mem_Sup_of_directed_on AddSubgroup.mem_sSup_of_directedOn variable {N : Type*} [Group N] {P : Type*} [Group P] /-- The preimage of a subgroup along a monoid homomorphism is a subgroup. -/ @[to_additive "The preimage of an `AddSubgroup` along an `AddMonoid` homomorphism is an `AddSubgroup`."] def comap {N : Type*} [Group N] (f : G →* N) (H : Subgroup N) : Subgroup G := { H.toSubmonoid.comap f with carrier := f ⁻¹' H inv_mem' := fun {a} ha => show f a⁻¹ ∈ H by rw [f.map_inv]; exact H.inv_mem ha } #align subgroup.comap Subgroup.comap #align add_subgroup.comap AddSubgroup.comap @[to_additive (attr := simp)] theorem coe_comap (K : Subgroup N) (f : G →* N) : (K.comap f : Set G) = f ⁻¹' K := rfl #align subgroup.coe_comap Subgroup.coe_comap #align add_subgroup.coe_comap AddSubgroup.coe_comap @[simp] theorem toAddSubgroup_comap {G₂ : Type*} [Group G₂] (f : G →* G₂) (s : Subgroup G₂) : s.toAddSubgroup.comap (MonoidHom.toAdditive f) = Subgroup.toAddSubgroup (s.comap f) := rfl @[simp] theorem _root_.AddSubgroup.toSubgroup_comap {A A₂ : Type*} [AddGroup A] [AddGroup A₂] (f : A →+ A₂) (s : AddSubgroup A₂) : s.toSubgroup.comap (AddMonoidHom.toMultiplicative f) = AddSubgroup.toSubgroup (s.comap f) := rfl @[to_additive (attr := simp)] theorem mem_comap {K : Subgroup N} {f : G →* N} {x : G} : x ∈ K.comap f ↔ f x ∈ K := Iff.rfl #align subgroup.mem_comap Subgroup.mem_comap #align add_subgroup.mem_comap AddSubgroup.mem_comap @[to_additive] theorem comap_mono {f : G →* N} {K K' : Subgroup N} : K ≤ K' → comap f K ≤ comap f K' := preimage_mono #align subgroup.comap_mono Subgroup.comap_mono #align add_subgroup.comap_mono AddSubgroup.comap_mono @[to_additive] theorem comap_comap (K : Subgroup P) (g : N →* P) (f : G →* N) : (K.comap g).comap f = K.comap (g.comp f) := rfl #align subgroup.comap_comap Subgroup.comap_comap #align add_subgroup.comap_comap AddSubgroup.comap_comap @[to_additive (attr := simp)] theorem comap_id (K : Subgroup N) : K.comap (MonoidHom.id _) = K := by ext rfl #align subgroup.comap_id Subgroup.comap_id #align add_subgroup.comap_id AddSubgroup.comap_id /-- The image of a subgroup along a monoid homomorphism is a subgroup. -/ @[to_additive "The image of an `AddSubgroup` along an `AddMonoid` homomorphism is an `AddSubgroup`."] def map (f : G →* N) (H : Subgroup G) : Subgroup N := { H.toSubmonoid.map f with carrier := f '' H inv_mem' := by rintro _ ⟨x, hx, rfl⟩ exact ⟨x⁻¹, H.inv_mem hx, f.map_inv x⟩ } #align subgroup.map Subgroup.map #align add_subgroup.map AddSubgroup.map @[to_additive (attr := simp)] theorem coe_map (f : G →* N) (K : Subgroup G) : (K.map f : Set N) = f '' K := rfl #align subgroup.coe_map Subgroup.coe_map #align add_subgroup.coe_map AddSubgroup.coe_map @[to_additive (attr := simp)] theorem mem_map {f : G →* N} {K : Subgroup G} {y : N} : y ∈ K.map f ↔ ∃ x ∈ K, f x = y := Iff.rfl #align subgroup.mem_map Subgroup.mem_map #align add_subgroup.mem_map AddSubgroup.mem_map @[to_additive] theorem mem_map_of_mem (f : G →* N) {K : Subgroup G} {x : G} (hx : x ∈ K) : f x ∈ K.map f := mem_image_of_mem f hx #align subgroup.mem_map_of_mem Subgroup.mem_map_of_mem #align add_subgroup.mem_map_of_mem AddSubgroup.mem_map_of_mem @[to_additive] theorem apply_coe_mem_map (f : G →* N) (K : Subgroup G) (x : K) : f x ∈ K.map f := mem_map_of_mem f x.prop #align subgroup.apply_coe_mem_map Subgroup.apply_coe_mem_map #align add_subgroup.apply_coe_mem_map AddSubgroup.apply_coe_mem_map @[to_additive] theorem map_mono {f : G →* N} {K K' : Subgroup G} : K ≤ K' → map f K ≤ map f K' := image_subset _ #align subgroup.map_mono Subgroup.map_mono #align add_subgroup.map_mono AddSubgroup.map_mono @[to_additive (attr := simp)] theorem map_id : K.map (MonoidHom.id G) = K := SetLike.coe_injective <| image_id _ #align subgroup.map_id Subgroup.map_id #align add_subgroup.map_id AddSubgroup.map_id @[to_additive] theorem map_map (g : N →* P) (f : G →* N) : (K.map f).map g = K.map (g.comp f) := SetLike.coe_injective <| image_image _ _ _ #align subgroup.map_map Subgroup.map_map #align add_subgroup.map_map AddSubgroup.map_map @[to_additive (attr := simp)] theorem map_one_eq_bot : K.map (1 : G →* N) = ⊥ := eq_bot_iff.mpr <| by rintro x ⟨y, _, rfl⟩ simp #align subgroup.map_one_eq_bot Subgroup.map_one_eq_bot #align add_subgroup.map_zero_eq_bot AddSubgroup.map_zero_eq_bot @[to_additive] theorem mem_map_equiv {f : G ≃* N} {K : Subgroup G} {x : N} : x ∈ K.map f.toMonoidHom ↔ f.symm x ∈ K := by erw [@Set.mem_image_equiv _ _ (↑K) f.toEquiv x]; rfl #align subgroup.mem_map_equiv Subgroup.mem_map_equiv #align add_subgroup.mem_map_equiv AddSubgroup.mem_map_equiv -- The simpNF linter says that the LHS can be simplified via `Subgroup.mem_map`. -- However this is a higher priority lemma. -- https://github.com/leanprover/std4/issues/207 @[to_additive (attr := simp 1100, nolint simpNF)] theorem mem_map_iff_mem {f : G →* N} (hf : Function.Injective f) {K : Subgroup G} {x : G} : f x ∈ K.map f ↔ x ∈ K := hf.mem_set_image #align subgroup.mem_map_iff_mem Subgroup.mem_map_iff_mem #align add_subgroup.mem_map_iff_mem AddSubgroup.mem_map_iff_mem @[to_additive] theorem map_equiv_eq_comap_symm' (f : G ≃* N) (K : Subgroup G) : K.map f.toMonoidHom = K.comap f.symm.toMonoidHom := SetLike.coe_injective (f.toEquiv.image_eq_preimage K) #align subgroup.map_equiv_eq_comap_symm Subgroup.map_equiv_eq_comap_symm' #align add_subgroup.map_equiv_eq_comap_symm AddSubgroup.map_equiv_eq_comap_symm' @[to_additive] theorem map_equiv_eq_comap_symm (f : G ≃* N) (K : Subgroup G) : K.map f = K.comap (G := N) f.symm := map_equiv_eq_comap_symm' _ _ @[to_additive] theorem comap_equiv_eq_map_symm (f : N ≃* G) (K : Subgroup G) : K.comap (G := N) f = K.map f.symm := (map_equiv_eq_comap_symm f.symm K).symm @[to_additive] theorem comap_equiv_eq_map_symm' (f : N ≃* G) (K : Subgroup G) : K.comap f.toMonoidHom = K.map f.symm.toMonoidHom := (map_equiv_eq_comap_symm f.symm K).symm #align subgroup.comap_equiv_eq_map_symm Subgroup.comap_equiv_eq_map_symm' #align add_subgroup.comap_equiv_eq_map_symm AddSubgroup.comap_equiv_eq_map_symm' @[to_additive] theorem map_symm_eq_iff_map_eq {H : Subgroup N} {e : G ≃* N} : H.map ↑e.symm = K ↔ K.map ↑e = H := by constructor <;> rintro rfl · rw [map_map, ← MulEquiv.coe_monoidHom_trans, MulEquiv.symm_trans_self, MulEquiv.coe_monoidHom_refl, map_id] · rw [map_map, ← MulEquiv.coe_monoidHom_trans, MulEquiv.self_trans_symm, MulEquiv.coe_monoidHom_refl, map_id] #align subgroup.map_symm_eq_iff_map_eq Subgroup.map_symm_eq_iff_map_eq #align add_subgroup.map_symm_eq_iff_map_eq AddSubgroup.map_symm_eq_iff_map_eq @[to_additive] theorem map_le_iff_le_comap {f : G →* N} {K : Subgroup G} {H : Subgroup N} : K.map f ≤ H ↔ K ≤ H.comap f := image_subset_iff #align subgroup.map_le_iff_le_comap Subgroup.map_le_iff_le_comap #align add_subgroup.map_le_iff_le_comap AddSubgroup.map_le_iff_le_comap @[to_additive] theorem gc_map_comap (f : G →* N) : GaloisConnection (map f) (comap f) := fun _ _ => map_le_iff_le_comap #align subgroup.gc_map_comap Subgroup.gc_map_comap #align add_subgroup.gc_map_comap AddSubgroup.gc_map_comap @[to_additive] theorem map_sup (H K : Subgroup G) (f : G →* N) : (H ⊔ K).map f = H.map f ⊔ K.map f := (gc_map_comap f).l_sup #align subgroup.map_sup Subgroup.map_sup #align add_subgroup.map_sup AddSubgroup.map_sup @[to_additive] theorem map_iSup {ι : Sort*} (f : G →* N) (s : ι → Subgroup G) : (iSup s).map f = ⨆ i, (s i).map f := (gc_map_comap f).l_iSup #align subgroup.map_supr Subgroup.map_iSup #align add_subgroup.map_supr AddSubgroup.map_iSup @[to_additive] theorem comap_sup_comap_le (H K : Subgroup N) (f : G →* N) : comap f H ⊔ comap f K ≤ comap f (H ⊔ K) := Monotone.le_map_sup (fun _ _ => comap_mono) H K #align subgroup.comap_sup_comap_le Subgroup.comap_sup_comap_le #align add_subgroup.comap_sup_comap_le AddSubgroup.comap_sup_comap_le @[to_additive] theorem iSup_comap_le {ι : Sort*} (f : G →* N) (s : ι → Subgroup N) : ⨆ i, (s i).comap f ≤ (iSup s).comap f := Monotone.le_map_iSup fun _ _ => comap_mono #align subgroup.supr_comap_le Subgroup.iSup_comap_le #align add_subgroup.supr_comap_le AddSubgroup.iSup_comap_le @[to_additive] theorem comap_inf (H K : Subgroup N) (f : G →* N) : (H ⊓ K).comap f = H.comap f ⊓ K.comap f := (gc_map_comap f).u_inf #align subgroup.comap_inf Subgroup.comap_inf #align add_subgroup.comap_inf AddSubgroup.comap_inf @[to_additive] theorem comap_iInf {ι : Sort*} (f : G →* N) (s : ι → Subgroup N) : (iInf s).comap f = ⨅ i, (s i).comap f := (gc_map_comap f).u_iInf #align subgroup.comap_infi Subgroup.comap_iInf #align add_subgroup.comap_infi AddSubgroup.comap_iInf @[to_additive] theorem map_inf_le (H K : Subgroup G) (f : G →* N) : map f (H ⊓ K) ≤ map f H ⊓ map f K := le_inf (map_mono inf_le_left) (map_mono inf_le_right) #align subgroup.map_inf_le Subgroup.map_inf_le #align add_subgroup.map_inf_le AddSubgroup.map_inf_le @[to_additive] theorem map_inf_eq (H K : Subgroup G) (f : G →* N) (hf : Function.Injective f) : map f (H ⊓ K) = map f H ⊓ map f K := by rw [← SetLike.coe_set_eq] simp [Set.image_inter hf] #align subgroup.map_inf_eq Subgroup.map_inf_eq #align add_subgroup.map_inf_eq AddSubgroup.map_inf_eq @[to_additive (attr := simp)] theorem map_bot (f : G →* N) : (⊥ : Subgroup G).map f = ⊥ := (gc_map_comap f).l_bot #align subgroup.map_bot Subgroup.map_bot #align add_subgroup.map_bot AddSubgroup.map_bot @[to_additive (attr := simp)] theorem map_top_of_surjective (f : G →* N) (h : Function.Surjective f) : Subgroup.map f ⊤ = ⊤ := by rw [eq_top_iff] intro x _ obtain ⟨y, hy⟩ := h x exact ⟨y, trivial, hy⟩ #align subgroup.map_top_of_surjective Subgroup.map_top_of_surjective #align add_subgroup.map_top_of_surjective AddSubgroup.map_top_of_surjective @[to_additive (attr := simp)] theorem comap_top (f : G →* N) : (⊤ : Subgroup N).comap f = ⊤ := (gc_map_comap f).u_top #align subgroup.comap_top Subgroup.comap_top #align add_subgroup.comap_top AddSubgroup.comap_top /-- For any subgroups `H` and `K`, view `H ⊓ K` as a subgroup of `K`. -/ @[to_additive "For any subgroups `H` and `K`, view `H ⊓ K` as a subgroup of `K`."] def subgroupOf (H K : Subgroup G) : Subgroup K := H.comap K.subtype #align subgroup.subgroup_of Subgroup.subgroupOf #align add_subgroup.add_subgroup_of AddSubgroup.addSubgroupOf /-- If `H ≤ K`, then `H` as a subgroup of `K` is isomorphic to `H`. -/ @[to_additive (attr := simps) "If `H ≤ K`, then `H` as a subgroup of `K` is isomorphic to `H`."] def subgroupOfEquivOfLe {G : Type*} [Group G] {H K : Subgroup G} (h : H ≤ K) : H.subgroupOf K ≃* H where toFun g := ⟨g.1, g.2⟩ invFun g := ⟨⟨g.1, h g.2⟩, g.2⟩ left_inv _g := Subtype.ext (Subtype.ext rfl) right_inv _g := Subtype.ext rfl map_mul' _g _h := rfl #align subgroup.subgroup_of_equiv_of_le Subgroup.subgroupOfEquivOfLe #align add_subgroup.add_subgroup_of_equiv_of_le AddSubgroup.addSubgroupOfEquivOfLe #align subgroup.subgroup_of_equiv_of_le_symm_apply_coe_coe Subgroup.subgroupOfEquivOfLe_symm_apply_coe_coe #align add_subgroup.subgroup_of_equiv_of_le_symm_apply_coe_coe AddSubgroup.addSubgroupOfEquivOfLe_symm_apply_coe_coe #align subgroup.subgroup_of_equiv_of_le_apply_coe Subgroup.subgroupOfEquivOfLe_apply_coe #align add_subgroup.subgroup_of_equiv_of_le_apply_coe AddSubgroup.addSubgroupOfEquivOfLe_apply_coe @[to_additive (attr := simp)] theorem comap_subtype (H K : Subgroup G) : H.comap K.subtype = H.subgroupOf K := rfl #align subgroup.comap_subtype Subgroup.comap_subtype #align add_subgroup.comap_subtype AddSubgroup.comap_subtype @[to_additive (attr := simp)] theorem comap_inclusion_subgroupOf {K₁ K₂ : Subgroup G} (h : K₁ ≤ K₂) (H : Subgroup G) : (H.subgroupOf K₂).comap (inclusion h) = H.subgroupOf K₁ := rfl #align subgroup.comap_inclusion_subgroup_of Subgroup.comap_inclusion_subgroupOf #align add_subgroup.comap_inclusion_add_subgroup_of AddSubgroup.comap_inclusion_addSubgroupOf @[to_additive] theorem coe_subgroupOf (H K : Subgroup G) : (H.subgroupOf K : Set K) = K.subtype ⁻¹' H := rfl #align subgroup.coe_subgroup_of Subgroup.coe_subgroupOf #align add_subgroup.coe_add_subgroup_of AddSubgroup.coe_addSubgroupOf @[to_additive] theorem mem_subgroupOf {H K : Subgroup G} {h : K} : h ∈ H.subgroupOf K ↔ (h : G) ∈ H := Iff.rfl #align subgroup.mem_subgroup_of Subgroup.mem_subgroupOf #align add_subgroup.mem_add_subgroup_of AddSubgroup.mem_addSubgroupOf -- TODO(kmill): use `K ⊓ H` order for RHS to match `Subtype.image_preimage_coe` @[to_additive (attr := simp)] theorem subgroupOf_map_subtype (H K : Subgroup G) : (H.subgroupOf K).map K.subtype = H ⊓ K := SetLike.ext' <| by refine Subtype.image_preimage_coe _ _ |>.trans ?_; apply Set.inter_comm #align subgroup.subgroup_of_map_subtype Subgroup.subgroupOf_map_subtype #align add_subgroup.add_subgroup_of_map_subtype AddSubgroup.addSubgroupOf_map_subtype @[to_additive (attr := simp)] theorem bot_subgroupOf : (⊥ : Subgroup G).subgroupOf H = ⊥ := Eq.symm (Subgroup.ext fun _g => Subtype.ext_iff) #align subgroup.bot_subgroup_of Subgroup.bot_subgroupOf #align add_subgroup.bot_add_subgroup_of AddSubgroup.bot_addSubgroupOf @[to_additive (attr := simp)] theorem top_subgroupOf : (⊤ : Subgroup G).subgroupOf H = ⊤ := rfl #align subgroup.top_subgroup_of Subgroup.top_subgroupOf #align add_subgroup.top_add_subgroup_of AddSubgroup.top_addSubgroupOf @[to_additive] theorem subgroupOf_bot_eq_bot : H.subgroupOf ⊥ = ⊥ := Subsingleton.elim _ _ #align subgroup.subgroup_of_bot_eq_bot Subgroup.subgroupOf_bot_eq_bot #align add_subgroup.add_subgroup_of_bot_eq_bot AddSubgroup.addSubgroupOf_bot_eq_bot @[to_additive] theorem subgroupOf_bot_eq_top : H.subgroupOf ⊥ = ⊤ := Subsingleton.elim _ _ #align subgroup.subgroup_of_bot_eq_top Subgroup.subgroupOf_bot_eq_top #align add_subgroup.add_subgroup_of_bot_eq_top AddSubgroup.addSubgroupOf_bot_eq_top @[to_additive (attr := simp)] theorem subgroupOf_self : H.subgroupOf H = ⊤ := top_unique fun g _hg => g.2 #align subgroup.subgroup_of_self Subgroup.subgroupOf_self #align add_subgroup.add_subgroup_of_self AddSubgroup.addSubgroupOf_self @[to_additive (attr := simp)] theorem subgroupOf_inj {H₁ H₂ K : Subgroup G} : H₁.subgroupOf K = H₂.subgroupOf K ↔ H₁ ⊓ K = H₂ ⊓ K := by simpa only [SetLike.ext_iff, mem_inf, mem_subgroupOf, and_congr_left_iff] using Subtype.forall #align subgroup.subgroup_of_inj Subgroup.subgroupOf_inj #align add_subgroup.add_subgroup_of_inj AddSubgroup.addSubgroupOf_inj @[to_additive (attr := simp)] theorem inf_subgroupOf_right (H K : Subgroup G) : (H ⊓ K).subgroupOf K = H.subgroupOf K := subgroupOf_inj.2 (inf_right_idem _ _) #align subgroup.inf_subgroup_of_right Subgroup.inf_subgroupOf_right #align add_subgroup.inf_add_subgroup_of_right AddSubgroup.inf_addSubgroupOf_right @[to_additive (attr := simp)] theorem inf_subgroupOf_left (H K : Subgroup G) : (K ⊓ H).subgroupOf K = H.subgroupOf K := by rw [inf_comm, inf_subgroupOf_right] #align subgroup.inf_subgroup_of_left Subgroup.inf_subgroupOf_left #align add_subgroup.inf_add_subgroup_of_left AddSubgroup.inf_addSubgroupOf_left @[to_additive (attr := simp)] theorem subgroupOf_eq_bot {H K : Subgroup G} : H.subgroupOf K = ⊥ ↔ Disjoint H K := by rw [disjoint_iff, ← bot_subgroupOf, subgroupOf_inj, bot_inf_eq] #align subgroup.subgroup_of_eq_bot Subgroup.subgroupOf_eq_bot #align add_subgroup.add_subgroup_of_eq_bot AddSubgroup.addSubgroupOf_eq_bot @[to_additive (attr := simp)] theorem subgroupOf_eq_top {H K : Subgroup G} : H.subgroupOf K = ⊤ ↔ K ≤ H := by rw [← top_subgroupOf, subgroupOf_inj, top_inf_eq, inf_eq_right] #align subgroup.subgroup_of_eq_top Subgroup.subgroupOf_eq_top #align add_subgroup.add_subgroup_of_eq_top AddSubgroup.addSubgroupOf_eq_top /-- Given `Subgroup`s `H`, `K` of groups `G`, `N` respectively, `H × K` as a subgroup of `G × N`. -/ @[to_additive prod "Given `AddSubgroup`s `H`, `K` of `AddGroup`s `A`, `B` respectively, `H × K` as an `AddSubgroup` of `A × B`."] def prod (H : Subgroup G) (K : Subgroup N) : Subgroup (G × N) := { Submonoid.prod H.toSubmonoid K.toSubmonoid with inv_mem' := fun hx => ⟨H.inv_mem' hx.1, K.inv_mem' hx.2⟩ } #align subgroup.prod Subgroup.prod #align add_subgroup.prod AddSubgroup.prod @[to_additive coe_prod] theorem coe_prod (H : Subgroup G) (K : Subgroup N) : (H.prod K : Set (G × N)) = (H : Set G) ×ˢ (K : Set N) := rfl #align subgroup.coe_prod Subgroup.coe_prod #align add_subgroup.coe_prod AddSubgroup.coe_prod @[to_additive mem_prod] theorem mem_prod {H : Subgroup G} {K : Subgroup N} {p : G × N} : p ∈ H.prod K ↔ p.1 ∈ H ∧ p.2 ∈ K := Iff.rfl #align subgroup.mem_prod Subgroup.mem_prod #align add_subgroup.mem_prod AddSubgroup.mem_prod @[to_additive prod_mono] theorem prod_mono : ((· ≤ ·) ⇒ (· ≤ ·) ⇒ (· ≤ ·)) (@prod G _ N _) (@prod G _ N _) := fun _s _s' hs _t _t' ht => Set.prod_mono hs ht #align subgroup.prod_mono Subgroup.prod_mono #align add_subgroup.prod_mono AddSubgroup.prod_mono @[to_additive prod_mono_right] theorem prod_mono_right (K : Subgroup G) : Monotone fun t : Subgroup N => K.prod t := prod_mono (le_refl K) #align subgroup.prod_mono_right Subgroup.prod_mono_right #align add_subgroup.prod_mono_right AddSubgroup.prod_mono_right @[to_additive prod_mono_left] theorem prod_mono_left (H : Subgroup N) : Monotone fun K : Subgroup G => K.prod H := fun _ _ hs => prod_mono hs (le_refl H) #align subgroup.prod_mono_left Subgroup.prod_mono_left #align add_subgroup.prod_mono_left AddSubgroup.prod_mono_left @[to_additive prod_top] theorem prod_top (K : Subgroup G) : K.prod (⊤ : Subgroup N) = K.comap (MonoidHom.fst G N) := ext fun x => by simp [mem_prod, MonoidHom.coe_fst] #align subgroup.prod_top Subgroup.prod_top #align add_subgroup.prod_top AddSubgroup.prod_top @[to_additive top_prod] theorem top_prod (H : Subgroup N) : (⊤ : Subgroup G).prod H = H.comap (MonoidHom.snd G N) := ext fun x => by simp [mem_prod, MonoidHom.coe_snd] #align subgroup.top_prod Subgroup.top_prod #align add_subgroup.top_prod AddSubgroup.top_prod @[to_additive (attr := simp) top_prod_top] theorem top_prod_top : (⊤ : Subgroup G).prod (⊤ : Subgroup N) = ⊤ := (top_prod _).trans <| comap_top _ #align subgroup.top_prod_top Subgroup.top_prod_top #align add_subgroup.top_prod_top AddSubgroup.top_prod_top @[to_additive] theorem bot_prod_bot : (⊥ : Subgroup G).prod (⊥ : Subgroup N) = ⊥ := SetLike.coe_injective <| by simp [coe_prod, Prod.one_eq_mk] #align subgroup.bot_prod_bot Subgroup.bot_prod_bot #align add_subgroup.bot_sum_bot AddSubgroup.bot_sum_bot @[to_additive le_prod_iff] theorem le_prod_iff {H : Subgroup G} {K : Subgroup N} {J : Subgroup (G × N)} : J ≤ H.prod K ↔ map (MonoidHom.fst G N) J ≤ H ∧ map (MonoidHom.snd G N) J ≤ K := by simpa only [← Subgroup.toSubmonoid_le] using Submonoid.le_prod_iff #align subgroup.le_prod_iff Subgroup.le_prod_iff #align add_subgroup.le_prod_iff AddSubgroup.le_prod_iff @[to_additive prod_le_iff] theorem prod_le_iff {H : Subgroup G} {K : Subgroup N} {J : Subgroup (G × N)} : H.prod K ≤ J ↔ map (MonoidHom.inl G N) H ≤ J ∧ map (MonoidHom.inr G N) K ≤ J := by simpa only [← Subgroup.toSubmonoid_le] using Submonoid.prod_le_iff #align subgroup.prod_le_iff Subgroup.prod_le_iff #align add_subgroup.prod_le_iff AddSubgroup.prod_le_iff @[to_additive (attr := simp) prod_eq_bot_iff] theorem prod_eq_bot_iff {H : Subgroup G} {K : Subgroup N} : H.prod K = ⊥ ↔ H = ⊥ ∧ K = ⊥ := by simpa only [← Subgroup.toSubmonoid_eq] using Submonoid.prod_eq_bot_iff #align subgroup.prod_eq_bot_iff Subgroup.prod_eq_bot_iff #align add_subgroup.prod_eq_bot_iff AddSubgroup.prod_eq_bot_iff /-- Product of subgroups is isomorphic to their product as groups. -/ @[to_additive prodEquiv "Product of additive subgroups is isomorphic to their product as additive groups"] def prodEquiv (H : Subgroup G) (K : Subgroup N) : H.prod K ≃* H × K := { Equiv.Set.prod (H : Set G) (K : Set N) with map_mul' := fun _ _ => rfl } #align subgroup.prod_equiv Subgroup.prodEquiv #align add_subgroup.prod_equiv AddSubgroup.prodEquiv section Pi variable {η : Type*} {f : η → Type*} -- defined here and not in Algebra.Group.Submonoid.Operations to have access to Algebra.Group.Pi /-- A version of `Set.pi` for submonoids. Given an index set `I` and a family of submodules `s : Π i, Submonoid f i`, `pi I s` is the submonoid of dependent functions `f : Π i, f i` such that `f i` belongs to `Pi I s` whenever `i ∈ I`. -/ @[to_additive "A version of `Set.pi` for `AddSubmonoid`s. Given an index set `I` and a family of submodules `s : Π i, AddSubmonoid f i`, `pi I s` is the `AddSubmonoid` of dependent functions `f : Π i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`."] def _root_.Submonoid.pi [∀ i, MulOneClass (f i)] (I : Set η) (s : ∀ i, Submonoid (f i)) : Submonoid (∀ i, f i) where carrier := I.pi fun i => (s i).carrier one_mem' i _ := (s i).one_mem mul_mem' hp hq i hI := (s i).mul_mem (hp i hI) (hq i hI) #align submonoid.pi Submonoid.pi #align add_submonoid.pi AddSubmonoid.pi variable [∀ i, Group (f i)] /-- A version of `Set.pi` for subgroups. Given an index set `I` and a family of submodules `s : Π i, Subgroup f i`, `pi I s` is the subgroup of dependent functions `f : Π i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`. -/ @[to_additive "A version of `Set.pi` for `AddSubgroup`s. Given an index set `I` and a family of submodules `s : Π i, AddSubgroup f i`, `pi I s` is the `AddSubgroup` of dependent functions `f : Π i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`."] def pi (I : Set η) (H : ∀ i, Subgroup (f i)) : Subgroup (∀ i, f i) := { Submonoid.pi I fun i => (H i).toSubmonoid with inv_mem' := fun hp i hI => (H i).inv_mem (hp i hI) } #align subgroup.pi Subgroup.pi #align add_subgroup.pi AddSubgroup.pi @[to_additive] theorem coe_pi (I : Set η) (H : ∀ i, Subgroup (f i)) : (pi I H : Set (∀ i, f i)) = Set.pi I fun i => (H i : Set (f i)) := rfl #align subgroup.coe_pi Subgroup.coe_pi #align add_subgroup.coe_pi AddSubgroup.coe_pi @[to_additive] theorem mem_pi (I : Set η) {H : ∀ i, Subgroup (f i)} {p : ∀ i, f i} : p ∈ pi I H ↔ ∀ i : η, i ∈ I → p i ∈ H i := Iff.rfl #align subgroup.mem_pi Subgroup.mem_pi #align add_subgroup.mem_pi AddSubgroup.mem_pi @[to_additive] theorem pi_top (I : Set η) : (pi I fun i => (⊤ : Subgroup (f i))) = ⊤ := ext fun x => by simp [mem_pi] #align subgroup.pi_top Subgroup.pi_top #align add_subgroup.pi_top AddSubgroup.pi_top @[to_additive] theorem pi_empty (H : ∀ i, Subgroup (f i)) : pi ∅ H = ⊤ := ext fun x => by simp [mem_pi] #align subgroup.pi_empty Subgroup.pi_empty #align add_subgroup.pi_empty AddSubgroup.pi_empty @[to_additive] theorem pi_bot : (pi Set.univ fun i => (⊥ : Subgroup (f i))) = ⊥ := (eq_bot_iff_forall _).mpr fun p hp => by simp only [mem_pi, mem_bot] at * ext j exact hp j trivial #align subgroup.pi_bot Subgroup.pi_bot #align add_subgroup.pi_bot AddSubgroup.pi_bot @[to_additive] theorem le_pi_iff {I : Set η} {H : ∀ i, Subgroup (f i)} {J : Subgroup (∀ i, f i)} : J ≤ pi I H ↔ ∀ i : η, i ∈ I → map (Pi.evalMonoidHom f i) J ≤ H i := by constructor · intro h i hi rintro _ ⟨x, hx, rfl⟩ exact (h hx) _ hi · intro h x hx i hi exact h i hi ⟨_, hx, rfl⟩ #align subgroup.le_pi_iff Subgroup.le_pi_iff #align add_subgroup.le_pi_iff AddSubgroup.le_pi_iff @[to_additive (attr := simp)] theorem mulSingle_mem_pi [DecidableEq η] {I : Set η} {H : ∀ i, Subgroup (f i)} (i : η) (x : f i) : Pi.mulSingle i x ∈ pi I H ↔ i ∈ I → x ∈ H i := by constructor · intro h hi simpa using h i hi · intro h j hj by_cases heq : j = i · subst heq simpa using h hj · simp [heq, one_mem] #align subgroup.mul_single_mem_pi Subgroup.mulSingle_mem_pi #align add_subgroup.single_mem_pi AddSubgroup.single_mem_pi @[to_additive] theorem pi_eq_bot_iff (H : ∀ i, Subgroup (f i)) : pi Set.univ H = ⊥ ↔ ∀ i, H i = ⊥ := by classical simp only [eq_bot_iff_forall] constructor · intro h i x hx have : MonoidHom.mulSingle f i x = 1 := h (MonoidHom.mulSingle f i x) ((mulSingle_mem_pi i x).mpr fun _ => hx) simpa using congr_fun this i · exact fun h x hx => funext fun i => h _ _ (hx i trivial) #align subgroup.pi_eq_bot_iff Subgroup.pi_eq_bot_iff #align add_subgroup.pi_eq_bot_iff AddSubgroup.pi_eq_bot_iff end Pi /-- A subgroup is normal if whenever `n ∈ H`, then `g * n * g⁻¹ ∈ H` for every `g : G` -/ structure Normal : Prop where /-- `N` is closed under conjugation -/ conj_mem : ∀ n, n ∈ H → ∀ g : G, g * n * g⁻¹ ∈ H #align subgroup.normal Subgroup.Normal attribute [class] Normal end Subgroup namespace AddSubgroup /-- An AddSubgroup is normal if whenever `n ∈ H`, then `g + n - g ∈ H` for every `g : G` -/ structure Normal (H : AddSubgroup A) : Prop where /-- `N` is closed under additive conjugation -/ conj_mem : ∀ n, n ∈ H → ∀ g : A, g + n + -g ∈ H #align add_subgroup.normal AddSubgroup.Normal attribute [to_additive] Subgroup.Normal attribute [class] Normal end AddSubgroup namespace Subgroup variable {H K : Subgroup G} @[to_additive] instance (priority := 100) normal_of_comm {G : Type*} [CommGroup G] (H : Subgroup G) : H.Normal := ⟨by simp [mul_comm, mul_left_comm]⟩ #align subgroup.normal_of_comm Subgroup.normal_of_comm #align add_subgroup.normal_of_comm AddSubgroup.normal_of_comm namespace Normal variable (nH : H.Normal) @[to_additive] theorem conj_mem' (n : G) (hn : n ∈ H) (g : G) : g⁻¹ * n * g ∈ H := by convert nH.conj_mem n hn g⁻¹ rw [inv_inv] @[to_additive] theorem mem_comm {a b : G} (h : a * b ∈ H) : b * a ∈ H := by have : a⁻¹ * (a * b) * a⁻¹⁻¹ ∈ H := nH.conj_mem (a * b) h a⁻¹ -- Porting note: Previous code was: -- simpa simp_all only [inv_mul_cancel_left, inv_inv] #align subgroup.normal.mem_comm Subgroup.Normal.mem_comm #align add_subgroup.normal.mem_comm AddSubgroup.Normal.mem_comm @[to_additive] theorem mem_comm_iff {a b : G} : a * b ∈ H ↔ b * a ∈ H := ⟨nH.mem_comm, nH.mem_comm⟩ #align subgroup.normal.mem_comm_iff Subgroup.Normal.mem_comm_iff #align add_subgroup.normal.mem_comm_iff AddSubgroup.Normal.mem_comm_iff end Normal variable (H) /-- A subgroup is characteristic if it is fixed by all automorphisms. Several equivalent conditions are provided by lemmas of the form `Characteristic.iff...` -/ structure Characteristic : Prop where /-- `H` is fixed by all automorphisms -/ fixed : ∀ ϕ : G ≃* G, H.comap ϕ.toMonoidHom = H #align subgroup.characteristic Subgroup.Characteristic attribute [class] Characteristic instance (priority := 100) normal_of_characteristic [h : H.Characteristic] : H.Normal := ⟨fun a ha b => (SetLike.ext_iff.mp (h.fixed (MulAut.conj b)) a).mpr ha⟩ #align subgroup.normal_of_characteristic Subgroup.normal_of_characteristic end Subgroup namespace AddSubgroup variable (H : AddSubgroup A) /-- An `AddSubgroup` is characteristic if it is fixed by all automorphisms. Several equivalent conditions are provided by lemmas of the form `Characteristic.iff...` -/ structure Characteristic : Prop where /-- `H` is fixed by all automorphisms -/ fixed : ∀ ϕ : A ≃+ A, H.comap ϕ.toAddMonoidHom = H #align add_subgroup.characteristic AddSubgroup.Characteristic attribute [to_additive] Subgroup.Characteristic attribute [class] Characteristic instance (priority := 100) normal_of_characteristic [h : H.Characteristic] : H.Normal := ⟨fun a ha b => (SetLike.ext_iff.mp (h.fixed (AddAut.conj b)) a).mpr ha⟩ #align add_subgroup.normal_of_characteristic AddSubgroup.normal_of_characteristic end AddSubgroup namespace Subgroup variable {H K : Subgroup G} @[to_additive] theorem characteristic_iff_comap_eq : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.comap ϕ.toMonoidHom = H := ⟨Characteristic.fixed, Characteristic.mk⟩ #align subgroup.characteristic_iff_comap_eq Subgroup.characteristic_iff_comap_eq #align add_subgroup.characteristic_iff_comap_eq AddSubgroup.characteristic_iff_comap_eq @[to_additive] theorem characteristic_iff_comap_le : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.comap ϕ.toMonoidHom ≤ H := characteristic_iff_comap_eq.trans ⟨fun h ϕ => le_of_eq (h ϕ), fun h ϕ => le_antisymm (h ϕ) fun g hg => h ϕ.symm ((congr_arg (· ∈ H) (ϕ.symm_apply_apply g)).mpr hg)⟩ #align subgroup.characteristic_iff_comap_le Subgroup.characteristic_iff_comap_le #align add_subgroup.characteristic_iff_comap_le AddSubgroup.characteristic_iff_comap_le @[to_additive] theorem characteristic_iff_le_comap : H.Characteristic ↔ ∀ ϕ : G ≃* G, H ≤ H.comap ϕ.toMonoidHom := characteristic_iff_comap_eq.trans ⟨fun h ϕ => ge_of_eq (h ϕ), fun h ϕ => le_antisymm (fun g hg => (congr_arg (· ∈ H) (ϕ.symm_apply_apply g)).mp (h ϕ.symm hg)) (h ϕ)⟩ #align subgroup.characteristic_iff_le_comap Subgroup.characteristic_iff_le_comap #align add_subgroup.characteristic_iff_le_comap AddSubgroup.characteristic_iff_le_comap @[to_additive] theorem characteristic_iff_map_eq : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.map ϕ.toMonoidHom = H := by simp_rw [map_equiv_eq_comap_symm'] exact characteristic_iff_comap_eq.trans ⟨fun h ϕ => h ϕ.symm, fun h ϕ => h ϕ.symm⟩ #align subgroup.characteristic_iff_map_eq Subgroup.characteristic_iff_map_eq #align add_subgroup.characteristic_iff_map_eq AddSubgroup.characteristic_iff_map_eq @[to_additive] theorem characteristic_iff_map_le : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.map ϕ.toMonoidHom ≤ H := by simp_rw [map_equiv_eq_comap_symm'] exact characteristic_iff_comap_le.trans ⟨fun h ϕ => h ϕ.symm, fun h ϕ => h ϕ.symm⟩ #align subgroup.characteristic_iff_map_le Subgroup.characteristic_iff_map_le #align add_subgroup.characteristic_iff_map_le AddSubgroup.characteristic_iff_map_le @[to_additive] theorem characteristic_iff_le_map : H.Characteristic ↔ ∀ ϕ : G ≃* G, H ≤ H.map ϕ.toMonoidHom := by simp_rw [map_equiv_eq_comap_symm'] exact characteristic_iff_le_comap.trans ⟨fun h ϕ => h ϕ.symm, fun h ϕ => h ϕ.symm⟩ #align subgroup.characteristic_iff_le_map Subgroup.characteristic_iff_le_map #align add_subgroup.characteristic_iff_le_map AddSubgroup.characteristic_iff_le_map @[to_additive] instance botCharacteristic : Characteristic (⊥ : Subgroup G) := characteristic_iff_le_map.mpr fun _ϕ => bot_le #align subgroup.bot_characteristic Subgroup.botCharacteristic #align add_subgroup.bot_characteristic AddSubgroup.botCharacteristic @[to_additive] instance topCharacteristic : Characteristic (⊤ : Subgroup G) := characteristic_iff_map_le.mpr fun _ϕ => le_top #align subgroup.top_characteristic Subgroup.topCharacteristic #align add_subgroup.top_characteristic AddSubgroup.topCharacteristic variable (H) section Normalizer /-- The `normalizer` of `H` is the largest subgroup of `G` inside which `H` is normal. -/ @[to_additive "The `normalizer` of `H` is the largest subgroup of `G` inside which `H` is normal."] def normalizer : Subgroup G where carrier := { g : G | ∀ n, n ∈ H ↔ g * n * g⁻¹ ∈ H } one_mem' := by simp mul_mem' {a b} (ha : ∀ n, n ∈ H ↔ a * n * a⁻¹ ∈ H) (hb : ∀ n, n ∈ H ↔ b * n * b⁻¹ ∈ H) n := by rw [hb, ha] simp only [mul_assoc, mul_inv_rev] inv_mem' {a} (ha : ∀ n, n ∈ H ↔ a * n * a⁻¹ ∈ H) n := by rw [ha (a⁻¹ * n * a⁻¹⁻¹)] simp only [inv_inv, mul_assoc, mul_inv_cancel_left, mul_right_inv, mul_one] #align subgroup.normalizer Subgroup.normalizer #align add_subgroup.normalizer AddSubgroup.normalizer -- variant for sets. -- TODO should this replace `normalizer`? /-- The `setNormalizer` of `S` is the subgroup of `G` whose elements satisfy `g*S*g⁻¹=S` -/ @[to_additive "The `setNormalizer` of `S` is the subgroup of `G` whose elements satisfy `g+S-g=S`."] def setNormalizer (S : Set G) : Subgroup G where carrier := { g : G | ∀ n, n ∈ S ↔ g * n * g⁻¹ ∈ S } one_mem' := by simp mul_mem' {a b} (ha : ∀ n, n ∈ S ↔ a * n * a⁻¹ ∈ S) (hb : ∀ n, n ∈ S ↔ b * n * b⁻¹ ∈ S) n := by rw [hb, ha] simp only [mul_assoc, mul_inv_rev] inv_mem' {a} (ha : ∀ n, n ∈ S ↔ a * n * a⁻¹ ∈ S) n := by rw [ha (a⁻¹ * n * a⁻¹⁻¹)] simp only [inv_inv, mul_assoc, mul_inv_cancel_left, mul_right_inv, mul_one] #align subgroup.set_normalizer Subgroup.setNormalizer #align add_subgroup.set_normalizer AddSubgroup.setNormalizer variable {H} @[to_additive] theorem mem_normalizer_iff {g : G} : g ∈ H.normalizer ↔ ∀ h, h ∈ H ↔ g * h * g⁻¹ ∈ H := Iff.rfl #align subgroup.mem_normalizer_iff Subgroup.mem_normalizer_iff #align add_subgroup.mem_normalizer_iff AddSubgroup.mem_normalizer_iff @[to_additive] theorem mem_normalizer_iff'' {g : G} : g ∈ H.normalizer ↔ ∀ h : G, h ∈ H ↔ g⁻¹ * h * g ∈ H := by rw [← inv_mem_iff (x := g), mem_normalizer_iff, inv_inv] #align subgroup.mem_normalizer_iff'' Subgroup.mem_normalizer_iff'' #align add_subgroup.mem_normalizer_iff'' AddSubgroup.mem_normalizer_iff'' @[to_additive] theorem mem_normalizer_iff' {g : G} : g ∈ H.normalizer ↔ ∀ n, n * g ∈ H ↔ g * n ∈ H := ⟨fun h n => by rw [h, mul_assoc, mul_inv_cancel_right], fun h n => by rw [mul_assoc, ← h, inv_mul_cancel_right]⟩ #align subgroup.mem_normalizer_iff' Subgroup.mem_normalizer_iff' #align add_subgroup.mem_normalizer_iff' AddSubgroup.mem_normalizer_iff' @[to_additive] theorem le_normalizer : H ≤ normalizer H := fun x xH n => by rw [H.mul_mem_cancel_right (H.inv_mem xH), H.mul_mem_cancel_left xH] #align subgroup.le_normalizer Subgroup.le_normalizer #align add_subgroup.le_normalizer AddSubgroup.le_normalizer @[to_additive] instance (priority := 100) normal_in_normalizer : (H.subgroupOf H.normalizer).Normal := ⟨fun x xH g => by simpa only [mem_subgroupOf] using (g.2 x.1).1 xH⟩ #align subgroup.normal_in_normalizer Subgroup.normal_in_normalizer #align add_subgroup.normal_in_normalizer AddSubgroup.normal_in_normalizer @[to_additive] theorem normalizer_eq_top : H.normalizer = ⊤ ↔ H.Normal := eq_top_iff.trans ⟨fun h => ⟨fun a ha b => (h (mem_top b) a).mp ha⟩, fun h a _ha b => ⟨fun hb => h.conj_mem b hb a, fun hb => by rwa [h.mem_comm_iff, inv_mul_cancel_left] at hb⟩⟩ #align subgroup.normalizer_eq_top Subgroup.normalizer_eq_top #align add_subgroup.normalizer_eq_top AddSubgroup.normalizer_eq_top open scoped Classical @[to_additive] theorem le_normalizer_of_normal [hK : (H.subgroupOf K).Normal] (HK : H ≤ K) : K ≤ H.normalizer := fun x hx y => ⟨fun yH => hK.conj_mem ⟨y, HK yH⟩ yH ⟨x, hx⟩, fun yH => by simpa [mem_subgroupOf, mul_assoc] using hK.conj_mem ⟨x * y * x⁻¹, HK yH⟩ yH ⟨x⁻¹, K.inv_mem hx⟩⟩ #align subgroup.le_normalizer_of_normal Subgroup.le_normalizer_of_normal #align add_subgroup.le_normalizer_of_normal AddSubgroup.le_normalizer_of_normal variable {N : Type*} [Group N] /-- The preimage of the normalizer is contained in the normalizer of the preimage. -/ @[to_additive "The preimage of the normalizer is contained in the normalizer of the preimage."] theorem le_normalizer_comap (f : N →* G) : H.normalizer.comap f ≤ (H.comap f).normalizer := fun x => by simp only [mem_normalizer_iff, mem_comap] intro h n simp [h (f n)] #align subgroup.le_normalizer_comap Subgroup.le_normalizer_comap #align add_subgroup.le_normalizer_comap AddSubgroup.le_normalizer_comap /-- The image of the normalizer is contained in the normalizer of the image. -/ @[to_additive "The image of the normalizer is contained in the normalizer of the image."] theorem le_normalizer_map (f : G →* N) : H.normalizer.map f ≤ (H.map f).normalizer := fun _ => by simp only [and_imp, exists_prop, mem_map, exists_imp, mem_normalizer_iff] rintro x hx rfl n constructor · rintro ⟨y, hy, rfl⟩ use x * y * x⁻¹, (hx y).1 hy simp · rintro ⟨y, hyH, hy⟩ use x⁻¹ * y * x rw [hx] simp [hy, hyH, mul_assoc] #align subgroup.le_normalizer_map Subgroup.le_normalizer_map #align add_subgroup.le_normalizer_map AddSubgroup.le_normalizer_map variable (G) /-- Every proper subgroup `H` of `G` is a proper normal subgroup of the normalizer of `H` in `G`. -/ def _root_.NormalizerCondition := ∀ H : Subgroup G, H < ⊤ → H < normalizer H #align normalizer_condition NormalizerCondition variable {G} /-- Alternative phrasing of the normalizer condition: Only the full group is self-normalizing. This may be easier to work with, as it avoids inequalities and negations. -/ theorem _root_.normalizerCondition_iff_only_full_group_self_normalizing : NormalizerCondition G ↔ ∀ H : Subgroup G, H.normalizer = H → H = ⊤ := by apply forall_congr'; intro H simp only [lt_iff_le_and_ne, le_normalizer, true_and_iff, le_top, Ne] tauto #align normalizer_condition_iff_only_full_group_self_normalizing normalizerCondition_iff_only_full_group_self_normalizing variable (H) /-- In a group that satisfies the normalizer condition, every maximal subgroup is normal -/ theorem NormalizerCondition.normal_of_coatom (hnc : NormalizerCondition G) (hmax : IsCoatom H) : H.Normal := normalizer_eq_top.mp (hmax.2 _ (hnc H (lt_top_iff_ne_top.mpr hmax.1))) #align subgroup.normalizer_condition.normal_of_coatom Subgroup.NormalizerCondition.normal_of_coatom end Normalizer /-- Commutativity of a subgroup -/ structure IsCommutative : Prop where /-- `*` is commutative on `H` -/ is_comm : Std.Commutative (α := H) (· * ·) #align subgroup.is_commutative Subgroup.IsCommutative attribute [class] IsCommutative /-- Commutativity of an additive subgroup -/ structure _root_.AddSubgroup.IsCommutative (H : AddSubgroup A) : Prop where /-- `+` is commutative on `H` -/ is_comm : Std.Commutative (α := H) (· + ·) #align add_subgroup.is_commutative AddSubgroup.IsCommutative attribute [to_additive] Subgroup.IsCommutative attribute [class] AddSubgroup.IsCommutative /-- A commutative subgroup is commutative. -/ @[to_additive "A commutative subgroup is commutative."] instance IsCommutative.commGroup [h : H.IsCommutative] : CommGroup H := { H.toGroup with mul_comm := h.is_comm.comm } #align subgroup.is_commutative.comm_group Subgroup.IsCommutative.commGroup #align add_subgroup.is_commutative.add_comm_group AddSubgroup.IsCommutative.addCommGroup @[to_additive] instance map_isCommutative (f : G →* G') [H.IsCommutative] : (H.map f).IsCommutative := ⟨⟨by rintro ⟨-, a, ha, rfl⟩ ⟨-, b, hb, rfl⟩ rw [Subtype.ext_iff, coe_mul, coe_mul, Subtype.coe_mk, Subtype.coe_mk, ← map_mul, ← map_mul] exact congr_arg f (Subtype.ext_iff.mp (mul_comm (⟨a, ha⟩ : H) ⟨b, hb⟩))⟩⟩ #align subgroup.map_is_commutative Subgroup.map_isCommutative #align add_subgroup.map_is_commutative AddSubgroup.map_isCommutative @[to_additive] theorem comap_injective_isCommutative {f : G' →* G} (hf : Injective f) [H.IsCommutative] : (H.comap f).IsCommutative := ⟨⟨fun a b => Subtype.ext (by have := mul_comm (⟨f a, a.2⟩ : H) (⟨f b, b.2⟩ : H) rwa [Subtype.ext_iff, coe_mul, coe_mul, coe_mk, coe_mk, ← map_mul, ← map_mul, hf.eq_iff] at this)⟩⟩ #align subgroup.comap_injective_is_commutative Subgroup.comap_injective_isCommutative #align add_subgroup.comap_injective_is_commutative AddSubgroup.comap_injective_isCommutative @[to_additive] instance subgroupOf_isCommutative [H.IsCommutative] : (H.subgroupOf K).IsCommutative := H.comap_injective_isCommutative Subtype.coe_injective #align subgroup.subgroup_of_is_commutative Subgroup.subgroupOf_isCommutative #align add_subgroup.add_subgroup_of_is_commutative AddSubgroup.addSubgroupOf_isCommutative end Subgroup namespace MulEquiv variable {H : Type*} [Group H] /-- An isomorphism of groups gives an order isomorphism between the lattices of subgroups, defined by sending subgroups to their inverse images. See also `MulEquiv.mapSubgroup` which maps subgroups to their forward images. -/ @[simps] def comapSubgroup (f : G ≃* H) : Subgroup H ≃o Subgroup G where toFun := Subgroup.comap f invFun := Subgroup.comap f.symm left_inv sg := by simp [Subgroup.comap_comap] right_inv sh := by simp [Subgroup.comap_comap] map_rel_iff' {sg1 sg2} := ⟨fun h => by simpa [Subgroup.comap_comap] using Subgroup.comap_mono (f := (f.symm : H →* G)) h, Subgroup.comap_mono⟩ /-- An isomorphism of groups gives an order isomorphism between the lattices of subgroups, defined by sending subgroups to their forward images. See also `MulEquiv.comapSubgroup` which maps subgroups to their inverse images. -/ @[simps] def mapSubgroup {H : Type*} [Group H] (f : G ≃* H) : Subgroup G ≃o Subgroup H where toFun := Subgroup.map f invFun := Subgroup.map f.symm left_inv sg := by simp [Subgroup.map_map] right_inv sh := by simp [Subgroup.map_map] map_rel_iff' {sg1 sg2} := ⟨fun h => by simpa [Subgroup.map_map] using Subgroup.map_mono (f := (f.symm : H →* G)) h, Subgroup.map_mono⟩ @[simp] theorem isCoatom_comap {H : Type*} [Group H] (f : G ≃* H) {K : Subgroup H} : IsCoatom (Subgroup.comap (f : G →* H) K) ↔ IsCoatom K := OrderIso.isCoatom_iff (f.comapSubgroup) K @[simp] theorem isCoatom_map (f : G ≃* H) {K : Subgroup G} : IsCoatom (Subgroup.map (f : G →* H) K) ↔ IsCoatom K := OrderIso.isCoatom_iff (f.mapSubgroup) K end MulEquiv namespace Group variable {s : Set G} /-- Given a set `s`, `conjugatesOfSet s` is the set of all conjugates of the elements of `s`. -/ def conjugatesOfSet (s : Set G) : Set G := ⋃ a ∈ s, conjugatesOf a #align group.conjugates_of_set Group.conjugatesOfSet theorem mem_conjugatesOfSet_iff {x : G} : x ∈ conjugatesOfSet s ↔ ∃ a ∈ s, IsConj a x := by erw [Set.mem_iUnion₂]; simp only [conjugatesOf, isConj_iff, Set.mem_setOf_eq, exists_prop] #align group.mem_conjugates_of_set_iff Group.mem_conjugatesOfSet_iff theorem subset_conjugatesOfSet : s ⊆ conjugatesOfSet s := fun (x : G) (h : x ∈ s) => mem_conjugatesOfSet_iff.2 ⟨x, h, IsConj.refl _⟩ #align group.subset_conjugates_of_set Group.subset_conjugatesOfSet theorem conjugatesOfSet_mono {s t : Set G} (h : s ⊆ t) : conjugatesOfSet s ⊆ conjugatesOfSet t := Set.biUnion_subset_biUnion_left h #align group.conjugates_of_set_mono Group.conjugatesOfSet_mono theorem conjugates_subset_normal {N : Subgroup G} [tn : N.Normal] {a : G} (h : a ∈ N) : conjugatesOf a ⊆ N := by rintro a hc obtain ⟨c, rfl⟩ := isConj_iff.1 hc exact tn.conj_mem a h c #align group.conjugates_subset_normal Group.conjugates_subset_normal theorem conjugatesOfSet_subset {s : Set G} {N : Subgroup G} [N.Normal] (h : s ⊆ N) : conjugatesOfSet s ⊆ N := Set.iUnion₂_subset fun _x H => conjugates_subset_normal (h H) #align group.conjugates_of_set_subset Group.conjugatesOfSet_subset /-- The set of conjugates of `s` is closed under conjugation. -/ theorem conj_mem_conjugatesOfSet {x c : G} : x ∈ conjugatesOfSet s → c * x * c⁻¹ ∈ conjugatesOfSet s := fun H => by rcases mem_conjugatesOfSet_iff.1 H with ⟨a, h₁, h₂⟩ exact mem_conjugatesOfSet_iff.2 ⟨a, h₁, h₂.trans (isConj_iff.2 ⟨c, rfl⟩)⟩ #align group.conj_mem_conjugates_of_set Group.conj_mem_conjugatesOfSet end Group namespace Subgroup open Group variable {s : Set G} /-- The normal closure of a set `s` is the subgroup closure of all the conjugates of elements of `s`. It is the smallest normal subgroup containing `s`. -/ def normalClosure (s : Set G) : Subgroup G := closure (conjugatesOfSet s) #align subgroup.normal_closure Subgroup.normalClosure theorem conjugatesOfSet_subset_normalClosure : conjugatesOfSet s ⊆ normalClosure s := subset_closure #align subgroup.conjugates_of_set_subset_normal_closure Subgroup.conjugatesOfSet_subset_normalClosure theorem subset_normalClosure : s ⊆ normalClosure s := Set.Subset.trans subset_conjugatesOfSet conjugatesOfSet_subset_normalClosure #align subgroup.subset_normal_closure Subgroup.subset_normalClosure theorem le_normalClosure {H : Subgroup G} : H ≤ normalClosure ↑H := fun _ h => subset_normalClosure h #align subgroup.le_normal_closure Subgroup.le_normalClosure /-- The normal closure of `s` is a normal subgroup. -/ instance normalClosure_normal : (normalClosure s).Normal := ⟨fun n h g => by refine Subgroup.closure_induction h (fun x hx => ?_) ?_ (fun x y ihx ihy => ?_) fun x ihx => ?_ · exact conjugatesOfSet_subset_normalClosure (conj_mem_conjugatesOfSet hx) · simpa using (normalClosure s).one_mem · rw [← conj_mul] exact mul_mem ihx ihy · rw [← conj_inv] exact inv_mem ihx⟩ #align subgroup.normal_closure_normal Subgroup.normalClosure_normal /-- The normal closure of `s` is the smallest normal subgroup containing `s`. -/ theorem normalClosure_le_normal {N : Subgroup G} [N.Normal] (h : s ⊆ N) : normalClosure s ≤ N := by intro a w refine closure_induction w (fun x hx => ?_) ?_ (fun x y ihx ihy => ?_) fun x ihx => ?_ · exact conjugatesOfSet_subset h hx · exact one_mem _ · exact mul_mem ihx ihy · exact inv_mem ihx #align subgroup.normal_closure_le_normal Subgroup.normalClosure_le_normal theorem normalClosure_subset_iff {N : Subgroup G} [N.Normal] : s ⊆ N ↔ normalClosure s ≤ N := ⟨normalClosure_le_normal, Set.Subset.trans subset_normalClosure⟩ #align subgroup.normal_closure_subset_iff Subgroup.normalClosure_subset_iff theorem normalClosure_mono {s t : Set G} (h : s ⊆ t) : normalClosure s ≤ normalClosure t := normalClosure_le_normal (Set.Subset.trans h subset_normalClosure) #align subgroup.normal_closure_mono Subgroup.normalClosure_mono theorem normalClosure_eq_iInf : normalClosure s = ⨅ (N : Subgroup G) (_ : Normal N) (_ : s ⊆ N), N := le_antisymm (le_iInf fun N => le_iInf fun hN => le_iInf normalClosure_le_normal) (iInf_le_of_le (normalClosure s) (iInf_le_of_le (by infer_instance) (iInf_le_of_le subset_normalClosure le_rfl))) #align subgroup.normal_closure_eq_infi Subgroup.normalClosure_eq_iInf @[simp] theorem normalClosure_eq_self (H : Subgroup G) [H.Normal] : normalClosure ↑H = H := le_antisymm (normalClosure_le_normal rfl.subset) le_normalClosure #align subgroup.normal_closure_eq_self Subgroup.normalClosure_eq_self -- @[simp] -- Porting note (#10618): simp can prove this theorem normalClosure_idempotent : normalClosure ↑(normalClosure s) = normalClosure s := normalClosure_eq_self _ #align subgroup.normal_closure_idempotent Subgroup.normalClosure_idempotent theorem closure_le_normalClosure {s : Set G} : closure s ≤ normalClosure s := by simp only [subset_normalClosure, closure_le] #align subgroup.closure_le_normal_closure Subgroup.closure_le_normalClosure @[simp] theorem normalClosure_closure_eq_normalClosure {s : Set G} : normalClosure ↑(closure s) = normalClosure s := le_antisymm (normalClosure_le_normal closure_le_normalClosure) (normalClosure_mono subset_closure) #align subgroup.normal_closure_closure_eq_normal_closure Subgroup.normalClosure_closure_eq_normalClosure /-- The normal core of a subgroup `H` is the largest normal subgroup of `G` contained in `H`, as shown by `Subgroup.normalCore_eq_iSup`. -/ def normalCore (H : Subgroup G) : Subgroup G where carrier := { a : G | ∀ b : G, b * a * b⁻¹ ∈ H } one_mem' a := by rw [mul_one, mul_inv_self]; exact H.one_mem inv_mem' {a} h b := (congr_arg (· ∈ H) conj_inv).mp (H.inv_mem (h b)) mul_mem' {a b} ha hb c := (congr_arg (· ∈ H) conj_mul).mp (H.mul_mem (ha c) (hb c)) #align subgroup.normal_core Subgroup.normalCore theorem normalCore_le (H : Subgroup G) : H.normalCore ≤ H := fun a h => by rw [← mul_one a, ← inv_one, ← one_mul a] exact h 1 #align subgroup.normal_core_le Subgroup.normalCore_le instance normalCore_normal (H : Subgroup G) : H.normalCore.Normal := ⟨fun a h b c => by rw [mul_assoc, mul_assoc, ← mul_inv_rev, ← mul_assoc, ← mul_assoc]; exact h (c * b)⟩ #align subgroup.normal_core_normal Subgroup.normalCore_normal theorem normal_le_normalCore {H : Subgroup G} {N : Subgroup G} [hN : N.Normal] : N ≤ H.normalCore ↔ N ≤ H := ⟨ge_trans H.normalCore_le, fun h_le n hn g => h_le (hN.conj_mem n hn g)⟩ #align subgroup.normal_le_normal_core Subgroup.normal_le_normalCore theorem normalCore_mono {H K : Subgroup G} (h : H ≤ K) : H.normalCore ≤ K.normalCore := normal_le_normalCore.mpr (H.normalCore_le.trans h) #align subgroup.normal_core_mono Subgroup.normalCore_mono theorem normalCore_eq_iSup (H : Subgroup G) : H.normalCore = ⨆ (N : Subgroup G) (_ : Normal N) (_ : N ≤ H), N := le_antisymm (le_iSup_of_le H.normalCore (le_iSup_of_le H.normalCore_normal (le_iSup_of_le H.normalCore_le le_rfl))) (iSup_le fun _ => iSup_le fun _ => iSup_le normal_le_normalCore.mpr) #align subgroup.normal_core_eq_supr Subgroup.normalCore_eq_iSup @[simp] theorem normalCore_eq_self (H : Subgroup G) [H.Normal] : H.normalCore = H := le_antisymm H.normalCore_le (normal_le_normalCore.mpr le_rfl) #align subgroup.normal_core_eq_self Subgroup.normalCore_eq_self -- @[simp] -- Porting note (#10618): simp can prove this theorem normalCore_idempotent (H : Subgroup G) : H.normalCore.normalCore = H.normalCore := H.normalCore.normalCore_eq_self #align subgroup.normal_core_idempotent Subgroup.normalCore_idempotent end Subgroup namespace MonoidHom variable {N : Type*} {P : Type*} [Group N] [Group P] (K : Subgroup G) open Subgroup /-- The range of a monoid homomorphism from a group is a subgroup. -/ @[to_additive "The range of an `AddMonoidHom` from an `AddGroup` is an `AddSubgroup`."] def range (f : G →* N) : Subgroup N := Subgroup.copy ((⊤ : Subgroup G).map f) (Set.range f) (by simp [Set.ext_iff]) #align monoid_hom.range MonoidHom.range #align add_monoid_hom.range AddMonoidHom.range @[to_additive (attr := simp)] theorem coe_range (f : G →* N) : (f.range : Set N) = Set.range f := rfl #align monoid_hom.coe_range MonoidHom.coe_range #align add_monoid_hom.coe_range AddMonoidHom.coe_range @[to_additive (attr := simp)] theorem mem_range {f : G →* N} {y : N} : y ∈ f.range ↔ ∃ x, f x = y := Iff.rfl #align monoid_hom.mem_range MonoidHom.mem_range #align add_monoid_hom.mem_range AddMonoidHom.mem_range @[to_additive] theorem range_eq_map (f : G →* N) : f.range = (⊤ : Subgroup G).map f := by ext; simp #align monoid_hom.range_eq_map MonoidHom.range_eq_map #align add_monoid_hom.range_eq_map AddMonoidHom.range_eq_map @[to_additive (attr := simp)] theorem restrict_range (f : G →* N) : (f.restrict K).range = K.map f := by simp_rw [SetLike.ext_iff, mem_range, mem_map, restrict_apply, SetLike.exists, exists_prop, forall_const] #align monoid_hom.restrict_range MonoidHom.restrict_range #align add_monoid_hom.restrict_range AddMonoidHom.restrict_range /-- The canonical surjective group homomorphism `G →* f(G)` induced by a group homomorphism `G →* N`. -/ @[to_additive "The canonical surjective `AddGroup` homomorphism `G →+ f(G)` induced by a group homomorphism `G →+ N`."] def rangeRestrict (f : G →* N) : G →* f.range := codRestrict f _ fun x => ⟨x, rfl⟩ #align monoid_hom.range_restrict MonoidHom.rangeRestrict #align add_monoid_hom.range_restrict AddMonoidHom.rangeRestrict @[to_additive (attr := simp)] theorem coe_rangeRestrict (f : G →* N) (g : G) : (f.rangeRestrict g : N) = f g := rfl #align monoid_hom.coe_range_restrict MonoidHom.coe_rangeRestrict #align add_monoid_hom.coe_range_restrict AddMonoidHom.coe_rangeRestrict @[to_additive] theorem coe_comp_rangeRestrict (f : G →* N) : ((↑) : f.range → N) ∘ (⇑f.rangeRestrict : G → f.range) = f := rfl #align monoid_hom.coe_comp_range_restrict MonoidHom.coe_comp_rangeRestrict #align add_monoid_hom.coe_comp_range_restrict AddMonoidHom.coe_comp_rangeRestrict @[to_additive] theorem subtype_comp_rangeRestrict (f : G →* N) : f.range.subtype.comp f.rangeRestrict = f := ext <| f.coe_rangeRestrict #align monoid_hom.subtype_comp_range_restrict MonoidHom.subtype_comp_rangeRestrict #align add_monoid_hom.subtype_comp_range_restrict AddMonoidHom.subtype_comp_rangeRestrict @[to_additive] theorem rangeRestrict_surjective (f : G →* N) : Function.Surjective f.rangeRestrict := fun ⟨_, g, rfl⟩ => ⟨g, rfl⟩ #align monoid_hom.range_restrict_surjective MonoidHom.rangeRestrict_surjective #align add_monoid_hom.range_restrict_surjective AddMonoidHom.rangeRestrict_surjective @[to_additive (attr := simp)] lemma rangeRestrict_injective_iff {f : G →* N} : Injective f.rangeRestrict ↔ Injective f := by convert Set.injective_codRestrict _ @[to_additive] theorem map_range (g : N →* P) (f : G →* N) : f.range.map g = (g.comp f).range := by rw [range_eq_map, range_eq_map]; exact (⊤ : Subgroup G).map_map g f #align monoid_hom.map_range MonoidHom.map_range #align add_monoid_hom.map_range AddMonoidHom.map_range @[to_additive] theorem range_top_iff_surjective {N} [Group N] {f : G →* N} : f.range = (⊤ : Subgroup N) ↔ Function.Surjective f := SetLike.ext'_iff.trans <| Iff.trans (by rw [coe_range, coe_top]) Set.range_iff_surjective #align monoid_hom.range_top_iff_surjective MonoidHom.range_top_iff_surjective #align add_monoid_hom.range_top_iff_surjective AddMonoidHom.range_top_iff_surjective /-- The range of a surjective monoid homomorphism is the whole of the codomain. -/ @[to_additive (attr := simp) "The range of a surjective `AddMonoid` homomorphism is the whole of the codomain."] theorem range_top_of_surjective {N} [Group N] (f : G →* N) (hf : Function.Surjective f) : f.range = (⊤ : Subgroup N) := range_top_iff_surjective.2 hf #align monoid_hom.range_top_of_surjective MonoidHom.range_top_of_surjective #align add_monoid_hom.range_top_of_surjective AddMonoidHom.range_top_of_surjective @[to_additive (attr := simp)] theorem range_one : (1 : G →* N).range = ⊥ := SetLike.ext fun x => by simpa using @comm _ (· = ·) _ 1 x #align monoid_hom.range_one MonoidHom.range_one #align add_monoid_hom.range_zero AddMonoidHom.range_zero @[to_additive (attr := simp)] theorem _root_.Subgroup.subtype_range (H : Subgroup G) : H.subtype.range = H := by rw [range_eq_map, ← SetLike.coe_set_eq, coe_map, Subgroup.coeSubtype] ext simp #align subgroup.subtype_range Subgroup.subtype_range #align add_subgroup.subtype_range AddSubgroup.subtype_range @[to_additive (attr := simp)] theorem _root_.Subgroup.inclusion_range {H K : Subgroup G} (h_le : H ≤ K) : (inclusion h_le).range = H.subgroupOf K := Subgroup.ext fun g => Set.ext_iff.mp (Set.range_inclusion h_le) g #align subgroup.inclusion_range Subgroup.inclusion_range #align add_subgroup.inclusion_range AddSubgroup.inclusion_range @[to_additive] theorem subgroupOf_range_eq_of_le {G₁ G₂ : Type*} [Group G₁] [Group G₂] {K : Subgroup G₂} (f : G₁ →* G₂) (h : f.range ≤ K) : f.range.subgroupOf K = (f.codRestrict K fun x => h ⟨x, rfl⟩).range := by ext k refine exists_congr ?_ simp [Subtype.ext_iff] #align monoid_hom.subgroup_of_range_eq_of_le MonoidHom.subgroupOf_range_eq_of_le #align add_monoid_hom.add_subgroup_of_range_eq_of_le AddMonoidHom.addSubgroupOf_range_eq_of_le @[simp] theorem coe_toAdditive_range (f : G →* G') : (MonoidHom.toAdditive f).range = Subgroup.toAddSubgroup f.range := rfl @[simp] theorem coe_toMultiplicative_range {A A' : Type*} [AddGroup A] [AddGroup A'] (f : A →+ A') : (AddMonoidHom.toMultiplicative f).range = AddSubgroup.toSubgroup f.range := rfl /-- Computable alternative to `MonoidHom.ofInjective`. -/ @[to_additive "Computable alternative to `AddMonoidHom.ofInjective`."] def ofLeftInverse {f : G →* N} {g : N →* G} (h : Function.LeftInverse g f) : G ≃* f.range := { f.rangeRestrict with toFun := f.rangeRestrict invFun := g ∘ f.range.subtype left_inv := h right_inv := by rintro ⟨x, y, rfl⟩ apply Subtype.ext rw [coe_rangeRestrict, Function.comp_apply, Subgroup.coeSubtype, Subtype.coe_mk, h] } #align monoid_hom.of_left_inverse MonoidHom.ofLeftInverse #align add_monoid_hom.of_left_inverse AddMonoidHom.ofLeftInverse @[to_additive (attr := simp)] theorem ofLeftInverse_apply {f : G →* N} {g : N →* G} (h : Function.LeftInverse g f) (x : G) : ↑(ofLeftInverse h x) = f x := rfl #align monoid_hom.of_left_inverse_apply MonoidHom.ofLeftInverse_apply #align add_monoid_hom.of_left_inverse_apply AddMonoidHom.ofLeftInverse_apply @[to_additive (attr := simp)] theorem ofLeftInverse_symm_apply {f : G →* N} {g : N →* G} (h : Function.LeftInverse g f) (x : f.range) : (ofLeftInverse h).symm x = g x := rfl #align monoid_hom.of_left_inverse_symm_apply MonoidHom.ofLeftInverse_symm_apply #align add_monoid_hom.of_left_inverse_symm_apply AddMonoidHom.ofLeftInverse_symm_apply /-- The range of an injective group homomorphism is isomorphic to its domain. -/ @[to_additive "The range of an injective additive group homomorphism is isomorphic to its domain."] noncomputable def ofInjective {f : G →* N} (hf : Function.Injective f) : G ≃* f.range := MulEquiv.ofBijective (f.codRestrict f.range fun x => ⟨x, rfl⟩) ⟨fun x y h => hf (Subtype.ext_iff.mp h), by rintro ⟨x, y, rfl⟩ exact ⟨y, rfl⟩⟩ #align monoid_hom.of_injective MonoidHom.ofInjective #align add_monoid_hom.of_injective AddMonoidHom.ofInjective @[to_additive] theorem ofInjective_apply {f : G →* N} (hf : Function.Injective f) {x : G} : ↑(ofInjective hf x) = f x := rfl #align monoid_hom.of_injective_apply MonoidHom.ofInjective_apply #align add_monoid_hom.of_injective_apply AddMonoidHom.ofInjective_apply @[to_additive (attr := simp)] theorem apply_ofInjective_symm {f : G →* N} (hf : Function.Injective f) (x : f.range) : f ((ofInjective hf).symm x) = x := Subtype.ext_iff.1 <| (ofInjective hf).apply_symm_apply x section Ker variable {M : Type*} [MulOneClass M] /-- The multiplicative kernel of a monoid homomorphism is the subgroup of elements `x : G` such that `f x = 1` -/ @[to_additive "The additive kernel of an `AddMonoid` homomorphism is the `AddSubgroup` of elements such that `f x = 0`"] def ker (f : G →* M) : Subgroup G := { MonoidHom.mker f with inv_mem' := fun {x} (hx : f x = 1) => calc f x⁻¹ = f x * f x⁻¹ := by rw [hx, one_mul] _ = 1 := by rw [← map_mul, mul_inv_self, map_one] } #align monoid_hom.ker MonoidHom.ker #align add_monoid_hom.ker AddMonoidHom.ker @[to_additive] theorem mem_ker (f : G →* M) {x : G} : x ∈ f.ker ↔ f x = 1 := Iff.rfl #align monoid_hom.mem_ker MonoidHom.mem_ker #align add_monoid_hom.mem_ker AddMonoidHom.mem_ker @[to_additive] theorem coe_ker (f : G →* M) : (f.ker : Set G) = (f : G → M) ⁻¹' {1} := rfl #align monoid_hom.coe_ker MonoidHom.coe_ker #align add_monoid_hom.coe_ker AddMonoidHom.coe_ker @[to_additive (attr := simp)] theorem ker_toHomUnits {M} [Monoid M] (f : G →* M) : f.toHomUnits.ker = f.ker := by ext x simp [mem_ker, Units.ext_iff] #align monoid_hom.ker_to_hom_units MonoidHom.ker_toHomUnits #align add_monoid_hom.ker_to_hom_add_units AddMonoidHom.ker_toHomAddUnits @[to_additive]
Mathlib/Algebra/Group/Subgroup/Basic.lean
2,709
2,712
theorem eq_iff (f : G →* M) {x y : G} : f x = f y ↔ y⁻¹ * x ∈ f.ker := by
constructor <;> intro h · rw [mem_ker, map_mul, h, ← map_mul, inv_mul_self, map_one] · rw [← one_mul x, ← mul_inv_self y, mul_assoc, map_mul, f.mem_ker.1 h, mul_one]
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Algebra.Hom #align_import algebra.hom.non_unital_alg from "leanprover-community/mathlib"@"bd9851ca476957ea4549eb19b40e7b5ade9428cc" /-! # Morphisms of non-unital algebras This file defines morphisms between two types, each of which carries: * an addition, * an additive zero, * a multiplication, * a scalar action. The multiplications are not assumed to be associative or unital, or even to be compatible with the scalar actions. In a typical application, the operations will satisfy compatibility conditions making them into algebras (albeit possibly non-associative and/or non-unital) but such conditions are not required to make this definition. This notion of morphism should be useful for any category of non-unital algebras. The motivating application at the time it was introduced was to be able to state the adjunction property for magma algebras. These are non-unital, non-associative algebras obtained by applying the group-algebra construction except where we take a type carrying just `Mul` instead of `Group`. For a plausible future application, one could take the non-unital algebra of compactly-supported functions on a non-compact topological space. A proper map between a pair of such spaces (contravariantly) induces a morphism between their algebras of compactly-supported functions which will be a `NonUnitalAlgHom`. TODO: add `NonUnitalAlgEquiv` when needed. ## Main definitions * `NonUnitalAlgHom` * `AlgHom.toNonUnitalAlgHom` ## Tags non-unital, algebra, morphism -/ universe u u₁ v w w₁ w₂ w₃ variable {R : Type u} {S : Type u₁} /-- A morphism respecting addition, multiplication, and scalar multiplication. When these arise from algebra structures, this is the same as a not-necessarily-unital morphism of algebras. -/ structure NonUnitalAlgHom [Monoid R] [Monoid S] (φ : R →* S) (A : Type v) (B : Type w) [NonUnitalNonAssocSemiring A] [DistribMulAction R A] [NonUnitalNonAssocSemiring B] [DistribMulAction S B] extends A →ₑ+[φ] B, A →ₙ* B #align non_unital_alg_hom NonUnitalAlgHom @[inherit_doc NonUnitalAlgHom] infixr:25 " →ₙₐ " => NonUnitalAlgHom _ @[inherit_doc] notation:25 A " →ₛₙₐ[" φ "] " B => NonUnitalAlgHom φ A B @[inherit_doc] notation:25 A " →ₙₐ[" R "] " B => NonUnitalAlgHom (MonoidHom.id R) A B attribute [nolint docBlame] NonUnitalAlgHom.toMulHom /-- `NonUnitalAlgSemiHomClass F φ A B` asserts `F` is a type of bundled algebra homomorphisms from `A` to `B` which are equivariant with respect to `φ`. -/ class NonUnitalAlgSemiHomClass (F : Type*) {R S : outParam Type*} [Monoid R] [Monoid S] (φ : outParam (R →* S)) (A B : outParam Type*) [NonUnitalNonAssocSemiring A] [NonUnitalNonAssocSemiring B] [DistribMulAction R A] [DistribMulAction S B] [FunLike F A B] extends DistribMulActionSemiHomClass F φ A B, MulHomClass F A B : Prop #align non_unital_alg_hom_class NonUnitalAlgSemiHomClass /-- `NonUnitalAlgHomClass F R A B` asserts `F` is a type of bundled algebra homomorphisms from `A` to `B` which are `R`-linear. This is an abbreviation to `NonUnitalAlgSemiHomClass F (MonoidHom.id R) A B` -/ abbrev NonUnitalAlgHomClass (F : Type*) (R A B : outParam Type*) [Monoid R] [NonUnitalNonAssocSemiring A] [NonUnitalNonAssocSemiring B] [DistribMulAction R A] [DistribMulAction R B] [FunLike F A B] := NonUnitalAlgSemiHomClass F (MonoidHom.id R) A B -- Porting note: commented out, not dangerous -- attribute [nolint dangerousInstance] NonUnitalAlgHomClass.toMulHomClass namespace NonUnitalAlgHomClass -- Porting note: Made following instance non-dangerous through [...] -> [...] replacement -- See note [lower instance priority] instance (priority := 100) toNonUnitalRingHomClass {F R S A B : Type*} {_ : Monoid R} {_ : Monoid S} {φ : outParam (R →* S)} {_ : NonUnitalNonAssocSemiring A} [DistribMulAction R A] {_ : NonUnitalNonAssocSemiring B} [DistribMulAction S B] [FunLike F A B] [NonUnitalAlgSemiHomClass F φ A B] : NonUnitalRingHomClass F A B := { ‹NonUnitalAlgSemiHomClass F φ A B› with } #align non_unital_alg_hom_class.non_unital_alg_hom_class.to_non_unital_ring_hom_class NonUnitalAlgHomClass.toNonUnitalRingHomClass variable [Semiring R] [Semiring S] {φ : R →+* S} {A B : Type*} [NonUnitalNonAssocSemiring A] [Module R A] [NonUnitalNonAssocSemiring B] [Module S B] -- see Note [lower instance priority] instance (priority := 100) {F R S A B : Type*} {_ : Semiring R} {_ : Semiring S} {φ : R →+* S} {_ : NonUnitalSemiring A} {_ : NonUnitalSemiring B} [Module R A] [Module S B] [FunLike F A B] [NonUnitalAlgSemiHomClass (R := R) (S := S) F φ A B] : SemilinearMapClass F φ A B := { ‹NonUnitalAlgSemiHomClass F φ A B› with map_smulₛₗ := map_smulₛₗ } instance (priority := 100) {F : Type*} [FunLike F A B] [Module R B] [NonUnitalAlgHomClass F R A B] : LinearMapClass F R A B := { ‹NonUnitalAlgHomClass F R A B› with map_smulₛₗ := map_smulₛₗ } /-- Turn an element of a type `F` satisfying `NonUnitalAlgSemiHomClass F φ A B` into an actual `NonUnitalAlgHom`. This is declared as the default coercion from `F` to `A →ₛₙₐ[φ] B`. -/ @[coe] def toNonUnitalAlgSemiHom {F R S : Type*} [Monoid R] [Monoid S] {φ : R →* S} {A B : Type*} [NonUnitalNonAssocSemiring A] [DistribMulAction R A] [NonUnitalNonAssocSemiring B] [DistribMulAction S B] [FunLike F A B] [NonUnitalAlgSemiHomClass F φ A B] (f : F) : A →ₛₙₐ[φ] B := { (f : A →ₙ+* B) with toFun := f map_smul' := map_smulₛₗ f } instance {F R S A B : Type*} [Monoid R] [Monoid S] {φ : R →* S} [NonUnitalNonAssocSemiring A] [DistribMulAction R A] [NonUnitalNonAssocSemiring B] [DistribMulAction S B] [FunLike F A B] [NonUnitalAlgSemiHomClass F φ A B] : CoeTC F (A →ₛₙₐ[φ] B) := ⟨toNonUnitalAlgSemiHom⟩ /-- Turn an element of a type `F` satisfying `NonUnitalAlgHomClass F R A B` into an actual @[coe] `NonUnitalAlgHom`. This is declared as the default coercion from `F` to `A →ₛₙₐ[R] B`. -/ def toNonUnitalAlgHom {F R : Type*} [Monoid R] {A B : Type*} [NonUnitalNonAssocSemiring A] [DistribMulAction R A] [NonUnitalNonAssocSemiring B] [DistribMulAction R B] [FunLike F A B] [NonUnitalAlgHomClass F R A B] (f : F) : A →ₙₐ[R] B := { (f : A →ₙ+* B) with toFun := f map_smul' := map_smulₛₗ f } instance {F R : Type*} [Monoid R] {A B : Type*} [NonUnitalNonAssocSemiring A] [DistribMulAction R A] [NonUnitalNonAssocSemiring B] [DistribMulAction R B] [FunLike F A B] [NonUnitalAlgHomClass F R A B] : CoeTC F (A →ₙₐ[R] B) := ⟨toNonUnitalAlgHom⟩ end NonUnitalAlgHomClass namespace NonUnitalAlgHom variable {T : Type*} [Monoid R] [Monoid S] [Monoid T] (φ : R →* S) variable (A : Type v) (B : Type w) (C : Type w₁) variable [NonUnitalNonAssocSemiring A] [DistribMulAction R A] variable [NonUnitalNonAssocSemiring B] [DistribMulAction S B] variable [NonUnitalNonAssocSemiring C] [DistribMulAction T C] -- Porting note: Replaced with DFunLike instance -- /-- see Note [function coercion] -/ -- instance : CoeFun (A →ₙₐ[R] B) fun _ => A → B := -- ⟨toFun⟩ instance : DFunLike (A →ₛₙₐ[φ] B) A fun _ => B where coe f := f.toFun coe_injective' := by rintro ⟨⟨⟨f, _⟩, _⟩, _⟩ ⟨⟨⟨g, _⟩, _⟩, _⟩ h; congr @[simp] theorem toFun_eq_coe (f : A →ₛₙₐ[φ] B) : f.toFun = ⇑f := rfl #align non_unital_alg_hom.to_fun_eq_coe NonUnitalAlgHom.toFun_eq_coe /-- See Note [custom simps projection] -/ def Simps.apply (f : A →ₛₙₐ[φ] B) : A → B := f initialize_simps_projections NonUnitalAlgHom (toDistribMulActionHom_toMulActionHom_toFun → apply, -toDistribMulActionHom) variable {φ A B C} @[simp] protected theorem coe_coe {F : Type*} [FunLike F A B] [NonUnitalAlgSemiHomClass F φ A B] (f : F) : ⇑(f : A →ₛₙₐ[φ] B) = f := rfl #align non_unital_alg_hom.coe_coe NonUnitalAlgHom.coe_coe theorem coe_injective : @Function.Injective (A →ₛₙₐ[φ] B) (A → B) (↑) := by rintro ⟨⟨⟨f, _⟩, _⟩, _⟩ ⟨⟨⟨g, _⟩, _⟩, _⟩ h; congr #align non_unital_alg_hom.coe_injective NonUnitalAlgHom.coe_injective instance : FunLike (A →ₛₙₐ[φ] B) A B where coe f := f.toFun coe_injective' := coe_injective instance : NonUnitalAlgSemiHomClass (A →ₛₙₐ[φ] B) φ A B where map_add f := f.map_add' map_zero f := f.map_zero' map_mul f := f.map_mul' map_smulₛₗ f := f.map_smul' @[ext] theorem ext {f g : A →ₛₙₐ[φ] B} (h : ∀ x, f x = g x) : f = g := coe_injective <| funext h #align non_unital_alg_hom.ext NonUnitalAlgHom.ext theorem ext_iff {f g : A →ₛₙₐ[φ] B} : f = g ↔ ∀ x, f x = g x := ⟨by rintro rfl x rfl, ext⟩ #align non_unital_alg_hom.ext_iff NonUnitalAlgHom.ext_iff theorem congr_fun {f g : A →ₛₙₐ[φ] B} (h : f = g) (x : A) : f x = g x := h ▸ rfl #align non_unital_alg_hom.congr_fun NonUnitalAlgHom.congr_fun @[simp] theorem coe_mk (f : A → B) (h₁ h₂ h₃ h₄) : ⇑(⟨⟨⟨f, h₁⟩, h₂, h₃⟩, h₄⟩ : A →ₛₙₐ[φ] B) = f := rfl #align non_unital_alg_hom.coe_mk NonUnitalAlgHom.coe_mk @[simp] theorem mk_coe (f : A →ₛₙₐ[φ] B) (h₁ h₂ h₃ h₄) : (⟨⟨⟨f, h₁⟩, h₂, h₃⟩, h₄⟩ : A →ₛₙₐ[φ] B) = f := by rfl #align non_unital_alg_hom.mk_coe NonUnitalAlgHom.mk_coe instance : CoeOut (A →ₛₙₐ[φ] B) (A →ₑ+[φ] B) := ⟨toDistribMulActionHom⟩ instance : CoeOut (A →ₛₙₐ[φ] B) (A →ₙ* B) := ⟨toMulHom⟩ @[simp] theorem toDistribMulActionHom_eq_coe (f : A →ₛₙₐ[φ] B) : f.toDistribMulActionHom = ↑f := rfl #align non_unital_alg_hom.to_distrib_mul_action_hom_eq_coe NonUnitalAlgHom.toDistribMulActionHom_eq_coe @[simp] theorem toMulHom_eq_coe (f : A →ₛₙₐ[φ] B) : f.toMulHom = ↑f := rfl #align non_unital_alg_hom.to_mul_hom_eq_coe NonUnitalAlgHom.toMulHom_eq_coe @[simp, norm_cast] theorem coe_to_distribMulActionHom (f : A →ₛₙₐ[φ] B) : ⇑(f : A →ₑ+[φ] B) = f := rfl #align non_unital_alg_hom.coe_to_distrib_mul_action_hom NonUnitalAlgHom.coe_to_distribMulActionHom @[simp, norm_cast] theorem coe_to_mulHom (f : A →ₛₙₐ[φ] B) : ⇑(f : A →ₙ* B) = f := rfl #align non_unital_alg_hom.coe_to_mul_hom NonUnitalAlgHom.coe_to_mulHom
Mathlib/Algebra/Algebra/NonUnitalHom.lean
257
260
theorem to_distribMulActionHom_injective {f g : A →ₛₙₐ[φ] B} (h : (f : A →ₑ+[φ] B) = (g : A →ₑ+[φ] B)) : f = g := by
ext a exact DistribMulActionHom.congr_fun h a
/- Copyright (c) 2018 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Simon Hudon -/ import Mathlib.Control.Functor.Multivariate import Mathlib.Data.PFunctor.Univariate.Basic #align_import data.pfunctor.multivariate.basic from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multivariate polynomial functors. Multivariate polynomial functors are used for defining M-types and W-types. They map a type vector `α` to the type `Σ a : A, B a ⟹ α`, with `A : Type` and `B : A → TypeVec n`. They interact well with Lean's inductive definitions because they guarantee that occurrences of `α` are positive. -/ universe u v open MvFunctor /-- multivariate polynomial functors -/ @[pp_with_univ] structure MvPFunctor (n : ℕ) where /-- The head type -/ A : Type u /-- The child family of types -/ B : A → TypeVec.{u} n #align mvpfunctor MvPFunctor namespace MvPFunctor open MvFunctor (LiftP LiftR) variable {n m : ℕ} (P : MvPFunctor.{u} n) /-- Applying `P` to an object of `Type` -/ @[coe] def Obj (α : TypeVec.{u} n) : Type u := Σ a : P.A, P.B a ⟹ α #align mvpfunctor.obj MvPFunctor.Obj instance : CoeFun (MvPFunctor.{u} n) (fun _ => TypeVec.{u} n → Type u) where coe := Obj /-- Applying `P` to a morphism of `Type` -/ def map {α β : TypeVec n} (f : α ⟹ β) : P α → P β := fun ⟨a, g⟩ => ⟨a, TypeVec.comp f g⟩ #align mvpfunctor.map MvPFunctor.map instance : Inhabited (MvPFunctor n) := ⟨⟨default, default⟩⟩ instance Obj.inhabited {α : TypeVec n} [Inhabited P.A] [∀ i, Inhabited (α i)] : Inhabited (P α) := ⟨⟨default, fun _ _ => default⟩⟩ #align mvpfunctor.obj.inhabited MvPFunctor.Obj.inhabited instance : MvFunctor.{u} P.Obj := ⟨@MvPFunctor.map n P⟩ theorem map_eq {α β : TypeVec n} (g : α ⟹ β) (a : P.A) (f : P.B a ⟹ α) : @MvFunctor.map _ P.Obj _ _ _ g ⟨a, f⟩ = ⟨a, g ⊚ f⟩ := rfl #align mvpfunctor.map_eq MvPFunctor.map_eq theorem id_map {α : TypeVec n} : ∀ x : P α, TypeVec.id <$$> x = x | ⟨_, _⟩ => rfl #align mvpfunctor.id_map MvPFunctor.id_map theorem comp_map {α β γ : TypeVec n} (f : α ⟹ β) (g : β ⟹ γ) : ∀ x : P α, (g ⊚ f) <$$> x = g <$$> f <$$> x | ⟨_, _⟩ => rfl #align mvpfunctor.comp_map MvPFunctor.comp_map instance : LawfulMvFunctor.{u} P.Obj where id_map := @id_map _ P comp_map := @comp_map _ P /-- Constant functor where the input object does not affect the output -/ def const (n : ℕ) (A : Type u) : MvPFunctor n := { A B := fun _ _ => PEmpty } #align mvpfunctor.const MvPFunctor.const section Const variable (n) {A : Type u} {α β : TypeVec.{u} n} /-- Constructor for the constant functor -/ def const.mk (x : A) {α} : const n A α := ⟨x, fun _ a => PEmpty.elim a⟩ #align mvpfunctor.const.mk MvPFunctor.const.mk variable {n} /-- Destructor for the constant functor -/ def const.get (x : const n A α) : A := x.1 #align mvpfunctor.const.get MvPFunctor.const.get @[simp] theorem const.get_map (f : α ⟹ β) (x : const n A α) : const.get (f <$$> x) = const.get x := by cases x rfl #align mvpfunctor.const.get_map MvPFunctor.const.get_map @[simp] theorem const.get_mk (x : A) : const.get (const.mk n x : const n A α) = x := rfl #align mvpfunctor.const.get_mk MvPFunctor.const.get_mk @[simp] theorem const.mk_get (x : const n A α) : const.mk n (const.get x) = x := by cases x dsimp [const.get, const.mk] congr with (_⟨⟩) #align mvpfunctor.const.mk_get MvPFunctor.const.mk_get end Const /-- Functor composition on polynomial functors -/ def comp (P : MvPFunctor.{u} n) (Q : Fin2 n → MvPFunctor.{u} m) : MvPFunctor m where A := Σ a₂ : P.1, ∀ i, P.2 a₂ i → (Q i).1 B a i := Σ(j : _) (b : P.2 a.1 j), (Q j).2 (a.snd j b) i #align mvpfunctor.comp MvPFunctor.comp variable {P} {Q : Fin2 n → MvPFunctor.{u} m} {α β : TypeVec.{u} m} /-- Constructor for functor composition -/ def comp.mk (x : P (fun i => Q i α)) : comp P Q α := ⟨⟨x.1, fun _ a => (x.2 _ a).1⟩, fun i a => (x.snd a.fst a.snd.fst).snd i a.snd.snd⟩ #align mvpfunctor.comp.mk MvPFunctor.comp.mk /-- Destructor for functor composition -/ def comp.get (x : comp P Q α) : P (fun i => Q i α) := ⟨x.1.1, fun i a => ⟨x.fst.snd i a, fun (j : Fin2 m) (b : (Q i).B _ j) => x.snd j ⟨i, ⟨a, b⟩⟩⟩⟩ #align mvpfunctor.comp.get MvPFunctor.comp.get theorem comp.get_map (f : α ⟹ β) (x : comp P Q α) : comp.get (f <$$> x) = (fun i (x : Q i α) => f <$$> x) <$$> comp.get x := by rfl #align mvpfunctor.comp.get_map MvPFunctor.comp.get_map @[simp] theorem comp.get_mk (x : P (fun i => Q i α)) : comp.get (comp.mk x) = x := by rfl #align mvpfunctor.comp.get_mk MvPFunctor.comp.get_mk @[simp] theorem comp.mk_get (x : comp P Q α) : comp.mk (comp.get x) = x := by rfl #align mvpfunctor.comp.mk_get MvPFunctor.comp.mk_get /- lifting predicates and relations -/ theorem liftP_iff {α : TypeVec n} (p : ∀ ⦃i⦄, α i → Prop) (x : P α) : LiftP p x ↔ ∃ a f, x = ⟨a, f⟩ ∧ ∀ i j, p (f i j) := by constructor · rintro ⟨y, hy⟩ cases' h : y with a f refine ⟨a, fun i j => (f i j).val, ?_, fun i j => (f i j).property⟩ rw [← hy, h, map_eq] rfl rintro ⟨a, f, xeq, pf⟩ use ⟨a, fun i j => ⟨f i j, pf i j⟩⟩ rw [xeq]; rfl #align mvpfunctor.liftp_iff MvPFunctor.liftP_iff theorem liftP_iff' {α : TypeVec n} (p : ∀ ⦃i⦄, α i → Prop) (a : P.A) (f : P.B a ⟹ α) : @LiftP.{u} _ P.Obj _ α p ⟨a, f⟩ ↔ ∀ i x, p (f i x) := by simp only [liftP_iff, Sigma.mk.inj_iff]; constructor · rintro ⟨_, _, ⟨⟩, _⟩ assumption · intro repeat' first |constructor|assumption #align mvpfunctor.liftp_iff' MvPFunctor.liftP_iff' theorem liftR_iff {α : TypeVec n} (r : ∀ ⦃i⦄, α i → α i → Prop) (x y : P α) : LiftR @r x y ↔ ∃ a f₀ f₁, x = ⟨a, f₀⟩ ∧ y = ⟨a, f₁⟩ ∧ ∀ i j, r (f₀ i j) (f₁ i j) := by constructor · rintro ⟨u, xeq, yeq⟩ cases' h : u with a f use a, fun i j => (f i j).val.fst, fun i j => (f i j).val.snd constructor · rw [← xeq, h] rfl constructor · rw [← yeq, h] rfl intro i j exact (f i j).property rintro ⟨a, f₀, f₁, xeq, yeq, h⟩ use ⟨a, fun i j => ⟨(f₀ i j, f₁ i j), h i j⟩⟩ dsimp; constructor · rw [xeq] rfl rw [yeq]; rfl #align mvpfunctor.liftr_iff MvPFunctor.liftR_iff open Set MvFunctor
Mathlib/Data/PFunctor/Multivariate/Basic.lean
206
217
theorem supp_eq {α : TypeVec n} (a : P.A) (f : P.B a ⟹ α) (i) : @supp.{u} _ P.Obj _ α (⟨a, f⟩ : P α) i = f i '' univ := by
ext x; simp only [supp, image_univ, mem_range, mem_setOf_eq] constructor <;> intro h · apply @h fun i x => ∃ y : P.B a i, f i y = x rw [liftP_iff'] intros exact ⟨_, rfl⟩ · simp only [liftP_iff'] cases h subst x tauto
/- Copyright (c) 2021 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Gabin Kolly -/ import Mathlib.Order.Closure import Mathlib.ModelTheory.Semantics import Mathlib.ModelTheory.Encoding #align_import model_theory.substructures from "leanprover-community/mathlib"@"0602c59878ff3d5f71dea69c2d32ccf2e93e5398" /-! # First-Order Substructures This file defines substructures of first-order structures in a similar manner to the various substructures appearing in the algebra library. ## Main Definitions * A `FirstOrder.Language.Substructure` is defined so that `L.Substructure M` is the type of all substructures of the `L`-structure `M`. * `FirstOrder.Language.Substructure.closure` is defined so that if `s : Set M`, `closure L s` is the least substructure of `M` containing `s`. * `FirstOrder.Language.Substructure.comap` is defined so that `s.comap f` is the preimage of the substructure `s` under the homomorphism `f`, as a substructure. * `FirstOrder.Language.Substructure.map` is defined so that `s.map f` is the image of the substructure `s` under the homomorphism `f`, as a substructure. * `FirstOrder.Language.Hom.range` is defined so that `f.range` is the range of the homomorphism `f`, as a substructure. * `FirstOrder.Language.Hom.domRestrict` and `FirstOrder.Language.Hom.codRestrict` restrict the domain and codomain respectively of first-order homomorphisms to substructures. * `FirstOrder.Language.Embedding.domRestrict` and `FirstOrder.Language.Embedding.codRestrict` restrict the domain and codomain respectively of first-order embeddings to substructures. * `FirstOrder.Language.Substructure.inclusion` is the inclusion embedding between substructures. ## Main Results * `L.Substructure M` forms a `CompleteLattice`. -/ universe u v w namespace FirstOrder namespace Language variable {L : Language.{u, v}} {M : Type w} {N P : Type*} variable [L.Structure M] [L.Structure N] [L.Structure P] open FirstOrder Cardinal open Structure Cardinal section ClosedUnder open Set variable {n : ℕ} (f : L.Functions n) (s : Set M) /-- Indicates that a set in a given structure is a closed under a function symbol. -/ def ClosedUnder : Prop := ∀ x : Fin n → M, (∀ i : Fin n, x i ∈ s) → funMap f x ∈ s #align first_order.language.closed_under FirstOrder.Language.ClosedUnder variable (L) @[simp] theorem closedUnder_univ : ClosedUnder f (univ : Set M) := fun _ _ => mem_univ _ #align first_order.language.closed_under_univ FirstOrder.Language.closedUnder_univ variable {L f s} {t : Set M} namespace ClosedUnder theorem inter (hs : ClosedUnder f s) (ht : ClosedUnder f t) : ClosedUnder f (s ∩ t) := fun x h => mem_inter (hs x fun i => mem_of_mem_inter_left (h i)) (ht x fun i => mem_of_mem_inter_right (h i)) #align first_order.language.closed_under.inter FirstOrder.Language.ClosedUnder.inter theorem inf (hs : ClosedUnder f s) (ht : ClosedUnder f t) : ClosedUnder f (s ⊓ t) := hs.inter ht #align first_order.language.closed_under.inf FirstOrder.Language.ClosedUnder.inf variable {S : Set (Set M)} theorem sInf (hS : ∀ s, s ∈ S → ClosedUnder f s) : ClosedUnder f (sInf S) := fun x h s hs => hS s hs x fun i => h i s hs #align first_order.language.closed_under.Inf FirstOrder.Language.ClosedUnder.sInf end ClosedUnder end ClosedUnder variable (L) (M) /-- A substructure of a structure `M` is a set closed under application of function symbols. -/ structure Substructure where carrier : Set M fun_mem : ∀ {n}, ∀ f : L.Functions n, ClosedUnder f carrier #align first_order.language.substructure FirstOrder.Language.Substructure #align first_order.language.substructure.carrier FirstOrder.Language.Substructure.carrier #align first_order.language.substructure.fun_mem FirstOrder.Language.Substructure.fun_mem variable {L} {M} namespace Substructure attribute [coe] Substructure.carrier instance instSetLike : SetLike (L.Substructure M) M := ⟨Substructure.carrier, fun p q h => by cases p; cases q; congr⟩ #align first_order.language.substructure.set_like FirstOrder.Language.Substructure.instSetLike /-- See Note [custom simps projection] -/ def Simps.coe (S : L.Substructure M) : Set M := S #align first_order.language.substructure.simps.coe FirstOrder.Language.Substructure.Simps.coe initialize_simps_projections Substructure (carrier → coe) @[simp] theorem mem_carrier {s : L.Substructure M} {x : M} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl #align first_order.language.substructure.mem_carrier FirstOrder.Language.Substructure.mem_carrier /-- Two substructures are equal if they have the same elements. -/ @[ext] theorem ext {S T : L.Substructure M} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h #align first_order.language.substructure.ext FirstOrder.Language.Substructure.ext /-- Copy a substructure replacing `carrier` with a set that is equal to it. -/ protected def copy (S : L.Substructure M) (s : Set M) (hs : s = S) : L.Substructure M where carrier := s fun_mem _ f := hs.symm ▸ S.fun_mem _ f #align first_order.language.substructure.copy FirstOrder.Language.Substructure.copy end Substructure variable {S : L.Substructure M} theorem Term.realize_mem {α : Type*} (t : L.Term α) (xs : α → M) (h : ∀ a, xs a ∈ S) : t.realize xs ∈ S := by induction' t with a n f ts ih · exact h a · exact Substructure.fun_mem _ _ _ ih #align first_order.language.term.realize_mem FirstOrder.Language.Term.realize_mem namespace Substructure @[simp] theorem coe_copy {s : Set M} (hs : s = S) : (S.copy s hs : Set M) = s := rfl #align first_order.language.substructure.coe_copy FirstOrder.Language.Substructure.coe_copy theorem copy_eq {s : Set M} (hs : s = S) : S.copy s hs = S := SetLike.coe_injective hs #align first_order.language.substructure.copy_eq FirstOrder.Language.Substructure.copy_eq theorem constants_mem (c : L.Constants) : (c : M) ∈ S := mem_carrier.2 (S.fun_mem c _ finZeroElim) #align first_order.language.substructure.constants_mem FirstOrder.Language.Substructure.constants_mem /-- The substructure `M` of the structure `M`. -/ instance instTop : Top (L.Substructure M) := ⟨{ carrier := Set.univ fun_mem := fun {_} _ _ _ => Set.mem_univ _ }⟩ #align first_order.language.substructure.has_top FirstOrder.Language.Substructure.instTop instance instInhabited : Inhabited (L.Substructure M) := ⟨⊤⟩ #align first_order.language.substructure.inhabited FirstOrder.Language.Substructure.instInhabited @[simp] theorem mem_top (x : M) : x ∈ (⊤ : L.Substructure M) := Set.mem_univ x #align first_order.language.substructure.mem_top FirstOrder.Language.Substructure.mem_top @[simp] theorem coe_top : ((⊤ : L.Substructure M) : Set M) = Set.univ := rfl #align first_order.language.substructure.coe_top FirstOrder.Language.Substructure.coe_top /-- The inf of two substructures is their intersection. -/ instance instInf : Inf (L.Substructure M) := ⟨fun S₁ S₂ => { carrier := (S₁ : Set M) ∩ (S₂ : Set M) fun_mem := fun {_} f => (S₁.fun_mem f).inf (S₂.fun_mem f) }⟩ #align first_order.language.substructure.has_inf FirstOrder.Language.Substructure.instInf @[simp] theorem coe_inf (p p' : L.Substructure M) : ((p ⊓ p' : L.Substructure M) : Set M) = (p : Set M) ∩ (p' : Set M) := rfl #align first_order.language.substructure.coe_inf FirstOrder.Language.Substructure.coe_inf @[simp] theorem mem_inf {p p' : L.Substructure M} {x : M} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' := Iff.rfl #align first_order.language.substructure.mem_inf FirstOrder.Language.Substructure.mem_inf instance instInfSet : InfSet (L.Substructure M) := ⟨fun s => { carrier := ⋂ t ∈ s, (t : Set M) fun_mem := fun {n} f => ClosedUnder.sInf (by rintro _ ⟨t, rfl⟩ by_cases h : t ∈ s · simpa [h] using t.fun_mem f · simp [h]) }⟩ #align first_order.language.substructure.has_Inf FirstOrder.Language.Substructure.instInfSet @[simp, norm_cast] theorem coe_sInf (S : Set (L.Substructure M)) : ((sInf S : L.Substructure M) : Set M) = ⋂ s ∈ S, (s : Set M) := rfl #align first_order.language.substructure.coe_Inf FirstOrder.Language.Substructure.coe_sInf theorem mem_sInf {S : Set (L.Substructure M)} {x : M} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := Set.mem_iInter₂ #align first_order.language.substructure.mem_Inf FirstOrder.Language.Substructure.mem_sInf theorem mem_iInf {ι : Sort*} {S : ι → L.Substructure M} {x : M} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by simp only [iInf, mem_sInf, Set.forall_mem_range] #align first_order.language.substructure.mem_infi FirstOrder.Language.Substructure.mem_iInf @[simp, norm_cast] theorem coe_iInf {ι : Sort*} {S : ι → L.Substructure M} : ((⨅ i, S i : L.Substructure M) : Set M) = ⋂ i, (S i : Set M) := by simp only [iInf, coe_sInf, Set.biInter_range] #align first_order.language.substructure.coe_infi FirstOrder.Language.Substructure.coe_iInf /-- Substructures of a structure form a complete lattice. -/ instance instCompleteLattice : CompleteLattice (L.Substructure M) := { completeLatticeOfInf (L.Substructure M) fun _ => IsGLB.of_image (fun {S T : L.Substructure M} => show (S : Set M) ≤ T ↔ S ≤ T from SetLike.coe_subset_coe) isGLB_biInf with le := (· ≤ ·) lt := (· < ·) top := ⊤ le_top := fun _ x _ => mem_top x inf := (· ⊓ ·) sInf := InfSet.sInf le_inf := fun _a _b _c ha hb _x hx => ⟨ha hx, hb hx⟩ inf_le_left := fun _ _ _ => And.left inf_le_right := fun _ _ _ => And.right } #align first_order.language.substructure.complete_lattice FirstOrder.Language.Substructure.instCompleteLattice variable (L) /-- The `L.Substructure` generated by a set. -/ def closure : LowerAdjoint ((↑) : L.Substructure M → Set M) := ⟨fun s => sInf { S | s ⊆ S }, fun _ _ => ⟨Set.Subset.trans fun _x hx => mem_sInf.2 fun _S hS => hS hx, fun h => sInf_le h⟩⟩ #align first_order.language.substructure.closure FirstOrder.Language.Substructure.closure variable {L} {s : Set M} theorem mem_closure {x : M} : x ∈ closure L s ↔ ∀ S : L.Substructure M, s ⊆ S → x ∈ S := mem_sInf #align first_order.language.substructure.mem_closure FirstOrder.Language.Substructure.mem_closure /-- The substructure generated by a set includes the set. -/ @[simp] theorem subset_closure : s ⊆ closure L s := (closure L).le_closure s #align first_order.language.substructure.subset_closure FirstOrder.Language.Substructure.subset_closure theorem not_mem_of_not_mem_closure {P : M} (hP : P ∉ closure L s) : P ∉ s := fun h => hP (subset_closure h) #align first_order.language.substructure.not_mem_of_not_mem_closure FirstOrder.Language.Substructure.not_mem_of_not_mem_closure @[simp] theorem closed (S : L.Substructure M) : (closure L).closed (S : Set M) := congr rfl ((closure L).eq_of_le Set.Subset.rfl fun _x xS => mem_closure.2 fun _T hT => hT xS) #align first_order.language.substructure.closed FirstOrder.Language.Substructure.closed open Set /-- A substructure `S` includes `closure L s` if and only if it includes `s`. -/ @[simp] theorem closure_le : closure L s ≤ S ↔ s ⊆ S := (closure L).closure_le_closed_iff_le s S.closed #align first_order.language.substructure.closure_le FirstOrder.Language.Substructure.closure_le /-- Substructure closure of a set is monotone in its argument: if `s ⊆ t`, then `closure L s ≤ closure L t`. -/ theorem closure_mono ⦃s t : Set M⦄ (h : s ⊆ t) : closure L s ≤ closure L t := (closure L).monotone h #align first_order.language.substructure.closure_mono FirstOrder.Language.Substructure.closure_mono theorem closure_eq_of_le (h₁ : s ⊆ S) (h₂ : S ≤ closure L s) : closure L s = S := (closure L).eq_of_le h₁ h₂ #align first_order.language.substructure.closure_eq_of_le FirstOrder.Language.Substructure.closure_eq_of_le theorem coe_closure_eq_range_term_realize : (closure L s : Set M) = range (@Term.realize L _ _ _ ((↑) : s → M)) := by let S : L.Substructure M := ⟨range (Term.realize (L := L) ((↑) : s → M)), fun {n} f x hx => by simp only [mem_range] at * refine ⟨func f fun i => Classical.choose (hx i), ?_⟩ simp only [Term.realize, fun i => Classical.choose_spec (hx i)]⟩ change _ = (S : Set M) rw [← SetLike.ext'_iff] refine closure_eq_of_le (fun x hx => ⟨var ⟨x, hx⟩, rfl⟩) (le_sInf fun S' hS' => ?_) rintro _ ⟨t, rfl⟩ exact t.realize_mem _ fun i => hS' i.2 #align first_order.language.substructure.coe_closure_eq_range_term_realize FirstOrder.Language.Substructure.coe_closure_eq_range_term_realize instance small_closure [Small.{u} s] : Small.{u} (closure L s) := by rw [← SetLike.coe_sort_coe, Substructure.coe_closure_eq_range_term_realize] exact small_range _ #align first_order.language.substructure.small_closure FirstOrder.Language.Substructure.small_closure theorem mem_closure_iff_exists_term {x : M} : x ∈ closure L s ↔ ∃ t : L.Term s, t.realize ((↑) : s → M) = x := by rw [← SetLike.mem_coe, coe_closure_eq_range_term_realize, mem_range] #align first_order.language.substructure.mem_closure_iff_exists_term FirstOrder.Language.Substructure.mem_closure_iff_exists_term theorem lift_card_closure_le_card_term : Cardinal.lift.{max u w} #(closure L s) ≤ #(L.Term s) := by rw [← SetLike.coe_sort_coe, coe_closure_eq_range_term_realize] rw [← Cardinal.lift_id'.{w, max u w} #(L.Term s)] exact Cardinal.mk_range_le_lift #align first_order.language.substructure.lift_card_closure_le_card_term FirstOrder.Language.Substructure.lift_card_closure_le_card_term theorem lift_card_closure_le : Cardinal.lift.{u, w} #(closure L s) ≤ max ℵ₀ (Cardinal.lift.{u, w} #s + Cardinal.lift.{w, u} #(Σi, L.Functions i)) := by rw [← lift_umax] refine lift_card_closure_le_card_term.trans (Term.card_le.trans ?_) rw [mk_sum, lift_umax.{w, u}] #align first_order.language.substructure.lift_card_closure_le FirstOrder.Language.Substructure.lift_card_closure_le variable (L) theorem _root_.Set.Countable.substructure_closure [Countable (Σl, L.Functions l)] (h : s.Countable) : Countable.{w + 1} (closure L s) := by haveI : Countable s := h.to_subtype rw [← mk_le_aleph0_iff, ← lift_le_aleph0] exact lift_card_closure_le_card_term.trans mk_le_aleph0 #align set.countable.substructure_closure Set.Countable.substructure_closure variable {L} (S) /-- An induction principle for closure membership. If `p` holds for all elements of `s`, and is preserved under function symbols, then `p` holds for all elements of the closure of `s`. -/ @[elab_as_elim] theorem closure_induction {p : M → Prop} {x} (h : x ∈ closure L s) (Hs : ∀ x ∈ s, p x) (Hfun : ∀ {n : ℕ} (f : L.Functions n), ClosedUnder f (setOf p)) : p x := (@closure_le L M _ ⟨setOf p, fun {_} => Hfun⟩ _).2 Hs h #align first_order.language.substructure.closure_induction FirstOrder.Language.Substructure.closure_induction /-- If `s` is a dense set in a structure `M`, `Substructure.closure L s = ⊤`, then in order to prove that some predicate `p` holds for all `x : M` it suffices to verify `p x` for `x ∈ s`, and verify that `p` is preserved under function symbols. -/ @[elab_as_elim] theorem dense_induction {p : M → Prop} (x : M) {s : Set M} (hs : closure L s = ⊤) (Hs : ∀ x ∈ s, p x) (Hfun : ∀ {n : ℕ} (f : L.Functions n), ClosedUnder f (setOf p)) : p x := by have : ∀ x ∈ closure L s, p x := fun x hx => closure_induction hx Hs fun {n} => Hfun simpa [hs] using this x #align first_order.language.substructure.dense_induction FirstOrder.Language.Substructure.dense_induction variable (L) (M) /-- `closure` forms a Galois insertion with the coercion to set. -/ protected def gi : GaloisInsertion (@closure L M _) (↑) where choice s _ := closure L s gc := (closure L).gc le_l_u _ := subset_closure choice_eq _ _ := rfl #align first_order.language.substructure.gi FirstOrder.Language.Substructure.gi variable {L} {M} /-- Closure of a substructure `S` equals `S`. -/ @[simp] theorem closure_eq : closure L (S : Set M) = S := (Substructure.gi L M).l_u_eq S #align first_order.language.substructure.closure_eq FirstOrder.Language.Substructure.closure_eq @[simp] theorem closure_empty : closure L (∅ : Set M) = ⊥ := (Substructure.gi L M).gc.l_bot #align first_order.language.substructure.closure_empty FirstOrder.Language.Substructure.closure_empty @[simp] theorem closure_univ : closure L (univ : Set M) = ⊤ := @coe_top L M _ ▸ closure_eq ⊤ #align first_order.language.substructure.closure_univ FirstOrder.Language.Substructure.closure_univ theorem closure_union (s t : Set M) : closure L (s ∪ t) = closure L s ⊔ closure L t := (Substructure.gi L M).gc.l_sup #align first_order.language.substructure.closure_union FirstOrder.Language.Substructure.closure_union theorem closure_unionᵢ {ι} (s : ι → Set M) : closure L (⋃ i, s i) = ⨆ i, closure L (s i) := (Substructure.gi L M).gc.l_iSup #align first_order.language.substructure.closure_Union FirstOrder.Language.Substructure.closure_unionᵢ instance small_bot : Small.{u} (⊥ : L.Substructure M) := by rw [← closure_empty] haveI : Small.{u} (∅ : Set M) := small_subsingleton _ exact Substructure.small_closure #align first_order.language.substructure.small_bot FirstOrder.Language.Substructure.small_bot /-! ### `comap` and `map` -/ /-- The preimage of a substructure along a homomorphism is a substructure. -/ @[simps] def comap (φ : M →[L] N) (S : L.Substructure N) : L.Substructure M where carrier := φ ⁻¹' S fun_mem {n} f x hx := by rw [mem_preimage, φ.map_fun] exact S.fun_mem f (φ ∘ x) hx #align first_order.language.substructure.comap FirstOrder.Language.Substructure.comap #align first_order.language.substructure.comap_coe FirstOrder.Language.Substructure.comap_coe @[simp] theorem mem_comap {S : L.Substructure N} {f : M →[L] N} {x : M} : x ∈ S.comap f ↔ f x ∈ S := Iff.rfl #align first_order.language.substructure.mem_comap FirstOrder.Language.Substructure.mem_comap theorem comap_comap (S : L.Substructure P) (g : N →[L] P) (f : M →[L] N) : (S.comap g).comap f = S.comap (g.comp f) := rfl #align first_order.language.substructure.comap_comap FirstOrder.Language.Substructure.comap_comap @[simp] theorem comap_id (S : L.Substructure P) : S.comap (Hom.id _ _) = S := ext (by simp) #align first_order.language.substructure.comap_id FirstOrder.Language.Substructure.comap_id /-- The image of a substructure along a homomorphism is a substructure. -/ @[simps] def map (φ : M →[L] N) (S : L.Substructure M) : L.Substructure N where carrier := φ '' S fun_mem {n} f x hx := (mem_image _ _ _).1 ⟨funMap f fun i => Classical.choose (hx i), S.fun_mem f _ fun i => (Classical.choose_spec (hx i)).1, by simp only [Hom.map_fun, SetLike.mem_coe] exact congr rfl (funext fun i => (Classical.choose_spec (hx i)).2)⟩ #align first_order.language.substructure.map FirstOrder.Language.Substructure.map #align first_order.language.substructure.map_coe FirstOrder.Language.Substructure.map_coe @[simp] theorem mem_map {f : M →[L] N} {S : L.Substructure M} {y : N} : y ∈ S.map f ↔ ∃ x ∈ S, f x = y := Iff.rfl #align first_order.language.substructure.mem_map FirstOrder.Language.Substructure.mem_map theorem mem_map_of_mem (f : M →[L] N) {S : L.Substructure M} {x : M} (hx : x ∈ S) : f x ∈ S.map f := mem_image_of_mem f hx #align first_order.language.substructure.mem_map_of_mem FirstOrder.Language.Substructure.mem_map_of_mem theorem apply_coe_mem_map (f : M →[L] N) (S : L.Substructure M) (x : S) : f x ∈ S.map f := mem_map_of_mem f x.prop #align first_order.language.substructure.apply_coe_mem_map FirstOrder.Language.Substructure.apply_coe_mem_map theorem map_map (g : N →[L] P) (f : M →[L] N) : (S.map f).map g = S.map (g.comp f) := SetLike.coe_injective <| image_image _ _ _ #align first_order.language.substructure.map_map FirstOrder.Language.Substructure.map_map theorem map_le_iff_le_comap {f : M →[L] N} {S : L.Substructure M} {T : L.Substructure N} : S.map f ≤ T ↔ S ≤ T.comap f := image_subset_iff #align first_order.language.substructure.map_le_iff_le_comap FirstOrder.Language.Substructure.map_le_iff_le_comap theorem gc_map_comap (f : M →[L] N) : GaloisConnection (map f) (comap f) := fun _ _ => map_le_iff_le_comap #align first_order.language.substructure.gc_map_comap FirstOrder.Language.Substructure.gc_map_comap theorem map_le_of_le_comap {T : L.Substructure N} {f : M →[L] N} : S ≤ T.comap f → S.map f ≤ T := (gc_map_comap f).l_le #align first_order.language.substructure.map_le_of_le_comap FirstOrder.Language.Substructure.map_le_of_le_comap theorem le_comap_of_map_le {T : L.Substructure N} {f : M →[L] N} : S.map f ≤ T → S ≤ T.comap f := (gc_map_comap f).le_u #align first_order.language.substructure.le_comap_of_map_le FirstOrder.Language.Substructure.le_comap_of_map_le theorem le_comap_map {f : M →[L] N} : S ≤ (S.map f).comap f := (gc_map_comap f).le_u_l _ #align first_order.language.substructure.le_comap_map FirstOrder.Language.Substructure.le_comap_map theorem map_comap_le {S : L.Substructure N} {f : M →[L] N} : (S.comap f).map f ≤ S := (gc_map_comap f).l_u_le _ #align first_order.language.substructure.map_comap_le FirstOrder.Language.Substructure.map_comap_le theorem monotone_map {f : M →[L] N} : Monotone (map f) := (gc_map_comap f).monotone_l #align first_order.language.substructure.monotone_map FirstOrder.Language.Substructure.monotone_map theorem monotone_comap {f : M →[L] N} : Monotone (comap f) := (gc_map_comap f).monotone_u #align first_order.language.substructure.monotone_comap FirstOrder.Language.Substructure.monotone_comap @[simp] theorem map_comap_map {f : M →[L] N} : ((S.map f).comap f).map f = S.map f := (gc_map_comap f).l_u_l_eq_l _ #align first_order.language.substructure.map_comap_map FirstOrder.Language.Substructure.map_comap_map @[simp] theorem comap_map_comap {S : L.Substructure N} {f : M →[L] N} : ((S.comap f).map f).comap f = S.comap f := (gc_map_comap f).u_l_u_eq_u _ #align first_order.language.substructure.comap_map_comap FirstOrder.Language.Substructure.comap_map_comap theorem map_sup (S T : L.Substructure M) (f : M →[L] N) : (S ⊔ T).map f = S.map f ⊔ T.map f := (gc_map_comap f).l_sup #align first_order.language.substructure.map_sup FirstOrder.Language.Substructure.map_sup theorem map_iSup {ι : Sort*} (f : M →[L] N) (s : ι → L.Substructure M) : (iSup s).map f = ⨆ i, (s i).map f := (gc_map_comap f).l_iSup #align first_order.language.substructure.map_supr FirstOrder.Language.Substructure.map_iSup theorem comap_inf (S T : L.Substructure N) (f : M →[L] N) : (S ⊓ T).comap f = S.comap f ⊓ T.comap f := (gc_map_comap f).u_inf #align first_order.language.substructure.comap_inf FirstOrder.Language.Substructure.comap_inf theorem comap_iInf {ι : Sort*} (f : M →[L] N) (s : ι → L.Substructure N) : (iInf s).comap f = ⨅ i, (s i).comap f := (gc_map_comap f).u_iInf #align first_order.language.substructure.comap_infi FirstOrder.Language.Substructure.comap_iInf @[simp] theorem map_bot (f : M →[L] N) : (⊥ : L.Substructure M).map f = ⊥ := (gc_map_comap f).l_bot #align first_order.language.substructure.map_bot FirstOrder.Language.Substructure.map_bot @[simp] theorem comap_top (f : M →[L] N) : (⊤ : L.Substructure N).comap f = ⊤ := (gc_map_comap f).u_top #align first_order.language.substructure.comap_top FirstOrder.Language.Substructure.comap_top @[simp] theorem map_id (S : L.Substructure M) : S.map (Hom.id L M) = S := ext fun _ => ⟨fun ⟨_, h, rfl⟩ => h, fun h => ⟨_, h, rfl⟩⟩ #align first_order.language.substructure.map_id FirstOrder.Language.Substructure.map_id theorem map_closure (f : M →[L] N) (s : Set M) : (closure L s).map f = closure L (f '' s) := Eq.symm <| closure_eq_of_le (Set.image_subset f subset_closure) <| map_le_iff_le_comap.2 <| closure_le.2 fun x hx => subset_closure ⟨x, hx, rfl⟩ #align first_order.language.substructure.map_closure FirstOrder.Language.Substructure.map_closure @[simp] theorem closure_image (f : M →[L] N) : closure L (f '' s) = map f (closure L s) := (map_closure f s).symm #align first_order.language.substructure.closure_image FirstOrder.Language.Substructure.closure_image section GaloisCoinsertion variable {ι : Type*} {f : M →[L] N} (hf : Function.Injective f) /-- `map f` and `comap f` form a `GaloisCoinsertion` when `f` is injective. -/ def gciMapComap : GaloisCoinsertion (map f) (comap f) := (gc_map_comap f).toGaloisCoinsertion fun S x => by simp [mem_comap, mem_map, hf.eq_iff] #align first_order.language.substructure.gci_map_comap FirstOrder.Language.Substructure.gciMapComap theorem comap_map_eq_of_injective (S : L.Substructure M) : (S.map f).comap f = S := (gciMapComap hf).u_l_eq _ #align first_order.language.substructure.comap_map_eq_of_injective FirstOrder.Language.Substructure.comap_map_eq_of_injective theorem comap_surjective_of_injective : Function.Surjective (comap f) := (gciMapComap hf).u_surjective #align first_order.language.substructure.comap_surjective_of_injective FirstOrder.Language.Substructure.comap_surjective_of_injective theorem map_injective_of_injective : Function.Injective (map f) := (gciMapComap hf).l_injective #align first_order.language.substructure.map_injective_of_injective FirstOrder.Language.Substructure.map_injective_of_injective theorem comap_inf_map_of_injective (S T : L.Substructure M) : (S.map f ⊓ T.map f).comap f = S ⊓ T := (gciMapComap hf).u_inf_l _ _ #align first_order.language.substructure.comap_inf_map_of_injective FirstOrder.Language.Substructure.comap_inf_map_of_injective theorem comap_iInf_map_of_injective (S : ι → L.Substructure M) : (⨅ i, (S i).map f).comap f = iInf S := (gciMapComap hf).u_iInf_l _ #align first_order.language.substructure.comap_infi_map_of_injective FirstOrder.Language.Substructure.comap_iInf_map_of_injective theorem comap_sup_map_of_injective (S T : L.Substructure M) : (S.map f ⊔ T.map f).comap f = S ⊔ T := (gciMapComap hf).u_sup_l _ _ #align first_order.language.substructure.comap_sup_map_of_injective FirstOrder.Language.Substructure.comap_sup_map_of_injective theorem comap_iSup_map_of_injective (S : ι → L.Substructure M) : (⨆ i, (S i).map f).comap f = iSup S := (gciMapComap hf).u_iSup_l _ #align first_order.language.substructure.comap_supr_map_of_injective FirstOrder.Language.Substructure.comap_iSup_map_of_injective theorem map_le_map_iff_of_injective {S T : L.Substructure M} : S.map f ≤ T.map f ↔ S ≤ T := (gciMapComap hf).l_le_l_iff #align first_order.language.substructure.map_le_map_iff_of_injective FirstOrder.Language.Substructure.map_le_map_iff_of_injective theorem map_strictMono_of_injective : StrictMono (map f) := (gciMapComap hf).strictMono_l #align first_order.language.substructure.map_strict_mono_of_injective FirstOrder.Language.Substructure.map_strictMono_of_injective end GaloisCoinsertion section GaloisInsertion variable {ι : Type*} {f : M →[L] N} (hf : Function.Surjective f) /-- `map f` and `comap f` form a `GaloisInsertion` when `f` is surjective. -/ def giMapComap : GaloisInsertion (map f) (comap f) := (gc_map_comap f).toGaloisInsertion fun S x h => let ⟨y, hy⟩ := hf x mem_map.2 ⟨y, by simp [hy, h]⟩ #align first_order.language.substructure.gi_map_comap FirstOrder.Language.Substructure.giMapComap theorem map_comap_eq_of_surjective (S : L.Substructure N) : (S.comap f).map f = S := (giMapComap hf).l_u_eq _ #align first_order.language.substructure.map_comap_eq_of_surjective FirstOrder.Language.Substructure.map_comap_eq_of_surjective theorem map_surjective_of_surjective : Function.Surjective (map f) := (giMapComap hf).l_surjective #align first_order.language.substructure.map_surjective_of_surjective FirstOrder.Language.Substructure.map_surjective_of_surjective theorem comap_injective_of_surjective : Function.Injective (comap f) := (giMapComap hf).u_injective #align first_order.language.substructure.comap_injective_of_surjective FirstOrder.Language.Substructure.comap_injective_of_surjective theorem map_inf_comap_of_surjective (S T : L.Substructure N) : (S.comap f ⊓ T.comap f).map f = S ⊓ T := (giMapComap hf).l_inf_u _ _ #align first_order.language.substructure.map_inf_comap_of_surjective FirstOrder.Language.Substructure.map_inf_comap_of_surjective theorem map_iInf_comap_of_surjective (S : ι → L.Substructure N) : (⨅ i, (S i).comap f).map f = iInf S := (giMapComap hf).l_iInf_u _ #align first_order.language.substructure.map_infi_comap_of_surjective FirstOrder.Language.Substructure.map_iInf_comap_of_surjective theorem map_sup_comap_of_surjective (S T : L.Substructure N) : (S.comap f ⊔ T.comap f).map f = S ⊔ T := (giMapComap hf).l_sup_u _ _ #align first_order.language.substructure.map_sup_comap_of_surjective FirstOrder.Language.Substructure.map_sup_comap_of_surjective theorem map_iSup_comap_of_surjective (S : ι → L.Substructure N) : (⨆ i, (S i).comap f).map f = iSup S := (giMapComap hf).l_iSup_u _ #align first_order.language.substructure.map_supr_comap_of_surjective FirstOrder.Language.Substructure.map_iSup_comap_of_surjective theorem comap_le_comap_iff_of_surjective {S T : L.Substructure N} : S.comap f ≤ T.comap f ↔ S ≤ T := (giMapComap hf).u_le_u_iff #align first_order.language.substructure.comap_le_comap_iff_of_surjective FirstOrder.Language.Substructure.comap_le_comap_iff_of_surjective theorem comap_strictMono_of_surjective : StrictMono (comap f) := (giMapComap hf).strictMono_u #align first_order.language.substructure.comap_strict_mono_of_surjective FirstOrder.Language.Substructure.comap_strictMono_of_surjective end GaloisInsertion instance inducedStructure {S : L.Substructure M} : L.Structure S where funMap {_} f x := ⟨funMap f fun i => x i, S.fun_mem f (fun i => x i) fun i => (x i).2⟩ RelMap {_} r x := RelMap r fun i => (x i : M) set_option linter.uppercaseLean3 false in #align first_order.language.substructure.induced_Structure FirstOrder.Language.Substructure.inducedStructure /-- The natural embedding of an `L.Substructure` of `M` into `M`. -/ def subtype (S : L.Substructure M) : S ↪[L] M where toFun := (↑) inj' := Subtype.coe_injective #align first_order.language.substructure.subtype FirstOrder.Language.Substructure.subtype @[simp] theorem coeSubtype : ⇑S.subtype = ((↑) : S → M) := rfl #align first_order.language.substructure.coe_subtype FirstOrder.Language.Substructure.coeSubtype /-- The equivalence between the maximal substructure of a structure and the structure itself. -/ def topEquiv : (⊤ : L.Substructure M) ≃[L] M where toFun := subtype ⊤ invFun m := ⟨m, mem_top m⟩ left_inv m := by simp right_inv m := rfl #align first_order.language.substructure.top_equiv FirstOrder.Language.Substructure.topEquiv @[simp] theorem coe_topEquiv : ⇑(topEquiv : (⊤ : L.Substructure M) ≃[L] M) = ((↑) : (⊤ : L.Substructure M) → M) := rfl #align first_order.language.substructure.coe_top_equiv FirstOrder.Language.Substructure.coe_topEquiv @[simp] theorem realize_boundedFormula_top {α : Type*} {n : ℕ} {φ : L.BoundedFormula α n} {v : α → (⊤ : L.Substructure M)} {xs : Fin n → (⊤ : L.Substructure M)} : φ.Realize v xs ↔ φ.Realize (((↑) : _ → M) ∘ v) ((↑) ∘ xs) := by rw [← Substructure.topEquiv.realize_boundedFormula φ] simp #align first_order.language.substructure.realize_bounded_formula_top FirstOrder.Language.Substructure.realize_boundedFormula_top @[simp] theorem realize_formula_top {α : Type*} {φ : L.Formula α} {v : α → (⊤ : L.Substructure M)} : φ.Realize v ↔ φ.Realize (((↑) : (⊤ : L.Substructure M) → M) ∘ v) := by rw [← Substructure.topEquiv.realize_formula φ] simp #align first_order.language.substructure.realize_formula_top FirstOrder.Language.Substructure.realize_formula_top /-- A dependent version of `Substructure.closure_induction`. -/ @[elab_as_elim] theorem closure_induction' (s : Set M) {p : ∀ x, x ∈ closure L s → Prop} (Hs : ∀ (x) (h : x ∈ s), p x (subset_closure h)) (Hfun : ∀ {n : ℕ} (f : L.Functions n), ClosedUnder f { x | ∃ hx, p x hx }) {x} (hx : x ∈ closure L s) : p x hx := by refine Exists.elim ?_ fun (hx : x ∈ closure L s) (hc : p x hx) => hc exact closure_induction hx (fun x hx => ⟨subset_closure hx, Hs x hx⟩) @Hfun #align first_order.language.substructure.closure_induction' FirstOrder.Language.Substructure.closure_induction' end Substructure namespace LHom set_option linter.uppercaseLean3 false open Substructure variable {L' : Language} [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] /-- Reduces the language of a substructure along a language hom. -/ def substructureReduct : L'.Substructure M ↪o L.Substructure M where toFun S := { carrier := S fun_mem := fun {n} f x hx => by have h := S.fun_mem (φ.onFunction f) x hx simp only [LHom.map_onFunction, Substructure.mem_carrier] at h exact h } inj' S T h := by simp only [SetLike.coe_set_eq, Substructure.mk.injEq] at h exact h map_rel_iff' {S T} := Iff.rfl #align first_order.language.Lhom.substructure_reduct FirstOrder.Language.LHom.substructureReduct @[simp] theorem mem_substructureReduct {x : M} {S : L'.Substructure M} : x ∈ φ.substructureReduct S ↔ x ∈ S := Iff.rfl #align first_order.language.Lhom.mem_substructure_reduct FirstOrder.Language.LHom.mem_substructureReduct @[simp] theorem coe_substructureReduct {S : L'.Substructure M} : (φ.substructureReduct S : Set M) = ↑S := rfl #align first_order.language.Lhom.coe_substructure_reduct FirstOrder.Language.LHom.coe_substructureReduct end LHom namespace Substructure /-- Turns any substructure containing a constant set `A` into a `L[[A]]`-substructure. -/ def withConstants (S : L.Substructure M) {A : Set M} (h : A ⊆ S) : L[[A]].Substructure M where carrier := S fun_mem {n} f := by cases' f with f f · exact S.fun_mem f · cases n · exact fun _ _ => h f.2 · exact isEmptyElim f #align first_order.language.substructure.with_constants FirstOrder.Language.Substructure.withConstants variable {A : Set M} {s : Set M} (h : A ⊆ S) @[simp] theorem mem_withConstants {x : M} : x ∈ S.withConstants h ↔ x ∈ S := Iff.rfl #align first_order.language.substructure.mem_with_constants FirstOrder.Language.Substructure.mem_withConstants @[simp] theorem coe_withConstants : (S.withConstants h : Set M) = ↑S := rfl #align first_order.language.substructure.coe_with_constants FirstOrder.Language.Substructure.coe_withConstants @[simp] theorem reduct_withConstants : (L.lhomWithConstants A).substructureReduct (S.withConstants h) = S := by ext simp #align first_order.language.substructure.reduct_with_constants FirstOrder.Language.Substructure.reduct_withConstants theorem subset_closure_withConstants : A ⊆ closure (L[[A]]) s := by intro a ha simp only [SetLike.mem_coe] let a' : L[[A]].Constants := Sum.inr ⟨a, ha⟩ exact constants_mem a' #align first_order.language.substructure.subset_closure_with_constants FirstOrder.Language.Substructure.subset_closure_withConstants theorem closure_withConstants_eq : closure (L[[A]]) s = (closure L (A ∪ s)).withConstants ((A.subset_union_left).trans subset_closure) := by refine closure_eq_of_le ((A.subset_union_right).trans subset_closure) ?_ rw [← (L.lhomWithConstants A).substructureReduct.le_iff_le] simp only [subset_closure, reduct_withConstants, closure_le, LHom.coe_substructureReduct, Set.union_subset_iff, and_true_iff] exact subset_closure_withConstants #align first_order.language.substructure.closure_with_constants_eq FirstOrder.Language.Substructure.closure_withConstants_eq end Substructure namespace Hom open Substructure /-- The restriction of a first-order hom to a substructure `s ⊆ M` gives a hom `s → N`. -/ @[simps!] def domRestrict (f : M →[L] N) (p : L.Substructure M) : p →[L] N := f.comp p.subtype.toHom #align first_order.language.hom.dom_restrict FirstOrder.Language.Hom.domRestrict #align first_order.language.hom.dom_restrict_to_fun FirstOrder.Language.Hom.domRestrict_toFun /-- A first-order hom `f : M → N` whose values lie in a substructure `p ⊆ N` can be restricted to a hom `M → p`. -/ @[simps] def codRestrict (p : L.Substructure N) (f : M →[L] N) (h : ∀ c, f c ∈ p) : M →[L] p where toFun c := ⟨f c, h c⟩ map_fun' {n} f x := by aesop map_rel' {n} R x h := f.map_rel R x h #align first_order.language.hom.cod_restrict FirstOrder.Language.Hom.codRestrict #align first_order.language.hom.cod_restrict_to_fun_coe FirstOrder.Language.Hom.codRestrict_toFun_coe @[simp] theorem comp_codRestrict (f : M →[L] N) (g : N →[L] P) (p : L.Substructure P) (h : ∀ b, g b ∈ p) : ((codRestrict p g h).comp f : M →[L] p) = codRestrict p (g.comp f) fun _ => h _ := ext fun _ => rfl #align first_order.language.hom.comp_cod_restrict FirstOrder.Language.Hom.comp_codRestrict @[simp] theorem subtype_comp_codRestrict (f : M →[L] N) (p : L.Substructure N) (h : ∀ b, f b ∈ p) : p.subtype.toHom.comp (codRestrict p f h) = f := ext fun _ => rfl #align first_order.language.hom.subtype_comp_cod_restrict FirstOrder.Language.Hom.subtype_comp_codRestrict /-- The range of a first-order hom `f : M → N` is a submodule of `N`. See Note [range copy pattern]. -/ def range (f : M →[L] N) : L.Substructure N := (map f ⊤).copy (Set.range f) Set.image_univ.symm #align first_order.language.hom.range FirstOrder.Language.Hom.range theorem range_coe (f : M →[L] N) : (range f : Set N) = Set.range f := rfl #align first_order.language.hom.range_coe FirstOrder.Language.Hom.range_coe @[simp] theorem mem_range {f : M →[L] N} {x} : x ∈ range f ↔ ∃ y, f y = x := Iff.rfl #align first_order.language.hom.mem_range FirstOrder.Language.Hom.mem_range theorem range_eq_map (f : M →[L] N) : f.range = map f ⊤ := by ext simp #align first_order.language.hom.range_eq_map FirstOrder.Language.Hom.range_eq_map theorem mem_range_self (f : M →[L] N) (x : M) : f x ∈ f.range := ⟨x, rfl⟩ #align first_order.language.hom.mem_range_self FirstOrder.Language.Hom.mem_range_self @[simp] theorem range_id : range (id L M) = ⊤ := SetLike.coe_injective Set.range_id #align first_order.language.hom.range_id FirstOrder.Language.Hom.range_id theorem range_comp (f : M →[L] N) (g : N →[L] P) : range (g.comp f : M →[L] P) = map g (range f) := SetLike.coe_injective (Set.range_comp g f) #align first_order.language.hom.range_comp FirstOrder.Language.Hom.range_comp theorem range_comp_le_range (f : M →[L] N) (g : N →[L] P) : range (g.comp f : M →[L] P) ≤ range g := SetLike.coe_mono (Set.range_comp_subset_range f g) #align first_order.language.hom.range_comp_le_range FirstOrder.Language.Hom.range_comp_le_range theorem range_eq_top {f : M →[L] N} : range f = ⊤ ↔ Function.Surjective f := by rw [SetLike.ext'_iff, range_coe, coe_top, Set.range_iff_surjective] #align first_order.language.hom.range_eq_top FirstOrder.Language.Hom.range_eq_top theorem range_le_iff_comap {f : M →[L] N} {p : L.Substructure N} : range f ≤ p ↔ comap f p = ⊤ := by rw [range_eq_map, map_le_iff_le_comap, eq_top_iff] #align first_order.language.hom.range_le_iff_comap FirstOrder.Language.Hom.range_le_iff_comap theorem map_le_range {f : M →[L] N} {p : L.Substructure M} : map f p ≤ range f := SetLike.coe_mono (Set.image_subset_range f p) #align first_order.language.hom.map_le_range FirstOrder.Language.Hom.map_le_range /-- The substructure of elements `x : M` such that `f x = g x` -/ def eqLocus (f g : M →[L] N) : Substructure L M where carrier := { x : M | f x = g x } fun_mem {n} fn x hx := by have h : f ∘ x = g ∘ x := by ext repeat' rw [Function.comp_apply] apply hx simp [h] #align first_order.language.hom.eq_locus FirstOrder.Language.Hom.eqLocus /-- If two `L.Hom`s are equal on a set, then they are equal on its substructure closure. -/ theorem eqOn_closure {f g : M →[L] N} {s : Set M} (h : Set.EqOn f g s) : Set.EqOn f g (closure L s) := show closure L s ≤ f.eqLocus g from closure_le.2 h #align first_order.language.hom.eq_on_closure FirstOrder.Language.Hom.eqOn_closure theorem eq_of_eqOn_top {f g : M →[L] N} (h : Set.EqOn f g (⊤ : Substructure L M)) : f = g := ext fun _ => h trivial #align first_order.language.hom.eq_of_eq_on_top FirstOrder.Language.Hom.eq_of_eqOn_top variable {s : Set M} theorem eq_of_eqOn_dense (hs : closure L s = ⊤) {f g : M →[L] N} (h : s.EqOn f g) : f = g := eq_of_eqOn_top <| hs ▸ eqOn_closure h #align first_order.language.hom.eq_of_eq_on_dense FirstOrder.Language.Hom.eq_of_eqOn_dense end Hom namespace Embedding open Substructure /-- The restriction of a first-order embedding to a substructure `s ⊆ M` gives an embedding `s → N`. -/ def domRestrict (f : M ↪[L] N) (p : L.Substructure M) : p ↪[L] N := f.comp p.subtype #align first_order.language.embedding.dom_restrict FirstOrder.Language.Embedding.domRestrict @[simp] theorem domRestrict_apply (f : M ↪[L] N) (p : L.Substructure M) (x : p) : f.domRestrict p x = f x := rfl #align first_order.language.embedding.dom_restrict_apply FirstOrder.Language.Embedding.domRestrict_apply /-- A first-order embedding `f : M → N` whose values lie in a substructure `p ⊆ N` can be restricted to an embedding `M → p`. -/ def codRestrict (p : L.Substructure N) (f : M ↪[L] N) (h : ∀ c, f c ∈ p) : M ↪[L] p where toFun := f.toHom.codRestrict p h inj' a b ab := f.injective (Subtype.mk_eq_mk.1 ab) map_fun' {n} F x := (f.toHom.codRestrict p h).map_fun' F x map_rel' {n} r x := by simp only rw [← p.subtype.map_rel] change RelMap r (Hom.comp p.subtype.toHom (f.toHom.codRestrict p h) ∘ x) ↔ _ rw [Hom.subtype_comp_codRestrict, ← f.map_rel] rfl #align first_order.language.embedding.cod_restrict FirstOrder.Language.Embedding.codRestrict @[simp] theorem codRestrict_apply (p : L.Substructure N) (f : M ↪[L] N) {h} (x : M) : (codRestrict p f h x : N) = f x := rfl #align first_order.language.embedding.cod_restrict_apply FirstOrder.Language.Embedding.codRestrict_apply @[simp] theorem codRestrict_apply' (p : L.Substructure N) (f : M ↪[L] N) {h} (x : M) : codRestrict p f h x = ⟨f x, h x⟩ := rfl @[simp] theorem comp_codRestrict (f : M ↪[L] N) (g : N ↪[L] P) (p : L.Substructure P) (h : ∀ b, g b ∈ p) : ((codRestrict p g h).comp f : M ↪[L] p) = codRestrict p (g.comp f) fun _ => h _ := ext fun _ => rfl #align first_order.language.embedding.comp_cod_restrict FirstOrder.Language.Embedding.comp_codRestrict @[simp] theorem subtype_comp_codRestrict (f : M ↪[L] N) (p : L.Substructure N) (h : ∀ b, f b ∈ p) : p.subtype.comp (codRestrict p f h) = f := ext fun _ => rfl #align first_order.language.embedding.subtype_comp_cod_restrict FirstOrder.Language.Embedding.subtype_comp_codRestrict /-- The equivalence between a substructure `s` and its image `s.map f.toHom`, where `f` is an embedding. -/ noncomputable def substructureEquivMap (f : M ↪[L] N) (s : L.Substructure M) : s ≃[L] s.map f.toHom where toFun := codRestrict (s.map f.toHom) (f.domRestrict s) fun ⟨m, hm⟩ => ⟨m, hm, rfl⟩ invFun n := ⟨Classical.choose n.2, (Classical.choose_spec n.2).1⟩ left_inv := fun ⟨m, hm⟩ => Subtype.mk_eq_mk.2 (f.injective (Classical.choose_spec (codRestrict (s.map f.toHom) (f.domRestrict s) (fun ⟨m, hm⟩ => ⟨m, hm, rfl⟩) ⟨m, hm⟩).2).2) right_inv := fun ⟨n, hn⟩ => Subtype.mk_eq_mk.2 (Classical.choose_spec hn).2 map_fun' {n} f x := by aesop map_rel' {n} R x := by aesop #align first_order.language.embedding.substructure_equiv_map FirstOrder.Language.Embedding.substructureEquivMap @[simp] theorem substructureEquivMap_apply (f : M ↪[L] N) (p : L.Substructure M) (x : p) : (f.substructureEquivMap p x : N) = f x := rfl #align first_order.language.embedding.substructure_equiv_map_apply FirstOrder.Language.Embedding.substructureEquivMap_apply @[simp] theorem subtype_substructureEquivMap (f : M ↪[L] N) (s : L.Substructure M) : (subtype _).comp (f.substructureEquivMap s).toEmbedding = f.comp (subtype _) := by ext; rfl /-- The equivalence between the domain and the range of an embedding `f`. -/ noncomputable def equivRange (f : M ↪[L] N) : M ≃[L] f.toHom.range where toFun := codRestrict f.toHom.range f f.toHom.mem_range_self invFun n := Classical.choose n.2 left_inv m := f.injective (Classical.choose_spec (codRestrict f.toHom.range f f.toHom.mem_range_self m).2) right_inv := fun ⟨n, hn⟩ => Subtype.mk_eq_mk.2 (Classical.choose_spec hn) map_fun' {n} f x := by aesop map_rel' {n} R x := by aesop #align first_order.language.embedding.equiv_range FirstOrder.Language.Embedding.equivRange @[simp] theorem equivRange_apply (f : M ↪[L] N) (x : M) : (f.equivRange x : N) = f x := rfl #align first_order.language.embedding.equiv_range_apply FirstOrder.Language.Embedding.equivRange_apply @[simp] theorem subtype_equivRange (f : M ↪[L] N) : (subtype _).comp f.equivRange.toEmbedding = f := by ext; rfl end Embedding namespace Equiv theorem toHom_range (f : M ≃[L] N) : f.toHom.range = ⊤ := by ext n simp only [Hom.mem_range, coe_toHom, Substructure.mem_top, iff_true_iff] exact ⟨f.symm n, apply_symm_apply _ _⟩ #align first_order.language.equiv.to_hom_range FirstOrder.Language.Equiv.toHom_range end Equiv namespace Substructure /-- The embedding associated to an inclusion of substructures. -/ def inclusion {S T : L.Substructure M} (h : S ≤ T) : S ↪[L] T := S.subtype.codRestrict _ fun x => h x.2 #align first_order.language.substructure.inclusion FirstOrder.Language.Substructure.inclusion @[simp] theorem inclusion_self (S : L.Substructure M) : inclusion (le_refl S) = Embedding.refl L S := rfl @[simp] theorem coe_inclusion {S T : L.Substructure M} (h : S ≤ T) : (inclusion h : S → T) = Set.inclusion h := rfl #align first_order.language.substructure.coe_inclusion FirstOrder.Language.Substructure.coe_inclusion
Mathlib/ModelTheory/Substructures.lean
1,039
1,044
theorem range_subtype (S : L.Substructure M) : S.subtype.toHom.range = S := by
ext x simp only [Hom.mem_range, Embedding.coe_toHom, coeSubtype] refine ⟨?_, fun h => ⟨⟨x, h⟩, rfl⟩⟩ rintro ⟨⟨y, hy⟩, rfl⟩ exact hy
/- Copyright (c) 2021 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.Data.Int.Interval import Mathlib.RingTheory.Binomial import Mathlib.RingTheory.HahnSeries.PowerSeries import Mathlib.RingTheory.HahnSeries.Summable import Mathlib.FieldTheory.RatFunc.AsPolynomial import Mathlib.RingTheory.Localization.FractionRing #align_import ring_theory.laurent_series from "leanprover-community/mathlib"@"831c494092374cfe9f50591ed0ac81a25efc5b86" /-! # Laurent Series ## Main Definitions * Defines `LaurentSeries` as an abbreviation for `HahnSeries ℤ`. * Defines `hasseDeriv` of a Laurent series with coefficients in a module over a ring. * Provides a coercion `PowerSeries R` into `LaurentSeries R` given by `HahnSeries.ofPowerSeries`. * Defines `LaurentSeries.powerSeriesPart` * Defines the localization map `LaurentSeries.of_powerSeries_localization` which evaluates to `HahnSeries.ofPowerSeries`. * Embedding of rational functions into Laurent series, provided as a coercion, utilizing the underlying `RatFunc.coeAlgHom`. ## Main Results * Basic properties of Hasse derivatives -/ universe u open scoped Classical open HahnSeries Polynomial noncomputable section /-- A `LaurentSeries` is implemented as a `HahnSeries` with value group `ℤ`. -/ abbrev LaurentSeries (R : Type u) [Zero R] := HahnSeries ℤ R #align laurent_series LaurentSeries variable {R : Type*} namespace LaurentSeries section HasseDeriv /-- The Hasse derivative of Laurent series, as a linear map. -/ @[simps] def hasseDeriv (R : Type*) {V : Type*} [AddCommGroup V] [Semiring R] [Module R V] (k : ℕ) : LaurentSeries V →ₗ[R] LaurentSeries V where toFun f := HahnSeries.ofSuppBddBelow (fun (n : ℤ) => (Ring.choose (n + k) k) • f.coeff (n + k)) (forallLTEqZero_supp_BddBelow _ (f.order - k : ℤ) (fun _ h_lt ↦ by rw [coeff_eq_zero_of_lt_order <| lt_sub_iff_add_lt.mp h_lt, smul_zero])) map_add' f g := by ext simp only [ofSuppBddBelow, add_coeff', Pi.add_apply, smul_add] map_smul' r f := by ext simp only [ofSuppBddBelow, smul_coeff, RingHom.id_apply, smul_comm r] variable [Semiring R] {V : Type*} [AddCommGroup V] [Module R V] theorem hasseDeriv_coeff (k : ℕ) (f : LaurentSeries V) (n : ℤ) : (hasseDeriv R k f).coeff n = Ring.choose (n + k) k • f.coeff (n + k) := rfl end HasseDeriv section Semiring variable [Semiring R] instance : Coe (PowerSeries R) (LaurentSeries R) := ⟨HahnSeries.ofPowerSeries ℤ R⟩ /- Porting note: now a syntactic tautology and not needed elsewhere theorem coe_powerSeries (x : PowerSeries R) : (x : LaurentSeries R) = HahnSeries.ofPowerSeries ℤ R x := rfl -/ #noalign laurent_series.coe_power_series @[simp] theorem coeff_coe_powerSeries (x : PowerSeries R) (n : ℕ) : HahnSeries.coeff (x : LaurentSeries R) n = PowerSeries.coeff R n x := by rw [ofPowerSeries_apply_coeff] #align laurent_series.coeff_coe_power_series LaurentSeries.coeff_coe_powerSeries /-- This is a power series that can be multiplied by an integer power of `X` to give our Laurent series. If the Laurent series is nonzero, `powerSeriesPart` has a nonzero constant term. -/ def powerSeriesPart (x : LaurentSeries R) : PowerSeries R := PowerSeries.mk fun n => x.coeff (x.order + n) #align laurent_series.power_series_part LaurentSeries.powerSeriesPart @[simp] theorem powerSeriesPart_coeff (x : LaurentSeries R) (n : ℕ) : PowerSeries.coeff R n x.powerSeriesPart = x.coeff (x.order + n) := PowerSeries.coeff_mk _ _ #align laurent_series.power_series_part_coeff LaurentSeries.powerSeriesPart_coeff @[simp] theorem powerSeriesPart_zero : powerSeriesPart (0 : LaurentSeries R) = 0 := by ext simp [(PowerSeries.coeff _ _).map_zero] -- Note: this doesn't get picked up any more #align laurent_series.power_series_part_zero LaurentSeries.powerSeriesPart_zero @[simp] theorem powerSeriesPart_eq_zero (x : LaurentSeries R) : x.powerSeriesPart = 0 ↔ x = 0 := by constructor · contrapose! simp only [ne_eq] intro h rw [PowerSeries.ext_iff, not_forall] refine ⟨0, ?_⟩ simp [coeff_order_ne_zero h] · rintro rfl simp #align laurent_series.power_series_part_eq_zero LaurentSeries.powerSeriesPart_eq_zero @[simp] theorem single_order_mul_powerSeriesPart (x : LaurentSeries R) : (single x.order 1 : LaurentSeries R) * x.powerSeriesPart = x := by ext n rw [← sub_add_cancel n x.order, single_mul_coeff_add, sub_add_cancel, one_mul] by_cases h : x.order ≤ n · rw [Int.eq_natAbs_of_zero_le (sub_nonneg_of_le h), coeff_coe_powerSeries, powerSeriesPart_coeff, ← Int.eq_natAbs_of_zero_le (sub_nonneg_of_le h), add_sub_cancel] · rw [ofPowerSeries_apply, embDomain_notin_range] · contrapose! h exact order_le_of_coeff_ne_zero h.symm · contrapose! h simp only [Set.mem_range, RelEmbedding.coe_mk, Function.Embedding.coeFn_mk] at h obtain ⟨m, hm⟩ := h rw [← sub_nonneg, ← hm] simp only [Nat.cast_nonneg] #align laurent_series.single_order_mul_power_series_part LaurentSeries.single_order_mul_powerSeriesPart theorem ofPowerSeries_powerSeriesPart (x : LaurentSeries R) : ofPowerSeries ℤ R x.powerSeriesPart = single (-x.order) 1 * x := by refine Eq.trans ?_ (congr rfl x.single_order_mul_powerSeriesPart) rw [← mul_assoc, single_mul_single, neg_add_self, mul_one, ← C_apply, C_one, one_mul] #align laurent_series.of_power_series_power_series_part LaurentSeries.ofPowerSeries_powerSeriesPart end Semiring instance [CommSemiring R] : Algebra (PowerSeries R) (LaurentSeries R) := (HahnSeries.ofPowerSeries ℤ R).toAlgebra @[simp] theorem coe_algebraMap [CommSemiring R] : ⇑(algebraMap (PowerSeries R) (LaurentSeries R)) = HahnSeries.ofPowerSeries ℤ R := rfl #align laurent_series.coe_algebra_map LaurentSeries.coe_algebraMap /-- The localization map from power series to Laurent series. -/ @[simps (config := { rhsMd := .all, simpRhs := true })] instance of_powerSeries_localization [CommRing R] : IsLocalization (Submonoid.powers (PowerSeries.X : PowerSeries R)) (LaurentSeries R) where map_units' := by rintro ⟨_, n, rfl⟩ refine ⟨⟨single (n : ℤ) 1, single (-n : ℤ) 1, ?_, ?_⟩, ?_⟩ · simp only [single_mul_single, mul_one, add_right_neg] rfl · simp only [single_mul_single, mul_one, add_left_neg] rfl · dsimp; rw [ofPowerSeries_X_pow] surj' z := by by_cases h : 0 ≤ z.order · refine ⟨⟨PowerSeries.X ^ Int.natAbs z.order * powerSeriesPart z, 1⟩, ?_⟩ simp only [RingHom.map_one, mul_one, RingHom.map_mul, coe_algebraMap, ofPowerSeries_X_pow, Submonoid.coe_one] rw [Int.natAbs_of_nonneg h, single_order_mul_powerSeriesPart] · refine ⟨⟨powerSeriesPart z, PowerSeries.X ^ Int.natAbs z.order, ⟨_, rfl⟩⟩, ?_⟩ simp only [coe_algebraMap, ofPowerSeries_powerSeriesPart] rw [mul_comm _ z] refine congr rfl ?_ rw [ofPowerSeries_X_pow, Int.ofNat_natAbs_of_nonpos] exact le_of_not_ge h exists_of_eq {x y} := by rw [coe_algebraMap, ofPowerSeries_injective.eq_iff] rintro rfl exact ⟨1, rfl⟩ #align laurent_series.of_power_series_localization LaurentSeries.of_powerSeries_localization instance {K : Type*} [Field K] : IsFractionRing (PowerSeries K) (LaurentSeries K) := IsLocalization.of_le (Submonoid.powers (PowerSeries.X : PowerSeries K)) _ (powers_le_nonZeroDivisors_of_noZeroDivisors PowerSeries.X_ne_zero) fun _ hf => isUnit_of_mem_nonZeroDivisors <| map_mem_nonZeroDivisors _ HahnSeries.ofPowerSeries_injective hf end LaurentSeries namespace PowerSeries open LaurentSeries variable {R' : Type*} [Semiring R] [Ring R'] (f g : PowerSeries R) (f' g' : PowerSeries R') @[norm_cast] -- Porting note (#10618): simp can prove this theorem coe_zero : ((0 : PowerSeries R) : LaurentSeries R) = 0 := (ofPowerSeries ℤ R).map_zero #align power_series.coe_zero PowerSeries.coe_zero @[norm_cast] -- Porting note (#10618): simp can prove this theorem coe_one : ((1 : PowerSeries R) : LaurentSeries R) = 1 := (ofPowerSeries ℤ R).map_one #align power_series.coe_one PowerSeries.coe_one @[norm_cast] -- Porting note (#10618): simp can prove this theorem coe_add : ((f + g : PowerSeries R) : LaurentSeries R) = f + g := (ofPowerSeries ℤ R).map_add _ _ #align power_series.coe_add PowerSeries.coe_add @[norm_cast] theorem coe_sub : ((f' - g' : PowerSeries R') : LaurentSeries R') = f' - g' := (ofPowerSeries ℤ R').map_sub _ _ #align power_series.coe_sub PowerSeries.coe_sub @[norm_cast] theorem coe_neg : ((-f' : PowerSeries R') : LaurentSeries R') = -f' := (ofPowerSeries ℤ R').map_neg _ #align power_series.coe_neg PowerSeries.coe_neg @[norm_cast] -- Porting note (#10618): simp can prove this theorem coe_mul : ((f * g : PowerSeries R) : LaurentSeries R) = f * g := (ofPowerSeries ℤ R).map_mul _ _ #align power_series.coe_mul PowerSeries.coe_mul theorem coeff_coe (i : ℤ) : ((f : PowerSeries R) : LaurentSeries R).coeff i = if i < 0 then 0 else PowerSeries.coeff R i.natAbs f := by cases i · rw [Int.ofNat_eq_coe, coeff_coe_powerSeries, if_neg (Int.natCast_nonneg _).not_lt, Int.natAbs_ofNat] · rw [ofPowerSeries_apply, embDomain_notin_image_support, if_pos (Int.negSucc_lt_zero _)] simp only [not_exists, RelEmbedding.coe_mk, Set.mem_image, not_and, Function.Embedding.coeFn_mk, Ne, toPowerSeries_symm_apply_coeff, mem_support, imp_true_iff, not_false_iff] #align power_series.coeff_coe PowerSeries.coeff_coe -- Porting note (#10618): simp can prove this -- Porting note: removed norm_cast attribute theorem coe_C (r : R) : ((C R r : PowerSeries R) : LaurentSeries R) = HahnSeries.C r := ofPowerSeries_C _ set_option linter.uppercaseLean3 false in #align power_series.coe_C PowerSeries.coe_C -- @[simp] -- Porting note (#10618): simp can prove this theorem coe_X : ((X : PowerSeries R) : LaurentSeries R) = single 1 1 := ofPowerSeries_X set_option linter.uppercaseLean3 false in #align power_series.coe_X PowerSeries.coe_X @[simp, norm_cast] theorem coe_smul {S : Type*} [Semiring S] [Module R S] (r : R) (x : PowerSeries S) : ((r • x : PowerSeries S) : LaurentSeries S) = r • (ofPowerSeries ℤ S x) := by ext simp [coeff_coe, coeff_smul, smul_ite] #align power_series.coe_smul PowerSeries.coe_smul -- Porting note: RingHom.map_bit0 and RingHom.map_bit1 no longer exist #noalign power_series.coe_bit0 #noalign power_series.coe_bit1 @[norm_cast] theorem coe_pow (n : ℕ) : ((f ^ n : PowerSeries R) : LaurentSeries R) = (ofPowerSeries ℤ R f) ^ n := (ofPowerSeries ℤ R).map_pow _ _ #align power_series.coe_pow PowerSeries.coe_pow end PowerSeries namespace RatFunc section RatFunc open RatFunc variable {F : Type u} [Field F] (p q : F[X]) (f g : RatFunc F) /-- The coercion `RatFunc F → LaurentSeries F` as bundled alg hom. -/ def coeAlgHom (F : Type u) [Field F] : RatFunc F →ₐ[F[X]] LaurentSeries F := liftAlgHom (Algebra.ofId _ _) <| nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _ <| Polynomial.algebraMap_hahnSeries_injective _ #align ratfunc.coe_alg_hom RatFunc.coeAlgHom /-- The coercion `RatFunc F → LaurentSeries F` as a function. This is the implementation of `coeToLaurentSeries`. -/ @[coe] def coeToLaurentSeries_fun {F : Type u} [Field F] : RatFunc F → LaurentSeries F := coeAlgHom F instance coeToLaurentSeries : Coe (RatFunc F) (LaurentSeries F) := ⟨coeToLaurentSeries_fun⟩ #align ratfunc.coe_to_laurent_series RatFunc.coeToLaurentSeries theorem coe_def : (f : LaurentSeries F) = coeAlgHom F f := rfl #align ratfunc.coe_def RatFunc.coe_def theorem coe_num_denom : (f : LaurentSeries F) = f.num / f.denom := liftAlgHom_apply _ _ f #align ratfunc.coe_num_denom RatFunc.coe_num_denom theorem coe_injective : Function.Injective ((↑) : RatFunc F → LaurentSeries F) := liftAlgHom_injective _ (Polynomial.algebraMap_hahnSeries_injective _) #align ratfunc.coe_injective RatFunc.coe_injective -- Porting note: removed the `norm_cast` tag: -- `norm_cast: badly shaped lemma, rhs can't start with coe `↑(coeAlgHom F) f` @[simp] theorem coe_apply : coeAlgHom F f = f := rfl #align ratfunc.coe_apply RatFunc.coe_apply
Mathlib/RingTheory/LaurentSeries.lean
321
322
theorem coe_coe (P : Polynomial F) : (P : LaurentSeries F) = (P : RatFunc F) := by
simp only [coePolynomial, coe_def, AlgHom.commutes, algebraMap_hahnSeries_apply]
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Yaël Dillies -/ import Mathlib.Order.Cover import Mathlib.Order.Interval.Finset.Defs #align_import data.finset.locally_finite from "leanprover-community/mathlib"@"442a83d738cb208d3600056c489be16900ba701d" /-! # Intervals as finsets This file provides basic results about all the `Finset.Ixx`, which are defined in `Order.Interval.Finset.Defs`. In addition, it shows that in a locally finite order `≤` and `<` are the transitive closures of, respectively, `⩿` and `⋖`, which then leads to a characterization of monotone and strictly functions whose domain is a locally finite order. In particular, this file proves: * `le_iff_transGen_wcovBy`: `≤` is the transitive closure of `⩿` * `lt_iff_transGen_covBy`: `≤` is the transitive closure of `⩿` * `monotone_iff_forall_wcovBy`: Characterization of monotone functions * `strictMono_iff_forall_covBy`: Characterization of strictly monotone functions ## TODO This file was originally only about `Finset.Ico a b` where `a b : ℕ`. No care has yet been taken to generalize these lemmas properly and many lemmas about `Icc`, `Ioc`, `Ioo` are missing. In general, what's to do is taking the lemmas in `Data.X.Intervals` and abstract away the concrete structure. Complete the API. See https://github.com/leanprover-community/mathlib/pull/14448#discussion_r906109235 for some ideas. -/ assert_not_exists MonoidWithZero assert_not_exists Finset.sum open Function OrderDual open FinsetInterval variable {ι α : Type*} namespace Finset section Preorder variable [Preorder α] section LocallyFiniteOrder variable [LocallyFiniteOrder α] {a a₁ a₂ b b₁ b₂ c x : α} @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem nonempty_Icc : (Icc a b).Nonempty ↔ a ≤ b := by rw [← coe_nonempty, coe_Icc, Set.nonempty_Icc] #align finset.nonempty_Icc Finset.nonempty_Icc @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem nonempty_Ico : (Ico a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ico, Set.nonempty_Ico] #align finset.nonempty_Ico Finset.nonempty_Ico @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem nonempty_Ioc : (Ioc a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ioc, Set.nonempty_Ioc] #align finset.nonempty_Ioc Finset.nonempty_Ioc -- TODO: This is nonsense. A locally finite order is never densely ordered @[simp] theorem nonempty_Ioo [DenselyOrdered α] : (Ioo a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ioo, Set.nonempty_Ioo] #align finset.nonempty_Ioo Finset.nonempty_Ioo @[simp] theorem Icc_eq_empty_iff : Icc a b = ∅ ↔ ¬a ≤ b := by rw [← coe_eq_empty, coe_Icc, Set.Icc_eq_empty_iff] #align finset.Icc_eq_empty_iff Finset.Icc_eq_empty_iff @[simp] theorem Ico_eq_empty_iff : Ico a b = ∅ ↔ ¬a < b := by rw [← coe_eq_empty, coe_Ico, Set.Ico_eq_empty_iff] #align finset.Ico_eq_empty_iff Finset.Ico_eq_empty_iff @[simp] theorem Ioc_eq_empty_iff : Ioc a b = ∅ ↔ ¬a < b := by rw [← coe_eq_empty, coe_Ioc, Set.Ioc_eq_empty_iff] #align finset.Ioc_eq_empty_iff Finset.Ioc_eq_empty_iff -- TODO: This is nonsense. A locally finite order is never densely ordered @[simp] theorem Ioo_eq_empty_iff [DenselyOrdered α] : Ioo a b = ∅ ↔ ¬a < b := by rw [← coe_eq_empty, coe_Ioo, Set.Ioo_eq_empty_iff] #align finset.Ioo_eq_empty_iff Finset.Ioo_eq_empty_iff alias ⟨_, Icc_eq_empty⟩ := Icc_eq_empty_iff #align finset.Icc_eq_empty Finset.Icc_eq_empty alias ⟨_, Ico_eq_empty⟩ := Ico_eq_empty_iff #align finset.Ico_eq_empty Finset.Ico_eq_empty alias ⟨_, Ioc_eq_empty⟩ := Ioc_eq_empty_iff #align finset.Ioc_eq_empty Finset.Ioc_eq_empty @[simp] theorem Ioo_eq_empty (h : ¬a < b) : Ioo a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ hx => h ((mem_Ioo.1 hx).1.trans (mem_Ioo.1 hx).2) #align finset.Ioo_eq_empty Finset.Ioo_eq_empty @[simp] theorem Icc_eq_empty_of_lt (h : b < a) : Icc a b = ∅ := Icc_eq_empty h.not_le #align finset.Icc_eq_empty_of_lt Finset.Icc_eq_empty_of_lt @[simp] theorem Ico_eq_empty_of_le (h : b ≤ a) : Ico a b = ∅ := Ico_eq_empty h.not_lt #align finset.Ico_eq_empty_of_le Finset.Ico_eq_empty_of_le @[simp] theorem Ioc_eq_empty_of_le (h : b ≤ a) : Ioc a b = ∅ := Ioc_eq_empty h.not_lt #align finset.Ioc_eq_empty_of_le Finset.Ioc_eq_empty_of_le @[simp] theorem Ioo_eq_empty_of_le (h : b ≤ a) : Ioo a b = ∅ := Ioo_eq_empty h.not_lt #align finset.Ioo_eq_empty_of_le Finset.Ioo_eq_empty_of_le -- porting note (#10618): simp can prove this -- @[simp] theorem left_mem_Icc : a ∈ Icc a b ↔ a ≤ b := by simp only [mem_Icc, true_and_iff, le_rfl] #align finset.left_mem_Icc Finset.left_mem_Icc -- porting note (#10618): simp can prove this -- @[simp] theorem left_mem_Ico : a ∈ Ico a b ↔ a < b := by simp only [mem_Ico, true_and_iff, le_refl] #align finset.left_mem_Ico Finset.left_mem_Ico -- porting note (#10618): simp can prove this -- @[simp] theorem right_mem_Icc : b ∈ Icc a b ↔ a ≤ b := by simp only [mem_Icc, and_true_iff, le_rfl] #align finset.right_mem_Icc Finset.right_mem_Icc -- porting note (#10618): simp can prove this -- @[simp] theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b := by simp only [mem_Ioc, and_true_iff, le_rfl] #align finset.right_mem_Ioc Finset.right_mem_Ioc -- porting note (#10618): simp can prove this -- @[simp] theorem left_not_mem_Ioc : a ∉ Ioc a b := fun h => lt_irrefl _ (mem_Ioc.1 h).1 #align finset.left_not_mem_Ioc Finset.left_not_mem_Ioc -- porting note (#10618): simp can prove this -- @[simp] theorem left_not_mem_Ioo : a ∉ Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).1 #align finset.left_not_mem_Ioo Finset.left_not_mem_Ioo -- porting note (#10618): simp can prove this -- @[simp] theorem right_not_mem_Ico : b ∉ Ico a b := fun h => lt_irrefl _ (mem_Ico.1 h).2 #align finset.right_not_mem_Ico Finset.right_not_mem_Ico -- porting note (#10618): simp can prove this -- @[simp] theorem right_not_mem_Ioo : b ∉ Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).2 #align finset.right_not_mem_Ioo Finset.right_not_mem_Ioo theorem Icc_subset_Icc (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊆ Icc a₂ b₂ := by simpa [← coe_subset] using Set.Icc_subset_Icc ha hb #align finset.Icc_subset_Icc Finset.Icc_subset_Icc theorem Ico_subset_Ico (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ico a₁ b₁ ⊆ Ico a₂ b₂ := by simpa [← coe_subset] using Set.Ico_subset_Ico ha hb #align finset.Ico_subset_Ico Finset.Ico_subset_Ico theorem Ioc_subset_Ioc (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ioc a₁ b₁ ⊆ Ioc a₂ b₂ := by simpa [← coe_subset] using Set.Ioc_subset_Ioc ha hb #align finset.Ioc_subset_Ioc Finset.Ioc_subset_Ioc theorem Ioo_subset_Ioo (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ioo a₁ b₁ ⊆ Ioo a₂ b₂ := by simpa [← coe_subset] using Set.Ioo_subset_Ioo ha hb #align finset.Ioo_subset_Ioo Finset.Ioo_subset_Ioo theorem Icc_subset_Icc_left (h : a₁ ≤ a₂) : Icc a₂ b ⊆ Icc a₁ b := Icc_subset_Icc h le_rfl #align finset.Icc_subset_Icc_left Finset.Icc_subset_Icc_left theorem Ico_subset_Ico_left (h : a₁ ≤ a₂) : Ico a₂ b ⊆ Ico a₁ b := Ico_subset_Ico h le_rfl #align finset.Ico_subset_Ico_left Finset.Ico_subset_Ico_left theorem Ioc_subset_Ioc_left (h : a₁ ≤ a₂) : Ioc a₂ b ⊆ Ioc a₁ b := Ioc_subset_Ioc h le_rfl #align finset.Ioc_subset_Ioc_left Finset.Ioc_subset_Ioc_left theorem Ioo_subset_Ioo_left (h : a₁ ≤ a₂) : Ioo a₂ b ⊆ Ioo a₁ b := Ioo_subset_Ioo h le_rfl #align finset.Ioo_subset_Ioo_left Finset.Ioo_subset_Ioo_left theorem Icc_subset_Icc_right (h : b₁ ≤ b₂) : Icc a b₁ ⊆ Icc a b₂ := Icc_subset_Icc le_rfl h #align finset.Icc_subset_Icc_right Finset.Icc_subset_Icc_right theorem Ico_subset_Ico_right (h : b₁ ≤ b₂) : Ico a b₁ ⊆ Ico a b₂ := Ico_subset_Ico le_rfl h #align finset.Ico_subset_Ico_right Finset.Ico_subset_Ico_right theorem Ioc_subset_Ioc_right (h : b₁ ≤ b₂) : Ioc a b₁ ⊆ Ioc a b₂ := Ioc_subset_Ioc le_rfl h #align finset.Ioc_subset_Ioc_right Finset.Ioc_subset_Ioc_right theorem Ioo_subset_Ioo_right (h : b₁ ≤ b₂) : Ioo a b₁ ⊆ Ioo a b₂ := Ioo_subset_Ioo le_rfl h #align finset.Ioo_subset_Ioo_right Finset.Ioo_subset_Ioo_right theorem Ico_subset_Ioo_left (h : a₁ < a₂) : Ico a₂ b ⊆ Ioo a₁ b := by rw [← coe_subset, coe_Ico, coe_Ioo] exact Set.Ico_subset_Ioo_left h #align finset.Ico_subset_Ioo_left Finset.Ico_subset_Ioo_left theorem Ioc_subset_Ioo_right (h : b₁ < b₂) : Ioc a b₁ ⊆ Ioo a b₂ := by rw [← coe_subset, coe_Ioc, coe_Ioo] exact Set.Ioc_subset_Ioo_right h #align finset.Ioc_subset_Ioo_right Finset.Ioc_subset_Ioo_right theorem Icc_subset_Ico_right (h : b₁ < b₂) : Icc a b₁ ⊆ Ico a b₂ := by rw [← coe_subset, coe_Icc, coe_Ico] exact Set.Icc_subset_Ico_right h #align finset.Icc_subset_Ico_right Finset.Icc_subset_Ico_right
Mathlib/Order/Interval/Finset/Basic.lean
235
237
theorem Ioo_subset_Ico_self : Ioo a b ⊆ Ico a b := by
rw [← coe_subset, coe_Ioo, coe_Ico] exact Set.Ioo_subset_Ico_self
/- Copyright (c) 2021 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.MvPolynomial.Variables #align_import data.mv_polynomial.supported from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Polynomials supported by a set of variables This file contains the definition and lemmas about `MvPolynomial.supported`. ## Main definitions * `MvPolynomial.supported` : Given a set `s : Set σ`, `supported R s` is the subalgebra of `MvPolynomial σ R` consisting of polynomials whose set of variables is contained in `s`. This subalgebra is isomorphic to `MvPolynomial s R`. ## Tags variables, polynomial, vars -/ universe u v w namespace MvPolynomial variable {σ τ : Type*} {R : Type u} {S : Type v} {r : R} {e : ℕ} {n m : σ} section CommSemiring variable [CommSemiring R] {p q : MvPolynomial σ R} variable (R) /-- The set of polynomials whose variables are contained in `s` as a `Subalgebra` over `R`. -/ noncomputable def supported (s : Set σ) : Subalgebra R (MvPolynomial σ R) := Algebra.adjoin R (X '' s) #align mv_polynomial.supported MvPolynomial.supported variable {R} open Algebra theorem supported_eq_range_rename (s : Set σ) : supported R s = (rename ((↑) : s → σ)).range := by rw [supported, Set.image_eq_range, adjoin_range_eq_range_aeval, rename] congr #align mv_polynomial.supported_eq_range_rename MvPolynomial.supported_eq_range_rename /-- The isomorphism between the subalgebra of polynomials supported by `s` and `MvPolynomial s R`. -/ noncomputable def supportedEquivMvPolynomial (s : Set σ) : supported R s ≃ₐ[R] MvPolynomial s R := (Subalgebra.equivOfEq _ _ (supported_eq_range_rename s)).trans (AlgEquiv.ofInjective (rename ((↑) : s → σ)) (rename_injective _ Subtype.val_injective)).symm #align mv_polynomial.supported_equiv_mv_polynomial MvPolynomial.supportedEquivMvPolynomial @[simp, nolint simpNF] -- Porting note: the `simpNF` linter complained about this lemma. theorem supportedEquivMvPolynomial_symm_C (s : Set σ) (x : R) : (supportedEquivMvPolynomial s).symm (C x) = algebraMap R (supported R s) x := by ext1 simp [supportedEquivMvPolynomial, MvPolynomial.algebraMap_eq] set_option linter.uppercaseLean3 false in #align mv_polynomial.supported_equiv_mv_polynomial_symm_C MvPolynomial.supportedEquivMvPolynomial_symm_C @[simp, nolint simpNF] -- Porting note: the `simpNF` linter complained about this lemma. theorem supportedEquivMvPolynomial_symm_X (s : Set σ) (i : s) : (↑((supportedEquivMvPolynomial s).symm (X i : MvPolynomial s R)) : MvPolynomial σ R) = X ↑i := by simp [supportedEquivMvPolynomial] set_option linter.uppercaseLean3 false in #align mv_polynomial.supported_equiv_mv_polynomial_symm_X MvPolynomial.supportedEquivMvPolynomial_symm_X variable {s t : Set σ} theorem mem_supported : p ∈ supported R s ↔ ↑p.vars ⊆ s := by classical rw [supported_eq_range_rename, AlgHom.mem_range] constructor · rintro ⟨p, rfl⟩ refine _root_.trans (Finset.coe_subset.2 (vars_rename _ _)) ?_ simp · intro hs exact exists_rename_eq_of_vars_subset_range p ((↑) : s → σ) Subtype.val_injective (by simpa) #align mv_polynomial.mem_supported MvPolynomial.mem_supported theorem supported_eq_vars_subset : (supported R s : Set (MvPolynomial σ R)) = { p | ↑p.vars ⊆ s } := Set.ext fun _ ↦ mem_supported #align mv_polynomial.supported_eq_vars_subset MvPolynomial.supported_eq_vars_subset @[simp]
Mathlib/Algebra/MvPolynomial/Supported.lean
91
92
theorem mem_supported_vars (p : MvPolynomial σ R) : p ∈ supported R (↑p.vars : Set σ) := by
rw [mem_supported]
/- Copyright (c) 2020 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov, Patrick Massot -/ import Mathlib.Order.Interval.Set.UnorderedInterval import Mathlib.Algebra.Order.Interval.Set.Monoid import Mathlib.Data.Set.Pointwise.Basic import Mathlib.Algebra.Order.Field.Basic import Mathlib.Algebra.Order.Group.MinMax #align_import data.set.pointwise.interval from "leanprover-community/mathlib"@"2196ab363eb097c008d4497125e0dde23fb36db2" /-! # (Pre)images of intervals In this file we prove a bunch of trivial lemmas like “if we add `a` to all points of `[b, c]`, then we get `[a + b, a + c]`”. For the functions `x ↦ x ± a`, `x ↦ a ± x`, and `x ↦ -x` we prove lemmas about preimages and images of all intervals. We also prove a few lemmas about images under `x ↦ a * x`, `x ↦ x * a` and `x ↦ x⁻¹`. -/ open Interval Pointwise variable {α : Type*} namespace Set /-! ### Binary pointwise operations Note that the subset operations below only cover the cases with the largest possible intervals on the LHS: to conclude that `Ioo a b * Ioo c d ⊆ Ioo (a * c) (c * d)`, you can use monotonicity of `*` and `Set.Ico_mul_Ioc_subset`. TODO: repeat these lemmas for the generality of `mul_le_mul` (which assumes nonnegativity), which the unprimed names have been reserved for -/ section ContravariantLE variable [Mul α] [Preorder α] variable [CovariantClass α α (· * ·) (· ≤ ·)] [CovariantClass α α (Function.swap HMul.hMul) LE.le] @[to_additive Icc_add_Icc_subset] theorem Icc_mul_Icc_subset' (a b c d : α) : Icc a b * Icc c d ⊆ Icc (a * c) (b * d) := by rintro x ⟨y, ⟨hya, hyb⟩, z, ⟨hzc, hzd⟩, rfl⟩ exact ⟨mul_le_mul' hya hzc, mul_le_mul' hyb hzd⟩ @[to_additive Iic_add_Iic_subset] theorem Iic_mul_Iic_subset' (a b : α) : Iic a * Iic b ⊆ Iic (a * b) := by rintro x ⟨y, hya, z, hzb, rfl⟩ exact mul_le_mul' hya hzb @[to_additive Ici_add_Ici_subset] theorem Ici_mul_Ici_subset' (a b : α) : Ici a * Ici b ⊆ Ici (a * b) := by rintro x ⟨y, hya, z, hzb, rfl⟩ exact mul_le_mul' hya hzb end ContravariantLE section ContravariantLT variable [Mul α] [PartialOrder α] variable [CovariantClass α α (· * ·) (· < ·)] [CovariantClass α α (Function.swap HMul.hMul) LT.lt] @[to_additive Icc_add_Ico_subset] theorem Icc_mul_Ico_subset' (a b c d : α) : Icc a b * Ico c d ⊆ Ico (a * c) (b * d) := by haveI := covariantClass_le_of_lt rintro x ⟨y, ⟨hya, hyb⟩, z, ⟨hzc, hzd⟩, rfl⟩ exact ⟨mul_le_mul' hya hzc, mul_lt_mul_of_le_of_lt hyb hzd⟩ @[to_additive Ico_add_Icc_subset] theorem Ico_mul_Icc_subset' (a b c d : α) : Ico a b * Icc c d ⊆ Ico (a * c) (b * d) := by haveI := covariantClass_le_of_lt rintro x ⟨y, ⟨hya, hyb⟩, z, ⟨hzc, hzd⟩, rfl⟩ exact ⟨mul_le_mul' hya hzc, mul_lt_mul_of_lt_of_le hyb hzd⟩ @[to_additive Ioc_add_Ico_subset] theorem Ioc_mul_Ico_subset' (a b c d : α) : Ioc a b * Ico c d ⊆ Ioo (a * c) (b * d) := by haveI := covariantClass_le_of_lt rintro x ⟨y, ⟨hya, hyb⟩, z, ⟨hzc, hzd⟩, rfl⟩ exact ⟨mul_lt_mul_of_lt_of_le hya hzc, mul_lt_mul_of_le_of_lt hyb hzd⟩ @[to_additive Ico_add_Ioc_subset] theorem Ico_mul_Ioc_subset' (a b c d : α) : Ico a b * Ioc c d ⊆ Ioo (a * c) (b * d) := by haveI := covariantClass_le_of_lt rintro x ⟨y, ⟨hya, hyb⟩, z, ⟨hzc, hzd⟩, rfl⟩ exact ⟨mul_lt_mul_of_le_of_lt hya hzc, mul_lt_mul_of_lt_of_le hyb hzd⟩ @[to_additive Iic_add_Iio_subset] theorem Iic_mul_Iio_subset' (a b : α) : Iic a * Iio b ⊆ Iio (a * b) := by haveI := covariantClass_le_of_lt rintro x ⟨y, hya, z, hzb, rfl⟩ exact mul_lt_mul_of_le_of_lt hya hzb @[to_additive Iio_add_Iic_subset] theorem Iio_mul_Iic_subset' (a b : α) : Iio a * Iic b ⊆ Iio (a * b) := by haveI := covariantClass_le_of_lt rintro x ⟨y, hya, z, hzb, rfl⟩ exact mul_lt_mul_of_lt_of_le hya hzb @[to_additive Ioi_add_Ici_subset] theorem Ioi_mul_Ici_subset' (a b : α) : Ioi a * Ici b ⊆ Ioi (a * b) := by haveI := covariantClass_le_of_lt rintro x ⟨y, hya, z, hzb, rfl⟩ exact mul_lt_mul_of_lt_of_le hya hzb @[to_additive Ici_add_Ioi_subset] theorem Ici_mul_Ioi_subset' (a b : α) : Ici a * Ioi b ⊆ Ioi (a * b) := by haveI := covariantClass_le_of_lt rintro x ⟨y, hya, z, hzb, rfl⟩ exact mul_lt_mul_of_le_of_lt hya hzb end ContravariantLT section OrderedAddCommGroup variable [OrderedAddCommGroup α] (a b c : α) /-! ### Preimages under `x ↦ a + x` -/ @[simp] theorem preimage_const_add_Ici : (fun x => a + x) ⁻¹' Ici b = Ici (b - a) := ext fun _x => sub_le_iff_le_add'.symm #align set.preimage_const_add_Ici Set.preimage_const_add_Ici @[simp] theorem preimage_const_add_Ioi : (fun x => a + x) ⁻¹' Ioi b = Ioi (b - a) := ext fun _x => sub_lt_iff_lt_add'.symm #align set.preimage_const_add_Ioi Set.preimage_const_add_Ioi @[simp] theorem preimage_const_add_Iic : (fun x => a + x) ⁻¹' Iic b = Iic (b - a) := ext fun _x => le_sub_iff_add_le'.symm #align set.preimage_const_add_Iic Set.preimage_const_add_Iic @[simp] theorem preimage_const_add_Iio : (fun x => a + x) ⁻¹' Iio b = Iio (b - a) := ext fun _x => lt_sub_iff_add_lt'.symm #align set.preimage_const_add_Iio Set.preimage_const_add_Iio @[simp] theorem preimage_const_add_Icc : (fun x => a + x) ⁻¹' Icc b c = Icc (b - a) (c - a) := by simp [← Ici_inter_Iic] #align set.preimage_const_add_Icc Set.preimage_const_add_Icc @[simp] theorem preimage_const_add_Ico : (fun x => a + x) ⁻¹' Ico b c = Ico (b - a) (c - a) := by simp [← Ici_inter_Iio] #align set.preimage_const_add_Ico Set.preimage_const_add_Ico @[simp] theorem preimage_const_add_Ioc : (fun x => a + x) ⁻¹' Ioc b c = Ioc (b - a) (c - a) := by simp [← Ioi_inter_Iic] #align set.preimage_const_add_Ioc Set.preimage_const_add_Ioc @[simp] theorem preimage_const_add_Ioo : (fun x => a + x) ⁻¹' Ioo b c = Ioo (b - a) (c - a) := by simp [← Ioi_inter_Iio] #align set.preimage_const_add_Ioo Set.preimage_const_add_Ioo /-! ### Preimages under `x ↦ x + a` -/ @[simp] theorem preimage_add_const_Ici : (fun x => x + a) ⁻¹' Ici b = Ici (b - a) := ext fun _x => sub_le_iff_le_add.symm #align set.preimage_add_const_Ici Set.preimage_add_const_Ici @[simp] theorem preimage_add_const_Ioi : (fun x => x + a) ⁻¹' Ioi b = Ioi (b - a) := ext fun _x => sub_lt_iff_lt_add.symm #align set.preimage_add_const_Ioi Set.preimage_add_const_Ioi @[simp] theorem preimage_add_const_Iic : (fun x => x + a) ⁻¹' Iic b = Iic (b - a) := ext fun _x => le_sub_iff_add_le.symm #align set.preimage_add_const_Iic Set.preimage_add_const_Iic @[simp] theorem preimage_add_const_Iio : (fun x => x + a) ⁻¹' Iio b = Iio (b - a) := ext fun _x => lt_sub_iff_add_lt.symm #align set.preimage_add_const_Iio Set.preimage_add_const_Iio @[simp] theorem preimage_add_const_Icc : (fun x => x + a) ⁻¹' Icc b c = Icc (b - a) (c - a) := by simp [← Ici_inter_Iic] #align set.preimage_add_const_Icc Set.preimage_add_const_Icc @[simp] theorem preimage_add_const_Ico : (fun x => x + a) ⁻¹' Ico b c = Ico (b - a) (c - a) := by simp [← Ici_inter_Iio] #align set.preimage_add_const_Ico Set.preimage_add_const_Ico @[simp] theorem preimage_add_const_Ioc : (fun x => x + a) ⁻¹' Ioc b c = Ioc (b - a) (c - a) := by simp [← Ioi_inter_Iic] #align set.preimage_add_const_Ioc Set.preimage_add_const_Ioc @[simp] theorem preimage_add_const_Ioo : (fun x => x + a) ⁻¹' Ioo b c = Ioo (b - a) (c - a) := by simp [← Ioi_inter_Iio] #align set.preimage_add_const_Ioo Set.preimage_add_const_Ioo /-! ### Preimages under `x ↦ -x` -/ @[simp] theorem preimage_neg_Ici : -Ici a = Iic (-a) := ext fun _x => le_neg #align set.preimage_neg_Ici Set.preimage_neg_Ici @[simp] theorem preimage_neg_Iic : -Iic a = Ici (-a) := ext fun _x => neg_le #align set.preimage_neg_Iic Set.preimage_neg_Iic @[simp] theorem preimage_neg_Ioi : -Ioi a = Iio (-a) := ext fun _x => lt_neg #align set.preimage_neg_Ioi Set.preimage_neg_Ioi @[simp] theorem preimage_neg_Iio : -Iio a = Ioi (-a) := ext fun _x => neg_lt #align set.preimage_neg_Iio Set.preimage_neg_Iio @[simp] theorem preimage_neg_Icc : -Icc a b = Icc (-b) (-a) := by simp [← Ici_inter_Iic, inter_comm] #align set.preimage_neg_Icc Set.preimage_neg_Icc @[simp] theorem preimage_neg_Ico : -Ico a b = Ioc (-b) (-a) := by simp [← Ici_inter_Iio, ← Ioi_inter_Iic, inter_comm] #align set.preimage_neg_Ico Set.preimage_neg_Ico @[simp] theorem preimage_neg_Ioc : -Ioc a b = Ico (-b) (-a) := by simp [← Ioi_inter_Iic, ← Ici_inter_Iio, inter_comm] #align set.preimage_neg_Ioc Set.preimage_neg_Ioc @[simp] theorem preimage_neg_Ioo : -Ioo a b = Ioo (-b) (-a) := by simp [← Ioi_inter_Iio, inter_comm] #align set.preimage_neg_Ioo Set.preimage_neg_Ioo /-! ### Preimages under `x ↦ x - a` -/ @[simp] theorem preimage_sub_const_Ici : (fun x => x - a) ⁻¹' Ici b = Ici (b + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Ici Set.preimage_sub_const_Ici @[simp] theorem preimage_sub_const_Ioi : (fun x => x - a) ⁻¹' Ioi b = Ioi (b + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Ioi Set.preimage_sub_const_Ioi @[simp] theorem preimage_sub_const_Iic : (fun x => x - a) ⁻¹' Iic b = Iic (b + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Iic Set.preimage_sub_const_Iic @[simp] theorem preimage_sub_const_Iio : (fun x => x - a) ⁻¹' Iio b = Iio (b + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Iio Set.preimage_sub_const_Iio @[simp] theorem preimage_sub_const_Icc : (fun x => x - a) ⁻¹' Icc b c = Icc (b + a) (c + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Icc Set.preimage_sub_const_Icc @[simp] theorem preimage_sub_const_Ico : (fun x => x - a) ⁻¹' Ico b c = Ico (b + a) (c + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Ico Set.preimage_sub_const_Ico @[simp] theorem preimage_sub_const_Ioc : (fun x => x - a) ⁻¹' Ioc b c = Ioc (b + a) (c + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Ioc Set.preimage_sub_const_Ioc @[simp] theorem preimage_sub_const_Ioo : (fun x => x - a) ⁻¹' Ioo b c = Ioo (b + a) (c + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Ioo Set.preimage_sub_const_Ioo /-! ### Preimages under `x ↦ a - x` -/ @[simp] theorem preimage_const_sub_Ici : (fun x => a - x) ⁻¹' Ici b = Iic (a - b) := ext fun _x => le_sub_comm #align set.preimage_const_sub_Ici Set.preimage_const_sub_Ici @[simp] theorem preimage_const_sub_Iic : (fun x => a - x) ⁻¹' Iic b = Ici (a - b) := ext fun _x => sub_le_comm #align set.preimage_const_sub_Iic Set.preimage_const_sub_Iic @[simp] theorem preimage_const_sub_Ioi : (fun x => a - x) ⁻¹' Ioi b = Iio (a - b) := ext fun _x => lt_sub_comm #align set.preimage_const_sub_Ioi Set.preimage_const_sub_Ioi @[simp] theorem preimage_const_sub_Iio : (fun x => a - x) ⁻¹' Iio b = Ioi (a - b) := ext fun _x => sub_lt_comm #align set.preimage_const_sub_Iio Set.preimage_const_sub_Iio @[simp] theorem preimage_const_sub_Icc : (fun x => a - x) ⁻¹' Icc b c = Icc (a - c) (a - b) := by simp [← Ici_inter_Iic, inter_comm] #align set.preimage_const_sub_Icc Set.preimage_const_sub_Icc @[simp] theorem preimage_const_sub_Ico : (fun x => a - x) ⁻¹' Ico b c = Ioc (a - c) (a - b) := by simp [← Ioi_inter_Iic, ← Ici_inter_Iio, inter_comm] #align set.preimage_const_sub_Ico Set.preimage_const_sub_Ico @[simp] theorem preimage_const_sub_Ioc : (fun x => a - x) ⁻¹' Ioc b c = Ico (a - c) (a - b) := by simp [← Ioi_inter_Iic, ← Ici_inter_Iio, inter_comm] #align set.preimage_const_sub_Ioc Set.preimage_const_sub_Ioc @[simp] theorem preimage_const_sub_Ioo : (fun x => a - x) ⁻¹' Ioo b c = Ioo (a - c) (a - b) := by simp [← Ioi_inter_Iio, inter_comm] #align set.preimage_const_sub_Ioo Set.preimage_const_sub_Ioo /-! ### Images under `x ↦ a + x` -/ -- @[simp] -- Porting note (#10618): simp can prove this modulo `add_comm` theorem image_const_add_Iic : (fun x => a + x) '' Iic b = Iic (a + b) := by simp [add_comm] #align set.image_const_add_Iic Set.image_const_add_Iic -- @[simp] -- Porting note (#10618): simp can prove this modulo `add_comm` theorem image_const_add_Iio : (fun x => a + x) '' Iio b = Iio (a + b) := by simp [add_comm] #align set.image_const_add_Iio Set.image_const_add_Iio /-! ### Images under `x ↦ x + a` -/ -- @[simp] -- Porting note (#10618): simp can prove this theorem image_add_const_Iic : (fun x => x + a) '' Iic b = Iic (b + a) := by simp #align set.image_add_const_Iic Set.image_add_const_Iic -- @[simp] -- Porting note (#10618): simp can prove this theorem image_add_const_Iio : (fun x => x + a) '' Iio b = Iio (b + a) := by simp #align set.image_add_const_Iio Set.image_add_const_Iio /-! ### Images under `x ↦ -x` -/ theorem image_neg_Ici : Neg.neg '' Ici a = Iic (-a) := by simp #align set.image_neg_Ici Set.image_neg_Ici theorem image_neg_Iic : Neg.neg '' Iic a = Ici (-a) := by simp #align set.image_neg_Iic Set.image_neg_Iic theorem image_neg_Ioi : Neg.neg '' Ioi a = Iio (-a) := by simp #align set.image_neg_Ioi Set.image_neg_Ioi theorem image_neg_Iio : Neg.neg '' Iio a = Ioi (-a) := by simp #align set.image_neg_Iio Set.image_neg_Iio theorem image_neg_Icc : Neg.neg '' Icc a b = Icc (-b) (-a) := by simp #align set.image_neg_Icc Set.image_neg_Icc theorem image_neg_Ico : Neg.neg '' Ico a b = Ioc (-b) (-a) := by simp #align set.image_neg_Ico Set.image_neg_Ico theorem image_neg_Ioc : Neg.neg '' Ioc a b = Ico (-b) (-a) := by simp #align set.image_neg_Ioc Set.image_neg_Ioc theorem image_neg_Ioo : Neg.neg '' Ioo a b = Ioo (-b) (-a) := by simp #align set.image_neg_Ioo Set.image_neg_Ioo /-! ### Images under `x ↦ a - x` -/ @[simp] theorem image_const_sub_Ici : (fun x => a - x) '' Ici b = Iic (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Ici Set.image_const_sub_Ici @[simp] theorem image_const_sub_Iic : (fun x => a - x) '' Iic b = Ici (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Iic Set.image_const_sub_Iic @[simp] theorem image_const_sub_Ioi : (fun x => a - x) '' Ioi b = Iio (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Ioi Set.image_const_sub_Ioi @[simp] theorem image_const_sub_Iio : (fun x => a - x) '' Iio b = Ioi (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Iio Set.image_const_sub_Iio @[simp] theorem image_const_sub_Icc : (fun x => a - x) '' Icc b c = Icc (a - c) (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Icc Set.image_const_sub_Icc @[simp] theorem image_const_sub_Ico : (fun x => a - x) '' Ico b c = Ioc (a - c) (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Ico Set.image_const_sub_Ico @[simp] theorem image_const_sub_Ioc : (fun x => a - x) '' Ioc b c = Ico (a - c) (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Ioc Set.image_const_sub_Ioc @[simp] theorem image_const_sub_Ioo : (fun x => a - x) '' Ioo b c = Ioo (a - c) (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Ioo Set.image_const_sub_Ioo /-! ### Images under `x ↦ x - a` -/ @[simp] theorem image_sub_const_Ici : (fun x => x - a) '' Ici b = Ici (b - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Ici Set.image_sub_const_Ici @[simp] theorem image_sub_const_Iic : (fun x => x - a) '' Iic b = Iic (b - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Iic Set.image_sub_const_Iic @[simp] theorem image_sub_const_Ioi : (fun x => x - a) '' Ioi b = Ioi (b - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Ioi Set.image_sub_const_Ioi @[simp] theorem image_sub_const_Iio : (fun x => x - a) '' Iio b = Iio (b - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Iio Set.image_sub_const_Iio @[simp] theorem image_sub_const_Icc : (fun x => x - a) '' Icc b c = Icc (b - a) (c - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Icc Set.image_sub_const_Icc @[simp] theorem image_sub_const_Ico : (fun x => x - a) '' Ico b c = Ico (b - a) (c - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Ico Set.image_sub_const_Ico @[simp] theorem image_sub_const_Ioc : (fun x => x - a) '' Ioc b c = Ioc (b - a) (c - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Ioc Set.image_sub_const_Ioc @[simp] theorem image_sub_const_Ioo : (fun x => x - a) '' Ioo b c = Ioo (b - a) (c - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Ioo Set.image_sub_const_Ioo /-! ### Bijections -/ theorem Iic_add_bij : BijOn (· + a) (Iic b) (Iic (b + a)) := image_add_const_Iic a b ▸ (add_left_injective _).injOn.bijOn_image #align set.Iic_add_bij Set.Iic_add_bij theorem Iio_add_bij : BijOn (· + a) (Iio b) (Iio (b + a)) := image_add_const_Iio a b ▸ (add_left_injective _).injOn.bijOn_image #align set.Iio_add_bij Set.Iio_add_bij end OrderedAddCommGroup section LinearOrderedAddCommGroup variable [LinearOrderedAddCommGroup α] (a b c d : α) @[simp] theorem preimage_const_add_uIcc : (fun x => a + x) ⁻¹' [[b, c]] = [[b - a, c - a]] := by simp only [← Icc_min_max, preimage_const_add_Icc, min_sub_sub_right, max_sub_sub_right] #align set.preimage_const_add_uIcc Set.preimage_const_add_uIcc @[simp] theorem preimage_add_const_uIcc : (fun x => x + a) ⁻¹' [[b, c]] = [[b - a, c - a]] := by simpa only [add_comm] using preimage_const_add_uIcc a b c #align set.preimage_add_const_uIcc Set.preimage_add_const_uIcc -- TODO: Why is the notation `-[[a, b]]` broken? @[simp] theorem preimage_neg_uIcc : @Neg.neg (Set α) Set.neg [[a, b]] = [[-a, -b]] := by simp only [← Icc_min_max, preimage_neg_Icc, min_neg_neg, max_neg_neg] #align set.preimage_neg_uIcc Set.preimage_neg_uIcc @[simp] theorem preimage_sub_const_uIcc : (fun x => x - a) ⁻¹' [[b, c]] = [[b + a, c + a]] := by simp [sub_eq_add_neg] #align set.preimage_sub_const_uIcc Set.preimage_sub_const_uIcc @[simp]
Mathlib/Data/Set/Pointwise/Interval.lean
534
536
theorem preimage_const_sub_uIcc : (fun x => a - x) ⁻¹' [[b, c]] = [[a - b, a - c]] := by
simp_rw [← Icc_min_max, preimage_const_sub_Icc] simp only [sub_eq_add_neg, min_add_add_left, max_add_add_left, min_neg_neg, max_neg_neg]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.MeasureTheory.Measure.MeasureSpace /-! # Restricting a measure to a subset or a subtype Given a measure `μ` on a type `α` and a subset `s` of `α`, we define a measure `μ.restrict s` as the restriction of `μ` to `s` (still as a measure on `α`). We investigate how this notion interacts with usual operations on measures (sum, pushforward, pullback), and on sets (inclusion, union, Union). We also study the relationship between the restriction of a measure to a subtype (given by the pullback under `Subtype.val`) and the restriction to a set as above. -/ open scoped ENNReal NNReal Topology open Set MeasureTheory Measure Filter MeasurableSpace ENNReal Function variable {R α β δ γ ι : Type*} namespace MeasureTheory variable {m0 : MeasurableSpace α} [MeasurableSpace β] [MeasurableSpace γ] variable {μ μ₁ μ₂ μ₃ ν ν' ν₁ ν₂ : Measure α} {s s' t : Set α} namespace Measure /-! ### Restricting a measure -/ /-- Restrict a measure `μ` to a set `s` as an `ℝ≥0∞`-linear map. -/ noncomputable def restrictₗ {m0 : MeasurableSpace α} (s : Set α) : Measure α →ₗ[ℝ≥0∞] Measure α := liftLinear (OuterMeasure.restrict s) fun μ s' hs' t => by suffices μ (s ∩ t) = μ (s ∩ t ∩ s') + μ ((s ∩ t) \ s') by simpa [← Set.inter_assoc, Set.inter_comm _ s, ← inter_diff_assoc] exact le_toOuterMeasure_caratheodory _ _ hs' _ #align measure_theory.measure.restrictₗ MeasureTheory.Measure.restrictₗ /-- Restrict a measure `μ` to a set `s`. -/ noncomputable def restrict {_m0 : MeasurableSpace α} (μ : Measure α) (s : Set α) : Measure α := restrictₗ s μ #align measure_theory.measure.restrict MeasureTheory.Measure.restrict @[simp] theorem restrictₗ_apply {_m0 : MeasurableSpace α} (s : Set α) (μ : Measure α) : restrictₗ s μ = μ.restrict s := rfl #align measure_theory.measure.restrictₗ_apply MeasureTheory.Measure.restrictₗ_apply /-- This lemma shows that `restrict` and `toOuterMeasure` commute. Note that the LHS has a restrict on measures and the RHS has a restrict on outer measures. -/ theorem restrict_toOuterMeasure_eq_toOuterMeasure_restrict (h : MeasurableSet s) : (μ.restrict s).toOuterMeasure = OuterMeasure.restrict s μ.toOuterMeasure := by simp_rw [restrict, restrictₗ, liftLinear, LinearMap.coe_mk, AddHom.coe_mk, toMeasure_toOuterMeasure, OuterMeasure.restrict_trim h, μ.trimmed] #align measure_theory.measure.restrict_to_outer_measure_eq_to_outer_measure_restrict MeasureTheory.Measure.restrict_toOuterMeasure_eq_toOuterMeasure_restrict theorem restrict_apply₀ (ht : NullMeasurableSet t (μ.restrict s)) : μ.restrict s t = μ (t ∩ s) := by rw [← restrictₗ_apply, restrictₗ, liftLinear_apply₀ _ ht, OuterMeasure.restrict_apply, coe_toOuterMeasure] #align measure_theory.measure.restrict_apply₀ MeasureTheory.Measure.restrict_apply₀ /-- If `t` is a measurable set, then the measure of `t` with respect to the restriction of the measure to `s` equals the outer measure of `t ∩ s`. An alternate version requiring that `s` be measurable instead of `t` exists as `Measure.restrict_apply'`. -/ @[simp] theorem restrict_apply (ht : MeasurableSet t) : μ.restrict s t = μ (t ∩ s) := restrict_apply₀ ht.nullMeasurableSet #align measure_theory.measure.restrict_apply MeasureTheory.Measure.restrict_apply /-- Restriction of a measure to a subset is monotone both in set and in measure. -/ theorem restrict_mono' {_m0 : MeasurableSpace α} ⦃s s' : Set α⦄ ⦃μ ν : Measure α⦄ (hs : s ≤ᵐ[μ] s') (hμν : μ ≤ ν) : μ.restrict s ≤ ν.restrict s' := Measure.le_iff.2 fun t ht => calc μ.restrict s t = μ (t ∩ s) := restrict_apply ht _ ≤ μ (t ∩ s') := (measure_mono_ae <| hs.mono fun _x hx ⟨hxt, hxs⟩ => ⟨hxt, hx hxs⟩) _ ≤ ν (t ∩ s') := le_iff'.1 hμν (t ∩ s') _ = ν.restrict s' t := (restrict_apply ht).symm #align measure_theory.measure.restrict_mono' MeasureTheory.Measure.restrict_mono' /-- Restriction of a measure to a subset is monotone both in set and in measure. -/ @[mono] theorem restrict_mono {_m0 : MeasurableSpace α} ⦃s s' : Set α⦄ (hs : s ⊆ s') ⦃μ ν : Measure α⦄ (hμν : μ ≤ ν) : μ.restrict s ≤ ν.restrict s' := restrict_mono' (ae_of_all _ hs) hμν #align measure_theory.measure.restrict_mono MeasureTheory.Measure.restrict_mono theorem restrict_mono_ae (h : s ≤ᵐ[μ] t) : μ.restrict s ≤ μ.restrict t := restrict_mono' h (le_refl μ) #align measure_theory.measure.restrict_mono_ae MeasureTheory.Measure.restrict_mono_ae theorem restrict_congr_set (h : s =ᵐ[μ] t) : μ.restrict s = μ.restrict t := le_antisymm (restrict_mono_ae h.le) (restrict_mono_ae h.symm.le) #align measure_theory.measure.restrict_congr_set MeasureTheory.Measure.restrict_congr_set /-- If `s` is a measurable set, then the outer measure of `t` with respect to the restriction of the measure to `s` equals the outer measure of `t ∩ s`. This is an alternate version of `Measure.restrict_apply`, requiring that `s` is measurable instead of `t`. -/ @[simp] theorem restrict_apply' (hs : MeasurableSet s) : μ.restrict s t = μ (t ∩ s) := by rw [← toOuterMeasure_apply, Measure.restrict_toOuterMeasure_eq_toOuterMeasure_restrict hs, OuterMeasure.restrict_apply s t _, toOuterMeasure_apply] #align measure_theory.measure.restrict_apply' MeasureTheory.Measure.restrict_apply' theorem restrict_apply₀' (hs : NullMeasurableSet s μ) : μ.restrict s t = μ (t ∩ s) := by rw [← restrict_congr_set hs.toMeasurable_ae_eq, restrict_apply' (measurableSet_toMeasurable _ _), measure_congr ((ae_eq_refl t).inter hs.toMeasurable_ae_eq)] #align measure_theory.measure.restrict_apply₀' MeasureTheory.Measure.restrict_apply₀' theorem restrict_le_self : μ.restrict s ≤ μ := Measure.le_iff.2 fun t ht => calc μ.restrict s t = μ (t ∩ s) := restrict_apply ht _ ≤ μ t := measure_mono inter_subset_left #align measure_theory.measure.restrict_le_self MeasureTheory.Measure.restrict_le_self variable (μ) theorem restrict_eq_self (h : s ⊆ t) : μ.restrict t s = μ s := (le_iff'.1 restrict_le_self s).antisymm <| calc μ s ≤ μ (toMeasurable (μ.restrict t) s ∩ t) := measure_mono (subset_inter (subset_toMeasurable _ _) h) _ = μ.restrict t s := by rw [← restrict_apply (measurableSet_toMeasurable _ _), measure_toMeasurable] #align measure_theory.measure.restrict_eq_self MeasureTheory.Measure.restrict_eq_self @[simp] theorem restrict_apply_self (s : Set α) : (μ.restrict s) s = μ s := restrict_eq_self μ Subset.rfl #align measure_theory.measure.restrict_apply_self MeasureTheory.Measure.restrict_apply_self variable {μ} theorem restrict_apply_univ (s : Set α) : μ.restrict s univ = μ s := by rw [restrict_apply MeasurableSet.univ, Set.univ_inter] #align measure_theory.measure.restrict_apply_univ MeasureTheory.Measure.restrict_apply_univ theorem le_restrict_apply (s t : Set α) : μ (t ∩ s) ≤ μ.restrict s t := calc μ (t ∩ s) = μ.restrict s (t ∩ s) := (restrict_eq_self μ inter_subset_right).symm _ ≤ μ.restrict s t := measure_mono inter_subset_left #align measure_theory.measure.le_restrict_apply MeasureTheory.Measure.le_restrict_apply theorem restrict_apply_le (s t : Set α) : μ.restrict s t ≤ μ t := Measure.le_iff'.1 restrict_le_self _ theorem restrict_apply_superset (h : s ⊆ t) : μ.restrict s t = μ s := ((measure_mono (subset_univ _)).trans_eq <| restrict_apply_univ _).antisymm ((restrict_apply_self μ s).symm.trans_le <| measure_mono h) #align measure_theory.measure.restrict_apply_superset MeasureTheory.Measure.restrict_apply_superset @[simp] theorem restrict_add {_m0 : MeasurableSpace α} (μ ν : Measure α) (s : Set α) : (μ + ν).restrict s = μ.restrict s + ν.restrict s := (restrictₗ s).map_add μ ν #align measure_theory.measure.restrict_add MeasureTheory.Measure.restrict_add @[simp] theorem restrict_zero {_m0 : MeasurableSpace α} (s : Set α) : (0 : Measure α).restrict s = 0 := (restrictₗ s).map_zero #align measure_theory.measure.restrict_zero MeasureTheory.Measure.restrict_zero @[simp] theorem restrict_smul {_m0 : MeasurableSpace α} (c : ℝ≥0∞) (μ : Measure α) (s : Set α) : (c • μ).restrict s = c • μ.restrict s := (restrictₗ s).map_smul c μ #align measure_theory.measure.restrict_smul MeasureTheory.Measure.restrict_smul theorem restrict_restrict₀ (hs : NullMeasurableSet s (μ.restrict t)) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) := ext fun u hu => by simp only [Set.inter_assoc, restrict_apply hu, restrict_apply₀ (hu.nullMeasurableSet.inter hs)] #align measure_theory.measure.restrict_restrict₀ MeasureTheory.Measure.restrict_restrict₀ @[simp] theorem restrict_restrict (hs : MeasurableSet s) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) := restrict_restrict₀ hs.nullMeasurableSet #align measure_theory.measure.restrict_restrict MeasureTheory.Measure.restrict_restrict theorem restrict_restrict_of_subset (h : s ⊆ t) : (μ.restrict t).restrict s = μ.restrict s := by ext1 u hu rw [restrict_apply hu, restrict_apply hu, restrict_eq_self] exact inter_subset_right.trans h #align measure_theory.measure.restrict_restrict_of_subset MeasureTheory.Measure.restrict_restrict_of_subset theorem restrict_restrict₀' (ht : NullMeasurableSet t μ) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) := ext fun u hu => by simp only [restrict_apply hu, restrict_apply₀' ht, inter_assoc] #align measure_theory.measure.restrict_restrict₀' MeasureTheory.Measure.restrict_restrict₀' theorem restrict_restrict' (ht : MeasurableSet t) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) := restrict_restrict₀' ht.nullMeasurableSet #align measure_theory.measure.restrict_restrict' MeasureTheory.Measure.restrict_restrict' theorem restrict_comm (hs : MeasurableSet s) : (μ.restrict t).restrict s = (μ.restrict s).restrict t := by rw [restrict_restrict hs, restrict_restrict' hs, inter_comm] #align measure_theory.measure.restrict_comm MeasureTheory.Measure.restrict_comm theorem restrict_apply_eq_zero (ht : MeasurableSet t) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 := by rw [restrict_apply ht] #align measure_theory.measure.restrict_apply_eq_zero MeasureTheory.Measure.restrict_apply_eq_zero theorem measure_inter_eq_zero_of_restrict (h : μ.restrict s t = 0) : μ (t ∩ s) = 0 := nonpos_iff_eq_zero.1 (h ▸ le_restrict_apply _ _) #align measure_theory.measure.measure_inter_eq_zero_of_restrict MeasureTheory.Measure.measure_inter_eq_zero_of_restrict theorem restrict_apply_eq_zero' (hs : MeasurableSet s) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 := by rw [restrict_apply' hs] #align measure_theory.measure.restrict_apply_eq_zero' MeasureTheory.Measure.restrict_apply_eq_zero' @[simp] theorem restrict_eq_zero : μ.restrict s = 0 ↔ μ s = 0 := by rw [← measure_univ_eq_zero, restrict_apply_univ] #align measure_theory.measure.restrict_eq_zero MeasureTheory.Measure.restrict_eq_zero /-- If `μ s ≠ 0`, then `μ.restrict s ≠ 0`, in terms of `NeZero` instances. -/ instance restrict.neZero [NeZero (μ s)] : NeZero (μ.restrict s) := ⟨mt restrict_eq_zero.mp <| NeZero.ne _⟩ theorem restrict_zero_set {s : Set α} (h : μ s = 0) : μ.restrict s = 0 := restrict_eq_zero.2 h #align measure_theory.measure.restrict_zero_set MeasureTheory.Measure.restrict_zero_set @[simp] theorem restrict_empty : μ.restrict ∅ = 0 := restrict_zero_set measure_empty #align measure_theory.measure.restrict_empty MeasureTheory.Measure.restrict_empty @[simp] theorem restrict_univ : μ.restrict univ = μ := ext fun s hs => by simp [hs] #align measure_theory.measure.restrict_univ MeasureTheory.Measure.restrict_univ theorem restrict_inter_add_diff₀ (s : Set α) (ht : NullMeasurableSet t μ) : μ.restrict (s ∩ t) + μ.restrict (s \ t) = μ.restrict s := by ext1 u hu simp only [add_apply, restrict_apply hu, ← inter_assoc, diff_eq] exact measure_inter_add_diff₀ (u ∩ s) ht #align measure_theory.measure.restrict_inter_add_diff₀ MeasureTheory.Measure.restrict_inter_add_diff₀ theorem restrict_inter_add_diff (s : Set α) (ht : MeasurableSet t) : μ.restrict (s ∩ t) + μ.restrict (s \ t) = μ.restrict s := restrict_inter_add_diff₀ s ht.nullMeasurableSet #align measure_theory.measure.restrict_inter_add_diff MeasureTheory.Measure.restrict_inter_add_diff theorem restrict_union_add_inter₀ (s : Set α) (ht : NullMeasurableSet t μ) : μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t := by rw [← restrict_inter_add_diff₀ (s ∪ t) ht, union_inter_cancel_right, union_diff_right, ← restrict_inter_add_diff₀ s ht, add_comm, ← add_assoc, add_right_comm] #align measure_theory.measure.restrict_union_add_inter₀ MeasureTheory.Measure.restrict_union_add_inter₀ theorem restrict_union_add_inter (s : Set α) (ht : MeasurableSet t) : μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t := restrict_union_add_inter₀ s ht.nullMeasurableSet #align measure_theory.measure.restrict_union_add_inter MeasureTheory.Measure.restrict_union_add_inter theorem restrict_union_add_inter' (hs : MeasurableSet s) (t : Set α) : μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t := by simpa only [union_comm, inter_comm, add_comm] using restrict_union_add_inter t hs #align measure_theory.measure.restrict_union_add_inter' MeasureTheory.Measure.restrict_union_add_inter' theorem restrict_union₀ (h : AEDisjoint μ s t) (ht : NullMeasurableSet t μ) : μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t := by simp [← restrict_union_add_inter₀ s ht, restrict_zero_set h] #align measure_theory.measure.restrict_union₀ MeasureTheory.Measure.restrict_union₀ theorem restrict_union (h : Disjoint s t) (ht : MeasurableSet t) : μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t := restrict_union₀ h.aedisjoint ht.nullMeasurableSet #align measure_theory.measure.restrict_union MeasureTheory.Measure.restrict_union theorem restrict_union' (h : Disjoint s t) (hs : MeasurableSet s) : μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t := by rw [union_comm, restrict_union h.symm hs, add_comm] #align measure_theory.measure.restrict_union' MeasureTheory.Measure.restrict_union' @[simp] theorem restrict_add_restrict_compl (hs : MeasurableSet s) : μ.restrict s + μ.restrict sᶜ = μ := by rw [← restrict_union (@disjoint_compl_right (Set α) _ _) hs.compl, union_compl_self, restrict_univ] #align measure_theory.measure.restrict_add_restrict_compl MeasureTheory.Measure.restrict_add_restrict_compl @[simp] theorem restrict_compl_add_restrict (hs : MeasurableSet s) : μ.restrict sᶜ + μ.restrict s = μ := by rw [add_comm, restrict_add_restrict_compl hs] #align measure_theory.measure.restrict_compl_add_restrict MeasureTheory.Measure.restrict_compl_add_restrict theorem restrict_union_le (s s' : Set α) : μ.restrict (s ∪ s') ≤ μ.restrict s + μ.restrict s' := le_iff.2 fun t ht ↦ by simpa [ht, inter_union_distrib_left] using measure_union_le (t ∩ s) (t ∩ s') #align measure_theory.measure.restrict_union_le MeasureTheory.Measure.restrict_union_le theorem restrict_iUnion_apply_ae [Countable ι] {s : ι → Set α} (hd : Pairwise (AEDisjoint μ on s)) (hm : ∀ i, NullMeasurableSet (s i) μ) {t : Set α} (ht : MeasurableSet t) : μ.restrict (⋃ i, s i) t = ∑' i, μ.restrict (s i) t := by simp only [restrict_apply, ht, inter_iUnion] exact measure_iUnion₀ (hd.mono fun i j h => h.mono inter_subset_right inter_subset_right) fun i => ht.nullMeasurableSet.inter (hm i) #align measure_theory.measure.restrict_Union_apply_ae MeasureTheory.Measure.restrict_iUnion_apply_ae theorem restrict_iUnion_apply [Countable ι] {s : ι → Set α} (hd : Pairwise (Disjoint on s)) (hm : ∀ i, MeasurableSet (s i)) {t : Set α} (ht : MeasurableSet t) : μ.restrict (⋃ i, s i) t = ∑' i, μ.restrict (s i) t := restrict_iUnion_apply_ae hd.aedisjoint (fun i => (hm i).nullMeasurableSet) ht #align measure_theory.measure.restrict_Union_apply MeasureTheory.Measure.restrict_iUnion_apply theorem restrict_iUnion_apply_eq_iSup [Countable ι] {s : ι → Set α} (hd : Directed (· ⊆ ·) s) {t : Set α} (ht : MeasurableSet t) : μ.restrict (⋃ i, s i) t = ⨆ i, μ.restrict (s i) t := by simp only [restrict_apply ht, inter_iUnion] rw [measure_iUnion_eq_iSup] exacts [hd.mono_comp _ fun s₁ s₂ => inter_subset_inter_right _] #align measure_theory.measure.restrict_Union_apply_eq_supr MeasureTheory.Measure.restrict_iUnion_apply_eq_iSup /-- The restriction of the pushforward measure is the pushforward of the restriction. For a version assuming only `AEMeasurable`, see `restrict_map_of_aemeasurable`. -/ theorem restrict_map {f : α → β} (hf : Measurable f) {s : Set β} (hs : MeasurableSet s) : (μ.map f).restrict s = (μ.restrict <| f ⁻¹' s).map f := ext fun t ht => by simp [*, hf ht] #align measure_theory.measure.restrict_map MeasureTheory.Measure.restrict_map theorem restrict_toMeasurable (h : μ s ≠ ∞) : μ.restrict (toMeasurable μ s) = μ.restrict s := ext fun t ht => by rw [restrict_apply ht, restrict_apply ht, inter_comm, measure_toMeasurable_inter ht h, inter_comm] #align measure_theory.measure.restrict_to_measurable MeasureTheory.Measure.restrict_toMeasurable theorem restrict_eq_self_of_ae_mem {_m0 : MeasurableSpace α} ⦃s : Set α⦄ ⦃μ : Measure α⦄ (hs : ∀ᵐ x ∂μ, x ∈ s) : μ.restrict s = μ := calc μ.restrict s = μ.restrict univ := restrict_congr_set (eventuallyEq_univ.mpr hs) _ = μ := restrict_univ #align measure_theory.measure.restrict_eq_self_of_ae_mem MeasureTheory.Measure.restrict_eq_self_of_ae_mem theorem restrict_congr_meas (hs : MeasurableSet s) : μ.restrict s = ν.restrict s ↔ ∀ t ⊆ s, MeasurableSet t → μ t = ν t := ⟨fun H t hts ht => by rw [← inter_eq_self_of_subset_left hts, ← restrict_apply ht, H, restrict_apply ht], fun H => ext fun t ht => by rw [restrict_apply ht, restrict_apply ht, H _ inter_subset_right (ht.inter hs)]⟩ #align measure_theory.measure.restrict_congr_meas MeasureTheory.Measure.restrict_congr_meas theorem restrict_congr_mono (hs : s ⊆ t) (h : μ.restrict t = ν.restrict t) : μ.restrict s = ν.restrict s := by rw [← restrict_restrict_of_subset hs, h, restrict_restrict_of_subset hs] #align measure_theory.measure.restrict_congr_mono MeasureTheory.Measure.restrict_congr_mono /-- If two measures agree on all measurable subsets of `s` and `t`, then they agree on all measurable subsets of `s ∪ t`. -/ theorem restrict_union_congr : μ.restrict (s ∪ t) = ν.restrict (s ∪ t) ↔ μ.restrict s = ν.restrict s ∧ μ.restrict t = ν.restrict t := by refine ⟨fun h => ⟨restrict_congr_mono subset_union_left h, restrict_congr_mono subset_union_right h⟩, ?_⟩ rintro ⟨hs, ht⟩ ext1 u hu simp only [restrict_apply hu, inter_union_distrib_left] rcases exists_measurable_superset₂ μ ν (u ∩ s) with ⟨US, hsub, hm, hμ, hν⟩ calc μ (u ∩ s ∪ u ∩ t) = μ (US ∪ u ∩ t) := measure_union_congr_of_subset hsub hμ.le Subset.rfl le_rfl _ = μ US + μ ((u ∩ t) \ US) := (measure_add_diff hm _).symm _ = restrict μ s u + restrict μ t (u \ US) := by simp only [restrict_apply, hu, hu.diff hm, hμ, ← inter_comm t, inter_diff_assoc] _ = restrict ν s u + restrict ν t (u \ US) := by rw [hs, ht] _ = ν US + ν ((u ∩ t) \ US) := by simp only [restrict_apply, hu, hu.diff hm, hν, ← inter_comm t, inter_diff_assoc] _ = ν (US ∪ u ∩ t) := measure_add_diff hm _ _ = ν (u ∩ s ∪ u ∩ t) := Eq.symm <| measure_union_congr_of_subset hsub hν.le Subset.rfl le_rfl #align measure_theory.measure.restrict_union_congr MeasureTheory.Measure.restrict_union_congr theorem restrict_finset_biUnion_congr {s : Finset ι} {t : ι → Set α} : μ.restrict (⋃ i ∈ s, t i) = ν.restrict (⋃ i ∈ s, t i) ↔ ∀ i ∈ s, μ.restrict (t i) = ν.restrict (t i) := by classical induction' s using Finset.induction_on with i s _ hs; · simp simp only [forall_eq_or_imp, iUnion_iUnion_eq_or_left, Finset.mem_insert] rw [restrict_union_congr, ← hs] #align measure_theory.measure.restrict_finset_bUnion_congr MeasureTheory.Measure.restrict_finset_biUnion_congr theorem restrict_iUnion_congr [Countable ι] {s : ι → Set α} : μ.restrict (⋃ i, s i) = ν.restrict (⋃ i, s i) ↔ ∀ i, μ.restrict (s i) = ν.restrict (s i) := by refine ⟨fun h i => restrict_congr_mono (subset_iUnion _ _) h, fun h => ?_⟩ ext1 t ht have D : Directed (· ⊆ ·) fun t : Finset ι => ⋃ i ∈ t, s i := Monotone.directed_le fun t₁ t₂ ht => biUnion_subset_biUnion_left ht rw [iUnion_eq_iUnion_finset] simp only [restrict_iUnion_apply_eq_iSup D ht, restrict_finset_biUnion_congr.2 fun i _ => h i] #align measure_theory.measure.restrict_Union_congr MeasureTheory.Measure.restrict_iUnion_congr theorem restrict_biUnion_congr {s : Set ι} {t : ι → Set α} (hc : s.Countable) : μ.restrict (⋃ i ∈ s, t i) = ν.restrict (⋃ i ∈ s, t i) ↔ ∀ i ∈ s, μ.restrict (t i) = ν.restrict (t i) := by haveI := hc.toEncodable simp only [biUnion_eq_iUnion, SetCoe.forall', restrict_iUnion_congr] #align measure_theory.measure.restrict_bUnion_congr MeasureTheory.Measure.restrict_biUnion_congr theorem restrict_sUnion_congr {S : Set (Set α)} (hc : S.Countable) : μ.restrict (⋃₀ S) = ν.restrict (⋃₀ S) ↔ ∀ s ∈ S, μ.restrict s = ν.restrict s := by rw [sUnion_eq_biUnion, restrict_biUnion_congr hc] #align measure_theory.measure.restrict_sUnion_congr MeasureTheory.Measure.restrict_sUnion_congr /-- This lemma shows that `Inf` and `restrict` commute for measures. -/ theorem restrict_sInf_eq_sInf_restrict {m0 : MeasurableSpace α} {m : Set (Measure α)} (hm : m.Nonempty) (ht : MeasurableSet t) : (sInf m).restrict t = sInf ((fun μ : Measure α => μ.restrict t) '' m) := by ext1 s hs simp_rw [sInf_apply hs, restrict_apply hs, sInf_apply (MeasurableSet.inter hs ht), Set.image_image, restrict_toOuterMeasure_eq_toOuterMeasure_restrict ht, ← Set.image_image _ toOuterMeasure, ← OuterMeasure.restrict_sInf_eq_sInf_restrict _ (hm.image _), OuterMeasure.restrict_apply] #align measure_theory.measure.restrict_Inf_eq_Inf_restrict MeasureTheory.Measure.restrict_sInf_eq_sInf_restrict theorem exists_mem_of_measure_ne_zero_of_ae (hs : μ s ≠ 0) {p : α → Prop} (hp : ∀ᵐ x ∂μ.restrict s, p x) : ∃ x, x ∈ s ∧ p x := by rw [← μ.restrict_apply_self, ← frequently_ae_mem_iff] at hs exact (hs.and_eventually hp).exists #align measure_theory.measure.exists_mem_of_measure_ne_zero_of_ae MeasureTheory.Measure.exists_mem_of_measure_ne_zero_of_ae /-! ### Extensionality results -/ /-- Two measures are equal if they have equal restrictions on a spanning collection of sets (formulated using `Union`). -/ theorem ext_iff_of_iUnion_eq_univ [Countable ι] {s : ι → Set α} (hs : ⋃ i, s i = univ) : μ = ν ↔ ∀ i, μ.restrict (s i) = ν.restrict (s i) := by rw [← restrict_iUnion_congr, hs, restrict_univ, restrict_univ] #align measure_theory.measure.ext_iff_of_Union_eq_univ MeasureTheory.Measure.ext_iff_of_iUnion_eq_univ alias ⟨_, ext_of_iUnion_eq_univ⟩ := ext_iff_of_iUnion_eq_univ #align measure_theory.measure.ext_of_Union_eq_univ MeasureTheory.Measure.ext_of_iUnion_eq_univ /-- Two measures are equal if they have equal restrictions on a spanning collection of sets (formulated using `biUnion`). -/ theorem ext_iff_of_biUnion_eq_univ {S : Set ι} {s : ι → Set α} (hc : S.Countable) (hs : ⋃ i ∈ S, s i = univ) : μ = ν ↔ ∀ i ∈ S, μ.restrict (s i) = ν.restrict (s i) := by rw [← restrict_biUnion_congr hc, hs, restrict_univ, restrict_univ] #align measure_theory.measure.ext_iff_of_bUnion_eq_univ MeasureTheory.Measure.ext_iff_of_biUnion_eq_univ alias ⟨_, ext_of_biUnion_eq_univ⟩ := ext_iff_of_biUnion_eq_univ #align measure_theory.measure.ext_of_bUnion_eq_univ MeasureTheory.Measure.ext_of_biUnion_eq_univ /-- Two measures are equal if they have equal restrictions on a spanning collection of sets (formulated using `sUnion`). -/ theorem ext_iff_of_sUnion_eq_univ {S : Set (Set α)} (hc : S.Countable) (hs : ⋃₀ S = univ) : μ = ν ↔ ∀ s ∈ S, μ.restrict s = ν.restrict s := ext_iff_of_biUnion_eq_univ hc <| by rwa [← sUnion_eq_biUnion] #align measure_theory.measure.ext_iff_of_sUnion_eq_univ MeasureTheory.Measure.ext_iff_of_sUnion_eq_univ alias ⟨_, ext_of_sUnion_eq_univ⟩ := ext_iff_of_sUnion_eq_univ #align measure_theory.measure.ext_of_sUnion_eq_univ MeasureTheory.Measure.ext_of_sUnion_eq_univ theorem ext_of_generateFrom_of_cover {S T : Set (Set α)} (h_gen : ‹_› = generateFrom S) (hc : T.Countable) (h_inter : IsPiSystem S) (hU : ⋃₀ T = univ) (htop : ∀ t ∈ T, μ t ≠ ∞) (ST_eq : ∀ t ∈ T, ∀ s ∈ S, μ (s ∩ t) = ν (s ∩ t)) (T_eq : ∀ t ∈ T, μ t = ν t) : μ = ν := by refine ext_of_sUnion_eq_univ hc hU fun t ht => ?_ ext1 u hu simp only [restrict_apply hu] refine induction_on_inter h_gen h_inter ?_ (ST_eq t ht) ?_ ?_ hu · simp only [Set.empty_inter, measure_empty] · intro v hv hvt have := T_eq t ht rw [Set.inter_comm] at hvt ⊢ rwa [← measure_inter_add_diff t hv, ← measure_inter_add_diff t hv, ← hvt, ENNReal.add_right_inj] at this exact ne_top_of_le_ne_top (htop t ht) (measure_mono Set.inter_subset_left) · intro f hfd hfm h_eq simp only [← restrict_apply (hfm _), ← restrict_apply (MeasurableSet.iUnion hfm)] at h_eq ⊢ simp only [measure_iUnion hfd hfm, h_eq] #align measure_theory.measure.ext_of_generate_from_of_cover MeasureTheory.Measure.ext_of_generateFrom_of_cover /-- Two measures are equal if they are equal on the π-system generating the σ-algebra, and they are both finite on an increasing spanning sequence of sets in the π-system. This lemma is formulated using `sUnion`. -/ theorem ext_of_generateFrom_of_cover_subset {S T : Set (Set α)} (h_gen : ‹_› = generateFrom S) (h_inter : IsPiSystem S) (h_sub : T ⊆ S) (hc : T.Countable) (hU : ⋃₀ T = univ) (htop : ∀ s ∈ T, μ s ≠ ∞) (h_eq : ∀ s ∈ S, μ s = ν s) : μ = ν := by refine ext_of_generateFrom_of_cover h_gen hc h_inter hU htop ?_ fun t ht => h_eq t (h_sub ht) intro t ht s hs; rcases (s ∩ t).eq_empty_or_nonempty with H | H · simp only [H, measure_empty] · exact h_eq _ (h_inter _ hs _ (h_sub ht) H) #align measure_theory.measure.ext_of_generate_from_of_cover_subset MeasureTheory.Measure.ext_of_generateFrom_of_cover_subset /-- Two measures are equal if they are equal on the π-system generating the σ-algebra, and they are both finite on an increasing spanning sequence of sets in the π-system. This lemma is formulated using `iUnion`. `FiniteSpanningSetsIn.ext` is a reformulation of this lemma. -/ theorem ext_of_generateFrom_of_iUnion (C : Set (Set α)) (B : ℕ → Set α) (hA : ‹_› = generateFrom C) (hC : IsPiSystem C) (h1B : ⋃ i, B i = univ) (h2B : ∀ i, B i ∈ C) (hμB : ∀ i, μ (B i) ≠ ∞) (h_eq : ∀ s ∈ C, μ s = ν s) : μ = ν := by refine ext_of_generateFrom_of_cover_subset hA hC ?_ (countable_range B) h1B ?_ h_eq · rintro _ ⟨i, rfl⟩ apply h2B · rintro _ ⟨i, rfl⟩ apply hμB #align measure_theory.measure.ext_of_generate_from_of_Union MeasureTheory.Measure.ext_of_generateFrom_of_iUnion @[simp] theorem restrict_sum (μ : ι → Measure α) {s : Set α} (hs : MeasurableSet s) : (sum μ).restrict s = sum fun i => (μ i).restrict s := ext fun t ht => by simp only [sum_apply, restrict_apply, ht, ht.inter hs] #align measure_theory.measure.restrict_sum MeasureTheory.Measure.restrict_sum @[simp] theorem restrict_sum_of_countable [Countable ι] (μ : ι → Measure α) (s : Set α) : (sum μ).restrict s = sum fun i => (μ i).restrict s := by ext t ht simp_rw [sum_apply _ ht, restrict_apply ht, sum_apply_of_countable] lemma AbsolutelyContinuous.restrict (h : μ ≪ ν) (s : Set α) : μ.restrict s ≪ ν.restrict s := by refine Measure.AbsolutelyContinuous.mk (fun t ht htν ↦ ?_) rw [restrict_apply ht] at htν ⊢ exact h htν theorem restrict_iUnion_ae [Countable ι] {s : ι → Set α} (hd : Pairwise (AEDisjoint μ on s)) (hm : ∀ i, NullMeasurableSet (s i) μ) : μ.restrict (⋃ i, s i) = sum fun i => μ.restrict (s i) := ext fun t ht => by simp only [sum_apply _ ht, restrict_iUnion_apply_ae hd hm ht] #align measure_theory.measure.restrict_Union_ae MeasureTheory.Measure.restrict_iUnion_ae theorem restrict_iUnion [Countable ι] {s : ι → Set α} (hd : Pairwise (Disjoint on s)) (hm : ∀ i, MeasurableSet (s i)) : μ.restrict (⋃ i, s i) = sum fun i => μ.restrict (s i) := restrict_iUnion_ae hd.aedisjoint fun i => (hm i).nullMeasurableSet #align measure_theory.measure.restrict_Union MeasureTheory.Measure.restrict_iUnion theorem restrict_iUnion_le [Countable ι] {s : ι → Set α} : μ.restrict (⋃ i, s i) ≤ sum fun i => μ.restrict (s i) := le_iff.2 fun t ht ↦ by simpa [ht, inter_iUnion] using measure_iUnion_le (t ∩ s ·) #align measure_theory.measure.restrict_Union_le MeasureTheory.Measure.restrict_iUnion_le end Measure @[simp] theorem ae_restrict_iUnion_eq [Countable ι] (s : ι → Set α) : ae (μ.restrict (⋃ i, s i)) = ⨆ i, ae (μ.restrict (s i)) := le_antisymm ((ae_sum_eq fun i => μ.restrict (s i)) ▸ ae_mono restrict_iUnion_le) <| iSup_le fun i => ae_mono <| restrict_mono (subset_iUnion s i) le_rfl #align measure_theory.ae_restrict_Union_eq MeasureTheory.ae_restrict_iUnion_eq @[simp] theorem ae_restrict_union_eq (s t : Set α) : ae (μ.restrict (s ∪ t)) = ae (μ.restrict s) ⊔ ae (μ.restrict t) := by simp [union_eq_iUnion, iSup_bool_eq] #align measure_theory.ae_restrict_union_eq MeasureTheory.ae_restrict_union_eq theorem ae_restrict_biUnion_eq (s : ι → Set α) {t : Set ι} (ht : t.Countable) : ae (μ.restrict (⋃ i ∈ t, s i)) = ⨆ i ∈ t, ae (μ.restrict (s i)) := by haveI := ht.to_subtype rw [biUnion_eq_iUnion, ae_restrict_iUnion_eq, ← iSup_subtype''] #align measure_theory.ae_restrict_bUnion_eq MeasureTheory.ae_restrict_biUnion_eq theorem ae_restrict_biUnion_finset_eq (s : ι → Set α) (t : Finset ι) : ae (μ.restrict (⋃ i ∈ t, s i)) = ⨆ i ∈ t, ae (μ.restrict (s i)) := ae_restrict_biUnion_eq s t.countable_toSet #align measure_theory.ae_restrict_bUnion_finset_eq MeasureTheory.ae_restrict_biUnion_finset_eq theorem ae_restrict_iUnion_iff [Countable ι] (s : ι → Set α) (p : α → Prop) : (∀ᵐ x ∂μ.restrict (⋃ i, s i), p x) ↔ ∀ i, ∀ᵐ x ∂μ.restrict (s i), p x := by simp #align measure_theory.ae_restrict_Union_iff MeasureTheory.ae_restrict_iUnion_iff theorem ae_restrict_union_iff (s t : Set α) (p : α → Prop) : (∀ᵐ x ∂μ.restrict (s ∪ t), p x) ↔ (∀ᵐ x ∂μ.restrict s, p x) ∧ ∀ᵐ x ∂μ.restrict t, p x := by simp #align measure_theory.ae_restrict_union_iff MeasureTheory.ae_restrict_union_iff theorem ae_restrict_biUnion_iff (s : ι → Set α) {t : Set ι} (ht : t.Countable) (p : α → Prop) : (∀ᵐ x ∂μ.restrict (⋃ i ∈ t, s i), p x) ↔ ∀ i ∈ t, ∀ᵐ x ∂μ.restrict (s i), p x := by simp_rw [Filter.Eventually, ae_restrict_biUnion_eq s ht, mem_iSup] #align measure_theory.ae_restrict_bUnion_iff MeasureTheory.ae_restrict_biUnion_iff @[simp] theorem ae_restrict_biUnion_finset_iff (s : ι → Set α) (t : Finset ι) (p : α → Prop) : (∀ᵐ x ∂μ.restrict (⋃ i ∈ t, s i), p x) ↔ ∀ i ∈ t, ∀ᵐ x ∂μ.restrict (s i), p x := by simp_rw [Filter.Eventually, ae_restrict_biUnion_finset_eq s, mem_iSup] #align measure_theory.ae_restrict_bUnion_finset_iff MeasureTheory.ae_restrict_biUnion_finset_iff theorem ae_eq_restrict_iUnion_iff [Countable ι] (s : ι → Set α) (f g : α → δ) : f =ᵐ[μ.restrict (⋃ i, s i)] g ↔ ∀ i, f =ᵐ[μ.restrict (s i)] g := by simp_rw [EventuallyEq, ae_restrict_iUnion_eq, eventually_iSup] #align measure_theory.ae_eq_restrict_Union_iff MeasureTheory.ae_eq_restrict_iUnion_iff theorem ae_eq_restrict_biUnion_iff (s : ι → Set α) {t : Set ι} (ht : t.Countable) (f g : α → δ) : f =ᵐ[μ.restrict (⋃ i ∈ t, s i)] g ↔ ∀ i ∈ t, f =ᵐ[μ.restrict (s i)] g := by simp_rw [ae_restrict_biUnion_eq s ht, EventuallyEq, eventually_iSup] #align measure_theory.ae_eq_restrict_bUnion_iff MeasureTheory.ae_eq_restrict_biUnion_iff theorem ae_eq_restrict_biUnion_finset_iff (s : ι → Set α) (t : Finset ι) (f g : α → δ) : f =ᵐ[μ.restrict (⋃ i ∈ t, s i)] g ↔ ∀ i ∈ t, f =ᵐ[μ.restrict (s i)] g := ae_eq_restrict_biUnion_iff s t.countable_toSet f g #align measure_theory.ae_eq_restrict_bUnion_finset_iff MeasureTheory.ae_eq_restrict_biUnion_finset_iff theorem ae_restrict_uIoc_eq [LinearOrder α] (a b : α) : ae (μ.restrict (Ι a b)) = ae (μ.restrict (Ioc a b)) ⊔ ae (μ.restrict (Ioc b a)) := by simp only [uIoc_eq_union, ae_restrict_union_eq] #align measure_theory.ae_restrict_uIoc_eq MeasureTheory.ae_restrict_uIoc_eq /-- See also `MeasureTheory.ae_uIoc_iff`. -/ theorem ae_restrict_uIoc_iff [LinearOrder α] {a b : α} {P : α → Prop} : (∀ᵐ x ∂μ.restrict (Ι a b), P x) ↔ (∀ᵐ x ∂μ.restrict (Ioc a b), P x) ∧ ∀ᵐ x ∂μ.restrict (Ioc b a), P x := by rw [ae_restrict_uIoc_eq, eventually_sup] #align measure_theory.ae_restrict_uIoc_iff MeasureTheory.ae_restrict_uIoc_iff
Mathlib/MeasureTheory/Measure/Restrict.lean
614
617
theorem ae_restrict_iff₀ {p : α → Prop} (hp : NullMeasurableSet { x | p x } (μ.restrict s)) : (∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x := by
simp only [ae_iff, ← compl_setOf, Measure.restrict_apply₀ hp.compl] rw [iff_iff_eq]; congr with x; simp [and_comm]
/- Copyright (c) 2023 Bulhwi Cha. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bulhwi Cha, Mario Carneiro -/ import Batteries.Data.Char import Batteries.Data.List.Lemmas import Batteries.Data.String.Basic import Batteries.Tactic.Lint.Misc import Batteries.Tactic.SeqFocus namespace String attribute [ext] ext theorem lt_trans {s₁ s₂ s₃ : String} : s₁ < s₂ → s₂ < s₃ → s₁ < s₃ := List.lt_trans' (α := Char) Nat.lt_trans (fun h1 h2 => Nat.not_lt.2 <| Nat.le_trans (Nat.not_lt.1 h2) (Nat.not_lt.1 h1)) theorem lt_antisymm {s₁ s₂ : String} (h₁ : ¬s₁ < s₂) (h₂ : ¬s₂ < s₁) : s₁ = s₂ := ext <| List.lt_antisymm' (α := Char) (fun h1 h2 => Char.le_antisymm (Nat.not_lt.1 h2) (Nat.not_lt.1 h1)) h₁ h₂ instance : Batteries.TransOrd String := .compareOfLessAndEq String.lt_irrefl String.lt_trans String.lt_antisymm instance : Batteries.LTOrd String := .compareOfLessAndEq String.lt_irrefl String.lt_trans String.lt_antisymm instance : Batteries.BEqOrd String := .compareOfLessAndEq String.lt_irrefl @[simp] theorem mk_length (s : List Char) : (String.mk s).length = s.length := rfl attribute [simp] toList -- prefer `String.data` over `String.toList` in lemmas private theorem add_csize_pos : 0 < i + csize c := Nat.add_pos_right _ (csize_pos c) private theorem ne_add_csize_add_self : i ≠ n + csize c + i := Nat.ne_of_lt (Nat.lt_add_of_pos_left add_csize_pos) private theorem ne_self_add_add_csize : i ≠ i + (n + csize c) := Nat.ne_of_lt (Nat.lt_add_of_pos_right add_csize_pos) /-- The UTF-8 byte length of a list of characters. (This is intended for specification purposes.) -/ @[inline] def utf8Len : List Char → Nat := utf8ByteSize.go @[simp] theorem utf8ByteSize.go_eq : utf8ByteSize.go = utf8Len := rfl @[simp] theorem utf8ByteSize_mk (cs) : utf8ByteSize ⟨cs⟩ = utf8Len cs := rfl @[simp] theorem utf8Len_nil : utf8Len [] = 0 := rfl @[simp] theorem utf8Len_cons (c cs) : utf8Len (c :: cs) = utf8Len cs + csize c := rfl @[simp] theorem utf8Len_append (cs₁ cs₂) : utf8Len (cs₁ ++ cs₂) = utf8Len cs₁ + utf8Len cs₂ := by induction cs₁ <;> simp [*, Nat.add_right_comm] @[simp] theorem utf8Len_reverseAux (cs₁ cs₂) : utf8Len (cs₁.reverseAux cs₂) = utf8Len cs₁ + utf8Len cs₂ := by induction cs₁ generalizing cs₂ <;> simp [*, ← Nat.add_assoc, Nat.add_right_comm] @[simp] theorem utf8Len_reverse (cs) : utf8Len cs.reverse = utf8Len cs := utf8Len_reverseAux .. @[simp] theorem utf8Len_eq_zero : utf8Len l = 0 ↔ l = [] := by cases l <;> simp [Nat.ne_of_gt add_csize_pos] section open List theorem utf8Len_le_of_sublist : ∀ {cs₁ cs₂}, cs₁ <+ cs₂ → utf8Len cs₁ ≤ utf8Len cs₂ | _, _, .slnil => Nat.le_refl _ | _, _, .cons _ h => Nat.le_trans (utf8Len_le_of_sublist h) (Nat.le_add_right ..) | _, _, .cons₂ _ h => Nat.add_le_add_right (utf8Len_le_of_sublist h) _ theorem utf8Len_le_of_infix (h : cs₁ <:+: cs₂) : utf8Len cs₁ ≤ utf8Len cs₂ := utf8Len_le_of_sublist h.sublist theorem utf8Len_le_of_suffix (h : cs₁ <:+ cs₂) : utf8Len cs₁ ≤ utf8Len cs₂ := utf8Len_le_of_sublist h.sublist theorem utf8Len_le_of_prefix (h : cs₁ <+: cs₂) : utf8Len cs₁ ≤ utf8Len cs₂ := utf8Len_le_of_sublist h.sublist end @[simp] theorem endPos_eq (cs : List Char) : endPos ⟨cs⟩ = ⟨utf8Len cs⟩ := rfl namespace Pos attribute [ext] ext theorem lt_addChar (p : Pos) (c : Char) : p < p + c := Nat.lt_add_of_pos_right (csize_pos _) private theorem zero_ne_addChar {i : Pos} {c : Char} : 0 ≠ i + c := ne_of_lt add_csize_pos /-- A string position is valid if it is equal to the UTF-8 length of an initial substring of `s`. -/ def Valid (s : String) (p : Pos) : Prop := ∃ cs cs', cs ++ cs' = s.1 ∧ p.1 = utf8Len cs @[simp] theorem valid_zero : Valid s 0 := ⟨[], s.1, rfl, rfl⟩ @[simp] theorem valid_endPos : Valid s (endPos s) := ⟨s.1, [], by simp, rfl⟩ theorem Valid.mk (cs cs' : List Char) : Valid ⟨cs ++ cs'⟩ ⟨utf8Len cs⟩ := ⟨cs, cs', rfl, rfl⟩ theorem Valid.le_endPos : ∀ {s p}, Valid s p → p ≤ endPos s | ⟨_⟩, ⟨_⟩, ⟨cs, cs', rfl, rfl⟩ => by simp [Nat.le_add_right] end Pos theorem endPos_eq_zero : ∀ (s : String), endPos s = 0 ↔ s = "" | ⟨_⟩ => Pos.ext_iff.trans <| utf8Len_eq_zero.trans ext_iff.symm theorem isEmpty_iff (s : String) : isEmpty s ↔ s = "" := (beq_iff_eq ..).trans (endPos_eq_zero _) /-- Induction along the valid positions in a list of characters. (This definition is intended only for specification purposes.) -/ def utf8InductionOn {motive : List Char → Pos → Sort u} (s : List Char) (i p : Pos) (nil : ∀ i, motive [] i) (eq : ∀ c cs, motive (c :: cs) p) (ind : ∀ (c : Char) cs i, i ≠ p → motive cs (i + c) → motive (c :: cs) i) : motive s i := match s with | [] => nil i | c::cs => if h : i = p then h ▸ eq c cs else ind c cs i h (utf8InductionOn cs (i + c) p nil eq ind) theorem utf8GetAux_add_right_cancel (s : List Char) (i p n : Nat) : utf8GetAux s ⟨i + n⟩ ⟨p + n⟩ = utf8GetAux s ⟨i⟩ ⟨p⟩ := by apply utf8InductionOn s ⟨i⟩ ⟨p⟩ (motive := fun s i => utf8GetAux s ⟨i.byteIdx + n⟩ ⟨p + n⟩ = utf8GetAux s i ⟨p⟩) <;> simp [utf8GetAux] intro c cs ⟨i⟩ h ih simp [Pos.ext_iff, Pos.addChar_eq] at h ⊢ simp [Nat.add_right_cancel_iff, h] rw [Nat.add_right_comm] exact ih theorem utf8GetAux_addChar_right_cancel (s : List Char) (i p : Pos) (c : Char) : utf8GetAux s (i + c) (p + c) = utf8GetAux s i p := utf8GetAux_add_right_cancel .. theorem utf8GetAux_of_valid (cs cs' : List Char) {i p : Nat} (hp : i + utf8Len cs = p) : utf8GetAux (cs ++ cs') ⟨i⟩ ⟨p⟩ = cs'.headD default := by match cs, cs' with | [], [] => rfl | [], c::cs' => simp [← hp, utf8GetAux] | c::cs, cs' => simp [utf8GetAux, -List.headD_eq_head?]; rw [if_neg] case hnc => simp [← hp, Pos.ext_iff]; exact ne_self_add_add_csize refine utf8GetAux_of_valid cs cs' ?_ simpa [Nat.add_assoc, Nat.add_comm] using hp theorem get_of_valid (cs cs' : List Char) : get ⟨cs ++ cs'⟩ ⟨utf8Len cs⟩ = cs'.headD default := utf8GetAux_of_valid _ _ (Nat.zero_add _) theorem get_cons_addChar (c : Char) (cs : List Char) (i : Pos) : get ⟨c :: cs⟩ (i + c) = get ⟨cs⟩ i := by simp [get, utf8GetAux, Pos.zero_ne_addChar, utf8GetAux_addChar_right_cancel] theorem utf8GetAux?_of_valid (cs cs' : List Char) {i p : Nat} (hp : i + utf8Len cs = p) : utf8GetAux? (cs ++ cs') ⟨i⟩ ⟨p⟩ = cs'.head? := by match cs, cs' with | [], [] => rfl | [], c::cs' => simp [← hp, utf8GetAux?] | c::cs, cs' => simp [utf8GetAux?]; rw [if_neg] case hnc => simp [← hp, Pos.ext_iff]; exact ne_self_add_add_csize refine utf8GetAux?_of_valid cs cs' ?_ simpa [Nat.add_assoc, Nat.add_comm] using hp theorem get?_of_valid (cs cs' : List Char) : get? ⟨cs ++ cs'⟩ ⟨utf8Len cs⟩ = cs'.head? := utf8GetAux?_of_valid _ _ (Nat.zero_add _) theorem utf8SetAux_of_valid (c' : Char) (cs cs' : List Char) {i p : Nat} (hp : i + utf8Len cs = p) : utf8SetAux c' (cs ++ cs') ⟨i⟩ ⟨p⟩ = cs ++ cs'.modifyHead fun _ => c' := by match cs, cs' with | [], [] => rfl | [], c::cs' => simp [← hp, utf8SetAux] | c::cs, cs' => simp [utf8SetAux]; rw [if_neg] case hnc => simp [← hp, Pos.ext_iff]; exact ne_self_add_add_csize refine congrArg (c::·) (utf8SetAux_of_valid c' cs cs' ?_) simpa [Nat.add_assoc, Nat.add_comm] using hp theorem set_of_valid (cs cs' : List Char) (c' : Char) : set ⟨cs ++ cs'⟩ ⟨utf8Len cs⟩ c' = ⟨cs ++ cs'.modifyHead fun _ => c'⟩ := ext (utf8SetAux_of_valid _ _ _ (Nat.zero_add _)) theorem modify_of_valid (cs cs' : List Char) : modify ⟨cs ++ cs'⟩ ⟨utf8Len cs⟩ f = ⟨cs ++ cs'.modifyHead f⟩ := by rw [modify, set_of_valid, get_of_valid]; cases cs' <;> rfl theorem next_of_valid' (cs cs' : List Char) : next ⟨cs ++ cs'⟩ ⟨utf8Len cs⟩ = ⟨utf8Len cs + csize (cs'.headD default)⟩ := by simp only [next, get_of_valid]; rfl theorem next_of_valid (cs : List Char) (c : Char) (cs' : List Char) : next ⟨cs ++ c :: cs'⟩ ⟨utf8Len cs⟩ = ⟨utf8Len cs + csize c⟩ := next_of_valid' .. @[simp] theorem atEnd_iff (s : String) (p : Pos) : atEnd s p ↔ s.endPos ≤ p := decide_eq_true_iff _ theorem valid_next {p : Pos} (h : p.Valid s) (h₂ : p < s.endPos) : (next s p).Valid s := by match s, p, h with | ⟨_⟩, ⟨_⟩, ⟨cs, [], rfl, rfl⟩ => simp at h₂ | ⟨_⟩, ⟨_⟩, ⟨cs, c::cs', rfl, rfl⟩ => rw [utf8ByteSize.go_eq, next_of_valid] simpa using Pos.Valid.mk (cs ++ [c]) cs' theorem utf8PrevAux_of_valid {cs cs' : List Char} {c : Char} {i p : Nat} (hp : i + (utf8Len cs + csize c) = p) : utf8PrevAux (cs ++ c :: cs') ⟨i⟩ ⟨p⟩ = ⟨i + utf8Len cs⟩ := by match cs with | [] => simp [utf8PrevAux, ← hp, Pos.addChar_eq] | c'::cs => simp [utf8PrevAux, Pos.addChar_eq, ← hp]; rw [if_neg] case hnc => simp [Pos.ext_iff]; rw [Nat.add_right_comm, Nat.add_left_comm]; apply ne_add_csize_add_self refine (utf8PrevAux_of_valid (by simp [Nat.add_assoc, Nat.add_left_comm])).trans ?_ simp [Nat.add_assoc, Nat.add_comm] theorem prev_of_valid (cs : List Char) (c : Char) (cs' : List Char) : prev ⟨cs ++ c :: cs'⟩ ⟨utf8Len cs + csize c⟩ = ⟨utf8Len cs⟩ := by simp [prev]; refine (if_neg (Pos.ne_of_gt add_csize_pos)).trans ?_ rw [utf8PrevAux_of_valid] <;> simp theorem prev_of_valid' (cs cs' : List Char) : prev ⟨cs ++ cs'⟩ ⟨utf8Len cs⟩ = ⟨utf8Len cs.dropLast⟩ := by match cs, cs.eq_nil_or_concat with | _, .inl rfl => rfl | _, .inr ⟨cs, c, rfl⟩ => simp [prev_of_valid] theorem front_eq (s : String) : front s = s.1.headD default := by unfold front; exact get_of_valid [] s.1 theorem back_eq (s : String) : back s = s.1.getLastD default := by match s, s.1.eq_nil_or_concat with | ⟨_⟩, .inl rfl => rfl | ⟨_⟩, .inr ⟨cs, c, rfl⟩ => simp [back, prev_of_valid, get_of_valid] theorem atEnd_of_valid (cs : List Char) (cs' : List Char) : atEnd ⟨cs ++ cs'⟩ ⟨utf8Len cs⟩ ↔ cs' = [] := by rw [atEnd_iff] cases cs' <;> simp [Nat.lt_add_of_pos_right add_csize_pos] unseal posOfAux findAux in theorem posOfAux_eq (s c) : posOfAux s c = findAux s (· == c) := rfl unseal posOfAux findAux in theorem posOf_eq (s c) : posOf s c = find s (· == c) := rfl unseal revPosOfAux revFindAux in theorem revPosOfAux_eq (s c) : revPosOfAux s c = revFindAux s (· == c) := rfl unseal revPosOfAux revFindAux in theorem revPosOf_eq (s c) : revPosOf s c = revFind s (· == c) := rfl @[nolint unusedHavesSuffices] -- false positive from unfolding String.findAux theorem findAux_of_valid (p) : ∀ l m r, findAux ⟨l ++ m ++ r⟩ p ⟨utf8Len l + utf8Len m⟩ ⟨utf8Len l⟩ = ⟨utf8Len l + utf8Len (m.takeWhile (!p ·))⟩ | l, [], r => by unfold findAux List.takeWhile; simp | l, c::m, r => by unfold findAux List.takeWhile rw [dif_pos (by exact Nat.lt_add_of_pos_right add_csize_pos)] have h1 := get_of_valid l (c::m++r); have h2 := next_of_valid l c (m++r) simp at h1 h2; simp [h1, h2] cases p c <;> simp have foo := findAux_of_valid p (l++[c]) m r; simp at foo rw [Nat.add_right_comm, Nat.add_assoc] at foo rw [foo, Nat.add_right_comm, Nat.add_assoc] theorem find_of_valid (p s) : find s p = ⟨utf8Len (s.1.takeWhile (!p ·))⟩ := by simpa using findAux_of_valid p [] s.1 [] @[nolint unusedHavesSuffices] -- false positive from unfolding String.revFindAux theorem revFindAux_of_valid (p) : ∀ l r, revFindAux ⟨l.reverse ++ r⟩ p ⟨utf8Len l⟩ = (l.dropWhile (!p ·)).tail?.map (⟨utf8Len ·⟩) | [], r => by unfold revFindAux List.dropWhile; simp | c::l, r => by unfold revFindAux List.dropWhile rw [dif_neg (by exact Pos.ne_of_gt add_csize_pos)] have h1 := get_of_valid l.reverse (c::r); have h2 := prev_of_valid l.reverse c r simp at h1 h2; simp [h1, h2] cases p c <;> simp exact revFindAux_of_valid p l (c::r) theorem revFind_of_valid (p s) : revFind s p = (s.1.reverse.dropWhile (!p ·)).tail?.map (⟨utf8Len ·⟩) := by simpa using revFindAux_of_valid p s.1.reverse [] theorem firstDiffPos_loop_eq (l₁ l₂ r₁ r₂ stop p) (hl₁ : p = utf8Len l₁) (hl₂ : p = utf8Len l₂) (hstop : stop = min (utf8Len l₁ + utf8Len r₁) (utf8Len l₂ + utf8Len r₂)) : firstDiffPos.loop ⟨l₁ ++ r₁⟩ ⟨l₂ ++ r₂⟩ ⟨stop⟩ ⟨p⟩ = ⟨p + utf8Len (List.takeWhile₂ (· = ·) r₁ r₂).1⟩ := by unfold List.takeWhile₂; split <;> unfold firstDiffPos.loop · next a r₁ b r₂ => rw [ dif_pos <| by rw [hstop, ← hl₁, ← hl₂] refine Nat.lt_min.2 ⟨?_, ?_⟩ <;> exact Nat.lt_add_of_pos_right add_csize_pos, show get ⟨l₁ ++ a :: r₁⟩ ⟨p⟩ = a by simp [hl₁, get_of_valid], show get ⟨l₂ ++ b :: r₂⟩ ⟨p⟩ = b by simp [hl₂, get_of_valid]] simp; split <;> simp subst b rw [show next ⟨l₁ ++ a :: r₁⟩ ⟨p⟩ = ⟨utf8Len l₁ + csize a⟩ by simp [hl₁, next_of_valid]] simpa [← hl₁, ← Nat.add_assoc, Nat.add_right_comm] using firstDiffPos_loop_eq (l₁ ++ [a]) (l₂ ++ [a]) r₁ r₂ stop (p + csize a) (by simp [hl₁]) (by simp [hl₂]) (by simp [hstop, ← Nat.add_assoc, Nat.add_right_comm]) · next h => rw [dif_neg] <;> simp [hstop, ← hl₁, ← hl₂, -Nat.not_lt, Nat.lt_min] intro h₁ h₂ have : ∀ {cs}, p < p + utf8Len cs → cs ≠ [] := by rintro _ h rfl; simp at h obtain ⟨a, as, e₁⟩ := List.exists_cons_of_ne_nil (this h₁) obtain ⟨b, bs, e₂⟩ := List.exists_cons_of_ne_nil (this h₂) exact h _ _ _ _ e₁ e₂ theorem firstDiffPos_eq (a b : String) : firstDiffPos a b = ⟨utf8Len (List.takeWhile₂ (· = ·) a.1 b.1).1⟩ := by simpa [firstDiffPos] using firstDiffPos_loop_eq [] [] a.1 b.1 ((utf8Len a.1).min (utf8Len b.1)) 0 rfl rfl (by simp) theorem extract.go₂_add_right_cancel (s : List Char) (i e n : Nat) : go₂ s ⟨i + n⟩ ⟨e + n⟩ = go₂ s ⟨i⟩ ⟨e⟩ := by apply utf8InductionOn s ⟨i⟩ ⟨e⟩ (motive := fun s i => go₂ s ⟨i.byteIdx + n⟩ ⟨e + n⟩ = go₂ s i ⟨e⟩) <;> simp [go₂] intro c cs ⟨i⟩ h ih simp [Pos.ext_iff, Pos.addChar_eq] at h ⊢ simp [Nat.add_right_cancel_iff, h] rw [Nat.add_right_comm] exact ih theorem extract.go₂_append_left : ∀ (s t : List Char) (i e : Nat), e = utf8Len s + i → go₂ (s ++ t) ⟨i⟩ ⟨e⟩ = s | [], t, i, _, rfl => by cases t <;> simp [go₂] | c :: cs, t, i, _, rfl => by simp [go₂, Pos.ext_iff, ne_add_csize_add_self, Pos.addChar_eq] apply go₂_append_left; rw [Nat.add_right_comm, Nat.add_assoc] theorem extract.go₁_add_right_cancel (s : List Char) (i b e n : Nat) : go₁ s ⟨i + n⟩ ⟨b + n⟩ ⟨e + n⟩ = go₁ s ⟨i⟩ ⟨b⟩ ⟨e⟩ := by apply utf8InductionOn s ⟨i⟩ ⟨b⟩ (motive := fun s i => go₁ s ⟨i.byteIdx + n⟩ ⟨b + n⟩ ⟨e + n⟩ = go₁ s i ⟨b⟩ ⟨e⟩) <;> simp [go₁] · intro c cs apply go₂_add_right_cancel · intro c cs ⟨i⟩ h ih simp [Pos.ext_iff, Pos.addChar_eq] at h ih ⊢ simp [Nat.add_right_cancel_iff, h] rw [Nat.add_right_comm] exact ih theorem extract.go₁_cons_addChar (c : Char) (cs : List Char) (b e : Pos) : go₁ (c :: cs) 0 (b + c) (e + c) = go₁ cs 0 b e := by simp [go₁, Pos.ext_iff, Nat.ne_of_lt add_csize_pos] apply go₁_add_right_cancel theorem extract.go₁_append_right : ∀ (s t : List Char) (i b : Nat) (e : Pos), b = utf8Len s + i → go₁ (s ++ t) ⟨i⟩ ⟨b⟩ e = go₂ t ⟨b⟩ e | [], t, i, _, e, rfl => by cases t <;> simp [go₁, go₂] | c :: cs, t, i, _, e, rfl => by simp [go₁, Pos.ext_iff, ne_add_csize_add_self, Pos.addChar_eq] apply go₁_append_right; rw [Nat.add_right_comm, Nat.add_assoc] theorem extract.go₁_zero_utf8Len (s : List Char) : go₁ s 0 0 ⟨utf8Len s⟩ = s := (go₁_append_right [] s 0 0 ⟨utf8Len s⟩ rfl).trans <| by simpa using go₂_append_left s [] 0 (utf8Len s) rfl theorem extract_cons_addChar (c : Char) (cs : List Char) (b e : Pos) : extract ⟨c :: cs⟩ (b + c) (e + c) = extract ⟨cs⟩ b e := by simp [extract, Nat.add_le_add_iff_right] split <;> [rfl; rw [extract.go₁_cons_addChar]] theorem extract_zero_endPos : ∀ (s : String), s.extract 0 (endPos s) = s | ⟨[]⟩ => rfl | ⟨c :: cs⟩ => by simp [extract, Nat.ne_of_gt add_csize_pos]; congr apply extract.go₁_zero_utf8Len theorem extract_of_valid (l m r : List Char) : extract ⟨l ++ m ++ r⟩ ⟨utf8Len l⟩ ⟨utf8Len l + utf8Len m⟩ = ⟨m⟩ := by simp only [extract] split · next h => rw [utf8Len_eq_zero.1 <| Nat.le_zero.1 <| Nat.add_le_add_iff_left.1 h] · congr; rw [List.append_assoc, extract.go₁_append_right _ _ _ _ _ (by rfl)] apply extract.go₂_append_left; apply Nat.add_comm
.lake/packages/batteries/Batteries/Data/String/Lemmas.lean
395
406
theorem splitAux_of_valid (p l m r acc) : splitAux ⟨l ++ m ++ r⟩ p ⟨utf8Len l⟩ ⟨utf8Len l + utf8Len m⟩ acc = acc.reverse ++ (List.splitOnP.go p r m.reverse).map mk := by
unfold splitAux simp [by simpa using atEnd_of_valid (l ++ m) r]; split · subst r; simpa [List.splitOnP.go] using extract_of_valid l m [] · obtain ⟨c, r, rfl⟩ := r.exists_cons_of_ne_nil ‹_› simp [by simpa using (⟨get_of_valid (l++m) (c::r), next_of_valid (l++m) c r, extract_of_valid l m (c::r)⟩ : _∧_∧_), List.splitOnP.go] split · simpa [Nat.add_assoc] using splitAux_of_valid p (l++m++[c]) [] r (⟨m⟩::acc) · simpa [Nat.add_assoc] using splitAux_of_valid p l (m++[c]) r acc
/- Copyright (c) 2023 Peter Nelson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Peter Nelson -/ import Mathlib.Data.Set.Card import Mathlib.Order.Minimal import Mathlib.Data.Matroid.Init /-! # Matroids A `Matroid` is a structure that combinatorially abstracts the notion of linear independence and dependence; matroids have connections with graph theory, discrete optimization, additive combinatorics and algebraic geometry. Mathematically, a matroid `M` is a structure on a set `E` comprising a collection of subsets of `E` called the bases of `M`, where the bases are required to obey certain axioms. This file gives a definition of a matroid `M` in terms of its bases, and some API relating independent sets (subsets of bases) and the notion of a basis of a set `X` (a maximal independent subset of `X`). ## Main definitions * a `Matroid α` on a type `α` is a structure comprising a 'ground set' and a suitably behaved 'base' predicate. Given `M : Matroid α` ... * `M.E` denotes the ground set of `M`, which has type `Set α` * For `B : Set α`, `M.Base B` means that `B` is a base of `M`. * For `I : Set α`, `M.Indep I` means that `I` is independent in `M` (that is, `I` is contained in a base of `M`). * For `D : Set α`, `M.Dep D` means that `D` is contained in the ground set of `M` but isn't independent. * For `I : Set α` and `X : Set α`, `M.Basis I X` means that `I` is a maximal independent subset of `X`. * `M.Finite` means that `M` has finite ground set. * `M.Nonempty` means that the ground set of `M` is nonempty. * `FiniteRk M` means that the bases of `M` are finite. * `InfiniteRk M` means that the bases of `M` are infinite. * `RkPos M` means that the bases of `M` are nonempty. * `Finitary M` means that a set is independent if and only if all its finite subsets are independent. * `aesop_mat` : a tactic designed to prove `X ⊆ M.E` for some set `X` and matroid `M`. ## Implementation details There are a few design decisions worth discussing. ### Finiteness The first is that our matroids are allowed to be infinite. Unlike with many mathematical structures, this isn't such an obvious choice. Finite matroids have been studied since the 1930's, and there was never controversy as to what is and isn't an example of a finite matroid - in fact, surprisingly many apparently different definitions of a matroid give rise to the same class of objects. However, generalizing different definitions of a finite matroid to the infinite in the obvious way (i.e. by simply allowing the ground set to be infinite) gives a number of different notions of 'infinite matroid' that disagree with each other, and that all lack nice properties. Many different competing notions of infinite matroid were studied through the years; in fact, the problem of which definition is the best was only really solved in 2013, when Bruhn et al. [2] showed that there is a unique 'reasonable' notion of an infinite matroid (these objects had previously defined by Higgs under the name 'B-matroid'). These are defined by adding one carefully chosen axiom to the standard set, and adapting existing axioms to not mention set cardinalities; they enjoy nearly all the nice properties of standard finite matroids. Even though at least 90% of the literature is on finite matroids, B-matroids are the definition we use, because they allow for additional generality, nearly all theorems are still true and just as easy to state, and (hopefully) the more general definition will prevent the need for a costly future refactor. The disadvantage is that developing API for the finite case is harder work (for instance, it is harder to prove that something is a matroid in the first place, and one must deal with `ℕ∞` rather than `ℕ`). For serious work on finite matroids, we provide the typeclasses `[M.Finite]` and `[FiniteRk M]` and associated API. ### Cardinality Just as with bases of a vector space, all bases of a finite matroid `M` are finite and have the same cardinality; this cardinality is an important invariant known as the 'rank' of `M`. For infinite matroids, bases are not in general equicardinal; in fact the equicardinality of bases of infinite matroids is independent of ZFC [3]. What is still true is that either all bases are finite and equicardinal, or all bases are infinite. This means that the natural notion of 'size' for a set in matroid theory is given by the function `Set.encard`, which is the cardinality as a term in `ℕ∞`. We use this function extensively in building the API; it is preferable to both `Set.ncard` and `Finset.card` because it allows infinite sets to be handled without splitting into cases. ### The ground `Set` A last place where we make a consequential choice is making the ground set of a matroid a structure field of type `Set α` (where `α` is the type of 'possible matroid elements') rather than just having a type `α` of all the matroid elements. This is because of how common it is to simultaneously consider a number of matroids on different but related ground sets. For example, a matroid `M` on ground set `E` can have its structure 'restricted' to some subset `R ⊆ E` to give a smaller matroid `M ↾ R` with ground set `R`. A statement like `(M ↾ R₁) ↾ R₂ = M ↾ R₂` is mathematically obvious. But if the ground set of a matroid is a type, this doesn't typecheck, and is only true up to canonical isomorphism. Restriction is just the tip of the iceberg here; one can also 'contract' and 'delete' elements and sets of elements in a matroid to give a smaller matroid, and in practice it is common to make statements like `M₁.E = M₂.E ∩ M₃.E` and `((M ⟋ e) ↾ R) ⟋ C = M ⟋ (C ∪ {e}) ↾ R`. Such things are a nightmare to work with unless `=` is actually propositional equality (especially because the relevant coercions are usually between sets and not just elements). So the solution is that the ground set `M.E` has type `Set α`, and there are elements of type `α` that aren't in the matroid. The tradeoff is that for many statements, one now has to add hypotheses of the form `X ⊆ M.E` to make sure than `X` is actually 'in the matroid', rather than letting a 'type of matroid elements' take care of this invisibly. It still seems that this is worth it. The tactic `aesop_mat` exists specifically to discharge such goals with minimal fuss (using default values). The tactic works fairly well, but has room for improvement. Even though the carrier set is written `M.E`, A related decision is to not have matroids themselves be a typeclass. This would make things be notationally simpler (having `Base` in the presence of `[Matroid α]` rather than `M.Base` for a term `M : Matroid α`) but is again just too awkward when one has multiple matroids on the same type. In fact, in regular written mathematics, it is normal to explicitly indicate which matroid something is happening in, so our notation mirrors common practice. ### Notation We use a couple of nonstandard conventions in theorem names that are related to the above. First, we mirror common informal practice by referring explicitly to the `ground` set rather than the notation `E`. (Writing `ground` everywhere in a proof term would be unwieldy, and writing `E` in theorem names would be unnatural to read.) Second, because we are typically interested in subsets of the ground set `M.E`, using `Set.compl` is inconvenient, since `Xᶜ ⊆ M.E` is typically false for `X ⊆ M.E`. On the other hand (especially when duals arise), it is common to complement a set `X ⊆ M.E` *within* the ground set, giving `M.E \ X`. For this reason, we use the term `compl` in theorem names to refer to taking a set difference with respect to the ground set, rather than a complement within a type. The lemma `compl_base_dual` is one of the many examples of this. ## References [1] The standard text on matroid theory [J. G. Oxley, Matroid Theory, Oxford University Press, New York, 2011.] [2] The robust axiomatic definition of infinite matroids [H. Bruhn, R. Diestel, M. Kriesell, R. Pendavingh, P. Wollan, Axioms for infinite matroids, Adv. Math 239 (2013), 18-46] [3] Equicardinality of matroid bases is independent of ZFC. [N. Bowler, S. Geschke, Self-dual uniform matroids on infinite sets, Proc. Amer. Math. Soc. 144 (2016), 459-471] -/ set_option autoImplicit true open Set /-- A predicate `P` on sets satisfies the **exchange property** if, for all `X` and `Y` satisfying `P` and all `a ∈ X \ Y`, there exists `b ∈ Y \ X` so that swapping `a` for `b` in `X` maintains `P`. -/ def Matroid.ExchangeProperty {α : Type _} (P : Set α → Prop) : Prop := ∀ X Y, P X → P Y → ∀ a ∈ X \ Y, ∃ b ∈ Y \ X, P (insert b (X \ {a})) /-- A set `X` has the maximal subset property for a predicate `P` if every subset of `X` satisfying `P` is contained in a maximal subset of `X` satisfying `P`. -/ def Matroid.ExistsMaximalSubsetProperty {α : Type _} (P : Set α → Prop) (X : Set α) : Prop := ∀ I, P I → I ⊆ X → (maximals (· ⊆ ·) {Y | P Y ∧ I ⊆ Y ∧ Y ⊆ X}).Nonempty /-- A `Matroid α` is a ground set `E` of type `Set α`, and a nonempty collection of its subsets satisfying the exchange property and the maximal subset property. Each such set is called a `Base` of `M`. An `Indep`endent set is just a set contained in a base, but we include this predicate as a structure field for better definitional properties. In most cases, using this definition directly is not the best way to construct a matroid, since it requires specifying both the bases and independent sets. If the bases are known, use `Matroid.ofBase` or a variant. If just the independent sets are known, define an `IndepMatroid`, and then use `IndepMatroid.matroid`. -/ @[ext] structure Matroid (α : Type _) where /-- `M` has a ground set `E`. -/ (E : Set α) /-- `M` has a predicate `Base` definining its bases. -/ (Base : Set α → Prop) /-- `M` has a predicate `Indep` defining its independent sets. -/ (Indep : Set α → Prop) /-- The `Indep`endent sets are those contained in `Base`s. -/ (indep_iff' : ∀ ⦃I⦄, Indep I ↔ ∃ B, Base B ∧ I ⊆ B) /-- There is at least one `Base`. -/ (exists_base : ∃ B, Base B) /-- For any bases `B`, `B'` and `e ∈ B \ B'`, there is some `f ∈ B' \ B` for which `B-e+f` is a base. -/ (base_exchange : Matroid.ExchangeProperty Base) /-- Every independent subset `I` of a set `X` for is contained in a maximal independent subset of `X`. -/ (maximality : ∀ X, X ⊆ E → Matroid.ExistsMaximalSubsetProperty Indep X) /-- Every base is contained in the ground set. -/ (subset_ground : ∀ B, Base B → B ⊆ E) namespace Matroid variable {α : Type*} {M : Matroid α} /-- Typeclass for a matroid having finite ground set. Just a wrapper for `M.E.Finite`-/ protected class Finite (M : Matroid α) : Prop where /-- The ground set is finite -/ (ground_finite : M.E.Finite) /-- Typeclass for a matroid having nonempty ground set. Just a wrapper for `M.E.Nonempty`-/ protected class Nonempty (M : Matroid α) : Prop where /-- The ground set is nonempty -/ (ground_nonempty : M.E.Nonempty) theorem ground_nonempty (M : Matroid α) [M.Nonempty] : M.E.Nonempty := Nonempty.ground_nonempty theorem ground_nonempty_iff (M : Matroid α) : M.E.Nonempty ↔ M.Nonempty := ⟨fun h ↦ ⟨h⟩, fun ⟨h⟩ ↦ h⟩ theorem ground_finite (M : Matroid α) [M.Finite] : M.E.Finite := Finite.ground_finite theorem set_finite (M : Matroid α) [M.Finite] (X : Set α) (hX : X ⊆ M.E := by aesop) : X.Finite := M.ground_finite.subset hX instance finite_of_finite [Finite α] {M : Matroid α} : M.Finite := ⟨Set.toFinite _⟩ /-- A `FiniteRk` matroid is one whose bases are finite -/ class FiniteRk (M : Matroid α) : Prop where /-- There is a finite base -/ exists_finite_base : ∃ B, M.Base B ∧ B.Finite instance finiteRk_of_finite (M : Matroid α) [M.Finite] : FiniteRk M := ⟨M.exists_base.imp (fun B hB ↦ ⟨hB, M.set_finite B (M.subset_ground _ hB)⟩)⟩ /-- An `InfiniteRk` matroid is one whose bases are infinite. -/ class InfiniteRk (M : Matroid α) : Prop where /-- There is an infinite base -/ exists_infinite_base : ∃ B, M.Base B ∧ B.Infinite /-- A `RkPos` matroid is one whose bases are nonempty. -/ class RkPos (M : Matroid α) : Prop where /-- The empty set isn't a base -/ empty_not_base : ¬M.Base ∅ theorem rkPos_iff_empty_not_base : M.RkPos ↔ ¬M.Base ∅ := ⟨fun ⟨h⟩ ↦ h, fun h ↦ ⟨h⟩⟩ section exchange namespace ExchangeProperty variable {Base : Set α → Prop} (exch : ExchangeProperty Base) /-- A family of sets with the exchange property is an antichain. -/ theorem antichain (hB : Base B) (hB' : Base B') (h : B ⊆ B') : B = B' := h.antisymm (fun x hx ↦ by_contra (fun hxB ↦ let ⟨_, hy, _⟩ := exch B' B hB' hB x ⟨hx, hxB⟩; hy.2 <| h hy.1)) theorem encard_diff_le_aux (exch : ExchangeProperty Base) (hB₁ : Base B₁) (hB₂ : Base B₂) : (B₁ \ B₂).encard ≤ (B₂ \ B₁).encard := by obtain (he | hinf | ⟨e, he, hcard⟩) := (B₂ \ B₁).eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt · rw [exch.antichain hB₂ hB₁ (diff_eq_empty.mp he)] · exact le_top.trans_eq hinf.symm obtain ⟨f, hf, hB'⟩ := exch B₂ B₁ hB₂ hB₁ e he have : encard (insert f (B₂ \ {e}) \ B₁) < encard (B₂ \ B₁) := by rw [insert_diff_of_mem _ hf.1, diff_diff_comm]; exact hcard have hencard := encard_diff_le_aux exch hB₁ hB' rw [insert_diff_of_mem _ hf.1, diff_diff_comm, ← union_singleton, ← diff_diff, diff_diff_right, inter_singleton_eq_empty.mpr he.2, union_empty] at hencard rw [← encard_diff_singleton_add_one he, ← encard_diff_singleton_add_one hf] exact add_le_add_right hencard 1 termination_by (B₂ \ B₁).encard /-- For any two sets `B₁`, `B₂` in a family with the exchange property, the differences `B₁ \ B₂` and `B₂ \ B₁` have the same `ℕ∞`-cardinality. -/ theorem encard_diff_eq (hB₁ : Base B₁) (hB₂ : Base B₂) : (B₁ \ B₂).encard = (B₂ \ B₁).encard := (encard_diff_le_aux exch hB₁ hB₂).antisymm (encard_diff_le_aux exch hB₂ hB₁) /-- Any two sets `B₁`, `B₂` in a family with the exchange property have the same `ℕ∞`-cardinality. -/ theorem encard_base_eq (hB₁ : Base B₁) (hB₂ : Base B₂) : B₁.encard = B₂.encard := by rw [← encard_diff_add_encard_inter B₁ B₂, exch.encard_diff_eq hB₁ hB₂, inter_comm, encard_diff_add_encard_inter] end ExchangeProperty end exchange section aesop /-- The `aesop_mat` tactic attempts to prove a set is contained in the ground set of a matroid. It uses a `[Matroid]` ruleset, and is allowed to fail. -/ macro (name := aesop_mat) "aesop_mat" c:Aesop.tactic_clause* : tactic => `(tactic| aesop $c* (config := { terminal := true }) (rule_sets := [$(Lean.mkIdent `Matroid):ident])) /- We add a number of trivial lemmas (deliberately specialized to statements in terms of the ground set of a matroid) to the ruleset `Matroid` for `aesop`. -/ @[aesop unsafe 5% (rule_sets := [Matroid])] private theorem inter_right_subset_ground (hX : X ⊆ M.E) : X ∩ Y ⊆ M.E := inter_subset_left.trans hX @[aesop unsafe 5% (rule_sets := [Matroid])] private theorem inter_left_subset_ground (hX : X ⊆ M.E) : Y ∩ X ⊆ M.E := inter_subset_right.trans hX @[aesop unsafe 5% (rule_sets := [Matroid])] private theorem diff_subset_ground (hX : X ⊆ M.E) : X \ Y ⊆ M.E := diff_subset.trans hX @[aesop unsafe 10% (rule_sets := [Matroid])] private theorem ground_diff_subset_ground : M.E \ X ⊆ M.E := diff_subset_ground rfl.subset @[aesop unsafe 10% (rule_sets := [Matroid])] private theorem singleton_subset_ground (he : e ∈ M.E) : {e} ⊆ M.E := singleton_subset_iff.mpr he @[aesop unsafe 5% (rule_sets := [Matroid])] private theorem subset_ground_of_subset (hXY : X ⊆ Y) (hY : Y ⊆ M.E) : X ⊆ M.E := hXY.trans hY @[aesop unsafe 5% (rule_sets := [Matroid])] private theorem mem_ground_of_mem_of_subset (hX : X ⊆ M.E) (heX : e ∈ X) : e ∈ M.E := hX heX @[aesop safe (rule_sets := [Matroid])] private theorem insert_subset_ground {e : α} {X : Set α} {M : Matroid α} (he : e ∈ M.E) (hX : X ⊆ M.E) : insert e X ⊆ M.E := insert_subset he hX @[aesop safe (rule_sets := [Matroid])] private theorem ground_subset_ground {M : Matroid α} : M.E ⊆ M.E := rfl.subset attribute [aesop safe (rule_sets := [Matroid])] empty_subset union_subset iUnion_subset end aesop section Base @[aesop unsafe 10% (rule_sets := [Matroid])] theorem Base.subset_ground (hB : M.Base B) : B ⊆ M.E := M.subset_ground B hB theorem Base.exchange (hB₁ : M.Base B₁) (hB₂ : M.Base B₂) (hx : e ∈ B₁ \ B₂) : ∃ y ∈ B₂ \ B₁, M.Base (insert y (B₁ \ {e})) := M.base_exchange B₁ B₂ hB₁ hB₂ _ hx theorem Base.exchange_mem (hB₁ : M.Base B₁) (hB₂ : M.Base B₂) (hxB₁ : e ∈ B₁) (hxB₂ : e ∉ B₂) : ∃ y, (y ∈ B₂ ∧ y ∉ B₁) ∧ M.Base (insert y (B₁ \ {e})) := by simpa using hB₁.exchange hB₂ ⟨hxB₁, hxB₂⟩ theorem Base.eq_of_subset_base (hB₁ : M.Base B₁) (hB₂ : M.Base B₂) (hB₁B₂ : B₁ ⊆ B₂) : B₁ = B₂ := M.base_exchange.antichain hB₁ hB₂ hB₁B₂ theorem Base.not_base_of_ssubset (hB : M.Base B) (hX : X ⊂ B) : ¬ M.Base X := fun h ↦ hX.ne (h.eq_of_subset_base hB hX.subset) theorem Base.insert_not_base (hB : M.Base B) (heB : e ∉ B) : ¬ M.Base (insert e B) := fun h ↦ h.not_base_of_ssubset (ssubset_insert heB) hB theorem Base.encard_diff_comm (hB₁ : M.Base B₁) (hB₂ : M.Base B₂) : (B₁ \ B₂).encard = (B₂ \ B₁).encard := M.base_exchange.encard_diff_eq hB₁ hB₂ theorem Base.ncard_diff_comm (hB₁ : M.Base B₁) (hB₂ : M.Base B₂) : (B₁ \ B₂).ncard = (B₂ \ B₁).ncard := by rw [ncard_def, hB₁.encard_diff_comm hB₂, ← ncard_def] theorem Base.card_eq_card_of_base (hB₁ : M.Base B₁) (hB₂ : M.Base B₂) : B₁.encard = B₂.encard := by rw [M.base_exchange.encard_base_eq hB₁ hB₂] theorem Base.ncard_eq_ncard_of_base (hB₁ : M.Base B₁) (hB₂ : M.Base B₂) : B₁.ncard = B₂.ncard := by rw [ncard_def B₁, hB₁.card_eq_card_of_base hB₂, ← ncard_def] theorem Base.finite_of_finite (hB : M.Base B) (h : B.Finite) (hB' : M.Base B') : B'.Finite := (finite_iff_finite_of_encard_eq_encard (hB.card_eq_card_of_base hB')).mp h theorem Base.infinite_of_infinite (hB : M.Base B) (h : B.Infinite) (hB₁ : M.Base B₁) : B₁.Infinite := by_contra (fun hB_inf ↦ (hB₁.finite_of_finite (not_infinite.mp hB_inf) hB).not_infinite h) theorem Base.finite [FiniteRk M] (hB : M.Base B) : B.Finite := let ⟨B₀,hB₀⟩ := ‹FiniteRk M›.exists_finite_base hB₀.1.finite_of_finite hB₀.2 hB theorem Base.infinite [InfiniteRk M] (hB : M.Base B) : B.Infinite := let ⟨B₀,hB₀⟩ := ‹InfiniteRk M›.exists_infinite_base hB₀.1.infinite_of_infinite hB₀.2 hB theorem empty_not_base [h : RkPos M] : ¬M.Base ∅ := h.empty_not_base theorem Base.nonempty [RkPos M] (hB : M.Base B) : B.Nonempty := by rw [nonempty_iff_ne_empty]; rintro rfl; exact M.empty_not_base hB theorem Base.rkPos_of_nonempty (hB : M.Base B) (h : B.Nonempty) : M.RkPos := by rw [rkPos_iff_empty_not_base] intro he obtain rfl := he.eq_of_subset_base hB (empty_subset B) simp at h theorem Base.finiteRk_of_finite (hB : M.Base B) (hfin : B.Finite) : FiniteRk M := ⟨⟨B, hB, hfin⟩⟩ theorem Base.infiniteRk_of_infinite (hB : M.Base B) (h : B.Infinite) : InfiniteRk M := ⟨⟨B, hB, h⟩⟩ theorem not_finiteRk (M : Matroid α) [InfiniteRk M] : ¬ FiniteRk M := by intro h; obtain ⟨B,hB⟩ := M.exists_base; exact hB.infinite hB.finite theorem not_infiniteRk (M : Matroid α) [FiniteRk M] : ¬ InfiniteRk M := by intro h; obtain ⟨B,hB⟩ := M.exists_base; exact hB.infinite hB.finite theorem finite_or_infiniteRk (M : Matroid α) : FiniteRk M ∨ InfiniteRk M := let ⟨B, hB⟩ := M.exists_base B.finite_or_infinite.elim (Or.inl ∘ hB.finiteRk_of_finite) (Or.inr ∘ hB.infiniteRk_of_infinite) theorem Base.diff_finite_comm (hB₁ : M.Base B₁) (hB₂ : M.Base B₂) : (B₁ \ B₂).Finite ↔ (B₂ \ B₁).Finite := finite_iff_finite_of_encard_eq_encard (hB₁.encard_diff_comm hB₂) theorem Base.diff_infinite_comm (hB₁ : M.Base B₁) (hB₂ : M.Base B₂) : (B₁ \ B₂).Infinite ↔ (B₂ \ B₁).Infinite := infinite_iff_infinite_of_encard_eq_encard (hB₁.encard_diff_comm hB₂) theorem eq_of_base_iff_base_forall {M₁ M₂ : Matroid α} (hE : M₁.E = M₂.E) (h : ∀ ⦃B⦄, B ⊆ M₁.E → (M₁.Base B ↔ M₂.Base B)) : M₁ = M₂ := by have h' : ∀ B, M₁.Base B ↔ M₂.Base B := fun B ↦ ⟨fun hB ↦ (h hB.subset_ground).1 hB, fun hB ↦ (h <| hB.subset_ground.trans_eq hE.symm).2 hB⟩ ext <;> simp [hE, M₁.indep_iff', M₂.indep_iff', h'] theorem base_compl_iff_mem_maximals_disjoint_base (hB : B ⊆ M.E := by aesop_mat) : M.Base (M.E \ B) ↔ B ∈ maximals (· ⊆ ·) {I | I ⊆ M.E ∧ ∃ B, M.Base B ∧ Disjoint I B} := by simp_rw [mem_maximals_setOf_iff, and_iff_right hB, and_imp, forall_exists_index] refine ⟨fun h ↦ ⟨⟨_, h, disjoint_sdiff_right⟩, fun I hI B' ⟨hB', hIB'⟩ hBI ↦ hBI.antisymm ?_⟩, fun ⟨⟨B', hB', hBB'⟩,h⟩ ↦ ?_⟩ · rw [hB'.eq_of_subset_base h, ← subset_compl_iff_disjoint_right, diff_eq, compl_inter, compl_compl] at hIB' · exact fun e he ↦ (hIB' he).elim (fun h' ↦ (h' (hI he)).elim) id rw [subset_diff, and_iff_right hB'.subset_ground, disjoint_comm] exact disjoint_of_subset_left hBI hIB' rw [h diff_subset B' ⟨hB', disjoint_sdiff_left⟩] · simpa [hB'.subset_ground] simp [subset_diff, hB, hBB'] end Base section dep_indep /-- A subset of `M.E` is `Dep`endent if it is not `Indep`endent . -/ def Dep (M : Matroid α) (D : Set α) : Prop := ¬M.Indep D ∧ D ⊆ M.E theorem indep_iff : M.Indep I ↔ ∃ B, M.Base B ∧ I ⊆ B := M.indep_iff' (I := I) theorem setOf_indep_eq (M : Matroid α) : {I | M.Indep I} = lowerClosure ({B | M.Base B}) := by simp_rw [indep_iff] rfl theorem Indep.exists_base_superset (hI : M.Indep I) : ∃ B, M.Base B ∧ I ⊆ B := indep_iff.1 hI theorem dep_iff : M.Dep D ↔ ¬M.Indep D ∧ D ⊆ M.E := Iff.rfl theorem setOf_dep_eq (M : Matroid α) : {D | M.Dep D} = {I | M.Indep I}ᶜ ∩ Iic M.E := rfl @[aesop unsafe 30% (rule_sets := [Matroid])] theorem Indep.subset_ground (hI : M.Indep I) : I ⊆ M.E := by obtain ⟨B, hB, hIB⟩ := hI.exists_base_superset exact hIB.trans hB.subset_ground @[aesop unsafe 20% (rule_sets := [Matroid])] theorem Dep.subset_ground (hD : M.Dep D) : D ⊆ M.E := hD.2 theorem indep_or_dep (hX : X ⊆ M.E := by aesop_mat) : M.Indep X ∨ M.Dep X := by rw [Dep, and_iff_left hX] apply em theorem Indep.not_dep (hI : M.Indep I) : ¬ M.Dep I := fun h ↦ h.1 hI theorem Dep.not_indep (hD : M.Dep D) : ¬ M.Indep D := hD.1 theorem dep_of_not_indep (hD : ¬ M.Indep D) (hDE : D ⊆ M.E := by aesop_mat) : M.Dep D := ⟨hD, hDE⟩ theorem indep_of_not_dep (hI : ¬ M.Dep I) (hIE : I ⊆ M.E := by aesop_mat) : M.Indep I := by_contra (fun h ↦ hI ⟨h, hIE⟩) @[simp] theorem not_dep_iff (hX : X ⊆ M.E := by aesop_mat) : ¬ M.Dep X ↔ M.Indep X := by rw [Dep, and_iff_left hX, not_not] @[simp] theorem not_indep_iff (hX : X ⊆ M.E := by aesop_mat) : ¬ M.Indep X ↔ M.Dep X := by rw [Dep, and_iff_left hX] theorem indep_iff_not_dep : M.Indep I ↔ ¬M.Dep I ∧ I ⊆ M.E := by rw [dep_iff, not_and, not_imp_not] exact ⟨fun h ↦ ⟨fun _ ↦ h, h.subset_ground⟩, fun h ↦ h.1 h.2⟩ theorem Indep.subset (hJ : M.Indep J) (hIJ : I ⊆ J) : M.Indep I := by obtain ⟨B, hB, hJB⟩ := hJ.exists_base_superset exact indep_iff.2 ⟨B, hB, hIJ.trans hJB⟩ theorem Dep.superset (hD : M.Dep D) (hDX : D ⊆ X) (hXE : X ⊆ M.E := by aesop_mat) : M.Dep X := dep_of_not_indep (fun hI ↦ (hI.subset hDX).not_dep hD) theorem Base.indep (hB : M.Base B) : M.Indep B := indep_iff.2 ⟨B, hB, subset_rfl⟩ @[simp] theorem empty_indep (M : Matroid α) : M.Indep ∅ := Exists.elim M.exists_base (fun _ hB ↦ hB.indep.subset (empty_subset _)) theorem Dep.nonempty (hD : M.Dep D) : D.Nonempty := by rw [nonempty_iff_ne_empty]; rintro rfl; exact hD.not_indep M.empty_indep theorem Indep.finite [FiniteRk M] (hI : M.Indep I) : I.Finite := let ⟨_, hB, hIB⟩ := hI.exists_base_superset hB.finite.subset hIB theorem Indep.rkPos_of_nonempty (hI : M.Indep I) (hne : I.Nonempty) : M.RkPos := by obtain ⟨B, hB, hIB⟩ := hI.exists_base_superset exact hB.rkPos_of_nonempty (hne.mono hIB) theorem Indep.inter_right (hI : M.Indep I) (X : Set α) : M.Indep (I ∩ X) := hI.subset inter_subset_left theorem Indep.inter_left (hI : M.Indep I) (X : Set α) : M.Indep (X ∩ I) := hI.subset inter_subset_right theorem Indep.diff (hI : M.Indep I) (X : Set α) : M.Indep (I \ X) := hI.subset diff_subset theorem Base.eq_of_subset_indep (hB : M.Base B) (hI : M.Indep I) (hBI : B ⊆ I) : B = I := let ⟨B', hB', hB'I⟩ := hI.exists_base_superset hBI.antisymm (by rwa [hB.eq_of_subset_base hB' (hBI.trans hB'I)]) theorem base_iff_maximal_indep : M.Base B ↔ M.Indep B ∧ ∀ I, M.Indep I → B ⊆ I → B = I := by refine ⟨fun h ↦ ⟨h.indep, fun _ ↦ h.eq_of_subset_indep ⟩, fun ⟨h, h'⟩ ↦ ?_⟩ obtain ⟨B', hB', hBB'⟩ := h.exists_base_superset rwa [h' _ hB'.indep hBB'] theorem setOf_base_eq_maximals_setOf_indep : {B | M.Base B} = maximals (· ⊆ ·) {I | M.Indep I} := by ext B; rw [mem_maximals_setOf_iff, mem_setOf, base_iff_maximal_indep] theorem Indep.base_of_maximal (hI : M.Indep I) (h : ∀ J, M.Indep J → I ⊆ J → I = J) : M.Base I := base_iff_maximal_indep.mpr ⟨hI,h⟩ theorem Base.dep_of_ssubset (hB : M.Base B) (h : B ⊂ X) (hX : X ⊆ M.E := by aesop_mat) : M.Dep X := ⟨fun hX ↦ h.ne (hB.eq_of_subset_indep hX h.subset), hX⟩ theorem Base.dep_of_insert (hB : M.Base B) (heB : e ∉ B) (he : e ∈ M.E := by aesop_mat) : M.Dep (insert e B) := hB.dep_of_ssubset (ssubset_insert heB) (insert_subset he hB.subset_ground) theorem Base.mem_of_insert_indep (hB : M.Base B) (heB : M.Indep (insert e B)) : e ∈ B := by_contra fun he ↦ (hB.dep_of_insert he (heB.subset_ground (mem_insert _ _))).not_indep heB /-- If the difference of two Bases is a singleton, then they differ by an insertion/removal -/ theorem Base.eq_exchange_of_diff_eq_singleton (hB : M.Base B) (hB' : M.Base B') (h : B \ B' = {e}) : ∃ f ∈ B' \ B, B' = (insert f B) \ {e} := by obtain ⟨f, hf, hb⟩ := hB.exchange hB' (h.symm.subset (mem_singleton e)) have hne : f ≠ e := by rintro rfl; exact hf.2 (h.symm.subset (mem_singleton f)).1 rw [insert_diff_singleton_comm hne] at hb refine ⟨f, hf, (hb.eq_of_subset_base hB' ?_).symm⟩ rw [diff_subset_iff, insert_subset_iff, union_comm, ← diff_subset_iff, h, and_iff_left rfl.subset] exact Or.inl hf.1 theorem Base.exchange_base_of_indep (hB : M.Base B) (hf : f ∉ B) (hI : M.Indep (insert f (B \ {e}))) : M.Base (insert f (B \ {e})) := by obtain ⟨B', hB', hIB'⟩ := hI.exists_base_superset have hcard := hB'.encard_diff_comm hB rw [insert_subset_iff, ← diff_eq_empty, diff_diff_comm, diff_eq_empty, subset_singleton_iff_eq] at hIB' obtain ⟨hfB, (h | h)⟩ := hIB' · rw [h, encard_empty, encard_eq_zero, eq_empty_iff_forall_not_mem] at hcard exact (hcard f ⟨hfB, hf⟩).elim rw [h, encard_singleton, encard_eq_one] at hcard obtain ⟨x, hx⟩ := hcard obtain (rfl : f = x) := hx.subset ⟨hfB, hf⟩ simp_rw [← h, ← singleton_union, ← hx, sdiff_sdiff_right_self, inf_eq_inter, inter_comm B, diff_union_inter] exact hB' theorem Base.exchange_base_of_indep' (hB : M.Base B) (he : e ∈ B) (hf : f ∉ B) (hI : M.Indep (insert f B \ {e})) : M.Base (insert f B \ {e}) := by have hfe : f ≠ e := by rintro rfl; exact hf he rw [← insert_diff_singleton_comm hfe] at * exact hB.exchange_base_of_indep hf hI theorem Base.insert_dep (hB : M.Base B) (h : e ∈ M.E \ B) : M.Dep (insert e B) := by rw [← not_indep_iff (insert_subset h.1 hB.subset_ground)] exact h.2 ∘ (fun hi ↦ insert_eq_self.mp (hB.eq_of_subset_indep hi (subset_insert e B)).symm) theorem Indep.exists_insert_of_not_base (hI : M.Indep I) (hI' : ¬M.Base I) (hB : M.Base B) : ∃ e ∈ B \ I, M.Indep (insert e I) := by obtain ⟨B', hB', hIB'⟩ := hI.exists_base_superset obtain ⟨x, hxB', hx⟩ := exists_of_ssubset (hIB'.ssubset_of_ne (by (rintro rfl; exact hI' hB'))) obtain (hxB | hxB) := em (x ∈ B) · exact ⟨x, ⟨hxB, hx⟩, hB'.indep.subset (insert_subset hxB' hIB') ⟩ obtain ⟨e,he, hBase⟩ := hB'.exchange hB ⟨hxB',hxB⟩ exact ⟨e, ⟨he.1, not_mem_subset hIB' he.2⟩, indep_iff.2 ⟨_, hBase, insert_subset_insert (subset_diff_singleton hIB' hx)⟩⟩ /-- This is the same as `Indep.exists_insert_of_not_base`, but phrased so that it is defeq to the augmentation axiom for independent sets. -/ theorem Indep.exists_insert_of_not_mem_maximals (M : Matroid α) ⦃I B : Set α⦄ (hI : M.Indep I) (hInotmax : I ∉ maximals (· ⊆ ·) {I | M.Indep I}) (hB : B ∈ maximals (· ⊆ ·) {I | M.Indep I}) : ∃ x ∈ B \ I, M.Indep (insert x I) := by simp only [mem_maximals_iff, mem_setOf_eq, not_and, not_forall, exists_prop, exists_and_left, iff_true_intro hI, true_imp_iff] at hB hInotmax refine hI.exists_insert_of_not_base (fun hIb ↦ ?_) ?_ · obtain ⟨I', hII', hI', hne⟩ := hInotmax exact hne <| hIb.eq_of_subset_indep hII' hI' exact hB.1.base_of_maximal fun J hJ hBJ ↦ hB.2 hJ hBJ theorem ground_indep_iff_base : M.Indep M.E ↔ M.Base M.E := ⟨fun h ↦ h.base_of_maximal (fun _ hJ hEJ ↦ hEJ.antisymm hJ.subset_ground), Base.indep⟩ theorem Base.exists_insert_of_ssubset (hB : M.Base B) (hIB : I ⊂ B) (hB' : M.Base B') : ∃ e ∈ B' \ I, M.Indep (insert e I) := (hB.indep.subset hIB.subset).exists_insert_of_not_base (fun hI ↦ hIB.ne (hI.eq_of_subset_base hB hIB.subset)) hB' theorem eq_of_indep_iff_indep_forall {M₁ M₂ : Matroid α} (hE : M₁.E = M₂.E) (h : ∀ I, I ⊆ M₁.E → (M₁.Indep I ↔ M₂.Indep I)) : M₁ = M₂ := let h' : ∀ I, M₁.Indep I ↔ M₂.Indep I := fun I ↦ (em (I ⊆ M₁.E)).elim (h I) (fun h' ↦ iff_of_false (fun hi ↦ h' (hi.subset_ground)) (fun hi ↦ h' (hi.subset_ground.trans_eq hE.symm))) eq_of_base_iff_base_forall hE (fun B _ ↦ by simp_rw [base_iff_maximal_indep, h']) theorem eq_iff_indep_iff_indep_forall {M₁ M₂ : Matroid α} : M₁ = M₂ ↔ (M₁.E = M₂.E) ∧ ∀ I, I ⊆ M₁.E → (M₁.Indep I ↔ M₂.Indep I) := ⟨fun h ↦ by (subst h; simp), fun h ↦ eq_of_indep_iff_indep_forall h.1 h.2⟩ /-- A `Finitary` matroid is one where a set is independent if and only if it all its finite subsets are independent, or equivalently a matroid whose circuits are finite. -/ class Finitary (M : Matroid α) : Prop where /-- `I` is independent if all its finite subsets are independent. -/ indep_of_forall_finite : ∀ I, (∀ J, J ⊆ I → J.Finite → M.Indep J) → M.Indep I theorem indep_of_forall_finite_subset_indep {M : Matroid α} [Finitary M] (I : Set α) (h : ∀ J, J ⊆ I → J.Finite → M.Indep J) : M.Indep I := Finitary.indep_of_forall_finite I h theorem indep_iff_forall_finite_subset_indep {M : Matroid α} [Finitary M] : M.Indep I ↔ ∀ J, J ⊆ I → J.Finite → M.Indep J := ⟨fun h _ hJI _ ↦ h.subset hJI, Finitary.indep_of_forall_finite I⟩ instance finitary_of_finiteRk {M : Matroid α} [FiniteRk M] : Finitary M := ⟨ by refine fun I hI ↦ I.finite_or_infinite.elim (hI _ Subset.rfl) (fun h ↦ False.elim ?_) obtain ⟨B, hB⟩ := M.exists_base obtain ⟨I₀, hI₀I, hI₀fin, hI₀card⟩ := h.exists_subset_ncard_eq (B.ncard + 1) obtain ⟨B', hB', hI₀B'⟩ := (hI _ hI₀I hI₀fin).exists_base_superset have hle := ncard_le_ncard hI₀B' hB'.finite rw [hI₀card, hB'.ncard_eq_ncard_of_base hB, Nat.add_one_le_iff] at hle exact hle.ne rfl ⟩ /-- Matroids obey the maximality axiom -/ theorem existsMaximalSubsetProperty_indep (M : Matroid α) : ∀ X, X ⊆ M.E → ExistsMaximalSubsetProperty M.Indep X := M.maximality end dep_indep section Basis /-- A Basis for a set `X ⊆ M.E` is a maximal independent subset of `X` (Often in the literature, the word 'Basis' is used to refer to what we call a 'Base'). -/ def Basis (M : Matroid α) (I X : Set α) : Prop := I ∈ maximals (· ⊆ ·) {A | M.Indep A ∧ A ⊆ X} ∧ X ⊆ M.E /-- A `Basis'` is a basis without the requirement that `X ⊆ M.E`. This is convenient for some API building, especially when working with rank and closure. -/ def Basis' (M : Matroid α) (I X : Set α) : Prop := I ∈ maximals (· ⊆ ·) {A | M.Indep A ∧ A ⊆ X} theorem Basis'.indep (hI : M.Basis' I X) : M.Indep I := hI.1.1 theorem Basis.indep (hI : M.Basis I X) : M.Indep I := hI.1.1.1 theorem Basis.subset (hI : M.Basis I X) : I ⊆ X := hI.1.1.2 theorem Basis.basis' (hI : M.Basis I X) : M.Basis' I X := hI.1 theorem Basis'.basis (hI : M.Basis' I X) (hX : X ⊆ M.E := by aesop_mat) : M.Basis I X := ⟨hI, hX⟩ theorem Basis'.subset (hI : M.Basis' I X) : I ⊆ X := hI.1.2 theorem setOf_basis_eq (M : Matroid α) (hX : X ⊆ M.E := by aesop_mat) : {I | M.Basis I X} = maximals (· ⊆ ·) ({I | M.Indep I} ∩ Iic X) := by ext I; simp [Matroid.Basis, maximals, iff_true_intro hX] @[aesop unsafe 15% (rule_sets := [Matroid])] theorem Basis.subset_ground (hI : M.Basis I X) : X ⊆ M.E := hI.2 theorem Basis.basis_inter_ground (hI : M.Basis I X) : M.Basis I (X ∩ M.E) := by convert hI rw [inter_eq_self_of_subset_left hI.subset_ground] @[aesop unsafe 15% (rule_sets := [Matroid])] theorem Basis.left_subset_ground (hI : M.Basis I X) : I ⊆ M.E := hI.indep.subset_ground theorem Basis.eq_of_subset_indep (hI : M.Basis I X) (hJ : M.Indep J) (hIJ : I ⊆ J) (hJX : J ⊆ X) : I = J := hIJ.antisymm (hI.1.2 ⟨hJ, hJX⟩ hIJ) theorem Basis.Finite (hI : M.Basis I X) [FiniteRk M] : I.Finite := hI.indep.finite theorem basis_iff' : M.Basis I X ↔ (M.Indep I ∧ I ⊆ X ∧ ∀ J, M.Indep J → I ⊆ J → J ⊆ X → I = J) ∧ X ⊆ M.E := by simp [Basis, mem_maximals_setOf_iff, and_assoc, and_congr_left_iff, and_imp, and_congr_left_iff, and_congr_right_iff, @Imp.swap (_ ⊆ X)] theorem basis_iff (hX : X ⊆ M.E := by aesop_mat) : M.Basis I X ↔ (M.Indep I ∧ I ⊆ X ∧ ∀ J, M.Indep J → I ⊆ J → J ⊆ X → I = J) := by rw [basis_iff', and_iff_left hX] theorem basis'_iff_basis_inter_ground : M.Basis' I X ↔ M.Basis I (X ∩ M.E) := by rw [Basis', Basis, and_iff_left inter_subset_right] convert Iff.rfl using 3 ext I simp only [subset_inter_iff, mem_setOf_eq, and_congr_right_iff, and_iff_left_iff_imp] exact fun h _ ↦ h.subset_ground theorem basis'_iff_basis (hX : X ⊆ M.E := by aesop_mat) : M.Basis' I X ↔ M.Basis I X := by rw [basis'_iff_basis_inter_ground, inter_eq_self_of_subset_left hX] theorem basis_iff_basis'_subset_ground : M.Basis I X ↔ M.Basis' I X ∧ X ⊆ M.E := ⟨fun h ↦ ⟨h.basis', h.subset_ground⟩, fun h ↦ (basis'_iff_basis h.2).mp h.1⟩ theorem Basis'.basis_inter_ground (hIX : M.Basis' I X) : M.Basis I (X ∩ M.E) := basis'_iff_basis_inter_ground.mp hIX theorem Basis'.eq_of_subset_indep (hI : M.Basis' I X) (hJ : M.Indep J) (hIJ : I ⊆ J) (hJX : J ⊆ X) : I = J := hIJ.antisymm (hI.2 ⟨hJ, hJX⟩ hIJ) theorem Basis'.insert_not_indep (hI : M.Basis' I X) (he : e ∈ X \ I) : ¬ M.Indep (insert e I) := fun hi ↦ he.2 <| insert_eq_self.1 <| Eq.symm <| hI.eq_of_subset_indep hi (subset_insert _ _) (insert_subset he.1 hI.subset) theorem basis_iff_mem_maximals (hX : X ⊆ M.E := by aesop_mat): M.Basis I X ↔ I ∈ maximals (· ⊆ ·) {I | M.Indep I ∧ I ⊆ X} := by rw [Basis, and_iff_left hX] theorem basis_iff_mem_maximals_Prop (hX : X ⊆ M.E := by aesop_mat): M.Basis I X ↔ I ∈ maximals (· ⊆ ·) (fun I ↦ M.Indep I ∧ I ⊆ X) := basis_iff_mem_maximals theorem Indep.basis_of_maximal_subset (hI : M.Indep I) (hIX : I ⊆ X) (hmax : ∀ ⦃J⦄, M.Indep J → I ⊆ J → J ⊆ X → J ⊆ I) (hX : X ⊆ M.E := by aesop_mat) : M.Basis I X := by rw [basis_iff (by aesop_mat : X ⊆ M.E), and_iff_right hI, and_iff_right hIX] exact fun J hJ hIJ hJX ↦ hIJ.antisymm (hmax hJ hIJ hJX) theorem Basis.basis_subset (hI : M.Basis I X) (hIY : I ⊆ Y) (hYX : Y ⊆ X) : M.Basis I Y := by rw [basis_iff (hYX.trans hI.subset_ground), and_iff_right hI.indep, and_iff_right hIY] exact fun J hJ hIJ hJY ↦ hI.eq_of_subset_indep hJ hIJ (hJY.trans hYX) @[simp] theorem basis_self_iff_indep : M.Basis I I ↔ M.Indep I := by rw [basis_iff', and_iff_right rfl.subset, and_assoc, and_iff_left_iff_imp] exact fun hi ↦ ⟨fun _ _ ↦ subset_antisymm, hi.subset_ground⟩ theorem Indep.basis_self (h : M.Indep I) : M.Basis I I := basis_self_iff_indep.mpr h @[simp] theorem basis_empty_iff (M : Matroid α) : M.Basis I ∅ ↔ I = ∅ := ⟨fun h ↦ subset_empty_iff.mp h.subset, fun h ↦ by (rw [h]; exact M.empty_indep.basis_self)⟩ theorem Basis.dep_of_ssubset (hI : M.Basis I X) (hIY : I ⊂ Y) (hYX : Y ⊆ X) : M.Dep Y := by have : X ⊆ M.E := hI.subset_ground rw [← not_indep_iff] exact fun hY ↦ hIY.ne (hI.eq_of_subset_indep hY hIY.subset hYX) theorem Basis.insert_dep (hI : M.Basis I X) (he : e ∈ X \ I) : M.Dep (insert e I) := hI.dep_of_ssubset (ssubset_insert he.2) (insert_subset he.1 hI.subset) theorem Basis.mem_of_insert_indep (hI : M.Basis I X) (he : e ∈ X) (hIe : M.Indep (insert e I)) : e ∈ I := by_contra (fun heI ↦ (hI.insert_dep ⟨he, heI⟩).not_indep hIe) theorem Basis'.mem_of_insert_indep (hI : M.Basis' I X) (he : e ∈ X) (hIe : M.Indep (insert e I)) : e ∈ I := hI.basis_inter_ground.mem_of_insert_indep ⟨he, hIe.subset_ground (mem_insert _ _)⟩ hIe theorem Basis.not_basis_of_ssubset (hI : M.Basis I X) (hJI : J ⊂ I) : ¬ M.Basis J X := fun h ↦ hJI.ne (h.eq_of_subset_indep hI.indep hJI.subset hI.subset) theorem Indep.subset_basis_of_subset (hI : M.Indep I) (hIX : I ⊆ X) (hX : X ⊆ M.E := by aesop_mat) : ∃ J, M.Basis J X ∧ I ⊆ J := by obtain ⟨J, ⟨(hJ : M.Indep J),hIJ,hJX⟩, hJmax⟩ := M.maximality X hX I hI hIX use J rw [and_iff_left hIJ, basis_iff, and_iff_right hJ, and_iff_right hJX] exact fun K hK hJK hKX ↦ hJK.antisymm (hJmax ⟨hK, hIJ.trans hJK, hKX⟩ hJK) theorem Indep.subset_basis'_of_subset (hI : M.Indep I) (hIX : I ⊆ X) : ∃ J, M.Basis' J X ∧ I ⊆ J := by simp_rw [basis'_iff_basis_inter_ground] exact hI.subset_basis_of_subset (subset_inter hIX hI.subset_ground) theorem exists_basis (M : Matroid α) (X : Set α) (hX : X ⊆ M.E := by aesop_mat) : ∃ I, M.Basis I X := let ⟨_, hI, _⟩ := M.empty_indep.subset_basis_of_subset (empty_subset X) ⟨_,hI⟩ theorem exists_basis' (M : Matroid α) (X : Set α) : ∃ I, M.Basis' I X := let ⟨_, hI, _⟩ := M.empty_indep.subset_basis'_of_subset (empty_subset X) ⟨_,hI⟩ theorem exists_basis_subset_basis (M : Matroid α) (hXY : X ⊆ Y) (hY : Y ⊆ M.E := by aesop_mat) : ∃ I J, M.Basis I X ∧ M.Basis J Y ∧ I ⊆ J := by obtain ⟨I, hI⟩ := M.exists_basis X (hXY.trans hY) obtain ⟨J, hJ, hIJ⟩ := hI.indep.subset_basis_of_subset (hI.subset.trans hXY) exact ⟨_, _, hI, hJ, hIJ⟩ theorem Basis.exists_basis_inter_eq_of_superset (hI : M.Basis I X) (hXY : X ⊆ Y) (hY : Y ⊆ M.E := by aesop_mat) : ∃ J, M.Basis J Y ∧ J ∩ X = I := by obtain ⟨J, hJ, hIJ⟩ := hI.indep.subset_basis_of_subset (hI.subset.trans hXY) refine ⟨J, hJ, subset_antisymm ?_ (subset_inter hIJ hI.subset)⟩ exact fun e he ↦ hI.mem_of_insert_indep he.2 (hJ.indep.subset (insert_subset he.1 hIJ)) theorem exists_basis_union_inter_basis (M : Matroid α) (X Y : Set α) (hX : X ⊆ M.E := by aesop_mat) (hY : Y ⊆ M.E := by aesop_mat) : ∃ I, M.Basis I (X ∪ Y) ∧ M.Basis (I ∩ Y) Y := let ⟨J, hJ⟩ := M.exists_basis Y (hJ.exists_basis_inter_eq_of_superset subset_union_right).imp (fun I hI ↦ ⟨hI.1, by rwa [hI.2]⟩) theorem Indep.eq_of_basis (hI : M.Indep I) (hJ : M.Basis J I) : J = I := hJ.eq_of_subset_indep hI hJ.subset rfl.subset theorem Basis.exists_base (hI : M.Basis I X) : ∃ B, M.Base B ∧ I = B ∩ X := let ⟨B,hB, hIB⟩ := hI.indep.exists_base_superset ⟨B, hB, subset_antisymm (subset_inter hIB hI.subset) (by rw [hI.eq_of_subset_indep (hB.indep.inter_right X) (subset_inter hIB hI.subset) inter_subset_right])⟩ @[simp] theorem basis_ground_iff : M.Basis B M.E ↔ M.Base B := by rw [base_iff_maximal_indep, basis_iff', and_assoc, and_congr_right] rw [and_iff_left (rfl.subset : M.E ⊆ M.E)] exact fun h ↦ ⟨fun h' I hI hBI ↦ h'.2 _ hI hBI hI.subset_ground, fun h' ↦ ⟨h.subset_ground,fun J hJ hBJ _ ↦ h' J hJ hBJ⟩⟩ theorem Base.basis_ground (hB : M.Base B) : M.Basis B M.E := basis_ground_iff.mpr hB theorem Indep.basis_iff_forall_insert_dep (hI : M.Indep I) (hIX : I ⊆ X) : M.Basis I X ↔ ∀ e ∈ X \ I, M.Dep (insert e I) := by rw [basis_iff', and_iff_right hIX, and_iff_right hI] refine ⟨fun h e he ↦ ⟨fun hi ↦ he.2 ?_, insert_subset (h.2 he.1) hI.subset_ground⟩, fun h ↦ ⟨fun J hJ hIJ hJX ↦ hIJ.antisymm (fun e heJ ↦ by_contra (fun heI ↦ ?_)), ?_⟩⟩ · exact (h.1 _ hi (subset_insert _ _) (insert_subset he.1 hIX)).symm.subset (mem_insert e I) · exact (h e ⟨hJX heJ, heI⟩).not_indep (hJ.subset (insert_subset heJ hIJ)) rw [← diff_union_of_subset hIX, union_subset_iff, and_iff_left hI.subset_ground] exact fun e he ↦ (h e he).subset_ground (mem_insert _ _) theorem Indep.basis_of_forall_insert (hI : M.Indep I) (hIX : I ⊆ X) (he : ∀ e ∈ X \ I, M.Dep (insert e I)) : M.Basis I X := (hI.basis_iff_forall_insert_dep hIX).mpr he theorem Indep.basis_insert_iff (hI : M.Indep I) : M.Basis I (insert e I) ↔ M.Dep (insert e I) ∨ e ∈ I := by simp_rw [hI.basis_iff_forall_insert_dep (subset_insert _ _), dep_iff, insert_subset_iff, and_iff_left hI.subset_ground, mem_diff, mem_insert_iff, or_and_right, and_not_self, or_false, and_imp, forall_eq] tauto theorem Basis.iUnion_basis_iUnion {ι : Type _} (X I : ι → Set α) (hI : ∀ i, M.Basis (I i) (X i)) (h_ind : M.Indep (⋃ i, I i)) : M.Basis (⋃ i, I i) (⋃ i, X i) := by refine h_ind.basis_of_forall_insert (iUnion_subset (fun i ↦ (hI i).subset.trans (subset_iUnion _ _))) ?_ rintro e ⟨⟨_, ⟨⟨i, hi, rfl⟩, (hes : e ∈ X i)⟩⟩, he'⟩ rw [mem_iUnion, not_exists] at he' refine ((hI i).insert_dep ⟨hes, he' _⟩).superset (insert_subset_insert (subset_iUnion _ _)) ?_ rw [insert_subset_iff, iUnion_subset_iff, and_iff_left (fun i ↦ (hI i).indep.subset_ground)] exact (hI i).subset_ground hes theorem Basis.basis_iUnion {ι : Type _} [Nonempty ι] (X : ι → Set α) (hI : ∀ i, M.Basis I (X i)) : M.Basis I (⋃ i, X i) := by convert Basis.iUnion_basis_iUnion X (fun _ ↦ I) (fun i ↦ hI i) _ <;> rw [iUnion_const] exact (hI (Classical.arbitrary ι)).indep theorem Basis.basis_sUnion {Xs : Set (Set α)} (hne : Xs.Nonempty) (h : ∀ X ∈ Xs, M.Basis I X) : M.Basis I (⋃₀ Xs) := by rw [sUnion_eq_iUnion] have := Iff.mpr nonempty_coe_sort hne exact Basis.basis_iUnion _ fun X ↦ (h X X.prop) theorem Indep.basis_setOf_insert_basis (hI : M.Indep I) : M.Basis I {x | M.Basis I (insert x I)} := by refine hI.basis_of_forall_insert (fun e he ↦ (?_ : M.Basis _ _)) (fun e he ↦ ⟨fun hu ↦ he.2 ?_, he.1.subset_ground⟩) · rw [insert_eq_of_mem he]; exact hI.basis_self simpa using (hu.eq_of_basis he.1).symm theorem Basis.union_basis_union (hIX : M.Basis I X) (hJY : M.Basis J Y) (h : M.Indep (I ∪ J)) : M.Basis (I ∪ J) (X ∪ Y) := by rw [union_eq_iUnion, union_eq_iUnion] refine Basis.iUnion_basis_iUnion _ _ ?_ ?_ · simp only [Bool.forall_bool, cond_false, cond_true]; exact ⟨hJY, hIX⟩ rwa [← union_eq_iUnion] theorem Basis.basis_union (hIX : M.Basis I X) (hIY : M.Basis I Y) : M.Basis I (X ∪ Y) := by convert hIX.union_basis_union hIY _ <;> rw [union_self]; exact hIX.indep theorem Basis.basis_union_of_subset (hI : M.Basis I X) (hJ : M.Indep J) (hIJ : I ⊆ J) : M.Basis J (J ∪ X) := by convert hJ.basis_self.union_basis_union hI _ <;> rw [union_eq_self_of_subset_right hIJ] assumption
Mathlib/Data/Matroid/Basic.lean
941
944
theorem Basis.insert_basis_insert (hI : M.Basis I X) (h : M.Indep (insert e I)) : M.Basis (insert e I) (insert e X) := by
simp_rw [← union_singleton] at * exact hI.union_basis_union (h.subset subset_union_right).basis_self h
/- Copyright (c) 2022 Jon Eugster. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jon Eugster -/ import Mathlib.Algebra.CharP.LocalRing import Mathlib.RingTheory.Ideal.Quotient import Mathlib.Tactic.FieldSimp #align_import algebra.char_p.mixed_char_zero from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a" /-! # Equal and mixed characteristic In commutative algebra, some statements are simpler when working over a `ℚ`-algebra `R`, in which case one also says that the ring has "equal characteristic zero". A ring that is not a `ℚ`-algebra has either positive characteristic or there exists a prime ideal `I ⊂ R` such that the quotient `R ⧸ I` has positive characteristic `p > 0`. In this case one speaks of "mixed characteristic `(0, p)`", where `p` is only unique if `R` is local. Examples of mixed characteristic rings are `ℤ` or the `p`-adic integers/numbers. This file provides the main theorem `split_by_characteristic` that splits any proposition `P` into the following three cases: 1) Positive characteristic: `CharP R p` (where `p ≠ 0`) 2) Equal characteristic zero: `Algebra ℚ R` 3) Mixed characteristic: `MixedCharZero R p` (where `p` is prime) ## Main definitions - `MixedCharZero` : A ring has mixed characteristic `(0, p)` if it has characteristic zero and there exists an ideal such that the quotient `R ⧸ I` has characteristic `p`. ## Main results - `split_equalCharZero_mixedCharZero` : Split a statement into equal/mixed characteristic zero. This main theorem has the following three corollaries which include the positive characteristic case for convenience: - `split_by_characteristic` : Generally consider positive char `p ≠ 0`. - `split_by_characteristic_domain` : In a domain we can assume that `p` is prime. - `split_by_characteristic_localRing` : In a local ring we can assume that `p` is a prime power. ## Implementation Notes We use the terms `EqualCharZero` and `AlgebraRat` despite not being such definitions in mathlib. The former refers to the statement `∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I)`, the latter refers to the existence of an instance `[Algebra ℚ R]`. The two are shown to be equivalent conditions. ## TODO - Relate mixed characteristic in a local ring to p-adic numbers [NumberTheory.PAdics]. -/ variable (R : Type*) [CommRing R] /-! ### Mixed characteristic -/ /-- A ring of characteristic zero is of "mixed characteristic `(0, p)`" if there exists an ideal such that the quotient `R ⧸ I` has characteristic `p`. **Remark:** For `p = 0`, `MixedChar R 0` is a meaningless definition (i.e. satisfied by any ring) as `R ⧸ ⊥ ≅ R` has by definition always characteristic zero. One could require `(I ≠ ⊥)` in the definition, but then `MixedChar R 0` would mean something like `ℤ`-algebra of extension degree `≥ 1` and would be completely independent from whether something is a `ℚ`-algebra or not (e.g. `ℚ[X]` would satisfy it but `ℚ` wouldn't). -/ class MixedCharZero (p : ℕ) : Prop where [toCharZero : CharZero R] charP_quotient : ∃ I : Ideal R, I ≠ ⊤ ∧ CharP (R ⧸ I) p #align mixed_char_zero MixedCharZero namespace MixedCharZero /-- Reduction to `p` prime: When proving any statement `P` about mixed characteristic rings we can always assume that `p` is prime. -/ theorem reduce_to_p_prime {P : Prop} : (∀ p > 0, MixedCharZero R p → P) ↔ ∀ p : ℕ, p.Prime → MixedCharZero R p → P := by constructor · intro h q q_prime q_mixedChar exact h q (Nat.Prime.pos q_prime) q_mixedChar · intro h q q_pos q_mixedChar rcases q_mixedChar.charP_quotient with ⟨I, hI_ne_top, _⟩ -- Krull's Thm: There exists a prime ideal `P` such that `I ≤ P` rcases Ideal.exists_le_maximal I hI_ne_top with ⟨M, hM_max, h_IM⟩ let r := ringChar (R ⧸ M) have r_pos : r ≠ 0 := by have q_zero := congr_arg (Ideal.Quotient.factor I M h_IM) (CharP.cast_eq_zero (R ⧸ I) q) simp only [map_natCast, map_zero] at q_zero apply ne_zero_of_dvd_ne_zero (ne_of_gt q_pos) exact (CharP.cast_eq_zero_iff (R ⧸ M) r q).mp q_zero have r_prime : Nat.Prime r := or_iff_not_imp_right.1 (CharP.char_is_prime_or_zero (R ⧸ M) r) r_pos apply h r r_prime have : CharZero R := q_mixedChar.toCharZero exact ⟨⟨M, hM_max.ne_top, ringChar.of_eq rfl⟩⟩ #align mixed_char_zero.reduce_to_p_prime MixedCharZero.reduce_to_p_prime /-- Reduction to `I` prime ideal: When proving statements about mixed characteristic rings, after we reduced to `p` prime, we can assume that the ideal `I` in the definition is maximal. -/ theorem reduce_to_maximal_ideal {p : ℕ} (hp : Nat.Prime p) : (∃ I : Ideal R, I ≠ ⊤ ∧ CharP (R ⧸ I) p) ↔ ∃ I : Ideal R, I.IsMaximal ∧ CharP (R ⧸ I) p := by constructor · intro g rcases g with ⟨I, ⟨hI_not_top, _⟩⟩ -- Krull's Thm: There exists a prime ideal `M` such that `I ≤ M`. rcases Ideal.exists_le_maximal I hI_not_top with ⟨M, ⟨hM_max, hM_ge⟩⟩ use M constructor · exact hM_max · cases CharP.exists (R ⧸ M) with | intro r hr => -- Porting note: This is odd. Added `have hr := hr`. -- Without this it seems that lean does not find `hr` as an instance. have hr := hr convert hr have r_dvd_p : r ∣ p := by rw [← CharP.cast_eq_zero_iff (R ⧸ M) r p] convert congr_arg (Ideal.Quotient.factor I M hM_ge) (CharP.cast_eq_zero (R ⧸ I) p) symm apply (Nat.Prime.eq_one_or_self_of_dvd hp r r_dvd_p).resolve_left exact CharP.char_ne_one (R ⧸ M) r · intro ⟨I, hI_max, h_charP⟩ use I exact ⟨Ideal.IsMaximal.ne_top hI_max, h_charP⟩ #align mixed_char_zero.reduce_to_maximal_ideal MixedCharZero.reduce_to_maximal_ideal end MixedCharZero /-! ### Equal characteristic zero A commutative ring `R` has "equal characteristic zero" if it satisfies one of the following equivalent properties: 1) `R` is a `ℚ`-algebra. 2) The quotient `R ⧸ I` has characteristic zero for any proper ideal `I ⊂ R`. 3) `R` has characteristic zero and does not have mixed characteristic for any prime `p`. We show `(1) ↔ (2) ↔ (3)`, and most of the following is concerned with constructing an explicit algebra map `ℚ →+* R` (given by `x ↦ (x.num : R) /ₚ ↑x.pnatDen`) for the direction `(1) ← (2)`. Note: Property `(2)` is denoted as `EqualCharZero` in the statement names below. -/ namespace EqualCharZero /-- `ℚ`-algebra implies equal characteristic. -/ theorem of_algebraRat [Algebra ℚ R] : ∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I) := by intro I hI constructor intro a b h_ab contrapose! hI -- `↑a - ↑b` is a unit contained in `I`, which contradicts `I ≠ ⊤`. refine I.eq_top_of_isUnit_mem ?_ (IsUnit.map (algebraMap ℚ R) (IsUnit.mk0 (a - b : ℚ) ?_)) · simpa only [← Ideal.Quotient.eq_zero_iff_mem, map_sub, sub_eq_zero, map_natCast] simpa only [Ne, sub_eq_zero] using (@Nat.cast_injective ℚ _ _).ne hI set_option linter.uppercaseLean3 false in #align Q_algebra_to_equal_char_zero EqualCharZero.of_algebraRat section ConstructionAlgebraRat variable {R} /-- Internal: Not intended to be used outside this local construction. -/ theorem PNat.isUnit_natCast [h : Fact (∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I))] (n : ℕ+) : IsUnit (n : R) := by -- `n : R` is a unit iff `(n)` is not a proper ideal in `R`. rw [← Ideal.span_singleton_eq_top] -- So by contrapositive, we should show the quotient does not have characteristic zero. apply not_imp_comm.mp (h.elim (Ideal.span {↑n})) intro h_char_zero -- In particular, the image of `n` in the quotient should be nonzero. apply h_char_zero.cast_injective.ne n.ne_zero -- But `n` generates the ideal, so its image is clearly zero. rw [← map_natCast (Ideal.Quotient.mk _), Nat.cast_zero, Ideal.Quotient.eq_zero_iff_mem] exact Ideal.subset_span (Set.mem_singleton _) #align equal_char_zero.pnat_coe_is_unit EqualCharZero.PNat.isUnit_natCast @[coe] noncomputable def pnatCast [Fact (∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I))] : ℕ+ → Rˣ := fun n => (PNat.isUnit_natCast n).unit /-- Internal: Not intended to be used outside this local construction. -/ noncomputable instance coePNatUnits [Fact (∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I))] : Coe ℕ+ Rˣ := ⟨EqualCharZero.pnatCast⟩ #align equal_char_zero.pnat_has_coe_units EqualCharZero.coePNatUnits /-- Internal: Not intended to be used outside this local construction. -/ @[simp] theorem pnatCast_one [Fact (∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I))] : ((1 : ℕ+) : Rˣ) = 1 := by apply Units.ext rw [Units.val_one] change ((PNat.isUnit_natCast (R := R) 1).unit : R) = 1 rw [IsUnit.unit_spec (PNat.isUnit_natCast 1)] rw [PNat.one_coe, Nat.cast_one] #align equal_char_zero.pnat_coe_units_eq_one EqualCharZero.pnatCast_one /-- Internal: Not intended to be used outside this local construction. -/ @[simp]
Mathlib/Algebra/CharP/MixedCharZero.lean
214
217
theorem pnatCast_eq_natCast [Fact (∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I))] (n : ℕ+) : ((n : Rˣ) : R) = ↑n := by
change ((PNat.isUnit_natCast (R := R) n).unit : R) = ↑n simp only [IsUnit.unit_spec]
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad, Minchao Wu, Mario Carneiro -/ import Mathlib.Data.Finset.Attr import Mathlib.Data.Multiset.FinsetOps import Mathlib.Logic.Equiv.Set import Mathlib.Order.Directed import Mathlib.Order.Interval.Set.Basic #align_import data.finset.basic from "leanprover-community/mathlib"@"442a83d738cb208d3600056c489be16900ba701d" /-! # Finite sets Terms of type `Finset α` are one way of talking about finite subsets of `α` in mathlib. Below, `Finset α` is defined as a structure with 2 fields: 1. `val` is a `Multiset α` of elements; 2. `nodup` is a proof that `val` has no duplicates. Finsets in Lean are constructive in that they have an underlying `List` that enumerates their elements. In particular, any function that uses the data of the underlying list cannot depend on its ordering. This is handled on the `Multiset` level by multiset API, so in most cases one needn't worry about it explicitly. Finsets give a basic foundation for defining finite sums and products over types: 1. `∑ i ∈ (s : Finset α), f i`; 2. `∏ i ∈ (s : Finset α), f i`. Lean refers to these operations as big operators. More information can be found in `Mathlib.Algebra.BigOperators.Group.Finset`. Finsets are directly used to define fintypes in Lean. A `Fintype α` instance for a type `α` consists of a universal `Finset α` containing every term of `α`, called `univ`. See `Mathlib.Data.Fintype.Basic`. There is also `univ'`, the noncomputable partner to `univ`, which is defined to be `α` as a finset if `α` is finite, and the empty finset otherwise. See `Mathlib.Data.Fintype.Basic`. `Finset.card`, the size of a finset is defined in `Mathlib.Data.Finset.Card`. This is then used to define `Fintype.card`, the size of a type. ## Main declarations ### Main definitions * `Finset`: Defines a type for the finite subsets of `α`. Constructing a `Finset` requires two pieces of data: `val`, a `Multiset α` of elements, and `nodup`, a proof that `val` has no duplicates. * `Finset.instMembershipFinset`: Defines membership `a ∈ (s : Finset α)`. * `Finset.instCoeTCFinsetSet`: Provides a coercion `s : Finset α` to `s : Set α`. * `Finset.instCoeSortFinsetType`: Coerce `s : Finset α` to the type of all `x ∈ s`. * `Finset.induction_on`: Induction on finsets. To prove a proposition about an arbitrary `Finset α`, it suffices to prove it for the empty finset, and to show that if it holds for some `Finset α`, then it holds for the finset obtained by inserting a new element. * `Finset.choose`: Given a proof `h` of existence and uniqueness of a certain element satisfying a predicate, `choose s h` returns the element of `s` satisfying that predicate. ### Finset constructions * `Finset.instSingletonFinset`: Denoted by `{a}`; the finset consisting of one element. * `Finset.empty`: Denoted by `∅`. The finset associated to any type consisting of no elements. * `Finset.range`: For any `n : ℕ`, `range n` is equal to `{0, 1, ... , n - 1} ⊆ ℕ`. This convention is consistent with other languages and normalizes `card (range n) = n`. Beware, `n` is not in `range n`. * `Finset.attach`: Given `s : Finset α`, `attach s` forms a finset of elements of the subtype `{a // a ∈ s}`; in other words, it attaches elements to a proof of membership in the set. ### Finsets from functions * `Finset.filter`: Given a decidable predicate `p : α → Prop`, `s.filter p` is the finset consisting of those elements in `s` satisfying the predicate `p`. ### The lattice structure on subsets of finsets There is a natural lattice structure on the subsets of a set. In Lean, we use lattice notation to talk about things involving unions and intersections. See `Mathlib.Order.Lattice`. For the lattice structure on finsets, `⊥` is called `bot` with `⊥ = ∅` and `⊤` is called `top` with `⊤ = univ`. * `Finset.instHasSubsetFinset`: Lots of API about lattices, otherwise behaves as one would expect. * `Finset.instUnionFinset`: Defines `s ∪ t` (or `s ⊔ t`) as the union of `s` and `t`. See `Finset.sup`/`Finset.biUnion` for finite unions. * `Finset.instInterFinset`: Defines `s ∩ t` (or `s ⊓ t`) as the intersection of `s` and `t`. See `Finset.inf` for finite intersections. ### Operations on two or more finsets * `insert` and `Finset.cons`: For any `a : α`, `insert s a` returns `s ∪ {a}`. `cons s a h` returns the same except that it requires a hypothesis stating that `a` is not already in `s`. This does not require decidable equality on the type `α`. * `Finset.instUnionFinset`: see "The lattice structure on subsets of finsets" * `Finset.instInterFinset`: see "The lattice structure on subsets of finsets" * `Finset.erase`: For any `a : α`, `erase s a` returns `s` with the element `a` removed. * `Finset.instSDiffFinset`: Defines the set difference `s \ t` for finsets `s` and `t`. * `Finset.product`: Given finsets of `α` and `β`, defines finsets of `α × β`. For arbitrary dependent products, see `Mathlib.Data.Finset.Pi`. ### Predicates on finsets * `Disjoint`: defined via the lattice structure on finsets; two sets are disjoint if their intersection is empty. * `Finset.Nonempty`: A finset is nonempty if it has elements. This is equivalent to saying `s ≠ ∅`. ### Equivalences between finsets * The `Mathlib.Data.Equiv` files describe a general type of equivalence, so look in there for any lemmas. There is some API for rewriting sums and products from `s` to `t` given that `s ≃ t`. TODO: examples ## Tags finite sets, finset -/ -- Assert that we define `Finset` without the material on `List.sublists`. -- Note that we cannot use `List.sublists` itself as that is defined very early. assert_not_exists List.sublistsLen assert_not_exists Multiset.Powerset assert_not_exists CompleteLattice open Multiset Subtype Nat Function universe u variable {α : Type*} {β : Type*} {γ : Type*} /-- `Finset α` is the type of finite sets of elements of `α`. It is implemented as a multiset (a list up to permutation) which has no duplicate elements. -/ structure Finset (α : Type*) where /-- The underlying multiset -/ val : Multiset α /-- `val` contains no duplicates -/ nodup : Nodup val #align finset Finset instance Multiset.canLiftFinset {α} : CanLift (Multiset α) (Finset α) Finset.val Multiset.Nodup := ⟨fun m hm => ⟨⟨m, hm⟩, rfl⟩⟩ #align multiset.can_lift_finset Multiset.canLiftFinset namespace Finset theorem eq_of_veq : ∀ {s t : Finset α}, s.1 = t.1 → s = t | ⟨s, _⟩, ⟨t, _⟩, h => by cases h; rfl #align finset.eq_of_veq Finset.eq_of_veq theorem val_injective : Injective (val : Finset α → Multiset α) := fun _ _ => eq_of_veq #align finset.val_injective Finset.val_injective @[simp] theorem val_inj {s t : Finset α} : s.1 = t.1 ↔ s = t := val_injective.eq_iff #align finset.val_inj Finset.val_inj @[simp] theorem dedup_eq_self [DecidableEq α] (s : Finset α) : dedup s.1 = s.1 := s.2.dedup #align finset.dedup_eq_self Finset.dedup_eq_self instance decidableEq [DecidableEq α] : DecidableEq (Finset α) | _, _ => decidable_of_iff _ val_inj #align finset.has_decidable_eq Finset.decidableEq /-! ### membership -/ instance : Membership α (Finset α) := ⟨fun a s => a ∈ s.1⟩ theorem mem_def {a : α} {s : Finset α} : a ∈ s ↔ a ∈ s.1 := Iff.rfl #align finset.mem_def Finset.mem_def @[simp] theorem mem_val {a : α} {s : Finset α} : a ∈ s.1 ↔ a ∈ s := Iff.rfl #align finset.mem_val Finset.mem_val @[simp] theorem mem_mk {a : α} {s nd} : a ∈ @Finset.mk α s nd ↔ a ∈ s := Iff.rfl #align finset.mem_mk Finset.mem_mk instance decidableMem [_h : DecidableEq α] (a : α) (s : Finset α) : Decidable (a ∈ s) := Multiset.decidableMem _ _ #align finset.decidable_mem Finset.decidableMem @[simp] lemma forall_mem_not_eq {s : Finset α} {a : α} : (∀ b ∈ s, ¬ a = b) ↔ a ∉ s := by aesop @[simp] lemma forall_mem_not_eq' {s : Finset α} {a : α} : (∀ b ∈ s, ¬ b = a) ↔ a ∉ s := by aesop /-! ### set coercion -/ -- Porting note (#11445): new definition /-- Convert a finset to a set in the natural way. -/ @[coe] def toSet (s : Finset α) : Set α := { a | a ∈ s } /-- Convert a finset to a set in the natural way. -/ instance : CoeTC (Finset α) (Set α) := ⟨toSet⟩ @[simp, norm_cast] theorem mem_coe {a : α} {s : Finset α} : a ∈ (s : Set α) ↔ a ∈ (s : Finset α) := Iff.rfl #align finset.mem_coe Finset.mem_coe @[simp] theorem setOf_mem {α} {s : Finset α} : { a | a ∈ s } = s := rfl #align finset.set_of_mem Finset.setOf_mem @[simp] theorem coe_mem {s : Finset α} (x : (s : Set α)) : ↑x ∈ s := x.2 #align finset.coe_mem Finset.coe_mem -- Porting note (#10618): @[simp] can prove this theorem mk_coe {s : Finset α} (x : (s : Set α)) {h} : (⟨x, h⟩ : (s : Set α)) = x := Subtype.coe_eta _ _ #align finset.mk_coe Finset.mk_coe instance decidableMem' [DecidableEq α] (a : α) (s : Finset α) : Decidable (a ∈ (s : Set α)) := s.decidableMem _ #align finset.decidable_mem' Finset.decidableMem' /-! ### extensionality -/ theorem ext_iff {s₁ s₂ : Finset α} : s₁ = s₂ ↔ ∀ a, a ∈ s₁ ↔ a ∈ s₂ := val_inj.symm.trans <| s₁.nodup.ext s₂.nodup #align finset.ext_iff Finset.ext_iff @[ext] theorem ext {s₁ s₂ : Finset α} : (∀ a, a ∈ s₁ ↔ a ∈ s₂) → s₁ = s₂ := ext_iff.2 #align finset.ext Finset.ext @[simp, norm_cast] theorem coe_inj {s₁ s₂ : Finset α} : (s₁ : Set α) = s₂ ↔ s₁ = s₂ := Set.ext_iff.trans ext_iff.symm #align finset.coe_inj Finset.coe_inj theorem coe_injective {α} : Injective ((↑) : Finset α → Set α) := fun _s _t => coe_inj.1 #align finset.coe_injective Finset.coe_injective /-! ### type coercion -/ /-- Coercion from a finset to the corresponding subtype. -/ instance {α : Type u} : CoeSort (Finset α) (Type u) := ⟨fun s => { x // x ∈ s }⟩ -- Porting note (#10618): @[simp] can prove this protected theorem forall_coe {α : Type*} (s : Finset α) (p : s → Prop) : (∀ x : s, p x) ↔ ∀ (x : α) (h : x ∈ s), p ⟨x, h⟩ := Subtype.forall #align finset.forall_coe Finset.forall_coe -- Porting note (#10618): @[simp] can prove this protected theorem exists_coe {α : Type*} (s : Finset α) (p : s → Prop) : (∃ x : s, p x) ↔ ∃ (x : α) (h : x ∈ s), p ⟨x, h⟩ := Subtype.exists #align finset.exists_coe Finset.exists_coe instance PiFinsetCoe.canLift (ι : Type*) (α : ι → Type*) [_ne : ∀ i, Nonempty (α i)] (s : Finset ι) : CanLift (∀ i : s, α i) (∀ i, α i) (fun f i => f i) fun _ => True := PiSubtype.canLift ι α (· ∈ s) #align finset.pi_finset_coe.can_lift Finset.PiFinsetCoe.canLift instance PiFinsetCoe.canLift' (ι α : Type*) [_ne : Nonempty α] (s : Finset ι) : CanLift (s → α) (ι → α) (fun f i => f i) fun _ => True := PiFinsetCoe.canLift ι (fun _ => α) s #align finset.pi_finset_coe.can_lift' Finset.PiFinsetCoe.canLift' instance FinsetCoe.canLift (s : Finset α) : CanLift α s (↑) fun a => a ∈ s where prf a ha := ⟨⟨a, ha⟩, rfl⟩ #align finset.finset_coe.can_lift Finset.FinsetCoe.canLift @[simp, norm_cast] theorem coe_sort_coe (s : Finset α) : ((s : Set α) : Sort _) = s := rfl #align finset.coe_sort_coe Finset.coe_sort_coe /-! ### Subset and strict subset relations -/ section Subset variable {s t : Finset α} instance : HasSubset (Finset α) := ⟨fun s t => ∀ ⦃a⦄, a ∈ s → a ∈ t⟩ instance : HasSSubset (Finset α) := ⟨fun s t => s ⊆ t ∧ ¬t ⊆ s⟩ instance partialOrder : PartialOrder (Finset α) where le := (· ⊆ ·) lt := (· ⊂ ·) le_refl s a := id le_trans s t u hst htu a ha := htu <| hst ha le_antisymm s t hst hts := ext fun a => ⟨@hst _, @hts _⟩ instance : IsRefl (Finset α) (· ⊆ ·) := show IsRefl (Finset α) (· ≤ ·) by infer_instance instance : IsTrans (Finset α) (· ⊆ ·) := show IsTrans (Finset α) (· ≤ ·) by infer_instance instance : IsAntisymm (Finset α) (· ⊆ ·) := show IsAntisymm (Finset α) (· ≤ ·) by infer_instance instance : IsIrrefl (Finset α) (· ⊂ ·) := show IsIrrefl (Finset α) (· < ·) by infer_instance instance : IsTrans (Finset α) (· ⊂ ·) := show IsTrans (Finset α) (· < ·) by infer_instance instance : IsAsymm (Finset α) (· ⊂ ·) := show IsAsymm (Finset α) (· < ·) by infer_instance instance : IsNonstrictStrictOrder (Finset α) (· ⊆ ·) (· ⊂ ·) := ⟨fun _ _ => Iff.rfl⟩ theorem subset_def : s ⊆ t ↔ s.1 ⊆ t.1 := Iff.rfl #align finset.subset_def Finset.subset_def theorem ssubset_def : s ⊂ t ↔ s ⊆ t ∧ ¬t ⊆ s := Iff.rfl #align finset.ssubset_def Finset.ssubset_def @[simp] theorem Subset.refl (s : Finset α) : s ⊆ s := Multiset.Subset.refl _ #align finset.subset.refl Finset.Subset.refl protected theorem Subset.rfl {s : Finset α} : s ⊆ s := Subset.refl _ #align finset.subset.rfl Finset.Subset.rfl protected theorem subset_of_eq {s t : Finset α} (h : s = t) : s ⊆ t := h ▸ Subset.refl _ #align finset.subset_of_eq Finset.subset_of_eq theorem Subset.trans {s₁ s₂ s₃ : Finset α} : s₁ ⊆ s₂ → s₂ ⊆ s₃ → s₁ ⊆ s₃ := Multiset.Subset.trans #align finset.subset.trans Finset.Subset.trans theorem Superset.trans {s₁ s₂ s₃ : Finset α} : s₁ ⊇ s₂ → s₂ ⊇ s₃ → s₁ ⊇ s₃ := fun h' h => Subset.trans h h' #align finset.superset.trans Finset.Superset.trans theorem mem_of_subset {s₁ s₂ : Finset α} {a : α} : s₁ ⊆ s₂ → a ∈ s₁ → a ∈ s₂ := Multiset.mem_of_subset #align finset.mem_of_subset Finset.mem_of_subset theorem not_mem_mono {s t : Finset α} (h : s ⊆ t) {a : α} : a ∉ t → a ∉ s := mt <| @h _ #align finset.not_mem_mono Finset.not_mem_mono theorem Subset.antisymm {s₁ s₂ : Finset α} (H₁ : s₁ ⊆ s₂) (H₂ : s₂ ⊆ s₁) : s₁ = s₂ := ext fun a => ⟨@H₁ a, @H₂ a⟩ #align finset.subset.antisymm Finset.Subset.antisymm theorem subset_iff {s₁ s₂ : Finset α} : s₁ ⊆ s₂ ↔ ∀ ⦃x⦄, x ∈ s₁ → x ∈ s₂ := Iff.rfl #align finset.subset_iff Finset.subset_iff @[simp, norm_cast] theorem coe_subset {s₁ s₂ : Finset α} : (s₁ : Set α) ⊆ s₂ ↔ s₁ ⊆ s₂ := Iff.rfl #align finset.coe_subset Finset.coe_subset @[simp] theorem val_le_iff {s₁ s₂ : Finset α} : s₁.1 ≤ s₂.1 ↔ s₁ ⊆ s₂ := le_iff_subset s₁.2 #align finset.val_le_iff Finset.val_le_iff theorem Subset.antisymm_iff {s₁ s₂ : Finset α} : s₁ = s₂ ↔ s₁ ⊆ s₂ ∧ s₂ ⊆ s₁ := le_antisymm_iff #align finset.subset.antisymm_iff Finset.Subset.antisymm_iff theorem not_subset : ¬s ⊆ t ↔ ∃ x ∈ s, x ∉ t := by simp only [← coe_subset, Set.not_subset, mem_coe] #align finset.not_subset Finset.not_subset @[simp] theorem le_eq_subset : ((· ≤ ·) : Finset α → Finset α → Prop) = (· ⊆ ·) := rfl #align finset.le_eq_subset Finset.le_eq_subset @[simp] theorem lt_eq_subset : ((· < ·) : Finset α → Finset α → Prop) = (· ⊂ ·) := rfl #align finset.lt_eq_subset Finset.lt_eq_subset theorem le_iff_subset {s₁ s₂ : Finset α} : s₁ ≤ s₂ ↔ s₁ ⊆ s₂ := Iff.rfl #align finset.le_iff_subset Finset.le_iff_subset theorem lt_iff_ssubset {s₁ s₂ : Finset α} : s₁ < s₂ ↔ s₁ ⊂ s₂ := Iff.rfl #align finset.lt_iff_ssubset Finset.lt_iff_ssubset @[simp, norm_cast] theorem coe_ssubset {s₁ s₂ : Finset α} : (s₁ : Set α) ⊂ s₂ ↔ s₁ ⊂ s₂ := show (s₁ : Set α) ⊂ s₂ ↔ s₁ ⊆ s₂ ∧ ¬s₂ ⊆ s₁ by simp only [Set.ssubset_def, Finset.coe_subset] #align finset.coe_ssubset Finset.coe_ssubset @[simp] theorem val_lt_iff {s₁ s₂ : Finset α} : s₁.1 < s₂.1 ↔ s₁ ⊂ s₂ := and_congr val_le_iff <| not_congr val_le_iff #align finset.val_lt_iff Finset.val_lt_iff lemma val_strictMono : StrictMono (val : Finset α → Multiset α) := fun _ _ ↦ val_lt_iff.2 theorem ssubset_iff_subset_ne {s t : Finset α} : s ⊂ t ↔ s ⊆ t ∧ s ≠ t := @lt_iff_le_and_ne _ _ s t #align finset.ssubset_iff_subset_ne Finset.ssubset_iff_subset_ne theorem ssubset_iff_of_subset {s₁ s₂ : Finset α} (h : s₁ ⊆ s₂) : s₁ ⊂ s₂ ↔ ∃ x ∈ s₂, x ∉ s₁ := Set.ssubset_iff_of_subset h #align finset.ssubset_iff_of_subset Finset.ssubset_iff_of_subset theorem ssubset_of_ssubset_of_subset {s₁ s₂ s₃ : Finset α} (hs₁s₂ : s₁ ⊂ s₂) (hs₂s₃ : s₂ ⊆ s₃) : s₁ ⊂ s₃ := Set.ssubset_of_ssubset_of_subset hs₁s₂ hs₂s₃ #align finset.ssubset_of_ssubset_of_subset Finset.ssubset_of_ssubset_of_subset theorem ssubset_of_subset_of_ssubset {s₁ s₂ s₃ : Finset α} (hs₁s₂ : s₁ ⊆ s₂) (hs₂s₃ : s₂ ⊂ s₃) : s₁ ⊂ s₃ := Set.ssubset_of_subset_of_ssubset hs₁s₂ hs₂s₃ #align finset.ssubset_of_subset_of_ssubset Finset.ssubset_of_subset_of_ssubset theorem exists_of_ssubset {s₁ s₂ : Finset α} (h : s₁ ⊂ s₂) : ∃ x ∈ s₂, x ∉ s₁ := Set.exists_of_ssubset h #align finset.exists_of_ssubset Finset.exists_of_ssubset instance isWellFounded_ssubset : IsWellFounded (Finset α) (· ⊂ ·) := Subrelation.isWellFounded (InvImage _ _) val_lt_iff.2 #align finset.is_well_founded_ssubset Finset.isWellFounded_ssubset instance wellFoundedLT : WellFoundedLT (Finset α) := Finset.isWellFounded_ssubset #align finset.is_well_founded_lt Finset.wellFoundedLT end Subset -- TODO: these should be global attributes, but this will require fixing other files attribute [local trans] Subset.trans Superset.trans /-! ### Order embedding from `Finset α` to `Set α` -/ /-- Coercion to `Set α` as an `OrderEmbedding`. -/ def coeEmb : Finset α ↪o Set α := ⟨⟨(↑), coe_injective⟩, coe_subset⟩ #align finset.coe_emb Finset.coeEmb @[simp] theorem coe_coeEmb : ⇑(coeEmb : Finset α ↪o Set α) = ((↑) : Finset α → Set α) := rfl #align finset.coe_coe_emb Finset.coe_coeEmb /-! ### Nonempty -/ /-- The property `s.Nonempty` expresses the fact that the finset `s` is not empty. It should be used in theorem assumptions instead of `∃ x, x ∈ s` or `s ≠ ∅` as it gives access to a nice API thanks to the dot notation. -/ protected def Nonempty (s : Finset α) : Prop := ∃ x : α, x ∈ s #align finset.nonempty Finset.Nonempty -- Porting note: Much longer than in Lean3 instance decidableNonempty {s : Finset α} : Decidable s.Nonempty := Quotient.recOnSubsingleton (motive := fun s : Multiset α => Decidable (∃ a, a ∈ s)) s.1 (fun l : List α => match l with | [] => isFalse <| by simp | a::l => isTrue ⟨a, by simp⟩) #align finset.decidable_nonempty Finset.decidableNonempty @[simp, norm_cast] theorem coe_nonempty {s : Finset α} : (s : Set α).Nonempty ↔ s.Nonempty := Iff.rfl #align finset.coe_nonempty Finset.coe_nonempty -- Porting note: Left-hand side simplifies @[simp] theorem nonempty_coe_sort {s : Finset α} : Nonempty (s : Type _) ↔ s.Nonempty := nonempty_subtype #align finset.nonempty_coe_sort Finset.nonempty_coe_sort alias ⟨_, Nonempty.to_set⟩ := coe_nonempty #align finset.nonempty.to_set Finset.Nonempty.to_set alias ⟨_, Nonempty.coe_sort⟩ := nonempty_coe_sort #align finset.nonempty.coe_sort Finset.Nonempty.coe_sort theorem Nonempty.exists_mem {s : Finset α} (h : s.Nonempty) : ∃ x : α, x ∈ s := h #align finset.nonempty.bex Finset.Nonempty.exists_mem @[deprecated (since := "2024-03-23")] alias Nonempty.bex := Nonempty.exists_mem theorem Nonempty.mono {s t : Finset α} (hst : s ⊆ t) (hs : s.Nonempty) : t.Nonempty := Set.Nonempty.mono hst hs #align finset.nonempty.mono Finset.Nonempty.mono theorem Nonempty.forall_const {s : Finset α} (h : s.Nonempty) {p : Prop} : (∀ x ∈ s, p) ↔ p := let ⟨x, hx⟩ := h ⟨fun h => h x hx, fun h _ _ => h⟩ #align finset.nonempty.forall_const Finset.Nonempty.forall_const theorem Nonempty.to_subtype {s : Finset α} : s.Nonempty → Nonempty s := nonempty_coe_sort.2 #align finset.nonempty.to_subtype Finset.Nonempty.to_subtype theorem Nonempty.to_type {s : Finset α} : s.Nonempty → Nonempty α := fun ⟨x, _hx⟩ => ⟨x⟩ #align finset.nonempty.to_type Finset.Nonempty.to_type /-! ### empty -/ section Empty variable {s : Finset α} /-- The empty finset -/ protected def empty : Finset α := ⟨0, nodup_zero⟩ #align finset.empty Finset.empty instance : EmptyCollection (Finset α) := ⟨Finset.empty⟩ instance inhabitedFinset : Inhabited (Finset α) := ⟨∅⟩ #align finset.inhabited_finset Finset.inhabitedFinset @[simp] theorem empty_val : (∅ : Finset α).1 = 0 := rfl #align finset.empty_val Finset.empty_val @[simp] theorem not_mem_empty (a : α) : a ∉ (∅ : Finset α) := by -- Porting note: was `id`. `a ∈ List.nil` is no longer definitionally equal to `False` simp only [mem_def, empty_val, not_mem_zero, not_false_iff] #align finset.not_mem_empty Finset.not_mem_empty @[simp] theorem not_nonempty_empty : ¬(∅ : Finset α).Nonempty := fun ⟨x, hx⟩ => not_mem_empty x hx #align finset.not_nonempty_empty Finset.not_nonempty_empty @[simp] theorem mk_zero : (⟨0, nodup_zero⟩ : Finset α) = ∅ := rfl #align finset.mk_zero Finset.mk_zero theorem ne_empty_of_mem {a : α} {s : Finset α} (h : a ∈ s) : s ≠ ∅ := fun e => not_mem_empty a <| e ▸ h #align finset.ne_empty_of_mem Finset.ne_empty_of_mem theorem Nonempty.ne_empty {s : Finset α} (h : s.Nonempty) : s ≠ ∅ := (Exists.elim h) fun _a => ne_empty_of_mem #align finset.nonempty.ne_empty Finset.Nonempty.ne_empty @[simp] theorem empty_subset (s : Finset α) : ∅ ⊆ s := zero_subset _ #align finset.empty_subset Finset.empty_subset theorem eq_empty_of_forall_not_mem {s : Finset α} (H : ∀ x, x ∉ s) : s = ∅ := eq_of_veq (eq_zero_of_forall_not_mem H) #align finset.eq_empty_of_forall_not_mem Finset.eq_empty_of_forall_not_mem theorem eq_empty_iff_forall_not_mem {s : Finset α} : s = ∅ ↔ ∀ x, x ∉ s := -- Porting note: used `id` ⟨by rintro rfl x; apply not_mem_empty, fun h => eq_empty_of_forall_not_mem h⟩ #align finset.eq_empty_iff_forall_not_mem Finset.eq_empty_iff_forall_not_mem @[simp] theorem val_eq_zero {s : Finset α} : s.1 = 0 ↔ s = ∅ := @val_inj _ s ∅ #align finset.val_eq_zero Finset.val_eq_zero theorem subset_empty {s : Finset α} : s ⊆ ∅ ↔ s = ∅ := subset_zero.trans val_eq_zero #align finset.subset_empty Finset.subset_empty @[simp] theorem not_ssubset_empty (s : Finset α) : ¬s ⊂ ∅ := fun h => let ⟨_, he, _⟩ := exists_of_ssubset h -- Porting note: was `he` not_mem_empty _ he #align finset.not_ssubset_empty Finset.not_ssubset_empty theorem nonempty_of_ne_empty {s : Finset α} (h : s ≠ ∅) : s.Nonempty := exists_mem_of_ne_zero (mt val_eq_zero.1 h) #align finset.nonempty_of_ne_empty Finset.nonempty_of_ne_empty theorem nonempty_iff_ne_empty {s : Finset α} : s.Nonempty ↔ s ≠ ∅ := ⟨Nonempty.ne_empty, nonempty_of_ne_empty⟩ #align finset.nonempty_iff_ne_empty Finset.nonempty_iff_ne_empty @[simp] theorem not_nonempty_iff_eq_empty {s : Finset α} : ¬s.Nonempty ↔ s = ∅ := nonempty_iff_ne_empty.not.trans not_not #align finset.not_nonempty_iff_eq_empty Finset.not_nonempty_iff_eq_empty theorem eq_empty_or_nonempty (s : Finset α) : s = ∅ ∨ s.Nonempty := by_cases Or.inl fun h => Or.inr (nonempty_of_ne_empty h) #align finset.eq_empty_or_nonempty Finset.eq_empty_or_nonempty @[simp, norm_cast] theorem coe_empty : ((∅ : Finset α) : Set α) = ∅ := Set.ext <| by simp #align finset.coe_empty Finset.coe_empty @[simp, norm_cast] theorem coe_eq_empty {s : Finset α} : (s : Set α) = ∅ ↔ s = ∅ := by rw [← coe_empty, coe_inj] #align finset.coe_eq_empty Finset.coe_eq_empty -- Porting note: Left-hand side simplifies @[simp] theorem isEmpty_coe_sort {s : Finset α} : IsEmpty (s : Type _) ↔ s = ∅ := by simpa using @Set.isEmpty_coe_sort α s #align finset.is_empty_coe_sort Finset.isEmpty_coe_sort instance instIsEmpty : IsEmpty (∅ : Finset α) := isEmpty_coe_sort.2 rfl /-- A `Finset` for an empty type is empty. -/ theorem eq_empty_of_isEmpty [IsEmpty α] (s : Finset α) : s = ∅ := Finset.eq_empty_of_forall_not_mem isEmptyElim #align finset.eq_empty_of_is_empty Finset.eq_empty_of_isEmpty instance : OrderBot (Finset α) where bot := ∅ bot_le := empty_subset @[simp] theorem bot_eq_empty : (⊥ : Finset α) = ∅ := rfl #align finset.bot_eq_empty Finset.bot_eq_empty @[simp] theorem empty_ssubset : ∅ ⊂ s ↔ s.Nonempty := (@bot_lt_iff_ne_bot (Finset α) _ _ _).trans nonempty_iff_ne_empty.symm #align finset.empty_ssubset Finset.empty_ssubset alias ⟨_, Nonempty.empty_ssubset⟩ := empty_ssubset #align finset.nonempty.empty_ssubset Finset.Nonempty.empty_ssubset end Empty /-! ### singleton -/ section Singleton variable {s : Finset α} {a b : α} /-- `{a} : Finset a` is the set `{a}` containing `a` and nothing else. This differs from `insert a ∅` in that it does not require a `DecidableEq` instance for `α`. -/ instance : Singleton α (Finset α) := ⟨fun a => ⟨{a}, nodup_singleton a⟩⟩ @[simp] theorem singleton_val (a : α) : ({a} : Finset α).1 = {a} := rfl #align finset.singleton_val Finset.singleton_val @[simp] theorem mem_singleton {a b : α} : b ∈ ({a} : Finset α) ↔ b = a := Multiset.mem_singleton #align finset.mem_singleton Finset.mem_singleton theorem eq_of_mem_singleton {x y : α} (h : x ∈ ({y} : Finset α)) : x = y := mem_singleton.1 h #align finset.eq_of_mem_singleton Finset.eq_of_mem_singleton theorem not_mem_singleton {a b : α} : a ∉ ({b} : Finset α) ↔ a ≠ b := not_congr mem_singleton #align finset.not_mem_singleton Finset.not_mem_singleton theorem mem_singleton_self (a : α) : a ∈ ({a} : Finset α) := -- Porting note: was `Or.inl rfl` mem_singleton.mpr rfl #align finset.mem_singleton_self Finset.mem_singleton_self @[simp]
Mathlib/Data/Finset/Basic.lean
698
700
theorem val_eq_singleton_iff {a : α} {s : Finset α} : s.val = {a} ↔ s = {a} := by
rw [← val_inj] rfl
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Johan Commelin, Patrick Massot -/ import Mathlib.Algebra.Group.WithOne.Defs import Mathlib.Algebra.GroupWithZero.InjSurj import Mathlib.Algebra.GroupWithZero.Units.Equiv import Mathlib.Algebra.GroupWithZero.WithZero import Mathlib.Algebra.Order.Group.Units import Mathlib.Algebra.Order.GroupWithZero.Synonym import Mathlib.Algebra.Order.Monoid.Basic import Mathlib.Algebra.Order.Monoid.OrderDual import Mathlib.Algebra.Order.Monoid.TypeTags import Mathlib.Algebra.Order.ZeroLEOne #align_import algebra.order.monoid.with_zero.defs from "leanprover-community/mathlib"@"4dc134b97a3de65ef2ed881f3513d56260971562" #align_import algebra.order.monoid.with_zero.basic from "leanprover-community/mathlib"@"dad7ecf9a1feae63e6e49f07619b7087403fb8d4" #align_import algebra.order.with_zero from "leanprover-community/mathlib"@"655994e298904d7e5bbd1e18c95defd7b543eb94" /-! # Linearly ordered commutative groups and monoids with a zero element adjoined This file sets up a special class of linearly ordered commutative monoids that show up as the target of so-called “valuations” in algebraic number theory. Usually, in the informal literature, these objects are constructed by taking a linearly ordered commutative group Γ and formally adjoining a zero element: Γ ∪ {0}. The disadvantage is that a type such as `NNReal` is not of that form, whereas it is a very common target for valuations. The solutions is to use a typeclass, and that is exactly what we do in this file. -/ variable {α : Type*} /-- A linearly ordered commutative monoid with a zero element. -/ class LinearOrderedCommMonoidWithZero (α : Type*) extends LinearOrderedCommMonoid α, CommMonoidWithZero α where /-- `0 ≤ 1` in any linearly ordered commutative monoid. -/ zero_le_one : (0 : α) ≤ 1 #align linear_ordered_comm_monoid_with_zero LinearOrderedCommMonoidWithZero /-- A linearly ordered commutative group with a zero element. -/ class LinearOrderedCommGroupWithZero (α : Type*) extends LinearOrderedCommMonoidWithZero α, CommGroupWithZero α #align linear_ordered_comm_group_with_zero LinearOrderedCommGroupWithZero instance (priority := 100) LinearOrderedCommMonoidWithZero.toZeroLeOneClass [LinearOrderedCommMonoidWithZero α] : ZeroLEOneClass α := { ‹LinearOrderedCommMonoidWithZero α› with } #align linear_ordered_comm_monoid_with_zero.to_zero_le_one_class LinearOrderedCommMonoidWithZero.toZeroLeOneClass instance (priority := 100) canonicallyOrderedAddCommMonoid.toZeroLeOneClass [CanonicallyOrderedAddCommMonoid α] [One α] : ZeroLEOneClass α := ⟨zero_le 1⟩ #align canonically_ordered_add_monoid.to_zero_le_one_class canonicallyOrderedAddCommMonoid.toZeroLeOneClass section LinearOrderedCommMonoidWithZero variable [LinearOrderedCommMonoidWithZero α] {a b c d x y z : α} {n : ℕ} /- The following facts are true more generally in a (linearly) ordered commutative monoid. -/ /-- Pullback a `LinearOrderedCommMonoidWithZero` under an injective map. See note [reducible non-instances]. -/ abbrev Function.Injective.linearOrderedCommMonoidWithZero {β : Type*} [Zero β] [One β] [Mul β] [Pow β ℕ] [Sup β] [Inf β] (f : β → α) (hf : Function.Injective f) (zero : f 0 = 0) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (hsup : ∀ x y, f (x ⊔ y) = max (f x) (f y)) (hinf : ∀ x y, f (x ⊓ y) = min (f x) (f y)) : LinearOrderedCommMonoidWithZero β := { LinearOrder.lift f hf hsup hinf, hf.orderedCommMonoid f one mul npow, hf.commMonoidWithZero f zero one mul npow with zero_le_one := show f 0 ≤ f 1 by simp only [zero, one, LinearOrderedCommMonoidWithZero.zero_le_one] } #align function.injective.linear_ordered_comm_monoid_with_zero Function.Injective.linearOrderedCommMonoidWithZero @[simp] lemma zero_le' : 0 ≤ a := by simpa only [mul_zero, mul_one] using mul_le_mul_left' (zero_le_one' α) a #align zero_le' zero_le' @[simp] theorem not_lt_zero' : ¬a < 0 := not_lt_of_le zero_le' #align not_lt_zero' not_lt_zero' @[simp] theorem le_zero_iff : a ≤ 0 ↔ a = 0 := ⟨fun h ↦ le_antisymm h zero_le', fun h ↦ h ▸ le_rfl⟩ #align le_zero_iff le_zero_iff theorem zero_lt_iff : 0 < a ↔ a ≠ 0 := ⟨ne_of_gt, fun h ↦ lt_of_le_of_ne zero_le' h.symm⟩ #align zero_lt_iff zero_lt_iff theorem ne_zero_of_lt (h : b < a) : a ≠ 0 := fun h1 ↦ not_lt_zero' <| show b < 0 from h1 ▸ h #align ne_zero_of_lt ne_zero_of_lt instance instLinearOrderedAddCommMonoidWithTopAdditiveOrderDual : LinearOrderedAddCommMonoidWithTop (Additive αᵒᵈ) := { Additive.orderedAddCommMonoid, Additive.linearOrder with top := (0 : α) top_add' := fun a ↦ zero_mul (Additive.toMul a) le_top := fun _ ↦ zero_le' } #align additive.linear_ordered_add_comm_monoid_with_top instLinearOrderedAddCommMonoidWithTopAdditiveOrderDual variable [NoZeroDivisors α] lemma pow_pos_iff (hn : n ≠ 0) : 0 < a ^ n ↔ 0 < a := by simp_rw [zero_lt_iff, pow_ne_zero_iff hn] #align pow_pos_iff pow_pos_iff end LinearOrderedCommMonoidWithZero section LinearOrderedCommGroupWithZero variable [LinearOrderedCommGroupWithZero α] {a b c d : α} {m n : ℕ} -- TODO: Do we really need the following two? /-- Alias of `mul_le_one'` for unification. -/ theorem mul_le_one₀ (ha : a ≤ 1) (hb : b ≤ 1) : a * b ≤ 1 := mul_le_one' ha hb #align mul_le_one₀ mul_le_one₀ /-- Alias of `one_le_mul'` for unification. -/ theorem one_le_mul₀ (ha : 1 ≤ a) (hb : 1 ≤ b) : 1 ≤ a * b := one_le_mul ha hb #align one_le_mul₀ one_le_mul₀
Mathlib/Algebra/Order/GroupWithZero/Canonical.lean
128
129
theorem le_of_le_mul_right (h : c ≠ 0) (hab : a * c ≤ b * c) : a ≤ b := by
simpa only [mul_inv_cancel_right₀ h] using mul_le_mul_right' hab c⁻¹
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro -/ import Batteries.Tactic.Alias import Batteries.Data.List.Init.Attach import Batteries.Data.List.Pairwise -- Adaptation note: nightly-2024-03-18. We should be able to remove this after nightly-2024-03-19. import Lean.Elab.Tactic.Rfl /-! # List Permutations This file introduces the `List.Perm` relation, which is true if two lists are permutations of one another. ## Notation The notation `~` is used for permutation equivalence. -/ open Nat namespace List open Perm (swap) @[simp, refl] protected theorem Perm.refl : ∀ l : List α, l ~ l | [] => .nil | x :: xs => (Perm.refl xs).cons x protected theorem Perm.rfl {l : List α} : l ~ l := .refl _ theorem Perm.of_eq (h : l₁ = l₂) : l₁ ~ l₂ := h ▸ .rfl protected theorem Perm.symm {l₁ l₂ : List α} (h : l₁ ~ l₂) : l₂ ~ l₁ := by induction h with | nil => exact nil | cons _ _ ih => exact cons _ ih | swap => exact swap .. | trans _ _ ih₁ ih₂ => exact trans ih₂ ih₁ theorem perm_comm {l₁ l₂ : List α} : l₁ ~ l₂ ↔ l₂ ~ l₁ := ⟨Perm.symm, Perm.symm⟩ theorem Perm.swap' (x y : α) {l₁ l₂ : List α} (p : l₁ ~ l₂) : y :: x :: l₁ ~ x :: y :: l₂ := (swap ..).trans <| p.cons _ |>.cons _ /-- Similar to `Perm.recOn`, but the `swap` case is generalized to `Perm.swap'`, where the tail of the lists are not necessarily the same. -/ @[elab_as_elim] theorem Perm.recOnSwap' {motive : (l₁ : List α) → (l₂ : List α) → l₁ ~ l₂ → Prop} {l₁ l₂ : List α} (p : l₁ ~ l₂) (nil : motive [] [] .nil) (cons : ∀ x {l₁ l₂}, (h : l₁ ~ l₂) → motive l₁ l₂ h → motive (x :: l₁) (x :: l₂) (.cons x h)) (swap' : ∀ x y {l₁ l₂}, (h : l₁ ~ l₂) → motive l₁ l₂ h → motive (y :: x :: l₁) (x :: y :: l₂) (.swap' _ _ h)) (trans : ∀ {l₁ l₂ l₃}, (h₁ : l₁ ~ l₂) → (h₂ : l₂ ~ l₃) → motive l₁ l₂ h₁ → motive l₂ l₃ h₂ → motive l₁ l₃ (.trans h₁ h₂)) : motive l₁ l₂ p := have motive_refl l : motive l l (.refl l) := List.recOn l nil fun x xs ih => cons x (.refl xs) ih Perm.recOn p nil cons (fun x y l => swap' x y (.refl l) (motive_refl l)) trans theorem Perm.eqv (α) : Equivalence (@Perm α) := ⟨.refl, .symm, .trans⟩ instance isSetoid (α) : Setoid (List α) := .mk Perm (Perm.eqv α) theorem Perm.mem_iff {a : α} {l₁ l₂ : List α} (p : l₁ ~ l₂) : a ∈ l₁ ↔ a ∈ l₂ := by induction p with | nil => rfl | cons _ _ ih => simp only [mem_cons, ih] | swap => simp only [mem_cons, or_left_comm] | trans _ _ ih₁ ih₂ => simp only [ih₁, ih₂] theorem Perm.subset {l₁ l₂ : List α} (p : l₁ ~ l₂) : l₁ ⊆ l₂ := fun _ => p.mem_iff.mp theorem Perm.append_right {l₁ l₂ : List α} (t₁ : List α) (p : l₁ ~ l₂) : l₁ ++ t₁ ~ l₂ ++ t₁ := by induction p with | nil => rfl | cons _ _ ih => exact cons _ ih | swap => exact swap .. | trans _ _ ih₁ ih₂ => exact trans ih₁ ih₂ theorem Perm.append_left {t₁ t₂ : List α} : ∀ l : List α, t₁ ~ t₂ → l ++ t₁ ~ l ++ t₂ | [], p => p | x :: xs, p => (p.append_left xs).cons x theorem Perm.append {l₁ l₂ t₁ t₂ : List α} (p₁ : l₁ ~ l₂) (p₂ : t₁ ~ t₂) : l₁ ++ t₁ ~ l₂ ++ t₂ := (p₁.append_right t₁).trans (p₂.append_left l₂) theorem Perm.append_cons (a : α) {h₁ h₂ t₁ t₂ : List α} (p₁ : h₁ ~ h₂) (p₂ : t₁ ~ t₂) : h₁ ++ a :: t₁ ~ h₂ ++ a :: t₂ := p₁.append (p₂.cons a) @[simp] theorem perm_middle {a : α} : ∀ {l₁ l₂ : List α}, l₁ ++ a :: l₂ ~ a :: (l₁ ++ l₂) | [], _ => .refl _ | b :: _, _ => (Perm.cons _ perm_middle).trans (swap a b _) @[simp] theorem perm_append_singleton (a : α) (l : List α) : l ++ [a] ~ a :: l := perm_middle.trans <| by rw [append_nil] theorem perm_append_comm : ∀ {l₁ l₂ : List α}, l₁ ++ l₂ ~ l₂ ++ l₁ | [], l₂ => by simp | a :: t, l₂ => (perm_append_comm.cons _).trans perm_middle.symm theorem concat_perm (l : List α) (a : α) : concat l a ~ a :: l := by simp theorem Perm.length_eq {l₁ l₂ : List α} (p : l₁ ~ l₂) : length l₁ = length l₂ := by induction p with | nil => rfl | cons _ _ ih => simp only [length_cons, ih] | swap => rfl | trans _ _ ih₁ ih₂ => simp only [ih₁, ih₂] theorem Perm.eq_nil {l : List α} (p : l ~ []) : l = [] := eq_nil_of_length_eq_zero p.length_eq theorem Perm.nil_eq {l : List α} (p : [] ~ l) : [] = l := p.symm.eq_nil.symm @[simp] theorem perm_nil {l₁ : List α} : l₁ ~ [] ↔ l₁ = [] := ⟨fun p => p.eq_nil, fun e => e ▸ .rfl⟩ @[simp] theorem nil_perm {l₁ : List α} : [] ~ l₁ ↔ l₁ = [] := perm_comm.trans perm_nil theorem not_perm_nil_cons (x : α) (l : List α) : ¬[] ~ x :: l := (nomatch ·.symm.eq_nil) @[simp] theorem reverse_perm : ∀ l : List α, reverse l ~ l | [] => .nil | a :: l => reverse_cons .. ▸ (perm_append_singleton _ _).trans ((reverse_perm l).cons a) theorem perm_cons_append_cons {l l₁ l₂ : List α} (a : α) (p : l ~ l₁ ++ l₂) : a :: l ~ l₁ ++ a :: l₂ := (p.cons a).trans perm_middle.symm @[simp] theorem perm_replicate {n : Nat} {a : α} {l : List α} : l ~ replicate n a ↔ l = replicate n a := by refine ⟨fun p => eq_replicate.2 ?_, fun h => h ▸ .rfl⟩ exact ⟨p.length_eq.trans <| length_replicate .., fun _b m => eq_of_mem_replicate <| p.subset m⟩ @[simp] theorem replicate_perm {n : Nat} {a : α} {l : List α} : replicate n a ~ l ↔ replicate n a = l := (perm_comm.trans perm_replicate).trans eq_comm @[simp] theorem perm_singleton {a : α} {l : List α} : l ~ [a] ↔ l = [a] := perm_replicate (n := 1) @[simp] theorem singleton_perm {a : α} {l : List α} : [a] ~ l ↔ [a] = l := replicate_perm (n := 1) alias ⟨Perm.eq_singleton,_⟩ := perm_singleton alias ⟨Perm.singleton_eq,_⟩ := singleton_perm theorem singleton_perm_singleton {a b : α} : [a] ~ [b] ↔ a = b := by simp theorem perm_cons_erase [DecidableEq α] {a : α} {l : List α} (h : a ∈ l) : l ~ a :: l.erase a := let ⟨_l₁, _l₂, _, e₁, e₂⟩ := exists_erase_eq h e₂ ▸ e₁ ▸ perm_middle theorem Perm.filterMap (f : α → Option β) {l₁ l₂ : List α} (p : l₁ ~ l₂) : filterMap f l₁ ~ filterMap f l₂ := by induction p with | nil => simp | cons x _p IH => cases h : f x <;> simp [h, filterMap, IH, Perm.cons] | swap x y l₂ => cases hx : f x <;> cases hy : f y <;> simp [hx, hy, filterMap, swap] | trans _p₁ _p₂ IH₁ IH₂ => exact IH₁.trans IH₂ theorem Perm.map (f : α → β) {l₁ l₂ : List α} (p : l₁ ~ l₂) : map f l₁ ~ map f l₂ := filterMap_eq_map f ▸ p.filterMap _ theorem Perm.pmap {p : α → Prop} (f : ∀ a, p a → β) {l₁ l₂ : List α} (p : l₁ ~ l₂) {H₁ H₂} : pmap f l₁ H₁ ~ pmap f l₂ H₂ := by induction p with | nil => simp | cons x _p IH => simp [IH, Perm.cons] | swap x y => simp [swap] | trans _p₁ p₂ IH₁ IH₂ => exact IH₁.trans (IH₂ (H₁ := fun a m => H₂ a (p₂.subset m))) theorem Perm.filter (p : α → Bool) {l₁ l₂ : List α} (s : l₁ ~ l₂) : filter p l₁ ~ filter p l₂ := by rw [← filterMap_eq_filter]; apply s.filterMap theorem filter_append_perm (p : α → Bool) (l : List α) : filter p l ++ filter (fun x => !p x) l ~ l := by induction l with | nil => rfl | cons x l ih => by_cases h : p x <;> simp [h] · exact ih.cons x · exact Perm.trans (perm_append_comm.trans (perm_append_comm.cons _)) (ih.cons x) theorem exists_perm_sublist {l₁ l₂ l₂' : List α} (s : l₁ <+ l₂) (p : l₂ ~ l₂') : ∃ l₁', l₁' ~ l₁ ∧ l₁' <+ l₂' := by induction p generalizing l₁ with | nil => exact ⟨[], sublist_nil.mp s ▸ .rfl, nil_sublist _⟩ | cons x _ IH => match s with | .cons _ s => let ⟨l₁', p', s'⟩ := IH s; exact ⟨l₁', p', s'.cons _⟩ | .cons₂ _ s => let ⟨l₁', p', s'⟩ := IH s; exact ⟨x :: l₁', p'.cons x, s'.cons₂ _⟩ | swap x y l' => match s with | .cons _ (.cons _ s) => exact ⟨_, .rfl, (s.cons _).cons _⟩ | .cons _ (.cons₂ _ s) => exact ⟨x :: _, .rfl, (s.cons _).cons₂ _⟩ | .cons₂ _ (.cons _ s) => exact ⟨y :: _, .rfl, (s.cons₂ _).cons _⟩ | .cons₂ _ (.cons₂ _ s) => exact ⟨x :: y :: _, .swap .., (s.cons₂ _).cons₂ _⟩ | trans _ _ IH₁ IH₂ => let ⟨m₁, pm, sm⟩ := IH₁ s let ⟨r₁, pr, sr⟩ := IH₂ sm exact ⟨r₁, pr.trans pm, sr⟩ theorem Perm.sizeOf_eq_sizeOf [SizeOf α] {l₁ l₂ : List α} (h : l₁ ~ l₂) : sizeOf l₁ = sizeOf l₂ := by induction h with | nil => rfl | cons _ _ h_sz₁₂ => simp [h_sz₁₂] | swap => simp [Nat.add_left_comm] | trans _ _ h_sz₁₂ h_sz₂₃ => simp [h_sz₁₂, h_sz₂₃] section Subperm theorem nil_subperm {l : List α} : [] <+~ l := ⟨[], Perm.nil, by simp⟩ theorem Perm.subperm_left {l l₁ l₂ : List α} (p : l₁ ~ l₂) : l <+~ l₁ ↔ l <+~ l₂ := suffices ∀ {l₁ l₂ : List α}, l₁ ~ l₂ → l <+~ l₁ → l <+~ l₂ from ⟨this p, this p.symm⟩ fun p ⟨_u, pu, su⟩ => let ⟨v, pv, sv⟩ := exists_perm_sublist su p ⟨v, pv.trans pu, sv⟩ theorem Perm.subperm_right {l₁ l₂ l : List α} (p : l₁ ~ l₂) : l₁ <+~ l ↔ l₂ <+~ l := ⟨fun ⟨u, pu, su⟩ => ⟨u, pu.trans p, su⟩, fun ⟨u, pu, su⟩ => ⟨u, pu.trans p.symm, su⟩⟩ theorem Sublist.subperm {l₁ l₂ : List α} (s : l₁ <+ l₂) : l₁ <+~ l₂ := ⟨l₁, .rfl, s⟩ theorem Perm.subperm {l₁ l₂ : List α} (p : l₁ ~ l₂) : l₁ <+~ l₂ := ⟨l₂, p.symm, Sublist.refl _⟩ @[refl] theorem Subperm.refl (l : List α) : l <+~ l := Perm.rfl.subperm theorem Subperm.trans {l₁ l₂ l₃ : List α} (s₁₂ : l₁ <+~ l₂) (s₂₃ : l₂ <+~ l₃) : l₁ <+~ l₃ := let ⟨_l₂', p₂, s₂⟩ := s₂₃ let ⟨l₁', p₁, s₁⟩ := p₂.subperm_left.2 s₁₂ ⟨l₁', p₁, s₁.trans s₂⟩ theorem Subperm.cons_right {α : Type _} {l l' : List α} (x : α) (h : l <+~ l') : l <+~ x :: l' := h.trans (sublist_cons x l').subperm theorem Subperm.length_le {l₁ l₂ : List α} : l₁ <+~ l₂ → length l₁ ≤ length l₂ | ⟨_l, p, s⟩ => p.length_eq ▸ s.length_le theorem Subperm.perm_of_length_le {l₁ l₂ : List α} : l₁ <+~ l₂ → length l₂ ≤ length l₁ → l₁ ~ l₂ | ⟨_l, p, s⟩, h => (s.eq_of_length_le <| p.symm.length_eq ▸ h) ▸ p.symm theorem Subperm.antisymm {l₁ l₂ : List α} (h₁ : l₁ <+~ l₂) (h₂ : l₂ <+~ l₁) : l₁ ~ l₂ := h₁.perm_of_length_le h₂.length_le theorem Subperm.subset {l₁ l₂ : List α} : l₁ <+~ l₂ → l₁ ⊆ l₂ | ⟨_l, p, s⟩ => Subset.trans p.symm.subset s.subset theorem Subperm.filter (p : α → Bool) ⦃l l' : List α⦄ (h : l <+~ l') : filter p l <+~ filter p l' := by let ⟨xs, hp, h⟩ := h exact ⟨_, hp.filter p, h.filter p⟩ @[simp] theorem singleton_subperm_iff {α} {l : List α} {a : α} : [a] <+~ l ↔ a ∈ l := by refine ⟨fun ⟨s, hla, h⟩ => ?_, fun h => ⟨[a], .rfl, singleton_sublist.mpr h⟩⟩ rwa [perm_singleton.mp hla, singleton_sublist] at h end Subperm theorem Sublist.exists_perm_append {l₁ l₂ : List α} : l₁ <+ l₂ → ∃ l, l₂ ~ l₁ ++ l | Sublist.slnil => ⟨nil, .rfl⟩ | Sublist.cons a s => let ⟨l, p⟩ := Sublist.exists_perm_append s ⟨a :: l, (p.cons a).trans perm_middle.symm⟩ | Sublist.cons₂ a s => let ⟨l, p⟩ := Sublist.exists_perm_append s ⟨l, p.cons a⟩ theorem Perm.countP_eq (p : α → Bool) {l₁ l₂ : List α} (s : l₁ ~ l₂) : countP p l₁ = countP p l₂ := by simp only [countP_eq_length_filter] exact (s.filter _).length_eq theorem Subperm.countP_le (p : α → Bool) {l₁ l₂ : List α} : l₁ <+~ l₂ → countP p l₁ ≤ countP p l₂ | ⟨_l, p', s⟩ => p'.countP_eq p ▸ s.countP_le p theorem Perm.countP_congr {l₁ l₂ : List α} (s : l₁ ~ l₂) {p p' : α → Bool} (hp : ∀ x ∈ l₁, p x = p' x) : l₁.countP p = l₂.countP p' := by rw [← s.countP_eq p'] clear s induction l₁ with | nil => rfl | cons y s hs => simp only [mem_cons, forall_eq_or_imp] at hp simp only [countP_cons, hs hp.2, hp.1] theorem countP_eq_countP_filter_add (l : List α) (p q : α → Bool) : l.countP p = (l.filter q).countP p + (l.filter fun a => !q a).countP p := countP_append .. ▸ Perm.countP_eq _ (filter_append_perm _ _).symm theorem Perm.count_eq [DecidableEq α] {l₁ l₂ : List α} (p : l₁ ~ l₂) (a) : count a l₁ = count a l₂ := p.countP_eq _ theorem Subperm.count_le [DecidableEq α] {l₁ l₂ : List α} (s : l₁ <+~ l₂) (a) : count a l₁ ≤ count a l₂ := s.countP_le _ theorem Perm.foldl_eq' {f : β → α → β} {l₁ l₂ : List α} (p : l₁ ~ l₂) (comm : ∀ x ∈ l₁, ∀ y ∈ l₁, ∀ (z), f (f z x) y = f (f z y) x) (init) : foldl f init l₁ = foldl f init l₂ := by induction p using recOnSwap' generalizing init with | nil => simp | cons x _p IH => simp only [foldl] apply IH; intros; apply comm <;> exact .tail _ ‹_› | swap' x y _p IH => simp only [foldl] rw [comm x (.tail _ <| .head _) y (.head _)] apply IH; intros; apply comm <;> exact .tail _ (.tail _ ‹_›) | trans p₁ _p₂ IH₁ IH₂ => refine (IH₁ comm init).trans (IH₂ ?_ _) intros; apply comm <;> apply p₁.symm.subset <;> assumption theorem Perm.rec_heq {β : List α → Sort _} {f : ∀ a l, β l → β (a :: l)} {b : β []} {l l' : List α} (hl : l ~ l') (f_congr : ∀ {a l l' b b'}, l ~ l' → HEq b b' → HEq (f a l b) (f a l' b')) (f_swap : ∀ {a a' l b}, HEq (f a (a' :: l) (f a' l b)) (f a' (a :: l) (f a l b))) : HEq (@List.rec α β b f l) (@List.rec α β b f l') := by induction hl with | nil => rfl | cons a h ih => exact f_congr h ih | swap a a' l => exact f_swap | trans _h₁ _h₂ ih₁ ih₂ => exact ih₁.trans ih₂ /-- Lemma used to destruct perms element by element. -/ theorem perm_inv_core {a : α} {l₁ l₂ r₁ r₂ : List α} : l₁ ++ a :: r₁ ~ l₂ ++ a :: r₂ → l₁ ++ r₁ ~ l₂ ++ r₂ := by -- Necessary generalization for `induction` suffices ∀ s₁ s₂ (_ : s₁ ~ s₂) {l₁ l₂ r₁ r₂}, l₁ ++ a :: r₁ = s₁ → l₂ ++ a :: r₂ = s₂ → l₁ ++ r₁ ~ l₂ ++ r₂ from (this _ _ · rfl rfl) intro s₁ s₂ p induction p using Perm.recOnSwap' with intro l₁ l₂ r₁ r₂ e₁ e₂ | nil => simp at e₁ | cons x p IH => cases l₁ <;> cases l₂ <;> dsimp at e₁ e₂ <;> injections <;> subst_vars · exact p · exact p.trans perm_middle · exact perm_middle.symm.trans p · exact (IH rfl rfl).cons _ | swap' x y p IH => obtain _ | ⟨y, _ | ⟨z, l₁⟩⟩ := l₁ <;> obtain _ | ⟨u, _ | ⟨v, l₂⟩⟩ := l₂ <;> dsimp at e₁ e₂ <;> injections <;> subst_vars <;> try exact p.cons _ · exact (p.trans perm_middle).cons u · exact ((p.trans perm_middle).cons _).trans (swap _ _ _) · exact (perm_middle.symm.trans p).cons y · exact (swap _ _ _).trans ((perm_middle.symm.trans p).cons u) · exact (IH rfl rfl).swap' _ _ | trans p₁ p₂ IH₁ IH₂ => subst e₁ e₂ obtain ⟨l₂, r₂, rfl⟩ := append_of_mem (a := a) (p₁.subset (by simp)) exact (IH₁ rfl rfl).trans (IH₂ rfl rfl) theorem Perm.cons_inv {a : α} {l₁ l₂ : List α} : a :: l₁ ~ a :: l₂ → l₁ ~ l₂ := perm_inv_core (l₁ := []) (l₂ := []) @[simp] theorem perm_cons (a : α) {l₁ l₂ : List α} : a :: l₁ ~ a :: l₂ ↔ l₁ ~ l₂ := ⟨.cons_inv, .cons a⟩ theorem perm_append_left_iff {l₁ l₂ : List α} : ∀ l, l ++ l₁ ~ l ++ l₂ ↔ l₁ ~ l₂ | [] => .rfl | a :: l => (perm_cons a).trans (perm_append_left_iff l) theorem perm_append_right_iff {l₁ l₂ : List α} (l) : l₁ ++ l ~ l₂ ++ l ↔ l₁ ~ l₂ := by refine ⟨fun p => ?_, .append_right _⟩ exact (perm_append_left_iff _).1 <| perm_append_comm.trans <| p.trans perm_append_comm theorem subperm_cons (a : α) {l₁ l₂ : List α} : a :: l₁ <+~ a :: l₂ ↔ l₁ <+~ l₂ := by refine ⟨fun ⟨l, p, s⟩ => ?_, fun ⟨l, p, s⟩ => ⟨a :: l, p.cons a, s.cons₂ _⟩⟩ match s with | .cons _ s' => exact (p.subperm_left.2 <| (sublist_cons _ _).subperm).trans s'.subperm | .cons₂ _ s' => exact ⟨_, p.cons_inv, s'⟩ /-- Weaker version of `Subperm.cons_left` -/ theorem cons_subperm_of_not_mem_of_mem {a : α} {l₁ l₂ : List α} (h₁ : a ∉ l₁) (h₂ : a ∈ l₂) (s : l₁ <+~ l₂) : a :: l₁ <+~ l₂ := by obtain ⟨l, p, s⟩ := s induction s generalizing l₁ with | slnil => cases h₂ | @cons r₁ _ b s' ih => simp at h₂ match h₂ with | .inl e => subst_vars; exact ⟨_ :: r₁, p.cons _, s'.cons₂ _⟩ | .inr m => let ⟨t, p', s'⟩ := ih h₁ m p; exact ⟨t, p', s'.cons _⟩ | @cons₂ _ r₂ b _ ih => have bm : b ∈ l₁ := p.subset <| mem_cons_self _ _ have am : a ∈ r₂ := by simp only [find?, mem_cons] at h₂ exact h₂.resolve_left fun e => h₁ <| e.symm ▸ bm obtain ⟨t₁, t₂, rfl⟩ := append_of_mem bm have st : t₁ ++ t₂ <+ t₁ ++ b :: t₂ := by simp obtain ⟨t, p', s'⟩ := ih (mt (st.subset ·) h₁) am (.cons_inv <| p.trans perm_middle) exact ⟨b :: t, (p'.cons b).trans <| (swap ..).trans (perm_middle.symm.cons a), s'.cons₂ _⟩ theorem subperm_append_left {l₁ l₂ : List α} : ∀ l, l ++ l₁ <+~ l ++ l₂ ↔ l₁ <+~ l₂ | [] => .rfl | a :: l => (subperm_cons a).trans (subperm_append_left l) theorem subperm_append_right {l₁ l₂ : List α} (l) : l₁ ++ l <+~ l₂ ++ l ↔ l₁ <+~ l₂ := (perm_append_comm.subperm_left.trans perm_append_comm.subperm_right).trans (subperm_append_left l) theorem Subperm.exists_of_length_lt {l₁ l₂ : List α} (s : l₁ <+~ l₂) (h : length l₁ < length l₂) : ∃ a, a :: l₁ <+~ l₂ := by obtain ⟨l, p, s⟩ := s suffices length l < length l₂ → ∃ a : α, a :: l <+~ l₂ from (this <| p.symm.length_eq ▸ h).imp fun a => (p.cons a).subperm_right.1 clear h p l₁ induction s with intro h | slnil => cases h | cons a s IH => match Nat.lt_or_eq_of_le (Nat.le_of_lt_succ h) with | .inl h => exact (IH h).imp fun a s => s.trans (sublist_cons _ _).subperm | .inr h => exact ⟨a, s.eq_of_length h ▸ .refl _⟩ | cons₂ b _ IH => exact (IH <| Nat.lt_of_succ_lt_succ h).imp fun a s => (swap ..).subperm_right.1 <| (subperm_cons _).2 s theorem subperm_of_subset (d : Nodup l₁) (H : l₁ ⊆ l₂) : l₁ <+~ l₂ := by induction d with | nil => exact ⟨nil, .nil, nil_sublist _⟩ | cons h _ IH => have ⟨H₁, H₂⟩ := forall_mem_cons.1 H exact cons_subperm_of_not_mem_of_mem (h _ · rfl) H₁ (IH H₂) theorem perm_ext_iff_of_nodup {l₁ l₂ : List α} (d₁ : Nodup l₁) (d₂ : Nodup l₂) : l₁ ~ l₂ ↔ ∀ a, a ∈ l₁ ↔ a ∈ l₂ := by refine ⟨fun p _ => p.mem_iff, fun H => ?_⟩ exact (subperm_of_subset d₁ fun a => (H a).1).antisymm <| subperm_of_subset d₂ fun a => (H a).2 theorem Nodup.perm_iff_eq_of_sublist {l₁ l₂ l : List α} (d : Nodup l) (s₁ : l₁ <+ l) (s₂ : l₂ <+ l) : l₁ ~ l₂ ↔ l₁ = l₂ := by refine ⟨fun h => ?_, fun h => by rw [h]⟩ induction s₂ generalizing l₁ with simp [Nodup] at d | slnil => exact h.eq_nil | cons a s₂ IH => match s₁ with | .cons _ s₁ => exact IH d.2 s₁ h | .cons₂ _ s₁ => have := Subperm.subset ⟨_, h.symm, s₂⟩ (.head _) exact (d.1 _ this rfl).elim | cons₂ a _ IH => match s₁ with | .cons _ s₁ => have := Subperm.subset ⟨_, h, s₁⟩ (.head _) exact (d.1 _ this rfl).elim | .cons₂ _ s₁ => rw [IH d.2 s₁ h.cons_inv] section DecidableEq variable [DecidableEq α] theorem Perm.erase (a : α) {l₁ l₂ : List α} (p : l₁ ~ l₂) : l₁.erase a ~ l₂.erase a := if h₁ : a ∈ l₁ then have h₂ : a ∈ l₂ := p.subset h₁ .cons_inv <| (perm_cons_erase h₁).symm.trans <| p.trans (perm_cons_erase h₂) else by have h₂ : a ∉ l₂ := mt p.mem_iff.2 h₁ rw [erase_of_not_mem h₁, erase_of_not_mem h₂]; exact p theorem subperm_cons_erase (a : α) (l : List α) : l <+~ a :: l.erase a := if h : a ∈ l then (perm_cons_erase h).subperm else (erase_of_not_mem h).symm ▸ (sublist_cons _ _).subperm theorem erase_subperm (a : α) (l : List α) : l.erase a <+~ l := (erase_sublist _ _).subperm theorem Subperm.erase {l₁ l₂ : List α} (a : α) (h : l₁ <+~ l₂) : l₁.erase a <+~ l₂.erase a := let ⟨l, hp, hs⟩ := h ⟨l.erase a, hp.erase _, hs.erase _⟩ theorem Perm.diff_right {l₁ l₂ : List α} (t : List α) (h : l₁ ~ l₂) : l₁.diff t ~ l₂.diff t := by induction t generalizing l₁ l₂ h with simp only [List.diff] | nil => exact h | cons x t ih => simp only [elem_eq_mem, decide_eq_true_eq, Perm.mem_iff h] split · exact ih (h.erase _) · exact ih h theorem Perm.diff_left (l : List α) {t₁ t₂ : List α} (h : t₁ ~ t₂) : l.diff t₁ = l.diff t₂ := by induction h generalizing l with try simp [List.diff] | cons x _ ih => apply ite_congr rfl <;> (intro; apply ih) | swap x y => if h : x = y then simp [h] else simp [mem_erase_of_ne h, mem_erase_of_ne (Ne.symm h), erase_comm x y] split <;> simp [h] | trans => simp only [*] theorem Perm.diff {l₁ l₂ t₁ t₂ : List α} (hl : l₁ ~ l₂) (ht : t₁ ~ t₂) : l₁.diff t₁ ~ l₂.diff t₂ := ht.diff_left l₂ ▸ hl.diff_right _ theorem Subperm.diff_right {l₁ l₂ : List α} (h : l₁ <+~ l₂) (t : List α) : l₁.diff t <+~ l₂.diff t := by induction t generalizing l₁ l₂ h with simp [List.diff, elem_eq_mem, *] | cons x t ih => split <;> rename_i hx1 · simp [h.subset hx1] exact ih (h.erase _) · split · rw [← erase_of_not_mem hx1] exact ih (h.erase _) · exact ih h theorem erase_cons_subperm_cons_erase (a b : α) (l : List α) : (a :: l).erase b <+~ a :: l.erase b := by if h : a = b then rw [h, erase_cons_head]; apply subperm_cons_erase else have : ¬(a == b) = true := by simp only [beq_false_of_ne h, not_false_eq_true] rw [erase_cons_tail _ this] theorem subperm_cons_diff {a : α} {l₁ l₂ : List α} : (a :: l₁).diff l₂ <+~ a :: l₁.diff l₂ := by induction l₂ with | nil => exact ⟨a :: l₁, by simp [List.diff]⟩ | cons b l₂ ih => rw [diff_cons, diff_cons, ← diff_erase, ← diff_erase] exact Subperm.trans (.erase _ ih) (erase_cons_subperm_cons_erase ..) theorem subset_cons_diff {a : α} {l₁ l₂ : List α} : (a :: l₁).diff l₂ ⊆ a :: l₁.diff l₂ := subperm_cons_diff.subset theorem cons_perm_iff_perm_erase {a : α} {l₁ l₂ : List α} : a :: l₁ ~ l₂ ↔ a ∈ l₂ ∧ l₁ ~ l₂.erase a := by refine ⟨fun h => ?_, fun ⟨m, h⟩ => (h.cons a).trans (perm_cons_erase m).symm⟩ have : a ∈ l₂ := h.subset (mem_cons_self a l₁) exact ⟨this, (h.trans <| perm_cons_erase this).cons_inv⟩ theorem perm_iff_count {l₁ l₂ : List α} : l₁ ~ l₂ ↔ ∀ a, count a l₁ = count a l₂ := by refine ⟨Perm.count_eq, fun H => ?_⟩ induction l₁ generalizing l₂ with | nil => match l₂ with | nil => rfl | cons b l₂ => specialize H b simp at H | cons a l₁ IH => have : a ∈ l₂ := count_pos_iff_mem.mp (by rw [← H]; simp) refine ((IH fun b => ?_).cons a).trans (perm_cons_erase this).symm specialize H b rw [(perm_cons_erase this).count_eq] at H by_cases h : b = a <;> simpa [h] using H /-- The list version of `add_tsub_cancel_of_le` for multisets. -/ theorem subperm_append_diff_self_of_count_le {l₁ l₂ : List α} (h : ∀ x ∈ l₁, count x l₁ ≤ count x l₂) : l₁ ++ l₂.diff l₁ ~ l₂ := by induction l₁ generalizing l₂ with | nil => simp | cons hd tl IH => have : hd ∈ l₂ := by rw [← count_pos_iff_mem] exact Nat.lt_of_lt_of_le (count_pos_iff_mem.mpr (.head _)) (h hd (.head _)) have := perm_cons_erase this refine Perm.trans ?_ this.symm rw [cons_append, diff_cons, perm_cons] refine IH fun x hx => ?_ specialize h x (.tail _ hx) rw [perm_iff_count.mp this] at h if hx : x = hd then subst hd; simpa [Nat.succ_le_succ_iff] using h else simpa [hx] using h /-- The list version of `Multiset.le_iff_count`. -/ theorem subperm_ext_iff {l₁ l₂ : List α} : l₁ <+~ l₂ ↔ ∀ x ∈ l₁, count x l₁ ≤ count x l₂ := by refine ⟨fun h x _ => h.count_le x, fun h => ?_⟩ have : l₁ <+~ l₂.diff l₁ ++ l₁ := (subperm_append_right l₁).mpr nil_subperm refine this.trans (Perm.subperm ?_) exact perm_append_comm.trans (subperm_append_diff_self_of_count_le h) theorem isSubperm_iff {l₁ l₂ : List α} : l₁.isSubperm l₂ ↔ l₁ <+~ l₂ := by simp [isSubperm, subperm_ext_iff] instance decidableSubperm : DecidableRel ((· <+~ ·) : List α → List α → Prop) := fun _ _ => decidable_of_iff _ isSubperm_iff theorem Subperm.cons_left {l₁ l₂ : List α} (h : l₁ <+~ l₂) (x : α) (hx : count x l₁ < count x l₂) : x :: l₁ <+~ l₂ := by rw [subperm_ext_iff] at h ⊢ intro y hy if hy' : y = x then subst x; simpa using Nat.succ_le_of_lt hx else rw [count_cons_of_ne hy'] refine h y ?_ simpa [hy'] using hy theorem isPerm_iff : ∀ {l₁ l₂ : List α}, l₁.isPerm l₂ ↔ l₁ ~ l₂ | [], [] => by simp [isPerm, isEmpty] | [], _ :: _ => by simp [isPerm, isEmpty, Perm.nil_eq] | a :: l₁, l₂ => by simp [isPerm, isPerm_iff, cons_perm_iff_perm_erase] instance decidablePerm (l₁ l₂ : List α) : Decidable (l₁ ~ l₂) := decidable_of_iff _ isPerm_iff protected theorem Perm.insert (a : α) {l₁ l₂ : List α} (p : l₁ ~ l₂) : l₁.insert a ~ l₂.insert a := by if h : a ∈ l₁ then simp [h, p.subset h, p] else have := p.cons a simpa [h, mt p.mem_iff.2 h] using this theorem perm_insert_swap (x y : α) (l : List α) : List.insert x (List.insert y l) ~ List.insert y (List.insert x l) := by by_cases xl : x ∈ l <;> by_cases yl : y ∈ l <;> simp [xl, yl] if xy : x = y then simp [xy] else simp [List.insert, xl, yl, xy, Ne.symm xy] constructor theorem perm_insertNth {α} (x : α) (l : List α) {n} (h : n ≤ l.length) : insertNth n x l ~ x :: l := by induction l generalizing n with | nil => cases n with | zero => rfl | succ => cases h | cons _ _ ih => cases n with | zero => simp [insertNth] | succ => simp only [insertNth, modifyNthTail] refine .trans (.cons _ (ih (Nat.le_of_succ_le_succ h))) (.swap ..) theorem Perm.union_right {l₁ l₂ : List α} (t₁ : List α) (h : l₁ ~ l₂) : l₁ ∪ t₁ ~ l₂ ∪ t₁ := by induction h with | nil => rfl | cons a _ ih => exact ih.insert a | swap => apply perm_insert_swap | trans _ _ ih_1 ih_2 => exact ih_1.trans ih_2 theorem Perm.union_left (l : List α) {t₁ t₂ : List α} (h : t₁ ~ t₂) : l ∪ t₁ ~ l ∪ t₂ := by induction l with | nil => simp only [nil_union, h] | cons _ _ ih => simp only [cons_union, Perm.insert _ ih] theorem Perm.union {l₁ l₂ t₁ t₂ : List α} (p₁ : l₁ ~ l₂) (p₂ : t₁ ~ t₂) : l₁ ∪ t₁ ~ l₂ ∪ t₂ := (p₁.union_right t₁).trans (p₂.union_left l₂) theorem Perm.inter_right {l₁ l₂ : List α} (t₁ : List α) : l₁ ~ l₂ → l₁ ∩ t₁ ~ l₂ ∩ t₁ := .filter _ theorem Perm.inter_left (l : List α) {t₁ t₂ : List α} (p : t₁ ~ t₂) : l ∩ t₁ = l ∩ t₂ := filter_congr' fun a _ => by simpa using p.mem_iff (a := a) theorem Perm.inter {l₁ l₂ t₁ t₂ : List α} (p₁ : l₁ ~ l₂) (p₂ : t₁ ~ t₂) : l₁ ∩ t₁ ~ l₂ ∩ t₂ := p₂.inter_left l₂ ▸ p₁.inter_right t₁ end DecidableEq theorem Perm.pairwise_iff {R : α → α → Prop} (S : ∀ {x y}, R x y → R y x) : ∀ {l₁ l₂ : List α} (_p : l₁ ~ l₂), Pairwise R l₁ ↔ Pairwise R l₂ := suffices ∀ {l₁ l₂}, l₁ ~ l₂ → Pairwise R l₁ → Pairwise R l₂ from fun p => ⟨this p, this p.symm⟩ fun {l₁ l₂} p d => by induction d generalizing l₂ with | nil => rw [← p.nil_eq]; constructor | cons h _ IH => have : _ ∈ l₂ := p.subset (mem_cons_self _ _) obtain ⟨s₂, t₂, rfl⟩ := append_of_mem this have p' := (p.trans perm_middle).cons_inv refine (pairwise_middle S).2 (pairwise_cons.2 ⟨fun b m => ?_, IH p'⟩) exact h _ (p'.symm.subset m) theorem Pairwise.perm {R : α → α → Prop} {l l' : List α} (hR : l.Pairwise R) (hl : l ~ l') (hsymm : ∀ {x y}, R x y → R y x) : l'.Pairwise R := (hl.pairwise_iff hsymm).mp hR theorem Perm.pairwise {R : α → α → Prop} {l l' : List α} (hl : l ~ l') (hR : l.Pairwise R) (hsymm : ∀ {x y}, R x y → R y x) : l'.Pairwise R := hR.perm hl hsymm theorem Perm.nodup_iff {l₁ l₂ : List α} : l₁ ~ l₂ → (Nodup l₁ ↔ Nodup l₂) := Perm.pairwise_iff <| @Ne.symm α theorem Perm.join {l₁ l₂ : List (List α)} (h : l₁ ~ l₂) : l₁.join ~ l₂.join := by induction h with | nil => rfl | cons _ _ ih => simp only [join_cons, perm_append_left_iff, ih] | swap => simp only [join_cons, ← append_assoc, perm_append_right_iff]; exact perm_append_comm .. | trans _ _ ih₁ ih₂ => exact trans ih₁ ih₂ theorem Perm.bind_right {l₁ l₂ : List α} (f : α → List β) (p : l₁ ~ l₂) : l₁.bind f ~ l₂.bind f := (p.map _).join theorem Perm.join_congr : ∀ {l₁ l₂ : List (List α)} (_ : List.Forall₂ (· ~ ·) l₁ l₂), l₁.join ~ l₂.join | _, _, .nil => .rfl | _ :: _, _ :: _, .cons h₁ h₂ => h₁.append (Perm.join_congr h₂)
.lake/packages/batteries/Batteries/Data/List/Perm.lean
691
704
theorem Perm.eraseP (f : α → Bool) {l₁ l₂ : List α} (H : Pairwise (fun a b => f a → f b → False) l₁) (p : l₁ ~ l₂) : eraseP f l₁ ~ eraseP f l₂ := by
induction p with | nil => simp | cons a p IH => if h : f a then simp [h, p] else simp [h]; exact IH (pairwise_cons.1 H).2 | swap a b l => by_cases h₁ : f a <;> by_cases h₂ : f b <;> simp [h₁, h₂] · cases (pairwise_cons.1 H).1 _ (mem_cons.2 (Or.inl rfl)) h₂ h₁ · apply swap | trans p₁ _ IH₁ IH₂ => refine (IH₁ H).trans (IH₂ ((p₁.pairwise_iff ?_).1 H)) exact fun h h₁ h₂ => h h₂ h₁
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.Polynomial.Expand import Mathlib.LinearAlgebra.FiniteDimensional import Mathlib.LinearAlgebra.Matrix.Charpoly.LinearMap import Mathlib.RingTheory.Adjoin.FG import Mathlib.RingTheory.FiniteType import Mathlib.RingTheory.Polynomial.ScaleRoots import Mathlib.RingTheory.Polynomial.Tower import Mathlib.RingTheory.TensorProduct.Basic #align_import ring_theory.integral_closure from "leanprover-community/mathlib"@"641b6a82006416ec431b2987b354af9311fed4f2" /-! # Integral closure of a subring. If A is an R-algebra then `a : A` is integral over R if it is a root of a monic polynomial with coefficients in R. Enough theory is developed to prove that integral elements form a sub-R-algebra of A. ## Main definitions Let `R` be a `CommRing` and let `A` be an R-algebra. * `RingHom.IsIntegralElem (f : R →+* A) (x : A)` : `x` is integral with respect to the map `f`, * `IsIntegral (x : A)` : `x` is integral over `R`, i.e., is a root of a monic polynomial with coefficients in `R`. * `integralClosure R A` : the integral closure of `R` in `A`, regarded as a sub-`R`-algebra of `A`. -/ open scoped Classical open Polynomial Submodule section Ring variable {R S A : Type*} variable [CommRing R] [Ring A] [Ring S] (f : R →+* S) /-- An element `x` of `A` is said to be integral over `R` with respect to `f` if it is a root of a monic polynomial `p : R[X]` evaluated under `f` -/ def RingHom.IsIntegralElem (f : R →+* A) (x : A) := ∃ p : R[X], Monic p ∧ eval₂ f x p = 0 #align ring_hom.is_integral_elem RingHom.IsIntegralElem /-- A ring homomorphism `f : R →+* A` is said to be integral if every element `A` is integral with respect to the map `f` -/ def RingHom.IsIntegral (f : R →+* A) := ∀ x : A, f.IsIntegralElem x #align ring_hom.is_integral RingHom.IsIntegral variable [Algebra R A] (R) /-- An element `x` of an algebra `A` over a commutative ring `R` is said to be *integral*, if it is a root of some monic polynomial `p : R[X]`. Equivalently, the element is integral over `R` with respect to the induced `algebraMap` -/ def IsIntegral (x : A) : Prop := (algebraMap R A).IsIntegralElem x #align is_integral IsIntegral variable (A) /-- An algebra is integral if every element of the extension is integral over the base ring -/ protected class Algebra.IsIntegral : Prop := isIntegral : ∀ x : A, IsIntegral R x #align algebra.is_integral Algebra.IsIntegral variable {R A} lemma Algebra.isIntegral_def : Algebra.IsIntegral R A ↔ ∀ x : A, IsIntegral R x := ⟨fun ⟨h⟩ ↦ h, fun h ↦ ⟨h⟩⟩ theorem RingHom.isIntegralElem_map {x : R} : f.IsIntegralElem (f x) := ⟨X - C x, monic_X_sub_C _, by simp⟩ #align ring_hom.is_integral_map RingHom.isIntegralElem_map theorem isIntegral_algebraMap {x : R} : IsIntegral R (algebraMap R A x) := (algebraMap R A).isIntegralElem_map #align is_integral_algebra_map isIntegral_algebraMap end Ring section variable {R A B S : Type*} variable [CommRing R] [CommRing A] [Ring B] [CommRing S] variable [Algebra R A] [Algebra R B] (f : R →+* S) theorem IsIntegral.map {B C F : Type*} [Ring B] [Ring C] [Algebra R B] [Algebra A B] [Algebra R C] [IsScalarTower R A B] [Algebra A C] [IsScalarTower R A C] {b : B} [FunLike F B C] [AlgHomClass F A B C] (f : F) (hb : IsIntegral R b) : IsIntegral R (f b) := by obtain ⟨P, hP⟩ := hb refine ⟨P, hP.1, ?_⟩ rw [← aeval_def, ← aeval_map_algebraMap A, aeval_algHom_apply, aeval_map_algebraMap, aeval_def, hP.2, _root_.map_zero] #align map_is_integral IsIntegral.map theorem IsIntegral.map_of_comp_eq {R S T U : Type*} [CommRing R] [Ring S] [CommRing T] [Ring U] [Algebra R S] [Algebra T U] (φ : R →+* T) (ψ : S →+* U) (h : (algebraMap T U).comp φ = ψ.comp (algebraMap R S)) {a : S} (ha : IsIntegral R a) : IsIntegral T (ψ a) := let ⟨p, hp⟩ := ha ⟨p.map φ, hp.1.map _, by rw [← eval_map, map_map, h, ← map_map, eval_map, eval₂_at_apply, eval_map, hp.2, ψ.map_zero]⟩ #align is_integral_map_of_comp_eq_of_is_integral IsIntegral.map_of_comp_eq section variable {A B : Type*} [Ring A] [Ring B] [Algebra R A] [Algebra R B] variable (f : A →ₐ[R] B) (hf : Function.Injective f) theorem isIntegral_algHom_iff {x : A} : IsIntegral R (f x) ↔ IsIntegral R x := by refine ⟨fun ⟨p, hp, hx⟩ ↦ ⟨p, hp, ?_⟩, IsIntegral.map f⟩ rwa [← f.comp_algebraMap, ← AlgHom.coe_toRingHom, ← hom_eval₂, AlgHom.coe_toRingHom, map_eq_zero_iff f hf] at hx #align is_integral_alg_hom_iff isIntegral_algHom_iff theorem Algebra.IsIntegral.of_injective [Algebra.IsIntegral R B] : Algebra.IsIntegral R A := ⟨fun _ ↦ (isIntegral_algHom_iff f hf).mp (isIntegral _)⟩ end @[simp] theorem isIntegral_algEquiv {A B : Type*} [Ring A] [Ring B] [Algebra R A] [Algebra R B] (f : A ≃ₐ[R] B) {x : A} : IsIntegral R (f x) ↔ IsIntegral R x := ⟨fun h ↦ by simpa using h.map f.symm, IsIntegral.map f⟩ #align is_integral_alg_equiv isIntegral_algEquiv /-- If `R → A → B` is an algebra tower, then if the entire tower is an integral extension so is `A → B`. -/ theorem IsIntegral.tower_top [Algebra A B] [IsScalarTower R A B] {x : B} (hx : IsIntegral R x) : IsIntegral A x := let ⟨p, hp, hpx⟩ := hx ⟨p.map <| algebraMap R A, hp.map _, by rw [← aeval_def, aeval_map_algebraMap, aeval_def, hpx]⟩ #align is_integral_of_is_scalar_tower IsIntegral.tower_top #align is_integral_tower_top_of_is_integral IsIntegral.tower_top theorem map_isIntegral_int {B C F : Type*} [Ring B] [Ring C] {b : B} [FunLike F B C] [RingHomClass F B C] (f : F) (hb : IsIntegral ℤ b) : IsIntegral ℤ (f b) := hb.map (f : B →+* C).toIntAlgHom #align map_is_integral_int map_isIntegral_int theorem IsIntegral.of_subring {x : B} (T : Subring R) (hx : IsIntegral T x) : IsIntegral R x := hx.tower_top #align is_integral_of_subring IsIntegral.of_subring protected theorem IsIntegral.algebraMap [Algebra A B] [IsScalarTower R A B] {x : A} (h : IsIntegral R x) : IsIntegral R (algebraMap A B x) := by rcases h with ⟨f, hf, hx⟩ use f, hf rw [IsScalarTower.algebraMap_eq R A B, ← hom_eval₂, hx, RingHom.map_zero] #align is_integral.algebra_map IsIntegral.algebraMap theorem isIntegral_algebraMap_iff [Algebra A B] [IsScalarTower R A B] {x : A} (hAB : Function.Injective (algebraMap A B)) : IsIntegral R (algebraMap A B x) ↔ IsIntegral R x := isIntegral_algHom_iff (IsScalarTower.toAlgHom R A B) hAB #align is_integral_algebra_map_iff isIntegral_algebraMap_iff theorem isIntegral_iff_isIntegral_closure_finite {r : B} : IsIntegral R r ↔ ∃ s : Set R, s.Finite ∧ IsIntegral (Subring.closure s) r := by constructor <;> intro hr · rcases hr with ⟨p, hmp, hpr⟩ refine ⟨_, Finset.finite_toSet _, p.restriction, monic_restriction.2 hmp, ?_⟩ rw [← aeval_def, ← aeval_map_algebraMap R r p.restriction, map_restriction, aeval_def, hpr] rcases hr with ⟨s, _, hsr⟩ exact hsr.of_subring _ #align is_integral_iff_is_integral_closure_finite isIntegral_iff_isIntegral_closure_finite theorem Submodule.span_range_natDegree_eq_adjoin {R A} [CommRing R] [Semiring A] [Algebra R A] {x : A} {f : R[X]} (hf : f.Monic) (hfx : aeval x f = 0) : span R (Finset.image (x ^ ·) (Finset.range (natDegree f))) = Subalgebra.toSubmodule (Algebra.adjoin R {x}) := by nontriviality A have hf1 : f ≠ 1 := by rintro rfl; simp [one_ne_zero' A] at hfx refine (span_le.mpr fun s hs ↦ ?_).antisymm fun r hr ↦ ?_ · rcases Finset.mem_image.1 hs with ⟨k, -, rfl⟩ exact (Algebra.adjoin R {x}).pow_mem (Algebra.subset_adjoin rfl) k rw [Subalgebra.mem_toSubmodule, Algebra.adjoin_singleton_eq_range_aeval] at hr rcases (aeval x).mem_range.mp hr with ⟨p, rfl⟩ rw [← modByMonic_add_div p hf, map_add, map_mul, hfx, zero_mul, add_zero, ← sum_C_mul_X_pow_eq (p %ₘ f), aeval_def, eval₂_sum, sum_def] refine sum_mem fun k hkq ↦ ?_ rw [C_mul_X_pow_eq_monomial, eval₂_monomial, ← Algebra.smul_def] exact smul_mem _ _ (subset_span <| Finset.mem_image_of_mem _ <| Finset.mem_range.mpr <| (le_natDegree_of_mem_supp _ hkq).trans_lt <| natDegree_modByMonic_lt p hf hf1) theorem IsIntegral.fg_adjoin_singleton {x : B} (hx : IsIntegral R x) : (Algebra.adjoin R {x}).toSubmodule.FG := by rcases hx with ⟨f, hfm, hfx⟩ use (Finset.range <| f.natDegree).image (x ^ ·) exact span_range_natDegree_eq_adjoin hfm (by rwa [aeval_def]) theorem fg_adjoin_of_finite {s : Set A} (hfs : s.Finite) (his : ∀ x ∈ s, IsIntegral R x) : (Algebra.adjoin R s).toSubmodule.FG := Set.Finite.induction_on hfs (fun _ => ⟨{1}, Submodule.ext fun x => by rw [Algebra.adjoin_empty, Finset.coe_singleton, ← one_eq_span, Algebra.toSubmodule_bot]⟩) (fun {a s} _ _ ih his => by rw [← Set.union_singleton, Algebra.adjoin_union_coe_submodule] exact FG.mul (ih fun i hi => his i <| Set.mem_insert_of_mem a hi) (his a <| Set.mem_insert a s).fg_adjoin_singleton) his #align fg_adjoin_of_finite fg_adjoin_of_finite theorem isNoetherian_adjoin_finset [IsNoetherianRing R] (s : Finset A) (hs : ∀ x ∈ s, IsIntegral R x) : IsNoetherian R (Algebra.adjoin R (s : Set A)) := isNoetherian_of_fg_of_noetherian _ (fg_adjoin_of_finite s.finite_toSet hs) #align is_noetherian_adjoin_finset isNoetherian_adjoin_finset instance Module.End.isIntegral {M : Type*} [AddCommGroup M] [Module R M] [Module.Finite R M] : Algebra.IsIntegral R (Module.End R M) := ⟨LinearMap.exists_monic_and_aeval_eq_zero R⟩ #align module.End.is_integral Module.End.isIntegral variable (R) theorem IsIntegral.of_finite [Module.Finite R B] (x : B) : IsIntegral R x := (isIntegral_algHom_iff (Algebra.lmul R B) Algebra.lmul_injective).mp (Algebra.IsIntegral.isIntegral _) variable (B) instance Algebra.IsIntegral.of_finite [Module.Finite R B] : Algebra.IsIntegral R B := ⟨.of_finite R⟩ #align algebra.is_integral.of_finite Algebra.IsIntegral.of_finite variable {R B} /-- If `S` is a sub-`R`-algebra of `A` and `S` is finitely-generated as an `R`-module, then all elements of `S` are integral over `R`. -/ theorem IsIntegral.of_mem_of_fg {A} [Ring A] [Algebra R A] (S : Subalgebra R A) (HS : S.toSubmodule.FG) (x : A) (hx : x ∈ S) : IsIntegral R x := have : Module.Finite R S := ⟨(fg_top _).mpr HS⟩ (isIntegral_algHom_iff S.val Subtype.val_injective).mpr (.of_finite R (⟨x, hx⟩ : S)) #align is_integral_of_mem_of_fg IsIntegral.of_mem_of_fg theorem isIntegral_of_noetherian (_ : IsNoetherian R B) (x : B) : IsIntegral R x := .of_finite R x #align is_integral_of_noetherian isIntegral_of_noetherian theorem isIntegral_of_submodule_noetherian (S : Subalgebra R B) (H : IsNoetherian R (Subalgebra.toSubmodule S)) (x : B) (hx : x ∈ S) : IsIntegral R x := .of_mem_of_fg _ ((fg_top _).mp <| H.noetherian _) _ hx #align is_integral_of_submodule_noetherian isIntegral_of_submodule_noetherian /-- Suppose `A` is an `R`-algebra, `M` is an `A`-module such that `a • m ≠ 0` for all non-zero `a` and `m`. If `x : A` fixes a nontrivial f.g. `R`-submodule `N` of `M`, then `x` is `R`-integral. -/ theorem isIntegral_of_smul_mem_submodule {M : Type*} [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors A M] (N : Submodule R M) (hN : N ≠ ⊥) (hN' : N.FG) (x : A) (hx : ∀ n ∈ N, x • n ∈ N) : IsIntegral R x := by let A' : Subalgebra R A := { carrier := { x | ∀ n ∈ N, x • n ∈ N } mul_mem' := fun {a b} ha hb n hn => smul_smul a b n ▸ ha _ (hb _ hn) one_mem' := fun n hn => (one_smul A n).symm ▸ hn add_mem' := fun {a b} ha hb n hn => (add_smul a b n).symm ▸ N.add_mem (ha _ hn) (hb _ hn) zero_mem' := fun n _hn => (zero_smul A n).symm ▸ N.zero_mem algebraMap_mem' := fun r n hn => (algebraMap_smul A r n).symm ▸ N.smul_mem r hn } let f : A' →ₐ[R] Module.End R N := AlgHom.ofLinearMap { toFun := fun x => (DistribMulAction.toLinearMap R M x).restrict x.prop -- Porting note: was -- `fun x y => LinearMap.ext fun n => Subtype.ext <| add_smul x y n` map_add' := by intros x y; ext; exact add_smul _ _ _ -- Porting note: was -- `fun r s => LinearMap.ext fun n => Subtype.ext <| smul_assoc r s n` map_smul' := by intros r s; ext; apply smul_assoc } -- Porting note: the next two lines were --`(LinearMap.ext fun n => Subtype.ext <| one_smul _ _) fun x y =>` --`LinearMap.ext fun n => Subtype.ext <| mul_smul x y n` (by ext; apply one_smul) (by intros x y; ext; apply mul_smul) obtain ⟨a, ha₁, ha₂⟩ : ∃ a ∈ N, a ≠ (0 : M) := by by_contra! h' apply hN rwa [eq_bot_iff] have : Function.Injective f := by show Function.Injective f.toLinearMap rw [← LinearMap.ker_eq_bot, eq_bot_iff] intro s hs have : s.1 • a = 0 := congr_arg Subtype.val (LinearMap.congr_fun hs ⟨a, ha₁⟩) exact Subtype.ext ((eq_zero_or_eq_zero_of_smul_eq_zero this).resolve_right ha₂) show IsIntegral R (A'.val ⟨x, hx⟩) rw [isIntegral_algHom_iff A'.val Subtype.val_injective, ← isIntegral_algHom_iff f this] haveI : Module.Finite R N := by rwa [Module.finite_def, Submodule.fg_top] apply Algebra.IsIntegral.isIntegral #align is_integral_of_smul_mem_submodule isIntegral_of_smul_mem_submodule variable {f} theorem RingHom.Finite.to_isIntegral (h : f.Finite) : f.IsIntegral := letI := f.toAlgebra fun _ ↦ IsIntegral.of_mem_of_fg ⊤ h.1 _ trivial #align ring_hom.finite.to_is_integral RingHom.Finite.to_isIntegral alias RingHom.IsIntegral.of_finite := RingHom.Finite.to_isIntegral #align ring_hom.is_integral.of_finite RingHom.IsIntegral.of_finite /-- The [Kurosh problem](https://en.wikipedia.org/wiki/Kurosh_problem) asks to show that this is still true when `A` is not necessarily commutative and `R` is a field, but it has been solved in the negative. See https://arxiv.org/pdf/1706.02383.pdf for criteria for a finitely generated algebraic (= integral) algebra over a field to be finite dimensional. This could be an `instance`, but we tend to go from `Module.Finite` to `IsIntegral`/`IsAlgebraic`, and making it an instance will cause the search to be complicated a lot. -/ theorem Algebra.IsIntegral.finite [Algebra.IsIntegral R A] [h' : Algebra.FiniteType R A] : Module.Finite R A := have ⟨s, hs⟩ := h' ⟨by apply hs ▸ fg_adjoin_of_finite s.finite_toSet fun x _ ↦ Algebra.IsIntegral.isIntegral x⟩ #align algebra.is_integral.finite Algebra.IsIntegral.finite /-- finite = integral + finite type -/ theorem Algebra.finite_iff_isIntegral_and_finiteType : Module.Finite R A ↔ Algebra.IsIntegral R A ∧ Algebra.FiniteType R A := ⟨fun _ ↦ ⟨⟨.of_finite R⟩, inferInstance⟩, fun ⟨h, _⟩ ↦ h.finite⟩ #align algebra.finite_iff_is_integral_and_finite_type Algebra.finite_iff_isIntegral_and_finiteType theorem RingHom.IsIntegral.to_finite (h : f.IsIntegral) (h' : f.FiniteType) : f.Finite := let _ := f.toAlgebra let _ : Algebra.IsIntegral R S := ⟨h⟩ Algebra.IsIntegral.finite (h' := h') #align ring_hom.is_integral.to_finite RingHom.IsIntegral.to_finite alias RingHom.Finite.of_isIntegral_of_finiteType := RingHom.IsIntegral.to_finite #align ring_hom.finite.of_is_integral_of_finite_type RingHom.Finite.of_isIntegral_of_finiteType /-- finite = integral + finite type -/ theorem RingHom.finite_iff_isIntegral_and_finiteType : f.Finite ↔ f.IsIntegral ∧ f.FiniteType := ⟨fun h ↦ ⟨h.to_isIntegral, h.to_finiteType⟩, fun ⟨h, h'⟩ ↦ h.to_finite h'⟩ #align ring_hom.finite_iff_is_integral_and_finite_type RingHom.finite_iff_isIntegral_and_finiteType variable (f) theorem RingHom.IsIntegralElem.of_mem_closure {x y z : S} (hx : f.IsIntegralElem x) (hy : f.IsIntegralElem y) (hz : z ∈ Subring.closure ({x, y} : Set S)) : f.IsIntegralElem z := by letI : Algebra R S := f.toAlgebra have := (IsIntegral.fg_adjoin_singleton hx).mul (IsIntegral.fg_adjoin_singleton hy) rw [← Algebra.adjoin_union_coe_submodule, Set.singleton_union] at this exact IsIntegral.of_mem_of_fg (Algebra.adjoin R {x, y}) this z (Algebra.mem_adjoin_iff.2 <| Subring.closure_mono Set.subset_union_right hz) #align ring_hom.is_integral_of_mem_closure RingHom.IsIntegralElem.of_mem_closure nonrec theorem IsIntegral.of_mem_closure {x y z : A} (hx : IsIntegral R x) (hy : IsIntegral R y) (hz : z ∈ Subring.closure ({x, y} : Set A)) : IsIntegral R z := hx.of_mem_closure (algebraMap R A) hy hz #align is_integral_of_mem_closure IsIntegral.of_mem_closure variable (f : R →+* B) theorem RingHom.isIntegralElem_zero : f.IsIntegralElem 0 := f.map_zero ▸ f.isIntegralElem_map #align ring_hom.is_integral_zero RingHom.isIntegralElem_zero theorem isIntegral_zero : IsIntegral R (0 : B) := (algebraMap R B).isIntegralElem_zero #align is_integral_zero isIntegral_zero theorem RingHom.isIntegralElem_one : f.IsIntegralElem 1 := f.map_one ▸ f.isIntegralElem_map #align ring_hom.is_integral_one RingHom.isIntegralElem_one theorem isIntegral_one : IsIntegral R (1 : B) := (algebraMap R B).isIntegralElem_one #align is_integral_one isIntegral_one theorem RingHom.IsIntegralElem.add (f : R →+* S) {x y : S} (hx : f.IsIntegralElem x) (hy : f.IsIntegralElem y) : f.IsIntegralElem (x + y) := hx.of_mem_closure f hy <| Subring.add_mem _ (Subring.subset_closure (Or.inl rfl)) (Subring.subset_closure (Or.inr rfl)) #align ring_hom.is_integral_add RingHom.IsIntegralElem.add nonrec theorem IsIntegral.add {x y : A} (hx : IsIntegral R x) (hy : IsIntegral R y) : IsIntegral R (x + y) := hx.add (algebraMap R A) hy #align is_integral_add IsIntegral.add variable (f : R →+* S) -- can be generalized to noncommutative S. theorem RingHom.IsIntegralElem.neg {x : S} (hx : f.IsIntegralElem x) : f.IsIntegralElem (-x) := hx.of_mem_closure f hx (Subring.neg_mem _ (Subring.subset_closure (Or.inl rfl))) #align ring_hom.is_integral_neg RingHom.IsIntegralElem.neg theorem IsIntegral.neg {x : B} (hx : IsIntegral R x) : IsIntegral R (-x) := .of_mem_of_fg _ hx.fg_adjoin_singleton _ (Subalgebra.neg_mem _ <| Algebra.subset_adjoin rfl) #align is_integral_neg IsIntegral.neg theorem RingHom.IsIntegralElem.sub {x y : S} (hx : f.IsIntegralElem x) (hy : f.IsIntegralElem y) : f.IsIntegralElem (x - y) := by simpa only [sub_eq_add_neg] using hx.add f (hy.neg f) #align ring_hom.is_integral_sub RingHom.IsIntegralElem.sub nonrec theorem IsIntegral.sub {x y : A} (hx : IsIntegral R x) (hy : IsIntegral R y) : IsIntegral R (x - y) := hx.sub (algebraMap R A) hy #align is_integral_sub IsIntegral.sub theorem RingHom.IsIntegralElem.mul {x y : S} (hx : f.IsIntegralElem x) (hy : f.IsIntegralElem y) : f.IsIntegralElem (x * y) := hx.of_mem_closure f hy (Subring.mul_mem _ (Subring.subset_closure (Or.inl rfl)) (Subring.subset_closure (Or.inr rfl))) #align ring_hom.is_integral_mul RingHom.IsIntegralElem.mul nonrec theorem IsIntegral.mul {x y : A} (hx : IsIntegral R x) (hy : IsIntegral R y) : IsIntegral R (x * y) := hx.mul (algebraMap R A) hy #align is_integral_mul IsIntegral.mul theorem IsIntegral.smul {R} [CommSemiring R] [CommRing S] [Algebra R B] [Algebra S B] [Algebra R S] [IsScalarTower R S B] {x : B} (r : R)(hx : IsIntegral S x) : IsIntegral S (r • x) := .of_mem_of_fg _ hx.fg_adjoin_singleton _ <| by rw [← algebraMap_smul S]; apply Subalgebra.smul_mem; exact Algebra.subset_adjoin rfl #align is_integral_smul IsIntegral.smul theorem IsIntegral.of_pow {x : B} {n : ℕ} (hn : 0 < n) (hx : IsIntegral R <| x ^ n) : IsIntegral R x := by rcases hx with ⟨p, hmonic, heval⟩ exact ⟨expand R n p, hmonic.expand hn, by rwa [← aeval_def, expand_aeval]⟩ #align is_integral_of_pow IsIntegral.of_pow variable (R A) /-- The integral closure of R in an R-algebra A. -/ def integralClosure : Subalgebra R A where carrier := { r | IsIntegral R r } zero_mem' := isIntegral_zero one_mem' := isIntegral_one add_mem' := IsIntegral.add mul_mem' := IsIntegral.mul algebraMap_mem' _ := isIntegral_algebraMap #align integral_closure integralClosure theorem mem_integralClosure_iff_mem_fg {r : A} : r ∈ integralClosure R A ↔ ∃ M : Subalgebra R A, M.toSubmodule.FG ∧ r ∈ M := ⟨fun hr => ⟨Algebra.adjoin R {r}, hr.fg_adjoin_singleton, Algebra.subset_adjoin rfl⟩, fun ⟨M, Hf, hrM⟩ => .of_mem_of_fg M Hf _ hrM⟩ #align mem_integral_closure_iff_mem_fg mem_integralClosure_iff_mem_fg variable {R A} theorem adjoin_le_integralClosure {x : A} (hx : IsIntegral R x) : Algebra.adjoin R {x} ≤ integralClosure R A := by rw [Algebra.adjoin_le_iff] simp only [SetLike.mem_coe, Set.singleton_subset_iff] exact hx #align adjoin_le_integral_closure adjoin_le_integralClosure theorem le_integralClosure_iff_isIntegral {S : Subalgebra R A} : S ≤ integralClosure R A ↔ Algebra.IsIntegral R S := SetLike.forall.symm.trans <| (forall_congr' fun x => show IsIntegral R (algebraMap S A x) ↔ IsIntegral R x from isIntegral_algebraMap_iff Subtype.coe_injective).trans Algebra.isIntegral_def.symm #align le_integral_closure_iff_is_integral le_integralClosure_iff_isIntegral
Mathlib/RingTheory/IntegralClosure.lean
468
471
theorem Algebra.isIntegral_sup {S T : Subalgebra R A} : Algebra.IsIntegral R (S ⊔ T : Subalgebra R A) ↔ Algebra.IsIntegral R S ∧ Algebra.IsIntegral R T := by
simp only [← le_integralClosure_iff_isIntegral, sup_le_iff]
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.BigOperators.Option import Mathlib.Analysis.BoxIntegral.Box.Basic import Mathlib.Data.Set.Pairwise.Lattice #align_import analysis.box_integral.partition.basic from "leanprover-community/mathlib"@"84dc0bd6619acaea625086d6f53cb35cdd554219" /-! # Partitions of rectangular boxes in `ℝⁿ` In this file we define (pre)partitions of rectangular boxes in `ℝⁿ`. A partition of a box `I` in `ℝⁿ` (see `BoxIntegral.Prepartition` and `BoxIntegral.Prepartition.IsPartition`) is a finite set of pairwise disjoint boxes such that their union is exactly `I`. We use `boxes : Finset (Box ι)` to store the set of boxes. Many lemmas about box integrals deal with pairwise disjoint collections of subboxes, so we define a structure `BoxIntegral.Prepartition (I : BoxIntegral.Box ι)` that stores a collection of boxes such that * each box `J ∈ boxes` is a subbox of `I`; * the boxes are pairwise disjoint as sets in `ℝⁿ`. Then we define a predicate `BoxIntegral.Prepartition.IsPartition`; `π.IsPartition` means that the boxes of `π` actually cover the whole `I`. We also define some operations on prepartitions: * `BoxIntegral.Prepartition.biUnion`: split each box of a partition into smaller boxes; * `BoxIntegral.Prepartition.restrict`: restrict a partition to a smaller box. We also define a `SemilatticeInf` structure on `BoxIntegral.Prepartition I` for all `I : BoxIntegral.Box ι`. ## Tags rectangular box, partition -/ open Set Finset Function open scoped Classical open NNReal noncomputable section namespace BoxIntegral variable {ι : Type*} /-- A prepartition of `I : BoxIntegral.Box ι` is a finite set of pairwise disjoint subboxes of `I`. -/ structure Prepartition (I : Box ι) where /-- The underlying set of boxes -/ boxes : Finset (Box ι) /-- Each box is a sub-box of `I` -/ le_of_mem' : ∀ J ∈ boxes, J ≤ I /-- The boxes in a prepartition are pairwise disjoint. -/ pairwiseDisjoint : Set.Pairwise (↑boxes) (Disjoint on ((↑) : Box ι → Set (ι → ℝ))) #align box_integral.prepartition BoxIntegral.Prepartition namespace Prepartition variable {I J J₁ J₂ : Box ι} (π : Prepartition I) {π₁ π₂ : Prepartition I} {x : ι → ℝ} instance : Membership (Box ι) (Prepartition I) := ⟨fun J π => J ∈ π.boxes⟩ @[simp] theorem mem_boxes : J ∈ π.boxes ↔ J ∈ π := Iff.rfl #align box_integral.prepartition.mem_boxes BoxIntegral.Prepartition.mem_boxes @[simp] theorem mem_mk {s h₁ h₂} : J ∈ (mk s h₁ h₂ : Prepartition I) ↔ J ∈ s := Iff.rfl #align box_integral.prepartition.mem_mk BoxIntegral.Prepartition.mem_mk theorem disjoint_coe_of_mem (h₁ : J₁ ∈ π) (h₂ : J₂ ∈ π) (h : J₁ ≠ J₂) : Disjoint (J₁ : Set (ι → ℝ)) J₂ := π.pairwiseDisjoint h₁ h₂ h #align box_integral.prepartition.disjoint_coe_of_mem BoxIntegral.Prepartition.disjoint_coe_of_mem theorem eq_of_mem_of_mem (h₁ : J₁ ∈ π) (h₂ : J₂ ∈ π) (hx₁ : x ∈ J₁) (hx₂ : x ∈ J₂) : J₁ = J₂ := by_contra fun H => (π.disjoint_coe_of_mem h₁ h₂ H).le_bot ⟨hx₁, hx₂⟩ #align box_integral.prepartition.eq_of_mem_of_mem BoxIntegral.Prepartition.eq_of_mem_of_mem theorem eq_of_le_of_le (h₁ : J₁ ∈ π) (h₂ : J₂ ∈ π) (hle₁ : J ≤ J₁) (hle₂ : J ≤ J₂) : J₁ = J₂ := π.eq_of_mem_of_mem h₁ h₂ (hle₁ J.upper_mem) (hle₂ J.upper_mem) #align box_integral.prepartition.eq_of_le_of_le BoxIntegral.Prepartition.eq_of_le_of_le theorem eq_of_le (h₁ : J₁ ∈ π) (h₂ : J₂ ∈ π) (hle : J₁ ≤ J₂) : J₁ = J₂ := π.eq_of_le_of_le h₁ h₂ le_rfl hle #align box_integral.prepartition.eq_of_le BoxIntegral.Prepartition.eq_of_le theorem le_of_mem (hJ : J ∈ π) : J ≤ I := π.le_of_mem' J hJ #align box_integral.prepartition.le_of_mem BoxIntegral.Prepartition.le_of_mem theorem lower_le_lower (hJ : J ∈ π) : I.lower ≤ J.lower := Box.antitone_lower (π.le_of_mem hJ) #align box_integral.prepartition.lower_le_lower BoxIntegral.Prepartition.lower_le_lower theorem upper_le_upper (hJ : J ∈ π) : J.upper ≤ I.upper := Box.monotone_upper (π.le_of_mem hJ) #align box_integral.prepartition.upper_le_upper BoxIntegral.Prepartition.upper_le_upper theorem injective_boxes : Function.Injective (boxes : Prepartition I → Finset (Box ι)) := by rintro ⟨s₁, h₁, h₁'⟩ ⟨s₂, h₂, h₂'⟩ (rfl : s₁ = s₂) rfl #align box_integral.prepartition.injective_boxes BoxIntegral.Prepartition.injective_boxes @[ext] theorem ext (h : ∀ J, J ∈ π₁ ↔ J ∈ π₂) : π₁ = π₂ := injective_boxes <| Finset.ext h #align box_integral.prepartition.ext BoxIntegral.Prepartition.ext /-- The singleton prepartition `{J}`, `J ≤ I`. -/ @[simps] def single (I J : Box ι) (h : J ≤ I) : Prepartition I := ⟨{J}, by simpa, by simp⟩ #align box_integral.prepartition.single BoxIntegral.Prepartition.single @[simp] theorem mem_single {J'} (h : J ≤ I) : J' ∈ single I J h ↔ J' = J := mem_singleton #align box_integral.prepartition.mem_single BoxIntegral.Prepartition.mem_single /-- We say that `π ≤ π'` if each box of `π` is a subbox of some box of `π'`. -/ instance : LE (Prepartition I) := ⟨fun π π' => ∀ ⦃I⦄, I ∈ π → ∃ I' ∈ π', I ≤ I'⟩ instance partialOrder : PartialOrder (Prepartition I) where le := (· ≤ ·) le_refl π I hI := ⟨I, hI, le_rfl⟩ le_trans π₁ π₂ π₃ h₁₂ h₂₃ I₁ hI₁ := let ⟨I₂, hI₂, hI₁₂⟩ := h₁₂ hI₁ let ⟨I₃, hI₃, hI₂₃⟩ := h₂₃ hI₂ ⟨I₃, hI₃, hI₁₂.trans hI₂₃⟩ le_antisymm := by suffices ∀ {π₁ π₂ : Prepartition I}, π₁ ≤ π₂ → π₂ ≤ π₁ → π₁.boxes ⊆ π₂.boxes from fun π₁ π₂ h₁ h₂ => injective_boxes (Subset.antisymm (this h₁ h₂) (this h₂ h₁)) intro π₁ π₂ h₁ h₂ J hJ rcases h₁ hJ with ⟨J', hJ', hle⟩; rcases h₂ hJ' with ⟨J'', hJ'', hle'⟩ obtain rfl : J = J'' := π₁.eq_of_le hJ hJ'' (hle.trans hle') obtain rfl : J' = J := le_antisymm ‹_› ‹_› assumption instance : OrderTop (Prepartition I) where top := single I I le_rfl le_top π J hJ := ⟨I, by simp, π.le_of_mem hJ⟩ instance : OrderBot (Prepartition I) where bot := ⟨∅, fun _ hJ => (Finset.not_mem_empty _ hJ).elim, fun _ hJ => (Set.not_mem_empty _ <| Finset.coe_empty ▸ hJ).elim⟩ bot_le _ _ hJ := (Finset.not_mem_empty _ hJ).elim instance : Inhabited (Prepartition I) := ⟨⊤⟩ theorem le_def : π₁ ≤ π₂ ↔ ∀ J ∈ π₁, ∃ J' ∈ π₂, J ≤ J' := Iff.rfl #align box_integral.prepartition.le_def BoxIntegral.Prepartition.le_def @[simp] theorem mem_top : J ∈ (⊤ : Prepartition I) ↔ J = I := mem_singleton #align box_integral.prepartition.mem_top BoxIntegral.Prepartition.mem_top @[simp] theorem top_boxes : (⊤ : Prepartition I).boxes = {I} := rfl #align box_integral.prepartition.top_boxes BoxIntegral.Prepartition.top_boxes @[simp] theorem not_mem_bot : J ∉ (⊥ : Prepartition I) := Finset.not_mem_empty _ #align box_integral.prepartition.not_mem_bot BoxIntegral.Prepartition.not_mem_bot @[simp] theorem bot_boxes : (⊥ : Prepartition I).boxes = ∅ := rfl #align box_integral.prepartition.bot_boxes BoxIntegral.Prepartition.bot_boxes /-- An auxiliary lemma used to prove that the same point can't belong to more than `2 ^ Fintype.card ι` closed boxes of a prepartition. -/ theorem injOn_setOf_mem_Icc_setOf_lower_eq (x : ι → ℝ) : InjOn (fun J : Box ι => { i | J.lower i = x i }) { J | J ∈ π ∧ x ∈ Box.Icc J } := by rintro J₁ ⟨h₁, hx₁⟩ J₂ ⟨h₂, hx₂⟩ (H : { i | J₁.lower i = x i } = { i | J₂.lower i = x i }) suffices ∀ i, (Ioc (J₁.lower i) (J₁.upper i) ∩ Ioc (J₂.lower i) (J₂.upper i)).Nonempty by choose y hy₁ hy₂ using this exact π.eq_of_mem_of_mem h₁ h₂ hy₁ hy₂ intro i simp only [Set.ext_iff, mem_setOf] at H rcases (hx₁.1 i).eq_or_lt with hi₁ | hi₁ · have hi₂ : J₂.lower i = x i := (H _).1 hi₁ have H₁ : x i < J₁.upper i := by simpa only [hi₁] using J₁.lower_lt_upper i have H₂ : x i < J₂.upper i := by simpa only [hi₂] using J₂.lower_lt_upper i rw [Ioc_inter_Ioc, hi₁, hi₂, sup_idem, Set.nonempty_Ioc] exact lt_min H₁ H₂ · have hi₂ : J₂.lower i < x i := (hx₂.1 i).lt_of_ne (mt (H _).2 hi₁.ne) exact ⟨x i, ⟨hi₁, hx₁.2 i⟩, ⟨hi₂, hx₂.2 i⟩⟩ #align box_integral.prepartition.inj_on_set_of_mem_Icc_set_of_lower_eq BoxIntegral.Prepartition.injOn_setOf_mem_Icc_setOf_lower_eq /-- The set of boxes of a prepartition that contain `x` in their closures has cardinality at most `2 ^ Fintype.card ι`. -/ theorem card_filter_mem_Icc_le [Fintype ι] (x : ι → ℝ) : (π.boxes.filter fun J : Box ι => x ∈ Box.Icc J).card ≤ 2 ^ Fintype.card ι := by rw [← Fintype.card_set] refine Finset.card_le_card_of_inj_on (fun J : Box ι => { i | J.lower i = x i }) (fun _ _ => Finset.mem_univ _) ?_ simpa only [Finset.mem_filter] using π.injOn_setOf_mem_Icc_setOf_lower_eq x #align box_integral.prepartition.card_filter_mem_Icc_le BoxIntegral.Prepartition.card_filter_mem_Icc_le /-- Given a prepartition `π : BoxIntegral.Prepartition I`, `π.iUnion` is the part of `I` covered by the boxes of `π`. -/ protected def iUnion : Set (ι → ℝ) := ⋃ J ∈ π, ↑J #align box_integral.prepartition.Union BoxIntegral.Prepartition.iUnion theorem iUnion_def : π.iUnion = ⋃ J ∈ π, ↑J := rfl #align box_integral.prepartition.Union_def BoxIntegral.Prepartition.iUnion_def theorem iUnion_def' : π.iUnion = ⋃ J ∈ π.boxes, ↑J := rfl #align box_integral.prepartition.Union_def' BoxIntegral.Prepartition.iUnion_def' -- Porting note: Previous proof was `:= Set.mem_iUnion₂` @[simp] theorem mem_iUnion : x ∈ π.iUnion ↔ ∃ J ∈ π, x ∈ J := by convert Set.mem_iUnion₂ rw [Box.mem_coe, exists_prop] #align box_integral.prepartition.mem_Union BoxIntegral.Prepartition.mem_iUnion @[simp] theorem iUnion_single (h : J ≤ I) : (single I J h).iUnion = J := by simp [iUnion_def] #align box_integral.prepartition.Union_single BoxIntegral.Prepartition.iUnion_single @[simp] theorem iUnion_top : (⊤ : Prepartition I).iUnion = I := by simp [Prepartition.iUnion] #align box_integral.prepartition.Union_top BoxIntegral.Prepartition.iUnion_top @[simp] theorem iUnion_eq_empty : π₁.iUnion = ∅ ↔ π₁ = ⊥ := by simp [← injective_boxes.eq_iff, Finset.ext_iff, Prepartition.iUnion, imp_false] #align box_integral.prepartition.Union_eq_empty BoxIntegral.Prepartition.iUnion_eq_empty @[simp] theorem iUnion_bot : (⊥ : Prepartition I).iUnion = ∅ := iUnion_eq_empty.2 rfl #align box_integral.prepartition.Union_bot BoxIntegral.Prepartition.iUnion_bot theorem subset_iUnion (h : J ∈ π) : ↑J ⊆ π.iUnion := subset_biUnion_of_mem h #align box_integral.prepartition.subset_Union BoxIntegral.Prepartition.subset_iUnion theorem iUnion_subset : π.iUnion ⊆ I := iUnion₂_subset π.le_of_mem' #align box_integral.prepartition.Union_subset BoxIntegral.Prepartition.iUnion_subset @[mono] theorem iUnion_mono (h : π₁ ≤ π₂) : π₁.iUnion ⊆ π₂.iUnion := fun _ hx => let ⟨_, hJ₁, hx⟩ := π₁.mem_iUnion.1 hx let ⟨J₂, hJ₂, hle⟩ := h hJ₁ π₂.mem_iUnion.2 ⟨J₂, hJ₂, hle hx⟩ #align box_integral.prepartition.Union_mono BoxIntegral.Prepartition.iUnion_mono theorem disjoint_boxes_of_disjoint_iUnion (h : Disjoint π₁.iUnion π₂.iUnion) : Disjoint π₁.boxes π₂.boxes := Finset.disjoint_left.2 fun J h₁ h₂ => Disjoint.le_bot (h.mono (π₁.subset_iUnion h₁) (π₂.subset_iUnion h₂)) ⟨J.upper_mem, J.upper_mem⟩ #align box_integral.prepartition.disjoint_boxes_of_disjoint_Union BoxIntegral.Prepartition.disjoint_boxes_of_disjoint_iUnion theorem le_iff_nonempty_imp_le_and_iUnion_subset : π₁ ≤ π₂ ↔ (∀ J ∈ π₁, ∀ J' ∈ π₂, (J ∩ J' : Set (ι → ℝ)).Nonempty → J ≤ J') ∧ π₁.iUnion ⊆ π₂.iUnion := by constructor · refine fun H => ⟨fun J hJ J' hJ' Hne => ?_, iUnion_mono H⟩ rcases H hJ with ⟨J'', hJ'', Hle⟩ rcases Hne with ⟨x, hx, hx'⟩ rwa [π₂.eq_of_mem_of_mem hJ' hJ'' hx' (Hle hx)] · rintro ⟨H, HU⟩ J hJ simp only [Set.subset_def, mem_iUnion] at HU rcases HU J.upper ⟨J, hJ, J.upper_mem⟩ with ⟨J₂, hJ₂, hx⟩ exact ⟨J₂, hJ₂, H _ hJ _ hJ₂ ⟨_, J.upper_mem, hx⟩⟩ #align box_integral.prepartition.le_iff_nonempty_imp_le_and_Union_subset BoxIntegral.Prepartition.le_iff_nonempty_imp_le_and_iUnion_subset theorem eq_of_boxes_subset_iUnion_superset (h₁ : π₁.boxes ⊆ π₂.boxes) (h₂ : π₂.iUnion ⊆ π₁.iUnion) : π₁ = π₂ := le_antisymm (fun J hJ => ⟨J, h₁ hJ, le_rfl⟩) <| le_iff_nonempty_imp_le_and_iUnion_subset.2 ⟨fun _ hJ₁ _ hJ₂ Hne => (π₂.eq_of_mem_of_mem hJ₁ (h₁ hJ₂) Hne.choose_spec.1 Hne.choose_spec.2).le, h₂⟩ #align box_integral.prepartition.eq_of_boxes_subset_Union_superset BoxIntegral.Prepartition.eq_of_boxes_subset_iUnion_superset /-- Given a prepartition `π` of a box `I` and a collection of prepartitions `πi J` of all boxes `J ∈ π`, returns the prepartition of `I` into the union of the boxes of all `πi J`. Though we only use the values of `πi` on the boxes of `π`, we require `πi` to be a globally defined function. -/ @[simps] def biUnion (πi : ∀ J : Box ι, Prepartition J) : Prepartition I where boxes := π.boxes.biUnion fun J => (πi J).boxes le_of_mem' J hJ := by simp only [Finset.mem_biUnion, exists_prop, mem_boxes] at hJ rcases hJ with ⟨J', hJ', hJ⟩ exact ((πi J').le_of_mem hJ).trans (π.le_of_mem hJ') pairwiseDisjoint := by simp only [Set.Pairwise, Finset.mem_coe, Finset.mem_biUnion] rintro J₁' ⟨J₁, hJ₁, hJ₁'⟩ J₂' ⟨J₂, hJ₂, hJ₂'⟩ Hne rw [Function.onFun, Set.disjoint_left] rintro x hx₁ hx₂; apply Hne obtain rfl : J₁ = J₂ := π.eq_of_mem_of_mem hJ₁ hJ₂ ((πi J₁).le_of_mem hJ₁' hx₁) ((πi J₂).le_of_mem hJ₂' hx₂) exact (πi J₁).eq_of_mem_of_mem hJ₁' hJ₂' hx₁ hx₂ #align box_integral.prepartition.bUnion BoxIntegral.Prepartition.biUnion variable {πi πi₁ πi₂ : ∀ J : Box ι, Prepartition J} @[simp] theorem mem_biUnion : J ∈ π.biUnion πi ↔ ∃ J' ∈ π, J ∈ πi J' := by simp [biUnion] #align box_integral.prepartition.mem_bUnion BoxIntegral.Prepartition.mem_biUnion theorem biUnion_le (πi : ∀ J, Prepartition J) : π.biUnion πi ≤ π := fun _ hJ => let ⟨J', hJ', hJ⟩ := π.mem_biUnion.1 hJ ⟨J', hJ', (πi J').le_of_mem hJ⟩ #align box_integral.prepartition.bUnion_le BoxIntegral.Prepartition.biUnion_le @[simp] theorem biUnion_top : (π.biUnion fun _ => ⊤) = π := by ext simp #align box_integral.prepartition.bUnion_top BoxIntegral.Prepartition.biUnion_top @[congr] theorem biUnion_congr (h : π₁ = π₂) (hi : ∀ J ∈ π₁, πi₁ J = πi₂ J) : π₁.biUnion πi₁ = π₂.biUnion πi₂ := by subst π₂ ext J simp only [mem_biUnion] constructor <;> exact fun ⟨J', h₁, h₂⟩ => ⟨J', h₁, hi J' h₁ ▸ h₂⟩ #align box_integral.prepartition.bUnion_congr BoxIntegral.Prepartition.biUnion_congr theorem biUnion_congr_of_le (h : π₁ = π₂) (hi : ∀ J ≤ I, πi₁ J = πi₂ J) : π₁.biUnion πi₁ = π₂.biUnion πi₂ := biUnion_congr h fun J hJ => hi J (π₁.le_of_mem hJ) #align box_integral.prepartition.bUnion_congr_of_le BoxIntegral.Prepartition.biUnion_congr_of_le @[simp] theorem iUnion_biUnion (πi : ∀ J : Box ι, Prepartition J) : (π.biUnion πi).iUnion = ⋃ J ∈ π, (πi J).iUnion := by simp [Prepartition.iUnion] #align box_integral.prepartition.Union_bUnion BoxIntegral.Prepartition.iUnion_biUnion @[simp] theorem sum_biUnion_boxes {M : Type*} [AddCommMonoid M] (π : Prepartition I) (πi : ∀ J, Prepartition J) (f : Box ι → M) : (∑ J ∈ π.boxes.biUnion fun J => (πi J).boxes, f J) = ∑ J ∈ π.boxes, ∑ J' ∈ (πi J).boxes, f J' := by refine Finset.sum_biUnion fun J₁ h₁ J₂ h₂ hne => Finset.disjoint_left.2 fun J' h₁' h₂' => ?_ exact hne (π.eq_of_le_of_le h₁ h₂ ((πi J₁).le_of_mem h₁') ((πi J₂).le_of_mem h₂')) #align box_integral.prepartition.sum_bUnion_boxes BoxIntegral.Prepartition.sum_biUnion_boxes /-- Given a box `J ∈ π.biUnion πi`, returns the box `J' ∈ π` such that `J ∈ πi J'`. For `J ∉ π.biUnion πi`, returns `I`. -/ def biUnionIndex (πi : ∀ (J : Box ι), Prepartition J) (J : Box ι) : Box ι := if hJ : J ∈ π.biUnion πi then (π.mem_biUnion.1 hJ).choose else I #align box_integral.prepartition.bUnion_index BoxIntegral.Prepartition.biUnionIndex theorem biUnionIndex_mem (hJ : J ∈ π.biUnion πi) : π.biUnionIndex πi J ∈ π := by rw [biUnionIndex, dif_pos hJ] exact (π.mem_biUnion.1 hJ).choose_spec.1 #align box_integral.prepartition.bUnion_index_mem BoxIntegral.Prepartition.biUnionIndex_mem theorem biUnionIndex_le (πi : ∀ J, Prepartition J) (J : Box ι) : π.biUnionIndex πi J ≤ I := by by_cases hJ : J ∈ π.biUnion πi · exact π.le_of_mem (π.biUnionIndex_mem hJ) · rw [biUnionIndex, dif_neg hJ] #align box_integral.prepartition.bUnion_index_le BoxIntegral.Prepartition.biUnionIndex_le theorem mem_biUnionIndex (hJ : J ∈ π.biUnion πi) : J ∈ πi (π.biUnionIndex πi J) := by convert (π.mem_biUnion.1 hJ).choose_spec.2 <;> exact dif_pos hJ #align box_integral.prepartition.mem_bUnion_index BoxIntegral.Prepartition.mem_biUnionIndex theorem le_biUnionIndex (hJ : J ∈ π.biUnion πi) : J ≤ π.biUnionIndex πi J := le_of_mem _ (π.mem_biUnionIndex hJ) #align box_integral.prepartition.le_bUnion_index BoxIntegral.Prepartition.le_biUnionIndex /-- Uniqueness property of `BoxIntegral.Prepartition.biUnionIndex`. -/ theorem biUnionIndex_of_mem (hJ : J ∈ π) {J'} (hJ' : J' ∈ πi J) : π.biUnionIndex πi J' = J := have : J' ∈ π.biUnion πi := π.mem_biUnion.2 ⟨J, hJ, hJ'⟩ π.eq_of_le_of_le (π.biUnionIndex_mem this) hJ (π.le_biUnionIndex this) (le_of_mem _ hJ') #align box_integral.prepartition.bUnion_index_of_mem BoxIntegral.Prepartition.biUnionIndex_of_mem theorem biUnion_assoc (πi : ∀ J, Prepartition J) (πi' : Box ι → ∀ J : Box ι, Prepartition J) : (π.biUnion fun J => (πi J).biUnion (πi' J)) = (π.biUnion πi).biUnion fun J => πi' (π.biUnionIndex πi J) J := by ext J simp only [mem_biUnion, exists_prop] constructor · rintro ⟨J₁, hJ₁, J₂, hJ₂, hJ⟩ refine ⟨J₂, ⟨J₁, hJ₁, hJ₂⟩, ?_⟩ rwa [π.biUnionIndex_of_mem hJ₁ hJ₂] · rintro ⟨J₁, ⟨J₂, hJ₂, hJ₁⟩, hJ⟩ refine ⟨J₂, hJ₂, J₁, hJ₁, ?_⟩ rwa [π.biUnionIndex_of_mem hJ₂ hJ₁] at hJ #align box_integral.prepartition.bUnion_assoc BoxIntegral.Prepartition.biUnion_assoc /-- Create a `BoxIntegral.Prepartition` from a collection of possibly empty boxes by filtering out the empty one if it exists. -/ def ofWithBot (boxes : Finset (WithBot (Box ι))) (le_of_mem : ∀ J ∈ boxes, (J : WithBot (Box ι)) ≤ I) (pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ι))) Disjoint) : Prepartition I where boxes := Finset.eraseNone boxes le_of_mem' J hJ := by rw [mem_eraseNone] at hJ simpa only [WithBot.some_eq_coe, WithBot.coe_le_coe] using le_of_mem _ hJ pairwiseDisjoint J₁ h₁ J₂ h₂ hne := by simp only [mem_coe, mem_eraseNone] at h₁ h₂ exact Box.disjoint_coe.1 (pairwise_disjoint h₁ h₂ (mt Option.some_inj.1 hne)) #align box_integral.prepartition.of_with_bot BoxIntegral.Prepartition.ofWithBot @[simp] theorem mem_ofWithBot {boxes : Finset (WithBot (Box ι))} {h₁ h₂} : J ∈ (ofWithBot boxes h₁ h₂ : Prepartition I) ↔ (J : WithBot (Box ι)) ∈ boxes := mem_eraseNone #align box_integral.prepartition.mem_of_with_bot BoxIntegral.Prepartition.mem_ofWithBot @[simp] theorem iUnion_ofWithBot (boxes : Finset (WithBot (Box ι))) (le_of_mem : ∀ J ∈ boxes, (J : WithBot (Box ι)) ≤ I) (pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ι))) Disjoint) : (ofWithBot boxes le_of_mem pairwise_disjoint).iUnion = ⋃ J ∈ boxes, ↑J := by suffices ⋃ (J : Box ι) (_ : ↑J ∈ boxes), ↑J = ⋃ J ∈ boxes, (J : Set (ι → ℝ)) by simpa [ofWithBot, Prepartition.iUnion] simp only [← Box.biUnion_coe_eq_coe, @iUnion_comm _ _ (Box ι), @iUnion_comm _ _ (@Eq _ _ _), iUnion_iUnion_eq_right] #align box_integral.prepartition.Union_of_with_bot BoxIntegral.Prepartition.iUnion_ofWithBot theorem ofWithBot_le {boxes : Finset (WithBot (Box ι))} {le_of_mem : ∀ J ∈ boxes, (J : WithBot (Box ι)) ≤ I} {pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ι))) Disjoint} (H : ∀ J ∈ boxes, J ≠ ⊥ → ∃ J' ∈ π, J ≤ ↑J') : ofWithBot boxes le_of_mem pairwise_disjoint ≤ π := by have : ∀ J : Box ι, ↑J ∈ boxes → ∃ J' ∈ π, J ≤ J' := fun J hJ => by simpa only [WithBot.coe_le_coe] using H J hJ WithBot.coe_ne_bot simpa [ofWithBot, le_def] #align box_integral.prepartition.of_with_bot_le BoxIntegral.Prepartition.ofWithBot_le theorem le_ofWithBot {boxes : Finset (WithBot (Box ι))} {le_of_mem : ∀ J ∈ boxes, (J : WithBot (Box ι)) ≤ I} {pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ι))) Disjoint} (H : ∀ J ∈ π, ∃ J' ∈ boxes, ↑J ≤ J') : π ≤ ofWithBot boxes le_of_mem pairwise_disjoint := by intro J hJ rcases H J hJ with ⟨J', J'mem, hle⟩ lift J' to Box ι using ne_bot_of_le_ne_bot WithBot.coe_ne_bot hle exact ⟨J', mem_ofWithBot.2 J'mem, WithBot.coe_le_coe.1 hle⟩ #align box_integral.prepartition.le_of_with_bot BoxIntegral.Prepartition.le_ofWithBot theorem ofWithBot_mono {boxes₁ : Finset (WithBot (Box ι))} {le_of_mem₁ : ∀ J ∈ boxes₁, (J : WithBot (Box ι)) ≤ I} {pairwise_disjoint₁ : Set.Pairwise (boxes₁ : Set (WithBot (Box ι))) Disjoint} {boxes₂ : Finset (WithBot (Box ι))} {le_of_mem₂ : ∀ J ∈ boxes₂, (J : WithBot (Box ι)) ≤ I} {pairwise_disjoint₂ : Set.Pairwise (boxes₂ : Set (WithBot (Box ι))) Disjoint} (H : ∀ J ∈ boxes₁, J ≠ ⊥ → ∃ J' ∈ boxes₂, J ≤ J') : ofWithBot boxes₁ le_of_mem₁ pairwise_disjoint₁ ≤ ofWithBot boxes₂ le_of_mem₂ pairwise_disjoint₂ := le_ofWithBot _ fun J hJ => H J (mem_ofWithBot.1 hJ) WithBot.coe_ne_bot #align box_integral.prepartition.of_with_bot_mono BoxIntegral.Prepartition.ofWithBot_mono theorem sum_ofWithBot {M : Type*} [AddCommMonoid M] (boxes : Finset (WithBot (Box ι))) (le_of_mem : ∀ J ∈ boxes, (J : WithBot (Box ι)) ≤ I) (pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ι))) Disjoint) (f : Box ι → M) : (∑ J ∈ (ofWithBot boxes le_of_mem pairwise_disjoint).boxes, f J) = ∑ J ∈ boxes, Option.elim' 0 f J := Finset.sum_eraseNone _ _ #align box_integral.prepartition.sum_of_with_bot BoxIntegral.Prepartition.sum_ofWithBot /-- Restrict a prepartition to a box. -/ def restrict (π : Prepartition I) (J : Box ι) : Prepartition J := ofWithBot (π.boxes.image fun J' : Box ι => J ⊓ J') (fun J' hJ' => by rcases Finset.mem_image.1 hJ' with ⟨J', -, rfl⟩ exact inf_le_left) (by simp only [Set.Pairwise, onFun, Finset.mem_coe, Finset.mem_image] rintro _ ⟨J₁, h₁, rfl⟩ _ ⟨J₂, h₂, rfl⟩ Hne have : J₁ ≠ J₂ := by rintro rfl exact Hne rfl exact ((Box.disjoint_coe.2 <| π.disjoint_coe_of_mem h₁ h₂ this).inf_left' _).inf_right' _) #align box_integral.prepartition.restrict BoxIntegral.Prepartition.restrict @[simp] theorem mem_restrict : J₁ ∈ π.restrict J ↔ ∃ J' ∈ π, (J₁ : WithBot (Box ι)) = ↑J ⊓ ↑J' := by simp [restrict, eq_comm] #align box_integral.prepartition.mem_restrict BoxIntegral.Prepartition.mem_restrict theorem mem_restrict' : J₁ ∈ π.restrict J ↔ ∃ J' ∈ π, (J₁ : Set (ι → ℝ)) = ↑J ∩ ↑J' := by simp only [mem_restrict, ← Box.withBotCoe_inj, Box.coe_inf, Box.coe_coe] #align box_integral.prepartition.mem_restrict' BoxIntegral.Prepartition.mem_restrict' @[mono] theorem restrict_mono {π₁ π₂ : Prepartition I} (Hle : π₁ ≤ π₂) : π₁.restrict J ≤ π₂.restrict J := by refine ofWithBot_mono fun J₁ hJ₁ hne => ?_ rw [Finset.mem_image] at hJ₁; rcases hJ₁ with ⟨J₁, hJ₁, rfl⟩ rcases Hle hJ₁ with ⟨J₂, hJ₂, hle⟩ exact ⟨_, Finset.mem_image_of_mem _ hJ₂, inf_le_inf_left _ <| WithBot.coe_le_coe.2 hle⟩ #align box_integral.prepartition.restrict_mono BoxIntegral.Prepartition.restrict_mono theorem monotone_restrict : Monotone fun π : Prepartition I => restrict π J := fun _ _ => restrict_mono #align box_integral.prepartition.monotone_restrict BoxIntegral.Prepartition.monotone_restrict /-- Restricting to a larger box does not change the set of boxes. We cannot claim equality of prepartitions because they have different types. -/ theorem restrict_boxes_of_le (π : Prepartition I) (h : I ≤ J) : (π.restrict J).boxes = π.boxes := by simp only [restrict, ofWithBot, eraseNone_eq_biUnion] refine Finset.image_biUnion.trans ?_ refine (Finset.biUnion_congr rfl ?_).trans Finset.biUnion_singleton_eq_self intro J' hJ' rw [inf_of_le_right, ← WithBot.some_eq_coe, Option.toFinset_some] exact WithBot.coe_le_coe.2 ((π.le_of_mem hJ').trans h) #align box_integral.prepartition.restrict_boxes_of_le BoxIntegral.Prepartition.restrict_boxes_of_le @[simp] theorem restrict_self : π.restrict I = π := injective_boxes <| restrict_boxes_of_le π le_rfl #align box_integral.prepartition.restrict_self BoxIntegral.Prepartition.restrict_self @[simp] theorem iUnion_restrict : (π.restrict J).iUnion = (J : Set (ι → ℝ)) ∩ (π.iUnion) := by simp [restrict, ← inter_iUnion, ← iUnion_def] #align box_integral.prepartition.Union_restrict BoxIntegral.Prepartition.iUnion_restrict @[simp] theorem restrict_biUnion (πi : ∀ J, Prepartition J) (hJ : J ∈ π) : (π.biUnion πi).restrict J = πi J := by refine (eq_of_boxes_subset_iUnion_superset (fun J₁ h₁ => ?_) ?_).symm · refine (mem_restrict _).2 ⟨J₁, π.mem_biUnion.2 ⟨J, hJ, h₁⟩, (inf_of_le_right ?_).symm⟩ exact WithBot.coe_le_coe.2 (le_of_mem _ h₁) · simp only [iUnion_restrict, iUnion_biUnion, Set.subset_def, Set.mem_inter_iff, Set.mem_iUnion] rintro x ⟨hxJ, J₁, h₁, hx⟩ obtain rfl : J = J₁ := π.eq_of_mem_of_mem hJ h₁ hxJ (iUnion_subset _ hx) exact hx #align box_integral.prepartition.restrict_bUnion BoxIntegral.Prepartition.restrict_biUnion
Mathlib/Analysis/BoxIntegral/Partition/Basic.lean
544
553
theorem biUnion_le_iff {πi : ∀ J, Prepartition J} {π' : Prepartition I} : π.biUnion πi ≤ π' ↔ ∀ J ∈ π, πi J ≤ π'.restrict J := by
constructor <;> intro H J hJ · rw [← π.restrict_biUnion πi hJ] exact restrict_mono H · rw [mem_biUnion] at hJ rcases hJ with ⟨J₁, h₁, hJ⟩ rcases H J₁ h₁ hJ with ⟨J₂, h₂, Hle⟩ rcases π'.mem_restrict.mp h₂ with ⟨J₃, h₃, H⟩ exact ⟨J₃, h₃, Hle.trans <| WithBot.coe_le_coe.1 <| H.trans_le inf_le_right⟩
/- Copyright (c) 2022 Pierre-Alexandre Bazin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Pierre-Alexandre Bazin -/ import Mathlib.Algebra.DirectSum.Module import Mathlib.Algebra.Module.BigOperators import Mathlib.LinearAlgebra.Isomorphisms import Mathlib.GroupTheory.Torsion import Mathlib.RingTheory.Coprime.Ideal import Mathlib.RingTheory.Finiteness import Mathlib.Data.Set.Lattice #align_import algebra.module.torsion from "leanprover-community/mathlib"@"cdc34484a07418af43daf8198beaf5c00324bca8" /-! # Torsion submodules ## Main definitions * `torsionOf R M x` : the torsion ideal of `x`, containing all `a` such that `a • x = 0`. * `Submodule.torsionBy R M a` : the `a`-torsion submodule, containing all elements `x` of `M` such that `a • x = 0`. * `Submodule.torsionBySet R M s` : the submodule containing all elements `x` of `M` such that `a • x = 0` for all `a` in `s`. * `Submodule.torsion' R M S` : the `S`-torsion submodule, containing all elements `x` of `M` such that `a • x = 0` for some `a` in `S`. * `Submodule.torsion R M` : the torsion submodule, containing all elements `x` of `M` such that `a • x = 0` for some non-zero-divisor `a` in `R`. * `Module.IsTorsionBy R M a` : the property that defines an `a`-torsion module. Similarly, `IsTorsionBySet`, `IsTorsion'` and `IsTorsion`. * `Module.IsTorsionBySet.module` : Creates an `R ⧸ I`-module from an `R`-module that `IsTorsionBySet R _ I`. ## Main statements * `quot_torsionOf_equiv_span_singleton` : isomorphism between the span of an element of `M` and the quotient by its torsion ideal. * `torsion' R M S` and `torsion R M` are submodules. * `torsionBySet_eq_torsionBySet_span` : torsion by a set is torsion by the ideal generated by it. * `Submodule.torsionBy_is_torsionBy` : the `a`-torsion submodule is an `a`-torsion module. Similar lemmas for `torsion'` and `torsion`. * `Submodule.torsionBy_isInternal` : a `∏ i, p i`-torsion module is the internal direct sum of its `p i`-torsion submodules when the `p i` are pairwise coprime. A more general version with coprime ideals is `Submodule.torsionBySet_is_internal`. * `Submodule.noZeroSMulDivisors_iff_torsion_bot` : a module over a domain has `NoZeroSMulDivisors` (that is, there is no non-zero `a`, `x` such that `a • x = 0`) iff its torsion submodule is trivial. * `Submodule.QuotientTorsion.torsion_eq_bot` : quotienting by the torsion submodule makes the torsion submodule of the new module trivial. If `R` is a domain, we can derive an instance `Submodule.QuotientTorsion.noZeroSMulDivisors : NoZeroSMulDivisors R (M ⧸ torsion R M)`. ## Notation * The notions are defined for a `CommSemiring R` and a `Module R M`. Some additional hypotheses on `R` and `M` are required by some lemmas. * The letters `a`, `b`, ... are used for scalars (in `R`), while `x`, `y`, ... are used for vectors (in `M`). ## Tags Torsion, submodule, module, quotient -/ namespace Ideal section TorsionOf variable (R M : Type*) [Semiring R] [AddCommMonoid M] [Module R M] /-- The torsion ideal of `x`, containing all `a` such that `a • x = 0`. -/ @[simps!] def torsionOf (x : M) : Ideal R := -- Porting note (#11036): broken dot notation on LinearMap.ker Lean4#1910 LinearMap.ker (LinearMap.toSpanSingleton R M x) #align ideal.torsion_of Ideal.torsionOf @[simp] theorem torsionOf_zero : torsionOf R M (0 : M) = ⊤ := by simp [torsionOf] #align ideal.torsion_of_zero Ideal.torsionOf_zero variable {R M} @[simp] theorem mem_torsionOf_iff (x : M) (a : R) : a ∈ torsionOf R M x ↔ a • x = 0 := Iff.rfl #align ideal.mem_torsion_of_iff Ideal.mem_torsionOf_iff variable (R) @[simp] theorem torsionOf_eq_top_iff (m : M) : torsionOf R M m = ⊤ ↔ m = 0 := by refine ⟨fun h => ?_, fun h => by simp [h]⟩ rw [← one_smul R m, ← mem_torsionOf_iff m (1 : R), h] exact Submodule.mem_top #align ideal.torsion_of_eq_top_iff Ideal.torsionOf_eq_top_iff @[simp] theorem torsionOf_eq_bot_iff_of_noZeroSMulDivisors [Nontrivial R] [NoZeroSMulDivisors R M] (m : M) : torsionOf R M m = ⊥ ↔ m ≠ 0 := by refine ⟨fun h contra => ?_, fun h => (Submodule.eq_bot_iff _).mpr fun r hr => ?_⟩ · rw [contra, torsionOf_zero] at h exact bot_ne_top.symm h · rw [mem_torsionOf_iff, smul_eq_zero] at hr tauto #align ideal.torsion_of_eq_bot_iff_of_no_zero_smul_divisors Ideal.torsionOf_eq_bot_iff_of_noZeroSMulDivisors /-- See also `CompleteLattice.Independent.linearIndependent` which provides the same conclusion but requires the stronger hypothesis `NoZeroSMulDivisors R M`. -/ theorem CompleteLattice.Independent.linear_independent' {ι R M : Type*} {v : ι → M} [Ring R] [AddCommGroup M] [Module R M] (hv : CompleteLattice.Independent fun i => R ∙ v i) (h_ne_zero : ∀ i, Ideal.torsionOf R M (v i) = ⊥) : LinearIndependent R v := by refine linearIndependent_iff_not_smul_mem_span.mpr fun i r hi => ?_ replace hv := CompleteLattice.independent_def.mp hv i simp only [iSup_subtype', ← Submodule.span_range_eq_iSup (ι := Subtype _), disjoint_iff] at hv have : r • v i ∈ (⊥ : Submodule R M) := by rw [← hv, Submodule.mem_inf] refine ⟨Submodule.mem_span_singleton.mpr ⟨r, rfl⟩, ?_⟩ convert hi ext simp rw [← Submodule.mem_bot R, ← h_ne_zero i] simpa using this #align ideal.complete_lattice.independent.linear_independent' Ideal.CompleteLattice.Independent.linear_independent' end TorsionOf section variable (R M : Type*) [Ring R] [AddCommGroup M] [Module R M] /-- The span of `x` in `M` is isomorphic to `R` quotiented by the torsion ideal of `x`. -/ noncomputable def quotTorsionOfEquivSpanSingleton (x : M) : (R ⧸ torsionOf R M x) ≃ₗ[R] R ∙ x := (LinearMap.toSpanSingleton R M x).quotKerEquivRange.trans <| LinearEquiv.ofEq _ _ (LinearMap.span_singleton_eq_range R M x).symm #align ideal.quot_torsion_of_equiv_span_singleton Ideal.quotTorsionOfEquivSpanSingleton variable {R M} @[simp] theorem quotTorsionOfEquivSpanSingleton_apply_mk (x : M) (a : R) : quotTorsionOfEquivSpanSingleton R M x (Submodule.Quotient.mk a) = a • ⟨x, Submodule.mem_span_singleton_self x⟩ := rfl #align ideal.quot_torsion_of_equiv_span_singleton_apply_mk Ideal.quotTorsionOfEquivSpanSingleton_apply_mk end end Ideal open nonZeroDivisors section Defs variable (R M : Type*) [CommSemiring R] [AddCommMonoid M] [Module R M] namespace Submodule /-- The `a`-torsion submodule for `a` in `R`, containing all elements `x` of `M` such that `a • x = 0`. -/ @[simps!] def torsionBy (a : R) : Submodule R M := -- Porting note (#11036): broken dot notation on LinearMap.ker Lean4#1910 LinearMap.ker (DistribMulAction.toLinearMap R M a) #align submodule.torsion_by Submodule.torsionBy /-- The submodule containing all elements `x` of `M` such that `a • x = 0` for all `a` in `s`. -/ @[simps!] def torsionBySet (s : Set R) : Submodule R M := sInf (torsionBy R M '' s) #align submodule.torsion_by_set Submodule.torsionBySet -- Porting note: torsion' had metavariables and factoring out this fixed it -- perhaps there is a better fix /-- The additive submonoid of all elements `x` of `M` such that `a • x = 0` for some `a` in `S`. -/ @[simps!] def torsion'AddSubMonoid (S : Type*) [CommMonoid S] [DistribMulAction S M] : AddSubmonoid M where carrier := { x | ∃ a : S, a • x = 0 } add_mem' := by intro x y ⟨a,hx⟩ ⟨b,hy⟩ use b * a rw [smul_add, mul_smul, mul_comm, mul_smul, hx, hy, smul_zero, smul_zero, add_zero] zero_mem' := ⟨1, smul_zero 1⟩ /-- The `S`-torsion submodule, containing all elements `x` of `M` such that `a • x = 0` for some `a` in `S`. -/ @[simps!] def torsion' (S : Type*) [CommMonoid S] [DistribMulAction S M] [SMulCommClass S R M] : Submodule R M := { torsion'AddSubMonoid M S with smul_mem' := fun a x ⟨b, h⟩ => ⟨b, by rw [smul_comm, h, smul_zero]⟩} #align submodule.torsion' Submodule.torsion' /-- The torsion submodule, containing all elements `x` of `M` such that `a • x = 0` for some non-zero-divisor `a` in `R`. -/ abbrev torsion := torsion' R M R⁰ #align submodule.torsion Submodule.torsion end Submodule namespace Module /-- An `a`-torsion module is a module where every element is `a`-torsion. -/ abbrev IsTorsionBy (a : R) := ∀ ⦃x : M⦄, a • x = 0 #align module.is_torsion_by Module.IsTorsionBy /-- A module where every element is `a`-torsion for all `a` in `s`. -/ abbrev IsTorsionBySet (s : Set R) := ∀ ⦃x : M⦄ ⦃a : s⦄, (a : R) • x = 0 #align module.is_torsion_by_set Module.IsTorsionBySet /-- An `S`-torsion module is a module where every element is `a`-torsion for some `a` in `S`. -/ abbrev IsTorsion' (S : Type*) [SMul S M] := ∀ ⦃x : M⦄, ∃ a : S, a • x = 0 #align module.is_torsion' Module.IsTorsion' /-- A torsion module is a module where every element is `a`-torsion for some non-zero-divisor `a`. -/ abbrev IsTorsion := ∀ ⦃x : M⦄, ∃ a : R⁰, a • x = 0 #align module.is_torsion Module.IsTorsion theorem isTorsionBySet_annihilator : IsTorsionBySet R M (Module.annihilator R M) := fun _ r ↦ Module.mem_annihilator.mp r.2 _ end Module end Defs lemma isSMulRegular_iff_torsionBy_eq_bot {R} (M : Type*) [CommRing R] [AddCommGroup M] [Module R M] (r : R) : IsSMulRegular M r ↔ Submodule.torsionBy R M r = ⊥ := Iff.symm (DistribMulAction.toLinearMap R M r).ker_eq_bot variable {R M : Type*} section variable [CommSemiring R] [AddCommMonoid M] [Module R M] (s : Set R) (a : R) namespace Submodule @[simp] theorem smul_torsionBy (x : torsionBy R M a) : a • x = 0 := Subtype.ext x.prop #align submodule.smul_torsion_by Submodule.smul_torsionBy @[simp] theorem smul_coe_torsionBy (x : torsionBy R M a) : a • (x : M) = 0 := x.prop #align submodule.smul_coe_torsion_by Submodule.smul_coe_torsionBy @[simp] theorem mem_torsionBy_iff (x : M) : x ∈ torsionBy R M a ↔ a • x = 0 := Iff.rfl #align submodule.mem_torsion_by_iff Submodule.mem_torsionBy_iff @[simp] theorem mem_torsionBySet_iff (x : M) : x ∈ torsionBySet R M s ↔ ∀ a : s, (a : R) • x = 0 := by refine ⟨fun h ⟨a, ha⟩ => mem_sInf.mp h _ (Set.mem_image_of_mem _ ha), fun h => mem_sInf.mpr ?_⟩ rintro _ ⟨a, ha, rfl⟩; exact h ⟨a, ha⟩ #align submodule.mem_torsion_by_set_iff Submodule.mem_torsionBySet_iff @[simp] theorem torsionBySet_singleton_eq : torsionBySet R M {a} = torsionBy R M a := by ext x simp only [mem_torsionBySet_iff, SetCoe.forall, Subtype.coe_mk, Set.mem_singleton_iff, forall_eq, mem_torsionBy_iff] #align submodule.torsion_by_singleton_eq Submodule.torsionBySet_singleton_eq theorem torsionBySet_le_torsionBySet_of_subset {s t : Set R} (st : s ⊆ t) : torsionBySet R M t ≤ torsionBySet R M s := sInf_le_sInf fun _ ⟨a, ha, h⟩ => ⟨a, st ha, h⟩ #align submodule.torsion_by_set_le_torsion_by_set_of_subset Submodule.torsionBySet_le_torsionBySet_of_subset /-- Torsion by a set is torsion by the ideal generated by it. -/ theorem torsionBySet_eq_torsionBySet_span : torsionBySet R M s = torsionBySet R M (Ideal.span s) := by refine le_antisymm (fun x hx => ?_) (torsionBySet_le_torsionBySet_of_subset subset_span) rw [mem_torsionBySet_iff] at hx ⊢ suffices Ideal.span s ≤ Ideal.torsionOf R M x by rintro ⟨a, ha⟩ exact this ha rw [Ideal.span_le] exact fun a ha => hx ⟨a, ha⟩ #align submodule.torsion_by_set_eq_torsion_by_span Submodule.torsionBySet_eq_torsionBySet_span theorem torsionBySet_span_singleton_eq : torsionBySet R M (R ∙ a) = torsionBy R M a := (torsionBySet_eq_torsionBySet_span _).symm.trans <| torsionBySet_singleton_eq _ #align submodule.torsion_by_span_singleton_eq Submodule.torsionBySet_span_singleton_eq theorem torsionBy_le_torsionBy_of_dvd (a b : R) (dvd : a ∣ b) : torsionBy R M a ≤ torsionBy R M b := by rw [← torsionBySet_span_singleton_eq, ← torsionBySet_singleton_eq] apply torsionBySet_le_torsionBySet_of_subset rintro c (rfl : c = b); exact Ideal.mem_span_singleton.mpr dvd #align submodule.torsion_by_le_torsion_by_of_dvd Submodule.torsionBy_le_torsionBy_of_dvd @[simp] theorem torsionBy_one : torsionBy R M 1 = ⊥ := eq_bot_iff.mpr fun _ h => by rw [mem_torsionBy_iff, one_smul] at h exact h #align submodule.torsion_by_one Submodule.torsionBy_one @[simp] theorem torsionBySet_univ : torsionBySet R M Set.univ = ⊥ := by rw [eq_bot_iff, ← torsionBy_one, ← torsionBySet_singleton_eq] exact torsionBySet_le_torsionBySet_of_subset fun _ _ => trivial #align submodule.torsion_by_univ Submodule.torsionBySet_univ end Submodule open Submodule namespace Module @[simp] theorem isTorsionBySet_singleton_iff : IsTorsionBySet R M {a} ↔ IsTorsionBy R M a := by refine ⟨fun h x => @h _ ⟨_, Set.mem_singleton _⟩, fun h x => ?_⟩ rintro ⟨b, rfl : b = a⟩; exact @h _ #align module.is_torsion_by_singleton_iff Module.isTorsionBySet_singleton_iff theorem isTorsionBySet_iff_torsionBySet_eq_top : IsTorsionBySet R M s ↔ Submodule.torsionBySet R M s = ⊤ := ⟨fun h => eq_top_iff.mpr fun _ _ => (mem_torsionBySet_iff _ _).mpr <| @h _, fun h x => by rw [← mem_torsionBySet_iff, h] trivial⟩ #align module.is_torsion_by_set_iff_torsion_by_set_eq_top Module.isTorsionBySet_iff_torsionBySet_eq_top /-- An `a`-torsion module is a module whose `a`-torsion submodule is the full space. -/ theorem isTorsionBy_iff_torsionBy_eq_top : IsTorsionBy R M a ↔ torsionBy R M a = ⊤ := by rw [← torsionBySet_singleton_eq, ← isTorsionBySet_singleton_iff, isTorsionBySet_iff_torsionBySet_eq_top] #align module.is_torsion_by_iff_torsion_by_eq_top Module.isTorsionBy_iff_torsionBy_eq_top theorem isTorsionBySet_iff_is_torsion_by_span : IsTorsionBySet R M s ↔ IsTorsionBySet R M (Ideal.span s) := by rw [isTorsionBySet_iff_torsionBySet_eq_top, isTorsionBySet_iff_torsionBySet_eq_top, torsionBySet_eq_torsionBySet_span] #align module.is_torsion_by_set_iff_is_torsion_by_span Module.isTorsionBySet_iff_is_torsion_by_span theorem isTorsionBySet_span_singleton_iff : IsTorsionBySet R M (R ∙ a) ↔ IsTorsionBy R M a := (isTorsionBySet_iff_is_torsion_by_span _).symm.trans <| isTorsionBySet_singleton_iff _ #align module.is_torsion_by_span_singleton_iff Module.isTorsionBySet_span_singleton_iff theorem isTorsionBySet_iff_subseteq_ker_lsmul : IsTorsionBySet R M s ↔ s ⊆ LinearMap.ker (LinearMap.lsmul R M) where mp h r hr := LinearMap.mem_ker.mpr <| LinearMap.ext fun x => @h x ⟨r, hr⟩ mpr | h, x, ⟨_, hr⟩ => DFunLike.congr_fun (LinearMap.mem_ker.mp (h hr)) x theorem isTorsionBy_iff_mem_ker_lsmul : IsTorsionBy R M a ↔ a ∈ LinearMap.ker (LinearMap.lsmul R M) := Iff.symm LinearMap.ext_iff end Module namespace Submodule open Module theorem torsionBySet_isTorsionBySet : IsTorsionBySet R (torsionBySet R M s) s := fun ⟨_, hx⟩ a => Subtype.ext <| (mem_torsionBySet_iff _ _).mp hx a #align submodule.torsion_by_set_is_torsion_by_set Submodule.torsionBySet_isTorsionBySet /-- The `a`-torsion submodule is an `a`-torsion module. -/ theorem torsionBy_isTorsionBy : IsTorsionBy R (torsionBy R M a) a := smul_torsionBy a #align submodule.torsion_by_is_torsion_by Submodule.torsionBy_isTorsionBy @[simp] theorem torsionBy_torsionBy_eq_top : torsionBy R (torsionBy R M a) a = ⊤ := (isTorsionBy_iff_torsionBy_eq_top a).mp <| torsionBy_isTorsionBy a #align submodule.torsion_by_torsion_by_eq_top Submodule.torsionBy_torsionBy_eq_top @[simp] theorem torsionBySet_torsionBySet_eq_top : torsionBySet R (torsionBySet R M s) s = ⊤ := (isTorsionBySet_iff_torsionBySet_eq_top s).mp <| torsionBySet_isTorsionBySet s #align submodule.torsion_by_set_torsion_by_set_eq_top Submodule.torsionBySet_torsionBySet_eq_top variable (R M) theorem torsion_gc : @GaloisConnection (Submodule R M) (Ideal R)ᵒᵈ _ _ annihilator fun I => torsionBySet R M ↑(OrderDual.ofDual I) := fun _ _ => ⟨fun h x hx => (mem_torsionBySet_iff _ _).mpr fun ⟨_, ha⟩ => mem_annihilator.mp (h ha) x hx, fun h a ha => mem_annihilator.mpr fun _ hx => (mem_torsionBySet_iff _ _).mp (h hx) ⟨a, ha⟩⟩ #align submodule.torsion_gc Submodule.torsion_gc variable {R M} section Coprime variable {ι : Type*} {p : ι → Ideal R} {S : Finset ι} variable (hp : (S : Set ι).Pairwise fun i j => p i ⊔ p j = ⊤) -- Porting note: mem_iSup_finset_iff_exists_sum now requires DecidableEq ι theorem iSup_torsionBySet_ideal_eq_torsionBySet_iInf : ⨆ i ∈ S, torsionBySet R M (p i) = torsionBySet R M ↑(⨅ i ∈ S, p i) := by rcases S.eq_empty_or_nonempty with h | h · simp only [h] -- Porting note: converts were not cooperating convert iSup_emptyset (f := fun i => torsionBySet R M (p i)) <;> simp apply le_antisymm · apply iSup_le _ intro i apply iSup_le _ intro is apply torsionBySet_le_torsionBySet_of_subset exact (iInf_le (fun i => ⨅ _ : i ∈ S, p i) i).trans (iInf_le _ is) · intro x hx rw [mem_iSup_finset_iff_exists_sum] obtain ⟨μ, hμ⟩ := (mem_iSup_finset_iff_exists_sum _ _).mp ((Ideal.eq_top_iff_one _).mp <| (Ideal.iSup_iInf_eq_top_iff_pairwise h _).mpr hp) refine ⟨fun i => ⟨(μ i : R) • x, ?_⟩, ?_⟩ · rw [mem_torsionBySet_iff] at hx ⊢ rintro ⟨a, ha⟩ rw [smul_smul] suffices a * μ i ∈ ⨅ i ∈ S, p i from hx ⟨_, this⟩ rw [mem_iInf] intro j rw [mem_iInf] intro hj by_cases ij : j = i · rw [ij] exact Ideal.mul_mem_right _ _ ha · have := coe_mem (μ i) simp only [mem_iInf] at this exact Ideal.mul_mem_left _ _ (this j hj ij) · rw [← Finset.sum_smul, hμ, one_smul] #align submodule.supr_torsion_by_ideal_eq_torsion_by_infi Submodule.iSup_torsionBySet_ideal_eq_torsionBySet_iInf -- Porting note: iSup_torsionBySet_ideal_eq_torsionBySet_iInf now requires DecidableEq ι theorem supIndep_torsionBySet_ideal : S.SupIndep fun i => torsionBySet R M <| p i := fun T hT i hi hiT => by rw [disjoint_iff, Finset.sup_eq_iSup, iSup_torsionBySet_ideal_eq_torsionBySet_iInf fun i hi j hj ij => hp (hT hi) (hT hj) ij] have := GaloisConnection.u_inf (b₁ := OrderDual.toDual (p i)) (b₂ := OrderDual.toDual (⨅ i ∈ T, p i)) (torsion_gc R M) dsimp at this ⊢ rw [← this, Ideal.sup_iInf_eq_top, top_coe, torsionBySet_univ] intro j hj; apply hp hi (hT hj); rintro rfl; exact hiT hj #align submodule.sup_indep_torsion_by_ideal Submodule.supIndep_torsionBySet_ideal variable {q : ι → R} (hq : (S : Set ι).Pairwise <| (IsCoprime on q)) theorem iSup_torsionBy_eq_torsionBy_prod : ⨆ i ∈ S, torsionBy R M (q i) = torsionBy R M (∏ i ∈ S, q i) := by rw [← torsionBySet_span_singleton_eq, Ideal.submodule_span_eq, ← Ideal.finset_inf_span_singleton _ _ hq, Finset.inf_eq_iInf, ← iSup_torsionBySet_ideal_eq_torsionBySet_iInf] · congr ext : 1 congr ext : 1 exact (torsionBySet_span_singleton_eq _).symm exact fun i hi j hj ij => (Ideal.sup_eq_top_iff_isCoprime _ _).mpr (hq hi hj ij) #align submodule.supr_torsion_by_eq_torsion_by_prod Submodule.iSup_torsionBy_eq_torsionBy_prod theorem supIndep_torsionBy : S.SupIndep fun i => torsionBy R M <| q i := by convert supIndep_torsionBySet_ideal (M := M) fun i hi j hj ij => (Ideal.sup_eq_top_iff_isCoprime (q i) _).mpr <| hq hi hj ij exact (torsionBySet_span_singleton_eq (R := R) (M := M) _).symm #align submodule.sup_indep_torsion_by Submodule.supIndep_torsionBy end Coprime end Submodule end section NeedsGroup variable [CommRing R] [AddCommGroup M] [Module R M] namespace Submodule variable {ι : Type*} [DecidableEq ι] {S : Finset ι} /-- If the `p i` are pairwise coprime, a `⨅ i, p i`-torsion module is the internal direct sum of its `p i`-torsion submodules. -/ theorem torsionBySet_isInternal {p : ι → Ideal R} (hp : (S : Set ι).Pairwise fun i j => p i ⊔ p j = ⊤) (hM : Module.IsTorsionBySet R M (⨅ i ∈ S, p i : Ideal R)) : DirectSum.IsInternal fun i : S => torsionBySet R M <| p i := DirectSum.isInternal_submodule_of_independent_of_iSup_eq_top (CompleteLattice.independent_iff_supIndep.mpr <| supIndep_torsionBySet_ideal hp) (by apply (iSup_subtype'' ↑S fun i => torsionBySet R M <| p i).trans -- Porting note: times out if we change apply below to <| apply (iSup_torsionBySet_ideal_eq_torsionBySet_iInf hp).trans <| (Module.isTorsionBySet_iff_torsionBySet_eq_top _).mp hM) #align submodule.torsion_by_set_is_internal Submodule.torsionBySet_isInternal /-- If the `q i` are pairwise coprime, a `∏ i, q i`-torsion module is the internal direct sum of its `q i`-torsion submodules. -/ theorem torsionBy_isInternal {q : ι → R} (hq : (S : Set ι).Pairwise <| (IsCoprime on q)) (hM : Module.IsTorsionBy R M <| ∏ i ∈ S, q i) : DirectSum.IsInternal fun i : S => torsionBy R M <| q i := by rw [← Module.isTorsionBySet_span_singleton_iff, Ideal.submodule_span_eq, ← Ideal.finset_inf_span_singleton _ _ hq, Finset.inf_eq_iInf] at hM convert torsionBySet_isInternal (fun i hi j hj ij => (Ideal.sup_eq_top_iff_isCoprime (q i) _).mpr <| hq hi hj ij) hM exact (torsionBySet_span_singleton_eq _ (R := R) (M := M)).symm #align submodule.torsion_by_is_internal Submodule.torsionBy_isInternal end Submodule namespace Module variable {I : Ideal R} {r : R} /-- can't be an instance because `hM` can't be inferred -/ def IsTorsionBySet.hasSMul (hM : IsTorsionBySet R M I) : SMul (R ⧸ I) M where smul b x := I.liftQ (LinearMap.lsmul R M) ((isTorsionBySet_iff_subseteq_ker_lsmul _).mp hM) b x #align module.is_torsion_by_set.has_smul Module.IsTorsionBySet.hasSMul /-- can't be an instance because `hM` can't be inferred -/ abbrev IsTorsionBy.hasSMul (hM : IsTorsionBy R M r) : SMul (R ⧸ Ideal.span {r}) M := ((isTorsionBySet_span_singleton_iff r).mpr hM).hasSMul @[simp] theorem IsTorsionBySet.mk_smul (hM : IsTorsionBySet R M I) (b : R) (x : M) : haveI := hM.hasSMul Ideal.Quotient.mk I b • x = b • x := rfl #align module.is_torsion_by_set.mk_smul Module.IsTorsionBySet.mk_smul @[simp] theorem IsTorsionBy.mk_smul (hM : IsTorsionBy R M r) (b : R) (x : M) : haveI := hM.hasSMul Ideal.Quotient.mk (Ideal.span {r}) b • x = b • x := rfl /-- An `(R ⧸ I)`-module is an `R`-module which `IsTorsionBySet R M I`. -/ def IsTorsionBySet.module (hM : IsTorsionBySet R M I) : Module (R ⧸ I) M := letI := hM.hasSMul; I.mkQ_surjective.moduleLeft _ (IsTorsionBySet.mk_smul hM) #align module.is_torsion_by_set.module Module.IsTorsionBySet.module instance IsTorsionBySet.isScalarTower (hM : IsTorsionBySet R M I) {S : Type*} [SMul S R] [SMul S M] [IsScalarTower S R M] [IsScalarTower S R R] : @IsScalarTower S (R ⧸ I) M _ (IsTorsionBySet.module hM).toSMul _ := -- Porting note: still needed to be fed the Module R / I M instance @IsScalarTower.mk S (R ⧸ I) M _ (IsTorsionBySet.module hM).toSMul _ (fun b d x => Quotient.inductionOn' d fun c => (smul_assoc b c x : _)) #align module.is_torsion_by_set.is_scalar_tower Module.IsTorsionBySet.isScalarTower /-- An `(R ⧸ Ideal.span {r})`-module is an `R`-module for which `IsTorsionBy R M r`. -/ abbrev IsTorsionBy.module (hM : IsTorsionBy R M r) : Module (R ⧸ Ideal.span {r}) M := ((isTorsionBySet_span_singleton_iff r).mpr hM).module /-- Any module is also a module over the quotient of the ring by the annihilator. Not an instance because it causes synthesis failures / timeouts. -/ def quotientAnnihilator : Module (R ⧸ Module.annihilator R M) M := (isTorsionBySet_annihilator R M).module theorem isTorsionBy_quotient_iff (N : Submodule R M) (r : R) : IsTorsionBy R (M⧸N) r ↔ ∀ x, r • x ∈ N := Iff.trans N.mkQ_surjective.forall <| forall_congr' fun _ => Submodule.Quotient.mk_eq_zero N theorem IsTorsionBy.quotient (N : Submodule R M) {r : R} (h : IsTorsionBy R M r) : IsTorsionBy R (M⧸N) r := (isTorsionBy_quotient_iff N r).mpr fun x => @h x ▸ N.zero_mem theorem isTorsionBySet_quotient_iff (N : Submodule R M) (s : Set R) : IsTorsionBySet R (M⧸N) s ↔ ∀ x, ∀ r ∈ s, r • x ∈ N := Iff.trans N.mkQ_surjective.forall <| forall_congr' fun _ => Iff.trans Subtype.forall <| forall₂_congr fun _ _ => Submodule.Quotient.mk_eq_zero N theorem IsTorsionBySet.quotient (N : Submodule R M) {s} (h : IsTorsionBySet R M s) : IsTorsionBySet R (M⧸N) s := (isTorsionBySet_quotient_iff N s).mpr fun x r h' => @h x ⟨r, h'⟩ ▸ N.zero_mem variable (M I) (s : Set R) (r : R) open Pointwise Submodule lemma isTorsionBySet_quotient_set_smul : IsTorsionBySet R (M⧸s • (⊤ : Submodule R M)) s := (isTorsionBySet_quotient_iff _ _).mpr fun _ _ h => mem_set_smul_of_mem_mem h mem_top lemma isTorsionBy_quotient_element_smul : IsTorsionBy R (M⧸r • (⊤ : Submodule R M)) r := (isTorsionBy_quotient_iff _ _).mpr (smul_mem_pointwise_smul · r ⊤ ⟨⟩) lemma isTorsionBySet_quotient_ideal_smul : IsTorsionBySet R (M⧸I • (⊤ : Submodule R M)) I := (isTorsionBySet_quotient_iff _ _).mpr fun _ _ h => smul_mem_smul h ⟨⟩ instance : Module (R ⧸ Ideal.span s) (M ⧸ s • (⊤ : Submodule R M)) := ((isTorsionBySet_iff_is_torsion_by_span s).mp (isTorsionBySet_quotient_set_smul M s)).module instance : Module (R ⧸ I) (M ⧸ I • (⊤ : Submodule R M)) := (isTorsionBySet_quotient_ideal_smul M I).module instance : Module (R ⧸ Ideal.span {r}) (M ⧸ r • (⊤ : Submodule R M)) := (isTorsionBy_quotient_element_smul M r).module lemma Quotient.mk_smul_mk (r : R) (m : M) : Ideal.Quotient.mk I r • Submodule.Quotient.mk (p := (I • ⊤ : Submodule R M)) m = Submodule.Quotient.mk (p := (I • ⊤ : Submodule R M)) (r • m) := rfl end Module namespace Submodule instance (I : Ideal R) : Module (R ⧸ I) (torsionBySet R M I) := -- Porting note: times out without the (R := R) Module.IsTorsionBySet.module <| torsionBySet_isTorsionBySet (R := R) I @[simp] theorem torsionBySet.mk_smul (I : Ideal R) (b : R) (x : torsionBySet R M I) : Ideal.Quotient.mk I b • x = b • x := rfl #align submodule.torsion_by_set.mk_smul Submodule.torsionBySet.mk_smul instance (I : Ideal R) {S : Type*} [SMul S R] [SMul S M] [IsScalarTower S R M] [IsScalarTower S R R] : IsScalarTower S (R ⧸ I) (torsionBySet R M I) := inferInstance /-- The `a`-torsion submodule as an `(R ⧸ R∙a)`-module. -/ instance instModuleQuotientTorsionBy (a : R) : Module (R ⧸ R ∙ a) (torsionBy R M a) := Module.IsTorsionBySet.module <| (Module.isTorsionBySet_span_singleton_iff a).mpr <| torsionBy_isTorsionBy a -- Porting note: added for torsionBy.mk_ideal_smul instance (a : R) : Module (R ⧸ Ideal.span {a}) (torsionBy R M a) := inferInstanceAs <| Module (R ⧸ R ∙ a) (torsionBy R M a) -- Porting note: added because torsionBy.mk_smul simplifies @[simp] theorem torsionBy.mk_ideal_smul (a b : R) (x : torsionBy R M a) : (Ideal.Quotient.mk (Ideal.span {a})) b • x = b • x := rfl theorem torsionBy.mk_smul (a b : R) (x : torsionBy R M a) : Ideal.Quotient.mk (R ∙ a) b • x = b • x := rfl #align submodule.torsion_by.mk_smul Submodule.torsionBy.mk_smul instance (a : R) {S : Type*} [SMul S R] [SMul S M] [IsScalarTower S R M] [IsScalarTower S R R] : IsScalarTower S (R ⧸ R ∙ a) (torsionBy R M a) := inferInstance /-- Given an `R`-module `M` and an element `a` in `R`, submodules of the `a`-torsion submodule of `M` do not depend on whether we take scalars to be `R` or `R ⧸ R ∙ a`. -/ def submodule_torsionBy_orderIso (a : R) : Submodule (R ⧸ R ∙ a) (torsionBy R M a) ≃o Submodule R (torsionBy R M a) := { restrictScalarsEmbedding R (R ⧸ R ∙ a) (torsionBy R M a) with invFun := fun p ↦ { carrier := p add_mem' := add_mem zero_mem' := p.zero_mem smul_mem' := by rintro ⟨b⟩; exact p.smul_mem b } left_inv := by intro; ext; simp [restrictScalarsEmbedding] right_inv := by intro; ext; simp [restrictScalarsEmbedding] } end Submodule end NeedsGroup namespace Submodule section Torsion' open Module variable [CommSemiring R] [AddCommMonoid M] [Module R M] variable (S : Type*) [CommMonoid S] [DistribMulAction S M] [SMulCommClass S R M] @[simp] theorem mem_torsion'_iff (x : M) : x ∈ torsion' R M S ↔ ∃ a : S, a • x = 0 := Iff.rfl #align submodule.mem_torsion'_iff Submodule.mem_torsion'_iff -- @[simp] Porting note (#10618): simp can prove this theorem mem_torsion_iff (x : M) : x ∈ torsion R M ↔ ∃ a : R⁰, a • x = 0 := Iff.rfl #align submodule.mem_torsion_iff Submodule.mem_torsion_iff @[simps] instance : SMul S (torsion' R M S) := ⟨fun s x => ⟨s • (x : M), by obtain ⟨x, a, h⟩ := x use a dsimp rw [smul_comm, h, smul_zero]⟩⟩ instance : DistribMulAction S (torsion' R M S) := Subtype.coe_injective.distribMulAction (torsion' R M S).subtype.toAddMonoidHom fun (_ : S) _ => rfl instance : SMulCommClass S R (torsion' R M S) := ⟨fun _ _ _ => Subtype.ext <| smul_comm _ _ _⟩ /-- An `S`-torsion module is a module whose `S`-torsion submodule is the full space. -/ theorem isTorsion'_iff_torsion'_eq_top : IsTorsion' M S ↔ torsion' R M S = ⊤ := ⟨fun h => eq_top_iff.mpr fun _ _ => @h _, fun h x => by rw [← @mem_torsion'_iff R, h] trivial⟩ #align submodule.is_torsion'_iff_torsion'_eq_top Submodule.isTorsion'_iff_torsion'_eq_top /-- The `S`-torsion submodule is an `S`-torsion module. -/ theorem torsion'_isTorsion' : IsTorsion' (torsion' R M S) S := fun ⟨_, ⟨a, h⟩⟩ => ⟨a, Subtype.ext h⟩ #align submodule.torsion'_is_torsion' Submodule.torsion'_isTorsion' @[simp] theorem torsion'_torsion'_eq_top : torsion' R (torsion' R M S) S = ⊤ := (isTorsion'_iff_torsion'_eq_top S).mp <| torsion'_isTorsion' S #align submodule.torsion'_torsion'_eq_top Submodule.torsion'_torsion'_eq_top /-- The torsion submodule of the torsion submodule (viewed as a module) is the full torsion module. -/ -- @[simp] Porting note (#10618): simp can prove this theorem torsion_torsion_eq_top : torsion R (torsion R M) = ⊤ := torsion'_torsion'_eq_top R⁰ #align submodule.torsion_torsion_eq_top Submodule.torsion_torsion_eq_top /-- The torsion submodule is always a torsion module. -/ theorem torsion_isTorsion : Module.IsTorsion R (torsion R M) := torsion'_isTorsion' R⁰ #align submodule.torsion_is_torsion Submodule.torsion_isTorsion end Torsion' section Torsion variable [CommSemiring R] [AddCommMonoid M] [Module R M] variable (R M) theorem _root_.Module.isTorsionBySet_annihilator_top : Module.IsTorsionBySet R M (⊤ : Submodule R M).annihilator := fun x ha => mem_annihilator.mp ha.prop x mem_top #align module.is_torsion_by_set_annihilator_top Module.isTorsionBySet_annihilator_top variable {R M} theorem _root_.Submodule.annihilator_top_inter_nonZeroDivisors [Module.Finite R M] (hM : Module.IsTorsion R M) : ((⊤ : Submodule R M).annihilator : Set R) ∩ R⁰ ≠ ∅ := by obtain ⟨S, hS⟩ := ‹Module.Finite R M›.out refine Set.Nonempty.ne_empty ⟨_, ?_, (∏ x ∈ S, (@hM x).choose : R⁰).prop⟩ rw [Submonoid.coe_finset_prod, SetLike.mem_coe, ← hS, mem_annihilator_span] intro n letI := Classical.decEq M rw [← Finset.prod_erase_mul _ _ n.prop, mul_smul, ← Submonoid.smul_def, (@hM n).choose_spec, smul_zero] #align submodule.annihilator_top_inter_non_zero_divisors Submodule.annihilator_top_inter_nonZeroDivisors variable [NoZeroDivisors R] [Nontrivial R] theorem coe_torsion_eq_annihilator_ne_bot : (torsion R M : Set M) = { x : M | (R ∙ x).annihilator ≠ ⊥ } := by ext x; simp_rw [Submodule.ne_bot_iff, mem_annihilator, mem_span_singleton] exact ⟨fun ⟨a, hax⟩ => ⟨a, fun _ ⟨b, hb⟩ => by rw [← hb, smul_comm, ← Submonoid.smul_def, hax, smul_zero], nonZeroDivisors.coe_ne_zero _⟩, fun ⟨a, hax, ha⟩ => ⟨⟨_, mem_nonZeroDivisors_of_ne_zero ha⟩, hax x ⟨1, one_smul _ _⟩⟩⟩ #align submodule.coe_torsion_eq_annihilator_ne_bot Submodule.coe_torsion_eq_annihilator_ne_bot /-- A module over a domain has `NoZeroSMulDivisors` iff its torsion submodule is trivial. -/
Mathlib/Algebra/Module/Torsion.lean
776
793
theorem noZeroSMulDivisors_iff_torsion_eq_bot : NoZeroSMulDivisors R M ↔ torsion R M = ⊥ := by
constructor <;> intro h · haveI : NoZeroSMulDivisors R M := h rw [eq_bot_iff] rintro x ⟨a, hax⟩ change (a : R) • x = 0 at hax cases' eq_zero_or_eq_zero_of_smul_eq_zero hax with h0 h0 · exfalso exact nonZeroDivisors.coe_ne_zero a h0 · exact h0 · exact { eq_zero_or_eq_zero_of_smul_eq_zero := fun {a} {x} hax => by by_cases ha : a = 0 · left exact ha · right rw [← mem_bot R, ← h] exact ⟨⟨a, mem_nonZeroDivisors_of_ne_zero ha⟩, hax⟩ }
/- Copyright (c) 2023 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.Integrals import Mathlib.MeasureTheory.Integral.PeakFunction #align_import analysis.special_functions.trigonometric.euler_sine_prod from "leanprover-community/mathlib"@"2c1d8ca2812b64f88992a5294ea3dba144755cd1" /-! # Euler's infinite product for the sine function This file proves the infinite product formula $$ \sin \pi z = \pi z \prod_{n = 1}^\infty \left(1 - \frac{z ^ 2}{n ^ 2}\right) $$ for any real or complex `z`. Our proof closely follows the article [Salwinski, *Euler's Sine Product Formula: An Elementary Proof*][salwinski2018]: the basic strategy is to prove a recurrence relation for the integrals `∫ x in 0..π/2, cos 2 z x * cos x ^ (2 * n)`, generalising the arguments used to prove Wallis' limit formula for `π`. -/ open scoped Real Topology open Real Set Filter intervalIntegral MeasureTheory.MeasureSpace namespace EulerSine section IntegralRecursion /-! ## Recursion formula for the integral of `cos (2 * z * x) * cos x ^ n` We evaluate the integral of `cos (2 * z * x) * cos x ^ n`, for any complex `z` and even integers `n`, via repeated integration by parts. -/ variable {z : ℂ} {n : ℕ} theorem antideriv_cos_comp_const_mul (hz : z ≠ 0) (x : ℝ) : HasDerivAt (fun y : ℝ => Complex.sin (2 * z * y) / (2 * z)) (Complex.cos (2 * z * x)) x := by have a : HasDerivAt (fun y : ℂ => y * (2 * z)) _ x := hasDerivAt_mul_const _ have b : HasDerivAt (fun y : ℂ => Complex.sin (y * (2 * z))) _ x := HasDerivAt.comp (x : ℂ) (Complex.hasDerivAt_sin (x * (2 * z))) a have c := b.comp_ofReal.div_const (2 * z) field_simp at c; simp only [fun y => mul_comm y (2 * z)] at c exact c #align euler_sine.antideriv_cos_comp_const_mul EulerSine.antideriv_cos_comp_const_mul theorem antideriv_sin_comp_const_mul (hz : z ≠ 0) (x : ℝ) : HasDerivAt (fun y : ℝ => -Complex.cos (2 * z * y) / (2 * z)) (Complex.sin (2 * z * x)) x := by have a : HasDerivAt (fun y : ℂ => y * (2 * z)) _ x := hasDerivAt_mul_const _ have b : HasDerivAt (fun y : ℂ => Complex.cos (y * (2 * z))) _ x := HasDerivAt.comp (x : ℂ) (Complex.hasDerivAt_cos (x * (2 * z))) a have c := (b.comp_ofReal.div_const (2 * z)).neg field_simp at c; simp only [fun y => mul_comm y (2 * z)] at c exact c #align euler_sine.antideriv_sin_comp_const_mul EulerSine.antideriv_sin_comp_const_mul
Mathlib/Analysis/SpecialFunctions/Trigonometric/EulerSineProd.lean
59
85
theorem integral_cos_mul_cos_pow_aux (hn : 2 ≤ n) (hz : z ≠ 0) : (∫ x in (0 : ℝ)..π / 2, Complex.cos (2 * z * x) * (cos x : ℂ) ^ n) = n / (2 * z) * ∫ x in (0 : ℝ)..π / 2, Complex.sin (2 * z * x) * sin x * (cos x : ℂ) ^ (n - 1) := by
have der1 : ∀ x : ℝ, x ∈ uIcc 0 (π / 2) → HasDerivAt (fun y : ℝ => (cos y : ℂ) ^ n) (-n * sin x * (cos x : ℂ) ^ (n - 1)) x := by intro x _ have b : HasDerivAt (fun y : ℝ => (cos y : ℂ)) (-sin x) x := by simpa using (hasDerivAt_cos x).ofReal_comp convert HasDerivAt.comp x (hasDerivAt_pow _ _) b using 1 ring convert (config := { sameFun := true }) integral_mul_deriv_eq_deriv_mul der1 (fun x _ => antideriv_cos_comp_const_mul hz x) _ _ using 2 · ext1 x; rw [mul_comm] · rw [Complex.ofReal_zero, mul_zero, Complex.sin_zero, zero_div, mul_zero, sub_zero, cos_pi_div_two, Complex.ofReal_zero, zero_pow (by positivity : n ≠ 0), zero_mul, zero_sub, ← integral_neg, ← integral_const_mul] refine integral_congr fun x _ => ?_ field_simp; ring · apply Continuous.intervalIntegrable exact (continuous_const.mul (Complex.continuous_ofReal.comp continuous_sin)).mul ((Complex.continuous_ofReal.comp continuous_cos).pow (n - 1)) · apply Continuous.intervalIntegrable exact Complex.continuous_cos.comp (continuous_const.mul Complex.continuous_ofReal)
/- Copyright (c) 2022 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Data.Finset.Lattice #align_import combinatorics.set_family.compression.down from "leanprover-community/mathlib"@"9003f28797c0664a49e4179487267c494477d853" /-! # Down-compressions This file defines down-compression. Down-compressing `𝒜 : Finset (Finset α)` along `a : α` means removing `a` from the elements of `𝒜`, when the resulting set is not already in `𝒜`. ## Main declarations * `Finset.nonMemberSubfamily`: `𝒜.nonMemberSubfamily a` is the subfamily of sets not containing `a`. * `Finset.memberSubfamily`: `𝒜.memberSubfamily a` is the image of the subfamily of sets containing `a` under removing `a`. * `Down.compression`: Down-compression. ## Notation `𝓓 a 𝒜` is notation for `Down.compress a 𝒜` in locale `SetFamily`. ## References * https://github.com/b-mehta/maths-notes/blob/master/iii/mich/combinatorics.pdf ## Tags compression, down-compression -/ variable {α : Type*} [DecidableEq α] {𝒜 ℬ : Finset (Finset α)} {s : Finset α} {a : α} namespace Finset /-- Elements of `𝒜` that do not contain `a`. -/ def nonMemberSubfamily (a : α) (𝒜 : Finset (Finset α)) : Finset (Finset α) := 𝒜.filter fun s => a ∉ s #align finset.non_member_subfamily Finset.nonMemberSubfamily /-- Image of the elements of `𝒜` which contain `a` under removing `a`. Finsets that do not contain `a` such that `insert a s ∈ 𝒜`. -/ def memberSubfamily (a : α) (𝒜 : Finset (Finset α)) : Finset (Finset α) := (𝒜.filter fun s => a ∈ s).image fun s => erase s a #align finset.member_subfamily Finset.memberSubfamily @[simp] theorem mem_nonMemberSubfamily : s ∈ 𝒜.nonMemberSubfamily a ↔ s ∈ 𝒜 ∧ a ∉ s := by simp [nonMemberSubfamily] #align finset.mem_non_member_subfamily Finset.mem_nonMemberSubfamily @[simp] theorem mem_memberSubfamily : s ∈ 𝒜.memberSubfamily a ↔ insert a s ∈ 𝒜 ∧ a ∉ s := by simp_rw [memberSubfamily, mem_image, mem_filter] refine ⟨?_, fun h => ⟨insert a s, ⟨h.1, by simp⟩, erase_insert h.2⟩⟩ rintro ⟨s, ⟨hs1, hs2⟩, rfl⟩ rw [insert_erase hs2] exact ⟨hs1, not_mem_erase _ _⟩ #align finset.mem_member_subfamily Finset.mem_memberSubfamily theorem nonMemberSubfamily_inter (a : α) (𝒜 ℬ : Finset (Finset α)) : (𝒜 ∩ ℬ).nonMemberSubfamily a = 𝒜.nonMemberSubfamily a ∩ ℬ.nonMemberSubfamily a := filter_inter_distrib _ _ _ #align finset.non_member_subfamily_inter Finset.nonMemberSubfamily_inter theorem memberSubfamily_inter (a : α) (𝒜 ℬ : Finset (Finset α)) : (𝒜 ∩ ℬ).memberSubfamily a = 𝒜.memberSubfamily a ∩ ℬ.memberSubfamily a := by unfold memberSubfamily rw [filter_inter_distrib, image_inter_of_injOn _ _ ((erase_injOn' _).mono _)] simp #align finset.member_subfamily_inter Finset.memberSubfamily_inter theorem nonMemberSubfamily_union (a : α) (𝒜 ℬ : Finset (Finset α)) : (𝒜 ∪ ℬ).nonMemberSubfamily a = 𝒜.nonMemberSubfamily a ∪ ℬ.nonMemberSubfamily a := filter_union _ _ _ #align finset.non_member_subfamily_union Finset.nonMemberSubfamily_union theorem memberSubfamily_union (a : α) (𝒜 ℬ : Finset (Finset α)) : (𝒜 ∪ ℬ).memberSubfamily a = 𝒜.memberSubfamily a ∪ ℬ.memberSubfamily a := by simp_rw [memberSubfamily, filter_union, image_union] #align finset.member_subfamily_union Finset.memberSubfamily_union theorem card_memberSubfamily_add_card_nonMemberSubfamily (a : α) (𝒜 : Finset (Finset α)) : (𝒜.memberSubfamily a).card + (𝒜.nonMemberSubfamily a).card = 𝒜.card := by rw [memberSubfamily, nonMemberSubfamily, card_image_of_injOn] · conv_rhs => rw [← filter_card_add_filter_neg_card_eq_card (fun s => (a ∈ s))] · apply (erase_injOn' _).mono simp #align finset.card_member_subfamily_add_card_non_member_subfamily Finset.card_memberSubfamily_add_card_nonMemberSubfamily theorem memberSubfamily_union_nonMemberSubfamily (a : α) (𝒜 : Finset (Finset α)) : 𝒜.memberSubfamily a ∪ 𝒜.nonMemberSubfamily a = 𝒜.image fun s => s.erase a := by ext s simp only [mem_union, mem_memberSubfamily, mem_nonMemberSubfamily, mem_image, exists_prop] constructor · rintro (h | h) · exact ⟨_, h.1, erase_insert h.2⟩ · exact ⟨_, h.1, erase_eq_of_not_mem h.2⟩ · rintro ⟨s, hs, rfl⟩ by_cases ha : a ∈ s · exact Or.inl ⟨by rwa [insert_erase ha], not_mem_erase _ _⟩ · exact Or.inr ⟨by rwa [erase_eq_of_not_mem ha], not_mem_erase _ _⟩ #align finset.member_subfamily_union_non_member_subfamily Finset.memberSubfamily_union_nonMemberSubfamily @[simp]
Mathlib/Combinatorics/SetFamily/Compression/Down.lean
114
116
theorem memberSubfamily_memberSubfamily : (𝒜.memberSubfamily a).memberSubfamily a = ∅ := by
ext simp
/- Copyright (c) 2022 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Order.Filter.Lift import Mathlib.Topology.Separation import Mathlib.Order.Interval.Set.Monotone #align_import topology.filter from "leanprover-community/mathlib"@"4c19a16e4b705bf135cf9a80ac18fcc99c438514" /-! # Topology on the set of filters on a type This file introduces a topology on `Filter α`. It is generated by the sets `Set.Iic (𝓟 s) = {l : Filter α | s ∈ l}`, `s : Set α`. A set `s : Set (Filter α)` is open if and only if it is a union of a family of these basic open sets, see `Filter.isOpen_iff`. This topology has the following important properties. * If `X` is a topological space, then the map `𝓝 : X → Filter X` is a topology inducing map. * In particular, it is a continuous map, so `𝓝 ∘ f` tends to `𝓝 (𝓝 a)` whenever `f` tends to `𝓝 a`. * If `X` is an ordered topological space with order topology and no max element, then `𝓝 ∘ f` tends to `𝓝 Filter.atTop` whenever `f` tends to `Filter.atTop`. * It turns `Filter X` into a T₀ space and the order on `Filter X` is the dual of the `specializationOrder (Filter X)`. ## Tags filter, topological space -/ open Set Filter TopologicalSpace open Filter Topology variable {ι : Sort*} {α β X Y : Type*} namespace Filter /-- The topology on `Filter α` is generated by the sets `Set.Iic (𝓟 s) = {l : Filter α | s ∈ l}`, `s : Set α`. A set `s : Set (Filter α)` is open if and only if it is a union of a family of these basic open sets, see `Filter.isOpen_iff`. -/ instance : TopologicalSpace (Filter α) := generateFrom <| range <| Iic ∘ 𝓟 theorem isOpen_Iic_principal {s : Set α} : IsOpen (Iic (𝓟 s)) := GenerateOpen.basic _ (mem_range_self _) #align filter.is_open_Iic_principal Filter.isOpen_Iic_principal theorem isOpen_setOf_mem {s : Set α} : IsOpen { l : Filter α | s ∈ l } := by simpa only [Iic_principal] using isOpen_Iic_principal #align filter.is_open_set_of_mem Filter.isOpen_setOf_mem theorem isTopologicalBasis_Iic_principal : IsTopologicalBasis (range (Iic ∘ 𝓟 : Set α → Set (Filter α))) := { exists_subset_inter := by rintro _ ⟨s, rfl⟩ _ ⟨t, rfl⟩ l hl exact ⟨Iic (𝓟 s) ∩ Iic (𝓟 t), ⟨s ∩ t, by simp⟩, hl, Subset.rfl⟩ sUnion_eq := sUnion_eq_univ_iff.2 fun l => ⟨Iic ⊤, ⟨univ, congr_arg Iic principal_univ⟩, mem_Iic.2 le_top⟩ eq_generateFrom := rfl } #align filter.is_topological_basis_Iic_principal Filter.isTopologicalBasis_Iic_principal theorem isOpen_iff {s : Set (Filter α)} : IsOpen s ↔ ∃ T : Set (Set α), s = ⋃ t ∈ T, Iic (𝓟 t) := isTopologicalBasis_Iic_principal.open_iff_eq_sUnion.trans <| by simp only [exists_subset_range_and_iff, sUnion_image, (· ∘ ·)] #align filter.is_open_iff Filter.isOpen_iff theorem nhds_eq (l : Filter α) : 𝓝 l = l.lift' (Iic ∘ 𝓟) := nhds_generateFrom.trans <| by simp only [mem_setOf_eq, @and_comm (l ∈ _), iInf_and, iInf_range, Filter.lift', Filter.lift, (· ∘ ·), mem_Iic, le_principal_iff] #align filter.nhds_eq Filter.nhds_eq theorem nhds_eq' (l : Filter α) : 𝓝 l = l.lift' fun s => { l' | s ∈ l' } := by simpa only [(· ∘ ·), Iic_principal] using nhds_eq l #align filter.nhds_eq' Filter.nhds_eq' protected theorem tendsto_nhds {la : Filter α} {lb : Filter β} {f : α → Filter β} : Tendsto f la (𝓝 lb) ↔ ∀ s ∈ lb, ∀ᶠ a in la, s ∈ f a := by simp only [nhds_eq', tendsto_lift', mem_setOf_eq] #align filter.tendsto_nhds Filter.tendsto_nhds protected theorem HasBasis.nhds {l : Filter α} {p : ι → Prop} {s : ι → Set α} (h : HasBasis l p s) : HasBasis (𝓝 l) p fun i => Iic (𝓟 (s i)) := by rw [nhds_eq] exact h.lift' monotone_principal.Iic #align filter.has_basis.nhds Filter.HasBasis.nhds protected theorem tendsto_pure_self (l : Filter X) : Tendsto (pure : X → Filter X) l (𝓝 l) := by rw [Filter.tendsto_nhds] exact fun s hs ↦ Eventually.mono hs fun x ↦ id /-- Neighborhoods of a countably generated filter is a countably generated filter. -/ instance {l : Filter α} [IsCountablyGenerated l] : IsCountablyGenerated (𝓝 l) := let ⟨_b, hb⟩ := l.exists_antitone_basis HasCountableBasis.isCountablyGenerated <| ⟨hb.nhds, Set.to_countable _⟩ theorem HasBasis.nhds' {l : Filter α} {p : ι → Prop} {s : ι → Set α} (h : HasBasis l p s) : HasBasis (𝓝 l) p fun i => { l' | s i ∈ l' } := by simpa only [Iic_principal] using h.nhds #align filter.has_basis.nhds' Filter.HasBasis.nhds' protected theorem mem_nhds_iff {l : Filter α} {S : Set (Filter α)} : S ∈ 𝓝 l ↔ ∃ t ∈ l, Iic (𝓟 t) ⊆ S := l.basis_sets.nhds.mem_iff #align filter.mem_nhds_iff Filter.mem_nhds_iff theorem mem_nhds_iff' {l : Filter α} {S : Set (Filter α)} : S ∈ 𝓝 l ↔ ∃ t ∈ l, ∀ ⦃l' : Filter α⦄, t ∈ l' → l' ∈ S := l.basis_sets.nhds'.mem_iff #align filter.mem_nhds_iff' Filter.mem_nhds_iff' @[simp] theorem nhds_bot : 𝓝 (⊥ : Filter α) = pure ⊥ := by simp [nhds_eq, (· ∘ ·), lift'_bot monotone_principal.Iic] #align filter.nhds_bot Filter.nhds_bot @[simp]
Mathlib/Topology/Filter.lean
125
125
theorem nhds_top : 𝓝 (⊤ : Filter α) = ⊤ := by
simp [nhds_eq]
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Anne Baanen -/ import Mathlib.Tactic.Ring.Basic import Mathlib.Tactic.TryThis import Mathlib.Tactic.Conv import Mathlib.Util.Qq /-! # `ring_nf` tactic A tactic which uses `ring` to rewrite expressions. This can be used non-terminally to normalize ring expressions in the goal such as `⊢ P (x + x + x)` ~> `⊢ P (x * 3)`, as well as being able to prove some equations that `ring` cannot because they involve ring reasoning inside a subterm, such as `sin (x + y) + sin (y + x) = 2 * sin (x + y)`. -/ set_option autoImplicit true -- In this file we would like to be able to use multi-character auto-implicits. set_option relaxedAutoImplicit true namespace Mathlib.Tactic open Lean hiding Rat open Qq Meta namespace Ring /-- True if this represents an atomic expression. -/ def ExBase.isAtom : ExBase sα a → Bool | .atom _ => true | _ => false /-- True if this represents an atomic expression. -/ def ExProd.isAtom : ExProd sα a → Bool | .mul va₁ (.const 1 _) (.const 1 _) => va₁.isAtom | _ => false /-- True if this represents an atomic expression. -/ def ExSum.isAtom : ExSum sα a → Bool | .add va₁ va₂ => match va₂ with -- FIXME: this takes a while to compile as one match | .zero => va₁.isAtom | _ => false | _ => false end Ring namespace RingNF open Ring /-- The normalization style for `ring_nf`. -/ inductive RingMode where /-- Sum-of-products form, like `x + x * y * 2 + z ^ 2`. -/ | SOP /-- Raw form: the representation `ring` uses internally. -/ | raw deriving Inhabited, BEq, Repr /-- Configuration for `ring_nf`. -/ structure Config where /-- the reducibility setting to use when comparing atoms for defeq -/ red := TransparencyMode.reducible /-- if true, atoms inside ring expressions will be reduced recursively -/ recursive := true /-- The normalization style. -/ mode := RingMode.SOP deriving Inhabited, BEq, Repr /-- Function elaborating `RingNF.Config`. -/ declare_config_elab elabConfig Config /-- The read-only state of the `RingNF` monad. -/ structure Context where /-- A basically empty simp context, passed to the `simp` traversal in `RingNF.rewrite`. -/ ctx : Simp.Context /-- A cleanup routine, which simplifies normalized polynomials to a more human-friendly format. -/ simp : Simp.Result → SimpM Simp.Result /-- The monad for `RingNF` contains, in addition to the `AtomM` state, a simp context for the main traversal and a simp function (which has another simp context) to simplify normalized polynomials. -/ abbrev M := ReaderT Context AtomM /-- A tactic in the `RingNF.M` monad which will simplify expression `parent` to a normal form. * `root`: true if this is a direct call to the function. `RingNF.M.run` sets this to `false` in recursive mode. -/ def rewrite (parent : Expr) (root := true) : M Simp.Result := fun nctx rctx s ↦ do let pre : Simp.Simproc := fun e => try guard <| root || parent != e -- recursion guard let e ← withReducible <| whnf e guard e.isApp -- all interesting ring expressions are applications let ⟨u, α, e⟩ ← inferTypeQ' e let sα ← synthInstanceQ (q(CommSemiring $α) : Q(Type u)) let c ← mkCache sα let ⟨a, _, pa⟩ ← match ← isAtomOrDerivable sα c e rctx s with | none => eval sα c e rctx s -- `none` indicates that `eval` will find something algebraic. | some none => failure -- No point rewriting atoms | some (some r) => pure r -- Nothing algebraic for `eval` to use, but `norm_num` simplifies. let r ← nctx.simp { expr := a, proof? := pa } if ← withReducible <| isDefEq r.expr e then return .done { expr := r.expr } pure (.done r) catch _ => pure <| .continue let post := Simp.postDefault #[] (·.1) <$> Simp.main parent nctx.ctx (methods := { pre, post }) variable [CommSemiring R] theorem add_assoc_rev (a b c : R) : a + (b + c) = a + b + c := (add_assoc ..).symm theorem mul_assoc_rev (a b c : R) : a * (b * c) = a * b * c := (mul_assoc ..).symm theorem mul_neg {R} [Ring R] (a b : R) : a * -b = -(a * b) := by simp theorem add_neg {R} [Ring R] (a b : R) : a + -b = a - b := (sub_eq_add_neg ..).symm theorem nat_rawCast_0 : (Nat.rawCast 0 : R) = 0 := by simp theorem nat_rawCast_1 : (Nat.rawCast 1 : R) = 1 := by simp theorem nat_rawCast_2 [Nat.AtLeastTwo n] : (Nat.rawCast n : R) = OfNat.ofNat n := rfl
Mathlib/Tactic/Ring/RingNF.lean
123
123
theorem int_rawCast_neg {R} [Ring R] : (Int.rawCast (.negOfNat n) : R) = -Nat.rawCast n := by
simp
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Johannes Hölzl, Mario Carneiro, Patrick Massot -/ import Mathlib.Data.Prod.PProd import Mathlib.Data.Set.Countable import Mathlib.Order.Filter.Prod import Mathlib.Order.Filter.Ker #align_import order.filter.bases from "leanprover-community/mathlib"@"996b0ff959da753a555053a480f36e5f264d4207" /-! # Filter bases A filter basis `B : FilterBasis α` on a type `α` is a nonempty collection of sets of `α` such that the intersection of two elements of this collection contains some element of the collection. Compared to filters, filter bases do not require that any set containing an element of `B` belongs to `B`. A filter basis `B` can be used to construct `B.filter : Filter α` such that a set belongs to `B.filter` if and only if it contains an element of `B`. Given an indexing type `ι`, a predicate `p : ι → Prop`, and a map `s : ι → Set α`, the proposition `h : Filter.IsBasis p s` makes sure the range of `s` bounded by `p` (ie. `s '' setOf p`) defines a filter basis `h.filterBasis`. If one already has a filter `l` on `α`, `Filter.HasBasis l p s` (where `p : ι → Prop` and `s : ι → Set α` as above) means that a set belongs to `l` if and only if it contains some `s i` with `p i`. It implies `h : Filter.IsBasis p s`, and `l = h.filterBasis.filter`. The point of this definition is that checking statements involving elements of `l` often reduces to checking them on the basis elements. We define a function `HasBasis.index (h : Filter.HasBasis l p s) (t) (ht : t ∈ l)` that returns some index `i` such that `p i` and `s i ⊆ t`. This function can be useful to avoid manual destruction of `h.mem_iff.mpr ht` using `cases` or `let`. This file also introduces more restricted classes of bases, involving monotonicity or countability. In particular, for `l : Filter α`, `l.IsCountablyGenerated` means there is a countable set of sets which generates `s`. This is reformulated in term of bases, and consequences are derived. ## Main statements * `Filter.HasBasis.mem_iff`, `HasBasis.mem_of_superset`, `HasBasis.mem_of_mem` : restate `t ∈ f` in terms of a basis; * `Filter.basis_sets` : all sets of a filter form a basis; * `Filter.HasBasis.inf`, `Filter.HasBasis.inf_principal`, `Filter.HasBasis.prod`, `Filter.HasBasis.prod_self`, `Filter.HasBasis.map`, `Filter.HasBasis.comap` : combinators to construct filters of `l ⊓ l'`, `l ⊓ 𝓟 t`, `l ×ˢ l'`, `l ×ˢ l`, `l.map f`, `l.comap f` respectively; * `Filter.HasBasis.le_iff`, `Filter.HasBasis.ge_iff`, `Filter.HasBasis.le_basis_iff` : restate `l ≤ l'` in terms of bases. * `Filter.HasBasis.tendsto_right_iff`, `Filter.HasBasis.tendsto_left_iff`, `Filter.HasBasis.tendsto_iff` : restate `Tendsto f l l'` in terms of bases. * `isCountablyGenerated_iff_exists_antitone_basis` : proves a filter is countably generated if and only if it admits a basis parametrized by a decreasing sequence of sets indexed by `ℕ`. * `tendsto_iff_seq_tendsto` : an abstract version of "sequentially continuous implies continuous". ## Implementation notes As with `Set.iUnion`/`biUnion`/`Set.sUnion`, there are three different approaches to filter bases: * `Filter.HasBasis l s`, `s : Set (Set α)`; * `Filter.HasBasis l s`, `s : ι → Set α`; * `Filter.HasBasis l p s`, `p : ι → Prop`, `s : ι → Set α`. We use the latter one because, e.g., `𝓝 x` in an `EMetricSpace` or in a `MetricSpace` has a basis of this form. The other two can be emulated using `s = id` or `p = fun _ ↦ True`. With this approach sometimes one needs to `simp` the statement provided by the `Filter.HasBasis` machinery, e.g., `simp only [true_and]` or `simp only [forall_const]` can help with the case `p = fun _ ↦ True`. -/ set_option autoImplicit true open Set Filter open scoped Classical open Filter section sort variable {α β γ : Type*} {ι ι' : Sort*} /-- A filter basis `B` on a type `α` is a nonempty collection of sets of `α` such that the intersection of two elements of this collection contains some element of the collection. -/ structure FilterBasis (α : Type*) where /-- Sets of a filter basis. -/ sets : Set (Set α) /-- The set of filter basis sets is nonempty. -/ nonempty : sets.Nonempty /-- The set of filter basis sets is directed downwards. -/ inter_sets {x y} : x ∈ sets → y ∈ sets → ∃ z ∈ sets, z ⊆ x ∩ y #align filter_basis FilterBasis instance FilterBasis.nonempty_sets (B : FilterBasis α) : Nonempty B.sets := B.nonempty.to_subtype #align filter_basis.nonempty_sets FilterBasis.nonempty_sets -- Porting note: this instance was reducible but it doesn't work the same way in Lean 4 /-- If `B` is a filter basis on `α`, and `U` a subset of `α` then we can write `U ∈ B` as on paper. -/ instance {α : Type*} : Membership (Set α) (FilterBasis α) := ⟨fun U B => U ∈ B.sets⟩ @[simp] theorem FilterBasis.mem_sets {s : Set α} {B : FilterBasis α} : s ∈ B.sets ↔ s ∈ B := Iff.rfl -- For illustration purposes, the filter basis defining `(atTop : Filter ℕ)` instance : Inhabited (FilterBasis ℕ) := ⟨{ sets := range Ici nonempty := ⟨Ici 0, mem_range_self 0⟩ inter_sets := by rintro _ _ ⟨n, rfl⟩ ⟨m, rfl⟩ exact ⟨Ici (max n m), mem_range_self _, Ici_inter_Ici.symm.subset⟩ }⟩ /-- View a filter as a filter basis. -/ def Filter.asBasis (f : Filter α) : FilterBasis α := ⟨f.sets, ⟨univ, univ_mem⟩, fun {x y} hx hy => ⟨x ∩ y, inter_mem hx hy, subset_rfl⟩⟩ #align filter.as_basis Filter.asBasis -- Porting note: was `protected` in Lean 3 but `protected` didn't work; removed /-- `is_basis p s` means the image of `s` bounded by `p` is a filter basis. -/ structure Filter.IsBasis (p : ι → Prop) (s : ι → Set α) : Prop where /-- There exists at least one `i` that satisfies `p`. -/ nonempty : ∃ i, p i /-- `s` is directed downwards on `i` such that `p i`. -/ inter : ∀ {i j}, p i → p j → ∃ k, p k ∧ s k ⊆ s i ∩ s j #align filter.is_basis Filter.IsBasis namespace Filter namespace IsBasis /-- Constructs a filter basis from an indexed family of sets satisfying `IsBasis`. -/ protected def filterBasis {p : ι → Prop} {s : ι → Set α} (h : IsBasis p s) : FilterBasis α where sets := { t | ∃ i, p i ∧ s i = t } nonempty := let ⟨i, hi⟩ := h.nonempty ⟨s i, ⟨i, hi, rfl⟩⟩ inter_sets := by rintro _ _ ⟨i, hi, rfl⟩ ⟨j, hj, rfl⟩ rcases h.inter hi hj with ⟨k, hk, hk'⟩ exact ⟨_, ⟨k, hk, rfl⟩, hk'⟩ #align filter.is_basis.filter_basis Filter.IsBasis.filterBasis variable {p : ι → Prop} {s : ι → Set α} (h : IsBasis p s) theorem mem_filterBasis_iff {U : Set α} : U ∈ h.filterBasis ↔ ∃ i, p i ∧ s i = U := Iff.rfl #align filter.is_basis.mem_filter_basis_iff Filter.IsBasis.mem_filterBasis_iff end IsBasis end Filter namespace FilterBasis /-- The filter associated to a filter basis. -/ protected def filter (B : FilterBasis α) : Filter α where sets := { s | ∃ t ∈ B, t ⊆ s } univ_sets := B.nonempty.imp fun s s_in => ⟨s_in, s.subset_univ⟩ sets_of_superset := fun ⟨s, s_in, h⟩ hxy => ⟨s, s_in, Set.Subset.trans h hxy⟩ inter_sets := fun ⟨_s, s_in, hs⟩ ⟨_t, t_in, ht⟩ => let ⟨u, u_in, u_sub⟩ := B.inter_sets s_in t_in ⟨u, u_in, u_sub.trans (inter_subset_inter hs ht)⟩ #align filter_basis.filter FilterBasis.filter theorem mem_filter_iff (B : FilterBasis α) {U : Set α} : U ∈ B.filter ↔ ∃ s ∈ B, s ⊆ U := Iff.rfl #align filter_basis.mem_filter_iff FilterBasis.mem_filter_iff theorem mem_filter_of_mem (B : FilterBasis α) {U : Set α} : U ∈ B → U ∈ B.filter := fun U_in => ⟨U, U_in, Subset.refl _⟩ #align filter_basis.mem_filter_of_mem FilterBasis.mem_filter_of_mem theorem eq_iInf_principal (B : FilterBasis α) : B.filter = ⨅ s : B.sets, 𝓟 s := by have : Directed (· ≥ ·) fun s : B.sets => 𝓟 (s : Set α) := by rintro ⟨U, U_in⟩ ⟨V, V_in⟩ rcases B.inter_sets U_in V_in with ⟨W, W_in, W_sub⟩ use ⟨W, W_in⟩ simp only [ge_iff_le, le_principal_iff, mem_principal, Subtype.coe_mk] exact subset_inter_iff.mp W_sub ext U simp [mem_filter_iff, mem_iInf_of_directed this] #align filter_basis.eq_infi_principal FilterBasis.eq_iInf_principal protected theorem generate (B : FilterBasis α) : generate B.sets = B.filter := by apply le_antisymm · intro U U_in rcases B.mem_filter_iff.mp U_in with ⟨V, V_in, h⟩ exact GenerateSets.superset (GenerateSets.basic V_in) h · rw [le_generate_iff] apply mem_filter_of_mem #align filter_basis.generate FilterBasis.generate end FilterBasis namespace Filter namespace IsBasis variable {p : ι → Prop} {s : ι → Set α} /-- Constructs a filter from an indexed family of sets satisfying `IsBasis`. -/ protected def filter (h : IsBasis p s) : Filter α := h.filterBasis.filter #align filter.is_basis.filter Filter.IsBasis.filter protected theorem mem_filter_iff (h : IsBasis p s) {U : Set α} : U ∈ h.filter ↔ ∃ i, p i ∧ s i ⊆ U := by simp only [IsBasis.filter, FilterBasis.mem_filter_iff, mem_filterBasis_iff, exists_exists_and_eq_and] #align filter.is_basis.mem_filter_iff Filter.IsBasis.mem_filter_iff theorem filter_eq_generate (h : IsBasis p s) : h.filter = generate { U | ∃ i, p i ∧ s i = U } := by erw [h.filterBasis.generate]; rfl #align filter.is_basis.filter_eq_generate Filter.IsBasis.filter_eq_generate end IsBasis -- Porting note: was `protected` in Lean 3 but `protected` didn't work; removed /-- We say that a filter `l` has a basis `s : ι → Set α` bounded by `p : ι → Prop`, if `t ∈ l` if and only if `t` includes `s i` for some `i` such that `p i`. -/ structure HasBasis (l : Filter α) (p : ι → Prop) (s : ι → Set α) : Prop where /-- A set `t` belongs to a filter `l` iff it includes an element of the basis. -/ mem_iff' : ∀ t : Set α, t ∈ l ↔ ∃ i, p i ∧ s i ⊆ t #align filter.has_basis Filter.HasBasis section SameType variable {l l' : Filter α} {p : ι → Prop} {s : ι → Set α} {t : Set α} {i : ι} {p' : ι' → Prop} {s' : ι' → Set α} {i' : ι'} theorem hasBasis_generate (s : Set (Set α)) : (generate s).HasBasis (fun t => Set.Finite t ∧ t ⊆ s) fun t => ⋂₀ t := ⟨fun U => by simp only [mem_generate_iff, exists_prop, and_assoc, and_left_comm]⟩ #align filter.has_basis_generate Filter.hasBasis_generate /-- The smallest filter basis containing a given collection of sets. -/ def FilterBasis.ofSets (s : Set (Set α)) : FilterBasis α where sets := sInter '' { t | Set.Finite t ∧ t ⊆ s } nonempty := ⟨univ, ∅, ⟨⟨finite_empty, empty_subset s⟩, sInter_empty⟩⟩ inter_sets := by rintro _ _ ⟨a, ⟨fina, suba⟩, rfl⟩ ⟨b, ⟨finb, subb⟩, rfl⟩ exact ⟨⋂₀ (a ∪ b), mem_image_of_mem _ ⟨fina.union finb, union_subset suba subb⟩, (sInter_union _ _).subset⟩ #align filter.filter_basis.of_sets Filter.FilterBasis.ofSets lemma FilterBasis.ofSets_sets (s : Set (Set α)) : (FilterBasis.ofSets s).sets = sInter '' { t | Set.Finite t ∧ t ⊆ s } := rfl -- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`. /-- Definition of `HasBasis` unfolded with implicit set argument. -/ theorem HasBasis.mem_iff (hl : l.HasBasis p s) : t ∈ l ↔ ∃ i, p i ∧ s i ⊆ t := hl.mem_iff' t #align filter.has_basis.mem_iff Filter.HasBasis.mem_iffₓ theorem HasBasis.eq_of_same_basis (hl : l.HasBasis p s) (hl' : l'.HasBasis p s) : l = l' := by ext t rw [hl.mem_iff, hl'.mem_iff] #align filter.has_basis.eq_of_same_basis Filter.HasBasis.eq_of_same_basis -- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`. theorem hasBasis_iff : l.HasBasis p s ↔ ∀ t, t ∈ l ↔ ∃ i, p i ∧ s i ⊆ t := ⟨fun ⟨h⟩ => h, fun h => ⟨h⟩⟩ #align filter.has_basis_iff Filter.hasBasis_iffₓ theorem HasBasis.ex_mem (h : l.HasBasis p s) : ∃ i, p i := (h.mem_iff.mp univ_mem).imp fun _ => And.left #align filter.has_basis.ex_mem Filter.HasBasis.ex_mem protected theorem HasBasis.nonempty (h : l.HasBasis p s) : Nonempty ι := nonempty_of_exists h.ex_mem #align filter.has_basis.nonempty Filter.HasBasis.nonempty protected theorem IsBasis.hasBasis (h : IsBasis p s) : HasBasis h.filter p s := ⟨fun t => by simp only [h.mem_filter_iff, exists_prop]⟩ #align filter.is_basis.has_basis Filter.IsBasis.hasBasis protected theorem HasBasis.mem_of_superset (hl : l.HasBasis p s) (hi : p i) (ht : s i ⊆ t) : t ∈ l := hl.mem_iff.2 ⟨i, hi, ht⟩ #align filter.has_basis.mem_of_superset Filter.HasBasis.mem_of_superset theorem HasBasis.mem_of_mem (hl : l.HasBasis p s) (hi : p i) : s i ∈ l := hl.mem_of_superset hi Subset.rfl #align filter.has_basis.mem_of_mem Filter.HasBasis.mem_of_mem /-- Index of a basis set such that `s i ⊆ t` as an element of `Subtype p`. -/ noncomputable def HasBasis.index (h : l.HasBasis p s) (t : Set α) (ht : t ∈ l) : { i : ι // p i } := ⟨(h.mem_iff.1 ht).choose, (h.mem_iff.1 ht).choose_spec.1⟩ #align filter.has_basis.index Filter.HasBasis.index theorem HasBasis.property_index (h : l.HasBasis p s) (ht : t ∈ l) : p (h.index t ht) := (h.index t ht).2 #align filter.has_basis.property_index Filter.HasBasis.property_index theorem HasBasis.set_index_mem (h : l.HasBasis p s) (ht : t ∈ l) : s (h.index t ht) ∈ l := h.mem_of_mem <| h.property_index _ #align filter.has_basis.set_index_mem Filter.HasBasis.set_index_mem theorem HasBasis.set_index_subset (h : l.HasBasis p s) (ht : t ∈ l) : s (h.index t ht) ⊆ t := (h.mem_iff.1 ht).choose_spec.2 #align filter.has_basis.set_index_subset Filter.HasBasis.set_index_subset theorem HasBasis.isBasis (h : l.HasBasis p s) : IsBasis p s where nonempty := h.ex_mem inter hi hj := by simpa only [h.mem_iff] using inter_mem (h.mem_of_mem hi) (h.mem_of_mem hj) #align filter.has_basis.is_basis Filter.HasBasis.isBasis theorem HasBasis.filter_eq (h : l.HasBasis p s) : h.isBasis.filter = l := by ext U simp [h.mem_iff, IsBasis.mem_filter_iff] #align filter.has_basis.filter_eq Filter.HasBasis.filter_eq
Mathlib/Order/Filter/Bases.lean
327
328
theorem HasBasis.eq_generate (h : l.HasBasis p s) : l = generate { U | ∃ i, p i ∧ s i = U } := by
rw [← h.isBasis.filter_eq_generate, h.filter_eq]
/- Copyright (c) 2022 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ import Mathlib.Data.ZMod.Basic import Mathlib.RingTheory.Int.Basic import Mathlib.RingTheory.PrincipalIdealDomain #align_import data.zmod.coprime from "leanprover-community/mathlib"@"4b4975cf92a1ffe2ddfeff6ff91b0c46a9162bf5" /-! # Coprimality and vanishing We show that for prime `p`, the image of an integer `a` in `ZMod p` vanishes if and only if `a` and `p` are not coprime. -/ namespace ZMod /-- If `p` is a prime and `a` is an integer, then `a : ZMod p` is zero if and only if `gcd a p ≠ 1`. -/
Mathlib/Data/ZMod/Coprime.lean
24
28
theorem eq_zero_iff_gcd_ne_one {a : ℤ} {p : ℕ} [pp : Fact p.Prime] : (a : ZMod p) = 0 ↔ a.gcd p ≠ 1 := by
rw [Ne, Int.gcd_comm, Int.gcd_eq_one_iff_coprime, (Nat.prime_iff_prime_int.1 pp.1).coprime_iff_not_dvd, Classical.not_not, intCast_zmod_eq_zero_iff_dvd]
/- Copyright (c) 2020 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou -/ import Mathlib.Algebra.Group.Pi.Lemmas import Mathlib.Algebra.Group.Support #align_import algebra.indicator_function from "leanprover-community/mathlib"@"2445c98ae4b87eabebdde552593519b9b6dc350c" /-! # Indicator function - `Set.indicator (s : Set α) (f : α → β) (a : α)` is `f a` if `a ∈ s` and is `0` otherwise. - `Set.mulIndicator (s : Set α) (f : α → β) (a : α)` is `f a` if `a ∈ s` and is `1` otherwise. ## Implementation note In mathematics, an indicator function or a characteristic function is a function used to indicate membership of an element in a set `s`, having the value `1` for all elements of `s` and the value `0` otherwise. But since it is usually used to restrict a function to a certain set `s`, we let the indicator function take the value `f x` for some function `f`, instead of `1`. If the usual indicator function is needed, just set `f` to be the constant function `fun _ ↦ 1`. The indicator function is implemented non-computably, to avoid having to pass around `Decidable` arguments. This is in contrast with the design of `Pi.single` or `Set.piecewise`. ## Tags indicator, characteristic -/ assert_not_exists MonoidWithZero open Function variable {α β ι M N : Type*} namespace Set section One variable [One M] [One N] {s t : Set α} {f g : α → M} {a : α} /-- `Set.mulIndicator s f a` is `f a` if `a ∈ s`, `1` otherwise. -/ @[to_additive "`Set.indicator s f a` is `f a` if `a ∈ s`, `0` otherwise."] noncomputable def mulIndicator (s : Set α) (f : α → M) (x : α) : M := haveI := Classical.decPred (· ∈ s) if x ∈ s then f x else 1 #align set.mul_indicator Set.mulIndicator @[to_additive (attr := simp)] theorem piecewise_eq_mulIndicator [DecidablePred (· ∈ s)] : s.piecewise f 1 = s.mulIndicator f := funext fun _ => @if_congr _ _ _ _ (id _) _ _ _ _ Iff.rfl rfl rfl #align set.piecewise_eq_mul_indicator Set.piecewise_eq_mulIndicator #align set.piecewise_eq_indicator Set.piecewise_eq_indicator -- Porting note: needed unfold for mulIndicator @[to_additive] theorem mulIndicator_apply (s : Set α) (f : α → M) (a : α) [Decidable (a ∈ s)] : mulIndicator s f a = if a ∈ s then f a else 1 := by unfold mulIndicator congr #align set.mul_indicator_apply Set.mulIndicator_apply #align set.indicator_apply Set.indicator_apply @[to_additive (attr := simp)] theorem mulIndicator_of_mem (h : a ∈ s) (f : α → M) : mulIndicator s f a = f a := if_pos h #align set.mul_indicator_of_mem Set.mulIndicator_of_mem #align set.indicator_of_mem Set.indicator_of_mem @[to_additive (attr := simp)] theorem mulIndicator_of_not_mem (h : a ∉ s) (f : α → M) : mulIndicator s f a = 1 := if_neg h #align set.mul_indicator_of_not_mem Set.mulIndicator_of_not_mem #align set.indicator_of_not_mem Set.indicator_of_not_mem @[to_additive] theorem mulIndicator_eq_one_or_self (s : Set α) (f : α → M) (a : α) : mulIndicator s f a = 1 ∨ mulIndicator s f a = f a := by by_cases h : a ∈ s · exact Or.inr (mulIndicator_of_mem h f) · exact Or.inl (mulIndicator_of_not_mem h f) #align set.mul_indicator_eq_one_or_self Set.mulIndicator_eq_one_or_self #align set.indicator_eq_zero_or_self Set.indicator_eq_zero_or_self @[to_additive (attr := simp)] theorem mulIndicator_apply_eq_self : s.mulIndicator f a = f a ↔ a ∉ s → f a = 1 := letI := Classical.dec (a ∈ s) ite_eq_left_iff.trans (by rw [@eq_comm _ (f a)]) #align set.mul_indicator_apply_eq_self Set.mulIndicator_apply_eq_self #align set.indicator_apply_eq_self Set.indicator_apply_eq_self @[to_additive (attr := simp)] theorem mulIndicator_eq_self : s.mulIndicator f = f ↔ mulSupport f ⊆ s := by simp only [funext_iff, subset_def, mem_mulSupport, mulIndicator_apply_eq_self, not_imp_comm] #align set.mul_indicator_eq_self Set.mulIndicator_eq_self #align set.indicator_eq_self Set.indicator_eq_self @[to_additive] theorem mulIndicator_eq_self_of_superset (h1 : s.mulIndicator f = f) (h2 : s ⊆ t) : t.mulIndicator f = f := by rw [mulIndicator_eq_self] at h1 ⊢ exact Subset.trans h1 h2 #align set.mul_indicator_eq_self_of_superset Set.mulIndicator_eq_self_of_superset #align set.indicator_eq_self_of_superset Set.indicator_eq_self_of_superset @[to_additive (attr := simp)] theorem mulIndicator_apply_eq_one : mulIndicator s f a = 1 ↔ a ∈ s → f a = 1 := letI := Classical.dec (a ∈ s) ite_eq_right_iff #align set.mul_indicator_apply_eq_one Set.mulIndicator_apply_eq_one #align set.indicator_apply_eq_zero Set.indicator_apply_eq_zero @[to_additive (attr := simp)] theorem mulIndicator_eq_one : (mulIndicator s f = fun x => 1) ↔ Disjoint (mulSupport f) s := by simp only [funext_iff, mulIndicator_apply_eq_one, Set.disjoint_left, mem_mulSupport, not_imp_not] #align set.mul_indicator_eq_one Set.mulIndicator_eq_one #align set.indicator_eq_zero Set.indicator_eq_zero @[to_additive (attr := simp)] theorem mulIndicator_eq_one' : mulIndicator s f = 1 ↔ Disjoint (mulSupport f) s := mulIndicator_eq_one #align set.mul_indicator_eq_one' Set.mulIndicator_eq_one' #align set.indicator_eq_zero' Set.indicator_eq_zero' @[to_additive] theorem mulIndicator_apply_ne_one {a : α} : s.mulIndicator f a ≠ 1 ↔ a ∈ s ∩ mulSupport f := by simp only [Ne, mulIndicator_apply_eq_one, Classical.not_imp, mem_inter_iff, mem_mulSupport] #align set.mul_indicator_apply_ne_one Set.mulIndicator_apply_ne_one #align set.indicator_apply_ne_zero Set.indicator_apply_ne_zero @[to_additive (attr := simp)] theorem mulSupport_mulIndicator : Function.mulSupport (s.mulIndicator f) = s ∩ Function.mulSupport f := ext fun x => by simp [Function.mem_mulSupport, mulIndicator_apply_eq_one] #align set.mul_support_mul_indicator Set.mulSupport_mulIndicator #align set.support_indicator Set.support_indicator /-- If a multiplicative indicator function is not equal to `1` at a point, then that point is in the set. -/ @[to_additive "If an additive indicator function is not equal to `0` at a point, then that point is in the set."] theorem mem_of_mulIndicator_ne_one (h : mulIndicator s f a ≠ 1) : a ∈ s := not_imp_comm.1 (fun hn => mulIndicator_of_not_mem hn f) h #align set.mem_of_mul_indicator_ne_one Set.mem_of_mulIndicator_ne_one #align set.mem_of_indicator_ne_zero Set.mem_of_indicator_ne_zero @[to_additive] theorem eqOn_mulIndicator : EqOn (mulIndicator s f) f s := fun _ hx => mulIndicator_of_mem hx f #align set.eq_on_mul_indicator Set.eqOn_mulIndicator #align set.eq_on_indicator Set.eqOn_indicator @[to_additive] theorem mulSupport_mulIndicator_subset : mulSupport (s.mulIndicator f) ⊆ s := fun _ hx => hx.imp_symm fun h => mulIndicator_of_not_mem h f #align set.mul_support_mul_indicator_subset Set.mulSupport_mulIndicator_subset #align set.support_indicator_subset Set.support_indicator_subset @[to_additive (attr := simp)] theorem mulIndicator_mulSupport : mulIndicator (mulSupport f) f = f := mulIndicator_eq_self.2 Subset.rfl #align set.mul_indicator_mul_support Set.mulIndicator_mulSupport #align set.indicator_support Set.indicator_support @[to_additive (attr := simp)] theorem mulIndicator_range_comp {ι : Sort*} (f : ι → α) (g : α → M) : mulIndicator (range f) g ∘ f = g ∘ f := letI := Classical.decPred (· ∈ range f) piecewise_range_comp _ _ _ #align set.mul_indicator_range_comp Set.mulIndicator_range_comp #align set.indicator_range_comp Set.indicator_range_comp @[to_additive] theorem mulIndicator_congr (h : EqOn f g s) : mulIndicator s f = mulIndicator s g := funext fun x => by simp only [mulIndicator] split_ifs with h_1 · exact h h_1 rfl #align set.mul_indicator_congr Set.mulIndicator_congr #align set.indicator_congr Set.indicator_congr @[to_additive (attr := simp)] theorem mulIndicator_univ (f : α → M) : mulIndicator (univ : Set α) f = f := mulIndicator_eq_self.2 <| subset_univ _ #align set.mul_indicator_univ Set.mulIndicator_univ #align set.indicator_univ Set.indicator_univ @[to_additive (attr := simp)] theorem mulIndicator_empty (f : α → M) : mulIndicator (∅ : Set α) f = fun _ => 1 := mulIndicator_eq_one.2 <| disjoint_empty _ #align set.mul_indicator_empty Set.mulIndicator_empty #align set.indicator_empty Set.indicator_empty @[to_additive] theorem mulIndicator_empty' (f : α → M) : mulIndicator (∅ : Set α) f = 1 := mulIndicator_empty f #align set.mul_indicator_empty' Set.mulIndicator_empty' #align set.indicator_empty' Set.indicator_empty' variable (M) @[to_additive (attr := simp)] theorem mulIndicator_one (s : Set α) : (mulIndicator s fun _ => (1 : M)) = fun _ => (1 : M) := mulIndicator_eq_one.2 <| by simp only [mulSupport_one, empty_disjoint] #align set.mul_indicator_one Set.mulIndicator_one #align set.indicator_zero Set.indicator_zero @[to_additive (attr := simp)] theorem mulIndicator_one' {s : Set α} : s.mulIndicator (1 : α → M) = 1 := mulIndicator_one M s #align set.mul_indicator_one' Set.mulIndicator_one' #align set.indicator_zero' Set.indicator_zero' variable {M} @[to_additive] theorem mulIndicator_mulIndicator (s t : Set α) (f : α → M) : mulIndicator s (mulIndicator t f) = mulIndicator (s ∩ t) f := funext fun x => by simp only [mulIndicator] split_ifs <;> simp_all (config := { contextual := true }) #align set.mul_indicator_mul_indicator Set.mulIndicator_mulIndicator #align set.indicator_indicator Set.indicator_indicator @[to_additive (attr := simp)] theorem mulIndicator_inter_mulSupport (s : Set α) (f : α → M) : mulIndicator (s ∩ mulSupport f) f = mulIndicator s f := by rw [← mulIndicator_mulIndicator, mulIndicator_mulSupport] #align set.mul_indicator_inter_mul_support Set.mulIndicator_inter_mulSupport #align set.indicator_inter_support Set.indicator_inter_support @[to_additive] theorem comp_mulIndicator (h : M → β) (f : α → M) {s : Set α} {x : α} [DecidablePred (· ∈ s)] : h (s.mulIndicator f x) = s.piecewise (h ∘ f) (const α (h 1)) x := by letI := Classical.decPred (· ∈ s) convert s.apply_piecewise f (const α 1) (fun _ => h) (x := x) using 2 #align set.comp_mul_indicator Set.comp_mulIndicator #align set.comp_indicator Set.comp_indicator @[to_additive] theorem mulIndicator_comp_right {s : Set α} (f : β → α) {g : α → M} {x : β} : mulIndicator (f ⁻¹' s) (g ∘ f) x = mulIndicator s g (f x) := by simp only [mulIndicator, Function.comp] split_ifs with h h' h'' <;> first | rfl | contradiction #align set.mul_indicator_comp_right Set.mulIndicator_comp_right #align set.indicator_comp_right Set.indicator_comp_right @[to_additive] theorem mulIndicator_image {s : Set α} {f : β → M} {g : α → β} (hg : Injective g) {x : α} : mulIndicator (g '' s) f (g x) = mulIndicator s (f ∘ g) x := by rw [← mulIndicator_comp_right, preimage_image_eq _ hg] #align set.mul_indicator_image Set.mulIndicator_image #align set.indicator_image Set.indicator_image @[to_additive] theorem mulIndicator_comp_of_one {g : M → N} (hg : g 1 = 1) : mulIndicator s (g ∘ f) = g ∘ mulIndicator s f := by funext simp only [mulIndicator] split_ifs <;> simp [*] #align set.mul_indicator_comp_of_one Set.mulIndicator_comp_of_one #align set.indicator_comp_of_zero Set.indicator_comp_of_zero @[to_additive] theorem comp_mulIndicator_const (c : M) (f : M → N) (hf : f 1 = 1) : (fun x => f (s.mulIndicator (fun _ => c) x)) = s.mulIndicator fun _ => f c := (mulIndicator_comp_of_one hf).symm #align set.comp_mul_indicator_const Set.comp_mulIndicator_const #align set.comp_indicator_const Set.comp_indicator_const @[to_additive] theorem mulIndicator_preimage (s : Set α) (f : α → M) (B : Set M) : mulIndicator s f ⁻¹' B = s.ite (f ⁻¹' B) (1 ⁻¹' B) := letI := Classical.decPred (· ∈ s) piecewise_preimage s f 1 B #align set.mul_indicator_preimage Set.mulIndicator_preimage #align set.indicator_preimage Set.indicator_preimage @[to_additive] theorem mulIndicator_one_preimage (s : Set M) : t.mulIndicator 1 ⁻¹' s ∈ ({Set.univ, ∅} : Set (Set α)) := by classical rw [mulIndicator_one', preimage_one] split_ifs <;> simp #align set.mul_indicator_one_preimage Set.mulIndicator_one_preimage #align set.indicator_zero_preimage Set.indicator_zero_preimage @[to_additive] theorem mulIndicator_const_preimage_eq_union (U : Set α) (s : Set M) (a : M) [Decidable (a ∈ s)] [Decidable ((1 : M) ∈ s)] : (U.mulIndicator fun _ => a) ⁻¹' s = (if a ∈ s then U else ∅) ∪ if (1 : M) ∈ s then Uᶜ else ∅ := by rw [mulIndicator_preimage, preimage_one, preimage_const] split_ifs <;> simp [← compl_eq_univ_diff] #align set.mul_indicator_const_preimage_eq_union Set.mulIndicator_const_preimage_eq_union #align set.indicator_const_preimage_eq_union Set.indicator_const_preimage_eq_union @[to_additive] theorem mulIndicator_const_preimage (U : Set α) (s : Set M) (a : M) : (U.mulIndicator fun _ => a) ⁻¹' s ∈ ({Set.univ, U, Uᶜ, ∅} : Set (Set α)) := by classical rw [mulIndicator_const_preimage_eq_union] split_ifs <;> simp #align set.mul_indicator_const_preimage Set.mulIndicator_const_preimage #align set.indicator_const_preimage Set.indicator_const_preimage theorem indicator_one_preimage [Zero M] (U : Set α) (s : Set M) : U.indicator 1 ⁻¹' s ∈ ({Set.univ, U, Uᶜ, ∅} : Set (Set α)) := indicator_const_preimage _ _ 1 #align set.indicator_one_preimage Set.indicator_one_preimage @[to_additive] theorem mulIndicator_preimage_of_not_mem (s : Set α) (f : α → M) {t : Set M} (ht : (1 : M) ∉ t) : mulIndicator s f ⁻¹' t = f ⁻¹' t ∩ s := by simp [mulIndicator_preimage, Pi.one_def, Set.preimage_const_of_not_mem ht] #align set.mul_indicator_preimage_of_not_mem Set.mulIndicator_preimage_of_not_mem #align set.indicator_preimage_of_not_mem Set.indicator_preimage_of_not_mem @[to_additive] theorem mem_range_mulIndicator {r : M} {s : Set α} {f : α → M} : r ∈ range (mulIndicator s f) ↔ r = 1 ∧ s ≠ univ ∨ r ∈ f '' s := by simp [mulIndicator, ite_eq_iff, exists_or, eq_univ_iff_forall, and_comm, or_comm, @eq_comm _ r 1] #align set.mem_range_mul_indicator Set.mem_range_mulIndicator #align set.mem_range_indicator Set.mem_range_indicator @[to_additive] theorem mulIndicator_rel_mulIndicator {r : M → M → Prop} (h1 : r 1 1) (ha : a ∈ s → r (f a) (g a)) : r (mulIndicator s f a) (mulIndicator s g a) := by simp only [mulIndicator] split_ifs with has exacts [ha has, h1] #align set.mul_indicator_rel_mul_indicator Set.mulIndicator_rel_mulIndicator #align set.indicator_rel_indicator Set.indicator_rel_indicator end One section Monoid variable [MulOneClass M] {s t : Set α} {f g : α → M} {a : α} @[to_additive] theorem mulIndicator_union_mul_inter_apply (f : α → M) (s t : Set α) (a : α) : mulIndicator (s ∪ t) f a * mulIndicator (s ∩ t) f a = mulIndicator s f a * mulIndicator t f a := by by_cases hs : a ∈ s <;> by_cases ht : a ∈ t <;> simp [*] #align set.mul_indicator_union_mul_inter_apply Set.mulIndicator_union_mul_inter_apply #align set.indicator_union_add_inter_apply Set.indicator_union_add_inter_apply @[to_additive] theorem mulIndicator_union_mul_inter (f : α → M) (s t : Set α) : mulIndicator (s ∪ t) f * mulIndicator (s ∩ t) f = mulIndicator s f * mulIndicator t f := funext <| mulIndicator_union_mul_inter_apply f s t #align set.mul_indicator_union_mul_inter Set.mulIndicator_union_mul_inter #align set.indicator_union_add_inter Set.indicator_union_add_inter @[to_additive] theorem mulIndicator_union_of_not_mem_inter (h : a ∉ s ∩ t) (f : α → M) : mulIndicator (s ∪ t) f a = mulIndicator s f a * mulIndicator t f a := by rw [← mulIndicator_union_mul_inter_apply f s t, mulIndicator_of_not_mem h, mul_one] #align set.mul_indicator_union_of_not_mem_inter Set.mulIndicator_union_of_not_mem_inter #align set.indicator_union_of_not_mem_inter Set.indicator_union_of_not_mem_inter @[to_additive] theorem mulIndicator_union_of_disjoint (h : Disjoint s t) (f : α → M) : mulIndicator (s ∪ t) f = fun a => mulIndicator s f a * mulIndicator t f a := funext fun _ => mulIndicator_union_of_not_mem_inter (fun ha => h.le_bot ha) _ #align set.mul_indicator_union_of_disjoint Set.mulIndicator_union_of_disjoint #align set.indicator_union_of_disjoint Set.indicator_union_of_disjoint open scoped symmDiff in @[to_additive] theorem mulIndicator_symmDiff (s t : Set α) (f : α → M) : mulIndicator (s ∆ t) f = mulIndicator (s \ t) f * mulIndicator (t \ s) f := mulIndicator_union_of_disjoint (disjoint_sdiff_self_right.mono_left sdiff_le) _ @[to_additive]
Mathlib/Algebra/Group/Indicator.lean
383
389
theorem mulIndicator_mul (s : Set α) (f g : α → M) : (mulIndicator s fun a => f a * g a) = fun a => mulIndicator s f a * mulIndicator s g a := by
funext simp only [mulIndicator] split_ifs · rfl rw [mul_one]
/- Copyright (c) 2023 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.MeasureTheory.Constructions.Pi import Mathlib.Probability.Kernel.Basic /-! # Independence with respect to a kernel and a measure A family of sets of sets `π : ι → Set (Set Ω)` is independent with respect to a kernel `κ : kernel α Ω` and a measure `μ` on `α` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ π i_1, ..., f i_n ∈ π i_n`, then for `μ`-almost every `a : α`, `κ a (⋂ i in s, f i) = ∏ i ∈ s, κ a (f i)`. This notion of independence is a generalization of both independence and conditional independence. For conditional independence, `κ` is the conditional kernel `ProbabilityTheory.condexpKernel` and `μ` is the ambiant measure. For (non-conditional) independence, `κ = kernel.const Unit μ` and the measure is the Dirac measure on `Unit`. The main purpose of this file is to prove only once the properties that hold for both conditional and non-conditional independence. ## Main definitions * `ProbabilityTheory.kernel.iIndepSets`: independence of a family of sets of sets. Variant for two sets of sets: `ProbabilityTheory.kernel.IndepSets`. * `ProbabilityTheory.kernel.iIndep`: independence of a family of σ-algebras. Variant for two σ-algebras: `Indep`. * `ProbabilityTheory.kernel.iIndepSet`: independence of a family of sets. Variant for two sets: `ProbabilityTheory.kernel.IndepSet`. * `ProbabilityTheory.kernel.iIndepFun`: independence of a family of functions (random variables). Variant for two functions: `ProbabilityTheory.kernel.IndepFun`. See the file `Mathlib/Probability/Kernel/Basic.lean` for a more detailed discussion of these definitions in the particular case of the usual independence notion. ## Main statements * `ProbabilityTheory.kernel.iIndepSets.iIndep`: if π-systems are independent as sets of sets, then the measurable space structures they generate are independent. * `ProbabilityTheory.kernel.IndepSets.Indep`: variant with two π-systems. -/ open MeasureTheory MeasurableSpace open scoped MeasureTheory ENNReal namespace ProbabilityTheory.kernel variable {α Ω ι : Type*} section Definitions variable {_mα : MeasurableSpace α} /-- A family of sets of sets `π : ι → Set (Set Ω)` is independent with respect to a kernel `κ` and a measure `μ` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ π i_1, ..., f i_n ∈ π i_n`, then `∀ᵐ a ∂μ, κ a (⋂ i in s, f i) = ∏ i ∈ s, κ a (f i)`. It will be used for families of pi_systems. -/ def iIndepSets {_mΩ : MeasurableSpace Ω} (π : ι → Set (Set Ω)) (κ : kernel α Ω) (μ : Measure α := by volume_tac) : Prop := ∀ (s : Finset ι) {f : ι → Set Ω} (_H : ∀ i, i ∈ s → f i ∈ π i), ∀ᵐ a ∂μ, κ a (⋂ i ∈ s, f i) = ∏ i ∈ s, κ a (f i) /-- Two sets of sets `s₁, s₂` are independent with respect to a kernel `κ` and a measure `μ` if for any sets `t₁ ∈ s₁, t₂ ∈ s₂`, then `∀ᵐ a ∂μ, κ a (t₁ ∩ t₂) = κ a (t₁) * κ a (t₂)` -/ def IndepSets {_mΩ : MeasurableSpace Ω} (s1 s2 : Set (Set Ω)) (κ : kernel α Ω) (μ : Measure α := by volume_tac) : Prop := ∀ t1 t2 : Set Ω, t1 ∈ s1 → t2 ∈ s2 → (∀ᵐ a ∂μ, κ a (t1 ∩ t2) = κ a t1 * κ a t2) /-- A family of measurable space structures (i.e. of σ-algebras) is independent with respect to a kernel `κ` and a measure `μ` if the family of sets of measurable sets they define is independent. -/ def iIndep (m : ι → MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (κ : kernel α Ω) (μ : Measure α := by volume_tac) : Prop := iIndepSets (fun x ↦ {s | MeasurableSet[m x] s}) κ μ /-- Two measurable space structures (or σ-algebras) `m₁, m₂` are independent with respect to a kernel `κ` and a measure `μ` if for any sets `t₁ ∈ m₁, t₂ ∈ m₂`, `∀ᵐ a ∂μ, κ a (t₁ ∩ t₂) = κ a (t₁) * κ a (t₂)` -/ def Indep (m₁ m₂ : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (κ : kernel α Ω) (μ : Measure α := by volume_tac) : Prop := IndepSets {s | MeasurableSet[m₁] s} {s | MeasurableSet[m₂] s} κ μ /-- A family of sets is independent if the family of measurable space structures they generate is independent. For a set `s`, the generated measurable space has measurable sets `∅, s, sᶜ, univ`. -/ def iIndepSet {_mΩ : MeasurableSpace Ω} (s : ι → Set Ω) (κ : kernel α Ω) (μ : Measure α := by volume_tac) : Prop := iIndep (fun i ↦ generateFrom {s i}) κ μ /-- Two sets are independent if the two measurable space structures they generate are independent. For a set `s`, the generated measurable space structure has measurable sets `∅, s, sᶜ, univ`. -/ def IndepSet {_mΩ : MeasurableSpace Ω} (s t : Set Ω) (κ : kernel α Ω) (μ : Measure α := by volume_tac) : Prop := Indep (generateFrom {s}) (generateFrom {t}) κ μ /-- A family of functions defined on the same space `Ω` and taking values in possibly different spaces, each with a measurable space structure, is independent if the family of measurable space structures they generate on `Ω` is independent. For a function `g` with codomain having measurable space structure `m`, the generated measurable space structure is `MeasurableSpace.comap g m`. -/ def iIndepFun {_mΩ : MeasurableSpace Ω} {β : ι → Type*} (m : ∀ x : ι, MeasurableSpace (β x)) (f : ∀ x : ι, Ω → β x) (κ : kernel α Ω) (μ : Measure α := by volume_tac) : Prop := iIndep (fun x ↦ MeasurableSpace.comap (f x) (m x)) κ μ /-- Two functions are independent if the two measurable space structures they generate are independent. For a function `f` with codomain having measurable space structure `m`, the generated measurable space structure is `MeasurableSpace.comap f m`. -/ def IndepFun {β γ} {_mΩ : MeasurableSpace Ω} [mβ : MeasurableSpace β] [mγ : MeasurableSpace γ] (f : Ω → β) (g : Ω → γ) (κ : kernel α Ω) (μ : Measure α := by volume_tac) : Prop := Indep (MeasurableSpace.comap f mβ) (MeasurableSpace.comap g mγ) κ μ end Definitions section ByDefinition variable {β : ι → Type*} {mβ : ∀ i, MeasurableSpace (β i)} {_mα : MeasurableSpace α} {m : ι → MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} {π : ι → Set (Set Ω)} {s : ι → Set Ω} {S : Finset ι} {f : ∀ x : ι, Ω → β x} lemma iIndepSets.meas_biInter (h : iIndepSets π κ μ) (s : Finset ι) {f : ι → Set Ω} (hf : ∀ i, i ∈ s → f i ∈ π i) : ∀ᵐ a ∂μ, κ a (⋂ i ∈ s, f i) = ∏ i ∈ s, κ a (f i) := h s hf lemma iIndepSets.meas_iInter [Fintype ι] (h : iIndepSets π κ μ) (hs : ∀ i, s i ∈ π i) : ∀ᵐ a ∂μ, κ a (⋂ i, s i) = ∏ i, κ a (s i) := by filter_upwards [h.meas_biInter Finset.univ (fun _i _ ↦ hs _)] with a ha using by simp [← ha] lemma iIndep.iIndepSets' (hμ : iIndep m κ μ) : iIndepSets (fun x ↦ {s | MeasurableSet[m x] s}) κ μ := hμ lemma iIndep.meas_biInter (hμ : iIndep m κ μ) (hs : ∀ i, i ∈ S → MeasurableSet[m i] (s i)) : ∀ᵐ a ∂μ, κ a (⋂ i ∈ S, s i) = ∏ i ∈ S, κ a (s i) := hμ _ hs lemma iIndep.meas_iInter [Fintype ι] (h : iIndep m κ μ) (hs : ∀ i, MeasurableSet[m i] (s i)) : ∀ᵐ a ∂μ, κ a (⋂ i, s i) = ∏ i, κ a (s i) := by filter_upwards [h.meas_biInter (fun i (_ : i ∈ Finset.univ) ↦ hs _)] with a ha simp [← ha] protected lemma iIndepFun.iIndep (hf : iIndepFun mβ f κ μ) : iIndep (fun x ↦ (mβ x).comap (f x)) κ μ := hf lemma iIndepFun.meas_biInter (hf : iIndepFun mβ f κ μ) (hs : ∀ i, i ∈ S → MeasurableSet[(mβ i).comap (f i)] (s i)) : ∀ᵐ a ∂μ, κ a (⋂ i ∈ S, s i) = ∏ i ∈ S, κ a (s i) := hf.iIndep.meas_biInter hs lemma iIndepFun.meas_iInter [Fintype ι] (hf : iIndepFun mβ f κ μ) (hs : ∀ i, MeasurableSet[(mβ i).comap (f i)] (s i)) : ∀ᵐ a ∂μ, κ a (⋂ i, s i) = ∏ i, κ a (s i) := hf.iIndep.meas_iInter hs lemma IndepFun.meas_inter {β γ : Type*} [mβ : MeasurableSpace β] [mγ : MeasurableSpace γ] {f : Ω → β} {g : Ω → γ} (hfg : IndepFun f g κ μ) {s t : Set Ω} (hs : MeasurableSet[mβ.comap f] s) (ht : MeasurableSet[mγ.comap g] t) : ∀ᵐ a ∂μ, κ a (s ∩ t) = κ a s * κ a t := hfg _ _ hs ht end ByDefinition section Indep variable {_mα : MeasurableSpace α} @[symm] theorem IndepSets.symm {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} {s₁ s₂ : Set (Set Ω)} (h : IndepSets s₁ s₂ κ μ) : IndepSets s₂ s₁ κ μ := by intros t1 t2 ht1 ht2 filter_upwards [h t2 t1 ht2 ht1] with a ha rwa [Set.inter_comm, mul_comm] @[symm] theorem Indep.symm {m₁ m₂ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} (h : Indep m₁ m₂ κ μ) : Indep m₂ m₁ κ μ := IndepSets.symm h theorem indep_bot_right (m' : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} [IsMarkovKernel κ] : Indep m' ⊥ κ μ := by intros s t _ ht rw [Set.mem_setOf_eq, MeasurableSpace.measurableSet_bot_iff] at ht refine Filter.eventually_of_forall (fun a ↦ ?_) cases' ht with ht ht · rw [ht, Set.inter_empty, measure_empty, mul_zero] · rw [ht, Set.inter_univ, measure_univ, mul_one] theorem indep_bot_left (m' : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} [IsMarkovKernel κ] : Indep ⊥ m' κ μ := (indep_bot_right m').symm theorem indepSet_empty_right {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} [IsMarkovKernel κ] (s : Set Ω) : IndepSet s ∅ κ μ := by simp only [IndepSet, generateFrom_singleton_empty]; exact indep_bot_right _ theorem indepSet_empty_left {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} [IsMarkovKernel κ] (s : Set Ω) : IndepSet ∅ s κ μ := (indepSet_empty_right s).symm theorem indepSets_of_indepSets_of_le_left {s₁ s₂ s₃ : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} (h_indep : IndepSets s₁ s₂ κ μ) (h31 : s₃ ⊆ s₁) : IndepSets s₃ s₂ κ μ := fun t1 t2 ht1 ht2 => h_indep t1 t2 (Set.mem_of_subset_of_mem h31 ht1) ht2 theorem indepSets_of_indepSets_of_le_right {s₁ s₂ s₃ : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} (h_indep : IndepSets s₁ s₂ κ μ) (h32 : s₃ ⊆ s₂) : IndepSets s₁ s₃ κ μ := fun t1 t2 ht1 ht2 => h_indep t1 t2 ht1 (Set.mem_of_subset_of_mem h32 ht2) theorem indep_of_indep_of_le_left {m₁ m₂ m₃ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} (h_indep : Indep m₁ m₂ κ μ) (h31 : m₃ ≤ m₁) : Indep m₃ m₂ κ μ := fun t1 t2 ht1 ht2 => h_indep t1 t2 (h31 _ ht1) ht2 theorem indep_of_indep_of_le_right {m₁ m₂ m₃ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} (h_indep : Indep m₁ m₂ κ μ) (h32 : m₃ ≤ m₂) : Indep m₁ m₃ κ μ := fun t1 t2 ht1 ht2 => h_indep t1 t2 ht1 (h32 _ ht2) theorem IndepSets.union {s₁ s₂ s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} (h₁ : IndepSets s₁ s' κ μ) (h₂ : IndepSets s₂ s' κ μ) : IndepSets (s₁ ∪ s₂) s' κ μ := by intro t1 t2 ht1 ht2 cases' (Set.mem_union _ _ _).mp ht1 with ht1₁ ht1₂ · exact h₁ t1 t2 ht1₁ ht2 · exact h₂ t1 t2 ht1₂ ht2 @[simp] theorem IndepSets.union_iff {s₁ s₂ s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} : IndepSets (s₁ ∪ s₂) s' κ μ ↔ IndepSets s₁ s' κ μ ∧ IndepSets s₂ s' κ μ := ⟨fun h => ⟨indepSets_of_indepSets_of_le_left h Set.subset_union_left, indepSets_of_indepSets_of_le_left h Set.subset_union_right⟩, fun h => IndepSets.union h.left h.right⟩ theorem IndepSets.iUnion {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} (hyp : ∀ n, IndepSets (s n) s' κ μ) : IndepSets (⋃ n, s n) s' κ μ := by intro t1 t2 ht1 ht2 rw [Set.mem_iUnion] at ht1 cases' ht1 with n ht1 exact hyp n t1 t2 ht1 ht2
Mathlib/Probability/Independence/Kernel.lean
250
256
theorem IndepSets.bUnion {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} {u : Set ι} (hyp : ∀ n ∈ u, IndepSets (s n) s' κ μ) : IndepSets (⋃ n ∈ u, s n) s' κ μ := by
intro t1 t2 ht1 ht2 simp_rw [Set.mem_iUnion] at ht1 rcases ht1 with ⟨n, hpn, ht1⟩ exact hyp n hpn t1 t2 ht1 ht2
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot -/ import Mathlib.Topology.Maps import Mathlib.Topology.NhdsSet #align_import topology.constructions from "leanprover-community/mathlib"@"f7ebde7ee0d1505dfccac8644ae12371aa3c1c9f" /-! # Constructions of new topological spaces from old ones This file constructs products, sums, subtypes and quotients of topological spaces and sets up their basic theory, such as criteria for maps into or out of these constructions to be continuous; descriptions of the open sets, neighborhood filters, and generators of these constructions; and their behavior with respect to embeddings and other specific classes of maps. ## Implementation note The constructed topologies are defined using induced and coinduced topologies along with the complete lattice structure on topologies. Their universal properties (for example, a map `X → Y × Z` is continuous if and only if both projections `X → Y`, `X → Z` are) follow easily using order-theoretic descriptions of continuity. With more work we can also extract descriptions of the open sets, neighborhood filters and so on. ## Tags product, sum, disjoint union, subspace, quotient space -/ noncomputable section open scoped Classical open Topology TopologicalSpace Set Filter Function universe u v variable {X : Type u} {Y : Type v} {Z W ε ζ : Type*} section Constructions instance instTopologicalSpaceSubtype {p : X → Prop} [t : TopologicalSpace X] : TopologicalSpace (Subtype p) := induced (↑) t instance {r : X → X → Prop} [t : TopologicalSpace X] : TopologicalSpace (Quot r) := coinduced (Quot.mk r) t instance instTopologicalSpaceQuotient {s : Setoid X} [t : TopologicalSpace X] : TopologicalSpace (Quotient s) := coinduced Quotient.mk' t instance instTopologicalSpaceProd [t₁ : TopologicalSpace X] [t₂ : TopologicalSpace Y] : TopologicalSpace (X × Y) := induced Prod.fst t₁ ⊓ induced Prod.snd t₂ instance instTopologicalSpaceSum [t₁ : TopologicalSpace X] [t₂ : TopologicalSpace Y] : TopologicalSpace (X ⊕ Y) := coinduced Sum.inl t₁ ⊔ coinduced Sum.inr t₂ instance instTopologicalSpaceSigma {ι : Type*} {X : ι → Type v} [t₂ : ∀ i, TopologicalSpace (X i)] : TopologicalSpace (Sigma X) := ⨆ i, coinduced (Sigma.mk i) (t₂ i) instance Pi.topologicalSpace {ι : Type*} {Y : ι → Type v} [t₂ : (i : ι) → TopologicalSpace (Y i)] : TopologicalSpace ((i : ι) → Y i) := ⨅ i, induced (fun f => f i) (t₂ i) #align Pi.topological_space Pi.topologicalSpace instance ULift.topologicalSpace [t : TopologicalSpace X] : TopologicalSpace (ULift.{v, u} X) := t.induced ULift.down #align ulift.topological_space ULift.topologicalSpace /-! ### `Additive`, `Multiplicative` The topology on those type synonyms is inherited without change. -/ section variable [TopologicalSpace X] open Additive Multiplicative instance : TopologicalSpace (Additive X) := ‹TopologicalSpace X› instance : TopologicalSpace (Multiplicative X) := ‹TopologicalSpace X› instance [DiscreteTopology X] : DiscreteTopology (Additive X) := ‹DiscreteTopology X› instance [DiscreteTopology X] : DiscreteTopology (Multiplicative X) := ‹DiscreteTopology X› theorem continuous_ofMul : Continuous (ofMul : X → Additive X) := continuous_id #align continuous_of_mul continuous_ofMul theorem continuous_toMul : Continuous (toMul : Additive X → X) := continuous_id #align continuous_to_mul continuous_toMul theorem continuous_ofAdd : Continuous (ofAdd : X → Multiplicative X) := continuous_id #align continuous_of_add continuous_ofAdd theorem continuous_toAdd : Continuous (toAdd : Multiplicative X → X) := continuous_id #align continuous_to_add continuous_toAdd theorem isOpenMap_ofMul : IsOpenMap (ofMul : X → Additive X) := IsOpenMap.id #align is_open_map_of_mul isOpenMap_ofMul theorem isOpenMap_toMul : IsOpenMap (toMul : Additive X → X) := IsOpenMap.id #align is_open_map_to_mul isOpenMap_toMul theorem isOpenMap_ofAdd : IsOpenMap (ofAdd : X → Multiplicative X) := IsOpenMap.id #align is_open_map_of_add isOpenMap_ofAdd theorem isOpenMap_toAdd : IsOpenMap (toAdd : Multiplicative X → X) := IsOpenMap.id #align is_open_map_to_add isOpenMap_toAdd theorem isClosedMap_ofMul : IsClosedMap (ofMul : X → Additive X) := IsClosedMap.id #align is_closed_map_of_mul isClosedMap_ofMul theorem isClosedMap_toMul : IsClosedMap (toMul : Additive X → X) := IsClosedMap.id #align is_closed_map_to_mul isClosedMap_toMul theorem isClosedMap_ofAdd : IsClosedMap (ofAdd : X → Multiplicative X) := IsClosedMap.id #align is_closed_map_of_add isClosedMap_ofAdd theorem isClosedMap_toAdd : IsClosedMap (toAdd : Multiplicative X → X) := IsClosedMap.id #align is_closed_map_to_add isClosedMap_toAdd theorem nhds_ofMul (x : X) : 𝓝 (ofMul x) = map ofMul (𝓝 x) := rfl #align nhds_of_mul nhds_ofMul theorem nhds_ofAdd (x : X) : 𝓝 (ofAdd x) = map ofAdd (𝓝 x) := rfl #align nhds_of_add nhds_ofAdd theorem nhds_toMul (x : Additive X) : 𝓝 (toMul x) = map toMul (𝓝 x) := rfl #align nhds_to_mul nhds_toMul theorem nhds_toAdd (x : Multiplicative X) : 𝓝 (toAdd x) = map toAdd (𝓝 x) := rfl #align nhds_to_add nhds_toAdd end /-! ### Order dual The topology on this type synonym is inherited without change. -/ section variable [TopologicalSpace X] open OrderDual instance : TopologicalSpace Xᵒᵈ := ‹TopologicalSpace X› instance [DiscreteTopology X] : DiscreteTopology Xᵒᵈ := ‹DiscreteTopology X› theorem continuous_toDual : Continuous (toDual : X → Xᵒᵈ) := continuous_id #align continuous_to_dual continuous_toDual theorem continuous_ofDual : Continuous (ofDual : Xᵒᵈ → X) := continuous_id #align continuous_of_dual continuous_ofDual theorem isOpenMap_toDual : IsOpenMap (toDual : X → Xᵒᵈ) := IsOpenMap.id #align is_open_map_to_dual isOpenMap_toDual theorem isOpenMap_ofDual : IsOpenMap (ofDual : Xᵒᵈ → X) := IsOpenMap.id #align is_open_map_of_dual isOpenMap_ofDual theorem isClosedMap_toDual : IsClosedMap (toDual : X → Xᵒᵈ) := IsClosedMap.id #align is_closed_map_to_dual isClosedMap_toDual theorem isClosedMap_ofDual : IsClosedMap (ofDual : Xᵒᵈ → X) := IsClosedMap.id #align is_closed_map_of_dual isClosedMap_ofDual theorem nhds_toDual (x : X) : 𝓝 (toDual x) = map toDual (𝓝 x) := rfl #align nhds_to_dual nhds_toDual theorem nhds_ofDual (x : X) : 𝓝 (ofDual x) = map ofDual (𝓝 x) := rfl #align nhds_of_dual nhds_ofDual end theorem Quotient.preimage_mem_nhds [TopologicalSpace X] [s : Setoid X] {V : Set <| Quotient s} {x : X} (hs : V ∈ 𝓝 (Quotient.mk' x)) : Quotient.mk' ⁻¹' V ∈ 𝓝 x := preimage_nhds_coinduced hs #align quotient.preimage_mem_nhds Quotient.preimage_mem_nhds /-- The image of a dense set under `Quotient.mk'` is a dense set. -/ theorem Dense.quotient [Setoid X] [TopologicalSpace X] {s : Set X} (H : Dense s) : Dense (Quotient.mk' '' s) := Quotient.surjective_Quotient_mk''.denseRange.dense_image continuous_coinduced_rng H #align dense.quotient Dense.quotient /-- The composition of `Quotient.mk'` and a function with dense range has dense range. -/ theorem DenseRange.quotient [Setoid X] [TopologicalSpace X] {f : Y → X} (hf : DenseRange f) : DenseRange (Quotient.mk' ∘ f) := Quotient.surjective_Quotient_mk''.denseRange.comp hf continuous_coinduced_rng #align dense_range.quotient DenseRange.quotient theorem continuous_map_of_le {α : Type*} [TopologicalSpace α] {s t : Setoid α} (h : s ≤ t) : Continuous (Setoid.map_of_le h) := continuous_coinduced_rng theorem continuous_map_sInf {α : Type*} [TopologicalSpace α] {S : Set (Setoid α)} {s : Setoid α} (h : s ∈ S) : Continuous (Setoid.map_sInf h) := continuous_coinduced_rng instance {p : X → Prop} [TopologicalSpace X] [DiscreteTopology X] : DiscreteTopology (Subtype p) := ⟨bot_unique fun s _ => ⟨(↑) '' s, isOpen_discrete _, preimage_image_eq _ Subtype.val_injective⟩⟩ instance Sum.discreteTopology [TopologicalSpace X] [TopologicalSpace Y] [h : DiscreteTopology X] [hY : DiscreteTopology Y] : DiscreteTopology (X ⊕ Y) := ⟨sup_eq_bot_iff.2 <| by simp [h.eq_bot, hY.eq_bot]⟩ #align sum.discrete_topology Sum.discreteTopology instance Sigma.discreteTopology {ι : Type*} {Y : ι → Type v} [∀ i, TopologicalSpace (Y i)] [h : ∀ i, DiscreteTopology (Y i)] : DiscreteTopology (Sigma Y) := ⟨iSup_eq_bot.2 fun _ => by simp only [(h _).eq_bot, coinduced_bot]⟩ #align sigma.discrete_topology Sigma.discreteTopology section Top variable [TopologicalSpace X] /- The 𝓝 filter and the subspace topology. -/ theorem mem_nhds_subtype (s : Set X) (x : { x // x ∈ s }) (t : Set { x // x ∈ s }) : t ∈ 𝓝 x ↔ ∃ u ∈ 𝓝 (x : X), Subtype.val ⁻¹' u ⊆ t := mem_nhds_induced _ x t #align mem_nhds_subtype mem_nhds_subtype theorem nhds_subtype (s : Set X) (x : { x // x ∈ s }) : 𝓝 x = comap (↑) (𝓝 (x : X)) := nhds_induced _ x #align nhds_subtype nhds_subtype theorem nhdsWithin_subtype_eq_bot_iff {s t : Set X} {x : s} : 𝓝[((↑) : s → X) ⁻¹' t] x = ⊥ ↔ 𝓝[t] (x : X) ⊓ 𝓟 s = ⊥ := by rw [inf_principal_eq_bot_iff_comap, nhdsWithin, nhdsWithin, comap_inf, comap_principal, nhds_induced] #align nhds_within_subtype_eq_bot_iff nhdsWithin_subtype_eq_bot_iff theorem nhds_ne_subtype_eq_bot_iff {S : Set X} {x : S} : 𝓝[≠] x = ⊥ ↔ 𝓝[≠] (x : X) ⊓ 𝓟 S = ⊥ := by rw [← nhdsWithin_subtype_eq_bot_iff, preimage_compl, ← image_singleton, Subtype.coe_injective.preimage_image] #align nhds_ne_subtype_eq_bot_iff nhds_ne_subtype_eq_bot_iff theorem nhds_ne_subtype_neBot_iff {S : Set X} {x : S} : (𝓝[≠] x).NeBot ↔ (𝓝[≠] (x : X) ⊓ 𝓟 S).NeBot := by rw [neBot_iff, neBot_iff, not_iff_not, nhds_ne_subtype_eq_bot_iff] #align nhds_ne_subtype_ne_bot_iff nhds_ne_subtype_neBot_iff theorem discreteTopology_subtype_iff {S : Set X} : DiscreteTopology S ↔ ∀ x ∈ S, 𝓝[≠] x ⊓ 𝓟 S = ⊥ := by simp_rw [discreteTopology_iff_nhds_ne, SetCoe.forall', nhds_ne_subtype_eq_bot_iff] #align discrete_topology_subtype_iff discreteTopology_subtype_iff end Top /-- A type synonym equipped with the topology whose open sets are the empty set and the sets with finite complements. -/ def CofiniteTopology (X : Type*) := X #align cofinite_topology CofiniteTopology namespace CofiniteTopology /-- The identity equivalence between `` and `CofiniteTopology `. -/ def of : X ≃ CofiniteTopology X := Equiv.refl X #align cofinite_topology.of CofiniteTopology.of instance [Inhabited X] : Inhabited (CofiniteTopology X) where default := of default instance : TopologicalSpace (CofiniteTopology X) where IsOpen s := s.Nonempty → Set.Finite sᶜ isOpen_univ := by simp isOpen_inter s t := by rintro hs ht ⟨x, hxs, hxt⟩ rw [compl_inter] exact (hs ⟨x, hxs⟩).union (ht ⟨x, hxt⟩) isOpen_sUnion := by rintro s h ⟨x, t, hts, hzt⟩ rw [compl_sUnion] exact Finite.sInter (mem_image_of_mem _ hts) (h t hts ⟨x, hzt⟩) theorem isOpen_iff {s : Set (CofiniteTopology X)} : IsOpen s ↔ s.Nonempty → sᶜ.Finite := Iff.rfl #align cofinite_topology.is_open_iff CofiniteTopology.isOpen_iff theorem isOpen_iff' {s : Set (CofiniteTopology X)} : IsOpen s ↔ s = ∅ ∨ sᶜ.Finite := by simp only [isOpen_iff, nonempty_iff_ne_empty, or_iff_not_imp_left] #align cofinite_topology.is_open_iff' CofiniteTopology.isOpen_iff' theorem isClosed_iff {s : Set (CofiniteTopology X)} : IsClosed s ↔ s = univ ∨ s.Finite := by simp only [← isOpen_compl_iff, isOpen_iff', compl_compl, compl_empty_iff] #align cofinite_topology.is_closed_iff CofiniteTopology.isClosed_iff theorem nhds_eq (x : CofiniteTopology X) : 𝓝 x = pure x ⊔ cofinite := by ext U rw [mem_nhds_iff] constructor · rintro ⟨V, hVU, V_op, haV⟩ exact mem_sup.mpr ⟨hVU haV, mem_of_superset (V_op ⟨_, haV⟩) hVU⟩ · rintro ⟨hU : x ∈ U, hU' : Uᶜ.Finite⟩ exact ⟨U, Subset.rfl, fun _ => hU', hU⟩ #align cofinite_topology.nhds_eq CofiniteTopology.nhds_eq theorem mem_nhds_iff {x : CofiniteTopology X} {s : Set (CofiniteTopology X)} : s ∈ 𝓝 x ↔ x ∈ s ∧ sᶜ.Finite := by simp [nhds_eq] #align cofinite_topology.mem_nhds_iff CofiniteTopology.mem_nhds_iff end CofiniteTopology end Constructions section Prod variable [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z] [TopologicalSpace W] [TopologicalSpace ε] [TopologicalSpace ζ] -- Porting note (#11215): TODO: Lean 4 fails to deduce implicit args @[simp] theorem continuous_prod_mk {f : X → Y} {g : X → Z} : (Continuous fun x => (f x, g x)) ↔ Continuous f ∧ Continuous g := (@continuous_inf_rng X (Y × Z) _ _ (TopologicalSpace.induced Prod.fst _) (TopologicalSpace.induced Prod.snd _)).trans <| continuous_induced_rng.and continuous_induced_rng #align continuous_prod_mk continuous_prod_mk @[continuity] theorem continuous_fst : Continuous (@Prod.fst X Y) := (continuous_prod_mk.1 continuous_id).1 #align continuous_fst continuous_fst /-- Postcomposing `f` with `Prod.fst` is continuous -/ @[fun_prop] theorem Continuous.fst {f : X → Y × Z} (hf : Continuous f) : Continuous fun x : X => (f x).1 := continuous_fst.comp hf #align continuous.fst Continuous.fst /-- Precomposing `f` with `Prod.fst` is continuous -/ theorem Continuous.fst' {f : X → Z} (hf : Continuous f) : Continuous fun x : X × Y => f x.fst := hf.comp continuous_fst #align continuous.fst' Continuous.fst' theorem continuousAt_fst {p : X × Y} : ContinuousAt Prod.fst p := continuous_fst.continuousAt #align continuous_at_fst continuousAt_fst /-- Postcomposing `f` with `Prod.fst` is continuous at `x` -/ @[fun_prop] theorem ContinuousAt.fst {f : X → Y × Z} {x : X} (hf : ContinuousAt f x) : ContinuousAt (fun x : X => (f x).1) x := continuousAt_fst.comp hf #align continuous_at.fst ContinuousAt.fst /-- Precomposing `f` with `Prod.fst` is continuous at `(x, y)` -/ theorem ContinuousAt.fst' {f : X → Z} {x : X} {y : Y} (hf : ContinuousAt f x) : ContinuousAt (fun x : X × Y => f x.fst) (x, y) := ContinuousAt.comp hf continuousAt_fst #align continuous_at.fst' ContinuousAt.fst' /-- Precomposing `f` with `Prod.fst` is continuous at `x : X × Y` -/ theorem ContinuousAt.fst'' {f : X → Z} {x : X × Y} (hf : ContinuousAt f x.fst) : ContinuousAt (fun x : X × Y => f x.fst) x := hf.comp continuousAt_fst #align continuous_at.fst'' ContinuousAt.fst'' theorem Filter.Tendsto.fst_nhds {l : Filter X} {f : X → Y × Z} {p : Y × Z} (h : Tendsto f l (𝓝 p)) : Tendsto (fun a ↦ (f a).1) l (𝓝 <| p.1) := continuousAt_fst.tendsto.comp h @[continuity] theorem continuous_snd : Continuous (@Prod.snd X Y) := (continuous_prod_mk.1 continuous_id).2 #align continuous_snd continuous_snd /-- Postcomposing `f` with `Prod.snd` is continuous -/ @[fun_prop] theorem Continuous.snd {f : X → Y × Z} (hf : Continuous f) : Continuous fun x : X => (f x).2 := continuous_snd.comp hf #align continuous.snd Continuous.snd /-- Precomposing `f` with `Prod.snd` is continuous -/ theorem Continuous.snd' {f : Y → Z} (hf : Continuous f) : Continuous fun x : X × Y => f x.snd := hf.comp continuous_snd #align continuous.snd' Continuous.snd' theorem continuousAt_snd {p : X × Y} : ContinuousAt Prod.snd p := continuous_snd.continuousAt #align continuous_at_snd continuousAt_snd /-- Postcomposing `f` with `Prod.snd` is continuous at `x` -/ @[fun_prop] theorem ContinuousAt.snd {f : X → Y × Z} {x : X} (hf : ContinuousAt f x) : ContinuousAt (fun x : X => (f x).2) x := continuousAt_snd.comp hf #align continuous_at.snd ContinuousAt.snd /-- Precomposing `f` with `Prod.snd` is continuous at `(x, y)` -/ theorem ContinuousAt.snd' {f : Y → Z} {x : X} {y : Y} (hf : ContinuousAt f y) : ContinuousAt (fun x : X × Y => f x.snd) (x, y) := ContinuousAt.comp hf continuousAt_snd #align continuous_at.snd' ContinuousAt.snd' /-- Precomposing `f` with `Prod.snd` is continuous at `x : X × Y` -/ theorem ContinuousAt.snd'' {f : Y → Z} {x : X × Y} (hf : ContinuousAt f x.snd) : ContinuousAt (fun x : X × Y => f x.snd) x := hf.comp continuousAt_snd #align continuous_at.snd'' ContinuousAt.snd'' theorem Filter.Tendsto.snd_nhds {l : Filter X} {f : X → Y × Z} {p : Y × Z} (h : Tendsto f l (𝓝 p)) : Tendsto (fun a ↦ (f a).2) l (𝓝 <| p.2) := continuousAt_snd.tendsto.comp h @[continuity, fun_prop] theorem Continuous.prod_mk {f : Z → X} {g : Z → Y} (hf : Continuous f) (hg : Continuous g) : Continuous fun x => (f x, g x) := continuous_prod_mk.2 ⟨hf, hg⟩ #align continuous.prod_mk Continuous.prod_mk @[continuity] theorem Continuous.Prod.mk (x : X) : Continuous fun y : Y => (x, y) := continuous_const.prod_mk continuous_id #align continuous.prod.mk Continuous.Prod.mk @[continuity] theorem Continuous.Prod.mk_left (y : Y) : Continuous fun x : X => (x, y) := continuous_id.prod_mk continuous_const #align continuous.prod.mk_left Continuous.Prod.mk_left /-- If `f x y` is continuous in `x` for all `y ∈ s`, then the set of `x` such that `f x` maps `s` to `t` is closed. -/ lemma IsClosed.setOf_mapsTo {α : Type*} {f : X → α → Z} {s : Set α} {t : Set Z} (ht : IsClosed t) (hf : ∀ a ∈ s, Continuous (f · a)) : IsClosed {x | MapsTo (f x) s t} := by simpa only [MapsTo, setOf_forall] using isClosed_biInter fun y hy ↦ ht.preimage (hf y hy) theorem Continuous.comp₂ {g : X × Y → Z} (hg : Continuous g) {e : W → X} (he : Continuous e) {f : W → Y} (hf : Continuous f) : Continuous fun w => g (e w, f w) := hg.comp <| he.prod_mk hf #align continuous.comp₂ Continuous.comp₂ theorem Continuous.comp₃ {g : X × Y × Z → ε} (hg : Continuous g) {e : W → X} (he : Continuous e) {f : W → Y} (hf : Continuous f) {k : W → Z} (hk : Continuous k) : Continuous fun w => g (e w, f w, k w) := hg.comp₂ he <| hf.prod_mk hk #align continuous.comp₃ Continuous.comp₃ theorem Continuous.comp₄ {g : X × Y × Z × ζ → ε} (hg : Continuous g) {e : W → X} (he : Continuous e) {f : W → Y} (hf : Continuous f) {k : W → Z} (hk : Continuous k) {l : W → ζ} (hl : Continuous l) : Continuous fun w => g (e w, f w, k w, l w) := hg.comp₃ he hf <| hk.prod_mk hl #align continuous.comp₄ Continuous.comp₄ @[continuity] theorem Continuous.prod_map {f : Z → X} {g : W → Y} (hf : Continuous f) (hg : Continuous g) : Continuous fun p : Z × W => (f p.1, g p.2) := hf.fst'.prod_mk hg.snd' #align continuous.prod_map Continuous.prod_map /-- A version of `continuous_inf_dom_left` for binary functions -/ theorem continuous_inf_dom_left₂ {X Y Z} {f : X → Y → Z} {ta1 ta2 : TopologicalSpace X} {tb1 tb2 : TopologicalSpace Y} {tc1 : TopologicalSpace Z} (h : by haveI := ta1; haveI := tb1; exact Continuous fun p : X × Y => f p.1 p.2) : by haveI := ta1 ⊓ ta2; haveI := tb1 ⊓ tb2; exact Continuous fun p : X × Y => f p.1 p.2 := by have ha := @continuous_inf_dom_left _ _ id ta1 ta2 ta1 (@continuous_id _ (id _)) have hb := @continuous_inf_dom_left _ _ id tb1 tb2 tb1 (@continuous_id _ (id _)) have h_continuous_id := @Continuous.prod_map _ _ _ _ ta1 tb1 (ta1 ⊓ ta2) (tb1 ⊓ tb2) _ _ ha hb exact @Continuous.comp _ _ _ (id _) (id _) _ _ _ h h_continuous_id #align continuous_inf_dom_left₂ continuous_inf_dom_left₂ /-- A version of `continuous_inf_dom_right` for binary functions -/ theorem continuous_inf_dom_right₂ {X Y Z} {f : X → Y → Z} {ta1 ta2 : TopologicalSpace X} {tb1 tb2 : TopologicalSpace Y} {tc1 : TopologicalSpace Z} (h : by haveI := ta2; haveI := tb2; exact Continuous fun p : X × Y => f p.1 p.2) : by haveI := ta1 ⊓ ta2; haveI := tb1 ⊓ tb2; exact Continuous fun p : X × Y => f p.1 p.2 := by have ha := @continuous_inf_dom_right _ _ id ta1 ta2 ta2 (@continuous_id _ (id _)) have hb := @continuous_inf_dom_right _ _ id tb1 tb2 tb2 (@continuous_id _ (id _)) have h_continuous_id := @Continuous.prod_map _ _ _ _ ta2 tb2 (ta1 ⊓ ta2) (tb1 ⊓ tb2) _ _ ha hb exact @Continuous.comp _ _ _ (id _) (id _) _ _ _ h h_continuous_id #align continuous_inf_dom_right₂ continuous_inf_dom_right₂ /-- A version of `continuous_sInf_dom` for binary functions -/ theorem continuous_sInf_dom₂ {X Y Z} {f : X → Y → Z} {tas : Set (TopologicalSpace X)} {tbs : Set (TopologicalSpace Y)} {tX : TopologicalSpace X} {tY : TopologicalSpace Y} {tc : TopologicalSpace Z} (hX : tX ∈ tas) (hY : tY ∈ tbs) (hf : Continuous fun p : X × Y => f p.1 p.2) : by haveI := sInf tas; haveI := sInf tbs; exact @Continuous _ _ _ tc fun p : X × Y => f p.1 p.2 := by have hX := continuous_sInf_dom hX continuous_id have hY := continuous_sInf_dom hY continuous_id have h_continuous_id := @Continuous.prod_map _ _ _ _ tX tY (sInf tas) (sInf tbs) _ _ hX hY exact @Continuous.comp _ _ _ (id _) (id _) _ _ _ hf h_continuous_id #align continuous_Inf_dom₂ continuous_sInf_dom₂ theorem Filter.Eventually.prod_inl_nhds {p : X → Prop} {x : X} (h : ∀ᶠ x in 𝓝 x, p x) (y : Y) : ∀ᶠ x in 𝓝 (x, y), p (x : X × Y).1 := continuousAt_fst h #align filter.eventually.prod_inl_nhds Filter.Eventually.prod_inl_nhds theorem Filter.Eventually.prod_inr_nhds {p : Y → Prop} {y : Y} (h : ∀ᶠ x in 𝓝 y, p x) (x : X) : ∀ᶠ x in 𝓝 (x, y), p (x : X × Y).2 := continuousAt_snd h #align filter.eventually.prod_inr_nhds Filter.Eventually.prod_inr_nhds theorem Filter.Eventually.prod_mk_nhds {px : X → Prop} {x} (hx : ∀ᶠ x in 𝓝 x, px x) {py : Y → Prop} {y} (hy : ∀ᶠ y in 𝓝 y, py y) : ∀ᶠ p in 𝓝 (x, y), px (p : X × Y).1 ∧ py p.2 := (hx.prod_inl_nhds y).and (hy.prod_inr_nhds x) #align filter.eventually.prod_mk_nhds Filter.Eventually.prod_mk_nhds theorem continuous_swap : Continuous (Prod.swap : X × Y → Y × X) := continuous_snd.prod_mk continuous_fst #align continuous_swap continuous_swap lemma isClosedMap_swap : IsClosedMap (Prod.swap : X × Y → Y × X) := fun s hs ↦ by rw [image_swap_eq_preimage_swap] exact hs.preimage continuous_swap theorem Continuous.uncurry_left {f : X → Y → Z} (x : X) (h : Continuous (uncurry f)) : Continuous (f x) := h.comp (Continuous.Prod.mk _) #align continuous_uncurry_left Continuous.uncurry_left theorem Continuous.uncurry_right {f : X → Y → Z} (y : Y) (h : Continuous (uncurry f)) : Continuous fun a => f a y := h.comp (Continuous.Prod.mk_left _) #align continuous_uncurry_right Continuous.uncurry_right -- 2024-03-09 @[deprecated] alias continuous_uncurry_left := Continuous.uncurry_left @[deprecated] alias continuous_uncurry_right := Continuous.uncurry_right theorem continuous_curry {g : X × Y → Z} (x : X) (h : Continuous g) : Continuous (curry g x) := Continuous.uncurry_left x h #align continuous_curry continuous_curry theorem IsOpen.prod {s : Set X} {t : Set Y} (hs : IsOpen s) (ht : IsOpen t) : IsOpen (s ×ˢ t) := (hs.preimage continuous_fst).inter (ht.preimage continuous_snd) #align is_open.prod IsOpen.prod -- Porting note (#11215): TODO: Lean fails to find `t₁` and `t₂` by unification theorem nhds_prod_eq {x : X} {y : Y} : 𝓝 (x, y) = 𝓝 x ×ˢ 𝓝 y := by dsimp only [SProd.sprod] rw [Filter.prod, instTopologicalSpaceProd, nhds_inf (t₁ := TopologicalSpace.induced Prod.fst _) (t₂ := TopologicalSpace.induced Prod.snd _), nhds_induced, nhds_induced] #align nhds_prod_eq nhds_prod_eq -- Porting note: moved from `Topology.ContinuousOn` theorem nhdsWithin_prod_eq (x : X) (y : Y) (s : Set X) (t : Set Y) : 𝓝[s ×ˢ t] (x, y) = 𝓝[s] x ×ˢ 𝓝[t] y := by simp only [nhdsWithin, nhds_prod_eq, ← prod_inf_prod, prod_principal_principal] #align nhds_within_prod_eq nhdsWithin_prod_eq #noalign continuous_uncurry_of_discrete_topology theorem mem_nhds_prod_iff {x : X} {y : Y} {s : Set (X × Y)} : s ∈ 𝓝 (x, y) ↔ ∃ u ∈ 𝓝 x, ∃ v ∈ 𝓝 y, u ×ˢ v ⊆ s := by rw [nhds_prod_eq, mem_prod_iff] #align mem_nhds_prod_iff mem_nhds_prod_iff theorem mem_nhdsWithin_prod_iff {x : X} {y : Y} {s : Set (X × Y)} {tx : Set X} {ty : Set Y} : s ∈ 𝓝[tx ×ˢ ty] (x, y) ↔ ∃ u ∈ 𝓝[tx] x, ∃ v ∈ 𝓝[ty] y, u ×ˢ v ⊆ s := by rw [nhdsWithin_prod_eq, mem_prod_iff] -- Porting note: moved up theorem Filter.HasBasis.prod_nhds {ιX ιY : Type*} {px : ιX → Prop} {py : ιY → Prop} {sx : ιX → Set X} {sy : ιY → Set Y} {x : X} {y : Y} (hx : (𝓝 x).HasBasis px sx) (hy : (𝓝 y).HasBasis py sy) : (𝓝 (x, y)).HasBasis (fun i : ιX × ιY => px i.1 ∧ py i.2) fun i => sx i.1 ×ˢ sy i.2 := by rw [nhds_prod_eq] exact hx.prod hy #align filter.has_basis.prod_nhds Filter.HasBasis.prod_nhds -- Porting note: moved up theorem Filter.HasBasis.prod_nhds' {ιX ιY : Type*} {pX : ιX → Prop} {pY : ιY → Prop} {sx : ιX → Set X} {sy : ιY → Set Y} {p : X × Y} (hx : (𝓝 p.1).HasBasis pX sx) (hy : (𝓝 p.2).HasBasis pY sy) : (𝓝 p).HasBasis (fun i : ιX × ιY => pX i.1 ∧ pY i.2) fun i => sx i.1 ×ˢ sy i.2 := hx.prod_nhds hy #align filter.has_basis.prod_nhds' Filter.HasBasis.prod_nhds' theorem mem_nhds_prod_iff' {x : X} {y : Y} {s : Set (X × Y)} : s ∈ 𝓝 (x, y) ↔ ∃ u v, IsOpen u ∧ x ∈ u ∧ IsOpen v ∧ y ∈ v ∧ u ×ˢ v ⊆ s := ((nhds_basis_opens x).prod_nhds (nhds_basis_opens y)).mem_iff.trans <| by simp only [Prod.exists, and_comm, and_assoc, and_left_comm] #align mem_nhds_prod_iff' mem_nhds_prod_iff' theorem Prod.tendsto_iff {X} (seq : X → Y × Z) {f : Filter X} (p : Y × Z) : Tendsto seq f (𝓝 p) ↔ Tendsto (fun n => (seq n).fst) f (𝓝 p.fst) ∧ Tendsto (fun n => (seq n).snd) f (𝓝 p.snd) := by rw [nhds_prod_eq, Filter.tendsto_prod_iff'] #align prod.tendsto_iff Prod.tendsto_iff instance [DiscreteTopology X] [DiscreteTopology Y] : DiscreteTopology (X × Y) := discreteTopology_iff_nhds.2 fun (a, b) => by rw [nhds_prod_eq, nhds_discrete X, nhds_discrete Y, prod_pure_pure] theorem prod_mem_nhds_iff {s : Set X} {t : Set Y} {x : X} {y : Y} : s ×ˢ t ∈ 𝓝 (x, y) ↔ s ∈ 𝓝 x ∧ t ∈ 𝓝 y := by rw [nhds_prod_eq, prod_mem_prod_iff] #align prod_mem_nhds_iff prod_mem_nhds_iff theorem prod_mem_nhds {s : Set X} {t : Set Y} {x : X} {y : Y} (hx : s ∈ 𝓝 x) (hy : t ∈ 𝓝 y) : s ×ˢ t ∈ 𝓝 (x, y) := prod_mem_nhds_iff.2 ⟨hx, hy⟩ #align prod_mem_nhds prod_mem_nhds theorem isOpen_setOf_disjoint_nhds_nhds : IsOpen { p : X × X | Disjoint (𝓝 p.1) (𝓝 p.2) } := by simp only [isOpen_iff_mem_nhds, Prod.forall, mem_setOf_eq] intro x y h obtain ⟨U, hU, V, hV, hd⟩ := ((nhds_basis_opens x).disjoint_iff (nhds_basis_opens y)).mp h exact mem_nhds_prod_iff'.mpr ⟨U, V, hU.2, hU.1, hV.2, hV.1, fun ⟨x', y'⟩ ⟨hx', hy'⟩ => disjoint_of_disjoint_of_mem hd (hU.2.mem_nhds hx') (hV.2.mem_nhds hy')⟩ #align is_open_set_of_disjoint_nhds_nhds isOpen_setOf_disjoint_nhds_nhds theorem Filter.Eventually.prod_nhds {p : X → Prop} {q : Y → Prop} {x : X} {y : Y} (hx : ∀ᶠ x in 𝓝 x, p x) (hy : ∀ᶠ y in 𝓝 y, q y) : ∀ᶠ z : X × Y in 𝓝 (x, y), p z.1 ∧ q z.2 := prod_mem_nhds hx hy #align filter.eventually.prod_nhds Filter.Eventually.prod_nhds theorem nhds_swap (x : X) (y : Y) : 𝓝 (x, y) = (𝓝 (y, x)).map Prod.swap := by rw [nhds_prod_eq, Filter.prod_comm, nhds_prod_eq]; rfl #align nhds_swap nhds_swap theorem Filter.Tendsto.prod_mk_nhds {γ} {x : X} {y : Y} {f : Filter γ} {mx : γ → X} {my : γ → Y} (hx : Tendsto mx f (𝓝 x)) (hy : Tendsto my f (𝓝 y)) : Tendsto (fun c => (mx c, my c)) f (𝓝 (x, y)) := by rw [nhds_prod_eq]; exact Filter.Tendsto.prod_mk hx hy #align filter.tendsto.prod_mk_nhds Filter.Tendsto.prod_mk_nhds theorem Filter.Eventually.curry_nhds {p : X × Y → Prop} {x : X} {y : Y} (h : ∀ᶠ x in 𝓝 (x, y), p x) : ∀ᶠ x' in 𝓝 x, ∀ᶠ y' in 𝓝 y, p (x', y') := by rw [nhds_prod_eq] at h exact h.curry #align filter.eventually.curry_nhds Filter.Eventually.curry_nhds @[fun_prop] theorem ContinuousAt.prod {f : X → Y} {g : X → Z} {x : X} (hf : ContinuousAt f x) (hg : ContinuousAt g x) : ContinuousAt (fun x => (f x, g x)) x := hf.prod_mk_nhds hg #align continuous_at.prod ContinuousAt.prod theorem ContinuousAt.prod_map {f : X → Z} {g : Y → W} {p : X × Y} (hf : ContinuousAt f p.fst) (hg : ContinuousAt g p.snd) : ContinuousAt (fun p : X × Y => (f p.1, g p.2)) p := hf.fst''.prod hg.snd'' #align continuous_at.prod_map ContinuousAt.prod_map theorem ContinuousAt.prod_map' {f : X → Z} {g : Y → W} {x : X} {y : Y} (hf : ContinuousAt f x) (hg : ContinuousAt g y) : ContinuousAt (fun p : X × Y => (f p.1, g p.2)) (x, y) := hf.fst'.prod hg.snd' #align continuous_at.prod_map' ContinuousAt.prod_map' theorem ContinuousAt.comp₂ {f : Y × Z → W} {g : X → Y} {h : X → Z} {x : X} (hf : ContinuousAt f (g x, h x)) (hg : ContinuousAt g x) (hh : ContinuousAt h x) : ContinuousAt (fun x ↦ f (g x, h x)) x := ContinuousAt.comp hf (hg.prod hh) theorem ContinuousAt.comp₂_of_eq {f : Y × Z → W} {g : X → Y} {h : X → Z} {x : X} {y : Y × Z} (hf : ContinuousAt f y) (hg : ContinuousAt g x) (hh : ContinuousAt h x) (e : (g x, h x) = y) : ContinuousAt (fun x ↦ f (g x, h x)) x := by rw [← e] at hf exact hf.comp₂ hg hh /-- Continuous functions on products are continuous in their first argument -/ theorem Continuous.curry_left {f : X × Y → Z} (hf : Continuous f) {y : Y} : Continuous fun x ↦ f (x, y) := hf.comp (continuous_id.prod_mk continuous_const) alias Continuous.along_fst := Continuous.curry_left /-- Continuous functions on products are continuous in their second argument -/ theorem Continuous.curry_right {f : X × Y → Z} (hf : Continuous f) {x : X} : Continuous fun y ↦ f (x, y) := hf.comp (continuous_const.prod_mk continuous_id) alias Continuous.along_snd := Continuous.curry_right -- todo: prove a version of `generateFrom_union` with `image2 (∩) s t` in the LHS and use it here theorem prod_generateFrom_generateFrom_eq {X Y : Type*} {s : Set (Set X)} {t : Set (Set Y)} (hs : ⋃₀ s = univ) (ht : ⋃₀ t = univ) : @instTopologicalSpaceProd X Y (generateFrom s) (generateFrom t) = generateFrom (image2 (· ×ˢ ·) s t) := let G := generateFrom (image2 (· ×ˢ ·) s t) le_antisymm (le_generateFrom fun g ⟨u, hu, v, hv, g_eq⟩ => g_eq.symm ▸ @IsOpen.prod _ _ (generateFrom s) (generateFrom t) _ _ (GenerateOpen.basic _ hu) (GenerateOpen.basic _ hv)) (le_inf (coinduced_le_iff_le_induced.mp <| le_generateFrom fun u hu => have : ⋃ v ∈ t, u ×ˢ v = Prod.fst ⁻¹' u := by simp_rw [← prod_iUnion, ← sUnion_eq_biUnion, ht, prod_univ] show G.IsOpen (Prod.fst ⁻¹' u) by rw [← this] exact isOpen_iUnion fun v => isOpen_iUnion fun hv => GenerateOpen.basic _ ⟨_, hu, _, hv, rfl⟩) (coinduced_le_iff_le_induced.mp <| le_generateFrom fun v hv => have : ⋃ u ∈ s, u ×ˢ v = Prod.snd ⁻¹' v := by simp_rw [← iUnion_prod_const, ← sUnion_eq_biUnion, hs, univ_prod] show G.IsOpen (Prod.snd ⁻¹' v) by rw [← this] exact isOpen_iUnion fun u => isOpen_iUnion fun hu => GenerateOpen.basic _ ⟨_, hu, _, hv, rfl⟩)) #align prod_generate_from_generate_from_eq prod_generateFrom_generateFrom_eq -- todo: use the previous lemma? theorem prod_eq_generateFrom : instTopologicalSpaceProd = generateFrom { g | ∃ (s : Set X) (t : Set Y), IsOpen s ∧ IsOpen t ∧ g = s ×ˢ t } := le_antisymm (le_generateFrom fun g ⟨s, t, hs, ht, g_eq⟩ => g_eq.symm ▸ hs.prod ht) (le_inf (forall_mem_image.2 fun t ht => GenerateOpen.basic _ ⟨t, univ, by simpa [Set.prod_eq] using ht⟩) (forall_mem_image.2 fun t ht => GenerateOpen.basic _ ⟨univ, t, by simpa [Set.prod_eq] using ht⟩)) #align prod_eq_generate_from prod_eq_generateFrom -- Porting note (#11215): TODO: align with `mem_nhds_prod_iff'` theorem isOpen_prod_iff {s : Set (X × Y)} : IsOpen s ↔ ∀ a b, (a, b) ∈ s → ∃ u v, IsOpen u ∧ IsOpen v ∧ a ∈ u ∧ b ∈ v ∧ u ×ˢ v ⊆ s := isOpen_iff_mem_nhds.trans <| by simp_rw [Prod.forall, mem_nhds_prod_iff', and_left_comm] #align is_open_prod_iff isOpen_prod_iff /-- A product of induced topologies is induced by the product map -/ theorem prod_induced_induced (f : X → Y) (g : Z → W) : @instTopologicalSpaceProd X Z (induced f ‹_›) (induced g ‹_›) = induced (fun p => (f p.1, g p.2)) instTopologicalSpaceProd := by delta instTopologicalSpaceProd simp_rw [induced_inf, induced_compose] rfl #align prod_induced_induced prod_induced_induced #noalign continuous_uncurry_of_discrete_topology_left /-- Given a neighborhood `s` of `(x, x)`, then `(x, x)` has a square open neighborhood that is a subset of `s`. -/ theorem exists_nhds_square {s : Set (X × X)} {x : X} (hx : s ∈ 𝓝 (x, x)) : ∃ U : Set X, IsOpen U ∧ x ∈ U ∧ U ×ˢ U ⊆ s := by simpa [nhds_prod_eq, (nhds_basis_opens x).prod_self.mem_iff, and_assoc, and_left_comm] using hx #align exists_nhds_square exists_nhds_square /-- `Prod.fst` maps neighborhood of `x : X × Y` within the section `Prod.snd ⁻¹' {x.2}` to `𝓝 x.1`. -/ theorem map_fst_nhdsWithin (x : X × Y) : map Prod.fst (𝓝[Prod.snd ⁻¹' {x.2}] x) = 𝓝 x.1 := by refine le_antisymm (continuousAt_fst.mono_left inf_le_left) fun s hs => ?_ rcases x with ⟨x, y⟩ rw [mem_map, nhdsWithin, mem_inf_principal, mem_nhds_prod_iff] at hs rcases hs with ⟨u, hu, v, hv, H⟩ simp only [prod_subset_iff, mem_singleton_iff, mem_setOf_eq, mem_preimage] at H exact mem_of_superset hu fun z hz => H _ hz _ (mem_of_mem_nhds hv) rfl #align map_fst_nhds_within map_fst_nhdsWithin @[simp] theorem map_fst_nhds (x : X × Y) : map Prod.fst (𝓝 x) = 𝓝 x.1 := le_antisymm continuousAt_fst <| (map_fst_nhdsWithin x).symm.trans_le (map_mono inf_le_left) #align map_fst_nhds map_fst_nhds /-- The first projection in a product of topological spaces sends open sets to open sets. -/ theorem isOpenMap_fst : IsOpenMap (@Prod.fst X Y) := isOpenMap_iff_nhds_le.2 fun x => (map_fst_nhds x).ge #align is_open_map_fst isOpenMap_fst /-- `Prod.snd` maps neighborhood of `x : X × Y` within the section `Prod.fst ⁻¹' {x.1}` to `𝓝 x.2`. -/ theorem map_snd_nhdsWithin (x : X × Y) : map Prod.snd (𝓝[Prod.fst ⁻¹' {x.1}] x) = 𝓝 x.2 := by refine le_antisymm (continuousAt_snd.mono_left inf_le_left) fun s hs => ?_ rcases x with ⟨x, y⟩ rw [mem_map, nhdsWithin, mem_inf_principal, mem_nhds_prod_iff] at hs rcases hs with ⟨u, hu, v, hv, H⟩ simp only [prod_subset_iff, mem_singleton_iff, mem_setOf_eq, mem_preimage] at H exact mem_of_superset hv fun z hz => H _ (mem_of_mem_nhds hu) _ hz rfl #align map_snd_nhds_within map_snd_nhdsWithin @[simp] theorem map_snd_nhds (x : X × Y) : map Prod.snd (𝓝 x) = 𝓝 x.2 := le_antisymm continuousAt_snd <| (map_snd_nhdsWithin x).symm.trans_le (map_mono inf_le_left) #align map_snd_nhds map_snd_nhds /-- The second projection in a product of topological spaces sends open sets to open sets. -/ theorem isOpenMap_snd : IsOpenMap (@Prod.snd X Y) := isOpenMap_iff_nhds_le.2 fun x => (map_snd_nhds x).ge #align is_open_map_snd isOpenMap_snd /-- A product set is open in a product space if and only if each factor is open, or one of them is empty -/ theorem isOpen_prod_iff' {s : Set X} {t : Set Y} : IsOpen (s ×ˢ t) ↔ IsOpen s ∧ IsOpen t ∨ s = ∅ ∨ t = ∅ := by rcases (s ×ˢ t).eq_empty_or_nonempty with h | h · simp [h, prod_eq_empty_iff.1 h] · have st : s.Nonempty ∧ t.Nonempty := prod_nonempty_iff.1 h constructor · intro (H : IsOpen (s ×ˢ t)) refine Or.inl ⟨?_, ?_⟩ · show IsOpen s rw [← fst_image_prod s st.2] exact isOpenMap_fst _ H · show IsOpen t rw [← snd_image_prod st.1 t] exact isOpenMap_snd _ H · intro H simp only [st.1.ne_empty, st.2.ne_empty, not_false_iff, or_false_iff] at H exact H.1.prod H.2 #align is_open_prod_iff' isOpen_prod_iff' theorem closure_prod_eq {s : Set X} {t : Set Y} : closure (s ×ˢ t) = closure s ×ˢ closure t := ext fun ⟨a, b⟩ => by simp_rw [mem_prod, mem_closure_iff_nhdsWithin_neBot, nhdsWithin_prod_eq, prod_neBot] #align closure_prod_eq closure_prod_eq theorem interior_prod_eq (s : Set X) (t : Set Y) : interior (s ×ˢ t) = interior s ×ˢ interior t := ext fun ⟨a, b⟩ => by simp only [mem_interior_iff_mem_nhds, mem_prod, prod_mem_nhds_iff] #align interior_prod_eq interior_prod_eq theorem frontier_prod_eq (s : Set X) (t : Set Y) : frontier (s ×ˢ t) = closure s ×ˢ frontier t ∪ frontier s ×ˢ closure t := by simp only [frontier, closure_prod_eq, interior_prod_eq, prod_diff_prod] #align frontier_prod_eq frontier_prod_eq @[simp] theorem frontier_prod_univ_eq (s : Set X) : frontier (s ×ˢ (univ : Set Y)) = frontier s ×ˢ univ := by simp [frontier_prod_eq] #align frontier_prod_univ_eq frontier_prod_univ_eq @[simp] theorem frontier_univ_prod_eq (s : Set Y) : frontier ((univ : Set X) ×ˢ s) = univ ×ˢ frontier s := by simp [frontier_prod_eq] #align frontier_univ_prod_eq frontier_univ_prod_eq theorem map_mem_closure₂ {f : X → Y → Z} {x : X} {y : Y} {s : Set X} {t : Set Y} {u : Set Z} (hf : Continuous (uncurry f)) (hx : x ∈ closure s) (hy : y ∈ closure t) (h : ∀ a ∈ s, ∀ b ∈ t, f a b ∈ u) : f x y ∈ closure u := have H₁ : (x, y) ∈ closure (s ×ˢ t) := by simpa only [closure_prod_eq] using mk_mem_prod hx hy have H₂ : MapsTo (uncurry f) (s ×ˢ t) u := forall_prod_set.2 h H₂.closure hf H₁ #align map_mem_closure₂ map_mem_closure₂ theorem IsClosed.prod {s₁ : Set X} {s₂ : Set Y} (h₁ : IsClosed s₁) (h₂ : IsClosed s₂) : IsClosed (s₁ ×ˢ s₂) := closure_eq_iff_isClosed.mp <| by simp only [h₁.closure_eq, h₂.closure_eq, closure_prod_eq] #align is_closed.prod IsClosed.prod /-- The product of two dense sets is a dense set. -/ theorem Dense.prod {s : Set X} {t : Set Y} (hs : Dense s) (ht : Dense t) : Dense (s ×ˢ t) := fun x => by rw [closure_prod_eq] exact ⟨hs x.1, ht x.2⟩ #align dense.prod Dense.prod /-- If `f` and `g` are maps with dense range, then `Prod.map f g` has dense range. -/ theorem DenseRange.prod_map {ι : Type*} {κ : Type*} {f : ι → Y} {g : κ → Z} (hf : DenseRange f) (hg : DenseRange g) : DenseRange (Prod.map f g) := by simpa only [DenseRange, prod_range_range_eq] using hf.prod hg #align dense_range.prod_map DenseRange.prod_map theorem Inducing.prod_map {f : X → Y} {g : Z → W} (hf : Inducing f) (hg : Inducing g) : Inducing (Prod.map f g) := inducing_iff_nhds.2 fun (x, z) => by simp_rw [Prod.map_def, nhds_prod_eq, hf.nhds_eq_comap, hg.nhds_eq_comap, prod_comap_comap_eq] #align inducing.prod_mk Inducing.prod_map @[simp] theorem inducing_const_prod {x : X} {f : Y → Z} : (Inducing fun x' => (x, f x')) ↔ Inducing f := by simp_rw [inducing_iff, instTopologicalSpaceProd, induced_inf, induced_compose, Function.comp, induced_const, top_inf_eq] #align inducing_const_prod inducing_const_prod @[simp] theorem inducing_prod_const {y : Y} {f : X → Z} : (Inducing fun x => (f x, y)) ↔ Inducing f := by simp_rw [inducing_iff, instTopologicalSpaceProd, induced_inf, induced_compose, Function.comp, induced_const, inf_top_eq] #align inducing_prod_const inducing_prod_const theorem Embedding.prod_map {f : X → Y} {g : Z → W} (hf : Embedding f) (hg : Embedding g) : Embedding (Prod.map f g) := { hf.toInducing.prod_map hg.toInducing with inj := fun ⟨x₁, z₁⟩ ⟨x₂, z₂⟩ => by simp [hf.inj.eq_iff, hg.inj.eq_iff] } #align embedding.prod_mk Embedding.prod_map protected theorem IsOpenMap.prod {f : X → Y} {g : Z → W} (hf : IsOpenMap f) (hg : IsOpenMap g) : IsOpenMap fun p : X × Z => (f p.1, g p.2) := by rw [isOpenMap_iff_nhds_le] rintro ⟨a, b⟩ rw [nhds_prod_eq, nhds_prod_eq, ← Filter.prod_map_map_eq] exact Filter.prod_mono (hf.nhds_le a) (hg.nhds_le b) #align is_open_map.prod IsOpenMap.prod protected theorem OpenEmbedding.prod {f : X → Y} {g : Z → W} (hf : OpenEmbedding f) (hg : OpenEmbedding g) : OpenEmbedding fun x : X × Z => (f x.1, g x.2) := openEmbedding_of_embedding_open (hf.1.prod_map hg.1) (hf.isOpenMap.prod hg.isOpenMap) #align open_embedding.prod OpenEmbedding.prod theorem embedding_graph {f : X → Y} (hf : Continuous f) : Embedding fun x => (x, f x) := embedding_of_embedding_compose (continuous_id.prod_mk hf) continuous_fst embedding_id #align embedding_graph embedding_graph theorem embedding_prod_mk (x : X) : Embedding (Prod.mk x : Y → X × Y) := embedding_of_embedding_compose (Continuous.Prod.mk x) continuous_snd embedding_id end Prod section Bool lemma continuous_bool_rng [TopologicalSpace X] {f : X → Bool} (b : Bool) : Continuous f ↔ IsClopen (f ⁻¹' {b}) := by rw [continuous_discrete_rng, Bool.forall_bool' b, IsClopen, ← isOpen_compl_iff, ← preimage_compl, Bool.compl_singleton, and_comm] end Bool section Sum open Sum variable [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z] [TopologicalSpace W] theorem continuous_sum_dom {f : X ⊕ Y → Z} : Continuous f ↔ Continuous (f ∘ Sum.inl) ∧ Continuous (f ∘ Sum.inr) := (continuous_sup_dom (t₁ := TopologicalSpace.coinduced Sum.inl _) (t₂ := TopologicalSpace.coinduced Sum.inr _)).trans <| continuous_coinduced_dom.and continuous_coinduced_dom #align continuous_sum_dom continuous_sum_dom theorem continuous_sum_elim {f : X → Z} {g : Y → Z} : Continuous (Sum.elim f g) ↔ Continuous f ∧ Continuous g := continuous_sum_dom #align continuous_sum_elim continuous_sum_elim @[continuity] theorem Continuous.sum_elim {f : X → Z} {g : Y → Z} (hf : Continuous f) (hg : Continuous g) : Continuous (Sum.elim f g) := continuous_sum_elim.2 ⟨hf, hg⟩ #align continuous.sum_elim Continuous.sum_elim @[continuity] theorem continuous_isLeft : Continuous (isLeft : X ⊕ Y → Bool) := continuous_sum_dom.2 ⟨continuous_const, continuous_const⟩ @[continuity] theorem continuous_isRight : Continuous (isRight : X ⊕ Y → Bool) := continuous_sum_dom.2 ⟨continuous_const, continuous_const⟩ @[continuity] -- Porting note: the proof was `continuous_sup_rng_left continuous_coinduced_rng` theorem continuous_inl : Continuous (@inl X Y) := ⟨fun _ => And.left⟩ #align continuous_inl continuous_inl @[continuity] -- Porting note: the proof was `continuous_sup_rng_right continuous_coinduced_rng` theorem continuous_inr : Continuous (@inr X Y) := ⟨fun _ => And.right⟩ #align continuous_inr continuous_inr theorem isOpen_sum_iff {s : Set (X ⊕ Y)} : IsOpen s ↔ IsOpen (inl ⁻¹' s) ∧ IsOpen (inr ⁻¹' s) := Iff.rfl #align is_open_sum_iff isOpen_sum_iff -- Porting note (#10756): new theorem theorem isClosed_sum_iff {s : Set (X ⊕ Y)} : IsClosed s ↔ IsClosed (inl ⁻¹' s) ∧ IsClosed (inr ⁻¹' s) := by simp only [← isOpen_compl_iff, isOpen_sum_iff, preimage_compl] theorem isOpenMap_inl : IsOpenMap (@inl X Y) := fun u hu => by simpa [isOpen_sum_iff, preimage_image_eq u Sum.inl_injective] #align is_open_map_inl isOpenMap_inl theorem isOpenMap_inr : IsOpenMap (@inr X Y) := fun u hu => by simpa [isOpen_sum_iff, preimage_image_eq u Sum.inr_injective] #align is_open_map_inr isOpenMap_inr theorem openEmbedding_inl : OpenEmbedding (@inl X Y) := openEmbedding_of_continuous_injective_open continuous_inl inl_injective isOpenMap_inl #align open_embedding_inl openEmbedding_inl theorem openEmbedding_inr : OpenEmbedding (@inr X Y) := openEmbedding_of_continuous_injective_open continuous_inr inr_injective isOpenMap_inr #align open_embedding_inr openEmbedding_inr theorem embedding_inl : Embedding (@inl X Y) := openEmbedding_inl.1 #align embedding_inl embedding_inl theorem embedding_inr : Embedding (@inr X Y) := openEmbedding_inr.1 #align embedding_inr embedding_inr theorem isOpen_range_inl : IsOpen (range (inl : X → X ⊕ Y)) := openEmbedding_inl.2 #align is_open_range_inl isOpen_range_inl theorem isOpen_range_inr : IsOpen (range (inr : Y → X ⊕ Y)) := openEmbedding_inr.2 #align is_open_range_inr isOpen_range_inr theorem isClosed_range_inl : IsClosed (range (inl : X → X ⊕ Y)) := by rw [← isOpen_compl_iff, compl_range_inl] exact isOpen_range_inr #align is_closed_range_inl isClosed_range_inl theorem isClosed_range_inr : IsClosed (range (inr : Y → X ⊕ Y)) := by rw [← isOpen_compl_iff, compl_range_inr] exact isOpen_range_inl #align is_closed_range_inr isClosed_range_inr theorem closedEmbedding_inl : ClosedEmbedding (inl : X → X ⊕ Y) := ⟨embedding_inl, isClosed_range_inl⟩ #align closed_embedding_inl closedEmbedding_inl theorem closedEmbedding_inr : ClosedEmbedding (inr : Y → X ⊕ Y) := ⟨embedding_inr, isClosed_range_inr⟩ #align closed_embedding_inr closedEmbedding_inr theorem nhds_inl (x : X) : 𝓝 (inl x : X ⊕ Y) = map inl (𝓝 x) := (openEmbedding_inl.map_nhds_eq _).symm #align nhds_inl nhds_inl theorem nhds_inr (y : Y) : 𝓝 (inr y : X ⊕ Y) = map inr (𝓝 y) := (openEmbedding_inr.map_nhds_eq _).symm #align nhds_inr nhds_inr @[simp] theorem continuous_sum_map {f : X → Y} {g : Z → W} : Continuous (Sum.map f g) ↔ Continuous f ∧ Continuous g := continuous_sum_elim.trans <| embedding_inl.continuous_iff.symm.and embedding_inr.continuous_iff.symm #align continuous_sum_map continuous_sum_map @[continuity] theorem Continuous.sum_map {f : X → Y} {g : Z → W} (hf : Continuous f) (hg : Continuous g) : Continuous (Sum.map f g) := continuous_sum_map.2 ⟨hf, hg⟩ #align continuous.sum_map Continuous.sum_map theorem isOpenMap_sum {f : X ⊕ Y → Z} : IsOpenMap f ↔ (IsOpenMap fun a => f (inl a)) ∧ IsOpenMap fun b => f (inr b) := by simp only [isOpenMap_iff_nhds_le, Sum.forall, nhds_inl, nhds_inr, Filter.map_map, comp] #align is_open_map_sum isOpenMap_sum @[simp] theorem isOpenMap_sum_elim {f : X → Z} {g : Y → Z} : IsOpenMap (Sum.elim f g) ↔ IsOpenMap f ∧ IsOpenMap g := by simp only [isOpenMap_sum, elim_inl, elim_inr] #align is_open_map_sum_elim isOpenMap_sum_elim theorem IsOpenMap.sum_elim {f : X → Z} {g : Y → Z} (hf : IsOpenMap f) (hg : IsOpenMap g) : IsOpenMap (Sum.elim f g) := isOpenMap_sum_elim.2 ⟨hf, hg⟩ #align is_open_map.sum_elim IsOpenMap.sum_elim end Sum section Subtype variable [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z] {p : X → Prop} theorem inducing_subtype_val {t : Set Y} : Inducing ((↑) : t → Y) := ⟨rfl⟩ #align inducing_coe inducing_subtype_val theorem Inducing.of_codRestrict {f : X → Y} {t : Set Y} (ht : ∀ x, f x ∈ t) (h : Inducing (t.codRestrict f ht)) : Inducing f := inducing_subtype_val.comp h #align inducing.of_cod_restrict Inducing.of_codRestrict theorem embedding_subtype_val : Embedding ((↑) : Subtype p → X) := ⟨inducing_subtype_val, Subtype.coe_injective⟩ #align embedding_subtype_coe embedding_subtype_val theorem closedEmbedding_subtype_val (h : IsClosed { a | p a }) : ClosedEmbedding ((↑) : Subtype p → X) := ⟨embedding_subtype_val, by rwa [Subtype.range_coe_subtype]⟩ #align closed_embedding_subtype_coe closedEmbedding_subtype_val @[continuity] theorem continuous_subtype_val : Continuous (@Subtype.val X p) := continuous_induced_dom #align continuous_subtype_val continuous_subtype_val #align continuous_subtype_coe continuous_subtype_val theorem Continuous.subtype_val {f : Y → Subtype p} (hf : Continuous f) : Continuous fun x => (f x : X) := continuous_subtype_val.comp hf #align continuous.subtype_coe Continuous.subtype_val theorem IsOpen.openEmbedding_subtype_val {s : Set X} (hs : IsOpen s) : OpenEmbedding ((↑) : s → X) := ⟨embedding_subtype_val, (@Subtype.range_coe _ s).symm ▸ hs⟩ #align is_open.open_embedding_subtype_coe IsOpen.openEmbedding_subtype_val theorem IsOpen.isOpenMap_subtype_val {s : Set X} (hs : IsOpen s) : IsOpenMap ((↑) : s → X) := hs.openEmbedding_subtype_val.isOpenMap #align is_open.is_open_map_subtype_coe IsOpen.isOpenMap_subtype_val theorem IsOpenMap.restrict {f : X → Y} (hf : IsOpenMap f) {s : Set X} (hs : IsOpen s) : IsOpenMap (s.restrict f) := hf.comp hs.isOpenMap_subtype_val #align is_open_map.restrict IsOpenMap.restrict nonrec theorem IsClosed.closedEmbedding_subtype_val {s : Set X} (hs : IsClosed s) : ClosedEmbedding ((↑) : s → X) := closedEmbedding_subtype_val hs #align is_closed.closed_embedding_subtype_coe IsClosed.closedEmbedding_subtype_val @[continuity] theorem Continuous.subtype_mk {f : Y → X} (h : Continuous f) (hp : ∀ x, p (f x)) : Continuous fun x => (⟨f x, hp x⟩ : Subtype p) := continuous_induced_rng.2 h #align continuous.subtype_mk Continuous.subtype_mk theorem Continuous.subtype_map {f : X → Y} (h : Continuous f) {q : Y → Prop} (hpq : ∀ x, p x → q (f x)) : Continuous (Subtype.map f hpq) := (h.comp continuous_subtype_val).subtype_mk _ #align continuous.subtype_map Continuous.subtype_map theorem continuous_inclusion {s t : Set X} (h : s ⊆ t) : Continuous (inclusion h) := continuous_id.subtype_map h #align continuous_inclusion continuous_inclusion theorem continuousAt_subtype_val {p : X → Prop} {x : Subtype p} : ContinuousAt ((↑) : Subtype p → X) x := continuous_subtype_val.continuousAt #align continuous_at_subtype_coe continuousAt_subtype_val theorem Subtype.dense_iff {s : Set X} {t : Set s} : Dense t ↔ s ⊆ closure ((↑) '' t) := by rw [inducing_subtype_val.dense_iff, SetCoe.forall] rfl #align subtype.dense_iff Subtype.dense_iff -- Porting note (#10756): new lemma theorem map_nhds_subtype_val {s : Set X} (x : s) : map ((↑) : s → X) (𝓝 x) = 𝓝[s] ↑x := by rw [inducing_subtype_val.map_nhds_eq, Subtype.range_val] theorem map_nhds_subtype_coe_eq_nhds {x : X} (hx : p x) (h : ∀ᶠ x in 𝓝 x, p x) : map ((↑) : Subtype p → X) (𝓝 ⟨x, hx⟩) = 𝓝 x := map_nhds_induced_of_mem <| by rw [Subtype.range_val]; exact h #align map_nhds_subtype_coe_eq map_nhds_subtype_coe_eq_nhds theorem nhds_subtype_eq_comap {x : X} {h : p x} : 𝓝 (⟨x, h⟩ : Subtype p) = comap (↑) (𝓝 x) := nhds_induced _ _ #align nhds_subtype_eq_comap nhds_subtype_eq_comap theorem tendsto_subtype_rng {Y : Type*} {p : X → Prop} {l : Filter Y} {f : Y → Subtype p} : ∀ {x : Subtype p}, Tendsto f l (𝓝 x) ↔ Tendsto (fun x => (f x : X)) l (𝓝 (x : X)) | ⟨a, ha⟩ => by rw [nhds_subtype_eq_comap, tendsto_comap_iff]; rfl #align tendsto_subtype_rng tendsto_subtype_rng theorem closure_subtype {x : { a // p a }} {s : Set { a // p a }} : x ∈ closure s ↔ (x : X) ∈ closure (((↑) : _ → X) '' s) := closure_induced #align closure_subtype closure_subtype @[simp] theorem continuousAt_codRestrict_iff {f : X → Y} {t : Set Y} (h1 : ∀ x, f x ∈ t) {x : X} : ContinuousAt (codRestrict f t h1) x ↔ ContinuousAt f x := inducing_subtype_val.continuousAt_iff #align continuous_at_cod_restrict_iff continuousAt_codRestrict_iff alias ⟨_, ContinuousAt.codRestrict⟩ := continuousAt_codRestrict_iff #align continuous_at.cod_restrict ContinuousAt.codRestrict theorem ContinuousAt.restrict {f : X → Y} {s : Set X} {t : Set Y} (h1 : MapsTo f s t) {x : s} (h2 : ContinuousAt f x) : ContinuousAt (h1.restrict f s t) x := (h2.comp continuousAt_subtype_val).codRestrict _ #align continuous_at.restrict ContinuousAt.restrict theorem ContinuousAt.restrictPreimage {f : X → Y} {s : Set Y} {x : f ⁻¹' s} (h : ContinuousAt f x) : ContinuousAt (s.restrictPreimage f) x := h.restrict _ #align continuous_at.restrict_preimage ContinuousAt.restrictPreimage @[continuity] theorem Continuous.codRestrict {f : X → Y} {s : Set Y} (hf : Continuous f) (hs : ∀ a, f a ∈ s) : Continuous (s.codRestrict f hs) := hf.subtype_mk hs #align continuous.cod_restrict Continuous.codRestrict @[continuity] theorem Continuous.restrict {f : X → Y} {s : Set X} {t : Set Y} (h1 : MapsTo f s t) (h2 : Continuous f) : Continuous (h1.restrict f s t) := (h2.comp continuous_subtype_val).codRestrict _ @[continuity] theorem Continuous.restrictPreimage {f : X → Y} {s : Set Y} (h : Continuous f) : Continuous (s.restrictPreimage f) := h.restrict _ theorem Inducing.codRestrict {e : X → Y} (he : Inducing e) {s : Set Y} (hs : ∀ x, e x ∈ s) : Inducing (codRestrict e s hs) := inducing_of_inducing_compose (he.continuous.codRestrict hs) continuous_subtype_val he #align inducing.cod_restrict Inducing.codRestrict theorem Embedding.codRestrict {e : X → Y} (he : Embedding e) (s : Set Y) (hs : ∀ x, e x ∈ s) : Embedding (codRestrict e s hs) := embedding_of_embedding_compose (he.continuous.codRestrict hs) continuous_subtype_val he #align embedding.cod_restrict Embedding.codRestrict theorem embedding_inclusion {s t : Set X} (h : s ⊆ t) : Embedding (inclusion h) := embedding_subtype_val.codRestrict _ _ #align embedding_inclusion embedding_inclusion /-- Let `s, t ⊆ X` be two subsets of a topological space `X`. If `t ⊆ s` and the topology induced by `X`on `s` is discrete, then also the topology induces on `t` is discrete. -/ theorem DiscreteTopology.of_subset {X : Type*} [TopologicalSpace X] {s t : Set X} (_ : DiscreteTopology s) (ts : t ⊆ s) : DiscreteTopology t := (embedding_inclusion ts).discreteTopology #align discrete_topology.of_subset DiscreteTopology.of_subset /-- Let `s` be a discrete subset of a topological space. Then the preimage of `s` by a continuous injective map is also discrete. -/ theorem DiscreteTopology.preimage_of_continuous_injective {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] (s : Set Y) [DiscreteTopology s] {f : X → Y} (hc : Continuous f) (hinj : Function.Injective f) : DiscreteTopology (f ⁻¹' s) := DiscreteTopology.of_continuous_injective (β := s) (Continuous.restrict (by exact fun _ x ↦ x) hc) ((MapsTo.restrict_inj _).mpr hinj.injOn) end Subtype section Quotient variable [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z] variable {r : X → X → Prop} {s : Setoid X} theorem quotientMap_quot_mk : QuotientMap (@Quot.mk X r) := ⟨Quot.exists_rep, rfl⟩ #align quotient_map_quot_mk quotientMap_quot_mk @[continuity] theorem continuous_quot_mk : Continuous (@Quot.mk X r) := continuous_coinduced_rng #align continuous_quot_mk continuous_quot_mk @[continuity] theorem continuous_quot_lift {f : X → Y} (hr : ∀ a b, r a b → f a = f b) (h : Continuous f) : Continuous (Quot.lift f hr : Quot r → Y) := continuous_coinduced_dom.2 h #align continuous_quot_lift continuous_quot_lift theorem quotientMap_quotient_mk' : QuotientMap (@Quotient.mk' X s) := quotientMap_quot_mk #align quotient_map_quotient_mk quotientMap_quotient_mk' theorem continuous_quotient_mk' : Continuous (@Quotient.mk' X s) := continuous_coinduced_rng #align continuous_quotient_mk continuous_quotient_mk' theorem Continuous.quotient_lift {f : X → Y} (h : Continuous f) (hs : ∀ a b, a ≈ b → f a = f b) : Continuous (Quotient.lift f hs : Quotient s → Y) := continuous_coinduced_dom.2 h #align continuous.quotient_lift Continuous.quotient_lift theorem Continuous.quotient_liftOn' {f : X → Y} (h : Continuous f) (hs : ∀ a b, @Setoid.r _ s a b → f a = f b) : Continuous (fun x => Quotient.liftOn' x f hs : Quotient s → Y) := h.quotient_lift hs #align continuous.quotient_lift_on' Continuous.quotient_liftOn' @[continuity] theorem Continuous.quotient_map' {t : Setoid Y} {f : X → Y} (hf : Continuous f) (H : (s.r ⇒ t.r) f f) : Continuous (Quotient.map' f H) := (continuous_quotient_mk'.comp hf).quotient_lift _ #align continuous.quotient_map' Continuous.quotient_map' end Quotient section Pi variable {ι : Type*} {π : ι → Type*} {κ : Type*} [TopologicalSpace X] [T : ∀ i, TopologicalSpace (π i)] {f : X → ∀ i : ι, π i} theorem continuous_pi_iff : Continuous f ↔ ∀ i, Continuous fun a => f a i := by simp only [continuous_iInf_rng, continuous_induced_rng, comp] #align continuous_pi_iff continuous_pi_iff @[continuity, fun_prop] theorem continuous_pi (h : ∀ i, Continuous fun a => f a i) : Continuous f := continuous_pi_iff.2 h #align continuous_pi continuous_pi @[continuity, fun_prop] theorem continuous_apply (i : ι) : Continuous fun p : ∀ i, π i => p i := continuous_iInf_dom continuous_induced_dom #align continuous_apply continuous_apply @[continuity] theorem continuous_apply_apply {ρ : κ → ι → Type*} [∀ j i, TopologicalSpace (ρ j i)] (j : κ) (i : ι) : Continuous fun p : ∀ j, ∀ i, ρ j i => p j i := (continuous_apply i).comp (continuous_apply j) #align continuous_apply_apply continuous_apply_apply theorem continuousAt_apply (i : ι) (x : ∀ i, π i) : ContinuousAt (fun p : ∀ i, π i => p i) x := (continuous_apply i).continuousAt #align continuous_at_apply continuousAt_apply theorem Filter.Tendsto.apply_nhds {l : Filter Y} {f : Y → ∀ i, π i} {x : ∀ i, π i} (h : Tendsto f l (𝓝 x)) (i : ι) : Tendsto (fun a => f a i) l (𝓝 <| x i) := (continuousAt_apply i _).tendsto.comp h #align filter.tendsto.apply Filter.Tendsto.apply_nhds theorem nhds_pi {a : ∀ i, π i} : 𝓝 a = pi fun i => 𝓝 (a i) := by simp only [nhds_iInf, nhds_induced, Filter.pi] #align nhds_pi nhds_pi theorem tendsto_pi_nhds {f : Y → ∀ i, π i} {g : ∀ i, π i} {u : Filter Y} : Tendsto f u (𝓝 g) ↔ ∀ x, Tendsto (fun i => f i x) u (𝓝 (g x)) := by rw [nhds_pi, Filter.tendsto_pi] #align tendsto_pi_nhds tendsto_pi_nhds theorem continuousAt_pi {f : X → ∀ i, π i} {x : X} : ContinuousAt f x ↔ ∀ i, ContinuousAt (fun y => f y i) x := tendsto_pi_nhds #align continuous_at_pi continuousAt_pi @[fun_prop] theorem continuousAt_pi' {f : X → ∀ i, π i} {x : X} (hf : ∀ i, ContinuousAt (fun y => f y i) x) : ContinuousAt f x := continuousAt_pi.2 hf theorem Pi.continuous_precomp' {ι' : Type*} (φ : ι' → ι) : Continuous (fun (f : (∀ i, π i)) (j : ι') ↦ f (φ j)) := continuous_pi fun j ↦ continuous_apply (φ j) theorem Pi.continuous_precomp {ι' : Type*} (φ : ι' → ι) : Continuous (· ∘ φ : (ι → X) → (ι' → X)) := Pi.continuous_precomp' φ theorem Pi.continuous_postcomp' {X : ι → Type*} [∀ i, TopologicalSpace (X i)] {g : ∀ i, π i → X i} (hg : ∀ i, Continuous (g i)) : Continuous (fun (f : (∀ i, π i)) (i : ι) ↦ g i (f i)) := continuous_pi fun i ↦ (hg i).comp <| continuous_apply i theorem Pi.continuous_postcomp [TopologicalSpace Y] {g : X → Y} (hg : Continuous g) : Continuous (g ∘ · : (ι → X) → (ι → Y)) := Pi.continuous_postcomp' fun _ ↦ hg lemma Pi.induced_precomp' {ι' : Type*} (φ : ι' → ι) : induced (fun (f : (∀ i, π i)) (j : ι') ↦ f (φ j)) Pi.topologicalSpace = ⨅ i', induced (eval (φ i')) (T (φ i')) := by simp [Pi.topologicalSpace, induced_iInf, induced_compose, comp] lemma Pi.induced_precomp [TopologicalSpace Y] {ι' : Type*} (φ : ι' → ι) : induced (· ∘ φ) Pi.topologicalSpace = ⨅ i', induced (eval (φ i')) ‹TopologicalSpace Y› := induced_precomp' φ lemma Pi.continuous_restrict (S : Set ι) : Continuous (S.restrict : (∀ i : ι, π i) → (∀ i : S, π i)) := Pi.continuous_precomp' ((↑) : S → ι) lemma Pi.induced_restrict (S : Set ι) : induced (S.restrict) Pi.topologicalSpace = ⨅ i ∈ S, induced (eval i) (T i) := by simp (config := { unfoldPartialApp := true }) [← iInf_subtype'', ← induced_precomp' ((↑) : S → ι), restrict] lemma Pi.induced_restrict_sUnion (𝔖 : Set (Set ι)) : induced (⋃₀ 𝔖).restrict (Pi.topologicalSpace (Y := fun i : (⋃₀ 𝔖) ↦ π i)) = ⨅ S ∈ 𝔖, induced S.restrict Pi.topologicalSpace := by simp_rw [Pi.induced_restrict, iInf_sUnion] theorem Filter.Tendsto.update [DecidableEq ι] {l : Filter Y} {f : Y → ∀ i, π i} {x : ∀ i, π i} (hf : Tendsto f l (𝓝 x)) (i : ι) {g : Y → π i} {xi : π i} (hg : Tendsto g l (𝓝 xi)) : Tendsto (fun a => update (f a) i (g a)) l (𝓝 <| update x i xi) := tendsto_pi_nhds.2 fun j => by rcases eq_or_ne j i with (rfl | hj) <;> simp [*, hf.apply_nhds] #align filter.tendsto.update Filter.Tendsto.update theorem ContinuousAt.update [DecidableEq ι] {x : X} (hf : ContinuousAt f x) (i : ι) {g : X → π i} (hg : ContinuousAt g x) : ContinuousAt (fun a => update (f a) i (g a)) x := hf.tendsto.update i hg #align continuous_at.update ContinuousAt.update theorem Continuous.update [DecidableEq ι] (hf : Continuous f) (i : ι) {g : X → π i} (hg : Continuous g) : Continuous fun a => update (f a) i (g a) := continuous_iff_continuousAt.2 fun _ => hf.continuousAt.update i hg.continuousAt #align continuous.update Continuous.update /-- `Function.update f i x` is continuous in `(f, x)`. -/ @[continuity] theorem continuous_update [DecidableEq ι] (i : ι) : Continuous fun f : (∀ j, π j) × π i => update f.1 i f.2 := continuous_fst.update i continuous_snd #align continuous_update continuous_update /-- `Pi.mulSingle i x` is continuous in `x`. -/ -- Porting note (#11215): TODO: restore @[continuity] @[to_additive "`Pi.single i x` is continuous in `x`."] theorem continuous_mulSingle [∀ i, One (π i)] [DecidableEq ι] (i : ι) : Continuous fun x => (Pi.mulSingle i x : ∀ i, π i) := continuous_const.update _ continuous_id #align continuous_mul_single continuous_mulSingle #align continuous_single continuous_single theorem Filter.Tendsto.fin_insertNth {n} {π : Fin (n + 1) → Type*} [∀ i, TopologicalSpace (π i)] (i : Fin (n + 1)) {f : Y → π i} {l : Filter Y} {x : π i} (hf : Tendsto f l (𝓝 x)) {g : Y → ∀ j : Fin n, π (i.succAbove j)} {y : ∀ j, π (i.succAbove j)} (hg : Tendsto g l (𝓝 y)) : Tendsto (fun a => i.insertNth (f a) (g a)) l (𝓝 <| i.insertNth x y) := tendsto_pi_nhds.2 fun j => Fin.succAboveCases i (by simpa) (by simpa using tendsto_pi_nhds.1 hg) j #align filter.tendsto.fin_insert_nth Filter.Tendsto.fin_insertNth theorem ContinuousAt.fin_insertNth {n} {π : Fin (n + 1) → Type*} [∀ i, TopologicalSpace (π i)] (i : Fin (n + 1)) {f : X → π i} {x : X} (hf : ContinuousAt f x) {g : X → ∀ j : Fin n, π (i.succAbove j)} (hg : ContinuousAt g x) : ContinuousAt (fun a => i.insertNth (f a) (g a)) x := hf.tendsto.fin_insertNth i hg #align continuous_at.fin_insert_nth ContinuousAt.fin_insertNth theorem Continuous.fin_insertNth {n} {π : Fin (n + 1) → Type*} [∀ i, TopologicalSpace (π i)] (i : Fin (n + 1)) {f : X → π i} (hf : Continuous f) {g : X → ∀ j : Fin n, π (i.succAbove j)} (hg : Continuous g) : Continuous fun a => i.insertNth (f a) (g a) := continuous_iff_continuousAt.2 fun _ => hf.continuousAt.fin_insertNth i hg.continuousAt #align continuous.fin_insert_nth Continuous.fin_insertNth theorem isOpen_set_pi {i : Set ι} {s : ∀ a, Set (π a)} (hi : i.Finite) (hs : ∀ a ∈ i, IsOpen (s a)) : IsOpen (pi i s) := by rw [pi_def]; exact hi.isOpen_biInter fun a ha => (hs _ ha).preimage (continuous_apply _) #align is_open_set_pi isOpen_set_pi theorem isOpen_pi_iff {s : Set (∀ a, π a)} : IsOpen s ↔ ∀ f, f ∈ s → ∃ (I : Finset ι) (u : ∀ a, Set (π a)), (∀ a, a ∈ I → IsOpen (u a) ∧ f a ∈ u a) ∧ (I : Set ι).pi u ⊆ s := by rw [isOpen_iff_nhds] simp_rw [le_principal_iff, nhds_pi, Filter.mem_pi', mem_nhds_iff] refine forall₂_congr fun a _ => ⟨?_, ?_⟩ · rintro ⟨I, t, ⟨h1, h2⟩⟩ refine ⟨I, fun a => eval a '' (I : Set ι).pi fun a => (h1 a).choose, fun i hi => ?_, ?_⟩ · simp_rw [eval_image_pi (Finset.mem_coe.mpr hi) (pi_nonempty_iff.mpr fun i => ⟨_, fun _ => (h1 i).choose_spec.2.2⟩)] exact (h1 i).choose_spec.2 · exact Subset.trans (pi_mono fun i hi => (eval_image_pi_subset hi).trans (h1 i).choose_spec.1) h2 · rintro ⟨I, t, ⟨h1, h2⟩⟩ refine ⟨I, fun a => ite (a ∈ I) (t a) univ, fun i => ?_, ?_⟩ · by_cases hi : i ∈ I · use t i simp_rw [if_pos hi] exact ⟨Subset.rfl, (h1 i) hi⟩ · use univ simp_rw [if_neg hi] exact ⟨Subset.rfl, isOpen_univ, mem_univ _⟩ · rw [← univ_pi_ite] simp only [← ite_and, ← Finset.mem_coe, and_self_iff, univ_pi_ite, h2] #align is_open_pi_iff isOpen_pi_iff theorem isOpen_pi_iff' [Finite ι] {s : Set (∀ a, π a)} : IsOpen s ↔ ∀ f, f ∈ s → ∃ u : ∀ a, Set (π a), (∀ a, IsOpen (u a) ∧ f a ∈ u a) ∧ univ.pi u ⊆ s := by cases nonempty_fintype ι rw [isOpen_iff_nhds] simp_rw [le_principal_iff, nhds_pi, Filter.mem_pi', mem_nhds_iff] refine forall₂_congr fun a _ => ⟨?_, ?_⟩ · rintro ⟨I, t, ⟨h1, h2⟩⟩ refine ⟨fun i => (h1 i).choose, ⟨fun i => (h1 i).choose_spec.2, (pi_mono fun i _ => (h1 i).choose_spec.1).trans (Subset.trans ?_ h2)⟩⟩ rw [← pi_inter_compl (I : Set ι)] exact inter_subset_left · exact fun ⟨u, ⟨h1, _⟩⟩ => ⟨Finset.univ, u, ⟨fun i => ⟨u i, ⟨rfl.subset, h1 i⟩⟩, by rwa [Finset.coe_univ]⟩⟩ #align is_open_pi_iff' isOpen_pi_iff' theorem isClosed_set_pi {i : Set ι} {s : ∀ a, Set (π a)} (hs : ∀ a ∈ i, IsClosed (s a)) : IsClosed (pi i s) := by rw [pi_def]; exact isClosed_biInter fun a ha => (hs _ ha).preimage (continuous_apply _) #align is_closed_set_pi isClosed_set_pi theorem mem_nhds_of_pi_mem_nhds {I : Set ι} {s : ∀ i, Set (π i)} (a : ∀ i, π i) (hs : I.pi s ∈ 𝓝 a) {i : ι} (hi : i ∈ I) : s i ∈ 𝓝 (a i) := by rw [nhds_pi] at hs; exact mem_of_pi_mem_pi hs hi #align mem_nhds_of_pi_mem_nhds mem_nhds_of_pi_mem_nhds theorem set_pi_mem_nhds {i : Set ι} {s : ∀ a, Set (π a)} {x : ∀ a, π a} (hi : i.Finite) (hs : ∀ a ∈ i, s a ∈ 𝓝 (x a)) : pi i s ∈ 𝓝 x := by rw [pi_def, biInter_mem hi] exact fun a ha => (continuous_apply a).continuousAt (hs a ha) #align set_pi_mem_nhds set_pi_mem_nhds theorem set_pi_mem_nhds_iff {I : Set ι} (hI : I.Finite) {s : ∀ i, Set (π i)} (a : ∀ i, π i) : I.pi s ∈ 𝓝 a ↔ ∀ i : ι, i ∈ I → s i ∈ 𝓝 (a i) := by rw [nhds_pi, pi_mem_pi_iff hI] #align set_pi_mem_nhds_iff set_pi_mem_nhds_iff theorem interior_pi_set {I : Set ι} (hI : I.Finite) {s : ∀ i, Set (π i)} : interior (pi I s) = I.pi fun i => interior (s i) := by ext a simp only [Set.mem_pi, mem_interior_iff_mem_nhds, set_pi_mem_nhds_iff hI] #align interior_pi_set interior_pi_set theorem exists_finset_piecewise_mem_of_mem_nhds [DecidableEq ι] {s : Set (∀ a, π a)} {x : ∀ a, π a} (hs : s ∈ 𝓝 x) (y : ∀ a, π a) : ∃ I : Finset ι, I.piecewise x y ∈ s := by simp only [nhds_pi, Filter.mem_pi'] at hs rcases hs with ⟨I, t, htx, hts⟩ refine ⟨I, hts fun i hi => ?_⟩ simpa [Finset.mem_coe.1 hi] using mem_of_mem_nhds (htx i) #align exists_finset_piecewise_mem_of_mem_nhds exists_finset_piecewise_mem_of_mem_nhds theorem pi_generateFrom_eq {π : ι → Type*} {g : ∀ a, Set (Set (π a))} : (@Pi.topologicalSpace ι π fun a => generateFrom (g a)) = generateFrom { t | ∃ (s : ∀ a, Set (π a)) (i : Finset ι), (∀ a ∈ i, s a ∈ g a) ∧ t = pi (↑i) s } := by refine le_antisymm ?_ ?_ · apply le_generateFrom rintro _ ⟨s, i, hi, rfl⟩ letI := fun a => generateFrom (g a) exact isOpen_set_pi i.finite_toSet (fun a ha => GenerateOpen.basic _ (hi a ha)) · refine le_iInf fun i => coinduced_le_iff_le_induced.1 <| le_generateFrom fun s hs => ?_ refine GenerateOpen.basic _ ⟨update (fun i => univ) i s, {i}, ?_⟩ simp [hs] #align pi_generate_from_eq pi_generateFrom_eq theorem pi_eq_generateFrom : Pi.topologicalSpace = generateFrom { g | ∃ (s : ∀ a, Set (π a)) (i : Finset ι), (∀ a ∈ i, IsOpen (s a)) ∧ g = pi (↑i) s } := calc Pi.topologicalSpace _ = @Pi.topologicalSpace ι π fun a => generateFrom { s | IsOpen s } := by simp only [generateFrom_setOf_isOpen] _ = _ := pi_generateFrom_eq #align pi_eq_generate_from pi_eq_generateFrom theorem pi_generateFrom_eq_finite {π : ι → Type*} {g : ∀ a, Set (Set (π a))} [Finite ι] (hg : ∀ a, ⋃₀ g a = univ) : (@Pi.topologicalSpace ι π fun a => generateFrom (g a)) = generateFrom { t | ∃ s : ∀ a, Set (π a), (∀ a, s a ∈ g a) ∧ t = pi univ s } := by cases nonempty_fintype ι rw [pi_generateFrom_eq] refine le_antisymm (generateFrom_anti ?_) (le_generateFrom ?_) · exact fun s ⟨t, ht, Eq⟩ => ⟨t, Finset.univ, by simp [ht, Eq]⟩ · rintro s ⟨t, i, ht, rfl⟩ letI := generateFrom { t | ∃ s : ∀ a, Set (π a), (∀ a, s a ∈ g a) ∧ t = pi univ s } refine isOpen_iff_forall_mem_open.2 fun f hf => ?_ choose c hcg hfc using fun a => sUnion_eq_univ_iff.1 (hg a) (f a) refine ⟨pi i t ∩ pi ((↑i)ᶜ : Set ι) c, inter_subset_left, ?_, ⟨hf, fun a _ => hfc a⟩⟩ rw [← univ_pi_piecewise] refine GenerateOpen.basic _ ⟨_, fun a => ?_, rfl⟩ by_cases a ∈ i <;> simp [*] #align pi_generate_from_eq_finite pi_generateFrom_eq_finite theorem induced_to_pi {X : Type*} (f : X → ∀ i, π i) : induced f Pi.topologicalSpace = ⨅ i, induced (f · i) inferInstance := by simp_rw [Pi.topologicalSpace, induced_iInf, induced_compose, Function.comp] /-- Suppose `π i` is a family of topological spaces indexed by `i : ι`, and `X` is a type endowed with a family of maps `f i : X → π i` for every `i : ι`, hence inducing a map `g : X → Π i, π i`. This lemma shows that infimum of the topologies on `X` induced by the `f i` as `i : ι` varies is simply the topology on `X` induced by `g : X → Π i, π i` where `Π i, π i` is endowed with the usual product topology. -/ theorem inducing_iInf_to_pi {X : Type*} (f : ∀ i, X → π i) : @Inducing X (∀ i, π i) (⨅ i, induced (f i) inferInstance) _ fun x i => f i x := letI := ⨅ i, induced (f i) inferInstance; ⟨(induced_to_pi _).symm⟩ #align inducing_infi_to_pi inducing_iInf_to_pi variable [Finite ι] [∀ i, DiscreteTopology (π i)] /-- A finite product of discrete spaces is discrete. -/ instance Pi.discreteTopology : DiscreteTopology (∀ i, π i) := singletons_open_iff_discrete.mp fun x => by rw [← univ_pi_singleton] exact isOpen_set_pi finite_univ fun i _ => (isOpen_discrete {x i}) #align Pi.discrete_topology Pi.discreteTopology end Pi section Sigma variable {ι κ : Type*} {σ : ι → Type*} {τ : κ → Type*} [∀ i, TopologicalSpace (σ i)] [∀ k, TopologicalSpace (τ k)] [TopologicalSpace X] @[continuity] theorem continuous_sigmaMk {i : ι} : Continuous (@Sigma.mk ι σ i) := continuous_iSup_rng continuous_coinduced_rng #align continuous_sigma_mk continuous_sigmaMk -- Porting note: the proof was `by simp only [isOpen_iSup_iff, isOpen_coinduced]` theorem isOpen_sigma_iff {s : Set (Sigma σ)} : IsOpen s ↔ ∀ i, IsOpen (Sigma.mk i ⁻¹' s) := by delta instTopologicalSpaceSigma rw [isOpen_iSup_iff] rfl #align is_open_sigma_iff isOpen_sigma_iff theorem isClosed_sigma_iff {s : Set (Sigma σ)} : IsClosed s ↔ ∀ i, IsClosed (Sigma.mk i ⁻¹' s) := by simp only [← isOpen_compl_iff, isOpen_sigma_iff, preimage_compl] #align is_closed_sigma_iff isClosed_sigma_iff theorem isOpenMap_sigmaMk {i : ι} : IsOpenMap (@Sigma.mk ι σ i) := by intro s hs rw [isOpen_sigma_iff] intro j rcases eq_or_ne j i with (rfl | hne) · rwa [preimage_image_eq _ sigma_mk_injective] · rw [preimage_image_sigmaMk_of_ne hne] exact isOpen_empty #align is_open_map_sigma_mk isOpenMap_sigmaMk theorem isOpen_range_sigmaMk {i : ι} : IsOpen (range (@Sigma.mk ι σ i)) := isOpenMap_sigmaMk.isOpen_range #align is_open_range_sigma_mk isOpen_range_sigmaMk theorem isClosedMap_sigmaMk {i : ι} : IsClosedMap (@Sigma.mk ι σ i) := by intro s hs rw [isClosed_sigma_iff] intro j rcases eq_or_ne j i with (rfl | hne) · rwa [preimage_image_eq _ sigma_mk_injective] · rw [preimage_image_sigmaMk_of_ne hne] exact isClosed_empty #align is_closed_map_sigma_mk isClosedMap_sigmaMk theorem isClosed_range_sigmaMk {i : ι} : IsClosed (range (@Sigma.mk ι σ i)) := isClosedMap_sigmaMk.isClosed_range #align is_closed_range_sigma_mk isClosed_range_sigmaMk theorem openEmbedding_sigmaMk {i : ι} : OpenEmbedding (@Sigma.mk ι σ i) := openEmbedding_of_continuous_injective_open continuous_sigmaMk sigma_mk_injective isOpenMap_sigmaMk #align open_embedding_sigma_mk openEmbedding_sigmaMk theorem closedEmbedding_sigmaMk {i : ι} : ClosedEmbedding (@Sigma.mk ι σ i) := closedEmbedding_of_continuous_injective_closed continuous_sigmaMk sigma_mk_injective isClosedMap_sigmaMk #align closed_embedding_sigma_mk closedEmbedding_sigmaMk theorem embedding_sigmaMk {i : ι} : Embedding (@Sigma.mk ι σ i) := closedEmbedding_sigmaMk.1 #align embedding_sigma_mk embedding_sigmaMk theorem Sigma.nhds_mk (i : ι) (x : σ i) : 𝓝 (⟨i, x⟩ : Sigma σ) = Filter.map (Sigma.mk i) (𝓝 x) := (openEmbedding_sigmaMk.map_nhds_eq x).symm #align sigma.nhds_mk Sigma.nhds_mk theorem Sigma.nhds_eq (x : Sigma σ) : 𝓝 x = Filter.map (Sigma.mk x.1) (𝓝 x.2) := by cases x apply Sigma.nhds_mk #align sigma.nhds_eq Sigma.nhds_eq theorem comap_sigmaMk_nhds (i : ι) (x : σ i) : comap (Sigma.mk i) (𝓝 ⟨i, x⟩) = 𝓝 x := (embedding_sigmaMk.nhds_eq_comap _).symm #align comap_sigma_mk_nhds comap_sigmaMk_nhds theorem isOpen_sigma_fst_preimage (s : Set ι) : IsOpen (Sigma.fst ⁻¹' s : Set (Σ a, σ a)) := by rw [← biUnion_of_singleton s, preimage_iUnion₂] simp only [← range_sigmaMk] exact isOpen_biUnion fun _ _ => isOpen_range_sigmaMk #align is_open_sigma_fst_preimage isOpen_sigma_fst_preimage /-- A map out of a sum type is continuous iff its restriction to each summand is. -/ @[simp] theorem continuous_sigma_iff {f : Sigma σ → X} : Continuous f ↔ ∀ i, Continuous fun a => f ⟨i, a⟩ := by delta instTopologicalSpaceSigma rw [continuous_iSup_dom] exact forall_congr' fun _ => continuous_coinduced_dom #align continuous_sigma_iff continuous_sigma_iff /-- A map out of a sum type is continuous if its restriction to each summand is. -/ @[continuity] theorem continuous_sigma {f : Sigma σ → X} (hf : ∀ i, Continuous fun a => f ⟨i, a⟩) : Continuous f := continuous_sigma_iff.2 hf #align continuous_sigma continuous_sigma /-- A map defined on a sigma type (a.k.a. the disjoint union of an indexed family of topological spaces) is inducing iff its restriction to each component is inducing and each the image of each component under `f` can be separated from the images of all other components by an open set. -/ theorem inducing_sigma {f : Sigma σ → X} : Inducing f ↔ (∀ i, Inducing (f ∘ Sigma.mk i)) ∧ (∀ i, ∃ U, IsOpen U ∧ ∀ x, f x ∈ U ↔ x.1 = i) := by refine ⟨fun h ↦ ⟨fun i ↦ h.comp embedding_sigmaMk.1, fun i ↦ ?_⟩, ?_⟩ · rcases h.isOpen_iff.1 (isOpen_range_sigmaMk (i := i)) with ⟨U, hUo, hU⟩ refine ⟨U, hUo, ?_⟩ simpa [ext_iff] using hU · refine fun ⟨h₁, h₂⟩ ↦ inducing_iff_nhds.2 fun ⟨i, x⟩ ↦ ?_ rw [Sigma.nhds_mk, (h₁ i).nhds_eq_comap, comp_apply, ← comap_comap, map_comap_of_mem] rcases h₂ i with ⟨U, hUo, hU⟩ filter_upwards [preimage_mem_comap <| hUo.mem_nhds <| (hU _).2 rfl] with y hy simpa [hU] using hy @[simp 1100] theorem continuous_sigma_map {f₁ : ι → κ} {f₂ : ∀ i, σ i → τ (f₁ i)} : Continuous (Sigma.map f₁ f₂) ↔ ∀ i, Continuous (f₂ i) := continuous_sigma_iff.trans <| by simp only [Sigma.map, embedding_sigmaMk.continuous_iff, comp] #align continuous_sigma_map continuous_sigma_map @[continuity] theorem Continuous.sigma_map {f₁ : ι → κ} {f₂ : ∀ i, σ i → τ (f₁ i)} (hf : ∀ i, Continuous (f₂ i)) : Continuous (Sigma.map f₁ f₂) := continuous_sigma_map.2 hf #align continuous.sigma_map Continuous.sigma_map theorem isOpenMap_sigma {f : Sigma σ → X} : IsOpenMap f ↔ ∀ i, IsOpenMap fun a => f ⟨i, a⟩ := by simp only [isOpenMap_iff_nhds_le, Sigma.forall, Sigma.nhds_eq, map_map, comp] #align is_open_map_sigma isOpenMap_sigma theorem isOpenMap_sigma_map {f₁ : ι → κ} {f₂ : ∀ i, σ i → τ (f₁ i)} : IsOpenMap (Sigma.map f₁ f₂) ↔ ∀ i, IsOpenMap (f₂ i) := isOpenMap_sigma.trans <| forall_congr' fun i => (@openEmbedding_sigmaMk _ _ _ (f₁ i)).isOpenMap_iff.symm #align is_open_map_sigma_map isOpenMap_sigma_map theorem inducing_sigma_map {f₁ : ι → κ} {f₂ : ∀ i, σ i → τ (f₁ i)} (h₁ : Injective f₁) : Inducing (Sigma.map f₁ f₂) ↔ ∀ i, Inducing (f₂ i) := by simp only [inducing_iff_nhds, Sigma.forall, Sigma.nhds_mk, Sigma.map_mk, ← map_sigma_mk_comap h₁, map_inj sigma_mk_injective] #align inducing_sigma_map inducing_sigma_map theorem embedding_sigma_map {f₁ : ι → κ} {f₂ : ∀ i, σ i → τ (f₁ i)} (h : Injective f₁) : Embedding (Sigma.map f₁ f₂) ↔ ∀ i, Embedding (f₂ i) := by simp only [embedding_iff, Injective.sigma_map, inducing_sigma_map h, forall_and, h.sigma_map_iff] #align embedding_sigma_map embedding_sigma_map theorem openEmbedding_sigma_map {f₁ : ι → κ} {f₂ : ∀ i, σ i → τ (f₁ i)} (h : Injective f₁) : OpenEmbedding (Sigma.map f₁ f₂) ↔ ∀ i, OpenEmbedding (f₂ i) := by simp only [openEmbedding_iff_embedding_open, isOpenMap_sigma_map, embedding_sigma_map h, forall_and] #align open_embedding_sigma_map openEmbedding_sigma_map end Sigma section ULift theorem ULift.isOpen_iff [TopologicalSpace X] {s : Set (ULift.{v} X)} : IsOpen s ↔ IsOpen (ULift.up ⁻¹' s) := by rw [ULift.topologicalSpace, ← Equiv.ulift_apply, ← Equiv.ulift.coinduced_symm, ← isOpen_coinduced] theorem ULift.isClosed_iff [TopologicalSpace X] {s : Set (ULift.{v} X)} : IsClosed s ↔ IsClosed (ULift.up ⁻¹' s) := by rw [← isOpen_compl_iff, ← isOpen_compl_iff, isOpen_iff, preimage_compl] @[continuity] theorem continuous_uLift_down [TopologicalSpace X] : Continuous (ULift.down : ULift.{v, u} X → X) := continuous_induced_dom #align continuous_ulift_down continuous_uLift_down @[continuity] theorem continuous_uLift_up [TopologicalSpace X] : Continuous (ULift.up : X → ULift.{v, u} X) := continuous_induced_rng.2 continuous_id #align continuous_ulift_up continuous_uLift_up theorem embedding_uLift_down [TopologicalSpace X] : Embedding (ULift.down : ULift.{v, u} X → X) := ⟨⟨rfl⟩, ULift.down_injective⟩ #align embedding_ulift_down embedding_uLift_down theorem ULift.closedEmbedding_down [TopologicalSpace X] : ClosedEmbedding (ULift.down : ULift.{v, u} X → X) := ⟨embedding_uLift_down, by simp only [ULift.down_surjective.range_eq, isClosed_univ]⟩ #align ulift.closed_embedding_down ULift.closedEmbedding_down instance [TopologicalSpace X] [DiscreteTopology X] : DiscreteTopology (ULift X) := embedding_uLift_down.discreteTopology end ULift section Monad variable [TopologicalSpace X] {s : Set X} {t : Set s}
Mathlib/Topology/Constructions.lean
1,763
1,766
theorem IsOpen.trans (ht : IsOpen t) (hs : IsOpen s) : IsOpen (t : Set X) := by
rcases isOpen_induced_iff.mp ht with ⟨s', hs', rfl⟩ rw [Subtype.image_preimage_coe] exact hs.inter hs'
/- Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Robert Y. Lewis, Johannes Hölzl, Mario Carneiro, Sébastien Gouëzel -/ import Mathlib.Data.ENNReal.Real import Mathlib.Order.Interval.Finset.Nat import Mathlib.Topology.UniformSpace.Pi import Mathlib.Topology.UniformSpace.UniformConvergence import Mathlib.Topology.UniformSpace.UniformEmbedding #align_import topology.metric_space.emetric_space from "leanprover-community/mathlib"@"c8f305514e0d47dfaa710f5a52f0d21b588e6328" /-! # Extended metric spaces This file is devoted to the definition and study of `EMetricSpace`s, i.e., metric spaces in which the distance is allowed to take the value ∞. This extended distance is called `edist`, and takes values in `ℝ≥0∞`. Many definitions and theorems expected on emetric spaces are already introduced on uniform spaces and topological spaces. For example: open and closed sets, compactness, completeness, continuity and uniform continuity. The class `EMetricSpace` therefore extends `UniformSpace` (and `TopologicalSpace`). Since a lot of elementary properties don't require `eq_of_edist_eq_zero` we start setting up the theory of `PseudoEMetricSpace`, where we don't require `edist x y = 0 → x = y` and we specialize to `EMetricSpace` at the end. -/ open Set Filter Classical open scoped Uniformity Topology Filter NNReal ENNReal Pointwise universe u v w variable {α : Type u} {β : Type v} {X : Type*} /-- Characterizing uniformities associated to a (generalized) distance function `D` in terms of the elements of the uniformity. -/ theorem uniformity_dist_of_mem_uniformity [LinearOrder β] {U : Filter (α × α)} (z : β) (D : α → α → β) (H : ∀ s, s ∈ U ↔ ∃ ε > z, ∀ {a b : α}, D a b < ε → (a, b) ∈ s) : U = ⨅ ε > z, 𝓟 { p : α × α | D p.1 p.2 < ε } := HasBasis.eq_biInf ⟨fun s => by simp only [H, subset_def, Prod.forall, mem_setOf]⟩ #align uniformity_dist_of_mem_uniformity uniformity_dist_of_mem_uniformity /-- `EDist α` means that `α` is equipped with an extended distance. -/ @[ext] class EDist (α : Type*) where edist : α → α → ℝ≥0∞ #align has_edist EDist export EDist (edist) /-- Creating a uniform space from an extended distance. -/ def uniformSpaceOfEDist (edist : α → α → ℝ≥0∞) (edist_self : ∀ x : α, edist x x = 0) (edist_comm : ∀ x y : α, edist x y = edist y x) (edist_triangle : ∀ x y z : α, edist x z ≤ edist x y + edist y z) : UniformSpace α := .ofFun edist edist_self edist_comm edist_triangle fun ε ε0 => ⟨ε / 2, ENNReal.half_pos ε0.ne', fun _ h₁ _ h₂ => (ENNReal.add_lt_add h₁ h₂).trans_eq (ENNReal.add_halves _)⟩ #align uniform_space_of_edist uniformSpaceOfEDist -- the uniform structure is embedded in the emetric space structure -- to avoid instance diamond issues. See Note [forgetful inheritance]. /-- Extended (pseudo) metric spaces, with an extended distance `edist` possibly taking the value ∞ Each pseudo_emetric space induces a canonical `UniformSpace` and hence a canonical `TopologicalSpace`. This is enforced in the type class definition, by extending the `UniformSpace` structure. When instantiating a `PseudoEMetricSpace` structure, the uniformity fields are not necessary, they will be filled in by default. There is a default value for the uniformity, that can be substituted in cases of interest, for instance when instantiating a `PseudoEMetricSpace` structure on a product. Continuity of `edist` is proved in `Topology.Instances.ENNReal` -/ class PseudoEMetricSpace (α : Type u) extends EDist α : Type u where edist_self : ∀ x : α, edist x x = 0 edist_comm : ∀ x y : α, edist x y = edist y x edist_triangle : ∀ x y z : α, edist x z ≤ edist x y + edist y z toUniformSpace : UniformSpace α := uniformSpaceOfEDist edist edist_self edist_comm edist_triangle uniformity_edist : 𝓤 α = ⨅ ε > 0, 𝓟 { p : α × α | edist p.1 p.2 < ε } := by rfl #align pseudo_emetric_space PseudoEMetricSpace attribute [instance] PseudoEMetricSpace.toUniformSpace /- Pseudoemetric spaces are less common than metric spaces. Therefore, we work in a dedicated namespace, while notions associated to metric spaces are mostly in the root namespace. -/ /-- Two pseudo emetric space structures with the same edistance function coincide. -/ @[ext] protected theorem PseudoEMetricSpace.ext {α : Type*} {m m' : PseudoEMetricSpace α} (h : m.toEDist = m'.toEDist) : m = m' := by cases' m with ed _ _ _ U hU cases' m' with ed' _ _ _ U' hU' congr 1 exact UniformSpace.ext (((show ed = ed' from h) ▸ hU).trans hU'.symm) variable [PseudoEMetricSpace α] export PseudoEMetricSpace (edist_self edist_comm edist_triangle) attribute [simp] edist_self /-- Triangle inequality for the extended distance -/ theorem edist_triangle_left (x y z : α) : edist x y ≤ edist z x + edist z y := by rw [edist_comm z]; apply edist_triangle #align edist_triangle_left edist_triangle_left theorem edist_triangle_right (x y z : α) : edist x y ≤ edist x z + edist y z := by rw [edist_comm y]; apply edist_triangle #align edist_triangle_right edist_triangle_right theorem edist_congr_right {x y z : α} (h : edist x y = 0) : edist x z = edist y z := by apply le_antisymm · rw [← zero_add (edist y z), ← h] apply edist_triangle · rw [edist_comm] at h rw [← zero_add (edist x z), ← h] apply edist_triangle #align edist_congr_right edist_congr_right theorem edist_congr_left {x y z : α} (h : edist x y = 0) : edist z x = edist z y := by rw [edist_comm z x, edist_comm z y] apply edist_congr_right h #align edist_congr_left edist_congr_left -- new theorem theorem edist_congr {w x y z : α} (hl : edist w x = 0) (hr : edist y z = 0) : edist w y = edist x z := (edist_congr_right hl).trans (edist_congr_left hr) theorem edist_triangle4 (x y z t : α) : edist x t ≤ edist x y + edist y z + edist z t := calc edist x t ≤ edist x z + edist z t := edist_triangle x z t _ ≤ edist x y + edist y z + edist z t := add_le_add_right (edist_triangle x y z) _ #align edist_triangle4 edist_triangle4 /-- The triangle (polygon) inequality for sequences of points; `Finset.Ico` version. -/ theorem edist_le_Ico_sum_edist (f : ℕ → α) {m n} (h : m ≤ n) : edist (f m) (f n) ≤ ∑ i ∈ Finset.Ico m n, edist (f i) (f (i + 1)) := by induction n, h using Nat.le_induction with | base => rw [Finset.Ico_self, Finset.sum_empty, edist_self] | succ n hle ihn => calc edist (f m) (f (n + 1)) ≤ edist (f m) (f n) + edist (f n) (f (n + 1)) := edist_triangle _ _ _ _ ≤ (∑ i ∈ Finset.Ico m n, _) + _ := add_le_add ihn le_rfl _ = ∑ i ∈ Finset.Ico m (n + 1), _ := by { rw [Nat.Ico_succ_right_eq_insert_Ico hle, Finset.sum_insert, add_comm]; simp } #align edist_le_Ico_sum_edist edist_le_Ico_sum_edist /-- The triangle (polygon) inequality for sequences of points; `Finset.range` version. -/ theorem edist_le_range_sum_edist (f : ℕ → α) (n : ℕ) : edist (f 0) (f n) ≤ ∑ i ∈ Finset.range n, edist (f i) (f (i + 1)) := Nat.Ico_zero_eq_range ▸ edist_le_Ico_sum_edist f (Nat.zero_le n) #align edist_le_range_sum_edist edist_le_range_sum_edist /-- A version of `edist_le_Ico_sum_edist` with each intermediate distance replaced with an upper estimate. -/ theorem edist_le_Ico_sum_of_edist_le {f : ℕ → α} {m n} (hmn : m ≤ n) {d : ℕ → ℝ≥0∞} (hd : ∀ {k}, m ≤ k → k < n → edist (f k) (f (k + 1)) ≤ d k) : edist (f m) (f n) ≤ ∑ i ∈ Finset.Ico m n, d i := le_trans (edist_le_Ico_sum_edist f hmn) <| Finset.sum_le_sum fun _k hk => hd (Finset.mem_Ico.1 hk).1 (Finset.mem_Ico.1 hk).2 #align edist_le_Ico_sum_of_edist_le edist_le_Ico_sum_of_edist_le /-- A version of `edist_le_range_sum_edist` with each intermediate distance replaced with an upper estimate. -/ theorem edist_le_range_sum_of_edist_le {f : ℕ → α} (n : ℕ) {d : ℕ → ℝ≥0∞} (hd : ∀ {k}, k < n → edist (f k) (f (k + 1)) ≤ d k) : edist (f 0) (f n) ≤ ∑ i ∈ Finset.range n, d i := Nat.Ico_zero_eq_range ▸ edist_le_Ico_sum_of_edist_le (zero_le n) fun _ => hd #align edist_le_range_sum_of_edist_le edist_le_range_sum_of_edist_le /-- Reformulation of the uniform structure in terms of the extended distance -/ theorem uniformity_pseudoedist : 𝓤 α = ⨅ ε > 0, 𝓟 { p : α × α | edist p.1 p.2 < ε } := PseudoEMetricSpace.uniformity_edist #align uniformity_pseudoedist uniformity_pseudoedist theorem uniformSpace_edist : ‹PseudoEMetricSpace α›.toUniformSpace = uniformSpaceOfEDist edist edist_self edist_comm edist_triangle := UniformSpace.ext uniformity_pseudoedist #align uniform_space_edist uniformSpace_edist theorem uniformity_basis_edist : (𝓤 α).HasBasis (fun ε : ℝ≥0∞ => 0 < ε) fun ε => { p : α × α | edist p.1 p.2 < ε } := (@uniformSpace_edist α _).symm ▸ UniformSpace.hasBasis_ofFun ⟨1, one_pos⟩ _ _ _ _ _ #align uniformity_basis_edist uniformity_basis_edist /-- Characterization of the elements of the uniformity in terms of the extended distance -/ theorem mem_uniformity_edist {s : Set (α × α)} : s ∈ 𝓤 α ↔ ∃ ε > 0, ∀ {a b : α}, edist a b < ε → (a, b) ∈ s := uniformity_basis_edist.mem_uniformity_iff #align mem_uniformity_edist mem_uniformity_edist /-- Given `f : β → ℝ≥0∞`, if `f` sends `{i | p i}` to a set of positive numbers accumulating to zero, then `f i`-neighborhoods of the diagonal form a basis of `𝓤 α`. For specific bases see `uniformity_basis_edist`, `uniformity_basis_edist'`, `uniformity_basis_edist_nnreal`, and `uniformity_basis_edist_inv_nat`. -/ protected theorem EMetric.mk_uniformity_basis {β : Type*} {p : β → Prop} {f : β → ℝ≥0∞} (hf₀ : ∀ x, p x → 0 < f x) (hf : ∀ ε, 0 < ε → ∃ x, p x ∧ f x ≤ ε) : (𝓤 α).HasBasis p fun x => { p : α × α | edist p.1 p.2 < f x } := by refine ⟨fun s => uniformity_basis_edist.mem_iff.trans ?_⟩ constructor · rintro ⟨ε, ε₀, hε⟩ rcases hf ε ε₀ with ⟨i, hi, H⟩ exact ⟨i, hi, fun x hx => hε <| lt_of_lt_of_le hx.out H⟩ · exact fun ⟨i, hi, H⟩ => ⟨f i, hf₀ i hi, H⟩ #align emetric.mk_uniformity_basis EMetric.mk_uniformity_basis /-- Given `f : β → ℝ≥0∞`, if `f` sends `{i | p i}` to a set of positive numbers accumulating to zero, then closed `f i`-neighborhoods of the diagonal form a basis of `𝓤 α`. For specific bases see `uniformity_basis_edist_le` and `uniformity_basis_edist_le'`. -/ protected theorem EMetric.mk_uniformity_basis_le {β : Type*} {p : β → Prop} {f : β → ℝ≥0∞} (hf₀ : ∀ x, p x → 0 < f x) (hf : ∀ ε, 0 < ε → ∃ x, p x ∧ f x ≤ ε) : (𝓤 α).HasBasis p fun x => { p : α × α | edist p.1 p.2 ≤ f x } := by refine ⟨fun s => uniformity_basis_edist.mem_iff.trans ?_⟩ constructor · rintro ⟨ε, ε₀, hε⟩ rcases exists_between ε₀ with ⟨ε', hε'⟩ rcases hf ε' hε'.1 with ⟨i, hi, H⟩ exact ⟨i, hi, fun x hx => hε <| lt_of_le_of_lt (le_trans hx.out H) hε'.2⟩ · exact fun ⟨i, hi, H⟩ => ⟨f i, hf₀ i hi, fun x hx => H (le_of_lt hx.out)⟩ #align emetric.mk_uniformity_basis_le EMetric.mk_uniformity_basis_le theorem uniformity_basis_edist_le : (𝓤 α).HasBasis (fun ε : ℝ≥0∞ => 0 < ε) fun ε => { p : α × α | edist p.1 p.2 ≤ ε } := EMetric.mk_uniformity_basis_le (fun _ => id) fun ε ε₀ => ⟨ε, ε₀, le_refl ε⟩ #align uniformity_basis_edist_le uniformity_basis_edist_le theorem uniformity_basis_edist' (ε' : ℝ≥0∞) (hε' : 0 < ε') : (𝓤 α).HasBasis (fun ε : ℝ≥0∞ => ε ∈ Ioo 0 ε') fun ε => { p : α × α | edist p.1 p.2 < ε } := EMetric.mk_uniformity_basis (fun _ => And.left) fun ε ε₀ => let ⟨δ, hδ⟩ := exists_between hε' ⟨min ε δ, ⟨lt_min ε₀ hδ.1, lt_of_le_of_lt (min_le_right _ _) hδ.2⟩, min_le_left _ _⟩ #align uniformity_basis_edist' uniformity_basis_edist' theorem uniformity_basis_edist_le' (ε' : ℝ≥0∞) (hε' : 0 < ε') : (𝓤 α).HasBasis (fun ε : ℝ≥0∞ => ε ∈ Ioo 0 ε') fun ε => { p : α × α | edist p.1 p.2 ≤ ε } := EMetric.mk_uniformity_basis_le (fun _ => And.left) fun ε ε₀ => let ⟨δ, hδ⟩ := exists_between hε' ⟨min ε δ, ⟨lt_min ε₀ hδ.1, lt_of_le_of_lt (min_le_right _ _) hδ.2⟩, min_le_left _ _⟩ #align uniformity_basis_edist_le' uniformity_basis_edist_le' theorem uniformity_basis_edist_nnreal : (𝓤 α).HasBasis (fun ε : ℝ≥0 => 0 < ε) fun ε => { p : α × α | edist p.1 p.2 < ε } := EMetric.mk_uniformity_basis (fun _ => ENNReal.coe_pos.2) fun _ε ε₀ => let ⟨δ, hδ⟩ := ENNReal.lt_iff_exists_nnreal_btwn.1 ε₀ ⟨δ, ENNReal.coe_pos.1 hδ.1, le_of_lt hδ.2⟩ #align uniformity_basis_edist_nnreal uniformity_basis_edist_nnreal theorem uniformity_basis_edist_nnreal_le : (𝓤 α).HasBasis (fun ε : ℝ≥0 => 0 < ε) fun ε => { p : α × α | edist p.1 p.2 ≤ ε } := EMetric.mk_uniformity_basis_le (fun _ => ENNReal.coe_pos.2) fun _ε ε₀ => let ⟨δ, hδ⟩ := ENNReal.lt_iff_exists_nnreal_btwn.1 ε₀ ⟨δ, ENNReal.coe_pos.1 hδ.1, le_of_lt hδ.2⟩ #align uniformity_basis_edist_nnreal_le uniformity_basis_edist_nnreal_le theorem uniformity_basis_edist_inv_nat : (𝓤 α).HasBasis (fun _ => True) fun n : ℕ => { p : α × α | edist p.1 p.2 < (↑n)⁻¹ } := EMetric.mk_uniformity_basis (fun n _ ↦ ENNReal.inv_pos.2 <| ENNReal.natCast_ne_top n) fun _ε ε₀ ↦ let ⟨n, hn⟩ := ENNReal.exists_inv_nat_lt (ne_of_gt ε₀) ⟨n, trivial, le_of_lt hn⟩ #align uniformity_basis_edist_inv_nat uniformity_basis_edist_inv_nat theorem uniformity_basis_edist_inv_two_pow : (𝓤 α).HasBasis (fun _ => True) fun n : ℕ => { p : α × α | edist p.1 p.2 < 2⁻¹ ^ n } := EMetric.mk_uniformity_basis (fun _ _ => ENNReal.pow_pos (ENNReal.inv_pos.2 ENNReal.two_ne_top) _) fun _ε ε₀ => let ⟨n, hn⟩ := ENNReal.exists_inv_two_pow_lt (ne_of_gt ε₀) ⟨n, trivial, le_of_lt hn⟩ #align uniformity_basis_edist_inv_two_pow uniformity_basis_edist_inv_two_pow /-- Fixed size neighborhoods of the diagonal belong to the uniform structure -/ theorem edist_mem_uniformity {ε : ℝ≥0∞} (ε0 : 0 < ε) : { p : α × α | edist p.1 p.2 < ε } ∈ 𝓤 α := mem_uniformity_edist.2 ⟨ε, ε0, id⟩ #align edist_mem_uniformity edist_mem_uniformity namespace EMetric instance (priority := 900) instIsCountablyGeneratedUniformity : IsCountablyGenerated (𝓤 α) := isCountablyGenerated_of_seq ⟨_, uniformity_basis_edist_inv_nat.eq_iInf⟩ -- Porting note: changed explicit/implicit /-- ε-δ characterization of uniform continuity on a set for pseudoemetric spaces -/ theorem uniformContinuousOn_iff [PseudoEMetricSpace β] {f : α → β} {s : Set α} : UniformContinuousOn f s ↔ ∀ ε > 0, ∃ δ > 0, ∀ {a}, a ∈ s → ∀ {b}, b ∈ s → edist a b < δ → edist (f a) (f b) < ε := uniformity_basis_edist.uniformContinuousOn_iff uniformity_basis_edist #align emetric.uniform_continuous_on_iff EMetric.uniformContinuousOn_iff /-- ε-δ characterization of uniform continuity on pseudoemetric spaces -/ theorem uniformContinuous_iff [PseudoEMetricSpace β] {f : α → β} : UniformContinuous f ↔ ∀ ε > 0, ∃ δ > 0, ∀ {a b : α}, edist a b < δ → edist (f a) (f b) < ε := uniformity_basis_edist.uniformContinuous_iff uniformity_basis_edist #align emetric.uniform_continuous_iff EMetric.uniformContinuous_iff -- Porting note (#10756): new lemma theorem uniformInducing_iff [PseudoEMetricSpace β] {f : α → β} : UniformInducing f ↔ UniformContinuous f ∧ ∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, edist (f a) (f b) < ε → edist a b < δ := uniformInducing_iff'.trans <| Iff.rfl.and <| ((uniformity_basis_edist.comap _).le_basis_iff uniformity_basis_edist).trans <| by simp only [subset_def, Prod.forall]; rfl /-- ε-δ characterization of uniform embeddings on pseudoemetric spaces -/ nonrec theorem uniformEmbedding_iff [PseudoEMetricSpace β] {f : α → β} : UniformEmbedding f ↔ Function.Injective f ∧ UniformContinuous f ∧ ∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, edist (f a) (f b) < ε → edist a b < δ := (uniformEmbedding_iff _).trans <| and_comm.trans <| Iff.rfl.and uniformInducing_iff #align emetric.uniform_embedding_iff EMetric.uniformEmbedding_iff /-- If a map between pseudoemetric spaces is a uniform embedding then the edistance between `f x` and `f y` is controlled in terms of the distance between `x` and `y`. In fact, this lemma holds for a `UniformInducing` map. TODO: generalize? -/ theorem controlled_of_uniformEmbedding [PseudoEMetricSpace β] {f : α → β} (h : UniformEmbedding f) : (∀ ε > 0, ∃ δ > 0, ∀ {a b : α}, edist a b < δ → edist (f a) (f b) < ε) ∧ ∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, edist (f a) (f b) < ε → edist a b < δ := ⟨uniformContinuous_iff.1 h.uniformContinuous, (uniformEmbedding_iff.1 h).2.2⟩ #align emetric.controlled_of_uniform_embedding EMetric.controlled_of_uniformEmbedding /-- ε-δ characterization of Cauchy sequences on pseudoemetric spaces -/ protected theorem cauchy_iff {f : Filter α} : Cauchy f ↔ f ≠ ⊥ ∧ ∀ ε > 0, ∃ t ∈ f, ∀ x, x ∈ t → ∀ y, y ∈ t → edist x y < ε := by rw [← neBot_iff]; exact uniformity_basis_edist.cauchy_iff #align emetric.cauchy_iff EMetric.cauchy_iff /-- A very useful criterion to show that a space is complete is to show that all sequences which satisfy a bound of the form `edist (u n) (u m) < B N` for all `n m ≥ N` are converging. This is often applied for `B N = 2^{-N}`, i.e., with a very fast convergence to `0`, which makes it possible to use arguments of converging series, while this is impossible to do in general for arbitrary Cauchy sequences. -/ theorem complete_of_convergent_controlled_sequences (B : ℕ → ℝ≥0∞) (hB : ∀ n, 0 < B n) (H : ∀ u : ℕ → α, (∀ N n m : ℕ, N ≤ n → N ≤ m → edist (u n) (u m) < B N) → ∃ x, Tendsto u atTop (𝓝 x)) : CompleteSpace α := UniformSpace.complete_of_convergent_controlled_sequences (fun n => { p : α × α | edist p.1 p.2 < B n }) (fun n => edist_mem_uniformity <| hB n) H #align emetric.complete_of_convergent_controlled_sequences EMetric.complete_of_convergent_controlled_sequences /-- A sequentially complete pseudoemetric space is complete. -/ theorem complete_of_cauchySeq_tendsto : (∀ u : ℕ → α, CauchySeq u → ∃ a, Tendsto u atTop (𝓝 a)) → CompleteSpace α := UniformSpace.complete_of_cauchySeq_tendsto #align emetric.complete_of_cauchy_seq_tendsto EMetric.complete_of_cauchySeq_tendsto /-- Expressing locally uniform convergence on a set using `edist`. -/ theorem tendstoLocallyUniformlyOn_iff {ι : Type*} [TopologicalSpace β] {F : ι → β → α} {f : β → α} {p : Filter ι} {s : Set β} : TendstoLocallyUniformlyOn F f p s ↔ ∀ ε > 0, ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, ∀ᶠ n in p, ∀ y ∈ t, edist (f y) (F n y) < ε := by refine ⟨fun H ε hε => H _ (edist_mem_uniformity hε), fun H u hu x hx => ?_⟩ rcases mem_uniformity_edist.1 hu with ⟨ε, εpos, hε⟩ rcases H ε εpos x hx with ⟨t, ht, Ht⟩ exact ⟨t, ht, Ht.mono fun n hs x hx => hε (hs x hx)⟩ #align emetric.tendsto_locally_uniformly_on_iff EMetric.tendstoLocallyUniformlyOn_iff /-- Expressing uniform convergence on a set using `edist`. -/
Mathlib/Topology/EMetricSpace/Basic.lean
368
372
theorem tendstoUniformlyOn_iff {ι : Type*} {F : ι → β → α} {f : β → α} {p : Filter ι} {s : Set β} : TendstoUniformlyOn F f p s ↔ ∀ ε > 0, ∀ᶠ n in p, ∀ x ∈ s, edist (f x) (F n x) < ε := by
refine ⟨fun H ε hε => H _ (edist_mem_uniformity hε), fun H u hu => ?_⟩ rcases mem_uniformity_edist.1 hu with ⟨ε, εpos, hε⟩ exact (H ε εpos).mono fun n hs x hx => hε (hs x hx)
/- Copyright (c) 2022 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import Mathlib.GroupTheory.Archimedean import Mathlib.Topology.Order.Basic #align_import topology.algebra.order.archimedean from "leanprover-community/mathlib"@"4c19a16e4b705bf135cf9a80ac18fcc99c438514" /-! # Topology on archimedean groups and fields In this file we prove the following theorems: - `Rat.denseRange_cast`: the coercion from `ℚ` to a linear ordered archimedean field has dense range; - `AddSubgroup.dense_of_not_isolated_zero`, `AddSubgroup.dense_of_no_min`: two sufficient conditions for a subgroup of an archimedean linear ordered additive commutative group to be dense; - `AddSubgroup.dense_or_cyclic`: an additive subgroup of an archimedean linear ordered additive commutative group `G` with order topology either is dense in `G` or is a cyclic subgroup. -/ open Set /-- Rational numbers are dense in a linear ordered archimedean field. -/ theorem Rat.denseRange_cast {𝕜} [LinearOrderedField 𝕜] [TopologicalSpace 𝕜] [OrderTopology 𝕜] [Archimedean 𝕜] : DenseRange ((↑) : ℚ → 𝕜) := dense_of_exists_between fun _ _ h => Set.exists_range_iff.2 <| exists_rat_btwn h #align rat.dense_range_cast Rat.denseRange_cast namespace AddSubgroup variable {G : Type*} [LinearOrderedAddCommGroup G] [TopologicalSpace G] [OrderTopology G] [Archimedean G] /-- An additive subgroup of an archimedean linear ordered additive commutative group with order topology is dense provided that for all positive `ε` there exists a positive element of the subgroup that is less than `ε`. -/ theorem dense_of_not_isolated_zero (S : AddSubgroup G) (hS : ∀ ε > 0, ∃ g ∈ S, g ∈ Ioo 0 ε) : Dense (S : Set G) := by cases subsingleton_or_nontrivial G · refine fun x => _root_.subset_closure ?_ rw [Subsingleton.elim x 0] exact zero_mem S refine dense_of_exists_between fun a b hlt => ?_ rcases hS (b - a) (sub_pos.2 hlt) with ⟨g, hgS, hg0, hg⟩ rcases (existsUnique_add_zsmul_mem_Ioc hg0 0 a).exists with ⟨m, hm⟩ rw [zero_add] at hm refine ⟨m • g, zsmul_mem hgS _, hm.1, hm.2.trans_lt ?_⟩ rwa [lt_sub_iff_add_lt'] at hg /-- Let `S` be a nontrivial additive subgroup in an archimedean linear ordered additive commutative group `G` with order topology. If the set of positive elements of `S` does not have a minimal element, then `S` is dense `G`. -/
Mathlib/Topology/Algebra/Order/Archimedean.lean
58
62
theorem dense_of_no_min (S : AddSubgroup G) (hbot : S ≠ ⊥) (H : ¬∃ a : G, IsLeast { g : G | g ∈ S ∧ 0 < g } a) : Dense (S : Set G) := by
refine S.dense_of_not_isolated_zero fun ε ε0 => ?_ contrapose! H exact exists_isLeast_pos hbot ε0 (disjoint_left.2 H)
/- Copyright (c) 2019 Neil Strickland. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Neil Strickland -/ import Mathlib.Tactic.Ring import Mathlib.Data.PNat.Prime #align_import data.pnat.xgcd from "leanprover-community/mathlib"@"6afc9b06856ad973f6a2619e3e8a0a8d537a58f2" /-! # Euclidean algorithm for ℕ This file sets up a version of the Euclidean algorithm that only works with natural numbers. Given `0 < a, b`, it computes the unique `(w, x, y, z, d)` such that the following identities hold: * `a = (w + x) d` * `b = (y + z) d` * `w * z = x * y + 1` `d` is then the gcd of `a` and `b`, and `a' := a / d = w + x` and `b' := b / d = y + z` are coprime. This story is closely related to the structure of SL₂(ℕ) (as a free monoid on two generators) and the theory of continued fractions. ## Main declarations * `XgcdType`: Helper type in defining the gcd. Encapsulates `(wp, x, y, zp, ap, bp)`. where `wp` `zp`, `ap`, `bp` are the variables getting changed through the algorithm. * `IsSpecial`: States `wp * zp = x * y + 1` * `IsReduced`: States `ap = a ∧ bp = b` ## Notes See `Nat.Xgcd` for a very similar algorithm allowing values in `ℤ`. -/ open Nat namespace PNat /-- A term of `XgcdType` is a system of six naturals. They should be thought of as representing the matrix [[w, x], [y, z]] = [[wp + 1, x], [y, zp + 1]] together with the vector [a, b] = [ap + 1, bp + 1]. -/ structure XgcdType where /-- `wp` is a variable which changes through the algorithm. -/ wp : ℕ /-- `x` satisfies `a / d = w + x` at the final step. -/ x : ℕ /-- `y` satisfies `b / d = z + y` at the final step. -/ y : ℕ /-- `zp` is a variable which changes through the algorithm. -/ zp : ℕ /-- `ap` is a variable which changes through the algorithm. -/ ap : ℕ /-- `bp` is a variable which changes through the algorithm. -/ bp : ℕ deriving Inhabited #align pnat.xgcd_type PNat.XgcdType namespace XgcdType variable (u : XgcdType) instance : SizeOf XgcdType := ⟨fun u => u.bp⟩ /-- The `Repr` instance converts terms to strings in a way that reflects the matrix/vector interpretation as above. -/ instance : Repr XgcdType where reprPrec | g, _ => s!"[[[{repr (g.wp + 1)}, {repr g.x}], \ [{repr g.y}, {repr (g.zp + 1)}]], \ [{repr (g.ap + 1)}, {repr (g.bp + 1)}]]" /-- Another `mk` using ℕ and ℕ+ -/ def mk' (w : ℕ+) (x : ℕ) (y : ℕ) (z : ℕ+) (a : ℕ+) (b : ℕ+) : XgcdType := mk w.val.pred x y z.val.pred a.val.pred b.val.pred #align pnat.xgcd_type.mk' PNat.XgcdType.mk' /-- `w = wp + 1` -/ def w : ℕ+ := succPNat u.wp #align pnat.xgcd_type.w PNat.XgcdType.w /-- `z = zp + 1` -/ def z : ℕ+ := succPNat u.zp #align pnat.xgcd_type.z PNat.XgcdType.z /-- `a = ap + 1` -/ def a : ℕ+ := succPNat u.ap #align pnat.xgcd_type.a PNat.XgcdType.a /-- `b = bp + 1` -/ def b : ℕ+ := succPNat u.bp #align pnat.xgcd_type.b PNat.XgcdType.b /-- `r = a % b`: remainder -/ def r : ℕ := (u.ap + 1) % (u.bp + 1) #align pnat.xgcd_type.r PNat.XgcdType.r /-- `q = ap / bp`: quotient -/ def q : ℕ := (u.ap + 1) / (u.bp + 1) #align pnat.xgcd_type.q PNat.XgcdType.q /-- `qp = q - 1` -/ def qp : ℕ := u.q - 1 #align pnat.xgcd_type.qp PNat.XgcdType.qp /-- The map `v` gives the product of the matrix [[w, x], [y, z]] = [[wp + 1, x], [y, zp + 1]] and the vector [a, b] = [ap + 1, bp + 1]. The map `vp` gives [sp, tp] such that v = [sp + 1, tp + 1]. -/ def vp : ℕ × ℕ := ⟨u.wp + u.x + u.ap + u.wp * u.ap + u.x * u.bp, u.y + u.zp + u.bp + u.y * u.ap + u.zp * u.bp⟩ #align pnat.xgcd_type.vp PNat.XgcdType.vp /-- `v = [sp + 1, tp + 1]`, check `vp` -/ def v : ℕ × ℕ := ⟨u.w * u.a + u.x * u.b, u.y * u.a + u.z * u.b⟩ #align pnat.xgcd_type.v PNat.XgcdType.v /-- `succ₂ [t.1, t.2] = [t.1.succ, t.2.succ]` -/ def succ₂ (t : ℕ × ℕ) : ℕ × ℕ := ⟨t.1.succ, t.2.succ⟩ #align pnat.xgcd_type.succ₂ PNat.XgcdType.succ₂ theorem v_eq_succ_vp : u.v = succ₂ u.vp := by ext <;> dsimp [v, vp, w, z, a, b, succ₂] <;> ring_nf #align pnat.xgcd_type.v_eq_succ_vp PNat.XgcdType.v_eq_succ_vp /-- `IsSpecial` holds if the matrix has determinant one. -/ def IsSpecial : Prop := u.wp + u.zp + u.wp * u.zp = u.x * u.y #align pnat.xgcd_type.is_special PNat.XgcdType.IsSpecial /-- `IsSpecial'` is an alternative of `IsSpecial`. -/ def IsSpecial' : Prop := u.w * u.z = succPNat (u.x * u.y) #align pnat.xgcd_type.is_special' PNat.XgcdType.IsSpecial' theorem isSpecial_iff : u.IsSpecial ↔ u.IsSpecial' := by dsimp [IsSpecial, IsSpecial'] let ⟨wp, x, y, zp, ap, bp⟩ := u constructor <;> intro h <;> simp [w, z, succPNat] at * <;> simp only [← coe_inj, mul_coe, mk_coe] at * · simp_all [← h, Nat.mul, Nat.succ_eq_add_one]; ring · simp [Nat.succ_eq_add_one, Nat.mul_add, Nat.add_mul, ← Nat.add_assoc] at h; rw [← h]; ring -- Porting note: Old code has been removed as it was much more longer. #align pnat.xgcd_type.is_special_iff PNat.XgcdType.isSpecial_iff /-- `IsReduced` holds if the two entries in the vector are the same. The reduction algorithm will produce a system with this property, whose product vector is the same as for the original system. -/ def IsReduced : Prop := u.ap = u.bp #align pnat.xgcd_type.is_reduced PNat.XgcdType.IsReduced /-- `IsReduced'` is an alternative of `IsReduced`. -/ def IsReduced' : Prop := u.a = u.b #align pnat.xgcd_type.is_reduced' PNat.XgcdType.IsReduced' theorem isReduced_iff : u.IsReduced ↔ u.IsReduced' := succPNat_inj.symm #align pnat.xgcd_type.is_reduced_iff PNat.XgcdType.isReduced_iff /-- `flip` flips the placement of variables during the algorithm. -/ def flip : XgcdType where wp := u.zp x := u.y y := u.x zp := u.wp ap := u.bp bp := u.ap #align pnat.xgcd_type.flip PNat.XgcdType.flip @[simp] theorem flip_w : (flip u).w = u.z := rfl #align pnat.xgcd_type.flip_w PNat.XgcdType.flip_w @[simp] theorem flip_x : (flip u).x = u.y := rfl #align pnat.xgcd_type.flip_x PNat.XgcdType.flip_x @[simp] theorem flip_y : (flip u).y = u.x := rfl #align pnat.xgcd_type.flip_y PNat.XgcdType.flip_y @[simp] theorem flip_z : (flip u).z = u.w := rfl #align pnat.xgcd_type.flip_z PNat.XgcdType.flip_z @[simp] theorem flip_a : (flip u).a = u.b := rfl #align pnat.xgcd_type.flip_a PNat.XgcdType.flip_a @[simp] theorem flip_b : (flip u).b = u.a := rfl #align pnat.xgcd_type.flip_b PNat.XgcdType.flip_b theorem flip_isReduced : (flip u).IsReduced ↔ u.IsReduced := by dsimp [IsReduced, flip] constructor <;> intro h <;> exact h.symm #align pnat.xgcd_type.flip_is_reduced PNat.XgcdType.flip_isReduced theorem flip_isSpecial : (flip u).IsSpecial ↔ u.IsSpecial := by dsimp [IsSpecial, flip] rw [mul_comm u.x, mul_comm u.zp, add_comm u.zp] #align pnat.xgcd_type.flip_is_special PNat.XgcdType.flip_isSpecial theorem flip_v : (flip u).v = u.v.swap := by dsimp [v] ext · simp only ring · simp only ring #align pnat.xgcd_type.flip_v PNat.XgcdType.flip_v /-- Properties of division with remainder for a / b. -/ theorem rq_eq : u.r + (u.bp + 1) * u.q = u.ap + 1 := Nat.mod_add_div (u.ap + 1) (u.bp + 1) #align pnat.xgcd_type.rq_eq PNat.XgcdType.rq_eq theorem qp_eq (hr : u.r = 0) : u.q = u.qp + 1 := by by_cases hq : u.q = 0 · let h := u.rq_eq rw [hr, hq, mul_zero, add_zero] at h cases h · exact (Nat.succ_pred_eq_of_pos (Nat.pos_of_ne_zero hq)).symm #align pnat.xgcd_type.qp_eq PNat.XgcdType.qp_eq /-- The following function provides the starting point for our algorithm. We will apply an iterative reduction process to it, which will produce a system satisfying IsReduced. The gcd can be read off from this final system. -/ def start (a b : ℕ+) : XgcdType := ⟨0, 0, 0, 0, a - 1, b - 1⟩ #align pnat.xgcd_type.start PNat.XgcdType.start theorem start_isSpecial (a b : ℕ+) : (start a b).IsSpecial := by dsimp [start, IsSpecial] #align pnat.xgcd_type.start_is_special PNat.XgcdType.start_isSpecial
Mathlib/Data/PNat/Xgcd.lean
262
267
theorem start_v (a b : ℕ+) : (start a b).v = ⟨a, b⟩ := by
dsimp [start, v, XgcdType.a, XgcdType.b, w, z] rw [one_mul, one_mul, zero_mul, zero_mul] have := a.pos have := b.pos congr <;> omega
/- Copyright (c) 2022 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.MeasureTheory.Integral.Bochner import Mathlib.MeasureTheory.Measure.GiryMonad #align_import probability.kernel.basic from "leanprover-community/mathlib"@"fd5edc43dc4f10b85abfe544b88f82cf13c5f844" /-! # Markov Kernels A kernel from a measurable space `α` to another measurable space `β` is a measurable map `α → MeasureTheory.Measure β`, where the measurable space instance on `measure β` is the one defined in `MeasureTheory.Measure.instMeasurableSpace`. That is, a kernel `κ` verifies that for all measurable sets `s` of `β`, `a ↦ κ a s` is measurable. ## Main definitions Classes of kernels: * `ProbabilityTheory.kernel α β`: kernels from `α` to `β`, defined as the `AddSubmonoid` of the measurable functions in `α → Measure β`. * `ProbabilityTheory.IsMarkovKernel κ`: a kernel from `α` to `β` is said to be a Markov kernel if for all `a : α`, `k a` is a probability measure. * `ProbabilityTheory.IsFiniteKernel κ`: a kernel from `α` to `β` is said to be finite if there exists `C : ℝ≥0∞` such that `C < ∞` and for all `a : α`, `κ a univ ≤ C`. This implies in particular that all measures in the image of `κ` are finite, but is stronger since it requires a uniform bound. This stronger condition is necessary to ensure that the composition of two finite kernels is finite. * `ProbabilityTheory.IsSFiniteKernel κ`: a kernel is called s-finite if it is a countable sum of finite kernels. Particular kernels: * `ProbabilityTheory.kernel.deterministic (f : α → β) (hf : Measurable f)`: kernel `a ↦ Measure.dirac (f a)`. * `ProbabilityTheory.kernel.const α (μβ : measure β)`: constant kernel `a ↦ μβ`. * `ProbabilityTheory.kernel.restrict κ (hs : MeasurableSet s)`: kernel for which the image of `a : α` is `(κ a).restrict s`. Integral: `∫⁻ b, f b ∂(kernel.restrict κ hs a) = ∫⁻ b in s, f b ∂(κ a)` ## Main statements * `ProbabilityTheory.kernel.ext_fun`: if `∫⁻ b, f b ∂(κ a) = ∫⁻ b, f b ∂(η a)` for all measurable functions `f` and all `a`, then the two kernels `κ` and `η` are equal. -/ open MeasureTheory open scoped MeasureTheory ENNReal NNReal namespace ProbabilityTheory /-- A kernel from a measurable space `α` to another measurable space `β` is a measurable function `κ : α → Measure β`. The measurable space structure on `MeasureTheory.Measure β` is given by `MeasureTheory.Measure.instMeasurableSpace`. A map `κ : α → MeasureTheory.Measure β` is measurable iff `∀ s : Set β, MeasurableSet s → Measurable (fun a ↦ κ a s)`. -/ noncomputable def kernel (α β : Type*) [MeasurableSpace α] [MeasurableSpace β] : AddSubmonoid (α → Measure β) where carrier := Measurable zero_mem' := measurable_zero add_mem' hf hg := Measurable.add hf hg #align probability_theory.kernel ProbabilityTheory.kernel -- Porting note: using `FunLike` instead of `CoeFun` to use `DFunLike.coe` instance {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] : FunLike (kernel α β) α (Measure β) where coe := Subtype.val coe_injective' := Subtype.val_injective instance kernel.instCovariantAddLE {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] : CovariantClass (kernel α β) (kernel α β) (· + ·) (· ≤ ·) := ⟨fun _ _ _ hμ a ↦ add_le_add_left (hμ a) _⟩ noncomputable instance kernel.instOrderBot {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] : OrderBot (kernel α β) where bot := 0 bot_le κ a := by simp only [ZeroMemClass.coe_zero, Pi.zero_apply, Measure.zero_le] variable {α β ι : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} namespace kernel @[simp] theorem coeFn_zero : ⇑(0 : kernel α β) = 0 := rfl #align probability_theory.kernel.coe_fn_zero ProbabilityTheory.kernel.coeFn_zero @[simp] theorem coeFn_add (κ η : kernel α β) : ⇑(κ + η) = κ + η := rfl #align probability_theory.kernel.coe_fn_add ProbabilityTheory.kernel.coeFn_add /-- Coercion to a function as an additive monoid homomorphism. -/ def coeAddHom (α β : Type*) [MeasurableSpace α] [MeasurableSpace β] : kernel α β →+ α → Measure β := AddSubmonoid.subtype _ #align probability_theory.kernel.coe_add_hom ProbabilityTheory.kernel.coeAddHom @[simp] theorem zero_apply (a : α) : (0 : kernel α β) a = 0 := rfl #align probability_theory.kernel.zero_apply ProbabilityTheory.kernel.zero_apply @[simp] theorem coe_finset_sum (I : Finset ι) (κ : ι → kernel α β) : ⇑(∑ i ∈ I, κ i) = ∑ i ∈ I, ⇑(κ i) := map_sum (coeAddHom α β) _ _ #align probability_theory.kernel.coe_finset_sum ProbabilityTheory.kernel.coe_finset_sum theorem finset_sum_apply (I : Finset ι) (κ : ι → kernel α β) (a : α) : (∑ i ∈ I, κ i) a = ∑ i ∈ I, κ i a := by rw [coe_finset_sum, Finset.sum_apply] #align probability_theory.kernel.finset_sum_apply ProbabilityTheory.kernel.finset_sum_apply theorem finset_sum_apply' (I : Finset ι) (κ : ι → kernel α β) (a : α) (s : Set β) : (∑ i ∈ I, κ i) a s = ∑ i ∈ I, κ i a s := by rw [finset_sum_apply, Measure.finset_sum_apply] #align probability_theory.kernel.finset_sum_apply' ProbabilityTheory.kernel.finset_sum_apply' end kernel /-- A kernel is a Markov kernel if every measure in its image is a probability measure. -/ class IsMarkovKernel (κ : kernel α β) : Prop where isProbabilityMeasure : ∀ a, IsProbabilityMeasure (κ a) #align probability_theory.is_markov_kernel ProbabilityTheory.IsMarkovKernel /-- A kernel is finite if every measure in its image is finite, with a uniform bound. -/ class IsFiniteKernel (κ : kernel α β) : Prop where exists_univ_le : ∃ C : ℝ≥0∞, C < ∞ ∧ ∀ a, κ a Set.univ ≤ C #align probability_theory.is_finite_kernel ProbabilityTheory.IsFiniteKernel /-- A constant `C : ℝ≥0∞` such that `C < ∞` (`ProbabilityTheory.IsFiniteKernel.bound_lt_top κ`) and for all `a : α` and `s : Set β`, `κ a s ≤ C` (`ProbabilityTheory.kernel.measure_le_bound κ a s`). Porting note (#11215): TODO: does it make sense to -- make `ProbabilityTheory.IsFiniteKernel.bound` the least possible bound? -- Should it be an `NNReal` number? -/ noncomputable def IsFiniteKernel.bound (κ : kernel α β) [h : IsFiniteKernel κ] : ℝ≥0∞ := h.exists_univ_le.choose #align probability_theory.is_finite_kernel.bound ProbabilityTheory.IsFiniteKernel.bound theorem IsFiniteKernel.bound_lt_top (κ : kernel α β) [h : IsFiniteKernel κ] : IsFiniteKernel.bound κ < ∞ := h.exists_univ_le.choose_spec.1 #align probability_theory.is_finite_kernel.bound_lt_top ProbabilityTheory.IsFiniteKernel.bound_lt_top theorem IsFiniteKernel.bound_ne_top (κ : kernel α β) [IsFiniteKernel κ] : IsFiniteKernel.bound κ ≠ ∞ := (IsFiniteKernel.bound_lt_top κ).ne #align probability_theory.is_finite_kernel.bound_ne_top ProbabilityTheory.IsFiniteKernel.bound_ne_top theorem kernel.measure_le_bound (κ : kernel α β) [h : IsFiniteKernel κ] (a : α) (s : Set β) : κ a s ≤ IsFiniteKernel.bound κ := (measure_mono (Set.subset_univ s)).trans (h.exists_univ_le.choose_spec.2 a) #align probability_theory.kernel.measure_le_bound ProbabilityTheory.kernel.measure_le_bound instance isFiniteKernel_zero (α β : Type*) {mα : MeasurableSpace α} {mβ : MeasurableSpace β} : IsFiniteKernel (0 : kernel α β) := ⟨⟨0, ENNReal.coe_lt_top, fun _ => by simp only [kernel.zero_apply, Measure.coe_zero, Pi.zero_apply, le_zero_iff]⟩⟩ #align probability_theory.is_finite_kernel_zero ProbabilityTheory.isFiniteKernel_zero instance IsFiniteKernel.add (κ η : kernel α β) [IsFiniteKernel κ] [IsFiniteKernel η] : IsFiniteKernel (κ + η) := by refine ⟨⟨IsFiniteKernel.bound κ + IsFiniteKernel.bound η, ENNReal.add_lt_top.mpr ⟨IsFiniteKernel.bound_lt_top κ, IsFiniteKernel.bound_lt_top η⟩, fun a => ?_⟩⟩ exact add_le_add (kernel.measure_le_bound _ _ _) (kernel.measure_le_bound _ _ _) #align probability_theory.is_finite_kernel.add ProbabilityTheory.IsFiniteKernel.add lemma isFiniteKernel_of_le {κ ν : kernel α β} [hν : IsFiniteKernel ν] (hκν : κ ≤ ν) : IsFiniteKernel κ := by refine ⟨hν.bound, hν.bound_lt_top, fun a ↦ (hκν _ _).trans (kernel.measure_le_bound ν a Set.univ)⟩ variable {κ : kernel α β} instance IsMarkovKernel.is_probability_measure' [IsMarkovKernel κ] (a : α) : IsProbabilityMeasure (κ a) := IsMarkovKernel.isProbabilityMeasure a #align probability_theory.is_markov_kernel.is_probability_measure' ProbabilityTheory.IsMarkovKernel.is_probability_measure' instance IsFiniteKernel.isFiniteMeasure [IsFiniteKernel κ] (a : α) : IsFiniteMeasure (κ a) := ⟨(kernel.measure_le_bound κ a Set.univ).trans_lt (IsFiniteKernel.bound_lt_top κ)⟩ #align probability_theory.is_finite_kernel.is_finite_measure ProbabilityTheory.IsFiniteKernel.isFiniteMeasure instance (priority := 100) IsMarkovKernel.isFiniteKernel [IsMarkovKernel κ] : IsFiniteKernel κ := ⟨⟨1, ENNReal.one_lt_top, fun _ => prob_le_one⟩⟩ #align probability_theory.is_markov_kernel.is_finite_kernel ProbabilityTheory.IsMarkovKernel.isFiniteKernel namespace kernel @[ext] theorem ext {η : kernel α β} (h : ∀ a, κ a = η a) : κ = η := DFunLike.ext _ _ h #align probability_theory.kernel.ext ProbabilityTheory.kernel.ext theorem ext_iff {η : kernel α β} : κ = η ↔ ∀ a, κ a = η a := DFunLike.ext_iff #align probability_theory.kernel.ext_iff ProbabilityTheory.kernel.ext_iff theorem ext_iff' {η : kernel α β} : κ = η ↔ ∀ a s, MeasurableSet s → κ a s = η a s := by simp_rw [ext_iff, Measure.ext_iff] #align probability_theory.kernel.ext_iff' ProbabilityTheory.kernel.ext_iff' theorem ext_fun {η : kernel α β} (h : ∀ a f, Measurable f → ∫⁻ b, f b ∂κ a = ∫⁻ b, f b ∂η a) : κ = η := by ext a s hs specialize h a (s.indicator fun _ => 1) (Measurable.indicator measurable_const hs) simp_rw [lintegral_indicator_const hs, one_mul] at h rw [h] #align probability_theory.kernel.ext_fun ProbabilityTheory.kernel.ext_fun theorem ext_fun_iff {η : kernel α β} : κ = η ↔ ∀ a f, Measurable f → ∫⁻ b, f b ∂κ a = ∫⁻ b, f b ∂η a := ⟨fun h a f _ => by rw [h], ext_fun⟩ #align probability_theory.kernel.ext_fun_iff ProbabilityTheory.kernel.ext_fun_iff protected theorem measurable (κ : kernel α β) : Measurable κ := κ.prop #align probability_theory.kernel.measurable ProbabilityTheory.kernel.measurable protected theorem measurable_coe (κ : kernel α β) {s : Set β} (hs : MeasurableSet s) : Measurable fun a => κ a s := (Measure.measurable_coe hs).comp (kernel.measurable κ) #align probability_theory.kernel.measurable_coe ProbabilityTheory.kernel.measurable_coe lemma IsFiniteKernel.integrable (μ : Measure α) [IsFiniteMeasure μ] (κ : kernel α β) [IsFiniteKernel κ] {s : Set β} (hs : MeasurableSet s) : Integrable (fun x => (κ x s).toReal) μ := by refine Integrable.mono' (integrable_const (IsFiniteKernel.bound κ).toReal) ((kernel.measurable_coe κ hs).ennreal_toReal.aestronglyMeasurable) (ae_of_all μ fun x => ?_) rw [Real.norm_eq_abs, abs_of_nonneg ENNReal.toReal_nonneg, ENNReal.toReal_le_toReal (measure_ne_top _ _) (IsFiniteKernel.bound_ne_top _)] exact kernel.measure_le_bound _ _ _ lemma IsMarkovKernel.integrable (μ : Measure α) [IsFiniteMeasure μ] (κ : kernel α β) [IsMarkovKernel κ] {s : Set β} (hs : MeasurableSet s) : Integrable (fun x => (κ x s).toReal) μ := IsFiniteKernel.integrable μ κ hs section Sum /-- Sum of an indexed family of kernels. -/ protected noncomputable def sum [Countable ι] (κ : ι → kernel α β) : kernel α β where val a := Measure.sum fun n => κ n a property := by refine Measure.measurable_of_measurable_coe _ fun s hs => ?_ simp_rw [Measure.sum_apply _ hs] exact Measurable.ennreal_tsum fun n => kernel.measurable_coe (κ n) hs #align probability_theory.kernel.sum ProbabilityTheory.kernel.sum theorem sum_apply [Countable ι] (κ : ι → kernel α β) (a : α) : kernel.sum κ a = Measure.sum fun n => κ n a := rfl #align probability_theory.kernel.sum_apply ProbabilityTheory.kernel.sum_apply theorem sum_apply' [Countable ι] (κ : ι → kernel α β) (a : α) {s : Set β} (hs : MeasurableSet s) : kernel.sum κ a s = ∑' n, κ n a s := by rw [sum_apply κ a, Measure.sum_apply _ hs] #align probability_theory.kernel.sum_apply' ProbabilityTheory.kernel.sum_apply' @[simp] theorem sum_zero [Countable ι] : (kernel.sum fun _ : ι => (0 : kernel α β)) = 0 := by ext a s hs rw [sum_apply' _ a hs] simp only [zero_apply, Measure.coe_zero, Pi.zero_apply, tsum_zero] #align probability_theory.kernel.sum_zero ProbabilityTheory.kernel.sum_zero theorem sum_comm [Countable ι] (κ : ι → ι → kernel α β) : (kernel.sum fun n => kernel.sum (κ n)) = kernel.sum fun m => kernel.sum fun n => κ n m := by ext a s; simp_rw [sum_apply]; rw [Measure.sum_comm] #align probability_theory.kernel.sum_comm ProbabilityTheory.kernel.sum_comm @[simp] theorem sum_fintype [Fintype ι] (κ : ι → kernel α β) : kernel.sum κ = ∑ i, κ i := by ext a s hs simp only [sum_apply' κ a hs, finset_sum_apply' _ κ a s, tsum_fintype] #align probability_theory.kernel.sum_fintype ProbabilityTheory.kernel.sum_fintype theorem sum_add [Countable ι] (κ η : ι → kernel α β) : (kernel.sum fun n => κ n + η n) = kernel.sum κ + kernel.sum η := by ext a s hs simp only [coeFn_add, Pi.add_apply, sum_apply, Measure.sum_apply _ hs, Pi.add_apply, Measure.coe_add, tsum_add ENNReal.summable ENNReal.summable] #align probability_theory.kernel.sum_add ProbabilityTheory.kernel.sum_add end Sum section SFinite /-- A kernel is s-finite if it can be written as the sum of countably many finite kernels. -/ class _root_.ProbabilityTheory.IsSFiniteKernel (κ : kernel α β) : Prop where tsum_finite : ∃ κs : ℕ → kernel α β, (∀ n, IsFiniteKernel (κs n)) ∧ κ = kernel.sum κs #align probability_theory.is_s_finite_kernel ProbabilityTheory.IsSFiniteKernel instance (priority := 100) IsFiniteKernel.isSFiniteKernel [h : IsFiniteKernel κ] : IsSFiniteKernel κ := ⟨⟨fun n => if n = 0 then κ else 0, fun n => by simp only; split_ifs · exact h · infer_instance, by ext a s hs rw [kernel.sum_apply' _ _ hs] have : (fun i => ((ite (i = 0) κ 0) a) s) = fun i => ite (i = 0) (κ a s) 0 := by ext1 i; split_ifs <;> rfl rw [this, tsum_ite_eq]⟩⟩ #align probability_theory.kernel.is_finite_kernel.is_s_finite_kernel ProbabilityTheory.kernel.IsFiniteKernel.isSFiniteKernel /-- A sequence of finite kernels such that `κ = ProbabilityTheory.kernel.sum (seq κ)`. See `ProbabilityTheory.kernel.isFiniteKernel_seq` and `ProbabilityTheory.kernel.kernel_sum_seq`. -/ noncomputable def seq (κ : kernel α β) [h : IsSFiniteKernel κ] : ℕ → kernel α β := h.tsum_finite.choose #align probability_theory.kernel.seq ProbabilityTheory.kernel.seq theorem kernel_sum_seq (κ : kernel α β) [h : IsSFiniteKernel κ] : kernel.sum (seq κ) = κ := h.tsum_finite.choose_spec.2.symm #align probability_theory.kernel.kernel_sum_seq ProbabilityTheory.kernel.kernel_sum_seq theorem measure_sum_seq (κ : kernel α β) [h : IsSFiniteKernel κ] (a : α) : (Measure.sum fun n => seq κ n a) = κ a := by rw [← kernel.sum_apply, kernel_sum_seq κ] #align probability_theory.kernel.measure_sum_seq ProbabilityTheory.kernel.measure_sum_seq instance isFiniteKernel_seq (κ : kernel α β) [h : IsSFiniteKernel κ] (n : ℕ) : IsFiniteKernel (kernel.seq κ n) := h.tsum_finite.choose_spec.1 n #align probability_theory.kernel.is_finite_kernel_seq ProbabilityTheory.kernel.isFiniteKernel_seq instance IsSFiniteKernel.sFinite [IsSFiniteKernel κ] (a : α) : SFinite (κ a) := ⟨⟨fun n ↦ seq κ n a, inferInstance, (measure_sum_seq κ a).symm⟩⟩ instance IsSFiniteKernel.add (κ η : kernel α β) [IsSFiniteKernel κ] [IsSFiniteKernel η] : IsSFiniteKernel (κ + η) := by refine ⟨⟨fun n => seq κ n + seq η n, fun n => inferInstance, ?_⟩⟩ rw [sum_add, kernel_sum_seq κ, kernel_sum_seq η] #align probability_theory.kernel.is_s_finite_kernel.add ProbabilityTheory.kernel.IsSFiniteKernel.add theorem IsSFiniteKernel.finset_sum {κs : ι → kernel α β} (I : Finset ι) (h : ∀ i ∈ I, IsSFiniteKernel (κs i)) : IsSFiniteKernel (∑ i ∈ I, κs i) := by classical induction' I using Finset.induction with i I hi_nmem_I h_ind h · rw [Finset.sum_empty]; infer_instance · rw [Finset.sum_insert hi_nmem_I] haveI : IsSFiniteKernel (κs i) := h i (Finset.mem_insert_self _ _) have : IsSFiniteKernel (∑ x ∈ I, κs x) := h_ind fun i hiI => h i (Finset.mem_insert_of_mem hiI) exact IsSFiniteKernel.add _ _ #align probability_theory.kernel.is_s_finite_kernel.finset_sum ProbabilityTheory.kernel.IsSFiniteKernel.finset_sum theorem isSFiniteKernel_sum_of_denumerable [Denumerable ι] {κs : ι → kernel α β} (hκs : ∀ n, IsSFiniteKernel (κs n)) : IsSFiniteKernel (kernel.sum κs) := by let e : ℕ ≃ ι × ℕ := (Denumerable.eqv (ι × ℕ)).symm refine ⟨⟨fun n => seq (κs (e n).1) (e n).2, inferInstance, ?_⟩⟩ have hκ_eq : kernel.sum κs = kernel.sum fun n => kernel.sum (seq (κs n)) := by simp_rw [kernel_sum_seq] ext a s hs rw [hκ_eq] simp_rw [kernel.sum_apply' _ _ hs] change (∑' i, ∑' m, seq (κs i) m a s) = ∑' n, (fun im : ι × ℕ => seq (κs im.fst) im.snd a s) (e n) rw [e.tsum_eq (fun im : ι × ℕ => seq (κs im.fst) im.snd a s), tsum_prod' ENNReal.summable fun _ => ENNReal.summable] #align probability_theory.kernel.is_s_finite_kernel_sum_of_denumerable ProbabilityTheory.kernel.isSFiniteKernel_sum_of_denumerable theorem isSFiniteKernel_sum [Countable ι] {κs : ι → kernel α β} (hκs : ∀ n, IsSFiniteKernel (κs n)) : IsSFiniteKernel (kernel.sum κs) := by cases fintypeOrInfinite ι · rw [sum_fintype] exact IsSFiniteKernel.finset_sum Finset.univ fun i _ => hκs i cases nonempty_denumerable ι exact isSFiniteKernel_sum_of_denumerable hκs #align probability_theory.kernel.is_s_finite_kernel_sum ProbabilityTheory.kernel.isSFiniteKernel_sum end SFinite section Deterministic /-- Kernel which to `a` associates the dirac measure at `f a`. This is a Markov kernel. -/ noncomputable def deterministic (f : α → β) (hf : Measurable f) : kernel α β where val a := Measure.dirac (f a) property := by refine Measure.measurable_of_measurable_coe _ fun s hs => ?_ simp_rw [Measure.dirac_apply' _ hs] exact measurable_one.indicator (hf hs) #align probability_theory.kernel.deterministic ProbabilityTheory.kernel.deterministic theorem deterministic_apply {f : α → β} (hf : Measurable f) (a : α) : deterministic f hf a = Measure.dirac (f a) := rfl #align probability_theory.kernel.deterministic_apply ProbabilityTheory.kernel.deterministic_apply theorem deterministic_apply' {f : α → β} (hf : Measurable f) (a : α) {s : Set β} (hs : MeasurableSet s) : deterministic f hf a s = s.indicator (fun _ => 1) (f a) := by rw [deterministic] change Measure.dirac (f a) s = s.indicator 1 (f a) simp_rw [Measure.dirac_apply' _ hs] #align probability_theory.kernel.deterministic_apply' ProbabilityTheory.kernel.deterministic_apply' instance isMarkovKernel_deterministic {f : α → β} (hf : Measurable f) : IsMarkovKernel (deterministic f hf) := ⟨fun a => by rw [deterministic_apply hf]; infer_instance⟩ #align probability_theory.kernel.is_markov_kernel_deterministic ProbabilityTheory.kernel.isMarkovKernel_deterministic theorem lintegral_deterministic' {f : β → ℝ≥0∞} {g : α → β} {a : α} (hg : Measurable g) (hf : Measurable f) : ∫⁻ x, f x ∂kernel.deterministic g hg a = f (g a) := by rw [kernel.deterministic_apply, lintegral_dirac' _ hf] #align probability_theory.kernel.lintegral_deterministic' ProbabilityTheory.kernel.lintegral_deterministic' @[simp]
Mathlib/Probability/Kernel/Basic.lean
409
411
theorem lintegral_deterministic {f : β → ℝ≥0∞} {g : α → β} {a : α} (hg : Measurable g) [MeasurableSingletonClass β] : ∫⁻ x, f x ∂kernel.deterministic g hg a = f (g a) := by
rw [kernel.deterministic_apply, lintegral_dirac (g a) f]
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.Analysis.InnerProductSpace.Basic import Mathlib.Analysis.NormedSpace.Dual import Mathlib.MeasureTheory.Function.StronglyMeasurable.Lp import Mathlib.MeasureTheory.Integral.SetIntegral #align_import measure_theory.function.ae_eq_of_integral from "leanprover-community/mathlib"@"915591b2bb3ea303648db07284a161a7f2a9e3d4" /-! # From equality of integrals to equality of functions This file provides various statements of the general form "if two functions have the same integral on all sets, then they are equal almost everywhere". The different lemmas use various hypotheses on the class of functions, on the target space or on the possible finiteness of the measure. ## Main statements All results listed below apply to two functions `f, g`, together with two main hypotheses, * `f` and `g` are integrable on all measurable sets with finite measure, * for all measurable sets `s` with finite measure, `∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ`. The conclusion is then `f =ᵐ[μ] g`. The main lemmas are: * `ae_eq_of_forall_setIntegral_eq_of_sigmaFinite`: case of a sigma-finite measure. * `AEFinStronglyMeasurable.ae_eq_of_forall_setIntegral_eq`: for functions which are `AEFinStronglyMeasurable`. * `Lp.ae_eq_of_forall_setIntegral_eq`: for elements of `Lp`, for `0 < p < ∞`. * `Integrable.ae_eq_of_forall_setIntegral_eq`: for integrable functions. For each of these results, we also provide a lemma about the equality of one function and 0. For example, `Lp.ae_eq_zero_of_forall_setIntegral_eq_zero`. We also register the corresponding lemma for integrals of `ℝ≥0∞`-valued functions, in `ae_eq_of_forall_set_lintegral_eq_of_sigmaFinite`. Generally useful lemmas which are not related to integrals: * `ae_eq_zero_of_forall_inner`: if for all constants `c`, `fun x => inner c (f x) =ᵐ[μ] 0` then `f =ᵐ[μ] 0`. * `ae_eq_zero_of_forall_dual`: if for all constants `c` in the dual space, `fun x => c (f x) =ᵐ[μ] 0` then `f =ᵐ[μ] 0`. -/ open MeasureTheory TopologicalSpace NormedSpace Filter open scoped ENNReal NNReal MeasureTheory Topology namespace MeasureTheory section AeEqOfForall variable {α E 𝕜 : Type*} {m : MeasurableSpace α} {μ : Measure α} [RCLike 𝕜] theorem ae_eq_zero_of_forall_inner [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [SecondCountableTopology E] {f : α → E} (hf : ∀ c : E, (fun x => (inner c (f x) : 𝕜)) =ᵐ[μ] 0) : f =ᵐ[μ] 0 := by let s := denseSeq E have hs : DenseRange s := denseRange_denseSeq E have hf' : ∀ᵐ x ∂μ, ∀ n : ℕ, inner (s n) (f x) = (0 : 𝕜) := ae_all_iff.mpr fun n => hf (s n) refine hf'.mono fun x hx => ?_ rw [Pi.zero_apply, ← @inner_self_eq_zero 𝕜] have h_closed : IsClosed {c : E | inner c (f x) = (0 : 𝕜)} := isClosed_eq (continuous_id.inner continuous_const) continuous_const exact @isClosed_property ℕ E _ s (fun c => inner c (f x) = (0 : 𝕜)) hs h_closed (fun n => hx n) _ #align measure_theory.ae_eq_zero_of_forall_inner MeasureTheory.ae_eq_zero_of_forall_inner local notation "⟪" x ", " y "⟫" => y x variable (𝕜) theorem ae_eq_zero_of_forall_dual_of_isSeparable [NormedAddCommGroup E] [NormedSpace 𝕜 E] {t : Set E} (ht : TopologicalSpace.IsSeparable t) {f : α → E} (hf : ∀ c : Dual 𝕜 E, (fun x => ⟪f x, c⟫) =ᵐ[μ] 0) (h't : ∀ᵐ x ∂μ, f x ∈ t) : f =ᵐ[μ] 0 := by rcases ht with ⟨d, d_count, hd⟩ haveI : Encodable d := d_count.toEncodable have : ∀ x : d, ∃ g : E →L[𝕜] 𝕜, ‖g‖ ≤ 1 ∧ g x = ‖(x : E)‖ := fun x => exists_dual_vector'' 𝕜 (x : E) choose s hs using this have A : ∀ a : E, a ∈ t → (∀ x, ⟪a, s x⟫ = (0 : 𝕜)) → a = 0 := by intro a hat ha contrapose! ha have a_pos : 0 < ‖a‖ := by simp only [ha, norm_pos_iff, Ne, not_false_iff] have a_mem : a ∈ closure d := hd hat obtain ⟨x, hx⟩ : ∃ x : d, dist a x < ‖a‖ / 2 := by rcases Metric.mem_closure_iff.1 a_mem (‖a‖ / 2) (half_pos a_pos) with ⟨x, h'x, hx⟩ exact ⟨⟨x, h'x⟩, hx⟩ use x have I : ‖a‖ / 2 < ‖(x : E)‖ := by have : ‖a‖ ≤ ‖(x : E)‖ + ‖a - x‖ := norm_le_insert' _ _ have : ‖a - x‖ < ‖a‖ / 2 := by rwa [dist_eq_norm] at hx linarith intro h apply lt_irrefl ‖s x x‖ calc ‖s x x‖ = ‖s x (x - a)‖ := by simp only [h, sub_zero, ContinuousLinearMap.map_sub] _ ≤ 1 * ‖(x : E) - a‖ := ContinuousLinearMap.le_of_opNorm_le _ (hs x).1 _ _ < ‖a‖ / 2 := by rw [one_mul]; rwa [dist_eq_norm'] at hx _ < ‖(x : E)‖ := I _ = ‖s x x‖ := by rw [(hs x).2, RCLike.norm_coe_norm] have hfs : ∀ y : d, ∀ᵐ x ∂μ, ⟪f x, s y⟫ = (0 : 𝕜) := fun y => hf (s y) have hf' : ∀ᵐ x ∂μ, ∀ y : d, ⟪f x, s y⟫ = (0 : 𝕜) := by rwa [ae_all_iff] filter_upwards [hf', h't] with x hx h'x exact A (f x) h'x hx #align measure_theory.ae_eq_zero_of_forall_dual_of_is_separable MeasureTheory.ae_eq_zero_of_forall_dual_of_isSeparable theorem ae_eq_zero_of_forall_dual [NormedAddCommGroup E] [NormedSpace 𝕜 E] [SecondCountableTopology E] {f : α → E} (hf : ∀ c : Dual 𝕜 E, (fun x => ⟪f x, c⟫) =ᵐ[μ] 0) : f =ᵐ[μ] 0 := ae_eq_zero_of_forall_dual_of_isSeparable 𝕜 (.of_separableSpace Set.univ) hf (eventually_of_forall fun _ => Set.mem_univ _) #align measure_theory.ae_eq_zero_of_forall_dual MeasureTheory.ae_eq_zero_of_forall_dual variable {𝕜} end AeEqOfForall variable {α E : Type*} {m m0 : MeasurableSpace α} {μ : Measure α} {s t : Set α} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {p : ℝ≥0∞} section AeEqOfForallSetIntegralEq theorem ae_const_le_iff_forall_lt_measure_zero {β} [LinearOrder β] [TopologicalSpace β] [OrderTopology β] [FirstCountableTopology β] (f : α → β) (c : β) : (∀ᵐ x ∂μ, c ≤ f x) ↔ ∀ b < c, μ {x | f x ≤ b} = 0 := by rw [ae_iff] push_neg constructor · intro h b hb exact measure_mono_null (fun y hy => (lt_of_le_of_lt hy hb : _)) h intro hc by_cases h : ∀ b, c ≤ b · have : {a : α | f a < c} = ∅ := by apply Set.eq_empty_iff_forall_not_mem.2 fun x hx => ?_ exact (lt_irrefl _ (lt_of_lt_of_le hx (h (f x)))).elim simp [this] by_cases H : ¬IsLUB (Set.Iio c) c · have : c ∈ upperBounds (Set.Iio c) := fun y hy => le_of_lt hy obtain ⟨b, b_up, bc⟩ : ∃ b : β, b ∈ upperBounds (Set.Iio c) ∧ b < c := by simpa [IsLUB, IsLeast, this, lowerBounds] using H exact measure_mono_null (fun x hx => b_up hx) (hc b bc) push_neg at H h obtain ⟨u, _, u_lt, u_lim, -⟩ : ∃ u : ℕ → β, StrictMono u ∧ (∀ n : ℕ, u n < c) ∧ Tendsto u atTop (𝓝 c) ∧ ∀ n : ℕ, u n ∈ Set.Iio c := H.exists_seq_strictMono_tendsto_of_not_mem (lt_irrefl c) h have h_Union : {x | f x < c} = ⋃ n : ℕ, {x | f x ≤ u n} := by ext1 x simp_rw [Set.mem_iUnion, Set.mem_setOf_eq] constructor <;> intro h · obtain ⟨n, hn⟩ := ((tendsto_order.1 u_lim).1 _ h).exists; exact ⟨n, hn.le⟩ · obtain ⟨n, hn⟩ := h; exact hn.trans_lt (u_lt _) rw [h_Union, measure_iUnion_null_iff] intro n exact hc _ (u_lt n) #align measure_theory.ae_const_le_iff_forall_lt_measure_zero MeasureTheory.ae_const_le_iff_forall_lt_measure_zero section ENNReal open scoped Topology theorem ae_le_of_forall_set_lintegral_le_of_sigmaFinite [SigmaFinite μ] {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) (h : ∀ s, MeasurableSet s → μ s < ∞ → (∫⁻ x in s, f x ∂μ) ≤ ∫⁻ x in s, g x ∂μ) : f ≤ᵐ[μ] g := by have A : ∀ (ε N : ℝ≥0) (p : ℕ), 0 < ε → μ ({x | g x + ε ≤ f x ∧ g x ≤ N} ∩ spanningSets μ p) = 0 := by intro ε N p εpos let s := {x | g x + ε ≤ f x ∧ g x ≤ N} ∩ spanningSets μ p have s_meas : MeasurableSet s := by have A : MeasurableSet {x | g x + ε ≤ f x} := measurableSet_le (hg.add measurable_const) hf have B : MeasurableSet {x | g x ≤ N} := measurableSet_le hg measurable_const exact (A.inter B).inter (measurable_spanningSets μ p) have s_lt_top : μ s < ∞ := (measure_mono (Set.inter_subset_right)).trans_lt (measure_spanningSets_lt_top μ p) have A : (∫⁻ x in s, g x ∂μ) + ε * μ s ≤ (∫⁻ x in s, g x ∂μ) + 0 := calc (∫⁻ x in s, g x ∂μ) + ε * μ s = (∫⁻ x in s, g x ∂μ) + ∫⁻ _ in s, ε ∂μ := by simp only [lintegral_const, Set.univ_inter, MeasurableSet.univ, Measure.restrict_apply] _ = ∫⁻ x in s, g x + ε ∂μ := (lintegral_add_right _ measurable_const).symm _ ≤ ∫⁻ x in s, f x ∂μ := (set_lintegral_mono (hg.add measurable_const) hf fun x hx => hx.1.1) _ ≤ (∫⁻ x in s, g x ∂μ) + 0 := by rw [add_zero]; exact h s s_meas s_lt_top have B : (∫⁻ x in s, g x ∂μ) ≠ ∞ := by apply ne_of_lt calc (∫⁻ x in s, g x ∂μ) ≤ ∫⁻ _ in s, N ∂μ := set_lintegral_mono hg measurable_const fun x hx => hx.1.2 _ = N * μ s := by simp only [lintegral_const, Set.univ_inter, MeasurableSet.univ, Measure.restrict_apply] _ < ∞ := by simp only [lt_top_iff_ne_top, s_lt_top.ne, and_false_iff, ENNReal.coe_ne_top, ENNReal.mul_eq_top, Ne, not_false_iff, false_and_iff, or_self_iff] have : (ε : ℝ≥0∞) * μ s ≤ 0 := ENNReal.le_of_add_le_add_left B A simpa only [ENNReal.coe_eq_zero, nonpos_iff_eq_zero, mul_eq_zero, εpos.ne', false_or_iff] obtain ⟨u, _, u_pos, u_lim⟩ : ∃ u : ℕ → ℝ≥0, StrictAnti u ∧ (∀ n, 0 < u n) ∧ Tendsto u atTop (𝓝 0) := exists_seq_strictAnti_tendsto (0 : ℝ≥0) let s := fun n : ℕ => {x | g x + u n ≤ f x ∧ g x ≤ (n : ℝ≥0)} ∩ spanningSets μ n have μs : ∀ n, μ (s n) = 0 := fun n => A _ _ _ (u_pos n) have B : {x | f x ≤ g x}ᶜ ⊆ ⋃ n, s n := by intro x hx simp only [Set.mem_compl_iff, Set.mem_setOf, not_le] at hx have L1 : ∀ᶠ n in atTop, g x + u n ≤ f x := by have : Tendsto (fun n => g x + u n) atTop (𝓝 (g x + (0 : ℝ≥0))) := tendsto_const_nhds.add (ENNReal.tendsto_coe.2 u_lim) simp only [ENNReal.coe_zero, add_zero] at this exact eventually_le_of_tendsto_lt hx this have L2 : ∀ᶠ n : ℕ in (atTop : Filter ℕ), g x ≤ (n : ℝ≥0) := haveI : Tendsto (fun n : ℕ => ((n : ℝ≥0) : ℝ≥0∞)) atTop (𝓝 ∞) := by simp only [ENNReal.coe_natCast] exact ENNReal.tendsto_nat_nhds_top eventually_ge_of_tendsto_gt (hx.trans_le le_top) this apply Set.mem_iUnion.2 exact ((L1.and L2).and (eventually_mem_spanningSets μ x)).exists refine le_antisymm ?_ bot_le calc μ {x : α | (fun x : α => f x ≤ g x) x}ᶜ ≤ μ (⋃ n, s n) := measure_mono B _ ≤ ∑' n, μ (s n) := measure_iUnion_le _ _ = 0 := by simp only [μs, tsum_zero] #align measure_theory.ae_le_of_forall_set_lintegral_le_of_sigma_finite MeasureTheory.ae_le_of_forall_set_lintegral_le_of_sigmaFinite theorem ae_le_of_forall_set_lintegral_le_of_sigmaFinite₀ [SigmaFinite μ] {f g : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) (h : ∀ s, MeasurableSet s → μ s < ∞ → ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ) : f ≤ᵐ[μ] g := by have h' : ∀ s, MeasurableSet s → μ s < ∞ → ∫⁻ x in s, hf.mk f x ∂μ ≤ ∫⁻ x in s, hg.mk g x ∂μ := by refine fun s hs hμs ↦ (set_lintegral_congr_fun hs ?_).trans_le ((h s hs hμs).trans_eq (set_lintegral_congr_fun hs ?_)) · filter_upwards [hf.ae_eq_mk] with a ha using fun _ ↦ ha.symm · filter_upwards [hg.ae_eq_mk] with a ha using fun _ ↦ ha filter_upwards [hf.ae_eq_mk, hg.ae_eq_mk, ae_le_of_forall_set_lintegral_le_of_sigmaFinite hf.measurable_mk hg.measurable_mk h'] with a haf hag ha rwa [haf, hag] theorem ae_eq_of_forall_set_lintegral_eq_of_sigmaFinite₀ [SigmaFinite μ] {f g : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) (h : ∀ s, MeasurableSet s → μ s < ∞ → ∫⁻ x in s, f x ∂μ = ∫⁻ x in s, g x ∂μ) : f =ᵐ[μ] g := by have A : f ≤ᵐ[μ] g := ae_le_of_forall_set_lintegral_le_of_sigmaFinite₀ hf hg fun s hs h's => le_of_eq (h s hs h's) have B : g ≤ᵐ[μ] f := ae_le_of_forall_set_lintegral_le_of_sigmaFinite₀ hg hf fun s hs h's => ge_of_eq (h s hs h's) filter_upwards [A, B] with x using le_antisymm theorem ae_eq_of_forall_set_lintegral_eq_of_sigmaFinite [SigmaFinite μ] {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) (h : ∀ s, MeasurableSet s → μ s < ∞ → ∫⁻ x in s, f x ∂μ = ∫⁻ x in s, g x ∂μ) : f =ᵐ[μ] g := ae_eq_of_forall_set_lintegral_eq_of_sigmaFinite₀ hf.aemeasurable hg.aemeasurable h #align measure_theory.ae_eq_of_forall_set_lintegral_eq_of_sigma_finite MeasureTheory.ae_eq_of_forall_set_lintegral_eq_of_sigmaFinite end ENNReal section Real variable {f : α → ℝ} /-- Don't use this lemma. Use `ae_nonneg_of_forall_setIntegral_nonneg`. -/ theorem ae_nonneg_of_forall_setIntegral_nonneg_of_stronglyMeasurable (hfm : StronglyMeasurable f) (hf : Integrable f μ) (hf_zero : ∀ s, MeasurableSet s → μ s < ∞ → 0 ≤ ∫ x in s, f x ∂μ) : 0 ≤ᵐ[μ] f := by simp_rw [EventuallyLE, Pi.zero_apply] rw [ae_const_le_iff_forall_lt_measure_zero] intro b hb_neg let s := {x | f x ≤ b} have hs : MeasurableSet s := hfm.measurableSet_le stronglyMeasurable_const have mus : μ s < ∞ := Integrable.measure_le_lt_top hf hb_neg have h_int_gt : (∫ x in s, f x ∂μ) ≤ b * (μ s).toReal := by have h_const_le : (∫ x in s, f x ∂μ) ≤ ∫ _ in s, b ∂μ := by refine setIntegral_mono_ae_restrict hf.integrableOn (integrableOn_const.mpr (Or.inr mus)) ?_ rw [EventuallyLE, ae_restrict_iff hs] exact eventually_of_forall fun x hxs => hxs rwa [setIntegral_const, smul_eq_mul, mul_comm] at h_const_le by_contra h refine (lt_self_iff_false (∫ x in s, f x ∂μ)).mp (h_int_gt.trans_lt ?_) refine (mul_neg_iff.mpr (Or.inr ⟨hb_neg, ?_⟩)).trans_le ?_ swap · exact hf_zero s hs mus refine ENNReal.toReal_nonneg.lt_of_ne fun h_eq => h ?_ cases' (ENNReal.toReal_eq_zero_iff _).mp h_eq.symm with hμs_eq_zero hμs_eq_top · exact hμs_eq_zero · exact absurd hμs_eq_top mus.ne #align measure_theory.ae_nonneg_of_forall_set_integral_nonneg_of_strongly_measurable MeasureTheory.ae_nonneg_of_forall_setIntegral_nonneg_of_stronglyMeasurable @[deprecated (since := "2024-04-17")] alias ae_nonneg_of_forall_set_integral_nonneg_of_stronglyMeasurable := ae_nonneg_of_forall_setIntegral_nonneg_of_stronglyMeasurable theorem ae_nonneg_of_forall_setIntegral_nonneg (hf : Integrable f μ) (hf_zero : ∀ s, MeasurableSet s → μ s < ∞ → 0 ≤ ∫ x in s, f x ∂μ) : 0 ≤ᵐ[μ] f := by rcases hf.1 with ⟨f', hf'_meas, hf_ae⟩ have hf'_integrable : Integrable f' μ := Integrable.congr hf hf_ae have hf'_zero : ∀ s, MeasurableSet s → μ s < ∞ → 0 ≤ ∫ x in s, f' x ∂μ := by intro s hs h's rw [setIntegral_congr_ae hs (hf_ae.mono fun x hx _ => hx.symm)] exact hf_zero s hs h's exact (ae_nonneg_of_forall_setIntegral_nonneg_of_stronglyMeasurable hf'_meas hf'_integrable hf'_zero).trans hf_ae.symm.le #align measure_theory.ae_nonneg_of_forall_set_integral_nonneg MeasureTheory.ae_nonneg_of_forall_setIntegral_nonneg @[deprecated (since := "2024-04-17")] alias ae_nonneg_of_forall_set_integral_nonneg := ae_nonneg_of_forall_setIntegral_nonneg theorem ae_le_of_forall_setIntegral_le {f g : α → ℝ} (hf : Integrable f μ) (hg : Integrable g μ) (hf_le : ∀ s, MeasurableSet s → μ s < ∞ → (∫ x in s, f x ∂μ) ≤ ∫ x in s, g x ∂μ) : f ≤ᵐ[μ] g := by rw [← eventually_sub_nonneg] refine ae_nonneg_of_forall_setIntegral_nonneg (hg.sub hf) fun s hs => ?_ rw [integral_sub' hg.integrableOn hf.integrableOn, sub_nonneg] exact hf_le s hs #align measure_theory.ae_le_of_forall_set_integral_le MeasureTheory.ae_le_of_forall_setIntegral_le @[deprecated (since := "2024-04-17")] alias ae_le_of_forall_set_integral_le := ae_le_of_forall_setIntegral_le theorem ae_nonneg_restrict_of_forall_setIntegral_nonneg_inter {f : α → ℝ} {t : Set α} (hf : IntegrableOn f t μ) (hf_zero : ∀ s, MeasurableSet s → μ (s ∩ t) < ∞ → 0 ≤ ∫ x in s ∩ t, f x ∂μ) : 0 ≤ᵐ[μ.restrict t] f := by refine ae_nonneg_of_forall_setIntegral_nonneg hf fun s hs h's => ?_ simp_rw [Measure.restrict_restrict hs] apply hf_zero s hs rwa [Measure.restrict_apply hs] at h's #align measure_theory.ae_nonneg_restrict_of_forall_set_integral_nonneg_inter MeasureTheory.ae_nonneg_restrict_of_forall_setIntegral_nonneg_inter @[deprecated (since := "2024-04-17")] alias ae_nonneg_restrict_of_forall_set_integral_nonneg_inter := ae_nonneg_restrict_of_forall_setIntegral_nonneg_inter theorem ae_nonneg_of_forall_setIntegral_nonneg_of_sigmaFinite [SigmaFinite μ] {f : α → ℝ} (hf_int_finite : ∀ s, MeasurableSet s → μ s < ∞ → IntegrableOn f s μ) (hf_zero : ∀ s, MeasurableSet s → μ s < ∞ → 0 ≤ ∫ x in s, f x ∂μ) : 0 ≤ᵐ[μ] f := by apply ae_of_forall_measure_lt_top_ae_restrict intro t t_meas t_lt_top apply ae_nonneg_restrict_of_forall_setIntegral_nonneg_inter (hf_int_finite t t_meas t_lt_top) intro s s_meas _ exact hf_zero _ (s_meas.inter t_meas) (lt_of_le_of_lt (measure_mono (Set.inter_subset_right)) t_lt_top) #align measure_theory.ae_nonneg_of_forall_set_integral_nonneg_of_sigma_finite MeasureTheory.ae_nonneg_of_forall_setIntegral_nonneg_of_sigmaFinite @[deprecated (since := "2024-04-17")] alias ae_nonneg_of_forall_set_integral_nonneg_of_sigmaFinite := ae_nonneg_of_forall_setIntegral_nonneg_of_sigmaFinite theorem AEFinStronglyMeasurable.ae_nonneg_of_forall_setIntegral_nonneg {f : α → ℝ} (hf : AEFinStronglyMeasurable f μ) (hf_int_finite : ∀ s, MeasurableSet s → μ s < ∞ → IntegrableOn f s μ) (hf_zero : ∀ s, MeasurableSet s → μ s < ∞ → 0 ≤ ∫ x in s, f x ∂μ) : 0 ≤ᵐ[μ] f := by let t := hf.sigmaFiniteSet suffices 0 ≤ᵐ[μ.restrict t] f from ae_of_ae_restrict_of_ae_restrict_compl _ this hf.ae_eq_zero_compl.symm.le haveI : SigmaFinite (μ.restrict t) := hf.sigmaFinite_restrict refine ae_nonneg_of_forall_setIntegral_nonneg_of_sigmaFinite (fun s hs hμts => ?_) fun s hs hμts => ?_ · rw [IntegrableOn, Measure.restrict_restrict hs] rw [Measure.restrict_apply hs] at hμts exact hf_int_finite (s ∩ t) (hs.inter hf.measurableSet) hμts · rw [Measure.restrict_restrict hs] rw [Measure.restrict_apply hs] at hμts exact hf_zero (s ∩ t) (hs.inter hf.measurableSet) hμts #align measure_theory.ae_fin_strongly_measurable.ae_nonneg_of_forall_set_integral_nonneg MeasureTheory.AEFinStronglyMeasurable.ae_nonneg_of_forall_setIntegral_nonneg @[deprecated (since := "2024-04-17")] alias AEFinStronglyMeasurable.ae_nonneg_of_forall_set_integral_nonneg := AEFinStronglyMeasurable.ae_nonneg_of_forall_setIntegral_nonneg
Mathlib/MeasureTheory/Function/AEEqOfIntegral.lean
373
381
theorem ae_nonneg_restrict_of_forall_setIntegral_nonneg {f : α → ℝ} (hf_int_finite : ∀ s, MeasurableSet s → μ s < ∞ → IntegrableOn f s μ) (hf_zero : ∀ s, MeasurableSet s → μ s < ∞ → 0 ≤ ∫ x in s, f x ∂μ) {t : Set α} (ht : MeasurableSet t) (hμt : μ t ≠ ∞) : 0 ≤ᵐ[μ.restrict t] f := by
refine ae_nonneg_restrict_of_forall_setIntegral_nonneg_inter (hf_int_finite t ht (lt_top_iff_ne_top.mpr hμt)) fun s hs _ => ?_ refine hf_zero (s ∩ t) (hs.inter ht) ?_ exact (measure_mono Set.inter_subset_right).trans_lt (lt_top_iff_ne_top.mpr hμt)
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura -/ import Mathlib.Init.ZeroOne import Mathlib.Data.Set.Defs import Mathlib.Order.Basic import Mathlib.Order.SymmDiff import Mathlib.Tactic.Tauto import Mathlib.Tactic.ByContra import Mathlib.Util.Delaborators #align_import data.set.basic from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29" /-! # Basic properties of sets Sets in Lean are homogeneous; all their elements have the same type. Sets whose elements have type `X` are thus defined as `Set X := X → Prop`. Note that this function need not be decidable. The definition is in the core library. This file provides some basic definitions related to sets and functions not present in the core library, as well as extra lemmas for functions in the core library (empty set, univ, union, intersection, insert, singleton, set-theoretic difference, complement, and powerset). Note that a set is a term, not a type. There is a coercion from `Set α` to `Type*` sending `s` to the corresponding subtype `↥s`. See also the file `SetTheory/ZFC.lean`, which contains an encoding of ZFC set theory in Lean. ## Main definitions Notation used here: - `f : α → β` is a function, - `s : Set α` and `s₁ s₂ : Set α` are subsets of `α` - `t : Set β` is a subset of `β`. Definitions in the file: * `Nonempty s : Prop` : the predicate `s ≠ ∅`. Note that this is the preferred way to express the fact that `s` has an element (see the Implementation Notes). * `inclusion s₁ s₂ : ↥s₁ → ↥s₂` : the map `↥s₁ → ↥s₂` induced by an inclusion `s₁ ⊆ s₂`. ## Notation * `sᶜ` for the complement of `s` ## Implementation notes * `s.Nonempty` is to be preferred to `s ≠ ∅` or `∃ x, x ∈ s`. It has the advantage that the `s.Nonempty` dot notation can be used. * For `s : Set α`, do not use `Subtype s`. Instead use `↥s` or `(s : Type*)` or `s`. ## Tags set, sets, subset, subsets, union, intersection, insert, singleton, complement, powerset -/ /-! ### Set coercion to a type -/ open Function universe u v w x namespace Set variable {α : Type u} {s t : Set α} instance instBooleanAlgebraSet : BooleanAlgebra (Set α) := { (inferInstance : BooleanAlgebra (α → Prop)) with sup := (· ∪ ·), le := (· ≤ ·), lt := fun s t => s ⊆ t ∧ ¬t ⊆ s, inf := (· ∩ ·), bot := ∅, compl := (·ᶜ), top := univ, sdiff := (· \ ·) } instance : HasSSubset (Set α) := ⟨(· < ·)⟩ @[simp] theorem top_eq_univ : (⊤ : Set α) = univ := rfl #align set.top_eq_univ Set.top_eq_univ @[simp] theorem bot_eq_empty : (⊥ : Set α) = ∅ := rfl #align set.bot_eq_empty Set.bot_eq_empty @[simp] theorem sup_eq_union : ((· ⊔ ·) : Set α → Set α → Set α) = (· ∪ ·) := rfl #align set.sup_eq_union Set.sup_eq_union @[simp] theorem inf_eq_inter : ((· ⊓ ·) : Set α → Set α → Set α) = (· ∩ ·) := rfl #align set.inf_eq_inter Set.inf_eq_inter @[simp] theorem le_eq_subset : ((· ≤ ·) : Set α → Set α → Prop) = (· ⊆ ·) := rfl #align set.le_eq_subset Set.le_eq_subset @[simp] theorem lt_eq_ssubset : ((· < ·) : Set α → Set α → Prop) = (· ⊂ ·) := rfl #align set.lt_eq_ssubset Set.lt_eq_ssubset theorem le_iff_subset : s ≤ t ↔ s ⊆ t := Iff.rfl #align set.le_iff_subset Set.le_iff_subset theorem lt_iff_ssubset : s < t ↔ s ⊂ t := Iff.rfl #align set.lt_iff_ssubset Set.lt_iff_ssubset alias ⟨_root_.LE.le.subset, _root_.HasSubset.Subset.le⟩ := le_iff_subset #align has_subset.subset.le HasSubset.Subset.le alias ⟨_root_.LT.lt.ssubset, _root_.HasSSubset.SSubset.lt⟩ := lt_iff_ssubset #align has_ssubset.ssubset.lt HasSSubset.SSubset.lt instance PiSetCoe.canLift (ι : Type u) (α : ι → Type v) [∀ i, Nonempty (α i)] (s : Set ι) : CanLift (∀ i : s, α i) (∀ i, α i) (fun f i => f i) fun _ => True := PiSubtype.canLift ι α s #align set.pi_set_coe.can_lift Set.PiSetCoe.canLift instance PiSetCoe.canLift' (ι : Type u) (α : Type v) [Nonempty α] (s : Set ι) : CanLift (s → α) (ι → α) (fun f i => f i) fun _ => True := PiSetCoe.canLift ι (fun _ => α) s #align set.pi_set_coe.can_lift' Set.PiSetCoe.canLift' end Set section SetCoe variable {α : Type u} instance (s : Set α) : CoeTC s α := ⟨fun x => x.1⟩ theorem Set.coe_eq_subtype (s : Set α) : ↥s = { x // x ∈ s } := rfl #align set.coe_eq_subtype Set.coe_eq_subtype @[simp] theorem Set.coe_setOf (p : α → Prop) : ↥{ x | p x } = { x // p x } := rfl #align set.coe_set_of Set.coe_setOf -- Porting note (#10618): removed `simp` because `simp` can prove it theorem SetCoe.forall {s : Set α} {p : s → Prop} : (∀ x : s, p x) ↔ ∀ (x) (h : x ∈ s), p ⟨x, h⟩ := Subtype.forall #align set_coe.forall SetCoe.forall -- Porting note (#10618): removed `simp` because `simp` can prove it theorem SetCoe.exists {s : Set α} {p : s → Prop} : (∃ x : s, p x) ↔ ∃ (x : _) (h : x ∈ s), p ⟨x, h⟩ := Subtype.exists #align set_coe.exists SetCoe.exists theorem SetCoe.exists' {s : Set α} {p : ∀ x, x ∈ s → Prop} : (∃ (x : _) (h : x ∈ s), p x h) ↔ ∃ x : s, p x.1 x.2 := (@SetCoe.exists _ _ fun x => p x.1 x.2).symm #align set_coe.exists' SetCoe.exists' theorem SetCoe.forall' {s : Set α} {p : ∀ x, x ∈ s → Prop} : (∀ (x) (h : x ∈ s), p x h) ↔ ∀ x : s, p x.1 x.2 := (@SetCoe.forall _ _ fun x => p x.1 x.2).symm #align set_coe.forall' SetCoe.forall' @[simp] theorem set_coe_cast : ∀ {s t : Set α} (H' : s = t) (H : ↥s = ↥t) (x : s), cast H x = ⟨x.1, H' ▸ x.2⟩ | _, _, rfl, _, _ => rfl #align set_coe_cast set_coe_cast theorem SetCoe.ext {s : Set α} {a b : s} : (a : α) = b → a = b := Subtype.eq #align set_coe.ext SetCoe.ext theorem SetCoe.ext_iff {s : Set α} {a b : s} : (↑a : α) = ↑b ↔ a = b := Iff.intro SetCoe.ext fun h => h ▸ rfl #align set_coe.ext_iff SetCoe.ext_iff end SetCoe /-- See also `Subtype.prop` -/ theorem Subtype.mem {α : Type*} {s : Set α} (p : s) : (p : α) ∈ s := p.prop #align subtype.mem Subtype.mem /-- Duplicate of `Eq.subset'`, which currently has elaboration problems. -/ theorem Eq.subset {α} {s t : Set α} : s = t → s ⊆ t := fun h₁ _ h₂ => by rw [← h₁]; exact h₂ #align eq.subset Eq.subset namespace Set variable {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x} {a b : α} {s s₁ s₂ t t₁ t₂ u : Set α} instance : Inhabited (Set α) := ⟨∅⟩ theorem ext_iff {s t : Set α} : s = t ↔ ∀ x, x ∈ s ↔ x ∈ t := ⟨fun h x => by rw [h], ext⟩ #align set.ext_iff Set.ext_iff @[trans] theorem mem_of_mem_of_subset {x : α} {s t : Set α} (hx : x ∈ s) (h : s ⊆ t) : x ∈ t := h hx #align set.mem_of_mem_of_subset Set.mem_of_mem_of_subset theorem forall_in_swap {p : α → β → Prop} : (∀ a ∈ s, ∀ (b), p a b) ↔ ∀ (b), ∀ a ∈ s, p a b := by tauto #align set.forall_in_swap Set.forall_in_swap /-! ### Lemmas about `mem` and `setOf` -/ theorem mem_setOf {a : α} {p : α → Prop} : a ∈ { x | p x } ↔ p a := Iff.rfl #align set.mem_set_of Set.mem_setOf /-- If `h : a ∈ {x | p x}` then `h.out : p x`. These are definitionally equal, but this can nevertheless be useful for various reasons, e.g. to apply further projection notation or in an argument to `simp`. -/ theorem _root_.Membership.mem.out {p : α → Prop} {a : α} (h : a ∈ { x | p x }) : p a := h #align has_mem.mem.out Membership.mem.out theorem nmem_setOf_iff {a : α} {p : α → Prop} : a ∉ { x | p x } ↔ ¬p a := Iff.rfl #align set.nmem_set_of_iff Set.nmem_setOf_iff @[simp] theorem setOf_mem_eq {s : Set α} : { x | x ∈ s } = s := rfl #align set.set_of_mem_eq Set.setOf_mem_eq theorem setOf_set {s : Set α} : setOf s = s := rfl #align set.set_of_set Set.setOf_set theorem setOf_app_iff {p : α → Prop} {x : α} : { x | p x } x ↔ p x := Iff.rfl #align set.set_of_app_iff Set.setOf_app_iff theorem mem_def {a : α} {s : Set α} : a ∈ s ↔ s a := Iff.rfl #align set.mem_def Set.mem_def theorem setOf_bijective : Bijective (setOf : (α → Prop) → Set α) := bijective_id #align set.set_of_bijective Set.setOf_bijective theorem subset_setOf {p : α → Prop} {s : Set α} : s ⊆ setOf p ↔ ∀ x, x ∈ s → p x := Iff.rfl theorem setOf_subset {p : α → Prop} {s : Set α} : setOf p ⊆ s ↔ ∀ x, p x → x ∈ s := Iff.rfl @[simp] theorem setOf_subset_setOf {p q : α → Prop} : { a | p a } ⊆ { a | q a } ↔ ∀ a, p a → q a := Iff.rfl #align set.set_of_subset_set_of Set.setOf_subset_setOf theorem setOf_and {p q : α → Prop} : { a | p a ∧ q a } = { a | p a } ∩ { a | q a } := rfl #align set.set_of_and Set.setOf_and theorem setOf_or {p q : α → Prop} : { a | p a ∨ q a } = { a | p a } ∪ { a | q a } := rfl #align set.set_of_or Set.setOf_or /-! ### Subset and strict subset relations -/ instance : IsRefl (Set α) (· ⊆ ·) := show IsRefl (Set α) (· ≤ ·) by infer_instance instance : IsTrans (Set α) (· ⊆ ·) := show IsTrans (Set α) (· ≤ ·) by infer_instance instance : Trans ((· ⊆ ·) : Set α → Set α → Prop) (· ⊆ ·) (· ⊆ ·) := show Trans (· ≤ ·) (· ≤ ·) (· ≤ ·) by infer_instance instance : IsAntisymm (Set α) (· ⊆ ·) := show IsAntisymm (Set α) (· ≤ ·) by infer_instance instance : IsIrrefl (Set α) (· ⊂ ·) := show IsIrrefl (Set α) (· < ·) by infer_instance instance : IsTrans (Set α) (· ⊂ ·) := show IsTrans (Set α) (· < ·) by infer_instance instance : Trans ((· ⊂ ·) : Set α → Set α → Prop) (· ⊂ ·) (· ⊂ ·) := show Trans (· < ·) (· < ·) (· < ·) by infer_instance instance : Trans ((· ⊂ ·) : Set α → Set α → Prop) (· ⊆ ·) (· ⊂ ·) := show Trans (· < ·) (· ≤ ·) (· < ·) by infer_instance instance : Trans ((· ⊆ ·) : Set α → Set α → Prop) (· ⊂ ·) (· ⊂ ·) := show Trans (· ≤ ·) (· < ·) (· < ·) by infer_instance instance : IsAsymm (Set α) (· ⊂ ·) := show IsAsymm (Set α) (· < ·) by infer_instance instance : IsNonstrictStrictOrder (Set α) (· ⊆ ·) (· ⊂ ·) := ⟨fun _ _ => Iff.rfl⟩ -- TODO(Jeremy): write a tactic to unfold specific instances of generic notation? theorem subset_def : (s ⊆ t) = ∀ x, x ∈ s → x ∈ t := rfl #align set.subset_def Set.subset_def theorem ssubset_def : (s ⊂ t) = (s ⊆ t ∧ ¬t ⊆ s) := rfl #align set.ssubset_def Set.ssubset_def @[refl] theorem Subset.refl (a : Set α) : a ⊆ a := fun _ => id #align set.subset.refl Set.Subset.refl theorem Subset.rfl {s : Set α} : s ⊆ s := Subset.refl s #align set.subset.rfl Set.Subset.rfl @[trans] theorem Subset.trans {a b c : Set α} (ab : a ⊆ b) (bc : b ⊆ c) : a ⊆ c := fun _ h => bc <| ab h #align set.subset.trans Set.Subset.trans @[trans] theorem mem_of_eq_of_mem {x y : α} {s : Set α} (hx : x = y) (h : y ∈ s) : x ∈ s := hx.symm ▸ h #align set.mem_of_eq_of_mem Set.mem_of_eq_of_mem theorem Subset.antisymm {a b : Set α} (h₁ : a ⊆ b) (h₂ : b ⊆ a) : a = b := Set.ext fun _ => ⟨@h₁ _, @h₂ _⟩ #align set.subset.antisymm Set.Subset.antisymm theorem Subset.antisymm_iff {a b : Set α} : a = b ↔ a ⊆ b ∧ b ⊆ a := ⟨fun e => ⟨e.subset, e.symm.subset⟩, fun ⟨h₁, h₂⟩ => Subset.antisymm h₁ h₂⟩ #align set.subset.antisymm_iff Set.Subset.antisymm_iff -- an alternative name theorem eq_of_subset_of_subset {a b : Set α} : a ⊆ b → b ⊆ a → a = b := Subset.antisymm #align set.eq_of_subset_of_subset Set.eq_of_subset_of_subset theorem mem_of_subset_of_mem {s₁ s₂ : Set α} {a : α} (h : s₁ ⊆ s₂) : a ∈ s₁ → a ∈ s₂ := @h _ #align set.mem_of_subset_of_mem Set.mem_of_subset_of_mem theorem not_mem_subset (h : s ⊆ t) : a ∉ t → a ∉ s := mt <| mem_of_subset_of_mem h #align set.not_mem_subset Set.not_mem_subset theorem not_subset : ¬s ⊆ t ↔ ∃ a ∈ s, a ∉ t := by simp only [subset_def, not_forall, exists_prop] #align set.not_subset Set.not_subset lemma eq_of_forall_subset_iff (h : ∀ u, s ⊆ u ↔ t ⊆ u) : s = t := eq_of_forall_ge_iff h /-! ### Definition of strict subsets `s ⊂ t` and basic properties. -/ protected theorem eq_or_ssubset_of_subset (h : s ⊆ t) : s = t ∨ s ⊂ t := eq_or_lt_of_le h #align set.eq_or_ssubset_of_subset Set.eq_or_ssubset_of_subset theorem exists_of_ssubset {s t : Set α} (h : s ⊂ t) : ∃ x ∈ t, x ∉ s := not_subset.1 h.2 #align set.exists_of_ssubset Set.exists_of_ssubset protected theorem ssubset_iff_subset_ne {s t : Set α} : s ⊂ t ↔ s ⊆ t ∧ s ≠ t := @lt_iff_le_and_ne (Set α) _ s t #align set.ssubset_iff_subset_ne Set.ssubset_iff_subset_ne theorem ssubset_iff_of_subset {s t : Set α} (h : s ⊆ t) : s ⊂ t ↔ ∃ x ∈ t, x ∉ s := ⟨exists_of_ssubset, fun ⟨_, hxt, hxs⟩ => ⟨h, fun h => hxs <| h hxt⟩⟩ #align set.ssubset_iff_of_subset Set.ssubset_iff_of_subset protected theorem ssubset_of_ssubset_of_subset {s₁ s₂ s₃ : Set α} (hs₁s₂ : s₁ ⊂ s₂) (hs₂s₃ : s₂ ⊆ s₃) : s₁ ⊂ s₃ := ⟨Subset.trans hs₁s₂.1 hs₂s₃, fun hs₃s₁ => hs₁s₂.2 (Subset.trans hs₂s₃ hs₃s₁)⟩ #align set.ssubset_of_ssubset_of_subset Set.ssubset_of_ssubset_of_subset protected theorem ssubset_of_subset_of_ssubset {s₁ s₂ s₃ : Set α} (hs₁s₂ : s₁ ⊆ s₂) (hs₂s₃ : s₂ ⊂ s₃) : s₁ ⊂ s₃ := ⟨Subset.trans hs₁s₂ hs₂s₃.1, fun hs₃s₁ => hs₂s₃.2 (Subset.trans hs₃s₁ hs₁s₂)⟩ #align set.ssubset_of_subset_of_ssubset Set.ssubset_of_subset_of_ssubset theorem not_mem_empty (x : α) : ¬x ∈ (∅ : Set α) := id #align set.not_mem_empty Set.not_mem_empty -- Porting note (#10618): removed `simp` because `simp` can prove it theorem not_not_mem : ¬a ∉ s ↔ a ∈ s := not_not #align set.not_not_mem Set.not_not_mem /-! ### Non-empty sets -/ -- Porting note: we seem to need parentheses at `(↥s)`, -- even if we increase the right precedence of `↥` in `Mathlib.Tactic.Coe`. -- Porting note: removed `simp` as it is competing with `nonempty_subtype`. -- @[simp] theorem nonempty_coe_sort {s : Set α} : Nonempty (↥s) ↔ s.Nonempty := nonempty_subtype #align set.nonempty_coe_sort Set.nonempty_coe_sort alias ⟨_, Nonempty.coe_sort⟩ := nonempty_coe_sort #align set.nonempty.coe_sort Set.Nonempty.coe_sort theorem nonempty_def : s.Nonempty ↔ ∃ x, x ∈ s := Iff.rfl #align set.nonempty_def Set.nonempty_def theorem nonempty_of_mem {x} (h : x ∈ s) : s.Nonempty := ⟨x, h⟩ #align set.nonempty_of_mem Set.nonempty_of_mem theorem Nonempty.not_subset_empty : s.Nonempty → ¬s ⊆ ∅ | ⟨_, hx⟩, hs => hs hx #align set.nonempty.not_subset_empty Set.Nonempty.not_subset_empty /-- Extract a witness from `s.Nonempty`. This function might be used instead of case analysis on the argument. Note that it makes a proof depend on the `Classical.choice` axiom. -/ protected noncomputable def Nonempty.some (h : s.Nonempty) : α := Classical.choose h #align set.nonempty.some Set.Nonempty.some protected theorem Nonempty.some_mem (h : s.Nonempty) : h.some ∈ s := Classical.choose_spec h #align set.nonempty.some_mem Set.Nonempty.some_mem theorem Nonempty.mono (ht : s ⊆ t) (hs : s.Nonempty) : t.Nonempty := hs.imp ht #align set.nonempty.mono Set.Nonempty.mono theorem nonempty_of_not_subset (h : ¬s ⊆ t) : (s \ t).Nonempty := let ⟨x, xs, xt⟩ := not_subset.1 h ⟨x, xs, xt⟩ #align set.nonempty_of_not_subset Set.nonempty_of_not_subset theorem nonempty_of_ssubset (ht : s ⊂ t) : (t \ s).Nonempty := nonempty_of_not_subset ht.2 #align set.nonempty_of_ssubset Set.nonempty_of_ssubset theorem Nonempty.of_diff (h : (s \ t).Nonempty) : s.Nonempty := h.imp fun _ => And.left #align set.nonempty.of_diff Set.Nonempty.of_diff theorem nonempty_of_ssubset' (ht : s ⊂ t) : t.Nonempty := (nonempty_of_ssubset ht).of_diff #align set.nonempty_of_ssubset' Set.nonempty_of_ssubset' theorem Nonempty.inl (hs : s.Nonempty) : (s ∪ t).Nonempty := hs.imp fun _ => Or.inl #align set.nonempty.inl Set.Nonempty.inl theorem Nonempty.inr (ht : t.Nonempty) : (s ∪ t).Nonempty := ht.imp fun _ => Or.inr #align set.nonempty.inr Set.Nonempty.inr @[simp] theorem union_nonempty : (s ∪ t).Nonempty ↔ s.Nonempty ∨ t.Nonempty := exists_or #align set.union_nonempty Set.union_nonempty theorem Nonempty.left (h : (s ∩ t).Nonempty) : s.Nonempty := h.imp fun _ => And.left #align set.nonempty.left Set.Nonempty.left theorem Nonempty.right (h : (s ∩ t).Nonempty) : t.Nonempty := h.imp fun _ => And.right #align set.nonempty.right Set.Nonempty.right theorem inter_nonempty : (s ∩ t).Nonempty ↔ ∃ x, x ∈ s ∧ x ∈ t := Iff.rfl #align set.inter_nonempty Set.inter_nonempty theorem inter_nonempty_iff_exists_left : (s ∩ t).Nonempty ↔ ∃ x ∈ s, x ∈ t := by simp_rw [inter_nonempty] #align set.inter_nonempty_iff_exists_left Set.inter_nonempty_iff_exists_left theorem inter_nonempty_iff_exists_right : (s ∩ t).Nonempty ↔ ∃ x ∈ t, x ∈ s := by simp_rw [inter_nonempty, and_comm] #align set.inter_nonempty_iff_exists_right Set.inter_nonempty_iff_exists_right theorem nonempty_iff_univ_nonempty : Nonempty α ↔ (univ : Set α).Nonempty := ⟨fun ⟨x⟩ => ⟨x, trivial⟩, fun ⟨x, _⟩ => ⟨x⟩⟩ #align set.nonempty_iff_univ_nonempty Set.nonempty_iff_univ_nonempty @[simp] theorem univ_nonempty : ∀ [Nonempty α], (univ : Set α).Nonempty | ⟨x⟩ => ⟨x, trivial⟩ #align set.univ_nonempty Set.univ_nonempty theorem Nonempty.to_subtype : s.Nonempty → Nonempty (↥s) := nonempty_subtype.2 #align set.nonempty.to_subtype Set.Nonempty.to_subtype theorem Nonempty.to_type : s.Nonempty → Nonempty α := fun ⟨x, _⟩ => ⟨x⟩ #align set.nonempty.to_type Set.Nonempty.to_type instance univ.nonempty [Nonempty α] : Nonempty (↥(Set.univ : Set α)) := Set.univ_nonempty.to_subtype #align set.univ.nonempty Set.univ.nonempty theorem nonempty_of_nonempty_subtype [Nonempty (↥s)] : s.Nonempty := nonempty_subtype.mp ‹_› #align set.nonempty_of_nonempty_subtype Set.nonempty_of_nonempty_subtype /-! ### Lemmas about the empty set -/ theorem empty_def : (∅ : Set α) = { _x : α | False } := rfl #align set.empty_def Set.empty_def @[simp] theorem mem_empty_iff_false (x : α) : x ∈ (∅ : Set α) ↔ False := Iff.rfl #align set.mem_empty_iff_false Set.mem_empty_iff_false @[simp] theorem setOf_false : { _a : α | False } = ∅ := rfl #align set.set_of_false Set.setOf_false @[simp] theorem setOf_bot : { _x : α | ⊥ } = ∅ := rfl @[simp] theorem empty_subset (s : Set α) : ∅ ⊆ s := nofun #align set.empty_subset Set.empty_subset theorem subset_empty_iff {s : Set α} : s ⊆ ∅ ↔ s = ∅ := (Subset.antisymm_iff.trans <| and_iff_left (empty_subset _)).symm #align set.subset_empty_iff Set.subset_empty_iff theorem eq_empty_iff_forall_not_mem {s : Set α} : s = ∅ ↔ ∀ x, x ∉ s := subset_empty_iff.symm #align set.eq_empty_iff_forall_not_mem Set.eq_empty_iff_forall_not_mem theorem eq_empty_of_forall_not_mem (h : ∀ x, x ∉ s) : s = ∅ := subset_empty_iff.1 h #align set.eq_empty_of_forall_not_mem Set.eq_empty_of_forall_not_mem theorem eq_empty_of_subset_empty {s : Set α} : s ⊆ ∅ → s = ∅ := subset_empty_iff.1 #align set.eq_empty_of_subset_empty Set.eq_empty_of_subset_empty theorem eq_empty_of_isEmpty [IsEmpty α] (s : Set α) : s = ∅ := eq_empty_of_subset_empty fun x _ => isEmptyElim x #align set.eq_empty_of_is_empty Set.eq_empty_of_isEmpty /-- There is exactly one set of a type that is empty. -/ instance uniqueEmpty [IsEmpty α] : Unique (Set α) where default := ∅ uniq := eq_empty_of_isEmpty #align set.unique_empty Set.uniqueEmpty /-- See also `Set.nonempty_iff_ne_empty`. -/ theorem not_nonempty_iff_eq_empty {s : Set α} : ¬s.Nonempty ↔ s = ∅ := by simp only [Set.Nonempty, not_exists, eq_empty_iff_forall_not_mem] #align set.not_nonempty_iff_eq_empty Set.not_nonempty_iff_eq_empty /-- See also `Set.not_nonempty_iff_eq_empty`. -/ theorem nonempty_iff_ne_empty : s.Nonempty ↔ s ≠ ∅ := not_nonempty_iff_eq_empty.not_right #align set.nonempty_iff_ne_empty Set.nonempty_iff_ne_empty /-- See also `nonempty_iff_ne_empty'`. -/ theorem not_nonempty_iff_eq_empty' : ¬Nonempty s ↔ s = ∅ := by rw [nonempty_subtype, not_exists, eq_empty_iff_forall_not_mem] /-- See also `not_nonempty_iff_eq_empty'`. -/ theorem nonempty_iff_ne_empty' : Nonempty s ↔ s ≠ ∅ := not_nonempty_iff_eq_empty'.not_right alias ⟨Nonempty.ne_empty, _⟩ := nonempty_iff_ne_empty #align set.nonempty.ne_empty Set.Nonempty.ne_empty @[simp] theorem not_nonempty_empty : ¬(∅ : Set α).Nonempty := fun ⟨_, hx⟩ => hx #align set.not_nonempty_empty Set.not_nonempty_empty -- Porting note: removing `@[simp]` as it is competing with `isEmpty_subtype`. -- @[simp] theorem isEmpty_coe_sort {s : Set α} : IsEmpty (↥s) ↔ s = ∅ := not_iff_not.1 <| by simpa using nonempty_iff_ne_empty #align set.is_empty_coe_sort Set.isEmpty_coe_sort theorem eq_empty_or_nonempty (s : Set α) : s = ∅ ∨ s.Nonempty := or_iff_not_imp_left.2 nonempty_iff_ne_empty.2 #align set.eq_empty_or_nonempty Set.eq_empty_or_nonempty theorem subset_eq_empty {s t : Set α} (h : t ⊆ s) (e : s = ∅) : t = ∅ := subset_empty_iff.1 <| e ▸ h #align set.subset_eq_empty Set.subset_eq_empty theorem forall_mem_empty {p : α → Prop} : (∀ x ∈ (∅ : Set α), p x) ↔ True := iff_true_intro fun _ => False.elim #align set.ball_empty_iff Set.forall_mem_empty @[deprecated (since := "2024-03-23")] alias ball_empty_iff := forall_mem_empty instance (α : Type u) : IsEmpty.{u + 1} (↥(∅ : Set α)) := ⟨fun x => x.2⟩ @[simp] theorem empty_ssubset : ∅ ⊂ s ↔ s.Nonempty := (@bot_lt_iff_ne_bot (Set α) _ _ _).trans nonempty_iff_ne_empty.symm #align set.empty_ssubset Set.empty_ssubset alias ⟨_, Nonempty.empty_ssubset⟩ := empty_ssubset #align set.nonempty.empty_ssubset Set.Nonempty.empty_ssubset /-! ### Universal set. In Lean `@univ α` (or `univ : Set α`) is the set that contains all elements of type `α`. Mathematically it is the same as `α` but it has a different type. -/ @[simp] theorem setOf_true : { _x : α | True } = univ := rfl #align set.set_of_true Set.setOf_true @[simp] theorem setOf_top : { _x : α | ⊤ } = univ := rfl @[simp] theorem univ_eq_empty_iff : (univ : Set α) = ∅ ↔ IsEmpty α := eq_empty_iff_forall_not_mem.trans ⟨fun H => ⟨fun x => H x trivial⟩, fun H x _ => @IsEmpty.false α H x⟩ #align set.univ_eq_empty_iff Set.univ_eq_empty_iff theorem empty_ne_univ [Nonempty α] : (∅ : Set α) ≠ univ := fun e => not_isEmpty_of_nonempty α <| univ_eq_empty_iff.1 e.symm #align set.empty_ne_univ Set.empty_ne_univ @[simp] theorem subset_univ (s : Set α) : s ⊆ univ := fun _ _ => trivial #align set.subset_univ Set.subset_univ @[simp] theorem univ_subset_iff {s : Set α} : univ ⊆ s ↔ s = univ := @top_le_iff _ _ _ s #align set.univ_subset_iff Set.univ_subset_iff alias ⟨eq_univ_of_univ_subset, _⟩ := univ_subset_iff #align set.eq_univ_of_univ_subset Set.eq_univ_of_univ_subset theorem eq_univ_iff_forall {s : Set α} : s = univ ↔ ∀ x, x ∈ s := univ_subset_iff.symm.trans <| forall_congr' fun _ => imp_iff_right trivial #align set.eq_univ_iff_forall Set.eq_univ_iff_forall theorem eq_univ_of_forall {s : Set α} : (∀ x, x ∈ s) → s = univ := eq_univ_iff_forall.2 #align set.eq_univ_of_forall Set.eq_univ_of_forall theorem Nonempty.eq_univ [Subsingleton α] : s.Nonempty → s = univ := by rintro ⟨x, hx⟩ exact eq_univ_of_forall fun y => by rwa [Subsingleton.elim y x] #align set.nonempty.eq_univ Set.Nonempty.eq_univ theorem eq_univ_of_subset {s t : Set α} (h : s ⊆ t) (hs : s = univ) : t = univ := eq_univ_of_univ_subset <| (hs ▸ h : univ ⊆ t) #align set.eq_univ_of_subset Set.eq_univ_of_subset theorem exists_mem_of_nonempty (α) : ∀ [Nonempty α], ∃ x : α, x ∈ (univ : Set α) | ⟨x⟩ => ⟨x, trivial⟩ #align set.exists_mem_of_nonempty Set.exists_mem_of_nonempty theorem ne_univ_iff_exists_not_mem {α : Type*} (s : Set α) : s ≠ univ ↔ ∃ a, a ∉ s := by rw [← not_forall, ← eq_univ_iff_forall] #align set.ne_univ_iff_exists_not_mem Set.ne_univ_iff_exists_not_mem theorem not_subset_iff_exists_mem_not_mem {α : Type*} {s t : Set α} : ¬s ⊆ t ↔ ∃ x, x ∈ s ∧ x ∉ t := by simp [subset_def] #align set.not_subset_iff_exists_mem_not_mem Set.not_subset_iff_exists_mem_not_mem theorem univ_unique [Unique α] : @Set.univ α = {default} := Set.ext fun x => iff_of_true trivial <| Subsingleton.elim x default #align set.univ_unique Set.univ_unique theorem ssubset_univ_iff : s ⊂ univ ↔ s ≠ univ := lt_top_iff_ne_top #align set.ssubset_univ_iff Set.ssubset_univ_iff instance nontrivial_of_nonempty [Nonempty α] : Nontrivial (Set α) := ⟨⟨∅, univ, empty_ne_univ⟩⟩ #align set.nontrivial_of_nonempty Set.nontrivial_of_nonempty /-! ### Lemmas about union -/ theorem union_def {s₁ s₂ : Set α} : s₁ ∪ s₂ = { a | a ∈ s₁ ∨ a ∈ s₂ } := rfl #align set.union_def Set.union_def theorem mem_union_left {x : α} {a : Set α} (b : Set α) : x ∈ a → x ∈ a ∪ b := Or.inl #align set.mem_union_left Set.mem_union_left theorem mem_union_right {x : α} {b : Set α} (a : Set α) : x ∈ b → x ∈ a ∪ b := Or.inr #align set.mem_union_right Set.mem_union_right theorem mem_or_mem_of_mem_union {x : α} {a b : Set α} (H : x ∈ a ∪ b) : x ∈ a ∨ x ∈ b := H #align set.mem_or_mem_of_mem_union Set.mem_or_mem_of_mem_union theorem MemUnion.elim {x : α} {a b : Set α} {P : Prop} (H₁ : x ∈ a ∪ b) (H₂ : x ∈ a → P) (H₃ : x ∈ b → P) : P := Or.elim H₁ H₂ H₃ #align set.mem_union.elim Set.MemUnion.elim @[simp] theorem mem_union (x : α) (a b : Set α) : x ∈ a ∪ b ↔ x ∈ a ∨ x ∈ b := Iff.rfl #align set.mem_union Set.mem_union @[simp] theorem union_self (a : Set α) : a ∪ a = a := ext fun _ => or_self_iff #align set.union_self Set.union_self @[simp] theorem union_empty (a : Set α) : a ∪ ∅ = a := ext fun _ => or_false_iff _ #align set.union_empty Set.union_empty @[simp] theorem empty_union (a : Set α) : ∅ ∪ a = a := ext fun _ => false_or_iff _ #align set.empty_union Set.empty_union theorem union_comm (a b : Set α) : a ∪ b = b ∪ a := ext fun _ => or_comm #align set.union_comm Set.union_comm theorem union_assoc (a b c : Set α) : a ∪ b ∪ c = a ∪ (b ∪ c) := ext fun _ => or_assoc #align set.union_assoc Set.union_assoc instance union_isAssoc : Std.Associative (α := Set α) (· ∪ ·) := ⟨union_assoc⟩ #align set.union_is_assoc Set.union_isAssoc instance union_isComm : Std.Commutative (α := Set α) (· ∪ ·) := ⟨union_comm⟩ #align set.union_is_comm Set.union_isComm theorem union_left_comm (s₁ s₂ s₃ : Set α) : s₁ ∪ (s₂ ∪ s₃) = s₂ ∪ (s₁ ∪ s₃) := ext fun _ => or_left_comm #align set.union_left_comm Set.union_left_comm theorem union_right_comm (s₁ s₂ s₃ : Set α) : s₁ ∪ s₂ ∪ s₃ = s₁ ∪ s₃ ∪ s₂ := ext fun _ => or_right_comm #align set.union_right_comm Set.union_right_comm @[simp] theorem union_eq_left {s t : Set α} : s ∪ t = s ↔ t ⊆ s := sup_eq_left #align set.union_eq_left_iff_subset Set.union_eq_left @[simp] theorem union_eq_right {s t : Set α} : s ∪ t = t ↔ s ⊆ t := sup_eq_right #align set.union_eq_right_iff_subset Set.union_eq_right theorem union_eq_self_of_subset_left {s t : Set α} (h : s ⊆ t) : s ∪ t = t := union_eq_right.mpr h #align set.union_eq_self_of_subset_left Set.union_eq_self_of_subset_left theorem union_eq_self_of_subset_right {s t : Set α} (h : t ⊆ s) : s ∪ t = s := union_eq_left.mpr h #align set.union_eq_self_of_subset_right Set.union_eq_self_of_subset_right @[simp] theorem subset_union_left {s t : Set α} : s ⊆ s ∪ t := fun _ => Or.inl #align set.subset_union_left Set.subset_union_left @[simp] theorem subset_union_right {s t : Set α} : t ⊆ s ∪ t := fun _ => Or.inr #align set.subset_union_right Set.subset_union_right theorem union_subset {s t r : Set α} (sr : s ⊆ r) (tr : t ⊆ r) : s ∪ t ⊆ r := fun _ => Or.rec (@sr _) (@tr _) #align set.union_subset Set.union_subset @[simp] theorem union_subset_iff {s t u : Set α} : s ∪ t ⊆ u ↔ s ⊆ u ∧ t ⊆ u := (forall_congr' fun _ => or_imp).trans forall_and #align set.union_subset_iff Set.union_subset_iff @[gcongr] theorem union_subset_union {s₁ s₂ t₁ t₂ : Set α} (h₁ : s₁ ⊆ s₂) (h₂ : t₁ ⊆ t₂) : s₁ ∪ t₁ ⊆ s₂ ∪ t₂ := fun _ => Or.imp (@h₁ _) (@h₂ _) #align set.union_subset_union Set.union_subset_union @[gcongr] theorem union_subset_union_left {s₁ s₂ : Set α} (t) (h : s₁ ⊆ s₂) : s₁ ∪ t ⊆ s₂ ∪ t := union_subset_union h Subset.rfl #align set.union_subset_union_left Set.union_subset_union_left @[gcongr] theorem union_subset_union_right (s) {t₁ t₂ : Set α} (h : t₁ ⊆ t₂) : s ∪ t₁ ⊆ s ∪ t₂ := union_subset_union Subset.rfl h #align set.union_subset_union_right Set.union_subset_union_right theorem subset_union_of_subset_left {s t : Set α} (h : s ⊆ t) (u : Set α) : s ⊆ t ∪ u := h.trans subset_union_left #align set.subset_union_of_subset_left Set.subset_union_of_subset_left theorem subset_union_of_subset_right {s u : Set α} (h : s ⊆ u) (t : Set α) : s ⊆ t ∪ u := h.trans subset_union_right #align set.subset_union_of_subset_right Set.subset_union_of_subset_right -- Porting note: replaced `⊔` in RHS theorem union_congr_left (ht : t ⊆ s ∪ u) (hu : u ⊆ s ∪ t) : s ∪ t = s ∪ u := sup_congr_left ht hu #align set.union_congr_left Set.union_congr_left theorem union_congr_right (hs : s ⊆ t ∪ u) (ht : t ⊆ s ∪ u) : s ∪ u = t ∪ u := sup_congr_right hs ht #align set.union_congr_right Set.union_congr_right theorem union_eq_union_iff_left : s ∪ t = s ∪ u ↔ t ⊆ s ∪ u ∧ u ⊆ s ∪ t := sup_eq_sup_iff_left #align set.union_eq_union_iff_left Set.union_eq_union_iff_left theorem union_eq_union_iff_right : s ∪ u = t ∪ u ↔ s ⊆ t ∪ u ∧ t ⊆ s ∪ u := sup_eq_sup_iff_right #align set.union_eq_union_iff_right Set.union_eq_union_iff_right @[simp] theorem union_empty_iff {s t : Set α} : s ∪ t = ∅ ↔ s = ∅ ∧ t = ∅ := by simp only [← subset_empty_iff] exact union_subset_iff #align set.union_empty_iff Set.union_empty_iff @[simp] theorem union_univ (s : Set α) : s ∪ univ = univ := sup_top_eq _ #align set.union_univ Set.union_univ @[simp] theorem univ_union (s : Set α) : univ ∪ s = univ := top_sup_eq _ #align set.univ_union Set.univ_union /-! ### Lemmas about intersection -/ theorem inter_def {s₁ s₂ : Set α} : s₁ ∩ s₂ = { a | a ∈ s₁ ∧ a ∈ s₂ } := rfl #align set.inter_def Set.inter_def @[simp, mfld_simps] theorem mem_inter_iff (x : α) (a b : Set α) : x ∈ a ∩ b ↔ x ∈ a ∧ x ∈ b := Iff.rfl #align set.mem_inter_iff Set.mem_inter_iff theorem mem_inter {x : α} {a b : Set α} (ha : x ∈ a) (hb : x ∈ b) : x ∈ a ∩ b := ⟨ha, hb⟩ #align set.mem_inter Set.mem_inter theorem mem_of_mem_inter_left {x : α} {a b : Set α} (h : x ∈ a ∩ b) : x ∈ a := h.left #align set.mem_of_mem_inter_left Set.mem_of_mem_inter_left theorem mem_of_mem_inter_right {x : α} {a b : Set α} (h : x ∈ a ∩ b) : x ∈ b := h.right #align set.mem_of_mem_inter_right Set.mem_of_mem_inter_right @[simp] theorem inter_self (a : Set α) : a ∩ a = a := ext fun _ => and_self_iff #align set.inter_self Set.inter_self @[simp] theorem inter_empty (a : Set α) : a ∩ ∅ = ∅ := ext fun _ => and_false_iff _ #align set.inter_empty Set.inter_empty @[simp] theorem empty_inter (a : Set α) : ∅ ∩ a = ∅ := ext fun _ => false_and_iff _ #align set.empty_inter Set.empty_inter theorem inter_comm (a b : Set α) : a ∩ b = b ∩ a := ext fun _ => and_comm #align set.inter_comm Set.inter_comm theorem inter_assoc (a b c : Set α) : a ∩ b ∩ c = a ∩ (b ∩ c) := ext fun _ => and_assoc #align set.inter_assoc Set.inter_assoc instance inter_isAssoc : Std.Associative (α := Set α) (· ∩ ·) := ⟨inter_assoc⟩ #align set.inter_is_assoc Set.inter_isAssoc instance inter_isComm : Std.Commutative (α := Set α) (· ∩ ·) := ⟨inter_comm⟩ #align set.inter_is_comm Set.inter_isComm theorem inter_left_comm (s₁ s₂ s₃ : Set α) : s₁ ∩ (s₂ ∩ s₃) = s₂ ∩ (s₁ ∩ s₃) := ext fun _ => and_left_comm #align set.inter_left_comm Set.inter_left_comm theorem inter_right_comm (s₁ s₂ s₃ : Set α) : s₁ ∩ s₂ ∩ s₃ = s₁ ∩ s₃ ∩ s₂ := ext fun _ => and_right_comm #align set.inter_right_comm Set.inter_right_comm @[simp, mfld_simps] theorem inter_subset_left {s t : Set α} : s ∩ t ⊆ s := fun _ => And.left #align set.inter_subset_left Set.inter_subset_left @[simp] theorem inter_subset_right {s t : Set α} : s ∩ t ⊆ t := fun _ => And.right #align set.inter_subset_right Set.inter_subset_right theorem subset_inter {s t r : Set α} (rs : r ⊆ s) (rt : r ⊆ t) : r ⊆ s ∩ t := fun _ h => ⟨rs h, rt h⟩ #align set.subset_inter Set.subset_inter @[simp] theorem subset_inter_iff {s t r : Set α} : r ⊆ s ∩ t ↔ r ⊆ s ∧ r ⊆ t := (forall_congr' fun _ => imp_and).trans forall_and #align set.subset_inter_iff Set.subset_inter_iff @[simp] lemma inter_eq_left : s ∩ t = s ↔ s ⊆ t := inf_eq_left #align set.inter_eq_left_iff_subset Set.inter_eq_left @[simp] lemma inter_eq_right : s ∩ t = t ↔ t ⊆ s := inf_eq_right #align set.inter_eq_right_iff_subset Set.inter_eq_right @[simp] lemma left_eq_inter : s = s ∩ t ↔ s ⊆ t := left_eq_inf @[simp] lemma right_eq_inter : t = s ∩ t ↔ t ⊆ s := right_eq_inf theorem inter_eq_self_of_subset_left {s t : Set α} : s ⊆ t → s ∩ t = s := inter_eq_left.mpr #align set.inter_eq_self_of_subset_left Set.inter_eq_self_of_subset_left theorem inter_eq_self_of_subset_right {s t : Set α} : t ⊆ s → s ∩ t = t := inter_eq_right.mpr #align set.inter_eq_self_of_subset_right Set.inter_eq_self_of_subset_right theorem inter_congr_left (ht : s ∩ u ⊆ t) (hu : s ∩ t ⊆ u) : s ∩ t = s ∩ u := inf_congr_left ht hu #align set.inter_congr_left Set.inter_congr_left theorem inter_congr_right (hs : t ∩ u ⊆ s) (ht : s ∩ u ⊆ t) : s ∩ u = t ∩ u := inf_congr_right hs ht #align set.inter_congr_right Set.inter_congr_right theorem inter_eq_inter_iff_left : s ∩ t = s ∩ u ↔ s ∩ u ⊆ t ∧ s ∩ t ⊆ u := inf_eq_inf_iff_left #align set.inter_eq_inter_iff_left Set.inter_eq_inter_iff_left theorem inter_eq_inter_iff_right : s ∩ u = t ∩ u ↔ t ∩ u ⊆ s ∧ s ∩ u ⊆ t := inf_eq_inf_iff_right #align set.inter_eq_inter_iff_right Set.inter_eq_inter_iff_right @[simp, mfld_simps] theorem inter_univ (a : Set α) : a ∩ univ = a := inf_top_eq _ #align set.inter_univ Set.inter_univ @[simp, mfld_simps] theorem univ_inter (a : Set α) : univ ∩ a = a := top_inf_eq _ #align set.univ_inter Set.univ_inter @[gcongr] theorem inter_subset_inter {s₁ s₂ t₁ t₂ : Set α} (h₁ : s₁ ⊆ t₁) (h₂ : s₂ ⊆ t₂) : s₁ ∩ s₂ ⊆ t₁ ∩ t₂ := fun _ => And.imp (@h₁ _) (@h₂ _) #align set.inter_subset_inter Set.inter_subset_inter @[gcongr] theorem inter_subset_inter_left {s t : Set α} (u : Set α) (H : s ⊆ t) : s ∩ u ⊆ t ∩ u := inter_subset_inter H Subset.rfl #align set.inter_subset_inter_left Set.inter_subset_inter_left @[gcongr] theorem inter_subset_inter_right {s t : Set α} (u : Set α) (H : s ⊆ t) : u ∩ s ⊆ u ∩ t := inter_subset_inter Subset.rfl H #align set.inter_subset_inter_right Set.inter_subset_inter_right theorem union_inter_cancel_left {s t : Set α} : (s ∪ t) ∩ s = s := inter_eq_self_of_subset_right subset_union_left #align set.union_inter_cancel_left Set.union_inter_cancel_left theorem union_inter_cancel_right {s t : Set α} : (s ∪ t) ∩ t = t := inter_eq_self_of_subset_right subset_union_right #align set.union_inter_cancel_right Set.union_inter_cancel_right theorem inter_setOf_eq_sep (s : Set α) (p : α → Prop) : s ∩ {a | p a} = {a ∈ s | p a} := rfl #align set.inter_set_of_eq_sep Set.inter_setOf_eq_sep theorem setOf_inter_eq_sep (p : α → Prop) (s : Set α) : {a | p a} ∩ s = {a ∈ s | p a} := inter_comm _ _ #align set.set_of_inter_eq_sep Set.setOf_inter_eq_sep /-! ### Distributivity laws -/ theorem inter_union_distrib_left (s t u : Set α) : s ∩ (t ∪ u) = s ∩ t ∪ s ∩ u := inf_sup_left _ _ _ #align set.inter_distrib_left Set.inter_union_distrib_left theorem union_inter_distrib_right (s t u : Set α) : (s ∪ t) ∩ u = s ∩ u ∪ t ∩ u := inf_sup_right _ _ _ #align set.inter_distrib_right Set.union_inter_distrib_right theorem union_inter_distrib_left (s t u : Set α) : s ∪ t ∩ u = (s ∪ t) ∩ (s ∪ u) := sup_inf_left _ _ _ #align set.union_distrib_left Set.union_inter_distrib_left theorem inter_union_distrib_right (s t u : Set α) : s ∩ t ∪ u = (s ∪ u) ∩ (t ∪ u) := sup_inf_right _ _ _ #align set.union_distrib_right Set.inter_union_distrib_right -- 2024-03-22 @[deprecated] alias inter_distrib_left := inter_union_distrib_left @[deprecated] alias inter_distrib_right := union_inter_distrib_right @[deprecated] alias union_distrib_left := union_inter_distrib_left @[deprecated] alias union_distrib_right := inter_union_distrib_right theorem union_union_distrib_left (s t u : Set α) : s ∪ (t ∪ u) = s ∪ t ∪ (s ∪ u) := sup_sup_distrib_left _ _ _ #align set.union_union_distrib_left Set.union_union_distrib_left theorem union_union_distrib_right (s t u : Set α) : s ∪ t ∪ u = s ∪ u ∪ (t ∪ u) := sup_sup_distrib_right _ _ _ #align set.union_union_distrib_right Set.union_union_distrib_right theorem inter_inter_distrib_left (s t u : Set α) : s ∩ (t ∩ u) = s ∩ t ∩ (s ∩ u) := inf_inf_distrib_left _ _ _ #align set.inter_inter_distrib_left Set.inter_inter_distrib_left theorem inter_inter_distrib_right (s t u : Set α) : s ∩ t ∩ u = s ∩ u ∩ (t ∩ u) := inf_inf_distrib_right _ _ _ #align set.inter_inter_distrib_right Set.inter_inter_distrib_right theorem union_union_union_comm (s t u v : Set α) : s ∪ t ∪ (u ∪ v) = s ∪ u ∪ (t ∪ v) := sup_sup_sup_comm _ _ _ _ #align set.union_union_union_comm Set.union_union_union_comm theorem inter_inter_inter_comm (s t u v : Set α) : s ∩ t ∩ (u ∩ v) = s ∩ u ∩ (t ∩ v) := inf_inf_inf_comm _ _ _ _ #align set.inter_inter_inter_comm Set.inter_inter_inter_comm /-! ### Lemmas about `insert` `insert α s` is the set `{α} ∪ s`. -/ theorem insert_def (x : α) (s : Set α) : insert x s = { y | y = x ∨ y ∈ s } := rfl #align set.insert_def Set.insert_def @[simp] theorem subset_insert (x : α) (s : Set α) : s ⊆ insert x s := fun _ => Or.inr #align set.subset_insert Set.subset_insert theorem mem_insert (x : α) (s : Set α) : x ∈ insert x s := Or.inl rfl #align set.mem_insert Set.mem_insert theorem mem_insert_of_mem {x : α} {s : Set α} (y : α) : x ∈ s → x ∈ insert y s := Or.inr #align set.mem_insert_of_mem Set.mem_insert_of_mem theorem eq_or_mem_of_mem_insert {x a : α} {s : Set α} : x ∈ insert a s → x = a ∨ x ∈ s := id #align set.eq_or_mem_of_mem_insert Set.eq_or_mem_of_mem_insert theorem mem_of_mem_insert_of_ne : b ∈ insert a s → b ≠ a → b ∈ s := Or.resolve_left #align set.mem_of_mem_insert_of_ne Set.mem_of_mem_insert_of_ne theorem eq_of_not_mem_of_mem_insert : b ∈ insert a s → b ∉ s → b = a := Or.resolve_right #align set.eq_of_not_mem_of_mem_insert Set.eq_of_not_mem_of_mem_insert @[simp] theorem mem_insert_iff {x a : α} {s : Set α} : x ∈ insert a s ↔ x = a ∨ x ∈ s := Iff.rfl #align set.mem_insert_iff Set.mem_insert_iff @[simp] theorem insert_eq_of_mem {a : α} {s : Set α} (h : a ∈ s) : insert a s = s := ext fun _ => or_iff_right_of_imp fun e => e.symm ▸ h #align set.insert_eq_of_mem Set.insert_eq_of_mem theorem ne_insert_of_not_mem {s : Set α} (t : Set α) {a : α} : a ∉ s → s ≠ insert a t := mt fun e => e.symm ▸ mem_insert _ _ #align set.ne_insert_of_not_mem Set.ne_insert_of_not_mem @[simp] theorem insert_eq_self : insert a s = s ↔ a ∈ s := ⟨fun h => h ▸ mem_insert _ _, insert_eq_of_mem⟩ #align set.insert_eq_self Set.insert_eq_self theorem insert_ne_self : insert a s ≠ s ↔ a ∉ s := insert_eq_self.not #align set.insert_ne_self Set.insert_ne_self theorem insert_subset_iff : insert a s ⊆ t ↔ a ∈ t ∧ s ⊆ t := by simp only [subset_def, mem_insert_iff, or_imp, forall_and, forall_eq] #align set.insert_subset Set.insert_subset_iff theorem insert_subset (ha : a ∈ t) (hs : s ⊆ t) : insert a s ⊆ t := insert_subset_iff.mpr ⟨ha, hs⟩ theorem insert_subset_insert (h : s ⊆ t) : insert a s ⊆ insert a t := fun _ => Or.imp_right (@h _) #align set.insert_subset_insert Set.insert_subset_insert @[simp] theorem insert_subset_insert_iff (ha : a ∉ s) : insert a s ⊆ insert a t ↔ s ⊆ t := by refine ⟨fun h x hx => ?_, insert_subset_insert⟩ rcases h (subset_insert _ _ hx) with (rfl | hxt) exacts [(ha hx).elim, hxt] #align set.insert_subset_insert_iff Set.insert_subset_insert_iff theorem subset_insert_iff_of_not_mem (ha : a ∉ s) : s ⊆ insert a t ↔ s ⊆ t := forall₂_congr fun _ hb => or_iff_right <| ne_of_mem_of_not_mem hb ha #align set.subset_insert_iff_of_not_mem Set.subset_insert_iff_of_not_mem theorem ssubset_iff_insert {s t : Set α} : s ⊂ t ↔ ∃ a ∉ s, insert a s ⊆ t := by simp only [insert_subset_iff, exists_and_right, ssubset_def, not_subset] aesop #align set.ssubset_iff_insert Set.ssubset_iff_insert theorem ssubset_insert {s : Set α} {a : α} (h : a ∉ s) : s ⊂ insert a s := ssubset_iff_insert.2 ⟨a, h, Subset.rfl⟩ #align set.ssubset_insert Set.ssubset_insert theorem insert_comm (a b : α) (s : Set α) : insert a (insert b s) = insert b (insert a s) := ext fun _ => or_left_comm #align set.insert_comm Set.insert_comm -- Porting note (#10618): removing `simp` attribute because `simp` can prove it theorem insert_idem (a : α) (s : Set α) : insert a (insert a s) = insert a s := insert_eq_of_mem <| mem_insert _ _ #align set.insert_idem Set.insert_idem theorem insert_union : insert a s ∪ t = insert a (s ∪ t) := ext fun _ => or_assoc #align set.insert_union Set.insert_union @[simp] theorem union_insert : s ∪ insert a t = insert a (s ∪ t) := ext fun _ => or_left_comm #align set.union_insert Set.union_insert @[simp] theorem insert_nonempty (a : α) (s : Set α) : (insert a s).Nonempty := ⟨a, mem_insert a s⟩ #align set.insert_nonempty Set.insert_nonempty instance (a : α) (s : Set α) : Nonempty (insert a s : Set α) := (insert_nonempty a s).to_subtype theorem insert_inter_distrib (a : α) (s t : Set α) : insert a (s ∩ t) = insert a s ∩ insert a t := ext fun _ => or_and_left #align set.insert_inter_distrib Set.insert_inter_distrib theorem insert_union_distrib (a : α) (s t : Set α) : insert a (s ∪ t) = insert a s ∪ insert a t := ext fun _ => or_or_distrib_left #align set.insert_union_distrib Set.insert_union_distrib theorem insert_inj (ha : a ∉ s) : insert a s = insert b s ↔ a = b := ⟨fun h => eq_of_not_mem_of_mem_insert (h.subst <| mem_insert a s) ha, congr_arg (fun x => insert x s)⟩ #align set.insert_inj Set.insert_inj -- useful in proofs by induction theorem forall_of_forall_insert {P : α → Prop} {a : α} {s : Set α} (H : ∀ x, x ∈ insert a s → P x) (x) (h : x ∈ s) : P x := H _ (Or.inr h) #align set.forall_of_forall_insert Set.forall_of_forall_insert theorem forall_insert_of_forall {P : α → Prop} {a : α} {s : Set α} (H : ∀ x, x ∈ s → P x) (ha : P a) (x) (h : x ∈ insert a s) : P x := h.elim (fun e => e.symm ▸ ha) (H _) #align set.forall_insert_of_forall Set.forall_insert_of_forall /- Porting note: ∃ x ∈ insert a s, P x is parsed as ∃ x, x ∈ insert a s ∧ P x, where in Lean3 it was parsed as `∃ x, ∃ (h : x ∈ insert a s), P x` -/ theorem exists_mem_insert {P : α → Prop} {a : α} {s : Set α} : (∃ x ∈ insert a s, P x) ↔ (P a ∨ ∃ x ∈ s, P x) := by simp [mem_insert_iff, or_and_right, exists_and_left, exists_or] #align set.bex_insert_iff Set.exists_mem_insert @[deprecated (since := "2024-03-23")] alias bex_insert_iff := exists_mem_insert theorem forall_mem_insert {P : α → Prop} {a : α} {s : Set α} : (∀ x ∈ insert a s, P x) ↔ P a ∧ ∀ x ∈ s, P x := forall₂_or_left.trans <| and_congr_left' forall_eq #align set.ball_insert_iff Set.forall_mem_insert @[deprecated (since := "2024-03-23")] alias ball_insert_iff := forall_mem_insert /-! ### Lemmas about singletons -/ /- porting note: instance was in core in Lean3 -/ instance : LawfulSingleton α (Set α) := ⟨fun x => Set.ext fun a => by simp only [mem_empty_iff_false, mem_insert_iff, or_false] exact Iff.rfl⟩ theorem singleton_def (a : α) : ({a} : Set α) = insert a ∅ := (insert_emptyc_eq a).symm #align set.singleton_def Set.singleton_def @[simp] theorem mem_singleton_iff {a b : α} : a ∈ ({b} : Set α) ↔ a = b := Iff.rfl #align set.mem_singleton_iff Set.mem_singleton_iff @[simp] theorem setOf_eq_eq_singleton {a : α} : { n | n = a } = {a} := rfl #align set.set_of_eq_eq_singleton Set.setOf_eq_eq_singleton @[simp] theorem setOf_eq_eq_singleton' {a : α} : { x | a = x } = {a} := ext fun _ => eq_comm #align set.set_of_eq_eq_singleton' Set.setOf_eq_eq_singleton' -- TODO: again, annotation needed --Porting note (#11119): removed `simp` attribute theorem mem_singleton (a : α) : a ∈ ({a} : Set α) := @rfl _ _ #align set.mem_singleton Set.mem_singleton theorem eq_of_mem_singleton {x y : α} (h : x ∈ ({y} : Set α)) : x = y := h #align set.eq_of_mem_singleton Set.eq_of_mem_singleton @[simp] theorem singleton_eq_singleton_iff {x y : α} : {x} = ({y} : Set α) ↔ x = y := ext_iff.trans eq_iff_eq_cancel_left #align set.singleton_eq_singleton_iff Set.singleton_eq_singleton_iff theorem singleton_injective : Injective (singleton : α → Set α) := fun _ _ => singleton_eq_singleton_iff.mp #align set.singleton_injective Set.singleton_injective theorem mem_singleton_of_eq {x y : α} (H : x = y) : x ∈ ({y} : Set α) := H #align set.mem_singleton_of_eq Set.mem_singleton_of_eq theorem insert_eq (x : α) (s : Set α) : insert x s = ({x} : Set α) ∪ s := rfl #align set.insert_eq Set.insert_eq @[simp] theorem singleton_nonempty (a : α) : ({a} : Set α).Nonempty := ⟨a, rfl⟩ #align set.singleton_nonempty Set.singleton_nonempty @[simp] theorem singleton_ne_empty (a : α) : ({a} : Set α) ≠ ∅ := (singleton_nonempty _).ne_empty #align set.singleton_ne_empty Set.singleton_ne_empty --Porting note (#10618): removed `simp` attribute because `simp` can prove it theorem empty_ssubset_singleton : (∅ : Set α) ⊂ {a} := (singleton_nonempty _).empty_ssubset #align set.empty_ssubset_singleton Set.empty_ssubset_singleton @[simp] theorem singleton_subset_iff {a : α} {s : Set α} : {a} ⊆ s ↔ a ∈ s := forall_eq #align set.singleton_subset_iff Set.singleton_subset_iff
Mathlib/Data/Set/Basic.lean
1,292
1,292
theorem singleton_subset_singleton : ({a} : Set α) ⊆ {b} ↔ a = b := by
simp
/- Copyright (c) 2020 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Jalex Stark -/ import Mathlib.Algebra.Polynomial.Monic #align_import algebra.polynomial.big_operators from "leanprover-community/mathlib"@"47adfab39a11a072db552f47594bf8ed2cf8a722" /-! # Lemmas for the interaction between polynomials and `∑` and `∏`. Recall that `∑` and `∏` are notation for `Finset.sum` and `Finset.prod` respectively. ## Main results - `Polynomial.natDegree_prod_of_monic` : the degree of a product of monic polynomials is the product of degrees. We prove this only for `[CommSemiring R]`, but it ought to be true for `[Semiring R]` and `List.prod`. - `Polynomial.natDegree_prod` : for polynomials over an integral domain, the degree of the product is the sum of degrees. - `Polynomial.leadingCoeff_prod` : for polynomials over an integral domain, the leading coefficient is the product of leading coefficients. - `Polynomial.prod_X_sub_C_coeff_card_pred` carries most of the content for computing the second coefficient of the characteristic polynomial. -/ open Finset open Multiset open Polynomial universe u w variable {R : Type u} {ι : Type w} namespace Polynomial variable (s : Finset ι) section Semiring variable {S : Type*} [Semiring S] set_option backward.isDefEq.lazyProjDelta false in -- See https://github.com/leanprover-community/mathlib4/issues/12535 theorem natDegree_list_sum_le (l : List S[X]) : natDegree l.sum ≤ (l.map natDegree).foldr max 0 := List.sum_le_foldr_max natDegree (by simp) natDegree_add_le _ #align polynomial.nat_degree_list_sum_le Polynomial.natDegree_list_sum_le theorem natDegree_multiset_sum_le (l : Multiset S[X]) : natDegree l.sum ≤ (l.map natDegree).foldr max max_left_comm 0 := Quotient.inductionOn l (by simpa using natDegree_list_sum_le) #align polynomial.nat_degree_multiset_sum_le Polynomial.natDegree_multiset_sum_le theorem natDegree_sum_le (f : ι → S[X]) : natDegree (∑ i ∈ s, f i) ≤ s.fold max 0 (natDegree ∘ f) := by simpa using natDegree_multiset_sum_le (s.val.map f) #align polynomial.nat_degree_sum_le Polynomial.natDegree_sum_le lemma natDegree_sum_le_of_forall_le {n : ℕ} (f : ι → S[X]) (h : ∀ i ∈ s, natDegree (f i) ≤ n) : natDegree (∑ i ∈ s, f i) ≤ n := le_trans (natDegree_sum_le s f) <| (Finset.fold_max_le n).mpr <| by simpa theorem degree_list_sum_le (l : List S[X]) : degree l.sum ≤ (l.map natDegree).maximum := by by_cases h : l.sum = 0 · simp [h] · rw [degree_eq_natDegree h] suffices (l.map natDegree).maximum = ((l.map natDegree).foldr max 0 : ℕ) by rw [this] simpa using natDegree_list_sum_le l rw [← List.foldr_max_of_ne_nil] · congr contrapose! h rw [List.map_eq_nil] at h simp [h] #align polynomial.degree_list_sum_le Polynomial.degree_list_sum_le theorem natDegree_list_prod_le (l : List S[X]) : natDegree l.prod ≤ (l.map natDegree).sum := by induction' l with hd tl IH · simp · simpa using natDegree_mul_le.trans (add_le_add_left IH _) #align polynomial.nat_degree_list_prod_le Polynomial.natDegree_list_prod_le theorem degree_list_prod_le (l : List S[X]) : degree l.prod ≤ (l.map degree).sum := by induction' l with hd tl IH · simp · simpa using (degree_mul_le _ _).trans (add_le_add_left IH _) #align polynomial.degree_list_prod_le Polynomial.degree_list_prod_le theorem coeff_list_prod_of_natDegree_le (l : List S[X]) (n : ℕ) (hl : ∀ p ∈ l, natDegree p ≤ n) : coeff (List.prod l) (l.length * n) = (l.map fun p => coeff p n).prod := by induction' l with hd tl IH · simp · have hl' : ∀ p ∈ tl, natDegree p ≤ n := fun p hp => hl p (List.mem_cons_of_mem _ hp) simp only [List.prod_cons, List.map, List.length] rw [add_mul, one_mul, add_comm, ← IH hl', mul_comm tl.length] have h : natDegree tl.prod ≤ n * tl.length := by refine (natDegree_list_prod_le _).trans ?_ rw [← tl.length_map natDegree, mul_comm] refine List.sum_le_card_nsmul _ _ ?_ simpa using hl' have hdn : natDegree hd ≤ n := hl _ (List.mem_cons_self _ _) rcases hdn.eq_or_lt with (rfl | hdn') · rcases h.eq_or_lt with h' | h' · rw [← h', coeff_mul_degree_add_degree, leadingCoeff, leadingCoeff] · rw [coeff_eq_zero_of_natDegree_lt, coeff_eq_zero_of_natDegree_lt h', mul_zero] exact natDegree_mul_le.trans_lt (add_lt_add_left h' _) · rw [coeff_eq_zero_of_natDegree_lt hdn', coeff_eq_zero_of_natDegree_lt, zero_mul] exact natDegree_mul_le.trans_lt (add_lt_add_of_lt_of_le hdn' h) #align polynomial.coeff_list_prod_of_nat_degree_le Polynomial.coeff_list_prod_of_natDegree_le end Semiring section CommSemiring variable [CommSemiring R] (f : ι → R[X]) (t : Multiset R[X]) theorem natDegree_multiset_prod_le : t.prod.natDegree ≤ (t.map natDegree).sum := Quotient.inductionOn t (by simpa using natDegree_list_prod_le) #align polynomial.nat_degree_multiset_prod_le Polynomial.natDegree_multiset_prod_le
Mathlib/Algebra/Polynomial/BigOperators.lean
124
125
theorem natDegree_prod_le : (∏ i ∈ s, f i).natDegree ≤ ∑ i ∈ s, (f i).natDegree := by
simpa using natDegree_multiset_prod_le (s.1.map f)
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.Polynomial.FieldDivision import Mathlib.Algebra.Polynomial.Lifts import Mathlib.Data.List.Prime #align_import data.polynomial.splits from "leanprover-community/mathlib"@"f694c7dead66f5d4c80f446c796a5aad14707f0e" /-! # Split polynomials A polynomial `f : K[X]` splits over a field extension `L` of `K` if it is zero or all of its irreducible factors over `L` have degree `1`. ## Main definitions * `Polynomial.Splits i f`: A predicate on a homomorphism `i : K →+* L` from a commutative ring to a field and a polynomial `f` saying that `f.map i` is zero or all of its irreducible factors over `L` have degree `1`. -/ noncomputable section open Polynomial universe u v w variable {R : Type*} {F : Type u} {K : Type v} {L : Type w} namespace Polynomial open Polynomial section Splits section CommRing variable [CommRing K] [Field L] [Field F] variable (i : K →+* L) /-- A polynomial `Splits` iff it is zero or all of its irreducible factors have `degree` 1. -/ def Splits (f : K[X]) : Prop := f.map i = 0 ∨ ∀ {g : L[X]}, Irreducible g → g ∣ f.map i → degree g = 1 #align polynomial.splits Polynomial.Splits @[simp] theorem splits_zero : Splits i (0 : K[X]) := Or.inl (Polynomial.map_zero i) #align polynomial.splits_zero Polynomial.splits_zero theorem splits_of_map_eq_C {f : K[X]} {a : L} (h : f.map i = C a) : Splits i f := letI := Classical.decEq L if ha : a = 0 then Or.inl (h.trans (ha.symm ▸ C_0)) else Or.inr fun hg ⟨p, hp⟩ => absurd hg.1 <| Classical.not_not.2 <| isUnit_iff_degree_eq_zero.2 <| by have := congr_arg degree hp rw [h, degree_C ha, degree_mul, @eq_comm (WithBot ℕ) 0, Nat.WithBot.add_eq_zero_iff] at this exact this.1 set_option linter.uppercaseLean3 false in #align polynomial.splits_of_map_eq_C Polynomial.splits_of_map_eq_C @[simp] theorem splits_C (a : K) : Splits i (C a) := splits_of_map_eq_C i (map_C i) set_option linter.uppercaseLean3 false in #align polynomial.splits_C Polynomial.splits_C theorem splits_of_map_degree_eq_one {f : K[X]} (hf : degree (f.map i) = 1) : Splits i f := Or.inr fun hg ⟨p, hp⟩ => by have := congr_arg degree hp simp [Nat.WithBot.add_eq_one_iff, hf, @eq_comm (WithBot ℕ) 1, mt isUnit_iff_degree_eq_zero.2 hg.1] at this tauto #align polynomial.splits_of_map_degree_eq_one Polynomial.splits_of_map_degree_eq_one theorem splits_of_degree_le_one {f : K[X]} (hf : degree f ≤ 1) : Splits i f := if hif : degree (f.map i) ≤ 0 then splits_of_map_eq_C i (degree_le_zero_iff.mp hif) else by push_neg at hif rw [← Order.succ_le_iff, ← WithBot.coe_zero, WithBot.succ_coe, Nat.succ_eq_succ] at hif exact splits_of_map_degree_eq_one i (le_antisymm ((degree_map_le i _).trans hf) hif) #align polynomial.splits_of_degree_le_one Polynomial.splits_of_degree_le_one theorem splits_of_degree_eq_one {f : K[X]} (hf : degree f = 1) : Splits i f := splits_of_degree_le_one i hf.le #align polynomial.splits_of_degree_eq_one Polynomial.splits_of_degree_eq_one theorem splits_of_natDegree_le_one {f : K[X]} (hf : natDegree f ≤ 1) : Splits i f := splits_of_degree_le_one i (degree_le_of_natDegree_le hf) #align polynomial.splits_of_nat_degree_le_one Polynomial.splits_of_natDegree_le_one theorem splits_of_natDegree_eq_one {f : K[X]} (hf : natDegree f = 1) : Splits i f := splits_of_natDegree_le_one i (le_of_eq hf) #align polynomial.splits_of_nat_degree_eq_one Polynomial.splits_of_natDegree_eq_one theorem splits_mul {f g : K[X]} (hf : Splits i f) (hg : Splits i g) : Splits i (f * g) := letI := Classical.decEq L if h : (f * g).map i = 0 then Or.inl h else Or.inr @fun p hp hpf => ((irreducible_iff_prime.1 hp).2.2 _ _ (show p ∣ map i f * map i g by convert hpf; rw [Polynomial.map_mul])).elim (hf.resolve_left (fun hf => by simp [hf] at h) hp) (hg.resolve_left (fun hg => by simp [hg] at h) hp) #align polynomial.splits_mul Polynomial.splits_mul theorem splits_of_splits_mul' {f g : K[X]} (hfg : (f * g).map i ≠ 0) (h : Splits i (f * g)) : Splits i f ∧ Splits i g := ⟨Or.inr @fun g hgi hg => Or.resolve_left h hfg hgi (by rw [Polynomial.map_mul]; exact hg.trans (dvd_mul_right _ _)), Or.inr @fun g hgi hg => Or.resolve_left h hfg hgi (by rw [Polynomial.map_mul]; exact hg.trans (dvd_mul_left _ _))⟩ #align polynomial.splits_of_splits_mul' Polynomial.splits_of_splits_mul' theorem splits_map_iff (j : L →+* F) {f : K[X]} : Splits j (f.map i) ↔ Splits (j.comp i) f := by simp [Splits, Polynomial.map_map] #align polynomial.splits_map_iff Polynomial.splits_map_iff theorem splits_one : Splits i 1 := splits_C i 1 #align polynomial.splits_one Polynomial.splits_one theorem splits_of_isUnit [IsDomain K] {u : K[X]} (hu : IsUnit u) : u.Splits i := (isUnit_iff.mp hu).choose_spec.2 ▸ splits_C _ _ #align polynomial.splits_of_is_unit Polynomial.splits_of_isUnit theorem splits_X_sub_C {x : K} : (X - C x).Splits i := splits_of_degree_le_one _ <| degree_X_sub_C_le _ set_option linter.uppercaseLean3 false in #align polynomial.splits_X_sub_C Polynomial.splits_X_sub_C theorem splits_X : X.Splits i := splits_of_degree_le_one _ degree_X_le set_option linter.uppercaseLean3 false in #align polynomial.splits_X Polynomial.splits_X theorem splits_prod {ι : Type u} {s : ι → K[X]} {t : Finset ι} : (∀ j ∈ t, (s j).Splits i) → (∏ x ∈ t, s x).Splits i := by classical refine Finset.induction_on t (fun _ => splits_one i) fun a t hat ih ht => ?_ rw [Finset.forall_mem_insert] at ht; rw [Finset.prod_insert hat] exact splits_mul i ht.1 (ih ht.2) #align polynomial.splits_prod Polynomial.splits_prod theorem splits_pow {f : K[X]} (hf : f.Splits i) (n : ℕ) : (f ^ n).Splits i := by rw [← Finset.card_range n, ← Finset.prod_const] exact splits_prod i fun j _ => hf #align polynomial.splits_pow Polynomial.splits_pow theorem splits_X_pow (n : ℕ) : (X ^ n).Splits i := splits_pow i (splits_X i) n set_option linter.uppercaseLean3 false in #align polynomial.splits_X_pow Polynomial.splits_X_pow theorem splits_id_iff_splits {f : K[X]} : (f.map i).Splits (RingHom.id L) ↔ f.Splits i := by rw [splits_map_iff, RingHom.id_comp] #align polynomial.splits_id_iff_splits Polynomial.splits_id_iff_splits theorem exists_root_of_splits' {f : K[X]} (hs : Splits i f) (hf0 : degree (f.map i) ≠ 0) : ∃ x, eval₂ i x f = 0 := letI := Classical.decEq L if hf0' : f.map i = 0 then by simp [eval₂_eq_eval_map, hf0'] else let ⟨g, hg⟩ := WfDvdMonoid.exists_irreducible_factor (show ¬IsUnit (f.map i) from mt isUnit_iff_degree_eq_zero.1 hf0) hf0' let ⟨x, hx⟩ := exists_root_of_degree_eq_one (hs.resolve_left hf0' hg.1 hg.2) let ⟨i, hi⟩ := hg.2 ⟨x, by rw [← eval_map, hi, eval_mul, show _ = _ from hx, zero_mul]⟩ #align polynomial.exists_root_of_splits' Polynomial.exists_root_of_splits' theorem roots_ne_zero_of_splits' {f : K[X]} (hs : Splits i f) (hf0 : natDegree (f.map i) ≠ 0) : (f.map i).roots ≠ 0 := let ⟨x, hx⟩ := exists_root_of_splits' i hs fun h => hf0 <| natDegree_eq_of_degree_eq_some h fun h => by rw [← eval_map] at hx have : f.map i ≠ 0 := by intro; simp_all cases h.subst ((mem_roots this).2 hx) #align polynomial.roots_ne_zero_of_splits' Polynomial.roots_ne_zero_of_splits' /-- Pick a root of a polynomial that splits. See `rootOfSplits` for polynomials over a field which has simpler assumptions. -/ def rootOfSplits' {f : K[X]} (hf : f.Splits i) (hfd : (f.map i).degree ≠ 0) : L := Classical.choose <| exists_root_of_splits' i hf hfd #align polynomial.root_of_splits' Polynomial.rootOfSplits' theorem map_rootOfSplits' {f : K[X]} (hf : f.Splits i) (hfd) : f.eval₂ i (rootOfSplits' i hf hfd) = 0 := Classical.choose_spec <| exists_root_of_splits' i hf hfd #align polynomial.map_root_of_splits' Polynomial.map_rootOfSplits' theorem natDegree_eq_card_roots' {p : K[X]} {i : K →+* L} (hsplit : Splits i p) : (p.map i).natDegree = Multiset.card (p.map i).roots := by by_cases hp : p.map i = 0 · rw [hp, natDegree_zero, roots_zero, Multiset.card_zero] obtain ⟨q, he, hd, hr⟩ := exists_prod_multiset_X_sub_C_mul (p.map i) rw [← splits_id_iff_splits, ← he] at hsplit rw [← he] at hp have hq : q ≠ 0 := fun h => hp (by rw [h, mul_zero]) rw [← hd, add_right_eq_self] by_contra h have h' : (map (RingHom.id L) q).natDegree ≠ 0 := by simp [h] have := roots_ne_zero_of_splits' (RingHom.id L) (splits_of_splits_mul' _ ?_ hsplit).2 h' · rw [map_id] at this exact this hr · rw [map_id] exact mul_ne_zero monic_prod_multiset_X_sub_C.ne_zero hq #align polynomial.nat_degree_eq_card_roots' Polynomial.natDegree_eq_card_roots' theorem degree_eq_card_roots' {p : K[X]} {i : K →+* L} (p_ne_zero : p.map i ≠ 0) (hsplit : Splits i p) : (p.map i).degree = Multiset.card (p.map i).roots := by simp [degree_eq_natDegree p_ne_zero, natDegree_eq_card_roots' hsplit] #align polynomial.degree_eq_card_roots' Polynomial.degree_eq_card_roots' end CommRing variable [CommRing R] [Field K] [Field L] [Field F] variable (i : K →+* L) /-- This lemma is for polynomials over a field. -/ theorem splits_iff (f : K[X]) : Splits i f ↔ f = 0 ∨ ∀ {g : L[X]}, Irreducible g → g ∣ f.map i → degree g = 1 := by rw [Splits, map_eq_zero] #align polynomial.splits_iff Polynomial.splits_iff /-- This lemma is for polynomials over a field. -/ theorem Splits.def {i : K →+* L} {f : K[X]} (h : Splits i f) : f = 0 ∨ ∀ {g : L[X]}, Irreducible g → g ∣ f.map i → degree g = 1 := (splits_iff i f).mp h #align polynomial.splits.def Polynomial.Splits.def theorem splits_of_splits_mul {f g : K[X]} (hfg : f * g ≠ 0) (h : Splits i (f * g)) : Splits i f ∧ Splits i g := splits_of_splits_mul' i (map_ne_zero hfg) h #align polynomial.splits_of_splits_mul Polynomial.splits_of_splits_mul theorem splits_of_splits_of_dvd {f g : K[X]} (hf0 : f ≠ 0) (hf : Splits i f) (hgf : g ∣ f) : Splits i g := by obtain ⟨f, rfl⟩ := hgf exact (splits_of_splits_mul i hf0 hf).1 #align polynomial.splits_of_splits_of_dvd Polynomial.splits_of_splits_of_dvd theorem splits_of_splits_gcd_left [DecidableEq K] {f g : K[X]} (hf0 : f ≠ 0) (hf : Splits i f) : Splits i (EuclideanDomain.gcd f g) := Polynomial.splits_of_splits_of_dvd i hf0 hf (EuclideanDomain.gcd_dvd_left f g) #align polynomial.splits_of_splits_gcd_left Polynomial.splits_of_splits_gcd_left theorem splits_of_splits_gcd_right [DecidableEq K] {f g : K[X]} (hg0 : g ≠ 0) (hg : Splits i g) : Splits i (EuclideanDomain.gcd f g) := Polynomial.splits_of_splits_of_dvd i hg0 hg (EuclideanDomain.gcd_dvd_right f g) #align polynomial.splits_of_splits_gcd_right Polynomial.splits_of_splits_gcd_right theorem splits_mul_iff {f g : K[X]} (hf : f ≠ 0) (hg : g ≠ 0) : (f * g).Splits i ↔ f.Splits i ∧ g.Splits i := ⟨splits_of_splits_mul i (mul_ne_zero hf hg), fun ⟨hfs, hgs⟩ => splits_mul i hfs hgs⟩ #align polynomial.splits_mul_iff Polynomial.splits_mul_iff theorem splits_prod_iff {ι : Type u} {s : ι → K[X]} {t : Finset ι} : (∀ j ∈ t, s j ≠ 0) → ((∏ x ∈ t, s x).Splits i ↔ ∀ j ∈ t, (s j).Splits i) := by classical refine Finset.induction_on t (fun _ => ⟨fun _ _ h => by simp only [Finset.not_mem_empty] at h, fun _ => splits_one i⟩) fun a t hat ih ht => ?_ rw [Finset.forall_mem_insert] at ht ⊢ rw [Finset.prod_insert hat, splits_mul_iff i ht.1 (Finset.prod_ne_zero_iff.2 ht.2), ih ht.2] #align polynomial.splits_prod_iff Polynomial.splits_prod_iff theorem degree_eq_one_of_irreducible_of_splits {p : K[X]} (hp : Irreducible p) (hp_splits : Splits (RingHom.id K) p) : p.degree = 1 := by rcases hp_splits with ⟨⟩ | hp_splits · exfalso simp_all · apply hp_splits hp simp #align polynomial.degree_eq_one_of_irreducible_of_splits Polynomial.degree_eq_one_of_irreducible_of_splits theorem exists_root_of_splits {f : K[X]} (hs : Splits i f) (hf0 : degree f ≠ 0) : ∃ x, eval₂ i x f = 0 := exists_root_of_splits' i hs ((f.degree_map i).symm ▸ hf0) #align polynomial.exists_root_of_splits Polynomial.exists_root_of_splits theorem roots_ne_zero_of_splits {f : K[X]} (hs : Splits i f) (hf0 : natDegree f ≠ 0) : (f.map i).roots ≠ 0 := roots_ne_zero_of_splits' i hs (ne_of_eq_of_ne (natDegree_map i) hf0) #align polynomial.roots_ne_zero_of_splits Polynomial.roots_ne_zero_of_splits /-- Pick a root of a polynomial that splits. This version is for polynomials over a field and has simpler assumptions. -/ def rootOfSplits {f : K[X]} (hf : f.Splits i) (hfd : f.degree ≠ 0) : L := rootOfSplits' i hf ((f.degree_map i).symm ▸ hfd) #align polynomial.root_of_splits Polynomial.rootOfSplits /-- `rootOfSplits'` is definitionally equal to `rootOfSplits`. -/ theorem rootOfSplits'_eq_rootOfSplits {f : K[X]} (hf : f.Splits i) (hfd) : rootOfSplits' i hf hfd = rootOfSplits i hf (f.degree_map i ▸ hfd) := rfl #align polynomial.root_of_splits'_eq_root_of_splits Polynomial.rootOfSplits'_eq_rootOfSplits theorem map_rootOfSplits {f : K[X]} (hf : f.Splits i) (hfd) : f.eval₂ i (rootOfSplits i hf hfd) = 0 := map_rootOfSplits' i hf (ne_of_eq_of_ne (degree_map f i) hfd) #align polynomial.map_root_of_splits Polynomial.map_rootOfSplits theorem natDegree_eq_card_roots {p : K[X]} {i : K →+* L} (hsplit : Splits i p) : p.natDegree = Multiset.card (p.map i).roots := (natDegree_map i).symm.trans <| natDegree_eq_card_roots' hsplit #align polynomial.nat_degree_eq_card_roots Polynomial.natDegree_eq_card_roots theorem degree_eq_card_roots {p : K[X]} {i : K →+* L} (p_ne_zero : p ≠ 0) (hsplit : Splits i p) : p.degree = Multiset.card (p.map i).roots := by rw [degree_eq_natDegree p_ne_zero, natDegree_eq_card_roots hsplit] #align polynomial.degree_eq_card_roots Polynomial.degree_eq_card_roots theorem roots_map {f : K[X]} (hf : f.Splits <| RingHom.id K) : (f.map i).roots = f.roots.map i := (roots_map_of_injective_of_card_eq_natDegree i.injective <| by convert (natDegree_eq_card_roots hf).symm rw [map_id]).symm #align polynomial.roots_map Polynomial.roots_map theorem image_rootSet [Algebra R K] [Algebra R L] {p : R[X]} (h : p.Splits (algebraMap R K)) (f : K →ₐ[R] L) : f '' p.rootSet K = p.rootSet L := by classical rw [rootSet, ← Finset.coe_image, ← Multiset.toFinset_map, ← f.coe_toRingHom, ← roots_map _ ((splits_id_iff_splits (algebraMap R K)).mpr h), map_map, f.comp_algebraMap, ← rootSet] #align polynomial.image_root_set Polynomial.image_rootSet theorem adjoin_rootSet_eq_range [Algebra R K] [Algebra R L] {p : R[X]} (h : p.Splits (algebraMap R K)) (f : K →ₐ[R] L) : Algebra.adjoin R (p.rootSet L) = f.range ↔ Algebra.adjoin R (p.rootSet K) = ⊤ := by rw [← image_rootSet h f, Algebra.adjoin_image, ← Algebra.map_top] exact (Subalgebra.map_injective f.toRingHom.injective).eq_iff #align polynomial.adjoin_root_set_eq_range Polynomial.adjoin_rootSet_eq_range theorem eq_prod_roots_of_splits {p : K[X]} {i : K →+* L} (hsplit : Splits i p) : p.map i = C (i p.leadingCoeff) * ((p.map i).roots.map fun a => X - C a).prod := by rw [← leadingCoeff_map]; symm apply C_leadingCoeff_mul_prod_multiset_X_sub_C rw [natDegree_map]; exact (natDegree_eq_card_roots hsplit).symm #align polynomial.eq_prod_roots_of_splits Polynomial.eq_prod_roots_of_splits theorem eq_prod_roots_of_splits_id {p : K[X]} (hsplit : Splits (RingHom.id K) p) : p = C p.leadingCoeff * (p.roots.map fun a => X - C a).prod := by simpa using eq_prod_roots_of_splits hsplit #align polynomial.eq_prod_roots_of_splits_id Polynomial.eq_prod_roots_of_splits_id theorem eq_prod_roots_of_monic_of_splits_id {p : K[X]} (m : Monic p) (hsplit : Splits (RingHom.id K) p) : p = (p.roots.map fun a => X - C a).prod := by convert eq_prod_roots_of_splits_id hsplit simp [m] #align polynomial.eq_prod_roots_of_monic_of_splits_id Polynomial.eq_prod_roots_of_monic_of_splits_id theorem eq_X_sub_C_of_splits_of_single_root {x : K} {h : K[X]} (h_splits : Splits i h) (h_roots : (h.map i).roots = {i x}) : h = C h.leadingCoeff * (X - C x) := by apply Polynomial.map_injective _ i.injective rw [eq_prod_roots_of_splits h_splits, h_roots] simp set_option linter.uppercaseLean3 false in #align polynomial.eq_X_sub_C_of_splits_of_single_root Polynomial.eq_X_sub_C_of_splits_of_single_root variable (R) in theorem mem_lift_of_splits_of_roots_mem_range [Algebra R K] {f : K[X]} (hs : f.Splits (RingHom.id K)) (hm : f.Monic) (hr : ∀ a ∈ f.roots, a ∈ (algebraMap R K).range) : f ∈ Polynomial.lifts (algebraMap R K) := by rw [eq_prod_roots_of_monic_of_splits_id hm hs, lifts_iff_liftsRing] refine Subring.multiset_prod_mem _ _ fun P hP => ?_ obtain ⟨b, hb, rfl⟩ := Multiset.mem_map.1 hP exact Subring.sub_mem _ (X_mem_lifts _) (C'_mem_lifts (hr _ hb)) #align polynomial.mem_lift_of_splits_of_roots_mem_range Polynomial.mem_lift_of_splits_of_roots_mem_range section UFD attribute [local instance] PrincipalIdealRing.to_uniqueFactorizationMonoid local infixl:50 " ~ᵤ " => Associated open UniqueFactorizationMonoid Associates theorem splits_of_exists_multiset {f : K[X]} {s : Multiset L} (hs : f.map i = C (i f.leadingCoeff) * (s.map fun a : L => X - C a).prod) : Splits i f := letI := Classical.decEq K if hf0 : f = 0 then hf0.symm ▸ splits_zero i else Or.inr @fun p hp hdp => by rw [irreducible_iff_prime] at hp rw [hs, ← Multiset.prod_toList] at hdp obtain hd | hd := hp.2.2 _ _ hdp · refine (hp.2.1 <| isUnit_of_dvd_unit hd ?_).elim exact isUnit_C.2 ((leadingCoeff_ne_zero.2 hf0).isUnit.map i) · obtain ⟨q, hq, hd⟩ := hp.dvd_prod_iff.1 hd obtain ⟨a, _, rfl⟩ := Multiset.mem_map.1 (Multiset.mem_toList.1 hq) rw [degree_eq_degree_of_associated ((hp.dvd_prime_iff_associated <| prime_X_sub_C a).1 hd)] exact degree_X_sub_C a #align polynomial.splits_of_exists_multiset Polynomial.splits_of_exists_multiset theorem splits_of_splits_id {f : K[X]} : Splits (RingHom.id K) f → Splits i f := UniqueFactorizationMonoid.induction_on_prime f (fun _ => splits_zero _) (fun _ hu _ => splits_of_degree_le_one _ ((isUnit_iff_degree_eq_zero.1 hu).symm ▸ by decide)) fun a p ha0 hp ih hfi => splits_mul _ (splits_of_degree_eq_one _ ((splits_of_splits_mul _ (mul_ne_zero hp.1 ha0) hfi).1.def.resolve_left hp.1 hp.irreducible (by rw [map_id]))) (ih (splits_of_splits_mul _ (mul_ne_zero hp.1 ha0) hfi).2) #align polynomial.splits_of_splits_id Polynomial.splits_of_splits_id end UFD theorem splits_iff_exists_multiset {f : K[X]} : Splits i f ↔ ∃ s : Multiset L, f.map i = C (i f.leadingCoeff) * (s.map fun a : L => X - C a).prod := ⟨fun hf => ⟨(f.map i).roots, eq_prod_roots_of_splits hf⟩, fun ⟨_, hs⟩ => splits_of_exists_multiset i hs⟩ #align polynomial.splits_iff_exists_multiset Polynomial.splits_iff_exists_multiset theorem splits_of_comp (j : L →+* F) {f : K[X]} (h : Splits (j.comp i) f) (roots_mem_range : ∀ a ∈ (f.map (j.comp i)).roots, a ∈ j.range) : Splits i f := by choose lift lift_eq using roots_mem_range rw [splits_iff_exists_multiset] refine ⟨(f.map (j.comp i)).roots.pmap lift fun _ ↦ id, map_injective _ j.injective ?_⟩ conv_lhs => rw [Polynomial.map_map, eq_prod_roots_of_splits h] simp_rw [Polynomial.map_mul, Polynomial.map_multiset_prod, Multiset.map_pmap, Polynomial.map_sub, map_C, map_X, lift_eq, Multiset.pmap_eq_map] rfl theorem splits_id_of_splits {f : K[X]} (h : Splits i f) (roots_mem_range : ∀ a ∈ (f.map i).roots, a ∈ i.range) : Splits (RingHom.id K) f := splits_of_comp (RingHom.id K) i h roots_mem_range theorem splits_comp_of_splits (i : R →+* K) (j : K →+* L) {f : R[X]} (h : Splits i f) : Splits (j.comp i) f := (splits_map_iff i j).mp (splits_of_splits_id _ <| (splits_map_iff i <| .id K).mpr h) #align polynomial.splits_comp_of_splits Polynomial.splits_comp_of_splits variable [Algebra R K] [Algebra R L] theorem splits_of_algHom {f : R[X]} (h : Splits (algebraMap R K) f) (e : K →ₐ[R] L) : Splits (algebraMap R L) f := by rw [← e.comp_algebraMap_of_tower R]; exact splits_comp_of_splits _ _ h variable (L) in theorem splits_of_isScalarTower {f : R[X]} [Algebra K L] [IsScalarTower R K L] (h : Splits (algebraMap R K) f) : Splits (algebraMap R L) f := splits_of_algHom h (IsScalarTower.toAlgHom R K L) /-- A polynomial splits if and only if it has as many roots as its degree. -/
Mathlib/Algebra/Polynomial/Splits.lean
457
466
theorem splits_iff_card_roots {p : K[X]} : Splits (RingHom.id K) p ↔ Multiset.card p.roots = p.natDegree := by
constructor · intro H rw [natDegree_eq_card_roots H, map_id] · intro hroots rw [splits_iff_exists_multiset (RingHom.id K)] use p.roots simp only [RingHom.id_apply, map_id] exact (C_leadingCoeff_mul_prod_multiset_X_sub_C hroots).symm
/- Copyright (c) 2024 Jeremy Tan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Tan -/ import Mathlib.Combinatorics.SimpleGraph.Clique /-! # The Turán graph This file defines the Turán graph and proves some of its basic properties. ## Main declarations * `SimpleGraph.IsTuranMaximal`: `G.IsTuranMaximal r` means that `G` has the most number of edges for its number of vertices while still being `r + 1`-cliquefree. * `SimpleGraph.turanGraph n r`: The canonical `r + 1`-cliquefree Turán graph on `n` vertices. ## TODO * Port the rest of Turán's theorem from https://github.com/leanprover-community/mathlib4/pull/9317 -/ open Finset namespace SimpleGraph variable {V : Type*} [Fintype V] [DecidableEq V] (G H : SimpleGraph V) [DecidableRel G.Adj] {n r : ℕ} /-- An `r + 1`-cliquefree graph is `r`-Turán-maximal if any other `r + 1`-cliquefree graph on the same vertex set has the same or fewer number of edges. -/ def IsTuranMaximal (r : ℕ) : Prop := G.CliqueFree (r + 1) ∧ ∀ (H : SimpleGraph V) [DecidableRel H.Adj], H.CliqueFree (r + 1) → H.edgeFinset.card ≤ G.edgeFinset.card variable {G H} lemma IsTuranMaximal.le_iff_eq (hG : G.IsTuranMaximal r) (hH : H.CliqueFree (r + 1)) : G ≤ H ↔ G = H := by classical exact ⟨fun hGH ↦ edgeFinset_inj.1 <| eq_of_subset_of_card_le (edgeFinset_subset_edgeFinset.2 hGH) (hG.2 _ hH), le_of_eq⟩ /-- The canonical `r + 1`-cliquefree Turán graph on `n` vertices. -/ def turanGraph (n r : ℕ) : SimpleGraph (Fin n) where Adj v w := v % r ≠ w % r instance turanGraph.instDecidableRelAdj : DecidableRel (turanGraph n r).Adj := by dsimp only [turanGraph]; infer_instance @[simp] lemma turanGraph_zero : turanGraph n 0 = ⊤ := by ext a b; simp_rw [turanGraph, top_adj, Nat.mod_zero, not_iff_not, Fin.val_inj] @[simp] theorem turanGraph_eq_top : turanGraph n r = ⊤ ↔ r = 0 ∨ n ≤ r := by simp_rw [SimpleGraph.ext_iff, Function.funext_iff, turanGraph, top_adj, eq_iff_iff, not_iff_not] refine ⟨fun h ↦ ?_, ?_⟩ · contrapose! h use ⟨0, (Nat.pos_of_ne_zero h.1).trans h.2⟩, ⟨r, h.2⟩ simp [h.1.symm] · rintro (rfl | h) a b · simp [Fin.val_inj] · rw [Nat.mod_eq_of_lt (a.2.trans_le h), Nat.mod_eq_of_lt (b.2.trans_le h), Fin.val_inj] variable (hr : 0 < r) theorem turanGraph_cliqueFree : (turanGraph n r).CliqueFree (r + 1) := by rw [cliqueFree_iff] by_contra h rw [not_isEmpty_iff] at h obtain ⟨f, ha⟩ := h simp only [turanGraph, top_adj] at ha obtain ⟨x, y, d, c⟩ := Fintype.exists_ne_map_eq_of_card_lt (fun x ↦ (⟨(f x).1 % r, Nat.mod_lt _ hr⟩ : Fin r)) (by simp) simp only [Fin.mk.injEq] at c exact absurd c ((@ha x y).mpr d) /-- For `n ≤ r` and `0 < r`, `turanGraph n r` is Turán-maximal. -/ theorem isTuranMaximal_turanGraph (h : n ≤ r) : (turanGraph n r).IsTuranMaximal r := ⟨turanGraph_cliqueFree hr, fun _ _ _ ↦ card_le_card (edgeFinset_mono ((turanGraph_eq_top.mpr (Or.inr h)).symm ▸ le_top))⟩ /-- An `r + 1`-cliquefree Turán-maximal graph is _not_ `r`-cliquefree if it can accommodate such a clique. -/
Mathlib/Combinatorics/SimpleGraph/Turan.lean
84
92
theorem not_cliqueFree_of_isTuranMaximal (hn : r ≤ Fintype.card V) (hG : G.IsTuranMaximal r) : ¬G.CliqueFree r := by
rintro h obtain ⟨K, _, rfl⟩ := exists_smaller_set (univ : Finset V) r hn obtain ⟨a, -, b, -, hab, hGab⟩ : ∃ a ∈ K, ∃ b ∈ K, a ≠ b ∧ ¬ G.Adj a b := by simpa only [isNClique_iff, IsClique, Set.Pairwise, mem_coe, ne_eq, and_true, not_forall, exists_prop, exists_and_right] using h K exact hGab <| le_sup_right.trans_eq ((hG.le_iff_eq <| h.sup_edge _ _).1 le_sup_left).symm <| (edge_adj ..).2 ⟨Or.inl ⟨rfl, rfl⟩, hab⟩
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Frédéric Dupuis, Heather Macbeth -/ import Mathlib.Analysis.Convex.Basic import Mathlib.Analysis.InnerProductSpace.Orthogonal import Mathlib.Analysis.InnerProductSpace.Symmetric import Mathlib.Analysis.NormedSpace.RCLike import Mathlib.Analysis.RCLike.Lemmas import Mathlib.Algebra.DirectSum.Decomposition #align_import analysis.inner_product_space.projection from "leanprover-community/mathlib"@"0b7c740e25651db0ba63648fbae9f9d6f941e31b" /-! # The orthogonal projection Given a nonempty complete subspace `K` of an inner product space `E`, this file constructs `orthogonalProjection K : E →L[𝕜] K`, the orthogonal projection of `E` onto `K`. This map satisfies: for any point `u` in `E`, the point `v = orthogonalProjection K u` in `K` minimizes the distance `‖u - v‖` to `u`. Also a linear isometry equivalence `reflection K : E ≃ₗᵢ[𝕜] E` is constructed, by choosing, for each `u : E`, the point `reflection K u` to satisfy `u + (reflection K u) = 2 • orthogonalProjection K u`. Basic API for `orthogonalProjection` and `reflection` is developed. Next, the orthogonal projection is used to prove a series of more subtle lemmas about the orthogonal complement of complete subspaces of `E` (the orthogonal complement itself was defined in `Analysis.InnerProductSpace.Orthogonal`); the lemma `Submodule.sup_orthogonal_of_completeSpace`, stating that for a complete subspace `K` of `E` we have `K ⊔ Kᗮ = ⊤`, is a typical example. ## References The orthogonal projection construction is adapted from * [Clément & Martin, *The Lax-Milgram Theorem. A detailed proof to be formalized in Coq*] * [Clément & Martin, *A Coq formal proof of the Lax–Milgram theorem*] The Coq code is available at the following address: <http://www.lri.fr/~sboldo/elfic/index.html> -/ noncomputable section open RCLike Real Filter open LinearMap (ker range) open Topology variable {𝕜 E F : Type*} [RCLike 𝕜] variable [NormedAddCommGroup E] [NormedAddCommGroup F] variable [InnerProductSpace 𝕜 E] [InnerProductSpace ℝ F] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y local notation "absR" => abs /-! ### Orthogonal projection in inner product spaces -/ -- FIXME this monolithic proof causes a deterministic timeout with `-T50000` -- It should be broken in a sequence of more manageable pieces, -- perhaps with individual statements for the three steps below. /-- Existence of minimizers Let `u` be a point in a real inner product space, and let `K` be a nonempty complete convex subset. Then there exists a (unique) `v` in `K` that minimizes the distance `‖u - v‖` to `u`. -/ theorem exists_norm_eq_iInf_of_complete_convex {K : Set F} (ne : K.Nonempty) (h₁ : IsComplete K) (h₂ : Convex ℝ K) : ∀ u : F, ∃ v ∈ K, ‖u - v‖ = ⨅ w : K, ‖u - w‖ := fun u => by let δ := ⨅ w : K, ‖u - w‖ letI : Nonempty K := ne.to_subtype have zero_le_δ : 0 ≤ δ := le_ciInf fun _ => norm_nonneg _ have δ_le : ∀ w : K, δ ≤ ‖u - w‖ := ciInf_le ⟨0, Set.forall_mem_range.2 fun _ => norm_nonneg _⟩ have δ_le' : ∀ w ∈ K, δ ≤ ‖u - w‖ := fun w hw => δ_le ⟨w, hw⟩ -- Step 1: since `δ` is the infimum, can find a sequence `w : ℕ → K` in `K` -- such that `‖u - w n‖ < δ + 1 / (n + 1)` (which implies `‖u - w n‖ --> δ`); -- maybe this should be a separate lemma have exists_seq : ∃ w : ℕ → K, ∀ n, ‖u - w n‖ < δ + 1 / (n + 1) := by have hδ : ∀ n : ℕ, δ < δ + 1 / (n + 1) := fun n => lt_add_of_le_of_pos le_rfl Nat.one_div_pos_of_nat have h := fun n => exists_lt_of_ciInf_lt (hδ n) let w : ℕ → K := fun n => Classical.choose (h n) exact ⟨w, fun n => Classical.choose_spec (h n)⟩ rcases exists_seq with ⟨w, hw⟩ have norm_tendsto : Tendsto (fun n => ‖u - w n‖) atTop (𝓝 δ) := by have h : Tendsto (fun _ : ℕ => δ) atTop (𝓝 δ) := tendsto_const_nhds have h' : Tendsto (fun n : ℕ => δ + 1 / (n + 1)) atTop (𝓝 δ) := by convert h.add tendsto_one_div_add_atTop_nhds_zero_nat simp only [add_zero] exact tendsto_of_tendsto_of_tendsto_of_le_of_le h h' (fun x => δ_le _) fun x => le_of_lt (hw _) -- Step 2: Prove that the sequence `w : ℕ → K` is a Cauchy sequence have seq_is_cauchy : CauchySeq fun n => (w n : F) := by rw [cauchySeq_iff_le_tendsto_0] -- splits into three goals let b := fun n : ℕ => 8 * δ * (1 / (n + 1)) + 4 * (1 / (n + 1)) * (1 / (n + 1)) use fun n => √(b n) constructor -- first goal : `∀ (n : ℕ), 0 ≤ √(b n)` · intro n exact sqrt_nonneg _ constructor -- second goal : `∀ (n m N : ℕ), N ≤ n → N ≤ m → dist ↑(w n) ↑(w m) ≤ √(b N)` · intro p q N hp hq let wp := (w p : F) let wq := (w q : F) let a := u - wq let b := u - wp let half := 1 / (2 : ℝ) let div := 1 / ((N : ℝ) + 1) have : 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ + ‖wp - wq‖ * ‖wp - wq‖ = 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) := calc 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ + ‖wp - wq‖ * ‖wp - wq‖ = 2 * ‖u - half • (wq + wp)‖ * (2 * ‖u - half • (wq + wp)‖) + ‖wp - wq‖ * ‖wp - wq‖ := by ring _ = absR (2 : ℝ) * ‖u - half • (wq + wp)‖ * (absR (2 : ℝ) * ‖u - half • (wq + wp)‖) + ‖wp - wq‖ * ‖wp - wq‖ := by rw [_root_.abs_of_nonneg] exact zero_le_two _ = ‖(2 : ℝ) • (u - half • (wq + wp))‖ * ‖(2 : ℝ) • (u - half • (wq + wp))‖ + ‖wp - wq‖ * ‖wp - wq‖ := by simp [norm_smul] _ = ‖a + b‖ * ‖a + b‖ + ‖a - b‖ * ‖a - b‖ := by rw [smul_sub, smul_smul, mul_one_div_cancel (_root_.two_ne_zero : (2 : ℝ) ≠ 0), ← one_add_one_eq_two, add_smul] simp only [one_smul] have eq₁ : wp - wq = a - b := (sub_sub_sub_cancel_left _ _ _).symm have eq₂ : u + u - (wq + wp) = a + b := by show u + u - (wq + wp) = u - wq + (u - wp) abel rw [eq₁, eq₂] _ = 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) := parallelogram_law_with_norm ℝ _ _ have eq : δ ≤ ‖u - half • (wq + wp)‖ := by rw [smul_add] apply δ_le' apply h₂ repeat' exact Subtype.mem _ repeat' exact le_of_lt one_half_pos exact add_halves 1 have eq₁ : 4 * δ * δ ≤ 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ := by simp_rw [mul_assoc] gcongr have eq₂ : ‖a‖ ≤ δ + div := le_trans (le_of_lt <| hw q) (add_le_add_left (Nat.one_div_le_one_div hq) _) have eq₂' : ‖b‖ ≤ δ + div := le_trans (le_of_lt <| hw p) (add_le_add_left (Nat.one_div_le_one_div hp) _) rw [dist_eq_norm] apply nonneg_le_nonneg_of_sq_le_sq · exact sqrt_nonneg _ rw [mul_self_sqrt] · calc ‖wp - wq‖ * ‖wp - wq‖ = 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) - 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ := by simp [← this] _ ≤ 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) - 4 * δ * δ := by gcongr _ ≤ 2 * ((δ + div) * (δ + div) + (δ + div) * (δ + div)) - 4 * δ * δ := by gcongr _ = 8 * δ * div + 4 * div * div := by ring positivity -- third goal : `Tendsto (fun (n : ℕ) => √(b n)) atTop (𝓝 0)` suffices Tendsto (fun x ↦ √(8 * δ * x + 4 * x * x) : ℝ → ℝ) (𝓝 0) (𝓝 0) from this.comp tendsto_one_div_add_atTop_nhds_zero_nat exact Continuous.tendsto' (by continuity) _ _ (by simp) -- Step 3: By completeness of `K`, let `w : ℕ → K` converge to some `v : K`. -- Prove that it satisfies all requirements. rcases cauchySeq_tendsto_of_isComplete h₁ (fun n => Subtype.mem _) seq_is_cauchy with ⟨v, hv, w_tendsto⟩ use v use hv have h_cont : Continuous fun v => ‖u - v‖ := Continuous.comp continuous_norm (Continuous.sub continuous_const continuous_id) have : Tendsto (fun n => ‖u - w n‖) atTop (𝓝 ‖u - v‖) := by convert Tendsto.comp h_cont.continuousAt w_tendsto exact tendsto_nhds_unique this norm_tendsto #align exists_norm_eq_infi_of_complete_convex exists_norm_eq_iInf_of_complete_convex /-- Characterization of minimizers for the projection on a convex set in a real inner product space. -/ theorem norm_eq_iInf_iff_real_inner_le_zero {K : Set F} (h : Convex ℝ K) {u : F} {v : F} (hv : v ∈ K) : (‖u - v‖ = ⨅ w : K, ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by letI : Nonempty K := ⟨⟨v, hv⟩⟩ constructor · intro eq w hw let δ := ⨅ w : K, ‖u - w‖ let p := ⟪u - v, w - v⟫_ℝ let q := ‖w - v‖ ^ 2 have δ_le (w : K) : δ ≤ ‖u - w‖ := ciInf_le ⟨0, fun _ ⟨_, h⟩ => h ▸ norm_nonneg _⟩ _ have δ_le' (w) (hw : w ∈ K) : δ ≤ ‖u - w‖ := δ_le ⟨w, hw⟩ have (θ : ℝ) (hθ₁ : 0 < θ) (hθ₂ : θ ≤ 1) : 2 * p ≤ θ * q := by have : ‖u - v‖ ^ 2 ≤ ‖u - v‖ ^ 2 - 2 * θ * ⟪u - v, w - v⟫_ℝ + θ * θ * ‖w - v‖ ^ 2 := calc ‖u - v‖ ^ 2 _ ≤ ‖u - (θ • w + (1 - θ) • v)‖ ^ 2 := by simp only [sq]; apply mul_self_le_mul_self (norm_nonneg _) rw [eq]; apply δ_le' apply h hw hv exacts [le_of_lt hθ₁, sub_nonneg.2 hθ₂, add_sub_cancel _ _] _ = ‖u - v - θ • (w - v)‖ ^ 2 := by have : u - (θ • w + (1 - θ) • v) = u - v - θ • (w - v) := by rw [smul_sub, sub_smul, one_smul] simp only [sub_eq_add_neg, add_comm, add_left_comm, add_assoc, neg_add_rev] rw [this] _ = ‖u - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) + θ * θ * ‖w - v‖ ^ 2 := by rw [@norm_sub_sq ℝ, inner_smul_right, norm_smul] simp only [sq] show ‖u - v‖ * ‖u - v‖ - 2 * (θ * inner (u - v) (w - v)) + absR θ * ‖w - v‖ * (absR θ * ‖w - v‖) = ‖u - v‖ * ‖u - v‖ - 2 * θ * inner (u - v) (w - v) + θ * θ * (‖w - v‖ * ‖w - v‖) rw [abs_of_pos hθ₁]; ring have eq₁ : ‖u - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) + θ * θ * ‖w - v‖ ^ 2 = ‖u - v‖ ^ 2 + (θ * θ * ‖w - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v)) := by abel rw [eq₁, le_add_iff_nonneg_right] at this have eq₂ : θ * θ * ‖w - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) = θ * (θ * ‖w - v‖ ^ 2 - 2 * inner (u - v) (w - v)) := by ring rw [eq₂] at this have := le_of_sub_nonneg (nonneg_of_mul_nonneg_right this hθ₁) exact this by_cases hq : q = 0 · rw [hq] at this have : p ≤ 0 := by have := this (1 : ℝ) (by norm_num) (by norm_num) linarith exact this · have q_pos : 0 < q := lt_of_le_of_ne (sq_nonneg _) fun h ↦ hq h.symm by_contra hp rw [not_le] at hp let θ := min (1 : ℝ) (p / q) have eq₁ : θ * q ≤ p := calc θ * q ≤ p / q * q := mul_le_mul_of_nonneg_right (min_le_right _ _) (sq_nonneg _) _ = p := div_mul_cancel₀ _ hq have : 2 * p ≤ p := calc 2 * p ≤ θ * q := by set_option tactic.skipAssignedInstances false in exact this θ (lt_min (by norm_num) (div_pos hp q_pos)) (by norm_num [θ]) _ ≤ p := eq₁ linarith · intro h apply le_antisymm · apply le_ciInf intro w apply nonneg_le_nonneg_of_sq_le_sq (norm_nonneg _) have := h w w.2 calc ‖u - v‖ * ‖u - v‖ ≤ ‖u - v‖ * ‖u - v‖ - 2 * inner (u - v) ((w : F) - v) := by linarith _ ≤ ‖u - v‖ ^ 2 - 2 * inner (u - v) ((w : F) - v) + ‖(w : F) - v‖ ^ 2 := by rw [sq] refine le_add_of_nonneg_right ?_ exact sq_nonneg _ _ = ‖u - v - (w - v)‖ ^ 2 := (@norm_sub_sq ℝ _ _ _ _ _ _).symm _ = ‖u - w‖ * ‖u - w‖ := by have : u - v - (w - v) = u - w := by abel rw [this, sq] · show ⨅ w : K, ‖u - w‖ ≤ (fun w : K => ‖u - w‖) ⟨v, hv⟩ apply ciInf_le use 0 rintro y ⟨z, rfl⟩ exact norm_nonneg _ #align norm_eq_infi_iff_real_inner_le_zero norm_eq_iInf_iff_real_inner_le_zero variable (K : Submodule 𝕜 E) /-- Existence of projections on complete subspaces. Let `u` be a point in an inner product space, and let `K` be a nonempty complete subspace. Then there exists a (unique) `v` in `K` that minimizes the distance `‖u - v‖` to `u`. This point `v` is usually called the orthogonal projection of `u` onto `K`. -/ theorem exists_norm_eq_iInf_of_complete_subspace (h : IsComplete (↑K : Set E)) : ∀ u : E, ∃ v ∈ K, ‖u - v‖ = ⨅ w : (K : Set E), ‖u - w‖ := by letI : InnerProductSpace ℝ E := InnerProductSpace.rclikeToReal 𝕜 E letI : Module ℝ E := RestrictScalars.module ℝ 𝕜 E let K' : Submodule ℝ E := Submodule.restrictScalars ℝ K exact exists_norm_eq_iInf_of_complete_convex ⟨0, K'.zero_mem⟩ h K'.convex #align exists_norm_eq_infi_of_complete_subspace exists_norm_eq_iInf_of_complete_subspace /-- Characterization of minimizers in the projection on a subspace, in the real case. Let `u` be a point in a real inner product space, and let `K` be a nonempty subspace. Then point `v` minimizes the distance `‖u - v‖` over points in `K` if and only if for all `w ∈ K`, `⟪u - v, w⟫ = 0` (i.e., `u - v` is orthogonal to the subspace `K`). This is superceded by `norm_eq_iInf_iff_inner_eq_zero` that gives the same conclusion over any `RCLike` field. -/ theorem norm_eq_iInf_iff_real_inner_eq_zero (K : Submodule ℝ F) {u : F} {v : F} (hv : v ∈ K) : (‖u - v‖ = ⨅ w : (↑K : Set F), ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w⟫_ℝ = 0 := Iff.intro (by intro h have h : ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by rwa [norm_eq_iInf_iff_real_inner_le_zero] at h exacts [K.convex, hv] intro w hw have le : ⟪u - v, w⟫_ℝ ≤ 0 := by let w' := w + v have : w' ∈ K := Submodule.add_mem _ hw hv have h₁ := h w' this have h₂ : w' - v = w := by simp only [w', add_neg_cancel_right, sub_eq_add_neg] rw [h₂] at h₁ exact h₁ have ge : ⟪u - v, w⟫_ℝ ≥ 0 := by let w'' := -w + v have : w'' ∈ K := Submodule.add_mem _ (Submodule.neg_mem _ hw) hv have h₁ := h w'' this have h₂ : w'' - v = -w := by simp only [w'', neg_inj, add_neg_cancel_right, sub_eq_add_neg] rw [h₂, inner_neg_right] at h₁ linarith exact le_antisymm le ge) (by intro h have : ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by intro w hw let w' := w - v have : w' ∈ K := Submodule.sub_mem _ hw hv have h₁ := h w' this exact le_of_eq h₁ rwa [norm_eq_iInf_iff_real_inner_le_zero] exacts [Submodule.convex _, hv]) #align norm_eq_infi_iff_real_inner_eq_zero norm_eq_iInf_iff_real_inner_eq_zero /-- Characterization of minimizers in the projection on a subspace. Let `u` be a point in an inner product space, and let `K` be a nonempty subspace. Then point `v` minimizes the distance `‖u - v‖` over points in `K` if and only if for all `w ∈ K`, `⟪u - v, w⟫ = 0` (i.e., `u - v` is orthogonal to the subspace `K`) -/ theorem norm_eq_iInf_iff_inner_eq_zero {u : E} {v : E} (hv : v ∈ K) : (‖u - v‖ = ⨅ w : K, ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w⟫ = 0 := by letI : InnerProductSpace ℝ E := InnerProductSpace.rclikeToReal 𝕜 E letI : Module ℝ E := RestrictScalars.module ℝ 𝕜 E let K' : Submodule ℝ E := K.restrictScalars ℝ constructor · intro H have A : ∀ w ∈ K, re ⟪u - v, w⟫ = 0 := (norm_eq_iInf_iff_real_inner_eq_zero K' hv).1 H intro w hw apply ext · simp [A w hw] · symm calc im (0 : 𝕜) = 0 := im.map_zero _ = re ⟪u - v, (-I : 𝕜) • w⟫ := (A _ (K.smul_mem (-I) hw)).symm _ = re (-I * ⟪u - v, w⟫) := by rw [inner_smul_right] _ = im ⟪u - v, w⟫ := by simp · intro H have : ∀ w ∈ K', ⟪u - v, w⟫_ℝ = 0 := by intro w hw rw [real_inner_eq_re_inner, H w hw] exact zero_re' exact (norm_eq_iInf_iff_real_inner_eq_zero K' hv).2 this #align norm_eq_infi_iff_inner_eq_zero norm_eq_iInf_iff_inner_eq_zero /-- A subspace `K : Submodule 𝕜 E` has an orthogonal projection if evey vector `v : E` admits an orthogonal projection to `K`. -/ class HasOrthogonalProjection (K : Submodule 𝕜 E) : Prop where exists_orthogonal (v : E) : ∃ w ∈ K, v - w ∈ Kᗮ instance (priority := 100) HasOrthogonalProjection.ofCompleteSpace [CompleteSpace K] : HasOrthogonalProjection K where exists_orthogonal v := by rcases exists_norm_eq_iInf_of_complete_subspace K (completeSpace_coe_iff_isComplete.mp ‹_›) v with ⟨w, hwK, hw⟩ refine ⟨w, hwK, (K.mem_orthogonal' _).2 ?_⟩ rwa [← norm_eq_iInf_iff_inner_eq_zero K hwK] instance [HasOrthogonalProjection K] : HasOrthogonalProjection Kᗮ where exists_orthogonal v := by rcases HasOrthogonalProjection.exists_orthogonal (K := K) v with ⟨w, hwK, hw⟩ refine ⟨_, hw, ?_⟩ rw [sub_sub_cancel] exact K.le_orthogonal_orthogonal hwK instance HasOrthogonalProjection.map_linearIsometryEquiv [HasOrthogonalProjection K] {E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') : HasOrthogonalProjection (K.map (f.toLinearEquiv : E →ₗ[𝕜] E')) where exists_orthogonal v := by rcases HasOrthogonalProjection.exists_orthogonal (K := K) (f.symm v) with ⟨w, hwK, hw⟩ refine ⟨f w, Submodule.mem_map_of_mem hwK, Set.forall_mem_image.2 fun u hu ↦ ?_⟩ erw [← f.symm.inner_map_map, f.symm_apply_apply, map_sub, f.symm_apply_apply, hw u hu] instance HasOrthogonalProjection.map_linearIsometryEquiv' [HasOrthogonalProjection K] {E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') : HasOrthogonalProjection (K.map f.toLinearIsometry) := HasOrthogonalProjection.map_linearIsometryEquiv K f instance : HasOrthogonalProjection (⊤ : Submodule 𝕜 E) := ⟨fun v ↦ ⟨v, trivial, by simp⟩⟩ section orthogonalProjection variable [HasOrthogonalProjection K] /-- The orthogonal projection onto a complete subspace, 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 (v : E) := (HasOrthogonalProjection.exists_orthogonal (K := K) v).choose #align orthogonal_projection_fn orthogonalProjectionFn variable {K} /-- The unbundled orthogonal projection is 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 (v : E) : orthogonalProjectionFn K v ∈ K := (HasOrthogonalProjection.exists_orthogonal (K := K) v).choose_spec.left #align orthogonal_projection_fn_mem orthogonalProjectionFn_mem /-- The characterization of the unbundled orthogonal projection. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ theorem orthogonalProjectionFn_inner_eq_zero (v : E) : ∀ w ∈ K, ⟪v - orthogonalProjectionFn K v, w⟫ = 0 := (K.mem_orthogonal' _).1 (HasOrthogonalProjection.exists_orthogonal (K := K) v).choose_spec.right #align orthogonal_projection_fn_inner_eq_zero orthogonalProjectionFn_inner_eq_zero /-- The unbundled orthogonal projection is the unique point in `K` with the orthogonality property. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ theorem eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero {u v : E} (hvm : v ∈ K) (hvo : ∀ w ∈ K, ⟪u - v, w⟫ = 0) : orthogonalProjectionFn K u = v := by rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜] have hvs : orthogonalProjectionFn K u - v ∈ K := Submodule.sub_mem K (orthogonalProjectionFn_mem u) hvm have huo : ⟪u - orthogonalProjectionFn K u, orthogonalProjectionFn K u - v⟫ = 0 := orthogonalProjectionFn_inner_eq_zero u _ hvs have huv : ⟪u - v, orthogonalProjectionFn K u - v⟫ = 0 := hvo _ hvs have houv : ⟪u - v - (u - orthogonalProjectionFn K u), orthogonalProjectionFn K u - v⟫ = 0 := by rw [inner_sub_left, huo, huv, sub_zero] rwa [sub_sub_sub_cancel_left] at houv #align eq_orthogonal_projection_fn_of_mem_of_inner_eq_zero eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero variable (K) theorem orthogonalProjectionFn_norm_sq (v : E) : ‖v‖ * ‖v‖ = ‖v - orthogonalProjectionFn K v‖ * ‖v - orthogonalProjectionFn K v‖ + ‖orthogonalProjectionFn K v‖ * ‖orthogonalProjectionFn K v‖ := by set p := orthogonalProjectionFn K v have h' : ⟪v - p, p⟫ = 0 := orthogonalProjectionFn_inner_eq_zero _ _ (orthogonalProjectionFn_mem v) convert norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (v - p) p h' using 2 <;> simp #align orthogonal_projection_fn_norm_sq orthogonalProjectionFn_norm_sq /-- The orthogonal projection onto a complete subspace. -/ def orthogonalProjection : E →L[𝕜] K := LinearMap.mkContinuous { toFun := fun v => ⟨orthogonalProjectionFn K v, orthogonalProjectionFn_mem v⟩ map_add' := fun x y => by have hm : orthogonalProjectionFn K x + orthogonalProjectionFn K y ∈ K := Submodule.add_mem K (orthogonalProjectionFn_mem x) (orthogonalProjectionFn_mem y) have ho : ∀ w ∈ K, ⟪x + y - (orthogonalProjectionFn K x + orthogonalProjectionFn K y), w⟫ = 0 := by intro w hw rw [add_sub_add_comm, inner_add_left, orthogonalProjectionFn_inner_eq_zero _ w hw, orthogonalProjectionFn_inner_eq_zero _ w hw, add_zero] ext simp [eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hm ho] map_smul' := fun c x => by have hm : c • orthogonalProjectionFn K x ∈ K := Submodule.smul_mem K _ (orthogonalProjectionFn_mem x) have ho : ∀ w ∈ K, ⟪c • x - c • orthogonalProjectionFn K x, w⟫ = 0 := by intro w hw rw [← smul_sub, inner_smul_left, orthogonalProjectionFn_inner_eq_zero _ w hw, mul_zero] ext simp [eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hm ho] } 1 fun x => by simp only [one_mul, LinearMap.coe_mk] refine le_of_pow_le_pow_left two_ne_zero (norm_nonneg _) ?_ change ‖orthogonalProjectionFn K x‖ ^ 2 ≤ ‖x‖ ^ 2 nlinarith [orthogonalProjectionFn_norm_sq K x] #align orthogonal_projection orthogonalProjection variable {K} @[simp] theorem orthogonalProjectionFn_eq (v : E) : orthogonalProjectionFn K v = (orthogonalProjection K v : E) := rfl #align orthogonal_projection_fn_eq orthogonalProjectionFn_eq /-- The characterization of the orthogonal projection. -/ @[simp] theorem orthogonalProjection_inner_eq_zero (v : E) : ∀ w ∈ K, ⟪v - orthogonalProjection K v, w⟫ = 0 := orthogonalProjectionFn_inner_eq_zero v #align orthogonal_projection_inner_eq_zero orthogonalProjection_inner_eq_zero /-- The difference of `v` from its orthogonal projection onto `K` is in `Kᗮ`. -/ @[simp] theorem sub_orthogonalProjection_mem_orthogonal (v : E) : v - orthogonalProjection K v ∈ Kᗮ := by intro w hw rw [inner_eq_zero_symm] exact orthogonalProjection_inner_eq_zero _ _ hw #align sub_orthogonal_projection_mem_orthogonal sub_orthogonalProjection_mem_orthogonal /-- The orthogonal projection is the unique point in `K` with the orthogonality property. -/ theorem eq_orthogonalProjection_of_mem_of_inner_eq_zero {u v : E} (hvm : v ∈ K) (hvo : ∀ w ∈ K, ⟪u - v, w⟫ = 0) : (orthogonalProjection K u : E) = v := eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hvm hvo #align eq_orthogonal_projection_of_mem_of_inner_eq_zero eq_orthogonalProjection_of_mem_of_inner_eq_zero /-- A point in `K` with the orthogonality property (here characterized in terms of `Kᗮ`) must be the orthogonal projection. -/ theorem eq_orthogonalProjection_of_mem_orthogonal {u v : E} (hv : v ∈ K) (hvo : u - v ∈ Kᗮ) : (orthogonalProjection K u : E) = v := eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hv <| (Submodule.mem_orthogonal' _ _).1 hvo #align eq_orthogonal_projection_of_mem_orthogonal eq_orthogonalProjection_of_mem_orthogonal /-- A point in `K` with the orthogonality property (here characterized in terms of `Kᗮ`) must be the orthogonal projection. -/ theorem eq_orthogonalProjection_of_mem_orthogonal' {u v z : E} (hv : v ∈ K) (hz : z ∈ Kᗮ) (hu : u = v + z) : (orthogonalProjection K u : E) = v := eq_orthogonalProjection_of_mem_orthogonal hv (by simpa [hu] ) #align eq_orthogonal_projection_of_mem_orthogonal' eq_orthogonalProjection_of_mem_orthogonal' @[simp] theorem orthogonalProjection_orthogonal_val (u : E) : (orthogonalProjection Kᗮ u : E) = u - orthogonalProjection K u := eq_orthogonalProjection_of_mem_orthogonal' (sub_orthogonalProjection_mem_orthogonal _) (K.le_orthogonal_orthogonal (orthogonalProjection K u).2) <| by simp theorem orthogonalProjection_orthogonal (u : E) : orthogonalProjection Kᗮ u = ⟨u - orthogonalProjection K u, sub_orthogonalProjection_mem_orthogonal _⟩ := Subtype.eq <| orthogonalProjection_orthogonal_val _ /-- The orthogonal projection of `y` on `U` minimizes the distance `‖y - x‖` for `x ∈ U`. -/ theorem orthogonalProjection_minimal {U : Submodule 𝕜 E} [HasOrthogonalProjection U] (y : E) : ‖y - orthogonalProjection U y‖ = ⨅ x : U, ‖y - x‖ := by rw [norm_eq_iInf_iff_inner_eq_zero _ (Submodule.coe_mem _)] exact orthogonalProjection_inner_eq_zero _ #align orthogonal_projection_minimal orthogonalProjection_minimal /-- The orthogonal projections onto equal subspaces are coerced back to the same point in `E`. -/ theorem eq_orthogonalProjection_of_eq_submodule {K' : Submodule 𝕜 E} [HasOrthogonalProjection K'] (h : K = K') (u : E) : (orthogonalProjection K u : E) = (orthogonalProjection K' u : E) := by subst h; rfl #align eq_orthogonal_projection_of_eq_submodule eq_orthogonalProjection_of_eq_submodule /-- The orthogonal projection sends elements of `K` to themselves. -/ @[simp] theorem orthogonalProjection_mem_subspace_eq_self (v : K) : orthogonalProjection K v = v := by ext apply eq_orthogonalProjection_of_mem_of_inner_eq_zero <;> simp #align orthogonal_projection_mem_subspace_eq_self orthogonalProjection_mem_subspace_eq_self /-- A point equals its orthogonal projection if and only if it lies in the subspace. -/ theorem orthogonalProjection_eq_self_iff {v : E} : (orthogonalProjection K v : E) = v ↔ v ∈ K := by refine ⟨fun h => ?_, fun h => eq_orthogonalProjection_of_mem_of_inner_eq_zero h ?_⟩ · rw [← h] simp · simp #align orthogonal_projection_eq_self_iff orthogonalProjection_eq_self_iff @[simp] theorem orthogonalProjection_eq_zero_iff {v : E} : orthogonalProjection K v = 0 ↔ v ∈ Kᗮ := by refine ⟨fun h ↦ ?_, fun h ↦ Subtype.eq <| eq_orthogonalProjection_of_mem_orthogonal (zero_mem _) ?_⟩ · simpa [h] using sub_orthogonalProjection_mem_orthogonal (K := K) v · simpa @[simp] theorem ker_orthogonalProjection : LinearMap.ker (orthogonalProjection K) = Kᗮ := by ext; exact orthogonalProjection_eq_zero_iff theorem LinearIsometry.map_orthogonalProjection {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E →ₗᵢ[𝕜] E') (p : Submodule 𝕜 E) [HasOrthogonalProjection p] [HasOrthogonalProjection (p.map f.toLinearMap)] (x : E) : f (orthogonalProjection p x) = orthogonalProjection (p.map f.toLinearMap) (f x) := by refine (eq_orthogonalProjection_of_mem_of_inner_eq_zero ?_ fun y hy => ?_).symm · refine Submodule.apply_coe_mem_map _ _ rcases hy with ⟨x', hx', rfl : f x' = y⟩ rw [← f.map_sub, f.inner_map_map, orthogonalProjection_inner_eq_zero x x' hx'] #align linear_isometry.map_orthogonal_projection LinearIsometry.map_orthogonalProjection theorem LinearIsometry.map_orthogonalProjection' {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E →ₗᵢ[𝕜] E') (p : Submodule 𝕜 E) [HasOrthogonalProjection p] [HasOrthogonalProjection (p.map f)] (x : E) : f (orthogonalProjection p x) = orthogonalProjection (p.map f) (f x) := have : HasOrthogonalProjection (p.map f.toLinearMap) := ‹_› f.map_orthogonalProjection p x #align linear_isometry.map_orthogonal_projection' LinearIsometry.map_orthogonalProjection' /-- Orthogonal projection onto the `Submodule.map` of a subspace. -/ theorem orthogonalProjection_map_apply {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') (p : Submodule 𝕜 E) [HasOrthogonalProjection p] (x : E') : (orthogonalProjection (p.map (f.toLinearEquiv : E →ₗ[𝕜] E')) x : E') = f (orthogonalProjection p (f.symm x)) := by simpa only [f.coe_toLinearIsometry, f.apply_symm_apply] using (f.toLinearIsometry.map_orthogonalProjection' p (f.symm x)).symm #align orthogonal_projection_map_apply orthogonalProjection_map_apply /-- The orthogonal projection onto the trivial submodule is the zero map. -/ @[simp] theorem orthogonalProjection_bot : orthogonalProjection (⊥ : Submodule 𝕜 E) = 0 := by ext #align orthogonal_projection_bot orthogonalProjection_bot variable (K) /-- The orthogonal projection has norm `≤ 1`. -/ theorem orthogonalProjection_norm_le : ‖orthogonalProjection K‖ ≤ 1 := LinearMap.mkContinuous_norm_le _ (by norm_num) _ #align orthogonal_projection_norm_le orthogonalProjection_norm_le variable (𝕜) theorem smul_orthogonalProjection_singleton {v : E} (w : E) : ((‖v‖ ^ 2 : ℝ) : 𝕜) • (orthogonalProjection (𝕜 ∙ v) w : E) = ⟪v, w⟫ • v := by suffices ((orthogonalProjection (𝕜 ∙ v) (((‖v‖ : 𝕜) ^ 2) • w)) : E) = ⟪v, w⟫ • v by simpa using this apply eq_orthogonalProjection_of_mem_of_inner_eq_zero · rw [Submodule.mem_span_singleton] use ⟪v, w⟫ · rw [← Submodule.mem_orthogonal', Submodule.mem_orthogonal_singleton_iff_inner_left] simp [inner_sub_left, inner_smul_left, inner_self_eq_norm_sq_to_K, mul_comm] #align smul_orthogonal_projection_singleton smul_orthogonalProjection_singleton /-- Formula for orthogonal projection onto a single vector. -/ theorem orthogonalProjection_singleton {v : E} (w : E) : (orthogonalProjection (𝕜 ∙ v) w : E) = (⟪v, w⟫ / ((‖v‖ ^ 2 : ℝ) : 𝕜)) • v := by by_cases hv : v = 0 · rw [hv, eq_orthogonalProjection_of_eq_submodule (Submodule.span_zero_singleton 𝕜)] simp have hv' : ‖v‖ ≠ 0 := ne_of_gt (norm_pos_iff.mpr hv) have key : (((‖v‖ ^ 2 : ℝ) : 𝕜)⁻¹ * ((‖v‖ ^ 2 : ℝ) : 𝕜)) • ((orthogonalProjection (𝕜 ∙ v) w) : E) = (((‖v‖ ^ 2 : ℝ) : 𝕜)⁻¹ * ⟪v, w⟫) • v := by simp [mul_smul, smul_orthogonalProjection_singleton 𝕜 w, -ofReal_pow] convert key using 1 <;> field_simp [hv'] #align orthogonal_projection_singleton orthogonalProjection_singleton /-- Formula for orthogonal projection onto a single unit vector. -/ theorem orthogonalProjection_unit_singleton {v : E} (hv : ‖v‖ = 1) (w : E) : (orthogonalProjection (𝕜 ∙ v) w : E) = ⟪v, w⟫ • v := by rw [← smul_orthogonalProjection_singleton 𝕜 w] simp [hv] #align orthogonal_projection_unit_singleton orthogonalProjection_unit_singleton end orthogonalProjection section reflection variable [HasOrthogonalProjection K] -- Porting note: `bit0` is deprecated. /-- Auxiliary definition for `reflection`: the reflection as a linear equivalence. -/ def reflectionLinearEquiv : E ≃ₗ[𝕜] E := LinearEquiv.ofInvolutive (2 • (K.subtype.comp (orthogonalProjection K).toLinearMap) - LinearMap.id) fun x => by simp [two_smul] #align reflection_linear_equiv reflectionLinearEquivₓ /-- Reflection in a complete subspace of an inner product space. 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 a subspace, is a more general sense of the word that includes both those common cases. -/ def reflection : E ≃ₗᵢ[𝕜] E := { reflectionLinearEquiv K with norm_map' := by intro x dsimp only let w : K := orthogonalProjection K x let v := x - w have : ⟪v, w⟫ = 0 := orthogonalProjection_inner_eq_zero x w w.2 convert norm_sub_eq_norm_add this using 2 · rw [LinearEquiv.coe_mk, reflectionLinearEquiv, LinearEquiv.toFun_eq_coe, LinearEquiv.coe_ofInvolutive, LinearMap.sub_apply, LinearMap.id_apply, two_smul, LinearMap.add_apply, LinearMap.comp_apply, Submodule.subtype_apply, ContinuousLinearMap.coe_coe] dsimp [v] abel · simp only [v, add_sub_cancel, eq_self_iff_true] } #align reflection reflection variable {K} /-- The result of reflecting. -/ theorem reflection_apply (p : E) : reflection K p = 2 • (orthogonalProjection K p : E) - p := rfl #align reflection_apply reflection_applyₓ /-- Reflection is its own inverse. -/ @[simp] theorem reflection_symm : (reflection K).symm = reflection K := rfl #align reflection_symm reflection_symm /-- Reflection is its own inverse. -/ @[simp] theorem reflection_inv : (reflection K)⁻¹ = reflection K := rfl #align reflection_inv reflection_inv variable (K) /-- Reflecting twice in the same subspace. -/ @[simp] theorem reflection_reflection (p : E) : reflection K (reflection K p) = p := (reflection K).left_inv p #align reflection_reflection reflection_reflection /-- Reflection is involutive. -/ theorem reflection_involutive : Function.Involutive (reflection K) := reflection_reflection K #align reflection_involutive reflection_involutive /-- Reflection is involutive. -/ @[simp] theorem reflection_trans_reflection : (reflection K).trans (reflection K) = LinearIsometryEquiv.refl 𝕜 E := LinearIsometryEquiv.ext <| reflection_involutive K #align reflection_trans_reflection reflection_trans_reflection /-- Reflection is involutive. -/ @[simp] theorem reflection_mul_reflection : reflection K * reflection K = 1 := reflection_trans_reflection _ #align reflection_mul_reflection reflection_mul_reflection theorem reflection_orthogonal_apply (v : E) : reflection Kᗮ v = -reflection K v := by simp [reflection_apply]; abel theorem reflection_orthogonal : reflection Kᗮ = .trans (reflection K) (.neg _) := by ext; apply reflection_orthogonal_apply variable {K} theorem reflection_singleton_apply (u v : E) : reflection (𝕜 ∙ u) v = 2 • (⟪u, v⟫ / ((‖u‖ : 𝕜) ^ 2)) • u - v := by rw [reflection_apply, orthogonalProjection_singleton, ofReal_pow] /-- A point is its own reflection if and only if it is in the subspace. -/ theorem reflection_eq_self_iff (x : E) : reflection K x = x ↔ x ∈ K := by rw [← orthogonalProjection_eq_self_iff, reflection_apply, sub_eq_iff_eq_add', ← two_smul 𝕜, two_smul ℕ, ← two_smul 𝕜] refine (smul_right_injective E ?_).eq_iff exact two_ne_zero #align reflection_eq_self_iff reflection_eq_self_iff theorem reflection_mem_subspace_eq_self {x : E} (hx : x ∈ K) : reflection K x = x := (reflection_eq_self_iff x).mpr hx #align reflection_mem_subspace_eq_self reflection_mem_subspace_eq_self /-- Reflection in the `Submodule.map` of a subspace. -/ theorem reflection_map_apply {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') (K : Submodule 𝕜 E) [HasOrthogonalProjection K] (x : E') : reflection (K.map (f.toLinearEquiv : E →ₗ[𝕜] E')) x = f (reflection K (f.symm x)) := by simp [two_smul, reflection_apply, orthogonalProjection_map_apply f K x] #align reflection_map_apply reflection_map_apply /-- Reflection in the `Submodule.map` of a subspace. -/ theorem reflection_map {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') (K : Submodule 𝕜 E) [HasOrthogonalProjection K] : reflection (K.map (f.toLinearEquiv : E →ₗ[𝕜] E')) = f.symm.trans ((reflection K).trans f) := LinearIsometryEquiv.ext <| reflection_map_apply f K #align reflection_map reflection_map /-- Reflection through the trivial subspace {0} is just negation. -/ @[simp] theorem reflection_bot : reflection (⊥ : Submodule 𝕜 E) = LinearIsometryEquiv.neg 𝕜 := by ext; simp [reflection_apply] #align reflection_bot reflection_bot end reflection section Orthogonal /-- If `K₁` is complete and contained in `K₂`, `K₁` and `K₁ᗮ ⊓ K₂` span `K₂`. -/ theorem Submodule.sup_orthogonal_inf_of_completeSpace {K₁ K₂ : Submodule 𝕜 E} (h : K₁ ≤ K₂) [HasOrthogonalProjection K₁] : K₁ ⊔ K₁ᗮ ⊓ K₂ = K₂ := by ext x rw [Submodule.mem_sup] let v : K₁ := orthogonalProjection K₁ x have hvm : x - v ∈ K₁ᗮ := sub_orthogonalProjection_mem_orthogonal x constructor · rintro ⟨y, hy, z, hz, rfl⟩ exact K₂.add_mem (h hy) hz.2 · exact fun hx => ⟨v, v.prop, x - v, ⟨hvm, K₂.sub_mem hx (h v.prop)⟩, add_sub_cancel _ _⟩ #align submodule.sup_orthogonal_inf_of_complete_space Submodule.sup_orthogonal_inf_of_completeSpace variable {K} /-- If `K` is complete, `K` and `Kᗮ` span the whole space. -/ theorem Submodule.sup_orthogonal_of_completeSpace [HasOrthogonalProjection K] : K ⊔ Kᗮ = ⊤ := by convert Submodule.sup_orthogonal_inf_of_completeSpace (le_top : K ≤ ⊤) using 2 simp #align submodule.sup_orthogonal_of_complete_space Submodule.sup_orthogonal_of_completeSpace variable (K) /-- If `K` is complete, any `v` in `E` can be expressed as a sum of elements of `K` and `Kᗮ`. -/ theorem Submodule.exists_add_mem_mem_orthogonal [HasOrthogonalProjection K] (v : E) : ∃ y ∈ K, ∃ z ∈ Kᗮ, v = y + z := ⟨orthogonalProjection K v, Subtype.coe_prop _, v - orthogonalProjection K v, sub_orthogonalProjection_mem_orthogonal _, by simp⟩ #align submodule.exists_sum_mem_mem_orthogonal Submodule.exists_add_mem_mem_orthogonal /-- If `K` admits an orthogonal projection, then the orthogonal complement of its orthogonal complement is itself. -/ @[simp] theorem Submodule.orthogonal_orthogonal [HasOrthogonalProjection K] : Kᗮᗮ = K := by ext v constructor · obtain ⟨y, hy, z, hz, rfl⟩ := K.exists_add_mem_mem_orthogonal v intro hv have hz' : z = 0 := by have hyz : ⟪z, y⟫ = 0 := by simp [hz y hy, inner_eq_zero_symm] simpa [inner_add_right, hyz] using hv z hz simp [hy, hz'] · intro hv w hw rw [inner_eq_zero_symm] exact hw v hv #align submodule.orthogonal_orthogonal Submodule.orthogonal_orthogonal /-- In a Hilbert space, the orthogonal complement of the orthogonal complement of a subspace `K` is the topological closure of `K`. Note that the completeness assumption is necessary. Let `E` be the space `ℕ →₀ ℝ` with inner space structure inherited from `PiLp 2 (fun _ : ℕ ↦ ℝ)`. Let `K` be the subspace of sequences with the sum of all elements equal to zero. Then `Kᗮ = ⊥`, `Kᗮᗮ = ⊤`. -/ theorem Submodule.orthogonal_orthogonal_eq_closure [CompleteSpace E] : Kᗮᗮ = K.topologicalClosure := by refine le_antisymm ?_ ?_ · convert Submodule.orthogonal_orthogonal_monotone K.le_topologicalClosure using 1 rw [K.topologicalClosure.orthogonal_orthogonal] · exact K.topologicalClosure_minimal K.le_orthogonal_orthogonal Kᗮ.isClosed_orthogonal #align submodule.orthogonal_orthogonal_eq_closure Submodule.orthogonal_orthogonal_eq_closure variable {K} /-- If `K` admits an orthogonal projection, `K` and `Kᗮ` are complements of each other. -/ theorem Submodule.isCompl_orthogonal_of_completeSpace [HasOrthogonalProjection K] : IsCompl K Kᗮ := ⟨K.orthogonal_disjoint, codisjoint_iff.2 Submodule.sup_orthogonal_of_completeSpace⟩ #align submodule.is_compl_orthogonal_of_complete_space Submodule.isCompl_orthogonal_of_completeSpace @[simp] theorem Submodule.orthogonal_eq_bot_iff [HasOrthogonalProjection K] : Kᗮ = ⊥ ↔ K = ⊤ := by refine ⟨?_, fun h => by rw [h, Submodule.top_orthogonal_eq_bot]⟩ intro h have : K ⊔ Kᗮ = ⊤ := Submodule.sup_orthogonal_of_completeSpace rwa [h, sup_comm, bot_sup_eq] at this #align submodule.orthogonal_eq_bot_iff Submodule.orthogonal_eq_bot_iff /-- The orthogonal projection onto `K` of an element of `Kᗮ` is zero. -/ theorem orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero [HasOrthogonalProjection K] {v : E} (hv : v ∈ Kᗮ) : orthogonalProjection K v = 0 := by ext convert eq_orthogonalProjection_of_mem_orthogonal (K := K) _ _ <;> simp [hv] #align orthogonal_projection_mem_subspace_orthogonal_complement_eq_zero orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero /-- The projection into `U` from an orthogonal submodule `V` is the zero map. -/ theorem Submodule.IsOrtho.orthogonalProjection_comp_subtypeL {U V : Submodule 𝕜 E} [HasOrthogonalProjection U] (h : U ⟂ V) : orthogonalProjection U ∘L V.subtypeL = 0 := ContinuousLinearMap.ext fun v => orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero <| h.symm v.prop set_option linter.uppercaseLean3 false in #align submodule.is_ortho.orthogonal_projection_comp_subtypeL Submodule.IsOrtho.orthogonalProjection_comp_subtypeL /-- The projection into `U` from `V` is the zero map if and only if `U` and `V` are orthogonal. -/ theorem orthogonalProjection_comp_subtypeL_eq_zero_iff {U V : Submodule 𝕜 E} [HasOrthogonalProjection U] : orthogonalProjection U ∘L V.subtypeL = 0 ↔ U ⟂ V := ⟨fun h u hu v hv => by convert orthogonalProjection_inner_eq_zero v u hu using 2 have : orthogonalProjection U v = 0 := DFunLike.congr_fun h (⟨_, hv⟩ : V) rw [this, Submodule.coe_zero, sub_zero], Submodule.IsOrtho.orthogonalProjection_comp_subtypeL⟩ set_option linter.uppercaseLean3 false in #align orthogonal_projection_comp_subtypeL_eq_zero_iff orthogonalProjection_comp_subtypeL_eq_zero_iff theorem orthogonalProjection_eq_linear_proj [HasOrthogonalProjection K] (x : E) : orthogonalProjection K x = K.linearProjOfIsCompl _ Submodule.isCompl_orthogonal_of_completeSpace x := by have : IsCompl K Kᗮ := Submodule.isCompl_orthogonal_of_completeSpace conv_lhs => rw [← Submodule.linear_proj_add_linearProjOfIsCompl_eq_self this x] rw [map_add, orthogonalProjection_mem_subspace_eq_self, orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero (Submodule.coe_mem _), add_zero] #align orthogonal_projection_eq_linear_proj orthogonalProjection_eq_linear_proj theorem orthogonalProjection_coe_linearMap_eq_linearProj [HasOrthogonalProjection K] : (orthogonalProjection K : E →ₗ[𝕜] K) = K.linearProjOfIsCompl _ Submodule.isCompl_orthogonal_of_completeSpace := LinearMap.ext <| orthogonalProjection_eq_linear_proj #align orthogonal_projection_coe_linear_map_eq_linear_proj orthogonalProjection_coe_linearMap_eq_linearProj /-- The reflection in `K` of an element of `Kᗮ` is its negation. -/ theorem reflection_mem_subspace_orthogonalComplement_eq_neg [HasOrthogonalProjection K] {v : E} (hv : v ∈ Kᗮ) : reflection K v = -v := by simp [reflection_apply, orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero hv] #align reflection_mem_subspace_orthogonal_complement_eq_neg reflection_mem_subspace_orthogonalComplement_eq_neg /-- The orthogonal projection onto `Kᗮ` of an element of `K` is zero. -/ theorem orthogonalProjection_mem_subspace_orthogonal_precomplement_eq_zero [HasOrthogonalProjection Kᗮ] {v : E} (hv : v ∈ K) : orthogonalProjection Kᗮ v = 0 := orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero (K.le_orthogonal_orthogonal hv) #align orthogonal_projection_mem_subspace_orthogonal_precomplement_eq_zero orthogonalProjection_mem_subspace_orthogonal_precomplement_eq_zero /-- If `U ≤ V`, then projecting on `V` and then on `U` is the same as projecting on `U`. -/ theorem orthogonalProjection_orthogonalProjection_of_le {U V : Submodule 𝕜 E} [HasOrthogonalProjection U] [HasOrthogonalProjection V] (h : U ≤ V) (x : E) : orthogonalProjection U (orthogonalProjection V x) = orthogonalProjection U x := Eq.symm <| by simpa only [sub_eq_zero, map_sub] using orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero (Submodule.orthogonal_le h (sub_orthogonalProjection_mem_orthogonal x)) #align orthogonal_projection_orthogonal_projection_of_le orthogonalProjection_orthogonalProjection_of_le /-- Given a monotone family `U` of complete submodules of `E` and a fixed `x : E`, the orthogonal projection of `x` on `U i` tends to the orthogonal projection of `x` on `(⨆ i, U i).topologicalClosure` along `atTop`. -/ theorem orthogonalProjection_tendsto_closure_iSup [CompleteSpace E] {ι : Type*} [SemilatticeSup ι] (U : ι → Submodule 𝕜 E) [∀ i, CompleteSpace (U i)] (hU : Monotone U) (x : E) : Filter.Tendsto (fun i => (orthogonalProjection (U i) x : E)) atTop (𝓝 (orthogonalProjection (⨆ i, U i).topologicalClosure x : E)) := by cases isEmpty_or_nonempty ι · exact tendsto_of_isEmpty let y := (orthogonalProjection (⨆ i, U i).topologicalClosure x : E) have proj_x : ∀ i, orthogonalProjection (U i) x = orthogonalProjection (U i) y := fun i => (orthogonalProjection_orthogonalProjection_of_le ((le_iSup U i).trans (iSup U).le_topologicalClosure) _).symm suffices ∀ ε > 0, ∃ I, ∀ i ≥ I, ‖(orthogonalProjection (U i) y : E) - y‖ < ε by simpa only [proj_x, NormedAddCommGroup.tendsto_atTop] using this intro ε hε obtain ⟨a, ha, hay⟩ : ∃ a ∈ ⨆ i, U i, dist y a < ε := by have y_mem : y ∈ (⨆ i, U i).topologicalClosure := Submodule.coe_mem _ rw [← SetLike.mem_coe, Submodule.topologicalClosure_coe, Metric.mem_closure_iff] at y_mem exact y_mem ε hε rw [dist_eq_norm] at hay obtain ⟨I, hI⟩ : ∃ I, a ∈ U I := by rwa [Submodule.mem_iSup_of_directed _ hU.directed_le] at ha refine ⟨I, fun i (hi : I ≤ i) => ?_⟩ rw [norm_sub_rev, orthogonalProjection_minimal] refine lt_of_le_of_lt ?_ hay change _ ≤ ‖y - (⟨a, hU hi hI⟩ : U i)‖ exact ciInf_le ⟨0, Set.forall_mem_range.mpr fun _ => norm_nonneg _⟩ _ #align orthogonal_projection_tendsto_closure_supr orthogonalProjection_tendsto_closure_iSup /-- Given a monotone family `U` of complete submodules of `E` with dense span supremum, and a fixed `x : E`, the orthogonal projection of `x` on `U i` tends to `x` along `at_top`. -/ theorem orthogonalProjection_tendsto_self [CompleteSpace E] {ι : Type*} [SemilatticeSup ι] (U : ι → Submodule 𝕜 E) [∀ t, CompleteSpace (U t)] (hU : Monotone U) (x : E) (hU' : ⊤ ≤ (⨆ t, U t).topologicalClosure) : Filter.Tendsto (fun t => (orthogonalProjection (U t) x : E)) atTop (𝓝 x) := by rw [← eq_top_iff] at hU' convert orthogonalProjection_tendsto_closure_iSup U hU x rw [orthogonalProjection_eq_self_iff.mpr _] rw [hU'] trivial #align orthogonal_projection_tendsto_self orthogonalProjection_tendsto_self /-- The orthogonal complement satisfies `Kᗮᗮᗮ = Kᗮ`. -/ theorem Submodule.triorthogonal_eq_orthogonal [CompleteSpace E] : Kᗮᗮᗮ = Kᗮ := by rw [Kᗮ.orthogonal_orthogonal_eq_closure] exact K.isClosed_orthogonal.submodule_topologicalClosure_eq #align submodule.triorthogonal_eq_orthogonal Submodule.triorthogonal_eq_orthogonal /-- The closure of `K` is the full space iff `Kᗮ` is trivial. -/ theorem Submodule.topologicalClosure_eq_top_iff [CompleteSpace E] : K.topologicalClosure = ⊤ ↔ Kᗮ = ⊥ := by rw [← Submodule.orthogonal_orthogonal_eq_closure] constructor <;> intro h · rw [← Submodule.triorthogonal_eq_orthogonal, h, Submodule.top_orthogonal_eq_bot] · rw [h, Submodule.bot_orthogonal_eq_top] #align submodule.topological_closure_eq_top_iff Submodule.topologicalClosure_eq_top_iff namespace Dense /- Porting note: unneeded assumption `[CompleteSpace E]` was removed from all theorems in this section. TODO: Move to another file? -/ open Submodule variable {x y : E} theorem eq_zero_of_inner_left (hK : Dense (K : Set E)) (h : ∀ v : K, ⟪x, v⟫ = 0) : x = 0 := by have : (⟪x, ·⟫) = 0 := (continuous_const.inner continuous_id).ext_on hK continuous_const (Subtype.forall.1 h) simpa using congr_fun this x #align dense.eq_zero_of_inner_left Dense.eq_zero_of_inner_left theorem eq_zero_of_mem_orthogonal (hK : Dense (K : Set E)) (h : x ∈ Kᗮ) : x = 0 := eq_zero_of_inner_left hK fun v ↦ (mem_orthogonal' _ _).1 h _ v.2 #align dense.eq_zero_of_mem_orthogonal Dense.eq_zero_of_mem_orthogonal /-- If `S` is dense and `x - y ∈ Kᗮ`, then `x = y`. -/ theorem eq_of_sub_mem_orthogonal (hK : Dense (K : Set E)) (h : x - y ∈ Kᗮ) : x = y := sub_eq_zero.1 <| eq_zero_of_mem_orthogonal hK h #align dense.eq_of_sub_mem_orthogonal Dense.eq_of_sub_mem_orthogonal theorem eq_of_inner_left (hK : Dense (K : Set E)) (h : ∀ v : K, ⟪x, v⟫ = ⟪y, v⟫) : x = y := hK.eq_of_sub_mem_orthogonal (Submodule.sub_mem_orthogonal_of_inner_left h) #align dense.eq_of_inner_left Dense.eq_of_inner_left theorem eq_of_inner_right (hK : Dense (K : Set E)) (h : ∀ v : K, ⟪(v : E), x⟫ = ⟪(v : E), y⟫) : x = y := hK.eq_of_sub_mem_orthogonal (Submodule.sub_mem_orthogonal_of_inner_right h) #align dense.eq_of_inner_right Dense.eq_of_inner_right theorem eq_zero_of_inner_right (hK : Dense (K : Set E)) (h : ∀ v : K, ⟪(v : E), x⟫ = 0) : x = 0 := hK.eq_of_inner_right fun v => by rw [inner_zero_right, h v] #align dense.eq_zero_of_inner_right Dense.eq_zero_of_inner_right end Dense /-- The reflection in `Kᗮ` of an element of `K` is its negation. -/ theorem reflection_mem_subspace_orthogonal_precomplement_eq_neg [HasOrthogonalProjection K] {v : E} (hv : v ∈ K) : reflection Kᗮ v = -v := reflection_mem_subspace_orthogonalComplement_eq_neg (K.le_orthogonal_orthogonal hv) #align reflection_mem_subspace_orthogonal_precomplement_eq_neg reflection_mem_subspace_orthogonal_precomplement_eq_neg /-- The orthogonal projection onto `(𝕜 ∙ v)ᗮ` of `v` is zero. -/ theorem orthogonalProjection_orthogonalComplement_singleton_eq_zero (v : E) : orthogonalProjection (𝕜 ∙ v)ᗮ v = 0 := orthogonalProjection_mem_subspace_orthogonal_precomplement_eq_zero (Submodule.mem_span_singleton_self v) #align orthogonal_projection_orthogonal_complement_singleton_eq_zero orthogonalProjection_orthogonalComplement_singleton_eq_zero /-- The reflection in `(𝕜 ∙ v)ᗮ` of `v` is `-v`. -/ theorem reflection_orthogonalComplement_singleton_eq_neg (v : E) : reflection (𝕜 ∙ v)ᗮ v = -v := reflection_mem_subspace_orthogonal_precomplement_eq_neg (Submodule.mem_span_singleton_self v) #align reflection_orthogonal_complement_singleton_eq_neg reflection_orthogonalComplement_singleton_eq_neg theorem reflection_sub {v w : F} (h : ‖v‖ = ‖w‖) : reflection (ℝ ∙ (v - w))ᗮ v = w := by set R : F ≃ₗᵢ[ℝ] F := reflection (ℝ ∙ v - w)ᗮ suffices R v + R v = w + w by apply smul_right_injective F (by norm_num : (2 : ℝ) ≠ 0) simpa [two_smul] using this have h₁ : R (v - w) = -(v - w) := reflection_orthogonalComplement_singleton_eq_neg (v - w) have h₂ : R (v + w) = v + w := by apply reflection_mem_subspace_eq_self rw [Submodule.mem_orthogonal_singleton_iff_inner_left] rw [real_inner_add_sub_eq_zero_iff] exact h convert congr_arg₂ (· + ·) h₂ h₁ using 1 · simp · abel #align reflection_sub reflection_sub variable (K) -- Porting note: relax assumptions, swap LHS with RHS /-- If the orthogonal projection to `K` is well-defined, then a vector splits as the sum of its orthogonal projections onto a complete submodule `K` and onto the orthogonal complement of `K`. -/ theorem orthogonalProjection_add_orthogonalProjection_orthogonal [HasOrthogonalProjection K] (w : E) : (orthogonalProjection K w : E) + (orthogonalProjection Kᗮ w : E) = w := by simp #align eq_sum_orthogonal_projection_self_orthogonal_complement orthogonalProjection_add_orthogonalProjection_orthogonalₓ /-- The Pythagorean theorem, for an orthogonal projection. -/ theorem norm_sq_eq_add_norm_sq_projection (x : E) (S : Submodule 𝕜 E) [HasOrthogonalProjection S] : ‖x‖ ^ 2 = ‖orthogonalProjection S x‖ ^ 2 + ‖orthogonalProjection Sᗮ x‖ ^ 2 := calc ‖x‖ ^ 2 = ‖(orthogonalProjection S x : E) + orthogonalProjection Sᗮ x‖ ^ 2 := by rw [orthogonalProjection_add_orthogonalProjection_orthogonal] _ = ‖orthogonalProjection S x‖ ^ 2 + ‖orthogonalProjection Sᗮ x‖ ^ 2 := by simp only [sq] exact norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero _ _ <| (S.mem_orthogonal _).1 (orthogonalProjection Sᗮ x).2 _ (orthogonalProjection S x).2 #align norm_sq_eq_add_norm_sq_projection norm_sq_eq_add_norm_sq_projection /-- In a complete space `E`, the projection maps onto a complete subspace `K` and its orthogonal complement sum to the identity. -/ theorem id_eq_sum_orthogonalProjection_self_orthogonalComplement [HasOrthogonalProjection K] : ContinuousLinearMap.id 𝕜 E = K.subtypeL.comp (orthogonalProjection K) + Kᗮ.subtypeL.comp (orthogonalProjection Kᗮ) := by ext w exact (orthogonalProjection_add_orthogonalProjection_orthogonal K w).symm #align id_eq_sum_orthogonal_projection_self_orthogonal_complement id_eq_sum_orthogonalProjection_self_orthogonalComplement -- Porting note: The priority should be higher than `Submodule.coe_inner`. @[simp high] theorem inner_orthogonalProjection_eq_of_mem_right [HasOrthogonalProjection K] (u : K) (v : E) : ⟪orthogonalProjection K v, u⟫ = ⟪v, u⟫ := calc ⟪orthogonalProjection K v, u⟫ = ⟪(orthogonalProjection K v : E), u⟫ := K.coe_inner _ _ _ = ⟪(orthogonalProjection K v : E), u⟫ + ⟪v - orthogonalProjection K v, u⟫ := by rw [orthogonalProjection_inner_eq_zero _ _ (Submodule.coe_mem _), add_zero] _ = ⟪v, u⟫ := by rw [← inner_add_left, add_sub_cancel] #align inner_orthogonal_projection_eq_of_mem_right inner_orthogonalProjection_eq_of_mem_right -- Porting note: The priority should be higher than `Submodule.coe_inner`. @[simp high]
Mathlib/Analysis/InnerProductSpace/Projection.lean
1,092
1,094
theorem inner_orthogonalProjection_eq_of_mem_left [HasOrthogonalProjection K] (u : K) (v : E) : ⟪u, orthogonalProjection K v⟫ = ⟪(u : E), v⟫ := by
rw [← inner_conj_symm, ← inner_conj_symm (u : E), inner_orthogonalProjection_eq_of_mem_right]
/- Copyright (c) 2023 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp #align_import analysis.calculus.deriv.inv from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # Derivatives of `x ↦ x⁻¹` and `f x / g x` In this file we prove `(x⁻¹)' = -1 / x ^ 2`, `((f x)⁻¹)' = -f' x / (f x) ^ 2`, and `(f x / g x)' = (f' x * g x - f x * g' x) / (g x) ^ 2` for different notions of derivative. For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of `Analysis/Calculus/Deriv/Basic`. ## Keywords derivative -/ universe u v w open scoped Classical open Topology Filter ENNReal open Filter Asymptotics Set open ContinuousLinearMap (smulRight smulRight_one_eq_iff) variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {f f₀ f₁ g : 𝕜 → F} variable {f' f₀' f₁' g' : F} variable {x : 𝕜} variable {s t : Set 𝕜} variable {L : Filter 𝕜} section Inverse /-! ### Derivative of `x ↦ x⁻¹` -/ theorem hasStrictDerivAt_inv (hx : x ≠ 0) : HasStrictDerivAt Inv.inv (-(x ^ 2)⁻¹) x := by suffices (fun p : 𝕜 × 𝕜 => (p.1 - p.2) * ((x * x)⁻¹ - (p.1 * p.2)⁻¹)) =o[𝓝 (x, x)] fun p => (p.1 - p.2) * 1 by refine this.congr' ?_ (eventually_of_forall fun _ => mul_one _) refine Eventually.mono ((isOpen_ne.prod isOpen_ne).mem_nhds ⟨hx, hx⟩) ?_ rintro ⟨y, z⟩ ⟨hy, hz⟩ simp only [mem_setOf_eq] at hy hz -- hy : y ≠ 0, hz : z ≠ 0 field_simp [hx, hy, hz] ring refine (isBigO_refl (fun p : 𝕜 × 𝕜 => p.1 - p.2) _).mul_isLittleO ((isLittleO_one_iff 𝕜).2 ?_) rw [← sub_self (x * x)⁻¹] exact tendsto_const_nhds.sub ((continuous_mul.tendsto (x, x)).inv₀ <| mul_ne_zero hx hx) #align has_strict_deriv_at_inv hasStrictDerivAt_inv theorem hasDerivAt_inv (x_ne_zero : x ≠ 0) : HasDerivAt (fun y => y⁻¹) (-(x ^ 2)⁻¹) x := (hasStrictDerivAt_inv x_ne_zero).hasDerivAt #align has_deriv_at_inv hasDerivAt_inv theorem hasDerivWithinAt_inv (x_ne_zero : x ≠ 0) (s : Set 𝕜) : HasDerivWithinAt (fun x => x⁻¹) (-(x ^ 2)⁻¹) s x := (hasDerivAt_inv x_ne_zero).hasDerivWithinAt #align has_deriv_within_at_inv hasDerivWithinAt_inv theorem differentiableAt_inv : DifferentiableAt 𝕜 (fun x => x⁻¹) x ↔ x ≠ 0 := ⟨fun H => NormedField.continuousAt_inv.1 H.continuousAt, fun H => (hasDerivAt_inv H).differentiableAt⟩ #align differentiable_at_inv differentiableAt_inv theorem differentiableWithinAt_inv (x_ne_zero : x ≠ 0) : DifferentiableWithinAt 𝕜 (fun x => x⁻¹) s x := (differentiableAt_inv.2 x_ne_zero).differentiableWithinAt #align differentiable_within_at_inv differentiableWithinAt_inv theorem differentiableOn_inv : DifferentiableOn 𝕜 (fun x : 𝕜 => x⁻¹) { x | x ≠ 0 } := fun _x hx => differentiableWithinAt_inv hx #align differentiable_on_inv differentiableOn_inv theorem deriv_inv : deriv (fun x => x⁻¹) x = -(x ^ 2)⁻¹ := by rcases eq_or_ne x 0 with (rfl | hne) · simp [deriv_zero_of_not_differentiableAt (mt differentiableAt_inv.1 (not_not.2 rfl))] · exact (hasDerivAt_inv hne).deriv #align deriv_inv deriv_inv @[simp] theorem deriv_inv' : (deriv fun x : 𝕜 => x⁻¹) = fun x => -(x ^ 2)⁻¹ := funext fun _ => deriv_inv #align deriv_inv' deriv_inv'
Mathlib/Analysis/Calculus/Deriv/Inv.lean
98
101
theorem derivWithin_inv (x_ne_zero : x ≠ 0) (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin (fun x => x⁻¹) s x = -(x ^ 2)⁻¹ := by
rw [DifferentiableAt.derivWithin (differentiableAt_inv.2 x_ne_zero) hxs] exact deriv_inv
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.Algebra.Bilinear import Mathlib.Algebra.Algebra.Equiv import Mathlib.Algebra.Algebra.Opposite import Mathlib.Algebra.GroupWithZero.NonZeroDivisors import Mathlib.Algebra.Module.Opposites import Mathlib.Algebra.Module.Submodule.Bilinear import Mathlib.Algebra.Module.Submodule.Pointwise import Mathlib.Algebra.Order.Kleene import Mathlib.Data.Finset.Pointwise import Mathlib.Data.Set.Pointwise.BigOperators import Mathlib.Data.Set.Semiring import Mathlib.GroupTheory.GroupAction.SubMulAction.Pointwise import Mathlib.LinearAlgebra.Basic #align_import algebra.algebra.operations from "leanprover-community/mathlib"@"27b54c47c3137250a521aa64e9f1db90be5f6a26" /-! # Multiplication and division of submodules of an algebra. An interface for multiplication and division of sub-R-modules of an R-algebra A is developed. ## Main definitions Let `R` be a commutative ring (or semiring) and let `A` be an `R`-algebra. * `1 : Submodule R A` : the R-submodule R of the R-algebra A * `Mul (Submodule R A)` : multiplication of two sub-R-modules M and N of A is defined to be the smallest submodule containing all the products `m * n`. * `Div (Submodule R A)` : `I / J` is defined to be the submodule consisting of all `a : A` such that `a • J ⊆ I` It is proved that `Submodule R A` is a semiring, and also an algebra over `Set A`. Additionally, in the `Pointwise` locale we promote `Submodule.pointwiseDistribMulAction` to a `MulSemiringAction` as `Submodule.pointwiseMulSemiringAction`. ## Tags multiplication of submodules, division of submodules, submodule semiring -/ universe uι u v open Algebra Set MulOpposite open Pointwise namespace SubMulAction variable {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A] theorem algebraMap_mem (r : R) : algebraMap R A r ∈ (1 : SubMulAction R A) := ⟨r, (algebraMap_eq_smul_one r).symm⟩ #align sub_mul_action.algebra_map_mem SubMulAction.algebraMap_mem theorem mem_one' {x : A} : x ∈ (1 : SubMulAction R A) ↔ ∃ y, algebraMap R A y = x := exists_congr fun r => by rw [algebraMap_eq_smul_one] #align sub_mul_action.mem_one' SubMulAction.mem_one' end SubMulAction namespace Submodule variable {ι : Sort uι} variable {R : Type u} [CommSemiring R] section Ring variable {A : Type v} [Semiring A] [Algebra R A] variable (S T : Set A) {M N P Q : Submodule R A} {m n : A} /-- `1 : Submodule R A` is the submodule R of A. -/ instance one : One (Submodule R A) := -- Porting note: `f.range` notation doesn't work ⟨LinearMap.range (Algebra.linearMap R A)⟩ #align submodule.has_one Submodule.one theorem one_eq_range : (1 : Submodule R A) = LinearMap.range (Algebra.linearMap R A) := rfl #align submodule.one_eq_range Submodule.one_eq_range theorem le_one_toAddSubmonoid : 1 ≤ (1 : Submodule R A).toAddSubmonoid := by rintro x ⟨n, rfl⟩ exact ⟨n, map_natCast (algebraMap R A) n⟩ #align submodule.le_one_to_add_submonoid Submodule.le_one_toAddSubmonoid theorem algebraMap_mem (r : R) : algebraMap R A r ∈ (1 : Submodule R A) := LinearMap.mem_range_self (Algebra.linearMap R A) _ #align submodule.algebra_map_mem Submodule.algebraMap_mem @[simp] theorem mem_one {x : A} : x ∈ (1 : Submodule R A) ↔ ∃ y, algebraMap R A y = x := Iff.rfl #align submodule.mem_one Submodule.mem_one @[simp] theorem toSubMulAction_one : (1 : Submodule R A).toSubMulAction = 1 := SetLike.ext fun _ => mem_one.trans SubMulAction.mem_one'.symm #align submodule.to_sub_mul_action_one Submodule.toSubMulAction_one theorem one_eq_span : (1 : Submodule R A) = R ∙ 1 := by apply Submodule.ext intro a simp only [mem_one, mem_span_singleton, Algebra.smul_def, mul_one] #align submodule.one_eq_span Submodule.one_eq_span theorem one_eq_span_one_set : (1 : Submodule R A) = span R 1 := one_eq_span #align submodule.one_eq_span_one_set Submodule.one_eq_span_one_set theorem one_le : (1 : Submodule R A) ≤ P ↔ (1 : A) ∈ P := by -- Porting note: simpa no longer closes refl goals, so added `SetLike.mem_coe` simp only [one_eq_span, span_le, Set.singleton_subset_iff, SetLike.mem_coe] #align submodule.one_le Submodule.one_le protected theorem map_one {A'} [Semiring A'] [Algebra R A'] (f : A →ₐ[R] A') : map f.toLinearMap (1 : Submodule R A) = 1 := by ext simp #align submodule.map_one Submodule.map_one @[simp] theorem map_op_one : map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) (1 : Submodule R A) = 1 := by ext x induction x using MulOpposite.rec' simp #align submodule.map_op_one Submodule.map_op_one @[simp] theorem comap_op_one : comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) (1 : Submodule R Aᵐᵒᵖ) = 1 := by ext simp #align submodule.comap_op_one Submodule.comap_op_one @[simp] theorem map_unop_one : map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) (1 : Submodule R Aᵐᵒᵖ) = 1 := by rw [← comap_equiv_eq_map_symm, comap_op_one] #align submodule.map_unop_one Submodule.map_unop_one @[simp] theorem comap_unop_one : comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) (1 : Submodule R A) = 1 := by rw [← map_equiv_eq_comap_symm, map_op_one] #align submodule.comap_unop_one Submodule.comap_unop_one /-- Multiplication of sub-R-modules of an R-algebra A. The submodule `M * N` is the smallest R-submodule of `A` containing the elements `m * n` for `m ∈ M` and `n ∈ N`. -/ instance mul : Mul (Submodule R A) := ⟨Submodule.map₂ <| LinearMap.mul R A⟩ #align submodule.has_mul Submodule.mul theorem mul_mem_mul (hm : m ∈ M) (hn : n ∈ N) : m * n ∈ M * N := apply_mem_map₂ _ hm hn #align submodule.mul_mem_mul Submodule.mul_mem_mul theorem mul_le : M * N ≤ P ↔ ∀ m ∈ M, ∀ n ∈ N, m * n ∈ P := map₂_le #align submodule.mul_le Submodule.mul_le theorem mul_toAddSubmonoid (M N : Submodule R A) : (M * N).toAddSubmonoid = M.toAddSubmonoid * N.toAddSubmonoid := by dsimp [HMul.hMul, Mul.mul] -- Porting note: added `hMul` rw [map₂, iSup_toAddSubmonoid] rfl #align submodule.mul_to_add_submonoid Submodule.mul_toAddSubmonoid @[elab_as_elim] protected theorem mul_induction_on {C : A → Prop} {r : A} (hr : r ∈ M * N) (hm : ∀ m ∈ M, ∀ n ∈ N, C (m * n)) (ha : ∀ x y, C x → C y → C (x + y)) : C r := by rw [← mem_toAddSubmonoid, mul_toAddSubmonoid] at hr exact AddSubmonoid.mul_induction_on hr hm ha #align submodule.mul_induction_on Submodule.mul_induction_on /-- A dependent version of `mul_induction_on`. -/ @[elab_as_elim] protected theorem mul_induction_on' {C : ∀ r, r ∈ M * N → Prop} (mem_mul_mem : ∀ m (hm : m ∈ M) n (hn : n ∈ N), C (m * n) (mul_mem_mul hm hn)) (add : ∀ x hx y hy, C x hx → C y hy → C (x + y) (add_mem hx hy)) {r : A} (hr : r ∈ M * N) : C r hr := by refine Exists.elim ?_ fun (hr : r ∈ M * N) (hc : C r hr) => hc exact Submodule.mul_induction_on hr (fun x hx y hy => ⟨_, mem_mul_mem _ hx _ hy⟩) fun x y ⟨_, hx⟩ ⟨_, hy⟩ => ⟨_, add _ _ _ _ hx hy⟩ #align submodule.mul_induction_on' Submodule.mul_induction_on' variable (R) theorem span_mul_span : span R S * span R T = span R (S * T) := map₂_span_span _ _ _ _ #align submodule.span_mul_span Submodule.span_mul_span variable {R} variable (M N P Q) @[simp] theorem mul_bot : M * ⊥ = ⊥ := map₂_bot_right _ _ #align submodule.mul_bot Submodule.mul_bot @[simp] theorem bot_mul : ⊥ * M = ⊥ := map₂_bot_left _ _ #align submodule.bot_mul Submodule.bot_mul -- @[simp] -- Porting note (#10618): simp can prove this once we have a monoid structure protected theorem one_mul : (1 : Submodule R A) * M = M := by conv_lhs => rw [one_eq_span, ← span_eq M] erw [span_mul_span, one_mul, span_eq] #align submodule.one_mul Submodule.one_mul -- @[simp] -- Porting note (#10618): simp can prove this once we have a monoid structure protected theorem mul_one : M * 1 = M := by conv_lhs => rw [one_eq_span, ← span_eq M] erw [span_mul_span, mul_one, span_eq] #align submodule.mul_one Submodule.mul_one variable {M N P Q} @[mono] theorem mul_le_mul (hmp : M ≤ P) (hnq : N ≤ Q) : M * N ≤ P * Q := map₂_le_map₂ hmp hnq #align submodule.mul_le_mul Submodule.mul_le_mul theorem mul_le_mul_left (h : M ≤ N) : M * P ≤ N * P := map₂_le_map₂_left h #align submodule.mul_le_mul_left Submodule.mul_le_mul_left theorem mul_le_mul_right (h : N ≤ P) : M * N ≤ M * P := map₂_le_map₂_right h #align submodule.mul_le_mul_right Submodule.mul_le_mul_right variable (M N P) theorem mul_sup : M * (N ⊔ P) = M * N ⊔ M * P := map₂_sup_right _ _ _ _ #align submodule.mul_sup Submodule.mul_sup theorem sup_mul : (M ⊔ N) * P = M * P ⊔ N * P := map₂_sup_left _ _ _ _ #align submodule.sup_mul Submodule.sup_mul theorem mul_subset_mul : (↑M : Set A) * (↑N : Set A) ⊆ (↑(M * N) : Set A) := image2_subset_map₂ (Algebra.lmul R A).toLinearMap M N #align submodule.mul_subset_mul Submodule.mul_subset_mul protected theorem map_mul {A'} [Semiring A'] [Algebra R A'] (f : A →ₐ[R] A') : map f.toLinearMap (M * N) = map f.toLinearMap M * map f.toLinearMap N := calc map f.toLinearMap (M * N) = ⨆ i : M, (N.map (LinearMap.mul R A i)).map f.toLinearMap := map_iSup _ _ _ = map f.toLinearMap M * map f.toLinearMap N := by apply congr_arg sSup ext S constructor <;> rintro ⟨y, hy⟩ · use ⟨f y, mem_map.mpr ⟨y.1, y.2, rfl⟩⟩ -- Porting note: added `⟨⟩` refine Eq.trans ?_ hy ext simp · obtain ⟨y', hy', fy_eq⟩ := mem_map.mp y.2 use ⟨y', hy'⟩ -- Porting note: added `⟨⟩` refine Eq.trans ?_ hy rw [f.toLinearMap_apply] at fy_eq ext simp [fy_eq] #align submodule.map_mul Submodule.map_mul theorem map_op_mul : map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) (M * N) = map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) N * map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) M := by apply le_antisymm · simp_rw [map_le_iff_le_comap] refine mul_le.2 fun m hm n hn => ?_ rw [mem_comap, map_equiv_eq_comap_symm, map_equiv_eq_comap_symm] show op n * op m ∈ _ exact mul_mem_mul hn hm · refine mul_le.2 (MulOpposite.rec' fun m hm => MulOpposite.rec' fun n hn => ?_) rw [Submodule.mem_map_equiv] at hm hn ⊢ exact mul_mem_mul hn hm #align submodule.map_op_mul Submodule.map_op_mul theorem comap_unop_mul : comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) (M * N) = comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) N * comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) M := by simp_rw [← map_equiv_eq_comap_symm, map_op_mul] #align submodule.comap_unop_mul Submodule.comap_unop_mul theorem map_unop_mul (M N : Submodule R Aᵐᵒᵖ) : map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) (M * N) = map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) N * map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) M := have : Function.Injective (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) := LinearEquiv.injective _ map_injective_of_injective this <| by rw [← map_comp, map_op_mul, ← map_comp, ← map_comp, LinearEquiv.comp_coe, LinearEquiv.symm_trans_self, LinearEquiv.refl_toLinearMap, map_id, map_id, map_id] #align submodule.map_unop_mul Submodule.map_unop_mul
Mathlib/Algebra/Algebra/Operations.lean
310
314
theorem comap_op_mul (M N : Submodule R Aᵐᵒᵖ) : comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) (M * N) = comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) N * comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) M := by
simp_rw [comap_equiv_eq_map_symm, map_unop_mul]
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.FieldTheory.Normal import Mathlib.FieldTheory.Perfect import Mathlib.RingTheory.Localization.Integral #align_import field_theory.is_alg_closed.basic from "leanprover-community/mathlib"@"00f91228655eecdcd3ac97a7fd8dbcb139fe990a" /-! # Algebraically Closed Field In this file we define the typeclass for algebraically closed fields and algebraic closures, and prove some of their properties. ## Main Definitions - `IsAlgClosed k` is the typeclass saying `k` is an algebraically closed field, i.e. every polynomial in `k` splits. - `IsAlgClosure R K` is the typeclass saying `K` is an algebraic closure of `R`, where `R` is a commutative ring. This means that the map from `R` to `K` is injective, and `K` is algebraically closed and algebraic over `R` - `IsAlgClosed.lift` is a map from an algebraic extension `L` of `R`, into any algebraically closed extension of `R`. - `IsAlgClosure.equiv` is a proof that any two algebraic closures of the same field are isomorphic. ## Tags algebraic closure, algebraically closed ## TODO - Prove that if `K / k` is algebraic, and any monic irreducible polynomial over `k` has a root in `K`, then `K` is algebraically closed (in fact an algebraic closure of `k`). Reference: <https://kconrad.math.uconn.edu/blurbs/galoistheory/algclosure.pdf>, Theorem 2 -/ universe u v w open scoped Classical Polynomial open Polynomial variable (k : Type u) [Field k] /-- Typeclass for algebraically closed fields. To show `Polynomial.Splits p f` for an arbitrary ring homomorphism `f`, see `IsAlgClosed.splits_codomain` and `IsAlgClosed.splits_domain`. -/ class IsAlgClosed : Prop where splits : ∀ p : k[X], p.Splits <| RingHom.id k #align is_alg_closed IsAlgClosed /-- Every polynomial splits in the field extension `f : K →+* k` if `k` is algebraically closed. See also `IsAlgClosed.splits_domain` for the case where `K` is algebraically closed. -/
Mathlib/FieldTheory/IsAlgClosed/Basic.lean
68
69
theorem IsAlgClosed.splits_codomain {k K : Type*} [Field k] [IsAlgClosed k] [Field K] {f : K →+* k} (p : K[X]) : p.Splits f := by
convert IsAlgClosed.splits (p.map f); simp [splits_map_iff]
/- Copyright (c) 2021 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Data.Finset.Sort import Mathlib.Data.List.FinRange import Mathlib.Data.Prod.Lex import Mathlib.GroupTheory.Perm.Basic import Mathlib.Order.Interval.Finset.Fin #align_import data.fin.tuple.sort from "leanprover-community/mathlib"@"8631e2d5ea77f6c13054d9151d82b83069680cb1" /-! # Sorting tuples by their values Given an `n`-tuple `f : Fin n → α` where `α` is ordered, we may want to turn it into a sorted `n`-tuple. This file provides an API for doing so, with the sorted `n`-tuple given by `f ∘ Tuple.sort f`. ## Main declarations * `Tuple.sort`: given `f : Fin n → α`, produces a permutation on `Fin n` * `Tuple.monotone_sort`: `f ∘ Tuple.sort f` is `Monotone` -/ namespace Tuple variable {n : ℕ} variable {α : Type*} [LinearOrder α] /-- `graph f` produces the finset of pairs `(f i, i)` equipped with the lexicographic order. -/ def graph (f : Fin n → α) : Finset (α ×ₗ Fin n) := Finset.univ.image fun i => (f i, i) #align tuple.graph Tuple.graph /-- Given `p : α ×ₗ (Fin n) := (f i, i)` with `p ∈ graph f`, `graph.proj p` is defined to be `f i`. -/ def graph.proj {f : Fin n → α} : graph f → α := fun p => p.1.1 #align tuple.graph.proj Tuple.graph.proj @[simp]
Mathlib/Data/Fin/Tuple/Sort.lean
50
57
theorem graph.card (f : Fin n → α) : (graph f).card = n := by
rw [graph, Finset.card_image_of_injective] · exact Finset.card_fin _ · intro _ _ -- porting note (#10745): was `simp` dsimp only rw [Prod.ext_iff] simp
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker, Johan Commelin -/ import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.Polynomial.BigOperators import Mathlib.Algebra.Polynomial.Degree.Lemmas import Mathlib.Algebra.Polynomial.Div #align_import data.polynomial.ring_division from "leanprover-community/mathlib"@"8efcf8022aac8e01df8d302dcebdbc25d6a886c8" /-! # Theory of univariate polynomials We prove basic results about univariate polynomials. -/ noncomputable section open Polynomial open Finset namespace Polynomial universe u v w z variable {R : Type u} {S : Type v} {T : Type w} {a b : R} {n : ℕ} section CommRing variable [CommRing R] {p q : R[X]} section variable [Semiring S] theorem natDegree_pos_of_aeval_root [Algebra R S] {p : R[X]} (hp : p ≠ 0) {z : S} (hz : aeval z p = 0) (inj : ∀ x : R, algebraMap R S x = 0 → x = 0) : 0 < p.natDegree := natDegree_pos_of_eval₂_root hp (algebraMap R S) hz inj #align polynomial.nat_degree_pos_of_aeval_root Polynomial.natDegree_pos_of_aeval_root theorem degree_pos_of_aeval_root [Algebra R S] {p : R[X]} (hp : p ≠ 0) {z : S} (hz : aeval z p = 0) (inj : ∀ x : R, algebraMap R S x = 0 → x = 0) : 0 < p.degree := natDegree_pos_iff_degree_pos.mp (natDegree_pos_of_aeval_root hp hz inj) #align polynomial.degree_pos_of_aeval_root Polynomial.degree_pos_of_aeval_root theorem modByMonic_eq_of_dvd_sub (hq : q.Monic) {p₁ p₂ : R[X]} (h : q ∣ p₁ - p₂) : p₁ %ₘ q = p₂ %ₘ q := by nontriviality R obtain ⟨f, sub_eq⟩ := h refine (div_modByMonic_unique (p₂ /ₘ q + f) _ hq ⟨?_, degree_modByMonic_lt _ hq⟩).2 rw [sub_eq_iff_eq_add.mp sub_eq, mul_add, ← add_assoc, modByMonic_add_div _ hq, add_comm] #align polynomial.mod_by_monic_eq_of_dvd_sub Polynomial.modByMonic_eq_of_dvd_sub theorem add_modByMonic (p₁ p₂ : R[X]) : (p₁ + p₂) %ₘ q = p₁ %ₘ q + p₂ %ₘ q := by by_cases hq : q.Monic · cases' subsingleton_or_nontrivial R with hR hR · simp only [eq_iff_true_of_subsingleton] · exact (div_modByMonic_unique (p₁ /ₘ q + p₂ /ₘ q) _ hq ⟨by rw [mul_add, add_left_comm, add_assoc, modByMonic_add_div _ hq, ← add_assoc, add_comm (q * _), modByMonic_add_div _ hq], (degree_add_le _ _).trans_lt (max_lt (degree_modByMonic_lt _ hq) (degree_modByMonic_lt _ hq))⟩).2 · simp_rw [modByMonic_eq_of_not_monic _ hq] #align polynomial.add_mod_by_monic Polynomial.add_modByMonic theorem smul_modByMonic (c : R) (p : R[X]) : c • p %ₘ q = c • (p %ₘ q) := by by_cases hq : q.Monic · cases' subsingleton_or_nontrivial R with hR hR · simp only [eq_iff_true_of_subsingleton] · exact (div_modByMonic_unique (c • (p /ₘ q)) (c • (p %ₘ q)) hq ⟨by rw [mul_smul_comm, ← smul_add, modByMonic_add_div p hq], (degree_smul_le _ _).trans_lt (degree_modByMonic_lt _ hq)⟩).2 · simp_rw [modByMonic_eq_of_not_monic _ hq] #align polynomial.smul_mod_by_monic Polynomial.smul_modByMonic /-- `_ %ₘ q` as an `R`-linear map. -/ @[simps] def modByMonicHom (q : R[X]) : R[X] →ₗ[R] R[X] where toFun p := p %ₘ q map_add' := add_modByMonic map_smul' := smul_modByMonic #align polynomial.mod_by_monic_hom Polynomial.modByMonicHom theorem neg_modByMonic (p mod : R[X]) : (-p) %ₘ mod = - (p %ₘ mod) := (modByMonicHom mod).map_neg p theorem sub_modByMonic (a b mod : R[X]) : (a - b) %ₘ mod = a %ₘ mod - b %ₘ mod := (modByMonicHom mod).map_sub a b end section variable [Ring S] theorem aeval_modByMonic_eq_self_of_root [Algebra R S] {p q : R[X]} (hq : q.Monic) {x : S} (hx : aeval x q = 0) : aeval x (p %ₘ q) = aeval x p := by --`eval₂_modByMonic_eq_self_of_root` doesn't work here as it needs commutativity rw [modByMonic_eq_sub_mul_div p hq, _root_.map_sub, _root_.map_mul, hx, zero_mul, sub_zero] #align polynomial.aeval_mod_by_monic_eq_self_of_root Polynomial.aeval_modByMonic_eq_self_of_root end end CommRing section NoZeroDivisors variable [Semiring R] [NoZeroDivisors R] {p q : R[X]} instance : NoZeroDivisors R[X] where eq_zero_or_eq_zero_of_mul_eq_zero h := by rw [← leadingCoeff_eq_zero, ← leadingCoeff_eq_zero] refine eq_zero_or_eq_zero_of_mul_eq_zero ?_ rw [← leadingCoeff_zero, ← leadingCoeff_mul, h] theorem natDegree_mul (hp : p ≠ 0) (hq : q ≠ 0) : (p*q).natDegree = p.natDegree + q.natDegree := by rw [← Nat.cast_inj (R := WithBot ℕ), ← degree_eq_natDegree (mul_ne_zero hp hq), Nat.cast_add, ← degree_eq_natDegree hp, ← degree_eq_natDegree hq, degree_mul] #align polynomial.nat_degree_mul Polynomial.natDegree_mul theorem trailingDegree_mul : (p * q).trailingDegree = p.trailingDegree + q.trailingDegree := by by_cases hp : p = 0 · rw [hp, zero_mul, trailingDegree_zero, top_add] by_cases hq : q = 0 · rw [hq, mul_zero, trailingDegree_zero, add_top] · rw [trailingDegree_eq_natTrailingDegree hp, trailingDegree_eq_natTrailingDegree hq, trailingDegree_eq_natTrailingDegree (mul_ne_zero hp hq), natTrailingDegree_mul hp hq] apply WithTop.coe_add #align polynomial.trailing_degree_mul Polynomial.trailingDegree_mul @[simp] theorem natDegree_pow (p : R[X]) (n : ℕ) : natDegree (p ^ n) = n * natDegree p := by classical obtain rfl | hp := eq_or_ne p 0 · obtain rfl | hn := eq_or_ne n 0 <;> simp [*] exact natDegree_pow' $ by rw [← leadingCoeff_pow, Ne, leadingCoeff_eq_zero]; exact pow_ne_zero _ hp #align polynomial.nat_degree_pow Polynomial.natDegree_pow theorem degree_le_mul_left (p : R[X]) (hq : q ≠ 0) : degree p ≤ degree (p * q) := by classical exact if hp : p = 0 then by simp only [hp, zero_mul, le_refl] else by rw [degree_mul, degree_eq_natDegree hp, degree_eq_natDegree hq]; exact WithBot.coe_le_coe.2 (Nat.le_add_right _ _) #align polynomial.degree_le_mul_left Polynomial.degree_le_mul_left theorem natDegree_le_of_dvd {p q : R[X]} (h1 : p ∣ q) (h2 : q ≠ 0) : p.natDegree ≤ q.natDegree := by rcases h1 with ⟨q, rfl⟩; rw [mul_ne_zero_iff] at h2 rw [natDegree_mul h2.1 h2.2]; exact Nat.le_add_right _ _ #align polynomial.nat_degree_le_of_dvd Polynomial.natDegree_le_of_dvd theorem degree_le_of_dvd {p q : R[X]} (h1 : p ∣ q) (h2 : q ≠ 0) : degree p ≤ degree q := by rcases h1 with ⟨q, rfl⟩; rw [mul_ne_zero_iff] at h2 exact degree_le_mul_left p h2.2 #align polynomial.degree_le_of_dvd Polynomial.degree_le_of_dvd theorem eq_zero_of_dvd_of_degree_lt {p q : R[X]} (h₁ : p ∣ q) (h₂ : degree q < degree p) : q = 0 := by by_contra hc exact (lt_iff_not_ge _ _).mp h₂ (degree_le_of_dvd h₁ hc) #align polynomial.eq_zero_of_dvd_of_degree_lt Polynomial.eq_zero_of_dvd_of_degree_lt theorem eq_zero_of_dvd_of_natDegree_lt {p q : R[X]} (h₁ : p ∣ q) (h₂ : natDegree q < natDegree p) : q = 0 := by by_contra hc exact (lt_iff_not_ge _ _).mp h₂ (natDegree_le_of_dvd h₁ hc) #align polynomial.eq_zero_of_dvd_of_nat_degree_lt Polynomial.eq_zero_of_dvd_of_natDegree_lt theorem not_dvd_of_degree_lt {p q : R[X]} (h0 : q ≠ 0) (hl : q.degree < p.degree) : ¬p ∣ q := by by_contra hcontra exact h0 (eq_zero_of_dvd_of_degree_lt hcontra hl) #align polynomial.not_dvd_of_degree_lt Polynomial.not_dvd_of_degree_lt theorem not_dvd_of_natDegree_lt {p q : R[X]} (h0 : q ≠ 0) (hl : q.natDegree < p.natDegree) : ¬p ∣ q := by by_contra hcontra exact h0 (eq_zero_of_dvd_of_natDegree_lt hcontra hl) #align polynomial.not_dvd_of_nat_degree_lt Polynomial.not_dvd_of_natDegree_lt /-- This lemma is useful for working with the `intDegree` of a rational function. -/ theorem natDegree_sub_eq_of_prod_eq {p₁ p₂ q₁ q₂ : R[X]} (hp₁ : p₁ ≠ 0) (hq₁ : q₁ ≠ 0) (hp₂ : p₂ ≠ 0) (hq₂ : q₂ ≠ 0) (h_eq : p₁ * q₂ = p₂ * q₁) : (p₁.natDegree : ℤ) - q₁.natDegree = (p₂.natDegree : ℤ) - q₂.natDegree := by rw [sub_eq_sub_iff_add_eq_add] norm_cast rw [← natDegree_mul hp₁ hq₂, ← natDegree_mul hp₂ hq₁, h_eq] #align polynomial.nat_degree_sub_eq_of_prod_eq Polynomial.natDegree_sub_eq_of_prod_eq theorem natDegree_eq_zero_of_isUnit (h : IsUnit p) : natDegree p = 0 := by nontriviality R obtain ⟨q, hq⟩ := h.exists_right_inv have := natDegree_mul (left_ne_zero_of_mul_eq_one hq) (right_ne_zero_of_mul_eq_one hq) rw [hq, natDegree_one, eq_comm, add_eq_zero_iff] at this exact this.1 #align polynomial.nat_degree_eq_zero_of_is_unit Polynomial.natDegree_eq_zero_of_isUnit theorem degree_eq_zero_of_isUnit [Nontrivial R] (h : IsUnit p) : degree p = 0 := (natDegree_eq_zero_iff_degree_le_zero.mp <| natDegree_eq_zero_of_isUnit h).antisymm (zero_le_degree_iff.mpr h.ne_zero) #align polynomial.degree_eq_zero_of_is_unit Polynomial.degree_eq_zero_of_isUnit @[simp] theorem degree_coe_units [Nontrivial R] (u : R[X]ˣ) : degree (u : R[X]) = 0 := degree_eq_zero_of_isUnit ⟨u, rfl⟩ #align polynomial.degree_coe_units Polynomial.degree_coe_units /-- Characterization of a unit of a polynomial ring over an integral domain `R`. See `Polynomial.isUnit_iff_coeff_isUnit_isNilpotent` when `R` is a commutative ring. -/ theorem isUnit_iff : IsUnit p ↔ ∃ r : R, IsUnit r ∧ C r = p := ⟨fun hp => ⟨p.coeff 0, let h := eq_C_of_natDegree_eq_zero (natDegree_eq_zero_of_isUnit hp) ⟨isUnit_C.1 (h ▸ hp), h.symm⟩⟩, fun ⟨_, hr, hrp⟩ => hrp ▸ isUnit_C.2 hr⟩ #align polynomial.is_unit_iff Polynomial.isUnit_iff theorem not_isUnit_of_degree_pos (p : R[X]) (hpl : 0 < p.degree) : ¬ IsUnit p := by cases subsingleton_or_nontrivial R · simp [Subsingleton.elim p 0] at hpl intro h simp [degree_eq_zero_of_isUnit h] at hpl theorem not_isUnit_of_natDegree_pos (p : R[X]) (hpl : 0 < p.natDegree) : ¬ IsUnit p := not_isUnit_of_degree_pos _ (natDegree_pos_iff_degree_pos.mp hpl) variable [CharZero R] end NoZeroDivisors section NoZeroDivisors variable [CommSemiring R] [NoZeroDivisors R] {p q : R[X]} theorem irreducible_of_monic (hp : p.Monic) (hp1 : p ≠ 1) : Irreducible p ↔ ∀ f g : R[X], f.Monic → g.Monic → f * g = p → f = 1 ∨ g = 1 := by refine ⟨fun h f g hf hg hp => (h.2 f g hp.symm).imp hf.eq_one_of_isUnit hg.eq_one_of_isUnit, fun h => ⟨hp1 ∘ hp.eq_one_of_isUnit, fun f g hfg => (h (g * C f.leadingCoeff) (f * C g.leadingCoeff) ?_ ?_ ?_).symm.imp (isUnit_of_mul_eq_one f _) (isUnit_of_mul_eq_one g _)⟩⟩ · rwa [Monic, leadingCoeff_mul, leadingCoeff_C, ← leadingCoeff_mul, mul_comm, ← hfg, ← Monic] · rwa [Monic, leadingCoeff_mul, leadingCoeff_C, ← leadingCoeff_mul, ← hfg, ← Monic] · rw [mul_mul_mul_comm, ← C_mul, ← leadingCoeff_mul, ← hfg, hp.leadingCoeff, C_1, mul_one, mul_comm, ← hfg] #align polynomial.irreducible_of_monic Polynomial.irreducible_of_monic theorem Monic.irreducible_iff_natDegree (hp : p.Monic) : Irreducible p ↔ p ≠ 1 ∧ ∀ f g : R[X], f.Monic → g.Monic → f * g = p → f.natDegree = 0 ∨ g.natDegree = 0 := by by_cases hp1 : p = 1; · simp [hp1] rw [irreducible_of_monic hp hp1, and_iff_right hp1] refine forall₄_congr fun a b ha hb => ?_ rw [ha.natDegree_eq_zero_iff_eq_one, hb.natDegree_eq_zero_iff_eq_one] #align polynomial.monic.irreducible_iff_nat_degree Polynomial.Monic.irreducible_iff_natDegree theorem Monic.irreducible_iff_natDegree' (hp : p.Monic) : Irreducible p ↔ p ≠ 1 ∧ ∀ f g : R[X], f.Monic → g.Monic → f * g = p → g.natDegree ∉ Ioc 0 (p.natDegree / 2) := by simp_rw [hp.irreducible_iff_natDegree, mem_Ioc, Nat.le_div_iff_mul_le zero_lt_two, mul_two] apply and_congr_right' constructor <;> intro h f g hf hg he <;> subst he · rw [hf.natDegree_mul hg, add_le_add_iff_right] exact fun ha => (h f g hf hg rfl).elim (ha.1.trans_le ha.2).ne' ha.1.ne' · simp_rw [hf.natDegree_mul hg, pos_iff_ne_zero] at h contrapose! h obtain hl | hl := le_total f.natDegree g.natDegree · exact ⟨g, f, hg, hf, mul_comm g f, h.1, add_le_add_left hl _⟩ · exact ⟨f, g, hf, hg, rfl, h.2, add_le_add_right hl _⟩ #align polynomial.monic.irreducible_iff_nat_degree' Polynomial.Monic.irreducible_iff_natDegree' /-- Alternate phrasing of `Polynomial.Monic.irreducible_iff_natDegree'` where we only have to check one divisor at a time. -/ theorem Monic.irreducible_iff_lt_natDegree_lt {p : R[X]} (hp : p.Monic) (hp1 : p ≠ 1) : Irreducible p ↔ ∀ q, Monic q → natDegree q ∈ Finset.Ioc 0 (natDegree p / 2) → ¬ q ∣ p := by rw [hp.irreducible_iff_natDegree', and_iff_right hp1] constructor · rintro h g hg hdg ⟨f, rfl⟩ exact h f g (hg.of_mul_monic_left hp) hg (mul_comm f g) hdg · rintro h f g - hg rfl hdg exact h g hg hdg (dvd_mul_left g f) theorem Monic.not_irreducible_iff_exists_add_mul_eq_coeff (hm : p.Monic) (hnd : p.natDegree = 2) : ¬Irreducible p ↔ ∃ c₁ c₂, p.coeff 0 = c₁ * c₂ ∧ p.coeff 1 = c₁ + c₂ := by cases subsingleton_or_nontrivial R · simp [natDegree_of_subsingleton] at hnd rw [hm.irreducible_iff_natDegree', and_iff_right, hnd] · push_neg constructor · rintro ⟨a, b, ha, hb, rfl, hdb⟩ simp only [zero_lt_two, Nat.div_self, ge_iff_le, Nat.Ioc_succ_singleton, zero_add, mem_singleton] at hdb have hda := hnd rw [ha.natDegree_mul hb, hdb] at hda use a.coeff 0, b.coeff 0, mul_coeff_zero a b simpa only [nextCoeff, hnd, add_right_cancel hda, hdb] using ha.nextCoeff_mul hb · rintro ⟨c₁, c₂, hmul, hadd⟩ refine ⟨X + C c₁, X + C c₂, monic_X_add_C _, monic_X_add_C _, ?_, ?_⟩ · rw [p.as_sum_range_C_mul_X_pow, hnd, Finset.sum_range_succ, Finset.sum_range_succ, Finset.sum_range_one, ← hnd, hm.coeff_natDegree, hnd, hmul, hadd, C_mul, C_add, C_1] ring · rw [mem_Ioc, natDegree_X_add_C _] simp · rintro rfl simp [natDegree_one] at hnd #align polynomial.monic.not_irreducible_iff_exists_add_mul_eq_coeff Polynomial.Monic.not_irreducible_iff_exists_add_mul_eq_coeff theorem root_mul : IsRoot (p * q) a ↔ IsRoot p a ∨ IsRoot q a := by simp_rw [IsRoot, eval_mul, mul_eq_zero] #align polynomial.root_mul Polynomial.root_mul theorem root_or_root_of_root_mul (h : IsRoot (p * q) a) : IsRoot p a ∨ IsRoot q a := root_mul.1 h #align polynomial.root_or_root_of_root_mul Polynomial.root_or_root_of_root_mul end NoZeroDivisors section Ring variable [Ring R] [IsDomain R] {p q : R[X]} instance : IsDomain R[X] := NoZeroDivisors.to_isDomain _ end Ring section CommSemiring variable [CommSemiring R] theorem Monic.C_dvd_iff_isUnit {p : R[X]} (hp : Monic p) {a : R} : C a ∣ p ↔ IsUnit a := ⟨fun h => isUnit_iff_dvd_one.mpr <| hp.coeff_natDegree ▸ (C_dvd_iff_dvd_coeff _ _).mp h p.natDegree, fun ha => (ha.map C).dvd⟩ theorem degree_pos_of_not_isUnit_of_dvd_monic {a p : R[X]} (ha : ¬ IsUnit a) (hap : a ∣ p) (hp : Monic p) : 0 < degree a := lt_of_not_ge <| fun h => ha <| by rw [Polynomial.eq_C_of_degree_le_zero h] at hap ⊢ simpa [hp.C_dvd_iff_isUnit, isUnit_C] using hap theorem natDegree_pos_of_not_isUnit_of_dvd_monic {a p : R[X]} (ha : ¬ IsUnit a) (hap : a ∣ p) (hp : Monic p) : 0 < natDegree a := natDegree_pos_iff_degree_pos.mpr <| degree_pos_of_not_isUnit_of_dvd_monic ha hap hp theorem degree_pos_of_monic_of_not_isUnit {a : R[X]} (hu : ¬ IsUnit a) (ha : Monic a) : 0 < degree a := degree_pos_of_not_isUnit_of_dvd_monic hu dvd_rfl ha theorem natDegree_pos_of_monic_of_not_isUnit {a : R[X]} (hu : ¬ IsUnit a) (ha : Monic a) : 0 < natDegree a := natDegree_pos_iff_degree_pos.mpr <| degree_pos_of_monic_of_not_isUnit hu ha theorem eq_zero_of_mul_eq_zero_of_smul (P : R[X]) (h : ∀ r : R, r • P = 0 → r = 0) : ∀ (Q : R[X]), P * Q = 0 → Q = 0 := by intro Q hQ suffices ∀ i, P.coeff i • Q = 0 by rw [← leadingCoeff_eq_zero] apply h simpa [ext_iff, mul_comm Q.leadingCoeff] using fun i ↦ congr_arg (·.coeff Q.natDegree) (this i) apply Nat.strong_decreasing_induction · use P.natDegree intro i hi rw [coeff_eq_zero_of_natDegree_lt hi, zero_smul] intro l IH obtain _|hl := (natDegree_smul_le (P.coeff l) Q).lt_or_eq · apply eq_zero_of_mul_eq_zero_of_smul _ h (P.coeff l • Q) rw [smul_eq_C_mul, mul_left_comm, hQ, mul_zero] suffices P.coeff l * Q.leadingCoeff = 0 by rwa [← leadingCoeff_eq_zero, ← coeff_natDegree, coeff_smul, hl, coeff_natDegree, smul_eq_mul] let m := Q.natDegree suffices (P * Q).coeff (l + m) = P.coeff l * Q.leadingCoeff by rw [← this, hQ, coeff_zero] rw [coeff_mul] apply Finset.sum_eq_single (l, m) _ (by simp) simp only [Finset.mem_antidiagonal, ne_eq, Prod.forall, Prod.mk.injEq, not_and] intro i j hij H obtain hi|rfl|hi := lt_trichotomy i l · have hj : m < j := by omega rw [coeff_eq_zero_of_natDegree_lt hj, mul_zero] · omega · rw [← coeff_C_mul, ← smul_eq_C_mul, IH _ hi, coeff_zero] termination_by Q => Q.natDegree open nonZeroDivisors in /-- *McCoy theorem*: a polynomial `P : R[X]` is a zerodivisor if and only if there is `a : R` such that `a ≠ 0` and `a • P = 0`. -/ theorem nmem_nonZeroDivisors_iff {P : R[X]} : P ∉ R[X]⁰ ↔ ∃ a : R, a ≠ 0 ∧ a • P = 0 := by refine ⟨fun hP ↦ ?_, fun ⟨a, ha, h⟩ h1 ↦ ha <| C_eq_zero.1 <| (h1 _) <| smul_eq_C_mul a ▸ h⟩ by_contra! h obtain ⟨Q, hQ⟩ := _root_.nmem_nonZeroDivisors_iff.1 hP refine hQ.2 (eq_zero_of_mul_eq_zero_of_smul P (fun a ha ↦ ?_) Q (mul_comm P _ ▸ hQ.1)) contrapose! ha exact h a ha open nonZeroDivisors in protected lemma mem_nonZeroDivisors_iff {P : R[X]} : P ∈ R[X]⁰ ↔ ∀ a : R, a • P = 0 → a = 0 := by simpa [not_imp_not] using (nmem_nonZeroDivisors_iff (P := P)).not end CommSemiring section CommRing variable [CommRing R] /- Porting note: the ML3 proof no longer worked because of a conflict in the inferred type and synthesized type for `DecidableRel` when using `Nat.le_find_iff` from `Mathlib.Algebra.Polynomial.Div` After some discussion on [Zulip] (https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/decidability.20leakage) introduced `Polynomial.rootMultiplicity_eq_nat_find_of_nonzero` to contain the issue -/ /-- The multiplicity of `a` as root of a nonzero polynomial `p` is at least `n` iff `(X - a) ^ n` divides `p`. -/ theorem le_rootMultiplicity_iff {p : R[X]} (p0 : p ≠ 0) {a : R} {n : ℕ} : n ≤ rootMultiplicity a p ↔ (X - C a) ^ n ∣ p := by classical rw [rootMultiplicity_eq_nat_find_of_nonzero p0, @Nat.le_find_iff _ (_)] simp_rw [Classical.not_not] refine ⟨fun h => ?_, fun h m hm => (pow_dvd_pow _ hm).trans h⟩ cases' n with n; · rw [pow_zero] apply one_dvd; · exact h n n.lt_succ_self #align polynomial.le_root_multiplicity_iff Polynomial.le_rootMultiplicity_iff theorem rootMultiplicity_le_iff {p : R[X]} (p0 : p ≠ 0) (a : R) (n : ℕ) : rootMultiplicity a p ≤ n ↔ ¬(X - C a) ^ (n + 1) ∣ p := by rw [← (le_rootMultiplicity_iff p0).not, not_le, Nat.lt_add_one_iff] #align polynomial.root_multiplicity_le_iff Polynomial.rootMultiplicity_le_iff theorem pow_rootMultiplicity_not_dvd {p : R[X]} (p0 : p ≠ 0) (a : R) : ¬(X - C a) ^ (rootMultiplicity a p + 1) ∣ p := by rw [← rootMultiplicity_le_iff p0] #align polynomial.pow_root_multiplicity_not_dvd Polynomial.pow_rootMultiplicity_not_dvd theorem X_sub_C_pow_dvd_iff {p : R[X]} {t : R} {n : ℕ} : (X - C t) ^ n ∣ p ↔ X ^ n ∣ p.comp (X + C t) := by convert (map_dvd_iff <| algEquivAevalXAddC t).symm using 2 simp [C_eq_algebraMap] theorem comp_X_add_C_eq_zero_iff {p : R[X]} (t : R) : p.comp (X + C t) = 0 ↔ p = 0 := AddEquivClass.map_eq_zero_iff (algEquivAevalXAddC t) theorem comp_X_add_C_ne_zero_iff {p : R[X]} (t : R) : p.comp (X + C t) ≠ 0 ↔ p ≠ 0 := Iff.not <| comp_X_add_C_eq_zero_iff t theorem rootMultiplicity_eq_rootMultiplicity {p : R[X]} {t : R} : p.rootMultiplicity t = (p.comp (X + C t)).rootMultiplicity 0 := by classical simp_rw [rootMultiplicity_eq_multiplicity, comp_X_add_C_eq_zero_iff] congr; ext; congr 1 rw [C_0, sub_zero] convert (multiplicity.multiplicity_map_eq <| algEquivAevalXAddC t).symm using 2 simp [C_eq_algebraMap] theorem rootMultiplicity_eq_natTrailingDegree' {p : R[X]} : p.rootMultiplicity 0 = p.natTrailingDegree := by by_cases h : p = 0 · simp only [h, rootMultiplicity_zero, natTrailingDegree_zero] refine le_antisymm ?_ ?_ · rw [rootMultiplicity_le_iff h, map_zero, sub_zero, X_pow_dvd_iff, not_forall] exact ⟨p.natTrailingDegree, fun h' ↦ trailingCoeff_nonzero_iff_nonzero.2 h <| h' <| Nat.lt.base _⟩ · rw [le_rootMultiplicity_iff h, map_zero, sub_zero, X_pow_dvd_iff] exact fun _ ↦ coeff_eq_zero_of_lt_natTrailingDegree theorem rootMultiplicity_eq_natTrailingDegree {p : R[X]} {t : R} : p.rootMultiplicity t = (p.comp (X + C t)).natTrailingDegree := rootMultiplicity_eq_rootMultiplicity.trans rootMultiplicity_eq_natTrailingDegree' theorem eval_divByMonic_eq_trailingCoeff_comp {p : R[X]} {t : R} : (p /ₘ (X - C t) ^ p.rootMultiplicity t).eval t = (p.comp (X + C t)).trailingCoeff := by obtain rfl | hp := eq_or_ne p 0 · rw [zero_divByMonic, eval_zero, zero_comp, trailingCoeff_zero] have mul_eq := p.pow_mul_divByMonic_rootMultiplicity_eq t set m := p.rootMultiplicity t set g := p /ₘ (X - C t) ^ m have : (g.comp (X + C t)).coeff 0 = g.eval t := by rw [coeff_zero_eq_eval_zero, eval_comp, eval_add, eval_X, eval_C, zero_add] rw [← congr_arg (comp · <| X + C t) mul_eq, mul_comp, pow_comp, sub_comp, X_comp, C_comp, add_sub_cancel_right, ← reverse_leadingCoeff, reverse_X_pow_mul, reverse_leadingCoeff, trailingCoeff, Nat.le_zero.1 (natTrailingDegree_le_of_ne_zero <| this ▸ eval_divByMonic_pow_rootMultiplicity_ne_zero t hp), this] section nonZeroDivisors open scoped nonZeroDivisors theorem Monic.mem_nonZeroDivisors {p : R[X]} (h : p.Monic) : p ∈ R[X]⁰ := mem_nonZeroDivisors_iff.2 fun _ hx ↦ (mul_left_eq_zero_iff h).1 hx theorem mem_nonZeroDivisors_of_leadingCoeff {p : R[X]} (h : p.leadingCoeff ∈ R⁰) : p ∈ R[X]⁰ := by refine mem_nonZeroDivisors_iff.2 fun x hx ↦ leadingCoeff_eq_zero.1 ?_ by_contra hx' rw [← mul_right_mem_nonZeroDivisors_eq_zero_iff h] at hx' simp only [← leadingCoeff_mul' hx', hx, leadingCoeff_zero, not_true] at hx' end nonZeroDivisors theorem rootMultiplicity_mul_X_sub_C_pow {p : R[X]} {a : R} {n : ℕ} (h : p ≠ 0) : (p * (X - C a) ^ n).rootMultiplicity a = p.rootMultiplicity a + n := by have h2 := monic_X_sub_C a |>.pow n |>.mul_left_ne_zero h refine le_antisymm ?_ ?_ · rw [rootMultiplicity_le_iff h2, add_assoc, add_comm n, ← add_assoc, pow_add, dvd_cancel_right_mem_nonZeroDivisors (monic_X_sub_C a |>.pow n |>.mem_nonZeroDivisors)] exact pow_rootMultiplicity_not_dvd h a · rw [le_rootMultiplicity_iff h2, pow_add] exact mul_dvd_mul_right (pow_rootMultiplicity_dvd p a) _ /-- The multiplicity of `a` as root of `(X - a) ^ n` is `n`. -/ theorem rootMultiplicity_X_sub_C_pow [Nontrivial R] (a : R) (n : ℕ) : rootMultiplicity a ((X - C a) ^ n) = n := by have := rootMultiplicity_mul_X_sub_C_pow (a := a) (n := n) C.map_one_ne_zero rwa [rootMultiplicity_C, map_one, one_mul, zero_add] at this set_option linter.uppercaseLean3 false in #align polynomial.root_multiplicity_X_sub_C_pow Polynomial.rootMultiplicity_X_sub_C_pow theorem rootMultiplicity_X_sub_C_self [Nontrivial R] {x : R} : rootMultiplicity x (X - C x) = 1 := pow_one (X - C x) ▸ rootMultiplicity_X_sub_C_pow x 1 set_option linter.uppercaseLean3 false in #align polynomial.root_multiplicity_X_sub_C_self Polynomial.rootMultiplicity_X_sub_C_self -- Porting note: swapped instance argument order theorem rootMultiplicity_X_sub_C [Nontrivial R] [DecidableEq R] {x y : R} : rootMultiplicity x (X - C y) = if x = y then 1 else 0 := by split_ifs with hxy · rw [hxy] exact rootMultiplicity_X_sub_C_self exact rootMultiplicity_eq_zero (mt root_X_sub_C.mp (Ne.symm hxy)) set_option linter.uppercaseLean3 false in #align polynomial.root_multiplicity_X_sub_C Polynomial.rootMultiplicity_X_sub_C /-- The multiplicity of `p + q` is at least the minimum of the multiplicities. -/ theorem rootMultiplicity_add {p q : R[X]} (a : R) (hzero : p + q ≠ 0) : min (rootMultiplicity a p) (rootMultiplicity a q) ≤ rootMultiplicity a (p + q) := by rw [le_rootMultiplicity_iff hzero] exact min_pow_dvd_add (pow_rootMultiplicity_dvd p a) (pow_rootMultiplicity_dvd q a) #align polynomial.root_multiplicity_add Polynomial.rootMultiplicity_add theorem le_rootMultiplicity_mul {p q : R[X]} (x : R) (hpq : p * q ≠ 0) : rootMultiplicity x p + rootMultiplicity x q ≤ rootMultiplicity x (p * q) := by rw [le_rootMultiplicity_iff hpq, pow_add] exact mul_dvd_mul (pow_rootMultiplicity_dvd p x) (pow_rootMultiplicity_dvd q x) theorem rootMultiplicity_mul' {p q : R[X]} {x : R} (hpq : (p /ₘ (X - C x) ^ p.rootMultiplicity x).eval x * (q /ₘ (X - C x) ^ q.rootMultiplicity x).eval x ≠ 0) : rootMultiplicity x (p * q) = rootMultiplicity x p + rootMultiplicity x q := by simp_rw [eval_divByMonic_eq_trailingCoeff_comp] at hpq simp_rw [rootMultiplicity_eq_natTrailingDegree, mul_comp, natTrailingDegree_mul' hpq] variable [IsDomain R] {p q : R[X]} @[simp] theorem natDegree_coe_units (u : R[X]ˣ) : natDegree (u : R[X]) = 0 := natDegree_eq_of_degree_eq_some (degree_coe_units u) #align polynomial.nat_degree_coe_units Polynomial.natDegree_coe_units theorem coeff_coe_units_zero_ne_zero (u : R[X]ˣ) : coeff (u : R[X]) 0 ≠ 0 := by conv in 0 => rw [← natDegree_coe_units u] rw [← leadingCoeff, Ne, leadingCoeff_eq_zero] exact Units.ne_zero _ #align polynomial.coeff_coe_units_zero_ne_zero Polynomial.coeff_coe_units_zero_ne_zero theorem degree_eq_degree_of_associated (h : Associated p q) : degree p = degree q := by let ⟨u, hu⟩ := h simp [hu.symm] #align polynomial.degree_eq_degree_of_associated Polynomial.degree_eq_degree_of_associated theorem degree_eq_one_of_irreducible_of_root (hi : Irreducible p) {x : R} (hx : IsRoot p x) : degree p = 1 := let ⟨g, hg⟩ := dvd_iff_isRoot.2 hx have : IsUnit (X - C x) ∨ IsUnit g := hi.isUnit_or_isUnit hg this.elim (fun h => by have h₁ : degree (X - C x) = 1 := degree_X_sub_C x have h₂ : degree (X - C x) = 0 := degree_eq_zero_of_isUnit h rw [h₁] at h₂; exact absurd h₂ (by decide)) fun hgu => by rw [hg, degree_mul, degree_X_sub_C, degree_eq_zero_of_isUnit hgu, add_zero] #align polynomial.degree_eq_one_of_irreducible_of_root Polynomial.degree_eq_one_of_irreducible_of_root /-- Division by a monic polynomial doesn't change the leading coefficient. -/ theorem leadingCoeff_divByMonic_of_monic {R : Type u} [CommRing R] {p q : R[X]} (hmonic : q.Monic) (hdegree : q.degree ≤ p.degree) : (p /ₘ q).leadingCoeff = p.leadingCoeff := by nontriviality have h : q.leadingCoeff * (p /ₘ q).leadingCoeff ≠ 0 := by simpa [divByMonic_eq_zero_iff hmonic, hmonic.leadingCoeff, Nat.WithBot.one_le_iff_zero_lt] using hdegree nth_rw 2 [← modByMonic_add_div p hmonic] rw [leadingCoeff_add_of_degree_lt, leadingCoeff_monic_mul hmonic] rw [degree_mul' h, degree_add_divByMonic hmonic hdegree] exact (degree_modByMonic_lt p hmonic).trans_le hdegree #align polynomial.leading_coeff_div_by_monic_of_monic Polynomial.leadingCoeff_divByMonic_of_monic theorem leadingCoeff_divByMonic_X_sub_C (p : R[X]) (hp : degree p ≠ 0) (a : R) : leadingCoeff (p /ₘ (X - C a)) = leadingCoeff p := by nontriviality cases' hp.lt_or_lt with hd hd · rw [degree_eq_bot.mp <| Nat.WithBot.lt_zero_iff.mp hd, zero_divByMonic] refine leadingCoeff_divByMonic_of_monic (monic_X_sub_C a) ?_ rwa [degree_X_sub_C, Nat.WithBot.one_le_iff_zero_lt] set_option linter.uppercaseLean3 false in #align polynomial.leading_coeff_div_by_monic_X_sub_C Polynomial.leadingCoeff_divByMonic_X_sub_C
Mathlib/Algebra/Polynomial/RingDivision.lean
618
629
theorem eq_of_dvd_of_natDegree_le_of_leadingCoeff {p q : R[X]} (hpq : p ∣ q) (h₁ : q.natDegree ≤ p.natDegree) (h₂ : p.leadingCoeff = q.leadingCoeff) : p = q := by
by_cases hq : q = 0 · rwa [hq, leadingCoeff_zero, leadingCoeff_eq_zero, ← hq] at h₂ replace h₁ := (natDegree_le_of_dvd hpq hq).antisymm h₁ obtain ⟨u, rfl⟩ := hpq replace hq := mul_ne_zero_iff.mp hq rw [natDegree_mul hq.1 hq.2, self_eq_add_right] at h₁ rw [eq_C_of_natDegree_eq_zero h₁, leadingCoeff_mul, leadingCoeff_C, eq_comm, mul_eq_left₀ (leadingCoeff_ne_zero.mpr hq.1)] at h₂ rw [eq_C_of_natDegree_eq_zero h₁, h₂, map_one, mul_one]
/- Copyright (c) 2018 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Johannes Hölzl -/ import Mathlib.Analysis.NormedSpace.Multilinear.Basic import Mathlib.Analysis.NormedSpace.Units import Mathlib.Analysis.NormedSpace.OperatorNorm.Completeness import Mathlib.Analysis.NormedSpace.OperatorNorm.Mul #align_import analysis.normed_space.bounded_linear_maps from "leanprover-community/mathlib"@"ce11c3c2a285bbe6937e26d9792fda4e51f3fe1a" /-! # Bounded linear maps This file defines a class stating that a map between normed vector spaces is (bi)linear and continuous. Instead of asking for continuity, the definition takes the equivalent condition (because the space is normed) that `‖f x‖` is bounded by a multiple of `‖x‖`. Hence the "bounded" in the name refers to `‖f x‖/‖x‖` rather than `‖f x‖` itself. ## Main definitions * `IsBoundedLinearMap`: Class stating that a map `f : E → F` is linear and has `‖f x‖` bounded by a multiple of `‖x‖`. * `IsBoundedBilinearMap`: Class stating that a map `f : E × F → G` is bilinear and continuous, but through the simpler to provide statement that `‖f (x, y)‖` is bounded by a multiple of `‖x‖ * ‖y‖` * `IsBoundedBilinearMap.linearDeriv`: Derivative of a continuous bilinear map as a linear map. * `IsBoundedBilinearMap.deriv`: Derivative of a continuous bilinear map as a continuous linear map. The proof that it is indeed the derivative is `IsBoundedBilinearMap.hasFDerivAt` in `Analysis.Calculus.FDeriv`. ## Main theorems * `IsBoundedBilinearMap.continuous`: A bounded bilinear map is continuous. * `ContinuousLinearEquiv.isOpen`: The continuous linear equivalences are an open subset of the set of continuous linear maps between a pair of Banach spaces. Placed in this file because its proof uses `IsBoundedBilinearMap.continuous`. ## Notes The main use of this file is `IsBoundedBilinearMap`. The file `Analysis.NormedSpace.Multilinear.Basic` already expounds the theory of multilinear maps, but the `2`-variables case is sufficiently simpler to currently deserve its own treatment. `IsBoundedLinearMap` is effectively an unbundled version of `ContinuousLinearMap` (defined in `Topology.Algebra.Module.Basic`, theory over normed spaces developed in `Analysis.NormedSpace.OperatorNorm`), albeit the name disparity. A bundled `ContinuousLinearMap` is to be preferred over an `IsBoundedLinearMap` hypothesis. Historical artifact, really. -/ noncomputable section open Topology open Filter (Tendsto) open Metric ContinuousLinearMap variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] /-- A function `f` satisfies `IsBoundedLinearMap 𝕜 f` if it is linear and satisfies the inequality `‖f x‖ ≤ M * ‖x‖` for some positive constant `M`. -/ structure IsBoundedLinearMap (𝕜 : Type*) [NormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] (f : E → F) extends IsLinearMap 𝕜 f : Prop where bound : ∃ M, 0 < M ∧ ∀ x : E, ‖f x‖ ≤ M * ‖x‖ #align is_bounded_linear_map IsBoundedLinearMap theorem IsLinearMap.with_bound {f : E → F} (hf : IsLinearMap 𝕜 f) (M : ℝ) (h : ∀ x : E, ‖f x‖ ≤ M * ‖x‖) : IsBoundedLinearMap 𝕜 f := ⟨hf, by_cases (fun (this : M ≤ 0) => ⟨1, zero_lt_one, fun x => (h x).trans <| mul_le_mul_of_nonneg_right (this.trans zero_le_one) (norm_nonneg x)⟩) fun (this : ¬M ≤ 0) => ⟨M, lt_of_not_ge this, h⟩⟩ #align is_linear_map.with_bound IsLinearMap.with_bound /-- A continuous linear map satisfies `IsBoundedLinearMap` -/ theorem ContinuousLinearMap.isBoundedLinearMap (f : E →L[𝕜] F) : IsBoundedLinearMap 𝕜 f := { f.toLinearMap.isLinear with bound := f.bound } #align continuous_linear_map.is_bounded_linear_map ContinuousLinearMap.isBoundedLinearMap namespace IsBoundedLinearMap /-- Construct a linear map from a function `f` satisfying `IsBoundedLinearMap 𝕜 f`. -/ def toLinearMap (f : E → F) (h : IsBoundedLinearMap 𝕜 f) : E →ₗ[𝕜] F := IsLinearMap.mk' _ h.toIsLinearMap #align is_bounded_linear_map.to_linear_map IsBoundedLinearMap.toLinearMap /-- Construct a continuous linear map from `IsBoundedLinearMap`. -/ def toContinuousLinearMap {f : E → F} (hf : IsBoundedLinearMap 𝕜 f) : E →L[𝕜] F := { toLinearMap f hf with cont := let ⟨C, _, hC⟩ := hf.bound AddMonoidHomClass.continuous_of_bound (toLinearMap f hf) C hC } #align is_bounded_linear_map.to_continuous_linear_map IsBoundedLinearMap.toContinuousLinearMap theorem zero : IsBoundedLinearMap 𝕜 fun _ : E => (0 : F) := (0 : E →ₗ[𝕜] F).isLinear.with_bound 0 <| by simp [le_refl] #align is_bounded_linear_map.zero IsBoundedLinearMap.zero theorem id : IsBoundedLinearMap 𝕜 fun x : E => x := LinearMap.id.isLinear.with_bound 1 <| by simp [le_refl] #align is_bounded_linear_map.id IsBoundedLinearMap.id theorem fst : IsBoundedLinearMap 𝕜 fun x : E × F => x.1 := by refine (LinearMap.fst 𝕜 E F).isLinear.with_bound 1 fun x => ?_ rw [one_mul] exact le_max_left _ _ #align is_bounded_linear_map.fst IsBoundedLinearMap.fst
Mathlib/Analysis/NormedSpace/BoundedLinearMaps.lean
121
124
theorem snd : IsBoundedLinearMap 𝕜 fun x : E × F => x.2 := by
refine (LinearMap.snd 𝕜 E F).isLinear.with_bound 1 fun x => ?_ rw [one_mul] exact le_max_right _ _
/- Copyright (c) 2022 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.MeasureTheory.Measure.Haar.Basic import Mathlib.Analysis.InnerProductSpace.PiL2 #align_import measure_theory.measure.haar.of_basis from "leanprover-community/mathlib"@"92bd7b1ffeb306a89f450bee126ddd8a284c259d" /-! # Additive Haar measure constructed from a basis Given a basis of a finite-dimensional real vector space, we define the corresponding Lebesgue measure, which gives measure `1` to the parallelepiped spanned by the basis. ## Main definitions * `parallelepiped v` is the parallelepiped spanned by a finite family of vectors. * `Basis.parallelepiped` is the parallelepiped associated to a basis, seen as a compact set with nonempty interior. * `Basis.addHaar` is the Lebesgue measure associated to a basis, giving measure `1` to the corresponding parallelepiped. In particular, we declare a `MeasureSpace` instance on any finite-dimensional inner product space, by using the Lebesgue measure associated to some orthonormal basis (which is in fact independent of the basis). -/ open Set TopologicalSpace MeasureTheory MeasureTheory.Measure FiniteDimensional open scoped Pointwise noncomputable section variable {ι ι' E F : Type*} section Fintype variable [Fintype ι] [Fintype ι'] section AddCommGroup variable [AddCommGroup E] [Module ℝ E] [AddCommGroup F] [Module ℝ F] /-- The closed parallelepiped spanned by a finite family of vectors. -/ def parallelepiped (v : ι → E) : Set E := (fun t : ι → ℝ => ∑ i, t i • v i) '' Icc 0 1 #align parallelepiped parallelepiped theorem mem_parallelepiped_iff (v : ι → E) (x : E) : x ∈ parallelepiped v ↔ ∃ t ∈ Icc (0 : ι → ℝ) 1, x = ∑ i, t i • v i := by simp [parallelepiped, eq_comm] #align mem_parallelepiped_iff mem_parallelepiped_iff theorem parallelepiped_basis_eq (b : Basis ι ℝ E) : parallelepiped b = {x | ∀ i, b.repr x i ∈ Set.Icc 0 1} := by classical ext x simp_rw [mem_parallelepiped_iff, mem_setOf_eq, b.ext_elem_iff, _root_.map_sum, _root_.map_smul, Finset.sum_apply', Basis.repr_self, Finsupp.smul_single, smul_eq_mul, mul_one, Finsupp.single_apply, Finset.sum_ite_eq', Finset.mem_univ, ite_true, mem_Icc, Pi.le_def, Pi.zero_apply, Pi.one_apply, ← forall_and] aesop theorem image_parallelepiped (f : E →ₗ[ℝ] F) (v : ι → E) : f '' parallelepiped v = parallelepiped (f ∘ v) := by simp only [parallelepiped, ← image_comp] congr 1 with t simp only [Function.comp_apply, _root_.map_sum, LinearMap.map_smulₛₗ, RingHom.id_apply] #align image_parallelepiped image_parallelepiped /-- Reindexing a family of vectors does not change their parallelepiped. -/ @[simp] theorem parallelepiped_comp_equiv (v : ι → E) (e : ι' ≃ ι) : parallelepiped (v ∘ e) = parallelepiped v := by simp only [parallelepiped] let K : (ι' → ℝ) ≃ (ι → ℝ) := Equiv.piCongrLeft' (fun _a : ι' => ℝ) e have : Icc (0 : ι → ℝ) 1 = K '' Icc (0 : ι' → ℝ) 1 := by rw [← Equiv.preimage_eq_iff_eq_image] ext x simp only [K, mem_preimage, mem_Icc, Pi.le_def, Pi.zero_apply, Equiv.piCongrLeft'_apply, Pi.one_apply] refine ⟨fun h => ⟨fun i => ?_, fun i => ?_⟩, fun h => ⟨fun i => h.1 (e.symm i), fun i => h.2 (e.symm i)⟩⟩ · simpa only [Equiv.symm_apply_apply] using h.1 (e i) · simpa only [Equiv.symm_apply_apply] using h.2 (e i) rw [this, ← image_comp] congr 1 with x have := fun z : ι' → ℝ => e.symm.sum_comp fun i => z i • v (e i) simp_rw [Equiv.apply_symm_apply] at this simp_rw [Function.comp_apply, mem_image, mem_Icc, K, Equiv.piCongrLeft'_apply, this] #align parallelepiped_comp_equiv parallelepiped_comp_equiv -- The parallelepiped associated to an orthonormal basis of `ℝ` is either `[0, 1]` or `[-1, 0]`. theorem parallelepiped_orthonormalBasis_one_dim (b : OrthonormalBasis ι ℝ ℝ) : parallelepiped b = Icc 0 1 ∨ parallelepiped b = Icc (-1) 0 := by have e : ι ≃ Fin 1 := by apply Fintype.equivFinOfCardEq simp only [← finrank_eq_card_basis b.toBasis, finrank_self] have B : parallelepiped (b.reindex e) = parallelepiped b := by convert parallelepiped_comp_equiv b e.symm ext i simp only [OrthonormalBasis.coe_reindex] rw [← B] let F : ℝ → Fin 1 → ℝ := fun t => fun _i => t have A : Icc (0 : Fin 1 → ℝ) 1 = F '' Icc (0 : ℝ) 1 := by apply Subset.antisymm · intro x hx refine ⟨x 0, ⟨hx.1 0, hx.2 0⟩, ?_⟩ ext j simp only [Subsingleton.elim j 0] · rintro x ⟨y, hy, rfl⟩ exact ⟨fun _j => hy.1, fun _j => hy.2⟩ rcases orthonormalBasis_one_dim (b.reindex e) with (H | H) · left simp_rw [parallelepiped, H, A, Algebra.id.smul_eq_mul, mul_one] simp only [Finset.univ_unique, Fin.default_eq_zero, smul_eq_mul, mul_one, Finset.sum_singleton, ← image_comp, Function.comp_apply, image_id', ge_iff_le, zero_le_one, not_true, gt_iff_lt] · right simp_rw [H, parallelepiped, Algebra.id.smul_eq_mul, A] simp only [F, Finset.univ_unique, Fin.default_eq_zero, mul_neg, mul_one, Finset.sum_neg_distrib, Finset.sum_singleton, ← image_comp, Function.comp, image_neg, preimage_neg_Icc, neg_zero] #align parallelepiped_orthonormal_basis_one_dim parallelepiped_orthonormalBasis_one_dim theorem parallelepiped_eq_sum_segment (v : ι → E) : parallelepiped v = ∑ i, segment ℝ 0 (v i) := by ext simp only [mem_parallelepiped_iff, Set.mem_finset_sum, Finset.mem_univ, forall_true_left, segment_eq_image, smul_zero, zero_add, ← Set.pi_univ_Icc, Set.mem_univ_pi] constructor · rintro ⟨t, ht, rfl⟩ exact ⟨t • v, fun {i} => ⟨t i, ht _, by simp⟩, rfl⟩ rintro ⟨g, hg, rfl⟩ choose t ht hg using @hg refine ⟨@t, @ht, ?_⟩ simp_rw [hg] #align parallelepiped_eq_sum_segment parallelepiped_eq_sum_segment theorem convex_parallelepiped (v : ι → E) : Convex ℝ (parallelepiped v) := by rw [parallelepiped_eq_sum_segment] exact convex_sum _ fun _i _hi => convex_segment _ _ #align convex_parallelepiped convex_parallelepiped /-- A `parallelepiped` is the convex hull of its vertices -/ theorem parallelepiped_eq_convexHull (v : ι → E) : parallelepiped v = convexHull ℝ (∑ i, {(0 : E), v i}) := by simp_rw [convexHull_sum, convexHull_pair, parallelepiped_eq_sum_segment] #align parallelepiped_eq_convex_hull parallelepiped_eq_convexHull /-- The axis aligned parallelepiped over `ι → ℝ` is a cuboid. -/ theorem parallelepiped_single [DecidableEq ι] (a : ι → ℝ) : (parallelepiped fun i => Pi.single i (a i)) = Set.uIcc 0 a := by ext x simp_rw [Set.uIcc, mem_parallelepiped_iff, Set.mem_Icc, Pi.le_def, ← forall_and, Pi.inf_apply, Pi.sup_apply, ← Pi.single_smul', Pi.one_apply, Pi.zero_apply, ← Pi.smul_apply', Finset.univ_sum_single (_ : ι → ℝ)] constructor · rintro ⟨t, ht, rfl⟩ i specialize ht i simp_rw [smul_eq_mul, Pi.mul_apply] rcases le_total (a i) 0 with hai | hai · rw [sup_eq_left.mpr hai, inf_eq_right.mpr hai] exact ⟨le_mul_of_le_one_left hai ht.2, mul_nonpos_of_nonneg_of_nonpos ht.1 hai⟩ · rw [sup_eq_right.mpr hai, inf_eq_left.mpr hai] exact ⟨mul_nonneg ht.1 hai, mul_le_of_le_one_left hai ht.2⟩ · intro h refine ⟨fun i => x i / a i, fun i => ?_, funext fun i => ?_⟩ · specialize h i rcases le_total (a i) 0 with hai | hai · rw [sup_eq_left.mpr hai, inf_eq_right.mpr hai] at h exact ⟨div_nonneg_of_nonpos h.2 hai, div_le_one_of_ge h.1 hai⟩ · rw [sup_eq_right.mpr hai, inf_eq_left.mpr hai] at h exact ⟨div_nonneg h.1 hai, div_le_one_of_le h.2 hai⟩ · specialize h i simp only [smul_eq_mul, Pi.mul_apply] rcases eq_or_ne (a i) 0 with hai | hai · rw [hai, inf_idem, sup_idem, ← le_antisymm_iff] at h rw [hai, ← h, zero_div, zero_mul] · rw [div_mul_cancel₀ _ hai] #align parallelepiped_single parallelepiped_single end AddCommGroup section NormedSpace variable [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedSpace ℝ E] [NormedSpace ℝ F] /-- The parallelepiped spanned by a basis, as a compact set with nonempty interior. -/ def Basis.parallelepiped (b : Basis ι ℝ E) : PositiveCompacts E where carrier := _root_.parallelepiped b isCompact' := IsCompact.image isCompact_Icc (continuous_finset_sum Finset.univ fun (i : ι) (_H : i ∈ Finset.univ) => (continuous_apply i).smul continuous_const) interior_nonempty' := by suffices H : Set.Nonempty (interior (b.equivFunL.symm.toHomeomorph '' Icc 0 1)) by dsimp only [_root_.parallelepiped] convert H exact (b.equivFun_symm_apply _).symm have A : Set.Nonempty (interior (Icc (0 : ι → ℝ) 1)) := by rw [← pi_univ_Icc, interior_pi_set (@finite_univ ι _)] simp only [univ_pi_nonempty_iff, Pi.zero_apply, Pi.one_apply, interior_Icc, nonempty_Ioo, zero_lt_one, imp_true_iff] rwa [← Homeomorph.image_interior, image_nonempty] #align basis.parallelepiped Basis.parallelepiped @[simp] theorem Basis.coe_parallelepiped (b : Basis ι ℝ E) : (b.parallelepiped : Set E) = _root_.parallelepiped b := rfl #align basis.coe_parallelepiped Basis.coe_parallelepiped @[simp] theorem Basis.parallelepiped_reindex (b : Basis ι ℝ E) (e : ι ≃ ι') : (b.reindex e).parallelepiped = b.parallelepiped := PositiveCompacts.ext <| (congr_arg _root_.parallelepiped (b.coe_reindex e)).trans (parallelepiped_comp_equiv b e.symm) #align basis.parallelepiped_reindex Basis.parallelepiped_reindex theorem Basis.parallelepiped_map (b : Basis ι ℝ E) (e : E ≃ₗ[ℝ] F) : (b.map e).parallelepiped = b.parallelepiped.map e (have := FiniteDimensional.of_fintype_basis b -- Porting note: Lean cannot infer the instance above LinearMap.continuous_of_finiteDimensional e.toLinearMap) (have := FiniteDimensional.of_fintype_basis (b.map e) -- Porting note: Lean cannot infer the instance above LinearMap.isOpenMap_of_finiteDimensional _ e.surjective) := PositiveCompacts.ext (image_parallelepiped e.toLinearMap _).symm #align basis.parallelepiped_map Basis.parallelepiped_map set_option tactic.skipAssignedInstances false in theorem Basis.prod_parallelepiped (v : Basis ι ℝ E) (w : Basis ι' ℝ F) : (v.prod w).parallelepiped = v.parallelepiped.prod w.parallelepiped := by ext x simp only [Basis.coe_parallelepiped, TopologicalSpace.PositiveCompacts.coe_prod, Set.mem_prod, mem_parallelepiped_iff] constructor · intro h rcases h with ⟨t, ht1, ht2⟩ constructor · use t ∘ Sum.inl constructor · exact ⟨(ht1.1 <| Sum.inl ·), (ht1.2 <| Sum.inl ·)⟩ simp [ht2, Prod.fst_sum, Prod.snd_sum] · use t ∘ Sum.inr constructor · exact ⟨(ht1.1 <| Sum.inr ·), (ht1.2 <| Sum.inr ·)⟩ simp [ht2, Prod.fst_sum, Prod.snd_sum] intro h rcases h with ⟨⟨t, ht1, ht2⟩, ⟨s, hs1, hs2⟩⟩ use Sum.elim t s constructor · constructor · change ∀ x : ι ⊕ ι', 0 ≤ Sum.elim t s x aesop · change ∀ x : ι ⊕ ι', Sum.elim t s x ≤ 1 aesop ext · simp [ht2, Prod.fst_sum] · simp [hs2, Prod.snd_sum] variable [MeasurableSpace E] [BorelSpace E] /-- The Lebesgue measure associated to a basis, giving measure `1` to the parallelepiped spanned by the basis. -/ irreducible_def Basis.addHaar (b : Basis ι ℝ E) : Measure E := Measure.addHaarMeasure b.parallelepiped #align basis.add_haar Basis.addHaar instance IsAddHaarMeasure_basis_addHaar (b : Basis ι ℝ E) : IsAddHaarMeasure b.addHaar := by rw [Basis.addHaar]; exact Measure.isAddHaarMeasure_addHaarMeasure _ #align is_add_haar_measure_basis_add_haar IsAddHaarMeasure_basis_addHaar instance (b : Basis ι ℝ E) : SigmaFinite b.addHaar := by have : FiniteDimensional ℝ E := FiniteDimensional.of_fintype_basis b rw [Basis.addHaar_def]; exact sigmaFinite_addHaarMeasure /-- Let `μ` be a σ-finite left invariant measure on `E`. Then `μ` is equal to the Haar measure defined by `b` iff the parallelepiped defined by `b` has measure `1` for `μ`. -/
Mathlib/MeasureTheory/Measure/Haar/OfBasis.lean
280
284
theorem Basis.addHaar_eq_iff [SecondCountableTopology E] (b : Basis ι ℝ E) (μ : Measure E) [SigmaFinite μ] [IsAddLeftInvariant μ] : b.addHaar = μ ↔ μ b.parallelepiped = 1 := by
rw [Basis.addHaar_def] exact addHaarMeasure_eq_iff b.parallelepiped μ
/- Copyright (c) 2019 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Lu-Ming Zhang -/ import Mathlib.Data.Matrix.Invertible import Mathlib.LinearAlgebra.Matrix.Adjugate import Mathlib.LinearAlgebra.FiniteDimensional #align_import linear_algebra.matrix.nonsingular_inverse from "leanprover-community/mathlib"@"722b3b152ddd5e0cf21c0a29787c76596cb6b422" /-! # Nonsingular inverses In this file, we define an inverse for square matrices of invertible determinant. For matrices that are not square or not of full rank, there is a more general notion of pseudoinverses which we do not consider here. The definition of inverse used in this file is the adjugate divided by the determinant. We show that dividing the adjugate by `det A` (if possible), giving a matrix `A⁻¹` (`nonsing_inv`), will result in a multiplicative inverse to `A`. Note that there are at least three different inverses in mathlib: * `A⁻¹` (`Inv.inv`): alone, this satisfies no properties, although it is usually used in conjunction with `Group` or `GroupWithZero`. On matrices, this is defined to be zero when no inverse exists. * `⅟A` (`invOf`): this is only available in the presence of `[Invertible A]`, which guarantees an inverse exists. * `Ring.inverse A`: this is defined on any `MonoidWithZero`, and just like `⁻¹` on matrices, is defined to be zero when no inverse exists. We start by working with `Invertible`, and show the main results: * `Matrix.invertibleOfDetInvertible` * `Matrix.detInvertibleOfInvertible` * `Matrix.isUnit_iff_isUnit_det` * `Matrix.mul_eq_one_comm` After this we define `Matrix.inv` and show it matches `⅟A` and `Ring.inverse A`. The rest of the results in the file are then about `A⁻¹` ## References * https://en.wikipedia.org/wiki/Cramer's_rule#Finding_inverse_matrix ## Tags matrix inverse, cramer, cramer's rule, adjugate -/ namespace Matrix universe u u' v variable {l : Type*} {m : Type u} {n : Type u'} {α : Type v} open Matrix Equiv Equiv.Perm Finset /-! ### Matrices are `Invertible` iff their determinants are -/ section Invertible variable [Fintype n] [DecidableEq n] [CommRing α] variable (A : Matrix n n α) (B : Matrix n n α) /-- If `A.det` has a constructive inverse, produce one for `A`. -/ def invertibleOfDetInvertible [Invertible A.det] : Invertible A where invOf := ⅟ A.det • A.adjugate mul_invOf_self := by rw [mul_smul_comm, mul_adjugate, smul_smul, invOf_mul_self, one_smul] invOf_mul_self := by rw [smul_mul_assoc, adjugate_mul, smul_smul, invOf_mul_self, one_smul] #align matrix.invertible_of_det_invertible Matrix.invertibleOfDetInvertible theorem invOf_eq [Invertible A.det] [Invertible A] : ⅟ A = ⅟ A.det • A.adjugate := by letI := invertibleOfDetInvertible A convert (rfl : ⅟ A = _) #align matrix.inv_of_eq Matrix.invOf_eq /-- `A.det` is invertible if `A` has a left inverse. -/ def detInvertibleOfLeftInverse (h : B * A = 1) : Invertible A.det where invOf := B.det mul_invOf_self := by rw [mul_comm, ← det_mul, h, det_one] invOf_mul_self := by rw [← det_mul, h, det_one] #align matrix.det_invertible_of_left_inverse Matrix.detInvertibleOfLeftInverse /-- `A.det` is invertible if `A` has a right inverse. -/ def detInvertibleOfRightInverse (h : A * B = 1) : Invertible A.det where invOf := B.det mul_invOf_self := by rw [← det_mul, h, det_one] invOf_mul_self := by rw [mul_comm, ← det_mul, h, det_one] #align matrix.det_invertible_of_right_inverse Matrix.detInvertibleOfRightInverse /-- If `A` has a constructive inverse, produce one for `A.det`. -/ def detInvertibleOfInvertible [Invertible A] : Invertible A.det := detInvertibleOfLeftInverse A (⅟ A) (invOf_mul_self _) #align matrix.det_invertible_of_invertible Matrix.detInvertibleOfInvertible theorem det_invOf [Invertible A] [Invertible A.det] : (⅟ A).det = ⅟ A.det := by letI := detInvertibleOfInvertible A convert (rfl : _ = ⅟ A.det) #align matrix.det_inv_of Matrix.det_invOf /-- Together `Matrix.detInvertibleOfInvertible` and `Matrix.invertibleOfDetInvertible` form an equivalence, although both sides of the equiv are subsingleton anyway. -/ @[simps] def invertibleEquivDetInvertible : Invertible A ≃ Invertible A.det where toFun := @detInvertibleOfInvertible _ _ _ _ _ A invFun := @invertibleOfDetInvertible _ _ _ _ _ A left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ #align matrix.invertible_equiv_det_invertible Matrix.invertibleEquivDetInvertible variable {A B} theorem mul_eq_one_comm : A * B = 1 ↔ B * A = 1 := suffices ∀ A B : Matrix n n α, A * B = 1 → B * A = 1 from ⟨this A B, this B A⟩ fun A B h => by letI : Invertible B.det := detInvertibleOfLeftInverse _ _ h letI : Invertible B := invertibleOfDetInvertible B calc B * A = B * A * (B * ⅟ B) := by rw [mul_invOf_self, Matrix.mul_one] _ = B * (A * B * ⅟ B) := by simp only [Matrix.mul_assoc] _ = B * ⅟ B := by rw [h, Matrix.one_mul] _ = 1 := mul_invOf_self B #align matrix.mul_eq_one_comm Matrix.mul_eq_one_comm variable (A B) /-- We can construct an instance of invertible A if A has a left inverse. -/ def invertibleOfLeftInverse (h : B * A = 1) : Invertible A := ⟨B, h, mul_eq_one_comm.mp h⟩ #align matrix.invertible_of_left_inverse Matrix.invertibleOfLeftInverse /-- We can construct an instance of invertible A if A has a right inverse. -/ def invertibleOfRightInverse (h : A * B = 1) : Invertible A := ⟨B, mul_eq_one_comm.mp h, h⟩ #align matrix.invertible_of_right_inverse Matrix.invertibleOfRightInverse /-- Given a proof that `A.det` has a constructive inverse, lift `A` to `(Matrix n n α)ˣ`-/ def unitOfDetInvertible [Invertible A.det] : (Matrix n n α)ˣ := @unitOfInvertible _ _ A (invertibleOfDetInvertible A) #align matrix.unit_of_det_invertible Matrix.unitOfDetInvertible /-- When lowered to a prop, `Matrix.invertibleEquivDetInvertible` forms an `iff`. -/ theorem isUnit_iff_isUnit_det : IsUnit A ↔ IsUnit A.det := by simp only [← nonempty_invertible_iff_isUnit, (invertibleEquivDetInvertible A).nonempty_congr] #align matrix.is_unit_iff_is_unit_det Matrix.isUnit_iff_isUnit_det @[simp] theorem isUnits_det_units (A : (Matrix n n α)ˣ) : IsUnit (A : Matrix n n α).det := isUnit_iff_isUnit_det _ |>.mp A.isUnit /-! #### Variants of the statements above with `IsUnit`-/ theorem isUnit_det_of_invertible [Invertible A] : IsUnit A.det := @isUnit_of_invertible _ _ _ (detInvertibleOfInvertible A) #align matrix.is_unit_det_of_invertible Matrix.isUnit_det_of_invertible variable {A B} theorem isUnit_of_left_inverse (h : B * A = 1) : IsUnit A := ⟨⟨A, B, mul_eq_one_comm.mp h, h⟩, rfl⟩ #align matrix.is_unit_of_left_inverse Matrix.isUnit_of_left_inverse theorem exists_left_inverse_iff_isUnit : (∃ B, B * A = 1) ↔ IsUnit A := ⟨fun ⟨_, h⟩ ↦ isUnit_of_left_inverse h, fun h ↦ have := h.invertible; ⟨⅟A, invOf_mul_self' A⟩⟩ theorem isUnit_of_right_inverse (h : A * B = 1) : IsUnit A := ⟨⟨A, B, h, mul_eq_one_comm.mp h⟩, rfl⟩ #align matrix.is_unit_of_right_inverse Matrix.isUnit_of_right_inverse theorem exists_right_inverse_iff_isUnit : (∃ B, A * B = 1) ↔ IsUnit A := ⟨fun ⟨_, h⟩ ↦ isUnit_of_right_inverse h, fun h ↦ have := h.invertible; ⟨⅟A, mul_invOf_self' A⟩⟩ theorem isUnit_det_of_left_inverse (h : B * A = 1) : IsUnit A.det := @isUnit_of_invertible _ _ _ (detInvertibleOfLeftInverse _ _ h) #align matrix.is_unit_det_of_left_inverse Matrix.isUnit_det_of_left_inverse theorem isUnit_det_of_right_inverse (h : A * B = 1) : IsUnit A.det := @isUnit_of_invertible _ _ _ (detInvertibleOfRightInverse _ _ h) #align matrix.is_unit_det_of_right_inverse Matrix.isUnit_det_of_right_inverse theorem det_ne_zero_of_left_inverse [Nontrivial α] (h : B * A = 1) : A.det ≠ 0 := (isUnit_det_of_left_inverse h).ne_zero #align matrix.det_ne_zero_of_left_inverse Matrix.det_ne_zero_of_left_inverse theorem det_ne_zero_of_right_inverse [Nontrivial α] (h : A * B = 1) : A.det ≠ 0 := (isUnit_det_of_right_inverse h).ne_zero #align matrix.det_ne_zero_of_right_inverse Matrix.det_ne_zero_of_right_inverse end Invertible section Inv variable [Fintype n] [DecidableEq n] [CommRing α] variable (A : Matrix n n α) (B : Matrix n n α) theorem isUnit_det_transpose (h : IsUnit A.det) : IsUnit Aᵀ.det := by rw [det_transpose] exact h #align matrix.is_unit_det_transpose Matrix.isUnit_det_transpose /-! ### A noncomputable `Inv` instance -/ /-- The inverse of a square matrix, when it is invertible (and zero otherwise). -/ noncomputable instance inv : Inv (Matrix n n α) := ⟨fun A => Ring.inverse A.det • A.adjugate⟩ theorem inv_def (A : Matrix n n α) : A⁻¹ = Ring.inverse A.det • A.adjugate := rfl #align matrix.inv_def Matrix.inv_def theorem nonsing_inv_apply_not_isUnit (h : ¬IsUnit A.det) : A⁻¹ = 0 := by rw [inv_def, Ring.inverse_non_unit _ h, zero_smul] #align matrix.nonsing_inv_apply_not_is_unit Matrix.nonsing_inv_apply_not_isUnit theorem nonsing_inv_apply (h : IsUnit A.det) : A⁻¹ = (↑h.unit⁻¹ : α) • A.adjugate := by rw [inv_def, ← Ring.inverse_unit h.unit, IsUnit.unit_spec] #align matrix.nonsing_inv_apply Matrix.nonsing_inv_apply /-- The nonsingular inverse is the same as `invOf` when `A` is invertible. -/ @[simp] theorem invOf_eq_nonsing_inv [Invertible A] : ⅟ A = A⁻¹ := by letI := detInvertibleOfInvertible A rw [inv_def, Ring.inverse_invertible, invOf_eq] #align matrix.inv_of_eq_nonsing_inv Matrix.invOf_eq_nonsing_inv /-- Coercing the result of `Units.instInv` is the same as coercing first and applying the nonsingular inverse. -/ @[simp, norm_cast] theorem coe_units_inv (A : (Matrix n n α)ˣ) : ↑A⁻¹ = (A⁻¹ : Matrix n n α) := by letI := A.invertible rw [← invOf_eq_nonsing_inv, invOf_units] #align matrix.coe_units_inv Matrix.coe_units_inv /-- The nonsingular inverse is the same as the general `Ring.inverse`. -/ theorem nonsing_inv_eq_ring_inverse : A⁻¹ = Ring.inverse A := by by_cases h_det : IsUnit A.det · cases (A.isUnit_iff_isUnit_det.mpr h_det).nonempty_invertible rw [← invOf_eq_nonsing_inv, Ring.inverse_invertible] · have h := mt A.isUnit_iff_isUnit_det.mp h_det rw [Ring.inverse_non_unit _ h, nonsing_inv_apply_not_isUnit A h_det] #align matrix.nonsing_inv_eq_ring_inverse Matrix.nonsing_inv_eq_ring_inverse
Mathlib/LinearAlgebra/Matrix/NonsingularInverse.lean
253
254
theorem transpose_nonsing_inv : A⁻¹ᵀ = Aᵀ⁻¹ := by
rw [inv_def, inv_def, transpose_smul, det_transpose, adjugate_transpose]
/- Copyright (c) 2019 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne -/ import Mathlib.Analysis.Convex.Jensen import Mathlib.Analysis.Convex.SpecificFunctions.Basic import Mathlib.Analysis.SpecialFunctions.Pow.NNReal import Mathlib.Data.Real.ConjExponents #align_import analysis.mean_inequalities from "leanprover-community/mathlib"@"8f9fea08977f7e450770933ee6abb20733b47c92" /-! # Mean value inequalities In this file we prove several inequalities for finite sums, including AM-GM inequality, Young's inequality, Hölder inequality, and Minkowski inequality. Versions for integrals of some of these inequalities are available in `MeasureTheory.MeanInequalities`. ## Main theorems ### AM-GM inequality: The inequality says that the geometric mean of a tuple of non-negative numbers is less than or equal to their arithmetic mean. We prove the weighted version of this inequality: if $w$ and $z$ are two non-negative vectors and $\sum_{i\in s} w_i=1$, then $$ \prod_{i\in s} z_i^{w_i} ≤ \sum_{i\in s} w_iz_i. $$ The classical version is a special case of this inequality for $w_i=\frac{1}{n}$. We prove a few versions of this inequality. Each of the following lemmas comes in two versions: a version for real-valued non-negative functions is in the `Real` namespace, and a version for `NNReal`-valued functions is in the `NNReal` namespace. - `geom_mean_le_arith_mean_weighted` : weighted version for functions on `Finset`s; - `geom_mean_le_arith_mean2_weighted` : weighted version for two numbers; - `geom_mean_le_arith_mean3_weighted` : weighted version for three numbers; - `geom_mean_le_arith_mean4_weighted` : weighted version for four numbers. ### Young's inequality Young's inequality says that for non-negative numbers `a`, `b`, `p`, `q` such that $\frac{1}{p}+\frac{1}{q}=1$ we have $$ ab ≤ \frac{a^p}{p} + \frac{b^q}{q}. $$ This inequality is a special case of the AM-GM inequality. It is then used to prove Hölder's inequality (see below). ### Hölder's inequality The inequality says that for two conjugate exponents `p` and `q` (i.e., for two positive numbers such that $\frac{1}{p}+\frac{1}{q}=1$) and any two non-negative vectors their inner product is less than or equal to the product of the $L_p$ norm of the first vector and the $L_q$ norm of the second vector: $$ \sum_{i\in s} a_ib_i ≤ \sqrt[p]{\sum_{i\in s} a_i^p}\sqrt[q]{\sum_{i\in s} b_i^q}. $$ We give versions of this result in `ℝ`, `ℝ≥0` and `ℝ≥0∞`. There are at least two short proofs of this inequality. In our proof we prenormalize both vectors, then apply Young's inequality to each $a_ib_i$. Another possible proof would be to deduce this inequality from the generalized mean inequality for well-chosen vectors and weights. ### Minkowski's inequality The inequality says that for `p ≥ 1` the function $$ \|a\|_p=\sqrt[p]{\sum_{i\in s} a_i^p} $$ satisfies the triangle inequality $\|a+b\|_p\le \|a\|_p+\|b\|_p$. We give versions of this result in `Real`, `ℝ≥0` and `ℝ≥0∞`. We deduce this inequality from Hölder's inequality. Namely, Hölder inequality implies that $\|a\|_p$ is the maximum of the inner product $\sum_{i\in s}a_ib_i$ over `b` such that $\|b\|_q\le 1$. Now Minkowski's inequality follows from the fact that the maximum value of the sum of two functions is less than or equal to the sum of the maximum values of the summands. ## TODO - each inequality `A ≤ B` should come with a theorem `A = B ↔ _`; one of the ways to prove them is to define `StrictConvexOn` functions. - generalized mean inequality with any `p ≤ q`, including negative numbers; - prove that the power mean tends to the geometric mean as the exponent tends to zero. -/ universe u v open scoped Classical open Finset NNReal ENNReal set_option linter.uppercaseLean3 false noncomputable section variable {ι : Type u} (s : Finset ι) section GeomMeanLEArithMean /-! ### AM-GM inequality -/ namespace Real /-- **AM-GM inequality**: The geometric mean is less than or equal to the arithmetic mean, weighted version for real-valued nonnegative functions. -/ theorem geom_mean_le_arith_mean_weighted (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i) (hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) : ∏ i ∈ s, z i ^ w i ≤ ∑ i ∈ s, w i * z i := by -- If some number `z i` equals zero and has non-zero weight, then LHS is 0 and RHS is nonnegative. by_cases A : ∃ i ∈ s, z i = 0 ∧ w i ≠ 0 · rcases A with ⟨i, his, hzi, hwi⟩ rw [prod_eq_zero his] · exact sum_nonneg fun j hj => mul_nonneg (hw j hj) (hz j hj) · rw [hzi] exact zero_rpow hwi -- If all numbers `z i` with non-zero weight are positive, then we apply Jensen's inequality -- for `exp` and numbers `log (z i)` with weights `w i`. · simp only [not_exists, not_and, Ne, Classical.not_not] at A have := convexOn_exp.map_sum_le hw hw' fun i _ => Set.mem_univ <| log (z i) simp only [exp_sum, (· ∘ ·), smul_eq_mul, mul_comm (w _) (log _)] at this convert this using 1 <;> [apply prod_congr rfl;apply sum_congr rfl] <;> intro i hi · cases' eq_or_lt_of_le (hz i hi) with hz hz · simp [A i hi hz.symm] · exact rpow_def_of_pos hz _ · cases' eq_or_lt_of_le (hz i hi) with hz hz · simp [A i hi hz.symm] · rw [exp_log hz] #align real.geom_mean_le_arith_mean_weighted Real.geom_mean_le_arith_mean_weighted /-- **AM-GM inequality**: The **geometric mean is less than or equal to the arithmetic mean. --/ theorem geom_mean_le_arith_mean {ι : Type*} (s : Finset ι) (w : ι → ℝ) (z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i) (hw' : 0 < ∑ i ∈ s, w i) (hz : ∀ i ∈ s, 0 ≤ z i) : (∏ i ∈ s, z i ^ w i) ^ (∑ i ∈ s, w i)⁻¹ ≤ (∑ i ∈ s, w i * z i) / (∑ i ∈ s, w i) := by convert geom_mean_le_arith_mean_weighted s (fun i => (w i) / ∑ i ∈ s, w i) z ?_ ?_ hz using 2 · rw [← finset_prod_rpow _ _ (fun i hi => rpow_nonneg (hz _ hi) _) _] refine Finset.prod_congr rfl (fun _ ih => ?_) rw [div_eq_mul_inv, rpow_mul (hz _ ih)] · simp_rw [div_eq_mul_inv, mul_assoc, mul_comm, ← mul_assoc, ← Finset.sum_mul, mul_comm] · exact fun _ hi => div_nonneg (hw _ hi) (le_of_lt hw') · simp_rw [div_eq_mul_inv, ← Finset.sum_mul] exact mul_inv_cancel (by linarith) theorem geom_mean_weighted_of_constant (w z : ι → ℝ) (x : ℝ) (hw : ∀ i ∈ s, 0 ≤ w i) (hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) (hx : ∀ i ∈ s, w i ≠ 0 → z i = x) : ∏ i ∈ s, z i ^ w i = x := calc ∏ i ∈ s, z i ^ w i = ∏ i ∈ s, x ^ w i := by refine prod_congr rfl fun i hi => ?_ rcases eq_or_ne (w i) 0 with h₀ | h₀ · rw [h₀, rpow_zero, rpow_zero] · rw [hx i hi h₀] _ = x := by rw [← rpow_sum_of_nonneg _ hw, hw', rpow_one] have : (∑ i ∈ s, w i) ≠ 0 := by rw [hw'] exact one_ne_zero obtain ⟨i, his, hi⟩ := exists_ne_zero_of_sum_ne_zero this rw [← hx i his hi] exact hz i his #align real.geom_mean_weighted_of_constant Real.geom_mean_weighted_of_constant theorem arith_mean_weighted_of_constant (w z : ι → ℝ) (x : ℝ) (hw' : ∑ i ∈ s, w i = 1) (hx : ∀ i ∈ s, w i ≠ 0 → z i = x) : ∑ i ∈ s, w i * z i = x := calc ∑ i ∈ s, w i * z i = ∑ i ∈ s, w i * x := by refine sum_congr rfl fun i hi => ?_ rcases eq_or_ne (w i) 0 with hwi | hwi · rw [hwi, zero_mul, zero_mul] · rw [hx i hi hwi] _ = x := by rw [← sum_mul, hw', one_mul] #align real.arith_mean_weighted_of_constant Real.arith_mean_weighted_of_constant theorem geom_mean_eq_arith_mean_weighted_of_constant (w z : ι → ℝ) (x : ℝ) (hw : ∀ i ∈ s, 0 ≤ w i) (hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) (hx : ∀ i ∈ s, w i ≠ 0 → z i = x) : ∏ i ∈ s, z i ^ w i = ∑ i ∈ s, w i * z i := by rw [geom_mean_weighted_of_constant, arith_mean_weighted_of_constant] <;> assumption #align real.geom_mean_eq_arith_mean_weighted_of_constant Real.geom_mean_eq_arith_mean_weighted_of_constant end Real namespace NNReal /-- **AM-GM inequality**: The geometric mean is less than or equal to the arithmetic mean, weighted version for `NNReal`-valued functions. -/ theorem geom_mean_le_arith_mean_weighted (w z : ι → ℝ≥0) (hw' : ∑ i ∈ s, w i = 1) : (∏ i ∈ s, z i ^ (w i : ℝ)) ≤ ∑ i ∈ s, w i * z i := mod_cast Real.geom_mean_le_arith_mean_weighted _ _ _ (fun i _ => (w i).coe_nonneg) (by assumption_mod_cast) fun i _ => (z i).coe_nonneg #align nnreal.geom_mean_le_arith_mean_weighted NNReal.geom_mean_le_arith_mean_weighted /-- **AM-GM inequality**: The geometric mean is less than or equal to the arithmetic mean, weighted version for two `NNReal` numbers. -/ theorem geom_mean_le_arith_mean2_weighted (w₁ w₂ p₁ p₂ : ℝ≥0) : w₁ + w₂ = 1 → p₁ ^ (w₁ : ℝ) * p₂ ^ (w₂ : ℝ) ≤ w₁ * p₁ + w₂ * p₂ := by simpa only [Fin.prod_univ_succ, Fin.sum_univ_succ, Finset.prod_empty, Finset.sum_empty, Finset.univ_eq_empty, Fin.cons_succ, Fin.cons_zero, add_zero, mul_one] using geom_mean_le_arith_mean_weighted univ ![w₁, w₂] ![p₁, p₂] #align nnreal.geom_mean_le_arith_mean2_weighted NNReal.geom_mean_le_arith_mean2_weighted theorem geom_mean_le_arith_mean3_weighted (w₁ w₂ w₃ p₁ p₂ p₃ : ℝ≥0) : w₁ + w₂ + w₃ = 1 → p₁ ^ (w₁ : ℝ) * p₂ ^ (w₂ : ℝ) * p₃ ^ (w₃ : ℝ) ≤ w₁ * p₁ + w₂ * p₂ + w₃ * p₃ := by simpa only [Fin.prod_univ_succ, Fin.sum_univ_succ, Finset.prod_empty, Finset.sum_empty, Finset.univ_eq_empty, Fin.cons_succ, Fin.cons_zero, add_zero, mul_one, ← add_assoc, mul_assoc] using geom_mean_le_arith_mean_weighted univ ![w₁, w₂, w₃] ![p₁, p₂, p₃] #align nnreal.geom_mean_le_arith_mean3_weighted NNReal.geom_mean_le_arith_mean3_weighted theorem geom_mean_le_arith_mean4_weighted (w₁ w₂ w₃ w₄ p₁ p₂ p₃ p₄ : ℝ≥0) : w₁ + w₂ + w₃ + w₄ = 1 → p₁ ^ (w₁ : ℝ) * p₂ ^ (w₂ : ℝ) * p₃ ^ (w₃ : ℝ) * p₄ ^ (w₄ : ℝ) ≤ w₁ * p₁ + w₂ * p₂ + w₃ * p₃ + w₄ * p₄ := by simpa only [Fin.prod_univ_succ, Fin.sum_univ_succ, Finset.prod_empty, Finset.sum_empty, Finset.univ_eq_empty, Fin.cons_succ, Fin.cons_zero, add_zero, mul_one, ← add_assoc, mul_assoc] using geom_mean_le_arith_mean_weighted univ ![w₁, w₂, w₃, w₄] ![p₁, p₂, p₃, p₄] #align nnreal.geom_mean_le_arith_mean4_weighted NNReal.geom_mean_le_arith_mean4_weighted end NNReal namespace Real theorem geom_mean_le_arith_mean2_weighted {w₁ w₂ p₁ p₂ : ℝ} (hw₁ : 0 ≤ w₁) (hw₂ : 0 ≤ w₂) (hp₁ : 0 ≤ p₁) (hp₂ : 0 ≤ p₂) (hw : w₁ + w₂ = 1) : p₁ ^ w₁ * p₂ ^ w₂ ≤ w₁ * p₁ + w₂ * p₂ := NNReal.geom_mean_le_arith_mean2_weighted ⟨w₁, hw₁⟩ ⟨w₂, hw₂⟩ ⟨p₁, hp₁⟩ ⟨p₂, hp₂⟩ <| NNReal.coe_inj.1 <| by assumption #align real.geom_mean_le_arith_mean2_weighted Real.geom_mean_le_arith_mean2_weighted theorem geom_mean_le_arith_mean3_weighted {w₁ w₂ w₃ p₁ p₂ p₃ : ℝ} (hw₁ : 0 ≤ w₁) (hw₂ : 0 ≤ w₂) (hw₃ : 0 ≤ w₃) (hp₁ : 0 ≤ p₁) (hp₂ : 0 ≤ p₂) (hp₃ : 0 ≤ p₃) (hw : w₁ + w₂ + w₃ = 1) : p₁ ^ w₁ * p₂ ^ w₂ * p₃ ^ w₃ ≤ w₁ * p₁ + w₂ * p₂ + w₃ * p₃ := NNReal.geom_mean_le_arith_mean3_weighted ⟨w₁, hw₁⟩ ⟨w₂, hw₂⟩ ⟨w₃, hw₃⟩ ⟨p₁, hp₁⟩ ⟨p₂, hp₂⟩ ⟨p₃, hp₃⟩ <| NNReal.coe_inj.1 hw #align real.geom_mean_le_arith_mean3_weighted Real.geom_mean_le_arith_mean3_weighted theorem geom_mean_le_arith_mean4_weighted {w₁ w₂ w₃ w₄ p₁ p₂ p₃ p₄ : ℝ} (hw₁ : 0 ≤ w₁) (hw₂ : 0 ≤ w₂) (hw₃ : 0 ≤ w₃) (hw₄ : 0 ≤ w₄) (hp₁ : 0 ≤ p₁) (hp₂ : 0 ≤ p₂) (hp₃ : 0 ≤ p₃) (hp₄ : 0 ≤ p₄) (hw : w₁ + w₂ + w₃ + w₄ = 1) : p₁ ^ w₁ * p₂ ^ w₂ * p₃ ^ w₃ * p₄ ^ w₄ ≤ w₁ * p₁ + w₂ * p₂ + w₃ * p₃ + w₄ * p₄ := NNReal.geom_mean_le_arith_mean4_weighted ⟨w₁, hw₁⟩ ⟨w₂, hw₂⟩ ⟨w₃, hw₃⟩ ⟨w₄, hw₄⟩ ⟨p₁, hp₁⟩ ⟨p₂, hp₂⟩ ⟨p₃, hp₃⟩ ⟨p₄, hp₄⟩ <| NNReal.coe_inj.1 <| by assumption #align real.geom_mean_le_arith_mean4_weighted Real.geom_mean_le_arith_mean4_weighted end Real end GeomMeanLEArithMean section Young /-! ### Young's inequality -/ namespace Real /-- **Young's inequality**, a version for nonnegative real numbers. -/ theorem young_inequality_of_nonneg {a b p q : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) (hpq : p.IsConjExponent q) : a * b ≤ a ^ p / p + b ^ q / q := by simpa [← rpow_mul, ha, hb, hpq.ne_zero, hpq.symm.ne_zero, _root_.div_eq_inv_mul] using geom_mean_le_arith_mean2_weighted hpq.inv_nonneg hpq.symm.inv_nonneg (rpow_nonneg ha p) (rpow_nonneg hb q) hpq.inv_add_inv_conj #align real.young_inequality_of_nonneg Real.young_inequality_of_nonneg /-- **Young's inequality**, a version for arbitrary real numbers. -/ theorem young_inequality (a b : ℝ) {p q : ℝ} (hpq : p.IsConjExponent q) : a * b ≤ |a| ^ p / p + |b| ^ q / q := calc a * b ≤ |a * b| := le_abs_self (a * b) _ = |a| * |b| := abs_mul a b _ ≤ |a| ^ p / p + |b| ^ q / q := Real.young_inequality_of_nonneg (abs_nonneg a) (abs_nonneg b) hpq #align real.young_inequality Real.young_inequality end Real namespace NNReal /-- **Young's inequality**, `ℝ≥0` version. We use `{p q : ℝ≥0}` in order to avoid constructing witnesses of `0 ≤ p` and `0 ≤ q` for the denominators. -/ theorem young_inequality (a b : ℝ≥0) {p q : ℝ≥0} (hpq : p.IsConjExponent q) : a * b ≤ a ^ (p : ℝ) / p + b ^ (q : ℝ) / q := Real.young_inequality_of_nonneg a.coe_nonneg b.coe_nonneg hpq.coe #align nnreal.young_inequality NNReal.young_inequality /-- **Young's inequality**, `ℝ≥0` version with real conjugate exponents. -/ theorem young_inequality_real (a b : ℝ≥0) {p q : ℝ} (hpq : p.IsConjExponent q) : a * b ≤ a ^ p / Real.toNNReal p + b ^ q / Real.toNNReal q := by simpa [Real.coe_toNNReal, hpq.nonneg, hpq.symm.nonneg] using young_inequality a b hpq.toNNReal #align nnreal.young_inequality_real NNReal.young_inequality_real end NNReal namespace ENNReal /-- **Young's inequality**, `ℝ≥0∞` version with real conjugate exponents. -/ theorem young_inequality (a b : ℝ≥0∞) {p q : ℝ} (hpq : p.IsConjExponent q) : a * b ≤ a ^ p / ENNReal.ofReal p + b ^ q / ENNReal.ofReal q := by by_cases h : a = ⊤ ∨ b = ⊤ · refine le_trans le_top (le_of_eq ?_) repeat rw [div_eq_mul_inv] cases' h with h h <;> rw [h] <;> simp [h, hpq.pos, hpq.symm.pos] push_neg at h -- if a ≠ ⊤ and b ≠ ⊤, use the nnreal version: nnreal.young_inequality_real rw [← coe_toNNReal h.left, ← coe_toNNReal h.right, ← coe_mul, coe_rpow_of_nonneg _ hpq.nonneg, coe_rpow_of_nonneg _ hpq.symm.nonneg, ENNReal.ofReal, ENNReal.ofReal, ← @coe_div (Real.toNNReal p) _ (by simp [hpq.pos]), ← @coe_div (Real.toNNReal q) _ (by simp [hpq.symm.pos]), ← coe_add, coe_le_coe] exact NNReal.young_inequality_real a.toNNReal b.toNNReal hpq #align ennreal.young_inequality ENNReal.young_inequality end ENNReal end Young section HoelderMinkowski /-! ### Hölder's and Minkowski's inequalities -/ namespace NNReal private theorem inner_le_Lp_mul_Lp_of_norm_le_one (f g : ι → ℝ≥0) {p q : ℝ} (hpq : p.IsConjExponent q) (hf : ∑ i ∈ s, f i ^ p ≤ 1) (hg : ∑ i ∈ s, g i ^ q ≤ 1) : ∑ i ∈ s, f i * g i ≤ 1 := by have hp_ne_zero : Real.toNNReal p ≠ 0 := (zero_lt_one.trans hpq.toNNReal.one_lt).ne.symm have hq_ne_zero : Real.toNNReal q ≠ 0 := (zero_lt_one.trans hpq.toNNReal.symm.one_lt).ne.symm calc ∑ i ∈ s, f i * g i ≤ ∑ i ∈ s, (f i ^ p / Real.toNNReal p + g i ^ q / Real.toNNReal q) := Finset.sum_le_sum fun i _ => young_inequality_real (f i) (g i) hpq _ = (∑ i ∈ s, f i ^ p) / Real.toNNReal p + (∑ i ∈ s, g i ^ q) / Real.toNNReal q := by rw [sum_add_distrib, sum_div, sum_div] _ ≤ 1 / Real.toNNReal p + 1 / Real.toNNReal q := by refine add_le_add ?_ ?_ · rwa [div_le_iff hp_ne_zero, div_mul_cancel₀ _ hp_ne_zero] · rwa [div_le_iff hq_ne_zero, div_mul_cancel₀ _ hq_ne_zero] _ = 1 := by simp_rw [one_div, hpq.toNNReal.inv_add_inv_conj] private theorem inner_le_Lp_mul_Lp_of_norm_eq_zero (f g : ι → ℝ≥0) {p q : ℝ} (hpq : p.IsConjExponent q) (hf : ∑ i ∈ s, f i ^ p = 0) : ∑ i ∈ s, f i * g i ≤ (∑ i ∈ s, f i ^ p) ^ (1 / p) * (∑ i ∈ s, g i ^ q) ^ (1 / q) := by simp only [hf, hpq.ne_zero, one_div, sum_eq_zero_iff, zero_rpow, zero_mul, inv_eq_zero, Ne, not_false_iff, le_zero_iff, mul_eq_zero] intro i his left rw [sum_eq_zero_iff] at hf exact (rpow_eq_zero_iff.mp (hf i his)).left /-- **Hölder inequality**: The scalar product of two functions is bounded by the product of their `L^p` and `L^q` norms when `p` and `q` are conjugate exponents. Version for sums over finite sets, with `ℝ≥0`-valued functions. -/ theorem inner_le_Lp_mul_Lq (f g : ι → ℝ≥0) {p q : ℝ} (hpq : p.IsConjExponent q) : ∑ i ∈ s, f i * g i ≤ (∑ i ∈ s, f i ^ p) ^ (1 / p) * (∑ i ∈ s, g i ^ q) ^ (1 / q) := by by_cases hF_zero : ∑ i ∈ s, f i ^ p = 0 · exact inner_le_Lp_mul_Lp_of_norm_eq_zero s f g hpq hF_zero by_cases hG_zero : ∑ i ∈ s, g i ^ q = 0 · calc ∑ i ∈ s, f i * g i = ∑ i ∈ s, g i * f i := by congr with i rw [mul_comm] _ ≤ (∑ i ∈ s, g i ^ q) ^ (1 / q) * (∑ i ∈ s, f i ^ p) ^ (1 / p) := (inner_le_Lp_mul_Lp_of_norm_eq_zero s g f hpq.symm hG_zero) _ = (∑ i ∈ s, f i ^ p) ^ (1 / p) * (∑ i ∈ s, g i ^ q) ^ (1 / q) := mul_comm _ _ let f' i := f i / (∑ i ∈ s, f i ^ p) ^ (1 / p) let g' i := g i / (∑ i ∈ s, g i ^ q) ^ (1 / q) suffices (∑ i ∈ s, f' i * g' i) ≤ 1 by simp_rw [f', g', div_mul_div_comm, ← sum_div] at this rwa [div_le_iff, one_mul] at this refine mul_ne_zero ?_ ?_ · rw [Ne, rpow_eq_zero_iff, not_and_or] exact Or.inl hF_zero · rw [Ne, rpow_eq_zero_iff, not_and_or] exact Or.inl hG_zero refine inner_le_Lp_mul_Lp_of_norm_le_one s f' g' hpq (le_of_eq ?_) (le_of_eq ?_) · simp_rw [f', div_rpow, ← sum_div, ← rpow_mul, one_div, inv_mul_cancel hpq.ne_zero, rpow_one, div_self hF_zero] · simp_rw [g', div_rpow, ← sum_div, ← rpow_mul, one_div, inv_mul_cancel hpq.symm.ne_zero, rpow_one, div_self hG_zero] #align nnreal.inner_le_Lp_mul_Lq NNReal.inner_le_Lp_mul_Lq /-- **Weighted Hölder inequality**. -/ lemma inner_le_weight_mul_Lp (s : Finset ι) {p : ℝ} (hp : 1 ≤ p) (w f : ι → ℝ≥0) : ∑ i ∈ s, w i * f i ≤ (∑ i ∈ s, w i) ^ (1 - p⁻¹) * (∑ i ∈ s, w i * f i ^ p) ^ p⁻¹ := by obtain rfl | hp := hp.eq_or_lt · simp calc _ = ∑ i ∈ s, w i ^ (1 - p⁻¹) * (w i ^ p⁻¹ * f i) := ?_ _ ≤ (∑ i ∈ s, (w i ^ (1 - p⁻¹)) ^ (1 - p⁻¹)⁻¹) ^ (1 / (1 - p⁻¹)⁻¹) * (∑ i ∈ s, (w i ^ p⁻¹ * f i) ^ p) ^ (1 / p) := inner_le_Lp_mul_Lq _ _ _ (.symm ⟨hp, by simp⟩) _ = _ := ?_ · congr with i rw [← mul_assoc, ← rpow_of_add_eq _ one_ne_zero, rpow_one] simp · have hp₀ : p ≠ 0 := by positivity have hp₁ : 1 - p⁻¹ ≠ 0 := by simp [sub_eq_zero, hp.ne'] simp [mul_rpow, div_inv_eq_mul, one_mul, one_div, hp₀, hp₁] /-- **Hölder inequality**: the scalar product of two functions is bounded by the product of their `L^p` and `L^q` norms when `p` and `q` are conjugate exponents. A version for `NNReal`-valued functions. For an alternative version, convenient if the infinite sums are already expressed as `p`-th powers, see `inner_le_Lp_mul_Lq_hasSum`. -/ theorem inner_le_Lp_mul_Lq_tsum {f g : ι → ℝ≥0} {p q : ℝ} (hpq : p.IsConjExponent q) (hf : Summable fun i => f i ^ p) (hg : Summable fun i => g i ^ q) : (Summable fun i => f i * g i) ∧ ∑' i, f i * g i ≤ (∑' i, f i ^ p) ^ (1 / p) * (∑' i, g i ^ q) ^ (1 / q) := by have H₁ : ∀ s : Finset ι, ∑ i ∈ s, f i * g i ≤ (∑' i, f i ^ p) ^ (1 / p) * (∑' i, g i ^ q) ^ (1 / q) := by intro s refine le_trans (inner_le_Lp_mul_Lq s f g hpq) (mul_le_mul ?_ ?_ bot_le bot_le) · rw [NNReal.rpow_le_rpow_iff (one_div_pos.mpr hpq.pos)] exact sum_le_tsum _ (fun _ _ => zero_le _) hf · rw [NNReal.rpow_le_rpow_iff (one_div_pos.mpr hpq.symm.pos)] exact sum_le_tsum _ (fun _ _ => zero_le _) hg have bdd : BddAbove (Set.range fun s => ∑ i ∈ s, f i * g i) := by refine ⟨(∑' i, f i ^ p) ^ (1 / p) * (∑' i, g i ^ q) ^ (1 / q), ?_⟩ rintro a ⟨s, rfl⟩ exact H₁ s have H₂ : Summable _ := (hasSum_of_isLUB _ (isLUB_ciSup bdd)).summable exact ⟨H₂, tsum_le_of_sum_le H₂ H₁⟩ #align nnreal.inner_le_Lp_mul_Lq_tsum NNReal.inner_le_Lp_mul_Lq_tsum theorem summable_mul_of_Lp_Lq {f g : ι → ℝ≥0} {p q : ℝ} (hpq : p.IsConjExponent q) (hf : Summable fun i => f i ^ p) (hg : Summable fun i => g i ^ q) : Summable fun i => f i * g i := (inner_le_Lp_mul_Lq_tsum hpq hf hg).1 #align nnreal.summable_mul_of_Lp_Lq NNReal.summable_mul_of_Lp_Lq theorem inner_le_Lp_mul_Lq_tsum' {f g : ι → ℝ≥0} {p q : ℝ} (hpq : p.IsConjExponent q) (hf : Summable fun i => f i ^ p) (hg : Summable fun i => g i ^ q) : ∑' i, f i * g i ≤ (∑' i, f i ^ p) ^ (1 / p) * (∑' i, g i ^ q) ^ (1 / q) := (inner_le_Lp_mul_Lq_tsum hpq hf hg).2 #align nnreal.inner_le_Lp_mul_Lq_tsum' NNReal.inner_le_Lp_mul_Lq_tsum' /-- **Hölder inequality**: the scalar product of two functions is bounded by the product of their `L^p` and `L^q` norms when `p` and `q` are conjugate exponents. A version for `NNReal`-valued functions. For an alternative version, convenient if the infinite sums are not already expressed as `p`-th powers, see `inner_le_Lp_mul_Lq_tsum`. -/ theorem inner_le_Lp_mul_Lq_hasSum {f g : ι → ℝ≥0} {A B : ℝ≥0} {p q : ℝ} (hpq : p.IsConjExponent q) (hf : HasSum (fun i => f i ^ p) (A ^ p)) (hg : HasSum (fun i => g i ^ q) (B ^ q)) : ∃ C, C ≤ A * B ∧ HasSum (fun i => f i * g i) C := by obtain ⟨H₁, H₂⟩ := inner_le_Lp_mul_Lq_tsum hpq hf.summable hg.summable have hA : A = (∑' i : ι, f i ^ p) ^ (1 / p) := by rw [hf.tsum_eq, rpow_inv_rpow_self hpq.ne_zero] have hB : B = (∑' i : ι, g i ^ q) ^ (1 / q) := by rw [hg.tsum_eq, rpow_inv_rpow_self hpq.symm.ne_zero] refine ⟨∑' i, f i * g i, ?_, ?_⟩ · simpa [hA, hB] using H₂ · simpa only [rpow_self_rpow_inv hpq.ne_zero] using H₁.hasSum #align nnreal.inner_le_Lp_mul_Lq_has_sum NNReal.inner_le_Lp_mul_Lq_hasSum /-- For `1 ≤ p`, the `p`-th power of the sum of `f i` is bounded above by a constant times the sum of the `p`-th powers of `f i`. Version for sums over finite sets, with `ℝ≥0`-valued functions. -/ theorem rpow_sum_le_const_mul_sum_rpow (f : ι → ℝ≥0) {p : ℝ} (hp : 1 ≤ p) : (∑ i ∈ s, f i) ^ p ≤ (card s : ℝ≥0) ^ (p - 1) * ∑ i ∈ s, f i ^ p := by cases' eq_or_lt_of_le hp with hp hp · simp [← hp] let q : ℝ := p / (p - 1) have hpq : p.IsConjExponent q := .conjExponent hp have hp₁ : 1 / p * p = 1 := one_div_mul_cancel hpq.ne_zero have hq : 1 / q * p = p - 1 := by rw [← hpq.div_conj_eq_sub_one] ring simpa only [NNReal.mul_rpow, ← NNReal.rpow_mul, hp₁, hq, one_mul, one_rpow, rpow_one, Pi.one_apply, sum_const, Nat.smul_one_eq_cast] using NNReal.rpow_le_rpow (inner_le_Lp_mul_Lq s 1 f hpq.symm) hpq.nonneg #align nnreal.rpow_sum_le_const_mul_sum_rpow NNReal.rpow_sum_le_const_mul_sum_rpow /-- The `L_p` seminorm of a vector `f` is the greatest value of the inner product `∑ i ∈ s, f i * g i` over functions `g` of `L_q` seminorm less than or equal to one. -/ theorem isGreatest_Lp (f : ι → ℝ≥0) {p q : ℝ} (hpq : p.IsConjExponent q) : IsGreatest ((fun g : ι → ℝ≥0 => ∑ i ∈ s, f i * g i) '' { g | ∑ i ∈ s, g i ^ q ≤ 1 }) ((∑ i ∈ s, f i ^ p) ^ (1 / p)) := by constructor · use fun i => f i ^ p / f i / (∑ i ∈ s, f i ^ p) ^ (1 / q) by_cases hf : ∑ i ∈ s, f i ^ p = 0 · simp [hf, hpq.ne_zero, hpq.symm.ne_zero] · have A : p + q - q ≠ 0 := by simp [hpq.ne_zero] have B : ∀ y : ℝ≥0, y * y ^ p / y = y ^ p := by refine fun y => mul_div_cancel_left_of_imp fun h => ?_ simp [h, hpq.ne_zero] simp only [Set.mem_setOf_eq, div_rpow, ← sum_div, ← rpow_mul, div_mul_cancel₀ _ hpq.symm.ne_zero, rpow_one, div_le_iff hf, one_mul, hpq.mul_eq_add, ← rpow_sub' _ A, add_sub_cancel_right, le_refl, true_and_iff, ← mul_div_assoc, B] rw [div_eq_iff, ← rpow_add hf, one_div, one_div, hpq.inv_add_inv_conj, rpow_one] simpa [hpq.symm.ne_zero] using hf · rintro _ ⟨g, hg, rfl⟩ apply le_trans (inner_le_Lp_mul_Lq s f g hpq) simpa only [mul_one] using mul_le_mul_left' (NNReal.rpow_le_one hg (le_of_lt hpq.symm.one_div_pos)) _ #align nnreal.is_greatest_Lp NNReal.isGreatest_Lp /-- **Minkowski inequality**: the `L_p` seminorm of the sum of two vectors is less than or equal to the sum of the `L_p`-seminorms of the summands. A version for `NNReal`-valued functions. -/ theorem Lp_add_le (f g : ι → ℝ≥0) {p : ℝ} (hp : 1 ≤ p) : (∑ i ∈ s, (f i + g i) ^ p) ^ (1 / p) ≤ (∑ i ∈ s, f i ^ p) ^ (1 / p) + (∑ i ∈ s, g i ^ p) ^ (1 / p) := by -- The result is trivial when `p = 1`, so we can assume `1 < p`. rcases eq_or_lt_of_le hp with (rfl | hp); · simp [Finset.sum_add_distrib] have hpq := Real.IsConjExponent.conjExponent hp have := isGreatest_Lp s (f + g) hpq simp only [Pi.add_apply, add_mul, sum_add_distrib] at this rcases this.1 with ⟨φ, hφ, H⟩ rw [← H] exact add_le_add ((isGreatest_Lp s f hpq).2 ⟨φ, hφ, rfl⟩) ((isGreatest_Lp s g hpq).2 ⟨φ, hφ, rfl⟩) #align nnreal.Lp_add_le NNReal.Lp_add_le /-- **Minkowski inequality**: the `L_p` seminorm of the infinite sum of two vectors is less than or equal to the infinite sum of the `L_p`-seminorms of the summands, if these infinite sums both exist. A version for `NNReal`-valued functions. For an alternative version, convenient if the infinite sums are already expressed as `p`-th powers, see `Lp_add_le_hasSum_of_nonneg`. -/ theorem Lp_add_le_tsum {f g : ι → ℝ≥0} {p : ℝ} (hp : 1 ≤ p) (hf : Summable fun i => f i ^ p) (hg : Summable fun i => g i ^ p) : (Summable fun i => (f i + g i) ^ p) ∧ (∑' i, (f i + g i) ^ p) ^ (1 / p) ≤ (∑' i, f i ^ p) ^ (1 / p) + (∑' i, g i ^ p) ^ (1 / p) := by have pos : 0 < p := lt_of_lt_of_le zero_lt_one hp have H₁ : ∀ s : Finset ι, (∑ i ∈ s, (f i + g i) ^ p) ≤ ((∑' i, f i ^ p) ^ (1 / p) + (∑' i, g i ^ p) ^ (1 / p)) ^ p := by intro s rw [← NNReal.rpow_one_div_le_iff pos] refine le_trans (Lp_add_le s f g hp) (add_le_add ?_ ?_) <;> rw [NNReal.rpow_le_rpow_iff (one_div_pos.mpr pos)] <;> refine sum_le_tsum _ (fun _ _ => zero_le _) ?_ exacts [hf, hg] have bdd : BddAbove (Set.range fun s => ∑ i ∈ s, (f i + g i) ^ p) := by refine ⟨((∑' i, f i ^ p) ^ (1 / p) + (∑' i, g i ^ p) ^ (1 / p)) ^ p, ?_⟩ rintro a ⟨s, rfl⟩ exact H₁ s have H₂ : Summable _ := (hasSum_of_isLUB _ (isLUB_ciSup bdd)).summable refine ⟨H₂, ?_⟩ rw [NNReal.rpow_one_div_le_iff pos] exact tsum_le_of_sum_le H₂ H₁ #align nnreal.Lp_add_le_tsum NNReal.Lp_add_le_tsum theorem summable_Lp_add {f g : ι → ℝ≥0} {p : ℝ} (hp : 1 ≤ p) (hf : Summable fun i => f i ^ p) (hg : Summable fun i => g i ^ p) : Summable fun i => (f i + g i) ^ p := (Lp_add_le_tsum hp hf hg).1 #align nnreal.summable_Lp_add NNReal.summable_Lp_add theorem Lp_add_le_tsum' {f g : ι → ℝ≥0} {p : ℝ} (hp : 1 ≤ p) (hf : Summable fun i => f i ^ p) (hg : Summable fun i => g i ^ p) : (∑' i, (f i + g i) ^ p) ^ (1 / p) ≤ (∑' i, f i ^ p) ^ (1 / p) + (∑' i, g i ^ p) ^ (1 / p) := (Lp_add_le_tsum hp hf hg).2 #align nnreal.Lp_add_le_tsum' NNReal.Lp_add_le_tsum' /-- **Minkowski inequality**: the `L_p` seminorm of the infinite sum of two vectors is less than or equal to the infinite sum of the `L_p`-seminorms of the summands, if these infinite sums both exist. A version for `NNReal`-valued functions. For an alternative version, convenient if the infinite sums are not already expressed as `p`-th powers, see `Lp_add_le_tsum_of_nonneg`. -/ theorem Lp_add_le_hasSum {f g : ι → ℝ≥0} {A B : ℝ≥0} {p : ℝ} (hp : 1 ≤ p) (hf : HasSum (fun i => f i ^ p) (A ^ p)) (hg : HasSum (fun i => g i ^ p) (B ^ p)) : ∃ C, C ≤ A + B ∧ HasSum (fun i => (f i + g i) ^ p) (C ^ p) := by have hp' : p ≠ 0 := (lt_of_lt_of_le zero_lt_one hp).ne' obtain ⟨H₁, H₂⟩ := Lp_add_le_tsum hp hf.summable hg.summable have hA : A = (∑' i : ι, f i ^ p) ^ (1 / p) := by rw [hf.tsum_eq, rpow_inv_rpow_self hp'] have hB : B = (∑' i : ι, g i ^ p) ^ (1 / p) := by rw [hg.tsum_eq, rpow_inv_rpow_self hp'] refine ⟨(∑' i, (f i + g i) ^ p) ^ (1 / p), ?_, ?_⟩ · simpa [hA, hB] using H₂ · simpa only [rpow_self_rpow_inv hp'] using H₁.hasSum #align nnreal.Lp_add_le_has_sum NNReal.Lp_add_le_hasSum end NNReal namespace Real variable (f g : ι → ℝ) {p q : ℝ} /-- **Hölder inequality**: the scalar product of two functions is bounded by the product of their `L^p` and `L^q` norms when `p` and `q` are conjugate exponents. Version for sums over finite sets, with real-valued functions. -/ theorem inner_le_Lp_mul_Lq (hpq : IsConjExponent p q) : ∑ i ∈ s, f i * g i ≤ (∑ i ∈ s, |f i| ^ p) ^ (1 / p) * (∑ i ∈ s, |g i| ^ q) ^ (1 / q) := by have := NNReal.coe_le_coe.2 (NNReal.inner_le_Lp_mul_Lq s (fun i => ⟨_, abs_nonneg (f i)⟩) (fun i => ⟨_, abs_nonneg (g i)⟩) hpq) push_cast at this refine le_trans (sum_le_sum fun i _ => ?_) this simp only [← abs_mul, le_abs_self] #align real.inner_le_Lp_mul_Lq Real.inner_le_Lp_mul_Lq /-- For `1 ≤ p`, the `p`-th power of the sum of `f i` is bounded above by a constant times the sum of the `p`-th powers of `f i`. Version for sums over finite sets, with `ℝ`-valued functions. -/ theorem rpow_sum_le_const_mul_sum_rpow (hp : 1 ≤ p) : (∑ i ∈ s, |f i|) ^ p ≤ (card s : ℝ) ^ (p - 1) * ∑ i ∈ s, |f i| ^ p := by have := NNReal.coe_le_coe.2 (NNReal.rpow_sum_le_const_mul_sum_rpow s (fun i => ⟨_, abs_nonneg (f i)⟩) hp) push_cast at this exact this #align real.rpow_sum_le_const_mul_sum_rpow Real.rpow_sum_le_const_mul_sum_rpow -- for some reason `exact_mod_cast` can't replace this argument /-- **Minkowski inequality**: the `L_p` seminorm of the sum of two vectors is less than or equal to the sum of the `L_p`-seminorms of the summands. A version for `Real`-valued functions. -/ theorem Lp_add_le (hp : 1 ≤ p) : (∑ i ∈ s, |f i + g i| ^ p) ^ (1 / p) ≤ (∑ i ∈ s, |f i| ^ p) ^ (1 / p) + (∑ i ∈ s, |g i| ^ p) ^ (1 / p) := by have := NNReal.coe_le_coe.2 (NNReal.Lp_add_le s (fun i => ⟨_, abs_nonneg (f i)⟩) (fun i => ⟨_, abs_nonneg (g i)⟩) hp) push_cast at this refine le_trans (rpow_le_rpow ?_ (sum_le_sum fun i _ => ?_) ?_) this <;> simp [sum_nonneg, rpow_nonneg, abs_nonneg, le_trans zero_le_one hp, abs_add, rpow_le_rpow] #align real.Lp_add_le Real.Lp_add_le variable {f g} /-- **Hölder inequality**: the scalar product of two functions is bounded by the product of their `L^p` and `L^q` norms when `p` and `q` are conjugate exponents. Version for sums over finite sets, with real-valued nonnegative functions. -/ theorem inner_le_Lp_mul_Lq_of_nonneg (hpq : IsConjExponent p q) (hf : ∀ i ∈ s, 0 ≤ f i) (hg : ∀ i ∈ s, 0 ≤ g i) : ∑ i ∈ s, f i * g i ≤ (∑ i ∈ s, f i ^ p) ^ (1 / p) * (∑ i ∈ s, g i ^ q) ^ (1 / q) := by convert inner_le_Lp_mul_Lq s f g hpq using 3 <;> apply sum_congr rfl <;> intro i hi <;> simp only [abs_of_nonneg, hf i hi, hg i hi] #align real.inner_le_Lp_mul_Lq_of_nonneg Real.inner_le_Lp_mul_Lq_of_nonneg /-- **Weighted Hölder inequality**. -/ lemma inner_le_weight_mul_Lp_of_nonneg (s : Finset ι) {p : ℝ} (hp : 1 ≤ p) (w f : ι → ℝ) (hw : ∀ i, 0 ≤ w i) (hf : ∀ i, 0 ≤ f i) : ∑ i ∈ s, w i * f i ≤ (∑ i ∈ s, w i) ^ (1 - p⁻¹) * (∑ i ∈ s, w i * f i ^ p) ^ p⁻¹ := by lift w to ι → ℝ≥0 using hw lift f to ι → ℝ≥0 using hf beta_reduce at * norm_cast at * exact NNReal.inner_le_weight_mul_Lp _ hp _ _ /-- **Hölder inequality**: the scalar product of two functions is bounded by the product of their `L^p` and `L^q` norms when `p` and `q` are conjugate exponents. A version for `ℝ`-valued functions. For an alternative version, convenient if the infinite sums are already expressed as `p`-th powers, see `inner_le_Lp_mul_Lq_hasSum_of_nonneg`. -/ theorem inner_le_Lp_mul_Lq_tsum_of_nonneg (hpq : p.IsConjExponent q) (hf : ∀ i, 0 ≤ f i) (hg : ∀ i, 0 ≤ g i) (hf_sum : Summable fun i => f i ^ p) (hg_sum : Summable fun i => g i ^ q) : (Summable fun i => f i * g i) ∧ ∑' i, f i * g i ≤ (∑' i, f i ^ p) ^ (1 / p) * (∑' i, g i ^ q) ^ (1 / q) := by lift f to ι → ℝ≥0 using hf lift g to ι → ℝ≥0 using hg -- After leanprover/lean4#2734, `norm_cast` needs help with beta reduction. beta_reduce at * norm_cast at * exact NNReal.inner_le_Lp_mul_Lq_tsum hpq hf_sum hg_sum #align real.inner_le_Lp_mul_Lq_tsum_of_nonneg Real.inner_le_Lp_mul_Lq_tsum_of_nonneg theorem summable_mul_of_Lp_Lq_of_nonneg (hpq : p.IsConjExponent q) (hf : ∀ i, 0 ≤ f i) (hg : ∀ i, 0 ≤ g i) (hf_sum : Summable fun i => f i ^ p) (hg_sum : Summable fun i => g i ^ q) : Summable fun i => f i * g i := (inner_le_Lp_mul_Lq_tsum_of_nonneg hpq hf hg hf_sum hg_sum).1 #align real.summable_mul_of_Lp_Lq_of_nonneg Real.summable_mul_of_Lp_Lq_of_nonneg theorem inner_le_Lp_mul_Lq_tsum_of_nonneg' (hpq : p.IsConjExponent q) (hf : ∀ i, 0 ≤ f i) (hg : ∀ i, 0 ≤ g i) (hf_sum : Summable fun i => f i ^ p) (hg_sum : Summable fun i => g i ^ q) : ∑' i, f i * g i ≤ (∑' i, f i ^ p) ^ (1 / p) * (∑' i, g i ^ q) ^ (1 / q) := (inner_le_Lp_mul_Lq_tsum_of_nonneg hpq hf hg hf_sum hg_sum).2 #align real.inner_le_Lp_mul_Lq_tsum_of_nonneg' Real.inner_le_Lp_mul_Lq_tsum_of_nonneg' /-- **Hölder inequality**: the scalar product of two functions is bounded by the product of their `L^p` and `L^q` norms when `p` and `q` are conjugate exponents. A version for `NNReal`-valued functions. For an alternative version, convenient if the infinite sums are not already expressed as `p`-th powers, see `inner_le_Lp_mul_Lq_tsum_of_nonneg`. -/ theorem inner_le_Lp_mul_Lq_hasSum_of_nonneg (hpq : p.IsConjExponent q) {A B : ℝ} (hA : 0 ≤ A) (hB : 0 ≤ B) (hf : ∀ i, 0 ≤ f i) (hg : ∀ i, 0 ≤ g i) (hf_sum : HasSum (fun i => f i ^ p) (A ^ p)) (hg_sum : HasSum (fun i => g i ^ q) (B ^ q)) : ∃ C : ℝ, 0 ≤ C ∧ C ≤ A * B ∧ HasSum (fun i => f i * g i) C := by lift f to ι → ℝ≥0 using hf lift g to ι → ℝ≥0 using hg lift A to ℝ≥0 using hA lift B to ℝ≥0 using hB -- After leanprover/lean4#2734, `norm_cast` needs help with beta reduction. beta_reduce at * norm_cast at hf_sum hg_sum obtain ⟨C, hC, H⟩ := NNReal.inner_le_Lp_mul_Lq_hasSum hpq hf_sum hg_sum refine ⟨C, C.prop, hC, ?_⟩ norm_cast #align real.inner_le_Lp_mul_Lq_has_sum_of_nonneg Real.inner_le_Lp_mul_Lq_hasSum_of_nonneg /-- For `1 ≤ p`, the `p`-th power of the sum of `f i` is bounded above by a constant times the sum of the `p`-th powers of `f i`. Version for sums over finite sets, with nonnegative `ℝ`-valued functions. -/ theorem rpow_sum_le_const_mul_sum_rpow_of_nonneg (hp : 1 ≤ p) (hf : ∀ i ∈ s, 0 ≤ f i) : (∑ i ∈ s, f i) ^ p ≤ (card s : ℝ) ^ (p - 1) * ∑ i ∈ s, f i ^ p := by convert rpow_sum_le_const_mul_sum_rpow s f hp using 2 <;> apply sum_congr rfl <;> intro i hi <;> simp only [abs_of_nonneg, hf i hi] #align real.rpow_sum_le_const_mul_sum_rpow_of_nonneg Real.rpow_sum_le_const_mul_sum_rpow_of_nonneg /-- **Minkowski inequality**: the `L_p` seminorm of the sum of two vectors is less than or equal to the sum of the `L_p`-seminorms of the summands. A version for `ℝ`-valued nonnegative functions. -/ theorem Lp_add_le_of_nonneg (hp : 1 ≤ p) (hf : ∀ i ∈ s, 0 ≤ f i) (hg : ∀ i ∈ s, 0 ≤ g i) : (∑ i ∈ s, (f i + g i) ^ p) ^ (1 / p) ≤ (∑ i ∈ s, f i ^ p) ^ (1 / p) + (∑ i ∈ s, g i ^ p) ^ (1 / p) := by convert Lp_add_le s f g hp using 2 <;> [skip;congr 1;congr 1] <;> apply sum_congr rfl <;> intro i hi <;> simp only [abs_of_nonneg, hf i hi, hg i hi, add_nonneg] #align real.Lp_add_le_of_nonneg Real.Lp_add_le_of_nonneg /-- **Minkowski inequality**: the `L_p` seminorm of the infinite sum of two vectors is less than or equal to the infinite sum of the `L_p`-seminorms of the summands, if these infinite sums both exist. A version for `ℝ`-valued functions. For an alternative version, convenient if the infinite sums are already expressed as `p`-th powers, see `Lp_add_le_hasSum_of_nonneg`. -/ theorem Lp_add_le_tsum_of_nonneg (hp : 1 ≤ p) (hf : ∀ i, 0 ≤ f i) (hg : ∀ i, 0 ≤ g i) (hf_sum : Summable fun i => f i ^ p) (hg_sum : Summable fun i => g i ^ p) : (Summable fun i => (f i + g i) ^ p) ∧ (∑' i, (f i + g i) ^ p) ^ (1 / p) ≤ (∑' i, f i ^ p) ^ (1 / p) + (∑' i, g i ^ p) ^ (1 / p) := by lift f to ι → ℝ≥0 using hf lift g to ι → ℝ≥0 using hg -- After leanprover/lean4#2734, `norm_cast` needs help with beta reduction. beta_reduce at * norm_cast0 at * exact NNReal.Lp_add_le_tsum hp hf_sum hg_sum #align real.Lp_add_le_tsum_of_nonneg Real.Lp_add_le_tsum_of_nonneg theorem summable_Lp_add_of_nonneg (hp : 1 ≤ p) (hf : ∀ i, 0 ≤ f i) (hg : ∀ i, 0 ≤ g i) (hf_sum : Summable fun i => f i ^ p) (hg_sum : Summable fun i => g i ^ p) : Summable fun i => (f i + g i) ^ p := (Lp_add_le_tsum_of_nonneg hp hf hg hf_sum hg_sum).1 #align real.summable_Lp_add_of_nonneg Real.summable_Lp_add_of_nonneg theorem Lp_add_le_tsum_of_nonneg' (hp : 1 ≤ p) (hf : ∀ i, 0 ≤ f i) (hg : ∀ i, 0 ≤ g i) (hf_sum : Summable fun i => f i ^ p) (hg_sum : Summable fun i => g i ^ p) : (∑' i, (f i + g i) ^ p) ^ (1 / p) ≤ (∑' i, f i ^ p) ^ (1 / p) + (∑' i, g i ^ p) ^ (1 / p) := (Lp_add_le_tsum_of_nonneg hp hf hg hf_sum hg_sum).2 #align real.Lp_add_le_tsum_of_nonneg' Real.Lp_add_le_tsum_of_nonneg' /-- **Minkowski inequality**: the `L_p` seminorm of the infinite sum of two vectors is less than or equal to the infinite sum of the `L_p`-seminorms of the summands, if these infinite sums both exist. A version for `ℝ`-valued functions. For an alternative version, convenient if the infinite sums are not already expressed as `p`-th powers, see `Lp_add_le_tsum_of_nonneg`. -/ theorem Lp_add_le_hasSum_of_nonneg (hp : 1 ≤ p) (hf : ∀ i, 0 ≤ f i) (hg : ∀ i, 0 ≤ g i) {A B : ℝ} (hA : 0 ≤ A) (hB : 0 ≤ B) (hfA : HasSum (fun i => f i ^ p) (A ^ p)) (hgB : HasSum (fun i => g i ^ p) (B ^ p)) : ∃ C, 0 ≤ C ∧ C ≤ A + B ∧ HasSum (fun i => (f i + g i) ^ p) (C ^ p) := by lift f to ι → ℝ≥0 using hf lift g to ι → ℝ≥0 using hg lift A to ℝ≥0 using hA lift B to ℝ≥0 using hB -- After leanprover/lean4#2734, `norm_cast` needs help with beta reduction. beta_reduce at hfA hgB norm_cast at hfA hgB obtain ⟨C, hC₁, hC₂⟩ := NNReal.Lp_add_le_hasSum hp hfA hgB use C -- After leanprover/lean4#2734, `norm_cast` needs help with beta reduction. beta_reduce norm_cast exact ⟨zero_le _, hC₁, hC₂⟩ #align real.Lp_add_le_has_sum_of_nonneg Real.Lp_add_le_hasSum_of_nonneg end Real namespace ENNReal variable (f g : ι → ℝ≥0∞) {p q : ℝ} /-- **Hölder inequality**: the scalar product of two functions is bounded by the product of their `L^p` and `L^q` norms when `p` and `q` are conjugate exponents. Version for sums over finite sets, with `ℝ≥0∞`-valued functions. -/ theorem inner_le_Lp_mul_Lq (hpq : p.IsConjExponent q) : ∑ i ∈ s, f i * g i ≤ (∑ i ∈ s, f i ^ p) ^ (1 / p) * (∑ i ∈ s, g i ^ q) ^ (1 / q) := by by_cases H : (∑ i ∈ s, f i ^ p) ^ (1 / p) = 0 ∨ (∑ i ∈ s, g i ^ q) ^ (1 / q) = 0 · replace H : (∀ i ∈ s, f i = 0) ∨ ∀ i ∈ s, g i = 0 := by simpa [ENNReal.rpow_eq_zero_iff, hpq.pos, hpq.symm.pos, asymm hpq.pos, asymm hpq.symm.pos, sum_eq_zero_iff_of_nonneg] using H have : ∀ i ∈ s, f i * g i = 0 := fun i hi => by cases' H with H H <;> simp [H i hi] simp [sum_eq_zero this] push_neg at H by_cases H' : (∑ i ∈ s, f i ^ p) ^ (1 / p) = ⊤ ∨ (∑ i ∈ s, g i ^ q) ^ (1 / q) = ⊤ · cases' H' with H' H' <;> simp [H', -one_div, -sum_eq_zero_iff, -rpow_eq_zero_iff, H] replace H' : (∀ i ∈ s, f i ≠ ⊤) ∧ ∀ i ∈ s, g i ≠ ⊤ := by simpa [ENNReal.rpow_eq_top_iff, asymm hpq.pos, asymm hpq.symm.pos, hpq.pos, hpq.symm.pos, ENNReal.sum_eq_top_iff, not_or] using H' have := ENNReal.coe_le_coe.2 (@NNReal.inner_le_Lp_mul_Lq _ s (fun i => ENNReal.toNNReal (f i)) (fun i => ENNReal.toNNReal (g i)) _ _ hpq) simp [← ENNReal.coe_rpow_of_nonneg, le_of_lt hpq.pos, le_of_lt hpq.one_div_pos, le_of_lt hpq.symm.pos, le_of_lt hpq.symm.one_div_pos] at this convert this using 1 <;> [skip; congr 2] <;> [skip; skip; simp; skip; simp] <;> · refine Finset.sum_congr rfl fun i hi => ?_ simp [H'.1 i hi, H'.2 i hi, -WithZero.coe_mul] #align ennreal.inner_le_Lp_mul_Lq ENNReal.inner_le_Lp_mul_Lq /-- **Weighted Hölder inequality**. -/ lemma inner_le_weight_mul_Lp_of_nonneg (s : Finset ι) {p : ℝ} (hp : 1 ≤ p) (w f : ι → ℝ≥0∞) : ∑ i ∈ s, w i * f i ≤ (∑ i ∈ s, w i) ^ (1 - p⁻¹) * (∑ i ∈ s, w i * f i ^ p) ^ p⁻¹ := by obtain rfl | hp := hp.eq_or_lt · simp have hp₀ : 0 < p := by positivity have hp₁ : p⁻¹ < 1 := inv_lt_one hp by_cases H : (∑ i ∈ s, w i) ^ (1 - p⁻¹) = 0 ∨ (∑ i ∈ s, w i * f i ^ p) ^ p⁻¹ = 0 · replace H : (∀ i ∈ s, w i = 0) ∨ ∀ i ∈ s, w i = 0 ∨ f i = 0 := by simpa [hp₀, hp₁, hp₀.not_lt, hp₁.not_lt, sum_eq_zero_iff_of_nonneg] using H have (i) (hi : i ∈ s) : w i * f i = 0 := by cases' H with H H <;> simp [H i hi] simp [sum_eq_zero this] push_neg at H by_cases H' : (∑ i ∈ s, w i) ^ (1 - p⁻¹) = ⊤ ∨ (∑ i ∈ s, w i * f i ^ p) ^ p⁻¹ = ⊤ · cases' H' with H' H' <;> simp [H', -one_div, -sum_eq_zero_iff, -rpow_eq_zero_iff, H] replace H' : (∀ i ∈ s, w i ≠ ⊤) ∧ ∀ i ∈ s, w i * f i ^ p ≠ ⊤ := by simpa [rpow_eq_top_iff,hp₀, hp₁, hp₀.not_lt, hp₁.not_lt, sum_eq_top_iff, not_or] using H' have := coe_le_coe.2 $ NNReal.inner_le_weight_mul_Lp s hp.le (fun i ↦ ENNReal.toNNReal (w i)) fun i ↦ ENNReal.toNNReal (f i) rw [coe_mul] at this simp_rw [← coe_rpow_of_nonneg _ $ inv_nonneg.2 hp₀.le, coe_finset_sum, ENNReal.toNNReal_rpow, ← ENNReal.toNNReal_mul, sum_congr rfl fun i hi ↦ coe_toNNReal (H'.2 i hi)] at this simp [← ENNReal.coe_rpow_of_nonneg, hp₀.le, hp₁.le] at this convert this using 2 with i hi · obtain hw | hw := eq_or_ne (w i) 0 · simp [hw] rw [coe_toNNReal (H'.1 _ hi), coe_toNNReal] simpa [mul_eq_top, hw, hp₀, hp₀.not_lt, H'.1 _ hi] using H'.2 _ hi · convert rfl with i hi exact coe_toNNReal (H'.1 _ hi) /-- For `1 ≤ p`, the `p`-th power of the sum of `f i` is bounded above by a constant times the sum of the `p`-th powers of `f i`. Version for sums over finite sets, with `ℝ≥0∞`-valued functions. -/
Mathlib/Analysis/MeanInequalities.lean
826
838
theorem rpow_sum_le_const_mul_sum_rpow (hp : 1 ≤ p) : (∑ i ∈ s, f i) ^ p ≤ (card s : ℝ≥0∞) ^ (p - 1) * ∑ i ∈ s, f i ^ p := by
cases' eq_or_lt_of_le hp with hp hp · simp [← hp] let q : ℝ := p / (p - 1) have hpq : p.IsConjExponent q := .conjExponent hp have hp₁ : 1 / p * p = 1 := one_div_mul_cancel hpq.ne_zero have hq : 1 / q * p = p - 1 := by rw [← hpq.div_conj_eq_sub_one] ring simpa only [ENNReal.mul_rpow_of_nonneg _ _ hpq.nonneg, ← ENNReal.rpow_mul, hp₁, hq, coe_one, one_mul, one_rpow, rpow_one, Pi.one_apply, sum_const, Nat.smul_one_eq_cast] using ENNReal.rpow_le_rpow (inner_le_Lp_mul_Lq s 1 f hpq.symm) hpq.nonneg