Context
stringlengths
227
76.5k
target
stringlengths
0
11.6k
file_name
stringlengths
21
79
start
int64
14
3.67k
end
int64
16
3.69k
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad -/ import Mathlib.Data.Int.Bitwise import Mathlib.Data.Int.Order.Lemmas import Mathlib.Data.Set.Function import Mathlib.Data.Set.Monotone import Mathlib.Order.Interval.Set.Defs /-! # Miscellaneous lemmas about the integers This file contains lemmas about integers, which require further imports than `Data.Int.Basic` or `Data.Int.Order`. -/ open Nat namespace Int theorem le_natCast_sub (m n : β„•) : (m - n : β„€) ≀ ↑(m - n : β„•) := by by_cases h : m β‰₯ n Β· exact le_of_eq (Int.ofNat_sub h).symm Β· simp [le_of_not_ge h, ofNat_le] /-! ### `succ` and `pred` -/ theorem succ_natCast_pos (n : β„•) : 0 < (n : β„€) + 1 := lt_add_one_iff.mpr (by simp) /-! ### `natAbs` -/ theorem natAbs_eq_iff_sq_eq {a b : β„€} : a.natAbs = b.natAbs ↔ a ^ 2 = b ^ 2 := by rw [sq, sq] exact natAbs_eq_iff_mul_self_eq theorem natAbs_lt_iff_sq_lt {a b : β„€} : a.natAbs < b.natAbs ↔ a ^ 2 < b ^ 2 := by rw [sq, sq] exact natAbs_lt_iff_mul_self_lt theorem natAbs_le_iff_sq_le {a b : β„€} : a.natAbs ≀ b.natAbs ↔ a ^ 2 ≀ b ^ 2 := by rw [sq, sq] exact natAbs_le_iff_mul_self_le theorem natAbs_inj_of_nonneg_of_nonneg {a b : β„€} (ha : 0 ≀ a) (hb : 0 ≀ b) : natAbs a = natAbs b ↔ a = b := by rw [← sq_eq_sqβ‚€ ha hb, ← natAbs_eq_iff_sq_eq] theorem natAbs_inj_of_nonpos_of_nonpos {a b : β„€} (ha : a ≀ 0) (hb : b ≀ 0) : natAbs a = natAbs b ↔ a = b := by simpa only [Int.natAbs_neg, neg_inj] using natAbs_inj_of_nonneg_of_nonneg (neg_nonneg_of_nonpos ha) (neg_nonneg_of_nonpos hb) theorem natAbs_inj_of_nonneg_of_nonpos {a b : β„€} (ha : 0 ≀ a) (hb : b ≀ 0) : natAbs a = natAbs b ↔ a = -b := by simpa only [Int.natAbs_neg] using natAbs_inj_of_nonneg_of_nonneg ha (neg_nonneg_of_nonpos hb) theorem natAbs_inj_of_nonpos_of_nonneg {a b : β„€} (ha : a ≀ 0) (hb : 0 ≀ b) : natAbs a = natAbs b ↔ -a = b := by simpa only [Int.natAbs_neg] using natAbs_inj_of_nonneg_of_nonneg (neg_nonneg_of_nonpos ha) hb /-- A specialization of `abs_sub_le_of_nonneg_of_le` for working with the signed subtraction of natural numbers. -/ theorem natAbs_coe_sub_coe_le_of_le {a b n : β„•} (a_le_n : a ≀ n) (b_le_n : b ≀ n) : natAbs (a - b : β„€) ≀ n := by rw [← Nat.cast_le (Ξ± := β„€), natCast_natAbs] exact abs_sub_le_of_nonneg_of_le (ofNat_nonneg a) (ofNat_le.mpr a_le_n) (ofNat_nonneg b) (ofNat_le.mpr b_le_n) /-- A specialization of `abs_sub_lt_of_nonneg_of_lt` for working with the signed subtraction of natural numbers. -/ theorem natAbs_coe_sub_coe_lt_of_lt {a b n : β„•} (a_lt_n : a < n) (b_lt_n : b < n) : natAbs (a - b : β„€) < n := by rw [← Nat.cast_lt (Ξ± := β„€), natCast_natAbs] exact abs_sub_lt_of_nonneg_of_lt (ofNat_nonneg a) (ofNat_lt.mpr a_lt_n) (ofNat_nonneg b) (ofNat_lt.mpr b_lt_n) section Intervals open Set theorem strictMonoOn_natAbs : StrictMonoOn natAbs (Ici 0) := fun _ ha _ _ hab => natAbs_lt_natAbs_of_nonneg_of_lt ha hab theorem strictAntiOn_natAbs : StrictAntiOn natAbs (Iic 0) := fun a _ b hb hab => by simpa [Int.natAbs_neg] using natAbs_lt_natAbs_of_nonneg_of_lt (Right.nonneg_neg_iff.mpr hb) (neg_lt_neg_iff.mpr hab) theorem injOn_natAbs_Ici : InjOn natAbs (Ici 0) := strictMonoOn_natAbs.injOn theorem injOn_natAbs_Iic : InjOn natAbs (Iic 0) := strictAntiOn_natAbs.injOn end Intervals /-! ### bitwise ops
This lemma is orphaned from `Data.Int.Bitwise` as it also requires material from `Data.Int.Order`. -/
Mathlib/Data/Int/Lemmas.lean
104
106
/- Copyright (c) 2021 Hunter Monroe. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Hunter Monroe, Kyle Miller, Alena Gusakov -/ import Mathlib.Combinatorics.SimpleGraph.DeleteEdges import Mathlib.Data.Fintype.Powerset /-! # Subgraphs of a simple graph A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the endpoints of each edge are present in the vertex subset. The edge subset is formalized as a sub-relation of the adjacency relation of the simple graph. ## Main definitions * `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`. * `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their `SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions. * `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`. (In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.) * `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and `Subgraph.IsInduced` for whether a subgraph is an induced subgraph. * Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`. * `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it into a member of the larger graph's `SimpleGraph.Subgraph` type. * Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs (`Subgraph.map`). ## Implementation notes * Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to this kind of subobject. ## TODO * Images of graph homomorphisms as subgraphs. -/ universe u v namespace SimpleGraph /-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice. Thinking of `V β†’ V β†’ Prop` as `Set (V Γ— V)`, a set of darts (i.e., half-edges), then `Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/ @[ext] structure Subgraph {V : Type u} (G : SimpleGraph V) where /-- Vertices of the subgraph -/ verts : Set V /-- Edges of the subgraph -/ Adj : V β†’ V β†’ Prop adj_sub : βˆ€ {v w : V}, Adj v w β†’ G.Adj v w edge_vert : βˆ€ {v w : V}, Adj v w β†’ v ∈ verts symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously` initialize_simps_projections SimpleGraph.Subgraph (Adj β†’ adj) variable {ΞΉ : Sort*} {V : Type u} {W : Type v} /-- The one-vertex subgraph. -/ @[simps] protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where verts := {v} Adj := βŠ₯ adj_sub := False.elim edge_vert := False.elim symm _ _ := False.elim /-- The one-edge subgraph. -/ @[simps] def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where verts := {v, w} Adj a b := s(v, w) = s(a, b) adj_sub h := by rw [← G.mem_edgeSet, ← h] exact hvw edge_vert {a b} h := by apply_fun fun e ↦ a ∈ e at h simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h exact h namespace Subgraph variable {G : SimpleGraph V} {G₁ Gβ‚‚ : G.Subgraph} {a b : V} protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj := fun v h ↦ G.loopless v (G'.adj_sub h) theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v := ⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩ @[symm] theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u := G'.symm h protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u := G'.symm h protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v := H.adj_sub h protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts := H.edge_vert h protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts := h.symm.fst_mem protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u β‰  v := h.adj_sub.ne theorem adj_congr_of_sym2 {H : G.Subgraph} {u v w x : V} (h2 : s(u, v) = s(w, x)) : H.Adj u v ↔ H.Adj w x := by simp only [Sym2.eq, Sym2.rel_iff', Prod.mk.injEq, Prod.swap_prod_mk] at h2 rcases h2 with hl | hr Β· rw [hl.1, hl.2] Β· rw [hr.1, hr.2, Subgraph.adj_comm] /-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/ @[simps] protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where Adj v w := G'.Adj v w symm _ _ h := G'.symm h loopless v h := loopless G v (G'.adj_sub h) @[simp] theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v := G'.adj_sub h -- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`. protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) : H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h instance (G : SimpleGraph V) (H : Subgraph G) [DecidableRel H.Adj] : DecidableRel H.coe.Adj := fun a b ↦ β€ΉDecidableRel H.Adjβ€Ί _ _ /-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/ def IsSpanning (G' : Subgraph G) : Prop := βˆ€ v : V, v ∈ G'.verts theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ := Set.eq_univ_iff_forall.symm protected alias ⟨IsSpanning.verts_eq_univ, _⟩ := isSpanning_iff /-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning subgraph, then `G'.spanningCoe` yields an isomorphic graph. In general, this adds in all vertices from `V` as isolated vertices. -/ @[simps] protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where Adj := G'.Adj symm := G'.symm loopless v hv := G.loopless v (G'.adj_sub hv) @[simp] theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) : G.Adj u v := G'.adj_sub h lemma spanningCoe_le (G' : G.Subgraph) : G'.spanningCoe ≀ G := fun _ _ ↦ G'.3 theorem spanningCoe_inj : G₁.spanningCoe = Gβ‚‚.spanningCoe ↔ G₁.Adj = Gβ‚‚.Adj := by simp [Subgraph.spanningCoe] lemma mem_of_adj_spanningCoe {v w : V} {s : Set V} (G : SimpleGraph s) (hadj : G.spanningCoe.Adj v w) : v ∈ s := by aesop @[simp] lemma spanningCoe_subgraphOfAdj {v w : V} (hadj : G.Adj v w) : (G.subgraphOfAdj hadj).spanningCoe = fromEdgeSet {s(v, w)} := by ext v w aesop /-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/ @[simps] def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe where toFun v := ⟨v, h v⟩ invFun v := v left_inv _ := rfl right_inv _ := rfl map_rel_iff' := Iff.rfl /-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if they are adjacent in `G`. -/ def IsInduced (G' : Subgraph G) : Prop := βˆ€ ⦃v⦄, v ∈ G'.verts β†’ βˆ€ ⦃w⦄, w ∈ G'.verts β†’ G.Adj v w β†’ G'.Adj v w @[simp] protected lemma IsInduced.adj {G' : G.Subgraph} (hG' : G'.IsInduced) {a b : G'.verts} : G'.Adj a b ↔ G.Adj a b := ⟨coe_adj_sub _ _ _, hG' a.2 b.2⟩ /-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/ def support (H : Subgraph G) : Set V := Rel.dom H.Adj theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ βˆƒ w, H.Adj v w := Iff.rfl theorem support_subset_verts (H : Subgraph G) : H.support βŠ† H.verts := fun _ ⟨_, h⟩ ↦ H.edge_vert h /-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/ def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w} theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v βŠ† G.neighborSet v := fun _ ↦ G'.adj_sub theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v βŠ† G'.verts := fun _ h ↦ G'.edge_vert (adj_symm G' h) @[simp] theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl /-- A subgraph as a graph has equivalent neighbor sets. -/ def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v where toFun w := ⟨w, w.2⟩ invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩ left_inv _ := rfl right_inv _ := rfl /-- The edge set of `G'` consists of a subset of edges of `G`. -/ def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet βŠ† G.edgeSet := Sym2.ind (fun _ _ ↦ G'.adj_sub) @[simp] protected lemma mem_edgeSet {G' : Subgraph G} {v w : V} : s(v, w) ∈ G'.edgeSet ↔ G'.Adj v w := .rfl @[simp] lemma edgeSet_coe {G' : G.Subgraph} : G'.coe.edgeSet = Sym2.map (↑) ⁻¹' G'.edgeSet := by ext e; induction e using Sym2.ind; simp lemma image_coe_edgeSet_coe (G' : G.Subgraph) : Sym2.map (↑) '' G'.coe.edgeSet = G'.edgeSet := by rw [edgeSet_coe, Set.image_preimage_eq_iff] rintro e he induction e using Sym2.ind with | h a b => rw [Subgraph.mem_edgeSet] at he exact ⟨s(⟨a, edge_vert _ he⟩, ⟨b, edge_vert _ he.symm⟩), Sym2.map_pair_eq ..⟩ theorem mem_verts_of_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet) (hv : v ∈ e) : v ∈ G'.verts := by induction e rcases Sym2.mem_iff.mp hv with (rfl | rfl) Β· exact G'.edge_vert he Β· exact G'.edge_vert (G'.symm he) /-- The `incidenceSet` is the set of edges incident to a given vertex. -/ def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e} theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) : G'.incidenceSet v βŠ† G.incidenceSet v := fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩ theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v βŠ† G'.edgeSet := fun _ h ↦ h.1 /-- Give a vertex as an element of the subgraph's vertex type. -/ abbrev vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩ /-- Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities. See Note [range copy pattern]. -/ def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts) (adj' : V β†’ V β†’ Prop) (hadj : adj' = G'.Adj) : Subgraph G where verts := V'' Adj := adj' adj_sub := hadj.symm β–Έ G'.adj_sub edge_vert := hV.symm β–Έ hadj.symm β–Έ G'.edge_vert symm := hadj.symm β–Έ G'.symm theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts) (adj' : V β†’ V β†’ Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' := Subgraph.ext hV hadj /-- The union of two subgraphs. -/ instance : Max G.Subgraph where max G₁ Gβ‚‚ := { verts := G₁.verts βˆͺ Gβ‚‚.verts Adj := G₁.Adj βŠ” Gβ‚‚.Adj adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => Gβ‚‚.adj_sub h edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => Gβ‚‚.edge_vert h symm := fun _ _ => Or.imp G₁.adj_symm Gβ‚‚.adj_symm } /-- The intersection of two subgraphs. -/ instance : Min G.Subgraph where min G₁ Gβ‚‚ := { verts := G₁.verts ∩ Gβ‚‚.verts Adj := G₁.Adj βŠ“ Gβ‚‚.Adj adj_sub := fun hab => G₁.adj_sub hab.1 edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => Gβ‚‚.edge_vert h symm := fun _ _ => And.imp G₁.adj_symm Gβ‚‚.adj_symm } /-- The `top` subgraph is `G` as a subgraph of itself. -/ instance : Top G.Subgraph where top := { verts := Set.univ Adj := G.Adj adj_sub := id edge_vert := @fun v _ _ => Set.mem_univ v symm := G.symm } /-- The `bot` subgraph is the subgraph with no vertices or edges. -/ instance : Bot G.Subgraph where bot := { verts := βˆ… Adj := βŠ₯ adj_sub := False.elim edge_vert := False.elim symm := fun _ _ => id } instance : SupSet G.Subgraph where sSup s := { verts := ⋃ G' ∈ s, verts G' Adj := fun a b => βˆƒ G' ∈ s, Adj G' a b adj_sub := by rintro a b ⟨G', -, hab⟩ exact G'.adj_sub hab edge_vert := by rintro a b ⟨G', hG', hab⟩ exact Set.mem_iUnionβ‚‚_of_mem hG' (G'.edge_vert hab) symm := fun a b h => by simpa [adj_comm] using h } instance : InfSet G.Subgraph where sInf s := { verts := β‹‚ G' ∈ s, verts G' Adj := fun a b => (βˆ€ ⦃G'⦄, G' ∈ s β†’ Adj G' a b) ∧ G.Adj a b adj_sub := And.right edge_vert := fun hab => Set.mem_iInterβ‚‚_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG' symm := fun _ _ => And.imp (forallβ‚‚_imp fun _ _ => Adj.symm) G.adj_symm } @[simp] theorem sup_adj : (G₁ βŠ” Gβ‚‚).Adj a b ↔ G₁.Adj a b ∨ Gβ‚‚.Adj a b := Iff.rfl @[simp] theorem inf_adj : (G₁ βŠ“ Gβ‚‚).Adj a b ↔ G₁.Adj a b ∧ Gβ‚‚.Adj a b := Iff.rfl @[simp] theorem top_adj : (⊀ : Subgraph G).Adj a b ↔ G.Adj a b := Iff.rfl @[simp] theorem not_bot_adj : Β¬ (βŠ₯ : Subgraph G).Adj a b := not_false @[simp] theorem verts_sup (G₁ Gβ‚‚ : G.Subgraph) : (G₁ βŠ” Gβ‚‚).verts = G₁.verts βˆͺ Gβ‚‚.verts := rfl @[simp] theorem verts_inf (G₁ Gβ‚‚ : G.Subgraph) : (G₁ βŠ“ Gβ‚‚).verts = G₁.verts ∩ Gβ‚‚.verts := rfl @[simp] theorem verts_top : (⊀ : G.Subgraph).verts = Set.univ := rfl @[simp] theorem verts_bot : (βŠ₯ : G.Subgraph).verts = βˆ… := rfl @[simp] theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ βˆƒ G ∈ s, Adj G a b := Iff.rfl @[simp] theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (βˆ€ G' ∈ s, Adj G' a b) ∧ G.Adj a b := Iff.rfl @[simp] theorem iSup_adj {f : ΞΉ β†’ G.Subgraph} : (⨆ i, f i).Adj a b ↔ βˆƒ i, (f i).Adj a b := by simp [iSup] @[simp] theorem iInf_adj {f : ΞΉ β†’ G.Subgraph} : (β¨… i, f i).Adj a b ↔ (βˆ€ i, (f i).Adj a b) ∧ G.Adj a b := by simp [iInf] theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) : (sInf s).Adj a b ↔ βˆ€ G' ∈ s, Adj G' a b := sInf_adj.trans <| and_iff_left_of_imp <| by obtain ⟨G', hG'⟩ := hs exact fun h => G'.adj_sub (h _ hG') theorem iInf_adj_of_nonempty [Nonempty ΞΉ] {f : ΞΉ β†’ G.Subgraph} : (β¨… i, f i).Adj a b ↔ βˆ€ i, (f i).Adj a b := by rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)] simp @[simp] theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' := rfl @[simp] theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = β‹‚ G' ∈ s, verts G' := rfl @[simp] theorem verts_iSup {f : ΞΉ β†’ G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup] @[simp] theorem verts_iInf {f : ΞΉ β†’ G.Subgraph} : (β¨… i, f i).verts = β‹‚ i, (f i).verts := by simp [iInf] @[simp] lemma coe_bot : (βŠ₯ : G.Subgraph).coe = βŠ₯ := rfl @[simp] lemma IsInduced.top : (⊀ : G.Subgraph).IsInduced := fun _ _ _ _ ↦ id /-- The graph isomorphism between the top element of `G.subgraph` and `G`. -/ def topIso : (⊀ : G.Subgraph).coe ≃g G where toFun := (↑) invFun a := ⟨a, Set.mem_univ _⟩ left_inv _ := Subtype.eta .. right_inv _ := rfl map_rel_iff' := .rfl theorem verts_spanningCoe_injective : (fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by intro G₁ Gβ‚‚ h rw [Prod.ext_iff] at h exact Subgraph.ext h.1 (spanningCoe_inj.1 h.2) /-- For subgraphs `G₁`, `Gβ‚‚`, `G₁ ≀ Gβ‚‚` iff `G₁.verts βŠ† Gβ‚‚.verts` and `βˆ€ a b, G₁.adj a b β†’ Gβ‚‚.adj a b`. -/ instance distribLattice : DistribLattice G.Subgraph := { show DistribLattice G.Subgraph from verts_spanningCoe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl with le := fun x y => x.verts βŠ† y.verts ∧ βˆ€ ⦃v w : V⦄, x.Adj v w β†’ y.Adj v w } instance : BoundedOrder (Subgraph G) where top := ⊀ bot := βŠ₯ le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩ bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩ /-- Note that subgraphs do not form a Boolean algebra, because of `verts`. -/ def completelyDistribLatticeMinimalAxioms : CompletelyDistribLattice.MinimalAxioms G.Subgraph := { Subgraph.distribLattice with le := (Β· ≀ Β·) sup := (Β· βŠ” Β·) inf := (Β· βŠ“ Β·) top := ⊀ bot := βŠ₯ le_top := fun G' => ⟨Set.subset_univ _, fun _ _ => G'.adj_sub⟩ bot_le := fun _ => ⟨Set.empty_subset _, fun _ _ => False.elim⟩ sSup := sSup -- Porting note: needed `apply` here to modify elaboration; previously the term itself was fine. le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnionβ‚‚ G' hG', fun _ _ hab => ⟨G', hG', hab⟩⟩ sSup_le := fun s G' hG' => ⟨Set.iUnionβ‚‚_subset fun _ hH => (hG' _ hH).1, by rintro a b ⟨H, hH, hab⟩ exact (hG' _ hH).2 hab⟩ sInf := sInf sInf_le := fun _ G' hG' => ⟨Set.iInterβ‚‚_subset G' hG', fun _ _ hab => hab.1 hG'⟩ le_sInf := fun _ G' hG' => ⟨Set.subset_iInterβ‚‚ fun _ hH => (hG' _ hH).1, fun _ _ hab => ⟨fun _ hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩ iInf_iSup_eq := fun f => Subgraph.ext (by simpa using iInf_iSup_eq) (by ext; simp [Classical.skolem]) } instance : CompletelyDistribLattice G.Subgraph := .ofMinimalAxioms completelyDistribLatticeMinimalAxioms @[gcongr] lemma verts_mono {H H' : G.Subgraph} (h : H ≀ H') : H.verts βŠ† H'.verts := h.1 lemma verts_monotone : Monotone (verts : G.Subgraph β†’ Set V) := fun _ _ h ↦ h.1 @[simps] instance subgraphInhabited : Inhabited (Subgraph G) := ⟨βŠ₯⟩ @[simp] theorem neighborSet_sup {H H' : G.Subgraph} (v : V) : (H βŠ” H').neighborSet v = H.neighborSet v βˆͺ H'.neighborSet v := rfl @[simp] theorem neighborSet_inf {H H' : G.Subgraph} (v : V) : (H βŠ“ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl @[simp] theorem neighborSet_top (v : V) : (⊀ : G.Subgraph).neighborSet v = G.neighborSet v := rfl @[simp] theorem neighborSet_bot (v : V) : (βŠ₯ : G.Subgraph).neighborSet v = βˆ… := rfl @[simp] theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) : (sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by ext simp @[simp] theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) : (sInf s).neighborSet v = (β‹‚ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by ext simp @[simp] theorem neighborSet_iSup (f : ΞΉ β†’ G.Subgraph) (v : V) : (⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup] @[simp] theorem neighborSet_iInf (f : ΞΉ β†’ G.Subgraph) (v : V) : (β¨… i, f i).neighborSet v = (β‹‚ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf] @[simp] theorem edgeSet_top : (⊀ : Subgraph G).edgeSet = G.edgeSet := rfl @[simp] theorem edgeSet_bot : (βŠ₯ : Subgraph G).edgeSet = βˆ… := Set.ext <| Sym2.ind (by simp) @[simp] theorem edgeSet_inf {H₁ Hβ‚‚ : Subgraph G} : (H₁ βŠ“ Hβ‚‚).edgeSet = H₁.edgeSet ∩ Hβ‚‚.edgeSet := Set.ext <| Sym2.ind (by simp) @[simp] theorem edgeSet_sup {H₁ Hβ‚‚ : Subgraph G} : (H₁ βŠ” Hβ‚‚).edgeSet = H₁.edgeSet βˆͺ Hβ‚‚.edgeSet := Set.ext <| Sym2.ind (by simp) @[simp] theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by ext e induction e simp @[simp] theorem edgeSet_sInf (s : Set G.Subgraph) : (sInf s).edgeSet = (β‹‚ G' ∈ s, edgeSet G') ∩ G.edgeSet := by ext e induction e simp @[simp] theorem edgeSet_iSup (f : ΞΉ β†’ G.Subgraph) : (⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup] @[simp] theorem edgeSet_iInf (f : ΞΉ β†’ G.Subgraph) : (β¨… i, f i).edgeSet = (β‹‚ i, (f i).edgeSet) ∩ G.edgeSet := by simp [iInf] @[simp] theorem spanningCoe_top : (⊀ : Subgraph G).spanningCoe = G := rfl @[simp] theorem spanningCoe_bot : (βŠ₯ : Subgraph G).spanningCoe = βŠ₯ := rfl /-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/ @[simps] def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≀ G) : G.Subgraph where verts := Set.univ Adj := H.Adj adj_sub e := h e edge_vert _ := Set.mem_univ _ symm := H.symm theorem support_mono {H H' : Subgraph G} (h : H ≀ H') : H.support βŠ† H'.support := Rel.dom_mono h.2 theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≀ G) : (toSubgraph H h).IsSpanning := Set.mem_univ theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≀ H') : H.spanningCoe ≀ H'.spanningCoe := h.2 @[simp] lemma sup_spanningCoe (H H' : Subgraph G) : (H βŠ” H').spanningCoe = H.spanningCoe βŠ” H'.spanningCoe := rfl /-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/ def topEquiv : (⊀ : Subgraph G).coe ≃g G where toFun v := ↑v invFun v := ⟨v, trivial⟩ left_inv _ := rfl right_inv _ := rfl map_rel_iff' := Iff.rfl /-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty vertex type. -/ def botEquiv : (βŠ₯ : Subgraph G).coe ≃g (βŠ₯ : SimpleGraph Empty) where toFun v := v.property.elim invFun v := v.elim left_inv := fun ⟨_, h⟩ ↦ h.elim right_inv v := v.elim map_rel_iff' := Iff.rfl theorem edgeSet_mono {H₁ Hβ‚‚ : Subgraph G} (h : H₁ ≀ Hβ‚‚) : H₁.edgeSet ≀ Hβ‚‚.edgeSet := Sym2.ind h.2 theorem _root_.Disjoint.edgeSet {H₁ Hβ‚‚ : Subgraph G} (h : Disjoint H₁ Hβ‚‚) : Disjoint H₁.edgeSet Hβ‚‚.edgeSet := disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot section map variable {G' : SimpleGraph W} {f : G β†’g G'} /-- Graph homomorphisms induce a covariant function on subgraphs. -/ @[simps] protected def map (f : G β†’g G') (H : G.Subgraph) : G'.Subgraph where verts := f '' H.verts Adj := Relation.Map H.Adj f f adj_sub := by rintro _ _ ⟨u, v, h, rfl, rfl⟩ exact f.map_rel (H.adj_sub h) edge_vert := by rintro _ _ ⟨u, v, h, rfl, rfl⟩ exact Set.mem_image_of_mem _ (H.edge_vert h) symm := by rintro _ _ ⟨u, v, h, rfl, rfl⟩ exact ⟨v, u, H.symm h, rfl, rfl⟩ @[simp] lemma map_id (H : G.Subgraph) : H.map Hom.id = H := by ext <;> simp lemma map_comp {U : Type*} {G'' : SimpleGraph U} (H : G.Subgraph) (f : G β†’g G') (g : G' β†’g G'') : H.map (g.comp f) = (H.map f).map g := by ext <;> simp [Subgraph.map] @[gcongr] lemma map_mono {H₁ Hβ‚‚ : G.Subgraph} (hH : H₁ ≀ Hβ‚‚) : H₁.map f ≀ Hβ‚‚.map f := by constructor Β· intro simp only [map_verts, Set.mem_image, forall_exists_index, and_imp] rintro v hv rfl exact ⟨_, hH.1 hv, rfl⟩ Β· rintro _ _ ⟨u, v, ha, rfl, rfl⟩ exact ⟨_, _, hH.2 ha, rfl, rfl⟩ lemma map_monotone : Monotone (Subgraph.map f) := fun _ _ ↦ map_mono theorem map_sup (f : G β†’g G') (H₁ Hβ‚‚ : G.Subgraph) : (H₁ βŠ” Hβ‚‚).map f = H₁.map f βŠ” Hβ‚‚.map f := by ext <;> simp [Set.image_union, map_adj, sup_adj, Relation.Map, or_and_right, exists_or] @[simp] lemma map_iso_top {H : SimpleGraph W} (e : G ≃g H) : Subgraph.map e.toHom ⊀ = ⊀ := by ext <;> simp [Relation.Map, e.apply_eq_iff_eq_symm_apply, ← e.map_rel_iff] @[simp] lemma edgeSet_map (f : G β†’g G') (H : G.Subgraph) : (H.map f).edgeSet = Sym2.map f '' H.edgeSet := Sym2.fromRel_relationMap .. end map /-- Graph homomorphisms induce a contravariant function on subgraphs. -/ @[simps] protected def comap {G' : SimpleGraph W} (f : G β†’g G') (H : G'.Subgraph) : G.Subgraph where verts := f ⁻¹' H.verts Adj u v := G.Adj u v ∧ H.Adj (f u) (f v) adj_sub h := h.1 edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2) symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩ theorem comap_monotone {G' : SimpleGraph W} (f : G β†’g G') : Monotone (Subgraph.comap f) := by intro H H' h constructor Β· intro simp only [comap_verts, Set.mem_preimage] apply h.1 Β· intro v w simp +contextual only [comap_adj, and_imp, true_and] intro apply h.2 @[simp] lemma comap_equiv_top {H : SimpleGraph W} (f : G β†’g H) : Subgraph.comap f ⊀ = ⊀ := by ext <;> simp +contextual [f.map_adj] theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G β†’g G') (H : G.Subgraph) (H' : G'.Subgraph) : H.map f ≀ H' ↔ H ≀ H'.comap f := by refine ⟨fun h ↦ ⟨fun v hv ↦ ?_, fun v w hvw ↦ ?_⟩, fun h ↦ ⟨fun v ↦ ?_, fun v w ↦ ?_⟩⟩ Β· simp only [comap_verts, Set.mem_preimage] exact h.1 ⟨v, hv, rfl⟩ Β· simp only [H.adj_sub hvw, comap_adj, true_and] exact h.2 ⟨v, w, hvw, rfl, rfl⟩ Β· simp only [map_verts, Set.mem_image, forall_exists_index, and_imp] rintro w hw rfl exact h.1 hw Β· simp only [Relation.Map, map_adj, forall_exists_index, and_imp] rintro u u' hu rfl rfl exact (h.2 hu).2 instance [DecidableEq V] [Fintype V] [DecidableRel G.Adj] : Fintype G.Subgraph := by refine .ofBijective (Ξ± := {H : Finset V Γ— (V β†’ V β†’ Bool) // (βˆ€ a b, H.2 a b β†’ G.Adj a b) ∧ (βˆ€ a b, H.2 a b β†’ a ∈ H.1) ∧ βˆ€ a b, H.2 a b = H.2 b a}) (fun H ↦ ⟨H.1.1, fun a b ↦ H.1.2 a b, @H.2.1, @H.2.2.1, by simp [Symmetric, H.2.2.2]⟩) ⟨?_, fun H ↦ ?_⟩ Β· rintro ⟨⟨_, _⟩, -⟩ ⟨⟨_, _⟩, -⟩ simp [funext_iff] Β· classical exact ⟨⟨(H.verts.toFinset, fun a b ↦ H.Adj a b), fun a b ↦ by simpa using H.adj_sub, fun a b ↦ by simpa using H.edge_vert, by simp [H.adj_comm]⟩, by simp⟩ instance [Finite V] : Finite G.Subgraph := by classical cases nonempty_fintype V; infer_instance /-- Given two subgraphs, one a subgraph of the other, there is an induced injective homomorphism of the subgraphs as graphs. -/ @[simps] def inclusion {x y : Subgraph G} (h : x ≀ y) : x.coe β†’g y.coe where toFun v := βŸ¨β†‘v, And.left h v.property⟩ map_rel' hvw := h.2 hvw theorem inclusion.injective {x y : Subgraph G} (h : x ≀ y) : Function.Injective (inclusion h) := by intro v w h rw [inclusion, DFunLike.coe, Subtype.mk_eq_mk] at h exact Subtype.ext h /-- There is an induced injective homomorphism of a subgraph of `G` into `G`. -/ @[simps] protected def hom (x : Subgraph G) : x.coe β†’g G where toFun v := v map_rel' := x.adj_sub @[simp] lemma coe_hom (x : Subgraph G) : (x.hom : x.verts β†’ V) = (fun (v : x.verts) => (v : V)) := rfl theorem hom_injective {x : Subgraph G} : Function.Injective x.hom := fun _ _ ↦ Subtype.ext @[deprecated (since := "2025-03-15")] alias hom.injective := hom_injective @[simp] lemma map_hom_top (G' : G.Subgraph) : Subgraph.map G'.hom ⊀ = G' := by aesop (add unfold safe Relation.Map, unsafe G'.edge_vert, unsafe Adj.symm) /-- There is an induced injective homomorphism of a subgraph of `G` as a spanning subgraph into `G`. -/ @[simps] def spanningHom (x : Subgraph G) : x.spanningCoe β†’g G where toFun := id map_rel' := x.adj_sub theorem spanningHom_injective {x : Subgraph G} : Function.Injective x.spanningHom := fun _ _ ↦ id @[deprecated (since := "2025-03-15")] alias spanningHom.injective := spanningHom_injective theorem neighborSet_subset_of_subgraph {x y : Subgraph G} (h : x ≀ y) (v : V) : x.neighborSet v βŠ† y.neighborSet v := fun _ h' ↦ h.2 h' instance neighborSet.decidablePred (G' : Subgraph G) [h : DecidableRel G'.Adj] (v : V) : DecidablePred (Β· ∈ G'.neighborSet v) := h v /-- If a graph is locally finite at a vertex, then so is a subgraph of that graph. -/ instance finiteAt {G' : Subgraph G} (v : G'.verts) [DecidableRel G'.Adj] [Fintype (G.neighborSet v)] : Fintype (G'.neighborSet v) := Set.fintypeSubset (G.neighborSet v) (G'.neighborSet_subset v) /-- If a subgraph is locally finite at a vertex, then so are subgraphs of that subgraph. This is not an instance because `G''` cannot be inferred. -/ def finiteAtOfSubgraph {G' G'' : Subgraph G} [DecidableRel G'.Adj] (h : G' ≀ G'') (v : G'.verts) [Fintype (G''.neighborSet v)] : Fintype (G'.neighborSet v) := Set.fintypeSubset (G''.neighborSet v) (neighborSet_subset_of_subgraph h v) instance (G' : Subgraph G) [Fintype G'.verts] (v : V) [DecidablePred (Β· ∈ G'.neighborSet v)] : Fintype (G'.neighborSet v) := Set.fintypeSubset G'.verts (neighborSet_subset_verts G' v) instance coeFiniteAt {G' : Subgraph G} (v : G'.verts) [Fintype (G'.neighborSet v)] : Fintype (G'.coe.neighborSet v) := Fintype.ofEquiv _ (coeNeighborSetEquiv v).symm theorem IsSpanning.card_verts [Fintype V] {G' : Subgraph G} [Fintype G'.verts] (h : G'.IsSpanning) : G'.verts.toFinset.card = Fintype.card V := by simp only [isSpanning_iff.1 h, Set.toFinset_univ] congr /-- The degree of a vertex in a subgraph. It's zero for vertices outside the subgraph. -/ def degree (G' : Subgraph G) (v : V) [Fintype (G'.neighborSet v)] : β„• := Fintype.card (G'.neighborSet v) theorem finset_card_neighborSet_eq_degree {G' : Subgraph G} {v : V} [Fintype (G'.neighborSet v)] : (G'.neighborSet v).toFinset.card = G'.degree v := by rw [degree, Set.toFinset_card] theorem degree_le (G' : Subgraph G) (v : V) [Fintype (G'.neighborSet v)] [Fintype (G.neighborSet v)] : G'.degree v ≀ G.degree v := by rw [← card_neighborSet_eq_degree] exact Set.card_le_card (G'.neighborSet_subset v) theorem degree_le' (G' G'' : Subgraph G) (h : G' ≀ G'') (v : V) [Fintype (G'.neighborSet v)] [Fintype (G''.neighborSet v)] : G'.degree v ≀ G''.degree v := Set.card_le_card (neighborSet_subset_of_subgraph h v) @[simp] theorem coe_degree (G' : Subgraph G) (v : G'.verts) [Fintype (G'.coe.neighborSet v)] [Fintype (G'.neighborSet v)] : G'.coe.degree v = G'.degree v := by rw [← card_neighborSet_eq_degree] exact Fintype.card_congr (coeNeighborSetEquiv v) @[simp] theorem degree_spanningCoe {G' : G.Subgraph} (v : V) [Fintype (G'.neighborSet v)] [Fintype (G'.spanningCoe.neighborSet v)] : G'.spanningCoe.degree v = G'.degree v := by rw [← card_neighborSet_eq_degree, Subgraph.degree] congr! theorem degree_eq_one_iff_unique_adj {G' : Subgraph G} {v : V} [Fintype (G'.neighborSet v)] : G'.degree v = 1 ↔ βˆƒ! w : V, G'.Adj v w := by rw [← finset_card_neighborSet_eq_degree, Finset.card_eq_one, Finset.singleton_iff_unique_mem] simp only [Set.mem_toFinset, mem_neighborSet] lemma neighborSet_eq_of_equiv {v : V} {H : Subgraph G} (h : G.neighborSet v ≃ H.neighborSet v) (hfin : (G.neighborSet v).Finite) : H.neighborSet v = G.neighborSet v := by lift H.neighborSet v to Finset V using h.set_finite_iff.mp hfin with s hs lift G.neighborSet v to Finset V using hfin with t ht refine congrArg _ <| Finset.eq_of_subset_of_card_le ?_ (Finset.card_eq_of_equiv h).le rw [← Finset.coe_subset, hs, ht] exact H.neighborSet_subset _ lemma adj_iff_of_neighborSet_equiv {v : V} {H : Subgraph G} (h : G.neighborSet v ≃ H.neighborSet v) (hfin : (G.neighborSet v).Finite) : βˆ€ {w}, H.Adj v w ↔ G.Adj v w := Set.ext_iff.mp (neighborSet_eq_of_equiv h hfin) _ end Subgraph section MkProperties /-! ### Properties of `singletonSubgraph` and `subgraphOfAdj` -/ variable {G : SimpleGraph V} {G' : SimpleGraph W} instance nonempty_singletonSubgraph_verts (v : V) : Nonempty (G.singletonSubgraph v).verts := ⟨⟨v, Set.mem_singleton v⟩⟩ @[simp] theorem singletonSubgraph_le_iff (v : V) (H : G.Subgraph) : G.singletonSubgraph v ≀ H ↔ v ∈ H.verts := by refine ⟨fun h ↦ h.1 (Set.mem_singleton v), ?_⟩ intro h constructor Β· rwa [singletonSubgraph_verts, Set.singleton_subset_iff] Β· exact fun _ _ ↦ False.elim
@[simp] theorem map_singletonSubgraph (f : G β†’g G') {v : V} : Subgraph.map f (G.singletonSubgraph v) = G'.singletonSubgraph (f v) := by ext <;> simp only [Relation.Map, Subgraph.map_adj, singletonSubgraph_adj, Pi.bot_apply, exists_and_left, and_iff_left_iff_imp, IsEmpty.forall_iff, Subgraph.map_verts, singletonSubgraph_verts, Set.image_singleton]
Mathlib/Combinatorics/SimpleGraph/Subgraph.lean
845
851
/- 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, Kim Morrison -/ import Mathlib.Data.List.Chain /-! # 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. -/ universe u open Nat namespace List variable {Ξ± : Type u} theorem getElem_range'_1 {n m} (i) (H : i < (range' n m).length) : (range' n m)[i] = n + i := by simp 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] rw [hn, forall_lt_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 section Ranges /-- From `l : List β„•`, construct `l.ranges : List (List β„•)` such that `l.ranges.map List.length = l` and `l.ranges.join = range l.sum` * Example: `[1,2,3].ranges = [[0],[1,2],[3,4,5]]` -/ def ranges : List β„• β†’ List (List β„•) | [] => nil | a::l => range a::(ranges l).map (map (a + Β·)) /-- The members of `l.ranges` are pairwise disjoint -/ theorem ranges_disjoint (l : List β„•) : Pairwise Disjoint (ranges l) := by induction l with | nil => exact Pairwise.nil | cons a l hl => simp only [ranges, pairwise_cons] constructor Β· intro s hs obtain ⟨s', _, rfl⟩ := mem_map.mp hs intro u hu rw [mem_map] rintro ⟨v, _, rfl⟩ rw [mem_range] at hu omega Β· rw [pairwise_map] apply Pairwise.imp _ hl intro u v apply disjoint_map exact fun u v => Nat.add_left_cancel /-- The lengths of the members of `l.ranges` are those given by `l` -/ theorem ranges_length (l : List β„•) : l.ranges.map length = l := by induction l with | nil => simp only [ranges, map_nil] | cons a l hl => -- (a :: l) simp only [ranges, map_cons, length_range, map_map, cons.injEq, true_and] conv_rhs => rw [← hl] apply map_congr_left intro s _ simp only [Function.comp_apply, length_map] end Ranges end List
Mathlib/Data/List/Range.lean
191
193
/- Copyright (c) 2024 Etienne Marion. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Etienne Marion -/ import Mathlib.Data.Finite.Prod import Mathlib.MeasureTheory.SetSemiring /-! # Algebra of sets In this file we define the notion of algebra of sets and give its basic properties. An algebra of sets is a family of sets containing the empty set and closed by complement and binary union. It is therefore similar to a `Οƒ`-algebra, except that it is not necessarily closed by countable unions. We also define the algebra of sets generated by a family of sets and give its basic properties, and we prove that it is countable when it is generated by a countable family. We prove that the `Οƒ`-algebra generated by a family of sets `π’œ` is the same as the one generated by the algebra of sets generated by `π’œ`. ## Main definitions * `MeasureTheory.IsSetAlgebra`: property of being an algebra of sets. * `MeasureTheory.generateSetAlgebra`: the algebra of sets generated by a family of sets. ## Main statements * `MeasureTheory.mem_generateSetAlgebra_elim`: If a set `s` belongs to the algebra of sets generated by `π’œ`, then it can be written as a finite union of finite intersections of sets which are in `π’œ` or have their complement in `π’œ`. * `MeasureTheory.countable_generateSetAlgebra`: If a family of sets is countable then so is the algebra of sets generated by it. ## References * <https://en.wikipedia.org/wiki/Field_of_sets> ## Tags algebra of sets, generated algebra of sets -/ open MeasurableSpace Set namespace MeasureTheory variable {Ξ± : Type*} {π’œ : Set (Set Ξ±)} {s t : Set Ξ±} /-! ### Definition and basic properties of an algebra of sets -/ /-- An algebra of sets is a family of sets containing the empty set and closed by complement and union. Consequently it is also closed by difference (see `IsSetAlgebra.diff_mem`) and intersection (see `IsSetAlgebra.inter_mem`). -/ structure IsSetAlgebra (π’œ : Set (Set Ξ±)) : Prop where empty_mem : βˆ… ∈ π’œ compl_mem : βˆ€ ⦃s⦄, s ∈ π’œ β†’ sᢜ ∈ π’œ union_mem : βˆ€ ⦃s t⦄, s ∈ π’œ β†’ t ∈ π’œ β†’ s βˆͺ t ∈ π’œ namespace IsSetAlgebra /-- An algebra of sets contains the whole set. -/ theorem univ_mem (hπ’œ : IsSetAlgebra π’œ) : univ ∈ π’œ := compl_empty β–Έ hπ’œ.compl_mem hπ’œ.empty_mem /-- An algebra of sets is closed by intersection. -/ theorem inter_mem (hπ’œ : IsSetAlgebra π’œ) (s_mem : s ∈ π’œ) (t_mem : t ∈ π’œ) : s ∩ t ∈ π’œ := inter_eq_compl_compl_union_compl .. β–Έ hπ’œ.compl_mem (hπ’œ.union_mem (hπ’œ.compl_mem s_mem) (hπ’œ.compl_mem t_mem)) /-- An algebra of sets is closed by difference. -/ theorem diff_mem (hπ’œ : IsSetAlgebra π’œ) (s_mem : s ∈ π’œ) (t_mem : t ∈ π’œ) : s \ t ∈ π’œ := hπ’œ.inter_mem s_mem (hπ’œ.compl_mem t_mem) /-- An algebra of sets is a ring of sets. -/ theorem isSetRing (hπ’œ : IsSetAlgebra π’œ) : IsSetRing π’œ where empty_mem := hπ’œ.empty_mem union_mem := hπ’œ.union_mem diff_mem := fun _ _ ↦ hπ’œ.diff_mem /-- An algebra of sets is closed by finite unions. -/ theorem biUnion_mem {ΞΉ : Type*} (hπ’œ : IsSetAlgebra π’œ) {s : ΞΉ β†’ Set Ξ±} (S : Finset ΞΉ) (hs : βˆ€ i ∈ S, s i ∈ π’œ) : ⋃ i ∈ S, s i ∈ π’œ := hπ’œ.isSetRing.biUnion_mem S hs /-- An algebra of sets is closed by finite intersections. -/ theorem biInter_mem {ΞΉ : Type*} (hπ’œ : IsSetAlgebra π’œ) {s : ΞΉ β†’ Set Ξ±} (S : Finset ΞΉ) (hs : βˆ€ i ∈ S, s i ∈ π’œ) : β‹‚ i ∈ S, s i ∈ π’œ := by by_cases h : S = βˆ… Β· rw [h, ← Finset.set_biInter_coe, Finset.coe_empty, biInter_empty] exact hπ’œ.univ_mem Β· rw [← ne_eq, ← Finset.nonempty_iff_ne_empty] at h exact hπ’œ.isSetRing.biInter_mem S h hs end IsSetAlgebra section generateSetAlgebra /-! ### Definition and properties of the algebra of sets generated by some family -/ /-- `generateSetAlgebra π’œ` is the smallest algebra of sets containing `π’œ`. -/ inductive generateSetAlgebra {Ξ± : Type*} (π’œ : Set (Set Ξ±)) : Set (Set Ξ±) | base (s : Set Ξ±) (s_mem : s ∈ π’œ) : generateSetAlgebra π’œ s | empty : generateSetAlgebra π’œ βˆ… | compl (s : Set Ξ±) (hs : generateSetAlgebra π’œ s) : generateSetAlgebra π’œ sᢜ | union (s t : Set Ξ±) (hs : generateSetAlgebra π’œ s) (ht : generateSetAlgebra π’œ t) : generateSetAlgebra π’œ (s βˆͺ t) /-- The algebra of sets generated by a family of sets is an algebra of sets. -/ theorem isSetAlgebra_generateSetAlgebra : IsSetAlgebra (generateSetAlgebra π’œ) where empty_mem := generateSetAlgebra.empty compl_mem := fun _ hs ↦ generateSetAlgebra.compl _ hs union_mem := fun _ _ hs ht ↦ generateSetAlgebra.union _ _ hs ht /-- The algebra of sets generated by `π’œ` contains `π’œ`. -/ theorem self_subset_generateSetAlgebra : π’œ βŠ† generateSetAlgebra π’œ := fun _ ↦ generateSetAlgebra.base _ /-- The measurable space generated by a family of sets `π’œ` is the same as the one generated by the algebra of sets generated by `π’œ`. -/
@[simp] theorem generateFrom_generateSetAlgebra_eq : generateFrom (generateSetAlgebra π’œ) = generateFrom π’œ := by refine le_antisymm (fun s ms ↦ ?_) (generateFrom_mono self_subset_generateSetAlgebra) induction s, ms using generateFrom_induction with | hC t ht h => clear h induction ht with | base u u_mem => exact measurableSet_generateFrom u_mem | empty => exact @MeasurableSet.empty _ (generateFrom π’œ) | compl u _ mu => exact mu.compl | union u v _ _ mu mv => exact MeasurableSet.union mu mv | empty => exact MeasurableSpace.measurableSet_empty _
Mathlib/MeasureTheory/SetAlgebra.lean
122
134
/- Copyright (c) 2023 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll, Ralf Stephan -/ import Mathlib.Data.Nat.Factorization.Defs import Mathlib.Data.Nat.Squarefree /-! # Smooth numbers For `s : Finset β„•` we define the set `Nat.factoredNumbers s` of "`s`-factored numbers" consisting of the positive natural numbers all of whose prime factors are in `s`, and we provide some API for this. We then define the set `Nat.smoothNumbers n` consisting of the positive natural numbers all of whose prime factors are strictly less than `n`. This is the special case `s = Finset.range n` of the set of `s`-factored numbers. We also define the finite set `Nat.primesBelow n` to be the set of prime numbers less than `n`. The main definition `Nat.equivProdNatSmoothNumbers` establishes the bijection between `β„• Γ— (smoothNumbers p)` and `smoothNumbers (p+1)` given by sending `(e, n)` to `p^e * n`. Here `p` is a prime number. It is obtained from the more general bijection between `β„• Γ— (factoredNumbers s)` and `factoredNumbers (s βˆͺ {p})`; see `Nat.equivProdNatFactoredNumbers`. Additionally, we define `Nat.smoothNumbersUpTo N n` as the `Finset` of `n`-smooth numbers up to and including `N`, and similarly `Nat.roughNumbersUpTo` for its complement in `{1, ..., N}`, and we provide some API, in particular bounds for their cardinalities; see `Nat.smoothNumbersUpTo_card_le` and `Nat.roughNumbersUpTo_card_le`. -/ open scoped Finset namespace Nat /-- `primesBelow n` is the set of primes less than `n` as a `Finset`. -/ def primesBelow (n : β„•) : Finset β„• := {p ∈ Finset.range n | p.Prime} @[simp] lemma primesBelow_zero : primesBelow 0 = βˆ… := by rw [primesBelow, Finset.range_zero, Finset.filter_empty] lemma mem_primesBelow {k n : β„•} : n ∈ primesBelow k ↔ n < k ∧ n.Prime := by simp [primesBelow] lemma prime_of_mem_primesBelow {p n : β„•} (h : p ∈ n.primesBelow) : p.Prime := (Finset.mem_filter.mp h).2 lemma lt_of_mem_primesBelow {p n : β„•} (h : p ∈ n.primesBelow) : p < n := Finset.mem_range.mp <| Finset.mem_of_mem_filter p h lemma primesBelow_succ (n : β„•) : primesBelow (n + 1) = if n.Prime then insert n (primesBelow n) else primesBelow n := by rw [primesBelow, primesBelow, Finset.range_succ, Finset.filter_insert] lemma not_mem_primesBelow (n : β„•) : n βˆ‰ primesBelow n := fun hn ↦ (lt_of_mem_primesBelow hn).false /-! ### `s`-factored numbers -/ /-- `factoredNumbers s`, for a finite set `s` of natural numbers, is the set of positive natural numbers all of whose prime factors are in `s`. -/ def factoredNumbers (s : Finset β„•) : Set β„• := {m | m β‰  0 ∧ βˆ€ p ∈ primeFactorsList m, p ∈ s} lemma mem_factoredNumbers {s : Finset β„•} {m : β„•} : m ∈ factoredNumbers s ↔ m β‰  0 ∧ βˆ€ p ∈ primeFactorsList m, p ∈ s := Iff.rfl /-- Membership in `Nat.factoredNumbers n` is decidable. -/ instance (s : Finset β„•) : DecidablePred (Β· ∈ factoredNumbers s) := inferInstanceAs <| DecidablePred fun x ↦ x ∈ {m | m β‰  0 ∧ βˆ€ p ∈ primeFactorsList m, p ∈ s} /-- A number that divides an `s`-factored number is itself `s`-factored. -/ lemma mem_factoredNumbers_of_dvd {s : Finset β„•} {m k : β„•} (h : m ∈ factoredNumbers s) (h' : k ∣ m) : k ∈ factoredNumbers s := by obtain ⟨h₁, hβ‚‚βŸ© := h have hk := ne_zero_of_dvd_ne_zero h₁ h' refine ⟨hk, fun p hp ↦ hβ‚‚ p ?_⟩ rw [mem_primeFactorsList <| by assumption] at hp ⊒ exact ⟨hp.1, hp.2.trans h'⟩ /-- `m` is `s`-factored if and only if `m` is nonzero and all prime divisors `≀ m` of `m` are in `s`. -/ lemma mem_factoredNumbers_iff_forall_le {s : Finset β„•} {m : β„•} : m ∈ factoredNumbers s ↔ m β‰  0 ∧ βˆ€ p ≀ m, p.Prime β†’ p ∣ m β†’ p ∈ s := by simp_rw [mem_factoredNumbers, mem_primeFactorsList'] exact ⟨fun ⟨Hβ‚€, Hβ‚βŸ© ↦ ⟨Hβ‚€, fun p _ hpβ‚‚ hp₃ ↦ H₁ p ⟨hpβ‚‚, hp₃, Hβ‚€βŸ©βŸ©, fun ⟨Hβ‚€, Hβ‚βŸ© ↦ ⟨Hβ‚€, fun p ⟨hp₁, hpβ‚‚, hpβ‚ƒβŸ© ↦ H₁ p (le_of_dvd (Nat.pos_of_ne_zero hp₃) hpβ‚‚) hp₁ hpβ‚‚βŸ©βŸ© /-- `m` is `s`-factored if and only if all prime divisors of `m` are in `s`. -/ lemma mem_factoredNumbers' {s : Finset β„•} {m : β„•} : m ∈ factoredNumbers s ↔ βˆ€ p, p.Prime β†’ p ∣ m β†’ p ∈ s := by obtain ⟨p, hp₁, hpβ‚‚βŸ© := exists_infinite_primes (1 + Finset.sup s id) rw [mem_factoredNumbers_iff_forall_le] refine ⟨fun ⟨Hβ‚€, Hβ‚βŸ© ↦ fun p hp₁ hpβ‚‚ ↦ H₁ p (le_of_dvd (Nat.pos_of_ne_zero Hβ‚€) hpβ‚‚) hp₁ hpβ‚‚, fun H ↦ ⟨fun h ↦ lt_irrefl p ?_, fun p _ ↦ H p⟩⟩ calc p ≀ s.sup id := Finset.le_sup (f := @id β„•) <| H p hpβ‚‚ <| h.symm β–Έ dvd_zero p _ < 1 + s.sup id := lt_one_add _ _ ≀ p := hp₁ lemma ne_zero_of_mem_factoredNumbers {s : Finset β„•} {m : β„•} (h : m ∈ factoredNumbers s) : m β‰  0 := h.1 /-- The `Finset` of prime factors of an `s`-factored number is contained in `s`. -/ lemma primeFactors_subset_of_mem_factoredNumbers {s : Finset β„•} {m : β„•} (hm : m ∈ factoredNumbers s) : m.primeFactors βŠ† s := by rw [mem_factoredNumbers] at hm exact fun n hn ↦ hm.2 n (mem_primeFactors_iff_mem_primeFactorsList.mp hn) /-- If `m β‰  0` and the `Finset` of prime factors of `m` is contained in `s`, then `m` is `s`-factored. -/ lemma mem_factoredNumbers_of_primeFactors_subset {s : Finset β„•} {m : β„•} (hm : m β‰  0) (hp : m.primeFactors βŠ† s) : m ∈ factoredNumbers s := by rw [mem_factoredNumbers] exact ⟨hm, fun p hp' ↦ hp <| mem_primeFactors_iff_mem_primeFactorsList.mpr hp'⟩ /-- `m` is `s`-factored if and only if `m β‰  0` and its `Finset` of prime factors is contained in `s`. -/ lemma mem_factoredNumbers_iff_primeFactors_subset {s : Finset β„•} {m : β„•} : m ∈ factoredNumbers s ↔ m β‰  0 ∧ m.primeFactors βŠ† s := ⟨fun h ↦ ⟨ne_zero_of_mem_factoredNumbers h, primeFactors_subset_of_mem_factoredNumbers h⟩, fun ⟨h₁, hβ‚‚βŸ© ↦ mem_factoredNumbers_of_primeFactors_subset h₁ hβ‚‚βŸ© @[simp] lemma factoredNumbers_empty : factoredNumbers βˆ… = {1} := by ext m simp only [mem_factoredNumbers, Finset.not_mem_empty, ← List.eq_nil_iff_forall_not_mem, primeFactorsList_eq_nil, and_or_left, not_and_self_iff, ne_and_eq_iff_right zero_ne_one, false_or, Set.mem_singleton_iff] /-- The product of two `s`-factored numbers is again `s`-factored. -/ lemma mul_mem_factoredNumbers {s : Finset β„•} {m n : β„•} (hm : m ∈ factoredNumbers s) (hn : n ∈ factoredNumbers s) : m * n ∈ factoredNumbers s := by have hm' := primeFactors_subset_of_mem_factoredNumbers hm have hn' := primeFactors_subset_of_mem_factoredNumbers hn exact mem_factoredNumbers_of_primeFactors_subset (mul_ne_zero hm.1 hn.1) <| primeFactors_mul hm.1 hn.1 β–Έ Finset.union_subset hm' hn' /-- The product of the prime factors of `n` that are in `s` is an `s`-factored number. -/ lemma prod_mem_factoredNumbers (s : Finset β„•) (n : β„•) : (n.primeFactorsList.filter (Β· ∈ s)).prod ∈ factoredNumbers s := by have hβ‚€ : (n.primeFactorsList.filter (Β· ∈ s)).prod β‰  0 := List.prod_ne_zero fun h ↦ (pos_of_mem_primeFactorsList (List.mem_of_mem_filter h)).false refine ⟨hβ‚€, fun p hp ↦ ?_⟩ obtain ⟨H₁, Hβ‚‚βŸ© := (mem_primeFactorsList hβ‚€).mp hp simpa only [decide_eq_true_eq] using List.of_mem_filter <| mem_list_primes_of_dvd_prod H₁.prime (fun _ hq ↦ (prime_of_mem_primeFactorsList (List.mem_of_mem_filter hq)).prime) Hβ‚‚
/-- The sets of `s`-factored and of `s βˆͺ {N}`-factored numbers are the same when `N` is not prime. See `Nat.equivProdNatFactoredNumbers` for when `N` is prime. -/ lemma factoredNumbers_insert (s : Finset β„•) {N : β„•} (hN : Β¬ N.Prime) : factoredNumbers (insert N s) = factoredNumbers s := by ext m refine ⟨fun hm ↦ ⟨hm.1, fun p hp ↦ ?_⟩, fun hm ↦ ⟨hm.1, fun p hp ↦ Finset.mem_insert_of_mem <| hm.2 p hp⟩⟩
Mathlib/NumberTheory/SmoothNumbers.lean
157
164
/- 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.Algebra.Order.Group.Unbundled.Int import Mathlib.Algebra.Ring.Nat import Mathlib.Data.Int.GCD /-! # Congruences modulo a natural number This file defines the equivalence relation `a ≑ b [MOD n]` on the natural numbers, and proves basic properties about it such as the Chinese Remainder Theorem `modEq_and_modEq_iff_modEq_mul`. ## Notations `a ≑ b [MOD n]` is notation for `nat.ModEq n a b`, which is defined to mean `a % n = b % n`. ## Tags ModEq, congruence, mod, MOD, modulo -/ assert_not_exists OrderedAddCommMonoid Function.support namespace Nat /-- Modular equality. `n.ModEq a b`, or `a ≑ b [MOD n]`, means that `a - b` is a multiple of `n`. -/ def ModEq (n a b : β„•) := a % n = b % n @[inherit_doc] notation:50 a " ≑ " b " [MOD " n "]" => ModEq n a b variable {m n a b c d : β„•} -- Since `ModEq` is semi-reducible, we need to provide the decidable instance manually instance : Decidable (ModEq n a b) := inferInstanceAs <| Decidable (a % n = b % n) namespace ModEq @[refl] protected theorem refl (a : β„•) : a ≑ a [MOD n] := rfl protected theorem rfl : a ≑ a [MOD n] := ModEq.refl _ instance : IsRefl _ (ModEq n) := ⟨ModEq.refl⟩ @[symm] protected theorem symm : a ≑ b [MOD n] β†’ b ≑ a [MOD n] := Eq.symm @[trans] protected theorem trans : a ≑ b [MOD n] β†’ b ≑ c [MOD n] β†’ a ≑ c [MOD n] := Eq.trans instance : Trans (ModEq n) (ModEq n) (ModEq n) where trans := Nat.ModEq.trans protected theorem comm : a ≑ b [MOD n] ↔ b ≑ a [MOD n] := ⟨ModEq.symm, ModEq.symm⟩ end ModEq theorem modEq_zero_iff_dvd : a ≑ 0 [MOD n] ↔ n ∣ a := by rw [ModEq, zero_mod, dvd_iff_mod_eq_zero] theorem _root_.Dvd.dvd.modEq_zero_nat (h : n ∣ a) : a ≑ 0 [MOD n] := modEq_zero_iff_dvd.2 h theorem _root_.Dvd.dvd.zero_modEq_nat (h : n ∣ a) : 0 ≑ a [MOD n] := h.modEq_zero_nat.symm theorem modEq_iff_dvd : a ≑ b [MOD n] ↔ (n : β„€) ∣ b - a := by rw [ModEq, eq_comm, ← Int.natCast_inj, Int.natCast_mod, Int.natCast_mod, Int.emod_eq_emod_iff_emod_sub_eq_zero, Int.dvd_iff_emod_eq_zero] alias ⟨ModEq.dvd, modEq_of_dvd⟩ := modEq_iff_dvd /-- A variant of `modEq_iff_dvd` with `Nat` divisibility -/ theorem modEq_iff_dvd' (h : a ≀ b) : a ≑ b [MOD n] ↔ n ∣ b - a := by rw [modEq_iff_dvd, ← Int.natCast_dvd_natCast, Int.ofNat_sub h] theorem mod_modEq (a n) : a % n ≑ a [MOD n] := mod_mod _ _ namespace ModEq lemma of_dvd (d : m ∣ n) (h : a ≑ b [MOD n]) : a ≑ b [MOD m] := modEq_of_dvd <| Int.ofNat_dvd.mpr d |>.trans h.dvd protected theorem mul_left' (c : β„•) (h : a ≑ b [MOD n]) : c * a ≑ c * b [MOD c * n] := by unfold ModEq at *; rw [mul_mod_mul_left, mul_mod_mul_left, h] @[gcongr] protected theorem mul_left (c : β„•) (h : a ≑ b [MOD n]) : c * a ≑ c * b [MOD n] := (h.mul_left' _).of_dvd (dvd_mul_left _ _) protected theorem mul_right' (c : β„•) (h : a ≑ b [MOD n]) : a * c ≑ b * c [MOD n * c] := by rw [mul_comm a, mul_comm b, mul_comm n]; exact h.mul_left' c @[gcongr] protected theorem mul_right (c : β„•) (h : a ≑ b [MOD n]) : a * c ≑ b * c [MOD n] := by rw [mul_comm a, mul_comm b]; exact h.mul_left c @[gcongr] protected theorem mul (h₁ : a ≑ b [MOD n]) (hβ‚‚ : c ≑ d [MOD n]) : a * c ≑ b * d [MOD n] := (hβ‚‚.mul_left _).trans (h₁.mul_right _) @[gcongr] protected theorem pow (m : β„•) (h : a ≑ b [MOD n]) : a ^ m ≑ b ^ m [MOD n] := by induction m with | zero => rfl | succ d hd => rw [Nat.pow_succ, Nat.pow_succ] exact hd.mul h @[gcongr] protected theorem add (h₁ : a ≑ b [MOD n]) (hβ‚‚ : c ≑ d [MOD n]) : a + c ≑ b + d [MOD n] := by rw [modEq_iff_dvd, Int.natCast_add, Int.natCast_add, add_sub_add_comm] exact Int.dvd_add h₁.dvd hβ‚‚.dvd @[gcongr] protected theorem add_left (c : β„•) (h : a ≑ b [MOD n]) : c + a ≑ c + b [MOD n] := ModEq.rfl.add h @[gcongr] protected theorem add_right (c : β„•) (h : a ≑ b [MOD n]) : a + c ≑ b + c [MOD n] := h.add ModEq.rfl protected theorem add_left_cancel (h₁ : a ≑ b [MOD n]) (hβ‚‚ : a + c ≑ b + d [MOD n]) : c ≑ d [MOD n] := by simp only [modEq_iff_dvd, Int.natCast_add] at * rw [add_sub_add_comm] at hβ‚‚ convert Int.dvd_sub hβ‚‚ h₁ using 1 rw [add_sub_cancel_left] protected theorem add_left_cancel' (c : β„•) (h : c + a ≑ c + b [MOD n]) : a ≑ b [MOD n] := ModEq.rfl.add_left_cancel h protected theorem add_right_cancel (h₁ : c ≑ d [MOD n]) (hβ‚‚ : a + c ≑ b + d [MOD n]) : a ≑ b [MOD n] := by
rw [add_comm a, add_comm b] at hβ‚‚ exact h₁.add_left_cancel hβ‚‚
Mathlib/Data/Nat/ModEq.lean
146
148
/- Copyright (c) 2023 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Algebra.Algebra.Unitization import Mathlib.Algebra.Star.Subalgebra import Mathlib.GroupTheory.GroupAction.Ring /-! # Relating unital and non-unital substructures This file relates various algebraic structures and provides maps (generally algebra homomorphisms), from the unitization of a non-unital subobject into the full structure. The range of this map is the unital closure of the non-unital subobject (e.g., `Algebra.adjoin`, `Subring.closure`, `Subsemiring.closure` or `StarAlgebra.adjoin`). When the underlying scalar ring is a field, for this map to be injective it suffices that the range omits `1`. In this setting we provide suitable `AlgEquiv` (or `StarAlgEquiv`) onto the range. ## Main declarations * `NonUnitalSubalgebra.unitization s : Unitization R s →ₐ[R] A`: where `s` is a non-unital subalgebra of a unital `R`-algebra `A`, this is the natural algebra homomorphism sending `(r, a)` to `r β€’ 1 + a`. The range of this map is `Algebra.adjoin R (s : Set A)`. * `NonUnitalSubalgebra.unitizationAlgEquiv s : Unitization R s ≃ₐ[R] Algebra.adjoin R (s : Set A)` when `R` is a field and `1 βˆ‰ s`. This is `NonUnitalSubalgebra.unitization` upgraded to an `AlgEquiv` onto its range. * `NonUnitalSubsemiring.unitization : Unitization β„• s →ₐ[β„•] R`: the natural `β„•`-algebra homomorphism from the unitization of a non-unital subsemiring `s` into the ring containing it. The range of this map is `subalgebraOfSubsemiring (Subsemiring.closure s)`. This is just `NonUnitalSubalgebra.unitization s` but we provide a separate declaration because there is an instance Lean can't find on its own due to `outParam`. * `NonUnitalSubring.unitization : Unitization β„€ s →ₐ[β„€] R`: the natural `β„€`-algebra homomorphism from the unitization of a non-unital subring `s` into the ring containing it. The range of this map is `subalgebraOfSubring (Subring.closure s)`. This is just `NonUnitalSubalgebra.unitization s` but we provide a separate declaration because there is an instance Lean can't find on its own due to `outParam`. * `NonUnitalStarSubalgebra s : Unitization R s →⋆ₐ[R] A`: a version of `NonUnitalSubalgebra.unitization` for star algebras. * `NonUnitalStarSubalgebra.unitizationStarAlgEquiv s :` `Unitization R s ≃⋆ₐ[R] StarAlgebra.adjoin R (s : Set A)`: a version of `NonUnitalSubalgebra.unitizationAlgEquiv` for star algebras. -/ /-! ## Subalgebras -/ namespace Unitization variable {R A C : Type*} [CommSemiring R] [NonUnitalSemiring A] variable [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] [Semiring C] [Algebra R C] theorem lift_range_le {f : A →ₙₐ[R] C} {S : Subalgebra R C} : (lift f).range ≀ S ↔ NonUnitalAlgHom.range f ≀ S.toNonUnitalSubalgebra := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ Β· rintro - ⟨x, rfl⟩ exact @h (f x) ⟨x, by simp⟩ Β· rintro - ⟨x, rfl⟩ induction x with | _ r a => simpa using add_mem (algebraMap_mem S r) (h ⟨a, rfl⟩) theorem lift_range (f : A →ₙₐ[R] C) : (lift f).range = Algebra.adjoin R (NonUnitalAlgHom.range f : Set C) := eq_of_forall_ge_iff fun c ↦ by rw [lift_range_le, Algebra.adjoin_le_iff]; rfl end Unitization namespace NonUnitalSubalgebra section Semiring variable {R S A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [SetLike S A] [hSA : NonUnitalSubsemiringClass S A] [hSRA : SMulMemClass S R A] (s : S) /-- The natural `R`-algebra homomorphism from the unitization of a non-unital subalgebra into the algebra containing it. -/ def unitization : Unitization R s →ₐ[R] A := Unitization.lift (NonUnitalSubalgebraClass.subtype s) @[simp] theorem unitization_apply (x : Unitization R s) : unitization s x = algebraMap R A x.fst + x.snd := rfl theorem unitization_range : (unitization s).range = Algebra.adjoin R (s : Set A) := by rw [unitization, Unitization.lift_range] simp only [NonUnitalAlgHom.coe_range, NonUnitalSubalgebraClass.coe_subtype, Subtype.range_coe_subtype, SetLike.mem_coe] rfl end Semiring /-- A sufficient condition for injectivity of `NonUnitalSubalgebra.unitization` when the scalars are a commutative ring. When the scalars are a field, one should use the more natural `NonUnitalStarSubalgebra.unitization_injective` whose hypothesis is easier to verify. -/ theorem _root_.AlgHomClass.unitization_injective' {F R S A : Type*} [CommRing R] [Ring A] [Algebra R A] [SetLike S A] [hSA : NonUnitalSubringClass S A] [hSRA : SMulMemClass S R A] (s : S) (h : βˆ€ r, r β‰  0 β†’ algebraMap R A r βˆ‰ s) [FunLike F (Unitization R s) A] [AlgHomClass F R (Unitization R s) A] (f : F) (hf : βˆ€ x : s, f x = x) : Function.Injective f := by refine (injective_iff_map_eq_zero f).mpr fun x hx => ?_ induction x with | inl_add_inr r a => simp_rw [map_add, hf, ← Unitization.algebraMap_eq_inl, AlgHomClass.commutes] at hx rw [add_eq_zero_iff_eq_neg] at hx ⊒ by_cases hr : r = 0 Β· ext Β· simp [hr] Β· simpa [hr] using hx Β· exact (h r hr <| hx β–Έ (neg_mem a.property)).elim /-- This is a generic version which allows us to prove both `NonUnitalSubalgebra.unitization_injective` and `NonUnitalStarSubalgebra.unitization_injective`. -/ theorem _root_.AlgHomClass.unitization_injective {F R S A : Type*} [Field R] [Ring A] [Algebra R A] [SetLike S A] [hSA : NonUnitalSubringClass S A] [hSRA : SMulMemClass S R A] (s : S) (h1 : 1 βˆ‰ s) [FunLike F (Unitization R s) A] [AlgHomClass F R (Unitization R s) A] (f : F) (hf : βˆ€ x : s, f x = x) : Function.Injective f := by refine AlgHomClass.unitization_injective' s (fun r hr hr' ↦ ?_) f hf rw [Algebra.algebraMap_eq_smul_one] at hr' exact h1 <| inv_smul_smulβ‚€ hr (1 : A) β–Έ SMulMemClass.smul_mem r⁻¹ hr' section Field variable {R S A : Type*} [Field R] [Ring A] [Algebra R A] [SetLike S A] [hSA : NonUnitalSubringClass S A] [hSRA : SMulMemClass S R A] (s : S) theorem unitization_injective (h1 : (1 : A) βˆ‰ s) : Function.Injective (unitization s) := AlgHomClass.unitization_injective s h1 (unitization s) fun _ ↦ by simp /-- If a `NonUnitalSubalgebra` over a field does not contain `1`, then its unitization is isomorphic to its `Algebra.adjoin`. -/ @[simps! apply_coe] noncomputable def unitizationAlgEquiv (h1 : (1 : A) βˆ‰ s) : Unitization R s ≃ₐ[R] Algebra.adjoin R (s : Set A) := let algHom : Unitization R s →ₐ[R] Algebra.adjoin R (s : Set A) := ((unitization s).codRestrict _ fun x ↦ (unitization_range s).le <| AlgHom.mem_range_self _ x) AlgEquiv.ofBijective algHom <| by refine ⟨?_, fun x ↦ ?_⟩ Β· have := AlgHomClass.unitization_injective s h1 ((Subalgebra.val _).comp algHom) fun _ ↦ by simp [algHom] rw [AlgHom.coe_comp] at this exact this.of_comp Β· obtain (⟨a, ha⟩ : (x : A) ∈ (unitization s).range) := (unitization_range s).ge x.property exact ⟨a, Subtype.ext ha⟩ end Field end NonUnitalSubalgebra /-! ## Subsemirings -/ namespace NonUnitalSubsemiring variable {R S : Type*} [Semiring R] [SetLike S R] [hSR : NonUnitalSubsemiringClass S R] (s : S) /-- The natural `β„•`-algebra homomorphism from the unitization of a non-unital subsemiring to its `Subsemiring.closure`. -/ def unitization : Unitization β„• s →ₐ[β„•] R := NonUnitalSubalgebra.unitization (hSRA := AddSubmonoidClass.nsmulMemClass) s @[simp] theorem unitization_apply (x : Unitization β„• s) : unitization s x = x.fst + x.snd := rfl theorem unitization_range : (unitization s).range = subalgebraOfSubsemiring (.closure s) := by have := AddSubmonoidClass.nsmulMemClass (S := S) rw [unitization, NonUnitalSubalgebra.unitization_range (hSRA := this), Algebra.adjoin_nat] end NonUnitalSubsemiring /-! ## Subrings -/ namespace NonUnitalSubring variable {R S : Type*} [Ring R] [SetLike S R] [hSR : NonUnitalSubringClass S R] (s : S) /-- The natural `β„€`-algebra homomorphism from the unitization of a non-unital subring to its `Subring.closure`. -/ def unitization : Unitization β„€ s →ₐ[β„€] R := NonUnitalSubalgebra.unitization (hSRA := AddSubgroupClass.zsmulMemClass) s @[simp] theorem unitization_apply (x : Unitization β„€ s) : unitization s x = x.fst + x.snd := rfl theorem unitization_range : (unitization s).range = subalgebraOfSubring (.closure s) := by have := AddSubgroupClass.zsmulMemClass (S := S) rw [unitization, NonUnitalSubalgebra.unitization_range (hSRA := this), Algebra.adjoin_int] end NonUnitalSubring /-! ## Star subalgebras -/ namespace Unitization variable {R A C : Type*} [CommSemiring R] [NonUnitalSemiring A] [StarRing R] [StarRing A] variable [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] [StarModule R A] variable [Semiring C] [StarRing C] [Algebra R C] [StarModule R C] theorem starLift_range_le {f : A →⋆ₙₐ[R] C} {S : StarSubalgebra R C} : (starLift f).range ≀ S ↔ NonUnitalStarAlgHom.range f ≀ S.toNonUnitalStarSubalgebra := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ Β· rintro - ⟨x, rfl⟩ exact @h (f x) ⟨x, by simp⟩ Β· rintro - ⟨x, rfl⟩ induction x with | _ r a => simpa using add_mem (algebraMap_mem S r) (h ⟨a, rfl⟩) theorem starLift_range (f : A →⋆ₙₐ[R] C) : (starLift f).range = StarAlgebra.adjoin R (NonUnitalStarAlgHom.range f : Set C) := eq_of_forall_ge_iff fun c ↦ by rw [starLift_range_le, StarAlgebra.adjoin_le_iff] rfl end Unitization namespace NonUnitalStarSubalgebra section Semiring variable {R S A : Type*} [CommSemiring R] [StarRing R] [Semiring A] [StarRing A] [Algebra R A] [StarModule R A] [SetLike S A] [hSA : NonUnitalSubsemiringClass S A] [hSRA : SMulMemClass S R A] [StarMemClass S A] (s : S) /-- The natural star `R`-algebra homomorphism from the unitization of a non-unital star subalgebra to its `StarAlgebra.adjoin`. -/ def unitization : Unitization R s →⋆ₐ[R] A := Unitization.starLift <| NonUnitalStarSubalgebraClass.subtype s @[simp] theorem unitization_apply (x : Unitization R s) : unitization s x = algebraMap R A x.fst + x.snd := rfl theorem unitization_range : (unitization s).range = StarAlgebra.adjoin R s := by rw [unitization, Unitization.starLift_range] simp only [NonUnitalStarAlgHom.coe_range, NonUnitalStarSubalgebraClass.coe_subtype, Subtype.range_coe_subtype] rfl end Semiring section Field variable {R S A : Type*} [Field R] [StarRing R] [Ring A] [StarRing A] [Algebra R A] [StarModule R A] [SetLike S A] [hSA : NonUnitalSubringClass S A] [hSRA : SMulMemClass S R A] [StarMemClass S A] (s : S) theorem unitization_injective (h1 : (1 : A) βˆ‰ s) : Function.Injective (unitization s) := AlgHomClass.unitization_injective s h1 (unitization s) fun _ ↦ by simp /-- If a `NonUnitalStarSubalgebra` over a field does not contain `1`, then its unitization is isomorphic to its `StarAlgebra.adjoin`. -/ @[simps! apply_coe] noncomputable def unitizationStarAlgEquiv (h1 : (1 : A) βˆ‰ s) : Unitization R s ≃⋆ₐ[R] StarAlgebra.adjoin R (s : Set A) := let starAlgHom : Unitization R s →⋆ₐ[R] StarAlgebra.adjoin R (s : Set A) := ((unitization s).codRestrict _ fun x ↦ (unitization_range s).le <| Set.mem_range_self x) StarAlgEquiv.ofBijective starAlgHom <| by refine ⟨?_, fun x ↦ ?_⟩ Β· have := AlgHomClass.unitization_injective s h1 ((StarSubalgebra.subtype _).comp starAlgHom) fun _ ↦ by simp [starAlgHom] rw [StarAlgHom.coe_comp] at this exact this.of_comp Β· obtain (⟨a, ha⟩ : (x : A) ∈ (unitization s).range) := (unitization_range s).ge x.property exact ⟨a, Subtype.ext ha⟩ end Field end NonUnitalStarSubalgebra
Mathlib/Algebra/Algebra/Subalgebra/Unitization.lean
322
323
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.MeasureTheory.Constructions.BorelSpace.Metric import Mathlib.MeasureTheory.Constructions.BorelSpace.Real import Mathlib.Topology.Metrizable.Real import Mathlib.Topology.IndicatorConstPointwise /-! # Measurable functions in (pseudo-)metrizable Borel spaces -/ open Filter MeasureTheory TopologicalSpace Topology NNReal ENNReal MeasureTheory variable {Ξ± Ξ² : Type*} [MeasurableSpace Ξ±] section Limits variable [TopologicalSpace Ξ²] [PseudoMetrizableSpace Ξ²] [MeasurableSpace Ξ²] [BorelSpace Ξ²] open Metric /-- A limit (over a general filter) of measurable functions valued in a (pseudo) metrizable space is measurable. -/ theorem measurable_of_tendsto_metrizable' {ΞΉ} {f : ΞΉ β†’ Ξ± β†’ Ξ²} {g : Ξ± β†’ Ξ²} (u : Filter ΞΉ) [NeBot u] [IsCountablyGenerated u] (hf : βˆ€ i, Measurable (f i)) (lim : Tendsto f u (𝓝 g)) : Measurable g := by letI : PseudoMetricSpace Ξ² := pseudoMetrizableSpacePseudoMetric Ξ² apply measurable_of_isClosed' intro s h1s h2s h3s have : Measurable fun x => infNndist (g x) s := by suffices Tendsto (fun i x => infNndist (f i x) s) u (𝓝 fun x => infNndist (g x) s) from NNReal.measurable_of_tendsto' u (fun i => (hf i).infNndist) this rw [tendsto_pi_nhds] at lim ⊒ intro x exact ((continuous_infNndist_pt s).tendsto (g x)).comp (lim x) have h4s : g ⁻¹' s = (fun x => infNndist (g x) s) ⁻¹' {0} := by ext x simp [h1s, ← h1s.mem_iff_infDist_zero h2s, ← NNReal.coe_eq_zero] rw [h4s] exact this (measurableSet_singleton 0) /-- A sequential limit of measurable functions valued in a (pseudo) metrizable space is measurable. -/ theorem measurable_of_tendsto_metrizable {f : β„• β†’ Ξ± β†’ Ξ²} {g : Ξ± β†’ Ξ²} (hf : βˆ€ i, Measurable (f i)) (lim : Tendsto f atTop (𝓝 g)) : Measurable g := measurable_of_tendsto_metrizable' atTop hf lim theorem aemeasurable_of_tendsto_metrizable_ae {ΞΉ} {ΞΌ : Measure Ξ±} {f : ΞΉ β†’ Ξ± β†’ Ξ²} {g : Ξ± β†’ Ξ²} (u : Filter ΞΉ) [hu : NeBot u] [IsCountablyGenerated u] (hf : βˆ€ n, AEMeasurable (f n) ΞΌ) (h_tendsto : βˆ€α΅ x βˆ‚ΞΌ, Tendsto (fun n => f n x) u (𝓝 (g x))) : AEMeasurable g ΞΌ := by classical rcases u.exists_seq_tendsto with ⟨v, hv⟩ have h'f : βˆ€ n, AEMeasurable (f (v n)) ΞΌ := fun n => hf (v n) set p : Ξ± β†’ (β„• β†’ Ξ²) β†’ Prop := fun x f' => Tendsto (fun n => f' n) atTop (𝓝 (g x)) have hp : βˆ€α΅ x βˆ‚ΞΌ, p x fun n => f (v n) x := by filter_upwards [h_tendsto] with x hx using hx.comp hv set aeSeqLim := fun x => ite (x ∈ aeSeqSet h'f p) (g x) (⟨f (v 0) x⟩ : Nonempty Ξ²).some refine ⟨aeSeqLim, measurable_of_tendsto_metrizable' atTop (aeSeq.measurable h'f p) (tendsto_pi_nhds.mpr fun x => ?_), ?_⟩ Β· simp_rw [aeSeqLim, aeSeq] split_ifs with hx Β· simp_rw [aeSeq.mk_eq_fun_of_mem_aeSeqSet h'f hx] exact @aeSeq.fun_prop_of_mem_aeSeqSet _ Ξ± Ξ² _ _ _ _ _ h'f x hx Β· exact tendsto_const_nhds Β· exact (ite_ae_eq_of_measure_compl_zero g (fun x => (⟨f (v 0) x⟩ : Nonempty Ξ²).some) (aeSeqSet h'f p) (aeSeq.measure_compl_aeSeqSet_eq_zero h'f hp)).symm theorem aemeasurable_of_tendsto_metrizable_ae' {ΞΌ : Measure Ξ±} {f : β„• β†’ Ξ± β†’ Ξ²} {g : Ξ± β†’ Ξ²} (hf : βˆ€ n, AEMeasurable (f n) ΞΌ) (h_ae_tendsto : βˆ€α΅ x βˆ‚ΞΌ, Tendsto (fun n => f n x) atTop (𝓝 (g x))) : AEMeasurable g ΞΌ := aemeasurable_of_tendsto_metrizable_ae atTop hf h_ae_tendsto theorem aemeasurable_of_unif_approx {Ξ²} [MeasurableSpace Ξ²] [PseudoMetricSpace Ξ²] [BorelSpace Ξ²] {ΞΌ : Measure Ξ±} {g : Ξ± β†’ Ξ²} (hf : βˆ€ Ξ΅ > (0 : ℝ), βˆƒ f : Ξ± β†’ Ξ², AEMeasurable f ΞΌ ∧ βˆ€α΅ x βˆ‚ΞΌ, dist (f x) (g x) ≀ Ξ΅) : AEMeasurable g ΞΌ := by obtain ⟨u, -, u_pos, u_lim⟩ : βˆƒ u : β„• β†’ ℝ, StrictAnti u ∧ (βˆ€ n : β„•, 0 < u n) ∧ Tendsto u atTop (𝓝 0) := exists_seq_strictAnti_tendsto (0 : ℝ) choose f Hf using fun n : β„• => hf (u n) (u_pos n) have : βˆ€α΅ x βˆ‚ΞΌ, Tendsto (fun n => f n x) atTop (𝓝 (g x)) := by have : βˆ€α΅ x βˆ‚ΞΌ, βˆ€ n, dist (f n x) (g x) ≀ u n := ae_all_iff.2 fun n => (Hf n).2 filter_upwards [this] intro x hx rw [tendsto_iff_dist_tendsto_zero] exact squeeze_zero (fun n => dist_nonneg) hx u_lim exact aemeasurable_of_tendsto_metrizable_ae' (fun n => (Hf n).1) this theorem measurable_of_tendsto_metrizable_ae {ΞΌ : Measure Ξ±} [ΞΌ.IsComplete] {f : β„• β†’ Ξ± β†’ Ξ²} {g : Ξ± β†’ Ξ²} (hf : βˆ€ n, Measurable (f n)) (h_ae_tendsto : βˆ€α΅ x βˆ‚ΞΌ, Tendsto (fun n => f n x) atTop (𝓝 (g x))) : Measurable g := aemeasurable_iff_measurable.mp (aemeasurable_of_tendsto_metrizable_ae' (fun i => (hf i).aemeasurable) h_ae_tendsto) theorem measurable_limit_of_tendsto_metrizable_ae {ΞΉ} [Countable ΞΉ] [Nonempty ΞΉ] {ΞΌ : Measure Ξ±} {f : ΞΉ β†’ Ξ± β†’ Ξ²} {L : Filter ΞΉ} [L.IsCountablyGenerated] (hf : βˆ€ n, AEMeasurable (f n) ΞΌ) (h_ae_tendsto : βˆ€α΅ x βˆ‚ΞΌ, βˆƒ l : Ξ², Tendsto (fun n => f n x) L (𝓝 l)) : βˆƒ f_lim : Ξ± β†’ Ξ², Measurable f_lim ∧ βˆ€α΅ x βˆ‚ΞΌ, Tendsto (fun n => f n x) L (𝓝 (f_lim x)) := by classical inhabit ΞΉ rcases eq_or_neBot L with (rfl | hL) Β· exact ⟨(hf default).mk _, (hf default).measurable_mk, Eventually.of_forall fun x => tendsto_bot⟩ let p : Ξ± β†’ (ΞΉ β†’ Ξ²) β†’ Prop := fun x f' => βˆƒ l : Ξ², Tendsto (fun n => f' n) L (𝓝 l) have hp_mem : βˆ€ x ∈ aeSeqSet hf p, p x fun n => f n x := fun x hx => aeSeq.fun_prop_of_mem_aeSeqSet hf hx have h_ae_eq : βˆ€α΅ x βˆ‚ΞΌ, βˆ€ n, aeSeq hf p n x = f n x := aeSeq.aeSeq_eq_fun_ae hf h_ae_tendsto set f_lim : Ξ± β†’ Ξ² := fun x => dite (x ∈ aeSeqSet hf p) (fun h => (hp_mem x h).choose) fun _ => (⟨f default x⟩ : Nonempty Ξ²).some have hf_lim : βˆ€ x, Tendsto (fun n => aeSeq hf p n x) L (𝓝 (f_lim x)) := by intro x simp only [aeSeq, f_lim] split_ifs with h Β· refine (hp_mem x h).choose_spec.congr fun n => ?_ exact (aeSeq.mk_eq_fun_of_mem_aeSeqSet hf h n).symm Β· exact tendsto_const_nhds have h_ae_tendsto_f_lim : βˆ€α΅ x βˆ‚ΞΌ, Tendsto (fun n => f n x) L (𝓝 (f_lim x)) := h_ae_eq.mono fun x hx => (hf_lim x).congr hx have h_f_lim_meas : Measurable f_lim := measurable_of_tendsto_metrizable' L (aeSeq.measurable hf p) (tendsto_pi_nhds.mpr fun x => hf_lim x) exact ⟨f_lim, h_f_lim_meas, h_ae_tendsto_f_lim⟩ end Limits section TendstoIndicator variable {Ξ± : Type*} [MeasurableSpace Ξ±] {A : Set Ξ±} variable {ΞΉ : Type*} (L : Filter ΞΉ) [IsCountablyGenerated L] {As : ΞΉ β†’ Set Ξ±} /-- If the indicator functions of measurable sets `Aα΅’` converge to the indicator function of a set `A` along a nontrivial countably generated filter, then `A` is also measurable. -/ lemma measurableSet_of_tendsto_indicator [NeBot L] (As_mble : βˆ€ i, MeasurableSet (As i)) (h_lim : βˆ€ x, βˆ€αΆ  i in L, x ∈ As i ↔ x ∈ A) : MeasurableSet A := by simp_rw [← measurable_indicator_const_iff (1 : ℝβ‰₯0∞)] at As_mble ⊒ exact ENNReal.measurable_of_tendsto' L As_mble ((tendsto_indicator_const_iff_forall_eventually L (1 : ℝβ‰₯0∞)).mpr h_lim) /-- If the indicator functions of a.e.-measurable sets `Aα΅’` converge a.e. to the indicator function of a set `A` along a nontrivial countably generated filter, then `A` is also a.e.-measurable. -/ lemma nullMeasurableSet_of_tendsto_indicator [NeBot L] {ΞΌ : Measure Ξ±} (As_mble : βˆ€ i, NullMeasurableSet (As i) ΞΌ) (h_lim : βˆ€α΅ x βˆ‚ΞΌ, βˆ€αΆ  i in L, x ∈ As i ↔ x ∈ A) : NullMeasurableSet A ΞΌ := by simp_rw [← aemeasurable_indicator_const_iff (1 : ℝβ‰₯0∞)] at As_mble ⊒ apply aemeasurable_of_tendsto_metrizable_ae L As_mble simpa [tendsto_indicator_const_apply_iff_eventually] using h_lim
end TendstoIndicator
Mathlib/MeasureTheory/Constructions/BorelSpace/Metrizable.lean
155
163
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Alex Kontorovich -/ import Mathlib.Data.Set.Piecewise import Mathlib.Order.Filter.Tendsto import Mathlib.Order.Filter.Bases.Finite /-! # (Co)product of a family of filters In this file we define two filters on `Ξ  i, Ξ± i` and prove some basic properties of these filters. * `Filter.pi (f : Ξ  i, Filter (Ξ± i))` to be the maximal filter on `Ξ  i, Ξ± i` such that `βˆ€ i, Filter.Tendsto (Function.eval i) (Filter.pi f) (f i)`. It is defined as `Ξ  i, Filter.comap (Function.eval i) (f i)`. This is a generalization of `Filter.prod` to indexed products. * `Filter.coprodα΅’ (f : Ξ  i, Filter (Ξ± i))`: a generalization of `Filter.coprod`; it is the supremum of `comap (eval i) (f i)`. -/ open Set Function Filter namespace Filter variable {ΞΉ : Type*} {Ξ± : ΞΉ β†’ Type*} {f f₁ fβ‚‚ : (i : ΞΉ) β†’ Filter (Ξ± i)} {s : (i : ΞΉ) β†’ Set (Ξ± i)} {p : βˆ€ i, Ξ± i β†’ Prop} section Pi theorem tendsto_eval_pi (f : βˆ€ i, Filter (Ξ± i)) (i : ΞΉ) : Tendsto (eval i) (pi f) (f i) := tendsto_iInf' i tendsto_comap theorem tendsto_pi {Ξ² : Type*} {m : Ξ² β†’ βˆ€ i, Ξ± i} {l : Filter Ξ²} : Tendsto m l (pi f) ↔ βˆ€ i, Tendsto (fun x => m x i) l (f i) := by simp only [pi, tendsto_iInf, tendsto_comap_iff]; rfl /-- If a function tends to a product `Filter.pi f` of filters, then its `i`-th component tends to `f i`. See also `Filter.Tendsto.apply_nhds` for the special case of converging to a point in a product of topological spaces. -/ alias ⟨Tendsto.apply, _⟩ := tendsto_pi theorem le_pi {g : Filter (βˆ€ i, Ξ± i)} : g ≀ pi f ↔ βˆ€ i, Tendsto (eval i) g (f i) := tendsto_pi @[mono] theorem pi_mono (h : βˆ€ i, f₁ i ≀ fβ‚‚ i) : pi f₁ ≀ pi fβ‚‚ := iInf_mono fun i => comap_mono <| h i theorem mem_pi_of_mem (i : ΞΉ) {s : Set (Ξ± i)} (hs : s ∈ f i) : eval i ⁻¹' s ∈ pi f := mem_iInf_of_mem i <| preimage_mem_comap hs theorem pi_mem_pi {I : Set ΞΉ} (hI : I.Finite) (h : βˆ€ i ∈ I, s i ∈ f i) : I.pi s ∈ pi f := by rw [pi_def, biInter_eq_iInter] refine mem_iInf_of_iInter hI (fun i => ?_) Subset.rfl exact preimage_mem_comap (h i i.2) theorem mem_pi {s : Set (βˆ€ i, Ξ± i)} : s ∈ pi f ↔ βˆƒ I : Set ΞΉ, I.Finite ∧ βˆƒ t : βˆ€ i, Set (Ξ± i), (βˆ€ i, t i ∈ f i) ∧ I.pi t βŠ† s := by constructor Β· simp only [pi, mem_iInf', mem_comap, pi_def] rintro ⟨I, If, V, hVf, -, rfl, -⟩ choose t htf htV using hVf exact ⟨I, If, t, htf, iInterβ‚‚_mono fun i _ => htV i⟩ Β· rintro ⟨I, If, t, htf, hts⟩ exact mem_of_superset (pi_mem_pi If fun i _ => htf i) hts theorem mem_pi' {s : Set (βˆ€ i, Ξ± i)} : s ∈ pi f ↔ βˆƒ I : Finset ΞΉ, βˆƒ t : βˆ€ i, Set (Ξ± i), (βˆ€ i, t i ∈ f i) ∧ Set.pi (↑I) t βŠ† s := mem_pi.trans exists_finite_iff_finset theorem mem_of_pi_mem_pi [βˆ€ i, NeBot (f i)] {I : Set ΞΉ} (h : I.pi s ∈ pi f) {i : ΞΉ} (hi : i ∈ I) : s i ∈ f i := by classical rcases mem_pi.1 h with ⟨I', -, t, htf, hts⟩ refine mem_of_superset (htf i) fun x hx => ?_ have : βˆ€ i, (t i).Nonempty := fun i => nonempty_of_mem (htf i) choose g hg using this have : update g i x ∈ I'.pi t := fun j _ => by rcases eq_or_ne j i with (rfl | hne) <;> simp [*] simpa using hts this i hi @[simp] theorem pi_mem_pi_iff [βˆ€ i, NeBot (f i)] {I : Set ΞΉ} (hI : I.Finite) : I.pi s ∈ pi f ↔ βˆ€ i ∈ I, s i ∈ f i := ⟨fun h _i hi => mem_of_pi_mem_pi h hi, pi_mem_pi hI⟩ theorem Eventually.eval_pi {i : ΞΉ} (hf : βˆ€αΆ  x : Ξ± i in f i, p i x) : βˆ€αΆ  x : βˆ€ i : ΞΉ, Ξ± i in pi f, p i (x i) := (tendsto_eval_pi _ _).eventually hf theorem eventually_pi [Finite ΞΉ] (hf : βˆ€ i, βˆ€αΆ  x in f i, p i x) : βˆ€αΆ  x : βˆ€ i, Ξ± i in pi f, βˆ€ i, p i (x i) := eventually_all.2 fun _i => (hf _).eval_pi theorem hasBasis_pi {ΞΉ' : ΞΉ β†’ Type*} {s : βˆ€ i, ΞΉ' i β†’ Set (Ξ± i)} {p : βˆ€ i, ΞΉ' i β†’ Prop} (h : βˆ€ i, (f i).HasBasis (p i) (s i)) : (pi f).HasBasis (fun If : Set ΞΉ Γ— βˆ€ i, ΞΉ' i => If.1.Finite ∧ βˆ€ i ∈ If.1, p i (If.2 i)) fun If : Set ΞΉ Γ— βˆ€ i, ΞΉ' i => If.1.pi fun i => s i <| If.2 i := by simpa [Set.pi_def] using hasBasis_iInf' fun i => (h i).comap (eval i : (βˆ€ j, Ξ± j) β†’ Ξ± i) theorem hasBasis_pi_same_index {ΞΊ : Type*} {p : ΞΊ β†’ Prop} {s : Ξ  i : ΞΉ, ΞΊ β†’ Set (Ξ± i)} (h : βˆ€ i : ΞΉ, (f i).HasBasis p (s i)) (h_dir : βˆ€ I : Set ΞΉ, βˆ€ k : ΞΉ β†’ ΞΊ, I.Finite β†’ (βˆ€ i ∈ I, p (k i)) β†’ βˆƒ kβ‚€, p kβ‚€ ∧ βˆ€ i ∈ I, s i kβ‚€ βŠ† s i (k i)) : (pi f).HasBasis (fun Ik : Set ΞΉ Γ— ΞΊ ↦ Ik.1.Finite ∧ p Ik.2) (fun Ik ↦ Ik.1.pi (fun i ↦ s i Ik.2)) := by refine hasBasis_pi h |>.to_hasBasis ?_ ?_ Β· rintro ⟨I, k⟩ ⟨hI, hk⟩ rcases h_dir I k hI hk with ⟨kβ‚€, hkβ‚€, hkβ‚€'⟩ exact ⟨⟨I, kβ‚€βŸ©, ⟨hI, hkβ‚€βŸ©, Set.pi_mono hkβ‚€'⟩ Β· rintro ⟨I, k⟩ ⟨hI, hk⟩ exact ⟨⟨I, fun _ ↦ k⟩, ⟨hI, fun _ _ ↦ hk⟩, subset_rfl⟩ theorem HasBasis.pi_self {Ξ± : Type*} {ΞΊ : Type*} {f : Filter Ξ±} {p : ΞΊ β†’ Prop} {s : ΞΊ β†’ Set Ξ±} (h : f.HasBasis p s) : (pi fun _ ↦ f).HasBasis (fun Ik : Set ΞΉ Γ— ΞΊ ↦ Ik.1.Finite ∧ p Ik.2) (fun Ik ↦ Ik.1.pi (fun _ ↦ s Ik.2)) := by refine hasBasis_pi_same_index (fun _ ↦ h) (fun I k hI hk ↦ ?_) rcases h.mem_iff.mp (biInter_mem hI |>.mpr fun i hi ↦ h.mem_of_mem (hk i hi)) with ⟨kβ‚€, hkβ‚€, hkβ‚€'⟩ exact ⟨kβ‚€, hkβ‚€, fun i hi ↦ hkβ‚€'.trans (biInter_subset_of_mem hi)⟩ theorem le_pi_principal (s : (i : ΞΉ) β†’ Set (Ξ± i)) : π“Ÿ (univ.pi s) ≀ pi fun i ↦ π“Ÿ (s i) := le_pi.2 fun i ↦ tendsto_principal_principal.2 fun _f hf ↦ hf i trivial /-- The indexed product of finitely many principal filters is the principal filter corresponding to the cylinder `Set.univ.pi s`. If the index type is infinite, then `mem_pi_principal` and `hasBasis_pi_principal` may be useful. -/ @[simp] theorem pi_principal [Finite ΞΉ] (s : (i : ΞΉ) β†’ Set (Ξ± i)) : pi (fun i ↦ π“Ÿ (s i)) = π“Ÿ (univ.pi s) := by simp [Filter.pi, Set.pi_def] /-- The indexed product of a (possibly, infinite) family of principal filters is generated by the finite `Set.pi` cylinders. If the index type is finite, then the indexed product of principal filters is a pricipal filter, see `pi_principal`. -/ theorem mem_pi_principal {t : Set ((i : ΞΉ) β†’ Ξ± i)} : t ∈ pi (fun i ↦ π“Ÿ (s i)) ↔ βˆƒ I : Set ΞΉ, I.Finite ∧ I.pi s βŠ† t := (hasBasis_pi (fun i ↦ hasBasis_principal _)).mem_iff.trans <| by simp /-- The indexed product of a (possibly, infinite) family of principal filters is generated by the finite `Set.pi` cylinders. If the index type is finite, then the indexed product of principal filters is a pricipal filter, see `pi_principal`. -/ theorem hasBasis_pi_principal (s : (i : ΞΉ) β†’ Set (Ξ± i)) : HasBasis (pi fun i ↦ π“Ÿ (s i)) Set.Finite (Set.pi Β· s) := ⟨fun _ ↦ mem_pi_principal⟩ /-- The indexed product of finitely many pure filters `pure (f i)` is the pure filter `pure f`. If the index type is infinite, then `mem_pi_pure` and `hasBasis_pi_pure` below may be useful. -/ @[simp] theorem pi_pure [Finite ΞΉ] (f : (i : ΞΉ) β†’ Ξ± i) : pi (pure <| f Β·) = pure f := by simp only [← principal_singleton, pi_principal, univ_pi_singleton] /-- The indexed product of a (possibly, infinite) family of pure filters `pure (f i)` is generated by the sets of functions that are equal to `f` on a finite set.
If the index type is finite, then the indexed product of pure filters is a pure filter,
Mathlib/Order/Filter/Pi.lean
165
166
/- Copyright (c) 2022 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.Data.Set.Finite.Lemmas import Mathlib.ModelTheory.Substructures /-! # Finitely Generated First-Order Structures This file defines what it means for a first-order (sub)structure to be finitely or countably generated, similarly to other finitely-generated objects in the algebra library. ## Main Definitions - `FirstOrder.Language.Substructure.FG` indicates that a substructure is finitely generated. - `FirstOrder.Language.Structure.FG` indicates that a structure is finitely generated. - `FirstOrder.Language.Substructure.CG` indicates that a substructure is countably generated. - `FirstOrder.Language.Structure.CG` indicates that a structure is countably generated. ## TODO Develop a more unified definition of finite generation using the theory of closure operators, or use this definition of finite generation to define the others. -/ open FirstOrder Set namespace FirstOrder namespace Language open Structure variable {L : Language} {M : Type*} [L.Structure M] namespace Substructure /-- A substructure of `M` is finitely generated if it is the closure of a finite subset of `M`. -/ def FG (N : L.Substructure M) : Prop := βˆƒ S : Finset M, closure L S = N theorem fg_def {N : L.Substructure M} : N.FG ↔ βˆƒ S : Set M, S.Finite ∧ closure L S = N := ⟨fun ⟨t, h⟩ => ⟨_, Finset.finite_toSet t, h⟩, by rintro ⟨t', h, rfl⟩ rcases Finite.exists_finset_coe h with ⟨t, rfl⟩ exact ⟨t, rfl⟩⟩ theorem fg_iff_exists_fin_generating_family {N : L.Substructure M} : N.FG ↔ βˆƒ (n : β„•) (s : Fin n β†’ M), closure L (range s) = N := by rw [fg_def] constructor Β· rintro ⟨S, Sfin, hS⟩ obtain ⟨n, f, rfl⟩ := Sfin.fin_embedding exact ⟨n, f, hS⟩ Β· rintro ⟨n, s, hs⟩ exact ⟨range s, finite_range s, hs⟩ theorem fg_bot : (βŠ₯ : L.Substructure M).FG := βŸ¨βˆ…, by rw [Finset.coe_empty, closure_empty]⟩ instance instInhabited_fg : Inhabited { S : L.Substructure M // S.FG } := ⟨βŠ₯, fg_bot⟩ theorem fg_closure {s : Set M} (hs : s.Finite) : FG (closure L s) := ⟨hs.toFinset, by rw [hs.coe_toFinset]⟩ theorem fg_closure_singleton (x : M) : FG (closure L ({x} : Set M)) := fg_closure (finite_singleton x) theorem FG.sup {N₁ Nβ‚‚ : L.Substructure M} (hN₁ : N₁.FG) (hNβ‚‚ : Nβ‚‚.FG) : (N₁ βŠ” Nβ‚‚).FG := let ⟨t₁, htβ‚βŸ© := fg_def.1 hN₁ let ⟨tβ‚‚, htβ‚‚βŸ© := fg_def.1 hNβ‚‚ fg_def.2 ⟨t₁ βˆͺ tβ‚‚, ht₁.1.union htβ‚‚.1, by rw [closure_union, ht₁.2, htβ‚‚.2]⟩ theorem FG.map {N : Type*} [L.Structure N] (f : M β†’[L] N) {s : L.Substructure M} (hs : s.FG) : (s.map f).FG := let ⟨t, ht⟩ := fg_def.1 hs fg_def.2 ⟨f '' t, ht.1.image _, by rw [closure_image, ht.2]⟩ theorem FG.of_map_embedding {N : Type*} [L.Structure N] (f : M β†ͺ[L] N) {s : L.Substructure M} (hs : (s.map f.toHom).FG) : s.FG := by rcases hs with ⟨t, h⟩ rw [fg_def] refine ⟨f ⁻¹' t, t.finite_toSet.preimage f.injective.injOn, ?_⟩ have hf : Function.Injective f.toHom := f.injective refine map_injective_of_injective hf ?_ rw [← h, map_closure, Embedding.coe_toHom, image_preimage_eq_of_subset] intro x hx have h' := subset_closure (L := L) hx rw [h] at h' exact Hom.map_le_range h' theorem FG.of_finite {s : L.Substructure M} [h : Finite s] : s.FG := ⟨Set.Finite.toFinset h, by simp only [Finite.coe_toFinset, closure_eq]⟩ theorem FG.finite [L.IsRelational] {S : L.Substructure M} (h : S.FG) : Finite S := by obtain ⟨s, rfl⟩ := h have hs := s.finite_toSet rw [← closure_eq_of_isRelational L (s : Set M)] at hs exact hs theorem fg_iff_finite [L.IsRelational] {S : L.Substructure M} : S.FG ↔ Finite S := ⟨FG.finite, fun _ => FG.of_finite⟩ /-- A substructure of `M` is countably generated if it is the closure of a countable subset of `M`. -/ def CG (N : L.Substructure M) : Prop := βˆƒ S : Set M, S.Countable ∧ closure L S = N theorem cg_def {N : L.Substructure M} : N.CG ↔ βˆƒ S : Set M, S.Countable ∧ closure L S = N := Iff.refl _ theorem FG.cg {N : L.Substructure M} (h : N.FG) : N.CG := by obtain ⟨s, hf, rfl⟩ := fg_def.1 h exact ⟨s, hf.countable, rfl⟩ theorem cg_iff_empty_or_exists_nat_generating_family {N : L.Substructure M} : N.CG ↔ N = (βˆ… : Set M) ∨ βˆƒ s : β„• β†’ M, closure L (range s) = N := by rw [cg_def] constructor Β· rintro ⟨S, Scount, hS⟩ rcases eq_empty_or_nonempty (N : Set M) with h | h Β· exact Or.intro_left _ h obtain ⟨f, h'⟩ := (Scount.union (Set.countable_singleton h.some)).exists_eq_range (singleton_nonempty h.some).inr refine Or.intro_right _ ⟨f, ?_⟩ rw [← h', closure_union, hS, sup_eq_left, closure_le] exact singleton_subset_iff.2 h.some_mem Β· intro h rcases h with h | h Β· refine βŸ¨βˆ…, countable_empty, closure_eq_of_le (empty_subset _) ?_⟩ rw [← SetLike.coe_subset_coe, h] exact empty_subset _ Β· obtain ⟨f, rfl⟩ := h exact ⟨range f, countable_range _, rfl⟩ theorem cg_bot : (βŠ₯ : L.Substructure M).CG := fg_bot.cg theorem cg_closure {s : Set M} (hs : s.Countable) : CG (closure L s) := ⟨s, hs, rfl⟩ theorem cg_closure_singleton (x : M) : CG (closure L ({x} : Set M)) := (fg_closure_singleton x).cg theorem CG.sup {N₁ Nβ‚‚ : L.Substructure M} (hN₁ : N₁.CG) (hNβ‚‚ : Nβ‚‚.CG) : (N₁ βŠ” Nβ‚‚).CG := let ⟨t₁, htβ‚βŸ© := cg_def.1 hN₁ let ⟨tβ‚‚, htβ‚‚βŸ© := cg_def.1 hNβ‚‚ cg_def.2 ⟨t₁ βˆͺ tβ‚‚, ht₁.1.union htβ‚‚.1, by rw [closure_union, ht₁.2, htβ‚‚.2]⟩ theorem CG.map {N : Type*} [L.Structure N] (f : M β†’[L] N) {s : L.Substructure M} (hs : s.CG) :
(s.map f).CG := let ⟨t, ht⟩ := cg_def.1 hs cg_def.2 ⟨f '' t, ht.1.image _, by rw [closure_image, ht.2]⟩
Mathlib/ModelTheory/FinitelyGenerated.lean
156
159
/- Copyright (c) 2021 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker -/ import Mathlib.Order.Antichain import Mathlib.Topology.ContinuousOn /-! # Left and right continuity In this file we prove a few lemmas about left and right continuous functions: * `continuousWithinAt_Ioi_iff_Ici`: two definitions of right continuity (with `(a, ∞)` and with `[a, ∞)`) are equivalent; * `continuousWithinAt_Iio_iff_Iic`: two definitions of left continuity (with `(-∞, a)` and with `(-∞, a]`) are equivalent; * `continuousAt_iff_continuous_left_right`, `continuousAt_iff_continuous_left'_right'` : a function is continuous at `a` if and only if it is left and right continuous at `a`. ## Tags left continuous, right continuous -/ open Set Filter Topology section Preorder variable {Ξ± : Type*} [TopologicalSpace Ξ±] [Preorder Ξ±] lemma frequently_lt_nhds (a : Ξ±) [NeBot (𝓝[<] a)] : βˆƒαΆ  x in 𝓝 a, x < a := frequently_iff_neBot.2 β€Ή_β€Ί lemma frequently_gt_nhds (a : Ξ±) [NeBot (𝓝[>] a)] : βˆƒαΆ  x in 𝓝 a, a < x := frequently_iff_neBot.2 β€Ή_β€Ί theorem Filter.Eventually.exists_lt {a : Ξ±} [NeBot (𝓝[<] a)] {p : Ξ± β†’ Prop} (h : βˆ€αΆ  x in 𝓝 a, p x) : βˆƒ b < a, p b := ((frequently_lt_nhds a).and_eventually h).exists theorem Filter.Eventually.exists_gt {a : Ξ±} [NeBot (𝓝[>] a)] {p : Ξ± β†’ Prop} (h : βˆ€αΆ  x in 𝓝 a, p x) : βˆƒ b > a, p b := ((frequently_gt_nhds a).and_eventually h).exists theorem nhdsWithin_Ici_neBot {a b : Ξ±} (Hβ‚‚ : a ≀ b) : NeBot (𝓝[Ici a] b) := nhdsWithin_neBot_of_mem Hβ‚‚ instance nhdsGE_neBot (a : Ξ±) : NeBot (𝓝[β‰₯] a) := nhdsWithin_Ici_neBot (le_refl a) @[deprecated nhdsGE_neBot (since := "2024-12-21")] theorem nhdsWithin_Ici_self_neBot (a : Ξ±) : NeBot (𝓝[β‰₯] a) := nhdsGE_neBot a theorem nhdsWithin_Iic_neBot {a b : Ξ±} (H : a ≀ b) : NeBot (𝓝[Iic b] a) := nhdsWithin_neBot_of_mem H instance nhdsLE_neBot (a : Ξ±) : NeBot (𝓝[≀] a) := nhdsWithin_Iic_neBot (le_refl a) @[deprecated nhdsLE_neBot (since := "2024-12-21")] theorem nhdsWithin_Iic_self_neBot (a : Ξ±) : NeBot (𝓝[≀] a) := nhdsLE_neBot a theorem nhdsLT_le_nhdsNE (a : Ξ±) : 𝓝[<] a ≀ 𝓝[β‰ ] a := nhdsWithin_mono a fun _ => ne_of_lt @[deprecated (since := "2024-12-21")] alias nhds_left'_le_nhds_ne := nhdsLT_le_nhdsNE theorem nhdsGT_le_nhdsNE (a : Ξ±) : 𝓝[>] a ≀ 𝓝[β‰ ] a := nhdsWithin_mono a fun _ => ne_of_gt @[deprecated (since := "2024-12-21")] alias nhds_right'_le_nhds_ne := nhdsGT_le_nhdsNE -- TODO: add instances for `NeBot (𝓝[<] x)` on (indexed) product types lemma IsAntichain.interior_eq_empty [βˆ€ x : Ξ±, (𝓝[<] x).NeBot] {s : Set Ξ±} (hs : IsAntichain (Β· ≀ Β·) s) : interior s = βˆ… := by refine eq_empty_of_forall_not_mem fun x hx ↦ ?_ have : βˆ€αΆ  y in 𝓝 x, y ∈ s := mem_interior_iff_mem_nhds.1 hx rcases this.exists_lt with ⟨y, hyx, hys⟩ exact hs hys (interior_subset hx) hyx.ne hyx.le lemma IsAntichain.interior_eq_empty' [βˆ€ x : Ξ±, (𝓝[>] x).NeBot] {s : Set Ξ±} (hs : IsAntichain (Β· ≀ Β·) s) : interior s = βˆ… := have : βˆ€ x : Ξ±α΅’α΅ˆ, NeBot (𝓝[<] x) := β€Ή_β€Ί hs.to_dual.interior_eq_empty end Preorder section PartialOrder variable {Ξ± Ξ² : Type*} [TopologicalSpace Ξ±] [PartialOrder Ξ±] [TopologicalSpace Ξ²] theorem continuousWithinAt_Ioi_iff_Ici {a : Ξ±} {f : Ξ± β†’ Ξ²} : ContinuousWithinAt f (Ioi a) a ↔ ContinuousWithinAt f (Ici a) a := by simp only [← Ici_diff_left, continuousWithinAt_diff_self]
theorem continuousWithinAt_Iio_iff_Iic {a : Ξ±} {f : Ξ± β†’ Ξ²} : ContinuousWithinAt f (Iio a) a ↔ ContinuousWithinAt f (Iic a) a :=
Mathlib/Topology/Order/LeftRight.lean
95
97
/- Copyright (c) 2022 Chris Birkbeck. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Birkbeck, David Loeffler -/ import Mathlib.Algebra.Module.Submodule.Basic import Mathlib.Analysis.Asymptotics.Lemmas import Mathlib.Algebra.Algebra.Pi /-! # Zero and Bounded at filter Given a filter `l` we define the notion of a function being `ZeroAtFilter` as well as being `BoundedAtFilter`. Alongside this we construct the `Submodule`, `AddSubmonoid` of functions that are `ZeroAtFilter`. Similarly, we construct the `Submodule` and `Subalgebra` of functions that are `BoundedAtFilter`. -/ namespace Filter variable {π•œ Ξ± Ξ² : Type*} open Topology /-- If `l` is a filter on `Ξ±`, then a function `f : Ξ± β†’ Ξ²` is `ZeroAtFilter l` if it tends to zero along `l`. -/ def ZeroAtFilter [Zero Ξ²] [TopologicalSpace Ξ²] (l : Filter Ξ±) (f : Ξ± β†’ Ξ²) : Prop := Filter.Tendsto f l (𝓝 0) theorem zero_zeroAtFilter [Zero Ξ²] [TopologicalSpace Ξ²] (l : Filter Ξ±) : ZeroAtFilter l (0 : Ξ± β†’ Ξ²) := tendsto_const_nhds nonrec theorem ZeroAtFilter.add [TopologicalSpace Ξ²] [AddZeroClass Ξ²] [ContinuousAdd Ξ²] {l : Filter Ξ±} {f g : Ξ± β†’ Ξ²} (hf : ZeroAtFilter l f) (hg : ZeroAtFilter l g) : ZeroAtFilter l (f + g) := by simpa using hf.add hg
nonrec theorem ZeroAtFilter.neg [TopologicalSpace Ξ²] [SubtractionMonoid Ξ²] [ContinuousNeg Ξ²] {l : Filter Ξ±} {f : Ξ± β†’ Ξ²} (hf : ZeroAtFilter l f) : ZeroAtFilter l (-f) := by simpa using hf.neg
Mathlib/Order/Filter/ZeroAndBoundedAtFilter.lean
41
44
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.Data.List.Lattice import Mathlib.Data.Bool.Basic import Mathlib.Order.Lattice /-! # Intervals in β„• This file defines intervals of naturals. `List.Ico m n` is the list of integers greater than `m` and strictly less than `n`. ## TODO - Define `Ioo` and `Icc`, state basic lemmas about them. - Also do the versions for integers? - One could generalise even further, defining 'locally finite partial orders', for which `Set.Ico a b` is `[Finite]`, and 'locally finite total orders', for which there is a list model. - Once the above is done, get rid of `Int.range` (and maybe `List.range'`?). -/ open Nat namespace List /-- `Ico n m` is the list of natural numbers `n ≀ x < m`. (Ico stands for "interval, closed-open".) See also `Mathlib/Order/Interval/Basic.lean` for modelling intervals in general preorders, as well as sibling definitions alongside it such as `Set.Ico`, `Multiset.Ico` and `Finset.Ico` for sets, multisets and finite sets respectively. -/ def Ico (n m : β„•) : List β„• := range' n (m - n) namespace Ico theorem zero_bot (n : β„•) : Ico 0 n = range n := by rw [Ico, Nat.sub_zero, range_eq_range'] @[simp] theorem length (n m : β„•) : length (Ico n m) = m - n := by dsimp [Ico] simp [length_range'] theorem pairwise_lt (n m : β„•) : Pairwise (Β· < Β·) (Ico n m) := by dsimp [Ico] simp [pairwise_lt_range'] theorem nodup (n m : β„•) : Nodup (Ico n m) := by dsimp [Ico] simp [nodup_range'] @[simp] theorem mem {n m l : β„•} : l ∈ Ico n m ↔ n ≀ l ∧ l < m := by suffices n ≀ l ∧ l < n + (m - n) ↔ n ≀ l ∧ l < m by simp [Ico, this] omega theorem eq_nil_of_le {n m : β„•} (h : m ≀ n) : Ico n m = [] := by simp [Ico, Nat.sub_eq_zero_iff_le.mpr h] theorem map_add (n m k : β„•) : (Ico n m).map (k + Β·) = Ico (n + k) (m + k) := by rw [Ico, Ico, map_add_range', Nat.add_sub_add_right m k, Nat.add_comm n k] theorem map_sub (n m k : β„•) (h₁ : k ≀ n) : ((Ico n m).map fun x => x - k) = Ico (n - k) (m - k) := by rw [Ico, Ico, Nat.sub_sub_sub_cancel_right h₁, map_sub_range' h₁] @[simp] theorem self_empty {n : β„•} : Ico n n = [] := eq_nil_of_le (le_refl n) @[simp] theorem eq_empty_iff {n m : β„•} : Ico n m = [] ↔ m ≀ n := Iff.intro (fun h => Nat.sub_eq_zero_iff_le.mp <| by rw [← length, h, List.length]) eq_nil_of_le theorem append_consecutive {n m l : β„•} (hnm : n ≀ m) (hml : m ≀ l) : Ico n m ++ Ico m l = Ico n l := by dsimp only [Ico] convert range'_append using 2 Β· rw [Nat.one_mul, Nat.add_sub_cancel' hnm] Β· omega @[simp] theorem inter_consecutive (n m l : β„•) : Ico n m ∩ Ico m l = [] := by apply eq_nil_iff_forall_not_mem.2 intro a simp only [and_imp, not_and, not_lt, List.mem_inter_iff, List.Ico.mem] intro _ hβ‚‚ h₃ exfalso exact not_lt_of_ge h₃ hβ‚‚ @[simp] theorem bagInter_consecutive (n m l : Nat) : @List.bagInter β„• instBEqOfDecidableEq (Ico n m) (Ico m l) = [] := (bagInter_nil_iff_inter_nil _ _).2 (by convert inter_consecutive n m l) @[simp] theorem succ_singleton {n : β„•} : Ico n (n + 1) = [n] := by dsimp [Ico] simp [range', Nat.add_sub_cancel_left] theorem succ_top {n m : β„•} (h : n ≀ m) : Ico n (m + 1) = Ico n m ++ [m] := by rwa [← succ_singleton, append_consecutive] exact Nat.le_succ _ theorem eq_cons {n m : β„•} (h : n < m) : Ico n m = n :: Ico (n + 1) m := by rw [← append_consecutive (Nat.le_succ n) h, succ_singleton] rfl @[simp] theorem pred_singleton {m : β„•} (h : 0 < m) : Ico (m - 1) m = [m - 1] := by simp [Ico, Nat.sub_sub_self (succ_le_of_lt h)] theorem chain'_succ (n m : β„•) : Chain' (fun a b => b = succ a) (Ico n m) := by by_cases h : n < m Β· rw [eq_cons h] exact chain_succ_range' _ _ 1 Β· rw [eq_nil_of_le (le_of_not_gt h)] trivial theorem not_mem_top {n m : β„•} : m βˆ‰ Ico n m := by simp theorem filter_lt_of_top_le {n m l : β„•} (hml : m ≀ l) : ((Ico n m).filter fun x => x < l) = Ico n m := filter_eq_self.2 fun k hk => by simp only [(lt_of_lt_of_le (mem.1 hk).2 hml), decide_true] theorem filter_lt_of_le_bot {n m l : β„•} (hln : l ≀ n) : ((Ico n m).filter fun x => x < l) = [] := filter_eq_nil_iff.2 fun k hk => by simp only [decide_eq_true_eq, not_lt] apply le_trans hln exact (mem.1 hk).1 theorem filter_lt_of_ge {n m l : β„•} (hlm : l ≀ m) : ((Ico n m).filter fun x => x < l) = Ico n l := by rcases le_total n l with hnl | hln Β· rw [← append_consecutive hnl hlm, filter_append, filter_lt_of_top_le (le_refl l), filter_lt_of_le_bot (le_refl l), append_nil] Β· rw [eq_nil_of_le hln, filter_lt_of_le_bot hln] @[simp] theorem filter_lt (n m l : β„•) : ((Ico n m).filter fun x => x < l) = Ico n (min m l) := by rcases le_total m l with hml | hlm Β· rw [min_eq_left hml, filter_lt_of_top_le hml] Β· rw [min_eq_right hlm, filter_lt_of_ge hlm] theorem filter_le_of_le_bot {n m l : β„•} (hln : l ≀ n) : ((Ico n m).filter fun x => l ≀ x) = Ico n m := filter_eq_self.2 fun k hk => by rw [decide_eq_true_eq] exact le_trans hln (mem.1 hk).1
theorem filter_le_of_top_le {n m l : β„•} (hml : m ≀ l) : ((Ico n m).filter fun x => l ≀ x) = [] := filter_eq_nil_iff.2 fun k hk => by rw [decide_eq_true_eq]
Mathlib/Data/List/Intervals.lean
156
159
/- Copyright (c) 2023 YaΓ«l Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: YaΓ«l Dillies -/ import Mathlib.Algebra.Algebra.Defs import Mathlib.Algebra.Order.Module.Defs /-! # Ordered algebras This file proves properties of algebras where both rings are ordered compatibly. ## TODO `positivity` extension for `algebraMap` -/ variable {Ξ± Ξ² : Type*} [CommSemiring Ξ±] [PartialOrder Ξ±] section OrderedSemiring variable (Ξ²) variable [Semiring Ξ²] [PartialOrder Ξ²] [IsOrderedRing Ξ²] [Algebra Ξ± Ξ²] [SMulPosMono Ξ± Ξ²] {a : Ξ±} @[mono] lemma algebraMap_mono : Monotone (algebraMap Ξ± Ξ²) := fun a₁ aβ‚‚ ha ↦ by simpa only [Algebra.algebraMap_eq_smul_one] using smul_le_smul_of_nonneg_right ha zero_le_one /-- A version of `algebraMap_mono` for use by `gcongr` since it currently does not preprocess `Monotone` conclusions. -/ @[gcongr] protected lemma GCongr.algebraMap_le_algebraMap {a₁ aβ‚‚ : Ξ±} (ha : a₁ ≀ aβ‚‚) : algebraMap Ξ± Ξ² a₁ ≀ algebraMap Ξ± Ξ² aβ‚‚ := algebraMap_mono _ ha
lemma algebraMap_nonneg (ha : 0 ≀ a) : 0 ≀ algebraMap Ξ± Ξ² a := by simpa using algebraMap_mono Ξ² ha
Mathlib/Algebra/Order/Module/Algebra.lean
34
34
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne, Benjamin Davidson -/ import Mathlib.Analysis.SpecialFunctions.Trigonometric.Angle import Mathlib.Analysis.SpecialFunctions.Trigonometric.Inverse /-! # The argument of a complex number. We define `arg : β„‚ β†’ ℝ`, returning a real number in the range (-Ο€, Ο€], such that for `x β‰  0`, `sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`, while `arg 0` defaults to `0` -/ open Filter Metric Set open scoped ComplexConjugate Real Topology namespace Complex variable {a x z : β„‚} /-- `arg` returns values in the range (-Ο€, Ο€], such that for `x β‰  0`, `sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`, `arg 0` defaults to `0` -/ noncomputable def arg (x : β„‚) : ℝ := if 0 ≀ x.re then Real.arcsin (x.im / β€–xβ€–) else if 0 ≀ x.im then Real.arcsin ((-x).im / β€–xβ€–) + Ο€ else Real.arcsin ((-x).im / β€–xβ€–) - Ο€ theorem sin_arg (x : β„‚) : Real.sin (arg x) = x.im / β€–xβ€– := by unfold arg; split_ifs <;> simp [sub_eq_add_neg, arg, Real.sin_arcsin (abs_le.1 (abs_im_div_norm_le_one x)).1 (abs_le.1 (abs_im_div_norm_le_one x)).2, Real.sin_add, neg_div, Real.arcsin_neg, Real.sin_neg] theorem cos_arg {x : β„‚} (hx : x β‰  0) : Real.cos (arg x) = x.re / β€–xβ€– := by rw [arg] split_ifs with h₁ hβ‚‚ Β· rw [Real.cos_arcsin] field_simp [Real.sqrt_sq, (norm_pos_iff.mpr hx).le, *] Β· rw [Real.cos_add_pi, Real.cos_arcsin] field_simp [Real.sqrt_div (sq_nonneg _), Real.sqrt_sq_eq_abs, _root_.abs_of_neg (not_le.1 h₁), *] Β· rw [Real.cos_sub_pi, Real.cos_arcsin] field_simp [Real.sqrt_div (sq_nonneg _), Real.sqrt_sq_eq_abs, _root_.abs_of_neg (not_le.1 h₁), *] @[simp] theorem norm_mul_exp_arg_mul_I (x : β„‚) : β€–xβ€– * exp (arg x * I) = x := by rcases eq_or_ne x 0 with (rfl | hx) Β· simp Β· have : β€–xβ€– β‰  0 := norm_ne_zero_iff.mpr hx apply Complex.ext <;> field_simp [sin_arg, cos_arg hx, this, mul_comm β€–xβ€–] @[simp] theorem norm_mul_cos_add_sin_mul_I (x : β„‚) : (β€–xβ€– * (cos (arg x) + sin (arg x) * I) : β„‚) = x := by rw [← exp_mul_I, norm_mul_exp_arg_mul_I] @[simp] lemma norm_mul_cos_arg (x : β„‚) : β€–xβ€– * Real.cos (arg x) = x.re := by simpa [-norm_mul_cos_add_sin_mul_I] using congr_arg re (norm_mul_cos_add_sin_mul_I x) @[simp] lemma norm_mul_sin_arg (x : β„‚) : β€–xβ€– * Real.sin (arg x) = x.im := by simpa [-norm_mul_cos_add_sin_mul_I] using congr_arg im (norm_mul_cos_add_sin_mul_I x) theorem norm_eq_one_iff (z : β„‚) : β€–zβ€– = 1 ↔ βˆƒ ΞΈ : ℝ, exp (ΞΈ * I) = z := by refine ⟨fun hz => ⟨arg z, ?_⟩, ?_⟩ Β· calc exp (arg z * I) = β€–zβ€– * exp (arg z * I) := by rw [hz, ofReal_one, one_mul] _ = z :=norm_mul_exp_arg_mul_I z Β· rintro ⟨θ, rfl⟩ exact Complex.norm_exp_ofReal_mul_I ΞΈ @[deprecated (since := "2025-02-16")] alias abs_mul_exp_arg_mul_I := norm_mul_exp_arg_mul_I @[deprecated (since := "2025-02-16")] alias abs_mul_cos_add_sin_mul_I := norm_mul_cos_add_sin_mul_I @[deprecated (since := "2025-02-16")] alias abs_mul_cos_arg := norm_mul_cos_arg @[deprecated (since := "2025-02-16")] alias abs_mul_sin_arg := norm_mul_sin_arg @[deprecated (since := "2025-02-16")] alias abs_eq_one_iff := norm_eq_one_iff @[simp] theorem range_exp_mul_I : (Set.range fun x : ℝ => exp (x * I)) = Metric.sphere 0 1 := by ext x simp only [mem_sphere_zero_iff_norm, norm_eq_one_iff, Set.mem_range] theorem arg_mul_cos_add_sin_mul_I {r : ℝ} (hr : 0 < r) {ΞΈ : ℝ} (hΞΈ : ΞΈ ∈ Set.Ioc (-Ο€) Ο€) : arg (r * (cos ΞΈ + sin ΞΈ * I)) = ΞΈ := by simp only [arg, norm_mul, norm_cos_add_sin_mul_I, Complex.norm_of_nonneg hr.le, mul_one] simp only [re_ofReal_mul, im_ofReal_mul, neg_im, ← ofReal_cos, ← ofReal_sin, ← mk_eq_add_mul_I, neg_div, mul_div_cancel_leftβ‚€ _ hr.ne', mul_nonneg_iff_right_nonneg_of_pos hr] by_cases h₁ : ΞΈ ∈ Set.Icc (-(Ο€ / 2)) (Ο€ / 2) Β· rw [if_pos] exacts [Real.arcsin_sin' h₁, Real.cos_nonneg_of_mem_Icc h₁] Β· rw [Set.mem_Icc, not_and_or, not_le, not_le] at h₁ rcases h₁ with h₁ | h₁ Β· replace hΞΈ := hΞΈ.1 have hcos : Real.cos ΞΈ < 0 := by rw [← neg_pos, ← Real.cos_add_pi] refine Real.cos_pos_of_mem_Ioo ⟨?_, ?_⟩ <;> linarith have hsin : Real.sin ΞΈ < 0 := Real.sin_neg_of_neg_of_neg_pi_lt (by linarith) hΞΈ rw [if_neg, if_neg, ← Real.sin_add_pi, Real.arcsin_sin, add_sub_cancel_right] <;> [linarith; linarith; exact hsin.not_le; exact hcos.not_le] Β· replace hΞΈ := hΞΈ.2 have hcos : Real.cos ΞΈ < 0 := Real.cos_neg_of_pi_div_two_lt_of_lt h₁ (by linarith) have hsin : 0 ≀ Real.sin ΞΈ := Real.sin_nonneg_of_mem_Icc ⟨by linarith, hθ⟩ rw [if_neg, if_pos, ← Real.sin_sub_pi, Real.arcsin_sin, sub_add_cancel] <;> [linarith; linarith; exact hsin; exact hcos.not_le] theorem arg_cos_add_sin_mul_I {ΞΈ : ℝ} (hΞΈ : ΞΈ ∈ Set.Ioc (-Ο€) Ο€) : arg (cos ΞΈ + sin ΞΈ * I) = ΞΈ := by rw [← one_mul (_ + _), ← ofReal_one, arg_mul_cos_add_sin_mul_I zero_lt_one hΞΈ] lemma arg_exp_mul_I (ΞΈ : ℝ) : arg (exp (ΞΈ * I)) = toIocMod (mul_pos two_pos Real.pi_pos) (-Ο€) ΞΈ := by convert arg_cos_add_sin_mul_I (ΞΈ := toIocMod (mul_pos two_pos Real.pi_pos) (-Ο€) ΞΈ) _ using 2 Β· rw [← exp_mul_I, eq_sub_of_add_eq <| toIocMod_add_toIocDiv_zsmul _ _ ΞΈ, ofReal_sub, ofReal_zsmul, ofReal_mul, ofReal_ofNat, exp_mul_I_periodic.sub_zsmul_eq] Β· convert toIocMod_mem_Ioc _ _ _ ring @[simp] theorem arg_zero : arg 0 = 0 := by simp [arg, le_refl] theorem ext_norm_arg {x y : β„‚} (h₁ : β€–xβ€– = β€–yβ€–) (hβ‚‚ : x.arg = y.arg) : x = y := by
rw [← norm_mul_exp_arg_mul_I x, ← norm_mul_exp_arg_mul_I y, h₁, hβ‚‚] theorem ext_norm_arg_iff {x y : β„‚} : x = y ↔ β€–xβ€– = β€–yβ€– ∧ arg x = arg y := ⟨fun h => h β–Έ ⟨rfl, rfl⟩, and_imp.2 ext_norm_arg⟩ @[deprecated (since := "2025-02-16")] alias ext_abs_arg := ext_norm_arg @[deprecated (since := "2025-02-16")] alias ext_abs_arg_iff := ext_norm_arg_iff
Mathlib/Analysis/SpecialFunctions/Complex/Arg.lean
123
129
/- Copyright (c) 2023 YaΓ«l Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: YaΓ«l Dillies -/ import Mathlib.Algebra.NoZeroSMulDivisors.Basic import Mathlib.Algebra.Order.GroupWithZero.Action.Synonym import Mathlib.Tactic.GCongr import Mathlib.Tactic.Positivity.Core /-! # Monotonicity of scalar multiplication by positive elements This file defines typeclasses to reason about monotonicity of the operations * `b ↦ a β€’ b`, "left scalar multiplication" * `a ↦ a β€’ b`, "right scalar multiplication" We use eight typeclasses to encode the various properties we care about for those two operations. These typeclasses are meant to be mostly internal to this file, to set up each lemma in the appropriate generality. Less granular typeclasses like `OrderedAddCommMonoid`, `LinearOrderedField`, `OrderedSMul` should be enough for most purposes, and the system is set up so that they imply the correct granular typeclasses here. If those are enough for you, you may stop reading here! Else, beware that what follows is a bit technical. ## Definitions In all that follows, `Ξ±` and `Ξ²` are orders which have a `0` and such that `Ξ±` acts on `Ξ²` by scalar multiplication. Note however that we do not use lawfulness of this action in most of the file. Hence `β€’` should be considered here as a mostly arbitrary function `Ξ± β†’ Ξ² β†’ Ξ²`. We use the following four typeclasses to reason about left scalar multiplication (`b ↦ a β€’ b`): * `PosSMulMono`: If `a β‰₯ 0`, then `b₁ ≀ bβ‚‚` implies `a β€’ b₁ ≀ a β€’ bβ‚‚`. * `PosSMulStrictMono`: If `a > 0`, then `b₁ < bβ‚‚` implies `a β€’ b₁ < a β€’ bβ‚‚`. * `PosSMulReflectLT`: If `a β‰₯ 0`, then `a β€’ b₁ < a β€’ bβ‚‚` implies `b₁ < bβ‚‚`. * `PosSMulReflectLE`: If `a > 0`, then `a β€’ b₁ ≀ a β€’ bβ‚‚` implies `b₁ ≀ bβ‚‚`. We use the following four typeclasses to reason about right scalar multiplication (`a ↦ a β€’ b`): * `SMulPosMono`: If `b β‰₯ 0`, then `a₁ ≀ aβ‚‚` implies `a₁ β€’ b ≀ aβ‚‚ β€’ b`. * `SMulPosStrictMono`: If `b > 0`, then `a₁ < aβ‚‚` implies `a₁ β€’ b < aβ‚‚ β€’ b`. * `SMulPosReflectLT`: If `b β‰₯ 0`, then `a₁ β€’ b < aβ‚‚ β€’ b` implies `a₁ < aβ‚‚`. * `SMulPosReflectLE`: If `b > 0`, then `a₁ β€’ b ≀ aβ‚‚ β€’ b` implies `a₁ ≀ aβ‚‚`. ## Constructors The four typeclasses about nonnegativity can usually be checked only on positive inputs due to their condition becoming trivial when `a = 0` or `b = 0`. We therefore make the following constructors available: `PosSMulMono.of_pos`, `PosSMulReflectLT.of_pos`, `SMulPosMono.of_pos`, `SMulPosReflectLT.of_pos` ## Implications As `Ξ±` and `Ξ²` get more and more structure, those typeclasses end up being equivalent. The commonly used implications are: * When `Ξ±`, `Ξ²` are partial orders: * `PosSMulStrictMono β†’ PosSMulMono` * `SMulPosStrictMono β†’ SMulPosMono` * `PosSMulReflectLE β†’ PosSMulReflectLT` * `SMulPosReflectLE β†’ SMulPosReflectLT` * When `Ξ²` is a linear order: * `PosSMulStrictMono β†’ PosSMulReflectLE` * `PosSMulReflectLT β†’ PosSMulMono` (not registered as instance) * `SMulPosReflectLT β†’ SMulPosMono` (not registered as instance) * `PosSMulReflectLE β†’ PosSMulStrictMono` (not registered as instance) * `SMulPosReflectLE β†’ SMulPosStrictMono` (not registered as instance) * When `Ξ±` is a linear order: * `SMulPosStrictMono β†’ SMulPosReflectLE` * When `Ξ±` is an ordered ring, `Ξ²` an ordered group and also an `Ξ±`-module: * `PosSMulMono β†’ SMulPosMono` * `PosSMulStrictMono β†’ SMulPosStrictMono` * When `Ξ±` is an linear ordered semifield, `Ξ²` is an `Ξ±`-module: * `PosSMulStrictMono β†’ PosSMulReflectLT` * `PosSMulMono β†’ PosSMulReflectLE` * When `Ξ±` is a semiring, `Ξ²` is an `Ξ±`-module with `NoZeroSMulDivisors`: * `PosSMulMono β†’ PosSMulStrictMono` (not registered as instance) * When `Ξ±` is a ring, `Ξ²` is an `Ξ±`-module with `NoZeroSMulDivisors`: * `SMulPosMono β†’ SMulPosStrictMono` (not registered as instance) Further, the bundled non-granular typeclasses imply the granular ones like so: * `OrderedSMul β†’ PosSMulStrictMono` * `OrderedSMul β†’ PosSMulReflectLT` Unless otherwise stated, all these implications are registered as instances, which means that in practice you should not worry about these implications. However, if you encounter a case where you think a statement is true but not covered by the current implications, please bring it up on Zulip! ## Implementation notes This file uses custom typeclasses instead of abbreviations of `CovariantClass`/`ContravariantClass` because: * They get displayed as classes in the docs. In particular, one can see their list of instances, instead of their instances being invariably dumped to the `CovariantClass`/`ContravariantClass` list. * They don't pollute other typeclass searches. Having many abbreviations of the same typeclass for different purposes always felt like a performance issue (more instances with the same key, for no added benefit), and indeed making the classes here abbreviation previous creates timeouts due to the higher number of `CovariantClass`/`ContravariantClass` instances. * `SMulPosReflectLT`/`SMulPosReflectLE` do not fit in the framework since they relate `≀` on two different types. So we would have to generalise `CovariantClass`/`ContravariantClass` to three types and two relations. * Very minor, but the constructors let you work with `a : Ξ±`, `h : 0 ≀ a` instead of `a : {a : Ξ± // 0 ≀ a}`. This actually makes some instances surprisingly cleaner to prove. * The `CovariantClass`/`ContravariantClass` framework is only useful to automate very simple logic anyway. It is easily copied over. In the future, it would be good to make the corresponding typeclasses in `Mathlib.Algebra.Order.GroupWithZero.Unbundled` custom typeclasses too. ## TODO This file acts as a substitute for `Mathlib.Algebra.Order.SMul`. We now need to * finish the transition by deleting the duplicate lemmas * rearrange the non-duplicate lemmas into new files * generalise (most of) the lemmas from `Mathlib.Algebra.Order.Module` to here * rethink `OrderedSMul` -/ open OrderDual variable (Ξ± Ξ² : Type*) section Defs variable [SMul Ξ± Ξ²] [Preorder Ξ±] [Preorder Ξ²] section Left variable [Zero Ξ±] /-- Typeclass for monotonicity of scalar multiplication by nonnegative elements on the left, namely `b₁ ≀ bβ‚‚ β†’ a β€’ b₁ ≀ a β€’ bβ‚‚` if `0 ≀ a`. You should usually not use this very granular typeclass directly, but rather a typeclass like `OrderedSMul`. -/ class PosSMulMono : Prop where /-- Do not use this. Use `smul_le_smul_of_nonneg_left` instead. -/ protected elim ⦃a : α⦄ (ha : 0 ≀ a) ⦃b₁ bβ‚‚ : β⦄ (hb : b₁ ≀ bβ‚‚) : a β€’ b₁ ≀ a β€’ bβ‚‚ /-- Typeclass for strict monotonicity of scalar multiplication by positive elements on the left, namely `b₁ < bβ‚‚ β†’ a β€’ b₁ < a β€’ bβ‚‚` if `0 < a`. You should usually not use this very granular typeclass directly, but rather a typeclass like `OrderedSMul`. -/ class PosSMulStrictMono : Prop where /-- Do not use this. Use `smul_lt_smul_of_pos_left` instead. -/ protected elim ⦃a : α⦄ (ha : 0 < a) ⦃b₁ bβ‚‚ : β⦄ (hb : b₁ < bβ‚‚) : a β€’ b₁ < a β€’ bβ‚‚ /-- Typeclass for strict reverse monotonicity of scalar multiplication by nonnegative elements on the left, namely `a β€’ b₁ < a β€’ bβ‚‚ β†’ b₁ < bβ‚‚` if `0 ≀ a`. You should usually not use this very granular typeclass directly, but rather a typeclass like `OrderedSMul`. -/ class PosSMulReflectLT : Prop where /-- Do not use this. Use `lt_of_smul_lt_smul_left` instead. -/ protected elim ⦃a : α⦄ (ha : 0 ≀ a) ⦃b₁ bβ‚‚ : β⦄ (hb : a β€’ b₁ < a β€’ bβ‚‚) : b₁ < bβ‚‚ /-- Typeclass for reverse monotonicity of scalar multiplication by positive elements on the left, namely `a β€’ b₁ ≀ a β€’ bβ‚‚ β†’ b₁ ≀ bβ‚‚` if `0 < a`. You should usually not use this very granular typeclass directly, but rather a typeclass like `OrderedSMul`. -/ class PosSMulReflectLE : Prop where /-- Do not use this. Use `le_of_smul_lt_smul_left` instead. -/ protected elim ⦃a : α⦄ (ha : 0 < a) ⦃b₁ bβ‚‚ : β⦄ (hb : a β€’ b₁ ≀ a β€’ bβ‚‚) : b₁ ≀ bβ‚‚ end Left section Right variable [Zero Ξ²] /-- Typeclass for monotonicity of scalar multiplication by nonnegative elements on the left, namely `a₁ ≀ aβ‚‚ β†’ a₁ β€’ b ≀ aβ‚‚ β€’ b` if `0 ≀ b`. You should usually not use this very granular typeclass directly, but rather a typeclass like `OrderedSMul`. -/ class SMulPosMono : Prop where /-- Do not use this. Use `smul_le_smul_of_nonneg_right` instead. -/ protected elim ⦃b : β⦄ (hb : 0 ≀ b) ⦃a₁ aβ‚‚ : α⦄ (ha : a₁ ≀ aβ‚‚) : a₁ β€’ b ≀ aβ‚‚ β€’ b /-- Typeclass for strict monotonicity of scalar multiplication by positive elements on the left, namely `a₁ < aβ‚‚ β†’ a₁ β€’ b < aβ‚‚ β€’ b` if `0 < b`. You should usually not use this very granular typeclass directly, but rather a typeclass like `OrderedSMul`. -/ class SMulPosStrictMono : Prop where /-- Do not use this. Use `smul_lt_smul_of_pos_right` instead. -/ protected elim ⦃b : β⦄ (hb : 0 < b) ⦃a₁ aβ‚‚ : α⦄ (ha : a₁ < aβ‚‚) : a₁ β€’ b < aβ‚‚ β€’ b /-- Typeclass for strict reverse monotonicity of scalar multiplication by nonnegative elements on the left, namely `a₁ β€’ b < aβ‚‚ β€’ b β†’ a₁ < aβ‚‚` if `0 ≀ b`. You should usually not use this very granular typeclass directly, but rather a typeclass like `OrderedSMul`. -/ class SMulPosReflectLT : Prop where /-- Do not use this. Use `lt_of_smul_lt_smul_right` instead. -/ protected elim ⦃b : β⦄ (hb : 0 ≀ b) ⦃a₁ aβ‚‚ : α⦄ (hb : a₁ β€’ b < aβ‚‚ β€’ b) : a₁ < aβ‚‚ /-- Typeclass for reverse monotonicity of scalar multiplication by positive elements on the left, namely `a₁ β€’ b ≀ aβ‚‚ β€’ b β†’ a₁ ≀ aβ‚‚` if `0 < b`. You should usually not use this very granular typeclass directly, but rather a typeclass like `OrderedSMul`. -/ class SMulPosReflectLE : Prop where /-- Do not use this. Use `le_of_smul_lt_smul_right` instead. -/ protected elim ⦃b : β⦄ (hb : 0 < b) ⦃a₁ aβ‚‚ : α⦄ (hb : a₁ β€’ b ≀ aβ‚‚ β€’ b) : a₁ ≀ aβ‚‚ end Right end Defs variable {Ξ± Ξ²} {a a₁ aβ‚‚ : Ξ±} {b b₁ bβ‚‚ : Ξ²} section Mul variable [Zero Ξ±] [Mul Ξ±] [Preorder Ξ±] -- See note [lower instance priority] instance (priority := 100) PosMulMono.toPosSMulMono [PosMulMono Ξ±] : PosSMulMono Ξ± Ξ± where elim _a ha _b₁ _bβ‚‚ hb := mul_le_mul_of_nonneg_left hb ha -- See note [lower instance priority] instance (priority := 100) PosMulStrictMono.toPosSMulStrictMono [PosMulStrictMono Ξ±] : PosSMulStrictMono Ξ± Ξ± where elim _a ha _b₁ _bβ‚‚ hb := mul_lt_mul_of_pos_left hb ha -- See note [lower instance priority] instance (priority := 100) PosMulReflectLT.toPosSMulReflectLT [PosMulReflectLT Ξ±] : PosSMulReflectLT Ξ± Ξ± where elim _a ha _b₁ _bβ‚‚ h := lt_of_mul_lt_mul_left h ha -- See note [lower instance priority] instance (priority := 100) PosMulReflectLE.toPosSMulReflectLE [PosMulReflectLE Ξ±] : PosSMulReflectLE Ξ± Ξ± where elim _a ha _b₁ _bβ‚‚ h := le_of_mul_le_mul_left h ha -- See note [lower instance priority] instance (priority := 100) MulPosMono.toSMulPosMono [MulPosMono Ξ±] : SMulPosMono Ξ± Ξ± where elim _b hb _a₁ _aβ‚‚ ha := mul_le_mul_of_nonneg_right ha hb -- See note [lower instance priority] instance (priority := 100) MulPosStrictMono.toSMulPosStrictMono [MulPosStrictMono Ξ±] : SMulPosStrictMono Ξ± Ξ± where elim _b hb _a₁ _aβ‚‚ ha := mul_lt_mul_of_pos_right ha hb -- See note [lower instance priority] instance (priority := 100) MulPosReflectLT.toSMulPosReflectLT [MulPosReflectLT Ξ±] : SMulPosReflectLT Ξ± Ξ± where elim _b hb _a₁ _aβ‚‚ h := lt_of_mul_lt_mul_right h hb -- See note [lower instance priority] instance (priority := 100) MulPosReflectLE.toSMulPosReflectLE [MulPosReflectLE Ξ±] : SMulPosReflectLE Ξ± Ξ± where elim _b hb _a₁ _aβ‚‚ h := le_of_mul_le_mul_right h hb end Mul section SMul variable [SMul Ξ± Ξ²] section Preorder variable [Preorder Ξ±] [Preorder Ξ²] section Left variable [Zero Ξ±] lemma monotone_smul_left_of_nonneg [PosSMulMono Ξ± Ξ²] (ha : 0 ≀ a) : Monotone ((a β€’ Β·) : Ξ² β†’ Ξ²) := PosSMulMono.elim ha lemma strictMono_smul_left_of_pos [PosSMulStrictMono Ξ± Ξ²] (ha : 0 < a) : StrictMono ((a β€’ Β·) : Ξ² β†’ Ξ²) := PosSMulStrictMono.elim ha @[gcongr] lemma smul_le_smul_of_nonneg_left [PosSMulMono Ξ± Ξ²] (hb : b₁ ≀ bβ‚‚) (ha : 0 ≀ a) : a β€’ b₁ ≀ a β€’ bβ‚‚ := monotone_smul_left_of_nonneg ha hb @[gcongr] lemma smul_lt_smul_of_pos_left [PosSMulStrictMono Ξ± Ξ²] (hb : b₁ < bβ‚‚) (ha : 0 < a) : a β€’ b₁ < a β€’ bβ‚‚ := strictMono_smul_left_of_pos ha hb lemma lt_of_smul_lt_smul_left [PosSMulReflectLT Ξ± Ξ²] (h : a β€’ b₁ < a β€’ bβ‚‚) (ha : 0 ≀ a) : b₁ < bβ‚‚ := PosSMulReflectLT.elim ha h lemma le_of_smul_le_smul_left [PosSMulReflectLE Ξ± Ξ²] (h : a β€’ b₁ ≀ a β€’ bβ‚‚) (ha : 0 < a) : b₁ ≀ bβ‚‚ := PosSMulReflectLE.elim ha h alias lt_of_smul_lt_smul_of_nonneg_left := lt_of_smul_lt_smul_left alias le_of_smul_le_smul_of_pos_left := le_of_smul_le_smul_left @[simp] lemma smul_le_smul_iff_of_pos_left [PosSMulMono Ξ± Ξ²] [PosSMulReflectLE Ξ± Ξ²] (ha : 0 < a) : a β€’ b₁ ≀ a β€’ bβ‚‚ ↔ b₁ ≀ bβ‚‚ := ⟨fun h ↦ le_of_smul_le_smul_left h ha, fun h ↦ smul_le_smul_of_nonneg_left h ha.le⟩ @[simp] lemma smul_lt_smul_iff_of_pos_left [PosSMulStrictMono Ξ± Ξ²] [PosSMulReflectLT Ξ± Ξ²] (ha : 0 < a) : a β€’ b₁ < a β€’ bβ‚‚ ↔ b₁ < bβ‚‚ := ⟨fun h ↦ lt_of_smul_lt_smul_left h ha.le, fun hb ↦ smul_lt_smul_of_pos_left hb ha⟩ end Left section Right variable [Zero Ξ²] lemma monotone_smul_right_of_nonneg [SMulPosMono Ξ± Ξ²] (hb : 0 ≀ b) : Monotone ((Β· β€’ b) : Ξ± β†’ Ξ²) := SMulPosMono.elim hb lemma strictMono_smul_right_of_pos [SMulPosStrictMono Ξ± Ξ²] (hb : 0 < b) : StrictMono ((Β· β€’ b) : Ξ± β†’ Ξ²) := SMulPosStrictMono.elim hb @[gcongr] lemma smul_le_smul_of_nonneg_right [SMulPosMono Ξ± Ξ²] (ha : a₁ ≀ aβ‚‚) (hb : 0 ≀ b) : a₁ β€’ b ≀ aβ‚‚ β€’ b := monotone_smul_right_of_nonneg hb ha @[gcongr] lemma smul_lt_smul_of_pos_right [SMulPosStrictMono Ξ± Ξ²] (ha : a₁ < aβ‚‚) (hb : 0 < b) : a₁ β€’ b < aβ‚‚ β€’ b := strictMono_smul_right_of_pos hb ha lemma lt_of_smul_lt_smul_right [SMulPosReflectLT Ξ± Ξ²] (h : a₁ β€’ b < aβ‚‚ β€’ b) (hb : 0 ≀ b) : a₁ < aβ‚‚ := SMulPosReflectLT.elim hb h lemma le_of_smul_le_smul_right [SMulPosReflectLE Ξ± Ξ²] (h : a₁ β€’ b ≀ aβ‚‚ β€’ b) (hb : 0 < b) : a₁ ≀ aβ‚‚ := SMulPosReflectLE.elim hb h alias lt_of_smul_lt_smul_of_nonneg_right := lt_of_smul_lt_smul_right alias le_of_smul_le_smul_of_pos_right := le_of_smul_le_smul_right @[simp] lemma smul_le_smul_iff_of_pos_right [SMulPosMono Ξ± Ξ²] [SMulPosReflectLE Ξ± Ξ²] (hb : 0 < b) : a₁ β€’ b ≀ aβ‚‚ β€’ b ↔ a₁ ≀ aβ‚‚ := ⟨fun h ↦ le_of_smul_le_smul_right h hb, fun ha ↦ smul_le_smul_of_nonneg_right ha hb.le⟩ @[simp] lemma smul_lt_smul_iff_of_pos_right [SMulPosStrictMono Ξ± Ξ²] [SMulPosReflectLT Ξ± Ξ²] (hb : 0 < b) : a₁ β€’ b < aβ‚‚ β€’ b ↔ a₁ < aβ‚‚ := ⟨fun h ↦ lt_of_smul_lt_smul_right h hb.le, fun ha ↦ smul_lt_smul_of_pos_right ha hb⟩ end Right section LeftRight variable [Zero Ξ±] [Zero Ξ²] lemma smul_lt_smul_of_le_of_lt [PosSMulStrictMono Ξ± Ξ²] [SMulPosMono Ξ± Ξ²] (ha : a₁ ≀ aβ‚‚) (hb : b₁ < bβ‚‚) (h₁ : 0 < a₁) (hβ‚‚ : 0 ≀ bβ‚‚) : a₁ β€’ b₁ < aβ‚‚ β€’ bβ‚‚ := (smul_lt_smul_of_pos_left hb h₁).trans_le (smul_le_smul_of_nonneg_right ha hβ‚‚) lemma smul_lt_smul_of_le_of_lt' [PosSMulStrictMono Ξ± Ξ²] [SMulPosMono Ξ± Ξ²] (ha : a₁ ≀ aβ‚‚) (hb : b₁ < bβ‚‚) (hβ‚‚ : 0 < aβ‚‚) (h₁ : 0 ≀ b₁) : a₁ β€’ b₁ < aβ‚‚ β€’ bβ‚‚ := (smul_le_smul_of_nonneg_right ha h₁).trans_lt (smul_lt_smul_of_pos_left hb hβ‚‚) lemma smul_lt_smul_of_lt_of_le [PosSMulMono Ξ± Ξ²] [SMulPosStrictMono Ξ± Ξ²] (ha : a₁ < aβ‚‚) (hb : b₁ ≀ bβ‚‚) (h₁ : 0 ≀ a₁) (hβ‚‚ : 0 < bβ‚‚) : a₁ β€’ b₁ < aβ‚‚ β€’ bβ‚‚ := (smul_le_smul_of_nonneg_left hb h₁).trans_lt (smul_lt_smul_of_pos_right ha hβ‚‚) lemma smul_lt_smul_of_lt_of_le' [PosSMulMono Ξ± Ξ²] [SMulPosStrictMono Ξ± Ξ²] (ha : a₁ < aβ‚‚) (hb : b₁ ≀ bβ‚‚) (hβ‚‚ : 0 ≀ aβ‚‚) (h₁ : 0 < b₁) : a₁ β€’ b₁ < aβ‚‚ β€’ bβ‚‚ := (smul_lt_smul_of_pos_right ha h₁).trans_le (smul_le_smul_of_nonneg_left hb hβ‚‚) lemma smul_lt_smul [PosSMulStrictMono Ξ± Ξ²] [SMulPosStrictMono Ξ± Ξ²] (ha : a₁ < aβ‚‚) (hb : b₁ < bβ‚‚) (h₁ : 0 < a₁) (hβ‚‚ : 0 < bβ‚‚) : a₁ β€’ b₁ < aβ‚‚ β€’ bβ‚‚ := (smul_lt_smul_of_pos_left hb h₁).trans (smul_lt_smul_of_pos_right ha hβ‚‚) lemma smul_lt_smul' [PosSMulStrictMono Ξ± Ξ²] [SMulPosStrictMono Ξ± Ξ²] (ha : a₁ < aβ‚‚) (hb : b₁ < bβ‚‚) (hβ‚‚ : 0 < aβ‚‚) (h₁ : 0 < b₁) : a₁ β€’ b₁ < aβ‚‚ β€’ bβ‚‚ := (smul_lt_smul_of_pos_right ha h₁).trans (smul_lt_smul_of_pos_left hb hβ‚‚) lemma smul_le_smul [PosSMulMono Ξ± Ξ²] [SMulPosMono Ξ± Ξ²] (ha : a₁ ≀ aβ‚‚) (hb : b₁ ≀ bβ‚‚) (h₁ : 0 ≀ a₁) (hβ‚‚ : 0 ≀ bβ‚‚) : a₁ β€’ b₁ ≀ aβ‚‚ β€’ bβ‚‚ := (smul_le_smul_of_nonneg_left hb h₁).trans (smul_le_smul_of_nonneg_right ha hβ‚‚) lemma smul_le_smul' [PosSMulMono Ξ± Ξ²] [SMulPosMono Ξ± Ξ²] (ha : a₁ ≀ aβ‚‚) (hb : b₁ ≀ bβ‚‚) (hβ‚‚ : 0 ≀ aβ‚‚) (h₁ : 0 ≀ b₁) : a₁ β€’ b₁ ≀ aβ‚‚ β€’ bβ‚‚ := (smul_le_smul_of_nonneg_right ha h₁).trans (smul_le_smul_of_nonneg_left hb hβ‚‚) end LeftRight end Preorder section LinearOrder variable [Preorder Ξ±] [LinearOrder Ξ²] section Left variable [Zero Ξ±] -- See note [lower instance priority] instance (priority := 100) PosSMulStrictMono.toPosSMulReflectLE [PosSMulStrictMono Ξ± Ξ²] : PosSMulReflectLE Ξ± Ξ² where elim _a ha _b₁ _bβ‚‚ := (strictMono_smul_left_of_pos ha).le_iff_le.1 lemma PosSMulReflectLE.toPosSMulStrictMono [PosSMulReflectLE Ξ± Ξ²] : PosSMulStrictMono Ξ± Ξ² where elim _a ha _b₁ _bβ‚‚ hb := not_le.1 fun h ↦ hb.not_le <| le_of_smul_le_smul_left h ha lemma posSMulStrictMono_iff_PosSMulReflectLE : PosSMulStrictMono Ξ± Ξ² ↔ PosSMulReflectLE Ξ± Ξ² := ⟨fun _ ↦ inferInstance, fun _ ↦ PosSMulReflectLE.toPosSMulStrictMono⟩ instance PosSMulMono.toPosSMulReflectLT [PosSMulMono Ξ± Ξ²] : PosSMulReflectLT Ξ± Ξ² where elim _a ha _b₁ _bβ‚‚ := (monotone_smul_left_of_nonneg ha).reflect_lt lemma PosSMulReflectLT.toPosSMulMono [PosSMulReflectLT Ξ± Ξ²] : PosSMulMono Ξ± Ξ² where elim _a ha _b₁ _bβ‚‚ hb := not_lt.1 fun h ↦ hb.not_lt <| lt_of_smul_lt_smul_left h ha lemma posSMulMono_iff_posSMulReflectLT : PosSMulMono Ξ± Ξ² ↔ PosSMulReflectLT Ξ± Ξ² := ⟨fun _ ↦ PosSMulMono.toPosSMulReflectLT, fun _ ↦ PosSMulReflectLT.toPosSMulMono⟩ lemma smul_max_of_nonneg [PosSMulMono Ξ± Ξ²] (ha : 0 ≀ a) (b₁ bβ‚‚ : Ξ²) : a β€’ max b₁ bβ‚‚ = max (a β€’ b₁) (a β€’ bβ‚‚) := (monotone_smul_left_of_nonneg ha).map_max lemma smul_min_of_nonneg [PosSMulMono Ξ± Ξ²] (ha : 0 ≀ a) (b₁ bβ‚‚ : Ξ²) : a β€’ min b₁ bβ‚‚ = min (a β€’ b₁) (a β€’ bβ‚‚) := (monotone_smul_left_of_nonneg ha).map_min end Left section Right variable [Zero Ξ²] lemma SMulPosReflectLE.toSMulPosStrictMono [SMulPosReflectLE Ξ± Ξ²] : SMulPosStrictMono Ξ± Ξ² where elim _b hb _a₁ _aβ‚‚ ha := not_le.1 fun h ↦ ha.not_le <| le_of_smul_le_smul_of_pos_right h hb lemma SMulPosReflectLT.toSMulPosMono [SMulPosReflectLT Ξ± Ξ²] : SMulPosMono Ξ± Ξ² where elim _b hb _a₁ _aβ‚‚ ha := not_lt.1 fun h ↦ ha.not_lt <| lt_of_smul_lt_smul_right h hb end Right end LinearOrder section LinearOrder variable [LinearOrder Ξ±] [Preorder Ξ²] section Right variable [Zero Ξ²] -- See note [lower instance priority] instance (priority := 100) SMulPosStrictMono.toSMulPosReflectLE [SMulPosStrictMono Ξ± Ξ²] : SMulPosReflectLE Ξ± Ξ² where elim _b hb _a₁ _aβ‚‚ h := not_lt.1 fun ha ↦ h.not_lt <| smul_lt_smul_of_pos_right ha hb lemma SMulPosMono.toSMulPosReflectLT [SMulPosMono Ξ± Ξ²] : SMulPosReflectLT Ξ± Ξ² where elim _b hb _a₁ _aβ‚‚ h := not_le.1 fun ha ↦ h.not_le <| smul_le_smul_of_nonneg_right ha hb end Right end LinearOrder section LinearOrder variable [LinearOrder Ξ±] [LinearOrder Ξ²] section Right variable [Zero Ξ²] lemma smulPosStrictMono_iff_SMulPosReflectLE : SMulPosStrictMono Ξ± Ξ² ↔ SMulPosReflectLE Ξ± Ξ² := ⟨fun _ ↦ SMulPosStrictMono.toSMulPosReflectLE, fun _ ↦ SMulPosReflectLE.toSMulPosStrictMono⟩ lemma smulPosMono_iff_smulPosReflectLT : SMulPosMono Ξ± Ξ² ↔ SMulPosReflectLT Ξ± Ξ² := ⟨fun _ ↦ SMulPosMono.toSMulPosReflectLT, fun _ ↦ SMulPosReflectLT.toSMulPosMono⟩ end Right end LinearOrder end SMul section SMulZeroClass variable [Zero Ξ±] [Zero Ξ²] [SMulZeroClass Ξ± Ξ²] section Preorder variable [Preorder Ξ±] [Preorder Ξ²] lemma smul_pos [PosSMulStrictMono Ξ± Ξ²] (ha : 0 < a) (hb : 0 < b) : 0 < a β€’ b := by simpa only [smul_zero] using smul_lt_smul_of_pos_left hb ha lemma smul_neg_of_pos_of_neg [PosSMulStrictMono Ξ± Ξ²] (ha : 0 < a) (hb : b < 0) : a β€’ b < 0 := by simpa only [smul_zero] using smul_lt_smul_of_pos_left hb ha @[simp] lemma smul_pos_iff_of_pos_left [PosSMulStrictMono Ξ± Ξ²] [PosSMulReflectLT Ξ± Ξ²] (ha : 0 < a) : 0 < a β€’ b ↔ 0 < b := by simpa only [smul_zero] using smul_lt_smul_iff_of_pos_left ha (b₁ := 0) (bβ‚‚ := b) lemma smul_neg_iff_of_pos_left [PosSMulStrictMono Ξ± Ξ²] [PosSMulReflectLT Ξ± Ξ²] (ha : 0 < a) : a β€’ b < 0 ↔ b < 0 := by simpa only [smul_zero] using smul_lt_smul_iff_of_pos_left ha (bβ‚‚ := (0 : Ξ²)) lemma smul_nonneg [PosSMulMono Ξ± Ξ²] (ha : 0 ≀ a) (hb : 0 ≀ b₁) : 0 ≀ a β€’ b₁ := by simpa only [smul_zero] using smul_le_smul_of_nonneg_left hb ha lemma smul_nonpos_of_nonneg_of_nonpos [PosSMulMono Ξ± Ξ²] (ha : 0 ≀ a) (hb : b ≀ 0) : a β€’ b ≀ 0 := by simpa only [smul_zero] using smul_le_smul_of_nonneg_left hb ha lemma pos_of_smul_pos_left [PosSMulReflectLT Ξ± Ξ²] (h : 0 < a β€’ b) (ha : 0 ≀ a) : 0 < b := lt_of_smul_lt_smul_left (by rwa [smul_zero]) ha lemma neg_of_smul_neg_left [PosSMulReflectLT Ξ± Ξ²] (h : a β€’ b < 0) (ha : 0 ≀ a) : b < 0 := lt_of_smul_lt_smul_left (by rwa [smul_zero]) ha end Preorder end SMulZeroClass section SMulWithZero variable [Zero Ξ±] [Zero Ξ²] [SMulWithZero Ξ± Ξ²] section Preorder variable [Preorder Ξ±] [Preorder Ξ²] lemma smul_pos' [SMulPosStrictMono Ξ± Ξ²] (ha : 0 < a) (hb : 0 < b) : 0 < a β€’ b := by simpa only [zero_smul] using smul_lt_smul_of_pos_right ha hb lemma smul_neg_of_neg_of_pos [SMulPosStrictMono Ξ± Ξ²] (ha : a < 0) (hb : 0 < b) : a β€’ b < 0 := by simpa only [zero_smul] using smul_lt_smul_of_pos_right ha hb @[simp] lemma smul_pos_iff_of_pos_right [SMulPosStrictMono Ξ± Ξ²] [SMulPosReflectLT Ξ± Ξ²] (hb : 0 < b) : 0 < a β€’ b ↔ 0 < a := by simpa only [zero_smul] using smul_lt_smul_iff_of_pos_right hb (a₁ := 0) (aβ‚‚ := a) lemma smul_nonneg' [SMulPosMono Ξ± Ξ²] (ha : 0 ≀ a) (hb : 0 ≀ b₁) : 0 ≀ a β€’ b₁ := by simpa only [zero_smul] using smul_le_smul_of_nonneg_right ha hb lemma smul_nonpos_of_nonpos_of_nonneg [SMulPosMono Ξ± Ξ²] (ha : a ≀ 0) (hb : 0 ≀ b) : a β€’ b ≀ 0 := by simpa only [zero_smul] using smul_le_smul_of_nonneg_right ha hb lemma pos_of_smul_pos_right [SMulPosReflectLT Ξ± Ξ²] (h : 0 < a β€’ b) (hb : 0 ≀ b) : 0 < a := lt_of_smul_lt_smul_right (by rwa [zero_smul]) hb lemma neg_of_smul_neg_right [SMulPosReflectLT Ξ± Ξ²] (h : a β€’ b < 0) (hb : 0 ≀ b) : a < 0 := lt_of_smul_lt_smul_right (by rwa [zero_smul]) hb lemma pos_iff_pos_of_smul_pos [PosSMulReflectLT Ξ± Ξ²] [SMulPosReflectLT Ξ± Ξ²] (hab : 0 < a β€’ b) : 0 < a ↔ 0 < b := ⟨pos_of_smul_pos_left hab ∘ le_of_lt, pos_of_smul_pos_right hab ∘ le_of_lt⟩ end Preorder section PartialOrder variable [PartialOrder Ξ±] [Preorder Ξ²] /-- A constructor for `PosSMulMono` requiring you to prove `b₁ ≀ bβ‚‚ β†’ a β€’ b₁ ≀ a β€’ bβ‚‚` only when `0 < a` -/ lemma PosSMulMono.of_pos (hβ‚€ : βˆ€ a : Ξ±, 0 < a β†’ βˆ€ b₁ bβ‚‚ : Ξ², b₁ ≀ bβ‚‚ β†’ a β€’ b₁ ≀ a β€’ bβ‚‚) : PosSMulMono Ξ± Ξ² where elim a ha b₁ bβ‚‚ h := by obtain ha | ha := ha.eq_or_lt Β· simp [← ha] Β· exact hβ‚€ _ ha _ _ h /-- A constructor for `PosSMulReflectLT` requiring you to prove `a β€’ b₁ < a β€’ bβ‚‚ β†’ b₁ < bβ‚‚` only when `0 < a` -/ lemma PosSMulReflectLT.of_pos (hβ‚€ : βˆ€ a : Ξ±, 0 < a β†’ βˆ€ b₁ bβ‚‚ : Ξ², a β€’ b₁ < a β€’ bβ‚‚ β†’ b₁ < bβ‚‚) : PosSMulReflectLT Ξ± Ξ² where elim a ha b₁ bβ‚‚ h := by obtain ha | ha := ha.eq_or_lt Β· simp [← ha] at h Β· exact hβ‚€ _ ha _ _ h end PartialOrder section PartialOrder variable [Preorder Ξ±] [PartialOrder Ξ²] /-- A constructor for `SMulPosMono` requiring you to prove `a₁ ≀ aβ‚‚ β†’ a₁ β€’ b ≀ aβ‚‚ β€’ b` only when `0 < b` -/ lemma SMulPosMono.of_pos (hβ‚€ : βˆ€ b : Ξ², 0 < b β†’ βˆ€ a₁ aβ‚‚ : Ξ±, a₁ ≀ aβ‚‚ β†’ a₁ β€’ b ≀ aβ‚‚ β€’ b) : SMulPosMono Ξ± Ξ² where elim b hb a₁ aβ‚‚ h := by obtain hb | hb := hb.eq_or_lt Β· simp [← hb] Β· exact hβ‚€ _ hb _ _ h /-- A constructor for `SMulPosReflectLT` requiring you to prove `a₁ β€’ b < aβ‚‚ β€’ b β†’ a₁ < aβ‚‚` only when `0 < b` -/ lemma SMulPosReflectLT.of_pos (hβ‚€ : βˆ€ b : Ξ², 0 < b β†’ βˆ€ a₁ aβ‚‚ : Ξ±, a₁ β€’ b < aβ‚‚ β€’ b β†’ a₁ < aβ‚‚) : SMulPosReflectLT Ξ± Ξ² where elim b hb a₁ aβ‚‚ h := by obtain hb | hb := hb.eq_or_lt Β· simp [← hb] at h Β· exact hβ‚€ _ hb _ _ h end PartialOrder section PartialOrder variable [PartialOrder Ξ±] [PartialOrder Ξ²] -- See note [lower instance priority] instance (priority := 100) PosSMulStrictMono.toPosSMulMono [PosSMulStrictMono Ξ± Ξ²] : PosSMulMono Ξ± Ξ² := PosSMulMono.of_pos fun _a ha ↦ (strictMono_smul_left_of_pos ha).monotone -- See note [lower instance priority] instance (priority := 100) SMulPosStrictMono.toSMulPosMono [SMulPosStrictMono Ξ± Ξ²] : SMulPosMono Ξ± Ξ² := SMulPosMono.of_pos fun _b hb ↦ (strictMono_smul_right_of_pos hb).monotone -- See note [lower instance priority] instance (priority := 100) PosSMulReflectLE.toPosSMulReflectLT [PosSMulReflectLE Ξ± Ξ²] : PosSMulReflectLT Ξ± Ξ² := PosSMulReflectLT.of_pos fun a ha b₁ bβ‚‚ h ↦ (le_of_smul_le_smul_of_pos_left h.le ha).lt_of_ne <| by rintro rfl; simp at h -- See note [lower instance priority] instance (priority := 100) SMulPosReflectLE.toSMulPosReflectLT [SMulPosReflectLE Ξ± Ξ²] : SMulPosReflectLT Ξ± Ξ² := SMulPosReflectLT.of_pos fun b hb a₁ aβ‚‚ h ↦ (le_of_smul_le_smul_of_pos_right h.le hb).lt_of_ne <| by rintro rfl; simp at h lemma smul_eq_smul_iff_eq_and_eq_of_pos [PosSMulStrictMono Ξ± Ξ²] [SMulPosStrictMono Ξ± Ξ²] (ha : a₁ ≀ aβ‚‚) (hb : b₁ ≀ bβ‚‚) (h₁ : 0 < a₁) (hβ‚‚ : 0 < bβ‚‚) : a₁ β€’ b₁ = aβ‚‚ β€’ bβ‚‚ ↔ a₁ = aβ‚‚ ∧ b₁ = bβ‚‚ := by refine ⟨fun h ↦ ?_, by rintro ⟨rfl, rfl⟩; rfl⟩ simp only [eq_iff_le_not_lt, ha, hb, true_and] refine ⟨fun ha ↦ h.not_lt ?_, fun hb ↦ h.not_lt ?_⟩ Β· exact (smul_le_smul_of_nonneg_left hb h₁.le).trans_lt (smul_lt_smul_of_pos_right ha hβ‚‚) Β· exact (smul_lt_smul_of_pos_left hb h₁).trans_le (smul_le_smul_of_nonneg_right ha hβ‚‚.le) lemma smul_eq_smul_iff_eq_and_eq_of_pos' [PosSMulStrictMono Ξ± Ξ²] [SMulPosStrictMono Ξ± Ξ²] (ha : a₁ ≀ aβ‚‚) (hb : b₁ ≀ bβ‚‚) (hβ‚‚ : 0 < aβ‚‚) (h₁ : 0 < b₁) : a₁ β€’ b₁ = aβ‚‚ β€’ bβ‚‚ ↔ a₁ = aβ‚‚ ∧ b₁ = bβ‚‚ := by refine ⟨fun h ↦ ?_, by rintro ⟨rfl, rfl⟩; rfl⟩ simp only [eq_iff_le_not_lt, ha, hb, true_and] refine ⟨fun ha ↦ h.not_lt ?_, fun hb ↦ h.not_lt ?_⟩ Β· exact (smul_lt_smul_of_pos_right ha h₁).trans_le (smul_le_smul_of_nonneg_left hb hβ‚‚.le) Β· exact (smul_le_smul_of_nonneg_right ha h₁.le).trans_lt (smul_lt_smul_of_pos_left hb hβ‚‚) end PartialOrder section LinearOrder variable [LinearOrder Ξ±] [LinearOrder Ξ²] lemma pos_and_pos_or_neg_and_neg_of_smul_pos [PosSMulMono Ξ± Ξ²] [SMulPosMono Ξ± Ξ²] (hab : 0 < a β€’ b) : 0 < a ∧ 0 < b ∨ a < 0 ∧ b < 0 := by obtain ha | rfl | ha := lt_trichotomy a 0 Β· refine Or.inr ⟨ha, lt_imp_lt_of_le_imp_le (fun hb ↦ ?_) hab⟩ exact smul_nonpos_of_nonpos_of_nonneg ha.le hb Β· rw [zero_smul] at hab exact hab.false.elim Β· refine Or.inl ⟨ha, lt_imp_lt_of_le_imp_le (fun hb ↦ ?_) hab⟩ exact smul_nonpos_of_nonneg_of_nonpos ha.le hb lemma neg_of_smul_pos_right [PosSMulMono Ξ± Ξ²] [SMulPosMono Ξ± Ξ²] (h : 0 < a β€’ b) (ha : a ≀ 0) : b < 0 := ((pos_and_pos_or_neg_and_neg_of_smul_pos h).resolve_left fun h ↦ h.1.not_le ha).2 lemma neg_of_smul_pos_left [PosSMulMono Ξ± Ξ²] [SMulPosMono Ξ± Ξ²] (h : 0 < a β€’ b) (ha : b ≀ 0) : a < 0 := ((pos_and_pos_or_neg_and_neg_of_smul_pos h).resolve_left fun h ↦ h.2.not_le ha).1 lemma neg_iff_neg_of_smul_pos [PosSMulMono Ξ± Ξ²] [SMulPosMono Ξ± Ξ²] (hab : 0 < a β€’ b) : a < 0 ↔ b < 0 := ⟨neg_of_smul_pos_right hab ∘ le_of_lt, neg_of_smul_pos_left hab ∘ le_of_lt⟩ lemma neg_of_smul_neg_left' [SMulPosMono Ξ± Ξ²] (h : a β€’ b < 0) (ha : 0 ≀ a) : b < 0 := lt_of_not_ge fun hb ↦ (smul_nonneg' ha hb).not_lt h lemma neg_of_smul_neg_right' [PosSMulMono Ξ± Ξ²] (h : a β€’ b < 0) (hb : 0 ≀ b) : a < 0 := lt_of_not_ge fun ha ↦ (smul_nonneg ha hb).not_lt h end LinearOrder end SMulWithZero section MulAction variable [Monoid Ξ±] [Zero Ξ²] [MulAction Ξ± Ξ²] section Preorder variable [Preorder Ξ±] [Preorder Ξ²] @[simp] lemma le_smul_iff_one_le_left [SMulPosMono Ξ± Ξ²] [SMulPosReflectLE Ξ± Ξ²] (hb : 0 < b) : b ≀ a β€’ b ↔ 1 ≀ a := Iff.trans (by rw [one_smul]) (smul_le_smul_iff_of_pos_right hb) @[simp] lemma lt_smul_iff_one_lt_left [SMulPosStrictMono Ξ± Ξ²] [SMulPosReflectLT Ξ± Ξ²] (hb : 0 < b) : b < a β€’ b ↔ 1 < a := Iff.trans (by rw [one_smul]) (smul_lt_smul_iff_of_pos_right hb) @[simp] lemma smul_le_iff_le_one_left [SMulPosMono Ξ± Ξ²] [SMulPosReflectLE Ξ± Ξ²] (hb : 0 < b) : a β€’ b ≀ b ↔ a ≀ 1 := Iff.trans (by rw [one_smul]) (smul_le_smul_iff_of_pos_right hb) @[simp] lemma smul_lt_iff_lt_one_left [SMulPosStrictMono Ξ± Ξ²] [SMulPosReflectLT Ξ± Ξ²] (hb : 0 < b) : a β€’ b < b ↔ a < 1 := Iff.trans (by rw [one_smul]) (smul_lt_smul_iff_of_pos_right hb) lemma smul_le_of_le_one_left [SMulPosMono Ξ± Ξ²] (hb : 0 ≀ b) (h : a ≀ 1) : a β€’ b ≀ b := by simpa only [one_smul] using smul_le_smul_of_nonneg_right h hb lemma le_smul_of_one_le_left [SMulPosMono Ξ± Ξ²] (hb : 0 ≀ b) (h : 1 ≀ a) : b ≀ a β€’ b := by simpa only [one_smul] using smul_le_smul_of_nonneg_right h hb lemma smul_lt_of_lt_one_left [SMulPosStrictMono Ξ± Ξ²] (hb : 0 < b) (h : a < 1) : a β€’ b < b := by simpa only [one_smul] using smul_lt_smul_of_pos_right h hb lemma lt_smul_of_one_lt_left [SMulPosStrictMono Ξ± Ξ²] (hb : 0 < b) (h : 1 < a) : b < a β€’ b := by
simpa only [one_smul] using smul_lt_smul_of_pos_right h hb end Preorder
Mathlib/Algebra/Order/Module/Defs.lean
676
678
/- 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.Attach import Mathlib.Data.Finset.Disjoint import Mathlib.Data.Finset.Erase import Mathlib.Data.Finset.Filter import Mathlib.Data.Finset.Range import Mathlib.Data.Finset.SDiff import Mathlib.Data.Multiset.Basic import Mathlib.Logic.Equiv.Set import Mathlib.Order.Directed import Mathlib.Order.Interval.Set.Defs import Mathlib.Data.Set.SymmDiff /-! # Basic lemmas on finite sets This file contains lemmas on the interaction of various definitions on the `Finset` type. For an explanation of `Finset` design decisions, please see `Mathlib/Data/Finset/Defs.lean`. ## Main declarations ### Main definitions * `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. ### Equivalences between finsets * The `Mathlib/Logic/Equiv/Defs.lean` file describes 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 Multiset.powerset CompleteLattice Monoid open Multiset Subtype Function universe u variable {Ξ± : Type*} {Ξ² : Type*} {Ξ³ : Type*} namespace Finset -- TODO: these should be global attributes, but this will require fixing other files attribute [local trans] Subset.trans Superset.trans set_option linter.deprecated false in @[deprecated "Deprecated without replacement." (since := "2025-02-07")] 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 [Nat.add_comm] refine lt_trans ?_ (Nat.lt_succ_self _) exact Multiset.sizeOf_lt_sizeOf_of_mem hx /-! ### Lattice structure -/ section Lattice variable [DecidableEq Ξ±] {s s₁ sβ‚‚ t t₁ tβ‚‚ u v : Finset Ξ±} {a b : Ξ±} /-! #### union -/ @[simp] theorem disjUnion_eq_union (s t h) : @disjUnion Ξ± s t h = s βˆͺ t := ext fun a => by simp @[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] @[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] /-! #### inter -/ theorem not_disjoint_iff_nonempty_inter : Β¬Disjoint s t ↔ (s ∩ t).Nonempty := not_disjoint_iff.trans <| by simp [Finset.Nonempty] alias ⟨_, Nonempty.not_disjoint⟩ := not_disjoint_iff_nonempty_inter theorem disjoint_or_nonempty_inter (s t : Finset Ξ±) : Disjoint s t ∨ (s ∩ t).Nonempty := by rw [← not_disjoint_iff_nonempty_inter] exact em _ omit [DecidableEq Ξ±] in theorem disjoint_of_subset_iff_left_eq_empty (h : s βŠ† t) : Disjoint s t ↔ s = βˆ… := disjoint_of_le_iff_left_eq_bot h lemma pairwiseDisjoint_iff {ΞΉ : Type*} {s : Set ΞΉ} {f : ΞΉ β†’ Finset Ξ±} : s.PairwiseDisjoint f ↔ βˆ€ ⦃i⦄, i ∈ s β†’ βˆ€ ⦃j⦄, j ∈ s β†’ (f i ∩ f j).Nonempty β†’ i = j := by simp [Set.PairwiseDisjoint, Set.Pairwise, Function.onFun, not_imp_comm (a := _ = _), not_disjoint_iff_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 : Ξ±} @[simp] theorem erase_empty (a : Ξ±) : erase βˆ… a = βˆ… := rfl 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 @[simp] theorem erase_insert_eq_erase (s : Finset Ξ±) (a : Ξ±) : (insert a s).erase a = s.erase a := ext fun x => by simp +contextual only [mem_erase, mem_insert, and_congr_right_iff, false_or, iff_self, imp_true_iff] 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] 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] 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] @[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] apply or_iff_right_of_imp rintro rfl exact h 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_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 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⟩⟩ 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 _ _⟩ 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] 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 theorem erase_insert_subset (a : Ξ±) (s : Finset Ξ±) : erase (insert a s) a βŠ† s := subset_insert_iff.1 <| Subset.rfl theorem insert_erase_subset (a : Ξ±) (s : Finset Ξ±) : s βŠ† insert a (erase s a) := subset_insert_iff.2 <| Subset.rfl 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] 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] 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] 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 : Ξ±} lemma erase_sdiff_erase (hab : a β‰  b) (hb : b ∈ s) : s.erase a \ s.erase b = {b} := by ext; aesop -- 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 \ {a} = erase s a := by ext rw [mem_erase, mem_sdiff, mem_singleton, and_comm] -- This lemma matches `Finset.insert_eq` in functionality. theorem erase_eq (s : Finset Ξ±) (a : Ξ±) : s.erase a = s \ {a} := (sdiff_singleton_eq_erase _ _).symm theorem disjoint_erase_comm : Disjoint (s.erase a) t ↔ Disjoint s (t.erase a) := by simp_rw [erase_eq, disjoint_sdiff_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⟩ 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⟩ theorem inter_erase (a : Ξ±) (s t : Finset Ξ±) : s ∩ t.erase a = (s ∩ t).erase a := by simp only [erase_eq, inter_sdiff_assoc] @[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 theorem erase_sdiff_comm (s t : Finset Ξ±) (a : Ξ±) : s.erase a \ t = (s \ t).erase a := by simp_rw [erase_eq, sdiff_right_comm] theorem erase_inter_comm (s t : Finset Ξ±) (a : Ξ±) : s.erase a ∩ t = s ∩ t.erase a := by rw [erase_inter, inter_erase] 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] 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] 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] 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] 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] 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)] 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] 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⟩)] 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] theorem sdiff_erase_self (ha : a ∈ s) : s \ s.erase a = {a} := by rw [sdiff_erase ha, Finset.sdiff_self, insert_empty_eq] 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] --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 theorem disjoint_sdiff : Disjoint s (t \ s) := sdiff_disjoint.symm theorem disjoint_sdiff_inter (s t : Finset Ξ±) : Disjoint (s \ t) (s ∩ t) := disjoint_of_subset_right inter_subset_right sdiff_disjoint end Sdiff /-! ### attach -/ @[simp] theorem attach_empty : attach (βˆ… : Finset Ξ±) = βˆ… := rfl @[simp] theorem attach_nonempty_iff {s : Finset Ξ±} : s.attach.Nonempty ↔ s.Nonempty := by simp [Finset.Nonempty] @[aesop safe apply (rule_sets := [finsetNonempty])] 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] /-! ### filter -/ section Filter variable (p q : Ξ± β†’ Prop) [DecidablePred p] [DecidablePred q] {s t : Finset Ξ±} 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'] 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_of_mem_filter _).mt ha) := eq_of_veq <| Multiset.filter_cons_of_pos s.val hp 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 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 +contextual [disjoint_left] 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 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 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 _ _ _ theorem filter_cons {a : Ξ±} (s : Finset Ξ±) (ha : a βˆ‰ s) : filter p (cons a s ha) = if p a then cons a (filter p s) ((mem_of_mem_filter _).mt ha) else filter p s := by split_ifs with h Β· rw [filter_cons_of_pos _ _ _ ha h] Β· rw [filter_cons_of_neg _ _ _ ha h] section 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] 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] 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] 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] 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] theorem inter_filter (s t : Finset Ξ±) : s ∩ filter p t = filter p (s ∩ t) := by rw [inter_comm, filter_inter, inter_comm] 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'] 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, mem_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] 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] 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] 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] 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β‚‚βŸ© -- 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, not_mem_empty, decide_eq_true_eq] rintro m rfl exact h m /-- 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) 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 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) 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 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 end end Filter /-! ### range -/ section Range open Nat variable {n m l : β„•} @[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 end Range end Finset /-! ### dedup on list and multiset -/ namespace Multiset variable [DecidableEq Ξ±] {s t : Multiset Ξ±} @[simp] theorem toFinset_add (s t : Multiset Ξ±) : toFinset (s + t) = toFinset s βˆͺ toFinset t := Finset.ext <| by simp @[simp] theorem toFinset_inter (s t : Multiset Ξ±) : toFinset (s ∩ t) = toFinset s ∩ toFinset t := Finset.ext <| by simp @[simp] theorem toFinset_union (s t : Multiset Ξ±) : (s βˆͺ t).toFinset = s.toFinset βˆͺ t.toFinset := by ext; simp @[simp] theorem toFinset_eq_empty {m : Multiset Ξ±} : m.toFinset = βˆ… ↔ m = 0 := Finset.val_inj.symm.trans Multiset.dedup_eq_zero @[simp] theorem toFinset_nonempty : s.toFinset.Nonempty ↔ s β‰  0 := by simp only [toFinset_eq_empty, Ne, Finset.nonempty_iff_ne_empty] @[aesop safe apply (rule_sets := [finsetNonempty])] protected alias ⟨_, Aesop.toFinset_nonempty_of_ne⟩ := toFinset_nonempty @[simp] theorem toFinset_filter (s : Multiset Ξ±) (p : Ξ± β†’ Prop) [DecidablePred p] : Multiset.toFinset (s.filter p) = s.toFinset.filter p := by ext; simp end Multiset namespace List
variable [DecidableEq Ξ±] {l l' : List Ξ±} {a : Ξ±} {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Set Ξ²} {t' : Finset Ξ²}
Mathlib/Data/Finset/Basic.lean
550
552
/- 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, Yury Kudryashov -/ import Mathlib.Data.Set.SymmDiff import Mathlib.Order.SuccPred.Relation import Mathlib.Topology.Irreducible /-! # Connected subsets of topological spaces In this file we define connected subsets of a topological spaces and various other properties and classes related to connectivity. ## Main definitions We define the following properties for sets in a topological space: * `IsConnected`: a nonempty set that has no non-trivial open partition. See also the section below in the module doc. * `connectedComponent` is the connected component of an element in the space. We also have a class stating that the whole space satisfies that property: `ConnectedSpace` ## On the definition of connected sets/spaces In informal mathematics, connected spaces are assumed to be nonempty. We formalise the predicate without that assumption as `IsPreconnected`. In other words, the only difference is whether the empty space counts as connected. There are good reasons to consider the empty space to be β€œtoo simple to be simple” See also https://ncatlab.org/nlab/show/too+simple+to+be+simple, and in particular https://ncatlab.org/nlab/show/too+simple+to+be+simple#relationship_to_biased_definitions. -/ open Set Function Topology TopologicalSpace Relation universe u v variable {Ξ± : Type u} {Ξ² : Type v} {ΞΉ : Type*} {Ο€ : ΞΉ β†’ Type*} [TopologicalSpace Ξ±] {s t u v : Set Ξ±} section Preconnected /-- A preconnected set is one where there is no non-trivial open partition. -/ def IsPreconnected (s : Set Ξ±) : Prop := βˆ€ u v : Set Ξ±, IsOpen u β†’ IsOpen v β†’ s βŠ† u βˆͺ v β†’ (s ∩ u).Nonempty β†’ (s ∩ v).Nonempty β†’ (s ∩ (u ∩ v)).Nonempty /-- A connected set is one that is nonempty and where there is no non-trivial open partition. -/ def IsConnected (s : Set Ξ±) : Prop := s.Nonempty ∧ IsPreconnected s theorem IsConnected.nonempty {s : Set Ξ±} (h : IsConnected s) : s.Nonempty := h.1 theorem IsConnected.isPreconnected {s : Set Ξ±} (h : IsConnected s) : IsPreconnected s := h.2 theorem IsPreirreducible.isPreconnected {s : Set Ξ±} (H : IsPreirreducible s) : IsPreconnected s := fun _ _ hu hv _ => H _ _ hu hv theorem IsIrreducible.isConnected {s : Set Ξ±} (H : IsIrreducible s) : IsConnected s := ⟨H.nonempty, H.isPreirreducible.isPreconnected⟩ theorem isPreconnected_empty : IsPreconnected (βˆ… : Set Ξ±) := isPreirreducible_empty.isPreconnected theorem isConnected_singleton {x} : IsConnected ({x} : Set Ξ±) := isIrreducible_singleton.isConnected theorem isPreconnected_singleton {x} : IsPreconnected ({x} : Set Ξ±) := isConnected_singleton.isPreconnected theorem Set.Subsingleton.isPreconnected {s : Set Ξ±} (hs : s.Subsingleton) : IsPreconnected s := hs.induction_on isPreconnected_empty fun _ => isPreconnected_singleton /-- If any point of a set is joined to a fixed point by a preconnected subset, then the original set is preconnected as well. -/ theorem isPreconnected_of_forall {s : Set Ξ±} (x : Ξ±) (H : βˆ€ y ∈ s, βˆƒ t, t βŠ† s ∧ x ∈ t ∧ y ∈ t ∧ IsPreconnected t) : IsPreconnected s := by rintro u v hu hv hs ⟨z, zs, zu⟩ ⟨y, ys, yv⟩ have xs : x ∈ s := by rcases H y ys with ⟨t, ts, xt, -, -⟩ exact ts xt -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: use `wlog xu : x ∈ u := hs xs using u v y z, v u z y` cases hs xs with | inl xu => rcases H y ys with ⟨t, ts, xt, yt, ht⟩ have := ht u v hu hv (ts.trans hs) ⟨x, xt, xu⟩ ⟨y, yt, yv⟩ exact this.imp fun z hz => ⟨ts hz.1, hz.2⟩ | inr xv => rcases H z zs with ⟨t, ts, xt, zt, ht⟩ have := ht v u hv hu (ts.trans <| by rwa [union_comm]) ⟨x, xt, xv⟩ ⟨z, zt, zu⟩ exact this.imp fun _ h => ⟨ts h.1, h.2.2, h.2.1⟩ /-- If any two points of a set are contained in a preconnected subset, then the original set is preconnected as well. -/ theorem isPreconnected_of_forall_pair {s : Set Ξ±} (H : βˆ€ x ∈ s, βˆ€ y ∈ s, βˆƒ t, t βŠ† s ∧ x ∈ t ∧ y ∈ t ∧ IsPreconnected t) : IsPreconnected s := by rcases eq_empty_or_nonempty s with (rfl | ⟨x, hx⟩) exacts [isPreconnected_empty, isPreconnected_of_forall x fun y => H x hx y] /-- A union of a family of preconnected sets with a common point is preconnected as well. -/ theorem isPreconnected_sUnion (x : Ξ±) (c : Set (Set Ξ±)) (H1 : βˆ€ s ∈ c, x ∈ s) (H2 : βˆ€ s ∈ c, IsPreconnected s) : IsPreconnected (⋃₀ c) := by apply isPreconnected_of_forall x rintro y ⟨s, sc, ys⟩ exact ⟨s, subset_sUnion_of_mem sc, H1 s sc, ys, H2 s sc⟩ theorem isPreconnected_iUnion {ΞΉ : Sort*} {s : ΞΉ β†’ Set Ξ±} (h₁ : (β‹‚ i, s i).Nonempty) (hβ‚‚ : βˆ€ i, IsPreconnected (s i)) : IsPreconnected (⋃ i, s i) := Exists.elim h₁ fun f hf => isPreconnected_sUnion f _ hf (forall_mem_range.2 hβ‚‚) theorem IsPreconnected.union (x : Ξ±) {s t : Set Ξ±} (H1 : x ∈ s) (H2 : x ∈ t) (H3 : IsPreconnected s) (H4 : IsPreconnected t) : IsPreconnected (s βˆͺ t) := sUnion_pair s t β–Έ isPreconnected_sUnion x {s, t} (by rintro r (rfl | rfl | h) <;> assumption) (by rintro r (rfl | rfl | h) <;> assumption) theorem IsPreconnected.union' {s t : Set Ξ±} (H : (s ∩ t).Nonempty) (hs : IsPreconnected s) (ht : IsPreconnected t) : IsPreconnected (s βˆͺ t) := by rcases H with ⟨x, hxs, hxt⟩ exact hs.union x hxs hxt ht theorem IsConnected.union {s t : Set Ξ±} (H : (s ∩ t).Nonempty) (Hs : IsConnected s) (Ht : IsConnected t) : IsConnected (s βˆͺ t) := by rcases H with ⟨x, hx⟩ refine ⟨⟨x, mem_union_left t (mem_of_mem_inter_left hx)⟩, ?_⟩ exact Hs.isPreconnected.union x (mem_of_mem_inter_left hx) (mem_of_mem_inter_right hx) Ht.isPreconnected /-- The directed sUnion of a set S of preconnected subsets is preconnected. -/ theorem IsPreconnected.sUnion_directed {S : Set (Set Ξ±)} (K : DirectedOn (Β· βŠ† Β·) S) (H : βˆ€ s ∈ S, IsPreconnected s) : IsPreconnected (⋃₀ S) := by rintro u v hu hv Huv ⟨a, ⟨s, hsS, has⟩, hau⟩ ⟨b, ⟨t, htS, hbt⟩, hbv⟩ obtain ⟨r, hrS, hsr, htr⟩ : βˆƒ r ∈ S, s βŠ† r ∧ t βŠ† r := K s hsS t htS have Hnuv : (r ∩ (u ∩ v)).Nonempty := H _ hrS u v hu hv ((subset_sUnion_of_mem hrS).trans Huv) ⟨a, hsr has, hau⟩ ⟨b, htr hbt, hbv⟩ have Kruv : r ∩ (u ∩ v) βŠ† ⋃₀ S ∩ (u ∩ v) := inter_subset_inter_left _ (subset_sUnion_of_mem hrS) exact Hnuv.mono Kruv /-- The biUnion of a family of preconnected sets is preconnected if the graph determined by whether two sets intersect is preconnected. -/ theorem IsPreconnected.biUnion_of_reflTransGen {ΞΉ : Type*} {t : Set ΞΉ} {s : ΞΉ β†’ Set Ξ±} (H : βˆ€ i ∈ t, IsPreconnected (s i)) (K : βˆ€ i, i ∈ t β†’ βˆ€ j, j ∈ t β†’ ReflTransGen (fun i j => (s i ∩ s j).Nonempty ∧ i ∈ t) i j) : IsPreconnected (⋃ n ∈ t, s n) := by let R := fun i j : ΞΉ => (s i ∩ s j).Nonempty ∧ i ∈ t have P : βˆ€ i, i ∈ t β†’ βˆ€ j, j ∈ t β†’ ReflTransGen R i j β†’ βˆƒ p, p βŠ† t ∧ i ∈ p ∧ j ∈ p ∧ IsPreconnected (⋃ j ∈ p, s j) := fun i hi j hj h => by induction h with | refl => refine ⟨{i}, singleton_subset_iff.mpr hi, mem_singleton i, mem_singleton i, ?_⟩ rw [biUnion_singleton] exact H i hi | @tail j k _ hjk ih => obtain ⟨p, hpt, hip, hjp, hp⟩ := ih hjk.2 refine ⟨insert k p, insert_subset_iff.mpr ⟨hj, hpt⟩, mem_insert_of_mem k hip, mem_insert k p, ?_⟩ rw [biUnion_insert] refine (H k hj).union' (hjk.1.mono ?_) hp rw [inter_comm] exact inter_subset_inter_right _ (subset_biUnion_of_mem hjp) refine isPreconnected_of_forall_pair ?_ intro x hx y hy obtain ⟨i : ΞΉ, hi : i ∈ t, hxi : x ∈ s i⟩ := mem_iUnionβ‚‚.1 hx obtain ⟨j : ΞΉ, hj : j ∈ t, hyj : y ∈ s j⟩ := mem_iUnionβ‚‚.1 hy obtain ⟨p, hpt, hip, hjp, hp⟩ := P i hi j hj (K i hi j hj) exact βŸ¨β‹ƒ j ∈ p, s j, biUnion_subset_biUnion_left hpt, mem_biUnion hip hxi, mem_biUnion hjp hyj, hp⟩ /-- The biUnion of a family of preconnected sets is preconnected if the graph determined by whether two sets intersect is preconnected. -/ theorem IsConnected.biUnion_of_reflTransGen {ΞΉ : Type*} {t : Set ΞΉ} {s : ΞΉ β†’ Set Ξ±} (ht : t.Nonempty) (H : βˆ€ i ∈ t, IsConnected (s i)) (K : βˆ€ i, i ∈ t β†’ βˆ€ j, j ∈ t β†’ ReflTransGen (fun i j : ΞΉ => (s i ∩ s j).Nonempty ∧ i ∈ t) i j) : IsConnected (⋃ n ∈ t, s n) := ⟨nonempty_biUnion.2 <| ⟨ht.some, ht.some_mem, (H _ ht.some_mem).nonempty⟩, IsPreconnected.biUnion_of_reflTransGen (fun i hi => (H i hi).isPreconnected) K⟩ /-- Preconnectedness of the iUnion of a family of preconnected sets indexed by the vertices of a preconnected graph, where two vertices are joined when the corresponding sets intersect. -/ theorem IsPreconnected.iUnion_of_reflTransGen {ΞΉ : Type*} {s : ΞΉ β†’ Set Ξ±} (H : βˆ€ i, IsPreconnected (s i)) (K : βˆ€ i j, ReflTransGen (fun i j : ΞΉ => (s i ∩ s j).Nonempty) i j) : IsPreconnected (⋃ n, s n) := by rw [← biUnion_univ] exact IsPreconnected.biUnion_of_reflTransGen (fun i _ => H i) fun i _ j _ => by simpa [mem_univ] using K i j theorem IsConnected.iUnion_of_reflTransGen {ΞΉ : Type*} [Nonempty ΞΉ] {s : ΞΉ β†’ Set Ξ±} (H : βˆ€ i, IsConnected (s i)) (K : βˆ€ i j, ReflTransGen (fun i j : ΞΉ => (s i ∩ s j).Nonempty) i j) : IsConnected (⋃ n, s n) := ⟨nonempty_iUnion.2 <| Nonempty.elim β€Ή_β€Ί fun i : ΞΉ => ⟨i, (H _).nonempty⟩, IsPreconnected.iUnion_of_reflTransGen (fun i => (H i).isPreconnected) K⟩ section SuccOrder open Order variable [LinearOrder Ξ²] [SuccOrder Ξ²] [IsSuccArchimedean Ξ²] /-- The iUnion of connected sets indexed by a type with an archimedean successor (like `β„•` or `β„€`) such that any two neighboring sets meet is preconnected. -/ theorem IsPreconnected.iUnion_of_chain {s : Ξ² β†’ Set Ξ±} (H : βˆ€ n, IsPreconnected (s n)) (K : βˆ€ n, (s n ∩ s (succ n)).Nonempty) : IsPreconnected (⋃ n, s n) := IsPreconnected.iUnion_of_reflTransGen H fun _ _ => reflTransGen_of_succ _ (fun i _ => K i) fun i _ => by rw [inter_comm] exact K i /-- The iUnion of connected sets indexed by a type with an archimedean successor (like `β„•` or `β„€`) such that any two neighboring sets meet is connected. -/ theorem IsConnected.iUnion_of_chain [Nonempty Ξ²] {s : Ξ² β†’ Set Ξ±} (H : βˆ€ n, IsConnected (s n)) (K : βˆ€ n, (s n ∩ s (succ n)).Nonempty) : IsConnected (⋃ n, s n) := IsConnected.iUnion_of_reflTransGen H fun _ _ => reflTransGen_of_succ _ (fun i _ => K i) fun i _ => by rw [inter_comm] exact K i /-- The iUnion of preconnected sets indexed by a subset of a type with an archimedean successor (like `β„•` or `β„€`) such that any two neighboring sets meet is preconnected. -/ theorem IsPreconnected.biUnion_of_chain {s : Ξ² β†’ Set Ξ±} {t : Set Ξ²} (ht : OrdConnected t) (H : βˆ€ n ∈ t, IsPreconnected (s n)) (K : βˆ€ n : Ξ², n ∈ t β†’ succ n ∈ t β†’ (s n ∩ s (succ n)).Nonempty) : IsPreconnected (⋃ n ∈ t, s n) := by have h1 : βˆ€ {i j k : Ξ²}, i ∈ t β†’ j ∈ t β†’ k ∈ Ico i j β†’ k ∈ t := fun hi hj hk => ht.out hi hj (Ico_subset_Icc_self hk) have h2 : βˆ€ {i j k : Ξ²}, i ∈ t β†’ j ∈ t β†’ k ∈ Ico i j β†’ succ k ∈ t := fun hi hj hk => ht.out hi hj ⟨hk.1.trans <| le_succ _, succ_le_of_lt hk.2⟩ have h3 : βˆ€ {i j k : Ξ²}, i ∈ t β†’ j ∈ t β†’ k ∈ Ico i j β†’ (s k ∩ s (succ k)).Nonempty := fun hi hj hk => K _ (h1 hi hj hk) (h2 hi hj hk) refine IsPreconnected.biUnion_of_reflTransGen H fun i hi j hj => ?_ exact reflTransGen_of_succ _ (fun k hk => ⟨h3 hi hj hk, h1 hi hj hk⟩) fun k hk => ⟨by rw [inter_comm]; exact h3 hj hi hk, h2 hj hi hk⟩ /-- The iUnion of connected sets indexed by a subset of a type with an archimedean successor (like `β„•` or `β„€`) such that any two neighboring sets meet is preconnected. -/ theorem IsConnected.biUnion_of_chain {s : Ξ² β†’ Set Ξ±} {t : Set Ξ²} (hnt : t.Nonempty) (ht : OrdConnected t) (H : βˆ€ n ∈ t, IsConnected (s n)) (K : βˆ€ n : Ξ², n ∈ t β†’ succ n ∈ t β†’ (s n ∩ s (succ n)).Nonempty) : IsConnected (⋃ n ∈ t, s n) := ⟨nonempty_biUnion.2 <| ⟨hnt.some, hnt.some_mem, (H _ hnt.some_mem).nonempty⟩, IsPreconnected.biUnion_of_chain ht (fun i hi => (H i hi).isPreconnected) K⟩ end SuccOrder /-- Theorem of bark and tree: if a set is within a preconnected set and its closure, then it is preconnected as well. See also `IsConnected.subset_closure`. -/ protected theorem IsPreconnected.subset_closure {s : Set Ξ±} {t : Set Ξ±} (H : IsPreconnected s) (Kst : s βŠ† t) (Ktcs : t βŠ† closure s) : IsPreconnected t := fun u v hu hv htuv ⟨_y, hyt, hyu⟩ ⟨_z, hzt, hzv⟩ => let ⟨p, hpu, hps⟩ := mem_closure_iff.1 (Ktcs hyt) u hu hyu let ⟨q, hqv, hqs⟩ := mem_closure_iff.1 (Ktcs hzt) v hv hzv let ⟨r, hrs, hruv⟩ := H u v hu hv (Subset.trans Kst htuv) ⟨p, hps, hpu⟩ ⟨q, hqs, hqv⟩ ⟨r, Kst hrs, hruv⟩ /-- Theorem of bark and tree: if a set is within a connected set and its closure, then it is connected as well. See also `IsPreconnected.subset_closure`. -/ protected theorem IsConnected.subset_closure {s : Set Ξ±} {t : Set Ξ±} (H : IsConnected s) (Kst : s βŠ† t) (Ktcs : t βŠ† closure s) : IsConnected t := ⟨Nonempty.mono Kst H.left, IsPreconnected.subset_closure H.right Kst Ktcs⟩ /-- The closure of a preconnected set is preconnected as well. -/ protected theorem IsPreconnected.closure {s : Set Ξ±} (H : IsPreconnected s) : IsPreconnected (closure s) := IsPreconnected.subset_closure H subset_closure Subset.rfl /-- The closure of a connected set is connected as well. -/ protected theorem IsConnected.closure {s : Set Ξ±} (H : IsConnected s) : IsConnected (closure s) := IsConnected.subset_closure H subset_closure <| Subset.rfl /-- The image of a preconnected set is preconnected as well. -/ protected theorem IsPreconnected.image [TopologicalSpace Ξ²] {s : Set Ξ±} (H : IsPreconnected s) (f : Ξ± β†’ Ξ²) (hf : ContinuousOn f s) : IsPreconnected (f '' s) := by -- Unfold/destruct definitions in hypotheses rintro u v hu hv huv ⟨_, ⟨x, xs, rfl⟩, xu⟩ ⟨_, ⟨y, ys, rfl⟩, yv⟩ rcases continuousOn_iff'.1 hf u hu with ⟨u', hu', u'_eq⟩ rcases continuousOn_iff'.1 hf v hv with ⟨v', hv', v'_eq⟩ -- Reformulate `huv : f '' s βŠ† u βˆͺ v` in terms of `u'` and `v'` replace huv : s βŠ† u' βˆͺ v' := by rw [image_subset_iff, preimage_union] at huv replace huv := subset_inter huv Subset.rfl rw [union_inter_distrib_right, u'_eq, v'_eq, ← union_inter_distrib_right] at huv exact (subset_inter_iff.1 huv).1 -- Now `s βŠ† u' βˆͺ v'`, so we can apply `β€ΉIsPreconnected sβ€Ί` obtain ⟨z, hz⟩ : (s ∩ (u' ∩ v')).Nonempty := by refine H u' v' hu' hv' huv ⟨x, ?_⟩ ⟨y, ?_⟩ <;> rw [inter_comm] exacts [u'_eq β–Έ ⟨xu, xs⟩, v'_eq β–Έ ⟨yv, ys⟩] rw [← inter_self s, inter_assoc, inter_left_comm s u', ← inter_assoc, inter_comm s, inter_comm s, ← u'_eq, ← v'_eq] at hz exact ⟨f z, ⟨z, hz.1.2, rfl⟩, hz.1.1, hz.2.1⟩ /-- The image of a connected set is connected as well. -/ protected theorem IsConnected.image [TopologicalSpace Ξ²] {s : Set Ξ±} (H : IsConnected s) (f : Ξ± β†’ Ξ²) (hf : ContinuousOn f s) : IsConnected (f '' s) := ⟨image_nonempty.mpr H.nonempty, H.isPreconnected.image f hf⟩ theorem isPreconnected_closed_iff {s : Set Ξ±} : IsPreconnected s ↔ βˆ€ t t', IsClosed t β†’ IsClosed t' β†’ s βŠ† t βˆͺ t' β†’ (s ∩ t).Nonempty β†’ (s ∩ t').Nonempty β†’ (s ∩ (t ∩ t')).Nonempty := ⟨by rintro h t t' ht ht' htt' ⟨x, xs, xt⟩ ⟨y, ys, yt'⟩ rw [← not_disjoint_iff_nonempty_inter, ← subset_compl_iff_disjoint_right, compl_inter] intro h' have xt' : x βˆ‰ t' := (h' xs).resolve_left (absurd xt) have yt : y βˆ‰ t := (h' ys).resolve_right (absurd yt') have := h _ _ ht.isOpen_compl ht'.isOpen_compl h' ⟨y, ys, yt⟩ ⟨x, xs, xt'⟩ rw [← compl_union] at this exact this.ne_empty htt'.disjoint_compl_right.inter_eq, by rintro h u v hu hv huv ⟨x, xs, xu⟩ ⟨y, ys, yv⟩ rw [← not_disjoint_iff_nonempty_inter, ← subset_compl_iff_disjoint_right, compl_inter] intro h' have xv : x βˆ‰ v := (h' xs).elim (absurd xu) id have yu : y βˆ‰ u := (h' ys).elim id (absurd yv) have := h _ _ hu.isClosed_compl hv.isClosed_compl h' ⟨y, ys, yu⟩ ⟨x, xs, xv⟩ rw [← compl_union] at this exact this.ne_empty huv.disjoint_compl_right.inter_eq⟩ theorem Topology.IsInducing.isPreconnected_image [TopologicalSpace Ξ²] {s : Set Ξ±} {f : Ξ± β†’ Ξ²} (hf : IsInducing f) : IsPreconnected (f '' s) ↔ IsPreconnected s := by refine ⟨fun h => ?_, fun h => h.image _ hf.continuous.continuousOn⟩ rintro u v hu' hv' huv ⟨x, hxs, hxu⟩ ⟨y, hys, hyv⟩ rcases hf.isOpen_iff.1 hu' with ⟨u, hu, rfl⟩ rcases hf.isOpen_iff.1 hv' with ⟨v, hv, rfl⟩ replace huv : f '' s βŠ† u βˆͺ v := by rwa [image_subset_iff] rcases h u v hu hv huv ⟨f x, mem_image_of_mem _ hxs, hxu⟩ ⟨f y, mem_image_of_mem _ hys, hyv⟩ with ⟨_, ⟨z, hzs, rfl⟩, hzuv⟩ exact ⟨z, hzs, hzuv⟩ @[deprecated (since := "2024-10-28")] alias Inducing.isPreconnected_image := IsInducing.isPreconnected_image /- TODO: The following lemmas about connection of preimages hold more generally for strict maps (the quotient and subspace topologies of the image agree) whose fibers are preconnected. -/ theorem IsPreconnected.preimage_of_isOpenMap [TopologicalSpace Ξ²] {f : Ξ± β†’ Ξ²} {s : Set Ξ²} (hs : IsPreconnected s) (hinj : Function.Injective f) (hf : IsOpenMap f) (hsf : s βŠ† range f) : IsPreconnected (f ⁻¹' s) := fun u v hu hv hsuv hsu hsv => by replace hsf : f '' (f ⁻¹' s) = s := image_preimage_eq_of_subset hsf obtain ⟨_, has, ⟨a, hau, rfl⟩, hav⟩ : (s ∩ (f '' u ∩ f '' v)).Nonempty := by refine hs (f '' u) (f '' v) (hf u hu) (hf v hv) ?_ ?_ ?_ Β· simpa only [hsf, image_union] using image_subset f hsuv Β· simpa only [image_preimage_inter] using hsu.image f Β· simpa only [image_preimage_inter] using hsv.image f Β· exact ⟨a, has, hau, hinj.mem_set_image.1 hav⟩ theorem IsPreconnected.preimage_of_isClosedMap [TopologicalSpace Ξ²] {s : Set Ξ²} (hs : IsPreconnected s) {f : Ξ± β†’ Ξ²} (hinj : Function.Injective f) (hf : IsClosedMap f) (hsf : s βŠ† range f) : IsPreconnected (f ⁻¹' s) := isPreconnected_closed_iff.2 fun u v hu hv hsuv hsu hsv => by replace hsf : f '' (f ⁻¹' s) = s := image_preimage_eq_of_subset hsf obtain ⟨_, has, ⟨a, hau, rfl⟩, hav⟩ : (s ∩ (f '' u ∩ f '' v)).Nonempty := by refine isPreconnected_closed_iff.1 hs (f '' u) (f '' v) (hf u hu) (hf v hv) ?_ ?_ ?_ Β· simpa only [hsf, image_union] using image_subset f hsuv Β· simpa only [image_preimage_inter] using hsu.image f Β· simpa only [image_preimage_inter] using hsv.image f Β· exact ⟨a, has, hau, hinj.mem_set_image.1 hav⟩ theorem IsConnected.preimage_of_isOpenMap [TopologicalSpace Ξ²] {s : Set Ξ²} (hs : IsConnected s) {f : Ξ± β†’ Ξ²} (hinj : Function.Injective f) (hf : IsOpenMap f) (hsf : s βŠ† range f) : IsConnected (f ⁻¹' s) := ⟨hs.nonempty.preimage' hsf, hs.isPreconnected.preimage_of_isOpenMap hinj hf hsf⟩ theorem IsConnected.preimage_of_isClosedMap [TopologicalSpace Ξ²] {s : Set Ξ²} (hs : IsConnected s) {f : Ξ± β†’ Ξ²} (hinj : Function.Injective f) (hf : IsClosedMap f) (hsf : s βŠ† range f) : IsConnected (f ⁻¹' s) := ⟨hs.nonempty.preimage' hsf, hs.isPreconnected.preimage_of_isClosedMap hinj hf hsf⟩ theorem IsPreconnected.subset_or_subset (hu : IsOpen u) (hv : IsOpen v) (huv : Disjoint u v) (hsuv : s βŠ† u βˆͺ v) (hs : IsPreconnected s) : s βŠ† u ∨ s βŠ† v := by specialize hs u v hu hv hsuv obtain hsu | hsu := (s ∩ u).eq_empty_or_nonempty Β· exact Or.inr ((Set.disjoint_iff_inter_eq_empty.2 hsu).subset_right_of_subset_union hsuv) Β· replace hs := mt (hs hsu) simp_rw [Set.not_nonempty_iff_eq_empty, ← Set.disjoint_iff_inter_eq_empty, disjoint_iff_inter_eq_empty.1 huv] at hs exact Or.inl ((hs s.disjoint_empty).subset_left_of_subset_union hsuv) theorem IsPreconnected.subset_left_of_subset_union (hu : IsOpen u) (hv : IsOpen v) (huv : Disjoint u v) (hsuv : s βŠ† u βˆͺ v) (hsu : (s ∩ u).Nonempty) (hs : IsPreconnected s) : s βŠ† u := Disjoint.subset_left_of_subset_union hsuv (by by_contra hsv rw [not_disjoint_iff_nonempty_inter] at hsv obtain ⟨x, _, hx⟩ := hs u v hu hv hsuv hsu hsv exact Set.disjoint_iff.1 huv hx) theorem IsPreconnected.subset_right_of_subset_union (hu : IsOpen u) (hv : IsOpen v) (huv : Disjoint u v) (hsuv : s βŠ† u βˆͺ v) (hsv : (s ∩ v).Nonempty) (hs : IsPreconnected s) : s βŠ† v := hs.subset_left_of_subset_union hv hu huv.symm (union_comm u v β–Έ hsuv) hsv /-- If a preconnected set `s` intersects an open set `u`, and limit points of `u` inside `s` are contained in `u`, then the whole set `s` is contained in `u`. -/ theorem IsPreconnected.subset_of_closure_inter_subset (hs : IsPreconnected s) (hu : IsOpen u) (h'u : (s ∩ u).Nonempty) (h : closure u ∩ s βŠ† u) : s βŠ† u := by have A : s βŠ† u βˆͺ (closure u)ᢜ := by intro x hx by_cases xu : x ∈ u Β· exact Or.inl xu Β· right intro h'x exact xu (h (mem_inter h'x hx)) apply hs.subset_left_of_subset_union hu isClosed_closure.isOpen_compl _ A h'u exact disjoint_compl_right.mono_right (compl_subset_compl.2 subset_closure) theorem IsPreconnected.prod [TopologicalSpace Ξ²] {s : Set Ξ±} {t : Set Ξ²} (hs : IsPreconnected s)
(ht : IsPreconnected t) : IsPreconnected (s Γ—Λ’ t) := by apply isPreconnected_of_forall_pair rintro ⟨a₁, bβ‚βŸ© ⟨ha₁, hbβ‚βŸ© ⟨aβ‚‚, bβ‚‚βŸ© ⟨haβ‚‚, hbβ‚‚βŸ© refine ⟨Prod.mk a₁ '' t βˆͺ flip Prod.mk bβ‚‚ '' s, ?_, .inl ⟨b₁, hb₁, rfl⟩, .inr ⟨aβ‚‚, haβ‚‚, rfl⟩, ?_⟩ Β· rintro _ (⟨y, hy, rfl⟩ | ⟨x, hx, rfl⟩) exacts [⟨ha₁, hy⟩, ⟨hx, hbβ‚‚βŸ©] Β· exact (ht.image _ (by fun_prop)).union (a₁, bβ‚‚) ⟨bβ‚‚, hbβ‚‚, rfl⟩ ⟨a₁, ha₁, rfl⟩ (hs.image _ (Continuous.prodMk_left _).continuousOn)
Mathlib/Topology/Connected/Basic.lean
413
421
/- 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, Yury Kudryashov -/ import Mathlib.Data.ENNReal.Operations /-! # Results about division in extended non-negative reals This file establishes basic properties related to the inversion and division operations on `ℝβ‰₯0∞`. For instance, as a consequence of being a `DivInvOneMonoid`, `ℝβ‰₯0∞` inherits a power operation with integer exponent. ## Main results A few order isomorphisms are worthy of mention: - `OrderIso.invENNReal : ℝβ‰₯0∞ ≃o ℝβ‰₯0βˆžα΅’α΅ˆ`: The map `x ↦ x⁻¹` as an order isomorphism to the dual. - `orderIsoIicOneBirational : ℝβ‰₯0∞ ≃o Iic (1 : ℝβ‰₯0∞)`: The birational order isomorphism between `ℝβ‰₯0∞` and the unit interval `Set.Iic (1 : ℝβ‰₯0∞)` given by `x ↦ (x⁻¹ + 1)⁻¹` with inverse `x ↦ (x⁻¹ - 1)⁻¹` - `orderIsoIicCoe (a : ℝβ‰₯0) : Iic (a : ℝβ‰₯0∞) ≃o Iic a`: Order isomorphism between an initial interval in `ℝβ‰₯0∞` and an initial interval in `ℝβ‰₯0` given by the identity map. - `orderIsoUnitIntervalBirational : ℝβ‰₯0∞ ≃o Icc (0 : ℝ) 1`: An order isomorphism between the extended nonnegative real numbers and the unit interval. This is `orderIsoIicOneBirational` composed with the identity order isomorphism between `Iic (1 : ℝβ‰₯0∞)` and `Icc (0 : ℝ) 1`. -/ assert_not_exists Finset open Set NNReal namespace ENNReal noncomputable section Inv variable {a b c d : ℝβ‰₯0∞} {r p q : ℝβ‰₯0} protected theorem div_eq_inv_mul : a / b = b⁻¹ * a := by rw [div_eq_mul_inv, mul_comm] @[simp] theorem inv_zero : (0 : ℝβ‰₯0∞)⁻¹ = ∞ := show sInf { b : ℝβ‰₯0∞ | 1 ≀ 0 * b } = ∞ by simp @[simp] theorem inv_top : ∞⁻¹ = 0 := bot_unique <| le_of_forall_gt_imp_ge_of_dense fun a (h : 0 < a) => sInf_le <| by simp [*, h.ne', top_mul] theorem coe_inv_le : (↑r⁻¹ : ℝβ‰₯0∞) ≀ (↑r)⁻¹ := le_sInf fun b (hb : 1 ≀ ↑r * b) => coe_le_iff.2 <| by rintro b rfl apply NNReal.inv_le_of_le_mul rwa [← coe_mul, ← coe_one, coe_le_coe] at hb @[simp, norm_cast] theorem coe_inv (hr : r β‰  0) : (↑r⁻¹ : ℝβ‰₯0∞) = (↑r)⁻¹ := coe_inv_le.antisymm <| sInf_le <| mem_setOf.2 <| by rw [← coe_mul, mul_inv_cancelβ‚€ hr, coe_one] @[norm_cast] theorem coe_inv_two : ((2⁻¹ : ℝβ‰₯0) : ℝβ‰₯0∞) = 2⁻¹ := by rw [coe_inv _root_.two_ne_zero, coe_two] @[simp, norm_cast] theorem coe_div (hr : r β‰  0) : (↑(p / r) : ℝβ‰₯0∞) = p / r := by rw [div_eq_mul_inv, div_eq_mul_inv, coe_mul, coe_inv hr] lemma coe_div_le : ↑(p / r) ≀ (p / r : ℝβ‰₯0∞) := by simpa only [div_eq_mul_inv, coe_mul] using mul_le_mul_left' coe_inv_le _ theorem div_zero (h : a β‰  0) : a / 0 = ∞ := by simp [div_eq_mul_inv, h] instance : DivInvOneMonoid ℝβ‰₯0∞ := { inferInstanceAs (DivInvMonoid ℝβ‰₯0∞) with inv_one := by simpa only [coe_inv one_ne_zero, coe_one] using coe_inj.2 inv_one } protected theorem inv_pow : βˆ€ {a : ℝβ‰₯0∞} {n : β„•}, (a ^ n)⁻¹ = a⁻¹ ^ n | _, 0 => by simp only [pow_zero, inv_one] | ⊀, n + 1 => by simp [top_pow] | (a : ℝβ‰₯0), n + 1 => by rcases eq_or_ne a 0 with (rfl | ha) Β· simp [top_pow] Β· have := pow_ne_zero (n + 1) ha norm_cast rw [inv_pow] protected theorem mul_inv_cancel (h0 : a β‰  0) (ht : a β‰  ∞) : a * a⁻¹ = 1 := by lift a to ℝβ‰₯0 using ht norm_cast at h0; norm_cast exact mul_inv_cancelβ‚€ h0 protected theorem inv_mul_cancel (h0 : a β‰  0) (ht : a β‰  ∞) : a⁻¹ * a = 1 := mul_comm a a⁻¹ β–Έ ENNReal.mul_inv_cancel h0 ht /-- See `ENNReal.inv_mul_cancel_left` for a simpler version assuming `a β‰  0`, `a β‰  ∞`. -/ protected lemma inv_mul_cancel_left' (haβ‚€ : a = 0 β†’ b = 0) (ha : a = ∞ β†’ b = 0) : a⁻¹ * (a * b) = b := by obtain rfl | haβ‚€ := eq_or_ne a 0 Β· simp_all obtain rfl | ha := eq_or_ne a ⊀ Β· simp_all Β· simp [← mul_assoc, ENNReal.inv_mul_cancel, *] /-- See `ENNReal.inv_mul_cancel_left'` for a stronger version. -/ protected lemma inv_mul_cancel_left (haβ‚€ : a β‰  0) (ha : a β‰  ∞) : a⁻¹ * (a * b) = b := ENNReal.inv_mul_cancel_left' (by simp [haβ‚€]) (by simp [ha]) /-- See `ENNReal.mul_inv_cancel_left` for a simpler version assuming `a β‰  0`, `a β‰  ∞`. -/ protected lemma mul_inv_cancel_left' (haβ‚€ : a = 0 β†’ b = 0) (ha : a = ∞ β†’ b = 0) : a * (a⁻¹ * b) = b := by obtain rfl | haβ‚€ := eq_or_ne a 0 Β· simp_all obtain rfl | ha := eq_or_ne a ⊀ Β· simp_all Β· simp [← mul_assoc, ENNReal.mul_inv_cancel, *] /-- See `ENNReal.mul_inv_cancel_left'` for a stronger version. -/ protected lemma mul_inv_cancel_left (haβ‚€ : a β‰  0) (ha : a β‰  ∞) : a * (a⁻¹ * b) = b := ENNReal.mul_inv_cancel_left' (by simp [haβ‚€]) (by simp [ha]) /-- See `ENNReal.mul_inv_cancel_right` for a simpler version assuming `b β‰  0`, `b β‰  ∞`. -/ protected lemma mul_inv_cancel_right' (hbβ‚€ : b = 0 β†’ a = 0) (hb : b = ∞ β†’ a = 0) : a * b * b⁻¹ = a := by obtain rfl | hbβ‚€ := eq_or_ne b 0 Β· simp_all obtain rfl | hb := eq_or_ne b ⊀ Β· simp_all Β· simp [mul_assoc, ENNReal.mul_inv_cancel, *] /-- See `ENNReal.mul_inv_cancel_right'` for a stronger version. -/ protected lemma mul_inv_cancel_right (hbβ‚€ : b β‰  0) (hb : b β‰  ∞) : a * b * b⁻¹ = a := ENNReal.mul_inv_cancel_right' (by simp [hbβ‚€]) (by simp [hb]) /-- See `ENNReal.inv_mul_cancel_right` for a simpler version assuming `b β‰  0`, `b β‰  ∞`. -/ protected lemma inv_mul_cancel_right' (hbβ‚€ : b = 0 β†’ a = 0) (hb : b = ∞ β†’ a = 0) : a * b⁻¹ * b = a := by obtain rfl | hbβ‚€ := eq_or_ne b 0 Β· simp_all obtain rfl | hb := eq_or_ne b ⊀ Β· simp_all Β· simp [mul_assoc, ENNReal.inv_mul_cancel, *] /-- See `ENNReal.inv_mul_cancel_right'` for a stronger version. -/ protected lemma inv_mul_cancel_right (hbβ‚€ : b β‰  0) (hb : b β‰  ∞) : a * b⁻¹ * b = a := ENNReal.inv_mul_cancel_right' (by simp [hbβ‚€]) (by simp [hb]) /-- See `ENNReal.mul_div_cancel_right` for a simpler version assuming `b β‰  0`, `b β‰  ∞`. -/ protected lemma mul_div_cancel_right' (hbβ‚€ : b = 0 β†’ a = 0) (hb : b = ∞ β†’ a = 0) : a * b / b = a := ENNReal.mul_inv_cancel_right' hbβ‚€ hb /-- See `ENNReal.mul_div_cancel_right'` for a stronger version. -/ protected lemma mul_div_cancel_right (hbβ‚€ : b β‰  0) (hb : b β‰  ∞) : a * b / b = a := ENNReal.mul_div_cancel_right' (by simp [hbβ‚€]) (by simp [hb]) /-- See `ENNReal.div_mul_cancel` for a simpler version assuming `a β‰  0`, `a β‰  ∞`. -/ protected lemma div_mul_cancel' (haβ‚€ : a = 0 β†’ b = 0) (ha : a = ∞ β†’ b = 0) : b / a * a = b := ENNReal.inv_mul_cancel_right' haβ‚€ ha /-- See `ENNReal.div_mul_cancel'` for a stronger version. -/ protected lemma div_mul_cancel (haβ‚€ : a β‰  0) (ha : a β‰  ∞) : b / a * a = b := ENNReal.div_mul_cancel' (by simp [haβ‚€]) (by simp [ha]) /-- See `ENNReal.mul_div_cancel` for a simpler version assuming `a β‰  0`, `a β‰  ∞`. -/ protected lemma mul_div_cancel' (haβ‚€ : a = 0 β†’ b = 0) (ha : a = ∞ β†’ b = 0) : a * (b / a) = b := by rw [mul_comm, ENNReal.div_mul_cancel' haβ‚€ ha] /-- See `ENNReal.mul_div_cancel'` for a stronger version. -/ protected lemma mul_div_cancel (haβ‚€ : a β‰  0) (ha : a β‰  ∞) : a * (b / a) = b := ENNReal.mul_div_cancel' (by simp [haβ‚€]) (by simp [ha]) protected theorem mul_comm_div : a / b * c = a * (c / b) := by simp only [div_eq_mul_inv, mul_left_comm, mul_comm, mul_assoc] protected theorem mul_div_right_comm : a * b / c = a / c * b := by simp only [div_eq_mul_inv, mul_right_comm] instance : InvolutiveInv ℝβ‰₯0∞ where inv_inv a := by by_cases a = 0 <;> cases a <;> simp_all [none_eq_top, some_eq_coe, -coe_inv, (coe_inv _).symm] @[simp] protected lemma inv_eq_one : a⁻¹ = 1 ↔ a = 1 := by rw [← inv_inj, inv_inv, inv_one] @[simp] theorem inv_eq_top : a⁻¹ = ∞ ↔ a = 0 := inv_zero β–Έ inv_inj theorem inv_ne_top : a⁻¹ β‰  ∞ ↔ a β‰  0 := by simp @[aesop (rule_sets := [finiteness]) safe apply] protected alias ⟨_, Finiteness.inv_ne_top⟩ := ENNReal.inv_ne_top @[simp] theorem inv_lt_top {x : ℝβ‰₯0∞} : x⁻¹ < ∞ ↔ 0 < x := by simp only [lt_top_iff_ne_top, inv_ne_top, pos_iff_ne_zero] theorem div_lt_top {x y : ℝβ‰₯0∞} (h1 : x β‰  ∞) (h2 : y β‰  0) : x / y < ∞ := mul_lt_top h1.lt_top (inv_ne_top.mpr h2).lt_top @[simp] protected theorem inv_eq_zero : a⁻¹ = 0 ↔ a = ∞ := inv_top β–Έ inv_inj protected theorem inv_ne_zero : a⁻¹ β‰  0 ↔ a β‰  ∞ := by simp protected theorem div_pos (ha : a β‰  0) (hb : b β‰  ∞) : 0 < a / b := ENNReal.mul_pos ha <| ENNReal.inv_ne_zero.2 hb protected theorem inv_mul_le_iff {x y z : ℝβ‰₯0∞} (h1 : x β‰  0) (h2 : x β‰  ∞) : x⁻¹ * y ≀ z ↔ y ≀ x * z := by rw [← mul_le_mul_left h1 h2, ← mul_assoc, ENNReal.mul_inv_cancel h1 h2, one_mul] protected theorem mul_inv_le_iff {x y z : ℝβ‰₯0∞} (h1 : y β‰  0) (h2 : y β‰  ∞) : x * y⁻¹ ≀ z ↔ x ≀ z * y := by rw [mul_comm, ENNReal.inv_mul_le_iff h1 h2, mul_comm] protected theorem div_le_iff {x y z : ℝβ‰₯0∞} (h1 : y β‰  0) (h2 : y β‰  ∞) : x / y ≀ z ↔ x ≀ z * y := by rw [div_eq_mul_inv, ENNReal.mul_inv_le_iff h1 h2] protected theorem div_le_iff' {x y z : ℝβ‰₯0∞} (h1 : y β‰  0) (h2 : y β‰  ∞) : x / y ≀ z ↔ x ≀ y * z := by rw [mul_comm, ENNReal.div_le_iff h1 h2] protected theorem mul_inv {a b : ℝβ‰₯0∞} (ha : a β‰  0 ∨ b β‰  ∞) (hb : a β‰  ∞ ∨ b β‰  0) : (a * b)⁻¹ = a⁻¹ * b⁻¹ := by induction' b with b Β· replace ha : a β‰  0 := ha.neg_resolve_right rfl simp [ha] induction' a with a Β· replace hb : b β‰  0 := coe_ne_zero.1 (hb.neg_resolve_left rfl) simp [hb] by_cases h'a : a = 0 Β· simp only [h'a, top_mul, ENNReal.inv_zero, ENNReal.coe_ne_top, zero_mul, Ne, not_false_iff, ENNReal.coe_zero, ENNReal.inv_eq_zero] by_cases h'b : b = 0 Β· simp only [h'b, ENNReal.inv_zero, ENNReal.coe_ne_top, mul_top, Ne, not_false_iff, mul_zero, ENNReal.coe_zero, ENNReal.inv_eq_zero] rw [← ENNReal.coe_mul, ← ENNReal.coe_inv, ← ENNReal.coe_inv h'a, ← ENNReal.coe_inv h'b, ← ENNReal.coe_mul, mul_inv_rev, mul_comm] simp [h'a, h'b] protected theorem inv_div {a b : ℝβ‰₯0∞} (htop : b β‰  ∞ ∨ a β‰  ∞) (hzero : b β‰  0 ∨ a β‰  0) : (a / b)⁻¹ = b / a := by rw [← ENNReal.inv_ne_zero] at htop rw [← ENNReal.inv_ne_top] at hzero rw [ENNReal.div_eq_inv_mul, ENNReal.div_eq_inv_mul, ENNReal.mul_inv htop hzero, mul_comm, inv_inv] protected theorem mul_div_mul_left (a b : ℝβ‰₯0∞) (hc : c β‰  0) (hc' : c β‰  ⊀) : c * a / (c * b) = a / b := by rw [div_eq_mul_inv, div_eq_mul_inv, ENNReal.mul_inv (Or.inl hc) (Or.inl hc'), mul_mul_mul_comm, ENNReal.mul_inv_cancel hc hc', one_mul] protected theorem mul_div_mul_right (a b : ℝβ‰₯0∞) (hc : c β‰  0) (hc' : c β‰  ⊀) : a * c / (b * c) = a / b := by rw [div_eq_mul_inv, div_eq_mul_inv, ENNReal.mul_inv (Or.inr hc') (Or.inr hc), mul_mul_mul_comm, ENNReal.mul_inv_cancel hc hc', mul_one] protected theorem sub_div (h : 0 < b β†’ b < a β†’ c β‰  0) : (a - b) / c = a / c - b / c := by simp_rw [div_eq_mul_inv] exact ENNReal.sub_mul (by simpa using h) @[simp] protected theorem inv_pos : 0 < a⁻¹ ↔ a β‰  ∞ := pos_iff_ne_zero.trans ENNReal.inv_ne_zero theorem inv_strictAnti : StrictAnti (Inv.inv : ℝβ‰₯0∞ β†’ ℝβ‰₯0∞) := by intro a b h lift a to ℝβ‰₯0 using h.ne_top induction b; Β· simp rw [coe_lt_coe] at h rcases eq_or_ne a 0 with (rfl | ha); Β· simp [h] rw [← coe_inv h.ne_bot, ← coe_inv ha, coe_lt_coe] exact NNReal.inv_lt_inv ha h @[simp] protected theorem inv_lt_inv : a⁻¹ < b⁻¹ ↔ b < a := inv_strictAnti.lt_iff_lt theorem inv_lt_iff_inv_lt : a⁻¹ < b ↔ b⁻¹ < a := by simpa only [inv_inv] using @ENNReal.inv_lt_inv a b⁻¹ theorem lt_inv_iff_lt_inv : a < b⁻¹ ↔ b < a⁻¹ := by simpa only [inv_inv] using @ENNReal.inv_lt_inv a⁻¹ b @[simp] protected theorem inv_le_inv : a⁻¹ ≀ b⁻¹ ↔ b ≀ a := inv_strictAnti.le_iff_le theorem inv_le_iff_inv_le : a⁻¹ ≀ b ↔ b⁻¹ ≀ a := by simpa only [inv_inv] using @ENNReal.inv_le_inv a b⁻¹ theorem le_inv_iff_le_inv : a ≀ b⁻¹ ↔ b ≀ a⁻¹ := by simpa only [inv_inv] using @ENNReal.inv_le_inv a⁻¹ b @[gcongr] protected theorem inv_le_inv' (h : a ≀ b) : b⁻¹ ≀ a⁻¹ := ENNReal.inv_strictAnti.antitone h @[gcongr] protected theorem inv_lt_inv' (h : a < b) : b⁻¹ < a⁻¹ := ENNReal.inv_strictAnti h @[simp] protected theorem inv_le_one : a⁻¹ ≀ 1 ↔ 1 ≀ a := by rw [inv_le_iff_inv_le, inv_one] protected theorem one_le_inv : 1 ≀ a⁻¹ ↔ a ≀ 1 := by rw [le_inv_iff_le_inv, inv_one] @[simp] protected theorem inv_lt_one : a⁻¹ < 1 ↔ 1 < a := by rw [inv_lt_iff_inv_lt, inv_one] @[simp] protected theorem one_lt_inv : 1 < a⁻¹ ↔ a < 1 := by rw [lt_inv_iff_lt_inv, inv_one] /-- The inverse map `fun x ↦ x⁻¹` is an order isomorphism between `ℝβ‰₯0∞` and its `OrderDual` -/ @[simps! apply] def _root_.OrderIso.invENNReal : ℝβ‰₯0∞ ≃o ℝβ‰₯0βˆžα΅’α΅ˆ where map_rel_iff' := ENNReal.inv_le_inv toEquiv := (Equiv.inv ℝβ‰₯0∞).trans OrderDual.toDual @[simp] theorem _root_.OrderIso.invENNReal_symm_apply (a : ℝβ‰₯0βˆžα΅’α΅ˆ) : OrderIso.invENNReal.symm a = (OrderDual.ofDual a)⁻¹ := rfl @[simp] theorem div_top : a / ∞ = 0 := by rw [div_eq_mul_inv, inv_top, mul_zero] theorem top_div : ∞ / a = if a = ∞ then 0 else ∞ := by simp [div_eq_mul_inv, top_mul'] theorem top_div_of_ne_top (h : a β‰  ∞) : ∞ / a = ∞ := by simp [top_div, h] @[simp] theorem top_div_coe : ∞ / p = ∞ := top_div_of_ne_top coe_ne_top theorem top_div_of_lt_top (h : a < ∞) : ∞ / a = ∞ := top_div_of_ne_top h.ne @[simp] protected theorem zero_div : 0 / a = 0 := zero_mul a⁻¹ theorem div_eq_top : a / b = ∞ ↔ a β‰  0 ∧ b = 0 ∨ a = ∞ ∧ b β‰  ∞ := by simp [div_eq_mul_inv, ENNReal.mul_eq_top] protected theorem le_div_iff_mul_le (h0 : b β‰  0 ∨ c β‰  0) (ht : b β‰  ∞ ∨ c β‰  ∞) : a ≀ c / b ↔ a * b ≀ c := by induction' b with b Β· lift c to ℝβ‰₯0 using ht.neg_resolve_left rfl rw [div_top, nonpos_iff_eq_zero] rcases eq_or_ne a 0 with (rfl | ha) <;> simp [*] rcases eq_or_ne b 0 with (rfl | hb) Β· have hc : c β‰  0 := h0.neg_resolve_left rfl simp [div_zero hc] Β· rw [← coe_ne_zero] at hb rw [← ENNReal.mul_le_mul_right hb coe_ne_top, ENNReal.div_mul_cancel hb coe_ne_top] protected theorem div_le_iff_le_mul (hb0 : b β‰  0 ∨ c β‰  ∞) (hbt : b β‰  ∞ ∨ c β‰  0) : a / b ≀ c ↔ a ≀ c * b := by suffices a * b⁻¹ ≀ c ↔ a ≀ c / b⁻¹ by simpa [div_eq_mul_inv] refine (ENNReal.le_div_iff_mul_le ?_ ?_).symm <;> simpa protected theorem lt_div_iff_mul_lt (hb0 : b β‰  0 ∨ c β‰  ∞) (hbt : b β‰  ∞ ∨ c β‰  0) : c < a / b ↔ c * b < a := lt_iff_lt_of_le_iff_le (ENNReal.div_le_iff_le_mul hb0 hbt) theorem div_le_of_le_mul (h : a ≀ b * c) : a / c ≀ b := by by_cases h0 : c = 0 Β· have : a = 0 := by simpa [h0] using h simp [*] by_cases hinf : c = ∞; Β· simp [hinf] exact (ENNReal.div_le_iff_le_mul (Or.inl h0) (Or.inl hinf)).2 h theorem div_le_of_le_mul' (h : a ≀ b * c) : a / b ≀ c := div_le_of_le_mul <| mul_comm b c β–Έ h @[simp] protected theorem div_self_le_one : a / a ≀ 1 := div_le_of_le_mul <| by rw [one_mul] @[simp] protected lemma mul_inv_le_one (a : ℝβ‰₯0∞) : a * a⁻¹ ≀ 1 := ENNReal.div_self_le_one @[simp] protected lemma inv_mul_le_one (a : ℝβ‰₯0∞) : a⁻¹ * a ≀ 1 := by simp [mul_comm] @[simp] lemma mul_inv_ne_top (a : ℝβ‰₯0∞) : a * a⁻¹ β‰  ⊀ := ne_top_of_le_ne_top one_ne_top a.mul_inv_le_one @[simp] lemma inv_mul_ne_top (a : ℝβ‰₯0∞) : a⁻¹ * a β‰  ⊀ := by simp [mul_comm] theorem mul_le_of_le_div (h : a ≀ b / c) : a * c ≀ b := by rw [← inv_inv c] exact div_le_of_le_mul h theorem mul_le_of_le_div' (h : a ≀ b / c) : c * a ≀ b := mul_comm a c β–Έ mul_le_of_le_div h protected theorem div_lt_iff (h0 : b β‰  0 ∨ c β‰  0) (ht : b β‰  ∞ ∨ c β‰  ∞) : c / b < a ↔ c < a * b := lt_iff_lt_of_le_iff_le <| ENNReal.le_div_iff_mul_le h0 ht theorem mul_lt_of_lt_div (h : a < b / c) : a * c < b := by contrapose! h exact ENNReal.div_le_of_le_mul h theorem mul_lt_of_lt_div' (h : a < b / c) : c * a < b := mul_comm a c β–Έ mul_lt_of_lt_div h theorem div_lt_of_lt_mul (h : a < b * c) : a / c < b := mul_lt_of_lt_div <| by rwa [div_eq_mul_inv, inv_inv] theorem div_lt_of_lt_mul' (h : a < b * c) : a / b < c := div_lt_of_lt_mul <| by rwa [mul_comm] theorem inv_le_iff_le_mul (h₁ : b = ∞ β†’ a β‰  0) (hβ‚‚ : a = ∞ β†’ b β‰  0) : a⁻¹ ≀ b ↔ 1 ≀ a * b := by rw [← one_div, ENNReal.div_le_iff_le_mul, mul_comm] exacts [or_not_of_imp h₁, not_or_of_imp hβ‚‚] @[simp 900] theorem le_inv_iff_mul_le : a ≀ b⁻¹ ↔ a * b ≀ 1 := by rw [← one_div, ENNReal.le_div_iff_mul_le] <;> Β· right simp @[gcongr] protected theorem div_le_div (hab : a ≀ b) (hdc : d ≀ c) : a / c ≀ b / d := div_eq_mul_inv b d β–Έ div_eq_mul_inv a c β–Έ mul_le_mul' hab (ENNReal.inv_le_inv.mpr hdc) @[gcongr] protected theorem div_le_div_left (h : a ≀ b) (c : ℝβ‰₯0∞) : c / b ≀ c / a := ENNReal.div_le_div le_rfl h @[gcongr] protected theorem div_le_div_right (h : a ≀ b) (c : ℝβ‰₯0∞) : a / c ≀ b / c := ENNReal.div_le_div h le_rfl protected theorem eq_inv_of_mul_eq_one_left (h : a * b = 1) : a = b⁻¹ := by rw [← mul_one a, ← ENNReal.mul_inv_cancel (right_ne_zero_of_mul_eq_one h), ← mul_assoc, h, one_mul] rintro rfl simp [left_ne_zero_of_mul_eq_one h] at h theorem mul_le_iff_le_inv {a b r : ℝβ‰₯0∞} (hrβ‚€ : r β‰  0) (hr₁ : r β‰  ∞) : r * a ≀ b ↔ a ≀ r⁻¹ * b := by rw [← @ENNReal.mul_le_mul_left _ a _ hrβ‚€ hr₁, ← mul_assoc, ENNReal.mul_inv_cancel hrβ‚€ hr₁, one_mul] theorem le_of_forall_nnreal_lt {x y : ℝβ‰₯0∞} (h : βˆ€ r : ℝβ‰₯0, ↑r < x β†’ ↑r ≀ y) : x ≀ y := by refine le_of_forall_lt_imp_le_of_dense fun r hr => ?_ lift r to ℝβ‰₯0 using ne_top_of_lt hr exact h r hr lemma eq_of_forall_nnreal_iff {x y : ℝβ‰₯0∞} (h : βˆ€ r : ℝβ‰₯0, ↑r ≀ x ↔ ↑r ≀ y) : x = y := le_antisymm (le_of_forall_nnreal_lt fun _r hr ↦ (h _).1 hr.le) (le_of_forall_nnreal_lt fun _r hr ↦ (h _).2 hr.le) theorem le_of_forall_pos_nnreal_lt {x y : ℝβ‰₯0∞} (h : βˆ€ r : ℝβ‰₯0, 0 < r β†’ ↑r < x β†’ ↑r ≀ y) : x ≀ y := le_of_forall_nnreal_lt fun r hr => (zero_le r).eq_or_lt.elim (fun h => h β–Έ zero_le _) fun h0 => h r h0 hr theorem eq_top_of_forall_nnreal_le {x : ℝβ‰₯0∞} (h : βˆ€ r : ℝβ‰₯0, ↑r ≀ x) : x = ∞ := top_unique <| le_of_forall_nnreal_lt fun r _ => h r protected theorem add_div : (a + b) / c = a / c + b / c := right_distrib a b c⁻¹ protected theorem div_add_div_same {a b c : ℝβ‰₯0∞} : a / c + b / c = (a + b) / c := ENNReal.add_div.symm protected theorem div_self (h0 : a β‰  0) (hI : a β‰  ∞) : a / a = 1 := ENNReal.mul_inv_cancel h0 hI theorem mul_div_le : a * (b / a) ≀ b := mul_le_of_le_div' le_rfl theorem eq_div_iff (ha : a β‰  0) (ha' : a β‰  ∞) : b = c / a ↔ a * b = c := ⟨fun h => by rw [h, ENNReal.mul_div_cancel ha ha'], fun h => by rw [← h, mul_div_assoc, ENNReal.mul_div_cancel ha ha']⟩ protected theorem div_eq_div_iff (ha : a β‰  0) (ha' : a β‰  ∞) (hb : b β‰  0) (hb' : b β‰  ∞) : c / b = d / a ↔ a * c = b * d := by rw [eq_div_iff ha ha'] conv_rhs => rw [eq_comm] rw [← eq_div_iff hb hb', mul_div_assoc, eq_comm] theorem div_eq_one_iff {a b : ℝβ‰₯0∞} (hbβ‚€ : b β‰  0) (hb₁ : b β‰  ∞) : a / b = 1 ↔ a = b := ⟨fun h => by rw [← (eq_div_iff hbβ‚€ hb₁).mp h.symm, mul_one], fun h => h.symm β–Έ ENNReal.div_self hbβ‚€ hbβ‚βŸ© theorem inv_two_add_inv_two : (2 : ℝβ‰₯0∞)⁻¹ + 2⁻¹ = 1 := by rw [← two_mul, ← div_eq_mul_inv, ENNReal.div_self two_ne_zero ofNat_ne_top] theorem inv_three_add_inv_three : (3 : ℝβ‰₯0∞)⁻¹ + 3⁻¹ + 3⁻¹ = 1 := by rw [← ENNReal.mul_inv_cancel three_ne_zero ofNat_ne_top] ring @[simp] protected theorem add_halves (a : ℝβ‰₯0∞) : a / 2 + a / 2 = a := by rw [div_eq_mul_inv, ← mul_add, inv_two_add_inv_two, mul_one] @[simp] theorem add_thirds (a : ℝβ‰₯0∞) : a / 3 + a / 3 + a / 3 = a := by rw [div_eq_mul_inv, ← mul_add, ← mul_add, inv_three_add_inv_three, mul_one] @[simp] theorem div_eq_zero_iff : a / b = 0 ↔ a = 0 ∨ b = ∞ := by simp [div_eq_mul_inv] @[simp] theorem div_pos_iff : 0 < a / b ↔ a β‰  0 ∧ b β‰  ∞ := by simp [pos_iff_ne_zero, not_or] protected lemma div_ne_zero : a / b β‰  0 ↔ a β‰  0 ∧ b β‰  ∞ := by rw [← pos_iff_ne_zero, div_pos_iff] protected lemma div_mul (a : ℝβ‰₯0∞) (h0 : b β‰  0 ∨ c β‰  0) (htop : b β‰  ∞ ∨ c β‰  ∞) : a / b * c = a / (b / c) := by simp only [div_eq_mul_inv] rw [ENNReal.mul_inv, inv_inv] Β· ring Β· simpa Β· simpa protected lemma mul_div_mul_comm (hc : c β‰  0 ∨ d β‰  ∞) (hd : c β‰  ∞ ∨ d β‰  0) : a * b / (c * d) = a / c * (b / d) := by simp only [div_eq_mul_inv, ENNReal.mul_inv hc hd] ring protected theorem half_pos (h : a β‰  0) : 0 < a / 2 := ENNReal.div_pos h ofNat_ne_top protected theorem one_half_lt_one : (2⁻¹ : ℝβ‰₯0∞) < 1 := ENNReal.inv_lt_one.2 <| one_lt_two protected theorem half_lt_self (hz : a β‰  0) (ht : a β‰  ∞) : a / 2 < a := by lift a to ℝβ‰₯0 using ht rw [coe_ne_zero] at hz rw [← coe_two, ← coe_div, coe_lt_coe] exacts [NNReal.half_lt_self hz, two_ne_zero' _] protected theorem half_le_self : a / 2 ≀ a := le_add_self.trans_eq <| ENNReal.add_halves _ theorem sub_half (h : a β‰  ∞) : a - a / 2 = a / 2 := ENNReal.sub_eq_of_eq_add' h a.add_halves.symm @[simp] theorem one_sub_inv_two : (1 : ℝβ‰₯0∞) - 2⁻¹ = 2⁻¹ := by rw [← one_div, sub_half one_ne_top] private lemma exists_lt_mul_left {a b c : ℝβ‰₯0∞} (hc : c < a * b) : βˆƒ a' < a, c < a' * b := by obtain ⟨a', hc, ha'⟩ := exists_between (ENNReal.div_lt_of_lt_mul hc) exact ⟨_, ha', (ENNReal.div_lt_iff (.inl <| by rintro rfl; simp at *) (.inr <| by rintro rfl; simp at *)).1 hc⟩ private lemma exists_lt_mul_right {a b c : ℝβ‰₯0∞} (hc : c < a * b) : βˆƒ b' < b, c < a * b' := by simp_rw [mul_comm a] at hc ⊒; exact exists_lt_mul_left hc lemma mul_le_of_forall_lt {a b c : ℝβ‰₯0∞} (h : βˆ€ a' < a, βˆ€ b' < b, a' * b' ≀ c) : a * b ≀ c := by refine le_of_forall_lt_imp_le_of_dense fun d hd ↦ ?_ obtain ⟨a', ha', hd⟩ := exists_lt_mul_left hd obtain ⟨b', hb', hd⟩ := exists_lt_mul_right hd exact le_trans hd.le <| h _ ha' _ hb' lemma le_mul_of_forall_lt {a b c : ℝβ‰₯0∞} (h₁ : a β‰  0 ∨ b β‰  ∞) (hβ‚‚ : a β‰  ∞ ∨ b β‰  0) (h : βˆ€ a' > a, βˆ€ b' > b, c ≀ a' * b') : c ≀ a * b := by rw [← ENNReal.inv_le_inv, ENNReal.mul_inv h₁ hβ‚‚] exact mul_le_of_forall_lt fun a' ha' b' hb' ↦ ENNReal.le_inv_iff_le_inv.1 <| (h _ (ENNReal.lt_inv_iff_lt_inv.1 ha') _ (ENNReal.lt_inv_iff_lt_inv.1 hb')).trans_eq (ENNReal.mul_inv (Or.inr hb'.ne_top) (Or.inl ha'.ne_top)).symm /-- The birational order isomorphism between `ℝβ‰₯0∞` and the unit interval `Set.Iic (1 : ℝβ‰₯0∞)`. -/ @[simps! apply_coe] def orderIsoIicOneBirational : ℝβ‰₯0∞ ≃o Iic (1 : ℝβ‰₯0∞) := by refine StrictMono.orderIsoOfRightInverse (fun x => ⟨(x⁻¹ + 1)⁻¹, ENNReal.inv_le_one.2 <| le_add_self⟩) (fun x y hxy => ?_) (fun x => (x.1⁻¹ - 1)⁻¹) fun x => Subtype.ext ?_ Β· simpa only [Subtype.mk_lt_mk, ENNReal.inv_lt_inv, ENNReal.add_lt_add_iff_right one_ne_top] Β· have : (1 : ℝβ‰₯0∞) ≀ x.1⁻¹ := ENNReal.one_le_inv.2 x.2 simp only [inv_inv, Subtype.coe_mk, tsub_add_cancel_of_le this] @[simp] theorem orderIsoIicOneBirational_symm_apply (x : Iic (1 : ℝβ‰₯0∞)) : orderIsoIicOneBirational.symm x = (x.1⁻¹ - 1)⁻¹ := rfl /-- Order isomorphism between an initial interval in `ℝβ‰₯0∞` and an initial interval in `ℝβ‰₯0`. -/ @[simps! apply_coe] def orderIsoIicCoe (a : ℝβ‰₯0) : Iic (a : ℝβ‰₯0∞) ≃o Iic a := OrderIso.symm { toFun := fun x => ⟨x, coe_le_coe.2 x.2⟩ invFun := fun x => ⟨ENNReal.toNNReal x, coe_le_coe.1 <| coe_toNNReal_le_self.trans x.2⟩ left_inv := fun _ => Subtype.ext <| toNNReal_coe _ right_inv := fun x => Subtype.ext <| coe_toNNReal (ne_top_of_le_ne_top coe_ne_top x.2) map_rel_iff' := fun {_ _} => by simp only [Equiv.coe_fn_mk, Subtype.mk_le_mk, coe_le_coe, Subtype.coe_le_coe] } @[simp] theorem orderIsoIicCoe_symm_apply_coe (a : ℝβ‰₯0) (b : Iic a) : ((orderIsoIicCoe a).symm b : ℝβ‰₯0∞) = b := rfl /-- An order isomorphism between the extended nonnegative real numbers and the unit interval. -/ def orderIsoUnitIntervalBirational : ℝβ‰₯0∞ ≃o Icc (0 : ℝ) 1 := orderIsoIicOneBirational.trans <| (orderIsoIicCoe 1).trans <| (NNReal.orderIsoIccZeroCoe 1).symm @[simp] theorem orderIsoUnitIntervalBirational_apply_coe (x : ℝβ‰₯0∞) : (orderIsoUnitIntervalBirational x : ℝ) = (x⁻¹ + 1)⁻¹.toReal := rfl theorem exists_inv_nat_lt {a : ℝβ‰₯0∞} (h : a β‰  0) : βˆƒ n : β„•, (n : ℝβ‰₯0∞)⁻¹ < a := inv_inv a β–Έ by simp only [ENNReal.inv_lt_inv, ENNReal.exists_nat_gt (inv_ne_top.2 h)] theorem exists_nat_pos_mul_gt (ha : a β‰  0) (hb : b β‰  ∞) : βˆƒ n > 0, b < (n : β„•) * a := let ⟨n, hn⟩ := ENNReal.exists_nat_gt (div_lt_top hb ha).ne ⟨n, Nat.cast_pos.1 ((zero_le _).trans_lt hn), by rwa [← ENNReal.div_lt_iff (Or.inl ha) (Or.inr hb)]⟩ theorem exists_nat_mul_gt (ha : a β‰  0) (hb : b β‰  ∞) : βˆƒ n : β„•, b < n * a := (exists_nat_pos_mul_gt ha hb).imp fun _ => And.right theorem exists_nat_pos_inv_mul_lt (ha : a β‰  ∞) (hb : b β‰  0) : βˆƒ n > 0, ((n : β„•) : ℝβ‰₯0∞)⁻¹ * a < b := by rcases exists_nat_pos_mul_gt hb ha with ⟨n, npos, hn⟩ use n, npos rw [← ENNReal.div_eq_inv_mul] exact div_lt_of_lt_mul' hn theorem exists_nnreal_pos_mul_lt (ha : a β‰  ∞) (hb : b β‰  0) : βˆƒ n > 0, ↑(n : ℝβ‰₯0) * a < b := by rcases exists_nat_pos_inv_mul_lt ha hb with ⟨n, npos : 0 < n, hn⟩ use (n : ℝβ‰₯0)⁻¹ simp [*, npos.ne', zero_lt_one] theorem exists_inv_two_pow_lt (ha : a β‰  0) : βˆƒ n : β„•, 2⁻¹ ^ n < a := by rcases exists_inv_nat_lt ha with ⟨n, hn⟩ refine ⟨n, lt_trans ?_ hn⟩ rw [← ENNReal.inv_pow, ENNReal.inv_lt_inv] norm_cast exact n.lt_two_pow_self @[simp, norm_cast] theorem coe_zpow (hr : r β‰  0) (n : β„€) : (↑(r ^ n) : ℝβ‰₯0∞) = (r : ℝβ‰₯0∞) ^ n := by rcases n with n | n Β· simp only [Int.ofNat_eq_coe, coe_pow, zpow_natCast] Β· have : r ^ n.succ β‰  0 := pow_ne_zero (n + 1) hr simp only [zpow_negSucc, coe_inv this, coe_pow] theorem zpow_pos (ha : a β‰  0) (h'a : a β‰  ∞) (n : β„€) : 0 < a ^ n := by cases n Β· simpa using ENNReal.pow_pos ha.bot_lt _ Β· simp only [h'a, pow_eq_top_iff, zpow_negSucc, Ne, not_false, ENNReal.inv_pos, false_and, not_false_eq_true] theorem zpow_lt_top (ha : a β‰  0) (h'a : a β‰  ∞) (n : β„€) : a ^ n < ∞ := by cases n Β· simpa using ENNReal.pow_lt_top h'a.lt_top Β· simp only [ENNReal.pow_pos ha.bot_lt, zpow_negSucc, inv_lt_top] theorem exists_mem_Ico_zpow {x y : ℝβ‰₯0∞} (hx : x β‰  0) (h'x : x β‰  ∞) (hy : 1 < y) (h'y : y β‰  ⊀) : βˆƒ n : β„€, x ∈ Ico (y ^ n) (y ^ (n + 1)) := by lift x to ℝβ‰₯0 using h'x lift y to ℝβ‰₯0 using h'y have A : y β‰  0 := by simpa only [Ne, coe_eq_zero] using (zero_lt_one.trans hy).ne' obtain ⟨n, hn, h'n⟩ : βˆƒ n : β„€, y ^ n ≀ x ∧ x < y ^ (n + 1) := by refine NNReal.exists_mem_Ico_zpow ?_ (one_lt_coe_iff.1 hy) simpa only [Ne, coe_eq_zero] using hx refine ⟨n, ?_, ?_⟩ Β· rwa [← ENNReal.coe_zpow A, ENNReal.coe_le_coe] Β· rwa [← ENNReal.coe_zpow A, ENNReal.coe_lt_coe] theorem exists_mem_Ioc_zpow {x y : ℝβ‰₯0∞} (hx : x β‰  0) (h'x : x β‰  ∞) (hy : 1 < y) (h'y : y β‰  ⊀) : βˆƒ n : β„€, x ∈ Ioc (y ^ n) (y ^ (n + 1)) := by lift x to ℝβ‰₯0 using h'x lift y to ℝβ‰₯0 using h'y have A : y β‰  0 := by simpa only [Ne, coe_eq_zero] using (zero_lt_one.trans hy).ne' obtain ⟨n, hn, h'n⟩ : βˆƒ n : β„€, y ^ n < x ∧ x ≀ y ^ (n + 1) := by refine NNReal.exists_mem_Ioc_zpow ?_ (one_lt_coe_iff.1 hy) simpa only [Ne, coe_eq_zero] using hx refine ⟨n, ?_, ?_⟩ Β· rwa [← ENNReal.coe_zpow A, ENNReal.coe_lt_coe] Β· rwa [← ENNReal.coe_zpow A, ENNReal.coe_le_coe] theorem Ioo_zero_top_eq_iUnion_Ico_zpow {y : ℝβ‰₯0∞} (hy : 1 < y) (h'y : y β‰  ⊀) : Ioo (0 : ℝβ‰₯0∞) (∞ : ℝβ‰₯0∞) = ⋃ n : β„€, Ico (y ^ n) (y ^ (n + 1)) := by ext x simp only [mem_iUnion, mem_Ioo, mem_Ico] constructor Β· rintro ⟨hx, h'x⟩ exact exists_mem_Ico_zpow hx.ne' h'x.ne hy h'y Β· rintro ⟨n, hn, h'n⟩ constructor Β· apply lt_of_lt_of_le _ hn exact ENNReal.zpow_pos (zero_lt_one.trans hy).ne' h'y _ Β· apply lt_trans h'n _ exact ENNReal.zpow_lt_top (zero_lt_one.trans hy).ne' h'y _ @[gcongr] theorem zpow_le_of_le {x : ℝβ‰₯0∞} (hx : 1 ≀ x) {a b : β„€} (h : a ≀ b) : x ^ a ≀ x ^ b := by obtain a | a := a <;> obtain b | b := b Β· simp only [Int.ofNat_eq_coe, zpow_natCast] exact pow_right_monoβ‚€ hx (Int.le_of_ofNat_le_ofNat h) Β· apply absurd h (not_le_of_gt _) exact lt_of_lt_of_le (Int.negSucc_lt_zero _) (Int.ofNat_nonneg _) Β· simp only [zpow_negSucc, Int.ofNat_eq_coe, zpow_natCast] refine (ENNReal.inv_le_one.2 ?_).trans ?_ <;> exact one_le_pow_of_one_le' hx _
Β· simp only [zpow_negSucc, ENNReal.inv_le_inv] apply pow_right_monoβ‚€ hx simpa only [← Int.ofNat_le, neg_le_neg_iff, Int.natCast_add, Int.ofNat_one] using h theorem monotone_zpow {x : ℝβ‰₯0∞} (hx : 1 ≀ x) : Monotone ((x ^ Β·) : β„€ β†’ ℝβ‰₯0∞) := fun _ _ h =>
Mathlib/Data/ENNReal/Inv.lean
684
688
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Heather Macbeth -/ import Mathlib.Analysis.InnerProductSpace.TwoDim import Mathlib.Geometry.Euclidean.Angle.Unoriented.Basic /-! # Oriented angles. This file defines oriented angles in real inner product spaces. ## Main definitions * `Orientation.oangle` is the oriented angle between two vectors with respect to an orientation. ## Implementation notes The definitions here use the `Real.angle` type, angles modulo `2 * Ο€`. For some purposes, angles modulo `Ο€` are more convenient, because results are true for such angles with less configuration dependence. Results that are only equalities modulo `Ο€` can be represented modulo `2 * Ο€` as equalities of `(2 : β„€) β€’ ΞΈ`. ## References * Evan Chen, Euclidean Geometry in Mathematical Olympiads. -/ noncomputable section open Module Complex open scoped Real RealInnerProductSpace ComplexConjugate namespace Orientation attribute [local instance] Complex.finrank_real_complex_fact variable {V V' : Type*} variable [NormedAddCommGroup V] [NormedAddCommGroup V'] variable [InnerProductSpace ℝ V] [InnerProductSpace ℝ V'] variable [Fact (finrank ℝ V = 2)] [Fact (finrank ℝ V' = 2)] (o : Orientation ℝ V (Fin 2)) local notation "Ο‰" => o.areaForm /-- The oriented angle from `x` to `y`, modulo `2 * Ο€`. If either vector is 0, this is 0. See `InnerProductGeometry.angle` for the corresponding unoriented angle definition. -/ def oangle (x y : V) : Real.Angle := Complex.arg (o.kahler x y) /-- Oriented angles are continuous when the vectors involved are nonzero. -/ @[fun_prop] theorem continuousAt_oangle {x : V Γ— V} (hx1 : x.1 β‰  0) (hx2 : x.2 β‰  0) : ContinuousAt (fun y : V Γ— V => o.oangle y.1 y.2) x := by refine (Complex.continuousAt_arg_coe_angle ?_).comp ?_ Β· exact o.kahler_ne_zero hx1 hx2 exact ((continuous_ofReal.comp continuous_inner).add ((continuous_ofReal.comp o.areaForm'.continuousβ‚‚).mul continuous_const)).continuousAt /-- If the first vector passed to `oangle` is 0, the result is 0. -/ @[simp] theorem oangle_zero_left (x : V) : o.oangle 0 x = 0 := by simp [oangle] /-- If the second vector passed to `oangle` is 0, the result is 0. -/ @[simp] theorem oangle_zero_right (x : V) : o.oangle x 0 = 0 := by simp [oangle] /-- If the two vectors passed to `oangle` are the same, the result is 0. -/ @[simp] theorem oangle_self (x : V) : o.oangle x x = 0 := by rw [oangle, kahler_apply_self, ← ofReal_pow] convert QuotientAddGroup.mk_zero (AddSubgroup.zmultiples (2 * Ο€)) apply arg_ofReal_of_nonneg positivity /-- If the angle between two vectors is nonzero, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y β‰  0) : x β‰  0 := by rintro rfl; simp at h /-- If the angle between two vectors is nonzero, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y β‰  0) : y β‰  0 := by rintro rfl; simp at h /-- If the angle between two vectors is nonzero, the vectors are not equal. -/ theorem ne_of_oangle_ne_zero {x y : V} (h : o.oangle x y β‰  0) : x β‰  y := by rintro rfl; simp at h /-- If the angle between two vectors is `Ο€`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = Ο€) : x β‰  0 := o.left_ne_zero_of_oangle_ne_zero (h.symm β–Έ Real.Angle.pi_ne_zero : o.oangle x y β‰  0) /-- If the angle between two vectors is `Ο€`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = Ο€) : y β‰  0 := o.right_ne_zero_of_oangle_ne_zero (h.symm β–Έ Real.Angle.pi_ne_zero : o.oangle x y β‰  0) /-- If the angle between two vectors is `Ο€`, the vectors are not equal. -/ theorem ne_of_oangle_eq_pi {x y : V} (h : o.oangle x y = Ο€) : x β‰  y := o.ne_of_oangle_ne_zero (h.symm β–Έ Real.Angle.pi_ne_zero : o.oangle x y β‰  0) /-- If the angle between two vectors is `Ο€ / 2`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (Ο€ / 2 : ℝ)) : x β‰  0 := o.left_ne_zero_of_oangle_ne_zero (h.symm β–Έ Real.Angle.pi_div_two_ne_zero : o.oangle x y β‰  0) /-- If the angle between two vectors is `Ο€ / 2`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (Ο€ / 2 : ℝ)) : y β‰  0 := o.right_ne_zero_of_oangle_ne_zero (h.symm β–Έ Real.Angle.pi_div_two_ne_zero : o.oangle x y β‰  0) /-- If the angle between two vectors is `Ο€ / 2`, the vectors are not equal. -/ theorem ne_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (Ο€ / 2 : ℝ)) : x β‰  y := o.ne_of_oangle_ne_zero (h.symm β–Έ Real.Angle.pi_div_two_ne_zero : o.oangle x y β‰  0) /-- If the angle between two vectors is `-Ο€ / 2`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-Ο€ / 2 : ℝ)) : x β‰  0 := o.left_ne_zero_of_oangle_ne_zero (h.symm β–Έ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y β‰  0) /-- If the angle between two vectors is `-Ο€ / 2`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-Ο€ / 2 : ℝ)) : y β‰  0 := o.right_ne_zero_of_oangle_ne_zero (h.symm β–Έ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y β‰  0) /-- If the angle between two vectors is `-Ο€ / 2`, the vectors are not equal. -/ theorem ne_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-Ο€ / 2 : ℝ)) : x β‰  y := o.ne_of_oangle_ne_zero (h.symm β–Έ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y β‰  0) /-- If the sign of the angle between two vectors is nonzero, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign β‰  0) : x β‰  0 := o.left_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 /-- If the sign of the angle between two vectors is nonzero, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign β‰  0) : y β‰  0 := o.right_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 /-- If the sign of the angle between two vectors is nonzero, the vectors are not equal. -/ theorem ne_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign β‰  0) : x β‰  y := o.ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 /-- If the sign of the angle between two vectors is positive, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x β‰  0 := o.left_ne_zero_of_oangle_sign_ne_zero (h.symm β–Έ by decide : (o.oangle x y).sign β‰  0) /-- If the sign of the angle between two vectors is positive, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : y β‰  0 := o.right_ne_zero_of_oangle_sign_ne_zero (h.symm β–Έ by decide : (o.oangle x y).sign β‰  0) /-- If the sign of the angle between two vectors is positive, the vectors are not equal. -/ theorem ne_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x β‰  y := o.ne_of_oangle_sign_ne_zero (h.symm β–Έ by decide : (o.oangle x y).sign β‰  0) /-- If the sign of the angle between two vectors is negative, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x β‰  0 := o.left_ne_zero_of_oangle_sign_ne_zero (h.symm β–Έ by decide : (o.oangle x y).sign β‰  0) /-- If the sign of the angle between two vectors is negative, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : y β‰  0 := o.right_ne_zero_of_oangle_sign_ne_zero (h.symm β–Έ by decide : (o.oangle x y).sign β‰  0) /-- If the sign of the angle between two vectors is negative, the vectors are not equal. -/ theorem ne_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x β‰  y := o.ne_of_oangle_sign_ne_zero (h.symm β–Έ by decide : (o.oangle x y).sign β‰  0) /-- Swapping the two vectors passed to `oangle` negates the angle. -/ theorem oangle_rev (x y : V) : o.oangle y x = -o.oangle x y := by simp only [oangle, o.kahler_swap y x, Complex.arg_conj_coe_angle] /-- Adding the angles between two vectors in each order results in 0. -/ @[simp] theorem oangle_add_oangle_rev (x y : V) : o.oangle x y + o.oangle y x = 0 := by simp [o.oangle_rev y x] /-- Negating the first vector passed to `oangle` adds `Ο€` to the angle. -/ theorem oangle_neg_left {x y : V} (hx : x β‰  0) (hy : y β‰  0) : o.oangle (-x) y = o.oangle x y + Ο€ := by simp only [oangle, map_neg] convert Complex.arg_neg_coe_angle _ exact o.kahler_ne_zero hx hy /-- Negating the second vector passed to `oangle` adds `Ο€` to the angle. -/ theorem oangle_neg_right {x y : V} (hx : x β‰  0) (hy : y β‰  0) : o.oangle x (-y) = o.oangle x y + Ο€ := by simp only [oangle, map_neg] convert Complex.arg_neg_coe_angle _ exact o.kahler_ne_zero hx hy /-- Negating the first vector passed to `oangle` does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_neg_left (x y : V) : (2 : β„€) β€’ o.oangle (-x) y = (2 : β„€) β€’ o.oangle x y := by by_cases hx : x = 0 Β· simp [hx] Β· by_cases hy : y = 0 Β· simp [hy] Β· simp [o.oangle_neg_left hx hy] /-- Negating the second vector passed to `oangle` does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_neg_right (x y : V) : (2 : β„€) β€’ o.oangle x (-y) = (2 : β„€) β€’ o.oangle x y := by by_cases hx : x = 0 Β· simp [hx] Β· by_cases hy : y = 0 Β· simp [hy] Β· simp [o.oangle_neg_right hx hy] /-- Negating both vectors passed to `oangle` does not change the angle. -/ @[simp] theorem oangle_neg_neg (x y : V) : o.oangle (-x) (-y) = o.oangle x y := by simp [oangle] /-- Negating the first vector produces the same angle as negating the second vector. -/ theorem oangle_neg_left_eq_neg_right (x y : V) : o.oangle (-x) y = o.oangle x (-y) := by rw [← neg_neg y, oangle_neg_neg, neg_neg] /-- The angle between the negation of a nonzero vector and that vector is `Ο€`. -/ @[simp] theorem oangle_neg_self_left {x : V} (hx : x β‰  0) : o.oangle (-x) x = Ο€ := by simp [oangle_neg_left, hx] /-- The angle between a nonzero vector and its negation is `Ο€`. -/ @[simp] theorem oangle_neg_self_right {x : V} (hx : x β‰  0) : o.oangle x (-x) = Ο€ := by simp [oangle_neg_right, hx] /-- Twice the angle between the negation of a vector and that vector is 0. -/ theorem two_zsmul_oangle_neg_self_left (x : V) : (2 : β„€) β€’ o.oangle (-x) x = 0 := by by_cases hx : x = 0 <;> simp [hx] /-- Twice the angle between a vector and its negation is 0. -/ theorem two_zsmul_oangle_neg_self_right (x : V) : (2 : β„€) β€’ o.oangle x (-x) = 0 := by by_cases hx : x = 0 <;> simp [hx] /-- Adding the angles between two vectors in each order, with the first vector in each angle negated, results in 0. -/ @[simp] theorem oangle_add_oangle_rev_neg_left (x y : V) : o.oangle (-x) y + o.oangle (-y) x = 0 := by rw [oangle_neg_left_eq_neg_right, oangle_rev, neg_add_cancel] /-- Adding the angles between two vectors in each order, with the second vector in each angle negated, results in 0. -/ @[simp] theorem oangle_add_oangle_rev_neg_right (x y : V) : o.oangle x (-y) + o.oangle y (-x) = 0 := by rw [o.oangle_rev (-x), oangle_neg_left_eq_neg_right, add_neg_cancel] /-- Multiplying the first vector passed to `oangle` by a positive real does not change the angle. -/ @[simp] theorem oangle_smul_left_of_pos (x y : V) {r : ℝ} (hr : 0 < r) : o.oangle (r β€’ x) y = o.oangle x y := by simp [oangle, Complex.arg_real_mul _ hr] /-- Multiplying the second vector passed to `oangle` by a positive real does not change the angle. -/ @[simp] theorem oangle_smul_right_of_pos (x y : V) {r : ℝ} (hr : 0 < r) : o.oangle x (r β€’ y) = o.oangle x y := by simp [oangle, Complex.arg_real_mul _ hr] /-- Multiplying the first vector passed to `oangle` by a negative real produces the same angle as negating that vector. -/ @[simp] theorem oangle_smul_left_of_neg (x y : V) {r : ℝ} (hr : r < 0) : o.oangle (r β€’ x) y = o.oangle (-x) y := by rw [← neg_neg r, neg_smul, ← smul_neg, o.oangle_smul_left_of_pos _ _ (neg_pos_of_neg hr)] /-- Multiplying the second vector passed to `oangle` by a negative real produces the same angle as negating that vector. -/ @[simp] theorem oangle_smul_right_of_neg (x y : V) {r : ℝ} (hr : r < 0) : o.oangle x (r β€’ y) = o.oangle x (-y) := by rw [← neg_neg r, neg_smul, ← smul_neg, o.oangle_smul_right_of_pos _ _ (neg_pos_of_neg hr)] /-- The angle between a nonnegative multiple of a vector and that vector is 0. -/ @[simp] theorem oangle_smul_left_self_of_nonneg (x : V) {r : ℝ} (hr : 0 ≀ r) : o.oangle (r β€’ x) x = 0 := by rcases hr.lt_or_eq with (h | h) Β· simp [h] Β· simp [h.symm] /-- The angle between a vector and a nonnegative multiple of that vector is 0. -/ @[simp] theorem oangle_smul_right_self_of_nonneg (x : V) {r : ℝ} (hr : 0 ≀ r) : o.oangle x (r β€’ x) = 0 := by rcases hr.lt_or_eq with (h | h) Β· simp [h] Β· simp [h.symm] /-- The angle between two nonnegative multiples of the same vector is 0. -/ @[simp] theorem oangle_smul_smul_self_of_nonneg (x : V) {r₁ rβ‚‚ : ℝ} (hr₁ : 0 ≀ r₁) (hrβ‚‚ : 0 ≀ rβ‚‚) : o.oangle (r₁ β€’ x) (rβ‚‚ β€’ x) = 0 := by rcases hr₁.lt_or_eq with (h | h) Β· simp [h, hrβ‚‚] Β· simp [h.symm] /-- Multiplying the first vector passed to `oangle` by a nonzero real does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_smul_left_of_ne_zero (x y : V) {r : ℝ} (hr : r β‰  0) : (2 : β„€) β€’ o.oangle (r β€’ x) y = (2 : β„€) β€’ o.oangle x y := by rcases hr.lt_or_lt with (h | h) <;> simp [h] /-- Multiplying the second vector passed to `oangle` by a nonzero real does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_smul_right_of_ne_zero (x y : V) {r : ℝ} (hr : r β‰  0) : (2 : β„€) β€’ o.oangle x (r β€’ y) = (2 : β„€) β€’ o.oangle x y := by rcases hr.lt_or_lt with (h | h) <;> simp [h] /-- Twice the angle between a multiple of a vector and that vector is 0. -/ @[simp] theorem two_zsmul_oangle_smul_left_self (x : V) {r : ℝ} : (2 : β„€) β€’ o.oangle (r β€’ x) x = 0 := by rcases lt_or_le r 0 with (h | h) <;> simp [h] /-- Twice the angle between a vector and a multiple of that vector is 0. -/ @[simp] theorem two_zsmul_oangle_smul_right_self (x : V) {r : ℝ} : (2 : β„€) β€’ o.oangle x (r β€’ x) = 0 := by rcases lt_or_le r 0 with (h | h) <;> simp [h] /-- Twice the angle between two multiples of a vector is 0. -/ @[simp] theorem two_zsmul_oangle_smul_smul_self (x : V) {r₁ rβ‚‚ : ℝ} : (2 : β„€) β€’ o.oangle (r₁ β€’ x) (rβ‚‚ β€’ x) = 0 := by by_cases h : r₁ = 0 <;> simp [h] /-- If the spans of two vectors are equal, twice angles with those vectors on the left are equal. -/ theorem two_zsmul_oangle_left_of_span_eq {x y : V} (z : V) (h : (ℝ βˆ™ x) = ℝ βˆ™ y) : (2 : β„€) β€’ o.oangle x z = (2 : β„€) β€’ o.oangle y z := by rw [Submodule.span_singleton_eq_span_singleton] at h rcases h with ⟨r, rfl⟩ exact (o.two_zsmul_oangle_smul_left_of_ne_zero _ _ (Units.ne_zero _)).symm /-- If the spans of two vectors are equal, twice angles with those vectors on the right are equal. -/ theorem two_zsmul_oangle_right_of_span_eq (x : V) {y z : V} (h : (ℝ βˆ™ y) = ℝ βˆ™ z) : (2 : β„€) β€’ o.oangle x y = (2 : β„€) β€’ o.oangle x z := by rw [Submodule.span_singleton_eq_span_singleton] at h rcases h with ⟨r, rfl⟩ exact (o.two_zsmul_oangle_smul_right_of_ne_zero _ _ (Units.ne_zero _)).symm /-- If the spans of two pairs of vectors are equal, twice angles between those vectors are equal. -/ theorem two_zsmul_oangle_of_span_eq_of_span_eq {w x y z : V} (hwx : (ℝ βˆ™ w) = ℝ βˆ™ x) (hyz : (ℝ βˆ™ y) = ℝ βˆ™ z) : (2 : β„€) β€’ o.oangle w y = (2 : β„€) β€’ o.oangle x z := by rw [o.two_zsmul_oangle_left_of_span_eq y hwx, o.two_zsmul_oangle_right_of_span_eq x hyz] /-- The oriented angle between two vectors is zero if and only if the angle with the vectors swapped is zero. -/ theorem oangle_eq_zero_iff_oangle_rev_eq_zero {x y : V} : o.oangle x y = 0 ↔ o.oangle y x = 0 := by rw [oangle_rev, neg_eq_zero] /-- The oriented angle between two vectors is zero if and only if they are on the same ray. -/ theorem oangle_eq_zero_iff_sameRay {x y : V} : o.oangle x y = 0 ↔ SameRay ℝ x y := by rw [oangle, kahler_apply_apply, Complex.arg_coe_angle_eq_iff_eq_toReal, Real.Angle.toReal_zero, Complex.arg_eq_zero_iff] simpa using o.nonneg_inner_and_areaForm_eq_zero_iff_sameRay x y /-- The oriented angle between two vectors is `Ο€` if and only if the angle with the vectors swapped is `Ο€`. -/ theorem oangle_eq_pi_iff_oangle_rev_eq_pi {x y : V} : o.oangle x y = Ο€ ↔ o.oangle y x = Ο€ := by rw [oangle_rev, neg_eq_iff_eq_neg, Real.Angle.neg_coe_pi] /-- The oriented angle between two vectors is `Ο€` if and only they are nonzero and the first is on the same ray as the negation of the second. -/ theorem oangle_eq_pi_iff_sameRay_neg {x y : V} : o.oangle x y = Ο€ ↔ x β‰  0 ∧ y β‰  0 ∧ SameRay ℝ x (-y) := by rw [← o.oangle_eq_zero_iff_sameRay] constructor Β· intro h by_cases hx : x = 0; Β· simp [hx, Real.Angle.pi_ne_zero.symm] at h by_cases hy : y = 0; Β· simp [hy, Real.Angle.pi_ne_zero.symm] at h refine ⟨hx, hy, ?_⟩ rw [o.oangle_neg_right hx hy, h, Real.Angle.coe_pi_add_coe_pi] Β· rintro ⟨hx, hy, h⟩ rwa [o.oangle_neg_right hx hy, ← Real.Angle.sub_coe_pi_eq_add_coe_pi, sub_eq_zero] at h /-- The oriented angle between two vectors is zero or `Ο€` if and only if those two vectors are not linearly independent. -/ theorem oangle_eq_zero_or_eq_pi_iff_not_linearIndependent {x y : V} : o.oangle x y = 0 ∨ o.oangle x y = Ο€ ↔ Β¬LinearIndependent ℝ ![x, y] := by rw [oangle_eq_zero_iff_sameRay, oangle_eq_pi_iff_sameRay_neg, sameRay_or_ne_zero_and_sameRay_neg_iff_not_linearIndependent] /-- The oriented angle between two vectors is zero or `Ο€` if and only if the first vector is zero or the second is a multiple of the first. -/ theorem oangle_eq_zero_or_eq_pi_iff_right_eq_smul {x y : V} : o.oangle x y = 0 ∨ o.oangle x y = Ο€ ↔ x = 0 ∨ βˆƒ r : ℝ, y = r β€’ x := by rw [oangle_eq_zero_iff_sameRay, oangle_eq_pi_iff_sameRay_neg] refine ⟨fun h => ?_, fun h => ?_⟩ Β· rcases h with (h | ⟨-, -, h⟩) Β· by_cases hx : x = 0; Β· simp [hx] obtain ⟨r, -, rfl⟩ := h.exists_nonneg_left hx exact Or.inr ⟨r, rfl⟩ Β· by_cases hx : x = 0; Β· simp [hx] obtain ⟨r, -, hy⟩ := h.exists_nonneg_left hx refine Or.inr ⟨-r, ?_⟩ simp [hy] Β· rcases h with (rfl | ⟨r, rfl⟩); Β· simp by_cases hx : x = 0; Β· simp [hx] rcases lt_trichotomy r 0 with (hr | hr | hr) Β· rw [← neg_smul] exact Or.inr ⟨hx, smul_ne_zero hr.ne hx, SameRay.sameRay_pos_smul_right x (Left.neg_pos_iff.2 hr)⟩ Β· simp [hr] Β· exact Or.inl (SameRay.sameRay_pos_smul_right x hr) /-- The oriented angle between two vectors is not zero or `Ο€` if and only if those two vectors are linearly independent. -/ theorem oangle_ne_zero_and_ne_pi_iff_linearIndependent {x y : V} : o.oangle x y β‰  0 ∧ o.oangle x y β‰  Ο€ ↔ LinearIndependent ℝ ![x, y] := by rw [← not_or, ← not_iff_not, Classical.not_not, oangle_eq_zero_or_eq_pi_iff_not_linearIndependent] /-- Two vectors are equal if and only if they have equal norms and zero angle between them. -/ theorem eq_iff_norm_eq_and_oangle_eq_zero (x y : V) : x = y ↔ β€–xβ€– = β€–yβ€– ∧ o.oangle x y = 0 := by rw [oangle_eq_zero_iff_sameRay] constructor Β· rintro rfl simp; rfl Β· rcases eq_or_ne y 0 with (rfl | hy) Β· simp rintro ⟨h₁, hβ‚‚βŸ© obtain ⟨r, hr, rfl⟩ := hβ‚‚.exists_nonneg_right hy have : β€–yβ€– β‰  0 := by simpa using hy obtain rfl : r = 1 := by apply mul_right_cancelβ‚€ this simpa [norm_smul, abs_of_nonneg hr] using h₁ simp /-- Two vectors with equal norms are equal if and only if they have zero angle between them. -/ theorem eq_iff_oangle_eq_zero_of_norm_eq {x y : V} (h : β€–xβ€– = β€–yβ€–) : x = y ↔ o.oangle x y = 0 := ⟨fun he => ((o.eq_iff_norm_eq_and_oangle_eq_zero x y).1 he).2, fun ha => (o.eq_iff_norm_eq_and_oangle_eq_zero x y).2 ⟨h, ha⟩⟩ /-- Two vectors with zero angle between them are equal if and only if they have equal norms. -/ theorem eq_iff_norm_eq_of_oangle_eq_zero {x y : V} (h : o.oangle x y = 0) : x = y ↔ β€–xβ€– = β€–yβ€– := ⟨fun he => ((o.eq_iff_norm_eq_and_oangle_eq_zero x y).1 he).1, fun hn => (o.eq_iff_norm_eq_and_oangle_eq_zero x y).2 ⟨hn, h⟩⟩ /-- Given three nonzero vectors, the angle between the first and the second plus the angle between the second and the third equals the angle between the first and the third. -/ @[simp] theorem oangle_add {x y z : V} (hx : x β‰  0) (hy : y β‰  0) (hz : z β‰  0) : o.oangle x y + o.oangle y z = o.oangle x z := by simp_rw [oangle] rw [← Complex.arg_mul_coe_angle, o.kahler_mul y x z] Β· congr 1 exact mod_cast Complex.arg_real_mul _ (by positivity : 0 < β€–yβ€– ^ 2) Β· exact o.kahler_ne_zero hx hy Β· exact o.kahler_ne_zero hy hz /-- Given three nonzero vectors, the angle between the second and the third plus the angle between the first and the second equals the angle between the first and the third. -/ @[simp] theorem oangle_add_swap {x y z : V} (hx : x β‰  0) (hy : y β‰  0) (hz : z β‰  0) : o.oangle y z + o.oangle x y = o.oangle x z := by rw [add_comm, o.oangle_add hx hy hz] /-- Given three nonzero vectors, the angle between the first and the third minus the angle between the first and the second equals the angle between the second and the third. -/ @[simp] theorem oangle_sub_left {x y z : V} (hx : x β‰  0) (hy : y β‰  0) (hz : z β‰  0) : o.oangle x z - o.oangle x y = o.oangle y z := by rw [sub_eq_iff_eq_add, o.oangle_add_swap hx hy hz] /-- Given three nonzero vectors, the angle between the first and the third minus the angle between the second and the third equals the angle between the first and the second. -/ @[simp] theorem oangle_sub_right {x y z : V} (hx : x β‰  0) (hy : y β‰  0) (hz : z β‰  0) : o.oangle x z - o.oangle y z = o.oangle x y := by rw [sub_eq_iff_eq_add, o.oangle_add hx hy hz] /-- Given three nonzero vectors, adding the angles between them in cyclic order results in 0. -/ @[simp] theorem oangle_add_cyc3 {x y z : V} (hx : x β‰  0) (hy : y β‰  0) (hz : z β‰  0) : o.oangle x y + o.oangle y z + o.oangle z x = 0 := by simp [hx, hy, hz] /-- Given three nonzero vectors, adding the angles between them in cyclic order, with the first vector in each angle negated, results in Ο€. If the vectors add to 0, this is a version of the sum of the angles of a triangle. -/ @[simp] theorem oangle_add_cyc3_neg_left {x y z : V} (hx : x β‰  0) (hy : y β‰  0) (hz : z β‰  0) : o.oangle (-x) y + o.oangle (-y) z + o.oangle (-z) x = Ο€ := by rw [o.oangle_neg_left hx hy, o.oangle_neg_left hy hz, o.oangle_neg_left hz hx, show o.oangle x y + Ο€ + (o.oangle y z + Ο€) + (o.oangle z x + Ο€) = o.oangle x y + o.oangle y z + o.oangle z x + (Ο€ + Ο€ + Ο€ : Real.Angle) by abel, o.oangle_add_cyc3 hx hy hz, Real.Angle.coe_pi_add_coe_pi, zero_add, zero_add] /-- Given three nonzero vectors, adding the angles between them in cyclic order, with the second vector in each angle negated, results in Ο€. If the vectors add to 0, this is a version of the sum of the angles of a triangle. -/ @[simp] theorem oangle_add_cyc3_neg_right {x y z : V} (hx : x β‰  0) (hy : y β‰  0) (hz : z β‰  0) : o.oangle x (-y) + o.oangle y (-z) + o.oangle z (-x) = Ο€ := by simp_rw [← oangle_neg_left_eq_neg_right, o.oangle_add_cyc3_neg_left hx hy hz] /-- Pons asinorum, oriented vector angle form. -/ theorem oangle_sub_eq_oangle_sub_rev_of_norm_eq {x y : V} (h : β€–xβ€– = β€–yβ€–) : o.oangle x (x - y) = o.oangle (y - x) y := by simp [oangle, h] /-- The angle at the apex of an isosceles triangle is `Ο€` minus twice a base angle, oriented vector angle form. -/ theorem oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq {x y : V} (hn : x β‰  y) (h : β€–xβ€– = β€–yβ€–) : o.oangle y x = Ο€ - (2 : β„€) β€’ o.oangle (y - x) y := by rw [two_zsmul] nth_rw 1 [← o.oangle_sub_eq_oangle_sub_rev_of_norm_eq h] rw [eq_sub_iff_add_eq, ← oangle_neg_neg, ← add_assoc] have hy : y β‰  0 := by rintro rfl rw [norm_zero, norm_eq_zero] at h exact hn h have hx : x β‰  0 := norm_ne_zero_iff.1 (h.symm β–Έ norm_ne_zero_iff.2 hy) convert o.oangle_add_cyc3_neg_right (neg_ne_zero.2 hy) hx (sub_ne_zero_of_ne hn.symm) using 1 simp /-- The angle between two vectors, with respect to an orientation given by `Orientation.map` with a linear isometric equivalence, equals the angle between those two vectors, transformed by the inverse of that equivalence, with respect to the original orientation. -/ @[simp] theorem oangle_map (x y : V') (f : V ≃ₗᡒ[ℝ] V') : (Orientation.map (Fin 2) f.toLinearEquiv o).oangle x y = o.oangle (f.symm x) (f.symm y) := by simp [oangle, o.kahler_map] @[simp] protected theorem _root_.Complex.oangle (w z : β„‚) : Complex.orientation.oangle w z = Complex.arg (conj w * z) := by simp [oangle, mul_comm z] /-- The oriented angle on an oriented real inner product space of dimension 2 can be evaluated in terms of a complex-number representation of the space. -/ theorem oangle_map_complex (f : V ≃ₗᡒ[ℝ] β„‚) (hf : Orientation.map (Fin 2) f.toLinearEquiv o = Complex.orientation) (x y : V) : o.oangle x y = Complex.arg (conj (f x) * f y) := by rw [← Complex.oangle, ← hf, o.oangle_map] iterate 2 rw [LinearIsometryEquiv.symm_apply_apply] /-- Negating the orientation negates the value of `oangle`. -/ theorem oangle_neg_orientation_eq_neg (x y : V) : (-o).oangle x y = -o.oangle x y := by simp [oangle] /-- The inner product of two vectors is the product of the norms and the cosine of the oriented angle between the vectors. -/ theorem inner_eq_norm_mul_norm_mul_cos_oangle (x y : V) : βŸͺx, y⟫ = β€–xβ€– * β€–yβ€– * Real.Angle.cos (o.oangle x y) := by by_cases hx : x = 0; Β· simp [hx] by_cases hy : y = 0; Β· simp [hy] rw [oangle, Real.Angle.cos_coe, Complex.cos_arg, o.norm_kahler] Β· simp only [kahler_apply_apply, real_smul, add_re, ofReal_re, mul_re, I_re, ofReal_im] field_simp Β· exact o.kahler_ne_zero hx hy /-- The cosine of the oriented angle between two nonzero vectors is the inner product divided by the product of the norms. -/ theorem cos_oangle_eq_inner_div_norm_mul_norm {x y : V} (hx : x β‰  0) (hy : y β‰  0) : Real.Angle.cos (o.oangle x y) = βŸͺx, y⟫ / (β€–xβ€– * β€–yβ€–) := by rw [o.inner_eq_norm_mul_norm_mul_cos_oangle] field_simp [norm_ne_zero_iff.2 hx, norm_ne_zero_iff.2 hy] /-- The cosine of the oriented angle between two nonzero vectors equals that of the unoriented angle. -/ theorem cos_oangle_eq_cos_angle {x y : V} (hx : x β‰  0) (hy : y β‰  0) : Real.Angle.cos (o.oangle x y) = Real.cos (InnerProductGeometry.angle x y) := by rw [o.cos_oangle_eq_inner_div_norm_mul_norm hx hy, InnerProductGeometry.cos_angle] /-- The oriented angle between two nonzero vectors is plus or minus the unoriented angle. -/ theorem oangle_eq_angle_or_eq_neg_angle {x y : V} (hx : x β‰  0) (hy : y β‰  0) : o.oangle x y = InnerProductGeometry.angle x y ∨ o.oangle x y = -InnerProductGeometry.angle x y := Real.Angle.cos_eq_real_cos_iff_eq_or_eq_neg.1 <| o.cos_oangle_eq_cos_angle hx hy /-- The unoriented angle between two nonzero vectors is the absolute value of the oriented angle, converted to a real. -/ theorem angle_eq_abs_oangle_toReal {x y : V} (hx : x β‰  0) (hy : y β‰  0) : InnerProductGeometry.angle x y = |(o.oangle x y).toReal| := by have h0 := InnerProductGeometry.angle_nonneg x y have hpi := InnerProductGeometry.angle_le_pi x y rcases o.oangle_eq_angle_or_eq_neg_angle hx hy with (h | h) Β· rw [h, eq_comm, Real.Angle.abs_toReal_coe_eq_self_iff] exact ⟨h0, hpi⟩ Β· rw [h, eq_comm, Real.Angle.abs_toReal_neg_coe_eq_self_iff] exact ⟨h0, hpi⟩ /-- If the sign of the oriented angle between two vectors is zero, either one of the vectors is zero or the unoriented angle is 0 or Ο€. -/ theorem eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero {x y : V} (h : (o.oangle x y).sign = 0) : x = 0 ∨ y = 0 ∨ InnerProductGeometry.angle x y = 0 ∨ InnerProductGeometry.angle x y = Ο€ := by by_cases hx : x = 0; Β· simp [hx] by_cases hy : y = 0; Β· simp [hy] rw [o.angle_eq_abs_oangle_toReal hx hy] rw [Real.Angle.sign_eq_zero_iff] at h rcases h with (h | h) <;> simp [h, Real.pi_pos.le] /-- If two unoriented angles are equal, and the signs of the corresponding oriented angles are equal, then the oriented angles are equal (even in degenerate cases). -/ theorem oangle_eq_of_angle_eq_of_sign_eq {w x y z : V} (h : InnerProductGeometry.angle w x = InnerProductGeometry.angle y z) (hs : (o.oangle w x).sign = (o.oangle y z).sign) : o.oangle w x = o.oangle y z := by by_cases h0 : (w = 0 ∨ x = 0) ∨ y = 0 ∨ z = 0 Β· have hs' : (o.oangle w x).sign = 0 ∧ (o.oangle y z).sign = 0 := by rcases h0 with ((rfl | rfl) | rfl | rfl) Β· simpa using hs.symm Β· simpa using hs.symm Β· simpa using hs Β· simpa using hs rcases hs' with ⟨hswx, hsyz⟩ have h' : InnerProductGeometry.angle w x = Ο€ / 2 ∧ InnerProductGeometry.angle y z = Ο€ / 2 := by rcases h0 with ((rfl | rfl) | rfl | rfl) Β· simpa using h.symm Β· simpa using h.symm Β· simpa using h Β· simpa using h rcases h' with ⟨hwx, hyz⟩ have hpi : Ο€ / 2 β‰  Ο€ := by intro hpi rw [div_eq_iff, eq_comm, ← sub_eq_zero, mul_two, add_sub_cancel_right] at hpi Β· exact Real.pi_pos.ne.symm hpi Β· exact two_ne_zero have h0wx : w = 0 ∨ x = 0 := by have h0' := o.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero hswx simpa [hwx, Real.pi_pos.ne.symm, hpi] using h0' have h0yz : y = 0 ∨ z = 0 := by have h0' := o.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero hsyz simpa [hyz, Real.pi_pos.ne.symm, hpi] using h0' rcases h0wx with (h0wx | h0wx) <;> rcases h0yz with (h0yz | h0yz) <;> simp [h0wx, h0yz] Β· push_neg at h0 rw [Real.Angle.eq_iff_abs_toReal_eq_of_sign_eq hs] rwa [o.angle_eq_abs_oangle_toReal h0.1.1 h0.1.2, o.angle_eq_abs_oangle_toReal h0.2.1 h0.2.2] at h /-- If the signs of two oriented angles between nonzero vectors are equal, the oriented angles are equal if and only if the unoriented angles are equal. -/ theorem angle_eq_iff_oangle_eq_of_sign_eq {w x y z : V} (hw : w β‰  0) (hx : x β‰  0) (hy : y β‰  0) (hz : z β‰  0) (hs : (o.oangle w x).sign = (o.oangle y z).sign) : InnerProductGeometry.angle w x = InnerProductGeometry.angle y z ↔ o.oangle w x = o.oangle y z := by refine ⟨fun h => o.oangle_eq_of_angle_eq_of_sign_eq h hs, fun h => ?_⟩ rw [o.angle_eq_abs_oangle_toReal hw hx, o.angle_eq_abs_oangle_toReal hy hz, h] /-- The oriented angle between two vectors equals the unoriented angle if the sign is positive. -/ theorem oangle_eq_angle_of_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : o.oangle x y = InnerProductGeometry.angle x y := by by_cases hx : x = 0; Β· exfalso; simp [hx] at h by_cases hy : y = 0; Β· exfalso; simp [hy] at h refine (o.oangle_eq_angle_or_eq_neg_angle hx hy).resolve_right ?_ intro hxy rw [hxy, Real.Angle.sign_neg, neg_eq_iff_eq_neg, ← SignType.neg_iff, ← not_le] at h exact h (Real.Angle.sign_coe_nonneg_of_nonneg_of_le_pi (InnerProductGeometry.angle_nonneg _ _) (InnerProductGeometry.angle_le_pi _ _)) /-- The oriented angle between two vectors equals minus the unoriented angle if the sign is negative. -/ theorem oangle_eq_neg_angle_of_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : o.oangle x y = -InnerProductGeometry.angle x y := by by_cases hx : x = 0; Β· exfalso; simp [hx] at h by_cases hy : y = 0; Β· exfalso; simp [hy] at h refine (o.oangle_eq_angle_or_eq_neg_angle hx hy).resolve_left ?_ intro hxy rw [hxy, ← SignType.neg_iff, ← not_le] at h exact h (Real.Angle.sign_coe_nonneg_of_nonneg_of_le_pi (InnerProductGeometry.angle_nonneg _ _) (InnerProductGeometry.angle_le_pi _ _)) /-- The oriented angle between two nonzero vectors is zero if and only if the unoriented angle is zero. -/ theorem oangle_eq_zero_iff_angle_eq_zero {x y : V} (hx : x β‰  0) (hy : y β‰  0) : o.oangle x y = 0 ↔ InnerProductGeometry.angle x y = 0 := by refine ⟨fun h => ?_, fun h => ?_⟩ Β· simpa [o.angle_eq_abs_oangle_toReal hx hy] Β· have ha := o.oangle_eq_angle_or_eq_neg_angle hx hy rw [h] at ha simpa using ha /-- The oriented angle between two vectors is `Ο€` if and only if the unoriented angle is `Ο€`. -/ theorem oangle_eq_pi_iff_angle_eq_pi {x y : V} : o.oangle x y = Ο€ ↔ InnerProductGeometry.angle x y = Ο€ := by by_cases hx : x = 0 Β· simp [hx, Real.Angle.pi_ne_zero.symm, div_eq_mul_inv, mul_right_eq_selfβ‚€, not_or, Real.pi_ne_zero] by_cases hy : y = 0 Β· simp [hy, Real.Angle.pi_ne_zero.symm, div_eq_mul_inv, mul_right_eq_selfβ‚€, not_or, Real.pi_ne_zero] refine ⟨fun h => ?_, fun h => ?_⟩ Β· rw [o.angle_eq_abs_oangle_toReal hx hy, h] simp [Real.pi_pos.le] Β· have ha := o.oangle_eq_angle_or_eq_neg_angle hx hy rw [h] at ha simpa using ha /-- One of two vectors is zero or the oriented angle between them is plus or minus `Ο€ / 2` if and only if the inner product of those vectors is zero. -/ theorem eq_zero_or_oangle_eq_iff_inner_eq_zero {x y : V} : x = 0 ∨ y = 0 ∨ o.oangle x y = (Ο€ / 2 : ℝ) ∨ o.oangle x y = (-Ο€ / 2 : ℝ) ↔ βŸͺx, y⟫ = 0 := by by_cases hx : x = 0; Β· simp [hx] by_cases hy : y = 0; Β· simp [hy] rw [InnerProductGeometry.inner_eq_zero_iff_angle_eq_pi_div_two, or_iff_right hx, or_iff_right hy] refine ⟨fun h => ?_, fun h => ?_⟩ Β· rwa [o.angle_eq_abs_oangle_toReal hx hy, Real.Angle.abs_toReal_eq_pi_div_two_iff] Β· convert o.oangle_eq_angle_or_eq_neg_angle hx hy using 2 <;> rw [h] simp only [neg_div, Real.Angle.coe_neg] /-- If the oriented angle between two vectors is `Ο€ / 2`, the inner product of those vectors is zero. -/ theorem inner_eq_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (Ο€ / 2 : ℝ)) : βŸͺx, y⟫ = 0 := o.eq_zero_or_oangle_eq_iff_inner_eq_zero.1 <| Or.inr <| Or.inr <| Or.inl h /-- If the oriented angle between two vectors is `Ο€ / 2`, the inner product of those vectors (reversed) is zero. -/ theorem inner_rev_eq_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (Ο€ / 2 : ℝ)) : βŸͺy, x⟫ = 0 := by rw [real_inner_comm, o.inner_eq_zero_of_oangle_eq_pi_div_two h] /-- If the oriented angle between two vectors is `-Ο€ / 2`, the inner product of those vectors is zero. -/ theorem inner_eq_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-Ο€ / 2 : ℝ)) : βŸͺx, y⟫ = 0 := o.eq_zero_or_oangle_eq_iff_inner_eq_zero.1 <| Or.inr <| Or.inr <| Or.inr h /-- If the oriented angle between two vectors is `-Ο€ / 2`, the inner product of those vectors (reversed) is zero. -/ theorem inner_rev_eq_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-Ο€ / 2 : ℝ)) : βŸͺy, x⟫ = 0 := by rw [real_inner_comm, o.inner_eq_zero_of_oangle_eq_neg_pi_div_two h] /-- Negating the first vector passed to `oangle` negates the sign of the angle. -/ @[simp] theorem oangle_sign_neg_left (x y : V) : (o.oangle (-x) y).sign = -(o.oangle x y).sign := by by_cases hx : x = 0; Β· simp [hx] by_cases hy : y = 0; Β· simp [hy] rw [o.oangle_neg_left hx hy, Real.Angle.sign_add_pi] /-- Negating the second vector passed to `oangle` negates the sign of the angle. -/ @[simp] theorem oangle_sign_neg_right (x y : V) : (o.oangle x (-y)).sign = -(o.oangle x y).sign := by by_cases hx : x = 0; Β· simp [hx] by_cases hy : y = 0; Β· simp [hy] rw [o.oangle_neg_right hx hy, Real.Angle.sign_add_pi] /-- Multiplying the first vector passed to `oangle` by a real multiplies the sign of the angle by the sign of the real. -/ @[simp] theorem oangle_sign_smul_left (x y : V) (r : ℝ) : (o.oangle (r β€’ x) y).sign = SignType.sign r * (o.oangle x y).sign := by rcases lt_trichotomy r 0 with (h | h | h) <;> simp [h] /-- Multiplying the second vector passed to `oangle` by a real multiplies the sign of the angle by the sign of the real. -/ @[simp]
theorem oangle_sign_smul_right (x y : V) (r : ℝ) : (o.oangle x (r β€’ y)).sign = SignType.sign r * (o.oangle x y).sign := by rcases lt_trichotomy r 0 with (h | h | h) <;> simp [h] /-- Auxiliary lemma for the proof of `oangle_sign_smul_add_right`; not intended to be used outside of that proof. -/ theorem oangle_smul_add_right_eq_zero_or_eq_pi_iff {x y : V} (r : ℝ) : o.oangle x (r β€’ x + y) = 0 ∨ o.oangle x (r β€’ x + y) = Ο€ ↔ o.oangle x y = 0 ∨ o.oangle x y = Ο€ := by
Mathlib/Geometry/Euclidean/Angle/Oriented/Basic.lean
743
751
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Algebra.ModEq import Mathlib.Algebra.Order.Archimedean.Basic import Mathlib.Algebra.Ring.Periodic import Mathlib.Data.Int.SuccPred import Mathlib.Order.Circular /-! # Reducing to an interval modulo its length This file defines operations that reduce a number (in an `Archimedean` `LinearOrderedAddCommGroup`) to a number in a given interval, modulo the length of that interval. ## Main definitions * `toIcoDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ico a (a + p)`. * `toIcoMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ico a (a + p)`. * `toIocDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ioc a (a + p)`. * `toIocMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ioc a (a + p)`. -/ assert_not_exists TwoSidedIdeal noncomputable section section LinearOrderedAddCommGroup variable {Ξ± : Type*} [AddCommGroup Ξ±] [LinearOrder Ξ±] [IsOrderedAddMonoid Ξ±] [hΞ± : Archimedean Ξ±] {p : Ξ±} (hp : 0 < p) {a b c : Ξ±} {n : β„€} section include hp /-- The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ico a (a + p)`. -/ def toIcoDiv (a b : Ξ±) : β„€ := (existsUnique_sub_zsmul_mem_Ico hp b a).choose theorem sub_toIcoDiv_zsmul_mem_Ico (a b : Ξ±) : b - toIcoDiv hp a b β€’ p ∈ Set.Ico a (a + p) := (existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.1 theorem toIcoDiv_eq_of_sub_zsmul_mem_Ico (h : b - n β€’ p ∈ Set.Ico a (a + p)) : toIcoDiv hp a b = n := ((existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.2 _ h).symm /-- The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ioc a (a + p)`. -/ def toIocDiv (a b : Ξ±) : β„€ := (existsUnique_sub_zsmul_mem_Ioc hp b a).choose theorem sub_toIocDiv_zsmul_mem_Ioc (a b : Ξ±) : b - toIocDiv hp a b β€’ p ∈ Set.Ioc a (a + p) := (existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.1 theorem toIocDiv_eq_of_sub_zsmul_mem_Ioc (h : b - n β€’ p ∈ Set.Ioc a (a + p)) : toIocDiv hp a b = n := ((existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.2 _ h).symm /-- Reduce `b` to the interval `Ico a (a + p)`. -/ def toIcoMod (a b : Ξ±) : Ξ± := b - toIcoDiv hp a b β€’ p /-- Reduce `b` to the interval `Ioc a (a + p)`. -/ def toIocMod (a b : Ξ±) : Ξ± := b - toIocDiv hp a b β€’ p theorem toIcoMod_mem_Ico (a b : Ξ±) : toIcoMod hp a b ∈ Set.Ico a (a + p) := sub_toIcoDiv_zsmul_mem_Ico hp a b theorem toIcoMod_mem_Ico' (b : Ξ±) : toIcoMod hp 0 b ∈ Set.Ico 0 p := by convert toIcoMod_mem_Ico hp 0 b exact (zero_add p).symm theorem toIocMod_mem_Ioc (a b : Ξ±) : toIocMod hp a b ∈ Set.Ioc a (a + p) := sub_toIocDiv_zsmul_mem_Ioc hp a b theorem left_le_toIcoMod (a b : Ξ±) : a ≀ toIcoMod hp a b := (Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).1 theorem left_lt_toIocMod (a b : Ξ±) : a < toIocMod hp a b := (Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).1 theorem toIcoMod_lt_right (a b : Ξ±) : toIcoMod hp a b < a + p := (Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).2 theorem toIocMod_le_right (a b : Ξ±) : toIocMod hp a b ≀ a + p := (Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).2 @[simp] theorem self_sub_toIcoDiv_zsmul (a b : Ξ±) : b - toIcoDiv hp a b β€’ p = toIcoMod hp a b := rfl @[simp] theorem self_sub_toIocDiv_zsmul (a b : Ξ±) : b - toIocDiv hp a b β€’ p = toIocMod hp a b := rfl @[simp] theorem toIcoDiv_zsmul_sub_self (a b : Ξ±) : toIcoDiv hp a b β€’ p - b = -toIcoMod hp a b := by rw [toIcoMod, neg_sub] @[simp] theorem toIocDiv_zsmul_sub_self (a b : Ξ±) : toIocDiv hp a b β€’ p - b = -toIocMod hp a b := by rw [toIocMod, neg_sub] @[simp] theorem toIcoMod_sub_self (a b : Ξ±) : toIcoMod hp a b - b = -toIcoDiv hp a b β€’ p := by rw [toIcoMod, sub_sub_cancel_left, neg_smul] @[simp] theorem toIocMod_sub_self (a b : Ξ±) : toIocMod hp a b - b = -toIocDiv hp a b β€’ p := by rw [toIocMod, sub_sub_cancel_left, neg_smul] @[simp] theorem self_sub_toIcoMod (a b : Ξ±) : b - toIcoMod hp a b = toIcoDiv hp a b β€’ p := by rw [toIcoMod, sub_sub_cancel] @[simp] theorem self_sub_toIocMod (a b : Ξ±) : b - toIocMod hp a b = toIocDiv hp a b β€’ p := by rw [toIocMod, sub_sub_cancel] @[simp] theorem toIcoMod_add_toIcoDiv_zsmul (a b : Ξ±) : toIcoMod hp a b + toIcoDiv hp a b β€’ p = b := by rw [toIcoMod, sub_add_cancel] @[simp] theorem toIocMod_add_toIocDiv_zsmul (a b : Ξ±) : toIocMod hp a b + toIocDiv hp a b β€’ p = b := by rw [toIocMod, sub_add_cancel] @[simp] theorem toIcoDiv_zsmul_sub_toIcoMod (a b : Ξ±) : toIcoDiv hp a b β€’ p + toIcoMod hp a b = b := by rw [add_comm, toIcoMod_add_toIcoDiv_zsmul] @[simp] theorem toIocDiv_zsmul_sub_toIocMod (a b : Ξ±) : toIocDiv hp a b β€’ p + toIocMod hp a b = b := by rw [add_comm, toIocMod_add_toIocDiv_zsmul] theorem toIcoMod_eq_iff : toIcoMod hp a b = c ↔ c ∈ Set.Ico a (a + p) ∧ βˆƒ z : β„€, b = c + z β€’ p := by refine ⟨fun h => ⟨h β–Έ toIcoMod_mem_Ico hp a b, toIcoDiv hp a b, h β–Έ (toIcoMod_add_toIcoDiv_zsmul _ _ _).symm⟩, ?_⟩ simp_rw [← @sub_eq_iff_eq_add] rintro ⟨hc, n, rfl⟩ rw [← toIcoDiv_eq_of_sub_zsmul_mem_Ico hp hc, toIcoMod] theorem toIocMod_eq_iff : toIocMod hp a b = c ↔ c ∈ Set.Ioc a (a + p) ∧ βˆƒ z : β„€, b = c + z β€’ p := by refine ⟨fun h => ⟨h β–Έ toIocMod_mem_Ioc hp a b, toIocDiv hp a b, h β–Έ (toIocMod_add_toIocDiv_zsmul hp _ _).symm⟩, ?_⟩ simp_rw [← @sub_eq_iff_eq_add] rintro ⟨hc, n, rfl⟩ rw [← toIocDiv_eq_of_sub_zsmul_mem_Ioc hp hc, toIocMod] @[simp] theorem toIcoDiv_apply_left (a : Ξ±) : toIcoDiv hp a a = 0 := toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp] @[simp] theorem toIocDiv_apply_left (a : Ξ±) : toIocDiv hp a a = -1 := toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp] @[simp] theorem toIcoMod_apply_left (a : Ξ±) : toIcoMod hp a a = a := by rw [toIcoMod_eq_iff hp, Set.left_mem_Ico] exact ⟨lt_add_of_pos_right _ hp, 0, by simp⟩ @[simp] theorem toIocMod_apply_left (a : Ξ±) : toIocMod hp a a = a + p := by rw [toIocMod_eq_iff hp, Set.right_mem_Ioc] exact ⟨lt_add_of_pos_right _ hp, -1, by simp⟩ theorem toIcoDiv_apply_right (a : Ξ±) : toIcoDiv hp a (a + p) = 1 := toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp] theorem toIocDiv_apply_right (a : Ξ±) : toIocDiv hp a (a + p) = 0 := toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp] theorem toIcoMod_apply_right (a : Ξ±) : toIcoMod hp a (a + p) = a := by rw [toIcoMod_eq_iff hp, Set.left_mem_Ico] exact ⟨lt_add_of_pos_right _ hp, 1, by simp⟩ theorem toIocMod_apply_right (a : Ξ±) : toIocMod hp a (a + p) = a + p := by rw [toIocMod_eq_iff hp, Set.right_mem_Ioc] exact ⟨lt_add_of_pos_right _ hp, 0, by simp⟩ @[simp] theorem toIcoDiv_add_zsmul (a b : Ξ±) (m : β„€) : toIcoDiv hp a (b + m β€’ p) = toIcoDiv hp a b + m := toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIcoDiv_zsmul_mem_Ico hp a b @[simp] theorem toIcoDiv_add_zsmul' (a b : Ξ±) (m : β„€) : toIcoDiv hp (a + m β€’ p) b = toIcoDiv hp a b - m := by refine toIcoDiv_eq_of_sub_zsmul_mem_Ico _ ?_ rw [sub_smul, ← sub_add, add_right_comm] simpa using sub_toIcoDiv_zsmul_mem_Ico hp a b @[simp] theorem toIocDiv_add_zsmul (a b : Ξ±) (m : β„€) : toIocDiv hp a (b + m β€’ p) = toIocDiv hp a b + m := toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIocDiv_zsmul_mem_Ioc hp a b @[simp] theorem toIocDiv_add_zsmul' (a b : Ξ±) (m : β„€) : toIocDiv hp (a + m β€’ p) b = toIocDiv hp a b - m := by refine toIocDiv_eq_of_sub_zsmul_mem_Ioc _ ?_ rw [sub_smul, ← sub_add, add_right_comm] simpa using sub_toIocDiv_zsmul_mem_Ioc hp a b @[simp] theorem toIcoDiv_zsmul_add (a b : Ξ±) (m : β„€) : toIcoDiv hp a (m β€’ p + b) = m + toIcoDiv hp a b := by rw [add_comm, toIcoDiv_add_zsmul, add_comm] /-! Note we omit `toIcoDiv_zsmul_add'` as `-m + toIcoDiv hp a b` is not very convenient. -/ @[simp] theorem toIocDiv_zsmul_add (a b : Ξ±) (m : β„€) : toIocDiv hp a (m β€’ p + b) = m + toIocDiv hp a b := by rw [add_comm, toIocDiv_add_zsmul, add_comm] /-! Note we omit `toIocDiv_zsmul_add'` as `-m + toIocDiv hp a b` is not very convenient. -/ @[simp] theorem toIcoDiv_sub_zsmul (a b : Ξ±) (m : β„€) : toIcoDiv hp a (b - m β€’ p) = toIcoDiv hp a b - m := by rw [sub_eq_add_neg, ← neg_smul, toIcoDiv_add_zsmul, sub_eq_add_neg] @[simp] theorem toIcoDiv_sub_zsmul' (a b : Ξ±) (m : β„€) : toIcoDiv hp (a - m β€’ p) b = toIcoDiv hp a b + m := by rw [sub_eq_add_neg, ← neg_smul, toIcoDiv_add_zsmul', sub_neg_eq_add] @[simp] theorem toIocDiv_sub_zsmul (a b : Ξ±) (m : β„€) : toIocDiv hp a (b - m β€’ p) = toIocDiv hp a b - m := by rw [sub_eq_add_neg, ← neg_smul, toIocDiv_add_zsmul, sub_eq_add_neg] @[simp] theorem toIocDiv_sub_zsmul' (a b : Ξ±) (m : β„€) : toIocDiv hp (a - m β€’ p) b = toIocDiv hp a b + m := by rw [sub_eq_add_neg, ← neg_smul, toIocDiv_add_zsmul', sub_neg_eq_add] @[simp] theorem toIcoDiv_add_right (a b : Ξ±) : toIcoDiv hp a (b + p) = toIcoDiv hp a b + 1 := by simpa only [one_zsmul] using toIcoDiv_add_zsmul hp a b 1 @[simp] theorem toIcoDiv_add_right' (a b : Ξ±) : toIcoDiv hp (a + p) b = toIcoDiv hp a b - 1 := by simpa only [one_zsmul] using toIcoDiv_add_zsmul' hp a b 1 @[simp] theorem toIocDiv_add_right (a b : Ξ±) : toIocDiv hp a (b + p) = toIocDiv hp a b + 1 := by simpa only [one_zsmul] using toIocDiv_add_zsmul hp a b 1 @[simp] theorem toIocDiv_add_right' (a b : Ξ±) : toIocDiv hp (a + p) b = toIocDiv hp a b - 1 := by simpa only [one_zsmul] using toIocDiv_add_zsmul' hp a b 1 @[simp] theorem toIcoDiv_add_left (a b : Ξ±) : toIcoDiv hp a (p + b) = toIcoDiv hp a b + 1 := by rw [add_comm, toIcoDiv_add_right] @[simp] theorem toIcoDiv_add_left' (a b : Ξ±) : toIcoDiv hp (p + a) b = toIcoDiv hp a b - 1 := by rw [add_comm, toIcoDiv_add_right'] @[simp] theorem toIocDiv_add_left (a b : Ξ±) : toIocDiv hp a (p + b) = toIocDiv hp a b + 1 := by rw [add_comm, toIocDiv_add_right] @[simp] theorem toIocDiv_add_left' (a b : Ξ±) : toIocDiv hp (p + a) b = toIocDiv hp a b - 1 := by rw [add_comm, toIocDiv_add_right'] @[simp] theorem toIcoDiv_sub (a b : Ξ±) : toIcoDiv hp a (b - p) = toIcoDiv hp a b - 1 := by simpa only [one_zsmul] using toIcoDiv_sub_zsmul hp a b 1 @[simp] theorem toIcoDiv_sub' (a b : Ξ±) : toIcoDiv hp (a - p) b = toIcoDiv hp a b + 1 := by simpa only [one_zsmul] using toIcoDiv_sub_zsmul' hp a b 1 @[simp] theorem toIocDiv_sub (a b : Ξ±) : toIocDiv hp a (b - p) = toIocDiv hp a b - 1 := by simpa only [one_zsmul] using toIocDiv_sub_zsmul hp a b 1 @[simp] theorem toIocDiv_sub' (a b : Ξ±) : toIocDiv hp (a - p) b = toIocDiv hp a b + 1 := by simpa only [one_zsmul] using toIocDiv_sub_zsmul' hp a b 1 theorem toIcoDiv_sub_eq_toIcoDiv_add (a b c : Ξ±) : toIcoDiv hp a (b - c) = toIcoDiv hp (a + c) b := by apply toIcoDiv_eq_of_sub_zsmul_mem_Ico rw [← sub_right_comm, Set.sub_mem_Ico_iff_left, add_right_comm] exact sub_toIcoDiv_zsmul_mem_Ico hp (a + c) b theorem toIocDiv_sub_eq_toIocDiv_add (a b c : Ξ±) : toIocDiv hp a (b - c) = toIocDiv hp (a + c) b := by apply toIocDiv_eq_of_sub_zsmul_mem_Ioc rw [← sub_right_comm, Set.sub_mem_Ioc_iff_left, add_right_comm] exact sub_toIocDiv_zsmul_mem_Ioc hp (a + c) b theorem toIcoDiv_sub_eq_toIcoDiv_add' (a b c : Ξ±) : toIcoDiv hp (a - c) b = toIcoDiv hp a (b + c) := by rw [← sub_neg_eq_add, toIcoDiv_sub_eq_toIcoDiv_add, sub_eq_add_neg] theorem toIocDiv_sub_eq_toIocDiv_add' (a b c : Ξ±) : toIocDiv hp (a - c) b = toIocDiv hp a (b + c) := by rw [← sub_neg_eq_add, toIocDiv_sub_eq_toIocDiv_add, sub_eq_add_neg] theorem toIcoDiv_neg (a b : Ξ±) : toIcoDiv hp a (-b) = -(toIocDiv hp (-a) b + 1) := by suffices toIcoDiv hp a (-b) = -toIocDiv hp (-(a + p)) b by rwa [neg_add, ← sub_eq_add_neg, toIocDiv_sub_eq_toIocDiv_add', toIocDiv_add_right] at this rw [← neg_eq_iff_eq_neg, eq_comm] apply toIocDiv_eq_of_sub_zsmul_mem_Ioc obtain ⟨hc, ho⟩ := sub_toIcoDiv_zsmul_mem_Ico hp a (-b) rw [← neg_lt_neg_iff, neg_sub' (-b), neg_neg, ← neg_smul] at ho rw [← neg_le_neg_iff, neg_sub' (-b), neg_neg, ← neg_smul] at hc refine ⟨ho, hc.trans_eq ?_⟩ rw [neg_add, neg_add_cancel_right] theorem toIcoDiv_neg' (a b : Ξ±) : toIcoDiv hp (-a) b = -(toIocDiv hp a (-b) + 1) := by simpa only [neg_neg] using toIcoDiv_neg hp (-a) (-b) theorem toIocDiv_neg (a b : Ξ±) : toIocDiv hp a (-b) = -(toIcoDiv hp (-a) b + 1) := by rw [← neg_neg b, toIcoDiv_neg, neg_neg, neg_neg, neg_add', neg_neg, add_sub_cancel_right] theorem toIocDiv_neg' (a b : Ξ±) : toIocDiv hp (-a) b = -(toIcoDiv hp a (-b) + 1) := by simpa only [neg_neg] using toIocDiv_neg hp (-a) (-b) @[simp] theorem toIcoMod_add_zsmul (a b : Ξ±) (m : β„€) : toIcoMod hp a (b + m β€’ p) = toIcoMod hp a b := by rw [toIcoMod, toIcoDiv_add_zsmul, toIcoMod, add_smul] abel @[simp] theorem toIcoMod_add_zsmul' (a b : Ξ±) (m : β„€) : toIcoMod hp (a + m β€’ p) b = toIcoMod hp a b + m β€’ p := by simp only [toIcoMod, toIcoDiv_add_zsmul', sub_smul, sub_add] @[simp] theorem toIocMod_add_zsmul (a b : Ξ±) (m : β„€) : toIocMod hp a (b + m β€’ p) = toIocMod hp a b := by rw [toIocMod, toIocDiv_add_zsmul, toIocMod, add_smul] abel @[simp] theorem toIocMod_add_zsmul' (a b : Ξ±) (m : β„€) : toIocMod hp (a + m β€’ p) b = toIocMod hp a b + m β€’ p := by simp only [toIocMod, toIocDiv_add_zsmul', sub_smul, sub_add] @[simp] theorem toIcoMod_zsmul_add (a b : Ξ±) (m : β„€) : toIcoMod hp a (m β€’ p + b) = toIcoMod hp a b := by rw [add_comm, toIcoMod_add_zsmul] @[simp] theorem toIcoMod_zsmul_add' (a b : Ξ±) (m : β„€) : toIcoMod hp (m β€’ p + a) b = m β€’ p + toIcoMod hp a b := by rw [add_comm, toIcoMod_add_zsmul', add_comm] @[simp] theorem toIocMod_zsmul_add (a b : Ξ±) (m : β„€) : toIocMod hp a (m β€’ p + b) = toIocMod hp a b := by rw [add_comm, toIocMod_add_zsmul] @[simp] theorem toIocMod_zsmul_add' (a b : Ξ±) (m : β„€) : toIocMod hp (m β€’ p + a) b = m β€’ p + toIocMod hp a b := by rw [add_comm, toIocMod_add_zsmul', add_comm] @[simp] theorem toIcoMod_sub_zsmul (a b : Ξ±) (m : β„€) : toIcoMod hp a (b - m β€’ p) = toIcoMod hp a b := by rw [sub_eq_add_neg, ← neg_smul, toIcoMod_add_zsmul] @[simp] theorem toIcoMod_sub_zsmul' (a b : Ξ±) (m : β„€) : toIcoMod hp (a - m β€’ p) b = toIcoMod hp a b - m β€’ p := by simp_rw [sub_eq_add_neg, ← neg_smul, toIcoMod_add_zsmul'] @[simp] theorem toIocMod_sub_zsmul (a b : Ξ±) (m : β„€) : toIocMod hp a (b - m β€’ p) = toIocMod hp a b := by rw [sub_eq_add_neg, ← neg_smul, toIocMod_add_zsmul] @[simp] theorem toIocMod_sub_zsmul' (a b : Ξ±) (m : β„€) : toIocMod hp (a - m β€’ p) b = toIocMod hp a b - m β€’ p := by simp_rw [sub_eq_add_neg, ← neg_smul, toIocMod_add_zsmul'] @[simp] theorem toIcoMod_add_right (a b : Ξ±) : toIcoMod hp a (b + p) = toIcoMod hp a b := by simpa only [one_zsmul] using toIcoMod_add_zsmul hp a b 1 @[simp] theorem toIcoMod_add_right' (a b : Ξ±) : toIcoMod hp (a + p) b = toIcoMod hp a b + p := by simpa only [one_zsmul] using toIcoMod_add_zsmul' hp a b 1 @[simp] theorem toIocMod_add_right (a b : Ξ±) : toIocMod hp a (b + p) = toIocMod hp a b := by simpa only [one_zsmul] using toIocMod_add_zsmul hp a b 1 @[simp] theorem toIocMod_add_right' (a b : Ξ±) : toIocMod hp (a + p) b = toIocMod hp a b + p := by simpa only [one_zsmul] using toIocMod_add_zsmul' hp a b 1 @[simp] theorem toIcoMod_add_left (a b : Ξ±) : toIcoMod hp a (p + b) = toIcoMod hp a b := by rw [add_comm, toIcoMod_add_right] @[simp] theorem toIcoMod_add_left' (a b : Ξ±) : toIcoMod hp (p + a) b = p + toIcoMod hp a b := by rw [add_comm, toIcoMod_add_right', add_comm] @[simp] theorem toIocMod_add_left (a b : Ξ±) : toIocMod hp a (p + b) = toIocMod hp a b := by rw [add_comm, toIocMod_add_right] @[simp] theorem toIocMod_add_left' (a b : Ξ±) : toIocMod hp (p + a) b = p + toIocMod hp a b := by rw [add_comm, toIocMod_add_right', add_comm] @[simp] theorem toIcoMod_sub (a b : Ξ±) : toIcoMod hp a (b - p) = toIcoMod hp a b := by simpa only [one_zsmul] using toIcoMod_sub_zsmul hp a b 1 @[simp] theorem toIcoMod_sub' (a b : Ξ±) : toIcoMod hp (a - p) b = toIcoMod hp a b - p := by simpa only [one_zsmul] using toIcoMod_sub_zsmul' hp a b 1 @[simp] theorem toIocMod_sub (a b : Ξ±) : toIocMod hp a (b - p) = toIocMod hp a b := by simpa only [one_zsmul] using toIocMod_sub_zsmul hp a b 1 @[simp] theorem toIocMod_sub' (a b : Ξ±) : toIocMod hp (a - p) b = toIocMod hp a b - p := by simpa only [one_zsmul] using toIocMod_sub_zsmul' hp a b 1 theorem toIcoMod_sub_eq_sub (a b c : Ξ±) : toIcoMod hp a (b - c) = toIcoMod hp (a + c) b - c := by simp_rw [toIcoMod, toIcoDiv_sub_eq_toIcoDiv_add, sub_right_comm] theorem toIocMod_sub_eq_sub (a b c : Ξ±) : toIocMod hp a (b - c) = toIocMod hp (a + c) b - c := by simp_rw [toIocMod, toIocDiv_sub_eq_toIocDiv_add, sub_right_comm] theorem toIcoMod_add_right_eq_add (a b c : Ξ±) : toIcoMod hp a (b + c) = toIcoMod hp (a - c) b + c := by simp_rw [toIcoMod, toIcoDiv_sub_eq_toIcoDiv_add', sub_add_eq_add_sub] theorem toIocMod_add_right_eq_add (a b c : Ξ±) : toIocMod hp a (b + c) = toIocMod hp (a - c) b + c := by simp_rw [toIocMod, toIocDiv_sub_eq_toIocDiv_add', sub_add_eq_add_sub] theorem toIcoMod_neg (a b : Ξ±) : toIcoMod hp a (-b) = p - toIocMod hp (-a) b := by simp_rw [toIcoMod, toIocMod, toIcoDiv_neg, neg_smul, add_smul] abel theorem toIcoMod_neg' (a b : Ξ±) : toIcoMod hp (-a) b = p - toIocMod hp a (-b) := by simpa only [neg_neg] using toIcoMod_neg hp (-a) (-b) theorem toIocMod_neg (a b : Ξ±) : toIocMod hp a (-b) = p - toIcoMod hp (-a) b := by simp_rw [toIocMod, toIcoMod, toIocDiv_neg, neg_smul, add_smul] abel theorem toIocMod_neg' (a b : Ξ±) : toIocMod hp (-a) b = p - toIcoMod hp a (-b) := by simpa only [neg_neg] using toIocMod_neg hp (-a) (-b) theorem toIcoMod_eq_toIcoMod : toIcoMod hp a b = toIcoMod hp a c ↔ βˆƒ n : β„€, c - b = n β€’ p := by refine ⟨fun h => ⟨toIcoDiv hp a c - toIcoDiv hp a b, ?_⟩, fun h => ?_⟩ Β· conv_lhs => rw [← toIcoMod_add_toIcoDiv_zsmul hp a b, ← toIcoMod_add_toIcoDiv_zsmul hp a c] rw [h, sub_smul] abel Β· rcases h with ⟨z, hz⟩ rw [sub_eq_iff_eq_add] at hz rw [hz, toIcoMod_zsmul_add] theorem toIocMod_eq_toIocMod : toIocMod hp a b = toIocMod hp a c ↔ βˆƒ n : β„€, c - b = n β€’ p := by refine ⟨fun h => ⟨toIocDiv hp a c - toIocDiv hp a b, ?_⟩, fun h => ?_⟩ Β· conv_lhs => rw [← toIocMod_add_toIocDiv_zsmul hp a b, ← toIocMod_add_toIocDiv_zsmul hp a c] rw [h, sub_smul] abel Β· rcases h with ⟨z, hz⟩ rw [sub_eq_iff_eq_add] at hz rw [hz, toIocMod_zsmul_add] /-! ### Links between the `Ico` and `Ioc` variants applied to the same element -/ section IcoIoc namespace AddCommGroup theorem modEq_iff_toIcoMod_eq_left : a ≑ b [PMOD p] ↔ toIcoMod hp a b = a := modEq_iff_eq_add_zsmul.trans ⟨by rintro ⟨n, rfl⟩ rw [toIcoMod_add_zsmul, toIcoMod_apply_left], fun h => ⟨toIcoDiv hp a b, eq_add_of_sub_eq h⟩⟩ theorem modEq_iff_toIocMod_eq_right : a ≑ b [PMOD p] ↔ toIocMod hp a b = a + p := by refine modEq_iff_eq_add_zsmul.trans ⟨?_, fun h => ⟨toIocDiv hp a b + 1, ?_⟩⟩ Β· rintro ⟨z, rfl⟩ rw [toIocMod_add_zsmul, toIocMod_apply_left] Β· rwa [add_one_zsmul, add_left_comm, ← sub_eq_iff_eq_add'] alias ⟨ModEq.toIcoMod_eq_left, _⟩ := modEq_iff_toIcoMod_eq_left alias ⟨ModEq.toIcoMod_eq_right, _⟩ := modEq_iff_toIocMod_eq_right variable (a b) open List in theorem tfae_modEq : TFAE [a ≑ b [PMOD p], βˆ€ z : β„€, b - z β€’ p βˆ‰ Set.Ioo a (a + p), toIcoMod hp a b β‰  toIocMod hp a b, toIcoMod hp a b + p = toIocMod hp a b] := by rw [modEq_iff_toIcoMod_eq_left hp] tfae_have 3 β†’ 2 := by rw [← not_exists, not_imp_not] exact fun ⟨i, hi⟩ => ((toIcoMod_eq_iff hp).2 ⟨Set.Ioo_subset_Ico_self hi, i, (sub_add_cancel b _).symm⟩).trans ((toIocMod_eq_iff hp).2 ⟨Set.Ioo_subset_Ioc_self hi, i, (sub_add_cancel b _).symm⟩).symm tfae_have 4 β†’ 3 | h => by rw [← h, Ne, eq_comm, add_eq_left] exact hp.ne' tfae_have 1 β†’ 4 | h => by rw [h, eq_comm, toIocMod_eq_iff, Set.right_mem_Ioc] refine ⟨lt_add_of_pos_right a hp, toIcoDiv hp a b - 1, ?_⟩ rw [sub_one_zsmul, add_add_add_comm, add_neg_cancel, add_zero] conv_lhs => rw [← toIcoMod_add_toIcoDiv_zsmul hp a b, h] tfae_have 2 β†’ 1 := by rw [← not_exists, not_imp_comm] have h' := toIcoMod_mem_Ico hp a b exact fun h => ⟨_, h'.1.lt_of_ne' h, h'.2⟩ tfae_finish variable {a b} theorem modEq_iff_not_forall_mem_Ioo_mod : a ≑ b [PMOD p] ↔ βˆ€ z : β„€, b - z β€’ p βˆ‰ Set.Ioo a (a + p) := (tfae_modEq hp a b).out 0 1 theorem modEq_iff_toIcoMod_ne_toIocMod : a ≑ b [PMOD p] ↔ toIcoMod hp a b β‰  toIocMod hp a b := (tfae_modEq hp a b).out 0 2 theorem modEq_iff_toIcoMod_add_period_eq_toIocMod : a ≑ b [PMOD p] ↔ toIcoMod hp a b + p = toIocMod hp a b := (tfae_modEq hp a b).out 0 3 theorem not_modEq_iff_toIcoMod_eq_toIocMod : Β¬a ≑ b [PMOD p] ↔ toIcoMod hp a b = toIocMod hp a b := (modEq_iff_toIcoMod_ne_toIocMod _).not_left theorem not_modEq_iff_toIcoDiv_eq_toIocDiv : Β¬a ≑ b [PMOD p] ↔ toIcoDiv hp a b = toIocDiv hp a b := by rw [not_modEq_iff_toIcoMod_eq_toIocMod hp, toIcoMod, toIocMod, sub_right_inj, zsmul_left_inj hp] theorem modEq_iff_toIcoDiv_eq_toIocDiv_add_one : a ≑ b [PMOD p] ↔ toIcoDiv hp a b = toIocDiv hp a b + 1 := by rw [modEq_iff_toIcoMod_add_period_eq_toIocMod hp, toIcoMod, toIocMod, ← eq_sub_iff_add_eq, sub_sub, sub_right_inj, ← add_one_zsmul, zsmul_left_inj hp] end AddCommGroup open AddCommGroup /-- If `a` and `b` fall within the same cycle WRT `c`, then they are congruent modulo `p`. -/ @[simp] theorem toIcoMod_inj {c : Ξ±} : toIcoMod hp c a = toIcoMod hp c b ↔ a ≑ b [PMOD p] := by simp_rw [toIcoMod_eq_toIcoMod, modEq_iff_eq_add_zsmul, sub_eq_iff_eq_add'] alias ⟨_, AddCommGroup.ModEq.toIcoMod_eq_toIcoMod⟩ := toIcoMod_inj theorem Ico_eq_locus_Ioc_eq_iUnion_Ioo : { b | toIcoMod hp a b = toIocMod hp a b } = ⋃ z : β„€, Set.Ioo (a + z β€’ p) (a + p + z β€’ p) := by ext1 simp_rw [Set.mem_setOf, Set.mem_iUnion, ← Set.sub_mem_Ioo_iff_left, ← not_modEq_iff_toIcoMod_eq_toIocMod, modEq_iff_not_forall_mem_Ioo_mod hp, not_forall, Classical.not_not] theorem toIocDiv_wcovBy_toIcoDiv (a b : Ξ±) : toIocDiv hp a b β©Ώ toIcoDiv hp a b := by suffices toIocDiv hp a b = toIcoDiv hp a b ∨ toIocDiv hp a b + 1 = toIcoDiv hp a b by rwa [wcovBy_iff_eq_or_covBy, ← Order.succ_eq_iff_covBy] rw [eq_comm, ← not_modEq_iff_toIcoDiv_eq_toIocDiv, eq_comm, ← modEq_iff_toIcoDiv_eq_toIocDiv_add_one] exact em' _ theorem toIcoMod_le_toIocMod (a b : Ξ±) : toIcoMod hp a b ≀ toIocMod hp a b := by rw [toIcoMod, toIocMod, sub_le_sub_iff_left] exact zsmul_left_mono hp.le (toIocDiv_wcovBy_toIcoDiv _ _ _).le theorem toIocMod_le_toIcoMod_add (a b : Ξ±) : toIocMod hp a b ≀ toIcoMod hp a b + p := by rw [toIcoMod, toIocMod, sub_add, sub_le_sub_iff_left, sub_le_iff_le_add, ← add_one_zsmul, (zsmul_left_strictMono hp).le_iff_le] apply (toIocDiv_wcovBy_toIcoDiv _ _ _).le_succ end IcoIoc open AddCommGroup theorem toIcoMod_eq_self : toIcoMod hp a b = b ↔ b ∈ Set.Ico a (a + p) := by rw [toIcoMod_eq_iff, and_iff_left] exact ⟨0, by simp⟩ theorem toIocMod_eq_self : toIocMod hp a b = b ↔ b ∈ Set.Ioc a (a + p) := by rw [toIocMod_eq_iff, and_iff_left] exact ⟨0, by simp⟩ @[simp] theorem toIcoMod_toIcoMod (a₁ aβ‚‚ b : Ξ±) : toIcoMod hp a₁ (toIcoMod hp aβ‚‚ b) = toIcoMod hp a₁ b := (toIcoMod_eq_toIcoMod _).2 ⟨toIcoDiv hp aβ‚‚ b, self_sub_toIcoMod hp aβ‚‚ b⟩ @[simp] theorem toIcoMod_toIocMod (a₁ aβ‚‚ b : Ξ±) : toIcoMod hp a₁ (toIocMod hp aβ‚‚ b) = toIcoMod hp a₁ b := (toIcoMod_eq_toIcoMod _).2 ⟨toIocDiv hp aβ‚‚ b, self_sub_toIocMod hp aβ‚‚ b⟩ @[simp] theorem toIocMod_toIocMod (a₁ aβ‚‚ b : Ξ±) : toIocMod hp a₁ (toIocMod hp aβ‚‚ b) = toIocMod hp a₁ b := (toIocMod_eq_toIocMod _).2 ⟨toIocDiv hp aβ‚‚ b, self_sub_toIocMod hp aβ‚‚ b⟩ @[simp] theorem toIocMod_toIcoMod (a₁ aβ‚‚ b : Ξ±) : toIocMod hp a₁ (toIcoMod hp aβ‚‚ b) = toIocMod hp a₁ b := (toIocMod_eq_toIocMod _).2 ⟨toIcoDiv hp aβ‚‚ b, self_sub_toIcoMod hp aβ‚‚ b⟩ theorem toIcoMod_periodic (a : Ξ±) : Function.Periodic (toIcoMod hp a) p := toIcoMod_add_right hp a theorem toIocMod_periodic (a : Ξ±) : Function.Periodic (toIocMod hp a) p := toIocMod_add_right hp a -- helper lemmas for when `a = 0` section Zero theorem toIcoMod_zero_sub_comm (a b : Ξ±) : toIcoMod hp 0 (a - b) = p - toIocMod hp 0 (b - a) := by rw [← neg_sub, toIcoMod_neg, neg_zero] theorem toIocMod_zero_sub_comm (a b : Ξ±) : toIocMod hp 0 (a - b) = p - toIcoMod hp 0 (b - a) := by rw [← neg_sub, toIocMod_neg, neg_zero] theorem toIcoDiv_eq_sub (a b : Ξ±) : toIcoDiv hp a b = toIcoDiv hp 0 (b - a) := by rw [toIcoDiv_sub_eq_toIcoDiv_add, zero_add] theorem toIocDiv_eq_sub (a b : Ξ±) : toIocDiv hp a b = toIocDiv hp 0 (b - a) := by rw [toIocDiv_sub_eq_toIocDiv_add, zero_add] theorem toIcoMod_eq_sub (a b : Ξ±) : toIcoMod hp a b = toIcoMod hp 0 (b - a) + a := by rw [toIcoMod_sub_eq_sub, zero_add, sub_add_cancel] theorem toIocMod_eq_sub (a b : Ξ±) : toIocMod hp a b = toIocMod hp 0 (b - a) + a := by rw [toIocMod_sub_eq_sub, zero_add, sub_add_cancel] theorem toIcoMod_add_toIocMod_zero (a b : Ξ±) : toIcoMod hp 0 (a - b) + toIocMod hp 0 (b - a) = p := by rw [toIcoMod_zero_sub_comm, sub_add_cancel] theorem toIocMod_add_toIcoMod_zero (a b : Ξ±) : toIocMod hp 0 (a - b) + toIcoMod hp 0 (b - a) = p := by rw [_root_.add_comm, toIcoMod_add_toIocMod_zero] end Zero /-- `toIcoMod` as an equiv from the quotient. -/ @[simps symm_apply] def QuotientAddGroup.equivIcoMod (a : Ξ±) : Ξ± β§Έ AddSubgroup.zmultiples p ≃ Set.Ico a (a + p) where toFun b := ⟨(toIcoMod_periodic hp a).lift b, QuotientAddGroup.induction_on b <| toIcoMod_mem_Ico hp a⟩ invFun := (↑) right_inv b := Subtype.ext <| (toIcoMod_eq_self hp).mpr b.prop left_inv b := by induction b using QuotientAddGroup.induction_on dsimp rw [QuotientAddGroup.eq_iff_sub_mem, toIcoMod_sub_self] apply AddSubgroup.zsmul_mem_zmultiples @[simp] theorem QuotientAddGroup.equivIcoMod_coe (a b : Ξ±) : QuotientAddGroup.equivIcoMod hp a ↑b = ⟨toIcoMod hp a b, toIcoMod_mem_Ico hp a _⟩ := rfl @[simp] theorem QuotientAddGroup.equivIcoMod_zero (a : Ξ±) : QuotientAddGroup.equivIcoMod hp a 0 = ⟨toIcoMod hp a 0, toIcoMod_mem_Ico hp a _⟩ := rfl /-- `toIocMod` as an equiv from the quotient. -/ @[simps symm_apply] def QuotientAddGroup.equivIocMod (a : Ξ±) : Ξ± β§Έ AddSubgroup.zmultiples p ≃ Set.Ioc a (a + p) where toFun b := ⟨(toIocMod_periodic hp a).lift b, QuotientAddGroup.induction_on b <| toIocMod_mem_Ioc hp a⟩ invFun := (↑) right_inv b := Subtype.ext <| (toIocMod_eq_self hp).mpr b.prop left_inv b := by induction b using QuotientAddGroup.induction_on dsimp rw [QuotientAddGroup.eq_iff_sub_mem, toIocMod_sub_self] apply AddSubgroup.zsmul_mem_zmultiples @[simp] theorem QuotientAddGroup.equivIocMod_coe (a b : Ξ±) : QuotientAddGroup.equivIocMod hp a ↑b = ⟨toIocMod hp a b, toIocMod_mem_Ioc hp a _⟩ := rfl @[simp] theorem QuotientAddGroup.equivIocMod_zero (a : Ξ±) : QuotientAddGroup.equivIocMod hp a 0 = ⟨toIocMod hp a 0, toIocMod_mem_Ioc hp a _⟩ := rfl end /-! ### The circular order structure on `Ξ± β§Έ AddSubgroup.zmultiples p` -/ section Circular open AddCommGroup private theorem toIxxMod_iff (x₁ xβ‚‚ x₃ : Ξ±) : toIcoMod hp x₁ xβ‚‚ ≀ toIocMod hp x₁ x₃ ↔ toIcoMod hp 0 (xβ‚‚ - x₁) + toIcoMod hp 0 (x₁ - x₃) ≀ p := by rw [toIcoMod_eq_sub, toIocMod_eq_sub _ x₁, add_le_add_iff_right, ← neg_sub x₁ x₃, toIocMod_neg, neg_zero, le_sub_iff_add_le] private theorem toIxxMod_cyclic_left {x₁ xβ‚‚ x₃ : Ξ±} (h : toIcoMod hp x₁ xβ‚‚ ≀ toIocMod hp x₁ x₃) : toIcoMod hp xβ‚‚ x₃ ≀ toIocMod hp xβ‚‚ x₁ := by let xβ‚‚' := toIcoMod hp x₁ xβ‚‚ let x₃' := toIcoMod hp xβ‚‚' x₃ have h : xβ‚‚' ≀ toIocMod hp x₁ x₃' := by simpa [x₃'] have h₂₁ : xβ‚‚' < x₁ + p := toIcoMod_lt_right _ _ _ have h₃₂ : x₃' - p < xβ‚‚' := sub_lt_iff_lt_add.2 (toIcoMod_lt_right _ _ _) suffices hequiv : x₃' ≀ toIocMod hp xβ‚‚' x₁ by obtain ⟨z, hd⟩ : βˆƒ z : β„€, xβ‚‚ = xβ‚‚' + z β€’ p := ((toIcoMod_eq_iff hp).1 rfl).2 simpa [hd, toIocMod_add_zsmul', toIcoMod_add_zsmul', add_le_add_iff_right] rcases le_or_lt x₃' (x₁ + p) with h₃₁ | h₁₃ Β· suffices hIoc₂₁ : toIocMod hp xβ‚‚' x₁ = x₁ + p from hIoc₂₁.symm.trans_ge h₃₁ apply (toIocMod_eq_iff hp).2 exact ⟨⟨h₂₁, by simp [xβ‚‚', left_le_toIcoMod]⟩, -1, by simp⟩ have hIoc₁₃ : toIocMod hp x₁ x₃' = x₃' - p := by apply (toIocMod_eq_iff hp).2 exact ⟨⟨lt_sub_iff_add_lt.2 h₁₃, le_of_lt (h₃₂.trans h₂₁)⟩, 1, by simp⟩ have not_h₃₂ := (h.trans hIoc₁₃.le).not_lt contradiction private theorem toIxxMod_antisymm (h₁₂₃ : toIcoMod hp a b ≀ toIocMod hp a c) (h₁₃₂ : toIcoMod hp a c ≀ toIocMod hp a b) : b ≑ a [PMOD p] ∨ c ≑ b [PMOD p] ∨ a ≑ c [PMOD p] := by by_contra! h rw [modEq_comm] at h rw [← (not_modEq_iff_toIcoMod_eq_toIocMod hp).mp h.2.2] at h₁₂₃ rw [← (not_modEq_iff_toIcoMod_eq_toIocMod hp).mp h.1] at h₁₃₂ exact h.2.1 ((toIcoMod_inj _).1 <| h₁₃₂.antisymm h₁₂₃) private theorem toIxxMod_total' (a b c : Ξ±) : toIcoMod hp b a ≀ toIocMod hp b c ∨ toIcoMod hp b c ≀ toIocMod hp b a := by /- an essential ingredient is the lemma saying {a-b} + {b-a} = period if a β‰  b (and = 0 if a = b). Thus if a β‰  b and b β‰  c then ({a-b} + {b-c}) + ({c-b} + {b-a}) = 2 * period, so one of `{a-b} + {b-c}` and `{c-b} + {b-a}` must be `≀ period` -/ have := congr_argβ‚‚ (Β· + Β·) (toIcoMod_add_toIocMod_zero hp a b) (toIcoMod_add_toIocMod_zero hp c b) simp only [add_add_add_comm] at this rw [_root_.add_comm (toIocMod _ _ _), add_add_add_comm, ← two_nsmul] at this replace := min_le_of_add_le_two_nsmul this.le rw [min_le_iff] at this rw [toIxxMod_iff, toIxxMod_iff] refine this.imp (le_trans <| add_le_add_left ?_ _) (le_trans <| add_le_add_left ?_ _) Β· apply toIcoMod_le_toIocMod Β· apply toIcoMod_le_toIocMod private theorem toIxxMod_total (a b c : Ξ±) : toIcoMod hp a b ≀ toIocMod hp a c ∨ toIcoMod hp c b ≀ toIocMod hp c a := (toIxxMod_total' _ _ _ _).imp_right <| toIxxMod_cyclic_left _ private theorem toIxxMod_trans {x₁ xβ‚‚ x₃ xβ‚„ : Ξ±} (h₁₂₃ : toIcoMod hp x₁ xβ‚‚ ≀ toIocMod hp x₁ x₃ ∧ Β¬toIcoMod hp x₃ xβ‚‚ ≀ toIocMod hp x₃ x₁) (h₂₃₄ : toIcoMod hp xβ‚‚ xβ‚„ ≀ toIocMod hp xβ‚‚ x₃ ∧ Β¬toIcoMod hp x₃ xβ‚„ ≀ toIocMod hp x₃ xβ‚‚) : toIcoMod hp x₁ xβ‚„ ≀ toIocMod hp x₁ x₃ ∧ Β¬toIcoMod hp x₃ xβ‚„ ≀ toIocMod hp x₃ x₁ := by constructor Β· suffices h : Β¬x₃ ≑ xβ‚‚ [PMOD p] by have h₁₂₃' := toIxxMod_cyclic_left _ (toIxxMod_cyclic_left _ h₁₂₃.1) have h₂₃₄' := toIxxMod_cyclic_left _ (toIxxMod_cyclic_left _ h₂₃₄.1) rw [(not_modEq_iff_toIcoMod_eq_toIocMod hp).1 h] at h₂₃₄' exact toIxxMod_cyclic_left _ (h₁₂₃'.trans h₂₃₄') by_contra h rw [(modEq_iff_toIcoMod_eq_left hp).1 h] at h₁₂₃ exact h₁₂₃.2 (left_lt_toIocMod _ _ _).le Β· rw [not_le] at h₁₂₃ h₂₃₄ ⊒ exact (h₁₂₃.2.trans_le (toIcoMod_le_toIocMod _ x₃ xβ‚‚)).trans h₂₃₄.2 namespace QuotientAddGroup variable [hp' : Fact (0 < p)] instance : Btw (Ξ± β§Έ AddSubgroup.zmultiples p) where btw x₁ xβ‚‚ x₃ := (equivIcoMod hp'.out 0 (xβ‚‚ - x₁) : Ξ±) ≀ equivIocMod hp'.out 0 (x₃ - x₁) theorem btw_coe_iff' {x₁ xβ‚‚ x₃ : Ξ±} : Btw.btw (x₁ : Ξ± β§Έ AddSubgroup.zmultiples p) xβ‚‚ x₃ ↔ toIcoMod hp'.out 0 (xβ‚‚ - x₁) ≀ toIocMod hp'.out 0 (x₃ - x₁) := Iff.rfl -- maybe harder to use than the primed one? theorem btw_coe_iff {x₁ xβ‚‚ x₃ : Ξ±} : Btw.btw (x₁ : Ξ± β§Έ AddSubgroup.zmultiples p) xβ‚‚ x₃ ↔ toIcoMod hp'.out x₁ xβ‚‚ ≀ toIocMod hp'.out x₁ x₃ := by rw [btw_coe_iff', toIocMod_sub_eq_sub, toIcoMod_sub_eq_sub, zero_add, sub_le_sub_iff_right] instance circularPreorder : CircularPreorder (Ξ± β§Έ AddSubgroup.zmultiples p) where btw_refl x := show _ ≀ _ by simp [sub_self, hp'.out.le] btw_cyclic_left {x₁ xβ‚‚ x₃} h := by induction x₁ using QuotientAddGroup.induction_on induction xβ‚‚ using QuotientAddGroup.induction_on induction x₃ using QuotientAddGroup.induction_on simp_rw [btw_coe_iff] at h ⊒ apply toIxxMod_cyclic_left _ h sbtw := _ sbtw_iff_btw_not_btw := Iff.rfl sbtw_trans_left {x₁ xβ‚‚ x₃ xβ‚„} (h₁₂₃ : _ ∧ _) (h₂₃₄ : _ ∧ _) := show _ ∧ _ by induction x₁ using QuotientAddGroup.induction_on induction xβ‚‚ using QuotientAddGroup.induction_on induction x₃ using QuotientAddGroup.induction_on induction xβ‚„ using QuotientAddGroup.induction_on simp_rw [btw_coe_iff] at h₁₂₃ h₂₃₄ ⊒ apply toIxxMod_trans _ h₁₂₃ h₂₃₄ instance circularOrder : CircularOrder (Ξ± β§Έ AddSubgroup.zmultiples p) := { QuotientAddGroup.circularPreorder with btw_antisymm := fun {x₁ xβ‚‚ x₃} h₁₂₃ h₃₂₁ => by induction x₁ using QuotientAddGroup.induction_on induction xβ‚‚ using QuotientAddGroup.induction_on induction x₃ using QuotientAddGroup.induction_on rw [btw_cyclic] at h₃₂₁ simp_rw [btw_coe_iff] at h₁₂₃ h₃₂₁ simp_rw [← modEq_iff_eq_mod_zmultiples] exact toIxxMod_antisymm _ h₁₂₃ h₃₂₁ btw_total := fun x₁ xβ‚‚ x₃ => by induction x₁ using QuotientAddGroup.induction_on induction xβ‚‚ using QuotientAddGroup.induction_on induction x₃ using QuotientAddGroup.induction_on simp_rw [btw_coe_iff] apply toIxxMod_total } end QuotientAddGroup end Circular end LinearOrderedAddCommGroup /-! ### Connections to `Int.floor` and `Int.fract` -/ section LinearOrderedField variable {Ξ± : Type*} [Field Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] [FloorRing Ξ±] {p : Ξ±} (hp : 0 < p) theorem toIcoDiv_eq_floor (a b : Ξ±) : toIcoDiv hp a b = ⌊(b - a) / pβŒ‹ := by refine toIcoDiv_eq_of_sub_zsmul_mem_Ico hp ?_ rw [Set.mem_Ico, zsmul_eq_mul, ← sub_nonneg, add_comm, sub_right_comm, ← sub_lt_iff_lt_add, sub_right_comm _ _ a] exact ⟨Int.sub_floor_div_mul_nonneg _ hp, Int.sub_floor_div_mul_lt _ hp⟩ theorem toIocDiv_eq_neg_floor (a b : Ξ±) : toIocDiv hp a b = -⌊(a + p - b) / pβŒ‹ := by refine toIocDiv_eq_of_sub_zsmul_mem_Ioc hp ?_ rw [Set.mem_Ioc, zsmul_eq_mul, Int.cast_neg, neg_mul, sub_neg_eq_add, ← sub_nonneg, sub_add_eq_sub_sub] refine ⟨?_, Int.sub_floor_div_mul_nonneg _ hp⟩ rw [← add_lt_add_iff_right p, add_assoc, add_comm b, ← sub_lt_iff_lt_add, add_comm (_ * _), ← sub_lt_iff_lt_add] exact Int.sub_floor_div_mul_lt _ hp theorem toIcoDiv_zero_one (b : Ξ±) : toIcoDiv (zero_lt_one' Ξ±) 0 b = ⌊bβŒ‹ := by simp [toIcoDiv_eq_floor] theorem toIcoMod_eq_add_fract_mul (a b : Ξ±) : toIcoMod hp a b = a + Int.fract ((b - a) / p) * p := by rw [toIcoMod, toIcoDiv_eq_floor, Int.fract] field_simp ring theorem toIcoMod_eq_fract_mul (b : Ξ±) : toIcoMod hp 0 b = Int.fract (b / p) * p := by simp [toIcoMod_eq_add_fract_mul] theorem toIocMod_eq_sub_fract_mul (a b : Ξ±) : toIocMod hp a b = a + p - Int.fract ((a + p - b) / p) * p := by rw [toIocMod, toIocDiv_eq_neg_floor, Int.fract] field_simp ring theorem toIcoMod_zero_one (b : Ξ±) : toIcoMod (zero_lt_one' Ξ±) 0 b = Int.fract b := by simp [toIcoMod_eq_add_fract_mul] end LinearOrderedField /-! ### Lemmas about unions of translates of intervals -/ section Union open Set Int section LinearOrderedAddCommGroup variable {Ξ± : Type*} [AddCommGroup Ξ±] [LinearOrder Ξ±] [IsOrderedAddMonoid Ξ±] [Archimedean Ξ±] {p : Ξ±} (hp : 0 < p) (a : Ξ±) include hp theorem iUnion_Ioc_add_zsmul : ⋃ n : β„€, Ioc (a + n β€’ p) (a + (n + 1) β€’ p) = univ := by refine eq_univ_iff_forall.mpr fun b => mem_iUnion.mpr ?_ rcases sub_toIocDiv_zsmul_mem_Ioc hp a b with ⟨hl, hr⟩ refine ⟨toIocDiv hp a b, ⟨lt_sub_iff_add_lt.mp hl, ?_⟩⟩ rw [add_smul, one_smul, ← add_assoc] convert sub_le_iff_le_add.mp hr using 1; abel theorem iUnion_Ico_add_zsmul : ⋃ n : β„€, Ico (a + n β€’ p) (a + (n + 1) β€’ p) = univ := by refine eq_univ_iff_forall.mpr fun b => mem_iUnion.mpr ?_ rcases sub_toIcoDiv_zsmul_mem_Ico hp a b with ⟨hl, hr⟩ refine ⟨toIcoDiv hp a b, ⟨le_sub_iff_add_le.mp hl, ?_⟩⟩ rw [add_smul, one_smul, ← add_assoc] convert sub_lt_iff_lt_add.mp hr using 1; abel theorem iUnion_Icc_add_zsmul : ⋃ n : β„€, Icc (a + n β€’ p) (a + (n + 1) β€’ p) = univ := by simpa only [iUnion_Ioc_add_zsmul hp a, univ_subset_iff] using iUnion_mono fun n : β„€ => (Ioc_subset_Icc_self : Ioc (a + n β€’ p) (a + (n + 1) β€’ p) βŠ† Icc _ _) theorem iUnion_Ioc_zsmul : ⋃ n : β„€, Ioc (n β€’ p) ((n + 1) β€’ p) = univ := by simpa only [zero_add] using iUnion_Ioc_add_zsmul hp 0 theorem iUnion_Ico_zsmul : ⋃ n : β„€, Ico (n β€’ p) ((n + 1) β€’ p) = univ := by simpa only [zero_add] using iUnion_Ico_add_zsmul hp 0 theorem iUnion_Icc_zsmul : ⋃ n : β„€, Icc (n β€’ p) ((n + 1) β€’ p) = univ := by simpa only [zero_add] using iUnion_Icc_add_zsmul hp 0 end LinearOrderedAddCommGroup section LinearOrderedRing variable {Ξ± : Type*} [Ring Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] [Archimedean Ξ±] (a : Ξ±) theorem iUnion_Ioc_add_intCast : ⋃ n : β„€, Ioc (a + n) (a + n + 1) = Set.univ := by simpa only [zsmul_one, Int.cast_add, Int.cast_one, ← add_assoc] using iUnion_Ioc_add_zsmul zero_lt_one a theorem iUnion_Ico_add_intCast : ⋃ n : β„€, Ico (a + n) (a + n + 1) = Set.univ := by simpa only [zsmul_one, Int.cast_add, Int.cast_one, ← add_assoc] using iUnion_Ico_add_zsmul zero_lt_one a theorem iUnion_Icc_add_intCast : ⋃ n : β„€, Icc (a + n) (a + n + 1) = Set.univ := by simpa only [zsmul_one, Int.cast_add, Int.cast_one, ← add_assoc] using iUnion_Icc_add_zsmul zero_lt_one a variable (Ξ±) theorem iUnion_Ioc_intCast : ⋃ n : β„€, Ioc (n : Ξ±) (n + 1) = Set.univ := by simpa only [zero_add] using iUnion_Ioc_add_intCast (0 : Ξ±) theorem iUnion_Ico_intCast : ⋃ n : β„€, Ico (n : Ξ±) (n + 1) = Set.univ := by simpa only [zero_add] using iUnion_Ico_add_intCast (0 : Ξ±) theorem iUnion_Icc_intCast : ⋃ n : β„€, Icc (n : Ξ±) (n + 1) = Set.univ := by simpa only [zero_add] using iUnion_Icc_add_intCast (0 : Ξ±) end LinearOrderedRing end Union
Mathlib/Algebra/Order/ToIntervalMod.lean
1,058
1,063
/- 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.Algebra.Group.TypeTags.Basic import Mathlib.Data.Fin.VecNotation import Mathlib.Data.Finset.Piecewise import Mathlib.Order.Filter.Cofinite import Mathlib.Order.Filter.Curry import Mathlib.Topology.Constructions.SumProd import Mathlib.Topology.NhdsSet /-! # Constructions of new topological spaces from old ones This file constructs pi types, 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, subspace, quotient space -/ noncomputable section open Topology TopologicalSpace Set Filter Function open scoped Set.Notation universe u v u' v' variable {X : Type u} {Y : Type v} {Z W Ξ΅ ΞΆ : Type*} section Constructions 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 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) instance ULift.topologicalSpace [t : TopologicalSpace X] : TopologicalSpace (ULift.{v, u} X) := t.induced ULift.down /-! ### `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 theorem continuous_toMul : Continuous (toMul : Additive X β†’ X) := continuous_id theorem continuous_ofAdd : Continuous (ofAdd : X β†’ Multiplicative X) := continuous_id theorem continuous_toAdd : Continuous (toAdd : Multiplicative X β†’ X) := continuous_id theorem isOpenMap_ofMul : IsOpenMap (ofMul : X β†’ Additive X) := IsOpenMap.id theorem isOpenMap_toMul : IsOpenMap (toMul : Additive X β†’ X) := IsOpenMap.id theorem isOpenMap_ofAdd : IsOpenMap (ofAdd : X β†’ Multiplicative X) := IsOpenMap.id theorem isOpenMap_toAdd : IsOpenMap (toAdd : Multiplicative X β†’ X) := IsOpenMap.id theorem isClosedMap_ofMul : IsClosedMap (ofMul : X β†’ Additive X) := IsClosedMap.id theorem isClosedMap_toMul : IsClosedMap (toMul : Additive X β†’ X) := IsClosedMap.id theorem isClosedMap_ofAdd : IsClosedMap (ofAdd : X β†’ Multiplicative X) := IsClosedMap.id theorem isClosedMap_toAdd : IsClosedMap (toAdd : Multiplicative X β†’ X) := IsClosedMap.id theorem nhds_ofMul (x : X) : 𝓝 (ofMul x) = map ofMul (𝓝 x) := rfl theorem nhds_ofAdd (x : X) : 𝓝 (ofAdd x) = map ofAdd (𝓝 x) := rfl theorem nhds_toMul (x : Additive X) : 𝓝 x.toMul = map toMul (𝓝 x) := rfl theorem nhds_toAdd (x : Multiplicative X) : 𝓝 x.toAdd = map toAdd (𝓝 x) := rfl end /-! ### Order dual The topology on this type synonym is inherited without change. -/ section variable [TopologicalSpace X] open OrderDual instance OrderDual.instTopologicalSpace : TopologicalSpace Xα΅’α΅ˆ := β€Ή_β€Ί instance OrderDual.instDiscreteTopology [DiscreteTopology X] : DiscreteTopology Xα΅’α΅ˆ := β€Ή_β€Ί theorem continuous_toDual : Continuous (toDual : X β†’ Xα΅’α΅ˆ) := continuous_id theorem continuous_ofDual : Continuous (ofDual : Xα΅’α΅ˆ β†’ X) := continuous_id theorem isOpenMap_toDual : IsOpenMap (toDual : X β†’ Xα΅’α΅ˆ) := IsOpenMap.id theorem isOpenMap_ofDual : IsOpenMap (ofDual : Xα΅’α΅ˆ β†’ X) := IsOpenMap.id theorem isClosedMap_toDual : IsClosedMap (toDual : X β†’ Xα΅’α΅ˆ) := IsClosedMap.id theorem isClosedMap_ofDual : IsClosedMap (ofDual : Xα΅’α΅ˆ β†’ X) := IsClosedMap.id theorem nhds_toDual (x : X) : 𝓝 (toDual x) = map toDual (𝓝 x) := rfl theorem nhds_ofDual (x : X) : 𝓝 (ofDual x) = map ofDual (𝓝 x) := rfl variable [Preorder X] {x : X} instance OrderDual.instNeBotNhdsWithinIoi [(𝓝[<] x).NeBot] : (𝓝[>] toDual x).NeBot := β€Ή_β€Ί instance OrderDual.instNeBotNhdsWithinIio [(𝓝[>] x).NeBot] : (𝓝[<] toDual x).NeBot := β€Ή_β€Ί 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 /-- 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.mk''_surjective.denseRange.dense_image continuous_coinduced_rng H /-- 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.mk''_surjective.denseRange.comp hf continuous_coinduced_rng 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]⟩ 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]⟩ @[simp] lemma comap_nhdsWithin_range {Ξ± Ξ²} [TopologicalSpace Ξ²] (f : Ξ± β†’ Ξ²) (y : Ξ²) : comap f (𝓝[range f] y) = comap f (𝓝 y) := comap_inf_principal_range 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 theorem nhds_subtype (s : Set X) (x : { x // x ∈ s }) : 𝓝 x = comap (↑) (𝓝 (x : X)) := nhds_induced _ x lemma nhds_subtype_eq_comap_nhdsWithin (s : Set X) (x : { x // x ∈ s }) : 𝓝 x = comap (↑) (𝓝[s] (x : X)) := by rw [nhds_subtype, ← comap_nhdsWithin_range, Subtype.range_val] 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] 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] 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] 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] 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 namespace CofiniteTopology /-- The identity equivalence between `` and `CofiniteTopology `. -/ def of : X ≃ CofiniteTopology X := Equiv.refl X 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 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] 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] 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⟩ theorem mem_nhds_iff {x : CofiniteTopology X} {s : Set (CofiniteTopology X)} : s ∈ 𝓝 x ↔ x ∈ s ∧ sᢜ.Finite := by simp [nhds_eq] end CofiniteTopology end Constructions section Prod variable [TopologicalSpace X] [TopologicalSpace Y] theorem MapClusterPt.curry_prodMap {Ξ± Ξ² : Type*} {f : Ξ± β†’ X} {g : Ξ² β†’ Y} {la : Filter Ξ±} {lb : Filter Ξ²} {x : X} {y : Y} (hf : MapClusterPt x la f) (hg : MapClusterPt y lb g) : MapClusterPt (x, y) (la.curry lb) (.map f g) := by rw [mapClusterPt_iff_frequently] at hf hg rw [((𝓝 x).basis_sets.prod_nhds (𝓝 y).basis_sets).mapClusterPt_iff_frequently] rintro ⟨s, t⟩ ⟨hs, ht⟩ rw [frequently_curry_iff] exact (hf s hs).mono fun x hx ↦ (hg t ht).mono fun y hy ↦ ⟨hx, hy⟩ theorem MapClusterPt.prodMap {Ξ± Ξ² : Type*} {f : Ξ± β†’ X} {g : Ξ² β†’ Y} {la : Filter Ξ±} {lb : Filter Ξ²} {x : X} {y : Y} (hf : MapClusterPt x la f) (hg : MapClusterPt y lb g) : MapClusterPt (x, y) (la Γ—Λ’ lb) (.map f g) := (hf.curry_prodMap hg).mono <| map_mono curry_le_prod 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 Subtype variable [TopologicalSpace X] [TopologicalSpace Y] {p : X β†’ Prop} lemma Topology.IsInducing.subtypeVal {t : Set Y} : IsInducing ((↑) : t β†’ Y) := ⟨rfl⟩ @[deprecated (since := "2024-10-28")] alias inducing_subtype_val := IsInducing.subtypeVal lemma Topology.IsInducing.of_codRestrict {f : X β†’ Y} {t : Set Y} (ht : βˆ€ x, f x ∈ t) (h : IsInducing (t.codRestrict f ht)) : IsInducing f := subtypeVal.comp h @[deprecated (since := "2024-10-28")] alias Inducing.of_codRestrict := IsInducing.of_codRestrict lemma Topology.IsEmbedding.subtypeVal : IsEmbedding ((↑) : Subtype p β†’ X) := ⟨.subtypeVal, Subtype.coe_injective⟩ @[deprecated (since := "2024-10-26")] alias embedding_subtype_val := IsEmbedding.subtypeVal theorem Topology.IsClosedEmbedding.subtypeVal (h : IsClosed {a | p a}) : IsClosedEmbedding ((↑) : Subtype p β†’ X) := ⟨.subtypeVal, by rwa [Subtype.range_coe_subtype]⟩ @[continuity, fun_prop] theorem continuous_subtype_val : Continuous (@Subtype.val X p) := continuous_induced_dom theorem Continuous.subtype_val {f : Y β†’ Subtype p} (hf : Continuous f) : Continuous fun x => (f x : X) := continuous_subtype_val.comp hf theorem IsOpen.isOpenEmbedding_subtypeVal {s : Set X} (hs : IsOpen s) : IsOpenEmbedding ((↑) : s β†’ X) := ⟨.subtypeVal, (@Subtype.range_coe _ s).symm β–Έ hs⟩ theorem IsOpen.isOpenMap_subtype_val {s : Set X} (hs : IsOpen s) : IsOpenMap ((↑) : s β†’ X) := hs.isOpenEmbedding_subtypeVal.isOpenMap 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 lemma IsClosed.isClosedEmbedding_subtypeVal {s : Set X} (hs : IsClosed s) : IsClosedEmbedding ((↑) : s β†’ X) := .subtypeVal hs theorem IsClosed.isClosedMap_subtype_val {s : Set X} (hs : IsClosed s) : IsClosedMap ((↑) : s β†’ X) := hs.isClosedEmbedding_subtypeVal.isClosedMap @[continuity, fun_prop] 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 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 _ theorem continuous_inclusion {s t : Set X} (h : s βŠ† t) : Continuous (inclusion h) := continuous_id.subtype_map h theorem continuousAt_subtype_val {p : X β†’ Prop} {x : Subtype p} : ContinuousAt ((↑) : Subtype p β†’ X) x := continuous_subtype_val.continuousAt theorem Subtype.dense_iff {s : Set X} {t : Set s} : Dense t ↔ s βŠ† closure ((↑) '' t) := by rw [IsInducing.subtypeVal.dense_iff, SetCoe.forall] rfl theorem map_nhds_subtype_val {s : Set X} (x : s) : map ((↑) : s β†’ X) (𝓝 x) = 𝓝[s] ↑x := by rw [IsInducing.subtypeVal.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 theorem nhds_subtype_eq_comap {x : X} {h : p x} : 𝓝 (⟨x, h⟩ : Subtype p) = comap (↑) (𝓝 x) := nhds_induced _ _ 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 theorem closure_subtype {x : { a // p a }} {s : Set { a // p a }} : x ∈ closure s ↔ (x : X) ∈ closure (((↑) : _ β†’ X) '' s) := closure_induced @[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 := IsInducing.subtypeVal.continuousAt_iff alias ⟨_, ContinuousAt.codRestrict⟩ := continuousAt_codRestrict_iff 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 _ theorem ContinuousAt.restrictPreimage {f : X β†’ Y} {s : Set Y} {x : f ⁻¹' s} (h : ContinuousAt f x) : ContinuousAt (s.restrictPreimage f) x := h.restrict _ @[continuity, fun_prop] 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 @[continuity, fun_prop] 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, fun_prop] theorem Continuous.restrictPreimage {f : X β†’ Y} {s : Set Y} (h : Continuous f) : Continuous (s.restrictPreimage f) := h.restrict _ lemma Topology.IsEmbedding.restrict {f : X β†’ Y} (hf : IsEmbedding f) {s : Set X} {t : Set Y} (H : s.MapsTo f t) : IsEmbedding H.restrict := .of_comp (hf.continuous.restrict H) continuous_subtype_val (hf.comp .subtypeVal) lemma Topology.IsOpenEmbedding.restrict {f : X β†’ Y} (hf : IsOpenEmbedding f) {s : Set X} {t : Set Y} (H : s.MapsTo f t) (hs : IsOpen s) : IsOpenEmbedding H.restrict := ⟨hf.isEmbedding.restrict H, (by rw [MapsTo.range_restrict] exact continuous_subtype_val.1 _ (hf.isOpenMap _ hs))⟩ theorem Topology.IsInducing.codRestrict {e : X β†’ Y} (he : IsInducing e) {s : Set Y} (hs : βˆ€ x, e x ∈ s) : IsInducing (codRestrict e s hs) := he.of_comp (he.continuous.codRestrict hs) continuous_subtype_val @[deprecated (since := "2024-10-28")] alias Inducing.codRestrict := IsInducing.codRestrict protected lemma Topology.IsEmbedding.codRestrict {e : X β†’ Y} (he : IsEmbedding e) (s : Set Y) (hs : βˆ€ x, e x ∈ s) : IsEmbedding (codRestrict e s hs) := he.of_comp (he.continuous.codRestrict hs) continuous_subtype_val @[deprecated (since := "2024-10-26")] alias Embedding.codRestrict := IsEmbedding.codRestrict variable {s t : Set X} protected lemma Topology.IsEmbedding.inclusion (h : s βŠ† t) : IsEmbedding (inclusion h) := IsEmbedding.subtypeVal.codRestrict _ _ protected lemma Topology.IsOpenEmbedding.inclusion (hst : s βŠ† t) (hs : IsOpen (t β†“βˆ© s)) : IsOpenEmbedding (inclusion hst) where toIsEmbedding := .inclusion _ isOpen_range := by rwa [range_inclusion] protected lemma Topology.IsClosedEmbedding.inclusion (hst : s βŠ† t) (hs : IsClosed (t β†“βˆ© s)) : IsClosedEmbedding (inclusion hst) where toIsEmbedding := .inclusion _ isClosed_range := by rwa [range_inclusion] @[deprecated (since := "2024-10-26")] alias embedding_inclusion := IsEmbedding.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 := (IsEmbedding.inclusion ts).discreteTopology /-- 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) /-- If `f : X β†’ Y` is a quotient map, then its restriction to the preimage of an open set is a quotient map too. -/ theorem Topology.IsQuotientMap.restrictPreimage_isOpen {f : X β†’ Y} (hf : IsQuotientMap f) {s : Set Y} (hs : IsOpen s) : IsQuotientMap (s.restrictPreimage f) := by refine isQuotientMap_iff.2 ⟨hf.surjective.restrictPreimage _, fun U ↦ ?_⟩ rw [hs.isOpenEmbedding_subtypeVal.isOpen_iff_image_isOpen, ← hf.isOpen_preimage, (hs.preimage hf.continuous).isOpenEmbedding_subtypeVal.isOpen_iff_image_isOpen, image_val_preimage_restrictPreimage] @[deprecated (since := "2024-10-22")] alias QuotientMap.restrictPreimage_isOpen := IsQuotientMap.restrictPreimage_isOpen open scoped Set.Notation in lemma isClosed_preimage_val {s t : Set X} : IsClosed (s β†“βˆ© t) ↔ s ∩ closure (s ∩ t) βŠ† t := by rw [← closure_eq_iff_isClosed, IsEmbedding.subtypeVal.closure_eq_preimage_closure_image, ← Subtype.val_injective.image_injective.eq_iff, Subtype.image_preimage_coe, Subtype.image_preimage_coe, subset_antisymm_iff, and_iff_left, Set.subset_inter_iff, and_iff_right] exacts [Set.inter_subset_left, Set.subset_inter Set.inter_subset_left subset_closure] theorem frontier_inter_open_inter {s t : Set X} (ht : IsOpen t) : frontier (s ∩ t) ∩ t = frontier s ∩ t := by simp only [Set.inter_comm _ t, ← Subtype.preimage_coe_eq_preimage_coe_iff, ht.isOpenMap_subtype_val.preimage_frontier_eq_frontier_preimage continuous_subtype_val, Subtype.preimage_coe_self_inter] section SetNotation open scoped Set.Notation lemma IsOpen.preimage_val {s t : Set X} (ht : IsOpen t) : IsOpen (s β†“βˆ© t) := ht.preimage continuous_subtype_val lemma IsClosed.preimage_val {s t : Set X} (ht : IsClosed t) : IsClosed (s β†“βˆ© t) := ht.preimage continuous_subtype_val @[simp] lemma IsOpen.inter_preimage_val_iff {s t : Set X} (hs : IsOpen s) : IsOpen (s β†“βˆ© t) ↔ IsOpen (s ∩ t) := ⟨fun h ↦ by simpa using hs.isOpenMap_subtype_val _ h, fun h ↦ (Subtype.preimage_coe_self_inter _ _).symm β–Έ h.preimage_val⟩ @[simp] lemma IsClosed.inter_preimage_val_iff {s t : Set X} (hs : IsClosed s) : IsClosed (s β†“βˆ© t) ↔ IsClosed (s ∩ t) := ⟨fun h ↦ by simpa using hs.isClosedMap_subtype_val _ h, fun h ↦ (Subtype.preimage_coe_self_inter _ _).symm β–Έ h.preimage_val⟩ end SetNotation end Subtype section Quotient variable [TopologicalSpace X] [TopologicalSpace Y] variable {r : X β†’ X β†’ Prop} {s : Setoid X} theorem isQuotientMap_quot_mk : IsQuotientMap (@Quot.mk X r) := ⟨Quot.exists_rep, rfl⟩ @[deprecated (since := "2024-10-22")] alias quotientMap_quot_mk := isQuotientMap_quot_mk @[continuity, fun_prop] theorem continuous_quot_mk : Continuous (@Quot.mk X r) := continuous_coinduced_rng @[continuity, fun_prop] 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 theorem isQuotientMap_quotient_mk' : IsQuotientMap (@Quotient.mk' X s) := isQuotientMap_quot_mk @[deprecated (since := "2024-10-22")] alias quotientMap_quotient_mk' := isQuotientMap_quotient_mk' theorem continuous_quotient_mk' : Continuous (@Quotient.mk' X s) := continuous_coinduced_rng 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 theorem Continuous.quotient_liftOn' {f : X β†’ Y} (h : Continuous f) (hs : βˆ€ a b, s a b β†’ f a = f b) : Continuous (fun x => Quotient.liftOn' x f hs : Quotient s β†’ Y) := h.quotient_lift hs open scoped Relator in @[continuity, fun_prop] 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 _ 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_def] @[continuity, fun_prop] theorem continuous_pi (h : βˆ€ i, Continuous fun a => f a i) : Continuous f := continuous_pi_iff.2 h @[continuity, fun_prop] theorem continuous_apply (i : ΞΉ) : Continuous fun p : βˆ€ i, Ο€ i => p i := continuous_iInf_dom continuous_induced_dom @[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) theorem continuousAt_apply (i : ΞΉ) (x : βˆ€ i, Ο€ i) : ContinuousAt (fun p : βˆ€ i, Ο€ i => p i) x := (continuous_apply i).continuousAt 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 @[fun_prop] protected theorem Continuous.piMap {Y : ΞΉ β†’ Type*} [βˆ€ i, TopologicalSpace (Y i)] {f : βˆ€ i, Ο€ i β†’ Y i} (hf : βˆ€ i, Continuous (f i)) : Continuous (Pi.map f) := continuous_pi fun i ↦ (hf i).comp (continuous_apply i) theorem nhds_pi {a : βˆ€ i, Ο€ i} : 𝓝 a = pi fun i => 𝓝 (a i) := by simp only [nhds_iInf, nhds_induced, Filter.pi] protected theorem IsOpenMap.piMap {Y : ΞΉ β†’ Type*} [βˆ€ i, TopologicalSpace (Y i)] {f : βˆ€ i, Ο€ i β†’ Y i} (hfo : βˆ€ i, IsOpenMap (f i)) (hsurj : βˆ€αΆ  i in cofinite, Surjective (f i)) : IsOpenMap (Pi.map f) := by refine IsOpenMap.of_nhds_le fun x ↦ ?_ rw [nhds_pi, nhds_pi, map_piMap_pi hsurj] exact Filter.pi_mono fun i ↦ (hfo i).nhds_le _ protected theorem IsOpenQuotientMap.piMap {Y : ΞΉ β†’ Type*} [βˆ€ i, TopologicalSpace (Y i)] {f : βˆ€ i, Ο€ i β†’ Y i} (hf : βˆ€ i, IsOpenQuotientMap (f i)) : IsOpenQuotientMap (Pi.map f) := ⟨.piMap fun i ↦ (hf i).1, .piMap fun i ↦ (hf i).2, .piMap (fun i ↦ (hf i).3) <| .of_forall fun i ↦ (hf i).1⟩ 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] theorem continuousAt_pi {f : X β†’ βˆ€ i, Ο€ i} {x : X} : ContinuousAt f x ↔ βˆ€ i, ContinuousAt (fun y => f y i) x := tendsto_pi_nhds @[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 @[fun_prop] protected theorem ContinuousAt.piMap {Y : ΞΉ β†’ Type*} [βˆ€ i, TopologicalSpace (Y i)] {f : βˆ€ i, Ο€ i β†’ Y i} {x : βˆ€ i, Ο€ i} (hf : βˆ€ i, ContinuousAt (f i) (x i)) : ContinuousAt (Pi.map f) x := continuousAt_pi.2 fun i ↦ (hf i).comp (continuousAt_apply i x) 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_def] lemma Pi.induced_precomp [TopologicalSpace Y] {ΞΉ' : Type*} (Ο† : ΞΉ' β†’ ΞΉ) : induced (Β· ∘ Ο†) Pi.topologicalSpace = β¨… i', induced (eval (Ο† i')) β€ΉTopologicalSpace Yβ€Ί := induced_precomp' Ο† @[continuity, fun_prop] lemma Pi.continuous_restrict (S : Set ΞΉ) : Continuous (S.restrict : (βˆ€ i : ΞΉ, Ο€ i) β†’ (βˆ€ i : S, Ο€ i)) := Pi.continuous_precomp' ((↑) : S β†’ ΞΉ) @[continuity, fun_prop] lemma Pi.continuous_restrictβ‚‚ {s t : Set ΞΉ} (hst : s βŠ† t) : Continuous (restrictβ‚‚ (Ο€ := Ο€) hst) := continuous_pi fun _ ↦ continuous_apply _ @[continuity, fun_prop] theorem Finset.continuous_restrict (s : Finset ΞΉ) : Continuous (s.restrict (Ο€ := Ο€)) := continuous_pi fun _ ↦ continuous_apply _ @[continuity, fun_prop] theorem Finset.continuous_restrictβ‚‚ {s t : Finset ΞΉ} (hst : s βŠ† t) : Continuous (Finset.restrictβ‚‚ (Ο€ := Ο€) hst) := continuous_pi fun _ ↦ continuous_apply _ variable [TopologicalSpace Z] @[continuity, fun_prop] theorem Pi.continuous_restrict_apply (s : Set X) {f : X β†’ Z} (hf : Continuous f) : Continuous (s.restrict f) := hf.comp continuous_subtype_val @[continuity, fun_prop] theorem Pi.continuous_restrictβ‚‚_apply {s t : Set X} (hst : s βŠ† t) {f : t β†’ Z} (hf : Continuous f) : Continuous (restrictβ‚‚ (Ο€ := fun _ ↦ Z) hst f) := hf.comp (continuous_inclusion hst) @[continuity, fun_prop] theorem Finset.continuous_restrict_apply (s : Finset X) {f : X β†’ Z} (hf : Continuous f) : Continuous (s.restrict f) := hf.comp continuous_subtype_val @[continuity, fun_prop] theorem Finset.continuous_restrictβ‚‚_apply {s t : Finset X} (hst : s βŠ† t) {f : t β†’ Z} (hf : Continuous f) : Continuous (restrictβ‚‚ (Ο€ := fun _ ↦ Z) hst f) := hf.comp (continuous_inclusion hst) lemma Pi.induced_restrict (S : Set ΞΉ) : induced (S.restrict) Pi.topologicalSpace = β¨… i ∈ S, induced (eval i) (T i) := by simp +unfoldPartialApp [← 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] 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 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 /-- `Function.update f i x` is continuous in `(f, x)`. -/ @[continuity, fun_prop] theorem continuous_update [DecidableEq ΞΉ] (i : ΞΉ) : Continuous fun f : (βˆ€ j, Ο€ j) Γ— Ο€ i => update f.1 i f.2 := continuous_fst.update i continuous_snd /-- `Pi.mulSingle i x` is continuous in `x`. -/ @[to_additive (attr := continuity) "`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 section Fin variable {n : β„•} {Ο€ : Fin (n + 1) β†’ Type*} [βˆ€ i, TopologicalSpace (Ο€ i)] theorem Filter.Tendsto.finCons {f : Y β†’ Ο€ 0} {g : Y β†’ βˆ€ j : Fin n, Ο€ j.succ} {l : Filter Y} {x : Ο€ 0} {y : βˆ€ j, Ο€ (Fin.succ j)} (hf : Tendsto f l (𝓝 x)) (hg : Tendsto g l (𝓝 y)) : Tendsto (fun a => Fin.cons (f a) (g a)) l (𝓝 <| Fin.cons x y) := tendsto_pi_nhds.2 fun j => Fin.cases (by simpa) (by simpa using tendsto_pi_nhds.1 hg) j theorem ContinuousAt.finCons {f : X β†’ Ο€ 0} {g : X β†’ βˆ€ j : Fin n, Ο€ (Fin.succ j)} {x : X} (hf : ContinuousAt f x) (hg : ContinuousAt g x) : ContinuousAt (fun a => Fin.cons (f a) (g a)) x := hf.tendsto.finCons hg theorem Continuous.finCons {f : X β†’ Ο€ 0} {g : X β†’ βˆ€ j : Fin n, Ο€ (Fin.succ j)} (hf : Continuous f) (hg : Continuous g) : Continuous fun a => Fin.cons (f a) (g a) := continuous_iff_continuousAt.2 fun _ => hf.continuousAt.finCons hg.continuousAt theorem Filter.Tendsto.matrixVecCons {f : Y β†’ Z} {g : Y β†’ Fin n β†’ Z} {l : Filter Y} {x : Z} {y : Fin n β†’ Z} (hf : Tendsto f l (𝓝 x)) (hg : Tendsto g l (𝓝 y)) : Tendsto (fun a => Matrix.vecCons (f a) (g a)) l (𝓝 <| Matrix.vecCons x y) := hf.finCons hg theorem ContinuousAt.matrixVecCons {f : X β†’ Z} {g : X β†’ Fin n β†’ Z} {x : X} (hf : ContinuousAt f x) (hg : ContinuousAt g x) : ContinuousAt (fun a => Matrix.vecCons (f a) (g a)) x := hf.finCons hg theorem Continuous.matrixVecCons {f : X β†’ Z} {g : X β†’ Fin n β†’ Z} (hf : Continuous f) (hg : Continuous g) : Continuous fun a => Matrix.vecCons (f a) (g a) := hf.finCons hg theorem Filter.Tendsto.finSnoc {f : Y β†’ βˆ€ j : Fin n, Ο€ j.castSucc} {g : Y β†’ Ο€ (Fin.last _)} {l : Filter Y} {x : βˆ€ j, Ο€ (Fin.castSucc j)} {y : Ο€ (Fin.last _)} (hf : Tendsto f l (𝓝 x)) (hg : Tendsto g l (𝓝 y)) : Tendsto (fun a => Fin.snoc (f a) (g a)) l (𝓝 <| Fin.snoc x y) := tendsto_pi_nhds.2 fun j => Fin.lastCases (by simpa) (by simpa using tendsto_pi_nhds.1 hf) j theorem ContinuousAt.finSnoc {f : X β†’ βˆ€ j : Fin n, Ο€ j.castSucc} {g : X β†’ Ο€ (Fin.last _)} {x : X} (hf : ContinuousAt f x) (hg : ContinuousAt g x) : ContinuousAt (fun a => Fin.snoc (f a) (g a)) x := hf.tendsto.finSnoc hg theorem Continuous.finSnoc {f : X β†’ βˆ€ j : Fin n, Ο€ j.castSucc} {g : X β†’ Ο€ (Fin.last _)} (hf : Continuous f) (hg : Continuous g) : Continuous fun a => Fin.snoc (f a) (g a) := continuous_iff_continuousAt.2 fun _ => hf.continuousAt.finSnoc hg.continuousAt theorem Filter.Tendsto.finInsertNth (i : Fin (n + 1)) {f : Y β†’ Ο€ i} {g : Y β†’ βˆ€ j : Fin n, Ο€ (i.succAbove j)} {l : Filter Y} {x : Ο€ i} {y : βˆ€ j, Ο€ (i.succAbove j)} (hf : Tendsto f l (𝓝 x)) (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 @[deprecated (since := "2025-01-02")] alias Filter.Tendsto.fin_insertNth := Filter.Tendsto.finInsertNth theorem ContinuousAt.finInsertNth (i : Fin (n + 1)) {f : X β†’ Ο€ i} {g : X β†’ βˆ€ j : Fin n, Ο€ (i.succAbove j)} {x : X} (hf : ContinuousAt f x) (hg : ContinuousAt g x) : ContinuousAt (fun a => i.insertNth (f a) (g a)) x := hf.tendsto.finInsertNth i hg @[deprecated (since := "2025-01-02")] alias ContinuousAt.fin_insertNth := ContinuousAt.finInsertNth theorem Continuous.finInsertNth (i : Fin (n + 1)) {f : X β†’ Ο€ i} {g : X β†’ βˆ€ j : Fin n, Ο€ (i.succAbove j)} (hf : Continuous f) (hg : Continuous g) : Continuous fun a => i.insertNth (f a) (g a) := continuous_iff_continuousAt.2 fun _ => hf.continuousAt.finInsertNth i hg.continuousAt @[deprecated (since := "2025-01-02")] alias Continuous.fin_insertNth := Continuous.finInsertNth theorem Filter.Tendsto.finInit {f : Y β†’ βˆ€ j : Fin (n + 1), Ο€ j} {l : Filter Y} {x : βˆ€ j, Ο€ j} (hg : Tendsto f l (𝓝 x)) : Tendsto (fun a ↦ Fin.init (f a)) l (𝓝 <| Fin.init x) := tendsto_pi_nhds.2 fun j ↦ apply_nhds hg j.castSucc @[fun_prop] theorem ContinuousAt.finInit {f : X β†’ βˆ€ j : Fin (n + 1), Ο€ j} {x : X} (hf : ContinuousAt f x) : ContinuousAt (fun a ↦ Fin.init (f a)) x := hf.tendsto.finInit @[fun_prop] theorem Continuous.finInit {f : X β†’ βˆ€ j : Fin (n + 1), Ο€ j} (hf : Continuous f) : Continuous fun a ↦ Fin.init (f a) := continuous_iff_continuousAt.2 fun _ ↦ hf.continuousAt.finInit theorem Filter.Tendsto.finTail {f : Y β†’ βˆ€ j : Fin (n + 1), Ο€ j} {l : Filter Y} {x : βˆ€ j, Ο€ j} (hg : Tendsto f l (𝓝 x)) : Tendsto (fun a ↦ Fin.tail (f a)) l (𝓝 <| Fin.tail x) := tendsto_pi_nhds.2 fun j ↦ apply_nhds hg j.succ @[fun_prop] theorem ContinuousAt.finTail {f : X β†’ βˆ€ j : Fin (n + 1), Ο€ j} {x : X} (hf : ContinuousAt f x) : ContinuousAt (fun a ↦ Fin.tail (f a)) x := hf.tendsto.finTail @[fun_prop] theorem Continuous.finTail {f : X β†’ βˆ€ j : Fin (n + 1), Ο€ j} (hf : Continuous f) : Continuous fun a ↦ Fin.tail (f a) := continuous_iff_continuousAt.2 fun _ ↦ hf.continuousAt.finTail end Fin 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 _) 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⟩⟩ classical 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] 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]⟩⟩ 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 _) 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 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) 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] 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] 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) 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)) Β· classical 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] 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 _ => generateFrom { s | IsOpen s } := by simp only [generateFrom_setOf_isOpen] _ = _ := pi_generateFrom_eq 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⟩⟩ classical rw [← univ_pi_piecewise] refine GenerateOpen.basic _ ⟨_, fun a => ?_, rfl⟩ by_cases a ∈ i <;> simp [*] 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_def] /-- 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) : @IsInducing X (βˆ€ i, Ο€ i) (β¨… i, induced (f i) inferInstance) _ fun x i => f i x := letI := β¨… i, induced (f i) inferInstance; ⟨(induced_to_pi _).symm⟩ 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}) end Pi section Sigma variable {ΞΉ ΞΊ : Type*} {Οƒ : ΞΉ β†’ Type*} {Ο„ : ΞΊ β†’ Type*} [βˆ€ i, TopologicalSpace (Οƒ i)] [βˆ€ k, TopologicalSpace (Ο„ k)] [TopologicalSpace X] @[continuity, fun_prop] theorem continuous_sigmaMk {i : ΞΉ} : Continuous (@Sigma.mk ΞΉ Οƒ i) := continuous_iSup_rng continuous_coinduced_rng theorem isOpen_sigma_iff {s : Set (Sigma Οƒ)} : IsOpen s ↔ βˆ€ i, IsOpen (Sigma.mk i ⁻¹' s) := by rw [isOpen_iSup_iff] rfl 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] 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 theorem isOpen_range_sigmaMk {i : ΞΉ} : IsOpen (range (@Sigma.mk ΞΉ Οƒ i)) := isOpenMap_sigmaMk.isOpen_range 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 theorem isClosed_range_sigmaMk {i : ΞΉ} : IsClosed (range (@Sigma.mk ΞΉ Οƒ i)) := isClosedMap_sigmaMk.isClosed_range lemma Topology.IsOpenEmbedding.sigmaMk {i : ΞΉ} : IsOpenEmbedding (@Sigma.mk ΞΉ Οƒ i) := .of_continuous_injective_isOpenMap continuous_sigmaMk sigma_mk_injective isOpenMap_sigmaMk @[deprecated (since := "2024-10-30")] alias isOpenEmbedding_sigmaMk := IsOpenEmbedding.sigmaMk lemma Topology.IsClosedEmbedding.sigmaMk {i : ΞΉ} : IsClosedEmbedding (@Sigma.mk ΞΉ Οƒ i) := .of_continuous_injective_isClosedMap continuous_sigmaMk sigma_mk_injective isClosedMap_sigmaMk @[deprecated (since := "2024-10-30")] alias isClosedEmbedding_sigmaMk := IsClosedEmbedding.sigmaMk lemma Topology.IsEmbedding.sigmaMk {i : ΞΉ} : IsEmbedding (@Sigma.mk ΞΉ Οƒ i) := IsClosedEmbedding.sigmaMk.1 @[deprecated (since := "2024-10-26")] alias embedding_sigmaMk := IsEmbedding.sigmaMk
theorem Sigma.nhds_mk (i : ΞΉ) (x : Οƒ i) : 𝓝 (⟨i, x⟩ : Sigma Οƒ) = Filter.map (Sigma.mk i) (𝓝 x) := (IsOpenEmbedding.sigmaMk.map_nhds_eq x).symm
Mathlib/Topology/Constructions.lean
1,052
1,054
/- Copyright (c) 2021 David WΓ€rn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WΓ€rn -/ import Mathlib.Data.Fintype.Option import Mathlib.Data.Fintype.Shrink import Mathlib.Data.Fintype.Sum import Mathlib.Data.Finite.Prod import Mathlib.Algebra.BigOperators.Group.Finset.Basic /-! # The Hales-Jewett theorem We prove the Hales-Jewett theorem. We deduce Van der Waerden's theorem and the multidimensional Hales-Jewett theorem as corollaries. The Hales-Jewett theorem is a result in Ramsey theory dealing with *combinatorial lines*. Given an 'alphabet' `Ξ± : Type*` and `a b : Ξ±`, an example of a combinatorial line in `Ξ±^5` is `{ (a, x, x, b, x) | x : Ξ± }`. See `Combinatorics.Line` for a precise general definition. The Hales-Jewett theorem states that for any fixed finite types `Ξ±` and `ΞΊ`, there exists a (potentially huge) finite type `ΞΉ` such that whenever `ΞΉ β†’ Ξ±` is `ΞΊ`-colored (i.e. for any coloring `C : (ΞΉ β†’ Ξ±) β†’ ΞΊ`), there exists a monochromatic line. We prove the Hales-Jewett theorem using the idea of *color focusing* and a *product argument*. See the proof of `Combinatorics.Line.exists_mono_in_high_dimension'` for details. *Combinatorial subspaces* are higher-dimensional analogues of combinatorial lines. See `Combinatorics.Subspace`. The multidimensional Hales-Jewett theorem generalises the statement above from combinatorial lines to combinatorial subspaces of a fixed dimension. The version of Van der Waerden's theorem in this file states that whenever a commutative monoid `M` is finitely colored and `S` is a finite subset, there exists a monochromatic homothetic copy of `S`. This follows from the Hales-Jewett theorem by considering the map `(ΞΉ β†’ S) β†’ M` sending `v` to `βˆ‘ i : ΞΉ, v i`, which sends a combinatorial line to a homothetic copy of `S`. ## Main results - `Combinatorics.Line.exists_mono_in_high_dimension`: The Hales-Jewett theorem. - `Combinatorics.Subspace.exists_mono_in_high_dimension`: The multidimensional Hales-Jewett theorem. - `Combinatorics.exists_mono_homothetic_copy`: A generalization of Van der Waerden's theorem. ## Implementation details For convenience, we work directly with finite types instead of natural numbers. That is, we write `Ξ±, ΞΉ, ΞΊ` for (finite) types where one might traditionally use natural numbers `n, H, c`. This allows us to work directly with `Ξ±`, `Option Ξ±`, `(ΞΉ β†’ Ξ±) β†’ ΞΊ`, and `ΞΉ βŠ• ΞΉ'` instead of `Fin n`, `Fin (n+1)`, `Fin (c^(n^H))`, and `Fin (H + H')`. ## TODO - Prove a finitary version of Van der Waerden's theorem (either by compactness or by modifying the current proof). - One could reformulate the proof of Hales-Jewett to give explicit upper bounds on the number of coordinates needed. ## Tags combinatorial line, Ramsey theory, arithmetic progression ### References * https://en.wikipedia.org/wiki/Hales%E2%80%93Jewett_theorem -/ open Function open scoped Finset universe u v variable {Ξ· Ξ± ΞΉ ΞΊ : Type*} namespace Combinatorics /-- The type of combinatorial subspaces. A subspace `l : Subspace Ξ· Ξ± ΞΉ` in the hypercube `ΞΉ β†’ Ξ±` defines a function `(Ξ· β†’ Ξ±) β†’ ΞΉ β†’ Ξ±` from `Ξ· β†’ Ξ±` to the hypercube, such that for each coordinate `i : ΞΉ` and direction `e : Ξ·`, the function `fun x ↦ l x i` is either `fun x ↦ x e` for some direction `e : Ξ·` or constant. We require subspaces to be non-degenerate in the sense that, for every `e : Ξ·`, `fun x ↦ l x i` is `fun x ↦ x e` for at least one `i`. Formally, a subspace is represented by a word `l.idxFun : ΞΉ β†’ Ξ± βŠ• Ξ·` which says whether `fun x ↦ l x i` is `fun x ↦ x e` (corresponding to `l.idxFun i = Sum.inr e`) or constantly `a` (corresponding to `l.idxFun i = Sum.inl a`). When `Ξ±` has size `1` there can be many elements of `Subspace Ξ· Ξ± ΞΉ` defining the same function. -/ @[ext] structure Subspace (Ξ· Ξ± ΞΉ : Type*) where /-- The word representing a combinatorial subspace. `l.idxfun i = Sum.inr e` means that `l x i = x e` for all `x` and `l.idxfun i = some a` means that `l x i = a` for all `x`. -/ idxFun : ΞΉ β†’ Ξ± βŠ• Ξ· /-- We require combinatorial subspaces to be nontrivial in the sense that `fun x ↦ l x i` is `fun x ↦ x e` for at least one coordinate `i`. -/ proper : βˆ€ e, βˆƒ i, idxFun i = Sum.inr e namespace Subspace variable {Ξ· Ξ± ΞΉ ΞΊ : Type*} {l : Subspace Ξ· Ξ± ΞΉ} {x : Ξ· β†’ Ξ±} {i : ΞΉ} {a : Ξ±} {e : Ξ·} /-- The combinatorial subspace corresponding to the identity embedding `(ΞΉ β†’ Ξ±) β†’ (ΞΉ β†’ Ξ±)`. -/ instance : Inhabited (Subspace ΞΉ Ξ± ΞΉ) := ⟨⟨Sum.inr, fun i ↦ ⟨i, rfl⟩⟩⟩ /-- Consider a subspace `l : Subspace Ξ· Ξ± ΞΉ` as a function `(Ξ· β†’ Ξ±) β†’ ΞΉ β†’ Ξ±`. -/ @[coe] def toFun (l : Subspace Ξ· Ξ± ΞΉ) (x : Ξ· β†’ Ξ±) (i : ΞΉ) : Ξ± := (l.idxFun i).elim id x instance instCoeFun : CoeFun (Subspace Ξ· Ξ± ΞΉ) (fun _ ↦ (Ξ· β†’ Ξ±) β†’ ΞΉ β†’ Ξ±) := ⟨toFun⟩ lemma coe_apply (l : Subspace Ξ· Ξ± ΞΉ) (x : Ξ· β†’ Ξ±) (i : ΞΉ) : l x i = (l.idxFun i).elim id x := rfl -- Note: This is not made a `FunLike` instance to avoid having two syntactically different coercions lemma coe_injective [Nontrivial Ξ±] : Injective ((⇑) : Subspace Ξ· Ξ± ΞΉ β†’ (Ξ· β†’ Ξ±) β†’ ΞΉ β†’ Ξ±) := by classical rintro l m hlm ext i simp only [funext_iff] at hlm cases hl : idxFun l i with | inl a => obtain ⟨b, hba⟩ := exists_ne a cases hm : idxFun m i <;> simpa [hl, hm, hba.symm, coe_apply] using hlm (const _ b) i | inr e => cases hm : idxFun m i with | inl a => obtain ⟨b, hba⟩ := exists_ne a simpa [hl, hm, hba, coe_apply] using hlm (const _ b) i | inr f => obtain ⟨a, b, hab⟩ := exists_pair_ne Ξ± simp only [Sum.inr.injEq] by_contra! hef simpa [hl, hm, hef, hab, coe_apply] using hlm (Function.update (const _ a) f b) i lemma apply_def (l : Subspace Ξ· Ξ± ΞΉ) (x : Ξ· β†’ Ξ±) (i : ΞΉ) : l x i = (l.idxFun i).elim id x := rfl lemma apply_inl (h : l.idxFun i = Sum.inl a) : l x i = a := by simp [apply_def, h] lemma apply_inr (h : l.idxFun i = Sum.inr e) : l x i = x e := by simp [apply_def, h] /-- Given a coloring `C` of `ΞΉ β†’ Ξ±` and a combinatorial subspace `l` of `ΞΉ β†’ Ξ±`, `l.IsMono C` means that `l` is monochromatic with regard to `C`. -/ def IsMono (C : (ΞΉ β†’ Ξ±) β†’ ΞΊ) (l : Subspace Ξ· Ξ± ΞΉ) : Prop := βˆƒ c, βˆ€ x, C (l x) = c variable {Ξ·' Ξ±' ΞΉ' : Type*} /-- Change the index types of a subspace. -/ def reindex (l : Subspace Ξ· Ξ± ΞΉ) (eΞ· : Ξ· ≃ Ξ·') (eΞ± : Ξ± ≃ Ξ±') (eΞΉ : ΞΉ ≃ ΞΉ') : Subspace Ξ·' Ξ±' ΞΉ' where idxFun i := (l.idxFun <| eΞΉ.symm i).map eΞ± eΞ· proper e := (eΞΉ.exists_congr fun i ↦ by cases h : idxFun l i <;> simp [*, funext_iff, Equiv.eq_symm_apply]).1 <| l.proper <| eΞ·.symm e @[simp] lemma reindex_apply (l : Subspace Ξ· Ξ± ΞΉ) (eΞ· : Ξ· ≃ Ξ·') (eΞ± : Ξ± ≃ Ξ±') (eΞΉ : ΞΉ ≃ ΞΉ') (x i) : l.reindex eΞ· eΞ± eΞΉ x i = eΞ± (l (eΞ±.symm ∘ x ∘ eΞ·) <| eΞΉ.symm i) := by cases h : l.idxFun (eΞΉ.symm i) <;> simp [h, reindex, coe_apply] @[simp] lemma reindex_isMono {eΞ· : Ξ· ≃ Ξ·'} {eΞ± : Ξ± ≃ Ξ±'} {eΞΉ : ΞΉ ≃ ΞΉ'} {C : (ΞΉ' β†’ Ξ±') β†’ ΞΊ} : (l.reindex eΞ· eΞ± eΞΉ).IsMono C ↔ l.IsMono fun x ↦ C <| eΞ± ∘ x ∘ eΞΉ.symm := by simp only [IsMono, funext (reindex_apply _ _ _ _ _), coe_apply] exact exists_congr fun c ↦ (eΞ·.arrowCongr eΞ±).symm.forall_congr <| by aesop protected lemma IsMono.reindex {eΞ· : Ξ· ≃ Ξ·'} {eΞ± : Ξ± ≃ Ξ±'} {eΞΉ : ΞΉ ≃ ΞΉ'} {C : (ΞΉ β†’ Ξ±) β†’ ΞΊ} (hl : l.IsMono C) : (l.reindex eΞ· eΞ± eΞΉ).IsMono fun x ↦ C <| eΞ±.symm ∘ x ∘ eΞΉ := by simp [reindex_isMono, Function.comp_assoc]; simpa [← Function.comp_assoc] end Subspace /-- The type of combinatorial lines. A line `l : Line Ξ± ΞΉ` in the hypercube `ΞΉ β†’ Ξ±` defines a function `Ξ± β†’ ΞΉ β†’ Ξ±` from `Ξ±` to the hypercube, such that for each coordinate `i : ΞΉ`, the function `fun x ↦ l x i` is either `id` or constant. We require lines to be nontrivial in the sense that `fun x ↦ l x i` is `id` for at least one `i`. Formally, a line is represented by a word `l.idxFun : ΞΉ β†’ Option Ξ±` which says whether `fun x ↦ l x i` is `id` (corresponding to `l.idxFun i = none`) or constantly `y` (corresponding to `l.idxFun i = some y`). When `Ξ±` has size `1` there can be many elements of `Line Ξ± ΞΉ` defining the same function. -/ @[ext] structure Line (Ξ± ΞΉ : Type*) where /-- The word representing a combinatorial line. `l.idxfun i = none` means that `l x i = x` for all `x` and `l.idxfun i = some y` means that `l x i = y`. -/ idxFun : ΞΉ β†’ Option Ξ± /-- We require combinatorial lines to be nontrivial in the sense that `fun x ↦ l x i` is `id` for at least one coordinate `i`. -/ proper : βˆƒ i, idxFun i = none namespace Line variable {l : Line Ξ± ΞΉ} {i : ΞΉ} {a x : Ξ±} /-- Consider a line `l : Line Ξ± ΞΉ` as a function `Ξ± β†’ ΞΉ β†’ Ξ±`. -/ @[coe] def toFun (l : Line Ξ± ΞΉ) (x : Ξ±) (i : ΞΉ) : Ξ± := (l.idxFun i).getD x -- This lets us treat a line `l : Line Ξ± ΞΉ` as a function `Ξ± β†’ ΞΉ β†’ Ξ±`. instance instCoeFun : CoeFun (Line Ξ± ΞΉ) fun _ => Ξ± β†’ ΞΉ β†’ Ξ± := ⟨toFun⟩ @[simp] lemma coe_apply (l : Line Ξ± ΞΉ) (x : Ξ±) (i : ΞΉ) : l x i = (l.idxFun i).getD x := rfl -- Note: This is not made a `FunLike` instance to avoid having two syntactically different coercions lemma coe_injective [Nontrivial Ξ±] : Injective ((⇑) : Line Ξ± ΞΉ β†’ Ξ± β†’ ΞΉ β†’ Ξ±) := by rintro l m hlm ext i a obtain ⟨b, hba⟩ := exists_ne a simp only [Option.mem_def, funext_iff] at hlm ⊒ refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
Β· cases hi : idxFun m i <;> simpa [@eq_comm _ a, hi, h, hba] using hlm b i Β· cases hi : idxFun l i <;> simpa [@eq_comm _ a, hi, h, hba] using hlm b i /-- A line is monochromatic if all its points are the same color. -/
Mathlib/Combinatorics/HalesJewett.lean
197
200
/- Copyright (c) 2024 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alex Kontorovich, David Loeffler, Heather Macbeth, SΓ©bastien GouΓ«zel -/ import Mathlib.Analysis.Calculus.ParametricIntegral import Mathlib.Analysis.Calculus.ContDiff.CPolynomial import Mathlib.Analysis.Fourier.AddCircle import Mathlib.Analysis.Fourier.FourierTransform import Mathlib.Analysis.Calculus.FDeriv.Analytic import Mathlib.Analysis.Calculus.LineDeriv.IntegrationByParts import Mathlib.Analysis.Calculus.ContDiff.Bounds /-! # Derivatives of the Fourier transform In this file we compute the FrΓ©chet derivative of the Fourier transform of `f`, where `f` is a function such that both `f` and `v ↦ β€–vβ€– * β€–f vβ€–` are integrable. Here the Fourier transform is understood as an operator `(V β†’ E) β†’ (W β†’ E)`, where `V` and `W` are normed `ℝ`-vector spaces and the Fourier transform is taken with respect to a continuous `ℝ`-bilinear pairing `L : V Γ— W β†’ ℝ` and a given reference measure `ΞΌ`. We also investigate higher derivatives: Assuming that `β€–vβ€–^n * β€–f vβ€–` is integrable, we show that the Fourier transform of `f` is `C^n`. We also study in a parallel way the Fourier transform of the derivative, which is obtained by tensoring the Fourier transform of the original function with the bilinear form. We also get results for iterated derivatives. A consequence of these results is that, if a function is smooth and all its derivatives are integrable when multiplied by `β€–vβ€–^k`, then the same goes for its Fourier transform, with explicit bounds. We give specialized versions of these results on inner product spaces (where `L` is the scalar product) and on the real line, where we express the one-dimensional derivative in more concrete terms, as the Fourier transform of `-2Ο€I x * f x` (or `(-2Ο€I x)^n * f x` for higher derivatives). ## Main definitions and results We introduce two convenience definitions: * `VectorFourier.fourierSMulRight L f`: given `f : V β†’ E` and `L` a bilinear pairing between `V` and `W`, then this is the function `fun v ↦ -(2 * Ο€ * I) (L v ⬝) β€’ f v`, from `V` to `Hom (W, E)`. This is essentially `ContinuousLinearMap.smulRight`, up to the factor `- 2Ο€I` designed to make sure that the Fourier integral of `fourierSMulRight L f` is the derivative of the Fourier integral of `f`. * `VectorFourier.fourierPowSMulRight` is the higher order analogue for higher derivatives: `fourierPowSMulRight L f v n` is informally `(-(2 * Ο€ * I))^n (L v ⬝)^n β€’ f v`, in the space of continuous multilinear maps `W [Γ—n]β†’L[ℝ] E`. With these definitions, the statements read as follows, first in a general context (arbitrary `L` and `ΞΌ`): * `VectorFourier.hasFDerivAt_fourierIntegral`: the Fourier integral of `f` is differentiable, with derivative the Fourier integral of `fourierSMulRight L f`. * `VectorFourier.differentiable_fourierIntegral`: the Fourier integral of `f` is differentiable. * `VectorFourier.fderiv_fourierIntegral`: formula for the derivative of the Fourier integral of `f`. * `VectorFourier.fourierIntegral_fderiv`: formula for the Fourier integral of the derivative of `f`. * `VectorFourier.hasFTaylorSeriesUpTo_fourierIntegral`: under suitable integrability conditions, the Fourier integral of `f` has an explicit Taylor series up to order `N`, given by the Fourier integrals of `fun v ↦ fourierPowSMulRight L f v n`. * `VectorFourier.contDiff_fourierIntegral`: under suitable integrability conditions, the Fourier integral of `f` is `C^n`. * `VectorFourier.iteratedFDeriv_fourierIntegral`: under suitable integrability conditions, explicit formula for the `n`-th derivative of the Fourier integral of `f`, as the Fourier integral of `fun v ↦ fourierPowSMulRight L f v n`. * `VectorFourier.pow_mul_norm_iteratedFDeriv_fourierIntegral_le`: explicit bounds for the `n`-th derivative of the Fourier integral, multiplied by a power function, in terms of corresponding integrals for the original function. These statements are then specialized to the case of the usual Fourier transform on finite-dimensional inner product spaces with their canonical Lebesgue measure (covering in particular the case of the real line), replacing the namespace `VectorFourier` by the namespace `Real` in the above statements. We also give specialized versions of the one-dimensional real derivative (and iterated derivative) in `Real.deriv_fourierIntegral` and `Real.iteratedDeriv_fourierIntegral`. -/ noncomputable section open Real Complex MeasureTheory Filter TopologicalSpace open scoped FourierTransform Topology ContDiff -- without this local instance, Lean tries first the instance -- `secondCountableTopologyEither_of_right` (whose priority is 100) and takes a very long time to -- fail. Since we only use the left instance in this file, we make sure it is tried first. attribute [local instance 101] secondCountableTopologyEither_of_left namespace Real lemma hasDerivAt_fourierChar (x : ℝ) : HasDerivAt (𝐞 Β· : ℝ β†’ β„‚) (2 * Ο€ * I * 𝐞 x) x := by have h1 (y : ℝ) : 𝐞 y = fourier 1 (y : UnitAddCircle) := by rw [fourierChar_apply, fourier_coe_apply] push_cast ring_nf simpa only [h1, Int.cast_one, ofReal_one, div_one, mul_one] using hasDerivAt_fourier 1 1 x lemma differentiable_fourierChar : Differentiable ℝ (𝐞 Β· : ℝ β†’ β„‚) := fun x ↦ (Real.hasDerivAt_fourierChar x).differentiableAt lemma deriv_fourierChar (x : ℝ) : deriv (𝐞 Β· : ℝ β†’ β„‚) x = 2 * Ο€ * I * 𝐞 x := (Real.hasDerivAt_fourierChar x).deriv variable {V W : Type*} [NormedAddCommGroup V] [NormedSpace ℝ V] [NormedAddCommGroup W] [NormedSpace ℝ W] (L : V β†’L[ℝ] W β†’L[ℝ] ℝ) lemma hasFDerivAt_fourierChar_neg_bilinear_right (v : V) (w : W) : HasFDerivAt (fun w ↦ (𝐞 (-L v w) : β„‚)) ((-2 * Ο€ * I * 𝐞 (-L v w)) β€’ (ofRealCLM ∘L (L v))) w := by have ha : HasFDerivAt (fun w' : W ↦ L v w') (L v) w := ContinuousLinearMap.hasFDerivAt (L v) convert (hasDerivAt_fourierChar (-L v w)).hasFDerivAt.comp w ha.neg using 1 ext y simp only [neg_mul, ContinuousLinearMap.coe_smul', ContinuousLinearMap.coe_comp', Pi.smul_apply, Function.comp_apply, ofRealCLM_apply, smul_eq_mul, ContinuousLinearMap.comp_neg, ContinuousLinearMap.neg_apply, ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.one_apply, real_smul, neg_inj] ring lemma fderiv_fourierChar_neg_bilinear_right_apply (v : V) (w y : W) : fderiv ℝ (fun w ↦ (𝐞 (-L v w) : β„‚)) w y = -2 * Ο€ * I * L v y * 𝐞 (-L v w) := by simp only [(hasFDerivAt_fourierChar_neg_bilinear_right L v w).fderiv, neg_mul, ContinuousLinearMap.coe_smul', ContinuousLinearMap.coe_comp', Pi.smul_apply, Function.comp_apply, ofRealCLM_apply, smul_eq_mul, neg_inj] ring lemma differentiable_fourierChar_neg_bilinear_right (v : V) : Differentiable ℝ (fun w ↦ (𝐞 (-L v w) : β„‚)) := fun w ↦ (hasFDerivAt_fourierChar_neg_bilinear_right L v w).differentiableAt lemma hasFDerivAt_fourierChar_neg_bilinear_left (v : V) (w : W) : HasFDerivAt (fun v ↦ (𝐞 (-L v w) : β„‚)) ((-2 * Ο€ * I * 𝐞 (-L v w)) β€’ (ofRealCLM ∘L (L.flip w))) v := hasFDerivAt_fourierChar_neg_bilinear_right L.flip w v lemma fderiv_fourierChar_neg_bilinear_left_apply (v y : V) (w : W) : fderiv ℝ (fun v ↦ (𝐞 (-L v w) : β„‚)) v y = -2 * Ο€ * I * L y w * 𝐞 (-L v w) := by simp only [(hasFDerivAt_fourierChar_neg_bilinear_left L v w).fderiv, neg_mul, ContinuousLinearMap.coe_smul', ContinuousLinearMap.coe_comp', Pi.smul_apply, Function.comp_apply, ContinuousLinearMap.flip_apply, ofRealCLM_apply, smul_eq_mul, neg_inj] ring lemma differentiable_fourierChar_neg_bilinear_left (w : W) : Differentiable ℝ (fun v ↦ (𝐞 (-L v w) : β„‚)) := fun v ↦ (hasFDerivAt_fourierChar_neg_bilinear_left L v w).differentiableAt end Real variable {E : Type*} [NormedAddCommGroup E] [NormedSpace β„‚ E] namespace VectorFourier variable {V W : Type*} [NormedAddCommGroup V] [NormedSpace ℝ V] [NormedAddCommGroup W] [NormedSpace ℝ W] (L : V β†’L[ℝ] W β†’L[ℝ] ℝ) (f : V β†’ E) /-- Send a function `f : V β†’ E` to the function `f : V β†’ Hom (W, E)` given by `v ↦ (w ↦ -2 * Ο€ * I * L (v, w) β€’ f v)`. This is designed so that the Fourier transform of `fourierSMulRight L f` is the derivative of the Fourier transform of `f`. -/ def fourierSMulRight (v : V) : (W β†’L[ℝ] E) := -(2 * Ο€ * I) β€’ (L v).smulRight (f v) @[simp] lemma fourierSMulRight_apply (v : V) (w : W) : fourierSMulRight L f v w = -(2 * Ο€ * I) β€’ L v w β€’ f v := rfl /-- The `w`-derivative of the Fourier transform integrand. -/ lemma hasFDerivAt_fourierChar_smul (v : V) (w : W) : HasFDerivAt (fun w' ↦ 𝐞 (-L v w') β€’ f v) (𝐞 (-L v w) β€’ fourierSMulRight L f v) w := by have ha : HasFDerivAt (fun w' : W ↦ L v w') (L v) w := ContinuousLinearMap.hasFDerivAt (L v) convert ((hasDerivAt_fourierChar (-L v w)).hasFDerivAt.comp w ha.neg).smul_const (f v) ext w' : 1 simp_rw [fourierSMulRight, ContinuousLinearMap.smul_apply, ContinuousLinearMap.smulRight_apply] rw [ContinuousLinearMap.comp_apply, ContinuousLinearMap.neg_apply, ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.one_apply, ← smul_assoc, smul_comm, ← smul_assoc, real_smul, real_smul, Submonoid.smul_def, smul_eq_mul] push_cast ring_nf lemma norm_fourierSMulRight (L : V β†’L[ℝ] W β†’L[ℝ] ℝ) (f : V β†’ E) (v : V) : β€–fourierSMulRight L f vβ€– = (2 * Ο€) * β€–L vβ€– * β€–f vβ€– := by rw [fourierSMulRight, norm_smul _ (ContinuousLinearMap.smulRight (L v) (f v)), norm_neg, norm_mul, norm_mul, norm_I, mul_one, Complex.norm_of_nonneg pi_pos.le, Complex.norm_two, ContinuousLinearMap.norm_smulRight_apply, ← mul_assoc] lemma norm_fourierSMulRight_le (L : V β†’L[ℝ] W β†’L[ℝ] ℝ) (f : V β†’ E) (v : V) : β€–fourierSMulRight L f vβ€– ≀ 2 * Ο€ * β€–Lβ€– * β€–vβ€– * β€–f vβ€– := calc β€–fourierSMulRight L f vβ€– = (2 * Ο€) * β€–L vβ€– * β€–f vβ€– := norm_fourierSMulRight _ _ _ _ ≀ (2 * Ο€) * (β€–Lβ€– * β€–vβ€–) * β€–f vβ€– := by gcongr; exact L.le_opNorm _ _ = 2 * Ο€ * β€–Lβ€– * β€–vβ€– * β€–f vβ€– := by ring
lemma _root_.MeasureTheory.AEStronglyMeasurable.fourierSMulRight [SecondCountableTopologyEither V (W β†’L[ℝ] ℝ)] [MeasurableSpace V] [BorelSpace V] {L : V β†’L[ℝ] W β†’L[ℝ] ℝ} {f : V β†’ E} {ΞΌ : Measure V} (hf : AEStronglyMeasurable f ΞΌ) : AEStronglyMeasurable (fun v ↦ fourierSMulRight L f v) ΞΌ := by apply AEStronglyMeasurable.const_smul' have aux0 : Continuous fun p : (W β†’L[ℝ] ℝ) Γ— E ↦ p.1.smulRight p.2 := (ContinuousLinearMap.smulRightL ℝ W E).continuousβ‚‚ have aux1 : AEStronglyMeasurable (fun v ↦ (L v, f v)) ΞΌ := L.continuous.aestronglyMeasurable.prodMk hf -- Elaboration without the expected type is faster here: exact (aux0.comp_aestronglyMeasurable aux1 :)
Mathlib/Analysis/Fourier/FourierTransformDeriv.lean
191
202
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.WSeq.Relation /-! # Parallel computation Parallel computation of a computable sequence of computations by a diagonal enumeration. The important theorems of this operation are proven as terminates_parallel and exists_of_mem_parallel. (This operation is nondeterministic in the sense that it does not honor sequence equivalence (irrelevance of computation time).) -/ universe u v namespace Computation open Stream' variable {Ξ± : Type u} {Ξ² : Type v} private def parallel.aux2 : List (Computation Ξ±) β†’ Ξ± βŠ• (List (Computation Ξ±)) := List.foldr (fun c o => match o with | Sum.inl a => Sum.inl a | Sum.inr ls => rmap (fun c' => c' :: ls) (destruct c)) (Sum.inr []) private def parallel.aux1 : List (Computation Ξ±) Γ— WSeq (Computation Ξ±) β†’ Ξ± βŠ• (List (Computation Ξ±) Γ— WSeq (Computation Ξ±)) | (l, S) => rmap (fun l' => match Seq.destruct S with | none => (l', Seq.nil) | some (none, S') => (l', S') | some (some c, S') => (c :: l', S')) (parallel.aux2 l) /-- Parallel computation of an infinite stream of computations, taking the first result -/ def parallel (S : WSeq (Computation Ξ±)) : Computation Ξ± := corec parallel.aux1 ([], S) theorem terminates_parallel.aux : βˆ€ {l : List (Computation Ξ±)} {S c}, c ∈ l β†’ Terminates c β†’ Terminates (corec parallel.aux1 (l, S)) := by have lem1 : βˆ€ l S, (βˆƒ a : Ξ±, parallel.aux2 l = Sum.inl a) β†’ Terminates (corec parallel.aux1 (l, S)) := by intro l S e obtain ⟨a, e⟩ := e have : corec parallel.aux1 (l, S) = return a := by apply destruct_eq_pure simp only [parallel.aux1, rmap, corec_eq] rw [e] rw [this] exact ret_terminates a intro l S c m T revert l S apply @terminatesRecOn _ _ c T _ _ Β· intro a l S m apply lem1 induction' l with c l IH <;> simp at m rcases m with e | m Β· rw [← e] simp only [parallel.aux2, rmap, List.foldr_cons, destruct_pure] split <;> simp Β· obtain ⟨a', e⟩ := IH m simp only [parallel.aux2, rmap, List.foldr_cons] simp? [parallel.aux2] at e says simp only [parallel.aux2, rmap] at e rw [e] exact ⟨a', rfl⟩ Β· intro s IH l S m have H1 : βˆ€ l', parallel.aux2 l = Sum.inr l' β†’ s ∈ l' := by induction' l with c l IH' <;> intro l' e' <;> simp at m rcases m with e | m <;> simp [parallel.aux2] at e' Β· rw [← e] at e' -- Porting note: `revert e'` is required. revert e' split Β· simp Β· simp only [destruct_think, Sum.inr.injEq] rintro rfl simp Β· induction' e : List.foldr (fun c o => match o with | Sum.inl a => Sum.inl a | Sum.inr ls => rmap (fun c' => c' :: ls) (destruct c)) (Sum.inr List.nil) l with a' ls <;> erw [e] at e' Β· contradiction have := IH' m _ e -- Porting note: `revert e'` & `intro e'` are required. revert e' cases destruct c <;> intro e' <;> [injection e'; injection e' with h'] rw [← h'] simp [this] induction' h : parallel.aux2 l with a l' Β· exact lem1 _ _ ⟨a, h⟩ Β· have H2 : corec parallel.aux1 (l, S) = think _ := destruct_eq_think (by simp only [parallel.aux1, rmap, corec_eq] rw [h]) rw [H2] refine @Computation.think_terminates _ _ ?_ have := H1 _ h rcases Seq.destruct S with (_ | ⟨_ | c, S'⟩) <;> simp [parallel.aux1] <;> apply IH <;> simp [this] theorem terminates_parallel {S : WSeq (Computation Ξ±)} {c} (h : c ∈ S) [T : Terminates c] : Terminates (parallel S) := by suffices βˆ€ (n) (l : List (Computation Ξ±)) (S c), c ∈ l ∨ some (some c) = Seq.get? S n β†’ Terminates c β†’ Terminates (corec parallel.aux1 (l, S)) from let ⟨n, h⟩ := h this n [] S c (Or.inr h) T intro n; induction' n with n IH <;> intro l S c o T Β· rcases o with a | a Β· exact terminates_parallel.aux a T have H : Seq.destruct S = some (some c, Seq.tail S) := by simp [Seq.destruct, (Β· <$> Β·), ← a] induction' h : parallel.aux2 l with a l' Β· have C : corec parallel.aux1 (l, S) = pure a := by apply destruct_eq_pure rw [corec_eq, parallel.aux1] rw [h] simp only [rmap] rw [C] infer_instance Β· have C : corec parallel.aux1 (l, S) = _ := destruct_eq_think (by simp only [corec_eq, rmap, parallel.aux1.eq_1] rw [h, H]) rw [C] refine @Computation.think_terminates _ _ ?_ apply terminates_parallel.aux _ T simp Β· rcases o with a | a Β· exact terminates_parallel.aux a T induction' h : parallel.aux2 l with a l' Β· have C : corec parallel.aux1 (l, S) = pure a := by apply destruct_eq_pure rw [corec_eq, parallel.aux1] rw [h] simp only [rmap] rw [C] infer_instance Β· have C : corec parallel.aux1 (l, S) = _ := destruct_eq_think (by simp only [corec_eq, rmap, parallel.aux1.eq_1] rw [h]) rw [C] refine @Computation.think_terminates _ _ ?_ have TT : βˆ€ l', Terminates (corec parallel.aux1 (l', S.tail)) := by intro apply IH _ _ _ (Or.inr _) T rw [a, Seq.get?_tail] induction' e : Seq.get? S 0 with o Β· have D : Seq.destruct S = none := by dsimp [Seq.destruct] rw [e] rfl rw [D] simp only have TT := TT l' rwa [Seq.destruct_eq_none D, Seq.tail_nil] at TT Β· have D : Seq.destruct S = some (o, S.tail) := by dsimp [Seq.destruct] rw [e] rfl rw [D] cases o <;> simp [parallel.aux1, TT] theorem exists_of_mem_parallel {S : WSeq (Computation Ξ±)} {a} (h : a ∈ parallel S) : βˆƒ c ∈ S, a ∈ c := by suffices βˆ€ C, a ∈ C β†’ βˆ€ (l : List (Computation Ξ±)) (S), corec parallel.aux1 (l, S) = C β†’ βˆƒ c, (c ∈ l ∨ c ∈ S) ∧ a ∈ c from let ⟨c, h1, h2⟩ := this _ h [] S rfl ⟨c, h1.resolve_left <| List.not_mem_nil, h2⟩ let F : List (Computation Ξ±) β†’ Ξ± βŠ• (List (Computation Ξ±)) β†’ Prop := by intro l a rcases a with a | l' Β· exact βˆƒ c ∈ l, a ∈ c Β· exact βˆ€ a', (βˆƒ c ∈ l', a' ∈ c) β†’ βˆƒ c ∈ l, a' ∈ c have lem1 : βˆ€ l : List (Computation Ξ±), F l (parallel.aux2 l) := by intro l induction' l with c l IH <;> simp only [parallel.aux2, List.foldr] Β· intro a h rcases h with ⟨c, hn, _⟩ exact False.elim <| List.not_mem_nil hn Β· simp only [parallel.aux2] at IH -- Porting note: `revert IH` & `intro IH` are required. revert IH cases List.foldr (fun c o => match o with | Sum.inl a => Sum.inl a | Sum.inr ls => rmap (fun c' => c' :: ls) (destruct c)) (Sum.inr List.nil) l <;> intro IH <;> simp only [parallel.aux2] Β· rcases IH with ⟨c', cl, ac⟩ exact ⟨c', List.Mem.tail _ cl, ac⟩ Β· induction' h : destruct c with a c' <;> simp only [rmap] Β· refine ⟨c, List.mem_cons_self, ?_⟩ rw [destruct_eq_pure h] apply ret_mem Β· intro a' h rcases h with ⟨d, dm, ad⟩ simp? at dm says simp only [List.mem_cons] at dm rcases dm with e | dl Β· rw [e] at ad refine ⟨c, List.mem_cons_self, ?_⟩ rw [destruct_eq_think h] exact think_mem ad Β· obtain ⟨d, dm⟩ := IH a' ⟨d, dl, ad⟩ obtain ⟨dm, ad⟩ := dm exact ⟨d, List.Mem.tail _ dm, ad⟩ intro C aC -- Porting note: `revert this e'` & `intro this e'` are required. apply memRecOn aC <;> [skip; intro C' IH] <;> intro l S e <;> have e' := congr_arg destruct e <;> have := lem1 l <;> simp only [parallel.aux1, corec_eq, destruct_pure, destruct_think] at e' <;> revert this e' <;> rcases parallel.aux2 l with a' | l' <;> intro this e' <;> [injection e' with h'; injection e'; injection e'; injection e' with h'] Β· rw [h'] at this rcases this with ⟨c, cl, ac⟩ exact ⟨c, Or.inl cl, ac⟩ Β· induction' e : Seq.destruct S with a <;> rw [e] at h' Β· exact let ⟨d, o, ad⟩ := IH _ _ h' let ⟨c, cl, ac⟩ := this a ⟨d, o.resolve_right (WSeq.not_mem_nil _), ad⟩ ⟨c, Or.inl cl, ac⟩ Β· obtain ⟨o, S'⟩ := a obtain - | c := o <;> simp [parallel.aux1] at h' <;> rcases IH _ _ h' with ⟨d, dl | dS', ad⟩ Β· exact let ⟨c, cl, ac⟩ := this a ⟨d, dl, ad⟩ ⟨c, Or.inl cl, ac⟩ Β· refine ⟨d, Or.inr ?_, ad⟩ rw [Seq.destruct_eq_cons e] exact Seq.mem_cons_of_mem _ dS' Β· simp at dl rcases dl with dc | dl Β· rw [dc] at ad refine ⟨c, Or.inr ?_, ad⟩ rw [Seq.destruct_eq_cons e] apply Seq.mem_cons Β· exact let ⟨c, cl, ac⟩ := this a ⟨d, dl, ad⟩ ⟨c, Or.inl cl, ac⟩ Β· refine ⟨d, Or.inr ?_, ad⟩ rw [Seq.destruct_eq_cons e] exact Seq.mem_cons_of_mem _ dS' theorem map_parallel (f : Ξ± β†’ Ξ²) (S) : map f (parallel S) = parallel (S.map (map f)) := by refine eq_of_bisim (fun c1 c2 => βˆƒ l S, c1 = map f (corec parallel.aux1 (l, S)) ∧ c2 = corec parallel.aux1 (l.map (map f), S.map (map f))) ?_ ⟨[], S, rfl, rfl⟩ intro c1 c2 h exact match c1, c2, h with | _, _, ⟨l, S, rfl, rfl⟩ => by have : parallel.aux2 (l.map (map f)) = lmap f (rmap (List.map (map f)) (parallel.aux2 l)) := by simp only [parallel.aux2, rmap, lmap] induction' l with c l IH <;> simp rw [IH] cases List.foldr _ _ _ Β· simp Β· cases destruct c <;> simp simp only [BisimO, destruct_map, lmap, rmap, corec_eq, parallel.aux1.eq_1] rw [this] rcases parallel.aux2 l with a | l' <;> simp induction' S using WSeq.recOn with c S S <;> simp <;> exact ⟨_, _, rfl, rfl⟩ theorem parallel_empty (S : WSeq (Computation Ξ±)) (h : S.head ~> none) : parallel S = empty _ := eq_empty_of_not_terminates fun ⟨⟨a, m⟩⟩ => by let ⟨c, cs, _⟩ := exists_of_mem_parallel m let ⟨n, nm⟩ := WSeq.exists_get?_of_mem cs let ⟨c', h'⟩ := WSeq.head_some_of_get?_some nm injection h h' /-- Induction principle for parallel computations. The reason this isn't trivial from `exists_of_mem_parallel` is because it eliminates to `Sort`. -/ def parallelRec {S : WSeq (Computation Ξ±)} (C : Ξ± β†’ Sort v) (H : βˆ€ s ∈ S, βˆ€ a ∈ s, C a) {a} (h : a ∈ parallel S) : C a := by let T : WSeq (Computation (Ξ± Γ— Computation Ξ±)) := S.map fun c => c.map fun a => (a, c) have : S = T.map (map fun c => c.1) := by rw [← WSeq.map_comp] refine (WSeq.map_id _).symm.trans (congr_arg (fun f => WSeq.map f S) ?_) funext c dsimp [id, Function.comp_def] rw [← map_comp] exact (map_id _).symm have pe := congr_arg parallel this rw [← map_parallel] at pe have h' := h rw [pe] at h' haveI : Terminates (parallel T) := (terminates_map_iff _ _).1 ⟨⟨_, h'⟩⟩ induction' e : get (parallel T) with a' c have : a ∈ c ∧ c ∈ S := by rcases exists_of_mem_map h' with ⟨d, dT, cd⟩ rw [get_eq_of_mem _ dT] at e cases e dsimp at cd cases cd rcases exists_of_mem_parallel dT with ⟨d', dT', ad'⟩ rcases WSeq.exists_of_mem_map dT' with ⟨c', cs', e'⟩ rw [← e'] at ad' rcases exists_of_mem_map ad' with ⟨a', ac', e'⟩ injection e' with i1 i2 constructor Β· rwa [i1, i2] at ac' Β· rwa [i2] at cs' obtain ⟨ac, cs⟩ := this apply H _ cs _ ac theorem parallel_promises {S : WSeq (Computation Ξ±)} {a} (H : βˆ€ s ∈ S, s ~> a) : parallel S ~> a := fun _ ma' => let ⟨_, cs, ac⟩ := exists_of_mem_parallel ma' H _ cs ac theorem mem_parallel {S : WSeq (Computation Ξ±)} {a} (H : βˆ€ s ∈ S, s ~> a) {c} (cs : c ∈ S) (ac : a ∈ c) : a ∈ parallel S := by haveI := terminates_of_mem ac haveI := terminates_parallel cs exact mem_of_promises _ (parallel_promises H) theorem parallel_congr_lem {S T : WSeq (Computation Ξ±)} {a} (H : S.LiftRel Equiv T) : (βˆ€ s ∈ S, s ~> a) ↔ βˆ€ t ∈ T, t ~> a := ⟨fun h1 _ tT => let ⟨_, sS, se⟩ := WSeq.exists_of_liftRel_right H tT (promises_congr se _).1 (h1 _ sS), fun h2 _ sS => let ⟨_, tT, se⟩ := WSeq.exists_of_liftRel_left H sS (promises_congr se _).2 (h2 _ tT)⟩ -- The parallel operation is only deterministic when all computation paths lead to the same value theorem parallel_congr_left {S T : WSeq (Computation Ξ±)} {a} (h1 : βˆ€ s ∈ S, s ~> a) (H : S.LiftRel Equiv T) : parallel S ~ parallel T := let h2 := (parallel_congr_lem H).1 h1 fun a' => ⟨fun h => by have aa := parallel_promises h1 h rw [← aa] rw [← aa] at h exact let ⟨s, sS, as⟩ := exists_of_mem_parallel h let ⟨t, tT, st⟩ := WSeq.exists_of_liftRel_left H sS let aT := (st _).1 as mem_parallel h2 tT aT, fun h => by have aa := parallel_promises h2 h rw [← aa] rw [← aa] at h exact let ⟨s, sS, as⟩ := exists_of_mem_parallel h let ⟨t, tT, st⟩ := WSeq.exists_of_liftRel_right H sS
let aT := (st _).2 as mem_parallel h1 tT aT⟩ theorem parallel_congr_right {S T : WSeq (Computation Ξ±)} {a} (h2 : βˆ€ t ∈ T, t ~> a) (H : S.LiftRel Equiv T) : parallel S ~ parallel T := parallel_congr_left ((parallel_congr_lem H).2 h2) H end Computation
Mathlib/Data/Seq/Parallel.lean
363
384
/- Copyright (c) 2022 Moritz Doll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Moritz Doll, Anatole Dedecker -/ import Mathlib.Analysis.LocallyConvex.Bounded import Mathlib.Analysis.Seminorm import Mathlib.Data.Real.Sqrt import Mathlib.Topology.Algebra.Equicontinuity import Mathlib.Topology.MetricSpace.Equicontinuity import Mathlib.Topology.Algebra.FilterBasis import Mathlib.Topology.Algebra.Module.LocallyConvex /-! # Topology induced by a family of seminorms ## Main definitions * `SeminormFamily.basisSets`: The set of open seminorm balls for a family of seminorms. * `SeminormFamily.moduleFilterBasis`: A module filter basis formed by the open balls. * `Seminorm.IsBounded`: A linear map `f : E β†’β‚—[π•œ] F` is bounded iff every seminorm in `F` can be bounded by a finite number of seminorms in `E`. ## Main statements * `WithSeminorms.toLocallyConvexSpace`: A space equipped with a family of seminorms is locally convex. * `WithSeminorms.firstCountable`: A space is first countable if it's topology is induced by a countable family of seminorms. ## Continuity of semilinear maps If `E` and `F` are topological vector space with the topology induced by a family of seminorms, then we have a direct method to prove that a linear map is continuous: * `Seminorm.continuous_from_bounded`: A bounded linear map `f : E β†’β‚—[π•œ] F` is continuous. If the topology of a space `E` is induced by a family of seminorms, then we can characterize von Neumann boundedness in terms of that seminorm family. Together with `LinearMap.continuous_of_locally_bounded` this gives general criterion for continuity. * `WithSeminorms.isVonNBounded_iff_finset_seminorm_bounded` * `WithSeminorms.isVonNBounded_iff_seminorm_bounded` * `WithSeminorms.image_isVonNBounded_iff_finset_seminorm_bounded` * `WithSeminorms.image_isVonNBounded_iff_seminorm_bounded` ## Tags seminorm, locally convex -/ open NormedField Set Seminorm TopologicalSpace Filter List open NNReal Pointwise Topology Uniformity variable {π•œ π•œβ‚‚ 𝕝 𝕝₂ E F G ΞΉ ΞΉ' : Type*} section FilterBasis variable [NormedField π•œ] [AddCommGroup E] [Module π•œ E] variable (π•œ E ΞΉ) /-- An abbreviation for indexed families of seminorms. This is mainly to allow for dot-notation. -/ abbrev SeminormFamily := ΞΉ β†’ Seminorm π•œ E variable {π•œ E ΞΉ} namespace SeminormFamily /-- The sets of a filter basis for the neighborhood filter of 0. -/ def basisSets (p : SeminormFamily π•œ E ΞΉ) : Set (Set E) := ⋃ (s : Finset ΞΉ) (r) (_ : 0 < r), singleton (ball (s.sup p) (0 : E) r) variable (p : SeminormFamily π•œ E ΞΉ) theorem basisSets_iff {U : Set E} : U ∈ p.basisSets ↔ βˆƒ (i : Finset ΞΉ) (r : ℝ), 0 < r ∧ U = ball (i.sup p) 0 r := by simp only [basisSets, mem_iUnion, exists_prop, mem_singleton_iff] theorem basisSets_mem (i : Finset ΞΉ) {r : ℝ} (hr : 0 < r) : (i.sup p).ball 0 r ∈ p.basisSets := (basisSets_iff _).mpr ⟨i, _, hr, rfl⟩ theorem basisSets_singleton_mem (i : ΞΉ) {r : ℝ} (hr : 0 < r) : (p i).ball 0 r ∈ p.basisSets := (basisSets_iff _).mpr ⟨{i}, _, hr, by rw [Finset.sup_singleton]⟩ theorem basisSets_nonempty [Nonempty ΞΉ] : p.basisSets.Nonempty := by let i := Classical.arbitrary ΞΉ refine nonempty_def.mpr ⟨(p i).ball 0 1, ?_⟩ exact p.basisSets_singleton_mem i zero_lt_one theorem basisSets_intersect (U V : Set E) (hU : U ∈ p.basisSets) (hV : V ∈ p.basisSets) : βˆƒ z ∈ p.basisSets, z βŠ† U ∩ V := by classical rcases p.basisSets_iff.mp hU with ⟨s, r₁, hr₁, hU⟩ rcases p.basisSets_iff.mp hV with ⟨t, rβ‚‚, hrβ‚‚, hV⟩ use ((s βˆͺ t).sup p).ball 0 (min r₁ rβ‚‚) refine ⟨p.basisSets_mem (s βˆͺ t) (lt_min_iff.mpr ⟨hr₁, hrβ‚‚βŸ©), ?_⟩ rw [hU, hV, ball_finset_sup_eq_iInter _ _ _ (lt_min_iff.mpr ⟨hr₁, hrβ‚‚βŸ©), ball_finset_sup_eq_iInter _ _ _ hr₁, ball_finset_sup_eq_iInter _ _ _ hrβ‚‚] exact Set.subset_inter (Set.iInterβ‚‚_mono' fun i hi => ⟨i, Finset.subset_union_left hi, ball_mono <| min_le_left _ _⟩) (Set.iInterβ‚‚_mono' fun i hi => ⟨i, Finset.subset_union_right hi, ball_mono <| min_le_right _ _⟩) theorem basisSets_zero (U) (hU : U ∈ p.basisSets) : (0 : E) ∈ U := by rcases p.basisSets_iff.mp hU with ⟨ι', r, hr, hU⟩ rw [hU, mem_ball_zero, map_zero] exact hr theorem basisSets_add (U) (hU : U ∈ p.basisSets) : βˆƒ V ∈ p.basisSets, V + V βŠ† U := by rcases p.basisSets_iff.mp hU with ⟨s, r, hr, hU⟩ use (s.sup p).ball 0 (r / 2)
refine ⟨p.basisSets_mem s (div_pos hr zero_lt_two), ?_⟩ refine Set.Subset.trans (ball_add_ball_subset (s.sup p) (r / 2) (r / 2) 0 0) ?_ rw [hU, add_zero, add_halves]
Mathlib/Analysis/LocallyConvex/WithSeminorms.lean
117
120
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.CategoryTheory.Abelian.Exact import Mathlib.CategoryTheory.Comma.Over.Basic import Mathlib.Algebra.Category.ModuleCat.EpiMono /-! # Pseudoelements in abelian categories A *pseudoelement* of an object `X` in an abelian category `C` is an equivalence class of arrows ending in `X`, where two arrows are considered equivalent if we can find two epimorphisms with a common domain making a commutative square with the two arrows. While the construction shows that pseudoelements are actually subobjects of `X` rather than "elements", it is possible to chase these pseudoelements through commutative diagrams in an abelian category to prove exactness properties. This is done using some "diagram-chasing metatheorems" proved in this file. In many cases, a proof in the category of abelian groups can more or less directly be converted into a proof using pseudoelements. A classic application of pseudoelements are diagram lemmas like the four lemma or the snake lemma. Pseudoelements are in some ways weaker than actual elements in a concrete category. The most important limitation is that there is no extensionality principle: If `f g : X ⟢ Y`, then `βˆ€ x ∈ X, f x = g x` does not necessarily imply that `f = g` (however, if `f = 0` or `g = 0`, it does). A corollary of this is that we can not define arrows in abelian categories by dictating their action on pseudoelements. Thus, a usual style of proofs in abelian categories is this: First, we construct some morphism using universal properties, and then we use diagram chasing of pseudoelements to verify that is has some desirable property such as exactness. It should be noted that the Freyd-Mitchell embedding theorem (see `CategoryTheory.Abelian.FreydMitchell`) gives a vastly stronger notion of pseudoelement (in particular one that gives extensionality) and this file should be updated to go use that instead! ## Main results We define the type of pseudoelements of an object and, in particular, the zero pseudoelement. We prove that every morphism maps the zero pseudoelement to the zero pseudoelement (`apply_zero`) and that a zero morphism maps every pseudoelement to the zero pseudoelement (`zero_apply`). Here are the metatheorems we provide: * A morphism `f` is zero if and only if it is the zero function on pseudoelements. * A morphism `f` is an epimorphism if and only if it is surjective on pseudoelements. * A morphism `f` is a monomorphism if and only if it is injective on pseudoelements if and only if `βˆ€ a, f a = 0 β†’ f = 0`. * A sequence `f, g` of morphisms is exact if and only if `βˆ€ a, g (f a) = 0` and `βˆ€ b, g b = 0 β†’ βˆƒ a, f a = b`. * If `f` is a morphism and `a, a'` are such that `f a = f a'`, then there is some pseudoelement `a''` such that `f a'' = 0` and for every `g` we have `g a' = 0 β†’ g a = g a''`. We can think of `a''` as `a - a'`, but don't get too carried away by that: pseudoelements of an object do not form an abelian group. ## Notations We introduce coercions from an object of an abelian category to the set of its pseudoelements and from a morphism to the function it induces on pseudoelements. These coercions must be explicitly enabled via local instances: `attribute [local instance] objectToSort homToFun` ## Implementation notes It appears that sometimes the coercion from morphisms to functions does not work, i.e., writing `g a` raises a "function expected" error. This error can be fixed by writing `(g : X ⟢ Y) a`. ## References * [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2] -/ open CategoryTheory open CategoryTheory.Limits open CategoryTheory.Abelian open CategoryTheory.Preadditive universe v u namespace CategoryTheory.Abelian variable {C : Type u} [Category.{v} C] attribute [local instance] Over.coeFromHom /-- This is just composition of morphisms in `C`. Another way to express this would be `(Over.map f).obj a`, but our definition has nicer definitional properties. -/ def app {P Q : C} (f : P ⟢ Q) (a : Over P) : Over Q := a.hom ≫ f @[simp] theorem app_hom {P Q : C} (f : P ⟢ Q) (a : Over P) : (app f a).hom = a.hom ≫ f := rfl /-- Two arrows `f : X ⟢ P` and `g : Y ⟢ P` are called pseudo-equal if there is some object `R` and epimorphisms `p : R ⟢ X` and `q : R ⟢ Y` such that `p ≫ f = q ≫ g`. -/ def PseudoEqual (P : C) (f g : Over P) : Prop := βˆƒ (R : C) (p : R ⟢ f.1) (q : R ⟢ g.1) (_ : Epi p) (_ : Epi q), p ≫ f.hom = q ≫ g.hom theorem pseudoEqual_refl {P : C} : Reflexive (PseudoEqual P) := fun f => ⟨f.1, πŸ™ f.1, πŸ™ f.1, inferInstance, inferInstance, by simp⟩ theorem pseudoEqual_symm {P : C} : Symmetric (PseudoEqual P) := fun _ _ ⟨R, p, q, ep, Eq, comm⟩ => ⟨R, q, p, Eq, ep, comm.symm⟩ variable [Abelian.{v} C] section /-- Pseudoequality is transitive: Just take the pullback. The pullback morphisms will be epimorphisms since in an abelian category, pullbacks of epimorphisms are epimorphisms. -/ theorem pseudoEqual_trans {P : C} : Transitive (PseudoEqual P) := by intro f g h ⟨R, p, q, ep, Eq, comm⟩ ⟨R', p', q', ep', eq', comm'⟩ refine ⟨pullback q p', pullback.fst _ _ ≫ p, pullback.snd _ _ ≫ q', epi_comp _ _, epi_comp _ _, ?_⟩ rw [Category.assoc, comm, ← Category.assoc, pullback.condition, Category.assoc, comm', Category.assoc] end /-- The arrows with codomain `P` equipped with the equivalence relation of being pseudo-equal. -/ def Pseudoelement.setoid (P : C) : Setoid (Over P) := ⟨_, ⟨pseudoEqual_refl, @pseudoEqual_symm _ _ _, @pseudoEqual_trans _ _ _ _⟩⟩ attribute [local instance] Pseudoelement.setoid /-- A `Pseudoelement` of `P` is just an equivalence class of arrows ending in `P` by being pseudo-equal. -/ def Pseudoelement (P : C) : Type max u v := Quotient (Pseudoelement.setoid P) namespace Pseudoelement /-- A coercion from an object of an abelian category to its pseudoelements. -/ def objectToSort : CoeSort C (Type max u v) := ⟨fun P => Pseudoelement P⟩ attribute [local instance] objectToSort scoped[Pseudoelement] attribute [instance] CategoryTheory.Abelian.Pseudoelement.objectToSort /-- A coercion from an arrow with codomain `P` to its associated pseudoelement. -/ def overToSort {P : C} : Coe (Over P) (Pseudoelement P) := ⟨Quot.mk (PseudoEqual P)⟩ attribute [local instance] overToSort theorem over_coe_def {P Q : C} (a : Q ⟢ P) : (a : Pseudoelement P) = βŸ¦β†‘a⟧ := rfl /-- If two elements are pseudo-equal, then their composition with a morphism is, too. -/ theorem pseudoApply_aux {P Q : C} (f : P ⟢ Q) (a b : Over P) : a β‰ˆ b β†’ app f a β‰ˆ app f b := fun ⟨R, p, q, ep, Eq, comm⟩ => ⟨R, p, q, ep, Eq, show p ≫ a.hom ≫ f = q ≫ b.hom ≫ f by rw [reassoc_of% comm]⟩ /-- A morphism `f` induces a function `pseudoApply f` on pseudoelements. -/ def pseudoApply {P Q : C} (f : P ⟢ Q) : P β†’ Q := Quotient.map (fun g : Over P => app f g) (pseudoApply_aux f) /-- A coercion from morphisms to functions on pseudoelements. -/ def homToFun {P Q : C} : CoeFun (P ⟢ Q) fun _ => P β†’ Q := ⟨pseudoApply⟩ attribute [local instance] homToFun scoped[Pseudoelement] attribute [instance] CategoryTheory.Abelian.Pseudoelement.homToFun theorem pseudoApply_mk' {P Q : C} (f : P ⟢ Q) (a : Over P) : f ⟦a⟧ = βŸ¦β†‘(a.hom ≫ f)⟧ := rfl /-- Applying a pseudoelement to a composition of morphisms is the same as composing with each morphism. Sadly, this is not a definitional equality, but at least it is true. -/ theorem comp_apply {P Q R : C} (f : P ⟢ Q) (g : Q ⟢ R) (a : P) : (f ≫ g) a = g (f a) := Quotient.inductionOn a fun x => Quotient.sound <| by simp only [app] rw [← Category.assoc, Over.coe_hom] /-- Composition of functions on pseudoelements is composition of morphisms. -/ theorem comp_comp {P Q R : C} (f : P ⟢ Q) (g : Q ⟢ R) : g ∘ f = f ≫ g := funext fun _ => (comp_apply _ _ _).symm section Zero /-! In this section we prove that for every `P` there is an equivalence class that contains precisely all the zero morphisms ending in `P` and use this to define *the* zero pseudoelement. -/ section attribute [local instance] HasBinaryBiproducts.of_hasBinaryProducts /-- The arrows pseudo-equal to a zero morphism are precisely the zero morphisms. -/ theorem pseudoZero_aux {P : C} (Q : C) (f : Over P) : f β‰ˆ (0 : Q ⟢ P) ↔ f.hom = 0 := ⟨fun ⟨R, p, q, _, _, comm⟩ => zero_of_epi_comp p (by simp [comm]), fun hf => ⟨biprod f.1 Q, biprod.fst, biprod.snd, inferInstance, inferInstance, by rw [hf, Over.coe_hom, HasZeroMorphisms.comp_zero, HasZeroMorphisms.comp_zero]⟩⟩ end theorem zero_eq_zero' {P Q R : C} : (⟦((0 : Q ⟢ P) : Over P)⟧ : Pseudoelement P) = ⟦((0 : R ⟢ P) : Over P)⟧ := Quotient.sound <| (pseudoZero_aux R _).2 rfl /-- The zero pseudoelement is the class of a zero morphism. -/ def pseudoZero {P : C} : P := ⟦(0 : P ⟢ P)⟧ -- Porting note: in mathlib3, we couldn't make this an instance -- as it would have fired on `coe_sort`. -- However now that coercions are treated differently, this is a structural instance triggered by -- the appearance of `Pseudoelement`. instance hasZero {P : C} : Zero P := ⟨pseudoZero⟩ instance {P : C} : Inhabited P := ⟨0⟩ theorem pseudoZero_def {P : C} : (0 : Pseudoelement P) = βŸ¦β†‘(0 : P ⟢ P)⟧ := rfl @[simp] theorem zero_eq_zero {P Q : C} : ⟦((0 : Q ⟢ P) : Over P)⟧ = (0 : Pseudoelement P) := zero_eq_zero' /-- The pseudoelement induced by an arrow is zero precisely when that arrow is zero. -/ theorem pseudoZero_iff {P : C} (a : Over P) : a = (0 : P) ↔ a.hom = 0 := by rw [← pseudoZero_aux P a] exact Quotient.eq' end Zero open Pseudoelement /-- Morphisms map the zero pseudoelement to the zero pseudoelement. -/ @[simp] theorem apply_zero {P Q : C} (f : P ⟢ Q) : f 0 = 0 := by rw [pseudoZero_def, pseudoApply_mk'] simp /-- The zero morphism maps every pseudoelement to 0. -/ @[simp] theorem zero_apply {P : C} (Q : C) (a : P) : (0 : P ⟢ Q) a = 0 := Quotient.inductionOn a fun a' => by rw [pseudoZero_def, pseudoApply_mk'] simp /-- An extensionality lemma for being the zero arrow. -/ theorem zero_morphism_ext {P Q : C} (f : P ⟢ Q) : (βˆ€ a, f a = 0) β†’ f = 0 := fun h => by rw [← Category.id_comp f] exact (pseudoZero_iff (πŸ™ P ≫ f : Over Q)).1 (h (πŸ™ P)) theorem zero_morphism_ext' {P Q : C} (f : P ⟢ Q) : (βˆ€ a, f a = 0) β†’ 0 = f := Eq.symm ∘ zero_morphism_ext f theorem eq_zero_iff {P Q : C} (f : P ⟢ Q) : f = 0 ↔ βˆ€ a, f a = 0 := ⟨fun h a => by simp [h], zero_morphism_ext _⟩ /-- A monomorphism is injective on pseudoelements. -/ theorem pseudo_injective_of_mono {P Q : C} (f : P ⟢ Q) [Mono f] : Function.Injective f := by intro abar abar' refine Quotient.inductionOnβ‚‚ abar abar' fun a a' ha => ?_ apply Quotient.sound have : (⟦(a.hom ≫ f : Over Q)⟧ : Quotient (setoid Q)) = βŸ¦β†‘(a'.hom ≫ f)⟧ := by convert ha have ⟨R, p, q, ep, Eq, comm⟩ := Quotient.exact this exact ⟨R, p, q, ep, Eq, (cancel_mono f).1 <| by simp only [Category.assoc] exact comm⟩ /-- A morphism that is injective on pseudoelements only maps the zero element to zero. -/ theorem zero_of_map_zero {P Q : C} (f : P ⟢ Q) : Function.Injective f β†’ βˆ€ a, f a = 0 β†’ a = 0 := fun h a ha => by rw [← apply_zero f] at ha exact h ha /-- A morphism that only maps the zero pseudoelement to zero is a monomorphism. -/ theorem mono_of_zero_of_map_zero {P Q : C} (f : P ⟢ Q) : (βˆ€ a, f a = 0 β†’ a = 0) β†’ Mono f := fun h => (mono_iff_cancel_zero _).2 fun _ g hg => (pseudoZero_iff (g : Over P)).1 <| h _ <| show f g = 0 from (pseudoZero_iff (g ≫ f : Over Q)).2 hg section /-- An epimorphism is surjective on pseudoelements. -/ theorem pseudo_surjective_of_epi {P Q : C} (f : P ⟢ Q) [Epi f] : Function.Surjective f := fun qbar => Quotient.inductionOn qbar fun q => ⟨(pullback.fst f q.hom : Over P), Quotient.sound <| ⟨pullback f q.hom, πŸ™ (pullback f q.hom), pullback.snd _ _, inferInstance, inferInstance, by rw [Category.id_comp, ← pullback.condition, app_hom, Over.coe_hom]⟩⟩ end /-- A morphism that is surjective on pseudoelements is an epimorphism. -/ theorem epi_of_pseudo_surjective {P Q : C} (f : P ⟢ Q) : Function.Surjective f β†’ Epi f := by intro h have ⟨pbar, hpbar⟩ := h (πŸ™ Q) have ⟨p, hp⟩ := Quotient.exists_rep pbar have : (⟦(p.hom ≫ f : Over Q)⟧ : Quotient (setoid Q)) = βŸ¦β†‘(πŸ™ Q)⟧ := by rw [← hp] at hpbar exact hpbar have ⟨R, x, y, _, ey, comm⟩ := Quotient.exact this apply @epi_of_epi_fac _ _ _ _ _ (x ≫ p.hom) f y ey dsimp at comm rw [Category.assoc, comm] apply Category.comp_id section /-- Two morphisms in an exact sequence are exact on pseudoelements. -/ theorem pseudo_exact_of_exact {S : ShortComplex C} (hS : S.Exact) : βˆ€ b, S.g b = 0 β†’ βˆƒ a, S.f a = b := fun b' => Quotient.inductionOn b' fun b hb => by have hb' : b.hom ≫ S.g = 0 := (pseudoZero_iff _).1 hb -- By exactness, `b` factors through `im f = ker g` via some `c`. obtain ⟨c, hc⟩ := KernelFork.IsLimit.lift' hS.isLimitImage _ hb' -- We compute the pullback of the map into the image and `c`. -- The pseudoelement induced by the first pullback map will be our preimage. use pullback.fst (Abelian.factorThruImage S.f) c -- It remains to show that the image of this element under `f` is pseudo-equal to `b`. apply Quotient.sound refine ⟨pullback (Abelian.factorThruImage S.f) c, πŸ™ _, pullback.snd _ _, inferInstance, inferInstance, ?_⟩ -- Now we can verify that the diagram commutes. calc πŸ™ (pullback (Abelian.factorThruImage S.f) c) ≫ pullback.fst _ _ ≫ S.f = pullback.fst _ _ ≫ S.f := Category.id_comp _ _ = pullback.fst _ _ ≫ Abelian.factorThruImage S.f ≫ kernel.ΞΉ (cokernel.Ο€ S.f) := by rw [Abelian.image.fac] _ = (pullback.snd _ _ ≫ c) ≫ kernel.ΞΉ (cokernel.Ο€ S.f) := by rw [← Category.assoc, pullback.condition] _ = pullback.snd _ _ ≫ b.hom := by rw [Category.assoc] congr end theorem apply_eq_zero_of_comp_eq_zero {P Q R : C} (f : Q ⟢ R) (a : P ⟢ Q) : a ≫ f = 0 β†’ f a = 0 := fun h => by simp [over_coe_def, pseudoApply_mk', Over.coe_hom, h] section /-- If two morphisms are exact on pseudoelements, they are exact. -/ theorem exact_of_pseudo_exact (S : ShortComplex C) (hS : βˆ€ b, S.g b = 0 β†’ βˆƒ a, S.f a = b) : S.Exact := (S.exact_iff_kernel_ΞΉ_comp_cokernel_Ο€_zero).2 (by -- If we apply `g` to the pseudoelement induced by its kernel, we get 0 (of course!). have : S.g (kernel.ΞΉ S.g) = 0 := apply_eq_zero_of_comp_eq_zero _ _ (kernel.condition _) -- By pseudo-exactness, we get a preimage. obtain ⟨a', ha⟩ := hS _ this obtain ⟨a, ha'⟩ := Quotient.exists_rep a' rw [← ha'] at ha obtain ⟨Z, r, q, _, eq, comm⟩ := Quotient.exact ha -- Consider the pullback of `kernel.ΞΉ (cokernel.Ο€ f)` and `kernel.ΞΉ g`. -- The commutative diagram given by the pseudo-equality `f a = b` induces -- a cone over this pullback, so we get a factorization `z`. obtain ⟨z, _, hzβ‚‚βŸ© := @pullback.lift' _ _ _ _ _ _ (kernel.ΞΉ (cokernel.Ο€ S.f)) (kernel.ΞΉ S.g) _ (r ≫ a.hom ≫ Abelian.factorThruImage S.f) q (by simp only [Category.assoc, Abelian.image.fac] exact comm) -- Let's give a name to the second pullback morphism. let j : pullback (kernel.ΞΉ (cokernel.Ο€ S.f)) (kernel.ΞΉ S.g) ⟢ kernel S.g := pullback.snd _ _ -- Since `q` is an epimorphism, in particular this means that `j` is an epimorphism. haveI pe : Epi j := epi_of_epi_fac hzβ‚‚ -- But it is also a monomorphism, because `kernel.ΞΉ (cokernel.Ο€ f)` is: A kernel is -- always a monomorphism and the pullback of a monomorphism is a monomorphism. -- But mono + epi = iso, so `j` is an isomorphism. haveI : IsIso j := isIso_of_mono_of_epi _ -- But then `kernel.ΞΉ g` can be expressed using all of the maps of the pullback square, and we -- are done. rw [(Iso.eq_inv_comp (asIso j)).2 pullback.condition.symm] simp only [Category.assoc, kernel.condition, HasZeroMorphisms.comp_zero]) end /-- If two pseudoelements `x` and `y` have the same image under some morphism `f`, then we can form their "difference" `z`. This pseudoelement has the properties that `f z = 0` and for all morphisms `g`, if `g y = 0` then `g z = g x`. -/ theorem sub_of_eq_image {P Q : C} (f : P ⟢ Q) (x y : P) : f x = f y β†’ βˆƒ z, f z = 0 ∧ βˆ€ (R : C) (g : P ⟢ R), (g : P ⟢ R) y = 0 β†’ g z = g x := Quotient.inductionOnβ‚‚ x y fun a a' h => match Quotient.exact h with | ⟨R, p, q, ep, _, comm⟩ => let a'' : R ⟢ P := (p ≫ a.hom : R ⟢ P) - (q ≫ a'.hom : R ⟢ P) ⟨a'', ⟨show ⟦(a'' ≫ f : Over Q)⟧ = βŸ¦β†‘(0 : Q ⟢ Q)⟧ by dsimp at comm simp [a'', sub_eq_zero.2 comm], fun Z g hh => by obtain ⟨X, p', q', ep', _, comm'⟩ := Quotient.exact hh have : a'.hom ≫ g = 0 := by apply (epi_iff_cancel_zero _).1 ep' _ (a'.hom ≫ g) simpa using comm' apply Quotient.sound -- Can we prevent quotient.sound from giving us this weird `coe_b` thingy? change app g (a'' : Over P) β‰ˆ app g a exact ⟨R, πŸ™ R, p, inferInstance, ep, by simp [a'', sub_eq_add_neg, this]⟩⟩⟩ variable [Limits.HasPullbacks C] /-- If `f : P ⟢ R` and `g : Q ⟢ R` are morphisms and `p : P` and `q : Q` are pseudoelements such that `f p = g q`, then there is some `s : pullback f g` such that `fst s = p` and `snd s = q`. Remark: Borceux claims that `s` is unique, but this is false. See `Counterexamples/Pseudoelement.lean` for details. -/ theorem pseudo_pullback {P Q R : C} {f : P ⟢ R} {g : Q ⟢ R} {p : P} {q : Q} : f p = g q β†’ βˆƒ s, pullback.fst f g s = p ∧ pullback.snd f g s = q := Quotient.inductionOnβ‚‚ p q fun x y h => by obtain ⟨Z, a, b, ea, eb, comm⟩ := Quotient.exact h obtain ⟨l, hl₁, hlβ‚‚βŸ© := @pullback.lift' _ _ _ _ _ _ f g _ (a ≫ x.hom) (b ≫ y.hom) (by simp only [Category.assoc] exact comm) exact ⟨l, ⟨Quotient.sound ⟨Z, πŸ™ Z, a, inferInstance, ea, by rwa [Category.id_comp]⟩, Quotient.sound ⟨Z, πŸ™ Z, b, inferInstance, eb, by rwa [Category.id_comp]⟩⟩⟩ section Module /-- In the category `Module R`, if `x` and `y` are pseudoequal, then the range of the associated morphisms is the same. -/ theorem ModuleCat.eq_range_of_pseudoequal {R : Type*} [Ring R] {G : ModuleCat R} {x y : Over G} (h : PseudoEqual G x y) : LinearMap.range x.hom.hom = LinearMap.range y.hom.hom := by obtain ⟨P, p, q, hp, hq, H⟩ := h refine Submodule.ext fun a => ⟨fun ha => ?_, fun ha => ?_⟩ Β· obtain ⟨a', ha'⟩ := ha obtain ⟨a'', ha''⟩ := (ModuleCat.epi_iff_surjective p).1 hp a'
refine ⟨q a'', ?_⟩ dsimp at ha' ⊒ rw [← LinearMap.comp_apply, ← ModuleCat.hom_comp, ← H, ModuleCat.hom_comp, LinearMap.comp_apply, ha'', ha'] Β· obtain ⟨a', ha'⟩ := ha obtain ⟨a'', ha''⟩ := (ModuleCat.epi_iff_surjective q).1 hq a' refine ⟨p a'', ?_⟩ dsimp at ha' ⊒ rw [← LinearMap.comp_apply, ← ModuleCat.hom_comp, H, ModuleCat.hom_comp, LinearMap.comp_apply, ha'', ha'] end Module end Pseudoelement end CategoryTheory.Abelian
Mathlib/CategoryTheory/Abelian/Pseudoelements.lean
436
454
/- Copyright (c) 2022 Yuma Mizuno. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yuma Mizuno -/ import Mathlib.CategoryTheory.Bicategory.Coherence import Mathlib.Tactic.CategoryTheory.BicategoricalComp /-! # A `coherence` tactic for bicategories We provide a `bicategory_coherence` tactic, which proves that any two 2-morphisms (with the same source and target) in a bicategory which are built out of associators and unitors are equal. This file mainly deals with the type class setup for the coherence tactic. The actual front end tactic is given in `Mathlib.Tactic.CategoryTheory.Coherence` at the same time as the coherence tactic for monoidal categories. -/ noncomputable section universe w v u open CategoryTheory CategoryTheory.FreeBicategory open scoped Bicategory variable {B : Type u} [Bicategory.{w, v} B] {a b c d : B} namespace Mathlib.Tactic.BicategoryCoherence /-- A typeclass carrying a choice of lift of a 1-morphism from `B` to `FreeBicategory B`. -/ class LiftHom {a b : B} (f : a ⟢ b) where /-- A lift of a morphism to the free bicategory. This should only exist for "structural" morphisms. -/ lift : of.obj a ⟢ of.obj b instance liftHomId : LiftHom (πŸ™ a) where lift := πŸ™ (of.obj a) instance liftHomComp (f : a ⟢ b) (g : b ⟢ c) [LiftHom f] [LiftHom g] : LiftHom (f ≫ g) where lift := LiftHom.lift f ≫ LiftHom.lift g instance (priority := 100) liftHomOf (f : a ⟢ b) : LiftHom f where lift := of.map f /-- A typeclass carrying a choice of lift of a 2-morphism from `B` to `FreeBicategory B`. -/ class LiftHomβ‚‚ {f g : a ⟢ b} [LiftHom f] [LiftHom g] (Ξ· : f ⟢ g) where /-- A lift of a 2-morphism to the free bicategory. This should only exist for "structural" 2-morphisms. -/ lift : LiftHom.lift f ⟢ LiftHom.lift g instance liftHomβ‚‚Id (f : a ⟢ b) [LiftHom f] : LiftHomβ‚‚ (πŸ™ f) where lift := πŸ™ _ instance liftHomβ‚‚LeftUnitorHom (f : a ⟢ b) [LiftHom f] : LiftHomβ‚‚ (Ξ»_ f).hom where lift := (Ξ»_ (LiftHom.lift f)).hom instance liftHomβ‚‚LeftUnitorInv (f : a ⟢ b) [LiftHom f] : LiftHomβ‚‚ (Ξ»_ f).inv where lift := (Ξ»_ (LiftHom.lift f)).inv instance liftHomβ‚‚RightUnitorHom (f : a ⟢ b) [LiftHom f] : LiftHomβ‚‚ (ρ_ f).hom where lift := (ρ_ (LiftHom.lift f)).hom instance liftHomβ‚‚RightUnitorInv (f : a ⟢ b) [LiftHom f] : LiftHomβ‚‚ (ρ_ f).inv where lift := (ρ_ (LiftHom.lift f)).inv instance liftHomβ‚‚AssociatorHom (f : a ⟢ b) (g : b ⟢ c) (h : c ⟢ d) [LiftHom f] [LiftHom g] [LiftHom h] : LiftHomβ‚‚ (Ξ±_ f g h).hom where lift := (Ξ±_ (LiftHom.lift f) (LiftHom.lift g) (LiftHom.lift h)).hom instance liftHomβ‚‚AssociatorInv (f : a ⟢ b) (g : b ⟢ c) (h : c ⟢ d) [LiftHom f] [LiftHom g] [LiftHom h] : LiftHomβ‚‚ (Ξ±_ f g h).inv where lift := (Ξ±_ (LiftHom.lift f) (LiftHom.lift g) (LiftHom.lift h)).inv instance liftHomβ‚‚Comp {f g h : a ⟢ b} [LiftHom f] [LiftHom g] [LiftHom h] (Ξ· : f ⟢ g) (ΞΈ : g ⟢ h) [LiftHomβ‚‚ Ξ·] [LiftHomβ‚‚ ΞΈ] : LiftHomβ‚‚ (Ξ· ≫ ΞΈ) where lift := LiftHomβ‚‚.lift Ξ· ≫ LiftHomβ‚‚.lift ΞΈ instance liftHomβ‚‚WhiskerLeft (f : a ⟢ b) [LiftHom f] {g h : b ⟢ c} (Ξ· : g ⟢ h) [LiftHom g] [LiftHom h] [LiftHomβ‚‚ Ξ·] : LiftHomβ‚‚ (f ◁ Ξ·) where lift := LiftHom.lift f ◁ LiftHomβ‚‚.lift Ξ· instance liftHomβ‚‚WhiskerRight {f g : a ⟢ b} (Ξ· : f ⟢ g) [LiftHom f] [LiftHom g] [LiftHomβ‚‚ Ξ·] {h : b ⟢ c} [LiftHom h] : LiftHomβ‚‚ (Ξ· β–· h) where lift := LiftHomβ‚‚.lift Ξ· β–· LiftHom.lift h open Lean Elab Tactic Meta /-- Helper function for throwing exceptions. -/ def exception {Ξ± : Type} (g : MVarId) (msg : MessageData) : MetaM Ξ± := throwTacticEx `bicategorical_coherence g msg /-- Helper function for throwing exceptions with respect to the main goal. -/ def exception' (msg : MessageData) : TacticM Unit := do try liftMetaTactic (exception (msg := msg)) catch _ => -- There might not be any goals throwError msg set_option quotPrecheck false in /-- Auxiliary definition for `bicategorical_coherence`. -/ -- We could construct this expression directly without using `elabTerm`, -- but it would require preparing many implicit arguments by hand. def mkLiftMapβ‚‚LiftExpr (e : Expr) : TermElabM Expr := do Term.elabTerm (← ``((FreeBicategory.lift (Prefunctor.id _)).mapβ‚‚ (LiftHomβ‚‚.lift $(← Term.exprToSyntax e)))) none /-- Coherence tactic for bicategories. -/ def bicategory_coherence (g : MVarId) : TermElabM Unit := g.withContext do withOptions (fun opts => synthInstance.maxSize.set opts (max 256 (synthInstance.maxSize.get opts))) do let thms := [``BicategoricalCoherence.iso, ``Iso.trans, ``Iso.symm, ``Iso.refl, ``Bicategory.whiskerRightIso, ``Bicategory.whiskerLeftIso].foldl (Β·.addDeclToUnfoldCore Β·) {} let (ty, _) ← dsimp (← g.getType) (← Simp.mkContext (simpTheorems := #[thms])) let some (_, lhs, rhs) := (← whnfR ty).eq? | exception g "Not an equation of morphisms." let lift_lhs ← mkLiftMapβ‚‚LiftExpr lhs let lift_rhs ← mkLiftMapβ‚‚LiftExpr rhs -- This new equation is defeq to the original by assumption -- on the `LiftHom` instances. let g₁ ← g.change (← mkEq lift_lhs lift_rhs) let [gβ‚‚] ← g₁.applyConst ``congrArg | exception g "congrArg failed in coherence" let [] ← gβ‚‚.applyConst ``Subsingleton.elim | exception g "This shouldn't happen; Subsingleton.elim does not create goals." /-- Coherence tactic for bicategories. Use `pure_coherence` instead, which is a frontend to this one. -/ elab "bicategory_coherence" : tactic => do bicategory_coherence (← getMainGoal) open Lean.Parser.Tactic /-- Simp lemmas for rewriting a 2-morphism into a normal form. -/ syntax (name := whisker_simps) "whisker_simps" optConfig : tactic @[inherit_doc whisker_simps] elab_rules : tactic | `(tactic| whisker_simps $cfg) => do evalTactic (← `(tactic| simp $cfg only [Category.assoc, Bicategory.comp_whiskerLeft, Bicategory.id_whiskerLeft, Bicategory.whiskerRight_comp, Bicategory.whiskerRight_id, Bicategory.whiskerLeft_comp, Bicategory.whiskerLeft_id, Bicategory.comp_whiskerRight, Bicategory.id_whiskerRight, Bicategory.whisker_assoc] )) -- We have unused typeclass arguments here. -- They are intentional, to ensure that `simp only [assoc_liftHomβ‚‚]` only left associates -- bicategorical structural morphisms. /-- Auxiliary simp lemma for the `coherence` tactic: this move brackets to the left in order to expose a maximal prefix built out of unitors and associators. -/ @[nolint unusedArguments] theorem assoc_liftHomβ‚‚ {f g h i : a ⟢ b} [LiftHom f] [LiftHom g] [LiftHom h] (Ξ· : f ⟢ g) (ΞΈ : g ⟢ h) (ΞΉ : h ⟢ i) [LiftHomβ‚‚ Ξ·] [LiftHomβ‚‚ ΞΈ] : Ξ· ≫ ΞΈ ≫ ΞΉ = (Ξ· ≫ ΞΈ) ≫ ΞΉ := (Category.assoc _ _ _).symm end Mathlib.Tactic.BicategoryCoherence
Mathlib/Tactic/CategoryTheory/BicategoryCoherence.lean
242
243
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes HΓΆlzl, Patrick Massot -/ import Mathlib.Data.Set.Image import Mathlib.Data.SProd /-! # Sets in product and pi types This file proves basic properties of product of sets in `Ξ± Γ— Ξ²` and in `Ξ  i, Ξ± i`, and of the diagonal of a type. ## Main declarations This file contains basic results on the following notions, which are defined in `Set.Operations`. * `Set.prod`: Binary product of sets. For `s : Set Ξ±`, `t : Set Ξ²`, we have `s.prod t : Set (Ξ± Γ— Ξ²)`. Denoted by `s Γ—Λ’ t`. * `Set.diagonal`: Diagonal of a type. `Set.diagonal Ξ± = {(x, x) | x : Ξ±}`. * `Set.offDiag`: Off-diagonal. `s Γ—Λ’ s` without the diagonal. * `Set.pi`: Arbitrary product of sets. -/ open Function namespace Set /-! ### Cartesian binary product of sets -/ section Prod variable {Ξ± Ξ² Ξ³ Ξ΄ : Type*} {s s₁ sβ‚‚ : Set Ξ±} {t t₁ tβ‚‚ : Set Ξ²} {a : Ξ±} {b : Ξ²} theorem Subsingleton.prod (hs : s.Subsingleton) (ht : t.Subsingleton) : (s Γ—Λ’ t).Subsingleton := fun _x hx _y hy ↦ Prod.ext (hs hx.1 hy.1) (ht hx.2 hy.2) noncomputable instance decidableMemProd [DecidablePred (Β· ∈ s)] [DecidablePred (Β· ∈ t)] : DecidablePred (Β· ∈ s Γ—Λ’ t) := fun x => inferInstanceAs (Decidable (x.1 ∈ s ∧ x.2 ∈ t)) @[gcongr] theorem prod_mono (hs : s₁ βŠ† sβ‚‚) (ht : t₁ βŠ† tβ‚‚) : s₁ Γ—Λ’ t₁ βŠ† sβ‚‚ Γ—Λ’ tβ‚‚ := fun _ ⟨h₁, hβ‚‚βŸ© => ⟨hs h₁, ht hβ‚‚βŸ© @[gcongr] theorem prod_mono_left (hs : s₁ βŠ† sβ‚‚) : s₁ Γ—Λ’ t βŠ† sβ‚‚ Γ—Λ’ t := prod_mono hs Subset.rfl @[gcongr] theorem prod_mono_right (ht : t₁ βŠ† tβ‚‚) : s Γ—Λ’ t₁ βŠ† s Γ—Λ’ tβ‚‚ := prod_mono Subset.rfl ht @[simp] theorem prod_self_subset_prod_self : s₁ Γ—Λ’ s₁ βŠ† sβ‚‚ Γ—Λ’ sβ‚‚ ↔ s₁ βŠ† sβ‚‚ := ⟨fun h _ hx => (h (mk_mem_prod hx hx)).1, fun h _ hx => ⟨h hx.1, h hx.2⟩⟩ @[simp] theorem prod_self_ssubset_prod_self : s₁ Γ—Λ’ s₁ βŠ‚ sβ‚‚ Γ—Λ’ sβ‚‚ ↔ s₁ βŠ‚ sβ‚‚ := and_congr prod_self_subset_prod_self <| not_congr prod_self_subset_prod_self theorem prod_subset_iff {P : Set (Ξ± Γ— Ξ²)} : s Γ—Λ’ t βŠ† P ↔ βˆ€ x ∈ s, βˆ€ y ∈ t, (x, y) ∈ P := ⟨fun h _ hx _ hy => h (mk_mem_prod hx hy), fun h ⟨_, _⟩ hp => h _ hp.1 _ hp.2⟩ theorem forall_prod_set {p : Ξ± Γ— Ξ² β†’ Prop} : (βˆ€ x ∈ s Γ—Λ’ t, p x) ↔ βˆ€ x ∈ s, βˆ€ y ∈ t, p (x, y) := prod_subset_iff theorem exists_prod_set {p : Ξ± Γ— Ξ² β†’ Prop} : (βˆƒ x ∈ s Γ—Λ’ t, p x) ↔ βˆƒ x ∈ s, βˆƒ y ∈ t, p (x, y) := by simp [and_assoc] @[simp] theorem prod_empty : s Γ—Λ’ (βˆ… : Set Ξ²) = βˆ… := by ext exact iff_of_eq (and_false _) @[simp] theorem empty_prod : (βˆ… : Set Ξ±) Γ—Λ’ t = βˆ… := by ext exact iff_of_eq (false_and _) @[simp, mfld_simps] theorem univ_prod_univ : @univ Ξ± Γ—Λ’ @univ Ξ² = univ := by ext exact iff_of_eq (true_and _) theorem univ_prod {t : Set Ξ²} : (univ : Set Ξ±) Γ—Λ’ t = Prod.snd ⁻¹' t := by simp [prod_eq] theorem prod_univ {s : Set Ξ±} : s Γ—Λ’ (univ : Set Ξ²) = Prod.fst ⁻¹' s := by simp [prod_eq] @[simp] lemma prod_eq_univ [Nonempty Ξ±] [Nonempty Ξ²] : s Γ—Λ’ t = univ ↔ s = univ ∧ t = univ := by simp [eq_univ_iff_forall, forall_and] theorem singleton_prod : ({a} : Set Ξ±) Γ—Λ’ t = Prod.mk a '' t := by ext ⟨x, y⟩ simp [and_left_comm, eq_comm] theorem prod_singleton : s Γ—Λ’ ({b} : Set Ξ²) = (fun a => (a, b)) '' s := by ext ⟨x, y⟩ simp [and_left_comm, eq_comm] @[simp] theorem singleton_prod_singleton : ({a} : Set Ξ±) Γ—Λ’ ({b} : Set Ξ²) = {(a, b)} := by ext ⟨c, d⟩; simp @[simp] theorem union_prod : (s₁ βˆͺ sβ‚‚) Γ—Λ’ t = s₁ Γ—Λ’ t βˆͺ sβ‚‚ Γ—Λ’ t := by ext ⟨x, y⟩ simp [or_and_right] @[simp] theorem prod_union : s Γ—Λ’ (t₁ βˆͺ tβ‚‚) = s Γ—Λ’ t₁ βˆͺ s Γ—Λ’ tβ‚‚ := by ext ⟨x, y⟩ simp [and_or_left] theorem inter_prod : (s₁ ∩ sβ‚‚) Γ—Λ’ t = s₁ Γ—Λ’ t ∩ sβ‚‚ Γ—Λ’ t := by ext ⟨x, y⟩ simp only [← and_and_right, mem_inter_iff, mem_prod] theorem prod_inter : s Γ—Λ’ (t₁ ∩ tβ‚‚) = s Γ—Λ’ t₁ ∩ s Γ—Λ’ tβ‚‚ := by ext ⟨x, y⟩ simp only [← and_and_left, mem_inter_iff, mem_prod] @[mfld_simps] theorem prod_inter_prod : s₁ Γ—Λ’ t₁ ∩ sβ‚‚ Γ—Λ’ tβ‚‚ = (s₁ ∩ sβ‚‚) Γ—Λ’ (t₁ ∩ tβ‚‚) := by ext ⟨x, y⟩ simp [and_assoc, and_left_comm] lemma compl_prod_eq_union {Ξ± Ξ² : Type*} (s : Set Ξ±) (t : Set Ξ²) : (s Γ—Λ’ t)ᢜ = (sᢜ Γ—Λ’ univ) βˆͺ (univ Γ—Λ’ tᢜ) := by ext p simp only [mem_compl_iff, mem_prod, not_and, mem_union, mem_univ, and_true, true_and] constructor <;> intro h Β· by_cases fst_in_s : p.fst ∈ s Β· exact Or.inr (h fst_in_s) Β· exact Or.inl fst_in_s Β· intro fst_in_s simpa only [fst_in_s, not_true, false_or] using h @[simp] theorem disjoint_prod : Disjoint (s₁ Γ—Λ’ t₁) (sβ‚‚ Γ—Λ’ tβ‚‚) ↔ Disjoint s₁ sβ‚‚ ∨ Disjoint t₁ tβ‚‚ := by simp_rw [disjoint_left, mem_prod, not_and_or, Prod.forall, and_imp, ← @forall_or_right Ξ±, ← @forall_or_left Ξ², ← @forall_or_right (_ ∈ s₁), ← @forall_or_left (_ ∈ t₁)] theorem Disjoint.set_prod_left (hs : Disjoint s₁ sβ‚‚) (t₁ tβ‚‚ : Set Ξ²) : Disjoint (s₁ Γ—Λ’ t₁) (sβ‚‚ Γ—Λ’ tβ‚‚) := disjoint_left.2 fun ⟨_a, _b⟩ ⟨ha₁, _⟩ ⟨haβ‚‚, _⟩ => disjoint_left.1 hs ha₁ haβ‚‚ theorem Disjoint.set_prod_right (ht : Disjoint t₁ tβ‚‚) (s₁ sβ‚‚ : Set Ξ±) : Disjoint (s₁ Γ—Λ’ t₁) (sβ‚‚ Γ—Λ’ tβ‚‚) := disjoint_left.2 fun ⟨_a, _b⟩ ⟨_, hbβ‚βŸ© ⟨_, hbβ‚‚βŸ© => disjoint_left.1 ht hb₁ hbβ‚‚ theorem prodMap_image_prod (f : Ξ± β†’ Ξ²) (g : Ξ³ β†’ Ξ΄) (s : Set Ξ±) (t : Set Ξ³) : (Prod.map f g) '' (s Γ—Λ’ t) = (f '' s) Γ—Λ’ (g '' t) := by ext aesop theorem insert_prod : insert a s Γ—Λ’ t = Prod.mk a '' t βˆͺ s Γ—Λ’ t := by simp only [insert_eq, union_prod, singleton_prod] theorem prod_insert : s Γ—Λ’ insert b t = (fun a => (a, b)) '' s βˆͺ s Γ—Λ’ t := by simp only [insert_eq, prod_union, prod_singleton] theorem prod_preimage_eq {f : Ξ³ β†’ Ξ±} {g : Ξ΄ β†’ Ξ²} : (f ⁻¹' s) Γ—Λ’ (g ⁻¹' t) = (fun p : Ξ³ Γ— Ξ΄ => (f p.1, g p.2)) ⁻¹' s Γ—Λ’ t := rfl theorem prod_preimage_left {f : Ξ³ β†’ Ξ±} : (f ⁻¹' s) Γ—Λ’ t = (fun p : Ξ³ Γ— Ξ² => (f p.1, p.2)) ⁻¹' s Γ—Λ’ t := rfl theorem prod_preimage_right {g : Ξ΄ β†’ Ξ²} : s Γ—Λ’ (g ⁻¹' t) = (fun p : Ξ± Γ— Ξ΄ => (p.1, g p.2)) ⁻¹' s Γ—Λ’ t := rfl theorem preimage_prod_map_prod (f : Ξ± β†’ Ξ²) (g : Ξ³ β†’ Ξ΄) (s : Set Ξ²) (t : Set Ξ΄) : Prod.map f g ⁻¹' s Γ—Λ’ t = (f ⁻¹' s) Γ—Λ’ (g ⁻¹' t) := rfl theorem mk_preimage_prod (f : Ξ³ β†’ Ξ±) (g : Ξ³ β†’ Ξ²) : (fun x => (f x, g x)) ⁻¹' s Γ—Λ’ t = f ⁻¹' s ∩ g ⁻¹' t := rfl @[simp] theorem mk_preimage_prod_left (hb : b ∈ t) : (fun a => (a, b)) ⁻¹' s Γ—Λ’ t = s := by ext a simp [hb] @[simp] theorem mk_preimage_prod_right (ha : a ∈ s) : Prod.mk a ⁻¹' s Γ—Λ’ t = t := by ext b simp [ha] @[simp] theorem mk_preimage_prod_left_eq_empty (hb : b βˆ‰ t) : (fun a => (a, b)) ⁻¹' s Γ—Λ’ t = βˆ… := by ext a simp [hb] @[simp] theorem mk_preimage_prod_right_eq_empty (ha : a βˆ‰ s) : Prod.mk a ⁻¹' s Γ—Λ’ t = βˆ… := by ext b simp [ha] theorem mk_preimage_prod_left_eq_if [DecidablePred (Β· ∈ t)] : (fun a => (a, b)) ⁻¹' s Γ—Λ’ t = if b ∈ t then s else βˆ… := by split_ifs with h <;> simp [h] theorem mk_preimage_prod_right_eq_if [DecidablePred (Β· ∈ s)] : Prod.mk a ⁻¹' s Γ—Λ’ t = if a ∈ s then t else βˆ… := by split_ifs with h <;> simp [h] theorem mk_preimage_prod_left_fn_eq_if [DecidablePred (Β· ∈ t)] (f : Ξ³ β†’ Ξ±) : (fun a => (f a, b)) ⁻¹' s Γ—Λ’ t = if b ∈ t then f ⁻¹' s else βˆ… := by rw [← mk_preimage_prod_left_eq_if, prod_preimage_left, preimage_preimage] theorem mk_preimage_prod_right_fn_eq_if [DecidablePred (Β· ∈ s)] (g : Ξ΄ β†’ Ξ²) : (fun b => (a, g b)) ⁻¹' s Γ—Λ’ t = if a ∈ s then g ⁻¹' t else βˆ… := by rw [← mk_preimage_prod_right_eq_if, prod_preimage_right, preimage_preimage] @[simp] theorem preimage_swap_prod (s : Set Ξ±) (t : Set Ξ²) : Prod.swap ⁻¹' s Γ—Λ’ t = t Γ—Λ’ s := by ext ⟨x, y⟩ simp [and_comm] @[simp] theorem image_swap_prod (s : Set Ξ±) (t : Set Ξ²) : Prod.swap '' s Γ—Λ’ t = t Γ—Λ’ s := by rw [image_swap_eq_preimage_swap, preimage_swap_prod] theorem mapsTo_swap_prod (s : Set Ξ±) (t : Set Ξ²) : MapsTo Prod.swap (s Γ—Λ’ t) (t Γ—Λ’ s) := fun _ ⟨hx, hy⟩ ↦ ⟨hy, hx⟩
theorem prod_image_image_eq {m₁ : Ξ± β†’ Ξ³} {mβ‚‚ : Ξ² β†’ Ξ΄} : (m₁ '' s) Γ—Λ’ (mβ‚‚ '' t) = (fun p : Ξ± Γ— Ξ² => (m₁ p.1, mβ‚‚ p.2)) '' s Γ—Λ’ t := ext <| by
Mathlib/Data/Set/Prod.lean
231
233
/- 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 -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Normed.Group.AddTorsor import Mathlib.Analysis.Normed.Module.Convex import Mathlib.Analysis.RCLike.Basic import Mathlib.Topology.Instances.RealVectorSpace import Mathlib.Topology.LocallyConstant.Basic /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `RCLike`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prodMk hB have : IsClosed s := by simp only [s, inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy rcases hxB.lt_or_eq with hxB | hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine nonempty_of_mem (inter_mem ?_ (Ioc_mem_nhdsGT hy)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsGT_of_mem xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y := hf'.and_eventually (HB.and (Ioc_mem_nhdsGT hy)) |>.exists refine ⟨z, ?_, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_iff_of_pos_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simp [g, hf' x hx] let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only [g, B]; rw [sub_self, norm_zero, sub_self, mul_zero] /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => ?_) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem_nhdsWithin (Icc_mem_nhdsGE_of_mem hx) /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine norm_image_sub_le_of_norm_deriv_le_segment' ?_ bound exact fun x hx => (hf x hx).hasDerivWithinAt /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem_nhdsWithin (Icc_mem_nhdsGE_of_mem hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem_nhdsWithin (Icc_mem_nhdsGE_of_mem hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[NontriviallyNormedField π•œ] [IsRCLikeNormedField π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section namespace Convex variable {π•œ G : Type*} [NontriviallyNormedField π•œ] [IsRCLikeNormedField π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} instance (priority := 100) : PathConnectedSpace π•œ := by letI : RCLike π•œ := IsRCLikeNormedField.rclike π•œ infer_instance /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : RCLike π•œ := IsRCLikeNormedField.rclike π•œ letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_opNorm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa [g] using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } := mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), ?_⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono inter_subset_left) fun y hy => (hΞ΅ hy).2.le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by letI : RCLike π•œ := IsRCLikeNormedField.rclike π•œ let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOnWith_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp [g] _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by letI : RCLike π•œ := IsRCLikeNormedField.rclike π•œ let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : s.EqOn (fderivWithin π•œ f s) (fderivWithin π•œ g s)) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => ?_) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' hz] /-- If `f` has zero derivative on an open set, then `f` is locally constant on `s`. -/ -- TODO: change the spelling once we have `IsLocallyConstantOn`. theorem _root_.IsOpen.isOpen_inter_preimage_of_fderiv_eq_zero (hs : IsOpen s) (hf : DifferentiableOn π•œ f s) (hf' : s.EqOn (fderiv π•œ f) 0) (t : Set G) : IsOpen (s ∩ f ⁻¹' t) := by refine Metric.isOpen_iff.mpr fun y ⟨hy, hy'⟩ ↦ ?_ obtain ⟨r, hr, h⟩ := Metric.isOpen_iff.mp hs y hy refine ⟨r, hr, Set.subset_inter h fun x hx ↦ ?_⟩ have := (convex_ball y r).is_const_of_fderivWithin_eq_zero (hf.mono h) ?_ hx (mem_ball_self hr) Β· simpa [this] Β· intro z hz simpa only [fderivWithin_of_isOpen Metric.isOpen_ball hz] using hf' (h hz) theorem _root_.isLocallyConstant_of_fderiv_eq_zero (h₁ : Differentiable π•œ f) (hβ‚‚ : βˆ€ x, fderiv π•œ f x = 0) : IsLocallyConstant f := by simpa using isOpen_univ.isOpen_inter_preimage_of_fderiv_eq_zero h₁.differentiableOn fun _ _ ↦ hβ‚‚ _ /-- If `f` has zero derivative on a connected open set, then `f` is constant on `s`. -/ theorem _root_.IsOpen.exists_is_const_of_fderiv_eq_zero (hs : IsOpen s) (hs' : IsPreconnected s) (hf : DifferentiableOn π•œ f s) (hf' : s.EqOn (fderiv π•œ f) 0) : βˆƒ a, βˆ€ x ∈ s, f x = a := by obtain (rfl|⟨y, hy⟩) := s.eq_empty_or_nonempty Β· exact ⟨0, by simp⟩ Β· refine ⟨f y, fun x hx ↦ ?_⟩ have h₁ := hs.isOpen_inter_preimage_of_fderiv_eq_zero hf hf' {f y} have hβ‚‚ := hf.continuousOn.comp_continuous continuous_subtype_val (fun x ↦ x.2) by_contra h₃ obtain ⟨t, ht, ht'⟩ := (isClosed_singleton (x := f y)).preimage hβ‚‚ have ht'' : βˆ€ a ∈ s, a ∈ t ↔ f a β‰  f y := by simpa [Set.ext_iff] using ht' obtain ⟨z, H₁, Hβ‚‚, Hβ‚ƒβŸ© := hs' _ _ h₁ ht (fun x h ↦ by simp [h, ht'', eq_or_ne]) ⟨y, by simpa⟩ ⟨x, by simp [ht'' _ hx, hx, h₃]⟩ exact (ht'' _ H₁).mp H₃ Hβ‚‚.2 theorem _root_.IsOpen.is_const_of_fderiv_eq_zero (hs : IsOpen s) (hs' : IsPreconnected s) (hf : DifferentiableOn π•œ f s) (hf' : s.EqOn (fderiv π•œ f) 0) {x y : E} (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by obtain ⟨a, ha⟩ := hs.exists_is_const_of_fderiv_eq_zero hs' hf hf' rw [ha x hx, ha y hy] theorem _root_.IsOpen.exists_eq_add_of_fderiv_eq (hs : IsOpen s) (hs' : IsPreconnected s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hf' : s.EqOn (fderiv π•œ f) (fderiv π•œ g)) : βˆƒ a, s.EqOn f (g Β· + a) := by simp_rw [Set.EqOn, ← sub_eq_iff_eq_add'] refine hs.exists_is_const_of_fderiv_eq_zero hs' (hf.sub hg) fun x hx ↦ ?_ rw [fderiv_sub (hf.differentiableAt (hs.mem_nhds hx)) (hg.differentiableAt (hs.mem_nhds hx)), hf' hx, sub_self, Pi.zero_apply] /-- If two functions have equal FrΓ©chet derivatives at every point of a connected open set, and are equal at one point in that set, then they are equal on that set. -/ theorem _root_.IsOpen.eqOn_of_fderiv_eq (hs : IsOpen s) (hs' : IsPreconnected s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hf' : βˆ€ x ∈ s, fderiv π•œ f x = fderiv π•œ g x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := by obtain ⟨a, ha⟩ := hs.exists_eq_add_of_fderiv_eq hs' hf hg hf' obtain rfl := left_eq_add.mp (hfgx.symm.trans (ha hx)) simpa using ha theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by letI : RCLike π•œ := IsRCLikeNormedField.rclike π•œ let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx lemma isLittleO_pow_succ {xβ‚€ : E} {n : β„•} (hs : Convex ℝ s) (hxβ‚€s : xβ‚€ ∈ s) (hff' : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (hf' : f' =o[𝓝[s] xβ‚€] fun x ↦ β€–x - xβ‚€β€– ^ n) : (fun x ↦ f x - f xβ‚€) =o[𝓝[s] xβ‚€] fun x ↦ β€–x - xβ‚€β€– ^ (n + 1) := by rw [Asymptotics.isLittleO_iff] at hf' ⊒ intro c hc simp_rw [norm_pow, pow_succ, ← mul_assoc, norm_norm] simp_rw [norm_pow, norm_norm] at hf' have : βˆ€αΆ  x in 𝓝[s] xβ‚€, segment ℝ xβ‚€ x βŠ† s ∧ βˆ€ y ∈ segment ℝ xβ‚€ x, β€–f' yβ€– ≀ c * β€–x - xβ‚€β€– ^ n := by have h1 : βˆ€αΆ  x in 𝓝[s] xβ‚€, x ∈ s := eventually_mem_nhdsWithin filter_upwards [h1, hs.eventually_nhdsWithin_segment hxβ‚€s (hf' hc)] with x hxs h refine ⟨hs.segment_subset hxβ‚€s hxs, fun y hy ↦ (h y hy).trans ?_⟩ gcongr exact norm_sub_le_of_mem_segment hy filter_upwards [this] with x ⟨h_segment, h⟩ convert (convex_segment xβ‚€ x).norm_image_sub_le_of_norm_hasFDerivWithin_le (f := fun x ↦ f x - f xβ‚€) (y := x) (x := xβ‚€) (s := segment ℝ xβ‚€ x) ?_ h (left_mem_segment ℝ xβ‚€ x) (right_mem_segment ℝ xβ‚€ x) using 1 Β· simp Β· simp only [hasFDerivWithinAt_sub_const_iff] exact fun x hx ↦ (hff' x (h_segment hx)).mono h_segment theorem isLittleO_pow_succ_real {f f' : ℝ β†’ E} {xβ‚€ : ℝ} {n : β„•} {s : Set ℝ} (hs : Convex ℝ s) (hxβ‚€s : xβ‚€ ∈ s) (hff' : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (hf' : f' =o[𝓝[s] xβ‚€] fun x ↦ (x - xβ‚€) ^ n) : (fun x ↦ f x - f xβ‚€) =o[𝓝[s] xβ‚€] fun x ↦ (x - xβ‚€) ^ (n + 1) := by have h := hs.isLittleO_pow_succ hxβ‚€s hff' ?_ (n := n) Β· rw [Asymptotics.isLittleO_iff] at h ⊒ simpa using h Β· rw [Asymptotics.isLittleO_iff] at hf' ⊒ convert hf' using 4 with c hc x simp end Convex namespace Convex variable {π•œ G : Type*} [RCLike π•œ] [NormedAddCommGroup G] [NormedSpace π•œ G] {f f' : π•œ β†’ G} {s : Set π•œ} {x y : π•œ} /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasDerivWithin_le {C : ℝ} (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs xs ys /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasDerivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `derivWithin` -/ theorem norm_image_sub_le_of_norm_derivWithin_le {C : ℝ} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound xs ys /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `derivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_derivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv`. -/ theorem norm_image_sub_le_of_norm_deriv_le {C : ℝ} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound xs ys /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `deriv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound /-- The mean value theorem set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–deriv f xβ€–β‚Š ≀ C) : LipschitzWith C f := lipschitzOnWith_univ.1 <| convex_univ.lipschitzOnWith_of_nnnorm_deriv_le (fun x _ => hf x) fun x _ => bound x /-- If `f : π•œ β†’ G`, `π•œ = R` or `π•œ = β„‚`, is differentiable everywhere and its derivative equal zero, then it is a constant function. -/ theorem _root_.is_const_of_deriv_eq_zero (hf : Differentiable π•œ f) (hf' : βˆ€ x, deriv f x = 0) (x y : π•œ) : f x = f y := is_const_of_fderiv_eq_zero hf (fun z => by ext; simp [← deriv_fderiv, hf']) _ _ theorem _root_.IsOpen.isOpen_inter_preimage_of_deriv_eq_zero (hs : IsOpen s) (hf : DifferentiableOn π•œ f s) (hf' : s.EqOn (deriv f) 0) (t : Set G) : IsOpen (s ∩ f ⁻¹' t) := hs.isOpen_inter_preimage_of_fderiv_eq_zero hf (fun x hx ↦ by ext; simp [← deriv_fderiv, hf' hx]) t theorem _root_.IsOpen.exists_is_const_of_deriv_eq_zero (hs : IsOpen s) (hs' : IsPreconnected s) (hf : DifferentiableOn π•œ f s) (hf' : s.EqOn (deriv f) 0) : βˆƒ a, βˆ€ x ∈ s, f x = a := hs.exists_is_const_of_fderiv_eq_zero hs' hf (fun {x} hx ↦ by ext; simp [← deriv_fderiv, hf' hx]) theorem _root_.IsOpen.is_const_of_deriv_eq_zero (hs : IsOpen s) (hs' : IsPreconnected s) (hf : DifferentiableOn π•œ f s) (hf' : s.EqOn (deriv f) 0) {x y : π•œ} (hx : x ∈ s) (hy : y ∈ s) : f x = f y := hs.is_const_of_fderiv_eq_zero hs' hf (fun a ha ↦ by ext; simp [← deriv_fderiv, hf' ha]) hx hy theorem _root_.IsOpen.exists_eq_add_of_deriv_eq {f g : π•œ β†’ G} (hs : IsOpen s) (hs' : IsPreconnected s)
(hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hf' : s.EqOn (deriv f) (deriv g)) : βˆƒ a, s.EqOn f (g Β· + a) := hs.exists_eq_add_of_fderiv_eq hs' hf hg (fun x hx ↦ by ext; simp [← deriv_fderiv, hf' hx]) theorem _root_.IsOpen.eqOn_of_deriv_eq {f g : π•œ β†’ G} (hs : IsOpen s) (hs' : IsPreconnected s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s)
Mathlib/Analysis/Calculus/MeanValue.lean
767
772
/- Copyright (c) 2023 JoΓ«l Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: JoΓ«l Riou -/ import Mathlib.Algebra.Homology.HomotopyCategory.HomComplex import Mathlib.Algebra.Homology.HomotopyCategory.Shift /-! Shifting cochains Let `C` be a preadditive category. Given two cochain complexes (indexed by `β„€`), the type of cochains `HomComplex.Cochain K L n` of degree `n` was introduced in `Mathlib.Algebra.Homology.HomotopyCategory.HomComplex`. In this file, we study how these cochains behave with respect to the shift on the complexes `K` and `L`. When `n`, `a`, `n'` are integers such that `h : n' + a = n`, we obtain `rightShiftAddEquiv K L n a n' h : Cochain K L n ≃+ Cochain K (L⟦a⟧) n'`. This definition does not involve signs, but the analogous definition of `leftShiftAddEquiv K L n a n' h' : Cochain K L n ≃+ Cochain (K⟦a⟧) L n'` when `h' : n + a = n'` does involve signs, as we follow the conventions appearing in the introduction of [Brian Conrad's book *Grothendieck duality and base change*][conrad2000]. ## References * [Brian Conrad, Grothendieck duality and base change][conrad2000] -/ assert_not_exists TwoSidedIdeal open CategoryTheory Category Limits Preadditive universe v u variable {C : Type u} [Category.{v} C] [Preadditive C] {R : Type*} [Ring R] [Linear R C] {K L M : CochainComplex C β„€} {n : β„€} namespace CochainComplex.HomComplex namespace Cochain variable (Ξ³ γ₁ Ξ³β‚‚ : Cochain K L n) /-- The map `Cochain K L n β†’ Cochain K (L⟦a⟧) n'` when `n' + a = n`. -/ def rightShift (a n' : β„€) (hn' : n' + a = n) : Cochain K (L⟦a⟧) n' := Cochain.mk (fun p q hpq => Ξ³.v p (p + n) rfl ≫ (L.shiftFunctorObjXIso a q (p + n) (by omega)).inv) lemma rightShift_v (a n' : β„€) (hn' : n' + a = n) (p q : β„€) (hpq : p + n' = q) (p' : β„€) (hp' : p + n = p') : (Ξ³.rightShift a n' hn').v p q hpq = Ξ³.v p p' hp' ≫ (L.shiftFunctorObjXIso a q p' (by rw [← hp', ← hpq, ← hn', add_assoc])).inv := by subst hp' dsimp only [rightShift] simp only [mk_v] /-- The map `Cochain K L n β†’ Cochain (K⟦a⟧) L n'` when `n + a = n'`. -/ def leftShift (a n' : β„€) (hn' : n + a = n') : Cochain (K⟦a⟧) L n' := Cochain.mk (fun p q hpq => (a * n' + ((a * (a-1))/2)).negOnePow β€’ (K.shiftFunctorObjXIso a p (p + a) rfl).hom ≫ Ξ³.v (p+a) q (by omega)) lemma leftShift_v (a n' : β„€) (hn' : n + a = n') (p q : β„€) (hpq : p + n' = q) (p' : β„€) (hp' : p' + n = q) : (Ξ³.leftShift a n' hn').v p q hpq = (a * n' + ((a * (a - 1))/2)).negOnePow β€’ (K.shiftFunctorObjXIso a p p' (by rw [← add_left_inj n, hp', add_assoc, add_comm a, hn', hpq])).hom ≫ Ξ³.v p' q hp' := by obtain rfl : p' = p + a := by omega dsimp only [leftShift] simp only [mk_v] /-- The map `Cochain K (L⟦a⟧) n' β†’ Cochain K L n` when `n' + a = n`. -/ def rightUnshift {n' a : β„€} (Ξ³ : Cochain K (L⟦a⟧) n') (n : β„€) (hn : n' + a = n) : Cochain K L n := Cochain.mk (fun p q hpq => Ξ³.v p (p + n') rfl ≫ (L.shiftFunctorObjXIso a (p + n') q (by rw [← hpq, add_assoc, hn])).hom) lemma rightUnshift_v {n' a : β„€} (Ξ³ : Cochain K (L⟦a⟧) n') (n : β„€) (hn : n' + a = n) (p q : β„€) (hpq : p + n = q) (p' : β„€) (hp' : p + n' = p') : (Ξ³.rightUnshift n hn).v p q hpq = Ξ³.v p p' hp' ≫ (L.shiftFunctorObjXIso a p' q (by rw [← hpq, ← hn, ← add_assoc, hp'])).hom := by subst hp' dsimp only [rightUnshift] simp only [mk_v] /-- The map `Cochain (K⟦a⟧) L n' β†’ Cochain K L n` when `n + a = n'`. -/ def leftUnshift {n' a : β„€} (Ξ³ : Cochain (K⟦a⟧) L n') (n : β„€) (hn : n + a = n') : Cochain K L n := Cochain.mk (fun p q hpq => (a * n' + ((a * (a-1))/2)).negOnePow β€’ (K.shiftFunctorObjXIso a (p - a) p (by omega)).inv ≫ Ξ³.v (p-a) q (by omega)) lemma leftUnshift_v {n' a : β„€} (Ξ³ : Cochain (K⟦a⟧) L n') (n : β„€) (hn : n + a = n') (p q : β„€) (hpq : p + n = q) (p' : β„€) (hp' : p' + n' = q) : (Ξ³.leftUnshift n hn).v p q hpq = (a * n' + ((a * (a-1))/2)).negOnePow β€’ (K.shiftFunctorObjXIso a p' p (by omega)).inv ≫ Ξ³.v p' q (by omega) := by obtain rfl : p' = p - a := by omega rfl /-- The map `Cochain K L n β†’ Cochain (K⟦a⟧) (L⟦a⟧) n`. -/ def shift (a : β„€) : Cochain (K⟦a⟧) (L⟦a⟧) n := Cochain.mk (fun p q hpq => (K.shiftFunctorObjXIso a p _ rfl).hom ≫ Ξ³.v (p + a) (q + a) (by omega) ≫ (L.shiftFunctorObjXIso a q _ rfl).inv) lemma shift_v (a : β„€) (p q : β„€) (hpq : p + n = q) (p' q' : β„€) (hp' : p' = p + a) (hq' : q' = q + a) : (Ξ³.shift a).v p q hpq = (K.shiftFunctorObjXIso a p p' hp').hom ≫ Ξ³.v p' q' (by rw [hp', hq', ← hpq, add_assoc, add_comm a, add_assoc]) ≫ (L.shiftFunctorObjXIso a q q' hq').inv := by subst hp' hq' rfl lemma shift_v' (a : β„€) (p q : β„€) (hpq : p + n = q) : (Ξ³.shift a).v p q hpq = Ξ³.v (p + a) (q + a) (by omega) := by simp only [shift_v Ξ³ a p q hpq _ _ rfl rfl, shiftFunctor_obj_X, shiftFunctorObjXIso, HomologicalComplex.XIsoOfEq_rfl, Iso.refl_hom, Iso.refl_inv, comp_id, id_comp] @[simp] lemma rightUnshift_rightShift (a n' : β„€) (hn' : n' + a = n) : (Ξ³.rightShift a n' hn').rightUnshift n hn' = Ξ³ := by ext p q hpq simp only [rightUnshift_v _ n hn' p q hpq (p + n') rfl, Ξ³.rightShift_v _ _ hn' p (p + n') rfl q hpq, shiftFunctorObjXIso, assoc, Iso.inv_hom_id, comp_id] @[simp] lemma rightShift_rightUnshift {a n' : β„€} (Ξ³ : Cochain K (L⟦a⟧) n') (n : β„€) (hn' : n' + a = n) : (Ξ³.rightUnshift n hn').rightShift a n' hn' = Ξ³ := by ext p q hpq simp only [(Ξ³.rightUnshift n hn').rightShift_v a n' hn' p q hpq (p + n) rfl, Ξ³.rightUnshift_v n hn' p (p + n) rfl q hpq, shiftFunctorObjXIso, assoc, Iso.hom_inv_id, comp_id] @[simp] lemma leftUnshift_leftShift (a n' : β„€) (hn' : n + a = n') : (Ξ³.leftShift a n' hn').leftUnshift n hn' = Ξ³ := by ext p q hpq rw [(Ξ³.leftShift a n' hn').leftUnshift_v n hn' p q hpq (q-n') (by omega), Ξ³.leftShift_v a n' hn' (q-n') q (by omega) p hpq, Linear.comp_units_smul, Iso.inv_hom_id_assoc, smul_smul, Int.units_mul_self, one_smul] @[simp] lemma leftShift_leftUnshift {a n' : β„€} (Ξ³ : Cochain (K⟦a⟧) L n') (n : β„€) (hn' : n + a = n') : (Ξ³.leftUnshift n hn').leftShift a n' hn' = Ξ³ := by ext p q hpq rw [(Ξ³.leftUnshift n hn').leftShift_v a n' hn' p q hpq (q-n) (by omega), Ξ³.leftUnshift_v n hn' (q-n) q (by omega) p hpq, Linear.comp_units_smul, smul_smul, Iso.hom_inv_id_assoc, Int.units_mul_self, one_smul] @[simp] lemma rightShift_add (a n' : β„€) (hn' : n' + a = n) : (γ₁ + Ξ³β‚‚).rightShift a n' hn' = γ₁.rightShift a n' hn' + Ξ³β‚‚.rightShift a n' hn' := by ext p q hpq dsimp simp only [rightShift_v _ a n' hn' p q hpq _ rfl, add_v, add_comp] @[simp] lemma leftShift_add (a n' : β„€) (hn' : n + a = n') : (γ₁ + Ξ³β‚‚).leftShift a n' hn' = γ₁.leftShift a n' hn' + Ξ³β‚‚.leftShift a n' hn' := by ext p q hpq dsimp simp only [leftShift_v _ a n' hn' p q hpq (p + a) (by omega), add_v, comp_add, smul_add] @[simp] lemma shift_add (a : β„€) : (γ₁ + Ξ³β‚‚).shift a = γ₁.shift a + Ξ³β‚‚.shift a := by ext p q hpq dsimp simp only [shift_v', add_v] variable (K L) /-- The additive equivalence `Cochain K L n ≃+ Cochain K L⟦a⟧ n'` when `n' + a = n`. -/ @[simps] def rightShiftAddEquiv (n a n' : β„€) (hn' : n' + a = n) : Cochain K L n ≃+ Cochain K (L⟦a⟧) n' where toFun Ξ³ := Ξ³.rightShift a n' hn' invFun Ξ³ := Ξ³.rightUnshift n hn' left_inv Ξ³ := by simp only [rightUnshift_rightShift] right_inv Ξ³ := by simp only [rightShift_rightUnshift] map_add' Ξ³ Ξ³' := by simp only [rightShift_add] /-- The additive equivalence `Cochain K L n ≃+ Cochain (K⟦a⟧) L n'` when `n + a = n'`. -/ @[simps] def leftShiftAddEquiv (n a n' : β„€) (hn' : n + a = n') : Cochain K L n ≃+ Cochain (K⟦a⟧) L n' where toFun Ξ³ := Ξ³.leftShift a n' hn' invFun Ξ³ := Ξ³.leftUnshift n hn' left_inv Ξ³ := by simp only [leftUnshift_leftShift] right_inv Ξ³ := by simp only [leftShift_leftUnshift] map_add' Ξ³ Ξ³' := by simp only [leftShift_add] /-- The additive map `Cochain K L n β†’+ Cochain (K⟦a⟧) (L⟦a⟧) n`. -/ @[simps!] def shiftAddHom (n a : β„€) : Cochain K L n β†’+ Cochain (K⟦a⟧) (L⟦a⟧) n := AddMonoidHom.mk' (fun Ξ³ => Ξ³.shift a) (by intros; dsimp; simp only [shift_add]) variable (n) @[simp] lemma rightShift_zero (a n' : β„€) (hn' : n' + a = n) : (0 : Cochain K L n).rightShift a n' hn' = 0 := by change rightShiftAddEquiv K L n a n' hn' 0 = 0 apply map_zero @[simp] lemma rightUnshift_zero (a n' : β„€) (hn' : n' + a = n) : (0 : Cochain K (L⟦a⟧) n').rightUnshift n hn' = 0 := by change (rightShiftAddEquiv K L n a n' hn').symm 0 = 0 apply map_zero @[simp] lemma leftShift_zero (a n' : β„€) (hn' : n + a = n') : (0 : Cochain K L n).leftShift a n' hn' = 0 := by change leftShiftAddEquiv K L n a n' hn' 0 = 0 apply map_zero @[simp] lemma leftUnshift_zero (a n' : β„€) (hn' : n + a = n') : (0 : Cochain (K⟦a⟧) L n').leftUnshift n hn' = 0 := by change (leftShiftAddEquiv K L n a n' hn').symm 0 = 0 apply map_zero @[simp] lemma shift_zero (a : β„€) : (0 : Cochain K L n).shift a = 0 := by change shiftAddHom K L n a 0 = 0 apply map_zero variable {K L n} @[simp] lemma rightShift_neg (a n' : β„€) (hn' : n' + a = n) : (-Ξ³).rightShift a n' hn' = -Ξ³.rightShift a n' hn' := by change rightShiftAddEquiv K L n a n' hn' (-Ξ³) = _ apply map_neg @[simp] lemma rightUnshift_neg {n' a : β„€} (Ξ³ : Cochain K (L⟦a⟧) n') (n : β„€) (hn : n' + a = n) : (-Ξ³).rightUnshift n hn = -Ξ³.rightUnshift n hn := by change (rightShiftAddEquiv K L n a n' hn).symm (-Ξ³) = _ apply map_neg @[simp] lemma leftShift_neg (a n' : β„€) (hn' : n + a = n') : (-Ξ³).leftShift a n' hn' = -Ξ³.leftShift a n' hn' := by
change leftShiftAddEquiv K L n a n' hn' (-Ξ³) = _ apply map_neg @[simp] lemma leftUnshift_neg {n' a : β„€} (Ξ³ : Cochain (K⟦a⟧) L n') (n : β„€) (hn : n + a = n') :
Mathlib/Algebra/Homology/HomotopyCategory/HomComplexShift.lean
246
250
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Exp import Mathlib.Data.Nat.Factorization.Defs import Mathlib.Analysis.NormedSpace.Real import Mathlib.Data.Rat.Cast.CharZero /-! # Real logarithm In this file we define `Real.log` to be the logarithm of a real number. As usual, we extend it from its domain `(0, +∞)` to a globally defined function. We choose to do it so that `log 0 = 0` and `log (-x) = log x`. We prove some basic properties of this function and show that it is continuous. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {x y : ℝ} /-- The real logarithm function, equal to the inverse of the exponential for `x > 0`, to `log |x|` for `x < 0`, and to `0` for `0`. We use this unconventional extension to `(-∞, 0]` as it gives the formula `log (x * y) = log x + log y` for all nonzero `x` and `y`, and the derivative of `log` is `1/x` away from `0`. -/ @[pp_nodot] noncomputable def log (x : ℝ) : ℝ := if hx : x = 0 then 0 else expOrderIso.symm ⟨|x|, abs_pos.2 hx⟩ theorem log_of_ne_zero (hx : x β‰  0) : log x = expOrderIso.symm ⟨|x|, abs_pos.2 hx⟩ := dif_neg hx theorem log_of_pos (hx : 0 < x) : log x = expOrderIso.symm ⟨x, hx⟩ := by rw [log_of_ne_zero hx.ne'] congr exact abs_of_pos hx theorem exp_log_eq_abs (hx : x β‰  0) : exp (log x) = |x| := by rw [log_of_ne_zero hx, ← coe_expOrderIso_apply, OrderIso.apply_symm_apply, Subtype.coe_mk] theorem exp_log (hx : 0 < x) : exp (log x) = x := by rw [exp_log_eq_abs hx.ne'] exact abs_of_pos hx theorem exp_log_of_neg (hx : x < 0) : exp (log x) = -x := by rw [exp_log_eq_abs (ne_of_lt hx)] exact abs_of_neg hx theorem le_exp_log (x : ℝ) : x ≀ exp (log x) := by by_cases h_zero : x = 0 Β· rw [h_zero, log, dif_pos rfl, exp_zero] exact zero_le_one Β· rw [exp_log_eq_abs h_zero] exact le_abs_self _ @[simp] theorem log_exp (x : ℝ) : log (exp x) = x := exp_injective <| exp_log (exp_pos x) theorem exp_one_mul_le_exp {x : ℝ} : exp 1 * x ≀ exp x := by by_cases hx0 : x ≀ 0 Β· apply le_trans (mul_nonpos_of_nonneg_of_nonpos (exp_pos 1).le hx0) (exp_nonneg x) Β· have h := add_one_le_exp (log x) rwa [← exp_le_exp, exp_add, exp_log (lt_of_not_le hx0), mul_comm] at h theorem two_mul_le_exp {x : ℝ} : 2 * x ≀ exp x := by by_cases hx0 : x < 0 Β· exact le_trans (mul_nonpos_of_nonneg_of_nonpos (by simp only [Nat.ofNat_nonneg]) hx0.le) (exp_nonneg x) Β· apply le_trans (mul_le_mul_of_nonneg_right _ (le_of_not_lt hx0)) exp_one_mul_le_exp have := Real.add_one_le_exp 1 rwa [one_add_one_eq_two] at this theorem surjOn_log : SurjOn log (Ioi 0) univ := fun x _ => ⟨exp x, exp_pos x, log_exp x⟩ theorem log_surjective : Surjective log := fun x => ⟨exp x, log_exp x⟩ @[simp] theorem range_log : range log = univ := log_surjective.range_eq @[simp] theorem log_zero : log 0 = 0 := dif_pos rfl @[simp] theorem log_one : log 1 = 0 := exp_injective <| by rw [exp_log zero_lt_one, exp_zero] /-- This holds true for all `x : ℝ` because of the junk values `0 / 0 = 0` and `log 0 = 0`. -/ @[simp] lemma log_div_self (x : ℝ) : log (x / x) = 0 := by obtain rfl | hx := eq_or_ne x 0 <;> simp [*] @[simp] theorem log_abs (x : ℝ) : log |x| = log x := by by_cases h : x = 0 Β· simp [h] Β· rw [← exp_eq_exp, exp_log_eq_abs h, exp_log_eq_abs (abs_pos.2 h).ne', abs_abs] @[simp] theorem log_neg_eq_log (x : ℝ) : log (-x) = log x := by rw [← log_abs x, ← log_abs (-x), abs_neg] theorem sinh_log {x : ℝ} (hx : 0 < x) : sinh (log x) = (x - x⁻¹) / 2 := by rw [sinh_eq, exp_neg, exp_log hx] theorem cosh_log {x : ℝ} (hx : 0 < x) : cosh (log x) = (x + x⁻¹) / 2 := by rw [cosh_eq, exp_neg, exp_log hx] theorem surjOn_log' : SurjOn log (Iio 0) univ := fun x _ => ⟨-exp x, neg_lt_zero.2 <| exp_pos x, by rw [log_neg_eq_log, log_exp]⟩ theorem log_mul (hx : x β‰  0) (hy : y β‰  0) : log (x * y) = log x + log y := exp_injective <| by rw [exp_log_eq_abs (mul_ne_zero hx hy), exp_add, exp_log_eq_abs hx, exp_log_eq_abs hy, abs_mul] theorem log_div (hx : x β‰  0) (hy : y β‰  0) : log (x / y) = log x - log y := exp_injective <| by rw [exp_log_eq_abs (div_ne_zero hx hy), exp_sub, exp_log_eq_abs hx, exp_log_eq_abs hy, abs_div] @[simp] theorem log_inv (x : ℝ) : log x⁻¹ = -log x := by by_cases hx : x = 0; Β· simp [hx] rw [← exp_eq_exp, exp_log_eq_abs (inv_ne_zero hx), exp_neg, exp_log_eq_abs hx, abs_inv] theorem log_le_log_iff (h : 0 < x) (h₁ : 0 < y) : log x ≀ log y ↔ x ≀ y := by rw [← exp_le_exp, exp_log h, exp_log h₁] @[gcongr, bound] lemma log_le_log (hx : 0 < x) (hxy : x ≀ y) : log x ≀ log y := (log_le_log_iff hx (hx.trans_le hxy)).2 hxy @[gcongr, bound] theorem log_lt_log (hx : 0 < x) (h : x < y) : log x < log y := by rwa [← exp_lt_exp, exp_log hx, exp_log (lt_trans hx h)] theorem log_lt_log_iff (hx : 0 < x) (hy : 0 < y) : log x < log y ↔ x < y := by rw [← exp_lt_exp, exp_log hx, exp_log hy] theorem log_le_iff_le_exp (hx : 0 < x) : log x ≀ y ↔ x ≀ exp y := by rw [← exp_le_exp, exp_log hx] theorem log_lt_iff_lt_exp (hx : 0 < x) : log x < y ↔ x < exp y := by rw [← exp_lt_exp, exp_log hx] theorem le_log_iff_exp_le (hy : 0 < y) : x ≀ log y ↔ exp x ≀ y := by rw [← exp_le_exp, exp_log hy] theorem lt_log_iff_exp_lt (hy : 0 < y) : x < log y ↔ exp x < y := by rw [← exp_lt_exp, exp_log hy] theorem log_pos_iff (hx : 0 ≀ x) : 0 < log x ↔ 1 < x := by rcases hx.eq_or_lt with (rfl | hx)
Β· simp [le_refl, zero_le_one]
Mathlib/Analysis/SpecialFunctions/Log/Basic.lean
162
162
/- 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, Kim Morrison, Jens Wagemaker, Johan Commelin -/ import Mathlib.Algebra.Polynomial.BigOperators import Mathlib.Algebra.Polynomial.RingDivision import Mathlib.Data.Set.Finite.Lemmas import Mathlib.RingTheory.Coprime.Lemmas import Mathlib.RingTheory.Localization.FractionRing import Mathlib.SetTheory.Cardinal.Order /-! # Theory of univariate polynomials We define the multiset of roots of a polynomial, and prove basic results about it. ## Main definitions * `Polynomial.roots p`: The multiset containing all the roots of `p`, including their multiplicities. * `Polynomial.rootSet p E`: The set of distinct roots of `p` in an algebra `E`. ## Main statements * `Polynomial.C_leadingCoeff_mul_prod_multiset_X_sub_C`: If a polynomial has as many roots as its degree, it can be written as the product of its leading coefficient with `∏ (X - a)` where `a` ranges through its roots. -/ assert_not_exists Ideal open Multiset Finset noncomputable section 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] [IsDomain R] {p q : R[X]} section Roots /-- `roots p` noncomputably gives a multiset containing all the roots of `p`, including their multiplicities. -/ noncomputable def roots (p : R[X]) : Multiset R := haveI := Classical.decEq R haveI := Classical.dec (p = 0) if h : p = 0 then βˆ… else Classical.choose (exists_multiset_roots h) theorem roots_def [DecidableEq R] (p : R[X]) [Decidable (p = 0)] : p.roots = if h : p = 0 then βˆ… else Classical.choose (exists_multiset_roots h) := by rename_i iR ip0 obtain rfl := Subsingleton.elim iR (Classical.decEq R) obtain rfl := Subsingleton.elim ip0 (Classical.dec (p = 0)) rfl @[simp] theorem roots_zero : (0 : R[X]).roots = 0 := dif_pos rfl theorem card_roots (hp0 : p β‰  0) : (Multiset.card (roots p) : WithBot β„•) ≀ degree p := by classical unfold roots rw [dif_neg hp0] exact (Classical.choose_spec (exists_multiset_roots hp0)).1 theorem card_roots' (p : R[X]) : Multiset.card p.roots ≀ natDegree p := by by_cases hp0 : p = 0 Β· simp [hp0] exact WithBot.coe_le_coe.1 (le_trans (card_roots hp0) (le_of_eq <| degree_eq_natDegree hp0)) theorem card_roots_sub_C {p : R[X]} {a : R} (hp0 : 0 < degree p) : (Multiset.card (p - C a).roots : WithBot β„•) ≀ degree p := calc (Multiset.card (p - C a).roots : WithBot β„•) ≀ degree (p - C a) := card_roots <| mt sub_eq_zero.1 fun h => not_le_of_gt hp0 <| h.symm β–Έ degree_C_le _ = degree p := by rw [sub_eq_add_neg, ← C_neg]; exact degree_add_C hp0 theorem card_roots_sub_C' {p : R[X]} {a : R} (hp0 : 0 < degree p) : Multiset.card (p - C a).roots ≀ natDegree p := WithBot.coe_le_coe.1 (le_trans (card_roots_sub_C hp0) (le_of_eq <| degree_eq_natDegree fun h => by simp_all [lt_irrefl])) @[simp] theorem count_roots [DecidableEq R] (p : R[X]) : p.roots.count a = rootMultiplicity a p := by classical by_cases hp : p = 0 Β· simp [hp] rw [roots_def, dif_neg hp] exact (Classical.choose_spec (exists_multiset_roots hp)).2 a @[simp] theorem mem_roots' : a ∈ p.roots ↔ p β‰  0 ∧ IsRoot p a := by classical rw [← count_pos, count_roots p, rootMultiplicity_pos'] theorem mem_roots (hp : p β‰  0) : a ∈ p.roots ↔ IsRoot p a := mem_roots'.trans <| and_iff_right hp theorem ne_zero_of_mem_roots (h : a ∈ p.roots) : p β‰  0 := (mem_roots'.1 h).1 theorem isRoot_of_mem_roots (h : a ∈ p.roots) : IsRoot p a := (mem_roots'.1 h).2 theorem mem_roots_map_of_injective [Semiring S] {p : S[X]} {f : S β†’+* R} (hf : Function.Injective f) {x : R} (hp : p β‰  0) : x ∈ (p.map f).roots ↔ p.evalβ‚‚ f x = 0 := by rw [mem_roots ((Polynomial.map_ne_zero_iff hf).mpr hp), IsRoot, eval_map] lemma mem_roots_iff_aeval_eq_zero {x : R} (w : p β‰  0) : x ∈ roots p ↔ aeval x p = 0 := by rw [aeval_def, ← mem_roots_map_of_injective (FaithfulSMul.algebraMap_injective _ _) w, Algebra.id.map_eq_id, map_id] theorem card_le_degree_of_subset_roots {p : R[X]} {Z : Finset R} (h : Z.val βŠ† p.roots) : #Z ≀ p.natDegree := (Multiset.card_le_card (Finset.val_le_iff_val_subset.2 h)).trans (Polynomial.card_roots' p) theorem finite_setOf_isRoot {p : R[X]} (hp : p β‰  0) : Set.Finite { x | IsRoot p x } := by classical simpa only [← Finset.setOf_mem, Multiset.mem_toFinset, mem_roots hp] using p.roots.toFinset.finite_toSet theorem eq_zero_of_infinite_isRoot (p : R[X]) (h : Set.Infinite { x | IsRoot p x }) : p = 0 := not_imp_comm.mp finite_setOf_isRoot h theorem exists_max_root [LinearOrder R] (p : R[X]) (hp : p β‰  0) : βˆƒ xβ‚€, βˆ€ x, p.IsRoot x β†’ x ≀ xβ‚€ := Set.exists_upper_bound_image _ _ <| finite_setOf_isRoot hp theorem exists_min_root [LinearOrder R] (p : R[X]) (hp : p β‰  0) : βˆƒ xβ‚€, βˆ€ x, p.IsRoot x β†’ xβ‚€ ≀ x := Set.exists_lower_bound_image _ _ <| finite_setOf_isRoot hp theorem eq_of_infinite_eval_eq (p q : R[X]) (h : Set.Infinite { x | eval x p = eval x q }) : p = q := by rw [← sub_eq_zero] apply eq_zero_of_infinite_isRoot simpa only [IsRoot, eval_sub, sub_eq_zero] theorem roots_mul {p q : R[X]} (hpq : p * q β‰  0) : (p * q).roots = p.roots + q.roots := by classical exact Multiset.ext.mpr fun r => by rw [count_add, count_roots, count_roots, count_roots, rootMultiplicity_mul hpq] theorem roots.le_of_dvd (h : q β‰  0) : p ∣ q β†’ roots p ≀ roots q := by rintro ⟨k, rfl⟩ exact Multiset.le_iff_exists_add.mpr ⟨k.roots, roots_mul h⟩ theorem mem_roots_sub_C' {p : R[X]} {a x : R} : x ∈ (p - C a).roots ↔ p β‰  C a ∧ p.eval x = a := by rw [mem_roots', IsRoot.def, sub_ne_zero, eval_sub, sub_eq_zero, eval_C] theorem mem_roots_sub_C {p : R[X]} {a x : R} (hp0 : 0 < degree p) : x ∈ (p - C a).roots ↔ p.eval x = a := mem_roots_sub_C'.trans <| and_iff_right fun hp => hp0.not_le <| hp.symm β–Έ degree_C_le @[simp] theorem roots_X_sub_C (r : R) : roots (X - C r) = {r} := by classical ext s rw [count_roots, rootMultiplicity_X_sub_C, count_singleton] @[simp] theorem roots_X_add_C (r : R) : roots (X + C r) = {-r} := by simpa using roots_X_sub_C (-r) @[simp] theorem roots_X : roots (X : R[X]) = {0} := by rw [← roots_X_sub_C, C_0, sub_zero] @[simp] theorem roots_C (x : R) : (C x).roots = 0 := by classical exact if H : x = 0 then by rw [H, C_0, roots_zero] else Multiset.ext.mpr fun r => (by rw [count_roots, count_zero, rootMultiplicity_eq_zero (not_isRoot_C _ _ H)]) @[simp] theorem roots_one : (1 : R[X]).roots = βˆ… := roots_C 1 @[simp] theorem roots_C_mul (p : R[X]) (ha : a β‰  0) : (C a * p).roots = p.roots := by by_cases hp : p = 0 <;> simp only [roots_mul, *, Ne, mul_eq_zero, C_eq_zero, or_self_iff, not_false_iff, roots_C, zero_add, mul_zero] @[simp] theorem roots_smul_nonzero (p : R[X]) (ha : a β‰  0) : (a β€’ p).roots = p.roots := by rw [smul_eq_C_mul, roots_C_mul _ ha] @[simp] lemma roots_neg (p : R[X]) : (-p).roots = p.roots := by rw [← neg_one_smul R p, roots_smul_nonzero p (neg_ne_zero.mpr one_ne_zero)] @[simp] theorem roots_C_mul_X_sub_C_of_IsUnit (b : R) (a : RΛ£) : (C (a : R) * X - C b).roots = {a⁻¹ * b} := by rw [← roots_C_mul _ (Units.ne_zero a⁻¹), mul_sub, ← mul_assoc, ← C_mul, ← C_mul, Units.inv_mul, C_1, one_mul] exact roots_X_sub_C (a⁻¹ * b) @[simp] theorem roots_C_mul_X_add_C_of_IsUnit (b : R) (a : RΛ£) : (C (a : R) * X + C b).roots = {-(a⁻¹ * b)} := by rw [← sub_neg_eq_add, ← C_neg, roots_C_mul_X_sub_C_of_IsUnit, mul_neg] theorem roots_list_prod (L : List R[X]) : (0 : R[X]) βˆ‰ L β†’ L.prod.roots = (L : Multiset R[X]).bind roots := List.recOn L (fun _ => roots_one) fun hd tl ih H => by rw [List.mem_cons, not_or] at H rw [List.prod_cons, roots_mul (mul_ne_zero (Ne.symm H.1) <| List.prod_ne_zero H.2), ← Multiset.cons_coe, Multiset.cons_bind, ih H.2] theorem roots_multiset_prod (m : Multiset R[X]) : (0 : R[X]) βˆ‰ m β†’ m.prod.roots = m.bind roots := by rcases m with ⟨L⟩ simpa only [Multiset.prod_coe, quot_mk_to_coe''] using roots_list_prod L theorem roots_prod {ΞΉ : Type*} (f : ΞΉ β†’ R[X]) (s : Finset ΞΉ) :
s.prod f β‰  0 β†’ (s.prod f).roots = s.val.bind fun i => roots (f i) := by rcases s with ⟨m, hm⟩ simpa [Multiset.prod_eq_zero_iff, Multiset.bind_map] using roots_multiset_prod (m.map f)
Mathlib/Algebra/Polynomial/Roots.lean
224
226
/- 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, Floris van Doorn -/ import Mathlib.Geometry.Manifold.IsManifold.ExtChartAt import Mathlib.Geometry.Manifold.LocalInvariantProperties /-! # `C^n` functions between manifolds We define `Cⁿ` functions between manifolds, as functions which are `Cⁿ` in charts, and prove basic properties of these notions. Here, `n` can be finite, or `∞`, or `Ο‰`. ## Main definitions and statements Let `M` and `M'` be two manifolds, with respect to models with corners `I` and `I'`. Let `f : M β†’ M'`. * `ContMDiffWithinAt I I' n f s x` states that the function `f` is `Cⁿ` within the set `s` around the point `x`. * `ContMDiffAt I I' n f x` states that the function `f` is `Cⁿ` around `x`. * `ContMDiffOn I I' n f s` states that the function `f` is `Cⁿ` on the set `s` * `ContMDiff I I' n f` states that the function `f` is `Cⁿ`. We also give some basic properties of `Cⁿ` functions between manifolds, following the API of `C^n` functions between vector spaces. See `Basic.lean` for further basic properties of `Cⁿ` functions between manifolds, `NormedSpace.lean` for the equivalence of manifold-smoothness to usual smoothness, `Product.lean` for smoothness results related to the product of manifolds and `Atlas.lean` for smoothness of atlas members and local structomorphisms. ## Implementation details Many properties follow for free from the corresponding properties of functions in vector spaces, as being `Cⁿ` is a local property invariant under the `Cⁿ` groupoid. We take advantage of the general machinery developed in `LocalInvariantProperties.lean` to get these properties automatically. For instance, the fact that being `Cⁿ` does not depend on the chart one considers is given by `liftPropWithinAt_indep_chart`. For this to work, the definition of `ContMDiffWithinAt` and friends has to follow definitionally the setup of local invariant properties. Still, we recast the definition in terms of extended charts in `contMDiffOn_iff` and `contMDiff_iff`. -/ open Set Function Filter ChartedSpace IsManifold open scoped Topology Manifold ContDiff /-! ### Definition of `Cⁿ` functions between manifolds -/ variable {π•œ : Type*} [NontriviallyNormedField π•œ] -- Prerequisite typeclasses to say that `M` is a manifold over the pair `(E, H)` {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners π•œ E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] -- Prerequisite typeclasses to say that `M'` is a manifold over the pair `(E', H')` {E' : Type*} [NormedAddCommGroup E'] [NormedSpace π•œ E'] {H' : Type*} [TopologicalSpace H'] {I' : ModelWithCorners π•œ E' H'} {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M'] -- Prerequisite typeclasses to say that `M''` is a manifold over the pair `(E'', H'')` {E'' : Type*} [NormedAddCommGroup E''] [NormedSpace π•œ E''] {H'' : Type*} [TopologicalSpace H''] {I'' : ModelWithCorners π•œ E'' H''} {M'' : Type*} [TopologicalSpace M''] [ChartedSpace H'' M''] -- declare functions, sets, points and smoothness indices {e : PartialHomeomorph M H} {e' : PartialHomeomorph M' H'} {f f₁ : M β†’ M'} {s s₁ t : Set M} {x : M} {m n : WithTop β„•βˆž} variable (I I') in /-- Property in the model space of a model with corners of being `C^n` within at set at a point, when read in the model vector space. This property will be lifted to manifolds to define `C^n` functions between manifolds. -/ def ContDiffWithinAtProp (n : WithTop β„•βˆž) (f : H β†’ H') (s : Set H) (x : H) : Prop := ContDiffWithinAt π•œ n (I' ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ range I) (I x) theorem contDiffWithinAtProp_self_source {f : E β†’ H'} {s : Set E} {x : E} : ContDiffWithinAtProp π“˜(π•œ, E) I' n f s x ↔ ContDiffWithinAt π•œ n (I' ∘ f) s x := by simp_rw [ContDiffWithinAtProp, modelWithCornersSelf_coe, range_id, inter_univ, modelWithCornersSelf_coe_symm, CompTriple.comp_eq, preimage_id_eq, id_eq] theorem contDiffWithinAtProp_self {f : E β†’ E'} {s : Set E} {x : E} : ContDiffWithinAtProp π“˜(π•œ, E) π“˜(π•œ, E') n f s x ↔ ContDiffWithinAt π•œ n f s x := contDiffWithinAtProp_self_source theorem contDiffWithinAtProp_self_target {f : H β†’ E'} {s : Set H} {x : H} : ContDiffWithinAtProp I π“˜(π•œ, E') n f s x ↔ ContDiffWithinAt π•œ n (f ∘ I.symm) (I.symm ⁻¹' s ∩ range I) (I x) := Iff.rfl /-- Being `Cⁿ` in the model space is a local property, invariant under `Cⁿ` maps. Therefore, it lifts nicely to manifolds. -/ theorem contDiffWithinAt_localInvariantProp_of_le (n m : WithTop β„•βˆž) (hmn : m ≀ n) : (contDiffGroupoid n I).LocalInvariantProp (contDiffGroupoid n I') (ContDiffWithinAtProp I I' m) where is_local {s x u f} u_open xu := by have : I.symm ⁻¹' (s ∩ u) ∩ range I = I.symm ⁻¹' s ∩ range I ∩ I.symm ⁻¹' u := by simp only [inter_right_comm, preimage_inter] rw [ContDiffWithinAtProp, ContDiffWithinAtProp, this] symm apply contDiffWithinAt_inter have : u ∈ 𝓝 (I.symm (I x)) := by rw [ModelWithCorners.left_inv] exact u_open.mem_nhds xu apply ContinuousAt.preimage_mem_nhds I.continuous_symm.continuousAt this right_invariance' {s x f e} he hx h := by rw [ContDiffWithinAtProp] at h ⊒ have : I x = (I ∘ e.symm ∘ I.symm) (I (e x)) := by simp only [hx, mfld_simps] rw [this] at h have : I (e x) ∈ I.symm ⁻¹' e.target ∩ range I := by simp only [hx, mfld_simps] have := (mem_groupoid_of_pregroupoid.2 he).2.contDiffWithinAt this convert (h.comp_inter _ (this.of_le hmn)).mono_of_mem_nhdsWithin _ using 1 Β· ext y; simp only [mfld_simps] refine mem_nhdsWithin.mpr ⟨I.symm ⁻¹' e.target, e.open_target.preimage I.continuous_symm, by simp_rw [mem_preimage, I.left_inv, e.mapsTo hx], ?_⟩ mfld_set_tac congr_of_forall {s x f g} h hx hf := by apply hf.congr Β· intro y hy simp only [mfld_simps] at hy simp only [h, hy, mfld_simps] Β· simp only [hx, mfld_simps] left_invariance' {s x f e'} he' hs hx h := by rw [ContDiffWithinAtProp] at h ⊒ have A : (I' ∘ f ∘ I.symm) (I x) ∈ I'.symm ⁻¹' e'.source ∩ range I' := by simp only [hx, mfld_simps] have := (mem_groupoid_of_pregroupoid.2 he').1.contDiffWithinAt A convert (this.of_le hmn).comp _ h _ Β· ext y; simp only [mfld_simps] Β· intro y hy; simp only [mfld_simps] at hy; simpa only [hy, mfld_simps] using hs hy.1 /-- Being `Cⁿ` in the model space is a local property, invariant under `C^n` maps. Therefore, it lifts nicely to manifolds. -/ theorem contDiffWithinAt_localInvariantProp (n : WithTop β„•βˆž) : (contDiffGroupoid n I).LocalInvariantProp (contDiffGroupoid n I') (ContDiffWithinAtProp I I' n) := contDiffWithinAt_localInvariantProp_of_le n n le_rfl theorem contDiffWithinAtProp_mono_of_mem_nhdsWithin (n : WithTop β„•βˆž) ⦃s x t⦄ ⦃f : H β†’ H'⦄ (hts : s ∈ 𝓝[t] x) (h : ContDiffWithinAtProp I I' n f s x) : ContDiffWithinAtProp I I' n f t x := by refine h.mono_of_mem_nhdsWithin ?_ refine inter_mem ?_ (mem_of_superset self_mem_nhdsWithin inter_subset_right) rwa [← Filter.mem_map, ← I.image_eq, I.symm_map_nhdsWithin_image] @[deprecated (since := "2024-10-31")] alias contDiffWithinAtProp_mono_of_mem := contDiffWithinAtProp_mono_of_mem_nhdsWithin theorem contDiffWithinAtProp_id (x : H) : ContDiffWithinAtProp I I n id univ x := by simp only [ContDiffWithinAtProp, id_comp, preimage_univ, univ_inter] have : ContDiffWithinAt π•œ n id (range I) (I x) := contDiff_id.contDiffAt.contDiffWithinAt refine this.congr (fun y hy => ?_) ?_ Β· simp only [ModelWithCorners.right_inv I hy, mfld_simps] Β· simp only [mfld_simps] variable (I I') in /-- A function is `n` times continuously differentiable within a set at a point in a manifold if it is continuous and it is `n` times continuously differentiable in this set around this point, when read in the preferred chart at this point. -/ def ContMDiffWithinAt (n : WithTop β„•βˆž) (f : M β†’ M') (s : Set M) (x : M) := LiftPropWithinAt (ContDiffWithinAtProp I I' n) f s x @[deprecated (since := "2024-11-21")] alias SmoothWithinAt := ContMDiffWithinAt variable (I I') in /-- A function is `n` times continuously differentiable at a point in a manifold if it is continuous and it is `n` times continuously differentiable around this point, when read in the preferred chart at this point. -/ def ContMDiffAt (n : WithTop β„•βˆž) (f : M β†’ M') (x : M) := ContMDiffWithinAt I I' n f univ x theorem contMDiffAt_iff {n : WithTop β„•βˆž} {f : M β†’ M'} {x : M} : ContMDiffAt I I' n f x ↔ ContinuousAt f x ∧ ContDiffWithinAt π•œ n (extChartAt I' (f x) ∘ f ∘ (extChartAt I x).symm) (range I) (extChartAt I x x) := liftPropAt_iff.trans <| by rw [ContDiffWithinAtProp, preimage_univ, univ_inter]; rfl @[deprecated (since := "2024-11-21")] alias SmoothAt := ContMDiffAt variable (I I') in /-- A function is `n` times continuously differentiable in a set of a manifold if it is continuous and, for any pair of points, it is `n` times continuously differentiable on this set in the charts around these points. -/ def ContMDiffOn (n : WithTop β„•βˆž) (f : M β†’ M') (s : Set M) := βˆ€ x ∈ s, ContMDiffWithinAt I I' n f s x @[deprecated (since := "2024-11-21")] alias SmoothOn := ContMDiffOn variable (I I') in /-- A function is `n` times continuously differentiable in a manifold if it is continuous and, for any pair of points, it is `n` times continuously differentiable in the charts around these points. -/ def ContMDiff (n : WithTop β„•βˆž) (f : M β†’ M') := βˆ€ x, ContMDiffAt I I' n f x @[deprecated (since := "2024-11-21")] alias Smooth := ContMDiff /-! ### Deducing smoothness from higher smoothness -/ theorem ContMDiffWithinAt.of_le (hf : ContMDiffWithinAt I I' n f s x) (le : m ≀ n) : ContMDiffWithinAt I I' m f s x := by simp only [ContMDiffWithinAt, LiftPropWithinAt] at hf ⊒ exact ⟨hf.1, hf.2.of_le (mod_cast le)⟩ theorem ContMDiffAt.of_le (hf : ContMDiffAt I I' n f x) (le : m ≀ n) : ContMDiffAt I I' m f x := ContMDiffWithinAt.of_le hf le theorem ContMDiffOn.of_le (hf : ContMDiffOn I I' n f s) (le : m ≀ n) : ContMDiffOn I I' m f s := fun x hx => (hf x hx).of_le le theorem ContMDiff.of_le (hf : ContMDiff I I' n f) (le : m ≀ n) : ContMDiff I I' m f := fun x => (hf x).of_le le /-! ### Basic properties of `C^n` functions between manifolds -/ @[deprecated (since := "2024-11-20")] alias ContMDiff.smooth := ContMDiff.of_le @[deprecated (since := "2024-11-20")] alias Smooth.contMDiff := ContMDiff.of_le @[deprecated (since := "2024-11-20")] alias ContMDiffOn.smoothOn := ContMDiffOn.of_le @[deprecated (since := "2024-11-20")] alias SmoothOn.contMDiffOn := ContMDiffOn.of_le @[deprecated (since := "2024-11-20")] alias ContMDiffAt.smoothAt := ContMDiffAt.of_le @[deprecated (since := "2024-11-20")] alias SmoothAt.contMDiffAt := ContMDiffOn.of_le @[deprecated (since := "2024-11-20")] alias ContMDiffWithinAt.smoothWithinAt := ContMDiffWithinAt.of_le @[deprecated (since := "2024-11-20")] alias SmoothWithinAt.contMDiffWithinAt := ContMDiffWithinAt.of_le theorem ContMDiff.contMDiffAt (h : ContMDiff I I' n f) : ContMDiffAt I I' n f x := h x @[deprecated (since := "2024-11-20")] alias Smooth.smoothAt := ContMDiff.contMDiffAt theorem contMDiffWithinAt_univ : ContMDiffWithinAt I I' n f univ x ↔ ContMDiffAt I I' n f x := Iff.rfl @[deprecated (since := "2024-11-20")] alias smoothWithinAt_univ := contMDiffWithinAt_univ theorem contMDiffOn_univ : ContMDiffOn I I' n f univ ↔ ContMDiff I I' n f := by simp only [ContMDiffOn, ContMDiff, contMDiffWithinAt_univ, forall_prop_of_true, mem_univ] @[deprecated (since := "2024-11-20")] alias smoothOn_univ := contMDiffOn_univ /-- One can reformulate being `C^n` within a set at a point as continuity within this set at this point, and being `C^n` in the corresponding extended chart. -/ theorem contMDiffWithinAt_iff : ContMDiffWithinAt I I' n f s x ↔ ContinuousWithinAt f s x ∧ ContDiffWithinAt π•œ n (extChartAt I' (f x) ∘ f ∘ (extChartAt I x).symm) ((extChartAt I x).symm ⁻¹' s ∩ range I) (extChartAt I x x) := by simp_rw [ContMDiffWithinAt, liftPropWithinAt_iff']; rfl /-- One can reformulate being `Cⁿ` within a set at a point as continuity within this set at this point, and being `Cⁿ` in the corresponding extended chart. This form states regularity of `f` written in such a way that the set is restricted to lie within the domain/codomain of the corresponding charts. Even though this expression is more complicated than the one in `contMDiffWithinAt_iff`, it is a smaller set, but their germs at `extChartAt I x x` are equal. It is sometimes useful to rewrite using this in the goal. -/ theorem contMDiffWithinAt_iff' : ContMDiffWithinAt I I' n f s x ↔ ContinuousWithinAt f s x ∧ ContDiffWithinAt π•œ n (extChartAt I' (f x) ∘ f ∘ (extChartAt I x).symm) ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' (s ∩ f ⁻¹' (extChartAt I' (f x)).source)) (extChartAt I x x) := by simp only [ContMDiffWithinAt, liftPropWithinAt_iff'] exact and_congr_right fun hc => contDiffWithinAt_congr_set <| hc.extChartAt_symm_preimage_inter_range_eventuallyEq /-- One can reformulate being `Cⁿ` within a set at a point as continuity within this set at this point, and being `Cⁿ` in the corresponding extended chart in the target. -/ theorem contMDiffWithinAt_iff_target : ContMDiffWithinAt I I' n f s x ↔ ContinuousWithinAt f s x ∧ ContMDiffWithinAt I π“˜(π•œ, E') n (extChartAt I' (f x) ∘ f) s x := by simp_rw [ContMDiffWithinAt, liftPropWithinAt_iff', ← and_assoc] have cont : ContinuousWithinAt f s x ∧ ContinuousWithinAt (extChartAt I' (f x) ∘ f) s x ↔ ContinuousWithinAt f s x := and_iff_left_of_imp <| (continuousAt_extChartAt _).comp_continuousWithinAt simp_rw [cont, ContDiffWithinAtProp, extChartAt, PartialHomeomorph.extend, PartialEquiv.coe_trans, ModelWithCorners.toPartialEquiv_coe, PartialHomeomorph.coe_coe, modelWithCornersSelf_coe, chartAt_self_eq, PartialHomeomorph.refl_apply, id_comp] rfl @[deprecated (since := "2024-11-20")] alias smoothWithinAt_iff := contMDiffWithinAt_iff @[deprecated (since := "2024-11-20")] alias smoothWithinAt_iff_target := contMDiffWithinAt_iff_target theorem contMDiffAt_iff_target {x : M} : ContMDiffAt I I' n f x ↔ ContinuousAt f x ∧ ContMDiffAt I π“˜(π•œ, E') n (extChartAt I' (f x) ∘ f) x := by rw [ContMDiffAt, ContMDiffAt, contMDiffWithinAt_iff_target, continuousWithinAt_univ] @[deprecated (since := "2024-11-20")] alias smoothAt_iff_target := contMDiffAt_iff_target /-- One can reformulate being `Cⁿ` within a set at a point as being `Cⁿ` in the source space when composing with the extended chart. -/ theorem contMDiffWithinAt_iff_source : ContMDiffWithinAt I I' n f s x ↔ ContMDiffWithinAt π“˜(π•œ, E) I' n (f ∘ (extChartAt I x).symm) ((extChartAt I x).symm ⁻¹' s ∩ range I) (extChartAt I x x) := by simp_rw [ContMDiffWithinAt, liftPropWithinAt_iff'] have : ContinuousWithinAt f s x ↔ ContinuousWithinAt (f ∘ ↑(extChartAt I x).symm) (↑(extChartAt I x).symm ⁻¹' s ∩ range ↑I) (extChartAt I x x) := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ Β· apply h.comp_of_eq Β· exact (continuousAt_extChartAt_symm x).continuousWithinAt Β· exact (mapsTo_preimage _ _).mono_left inter_subset_left Β· exact extChartAt_to_inv x Β· rw [← continuousWithinAt_inter (extChartAt_source_mem_nhds (I := I) x)] have : ContinuousWithinAt ((f ∘ ↑(extChartAt I x).symm) ∘ ↑(extChartAt I x)) (s ∩ (extChartAt I x).source) x := by apply h.comp (continuousAt_extChartAt x).continuousWithinAt intro y hy have : (chartAt H x).symm ((chartAt H x) y) = y := PartialHomeomorph.left_inv _ (by simpa using hy.2) simpa [this] using hy.1 apply this.congr Β· intro y hy have : (chartAt H x).symm ((chartAt H x) y) = y := PartialHomeomorph.left_inv _ (by simpa using hy.2) simp [this] Β· simp rw [← this] simp only [ContDiffWithinAtProp, mfld_simps, preimage_comp, comp_assoc] /-- One can reformulate being `Cⁿ` at a point as being `Cⁿ` in the source space when composing with the extended chart. -/ theorem contMDiffAt_iff_source : ContMDiffAt I I' n f x ↔ ContMDiffWithinAt π“˜(π•œ, E) I' n (f ∘ (extChartAt I x).symm) (range I) (extChartAt I x x) := by rw [← contMDiffWithinAt_univ, contMDiffWithinAt_iff_source] simp section IsManifold theorem contMDiffWithinAt_iff_source_of_mem_maximalAtlas [IsManifold I n M] (he : e ∈ maximalAtlas I n M) (hx : x ∈ e.source) : ContMDiffWithinAt I I' n f s x ↔ ContMDiffWithinAt π“˜(π•œ, E) I' n (f ∘ (e.extend I).symm) ((e.extend I).symm ⁻¹' s ∩ range I) (e.extend I x) := by have h2x := hx; rw [← e.extend_source (I := I)] at h2x simp_rw [ContMDiffWithinAt, (contDiffWithinAt_localInvariantProp n).liftPropWithinAt_indep_chart_source he hx, StructureGroupoid.liftPropWithinAt_self_source, e.extend_symm_continuousWithinAt_comp_right_iff, contDiffWithinAtProp_self_source, ContDiffWithinAtProp, Function.comp, e.left_inv hx, (e.extend I).left_inv h2x] rfl theorem contMDiffWithinAt_iff_source_of_mem_source [IsManifold I n M] {x' : M} (hx' : x' ∈ (chartAt H x).source) : ContMDiffWithinAt I I' n f s x' ↔ ContMDiffWithinAt π“˜(π•œ, E) I' n (f ∘ (extChartAt I x).symm) ((extChartAt I x).symm ⁻¹' s ∩ range I) (extChartAt I x x') := contMDiffWithinAt_iff_source_of_mem_maximalAtlas (chart_mem_maximalAtlas x) hx' theorem contMDiffAt_iff_source_of_mem_source [IsManifold I n M] {x' : M} (hx' : x' ∈ (chartAt H x).source) : ContMDiffAt I I' n f x' ↔ ContMDiffWithinAt π“˜(π•œ, E) I' n (f ∘ (extChartAt I x).symm) (range I) (extChartAt I x x') := by simp_rw [ContMDiffAt, contMDiffWithinAt_iff_source_of_mem_source hx', preimage_univ, univ_inter]
theorem contMDiffWithinAt_iff_target_of_mem_source [IsManifold I' n M'] {x : M} {y : M'} (hy : f x ∈ (chartAt H' y).source) : ContMDiffWithinAt I I' n f s x ↔ ContinuousWithinAt f s x ∧ ContMDiffWithinAt I π“˜(π•œ, E') n (extChartAt I' y ∘ f) s x := by
Mathlib/Geometry/Manifold/ContMDiff/Defs.lean
377
380
/- Copyright (c) 2021 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying, RΓ©my Degenne -/ import Mathlib.Probability.Process.Adapted import Mathlib.MeasureTheory.Constructions.BorelSpace.Order /-! # Stopping times, stopped processes and stopped values Definition and properties of stopping times. ## Main definitions * `MeasureTheory.IsStoppingTime`: a stopping time with respect to some filtration `f` is a function `Ο„` such that for all `i`, the preimage of `{j | j ≀ i}` along `Ο„` is `f i`-measurable * `MeasureTheory.IsStoppingTime.measurableSpace`: the Οƒ-algebra associated with a stopping time ## Main results * `ProgMeasurable.stoppedProcess`: the stopped process of a progressively measurable process is progressively measurable. * `memLp_stoppedProcess`: if a process belongs to `β„’p` at every time in `β„•`, then its stopped process belongs to `β„’p` as well. ## Tags stopping time, stochastic process -/ open Filter Order TopologicalSpace open scoped MeasureTheory NNReal ENNReal Topology namespace MeasureTheory variable {Ξ© Ξ² ΞΉ : Type*} {m : MeasurableSpace Ξ©} /-! ### Stopping times -/ /-- A stopping time with respect to some filtration `f` is a function `Ο„` such that for all `i`, the preimage of `{j | j ≀ i}` along `Ο„` is measurable with respect to `f i`. Intuitively, the stopping time `Ο„` describes some stopping rule such that at time `i`, we may determine it with the information we have at time `i`. -/ def IsStoppingTime [Preorder ΞΉ] (f : Filtration ΞΉ m) (Ο„ : Ξ© β†’ ΞΉ) := βˆ€ i : ΞΉ, MeasurableSet[f i] <| {Ο‰ | Ο„ Ο‰ ≀ i} theorem isStoppingTime_const [Preorder ΞΉ] (f : Filtration ΞΉ m) (i : ΞΉ) : IsStoppingTime f fun _ => i := fun j => by simp only [MeasurableSet.const] section MeasurableSet section Preorder variable [Preorder ΞΉ] {f : Filtration ΞΉ m} {Ο„ : Ξ© β†’ ΞΉ} protected theorem IsStoppingTime.measurableSet_le (hΟ„ : IsStoppingTime f Ο„) (i : ΞΉ) : MeasurableSet[f i] {Ο‰ | Ο„ Ο‰ ≀ i} := hΟ„ i theorem IsStoppingTime.measurableSet_lt_of_pred [PredOrder ΞΉ] (hΟ„ : IsStoppingTime f Ο„) (i : ΞΉ) : MeasurableSet[f i] {Ο‰ | Ο„ Ο‰ < i} := by by_cases hi_min : IsMin i Β· suffices {Ο‰ : Ξ© | Ο„ Ο‰ < i} = βˆ… by rw [this]; exact @MeasurableSet.empty _ (f i) ext1 Ο‰ simp only [Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false] rw [isMin_iff_forall_not_lt] at hi_min exact hi_min (Ο„ Ο‰) have : {Ο‰ : Ξ© | Ο„ Ο‰ < i} = Ο„ ⁻¹' Set.Iic (pred i) := by ext; simp [Iic_pred_of_not_isMin hi_min] rw [this] exact f.mono (pred_le i) _ (hΟ„.measurableSet_le <| pred i) end Preorder section CountableStoppingTime namespace IsStoppingTime variable [PartialOrder ΞΉ] {Ο„ : Ξ© β†’ ΞΉ} {f : Filtration ΞΉ m} protected theorem measurableSet_eq_of_countable_range (hΟ„ : IsStoppingTime f Ο„) (h_countable : (Set.range Ο„).Countable) (i : ΞΉ) : MeasurableSet[f i] {Ο‰ | Ο„ Ο‰ = i} := by have : {Ο‰ | Ο„ Ο‰ = i} = {Ο‰ | Ο„ Ο‰ ≀ i} \ ⋃ (j ∈ Set.range Ο„) (_ : j < i), {Ο‰ | Ο„ Ο‰ ≀ j} := by ext1 a simp only [Set.mem_setOf_eq, Set.mem_range, Set.iUnion_exists, Set.iUnion_iUnion_eq', Set.mem_diff, Set.mem_iUnion, exists_prop, not_exists, not_and, not_le] constructor <;> intro h Β· simp only [h, lt_iff_le_not_le, le_refl, and_imp, imp_self, imp_true_iff, and_self_iff] Β· exact h.1.eq_or_lt.resolve_right fun h_lt => h.2 a h_lt le_rfl rw [this] refine (hΟ„.measurableSet_le i).diff ?_ refine MeasurableSet.biUnion h_countable fun j _ => ?_ classical rw [Set.iUnion_eq_if] split_ifs with hji Β· exact f.mono hji.le _ (hΟ„.measurableSet_le j) Β· exact @MeasurableSet.empty _ (f i) protected theorem measurableSet_eq_of_countable [Countable ΞΉ] (hΟ„ : IsStoppingTime f Ο„) (i : ΞΉ) : MeasurableSet[f i] {Ο‰ | Ο„ Ο‰ = i} := hΟ„.measurableSet_eq_of_countable_range (Set.to_countable _) i protected theorem measurableSet_lt_of_countable_range (hΟ„ : IsStoppingTime f Ο„) (h_countable : (Set.range Ο„).Countable) (i : ΞΉ) : MeasurableSet[f i] {Ο‰ | Ο„ Ο‰ < i} := by have : {Ο‰ | Ο„ Ο‰ < i} = {Ο‰ | Ο„ Ο‰ ≀ i} \ {Ο‰ | Ο„ Ο‰ = i} := by ext1 Ο‰; simp [lt_iff_le_and_ne] rw [this] exact (hΟ„.measurableSet_le i).diff (hΟ„.measurableSet_eq_of_countable_range h_countable i) protected theorem measurableSet_lt_of_countable [Countable ΞΉ] (hΟ„ : IsStoppingTime f Ο„) (i : ΞΉ) : MeasurableSet[f i] {Ο‰ | Ο„ Ο‰ < i} := hΟ„.measurableSet_lt_of_countable_range (Set.to_countable _) i protected theorem measurableSet_ge_of_countable_range {ΞΉ} [LinearOrder ΞΉ] {Ο„ : Ξ© β†’ ΞΉ} {f : Filtration ΞΉ m} (hΟ„ : IsStoppingTime f Ο„) (h_countable : (Set.range Ο„).Countable) (i : ΞΉ) : MeasurableSet[f i] {Ο‰ | i ≀ Ο„ Ο‰} := by have : {Ο‰ | i ≀ Ο„ Ο‰} = {Ο‰ | Ο„ Ο‰ < i}ᢜ := by ext1 Ο‰; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_lt] rw [this] exact (hΟ„.measurableSet_lt_of_countable_range h_countable i).compl protected theorem measurableSet_ge_of_countable {ΞΉ} [LinearOrder ΞΉ] {Ο„ : Ξ© β†’ ΞΉ} {f : Filtration ΞΉ m} [Countable ΞΉ] (hΟ„ : IsStoppingTime f Ο„) (i : ΞΉ) : MeasurableSet[f i] {Ο‰ | i ≀ Ο„ Ο‰} := hΟ„.measurableSet_ge_of_countable_range (Set.to_countable _) i end IsStoppingTime end CountableStoppingTime section LinearOrder variable [LinearOrder ΞΉ] {f : Filtration ΞΉ m} {Ο„ : Ξ© β†’ ΞΉ} theorem IsStoppingTime.measurableSet_gt (hΟ„ : IsStoppingTime f Ο„) (i : ΞΉ) : MeasurableSet[f i] {Ο‰ | i < Ο„ Ο‰} := by have : {Ο‰ | i < Ο„ Ο‰} = {Ο‰ | Ο„ Ο‰ ≀ i}ᢜ := by ext1 Ο‰; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_le] rw [this] exact (hΟ„.measurableSet_le i).compl section TopologicalSpace variable [TopologicalSpace ΞΉ] [OrderTopology ΞΉ] [FirstCountableTopology ΞΉ] /-- Auxiliary lemma for `MeasureTheory.IsStoppingTime.measurableSet_lt`. -/ theorem IsStoppingTime.measurableSet_lt_of_isLUB (hΟ„ : IsStoppingTime f Ο„) (i : ΞΉ) (h_lub : IsLUB (Set.Iio i) i) : MeasurableSet[f i] {Ο‰ | Ο„ Ο‰ < i} := by by_cases hi_min : IsMin i Β· suffices {Ο‰ | Ο„ Ο‰ < i} = βˆ… by rw [this]; exact @MeasurableSet.empty _ (f i) ext1 Ο‰ simp only [Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false] exact isMin_iff_forall_not_lt.mp hi_min (Ο„ Ο‰) obtain ⟨seq, -, -, h_tendsto, h_bound⟩ : βˆƒ seq : β„• β†’ ΞΉ, Monotone seq ∧ (βˆ€ j, seq j ≀ i) ∧ Tendsto seq atTop (𝓝 i) ∧ βˆ€ j, seq j < i := h_lub.exists_seq_monotone_tendsto (not_isMin_iff.mp hi_min) have h_Ioi_eq_Union : Set.Iio i = ⋃ j, {k | k ≀ seq j} := by ext1 k simp only [Set.mem_Iio, Set.mem_iUnion, Set.mem_setOf_eq] refine ⟨fun hk_lt_i => ?_, fun h_exists_k_le_seq => ?_⟩ Β· rw [tendsto_atTop'] at h_tendsto have h_nhds : Set.Ici k ∈ 𝓝 i := mem_nhds_iff.mpr ⟨Set.Ioi k, Set.Ioi_subset_Ici le_rfl, isOpen_Ioi, hk_lt_i⟩ obtain ⟨a, ha⟩ : βˆƒ a : β„•, βˆ€ b : β„•, b β‰₯ a β†’ k ≀ seq b := h_tendsto (Set.Ici k) h_nhds exact ⟨a, ha a le_rfl⟩ Β· obtain ⟨j, hk_seq_j⟩ := h_exists_k_le_seq exact hk_seq_j.trans_lt (h_bound j) have h_lt_eq_preimage : {Ο‰ | Ο„ Ο‰ < i} = Ο„ ⁻¹' Set.Iio i := by ext1 Ο‰; simp only [Set.mem_setOf_eq, Set.mem_preimage, Set.mem_Iio] rw [h_lt_eq_preimage, h_Ioi_eq_Union] simp only [Set.preimage_iUnion, Set.preimage_setOf_eq] exact MeasurableSet.iUnion fun n => f.mono (h_bound n).le _ (hΟ„.measurableSet_le (seq n)) theorem IsStoppingTime.measurableSet_lt (hΟ„ : IsStoppingTime f Ο„) (i : ΞΉ) : MeasurableSet[f i] {Ο‰ | Ο„ Ο‰ < i} := by obtain ⟨i', hi'_lub⟩ : βˆƒ i', IsLUB (Set.Iio i) i' := exists_lub_Iio i rcases lub_Iio_eq_self_or_Iio_eq_Iic i hi'_lub with hi'_eq_i | h_Iio_eq_Iic Β· rw [← hi'_eq_i] at hi'_lub ⊒ exact hΟ„.measurableSet_lt_of_isLUB i' hi'_lub Β· have h_lt_eq_preimage : {Ο‰ : Ξ© | Ο„ Ο‰ < i} = Ο„ ⁻¹' Set.Iio i := rfl rw [h_lt_eq_preimage, h_Iio_eq_Iic] exact f.mono (lub_Iio_le i hi'_lub) _ (hΟ„.measurableSet_le i') theorem IsStoppingTime.measurableSet_ge (hΟ„ : IsStoppingTime f Ο„) (i : ΞΉ) : MeasurableSet[f i] {Ο‰ | i ≀ Ο„ Ο‰} := by have : {Ο‰ | i ≀ Ο„ Ο‰} = {Ο‰ | Ο„ Ο‰ < i}ᢜ := by ext1 Ο‰; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_lt] rw [this] exact (hΟ„.measurableSet_lt i).compl theorem IsStoppingTime.measurableSet_eq (hΟ„ : IsStoppingTime f Ο„) (i : ΞΉ) : MeasurableSet[f i] {Ο‰ | Ο„ Ο‰ = i} := by have : {Ο‰ | Ο„ Ο‰ = i} = {Ο‰ | Ο„ Ο‰ ≀ i} ∩ {Ο‰ | Ο„ Ο‰ β‰₯ i} := by ext1 Ο‰; simp only [Set.mem_setOf_eq, Set.mem_inter_iff, le_antisymm_iff] rw [this] exact (hΟ„.measurableSet_le i).inter (hΟ„.measurableSet_ge i)
theorem IsStoppingTime.measurableSet_eq_le (hΟ„ : IsStoppingTime f Ο„) {i j : ΞΉ} (hle : i ≀ j) : MeasurableSet[f j] {Ο‰ | Ο„ Ο‰ = i} := f.mono hle _ <| hΟ„.measurableSet_eq i theorem IsStoppingTime.measurableSet_lt_le (hΟ„ : IsStoppingTime f Ο„) {i j : ΞΉ} (hle : i ≀ j) : MeasurableSet[f j] {Ο‰ | Ο„ Ο‰ < i} :=
Mathlib/Probability/Process/Stopping.lean
202
207
/- 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, Floris van Doorn -/ import Mathlib.Geometry.Manifold.IsManifold.ExtChartAt import Mathlib.Geometry.Manifold.LocalInvariantProperties /-! # `C^n` functions between manifolds We define `Cⁿ` functions between manifolds, as functions which are `Cⁿ` in charts, and prove basic properties of these notions. Here, `n` can be finite, or `∞`, or `Ο‰`. ## Main definitions and statements Let `M` and `M'` be two manifolds, with respect to models with corners `I` and `I'`. Let `f : M β†’ M'`. * `ContMDiffWithinAt I I' n f s x` states that the function `f` is `Cⁿ` within the set `s` around the point `x`. * `ContMDiffAt I I' n f x` states that the function `f` is `Cⁿ` around `x`. * `ContMDiffOn I I' n f s` states that the function `f` is `Cⁿ` on the set `s` * `ContMDiff I I' n f` states that the function `f` is `Cⁿ`. We also give some basic properties of `Cⁿ` functions between manifolds, following the API of `C^n` functions between vector spaces. See `Basic.lean` for further basic properties of `Cⁿ` functions between manifolds, `NormedSpace.lean` for the equivalence of manifold-smoothness to usual smoothness, `Product.lean` for smoothness results related to the product of manifolds and `Atlas.lean` for smoothness of atlas members and local structomorphisms. ## Implementation details Many properties follow for free from the corresponding properties of functions in vector spaces, as being `Cⁿ` is a local property invariant under the `Cⁿ` groupoid. We take advantage of the general machinery developed in `LocalInvariantProperties.lean` to get these properties automatically. For instance, the fact that being `Cⁿ` does not depend on the chart one considers is given by `liftPropWithinAt_indep_chart`. For this to work, the definition of `ContMDiffWithinAt` and friends has to follow definitionally the setup of local invariant properties. Still, we recast the definition in terms of extended charts in `contMDiffOn_iff` and `contMDiff_iff`. -/ open Set Function Filter ChartedSpace IsManifold open scoped Topology Manifold ContDiff /-! ### Definition of `Cⁿ` functions between manifolds -/ variable {π•œ : Type*} [NontriviallyNormedField π•œ] -- Prerequisite typeclasses to say that `M` is a manifold over the pair `(E, H)` {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners π•œ E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] -- Prerequisite typeclasses to say that `M'` is a manifold over the pair `(E', H')` {E' : Type*} [NormedAddCommGroup E'] [NormedSpace π•œ E'] {H' : Type*} [TopologicalSpace H'] {I' : ModelWithCorners π•œ E' H'} {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M'] -- Prerequisite typeclasses to say that `M''` is a manifold over the pair `(E'', H'')` {E'' : Type*} [NormedAddCommGroup E''] [NormedSpace π•œ E''] {H'' : Type*} [TopologicalSpace H''] {I'' : ModelWithCorners π•œ E'' H''} {M'' : Type*} [TopologicalSpace M''] [ChartedSpace H'' M''] -- declare functions, sets, points and smoothness indices {e : PartialHomeomorph M H} {e' : PartialHomeomorph M' H'} {f f₁ : M β†’ M'} {s s₁ t : Set M} {x : M} {m n : WithTop β„•βˆž} variable (I I') in /-- Property in the model space of a model with corners of being `C^n` within at set at a point, when read in the model vector space. This property will be lifted to manifolds to define `C^n` functions between manifolds. -/ def ContDiffWithinAtProp (n : WithTop β„•βˆž) (f : H β†’ H') (s : Set H) (x : H) : Prop := ContDiffWithinAt π•œ n (I' ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ range I) (I x) theorem contDiffWithinAtProp_self_source {f : E β†’ H'} {s : Set E} {x : E} : ContDiffWithinAtProp π“˜(π•œ, E) I' n f s x ↔ ContDiffWithinAt π•œ n (I' ∘ f) s x := by simp_rw [ContDiffWithinAtProp, modelWithCornersSelf_coe, range_id, inter_univ, modelWithCornersSelf_coe_symm, CompTriple.comp_eq, preimage_id_eq, id_eq] theorem contDiffWithinAtProp_self {f : E β†’ E'} {s : Set E} {x : E} : ContDiffWithinAtProp π“˜(π•œ, E) π“˜(π•œ, E') n f s x ↔ ContDiffWithinAt π•œ n f s x := contDiffWithinAtProp_self_source theorem contDiffWithinAtProp_self_target {f : H β†’ E'} {s : Set H} {x : H} : ContDiffWithinAtProp I π“˜(π•œ, E') n f s x ↔ ContDiffWithinAt π•œ n (f ∘ I.symm) (I.symm ⁻¹' s ∩ range I) (I x) := Iff.rfl /-- Being `Cⁿ` in the model space is a local property, invariant under `Cⁿ` maps. Therefore, it lifts nicely to manifolds. -/ theorem contDiffWithinAt_localInvariantProp_of_le (n m : WithTop β„•βˆž) (hmn : m ≀ n) : (contDiffGroupoid n I).LocalInvariantProp (contDiffGroupoid n I') (ContDiffWithinAtProp I I' m) where is_local {s x u f} u_open xu := by have : I.symm ⁻¹' (s ∩ u) ∩ range I = I.symm ⁻¹' s ∩ range I ∩ I.symm ⁻¹' u := by simp only [inter_right_comm, preimage_inter] rw [ContDiffWithinAtProp, ContDiffWithinAtProp, this] symm apply contDiffWithinAt_inter have : u ∈ 𝓝 (I.symm (I x)) := by rw [ModelWithCorners.left_inv] exact u_open.mem_nhds xu apply ContinuousAt.preimage_mem_nhds I.continuous_symm.continuousAt this right_invariance' {s x f e} he hx h := by rw [ContDiffWithinAtProp] at h ⊒ have : I x = (I ∘ e.symm ∘ I.symm) (I (e x)) := by simp only [hx, mfld_simps] rw [this] at h have : I (e x) ∈ I.symm ⁻¹' e.target ∩ range I := by simp only [hx, mfld_simps] have := (mem_groupoid_of_pregroupoid.2 he).2.contDiffWithinAt this convert (h.comp_inter _ (this.of_le hmn)).mono_of_mem_nhdsWithin _ using 1 Β· ext y; simp only [mfld_simps] refine mem_nhdsWithin.mpr ⟨I.symm ⁻¹' e.target, e.open_target.preimage I.continuous_symm, by simp_rw [mem_preimage, I.left_inv, e.mapsTo hx], ?_⟩ mfld_set_tac congr_of_forall {s x f g} h hx hf := by apply hf.congr Β· intro y hy simp only [mfld_simps] at hy simp only [h, hy, mfld_simps] Β· simp only [hx, mfld_simps] left_invariance' {s x f e'} he' hs hx h := by rw [ContDiffWithinAtProp] at h ⊒ have A : (I' ∘ f ∘ I.symm) (I x) ∈ I'.symm ⁻¹' e'.source ∩ range I' := by simp only [hx, mfld_simps] have := (mem_groupoid_of_pregroupoid.2 he').1.contDiffWithinAt A convert (this.of_le hmn).comp _ h _ Β· ext y; simp only [mfld_simps] Β· intro y hy; simp only [mfld_simps] at hy; simpa only [hy, mfld_simps] using hs hy.1 /-- Being `Cⁿ` in the model space is a local property, invariant under `C^n` maps. Therefore, it lifts nicely to manifolds. -/ theorem contDiffWithinAt_localInvariantProp (n : WithTop β„•βˆž) : (contDiffGroupoid n I).LocalInvariantProp (contDiffGroupoid n I') (ContDiffWithinAtProp I I' n) := contDiffWithinAt_localInvariantProp_of_le n n le_rfl theorem contDiffWithinAtProp_mono_of_mem_nhdsWithin (n : WithTop β„•βˆž) ⦃s x t⦄ ⦃f : H β†’ H'⦄ (hts : s ∈ 𝓝[t] x) (h : ContDiffWithinAtProp I I' n f s x) : ContDiffWithinAtProp I I' n f t x := by refine h.mono_of_mem_nhdsWithin ?_ refine inter_mem ?_ (mem_of_superset self_mem_nhdsWithin inter_subset_right) rwa [← Filter.mem_map, ← I.image_eq, I.symm_map_nhdsWithin_image] @[deprecated (since := "2024-10-31")] alias contDiffWithinAtProp_mono_of_mem := contDiffWithinAtProp_mono_of_mem_nhdsWithin theorem contDiffWithinAtProp_id (x : H) : ContDiffWithinAtProp I I n id univ x := by simp only [ContDiffWithinAtProp, id_comp, preimage_univ, univ_inter] have : ContDiffWithinAt π•œ n id (range I) (I x) := contDiff_id.contDiffAt.contDiffWithinAt refine this.congr (fun y hy => ?_) ?_ Β· simp only [ModelWithCorners.right_inv I hy, mfld_simps] Β· simp only [mfld_simps] variable (I I') in /-- A function is `n` times continuously differentiable within a set at a point in a manifold if it is continuous and it is `n` times continuously differentiable in this set around this point, when read in the preferred chart at this point. -/ def ContMDiffWithinAt (n : WithTop β„•βˆž) (f : M β†’ M') (s : Set M) (x : M) := LiftPropWithinAt (ContDiffWithinAtProp I I' n) f s x @[deprecated (since := "2024-11-21")] alias SmoothWithinAt := ContMDiffWithinAt variable (I I') in /-- A function is `n` times continuously differentiable at a point in a manifold if it is continuous and it is `n` times continuously differentiable around this point, when read in the preferred chart at this point. -/ def ContMDiffAt (n : WithTop β„•βˆž) (f : M β†’ M') (x : M) := ContMDiffWithinAt I I' n f univ x theorem contMDiffAt_iff {n : WithTop β„•βˆž} {f : M β†’ M'} {x : M} : ContMDiffAt I I' n f x ↔ ContinuousAt f x ∧ ContDiffWithinAt π•œ n (extChartAt I' (f x) ∘ f ∘ (extChartAt I x).symm) (range I) (extChartAt I x x) := liftPropAt_iff.trans <| by rw [ContDiffWithinAtProp, preimage_univ, univ_inter]; rfl @[deprecated (since := "2024-11-21")] alias SmoothAt := ContMDiffAt variable (I I') in /-- A function is `n` times continuously differentiable in a set of a manifold if it is continuous and, for any pair of points, it is `n` times continuously differentiable on this set in the charts around these points. -/ def ContMDiffOn (n : WithTop β„•βˆž) (f : M β†’ M') (s : Set M) := βˆ€ x ∈ s, ContMDiffWithinAt I I' n f s x @[deprecated (since := "2024-11-21")] alias SmoothOn := ContMDiffOn variable (I I') in /-- A function is `n` times continuously differentiable in a manifold if it is continuous and, for any pair of points, it is `n` times continuously differentiable in the charts around these points. -/ def ContMDiff (n : WithTop β„•βˆž) (f : M β†’ M') := βˆ€ x, ContMDiffAt I I' n f x @[deprecated (since := "2024-11-21")] alias Smooth := ContMDiff /-! ### Deducing smoothness from higher smoothness -/ theorem ContMDiffWithinAt.of_le (hf : ContMDiffWithinAt I I' n f s x) (le : m ≀ n) : ContMDiffWithinAt I I' m f s x := by simp only [ContMDiffWithinAt, LiftPropWithinAt] at hf ⊒ exact ⟨hf.1, hf.2.of_le (mod_cast le)⟩ theorem ContMDiffAt.of_le (hf : ContMDiffAt I I' n f x) (le : m ≀ n) : ContMDiffAt I I' m f x := ContMDiffWithinAt.of_le hf le theorem ContMDiffOn.of_le (hf : ContMDiffOn I I' n f s) (le : m ≀ n) : ContMDiffOn I I' m f s := fun x hx => (hf x hx).of_le le theorem ContMDiff.of_le (hf : ContMDiff I I' n f) (le : m ≀ n) : ContMDiff I I' m f := fun x => (hf x).of_le le /-! ### Basic properties of `C^n` functions between manifolds -/ @[deprecated (since := "2024-11-20")] alias ContMDiff.smooth := ContMDiff.of_le @[deprecated (since := "2024-11-20")] alias Smooth.contMDiff := ContMDiff.of_le @[deprecated (since := "2024-11-20")] alias ContMDiffOn.smoothOn := ContMDiffOn.of_le @[deprecated (since := "2024-11-20")] alias SmoothOn.contMDiffOn := ContMDiffOn.of_le @[deprecated (since := "2024-11-20")] alias ContMDiffAt.smoothAt := ContMDiffAt.of_le @[deprecated (since := "2024-11-20")] alias SmoothAt.contMDiffAt := ContMDiffOn.of_le @[deprecated (since := "2024-11-20")] alias ContMDiffWithinAt.smoothWithinAt := ContMDiffWithinAt.of_le @[deprecated (since := "2024-11-20")] alias SmoothWithinAt.contMDiffWithinAt := ContMDiffWithinAt.of_le theorem ContMDiff.contMDiffAt (h : ContMDiff I I' n f) : ContMDiffAt I I' n f x := h x @[deprecated (since := "2024-11-20")] alias Smooth.smoothAt := ContMDiff.contMDiffAt theorem contMDiffWithinAt_univ : ContMDiffWithinAt I I' n f univ x ↔ ContMDiffAt I I' n f x := Iff.rfl @[deprecated (since := "2024-11-20")] alias smoothWithinAt_univ := contMDiffWithinAt_univ theorem contMDiffOn_univ : ContMDiffOn I I' n f univ ↔ ContMDiff I I' n f := by simp only [ContMDiffOn, ContMDiff, contMDiffWithinAt_univ, forall_prop_of_true, mem_univ] @[deprecated (since := "2024-11-20")] alias smoothOn_univ := contMDiffOn_univ /-- One can reformulate being `C^n` within a set at a point as continuity within this set at this point, and being `C^n` in the corresponding extended chart. -/ theorem contMDiffWithinAt_iff : ContMDiffWithinAt I I' n f s x ↔ ContinuousWithinAt f s x ∧ ContDiffWithinAt π•œ n (extChartAt I' (f x) ∘ f ∘ (extChartAt I x).symm) ((extChartAt I x).symm ⁻¹' s ∩ range I) (extChartAt I x x) := by simp_rw [ContMDiffWithinAt, liftPropWithinAt_iff']; rfl /-- One can reformulate being `Cⁿ` within a set at a point as continuity within this set at this point, and being `Cⁿ` in the corresponding extended chart. This form states regularity of `f` written in such a way that the set is restricted to lie within the domain/codomain of the corresponding charts. Even though this expression is more complicated than the one in `contMDiffWithinAt_iff`, it is a smaller set, but their germs at `extChartAt I x x` are equal. It is sometimes useful to rewrite using this in the goal. -/ theorem contMDiffWithinAt_iff' : ContMDiffWithinAt I I' n f s x ↔ ContinuousWithinAt f s x ∧ ContDiffWithinAt π•œ n (extChartAt I' (f x) ∘ f ∘ (extChartAt I x).symm) ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' (s ∩ f ⁻¹' (extChartAt I' (f x)).source)) (extChartAt I x x) := by simp only [ContMDiffWithinAt, liftPropWithinAt_iff'] exact and_congr_right fun hc => contDiffWithinAt_congr_set <| hc.extChartAt_symm_preimage_inter_range_eventuallyEq /-- One can reformulate being `Cⁿ` within a set at a point as continuity within this set at this point, and being `Cⁿ` in the corresponding extended chart in the target. -/ theorem contMDiffWithinAt_iff_target : ContMDiffWithinAt I I' n f s x ↔ ContinuousWithinAt f s x ∧ ContMDiffWithinAt I π“˜(π•œ, E') n (extChartAt I' (f x) ∘ f) s x := by simp_rw [ContMDiffWithinAt, liftPropWithinAt_iff', ← and_assoc] have cont : ContinuousWithinAt f s x ∧ ContinuousWithinAt (extChartAt I' (f x) ∘ f) s x ↔ ContinuousWithinAt f s x := and_iff_left_of_imp <| (continuousAt_extChartAt _).comp_continuousWithinAt simp_rw [cont, ContDiffWithinAtProp, extChartAt, PartialHomeomorph.extend, PartialEquiv.coe_trans, ModelWithCorners.toPartialEquiv_coe, PartialHomeomorph.coe_coe, modelWithCornersSelf_coe, chartAt_self_eq, PartialHomeomorph.refl_apply, id_comp] rfl @[deprecated (since := "2024-11-20")] alias smoothWithinAt_iff := contMDiffWithinAt_iff @[deprecated (since := "2024-11-20")] alias smoothWithinAt_iff_target := contMDiffWithinAt_iff_target theorem contMDiffAt_iff_target {x : M} : ContMDiffAt I I' n f x ↔ ContinuousAt f x ∧ ContMDiffAt I π“˜(π•œ, E') n (extChartAt I' (f x) ∘ f) x := by rw [ContMDiffAt, ContMDiffAt, contMDiffWithinAt_iff_target, continuousWithinAt_univ] @[deprecated (since := "2024-11-20")] alias smoothAt_iff_target := contMDiffAt_iff_target /-- One can reformulate being `Cⁿ` within a set at a point as being `Cⁿ` in the source space when composing with the extended chart. -/ theorem contMDiffWithinAt_iff_source : ContMDiffWithinAt I I' n f s x ↔ ContMDiffWithinAt π“˜(π•œ, E) I' n (f ∘ (extChartAt I x).symm) ((extChartAt I x).symm ⁻¹' s ∩ range I) (extChartAt I x x) := by simp_rw [ContMDiffWithinAt, liftPropWithinAt_iff'] have : ContinuousWithinAt f s x ↔ ContinuousWithinAt (f ∘ ↑(extChartAt I x).symm) (↑(extChartAt I x).symm ⁻¹' s ∩ range ↑I) (extChartAt I x x) := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ Β· apply h.comp_of_eq Β· exact (continuousAt_extChartAt_symm x).continuousWithinAt Β· exact (mapsTo_preimage _ _).mono_left inter_subset_left Β· exact extChartAt_to_inv x Β· rw [← continuousWithinAt_inter (extChartAt_source_mem_nhds (I := I) x)] have : ContinuousWithinAt ((f ∘ ↑(extChartAt I x).symm) ∘ ↑(extChartAt I x)) (s ∩ (extChartAt I x).source) x := by apply h.comp (continuousAt_extChartAt x).continuousWithinAt intro y hy have : (chartAt H x).symm ((chartAt H x) y) = y := PartialHomeomorph.left_inv _ (by simpa using hy.2) simpa [this] using hy.1 apply this.congr Β· intro y hy have : (chartAt H x).symm ((chartAt H x) y) = y := PartialHomeomorph.left_inv _ (by simpa using hy.2) simp [this] Β· simp rw [← this] simp only [ContDiffWithinAtProp, mfld_simps, preimage_comp, comp_assoc] /-- One can reformulate being `Cⁿ` at a point as being `Cⁿ` in the source space when composing with the extended chart. -/ theorem contMDiffAt_iff_source : ContMDiffAt I I' n f x ↔ ContMDiffWithinAt π“˜(π•œ, E) I' n (f ∘ (extChartAt I x).symm) (range I) (extChartAt I x x) := by rw [← contMDiffWithinAt_univ, contMDiffWithinAt_iff_source] simp section IsManifold theorem contMDiffWithinAt_iff_source_of_mem_maximalAtlas [IsManifold I n M] (he : e ∈ maximalAtlas I n M) (hx : x ∈ e.source) : ContMDiffWithinAt I I' n f s x ↔ ContMDiffWithinAt π“˜(π•œ, E) I' n (f ∘ (e.extend I).symm) ((e.extend I).symm ⁻¹' s ∩ range I) (e.extend I x) := by have h2x := hx; rw [← e.extend_source (I := I)] at h2x simp_rw [ContMDiffWithinAt, (contDiffWithinAt_localInvariantProp n).liftPropWithinAt_indep_chart_source he hx, StructureGroupoid.liftPropWithinAt_self_source, e.extend_symm_continuousWithinAt_comp_right_iff, contDiffWithinAtProp_self_source, ContDiffWithinAtProp, Function.comp, e.left_inv hx, (e.extend I).left_inv h2x] rfl theorem contMDiffWithinAt_iff_source_of_mem_source [IsManifold I n M] {x' : M} (hx' : x' ∈ (chartAt H x).source) : ContMDiffWithinAt I I' n f s x' ↔ ContMDiffWithinAt π“˜(π•œ, E) I' n (f ∘ (extChartAt I x).symm) ((extChartAt I x).symm ⁻¹' s ∩ range I) (extChartAt I x x') := contMDiffWithinAt_iff_source_of_mem_maximalAtlas (chart_mem_maximalAtlas x) hx' theorem contMDiffAt_iff_source_of_mem_source [IsManifold I n M] {x' : M} (hx' : x' ∈ (chartAt H x).source) : ContMDiffAt I I' n f x' ↔ ContMDiffWithinAt π“˜(π•œ, E) I' n (f ∘ (extChartAt I x).symm) (range I) (extChartAt I x x') := by simp_rw [ContMDiffAt, contMDiffWithinAt_iff_source_of_mem_source hx', preimage_univ, univ_inter] theorem contMDiffWithinAt_iff_target_of_mem_source [IsManifold I' n M'] {x : M} {y : M'} (hy : f x ∈ (chartAt H' y).source) : ContMDiffWithinAt I I' n f s x ↔ ContinuousWithinAt f s x ∧ ContMDiffWithinAt I π“˜(π•œ, E') n (extChartAt I' y ∘ f) s x := by simp_rw [ContMDiffWithinAt] rw [(contDiffWithinAt_localInvariantProp n).liftPropWithinAt_indep_chart_target (chart_mem_maximalAtlas y) hy, and_congr_right] intro hf simp_rw [StructureGroupoid.liftPropWithinAt_self_target] simp_rw [((chartAt H' y).continuousAt hy).comp_continuousWithinAt hf] rw [← extChartAt_source (I := I')] at hy simp_rw [(continuousAt_extChartAt' hy).comp_continuousWithinAt hf] rfl theorem contMDiffAt_iff_target_of_mem_source [IsManifold I' n M'] {x : M} {y : M'} (hy : f x ∈ (chartAt H' y).source) : ContMDiffAt I I' n f x ↔ ContinuousAt f x ∧ ContMDiffAt I π“˜(π•œ, E') n (extChartAt I' y ∘ f) x := by rw [ContMDiffAt, contMDiffWithinAt_iff_target_of_mem_source hy, continuousWithinAt_univ, ContMDiffAt]
variable [IsManifold I n M] [IsManifold I' n M'] theorem contMDiffWithinAt_iff_of_mem_maximalAtlas {x : M} (he : e ∈ maximalAtlas I n M) (he' : e' ∈ maximalAtlas I' n M') (hx : x ∈ e.source) (hy : f x ∈ e'.source) : ContMDiffWithinAt I I' n f s x ↔ ContinuousWithinAt f s x ∧ ContDiffWithinAt π•œ n (e'.extend I' ∘ f ∘ (e.extend I).symm) ((e.extend I).symm ⁻¹' s ∩ range I) (e.extend I x) := (contDiffWithinAt_localInvariantProp n).liftPropWithinAt_indep_chart he hx he' hy
Mathlib/Geometry/Manifold/ContMDiff/Defs.lean
399
407
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Bhavik Mehta, Stuart Presnell -/ import Mathlib.Data.Nat.Factorial.Basic import Mathlib.Order.Monotone.Defs /-! # Binomial coefficients This file defines binomial coefficients and proves simple lemmas (i.e. those not requiring more imports). For the lemma that `n.choose k` counts the `k`-element-subsets of an `n`-element set, see `Fintype.card_powersetCard` in `Mathlib.Data.Finset.Powerset`. ## Main definition and results * `Nat.choose`: binomial coefficients, defined inductively * `Nat.choose_eq_factorial_div_factorial`: a proof that `choose n k = n! / (k! * (n - k)!)` * `Nat.choose_symm`: symmetry of binomial coefficients * `Nat.choose_le_succ_of_lt_half_left`: `choose n k` is increasing for small values of `k` * `Nat.choose_le_middle`: `choose n r` is maximised when `r` is `n/2` * `Nat.descFactorial_eq_factorial_mul_choose`: Relates binomial coefficients to the descending factorial. This is used to prove `Nat.choose_le_pow` and variants. We provide similar statements for the ascending factorial. * `Nat.multichoose`: whereas `choose` counts combinations, `multichoose` counts multicombinations. The fact that this is indeed the correct counting function for multisets is proved in `Sym.card_sym_eq_multichoose` in `Data.Sym.Card`. * `Nat.multichoose_eq` : a proof that `multichoose n k = (n + k - 1).choose k`. This is central to the "stars and bars" technique in informal mathematics, where we switch between counting multisets of size `k` over an alphabet of size `n` to counting strings of `k` elements ("stars") separated by `n-1` dividers ("bars"). See `Data.Sym.Card` for more detail. ## Tags binomial coefficient, combination, multicombination, stars and bars -/ open Nat namespace Nat /-- `choose n k` is the number of `k`-element subsets in an `n`-element set. Also known as binomial coefficients. For the fact that this is the number of `k`-element-subsets of an `n`-element set, see `Fintype.card_powersetCard`. -/ def choose : β„• β†’ β„• β†’ β„• | _, 0 => 1 | 0, _ + 1 => 0 | n + 1, k + 1 => choose n k + choose n (k + 1) @[simp] theorem choose_zero_right (n : β„•) : choose n 0 = 1 := by cases n <;> rfl @[simp] theorem choose_zero_succ (k : β„•) : choose 0 (succ k) = 0 := rfl theorem choose_succ_succ (n k : β„•) : choose (succ n) (succ k) = choose n k + choose n (succ k) := rfl theorem choose_succ_succ' (n k : β„•) : choose (n + 1) (k + 1) = choose n k + choose n (k + 1) := rfl theorem choose_succ_left (n k : β„•) (hk : 0 < k) : choose (n + 1) k = choose n (k - 1) + choose n k := by obtain ⟨l, rfl⟩ : βˆƒ l, k = l + 1 := Nat.exists_eq_add_of_le' hk rfl theorem choose_succ_right (n k : β„•) (hn : 0 < n) : choose n (k + 1) = choose (n - 1) k + choose (n - 1) (k + 1) := by obtain ⟨l, rfl⟩ : βˆƒ l, n = l + 1 := Nat.exists_eq_add_of_le' hn rfl theorem choose_eq_choose_pred_add {n k : β„•} (hn : 0 < n) (hk : 0 < k) : choose n k = choose (n - 1) (k - 1) + choose (n - 1) k := by obtain ⟨l, rfl⟩ : βˆƒ l, k = l + 1 := Nat.exists_eq_add_of_le' hk rw [choose_succ_right _ _ hn, Nat.add_one_sub_one] theorem choose_eq_zero_of_lt : βˆ€ {n k}, n < k β†’ choose n k = 0 | _, 0, hk => absurd hk (Nat.not_lt_zero _) | 0, _ + 1, _ => choose_zero_succ _ | n + 1, k + 1, hk => by have hnk : n < k := lt_of_succ_lt_succ hk have hnk1 : n < k + 1 := lt_of_succ_lt hk rw [choose_succ_succ, choose_eq_zero_of_lt hnk, choose_eq_zero_of_lt hnk1] @[simp] theorem choose_self (n : β„•) : choose n n = 1 := by induction n <;> simp [*, choose, choose_eq_zero_of_lt (lt_succ_self _)] @[simp] theorem choose_succ_self (n : β„•) : choose n (succ n) = 0 := choose_eq_zero_of_lt (lt_succ_self _) @[simp] lemma choose_one_right (n : β„•) : choose n 1 = n := by induction n <;> simp [*, choose, Nat.add_comm] -- The `n+1`-st triangle number is `n` more than the `n`-th triangle number theorem triangle_succ (n : β„•) : (n + 1) * (n + 1 - 1) / 2 = n * (n - 1) / 2 + n := by rw [← add_mul_div_left, Nat.mul_comm 2 n, ← Nat.mul_add, Nat.add_sub_cancel, Nat.mul_comm] cases n <;> rfl; apply zero_lt_succ /-- `choose n 2` is the `n`-th triangle number. -/ theorem choose_two_right (n : β„•) : choose n 2 = n * (n - 1) / 2 := by induction' n with n ih Β· simp Β· rw [triangle_succ n, choose, ih] simp [Nat.add_comm] theorem choose_pos : βˆ€ {n k}, k ≀ n β†’ 0 < choose n k | 0, _, hk => by rw [Nat.eq_zero_of_le_zero hk]; decide | n + 1, 0, _ => by simp | _ + 1, _ + 1, hk => Nat.add_pos_left (choose_pos (le_of_succ_le_succ hk)) _ theorem choose_eq_zero_iff {n k : β„•} : n.choose k = 0 ↔ n < k := ⟨fun h => lt_of_not_ge (mt Nat.choose_pos h.symm.not_lt), Nat.choose_eq_zero_of_lt⟩ theorem succ_mul_choose_eq : βˆ€ n k, succ n * choose n k = choose (succ n) (succ k) * succ k | 0, 0 => by decide | 0, k + 1 => by simp [choose] | n + 1, 0 => by simp [choose, mul_succ, Nat.add_comm] | n + 1, k + 1 => by rw [choose_succ_succ (succ n) (succ k), Nat.add_mul, ← succ_mul_choose_eq n, mul_succ, ← succ_mul_choose_eq n, Nat.add_right_comm, ← Nat.mul_add, ← choose_succ_succ, ← succ_mul] theorem choose_mul_factorial_mul_factorial : βˆ€ {n k}, k ≀ n β†’ choose n k * k ! * (n - k)! = n ! | 0, _, hk => by simp [Nat.eq_zero_of_le_zero hk] | n + 1, 0, _ => by simp | n + 1, succ k, hk => by rcases lt_or_eq_of_le hk with hk₁ | hk₁ Β· have h : choose n k * k.succ ! * (n - k)! = (k + 1) * n ! := by rw [← choose_mul_factorial_mul_factorial (le_of_succ_le_succ hk)] simp [factorial_succ, Nat.mul_comm, Nat.mul_left_comm, Nat.mul_assoc] have h₁ : (n - k)! = (n - k) * (n - k.succ)! := by rw [← succ_sub_succ, succ_sub (le_of_lt_succ hk₁), factorial_succ] have hβ‚‚ : choose n (succ k) * k.succ ! * ((n - k) * (n - k.succ)!) = (n - k) * n ! := by rw [← choose_mul_factorial_mul_factorial (le_of_lt_succ hk₁)] simp [factorial_succ, Nat.mul_comm, Nat.mul_left_comm, Nat.mul_assoc] have h₃ : k * n ! ≀ n * n ! := Nat.mul_le_mul_right _ (le_of_succ_le_succ hk) rw [choose_succ_succ, Nat.add_mul, Nat.add_mul, succ_sub_succ, h, h₁, hβ‚‚, Nat.add_mul, Nat.mul_sub_right_distrib, factorial_succ, ← Nat.add_sub_assoc h₃, Nat.add_assoc, ← Nat.add_mul, Nat.add_sub_cancel_left, Nat.add_comm] Β· rw [hk₁]; simp [hk₁, Nat.mul_comm, choose, Nat.sub_self] theorem choose_mul {n k s : β„•} (hkn : k ≀ n) (hsk : s ≀ k) : n.choose k * k.choose s = n.choose s * (n - s).choose (k - s) := have h : 0 < (n - k)! * (k - s)! * s ! := by apply_rules [factorial_pos, Nat.mul_pos] Nat.mul_right_cancel h <| calc n.choose k * k.choose s * ((n - k)! * (k - s)! * s !) = n.choose k * (k.choose s * s ! * (k - s)!) * (n - k)! := by rw [Nat.mul_assoc, Nat.mul_assoc, Nat.mul_assoc, Nat.mul_assoc _ s !, Nat.mul_assoc, Nat.mul_comm (n - k)!, Nat.mul_comm s !] _ = n ! := by rw [choose_mul_factorial_mul_factorial hsk, choose_mul_factorial_mul_factorial hkn] _ = n.choose s * s ! * ((n - s).choose (k - s) * (k - s)! * (n - s - (k - s))!) := by rw [choose_mul_factorial_mul_factorial (Nat.sub_le_sub_right hkn _), choose_mul_factorial_mul_factorial (hsk.trans hkn)] _ = n.choose s * (n - s).choose (k - s) * ((n - k)! * (k - s)! * s !) := by rw [Nat.sub_sub_sub_cancel_right hsk, Nat.mul_assoc, Nat.mul_left_comm s !, Nat.mul_assoc, Nat.mul_comm (k - s)!, Nat.mul_comm s !, Nat.mul_right_comm, ← Nat.mul_assoc] theorem choose_eq_factorial_div_factorial {n k : β„•} (hk : k ≀ n) : choose n k = n ! / (k ! * (n - k)!) := by rw [← choose_mul_factorial_mul_factorial hk, Nat.mul_assoc] exact (mul_div_left _ (Nat.mul_pos (factorial_pos _) (factorial_pos _))).symm theorem add_choose (i j : β„•) : (i + j).choose j = (i + j)! / (i ! * j !) := by rw [choose_eq_factorial_div_factorial (Nat.le_add_left j i), Nat.add_sub_cancel_right, Nat.mul_comm] theorem add_choose_mul_factorial_mul_factorial (i j : β„•) : (i + j).choose j * i ! * j ! = (i + j)! := by rw [← choose_mul_factorial_mul_factorial (Nat.le_add_left _ _), Nat.add_sub_cancel_right, Nat.mul_right_comm] theorem factorial_mul_factorial_dvd_factorial {n k : β„•} (hk : k ≀ n) : k ! * (n - k)! ∣ n ! := by rw [← choose_mul_factorial_mul_factorial hk, Nat.mul_assoc]; exact Nat.dvd_mul_left _ _ theorem factorial_mul_factorial_dvd_factorial_add (i j : β„•) : i ! * j ! ∣ (i + j)! := by suffices i ! * (i + j - i) ! ∣ (i + j)! by rwa [Nat.add_sub_cancel_left i j] at this exact factorial_mul_factorial_dvd_factorial (Nat.le_add_right _ _) @[simp] theorem choose_symm {n k : β„•} (hk : k ≀ n) : choose n (n - k) = choose n k := by rw [choose_eq_factorial_div_factorial hk, choose_eq_factorial_div_factorial (Nat.sub_le _ _), Nat.sub_sub_self hk, Nat.mul_comm]
theorem choose_symm_of_eq_add {n a b : β„•} (h : n = a + b) : Nat.choose n a = Nat.choose n b := by suffices choose n (n - b) = choose n b by rw [h, Nat.add_sub_cancel_right] at this; rwa [h]
Mathlib/Data/Nat/Choose/Basic.lean
192
194
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.Order.Iterate import Mathlib.Order.SemiconjSup import Mathlib.Topology.Order.MonotoneContinuity import Mathlib.Algebra.CharP.Defs /-! # Translation number of a monotone real map that commutes with `x ↦ x + 1` Let `f : ℝ β†’ ℝ` be a monotone map such that `f (x + 1) = f x + 1` for all `x`. Then the limit $$ \tau(f)=\lim_{n\to\infty}{f^n(x)-x}{n} $$ exists and does not depend on `x`. This number is called the *translation number* of `f`. Different authors use different notation for this number: `Ο„`, `ρ`, `rot`, etc In this file we define a structure `CircleDeg1Lift` for bundled maps with these properties, define translation number of `f : CircleDeg1Lift`, prove some estimates relating `f^n(x)-x` to `Ο„(f)`. In case of a continuous map `f` we also prove that `f` admits a point `x` such that `f^n(x)=x+m` if and only if `Ο„(f)=m/n`. Maps of this type naturally appear as lifts of orientation preserving circle homeomorphisms. More precisely, let `f` be an orientation preserving homeomorphism of the circle $S^1=ℝ/β„€$, and consider a real number `a` such that `⟦a⟧ = f 0`, where `⟦⟧` means the natural projection `ℝ β†’ ℝ/β„€`. Then there exists a unique continuous function `F : ℝ β†’ ℝ` such that `F 0 = a` and `⟦F x⟧ = f ⟦x⟧` for all `x` (this fact is not formalized yet). This function is strictly monotone, continuous, and satisfies `F (x + 1) = F x + 1`. The number `βŸ¦Ο„ F⟧ : ℝ / β„€` is called the *rotation number* of `f`. It does not depend on the choice of `a`. ## Main definitions * `CircleDeg1Lift`: a monotone map `f : ℝ β†’ ℝ` such that `f (x + 1) = f x + 1` for all `x`; the type `CircleDeg1Lift` is equipped with `Lattice` and `Monoid` structures; the multiplication is given by composition: `(f * g) x = f (g x)`. * `CircleDeg1Lift.translationNumber`: translation number of `f : CircleDeg1Lift`. ## Main statements We prove the following properties of `CircleDeg1Lift.translationNumber`. * `CircleDeg1Lift.translationNumber_eq_of_dist_bounded`: if the distance between `(f^n) 0` and `(g^n) 0` is bounded from above uniformly in `n : β„•`, then `f` and `g` have equal translation numbers. * `CircleDeg1Lift.translationNumber_eq_of_semiconjBy`: if two `CircleDeg1Lift` maps `f`, `g` are semiconjugate by a `CircleDeg1Lift` map, then `Ο„ f = Ο„ g`. * `CircleDeg1Lift.translationNumber_units_inv`: if `f` is an invertible `CircleDeg1Lift` map (equivalently, `f` is a lift of an orientation-preserving circle homeomorphism), then the translation number of `f⁻¹` is the negative of the translation number of `f`. * `CircleDeg1Lift.translationNumber_mul_of_commute`: if `f` and `g` commute, then `Ο„ (f * g) = Ο„ f + Ο„ g`. * `CircleDeg1Lift.translationNumber_eq_rat_iff`: the translation number of `f` is equal to a rational number `m / n` if and only if `(f^n) x = x + m` for some `x`. * `CircleDeg1Lift.semiconj_of_bijective_of_translationNumber_eq`: if `f` and `g` are two bijective `CircleDeg1Lift` maps and their translation numbers are equal, then these maps are semiconjugate to each other. * `CircleDeg1Lift.semiconj_of_group_action_of_forall_translationNumber_eq`: let `f₁` and `fβ‚‚` be two actions of a group `G` on the circle by degree 1 maps (formally, `f₁` and `fβ‚‚` are two homomorphisms from `G β†’* CircleDeg1Lift`). If the translation numbers of `f₁ g` and `fβ‚‚ g` are equal to each other for all `g : G`, then these two actions are semiconjugate by some `F : CircleDeg1Lift`. This is a version of Proposition 5.4 from [Γ‰tienne Ghys, Groupes d'homeomorphismes du cercle et cohomologie bornee][ghys87:groupes]. ## Notation We use a local notation `Ο„` for the translation number of `f : CircleDeg1Lift`. ## Implementation notes We define the translation number of `f : CircleDeg1Lift` to be the limit of the sequence `(f ^ (2 ^ n)) 0 / (2 ^ n)`, then prove that `((f ^ n) x - x) / n` tends to this number for any `x`. This way it is much easier to prove that the limit exists and basic properties of the limit. We define translation number for a wider class of maps `f : ℝ β†’ ℝ` instead of lifts of orientation preserving circle homeomorphisms for two reasons: * non-strictly monotone circle self-maps with discontinuities naturally appear as PoincarΓ© maps for some flows on the two-torus (e.g., one can take a constant flow and glue in a few Cherry cells); * definition and some basic properties still work for this class. ## References * [Γ‰tienne Ghys, Groupes d'homeomorphismes du cercle et cohomologie bornee][ghys87:groupes] ## TODO Here are some short-term goals. * Introduce a structure or a typeclass for lifts of circle homeomorphisms. We use `Units CircleDeg1Lift` for now, but it's better to have a dedicated type (or a typeclass?). * Prove that the `SemiconjBy` relation on circle homeomorphisms is an equivalence relation. * Introduce `ConditionallyCompleteLattice` structure, use it in the proof of `CircleDeg1Lift.semiconj_of_group_action_of_forall_translationNumber_eq`. * Prove that the orbits of the irrational rotation are dense in the circle. Deduce that a homeomorphism with an irrational rotation is semiconjugate to the corresponding irrational translation by a continuous `CircleDeg1Lift`. ## Tags circle homeomorphism, rotation number -/ open Filter Set Int Topology open Function hiding Commute /-! ### Definition and monoid structure -/ /-- A lift of a monotone degree one map `SΒΉ β†’ SΒΉ`. -/ structure CircleDeg1Lift : Type extends ℝ β†’o ℝ where map_add_one' : βˆ€ x, toFun (x + 1) = toFun x + 1 namespace CircleDeg1Lift instance : FunLike CircleDeg1Lift ℝ ℝ where coe f := f.toFun coe_injective' | ⟨⟨_, _⟩, _⟩, ⟨⟨_, _⟩, _⟩, rfl => rfl instance : OrderHomClass CircleDeg1Lift ℝ ℝ where map_rel f _ _ h := f.monotone' h @[simp] theorem coe_mk (f h) : ⇑(mk f h) = f := rfl variable (f g : CircleDeg1Lift) @[simp] theorem coe_toOrderHom : ⇑f.toOrderHom = f := rfl protected theorem monotone : Monotone f := f.monotone' @[mono] theorem mono {x y} (h : x ≀ y) : f x ≀ f y := f.monotone h theorem strictMono_iff_injective : StrictMono f ↔ Injective f := f.monotone.strictMono_iff_injective @[simp] theorem map_add_one : βˆ€ x, f (x + 1) = f x + 1 := f.map_add_one' @[simp] theorem map_one_add (x : ℝ) : f (1 + x) = 1 + f x := by rw [add_comm, map_add_one, add_comm 1] @[ext] theorem ext ⦃f g : CircleDeg1Lift⦄ (h : βˆ€ x, f x = g x) : f = g := DFunLike.ext f g h instance : Monoid CircleDeg1Lift where mul f g := { toOrderHom := f.1.comp g.1 map_add_one' := fun x => by simp [map_add_one] } one := ⟨.id, fun _ => rfl⟩ mul_one _ := rfl one_mul _ := rfl mul_assoc _ _ _ := DFunLike.coe_injective rfl instance : Inhabited CircleDeg1Lift := ⟨1⟩ @[simp] theorem coe_mul : ⇑(f * g) = f ∘ g := rfl theorem mul_apply (x) : (f * g) x = f (g x) := rfl @[simp] theorem coe_one : ⇑(1 : CircleDeg1Lift) = id := rfl instance unitsHasCoeToFun : CoeFun CircleDeg1LiftΛ£ fun _ => ℝ β†’ ℝ := ⟨fun f => ⇑(f : CircleDeg1Lift)⟩ @[simp] theorem units_inv_apply_apply (f : CircleDeg1LiftΛ£) (x : ℝ) : (f⁻¹ : CircleDeg1LiftΛ£) (f x) = x := by simp only [← mul_apply, f.inv_mul, coe_one, id] @[simp] theorem units_apply_inv_apply (f : CircleDeg1LiftΛ£) (x : ℝ) : f ((f⁻¹ : CircleDeg1LiftΛ£) x) = x := by simp only [← mul_apply, f.mul_inv, coe_one, id] /-- If a lift of a circle map is bijective, then it is an order automorphism of the line. -/ def toOrderIso : CircleDeg1LiftΛ£ β†’* ℝ ≃o ℝ where toFun f := { toFun := f invFun := ⇑f⁻¹ left_inv := units_inv_apply_apply f right_inv := units_apply_inv_apply f map_rel_iff' := ⟨fun h => by simpa using mono (↑f⁻¹) h, mono f⟩ } map_one' := rfl map_mul' _ _ := rfl @[simp] theorem coe_toOrderIso (f : CircleDeg1LiftΛ£) : ⇑(toOrderIso f) = f := rfl @[simp] theorem coe_toOrderIso_symm (f : CircleDeg1LiftΛ£) : ⇑(toOrderIso f).symm = (f⁻¹ : CircleDeg1LiftΛ£) := rfl @[simp] theorem coe_toOrderIso_inv (f : CircleDeg1LiftΛ£) : ⇑(toOrderIso f)⁻¹ = (f⁻¹ : CircleDeg1LiftΛ£) := rfl theorem isUnit_iff_bijective {f : CircleDeg1Lift} : IsUnit f ↔ Bijective f := ⟨fun ⟨u, h⟩ => h β–Έ (toOrderIso u).bijective, fun h => Units.isUnit { val := f inv := { toFun := (Equiv.ofBijective f h).symm monotone' := fun x y hxy => (f.strictMono_iff_injective.2 h.1).le_iff_le.1 (by simp only [Equiv.ofBijective_apply_symm_apply f h, hxy]) map_add_one' := fun x => h.1 <| by simp only [Equiv.ofBijective_apply_symm_apply f, f.map_add_one] } val_inv := ext <| Equiv.ofBijective_apply_symm_apply f h inv_val := ext <| Equiv.ofBijective_symm_apply_apply f h }⟩ theorem coe_pow : βˆ€ n : β„•, ⇑(f ^ n) = f^[n] | 0 => rfl | n + 1 => by ext x simp [coe_pow n, pow_succ] theorem semiconjBy_iff_semiconj {f g₁ gβ‚‚ : CircleDeg1Lift} : SemiconjBy f g₁ gβ‚‚ ↔ Semiconj f g₁ gβ‚‚ := CircleDeg1Lift.ext_iff theorem commute_iff_commute {f g : CircleDeg1Lift} : Commute f g ↔ Function.Commute f g := CircleDeg1Lift.ext_iff /-! ### Translate by a constant -/ /-- The map `y ↦ x + y` as a `CircleDeg1Lift`. More precisely, we define a homomorphism from `Multiplicative ℝ` to `CircleDeg1LiftΛ£`, so the translation by `x` is `translation (Multiplicative.ofAdd x)`. -/ def translate : Multiplicative ℝ β†’* CircleDeg1LiftΛ£ := MonoidHom.toHomUnits <| { toFun := fun x => ⟨⟨fun y => x.toAdd + y, fun _ _ h => add_le_add_left h _⟩, fun _ => (add_assoc _ _ _).symm⟩ map_one' := ext <| zero_add map_mul' := fun _ _ => ext <| add_assoc _ _ } @[simp] theorem translate_apply (x y : ℝ) : translate (Multiplicative.ofAdd x) y = x + y := rfl @[simp] theorem translate_inv_apply (x y : ℝ) : (translate <| Multiplicative.ofAdd x)⁻¹ y = -x + y := rfl @[simp] theorem translate_zpow (x : ℝ) (n : β„€) : translate (Multiplicative.ofAdd x) ^ n = translate (Multiplicative.ofAdd <| ↑n * x) := by simp only [← zsmul_eq_mul, ofAdd_zsmul, MonoidHom.map_zpow] @[simp] theorem translate_pow (x : ℝ) (n : β„•) : translate (Multiplicative.ofAdd x) ^ n = translate (Multiplicative.ofAdd <| ↑n * x) := translate_zpow x n @[simp] theorem translate_iterate (x : ℝ) (n : β„•) : (translate (Multiplicative.ofAdd x))^[n] = translate (Multiplicative.ofAdd <| ↑n * x) := by rw [← coe_pow, ← Units.val_pow_eq_pow_val, translate_pow] /-! ### Commutativity with integer translations In this section we prove that `f` commutes with translations by an integer number. First we formulate these statements (for a natural or an integer number, addition on the left or on the right, addition or subtraction) using `Function.Commute`, then reformulate as `simp` lemmas `map_int_add` etc. -/ theorem commute_nat_add (n : β„•) : Function.Commute f (n + Β·) := by simpa only [nsmul_one, add_left_iterate] using Function.Commute.iterate_right f.map_one_add n theorem commute_add_nat (n : β„•) : Function.Commute f (Β· + n) := by simp only [add_comm _ (n : ℝ), f.commute_nat_add n] theorem commute_sub_nat (n : β„•) : Function.Commute f (Β· - n) := by simpa only [sub_eq_add_neg] using (f.commute_add_nat n).inverses_right (Equiv.addRight _).right_inv (Equiv.addRight _).left_inv theorem commute_add_int : βˆ€ n : β„€, Function.Commute f (Β· + n) | (n : β„•) => f.commute_add_nat n | -[n+1] => by simpa [sub_eq_add_neg] using f.commute_sub_nat (n + 1) theorem commute_int_add (n : β„€) : Function.Commute f (n + Β·) := by simpa only [add_comm _ (n : ℝ)] using f.commute_add_int n theorem commute_sub_int (n : β„€) : Function.Commute f (Β· - n) := by simpa only [sub_eq_add_neg] using (f.commute_add_int n).inverses_right (Equiv.addRight _).right_inv (Equiv.addRight _).left_inv @[simp] theorem map_int_add (m : β„€) (x : ℝ) : f (m + x) = m + f x := f.commute_int_add m x @[simp] theorem map_add_int (x : ℝ) (m : β„€) : f (x + m) = f x + m := f.commute_add_int m x @[simp] theorem map_sub_int (x : ℝ) (n : β„€) : f (x - n) = f x - n := f.commute_sub_int n x @[simp] theorem map_add_nat (x : ℝ) (n : β„•) : f (x + n) = f x + n := f.map_add_int x n @[simp] theorem map_nat_add (n : β„•) (x : ℝ) : f (n + x) = n + f x := f.map_int_add n x @[simp] theorem map_sub_nat (x : ℝ) (n : β„•) : f (x - n) = f x - n := f.map_sub_int x n theorem map_int_of_map_zero (n : β„€) : f n = f 0 + n := by rw [← f.map_add_int, zero_add] @[simp] theorem map_fract_sub_fract_eq (x : ℝ) : f (fract x) - fract x = f x - x := by rw [Int.fract, f.map_sub_int, sub_sub_sub_cancel_right] /-! ### Pointwise order on circle maps -/ /-- Monotone circle maps form a lattice with respect to the pointwise order -/ noncomputable instance : Lattice CircleDeg1Lift where
sup f g := { toFun := fun x => max (f x) (g x)
Mathlib/Dynamics/Circle/RotationNumber/TranslationNumber.lean
351
352
/- Copyright (c) 2023 JoΓ«l Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: JoΓ«l Riou -/ import Mathlib.Algebra.Homology.ShortComplex.LeftHomology import Mathlib.CategoryTheory.Limits.Opposites /-! # Right Homology of short complexes In this file, we define the dual notions to those defined in `Algebra.Homology.ShortComplex.LeftHomology`. In particular, if `S : ShortComplex C` is a short complex consisting of two composable maps `f : X₁ ⟢ Xβ‚‚` and `g : Xβ‚‚ ⟢ X₃` such that `f ≫ g = 0`, we define `h : S.RightHomologyData` to be the datum of morphisms `p : Xβ‚‚ ⟢ Q` and `ΞΉ : H ⟢ Q` such that `Q` identifies to the cokernel of `f` and `H` to the kernel of the induced map `g' : Q ⟢ X₃`. When such a `S.RightHomologyData` exists, we shall say that `[S.HasRightHomology]` and we define `S.rightHomology` to be the `H` field of a chosen right homology data. Similarly, we define `S.opcycles` to be the `Q` field. In `Homology.lean`, when `S` has two compatible left and right homology data (i.e. they give the same `H` up to a canonical isomorphism), we shall define `[S.HasHomology]` and `S.homology`. -/ namespace CategoryTheory open Category Limits namespace ShortComplex variable {C : Type*} [Category C] [HasZeroMorphisms C] (S : ShortComplex C) {S₁ Sβ‚‚ S₃ : ShortComplex C} /-- A right homology data for a short complex `S` consists of morphisms `p : S.Xβ‚‚ ⟢ Q` and `ΞΉ : H ⟢ Q` such that `p` identifies `Q` to the kernel of `f : S.X₁ ⟢ S.Xβ‚‚`, and that `ΞΉ` identifies `H` to the kernel of the induced map `g' : Q ⟢ S.X₃` -/ structure RightHomologyData where /-- a choice of cokernel of `S.f : S.X₁ ⟢ S.Xβ‚‚` -/ Q : C /-- a choice of kernel of the induced morphism `S.g' : S.Q ⟢ X₃` -/ H : C /-- the projection from `S.Xβ‚‚` -/ p : S.Xβ‚‚ ⟢ Q /-- the inclusion of the (right) homology in the chosen cokernel of `S.f` -/ ΞΉ : H ⟢ Q /-- the cokernel condition for `p` -/ wp : S.f ≫ p = 0 /-- `p : S.Xβ‚‚ ⟢ Q` is a cokernel of `S.f : S.X₁ ⟢ S.Xβ‚‚` -/ hp : IsColimit (CokernelCofork.ofΟ€ p wp) /-- the kernel condition for `ΞΉ` -/ wΞΉ : ΞΉ ≫ hp.desc (CokernelCofork.ofΟ€ _ S.zero) = 0 /-- `ΞΉ : H ⟢ Q` is a kernel of `S.g' : Q ⟢ S.X₃` -/ hΞΉ : IsLimit (KernelFork.ofΞΉ ΞΉ wΞΉ) initialize_simps_projections RightHomologyData (-hp, -hΞΉ) namespace RightHomologyData /-- The chosen cokernels and kernels of the limits API give a `RightHomologyData` -/ @[simps] noncomputable def ofHasCokernelOfHasKernel [HasCokernel S.f] [HasKernel (cokernel.desc S.f S.g S.zero)] : S.RightHomologyData := { Q := cokernel S.f, H := kernel (cokernel.desc S.f S.g S.zero), p := cokernel.Ο€ _, ΞΉ := kernel.ΞΉ _, wp := cokernel.condition _, hp := cokernelIsCokernel _, wΞΉ := kernel.condition _, hΞΉ := kernelIsKernel _, } attribute [reassoc (attr := simp)] wp wΞΉ variable {S} variable (h : S.RightHomologyData) {A : C} instance : Epi h.p := ⟨fun _ _ => Cofork.IsColimit.hom_ext h.hp⟩ instance : Mono h.ΞΉ := ⟨fun _ _ => Fork.IsLimit.hom_ext h.hι⟩ /-- Any morphism `k : S.Xβ‚‚ ⟢ A` such that `S.f ≫ k = 0` descends to a morphism `Q ⟢ A` -/ def descQ (k : S.Xβ‚‚ ⟢ A) (hk : S.f ≫ k = 0) : h.Q ⟢ A := h.hp.desc (CokernelCofork.ofΟ€ k hk) @[reassoc (attr := simp)] lemma p_descQ (k : S.Xβ‚‚ ⟢ A) (hk : S.f ≫ k = 0) : h.p ≫ h.descQ k hk = k := h.hp.fac _ WalkingParallelPair.one /-- The morphism from the (right) homology attached to a morphism `k : S.Xβ‚‚ ⟢ A` such that `S.f ≫ k = 0`. -/ @[simp] def descH (k : S.Xβ‚‚ ⟢ A) (hk : S.f ≫ k = 0) : h.H ⟢ A := h.ΞΉ ≫ h.descQ k hk /-- The morphism `h.Q ⟢ S.X₃` induced by `S.g : S.Xβ‚‚ ⟢ S.X₃` and the fact that `h.Q` is a cokernel of `S.f : S.X₁ ⟢ S.Xβ‚‚`. -/ def g' : h.Q ⟢ S.X₃ := h.descQ S.g S.zero @[reassoc (attr := simp)] lemma p_g' : h.p ≫ h.g' = S.g := p_descQ _ _ _ @[reassoc (attr := simp)] lemma ΞΉ_g' : h.ΞΉ ≫ h.g' = 0 := h.wΞΉ @[reassoc] lemma ΞΉ_descQ_eq_zero_of_boundary (k : S.Xβ‚‚ ⟢ A) (x : S.X₃ ⟢ A) (hx : k = S.g ≫ x) : h.ΞΉ ≫ h.descQ k (by rw [hx, S.zero_assoc, zero_comp]) = 0 := by rw [show 0 = h.ΞΉ ≫ h.g' ≫ x by simp] congr 1 simp only [← cancel_epi h.p, hx, p_descQ, p_g'_assoc] /-- For `h : S.RightHomologyData`, this is a restatement of `h.hΞΉ`, saying that `ΞΉ : h.H ⟢ h.Q` is a kernel of `h.g' : h.Q ⟢ S.X₃`. -/ def hΞΉ' : IsLimit (KernelFork.ofΞΉ h.ΞΉ h.ΞΉ_g') := h.hΞΉ /-- The morphism `A ⟢ H` induced by a morphism `k : A ⟢ Q` such that `k ≫ g' = 0` -/ def liftH (k : A ⟢ h.Q) (hk : k ≫ h.g' = 0) : A ⟢ h.H := h.hΞΉ.lift (KernelFork.ofΞΉ k hk) @[reassoc (attr := simp)] lemma liftH_ΞΉ (k : A ⟢ h.Q) (hk : k ≫ h.g' = 0) : h.liftH k hk ≫ h.ΞΉ = k := h.hΞΉ.fac (KernelFork.ofΞΉ k hk) WalkingParallelPair.zero lemma isIso_p (hf : S.f = 0) : IsIso h.p := ⟨h.descQ (πŸ™ S.Xβ‚‚) (by rw [hf, comp_id]), p_descQ _ _ _, by simp only [← cancel_epi h.p, p_descQ_assoc, id_comp, comp_id]⟩ lemma isIso_ΞΉ (hg : S.g = 0) : IsIso h.ΞΉ := by have βŸ¨Ο†, hΟ†βŸ© := KernelFork.IsLimit.lift' h.hΞΉ' (πŸ™ _) (by rw [← cancel_epi h.p, id_comp, p_g', comp_zero, hg]) dsimp at hΟ† exact βŸ¨Ο†, by rw [← cancel_mono h.ΞΉ, assoc, hΟ†, comp_id, id_comp], hΟ†βŸ© variable (S) /-- When the first map `S.f` is zero, this is the right homology data on `S` given by any limit kernel fork of `S.g` -/ @[simps] def ofIsLimitKernelFork (hf : S.f = 0) (c : KernelFork S.g) (hc : IsLimit c) : S.RightHomologyData where Q := S.Xβ‚‚ H := c.pt p := πŸ™ _ ΞΉ := c.ΞΉ wp := by rw [comp_id, hf] hp := CokernelCofork.IsColimit.ofId _ hf wΞΉ := KernelFork.condition _ hΞΉ := IsLimit.ofIsoLimit hc (Fork.ext (Iso.refl _) (by simp)) @[simp] lemma ofIsLimitKernelFork_g' (hf : S.f = 0) (c : KernelFork S.g) (hc : IsLimit c) : (ofIsLimitKernelFork S hf c hc).g' = S.g := by rw [← cancel_epi (ofIsLimitKernelFork S hf c hc).p, p_g', ofIsLimitKernelFork_p, id_comp] /-- When the first map `S.f` is zero, this is the right homology data on `S` given by the chosen `kernel S.g` -/ @[simps!] noncomputable def ofHasKernel [HasKernel S.g] (hf : S.f = 0) : S.RightHomologyData := ofIsLimitKernelFork S hf _ (kernelIsKernel _) /-- When the second map `S.g` is zero, this is the right homology data on `S` given by any colimit cokernel cofork of `S.g` -/ @[simps] def ofIsColimitCokernelCofork (hg : S.g = 0) (c : CokernelCofork S.f) (hc : IsColimit c) : S.RightHomologyData where Q := c.pt H := c.pt p := c.Ο€ ΞΉ := πŸ™ _ wp := CokernelCofork.condition _ hp := IsColimit.ofIsoColimit hc (Cofork.ext (Iso.refl _) (by simp)) wΞΉ := Cofork.IsColimit.hom_ext hc (by simp [hg]) hΞΉ := KernelFork.IsLimit.ofId _ (Cofork.IsColimit.hom_ext hc (by simp [hg])) @[simp] lemma ofIsColimitCokernelCofork_g' (hg : S.g = 0) (c : CokernelCofork S.f) (hc : IsColimit c) : (ofIsColimitCokernelCofork S hg c hc).g' = 0 := by rw [← cancel_epi (ofIsColimitCokernelCofork S hg c hc).p, p_g', hg, comp_zero] /-- When the second map `S.g` is zero, this is the right homology data on `S` given by the chosen `cokernel S.f` -/ @[simp] noncomputable def ofHasCokernel [HasCokernel S.f] (hg : S.g = 0) : S.RightHomologyData := ofIsColimitCokernelCofork S hg _ (cokernelIsCokernel _) /-- When both `S.f` and `S.g` are zero, the middle object `S.Xβ‚‚` gives a right homology data on S -/ @[simps] def ofZeros (hf : S.f = 0) (hg : S.g = 0) : S.RightHomologyData where Q := S.Xβ‚‚ H := S.Xβ‚‚ p := πŸ™ _ ΞΉ := πŸ™ _ wp := by rw [comp_id, hf] hp := CokernelCofork.IsColimit.ofId _ hf wΞΉ := by change πŸ™ _ ≫ S.g = 0 simp only [hg, comp_zero] hΞΉ := KernelFork.IsLimit.ofId _ hg @[simp] lemma ofZeros_g' (hf : S.f = 0) (hg : S.g = 0) : (ofZeros S hf hg).g' = 0 := by rw [← cancel_epi ((ofZeros S hf hg).p), comp_zero, p_g', hg] end RightHomologyData /-- A short complex `S` has right homology when there exists a `S.RightHomologyData` -/ class HasRightHomology : Prop where condition : Nonempty S.RightHomologyData /-- A chosen `S.RightHomologyData` for a short complex `S` that has right homology -/ noncomputable def rightHomologyData [HasRightHomology S] : S.RightHomologyData := HasRightHomology.condition.some variable {S} namespace HasRightHomology lemma mk' (h : S.RightHomologyData) : HasRightHomology S := ⟨Nonempty.intro h⟩ instance of_hasCokernel_of_hasKernel [HasCokernel S.f] [HasKernel (cokernel.desc S.f S.g S.zero)] : S.HasRightHomology := HasRightHomology.mk' (RightHomologyData.ofHasCokernelOfHasKernel S) instance of_hasKernel {Y Z : C} (g : Y ⟢ Z) (X : C) [HasKernel g] : (ShortComplex.mk (0 : X ⟢ Y) g zero_comp).HasRightHomology := HasRightHomology.mk' (RightHomologyData.ofHasKernel _ rfl) instance of_hasCokernel {X Y : C} (f : X ⟢ Y) (Z : C) [HasCokernel f] : (ShortComplex.mk f (0 : Y ⟢ Z) comp_zero).HasRightHomology := HasRightHomology.mk' (RightHomologyData.ofHasCokernel _ rfl) instance of_zeros (X Y Z : C) : (ShortComplex.mk (0 : X ⟢ Y) (0 : Y ⟢ Z) zero_comp).HasRightHomology := HasRightHomology.mk' (RightHomologyData.ofZeros _ rfl rfl) end HasRightHomology namespace RightHomologyData /-- A right homology data for a short complex `S` induces a left homology data for `S.op`. -/ @[simps] def op (h : S.RightHomologyData) : S.op.LeftHomologyData where K := Opposite.op h.Q H := Opposite.op h.H i := h.p.op Ο€ := h.ΞΉ.op wi := Quiver.Hom.unop_inj h.wp hi := CokernelCofork.IsColimit.ofΟ€Op _ _ h.hp wΟ€ := Quiver.Hom.unop_inj h.wΞΉ hΟ€ := KernelFork.IsLimit.ofΞΉOp _ _ h.hΞΉ @[simp] lemma op_f' (h : S.RightHomologyData) : h.op.f' = h.g'.op := rfl /-- A right homology data for a short complex `S` in the opposite category induces a left homology data for `S.unop`. -/ @[simps] def unop {S : ShortComplex Cα΅’α΅–} (h : S.RightHomologyData) : S.unop.LeftHomologyData where K := Opposite.unop h.Q H := Opposite.unop h.H i := h.p.unop Ο€ := h.ΞΉ.unop wi := Quiver.Hom.op_inj h.wp hi := CokernelCofork.IsColimit.ofΟ€Unop _ _ h.hp wΟ€ := Quiver.Hom.op_inj h.wΞΉ hΟ€ := KernelFork.IsLimit.ofΞΉUnop _ _ h.hΞΉ @[simp] lemma unop_f' {S : ShortComplex Cα΅’α΅–} (h : S.RightHomologyData) : h.unop.f' = h.g'.unop := rfl end RightHomologyData namespace LeftHomologyData /-- A left homology data for a short complex `S` induces a right homology data for `S.op`. -/ @[simps] def op (h : S.LeftHomologyData) : S.op.RightHomologyData where Q := Opposite.op h.K H := Opposite.op h.H p := h.i.op ΞΉ := h.Ο€.op wp := Quiver.Hom.unop_inj h.wi hp := KernelFork.IsLimit.ofΞΉOp _ _ h.hi wΞΉ := Quiver.Hom.unop_inj h.wΟ€ hΞΉ := CokernelCofork.IsColimit.ofΟ€Op _ _ h.hΟ€ @[simp] lemma op_g' (h : S.LeftHomologyData) : h.op.g' = h.f'.op := rfl /-- A left homology data for a short complex `S` in the opposite category induces a right homology data for `S.unop`. -/ @[simps] def unop {S : ShortComplex Cα΅’α΅–} (h : S.LeftHomologyData) : S.unop.RightHomologyData where Q := Opposite.unop h.K H := Opposite.unop h.H p := h.i.unop ΞΉ := h.Ο€.unop wp := Quiver.Hom.op_inj h.wi hp := KernelFork.IsLimit.ofΞΉUnop _ _ h.hi wΞΉ := Quiver.Hom.op_inj h.wΟ€ hΞΉ := CokernelCofork.IsColimit.ofΟ€Unop _ _ h.hΟ€ @[simp] lemma unop_g' {S : ShortComplex Cα΅’α΅–} (h : S.LeftHomologyData) : h.unop.g' = h.f'.unop := rfl end LeftHomologyData instance [S.HasLeftHomology] : HasRightHomology S.op := HasRightHomology.mk' S.leftHomologyData.op instance [S.HasRightHomology] : HasLeftHomology S.op := HasLeftHomology.mk' S.rightHomologyData.op lemma hasLeftHomology_iff_op (S : ShortComplex C) : S.HasLeftHomology ↔ S.op.HasRightHomology := ⟨fun _ => inferInstance, fun _ => HasLeftHomology.mk' S.op.rightHomologyData.unop⟩ lemma hasRightHomology_iff_op (S : ShortComplex C) : S.HasRightHomology ↔ S.op.HasLeftHomology := ⟨fun _ => inferInstance, fun _ => HasRightHomology.mk' S.op.leftHomologyData.unop⟩ lemma hasLeftHomology_iff_unop (S : ShortComplex Cα΅’α΅–) : S.HasLeftHomology ↔ S.unop.HasRightHomology := S.unop.hasRightHomology_iff_op.symm lemma hasRightHomology_iff_unop (S : ShortComplex Cα΅’α΅–) : S.HasRightHomology ↔ S.unop.HasLeftHomology := S.unop.hasLeftHomology_iff_op.symm section variable (Ο† : S₁ ⟢ Sβ‚‚) (h₁ : S₁.RightHomologyData) (hβ‚‚ : Sβ‚‚.RightHomologyData) /-- Given right homology data `h₁` and `hβ‚‚` for two short complexes `S₁` and `Sβ‚‚`, a `RightHomologyMapData` for a morphism `Ο† : S₁ ⟢ Sβ‚‚` consists of a description of the induced morphisms on the `Q` (opcycles) and `H` (right homology) fields of `h₁` and `hβ‚‚`. -/ structure RightHomologyMapData where /-- the induced map on opcycles -/ Ο†Q : h₁.Q ⟢ hβ‚‚.Q /-- the induced map on right homology -/ Ο†H : h₁.H ⟢ hβ‚‚.H /-- commutation with `p` -/ commp : h₁.p ≫ Ο†Q = Ο†.Ο„β‚‚ ≫ hβ‚‚.p := by aesop_cat /-- commutation with `g'` -/ commg' : Ο†Q ≫ hβ‚‚.g' = h₁.g' ≫ Ο†.τ₃ := by aesop_cat /-- commutation with `ΞΉ` -/ commΞΉ : Ο†H ≫ hβ‚‚.ΞΉ = h₁.ΞΉ ≫ Ο†Q := by aesop_cat namespace RightHomologyMapData attribute [reassoc (attr := simp)] commp commg' commΞΉ /-- The right homology map data associated to the zero morphism between two short complexes. -/ @[simps] def zero (h₁ : S₁.RightHomologyData) (hβ‚‚ : Sβ‚‚.RightHomologyData) : RightHomologyMapData 0 h₁ hβ‚‚ where Ο†Q := 0 Ο†H := 0 /-- The right homology map data associated to the identity morphism of a short complex. -/ @[simps] def id (h : S.RightHomologyData) : RightHomologyMapData (πŸ™ S) h h where Ο†Q := πŸ™ _ Ο†H := πŸ™ _ /-- The composition of right homology map data. -/ @[simps] def comp {Ο† : S₁ ⟢ Sβ‚‚} {Ο†' : Sβ‚‚ ⟢ S₃} {h₁ : S₁.RightHomologyData} {hβ‚‚ : Sβ‚‚.RightHomologyData} {h₃ : S₃.RightHomologyData} (ψ : RightHomologyMapData Ο† h₁ hβ‚‚) (ψ' : RightHomologyMapData Ο†' hβ‚‚ h₃) : RightHomologyMapData (Ο† ≫ Ο†') h₁ h₃ where Ο†Q := ψ.Ο†Q ≫ ψ'.Ο†Q Ο†H := ψ.Ο†H ≫ ψ'.Ο†H instance : Subsingleton (RightHomologyMapData Ο† h₁ hβ‚‚) := ⟨fun Οˆβ‚ Οˆβ‚‚ => by have hQ : Οˆβ‚.Ο†Q = Οˆβ‚‚.Ο†Q := by rw [← cancel_epi h₁.p, commp, commp] have hH : Οˆβ‚.Ο†H = Οˆβ‚‚.Ο†H := by rw [← cancel_mono hβ‚‚.ΞΉ, commΞΉ, commΞΉ, hQ] cases Οˆβ‚ cases Οˆβ‚‚ congr⟩ instance : Inhabited (RightHomologyMapData Ο† h₁ hβ‚‚) := ⟨by let Ο†Q : h₁.Q ⟢ hβ‚‚.Q := h₁.descQ (Ο†.Ο„β‚‚ ≫ hβ‚‚.p) (by rw [← Ο†.comm₁₂_assoc, hβ‚‚.wp, comp_zero]) have commg' : Ο†Q ≫ hβ‚‚.g' = h₁.g' ≫ Ο†.τ₃ := by rw [← cancel_epi h₁.p, RightHomologyData.p_descQ_assoc, assoc, RightHomologyData.p_g', Ο†.comm₂₃, RightHomologyData.p_g'_assoc] let Ο†H : h₁.H ⟢ hβ‚‚.H := hβ‚‚.liftH (h₁.ΞΉ ≫ Ο†Q) (by rw [assoc, commg', RightHomologyData.ΞΉ_g'_assoc, zero_comp]) exact βŸ¨Ο†Q, Ο†H, by simp [Ο†Q], commg', by simp [Ο†H]⟩⟩ instance : Unique (RightHomologyMapData Ο† h₁ hβ‚‚) := Unique.mk' _ variable {Ο† h₁ hβ‚‚} lemma congr_Ο†H {γ₁ Ξ³β‚‚ : RightHomologyMapData Ο† h₁ hβ‚‚} (eq : γ₁ = Ξ³β‚‚) : γ₁.Ο†H = Ξ³β‚‚.Ο†H := by rw [eq] lemma congr_Ο†Q {γ₁ Ξ³β‚‚ : RightHomologyMapData Ο† h₁ hβ‚‚} (eq : γ₁ = Ξ³β‚‚) : γ₁.Ο†Q = Ξ³β‚‚.Ο†Q := by rw [eq] /-- When `S₁.f`, `S₁.g`, `Sβ‚‚.f` and `Sβ‚‚.g` are all zero, the action on right homology of a morphism `Ο† : S₁ ⟢ Sβ‚‚` is given by the action `Ο†.Ο„β‚‚` on the middle objects. -/ @[simps] def ofZeros (Ο† : S₁ ⟢ Sβ‚‚) (hf₁ : S₁.f = 0) (hg₁ : S₁.g = 0) (hfβ‚‚ : Sβ‚‚.f = 0) (hgβ‚‚ : Sβ‚‚.g = 0) : RightHomologyMapData Ο† (RightHomologyData.ofZeros S₁ hf₁ hg₁) (RightHomologyData.ofZeros Sβ‚‚ hfβ‚‚ hgβ‚‚) where Ο†Q := Ο†.Ο„β‚‚ Ο†H := Ο†.Ο„β‚‚ /-- When `S₁.f` and `Sβ‚‚.f` are zero and we have chosen limit kernel forks `c₁` and `cβ‚‚` for `S₁.g` and `Sβ‚‚.g` respectively, the action on right homology of a morphism `Ο† : S₁ ⟢ Sβ‚‚` of short complexes is given by the unique morphism `f : c₁.pt ⟢ cβ‚‚.pt` such that `c₁.ΞΉ ≫ Ο†.Ο„β‚‚ = f ≫ cβ‚‚.ΞΉ`. -/ @[simps] def ofIsLimitKernelFork (Ο† : S₁ ⟢ Sβ‚‚) (hf₁ : S₁.f = 0) (c₁ : KernelFork S₁.g) (hc₁ : IsLimit c₁) (hfβ‚‚ : Sβ‚‚.f = 0) (cβ‚‚ : KernelFork Sβ‚‚.g) (hcβ‚‚ : IsLimit cβ‚‚) (f : c₁.pt ⟢ cβ‚‚.pt) (comm : c₁.ΞΉ ≫ Ο†.Ο„β‚‚ = f ≫ cβ‚‚.ΞΉ) : RightHomologyMapData Ο† (RightHomologyData.ofIsLimitKernelFork S₁ hf₁ c₁ hc₁) (RightHomologyData.ofIsLimitKernelFork Sβ‚‚ hfβ‚‚ cβ‚‚ hcβ‚‚) where Ο†Q := Ο†.Ο„β‚‚ Ο†H := f commg' := by simp only [RightHomologyData.ofIsLimitKernelFork_g', Ο†.comm₂₃] commΞΉ := comm.symm /-- When `S₁.g` and `Sβ‚‚.g` are zero and we have chosen colimit cokernel coforks `c₁` and `cβ‚‚` for `S₁.f` and `Sβ‚‚.f` respectively, the action on right homology of a morphism `Ο† : S₁ ⟢ Sβ‚‚` of short complexes is given by the unique morphism `f : c₁.pt ⟢ cβ‚‚.pt` such that `Ο†.Ο„β‚‚ ≫ cβ‚‚.Ο€ = c₁.Ο€ ≫ f`. -/ @[simps] def ofIsColimitCokernelCofork (Ο† : S₁ ⟢ Sβ‚‚) (hg₁ : S₁.g = 0) (c₁ : CokernelCofork S₁.f) (hc₁ : IsColimit c₁) (hgβ‚‚ : Sβ‚‚.g = 0) (cβ‚‚ : CokernelCofork Sβ‚‚.f) (hcβ‚‚ : IsColimit cβ‚‚) (f : c₁.pt ⟢ cβ‚‚.pt) (comm : Ο†.Ο„β‚‚ ≫ cβ‚‚.Ο€ = c₁.Ο€ ≫ f) : RightHomologyMapData Ο† (RightHomologyData.ofIsColimitCokernelCofork S₁ hg₁ c₁ hc₁) (RightHomologyData.ofIsColimitCokernelCofork Sβ‚‚ hgβ‚‚ cβ‚‚ hcβ‚‚) where Ο†Q := f Ο†H := f commp := comm.symm variable (S) /-- When both maps `S.f` and `S.g` of a short complex `S` are zero, this is the right homology map data (for the identity of `S`) which relates the right homology data `RightHomologyData.ofIsLimitKernelFork` and `ofZeros` . -/ @[simps] def compatibilityOfZerosOfIsLimitKernelFork (hf : S.f = 0) (hg : S.g = 0) (c : KernelFork S.g) (hc : IsLimit c) : RightHomologyMapData (πŸ™ S) (RightHomologyData.ofIsLimitKernelFork S hf c hc) (RightHomologyData.ofZeros S hf hg) where Ο†Q := πŸ™ _ Ο†H := c.ΞΉ /-- When both maps `S.f` and `S.g` of a short complex `S` are zero, this is the right homology map data (for the identity of `S`) which relates the right homology data `ofZeros` and `ofIsColimitCokernelCofork`. -/ @[simps] def compatibilityOfZerosOfIsColimitCokernelCofork (hf : S.f = 0) (hg : S.g = 0) (c : CokernelCofork S.f) (hc : IsColimit c) : RightHomologyMapData (πŸ™ S) (RightHomologyData.ofZeros S hf hg) (RightHomologyData.ofIsColimitCokernelCofork S hg c hc) where Ο†Q := c.Ο€ Ο†H := c.Ο€ end RightHomologyMapData end section variable (S) variable [S.HasRightHomology] /-- The right homology of a short complex, given by the `H` field of a chosen right homology data. -/ noncomputable def rightHomology : C := S.rightHomologyData.H -- `S.rightHomology` is the simp normal form. @[simp] lemma rightHomologyData_H : S.rightHomologyData.H = S.rightHomology := rfl /-- The "opcycles" of a short complex, given by the `Q` field of a chosen right homology data. This is the dual notion to cycles. -/ noncomputable def opcycles : C := S.rightHomologyData.Q /-- The canonical map `S.rightHomology ⟢ S.opcycles`. -/ noncomputable def rightHomologyΞΉ : S.rightHomology ⟢ S.opcycles := S.rightHomologyData.ΞΉ /-- The projection `S.Xβ‚‚ ⟢ S.opcycles`. -/ noncomputable def pOpcycles : S.Xβ‚‚ ⟢ S.opcycles := S.rightHomologyData.p /-- The canonical map `S.opcycles ⟢ X₃`. -/ noncomputable def fromOpcycles : S.opcycles ⟢ S.X₃ := S.rightHomologyData.g' @[reassoc (attr := simp)] lemma f_pOpcycles : S.f ≫ S.pOpcycles = 0 := S.rightHomologyData.wp @[reassoc (attr := simp)] lemma p_fromOpcycles : S.pOpcycles ≫ S.fromOpcycles = S.g := S.rightHomologyData.p_g' instance : Epi S.pOpcycles := by dsimp only [pOpcycles] infer_instance instance : Mono S.rightHomologyΞΉ := by dsimp only [rightHomologyΞΉ] infer_instance lemma rightHomology_ext_iff {A : C} (f₁ fβ‚‚ : A ⟢ S.rightHomology) : f₁ = fβ‚‚ ↔ f₁ ≫ S.rightHomologyΞΉ = fβ‚‚ ≫ S.rightHomologyΞΉ := by rw [cancel_mono] @[ext] lemma rightHomology_ext {A : C} (f₁ fβ‚‚ : A ⟢ S.rightHomology) (h : f₁ ≫ S.rightHomologyΞΉ = fβ‚‚ ≫ S.rightHomologyΞΉ) : f₁ = fβ‚‚ := by simpa only [rightHomology_ext_iff] lemma opcycles_ext_iff {A : C} (f₁ fβ‚‚ : S.opcycles ⟢ A) : f₁ = fβ‚‚ ↔ S.pOpcycles ≫ f₁ = S.pOpcycles ≫ fβ‚‚ := by rw [cancel_epi] @[ext] lemma opcycles_ext {A : C} (f₁ fβ‚‚ : S.opcycles ⟢ A) (h : S.pOpcycles ≫ f₁ = S.pOpcycles ≫ fβ‚‚) : f₁ = fβ‚‚ := by simpa only [opcycles_ext_iff] lemma isIso_pOpcycles (hf : S.f = 0) : IsIso S.pOpcycles := RightHomologyData.isIso_p _ hf /-- When `S.f = 0`, this is the canonical isomorphism `S.opcycles β‰… S.Xβ‚‚` induced by `S.pOpcycles`. -/ @[simps! inv] noncomputable def opcyclesIsoXβ‚‚ (hf : S.f = 0) : S.opcycles β‰… S.Xβ‚‚ := by have := S.isIso_pOpcycles hf exact (asIso S.pOpcycles).symm @[reassoc (attr := simp)] lemma opcyclesIsoXβ‚‚_inv_hom_id (hf : S.f = 0) : S.pOpcycles ≫ (S.opcyclesIsoXβ‚‚ hf).hom = πŸ™ _ := (S.opcyclesIsoXβ‚‚ hf).inv_hom_id @[reassoc (attr := simp)] lemma opcyclesIsoXβ‚‚_hom_inv_id (hf : S.f = 0) : (S.opcyclesIsoXβ‚‚ hf).hom ≫ S.pOpcycles = πŸ™ _ := (S.opcyclesIsoXβ‚‚ hf).hom_inv_id lemma isIso_rightHomologyΞΉ (hg : S.g = 0) : IsIso S.rightHomologyΞΉ := RightHomologyData.isIso_ΞΉ _ hg /-- When `S.g = 0`, this is the canonical isomorphism `S.opcycles β‰… S.rightHomology` induced by `S.rightHomologyΞΉ`. -/ @[simps! inv] noncomputable def opcyclesIsoRightHomology (hg : S.g = 0) : S.opcycles β‰… S.rightHomology := by have := S.isIso_rightHomologyΞΉ hg exact (asIso S.rightHomologyΞΉ).symm @[reassoc (attr := simp)] lemma opcyclesIsoRightHomology_inv_hom_id (hg : S.g = 0) : S.rightHomologyΞΉ ≫ (S.opcyclesIsoRightHomology hg).hom = πŸ™ _ := (S.opcyclesIsoRightHomology hg).inv_hom_id @[reassoc (attr := simp)] lemma opcyclesIsoRightHomology_hom_inv_id (hg : S.g = 0) : (S.opcyclesIsoRightHomology hg).hom ≫ S.rightHomologyΞΉ = πŸ™ _ := (S.opcyclesIsoRightHomology hg).hom_inv_id end section variable (Ο† : S₁ ⟢ Sβ‚‚) (h₁ : S₁.RightHomologyData) (hβ‚‚ : Sβ‚‚.RightHomologyData) /-- The (unique) right homology map data associated to a morphism of short complexes that are both equipped with right homology data. -/ def rightHomologyMapData : RightHomologyMapData Ο† h₁ hβ‚‚ := default /-- Given a morphism `Ο† : S₁ ⟢ Sβ‚‚` of short complexes and right homology data `h₁` and `hβ‚‚` for `S₁` and `Sβ‚‚` respectively, this is the induced right homology map `h₁.H ⟢ h₁.H`. -/ def rightHomologyMap' : h₁.H ⟢ hβ‚‚.H := (rightHomologyMapData Ο† _ _).Ο†H /-- Given a morphism `Ο† : S₁ ⟢ Sβ‚‚` of short complexes and right homology data `h₁` and `hβ‚‚` for `S₁` and `Sβ‚‚` respectively, this is the induced morphism `h₁.K ⟢ h₁.K` on opcycles. -/ def opcyclesMap' : h₁.Q ⟢ hβ‚‚.Q := (rightHomologyMapData Ο† _ _).Ο†Q @[reassoc (attr := simp)] lemma p_opcyclesMap' : h₁.p ≫ opcyclesMap' Ο† h₁ hβ‚‚ = Ο†.Ο„β‚‚ ≫ hβ‚‚.p := RightHomologyMapData.commp _ @[reassoc (attr := simp)] lemma opcyclesMap'_g' : opcyclesMap' Ο† h₁ hβ‚‚ ≫ hβ‚‚.g' = h₁.g' ≫ Ο†.τ₃ := by simp only [← cancel_epi h₁.p, assoc, Ο†.comm₂₃, p_opcyclesMap'_assoc, RightHomologyData.p_g'_assoc, RightHomologyData.p_g'] @[reassoc (attr := simp)] lemma rightHomologyΞΉ_naturality' : rightHomologyMap' Ο† h₁ hβ‚‚ ≫ hβ‚‚.ΞΉ = h₁.ΞΉ ≫ opcyclesMap' Ο† h₁ hβ‚‚ := RightHomologyMapData.commΞΉ _ end section variable [HasRightHomology S₁] [HasRightHomology Sβ‚‚] (Ο† : S₁ ⟢ Sβ‚‚) /-- The (right) homology map `S₁.rightHomology ⟢ Sβ‚‚.rightHomology` induced by a morphism `S₁ ⟢ Sβ‚‚` of short complexes. -/ noncomputable def rightHomologyMap : S₁.rightHomology ⟢ Sβ‚‚.rightHomology := rightHomologyMap' Ο† _ _ /-- The morphism `S₁.opcycles ⟢ Sβ‚‚.opcycles` induced by a morphism `S₁ ⟢ Sβ‚‚` of short complexes. -/ noncomputable def opcyclesMap : S₁.opcycles ⟢ Sβ‚‚.opcycles := opcyclesMap' Ο† _ _ @[reassoc (attr := simp)] lemma p_opcyclesMap : S₁.pOpcycles ≫ opcyclesMap Ο† = Ο†.Ο„β‚‚ ≫ Sβ‚‚.pOpcycles := p_opcyclesMap' _ _ _ @[reassoc (attr := simp)] lemma fromOpcycles_naturality : opcyclesMap Ο† ≫ Sβ‚‚.fromOpcycles = S₁.fromOpcycles ≫ Ο†.τ₃ := opcyclesMap'_g' _ _ _ @[reassoc (attr := simp)] lemma rightHomologyΞΉ_naturality : rightHomologyMap Ο† ≫ Sβ‚‚.rightHomologyΞΉ = S₁.rightHomologyΞΉ ≫ opcyclesMap Ο† := rightHomologyΞΉ_naturality' _ _ _ end namespace RightHomologyMapData variable {Ο† : S₁ ⟢ Sβ‚‚} {h₁ : S₁.RightHomologyData} {hβ‚‚ : Sβ‚‚.RightHomologyData} (Ξ³ : RightHomologyMapData Ο† h₁ hβ‚‚) lemma rightHomologyMap'_eq : rightHomologyMap' Ο† h₁ hβ‚‚ = Ξ³.Ο†H := RightHomologyMapData.congr_Ο†H (Subsingleton.elim _ _) lemma opcyclesMap'_eq : opcyclesMap' Ο† h₁ hβ‚‚ = Ξ³.Ο†Q := RightHomologyMapData.congr_Ο†Q (Subsingleton.elim _ _) end RightHomologyMapData @[simp] lemma rightHomologyMap'_id (h : S.RightHomologyData) : rightHomologyMap' (πŸ™ S) h h = πŸ™ _ := (RightHomologyMapData.id h).rightHomologyMap'_eq @[simp] lemma opcyclesMap'_id (h : S.RightHomologyData) : opcyclesMap' (πŸ™ S) h h = πŸ™ _ := (RightHomologyMapData.id h).opcyclesMap'_eq variable (S) @[simp] lemma rightHomologyMap_id [HasRightHomology S] : rightHomologyMap (πŸ™ S) = πŸ™ _ := rightHomologyMap'_id _ @[simp] lemma opcyclesMap_id [HasRightHomology S] : opcyclesMap (πŸ™ S) = πŸ™ _ := opcyclesMap'_id _ @[simp] lemma rightHomologyMap'_zero (h₁ : S₁.RightHomologyData) (hβ‚‚ : Sβ‚‚.RightHomologyData) : rightHomologyMap' 0 h₁ hβ‚‚ = 0 := (RightHomologyMapData.zero h₁ hβ‚‚).rightHomologyMap'_eq @[simp] lemma opcyclesMap'_zero (h₁ : S₁.RightHomologyData) (hβ‚‚ : Sβ‚‚.RightHomologyData) : opcyclesMap' 0 h₁ hβ‚‚ = 0 := (RightHomologyMapData.zero h₁ hβ‚‚).opcyclesMap'_eq variable (S₁ Sβ‚‚) @[simp] lemma rightHomologyMap_zero [HasRightHomology S₁] [HasRightHomology Sβ‚‚] : rightHomologyMap (0 : S₁ ⟢ Sβ‚‚) = 0 := rightHomologyMap'_zero _ _ @[simp] lemma opcyclesMap_zero [HasRightHomology S₁] [HasRightHomology Sβ‚‚] : opcyclesMap (0 : S₁ ⟢ Sβ‚‚) = 0 := opcyclesMap'_zero _ _ variable {S₁ Sβ‚‚} @[reassoc] lemma rightHomologyMap'_comp (φ₁ : S₁ ⟢ Sβ‚‚) (Ο†β‚‚ : Sβ‚‚ ⟢ S₃) (h₁ : S₁.RightHomologyData) (hβ‚‚ : Sβ‚‚.RightHomologyData) (h₃ : S₃.RightHomologyData) : rightHomologyMap' (φ₁ ≫ Ο†β‚‚) h₁ h₃ = rightHomologyMap' φ₁ h₁ hβ‚‚ ≫ rightHomologyMap' Ο†β‚‚ hβ‚‚ h₃ := by let γ₁ := rightHomologyMapData φ₁ h₁ hβ‚‚ let Ξ³β‚‚ := rightHomologyMapData Ο†β‚‚ hβ‚‚ h₃ rw [γ₁.rightHomologyMap'_eq, Ξ³β‚‚.rightHomologyMap'_eq, (γ₁.comp Ξ³β‚‚).rightHomologyMap'_eq, RightHomologyMapData.comp_Ο†H] @[reassoc] lemma opcyclesMap'_comp (φ₁ : S₁ ⟢ Sβ‚‚) (Ο†β‚‚ : Sβ‚‚ ⟢ S₃) (h₁ : S₁.RightHomologyData) (hβ‚‚ : Sβ‚‚.RightHomologyData) (h₃ : S₃.RightHomologyData) : opcyclesMap' (φ₁ ≫ Ο†β‚‚) h₁ h₃ = opcyclesMap' φ₁ h₁ hβ‚‚ ≫ opcyclesMap' Ο†β‚‚ hβ‚‚ h₃ := by let γ₁ := rightHomologyMapData φ₁ h₁ hβ‚‚ let Ξ³β‚‚ := rightHomologyMapData Ο†β‚‚ hβ‚‚ h₃ rw [γ₁.opcyclesMap'_eq, Ξ³β‚‚.opcyclesMap'_eq, (γ₁.comp Ξ³β‚‚).opcyclesMap'_eq, RightHomologyMapData.comp_Ο†Q] @[simp] lemma rightHomologyMap_comp [HasRightHomology S₁] [HasRightHomology Sβ‚‚] [HasRightHomology S₃] (φ₁ : S₁ ⟢ Sβ‚‚) (Ο†β‚‚ : Sβ‚‚ ⟢ S₃) : rightHomologyMap (φ₁ ≫ Ο†β‚‚) = rightHomologyMap φ₁ ≫ rightHomologyMap Ο†β‚‚ := rightHomologyMap'_comp _ _ _ _ _ @[simp] lemma opcyclesMap_comp [HasRightHomology S₁] [HasRightHomology Sβ‚‚] [HasRightHomology S₃] (φ₁ : S₁ ⟢ Sβ‚‚) (Ο†β‚‚ : Sβ‚‚ ⟢ S₃) : opcyclesMap (φ₁ ≫ Ο†β‚‚) = opcyclesMap φ₁ ≫ opcyclesMap Ο†β‚‚ := opcyclesMap'_comp _ _ _ _ _ attribute [simp] rightHomologyMap_comp opcyclesMap_comp /-- An isomorphism of short complexes `S₁ β‰… Sβ‚‚` induces an isomorphism on the `H` fields of right homology data of `S₁` and `Sβ‚‚`. -/ @[simps] def rightHomologyMapIso' (e : S₁ β‰… Sβ‚‚) (h₁ : S₁.RightHomologyData) (hβ‚‚ : Sβ‚‚.RightHomologyData) : h₁.H β‰… hβ‚‚.H where hom := rightHomologyMap' e.hom h₁ hβ‚‚ inv := rightHomologyMap' e.inv hβ‚‚ h₁ hom_inv_id := by rw [← rightHomologyMap'_comp, e.hom_inv_id, rightHomologyMap'_id] inv_hom_id := by rw [← rightHomologyMap'_comp, e.inv_hom_id, rightHomologyMap'_id] instance isIso_rightHomologyMap'_of_isIso (Ο† : S₁ ⟢ Sβ‚‚) [IsIso Ο†] (h₁ : S₁.RightHomologyData) (hβ‚‚ : Sβ‚‚.RightHomologyData) : IsIso (rightHomologyMap' Ο† h₁ hβ‚‚) := (inferInstance : IsIso (rightHomologyMapIso' (asIso Ο†) h₁ hβ‚‚).hom) /-- An isomorphism of short complexes `S₁ β‰… Sβ‚‚` induces an isomorphism on the `Q` fields of right homology data of `S₁` and `Sβ‚‚`. -/ @[simps] def opcyclesMapIso' (e : S₁ β‰… Sβ‚‚) (h₁ : S₁.RightHomologyData) (hβ‚‚ : Sβ‚‚.RightHomologyData) : h₁.Q β‰… hβ‚‚.Q where hom := opcyclesMap' e.hom h₁ hβ‚‚ inv := opcyclesMap' e.inv hβ‚‚ h₁ hom_inv_id := by rw [← opcyclesMap'_comp, e.hom_inv_id, opcyclesMap'_id] inv_hom_id := by rw [← opcyclesMap'_comp, e.inv_hom_id, opcyclesMap'_id] instance isIso_opcyclesMap'_of_isIso (Ο† : S₁ ⟢ Sβ‚‚) [IsIso Ο†] (h₁ : S₁.RightHomologyData) (hβ‚‚ : Sβ‚‚.RightHomologyData) : IsIso (opcyclesMap' Ο† h₁ hβ‚‚) := (inferInstance : IsIso (opcyclesMapIso' (asIso Ο†) h₁ hβ‚‚).hom) /-- The isomorphism `S₁.rightHomology β‰… Sβ‚‚.rightHomology` induced by an isomorphism of short complexes `S₁ β‰… Sβ‚‚`. -/ @[simps] noncomputable def rightHomologyMapIso (e : S₁ β‰… Sβ‚‚) [S₁.HasRightHomology] [Sβ‚‚.HasRightHomology] : S₁.rightHomology β‰… Sβ‚‚.rightHomology where hom := rightHomologyMap e.hom inv := rightHomologyMap e.inv hom_inv_id := by rw [← rightHomologyMap_comp, e.hom_inv_id, rightHomologyMap_id] inv_hom_id := by rw [← rightHomologyMap_comp, e.inv_hom_id, rightHomologyMap_id] instance isIso_rightHomologyMap_of_iso (Ο† : S₁ ⟢ Sβ‚‚) [IsIso Ο†] [S₁.HasRightHomology] [Sβ‚‚.HasRightHomology] : IsIso (rightHomologyMap Ο†) := (inferInstance : IsIso (rightHomologyMapIso (asIso Ο†)).hom) /-- The isomorphism `S₁.opcycles β‰… Sβ‚‚.opcycles` induced by an isomorphism of short complexes `S₁ β‰… Sβ‚‚`. -/ @[simps] noncomputable def opcyclesMapIso (e : S₁ β‰… Sβ‚‚) [S₁.HasRightHomology] [Sβ‚‚.HasRightHomology] : S₁.opcycles β‰… Sβ‚‚.opcycles where hom := opcyclesMap e.hom inv := opcyclesMap e.inv hom_inv_id := by rw [← opcyclesMap_comp, e.hom_inv_id, opcyclesMap_id] inv_hom_id := by rw [← opcyclesMap_comp, e.inv_hom_id, opcyclesMap_id] instance isIso_opcyclesMap_of_iso (Ο† : S₁ ⟢ Sβ‚‚) [IsIso Ο†] [S₁.HasRightHomology] [Sβ‚‚.HasRightHomology] : IsIso (opcyclesMap Ο†) := (inferInstance : IsIso (opcyclesMapIso (asIso Ο†)).hom) variable {S} namespace RightHomologyData variable (h : S.RightHomologyData) [S.HasRightHomology] /-- The isomorphism `S.rightHomology β‰… h.H` induced by a right homology data `h` for a short complex `S`. -/ noncomputable def rightHomologyIso : S.rightHomology β‰… h.H := rightHomologyMapIso' (Iso.refl _) _ _ /-- The isomorphism `S.opcycles β‰… h.Q` induced by a right homology data `h` for a short complex `S`. -/ noncomputable def opcyclesIso : S.opcycles β‰… h.Q :=
opcyclesMapIso' (Iso.refl _) _ _ @[reassoc (attr := simp)] lemma p_comp_opcyclesIso_inv : h.p ≫ h.opcyclesIso.inv = S.pOpcycles := by
Mathlib/Algebra/Homology/ShortComplex/RightHomology.lean
799
802
/- 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, SΓ©bastien GouΓ«zel -/ import Mathlib.Analysis.Normed.Module.Basic import Mathlib.MeasureTheory.Function.SimpleFuncDense /-! # Strongly measurable and finitely strongly measurable functions A function `f` is said to be strongly measurable if `f` is the sequential limit of simple functions. It is said to be finitely strongly measurable with respect to a measure `ΞΌ` if the supports of those simple functions have finite measure. If the target space has a second countable topology, strongly measurable and measurable are equivalent. If the measure is sigma-finite, strongly measurable and finitely strongly measurable are equivalent. The main property of finitely strongly measurable functions is `FinStronglyMeasurable.exists_set_sigmaFinite`: there exists a measurable set `t` such that the function is supported on `t` and `ΞΌ.restrict t` is sigma-finite. As a consequence, we can prove some results for those functions as if the measure was sigma-finite. We provide a solid API for strongly measurable functions, as a basis for the Bochner integral. ## Main definitions * `StronglyMeasurable f`: `f : Ξ± β†’ Ξ²` is the limit of a sequence `fs : β„• β†’ SimpleFunc Ξ± Ξ²`. * `FinStronglyMeasurable f ΞΌ`: `f : Ξ± β†’ Ξ²` is the limit of a sequence `fs : β„• β†’ SimpleFunc Ξ± Ξ²` such that for all `n ∈ β„•`, the measure of the support of `fs n` is finite. ## References * [HytΓΆnen, Tuomas, Jan Van Neerven, Mark Veraar, and Lutz Weis. Analysis in Banach spaces. Springer, 2016.][Hytonen_VanNeerven_Veraar_Wies_2016] -/ -- Guard against import creep assert_not_exists InnerProductSpace open MeasureTheory Filter TopologicalSpace Function Set MeasureTheory.Measure open ENNReal Topology MeasureTheory NNReal variable {Ξ± Ξ² Ξ³ ΞΉ : Type*} [Countable ΞΉ] namespace MeasureTheory local infixr:25 " β†’β‚› " => SimpleFunc section Definitions variable [TopologicalSpace Ξ²] /-- A function is `StronglyMeasurable` if it is the limit of simple functions. -/ def StronglyMeasurable [MeasurableSpace Ξ±] (f : Ξ± β†’ Ξ²) : Prop := βˆƒ fs : β„• β†’ Ξ± β†’β‚› Ξ², βˆ€ x, Tendsto (fun n => fs n x) atTop (𝓝 (f x)) /-- The notation for StronglyMeasurable giving the measurable space instance explicitly. -/ scoped notation "StronglyMeasurable[" m "]" => @MeasureTheory.StronglyMeasurable _ _ _ m /-- A function is `FinStronglyMeasurable` with respect to a measure if it is the limit of simple functions with support with finite measure. -/ def FinStronglyMeasurable [Zero Ξ²] {_ : MeasurableSpace Ξ±} (f : Ξ± β†’ Ξ²) (ΞΌ : Measure Ξ± := by volume_tac) : Prop := βˆƒ fs : β„• β†’ Ξ± β†’β‚› Ξ², (βˆ€ n, ΞΌ (support (fs n)) < ∞) ∧ βˆ€ x, Tendsto (fun n => fs n x) atTop (𝓝 (f x)) end Definitions open MeasureTheory /-! ## Strongly measurable functions -/ section StronglyMeasurable variable {_ : MeasurableSpace Ξ±} {ΞΌ : Measure Ξ±} {f : Ξ± β†’ Ξ²} {g : β„• β†’ Ξ±} {m : β„•} variable [TopologicalSpace Ξ²] theorem SimpleFunc.stronglyMeasurable (f : Ξ± β†’β‚› Ξ²) : StronglyMeasurable f := ⟨fun _ => f, fun _ => tendsto_const_nhds⟩ @[simp, nontriviality] lemma StronglyMeasurable.of_subsingleton_dom [Subsingleton Ξ±] : StronglyMeasurable f := ⟨fun _ => SimpleFunc.ofFinite f, fun _ => tendsto_const_nhds⟩ @[simp, nontriviality] lemma StronglyMeasurable.of_subsingleton_cod [Subsingleton Ξ²] : StronglyMeasurable f := by let f_sf : Ξ± β†’β‚› Ξ² := ⟨f, fun x => ?_, Set.Subsingleton.finite Set.subsingleton_of_subsingleton⟩ Β· exact ⟨fun _ => f_sf, fun x => tendsto_const_nhds⟩ Β· simp [Set.preimage, eq_iff_true_of_subsingleton] @[deprecated StronglyMeasurable.of_subsingleton_cod (since := "2025-04-09")] lemma Subsingleton.stronglyMeasurable [Subsingleton Ξ²] (f : Ξ± β†’ Ξ²) : StronglyMeasurable f := .of_subsingleton_cod @[deprecated StronglyMeasurable.of_subsingleton_dom (since := "2025-04-09")] lemma Subsingleton.stronglyMeasurable' [Subsingleton Ξ±] (f : Ξ± β†’ Ξ²) : StronglyMeasurable f := .of_subsingleton_dom theorem stronglyMeasurable_const {b : Ξ²} : StronglyMeasurable fun _ : Ξ± => b := ⟨fun _ => SimpleFunc.const Ξ± b, fun _ => tendsto_const_nhds⟩ @[to_additive] theorem stronglyMeasurable_one [One Ξ²] : StronglyMeasurable (1 : Ξ± β†’ Ξ²) := stronglyMeasurable_const /-- A version of `stronglyMeasurable_const` that assumes `f x = f y` for all `x, y`. This version works for functions between empty types. -/ theorem stronglyMeasurable_const' (hf : βˆ€ x y, f x = f y) : StronglyMeasurable f := by nontriviality Ξ± inhabit Ξ± convert stronglyMeasurable_const (Ξ² := Ξ²) using 1 exact funext fun x => hf x default variable [MeasurableSingletonClass Ξ±] section aux omit [TopologicalSpace Ξ²] /-- Auxiliary definition for `StronglyMeasurable.of_discrete`. -/ private noncomputable def simpleFuncAux (f : Ξ± β†’ Ξ²) (g : β„• β†’ Ξ±) : β„• β†’ SimpleFunc Ξ± Ξ² | 0 => .const _ (f (g 0)) | n + 1 => .piecewise {g n} (.singleton _) (.const _ <| f (g n)) (simpleFuncAux f g n) private lemma simpleFuncAux_eq_of_lt : βˆ€ n > m, simpleFuncAux f g n (g m) = f (g m) | _, .refl => by simp [simpleFuncAux] | _, Nat.le.step (m := n) hmn => by obtain hnm | hnm := eq_or_ne (g n) (g m) <;> simp [simpleFuncAux, Set.piecewise_eq_of_not_mem , hnm.symm, simpleFuncAux_eq_of_lt _ hmn] private lemma simpleFuncAux_eventuallyEq : βˆ€αΆ  n in atTop, simpleFuncAux f g n (g m) = f (g m) := eventually_atTop.2 ⟨_, simpleFuncAux_eq_of_lt⟩ end aux lemma StronglyMeasurable.of_discrete [Countable Ξ±] : StronglyMeasurable f := by nontriviality Ξ± nontriviality Ξ² obtain ⟨g, hg⟩ := exists_surjective_nat Ξ± exact ⟨simpleFuncAux f g, hg.forall.2 fun m ↦ tendsto_nhds_of_eventually_eq simpleFuncAux_eventuallyEq⟩ @[deprecated StronglyMeasurable.of_discrete (since := "2025-04-09")] theorem StronglyMeasurable.of_finite [Finite Ξ±] : StronglyMeasurable f := .of_discrete end StronglyMeasurable namespace StronglyMeasurable variable {f g : Ξ± β†’ Ξ²} section BasicPropertiesInAnyTopologicalSpace variable [TopologicalSpace Ξ²] /-- A sequence of simple functions such that `βˆ€ x, Tendsto (fun n => hf.approx n x) atTop (𝓝 (f x))`. That property is given by `stronglyMeasurable.tendsto_approx`. -/ protected noncomputable def approx {_ : MeasurableSpace Ξ±} (hf : StronglyMeasurable f) : β„• β†’ Ξ± β†’β‚› Ξ² := hf.choose protected theorem tendsto_approx {_ : MeasurableSpace Ξ±} (hf : StronglyMeasurable f) : βˆ€ x, Tendsto (fun n => hf.approx n x) atTop (𝓝 (f x)) := hf.choose_spec /-- Similar to `stronglyMeasurable.approx`, but enforces that the norm of every function in the sequence is less than `c` everywhere. If `β€–f xβ€– ≀ c` this sequence of simple functions verifies `Tendsto (fun n => hf.approxBounded n x) atTop (𝓝 (f x))`. -/ noncomputable def approxBounded {_ : MeasurableSpace Ξ±} [Norm Ξ²] [SMul ℝ Ξ²] (hf : StronglyMeasurable f) (c : ℝ) : β„• β†’ SimpleFunc Ξ± Ξ² := fun n => (hf.approx n).map fun x => min 1 (c / β€–xβ€–) β€’ x theorem tendsto_approxBounded_of_norm_le {Ξ²} {f : Ξ± β†’ Ξ²} [NormedAddCommGroup Ξ²] [NormedSpace ℝ Ξ²] {m : MeasurableSpace Ξ±} (hf : StronglyMeasurable[m] f) {c : ℝ} {x : Ξ±} (hfx : β€–f xβ€– ≀ c) : Tendsto (fun n => hf.approxBounded c n x) atTop (𝓝 (f x)) := by have h_tendsto := hf.tendsto_approx x simp only [StronglyMeasurable.approxBounded, SimpleFunc.coe_map, Function.comp_apply] by_cases hfx0 : β€–f xβ€– = 0 Β· rw [norm_eq_zero] at hfx0 rw [hfx0] at h_tendsto ⊒ have h_tendsto_norm : Tendsto (fun n => β€–hf.approx n xβ€–) atTop (𝓝 0) := by convert h_tendsto.norm rw [norm_zero] refine squeeze_zero_norm (fun n => ?_) h_tendsto_norm calc β€–min 1 (c / β€–hf.approx n xβ€–) β€’ hf.approx n xβ€– = β€–min 1 (c / β€–hf.approx n xβ€–)β€– * β€–hf.approx n xβ€– := norm_smul _ _ _ ≀ β€–(1 : ℝ)β€– * β€–hf.approx n xβ€– := by refine mul_le_mul_of_nonneg_right ?_ (norm_nonneg _) rw [norm_one, Real.norm_of_nonneg] Β· exact min_le_left _ _ Β· exact le_min zero_le_one (div_nonneg ((norm_nonneg _).trans hfx) (norm_nonneg _)) _ = β€–hf.approx n xβ€– := by rw [norm_one, one_mul] rw [← one_smul ℝ (f x)] refine Tendsto.smul ?_ h_tendsto have : min 1 (c / β€–f xβ€–) = 1 := by rw [min_eq_left_iff, one_le_div (lt_of_le_of_ne (norm_nonneg _) (Ne.symm hfx0))] exact hfx nth_rw 2 [this.symm] refine Tendsto.min tendsto_const_nhds ?_ exact Tendsto.div tendsto_const_nhds h_tendsto.norm hfx0 theorem tendsto_approxBounded_ae {Ξ²} {f : Ξ± β†’ Ξ²} [NormedAddCommGroup Ξ²] [NormedSpace ℝ Ξ²] {m m0 : MeasurableSpace Ξ±} {ΞΌ : Measure Ξ±} (hf : StronglyMeasurable[m] f) {c : ℝ} (hf_bound : βˆ€α΅ x βˆ‚ΞΌ, β€–f xβ€– ≀ c) : βˆ€α΅ x βˆ‚ΞΌ, Tendsto (fun n => hf.approxBounded c n x) atTop (𝓝 (f x)) := by filter_upwards [hf_bound] with x hfx using tendsto_approxBounded_of_norm_le hf hfx theorem norm_approxBounded_le {Ξ²} {f : Ξ± β†’ Ξ²} [SeminormedAddCommGroup Ξ²] [NormedSpace ℝ Ξ²] {m : MeasurableSpace Ξ±} {c : ℝ} (hf : StronglyMeasurable[m] f) (hc : 0 ≀ c) (n : β„•) (x : Ξ±) : β€–hf.approxBounded c n xβ€– ≀ c := by simp only [StronglyMeasurable.approxBounded, SimpleFunc.coe_map, Function.comp_apply] refine (norm_smul_le _ _).trans ?_ by_cases h0 : β€–hf.approx n xβ€– = 0 Β· simp only [h0, _root_.div_zero, min_eq_right, zero_le_one, norm_zero, mul_zero] exact hc rcases le_total β€–hf.approx n xβ€– c with h | h Β· rw [min_eq_left _] Β· simpa only [norm_one, one_mul] using h Β· rwa [one_le_div (lt_of_le_of_ne (norm_nonneg _) (Ne.symm h0))] Β· rw [min_eq_right _] Β· rw [norm_div, norm_norm, mul_comm, mul_div, div_eq_mul_inv, mul_comm, ← mul_assoc, inv_mul_cancelβ‚€ h0, one_mul, Real.norm_of_nonneg hc] Β· rwa [div_le_one (lt_of_le_of_ne (norm_nonneg _) (Ne.symm h0))] theorem _root_.stronglyMeasurable_bot_iff [Nonempty Ξ²] [T2Space Ξ²] : StronglyMeasurable[βŠ₯] f ↔ βˆƒ c, f = fun _ => c := by rcases isEmpty_or_nonempty Ξ± with hΞ± | hΞ± Β· simp [eq_iff_true_of_subsingleton] refine ⟨fun hf => ?_, fun hf_eq => ?_⟩ Β· refine ⟨f hΞ±.some, ?_⟩ let fs := hf.approx have h_fs_tendsto : βˆ€ x, Tendsto (fun n => fs n x) atTop (𝓝 (f x)) := hf.tendsto_approx have : βˆ€ n, βˆƒ c, βˆ€ x, fs n x = c := fun n => SimpleFunc.simpleFunc_bot (fs n) let cs n := (this n).choose have h_cs_eq : βˆ€ n, ⇑(fs n) = fun _ => cs n := fun n => funext (this n).choose_spec conv at h_fs_tendsto => enter [x, 1, n]; rw [h_cs_eq] have h_tendsto : Tendsto cs atTop (𝓝 (f hΞ±.some)) := h_fs_tendsto hΞ±.some ext1 x exact tendsto_nhds_unique (h_fs_tendsto x) h_tendsto Β· obtain ⟨c, rfl⟩ := hf_eq exact stronglyMeasurable_const end BasicPropertiesInAnyTopologicalSpace theorem finStronglyMeasurable_of_set_sigmaFinite [TopologicalSpace Ξ²] [Zero Ξ²] {m : MeasurableSpace Ξ±} {ΞΌ : Measure Ξ±} (hf_meas : StronglyMeasurable f) {t : Set Ξ±} (ht : MeasurableSet t) (hft_zero : βˆ€ x ∈ tᢜ, f x = 0) (htΞΌ : SigmaFinite (ΞΌ.restrict t)) : FinStronglyMeasurable f ΞΌ := by haveI : SigmaFinite (ΞΌ.restrict t) := htΞΌ let S := spanningSets (ΞΌ.restrict t) have hS_meas : βˆ€ n, MeasurableSet (S n) := measurableSet_spanningSets (ΞΌ.restrict t) let f_approx := hf_meas.approx let fs n := SimpleFunc.restrict (f_approx n) (S n ∩ t) have h_fs_t_compl : βˆ€ n, βˆ€ x, x βˆ‰ t β†’ fs n x = 0 := by intro n x hxt rw [SimpleFunc.restrict_apply _ ((hS_meas n).inter ht)] refine Set.indicator_of_not_mem ?_ _
simp [hxt] refine ⟨fs, ?_, fun x => ?_⟩ Β· simp_rw [SimpleFunc.support_eq, ← Finset.mem_coe] classical refine fun n => measure_biUnion_lt_top {y ∈ (fs n).range | y β‰  0}.finite_toSet fun y hy => ?_ rw [SimpleFunc.restrict_preimage_singleton _ ((hS_meas n).inter ht)] swap Β· letI : (y : Ξ²) β†’ Decidable (y = 0) := fun y => Classical.propDecidable _ rw [Finset.mem_coe, Finset.mem_filter] at hy exact hy.2 refine (measure_mono Set.inter_subset_left).trans_lt ?_ have h_lt_top := measure_spanningSets_lt_top (ΞΌ.restrict t) n rwa [Measure.restrict_apply' ht] at h_lt_top Β· by_cases hxt : x ∈ t swap Β· rw [funext fun n => h_fs_t_compl n x hxt, hft_zero x hxt] exact tendsto_const_nhds have h : Tendsto (fun n => (f_approx n) x) atTop (𝓝 (f x)) := hf_meas.tendsto_approx x
Mathlib/MeasureTheory/Function/StronglyMeasurable/Basic.lean
263
280
/- Copyright (c) 2022 Jake Levinson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jake Levinson -/ import Mathlib.Data.Finset.Preimage import Mathlib.Data.Finset.Prod import Mathlib.Data.SetLike.Basic import Mathlib.Order.UpperLower.Basic /-! # Young diagrams A Young diagram is a finite set of up-left justified boxes: ```text β–‘β–‘β–‘β–‘β–‘ β–‘β–‘β–‘ β–‘β–‘β–‘ β–‘ ``` This Young diagram corresponds to the [5, 3, 3, 1] partition of 12. We represent it as a lower set in `β„• Γ— β„•` in the product partial order. We write `(i, j) ∈ ΞΌ` to say that `(i, j)` (in matrix coordinates) is in the Young diagram `ΞΌ`. ## Main definitions - `YoungDiagram` : Young diagrams - `YoungDiagram.card` : the number of cells in a Young diagram (its *cardinality*) - `YoungDiagram.instDistribLatticeYoungDiagram` : a distributive lattice instance for Young diagrams ordered by containment, with `(βŠ₯ : YoungDiagram)` the empty diagram. - `YoungDiagram.row` and `YoungDiagram.rowLen`: rows of a Young diagram and their lengths - `YoungDiagram.col` and `YoungDiagram.colLen`: columns of a Young diagram and their lengths ## Notation In "English notation", a Young diagram is drawn so that (i1, j1) ≀ (i2, j2) means (i1, j1) is weakly up-and-left of (i2, j2). This terminology is used below, e.g. in `YoungDiagram.up_left_mem`. ## Tags Young diagram ## References <https://en.wikipedia.org/wiki/Young_tableau> -/ open Function /-- A Young diagram is a finite collection of cells on the `β„• Γ— β„•` grid such that whenever a cell is present, so are all the ones above and to the left of it. Like matrices, an `(i, j)` cell is a cell in row `i` and column `j`, where rows are enumerated downward and columns rightward. Young diagrams are modeled as finite sets in `β„• Γ— β„•` that are lower sets with respect to the standard order on products. -/ @[ext] structure YoungDiagram where /-- A finite set which represents a finite collection of cells on the `β„• Γ— β„•` grid. -/ cells : Finset (β„• Γ— β„•) /-- Cells are up-left justified, witnessed by the fact that `cells` is a lower set in `β„• Γ— β„•`. -/ isLowerSet : IsLowerSet (cells : Set (β„• Γ— β„•)) namespace YoungDiagram instance : SetLike YoungDiagram (β„• Γ— β„•) where -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: figure out how to do this correctly coe y := y.cells coe_injective' ΞΌ Ξ½ h := by rwa [YoungDiagram.ext_iff, ← Finset.coe_inj] @[simp] theorem mem_cells {ΞΌ : YoungDiagram} (c : β„• Γ— β„•) : c ∈ ΞΌ.cells ↔ c ∈ ΞΌ := Iff.rfl @[simp] theorem mem_mk (c : β„• Γ— β„•) (cells) (isLowerSet) : c ∈ YoungDiagram.mk cells isLowerSet ↔ c ∈ cells := Iff.rfl instance decidableMem (ΞΌ : YoungDiagram) : DecidablePred (Β· ∈ ΞΌ) := inferInstanceAs (DecidablePred (Β· ∈ ΞΌ.cells)) /-- In "English notation", a Young diagram is drawn so that (i1, j1) ≀ (i2, j2) means (i1, j1) is weakly up-and-left of (i2, j2). -/ theorem up_left_mem (ΞΌ : YoungDiagram) {i1 i2 j1 j2 : β„•} (hi : i1 ≀ i2) (hj : j1 ≀ j2) (hcell : (i2, j2) ∈ ΞΌ) : (i1, j1) ∈ ΞΌ := ΞΌ.isLowerSet (Prod.mk_le_mk.mpr ⟨hi, hj⟩) hcell section DistribLattice @[simp] theorem cells_subset_iff {ΞΌ Ξ½ : YoungDiagram} : ΞΌ.cells βŠ† Ξ½.cells ↔ ΞΌ ≀ Ξ½ := Iff.rfl @[simp] theorem cells_ssubset_iff {ΞΌ Ξ½ : YoungDiagram} : ΞΌ.cells βŠ‚ Ξ½.cells ↔ ΞΌ < Ξ½ := Iff.rfl instance : Max YoungDiagram where max ΞΌ Ξ½ := { cells := ΞΌ.cells βˆͺ Ξ½.cells isLowerSet := by rw [Finset.coe_union] exact ΞΌ.isLowerSet.union Ξ½.isLowerSet } @[simp] theorem cells_sup (ΞΌ Ξ½ : YoungDiagram) : (ΞΌ βŠ” Ξ½).cells = ΞΌ.cells βˆͺ Ξ½.cells := rfl @[simp, norm_cast] theorem coe_sup (ΞΌ Ξ½ : YoungDiagram) : ↑(ΞΌ βŠ” Ξ½) = (ΞΌ βˆͺ Ξ½ : Set (β„• Γ— β„•)) := Finset.coe_union _ _ @[simp] theorem mem_sup {ΞΌ Ξ½ : YoungDiagram} {x : β„• Γ— β„•} : x ∈ ΞΌ βŠ” Ξ½ ↔ x ∈ ΞΌ ∨ x ∈ Ξ½ := Finset.mem_union instance : Min YoungDiagram where min ΞΌ Ξ½ := { cells := ΞΌ.cells ∩ Ξ½.cells isLowerSet := by rw [Finset.coe_inter] exact ΞΌ.isLowerSet.inter Ξ½.isLowerSet } @[simp] theorem cells_inf (ΞΌ Ξ½ : YoungDiagram) : (ΞΌ βŠ“ Ξ½).cells = ΞΌ.cells ∩ Ξ½.cells := rfl @[simp, norm_cast] theorem coe_inf (ΞΌ Ξ½ : YoungDiagram) : ↑(ΞΌ βŠ“ Ξ½) = (ΞΌ ∩ Ξ½ : Set (β„• Γ— β„•)) := Finset.coe_inter _ _ @[simp] theorem mem_inf {ΞΌ Ξ½ : YoungDiagram} {x : β„• Γ— β„•} : x ∈ ΞΌ βŠ“ Ξ½ ↔ x ∈ ΞΌ ∧ x ∈ Ξ½ := Finset.mem_inter /-- The empty Young diagram is (βŠ₯ : young_diagram). -/ instance : OrderBot YoungDiagram where bot := { cells := βˆ… isLowerSet := by intros a b _ h simp only [Finset.coe_empty, Set.mem_empty_iff_false] simp only [Finset.coe_empty, Set.mem_empty_iff_false] at h } bot_le _ _ := by intro y simp only [mem_mk, Finset.not_mem_empty] at y @[simp] theorem cells_bot : (βŠ₯ : YoungDiagram).cells = βˆ… := rfl @[simp] theorem not_mem_bot (x : β„• Γ— β„•) : x βˆ‰ (βŠ₯ : YoungDiagram) := Finset.not_mem_empty x @[norm_cast] theorem coe_bot : (βŠ₯ : YoungDiagram) = (βˆ… : Set (β„• Γ— β„•)) := by ext; simp instance : Inhabited YoungDiagram := ⟨βŠ₯⟩ instance : DistribLattice YoungDiagram := Function.Injective.distribLattice YoungDiagram.cells (fun ΞΌ Ξ½ h => by rwa [YoungDiagram.ext_iff]) (fun _ _ => rfl) fun _ _ => rfl end DistribLattice /-- Cardinality of a Young diagram -/ protected abbrev card (ΞΌ : YoungDiagram) : β„• := ΞΌ.cells.card section Transpose /-- The `transpose` of a Young diagram is obtained by swapping i's with j's. -/ def transpose (ΞΌ : YoungDiagram) : YoungDiagram where cells := (Equiv.prodComm _ _).finsetCongr ΞΌ.cells isLowerSet _ _ h := by simp only [Finset.mem_coe, Equiv.finsetCongr_apply, Finset.mem_map_equiv] intro hcell apply ΞΌ.isLowerSet _ hcell simp [h] @[simp] theorem mem_transpose {ΞΌ : YoungDiagram} {c : β„• Γ— β„•} : c ∈ ΞΌ.transpose ↔ c.swap ∈ ΞΌ := by simp [transpose] @[simp] theorem transpose_transpose (ΞΌ : YoungDiagram) : ΞΌ.transpose.transpose = ΞΌ := by ext x simp theorem transpose_eq_iff_eq_transpose {ΞΌ Ξ½ : YoungDiagram} : ΞΌ.transpose = Ξ½ ↔ ΞΌ = Ξ½.transpose := by constructor <;> Β· rintro rfl simp @[simp] theorem transpose_eq_iff {ΞΌ Ξ½ : YoungDiagram} : ΞΌ.transpose = Ξ½.transpose ↔ ΞΌ = Ξ½ := by rw [transpose_eq_iff_eq_transpose] simp -- This is effectively both directions of `transpose_le_iff` below. protected theorem le_of_transpose_le {ΞΌ Ξ½ : YoungDiagram} (h_le : ΞΌ.transpose ≀ Ξ½) : ΞΌ ≀ Ξ½.transpose := fun c hc => by simp only [mem_cells, mem_transpose] apply h_le simpa @[simp] theorem transpose_le_iff {ΞΌ Ξ½ : YoungDiagram} : ΞΌ.transpose ≀ Ξ½.transpose ↔ ΞΌ ≀ Ξ½ := ⟨fun h => by convert YoungDiagram.le_of_transpose_le h simp, fun h => by rw [← transpose_transpose ΞΌ] at h exact YoungDiagram.le_of_transpose_le h ⟩ @[mono] protected theorem transpose_mono {ΞΌ Ξ½ : YoungDiagram} (h_le : ΞΌ ≀ Ξ½) : ΞΌ.transpose ≀ Ξ½.transpose := transpose_le_iff.mpr h_le /-- Transposing Young diagrams is an `OrderIso`. -/ @[simps] def transposeOrderIso : YoungDiagram ≃o YoungDiagram := ⟨⟨transpose, transpose, fun _ => by simp, fun _ => by simp⟩, by simp⟩ end Transpose section Rows /-! ### Rows and row lengths of Young diagrams. This section defines `ΞΌ.row` and `ΞΌ.rowLen`, with the following API: 1. `(i, j) ∈ ΞΌ ↔ j < ΞΌ.rowLen i` 2. `ΞΌ.row i = {i} Γ—Λ’ (Finset.range (ΞΌ.rowLen i))` 3. `ΞΌ.rowLen i = (ΞΌ.row i).card` 4. `βˆ€ {i1 i2}, i1 ≀ i2 β†’ ΞΌ.rowLen i2 ≀ ΞΌ.rowLen i1` Note: #3 is not convenient for defining `ΞΌ.rowLen`; instead, `ΞΌ.rowLen` is defined as the smallest `j` such that `(i, j) βˆ‰ ΞΌ`. -/ /-- The `i`-th row of a Young diagram consists of the cells whose first coordinate is `i`. -/ def row (ΞΌ : YoungDiagram) (i : β„•) : Finset (β„• Γ— β„•) := ΞΌ.cells.filter fun c => c.fst = i theorem mem_row_iff {ΞΌ : YoungDiagram} {i : β„•} {c : β„• Γ— β„•} : c ∈ ΞΌ.row i ↔ c ∈ ΞΌ ∧ c.fst = i := by simp [row] theorem mk_mem_row_iff {ΞΌ : YoungDiagram} {i j : β„•} : (i, j) ∈ ΞΌ.row i ↔ (i, j) ∈ ΞΌ := by simp [row] protected theorem exists_not_mem_row (ΞΌ : YoungDiagram) (i : β„•) : βˆƒ j, (i, j) βˆ‰ ΞΌ := by obtain ⟨j, hj⟩ := Infinite.exists_not_mem_finset (ΞΌ.cells.preimage (Prod.mk i) fun _ _ _ _ h => by cases h rfl) rw [Finset.mem_preimage] at hj exact ⟨j, hj⟩ /-- Length of a row of a Young diagram -/ def rowLen (ΞΌ : YoungDiagram) (i : β„•) : β„• := Nat.find <| ΞΌ.exists_not_mem_row i theorem mem_iff_lt_rowLen {ΞΌ : YoungDiagram} {i j : β„•} : (i, j) ∈ ΞΌ ↔ j < ΞΌ.rowLen i := by rw [rowLen, Nat.lt_find_iff] push_neg exact ⟨fun h _ hmj => ΞΌ.up_left_mem (by rfl) hmj h, fun h => h _ (by rfl)⟩ theorem row_eq_prod {ΞΌ : YoungDiagram} {i : β„•} : ΞΌ.row i = {i} Γ—Λ’ Finset.range (ΞΌ.rowLen i) := by ext ⟨a, b⟩ simp only [Finset.mem_product, Finset.mem_singleton, Finset.mem_range, mem_row_iff, mem_iff_lt_rowLen, and_comm, and_congr_right_iff] rintro rfl rfl theorem rowLen_eq_card (ΞΌ : YoungDiagram) {i : β„•} : ΞΌ.rowLen i = (ΞΌ.row i).card := by simp [row_eq_prod] @[mono] theorem rowLen_anti (ΞΌ : YoungDiagram) (i1 i2 : β„•) (hi : i1 ≀ i2) : ΞΌ.rowLen i2 ≀ ΞΌ.rowLen i1 := by by_contra! h_lt rw [← lt_self_iff_false (ΞΌ.rowLen i1)] rw [← mem_iff_lt_rowLen] at h_lt ⊒ exact ΞΌ.up_left_mem hi (by rfl) h_lt end Rows section Columns /-! ### Columns and column lengths of Young diagrams. This section has an identical API to the rows section. -/ /-- The `j`-th column of a Young diagram consists of the cells whose second coordinate is `j`. -/ def col (ΞΌ : YoungDiagram) (j : β„•) : Finset (β„• Γ— β„•) := ΞΌ.cells.filter fun c => c.snd = j theorem mem_col_iff {ΞΌ : YoungDiagram} {j : β„•} {c : β„• Γ— β„•} : c ∈ ΞΌ.col j ↔ c ∈ ΞΌ ∧ c.snd = j := by simp [col] theorem mk_mem_col_iff {ΞΌ : YoungDiagram} {i j : β„•} : (i, j) ∈ ΞΌ.col j ↔ (i, j) ∈ ΞΌ := by simp [col] protected theorem exists_not_mem_col (ΞΌ : YoungDiagram) (j : β„•) : βˆƒ i, (i, j) βˆ‰ ΞΌ.cells := by convert ΞΌ.transpose.exists_not_mem_row j using 1 simp /-- Length of a column of a Young diagram -/ def colLen (ΞΌ : YoungDiagram) (j : β„•) : β„• := Nat.find <| ΞΌ.exists_not_mem_col j @[simp] theorem colLen_transpose (ΞΌ : YoungDiagram) (j : β„•) : ΞΌ.transpose.colLen j = ΞΌ.rowLen j := by simp [rowLen, colLen] @[simp] theorem rowLen_transpose (ΞΌ : YoungDiagram) (i : β„•) : ΞΌ.transpose.rowLen i = ΞΌ.colLen i := by simp [rowLen, colLen] theorem mem_iff_lt_colLen {ΞΌ : YoungDiagram} {i j : β„•} : (i, j) ∈ ΞΌ ↔ i < ΞΌ.colLen j := by rw [← rowLen_transpose, ← mem_iff_lt_rowLen] simp theorem col_eq_prod {ΞΌ : YoungDiagram} {j : β„•} : ΞΌ.col j = Finset.range (ΞΌ.colLen j) Γ—Λ’ {j} := by ext ⟨a, b⟩ simp only [Finset.mem_product, Finset.mem_singleton, Finset.mem_range, mem_col_iff, mem_iff_lt_colLen, and_comm, and_congr_right_iff] rintro rfl rfl theorem colLen_eq_card (ΞΌ : YoungDiagram) {j : β„•} : ΞΌ.colLen j = (ΞΌ.col j).card := by simp [col_eq_prod] @[mono] theorem colLen_anti (ΞΌ : YoungDiagram) (j1 j2 : β„•) (hj : j1 ≀ j2) : ΞΌ.colLen j2 ≀ ΞΌ.colLen j1 := by convert ΞΌ.transpose.rowLen_anti j1 j2 hj using 1 <;> simp end Columns section RowLens /-! ### The list of row lengths of a Young diagram This section defines `ΞΌ.rowLens : List β„•`, the list of row lengths of a Young diagram `ΞΌ`. 1. `YoungDiagram.rowLens_sorted` : It is weakly decreasing (`List.Sorted (Β· β‰₯ Β·)`). 2. `YoungDiagram.rowLens_pos` : It is strictly positive. -/ /-- List of row lengths of a Young diagram -/ def rowLens (ΞΌ : YoungDiagram) : List β„• := (List.range <| ΞΌ.colLen 0).map ΞΌ.rowLen @[simp] theorem get_rowLens {ΞΌ : YoungDiagram} {i : Nat} {h : i < ΞΌ.rowLens.length} : ΞΌ.rowLens[i] = ΞΌ.rowLen i := by simp only [rowLens, List.getElem_range, List.getElem_map] @[simp] theorem length_rowLens {ΞΌ : YoungDiagram} : ΞΌ.rowLens.length = ΞΌ.colLen 0 := by simp only [rowLens, List.length_map, List.length_range] theorem rowLens_sorted (ΞΌ : YoungDiagram) : ΞΌ.rowLens.Sorted (Β· β‰₯ Β·) := List.pairwise_le_range.map _ ΞΌ.rowLen_anti theorem pos_of_mem_rowLens (ΞΌ : YoungDiagram) (x : β„•) (hx : x ∈ ΞΌ.rowLens) : 0 < x := by rw [rowLens, List.mem_map] at hx obtain ⟨i, hi, rfl : ΞΌ.rowLen i = x⟩ := hx rwa [List.mem_range, ← mem_iff_lt_colLen, mem_iff_lt_rowLen] at hi end RowLens section EquivListRowLens /-! ### Equivalence between Young diagrams and lists of natural numbers This section defines the equivalence between Young diagrams `ΞΌ` and weakly decreasing lists `w` of positive natural numbers, corresponding to row lengths of the diagram: `YoungDiagram.equivListRowLens :` `YoungDiagram ≃ {w : List β„• // w.Sorted (Β· β‰₯ Β·) ∧ βˆ€ x ∈ w, 0 < x}` The two directions are `YoungDiagram.rowLens` (defined above) and `YoungDiagram.ofRowLens`. -/
/-- The cells making up a `YoungDiagram` from a list of row lengths -/
Mathlib/Combinatorics/Young/YoungDiagram.lean
392
393
/- 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.OuterMeasure.OfFunction import Mathlib.MeasureTheory.PiSystem /-! # The Caratheodory Οƒ-algebra of an outer measure Given an outer measure `m`, the CarathΓ©odory-measurable sets are the sets `s` such that for all sets `t` we have `m t = m (t ∩ s) + m (t \ s)`. This forms a measurable space. ## Main definitions and statements * `MeasureTheory.OuterMeasure.caratheodory` is the CarathΓ©odory-measurable space of an outer measure. ## References * <https://en.wikipedia.org/wiki/Outer_measure> * <https://en.wikipedia.org/wiki/Carath%C3%A9odory%27s_criterion> ## Tags CarathΓ©odory-measurable, CarathΓ©odory's criterion -/ noncomputable section open Set Function Filter open scoped NNReal Topology ENNReal namespace MeasureTheory namespace OuterMeasure section CaratheodoryMeasurable universe u variable {Ξ± : Type u} (m : OuterMeasure Ξ±) attribute [local simp] Set.inter_comm Set.inter_left_comm Set.inter_assoc variable {s s₁ sβ‚‚ : Set Ξ±} /-- A set `s` is CarathΓ©odory-measurable for an outer measure `m` if for all sets `t` we have `m t = m (t ∩ s) + m (t \ s)`. -/ def IsCaratheodory (s : Set Ξ±) : Prop := βˆ€ t, m t = m (t ∩ s) + m (t \ s) theorem isCaratheodory_iff_le' {s : Set Ξ±} : IsCaratheodory m s ↔ βˆ€ t, m (t ∩ s) + m (t \ s) ≀ m t := forall_congr' fun _ => le_antisymm_iff.trans <| and_iff_right <| measure_le_inter_add_diff _ _ _ @[simp] theorem isCaratheodory_empty : IsCaratheodory m βˆ… := by simp [IsCaratheodory, m.empty, diff_empty] theorem isCaratheodory_compl : IsCaratheodory m s₁ β†’ IsCaratheodory m sβ‚αΆœ := by simp [IsCaratheodory, diff_eq, add_comm] @[simp] theorem isCaratheodory_compl_iff : IsCaratheodory m sᢜ ↔ IsCaratheodory m s := ⟨fun h => by simpa using isCaratheodory_compl m h, isCaratheodory_compl m⟩ theorem isCaratheodory_union (h₁ : IsCaratheodory m s₁) (hβ‚‚ : IsCaratheodory m sβ‚‚) : IsCaratheodory m (s₁ βˆͺ sβ‚‚) := fun t => by rw [h₁ t, hβ‚‚ (t ∩ s₁), hβ‚‚ (t \ s₁), h₁ (t ∩ (s₁ βˆͺ sβ‚‚)), inter_diff_assoc _ _ s₁, Set.inter_assoc _ _ s₁, inter_eq_self_of_subset_right Set.subset_union_left, union_diff_left, hβ‚‚ (t ∩ s₁)] simp [diff_eq, add_assoc] variable {m} in lemma IsCaratheodory.biUnion_of_finite {ΞΉ : Type*} {s : ΞΉ β†’ Set Ξ±} {t : Set ΞΉ} (ht : t.Finite) (h : βˆ€ i ∈ t, m.IsCaratheodory (s i)) : m.IsCaratheodory (⋃ i ∈ t, s i) := by classical lift t to Finset ΞΉ using ht induction t using Finset.induction_on with | empty => simp | insert i t hi IH => simp only [Finset.mem_coe, Finset.mem_insert, iUnion_iUnion_eq_or_left] at h ⊒ exact m.isCaratheodory_union (h _ <| Or.inl rfl) (IH fun _ hj ↦ h _ <| Or.inr hj) theorem measure_inter_union (h : s₁ ∩ sβ‚‚ βŠ† βˆ…) (h₁ : IsCaratheodory m s₁) {t : Set Ξ±} : m (t ∩ (s₁ βˆͺ sβ‚‚)) = m (t ∩ s₁) + m (t ∩ sβ‚‚) := by rw [h₁, Set.inter_assoc, Set.union_inter_cancel_left, inter_diff_assoc, union_diff_cancel_left h] theorem isCaratheodory_iUnion_lt {s : β„• β†’ Set Ξ±} : βˆ€ {n : β„•}, (βˆ€ i < n, IsCaratheodory m (s i)) β†’ IsCaratheodory m (⋃ i < n, s i) | 0, _ => by simp [Nat.not_lt_zero] | n + 1, h => by rw [biUnion_lt_succ] exact isCaratheodory_union m (isCaratheodory_iUnion_lt fun i hi => h i <| lt_of_lt_of_le hi <| Nat.le_succ _) (h n (le_refl (n + 1))) theorem isCaratheodory_inter (h₁ : IsCaratheodory m s₁) (hβ‚‚ : IsCaratheodory m sβ‚‚) : IsCaratheodory m (s₁ ∩ sβ‚‚) := by rw [← isCaratheodory_compl_iff, Set.compl_inter] exact isCaratheodory_union _ (isCaratheodory_compl _ h₁) (isCaratheodory_compl _ hβ‚‚) lemma isCaratheodory_diff (h₁ : IsCaratheodory m s₁) (hβ‚‚ : IsCaratheodory m sβ‚‚) : IsCaratheodory m (s₁ \ sβ‚‚) := m.isCaratheodory_inter h₁ (m.isCaratheodory_compl hβ‚‚) lemma isCaratheodory_partialSups {ΞΉ : Type*} [Preorder ΞΉ] [LocallyFiniteOrderBot ΞΉ] {s : ΞΉ β†’ Set Ξ±} (h : βˆ€ i, m.IsCaratheodory (s i)) (i : ΞΉ) : m.IsCaratheodory (partialSups s i) := by simpa only [partialSups_apply, Finset.sup'_eq_sup, Finset.sup_set_eq_biUnion, ← Finset.mem_coe, Finset.coe_Iic] using .biUnion_of_finite (finite_Iic _) (fun j _ ↦ h j) lemma isCaratheodory_disjointed {ΞΉ : Type*} [Preorder ΞΉ] [LocallyFiniteOrderBot ΞΉ] {s : ΞΉ β†’ Set Ξ±} (h : βˆ€ i, m.IsCaratheodory (s i)) (i : ΞΉ) : m.IsCaratheodory (disjointed s i) := disjointedRec (fun _ j ht ↦ m.isCaratheodory_diff ht <| h j) (h i) theorem isCaratheodory_sum {s : β„• β†’ Set Ξ±} (h : βˆ€ i, IsCaratheodory m (s i)) (hd : Pairwise (Disjoint on s)) {t : Set Ξ±} : βˆ€ {n}, (βˆ‘ i ∈ Finset.range n, m (t ∩ s i)) = m (t ∩ ⋃ i < n, s i) | 0 => by simp [Nat.not_lt_zero, m.empty] | Nat.succ n => by rw [biUnion_lt_succ, Finset.sum_range_succ, Set.union_comm, isCaratheodory_sum h hd, m.measure_inter_union _ (h n), add_comm] intro a simpa using fun (h₁ : a ∈ s n) i (hi : i < n) hβ‚‚ => (hd (ne_of_gt hi)).le_bot ⟨h₁, hβ‚‚βŸ© /-- Use `isCaratheodory_iUnion` instead, which does not require the disjoint assumption. -/ theorem isCaratheodory_iUnion_of_disjoint {s : β„• β†’ Set Ξ±} (h : βˆ€ i, IsCaratheodory m (s i)) (hd : Pairwise (Disjoint on s)) : IsCaratheodory m (⋃ i, s i) := by apply (isCaratheodory_iff_le' m).mpr intro t have hp : m (t ∩ ⋃ i, s i) ≀ ⨆ n, m (t ∩ ⋃ i < n, s i) := by convert measure_iUnion_le (ΞΌ := m) fun i => t ∩ s i using 1 Β· simp [inter_iUnion] Β· simp [ENNReal.tsum_eq_iSup_nat, isCaratheodory_sum m h hd] refine le_trans (add_le_add_right hp _) ?_ rw [ENNReal.iSup_add] refine iSup_le fun n => le_trans (add_le_add_left ?_ _) (ge_of_eq (isCaratheodory_iUnion_lt m (fun i _ => h i) _)) refine m.mono (diff_subset_diff_right ?_) exact iUnionβ‚‚_subset fun i _ => subset_iUnion _ i lemma isCaratheodory_iUnion {s : β„• β†’ Set Ξ±} (h : βˆ€ i, m.IsCaratheodory (s i)) : m.IsCaratheodory (⋃ i, s i) := by rw [← iUnion_disjointed] exact m.isCaratheodory_iUnion_of_disjoint (m.isCaratheodory_disjointed h) (disjoint_disjointed _) theorem f_iUnion {s : β„• β†’ Set Ξ±} (h : βˆ€ i, IsCaratheodory m (s i)) (hd : Pairwise (Disjoint on s)) : m (⋃ i, s i) = βˆ‘' i, m (s i) := by refine le_antisymm (measure_iUnion_le s) ?_ rw [ENNReal.tsum_eq_iSup_nat] refine iSup_le fun n => ?_ have := @isCaratheodory_sum _ m _ h hd univ n simp only [inter_comm, inter_univ, univ_inter] at this; simp only [this] exact m.mono (iUnionβ‚‚_subset fun i _ => subset_iUnion _ i) /-- The CarathΓ©odory-measurable sets for an outer measure `m` form a Dynkin system. -/ def caratheodoryDynkin : MeasurableSpace.DynkinSystem Ξ± where Has := IsCaratheodory m has_empty := isCaratheodory_empty m has_compl s := isCaratheodory_compl m s has_iUnion_nat _ hf hn := by apply isCaratheodory_iUnion m hf /-- Given an outer measure `ΞΌ`, the CarathΓ©odory-measurable space is defined such that `s` is measurable if `βˆ€t, ΞΌ t = ΞΌ (t ∩ s) + ΞΌ (t \ s)`. -/ protected def caratheodory : MeasurableSpace Ξ± := by apply MeasurableSpace.DynkinSystem.toMeasurableSpace (caratheodoryDynkin m) intro s₁ sβ‚‚ apply isCaratheodory_inter theorem isCaratheodory_iff {s : Set Ξ±} : MeasurableSet[OuterMeasure.caratheodory m] s ↔ βˆ€ t, m t = m (t ∩ s) + m (t \ s) := Iff.rfl theorem isCaratheodory_iff_le {s : Set Ξ±} : MeasurableSet[OuterMeasure.caratheodory m] s ↔ βˆ€ t, m (t ∩ s) + m (t \ s) ≀ m t := isCaratheodory_iff_le' m protected theorem iUnion_eq_of_caratheodory {s : β„• β†’ Set Ξ±} (h : βˆ€ i, MeasurableSet[OuterMeasure.caratheodory m] (s i)) (hd : Pairwise (Disjoint on s)) : m (⋃ i, s i) = βˆ‘' i, m (s i) := f_iUnion m h hd end CaratheodoryMeasurable variable {Ξ± : Type*} theorem ofFunction_caratheodory {m : Set Ξ± β†’ ℝβ‰₯0∞} {s : Set Ξ±} {hβ‚€ : m βˆ… = 0} (hs : βˆ€ t, m (t ∩ s) + m (t \ s) ≀ m t) : MeasurableSet[(OuterMeasure.ofFunction m hβ‚€).caratheodory] s := by apply (isCaratheodory_iff_le _).mpr refine fun t => le_iInf fun f => le_iInf fun hf => ?_ refine le_trans (add_le_add ((iInf_le_of_le fun i => f i ∩ s) <| iInf_le _ ?_) ((iInf_le_of_le fun i => f i \ s) <| iInf_le _ ?_)) ?_ Β· rw [← iUnion_inter] exact inter_subset_inter_left _ hf Β· rw [← iUnion_diff] exact diff_subset_diff_left hf Β· rw [← ENNReal.tsum_add] exact ENNReal.tsum_le_tsum fun i => hs _ theorem boundedBy_caratheodory {m : Set Ξ± β†’ ℝβ‰₯0∞} {s : Set Ξ±} (hs : βˆ€ t, m (t ∩ s) + m (t \ s) ≀ m t) : MeasurableSet[(boundedBy m).caratheodory] s := by apply ofFunction_caratheodory; intro t rcases t.eq_empty_or_nonempty with h | h Β· simp [h, Set.not_nonempty_empty] Β· convert le_trans _ (hs t) Β· simp [h] exact add_le_add iSup_const_le iSup_const_le @[simp] theorem zero_caratheodory : (0 : OuterMeasure Ξ±).caratheodory = ⊀ := top_unique fun _ _ _ => (add_zero _).symm theorem top_caratheodory : (⊀ : OuterMeasure Ξ±).caratheodory = ⊀ := top_unique fun s _ => (isCaratheodory_iff_le _).2 fun t => t.eq_empty_or_nonempty.elim (fun ht => by simp [ht]) fun ht => by simp only [ht, top_apply, le_top] theorem le_add_caratheodory (m₁ mβ‚‚ : OuterMeasure Ξ±) : m₁.caratheodory βŠ“ mβ‚‚.caratheodory ≀ (m₁ + mβ‚‚ : OuterMeasure Ξ±).caratheodory := fun s ⟨hs₁, hsβ‚‚βŸ© t => by simp [hs₁ t, hsβ‚‚ t, add_left_comm, add_assoc] theorem le_sum_caratheodory {ΞΉ} (m : ΞΉ β†’ OuterMeasure Ξ±) : β¨… i, (m i).caratheodory ≀ (sum m).caratheodory := fun s h t => by simp [fun i => MeasurableSpace.measurableSet_iInf.1 h i t, ENNReal.tsum_add]
theorem le_smul_caratheodory (a : ℝβ‰₯0∞) (m : OuterMeasure Ξ±) : m.caratheodory ≀ (a β€’ m).caratheodory := fun s h t => by simp only [smul_apply, smul_eq_mul] rw [(isCaratheodory_iff m).mp h t]
Mathlib/MeasureTheory/OuterMeasure/Caratheodory.lean
235
238
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Kenny Lau -/ import Mathlib.RingTheory.MvPowerSeries.Basic import Mathlib.Data.Finsupp.Interval import Mathlib.Algebra.MvPolynomial.Eval /-! # Formal (multivariate) power series - Truncation * `MvPowerSeries.trunc n Ο†` truncates a formal multivariate power series to the multivariate polynomial that has the same coefficients as `Ο†`, for all `m < n`, and `0` otherwise. Note that here, `m` and `n` have types `Οƒ β†’β‚€ β„•`, so that `m < n` means that `m β‰  n` and `m s ≀ n s` for all `s : Οƒ`. * `MvPowerSeries.trunc_one` : truncation of the unit power series * `MvPowerSeries.trunc_C` : truncation of a constant * `MvPowerSeries.trunc_C_mul` : truncation of constant multiple. * `MvPowerSeries.trunc' n Ο†` truncates a formal multivariate power series to the multivariate polynomial that has the same coefficients as `Ο†`, for all `m ≀ n`, and `0` otherwise. Here, `m` and `n` have types `Οƒ β†’β‚€ β„•` so that `m ≀ n` means that `m s ≀ n s` for all `s : Οƒ`. * `MvPowerSeries.coeff_mul_eq_coeff_trunc'_mul_trunc'` : compares the coefficients of a product with those of the product of truncations. * `MvPowerSeries.trunc'_one` : truncation of a the unit power series. * `MvPowerSeries.trunc'_C` : truncation of a constant. * `MvPowerSeries.trunc'_C_mul` : truncation of a constant multiple. * `MvPowerSeries.trunc'_map` : image of a truncation under a change of rings ## TODO * Unify both versions using a general purpose API -/ noncomputable section open Finset (antidiagonal mem_antidiagonal) namespace MvPowerSeries open Finsupp variable {Οƒ R S : Type*} section TruncLT variable [DecidableEq Οƒ] [CommSemiring R] (n : Οƒ β†’β‚€ β„•) /-- Auxiliary definition for the truncation function. -/ def truncFun (Ο† : MvPowerSeries Οƒ R) : MvPolynomial Οƒ R := βˆ‘ m ∈ Finset.Iio n, MvPolynomial.monomial m (coeff R m Ο†) theorem coeff_truncFun (m : Οƒ β†’β‚€ β„•) (Ο† : MvPowerSeries Οƒ R) : (truncFun n Ο†).coeff m = if m < n then coeff R m Ο† else 0 := by classical simp [truncFun, MvPolynomial.coeff_sum] variable (R) in /-- The `n`th truncation of a multivariate formal power series to a multivariate polynomial If `f : MvPowerSeries Οƒ R` and `n : Οƒ β†’β‚€ β„•` is a (finitely-supported) function from `Οƒ` to the naturals, then `trunc' R n f` is the multivariable power series obtained from `f` by keeping only the monomials $c\prod_i X_i^{a_i}$ where `a i ≀ n i` for all `i` and $a i < n i` for some `i`. -/ def trunc : MvPowerSeries Οƒ R β†’+ MvPolynomial Οƒ R where toFun := truncFun n map_zero' := by classical ext simp [coeff_truncFun] map_add' := by classical intros x y ext m simp only [coeff_truncFun, MvPolynomial.coeff_add, ite_add_ite, ← map_add, add_zero] theorem coeff_trunc (m : Οƒ β†’β‚€ β„•) (Ο† : MvPowerSeries Οƒ R) :
(trunc R n Ο†).coeff m = if m < n then coeff R m Ο† else 0 := by classical simp [trunc, coeff_truncFun] @[simp] theorem trunc_one (n : Οƒ β†’β‚€ β„•) (hnn : n β‰  0) : trunc R n 1 = 1 := MvPolynomial.ext _ _ fun m ↦ by
Mathlib/RingTheory/MvPowerSeries/Trunc.lean
96
101
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Gabriel Ebner -/ import Mathlib.Data.Int.Cast.Defs import Mathlib.Algebra.Group.Basic import Mathlib.Data.Nat.Basic /-! # Cast of integers (additional theorems) This file proves additional properties about the *canonical* homomorphism from the integers into an additive group with a one (`Int.cast`). There is also `Data.Int.Cast.Lemmas`, which includes lemmas stated in terms of algebraic homomorphisms, and results involving the order structure of `β„€`. By contrast, this file's only import beyond `Data.Int.Cast.Defs` is `Algebra.Group.Basic`. -/ universe u namespace Nat variable {R : Type u} [AddGroupWithOne R] @[simp, norm_cast] theorem cast_sub {m n} (h : m ≀ n) : ((n - m : β„•) : R) = n - m := eq_sub_of_add_eq <| by rw [← cast_add, Nat.sub_add_cancel h] -- `HasLiftT` appeared in the type signature @[simp, norm_cast] theorem cast_pred : βˆ€ {n}, 0 < n β†’ ((n - 1 : β„•) : R) = n - 1 | 0, h => by cases h | n + 1, _ => by rw [cast_succ, add_sub_cancel_right]; rfl end Nat open Nat namespace Int variable {R : Type u} [AddGroupWithOne R] -- TODO: I don't like that `norm_cast` is used here, because it results in `norm_cast` -- introducing the "implementation detail" `Int.negSucc`. @[simp, norm_cast squash] theorem cast_negSucc (n : β„•) : (-[n+1] : R) = -(n + 1 : β„•) := AddGroupWithOne.intCast_negSucc n -- expected `n` to be implicit, and `HasLiftT` @[simp, norm_cast] theorem cast_zero : ((0 : β„€) : R) = 0 := (AddGroupWithOne.intCast_ofNat 0).trans Nat.cast_zero -- type had `HasLiftT` -- This lemma competes with `Int.ofNat_eq_natCast` to come later @[simp high, nolint simpNF, norm_cast] theorem cast_natCast (n : β„•) : ((n : β„€) : R) = n := AddGroupWithOne.intCast_ofNat _ -- expected `n` to be implicit, and `HasLiftT` @[simp, norm_cast] theorem cast_ofNat (n : β„•) [n.AtLeastTwo] : ((ofNat(n) : β„€) : R) = ofNat(n) := by simpa only [OfNat.ofNat] using AddGroupWithOne.intCast_ofNat (R := R) n @[simp, norm_cast] theorem cast_one : ((1 : β„€) : R) = 1 := by rw [← Int.natCast_one, cast_natCast, Nat.cast_one] -- type had `HasLiftT` @[simp, norm_cast] theorem cast_neg : βˆ€ n, ((-n : β„€) : R) = -n | (0 : β„•) => by simp | (n + 1 : β„•) => by rw [cast_natCast, neg_ofNat_succ]; simp | -[n+1] => by rw [Int.neg_negSucc, cast_natCast]; simp -- type had `HasLiftT` @[simp, norm_cast] theorem cast_subNatNat (m n) : ((Int.subNatNat m n : β„€) : R) = m - n := by unfold subNatNat cases e : n - m Β· simp only [ofNat_eq_coe] simp [e, Nat.le_of_sub_eq_zero e] Β· rw [cast_negSucc, ← e, Nat.cast_sub <| _root_.le_of_lt <| Nat.lt_of_sub_eq_succ e, neg_sub] -- type had `HasLiftT` @[simp] theorem cast_negOfNat (n : β„•) : ((negOfNat n : β„€) : R) = -n := by simp [Int.cast_neg, negOfNat_eq] @[simp, norm_cast] theorem cast_add : βˆ€ m n, ((m + n : β„€) : R) = m + n | (m : β„•), (n : β„•) => by simp [← Int.natCast_add] | (m : β„•), -[n+1] => by erw [cast_subNatNat, cast_natCast, cast_negSucc, sub_eq_add_neg] | -[m+1], (n : β„•) => by #adaptation_note /-- `_root_` can be removed again after https://github.com/leanprover/lean4/pull/7359 lands in nightly-2025-03-06. -/ erw [cast_subNatNat, cast_natCast, cast_negSucc, _root_.sub_eq_iff_eq_add, add_assoc, eq_neg_add_iff_add_eq, ← Nat.cast_add, ← Nat.cast_add, Nat.add_comm] | -[m+1], -[n+1] => show (-[m + n + 1+1] : R) = _ by rw [cast_negSucc, cast_negSucc, cast_negSucc, ← neg_add_rev, ← Nat.cast_add, Nat.add_right_comm m n 1, Nat.add_assoc, Nat.add_comm] -- type had `HasLiftT` @[simp, norm_cast] theorem cast_sub (m n) : ((m - n : β„€) : R) = m - n := by simp [Int.sub_eq_add_neg, sub_eq_add_neg, Int.cast_neg, Int.cast_add] -- type had `HasLiftT` theorem cast_two : ((2 : β„€) : R) = 2 := cast_ofNat _ theorem cast_three : ((3 : β„€) : R) = 3 := cast_ofNat _ theorem cast_four : ((4 : β„€) : R) = 4 := cast_ofNat _ end Int section zsmul variable {R : Type*} @[simp] lemma zsmul_one [AddGroupWithOne R] (n : β„€) : n β€’ (1 : R) = n := by cases n <;> simp end zsmul
Mathlib/Data/Int/Cast/Basic.lean
137
138
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Johannes HΓΆlzl, Yury Kudryashov, Patrick Massot -/ import Mathlib.Algebra.GeomSum import Mathlib.Order.Filter.AtTopBot.Archimedean import Mathlib.Order.Iterate import Mathlib.Topology.Algebra.Algebra import Mathlib.Topology.Algebra.InfiniteSum.Real import Mathlib.Topology.Instances.EReal.Lemmas /-! # A collection of specific limit computations This file, by design, is independent of `NormedSpace` in the import hierarchy. It contains important specific limit computations in metric spaces, in ordered rings/fields, and in specific instances of these such as `ℝ`, `ℝβ‰₯0` and `ℝβ‰₯0∞`. -/ assert_not_exists Basis NormedSpace noncomputable section open Set Function Filter Finset Metric Topology Nat uniformity NNReal ENNReal variable {Ξ± : Type*} {Ξ² : Type*} {ΞΉ : Type*} theorem tendsto_inverse_atTop_nhds_zero_nat : Tendsto (fun n : β„• ↦ (n : ℝ)⁻¹) atTop (𝓝 0) := tendsto_inv_atTop_zero.comp tendsto_natCast_atTop_atTop theorem tendsto_const_div_atTop_nhds_zero_nat (C : ℝ) : Tendsto (fun n : β„• ↦ C / n) atTop (𝓝 0) := by simpa only [mul_zero] using tendsto_const_nhds.mul tendsto_inverse_atTop_nhds_zero_nat theorem tendsto_one_div_atTop_nhds_zero_nat : Tendsto (fun n : β„• ↦ 1/(n : ℝ)) atTop (𝓝 0) := tendsto_const_div_atTop_nhds_zero_nat 1 theorem NNReal.tendsto_inverse_atTop_nhds_zero_nat : Tendsto (fun n : β„• ↦ (n : ℝβ‰₯0)⁻¹) atTop (𝓝 0) := by rw [← NNReal.tendsto_coe] exact _root_.tendsto_inverse_atTop_nhds_zero_nat theorem NNReal.tendsto_const_div_atTop_nhds_zero_nat (C : ℝβ‰₯0) : Tendsto (fun n : β„• ↦ C / n) atTop (𝓝 0) := by simpa using tendsto_const_nhds.mul NNReal.tendsto_inverse_atTop_nhds_zero_nat theorem EReal.tendsto_const_div_atTop_nhds_zero_nat {C : EReal} (h : C β‰  βŠ₯) (h' : C β‰  ⊀) : Tendsto (fun n : β„• ↦ C / n) atTop (𝓝 0) := by have : (fun n : β„• ↦ C / n) = fun n : β„• ↦ ((C.toReal / n : ℝ) : EReal) := by ext n nth_rw 1 [← coe_toReal h' h, ← coe_coe_eq_natCast n, ← coe_div C.toReal n] rw [this, ← coe_zero, tendsto_coe] exact _root_.tendsto_const_div_atTop_nhds_zero_nat C.toReal theorem tendsto_one_div_add_atTop_nhds_zero_nat : Tendsto (fun n : β„• ↦ 1 / ((n : ℝ) + 1)) atTop (𝓝 0) := suffices Tendsto (fun n : β„• ↦ 1 / (↑(n + 1) : ℝ)) atTop (𝓝 0) by simpa (tendsto_add_atTop_iff_nat 1).2 (_root_.tendsto_const_div_atTop_nhds_zero_nat 1) theorem NNReal.tendsto_algebraMap_inverse_atTop_nhds_zero_nat (π•œ : Type*) [Semiring π•œ] [Algebra ℝβ‰₯0 π•œ] [TopologicalSpace π•œ] [ContinuousSMul ℝβ‰₯0 π•œ] : Tendsto (algebraMap ℝβ‰₯0 π•œ ∘ fun n : β„• ↦ (n : ℝβ‰₯0)⁻¹) atTop (𝓝 0) := by convert (continuous_algebraMap ℝβ‰₯0 π•œ).continuousAt.tendsto.comp tendsto_inverse_atTop_nhds_zero_nat rw [map_zero] theorem tendsto_algebraMap_inverse_atTop_nhds_zero_nat (π•œ : Type*) [Semiring π•œ] [Algebra ℝ π•œ] [TopologicalSpace π•œ] [ContinuousSMul ℝ π•œ] : Tendsto (algebraMap ℝ π•œ ∘ fun n : β„• ↦ (n : ℝ)⁻¹) atTop (𝓝 0) := NNReal.tendsto_algebraMap_inverse_atTop_nhds_zero_nat π•œ /-- The limit of `n / (n + x)` is 1, for any constant `x` (valid in `ℝ` or any topological division algebra over `ℝ`, e.g., `β„‚`). TODO: introduce a typeclass saying that `1 / n` tends to 0 at top, making it possible to get this statement simultaneously on `β„š`, `ℝ` and `β„‚`. -/ theorem tendsto_natCast_div_add_atTop {π•œ : Type*} [DivisionRing π•œ] [TopologicalSpace π•œ] [CharZero π•œ] [Algebra ℝ π•œ] [ContinuousSMul ℝ π•œ] [IsTopologicalDivisionRing π•œ] (x : π•œ) : Tendsto (fun n : β„• ↦ (n : π•œ) / (n + x)) atTop (𝓝 1) := by convert Tendsto.congr' ((eventually_ne_atTop 0).mp (Eventually.of_forall fun n hn ↦ _)) _ Β· exact fun n : β„• ↦ 1 / (1 + x / n) Β· field_simp [Nat.cast_ne_zero.mpr hn] Β· have : 𝓝 (1 : π•œ) = 𝓝 (1 / (1 + x * (0 : π•œ))) := by rw [mul_zero, add_zero, div_one] rw [this] refine tendsto_const_nhds.div (tendsto_const_nhds.add ?_) (by simp) simp_rw [div_eq_mul_inv] refine tendsto_const_nhds.mul ?_ have := ((continuous_algebraMap ℝ π•œ).tendsto _).comp tendsto_inverse_atTop_nhds_zero_nat rw [map_zero, Filter.tendsto_atTop'] at this refine Iff.mpr tendsto_atTop' ?_ intros simp_all only [comp_apply, map_invβ‚€, map_natCast] /-- For any positive `m : β„•`, `((n % m : β„•) : ℝ) / (n : ℝ)` tends to `0` as `n` tends to `∞`. -/ theorem tendsto_mod_div_atTop_nhds_zero_nat {m : β„•} (hm : 0 < m) : Tendsto (fun n : β„• => ((n % m : β„•) : ℝ) / (n : ℝ)) atTop (𝓝 0) := by have h0 : βˆ€αΆ  n : β„• in atTop, 0 ≀ (fun n : β„• => ((n % m : β„•) : ℝ)) n := by aesop exact tendsto_bdd_div_atTop_nhds_zero h0 (.of_forall (fun n ↦ cast_le.mpr (mod_lt n hm).le)) tendsto_natCast_atTop_atTop theorem Filter.EventuallyEq.div_mul_cancel {Ξ± G : Type*} [GroupWithZero G] {f g : Ξ± β†’ G} {l : Filter Ξ±} (hg : Tendsto g l (π“Ÿ {0}ᢜ)) : (fun x ↦ f x / g x * g x) =αΆ [l] fun x ↦ f x := by filter_upwards [hg.le_comap <| preimage_mem_comap (m := g) (mem_principal_self {0}ᢜ)] with x hx aesop /-- If `g` tends to `∞`, then eventually for all `x` we have `(f x / g x) * g x = f x`. -/ theorem Filter.EventuallyEq.div_mul_cancel_atTop {Ξ± K : Type*} [Semifield K] [LinearOrder K] [IsStrictOrderedRing K] {f g : Ξ± β†’ K} {l : Filter Ξ±} (hg : Tendsto g l atTop) : (fun x ↦ f x / g x * g x) =αΆ [l] fun x ↦ f x := div_mul_cancel <| hg.mono_right <| le_principal_iff.mpr <| mem_of_superset (Ioi_mem_atTop 0) <| by simp /-- If when `x` tends to `∞`, `g` tends to `∞` and `f x / g x` tends to a positive constant, then `f` tends to `∞`. -/ theorem Tendsto.num {Ξ± K : Type*} [Field K] [LinearOrder K] [IsStrictOrderedRing K] [TopologicalSpace K] [OrderTopology K] {f g : Ξ± β†’ K} {l : Filter Ξ±} (hg : Tendsto g l atTop) {a : K} (ha : 0 < a) (hlim : Tendsto (fun x => f x / g x) l (𝓝 a)) : Tendsto f l atTop := (hlim.pos_mul_atTop ha hg).congr' (EventuallyEq.div_mul_cancel_atTop hg) /-- If when `x` tends to `∞`, `g` tends to `∞` and `f x / g x` tends to a positive constant, then `f` tends to `∞`. -/ theorem Tendsto.den {Ξ± K : Type*} [Field K] [LinearOrder K] [IsStrictOrderedRing K] [TopologicalSpace K] [OrderTopology K] [ContinuousInv K] {f g : Ξ± β†’ K} {l : Filter Ξ±} (hf : Tendsto f l atTop) {a : K} (ha : 0 < a) (hlim : Tendsto (fun x => f x / g x) l (𝓝 a)) : Tendsto g l atTop := have hlim' : Tendsto (fun x => g x / f x) l (𝓝 a⁻¹) := by simp_rw [← inv_div (f _)] exact Filter.Tendsto.inv (f := fun x => f x / g x) hlim (hlim'.pos_mul_atTop (inv_pos_of_pos ha) hf).congr' (.div_mul_cancel_atTop hf) /-- If when `x` tends to `∞`, `f x / g x` tends to a positive constant, then `f` tends to `∞` if and only if `g` tends to `∞`. -/ theorem Tendsto.num_atTop_iff_den_atTop {Ξ± K : Type*} [Field K] [LinearOrder K] [IsStrictOrderedRing K] [TopologicalSpace K] [OrderTopology K] [ContinuousInv K] {f g : Ξ± β†’ K} {l : Filter Ξ±} {a : K} (ha : 0 < a) (hlim : Tendsto (fun x => f x / g x) l (𝓝 a)) : Tendsto f l atTop ↔ Tendsto g l atTop := ⟨fun hf ↦ Tendsto.den hf ha hlim, fun hg ↦ Tendsto.num hg ha hlim⟩ /-! ### Powers -/ theorem tendsto_add_one_pow_atTop_atTop_of_pos [Semiring Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] [Archimedean Ξ±] {r : Ξ±} (h : 0 < r) : Tendsto (fun n : β„• ↦ (r + 1) ^ n) atTop atTop := tendsto_atTop_atTop_of_monotone' (pow_right_monoβ‚€ <| le_add_of_nonneg_left h.le) <| not_bddAbove_iff.2 fun _ ↦ Set.exists_range_iff.2 <| add_one_pow_unbounded_of_pos _ h theorem tendsto_pow_atTop_atTop_of_one_lt [Ring Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] [Archimedean Ξ±] {r : Ξ±} (h : 1 < r) : Tendsto (fun n : β„• ↦ r ^ n) atTop atTop := sub_add_cancel r 1 β–Έ tendsto_add_one_pow_atTop_atTop_of_pos (sub_pos.2 h) theorem Nat.tendsto_pow_atTop_atTop_of_one_lt {m : β„•} (h : 1 < m) : Tendsto (fun n : β„• ↦ m ^ n) atTop atTop := tsub_add_cancel_of_le (le_of_lt h) β–Έ tendsto_add_one_pow_atTop_atTop_of_pos (tsub_pos_of_lt h) theorem tendsto_pow_atTop_nhds_zero_of_lt_one {π•œ : Type*} [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [Archimedean π•œ] [TopologicalSpace π•œ] [OrderTopology π•œ] {r : π•œ} (h₁ : 0 ≀ r) (hβ‚‚ : r < 1) : Tendsto (fun n : β„• ↦ r ^ n) atTop (𝓝 0) := h₁.eq_or_lt.elim (fun hr ↦ (tendsto_add_atTop_iff_nat 1).mp <| by simp [_root_.pow_succ, ← hr, tendsto_const_nhds]) (fun hr ↦ have := (one_lt_invβ‚€ hr).2 hβ‚‚ |> tendsto_pow_atTop_atTop_of_one_lt (tendsto_inv_atTop_zero.comp this).congr fun n ↦ by simp) @[simp] theorem tendsto_pow_atTop_nhds_zero_iff {π•œ : Type*} [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [Archimedean π•œ] [TopologicalSpace π•œ] [OrderTopology π•œ] {r : π•œ} : Tendsto (fun n : β„• ↦ r ^ n) atTop (𝓝 0) ↔ |r| < 1 := by rw [tendsto_zero_iff_abs_tendsto_zero] refine ⟨fun h ↦ by_contra (fun hr_le ↦ ?_), fun h ↦ ?_⟩ Β· by_cases hr : 1 = |r| Β· replace h : Tendsto (fun n : β„• ↦ |r|^n) atTop (𝓝 0) := by simpa only [← abs_pow, h] simp only [hr.symm, one_pow] at h exact zero_ne_one <| tendsto_nhds_unique h tendsto_const_nhds Β· apply @not_tendsto_nhds_of_tendsto_atTop π•œ β„• _ _ _ _ atTop _ (fun n ↦ |r| ^ n) _ 0 _ Β· refine (pow_right_strictMonoβ‚€ <| lt_of_le_of_ne (le_of_not_lt hr_le) hr).monotone.tendsto_atTop_atTop (fun b ↦ ?_) obtain ⟨n, hn⟩ := (pow_unbounded_of_one_lt b (lt_of_le_of_ne (le_of_not_lt hr_le) hr)) exact ⟨n, le_of_lt hn⟩ Β· simpa only [← abs_pow] Β· simpa only [← abs_pow] using (tendsto_pow_atTop_nhds_zero_of_lt_one (abs_nonneg r)) h theorem tendsto_pow_atTop_nhdsWithin_zero_of_lt_one {π•œ : Type*} [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [Archimedean π•œ] [TopologicalSpace π•œ] [OrderTopology π•œ] {r : π•œ} (h₁ : 0 < r) (hβ‚‚ : r < 1) : Tendsto (fun n : β„• ↦ r ^ n) atTop (𝓝[>] 0) := tendsto_inf.2 ⟨tendsto_pow_atTop_nhds_zero_of_lt_one h₁.le hβ‚‚, tendsto_principal.2 <| Eventually.of_forall fun _ ↦ pow_pos h₁ _⟩ theorem uniformity_basis_dist_pow_of_lt_one {Ξ± : Type*} [PseudoMetricSpace Ξ±] {r : ℝ} (hβ‚€ : 0 < r) (h₁ : r < 1) : (uniformity Ξ±).HasBasis (fun _ : β„• ↦ True) fun k ↦ { p : Ξ± Γ— Ξ± | dist p.1 p.2 < r ^ k } := Metric.mk_uniformity_basis (fun _ _ ↦ pow_pos hβ‚€ _) fun _ Ξ΅0 ↦ (exists_pow_lt_of_lt_one Ξ΅0 h₁).imp fun _ hk ↦ ⟨trivial, hk.le⟩ theorem geom_lt {u : β„• β†’ ℝ} {c : ℝ} (hc : 0 ≀ c) {n : β„•} (hn : 0 < n) (h : βˆ€ k < n, c * u k < u (k + 1)) : c ^ n * u 0 < u n := by apply (monotone_mul_left_of_nonneg hc).seq_pos_lt_seq_of_le_of_lt hn _ _ h Β· simp Β· simp [_root_.pow_succ', mul_assoc, le_refl] theorem geom_le {u : β„• β†’ ℝ} {c : ℝ} (hc : 0 ≀ c) (n : β„•) (h : βˆ€ k < n, c * u k ≀ u (k + 1)) : c ^ n * u 0 ≀ u n := by apply (monotone_mul_left_of_nonneg hc).seq_le_seq n _ _ h <;> simp [_root_.pow_succ', mul_assoc, le_refl] theorem lt_geom {u : β„• β†’ ℝ} {c : ℝ} (hc : 0 ≀ c) {n : β„•} (hn : 0 < n) (h : βˆ€ k < n, u (k + 1) < c * u k) : u n < c ^ n * u 0 := by apply (monotone_mul_left_of_nonneg hc).seq_pos_lt_seq_of_lt_of_le hn _ h _ Β· simp Β· simp [_root_.pow_succ', mul_assoc, le_refl] theorem le_geom {u : β„• β†’ ℝ} {c : ℝ} (hc : 0 ≀ c) (n : β„•) (h : βˆ€ k < n, u (k + 1) ≀ c * u k) : u n ≀ c ^ n * u 0 := by apply (monotone_mul_left_of_nonneg hc).seq_le_seq n _ h _ <;> simp [_root_.pow_succ', mul_assoc, le_refl] /-- If a sequence `v` of real numbers satisfies `k * v n ≀ v (n+1)` with `1 < k`, then it goes to +∞. -/ theorem tendsto_atTop_of_geom_le {v : β„• β†’ ℝ} {c : ℝ} (hβ‚€ : 0 < v 0) (hc : 1 < c) (hu : βˆ€ n, c * v n ≀ v (n + 1)) : Tendsto v atTop atTop := (tendsto_atTop_mono fun n ↦ geom_le (zero_le_one.trans hc.le) n fun k _ ↦ hu k) <| (tendsto_pow_atTop_atTop_of_one_lt hc).atTop_mul_const hβ‚€ theorem NNReal.tendsto_pow_atTop_nhds_zero_of_lt_one {r : ℝβ‰₯0} (hr : r < 1) : Tendsto (fun n : β„• ↦ r ^ n) atTop (𝓝 0) := NNReal.tendsto_coe.1 <| by simp only [NNReal.coe_pow, NNReal.coe_zero, _root_.tendsto_pow_atTop_nhds_zero_of_lt_one r.coe_nonneg hr] @[simp] protected theorem NNReal.tendsto_pow_atTop_nhds_zero_iff {r : ℝβ‰₯0} : Tendsto (fun n : β„• => r ^ n) atTop (𝓝 0) ↔ r < 1 := ⟨fun h => by simpa [coe_pow, coe_zero, abs_eq, coe_lt_one, val_eq_coe] using tendsto_pow_atTop_nhds_zero_iff.mp <| tendsto_coe.mpr h, tendsto_pow_atTop_nhds_zero_of_lt_one⟩ theorem ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one {r : ℝβ‰₯0∞} (hr : r < 1) : Tendsto (fun n : β„• ↦ r ^ n) atTop (𝓝 0) := by rcases ENNReal.lt_iff_exists_coe.1 hr with ⟨r, rfl, hr'⟩ rw [← ENNReal.coe_zero] norm_cast at * apply NNReal.tendsto_pow_atTop_nhds_zero_of_lt_one hr @[simp] protected theorem ENNReal.tendsto_pow_atTop_nhds_zero_iff {r : ℝβ‰₯0∞} : Tendsto (fun n : β„• => r ^ n) atTop (𝓝 0) ↔ r < 1 := by refine ⟨fun h ↦ ?_, tendsto_pow_atTop_nhds_zero_of_lt_one⟩ lift r to NNReal Β· refine fun hr ↦ top_ne_zero (tendsto_nhds_unique (EventuallyEq.tendsto ?_) (hr β–Έ h)) exact eventually_atTop.mpr ⟨1, fun _ hn ↦ pow_eq_top_iff.mpr ⟨rfl, Nat.pos_iff_ne_zero.mp hn⟩⟩ rw [← coe_zero] at h norm_cast at h ⊒ exact NNReal.tendsto_pow_atTop_nhds_zero_iff.mp h @[simp] protected theorem ENNReal.tendsto_pow_atTop_nhds_top_iff {r : ℝβ‰₯0∞} : Tendsto (fun n ↦ r^n) atTop (𝓝 ∞) ↔ 1 < r := by refine ⟨?_, ?_⟩ Β· contrapose! intro r_le_one h_tends specialize h_tends (Ioi_mem_nhds one_lt_top) simp only [Filter.mem_map, mem_atTop_sets, ge_iff_le, Set.mem_preimage, Set.mem_Ioi] at h_tends obtain ⟨n, hn⟩ := h_tends exact lt_irrefl _ <| lt_of_lt_of_le (hn n le_rfl) <| pow_le_oneβ‚€ (zero_le _) r_le_one Β· intro r_gt_one have obs := @Tendsto.inv ℝβ‰₯0∞ β„• _ _ _ (fun n ↦ (r⁻¹)^n) atTop 0 simp only [ENNReal.tendsto_pow_atTop_nhds_zero_iff, inv_zero] at obs simpa [← ENNReal.inv_pow] using obs <| ENNReal.inv_lt_one.mpr r_gt_one lemma ENNReal.eq_zero_of_le_mul_pow {x r : ℝβ‰₯0∞} {Ξ΅ : ℝβ‰₯0} (hr : r < 1) (h : βˆ€ n : β„•, x ≀ Ξ΅ * r ^ n) : x = 0 := by rw [← nonpos_iff_eq_zero] refine ge_of_tendsto' (f := fun (n : β„•) ↦ Ξ΅ * r ^ n) (x := atTop) ?_ h rw [← mul_zero (Mβ‚€ := ℝβ‰₯0∞) (a := Ξ΅)] exact Tendsto.const_mul (tendsto_pow_atTop_nhds_zero_of_lt_one hr) (Or.inr coe_ne_top) /-! ### Geometric series -/ section Geometric theorem hasSum_geometric_of_lt_one {r : ℝ} (h₁ : 0 ≀ r) (hβ‚‚ : r < 1) : HasSum (fun n : β„• ↦ r ^ n) (1 - r)⁻¹ := have : r β‰  1 := ne_of_lt hβ‚‚ have : Tendsto (fun n ↦ (r ^ n - 1) * (r - 1)⁻¹) atTop (𝓝 ((0 - 1) * (r - 1)⁻¹)) := ((tendsto_pow_atTop_nhds_zero_of_lt_one h₁ hβ‚‚).sub tendsto_const_nhds).mul tendsto_const_nhds (hasSum_iff_tendsto_nat_of_nonneg (pow_nonneg h₁) _).mpr <| by simp_all [neg_inv, geom_sum_eq, div_eq_mul_inv] theorem summable_geometric_of_lt_one {r : ℝ} (h₁ : 0 ≀ r) (hβ‚‚ : r < 1) : Summable fun n : β„• ↦ r ^ n := ⟨_, hasSum_geometric_of_lt_one h₁ hβ‚‚βŸ© theorem tsum_geometric_of_lt_one {r : ℝ} (h₁ : 0 ≀ r) (hβ‚‚ : r < 1) : βˆ‘' n : β„•, r ^ n = (1 - r)⁻¹ := (hasSum_geometric_of_lt_one h₁ hβ‚‚).tsum_eq theorem hasSum_geometric_two : HasSum (fun n : β„• ↦ ((1 : ℝ) / 2) ^ n) 2 := by convert hasSum_geometric_of_lt_one _ _ <;> norm_num theorem summable_geometric_two : Summable fun n : β„• ↦ ((1 : ℝ) / 2) ^ n := ⟨_, hasSum_geometric_two⟩ theorem summable_geometric_two_encode {ΞΉ : Type*} [Encodable ΞΉ] : Summable fun i : ΞΉ ↦ (1 / 2 : ℝ) ^ Encodable.encode i := summable_geometric_two.comp_injective Encodable.encode_injective theorem tsum_geometric_two : (βˆ‘' n : β„•, ((1 : ℝ) / 2) ^ n) = 2 := hasSum_geometric_two.tsum_eq theorem sum_geometric_two_le (n : β„•) : (βˆ‘ i ∈ range n, (1 / (2 : ℝ)) ^ i) ≀ 2 := by have : βˆ€ i, 0 ≀ (1 / (2 : ℝ)) ^ i := by intro i apply pow_nonneg norm_num convert summable_geometric_two.sum_le_tsum (range n) (fun i _ ↦ this i) exact tsum_geometric_two.symm
theorem tsum_geometric_inv_two : (βˆ‘' n : β„•, (2 : ℝ)⁻¹ ^ n) = 2 := (inv_eq_one_div (2 : ℝ)).symm β–Έ tsum_geometric_two /-- The sum of `2⁻¹ ^ i` for `n ≀ i` equals `2 * 2⁻¹ ^ n`. -/ theorem tsum_geometric_inv_two_ge (n : β„•) : (βˆ‘' i, ite (n ≀ i) ((2 : ℝ)⁻¹ ^ i) 0) = 2 * 2⁻¹ ^ n := by have A : Summable fun i : β„• ↦ ite (n ≀ i) ((2⁻¹ : ℝ) ^ i) 0 := by
Mathlib/Analysis/SpecificLimits/Basic.lean
329
335
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Algebra.BigOperators.Field import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`. -/ @[pp_nodot] noncomputable def logb (b x : ℝ) : ℝ := log x / log b theorem log_div_log : log x / log b = logb b x := rfl @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] theorem logb_zero_left : logb 0 x = 0 := by simp only [← log_div_log, log_zero, div_zero] @[simp] theorem logb_zero_left_eq_zero : logb 0 = 0 := by ext; rw [logb_zero_left, Pi.zero_apply] theorem logb_one_left : logb 1 x = 0 := by simp only [← log_div_log, log_one, div_zero] @[simp] theorem logb_one_left_eq_zero : logb 1 = 0 := by ext; rw [logb_one_left, Pi.zero_apply] @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] theorem logb_div (hx : x β‰  0) (hy : y β‰  0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div] theorem inv_logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_mul h₁ hβ‚‚ theorem inv_logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_div h₁ hβ‚‚ theorem logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_mul_base h₁ hβ‚‚ c, inv_inv] theorem logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a / b) c = ((logb a c)⁻¹ - (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_div_base h₁ hβ‚‚ c, inv_inv] theorem mul_logb {a b c : ℝ} (h₁ : b β‰  0) (hβ‚‚ : b β‰  1) (h₃ : b β‰  -1) : logb a b * logb b c = logb a c := by unfold logb rw [mul_comm, div_mul_div_cancelβ‚€ (log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ©)] theorem div_logb {a b c : ℝ} (h₁ : c β‰  0) (hβ‚‚ : c β‰  1) (h₃ : c β‰  -1) : logb a c / logb b c = logb a b := div_div_div_cancel_left' _ _ <| log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ© theorem logb_rpow_eq_mul_logb_of_pos (hx : 0 < x) : logb b (x ^ y) = y * logb b x := by rw [logb, log_rpow hx, logb, mul_div_assoc] theorem logb_pow (b x : ℝ) (k : β„•) : logb b (x ^ k) = k * logb b x := by rw [logb, logb, log_pow, mul_div_assoc] section BPosAndNeOne variable (b_pos : 0 < b) (b_ne_one : b β‰  1) include b_pos b_ne_one private theorem log_b_ne_zero : log b β‰  0 := by have b_ne_zero : b β‰  0 := by linarith have b_ne_minus_one : b β‰  -1 := by linarith simp [b_ne_one, b_ne_zero, b_ne_minus_one] @[simp] theorem logb_rpow : logb b (b ^ x) = x := by rw [logb, div_eq_iff, log_rpow b_pos] exact log_b_ne_zero b_pos b_ne_one theorem rpow_logb_eq_abs (hx : x β‰  0) : b ^ logb b x = |x| := by apply log_injOn_pos Β· simp only [Set.mem_Ioi] apply rpow_pos_of_pos b_pos Β· simp only [abs_pos, mem_Ioi, Ne, hx, not_false_iff] rw [log_rpow b_pos, logb, log_abs] field_simp [log_b_ne_zero b_pos b_ne_one] @[simp] theorem rpow_logb (hx : 0 < x) : b ^ logb b x = x := by rw [rpow_logb_eq_abs b_pos b_ne_one hx.ne'] exact abs_of_pos hx theorem rpow_logb_of_neg (hx : x < 0) : b ^ logb b x = -x := by rw [rpow_logb_eq_abs b_pos b_ne_one (ne_of_lt hx)] exact abs_of_neg hx theorem logb_eq_iff_rpow_eq (hy : 0 < y) : logb b y = x ↔ b ^ x = y := by constructor <;> rintro rfl Β· exact rpow_logb b_pos b_ne_one hy Β· exact logb_rpow b_pos b_ne_one theorem surjOn_logb : SurjOn (logb b) (Ioi 0) univ := fun x _ => ⟨b ^ x, rpow_pos_of_pos b_pos x, logb_rpow b_pos b_ne_one⟩ theorem logb_surjective : Surjective (logb b) := fun x => ⟨b ^ x, logb_rpow b_pos b_ne_one⟩ @[simp] theorem range_logb : range (logb b) = univ := (logb_surjective b_pos b_ne_one).range_eq theorem surjOn_logb' : SurjOn (logb b) (Iio 0) univ := by intro x _ use -b ^ x constructor Β· simp only [Right.neg_neg_iff, Set.mem_Iio] apply rpow_pos_of_pos b_pos Β· rw [logb_neg_eq_logb, logb_rpow b_pos b_ne_one] end BPosAndNeOne section OneLtB variable (hb : 1 < b) include hb
private theorem b_pos : 0 < b := by linarith -- Name has a prime added to avoid clashing with `b_ne_one` further down the file private theorem b_ne_one' : b β‰  1 := by linarith @[simp] theorem logb_le_logb (h : 0 < x) (h₁ : 0 < y) : logb b x ≀ logb b y ↔ x ≀ y := by
Mathlib/Analysis/SpecialFunctions/Log/Base.lean
174
180
/- Copyright (c) 2023 Adam Topaz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Adam Topaz -/ import Mathlib.CategoryTheory.Limits.Shapes.Products /-! # Effective epimorphisms We define the notion of effective epimorphism and effective epimorphic family of morphisms. A morphism is an *effective epi* if it is a joint coequalizer of all pairs of morphisms which it coequalizes. A family of morphisms with fixed target is *effective epimorphic* if it is initial among families of morphisms with its sources and a general fixed target, coequalizing every pair of morphisms it coequalizes (here, the pair of morphisms coequalized can have different targets among the sources of the family). We have defined the notion of effective epi for morphisms and families of morphisms in such a way that avoids requiring the existence of pullbacks. However, if the relevant pullbacks exist then these definitions are equivalent, see the file `CategoryTheory/EffectiveEpi/RegularEpi.lean` See [nlab: *Effective Epimorphism*](https://ncatlab.org/nlab/show/effective+epimorphism) and [Stacks 00WP](https://stacks.math.columbia.edu/tag/00WP) for the standard definitions. Note that our notion of `EffectiveEpi` is often called "strict epi" in the literature. ## References - [Elephant]: *Sketches of an Elephant*, P. T. Johnstone: C2.1, Example 2.1.12. - [nlab: *Effective Epimorphism*](https://ncatlab.org/nlab/show/effective+epimorphism) and - [Stacks 00WP](https://stacks.math.columbia.edu/tag/00WP) for the standard definitions. -/ namespace CategoryTheory open Limits variable {C : Type*} [Category C] /-- This structure encodes the data required for a morphism to be an effective epimorphism. -/ structure EffectiveEpiStruct {X Y : C} (f : Y ⟢ X) where /-- For every `W` with a morphism `e : Y ⟢ W` that coequalizes every pair of morphisms `g₁ gβ‚‚ : Z ⟢ Y` which `f` coequalizes, `desc e h` is a morphism `X ⟢ W`... -/ desc : βˆ€ {W : C} (e : Y ⟢ W), (βˆ€ {Z : C} (g₁ gβ‚‚ : Z ⟢ Y), g₁ ≫ f = gβ‚‚ ≫ f β†’ g₁ ≫ e = gβ‚‚ ≫ e) β†’ (X ⟢ W) /-- ...factorizing `e` through `f`... -/ fac : βˆ€ {W : C} (e : Y ⟢ W) (h : βˆ€ {Z : C} (g₁ gβ‚‚ : Z ⟢ Y), g₁ ≫ f = gβ‚‚ ≫ f β†’ g₁ ≫ e = gβ‚‚ ≫ e), f ≫ desc e h = e /-- ...and as such, unique. -/ uniq : βˆ€ {W : C} (e : Y ⟢ W) (h : βˆ€ {Z : C} (g₁ gβ‚‚ : Z ⟢ Y), g₁ ≫ f = gβ‚‚ ≫ f β†’ g₁ ≫ e = gβ‚‚ ≫ e) (m : X ⟢ W), f ≫ m = e β†’ m = desc e h /-- A morphism `f : Y ⟢ X` is an effective epimorphism provided that `f` exhibits `X` as a colimit of the diagram of all "relations" `R ⇉ Y`. If `f` has a kernel pair, then this is equivalent to showing that the corresponding cofork is a colimit. -/ class EffectiveEpi {X Y : C} (f : Y ⟢ X) : Prop where /-- `f` is an effective epimorphism if there exists an `EffectiveEpiStruct` for `f`. -/ effectiveEpi : Nonempty (EffectiveEpiStruct f) /-- Some chosen `EffectiveEpiStruct` associated to an effective epi. -/ noncomputable def EffectiveEpi.getStruct {X Y : C} (f : Y ⟢ X) [EffectiveEpi f] : EffectiveEpiStruct f := EffectiveEpi.effectiveEpi.some /-- Descend along an effective epi. -/ noncomputable def EffectiveEpi.desc {X Y W : C} (f : Y ⟢ X) [EffectiveEpi f] (e : Y ⟢ W) (h : βˆ€ {Z : C} (g₁ gβ‚‚ : Z ⟢ Y), g₁ ≫ f = gβ‚‚ ≫ f β†’ g₁ ≫ e = gβ‚‚ ≫ e) : X ⟢ W := (EffectiveEpi.getStruct f).desc e h @[reassoc (attr := simp)] lemma EffectiveEpi.fac {X Y W : C} (f : Y ⟢ X) [EffectiveEpi f] (e : Y ⟢ W) (h : βˆ€ {Z : C} (g₁ gβ‚‚ : Z ⟢ Y), g₁ ≫ f = gβ‚‚ ≫ f β†’ g₁ ≫ e = gβ‚‚ ≫ e) : f ≫ EffectiveEpi.desc f e h = e := (EffectiveEpi.getStruct f).fac e h lemma EffectiveEpi.uniq {X Y W : C} (f : Y ⟢ X) [EffectiveEpi f] (e : Y ⟢ W) (h : βˆ€ {Z : C} (g₁ gβ‚‚ : Z ⟢ Y), g₁ ≫ f = gβ‚‚ ≫ f β†’ g₁ ≫ e = gβ‚‚ ≫ e) (m : X ⟢ W) (hm : f ≫ m = e) : m = EffectiveEpi.desc f e h := (EffectiveEpi.getStruct f).uniq e h _ hm instance epiOfEffectiveEpi {X Y : C} (f : Y ⟢ X) [EffectiveEpi f] : Epi f := by constructor intro W m₁ mβ‚‚ h have : mβ‚‚ = EffectiveEpi.desc f (f ≫ mβ‚‚) (fun {Z} g₁ gβ‚‚ h => by simp only [← Category.assoc, h]) := EffectiveEpi.uniq _ _ _ _ rfl rw [this] exact EffectiveEpi.uniq _ _ _ _ h /-- This structure encodes the data required for a family of morphisms to be effective epimorphic. -/ structure EffectiveEpiFamilyStruct {B : C} {Ξ± : Type*} (X : Ξ± β†’ C) (Ο€ : (a : Ξ±) β†’ (X a ⟢ B)) where /-- For every `W` with a family of morphisms `e a : Y a ⟢ W` that coequalizes every pair of morphisms `g₁ : Z ⟢ Y a₁`, `gβ‚‚ : Z ⟢ Y aβ‚‚` which the family `Ο€` coequalizes, `desc e h` is a morphism `X ⟢ W`... -/ desc : βˆ€ {W} (e : (a : Ξ±) β†’ (X a ⟢ W)), (βˆ€ {Z : C} (a₁ aβ‚‚ : Ξ±) (g₁ : Z ⟢ X a₁) (gβ‚‚ : Z ⟢ X aβ‚‚), g₁ ≫ Ο€ _ = gβ‚‚ ≫ Ο€ _ β†’ g₁ ≫ e _ = gβ‚‚ ≫ e _) β†’ (B ⟢ W) /-- ...factorizing the components of `e` through the components of `Ο€`... -/ fac : βˆ€ {W} (e : (a : Ξ±) β†’ (X a ⟢ W)) (h : βˆ€ {Z : C} (a₁ aβ‚‚ : Ξ±) (g₁ : Z ⟢ X a₁) (gβ‚‚ : Z ⟢ X aβ‚‚), g₁ ≫ Ο€ _ = gβ‚‚ ≫ Ο€ _ β†’ g₁ ≫ e _ = gβ‚‚ ≫ e _) (a : Ξ±), Ο€ a ≫ desc e h = e a /-- ...and as such, unique. -/ uniq : βˆ€ {W} (e : (a : Ξ±) β†’ (X a ⟢ W)) (h : βˆ€ {Z : C} (a₁ aβ‚‚ : Ξ±) (g₁ : Z ⟢ X a₁) (gβ‚‚ : Z ⟢ X aβ‚‚), g₁ ≫ Ο€ _ = gβ‚‚ ≫ Ο€ _ β†’ g₁ ≫ e _ = gβ‚‚ ≫ e _) (m : B ⟢ W), (βˆ€ (a : Ξ±), Ο€ a ≫ m = e a) β†’ m = desc e h /-- A family of morphisms `Ο€ a : X a ⟢ B` indexed by `Ξ±` is effective epimorphic provided that the `Ο€ a` exhibit `B` as a colimit of the diagram of all "relations" `R β†’ X a₁`, `R ⟢ X aβ‚‚` for all `a₁ aβ‚‚ : Ξ±`. -/ class EffectiveEpiFamily {B : C} {Ξ± : Type*} (X : Ξ± β†’ C) (Ο€ : (a : Ξ±) β†’ (X a ⟢ B)) : Prop where /-- `Ο€` is an effective epimorphic family if there exists an `EffectiveEpiFamilyStruct` for `Ο€` -/ effectiveEpiFamily : Nonempty (EffectiveEpiFamilyStruct X Ο€) /-- Some chosen `EffectiveEpiFamilyStruct` associated to an effective epi family. -/ noncomputable def EffectiveEpiFamily.getStruct {B : C} {Ξ± : Type*} (X : Ξ± β†’ C) (Ο€ : (a : Ξ±) β†’ (X a ⟢ B)) [EffectiveEpiFamily X Ο€] : EffectiveEpiFamilyStruct X Ο€ := EffectiveEpiFamily.effectiveEpiFamily.some /-- Descend along an effective epi family. -/ noncomputable def EffectiveEpiFamily.desc {B W : C} {Ξ± : Type*} (X : Ξ± β†’ C) (Ο€ : (a : Ξ±) β†’ (X a ⟢ B)) [EffectiveEpiFamily X Ο€] (e : (a : Ξ±) β†’ (X a ⟢ W)) (h : βˆ€ {Z : C} (a₁ aβ‚‚ : Ξ±) (g₁ : Z ⟢ X a₁) (gβ‚‚ : Z ⟢ X aβ‚‚), g₁ ≫ Ο€ _ = gβ‚‚ ≫ Ο€ _ β†’ g₁ ≫ e _ = gβ‚‚ ≫ e _) : B ⟢ W := (EffectiveEpiFamily.getStruct X Ο€).desc e h @[reassoc (attr := simp)] lemma EffectiveEpiFamily.fac {B W : C} {Ξ± : Type*} (X : Ξ± β†’ C) (Ο€ : (a : Ξ±) β†’ (X a ⟢ B)) [EffectiveEpiFamily X Ο€] (e : (a : Ξ±) β†’ (X a ⟢ W)) (h : βˆ€ {Z : C} (a₁ aβ‚‚ : Ξ±) (g₁ : Z ⟢ X a₁) (gβ‚‚ : Z ⟢ X aβ‚‚), g₁ ≫ Ο€ _ = gβ‚‚ ≫ Ο€ _ β†’ g₁ ≫ e _ = gβ‚‚ ≫ e _) (a : Ξ±) : Ο€ a ≫ EffectiveEpiFamily.desc X Ο€ e h = e a := (EffectiveEpiFamily.getStruct X Ο€).fac e h a lemma EffectiveEpiFamily.uniq {B W : C} {Ξ± : Type*} (X : Ξ± β†’ C) (Ο€ : (a : Ξ±) β†’ (X a ⟢ B)) [EffectiveEpiFamily X Ο€] (e : (a : Ξ±) β†’ (X a ⟢ W)) (h : βˆ€ {Z : C} (a₁ aβ‚‚ : Ξ±) (g₁ : Z ⟢ X a₁) (gβ‚‚ : Z ⟢ X aβ‚‚), g₁ ≫ Ο€ _ = gβ‚‚ ≫ Ο€ _ β†’ g₁ ≫ e _ = gβ‚‚ ≫ e _) (m : B ⟢ W) (hm : βˆ€ a, Ο€ a ≫ m = e a) : m = EffectiveEpiFamily.desc X Ο€ e h := (EffectiveEpiFamily.getStruct X Ο€).uniq e h m hm -- TODO: Once we have "jointly epimorphic families", we could rephrase this as such a property.
lemma EffectiveEpiFamily.hom_ext {B W : C} {Ξ± : Type*} (X : Ξ± β†’ C) (Ο€ : (a : Ξ±) β†’ (X a ⟢ B)) [EffectiveEpiFamily X Ο€] (m₁ mβ‚‚ : B ⟢ W) (h : βˆ€ a, Ο€ a ≫ m₁ = Ο€ a ≫ mβ‚‚) : m₁ = mβ‚‚ := by have : mβ‚‚ = EffectiveEpiFamily.desc X Ο€ (fun a => Ο€ a ≫ mβ‚‚) (fun a₁ aβ‚‚ g₁ gβ‚‚ h => by simp only [← Category.assoc, h]) := by apply EffectiveEpiFamily.uniq; intro; rfl rw [this] exact EffectiveEpiFamily.uniq _ _ _ _ _ h
Mathlib/CategoryTheory/EffectiveEpi/Basic.lean
166
173
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson -/ import Mathlib.Topology.Category.Profinite.Nobeling.Basic import Mathlib.Topology.Category.Profinite.Nobeling.Induction import Mathlib.Topology.Category.Profinite.Nobeling.Span import Mathlib.Topology.Category.Profinite.Nobeling.Successor import Mathlib.Topology.Category.Profinite.Nobeling.ZeroLimit deprecated_module (since := "2025-04-13")
Mathlib/Topology/Category/Profinite/Nobeling.lean
787
796
/- 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.Algebra.Group.Subgroup.Pointwise import Mathlib.Algebra.Order.Archimedean.Basic import Mathlib.Order.Filter.Bases.Finite import Mathlib.Topology.Algebra.Group.Defs import Mathlib.Topology.Algebra.Monoid import Mathlib.Topology.Homeomorph.Lemmas /-! # Topological groups This file defines the following typeclasses: * `IsTopologicalGroup`, `IsTopologicalAddGroup`: multiplicative and additive topological groups, i.e., groups with continuous `(*)` and `(⁻¹)` / `(+)` and `(-)`; * `ContinuousSub G` means that `G` has a continuous subtraction operation. There is an instance deducing `ContinuousSub` from `IsTopologicalGroup` but we use a separate typeclass because, e.g., `β„•` and `ℝβ‰₯0` have continuous subtraction but are not additive groups. We also define `Homeomorph` versions of several `Equiv`s: `Homeomorph.mulLeft`, `Homeomorph.mulRight`, `Homeomorph.inv`, and prove a few facts about neighbourhood filters in groups. ## Tags topological space, group, topological group -/ open Set Filter TopologicalSpace Function Topology MulOpposite Pointwise universe u v w x variable {G : Type w} {H : Type x} {Ξ± : Type u} {Ξ² : Type v} section ContinuousMulGroup /-! ### Groups with continuous multiplication In this section we prove a few statements about groups with continuous `(*)`. -/ variable [TopologicalSpace G] [Group G] [ContinuousMul G] /-- Multiplication from the left in a topological group as a homeomorphism. -/ @[to_additive "Addition from the left in a topological additive group as a homeomorphism."] protected def Homeomorph.mulLeft (a : G) : G β‰ƒβ‚œ G := { Equiv.mulLeft a with continuous_toFun := continuous_const.mul continuous_id continuous_invFun := continuous_const.mul continuous_id } @[to_additive (attr := simp)] theorem Homeomorph.coe_mulLeft (a : G) : ⇑(Homeomorph.mulLeft a) = (a * Β·) := rfl @[to_additive] theorem Homeomorph.mulLeft_symm (a : G) : (Homeomorph.mulLeft a).symm = Homeomorph.mulLeft a⁻¹ := by ext rfl @[to_additive] lemma isOpenMap_mul_left (a : G) : IsOpenMap (a * Β·) := (Homeomorph.mulLeft a).isOpenMap @[to_additive IsOpen.left_addCoset] theorem IsOpen.leftCoset {U : Set G} (h : IsOpen U) (x : G) : IsOpen (x β€’ U) := isOpenMap_mul_left x _ h @[to_additive] lemma isClosedMap_mul_left (a : G) : IsClosedMap (a * Β·) := (Homeomorph.mulLeft a).isClosedMap @[to_additive IsClosed.left_addCoset] theorem IsClosed.leftCoset {U : Set G} (h : IsClosed U) (x : G) : IsClosed (x β€’ U) := isClosedMap_mul_left x _ h /-- Multiplication from the right in a topological group as a homeomorphism. -/ @[to_additive "Addition from the right in a topological additive group as a homeomorphism."] protected def Homeomorph.mulRight (a : G) : G β‰ƒβ‚œ G := { Equiv.mulRight a with continuous_toFun := continuous_id.mul continuous_const continuous_invFun := continuous_id.mul continuous_const } @[to_additive (attr := simp)] lemma Homeomorph.coe_mulRight (a : G) : ⇑(Homeomorph.mulRight a) = (Β· * a) := rfl @[to_additive] theorem Homeomorph.mulRight_symm (a : G) : (Homeomorph.mulRight a).symm = Homeomorph.mulRight a⁻¹ := by ext rfl @[to_additive] theorem isOpenMap_mul_right (a : G) : IsOpenMap (Β· * a) := (Homeomorph.mulRight a).isOpenMap @[to_additive IsOpen.right_addCoset] theorem IsOpen.rightCoset {U : Set G} (h : IsOpen U) (x : G) : IsOpen (op x β€’ U) := isOpenMap_mul_right x _ h @[to_additive] theorem isClosedMap_mul_right (a : G) : IsClosedMap (Β· * a) := (Homeomorph.mulRight a).isClosedMap @[to_additive IsClosed.right_addCoset] theorem IsClosed.rightCoset {U : Set G} (h : IsClosed U) (x : G) : IsClosed (op x β€’ U) := isClosedMap_mul_right x _ h @[to_additive] theorem discreteTopology_of_isOpen_singleton_one (h : IsOpen ({1} : Set G)) : DiscreteTopology G := by rw [← singletons_open_iff_discrete] intro g suffices {g} = (g⁻¹ * Β·) ⁻¹' {1} by rw [this] exact (continuous_mul_left g⁻¹).isOpen_preimage _ h simp only [mul_one, Set.preimage_mul_left_singleton, eq_self_iff_true, inv_inv, Set.singleton_eq_singleton_iff] @[to_additive] theorem discreteTopology_iff_isOpen_singleton_one : DiscreteTopology G ↔ IsOpen ({1} : Set G) := ⟨fun h => forall_open_iff_discrete.mpr h {1}, discreteTopology_of_isOpen_singleton_one⟩ end ContinuousMulGroup /-! ### `ContinuousInv` and `ContinuousNeg` -/ section ContinuousInv variable [TopologicalSpace G] [Inv G] [ContinuousInv G] @[to_additive] theorem ContinuousInv.induced {Ξ± : Type*} {Ξ² : Type*} {F : Type*} [FunLike F Ξ± Ξ²] [Group Ξ±] [DivisionMonoid Ξ²] [MonoidHomClass F Ξ± Ξ²] [tΞ² : TopologicalSpace Ξ²] [ContinuousInv Ξ²] (f : F) : @ContinuousInv Ξ± (tΞ².induced f) _ := by let _tΞ± := tΞ².induced f refine ⟨continuous_induced_rng.2 ?_⟩ simp only [Function.comp_def, map_inv] fun_prop @[to_additive] protected theorem Specializes.inv {x y : G} (h : x β€³ y) : (x⁻¹) β€³ (y⁻¹) := h.map continuous_inv @[to_additive] protected theorem Inseparable.inv {x y : G} (h : Inseparable x y) : Inseparable (x⁻¹) (y⁻¹) := h.map continuous_inv @[to_additive] protected theorem Specializes.zpow {G : Type*} [DivInvMonoid G] [TopologicalSpace G] [ContinuousMul G] [ContinuousInv G] {x y : G} (h : x β€³ y) : βˆ€ m : β„€, (x ^ m) β€³ (y ^ m) | .ofNat n => by simpa using h.pow n | .negSucc n => by simpa using (h.pow (n + 1)).inv @[to_additive] protected theorem Inseparable.zpow {G : Type*} [DivInvMonoid G] [TopologicalSpace G] [ContinuousMul G] [ContinuousInv G] {x y : G} (h : Inseparable x y) (m : β„€) : Inseparable (x ^ m) (y ^ m) := (h.specializes.zpow m).antisymm (h.specializes'.zpow m) @[to_additive] instance : ContinuousInv (ULift G) := ⟨continuous_uliftUp.comp (continuous_inv.comp continuous_uliftDown)⟩ @[to_additive] theorem continuousOn_inv {s : Set G} : ContinuousOn Inv.inv s := continuous_inv.continuousOn @[to_additive] theorem continuousWithinAt_inv {s : Set G} {x : G} : ContinuousWithinAt Inv.inv s x := continuous_inv.continuousWithinAt @[to_additive] theorem continuousAt_inv {x : G} : ContinuousAt Inv.inv x := continuous_inv.continuousAt @[to_additive] theorem tendsto_inv (a : G) : Tendsto Inv.inv (𝓝 a) (𝓝 a⁻¹) := continuousAt_inv variable [TopologicalSpace Ξ±] {f : Ξ± β†’ G} {s : Set Ξ±} {x : Ξ±} @[to_additive] instance OrderDual.instContinuousInv : ContinuousInv Gα΅’α΅ˆ := β€ΉContinuousInv Gβ€Ί @[to_additive] instance Prod.continuousInv [TopologicalSpace H] [Inv H] [ContinuousInv H] : ContinuousInv (G Γ— H) := ⟨continuous_inv.fst'.prodMk continuous_inv.snd'⟩ variable {ΞΉ : Type*} @[to_additive] instance Pi.continuousInv {C : ΞΉ β†’ Type*} [βˆ€ i, TopologicalSpace (C i)] [βˆ€ i, Inv (C i)] [βˆ€ i, ContinuousInv (C i)] : ContinuousInv (βˆ€ i, C i) where continuous_inv := continuous_pi fun i => (continuous_apply i).inv /-- A version of `Pi.continuousInv` for non-dependent functions. It is needed because sometimes Lean fails to use `Pi.continuousInv` for non-dependent functions. -/ @[to_additive "A version of `Pi.continuousNeg` for non-dependent functions. It is needed because sometimes Lean fails to use `Pi.continuousNeg` for non-dependent functions."] instance Pi.has_continuous_inv' : ContinuousInv (ΞΉ β†’ G) := Pi.continuousInv @[to_additive] instance (priority := 100) continuousInv_of_discreteTopology [TopologicalSpace H] [Inv H] [DiscreteTopology H] : ContinuousInv H := ⟨continuous_of_discreteTopology⟩ section PointwiseLimits variable (G₁ Gβ‚‚ : Type*) [TopologicalSpace Gβ‚‚] [T2Space Gβ‚‚] @[to_additive] theorem isClosed_setOf_map_inv [Inv G₁] [Inv Gβ‚‚] [ContinuousInv Gβ‚‚] : IsClosed { f : G₁ β†’ Gβ‚‚ | βˆ€ x, f x⁻¹ = (f x)⁻¹ } := by simp only [setOf_forall] exact isClosed_iInter fun i => isClosed_eq (continuous_apply _) (continuous_apply _).inv end PointwiseLimits instance [TopologicalSpace H] [Inv H] [ContinuousInv H] : ContinuousNeg (Additive H) where continuous_neg := @continuous_inv H _ _ _ instance [TopologicalSpace H] [Neg H] [ContinuousNeg H] : ContinuousInv (Multiplicative H) where continuous_inv := @continuous_neg H _ _ _ end ContinuousInv section ContinuousInvolutiveInv variable [TopologicalSpace G] [InvolutiveInv G] [ContinuousInv G] {s : Set G} @[to_additive] theorem IsCompact.inv (hs : IsCompact s) : IsCompact s⁻¹ := by rw [← image_inv_eq_inv] exact hs.image continuous_inv variable (G) /-- Inversion in a topological group as a homeomorphism. -/ @[to_additive "Negation in a topological group as a homeomorphism."] protected def Homeomorph.inv (G : Type*) [TopologicalSpace G] [InvolutiveInv G] [ContinuousInv G] : G β‰ƒβ‚œ G := { Equiv.inv G with continuous_toFun := continuous_inv continuous_invFun := continuous_inv } @[to_additive (attr := simp)] lemma Homeomorph.coe_inv {G : Type*} [TopologicalSpace G] [InvolutiveInv G] [ContinuousInv G] : ⇑(Homeomorph.inv G) = Inv.inv := rfl @[to_additive] theorem nhds_inv (a : G) : 𝓝 a⁻¹ = (𝓝 a)⁻¹ := ((Homeomorph.inv G).map_nhds_eq a).symm @[to_additive] theorem isOpenMap_inv : IsOpenMap (Inv.inv : G β†’ G) := (Homeomorph.inv _).isOpenMap @[to_additive] theorem isClosedMap_inv : IsClosedMap (Inv.inv : G β†’ G) := (Homeomorph.inv _).isClosedMap variable {G} @[to_additive] theorem IsOpen.inv (hs : IsOpen s) : IsOpen s⁻¹ := hs.preimage continuous_inv @[to_additive] theorem IsClosed.inv (hs : IsClosed s) : IsClosed s⁻¹ := hs.preimage continuous_inv @[to_additive] theorem inv_closure : βˆ€ s : Set G, (closure s)⁻¹ = closure s⁻¹ := (Homeomorph.inv G).preimage_closure variable [TopologicalSpace Ξ±] {f : Ξ± β†’ G} {s : Set Ξ±} {x : Ξ±} @[to_additive (attr := simp)] lemma continuous_inv_iff : Continuous f⁻¹ ↔ Continuous f := (Homeomorph.inv G).comp_continuous_iff @[to_additive (attr := simp)] lemma continuousAt_inv_iff : ContinuousAt f⁻¹ x ↔ ContinuousAt f x := (Homeomorph.inv G).comp_continuousAt_iff _ _ @[to_additive (attr := simp)] lemma continuousOn_inv_iff : ContinuousOn f⁻¹ s ↔ ContinuousOn f s := (Homeomorph.inv G).comp_continuousOn_iff _ _ @[to_additive] alias ⟨Continuous.of_inv, _⟩ := continuous_inv_iff @[to_additive] alias ⟨ContinuousAt.of_inv, _⟩ := continuousAt_inv_iff @[to_additive] alias ⟨ContinuousOn.of_inv, _⟩ := continuousOn_inv_iff end ContinuousInvolutiveInv section LatticeOps variable {ΞΉ' : Sort*} [Inv G] @[to_additive] theorem continuousInv_sInf {ts : Set (TopologicalSpace G)} (h : βˆ€ t ∈ ts, @ContinuousInv G t _) : @ContinuousInv G (sInf ts) _ := letI := sInf ts { continuous_inv := continuous_sInf_rng.2 fun t ht => continuous_sInf_dom ht (@ContinuousInv.continuous_inv G t _ (h t ht)) } @[to_additive] theorem continuousInv_iInf {ts' : ΞΉ' β†’ TopologicalSpace G} (h' : βˆ€ i, @ContinuousInv G (ts' i) _) : @ContinuousInv G (β¨… i, ts' i) _ := by rw [← sInf_range] exact continuousInv_sInf (Set.forall_mem_range.mpr h') @[to_additive] theorem continuousInv_inf {t₁ tβ‚‚ : TopologicalSpace G} (h₁ : @ContinuousInv G t₁ _) (hβ‚‚ : @ContinuousInv G tβ‚‚ _) : @ContinuousInv G (t₁ βŠ“ tβ‚‚) _ := by rw [inf_eq_iInf] refine continuousInv_iInf fun b => ?_ cases b <;> assumption end LatticeOps @[to_additive] theorem Topology.IsInducing.continuousInv {G H : Type*} [Inv G] [Inv H] [TopologicalSpace G] [TopologicalSpace H] [ContinuousInv H] {f : G β†’ H} (hf : IsInducing f) (hf_inv : βˆ€ x, f x⁻¹ = (f x)⁻¹) : ContinuousInv G := ⟨hf.continuous_iff.2 <| by simpa only [Function.comp_def, hf_inv] using hf.continuous.inv⟩ @[deprecated (since := "2024-10-28")] alias Inducing.continuousInv := IsInducing.continuousInv section IsTopologicalGroup /-! ### Topological groups A topological group is a group in which the multiplication and inversion operations are continuous. Topological additive groups are defined in the same way. Equivalently, we can require that the division operation `x y ↦ x * y⁻¹` (resp., subtraction) is continuous. -/ section Conj instance ConjAct.units_continuousConstSMul {M} [Monoid M] [TopologicalSpace M] [ContinuousMul M] : ContinuousConstSMul (ConjAct MΛ£) M := ⟨fun _ => (continuous_const.mul continuous_id).mul continuous_const⟩ variable [TopologicalSpace G] [Inv G] [Mul G] [ContinuousMul G] /-- Conjugation is jointly continuous on `G Γ— G` when both `mul` and `inv` are continuous. -/ @[to_additive continuous_addConj_prod "Conjugation is jointly continuous on `G Γ— G` when both `add` and `neg` are continuous."] theorem IsTopologicalGroup.continuous_conj_prod [ContinuousInv G] : Continuous fun g : G Γ— G => g.fst * g.snd * g.fst⁻¹ := continuous_mul.mul (continuous_inv.comp continuous_fst) @[deprecated (since := "2025-03-11")] alias IsTopologicalAddGroup.continuous_conj_sum := IsTopologicalAddGroup.continuous_addConj_prod /-- Conjugation by a fixed element is continuous when `mul` is continuous. -/ @[to_additive (attr := continuity) "Conjugation by a fixed element is continuous when `add` is continuous."] theorem IsTopologicalGroup.continuous_conj (g : G) : Continuous fun h : G => g * h * g⁻¹ := (continuous_mul_right g⁻¹).comp (continuous_mul_left g) /-- Conjugation acting on fixed element of the group is continuous when both `mul` and `inv` are continuous. -/ @[to_additive (attr := continuity) "Conjugation acting on fixed element of the additive group is continuous when both `add` and `neg` are continuous."] theorem IsTopologicalGroup.continuous_conj' [ContinuousInv G] (h : G) : Continuous fun g : G => g * h * g⁻¹ := (continuous_mul_right h).mul continuous_inv end Conj variable [TopologicalSpace G] [Group G] [IsTopologicalGroup G] [TopologicalSpace Ξ±] {f : Ξ± β†’ G} {s : Set Ξ±} {x : Ξ±} instance : IsTopologicalGroup (ULift G) where section ZPow @[to_additive (attr := continuity, fun_prop)] theorem continuous_zpow : βˆ€ z : β„€, Continuous fun a : G => a ^ z | Int.ofNat n => by simpa using continuous_pow n | Int.negSucc n => by simpa using (continuous_pow (n + 1)).inv instance AddGroup.continuousConstSMul_int {A} [AddGroup A] [TopologicalSpace A] [IsTopologicalAddGroup A] : ContinuousConstSMul β„€ A := ⟨continuous_zsmul⟩ instance AddGroup.continuousSMul_int {A} [AddGroup A] [TopologicalSpace A] [IsTopologicalAddGroup A] : ContinuousSMul β„€ A := ⟨continuous_prod_of_discrete_left.mpr continuous_zsmul⟩ @[to_additive (attr := continuity, fun_prop)] theorem Continuous.zpow {f : Ξ± β†’ G} (h : Continuous f) (z : β„€) : Continuous fun b => f b ^ z := (continuous_zpow z).comp h @[to_additive] theorem continuousOn_zpow {s : Set G} (z : β„€) : ContinuousOn (fun x => x ^ z) s := (continuous_zpow z).continuousOn @[to_additive] theorem continuousAt_zpow (x : G) (z : β„€) : ContinuousAt (fun x => x ^ z) x := (continuous_zpow z).continuousAt @[to_additive] theorem Filter.Tendsto.zpow {Ξ±} {l : Filter Ξ±} {f : Ξ± β†’ G} {x : G} (hf : Tendsto f l (𝓝 x)) (z : β„€) : Tendsto (fun x => f x ^ z) l (𝓝 (x ^ z)) := (continuousAt_zpow _ _).tendsto.comp hf @[to_additive] theorem ContinuousWithinAt.zpow {f : Ξ± β†’ G} {x : Ξ±} {s : Set Ξ±} (hf : ContinuousWithinAt f s x) (z : β„€) : ContinuousWithinAt (fun x => f x ^ z) s x := Filter.Tendsto.zpow hf z @[to_additive (attr := fun_prop)] theorem ContinuousAt.zpow {f : Ξ± β†’ G} {x : Ξ±} (hf : ContinuousAt f x) (z : β„€) : ContinuousAt (fun x => f x ^ z) x := Filter.Tendsto.zpow hf z @[to_additive (attr := fun_prop)] theorem ContinuousOn.zpow {f : Ξ± β†’ G} {s : Set Ξ±} (hf : ContinuousOn f s) (z : β„€) : ContinuousOn (fun x => f x ^ z) s := fun x hx => (hf x hx).zpow z end ZPow section OrderedCommGroup variable [TopologicalSpace H] [CommGroup H] [PartialOrder H] [IsOrderedMonoid H] [ContinuousInv H] @[to_additive] theorem tendsto_inv_nhdsGT {a : H} : Tendsto Inv.inv (𝓝[>] a) (𝓝[<] a⁻¹) := (continuous_inv.tendsto a).inf <| by simp [tendsto_principal_principal] @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Ioi := tendsto_neg_nhdsGT @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Ioi := tendsto_inv_nhdsGT @[to_additive] theorem tendsto_inv_nhdsLT {a : H} : Tendsto Inv.inv (𝓝[<] a) (𝓝[>] a⁻¹) := (continuous_inv.tendsto a).inf <| by simp [tendsto_principal_principal] @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Iio := tendsto_neg_nhdsLT @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Iio := tendsto_inv_nhdsLT @[to_additive] theorem tendsto_inv_nhdsGT_inv {a : H} : Tendsto Inv.inv (𝓝[>] a⁻¹) (𝓝[<] a) := by simpa only [inv_inv] using tendsto_inv_nhdsGT (a := a⁻¹) @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Ioi_neg := tendsto_neg_nhdsGT_neg @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Ioi_inv := tendsto_inv_nhdsGT_inv @[to_additive] theorem tendsto_inv_nhdsLT_inv {a : H} : Tendsto Inv.inv (𝓝[<] a⁻¹) (𝓝[>] a) := by simpa only [inv_inv] using tendsto_inv_nhdsLT (a := a⁻¹) @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Iio_neg := tendsto_neg_nhdsLT_neg @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Iio_inv := tendsto_inv_nhdsLT_inv @[to_additive] theorem tendsto_inv_nhdsGE {a : H} : Tendsto Inv.inv (𝓝[β‰₯] a) (𝓝[≀] a⁻¹) := (continuous_inv.tendsto a).inf <| by simp [tendsto_principal_principal] @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Ici := tendsto_neg_nhdsGE @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Ici := tendsto_inv_nhdsGE @[to_additive] theorem tendsto_inv_nhdsLE {a : H} : Tendsto Inv.inv (𝓝[≀] a) (𝓝[β‰₯] a⁻¹) := (continuous_inv.tendsto a).inf <| by simp [tendsto_principal_principal] @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Iic := tendsto_neg_nhdsLE @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Iic := tendsto_inv_nhdsLE @[to_additive] theorem tendsto_inv_nhdsGE_inv {a : H} : Tendsto Inv.inv (𝓝[β‰₯] a⁻¹) (𝓝[≀] a) := by simpa only [inv_inv] using tendsto_inv_nhdsGE (a := a⁻¹) @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Ici_neg := tendsto_neg_nhdsGE_neg @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Ici_inv := tendsto_inv_nhdsGE_inv @[to_additive] theorem tendsto_inv_nhdsLE_inv {a : H} : Tendsto Inv.inv (𝓝[≀] a⁻¹) (𝓝[β‰₯] a) := by simpa only [inv_inv] using tendsto_inv_nhdsLE (a := a⁻¹) @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Iic_neg := tendsto_neg_nhdsLE_neg @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Iic_inv := tendsto_inv_nhdsLE_inv end OrderedCommGroup @[to_additive] instance Prod.instIsTopologicalGroup [TopologicalSpace H] [Group H] [IsTopologicalGroup H] : IsTopologicalGroup (G Γ— H) where continuous_inv := continuous_inv.prodMap continuous_inv @[to_additive] instance OrderDual.instIsTopologicalGroup : IsTopologicalGroup Gα΅’α΅ˆ where @[to_additive] instance Pi.topologicalGroup {C : Ξ² β†’ Type*} [βˆ€ b, TopologicalSpace (C b)] [βˆ€ b, Group (C b)] [βˆ€ b, IsTopologicalGroup (C b)] : IsTopologicalGroup (βˆ€ b, C b) where continuous_inv := continuous_pi fun i => (continuous_apply i).inv open MulOpposite @[to_additive] instance [Inv Ξ±] [ContinuousInv Ξ±] : ContinuousInv αᡐᡒᡖ := opHomeomorph.symm.isInducing.continuousInv unop_inv /-- If multiplication is continuous in `Ξ±`, then it also is in `αᡐᡒᡖ`. -/ @[to_additive "If addition is continuous in `Ξ±`, then it also is in `αᡃᡒᡖ`."] instance [Group Ξ±] [IsTopologicalGroup Ξ±] : IsTopologicalGroup αᡐᡒᡖ where variable (G) @[to_additive] theorem nhds_one_symm : comap Inv.inv (𝓝 (1 : G)) = 𝓝 (1 : G) := ((Homeomorph.inv G).comap_nhds_eq _).trans (congr_arg nhds inv_one) @[to_additive] theorem nhds_one_symm' : map Inv.inv (𝓝 (1 : G)) = 𝓝 (1 : G) := ((Homeomorph.inv G).map_nhds_eq _).trans (congr_arg nhds inv_one) @[to_additive] theorem inv_mem_nhds_one {S : Set G} (hS : S ∈ (𝓝 1 : Filter G)) : S⁻¹ ∈ 𝓝 (1 : G) := by rwa [← nhds_one_symm'] at hS /-- The map `(x, y) ↦ (x, x * y)` as a homeomorphism. This is a shear mapping. -/ @[to_additive "The map `(x, y) ↦ (x, x + y)` as a homeomorphism. This is a shear mapping."] protected def Homeomorph.shearMulRight : G Γ— G β‰ƒβ‚œ G Γ— G := { Equiv.prodShear (Equiv.refl _) Equiv.mulLeft with continuous_toFun := by dsimp; fun_prop continuous_invFun := by dsimp; fun_prop } @[to_additive (attr := simp)] theorem Homeomorph.shearMulRight_coe : ⇑(Homeomorph.shearMulRight G) = fun z : G Γ— G => (z.1, z.1 * z.2) := rfl @[to_additive (attr := simp)] theorem Homeomorph.shearMulRight_symm_coe : ⇑(Homeomorph.shearMulRight G).symm = fun z : G Γ— G => (z.1, z.1⁻¹ * z.2) := rfl variable {G} @[to_additive] protected theorem Topology.IsInducing.topologicalGroup {F : Type*} [Group H] [TopologicalSpace H] [FunLike F H G] [MonoidHomClass F H G] (f : F) (hf : IsInducing f) : IsTopologicalGroup H := { toContinuousMul := hf.continuousMul _ toContinuousInv := hf.continuousInv (map_inv f) } @[deprecated (since := "2024-10-28")] alias Inducing.topologicalGroup := IsInducing.topologicalGroup @[to_additive] theorem topologicalGroup_induced {F : Type*} [Group H] [FunLike F H G] [MonoidHomClass F H G] (f : F) : @IsTopologicalGroup H (induced f β€Ή_β€Ί) _ := letI := induced f β€Ή_β€Ί IsInducing.topologicalGroup f ⟨rfl⟩ namespace Subgroup @[to_additive] instance (S : Subgroup G) : IsTopologicalGroup S := IsInducing.subtypeVal.topologicalGroup S.subtype end Subgroup /-- The (topological-space) closure of a subgroup of a topological group is itself a subgroup. -/ @[to_additive "The (topological-space) closure of an additive subgroup of an additive topological group is itself an additive subgroup."] def Subgroup.topologicalClosure (s : Subgroup G) : Subgroup G := { s.toSubmonoid.topologicalClosure with carrier := _root_.closure (s : Set G) inv_mem' := fun {g} hg => by simpa only [← Set.mem_inv, inv_closure, inv_coe_set] using hg } @[to_additive (attr := simp)] theorem Subgroup.topologicalClosure_coe {s : Subgroup G} : (s.topologicalClosure : Set G) = _root_.closure s := rfl @[to_additive] theorem Subgroup.le_topologicalClosure (s : Subgroup G) : s ≀ s.topologicalClosure := _root_.subset_closure @[to_additive] theorem Subgroup.isClosed_topologicalClosure (s : Subgroup G) : IsClosed (s.topologicalClosure : Set G) := isClosed_closure @[to_additive] theorem Subgroup.topologicalClosure_minimal (s : Subgroup G) {t : Subgroup G} (h : s ≀ t) (ht : IsClosed (t : Set G)) : s.topologicalClosure ≀ t := closure_minimal h ht @[to_additive] theorem DenseRange.topologicalClosure_map_subgroup [Group H] [TopologicalSpace H] [IsTopologicalGroup H] {f : G β†’* H} (hf : Continuous f) (hf' : DenseRange f) {s : Subgroup G} (hs : s.topologicalClosure = ⊀) : (s.map f).topologicalClosure = ⊀ := by rw [SetLike.ext'_iff] at hs ⊒ simp only [Subgroup.topologicalClosure_coe, Subgroup.coe_top, ← dense_iff_closure_eq] at hs ⊒ exact hf'.dense_image hf hs /-- The topological closure of a normal subgroup is normal. -/ @[to_additive "The topological closure of a normal additive subgroup is normal."] theorem Subgroup.is_normal_topologicalClosure {G : Type*} [TopologicalSpace G] [Group G] [IsTopologicalGroup G] (N : Subgroup G) [N.Normal] : (Subgroup.topologicalClosure N).Normal where conj_mem n hn g := by apply map_mem_closure (IsTopologicalGroup.continuous_conj g) hn exact fun m hm => Subgroup.Normal.conj_mem inferInstance m hm g @[to_additive] theorem mul_mem_connectedComponent_one {G : Type*} [TopologicalSpace G] [MulOneClass G] [ContinuousMul G] {g h : G} (hg : g ∈ connectedComponent (1 : G)) (hh : h ∈ connectedComponent (1 : G)) : g * h ∈ connectedComponent (1 : G) := by rw [connectedComponent_eq hg] have hmul : g ∈ connectedComponent (g * h) := by apply Continuous.image_connectedComponent_subset (continuous_mul_left g) rw [← connectedComponent_eq hh] exact ⟨(1 : G), mem_connectedComponent, by simp only [mul_one]⟩ simpa [← connectedComponent_eq hmul] using mem_connectedComponent @[to_additive] theorem inv_mem_connectedComponent_one {G : Type*} [TopologicalSpace G] [DivisionMonoid G] [ContinuousInv G] {g : G} (hg : g ∈ connectedComponent (1 : G)) : g⁻¹ ∈ connectedComponent (1 : G) := by rw [← inv_one] exact Continuous.image_connectedComponent_subset continuous_inv _ ((Set.mem_image _ _ _).mp ⟨g, hg, rfl⟩) /-- The connected component of 1 is a subgroup of `G`. -/ @[to_additive "The connected component of 0 is a subgroup of `G`."] def Subgroup.connectedComponentOfOne (G : Type*) [TopologicalSpace G] [Group G] [IsTopologicalGroup G] : Subgroup G where carrier := connectedComponent (1 : G) one_mem' := mem_connectedComponent mul_mem' hg hh := mul_mem_connectedComponent_one hg hh inv_mem' hg := inv_mem_connectedComponent_one hg /-- If a subgroup of a topological group is commutative, then so is its topological closure. See note [reducible non-instances]. -/ @[to_additive "If a subgroup of an additive topological group is commutative, then so is its topological closure. See note [reducible non-instances]."] abbrev Subgroup.commGroupTopologicalClosure [T2Space G] (s : Subgroup G) (hs : βˆ€ x y : s, x * y = y * x) : CommGroup s.topologicalClosure := { s.topologicalClosure.toGroup, s.toSubmonoid.commMonoidTopologicalClosure hs with } variable (G) in @[to_additive] lemma Subgroup.coe_topologicalClosure_bot : ((βŠ₯ : Subgroup G).topologicalClosure : Set G) = _root_.closure ({1} : Set G) := by simp @[to_additive exists_nhds_half_neg] theorem exists_nhds_split_inv {s : Set G} (hs : s ∈ 𝓝 (1 : G)) : βˆƒ V ∈ 𝓝 (1 : G), βˆ€ v ∈ V, βˆ€ w ∈ V, v / w ∈ s := by have : (fun p : G Γ— G => p.1 * p.2⁻¹) ⁻¹' s ∈ 𝓝 ((1, 1) : G Γ— G) := continuousAt_fst.mul continuousAt_snd.inv (by simpa) simpa only [div_eq_mul_inv, nhds_prod_eq, mem_prod_self_iff, prod_subset_iff, mem_preimage] using this @[to_additive] theorem nhds_translation_mul_inv (x : G) : comap (Β· * x⁻¹) (𝓝 1) = 𝓝 x := ((Homeomorph.mulRight x⁻¹).comap_nhds_eq 1).trans <| show 𝓝 (1 * x⁻¹⁻¹) = 𝓝 x by simp @[to_additive (attr := simp)] theorem map_mul_left_nhds (x y : G) : map (x * Β·) (𝓝 y) = 𝓝 (x * y) := (Homeomorph.mulLeft x).map_nhds_eq y @[to_additive] theorem map_mul_left_nhds_one (x : G) : map (x * Β·) (𝓝 1) = 𝓝 x := by simp @[to_additive (attr := simp)] theorem map_mul_right_nhds (x y : G) : map (Β· * x) (𝓝 y) = 𝓝 (y * x) := (Homeomorph.mulRight x).map_nhds_eq y @[to_additive] theorem map_mul_right_nhds_one (x : G) : map (Β· * x) (𝓝 1) = 𝓝 x := by simp @[to_additive] theorem Filter.HasBasis.nhds_of_one {ΞΉ : Sort*} {p : ΞΉ β†’ Prop} {s : ΞΉ β†’ Set G} (hb : HasBasis (𝓝 1 : Filter G) p s) (x : G) : HasBasis (𝓝 x) p fun i => { y | y / x ∈ s i } := by rw [← nhds_translation_mul_inv] simp_rw [div_eq_mul_inv] exact hb.comap _ @[to_additive] theorem mem_closure_iff_nhds_one {x : G} {s : Set G} : x ∈ closure s ↔ βˆ€ U ∈ (𝓝 1 : Filter G), βˆƒ y ∈ s, y / x ∈ U := by rw [mem_closure_iff_nhds_basis ((𝓝 1 : Filter G).basis_sets.nhds_of_one x)] simp_rw [Set.mem_setOf, id] /-- A monoid homomorphism (a bundled morphism of a type that implements `MonoidHomClass`) from a topological group to a topological monoid is continuous provided that it is continuous at one. See also `uniformContinuous_of_continuousAt_one`. -/ @[to_additive "An additive monoid homomorphism (a bundled morphism of a type that implements `AddMonoidHomClass`) from an additive topological group to an additive topological monoid is continuous provided that it is continuous at zero. See also `uniformContinuous_of_continuousAt_zero`."] theorem continuous_of_continuousAt_one {M hom : Type*} [MulOneClass M] [TopologicalSpace M] [ContinuousMul M] [FunLike hom G M] [MonoidHomClass hom G M] (f : hom) (hf : ContinuousAt f 1) : Continuous f := continuous_iff_continuousAt.2 fun x => by simpa only [ContinuousAt, ← map_mul_left_nhds_one x, tendsto_map'_iff, Function.comp_def, map_mul, map_one, mul_one] using hf.tendsto.const_mul (f x) @[to_additive continuous_of_continuousAt_zeroβ‚‚] theorem continuous_of_continuousAt_oneβ‚‚ {H M : Type*} [CommMonoid M] [TopologicalSpace M] [ContinuousMul M] [Group H] [TopologicalSpace H] [IsTopologicalGroup H] (f : G β†’* H β†’* M) (hf : ContinuousAt (fun x : G Γ— H ↦ f x.1 x.2) (1, 1)) (hl : βˆ€ x, ContinuousAt (f x) 1) (hr : βˆ€ y, ContinuousAt (f Β· y) 1) : Continuous (fun x : G Γ— H ↦ f x.1 x.2) := continuous_iff_continuousAt.2 fun (x, y) => by simp only [ContinuousAt, nhds_prod_eq, ← map_mul_left_nhds_one x, ← map_mul_left_nhds_one y, prod_map_map_eq, tendsto_map'_iff, Function.comp_def, map_mul, MonoidHom.mul_apply] at * refine ((tendsto_const_nhds.mul ((hr y).comp tendsto_fst)).mul (((hl x).comp tendsto_snd).mul hf)).mono_right (le_of_eq ?_) simp only [map_one, mul_one, MonoidHom.one_apply] @[to_additive] lemma IsTopologicalGroup.isInducing_iff_nhds_one {H : Type*} [Group H] [TopologicalSpace H] [IsTopologicalGroup H] {F : Type*} [FunLike F G H] [MonoidHomClass F G H] {f : F} : Topology.IsInducing f ↔ 𝓝 (1 : G) = (𝓝 (1 : H)).comap f := by rw [Topology.isInducing_iff_nhds] refine ⟨(map_one f β–Έ Β· 1), fun hf x ↦ ?_⟩ rw [← nhds_translation_mul_inv, ← nhds_translation_mul_inv (f x), Filter.comap_comap, hf, Filter.comap_comap] congr 1 ext; simp @[to_additive] lemma TopologicalGroup.isOpenMap_iff_nhds_one {H : Type*} [Monoid H] [TopologicalSpace H] [ContinuousConstSMul H H] {F : Type*} [FunLike F G H] [MonoidHomClass F G H] {f : F} : IsOpenMap f ↔ 𝓝 1 ≀ .map f (𝓝 1) := by refine ⟨fun H ↦ map_one f β–Έ H.nhds_le 1, fun h ↦ IsOpenMap.of_nhds_le fun x ↦ ?_⟩ have : Filter.map (f x * Β·) (𝓝 1) = 𝓝 (f x) := by simpa [-Homeomorph.map_nhds_eq, Units.smul_def] using (Homeomorph.smul ((toUnits x).map (MonoidHomClass.toMonoidHom f))).map_nhds_eq (1 : H) rw [← map_mul_left_nhds_one x, Filter.map_map, Function.comp_def, ← this] refine (Filter.map_mono h).trans ?_ simp [Function.comp_def] -- TODO: unify with `QuotientGroup.isOpenQuotientMap_mk` /-- Let `A` and `B` be topological groups, and let `Ο† : A β†’ B` be a continuous surjective group homomorphism. Assume furthermore that `Ο†` is a quotient map (i.e., `V βŠ† B` is open iff `φ⁻¹ V` is open). Then `Ο†` is an open quotient map, and in particular an open map. -/ @[to_additive "Let `A` and `B` be topological additive groups, and let `Ο† : A β†’ B` be a continuous surjective additive group homomorphism. Assume furthermore that `Ο†` is a quotient map (i.e., `V βŠ† B` is open iff `φ⁻¹ V` is open). Then `Ο†` is an open quotient map, and in particular an open map."] lemma MonoidHom.isOpenQuotientMap_of_isQuotientMap {A : Type*} [Group A] [TopologicalSpace A] [ContinuousMul A] {B : Type*} [Group B] [TopologicalSpace B] {F : Type*} [FunLike F A B] [MonoidHomClass F A B] {Ο† : F} (hΟ† : IsQuotientMap Ο†) : IsOpenQuotientMap Ο† where surjective := hΟ†.surjective continuous := hΟ†.continuous isOpenMap := by -- We need to check that if `U βŠ† A` is open then `φ⁻¹ (Ο† U)` is open. intro U hU rw [← hΟ†.isOpen_preimage] -- It suffices to show that `φ⁻¹ (Ο† U) = ⋃ (U * k⁻¹)` as `k` runs through the kernel of `Ο†`, -- as `U * k⁻¹` is open because `x ↦ x * k` is continuous. -- Remark: here is where we use that we have groups not monoids (you cannot avoid -- using both `k` and `k⁻¹` at this point). suffices ⇑φ ⁻¹' (⇑φ '' U) = ⋃ k ∈ ker (Ο† : A β†’* B), (fun x ↦ x * k) ⁻¹' U by exact this β–Έ isOpen_biUnion (fun k _ ↦ Continuous.isOpen_preimage (by fun_prop) _ hU) ext x -- But this is an elementary calculation. constructor Β· rintro ⟨y, hyU, hyx⟩ apply Set.mem_iUnion_of_mem (x⁻¹ * y) simp_all Β· rintro ⟨_, ⟨k, rfl⟩, _, ⟨(hk : Ο† k = 1), rfl⟩, hx⟩ use x * k, hx rw [map_mul, hk, mul_one] @[to_additive] theorem IsTopologicalGroup.ext {G : Type*} [Group G] {t t' : TopologicalSpace G} (tg : @IsTopologicalGroup G t _) (tg' : @IsTopologicalGroup G t' _) (h : @nhds G t 1 = @nhds G t' 1) : t = t' := TopologicalSpace.ext_nhds fun x ↦ by rw [← @nhds_translation_mul_inv G t _ _ x, ← @nhds_translation_mul_inv G t' _ _ x, ← h] @[to_additive] theorem IsTopologicalGroup.ext_iff {G : Type*} [Group G] {t t' : TopologicalSpace G} (tg : @IsTopologicalGroup G t _) (tg' : @IsTopologicalGroup G t' _) : t = t' ↔ @nhds G t 1 = @nhds G t' 1 := ⟨fun h => h β–Έ rfl, tg.ext tg'⟩ @[to_additive] theorem ContinuousInv.of_nhds_one {G : Type*} [Group G] [TopologicalSpace G] (hinv : Tendsto (fun x : G => x⁻¹) (𝓝 1) (𝓝 1)) (hleft : βˆ€ xβ‚€ : G, 𝓝 xβ‚€ = map (fun x : G => xβ‚€ * x) (𝓝 1)) (hconj : βˆ€ xβ‚€ : G, Tendsto (fun x : G => xβ‚€ * x * x₀⁻¹) (𝓝 1) (𝓝 1)) : ContinuousInv G := by refine ⟨continuous_iff_continuousAt.2 fun xβ‚€ => ?_⟩ have : Tendsto (fun x => x₀⁻¹ * (xβ‚€ * x⁻¹ * x₀⁻¹)) (𝓝 1) (map (x₀⁻¹ * Β·) (𝓝 1)) := (tendsto_map.comp <| hconj xβ‚€).comp hinv simpa only [ContinuousAt, hleft xβ‚€, hleft x₀⁻¹, tendsto_map'_iff, Function.comp_def, mul_assoc, mul_inv_rev, inv_mul_cancel_left] using this @[to_additive] theorem IsTopologicalGroup.of_nhds_one' {G : Type u} [Group G] [TopologicalSpace G] (hmul : Tendsto (uncurry ((Β· * Β·) : G β†’ G β†’ G)) (𝓝 1 Γ—Λ’ 𝓝 1) (𝓝 1)) (hinv : Tendsto (fun x : G => x⁻¹) (𝓝 1) (𝓝 1)) (hleft : βˆ€ xβ‚€ : G, 𝓝 xβ‚€ = map (fun x => xβ‚€ * x) (𝓝 1)) (hright : βˆ€ xβ‚€ : G, 𝓝 xβ‚€ = map (fun x => x * xβ‚€) (𝓝 1)) : IsTopologicalGroup G := { toContinuousMul := ContinuousMul.of_nhds_one hmul hleft hright toContinuousInv := ContinuousInv.of_nhds_one hinv hleft fun xβ‚€ => le_of_eq (by rw [show (fun x => xβ‚€ * x * x₀⁻¹) = (fun x => x * x₀⁻¹) ∘ fun x => xβ‚€ * x from rfl, ← map_map, ← hleft, hright, map_map] simp [(Β· ∘ Β·)]) } @[to_additive] theorem IsTopologicalGroup.of_nhds_one {G : Type u} [Group G] [TopologicalSpace G] (hmul : Tendsto (uncurry ((Β· * Β·) : G β†’ G β†’ G)) (𝓝 1 Γ—Λ’ 𝓝 1) (𝓝 1)) (hinv : Tendsto (fun x : G => x⁻¹) (𝓝 1) (𝓝 1)) (hleft : βˆ€ xβ‚€ : G, 𝓝 xβ‚€ = map (xβ‚€ * Β·) (𝓝 1)) (hconj : βˆ€ xβ‚€ : G, Tendsto (xβ‚€ * Β· * x₀⁻¹) (𝓝 1) (𝓝 1)) : IsTopologicalGroup G := by refine IsTopologicalGroup.of_nhds_one' hmul hinv hleft fun xβ‚€ => ?_ replace hconj : βˆ€ xβ‚€ : G, map (xβ‚€ * Β· * x₀⁻¹) (𝓝 1) = 𝓝 1 := fun xβ‚€ => map_eq_of_inverse (x₀⁻¹ * Β· * x₀⁻¹⁻¹) (by ext; simp [mul_assoc]) (hconj _) (hconj _) rw [← hconj xβ‚€] simpa [Function.comp_def] using hleft _ @[to_additive] theorem IsTopologicalGroup.of_comm_of_nhds_one {G : Type u} [CommGroup G] [TopologicalSpace G] (hmul : Tendsto (uncurry ((Β· * Β·) : G β†’ G β†’ G)) (𝓝 1 Γ—Λ’ 𝓝 1) (𝓝 1)) (hinv : Tendsto (fun x : G => x⁻¹) (𝓝 1) (𝓝 1)) (hleft : βˆ€ xβ‚€ : G, 𝓝 xβ‚€ = map (xβ‚€ * Β·) (𝓝 1)) : IsTopologicalGroup G := IsTopologicalGroup.of_nhds_one hmul hinv hleft (by simpa using tendsto_id) variable (G) in /-- Any first countable topological group has an antitone neighborhood basis `u : β„• β†’ Set G` for which `(u (n + 1)) ^ 2 βŠ† u n`. The existence of such a neighborhood basis is a key tool for `QuotientGroup.completeSpace` -/ @[to_additive "Any first countable topological additive group has an antitone neighborhood basis `u : β„• β†’ set G` for which `u (n + 1) + u (n + 1) βŠ† u n`. The existence of such a neighborhood basis is a key tool for `QuotientAddGroup.completeSpace`"] theorem IsTopologicalGroup.exists_antitone_basis_nhds_one [FirstCountableTopology G] : βˆƒ u : β„• β†’ Set G, (𝓝 1).HasAntitoneBasis u ∧ βˆ€ n, u (n + 1) * u (n + 1) βŠ† u n := by rcases (𝓝 (1 : G)).exists_antitone_basis with ⟨u, hu, u_anti⟩ have := ((hu.prod_nhds hu).tendsto_iff hu).mp (by simpa only [mul_one] using continuous_mul.tendsto ((1, 1) : G Γ— G)) simp only [and_self_iff, mem_prod, and_imp, Prod.forall, exists_true_left, Prod.exists, forall_true_left] at this have event_mul : βˆ€ n : β„•, βˆ€αΆ  m in atTop, u m * u m βŠ† u n := by intro n rcases this n with ⟨j, k, -, h⟩ refine atTop_basis.eventually_iff.mpr ⟨max j k, True.intro, fun m hm => ?_⟩ rintro - ⟨a, ha, b, hb, rfl⟩ exact h a b (u_anti ((le_max_left _ _).trans hm) ha) (u_anti ((le_max_right _ _).trans hm) hb) obtain βŸ¨Ο†, -, hΟ†, Ο†_anti_basis⟩ := HasAntitoneBasis.subbasis_with_rel ⟨hu, u_anti⟩ event_mul exact ⟨u ∘ Ο†, Ο†_anti_basis, fun n => hΟ† n.lt_succ_self⟩ end IsTopologicalGroup section ContinuousDiv variable [TopologicalSpace G] [Div G] [ContinuousDiv G] @[to_additive const_sub] theorem Filter.Tendsto.const_div' (b : G) {c : G} {f : Ξ± β†’ G} {l : Filter Ξ±} (h : Tendsto f l (𝓝 c)) : Tendsto (fun k : Ξ± => b / f k) l (𝓝 (b / c)) := tendsto_const_nhds.div' h @[to_additive] lemma Filter.tendsto_const_div_iff {G : Type*} [CommGroup G] [TopologicalSpace G] [ContinuousDiv G] (b : G) {c : G} {f : Ξ± β†’ G} {l : Filter Ξ±} : Tendsto (fun k : Ξ± ↦ b / f k) l (𝓝 (b / c)) ↔ Tendsto f l (𝓝 c) := by refine ⟨fun h ↦ ?_, Filter.Tendsto.const_div' b⟩ convert h.const_div' b with k <;> rw [div_div_cancel] @[to_additive sub_const] theorem Filter.Tendsto.div_const' {c : G} {f : Ξ± β†’ G} {l : Filter Ξ±} (h : Tendsto f l (𝓝 c)) (b : G) : Tendsto (f Β· / b) l (𝓝 (c / b)) := h.div' tendsto_const_nhds lemma Filter.tendsto_div_const_iff {G : Type*} [CommGroupWithZero G] [TopologicalSpace G] [ContinuousDiv G] {b : G} (hb : b β‰  0) {c : G} {f : Ξ± β†’ G} {l : Filter Ξ±} : Tendsto (f Β· / b) l (𝓝 (c / b)) ↔ Tendsto f l (𝓝 c) := by refine ⟨fun h ↦ ?_, fun h ↦ Filter.Tendsto.div_const' h b⟩ convert h.div_const' b⁻¹ with k <;> rw [div_div, mul_inv_cancelβ‚€ hb, div_one] lemma Filter.tendsto_sub_const_iff {G : Type*} [AddCommGroup G] [TopologicalSpace G] [ContinuousSub G] (b : G) {c : G} {f : Ξ± β†’ G} {l : Filter Ξ±} : Tendsto (f Β· - b) l (𝓝 (c - b)) ↔ Tendsto f l (𝓝 c) := by refine ⟨fun h ↦ ?_, fun h ↦ Filter.Tendsto.sub_const h b⟩ convert h.sub_const (-b) with k <;> rw [sub_sub, ← sub_eq_add_neg, sub_self, sub_zero] variable [TopologicalSpace Ξ±] {f g : Ξ± β†’ G} {s : Set Ξ±} {x : Ξ±} @[to_additive (attr := continuity) continuous_sub_left] lemma continuous_div_left' (a : G) : Continuous (a / Β·) := continuous_const.div' continuous_id @[to_additive (attr := continuity) continuous_sub_right] lemma continuous_div_right' (a : G) : Continuous (Β· / a) := continuous_id.div' continuous_const end ContinuousDiv section DivInvTopologicalGroup variable [Group G] [TopologicalSpace G] [IsTopologicalGroup G] /-- A version of `Homeomorph.mulLeft a b⁻¹` that is defeq to `a / b`. -/ @[to_additive (attr := simps! +simpRhs) "A version of `Homeomorph.addLeft a (-b)` that is defeq to `a - b`."] def Homeomorph.divLeft (x : G) : G β‰ƒβ‚œ G := { Equiv.divLeft x with continuous_toFun := continuous_const.div' continuous_id continuous_invFun := continuous_inv.mul continuous_const } @[to_additive] theorem isOpenMap_div_left (a : G) : IsOpenMap (a / Β·) := (Homeomorph.divLeft _).isOpenMap @[to_additive] theorem isClosedMap_div_left (a : G) : IsClosedMap (a / Β·) := (Homeomorph.divLeft _).isClosedMap /-- A version of `Homeomorph.mulRight a⁻¹ b` that is defeq to `b / a`. -/ @[to_additive (attr := simps! +simpRhs) "A version of `Homeomorph.addRight (-a) b` that is defeq to `b - a`. "] def Homeomorph.divRight (x : G) : G β‰ƒβ‚œ G := { Equiv.divRight x with continuous_toFun := continuous_id.div' continuous_const continuous_invFun := continuous_id.mul continuous_const } @[to_additive] lemma isOpenMap_div_right (a : G) : IsOpenMap (Β· / a) := (Homeomorph.divRight a).isOpenMap @[to_additive] lemma isClosedMap_div_right (a : G) : IsClosedMap (Β· / a) := (Homeomorph.divRight a).isClosedMap @[to_additive] theorem tendsto_div_nhds_one_iff {Ξ± : Type*} {l : Filter Ξ±} {x : G} {u : Ξ± β†’ G} : Tendsto (u Β· / x) l (𝓝 1) ↔ Tendsto u l (𝓝 x) := haveI A : Tendsto (fun _ : Ξ± => x) l (𝓝 x) := tendsto_const_nhds ⟨fun h => by simpa using h.mul A, fun h => by simpa using h.div' A⟩ @[to_additive] theorem nhds_translation_div (x : G) : comap (Β· / x) (𝓝 1) = 𝓝 x := by simpa only [div_eq_mul_inv] using nhds_translation_mul_inv x end DivInvTopologicalGroup section FilterMul section variable (G) [TopologicalSpace G] [Group G] [ContinuousMul G] @[to_additive] theorem IsTopologicalGroup.t1Space (h : @IsClosed G _ {1}) : T1Space G := ⟨fun x => by simpa using isClosedMap_mul_right x _ h⟩ end section variable [TopologicalSpace G] [Group G] [IsTopologicalGroup G] variable (S : Subgroup G) [Subgroup.Normal S] [IsClosed (S : Set G)] /-- A subgroup `S` of a topological group `G` acts on `G` properly discontinuously on the left, if it is discrete in the sense that `S ∩ K` is finite for all compact `K`. (See also `DiscreteTopology`.) -/ @[to_additive "A subgroup `S` of an additive topological group `G` acts on `G` properly discontinuously on the left, if it is discrete in the sense that `S ∩ K` is finite for all compact `K`. (See also `DiscreteTopology`."] theorem Subgroup.properlyDiscontinuousSMul_of_tendsto_cofinite (S : Subgroup G) (hS : Tendsto S.subtype cofinite (cocompact G)) : ProperlyDiscontinuousSMul S G := { finite_disjoint_inter_image := by intro K L hK hL have H : Set.Finite _ := hS ((hL.prod hK).image continuous_div').compl_mem_cocompact rw [preimage_compl, compl_compl] at H convert H ext x simp only [image_smul, mem_setOf_eq, coe_subtype, mem_preimage, mem_image, Prod.exists] exact Set.smul_inter_ne_empty_iff' } /-- A subgroup `S` of a topological group `G` acts on `G` properly discontinuously on the right, if it is discrete in the sense that `S ∩ K` is finite for all compact `K`. (See also `DiscreteTopology`.) If `G` is Hausdorff, this can be combined with `t2Space_of_properlyDiscontinuousSMul_of_t2Space` to show that the quotient group `G β§Έ S` is Hausdorff. -/ @[to_additive "A subgroup `S` of an additive topological group `G` acts on `G` properly discontinuously on the right, if it is discrete in the sense that `S ∩ K` is finite for all compact `K`. (See also `DiscreteTopology`.) If `G` is Hausdorff, this can be combined with `t2Space_of_properlyDiscontinuousVAdd_of_t2Space` to show that the quotient group `G β§Έ S` is Hausdorff."] theorem Subgroup.properlyDiscontinuousSMul_opposite_of_tendsto_cofinite (S : Subgroup G) (hS : Tendsto S.subtype cofinite (cocompact G)) : ProperlyDiscontinuousSMul S.op G := { finite_disjoint_inter_image := by intro K L hK hL have : Continuous fun p : G Γ— G => (p.1⁻¹, p.2) := continuous_inv.prodMap continuous_id have H : Set.Finite _ := hS ((hK.prod hL).image (continuous_mul.comp this)).compl_mem_cocompact simp only [preimage_compl, compl_compl, coe_subtype, comp_apply] at H apply Finite.of_preimage _ (equivOp S).surjective convert H using 1 ext x simp only [image_smul, mem_setOf_eq, coe_subtype, mem_preimage, mem_image, Prod.exists] exact Set.op_smul_inter_ne_empty_iff } end section /-! Some results about an open set containing the product of two sets in a topological group. -/ variable [TopologicalSpace G] [MulOneClass G] [ContinuousMul G] /-- Given a compact set `K` inside an open set `U`, there is an open neighborhood `V` of `1` such that `K * V βŠ† U`. -/ @[to_additive "Given a compact set `K` inside an open set `U`, there is an open neighborhood `V` of `0` such that `K + V βŠ† U`."] theorem compact_open_separated_mul_right {K U : Set G} (hK : IsCompact K) (hU : IsOpen U) (hKU : K βŠ† U) : βˆƒ V ∈ 𝓝 (1 : G), K * V βŠ† U := by refine hK.induction_on ?_ ?_ ?_ ?_ Β· exact ⟨univ, by simp⟩ Β· rintro s t hst ⟨V, hV, hV'⟩ exact ⟨V, hV, (mul_subset_mul_right hst).trans hV'⟩ Β· rintro s t ⟨V, V_in, hV'⟩ ⟨W, W_in, hW'⟩ use V ∩ W, inter_mem V_in W_in rw [union_mul] exact union_subset ((mul_subset_mul_left V.inter_subset_left).trans hV') ((mul_subset_mul_left V.inter_subset_right).trans hW') Β· intro x hx have := tendsto_mul (show U ∈ 𝓝 (x * 1) by simpa using hU.mem_nhds (hKU hx)) rw [nhds_prod_eq, mem_map, mem_prod_iff] at this rcases this with ⟨t, ht, s, hs, h⟩ rw [← image_subset_iff, image_mul_prod] at h exact ⟨t, mem_nhdsWithin_of_mem_nhds ht, s, hs, h⟩ open MulOpposite /-- Given a compact set `K` inside an open set `U`, there is an open neighborhood `V` of `1` such that `V * K βŠ† U`. -/ @[to_additive "Given a compact set `K` inside an open set `U`, there is an open neighborhood `V` of `0` such that `V + K βŠ† U`."] theorem compact_open_separated_mul_left {K U : Set G} (hK : IsCompact K) (hU : IsOpen U) (hKU : K βŠ† U) : βˆƒ V ∈ 𝓝 (1 : G), V * K βŠ† U := by rcases compact_open_separated_mul_right (hK.image continuous_op) (opHomeomorph.isOpenMap U hU) (image_subset op hKU) with ⟨V, hV : V ∈ 𝓝 (op (1 : G)), hV' : op '' K * V βŠ† op '' U⟩ refine ⟨op ⁻¹' V, continuous_op.continuousAt hV, ?_⟩ rwa [← image_preimage_eq V op_surjective, ← image_op_mul, image_subset_iff, preimage_image_eq _ op_injective] at hV' end section variable [TopologicalSpace G] [Group G] [IsTopologicalGroup G] /-- A compact set is covered by finitely many left multiplicative translates of a set with non-empty interior. -/ @[to_additive "A compact set is covered by finitely many left additive translates of a set with non-empty interior."] theorem compact_covered_by_mul_left_translates {K V : Set G} (hK : IsCompact K) (hV : (interior V).Nonempty) : βˆƒ t : Finset G, K βŠ† ⋃ g ∈ t, (g * Β·) ⁻¹' V := by obtain ⟨t, ht⟩ : βˆƒ t : Finset G, K βŠ† ⋃ x ∈ t, interior ((x * Β·) ⁻¹' V) := by refine hK.elim_finite_subcover (fun x => interior <| (x * Β·) ⁻¹' V) (fun x => isOpen_interior) ?_ obtain ⟨gβ‚€, hgβ‚€βŸ© := hV refine fun g _ => mem_iUnion.2 ⟨gβ‚€ * g⁻¹, ?_⟩ refine preimage_interior_subset_interior_preimage (continuous_const.mul continuous_id) ?_ rwa [mem_preimage, Function.id_def, inv_mul_cancel_right] exact ⟨t, Subset.trans ht <| iUnionβ‚‚_mono fun g _ => interior_subset⟩ /-- Every weakly locally compact separable topological group is Οƒ-compact. Note: this is not true if we drop the topological group hypothesis. -/ @[to_additive SeparableWeaklyLocallyCompactAddGroup.sigmaCompactSpace "Every weakly locally compact separable topological additive group is Οƒ-compact. Note: this is not true if we drop the topological group hypothesis."] instance (priority := 100) SeparableWeaklyLocallyCompactGroup.sigmaCompactSpace [SeparableSpace G] [WeaklyLocallyCompactSpace G] : SigmaCompactSpace G := by obtain ⟨L, hLc, hL1⟩ := exists_compact_mem_nhds (1 : G) refine ⟨⟨fun n => (fun x => x * denseSeq G n) ⁻¹' L, ?_, ?_⟩⟩ Β· intro n exact (Homeomorph.mulRight _).isCompact_preimage.mpr hLc Β· refine iUnion_eq_univ_iff.2 fun x => ?_ obtain ⟨_, ⟨n, rfl⟩, hn⟩ : (range (denseSeq G) ∩ (fun y => x * y) ⁻¹' L).Nonempty := by rw [← (Homeomorph.mulLeft x).apply_symm_apply 1] at hL1 exact (denseRange_denseSeq G).inter_nhds_nonempty ((Homeomorph.mulLeft x).continuous.continuousAt <| hL1) exact ⟨n, hn⟩ /-- Given two compact sets in a noncompact topological group, there is a translate of the second one that is disjoint from the first one. -/ @[to_additive "Given two compact sets in a noncompact additive topological group, there is a translate of the second one that is disjoint from the first one."] theorem exists_disjoint_smul_of_isCompact [NoncompactSpace G] {K L : Set G} (hK : IsCompact K) (hL : IsCompact L) : βˆƒ g : G, Disjoint K (g β€’ L) := by have A : Β¬K * L⁻¹ = univ := (hK.mul hL.inv).ne_univ obtain ⟨g, hg⟩ : βˆƒ g, g βˆ‰ K * L⁻¹ := by contrapose! A exact eq_univ_iff_forall.2 A refine ⟨g, ?_⟩ refine disjoint_left.2 fun a ha h'a => hg ?_ rcases h'a with ⟨b, bL, rfl⟩ refine ⟨g * b, ha, b⁻¹, by simpa only [Set.mem_inv, inv_inv] using bL, ?_⟩ simp only [smul_eq_mul, mul_inv_cancel_right] end section variable [TopologicalSpace G] [Group G] [IsTopologicalGroup G] @[to_additive] theorem nhds_mul (x y : G) : 𝓝 (x * y) = 𝓝 x * 𝓝 y := calc 𝓝 (x * y) = map (x * Β·) (map (Β· * y) (𝓝 1 * 𝓝 1)) := by simp _ = mapβ‚‚ (fun a b => x * (a * b * y)) (𝓝 1) (𝓝 1) := by rw [← mapβ‚‚_mul, map_mapβ‚‚, map_mapβ‚‚] _ = mapβ‚‚ (fun a b => x * a * (b * y)) (𝓝 1) (𝓝 1) := by simp only [mul_assoc] _ = 𝓝 x * 𝓝 y := by rw [← map_mul_left_nhds_one x, ← map_mul_right_nhds_one y, ← mapβ‚‚_mul, mapβ‚‚_map_left, mapβ‚‚_map_right] /-- On a topological group, `𝓝 : G β†’ Filter G` can be promoted to a `MulHom`. -/ @[to_additive (attr := simps) "On an additive topological group, `𝓝 : G β†’ Filter G` can be promoted to an `AddHom`."] def nhdsMulHom : G β†’β‚™* Filter G where toFun := 𝓝 map_mul' _ _ := nhds_mul _ _ end end FilterMul instance {G} [TopologicalSpace G] [Group G] [IsTopologicalGroup G] : IsTopologicalAddGroup (Additive G) where continuous_neg := @continuous_inv G _ _ _ instance {G} [TopologicalSpace G] [AddGroup G] [IsTopologicalAddGroup G] : IsTopologicalGroup (Multiplicative G) where continuous_inv := @continuous_neg G _ _ _ /-- If `G` is a group with topological `⁻¹`, then it is homeomorphic to its units. -/ @[to_additive "If `G` is an additive group with topological negation, then it is homeomorphic to its additive units."] def toUnits_homeomorph [Group G] [TopologicalSpace G] [ContinuousInv G] : G β‰ƒβ‚œ GΛ£ where toEquiv := toUnits.toEquiv continuous_toFun := Units.continuous_iff.2 ⟨continuous_id, continuous_inv⟩ continuous_invFun := Units.continuous_val @[to_additive] theorem Units.isEmbedding_val [Group G] [TopologicalSpace G] [ContinuousInv G] : IsEmbedding (val : GΛ£ β†’ G) := toUnits_homeomorph.symm.isEmbedding @[deprecated (since := "2024-10-26")] alias Units.embedding_val := Units.isEmbedding_val lemma Continuous.of_coeHom_comp [Group G] [Monoid H] [TopologicalSpace G] [TopologicalSpace H] [ContinuousInv G] {f : G β†’* HΛ£} (hf : Continuous ((Units.coeHom H).comp f)) : Continuous f := by apply continuous_induced_rng.mpr ?_ refine continuous_prodMk.mpr ⟨hf, ?_⟩ simp_rw [← map_inv] exact MulOpposite.continuous_op.comp (hf.comp continuous_inv) namespace Units open MulOpposite (continuous_op continuous_unop) variable [Monoid Ξ±] [TopologicalSpace Ξ±] [Monoid Ξ²] [TopologicalSpace Ξ²] @[to_additive] instance [ContinuousMul Ξ±] : IsTopologicalGroup Ξ±Λ£ where continuous_inv := Units.continuous_iff.2 <| ⟨continuous_coe_inv, continuous_val⟩ /-- The topological group isomorphism between the units of a product of two monoids, and the product of the units of each monoid. -/ @[to_additive prodAddUnits "The topological group isomorphism between the additive units of a product of two additive monoids, and the product of the additive units of each additive monoid."] def _root_.Homeomorph.prodUnits : (Ξ± Γ— Ξ²)Λ£ β‰ƒβ‚œ Ξ±Λ£ Γ— Ξ²Λ£ where continuous_toFun := (continuous_fst.units_map (MonoidHom.fst Ξ± Ξ²)).prodMk (continuous_snd.units_map (MonoidHom.snd Ξ± Ξ²)) continuous_invFun := Units.continuous_iff.2 ⟨continuous_val.fst'.prodMk continuous_val.snd', continuous_coe_inv.fst'.prodMk continuous_coe_inv.snd'⟩ toEquiv := MulEquiv.prodUnits.toEquiv @[deprecated (since := "2025-02-21")] alias Homeomorph.sumAddUnits := Homeomorph.prodAddUnits @[deprecated (since := "2025-02-21")] protected alias Homeomorph.prodUnits := Homeomorph.prodUnits end Units section LatticeOps variable {ΞΉ : Sort*} [Group G] @[to_additive] theorem topologicalGroup_sInf {ts : Set (TopologicalSpace G)} (h : βˆ€ t ∈ ts, @IsTopologicalGroup G t _) : @IsTopologicalGroup G (sInf ts) _ := letI := sInf ts { toContinuousInv := @continuousInv_sInf _ _ _ fun t ht => @IsTopologicalGroup.toContinuousInv G t _ <| h t ht toContinuousMul := @continuousMul_sInf _ _ _ fun t ht => @IsTopologicalGroup.toContinuousMul G t _ <| h t ht } @[to_additive] theorem topologicalGroup_iInf {ts' : ΞΉ β†’ TopologicalSpace G} (h' : βˆ€ i, @IsTopologicalGroup G (ts' i) _) : @IsTopologicalGroup G (β¨… i, ts' i) _ := by rw [← sInf_range] exact topologicalGroup_sInf (Set.forall_mem_range.mpr h') @[to_additive] theorem topologicalGroup_inf {t₁ tβ‚‚ : TopologicalSpace G} (h₁ : @IsTopologicalGroup G t₁ _) (hβ‚‚ : @IsTopologicalGroup G tβ‚‚ _) : @IsTopologicalGroup G (t₁ βŠ“ tβ‚‚) _ := by rw [inf_eq_iInf] refine topologicalGroup_iInf fun b => ?_ cases b <;> assumption end LatticeOps
Mathlib/Topology/Algebra/Group/Basic.lean
1,305
1,307
/- Copyright (c) 2021 Martin Dvorak. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Martin Dvorak, Kyle Miller, Eric Wieser -/ import Mathlib.Algebra.Lie.Basic import Mathlib.Data.Matrix.Notation import Mathlib.LinearAlgebra.BilinearMap import Mathlib.LinearAlgebra.LinearIndependent.Lemmas import Mathlib.LinearAlgebra.Matrix.Determinant.Basic /-! # Cross products This module defines the cross product of vectors in $R^3$ for $R$ a commutative ring, as a bilinear map. ## Main definitions * `crossProduct` is the cross product of pairs of vectors in $R^3$. ## Main results * `triple_product_eq_det` * `cross_dot_cross` * `jacobi_cross` ## Notation The locale `Matrix` gives the following notation: * `×₃` for the cross product ## Tags crossproduct -/ open Matrix variable {R : Type*} [CommRing R] /-- The cross product of two vectors in $R^3$ for $R$ a commutative ring. -/ def crossProduct : (Fin 3 β†’ R) β†’β‚—[R] (Fin 3 β†’ R) β†’β‚—[R] Fin 3 β†’ R := by apply LinearMap.mkβ‚‚ R fun a b : Fin 3 β†’ R => ![a 1 * b 2 - a 2 * b 1, a 2 * b 0 - a 0 * b 2, a 0 * b 1 - a 1 * b 0] Β· intros simp_rw [vec3_add, Pi.add_apply] apply vec3_eq <;> ring Β· intros simp_rw [smul_vec3, Pi.smul_apply, smul_sub, smul_mul_assoc] Β· intros simp_rw [vec3_add, Pi.add_apply] apply vec3_eq <;> ring Β· intros simp_rw [smul_vec3, Pi.smul_apply, smul_sub, mul_smul_comm] @[inherit_doc] scoped[Matrix] infixl:74 " ×₃ " => crossProduct theorem cross_apply (a b : Fin 3 β†’ R) : a ×₃ b = ![a 1 * b 2 - a 2 * b 1, a 2 * b 0 - a 0 * b 2, a 0 * b 1 - a 1 * b 0] := rfl section ProductsProperties @[simp] theorem cross_anticomm (v w : Fin 3 β†’ R) : -(v ×₃ w) = w ×₃ v := by simp [cross_apply, mul_comm] alias neg_cross := cross_anticomm @[simp] theorem cross_anticomm' (v w : Fin 3 β†’ R) : v ×₃ w + w ×₃ v = 0 := by rw [add_eq_zero_iff_eq_neg, cross_anticomm] @[simp] theorem cross_self (v : Fin 3 β†’ R) : v ×₃ v = 0 := by simp [cross_apply, mul_comm] /-- The cross product of two vectors is perpendicular to the first vector. -/ @[simp] theorem dot_self_cross (v w : Fin 3 β†’ R) : v ⬝α΅₯ v ×₃ w = 0 := by rw [cross_apply, vec3_dotProduct] dsimp only [Matrix.cons_val] ring /-- The cross product of two vectors is perpendicular to the second vector. -/ @[simp] theorem dot_cross_self (v w : Fin 3 β†’ R) : w ⬝α΅₯ v ×₃ w = 0 := by rw [← cross_anticomm, dotProduct_neg, dot_self_cross, neg_zero] /-- Cyclic permutations preserve the triple product. See also `triple_product_eq_det`. -/ theorem triple_product_permutation (u v w : Fin 3 β†’ R) : u ⬝α΅₯ v ×₃ w = v ⬝α΅₯ w ×₃ u := by
simp_rw [cross_apply, vec3_dotProduct] dsimp only [Matrix.cons_val]
Mathlib/LinearAlgebra/CrossProduct.lean
94
95
/- 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.Algebra.Order.Ring.Nat import Mathlib.Logic.Encodable.Pi import Mathlib.Logic.Function.Iterate /-! # The primitive recursive functions The primitive recursive functions are the least collection of functions `β„• β†’ β„•` which are closed under projections (using the `pair` pairing function), composition, zero, successor, and primitive recursion (i.e. `Nat.rec` where the motive is `C n := β„•`). We can extend this definition to a large class of basic types by using canonical encodings of types as natural numbers (GΓΆdel numbering), which we implement through the type class `Encodable`. (More precisely, we need that the composition of encode with decode yields a primitive recursive function, so we have the `Primcodable` type class for this.) In the above, the pairing function is primitive recursive by definition. This deviates from the textbook definition of primitive recursive functions, which instead work with *`n`-ary* functions. We formalize the textbook definition in `Nat.Primrec'`. `Nat.Primrec'.prim_iff` then proves it is equivalent to our chosen formulation. For more discussionn of this and other design choices in this formalization, see [carneiro2019]. ## Main definitions - `Nat.Primrec f`: `f` is primitive recursive, for functions `f : β„• β†’ β„•` - `Primrec f`: `f` is primitive recursive, for functions between `Primcodable` types - `Primcodable Ξ±`: well-behaved encoding of `Ξ±` into `β„•`, i.e. one such that roundtripping through the encoding functions adds no computational power ## References * [Mario Carneiro, *Formalizing computability theory via partial recursive functions*][carneiro2019] -/ open List (Vector) open Denumerable Encodable Function namespace Nat /-- Calls the given function on a pair of entries `n`, encoded via the pairing function. -/ @[simp, reducible] def unpaired {Ξ±} (f : β„• β†’ β„• β†’ Ξ±) (n : β„•) : Ξ± := f n.unpair.1 n.unpair.2 /-- The primitive recursive functions `β„• β†’ β„•`. -/ protected inductive Primrec : (β„• β†’ β„•) β†’ Prop | zero : Nat.Primrec fun _ => 0 | protected succ : Nat.Primrec succ | left : Nat.Primrec fun n => n.unpair.1 | right : Nat.Primrec fun n => n.unpair.2 | pair {f g} : Nat.Primrec f β†’ Nat.Primrec g β†’ Nat.Primrec fun n => pair (f n) (g n) | comp {f g} : Nat.Primrec f β†’ Nat.Primrec g β†’ Nat.Primrec fun n => f (g n) | prec {f g} : Nat.Primrec f β†’ Nat.Primrec g β†’ Nat.Primrec (unpaired fun z n => n.rec (f z) fun y IH => g <| pair z <| pair y IH) namespace Primrec theorem of_eq {f g : β„• β†’ β„•} (hf : Nat.Primrec f) (H : βˆ€ n, f n = g n) : Nat.Primrec g := (funext H : f = g) β–Έ hf theorem const : βˆ€ n : β„•, Nat.Primrec fun _ => n | 0 => zero | n + 1 => Primrec.succ.comp (const n) protected theorem id : Nat.Primrec id := (left.pair right).of_eq fun n => by simp theorem prec1 {f} (m : β„•) (hf : Nat.Primrec f) : Nat.Primrec fun n => n.rec m fun y IH => f <| Nat.pair y IH := ((prec (const m) (hf.comp right)).comp (zero.pair Primrec.id)).of_eq fun n => by simp theorem casesOn1 {f} (m : β„•) (hf : Nat.Primrec f) : Nat.Primrec (Nat.casesOn Β· m f) := (prec1 m (hf.comp left)).of_eq <| by simp -- Porting note: `Nat.Primrec.casesOn` is already declared as a recursor. theorem casesOn' {f g} (hf : Nat.Primrec f) (hg : Nat.Primrec g) : Nat.Primrec (unpaired fun z n => n.casesOn (f z) fun y => g <| Nat.pair z y) := (prec hf (hg.comp (pair left (left.comp right)))).of_eq fun n => by simp protected theorem swap : Nat.Primrec (unpaired (swap Nat.pair)) := (pair right left).of_eq fun n => by simp theorem swap' {f} (hf : Nat.Primrec (unpaired f)) : Nat.Primrec (unpaired (swap f)) := (hf.comp .swap).of_eq fun n => by simp theorem pred : Nat.Primrec pred := (casesOn1 0 Primrec.id).of_eq fun n => by cases n <;> simp [*] theorem add : Nat.Primrec (unpaired (Β· + Β·)) := (prec .id ((Primrec.succ.comp right).comp right)).of_eq fun p => by simp; induction p.unpair.2 <;> simp [*, Nat.add_assoc] theorem sub : Nat.Primrec (unpaired (Β· - Β·)) := (prec .id ((pred.comp right).comp right)).of_eq fun p => by simp; induction p.unpair.2 <;> simp [*, Nat.sub_add_eq] theorem mul : Nat.Primrec (unpaired (Β· * Β·)) := (prec zero (add.comp (pair left (right.comp right)))).of_eq fun p => by simp; induction p.unpair.2 <;> simp [*, mul_succ, add_comm _ (unpair p).fst] theorem pow : Nat.Primrec (unpaired (Β· ^ Β·)) := (prec (const 1) (mul.comp (pair (right.comp right) left))).of_eq fun p => by simp; induction p.unpair.2 <;> simp [*, Nat.pow_succ] end Primrec end Nat /-- A `Primcodable` type is, essentially, an `Encodable` type for which the encode/decode functions are primitive recursive. However, such a definition is circular. Instead, we ask that the composition of `decode : β„• β†’ Option Ξ±` with `encode : Option Ξ± β†’ β„•` is primitive recursive. Said composition is the identity function, restricted to the image of `encode`. Thus, in a way, the added requirement ensures that no predicates can be smuggled in through a cunning choice of the subset of `β„•` into which the type is encoded. -/ class Primcodable (Ξ± : Type*) extends Encodable Ξ± where -- Porting note: was `prim [] `. -- This means that `prim` does not take the type explicitly in Lean 4 prim : Nat.Primrec fun n => Encodable.encode (decode n) namespace Primcodable open Nat.Primrec instance (priority := 10) ofDenumerable (Ξ±) [Denumerable Ξ±] : Primcodable Ξ± := ⟨Nat.Primrec.succ.of_eq <| by simp⟩ /-- Builds a `Primcodable` instance from an equivalence to a `Primcodable` type. -/ def ofEquiv (Ξ±) {Ξ²} [Primcodable Ξ±] (e : Ξ² ≃ Ξ±) : Primcodable Ξ² := { __ := Encodable.ofEquiv Ξ± e prim := (@Primcodable.prim Ξ± _).of_eq fun n => by rw [decode_ofEquiv] cases (@decode Ξ± _ n) <;> simp [encode_ofEquiv] } instance empty : Primcodable Empty := ⟨zero⟩ instance unit : Primcodable PUnit := ⟨(casesOn1 1 zero).of_eq fun n => by cases n <;> simp⟩ instance option {Ξ± : Type*} [h : Primcodable Ξ±] : Primcodable (Option Ξ±) := ⟨(casesOn1 1 ((casesOn1 0 (.comp .succ .succ)).comp (@Primcodable.prim Ξ± _))).of_eq fun n => by cases n with | zero => rfl | succ n => rw [decode_option_succ] cases H : @decode Ξ± _ n <;> simp [H]⟩ instance bool : Primcodable Bool := ⟨(casesOn1 1 (casesOn1 2 zero)).of_eq fun n => match n with | 0 => rfl | 1 => rfl | (n + 2) => by rw [decode_ge_two] <;> simp⟩ end Primcodable /-- `Primrec f` means `f` is primitive recursive (after encoding its input and output as natural numbers). -/ def Primrec {Ξ± Ξ²} [Primcodable Ξ±] [Primcodable Ξ²] (f : Ξ± β†’ Ξ²) : Prop := Nat.Primrec fun n => encode ((@decode Ξ± _ n).map f) namespace Primrec variable {Ξ± : Type*} {Ξ² : Type*} {Οƒ : Type*} variable [Primcodable Ξ±] [Primcodable Ξ²] [Primcodable Οƒ] open Nat.Primrec protected theorem encode : Primrec (@encode Ξ± _) := (@Primcodable.prim Ξ± _).of_eq fun n => by cases @decode Ξ± _ n <;> rfl protected theorem decode : Primrec (@decode Ξ± _) := Nat.Primrec.succ.comp (@Primcodable.prim Ξ± _) theorem dom_denumerable {Ξ± Ξ²} [Denumerable Ξ±] [Primcodable Ξ²] {f : Ξ± β†’ Ξ²} : Primrec f ↔ Nat.Primrec fun n => encode (f (ofNat Ξ± n)) := ⟨fun h => (pred.comp h).of_eq fun n => by simp, fun h => (Nat.Primrec.succ.comp h).of_eq fun n => by simp⟩ theorem nat_iff {f : β„• β†’ β„•} : Primrec f ↔ Nat.Primrec f := dom_denumerable theorem encdec : Primrec fun n => encode (@decode Ξ± _ n) := nat_iff.2 Primcodable.prim theorem option_some : Primrec (@some Ξ±) := ((casesOn1 0 (Nat.Primrec.succ.comp .succ)).comp (@Primcodable.prim Ξ± _)).of_eq fun n => by cases @decode Ξ± _ n <;> simp theorem of_eq {f g : Ξ± β†’ Οƒ} (hf : Primrec f) (H : βˆ€ n, f n = g n) : Primrec g := (funext H : f = g) β–Έ hf theorem const (x : Οƒ) : Primrec fun _ : Ξ± => x := ((casesOn1 0 (.const (encode x).succ)).comp (@Primcodable.prim Ξ± _)).of_eq fun n => by cases @decode Ξ± _ n <;> rfl protected theorem id : Primrec (@id Ξ±) := (@Primcodable.prim Ξ±).of_eq <| by simp theorem comp {f : Ξ² β†’ Οƒ} {g : Ξ± β†’ Ξ²} (hf : Primrec f) (hg : Primrec g) : Primrec fun a => f (g a) := ((casesOn1 0 (.comp hf (pred.comp hg))).comp (@Primcodable.prim Ξ± _)).of_eq fun n => by cases @decode Ξ± _ n <;> simp [encodek] theorem succ : Primrec Nat.succ := nat_iff.2 Nat.Primrec.succ theorem pred : Primrec Nat.pred := nat_iff.2 Nat.Primrec.pred theorem encode_iff {f : Ξ± β†’ Οƒ} : (Primrec fun a => encode (f a)) ↔ Primrec f := ⟨fun h => Nat.Primrec.of_eq h fun n => by cases @decode Ξ± _ n <;> rfl, Primrec.encode.comp⟩ theorem ofNat_iff {Ξ± Ξ²} [Denumerable Ξ±] [Primcodable Ξ²] {f : Ξ± β†’ Ξ²} : Primrec f ↔ Primrec fun n => f (ofNat Ξ± n) := dom_denumerable.trans <| nat_iff.symm.trans encode_iff protected theorem ofNat (Ξ±) [Denumerable Ξ±] : Primrec (ofNat Ξ±) := ofNat_iff.1 Primrec.id theorem option_some_iff {f : Ξ± β†’ Οƒ} : (Primrec fun a => some (f a)) ↔ Primrec f := ⟨fun h => encode_iff.1 <| pred.comp <| encode_iff.2 h, option_some.comp⟩ theorem of_equiv {Ξ²} {e : Ξ² ≃ Ξ±} : haveI := Primcodable.ofEquiv Ξ± e Primrec e := letI : Primcodable Ξ² := Primcodable.ofEquiv Ξ± e encode_iff.1 Primrec.encode theorem of_equiv_symm {Ξ²} {e : Ξ² ≃ Ξ±} : haveI := Primcodable.ofEquiv Ξ± e Primrec e.symm := letI := Primcodable.ofEquiv Ξ± e encode_iff.1 (show Primrec fun a => encode (e (e.symm a)) by simp [Primrec.encode]) theorem of_equiv_iff {Ξ²} (e : Ξ² ≃ Ξ±) {f : Οƒ β†’ Ξ²} : haveI := Primcodable.ofEquiv Ξ± e (Primrec fun a => e (f a)) ↔ Primrec f := letI := Primcodable.ofEquiv Ξ± e ⟨fun h => (of_equiv_symm.comp h).of_eq fun a => by simp, of_equiv.comp⟩ theorem of_equiv_symm_iff {Ξ²} (e : Ξ² ≃ Ξ±) {f : Οƒ β†’ Ξ±} : haveI := Primcodable.ofEquiv Ξ± e (Primrec fun a => e.symm (f a)) ↔ Primrec f := letI := Primcodable.ofEquiv Ξ± e ⟨fun h => (of_equiv.comp h).of_eq fun a => by simp, of_equiv_symm.comp⟩ end Primrec namespace Primcodable open Nat.Primrec instance prod {Ξ± Ξ²} [Primcodable Ξ±] [Primcodable Ξ²] : Primcodable (Ξ± Γ— Ξ²) := ⟨((casesOn' zero ((casesOn' zero .succ).comp (pair right ((@Primcodable.prim Ξ²).comp left)))).comp (pair right ((@Primcodable.prim Ξ±).comp left))).of_eq fun n => by simp only [Nat.unpaired, Nat.unpair_pair, decode_prod_val] cases @decode Ξ± _ n.unpair.1; Β· simp cases @decode Ξ² _ n.unpair.2 <;> simp⟩ end Primcodable namespace Primrec variable {Ξ± : Type*} [Primcodable Ξ±] open Nat.Primrec theorem fst {Ξ± Ξ²} [Primcodable Ξ±] [Primcodable Ξ²] : Primrec (@Prod.fst Ξ± Ξ²) := ((casesOn' zero ((casesOn' zero (Nat.Primrec.succ.comp left)).comp (pair right ((@Primcodable.prim Ξ²).comp left)))).comp (pair right ((@Primcodable.prim Ξ±).comp left))).of_eq fun n => by simp only [Nat.unpaired, Nat.unpair_pair, decode_prod_val] cases @decode Ξ± _ n.unpair.1 <;> simp cases @decode Ξ² _ n.unpair.2 <;> simp theorem snd {Ξ± Ξ²} [Primcodable Ξ±] [Primcodable Ξ²] : Primrec (@Prod.snd Ξ± Ξ²) := ((casesOn' zero ((casesOn' zero (Nat.Primrec.succ.comp right)).comp (pair right ((@Primcodable.prim Ξ²).comp left)))).comp (pair right ((@Primcodable.prim Ξ±).comp left))).of_eq fun n => by simp only [Nat.unpaired, Nat.unpair_pair, decode_prod_val] cases @decode Ξ± _ n.unpair.1 <;> simp cases @decode Ξ² _ n.unpair.2 <;> simp theorem pair {Ξ± Ξ² Ξ³} [Primcodable Ξ±] [Primcodable Ξ²] [Primcodable Ξ³] {f : Ξ± β†’ Ξ²} {g : Ξ± β†’ Ξ³} (hf : Primrec f) (hg : Primrec g) : Primrec fun a => (f a, g a) := ((casesOn1 0 (Nat.Primrec.succ.comp <| .pair (Nat.Primrec.pred.comp hf) (Nat.Primrec.pred.comp hg))).comp (@Primcodable.prim Ξ± _)).of_eq fun n => by cases @decode Ξ± _ n <;> simp [encodek] theorem unpair : Primrec Nat.unpair := (pair (nat_iff.2 .left) (nat_iff.2 .right)).of_eq fun n => by simp theorem list_getElem?₁ : βˆ€ l : List Ξ±, Primrec (l[Β·]? : β„• β†’ Option Ξ±) | [] => dom_denumerable.2 zero | a :: l => dom_denumerable.2 <| (casesOn1 (encode a).succ <| dom_denumerable.1 <| list_getElem?₁ l).of_eq fun n => by cases n <;> simp @[deprecated (since := "2025-02-14")] alias list_get?₁ := list_getElem?₁ end Primrec /-- `Primrecβ‚‚ f` means `f` is a binary primitive recursive function. This is technically unnecessary since we can always curry all the arguments together, but there are enough natural two-arg functions that it is convenient to express this directly. -/ def Primrecβ‚‚ {Ξ± Ξ² Οƒ} [Primcodable Ξ±] [Primcodable Ξ²] [Primcodable Οƒ] (f : Ξ± β†’ Ξ² β†’ Οƒ) := Primrec fun p : Ξ± Γ— Ξ² => f p.1 p.2 /-- `PrimrecPred p` means `p : Ξ± β†’ Prop` is a (decidable) primitive recursive predicate, which is to say that `decide ∘ p : Ξ± β†’ Bool` is primitive recursive. -/ def PrimrecPred {Ξ±} [Primcodable Ξ±] (p : Ξ± β†’ Prop) [DecidablePred p] := Primrec fun a => decide (p a) /-- `PrimrecRel p` means `p : Ξ± β†’ Ξ² β†’ Prop` is a (decidable) primitive recursive relation, which is to say that `decide ∘ p : Ξ± β†’ Ξ² β†’ Bool` is primitive recursive. -/ def PrimrecRel {Ξ± Ξ²} [Primcodable Ξ±] [Primcodable Ξ²] (s : Ξ± β†’ Ξ² β†’ Prop) [βˆ€ a b, Decidable (s a b)] := Primrecβ‚‚ fun a b => decide (s a b) namespace Primrecβ‚‚ variable {Ξ± : Type*} {Ξ² : Type*} {Οƒ : Type*} variable [Primcodable Ξ±] [Primcodable Ξ²] [Primcodable Οƒ] theorem mk {f : Ξ± β†’ Ξ² β†’ Οƒ} (hf : Primrec fun p : Ξ± Γ— Ξ² => f p.1 p.2) : Primrecβ‚‚ f := hf theorem of_eq {f g : Ξ± β†’ Ξ² β†’ Οƒ} (hg : Primrecβ‚‚ f) (H : βˆ€ a b, f a b = g a b) : Primrecβ‚‚ g := (by funext a b; apply H : f = g) β–Έ hg theorem const (x : Οƒ) : Primrecβ‚‚ fun (_ : Ξ±) (_ : Ξ²) => x := Primrec.const _ protected theorem pair : Primrecβ‚‚ (@Prod.mk Ξ± Ξ²) := Primrec.pair .fst .snd theorem left : Primrecβ‚‚ fun (a : Ξ±) (_ : Ξ²) => a := .fst theorem right : Primrecβ‚‚ fun (_ : Ξ±) (b : Ξ²) => b := .snd theorem natPair : Primrecβ‚‚ Nat.pair := by simp [Primrecβ‚‚, Primrec]; constructor theorem unpaired {f : β„• β†’ β„• β†’ Ξ±} : Primrec (Nat.unpaired f) ↔ Primrecβ‚‚ f := ⟨fun h => by simpa using h.comp natPair, fun h => h.comp Primrec.unpair⟩ theorem unpaired' {f : β„• β†’ β„• β†’ β„•} : Nat.Primrec (Nat.unpaired f) ↔ Primrecβ‚‚ f := Primrec.nat_iff.symm.trans unpaired theorem encode_iff {f : Ξ± β†’ Ξ² β†’ Οƒ} : (Primrecβ‚‚ fun a b => encode (f a b)) ↔ Primrecβ‚‚ f := Primrec.encode_iff theorem option_some_iff {f : Ξ± β†’ Ξ² β†’ Οƒ} : (Primrecβ‚‚ fun a b => some (f a b)) ↔ Primrecβ‚‚ f := Primrec.option_some_iff theorem ofNat_iff {Ξ± Ξ² Οƒ} [Denumerable Ξ±] [Denumerable Ξ²] [Primcodable Οƒ] {f : Ξ± β†’ Ξ² β†’ Οƒ} : Primrecβ‚‚ f ↔ Primrecβ‚‚ fun m n : β„• => f (ofNat Ξ± m) (ofNat Ξ² n) := (Primrec.ofNat_iff.trans <| by simp).trans unpaired theorem uncurry {f : Ξ± β†’ Ξ² β†’ Οƒ} : Primrec (Function.uncurry f) ↔ Primrecβ‚‚ f := by rw [show Function.uncurry f = fun p : Ξ± Γ— Ξ² => f p.1 p.2 from funext fun ⟨a, b⟩ => rfl]; rfl theorem curry {f : Ξ± Γ— Ξ² β†’ Οƒ} : Primrecβ‚‚ (Function.curry f) ↔ Primrec f := by rw [← uncurry, Function.uncurry_curry] end Primrecβ‚‚ section Comp variable {Ξ± : Type*} {Ξ² : Type*} {Ξ³ : Type*} {Ξ΄ : Type*} {Οƒ : Type*} variable [Primcodable Ξ±] [Primcodable Ξ²] [Primcodable Ξ³] [Primcodable Ξ΄] [Primcodable Οƒ] theorem Primrec.compβ‚‚ {f : Ξ³ β†’ Οƒ} {g : Ξ± β†’ Ξ² β†’ Ξ³} (hf : Primrec f) (hg : Primrecβ‚‚ g) : Primrecβ‚‚ fun a b => f (g a b) := hf.comp hg theorem Primrecβ‚‚.comp {f : Ξ² β†’ Ξ³ β†’ Οƒ} {g : Ξ± β†’ Ξ²} {h : Ξ± β†’ Ξ³} (hf : Primrecβ‚‚ f) (hg : Primrec g) (hh : Primrec h) : Primrec fun a => f (g a) (h a) := Primrec.comp hf (hg.pair hh) theorem Primrecβ‚‚.compβ‚‚ {f : Ξ³ β†’ Ξ΄ β†’ Οƒ} {g : Ξ± β†’ Ξ² β†’ Ξ³} {h : Ξ± β†’ Ξ² β†’ Ξ΄} (hf : Primrecβ‚‚ f) (hg : Primrecβ‚‚ g) (hh : Primrecβ‚‚ h) : Primrecβ‚‚ fun a b => f (g a b) (h a b) := hf.comp hg hh theorem PrimrecPred.comp {p : Ξ² β†’ Prop} [DecidablePred p] {f : Ξ± β†’ Ξ²} : PrimrecPred p β†’ Primrec f β†’ PrimrecPred fun a => p (f a) := Primrec.comp theorem PrimrecRel.comp {R : Ξ² β†’ Ξ³ β†’ Prop} [βˆ€ a b, Decidable (R a b)] {f : Ξ± β†’ Ξ²} {g : Ξ± β†’ Ξ³} : PrimrecRel R β†’ Primrec f β†’ Primrec g β†’ PrimrecPred fun a => R (f a) (g a) := Primrecβ‚‚.comp theorem PrimrecRel.compβ‚‚ {R : Ξ³ β†’ Ξ΄ β†’ Prop} [βˆ€ a b, Decidable (R a b)] {f : Ξ± β†’ Ξ² β†’ Ξ³} {g : Ξ± β†’ Ξ² β†’ Ξ΄} : PrimrecRel R β†’ Primrecβ‚‚ f β†’ Primrecβ‚‚ g β†’ PrimrecRel fun a b => R (f a b) (g a b) := PrimrecRel.comp end Comp theorem PrimrecPred.of_eq {Ξ±} [Primcodable Ξ±] {p q : Ξ± β†’ Prop} [DecidablePred p] [DecidablePred q] (hp : PrimrecPred p) (H : βˆ€ a, p a ↔ q a) : PrimrecPred q := Primrec.of_eq hp fun a => Bool.decide_congr (H a) theorem PrimrecRel.of_eq {Ξ± Ξ²} [Primcodable Ξ±] [Primcodable Ξ²] {r s : Ξ± β†’ Ξ² β†’ Prop} [βˆ€ a b, Decidable (r a b)] [βˆ€ a b, Decidable (s a b)] (hr : PrimrecRel r) (H : βˆ€ a b, r a b ↔ s a b) : PrimrecRel s := Primrecβ‚‚.of_eq hr fun a b => Bool.decide_congr (H a b) namespace Primrecβ‚‚ variable {Ξ± : Type*} {Ξ² : Type*} {Οƒ : Type*} variable [Primcodable Ξ±] [Primcodable Ξ²] [Primcodable Οƒ] open Nat.Primrec theorem swap {f : Ξ± β†’ Ξ² β†’ Οƒ} (h : Primrecβ‚‚ f) : Primrecβ‚‚ (swap f) := h.compβ‚‚ Primrecβ‚‚.right Primrecβ‚‚.left theorem nat_iff {f : Ξ± β†’ Ξ² β†’ Οƒ} : Primrecβ‚‚ f ↔ Nat.Primrec (.unpaired fun m n => encode <| (@decode Ξ± _ m).bind fun a => (@decode Ξ² _ n).map (f a)) := by have : βˆ€ (a : Option Ξ±) (b : Option Ξ²), Option.map (fun p : Ξ± Γ— Ξ² => f p.1 p.2) (Option.bind a fun a : Ξ± => Option.map (Prod.mk a) b) = Option.bind a fun a => Option.map (f a) b := fun a b => by cases a <;> cases b <;> rfl simp [Primrecβ‚‚, Primrec, this] theorem nat_iff' {f : Ξ± β†’ Ξ² β†’ Οƒ} : Primrecβ‚‚ f ↔ Primrecβ‚‚ fun m n : β„• => (@decode Ξ± _ m).bind fun a => Option.map (f a) (@decode Ξ² _ n) := nat_iff.trans <| unpaired'.trans encode_iff end Primrecβ‚‚ namespace Primrec variable {Ξ± : Type*} {Ξ² : Type*} {Οƒ : Type*} variable [Primcodable Ξ±] [Primcodable Ξ²] [Primcodable Οƒ] theorem toβ‚‚ {f : Ξ± Γ— Ξ² β†’ Οƒ} (hf : Primrec f) : Primrecβ‚‚ fun a b => f (a, b) := hf.of_eq fun _ => rfl theorem nat_rec {f : Ξ± β†’ Ξ²} {g : Ξ± β†’ β„• Γ— Ξ² β†’ Ξ²} (hf : Primrec f) (hg : Primrecβ‚‚ g) : Primrecβ‚‚ fun a (n : β„•) => n.rec (motive := fun _ => Ξ²) (f a) fun n IH => g a (n, IH) := Primrecβ‚‚.nat_iff.2 <| ((Nat.Primrec.casesOn' .zero <| (Nat.Primrec.prec hf <| .comp hg <| Nat.Primrec.left.pair <| (Nat.Primrec.left.comp .right).pair <| Nat.Primrec.pred.comp <| Nat.Primrec.right.comp .right).comp <| Nat.Primrec.right.pair <| Nat.Primrec.right.comp Nat.Primrec.left).comp <| Nat.Primrec.id.pair <| (@Primcodable.prim Ξ±).comp Nat.Primrec.left).of_eq fun n => by simp only [Nat.unpaired, id_eq, Nat.unpair_pair, decode_prod_val, decode_nat, Option.some_bind, Option.map_map, Option.map_some'] rcases @decode Ξ± _ n.unpair.1 with - | a; Β· rfl simp only [Nat.pred_eq_sub_one, encode_some, Nat.succ_eq_add_one, encodek, Option.map_some', Option.some_bind, Option.map_map] induction' n.unpair.2 with m <;> simp [encodek] simp [*, encodek] theorem nat_rec' {f : Ξ± β†’ β„•} {g : Ξ± β†’ Ξ²} {h : Ξ± β†’ β„• Γ— Ξ² β†’ Ξ²} (hf : Primrec f) (hg : Primrec g) (hh : Primrecβ‚‚ h) : Primrec fun a => (f a).rec (motive := fun _ => Ξ²) (g a) fun n IH => h a (n, IH) := (nat_rec hg hh).comp .id hf theorem nat_rec₁ {f : β„• β†’ Ξ± β†’ Ξ±} (a : Ξ±) (hf : Primrecβ‚‚ f) : Primrec (Nat.rec a f) := nat_rec' .id (const a) <| compβ‚‚ hf Primrecβ‚‚.right theorem nat_casesOn' {f : Ξ± β†’ Ξ²} {g : Ξ± β†’ β„• β†’ Ξ²} (hf : Primrec f) (hg : Primrecβ‚‚ g) : Primrecβ‚‚ fun a (n : β„•) => (n.casesOn (f a) (g a) : Ξ²) := nat_rec hf <| hg.compβ‚‚ Primrecβ‚‚.left <| compβ‚‚ fst Primrecβ‚‚.right theorem nat_casesOn {f : Ξ± β†’ β„•} {g : Ξ± β†’ Ξ²} {h : Ξ± β†’ β„• β†’ Ξ²} (hf : Primrec f) (hg : Primrec g) (hh : Primrecβ‚‚ h) : Primrec fun a => ((f a).casesOn (g a) (h a) : Ξ²) := (nat_casesOn' hg hh).comp .id hf theorem nat_casesOn₁ {f : β„• β†’ Ξ±} (a : Ξ±) (hf : Primrec f) : Primrec (fun (n : β„•) => (n.casesOn a f : Ξ±)) := nat_casesOn .id (const a) (compβ‚‚ hf .right) theorem nat_iterate {f : Ξ± β†’ β„•} {g : Ξ± β†’ Ξ²} {h : Ξ± β†’ Ξ² β†’ Ξ²} (hf : Primrec f) (hg : Primrec g) (hh : Primrecβ‚‚ h) : Primrec fun a => (h a)^[f a] (g a) := (nat_rec' hf hg (hh.compβ‚‚ Primrecβ‚‚.left <| snd.compβ‚‚ Primrecβ‚‚.right)).of_eq fun a => by induction f a <;> simp [*, -Function.iterate_succ, Function.iterate_succ'] theorem option_casesOn {o : Ξ± β†’ Option Ξ²} {f : Ξ± β†’ Οƒ} {g : Ξ± β†’ Ξ² β†’ Οƒ} (ho : Primrec o) (hf : Primrec f) (hg : Primrecβ‚‚ g) : @Primrec _ Οƒ _ _ fun a => Option.casesOn (o a) (f a) (g a) := encode_iff.1 <| (nat_casesOn (encode_iff.2 ho) (encode_iff.2 hf) <| pred.compβ‚‚ <| Primrecβ‚‚.encode_iff.2 <| (Primrecβ‚‚.nat_iff'.1 hg).compβ‚‚ ((@Primrec.encode Ξ± _).comp fst).toβ‚‚ Primrecβ‚‚.right).of_eq fun a => by rcases o a with - | b <;> simp [encodek] theorem option_bind {f : Ξ± β†’ Option Ξ²} {g : Ξ± β†’ Ξ² β†’ Option Οƒ} (hf : Primrec f) (hg : Primrecβ‚‚ g) : Primrec fun a => (f a).bind (g a) := (option_casesOn hf (const none) hg).of_eq fun a => by cases f a <;> rfl theorem option_bind₁ {f : Ξ± β†’ Option Οƒ} (hf : Primrec f) : Primrec fun o => Option.bind o f := option_bind .id (hf.comp snd).toβ‚‚ theorem option_map {f : Ξ± β†’ Option Ξ²} {g : Ξ± β†’ Ξ² β†’ Οƒ} (hf : Primrec f) (hg : Primrecβ‚‚ g) : Primrec fun a => (f a).map (g a) := (option_bind hf (option_some.compβ‚‚ hg)).of_eq fun x => by cases f x <;> rfl theorem option_map₁ {f : Ξ± β†’ Οƒ} (hf : Primrec f) : Primrec (Option.map f) := option_map .id (hf.comp snd).toβ‚‚ theorem option_iget [Inhabited Ξ±] : Primrec (@Option.iget Ξ± _) := (option_casesOn .id (const <| @default Ξ± _) .right).of_eq fun o => by cases o <;> rfl theorem option_isSome : Primrec (@Option.isSome Ξ±) := (option_casesOn .id (const false) (const true).toβ‚‚).of_eq fun o => by cases o <;> rfl theorem option_getD : Primrecβ‚‚ (@Option.getD Ξ±) := Primrec.of_eq (option_casesOn Primrecβ‚‚.left Primrecβ‚‚.right .right) fun ⟨o, a⟩ => by cases o <;> rfl theorem bind_decode_iff {f : Ξ± β†’ Ξ² β†’ Option Οƒ} : (Primrecβ‚‚ fun a n => (@decode Ξ² _ n).bind (f a)) ↔ Primrecβ‚‚ f := ⟨fun h => by simpa [encodek] using h.comp fst ((@Primrec.encode Ξ² _).comp snd), fun h => option_bind (Primrec.decode.comp snd) <| h.comp (fst.comp fst) snd⟩ theorem map_decode_iff {f : Ξ± β†’ Ξ² β†’ Οƒ} : (Primrecβ‚‚ fun a n => (@decode Ξ² _ n).map (f a)) ↔ Primrecβ‚‚ f := by simp only [Option.map_eq_bind] exact bind_decode_iff.trans Primrecβ‚‚.option_some_iff theorem nat_add : Primrecβ‚‚ ((Β· + Β·) : β„• β†’ β„• β†’ β„•) := Primrecβ‚‚.unpaired'.1 Nat.Primrec.add theorem nat_sub : Primrecβ‚‚ ((Β· - Β·) : β„• β†’ β„• β†’ β„•) := Primrecβ‚‚.unpaired'.1 Nat.Primrec.sub theorem nat_mul : Primrecβ‚‚ ((Β· * Β·) : β„• β†’ β„• β†’ β„•) := Primrecβ‚‚.unpaired'.1 Nat.Primrec.mul theorem cond {c : Ξ± β†’ Bool} {f : Ξ± β†’ Οƒ} {g : Ξ± β†’ Οƒ} (hc : Primrec c) (hf : Primrec f) (hg : Primrec g) : Primrec fun a => bif (c a) then (f a) else (g a) := (nat_casesOn (encode_iff.2 hc) hg (hf.comp fst).toβ‚‚).of_eq fun a => by cases c a <;> rfl theorem ite {c : Ξ± β†’ Prop} [DecidablePred c] {f : Ξ± β†’ Οƒ} {g : Ξ± β†’ Οƒ} (hc : PrimrecPred c) (hf : Primrec f) (hg : Primrec g) : Primrec fun a => if c a then f a else g a := by simpa [Bool.cond_decide] using cond hc hf hg theorem nat_le : PrimrecRel ((Β· ≀ Β·) : β„• β†’ β„• β†’ Prop) := (nat_casesOn nat_sub (const true) (const false).toβ‚‚).of_eq fun p => by dsimp [swap] rcases e : p.1 - p.2 with - | n Β· simp [Nat.sub_eq_zero_iff_le.1 e] Β· simp [not_le.2 (Nat.lt_of_sub_eq_succ e)] theorem nat_min : Primrecβ‚‚ (@min β„• _) := ite nat_le fst snd theorem nat_max : Primrecβ‚‚ (@max β„• _) := ite (nat_le.comp fst snd) snd fst theorem dom_bool (f : Bool β†’ Ξ±) : Primrec f := (cond .id (const (f true)) (const (f false))).of_eq fun b => by cases b <;> rfl theorem dom_boolβ‚‚ (f : Bool β†’ Bool β†’ Ξ±) : Primrecβ‚‚ f := (cond fst ((dom_bool (f true)).comp snd) ((dom_bool (f false)).comp snd)).of_eq fun ⟨a, b⟩ => by cases a <;> rfl protected theorem not : Primrec not := dom_bool _ protected theorem and : Primrecβ‚‚ and := dom_boolβ‚‚ _ protected theorem or : Primrecβ‚‚ or := dom_boolβ‚‚ _ theorem _root_.PrimrecPred.not {p : Ξ± β†’ Prop} [DecidablePred p] (hp : PrimrecPred p) : PrimrecPred fun a => Β¬p a := (Primrec.not.comp hp).of_eq fun n => by simp theorem _root_.PrimrecPred.and {p q : Ξ± β†’ Prop} [DecidablePred p] [DecidablePred q] (hp : PrimrecPred p) (hq : PrimrecPred q) : PrimrecPred fun a => p a ∧ q a := (Primrec.and.comp hp hq).of_eq fun n => by simp theorem _root_.PrimrecPred.or {p q : Ξ± β†’ Prop} [DecidablePred p] [DecidablePred q] (hp : PrimrecPred p) (hq : PrimrecPred q) : PrimrecPred fun a => p a ∨ q a := (Primrec.or.comp hp hq).of_eq fun n => by simp protected theorem beq [DecidableEq Ξ±] : Primrecβ‚‚ (@BEq.beq Ξ± _) := have : PrimrecRel fun a b : β„• => a = b := (PrimrecPred.and nat_le nat_le.swap).of_eq fun a => by simp [le_antisymm_iff] (this.compβ‚‚ (Primrec.encode.compβ‚‚ Primrecβ‚‚.left) (Primrec.encode.compβ‚‚ Primrecβ‚‚.right)).of_eq fun _ _ => encode_injective.eq_iff protected theorem eq [DecidableEq Ξ±] : PrimrecRel (@Eq Ξ±) := Primrec.beq theorem nat_lt : PrimrecRel ((Β· < Β·) : β„• β†’ β„• β†’ Prop) := (nat_le.comp snd fst).not.of_eq fun p => by simp theorem option_guard {p : Ξ± β†’ Ξ² β†’ Prop} [βˆ€ a b, Decidable (p a b)] (hp : PrimrecRel p) {f : Ξ± β†’ Ξ²} (hf : Primrec f) : Primrec fun a => Option.guard (p a) (f a) := ite (hp.comp Primrec.id hf) (option_some_iff.2 hf) (const none) theorem option_orElse : Primrecβ‚‚ ((Β· <|> Β·) : Option Ξ± β†’ Option Ξ± β†’ Option Ξ±) := (option_casesOn fst snd (fst.comp fst).toβ‚‚).of_eq fun ⟨o₁, oβ‚‚βŸ© => by cases o₁ <;> cases oβ‚‚ <;> rfl protected theorem decodeβ‚‚ : Primrec (decodeβ‚‚ Ξ±) := option_bind .decode <| option_guard (Primrec.beq.compβ‚‚ (by exact encode_iff.mpr snd) (by exact fst.comp fst)) snd theorem list_findIdx₁ {p : Ξ± β†’ Ξ² β†’ Bool} (hp : Primrecβ‚‚ p) : βˆ€ l : List Ξ², Primrec fun a => l.findIdx (p a) | [] => const 0 | a :: l => (cond (hp.comp .id (const a)) (const 0) (succ.comp (list_findIdx₁ hp l))).of_eq fun n => by simp [List.findIdx_cons] theorem list_idxOf₁ [DecidableEq Ξ±] (l : List Ξ±) : Primrec fun a => l.idxOf a := list_findIdx₁ (.swap .beq) l @[deprecated (since := "2025-01-30")] alias list_indexOf₁ := list_idxOf₁ theorem dom_fintype [Finite Ξ±] (f : Ξ± β†’ Οƒ) : Primrec f := let ⟨l, _, m⟩ := Finite.exists_univ_list Ξ± option_some_iff.1 <| by haveI := decidableEqOfEncodable Ξ± refine ((list_getElem?₁ (l.map f)).comp (list_idxOf₁ l)).of_eq fun a => ?_ rw [List.getElem?_map, List.getElem?_idxOf (m a), Option.map_some'] -- Porting note: These are new lemmas -- I added it because it actually simplified the proofs -- and because I couldn't understand the original proof /-- A function is `PrimrecBounded` if its size is bounded by a primitive recursive function -/ def PrimrecBounded (f : Ξ± β†’ Ξ²) : Prop := βˆƒ g : Ξ± β†’ β„•, Primrec g ∧ βˆ€ x, encode (f x) ≀ g x theorem nat_findGreatest {f : Ξ± β†’ β„•} {p : Ξ± β†’ β„• β†’ Prop} [βˆ€ x n, Decidable (p x n)] (hf : Primrec f) (hp : PrimrecRel p) : Primrec fun x => (f x).findGreatest (p x) := (nat_rec' (h := fun x nih => if p x (nih.1 + 1) then nih.1 + 1 else nih.2) hf (const 0) (ite (hp.comp fst (snd |> fst.comp |> succ.comp)) (snd |> fst.comp |> succ.comp) (snd.comp snd))).of_eq fun x => by induction f x <;> simp [Nat.findGreatest, *] /-- To show a function `f : Ξ± β†’ β„•` is primitive recursive, it is enough to show that the function is bounded by a primitive recursive function and that its graph is primitive recursive -/ theorem of_graph {f : Ξ± β†’ β„•} (h₁ : PrimrecBounded f) (hβ‚‚ : PrimrecRel fun a b => f a = b) : Primrec f := by rcases h₁ with ⟨g, pg, hg : βˆ€ x, f x ≀ g x⟩ refine (nat_findGreatest pg hβ‚‚).of_eq fun n => ?_ exact (Nat.findGreatest_spec (P := fun b => f n = b) (hg n) rfl).symm -- We show that division is primitive recursive by showing that the graph is theorem nat_div : Primrecβ‚‚ ((Β· / Β·) : β„• β†’ β„• β†’ β„•) := by refine of_graph ⟨_, fst, fun p => Nat.div_le_self _ _⟩ ?_ have : PrimrecRel fun (a : β„• Γ— β„•) (b : β„•) => (a.2 = 0 ∧ b = 0) ∨ (0 < a.2 ∧ b * a.2 ≀ a.1 ∧ a.1 < (b + 1) * a.2) := PrimrecPred.or (.and (const 0 |> Primrec.eq.comp (fst |> snd.comp)) (const 0 |> Primrec.eq.comp snd)) (.and (nat_lt.comp (const 0) (fst |> snd.comp)) <| .and (nat_le.comp (nat_mul.comp snd (fst |> snd.comp)) (fst |> fst.comp)) (nat_lt.comp (fst.comp fst) (nat_mul.comp (Primrec.succ.comp snd) (snd.comp fst)))) refine this.of_eq ?_ rintro ⟨a, k⟩ q if H : k = 0 then simp [H, eq_comm] else have : q * k ≀ a ∧ a < (q + 1) * k ↔ q = a / k := by rw [le_antisymm_iff, ← (@Nat.lt_succ _ q), Nat.le_div_iff_mul_le (Nat.pos_of_ne_zero H), Nat.div_lt_iff_lt_mul (Nat.pos_of_ne_zero H)] simpa [H, zero_lt_iff, eq_comm (b := q)] theorem nat_mod : Primrecβ‚‚ ((Β· % Β·) : β„• β†’ β„• β†’ β„•) := (nat_sub.comp fst (nat_mul.comp snd nat_div)).toβ‚‚.of_eq fun m n => by apply Nat.sub_eq_of_eq_add simp [add_comm (m % n), Nat.div_add_mod] theorem nat_bodd : Primrec Nat.bodd := (Primrec.beq.comp (nat_mod.comp .id (const 2)) (const 1)).of_eq fun n => by cases H : n.bodd <;> simp [Nat.mod_two_of_bodd, H] theorem nat_div2 : Primrec Nat.div2 := (nat_div.comp .id (const 2)).of_eq fun n => n.div2_val.symm theorem nat_double : Primrec (fun n : β„• => 2 * n) := nat_mul.comp (const _) Primrec.id theorem nat_double_succ : Primrec (fun n : β„• => 2 * n + 1) := nat_double |> Primrec.succ.comp end Primrec section variable {Ξ± : Type*} {Ξ² : Type*} {Οƒ : Type*} variable [Primcodable Ξ±] [Primcodable Ξ²] [Primcodable Οƒ] variable (H : Nat.Primrec fun n => Encodable.encode (@decode (List Ξ²) _ n)) open Primrec private def prim : Primcodable (List Ξ²) := ⟨H⟩ private theorem list_casesOn' {f : Ξ± β†’ List Ξ²} {g : Ξ± β†’ Οƒ} {h : Ξ± β†’ Ξ² Γ— List Ξ² β†’ Οƒ} (hf : haveI := prim H; Primrec f) (hg : Primrec g) (hh : haveI := prim H; Primrecβ‚‚ h) : @Primrec _ Οƒ _ _ fun a => List.casesOn (f a) (g a) fun b l => h a (b, l) := letI := prim H have : @Primrec _ (Option Οƒ) _ _ fun a => (@decode (Option (Ξ² Γ— List Ξ²)) _ (encode (f a))).map fun o => Option.casesOn o (g a) (h a) := ((@map_decode_iff _ (Option (Ξ² Γ— List Ξ²)) _ _ _ _ _).2 <| toβ‚‚ <| option_casesOn snd (hg.comp fst) (hh.compβ‚‚ (fst.compβ‚‚ Primrecβ‚‚.left) Primrecβ‚‚.right)).comp .id (encode_iff.2 hf) option_some_iff.1 <| this.of_eq fun a => by rcases f a with - | ⟨b, l⟩ <;> simp [encodek] private theorem list_foldl' {f : Ξ± β†’ List Ξ²} {g : Ξ± β†’ Οƒ} {h : Ξ± β†’ Οƒ Γ— Ξ² β†’ Οƒ} (hf : haveI := prim H; Primrec f) (hg : Primrec g) (hh : haveI := prim H; Primrecβ‚‚ h) : Primrec fun a => (f a).foldl (fun s b => h a (s, b)) (g a) := by letI := prim H let G (a : Ξ±) (IH : Οƒ Γ— List Ξ²) : Οƒ Γ— List Ξ² := List.casesOn IH.2 IH fun b l => (h a (IH.1, b), l) have hG : Primrecβ‚‚ G := list_casesOn' H (snd.comp snd) snd <| toβ‚‚ <| pair (hh.comp (fst.comp fst) <| pair ((fst.comp snd).comp fst) (fst.comp snd)) (snd.comp snd) let F := fun (a : Ξ±) (n : β„•) => (G a)^[n] (g a, f a) have hF : Primrec fun a => (F a (encode (f a))).1 := (fst.comp <| nat_iterate (encode_iff.2 hf) (pair hg hf) <| hG) suffices βˆ€ a n, F a n = (((f a).take n).foldl (fun s b => h a (s, b)) (g a), (f a).drop n) by refine hF.of_eq fun a => ?_ rw [this, List.take_of_length_le (length_le_encode _)] introv dsimp only [F] generalize f a = l generalize g a = x induction n generalizing l x with | zero => rfl | succ n IH => simp only [iterate_succ, comp_apply] rcases l with - | ⟨b, l⟩ <;> simp [G, IH] private theorem list_cons' : (haveI := prim H; Primrecβ‚‚ (@List.cons Ξ²)) := letI := prim H encode_iff.1 (succ.comp <| Primrecβ‚‚.natPair.comp (encode_iff.2 fst) (encode_iff.2 snd)) private theorem list_reverse' : haveI := prim H Primrec (@List.reverse Ξ²) := letI := prim H (list_foldl' H .id (const []) <| toβ‚‚ <| ((list_cons' H).comp snd fst).comp snd).of_eq (suffices βˆ€ l r, List.foldl (fun (s : List Ξ²) (b : Ξ²) => b :: s) r l = List.reverseAux l r from fun l => this l [] fun l => by induction l <;> simp [*, List.reverseAux]) end namespace Primcodable variable {Ξ± : Type*} {Ξ² : Type*} variable [Primcodable Ξ±] [Primcodable Ξ²] open Primrec instance sum : Primcodable (Ξ± βŠ• Ξ²) := ⟨Primrec.nat_iff.1 <| (encode_iff.2 (cond nat_bodd (((@Primrec.decode Ξ² _).comp nat_div2).option_map <| toβ‚‚ <| nat_double_succ.comp (Primrec.encode.comp snd)) (((@Primrec.decode Ξ± _).comp nat_div2).option_map <| toβ‚‚ <| nat_double.comp (Primrec.encode.comp snd)))).of_eq fun n => show _ = encode (decodeSum n) by simp only [decodeSum, Nat.boddDiv2_eq] cases Nat.bodd n <;> simp [decodeSum] Β· cases @decode Ξ± _ n.div2 <;> rfl Β· cases @decode Ξ² _ n.div2 <;> rfl⟩ instance list : Primcodable (List Ξ±) := ⟨letI H := @Primcodable.prim (List β„•) _ have : Primrecβ‚‚ fun (a : Ξ±) (o : Option (List β„•)) => o.map (List.cons (encode a)) := option_map snd <| (list_cons' H).comp ((@Primrec.encode Ξ± _).comp (fst.comp fst)) snd have : Primrec fun n => (ofNat (List β„•) n).reverse.foldl (fun o m => (@decode Ξ± _ m).bind fun a => o.map (List.cons (encode a))) (some []) := list_foldl' H ((list_reverse' H).comp (.ofNat (List β„•))) (const (some [])) (Primrec.compβ‚‚ (bind_decode_iff.2 <| .swap this) Primrecβ‚‚.right) nat_iff.1 <| (encode_iff.2 this).of_eq fun n => by rw [List.foldl_reverse] apply Nat.case_strong_induction_on n; Β· simp intro n IH; simp rcases @decode Ξ± _ n.unpair.1 with - | a; Β· rfl simp only [decode_eq_ofNat, Option.some.injEq, Option.some_bind, Option.map_some'] suffices βˆ€ (o : Option (List β„•)) (p), encode o = encode p β†’ encode (Option.map (List.cons (encode a)) o) = encode (Option.map (List.cons a) p) from this _ _ (IH _ (Nat.unpair_right_le n)) intro o p IH cases o <;> cases p Β· rfl Β· injection IH Β· injection IH Β· exact congr_arg (fun k => (Nat.pair (encode a) k).succ.succ) (Nat.succ.inj IH)⟩ end Primcodable namespace Primrec variable {Ξ± : Type*} {Ξ² : Type*} {Ξ³ : Type*} {Οƒ : Type*} variable [Primcodable Ξ±] [Primcodable Ξ²] [Primcodable Ξ³] [Primcodable Οƒ] theorem sumInl : Primrec (@Sum.inl Ξ± Ξ²) := encode_iff.1 <| nat_double.comp Primrec.encode theorem sumInr : Primrec (@Sum.inr Ξ± Ξ²) := encode_iff.1 <| nat_double_succ.comp Primrec.encode @[deprecated (since := "2025-02-21")] alias sum_inl := Primrec.sumInl @[deprecated (since := "2025-02-21")] alias sum_inr := Primrec.sumInr theorem sumCasesOn {f : Ξ± β†’ Ξ² βŠ• Ξ³} {g : Ξ± β†’ Ξ² β†’ Οƒ} {h : Ξ± β†’ Ξ³ β†’ Οƒ} (hf : Primrec f) (hg : Primrecβ‚‚ g) (hh : Primrecβ‚‚ h) : @Primrec _ Οƒ _ _ fun a => Sum.casesOn (f a) (g a) (h a) := option_some_iff.1 <| (cond (nat_bodd.comp <| encode_iff.2 hf) (option_map (Primrec.decode.comp <| nat_div2.comp <| encode_iff.2 hf) hh) (option_map (Primrec.decode.comp <| nat_div2.comp <| encode_iff.2 hf) hg)).of_eq fun a => by rcases f a with b | c <;> simp [Nat.div2_val, encodek] @[deprecated (since := "2025-02-21")] alias sum_casesOn := Primrec.sumCasesOn theorem list_cons : Primrecβ‚‚ (@List.cons Ξ±) := list_cons' Primcodable.prim theorem list_casesOn {f : Ξ± β†’ List Ξ²} {g : Ξ± β†’ Οƒ} {h : Ξ± β†’ Ξ² Γ— List Ξ² β†’ Οƒ} : Primrec f β†’ Primrec g β†’ Primrecβ‚‚ h β†’ @Primrec _ Οƒ _ _ fun a => List.casesOn (f a) (g a) fun b l => h a (b, l) := list_casesOn' Primcodable.prim theorem list_foldl {f : Ξ± β†’ List Ξ²} {g : Ξ± β†’ Οƒ} {h : Ξ± β†’ Οƒ Γ— Ξ² β†’ Οƒ} : Primrec f β†’ Primrec g β†’ Primrecβ‚‚ h β†’ Primrec fun a => (f a).foldl (fun s b => h a (s, b)) (g a) := list_foldl' Primcodable.prim theorem list_reverse : Primrec (@List.reverse Ξ±) := list_reverse' Primcodable.prim theorem list_foldr {f : Ξ± β†’ List Ξ²} {g : Ξ± β†’ Οƒ} {h : Ξ± β†’ Ξ² Γ— Οƒ β†’ Οƒ} (hf : Primrec f) (hg : Primrec g) (hh : Primrecβ‚‚ h) : Primrec fun a => (f a).foldr (fun b s => h a (b, s)) (g a) := (list_foldl (list_reverse.comp hf) hg <| toβ‚‚ <| hh.comp fst <| (pair snd fst).comp snd).of_eq fun a => by simp [List.foldl_reverse] theorem list_head? : Primrec (@List.head? Ξ±) := (list_casesOn .id (const none) (option_some_iff.2 <| fst.comp snd).toβ‚‚).of_eq fun l => by cases l <;> rfl theorem list_headI [Inhabited Ξ±] : Primrec (@List.headI Ξ± _) := (option_iget.comp list_head?).of_eq fun l => l.head!_eq_head?.symm theorem list_tail : Primrec (@List.tail Ξ±) := (list_casesOn .id (const []) (snd.comp snd).toβ‚‚).of_eq fun l => by cases l <;> rfl theorem list_rec {f : Ξ± β†’ List Ξ²} {g : Ξ± β†’ Οƒ} {h : Ξ± β†’ Ξ² Γ— List Ξ² Γ— Οƒ β†’ Οƒ} (hf : Primrec f) (hg : Primrec g) (hh : Primrecβ‚‚ h) : @Primrec _ Οƒ _ _ fun a => List.recOn (f a) (g a) fun b l IH => h a (b, l, IH) := let F (a : Ξ±) := (f a).foldr (fun (b : Ξ²) (s : List Ξ² Γ— Οƒ) => (b :: s.1, h a (b, s))) ([], g a) have : Primrec F := list_foldr hf (pair (const []) hg) <| toβ‚‚ <| pair ((list_cons.comp fst (fst.comp snd)).comp snd) hh (snd.comp this).of_eq fun a => by suffices F a = (f a, List.recOn (f a) (g a) fun b l IH => h a (b, l, IH)) by rw [this] dsimp [F] induction' f a with b l IH <;> simp [*] theorem list_getElem? : Primrecβ‚‚ ((Β·[Β·]? : List Ξ± β†’ β„• β†’ Option Ξ±)) := let F (l : List Ξ±) (n : β„•) := l.foldl (fun (s : β„• βŠ• Ξ±) (a : Ξ±) => Sum.casesOn s (@Nat.casesOn (fun _ => β„• βŠ• Ξ±) Β· (Sum.inr a) Sum.inl) Sum.inr) (Sum.inl n) have hF : Primrecβ‚‚ F := (list_foldl fst (sumInl.comp snd) ((sumCasesOn fst (nat_casesOn snd (sumInr.comp <| snd.comp fst) (sumInl.comp snd).toβ‚‚).toβ‚‚ (sumInr.comp snd).toβ‚‚).comp snd).toβ‚‚).toβ‚‚ have : @Primrec _ (Option Ξ±) _ _ fun p : List Ξ± Γ— β„• => Sum.casesOn (F p.1 p.2) (fun _ => none) some := sumCasesOn hF (const none).toβ‚‚ (option_some.comp snd).toβ‚‚ this.toβ‚‚.of_eq fun l n => by dsimp; symm induction' l with a l IH generalizing n; Β· rfl rcases n with - | n Β· dsimp [F] clear IH induction' l with _ l IH <;> simp_all Β· simpa using IH .. @[deprecated (since := "2025-02-14")] alias list_get? := list_getElem? theorem list_getD (d : Ξ±) : Primrecβ‚‚ fun l n => List.getD l n d := by simp only [List.getD_eq_getElem?_getD] exact option_getD.compβ‚‚ list_getElem? (const _) theorem list_getI [Inhabited Ξ±] : Primrecβ‚‚ (@List.getI Ξ± _) := list_getD _ theorem list_append : Primrecβ‚‚ ((Β· ++ Β·) : List Ξ± β†’ List Ξ± β†’ List Ξ±) := (list_foldr fst snd <| toβ‚‚ <| comp (@list_cons Ξ± _) snd).toβ‚‚.of_eq fun l₁ lβ‚‚ => by induction l₁ <;> simp [*] theorem list_concat : Primrecβ‚‚ fun l (a : Ξ±) => l ++ [a] := list_append.comp fst (list_cons.comp snd (const [])) theorem list_map {f : Ξ± β†’ List Ξ²} {g : Ξ± β†’ Ξ² β†’ Οƒ} (hf : Primrec f) (hg : Primrecβ‚‚ g) : Primrec fun a => (f a).map (g a) := (list_foldr hf (const []) <| toβ‚‚ <| list_cons.comp (hg.comp fst (fst.comp snd)) (snd.comp snd)).of_eq fun a => by induction f a <;> simp [*] theorem list_range : Primrec List.range := (nat_rec' .id (const []) ((list_concat.comp snd fst).comp snd).toβ‚‚).of_eq fun n => by simp; induction n <;> simp [*, List.range_succ] theorem list_flatten : Primrec (@List.flatten Ξ±) := (list_foldr .id (const []) <| toβ‚‚ <| comp (@list_append Ξ± _) snd).of_eq fun l => by dsimp; induction l <;> simp [*] theorem list_flatMap {f : Ξ± β†’ List Ξ²} {g : Ξ± β†’ Ξ² β†’ List Οƒ} (hf : Primrec f) (hg : Primrecβ‚‚ g) : Primrec (fun a => (f a).flatMap (g a)) := list_flatten.comp (list_map hf hg) theorem optionToList : Primrec (Option.toList : Option Ξ± β†’ List Ξ±) := (option_casesOn Primrec.id (const []) ((list_cons.comp Primrec.id (const [])).compβ‚‚ Primrecβ‚‚.right)).of_eq (fun o => by rcases o <;> simp) theorem listFilterMap {f : Ξ± β†’ List Ξ²} {g : Ξ± β†’ Ξ² β†’ Option Οƒ} (hf : Primrec f) (hg : Primrecβ‚‚ g) : Primrec fun a => (f a).filterMap (g a) := (list_flatMap hf (compβ‚‚ optionToList hg)).of_eq fun _ ↦ Eq.symm <| List.filterMap_eq_flatMap_toList _ _ theorem list_length : Primrec (@List.length Ξ±) := (list_foldr (@Primrec.id (List Ξ±) _) (const 0) <| toβ‚‚ <| (succ.comp <| snd.comp snd).toβ‚‚).of_eq fun l => by dsimp; induction l <;> simp [*] theorem list_findIdx {f : Ξ± β†’ List Ξ²} {p : Ξ± β†’ Ξ² β†’ Bool} (hf : Primrec f) (hp : Primrecβ‚‚ p) : Primrec fun a => (f a).findIdx (p a) := (list_foldr hf (const 0) <| toβ‚‚ <| cond (hp.comp fst <| fst.comp snd) (const 0) (succ.comp <| snd.comp snd)).of_eq fun a => by dsimp; induction f a <;> simp [List.findIdx_cons, *] theorem list_idxOf [DecidableEq Ξ±] : Primrecβ‚‚ (@List.idxOf Ξ± _) := toβ‚‚ <| list_findIdx snd <| Primrec.beq.compβ‚‚ snd.toβ‚‚ (fst.comp fst).toβ‚‚ @[deprecated (since := "2025-01-30")] alias list_indexOf := list_idxOf theorem nat_strong_rec (f : Ξ± β†’ β„• β†’ Οƒ) {g : Ξ± β†’ List Οƒ β†’ Option Οƒ} (hg : Primrecβ‚‚ g) (H : βˆ€ a n, g a ((List.range n).map (f a)) = some (f a n)) : Primrecβ‚‚ f := suffices Primrecβ‚‚ fun a n => (List.range n).map (f a) from Primrecβ‚‚.option_some_iff.1 <| (list_getElem?.comp (this.comp fst (succ.comp snd)) snd).toβ‚‚.of_eq fun a n => by simp [List.getElem?_range (Nat.lt_succ_self n)] Primrecβ‚‚.option_some_iff.1 <| (nat_rec (const (some [])) (toβ‚‚ <| option_bind (snd.comp snd) <| toβ‚‚ <| option_map (hg.comp (fst.comp fst) snd) (toβ‚‚ <| list_concat.comp (snd.comp fst) snd))).of_eq fun a n => by induction n with | zero => rfl | succ n IH => simp [IH, H, List.range_succ] theorem listLookup [DecidableEq Ξ±] : Primrecβ‚‚ (List.lookup : Ξ± β†’ List (Ξ± Γ— Ξ²) β†’ Option Ξ²) := (toβ‚‚ <| list_rec snd (const none) <| toβ‚‚ <| cond (Primrec.beq.comp (fst.comp fst) (fst.comp <| fst.comp snd)) (option_some.comp <| snd.comp <| fst.comp snd) (snd.comp <| snd.comp snd)).of_eq fun a ps => by induction' ps with p ps ih <;> simp [List.lookup, *] cases ha : a == p.1 <;> simp [ha] theorem nat_omega_rec' (f : Ξ² β†’ Οƒ) {m : Ξ² β†’ β„•} {l : Ξ² β†’ List Ξ²} {g : Ξ² β†’ List Οƒ β†’ Option Οƒ} (hm : Primrec m) (hl : Primrec l) (hg : Primrecβ‚‚ g) (Ord : βˆ€ b, βˆ€ b' ∈ l b, m b' < m b) (H : βˆ€ b, g b ((l b).map f) = some (f b)) : Primrec f := by haveI : DecidableEq Ξ² := Encodable.decidableEqOfEncodable Ξ² let mapGraph (M : List (Ξ² Γ— Οƒ)) (bs : List Ξ²) : List Οƒ := bs.flatMap (Option.toList <| M.lookup Β·) let bindList (b : Ξ²) : β„• β†’ List Ξ² := fun n ↦ n.rec [b] fun _ bs ↦ bs.flatMap l let graph (b : Ξ²) : β„• β†’ List (Ξ² Γ— Οƒ) := fun i ↦ i.rec [] fun i ih ↦ (bindList b (m b - i)).filterMap fun b' ↦ (g b' <| mapGraph ih (l b')).map (b', Β·) have mapGraph_primrec : Primrecβ‚‚ mapGraph := toβ‚‚ <| list_flatMap snd <| optionToList.compβ‚‚ <| listLookup.compβ‚‚ .right (fst.compβ‚‚ .left) have bindList_primrec : Primrecβ‚‚ (bindList) := nat_rec' snd (list_cons.comp fst (const [])) (toβ‚‚ <| list_flatMap (snd.comp snd) (hl.compβ‚‚ .right)) have graph_primrec : Primrecβ‚‚ (graph) := toβ‚‚ <| nat_rec' snd (const []) <| toβ‚‚ <| listFilterMap (bindList_primrec.comp (fst.comp fst) (nat_sub.comp (hm.comp <| fst.comp fst) (fst.comp snd))) <| toβ‚‚ <| option_map (hg.comp snd (mapGraph_primrec.comp (snd.comp <| snd.comp fst) (hl.comp snd))) (Primrecβ‚‚.pair.compβ‚‚ (snd.compβ‚‚ .left) .right) have : Primrec (fun b => (graph b (m b + 1))[0]?.map Prod.snd) := option_map (list_getElem?.comp (graph_primrec.comp Primrec.id (succ.comp hm)) (const 0)) (snd.compβ‚‚ Primrecβ‚‚.right) exact option_some_iff.mp <| this.of_eq <| fun b ↦ by have graph_eq_map_bindList (i : β„•) (hi : i ≀ m b + 1) : graph b i = (bindList b (m b + 1 - i)).map fun x ↦ (x, f x) := by have bindList_eq_nil : bindList b (m b + 1) = [] := have bindList_m_lt (k : β„•) : βˆ€ b' ∈ bindList b k, m b' < m b + 1 - k := by induction' k with k ih <;> simp [bindList] intro aβ‚‚ a₁ ha₁ haβ‚‚ have : k ≀ m b := Nat.lt_succ.mp (by simpa using Nat.add_lt_of_lt_sub <| Nat.zero_lt_of_lt (ih a₁ ha₁)) have : m a₁ ≀ m b - k := Nat.lt_succ.mp (by rw [← Nat.succ_sub this]; simpa using ih a₁ ha₁) exact lt_of_lt_of_le (Ord a₁ aβ‚‚ haβ‚‚) this List.eq_nil_iff_forall_not_mem.mpr (by intro b' ha'; by_contra; simpa using bindList_m_lt (m b + 1) b' ha') have mapGraph_graph {bs bs' : List Ξ²} (has : bs' βŠ† bs) : mapGraph (bs.map <| fun x => (x, f x)) bs' = bs'.map f := by induction' bs' with b bs' ih <;> simp [mapGraph] Β· have : b ∈ bs ∧ bs' βŠ† bs := by simpa using has rcases this with ⟨ha, has'⟩ simpa [List.lookup_graph f ha] using ih has' have graph_succ : βˆ€ i, graph b (i + 1) = (bindList b (m b - i)).filterMap fun b' => (g b' <| mapGraph (graph b i) (l b')).map (b', Β·) := fun _ => rfl have bindList_succ : βˆ€ i, bindList b (i + 1) = (bindList b i).flatMap l := fun _ => rfl induction' i with i ih Β· symm; simpa [graph] using bindList_eq_nil Β· simp only [graph_succ, ih (Nat.le_of_lt hi), Nat.succ_sub (Nat.lt_succ.mp hi), Nat.succ_eq_add_one, bindList_succ, Nat.reduceSubDiff] apply List.filterMap_eq_map_iff_forall_eq_some.mpr intro b' ha'; simp; rw [mapGraph_graph] Β· exact H b' Β· exact (List.infix_flatMap_of_mem ha' l).subset simp [graph_eq_map_bindList (m b + 1) (Nat.le_refl _), bindList] theorem nat_omega_rec (f : Ξ± β†’ Ξ² β†’ Οƒ) {m : Ξ± β†’ Ξ² β†’ β„•} {l : Ξ± β†’ Ξ² β†’ List Ξ²} {g : Ξ± β†’ Ξ² Γ— List Οƒ β†’ Option Οƒ} (hm : Primrecβ‚‚ m) (hl : Primrecβ‚‚ l) (hg : Primrecβ‚‚ g) (Ord : βˆ€ a b, βˆ€ b' ∈ l a b, m a b' < m a b) (H : βˆ€ a b, g a (b, (l a b).map (f a)) = some (f a b)) : Primrecβ‚‚ f := Primrecβ‚‚.uncurry.mp <| nat_omega_rec' (Function.uncurry f) (Primrecβ‚‚.uncurry.mpr hm) (list_map (hl.comp fst snd) (Primrecβ‚‚.pair.compβ‚‚ (fst.compβ‚‚ .left) .right)) (hg.compβ‚‚ (fst.compβ‚‚ .left) (Primrecβ‚‚.pair.compβ‚‚ (snd.compβ‚‚ .left) .right)) (by simpa using Ord) (by simpa [Function.comp] using H) end Primrec namespace Primcodable variable {Ξ± : Type*} [Primcodable Ξ±] open Primrec /-- A subtype of a primitive recursive predicate is `Primcodable`. -/ def subtype {p : Ξ± β†’ Prop} [DecidablePred p] (hp : PrimrecPred p) : Primcodable (Subtype p) := ⟨have : Primrec fun n => (@decode Ξ± _ n).bind fun a => Option.guard p a := option_bind .decode (option_guard (hp.comp snd).toβ‚‚ snd) nat_iff.1 <| (encode_iff.2 this).of_eq fun n => show _ = encode ((@decode Ξ± _ n).bind fun _ => _) by rcases @decode Ξ± _ n with - | a; Β· rfl dsimp [Option.guard] by_cases h : p a <;> simp [h]; rfl⟩ instance fin {n} : Primcodable (Fin n) := @ofEquiv _ _ (subtype <| nat_lt.comp .id (const n)) Fin.equivSubtype instance vector {n} : Primcodable (List.Vector Ξ± n) := subtype ((@Primrec.eq β„• _ _).comp list_length (const _)) instance finArrow {n} : Primcodable (Fin n β†’ Ξ±) :=
ofEquiv _ (Equiv.vectorEquivFin _ _).symm
Mathlib/Computability/Primrec.lean
1,109
1,111
/- 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, Johannes HΓΆlzl, Mario Carneiro -/ import Mathlib.Logic.Pairwise import Mathlib.Data.Set.BooleanAlgebra /-! # The set lattice This file is a collection of results on the complete atomic boolean algebra structure of `Set Ξ±`. Notation for the complete lattice operations can be found in `Mathlib.Order.SetNotation`. ## Main declarations * `Set.sInter_eq_biInter`, `Set.sUnion_eq_biInter`: Shows that `β‹‚β‚€ s = β‹‚ x ∈ s, x` and `⋃₀ s = ⋃ x ∈ s, x`. * `Set.completeAtomicBooleanAlgebra`: `Set Ξ±` is a `CompleteAtomicBooleanAlgebra` with `≀ = βŠ†`, `< = βŠ‚`, `βŠ“ = ∩`, `βŠ” = βˆͺ`, `β¨… = β‹‚`, `⨆ = ⋃` and `\` as the set difference. See `Set.instBooleanAlgebra`. * `Set.unionEqSigmaOfDisjoint`: Equivalence between `⋃ i, t i` and `Ξ£ i, t i`, where `t` is an indexed family of disjoint sets. ## Naming convention In lemma names, * `⋃ i, s i` is called `iUnion` * `β‹‚ i, s i` is called `iInter` * `⋃ i j, s i j` is called `iUnionβ‚‚`. This is an `iUnion` inside an `iUnion`. * `β‹‚ i j, s i j` is called `iInterβ‚‚`. This is an `iInter` inside an `iInter`. * `⋃ i ∈ s, t i` is called `biUnion` for "bounded `iUnion`". This is the special case of `iUnionβ‚‚` where `j : i ∈ s`. * `β‹‚ i ∈ s, t i` is called `biInter` for "bounded `iInter`". This is the special case of `iInterβ‚‚` where `j : i ∈ s`. ## Notation * `⋃`: `Set.iUnion` * `β‹‚`: `Set.iInter` * `⋃₀`: `Set.sUnion` * `β‹‚β‚€`: `Set.sInter` -/ open Function Set universe u variable {Ξ± Ξ² Ξ³ Ξ΄ : Type*} {ΞΉ ΞΉ' ΞΉβ‚‚ : Sort*} {ΞΊ κ₁ ΞΊβ‚‚ : ΞΉ β†’ Sort*} {ΞΊ' : ΞΉ' β†’ Sort*} namespace Set /-! ### Complete lattice and complete Boolean algebra instances -/ theorem mem_iUnionβ‚‚ {x : Ξ³} {s : βˆ€ i, ΞΊ i β†’ Set Ξ³} : (x ∈ ⋃ (i) (j), s i j) ↔ βˆƒ i j, x ∈ s i j := by simp_rw [mem_iUnion] theorem mem_iInterβ‚‚ {x : Ξ³} {s : βˆ€ i, ΞΊ i β†’ Set Ξ³} : (x ∈ β‹‚ (i) (j), s i j) ↔ βˆ€ i j, x ∈ s i j := by simp_rw [mem_iInter] theorem mem_iUnion_of_mem {s : ΞΉ β†’ Set Ξ±} {a : Ξ±} (i : ΞΉ) (ha : a ∈ s i) : a ∈ ⋃ i, s i := mem_iUnion.2 ⟨i, ha⟩ theorem mem_iUnionβ‚‚_of_mem {s : βˆ€ i, ΞΊ i β†’ Set Ξ±} {a : Ξ±} {i : ΞΉ} (j : ΞΊ i) (ha : a ∈ s i j) : a ∈ ⋃ (i) (j), s i j := mem_iUnionβ‚‚.2 ⟨i, j, ha⟩ theorem mem_iInter_of_mem {s : ΞΉ β†’ Set Ξ±} {a : Ξ±} (h : βˆ€ i, a ∈ s i) : a ∈ β‹‚ i, s i := mem_iInter.2 h theorem mem_iInterβ‚‚_of_mem {s : βˆ€ i, ΞΊ i β†’ Set Ξ±} {a : Ξ±} (h : βˆ€ i j, a ∈ s i j) : a ∈ β‹‚ (i) (j), s i j := mem_iInterβ‚‚.2 h /-! ### Union and intersection over an indexed family of sets -/ @[congr] theorem iUnion_congr_Prop {p q : Prop} {f₁ : p β†’ Set Ξ±} {fβ‚‚ : q β†’ Set Ξ±} (pq : p ↔ q) (f : βˆ€ x, f₁ (pq.mpr x) = fβ‚‚ x) : iUnion f₁ = iUnion fβ‚‚ := iSup_congr_Prop pq f @[congr] theorem iInter_congr_Prop {p q : Prop} {f₁ : p β†’ Set Ξ±} {fβ‚‚ : q β†’ Set Ξ±} (pq : p ↔ q) (f : βˆ€ x, f₁ (pq.mpr x) = fβ‚‚ x) : iInter f₁ = iInter fβ‚‚ := iInf_congr_Prop pq f theorem iUnion_plift_up (f : PLift ΞΉ β†’ Set Ξ±) : ⋃ i, f (PLift.up i) = ⋃ i, f i := iSup_plift_up _ theorem iUnion_plift_down (f : ΞΉ β†’ Set Ξ±) : ⋃ i, f (PLift.down i) = ⋃ i, f i := iSup_plift_down _ theorem iInter_plift_up (f : PLift ΞΉ β†’ Set Ξ±) : β‹‚ i, f (PLift.up i) = β‹‚ i, f i := iInf_plift_up _ theorem iInter_plift_down (f : ΞΉ β†’ Set Ξ±) : β‹‚ i, f (PLift.down i) = β‹‚ i, f i := iInf_plift_down _ theorem iUnion_eq_if {p : Prop} [Decidable p] (s : Set Ξ±) : ⋃ _ : p, s = if p then s else βˆ… := iSup_eq_if _ theorem iUnion_eq_dif {p : Prop} [Decidable p] (s : p β†’ Set Ξ±) : ⋃ h : p, s h = if h : p then s h else βˆ… := iSup_eq_dif _ theorem iInter_eq_if {p : Prop} [Decidable p] (s : Set Ξ±) : β‹‚ _ : p, s = if p then s else univ := iInf_eq_if _ theorem iInf_eq_dif {p : Prop} [Decidable p] (s : p β†’ Set Ξ±) : β‹‚ h : p, s h = if h : p then s h else univ := _root_.iInf_eq_dif _ theorem exists_set_mem_of_union_eq_top {ΞΉ : Type*} (t : Set ΞΉ) (s : ΞΉ β†’ Set Ξ²) (w : ⋃ i ∈ t, s i = ⊀) (x : Ξ²) : βˆƒ i ∈ t, x ∈ s i := by have p : x ∈ ⊀ := Set.mem_univ x rw [← w, Set.mem_iUnion] at p simpa using p theorem nonempty_of_union_eq_top_of_nonempty {ΞΉ : Type*} (t : Set ΞΉ) (s : ΞΉ β†’ Set Ξ±) (H : Nonempty Ξ±) (w : ⋃ i ∈ t, s i = ⊀) : t.Nonempty := by obtain ⟨x, m, -⟩ := exists_set_mem_of_union_eq_top t s w H.some exact ⟨x, m⟩ theorem nonempty_of_nonempty_iUnion {s : ΞΉ β†’ Set Ξ±} (h_Union : (⋃ i, s i).Nonempty) : Nonempty ΞΉ := by obtain ⟨x, hx⟩ := h_Union exact ⟨Classical.choose <| mem_iUnion.mp hx⟩ theorem nonempty_of_nonempty_iUnion_eq_univ {s : ΞΉ β†’ Set Ξ±} [Nonempty Ξ±] (h_Union : ⋃ i, s i = univ) : Nonempty ΞΉ := nonempty_of_nonempty_iUnion (s := s) (by simpa only [h_Union] using univ_nonempty) theorem setOf_exists (p : ΞΉ β†’ Ξ² β†’ Prop) : { x | βˆƒ i, p i x } = ⋃ i, { x | p i x } := ext fun _ => mem_iUnion.symm theorem setOf_forall (p : ΞΉ β†’ Ξ² β†’ Prop) : { x | βˆ€ i, p i x } = β‹‚ i, { x | p i x } := ext fun _ => mem_iInter.symm theorem iUnion_subset {s : ΞΉ β†’ Set Ξ±} {t : Set Ξ±} (h : βˆ€ i, s i βŠ† t) : ⋃ i, s i βŠ† t := iSup_le h theorem iUnionβ‚‚_subset {s : βˆ€ i, ΞΊ i β†’ Set Ξ±} {t : Set Ξ±} (h : βˆ€ i j, s i j βŠ† t) : ⋃ (i) (j), s i j βŠ† t := iUnion_subset fun x => iUnion_subset (h x) theorem subset_iInter {t : Set Ξ²} {s : ΞΉ β†’ Set Ξ²} (h : βˆ€ i, t βŠ† s i) : t βŠ† β‹‚ i, s i := le_iInf h theorem subset_iInterβ‚‚ {s : Set Ξ±} {t : βˆ€ i, ΞΊ i β†’ Set Ξ±} (h : βˆ€ i j, s βŠ† t i j) : s βŠ† β‹‚ (i) (j), t i j := subset_iInter fun x => subset_iInter <| h x @[simp] theorem iUnion_subset_iff {s : ΞΉ β†’ Set Ξ±} {t : Set Ξ±} : ⋃ i, s i βŠ† t ↔ βˆ€ i, s i βŠ† t := ⟨fun h _ => Subset.trans (le_iSup s _) h, iUnion_subset⟩ theorem iUnionβ‚‚_subset_iff {s : βˆ€ i, ΞΊ i β†’ Set Ξ±} {t : Set Ξ±} : ⋃ (i) (j), s i j βŠ† t ↔ βˆ€ i j, s i j βŠ† t := by simp_rw [iUnion_subset_iff] @[simp] theorem subset_iInter_iff {s : Set Ξ±} {t : ΞΉ β†’ Set Ξ±} : (s βŠ† β‹‚ i, t i) ↔ βˆ€ i, s βŠ† t i := le_iInf_iff theorem subset_iInterβ‚‚_iff {s : Set Ξ±} {t : βˆ€ i, ΞΊ i β†’ Set Ξ±} : (s βŠ† β‹‚ (i) (j), t i j) ↔ βˆ€ i j, s βŠ† t i j := by simp_rw [subset_iInter_iff] theorem subset_iUnion : βˆ€ (s : ΞΉ β†’ Set Ξ²) (i : ΞΉ), s i βŠ† ⋃ i, s i := le_iSup theorem iInter_subset : βˆ€ (s : ΞΉ β†’ Set Ξ²) (i : ΞΉ), β‹‚ i, s i βŠ† s i := iInf_le lemma iInter_subset_iUnion [Nonempty ΞΉ] {s : ΞΉ β†’ Set Ξ±} : β‹‚ i, s i βŠ† ⋃ i, s i := iInf_le_iSup theorem subset_iUnionβ‚‚ {s : βˆ€ i, ΞΊ i β†’ Set Ξ±} (i : ΞΉ) (j : ΞΊ i) : s i j βŠ† ⋃ (i') (j'), s i' j' := le_iSupβ‚‚ i j theorem iInterβ‚‚_subset {s : βˆ€ i, ΞΊ i β†’ Set Ξ±} (i : ΞΉ) (j : ΞΊ i) : β‹‚ (i) (j), s i j βŠ† s i j := iInfβ‚‚_le i j /-- This rather trivial consequence of `subset_iUnion`is convenient with `apply`, and has `i` explicit for this purpose. -/ theorem subset_iUnion_of_subset {s : Set Ξ±} {t : ΞΉ β†’ Set Ξ±} (i : ΞΉ) (h : s βŠ† t i) : s βŠ† ⋃ i, t i := le_iSup_of_le i h /-- This rather trivial consequence of `iInter_subset`is convenient with `apply`, and has `i` explicit for this purpose. -/ theorem iInter_subset_of_subset {s : ΞΉ β†’ Set Ξ±} {t : Set Ξ±} (i : ΞΉ) (h : s i βŠ† t) : β‹‚ i, s i βŠ† t := iInf_le_of_le i h /-- This rather trivial consequence of `subset_iUnionβ‚‚` is convenient with `apply`, and has `i` and `j` explicit for this purpose. -/ theorem subset_iUnionβ‚‚_of_subset {s : Set Ξ±} {t : βˆ€ i, ΞΊ i β†’ Set Ξ±} (i : ΞΉ) (j : ΞΊ i) (h : s βŠ† t i j) : s βŠ† ⋃ (i) (j), t i j := le_iSupβ‚‚_of_le i j h /-- This rather trivial consequence of `iInterβ‚‚_subset` is convenient with `apply`, and has `i` and `j` explicit for this purpose. -/ theorem iInterβ‚‚_subset_of_subset {s : βˆ€ i, ΞΊ i β†’ Set Ξ±} {t : Set Ξ±} (i : ΞΉ) (j : ΞΊ i) (h : s i j βŠ† t) : β‹‚ (i) (j), s i j βŠ† t := iInfβ‚‚_le_of_le i j h theorem iUnion_mono {s t : ΞΉ β†’ Set Ξ±} (h : βˆ€ i, s i βŠ† t i) : ⋃ i, s i βŠ† ⋃ i, t i := iSup_mono h @[gcongr] theorem iUnion_mono'' {s t : ΞΉ β†’ Set Ξ±} (h : βˆ€ i, s i βŠ† t i) : iUnion s βŠ† iUnion t := iSup_mono h theorem iUnionβ‚‚_mono {s t : βˆ€ i, ΞΊ i β†’ Set Ξ±} (h : βˆ€ i j, s i j βŠ† t i j) : ⋃ (i) (j), s i j βŠ† ⋃ (i) (j), t i j := iSupβ‚‚_mono h theorem iInter_mono {s t : ΞΉ β†’ Set Ξ±} (h : βˆ€ i, s i βŠ† t i) : β‹‚ i, s i βŠ† β‹‚ i, t i := iInf_mono h @[gcongr] theorem iInter_mono'' {s t : ΞΉ β†’ Set Ξ±} (h : βˆ€ i, s i βŠ† t i) : iInter s βŠ† iInter t := iInf_mono h theorem iInterβ‚‚_mono {s t : βˆ€ i, ΞΊ i β†’ Set Ξ±} (h : βˆ€ i j, s i j βŠ† t i j) : β‹‚ (i) (j), s i j βŠ† β‹‚ (i) (j), t i j := iInfβ‚‚_mono h theorem iUnion_mono' {s : ΞΉ β†’ Set Ξ±} {t : ΞΉβ‚‚ β†’ Set Ξ±} (h : βˆ€ i, βˆƒ j, s i βŠ† t j) : ⋃ i, s i βŠ† ⋃ i, t i := iSup_mono' h theorem iUnionβ‚‚_mono' {s : βˆ€ i, ΞΊ i β†’ Set Ξ±} {t : βˆ€ i', ΞΊ' i' β†’ Set Ξ±} (h : βˆ€ i j, βˆƒ i' j', s i j βŠ† t i' j') : ⋃ (i) (j), s i j βŠ† ⋃ (i') (j'), t i' j' := iSupβ‚‚_mono' h theorem iInter_mono' {s : ΞΉ β†’ Set Ξ±} {t : ΞΉ' β†’ Set Ξ±} (h : βˆ€ j, βˆƒ i, s i βŠ† t j) : β‹‚ i, s i βŠ† β‹‚ j, t j := Set.subset_iInter fun j => let ⟨i, hi⟩ := h j iInter_subset_of_subset i hi theorem iInterβ‚‚_mono' {s : βˆ€ i, ΞΊ i β†’ Set Ξ±} {t : βˆ€ i', ΞΊ' i' β†’ Set Ξ±} (h : βˆ€ i' j', βˆƒ i j, s i j βŠ† t i' j') : β‹‚ (i) (j), s i j βŠ† β‹‚ (i') (j'), t i' j' := subset_iInterβ‚‚_iff.2 fun i' j' => let ⟨_, _, hst⟩ := h i' j' (iInterβ‚‚_subset _ _).trans hst theorem iUnionβ‚‚_subset_iUnion (ΞΊ : ΞΉ β†’ Sort*) (s : ΞΉ β†’ Set Ξ±) : ⋃ (i) (_ : ΞΊ i), s i βŠ† ⋃ i, s i := iUnion_mono fun _ => iUnion_subset fun _ => Subset.rfl theorem iInter_subset_iInterβ‚‚ (ΞΊ : ΞΉ β†’ Sort*) (s : ΞΉ β†’ Set Ξ±) : β‹‚ i, s i βŠ† β‹‚ (i) (_ : ΞΊ i), s i := iInter_mono fun _ => subset_iInter fun _ => Subset.rfl theorem iUnion_setOf (P : ΞΉ β†’ Ξ± β†’ Prop) : ⋃ i, { x : Ξ± | P i x } = { x : Ξ± | βˆƒ i, P i x } := by ext exact mem_iUnion theorem iInter_setOf (P : ΞΉ β†’ Ξ± β†’ Prop) : β‹‚ i, { x : Ξ± | P i x } = { x : Ξ± | βˆ€ i, P i x } := by ext exact mem_iInter theorem iUnion_congr_of_surjective {f : ΞΉ β†’ Set Ξ±} {g : ΞΉβ‚‚ β†’ Set Ξ±} (h : ΞΉ β†’ ΞΉβ‚‚) (h1 : Surjective h) (h2 : βˆ€ x, g (h x) = f x) : ⋃ x, f x = ⋃ y, g y := h1.iSup_congr h h2 theorem iInter_congr_of_surjective {f : ΞΉ β†’ Set Ξ±} {g : ΞΉβ‚‚ β†’ Set Ξ±} (h : ΞΉ β†’ ΞΉβ‚‚) (h1 : Surjective h) (h2 : βˆ€ x, g (h x) = f x) : β‹‚ x, f x = β‹‚ y, g y := h1.iInf_congr h h2 lemma iUnion_congr {s t : ΞΉ β†’ Set Ξ±} (h : βˆ€ i, s i = t i) : ⋃ i, s i = ⋃ i, t i := iSup_congr h lemma iInter_congr {s t : ΞΉ β†’ Set Ξ±} (h : βˆ€ i, s i = t i) : β‹‚ i, s i = β‹‚ i, t i := iInf_congr h lemma iUnionβ‚‚_congr {s t : βˆ€ i, ΞΊ i β†’ Set Ξ±} (h : βˆ€ i j, s i j = t i j) : ⋃ (i) (j), s i j = ⋃ (i) (j), t i j := iUnion_congr fun i => iUnion_congr <| h i lemma iInterβ‚‚_congr {s t : βˆ€ i, ΞΊ i β†’ Set Ξ±} (h : βˆ€ i j, s i j = t i j) : β‹‚ (i) (j), s i j = β‹‚ (i) (j), t i j := iInter_congr fun i => iInter_congr <| h i section Nonempty variable [Nonempty ΞΉ] {f : ΞΉ β†’ Set Ξ±} {s : Set Ξ±} lemma iUnion_const (s : Set Ξ²) : ⋃ _ : ΞΉ, s = s := iSup_const lemma iInter_const (s : Set Ξ²) : β‹‚ _ : ΞΉ, s = s := iInf_const lemma iUnion_eq_const (hf : βˆ€ i, f i = s) : ⋃ i, f i = s := (iUnion_congr hf).trans <| iUnion_const _ lemma iInter_eq_const (hf : βˆ€ i, f i = s) : β‹‚ i, f i = s := (iInter_congr hf).trans <| iInter_const _ end Nonempty @[simp] theorem compl_iUnion (s : ΞΉ β†’ Set Ξ²) : (⋃ i, s i)ᢜ = β‹‚ i, (s i)ᢜ := compl_iSup theorem compl_iUnionβ‚‚ (s : βˆ€ i, ΞΊ i β†’ Set Ξ±) : (⋃ (i) (j), s i j)ᢜ = β‹‚ (i) (j), (s i j)ᢜ := by simp_rw [compl_iUnion] @[simp] theorem compl_iInter (s : ΞΉ β†’ Set Ξ²) : (β‹‚ i, s i)ᢜ = ⋃ i, (s i)ᢜ := compl_iInf theorem compl_iInterβ‚‚ (s : βˆ€ i, ΞΊ i β†’ Set Ξ±) : (β‹‚ (i) (j), s i j)ᢜ = ⋃ (i) (j), (s i j)ᢜ := by simp_rw [compl_iInter] -- classical -- complete_boolean_algebra theorem iUnion_eq_compl_iInter_compl (s : ΞΉ β†’ Set Ξ²) : ⋃ i, s i = (β‹‚ i, (s i)ᢜ)ᢜ := by simp only [compl_iInter, compl_compl] -- classical -- complete_boolean_algebra theorem iInter_eq_compl_iUnion_compl (s : ΞΉ β†’ Set Ξ²) : β‹‚ i, s i = (⋃ i, (s i)ᢜ)ᢜ := by simp only [compl_iUnion, compl_compl] theorem inter_iUnion (s : Set Ξ²) (t : ΞΉ β†’ Set Ξ²) : (s ∩ ⋃ i, t i) = ⋃ i, s ∩ t i := inf_iSup_eq _ _ theorem iUnion_inter (s : Set Ξ²) (t : ΞΉ β†’ Set Ξ²) : (⋃ i, t i) ∩ s = ⋃ i, t i ∩ s := iSup_inf_eq _ _ theorem iUnion_union_distrib (s : ΞΉ β†’ Set Ξ²) (t : ΞΉ β†’ Set Ξ²) : ⋃ i, s i βˆͺ t i = (⋃ i, s i) βˆͺ ⋃ i, t i := iSup_sup_eq theorem iInter_inter_distrib (s : ΞΉ β†’ Set Ξ²) (t : ΞΉ β†’ Set Ξ²) : β‹‚ i, s i ∩ t i = (β‹‚ i, s i) ∩ β‹‚ i, t i := iInf_inf_eq theorem union_iUnion [Nonempty ΞΉ] (s : Set Ξ²) (t : ΞΉ β†’ Set Ξ²) : (s βˆͺ ⋃ i, t i) = ⋃ i, s βˆͺ t i := sup_iSup theorem iUnion_union [Nonempty ΞΉ] (s : Set Ξ²) (t : ΞΉ β†’ Set Ξ²) : (⋃ i, t i) βˆͺ s = ⋃ i, t i βˆͺ s := iSup_sup theorem inter_iInter [Nonempty ΞΉ] (s : Set Ξ²) (t : ΞΉ β†’ Set Ξ²) : (s ∩ β‹‚ i, t i) = β‹‚ i, s ∩ t i := inf_iInf theorem iInter_inter [Nonempty ΞΉ] (s : Set Ξ²) (t : ΞΉ β†’ Set Ξ²) : (β‹‚ i, t i) ∩ s = β‹‚ i, t i ∩ s := iInf_inf theorem insert_iUnion [Nonempty ΞΉ] (x : Ξ²) (t : ΞΉ β†’ Set Ξ²) : insert x (⋃ i, t i) = ⋃ i, insert x (t i) := by simp_rw [← union_singleton, iUnion_union] -- classical theorem union_iInter (s : Set Ξ²) (t : ΞΉ β†’ Set Ξ²) : (s βˆͺ β‹‚ i, t i) = β‹‚ i, s βˆͺ t i := sup_iInf_eq _ _ theorem iInter_union (s : ΞΉ β†’ Set Ξ²) (t : Set Ξ²) : (β‹‚ i, s i) βˆͺ t = β‹‚ i, s i βˆͺ t := iInf_sup_eq _ _ theorem insert_iInter (x : Ξ²) (t : ΞΉ β†’ Set Ξ²) : insert x (β‹‚ i, t i) = β‹‚ i, insert x (t i) := by simp_rw [← union_singleton, iInter_union] theorem iUnion_diff (s : Set Ξ²) (t : ΞΉ β†’ Set Ξ²) : (⋃ i, t i) \ s = ⋃ i, t i \ s := iUnion_inter _ _ theorem diff_iUnion [Nonempty ΞΉ] (s : Set Ξ²) (t : ΞΉ β†’ Set Ξ²) : (s \ ⋃ i, t i) = β‹‚ i, s \ t i := by rw [diff_eq, compl_iUnion, inter_iInter]; rfl theorem diff_iInter (s : Set Ξ²) (t : ΞΉ β†’ Set Ξ²) : (s \ β‹‚ i, t i) = ⋃ i, s \ t i := by rw [diff_eq, compl_iInter, inter_iUnion]; rfl theorem iUnion_inter_subset {ΞΉ Ξ±} {s t : ΞΉ β†’ Set Ξ±} : ⋃ i, s i ∩ t i βŠ† (⋃ i, s i) ∩ ⋃ i, t i := le_iSup_inf_iSup s t theorem iUnion_inter_of_monotone {ΞΉ Ξ±} [Preorder ΞΉ] [IsDirected ΞΉ (Β· ≀ Β·)] {s t : ΞΉ β†’ Set Ξ±} (hs : Monotone s) (ht : Monotone t) : ⋃ i, s i ∩ t i = (⋃ i, s i) ∩ ⋃ i, t i := iSup_inf_of_monotone hs ht theorem iUnion_inter_of_antitone {ΞΉ Ξ±} [Preorder ΞΉ] [IsDirected ΞΉ (swap (Β· ≀ Β·))] {s t : ΞΉ β†’ Set Ξ±} (hs : Antitone s) (ht : Antitone t) : ⋃ i, s i ∩ t i = (⋃ i, s i) ∩ ⋃ i, t i := iSup_inf_of_antitone hs ht theorem iInter_union_of_monotone {ΞΉ Ξ±} [Preorder ΞΉ] [IsDirected ΞΉ (swap (Β· ≀ Β·))] {s t : ΞΉ β†’ Set Ξ±} (hs : Monotone s) (ht : Monotone t) : β‹‚ i, s i βˆͺ t i = (β‹‚ i, s i) βˆͺ β‹‚ i, t i := iInf_sup_of_monotone hs ht theorem iInter_union_of_antitone {ΞΉ Ξ±} [Preorder ΞΉ] [IsDirected ΞΉ (Β· ≀ Β·)] {s t : ΞΉ β†’ Set Ξ±} (hs : Antitone s) (ht : Antitone t) : β‹‚ i, s i βˆͺ t i = (β‹‚ i, s i) βˆͺ β‹‚ i, t i := iInf_sup_of_antitone hs ht /-- An equality version of this lemma is `iUnion_iInter_of_monotone` in `Data.Set.Finite`. -/ theorem iUnion_iInter_subset {s : ΞΉ β†’ ΞΉ' β†’ Set Ξ±} : (⋃ j, β‹‚ i, s i j) βŠ† β‹‚ i, ⋃ j, s i j := iSup_iInf_le_iInf_iSup (flip s) theorem iUnion_option {ΞΉ} (s : Option ΞΉ β†’ Set Ξ±) : ⋃ o, s o = s none βˆͺ ⋃ i, s (some i) := iSup_option s theorem iInter_option {ΞΉ} (s : Option ΞΉ β†’ Set Ξ±) : β‹‚ o, s o = s none ∩ β‹‚ i, s (some i) := iInf_option s section variable (p : ΞΉ β†’ Prop) [DecidablePred p] theorem iUnion_dite (f : βˆ€ i, p i β†’ Set Ξ±) (g : βˆ€ i, Β¬p i β†’ Set Ξ±) : ⋃ i, (if h : p i then f i h else g i h) = (⋃ (i) (h : p i), f i h) βˆͺ ⋃ (i) (h : Β¬p i), g i h := iSup_dite _ _ _ theorem iUnion_ite (f g : ΞΉ β†’ Set Ξ±) : ⋃ i, (if p i then f i else g i) = (⋃ (i) (_ : p i), f i) βˆͺ ⋃ (i) (_ : Β¬p i), g i := iUnion_dite _ _ _ theorem iInter_dite (f : βˆ€ i, p i β†’ Set Ξ±) (g : βˆ€ i, Β¬p i β†’ Set Ξ±) : β‹‚ i, (if h : p i then f i h else g i h) = (β‹‚ (i) (h : p i), f i h) ∩ β‹‚ (i) (h : Β¬p i), g i h := iInf_dite _ _ _ theorem iInter_ite (f g : ΞΉ β†’ Set Ξ±) : β‹‚ i, (if p i then f i else g i) = (β‹‚ (i) (_ : p i), f i) ∩ β‹‚ (i) (_ : Β¬p i), g i := iInter_dite _ _ _ end /-! ### Unions and intersections indexed by `Prop` -/ theorem iInter_false {s : False β†’ Set Ξ±} : iInter s = univ := iInf_false theorem iUnion_false {s : False β†’ Set Ξ±} : iUnion s = βˆ… := iSup_false @[simp] theorem iInter_true {s : True β†’ Set Ξ±} : iInter s = s trivial := iInf_true @[simp] theorem iUnion_true {s : True β†’ Set Ξ±} : iUnion s = s trivial := iSup_true @[simp] theorem iInter_exists {p : ΞΉ β†’ Prop} {f : Exists p β†’ Set Ξ±} : β‹‚ x, f x = β‹‚ (i) (h : p i), f ⟨i, h⟩ := iInf_exists @[simp] theorem iUnion_exists {p : ΞΉ β†’ Prop} {f : Exists p β†’ Set Ξ±} : ⋃ x, f x = ⋃ (i) (h : p i), f ⟨i, h⟩ := iSup_exists @[simp] theorem iUnion_empty : (⋃ _ : ΞΉ, βˆ… : Set Ξ±) = βˆ… := iSup_bot @[simp] theorem iInter_univ : (β‹‚ _ : ΞΉ, univ : Set Ξ±) = univ := iInf_top section variable {s : ΞΉ β†’ Set Ξ±} @[simp] theorem iUnion_eq_empty : ⋃ i, s i = βˆ… ↔ βˆ€ i, s i = βˆ… := iSup_eq_bot @[simp] theorem iInter_eq_univ : β‹‚ i, s i = univ ↔ βˆ€ i, s i = univ := iInf_eq_top @[simp] theorem nonempty_iUnion : (⋃ i, s i).Nonempty ↔ βˆƒ i, (s i).Nonempty := by simp [nonempty_iff_ne_empty] theorem nonempty_biUnion {t : Set Ξ±} {s : Ξ± β†’ Set Ξ²} : (⋃ i ∈ t, s i).Nonempty ↔ βˆƒ i ∈ t, (s i).Nonempty := by simp theorem iUnion_nonempty_index (s : Set Ξ±) (t : s.Nonempty β†’ Set Ξ²) : ⋃ h, t h = ⋃ x ∈ s, t ⟨x, β€Ή_β€ΊβŸ© := iSup_exists end @[simp] theorem iInter_iInter_eq_left {b : Ξ²} {s : βˆ€ x : Ξ², x = b β†’ Set Ξ±} : β‹‚ (x) (h : x = b), s x h = s b rfl := iInf_iInf_eq_left @[simp] theorem iInter_iInter_eq_right {b : Ξ²} {s : βˆ€ x : Ξ², b = x β†’ Set Ξ±} : β‹‚ (x) (h : b = x), s x h = s b rfl := iInf_iInf_eq_right @[simp] theorem iUnion_iUnion_eq_left {b : Ξ²} {s : βˆ€ x : Ξ², x = b β†’ Set Ξ±} : ⋃ (x) (h : x = b), s x h = s b rfl := iSup_iSup_eq_left @[simp] theorem iUnion_iUnion_eq_right {b : Ξ²} {s : βˆ€ x : Ξ², b = x β†’ Set Ξ±} : ⋃ (x) (h : b = x), s x h = s b rfl := iSup_iSup_eq_right theorem iInter_or {p q : Prop} (s : p ∨ q β†’ Set Ξ±) : β‹‚ h, s h = (β‹‚ h : p, s (Or.inl h)) ∩ β‹‚ h : q, s (Or.inr h) := iInf_or theorem iUnion_or {p q : Prop} (s : p ∨ q β†’ Set Ξ±) : ⋃ h, s h = (⋃ i, s (Or.inl i)) βˆͺ ⋃ j, s (Or.inr j) := iSup_or theorem iUnion_and {p q : Prop} (s : p ∧ q β†’ Set Ξ±) : ⋃ h, s h = ⋃ (hp) (hq), s ⟨hp, hq⟩ := iSup_and theorem iInter_and {p q : Prop} (s : p ∧ q β†’ Set Ξ±) : β‹‚ h, s h = β‹‚ (hp) (hq), s ⟨hp, hq⟩ := iInf_and theorem iUnion_comm (s : ΞΉ β†’ ΞΉ' β†’ Set Ξ±) : ⋃ (i) (i'), s i i' = ⋃ (i') (i), s i i' := iSup_comm theorem iInter_comm (s : ΞΉ β†’ ΞΉ' β†’ Set Ξ±) : β‹‚ (i) (i'), s i i' = β‹‚ (i') (i), s i i' := iInf_comm theorem iUnion_sigma {Ξ³ : Ξ± β†’ Type*} (s : Sigma Ξ³ β†’ Set Ξ²) : ⋃ ia, s ia = ⋃ i, ⋃ a, s ⟨i, a⟩ := iSup_sigma theorem iUnion_sigma' {Ξ³ : Ξ± β†’ Type*} (s : βˆ€ i, Ξ³ i β†’ Set Ξ²) : ⋃ i, ⋃ a, s i a = ⋃ ia : Sigma Ξ³, s ia.1 ia.2 := iSup_sigma' _ theorem iInter_sigma {Ξ³ : Ξ± β†’ Type*} (s : Sigma Ξ³ β†’ Set Ξ²) : β‹‚ ia, s ia = β‹‚ i, β‹‚ a, s ⟨i, a⟩ := iInf_sigma theorem iInter_sigma' {Ξ³ : Ξ± β†’ Type*} (s : βˆ€ i, Ξ³ i β†’ Set Ξ²) : β‹‚ i, β‹‚ a, s i a = β‹‚ ia : Sigma Ξ³, s ia.1 ia.2 := iInf_sigma' _ theorem iUnionβ‚‚_comm (s : βˆ€ i₁, κ₁ i₁ β†’ βˆ€ iβ‚‚, ΞΊβ‚‚ iβ‚‚ β†’ Set Ξ±) : ⋃ (i₁) (j₁) (iβ‚‚) (jβ‚‚), s i₁ j₁ iβ‚‚ jβ‚‚ = ⋃ (iβ‚‚) (jβ‚‚) (i₁) (j₁), s i₁ j₁ iβ‚‚ jβ‚‚ := iSupβ‚‚_comm _ theorem iInterβ‚‚_comm (s : βˆ€ i₁, κ₁ i₁ β†’ βˆ€ iβ‚‚, ΞΊβ‚‚ iβ‚‚ β†’ Set Ξ±) : β‹‚ (i₁) (j₁) (iβ‚‚) (jβ‚‚), s i₁ j₁ iβ‚‚ jβ‚‚ = β‹‚ (iβ‚‚) (jβ‚‚) (i₁) (j₁), s i₁ j₁ iβ‚‚ jβ‚‚ := iInfβ‚‚_comm _ @[simp] theorem biUnion_and (p : ΞΉ β†’ Prop) (q : ΞΉ β†’ ΞΉ' β†’ Prop) (s : βˆ€ x y, p x ∧ q x y β†’ Set Ξ±) : ⋃ (x : ΞΉ) (y : ΞΉ') (h : p x ∧ q x y), s x y h = ⋃ (x : ΞΉ) (hx : p x) (y : ΞΉ') (hy : q x y), s x y ⟨hx, hy⟩ := by simp only [iUnion_and, @iUnion_comm _ ΞΉ'] @[simp] theorem biUnion_and' (p : ΞΉ' β†’ Prop) (q : ΞΉ β†’ ΞΉ' β†’ Prop) (s : βˆ€ x y, p y ∧ q x y β†’ Set Ξ±) : ⋃ (x : ΞΉ) (y : ΞΉ') (h : p y ∧ q x y), s x y h = ⋃ (y : ΞΉ') (hy : p y) (x : ΞΉ) (hx : q x y), s x y ⟨hy, hx⟩ := by simp only [iUnion_and, @iUnion_comm _ ΞΉ] @[simp] theorem biInter_and (p : ΞΉ β†’ Prop) (q : ΞΉ β†’ ΞΉ' β†’ Prop) (s : βˆ€ x y, p x ∧ q x y β†’ Set Ξ±) : β‹‚ (x : ΞΉ) (y : ΞΉ') (h : p x ∧ q x y), s x y h = β‹‚ (x : ΞΉ) (hx : p x) (y : ΞΉ') (hy : q x y), s x y ⟨hx, hy⟩ := by simp only [iInter_and, @iInter_comm _ ΞΉ'] @[simp] theorem biInter_and' (p : ΞΉ' β†’ Prop) (q : ΞΉ β†’ ΞΉ' β†’ Prop) (s : βˆ€ x y, p y ∧ q x y β†’ Set Ξ±) : β‹‚ (x : ΞΉ) (y : ΞΉ') (h : p y ∧ q x y), s x y h = β‹‚ (y : ΞΉ') (hy : p y) (x : ΞΉ) (hx : q x y), s x y ⟨hy, hx⟩ := by simp only [iInter_and, @iInter_comm _ ΞΉ] @[simp] theorem iUnion_iUnion_eq_or_left {b : Ξ²} {p : Ξ² β†’ Prop} {s : βˆ€ x : Ξ², x = b ∨ p x β†’ Set Ξ±} : ⋃ (x) (h), s x h = s b (Or.inl rfl) βˆͺ ⋃ (x) (h : p x), s x (Or.inr h) := by simp only [iUnion_or, iUnion_union_distrib, iUnion_iUnion_eq_left] @[simp] theorem iInter_iInter_eq_or_left {b : Ξ²} {p : Ξ² β†’ Prop} {s : βˆ€ x : Ξ², x = b ∨ p x β†’ Set Ξ±} : β‹‚ (x) (h), s x h = s b (Or.inl rfl) ∩ β‹‚ (x) (h : p x), s x (Or.inr h) := by simp only [iInter_or, iInter_inter_distrib, iInter_iInter_eq_left] lemma iUnion_sum {s : Ξ± βŠ• Ξ² β†’ Set Ξ³} : ⋃ x, s x = (⋃ x, s (.inl x)) βˆͺ ⋃ x, s (.inr x) := iSup_sum lemma iInter_sum {s : Ξ± βŠ• Ξ² β†’ Set Ξ³} : β‹‚ x, s x = (β‹‚ x, s (.inl x)) ∩ β‹‚ x, s (.inr x) := iInf_sum theorem iUnion_psigma {Ξ³ : Ξ± β†’ Type*} (s : PSigma Ξ³ β†’ Set Ξ²) : ⋃ ia, s ia = ⋃ i, ⋃ a, s ⟨i, a⟩ := iSup_psigma _ /-- A reversed version of `iUnion_psigma` with a curried map. -/ theorem iUnion_psigma' {Ξ³ : Ξ± β†’ Type*} (s : βˆ€ i, Ξ³ i β†’ Set Ξ²) : ⋃ i, ⋃ a, s i a = ⋃ ia : PSigma Ξ³, s ia.1 ia.2 := iSup_psigma' _ theorem iInter_psigma {Ξ³ : Ξ± β†’ Type*} (s : PSigma Ξ³ β†’ Set Ξ²) : β‹‚ ia, s ia = β‹‚ i, β‹‚ a, s ⟨i, a⟩ := iInf_psigma _ /-- A reversed version of `iInter_psigma` with a curried map. -/ theorem iInter_psigma' {Ξ³ : Ξ± β†’ Type*} (s : βˆ€ i, Ξ³ i β†’ Set Ξ²) : β‹‚ i, β‹‚ a, s i a = β‹‚ ia : PSigma Ξ³, s ia.1 ia.2 := iInf_psigma' _ /-! ### Bounded unions and intersections -/ /-- A specialization of `mem_iUnionβ‚‚`. -/ theorem mem_biUnion {s : Set Ξ±} {t : Ξ± β†’ Set Ξ²} {x : Ξ±} {y : Ξ²} (xs : x ∈ s) (ytx : y ∈ t x) : y ∈ ⋃ x ∈ s, t x := mem_iUnionβ‚‚_of_mem xs ytx /-- A specialization of `mem_iInterβ‚‚`. -/ theorem mem_biInter {s : Set Ξ±} {t : Ξ± β†’ Set Ξ²} {y : Ξ²} (h : βˆ€ x ∈ s, y ∈ t x) : y ∈ β‹‚ x ∈ s, t x := mem_iInterβ‚‚_of_mem h /-- A specialization of `subset_iUnionβ‚‚`. -/ theorem subset_biUnion_of_mem {s : Set Ξ±} {u : Ξ± β†’ Set Ξ²} {x : Ξ±} (xs : x ∈ s) : u x βŠ† ⋃ x ∈ s, u x := subset_iUnionβ‚‚ (s := fun i _ => u i) x xs /-- A specialization of `iInterβ‚‚_subset`. -/ theorem biInter_subset_of_mem {s : Set Ξ±} {t : Ξ± β†’ Set Ξ²} {x : Ξ±} (xs : x ∈ s) : β‹‚ x ∈ s, t x βŠ† t x := iInterβ‚‚_subset x xs lemma biInter_subset_biUnion {s : Set Ξ±} (hs : s.Nonempty) {t : Ξ± β†’ Set Ξ²} : β‹‚ x ∈ s, t x βŠ† ⋃ x ∈ s, t x := biInf_le_biSup hs theorem biUnion_subset_biUnion_left {s s' : Set Ξ±} {t : Ξ± β†’ Set Ξ²} (h : s βŠ† s') : ⋃ x ∈ s, t x βŠ† ⋃ x ∈ s', t x := iUnionβ‚‚_subset fun _ hx => subset_biUnion_of_mem <| h hx theorem biInter_subset_biInter_left {s s' : Set Ξ±} {t : Ξ± β†’ Set Ξ²} (h : s' βŠ† s) : β‹‚ x ∈ s, t x βŠ† β‹‚ x ∈ s', t x := subset_iInterβ‚‚ fun _ hx => biInter_subset_of_mem <| h hx theorem biUnion_mono {s s' : Set Ξ±} {t t' : Ξ± β†’ Set Ξ²} (hs : s' βŠ† s) (h : βˆ€ x ∈ s, t x βŠ† t' x) : ⋃ x ∈ s', t x βŠ† ⋃ x ∈ s, t' x := (biUnion_subset_biUnion_left hs).trans <| iUnionβ‚‚_mono h theorem biInter_mono {s s' : Set Ξ±} {t t' : Ξ± β†’ Set Ξ²} (hs : s βŠ† s') (h : βˆ€ x ∈ s, t x βŠ† t' x) : β‹‚ x ∈ s', t x βŠ† β‹‚ x ∈ s, t' x := (biInter_subset_biInter_left hs).trans <| iInterβ‚‚_mono h theorem biUnion_eq_iUnion (s : Set Ξ±) (t : βˆ€ x ∈ s, Set Ξ²) : ⋃ x ∈ s, t x β€Ή_β€Ί = ⋃ x : s, t x x.2 := iSup_subtype' theorem biInter_eq_iInter (s : Set Ξ±) (t : βˆ€ x ∈ s, Set Ξ²) : β‹‚ x ∈ s, t x β€Ή_β€Ί = β‹‚ x : s, t x x.2 := iInf_subtype' @[simp] lemma biUnion_const {s : Set Ξ±} (hs : s.Nonempty) (t : Set Ξ²) : ⋃ a ∈ s, t = t := biSup_const hs @[simp] lemma biInter_const {s : Set Ξ±} (hs : s.Nonempty) (t : Set Ξ²) : β‹‚ a ∈ s, t = t := biInf_const hs theorem iUnion_subtype (p : Ξ± β†’ Prop) (s : { x // p x } β†’ Set Ξ²) : ⋃ x : { x // p x }, s x = ⋃ (x) (hx : p x), s ⟨x, hx⟩ := iSup_subtype theorem iInter_subtype (p : Ξ± β†’ Prop) (s : { x // p x } β†’ Set Ξ²) : β‹‚ x : { x // p x }, s x = β‹‚ (x) (hx : p x), s ⟨x, hx⟩ := iInf_subtype theorem biInter_empty (u : Ξ± β†’ Set Ξ²) : β‹‚ x ∈ (βˆ… : Set Ξ±), u x = univ := iInf_emptyset theorem biInter_univ (u : Ξ± β†’ Set Ξ²) : β‹‚ x ∈ @univ Ξ±, u x = β‹‚ x, u x := iInf_univ @[simp] theorem biUnion_self (s : Set Ξ±) : ⋃ x ∈ s, s = s := Subset.antisymm (iUnionβ‚‚_subset fun _ _ => Subset.refl s) fun _ hx => mem_biUnion hx hx @[simp] theorem iUnion_nonempty_self (s : Set Ξ±) : ⋃ _ : s.Nonempty, s = s := by rw [iUnion_nonempty_index, biUnion_self] theorem biInter_singleton (a : Ξ±) (s : Ξ± β†’ Set Ξ²) : β‹‚ x ∈ ({a} : Set Ξ±), s x = s a := iInf_singleton theorem biInter_union (s t : Set Ξ±) (u : Ξ± β†’ Set Ξ²) : β‹‚ x ∈ s βˆͺ t, u x = (β‹‚ x ∈ s, u x) ∩ β‹‚ x ∈ t, u x := iInf_union theorem biInter_insert (a : Ξ±) (s : Set Ξ±) (t : Ξ± β†’ Set Ξ²) : β‹‚ x ∈ insert a s, t x = t a ∩ β‹‚ x ∈ s, t x := by simp theorem biInter_pair (a b : Ξ±) (s : Ξ± β†’ Set Ξ²) : β‹‚ x ∈ ({a, b} : Set Ξ±), s x = s a ∩ s b := by rw [biInter_insert, biInter_singleton] theorem biInter_inter {ΞΉ Ξ± : Type*} {s : Set ΞΉ} (hs : s.Nonempty) (f : ΞΉ β†’ Set Ξ±) (t : Set Ξ±) : β‹‚ i ∈ s, f i ∩ t = (β‹‚ i ∈ s, f i) ∩ t := by haveI : Nonempty s := hs.to_subtype simp [biInter_eq_iInter, ← iInter_inter] theorem inter_biInter {ΞΉ Ξ± : Type*} {s : Set ΞΉ} (hs : s.Nonempty) (f : ΞΉ β†’ Set Ξ±) (t : Set Ξ±) : β‹‚ i ∈ s, t ∩ f i = t ∩ β‹‚ i ∈ s, f i := by rw [inter_comm, ← biInter_inter hs] simp [inter_comm] theorem biUnion_empty (s : Ξ± β†’ Set Ξ²) : ⋃ x ∈ (βˆ… : Set Ξ±), s x = βˆ… := iSup_emptyset theorem biUnion_univ (s : Ξ± β†’ Set Ξ²) : ⋃ x ∈ @univ Ξ±, s x = ⋃ x, s x := iSup_univ theorem biUnion_singleton (a : Ξ±) (s : Ξ± β†’ Set Ξ²) : ⋃ x ∈ ({a} : Set Ξ±), s x = s a := iSup_singleton @[simp] theorem biUnion_of_singleton (s : Set Ξ±) : ⋃ x ∈ s, {x} = s := ext <| by simp theorem biUnion_union (s t : Set Ξ±) (u : Ξ± β†’ Set Ξ²) : ⋃ x ∈ s βˆͺ t, u x = (⋃ x ∈ s, u x) βˆͺ ⋃ x ∈ t, u x := iSup_union @[simp] theorem iUnion_coe_set {Ξ± Ξ² : Type*} (s : Set Ξ±) (f : s β†’ Set Ξ²) : ⋃ i, f i = ⋃ i ∈ s, f ⟨i, β€Ήi ∈ sβ€ΊβŸ© := iUnion_subtype _ _ @[simp] theorem iInter_coe_set {Ξ± Ξ² : Type*} (s : Set Ξ±) (f : s β†’ Set Ξ²) : β‹‚ i, f i = β‹‚ i ∈ s, f ⟨i, β€Ήi ∈ sβ€ΊβŸ© := iInter_subtype _ _ theorem biUnion_insert (a : Ξ±) (s : Set Ξ±) (t : Ξ± β†’ Set Ξ²) : ⋃ x ∈ insert a s, t x = t a βˆͺ ⋃ x ∈ s, t x := by simp theorem biUnion_pair (a b : Ξ±) (s : Ξ± β†’ Set Ξ²) : ⋃ x ∈ ({a, b} : Set Ξ±), s x = s a βˆͺ s b := by simp theorem inter_iUnionβ‚‚ (s : Set Ξ±) (t : βˆ€ i, ΞΊ i β†’ Set Ξ±) : (s ∩ ⋃ (i) (j), t i j) = ⋃ (i) (j), s ∩ t i j := by simp only [inter_iUnion] theorem iUnionβ‚‚_inter (s : βˆ€ i, ΞΊ i β†’ Set Ξ±) (t : Set Ξ±) : (⋃ (i) (j), s i j) ∩ t = ⋃ (i) (j), s i j ∩ t := by simp_rw [iUnion_inter] theorem union_iInterβ‚‚ (s : Set Ξ±) (t : βˆ€ i, ΞΊ i β†’ Set Ξ±) : (s βˆͺ β‹‚ (i) (j), t i j) = β‹‚ (i) (j), s βˆͺ t i j := by simp_rw [union_iInter] theorem iInterβ‚‚_union (s : βˆ€ i, ΞΊ i β†’ Set Ξ±) (t : Set Ξ±) : (β‹‚ (i) (j), s i j) βˆͺ t = β‹‚ (i) (j), s i j βˆͺ t := by simp_rw [iInter_union] theorem mem_sUnion_of_mem {x : Ξ±} {t : Set Ξ±} {S : Set (Set Ξ±)} (hx : x ∈ t) (ht : t ∈ S) : x ∈ ⋃₀ S := ⟨t, ht, hx⟩ -- is this theorem really necessary? theorem not_mem_of_not_mem_sUnion {x : Ξ±} {t : Set Ξ±} {S : Set (Set Ξ±)} (hx : x βˆ‰ ⋃₀ S) (ht : t ∈ S) : x βˆ‰ t := fun h => hx ⟨t, ht, h⟩ theorem sInter_subset_of_mem {S : Set (Set Ξ±)} {t : Set Ξ±} (tS : t ∈ S) : β‹‚β‚€ S βŠ† t := sInf_le tS theorem subset_sUnion_of_mem {S : Set (Set Ξ±)} {t : Set Ξ±} (tS : t ∈ S) : t βŠ† ⋃₀ S := le_sSup tS theorem subset_sUnion_of_subset {s : Set Ξ±} (t : Set (Set Ξ±)) (u : Set Ξ±) (h₁ : s βŠ† u) (hβ‚‚ : u ∈ t) : s βŠ† ⋃₀ t := Subset.trans h₁ (subset_sUnion_of_mem hβ‚‚) theorem sUnion_subset {S : Set (Set Ξ±)} {t : Set Ξ±} (h : βˆ€ t' ∈ S, t' βŠ† t) : ⋃₀ S βŠ† t := sSup_le h @[simp] theorem sUnion_subset_iff {s : Set (Set Ξ±)} {t : Set Ξ±} : ⋃₀ s βŠ† t ↔ βˆ€ t' ∈ s, t' βŠ† t := sSup_le_iff /-- `sUnion` is monotone under taking a subset of each set. -/ lemma sUnion_mono_subsets {s : Set (Set Ξ±)} {f : Set Ξ± β†’ Set Ξ±} (hf : βˆ€ t : Set Ξ±, t βŠ† f t) : ⋃₀ s βŠ† ⋃₀ (f '' s) := fun _ ⟨t, htx, hxt⟩ ↦ ⟨f t, mem_image_of_mem f htx, hf t hxt⟩ /-- `sUnion` is monotone under taking a superset of each set. -/ lemma sUnion_mono_supsets {s : Set (Set Ξ±)} {f : Set Ξ± β†’ Set Ξ±} (hf : βˆ€ t : Set Ξ±, f t βŠ† t) : ⋃₀ (f '' s) βŠ† ⋃₀ s := -- If t ∈ f '' s is arbitrary; t = f u for some u : Set Ξ±. fun _ ⟨_, ⟨u, hus, hut⟩, hxt⟩ ↦ ⟨u, hus, (hut β–Έ hf u) hxt⟩ theorem subset_sInter {S : Set (Set Ξ±)} {t : Set Ξ±} (h : βˆ€ t' ∈ S, t βŠ† t') : t βŠ† β‹‚β‚€ S := le_sInf h @[simp] theorem subset_sInter_iff {S : Set (Set Ξ±)} {t : Set Ξ±} : t βŠ† β‹‚β‚€ S ↔ βˆ€ t' ∈ S, t βŠ† t' := le_sInf_iff @[gcongr] theorem sUnion_subset_sUnion {S T : Set (Set Ξ±)} (h : S βŠ† T) : ⋃₀ S βŠ† ⋃₀ T := sUnion_subset fun _ hs => subset_sUnion_of_mem (h hs) @[gcongr] theorem sInter_subset_sInter {S T : Set (Set Ξ±)} (h : S βŠ† T) : β‹‚β‚€ T βŠ† β‹‚β‚€ S := subset_sInter fun _ hs => sInter_subset_of_mem (h hs) @[simp] theorem sUnion_empty : ⋃₀ βˆ… = (βˆ… : Set Ξ±) := sSup_empty @[simp] theorem sInter_empty : β‹‚β‚€ βˆ… = (univ : Set Ξ±) := sInf_empty @[simp] theorem sUnion_singleton (s : Set Ξ±) : ⋃₀ {s} = s := sSup_singleton @[simp] theorem sInter_singleton (s : Set Ξ±) : β‹‚β‚€ {s} = s := sInf_singleton @[simp] theorem sUnion_eq_empty {S : Set (Set Ξ±)} : ⋃₀ S = βˆ… ↔ βˆ€ s ∈ S, s = βˆ… := sSup_eq_bot @[simp] theorem sInter_eq_univ {S : Set (Set Ξ±)} : β‹‚β‚€ S = univ ↔ βˆ€ s ∈ S, s = univ := sInf_eq_top theorem subset_powerset_iff {s : Set (Set Ξ±)} {t : Set Ξ±} : s βŠ† 𝒫 t ↔ ⋃₀ s βŠ† t := sUnion_subset_iff.symm /-- `⋃₀` and `𝒫` form a Galois connection. -/ theorem sUnion_powerset_gc : GaloisConnection (⋃₀ Β· : Set (Set Ξ±) β†’ Set Ξ±) (𝒫 Β· : Set Ξ± β†’ Set (Set Ξ±)) := gc_sSup_Iic /-- `⋃₀` and `𝒫` form a Galois insertion. -/ def sUnionPowersetGI : GaloisInsertion (⋃₀ Β· : Set (Set Ξ±) β†’ Set Ξ±) (𝒫 Β· : Set Ξ± β†’ Set (Set Ξ±)) := gi_sSup_Iic @[deprecated (since := "2024-12-07")] alias sUnion_powerset_gi := sUnionPowersetGI /-- If all sets in a collection are either `βˆ…` or `Set.univ`, then so is their union. -/ theorem sUnion_mem_empty_univ {S : Set (Set Ξ±)} (h : S βŠ† {βˆ…, univ}) : ⋃₀ S ∈ ({βˆ…, univ} : Set (Set Ξ±)) := by simp only [mem_insert_iff, mem_singleton_iff, or_iff_not_imp_left, sUnion_eq_empty, not_forall] rintro ⟨s, hs, hne⟩ obtain rfl : s = univ := (h hs).resolve_left hne exact univ_subset_iff.1 <| subset_sUnion_of_mem hs @[simp] theorem nonempty_sUnion {S : Set (Set Ξ±)} : (⋃₀ S).Nonempty ↔ βˆƒ s ∈ S, Set.Nonempty s := by simp [nonempty_iff_ne_empty] theorem Nonempty.of_sUnion {s : Set (Set Ξ±)} (h : (⋃₀ s).Nonempty) : s.Nonempty := let ⟨s, hs, _⟩ := nonempty_sUnion.1 h ⟨s, hs⟩ theorem Nonempty.of_sUnion_eq_univ [Nonempty Ξ±] {s : Set (Set Ξ±)} (h : ⋃₀ s = univ) : s.Nonempty := Nonempty.of_sUnion <| h.symm β–Έ univ_nonempty theorem sUnion_union (S T : Set (Set Ξ±)) : ⋃₀ (S βˆͺ T) = ⋃₀ S βˆͺ ⋃₀ T := sSup_union theorem sInter_union (S T : Set (Set Ξ±)) : β‹‚β‚€ (S βˆͺ T) = β‹‚β‚€ S ∩ β‹‚β‚€ T := sInf_union @[simp] theorem sUnion_insert (s : Set Ξ±) (T : Set (Set Ξ±)) : ⋃₀ insert s T = s βˆͺ ⋃₀ T := sSup_insert @[simp] theorem sInter_insert (s : Set Ξ±) (T : Set (Set Ξ±)) : β‹‚β‚€ insert s T = s ∩ β‹‚β‚€ T := sInf_insert @[simp] theorem sUnion_diff_singleton_empty (s : Set (Set Ξ±)) : ⋃₀ (s \ {βˆ…}) = ⋃₀ s := sSup_diff_singleton_bot s @[simp] theorem sInter_diff_singleton_univ (s : Set (Set Ξ±)) : β‹‚β‚€ (s \ {univ}) = β‹‚β‚€ s := sInf_diff_singleton_top s theorem sUnion_pair (s t : Set Ξ±) : ⋃₀ {s, t} = s βˆͺ t := sSup_pair theorem sInter_pair (s t : Set Ξ±) : β‹‚β‚€ {s, t} = s ∩ t := sInf_pair @[simp] theorem sUnion_image (f : Ξ± β†’ Set Ξ²) (s : Set Ξ±) : ⋃₀ (f '' s) = ⋃ a ∈ s, f a := sSup_image @[simp] theorem sInter_image (f : Ξ± β†’ Set Ξ²) (s : Set Ξ±) : β‹‚β‚€ (f '' s) = β‹‚ a ∈ s, f a := sInf_image @[simp] lemma sUnion_image2 (f : Ξ± β†’ Ξ² β†’ Set Ξ³) (s : Set Ξ±) (t : Set Ξ²) : ⋃₀ (image2 f s t) = ⋃ (a ∈ s) (b ∈ t), f a b := sSup_image2 @[simp] lemma sInter_image2 (f : Ξ± β†’ Ξ² β†’ Set Ξ³) (s : Set Ξ±) (t : Set Ξ²) : β‹‚β‚€ (image2 f s t) = β‹‚ (a ∈ s) (b ∈ t), f a b := sInf_image2 @[simp] theorem sUnion_range (f : ΞΉ β†’ Set Ξ²) : ⋃₀ range f = ⋃ x, f x := rfl @[simp] theorem sInter_range (f : ΞΉ β†’ Set Ξ²) : β‹‚β‚€ range f = β‹‚ x, f x := rfl theorem iUnion_eq_univ_iff {f : ΞΉ β†’ Set Ξ±} : ⋃ i, f i = univ ↔ βˆ€ x, βˆƒ i, x ∈ f i := by simp only [eq_univ_iff_forall, mem_iUnion] theorem iUnionβ‚‚_eq_univ_iff {s : βˆ€ i, ΞΊ i β†’ Set Ξ±} : ⋃ (i) (j), s i j = univ ↔ βˆ€ a, βˆƒ i j, a ∈ s i j := by simp only [iUnion_eq_univ_iff, mem_iUnion] theorem sUnion_eq_univ_iff {c : Set (Set Ξ±)} : ⋃₀ c = univ ↔ βˆ€ a, βˆƒ b ∈ c, a ∈ b := by simp only [eq_univ_iff_forall, mem_sUnion] -- classical theorem iInter_eq_empty_iff {f : ΞΉ β†’ Set Ξ±} : β‹‚ i, f i = βˆ… ↔ βˆ€ x, βˆƒ i, x βˆ‰ f i := by simp [Set.eq_empty_iff_forall_not_mem] -- classical theorem iInterβ‚‚_eq_empty_iff {s : βˆ€ i, ΞΊ i β†’ Set Ξ±} : β‹‚ (i) (j), s i j = βˆ… ↔ βˆ€ a, βˆƒ i j, a βˆ‰ s i j := by simp only [eq_empty_iff_forall_not_mem, mem_iInter, not_forall] -- classical theorem sInter_eq_empty_iff {c : Set (Set Ξ±)} : β‹‚β‚€ c = βˆ… ↔ βˆ€ a, βˆƒ b ∈ c, a βˆ‰ b := by simp [Set.eq_empty_iff_forall_not_mem] -- classical @[simp] theorem nonempty_iInter {f : ΞΉ β†’ Set Ξ±} : (β‹‚ i, f i).Nonempty ↔ βˆƒ x, βˆ€ i, x ∈ f i := by simp [nonempty_iff_ne_empty, iInter_eq_empty_iff] -- classical theorem nonempty_iInterβ‚‚ {s : βˆ€ i, ΞΊ i β†’ Set Ξ±} : (β‹‚ (i) (j), s i j).Nonempty ↔ βˆƒ a, βˆ€ i j, a ∈ s i j := by simp -- classical @[simp] theorem nonempty_sInter {c : Set (Set Ξ±)} : (β‹‚β‚€ c).Nonempty ↔ βˆƒ a, βˆ€ b ∈ c, a ∈ b := by simp [nonempty_iff_ne_empty, sInter_eq_empty_iff] -- classical theorem compl_sUnion (S : Set (Set Ξ±)) : (⋃₀ S)ᢜ = β‹‚β‚€ (compl '' S) := ext fun x => by simp -- classical theorem sUnion_eq_compl_sInter_compl (S : Set (Set Ξ±)) : ⋃₀ S = (β‹‚β‚€ (compl '' S))ᢜ := by rw [← compl_compl (⋃₀ S), compl_sUnion] -- classical theorem compl_sInter (S : Set (Set Ξ±)) : (β‹‚β‚€ S)ᢜ = ⋃₀ (compl '' S) := by rw [sUnion_eq_compl_sInter_compl, compl_compl_image] -- classical theorem sInter_eq_compl_sUnion_compl (S : Set (Set Ξ±)) : β‹‚β‚€ S = (⋃₀ (compl '' S))ᢜ := by rw [← compl_compl (β‹‚β‚€ S), compl_sInter] theorem inter_empty_of_inter_sUnion_empty {s t : Set Ξ±} {S : Set (Set Ξ±)} (hs : t ∈ S) (h : s ∩ ⋃₀ S = βˆ…) : s ∩ t = βˆ… := eq_empty_of_subset_empty <| by rw [← h]; exact inter_subset_inter_right _ (subset_sUnion_of_mem hs) theorem range_sigma_eq_iUnion_range {Ξ³ : Ξ± β†’ Type*} (f : Sigma Ξ³ β†’ Ξ²) : range f = ⋃ a, range fun b => f ⟨a, b⟩ := Set.ext <| by simp theorem iUnion_eq_range_sigma (s : Ξ± β†’ Set Ξ²) : ⋃ i, s i = range fun a : Ξ£i, s i => a.2 := by simp [Set.ext_iff] theorem iUnion_eq_range_psigma (s : ΞΉ β†’ Set Ξ²) : ⋃ i, s i = range fun a : Ξ£'i, s i => a.2 := by simp [Set.ext_iff] theorem iUnion_image_preimage_sigma_mk_eq_self {ΞΉ : Type*} {Οƒ : ΞΉ β†’ Type*} (s : Set (Sigma Οƒ)) : ⋃ i, Sigma.mk i '' (Sigma.mk i ⁻¹' s) = s := by ext x simp only [mem_iUnion, mem_image, mem_preimage] constructor Β· rintro ⟨i, a, h, rfl⟩ exact h Β· intro h obtain ⟨i, a⟩ := x exact ⟨i, a, h, rfl⟩ theorem Sigma.univ (X : Ξ± β†’ Type*) : (Set.univ : Set (Ξ£a, X a)) = ⋃ a, range (Sigma.mk a) := Set.ext fun x => iff_of_true trivial ⟨range (Sigma.mk x.1), Set.mem_range_self _, x.2, Sigma.eta x⟩ alias sUnion_mono := sUnion_subset_sUnion alias sInter_mono := sInter_subset_sInter theorem iUnion_subset_iUnion_const {s : Set Ξ±} (h : ΞΉ β†’ ΞΉβ‚‚) : ⋃ _ : ΞΉ, s βŠ† ⋃ _ : ΞΉβ‚‚, s := iSup_const_mono (Ξ± := Set Ξ±) h @[simp] theorem iUnion_singleton_eq_range (f : Ξ± β†’ Ξ²) : ⋃ x : Ξ±, {f x} = range f := by ext x simp [@eq_comm _ x] theorem iUnion_insert_eq_range_union_iUnion {ΞΉ : Type*} (x : ΞΉ β†’ Ξ²) (t : ΞΉ β†’ Set Ξ²) : ⋃ i, insert (x i) (t i) = range x βˆͺ ⋃ i, t i := by simp_rw [← union_singleton, iUnion_union_distrib, union_comm, iUnion_singleton_eq_range] theorem iUnion_of_singleton (Ξ± : Type*) : (⋃ x, {x} : Set Ξ±) = univ := by simp [Set.ext_iff] theorem iUnion_of_singleton_coe (s : Set Ξ±) : ⋃ i : s, ({(i : Ξ±)} : Set Ξ±) = s := by simp theorem sUnion_eq_biUnion {s : Set (Set Ξ±)} : ⋃₀ s = ⋃ (i : Set Ξ±) (_ : i ∈ s), i := by rw [← sUnion_image, image_id'] theorem sInter_eq_biInter {s : Set (Set Ξ±)} : β‹‚β‚€ s = β‹‚ (i : Set Ξ±) (_ : i ∈ s), i := by rw [← sInter_image, image_id'] theorem sUnion_eq_iUnion {s : Set (Set Ξ±)} : ⋃₀ s = ⋃ i : s, i := by simp only [← sUnion_range, Subtype.range_coe] theorem sInter_eq_iInter {s : Set (Set Ξ±)} : β‹‚β‚€ s = β‹‚ i : s, i := by simp only [← sInter_range, Subtype.range_coe] @[simp] theorem iUnion_of_empty [IsEmpty ΞΉ] (s : ΞΉ β†’ Set Ξ±) : ⋃ i, s i = βˆ… := iSup_of_empty _ @[simp] theorem iInter_of_empty [IsEmpty ΞΉ] (s : ΞΉ β†’ Set Ξ±) : β‹‚ i, s i = univ := iInf_of_empty _ theorem union_eq_iUnion {s₁ sβ‚‚ : Set Ξ±} : s₁ βˆͺ sβ‚‚ = ⋃ b : Bool, cond b s₁ sβ‚‚ := sup_eq_iSup s₁ sβ‚‚ theorem inter_eq_iInter {s₁ sβ‚‚ : Set Ξ±} : s₁ ∩ sβ‚‚ = β‹‚ b : Bool, cond b s₁ sβ‚‚ := inf_eq_iInf s₁ sβ‚‚ theorem sInter_union_sInter {S T : Set (Set Ξ±)} : β‹‚β‚€ S βˆͺ β‹‚β‚€ T = β‹‚ p ∈ S Γ—Λ’ T, (p : Set Ξ± Γ— Set Ξ±).1 βˆͺ p.2 := sInf_sup_sInf theorem sUnion_inter_sUnion {s t : Set (Set Ξ±)} : ⋃₀ s ∩ ⋃₀ t = ⋃ p ∈ s Γ—Λ’ t, (p : Set Ξ± Γ— Set Ξ±).1 ∩ p.2 := sSup_inf_sSup theorem biUnion_iUnion (s : ΞΉ β†’ Set Ξ±) (t : Ξ± β†’ Set Ξ²) : ⋃ x ∈ ⋃ i, s i, t x = ⋃ (i) (x ∈ s i), t x := by simp [@iUnion_comm _ ΞΉ] theorem biInter_iUnion (s : ΞΉ β†’ Set Ξ±) (t : Ξ± β†’ Set Ξ²) : β‹‚ x ∈ ⋃ i, s i, t x = β‹‚ (i) (x ∈ s i), t x := by simp [@iInter_comm _ ΞΉ] theorem sUnion_iUnion (s : ΞΉ β†’ Set (Set Ξ±)) : ⋃₀ ⋃ i, s i = ⋃ i, ⋃₀ s i := by simp only [sUnion_eq_biUnion, biUnion_iUnion] theorem sInter_iUnion (s : ΞΉ β†’ Set (Set Ξ±)) : β‹‚β‚€ ⋃ i, s i = β‹‚ i, β‹‚β‚€ s i := by simp only [sInter_eq_biInter, biInter_iUnion] theorem iUnion_range_eq_sUnion {Ξ± Ξ² : Type*} (C : Set (Set Ξ±)) {f : βˆ€ s : C, Ξ² β†’ (s : Type _)} (hf : βˆ€ s : C, Surjective (f s)) : ⋃ y : Ξ², range (fun s : C => (f s y).val) = ⋃₀ C := by ext x; constructor Β· rintro ⟨s, ⟨y, rfl⟩, ⟨s, hs⟩, rfl⟩ refine ⟨_, hs, ?_⟩ exact (f ⟨s, hs⟩ y).2 Β· rintro ⟨s, hs, hx⟩ obtain ⟨y, hy⟩ := hf ⟨s, hs⟩ ⟨x, hx⟩ refine ⟨_, ⟨y, rfl⟩, ⟨s, hs⟩, ?_⟩ exact congr_arg Subtype.val hy theorem iUnion_range_eq_iUnion (C : ΞΉ β†’ Set Ξ±) {f : βˆ€ x : ΞΉ, Ξ² β†’ C x} (hf : βˆ€ x : ΞΉ, Surjective (f x)) : ⋃ y : Ξ², range (fun x : ΞΉ => (f x y).val) = ⋃ x, C x := by ext x; rw [mem_iUnion, mem_iUnion]; constructor Β· rintro ⟨y, i, rfl⟩ exact ⟨i, (f i y).2⟩ Β· rintro ⟨i, hx⟩ obtain ⟨y, hy⟩ := hf i ⟨x, hx⟩ exact ⟨y, i, congr_arg Subtype.val hy⟩ theorem union_distrib_iInter_left (s : ΞΉ β†’ Set Ξ±) (t : Set Ξ±) : (t βˆͺ β‹‚ i, s i) = β‹‚ i, t βˆͺ s i := sup_iInf_eq _ _ theorem union_distrib_iInterβ‚‚_left (s : Set Ξ±) (t : βˆ€ i, ΞΊ i β†’ Set Ξ±) : (s βˆͺ β‹‚ (i) (j), t i j) = β‹‚ (i) (j), s βˆͺ t i j := by simp_rw [union_distrib_iInter_left] theorem union_distrib_iInter_right (s : ΞΉ β†’ Set Ξ±) (t : Set Ξ±) : (β‹‚ i, s i) βˆͺ t = β‹‚ i, s i βˆͺ t := iInf_sup_eq _ _ theorem union_distrib_iInterβ‚‚_right (s : βˆ€ i, ΞΊ i β†’ Set Ξ±) (t : Set Ξ±) : (β‹‚ (i) (j), s i j) βˆͺ t = β‹‚ (i) (j), s i j βˆͺ t := by simp_rw [union_distrib_iInter_right] lemma biUnion_lt_eq_iUnion [LT Ξ±] [NoMaxOrder Ξ±] {s : Ξ± β†’ Set Ξ²} : ⋃ (n) (m < n), s m = ⋃ n, s n := biSup_lt_eq_iSup lemma biUnion_le_eq_iUnion [Preorder Ξ±] {s : Ξ± β†’ Set Ξ²} : ⋃ (n) (m ≀ n), s m = ⋃ n, s n := biSup_le_eq_iSup lemma biInter_lt_eq_iInter [LT Ξ±] [NoMaxOrder Ξ±] {s : Ξ± β†’ Set Ξ²} : β‹‚ (n) (m < n), s m = β‹‚ (n), s n := biInf_lt_eq_iInf lemma biInter_le_eq_iInter [Preorder Ξ±] {s : Ξ± β†’ Set Ξ²} : β‹‚ (n) (m ≀ n), s m = β‹‚ (n), s n := biInf_le_eq_iInf lemma biUnion_gt_eq_iUnion [LT Ξ±] [NoMinOrder Ξ±] {s : Ξ± β†’ Set Ξ²} : ⋃ (n) (m > n), s m = ⋃ n, s n := biSup_gt_eq_iSup lemma biUnion_ge_eq_iUnion [Preorder Ξ±] {s : Ξ± β†’ Set Ξ²} : ⋃ (n) (m β‰₯ n), s m = ⋃ n, s n := biSup_ge_eq_iSup lemma biInter_gt_eq_iInf [LT Ξ±] [NoMinOrder Ξ±] {s : Ξ± β†’ Set Ξ²} : β‹‚ (n) (m > n), s m = β‹‚ n, s n := biInf_gt_eq_iInf lemma biInter_ge_eq_iInf [Preorder Ξ±] {s : Ξ± β†’ Set Ξ²} : β‹‚ (n) (m β‰₯ n), s m = β‹‚ n, s n := biInf_ge_eq_iInf section le variable {ΞΉ : Type*} [PartialOrder ΞΉ] (s : ΞΉ β†’ Set Ξ±) (i : ΞΉ) theorem biUnion_le : (⋃ j ≀ i, s j) = (⋃ j < i, s j) βˆͺ s i := biSup_le_eq_sup s i theorem biInter_le : (β‹‚ j ≀ i, s j) = (β‹‚ j < i, s j) ∩ s i := biInf_le_eq_inf s i theorem biUnion_ge : (⋃ j β‰₯ i, s j) = s i βˆͺ ⋃ j > i, s j := biSup_ge_eq_sup s i theorem biInter_ge : (β‹‚ j β‰₯ i, s j) = s i ∩ β‹‚ j > i, s j := biInf_ge_eq_inf s i end le section Pi variable {Ο€ : Ξ± β†’ Type*} theorem pi_def (i : Set Ξ±) (s : βˆ€ a, Set (Ο€ a)) : pi i s = β‹‚ a ∈ i, eval a ⁻¹' s a := by ext simp theorem univ_pi_eq_iInter (t : βˆ€ i, Set (Ο€ i)) : pi univ t = β‹‚ i, eval i ⁻¹' t i := by simp only [pi_def, iInter_true, mem_univ] theorem pi_diff_pi_subset (i : Set Ξ±) (s t : βˆ€ a, Set (Ο€ a)) : pi i s \ pi i t βŠ† ⋃ a ∈ i, eval a ⁻¹' (s a \ t a) := by refine diff_subset_comm.2 fun x hx a ha => ?_ simp only [mem_diff, mem_pi, mem_iUnion, not_exists, mem_preimage, not_and, not_not, eval_apply] at hx exact hx.2 _ ha (hx.1 _ ha) theorem iUnion_univ_pi {ΞΉ : Ξ± β†’ Type*} (t : (a : Ξ±) β†’ ΞΉ a β†’ Set (Ο€ a)) : ⋃ x : (a : Ξ±) β†’ ΞΉ a, pi univ (fun a => t a (x a)) = pi univ fun a => ⋃ j : ΞΉ a, t a j := by ext simp [Classical.skolem] end Pi section Directed theorem directedOn_iUnion {r} {f : ΞΉ β†’ Set Ξ±} (hd : Directed (Β· βŠ† Β·) f) (h : βˆ€ x, DirectedOn r (f x)) : DirectedOn r (⋃ x, f x) := by simp only [DirectedOn, exists_prop, mem_iUnion, exists_imp] exact fun a₁ b₁ fb₁ aβ‚‚ bβ‚‚ fbβ‚‚ => let ⟨z, zb₁, zbβ‚‚βŸ© := hd b₁ bβ‚‚ let ⟨x, xf, xa₁, xaβ‚‚βŸ© := h z a₁ (zb₁ fb₁) aβ‚‚ (zbβ‚‚ fbβ‚‚) ⟨x, ⟨z, xf⟩, xa₁, xaβ‚‚βŸ© theorem directedOn_sUnion {r} {S : Set (Set Ξ±)} (hd : DirectedOn (Β· βŠ† Β·) S) (h : βˆ€ x ∈ S, DirectedOn r x) : DirectedOn r (⋃₀ S) := by rw [sUnion_eq_iUnion] exact directedOn_iUnion (directedOn_iff_directed.mp hd) (fun i ↦ h i.1 i.2) theorem pairwise_iUnionβ‚‚ {S : Set (Set Ξ±)} (hd : DirectedOn (Β· βŠ† Β·) S) (r : Ξ± β†’ Ξ± β†’ Prop) (h : βˆ€ s ∈ S, s.Pairwise r) : (⋃ s ∈ S, s).Pairwise r := by simp only [Set.Pairwise, Set.mem_iUnion, exists_prop, forall_exists_index, and_imp] intro x S hS hx y T hT hy hne obtain ⟨U, hU, hSU, hTU⟩ := hd S hS T hT exact h U hU (hSU hx) (hTU hy) hne end Directed end Set namespace Function namespace Surjective theorem iUnion_comp {f : ΞΉ β†’ ΞΉβ‚‚} (hf : Surjective f) (g : ΞΉβ‚‚ β†’ Set Ξ±) : ⋃ x, g (f x) = ⋃ y, g y := hf.iSup_comp g theorem iInter_comp {f : ΞΉ β†’ ΞΉβ‚‚} (hf : Surjective f) (g : ΞΉβ‚‚ β†’ Set Ξ±) : β‹‚ x, g (f x) = β‹‚ y, g y := hf.iInf_comp g end Surjective end Function /-! ### Disjoint sets -/ section Disjoint variable {s t : Set Ξ±} namespace Set @[simp] theorem disjoint_iUnion_left {ΞΉ : Sort*} {s : ΞΉ β†’ Set Ξ±} : Disjoint (⋃ i, s i) t ↔ βˆ€ i, Disjoint (s i) t := iSup_disjoint_iff @[simp] theorem disjoint_iUnion_right {ΞΉ : Sort*} {s : ΞΉ β†’ Set Ξ±} : Disjoint t (⋃ i, s i) ↔ βˆ€ i, Disjoint t (s i) := disjoint_iSup_iff theorem disjoint_iUnionβ‚‚_left {s : βˆ€ i, ΞΊ i β†’ Set Ξ±} {t : Set Ξ±} : Disjoint (⋃ (i) (j), s i j) t ↔ βˆ€ i j, Disjoint (s i j) t := iSupβ‚‚_disjoint_iff theorem disjoint_iUnionβ‚‚_right {s : Set Ξ±} {t : βˆ€ i, ΞΊ i β†’ Set Ξ±} : Disjoint s (⋃ (i) (j), t i j) ↔ βˆ€ i j, Disjoint s (t i j) := disjoint_iSupβ‚‚_iff @[simp] theorem disjoint_sUnion_left {S : Set (Set Ξ±)} {t : Set Ξ±} : Disjoint (⋃₀ S) t ↔ βˆ€ s ∈ S, Disjoint s t := sSup_disjoint_iff @[simp] theorem disjoint_sUnion_right {s : Set Ξ±} {S : Set (Set Ξ±)} : Disjoint s (⋃₀ S) ↔ βˆ€ t ∈ S, Disjoint s t := disjoint_sSup_iff lemma biUnion_compl_eq_of_pairwise_disjoint_of_iUnion_eq_univ {ΞΉ : Type*} {Es : ΞΉ β†’ Set Ξ±} (Es_union : ⋃ i, Es i = univ) (Es_disj : Pairwise fun i j ↦ Disjoint (Es i) (Es j)) (I : Set ΞΉ) : (⋃ i ∈ I, Es i)ᢜ = ⋃ i ∈ Iᢜ, Es i := by ext x obtain ⟨i, hix⟩ : βˆƒ i, x ∈ Es i := by simp [← mem_iUnion, Es_union] have obs : βˆ€ (J : Set ΞΉ), x ∈ ⋃ j ∈ J, Es j ↔ i ∈ J := by refine fun J ↦ ⟨?_, fun i_in_J ↦ by simpa only [mem_iUnion, exists_prop] using ⟨i, i_in_J, hix⟩⟩ intro x_in_U simp only [mem_iUnion, exists_prop] at x_in_U obtain ⟨j, j_in_J, hjx⟩ := x_in_U rwa [show i = j by by_contra i_ne_j; exact Disjoint.ne_of_mem (Es_disj i_ne_j) hix hjx rfl] have obs' : βˆ€ (J : Set ΞΉ), x ∈ (⋃ j ∈ J, Es j)ᢜ ↔ i βˆ‰ J := fun J ↦ by simpa only [mem_compl_iff, not_iff_not] using obs J rw [obs, obs', mem_compl_iff] end Set end Disjoint /-! ### Intervals -/ namespace Set lemma nonempty_iInter_Iic_iff [Preorder Ξ±] {f : ΞΉ β†’ Ξ±} : (β‹‚ i, Iic (f i)).Nonempty ↔ BddBelow (range f) := by have : (β‹‚ (i : ΞΉ), Iic (f i)) = lowerBounds (range f) := by ext c; simp [lowerBounds] simp [this, BddBelow] lemma nonempty_iInter_Ici_iff [Preorder Ξ±] {f : ΞΉ β†’ Ξ±} : (β‹‚ i, Ici (f i)).Nonempty ↔ BddAbove (range f) := nonempty_iInter_Iic_iff (Ξ± := Ξ±α΅’α΅ˆ) variable [CompleteLattice Ξ±] theorem Ici_iSup (f : ΞΉ β†’ Ξ±) : Ici (⨆ i, f i) = β‹‚ i, Ici (f i) := ext fun _ => by simp only [mem_Ici, iSup_le_iff, mem_iInter] theorem Iic_iInf (f : ΞΉ β†’ Ξ±) : Iic (β¨… i, f i) = β‹‚ i, Iic (f i) := ext fun _ => by simp only [mem_Iic, le_iInf_iff, mem_iInter] theorem Ici_iSupβ‚‚ (f : βˆ€ i, ΞΊ i β†’ Ξ±) : Ici (⨆ (i) (j), f i j) = β‹‚ (i) (j), Ici (f i j) := by simp_rw [Ici_iSup] theorem Iic_iInfβ‚‚ (f : βˆ€ i, ΞΊ i β†’ Ξ±) : Iic (β¨… (i) (j), f i j) = β‹‚ (i) (j), Iic (f i j) := by simp_rw [Iic_iInf] theorem Ici_sSup (s : Set Ξ±) : Ici (sSup s) = β‹‚ a ∈ s, Ici a := by rw [sSup_eq_iSup, Ici_iSupβ‚‚] theorem Iic_sInf (s : Set Ξ±) : Iic (sInf s) = β‹‚ a ∈ s, Iic a := by rw [sInf_eq_iInf, Iic_iInfβ‚‚] end Set namespace Set variable (t : Ξ± β†’ Set Ξ²) theorem biUnion_diff_biUnion_subset (s₁ sβ‚‚ : Set Ξ±) : ((⋃ x ∈ s₁, t x) \ ⋃ x ∈ sβ‚‚, t x) βŠ† ⋃ x ∈ s₁ \ sβ‚‚, t x := by simp only [diff_subset_iff, ← biUnion_union] apply biUnion_subset_biUnion_left rw [union_diff_self] apply subset_union_right /-- If `t` is an indexed family of sets, then there is a natural map from `Ξ£ i, t i` to `⋃ i, t i` sending `⟨i, x⟩` to `x`. -/ def sigmaToiUnion (x : Ξ£i, t i) : ⋃ i, t i := ⟨x.2, mem_iUnion.2 ⟨x.1, x.2.2⟩⟩ theorem sigmaToiUnion_surjective : Surjective (sigmaToiUnion t) | ⟨b, hb⟩ => have : βˆƒ a, b ∈ t a := by simpa using hb let ⟨a, hb⟩ := this ⟨⟨a, b, hb⟩, rfl⟩ theorem sigmaToiUnion_injective (h : Pairwise (Disjoint on t)) : Injective (sigmaToiUnion t) | ⟨a₁, b₁, hβ‚βŸ©, ⟨aβ‚‚, bβ‚‚, hβ‚‚βŸ©, eq => have b_eq : b₁ = bβ‚‚ := congr_arg Subtype.val eq have a_eq : a₁ = aβ‚‚ := by_contradiction fun ne => have : b₁ ∈ t a₁ ∩ t aβ‚‚ := ⟨h₁, b_eq.symm β–Έ hβ‚‚βŸ© (h ne).le_bot this Sigma.eq a_eq <| Subtype.eq <| by subst b_eq; subst a_eq; rfl theorem sigmaToiUnion_bijective (h : Pairwise (Disjoint on t)) : Bijective (sigmaToiUnion t) := ⟨sigmaToiUnion_injective t h, sigmaToiUnion_surjective t⟩ /-- Equivalence from the disjoint union of a family of sets forming a partition of `Ξ²`, to `Ξ²` itself. -/ noncomputable def sigmaEquiv (s : Ξ± β†’ Set Ξ²) (hs : βˆ€ b, βˆƒ! i, b ∈ s i) : (Ξ£ i, s i) ≃ Ξ² where toFun | ⟨_, b⟩ => b invFun b := ⟨(hs b).choose, b, (hs b).choose_spec.1⟩ left_inv | ⟨i, b, hb⟩ => Sigma.subtype_ext ((hs b).choose_spec.2 i hb).symm rfl right_inv _ := rfl /-- Equivalence between a disjoint union and a dependent sum. -/ noncomputable def unionEqSigmaOfDisjoint {t : Ξ± β†’ Set Ξ²} (h : Pairwise (Disjoint on t)) : (⋃ i, t i) ≃ Ξ£i, t i := (Equiv.ofBijective _ <| sigmaToiUnion_bijective t h).symm theorem iUnion_ge_eq_iUnion_nat_add (u : β„• β†’ Set Ξ±) (n : β„•) : ⋃ i β‰₯ n, u i = ⋃ i, u (i + n) := iSup_ge_eq_iSup_nat_add u n theorem iInter_ge_eq_iInter_nat_add (u : β„• β†’ Set Ξ±) (n : β„•) : β‹‚ i β‰₯ n, u i = β‹‚ i, u (i + n) := iInf_ge_eq_iInf_nat_add u n theorem _root_.Monotone.iUnion_nat_add {f : β„• β†’ Set Ξ±} (hf : Monotone f) (k : β„•) : ⋃ n, f (n + k) = ⋃ n, f n := hf.iSup_nat_add k theorem _root_.Antitone.iInter_nat_add {f : β„• β†’ Set Ξ±} (hf : Antitone f) (k : β„•) : β‹‚ n, f (n + k) = β‹‚ n, f n := hf.iInf_nat_add k @[simp] theorem iUnion_iInter_ge_nat_add (f : β„• β†’ Set Ξ±) (k : β„•) : ⋃ n, β‹‚ i β‰₯ n, f (i + k) = ⋃ n, β‹‚ i β‰₯ n, f i := iSup_iInf_ge_nat_add f k theorem union_iUnion_nat_succ (u : β„• β†’ Set Ξ±) : (u 0 βˆͺ ⋃ i, u (i + 1)) = ⋃ i, u i := sup_iSup_nat_succ u theorem inter_iInter_nat_succ (u : β„• β†’ Set Ξ±) : (u 0 ∩ β‹‚ i, u (i + 1)) = β‹‚ i, u i := inf_iInf_nat_succ u end Set open Set variable [CompleteLattice Ξ²] theorem iSup_iUnion (s : ΞΉ β†’ Set Ξ±) (f : Ξ± β†’ Ξ²) : ⨆ a ∈ ⋃ i, s i, f a = ⨆ (i) (a ∈ s i), f a := by rw [iSup_comm] simp_rw [mem_iUnion, iSup_exists] theorem iInf_iUnion (s : ΞΉ β†’ Set Ξ±) (f : Ξ± β†’ Ξ²) : β¨… a ∈ ⋃ i, s i, f a = β¨… (i) (a ∈ s i), f a := iSup_iUnion (Ξ² := Ξ²α΅’α΅ˆ) s f theorem sSup_iUnion (t : ΞΉ β†’ Set Ξ²) : sSup (⋃ i, t i) = ⨆ i, sSup (t i) := by simp_rw [sSup_eq_iSup, iSup_iUnion] theorem sSup_sUnion (s : Set (Set Ξ²)) : sSup (⋃₀ s) = ⨆ t ∈ s, sSup t := by simp only [sUnion_eq_biUnion, sSup_eq_iSup, iSup_iUnion] theorem sInf_sUnion (s : Set (Set Ξ²)) : sInf (⋃₀ s) = β¨… t ∈ s, sInf t := sSup_sUnion (Ξ² := Ξ²α΅’α΅ˆ) s lemma iSup_sUnion (S : Set (Set Ξ±)) (f : Ξ± β†’ Ξ²) : (⨆ x ∈ ⋃₀ S, f x) = ⨆ (s ∈ S) (x ∈ s), f x := by rw [sUnion_eq_iUnion, iSup_iUnion, ← iSup_subtype''] lemma iInf_sUnion (S : Set (Set Ξ±)) (f : Ξ± β†’ Ξ²) : (β¨… x ∈ ⋃₀ S, f x) = β¨… (s ∈ S) (x ∈ s), f x := by rw [sUnion_eq_iUnion, iInf_iUnion, ← iInf_subtype''] lemma forall_sUnion {S : Set (Set Ξ±)} {p : Ξ± β†’ Prop} : (βˆ€ x ∈ ⋃₀ S, p x) ↔ βˆ€ s ∈ S, βˆ€ x ∈ s, p x := by simp_rw [← iInf_Prop_eq, iInf_sUnion] lemma exists_sUnion {S : Set (Set Ξ±)} {p : Ξ± β†’ Prop} : (βˆƒ x ∈ ⋃₀ S, p x) ↔ βˆƒ s ∈ S, βˆƒ x ∈ s, p x := by simp_rw [← exists_prop, ← iSup_Prop_eq, iSup_sUnion]
Mathlib/Data/Set/Lattice.lean
1,972
1,973
/- Copyright (c) 2022 YaΓ«l Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: YaΓ«l Dillies, Bhavik Mehta -/ import Mathlib.Analysis.InnerProductSpace.Convex import Mathlib.Analysis.InnerProductSpace.PiL2 import Mathlib.Combinatorics.Additive.AP.Three.Defs import Mathlib.Combinatorics.Pigeonhole import Mathlib.Data.Complex.ExponentialBounds /-! # Behrend's bound on Roth numbers This file proves Behrend's lower bound on Roth numbers. This says that we can find a subset of `{1, ..., n}` of size `n / exp (O (sqrt (log n)))` which does not contain arithmetic progressions of length `3`. The idea is that the sphere (in the `n` dimensional Euclidean space) doesn't contain arithmetic progressions (literally) because the corresponding ball is strictly convex. Thus we can take integer points on that sphere and map them onto `β„•` in a way that preserves arithmetic progressions (`Behrend.map`). ## Main declarations * `Behrend.sphere`: The intersection of the Euclidean sphere with the positive integer quadrant. This is the set that we will map on `β„•`. * `Behrend.map`: Given a natural number `d`, `Behrend.map d : ℕⁿ β†’ β„•` reads off the coordinates as digits in base `d`. * `Behrend.card_sphere_le_rothNumberNat`: Implicit lower bound on Roth numbers in terms of `Behrend.sphere`. * `Behrend.roth_lower_bound`: Behrend's explicit lower bound on Roth numbers. ## References * [Bryan Gillespie, *Behrend’s Construction*] (http://www.epsilonsmall.com/resources/behrends-construction/behrend.pdf) * Behrend, F. A., "On sets of integers which contain no three terms in arithmetical progression" * [Wikipedia, *Salem-Spencer set*](https://en.wikipedia.org/wiki/Salem–Spencer_set) ## Tags 3AP-free, Salem-Spencer, Behrend construction, arithmetic progression, sphere, strictly convex -/ assert_not_exists IsConformalMap Conformal open Nat hiding log open Finset Metric Real open scoped Pointwise /-- The frontier of a closed strictly convex set only contains trivial arithmetic progressions. The idea is that an arithmetic progression is contained on a line and the frontier of a strictly convex set does not contain lines. -/ lemma threeAPFree_frontier {π•œ E : Type*} [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [TopologicalSpace E] [AddCommMonoid E] [Module π•œ E] {s : Set E} (hsβ‚€ : IsClosed s) (hs₁ : StrictConvex π•œ s) : ThreeAPFree (frontier s) := by intro a ha b hb c hc habc obtain rfl : (1 / 2 : π•œ) β€’ a + (1 / 2 : π•œ) β€’ c = b := by rwa [← smul_add, one_div, inv_smul_eq_iffβ‚€ (show (2 : π•œ) β‰  0 by norm_num), two_smul] have := hs₁.eq (hsβ‚€.frontier_subset ha) (hsβ‚€.frontier_subset hc) one_half_pos one_half_pos (add_halves _) hb.2 simp [this, ← add_smul] ring_nf simp lemma threeAPFree_sphere {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [StrictConvexSpace ℝ E] (x : E) (r : ℝ) : ThreeAPFree (sphere x r) := by obtain rfl | hr := eq_or_ne r 0 Β· rw [sphere_zero] exact threeAPFree_singleton _ Β· convert threeAPFree_frontier isClosed_closedBall (strictConvex_closedBall ℝ x r) exact (frontier_closedBall _ hr).symm namespace Behrend variable {n d k N : β„•} {x : Fin n β†’ β„•} /-! ### Turning the sphere into 3AP-free set We define `Behrend.sphere`, the intersection of the $L^2$ sphere with the positive quadrant of integer points. Because the $L^2$ closed ball is strictly convex, the $L^2$ sphere and `Behrend.sphere` are 3AP-free (`threeAPFree_sphere`). Then we can turn this set in `Fin n β†’ β„•` into a set in `β„•` using `Behrend.map`, which preserves `ThreeAPFree` because it is an additive monoid homomorphism. -/ /-- The box `{0, ..., d - 1}^n` as a `Finset`. -/ def box (n d : β„•) : Finset (Fin n β†’ β„•) := Fintype.piFinset fun _ => range d theorem mem_box : x ∈ box n d ↔ βˆ€ i, x i < d := by simp only [box, Fintype.mem_piFinset, mem_range] @[simp] theorem card_box : #(box n d) = d ^ n := by simp [box] @[simp] theorem box_zero : box (n + 1) 0 = βˆ… := by simp [box] /-- The intersection of the sphere of radius `√k` with the integer points in the positive quadrant. -/ def sphere (n d k : β„•) : Finset (Fin n β†’ β„•) := {x ∈ box n d | βˆ‘ i, x i ^ 2 = k} theorem sphere_zero_subset : sphere n d 0 βŠ† 0 := fun x => by simp [sphere, funext_iff] @[simp] theorem sphere_zero_right (n k : β„•) : sphere (n + 1) 0 k = βˆ… := by simp [sphere] theorem sphere_subset_box : sphere n d k βŠ† box n d := filter_subset _ _ theorem norm_of_mem_sphere {x : Fin n β†’ β„•} (hx : x ∈ sphere n d k) : β€–(WithLp.equiv 2 _).symm ((↑) ∘ x : Fin n β†’ ℝ)β€– = βˆšβ†‘k := by rw [EuclideanSpace.norm_eq] dsimp simp_rw [abs_cast, ← cast_pow, ← cast_sum, (mem_filter.1 hx).2] theorem sphere_subset_preimage_metric_sphere : (sphere n d k : Set (Fin n β†’ β„•)) βŠ† (fun x : Fin n β†’ β„• => (WithLp.equiv 2 _).symm ((↑) ∘ x : Fin n β†’ ℝ)) ⁻¹' Metric.sphere (0 : PiLp 2 fun _ : Fin n => ℝ) (βˆšβ†‘k) := fun x hx => by rw [Set.mem_preimage, mem_sphere_zero_iff_norm, norm_of_mem_sphere hx] /-- The map that appears in Behrend's bound on Roth numbers. -/ @[simps] def map (d : β„•) : (Fin n β†’ β„•) β†’+ β„• where toFun a := βˆ‘ i, a i * d ^ (i : β„•) map_zero' := by simp_rw [Pi.zero_apply, zero_mul, sum_const_zero] map_add' a b := by simp_rw [Pi.add_apply, add_mul, sum_add_distrib] theorem map_zero (d : β„•) (a : Fin 0 β†’ β„•) : map d a = 0 := by simp [map] theorem map_succ (a : Fin (n + 1) β†’ β„•) : map d a = a 0 + (βˆ‘ x : Fin n, a x.succ * d ^ (x : β„•)) * d := by simp [map, Fin.sum_univ_succ, _root_.pow_succ, ← mul_assoc, ← sum_mul] theorem map_succ' (a : Fin (n + 1) β†’ β„•) : map d a = a 0 + map d (a ∘ Fin.succ) * d := map_succ _ theorem map_monotone (d : β„•) : Monotone (map d : (Fin n β†’ β„•) β†’ β„•) := fun x y h => by dsimp; exact sum_le_sum fun i _ => Nat.mul_le_mul_right _ <| h i theorem map_mod (a : Fin n.succ β†’ β„•) : map d a % d = a 0 % d := by rw [map_succ, Nat.add_mul_mod_self_right] theorem map_eq_iff {x₁ xβ‚‚ : Fin n.succ β†’ β„•} (hx₁ : βˆ€ i, x₁ i < d) (hxβ‚‚ : βˆ€ i, xβ‚‚ i < d) : map d x₁ = map d xβ‚‚ ↔ x₁ 0 = xβ‚‚ 0 ∧ map d (x₁ ∘ Fin.succ) = map d (xβ‚‚ ∘ Fin.succ) := by refine ⟨fun h => ?_, fun h => by rw [map_succ', map_succ', h.1, h.2]⟩ have : x₁ 0 = xβ‚‚ 0 := by rw [← mod_eq_of_lt (hx₁ _), ← map_mod, ← mod_eq_of_lt (hxβ‚‚ _), ← map_mod, h] rw [map_succ, map_succ, this, add_right_inj, mul_eq_mul_right_iff] at h exact ⟨this, h.resolve_right (pos_of_gt (hx₁ 0)).ne'⟩ theorem map_injOn : {x : Fin n β†’ β„• | βˆ€ i, x i < d}.InjOn (map d) := by intro x₁ hx₁ xβ‚‚ hxβ‚‚ h induction n with | zero => simp [eq_iff_true_of_subsingleton] | succ n ih => ext i have x := (map_eq_iff hx₁ hxβ‚‚).1 h exact Fin.cases x.1 (congr_fun <| ih (fun _ => hx₁ _) (fun _ => hxβ‚‚ _) x.2) i theorem map_le_of_mem_box (hx : x ∈ box n d) : map (2 * d - 1) x ≀ βˆ‘ i : Fin n, (d - 1) * (2 * d - 1) ^ (i : β„•) := map_monotone (2 * d - 1) fun _ => Nat.le_sub_one_of_lt <| mem_box.1 hx _ nonrec theorem threeAPFree_sphere : ThreeAPFree (sphere n d k : Set (Fin n β†’ β„•)) := by set f : (Fin n β†’ β„•) β†’+ EuclideanSpace ℝ (Fin n) := { toFun := fun f => ((↑) : β„• β†’ ℝ) ∘ f map_zero' := funext fun _ => cast_zero map_add' := fun _ _ => funext fun _ => cast_add _ _ } refine ThreeAPFree.of_image (AddMonoidHomClass.isAddFreimanHom f (Set.mapsTo_image _ _)) cast_injective.comp_left.injOn (Set.subset_univ _) ?_ refine (threeAPFree_sphere 0 (βˆšβ†‘k)).mono (Set.image_subset_iff.2 fun x => ?_) rw [Set.mem_preimage, mem_sphere_zero_iff_norm] exact norm_of_mem_sphere theorem threeAPFree_image_sphere : ThreeAPFree ((sphere n d k).image (map (2 * d - 1)) : Set β„•) := by rw [coe_image] apply ThreeAPFree.image' (Ξ± := Fin n β†’ β„•) (Ξ² := β„•) (s := sphere n d k) (map (2 * d - 1)) (map_injOn.mono _) threeAPFree_sphere rw [Set.add_subset_iff] rintro a ha b hb i have hai := mem_box.1 (sphere_subset_box ha) i have hbi := mem_box.1 (sphere_subset_box hb) i rw [lt_tsub_iff_right, ← succ_le_iff, two_mul] exact (add_add_add_comm _ _ 1 1).trans_le (_root_.add_le_add hai hbi) theorem sum_sq_le_of_mem_box (hx : x ∈ box n d) : βˆ‘ i : Fin n, x i ^ 2 ≀ n * (d - 1) ^ 2 := by rw [mem_box] at hx have : βˆ€ i, x i ^ 2 ≀ (d - 1) ^ 2 := fun i => Nat.pow_le_pow_left (Nat.le_sub_one_of_lt (hx i)) _ exact (sum_le_card_nsmul univ _ _ fun i _ => this i).trans (by rw [card_fin, smul_eq_mul]) theorem sum_eq : (βˆ‘ i : Fin n, d * (2 * d + 1) ^ (i : β„•)) = ((2 * d + 1) ^ n - 1) / 2 := by refine (Nat.div_eq_of_eq_mul_left zero_lt_two ?_).symm rw [← sum_range fun i => d * (2 * d + 1) ^ (i : β„•), ← mul_sum, mul_right_comm, mul_comm d, ← geom_sum_mul_add, add_tsub_cancel_right, mul_comm] theorem sum_lt : (βˆ‘ i : Fin n, d * (2 * d + 1) ^ (i : β„•)) < (2 * d + 1) ^ n := sum_eq.trans_lt <| (Nat.div_le_self _ 2).trans_lt <| pred_lt (pow_pos (succ_pos _) _).ne' theorem card_sphere_le_rothNumberNat (n d k : β„•) : #(sphere n d k) ≀ rothNumberNat ((2 * d - 1) ^ n) := by cases n Β· dsimp; refine (card_le_univ _).trans_eq ?_; rfl cases d Β· simp apply threeAPFree_image_sphere.le_rothNumberNat _ _ (card_image_of_injOn _) Β· simp only [subset_iff, mem_image, and_imp, forall_exists_index, mem_range, forall_apply_eq_imp_iffβ‚‚, sphere, mem_filter] rintro _ x hx _ rfl exact (map_le_of_mem_box hx).trans_lt sum_lt apply map_injOn.mono fun x => ?_ simp only [mem_coe, sphere, mem_filter, mem_box, and_imp, two_mul] exact fun h _ i => (h i).trans_le le_self_add /-! ### Optimization Now that we know how to turn the integer points of any sphere into a 3AP-free set, we find a sphere containing many integer points by the pigeonhole principle. This gives us an implicit bound that we then optimize by tweaking the parameters. The (almost) optimal parameters are `Behrend.nValue` and `Behrend.dValue`. -/ theorem exists_large_sphere_aux (n d : β„•) : βˆƒ k ∈ range (n * (d - 1) ^ 2 + 1), (↑(d ^ n) / ((n * (d - 1) ^ 2 :) + 1) : ℝ) ≀ #(sphere n d k) := by refine exists_le_card_fiber_of_nsmul_le_card_of_maps_to (fun x hx => ?_) nonempty_range_succ ?_ Β· rw [mem_range, Nat.lt_succ_iff] exact sum_sq_le_of_mem_box hx Β· rw [card_range, _root_.nsmul_eq_mul, mul_div_assoc', cast_add_one, mul_div_cancel_leftβ‚€, card_box] exact (cast_add_one_pos _).ne' theorem exists_large_sphere (n d : β„•) : βˆƒ k, ((d ^ n :) / (n * d ^ 2 :) : ℝ) ≀ #(sphere n d k) := by obtain ⟨k, -, hk⟩ := exists_large_sphere_aux n d refine ⟨k, ?_⟩ obtain rfl | hn := n.eq_zero_or_pos Β· simp obtain rfl | hd := d.eq_zero_or_pos Β· simp refine (div_le_div_of_nonneg_left ?_ ?_ ?_).trans hk Β· exact cast_nonneg _ Β· exact cast_add_one_pos _ simp only [← le_sub_iff_add_le', cast_mul, ← mul_sub, cast_pow, cast_sub hd, sub_sq, one_pow, cast_one, mul_one, sub_add, sub_sub_self] apply one_le_mul_of_one_le_of_one_le Β· rwa [one_le_cast] rw [_root_.le_sub_iff_add_le] norm_num exact one_le_cast.2 hd theorem bound_aux' (n d : β„•) : ((d ^ n :) / (n * d ^ 2 :) : ℝ) ≀ rothNumberNat ((2 * d - 1) ^ n) := let ⟨_, h⟩ := exists_large_sphere n d h.trans <| cast_le.2 <| card_sphere_le_rothNumberNat _ _ _ theorem bound_aux (hd : d β‰  0) (hn : 2 ≀ n) : (d ^ (n - 2 :) / n : ℝ) ≀ rothNumberNat ((2 * d - 1) ^ n) := by convert bound_aux' n d using 1 rw [cast_mul, cast_pow, mul_comm, ← div_div, pow_subβ‚€ _ _ hn, ← div_eq_mul_inv, cast_pow] rwa [cast_ne_zero] open scoped Filter Topology open Real section NumericalBounds theorem log_two_mul_two_le_sqrt_log_eight : log 2 * 2 ≀ √(log 8) := by have : (8 : ℝ) = 2 ^ ((3 : β„•) : ℝ) := by rw [rpow_natCast]; norm_num rw [this, log_rpow zero_lt_two (3 : β„•)] apply le_sqrt_of_sq_le rw [mul_pow, sq (log 2), mul_assoc, mul_comm] refine mul_le_mul_of_nonneg_right ?_ (log_nonneg one_le_two) rw [← le_div_iffβ‚€] on_goal 1 => apply log_two_lt_d9.le.trans all_goals norm_num1 theorem two_div_one_sub_two_div_e_le_eight : 2 / (1 - 2 / exp 1) ≀ 8 := by rw [div_le_iffβ‚€, mul_sub, mul_one, mul_div_assoc', le_sub_comm, div_le_iffβ‚€ (exp_pos _)] Β· linarith [exp_one_gt_d9] rw [sub_pos, div_lt_one] <;> exact exp_one_gt_d9.trans' (by norm_num) theorem le_sqrt_log (hN : 4096 ≀ N) : log (2 / (1 - 2 / exp 1)) * (69 / 50) ≀ √(log ↑N) := by have : (12 : β„•) * log 2 ≀ log N := by rw [← log_rpow zero_lt_two, rpow_natCast] exact log_le_log (by positivity) (mod_cast hN) refine (mul_le_mul_of_nonneg_right (log_le_log ?_ two_div_one_sub_two_div_e_le_eight) <| by norm_num1).trans ?_ Β· refine div_pos zero_lt_two ?_ rw [sub_pos, div_lt_one (exp_pos _)] exact exp_one_gt_d9.trans_le' (by norm_num1) have l8 : log 8 = (3 : β„•) * log 2 := by rw [← log_rpow zero_lt_two, rpow_natCast] norm_num rw [l8] apply le_sqrt_of_sq_le (le_trans _ this) rw [mul_right_comm, mul_pow, sq (log 2), ← mul_assoc] apply mul_le_mul_of_nonneg_right _ (log_nonneg one_le_two) rw [← le_div_iffβ‚€'] Β· exact log_two_lt_d9.le.trans (by norm_num1) exact sq_pos_of_ne_zero (by norm_num1) theorem exp_neg_two_mul_le {x : ℝ} (hx : 0 < x) : exp (-2 * x) < exp (2 - ⌈xβŒ‰β‚Š) / ⌈xβŒ‰β‚Š := by have h₁ := ceil_lt_add_one hx.le have hβ‚‚ : 1 - x ≀ 2 - ⌈xβŒ‰β‚Š := by linarith calc _ ≀ exp (1 - x) / (x + 1) := ?_ _ ≀ exp (2 - ⌈xβŒ‰β‚Š) / (x + 1) := by gcongr _ < _ := by gcongr rw [le_div_iffβ‚€ (add_pos hx zero_lt_one), ← le_div_iffβ‚€' (exp_pos _), ← exp_sub, neg_mul, sub_neg_eq_add, two_mul, sub_add_add_cancel, add_comm _ x] exact le_trans (le_add_of_nonneg_right zero_le_one) (add_one_le_exp _) theorem div_lt_floor {x : ℝ} (hx : 2 / (1 - 2 / exp 1) ≀ x) : x / exp 1 < (⌊x / 2βŒ‹β‚Š : ℝ) := by apply lt_of_le_of_lt _ (sub_one_lt_floor _) have : 0 < 1 - 2 / exp 1 := by rw [sub_pos, div_lt_one (exp_pos _)] exact lt_of_le_of_lt (by norm_num) exp_one_gt_d9 rwa [le_sub_comm, div_eq_mul_one_div x, div_eq_mul_one_div x, ← mul_sub, div_sub', ← div_eq_mul_one_div, mul_div_assoc', one_le_div, ← div_le_iffβ‚€ this] Β· exact zero_lt_two Β· exact two_ne_zero theorem ceil_lt_mul {x : ℝ} (hx : 50 / 19 ≀ x) : (⌈xβŒ‰β‚Š : ℝ) < 1.38 * x := by refine (ceil_lt_add_one <| hx.trans' <| by norm_num).trans_le ?_ rw [← le_sub_iff_add_le', ← sub_one_mul] have : (1.38 : ℝ) = 69 / 50 := by norm_num rwa [this, show (69 / 50 - 1 : ℝ) = (50 / 19)⁻¹ by norm_num1, ← div_eq_inv_mul, one_le_div] norm_num1 end NumericalBounds /-- The (almost) optimal value of `n` in `Behrend.bound_aux`. -/ noncomputable def nValue (N : β„•) : β„• := ⌈√(log N)βŒ‰β‚Š /-- The (almost) optimal value of `d` in `Behrend.bound_aux`. -/ noncomputable def dValue (N : β„•) : β„• := ⌊(N : ℝ) ^ (nValue N : ℝ)⁻¹ / 2βŒ‹β‚Š theorem nValue_pos (hN : 2 ≀ N) : 0 < nValue N := ceil_pos.2 <| Real.sqrt_pos.2 <| log_pos <| one_lt_cast.2 <| hN theorem three_le_nValue (hN : 64 ≀ N) : 3 ≀ nValue N := by rw [nValue, ← lt_iff_add_one_le, lt_ceil, cast_two] apply lt_sqrt_of_sq_lt have : (2 : ℝ) ^ ((6 : β„•) : ℝ) ≀ N := by rw [rpow_natCast] exact (cast_le.2 hN).trans' (by norm_num1) apply lt_of_lt_of_le _ (log_le_log (rpow_pos_of_pos zero_lt_two _) this) rw [log_rpow zero_lt_two, ← div_lt_iffβ‚€'] Β· exact log_two_gt_d9.trans_le' (by norm_num1) Β· norm_num1 theorem dValue_pos (hN₃ : 8 ≀ N) : 0 < dValue N := by have hNβ‚€ : 0 < (N : ℝ) := cast_pos.2 (succ_pos'.trans_le hN₃) rw [dValue, floor_pos, ← log_le_log_iff zero_lt_one, log_one, log_div _ two_ne_zero, log_rpow hNβ‚€, inv_mul_eq_div, sub_nonneg, le_div_iffβ‚€] Β· have : (nValue N : ℝ) ≀ 2 * √(log N) := by apply (ceil_lt_add_one <| sqrt_nonneg _).le.trans rw [two_mul, add_le_add_iff_left] apply le_sqrt_of_sq_le rw [one_pow, le_log_iff_exp_le hNβ‚€] exact (exp_one_lt_d9.le.trans <| by norm_num).trans (cast_le.2 hN₃) apply (mul_le_mul_of_nonneg_left this <| log_nonneg one_le_two).trans _ rw [← mul_assoc, ← le_div_iffβ‚€ (Real.sqrt_pos.2 <| log_pos <| one_lt_cast.2 _), div_sqrt] Β· apply log_two_mul_two_le_sqrt_log_eight.trans apply Real.sqrt_le_sqrt exact log_le_log (by norm_num) (mod_cast hN₃) exact hN₃.trans_lt' (by norm_num) Β· exact cast_pos.2 (nValue_pos <| hN₃.trans' <| by norm_num) Β· exact (rpow_pos_of_pos hNβ‚€ _).ne' Β· exact div_pos (rpow_pos_of_pos hNβ‚€ _) zero_lt_two theorem le_N (hN : 2 ≀ N) : (2 * dValue N - 1) ^ nValue N ≀ N := by have : (2 * dValue N - 1) ^ nValue N ≀ (2 * dValue N) ^ nValue N := Nat.pow_le_pow_left (Nat.sub_le _ _) _ apply this.trans suffices ((2 * dValue N) ^ nValue N : ℝ) ≀ N from mod_cast this suffices i : (2 * dValue N : ℝ) ≀ (N : ℝ) ^ (nValue N : ℝ)⁻¹ by rw [← rpow_natCast] apply (rpow_le_rpow (mul_nonneg zero_le_two (cast_nonneg _)) i (cast_nonneg _)).trans rw [← rpow_mul (cast_nonneg _), inv_mul_cancelβ‚€, rpow_one] rw [cast_ne_zero] apply (nValue_pos hN).ne' rw [← le_div_iffβ‚€'] Β· exact floor_le (div_nonneg (rpow_nonneg (cast_nonneg _) _) zero_le_two) apply zero_lt_two theorem bound (hN : 4096 ≀ N) : (N : ℝ) ^ (nValue N : ℝ)⁻¹ / exp 1 < dValue N := by apply div_lt_floor _
rw [← log_le_log_iff, log_rpow, mul_comm, ← div_eq_mul_inv] Β· apply le_trans _ (div_le_div_of_nonneg_left _ _ (ceil_lt_mul _).le) Β· rw [mul_comm, ← div_div, div_sqrt, le_div_iffβ‚€] Β· norm_num; exact le_sqrt_log hN Β· norm_num1 Β· apply log_nonneg rw [one_le_cast] exact hN.trans' (by norm_num1) Β· rw [cast_pos, lt_ceil, cast_zero, Real.sqrt_pos] refine log_pos ?_
Mathlib/Combinatorics/Additive/AP/Three/Behrend.lean
400
409
/- Copyright (c) 2020 FrΓ©dΓ©ric Dupuis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: FrΓ©dΓ©ric Dupuis -/ import Mathlib.Algebra.Algebra.Field import Mathlib.Algebra.BigOperators.Balance import Mathlib.Algebra.Order.BigOperators.Expect import Mathlib.Algebra.Order.Star.Basic import Mathlib.Analysis.CStarAlgebra.Basic import Mathlib.Analysis.Normed.Operator.ContinuousLinearMap import Mathlib.Data.Real.Sqrt import Mathlib.LinearAlgebra.Basis.VectorSpace /-! # `RCLike`: a typeclass for ℝ or β„‚ This file defines the typeclass `RCLike` intended to have only two instances: ℝ and β„‚. It is meant for definitions and theorems which hold for both the real and the complex case, and in particular when the real case follows directly from the complex case by setting `re` to `id`, `im` to zero and so on. Its API follows closely that of β„‚. Applications include defining inner products and Hilbert spaces for both the real and complex case. One typically produces the definitions and proof for an arbitrary field of this typeclass, which basically amounts to doing the complex case, and the two cases then fall out immediately from the two instances of the class. The instance for `ℝ` is registered in this file. The instance for `β„‚` is declared in `Mathlib/Analysis/Complex/Basic.lean`. ## Implementation notes The coercion from reals into an `RCLike` field is done by registering `RCLike.ofReal` as a `CoeTC`. For this to work, we must proceed carefully to avoid problems involving circular coercions in the case `K=ℝ`; in particular, we cannot use the plain `Coe` and must set priorities carefully. This problem was already solved for `β„•`, and we copy the solution detailed in `Mathlib/Data/Nat/Cast/Defs.lean`. See also Note [coercion into rings] for more details. In addition, several lemmas need to be set at priority 900 to make sure that they do not override their counterparts in `Mathlib/Analysis/Complex/Basic.lean` (which causes linter errors). A few lemmas requiring heavier imports are in `Mathlib/Analysis/RCLike/Lemmas.lean`. -/ open Fintype open scoped BigOperators ComplexConjugate section local notation "π“š" => algebraMap ℝ _ /-- This typeclass captures properties shared by ℝ and β„‚, with an API that closely matches that of β„‚. -/ class RCLike (K : semiOutParam Type*) extends DenselyNormedField K, StarRing K, NormedAlgebra ℝ K, CompleteSpace K where /-- The real part as an additive monoid homomorphism -/ re : K β†’+ ℝ /-- The imaginary part as an additive monoid homomorphism -/ im : K β†’+ ℝ /-- Imaginary unit in `K`. Meant to be set to `0` for `K = ℝ`. -/ I : K I_re_ax : re I = 0 I_mul_I_ax : I = 0 ∨ I * I = -1 re_add_im_ax : βˆ€ z : K, π“š (re z) + π“š (im z) * I = z ofReal_re_ax : βˆ€ r : ℝ, re (π“š r) = r ofReal_im_ax : βˆ€ r : ℝ, im (π“š r) = 0 mul_re_ax : βˆ€ z w : K, re (z * w) = re z * re w - im z * im w mul_im_ax : βˆ€ z w : K, im (z * w) = re z * im w + im z * re w conj_re_ax : βˆ€ z : K, re (conj z) = re z conj_im_ax : βˆ€ z : K, im (conj z) = -im z conj_I_ax : conj I = -I norm_sq_eq_def_ax : βˆ€ z : K, β€–zβ€– ^ 2 = re z * re z + im z * im z mul_im_I_ax : βˆ€ z : K, im z * im I = im z /-- only an instance in the `ComplexOrder` locale -/ [toPartialOrder : PartialOrder K] le_iff_re_im {z w : K} : z ≀ w ↔ re z ≀ re w ∧ im z = im w -- note we cannot put this in the `extends` clause [toDecidableEq : DecidableEq K] scoped[ComplexOrder] attribute [instance 100] RCLike.toPartialOrder attribute [instance 100] RCLike.toDecidableEq end variable {K E : Type*} [RCLike K] namespace RCLike /-- Coercion from `ℝ` to an `RCLike` field. -/ @[coe] abbrev ofReal : ℝ β†’ K := Algebra.cast /- The priority must be set at 900 to ensure that coercions are tried in the right order. See Note [coercion into rings], or `Mathlib/Data/Nat/Cast/Basic.lean` for more details. -/ noncomputable instance (priority := 900) algebraMapCoe : CoeTC ℝ K := ⟨ofReal⟩ theorem ofReal_alg (x : ℝ) : (x : K) = x β€’ (1 : K) := Algebra.algebraMap_eq_smul_one x theorem real_smul_eq_coe_mul (r : ℝ) (z : K) : r β€’ z = (r : K) * z := Algebra.smul_def r z theorem real_smul_eq_coe_smul [AddCommGroup E] [Module K E] [Module ℝ E] [IsScalarTower ℝ K E] (r : ℝ) (x : E) : r β€’ x = (r : K) β€’ x := by rw [RCLike.ofReal_alg, smul_one_smul] theorem algebraMap_eq_ofReal : ⇑(algebraMap ℝ K) = ofReal := rfl @[simp, rclike_simps] theorem re_add_im (z : K) : (re z : K) + im z * I = z := RCLike.re_add_im_ax z @[simp, norm_cast, rclike_simps] theorem ofReal_re : βˆ€ r : ℝ, re (r : K) = r := RCLike.ofReal_re_ax @[simp, norm_cast, rclike_simps] theorem ofReal_im : βˆ€ r : ℝ, im (r : K) = 0 := RCLike.ofReal_im_ax @[simp, rclike_simps] theorem mul_re : βˆ€ z w : K, re (z * w) = re z * re w - im z * im w := RCLike.mul_re_ax @[simp, rclike_simps] theorem mul_im : βˆ€ z w : K, im (z * w) = re z * im w + im z * re w := RCLike.mul_im_ax theorem ext_iff {z w : K} : z = w ↔ re z = re w ∧ im z = im w := ⟨fun h => h β–Έ ⟨rfl, rfl⟩, fun ⟨h₁, hβ‚‚βŸ© => re_add_im z β–Έ re_add_im w β–Έ h₁ β–Έ hβ‚‚ β–Έ rfl⟩ theorem ext {z w : K} (hre : re z = re w) (him : im z = im w) : z = w := ext_iff.2 ⟨hre, him⟩ @[norm_cast] theorem ofReal_zero : ((0 : ℝ) : K) = 0 := algebraMap.coe_zero @[rclike_simps] theorem zero_re' : re (0 : K) = (0 : ℝ) := map_zero re @[norm_cast] theorem ofReal_one : ((1 : ℝ) : K) = 1 := map_one (algebraMap ℝ K) @[simp, rclike_simps] theorem one_re : re (1 : K) = 1 := by rw [← ofReal_one, ofReal_re] @[simp, rclike_simps] theorem one_im : im (1 : K) = 0 := by rw [← ofReal_one, ofReal_im] theorem ofReal_injective : Function.Injective ((↑) : ℝ β†’ K) := (algebraMap ℝ K).injective @[norm_cast] theorem ofReal_inj {z w : ℝ} : (z : K) = (w : K) ↔ z = w := algebraMap.coe_inj -- replaced by `RCLike.ofNat_re` -- replaced by `RCLike.ofNat_im` theorem ofReal_eq_zero {x : ℝ} : (x : K) = 0 ↔ x = 0 := algebraMap.lift_map_eq_zero_iff x theorem ofReal_ne_zero {x : ℝ} : (x : K) β‰  0 ↔ x β‰  0 := ofReal_eq_zero.not @[rclike_simps, norm_cast] theorem ofReal_add (r s : ℝ) : ((r + s : ℝ) : K) = r + s := algebraMap.coe_add _ _ -- replaced by `RCLike.ofReal_ofNat` @[rclike_simps, norm_cast] theorem ofReal_neg (r : ℝ) : ((-r : ℝ) : K) = -r := algebraMap.coe_neg r @[rclike_simps, norm_cast] theorem ofReal_sub (r s : ℝ) : ((r - s : ℝ) : K) = r - s := map_sub (algebraMap ℝ K) r s @[rclike_simps, norm_cast] theorem ofReal_sum {Ξ± : Type*} (s : Finset Ξ±) (f : Ξ± β†’ ℝ) : ((βˆ‘ i ∈ s, f i : ℝ) : K) = βˆ‘ i ∈ s, (f i : K) := map_sum (algebraMap ℝ K) _ _ @[simp, rclike_simps, norm_cast] theorem ofReal_finsupp_sum {Ξ± M : Type*} [Zero M] (f : Ξ± β†’β‚€ M) (g : Ξ± β†’ M β†’ ℝ) : ((f.sum fun a b => g a b : ℝ) : K) = f.sum fun a b => (g a b : K) := map_finsuppSum (algebraMap ℝ K) f g @[rclike_simps, norm_cast] theorem ofReal_mul (r s : ℝ) : ((r * s : ℝ) : K) = r * s := algebraMap.coe_mul _ _ @[rclike_simps, norm_cast] theorem ofReal_pow (r : ℝ) (n : β„•) : ((r ^ n : ℝ) : K) = (r : K) ^ n := map_pow (algebraMap ℝ K) r n @[rclike_simps, norm_cast] theorem ofReal_prod {Ξ± : Type*} (s : Finset Ξ±) (f : Ξ± β†’ ℝ) : ((∏ i ∈ s, f i : ℝ) : K) = ∏ i ∈ s, (f i : K) := map_prod (algebraMap ℝ K) _ _ @[simp, rclike_simps, norm_cast] theorem ofReal_finsuppProd {Ξ± M : Type*} [Zero M] (f : Ξ± β†’β‚€ M) (g : Ξ± β†’ M β†’ ℝ) : ((f.prod fun a b => g a b : ℝ) : K) = f.prod fun a b => (g a b : K) := map_finsuppProd _ f g @[deprecated (since := "2025-04-06")] alias ofReal_finsupp_prod := ofReal_finsuppProd @[simp, norm_cast, rclike_simps] theorem real_smul_ofReal (r x : ℝ) : r β€’ (x : K) = (r : K) * (x : K) := real_smul_eq_coe_mul _ _ @[rclike_simps] theorem re_ofReal_mul (r : ℝ) (z : K) : re (↑r * z) = r * re z := by simp only [mul_re, ofReal_im, zero_mul, ofReal_re, sub_zero] @[rclike_simps] theorem im_ofReal_mul (r : ℝ) (z : K) : im (↑r * z) = r * im z := by simp only [add_zero, ofReal_im, zero_mul, ofReal_re, mul_im] @[rclike_simps] theorem smul_re (r : ℝ) (z : K) : re (r β€’ z) = r * re z := by rw [real_smul_eq_coe_mul, re_ofReal_mul] @[rclike_simps] theorem smul_im (r : ℝ) (z : K) : im (r β€’ z) = r * im z := by rw [real_smul_eq_coe_mul, im_ofReal_mul] @[rclike_simps, norm_cast] theorem norm_ofReal (r : ℝ) : β€–(r : K)β€– = |r| := norm_algebraMap' K r /-! ### Characteristic zero -/ -- see Note [lower instance priority] /-- ℝ and β„‚ are both of characteristic zero. -/ instance (priority := 100) charZero_rclike : CharZero K := (RingHom.charZero_iff (algebraMap ℝ K).injective).1 inferInstance @[rclike_simps, norm_cast] lemma ofReal_expect {Ξ± : Type*} (s : Finset Ξ±) (f : Ξ± β†’ ℝ) : 𝔼 i ∈ s, f i = 𝔼 i ∈ s, (f i : K) := map_expect (algebraMap ..) .. @[norm_cast] lemma ofReal_balance {ΞΉ : Type*} [Fintype ΞΉ] (f : ΞΉ β†’ ℝ) (i : ΞΉ) : ((balance f i : ℝ) : K) = balance ((↑) ∘ f) i := map_balance (algebraMap ..) .. @[simp] lemma ofReal_comp_balance {ΞΉ : Type*} [Fintype ΞΉ] (f : ΞΉ β†’ ℝ) : ofReal ∘ balance f = balance (ofReal ∘ f : ΞΉ β†’ K) := funext <| ofReal_balance _ /-! ### The imaginary unit, `I` -/ /-- The imaginary unit. -/ @[simp, rclike_simps] theorem I_re : re (I : K) = 0 := I_re_ax @[simp, rclike_simps] theorem I_im (z : K) : im z * im (I : K) = im z := mul_im_I_ax z @[simp, rclike_simps] theorem I_im' (z : K) : im (I : K) * im z = im z := by rw [mul_comm, I_im] @[rclike_simps] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11119): was `simp` theorem I_mul_re (z : K) : re (I * z) = -im z := by simp only [I_re, zero_sub, I_im', zero_mul, mul_re] theorem I_mul_I : (I : K) = 0 ∨ (I : K) * I = -1 := I_mul_I_ax variable (π•œ) in lemma I_eq_zero_or_im_I_eq_one : (I : K) = 0 ∨ im (I : K) = 1 := I_mul_I (K := K) |>.imp_right fun h ↦ by simpa [h] using (I_mul_re (I : K)).symm @[simp, rclike_simps] theorem conj_re (z : K) : re (conj z) = re z := RCLike.conj_re_ax z @[simp, rclike_simps] theorem conj_im (z : K) : im (conj z) = -im z := RCLike.conj_im_ax z @[simp, rclike_simps] theorem conj_I : conj (I : K) = -I := RCLike.conj_I_ax @[simp, rclike_simps] theorem conj_ofReal (r : ℝ) : conj (r : K) = (r : K) := by rw [ext_iff] simp only [ofReal_im, conj_im, eq_self_iff_true, conj_re, and_self_iff, neg_zero] -- replaced by `RCLike.conj_ofNat` theorem conj_nat_cast (n : β„•) : conj (n : K) = n := map_natCast _ _ theorem conj_ofNat (n : β„•) [n.AtLeastTwo] : conj (ofNat(n) : K) = ofNat(n) := map_ofNat _ _ @[rclike_simps, simp] theorem conj_neg_I : conj (-I) = (I : K) := by rw [map_neg, conj_I, neg_neg] theorem conj_eq_re_sub_im (z : K) : conj z = re z - im z * I := (congr_arg conj (re_add_im z).symm).trans <| by rw [map_add, map_mul, conj_I, conj_ofReal, conj_ofReal, mul_neg, sub_eq_add_neg] theorem sub_conj (z : K) : z - conj z = 2 * im z * I := calc z - conj z = re z + im z * I - (re z - im z * I) := by rw [re_add_im, ← conj_eq_re_sub_im] _ = 2 * im z * I := by rw [add_sub_sub_cancel, ← two_mul, mul_assoc] @[rclike_simps] theorem conj_smul (r : ℝ) (z : K) : conj (r β€’ z) = r β€’ conj z := by rw [conj_eq_re_sub_im, conj_eq_re_sub_im, smul_re, smul_im, ofReal_mul, ofReal_mul, real_smul_eq_coe_mul r (_ - _), mul_sub, mul_assoc] theorem add_conj (z : K) : z + conj z = 2 * re z := calc z + conj z = re z + im z * I + (re z - im z * I) := by rw [re_add_im, conj_eq_re_sub_im] _ = 2 * re z := by rw [add_add_sub_cancel, two_mul] theorem re_eq_add_conj (z : K) : ↑(re z) = (z + conj z) / 2 := by rw [add_conj, mul_div_cancel_leftβ‚€ (re z : K) two_ne_zero] theorem im_eq_conj_sub (z : K) : ↑(im z) = I * (conj z - z) / 2 := by rw [← neg_inj, ← ofReal_neg, ← I_mul_re, re_eq_add_conj, map_mul, conj_I, ← neg_div, ← mul_neg, neg_sub, mul_sub, neg_mul, sub_eq_add_neg] open List in /-- There are several equivalent ways to say that a number `z` is in fact a real number. -/ theorem is_real_TFAE (z : K) : TFAE [conj z = z, βˆƒ r : ℝ, (r : K) = z, ↑(re z) = z, im z = 0] := by tfae_have 1 β†’ 4 | h => by rw [← @ofReal_inj K, im_eq_conj_sub, h, sub_self, mul_zero, zero_div, ofReal_zero] tfae_have 4 β†’ 3 | h => by conv_rhs => rw [← re_add_im z, h, ofReal_zero, zero_mul, add_zero] tfae_have 3 β†’ 2 := fun h => ⟨_, h⟩ tfae_have 2 β†’ 1 := fun ⟨r, hr⟩ => hr β–Έ conj_ofReal _ tfae_finish theorem conj_eq_iff_real {z : K} : conj z = z ↔ βˆƒ r : ℝ, z = (r : K) := calc _ ↔ βˆƒ r : ℝ, (r : K) = z := (is_real_TFAE z).out 0 1 _ ↔ _ := by simp only [eq_comm] theorem conj_eq_iff_re {z : K} : conj z = z ↔ (re z : K) = z := (is_real_TFAE z).out 0 2 theorem conj_eq_iff_im {z : K} : conj z = z ↔ im z = 0 := (is_real_TFAE z).out 0 3 @[simp] theorem star_def : (Star.star : K β†’ K) = conj := rfl variable (K) /-- Conjugation as a ring equivalence. This is used to convert the inner product into a sesquilinear product. -/ abbrev conjToRingEquiv : K ≃+* Kᡐᡒᡖ := starRingEquiv variable {K} {z : K} /-- The norm squared function. -/ def normSq : K β†’*β‚€ ℝ where toFun z := re z * re z + im z * im z map_zero' := by simp only [add_zero, mul_zero, map_zero] map_one' := by simp only [one_im, add_zero, mul_one, one_re, mul_zero] map_mul' z w := by simp only [mul_im, mul_re] ring theorem normSq_apply (z : K) : normSq z = re z * re z + im z * im z := rfl theorem norm_sq_eq_def {z : K} : β€–zβ€– ^ 2 = re z * re z + im z * im z := norm_sq_eq_def_ax z theorem normSq_eq_def' (z : K) : normSq z = β€–zβ€– ^ 2 := norm_sq_eq_def.symm @[rclike_simps] theorem normSq_zero : normSq (0 : K) = 0 := normSq.map_zero @[rclike_simps] theorem normSq_one : normSq (1 : K) = 1 := normSq.map_one theorem normSq_nonneg (z : K) : 0 ≀ normSq z := add_nonneg (mul_self_nonneg _) (mul_self_nonneg _) @[rclike_simps] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11119): was `simp` theorem normSq_eq_zero {z : K} : normSq z = 0 ↔ z = 0 := map_eq_zero _ @[simp, rclike_simps] theorem normSq_pos {z : K} : 0 < normSq z ↔ z β‰  0 := by rw [lt_iff_le_and_ne, Ne, eq_comm]; simp [normSq_nonneg] @[simp, rclike_simps] theorem normSq_neg (z : K) : normSq (-z) = normSq z := by simp only [normSq_eq_def', norm_neg] @[simp, rclike_simps] theorem normSq_conj (z : K) : normSq (conj z) = normSq z := by simp only [normSq_apply, neg_mul, mul_neg, neg_neg, rclike_simps] @[rclike_simps] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11119): was `simp` theorem normSq_mul (z w : K) : normSq (z * w) = normSq z * normSq w := map_mul _ z w theorem normSq_add (z w : K) : normSq (z + w) = normSq z + normSq w + 2 * re (z * conj w) := by simp only [normSq_apply, map_add, rclike_simps] ring theorem re_sq_le_normSq (z : K) : re z * re z ≀ normSq z := le_add_of_nonneg_right (mul_self_nonneg _) theorem im_sq_le_normSq (z : K) : im z * im z ≀ normSq z := le_add_of_nonneg_left (mul_self_nonneg _) theorem mul_conj (z : K) : z * conj z = β€–zβ€– ^ 2 := by apply ext <;> simp [← ofReal_pow, norm_sq_eq_def, mul_comm] theorem conj_mul (z : K) : conj z * z = β€–zβ€– ^ 2 := by rw [mul_comm, mul_conj] lemma inv_eq_conj (hz : β€–zβ€– = 1) : z⁻¹ = conj z := inv_eq_of_mul_eq_one_left <| by simp_rw [conj_mul, hz, algebraMap.coe_one, one_pow] theorem normSq_sub (z w : K) : normSq (z - w) = normSq z + normSq w - 2 * re (z * conj w) := by simp only [normSq_add, sub_eq_add_neg, map_neg, mul_neg, normSq_neg, map_neg] theorem sqrt_normSq_eq_norm {z : K} : √(normSq z) = β€–zβ€– := by rw [normSq_eq_def', Real.sqrt_sq (norm_nonneg _)] /-! ### Inversion -/ @[rclike_simps, norm_cast] theorem ofReal_inv (r : ℝ) : ((r⁻¹ : ℝ) : K) = (r : K)⁻¹ := map_invβ‚€ _ r theorem inv_def (z : K) : z⁻¹ = conj z * ((β€–zβ€– ^ 2)⁻¹ : ℝ) := by rcases eq_or_ne z 0 with (rfl | hβ‚€) Β· simp Β· apply inv_eq_of_mul_eq_one_right rw [← mul_assoc, mul_conj, ofReal_inv, ofReal_pow, mul_inv_cancelβ‚€] simpa @[simp, rclike_simps] theorem inv_re (z : K) : re z⁻¹ = re z / normSq z := by rw [inv_def, normSq_eq_def', mul_comm, re_ofReal_mul, conj_re, div_eq_inv_mul] @[simp, rclike_simps] theorem inv_im (z : K) : im z⁻¹ = -im z / normSq z := by rw [inv_def, normSq_eq_def', mul_comm, im_ofReal_mul, conj_im, div_eq_inv_mul] theorem div_re (z w : K) : re (z / w) = re z * re w / normSq w + im z * im w / normSq w := by simp only [div_eq_mul_inv, mul_assoc, sub_eq_add_neg, neg_mul, mul_neg, neg_neg, map_neg, rclike_simps] theorem div_im (z w : K) : im (z / w) = im z * re w / normSq w - re z * im w / normSq w := by simp only [div_eq_mul_inv, mul_assoc, sub_eq_add_neg, add_comm, neg_mul, mul_neg, map_neg, rclike_simps] @[rclike_simps] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11119): was `simp` theorem conj_inv (x : K) : conj x⁻¹ = (conj x)⁻¹ := star_invβ‚€ _ lemma conj_div (x y : K) : conj (x / y) = conj x / conj y := map_div' conj conj_inv _ _ --TODO: Do we rather want the map as an explicit definition? lemma exists_norm_eq_mul_self (x : K) : βˆƒ c, β€–cβ€– = 1 ∧ ↑‖xβ€– = c * x := by obtain rfl | hx := eq_or_ne x 0 Β· exact ⟨1, by simp⟩ Β· exact βŸ¨β€–xβ€– / x, by simp [norm_ne_zero_iff.2, hx]⟩ lemma exists_norm_mul_eq_self (x : K) : βˆƒ c, β€–cβ€– = 1 ∧ c * β€–xβ€– = x := by obtain rfl | hx := eq_or_ne x 0 Β· exact ⟨1, by simp⟩ Β· exact ⟨x / β€–xβ€–, by simp [norm_ne_zero_iff.2, hx]⟩ @[rclike_simps, norm_cast] theorem ofReal_div (r s : ℝ) : ((r / s : ℝ) : K) = r / s := map_divβ‚€ (algebraMap ℝ K) r s theorem div_re_ofReal {z : K} {r : ℝ} : re (z / r) = re z / r := by rw [div_eq_inv_mul, div_eq_inv_mul, ← ofReal_inv, re_ofReal_mul] @[rclike_simps, norm_cast] theorem ofReal_zpow (r : ℝ) (n : β„€) : ((r ^ n : ℝ) : K) = (r : K) ^ n := map_zpowβ‚€ (algebraMap ℝ K) r n theorem I_mul_I_of_nonzero : (I : K) β‰  0 β†’ (I : K) * I = -1 := I_mul_I_ax.resolve_left @[simp, rclike_simps] theorem inv_I : (I : K)⁻¹ = -I := by by_cases h : (I : K) = 0 Β· simp [h] Β· field_simp [I_mul_I_of_nonzero h] @[simp, rclike_simps] theorem div_I (z : K) : z / I = -(z * I) := by rw [div_eq_mul_inv, inv_I, mul_neg]
Mathlib/Analysis/RCLike/Basic.lean
512
512
/- 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.Calculus.SmoothSeries import Mathlib.Analysis.NormedSpace.OperatorNorm.Prod import Mathlib.Analysis.SpecialFunctions.Gaussian.PoissonSummation import Mathlib.Data.Complex.FiniteDimensional /-! # The two-variable Jacobi theta function This file defines the two-variable Jacobi theta function $$\theta(z, \tau) = \sum_{n \in \mathbb{Z}} \exp (2 i \pi n z + i \pi n ^ 2 \tau),$$ and proves the functional equation relating the values at `(z, Ο„)` and `(z / Ο„, -1 / Ο„)`, using Poisson's summation formula. We also show holomorphy (jointly in both variables). Additionally, we show some analogous results about the derivative (in the `z`-variable) $$\theta'(z, Ο„) = \sum_{n \in \mathbb{Z}} 2 \pi i n \exp (2 i \pi n z + i \pi n ^ 2 \tau).$$ (Note that the Mellin transform of `ΞΈ` will give us functional equations for `L`-functions of even Dirichlet characters, and that of `ΞΈ'` will do the same for odd Dirichlet characters.) -/ open Complex Real Asymptotics Filter Topology open scoped ComplexConjugate noncomputable section section term_defs /-! ## Definitions of the summands -/ /-- Summand in the series for the Jacobi theta function. -/ def jacobiThetaβ‚‚_term (n : β„€) (z Ο„ : β„‚) : β„‚ := cexp (2 * Ο€ * I * n * z + Ο€ * I * n ^ 2 * Ο„) /-- Summand in the series for the FrΓ©chet derivative of the Jacobi theta function. -/ def jacobiThetaβ‚‚_term_fderiv (n : β„€) (z Ο„ : β„‚) : β„‚ Γ— β„‚ β†’L[β„‚] β„‚ := cexp (2 * Ο€ * I * n * z + Ο€ * I * n ^ 2 * Ο„) β€’ ((2 * Ο€ * I * n) β€’ (ContinuousLinearMap.fst β„‚ β„‚ β„‚) + (Ο€ * I * n ^ 2) β€’ (ContinuousLinearMap.snd β„‚ β„‚ β„‚)) lemma hasFDerivAt_jacobiThetaβ‚‚_term (n : β„€) (z Ο„ : β„‚) : HasFDerivAt (fun p : β„‚ Γ— β„‚ ↦ jacobiThetaβ‚‚_term n p.1 p.2) (jacobiThetaβ‚‚_term_fderiv n z Ο„) (z, Ο„) := by let f : β„‚ Γ— β„‚ β†’ β„‚ := fun p ↦ 2 * Ο€ * I * n * p.1 + Ο€ * I * n ^ 2 * p.2 suffices HasFDerivAt f ((2 * Ο€ * I * n) β€’ (ContinuousLinearMap.fst β„‚ β„‚ β„‚) + (Ο€ * I * n ^ 2) β€’ (ContinuousLinearMap.snd β„‚ β„‚ β„‚)) (z, Ο„) from this.cexp exact (hasFDerivAt_fst.const_mul _).add (hasFDerivAt_snd.const_mul _) /-- Summand in the series for the `z`-derivative of the Jacobi theta function. -/ def jacobiThetaβ‚‚'_term (n : β„€) (z Ο„ : β„‚) := 2 * Ο€ * I * n * jacobiThetaβ‚‚_term n z Ο„ end term_defs section term_bounds /-! ## Bounds for the summands We show that the sums of the three functions `jacobiThetaβ‚‚_term`, `jacobiThetaβ‚‚'_term` and `jacobiThetaβ‚‚_term_fderiv` are locally uniformly convergent in the domain `0 < im Ο„`, and diverge everywhere else. -/ lemma norm_jacobiThetaβ‚‚_term (n : β„€) (z Ο„ : β„‚) : β€–jacobiThetaβ‚‚_term n z Ο„β€– = rexp (-Ο€ * n ^ 2 * Ο„.im - 2 * Ο€ * n * z.im) := by rw [jacobiThetaβ‚‚_term, Complex.norm_exp, (by push_cast; ring : (2 * Ο€ : β„‚) * I * n * z + Ο€ * I * n ^ 2 * Ο„ = (Ο€ * (2 * n):) * z * I + (Ο€ * n ^ 2 :) * Ο„ * I), add_re, mul_I_re, im_ofReal_mul, mul_I_re, im_ofReal_mul] ring_nf /-- A uniform upper bound for `jacobiThetaβ‚‚_term` on compact subsets. -/ lemma norm_jacobiThetaβ‚‚_term_le {S T : ℝ} (hT : 0 < T) {z Ο„ : β„‚} (hz : |im z| ≀ S) (hΟ„ : T ≀ im Ο„) (n : β„€) : β€–jacobiThetaβ‚‚_term n z Ο„β€– ≀ rexp (-Ο€ * (T * n ^ 2 - 2 * S * |n|)) := by simp_rw [norm_jacobiThetaβ‚‚_term, Real.exp_le_exp, sub_eq_add_neg, neg_mul, ← neg_add, neg_le_neg_iff, mul_comm (2 : ℝ), mul_assoc Ο€, ← mul_add, mul_le_mul_left pi_pos, mul_comm T, mul_comm S] refine add_le_add (mul_le_mul le_rfl hΟ„ hT.le (sq_nonneg _)) ?_ rw [← mul_neg, mul_assoc, mul_assoc, mul_le_mul_left two_pos, mul_comm, neg_mul, ← mul_neg] refine le_trans ?_ (neg_abs_le _) rw [mul_neg, neg_le_neg_iff, abs_mul, Int.cast_abs] exact mul_le_mul_of_nonneg_left hz (abs_nonneg _) /-- A uniform upper bound for `jacobiThetaβ‚‚'_term` on compact subsets. -/ lemma norm_jacobiThetaβ‚‚'_term_le {S T : ℝ} (hT : 0 < T) {z Ο„ : β„‚} (hz : |im z| ≀ S) (hΟ„ : T ≀ im Ο„) (n : β„€) : β€–jacobiThetaβ‚‚'_term n z Ο„β€– ≀ 2 * Ο€ * |n| * rexp (-Ο€ * (T * n ^ 2 - 2 * S * |n|)) := by rw [jacobiThetaβ‚‚'_term, norm_mul] refine mul_le_mul (le_of_eq ?_) (norm_jacobiThetaβ‚‚_term_le hT hz hΟ„ n) (norm_nonneg _) (by positivity) simp only [norm_mul, Complex.norm_two, norm_I, Complex.norm_of_nonneg pi_pos.le, norm_intCast, mul_one, Int.cast_abs] /-- The uniform bound we have given is summable, and remains so after multiplying by any fixed power of `|n|` (we shall need this for `k = 0, 1, 2`). -/ lemma summable_pow_mul_jacobiThetaβ‚‚_term_bound (S : ℝ) {T : ℝ} (hT : 0 < T) (k : β„•) : Summable (fun n : β„€ ↦ (|n| ^ k : ℝ) * Real.exp (-Ο€ * (T * n ^ 2 - 2 * S * |n|))) := by suffices Summable (fun n : β„• ↦ (n ^ k : ℝ) * Real.exp (-Ο€ * (T * n ^ 2 - 2 * S * n))) by apply Summable.of_nat_of_neg <;> simpa only [Int.cast_neg, neg_sq, abs_neg, Int.cast_natCast, Nat.abs_cast] apply summable_of_isBigO_nat (summable_pow_mul_exp_neg_nat_mul k zero_lt_one) apply IsBigO.mul (isBigO_refl _ _) refine Real.isBigO_exp_comp_exp_comp.mpr (Tendsto.isBoundedUnder_le_atBot ?_) simp_rw [← tendsto_neg_atTop_iff, Pi.sub_apply] conv => enter [1, n] rw [show -(-Ο€ * (T * n ^ 2 - 2 * S * n) - -1 * n) = n * (Ο€ * T * n - (2 * Ο€ * S + 1)) by ring] refine tendsto_natCast_atTop_atTop.atTop_mul_atTopβ‚€ (tendsto_atTop_add_const_right _ _ ?_) exact tendsto_natCast_atTop_atTop.const_mul_atTop (mul_pos pi_pos hT) /-- The series defining the theta function is summable if and only if `0 < im Ο„`. -/ lemma summable_jacobiThetaβ‚‚_term_iff (z Ο„ : β„‚) : Summable (jacobiThetaβ‚‚_term Β· z Ο„) ↔ 0 < im Ο„ := by -- NB. This is a statement of no great mathematical interest; it is included largely to avoid -- having to impose `0 < im Ο„` as a hypothesis on many later lemmas. refine Iff.symm ⟨fun hΟ„ ↦ ?_, fun h ↦ ?_⟩ -- do quicker implication first! Β· refine (summable_pow_mul_jacobiThetaβ‚‚_term_bound |im z| hΟ„ 0).of_norm_bounded _ ?_ simpa only [pow_zero, one_mul] using norm_jacobiThetaβ‚‚_term_le hΟ„ le_rfl le_rfl Β· by_contra! hΟ„ rcases lt_or_eq_of_le hΟ„ with hΟ„ | hΟ„ Β· -- easy case `im Ο„ < 0` suffices Tendsto (fun n : β„• ↦ β€–jacobiThetaβ‚‚_term ↑n z Ο„β€–) atTop atTop by replace h := (h.comp_injective (fun a b ↦ Int.ofNat_inj.mp)).tendsto_atTop_zero.norm exact atTop_neBot.ne (disjoint_self.mp <| h.disjoint (disjoint_nhds_atTop _) this) simp only [norm_zero, Function.comp_def, norm_jacobiThetaβ‚‚_term, Int.cast_natCast] conv => enter [1, n] rw [show -Ο€ * n ^ 2 * Ο„.im - 2 * Ο€ * n * z.im = n * (n * (-Ο€ * Ο„.im) - 2 * Ο€ * z.im) by ring] refine tendsto_exp_atTop.comp (tendsto_natCast_atTop_atTop.atTop_mul_atTopβ‚€ ?_) exact tendsto_atTop_add_const_right _ _ (tendsto_natCast_atTop_atTop.atTop_mul_const (mul_pos_of_neg_of_neg (neg_lt_zero.mpr pi_pos) hΟ„)) Β· -- case im Ο„ = 0: 3-way split according to `im z` simp_rw [← summable_norm_iff (E := β„‚), norm_jacobiThetaβ‚‚_term, hΟ„, mul_zero, zero_sub] at h rcases lt_trichotomy (im z) 0 with hz | hz | hz Β· replace h := (h.comp_injective (fun a b ↦ Int.ofNat_inj.mp)).tendsto_atTop_zero simp_rw [Function.comp_def, Int.cast_natCast] at h refine atTop_neBot.ne (disjoint_self.mp <| h.disjoint (disjoint_nhds_atTop 0) ?_) refine tendsto_exp_atTop.comp ?_ simp only [tendsto_neg_atTop_iff, mul_assoc] apply Filter.Tendsto.const_mul_atBot two_pos exact (tendsto_natCast_atTop_atTop.atTop_mul_const_of_neg hz).const_mul_atBot pi_pos Β· revert h simpa only [hz, mul_zero, neg_zero, Real.exp_zero, summable_const_iff] using one_ne_zero Β· have : ((-↑·) : β„• β†’ β„€).Injective := fun _ _ ↦ by simp only [neg_inj, Nat.cast_inj, imp_self] replace h := (h.comp_injective this).tendsto_atTop_zero simp_rw [Function.comp_def, Int.cast_neg, Int.cast_natCast, mul_neg, neg_mul, neg_neg] at h refine atTop_neBot.ne (disjoint_self.mp <| h.disjoint (disjoint_nhds_atTop 0) ?_) exact tendsto_exp_atTop.comp ((tendsto_natCast_atTop_atTop.const_mul_atTop (mul_pos two_pos pi_pos)).atTop_mul_const hz) lemma norm_jacobiThetaβ‚‚_term_fderiv_le (n : β„€) (z Ο„ : β„‚) : β€–jacobiThetaβ‚‚_term_fderiv n z Ο„β€– ≀ 3 * Ο€ * |n| ^ 2 * β€–jacobiThetaβ‚‚_term n z Ο„β€– := by -- this is slow to elaborate so do it once and reuse: have hns (a : β„‚) (f : (β„‚ Γ— β„‚) β†’L[β„‚] β„‚) : β€–a β€’ fβ€– = β€–aβ€– * β€–fβ€– := norm_smul a f rw [jacobiThetaβ‚‚_term_fderiv, jacobiThetaβ‚‚_term, hns, mul_comm _ β€–cexp _β€–, (by norm_num : (3 : ℝ) = 2 + 1), add_mul, add_mul] refine mul_le_mul_of_nonneg_left ((norm_add_le _ _).trans (add_le_add ?_ ?_)) (norm_nonneg _) Β· simp_rw [hns, norm_mul, ← ofReal_ofNat, ← ofReal_intCast, norm_real, norm_of_nonneg zero_le_two, Real.norm_of_nonneg pi_pos.le, norm_I, mul_one, Real.norm_eq_abs, Int.cast_abs, mul_assoc] refine mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left ?_ pi_pos.le) two_pos.le refine le_trans ?_ (?_ : |(n : ℝ)| ≀ |(n : ℝ)| ^ 2) Β· exact mul_le_of_le_one_right (abs_nonneg _) (ContinuousLinearMap.norm_fst_le ..) Β· exact_mod_cast Int.le_self_sq |n| Β· simp_rw [hns, norm_mul, one_mul, norm_I, mul_one, norm_real, norm_of_nonneg pi_pos.le, ← ofReal_intCast, ← ofReal_pow, norm_real, Real.norm_eq_abs, Int.cast_abs, abs_pow] apply mul_le_of_le_one_right (mul_nonneg pi_pos.le (pow_nonneg (abs_nonneg _) _)) exact ContinuousLinearMap.norm_snd_le .. lemma norm_jacobiThetaβ‚‚_term_fderiv_ge (n : β„€) (z Ο„ : β„‚) : Ο€ * |n| ^ 2 * β€–jacobiThetaβ‚‚_term n z Ο„β€– ≀ β€–jacobiThetaβ‚‚_term_fderiv n z Ο„β€– := by have : β€–(jacobiThetaβ‚‚_term_fderiv n z Ο„) (0, 1)β€– ≀ β€–jacobiThetaβ‚‚_term_fderiv n z Ο„β€– := by refine (ContinuousLinearMap.le_opNorm _ _).trans ?_ simp_rw [Prod.norm_def, norm_one, norm_zero, max_eq_right zero_le_one, mul_one, le_refl] refine le_trans ?_ this simp_rw [jacobiThetaβ‚‚_term_fderiv, jacobiThetaβ‚‚_term, ContinuousLinearMap.coe_smul', Pi.smul_apply, ContinuousLinearMap.add_apply, ContinuousLinearMap.coe_smul', ContinuousLinearMap.coe_fst', ContinuousLinearMap.coe_snd', Pi.smul_apply, smul_zero, zero_add, smul_eq_mul, mul_one, mul_comm _ β€–cexp _β€–, norm_mul] refine mul_le_mul_of_nonneg_left (le_of_eq ?_) (norm_nonneg _) simp_rw [norm_real, norm_of_nonneg pi_pos.le, norm_I, mul_one, Int.cast_abs, ← norm_intCast, norm_pow] lemma summable_jacobiThetaβ‚‚_term_fderiv_iff (z Ο„ : β„‚) : Summable (jacobiThetaβ‚‚_term_fderiv Β· z Ο„) ↔ 0 < im Ο„ := by constructor Β· rw [← summable_jacobiThetaβ‚‚_term_iff (z := z)] intro h have := h.norm refine this.of_norm_bounded_eventually _ ?_ have : βˆ€αΆ  (n : β„€) in cofinite, n β‰  0 := Int.cofinite_eq β–Έ (mem_sup.mpr ⟨eventually_ne_atBot 0, eventually_ne_atTop 0⟩) filter_upwards [this] with n hn refine le_trans ?_ (norm_jacobiThetaβ‚‚_term_fderiv_ge n z Ο„) apply le_mul_of_one_le_left (norm_nonneg _) refine one_le_pi_div_two.trans (mul_le_mul_of_nonneg_left ?_ pi_pos.le) refine (by norm_num : 2⁻¹ ≀ (1 : ℝ)).trans ?_ rw [one_le_sq_iff_one_le_abs, ← Int.cast_abs, abs_abs, ← Int.cast_one, Int.cast_le] exact Int.one_le_abs hn Β· intro hΟ„ refine ((summable_pow_mul_jacobiThetaβ‚‚_term_bound |z.im| hΟ„ 2).mul_left (3 * Ο€)).of_norm_bounded _ (fun n ↦ ?_) refine (norm_jacobiThetaβ‚‚_term_fderiv_le n z Ο„).trans (?_ : 3 * Ο€ * |n| ^ 2 * β€–jacobiThetaβ‚‚_term n z Ο„β€– ≀ _) simp_rw [mul_assoc (3 * Ο€)] refine mul_le_mul_of_nonneg_left ?_ (mul_pos (by norm_num : 0 < (3 : ℝ)) pi_pos).le refine mul_le_mul_of_nonneg_left ?_ (pow_nonneg (Int.cast_nonneg.mpr (abs_nonneg _)) _) exact norm_jacobiThetaβ‚‚_term_le hΟ„ le_rfl le_rfl n lemma summable_jacobiThetaβ‚‚'_term_iff (z Ο„ : β„‚) : Summable (jacobiThetaβ‚‚'_term Β· z Ο„) ↔ 0 < im Ο„ := by constructor Β· rw [← summable_jacobiThetaβ‚‚_term_iff (z := z)] refine fun h ↦ (h.norm.mul_left (2 * Ο€)⁻¹).of_norm_bounded_eventually _ ?_ have : βˆ€αΆ  (n : β„€) in cofinite, n β‰  0 := Int.cofinite_eq β–Έ (mem_sup.mpr ⟨eventually_ne_atBot 0, eventually_ne_atTop 0⟩) filter_upwards [this] with n hn rw [jacobiThetaβ‚‚'_term, norm_mul, ← mul_assoc] refine le_mul_of_one_le_left (norm_nonneg _) ?_ simp_rw [norm_mul, norm_I, norm_real, mul_one, norm_of_nonneg pi_pos.le, ← ofReal_ofNat, norm_real, norm_of_nonneg two_pos.le, ← ofReal_intCast, norm_real, Real.norm_eq_abs, ← Int.cast_abs, ← mul_assoc _ (2 * Ο€), inv_mul_cancelβ‚€ (mul_pos two_pos pi_pos).ne', one_mul] rw [← Int.cast_one, Int.cast_le] exact Int.one_le_abs hn Β· refine fun hΟ„ ↦ ((summable_pow_mul_jacobiThetaβ‚‚_term_bound |z.im| hΟ„ 1).mul_left (2 * Ο€)).of_norm_bounded _ (fun n ↦ ?_) rw [jacobiThetaβ‚‚'_term, norm_mul, ← mul_assoc, pow_one] refine mul_le_mul (le_of_eq ?_) (norm_jacobiThetaβ‚‚_term_le hΟ„ le_rfl le_rfl n) (norm_nonneg _) (by positivity) simp_rw [norm_mul, Complex.norm_two, norm_I, Complex.norm_of_nonneg pi_pos.le, norm_intCast, mul_one, Int.cast_abs] end term_bounds /-! ## Definitions of the functions -/ /-- The two-variable Jacobi theta function, `ΞΈ z Ο„ = βˆ‘' (n : β„€), cexp (2 * Ο€ * I * n * z + Ο€ * I * n ^ 2 * Ο„)`. -/ def jacobiThetaβ‚‚ (z Ο„ : β„‚) : β„‚ := βˆ‘' n : β„€, jacobiThetaβ‚‚_term n z Ο„ /-- FrΓ©chet derivative of the two-variable Jacobi theta function. -/ def jacobiThetaβ‚‚_fderiv (z Ο„ : β„‚) : β„‚ Γ— β„‚ β†’L[β„‚] β„‚ := βˆ‘' n : β„€, jacobiThetaβ‚‚_term_fderiv n z Ο„ /-- The `z`-derivative of the Jacobi theta function, `ΞΈ' z Ο„ = βˆ‘' (n : β„€), 2 * Ο€ * I * n * cexp (2 * Ο€ * I * n * z + Ο€ * I * n ^ 2 * Ο„)`. -/ def jacobiThetaβ‚‚' (z Ο„ : β„‚) := βˆ‘' n : β„€, jacobiThetaβ‚‚'_term n z Ο„ lemma hasSum_jacobiThetaβ‚‚_term (z : β„‚) {Ο„ : β„‚} (hΟ„ : 0 < im Ο„) : HasSum (fun n ↦ jacobiThetaβ‚‚_term n z Ο„) (jacobiThetaβ‚‚ z Ο„) := ((summable_jacobiThetaβ‚‚_term_iff z Ο„).mpr hΟ„).hasSum lemma hasSum_jacobiThetaβ‚‚_term_fderiv (z : β„‚) {Ο„ : β„‚} (hΟ„ : 0 < im Ο„) : HasSum (fun n ↦ jacobiThetaβ‚‚_term_fderiv n z Ο„) (jacobiThetaβ‚‚_fderiv z Ο„) := ((summable_jacobiThetaβ‚‚_term_fderiv_iff z Ο„).mpr hΟ„).hasSum lemma hasSum_jacobiThetaβ‚‚'_term (z : β„‚) {Ο„ : β„‚} (hΟ„ : 0 < im Ο„) : HasSum (fun n ↦ jacobiThetaβ‚‚'_term n z Ο„) (jacobiThetaβ‚‚' z Ο„) := ((summable_jacobiThetaβ‚‚'_term_iff z Ο„).mpr hΟ„).hasSum lemma jacobiThetaβ‚‚_undef (z : β„‚) {Ο„ : β„‚} (hΟ„ : im Ο„ ≀ 0) : jacobiThetaβ‚‚ z Ο„ = 0 := by apply tsum_eq_zero_of_not_summable rw [summable_jacobiThetaβ‚‚_term_iff] exact not_lt.mpr hΟ„ lemma jacobiThetaβ‚‚_fderiv_undef (z : β„‚) {Ο„ : β„‚} (hΟ„ : im Ο„ ≀ 0) : jacobiThetaβ‚‚_fderiv z Ο„ = 0 := by apply tsum_eq_zero_of_not_summable rw [summable_jacobiThetaβ‚‚_term_fderiv_iff] exact not_lt.mpr hΟ„ lemma jacobiThetaβ‚‚'_undef (z : β„‚) {Ο„ : β„‚} (hΟ„ : im Ο„ ≀ 0) : jacobiThetaβ‚‚' z Ο„ = 0 := by apply tsum_eq_zero_of_not_summable rw [summable_jacobiThetaβ‚‚'_term_iff] exact not_lt.mpr hΟ„ /-! ## Derivatives and continuity -/
lemma hasFDerivAt_jacobiThetaβ‚‚ (z : β„‚) {Ο„ : β„‚} (hΟ„ : 0 < im Ο„) : HasFDerivAt (fun p : β„‚ Γ— β„‚ ↦ jacobiThetaβ‚‚ p.1 p.2) (jacobiThetaβ‚‚_fderiv z Ο„) (z, Ο„) := by obtain ⟨T, hT, hΟ„'⟩ := exists_between hΟ„ obtain ⟨S, hz⟩ := exists_gt |im z| let V := {u | |im u| < S} Γ—Λ’ {v | T < im v} have hVo : IsOpen V := by refine ((_root_.continuous_abs.comp continuous_im).isOpen_preimage _ isOpen_Iio).prod ?_ exact continuous_im.isOpen_preimage _ isOpen_Ioi have hVmem : (z, Ο„) ∈ V := ⟨hz, hΟ„'⟩ have hVp : IsPreconnected V := by refine (Convex.isPreconnected ?_).prod (convex_halfSpace_im_gt T).isPreconnected simpa only [abs_lt] using (convex_halfSpace_im_gt _).inter (convex_halfSpace_im_lt _) let f : β„€ β†’ β„‚ Γ— β„‚ β†’ β„‚ := fun n p ↦ jacobiThetaβ‚‚_term n p.1 p.2 let f' : β„€ β†’ β„‚ Γ— β„‚ β†’ β„‚ Γ— β„‚ β†’L[β„‚] β„‚ := fun n p ↦ jacobiThetaβ‚‚_term_fderiv n p.1 p.2 have hf (n : β„€) : βˆ€ p ∈ V, HasFDerivAt (f n) (f' n p) p := fun p _ ↦ hasFDerivAt_jacobiThetaβ‚‚_term n p.1 p.2 let u : β„€ β†’ ℝ := fun n ↦ 3 * Ο€ * |n| ^ 2 * Real.exp (-Ο€ * (T * n ^ 2 - 2 * S * |n|)) have hu : βˆ€ (n : β„€), βˆ€ x ∈ V, β€–f' n xβ€– ≀ u n := by refine fun n p hp ↦ (norm_jacobiThetaβ‚‚_term_fderiv_le n p.1 p.2).trans ?_ refine mul_le_mul_of_nonneg_left ?_ (by positivity) exact norm_jacobiThetaβ‚‚_term_le hT (le_of_lt hp.1) (le_of_lt hp.2) n have hu_sum : Summable u := by simp_rw [u, mul_assoc (3 * Ο€)] exact (summable_pow_mul_jacobiThetaβ‚‚_term_bound S hT 2).mul_left _ have hf_sum : Summable fun n : β„€ ↦ f n (z, Ο„) := by refine (summable_pow_mul_jacobiThetaβ‚‚_term_bound S hT 0).of_norm_bounded _ ?_ simpa only [pow_zero, one_mul] using norm_jacobiThetaβ‚‚_term_le hT hz.le hΟ„'.le simpa only [jacobiThetaβ‚‚, jacobiThetaβ‚‚_fderiv, f, f'] using
Mathlib/NumberTheory/ModularForms/JacobiTheta/TwoVariable.lean
291
319
/- Copyright (c) 2022 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.Analysis.Calculus.ContDiff.Basic import Mathlib.Analysis.Calculus.ParametricIntegral import Mathlib.MeasureTheory.Integral.Prod import Mathlib.MeasureTheory.Function.LocallyIntegrable import Mathlib.MeasureTheory.Group.Integral import Mathlib.MeasureTheory.Group.Prod import Mathlib.MeasureTheory.Integral.IntervalIntegral.Basic /-! # Convolution of functions This file defines the convolution on two functions, i.e. `x ↦ ∫ f(t)g(x - t) βˆ‚t`. In the general case, these functions can be vector-valued, and have an arbitrary (additive) group as domain. We use a continuous bilinear operation `L` on these function values as "multiplication". The domain must be equipped with a Haar measure `ΞΌ` (though many individual results have weaker conditions on `ΞΌ`). For many applications we can take `L = ContinuousLinearMap.lsmul ℝ ℝ` or `L = ContinuousLinearMap.mul ℝ ℝ`. We also define `ConvolutionExists` and `ConvolutionExistsAt` to state that the convolution is well-defined (everywhere or at a single point). These conditions are needed for pointwise computations (e.g. `ConvolutionExistsAt.distrib_add`), but are generally not strong enough for any local (or global) properties of the convolution. For this we need stronger assumptions on `f` and/or `g`, and generally if we impose stronger conditions on one of the functions, we can impose weaker conditions on the other. We have proven many of the properties of the convolution assuming one of these functions has compact support (in which case the other function only needs to be locally integrable). We still need to prove the properties for other pairs of conditions (e.g. both functions are rapidly decreasing) # Design Decisions We use a bilinear map `L` to "multiply" the two functions in the integrand. This generality has several advantages * This allows us to compute the total derivative of the convolution, in case the functions are multivariate. The total derivative is again a convolution, but where the codomains of the functions can be higher-dimensional. See `HasCompactSupport.hasFDerivAt_convolution_right`. * This allows us to use `@[to_additive]` everywhere (which would not be possible if we would use `mul`/`smul` in the integral, since `@[to_additive]` will incorrectly also try to additivize those definitions). * We need to support the case where at least one of the functions is vector-valued, but if we use `smul` to multiply the functions, that would be an asymmetric definition. # Main Definitions * `MeasureTheory.convolution f g L ΞΌ x = (f ⋆[L, ΞΌ] g) x = ∫ t, L (f t) (g (x - t)) βˆ‚ΞΌ` is the convolution of `f` and `g` w.r.t. the continuous bilinear map `L` and measure `ΞΌ`. * `MeasureTheory.ConvolutionExistsAt f g x L ΞΌ` states that the convolution `(f ⋆[L, ΞΌ] g) x` is well-defined (i.e. the integral exists). * `MeasureTheory.ConvolutionExists f g L ΞΌ` states that the convolution `f ⋆[L, ΞΌ] g` is well-defined at each point. # Main Results * `HasCompactSupport.hasFDerivAt_convolution_right` and `HasCompactSupport.hasFDerivAt_convolution_left`: we can compute the total derivative of the convolution as a convolution with the total derivative of the right (left) function. * `HasCompactSupport.contDiff_convolution_right` and `HasCompactSupport.contDiff_convolution_left`: the convolution is `π’žβΏ` if one of the functions is `π’žβΏ` with compact support and the other function in locally integrable. Versions of these statements for functions depending on a parameter are also given. * `MeasureTheory.convolution_tendsto_right`: Given a sequence of nonnegative normalized functions whose support tends to a small neighborhood around `0`, the convolution tends to the right argument. This is specialized to bump functions in `ContDiffBump.convolution_tendsto_right`. # Notation The following notations are localized in the locale `Convolution`: * `f ⋆[L, ΞΌ] g` for the convolution. Note: you have to use parentheses to apply the convolution to an argument: `(f ⋆[L, ΞΌ] g) x`. * `f ⋆[L] g := f ⋆[L, volume] g` * `f ⋆ g := f ⋆[lsmul ℝ ℝ] g` # To do * Existence and (uniform) continuity of the convolution if one of the maps is in `β„’^p` and the other in `β„’^q` with `1 / p + 1 / q = 1`. This might require a generalization of `MeasureTheory.MemLp.smul` where `smul` is generalized to a continuous bilinear map. (see e.g. [Fremlin, *Measure Theory* (volume 2)][fremlin_vol2], 255K) * The convolution is an `AEStronglyMeasurable` function (see e.g. [Fremlin, *Measure Theory* (volume 2)][fremlin_vol2], 255I). * Prove properties about the convolution if both functions are rapidly decreasing. * Use `@[to_additive]` everywhere (this likely requires changes in `to_additive`) -/ open Set Function Filter MeasureTheory MeasureTheory.Measure TopologicalSpace open Bornology ContinuousLinearMap Metric Topology open scoped Pointwise NNReal Filter universe uπ•œ uG uE uE' uE'' uF uF' uF'' uP variable {π•œ : Type uπ•œ} {G : Type uG} {E : Type uE} {E' : Type uE'} {E'' : Type uE''} {F : Type uF} {F' : Type uF'} {F'' : Type uF''} {P : Type uP} variable [NormedAddCommGroup E] [NormedAddCommGroup E'] [NormedAddCommGroup E''] [NormedAddCommGroup F] {f f' : G β†’ E} {g g' : G β†’ E'} {x x' : G} {y y' : E} namespace MeasureTheory section NontriviallyNormedField variable [NontriviallyNormedField π•œ] variable [NormedSpace π•œ E] [NormedSpace π•œ E'] [NormedSpace π•œ E''] [NormedSpace π•œ F] variable (L : E β†’L[π•œ] E' β†’L[π•œ] F) section NoMeasurability variable [AddGroup G] [TopologicalSpace G] theorem convolution_integrand_bound_right_of_le_of_subset {C : ℝ} (hC : βˆ€ i, β€–g iβ€– ≀ C) {x t : G} {s u : Set G} (hx : x ∈ s) (hu : -tsupport g + s βŠ† u) : β€–L (f t) (g (x - t))β€– ≀ u.indicator (fun t => β€–Lβ€– * β€–f tβ€– * C) t := by -- Porting note: had to add `f := _` refine le_indicator (f := fun t ↦ β€–L (f t) (g (x - t))β€–) (fun t _ => ?_) (fun t ht => ?_) t Β· apply_rules [L.le_of_opNormβ‚‚_le_of_le, le_rfl] Β· have : x - t βˆ‰ support g := by refine mt (fun hxt => hu ?_) ht refine ⟨_, Set.neg_mem_neg.mpr (subset_closure hxt), _, hx, ?_⟩ simp only [neg_sub, sub_add_cancel] simp only [nmem_support.mp this, (L _).map_zero, norm_zero, le_rfl] theorem _root_.HasCompactSupport.convolution_integrand_bound_right_of_subset (hcg : HasCompactSupport g) (hg : Continuous g) {x t : G} {s u : Set G} (hx : x ∈ s) (hu : -tsupport g + s βŠ† u) : β€–L (f t) (g (x - t))β€– ≀ u.indicator (fun t => β€–Lβ€– * β€–f tβ€– * ⨆ i, β€–g iβ€–) t := by refine convolution_integrand_bound_right_of_le_of_subset _ (fun i => ?_) hx hu exact le_ciSup (hg.norm.bddAbove_range_of_hasCompactSupport hcg.norm) _ theorem _root_.HasCompactSupport.convolution_integrand_bound_right (hcg : HasCompactSupport g) (hg : Continuous g) {x t : G} {s : Set G} (hx : x ∈ s) : β€–L (f t) (g (x - t))β€– ≀ (-tsupport g + s).indicator (fun t => β€–Lβ€– * β€–f tβ€– * ⨆ i, β€–g iβ€–) t := hcg.convolution_integrand_bound_right_of_subset L hg hx Subset.rfl theorem _root_.Continuous.convolution_integrand_fst [ContinuousSub G] (hg : Continuous g) (t : G) : Continuous fun x => L (f t) (g (x - t)) := L.continuousβ‚‚.compβ‚‚ continuous_const <| hg.comp <| continuous_id.sub continuous_const theorem _root_.HasCompactSupport.convolution_integrand_bound_left (hcf : HasCompactSupport f) (hf : Continuous f) {x t : G} {s : Set G} (hx : x ∈ s) : β€–L (f (x - t)) (g t)β€– ≀ (-tsupport f + s).indicator (fun t => (β€–Lβ€– * ⨆ i, β€–f iβ€–) * β€–g tβ€–) t := by convert hcf.convolution_integrand_bound_right L.flip hf hx using 1 simp_rw [L.opNorm_flip, mul_right_comm] end NoMeasurability section Measurability variable [MeasurableSpace G] {ΞΌ Ξ½ : Measure G} /-- The convolution of `f` and `g` exists at `x` when the function `t ↦ L (f t) (g (x - t))` is integrable. There are various conditions on `f` and `g` to prove this. -/ def ConvolutionExistsAt [Sub G] (f : G β†’ E) (g : G β†’ E') (x : G) (L : E β†’L[π•œ] E' β†’L[π•œ] F) (ΞΌ : Measure G := by volume_tac) : Prop := Integrable (fun t => L (f t) (g (x - t))) ΞΌ /-- The convolution of `f` and `g` exists when the function `t ↦ L (f t) (g (x - t))` is integrable for all `x : G`. There are various conditions on `f` and `g` to prove this. -/ def ConvolutionExists [Sub G] (f : G β†’ E) (g : G β†’ E') (L : E β†’L[π•œ] E' β†’L[π•œ] F) (ΞΌ : Measure G := by volume_tac) : Prop := βˆ€ x : G, ConvolutionExistsAt f g x L ΞΌ section ConvolutionExists variable {L} in theorem ConvolutionExistsAt.integrable [Sub G] {x : G} (h : ConvolutionExistsAt f g x L ΞΌ) : Integrable (fun t => L (f t) (g (x - t))) ΞΌ := h section Group variable [AddGroup G] theorem AEStronglyMeasurable.convolution_integrand' [MeasurableAddβ‚‚ G] [MeasurableNeg G] (hf : AEStronglyMeasurable f Ξ½) (hg : AEStronglyMeasurable g <| map (fun p : G Γ— G => p.1 - p.2) (ΞΌ.prod Ξ½)) : AEStronglyMeasurable (fun p : G Γ— G => L (f p.2) (g (p.1 - p.2))) (ΞΌ.prod Ξ½) := L.aestronglyMeasurable_compβ‚‚ hf.snd <| hg.comp_measurable measurable_sub section variable [MeasurableAdd G] [MeasurableNeg G] theorem AEStronglyMeasurable.convolution_integrand_snd' (hf : AEStronglyMeasurable f ΞΌ) {x : G} (hg : AEStronglyMeasurable g <| map (fun t => x - t) ΞΌ) : AEStronglyMeasurable (fun t => L (f t) (g (x - t))) ΞΌ := L.aestronglyMeasurable_compβ‚‚ hf <| hg.comp_measurable <| measurable_id.const_sub x theorem AEStronglyMeasurable.convolution_integrand_swap_snd' {x : G} (hf : AEStronglyMeasurable f <| map (fun t => x - t) ΞΌ) (hg : AEStronglyMeasurable g ΞΌ) : AEStronglyMeasurable (fun t => L (f (x - t)) (g t)) ΞΌ := L.aestronglyMeasurable_compβ‚‚ (hf.comp_measurable <| measurable_id.const_sub x) hg /-- A sufficient condition to prove that `f ⋆[L, ΞΌ] g` exists. We assume that `f` is integrable on a set `s` and `g` is bounded and ae strongly measurable on `xβ‚€ - s` (note that both properties hold if `g` is continuous with compact support). -/ theorem _root_.BddAbove.convolutionExistsAt' {xβ‚€ : G} {s : Set G} (hbg : BddAbove ((fun i => β€–g iβ€–) '' ((fun t => -t + xβ‚€) ⁻¹' s))) (hs : MeasurableSet s) (h2s : (support fun t => L (f t) (g (xβ‚€ - t))) βŠ† s) (hf : IntegrableOn f s ΞΌ) (hmg : AEStronglyMeasurable g <| map (fun t => xβ‚€ - t) (ΞΌ.restrict s)) : ConvolutionExistsAt f g xβ‚€ L ΞΌ := by rw [ConvolutionExistsAt] rw [← integrableOn_iff_integrable_of_support_subset h2s] set s' := (fun t => -t + xβ‚€) ⁻¹' s have : βˆ€α΅ t : G βˆ‚ΞΌ.restrict s, β€–L (f t) (g (xβ‚€ - t))β€– ≀ s.indicator (fun t => β€–Lβ€– * β€–f tβ€– * ⨆ i : s', β€–g iβ€–) t := by filter_upwards refine le_indicator (fun t ht => ?_) fun t ht => ?_ Β· apply_rules [L.le_of_opNormβ‚‚_le_of_le, le_rfl] refine (le_ciSup_set hbg <| mem_preimage.mpr ?_) rwa [neg_sub, sub_add_cancel] Β· have : t βˆ‰ support fun t => L (f t) (g (xβ‚€ - t)) := mt (fun h => h2s h) ht rw [nmem_support.mp this, norm_zero] refine Integrable.mono' ?_ ?_ this Β· rw [integrable_indicator_iff hs]; exact ((hf.norm.const_mul _).mul_const _).integrableOn Β· exact hf.aestronglyMeasurable.convolution_integrand_snd' L hmg /-- If `β€–fβ€– *[ΞΌ] β€–gβ€–` exists, then `f *[L, ΞΌ] g` exists. -/ theorem ConvolutionExistsAt.of_norm' {xβ‚€ : G} (h : ConvolutionExistsAt (fun x => β€–f xβ€–) (fun x => β€–g xβ€–) xβ‚€ (mul ℝ ℝ) ΞΌ) (hmf : AEStronglyMeasurable f ΞΌ) (hmg : AEStronglyMeasurable g <| map (fun t => xβ‚€ - t) ΞΌ) : ConvolutionExistsAt f g xβ‚€ L ΞΌ := by refine (h.const_mul β€–Lβ€–).mono' (hmf.convolution_integrand_snd' L hmg) (Eventually.of_forall fun x => ?_) rw [mul_apply', ← mul_assoc] apply L.le_opNormβ‚‚ @[deprecated (since := "2025-02-07")] alias ConvolutionExistsAt.ofNorm' := ConvolutionExistsAt.of_norm' end section Left variable [MeasurableAddβ‚‚ G] [MeasurableNeg G] [SFinite ΞΌ] [IsAddRightInvariant ΞΌ] theorem AEStronglyMeasurable.convolution_integrand_snd (hf : AEStronglyMeasurable f ΞΌ) (hg : AEStronglyMeasurable g ΞΌ) (x : G) : AEStronglyMeasurable (fun t => L (f t) (g (x - t))) ΞΌ := hf.convolution_integrand_snd' L <| hg.mono_ac <| (quasiMeasurePreserving_sub_left_of_right_invariant ΞΌ x).absolutelyContinuous theorem AEStronglyMeasurable.convolution_integrand_swap_snd (hf : AEStronglyMeasurable f ΞΌ) (hg : AEStronglyMeasurable g ΞΌ) (x : G) : AEStronglyMeasurable (fun t => L (f (x - t)) (g t)) ΞΌ := (hf.mono_ac (quasiMeasurePreserving_sub_left_of_right_invariant ΞΌ x).absolutelyContinuous).convolution_integrand_swap_snd' L hg /-- If `β€–fβ€– *[ΞΌ] β€–gβ€–` exists, then `f *[L, ΞΌ] g` exists. -/ theorem ConvolutionExistsAt.of_norm {xβ‚€ : G} (h : ConvolutionExistsAt (fun x => β€–f xβ€–) (fun x => β€–g xβ€–) xβ‚€ (mul ℝ ℝ) ΞΌ) (hmf : AEStronglyMeasurable f ΞΌ) (hmg : AEStronglyMeasurable g ΞΌ) : ConvolutionExistsAt f g xβ‚€ L ΞΌ := h.of_norm' L hmf <| hmg.mono_ac (quasiMeasurePreserving_sub_left_of_right_invariant ΞΌ xβ‚€).absolutelyContinuous @[deprecated (since := "2025-02-07")] alias ConvolutionExistsAt.ofNorm := ConvolutionExistsAt.of_norm end Left section Right variable [MeasurableAddβ‚‚ G] [MeasurableNeg G] [SFinite ΞΌ] [IsAddRightInvariant ΞΌ] [SFinite Ξ½] theorem AEStronglyMeasurable.convolution_integrand (hf : AEStronglyMeasurable f Ξ½) (hg : AEStronglyMeasurable g ΞΌ) : AEStronglyMeasurable (fun p : G Γ— G => L (f p.2) (g (p.1 - p.2))) (ΞΌ.prod Ξ½) := hf.convolution_integrand' L <| hg.mono_ac (quasiMeasurePreserving_sub_of_right_invariant ΞΌ Ξ½).absolutelyContinuous theorem Integrable.convolution_integrand (hf : Integrable f Ξ½) (hg : Integrable g ΞΌ) : Integrable (fun p : G Γ— G => L (f p.2) (g (p.1 - p.2))) (ΞΌ.prod Ξ½) := by have h_meas : AEStronglyMeasurable (fun p : G Γ— G => L (f p.2) (g (p.1 - p.2))) (ΞΌ.prod Ξ½) := hf.aestronglyMeasurable.convolution_integrand L hg.aestronglyMeasurable have h2_meas : AEStronglyMeasurable (fun y : G => ∫ x : G, β€–L (f y) (g (x - y))β€– βˆ‚ΞΌ) Ξ½ := h_meas.prod_swap.norm.integral_prod_right' simp_rw [integrable_prod_iff' h_meas] refine ⟨Eventually.of_forall fun t => (L (f t)).integrable_comp (hg.comp_sub_right t), ?_⟩ refine Integrable.mono' ?_ h2_meas (Eventually.of_forall fun t => (?_ : _ ≀ β€–Lβ€– * β€–f tβ€– * ∫ x, β€–g (x - t)β€– βˆ‚ΞΌ)) Β· simp only [integral_sub_right_eq_self (β€–g Β·β€–)] exact (hf.norm.const_mul _).mul_const _ Β· simp_rw [← integral_const_mul] rw [Real.norm_of_nonneg (by positivity)] exact integral_mono_of_nonneg (Eventually.of_forall fun t => norm_nonneg _) ((hg.comp_sub_right t).norm.const_mul _) (Eventually.of_forall fun t => L.le_opNormβ‚‚ _ _) theorem Integrable.ae_convolution_exists (hf : Integrable f Ξ½) (hg : Integrable g ΞΌ) : βˆ€α΅ x βˆ‚ΞΌ, ConvolutionExistsAt f g x L Ξ½ := ((integrable_prod_iff <| hf.aestronglyMeasurable.convolution_integrand L hg.aestronglyMeasurable).mp <| hf.convolution_integrand L hg).1 end Right variable [TopologicalSpace G] [IsTopologicalAddGroup G] [BorelSpace G] theorem _root_.HasCompactSupport.convolutionExistsAt {xβ‚€ : G} (h : HasCompactSupport fun t => L (f t) (g (xβ‚€ - t))) (hf : LocallyIntegrable f ΞΌ) (hg : Continuous g) : ConvolutionExistsAt f g xβ‚€ L ΞΌ := by let u := (Homeomorph.neg G).trans (Homeomorph.addRight xβ‚€) let v := (Homeomorph.neg G).trans (Homeomorph.addLeft xβ‚€) apply ((u.isCompact_preimage.mpr h).bddAbove_image hg.norm.continuousOn).convolutionExistsAt' L isClosed_closure.measurableSet subset_closure (hf.integrableOn_isCompact h) have A : AEStronglyMeasurable (g ∘ v) (ΞΌ.restrict (tsupport fun t : G => L (f t) (g (xβ‚€ - t)))) := by apply (hg.comp v.continuous).continuousOn.aestronglyMeasurable_of_isCompact h exact (isClosed_tsupport _).measurableSet convert ((v.continuous.measurable.measurePreserving (ΞΌ.restrict (tsupport fun t => L (f t) (g (xβ‚€ - t))))).aestronglyMeasurable_comp_iff v.measurableEmbedding).1 A ext x simp only [v, Homeomorph.neg, sub_eq_add_neg, val_toAddUnits_apply, Homeomorph.trans_apply, Equiv.neg_apply, Equiv.toFun_as_coe, Homeomorph.homeomorph_mk_coe, Equiv.coe_fn_mk, Homeomorph.coe_addLeft] theorem _root_.HasCompactSupport.convolutionExists_right (hcg : HasCompactSupport g) (hf : LocallyIntegrable f ΞΌ) (hg : Continuous g) : ConvolutionExists f g L ΞΌ := by intro xβ‚€ refine HasCompactSupport.convolutionExistsAt L ?_ hf hg refine (hcg.comp_homeomorph (Homeomorph.subLeft xβ‚€)).mono ?_ refine fun t => mt fun ht : g (xβ‚€ - t) = 0 => ?_ simp_rw [ht, (L _).map_zero] theorem _root_.HasCompactSupport.convolutionExists_left_of_continuous_right (hcf : HasCompactSupport f) (hf : LocallyIntegrable f ΞΌ) (hg : Continuous g) : ConvolutionExists f g L ΞΌ := by intro xβ‚€ refine HasCompactSupport.convolutionExistsAt L ?_ hf hg refine hcf.mono ?_ refine fun t => mt fun ht : f t = 0 => ?_ simp_rw [ht, L.map_zeroβ‚‚] end Group section CommGroup variable [AddCommGroup G] section MeasurableGroup variable [MeasurableNeg G] [IsAddLeftInvariant ΞΌ] /-- A sufficient condition to prove that `f ⋆[L, ΞΌ] g` exists. We assume that the integrand has compact support and `g` is bounded on this support (note that both properties hold if `g` is continuous with compact support). We also require that `f` is integrable on the support of the integrand, and that both functions are strongly measurable. This is a variant of `BddAbove.convolutionExistsAt'` in an abelian group with a left-invariant measure. This allows us to state the boundedness and measurability of `g` in a more natural way. -/ theorem _root_.BddAbove.convolutionExistsAt [MeasurableAddβ‚‚ G] [SFinite ΞΌ] {xβ‚€ : G} {s : Set G} (hbg : BddAbove ((fun i => β€–g iβ€–) '' ((fun t => xβ‚€ - t) ⁻¹' s))) (hs : MeasurableSet s) (h2s : (support fun t => L (f t) (g (xβ‚€ - t))) βŠ† s) (hf : IntegrableOn f s ΞΌ) (hmg : AEStronglyMeasurable g ΞΌ) : ConvolutionExistsAt f g xβ‚€ L ΞΌ := by refine BddAbove.convolutionExistsAt' L ?_ hs h2s hf ?_ Β· simp_rw [← sub_eq_neg_add, hbg] Β· have : AEStronglyMeasurable g (map (fun t : G => xβ‚€ - t) ΞΌ) := hmg.mono_ac (quasiMeasurePreserving_sub_left_of_right_invariant ΞΌ xβ‚€).absolutelyContinuous apply this.mono_measure exact map_mono restrict_le_self (measurable_const.sub measurable_id') variable {L} [MeasurableAdd G] [IsNegInvariant ΞΌ] theorem convolutionExistsAt_flip : ConvolutionExistsAt g f x L.flip ΞΌ ↔ ConvolutionExistsAt f g x L ΞΌ := by simp_rw [ConvolutionExistsAt, ← integrable_comp_sub_left (fun t => L (f t) (g (x - t))) x, sub_sub_cancel, flip_apply] theorem ConvolutionExistsAt.integrable_swap (h : ConvolutionExistsAt f g x L ΞΌ) : Integrable (fun t => L (f (x - t)) (g t)) ΞΌ := by convert h.comp_sub_left x simp_rw [sub_sub_self] theorem convolutionExistsAt_iff_integrable_swap : ConvolutionExistsAt f g x L ΞΌ ↔ Integrable (fun t => L (f (x - t)) (g t)) ΞΌ := convolutionExistsAt_flip.symm end MeasurableGroup variable [TopologicalSpace G] [IsTopologicalAddGroup G] [BorelSpace G] variable [IsAddLeftInvariant ΞΌ] [IsNegInvariant ΞΌ] theorem _root_.HasCompactSupport.convolutionExists_left (hcf : HasCompactSupport f) (hf : Continuous f) (hg : LocallyIntegrable g ΞΌ) : ConvolutionExists f g L ΞΌ := fun xβ‚€ => convolutionExistsAt_flip.mp <| hcf.convolutionExists_right L.flip hg hf xβ‚€ @[deprecated (since := "2025-02-06")] alias _root_.HasCompactSupport.convolutionExistsLeft := HasCompactSupport.convolutionExists_left theorem _root_.HasCompactSupport.convolutionExists_right_of_continuous_left (hcg : HasCompactSupport g) (hf : Continuous f) (hg : LocallyIntegrable g ΞΌ) : ConvolutionExists f g L ΞΌ := fun xβ‚€ => convolutionExistsAt_flip.mp <| hcg.convolutionExists_left_of_continuous_right L.flip hg hf xβ‚€ @[deprecated (since := "2025-02-06")] alias _root_.HasCompactSupport.convolutionExistsRightOfContinuousLeft := HasCompactSupport.convolutionExists_right_of_continuous_left end CommGroup end ConvolutionExists variable [NormedSpace ℝ F] /-- The convolution of two functions `f` and `g` with respect to a continuous bilinear map `L` and measure `ΞΌ`. It is defined to be `(f ⋆[L, ΞΌ] g) x = ∫ t, L (f t) (g (x - t)) βˆ‚ΞΌ`. -/ noncomputable def convolution [Sub G] (f : G β†’ E) (g : G β†’ E') (L : E β†’L[π•œ] E' β†’L[π•œ] F) (ΞΌ : Measure G := by volume_tac) : G β†’ F := fun x => ∫ t, L (f t) (g (x - t)) βˆ‚ΞΌ /-- The convolution of two functions with respect to a bilinear operation `L` and a measure `ΞΌ`. -/ scoped[Convolution] notation:67 f " ⋆[" L:67 ", " ΞΌ:67 "] " g:66 => convolution f g L ΞΌ /-- The convolution of two functions with respect to a bilinear operation `L` and the volume. -/ scoped[Convolution] notation:67 f " ⋆[" L:67 "]" g:66 => convolution f g L MeasureSpace.volume /-- The convolution of two real-valued functions with respect to volume. -/ scoped[Convolution] notation:67 f " ⋆ " g:66 => convolution f g (ContinuousLinearMap.lsmul ℝ ℝ) MeasureSpace.volume open scoped Convolution theorem convolution_def [Sub G] : (f ⋆[L, ΞΌ] g) x = ∫ t, L (f t) (g (x - t)) βˆ‚ΞΌ := rfl /-- The definition of convolution where the bilinear operator is scalar multiplication. Note: it often helps the elaborator to give the type of the convolution explicitly. -/ theorem convolution_lsmul [Sub G] {f : G β†’ π•œ} {g : G β†’ F} : (f ⋆[lsmul π•œ π•œ, ΞΌ] g : G β†’ F) x = ∫ t, f t β€’ g (x - t) βˆ‚ΞΌ := rfl /-- The definition of convolution where the bilinear operator is multiplication. -/ theorem convolution_mul [Sub G] [NormedSpace ℝ π•œ] {f : G β†’ π•œ} {g : G β†’ π•œ} : (f ⋆[mul π•œ π•œ, ΞΌ] g) x = ∫ t, f t * g (x - t) βˆ‚ΞΌ := rfl section Group variable {L} [AddGroup G] theorem smul_convolution [SMulCommClass ℝ π•œ F] {y : π•œ} : y β€’ f ⋆[L, ΞΌ] g = y β€’ (f ⋆[L, ΞΌ] g) := by ext; simp only [Pi.smul_apply, convolution_def, ← integral_smul, L.map_smulβ‚‚] theorem convolution_smul [SMulCommClass ℝ π•œ F] {y : π•œ} : f ⋆[L, ΞΌ] y β€’ g = y β€’ (f ⋆[L, ΞΌ] g) := by ext; simp only [Pi.smul_apply, convolution_def, ← integral_smul, (L _).map_smul] @[simp] theorem zero_convolution : 0 ⋆[L, ΞΌ] g = 0 := by ext simp_rw [convolution_def, Pi.zero_apply, L.map_zeroβ‚‚, integral_zero] @[simp] theorem convolution_zero : f ⋆[L, ΞΌ] 0 = 0 := by ext simp_rw [convolution_def, Pi.zero_apply, (L _).map_zero, integral_zero] theorem ConvolutionExistsAt.distrib_add {x : G} (hfg : ConvolutionExistsAt f g x L ΞΌ) (hfg' : ConvolutionExistsAt f g' x L ΞΌ) : (f ⋆[L, ΞΌ] (g + g')) x = (f ⋆[L, ΞΌ] g) x + (f ⋆[L, ΞΌ] g') x := by simp only [convolution_def, (L _).map_add, Pi.add_apply, integral_add hfg hfg'] theorem ConvolutionExists.distrib_add (hfg : ConvolutionExists f g L ΞΌ) (hfg' : ConvolutionExists f g' L ΞΌ) : f ⋆[L, ΞΌ] (g + g') = f ⋆[L, ΞΌ] g + f ⋆[L, ΞΌ] g' := by ext x exact (hfg x).distrib_add (hfg' x) theorem ConvolutionExistsAt.add_distrib {x : G} (hfg : ConvolutionExistsAt f g x L ΞΌ) (hfg' : ConvolutionExistsAt f' g x L ΞΌ) : ((f + f') ⋆[L, ΞΌ] g) x = (f ⋆[L, ΞΌ] g) x + (f' ⋆[L, ΞΌ] g) x := by simp only [convolution_def, L.map_addβ‚‚, Pi.add_apply, integral_add hfg hfg'] theorem ConvolutionExists.add_distrib (hfg : ConvolutionExists f g L ΞΌ) (hfg' : ConvolutionExists f' g L ΞΌ) : (f + f') ⋆[L, ΞΌ] g = f ⋆[L, ΞΌ] g + f' ⋆[L, ΞΌ] g := by ext x exact (hfg x).add_distrib (hfg' x) theorem convolution_mono_right {f g g' : G β†’ ℝ} (hfg : ConvolutionExistsAt f g x (lsmul ℝ ℝ) ΞΌ) (hfg' : ConvolutionExistsAt f g' x (lsmul ℝ ℝ) ΞΌ) (hf : βˆ€ x, 0 ≀ f x) (hg : βˆ€ x, g x ≀ g' x) : (f ⋆[lsmul ℝ ℝ, ΞΌ] g) x ≀ (f ⋆[lsmul ℝ ℝ, ΞΌ] g') x := by apply integral_mono hfg hfg' simp only [lsmul_apply, Algebra.id.smul_eq_mul] intro t apply mul_le_mul_of_nonneg_left (hg _) (hf _) theorem convolution_mono_right_of_nonneg {f g g' : G β†’ ℝ} (hfg' : ConvolutionExistsAt f g' x (lsmul ℝ ℝ) ΞΌ) (hf : βˆ€ x, 0 ≀ f x) (hg : βˆ€ x, g x ≀ g' x) (hg' : βˆ€ x, 0 ≀ g' x) : (f ⋆[lsmul ℝ ℝ, ΞΌ] g) x ≀ (f ⋆[lsmul ℝ ℝ, ΞΌ] g') x := by by_cases H : ConvolutionExistsAt f g x (lsmul ℝ ℝ) ΞΌ Β· exact convolution_mono_right H hfg' hf hg have : (f ⋆[lsmul ℝ ℝ, ΞΌ] g) x = 0 := integral_undef H rw [this] exact integral_nonneg fun y => mul_nonneg (hf y) (hg' (x - y)) variable (L) theorem convolution_congr [MeasurableAddβ‚‚ G] [MeasurableNeg G] [SFinite ΞΌ] [IsAddRightInvariant ΞΌ] (h1 : f =ᡐ[ΞΌ] f') (h2 : g =ᡐ[ΞΌ] g') : f ⋆[L, ΞΌ] g = f' ⋆[L, ΞΌ] g' := by ext x apply integral_congr_ae exact (h1.prodMk <| h2.comp_tendsto (quasiMeasurePreserving_sub_left_of_right_invariant ΞΌ x).tendsto_ae).fun_comp β†Ώfun x y ↦ L x y theorem support_convolution_subset_swap : support (f ⋆[L, ΞΌ] g) βŠ† support g + support f := by intro x h2x by_contra hx apply h2x simp_rw [Set.mem_add, ← exists_and_left, not_exists, not_and_or, nmem_support] at hx rw [convolution_def] convert integral_zero G F using 2 ext t rcases hx (x - t) t with (h | h | h) Β· rw [h, (L _).map_zero] Β· rw [h, L.map_zeroβ‚‚] Β· exact (h <| sub_add_cancel x t).elim section variable [MeasurableAddβ‚‚ G] [MeasurableNeg G] [SFinite ΞΌ] [IsAddRightInvariant ΞΌ] theorem Integrable.integrable_convolution (hf : Integrable f ΞΌ) (hg : Integrable g ΞΌ) : Integrable (f ⋆[L, ΞΌ] g) ΞΌ := (hf.convolution_integrand L hg).integral_prod_left end variable [TopologicalSpace G] variable [IsTopologicalAddGroup G] protected theorem _root_.HasCompactSupport.convolution [T2Space G] (hcf : HasCompactSupport f) (hcg : HasCompactSupport g) : HasCompactSupport (f ⋆[L, ΞΌ] g) := (hcg.isCompact.add hcf).of_isClosed_subset isClosed_closure <| closure_minimal ((support_convolution_subset_swap L).trans <| add_subset_add subset_closure subset_closure) (hcg.isCompact.add hcf).isClosed variable [BorelSpace G] [TopologicalSpace P] /-- The convolution `f * g` is continuous if `f` is locally integrable and `g` is continuous and compactly supported. Version where `g` depends on an additional parameter in a subset `s` of a parameter space `P` (and the compact support `k` is independent of the parameter in `s`). -/ theorem continuousOn_convolution_right_with_param {g : P β†’ G β†’ E'} {s : Set P} {k : Set G} (hk : IsCompact k) (hgs : βˆ€ p, βˆ€ x, p ∈ s β†’ x βˆ‰ k β†’ g p x = 0) (hf : LocallyIntegrable f ΞΌ) (hg : ContinuousOn (β†Ώg) (s Γ—Λ’ univ)) : ContinuousOn (fun q : P Γ— G => (f ⋆[L, ΞΌ] g q.1) q.2) (s Γ—Λ’ univ) := by /- First get rid of the case where the space is not locally compact. Then `g` vanishes everywhere and the conclusion is trivial. -/ by_cases H : βˆ€ p ∈ s, βˆ€ x, g p x = 0 Β· apply (continuousOn_const (c := 0)).congr rintro ⟨p, x⟩ ⟨hp, -⟩ apply integral_eq_zero_of_ae (Eventually.of_forall (fun y ↦ ?_)) simp [H p hp _] have : LocallyCompactSpace G := by push_neg at H rcases H with ⟨p, hp, x, hx⟩ have A : support (g p) βŠ† k := support_subset_iff'.2 (fun y hy ↦ hgs p y hp hy) have B : Continuous (g p) := by refine hg.comp_continuous (.prodMk_right _) fun x => ?_ simpa only [prodMk_mem_set_prod_eq, mem_univ, and_true] using hp rcases eq_zero_or_locallyCompactSpace_of_support_subset_isCompact_of_addGroup hk A B with H|H Β· simp [H] at hx Β· exact H /- Since `G` is locally compact, one may thicken `k` a little bit into a larger compact set `(-k) + t`, outside of which all functions that appear in the convolution vanish. Then we can apply a continuity statement for integrals depending on a parameter, with respect to locally integrable functions and compactly supported continuous functions. -/ rintro ⟨qβ‚€, xβ‚€βŸ© ⟨hqβ‚€, -⟩ obtain ⟨t, t_comp, ht⟩ : βˆƒ t, IsCompact t ∧ t ∈ 𝓝 xβ‚€ := exists_compact_mem_nhds xβ‚€ let k' : Set G := (-k) +α΅₯ t have k'_comp : IsCompact k' := IsCompact.vadd_set hk.neg t_comp let g' : (P Γ— G) β†’ G β†’ E' := fun p x ↦ g p.1 (p.2 - x) let s' : Set (P Γ— G) := s Γ—Λ’ t have A : ContinuousOn g'.uncurry (s' Γ—Λ’ univ) := by have : g'.uncurry = g.uncurry ∘ (fun w ↦ (w.1.1, w.1.2 - w.2)) := by ext y; rfl rw [this] refine hg.comp (by fun_prop) ?_ simp +contextual [s', MapsTo] have B : ContinuousOn (fun a ↦ ∫ x, L (f x) (g' a x) βˆ‚ΞΌ) s' := by apply continuousOn_integral_bilinear_of_locally_integrable_of_compact_support L k'_comp A _ (hf.integrableOn_isCompact k'_comp) rintro ⟨p, x⟩ y ⟨hp, hx⟩ hy apply hgs p _ hp contrapose! hy exact ⟨y - x, by simpa using hy, x, hx, by simp⟩ apply ContinuousWithinAt.mono_of_mem_nhdsWithin (B (qβ‚€, xβ‚€) ⟨hqβ‚€, mem_of_mem_nhds ht⟩) exact mem_nhdsWithin_prod_iff.2 ⟨s, self_mem_nhdsWithin, t, nhdsWithin_le_nhds ht, Subset.rfl⟩ /-- The convolution `f * g` is continuous if `f` is locally integrable and `g` is continuous and compactly supported. Version where `g` depends on an additional parameter in an open subset `s` of a parameter space `P` (and the compact support `k` is independent of the parameter in `s`), given in terms of compositions with an additional continuous map. -/ theorem continuousOn_convolution_right_with_param_comp {s : Set P} {v : P β†’ G} (hv : ContinuousOn v s) {g : P β†’ G β†’ E'} {k : Set G} (hk : IsCompact k) (hgs : βˆ€ p, βˆ€ x, p ∈ s β†’ x βˆ‰ k β†’ g p x = 0) (hf : LocallyIntegrable f ΞΌ) (hg : ContinuousOn (β†Ώg) (s Γ—Λ’ univ)) : ContinuousOn (fun x => (f ⋆[L, ΞΌ] g x) (v x)) s := by apply (continuousOn_convolution_right_with_param L hk hgs hf hg).comp (continuousOn_id.prodMk hv) intro x hx simp only [hx, prodMk_mem_set_prod_eq, mem_univ, and_self_iff, _root_.id] /-- The convolution is continuous if one function is locally integrable and the other has compact support and is continuous. -/ theorem _root_.HasCompactSupport.continuous_convolution_right (hcg : HasCompactSupport g) (hf : LocallyIntegrable f ΞΌ) (hg : Continuous g) : Continuous (f ⋆[L, ΞΌ] g) := by rw [continuous_iff_continuousOn_univ] let g' : G β†’ G β†’ E' := fun _ q => g q have : ContinuousOn (β†Ώg') (univ Γ—Λ’ univ) := (hg.comp continuous_snd).continuousOn exact continuousOn_convolution_right_with_param_comp L (continuous_iff_continuousOn_univ.1 continuous_id) hcg (fun p x _ hx => image_eq_zero_of_nmem_tsupport hx) hf this /-- The convolution is continuous if one function is integrable and the other is bounded and continuous. -/ theorem _root_.BddAbove.continuous_convolution_right_of_integrable [FirstCountableTopology G] [SecondCountableTopologyEither G E'] (hbg : BddAbove (range fun x => β€–g xβ€–)) (hf : Integrable f ΞΌ) (hg : Continuous g) : Continuous (f ⋆[L, ΞΌ] g) := by refine continuous_iff_continuousAt.mpr fun xβ‚€ => ?_ have : βˆ€αΆ  x in 𝓝 xβ‚€, βˆ€α΅ t : G βˆ‚ΞΌ, β€–L (f t) (g (x - t))β€– ≀ β€–Lβ€– * β€–f tβ€– * ⨆ i, β€–g iβ€– := by filter_upwards with x; filter_upwards with t apply_rules [L.le_of_opNormβ‚‚_le_of_le, le_rfl, le_ciSup hbg (x - t)] refine continuousAt_of_dominated ?_ this ?_ ?_ Β· exact Eventually.of_forall fun x => hf.aestronglyMeasurable.convolution_integrand_snd' L hg.aestronglyMeasurable Β· exact (hf.norm.const_mul _).mul_const _ Β· exact Eventually.of_forall fun t => (L.continuousβ‚‚.compβ‚‚ continuous_const <| hg.comp <| continuous_id.sub continuous_const).continuousAt end Group section CommGroup variable [AddCommGroup G] theorem support_convolution_subset : support (f ⋆[L, ΞΌ] g) βŠ† support f + support g := (support_convolution_subset_swap L).trans (add_comm _ _).subset variable [IsAddLeftInvariant ΞΌ] [IsNegInvariant ΞΌ] section Measurable variable [MeasurableNeg G] variable [MeasurableAdd G] /-- Commutativity of convolution -/ theorem convolution_flip : g ⋆[L.flip, ΞΌ] f = f ⋆[L, ΞΌ] g := by ext1 x simp_rw [convolution_def] rw [← integral_sub_left_eq_self _ ΞΌ x] simp_rw [sub_sub_self, flip_apply] /-- The symmetric definition of convolution. -/ theorem convolution_eq_swap : (f ⋆[L, ΞΌ] g) x = ∫ t, L (f (x - t)) (g t) βˆ‚ΞΌ := by rw [← convolution_flip]; rfl /-- The symmetric definition of convolution where the bilinear operator is scalar multiplication. -/ theorem convolution_lsmul_swap {f : G β†’ π•œ} {g : G β†’ F} : (f ⋆[lsmul π•œ π•œ, ΞΌ] g : G β†’ F) x = ∫ t, f (x - t) β€’ g t βˆ‚ΞΌ := convolution_eq_swap _ /-- The symmetric definition of convolution where the bilinear operator is multiplication. -/ theorem convolution_mul_swap [NormedSpace ℝ π•œ] {f : G β†’ π•œ} {g : G β†’ π•œ} : (f ⋆[mul π•œ π•œ, ΞΌ] g) x = ∫ t, f (x - t) * g t βˆ‚ΞΌ := convolution_eq_swap _ /-- The convolution of two even functions is also even. -/ theorem convolution_neg_of_neg_eq (h1 : βˆ€α΅ x βˆ‚ΞΌ, f (-x) = f x) (h2 : βˆ€α΅ x βˆ‚ΞΌ, g (-x) = g x) : (f ⋆[L, ΞΌ] g) (-x) = (f ⋆[L, ΞΌ] g) x := calc ∫ t : G, (L (f t)) (g (-x - t)) βˆ‚ΞΌ = ∫ t : G, (L (f (-t))) (g (x + t)) βˆ‚ΞΌ := by apply integral_congr_ae filter_upwards [h1, (eventually_add_left_iff ΞΌ x).2 h2] with t ht h't simp_rw [ht, ← h't, neg_add'] _ = ∫ t : G, (L (f t)) (g (x - t)) βˆ‚ΞΌ := by rw [← integral_neg_eq_self] simp only [neg_neg, ← sub_eq_add_neg] end Measurable variable [TopologicalSpace G] variable [IsTopologicalAddGroup G] variable [BorelSpace G] theorem _root_.HasCompactSupport.continuous_convolution_left (hcf : HasCompactSupport f) (hf : Continuous f) (hg : LocallyIntegrable g ΞΌ) : Continuous (f ⋆[L, ΞΌ] g) := by rw [← convolution_flip] exact hcf.continuous_convolution_right L.flip hg hf theorem _root_.BddAbove.continuous_convolution_left_of_integrable [FirstCountableTopology G] [SecondCountableTopologyEither G E] (hbf : BddAbove (range fun x => β€–f xβ€–)) (hf : Continuous f) (hg : Integrable g ΞΌ) : Continuous (f ⋆[L, ΞΌ] g) := by rw [← convolution_flip] exact hbf.continuous_convolution_right_of_integrable L.flip hg hf end CommGroup section NormedAddCommGroup
variable [SeminormedAddCommGroup G]
Mathlib/Analysis/Convolution.lean
711
712
/- 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, Kim Morrison, Jens Wagemaker, Johan Commelin -/ import Mathlib.Algebra.Polynomial.BigOperators import Mathlib.Algebra.Polynomial.RingDivision import Mathlib.Data.Set.Finite.Lemmas import Mathlib.RingTheory.Coprime.Lemmas import Mathlib.RingTheory.Localization.FractionRing import Mathlib.SetTheory.Cardinal.Order /-! # Theory of univariate polynomials We define the multiset of roots of a polynomial, and prove basic results about it. ## Main definitions * `Polynomial.roots p`: The multiset containing all the roots of `p`, including their multiplicities. * `Polynomial.rootSet p E`: The set of distinct roots of `p` in an algebra `E`. ## Main statements * `Polynomial.C_leadingCoeff_mul_prod_multiset_X_sub_C`: If a polynomial has as many roots as its degree, it can be written as the product of its leading coefficient with `∏ (X - a)` where `a` ranges through its roots. -/ assert_not_exists Ideal open Multiset Finset noncomputable section 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] [IsDomain R] {p q : R[X]} section Roots /-- `roots p` noncomputably gives a multiset containing all the roots of `p`, including their multiplicities. -/ noncomputable def roots (p : R[X]) : Multiset R := haveI := Classical.decEq R haveI := Classical.dec (p = 0) if h : p = 0 then βˆ… else Classical.choose (exists_multiset_roots h) theorem roots_def [DecidableEq R] (p : R[X]) [Decidable (p = 0)] : p.roots = if h : p = 0 then βˆ… else Classical.choose (exists_multiset_roots h) := by rename_i iR ip0 obtain rfl := Subsingleton.elim iR (Classical.decEq R) obtain rfl := Subsingleton.elim ip0 (Classical.dec (p = 0)) rfl @[simp] theorem roots_zero : (0 : R[X]).roots = 0 := dif_pos rfl theorem card_roots (hp0 : p β‰  0) : (Multiset.card (roots p) : WithBot β„•) ≀ degree p := by classical unfold roots rw [dif_neg hp0] exact (Classical.choose_spec (exists_multiset_roots hp0)).1 theorem card_roots' (p : R[X]) : Multiset.card p.roots ≀ natDegree p := by by_cases hp0 : p = 0 Β· simp [hp0] exact WithBot.coe_le_coe.1 (le_trans (card_roots hp0) (le_of_eq <| degree_eq_natDegree hp0)) theorem card_roots_sub_C {p : R[X]} {a : R} (hp0 : 0 < degree p) : (Multiset.card (p - C a).roots : WithBot β„•) ≀ degree p := calc (Multiset.card (p - C a).roots : WithBot β„•) ≀ degree (p - C a) := card_roots <| mt sub_eq_zero.1 fun h => not_le_of_gt hp0 <| h.symm β–Έ degree_C_le _ = degree p := by rw [sub_eq_add_neg, ← C_neg]; exact degree_add_C hp0 theorem card_roots_sub_C' {p : R[X]} {a : R} (hp0 : 0 < degree p) : Multiset.card (p - C a).roots ≀ natDegree p := WithBot.coe_le_coe.1 (le_trans (card_roots_sub_C hp0) (le_of_eq <| degree_eq_natDegree fun h => by simp_all [lt_irrefl])) @[simp] theorem count_roots [DecidableEq R] (p : R[X]) : p.roots.count a = rootMultiplicity a p := by classical by_cases hp : p = 0 Β· simp [hp] rw [roots_def, dif_neg hp] exact (Classical.choose_spec (exists_multiset_roots hp)).2 a @[simp] theorem mem_roots' : a ∈ p.roots ↔ p β‰  0 ∧ IsRoot p a := by classical rw [← count_pos, count_roots p, rootMultiplicity_pos'] theorem mem_roots (hp : p β‰  0) : a ∈ p.roots ↔ IsRoot p a := mem_roots'.trans <| and_iff_right hp theorem ne_zero_of_mem_roots (h : a ∈ p.roots) : p β‰  0 := (mem_roots'.1 h).1 theorem isRoot_of_mem_roots (h : a ∈ p.roots) : IsRoot p a := (mem_roots'.1 h).2 theorem mem_roots_map_of_injective [Semiring S] {p : S[X]} {f : S β†’+* R} (hf : Function.Injective f) {x : R} (hp : p β‰  0) : x ∈ (p.map f).roots ↔ p.evalβ‚‚ f x = 0 := by rw [mem_roots ((Polynomial.map_ne_zero_iff hf).mpr hp), IsRoot, eval_map] lemma mem_roots_iff_aeval_eq_zero {x : R} (w : p β‰  0) : x ∈ roots p ↔ aeval x p = 0 := by rw [aeval_def, ← mem_roots_map_of_injective (FaithfulSMul.algebraMap_injective _ _) w, Algebra.id.map_eq_id, map_id] theorem card_le_degree_of_subset_roots {p : R[X]} {Z : Finset R} (h : Z.val βŠ† p.roots) : #Z ≀ p.natDegree := (Multiset.card_le_card (Finset.val_le_iff_val_subset.2 h)).trans (Polynomial.card_roots' p) theorem finite_setOf_isRoot {p : R[X]} (hp : p β‰  0) : Set.Finite { x | IsRoot p x } := by classical simpa only [← Finset.setOf_mem, Multiset.mem_toFinset, mem_roots hp] using p.roots.toFinset.finite_toSet theorem eq_zero_of_infinite_isRoot (p : R[X]) (h : Set.Infinite { x | IsRoot p x }) : p = 0 := not_imp_comm.mp finite_setOf_isRoot h theorem exists_max_root [LinearOrder R] (p : R[X]) (hp : p β‰  0) : βˆƒ xβ‚€, βˆ€ x, p.IsRoot x β†’ x ≀ xβ‚€ := Set.exists_upper_bound_image _ _ <| finite_setOf_isRoot hp theorem exists_min_root [LinearOrder R] (p : R[X]) (hp : p β‰  0) : βˆƒ xβ‚€, βˆ€ x, p.IsRoot x β†’ xβ‚€ ≀ x := Set.exists_lower_bound_image _ _ <| finite_setOf_isRoot hp theorem eq_of_infinite_eval_eq (p q : R[X]) (h : Set.Infinite { x | eval x p = eval x q }) : p = q := by rw [← sub_eq_zero] apply eq_zero_of_infinite_isRoot simpa only [IsRoot, eval_sub, sub_eq_zero] theorem roots_mul {p q : R[X]} (hpq : p * q β‰  0) : (p * q).roots = p.roots + q.roots := by classical exact Multiset.ext.mpr fun r => by rw [count_add, count_roots, count_roots, count_roots, rootMultiplicity_mul hpq] theorem roots.le_of_dvd (h : q β‰  0) : p ∣ q β†’ roots p ≀ roots q := by rintro ⟨k, rfl⟩ exact Multiset.le_iff_exists_add.mpr ⟨k.roots, roots_mul h⟩ theorem mem_roots_sub_C' {p : R[X]} {a x : R} : x ∈ (p - C a).roots ↔ p β‰  C a ∧ p.eval x = a := by rw [mem_roots', IsRoot.def, sub_ne_zero, eval_sub, sub_eq_zero, eval_C] theorem mem_roots_sub_C {p : R[X]} {a x : R} (hp0 : 0 < degree p) : x ∈ (p - C a).roots ↔ p.eval x = a := mem_roots_sub_C'.trans <| and_iff_right fun hp => hp0.not_le <| hp.symm β–Έ degree_C_le @[simp] theorem roots_X_sub_C (r : R) : roots (X - C r) = {r} := by classical ext s rw [count_roots, rootMultiplicity_X_sub_C, count_singleton] @[simp] theorem roots_X_add_C (r : R) : roots (X + C r) = {-r} := by simpa using roots_X_sub_C (-r) @[simp] theorem roots_X : roots (X : R[X]) = {0} := by rw [← roots_X_sub_C, C_0, sub_zero] @[simp] theorem roots_C (x : R) : (C x).roots = 0 := by classical exact if H : x = 0 then by rw [H, C_0, roots_zero] else Multiset.ext.mpr fun r => (by rw [count_roots, count_zero, rootMultiplicity_eq_zero (not_isRoot_C _ _ H)]) @[simp] theorem roots_one : (1 : R[X]).roots = βˆ… := roots_C 1 @[simp] theorem roots_C_mul (p : R[X]) (ha : a β‰  0) : (C a * p).roots = p.roots := by by_cases hp : p = 0 <;> simp only [roots_mul, *, Ne, mul_eq_zero, C_eq_zero, or_self_iff, not_false_iff, roots_C, zero_add, mul_zero] @[simp] theorem roots_smul_nonzero (p : R[X]) (ha : a β‰  0) : (a β€’ p).roots = p.roots := by rw [smul_eq_C_mul, roots_C_mul _ ha] @[simp] lemma roots_neg (p : R[X]) : (-p).roots = p.roots := by rw [← neg_one_smul R p, roots_smul_nonzero p (neg_ne_zero.mpr one_ne_zero)] @[simp] theorem roots_C_mul_X_sub_C_of_IsUnit (b : R) (a : RΛ£) : (C (a : R) * X - C b).roots = {a⁻¹ * b} := by rw [← roots_C_mul _ (Units.ne_zero a⁻¹), mul_sub, ← mul_assoc, ← C_mul, ← C_mul, Units.inv_mul, C_1, one_mul] exact roots_X_sub_C (a⁻¹ * b) @[simp] theorem roots_C_mul_X_add_C_of_IsUnit (b : R) (a : RΛ£) : (C (a : R) * X + C b).roots = {-(a⁻¹ * b)} := by rw [← sub_neg_eq_add, ← C_neg, roots_C_mul_X_sub_C_of_IsUnit, mul_neg] theorem roots_list_prod (L : List R[X]) : (0 : R[X]) βˆ‰ L β†’ L.prod.roots = (L : Multiset R[X]).bind roots := List.recOn L (fun _ => roots_one) fun hd tl ih H => by rw [List.mem_cons, not_or] at H rw [List.prod_cons, roots_mul (mul_ne_zero (Ne.symm H.1) <| List.prod_ne_zero H.2), ← Multiset.cons_coe, Multiset.cons_bind, ih H.2] theorem roots_multiset_prod (m : Multiset R[X]) : (0 : R[X]) βˆ‰ m β†’ m.prod.roots = m.bind roots := by rcases m with ⟨L⟩ simpa only [Multiset.prod_coe, quot_mk_to_coe''] using roots_list_prod L theorem roots_prod {ΞΉ : Type*} (f : ΞΉ β†’ R[X]) (s : Finset ΞΉ) : s.prod f β‰  0 β†’ (s.prod f).roots = s.val.bind fun i => roots (f i) := by rcases s with ⟨m, hm⟩ simpa [Multiset.prod_eq_zero_iff, Multiset.bind_map] using roots_multiset_prod (m.map f) @[simp] theorem roots_pow (p : R[X]) (n : β„•) : (p ^ n).roots = n β€’ p.roots := by induction n with | zero => rw [pow_zero, roots_one, zero_smul, empty_eq_zero] | succ n ihn => rcases eq_or_ne p 0 with (rfl | hp) Β· rw [zero_pow n.succ_ne_zero, roots_zero, smul_zero] Β· rw [pow_succ, roots_mul (mul_ne_zero (pow_ne_zero _ hp) hp), ihn, add_smul, one_smul] theorem roots_X_pow (n : β„•) : (X ^ n : R[X]).roots = n β€’ ({0} : Multiset R) := by rw [roots_pow, roots_X] theorem roots_C_mul_X_pow (ha : a β‰  0) (n : β„•) : Polynomial.roots (C a * X ^ n) = n β€’ ({0} : Multiset R) := by rw [roots_C_mul _ ha, roots_X_pow] @[simp] theorem roots_monomial (ha : a β‰  0) (n : β„•) : (monomial n a).roots = n β€’ ({0} : Multiset R) := by rw [← C_mul_X_pow_eq_monomial, roots_C_mul_X_pow ha] theorem roots_prod_X_sub_C (s : Finset R) : (s.prod fun a => X - C a).roots = s.val := by apply (roots_prod (fun a => X - C a) s ?_).trans Β· simp_rw [roots_X_sub_C] rw [Multiset.bind_singleton, Multiset.map_id'] Β· refine prod_ne_zero_iff.mpr (fun a _ => X_sub_C_ne_zero a) @[simp] theorem roots_multiset_prod_X_sub_C (s : Multiset R) : (s.map fun a => X - C a).prod.roots = s := by rw [roots_multiset_prod, Multiset.bind_map] Β· simp_rw [roots_X_sub_C] rw [Multiset.bind_singleton, Multiset.map_id'] Β· rw [Multiset.mem_map] rintro ⟨a, -, h⟩ exact X_sub_C_ne_zero a h theorem card_roots_X_pow_sub_C {n : β„•} (hn : 0 < n) (a : R) : Multiset.card (roots ((X : R[X]) ^ n - C a)) ≀ n := WithBot.coe_le_coe.1 <| calc (Multiset.card (roots ((X : R[X]) ^ n - C a)) : WithBot β„•) ≀ degree ((X : R[X]) ^ n - C a) := card_roots (X_pow_sub_C_ne_zero hn a) _ = n := degree_X_pow_sub_C hn a section NthRoots /-- `nthRoots n a` noncomputably returns the solutions to `x ^ n = a`. -/ def nthRoots (n : β„•) (a : R) : Multiset R := roots ((X : R[X]) ^ n - C a) @[simp] theorem mem_nthRoots {n : β„•} (hn : 0 < n) {a x : R} : x ∈ nthRoots n a ↔ x ^ n = a := by rw [nthRoots, mem_roots (X_pow_sub_C_ne_zero hn a), IsRoot.def, eval_sub, eval_C, eval_pow, eval_X, sub_eq_zero] @[simp] theorem nthRoots_zero (r : R) : nthRoots 0 r = 0 := by simp only [empty_eq_zero, pow_zero, nthRoots, ← C_1, ← C_sub, roots_C] @[simp] theorem nthRoots_zero_right {R} [CommRing R] [IsDomain R] (n : β„•) : nthRoots n (0 : R) = Multiset.replicate n 0 := by rw [nthRoots, C.map_zero, sub_zero, roots_pow, roots_X, Multiset.nsmul_singleton] theorem card_nthRoots (n : β„•) (a : R) : Multiset.card (nthRoots n a) ≀ n := by classical exact (if hn : n = 0 then if h : (X : R[X]) ^ n - C a = 0 then by simp [Nat.zero_le, nthRoots, roots, h, dif_pos rfl, empty_eq_zero, Multiset.card_zero] else WithBot.coe_le_coe.1 (le_trans (card_roots h) (by rw [hn, pow_zero, ← C_1, ← RingHom.map_sub] exact degree_C_le)) else by rw [← Nat.cast_le (Ξ± := WithBot β„•)] rw [← degree_X_pow_sub_C (Nat.pos_of_ne_zero hn) a] exact card_roots (X_pow_sub_C_ne_zero (Nat.pos_of_ne_zero hn) a)) @[simp] theorem nthRoots_two_eq_zero_iff {r : R} : nthRoots 2 r = 0 ↔ Β¬IsSquare r := by simp_rw [isSquare_iff_exists_sq, eq_zero_iff_forall_not_mem, mem_nthRoots (by norm_num : 0 < 2), ← not_exists, eq_comm] /-- The multiset `nthRoots ↑n a` as a Finset. Previously `nthRootsFinset n` was defined to be `nthRoots n (1 : R)` as a Finset. That situation can be recovered by setting `a` to be `(1 : R)` -/ def nthRootsFinset (n : β„•) {R : Type*} (a : R) [CommRing R] [IsDomain R] : Finset R := haveI := Classical.decEq R Multiset.toFinset (nthRoots n a) lemma nthRootsFinset_def (n : β„•) {R : Type*} (a : R) [CommRing R] [IsDomain R] [DecidableEq R] : nthRootsFinset n a = Multiset.toFinset (nthRoots n a) := by unfold nthRootsFinset convert rfl @[simp] theorem mem_nthRootsFinset {n : β„•} (h : 0 < n) (a : R) {x : R} : x ∈ nthRootsFinset n a ↔ x ^ (n : β„•) = a := by classical rw [nthRootsFinset_def, mem_toFinset, mem_nthRoots h] @[simp] theorem nthRootsFinset_zero (a : R) : nthRootsFinset 0 a = βˆ… := by classical simp [nthRootsFinset_def] theorem map_mem_nthRootsFinset {S F : Type*} [CommRing S] [IsDomain S] [FunLike F R S] [MonoidHomClass F R S] {a : R} {x : R} (hx : x ∈ nthRootsFinset n a) (f : F) : f x ∈ nthRootsFinset n (f a) := by by_cases hn : n = 0 Β· simp [hn] at hx Β· rw [mem_nthRootsFinset <| Nat.pos_of_ne_zero hn, ← map_pow, (mem_nthRootsFinset (Nat.pos_of_ne_zero hn) a).1 hx] theorem map_mem_nthRootsFinset_one {S F : Type*} [CommRing S] [IsDomain S] [FunLike F R S] [RingHomClass F R S] {x : R} (hx : x ∈ nthRootsFinset n 1) (f : F) : f x ∈ nthRootsFinset n 1 := by rw [← (map_one f)] exact map_mem_nthRootsFinset hx _ theorem mul_mem_nthRootsFinset {η₁ Ξ·β‚‚ : R} {a₁ aβ‚‚ : R} (hη₁ : η₁ ∈ nthRootsFinset n a₁) (hΞ·β‚‚ : Ξ·β‚‚ ∈ nthRootsFinset n aβ‚‚) : η₁ * Ξ·β‚‚ ∈ nthRootsFinset n (a₁ * aβ‚‚) := by cases n with | zero => simp only [nthRootsFinset_zero, not_mem_empty] at hη₁ | succ n => rw [mem_nthRootsFinset n.succ_pos] at hη₁ hΞ·β‚‚ ⊒ rw [mul_pow, hη₁, hΞ·β‚‚] theorem ne_zero_of_mem_nthRootsFinset {Ξ· : R} {a : R} (ha : a β‰  0) (hΞ· : Ξ· ∈ nthRootsFinset n a) : Ξ· β‰  0 := by nontriviality R rintro rfl cases n with | zero => simp only [nthRootsFinset_zero, not_mem_empty] at hΞ· | succ n => rw [mem_nthRootsFinset n.succ_pos, zero_pow n.succ_ne_zero] at hΞ· exact ha hΞ·.symm theorem one_mem_nthRootsFinset (hn : 0 < n) : 1 ∈ nthRootsFinset n (1 : R) := by rw [mem_nthRootsFinset hn, one_pow] end NthRoots theorem zero_of_eval_zero [Infinite R] (p : R[X]) (h : βˆ€ x, p.eval x = 0) : p = 0 := by classical by_contra hp refine @Fintype.false R _ ?_ exact ⟨p.roots.toFinset, fun x => Multiset.mem_toFinset.mpr ((mem_roots hp).mpr (h _))⟩ theorem funext [Infinite R] {p q : R[X]} (ext : βˆ€ r : R, p.eval r = q.eval r) : p = q := by rw [← sub_eq_zero] apply zero_of_eval_zero intro x rw [eval_sub, sub_eq_zero, ext] variable [CommRing T] /-- Given a polynomial `p` with coefficients in a ring `T` and a `T`-algebra `S`, `aroots p S` is the multiset of roots of `p` regarded as a polynomial over `S`. -/ noncomputable abbrev aroots (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : Multiset S := (p.map (algebraMap T S)).roots theorem aroots_def (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : p.aroots S = (p.map (algebraMap T S)).roots := rfl theorem mem_aroots' [CommRing S] [IsDomain S] [Algebra T S] {p : T[X]} {a : S} : a ∈ p.aroots S ↔ p.map (algebraMap T S) β‰  0 ∧ aeval a p = 0 := by rw [mem_roots', IsRoot.def, ← evalβ‚‚_eq_eval_map, aeval_def] theorem mem_aroots [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {p : T[X]} {a : S} : a ∈ p.aroots S ↔ p β‰  0 ∧ aeval a p = 0 := by rw [mem_aroots', Polynomial.map_ne_zero_iff] exact FaithfulSMul.algebraMap_injective T S theorem aroots_mul [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {p q : T[X]} (hpq : p * q β‰  0) : (p * q).aroots S = p.aroots S + q.aroots S := by suffices map (algebraMap T S) p * map (algebraMap T S) q β‰  0 by rw [aroots_def, Polynomial.map_mul, roots_mul this] rwa [← Polynomial.map_mul, Polynomial.map_ne_zero_iff (FaithfulSMul.algebraMap_injective T S)] @[simp] theorem aroots_X_sub_C [CommRing S] [IsDomain S] [Algebra T S] (r : T) : aroots (X - C r) S = {algebraMap T S r} := by rw [aroots_def, Polynomial.map_sub, map_X, map_C, roots_X_sub_C] @[simp] theorem aroots_X [CommRing S] [IsDomain S] [Algebra T S] : aroots (X : T[X]) S = {0} := by rw [aroots_def, map_X, roots_X] @[simp] theorem aroots_C [CommRing S] [IsDomain S] [Algebra T S] (a : T) : (C a).aroots S = 0 := by rw [aroots_def, map_C, roots_C] @[simp] theorem aroots_zero (S) [CommRing S] [IsDomain S] [Algebra T S] : (0 : T[X]).aroots S = 0 := by rw [← C_0, aroots_C] @[simp] theorem aroots_one [CommRing S] [IsDomain S] [Algebra T S] : (1 : T[X]).aroots S = 0 := aroots_C 1 @[simp] theorem aroots_neg [CommRing S] [IsDomain S] [Algebra T S] (p : T[X]) : (-p).aroots S = p.aroots S := by rw [aroots, Polynomial.map_neg, roots_neg] @[simp] theorem aroots_C_mul [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {a : T} (p : T[X]) (ha : a β‰  0) : (C a * p).aroots S = p.aroots S := by rw [aroots_def, Polynomial.map_mul, map_C, roots_C_mul] rwa [map_ne_zero_iff] exact FaithfulSMul.algebraMap_injective T S @[simp] theorem aroots_smul_nonzero [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {a : T} (p : T[X]) (ha : a β‰  0) : (a β€’ p).aroots S = p.aroots S := by rw [smul_eq_C_mul, aroots_C_mul _ ha] @[simp] theorem aroots_pow [CommRing S] [IsDomain S] [Algebra T S] (p : T[X]) (n : β„•) : (p ^ n).aroots S = n β€’ p.aroots S := by rw [aroots_def, Polynomial.map_pow, roots_pow] theorem aroots_X_pow [CommRing S] [IsDomain S] [Algebra T S] (n : β„•) : (X ^ n : T[X]).aroots S = n β€’ ({0} : Multiset S) := by rw [aroots_pow, aroots_X] theorem aroots_C_mul_X_pow [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {a : T} (ha : a β‰  0) (n : β„•) : (C a * X ^ n : T[X]).aroots S = n β€’ ({0} : Multiset S) := by rw [aroots_C_mul _ ha, aroots_X_pow] @[simp] theorem aroots_monomial [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {a : T} (ha : a β‰  0) (n : β„•) : (monomial n a).aroots S = n β€’ ({0} : Multiset S) := by rw [← C_mul_X_pow_eq_monomial, aroots_C_mul_X_pow ha] variable (R S) in @[simp] theorem aroots_map (p : T[X]) [CommRing S] [Algebra T S] [Algebra S R] [Algebra T R] [IsScalarTower T S R] : (p.map (algebraMap T S)).aroots R = p.aroots R := by rw [aroots_def, aroots_def, map_map, IsScalarTower.algebraMap_eq T S R] /-- The set of distinct roots of `p` in `S`. If you have a non-separable polynomial, use `Polynomial.aroots` for the multiset where multiple roots have the appropriate multiplicity. -/ def rootSet (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : Set S := haveI := Classical.decEq S (p.aroots S).toFinset theorem rootSet_def (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] [DecidableEq S] : p.rootSet S = (p.aroots S).toFinset := by rw [rootSet] convert rfl @[simp] theorem rootSet_C [CommRing S] [IsDomain S] [Algebra T S] (a : T) : (C a).rootSet S = βˆ… := by classical rw [rootSet_def, aroots_C, Multiset.toFinset_zero, Finset.coe_empty] @[simp] theorem rootSet_zero (S) [CommRing S] [IsDomain S] [Algebra T S] : (0 : T[X]).rootSet S = βˆ… := by rw [← C_0, rootSet_C] @[simp] theorem rootSet_one (S) [CommRing S] [IsDomain S] [Algebra T S] : (1 : T[X]).rootSet S = βˆ… := by rw [← C_1, rootSet_C] @[simp] theorem rootSet_neg (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : (-p).rootSet S = p.rootSet S := by rw [rootSet, aroots_neg, rootSet] instance rootSetFintype (p : T[X]) (S : Type*) [CommRing S] [IsDomain S] [Algebra T S] : Fintype (p.rootSet S) := FinsetCoe.fintype _ theorem rootSet_finite (p : T[X]) (S : Type*) [CommRing S] [IsDomain S] [Algebra T S] : (p.rootSet S).Finite := Set.toFinite _ /-- The set of roots of all polynomials of bounded degree and having coefficients in a finite set is finite. -/ theorem bUnion_roots_finite {R S : Type*} [Semiring R] [CommRing S] [IsDomain S] [DecidableEq S] (m : R β†’+* S) (d : β„•) {U : Set R} (h : U.Finite) : (⋃ (f : R[X]) (_ : f.natDegree ≀ d ∧ βˆ€ i, f.coeff i ∈ U), ((f.map m).roots.toFinset.toSet : Set S)).Finite := Set.Finite.biUnion (by -- We prove that the set of polynomials under consideration is finite because its -- image by the injective map `Ο€` is finite let Ο€ : R[X] β†’ Fin (d + 1) β†’ R := fun f i => f.coeff i refine ((Set.Finite.pi fun _ => h).subset <| ?_).of_finite_image (?_ : Set.InjOn Ο€ _) Β· exact Set.image_subset_iff.2 fun f hf i _ => hf.2 i Β· refine fun x hx y hy hxy => (ext_iff_natDegree_le hx.1 hy.1).2 fun i hi => ?_ exact id congr_fun hxy ⟨i, Nat.lt_succ_of_le hi⟩) fun _ _ => Finset.finite_toSet _ theorem mem_rootSet' {p : T[X]} {S : Type*} [CommRing S] [IsDomain S] [Algebra T S] {a : S} : a ∈ p.rootSet S ↔ p.map (algebraMap T S) β‰  0 ∧ aeval a p = 0 := by classical rw [rootSet_def, Finset.mem_coe, mem_toFinset, mem_aroots'] theorem mem_rootSet {p : T[X]} {S : Type*} [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {a : S} : a ∈ p.rootSet S ↔ p β‰  0 ∧ aeval a p = 0 := by rw [mem_rootSet', Polynomial.map_ne_zero_iff (FaithfulSMul.algebraMap_injective T S)] theorem mem_rootSet_of_ne {p : T[X]} {S : Type*} [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] (hp : p β‰  0) {a : S} : a ∈ p.rootSet S ↔ aeval a p = 0 := mem_rootSet.trans <| and_iff_right hp theorem rootSet_maps_to' {p : T[X]} {S S'} [CommRing S] [IsDomain S] [Algebra T S] [CommRing S'] [IsDomain S'] [Algebra T S'] (hp : p.map (algebraMap T S') = 0 β†’ p.map (algebraMap T S) = 0) (f : S →ₐ[T] S') : (p.rootSet S).MapsTo f (p.rootSet S') := fun x hx => by rw [mem_rootSet'] at hx ⊒ rw [aeval_algHom, AlgHom.comp_apply, hx.2, _root_.map_zero] exact ⟨mt hp hx.1, rfl⟩ theorem ne_zero_of_mem_rootSet {p : T[X]} [CommRing S] [IsDomain S] [Algebra T S] {a : S} (h : a ∈ p.rootSet S) : p β‰  0 := fun hf => by rwa [hf, rootSet_zero] at h theorem aeval_eq_zero_of_mem_rootSet {p : T[X]} [CommRing S] [IsDomain S] [Algebra T S] {a : S} (hx : a ∈ p.rootSet S) : aeval a p = 0 := (mem_rootSet'.1 hx).2 theorem rootSet_mapsTo {p : T[X]} {S S'} [CommRing S] [IsDomain S] [Algebra T S] [CommRing S'] [IsDomain S'] [Algebra T S'] [NoZeroSMulDivisors T S'] (f : S →ₐ[T] S') : (p.rootSet S).MapsTo f (p.rootSet S') := by refine rootSet_maps_to' (fun hβ‚€ => ?_) f obtain rfl : p = 0 := map_injective _ (FaithfulSMul.algebraMap_injective T S') (by rwa [Polynomial.map_zero]) exact Polynomial.map_zero _ theorem mem_rootSet_of_injective [CommRing S] {p : S[X]} [Algebra S R] (h : Function.Injective (algebraMap S R)) {x : R} (hp : p β‰  0) : x ∈ p.rootSet R ↔ aeval x p = 0 := by classical exact Multiset.mem_toFinset.trans (mem_roots_map_of_injective h hp) end Roots lemma eq_zero_of_natDegree_lt_card_of_eval_eq_zero {R} [CommRing R] [IsDomain R] (p : R[X]) {ΞΉ} [Fintype ΞΉ] {f : ΞΉ β†’ R} (hf : Function.Injective f) (heval : βˆ€ i, p.eval (f i) = 0) (hcard : natDegree p < Fintype.card ΞΉ) : p = 0 := by classical by_contra hp refine lt_irrefl #p.roots.toFinset ?_ calc #p.roots.toFinset ≀ Multiset.card p.roots := Multiset.toFinset_card_le _ _ ≀ natDegree p := Polynomial.card_roots' p _ < Fintype.card ΞΉ := hcard _ = Fintype.card (Set.range f) := (Set.card_range_of_injective hf).symm _ = #(Finset.univ.image f) := by rw [← Set.toFinset_card, Set.toFinset_range] _ ≀ #p.roots.toFinset := Finset.card_mono ?_ intro _ simp only [Finset.mem_image, Finset.mem_univ, true_and, Multiset.mem_toFinset, mem_roots', ne_eq, IsRoot.def, forall_exists_index, hp, not_false_eq_true] rintro x rfl exact heval _ lemma eq_zero_of_natDegree_lt_card_of_eval_eq_zero' {R} [CommRing R] [IsDomain R] (p : R[X]) (s : Finset R) (heval : βˆ€ i ∈ s, p.eval i = 0) (hcard : natDegree p < #s) : p = 0 := eq_zero_of_natDegree_lt_card_of_eval_eq_zero p Subtype.val_injective (fun i : s ↦ heval i i.prop) (hcard.trans_eq (Fintype.card_coe s).symm) open Cardinal in lemma eq_zero_of_forall_eval_zero_of_natDegree_lt_card (f : R[X]) (hf : βˆ€ r, f.eval r = 0) (hfR : f.natDegree < #R) : f = 0 := by obtain hR|hR := finite_or_infinite R Β· have := Fintype.ofFinite R apply eq_zero_of_natDegree_lt_card_of_eval_eq_zero f Function.injective_id hf simpa only [mk_fintype, Nat.cast_lt] using hfR Β· exact zero_of_eval_zero _ hf open Cardinal in lemma exists_eval_ne_zero_of_natDegree_lt_card (f : R[X]) (hf : f β‰  0) (hfR : f.natDegree < #R) : βˆƒ r, f.eval r β‰  0 := by contrapose! hf exact eq_zero_of_forall_eval_zero_of_natDegree_lt_card f hf hfR section omit [IsDomain R] theorem monic_multisetProd_X_sub_C (s : Multiset R) : Monic (s.map fun a => X - C a).prod := monic_multiset_prod_of_monic _ _ fun a _ => monic_X_sub_C a theorem monic_prod_X_sub_C {Ξ± : Type*} (b : Ξ± β†’ R) (s : Finset Ξ±) : Monic (∏ a ∈ s, (X - C (b a))) := monic_prod_of_monic _ _ fun a _ => monic_X_sub_C (b a) theorem monic_finprod_X_sub_C {Ξ± : Type*} (b : Ξ± β†’ R) : Monic (∏ᢠ k, (X - C (b k))) := monic_finprod_of_monic _ _ fun a _ => monic_X_sub_C (b a) end theorem prod_multiset_root_eq_finset_root [DecidableEq R] : (p.roots.map fun a => X - C a).prod = p.roots.toFinset.prod fun a => (X - C a) ^ rootMultiplicity a p := by simp only [count_roots, Finset.prod_multiset_map_count] /-- The product `∏ (X - a)` for `a` inside the multiset `p.roots` divides `p`. -/ theorem prod_multiset_X_sub_C_dvd (p : R[X]) : (p.roots.map fun a => X - C a).prod ∣ p := by classical rw [← map_dvd_map _ (IsFractionRing.injective R <| FractionRing R) (monic_multisetProd_X_sub_C p.roots)] rw [prod_multiset_root_eq_finset_root, Polynomial.map_prod] refine Finset.prod_dvd_of_coprime (fun a _ b _ h => ?_) fun a _ => ?_ Β· simp_rw [Polynomial.map_pow, Polynomial.map_sub, map_C, map_X] exact (pairwise_coprime_X_sub_C (IsFractionRing.injective R <| FractionRing R) h).pow Β· exact Polynomial.map_dvd _ (pow_rootMultiplicity_dvd p a) /-- A Galois connection. -/ theorem _root_.Multiset.prod_X_sub_C_dvd_iff_le_roots {p : R[X]} (hp : p β‰  0) (s : Multiset R) : (s.map fun a => X - C a).prod ∣ p ↔ s ≀ p.roots := by classical exact ⟨fun h => Multiset.le_iff_count.2 fun r => by rw [count_roots, le_rootMultiplicity_iff hp, ← Multiset.prod_replicate, ← Multiset.map_replicate fun a => X - C a, ← Multiset.filter_eq] exact (Multiset.prod_dvd_prod_of_le <| Multiset.map_le_map <| s.filter_le _).trans h, fun h => (Multiset.prod_dvd_prod_of_le <| Multiset.map_le_map h).trans p.prod_multiset_X_sub_C_dvd⟩ theorem exists_prod_multiset_X_sub_C_mul (p : R[X]) : βˆƒ q, (p.roots.map fun a => X - C a).prod * q = p ∧ Multiset.card p.roots + q.natDegree = p.natDegree ∧ q.roots = 0 := by obtain ⟨q, he⟩ := p.prod_multiset_X_sub_C_dvd use q, he.symm obtain rfl | hq := eq_or_ne q 0 Β· rw [mul_zero] at he subst he simp constructor Β· conv_rhs => rw [he] rw [(monic_multisetProd_X_sub_C p.roots).natDegree_mul' hq, natDegree_multiset_prod_X_sub_C_eq_card] Β· replace he := congr_arg roots he.symm rw [roots_mul, roots_multiset_prod_X_sub_C] at he exacts [add_eq_left.1 he, mul_ne_zero (monic_multisetProd_X_sub_C p.roots).ne_zero hq] /-- A polynomial `p` that has as many roots as its degree can be written `p = p.leadingCoeff * ∏(X - a)`, for `a` in `p.roots`. -/ theorem C_leadingCoeff_mul_prod_multiset_X_sub_C (hroots : Multiset.card p.roots = p.natDegree) : C p.leadingCoeff * (p.roots.map fun a => X - C a).prod = p := (eq_leadingCoeff_mul_of_monic_of_dvd_of_natDegree_le (monic_multisetProd_X_sub_C p.roots) p.prod_multiset_X_sub_C_dvd ((natDegree_multiset_prod_X_sub_C_eq_card _).trans hroots).ge).symm /-- A monic polynomial `p` that has as many roots as its degree can be written `p = ∏(X - a)`, for `a` in `p.roots`. -/ theorem prod_multiset_X_sub_C_of_monic_of_roots_card_eq (hp : p.Monic) (hroots : Multiset.card p.roots = p.natDegree) : (p.roots.map fun a => X - C a).prod = p := by convert C_leadingCoeff_mul_prod_multiset_X_sub_C hroots rw [hp.leadingCoeff, C_1, one_mul] theorem Monic.isUnit_leadingCoeff_of_dvd {a p : R[X]} (hp : Monic p) (hap : a ∣ p) : IsUnit a.leadingCoeff := isUnit_of_dvd_one (by simpa only [hp.leadingCoeff] using leadingCoeff_dvd_leadingCoeff hap) /-- To check a monic polynomial is irreducible, it suffices to check only for divisors that have smaller degree. See also: `Polynomial.Monic.irreducible_iff_natDegree`. -/ theorem Monic.irreducible_iff_degree_lt {p : R[X]} (p_monic : Monic p) (p_1 : p β‰  1) : Irreducible p ↔ βˆ€ q, degree q ≀ ↑(p.natDegree / 2) β†’ q ∣ p β†’ IsUnit q := by simp only [p_monic.irreducible_iff_lt_natDegree_lt p_1, Finset.mem_Ioc, and_imp, natDegree_pos_iff_degree_pos, natDegree_le_iff_degree_le] constructor Β· rintro h q deg_le dvd by_contra q_unit have := degree_pos_of_not_isUnit_of_dvd_monic p_monic q_unit dvd have hu := p_monic.isUnit_leadingCoeff_of_dvd dvd refine (h _ (monic_of_isUnit_leadingCoeff_inv_smul hu) ?_ ?_ (dvd_trans ?_ dvd)).elim Β· rwa [degree_smul_of_smul_regular _ (isSMulRegular_of_group _)] Β· rwa [degree_smul_of_smul_regular _ (isSMulRegular_of_group _)] Β· rw [Units.smul_def, Polynomial.smul_eq_C_mul, (isUnit_C.mpr (Units.isUnit _)).mul_left_dvd] Β· rintro h q _ deg_pos deg_le dvd exact deg_pos.ne' <| degree_eq_zero_of_isUnit (h q deg_le dvd) end CommRing section variable {A B : Type*} [CommRing A] [CommRing B] theorem le_rootMultiplicity_map {p : A[X]} {f : A β†’+* B} (hmap : map f p β‰  0) (a : A) : rootMultiplicity a p ≀ rootMultiplicity (f a) (p.map f) := by rw [le_rootMultiplicity_iff hmap] refine _root_.trans ?_ ((mapRingHom f).map_dvd (pow_rootMultiplicity_dvd p a)) rw [map_pow, map_sub, coe_mapRingHom, map_X, map_C] theorem eq_rootMultiplicity_map {p : A[X]} {f : A β†’+* B} (hf : Function.Injective f) (a : A) : rootMultiplicity a p = rootMultiplicity (f a) (p.map f) := by by_cases hp0 : p = 0; Β· simp only [hp0, rootMultiplicity_zero, Polynomial.map_zero] apply le_antisymm (le_rootMultiplicity_map ((Polynomial.map_ne_zero_iff hf).mpr hp0) a) rw [le_rootMultiplicity_iff hp0, ← map_dvd_map f hf ((monic_X_sub_C a).pow _), Polynomial.map_pow, Polynomial.map_sub, map_X, map_C] apply pow_rootMultiplicity_dvd theorem count_map_roots [IsDomain A] [DecidableEq B] {p : A[X]} {f : A β†’+* B} (hmap : map f p β‰  0) (b : B) : (p.roots.map f).count b ≀ rootMultiplicity b (p.map f) := by rw [le_rootMultiplicity_iff hmap, ← Multiset.prod_replicate, ← Multiset.map_replicate fun a => X - C a] rw [← Multiset.filter_eq] refine (Multiset.prod_dvd_prod_of_le <| Multiset.map_le_map <| Multiset.filter_le (Eq b) _).trans ?_ convert Polynomial.map_dvd f p.prod_multiset_X_sub_C_dvd simp only [Polynomial.map_multiset_prod, Multiset.map_map] congr; ext1 simp only [Function.comp_apply, Polynomial.map_sub, map_X, map_C] theorem count_map_roots_of_injective [IsDomain A] [DecidableEq B] (p : A[X]) {f : A β†’+* B} (hf : Function.Injective f) (b : B) : (p.roots.map f).count b ≀ rootMultiplicity b (p.map f) := by by_cases hp0 : p = 0 Β· simp only [hp0, roots_zero, Multiset.map_zero, Multiset.count_zero, Polynomial.map_zero, rootMultiplicity_zero, le_refl] Β· exact count_map_roots ((Polynomial.map_ne_zero_iff hf).mpr hp0) b theorem map_roots_le [IsDomain A] [IsDomain B] {p : A[X]} {f : A β†’+* B} (h : p.map f β‰  0) : p.roots.map f ≀ (p.map f).roots := by classical exact Multiset.le_iff_count.2 fun b => by
rw [count_roots] apply count_map_roots h theorem map_roots_le_of_injective [IsDomain A] [IsDomain B] (p : A[X]) {f : A β†’+* B} (hf : Function.Injective f) : p.roots.map f ≀ (p.map f).roots := by by_cases hp0 : p = 0 Β· simp only [hp0, roots_zero, Multiset.map_zero, Polynomial.map_zero, le_rfl] exact map_roots_le ((Polynomial.map_ne_zero_iff hf).mpr hp0) theorem card_roots_le_map [IsDomain A] [IsDomain B] {p : A[X]} {f : A β†’+* B} (h : p.map f β‰  0) : Multiset.card p.roots ≀ Multiset.card (p.map f).roots := by rw [← p.roots.card_map f]
Mathlib/Algebra/Polynomial/Roots.lean
768
779
/- Copyright (c) 2024 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.NumberTheory.LSeries.AbstractFuncEq import Mathlib.NumberTheory.ModularForms.JacobiTheta.Bounds import Mathlib.Analysis.SpecialFunctions.Gamma.Deligne import Mathlib.NumberTheory.LSeries.MellinEqDirichlet import Mathlib.NumberTheory.LSeries.Basic import Mathlib.Analysis.Complex.RemovableSingularity /-! # Even Hurwitz zeta functions In this file we study the functions on `β„‚` which are the meromorphic continuation of the following series (convergent for `1 < re s`), where `a ∈ ℝ` is a parameter: `hurwitzZetaEven a s = 1 / 2 * βˆ‘' n : β„€, 1 / |n + a| ^ s` and `cosZeta a s = βˆ‘' n : β„•, cos (2 * Ο€ * a * n) / |n| ^ s`. Note that the term for `n = -a` in the first sum is omitted if `a` is an integer, and the term for `n = 0` is omitted in the second sum (always). Of course, we cannot *define* these functions by the above formulae (since existence of the meromorphic continuation is not at all obvious); we in fact construct them as Mellin transforms of various versions of the Jacobi theta function. We also define completed versions of these functions with nicer functional equations (satisfying `completedHurwitzZetaEven a s = Gammaℝ s * hurwitzZetaEven a s`, and similarly for `cosZeta`); and modified versions with a subscript `0`, which are entire functions differing from the above by multiples of `1 / s` and `1 / (1 - s)`. ## Main definitions and theorems * `hurwitzZetaEven` and `cosZeta`: the zeta functions * `completedHurwitzZetaEven` and `completedCosZeta`: completed variants * `differentiableAt_hurwitzZetaEven` and `differentiableAt_cosZeta`: differentiability away from `s = 1` * `completedHurwitzZetaEven_one_sub`: the functional equation `completedHurwitzZetaEven a (1 - s) = completedCosZeta a s` * `hasSum_int_hurwitzZetaEven` and `hasSum_nat_cosZeta`: relation between the zeta functions and the corresponding Dirichlet series for `1 < re s`. -/ noncomputable section open Complex Filter Topology Asymptotics Real Set MeasureTheory namespace HurwitzZeta section kernel_defs /-! ## Definitions and elementary properties of kernels -/ /-- Even Hurwitz zeta kernel (function whose Mellin transform will be the even part of the completed Hurwit zeta function). See `evenKernel_def` for the defining formula, and `hasSum_int_evenKernel` for an expression as a sum over `β„€`. -/ @[irreducible] def evenKernel (a : UnitAddCircle) (x : ℝ) : ℝ := (show Function.Periodic (fun ΞΎ : ℝ ↦ rexp (-Ο€ * ΞΎ ^ 2 * x) * re (jacobiThetaβ‚‚ (ΞΎ * I * x) (I * x))) 1 by intro ΞΎ simp only [ofReal_add, ofReal_one, add_mul, one_mul, jacobiThetaβ‚‚_add_left'] have : cexp (-↑π * I * ((I * ↑x) + 2 * (↑ξ * I * ↑x))) = rexp (Ο€ * (x + 2 * ΞΎ * x)) := by ring_nf simp [I_sq] rw [this, re_ofReal_mul, ← mul_assoc, ← Real.exp_add] congr ring).lift a lemma evenKernel_def (a x : ℝ) : ↑(evenKernel ↑a x) = cexp (-Ο€ * a ^ 2 * x) * jacobiThetaβ‚‚ (a * I * x) (I * x) := by simp [evenKernel, re_eq_add_conj, jacobiThetaβ‚‚_conj, ← mul_two, mul_div_cancel_rightβ‚€ _ (two_ne_zero' β„‚)] /-- For `x ≀ 0` the defining sum diverges, so the kernel is 0. -/ lemma evenKernel_undef (a : UnitAddCircle) {x : ℝ} (hx : x ≀ 0) : evenKernel a x = 0 := by induction a using QuotientAddGroup.induction_on with | H a' => simp [← ofReal_inj, evenKernel_def, jacobiThetaβ‚‚_undef _ (by simpa : (I * ↑x).im ≀ 0)] /-- Cosine Hurwitz zeta kernel. See `cosKernel_def` for the defining formula, and `hasSum_int_cosKernel` for expression as a sum. -/ @[irreducible] def cosKernel (a : UnitAddCircle) (x : ℝ) : ℝ := (show Function.Periodic (fun ΞΎ : ℝ ↦ re (jacobiThetaβ‚‚ ΞΎ (I * x))) 1 by intro ΞΎ; simp [jacobiThetaβ‚‚_add_left]).lift a lemma cosKernel_def (a x : ℝ) : ↑(cosKernel ↑a x) = jacobiThetaβ‚‚ a (I * x) := by simp [cosKernel, re_eq_add_conj, jacobiThetaβ‚‚_conj, ← mul_two, mul_div_cancel_rightβ‚€ _ (two_ne_zero' β„‚)] lemma cosKernel_undef (a : UnitAddCircle) {x : ℝ} (hx : x ≀ 0) : cosKernel a x = 0 := by induction a using QuotientAddGroup.induction_on with | H => simp [← ofReal_inj, cosKernel_def, jacobiThetaβ‚‚_undef _ (by simpa : (I * ↑x).im ≀ 0)] /-- For `a = 0`, both kernels agree. -/ lemma evenKernel_eq_cosKernel_of_zero : evenKernel 0 = cosKernel 0 := by ext1 x simp [← QuotientAddGroup.mk_zero, ← ofReal_inj, evenKernel_def, cosKernel_def] @[simp] lemma evenKernel_neg (a : UnitAddCircle) (x : ℝ) : evenKernel (-a) x = evenKernel a x := by induction a using QuotientAddGroup.induction_on with | H => simp [← QuotientAddGroup.mk_neg, ← ofReal_inj, evenKernel_def, jacobiThetaβ‚‚_neg_left] @[simp] lemma cosKernel_neg (a : UnitAddCircle) (x : ℝ) : cosKernel (-a) x = cosKernel a x := by induction a using QuotientAddGroup.induction_on with | H => simp [← QuotientAddGroup.mk_neg, ← ofReal_inj, cosKernel_def] lemma continuousOn_evenKernel (a : UnitAddCircle) : ContinuousOn (evenKernel a) (Ioi 0) := by induction a using QuotientAddGroup.induction_on with | H a' => apply continuous_re.comp_continuousOn (f := fun x ↦ (evenKernel a' x : β„‚)) simp only [evenKernel_def] refine continuousOn_of_forall_continuousAt (fun x hx ↦ .mul (by fun_prop) ?_) exact (continuousAt_jacobiThetaβ‚‚ (a' * I * x) <| by simpa).comp (f := fun u : ℝ ↦ (a' * I * u, I * u)) (by fun_prop) lemma continuousOn_cosKernel (a : UnitAddCircle) : ContinuousOn (cosKernel a) (Ioi 0) := by induction a using QuotientAddGroup.induction_on with | H a' => apply continuous_re.comp_continuousOn (f := fun x ↦ (cosKernel a' x : β„‚)) simp only [cosKernel_def] refine continuousOn_of_forall_continuousAt (fun x hx ↦ ?_) exact (continuousAt_jacobiThetaβ‚‚ a' <| by simpa).comp (f := fun u : ℝ ↦ ((a' : β„‚), I * u)) (by fun_prop) lemma evenKernel_functional_equation (a : UnitAddCircle) (x : ℝ) : evenKernel a x = 1 / x ^ (1 / 2 : ℝ) * cosKernel a (1 / x) := by rcases le_or_lt x 0 with hx | hx Β· rw [evenKernel_undef _ hx, cosKernel_undef, mul_zero] exact div_nonpos_of_nonneg_of_nonpos zero_le_one hx induction a using QuotientAddGroup.induction_on with | H a => rw [← ofReal_inj, ofReal_mul, evenKernel_def, cosKernel_def, jacobiThetaβ‚‚_functional_equation] have h1 : I * ↑(1 / x) = -1 / (I * x) := by push_cast rw [← div_div, mul_one_div, div_I, neg_one_mul, neg_neg] have hx' : I * x β‰  0 := mul_ne_zero I_ne_zero (ofReal_ne_zero.mpr hx.ne') have h2 : a * I * x / (I * x) = a := by rw [div_eq_iff hx'] ring have h3 : 1 / (-I * (I * x)) ^ (1 / 2 : β„‚) = 1 / ↑(x ^ (1 / 2 : ℝ)) := by rw [neg_mul, ← mul_assoc, I_mul_I, neg_one_mul, neg_neg,ofReal_cpow hx.le, ofReal_div, ofReal_one, ofReal_ofNat] have h4 : -Ο€ * I * (a * I * x) ^ 2 / (I * x) = - (-Ο€ * a ^ 2 * x) := by rw [mul_pow, mul_pow, I_sq, div_eq_iff hx'] ring rw [h1, h2, h3, h4, ← mul_assoc, mul_comm (cexp _), mul_assoc _ (cexp _) (cexp _), ← Complex.exp_add, neg_add_cancel, Complex.exp_zero, mul_one, ofReal_div, ofReal_one] end kernel_defs section asymp /-! ## Formulae for the kernels as sums -/ lemma hasSum_int_evenKernel (a : ℝ) {t : ℝ} (ht : 0 < t) : HasSum (fun n : β„€ ↦ rexp (-Ο€ * (n + a) ^ 2 * t)) (evenKernel a t) := by rw [← hasSum_ofReal, evenKernel_def] have (n : β„€) : cexp (-(Ο€ * (n + a) ^ 2 * t)) = cexp (-(Ο€ * a ^ 2 * t)) * jacobiThetaβ‚‚_term n (a * I * t) (I * t) := by rw [jacobiThetaβ‚‚_term, ← Complex.exp_add] ring_nf simp simpa [this] using (hasSum_jacobiThetaβ‚‚_term _ (by simpa)).mul_left _ lemma hasSum_int_cosKernel (a : ℝ) {t : ℝ} (ht : 0 < t) : HasSum (fun n : β„€ ↦ cexp (2 * Ο€ * I * a * n) * rexp (-Ο€ * n ^ 2 * t)) ↑(cosKernel a t) := by rw [cosKernel_def a t] have (n : β„€) : cexp (2 * Ο€ * I * a * n) * cexp (-(Ο€ * n ^ 2 * t)) = jacobiThetaβ‚‚_term n a (I * ↑t) := by rw [jacobiThetaβ‚‚_term, ← Complex.exp_add] ring_nf simp [sub_eq_add_neg] simpa [this] using hasSum_jacobiThetaβ‚‚_term _ (by simpa) /-- Modified version of `hasSum_int_evenKernel` omitting the constant term at `∞`. -/ lemma hasSum_int_evenKernelβ‚€ (a : ℝ) {t : ℝ} (ht : 0 < t) : HasSum (fun n : β„€ ↦ if n + a = 0 then 0 else rexp (-Ο€ * (n + a) ^ 2 * t)) (evenKernel a t - if (a : UnitAddCircle) = 0 then 1 else 0) := by haveI := Classical.propDecidable -- speed up instance search for `if / then / else` simp_rw [AddCircle.coe_eq_zero_iff, zsmul_one] split_ifs with h Β· obtain ⟨k, rfl⟩ := h simpa [← Int.cast_add, add_eq_zero_iff_eq_neg] using hasSum_ite_sub_hasSum (hasSum_int_evenKernel (k : ℝ) ht) (-k) Β· suffices βˆ€ (n : β„€), n + a β‰  0 by simpa [this] using hasSum_int_evenKernel a ht contrapose! h let ⟨n, hn⟩ := h
exact ⟨-n, by simpa [neg_eq_iff_add_eq_zero]⟩ lemma hasSum_int_cosKernelβ‚€ (a : ℝ) {t : ℝ} (ht : 0 < t) : HasSum (fun n : β„€ ↦ if n = 0 then 0 else cexp (2 * Ο€ * I * a * n) * rexp (-Ο€ * n ^ 2 * t)) (↑(cosKernel a t) - 1) := by simpa using hasSum_ite_sub_hasSum (hasSum_int_cosKernel a ht) 0 lemma hasSum_nat_cosKernelβ‚€ (a : ℝ) {t : ℝ} (ht : 0 < t) : HasSum (fun n : β„• ↦ 2 * Real.cos (2 * Ο€ * a * (n + 1)) * rexp (-Ο€ * (n + 1) ^ 2 * t)) (cosKernel a t - 1) := by rw [← hasSum_ofReal, ofReal_sub, ofReal_one] have := (hasSum_int_cosKernel a ht).nat_add_neg rw [← hasSum_nat_add_iff' 1] at this simp_rw [Finset.sum_range_one, Nat.cast_zero, neg_zero, Int.cast_zero, zero_pow two_ne_zero, mul_zero, zero_mul, Complex.exp_zero, Real.exp_zero, ofReal_one, mul_one, Int.cast_neg, Int.cast_natCast, neg_sq, ← add_mul, add_sub_assoc, ← sub_sub, sub_self, zero_sub,
Mathlib/NumberTheory/LSeries/HurwitzZetaEven.lean
192
207
/- Copyright (c) 2014 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Leonardo de Moura, Mario Carneiro, Floris van Doorn -/ import Mathlib.Algebra.Field.Basic import Mathlib.Algebra.GroupWithZero.Units.Lemmas import Mathlib.Algebra.Order.Ring.Abs import Mathlib.Order.Bounds.Basic import Mathlib.Order.Bounds.OrderIso import Mathlib.Tactic.Positivity.Core /-! # Lemmas about linear ordered (semi)fields -/ open Function OrderDual variable {ΞΉ Ξ± Ξ² : Type*} section LinearOrderedSemifield variable [Semifield Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] {a b c d e : Ξ±} {m n : β„€} /-! ### Relating two divisions. -/ @[deprecated div_le_div_iff_of_pos_right (since := "2024-11-12")] theorem div_le_div_right (hc : 0 < c) : a / c ≀ b / c ↔ a ≀ b := div_le_div_iff_of_pos_right hc @[deprecated div_lt_div_iff_of_pos_right (since := "2024-11-12")] theorem div_lt_div_right (hc : 0 < c) : a / c < b / c ↔ a < b := div_lt_div_iff_of_pos_right hc @[deprecated div_lt_div_iff_of_pos_left (since := "2024-11-13")] theorem div_lt_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b < a / c ↔ c < b := div_lt_div_iff_of_pos_left ha hb hc @[deprecated div_le_div_iff_of_pos_left (since := "2024-11-12")] theorem div_le_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b ≀ a / c ↔ c ≀ b := div_le_div_iff_of_pos_left ha hb hc @[deprecated div_lt_div_iffβ‚€ (since := "2024-11-12")] theorem div_lt_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b < c / d ↔ a * d < c * b := div_lt_div_iffβ‚€ b0 d0 @[deprecated div_le_div_iffβ‚€ (since := "2024-11-12")] theorem div_le_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b ≀ c / d ↔ a * d ≀ c * b := div_le_div_iffβ‚€ b0 d0 @[deprecated div_le_divβ‚€ (since := "2024-11-12")] theorem div_le_div (hc : 0 ≀ c) (hac : a ≀ c) (hd : 0 < d) (hbd : d ≀ b) : a / b ≀ c / d := div_le_divβ‚€ hc hac hd hbd @[deprecated div_lt_divβ‚€ (since := "2024-11-12")] theorem div_lt_div (hac : a < c) (hbd : d ≀ b) (c0 : 0 ≀ c) (d0 : 0 < d) : a / b < c / d := div_lt_divβ‚€ hac hbd c0 d0 @[deprecated div_lt_divβ‚€' (since := "2024-11-12")] theorem div_lt_div' (hac : a ≀ c) (hbd : d < b) (c0 : 0 < c) (d0 : 0 < d) : a / b < c / d := div_lt_divβ‚€' hac hbd c0 d0 /-! ### Relating one division and involving `1` -/ @[bound] theorem div_le_self (ha : 0 ≀ a) (hb : 1 ≀ b) : a / b ≀ a := by simpa only [div_one] using div_le_div_of_nonneg_left ha zero_lt_one hb @[bound] theorem div_lt_self (ha : 0 < a) (hb : 1 < b) : a / b < a := by simpa only [div_one] using div_lt_div_of_pos_left ha zero_lt_one hb @[bound] theorem le_div_self (ha : 0 ≀ a) (hbβ‚€ : 0 < b) (hb₁ : b ≀ 1) : a ≀ a / b := by simpa only [div_one] using div_le_div_of_nonneg_left ha hbβ‚€ hb₁ theorem one_le_div (hb : 0 < b) : 1 ≀ a / b ↔ b ≀ a := by rw [le_div_iffβ‚€ hb, one_mul] theorem div_le_one (hb : 0 < b) : a / b ≀ 1 ↔ a ≀ b := by rw [div_le_iffβ‚€ hb, one_mul] theorem one_lt_div (hb : 0 < b) : 1 < a / b ↔ b < a := by rw [lt_div_iffβ‚€ hb, one_mul] theorem div_lt_one (hb : 0 < b) : a / b < 1 ↔ a < b := by rw [div_lt_iffβ‚€ hb, one_mul] theorem one_div_le (ha : 0 < a) (hb : 0 < b) : 1 / a ≀ b ↔ 1 / b ≀ a := by simpa using inv_le_commβ‚€ ha hb theorem one_div_lt (ha : 0 < a) (hb : 0 < b) : 1 / a < b ↔ 1 / b < a := by
simpa using inv_lt_commβ‚€ ha hb
Mathlib/Algebra/Order/Field/Basic.lean
93
93
/- Copyright (c) 2023 JoΓ«l Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: JoΓ«l Riou -/ import Mathlib.Algebra.Homology.ShortComplex.Basic import Mathlib.CategoryTheory.Limits.Shapes.Kernels /-! # Left Homology of short complexes Given a short complex `S : ShortComplex C`, which consists of two composable maps `f : X₁ ⟢ Xβ‚‚` and `g : Xβ‚‚ ⟢ X₃` such that `f ≫ g = 0`, we shall define here the "left homology" `S.leftHomology` of `S`. For this, we introduce the notion of "left homology data". Such an `h : S.LeftHomologyData` consists of the data of morphisms `i : K ⟢ Xβ‚‚` and `Ο€ : K ⟢ H` such that `i` identifies `K` with the kernel of `g : Xβ‚‚ ⟢ X₃`, and that `Ο€` identifies `H` with the cokernel of the induced map `f' : X₁ ⟢ K`. When such a `S.LeftHomologyData` exists, we shall say that `[S.HasLeftHomology]` and we define `S.leftHomology` to be the `H` field of a chosen left homology data. Similarly, we define `S.cycles` to be the `K` field. The dual notion is defined in `RightHomologyData.lean`. In `Homology.lean`, when `S` has two compatible left and right homology data (i.e. they give the same `H` up to a canonical isomorphism), we shall define `[S.HasHomology]` and `S.homology`. -/ namespace CategoryTheory open Category Limits namespace ShortComplex variable {C : Type*} [Category C] [HasZeroMorphisms C] (S : ShortComplex C) {S₁ Sβ‚‚ S₃ : ShortComplex C} /-- A left homology data for a short complex `S` consists of morphisms `i : K ⟢ S.Xβ‚‚` and `Ο€ : K ⟢ H` such that `i` identifies `K` to the kernel of `g : S.Xβ‚‚ ⟢ S.X₃`, and that `Ο€` identifies `H` to the cokernel of the induced map `f' : S.X₁ ⟢ K` -/ structure LeftHomologyData where /-- a choice of kernel of `S.g : S.Xβ‚‚ ⟢ S.X₃` -/ K : C /-- a choice of cokernel of the induced morphism `S.f' : S.X₁ ⟢ K` -/ H : C /-- the inclusion of cycles in `S.Xβ‚‚` -/ i : K ⟢ S.Xβ‚‚ /-- the projection from cycles to the (left) homology -/ Ο€ : K ⟢ H /-- the kernel condition for `i` -/ wi : i ≫ S.g = 0 /-- `i : K ⟢ S.Xβ‚‚` is a kernel of `g : S.Xβ‚‚ ⟢ S.X₃` -/ hi : IsLimit (KernelFork.ofΞΉ i wi) /-- the cokernel condition for `Ο€` -/ wΟ€ : hi.lift (KernelFork.ofΞΉ _ S.zero) ≫ Ο€ = 0 /-- `Ο€ : K ⟢ H` is a cokernel of the induced morphism `S.f' : S.X₁ ⟢ K` -/ hΟ€ : IsColimit (CokernelCofork.ofΟ€ Ο€ wΟ€) initialize_simps_projections LeftHomologyData (-hi, -hΟ€) namespace LeftHomologyData /-- The chosen kernels and cokernels of the limits API give a `LeftHomologyData` -/ @[simps] noncomputable def ofHasKernelOfHasCokernel [HasKernel S.g] [HasCokernel (kernel.lift S.g S.f S.zero)] : S.LeftHomologyData where K := kernel S.g H := cokernel (kernel.lift S.g S.f S.zero) i := kernel.ΞΉ _ Ο€ := cokernel.Ο€ _ wi := kernel.condition _ hi := kernelIsKernel _ wΟ€ := cokernel.condition _ hΟ€ := cokernelIsCokernel _ attribute [reassoc (attr := simp)] wi wΟ€ variable {S} variable (h : S.LeftHomologyData) {A : C} instance : Mono h.i := ⟨fun _ _ => Fork.IsLimit.hom_ext h.hi⟩ instance : Epi h.Ο€ := ⟨fun _ _ => Cofork.IsColimit.hom_ext h.hΟ€βŸ© /-- Any morphism `k : A ⟢ S.Xβ‚‚` that is a cycle (i.e. `k ≫ S.g = 0`) lifts to a morphism `A ⟢ K` -/ def liftK (k : A ⟢ S.Xβ‚‚) (hk : k ≫ S.g = 0) : A ⟢ h.K := h.hi.lift (KernelFork.ofΞΉ k hk) @[reassoc (attr := simp)] lemma liftK_i (k : A ⟢ S.Xβ‚‚) (hk : k ≫ S.g = 0) : h.liftK k hk ≫ h.i = k := h.hi.fac _ WalkingParallelPair.zero /-- The (left) homology class `A ⟢ H` attached to a cycle `k : A ⟢ S.Xβ‚‚` -/ @[simp] def liftH (k : A ⟢ S.Xβ‚‚) (hk : k ≫ S.g = 0) : A ⟢ h.H := h.liftK k hk ≫ h.Ο€ /-- Given `h : LeftHomologyData S`, this is morphism `S.X₁ ⟢ h.K` induced by `S.f : S.X₁ ⟢ S.Xβ‚‚` and the fact that `h.K` is a kernel of `S.g : S.Xβ‚‚ ⟢ S.X₃`. -/ def f' : S.X₁ ⟢ h.K := h.liftK S.f S.zero @[reassoc (attr := simp)] lemma f'_i : h.f' ≫ h.i = S.f := liftK_i _ _ _ @[reassoc (attr := simp)] lemma f'_Ο€ : h.f' ≫ h.Ο€ = 0 := h.wΟ€ @[reassoc] lemma liftK_Ο€_eq_zero_of_boundary (k : A ⟢ S.Xβ‚‚) (x : A ⟢ S.X₁) (hx : k = x ≫ S.f) : h.liftK k (by rw [hx, assoc, S.zero, comp_zero]) ≫ h.Ο€ = 0 := by rw [show 0 = (x ≫ h.f') ≫ h.Ο€ by simp] congr 1 simp only [← cancel_mono h.i, hx, liftK_i, assoc, f'_i] /-- For `h : S.LeftHomologyData`, this is a restatement of `h.hΟ€`, saying that `Ο€ : h.K ⟢ h.H` is a cokernel of `h.f' : S.X₁ ⟢ h.K`. -/ def hΟ€' : IsColimit (CokernelCofork.ofΟ€ h.Ο€ h.f'_Ο€) := h.hΟ€ /-- The morphism `H ⟢ A` induced by a morphism `k : K ⟢ A` such that `f' ≫ k = 0` -/ def descH (k : h.K ⟢ A) (hk : h.f' ≫ k = 0) : h.H ⟢ A := h.hΟ€.desc (CokernelCofork.ofΟ€ k hk) @[reassoc (attr := simp)] lemma Ο€_descH (k : h.K ⟢ A) (hk : h.f' ≫ k = 0) : h.Ο€ ≫ h.descH k hk = k := h.hΟ€.fac (CokernelCofork.ofΟ€ k hk) WalkingParallelPair.one lemma isIso_i (hg : S.g = 0) : IsIso h.i := ⟨h.liftK (πŸ™ S.Xβ‚‚) (by rw [hg, id_comp]), by simp only [← cancel_mono h.i, id_comp, assoc, liftK_i, comp_id], liftK_i _ _ _⟩ lemma isIso_Ο€ (hf : S.f = 0) : IsIso h.Ο€ := by have βŸ¨Ο†, hΟ†βŸ© := CokernelCofork.IsColimit.desc' h.hΟ€' (πŸ™ _) (by rw [← cancel_mono h.i, comp_id, f'_i, zero_comp, hf]) dsimp at hΟ† exact βŸ¨Ο†, hΟ†, by rw [← cancel_epi h.Ο€, reassoc_of% hΟ†, comp_id]⟩ variable (S) /-- When the second map `S.g` is zero, this is the left homology data on `S` given by any colimit cokernel cofork of `S.f` -/ @[simps] def ofIsColimitCokernelCofork (hg : S.g = 0) (c : CokernelCofork S.f) (hc : IsColimit c) : S.LeftHomologyData where K := S.Xβ‚‚ H := c.pt i := πŸ™ _ Ο€ := c.Ο€ wi := by rw [id_comp, hg] hi := KernelFork.IsLimit.ofId _ hg wΟ€ := CokernelCofork.condition _ hΟ€ := IsColimit.ofIsoColimit hc (Cofork.ext (Iso.refl _)) @[simp] lemma ofIsColimitCokernelCofork_f' (hg : S.g = 0) (c : CokernelCofork S.f) (hc : IsColimit c) : (ofIsColimitCokernelCofork S hg c hc).f' = S.f := by rw [← cancel_mono (ofIsColimitCokernelCofork S hg c hc).i, f'_i, ofIsColimitCokernelCofork_i] dsimp rw [comp_id] /-- When the second map `S.g` is zero, this is the left homology data on `S` given by the chosen `cokernel S.f` -/ @[simps!] noncomputable def ofHasCokernel [HasCokernel S.f] (hg : S.g = 0) : S.LeftHomologyData := ofIsColimitCokernelCofork S hg _ (cokernelIsCokernel _) /-- When the first map `S.f` is zero, this is the left homology data on `S` given by any limit kernel fork of `S.g` -/ @[simps] def ofIsLimitKernelFork (hf : S.f = 0) (c : KernelFork S.g) (hc : IsLimit c) : S.LeftHomologyData where K := c.pt H := c.pt i := c.ΞΉ Ο€ := πŸ™ _ wi := KernelFork.condition _ hi := IsLimit.ofIsoLimit hc (Fork.ext (Iso.refl _)) wΟ€ := Fork.IsLimit.hom_ext hc (by dsimp simp only [comp_id, zero_comp, Fork.IsLimit.lift_ΞΉ, Fork.ΞΉ_ofΞΉ, hf]) hΟ€ := CokernelCofork.IsColimit.ofId _ (Fork.IsLimit.hom_ext hc (by dsimp simp only [comp_id, zero_comp, Fork.IsLimit.lift_ΞΉ, Fork.ΞΉ_ofΞΉ, hf])) @[simp] lemma ofIsLimitKernelFork_f' (hf : S.f = 0) (c : KernelFork S.g) (hc : IsLimit c) : (ofIsLimitKernelFork S hf c hc).f' = 0 := by rw [← cancel_mono (ofIsLimitKernelFork S hf c hc).i, f'_i, hf, zero_comp] /-- When the first map `S.f` is zero, this is the left homology data on `S` given by the chosen `kernel S.g` -/ @[simp] noncomputable def ofHasKernel [HasKernel S.g] (hf : S.f = 0) : S.LeftHomologyData := ofIsLimitKernelFork S hf _ (kernelIsKernel _) /-- When both `S.f` and `S.g` are zero, the middle object `S.Xβ‚‚` gives a left homology data on S -/ @[simps] def ofZeros (hf : S.f = 0) (hg : S.g = 0) : S.LeftHomologyData where K := S.Xβ‚‚ H := S.Xβ‚‚ i := πŸ™ _ Ο€ := πŸ™ _ wi := by rw [id_comp, hg] hi := KernelFork.IsLimit.ofId _ hg wΟ€ := by change S.f ≫ πŸ™ _ = 0 simp only [hf, zero_comp] hΟ€ := CokernelCofork.IsColimit.ofId _ hf @[simp] lemma ofZeros_f' (hf : S.f = 0) (hg : S.g = 0) : (ofZeros S hf hg).f' = 0 := by rw [← cancel_mono ((ofZeros S hf hg).i), zero_comp, f'_i, hf] end LeftHomologyData /-- A short complex `S` has left homology when there exists a `S.LeftHomologyData` -/ class HasLeftHomology : Prop where condition : Nonempty S.LeftHomologyData /-- A chosen `S.LeftHomologyData` for a short complex `S` that has left homology -/ noncomputable def leftHomologyData [S.HasLeftHomology] : S.LeftHomologyData := HasLeftHomology.condition.some variable {S} namespace HasLeftHomology lemma mk' (h : S.LeftHomologyData) : HasLeftHomology S := ⟨Nonempty.intro h⟩ instance of_hasKernel_of_hasCokernel [HasKernel S.g] [HasCokernel (kernel.lift S.g S.f S.zero)] : S.HasLeftHomology := HasLeftHomology.mk' (LeftHomologyData.ofHasKernelOfHasCokernel S) instance of_hasCokernel {X Y : C} (f : X ⟢ Y) (Z : C) [HasCokernel f] : (ShortComplex.mk f (0 : Y ⟢ Z) comp_zero).HasLeftHomology := HasLeftHomology.mk' (LeftHomologyData.ofHasCokernel _ rfl) instance of_hasKernel {Y Z : C} (g : Y ⟢ Z) (X : C) [HasKernel g] : (ShortComplex.mk (0 : X ⟢ Y) g zero_comp).HasLeftHomology := HasLeftHomology.mk' (LeftHomologyData.ofHasKernel _ rfl) instance of_zeros (X Y Z : C) : (ShortComplex.mk (0 : X ⟢ Y) (0 : Y ⟢ Z) zero_comp).HasLeftHomology := HasLeftHomology.mk' (LeftHomologyData.ofZeros _ rfl rfl) end HasLeftHomology section variable (Ο† : S₁ ⟢ Sβ‚‚) (h₁ : S₁.LeftHomologyData) (hβ‚‚ : Sβ‚‚.LeftHomologyData) /-- Given left homology data `h₁` and `hβ‚‚` for two short complexes `S₁` and `Sβ‚‚`, a `LeftHomologyMapData` for a morphism `Ο† : S₁ ⟢ Sβ‚‚` consists of a description of the induced morphisms on the `K` (cycles) and `H` (left homology) fields of `h₁` and `hβ‚‚`. -/ structure LeftHomologyMapData where /-- the induced map on cycles -/ Ο†K : h₁.K ⟢ hβ‚‚.K /-- the induced map on left homology -/ Ο†H : h₁.H ⟢ hβ‚‚.H /-- commutation with `i` -/ commi : Ο†K ≫ hβ‚‚.i = h₁.i ≫ Ο†.Ο„β‚‚ := by aesop_cat /-- commutation with `f'` -/ commf' : h₁.f' ≫ Ο†K = Ο†.τ₁ ≫ hβ‚‚.f' := by aesop_cat /-- commutation with `Ο€` -/ commΟ€ : h₁.Ο€ ≫ Ο†H = Ο†K ≫ hβ‚‚.Ο€ := by aesop_cat namespace LeftHomologyMapData attribute [reassoc (attr := simp)] commi commf' commΟ€ /-- The left homology map data associated to the zero morphism between two short complexes. -/ @[simps] def zero (h₁ : S₁.LeftHomologyData) (hβ‚‚ : Sβ‚‚.LeftHomologyData) : LeftHomologyMapData 0 h₁ hβ‚‚ where Ο†K := 0 Ο†H := 0 /-- The left homology map data associated to the identity morphism of a short complex. -/ @[simps] def id (h : S.LeftHomologyData) : LeftHomologyMapData (πŸ™ S) h h where Ο†K := πŸ™ _ Ο†H := πŸ™ _ /-- The composition of left homology map data. -/ @[simps] def comp {Ο† : S₁ ⟢ Sβ‚‚} {Ο†' : Sβ‚‚ ⟢ S₃} {h₁ : S₁.LeftHomologyData} {hβ‚‚ : Sβ‚‚.LeftHomologyData} {h₃ : S₃.LeftHomologyData} (ψ : LeftHomologyMapData Ο† h₁ hβ‚‚) (ψ' : LeftHomologyMapData Ο†' hβ‚‚ h₃) : LeftHomologyMapData (Ο† ≫ Ο†') h₁ h₃ where Ο†K := ψ.Ο†K ≫ ψ'.Ο†K Ο†H := ψ.Ο†H ≫ ψ'.Ο†H instance : Subsingleton (LeftHomologyMapData Ο† h₁ hβ‚‚) := ⟨fun Οˆβ‚ Οˆβ‚‚ => by have hK : Οˆβ‚.Ο†K = Οˆβ‚‚.Ο†K := by rw [← cancel_mono hβ‚‚.i, commi, commi] have hH : Οˆβ‚.Ο†H = Οˆβ‚‚.Ο†H := by rw [← cancel_epi h₁.Ο€, commΟ€, commΟ€, hK] cases Οˆβ‚ cases Οˆβ‚‚ congr⟩ instance : Inhabited (LeftHomologyMapData Ο† h₁ hβ‚‚) := ⟨by let Ο†K : h₁.K ⟢ hβ‚‚.K := hβ‚‚.liftK (h₁.i ≫ Ο†.Ο„β‚‚) (by rw [assoc, Ο†.comm₂₃, h₁.wi_assoc, zero_comp]) have commf' : h₁.f' ≫ Ο†K = Ο†.τ₁ ≫ hβ‚‚.f' := by rw [← cancel_mono hβ‚‚.i, assoc, assoc, LeftHomologyData.liftK_i, LeftHomologyData.f'_i_assoc, LeftHomologyData.f'_i, Ο†.comm₁₂] let Ο†H : h₁.H ⟢ hβ‚‚.H := h₁.descH (Ο†K ≫ hβ‚‚.Ο€) (by rw [reassoc_of% commf', hβ‚‚.f'_Ο€, comp_zero]) exact βŸ¨Ο†K, Ο†H, by simp [Ο†K], commf', by simp [Ο†H]⟩⟩ instance : Unique (LeftHomologyMapData Ο† h₁ hβ‚‚) := Unique.mk' _ variable {Ο† h₁ hβ‚‚} lemma congr_Ο†H {γ₁ Ξ³β‚‚ : LeftHomologyMapData Ο† h₁ hβ‚‚} (eq : γ₁ = Ξ³β‚‚) : γ₁.Ο†H = Ξ³β‚‚.Ο†H := by rw [eq] lemma congr_Ο†K {γ₁ Ξ³β‚‚ : LeftHomologyMapData Ο† h₁ hβ‚‚} (eq : γ₁ = Ξ³β‚‚) : γ₁.Ο†K = Ξ³β‚‚.Ο†K := by rw [eq] /-- When `S₁.f`, `S₁.g`, `Sβ‚‚.f` and `Sβ‚‚.g` are all zero, the action on left homology of a morphism `Ο† : S₁ ⟢ Sβ‚‚` is given by the action `Ο†.Ο„β‚‚` on the middle objects. -/ @[simps] def ofZeros (Ο† : S₁ ⟢ Sβ‚‚) (hf₁ : S₁.f = 0) (hg₁ : S₁.g = 0) (hfβ‚‚ : Sβ‚‚.f = 0) (hgβ‚‚ : Sβ‚‚.g = 0) : LeftHomologyMapData Ο† (LeftHomologyData.ofZeros S₁ hf₁ hg₁) (LeftHomologyData.ofZeros Sβ‚‚ hfβ‚‚ hgβ‚‚) where Ο†K := Ο†.Ο„β‚‚ Ο†H := Ο†.Ο„β‚‚ /-- When `S₁.g` and `Sβ‚‚.g` are zero and we have chosen colimit cokernel coforks `c₁` and `cβ‚‚` for `S₁.f` and `Sβ‚‚.f` respectively, the action on left homology of a morphism `Ο† : S₁ ⟢ Sβ‚‚` of short complexes is given by the unique morphism `f : c₁.pt ⟢ cβ‚‚.pt` such that `Ο†.Ο„β‚‚ ≫ cβ‚‚.Ο€ = c₁.Ο€ ≫ f`. -/ @[simps] def ofIsColimitCokernelCofork (Ο† : S₁ ⟢ Sβ‚‚) (hg₁ : S₁.g = 0) (c₁ : CokernelCofork S₁.f) (hc₁ : IsColimit c₁) (hgβ‚‚ : Sβ‚‚.g = 0) (cβ‚‚ : CokernelCofork Sβ‚‚.f) (hcβ‚‚ : IsColimit cβ‚‚) (f : c₁.pt ⟢ cβ‚‚.pt) (comm : Ο†.Ο„β‚‚ ≫ cβ‚‚.Ο€ = c₁.Ο€ ≫ f) : LeftHomologyMapData Ο† (LeftHomologyData.ofIsColimitCokernelCofork S₁ hg₁ c₁ hc₁) (LeftHomologyData.ofIsColimitCokernelCofork Sβ‚‚ hgβ‚‚ cβ‚‚ hcβ‚‚) where Ο†K := Ο†.Ο„β‚‚ Ο†H := f commΟ€ := comm.symm commf' := by simp only [LeftHomologyData.ofIsColimitCokernelCofork_f', Ο†.comm₁₂] /-- When `S₁.f` and `Sβ‚‚.f` are zero and we have chosen limit kernel forks `c₁` and `cβ‚‚` for `S₁.g` and `Sβ‚‚.g` respectively, the action on left homology of a morphism `Ο† : S₁ ⟢ Sβ‚‚` of short complexes is given by the unique morphism `f : c₁.pt ⟢ cβ‚‚.pt` such that `c₁.ΞΉ ≫ Ο†.Ο„β‚‚ = f ≫ cβ‚‚.ΞΉ`. -/ @[simps] def ofIsLimitKernelFork (Ο† : S₁ ⟢ Sβ‚‚) (hf₁ : S₁.f = 0) (c₁ : KernelFork S₁.g) (hc₁ : IsLimit c₁) (hfβ‚‚ : Sβ‚‚.f = 0) (cβ‚‚ : KernelFork Sβ‚‚.g) (hcβ‚‚ : IsLimit cβ‚‚) (f : c₁.pt ⟢ cβ‚‚.pt) (comm : c₁.ΞΉ ≫ Ο†.Ο„β‚‚ = f ≫ cβ‚‚.ΞΉ) : LeftHomologyMapData Ο† (LeftHomologyData.ofIsLimitKernelFork S₁ hf₁ c₁ hc₁) (LeftHomologyData.ofIsLimitKernelFork Sβ‚‚ hfβ‚‚ cβ‚‚ hcβ‚‚) where Ο†K := f Ο†H := f commi := comm.symm variable (S) /-- When both maps `S.f` and `S.g` of a short complex `S` are zero, this is the left homology map data (for the identity of `S`) which relates the left homology data `ofZeros` and `ofIsColimitCokernelCofork`. -/ @[simps] def compatibilityOfZerosOfIsColimitCokernelCofork (hf : S.f = 0) (hg : S.g = 0) (c : CokernelCofork S.f) (hc : IsColimit c) : LeftHomologyMapData (πŸ™ S) (LeftHomologyData.ofZeros S hf hg) (LeftHomologyData.ofIsColimitCokernelCofork S hg c hc) where Ο†K := πŸ™ _ Ο†H := c.Ο€ /-- When both maps `S.f` and `S.g` of a short complex `S` are zero, this is the left homology map data (for the identity of `S`) which relates the left homology data `LeftHomologyData.ofIsLimitKernelFork` and `ofZeros` . -/ @[simps] def compatibilityOfZerosOfIsLimitKernelFork (hf : S.f = 0) (hg : S.g = 0) (c : KernelFork S.g) (hc : IsLimit c) : LeftHomologyMapData (πŸ™ S) (LeftHomologyData.ofIsLimitKernelFork S hf c hc) (LeftHomologyData.ofZeros S hf hg) where Ο†K := c.ΞΉ Ο†H := c.ΞΉ end LeftHomologyMapData end section variable (S) variable [S.HasLeftHomology] /-- The left homology of a short complex, given by the `H` field of a chosen left homology data. -/ noncomputable def leftHomology : C := S.leftHomologyData.H -- `S.leftHomology` is the simp normal form. @[simp] lemma leftHomologyData_H : S.leftHomologyData.H = S.leftHomology := rfl /-- The cycles of a short complex, given by the `K` field of a chosen left homology data. -/ noncomputable def cycles : C := S.leftHomologyData.K /-- The "homology class" map `S.cycles ⟢ S.leftHomology`. -/ noncomputable def leftHomologyΟ€ : S.cycles ⟢ S.leftHomology := S.leftHomologyData.Ο€ /-- The inclusion `S.cycles ⟢ S.Xβ‚‚`. -/ noncomputable def iCycles : S.cycles ⟢ S.Xβ‚‚ := S.leftHomologyData.i /-- The "boundaries" map `S.X₁ ⟢ S.cycles`. (Note that in this homology API, we make no use of the "image" of this morphism, which under some categorical assumptions would be a subobject of `S.Xβ‚‚` contained in `S.cycles`.) -/ noncomputable def toCycles : S.X₁ ⟢ S.cycles := S.leftHomologyData.f' @[reassoc (attr := simp)] lemma iCycles_g : S.iCycles ≫ S.g = 0 := S.leftHomologyData.wi @[reassoc (attr := simp)] lemma toCycles_i : S.toCycles ≫ S.iCycles = S.f := S.leftHomologyData.f'_i instance : Mono S.iCycles := by dsimp only [iCycles] infer_instance instance : Epi S.leftHomologyΟ€ := by dsimp only [leftHomologyΟ€] infer_instance lemma leftHomology_ext_iff {A : C} (f₁ fβ‚‚ : S.leftHomology ⟢ A) : f₁ = fβ‚‚ ↔ S.leftHomologyΟ€ ≫ f₁ = S.leftHomologyΟ€ ≫ fβ‚‚ := by rw [cancel_epi] @[ext] lemma leftHomology_ext {A : C} (f₁ fβ‚‚ : S.leftHomology ⟢ A) (h : S.leftHomologyΟ€ ≫ f₁ = S.leftHomologyΟ€ ≫ fβ‚‚) : f₁ = fβ‚‚ := by simpa only [leftHomology_ext_iff] using h lemma cycles_ext_iff {A : C} (f₁ fβ‚‚ : A ⟢ S.cycles) : f₁ = fβ‚‚ ↔ f₁ ≫ S.iCycles = fβ‚‚ ≫ S.iCycles := by rw [cancel_mono] @[ext] lemma cycles_ext {A : C} (f₁ fβ‚‚ : A ⟢ S.cycles) (h : f₁ ≫ S.iCycles = fβ‚‚ ≫ S.iCycles) : f₁ = fβ‚‚ := by simpa only [cycles_ext_iff] using h lemma isIso_iCycles (hg : S.g = 0) : IsIso S.iCycles := LeftHomologyData.isIso_i _ hg /-- When `S.g = 0`, this is the canonical isomorphism `S.cycles β‰… S.Xβ‚‚` induced by `S.iCycles`. -/ @[simps! hom] noncomputable def cyclesIsoXβ‚‚ (hg : S.g = 0) : S.cycles β‰… S.Xβ‚‚ := by have := S.isIso_iCycles hg exact asIso S.iCycles @[reassoc (attr := simp)] lemma cyclesIsoXβ‚‚_hom_inv_id (hg : S.g = 0) : S.iCycles ≫ (S.cyclesIsoXβ‚‚ hg).inv = πŸ™ _ := (S.cyclesIsoXβ‚‚ hg).hom_inv_id @[reassoc (attr := simp)] lemma cyclesIsoXβ‚‚_inv_hom_id (hg : S.g = 0) : (S.cyclesIsoXβ‚‚ hg).inv ≫ S.iCycles = πŸ™ _ := (S.cyclesIsoXβ‚‚ hg).inv_hom_id lemma isIso_leftHomologyΟ€ (hf : S.f = 0) : IsIso S.leftHomologyΟ€ := LeftHomologyData.isIso_Ο€ _ hf /-- When `S.f = 0`, this is the canonical isomorphism `S.cycles β‰… S.leftHomology` induced by `S.leftHomologyΟ€`. -/ @[simps! hom] noncomputable def cyclesIsoLeftHomology (hf : S.f = 0) : S.cycles β‰… S.leftHomology := by have := S.isIso_leftHomologyΟ€ hf exact asIso S.leftHomologyΟ€ @[reassoc (attr := simp)] lemma cyclesIsoLeftHomology_hom_inv_id (hf : S.f = 0) : S.leftHomologyΟ€ ≫ (S.cyclesIsoLeftHomology hf).inv = πŸ™ _ := (S.cyclesIsoLeftHomology hf).hom_inv_id @[reassoc (attr := simp)] lemma cyclesIsoLeftHomology_inv_hom_id (hf : S.f = 0) : (S.cyclesIsoLeftHomology hf).inv ≫ S.leftHomologyΟ€ = πŸ™ _ := (S.cyclesIsoLeftHomology hf).inv_hom_id end section variable (Ο† : S₁ ⟢ Sβ‚‚) (h₁ : S₁.LeftHomologyData) (hβ‚‚ : Sβ‚‚.LeftHomologyData) /-- The (unique) left homology map data associated to a morphism of short complexes that are both equipped with left homology data. -/ def leftHomologyMapData : LeftHomologyMapData Ο† h₁ hβ‚‚ := default /-- Given a morphism `Ο† : S₁ ⟢ Sβ‚‚` of short complexes and left homology data `h₁` and `hβ‚‚` for `S₁` and `Sβ‚‚` respectively, this is the induced left homology map `h₁.H ⟢ h₁.H`. -/ def leftHomologyMap' : h₁.H ⟢ hβ‚‚.H := (leftHomologyMapData Ο† _ _).Ο†H /-- Given a morphism `Ο† : S₁ ⟢ Sβ‚‚` of short complexes and left homology data `h₁` and `hβ‚‚` for `S₁` and `Sβ‚‚` respectively, this is the induced morphism `h₁.K ⟢ h₁.K` on cycles. -/ def cyclesMap' : h₁.K ⟢ hβ‚‚.K := (leftHomologyMapData Ο† _ _).Ο†K @[reassoc (attr := simp)] lemma cyclesMap'_i : cyclesMap' Ο† h₁ hβ‚‚ ≫ hβ‚‚.i = h₁.i ≫ Ο†.Ο„β‚‚ := LeftHomologyMapData.commi _ @[reassoc (attr := simp)] lemma f'_cyclesMap' : h₁.f' ≫ cyclesMap' Ο† h₁ hβ‚‚ = Ο†.τ₁ ≫ hβ‚‚.f' := by simp only [← cancel_mono hβ‚‚.i, assoc, Ο†.comm₁₂, cyclesMap'_i, LeftHomologyData.f'_i_assoc, LeftHomologyData.f'_i] @[reassoc (attr := simp)] lemma leftHomologyΟ€_naturality' : h₁.Ο€ ≫ leftHomologyMap' Ο† h₁ hβ‚‚ = cyclesMap' Ο† h₁ hβ‚‚ ≫ hβ‚‚.Ο€ := LeftHomologyMapData.commΟ€ _ end section variable [HasLeftHomology S₁] [HasLeftHomology Sβ‚‚] (Ο† : S₁ ⟢ Sβ‚‚) /-- The (left) homology map `S₁.leftHomology ⟢ Sβ‚‚.leftHomology` induced by a morphism `S₁ ⟢ Sβ‚‚` of short complexes. -/ noncomputable def leftHomologyMap : S₁.leftHomology ⟢ Sβ‚‚.leftHomology := leftHomologyMap' Ο† _ _ /-- The morphism `S₁.cycles ⟢ Sβ‚‚.cycles` induced by a morphism `S₁ ⟢ Sβ‚‚` of short complexes. -/ noncomputable def cyclesMap : S₁.cycles ⟢ Sβ‚‚.cycles := cyclesMap' Ο† _ _ @[reassoc (attr := simp)] lemma cyclesMap_i : cyclesMap Ο† ≫ Sβ‚‚.iCycles = S₁.iCycles ≫ Ο†.Ο„β‚‚ := cyclesMap'_i _ _ _ @[reassoc (attr := simp)] lemma toCycles_naturality : S₁.toCycles ≫ cyclesMap Ο† = Ο†.τ₁ ≫ Sβ‚‚.toCycles := f'_cyclesMap' _ _ _ @[reassoc (attr := simp)] lemma leftHomologyΟ€_naturality : S₁.leftHomologyΟ€ ≫ leftHomologyMap Ο† = cyclesMap Ο† ≫ Sβ‚‚.leftHomologyΟ€ := leftHomologyΟ€_naturality' _ _ _ end namespace LeftHomologyMapData variable {Ο† : S₁ ⟢ Sβ‚‚} {h₁ : S₁.LeftHomologyData} {hβ‚‚ : Sβ‚‚.LeftHomologyData} (Ξ³ : LeftHomologyMapData Ο† h₁ hβ‚‚) lemma leftHomologyMap'_eq : leftHomologyMap' Ο† h₁ hβ‚‚ = Ξ³.Ο†H := LeftHomologyMapData.congr_Ο†H (Subsingleton.elim _ _) lemma cyclesMap'_eq : cyclesMap' Ο† h₁ hβ‚‚ = Ξ³.Ο†K := LeftHomologyMapData.congr_Ο†K (Subsingleton.elim _ _) end LeftHomologyMapData @[simp] lemma leftHomologyMap'_id (h : S.LeftHomologyData) : leftHomologyMap' (πŸ™ S) h h = πŸ™ _ := (LeftHomologyMapData.id h).leftHomologyMap'_eq @[simp] lemma cyclesMap'_id (h : S.LeftHomologyData) : cyclesMap' (πŸ™ S) h h = πŸ™ _ := (LeftHomologyMapData.id h).cyclesMap'_eq variable (S) @[simp] lemma leftHomologyMap_id [HasLeftHomology S] : leftHomologyMap (πŸ™ S) = πŸ™ _ := leftHomologyMap'_id _ @[simp] lemma cyclesMap_id [HasLeftHomology S] : cyclesMap (πŸ™ S) = πŸ™ _ := cyclesMap'_id _ @[simp] lemma leftHomologyMap'_zero (h₁ : S₁.LeftHomologyData) (hβ‚‚ : Sβ‚‚.LeftHomologyData) : leftHomologyMap' 0 h₁ hβ‚‚ = 0 := (LeftHomologyMapData.zero h₁ hβ‚‚).leftHomologyMap'_eq @[simp] lemma cyclesMap'_zero (h₁ : S₁.LeftHomologyData) (hβ‚‚ : Sβ‚‚.LeftHomologyData) : cyclesMap' 0 h₁ hβ‚‚ = 0 := (LeftHomologyMapData.zero h₁ hβ‚‚).cyclesMap'_eq variable (S₁ Sβ‚‚) @[simp] lemma leftHomologyMap_zero [HasLeftHomology S₁] [HasLeftHomology Sβ‚‚] : leftHomologyMap (0 : S₁ ⟢ Sβ‚‚) = 0 := leftHomologyMap'_zero _ _ @[simp] lemma cyclesMap_zero [HasLeftHomology S₁] [HasLeftHomology Sβ‚‚] : cyclesMap (0 : S₁ ⟢ Sβ‚‚) = 0 := cyclesMap'_zero _ _
variable {S₁ Sβ‚‚} @[reassoc] lemma leftHomologyMap'_comp (φ₁ : S₁ ⟢ Sβ‚‚) (Ο†β‚‚ : Sβ‚‚ ⟢ S₃) (h₁ : S₁.LeftHomologyData) (hβ‚‚ : Sβ‚‚.LeftHomologyData) (h₃ : S₃.LeftHomologyData) : leftHomologyMap' (φ₁ ≫ Ο†β‚‚) h₁ h₃ = leftHomologyMap' φ₁ h₁ hβ‚‚ ≫ leftHomologyMap' Ο†β‚‚ hβ‚‚ h₃ := by let γ₁ := leftHomologyMapData φ₁ h₁ hβ‚‚ let Ξ³β‚‚ := leftHomologyMapData Ο†β‚‚ hβ‚‚ h₃
Mathlib/Algebra/Homology/ShortComplex/LeftHomology.lean
597
605
/- 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.Card import Mathlib.Data.Fintype.Basic /-! # Cardinalities of finite types This file defines the cardinality `Fintype.card Ξ±` as the number of elements in `(univ : Finset Ξ±)`. We also include some elementary results on the values of `Fintype.card` on specific types. ## Main declarations * `Fintype.card Ξ±`: Cardinality of a fintype. Equal to `Finset.univ.card`. * `Finite.surjective_of_injective`: an injective function from a finite type to itself is also surjective. -/ assert_not_exists Monoid open Function universe u v variable {Ξ± Ξ² Ξ³ : Type*} open Finset Function namespace Fintype /-- `card Ξ±` is the number of elements in `Ξ±`, defined when `Ξ±` is a fintype. -/ def card (Ξ±) [Fintype Ξ±] : β„• := (@univ Ξ± _).card theorem subtype_card {p : Ξ± β†’ Prop} (s : Finset Ξ±) (H : βˆ€ x : Ξ±, x ∈ s ↔ p x) : @card { x // p x } (Fintype.subtype s H) = #s := Multiset.card_pmap _ _ _ theorem card_of_subtype {p : Ξ± β†’ Prop} (s : Finset Ξ±) (H : βˆ€ x : Ξ±, x ∈ s ↔ p x) [Fintype { x // p x }] : card { x // p x } = #s := by rw [← subtype_card s H] congr! @[simp] theorem card_ofFinset {p : Set Ξ±} (s : Finset Ξ±) (H : βˆ€ x, x ∈ s ↔ x ∈ p) : @Fintype.card p (ofFinset s H) = #s := Fintype.subtype_card s H theorem card_of_finset' {p : Set Ξ±} (s : Finset Ξ±) (H : βˆ€ x, x ∈ s ↔ x ∈ p) [Fintype p] : Fintype.card p = #s := by rw [← card_ofFinset s H]; congr! end Fintype namespace Fintype theorem ofEquiv_card [Fintype Ξ±] (f : Ξ± ≃ Ξ²) : @card Ξ² (ofEquiv Ξ± f) = card Ξ± := Multiset.card_map _ _ theorem card_congr {Ξ± Ξ²} [Fintype Ξ±] [Fintype Ξ²] (f : Ξ± ≃ Ξ²) : card Ξ± = card Ξ² := by rw [← ofEquiv_card f]; congr! @[congr] theorem card_congr' {Ξ± Ξ²} [Fintype Ξ±] [Fintype Ξ²] (h : Ξ± = Ξ²) : card Ξ± = card Ξ² := card_congr (by rw [h]) /-- Note: this lemma is specifically about `Fintype.ofSubsingleton`. For a statement about arbitrary `Fintype` instances, use either `Fintype.card_le_one_iff_subsingleton` or `Fintype.card_unique`. -/ theorem card_ofSubsingleton (a : Ξ±) [Subsingleton Ξ±] : @Fintype.card _ (ofSubsingleton a) = 1 := rfl @[simp] theorem card_unique [Unique Ξ±] [h : Fintype Ξ±] : Fintype.card Ξ± = 1 := Subsingleton.elim (ofSubsingleton default) h β–Έ card_ofSubsingleton _ /-- Note: this lemma is specifically about `Fintype.ofIsEmpty`. For a statement about arbitrary `Fintype` instances, use `Fintype.card_eq_zero`. -/ theorem card_ofIsEmpty [IsEmpty Ξ±] : @Fintype.card Ξ± Fintype.ofIsEmpty = 0 := rfl end Fintype namespace Set variable {s t : Set Ξ±} -- We use an arbitrary `[Fintype s]` instance here, -- not necessarily coming from a `[Fintype Ξ±]`. @[simp] theorem toFinset_card {Ξ± : Type*} (s : Set Ξ±) [Fintype s] : s.toFinset.card = Fintype.card s := Multiset.card_map Subtype.val Finset.univ.val end Set @[simp] theorem Finset.card_univ [Fintype Ξ±] : #(univ : Finset Ξ±) = Fintype.card Ξ± := rfl theorem Finset.eq_univ_of_card [Fintype Ξ±] (s : Finset Ξ±) (hs : #s = Fintype.card Ξ±) : s = univ := eq_of_subset_of_card_le (subset_univ _) <| by rw [hs, Finset.card_univ] theorem Finset.card_eq_iff_eq_univ [Fintype Ξ±] (s : Finset Ξ±) : #s = Fintype.card Ξ± ↔ s = univ := ⟨s.eq_univ_of_card, by rintro rfl exact Finset.card_univ⟩ theorem Finset.card_le_univ [Fintype Ξ±] (s : Finset Ξ±) : #s ≀ Fintype.card Ξ± := card_le_card (subset_univ s) theorem Finset.card_lt_univ_of_not_mem [Fintype Ξ±] {s : Finset Ξ±} {x : Ξ±} (hx : x βˆ‰ s) : #s < Fintype.card Ξ± := card_lt_card ⟨subset_univ s, not_forall.2 ⟨x, fun hx' => hx (hx' <| mem_univ x)⟩⟩ theorem Finset.card_lt_iff_ne_univ [Fintype Ξ±] (s : Finset Ξ±) : #s < Fintype.card Ξ± ↔ s β‰  Finset.univ := s.card_le_univ.lt_iff_ne.trans (not_congr s.card_eq_iff_eq_univ) theorem Finset.card_compl_lt_iff_nonempty [Fintype Ξ±] [DecidableEq Ξ±] (s : Finset Ξ±) : #sᢜ < Fintype.card Ξ± ↔ s.Nonempty := sᢜ.card_lt_iff_ne_univ.trans s.compl_ne_univ_iff_nonempty theorem Finset.card_univ_diff [DecidableEq Ξ±] [Fintype Ξ±] (s : Finset Ξ±) : #(univ \ s) = Fintype.card Ξ± - #s := Finset.card_sdiff (subset_univ s) theorem Finset.card_compl [DecidableEq Ξ±] [Fintype Ξ±] (s : Finset Ξ±) : #sᢜ = Fintype.card Ξ± - #s := Finset.card_univ_diff s @[simp] theorem Finset.card_add_card_compl [DecidableEq Ξ±] [Fintype Ξ±] (s : Finset Ξ±) : #s + #sᢜ = Fintype.card Ξ± := by rw [Finset.card_compl, ← Nat.add_sub_assoc (card_le_univ s), Nat.add_sub_cancel_left] @[simp] theorem Finset.card_compl_add_card [DecidableEq Ξ±] [Fintype Ξ±] (s : Finset Ξ±) : #sᢜ + #s = Fintype.card Ξ± := by rw [Nat.add_comm, card_add_card_compl] theorem Fintype.card_compl_set [Fintype Ξ±] (s : Set Ξ±) [Fintype s] [Fintype (β†₯sᢜ : Sort _)] : Fintype.card (β†₯sᢜ : Sort _) = Fintype.card Ξ± - Fintype.card s := by classical rw [← Set.toFinset_card, ← Set.toFinset_card, ← Finset.card_compl, Set.toFinset_compl] theorem Fintype.card_subtype_eq (y : Ξ±) [Fintype { x // x = y }] : Fintype.card { x // x = y } = 1 := Fintype.card_unique theorem Fintype.card_subtype_eq' (y : Ξ±) [Fintype { x // y = x }] : Fintype.card { x // y = x } = 1 := Fintype.card_unique theorem Fintype.card_empty : Fintype.card Empty = 0 := rfl theorem Fintype.card_pempty : Fintype.card PEmpty = 0 := rfl theorem Fintype.card_unit : Fintype.card Unit = 1 := rfl @[simp] theorem Fintype.card_punit : Fintype.card PUnit = 1 := rfl @[simp] theorem Fintype.card_bool : Fintype.card Bool = 2 := rfl @[simp] theorem Fintype.card_ulift (Ξ± : Type*) [Fintype Ξ±] : Fintype.card (ULift Ξ±) = Fintype.card Ξ± := Fintype.ofEquiv_card _ @[simp] theorem Fintype.card_plift (Ξ± : Type*) [Fintype Ξ±] : Fintype.card (PLift Ξ±) = Fintype.card Ξ± := Fintype.ofEquiv_card _ @[simp] theorem Fintype.card_orderDual (Ξ± : Type*) [Fintype Ξ±] : Fintype.card Ξ±α΅’α΅ˆ = Fintype.card Ξ± := rfl @[simp] theorem Fintype.card_lex (Ξ± : Type*) [Fintype Ξ±] : Fintype.card (Lex Ξ±) = Fintype.card Ξ± := rfl -- Note: The extra hypothesis `h` is there so that the rewrite lemma applies, -- no matter what instance of `Fintype (Set.univ : Set Ξ±)` is used. @[simp] theorem Fintype.card_setUniv [Fintype Ξ±] {h : Fintype (Set.univ : Set Ξ±)} : Fintype.card (Set.univ : Set Ξ±) = Fintype.card Ξ± := by apply Fintype.card_of_finset' simp @[simp] theorem Fintype.card_subtype_true [Fintype Ξ±] {h : Fintype {_a : Ξ± // True}} : @Fintype.card {_a // True} h = Fintype.card Ξ± := by apply Fintype.card_of_subtype simp /-- Given that `Ξ± βŠ• Ξ²` is a fintype, `Ξ±` is also a fintype. This is non-computable as it uses that `Sum.inl` is an injection, but there's no clear inverse if `Ξ±` is empty. -/ noncomputable def Fintype.sumLeft {Ξ± Ξ²} [Fintype (Ξ± βŠ• Ξ²)] : Fintype Ξ± := Fintype.ofInjective (Sum.inl : Ξ± β†’ Ξ± βŠ• Ξ²) Sum.inl_injective /-- Given that `Ξ± βŠ• Ξ²` is a fintype, `Ξ²` is also a fintype. This is non-computable as it uses that `Sum.inr` is an injection, but there's no clear inverse if `Ξ²` is empty. -/ noncomputable def Fintype.sumRight {Ξ± Ξ²} [Fintype (Ξ± βŠ• Ξ²)] : Fintype Ξ² := Fintype.ofInjective (Sum.inr : Ξ² β†’ Ξ± βŠ• Ξ²) Sum.inr_injective theorem Finite.exists_univ_list (Ξ±) [Finite Ξ±] : βˆƒ l : List Ξ±, l.Nodup ∧ βˆ€ x : Ξ±, x ∈ l := by cases nonempty_fintype Ξ± obtain ⟨l, e⟩ := Quotient.exists_rep (@univ Ξ± _).1 have := And.intro (@univ Ξ± _).2 (@mem_univ_val Ξ± _) exact ⟨_, by rwa [← e] at this⟩ theorem List.Nodup.length_le_card {Ξ± : Type*} [Fintype Ξ±] {l : List Ξ±} (h : l.Nodup) : l.length ≀ Fintype.card Ξ± := by classical exact List.toFinset_card_of_nodup h β–Έ l.toFinset.card_le_univ namespace Fintype variable [Fintype Ξ±] [Fintype Ξ²] theorem card_le_of_injective (f : Ξ± β†’ Ξ²) (hf : Function.Injective f) : card Ξ± ≀ card Ξ² := Finset.card_le_card_of_injOn f (fun _ _ => Finset.mem_univ _) fun _ _ _ _ h => hf h theorem card_le_of_embedding (f : Ξ± β†ͺ Ξ²) : card Ξ± ≀ card Ξ² := card_le_of_injective f f.2 theorem card_lt_of_injective_of_not_mem (f : Ξ± β†’ Ξ²) (h : Function.Injective f) {b : Ξ²} (w : b βˆ‰ Set.range f) : card Ξ± < card Ξ² := calc card Ξ± = (univ.map ⟨f, h⟩).card := (card_map _).symm _ < card Ξ² := Finset.card_lt_univ_of_not_mem (x := b) <| by rwa [← mem_coe, coe_map, coe_univ, Set.image_univ] theorem card_lt_of_injective_not_surjective (f : Ξ± β†’ Ξ²) (h : Function.Injective f) (h' : Β¬Function.Surjective f) : card Ξ± < card Ξ² := let ⟨_y, hy⟩ := not_forall.1 h' card_lt_of_injective_of_not_mem f h hy theorem card_le_of_surjective (f : Ξ± β†’ Ξ²) (h : Function.Surjective f) : card Ξ² ≀ card Ξ± := card_le_of_injective _ (Function.injective_surjInv h) theorem card_range_le {Ξ± Ξ² : Type*} (f : Ξ± β†’ Ξ²) [Fintype Ξ±] [Fintype (Set.range f)] : Fintype.card (Set.range f) ≀ Fintype.card Ξ± := Fintype.card_le_of_surjective (fun a => ⟨f a, by simp⟩) fun ⟨_, a, ha⟩ => ⟨a, by simpa using ha⟩ theorem card_range {Ξ± Ξ² F : Type*} [FunLike F Ξ± Ξ²] [EmbeddingLike F Ξ± Ξ²] (f : F) [Fintype Ξ±] [Fintype (Set.range f)] : Fintype.card (Set.range f) = Fintype.card Ξ± := Eq.symm <| Fintype.card_congr <| Equiv.ofInjective _ <| EmbeddingLike.injective f theorem card_eq_zero_iff : card Ξ± = 0 ↔ IsEmpty Ξ± := by rw [card, Finset.card_eq_zero, univ_eq_empty_iff] @[simp] theorem card_eq_zero [IsEmpty Ξ±] : card Ξ± = 0 := card_eq_zero_iff.2 β€Ή_β€Ί alias card_of_isEmpty := card_eq_zero /-- A `Fintype` with cardinality zero is equivalent to `Empty`. -/ def cardEqZeroEquivEquivEmpty : card Ξ± = 0 ≃ (Ξ± ≃ Empty) := (Equiv.ofIff card_eq_zero_iff).trans (Equiv.equivEmptyEquiv Ξ±).symm theorem card_pos_iff : 0 < card Ξ± ↔ Nonempty Ξ± := Nat.pos_iff_ne_zero.trans <| not_iff_comm.mp <| not_nonempty_iff.trans card_eq_zero_iff.symm theorem card_pos [h : Nonempty Ξ±] : 0 < card Ξ± := card_pos_iff.mpr h @[simp] theorem card_ne_zero [Nonempty Ξ±] : card Ξ± β‰  0 := _root_.ne_of_gt card_pos instance [Nonempty Ξ±] : NeZero (card Ξ±) := ⟨card_ne_zero⟩ theorem existsUnique_iff_card_one {Ξ±} [Fintype Ξ±] (p : Ξ± β†’ Prop) [DecidablePred p] : (βˆƒ! a : Ξ±, p a) ↔ #{x | p x} = 1 := by rw [Finset.card_eq_one] refine exists_congr fun x => ?_ simp only [forall_true_left, Subset.antisymm_iff, subset_singleton_iff', singleton_subset_iff, true_and, and_comm, mem_univ, mem_filter] @[deprecated (since := "2024-12-17")] alias exists_unique_iff_card_one := existsUnique_iff_card_one nonrec theorem two_lt_card_iff : 2 < card Ξ± ↔ βˆƒ a b c : Ξ±, a β‰  b ∧ a β‰  c ∧ b β‰  c := by simp_rw [← Finset.card_univ, two_lt_card_iff, mem_univ, true_and] theorem card_of_bijective {f : Ξ± β†’ Ξ²} (hf : Bijective f) : card Ξ± = card Ξ² := card_congr (Equiv.ofBijective f hf) end Fintype namespace Finite variable [Finite Ξ±]
theorem surjective_of_injective {f : Ξ± β†’ Ξ±} (hinj : Injective f) : Surjective f := by intro x have := Classical.propDecidable
Mathlib/Data/Fintype/Card.lean
301
303
/- 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.Algebra.Module.LinearMap.End import Mathlib.Algebra.Module.Submodule.Defs import Mathlib.Algebra.BigOperators.Group.Finset.Defs /-! # Linear maps involving submodules of a module In this file we define a number of linear maps involving submodules of a module. ## Main declarations * `Submodule.subtype`: Embedding of a submodule `p` to the ambient space `M` as a `Submodule`. * `LinearMap.domRestrict`: The restriction of a semilinear map `f : M β†’ Mβ‚‚` to a submodule `p βŠ† M` as a semilinear map `p β†’ Mβ‚‚`. * `LinearMap.restrict`: The restriction of a linear map `f : M β†’ M₁` to a submodule `p βŠ† M` and `q βŠ† M₁` (if `q` contains the codomain). * `Submodule.inclusion`: the inclusion `p βŠ† p'` of submodules `p` and `p'` as a linear map. ## Tags submodule, subspace, linear map -/ open Function Set universe u'' u' u v w section variable {G : Type u''} {S : Type u'} {R : Type u} {M : Type v} {ΞΉ : Type w} namespace SMulMemClass variable [Semiring R] [AddCommMonoid M] [Module R M] {A : Type*} [SetLike A M] [AddSubmonoidClass A M] [SMulMemClass A R M] (S' : A) /-- The natural `R`-linear map from a submodule of an `R`-module `M` to `M`. -/ protected def subtype : S' β†’β‚—[R] M where toFun := Subtype.val map_add' _ _ := rfl map_smul' _ _ := rfl variable {S'} in @[simp] lemma subtype_apply (x : S') : SMulMemClass.subtype S' x = x := rfl lemma subtype_injective : Function.Injective (SMulMemClass.subtype S') := Subtype.coe_injective @[simp] protected theorem coe_subtype : (SMulMemClass.subtype S' : S' β†’ M) = Subtype.val := rfl @[deprecated (since := "2025-02-18")] protected alias coeSubtype := SMulMemClass.coe_subtype end SMulMemClass namespace Submodule section AddCommMonoid variable [Semiring R] [AddCommMonoid M] -- We can infer the module structure implicitly from the bundled submodule, -- rather than via typeclass resolution. variable {module_M : Module R M} variable {p q : Submodule R M} variable {r : R} {x y : M} variable (p) /-- Embedding of a submodule `p` to the ambient space `M`. -/ protected def subtype : p β†’β‚—[R] M where toFun := Subtype.val map_add' := by simp [coe_smul] map_smul' := by simp [coe_smul] variable {p} in @[simp] theorem subtype_apply (x : p) : p.subtype x = x := rfl lemma subtype_injective : Function.Injective p.subtype := Subtype.coe_injective @[simp] theorem coe_subtype : (Submodule.subtype p : p β†’ M) = Subtype.val := rfl theorem injective_subtype : Injective p.subtype := Subtype.coe_injective /-- Note the `AddSubmonoid` version of this lemma is called `AddSubmonoid.coe_finset_sum`. -/ theorem coe_sum (x : ΞΉ β†’ p) (s : Finset ΞΉ) : ↑(βˆ‘ i ∈ s, x i) = βˆ‘ i ∈ s, (x i : M) := map_sum p.subtype _ _ section AddAction variable {Ξ± Ξ² : Type*} /-- The action by a submodule is the action by the underlying module. -/ instance [AddAction M Ξ±] : AddAction p Ξ± := AddAction.compHom _ p.subtype.toAddMonoidHom end AddAction end AddCommMonoid end Submodule end section variable {R : Type*} {R₁ : Type*} {Rβ‚‚ : Type*} {R₃ : Type*} variable {M : Type*} {M₁ : Type*} {Mβ‚‚ : Type*} {M₃ : Type*} variable {ΞΉ : Type*} namespace LinearMap section AddCommMonoid variable [Semiring R] [Semiring Rβ‚‚] [Semiring R₃] variable [AddCommMonoid M] [AddCommMonoid M₁] [AddCommMonoid Mβ‚‚] [AddCommMonoid M₃] variable [Module R M] [Module R M₁] [Module Rβ‚‚ Mβ‚‚] [Module R₃ M₃] variable {σ₁₂ : R β†’+* Rβ‚‚} {σ₂₃ : Rβ‚‚ β†’+* R₃} {σ₁₃ : R β†’+* R₃} [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] variable (f : M β†’β‚›β‚—[σ₁₂] Mβ‚‚) (g : Mβ‚‚ β†’β‚›β‚—[σ₂₃] M₃) /-- The restriction of a linear map `f : M β†’ Mβ‚‚` to a submodule `p βŠ† M` gives a linear map `p β†’ Mβ‚‚`. -/ def domRestrict (f : M β†’β‚›β‚—[σ₁₂] Mβ‚‚) (p : Submodule R M) : p β†’β‚›β‚—[σ₁₂] Mβ‚‚ := f.comp p.subtype @[simp] theorem domRestrict_apply (f : M β†’β‚›β‚—[σ₁₂] Mβ‚‚) (p : Submodule R M) (x : p) : f.domRestrict p x = f x := rfl /-- A linear map `f : Mβ‚‚ β†’ M` whose values lie in a submodule `p βŠ† M` can be restricted to a linear map Mβ‚‚ β†’ p. See also `LinearMap.codLift`. -/ def codRestrict (p : Submodule Rβ‚‚ Mβ‚‚) (f : M β†’β‚›β‚—[σ₁₂] Mβ‚‚) (h : βˆ€ c, f c ∈ p) : M β†’β‚›β‚—[σ₁₂] p where toFun c := ⟨f c, h c⟩ map_add' _ _ := by simp map_smul' _ _ := by simp @[simp] theorem codRestrict_apply (p : Submodule Rβ‚‚ Mβ‚‚) (f : M β†’β‚›β‚—[σ₁₂] Mβ‚‚) {h} (x : M) : (codRestrict p f h x : Mβ‚‚) = f x := rfl @[simp] theorem comp_codRestrict (p : Submodule R₃ M₃) (h : βˆ€ b, g b ∈ p) : ((codRestrict p g h).comp f : M β†’β‚›β‚—[σ₁₃] p) = codRestrict p (g.comp f) fun _ => h _ := ext fun _ => rfl @[simp] theorem subtype_comp_codRestrict (p : Submodule Rβ‚‚ Mβ‚‚) (h : βˆ€ b, f b ∈ p) : p.subtype.comp (codRestrict p f h) = f := ext fun _ => rfl section variable {Mβ‚‚' : Type*} [AddCommMonoid Mβ‚‚'] [Module Rβ‚‚ Mβ‚‚'] (p : Mβ‚‚' β†’β‚—[Rβ‚‚] Mβ‚‚) (hp : Injective p) (h : βˆ€ c, f c ∈ range p) /-- A linear map `f : M β†’ Mβ‚‚` whose values lie in the image of an injective linear map `p : Mβ‚‚' β†’ Mβ‚‚` admits a unique lift to a linear map `M β†’ Mβ‚‚'`. -/ noncomputable def codLift : M β†’β‚›β‚—[σ₁₂] Mβ‚‚' where toFun c := (h c).choose map_add' b c := by apply hp; simp_rw [map_add, (h _).choose_spec, ← map_add, (h _).choose_spec] map_smul' r c := by apply hp; simp_rw [map_smul, (h _).choose_spec, LinearMap.map_smulβ‚›β‚—] @[simp] theorem codLift_apply (x : M) : (f.codLift p hp h x) = (h x).choose := rfl @[simp] theorem comp_codLift : p.comp (f.codLift p hp h) = f := by ext x rw [comp_apply, codLift_apply, (h x).choose_spec] end /-- Restrict domain and codomain of a linear map. -/ def restrict (f : M β†’β‚—[R] M₁) {p : Submodule R M} {q : Submodule R M₁} (hf : βˆ€ x ∈ p, f x ∈ q) : p β†’β‚—[R] q := (f.domRestrict p).codRestrict q <| SetLike.forall.2 hf @[simp] theorem restrict_coe_apply (f : M β†’β‚—[R] M₁) {p : Submodule R M} {q : Submodule R M₁} (hf : βˆ€ x ∈ p, f x ∈ q) (x : p) : ↑(f.restrict hf x) = f x := rfl theorem restrict_apply {f : M β†’β‚—[R] M₁} {p : Submodule R M} {q : Submodule R M₁} (hf : βˆ€ x ∈ p, f x ∈ q) (x : p) : f.restrict hf x = ⟨f x, hf x.1 x.2⟩ := rfl lemma restrict_sub {R M M₁ : Type*} [Ring R] [AddCommGroup M] [AddCommGroup M₁] [Module R M] [Module R M₁] {p : Submodule R M} {q : Submodule R M₁} {f g : M β†’β‚—[R] M₁} (hf : MapsTo f p q) (hg : MapsTo g p q) (hfg : MapsTo (f - g) p q := fun _ hx ↦ q.sub_mem (hf hx) (hg hx)) : f.restrict hf - g.restrict hg = (f - g).restrict hfg := by ext; simp lemma restrict_comp {Mβ‚‚ M₃ : Type*} [AddCommMonoid Mβ‚‚] [AddCommMonoid M₃] [Module R Mβ‚‚] [Module R M₃] {p : Submodule R M} {pβ‚‚ : Submodule R Mβ‚‚} {p₃ : Submodule R M₃} {f : M β†’β‚—[R] Mβ‚‚} {g : Mβ‚‚ β†’β‚—[R] M₃} (hf : MapsTo f p pβ‚‚) (hg : MapsTo g pβ‚‚ p₃) (hfg : MapsTo (g βˆ˜β‚— f) p p₃ := hg.comp hf) : (g βˆ˜β‚— f).restrict hfg = (g.restrict hg) βˆ˜β‚— (f.restrict hf) := rfl -- TODO Consider defining `Algebra R (p.compatibleMaps p)`, `AlgHom` version of `LinearMap.restrict` lemma restrict_smul_one {R M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] {p : Submodule R M} (ΞΌ : R) (h : βˆ€ x ∈ p, (ΞΌ β€’ (1 : Module.End R M)) x ∈ p := fun _ ↦ p.smul_mem ΞΌ) : (ΞΌ β€’ 1 : Module.End R M).restrict h = ΞΌ β€’ (1 : Module.End R p) := rfl lemma restrict_commute {f g : M β†’β‚—[R] M} (h : Commute f g) {p : Submodule R M} (hf : MapsTo f p p) (hg : MapsTo g p p) : Commute (f.restrict hf) (g.restrict hg) := by change (f βˆ˜β‚— g).restrict (hf.comp hg) = (g βˆ˜β‚— f).restrict (hg.comp hf) congr 1 theorem subtype_comp_restrict {f : M β†’β‚—[R] M₁} {p : Submodule R M} {q : Submodule R M₁} (hf : βˆ€ x ∈ p, f x ∈ q) : q.subtype.comp (f.restrict hf) = f.domRestrict p := rfl theorem restrict_eq_codRestrict_domRestrict {f : M β†’β‚—[R] M₁} {p : Submodule R M} {q : Submodule R M₁} (hf : βˆ€ x ∈ p, f x ∈ q) : f.restrict hf = (f.domRestrict p).codRestrict q fun x => hf x.1 x.2 := rfl theorem restrict_eq_domRestrict_codRestrict {f : M β†’β‚—[R] M₁} {p : Submodule R M} {q : Submodule R M₁} (hf : βˆ€ x, f x ∈ q) : (f.restrict fun x _ => hf x) = (f.codRestrict q hf).domRestrict p := rfl theorem sum_apply (t : Finset ΞΉ) (f : ΞΉ β†’ M β†’β‚›β‚—[σ₁₂] Mβ‚‚) (b : M) : (βˆ‘ d ∈ t, f d) b = βˆ‘ d ∈ t, f d b := _root_.map_sum ((AddMonoidHom.eval b).comp toAddMonoidHom') f _ @[simp, norm_cast] theorem coeFn_sum {ΞΉ : Type*} (t : Finset ΞΉ) (f : ΞΉ β†’ M β†’β‚›β‚—[σ₁₂] Mβ‚‚) : ⇑(βˆ‘ i ∈ t, f i) = βˆ‘ i ∈ t, (f i : M β†’ Mβ‚‚) :=
_root_.map_sum (show AddMonoidHom (M β†’β‚›β‚—[σ₁₂] Mβ‚‚) (M β†’ Mβ‚‚) from { toFun := DFunLike.coe, map_zero' := rfl map_add' := fun _ _ => rfl }) _ _
Mathlib/Algebra/Module/Submodule/LinearMap.lean
263
268
/- Copyright (c) 2017 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Tim Baumann, Stephen Morgan, Kim Morrison, Floris van Doorn -/ import Mathlib.CategoryTheory.Functor.FullyFaithful import Mathlib.CategoryTheory.ObjectProperty.FullSubcategory import Mathlib.CategoryTheory.Whiskering import Mathlib.CategoryTheory.EssentialImage import Mathlib.Tactic.CategoryTheory.Slice /-! # Equivalence of categories An equivalence of categories `C` and `D` is a pair of functors `F : C β₯€ D` and `G : D β₯€ C` such that `Ξ· : 𝟭 C β‰… F β‹™ G` and `Ξ΅ : G β‹™ F β‰… 𝟭 D`. In many situations, equivalences are a better notion of "sameness" of categories than the stricter isomorphism of categories. Recall that one way to express that two functors `F : C β₯€ D` and `G : D β₯€ C` are adjoint is using two natural transformations `Ξ· : 𝟭 C ⟢ F β‹™ G` and `Ξ΅ : G β‹™ F ⟢ 𝟭 D`, called the unit and the counit, such that the compositions `F ⟢ FGF ⟢ F` and `G ⟢ GFG ⟢ G` are the identity. Unfortunately, it is not the case that the natural isomorphisms `Ξ·` and `Ξ΅` in the definition of an equivalence automatically give an adjunction. However, it is true that * if one of the two compositions is the identity, then so is the other, and * given an equivalence of categories, it is always possible to refine `Ξ·` in such a way that the identities are satisfied. For this reason, in mathlib we define an equivalence to be a "half-adjoint equivalence", which is a tuple `(F, G, Ξ·, Ξ΅)` as in the first paragraph such that the composite `F ⟢ FGF ⟢ F` is the identity. By the remark above, this already implies that the tuple is an "adjoint equivalence", i.e., that the composite `G ⟢ GFG ⟢ G` is also the identity. We also define essentially surjective functors and show that a functor is an equivalence if and only if it is full, faithful and essentially surjective. ## Main definitions * `Equivalence`: bundled (half-)adjoint equivalences of categories * `Functor.EssSurj`: type class on a functor `F` containing the data of the preimages and the isomorphisms `F.obj (preimage d) β‰… d`. * `Functor.IsEquivalence`: type class on a functor `F` which is full, faithful and essentially surjective. ## Main results * `Equivalence.mk`: upgrade an equivalence to a (half-)adjoint equivalence * `isEquivalence_iff_of_iso`: when `F` and `G` are isomorphic functors, `F` is an equivalence iff `G` is. * `Functor.asEquivalenceFunctor`: construction of an equivalence of categories from a functor `F` which satisfies the property `F.IsEquivalence` (i.e. `F` is full, faithful and essentially surjective). ## Notations We write `C β‰Œ D` (`\backcong`, not to be confused with `β‰…`/`\cong`) for a bundled equivalence. -/ namespace CategoryTheory open CategoryTheory.Functor NatIso Category -- declare the `v`'s first; see `CategoryTheory.Category` for an explanation universe v₁ vβ‚‚ v₃ u₁ uβ‚‚ u₃ /-- We define an equivalence as a (half)-adjoint equivalence, a pair of functors with a unit and counit which are natural isomorphisms and the triangle law `FΞ· ≫ Ξ΅F = 1`, or in other words the composite `F ⟢ FGF ⟢ F` is the identity. In `unit_inverse_comp`, we show that this is actually an adjoint equivalence, i.e., that the composite `G ⟢ GFG ⟢ G` is also the identity. The triangle equation is written as a family of equalities between morphisms, it is more complicated if we write it as an equality of natural transformations, because then we would have to insert natural transformations like `F ⟢ F1`. -/ @[ext, stacks 001J] structure Equivalence (C : Type u₁) (D : Type uβ‚‚) [Category.{v₁} C] [Category.{vβ‚‚} D] where mk' :: /-- A functor in one direction -/ functor : C β₯€ D /-- A functor in the other direction -/ inverse : D β₯€ C /-- The composition `functor β‹™ inverse` is isomorphic to the identity -/ unitIso : 𝟭 C β‰… functor β‹™ inverse /-- The composition `inverse β‹™ functor` is also isomorphic to the identity -/ counitIso : inverse β‹™ functor β‰… 𝟭 D /-- The natural isomorphisms compose to the identity. -/ functor_unitIso_comp : βˆ€ X : C, functor.map (unitIso.hom.app X) ≫ counitIso.hom.app (functor.obj X) = πŸ™ (functor.obj X) := by aesop_cat /-- We infix the usual notation for an equivalence -/ infixr:10 " β‰Œ " => Equivalence variable {C : Type u₁} [Category.{v₁} C] {D : Type uβ‚‚} [Category.{vβ‚‚} D] namespace Equivalence /-- The unit of an equivalence of categories. -/ abbrev unit (e : C β‰Œ D) : 𝟭 C ⟢ e.functor β‹™ e.inverse := e.unitIso.hom /-- The counit of an equivalence of categories. -/ abbrev counit (e : C β‰Œ D) : e.inverse β‹™ e.functor ⟢ 𝟭 D := e.counitIso.hom /-- The inverse of the unit of an equivalence of categories. -/ abbrev unitInv (e : C β‰Œ D) : e.functor β‹™ e.inverse ⟢ 𝟭 C := e.unitIso.inv /-- The inverse of the counit of an equivalence of categories. -/ abbrev counitInv (e : C β‰Œ D) : 𝟭 D ⟢ e.inverse β‹™ e.functor := e.counitIso.inv /- While these abbreviations are convenient, they also cause some trouble, preventing structure projections from unfolding. -/ @[simp] theorem Equivalence_mk'_unit (functor inverse unit_iso counit_iso f) : (⟨functor, inverse, unit_iso, counit_iso, f⟩ : C β‰Œ D).unit = unit_iso.hom := rfl @[simp] theorem Equivalence_mk'_counit (functor inverse unit_iso counit_iso f) : (⟨functor, inverse, unit_iso, counit_iso, f⟩ : C β‰Œ D).counit = counit_iso.hom := rfl @[simp] theorem Equivalence_mk'_unitInv (functor inverse unit_iso counit_iso f) : (⟨functor, inverse, unit_iso, counit_iso, f⟩ : C β‰Œ D).unitInv = unit_iso.inv := rfl @[simp] theorem Equivalence_mk'_counitInv (functor inverse unit_iso counit_iso f) : (⟨functor, inverse, unit_iso, counit_iso, f⟩ : C β‰Œ D).counitInv = counit_iso.inv := rfl @[reassoc] theorem counit_naturality (e : C β‰Œ D) {X Y : D} (f : X ⟢ Y) : e.functor.map (e.inverse.map f) ≫ e.counit.app Y = e.counit.app X ≫ f := e.counit.naturality f @[reassoc] theorem unit_naturality (e : C β‰Œ D) {X Y : C} (f : X ⟢ Y) : e.unit.app X ≫ e.inverse.map (e.functor.map f) = f ≫ e.unit.app Y := (e.unit.naturality f).symm @[reassoc] theorem counitInv_naturality (e : C β‰Œ D) {X Y : D} (f : X ⟢ Y) : e.counitInv.app X ≫ e.functor.map (e.inverse.map f) = f ≫ e.counitInv.app Y := (e.counitInv.naturality f).symm @[reassoc] theorem unitInv_naturality (e : C β‰Œ D) {X Y : C} (f : X ⟢ Y) : e.inverse.map (e.functor.map f) ≫ e.unitInv.app Y = e.unitInv.app X ≫ f := e.unitInv.naturality f @[reassoc (attr := simp)] theorem functor_unit_comp (e : C β‰Œ D) (X : C) : e.functor.map (e.unit.app X) ≫ e.counit.app (e.functor.obj X) = πŸ™ (e.functor.obj X) := e.functor_unitIso_comp X
@[reassoc (attr := simp)] theorem counitInv_functor_comp (e : C β‰Œ D) (X : C) : e.counitInv.app (e.functor.obj X) ≫ e.functor.map (e.unitInv.app X) = πŸ™ (e.functor.obj X) := by simpa using Iso.inv_eq_inv
Mathlib/CategoryTheory/Equivalence.lean
159
163
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Heather Macbeth -/ import Mathlib.Analysis.InnerProductSpace.TwoDim import Mathlib.Geometry.Euclidean.Angle.Unoriented.Basic /-! # Oriented angles. This file defines oriented angles in real inner product spaces. ## Main definitions * `Orientation.oangle` is the oriented angle between two vectors with respect to an orientation. ## Implementation notes The definitions here use the `Real.angle` type, angles modulo `2 * Ο€`. For some purposes, angles modulo `Ο€` are more convenient, because results are true for such angles with less configuration dependence. Results that are only equalities modulo `Ο€` can be represented modulo `2 * Ο€` as equalities of `(2 : β„€) β€’ ΞΈ`. ## References * Evan Chen, Euclidean Geometry in Mathematical Olympiads. -/ noncomputable section open Module Complex open scoped Real RealInnerProductSpace ComplexConjugate namespace Orientation attribute [local instance] Complex.finrank_real_complex_fact variable {V V' : Type*} variable [NormedAddCommGroup V] [NormedAddCommGroup V'] variable [InnerProductSpace ℝ V] [InnerProductSpace ℝ V'] variable [Fact (finrank ℝ V = 2)] [Fact (finrank ℝ V' = 2)] (o : Orientation ℝ V (Fin 2)) local notation "Ο‰" => o.areaForm /-- The oriented angle from `x` to `y`, modulo `2 * Ο€`. If either vector is 0, this is 0. See `InnerProductGeometry.angle` for the corresponding unoriented angle definition. -/ def oangle (x y : V) : Real.Angle := Complex.arg (o.kahler x y) /-- Oriented angles are continuous when the vectors involved are nonzero. -/ @[fun_prop] theorem continuousAt_oangle {x : V Γ— V} (hx1 : x.1 β‰  0) (hx2 : x.2 β‰  0) : ContinuousAt (fun y : V Γ— V => o.oangle y.1 y.2) x := by refine (Complex.continuousAt_arg_coe_angle ?_).comp ?_ Β· exact o.kahler_ne_zero hx1 hx2 exact ((continuous_ofReal.comp continuous_inner).add ((continuous_ofReal.comp o.areaForm'.continuousβ‚‚).mul continuous_const)).continuousAt /-- If the first vector passed to `oangle` is 0, the result is 0. -/ @[simp] theorem oangle_zero_left (x : V) : o.oangle 0 x = 0 := by simp [oangle] /-- If the second vector passed to `oangle` is 0, the result is 0. -/ @[simp] theorem oangle_zero_right (x : V) : o.oangle x 0 = 0 := by simp [oangle] /-- If the two vectors passed to `oangle` are the same, the result is 0. -/ @[simp] theorem oangle_self (x : V) : o.oangle x x = 0 := by rw [oangle, kahler_apply_self, ← ofReal_pow] convert QuotientAddGroup.mk_zero (AddSubgroup.zmultiples (2 * Ο€)) apply arg_ofReal_of_nonneg positivity /-- If the angle between two vectors is nonzero, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y β‰  0) : x β‰  0 := by rintro rfl; simp at h /-- If the angle between two vectors is nonzero, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y β‰  0) : y β‰  0 := by rintro rfl; simp at h /-- If the angle between two vectors is nonzero, the vectors are not equal. -/ theorem ne_of_oangle_ne_zero {x y : V} (h : o.oangle x y β‰  0) : x β‰  y := by rintro rfl; simp at h /-- If the angle between two vectors is `Ο€`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = Ο€) : x β‰  0 := o.left_ne_zero_of_oangle_ne_zero (h.symm β–Έ Real.Angle.pi_ne_zero : o.oangle x y β‰  0) /-- If the angle between two vectors is `Ο€`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = Ο€) : y β‰  0 := o.right_ne_zero_of_oangle_ne_zero (h.symm β–Έ Real.Angle.pi_ne_zero : o.oangle x y β‰  0) /-- If the angle between two vectors is `Ο€`, the vectors are not equal. -/ theorem ne_of_oangle_eq_pi {x y : V} (h : o.oangle x y = Ο€) : x β‰  y := o.ne_of_oangle_ne_zero (h.symm β–Έ Real.Angle.pi_ne_zero : o.oangle x y β‰  0) /-- If the angle between two vectors is `Ο€ / 2`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (Ο€ / 2 : ℝ)) : x β‰  0 := o.left_ne_zero_of_oangle_ne_zero (h.symm β–Έ Real.Angle.pi_div_two_ne_zero : o.oangle x y β‰  0) /-- If the angle between two vectors is `Ο€ / 2`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (Ο€ / 2 : ℝ)) : y β‰  0 := o.right_ne_zero_of_oangle_ne_zero (h.symm β–Έ Real.Angle.pi_div_two_ne_zero : o.oangle x y β‰  0) /-- If the angle between two vectors is `Ο€ / 2`, the vectors are not equal. -/ theorem ne_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (Ο€ / 2 : ℝ)) : x β‰  y := o.ne_of_oangle_ne_zero (h.symm β–Έ Real.Angle.pi_div_two_ne_zero : o.oangle x y β‰  0) /-- If the angle between two vectors is `-Ο€ / 2`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-Ο€ / 2 : ℝ)) : x β‰  0 := o.left_ne_zero_of_oangle_ne_zero (h.symm β–Έ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y β‰  0) /-- If the angle between two vectors is `-Ο€ / 2`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-Ο€ / 2 : ℝ)) : y β‰  0 := o.right_ne_zero_of_oangle_ne_zero (h.symm β–Έ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y β‰  0) /-- If the angle between two vectors is `-Ο€ / 2`, the vectors are not equal. -/ theorem ne_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-Ο€ / 2 : ℝ)) : x β‰  y := o.ne_of_oangle_ne_zero (h.symm β–Έ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y β‰  0) /-- If the sign of the angle between two vectors is nonzero, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign β‰  0) : x β‰  0 := o.left_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 /-- If the sign of the angle between two vectors is nonzero, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign β‰  0) : y β‰  0 := o.right_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 /-- If the sign of the angle between two vectors is nonzero, the vectors are not equal. -/ theorem ne_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign β‰  0) : x β‰  y := o.ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 /-- If the sign of the angle between two vectors is positive, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x β‰  0 := o.left_ne_zero_of_oangle_sign_ne_zero (h.symm β–Έ by decide : (o.oangle x y).sign β‰  0) /-- If the sign of the angle between two vectors is positive, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : y β‰  0 := o.right_ne_zero_of_oangle_sign_ne_zero (h.symm β–Έ by decide : (o.oangle x y).sign β‰  0) /-- If the sign of the angle between two vectors is positive, the vectors are not equal. -/ theorem ne_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x β‰  y := o.ne_of_oangle_sign_ne_zero (h.symm β–Έ by decide : (o.oangle x y).sign β‰  0) /-- If the sign of the angle between two vectors is negative, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x β‰  0 := o.left_ne_zero_of_oangle_sign_ne_zero (h.symm β–Έ by decide : (o.oangle x y).sign β‰  0) /-- If the sign of the angle between two vectors is negative, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : y β‰  0 := o.right_ne_zero_of_oangle_sign_ne_zero (h.symm β–Έ by decide : (o.oangle x y).sign β‰  0) /-- If the sign of the angle between two vectors is negative, the vectors are not equal. -/ theorem ne_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x β‰  y := o.ne_of_oangle_sign_ne_zero (h.symm β–Έ by decide : (o.oangle x y).sign β‰  0) /-- Swapping the two vectors passed to `oangle` negates the angle. -/ theorem oangle_rev (x y : V) : o.oangle y x = -o.oangle x y := by simp only [oangle, o.kahler_swap y x, Complex.arg_conj_coe_angle] /-- Adding the angles between two vectors in each order results in 0. -/ @[simp] theorem oangle_add_oangle_rev (x y : V) : o.oangle x y + o.oangle y x = 0 := by simp [o.oangle_rev y x] /-- Negating the first vector passed to `oangle` adds `Ο€` to the angle. -/ theorem oangle_neg_left {x y : V} (hx : x β‰  0) (hy : y β‰  0) : o.oangle (-x) y = o.oangle x y + Ο€ := by simp only [oangle, map_neg] convert Complex.arg_neg_coe_angle _ exact o.kahler_ne_zero hx hy /-- Negating the second vector passed to `oangle` adds `Ο€` to the angle. -/ theorem oangle_neg_right {x y : V} (hx : x β‰  0) (hy : y β‰  0) : o.oangle x (-y) = o.oangle x y + Ο€ := by simp only [oangle, map_neg] convert Complex.arg_neg_coe_angle _ exact o.kahler_ne_zero hx hy /-- Negating the first vector passed to `oangle` does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_neg_left (x y : V) : (2 : β„€) β€’ o.oangle (-x) y = (2 : β„€) β€’ o.oangle x y := by by_cases hx : x = 0 Β· simp [hx] Β· by_cases hy : y = 0 Β· simp [hy] Β· simp [o.oangle_neg_left hx hy] /-- Negating the second vector passed to `oangle` does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_neg_right (x y : V) : (2 : β„€) β€’ o.oangle x (-y) = (2 : β„€) β€’ o.oangle x y := by by_cases hx : x = 0 Β· simp [hx] Β· by_cases hy : y = 0 Β· simp [hy] Β· simp [o.oangle_neg_right hx hy] /-- Negating both vectors passed to `oangle` does not change the angle. -/ @[simp] theorem oangle_neg_neg (x y : V) : o.oangle (-x) (-y) = o.oangle x y := by simp [oangle] /-- Negating the first vector produces the same angle as negating the second vector. -/ theorem oangle_neg_left_eq_neg_right (x y : V) : o.oangle (-x) y = o.oangle x (-y) := by rw [← neg_neg y, oangle_neg_neg, neg_neg] /-- The angle between the negation of a nonzero vector and that vector is `Ο€`. -/ @[simp] theorem oangle_neg_self_left {x : V} (hx : x β‰  0) : o.oangle (-x) x = Ο€ := by simp [oangle_neg_left, hx] /-- The angle between a nonzero vector and its negation is `Ο€`. -/ @[simp] theorem oangle_neg_self_right {x : V} (hx : x β‰  0) : o.oangle x (-x) = Ο€ := by simp [oangle_neg_right, hx] /-- Twice the angle between the negation of a vector and that vector is 0. -/ theorem two_zsmul_oangle_neg_self_left (x : V) : (2 : β„€) β€’ o.oangle (-x) x = 0 := by by_cases hx : x = 0 <;> simp [hx] /-- Twice the angle between a vector and its negation is 0. -/ theorem two_zsmul_oangle_neg_self_right (x : V) : (2 : β„€) β€’ o.oangle x (-x) = 0 := by by_cases hx : x = 0 <;> simp [hx] /-- Adding the angles between two vectors in each order, with the first vector in each angle negated, results in 0. -/ @[simp] theorem oangle_add_oangle_rev_neg_left (x y : V) : o.oangle (-x) y + o.oangle (-y) x = 0 := by rw [oangle_neg_left_eq_neg_right, oangle_rev, neg_add_cancel] /-- Adding the angles between two vectors in each order, with the second vector in each angle negated, results in 0. -/ @[simp] theorem oangle_add_oangle_rev_neg_right (x y : V) : o.oangle x (-y) + o.oangle y (-x) = 0 := by rw [o.oangle_rev (-x), oangle_neg_left_eq_neg_right, add_neg_cancel] /-- Multiplying the first vector passed to `oangle` by a positive real does not change the angle. -/ @[simp] theorem oangle_smul_left_of_pos (x y : V) {r : ℝ} (hr : 0 < r) : o.oangle (r β€’ x) y = o.oangle x y := by simp [oangle, Complex.arg_real_mul _ hr] /-- Multiplying the second vector passed to `oangle` by a positive real does not change the angle. -/ @[simp] theorem oangle_smul_right_of_pos (x y : V) {r : ℝ} (hr : 0 < r) : o.oangle x (r β€’ y) = o.oangle x y := by simp [oangle, Complex.arg_real_mul _ hr] /-- Multiplying the first vector passed to `oangle` by a negative real produces the same angle as negating that vector. -/ @[simp] theorem oangle_smul_left_of_neg (x y : V) {r : ℝ} (hr : r < 0) : o.oangle (r β€’ x) y = o.oangle (-x) y := by rw [← neg_neg r, neg_smul, ← smul_neg, o.oangle_smul_left_of_pos _ _ (neg_pos_of_neg hr)] /-- Multiplying the second vector passed to `oangle` by a negative real produces the same angle as negating that vector. -/ @[simp] theorem oangle_smul_right_of_neg (x y : V) {r : ℝ} (hr : r < 0) : o.oangle x (r β€’ y) = o.oangle x (-y) := by rw [← neg_neg r, neg_smul, ← smul_neg, o.oangle_smul_right_of_pos _ _ (neg_pos_of_neg hr)] /-- The angle between a nonnegative multiple of a vector and that vector is 0. -/ @[simp] theorem oangle_smul_left_self_of_nonneg (x : V) {r : ℝ} (hr : 0 ≀ r) : o.oangle (r β€’ x) x = 0 := by rcases hr.lt_or_eq with (h | h) Β· simp [h] Β· simp [h.symm] /-- The angle between a vector and a nonnegative multiple of that vector is 0. -/ @[simp] theorem oangle_smul_right_self_of_nonneg (x : V) {r : ℝ} (hr : 0 ≀ r) : o.oangle x (r β€’ x) = 0 := by rcases hr.lt_or_eq with (h | h) Β· simp [h] Β· simp [h.symm] /-- The angle between two nonnegative multiples of the same vector is 0. -/ @[simp] theorem oangle_smul_smul_self_of_nonneg (x : V) {r₁ rβ‚‚ : ℝ} (hr₁ : 0 ≀ r₁) (hrβ‚‚ : 0 ≀ rβ‚‚) : o.oangle (r₁ β€’ x) (rβ‚‚ β€’ x) = 0 := by rcases hr₁.lt_or_eq with (h | h) Β· simp [h, hrβ‚‚] Β· simp [h.symm] /-- Multiplying the first vector passed to `oangle` by a nonzero real does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_smul_left_of_ne_zero (x y : V) {r : ℝ} (hr : r β‰  0) : (2 : β„€) β€’ o.oangle (r β€’ x) y = (2 : β„€) β€’ o.oangle x y := by rcases hr.lt_or_lt with (h | h) <;> simp [h] /-- Multiplying the second vector passed to `oangle` by a nonzero real does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_smul_right_of_ne_zero (x y : V) {r : ℝ} (hr : r β‰  0) : (2 : β„€) β€’ o.oangle x (r β€’ y) = (2 : β„€) β€’ o.oangle x y := by rcases hr.lt_or_lt with (h | h) <;> simp [h] /-- Twice the angle between a multiple of a vector and that vector is 0. -/ @[simp] theorem two_zsmul_oangle_smul_left_self (x : V) {r : ℝ} : (2 : β„€) β€’ o.oangle (r β€’ x) x = 0 := by rcases lt_or_le r 0 with (h | h) <;> simp [h] /-- Twice the angle between a vector and a multiple of that vector is 0. -/ @[simp] theorem two_zsmul_oangle_smul_right_self (x : V) {r : ℝ} : (2 : β„€) β€’ o.oangle x (r β€’ x) = 0 := by rcases lt_or_le r 0 with (h | h) <;> simp [h] /-- Twice the angle between two multiples of a vector is 0. -/ @[simp] theorem two_zsmul_oangle_smul_smul_self (x : V) {r₁ rβ‚‚ : ℝ} : (2 : β„€) β€’ o.oangle (r₁ β€’ x) (rβ‚‚ β€’ x) = 0 := by by_cases h : r₁ = 0 <;> simp [h] /-- If the spans of two vectors are equal, twice angles with those vectors on the left are equal. -/ theorem two_zsmul_oangle_left_of_span_eq {x y : V} (z : V) (h : (ℝ βˆ™ x) = ℝ βˆ™ y) : (2 : β„€) β€’ o.oangle x z = (2 : β„€) β€’ o.oangle y z := by rw [Submodule.span_singleton_eq_span_singleton] at h rcases h with ⟨r, rfl⟩ exact (o.two_zsmul_oangle_smul_left_of_ne_zero _ _ (Units.ne_zero _)).symm /-- If the spans of two vectors are equal, twice angles with those vectors on the right are equal. -/ theorem two_zsmul_oangle_right_of_span_eq (x : V) {y z : V} (h : (ℝ βˆ™ y) = ℝ βˆ™ z) : (2 : β„€) β€’ o.oangle x y = (2 : β„€) β€’ o.oangle x z := by rw [Submodule.span_singleton_eq_span_singleton] at h rcases h with ⟨r, rfl⟩ exact (o.two_zsmul_oangle_smul_right_of_ne_zero _ _ (Units.ne_zero _)).symm /-- If the spans of two pairs of vectors are equal, twice angles between those vectors are equal. -/ theorem two_zsmul_oangle_of_span_eq_of_span_eq {w x y z : V} (hwx : (ℝ βˆ™ w) = ℝ βˆ™ x) (hyz : (ℝ βˆ™ y) = ℝ βˆ™ z) : (2 : β„€) β€’ o.oangle w y = (2 : β„€) β€’ o.oangle x z := by rw [o.two_zsmul_oangle_left_of_span_eq y hwx, o.two_zsmul_oangle_right_of_span_eq x hyz] /-- The oriented angle between two vectors is zero if and only if the angle with the vectors swapped is zero. -/ theorem oangle_eq_zero_iff_oangle_rev_eq_zero {x y : V} : o.oangle x y = 0 ↔ o.oangle y x = 0 := by rw [oangle_rev, neg_eq_zero] /-- The oriented angle between two vectors is zero if and only if they are on the same ray. -/ theorem oangle_eq_zero_iff_sameRay {x y : V} : o.oangle x y = 0 ↔ SameRay ℝ x y := by rw [oangle, kahler_apply_apply, Complex.arg_coe_angle_eq_iff_eq_toReal, Real.Angle.toReal_zero, Complex.arg_eq_zero_iff] simpa using o.nonneg_inner_and_areaForm_eq_zero_iff_sameRay x y /-- The oriented angle between two vectors is `Ο€` if and only if the angle with the vectors swapped is `Ο€`. -/ theorem oangle_eq_pi_iff_oangle_rev_eq_pi {x y : V} : o.oangle x y = Ο€ ↔ o.oangle y x = Ο€ := by rw [oangle_rev, neg_eq_iff_eq_neg, Real.Angle.neg_coe_pi] /-- The oriented angle between two vectors is `Ο€` if and only they are nonzero and the first is on the same ray as the negation of the second. -/ theorem oangle_eq_pi_iff_sameRay_neg {x y : V} : o.oangle x y = Ο€ ↔ x β‰  0 ∧ y β‰  0 ∧ SameRay ℝ x (-y) := by rw [← o.oangle_eq_zero_iff_sameRay] constructor Β· intro h by_cases hx : x = 0; Β· simp [hx, Real.Angle.pi_ne_zero.symm] at h by_cases hy : y = 0; Β· simp [hy, Real.Angle.pi_ne_zero.symm] at h refine ⟨hx, hy, ?_⟩ rw [o.oangle_neg_right hx hy, h, Real.Angle.coe_pi_add_coe_pi] Β· rintro ⟨hx, hy, h⟩ rwa [o.oangle_neg_right hx hy, ← Real.Angle.sub_coe_pi_eq_add_coe_pi, sub_eq_zero] at h /-- The oriented angle between two vectors is zero or `Ο€` if and only if those two vectors are not linearly independent. -/ theorem oangle_eq_zero_or_eq_pi_iff_not_linearIndependent {x y : V} : o.oangle x y = 0 ∨ o.oangle x y = Ο€ ↔ Β¬LinearIndependent ℝ ![x, y] := by rw [oangle_eq_zero_iff_sameRay, oangle_eq_pi_iff_sameRay_neg, sameRay_or_ne_zero_and_sameRay_neg_iff_not_linearIndependent] /-- The oriented angle between two vectors is zero or `Ο€` if and only if the first vector is zero or the second is a multiple of the first. -/ theorem oangle_eq_zero_or_eq_pi_iff_right_eq_smul {x y : V} : o.oangle x y = 0 ∨ o.oangle x y = Ο€ ↔ x = 0 ∨ βˆƒ r : ℝ, y = r β€’ x := by rw [oangle_eq_zero_iff_sameRay, oangle_eq_pi_iff_sameRay_neg] refine ⟨fun h => ?_, fun h => ?_⟩ Β· rcases h with (h | ⟨-, -, h⟩) Β· by_cases hx : x = 0; Β· simp [hx] obtain ⟨r, -, rfl⟩ := h.exists_nonneg_left hx exact Or.inr ⟨r, rfl⟩ Β· by_cases hx : x = 0; Β· simp [hx] obtain ⟨r, -, hy⟩ := h.exists_nonneg_left hx refine Or.inr ⟨-r, ?_⟩ simp [hy] Β· rcases h with (rfl | ⟨r, rfl⟩); Β· simp by_cases hx : x = 0; Β· simp [hx] rcases lt_trichotomy r 0 with (hr | hr | hr) Β· rw [← neg_smul] exact Or.inr ⟨hx, smul_ne_zero hr.ne hx, SameRay.sameRay_pos_smul_right x (Left.neg_pos_iff.2 hr)⟩ Β· simp [hr] Β· exact Or.inl (SameRay.sameRay_pos_smul_right x hr) /-- The oriented angle between two vectors is not zero or `Ο€` if and only if those two vectors are linearly independent. -/ theorem oangle_ne_zero_and_ne_pi_iff_linearIndependent {x y : V} : o.oangle x y β‰  0 ∧ o.oangle x y β‰  Ο€ ↔ LinearIndependent ℝ ![x, y] := by rw [← not_or, ← not_iff_not, Classical.not_not, oangle_eq_zero_or_eq_pi_iff_not_linearIndependent] /-- Two vectors are equal if and only if they have equal norms and zero angle between them. -/ theorem eq_iff_norm_eq_and_oangle_eq_zero (x y : V) : x = y ↔ β€–xβ€– = β€–yβ€– ∧ o.oangle x y = 0 := by rw [oangle_eq_zero_iff_sameRay] constructor Β· rintro rfl simp; rfl Β· rcases eq_or_ne y 0 with (rfl | hy) Β· simp rintro ⟨h₁, hβ‚‚βŸ© obtain ⟨r, hr, rfl⟩ := hβ‚‚.exists_nonneg_right hy have : β€–yβ€– β‰  0 := by simpa using hy obtain rfl : r = 1 := by apply mul_right_cancelβ‚€ this simpa [norm_smul, abs_of_nonneg hr] using h₁ simp /-- Two vectors with equal norms are equal if and only if they have zero angle between them. -/ theorem eq_iff_oangle_eq_zero_of_norm_eq {x y : V} (h : β€–xβ€– = β€–yβ€–) : x = y ↔ o.oangle x y = 0 := ⟨fun he => ((o.eq_iff_norm_eq_and_oangle_eq_zero x y).1 he).2, fun ha => (o.eq_iff_norm_eq_and_oangle_eq_zero x y).2 ⟨h, ha⟩⟩ /-- Two vectors with zero angle between them are equal if and only if they have equal norms. -/ theorem eq_iff_norm_eq_of_oangle_eq_zero {x y : V} (h : o.oangle x y = 0) : x = y ↔ β€–xβ€– = β€–yβ€– := ⟨fun he => ((o.eq_iff_norm_eq_and_oangle_eq_zero x y).1 he).1, fun hn => (o.eq_iff_norm_eq_and_oangle_eq_zero x y).2 ⟨hn, h⟩⟩ /-- Given three nonzero vectors, the angle between the first and the second plus the angle between the second and the third equals the angle between the first and the third. -/ @[simp] theorem oangle_add {x y z : V} (hx : x β‰  0) (hy : y β‰  0) (hz : z β‰  0) : o.oangle x y + o.oangle y z = o.oangle x z := by simp_rw [oangle] rw [← Complex.arg_mul_coe_angle, o.kahler_mul y x z] Β· congr 1 exact mod_cast Complex.arg_real_mul _ (by positivity : 0 < β€–yβ€– ^ 2) Β· exact o.kahler_ne_zero hx hy Β· exact o.kahler_ne_zero hy hz /-- Given three nonzero vectors, the angle between the second and the third plus the angle between the first and the second equals the angle between the first and the third. -/ @[simp] theorem oangle_add_swap {x y z : V} (hx : x β‰  0) (hy : y β‰  0) (hz : z β‰  0) : o.oangle y z + o.oangle x y = o.oangle x z := by rw [add_comm, o.oangle_add hx hy hz] /-- Given three nonzero vectors, the angle between the first and the third minus the angle between the first and the second equals the angle between the second and the third. -/ @[simp] theorem oangle_sub_left {x y z : V} (hx : x β‰  0) (hy : y β‰  0) (hz : z β‰  0) : o.oangle x z - o.oangle x y = o.oangle y z := by rw [sub_eq_iff_eq_add, o.oangle_add_swap hx hy hz] /-- Given three nonzero vectors, the angle between the first and the third minus the angle between the second and the third equals the angle between the first and the second. -/ @[simp] theorem oangle_sub_right {x y z : V} (hx : x β‰  0) (hy : y β‰  0) (hz : z β‰  0) : o.oangle x z - o.oangle y z = o.oangle x y := by rw [sub_eq_iff_eq_add, o.oangle_add hx hy hz] /-- Given three nonzero vectors, adding the angles between them in cyclic order results in 0. -/ @[simp] theorem oangle_add_cyc3 {x y z : V} (hx : x β‰  0) (hy : y β‰  0) (hz : z β‰  0) : o.oangle x y + o.oangle y z + o.oangle z x = 0 := by simp [hx, hy, hz] /-- Given three nonzero vectors, adding the angles between them in cyclic order, with the first vector in each angle negated, results in Ο€. If the vectors add to 0, this is a version of the sum of the angles of a triangle. -/ @[simp] theorem oangle_add_cyc3_neg_left {x y z : V} (hx : x β‰  0) (hy : y β‰  0) (hz : z β‰  0) : o.oangle (-x) y + o.oangle (-y) z + o.oangle (-z) x = Ο€ := by rw [o.oangle_neg_left hx hy, o.oangle_neg_left hy hz, o.oangle_neg_left hz hx, show o.oangle x y + Ο€ + (o.oangle y z + Ο€) + (o.oangle z x + Ο€) = o.oangle x y + o.oangle y z + o.oangle z x + (Ο€ + Ο€ + Ο€ : Real.Angle) by abel, o.oangle_add_cyc3 hx hy hz, Real.Angle.coe_pi_add_coe_pi, zero_add, zero_add] /-- Given three nonzero vectors, adding the angles between them in cyclic order, with the second vector in each angle negated, results in Ο€. If the vectors add to 0, this is a version of the sum of the angles of a triangle. -/ @[simp] theorem oangle_add_cyc3_neg_right {x y z : V} (hx : x β‰  0) (hy : y β‰  0) (hz : z β‰  0) : o.oangle x (-y) + o.oangle y (-z) + o.oangle z (-x) = Ο€ := by simp_rw [← oangle_neg_left_eq_neg_right, o.oangle_add_cyc3_neg_left hx hy hz] /-- Pons asinorum, oriented vector angle form. -/ theorem oangle_sub_eq_oangle_sub_rev_of_norm_eq {x y : V} (h : β€–xβ€– = β€–yβ€–) : o.oangle x (x - y) = o.oangle (y - x) y := by simp [oangle, h] /-- The angle at the apex of an isosceles triangle is `Ο€` minus twice a base angle, oriented vector angle form. -/ theorem oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq {x y : V} (hn : x β‰  y) (h : β€–xβ€– = β€–yβ€–) : o.oangle y x = Ο€ - (2 : β„€) β€’ o.oangle (y - x) y := by rw [two_zsmul] nth_rw 1 [← o.oangle_sub_eq_oangle_sub_rev_of_norm_eq h] rw [eq_sub_iff_add_eq, ← oangle_neg_neg, ← add_assoc] have hy : y β‰  0 := by rintro rfl rw [norm_zero, norm_eq_zero] at h exact hn h have hx : x β‰  0 := norm_ne_zero_iff.1 (h.symm β–Έ norm_ne_zero_iff.2 hy) convert o.oangle_add_cyc3_neg_right (neg_ne_zero.2 hy) hx (sub_ne_zero_of_ne hn.symm) using 1 simp /-- The angle between two vectors, with respect to an orientation given by `Orientation.map` with a linear isometric equivalence, equals the angle between those two vectors, transformed by the inverse of that equivalence, with respect to the original orientation. -/ @[simp] theorem oangle_map (x y : V') (f : V ≃ₗᡒ[ℝ] V') : (Orientation.map (Fin 2) f.toLinearEquiv o).oangle x y = o.oangle (f.symm x) (f.symm y) := by simp [oangle, o.kahler_map] @[simp] protected theorem _root_.Complex.oangle (w z : β„‚) : Complex.orientation.oangle w z = Complex.arg (conj w * z) := by simp [oangle, mul_comm z] /-- The oriented angle on an oriented real inner product space of dimension 2 can be evaluated in terms of a complex-number representation of the space. -/ theorem oangle_map_complex (f : V ≃ₗᡒ[ℝ] β„‚) (hf : Orientation.map (Fin 2) f.toLinearEquiv o = Complex.orientation) (x y : V) : o.oangle x y = Complex.arg (conj (f x) * f y) := by rw [← Complex.oangle, ← hf, o.oangle_map] iterate 2 rw [LinearIsometryEquiv.symm_apply_apply] /-- Negating the orientation negates the value of `oangle`. -/ theorem oangle_neg_orientation_eq_neg (x y : V) : (-o).oangle x y = -o.oangle x y := by simp [oangle] /-- The inner product of two vectors is the product of the norms and the cosine of the oriented angle between the vectors. -/ theorem inner_eq_norm_mul_norm_mul_cos_oangle (x y : V) : βŸͺx, y⟫ = β€–xβ€– * β€–yβ€– * Real.Angle.cos (o.oangle x y) := by by_cases hx : x = 0; Β· simp [hx] by_cases hy : y = 0; Β· simp [hy] rw [oangle, Real.Angle.cos_coe, Complex.cos_arg, o.norm_kahler] Β· simp only [kahler_apply_apply, real_smul, add_re, ofReal_re, mul_re, I_re, ofReal_im] field_simp Β· exact o.kahler_ne_zero hx hy /-- The cosine of the oriented angle between two nonzero vectors is the inner product divided by the product of the norms. -/ theorem cos_oangle_eq_inner_div_norm_mul_norm {x y : V} (hx : x β‰  0) (hy : y β‰  0) : Real.Angle.cos (o.oangle x y) = βŸͺx, y⟫ / (β€–xβ€– * β€–yβ€–) := by rw [o.inner_eq_norm_mul_norm_mul_cos_oangle] field_simp [norm_ne_zero_iff.2 hx, norm_ne_zero_iff.2 hy] /-- The cosine of the oriented angle between two nonzero vectors equals that of the unoriented angle. -/ theorem cos_oangle_eq_cos_angle {x y : V} (hx : x β‰  0) (hy : y β‰  0) : Real.Angle.cos (o.oangle x y) = Real.cos (InnerProductGeometry.angle x y) := by rw [o.cos_oangle_eq_inner_div_norm_mul_norm hx hy, InnerProductGeometry.cos_angle] /-- The oriented angle between two nonzero vectors is plus or minus the unoriented angle. -/ theorem oangle_eq_angle_or_eq_neg_angle {x y : V} (hx : x β‰  0) (hy : y β‰  0) : o.oangle x y = InnerProductGeometry.angle x y ∨ o.oangle x y = -InnerProductGeometry.angle x y := Real.Angle.cos_eq_real_cos_iff_eq_or_eq_neg.1 <| o.cos_oangle_eq_cos_angle hx hy /-- The unoriented angle between two nonzero vectors is the absolute value of the oriented angle, converted to a real. -/ theorem angle_eq_abs_oangle_toReal {x y : V} (hx : x β‰  0) (hy : y β‰  0) : InnerProductGeometry.angle x y = |(o.oangle x y).toReal| := by have h0 := InnerProductGeometry.angle_nonneg x y have hpi := InnerProductGeometry.angle_le_pi x y rcases o.oangle_eq_angle_or_eq_neg_angle hx hy with (h | h) Β· rw [h, eq_comm, Real.Angle.abs_toReal_coe_eq_self_iff] exact ⟨h0, hpi⟩ Β· rw [h, eq_comm, Real.Angle.abs_toReal_neg_coe_eq_self_iff] exact ⟨h0, hpi⟩ /-- If the sign of the oriented angle between two vectors is zero, either one of the vectors is zero or the unoriented angle is 0 or Ο€. -/ theorem eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero {x y : V} (h : (o.oangle x y).sign = 0) : x = 0 ∨ y = 0 ∨ InnerProductGeometry.angle x y = 0 ∨ InnerProductGeometry.angle x y = Ο€ := by by_cases hx : x = 0; Β· simp [hx] by_cases hy : y = 0; Β· simp [hy] rw [o.angle_eq_abs_oangle_toReal hx hy] rw [Real.Angle.sign_eq_zero_iff] at h rcases h with (h | h) <;> simp [h, Real.pi_pos.le] /-- If two unoriented angles are equal, and the signs of the corresponding oriented angles are equal, then the oriented angles are equal (even in degenerate cases). -/ theorem oangle_eq_of_angle_eq_of_sign_eq {w x y z : V} (h : InnerProductGeometry.angle w x = InnerProductGeometry.angle y z) (hs : (o.oangle w x).sign = (o.oangle y z).sign) : o.oangle w x = o.oangle y z := by by_cases h0 : (w = 0 ∨ x = 0) ∨ y = 0 ∨ z = 0 Β· have hs' : (o.oangle w x).sign = 0 ∧ (o.oangle y z).sign = 0 := by rcases h0 with ((rfl | rfl) | rfl | rfl) Β· simpa using hs.symm Β· simpa using hs.symm Β· simpa using hs Β· simpa using hs rcases hs' with ⟨hswx, hsyz⟩ have h' : InnerProductGeometry.angle w x = Ο€ / 2 ∧ InnerProductGeometry.angle y z = Ο€ / 2 := by rcases h0 with ((rfl | rfl) | rfl | rfl) Β· simpa using h.symm Β· simpa using h.symm Β· simpa using h Β· simpa using h rcases h' with ⟨hwx, hyz⟩ have hpi : Ο€ / 2 β‰  Ο€ := by intro hpi rw [div_eq_iff, eq_comm, ← sub_eq_zero, mul_two, add_sub_cancel_right] at hpi Β· exact Real.pi_pos.ne.symm hpi Β· exact two_ne_zero have h0wx : w = 0 ∨ x = 0 := by have h0' := o.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero hswx simpa [hwx, Real.pi_pos.ne.symm, hpi] using h0' have h0yz : y = 0 ∨ z = 0 := by have h0' := o.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero hsyz simpa [hyz, Real.pi_pos.ne.symm, hpi] using h0' rcases h0wx with (h0wx | h0wx) <;> rcases h0yz with (h0yz | h0yz) <;> simp [h0wx, h0yz] Β· push_neg at h0 rw [Real.Angle.eq_iff_abs_toReal_eq_of_sign_eq hs] rwa [o.angle_eq_abs_oangle_toReal h0.1.1 h0.1.2, o.angle_eq_abs_oangle_toReal h0.2.1 h0.2.2] at h /-- If the signs of two oriented angles between nonzero vectors are equal, the oriented angles are equal if and only if the unoriented angles are equal. -/ theorem angle_eq_iff_oangle_eq_of_sign_eq {w x y z : V} (hw : w β‰  0) (hx : x β‰  0) (hy : y β‰  0) (hz : z β‰  0) (hs : (o.oangle w x).sign = (o.oangle y z).sign) : InnerProductGeometry.angle w x = InnerProductGeometry.angle y z ↔ o.oangle w x = o.oangle y z := by refine ⟨fun h => o.oangle_eq_of_angle_eq_of_sign_eq h hs, fun h => ?_⟩ rw [o.angle_eq_abs_oangle_toReal hw hx, o.angle_eq_abs_oangle_toReal hy hz, h] /-- The oriented angle between two vectors equals the unoriented angle if the sign is positive. -/ theorem oangle_eq_angle_of_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : o.oangle x y = InnerProductGeometry.angle x y := by by_cases hx : x = 0; Β· exfalso; simp [hx] at h by_cases hy : y = 0; Β· exfalso; simp [hy] at h refine (o.oangle_eq_angle_or_eq_neg_angle hx hy).resolve_right ?_ intro hxy rw [hxy, Real.Angle.sign_neg, neg_eq_iff_eq_neg, ← SignType.neg_iff, ← not_le] at h exact h (Real.Angle.sign_coe_nonneg_of_nonneg_of_le_pi (InnerProductGeometry.angle_nonneg _ _) (InnerProductGeometry.angle_le_pi _ _)) /-- The oriented angle between two vectors equals minus the unoriented angle if the sign is negative. -/ theorem oangle_eq_neg_angle_of_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : o.oangle x y = -InnerProductGeometry.angle x y := by by_cases hx : x = 0; Β· exfalso; simp [hx] at h by_cases hy : y = 0; Β· exfalso; simp [hy] at h refine (o.oangle_eq_angle_or_eq_neg_angle hx hy).resolve_left ?_ intro hxy rw [hxy, ← SignType.neg_iff, ← not_le] at h exact h (Real.Angle.sign_coe_nonneg_of_nonneg_of_le_pi (InnerProductGeometry.angle_nonneg _ _) (InnerProductGeometry.angle_le_pi _ _)) /-- The oriented angle between two nonzero vectors is zero if and only if the unoriented angle is zero. -/ theorem oangle_eq_zero_iff_angle_eq_zero {x y : V} (hx : x β‰  0) (hy : y β‰  0) : o.oangle x y = 0 ↔ InnerProductGeometry.angle x y = 0 := by refine ⟨fun h => ?_, fun h => ?_⟩ Β· simpa [o.angle_eq_abs_oangle_toReal hx hy] Β· have ha := o.oangle_eq_angle_or_eq_neg_angle hx hy rw [h] at ha simpa using ha /-- The oriented angle between two vectors is `Ο€` if and only if the unoriented angle is `Ο€`. -/ theorem oangle_eq_pi_iff_angle_eq_pi {x y : V} : o.oangle x y = Ο€ ↔ InnerProductGeometry.angle x y = Ο€ := by by_cases hx : x = 0 Β· simp [hx, Real.Angle.pi_ne_zero.symm, div_eq_mul_inv, mul_right_eq_selfβ‚€, not_or, Real.pi_ne_zero] by_cases hy : y = 0 Β· simp [hy, Real.Angle.pi_ne_zero.symm, div_eq_mul_inv, mul_right_eq_selfβ‚€, not_or, Real.pi_ne_zero] refine ⟨fun h => ?_, fun h => ?_⟩ Β· rw [o.angle_eq_abs_oangle_toReal hx hy, h] simp [Real.pi_pos.le] Β· have ha := o.oangle_eq_angle_or_eq_neg_angle hx hy rw [h] at ha simpa using ha /-- One of two vectors is zero or the oriented angle between them is plus or minus `Ο€ / 2` if and only if the inner product of those vectors is zero. -/ theorem eq_zero_or_oangle_eq_iff_inner_eq_zero {x y : V} : x = 0 ∨ y = 0 ∨ o.oangle x y = (Ο€ / 2 : ℝ) ∨ o.oangle x y = (-Ο€ / 2 : ℝ) ↔ βŸͺx, y⟫ = 0 := by by_cases hx : x = 0; Β· simp [hx] by_cases hy : y = 0; Β· simp [hy] rw [InnerProductGeometry.inner_eq_zero_iff_angle_eq_pi_div_two, or_iff_right hx, or_iff_right hy] refine ⟨fun h => ?_, fun h => ?_⟩ Β· rwa [o.angle_eq_abs_oangle_toReal hx hy, Real.Angle.abs_toReal_eq_pi_div_two_iff] Β· convert o.oangle_eq_angle_or_eq_neg_angle hx hy using 2 <;> rw [h] simp only [neg_div, Real.Angle.coe_neg] /-- If the oriented angle between two vectors is `Ο€ / 2`, the inner product of those vectors is zero. -/ theorem inner_eq_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (Ο€ / 2 : ℝ)) : βŸͺx, y⟫ = 0 := o.eq_zero_or_oangle_eq_iff_inner_eq_zero.1 <| Or.inr <| Or.inr <| Or.inl h /-- If the oriented angle between two vectors is `Ο€ / 2`, the inner product of those vectors (reversed) is zero. -/ theorem inner_rev_eq_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (Ο€ / 2 : ℝ)) : βŸͺy, x⟫ = 0 := by rw [real_inner_comm, o.inner_eq_zero_of_oangle_eq_pi_div_two h] /-- If the oriented angle between two vectors is `-Ο€ / 2`, the inner product of those vectors is zero. -/ theorem inner_eq_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-Ο€ / 2 : ℝ)) : βŸͺx, y⟫ = 0 := o.eq_zero_or_oangle_eq_iff_inner_eq_zero.1 <| Or.inr <| Or.inr <| Or.inr h /-- If the oriented angle between two vectors is `-Ο€ / 2`, the inner product of those vectors (reversed) is zero. -/ theorem inner_rev_eq_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-Ο€ / 2 : ℝ)) : βŸͺy, x⟫ = 0 := by rw [real_inner_comm, o.inner_eq_zero_of_oangle_eq_neg_pi_div_two h] /-- Negating the first vector passed to `oangle` negates the sign of the angle. -/ @[simp] theorem oangle_sign_neg_left (x y : V) : (o.oangle (-x) y).sign = -(o.oangle x y).sign := by by_cases hx : x = 0; Β· simp [hx] by_cases hy : y = 0; Β· simp [hy] rw [o.oangle_neg_left hx hy, Real.Angle.sign_add_pi] /-- Negating the second vector passed to `oangle` negates the sign of the angle. -/ @[simp] theorem oangle_sign_neg_right (x y : V) : (o.oangle x (-y)).sign = -(o.oangle x y).sign := by by_cases hx : x = 0; Β· simp [hx] by_cases hy : y = 0; Β· simp [hy] rw [o.oangle_neg_right hx hy, Real.Angle.sign_add_pi] /-- Multiplying the first vector passed to `oangle` by a real multiplies the sign of the angle by the sign of the real. -/ @[simp] theorem oangle_sign_smul_left (x y : V) (r : ℝ) : (o.oangle (r β€’ x) y).sign = SignType.sign r * (o.oangle x y).sign := by rcases lt_trichotomy r 0 with (h | h | h) <;> simp [h] /-- Multiplying the second vector passed to `oangle` by a real multiplies the sign of the angle by the sign of the real. -/ @[simp] theorem oangle_sign_smul_right (x y : V) (r : ℝ) : (o.oangle x (r β€’ y)).sign = SignType.sign r * (o.oangle x y).sign := by rcases lt_trichotomy r 0 with (h | h | h) <;> simp [h] /-- Auxiliary lemma for the proof of `oangle_sign_smul_add_right`; not intended to be used outside of that proof. -/ theorem oangle_smul_add_right_eq_zero_or_eq_pi_iff {x y : V} (r : ℝ) : o.oangle x (r β€’ x + y) = 0 ∨ o.oangle x (r β€’ x + y) = Ο€ ↔ o.oangle x y = 0 ∨ o.oangle x y = Ο€ := by simp_rw [oangle_eq_zero_or_eq_pi_iff_not_linearIndependent, Fintype.not_linearIndependent_iff, Fin.sum_univ_two, Fin.exists_fin_two] refine ⟨fun h => ?_, fun h => ?_⟩ Β· rcases h with ⟨m, h, hm⟩ change m 0 β€’ x + m 1 β€’ (r β€’ x + y) = 0 at h refine ⟨![m 0 + m 1 * r, m 1], ?_⟩ change (m 0 + m 1 * r) β€’ x + m 1 β€’ y = 0 ∧ (m 0 + m 1 * r β‰  0 ∨ m 1 β‰  0) rw [smul_add, smul_smul, ← add_assoc, ← add_smul] at h refine ⟨h, not_and_or.1 fun h0 => ?_⟩ obtain ⟨h0, h1⟩ := h0 rw [h1] at h0 hm rw [zero_mul, add_zero] at h0 simp [h0] at hm Β· rcases h with ⟨m, h, hm⟩ change m 0 β€’ x + m 1 β€’ y = 0 at h refine ⟨![m 0 - m 1 * r, m 1], ?_⟩ change (m 0 - m 1 * r) β€’ x + m 1 β€’ (r β€’ x + y) = 0 ∧ (m 0 - m 1 * r β‰  0 ∨ m 1 β‰  0) rw [sub_smul, smul_add, smul_smul, ← add_assoc, sub_add_cancel] refine ⟨h, not_and_or.1 fun h0 => ?_⟩ obtain ⟨h0, h1⟩ := h0 rw [h1] at h0 hm rw [zero_mul, sub_zero] at h0 simp [h0] at hm /-- Adding a multiple of the first vector passed to `oangle` to the second vector does not change the sign of the angle. -/ @[simp] theorem oangle_sign_smul_add_right (x y : V) (r : ℝ) : (o.oangle x (r β€’ x + y)).sign = (o.oangle x y).sign := by by_cases h : o.oangle x y = 0 ∨ o.oangle x y = Ο€ Β· rwa [Real.Angle.sign_eq_zero_iff.2 h, Real.Angle.sign_eq_zero_iff, oangle_smul_add_right_eq_zero_or_eq_pi_iff] have h' : βˆ€ r' : ℝ, o.oangle x (r' β€’ x + y) β‰  0 ∧ o.oangle x (r' β€’ x + y) β‰  Ο€ := by intro r' rwa [← o.oangle_smul_add_right_eq_zero_or_eq_pi_iff r', not_or] at h let s : Set (V Γ— V) := (fun r' : ℝ => (x, r' β€’ x + y)) '' Set.univ have hc : IsConnected s := isConnected_univ.image _ (by fun_prop) have hf : ContinuousOn (fun z : V Γ— V => o.oangle z.1 z.2) s := by refine continuousOn_of_forall_continuousAt fun z hz => o.continuousAt_oangle ?_ ?_ all_goals simp_rw [s, Set.mem_image] at hz obtain ⟨r', -, rfl⟩ := hz simp only [Prod.fst, Prod.snd] intro hz Β· simpa [hz] using (h' 0).1 Β· simpa [hz] using (h' r').1 have hs : βˆ€ z : V Γ— V, z ∈ s β†’ o.oangle z.1 z.2 β‰  0 ∧ o.oangle z.1 z.2 β‰  Ο€ := by intro z hz simp_rw [s, Set.mem_image] at hz obtain ⟨r', -, rfl⟩ := hz exact h' r' have hx : (x, y) ∈ s := by convert Set.mem_image_of_mem (fun r' : ℝ => (x, r' β€’ x + y)) (Set.mem_univ 0) simp have hy : (x, r β€’ x + y) ∈ s := Set.mem_image_of_mem _ (Set.mem_univ _) convert Real.Angle.sign_eq_of_continuousOn hc hf hs hx hy /-- Adding a multiple of the second vector passed to `oangle` to the first vector does not change the sign of the angle. -/ @[simp] theorem oangle_sign_add_smul_left (x y : V) (r : ℝ) : (o.oangle (x + r β€’ y) y).sign = (o.oangle x y).sign := by simp_rw [o.oangle_rev y, Real.Angle.sign_neg, add_comm x, oangle_sign_smul_add_right] /-- Subtracting a multiple of the first vector passed to `oangle` from the second vector does not change the sign of the angle. -/ @[simp] theorem oangle_sign_sub_smul_right (x y : V) (r : ℝ) : (o.oangle x (y - r β€’ x)).sign = (o.oangle x y).sign := by rw [sub_eq_add_neg, ← neg_smul, add_comm, oangle_sign_smul_add_right] /-- Subtracting a multiple of the second vector passed to `oangle` from the first vector does not change the sign of the angle. -/ @[simp] theorem oangle_sign_sub_smul_left (x y : V) (r : ℝ) : (o.oangle (x - r β€’ y) y).sign = (o.oangle x y).sign := by rw [sub_eq_add_neg, ← neg_smul, oangle_sign_add_smul_left] /-- Adding the first vector passed to `oangle` to the second vector does not change the sign of the angle. -/ @[simp] theorem oangle_sign_add_right (x y : V) : (o.oangle x (x + y)).sign = (o.oangle x y).sign := by rw [← o.oangle_sign_smul_add_right x y 1, one_smul] /-- Adding the second vector passed to `oangle` to the first vector does not change the sign of the angle. -/ @[simp] theorem oangle_sign_add_left (x y : V) : (o.oangle (x + y) y).sign = (o.oangle x y).sign := by rw [← o.oangle_sign_add_smul_left x y 1, one_smul] /-- Subtracting the first vector passed to `oangle` from the second vector does not change the sign of the angle. -/ @[simp] theorem oangle_sign_sub_right (x y : V) : (o.oangle x (y - x)).sign = (o.oangle x y).sign := by rw [← o.oangle_sign_sub_smul_right x y 1, one_smul] /-- Subtracting the second vector passed to `oangle` from the first vector does not change the sign of the angle. -/ @[simp] theorem oangle_sign_sub_left (x y : V) : (o.oangle (x - y) y).sign = (o.oangle x y).sign := by rw [← o.oangle_sign_sub_smul_left x y 1, one_smul] /-- Subtracting the second vector passed to `oangle` from a multiple of the first vector negates the sign of the angle. -/ @[simp] theorem oangle_sign_smul_sub_right (x y : V) (r : ℝ) : (o.oangle x (r β€’ x - y)).sign = -(o.oangle x y).sign := by rw [← oangle_sign_neg_right, sub_eq_add_neg, oangle_sign_smul_add_right] /-- Subtracting the first vector passed to `oangle` from a multiple of the second vector negates the sign of the angle. -/ @[simp] theorem oangle_sign_smul_sub_left (x y : V) (r : ℝ) : (o.oangle (r β€’ y - x) y).sign = -(o.oangle x y).sign := by rw [← oangle_sign_neg_left, sub_eq_neg_add, oangle_sign_add_smul_left] /-- Subtracting the second vector passed to `oangle` from the first vector negates the sign of the angle. -/ theorem oangle_sign_sub_right_eq_neg (x y : V) : (o.oangle x (x - y)).sign = -(o.oangle x y).sign := by rw [← o.oangle_sign_smul_sub_right x y 1, one_smul] /-- Subtracting the first vector passed to `oangle` from the second vector negates the sign of the angle. -/ theorem oangle_sign_sub_left_eq_neg (x y : V) : (o.oangle (y - x) y).sign = -(o.oangle x y).sign := by rw [← o.oangle_sign_smul_sub_left x y 1, one_smul] /-- Subtracting the first vector passed to `oangle` from the second vector then swapping the vectors does not change the sign of the angle. -/ @[simp] theorem oangle_sign_sub_right_swap (x y : V) : (o.oangle y (y - x)).sign = (o.oangle x y).sign := by rw [oangle_sign_sub_right_eq_neg, o.oangle_rev y x, Real.Angle.sign_neg] /-- Subtracting the second vector passed to `oangle` from the first vector then swapping the vectors does not change the sign of the angle. -/ @[simp] theorem oangle_sign_sub_left_swap (x y : V) : (o.oangle (x - y) x).sign = (o.oangle x y).sign := by rw [oangle_sign_sub_left_eq_neg, o.oangle_rev y x, Real.Angle.sign_neg] /-- The sign of the angle between a vector, and a linear combination of that vector with a second vector, is the sign of the factor by which the second vector is multiplied in that combination multiplied by the sign of the angle between the two vectors. -/ theorem oangle_sign_smul_add_smul_right (x y : V) (r₁ rβ‚‚ : ℝ) : (o.oangle x (r₁ β€’ x + rβ‚‚ β€’ y)).sign = SignType.sign rβ‚‚ * (o.oangle x y).sign := by rw [← o.oangle_sign_smul_add_right x (r₁ β€’ x + rβ‚‚ β€’ y) (-r₁)] simp /-- The sign of the angle between a linear combination of two vectors and the second vector is the sign of the factor by which the first vector is multiplied in that combination multiplied by the sign of the angle between the two vectors. -/ theorem oangle_sign_smul_add_smul_left (x y : V) (r₁ rβ‚‚ : ℝ) : (o.oangle (r₁ β€’ x + rβ‚‚ β€’ y) y).sign = SignType.sign r₁ * (o.oangle x y).sign := by simp_rw [o.oangle_rev y, Real.Angle.sign_neg, add_comm (r₁ β€’ x), oangle_sign_smul_add_smul_right, mul_neg] /-- The sign of the angle between two linear combinations of two vectors is the sign of the determinant of the factors in those combinations multiplied by the sign of the angle between the two vectors. -/ theorem oangle_sign_smul_add_smul_smul_add_smul (x y : V) (r₁ rβ‚‚ r₃ rβ‚„ : ℝ) : (o.oangle (r₁ β€’ x + rβ‚‚ β€’ y) (r₃ β€’ x + rβ‚„ β€’ y)).sign = SignType.sign (r₁ * rβ‚„ - rβ‚‚ * r₃) * (o.oangle x y).sign := by by_cases hr₁ : r₁ = 0 Β· rw [hr₁, zero_smul, zero_mul, zero_add, zero_sub, Left.sign_neg, oangle_sign_smul_left, add_comm, oangle_sign_smul_add_smul_right, oangle_rev, Real.Angle.sign_neg, sign_mul, mul_neg, mul_neg, neg_mul, mul_assoc] Β· rw [← o.oangle_sign_smul_add_right (r₁ β€’ x + rβ‚‚ β€’ y) (r₃ β€’ x + rβ‚„ β€’ y) (-r₃ / r₁), smul_add, smul_smul, smul_smul, div_mul_cancelβ‚€ _ hr₁, neg_smul, ← add_assoc, add_comm (-(r₃ β€’ x)), ← sub_eq_add_neg, sub_add_cancel, ← add_smul, oangle_sign_smul_right, oangle_sign_smul_add_smul_left, ← mul_assoc, ← sign_mul, add_mul, mul_assoc, mul_comm rβ‚‚ r₁, ← mul_assoc, div_mul_cancelβ‚€ _ hr₁, add_comm, neg_mul, ← sub_eq_add_neg, mul_comm rβ‚„, mul_comm r₃] /-- A base angle of an isosceles triangle is acute, oriented vector angle form. -/ theorem abs_oangle_sub_left_toReal_lt_pi_div_two {x y : V} (h : β€–xβ€– = β€–yβ€–) : |(o.oangle (y - x) y).toReal| < Ο€ / 2 := by by_cases hn : x = y; Β· simp [hn, div_pos, Real.pi_pos] have hs : ((2 : β„€) β€’ o.oangle (y - x) y).sign = (o.oangle (y - x) y).sign := by conv_rhs => rw [oangle_sign_sub_left_swap] rw [o.oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq hn h, Real.Angle.sign_pi_sub] rw [Real.Angle.sign_two_zsmul_eq_sign_iff] at hs rcases hs with (hs | hs) Β· rw [oangle_eq_pi_iff_oangle_rev_eq_pi, oangle_eq_pi_iff_sameRay_neg, neg_sub] at hs rcases hs with ⟨hy, -, hr⟩ rw [← exists_nonneg_left_iff_sameRay hy] at hr rcases hr with ⟨r, hr0, hr⟩ rw [eq_sub_iff_add_eq] at hr nth_rw 2 [← one_smul ℝ y] at hr rw [← add_smul] at hr rw [← hr, norm_smul, Real.norm_eq_abs, abs_of_pos (Left.add_pos_of_nonneg_of_pos hr0 one_pos), mul_left_eq_selfβ‚€, or_iff_left (norm_ne_zero_iff.2 hy), add_eq_right] at h rw [h, zero_add, one_smul] at hr exact False.elim (hn hr.symm) Β· exact hs /-- A base angle of an isosceles triangle is acute, oriented vector angle form. -/ theorem abs_oangle_sub_right_toReal_lt_pi_div_two {x y : V} (h : β€–xβ€– = β€–yβ€–) : |(o.oangle x (x - y)).toReal| < Ο€ / 2 := (o.oangle_sub_eq_oangle_sub_rev_of_norm_eq h).symm β–Έ o.abs_oangle_sub_left_toReal_lt_pi_div_two h end Orientation
Mathlib/Geometry/Euclidean/Angle/Oriented/Basic.lean
984
986
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.Complex.Asymptotics import Mathlib.Analysis.SpecificLimits.Normed import Mathlib.Data.Complex.Trigonometric /-! # Complex and real exponential In this file we prove continuity of `Complex.exp` and `Real.exp`. We also prove a few facts about limits of `Real.exp` at infinity. ## Tags exp -/ noncomputable section open Asymptotics Bornology Finset Filter Function Metric Set Topology open scoped Nat namespace Complex variable {z y x : ℝ} theorem exp_bound_sq (x z : β„‚) (hz : β€–zβ€– ≀ 1) : β€–exp (x + z) - exp x - z β€’ exp xβ€– ≀ β€–exp xβ€– * β€–zβ€– ^ 2 := calc β€–exp (x + z) - exp x - z * exp xβ€– = β€–exp x * (exp z - 1 - z)β€– := by congr rw [exp_add] ring _ = β€–exp xβ€– * β€–exp z - 1 - zβ€– := norm_mul _ _ _ ≀ β€–exp xβ€– * β€–zβ€– ^ 2 := mul_le_mul_of_nonneg_left (norm_exp_sub_one_sub_id_le hz) (norm_nonneg _) theorem locally_lipschitz_exp {r : ℝ} (hr_nonneg : 0 ≀ r) (hr_le : r ≀ 1) (x y : β„‚) (hyx : β€–y - xβ€– < r) : β€–exp y - exp xβ€– ≀ (1 + r) * β€–exp xβ€– * β€–y - xβ€– := by have hy_eq : y = x + (y - x) := by abel have hyx_sq_le : β€–y - xβ€– ^ 2 ≀ r * β€–y - xβ€– := by rw [pow_two] exact mul_le_mul hyx.le le_rfl (norm_nonneg _) hr_nonneg have h_sq : βˆ€ z, β€–zβ€– ≀ 1 β†’ β€–exp (x + z) - exp xβ€– ≀ β€–zβ€– * β€–exp xβ€– + β€–exp xβ€– * β€–zβ€– ^ 2 := by intro z hz have : β€–exp (x + z) - exp x - z β€’ exp xβ€– ≀ β€–exp xβ€– * β€–zβ€– ^ 2 := exp_bound_sq x z hz rw [← sub_le_iff_le_add', ← norm_smul z] exact (norm_sub_norm_le _ _).trans this calc β€–exp y - exp xβ€– = β€–exp (x + (y - x)) - exp xβ€– := by nth_rw 1 [hy_eq] _ ≀ β€–y - xβ€– * β€–exp xβ€– + β€–exp xβ€– * β€–y - xβ€– ^ 2 := h_sq (y - x) (hyx.le.trans hr_le) _ ≀ β€–y - xβ€– * β€–exp xβ€– + β€–exp xβ€– * (r * β€–y - xβ€–) := (add_le_add_left (mul_le_mul le_rfl hyx_sq_le (sq_nonneg _) (norm_nonneg _)) _) _ = (1 + r) * β€–exp xβ€– * β€–y - xβ€– := by ring -- Porting note: proof by term mode `locally_lipschitz_exp zero_le_one le_rfl x` -- doesn't work because `β€–y - xβ€–` and `dist y x` don't unify @[continuity] theorem continuous_exp : Continuous exp := continuous_iff_continuousAt.mpr fun x => continuousAt_of_locally_lipschitz zero_lt_one (2 * β€–exp xβ€–) (fun y ↦ by convert locally_lipschitz_exp zero_le_one le_rfl x y using 2 congr ring) theorem continuousOn_exp {s : Set β„‚} : ContinuousOn exp s := continuous_exp.continuousOn lemma exp_sub_sum_range_isBigO_pow (n : β„•) : (fun x ↦ exp x - βˆ‘ i ∈ Finset.range n, x ^ i / i !) =O[𝓝 0] (Β· ^ n) := by rcases (zero_le n).eq_or_lt with rfl | hn Β· simpa using continuous_exp.continuousAt.norm.isBoundedUnder_le Β· refine .of_bound (n.succ / (n ! * n)) ?_ rw [NormedAddCommGroup.nhds_zero_basis_norm_lt.eventually_iff] refine ⟨1, one_pos, fun x hx ↦ ?_⟩ convert exp_bound hx.out.le hn using 1 field_simp [mul_comm] lemma exp_sub_sum_range_succ_isLittleO_pow (n : β„•) : (fun x ↦ exp x - βˆ‘ i ∈ Finset.range (n + 1), x ^ i / i !) =o[𝓝 0] (Β· ^ n) := (exp_sub_sum_range_isBigO_pow (n + 1)).trans_isLittleO <| isLittleO_pow_pow n.lt_succ_self end Complex section ComplexContinuousExpComp variable {Ξ± : Type*} open Complex theorem Filter.Tendsto.cexp {l : Filter Ξ±} {f : Ξ± β†’ β„‚} {z : β„‚} (hf : Tendsto f l (𝓝 z)) : Tendsto (fun x => exp (f x)) l (𝓝 (exp z)) := (continuous_exp.tendsto _).comp hf variable [TopologicalSpace Ξ±] {f : Ξ± β†’ β„‚} {s : Set Ξ±} {x : Ξ±} nonrec theorem ContinuousWithinAt.cexp (h : ContinuousWithinAt f s x) : ContinuousWithinAt (fun y => exp (f y)) s x := h.cexp @[fun_prop] nonrec theorem ContinuousAt.cexp (h : ContinuousAt f x) : ContinuousAt (fun y => exp (f y)) x := h.cexp @[fun_prop] theorem ContinuousOn.cexp (h : ContinuousOn f s) : ContinuousOn (fun y => exp (f y)) s := fun x hx => (h x hx).cexp @[fun_prop] theorem Continuous.cexp (h : Continuous f) : Continuous fun y => exp (f y) := continuous_iff_continuousAt.2 fun _ => h.continuousAt.cexp /-- The complex exponential function is uniformly continuous on left half planes. -/ lemma UniformContinuousOn.cexp (a : ℝ) : UniformContinuousOn exp {x : β„‚ | x.re ≀ a} := by have : Continuous (cexp - 1) := Continuous.sub (Continuous.cexp continuous_id') continuous_one rw [Metric.uniformContinuousOn_iff, Metric.continuous_iff'] at * intro Ξ΅ hΞ΅ simp only [gt_iff_lt, Pi.sub_apply, Pi.one_apply, dist_sub_eq_dist_add_right, sub_add_cancel] at this have ha : 0 < Ξ΅ / (2 * Real.exp a) := by positivity have H := this 0 (Ξ΅ / (2 * Real.exp a)) ha rw [Metric.eventually_nhds_iff] at H obtain ⟨δ, hδ⟩ := H refine ⟨δ, hΞ΄.1, ?_⟩ intros x _ y hy hxy have h3 := hΞ΄.2 (y := x - y) (by simpa only [dist_zero_right] using hxy) rw [dist_eq_norm, exp_zero] at * have : cexp x - cexp y = cexp y * (cexp (x - y) - 1) := by rw [mul_sub_one, ← exp_add] ring_nf rw [this, mul_comm] have hya : β€–cexp yβ€– ≀ Real.exp a := by simp only [norm_exp, Real.exp_le_exp] exact hy simp only [gt_iff_lt, dist_zero_right, Set.mem_setOf_eq, norm_mul, Complex.norm_exp] at * apply lt_of_le_of_lt (mul_le_mul h3.le hya (Real.exp_nonneg y.re) (le_of_lt ha)) have hrr : Ξ΅ / (2 * a.exp) * a.exp = Ξ΅ / 2 := by nth_rw 2 [mul_comm] field_simp [mul_assoc] rw [hrr] exact div_two_lt_of_pos hΞ΅ @[deprecated (since := "2025-02-11")] alias UniformlyContinuousOn.cexp := UniformContinuousOn.cexp end ComplexContinuousExpComp namespace Real @[continuity] theorem continuous_exp : Continuous exp := Complex.continuous_re.comp Complex.continuous_ofReal.cexp theorem continuousOn_exp {s : Set ℝ} : ContinuousOn exp s := continuous_exp.continuousOn lemma exp_sub_sum_range_isBigO_pow (n : β„•) : (fun x ↦ exp x - βˆ‘ i ∈ Finset.range n, x ^ i / i !) =O[𝓝 0] (Β· ^ n) := by have := (Complex.exp_sub_sum_range_isBigO_pow n).comp_tendsto (Complex.continuous_ofReal.tendsto' 0 0 rfl) simp only [Function.comp_def] at this norm_cast at this lemma exp_sub_sum_range_succ_isLittleO_pow (n : β„•) : (fun x ↦ exp x - βˆ‘ i ∈ Finset.range (n + 1), x ^ i / i !) =o[𝓝 0] (Β· ^ n) := (exp_sub_sum_range_isBigO_pow (n + 1)).trans_isLittleO <| isLittleO_pow_pow n.lt_succ_self end Real section RealContinuousExpComp variable {Ξ± : Type*} open Real theorem Filter.Tendsto.rexp {l : Filter Ξ±} {f : Ξ± β†’ ℝ} {z : ℝ} (hf : Tendsto f l (𝓝 z)) : Tendsto (fun x => exp (f x)) l (𝓝 (exp z)) := (continuous_exp.tendsto _).comp hf variable [TopologicalSpace Ξ±] {f : Ξ± β†’ ℝ} {s : Set Ξ±} {x : Ξ±} nonrec theorem ContinuousWithinAt.rexp (h : ContinuousWithinAt f s x) : ContinuousWithinAt (fun y ↦ exp (f y)) s x := h.rexp @[fun_prop] nonrec theorem ContinuousAt.rexp (h : ContinuousAt f x) : ContinuousAt (fun y ↦ exp (f y)) x := h.rexp @[fun_prop] theorem ContinuousOn.rexp (h : ContinuousOn f s) : ContinuousOn (fun y ↦ exp (f y)) s := fun x hx ↦ (h x hx).rexp @[fun_prop] theorem Continuous.rexp (h : Continuous f) : Continuous fun y ↦ exp (f y) := continuous_iff_continuousAt.2 fun _ ↦ h.continuousAt.rexp end RealContinuousExpComp namespace Real variable {Ξ± : Type*} {x y z : ℝ} {l : Filter Ξ±} theorem exp_half (x : ℝ) : exp (x / 2) = √(exp x) := by rw [eq_comm, sqrt_eq_iff_eq_sq, sq, ← exp_add, add_halves] <;> exact (exp_pos _).le /-- The real exponential function tends to `+∞` at `+∞`. -/ theorem tendsto_exp_atTop : Tendsto exp atTop atTop := by have A : Tendsto (fun x : ℝ => x + 1) atTop atTop := tendsto_atTop_add_const_right atTop 1 tendsto_id have B : βˆ€αΆ  x in atTop, x + 1 ≀ exp x := eventually_atTop.2 ⟨0, fun x _ => add_one_le_exp x⟩ exact tendsto_atTop_mono' atTop B A /-- The real exponential function tends to `0` at `-∞` or, equivalently, `exp(-x)` tends to `0` at `+∞` -/ theorem tendsto_exp_neg_atTop_nhds_zero : Tendsto (fun x => exp (-x)) atTop (𝓝 0) := (tendsto_inv_atTop_zero.comp tendsto_exp_atTop).congr fun x => (exp_neg x).symm /-- The real exponential function tends to `1` at `0`. -/ theorem tendsto_exp_nhds_zero_nhds_one : Tendsto exp (𝓝 0) (𝓝 1) := by convert continuous_exp.tendsto 0 simp theorem tendsto_exp_atBot : Tendsto exp atBot (𝓝 0) := (tendsto_exp_neg_atTop_nhds_zero.comp tendsto_neg_atBot_atTop).congr fun x => congr_arg exp <| neg_neg x theorem tendsto_exp_atBot_nhdsGT : Tendsto exp atBot (𝓝[>] 0) := tendsto_inf.2 ⟨tendsto_exp_atBot, tendsto_principal.2 <| Eventually.of_forall exp_pos⟩ @[deprecated (since := "2024-12-22")] alias tendsto_exp_atBot_nhdsWithin := tendsto_exp_atBot_nhdsGT @[simp] theorem isBoundedUnder_ge_exp_comp (l : Filter Ξ±) (f : Ξ± β†’ ℝ) : IsBoundedUnder (Β· β‰₯ Β·) l fun x => exp (f x) := isBoundedUnder_of ⟨0, fun _ => (exp_pos _).le⟩ @[simp] theorem isBoundedUnder_le_exp_comp {f : Ξ± β†’ ℝ} : (IsBoundedUnder (Β· ≀ Β·) l fun x => exp (f x)) ↔ IsBoundedUnder (Β· ≀ Β·) l f := exp_monotone.isBoundedUnder_le_comp_iff tendsto_exp_atTop /-- The function `exp(x)/x^n` tends to `+∞` at `+∞`, for any natural number `n` -/ theorem tendsto_exp_div_pow_atTop (n : β„•) : Tendsto (fun x => exp x / x ^ n) atTop atTop := by refine (atTop_basis_Ioi.tendsto_iff (atTop_basis' 1)).2 fun C hC₁ => ?_ have hCβ‚€ : 0 < C := zero_lt_one.trans_le hC₁ have : 0 < (exp 1 * C)⁻¹ := inv_pos.2 (mul_pos (exp_pos _) hCβ‚€) obtain ⟨N, hN⟩ : βˆƒ N : β„•, βˆ€ k β‰₯ N, (↑k : ℝ) ^ n / exp 1 ^ k < (exp 1 * C)⁻¹ := eventually_atTop.1 ((tendsto_pow_const_div_const_pow_of_one_lt n (one_lt_exp_iff.2 zero_lt_one)).eventually (gt_mem_nhds this)) simp only [← exp_nat_mul, mul_one, div_lt_iffβ‚€, exp_pos, ← div_eq_inv_mul] at hN refine ⟨N, trivial, fun x hx => ?_⟩ rw [Set.mem_Ioi] at hx have hxβ‚€ : 0 < x := (Nat.cast_nonneg N).trans_lt hx rw [Set.mem_Ici, le_div_iffβ‚€ (pow_pos hxβ‚€ _), ← le_div_iffβ‚€' hCβ‚€] calc x ^ n ≀ ⌈xβŒ‰β‚Š ^ n := by gcongr; exact Nat.le_ceil _ _ ≀ exp ⌈xβŒ‰β‚Š / (exp 1 * C) := mod_cast (hN _ (Nat.lt_ceil.2 hx).le).le _ ≀ exp (x + 1) / (exp 1 * C) := by gcongr; exact (Nat.ceil_lt_add_one hxβ‚€.le).le _ = exp x / C := by rw [add_comm, exp_add, mul_div_mul_left _ _ (exp_pos _).ne'] /-- The function `x^n * exp(-x)` tends to `0` at `+∞`, for any natural number `n`. -/ theorem tendsto_pow_mul_exp_neg_atTop_nhds_zero (n : β„•) : Tendsto (fun x => x ^ n * exp (-x)) atTop (𝓝 0) := (tendsto_inv_atTop_zero.comp (tendsto_exp_div_pow_atTop n)).congr fun x => by rw [comp_apply, inv_eq_one_div, div_div_eq_mul_div, one_mul, div_eq_mul_inv, exp_neg] /-- The function `(b * exp x + c) / (x ^ n)` tends to `+∞` at `+∞`, for any natural number `n` and any real numbers `b` and `c` such that `b` is positive. -/ theorem tendsto_mul_exp_add_div_pow_atTop (b c : ℝ) (n : β„•) (hb : 0 < b) : Tendsto (fun x => (b * exp x + c) / x ^ n) atTop atTop := by rcases eq_or_ne n 0 with (rfl | hn) Β· simp only [pow_zero, div_one] exact (tendsto_exp_atTop.const_mul_atTop hb).atTop_add tendsto_const_nhds simp only [add_div, mul_div_assoc] exact ((tendsto_exp_div_pow_atTop n).const_mul_atTop hb).atTop_add (tendsto_const_nhds.div_atTop (tendsto_pow_atTop hn)) /-- The function `(x ^ n) / (b * exp x + c)` tends to `0` at `+∞`, for any natural number `n` and any real numbers `b` and `c` such that `b` is nonzero. -/ theorem tendsto_div_pow_mul_exp_add_atTop (b c : ℝ) (n : β„•) (hb : 0 β‰  b) : Tendsto (fun x => x ^ n / (b * exp x + c)) atTop (𝓝 0) := by have H : βˆ€ d e, 0 < d β†’ Tendsto (fun x : ℝ => x ^ n / (d * exp x + e)) atTop (𝓝 0) := by intro b' c' h convert (tendsto_mul_exp_add_div_pow_atTop b' c' n h).inv_tendsto_atTop using 1 ext x simp rcases lt_or_gt_of_ne hb with h | h Β· exact H b c h
Β· convert (H (-b) (-c) (neg_pos.mpr h)).neg using 1 Β· ext x field_simp rw [← neg_add (b * exp x) c, neg_div_neg_eq] Β· rw [neg_zero] /-- `Real.exp` as an order isomorphism between `ℝ` and `(0, +∞)`. -/ def expOrderIso : ℝ ≃o Ioi (0 : ℝ) := StrictMono.orderIsoOfSurjective _ (exp_strictMono.codRestrict exp_pos) <| (continuous_exp.subtype_mk _).surjective (by rw [tendsto_Ioi_atTop]; simp only [tendsto_exp_atTop]) (by rw [tendsto_Ioi_atBot]; simp only [tendsto_exp_atBot_nhdsGT]) @[simp]
Mathlib/Analysis/SpecialFunctions/Exp.lean
298
311
/- Copyright (c) 2022 Adam Topaz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Adam Topaz, Junyan Xu, Jack McKoen -/ import Mathlib.RingTheory.Valuation.ValuationRing import Mathlib.RingTheory.Localization.AsSubring import Mathlib.Algebra.Ring.Subring.Pointwise import Mathlib.Algebra.Ring.Action.Field import Mathlib.RingTheory.Spectrum.Prime.Basic import Mathlib.RingTheory.LocalRing.ResidueField.Basic /-! # Valuation subrings of a field ## Projects The order structure on `ValuationSubring K`. -/ universe u noncomputable section variable (K : Type u) [Field K] /-- A valuation subring of a field `K` is a subring `A` such that for every `x : K`, either `x ∈ A` or `x⁻¹ ∈ A`. This is equivalent to being maximal in the domination order of local subrings (the stacks project definition). See `LocalSubring.isMax_iff`. -/ structure ValuationSubring extends Subring K where mem_or_inv_mem' : βˆ€ x : K, x ∈ carrier ∨ x⁻¹ ∈ carrier namespace ValuationSubring variable {K} variable (A : ValuationSubring K) instance : SetLike (ValuationSubring K) K where coe A := A.toSubring coe_injective' := by intro ⟨_, _⟩ ⟨_, _⟩ h replace h := SetLike.coe_injective' h congr theorem mem_carrier (x : K) : x ∈ A.carrier ↔ x ∈ A := Iff.refl _ @[simp] theorem mem_toSubring (x : K) : x ∈ A.toSubring ↔ x ∈ A := Iff.refl _ @[ext] theorem ext (A B : ValuationSubring K) (h : βˆ€ x, x ∈ A ↔ x ∈ B) : A = B := SetLike.ext h theorem zero_mem : (0 : K) ∈ A := A.toSubring.zero_mem theorem one_mem : (1 : K) ∈ A := A.toSubring.one_mem theorem add_mem (x y : K) : x ∈ A β†’ y ∈ A β†’ x + y ∈ A := A.toSubring.add_mem theorem mul_mem (x y : K) : x ∈ A β†’ y ∈ A β†’ x * y ∈ A := A.toSubring.mul_mem theorem neg_mem (x : K) : x ∈ A β†’ -x ∈ A := A.toSubring.neg_mem theorem mem_or_inv_mem (x : K) : x ∈ A ∨ x⁻¹ ∈ A := A.mem_or_inv_mem' _ instance : SubringClass (ValuationSubring K) K where zero_mem := zero_mem add_mem {_} a b := add_mem _ a b one_mem := one_mem mul_mem {_} a b := mul_mem _ a b neg_mem {_} x := neg_mem _ x theorem toSubring_injective : Function.Injective (toSubring : ValuationSubring K β†’ Subring K) := fun x y h => by cases x; cases y; congr instance : CommRing A := show CommRing A.toSubring by infer_instance instance : IsDomain A := show IsDomain A.toSubring by infer_instance instance : Top (ValuationSubring K) := Top.mk <| { (⊀ : Subring K) with mem_or_inv_mem' := fun _ => Or.inl trivial } theorem mem_top (x : K) : x ∈ (⊀ : ValuationSubring K) := trivial theorem le_top : A ≀ ⊀ := fun _a _ha => mem_top _ instance : OrderTop (ValuationSubring K) where top := ⊀ le_top := le_top instance : Inhabited (ValuationSubring K) := ⟨⊀⟩ instance : ValuationRing A where cond' a b := by by_cases h : (b : K) = 0 Β· use 0 left ext simp [h] by_cases h : (a : K) = 0 Β· use 0; right ext simp [h] rcases A.mem_or_inv_mem (a / b) with hh | hh Β· use ⟨a / b, hh⟩ right ext field_simp Β· rw [show (a / b : K)⁻¹ = b / a by field_simp] at hh use ⟨b / a, hh⟩ left ext field_simp instance : Algebra A K := show Algebra A.toSubring K by infer_instance -- Porting note: Somehow it cannot find this instance and I'm too lazy to debug. wrong prio? instance isLocalRing : IsLocalRing A := ValuationRing.isLocalRing A @[simp] theorem algebraMap_apply (a : A) : algebraMap A K a = a := rfl instance : IsFractionRing A K where map_units' := fun ⟨y, hy⟩ => (Units.mk0 (y : K) fun c => nonZeroDivisors.ne_zero hy <| Subtype.ext c).isUnit surj' z := by by_cases h : z = 0; Β· use (0, 1); simp [h] rcases A.mem_or_inv_mem z with hh | hh Β· use (⟨z, hh⟩, 1); simp Β· refine ⟨⟨1, ⟨⟨_, hh⟩, ?_⟩⟩, mul_inv_cancelβ‚€ h⟩ exact mem_nonZeroDivisors_iff_ne_zero.2 fun c => h (inv_eq_zero.mp (congr_arg Subtype.val c)) exists_of_eq {a b} h := ⟨1, by ext; simpa using h⟩ /-- The value group of the valuation associated to `A`. Note: it is actually a group with zero. -/ def ValueGroup := ValuationRing.ValueGroup A K -- The `LinearOrderedCommGroupWithZero` instance should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 instance : LinearOrderedCommGroupWithZero (ValueGroup A) := by unfold ValueGroup infer_instance /-- Any valuation subring of `K` induces a natural valuation on `K`. -/ def valuation : Valuation K A.ValueGroup := ValuationRing.valuation A K instance inhabitedValueGroup : Inhabited A.ValueGroup := ⟨A.valuation 0⟩ theorem valuation_le_one (a : A) : A.valuation a ≀ 1 := (ValuationRing.mem_integer_iff A K _).2 ⟨a, rfl⟩ theorem mem_of_valuation_le_one (x : K) (h : A.valuation x ≀ 1) : x ∈ A := let ⟨a, ha⟩ := (ValuationRing.mem_integer_iff A K x).1 h ha β–Έ a.2 theorem valuation_le_one_iff (x : K) : A.valuation x ≀ 1 ↔ x ∈ A := ⟨mem_of_valuation_le_one _ _, fun ha => A.valuation_le_one ⟨x, ha⟩⟩ theorem valuation_eq_iff (x y : K) : A.valuation x = A.valuation y ↔ βˆƒ a : AΛ£, (a : K) * y = x := Quotient.eq'' theorem valuation_le_iff (x y : K) : A.valuation x ≀ A.valuation y ↔ βˆƒ a : A, (a : K) * y = x := Iff.rfl theorem valuation_surjective : Function.Surjective A.valuation := Quot.mk_surjective theorem valuation_unit (a : AΛ£) : A.valuation a = 1 := by rw [← A.valuation.map_one, valuation_eq_iff]; use a; simp theorem valuation_eq_one_iff (a : A) : IsUnit a ↔ A.valuation a = 1 := ⟨fun h => A.valuation_unit h.unit, fun h => by have ha : (a : K) β‰  0 := by intro c rw [c, A.valuation.map_zero] at h exact zero_ne_one h have ha' : (a : K)⁻¹ ∈ A := by rw [← valuation_le_one_iff, map_invβ‚€, h, inv_one] apply isUnit_of_mul_eq_one a ⟨a⁻¹, ha'⟩; ext; field_simp⟩ theorem valuation_lt_one_or_eq_one (a : A) : A.valuation a < 1 ∨ A.valuation a = 1 := lt_or_eq_of_le (A.valuation_le_one a) theorem valuation_lt_one_iff (a : A) : a ∈ IsLocalRing.maximalIdeal A ↔ A.valuation a < 1 := by rw [IsLocalRing.mem_maximalIdeal] dsimp [nonunits]; rw [valuation_eq_one_iff] exact (A.valuation_le_one a).lt_iff_ne.symm /-- A subring `R` of `K` such that for all `x : K` either `x ∈ R` or `x⁻¹ ∈ R` is a valuation subring of `K`. -/ def ofSubring (R : Subring K) (hR : βˆ€ x : K, x ∈ R ∨ x⁻¹ ∈ R) : ValuationSubring K := { R with mem_or_inv_mem' := hR } @[simp] theorem mem_ofSubring (R : Subring K) (hR : βˆ€ x : K, x ∈ R ∨ x⁻¹ ∈ R) (x : K) : x ∈ ofSubring R hR ↔ x ∈ R := Iff.refl _ /-- An overring of a valuation ring is a valuation ring. -/ def ofLE (R : ValuationSubring K) (S : Subring K) (h : R.toSubring ≀ S) : ValuationSubring K := { S with mem_or_inv_mem' := fun x => (R.mem_or_inv_mem x).imp (@h x) (@h _) } section Order instance : SemilatticeSup (ValuationSubring K) := { (inferInstance : PartialOrder (ValuationSubring K)) with sup := fun R S => ofLE R (R.toSubring βŠ” S.toSubring) <| le_sup_left le_sup_left := fun R S _ hx => (le_sup_left : R.toSubring ≀ R.toSubring βŠ” S.toSubring) hx le_sup_right := fun R S _ hx => (le_sup_right : S.toSubring ≀ R.toSubring βŠ” S.toSubring) hx sup_le := fun R S T hR hT _ hx => (sup_le hR hT : R.toSubring βŠ” S.toSubring ≀ T.toSubring) hx } /-- The ring homomorphism induced by the partial order. -/ def inclusion (R S : ValuationSubring K) (h : R ≀ S) : R β†’+* S := Subring.inclusion h /-- The canonical ring homomorphism from a valuation ring to its field of fractions. -/ def subtype (R : ValuationSubring K) : R β†’+* K := Subring.subtype R.toSubring @[simp] lemma subtype_apply {R : ValuationSubring K} (x : R) : R.subtype x = x := rfl lemma subtype_injective (R : ValuationSubring K) : Function.Injective R.subtype := R.toSubring.subtype_injective @[simp] theorem coe_subtype (R : ValuationSubring K) : ⇑(subtype R) = Subtype.val := rfl /-- The canonical map on value groups induced by a coarsening of valuation rings. -/ def mapOfLE (R S : ValuationSubring K) (h : R ≀ S) : R.ValueGroup β†’*β‚€ S.ValueGroup where toFun := Quotient.map' id fun _ _ ⟨u, hu⟩ => ⟨Units.map (R.inclusion S h).toMonoidHom u, hu⟩ map_zero' := rfl map_one' := rfl map_mul' := by rintro ⟨⟩ ⟨⟩; rfl @[mono] theorem monotone_mapOfLE (R S : ValuationSubring K) (h : R ≀ S) : Monotone (R.mapOfLE S h) := by rintro ⟨⟩ ⟨⟩ ⟨a, ha⟩; exact ⟨R.inclusion S h a, ha⟩ @[simp] theorem mapOfLE_comp_valuation (R S : ValuationSubring K) (h : R ≀ S) : R.mapOfLE S h ∘ R.valuation = S.valuation := by ext; rfl @[simp] theorem mapOfLE_valuation_apply (R S : ValuationSubring K) (h : R ≀ S) (x : K) : R.mapOfLE S h (R.valuation x) = S.valuation x := rfl /-- The ideal corresponding to a coarsening of a valuation ring. -/ def idealOfLE (R S : ValuationSubring K) (h : R ≀ S) : Ideal R := (IsLocalRing.maximalIdeal S).comap (R.inclusion S h) instance prime_idealOfLE (R S : ValuationSubring K) (h : R ≀ S) : (idealOfLE R S h).IsPrime := (IsLocalRing.maximalIdeal S).comap_isPrime _ /-- The coarsening of a valuation ring associated to a prime ideal. -/ def ofPrime (A : ValuationSubring K) (P : Ideal A) [P.IsPrime] : ValuationSubring K := ofLE A (Localization.subalgebra.ofField K _ P.primeCompl_le_nonZeroDivisors).toSubring fun a ha => Subalgebra.mem_toSubring.mpr <| Subalgebra.algebraMap_mem (Localization.subalgebra.ofField K _ P.primeCompl_le_nonZeroDivisors) (⟨a, ha⟩ : A) instance ofPrimeAlgebra (A : ValuationSubring K) (P : Ideal A) [P.IsPrime] : Algebra A (A.ofPrime P) := Subalgebra.algebra (Localization.subalgebra.ofField K _ P.primeCompl_le_nonZeroDivisors) instance ofPrime_scalar_tower (A : ValuationSubring K) (P : Ideal A) [P.IsPrime] : letI : SMul A (A.ofPrime P) := SMulZeroClass.toSMul IsScalarTower A (A.ofPrime P) K := IsScalarTower.subalgebra' A K K (Localization.subalgebra.ofField K _ P.primeCompl_le_nonZeroDivisors) instance ofPrime_localization (A : ValuationSubring K) (P : Ideal A) [P.IsPrime] : IsLocalization.AtPrime (A.ofPrime P) P := by apply Localization.subalgebra.isLocalization_ofField K P.primeCompl P.primeCompl_le_nonZeroDivisors theorem le_ofPrime (A : ValuationSubring K) (P : Ideal A) [P.IsPrime] : A ≀ ofPrime A P := fun a ha => Subalgebra.mem_toSubring.mpr <| Subalgebra.algebraMap_mem _ (⟨a, ha⟩ : A) theorem ofPrime_valuation_eq_one_iff_mem_primeCompl (A : ValuationSubring K) (P : Ideal A) [P.IsPrime] (x : A) : (ofPrime A P).valuation x = 1 ↔ x ∈ P.primeCompl := by rw [← IsLocalization.AtPrime.isUnit_to_map_iff (A.ofPrime P) P x, valuation_eq_one_iff]; rfl @[simp] theorem idealOfLE_ofPrime (A : ValuationSubring K) (P : Ideal A) [P.IsPrime] : idealOfLE A (ofPrime A P) (le_ofPrime A P) = P := by refine Ideal.ext (fun x => ?_) apply IsLocalization.AtPrime.to_map_mem_maximal_iff exact isLocalRing (ofPrime A P) @[simp] theorem ofPrime_idealOfLE (R S : ValuationSubring K) (h : R ≀ S) : ofPrime R (idealOfLE R S h) = S := by ext x; constructor Β· rintro ⟨a, r, hr, rfl⟩; apply mul_mem; Β· exact h a.2 Β· rw [← valuation_le_one_iff, map_invβ‚€, ← inv_one, inv_le_invβ‚€] Β· exact not_lt.1 ((not_iff_not.2 <| valuation_lt_one_iff S _).1 hr) Β· simpa [Valuation.pos_iff] using fun hrβ‚€ ↦ hrβ‚€ β–Έ hr <| Ideal.zero_mem (R.idealOfLE S h) Β· exact zero_lt_one Β· intro hx; by_cases hr : x ∈ R; Β· exact R.le_ofPrime _ hr have : x β‰  0 := fun h => hr (by rw [h]; exact R.zero_mem) replace hr := (R.mem_or_inv_mem x).resolve_left hr refine ⟨1, ⟨x⁻¹, hr⟩, ?_, ?_⟩ Β· simp only [Ideal.primeCompl, Submonoid.mem_mk, Subsemigroup.mem_mk, Set.mem_compl_iff, SetLike.mem_coe, idealOfLE, Ideal.mem_comap, IsLocalRing.mem_maximalIdeal, mem_nonunits_iff, not_not] change IsUnit (⟨x⁻¹, h hr⟩ : S) apply isUnit_of_mul_eq_one _ (⟨x, hx⟩ : S) ext; field_simp Β· field_simp theorem ofPrime_le_of_le (P Q : Ideal A) [P.IsPrime] [Q.IsPrime] (h : P ≀ Q) : ofPrime A Q ≀ ofPrime A P := fun _x ⟨a, s, hs, he⟩ => ⟨a, s, fun c => hs (h c), he⟩ theorem idealOfLE_le_of_le (R S : ValuationSubring K) (hR : A ≀ R) (hS : A ≀ S) (h : R ≀ S) : idealOfLE A S hS ≀ idealOfLE A R hR := fun x hx => (valuation_lt_one_iff R _).2 (by by_contra c; push_neg at c; replace c := monotone_mapOfLE R S h c rw [(mapOfLE _ _ _).map_one, mapOfLE_valuation_apply] at c apply not_le_of_lt ((valuation_lt_one_iff S _).1 hx) c) /-- The equivalence between coarsenings of a valuation ring and its prime ideals. -/ @[simps apply] def primeSpectrumEquiv : PrimeSpectrum A ≃ {S // A ≀ S} where toFun P := ⟨ofPrime A P.asIdeal, le_ofPrime _ _⟩ invFun S := ⟨idealOfLE _ S S.2, inferInstance⟩ left_inv P := by ext1; simp right_inv S := by ext1; simp /-- An ordered variant of `primeSpectrumEquiv`. -/ @[simps!] def primeSpectrumOrderEquiv : (PrimeSpectrum A)α΅’α΅ˆ ≃o {S // A ≀ S} := { OrderDual.ofDual.trans (primeSpectrumEquiv A) with map_rel_iff' {a b} := ⟨a.rec <| fun a => b.rec <| fun b => fun h => by simp only [OrderDual.toDual_le_toDual] dsimp at h have := idealOfLE_le_of_le A _ _ ?_ ?_ h Β· rwa [idealOfLE_ofPrime, idealOfLE_ofPrime] at this all_goals exact le_ofPrime A (PrimeSpectrum.asIdeal _), fun h => by apply ofPrime_le_of_le; exact h⟩ } instance le_total_ideal : IsTotal {S // A ≀ S} LE.le := by classical let _ : IsTotal (PrimeSpectrum A) (Β· ≀ Β·) := ⟨fun ⟨x, _⟩ ⟨y, _⟩ => LE.isTotal.total x y⟩ exact ⟨(primeSpectrumOrderEquiv A).symm.toRelEmbedding.isTotal.total⟩ open scoped Classical in instance linearOrderOverring : LinearOrder {S // A ≀ S} where le_total := (le_total_ideal A).1 max_def a b := congr_funβ‚‚ sup_eq_maxDefault a b toDecidableLE := _ end Order end ValuationSubring namespace Valuation variable {K} variable {Ξ“ Γ₁ Ξ“β‚‚ : Type*} [LinearOrderedCommGroupWithZero Ξ“] [LinearOrderedCommGroupWithZero Γ₁] [LinearOrderedCommGroupWithZero Ξ“β‚‚] (v : Valuation K Ξ“) (v₁ : Valuation K Γ₁) (vβ‚‚ : Valuation K Ξ“β‚‚) /-- The valuation subring associated to a valuation. -/ def valuationSubring : ValuationSubring K := { v.integer with mem_or_inv_mem' := by intro x rcases val_le_one_or_val_inv_le_one v x with h | h exacts [Or.inl h, Or.inr h] } @[simp] theorem mem_valuationSubring_iff (x : K) : x ∈ v.valuationSubring ↔ v x ≀ 1 := Iff.refl _ theorem isEquiv_iff_valuationSubring : v₁.IsEquiv vβ‚‚ ↔ v₁.valuationSubring = vβ‚‚.valuationSubring := by constructor Β· intro h; ext x; specialize h x 1; simpa using h Β· intro h; apply isEquiv_of_val_le_one intro x have : x ∈ v₁.valuationSubring ↔ x ∈ vβ‚‚.valuationSubring := by rw [h] simpa using this theorem isEquiv_valuation_valuationSubring : v.IsEquiv v.valuationSubring.valuation := by rw [isEquiv_iff_val_le_one] intro x rw [ValuationSubring.valuation_le_one_iff] rfl end Valuation namespace ValuationSubring variable {K} variable (A : ValuationSubring K) @[simp] theorem valuationSubring_valuation : A.valuation.valuationSubring = A := by ext; rw [← A.valuation_le_one_iff]; rfl section UnitGroup /-- The unit group of a valuation subring, as a subgroup of `KΛ£`. -/ def unitGroup : Subgroup KΛ£ := (A.valuation.toMonoidWithZeroHom.toMonoidHom.comp (Units.coeHom K)).ker @[simp] theorem mem_unitGroup_iff (x : KΛ£) : x ∈ A.unitGroup ↔ A.valuation x = 1 := Iff.rfl /-- For a valuation subring `A`, `A.unitGroup` agrees with the units of `A`. -/ def unitGroupMulEquiv : A.unitGroup ≃* AΛ£ where toFun x := { val := ⟨(x : KΛ£), mem_of_valuation_le_one A _ x.prop.le⟩ inv := ⟨((x⁻¹ : A.unitGroup) : KΛ£), mem_of_valuation_le_one _ _ x⁻¹.prop.le⟩ -- Porting note: was `Units.mul_inv x` val_inv := Subtype.ext (by simp) -- Porting note: was `Units.inv_mul x` inv_val := Subtype.ext (by simp) } invFun x := ⟨Units.map A.subtype.toMonoidHom x, A.valuation_unit x⟩ left_inv a := by ext; rfl right_inv a := by ext; rfl map_mul' a b := by ext; rfl @[simp] theorem coe_unitGroupMulEquiv_apply (a : A.unitGroup) : ((A.unitGroupMulEquiv a : A) : K) = ((a : KΛ£) : K) := rfl @[simp] theorem coe_unitGroupMulEquiv_symm_apply (a : AΛ£) : ((A.unitGroupMulEquiv.symm a : KΛ£) : K) = a := rfl theorem unitGroup_le_unitGroup {A B : ValuationSubring K} : A.unitGroup ≀ B.unitGroup ↔ A ≀ B := by constructor Β· intro h x hx rw [← A.valuation_le_one_iff x, le_iff_lt_or_eq] at hx by_cases h_1 : x = 0; Β· simp only [h_1, zero_mem] by_cases h_2 : 1 + x = 0 Β· simp only [← add_eq_zero_iff_neg_eq.1 h_2, neg_mem _ _ (one_mem _)] rcases hx with hx | hx Β· have := h (show Units.mk0 _ h_2 ∈ A.unitGroup from A.valuation.map_one_add_of_lt hx) simpa using B.add_mem _ _ (show 1 + x ∈ B from SetLike.coe_mem (B.unitGroupMulEquiv ⟨_, this⟩ : B)) (B.neg_mem _ B.one_mem) Β· have := h (show Units.mk0 x h_1 ∈ A.unitGroup from hx) exact SetLike.coe_mem (B.unitGroupMulEquiv ⟨_, this⟩ : B) Β· rintro h x (hx : A.valuation x = 1) apply_fun A.mapOfLE B h at hx simpa using hx theorem unitGroup_injective : Function.Injective (unitGroup : ValuationSubring K β†’ Subgroup _) := fun A B h => by simpa only [le_antisymm_iff, unitGroup_le_unitGroup] using h theorem eq_iff_unitGroup {A B : ValuationSubring K} : A = B ↔ A.unitGroup = B.unitGroup := unitGroup_injective.eq_iff.symm /-- The map on valuation subrings to their unit groups is an order embedding. -/ def unitGroupOrderEmbedding : ValuationSubring K β†ͺo Subgroup KΛ£ where toFun A := A.unitGroup inj' := unitGroup_injective map_rel_iff' {_A _B} := unitGroup_le_unitGroup theorem unitGroup_strictMono : StrictMono (unitGroup : ValuationSubring K β†’ Subgroup _) := unitGroupOrderEmbedding.strictMono end UnitGroup section nonunits /-- The nonunits of a valuation subring of `K`, as a subsemigroup of `K` -/ def nonunits : Subsemigroup K where carrier := {x | A.valuation x < 1} -- Porting note: added `Set.mem_setOf.mp` mul_mem' ha hb := (mul_lt_mul'' (Set.mem_setOf.mp ha) (Set.mem_setOf.mp hb) zero_le' zero_le').trans_eq <| mul_one _ theorem mem_nonunits_iff {x : K} : x ∈ A.nonunits ↔ A.valuation x < 1 := Iff.rfl theorem nonunits_le_nonunits {A B : ValuationSubring K} : B.nonunits ≀ A.nonunits ↔ A ≀ B := by constructor Β· intro h x hx by_cases h_1 : x = 0; Β· simp only [h_1, zero_mem] rw [← valuation_le_one_iff, ← not_lt, Valuation.one_lt_val_iff _ h_1] at hx ⊒ by_contra h_2; exact hx (h h_2) Β· intro h x hx by_contra h_1; exact not_lt.2 (monotone_mapOfLE _ _ h (not_lt.1 h_1)) hx theorem nonunits_injective : Function.Injective (nonunits : ValuationSubring K β†’ Subsemigroup _) := fun A B h => by simpa only [le_antisymm_iff, nonunits_le_nonunits] using h.symm theorem nonunits_inj {A B : ValuationSubring K} : A.nonunits = B.nonunits ↔ A = B := nonunits_injective.eq_iff /-- The map on valuation subrings to their nonunits is a dual order embedding. -/ def nonunitsOrderEmbedding : ValuationSubring K β†ͺo (Subsemigroup K)α΅’α΅ˆ where toFun A := A.nonunits inj' := nonunits_injective map_rel_iff' {_A _B} := nonunits_le_nonunits variable {A} /-- The elements of `A.nonunits` are those of the maximal ideal of `A` after coercion to `K`. See also `mem_nonunits_iff_exists_mem_maximalIdeal`, which gets rid of the coercion to `K`, at the expense of a more complicated right hand side. -/ theorem coe_mem_nonunits_iff {a : A} : (a : K) ∈ A.nonunits ↔ a ∈ IsLocalRing.maximalIdeal A := (valuation_lt_one_iff _ _).symm theorem nonunits_le : A.nonunits ≀ A.toSubring.toSubmonoid.toSubsemigroup := fun _a ha => (A.valuation_le_one_iff _).mp (A.mem_nonunits_iff.mp ha).le theorem nonunits_subset : (A.nonunits : Set K) βŠ† A := nonunits_le /-- The elements of `A.nonunits` are those of the maximal ideal of `A`. See also `coe_mem_nonunits_iff`, which has a simpler right hand side but requires the element to be in `A` already. -/ theorem mem_nonunits_iff_exists_mem_maximalIdeal {a : K} : a ∈ A.nonunits ↔ βˆƒ ha, (⟨a, ha⟩ : A) ∈ IsLocalRing.maximalIdeal A := ⟨fun h => ⟨nonunits_subset h, coe_mem_nonunits_iff.mp h⟩, fun ⟨_, h⟩ => coe_mem_nonunits_iff.mpr h⟩ /-- `A.nonunits` agrees with the maximal ideal of `A`, after taking its image in `K`. -/ theorem image_maximalIdeal : ((↑) : A β†’ K) '' IsLocalRing.maximalIdeal A = A.nonunits := by ext a simp only [Set.mem_image, SetLike.mem_coe, mem_nonunits_iff_exists_mem_maximalIdeal] rw [Subtype.exists] simp_rw [exists_and_right, exists_eq_right] end nonunits section PrincipalUnitGroup /-- The principal unit group of a valuation subring, as a subgroup of `KΛ£`. -/ def principalUnitGroup : Subgroup KΛ£ where carrier := {x | A.valuation (x - 1) < 1} mul_mem' := by intro a b ha hb -- Porting note: added rw [Set.mem_setOf] at ha hb refine lt_of_le_of_lt ?_ (max_lt hb ha) -- Porting note: `sub_add_sub_cancel` needed some help rw [← one_mul (A.valuation (b - 1)), ← A.valuation.map_one_add_of_lt ha, add_sub_cancel, ← Valuation.map_mul, mul_sub_one, ← sub_add_sub_cancel (↑(a * b) : K) _ 1] exact A.valuation.map_add _ _ one_mem' := by simp inv_mem' := by dsimp intro a ha conv => lhs rw [← mul_one (A.valuation _), ← A.valuation.map_one_add_of_lt ha] rwa [add_sub_cancel, ← Valuation.map_mul, sub_mul, Units.inv_mul, ← neg_sub, one_mul, Valuation.map_neg] theorem principal_units_le_units : A.principalUnitGroup ≀ A.unitGroup := fun a h => by simpa only [add_sub_cancel] using A.valuation.map_one_add_of_lt h theorem mem_principalUnitGroup_iff (x : KΛ£) : x ∈ A.principalUnitGroup ↔ A.valuation ((x : K) - 1) < 1 := Iff.rfl theorem principalUnitGroup_le_principalUnitGroup {A B : ValuationSubring K} : B.principalUnitGroup ≀ A.principalUnitGroup ↔ A ≀ B := by constructor Β· intro h x hx by_cases h_1 : x = 0; Β· simp only [h_1, zero_mem] by_cases h_2 : x⁻¹ + 1 = 0 Β· rw [add_eq_zero_iff_eq_neg, inv_eq_iff_eq_inv, inv_neg, inv_one] at h_2 simpa only [h_2] using B.neg_mem _ B.one_mem Β· rw [← valuation_le_one_iff, ← not_lt, Valuation.one_lt_val_iff _ h_1, ← add_sub_cancel_right x⁻¹, ← Units.val_mk0 h_2, ← mem_principalUnitGroup_iff] at hx ⊒ simpa only [hx] using @h (Units.mk0 (x⁻¹ + 1) h_2) Β· intro h x hx by_contra h_1; exact not_lt.2 (monotone_mapOfLE _ _ h (not_lt.1 h_1)) hx theorem principalUnitGroup_injective : Function.Injective (principalUnitGroup : ValuationSubring K β†’ Subgroup _) := fun A B h => by simpa [le_antisymm_iff, principalUnitGroup_le_principalUnitGroup] using h.symm theorem eq_iff_principalUnitGroup {A B : ValuationSubring K} : A = B ↔ A.principalUnitGroup = B.principalUnitGroup := principalUnitGroup_injective.eq_iff.symm /-- The map on valuation subrings to their principal unit groups is an order embedding. -/ def principalUnitGroupOrderEmbedding : ValuationSubring K β†ͺo (Subgroup KΛ£)α΅’α΅ˆ where toFun A := A.principalUnitGroup inj' := principalUnitGroup_injective map_rel_iff' {_A _B} := principalUnitGroup_le_principalUnitGroup theorem coe_mem_principalUnitGroup_iff {x : A.unitGroup} : (x : KΛ£) ∈ A.principalUnitGroup ↔ A.unitGroupMulEquiv x ∈ (Units.map (IsLocalRing.residue A).toMonoidHom).ker := by rw [MonoidHom.mem_ker, Units.ext_iff] let Ο€ := Ideal.Quotient.mk (IsLocalRing.maximalIdeal A); convert_to _ ↔ Ο€ _ = 1 rw [← Ο€.map_one, ← sub_eq_zero, ← Ο€.map_sub, Ideal.Quotient.eq_zero_iff_mem, valuation_lt_one_iff] simp [mem_principalUnitGroup_iff] /-- The principal unit group agrees with the kernel of the canonical map from the units of `A` to the units of the residue field of `A`. -/ def principalUnitGroupEquiv : A.principalUnitGroup ≃* (Units.map (IsLocalRing.residue A).toMonoidHom).ker where toFun x := ⟨A.unitGroupMulEquiv ⟨_, A.principal_units_le_units x.2⟩, A.coe_mem_principalUnitGroup_iff.1 x.2⟩ invFun x := ⟨A.unitGroupMulEquiv.symm x, by rw [A.coe_mem_principalUnitGroup_iff]; simp⟩ left_inv x := by simp right_inv x := by simp map_mul' _ _ := rfl theorem principalUnitGroupEquiv_apply (a : A.principalUnitGroup) : (((principalUnitGroupEquiv A a : AΛ£) : A) : K) = (a : KΛ£) := rfl theorem principalUnitGroup_symm_apply (a : (Units.map (IsLocalRing.residue A).toMonoidHom).ker) : ((A.principalUnitGroupEquiv.symm a : KΛ£) : K) = ((a : AΛ£) : A) := rfl /-- The canonical map from the unit group of `A` to the units of the residue field of `A`. -/ def unitGroupToResidueFieldUnits : A.unitGroup β†’* (IsLocalRing.ResidueField A)Λ£ := MonoidHom.comp (Units.map <| (Ideal.Quotient.mk _).toMonoidHom) A.unitGroupMulEquiv.toMonoidHom @[simp] theorem coe_unitGroupToResidueFieldUnits_apply (x : A.unitGroup) : (A.unitGroupToResidueFieldUnits x : IsLocalRing.ResidueField A) = Ideal.Quotient.mk _ (A.unitGroupMulEquiv x : A) := rfl theorem ker_unitGroupToResidueFieldUnits : A.unitGroupToResidueFieldUnits.ker = A.principalUnitGroup.comap A.unitGroup.subtype := by ext simp_rw [Subgroup.mem_comap, Subgroup.coe_subtype, coe_mem_principalUnitGroup_iff, unitGroupToResidueFieldUnits, IsLocalRing.residue, RingHom.toMonoidHom_eq_coe, MulEquiv.toMonoidHom_eq_coe, MonoidHom.mem_ker, MonoidHom.coe_comp, MonoidHom.coe_coe, Function.comp_apply] theorem surjective_unitGroupToResidueFieldUnits : Function.Surjective A.unitGroupToResidueFieldUnits := (IsLocalRing.surjective_units_map_of_local_ringHom _ Ideal.Quotient.mk_surjective IsLocalRing.isLocalHom_residue).comp (MulEquiv.surjective _) /-- The quotient of the unit group of `A` by the principal unit group of `A` agrees with the units of the residue field of `A`. -/ def unitsModPrincipalUnitsEquivResidueFieldUnits : A.unitGroup β§Έ A.principalUnitGroup.comap A.unitGroup.subtype ≃* (IsLocalRing.ResidueField A)Λ£ := (QuotientGroup.quotientMulEquivOfEq A.ker_unitGroupToResidueFieldUnits.symm).trans (QuotientGroup.quotientKerEquivOfSurjective _ A.surjective_unitGroupToResidueFieldUnits) /-- Porting note: Lean needs to be reminded of this instance -/ local instance : MulOneClass ({ x // x ∈ unitGroup A } β§Έ Subgroup.comap (Subgroup.subtype (unitGroup A)) (principalUnitGroup A)) := inferInstance theorem unitsModPrincipalUnitsEquivResidueFieldUnits_comp_quotientGroup_mk : (A.unitsModPrincipalUnitsEquivResidueFieldUnits : _ β§Έ Subgroup.comap _ _ β†’* _).comp (QuotientGroup.mk' (A.principalUnitGroup.subgroupOf A.unitGroup)) = A.unitGroupToResidueFieldUnits := rfl theorem unitsModPrincipalUnitsEquivResidueFieldUnits_comp_quotientGroup_mk_apply (x : A.unitGroup) : A.unitsModPrincipalUnitsEquivResidueFieldUnits.toMonoidHom (QuotientGroup.mk x) = A.unitGroupToResidueFieldUnits x := rfl end PrincipalUnitGroup /-! ### Pointwise actions This transfers the action from `Subring.pointwiseMulAction`, noting that it only applies when the action is by a group. Notably this provides an instances when `G` is `K ≃+* K`. These instances are in the `Pointwise` locale. The lemmas in this section are copied from the file `Mathlib.Algebra.Ring.Subring.Pointwise`; try to keep these in sync. -/ section PointwiseActions open scoped Pointwise variable {G : Type*} [Group G] [MulSemiringAction G K] /-- The action on a valuation subring corresponding to applying the action to every element. This is available as an instance in the `Pointwise` locale. -/ def pointwiseHasSMul : SMul G (ValuationSubring K) where smul g S :=-- TODO: if we add `ValuationSubring.map` at a later date, we should use it here { g β€’ S.toSubring with mem_or_inv_mem' := fun x => (mem_or_inv_mem S (g⁻¹ β€’ x)).imp Subring.mem_pointwise_smul_iff_inv_smul_mem.mpr fun h => Subring.mem_pointwise_smul_iff_inv_smul_mem.mpr <| by rwa [smul_inv''] } scoped[Pointwise] attribute [instance] ValuationSubring.pointwiseHasSMul open scoped Pointwise @[simp] theorem coe_pointwise_smul (g : G) (S : ValuationSubring K) : ↑(g β€’ S) = g β€’ (S : Set K) := rfl @[simp] theorem pointwise_smul_toSubring (g : G) (S : ValuationSubring K) : (g β€’ S).toSubring = g β€’ S.toSubring := rfl /-- The action on a valuation subring corresponding to applying the action to every element. This is available as an instance in the `Pointwise` locale. This is a stronger version of `ValuationSubring.pointwiseSMul`. -/ def pointwiseMulAction : MulAction G (ValuationSubring K) := toSubring_injective.mulAction toSubring pointwise_smul_toSubring
scoped[Pointwise] attribute [instance] ValuationSubring.pointwiseMulAction open scoped Pointwise theorem smul_mem_pointwise_smul (g : G) (x : K) (S : ValuationSubring K) : x ∈ S β†’ g β€’ x ∈ g β€’ S := (Set.smul_mem_smul_set : _ β†’ _ ∈ g β€’ (S : Set K)) instance : CovariantClass G (ValuationSubring K) HSMul.hSMul LE.le :=
Mathlib/RingTheory/Valuation/ValuationSubring.lean
733
740
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne, Benjamin Davidson -/ import Mathlib.Order.Monotone.Odd import Mathlib.Analysis.Calculus.LogDeriv import Mathlib.Analysis.SpecialFunctions.ExpDeriv import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic import Mathlib.Analysis.Calculus.Deriv.MeanValue /-! # Differentiability of trigonometric functions ## Main statements The differentiability of the usual trigonometric functions is proved, and their derivatives are computed. ## Tags sin, cos, tan, angle -/ noncomputable section open scoped Topology Filter open Set namespace Complex /-- The complex sine function is everywhere strictly differentiable, with the derivative `cos x`. -/ theorem hasStrictDerivAt_sin (x : β„‚) : HasStrictDerivAt sin (cos x) x := by simp only [cos, div_eq_mul_inv] convert ((((hasStrictDerivAt_id x).neg.mul_const I).cexp.sub ((hasStrictDerivAt_id x).mul_const I).cexp).mul_const I).mul_const (2 : β„‚)⁻¹ using 1 simp only [Function.comp, id] rw [sub_mul, mul_assoc, mul_assoc, I_mul_I, neg_one_mul, neg_neg, mul_one, one_mul, mul_assoc, I_mul_I, mul_neg_one, sub_neg_eq_add, add_comm] /-- The complex sine function is everywhere differentiable, with the derivative `cos x`. -/ theorem hasDerivAt_sin (x : β„‚) : HasDerivAt sin (cos x) x := (hasStrictDerivAt_sin x).hasDerivAt theorem contDiff_sin {n} : ContDiff β„‚ n sin := (((contDiff_neg.mul contDiff_const).cexp.sub (contDiff_id.mul contDiff_const).cexp).mul contDiff_const).div_const _ @[simp] theorem differentiable_sin : Differentiable β„‚ sin := fun x => (hasDerivAt_sin x).differentiableAt @[simp] theorem differentiableAt_sin {x : β„‚} : DifferentiableAt β„‚ sin x := differentiable_sin x @[simp] theorem deriv_sin : deriv sin = cos := funext fun x => (hasDerivAt_sin x).deriv /-- The complex cosine function is everywhere strictly differentiable, with the derivative `-sin x`. -/ theorem hasStrictDerivAt_cos (x : β„‚) : HasStrictDerivAt cos (-sin x) x := by simp only [sin, div_eq_mul_inv, neg_mul_eq_neg_mul] convert (((hasStrictDerivAt_id x).mul_const I).cexp.add ((hasStrictDerivAt_id x).neg.mul_const I).cexp).mul_const (2 : β„‚)⁻¹ using 1 simp only [Function.comp, id] ring /-- The complex cosine function is everywhere differentiable, with the derivative `-sin x`. -/ theorem hasDerivAt_cos (x : β„‚) : HasDerivAt cos (-sin x) x := (hasStrictDerivAt_cos x).hasDerivAt theorem contDiff_cos {n} : ContDiff β„‚ n cos := ((contDiff_id.mul contDiff_const).cexp.add (contDiff_neg.mul contDiff_const).cexp).div_const _ @[simp] theorem differentiable_cos : Differentiable β„‚ cos := fun x => (hasDerivAt_cos x).differentiableAt @[simp] theorem differentiableAt_cos {x : β„‚} : DifferentiableAt β„‚ cos x := differentiable_cos x theorem deriv_cos {x : β„‚} : deriv cos x = -sin x := (hasDerivAt_cos x).deriv @[simp] theorem deriv_cos' : deriv cos = fun x => -sin x := funext fun _ => deriv_cos /-- The complex hyperbolic sine function is everywhere strictly differentiable, with the derivative `cosh x`. -/ theorem hasStrictDerivAt_sinh (x : β„‚) : HasStrictDerivAt sinh (cosh x) x := by simp only [cosh, div_eq_mul_inv] convert ((hasStrictDerivAt_exp x).sub (hasStrictDerivAt_id x).neg.cexp).mul_const (2 : β„‚)⁻¹ using 1 rw [id, mul_neg_one, sub_eq_add_neg, neg_neg] /-- The complex hyperbolic sine function is everywhere differentiable, with the derivative `cosh x`. -/ theorem hasDerivAt_sinh (x : β„‚) : HasDerivAt sinh (cosh x) x := (hasStrictDerivAt_sinh x).hasDerivAt theorem contDiff_sinh {n} : ContDiff β„‚ n sinh := (contDiff_exp.sub contDiff_neg.cexp).div_const _ @[simp] theorem differentiable_sinh : Differentiable β„‚ sinh := fun x => (hasDerivAt_sinh x).differentiableAt @[simp] theorem differentiableAt_sinh {x : β„‚} : DifferentiableAt β„‚ sinh x := differentiable_sinh x @[simp] theorem deriv_sinh : deriv sinh = cosh := funext fun x => (hasDerivAt_sinh x).deriv /-- The complex hyperbolic cosine function is everywhere strictly differentiable, with the derivative `sinh x`. -/ theorem hasStrictDerivAt_cosh (x : β„‚) : HasStrictDerivAt cosh (sinh x) x := by simp only [sinh, div_eq_mul_inv] convert ((hasStrictDerivAt_exp x).add (hasStrictDerivAt_id x).neg.cexp).mul_const (2 : β„‚)⁻¹ using 1 rw [id, mul_neg_one, sub_eq_add_neg] /-- The complex hyperbolic cosine function is everywhere differentiable, with the derivative `sinh x`. -/ theorem hasDerivAt_cosh (x : β„‚) : HasDerivAt cosh (sinh x) x := (hasStrictDerivAt_cosh x).hasDerivAt theorem contDiff_cosh {n} : ContDiff β„‚ n cosh := (contDiff_exp.add contDiff_neg.cexp).div_const _ @[simp] theorem differentiable_cosh : Differentiable β„‚ cosh := fun x => (hasDerivAt_cosh x).differentiableAt @[simp] theorem differentiableAt_cosh {x : β„‚} : DifferentiableAt β„‚ cosh x := differentiable_cosh x @[simp] theorem deriv_cosh : deriv cosh = sinh := funext fun x => (hasDerivAt_cosh x).deriv end Complex section /-! ### Simp lemmas for derivatives of `fun x => Complex.cos (f x)` etc., `f : β„‚ β†’ β„‚` -/ variable {f : β„‚ β†’ β„‚} {f' x : β„‚} {s : Set β„‚} /-! #### `Complex.cos` -/ theorem HasStrictDerivAt.ccos (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) * f') x := (Complex.hasStrictDerivAt_cos (f x)).comp x hf theorem HasDerivAt.ccos (hf : HasDerivAt f f' x) : HasDerivAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) * f') x := (Complex.hasDerivAt_cos (f x)).comp x hf theorem HasDerivWithinAt.ccos (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) * f') s x := (Complex.hasDerivAt_cos (f x)).comp_hasDerivWithinAt x hf theorem derivWithin_ccos (hf : DifferentiableWithinAt β„‚ f s x) (hxs : UniqueDiffWithinAt β„‚ s x) : derivWithin (fun x => Complex.cos (f x)) s x = -Complex.sin (f x) * derivWithin f s x := hf.hasDerivWithinAt.ccos.derivWithin hxs @[simp] theorem deriv_ccos (hc : DifferentiableAt β„‚ f x) : deriv (fun x => Complex.cos (f x)) x = -Complex.sin (f x) * deriv f x := hc.hasDerivAt.ccos.deriv /-! #### `Complex.sin` -/ theorem HasStrictDerivAt.csin (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun x => Complex.sin (f x)) (Complex.cos (f x) * f') x := (Complex.hasStrictDerivAt_sin (f x)).comp x hf theorem HasDerivAt.csin (hf : HasDerivAt f f' x) : HasDerivAt (fun x => Complex.sin (f x)) (Complex.cos (f x) * f') x := (Complex.hasDerivAt_sin (f x)).comp x hf theorem HasDerivWithinAt.csin (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun x => Complex.sin (f x)) (Complex.cos (f x) * f') s x := (Complex.hasDerivAt_sin (f x)).comp_hasDerivWithinAt x hf theorem derivWithin_csin (hf : DifferentiableWithinAt β„‚ f s x) (hxs : UniqueDiffWithinAt β„‚ s x) : derivWithin (fun x => Complex.sin (f x)) s x = Complex.cos (f x) * derivWithin f s x := hf.hasDerivWithinAt.csin.derivWithin hxs @[simp] theorem deriv_csin (hc : DifferentiableAt β„‚ f x) : deriv (fun x => Complex.sin (f x)) x = Complex.cos (f x) * deriv f x := hc.hasDerivAt.csin.deriv /-! #### `Complex.cosh` -/ theorem HasStrictDerivAt.ccosh (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) * f') x := (Complex.hasStrictDerivAt_cosh (f x)).comp x hf theorem HasDerivAt.ccosh (hf : HasDerivAt f f' x) : HasDerivAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) * f') x := (Complex.hasDerivAt_cosh (f x)).comp x hf theorem HasDerivWithinAt.ccosh (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) * f') s x := (Complex.hasDerivAt_cosh (f x)).comp_hasDerivWithinAt x hf theorem derivWithin_ccosh (hf : DifferentiableWithinAt β„‚ f s x) (hxs : UniqueDiffWithinAt β„‚ s x) : derivWithin (fun x => Complex.cosh (f x)) s x = Complex.sinh (f x) * derivWithin f s x := hf.hasDerivWithinAt.ccosh.derivWithin hxs @[simp] theorem deriv_ccosh (hc : DifferentiableAt β„‚ f x) : deriv (fun x => Complex.cosh (f x)) x = Complex.sinh (f x) * deriv f x := hc.hasDerivAt.ccosh.deriv /-! #### `Complex.sinh` -/ theorem HasStrictDerivAt.csinh (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) * f') x := (Complex.hasStrictDerivAt_sinh (f x)).comp x hf theorem HasDerivAt.csinh (hf : HasDerivAt f f' x) : HasDerivAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) * f') x := (Complex.hasDerivAt_sinh (f x)).comp x hf theorem HasDerivWithinAt.csinh (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) * f') s x := (Complex.hasDerivAt_sinh (f x)).comp_hasDerivWithinAt x hf theorem derivWithin_csinh (hf : DifferentiableWithinAt β„‚ f s x) (hxs : UniqueDiffWithinAt β„‚ s x) : derivWithin (fun x => Complex.sinh (f x)) s x = Complex.cosh (f x) * derivWithin f s x := hf.hasDerivWithinAt.csinh.derivWithin hxs @[simp] theorem deriv_csinh (hc : DifferentiableAt β„‚ f x) : deriv (fun x => Complex.sinh (f x)) x = Complex.cosh (f x) * deriv f x := hc.hasDerivAt.csinh.deriv end section /-! ### Simp lemmas for derivatives of `fun x => Complex.cos (f x)` etc., `f : E β†’ β„‚` -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace β„‚ E] {f : E β†’ β„‚} {f' : E β†’L[β„‚] β„‚} {x : E} {s : Set E} /-! #### `Complex.cos` -/ theorem HasStrictFDerivAt.ccos (hf : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) β€’ f') x := (Complex.hasStrictDerivAt_cos (f x)).comp_hasStrictFDerivAt x hf theorem HasFDerivAt.ccos (hf : HasFDerivAt f f' x) : HasFDerivAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) β€’ f') x := (Complex.hasDerivAt_cos (f x)).comp_hasFDerivAt x hf theorem HasFDerivWithinAt.ccos (hf : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) β€’ f') s x := (Complex.hasDerivAt_cos (f x)).comp_hasFDerivWithinAt x hf theorem DifferentiableWithinAt.ccos (hf : DifferentiableWithinAt β„‚ f s x) : DifferentiableWithinAt β„‚ (fun x => Complex.cos (f x)) s x := hf.hasFDerivWithinAt.ccos.differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.ccos (hc : DifferentiableAt β„‚ f x) : DifferentiableAt β„‚ (fun x => Complex.cos (f x)) x := hc.hasFDerivAt.ccos.differentiableAt theorem DifferentiableOn.ccos (hc : DifferentiableOn β„‚ f s) : DifferentiableOn β„‚ (fun x => Complex.cos (f x)) s := fun x h => (hc x h).ccos @[simp, fun_prop] theorem Differentiable.ccos (hc : Differentiable β„‚ f) : Differentiable β„‚ fun x => Complex.cos (f x) := fun x => (hc x).ccos theorem fderivWithin_ccos (hf : DifferentiableWithinAt β„‚ f s x) (hxs : UniqueDiffWithinAt β„‚ s x) : fderivWithin β„‚ (fun x => Complex.cos (f x)) s x = -Complex.sin (f x) β€’ fderivWithin β„‚ f s x := hf.hasFDerivWithinAt.ccos.fderivWithin hxs @[simp] theorem fderiv_ccos (hc : DifferentiableAt β„‚ f x) : fderiv β„‚ (fun x => Complex.cos (f x)) x = -Complex.sin (f x) β€’ fderiv β„‚ f x := hc.hasFDerivAt.ccos.fderiv theorem ContDiff.ccos {n} (h : ContDiff β„‚ n f) : ContDiff β„‚ n fun x => Complex.cos (f x) := Complex.contDiff_cos.comp h theorem ContDiffAt.ccos {n} (hf : ContDiffAt β„‚ n f x) : ContDiffAt β„‚ n (fun x => Complex.cos (f x)) x := Complex.contDiff_cos.contDiffAt.comp x hf theorem ContDiffOn.ccos {n} (hf : ContDiffOn β„‚ n f s) : ContDiffOn β„‚ n (fun x => Complex.cos (f x)) s := Complex.contDiff_cos.comp_contDiffOn hf theorem ContDiffWithinAt.ccos {n} (hf : ContDiffWithinAt β„‚ n f s x) : ContDiffWithinAt β„‚ n (fun x => Complex.cos (f x)) s x := Complex.contDiff_cos.contDiffAt.comp_contDiffWithinAt x hf /-! #### `Complex.sin` -/ theorem HasStrictFDerivAt.csin (hf : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (fun x => Complex.sin (f x)) (Complex.cos (f x) β€’ f') x := (Complex.hasStrictDerivAt_sin (f x)).comp_hasStrictFDerivAt x hf theorem HasFDerivAt.csin (hf : HasFDerivAt f f' x) : HasFDerivAt (fun x => Complex.sin (f x)) (Complex.cos (f x) β€’ f') x := (Complex.hasDerivAt_sin (f x)).comp_hasFDerivAt x hf theorem HasFDerivWithinAt.csin (hf : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (fun x => Complex.sin (f x)) (Complex.cos (f x) β€’ f') s x := (Complex.hasDerivAt_sin (f x)).comp_hasFDerivWithinAt x hf theorem DifferentiableWithinAt.csin (hf : DifferentiableWithinAt β„‚ f s x) : DifferentiableWithinAt β„‚ (fun x => Complex.sin (f x)) s x := hf.hasFDerivWithinAt.csin.differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.csin (hc : DifferentiableAt β„‚ f x) : DifferentiableAt β„‚ (fun x => Complex.sin (f x)) x := hc.hasFDerivAt.csin.differentiableAt theorem DifferentiableOn.csin (hc : DifferentiableOn β„‚ f s) : DifferentiableOn β„‚ (fun x => Complex.sin (f x)) s := fun x h => (hc x h).csin @[simp, fun_prop] theorem Differentiable.csin (hc : Differentiable β„‚ f) : Differentiable β„‚ fun x => Complex.sin (f x) := fun x => (hc x).csin theorem fderivWithin_csin (hf : DifferentiableWithinAt β„‚ f s x) (hxs : UniqueDiffWithinAt β„‚ s x) : fderivWithin β„‚ (fun x => Complex.sin (f x)) s x = Complex.cos (f x) β€’ fderivWithin β„‚ f s x := hf.hasFDerivWithinAt.csin.fderivWithin hxs @[simp] theorem fderiv_csin (hc : DifferentiableAt β„‚ f x) : fderiv β„‚ (fun x => Complex.sin (f x)) x = Complex.cos (f x) β€’ fderiv β„‚ f x := hc.hasFDerivAt.csin.fderiv theorem ContDiff.csin {n} (h : ContDiff β„‚ n f) : ContDiff β„‚ n fun x => Complex.sin (f x) := Complex.contDiff_sin.comp h theorem ContDiffAt.csin {n} (hf : ContDiffAt β„‚ n f x) : ContDiffAt β„‚ n (fun x => Complex.sin (f x)) x := Complex.contDiff_sin.contDiffAt.comp x hf theorem ContDiffOn.csin {n} (hf : ContDiffOn β„‚ n f s) : ContDiffOn β„‚ n (fun x => Complex.sin (f x)) s := Complex.contDiff_sin.comp_contDiffOn hf theorem ContDiffWithinAt.csin {n} (hf : ContDiffWithinAt β„‚ n f s x) : ContDiffWithinAt β„‚ n (fun x => Complex.sin (f x)) s x := Complex.contDiff_sin.contDiffAt.comp_contDiffWithinAt x hf /-! #### `Complex.cosh` -/ theorem HasStrictFDerivAt.ccosh (hf : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) β€’ f') x := (Complex.hasStrictDerivAt_cosh (f x)).comp_hasStrictFDerivAt x hf theorem HasFDerivAt.ccosh (hf : HasFDerivAt f f' x) : HasFDerivAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) β€’ f') x := (Complex.hasDerivAt_cosh (f x)).comp_hasFDerivAt x hf theorem HasFDerivWithinAt.ccosh (hf : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) β€’ f') s x := (Complex.hasDerivAt_cosh (f x)).comp_hasFDerivWithinAt x hf theorem DifferentiableWithinAt.ccosh (hf : DifferentiableWithinAt β„‚ f s x) : DifferentiableWithinAt β„‚ (fun x => Complex.cosh (f x)) s x := hf.hasFDerivWithinAt.ccosh.differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.ccosh (hc : DifferentiableAt β„‚ f x) : DifferentiableAt β„‚ (fun x => Complex.cosh (f x)) x := hc.hasFDerivAt.ccosh.differentiableAt theorem DifferentiableOn.ccosh (hc : DifferentiableOn β„‚ f s) : DifferentiableOn β„‚ (fun x => Complex.cosh (f x)) s := fun x h => (hc x h).ccosh @[simp, fun_prop] theorem Differentiable.ccosh (hc : Differentiable β„‚ f) : Differentiable β„‚ fun x => Complex.cosh (f x) := fun x => (hc x).ccosh theorem fderivWithin_ccosh (hf : DifferentiableWithinAt β„‚ f s x) (hxs : UniqueDiffWithinAt β„‚ s x) : fderivWithin β„‚ (fun x => Complex.cosh (f x)) s x = Complex.sinh (f x) β€’ fderivWithin β„‚ f s x := hf.hasFDerivWithinAt.ccosh.fderivWithin hxs @[simp] theorem fderiv_ccosh (hc : DifferentiableAt β„‚ f x) : fderiv β„‚ (fun x => Complex.cosh (f x)) x = Complex.sinh (f x) β€’ fderiv β„‚ f x := hc.hasFDerivAt.ccosh.fderiv theorem ContDiff.ccosh {n} (h : ContDiff β„‚ n f) : ContDiff β„‚ n fun x => Complex.cosh (f x) := Complex.contDiff_cosh.comp h theorem ContDiffAt.ccosh {n} (hf : ContDiffAt β„‚ n f x) : ContDiffAt β„‚ n (fun x => Complex.cosh (f x)) x := Complex.contDiff_cosh.contDiffAt.comp x hf theorem ContDiffOn.ccosh {n} (hf : ContDiffOn β„‚ n f s) : ContDiffOn β„‚ n (fun x => Complex.cosh (f x)) s := Complex.contDiff_cosh.comp_contDiffOn hf theorem ContDiffWithinAt.ccosh {n} (hf : ContDiffWithinAt β„‚ n f s x) : ContDiffWithinAt β„‚ n (fun x => Complex.cosh (f x)) s x := Complex.contDiff_cosh.contDiffAt.comp_contDiffWithinAt x hf /-! #### `Complex.sinh` -/ theorem HasStrictFDerivAt.csinh (hf : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) β€’ f') x := (Complex.hasStrictDerivAt_sinh (f x)).comp_hasStrictFDerivAt x hf theorem HasFDerivAt.csinh (hf : HasFDerivAt f f' x) : HasFDerivAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) β€’ f') x := (Complex.hasDerivAt_sinh (f x)).comp_hasFDerivAt x hf theorem HasFDerivWithinAt.csinh (hf : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) β€’ f') s x := (Complex.hasDerivAt_sinh (f x)).comp_hasFDerivWithinAt x hf theorem DifferentiableWithinAt.csinh (hf : DifferentiableWithinAt β„‚ f s x) : DifferentiableWithinAt β„‚ (fun x => Complex.sinh (f x)) s x := hf.hasFDerivWithinAt.csinh.differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.csinh (hc : DifferentiableAt β„‚ f x) : DifferentiableAt β„‚ (fun x => Complex.sinh (f x)) x := hc.hasFDerivAt.csinh.differentiableAt theorem DifferentiableOn.csinh (hc : DifferentiableOn β„‚ f s) : DifferentiableOn β„‚ (fun x => Complex.sinh (f x)) s := fun x h => (hc x h).csinh @[simp, fun_prop] theorem Differentiable.csinh (hc : Differentiable β„‚ f) : Differentiable β„‚ fun x => Complex.sinh (f x) := fun x => (hc x).csinh theorem fderivWithin_csinh (hf : DifferentiableWithinAt β„‚ f s x) (hxs : UniqueDiffWithinAt β„‚ s x) : fderivWithin β„‚ (fun x => Complex.sinh (f x)) s x = Complex.cosh (f x) β€’ fderivWithin β„‚ f s x := hf.hasFDerivWithinAt.csinh.fderivWithin hxs @[simp] theorem fderiv_csinh (hc : DifferentiableAt β„‚ f x) : fderiv β„‚ (fun x => Complex.sinh (f x)) x = Complex.cosh (f x) β€’ fderiv β„‚ f x := hc.hasFDerivAt.csinh.fderiv theorem ContDiff.csinh {n} (h : ContDiff β„‚ n f) : ContDiff β„‚ n fun x => Complex.sinh (f x) := Complex.contDiff_sinh.comp h theorem ContDiffAt.csinh {n} (hf : ContDiffAt β„‚ n f x) : ContDiffAt β„‚ n (fun x => Complex.sinh (f x)) x := Complex.contDiff_sinh.contDiffAt.comp x hf theorem ContDiffOn.csinh {n} (hf : ContDiffOn β„‚ n f s) : ContDiffOn β„‚ n (fun x => Complex.sinh (f x)) s := Complex.contDiff_sinh.comp_contDiffOn hf theorem ContDiffWithinAt.csinh {n} (hf : ContDiffWithinAt β„‚ n f s x) : ContDiffWithinAt β„‚ n (fun x => Complex.sinh (f x)) s x := Complex.contDiff_sinh.contDiffAt.comp_contDiffWithinAt x hf end namespace Real variable {x y z : ℝ} theorem hasStrictDerivAt_sin (x : ℝ) : HasStrictDerivAt sin (cos x) x := (Complex.hasStrictDerivAt_sin x).real_of_complex theorem hasDerivAt_sin (x : ℝ) : HasDerivAt sin (cos x) x := (hasStrictDerivAt_sin x).hasDerivAt theorem contDiff_sin {n} : ContDiff ℝ n sin := Complex.contDiff_sin.real_of_complex @[simp] theorem differentiable_sin : Differentiable ℝ sin := fun x => (hasDerivAt_sin x).differentiableAt @[simp] theorem differentiableAt_sin : DifferentiableAt ℝ sin x := differentiable_sin x @[simp] theorem deriv_sin : deriv sin = cos := funext fun x => (hasDerivAt_sin x).deriv theorem hasStrictDerivAt_cos (x : ℝ) : HasStrictDerivAt cos (-sin x) x := (Complex.hasStrictDerivAt_cos x).real_of_complex theorem hasDerivAt_cos (x : ℝ) : HasDerivAt cos (-sin x) x := (Complex.hasDerivAt_cos x).real_of_complex theorem contDiff_cos {n} : ContDiff ℝ n cos := Complex.contDiff_cos.real_of_complex @[simp] theorem differentiable_cos : Differentiable ℝ cos := fun x => (hasDerivAt_cos x).differentiableAt @[simp] theorem differentiableAt_cos : DifferentiableAt ℝ cos x := differentiable_cos x theorem deriv_cos : deriv cos x = -sin x := (hasDerivAt_cos x).deriv @[simp] theorem deriv_cos' : deriv cos = fun x => -sin x := funext fun _ => deriv_cos theorem hasStrictDerivAt_sinh (x : ℝ) : HasStrictDerivAt sinh (cosh x) x := (Complex.hasStrictDerivAt_sinh x).real_of_complex theorem hasDerivAt_sinh (x : ℝ) : HasDerivAt sinh (cosh x) x := (Complex.hasDerivAt_sinh x).real_of_complex theorem contDiff_sinh {n} : ContDiff ℝ n sinh := Complex.contDiff_sinh.real_of_complex @[simp] theorem differentiable_sinh : Differentiable ℝ sinh := fun x => (hasDerivAt_sinh x).differentiableAt @[simp] theorem differentiableAt_sinh : DifferentiableAt ℝ sinh x := differentiable_sinh x @[simp] theorem deriv_sinh : deriv sinh = cosh := funext fun x => (hasDerivAt_sinh x).deriv theorem hasStrictDerivAt_cosh (x : ℝ) : HasStrictDerivAt cosh (sinh x) x := (Complex.hasStrictDerivAt_cosh x).real_of_complex theorem hasDerivAt_cosh (x : ℝ) : HasDerivAt cosh (sinh x) x := (Complex.hasDerivAt_cosh x).real_of_complex theorem contDiff_cosh {n} : ContDiff ℝ n cosh := Complex.contDiff_cosh.real_of_complex @[simp] theorem differentiable_cosh : Differentiable ℝ cosh := fun x => (hasDerivAt_cosh x).differentiableAt @[simp] theorem differentiableAt_cosh : DifferentiableAt ℝ cosh x := differentiable_cosh x @[simp] theorem deriv_cosh : deriv cosh = sinh := funext fun x => (hasDerivAt_cosh x).deriv /-- `sinh` is strictly monotone. -/ theorem sinh_strictMono : StrictMono sinh := strictMono_of_deriv_pos <| by rw [Real.deriv_sinh]; exact cosh_pos /-- `sinh` is injective, `βˆ€ a b, sinh a = sinh b β†’ a = b`. -/ theorem sinh_injective : Function.Injective sinh := sinh_strictMono.injective @[simp] theorem sinh_inj : sinh x = sinh y ↔ x = y := sinh_injective.eq_iff @[simp] theorem sinh_le_sinh : sinh x ≀ sinh y ↔ x ≀ y := sinh_strictMono.le_iff_le @[simp] theorem sinh_lt_sinh : sinh x < sinh y ↔ x < y := sinh_strictMono.lt_iff_lt @[simp] lemma sinh_eq_zero : sinh x = 0 ↔ x = 0 := by rw [← @sinh_inj x, sinh_zero] lemma sinh_ne_zero : sinh x β‰  0 ↔ x β‰  0 := sinh_eq_zero.not @[simp] theorem sinh_pos_iff : 0 < sinh x ↔ 0 < x := by simpa only [sinh_zero] using @sinh_lt_sinh 0 x @[simp] theorem sinh_nonpos_iff : sinh x ≀ 0 ↔ x ≀ 0 := by simpa only [sinh_zero] using @sinh_le_sinh x 0 @[simp] theorem sinh_neg_iff : sinh x < 0 ↔ x < 0 := by simpa only [sinh_zero] using @sinh_lt_sinh x 0 @[simp] theorem sinh_nonneg_iff : 0 ≀ sinh x ↔ 0 ≀ x := by simpa only [sinh_zero] using @sinh_le_sinh 0 x theorem abs_sinh (x : ℝ) : |sinh x| = sinh |x| := by cases le_total x 0 <;> simp [abs_of_nonneg, abs_of_nonpos, *] theorem cosh_strictMonoOn : StrictMonoOn cosh (Ici 0) := strictMonoOn_of_deriv_pos (convex_Ici _) continuous_cosh.continuousOn fun x hx => by rw [interior_Ici, mem_Ioi] at hx; rwa [deriv_cosh, sinh_pos_iff] @[simp] theorem cosh_le_cosh : cosh x ≀ cosh y ↔ |x| ≀ |y| := cosh_abs x β–Έ cosh_abs y β–Έ cosh_strictMonoOn.le_iff_le (abs_nonneg x) (abs_nonneg y) @[simp] theorem cosh_lt_cosh : cosh x < cosh y ↔ |x| < |y| := lt_iff_lt_of_le_iff_le cosh_le_cosh @[simp] theorem one_le_cosh (x : ℝ) : 1 ≀ cosh x := cosh_zero β–Έ cosh_le_cosh.2 (by simp only [_root_.abs_zero, _root_.abs_nonneg]) @[simp] theorem one_lt_cosh : 1 < cosh x ↔ x β‰  0 := cosh_zero β–Έ cosh_lt_cosh.trans (by simp only [_root_.abs_zero, abs_pos]) theorem sinh_sub_id_strictMono : StrictMono fun x => sinh x - x := by refine strictMono_of_odd_strictMonoOn_nonneg (fun x => by simp; abel) ?_ refine strictMonoOn_of_deriv_pos (convex_Ici _) ?_ fun x hx => ?_ Β· exact (continuous_sinh.sub continuous_id).continuousOn Β· rw [interior_Ici, mem_Ioi] at hx rw [deriv_sub, deriv_sinh, deriv_id'', sub_pos, one_lt_cosh] exacts [hx.ne', differentiableAt_sinh, differentiableAt_id] @[simp] theorem self_le_sinh_iff : x ≀ sinh x ↔ 0 ≀ x := calc x ≀ sinh x ↔ sinh 0 - 0 ≀ sinh x - x := by simp _ ↔ 0 ≀ x := sinh_sub_id_strictMono.le_iff_le @[simp] theorem sinh_le_self_iff : sinh x ≀ x ↔ x ≀ 0 := calc sinh x ≀ x ↔ sinh x - x ≀ sinh 0 - 0 := by simp _ ↔ x ≀ 0 := sinh_sub_id_strictMono.le_iff_le @[simp] theorem self_lt_sinh_iff : x < sinh x ↔ 0 < x := lt_iff_lt_of_le_iff_le sinh_le_self_iff @[simp] theorem sinh_lt_self_iff : sinh x < x ↔ x < 0 := lt_iff_lt_of_le_iff_le self_le_sinh_iff end Real section /-! ### Simp lemmas for derivatives of `fun x => Real.cos (f x)` etc., `f : ℝ β†’ ℝ` -/ variable {f : ℝ β†’ ℝ} {f' x : ℝ} {s : Set ℝ} /-! #### `Real.cos` -/ theorem HasStrictDerivAt.cos (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun x => Real.cos (f x)) (-Real.sin (f x) * f') x := (Real.hasStrictDerivAt_cos (f x)).comp x hf theorem HasDerivAt.cos (hf : HasDerivAt f f' x) : HasDerivAt (fun x => Real.cos (f x)) (-Real.sin (f x) * f') x := (Real.hasDerivAt_cos (f x)).comp x hf theorem HasDerivWithinAt.cos (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun x => Real.cos (f x)) (-Real.sin (f x) * f') s x := (Real.hasDerivAt_cos (f x)).comp_hasDerivWithinAt x hf theorem derivWithin_cos (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) : derivWithin (fun x => Real.cos (f x)) s x = -Real.sin (f x) * derivWithin f s x := hf.hasDerivWithinAt.cos.derivWithin hxs @[simp] theorem deriv_cos (hc : DifferentiableAt ℝ f x) : deriv (fun x => Real.cos (f x)) x = -Real.sin (f x) * deriv f x := hc.hasDerivAt.cos.deriv /-! #### `Real.sin` -/ theorem HasStrictDerivAt.sin (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun x => Real.sin (f x)) (Real.cos (f x) * f') x := (Real.hasStrictDerivAt_sin (f x)).comp x hf theorem HasDerivAt.sin (hf : HasDerivAt f f' x) : HasDerivAt (fun x => Real.sin (f x)) (Real.cos (f x) * f') x := (Real.hasDerivAt_sin (f x)).comp x hf theorem HasDerivWithinAt.sin (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun x => Real.sin (f x)) (Real.cos (f x) * f') s x := (Real.hasDerivAt_sin (f x)).comp_hasDerivWithinAt x hf theorem derivWithin_sin (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) : derivWithin (fun x => Real.sin (f x)) s x = Real.cos (f x) * derivWithin f s x := hf.hasDerivWithinAt.sin.derivWithin hxs @[simp] theorem deriv_sin (hc : DifferentiableAt ℝ f x) : deriv (fun x => Real.sin (f x)) x = Real.cos (f x) * deriv f x := hc.hasDerivAt.sin.deriv /-! #### `Real.cosh` -/ theorem HasStrictDerivAt.cosh (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun x => Real.cosh (f x)) (Real.sinh (f x) * f') x := (Real.hasStrictDerivAt_cosh (f x)).comp x hf theorem HasDerivAt.cosh (hf : HasDerivAt f f' x) : HasDerivAt (fun x => Real.cosh (f x)) (Real.sinh (f x) * f') x := (Real.hasDerivAt_cosh (f x)).comp x hf theorem HasDerivWithinAt.cosh (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun x => Real.cosh (f x)) (Real.sinh (f x) * f') s x := (Real.hasDerivAt_cosh (f x)).comp_hasDerivWithinAt x hf theorem derivWithin_cosh (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) : derivWithin (fun x => Real.cosh (f x)) s x = Real.sinh (f x) * derivWithin f s x := hf.hasDerivWithinAt.cosh.derivWithin hxs @[simp] theorem deriv_cosh (hc : DifferentiableAt ℝ f x) : deriv (fun x => Real.cosh (f x)) x = Real.sinh (f x) * deriv f x := hc.hasDerivAt.cosh.deriv /-! #### `Real.sinh` -/ theorem HasStrictDerivAt.sinh (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun x => Real.sinh (f x)) (Real.cosh (f x) * f') x := (Real.hasStrictDerivAt_sinh (f x)).comp x hf theorem HasDerivAt.sinh (hf : HasDerivAt f f' x) : HasDerivAt (fun x => Real.sinh (f x)) (Real.cosh (f x) * f') x := (Real.hasDerivAt_sinh (f x)).comp x hf theorem HasDerivWithinAt.sinh (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun x => Real.sinh (f x)) (Real.cosh (f x) * f') s x := (Real.hasDerivAt_sinh (f x)).comp_hasDerivWithinAt x hf
theorem derivWithin_sinh (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) : derivWithin (fun x => Real.sinh (f x)) s x = Real.cosh (f x) * derivWithin f s x := hf.hasDerivWithinAt.sinh.derivWithin hxs @[simp] theorem deriv_sinh (hc : DifferentiableAt ℝ f x) : deriv (fun x => Real.sinh (f x)) x = Real.cosh (f x) * deriv f x := hc.hasDerivAt.sinh.deriv
Mathlib/Analysis/SpecialFunctions/Trigonometric/Deriv.lean
751
758
/- Copyright (c) 2022 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jujian Zhang, Junyan Xu -/ import Mathlib.Topology.Sheaves.PUnit import Mathlib.Topology.Sheaves.Stalks import Mathlib.Topology.Sheaves.Functors /-! # Skyscraper (pre)sheaves A skyscraper (pre)sheaf `𝓕 : (Pre)Sheaf C X` is the (pre)sheaf with value `A` at point `pβ‚€` that is supported only at open sets contain `pβ‚€`, i.e. `𝓕(U) = A` if `pβ‚€ ∈ U` and `𝓕(U) = *` if `pβ‚€ βˆ‰ U` where `*` is a terminal object of `C`. In terms of stalks, `𝓕` is supported at all specializations of `pβ‚€`, i.e. if `pβ‚€ β€³ x` then `𝓕ₓ β‰… A` and if `Β¬ pβ‚€ β€³ x` then `𝓕ₓ β‰… *`. ## Main definitions * `skyscraperPresheaf`: `skyscraperPresheaf pβ‚€ A` is the skyscraper presheaf at point `pβ‚€` with value `A`. * `skyscraperSheaf`: the skyscraper presheaf satisfies the sheaf condition. ## Main statements * `skyscraperPresheafStalkOfSpecializes`: if `y ∈ closure {pβ‚€}` then the stalk of `skyscraperPresheaf pβ‚€ A` at `y` is `A`. * `skyscraperPresheafStalkOfNotSpecializes`: if `y βˆ‰ closure {pβ‚€}` then the stalk of `skyscraperPresheaf pβ‚€ A` at `y` is `*` the terminal object. TODO: generalize universe level when calculating stalks, after generalizing universe level of stalk. -/ noncomputable section open TopologicalSpace TopCat CategoryTheory CategoryTheory.Limits Opposite open scoped AlgebraicGeometry universe u v w variable {X : TopCat.{u}} (pβ‚€ : X) [βˆ€ U : Opens X, Decidable (pβ‚€ ∈ U)] section variable {C : Type v} [Category.{w} C] [HasTerminal C] (A : C) /-- A skyscraper presheaf is a presheaf supported at a single point: if `pβ‚€ ∈ X` is a specified point, then the skyscraper presheaf `𝓕` with value `A` is defined by `U ↦ A` if `pβ‚€ ∈ U` and `U ↦ *` if `pβ‚€ βˆ‰ A` where `*` is some terminal object. -/ @[simps] def skyscraperPresheaf : Presheaf C X where obj U := if pβ‚€ ∈ unop U then A else terminal C map {U V} i := if h : pβ‚€ ∈ unop V then eqToHom <| by rw [if_pos h, if_pos (by simpa using i.unop.le h)] else ((if_neg h).symm.ndrec terminalIsTerminal).from _ map_id U := (em (pβ‚€ ∈ U.unop)).elim (fun h => dif_pos h) fun h => ((if_neg h).symm.ndrec terminalIsTerminal).hom_ext _ _ map_comp {U V W} iVU iWV := by by_cases hW : pβ‚€ ∈ unop W Β· have hV : pβ‚€ ∈ unop V := leOfHom iWV.unop hW simp only [dif_pos hW, dif_pos hV, eqToHom_trans] Β· dsimp; rw [dif_neg hW]; apply ((if_neg hW).symm.ndrec terminalIsTerminal).hom_ext theorem skyscraperPresheaf_eq_pushforward [hd : βˆ€ U : Opens (TopCat.of PUnit.{u + 1}), Decidable (PUnit.unit ∈ U)] : skyscraperPresheaf pβ‚€ A = (ofHom (ContinuousMap.const (TopCat.of PUnit) pβ‚€)) _* skyscraperPresheaf (X := TopCat.of PUnit) PUnit.unit A := by convert_to @skyscraperPresheaf X pβ‚€ (fun U => hd <| (Opens.map <| ofHom <| ContinuousMap.const _ pβ‚€).obj U) C _ _ A = _ <;> congr /-- Taking skyscraper presheaf at a point is functorial: `c ↦ skyscraper pβ‚€ c` defines a functor by sending every `f : a ⟢ b` to the natural transformation `Ξ±` defined as: `Ξ±(U) = f : a ⟢ b` if `pβ‚€ ∈ U` and the unique morphism to a terminal object in `C` if `pβ‚€ βˆ‰ U`. -/ @[simps] def SkyscraperPresheafFunctor.map' {a b : C} (f : a ⟢ b) : skyscraperPresheaf pβ‚€ a ⟢ skyscraperPresheaf pβ‚€ b where app U := if h : pβ‚€ ∈ U.unop then eqToHom (if_pos h) ≫ f ≫ eqToHom (if_pos h).symm else ((if_neg h).symm.ndrec terminalIsTerminal).from _ naturality U V i := by simp only [skyscraperPresheaf_map] by_cases hV : pβ‚€ ∈ V.unop Β· have hU : pβ‚€ ∈ U.unop := leOfHom i.unop hV simp only [skyscraperPresheaf_obj, hU, hV, ↓reduceDIte, eqToHom_trans_assoc, Category.assoc, eqToHom_trans] Β· apply ((if_neg hV).symm.ndrec terminalIsTerminal).hom_ext theorem SkyscraperPresheafFunctor.map'_id {a : C} :
SkyscraperPresheafFunctor.map' pβ‚€ (πŸ™ a) = πŸ™ _ := by ext U simp only [SkyscraperPresheafFunctor.map'_app, NatTrans.id_app]; split_ifs <;> aesop_cat
Mathlib/Topology/Sheaves/Skyscraper.lean
94
97
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Order.Interval.Set.OrderEmbedding import Mathlib.Order.Antichain import Mathlib.Order.SetNotation /-! # Order-connected sets We say that a set `s : Set Ξ±` is `OrdConnected` if for all `x y ∈ s` it includes the interval `[[x, y]]`. If `Ξ±` is a `DenselyOrdered` `ConditionallyCompleteLinearOrder` with the `OrderTopology`, then this condition is equivalent to `IsPreconnected s`. If `Ξ±` is a `LinearOrderedField`, then this condition is also equivalent to `Convex Ξ± s`. In this file we prove that intersection of a family of `OrdConnected` sets is `OrdConnected` and that all standard intervals are `OrdConnected`. -/ open scoped Interval open Set open OrderDual (toDual ofDual) namespace Set section Preorder variable {Ξ± Ξ² : Type*} [Preorder Ξ±] [Preorder Ξ²] {s : Set Ξ±} theorem OrdConnected.out (h : OrdConnected s) : βˆ€ ⦃x⦄ (_ : x ∈ s) ⦃y⦄ (_ : y ∈ s), Icc x y βŠ† s := h.1 theorem ordConnected_def : OrdConnected s ↔ βˆ€ ⦃x⦄ (_ : x ∈ s) ⦃y⦄ (_ : y ∈ s), Icc x y βŠ† s := ⟨fun h => h.1, fun h => ⟨h⟩⟩ /-- It suffices to prove `[[x, y]] βŠ† s` for `x y ∈ s`, `x ≀ y`. -/ theorem ordConnected_iff : OrdConnected s ↔ βˆ€ x ∈ s, βˆ€ y ∈ s, x ≀ y β†’ Icc x y βŠ† s := ordConnected_def.trans ⟨fun hs _ hx _ hy _ => hs hx hy, fun H x hx y hy _ hz => H x hx y hy (le_trans hz.1 hz.2) hz⟩ theorem ordConnected_of_Ioo {Ξ± : Type*} [PartialOrder Ξ±] {s : Set Ξ±} (hs : βˆ€ x ∈ s, βˆ€ y ∈ s, x < y β†’ Ioo x y βŠ† s) : OrdConnected s := by rw [ordConnected_iff] intro x hx y hy hxy rcases eq_or_lt_of_le hxy with (rfl | hxy'); Β· simpa rw [← Ioc_insert_left hxy, ← Ioo_insert_right hxy'] exact insert_subset_iff.2 ⟨hx, insert_subset_iff.2 ⟨hy, hs x hx y hy hxy'⟩⟩ theorem OrdConnected.preimage_mono {f : Ξ² β†’ Ξ±} (hs : OrdConnected s) (hf : Monotone f) : OrdConnected (f ⁻¹' s) := ⟨fun _ hx _ hy _ hz => hs.out hx hy ⟨hf hz.1, hf hz.2⟩⟩ theorem OrdConnected.preimage_anti {f : Ξ² β†’ Ξ±} (hs : OrdConnected s) (hf : Antitone f) : OrdConnected (f ⁻¹' s) := ⟨fun _ hx _ hy _ hz => hs.out hy hx ⟨hf hz.2, hf hz.1⟩⟩ protected theorem Icc_subset (s : Set Ξ±) [hs : OrdConnected s] {x y} (hx : x ∈ s) (hy : y ∈ s) : Icc x y βŠ† s := hs.out hx hy end Preorder end Set namespace OrderEmbedding variable {Ξ± Ξ² : Type*} [Preorder Ξ±] [Preorder Ξ²] theorem image_Icc (e : Ξ± β†ͺo Ξ²) (he : OrdConnected (range e)) (x y : Ξ±) : e '' Icc x y = Icc (e x) (e y) := by rw [← e.preimage_Icc, image_preimage_eq_inter_range, inter_eq_left.2 (he.out ⟨_, rfl⟩ ⟨_, rfl⟩)] theorem image_Ico (e : Ξ± β†ͺo Ξ²) (he : OrdConnected (range e)) (x y : Ξ±) : e '' Ico x y = Ico (e x) (e y) := by rw [← e.preimage_Ico, image_preimage_eq_inter_range, inter_eq_left.2 <| Ico_subset_Icc_self.trans <| he.out ⟨_, rfl⟩ ⟨_, rfl⟩] theorem image_Ioc (e : Ξ± β†ͺo Ξ²) (he : OrdConnected (range e)) (x y : Ξ±) : e '' Ioc x y = Ioc (e x) (e y) := by rw [← e.preimage_Ioc, image_preimage_eq_inter_range, inter_eq_left.2 <| Ioc_subset_Icc_self.trans <| he.out ⟨_, rfl⟩ ⟨_, rfl⟩] theorem image_Ioo (e : Ξ± β†ͺo Ξ²) (he : OrdConnected (range e)) (x y : Ξ±) : e '' Ioo x y = Ioo (e x) (e y) := by rw [← e.preimage_Ioo, image_preimage_eq_inter_range, inter_eq_left.2 <| Ioo_subset_Icc_self.trans <| he.out ⟨_, rfl⟩ ⟨_, rfl⟩] end OrderEmbedding namespace Set section Preorder variable {Ξ± Ξ² : Type*} [Preorder Ξ±] [Preorder Ξ²] @[simp] lemma image_subtype_val_Icc {s : Set Ξ±} [OrdConnected s] (x y : s) : Subtype.val '' Icc x y = Icc x.1 y := (OrderEmbedding.subtype (Β· ∈ s)).image_Icc (by simpa) x y @[simp] lemma image_subtype_val_Ico {s : Set Ξ±} [OrdConnected s] (x y : s) : Subtype.val '' Ico x y = Ico x.1 y := (OrderEmbedding.subtype (Β· ∈ s)).image_Ico (by simpa) x y @[simp] lemma image_subtype_val_Ioc {s : Set Ξ±} [OrdConnected s] (x y : s) : Subtype.val '' Ioc x y = Ioc x.1 y := (OrderEmbedding.subtype (Β· ∈ s)).image_Ioc (by simpa) x y @[simp] lemma image_subtype_val_Ioo {s : Set Ξ±} [OrdConnected s] (x y : s) : Subtype.val '' Ioo x y = Ioo x.1 y := (OrderEmbedding.subtype (Β· ∈ s)).image_Ioo (by simpa) x y theorem OrdConnected.inter {s t : Set Ξ±} (hs : OrdConnected s) (ht : OrdConnected t) : OrdConnected (s ∩ t) := ⟨fun _ hx _ hy => subset_inter (hs.out hx.1 hy.1) (ht.out hx.2 hy.2)⟩ instance OrdConnected.inter' {s t : Set Ξ±} [OrdConnected s] [OrdConnected t] : OrdConnected (s ∩ t) := OrdConnected.inter β€Ή_β€Ί β€Ή_β€Ί theorem OrdConnected.dual {s : Set Ξ±} (hs : OrdConnected s) : OrdConnected (OrderDual.ofDual ⁻¹' s) := ⟨fun _ hx _ hy _ hz => hs.out hy hx ⟨hz.2, hz.1⟩⟩ theorem ordConnected_dual {s : Set Ξ±} : OrdConnected (OrderDual.ofDual ⁻¹' s) ↔ OrdConnected s := ⟨fun h => by simpa only [ordConnected_def] using h.dual, fun h => h.dual⟩ theorem ordConnected_sInter {S : Set (Set Ξ±)} (hS : βˆ€ s ∈ S, OrdConnected s) : OrdConnected (β‹‚β‚€ S) := ⟨fun _x hx _y hy _z hz s hs => (hS s hs).out (hx s hs) (hy s hs) hz⟩ theorem ordConnected_iInter {ΞΉ : Sort*} {s : ΞΉ β†’ Set Ξ±} (hs : βˆ€ i, OrdConnected (s i)) : OrdConnected (β‹‚ i, s i) := ordConnected_sInter <| forall_mem_range.2 hs instance ordConnected_iInter' {ΞΉ : Sort*} {s : ΞΉ β†’ Set Ξ±} [βˆ€ i, OrdConnected (s i)] : OrdConnected (β‹‚ i, s i) := ordConnected_iInter β€Ή_β€Ί theorem ordConnected_biInter {ΞΉ : Sort*} {p : ΞΉ β†’ Prop} {s : βˆ€ i, p i β†’ Set Ξ±} (hs : βˆ€ i hi, OrdConnected (s i hi)) : OrdConnected (β‹‚ (i) (hi), s i hi) := ordConnected_iInter fun i => ordConnected_iInter <| hs i theorem ordConnected_pi {ΞΉ : Type*} {Ξ± : ΞΉ β†’ Type*} [βˆ€ i, Preorder (Ξ± i)] {s : Set ΞΉ} {t : βˆ€ i, Set (Ξ± i)} (h : βˆ€ i ∈ s, OrdConnected (t i)) : OrdConnected (s.pi t) := ⟨fun _ hx _ hy _ hz i hi => (h i hi).out (hx i hi) (hy i hi) ⟨hz.1 i, hz.2 i⟩⟩ instance ordConnected_pi' {ΞΉ : Type*} {Ξ± : ΞΉ β†’ Type*} [βˆ€ i, Preorder (Ξ± i)] {s : Set ΞΉ} {t : βˆ€ i, Set (Ξ± i)} [h : βˆ€ i, OrdConnected (t i)] : OrdConnected (s.pi t) := ordConnected_pi fun i _ => h i @[instance] theorem ordConnected_Ici {a : Ξ±} : OrdConnected (Ici a) := ⟨fun _ hx _ _ _ hz => le_trans hx hz.1⟩ @[instance] theorem ordConnected_Iic {a : Ξ±} : OrdConnected (Iic a) := ⟨fun _ _ _ hy _ hz => le_trans hz.2 hy⟩ @[instance] theorem ordConnected_Ioi {a : Ξ±} : OrdConnected (Ioi a) := ⟨fun _ hx _ _ _ hz => lt_of_lt_of_le hx hz.1⟩ @[instance] theorem ordConnected_Iio {a : Ξ±} : OrdConnected (Iio a) := ⟨fun _ _ _ hy _ hz => lt_of_le_of_lt hz.2 hy⟩ @[instance] theorem ordConnected_Icc {a b : Ξ±} : OrdConnected (Icc a b) := ordConnected_Ici.inter ordConnected_Iic @[instance] theorem ordConnected_Ico {a b : Ξ±} : OrdConnected (Ico a b) := ordConnected_Ici.inter ordConnected_Iio @[instance] theorem ordConnected_Ioc {a b : Ξ±} : OrdConnected (Ioc a b) := ordConnected_Ioi.inter ordConnected_Iic @[instance] theorem ordConnected_Ioo {a b : Ξ±} : OrdConnected (Ioo a b) := ordConnected_Ioi.inter ordConnected_Iio @[instance] theorem ordConnected_singleton {Ξ± : Type*} [PartialOrder Ξ±] {a : Ξ±} : OrdConnected ({a} : Set Ξ±) := by rw [← Icc_self] exact ordConnected_Icc @[instance] theorem ordConnected_empty : OrdConnected (βˆ… : Set Ξ±) := ⟨fun _ => False.elim⟩ @[instance] theorem ordConnected_univ : OrdConnected (univ : Set Ξ±) := ⟨fun _ _ _ _ => subset_univ _⟩ /-- In a dense order `Ξ±`, the subtype from an `OrdConnected` set is also densely ordered. -/ instance instDenselyOrdered [DenselyOrdered Ξ±] {s : Set Ξ±} [hs : OrdConnected s] : DenselyOrdered s := ⟨fun a b (h : (a : Ξ±) < b) => let ⟨x, H⟩ := exists_between h ⟨⟨x, (hs.out a.2 b.2) (Ioo_subset_Icc_self H)⟩, H⟩⟩ @[instance] theorem ordConnected_preimage {F : Type*} [FunLike F Ξ± Ξ²] [OrderHomClass F Ξ± Ξ²] (f : F) {s : Set Ξ²} [hs : OrdConnected s] : OrdConnected (f ⁻¹' s) := ⟨fun _ hx _ hy _ hz => hs.out hx hy ⟨OrderHomClass.mono _ hz.1, OrderHomClass.mono _ hz.2⟩⟩ @[instance] theorem ordConnected_image {E : Type*} [EquivLike E Ξ± Ξ²] [OrderIsoClass E Ξ± Ξ²] (e : E) {s : Set Ξ±} [hs : OrdConnected s] : OrdConnected (e '' s) := by erw [(e : Ξ± ≃o Ξ²).image_eq_preimage] apply ordConnected_preimage (e : Ξ± ≃o Ξ²).symm @[instance] theorem ordConnected_range {E : Type*} [EquivLike E Ξ± Ξ²] [OrderIsoClass E Ξ± Ξ²] (e : E) : OrdConnected (range e) := by simp_rw [← image_univ] exact ordConnected_image (e : Ξ± ≃o Ξ²) @[simp] theorem dual_ordConnected_iff {s : Set Ξ±} : OrdConnected (ofDual ⁻¹' s) ↔ OrdConnected s := by simp_rw [ordConnected_def, toDual.surjective.forall, Icc_toDual, Subtype.forall'] exact forall_swap @[instance] theorem dual_ordConnected {s : Set Ξ±} [OrdConnected s] : OrdConnected (ofDual ⁻¹' s) := dual_ordConnected_iff.2 β€Ή_β€Ί end Preorder section PartialOrder variable {Ξ± : Type*} [PartialOrder Ξ±] {s : Set Ξ±} {x y : Ξ±} protected theorem _root_.IsAntichain.ordConnected (hs : IsAntichain (Β· ≀ Β·) s) : s.OrdConnected := ⟨fun x hx y hy z hz => by obtain rfl := hs.eq hx hy (hz.1.trans hz.2) rw [Icc_self, mem_singleton_iff] at hz rwa [hz]⟩ lemma ordConnected_inter_Icc_of_subset (h : Ioo x y βŠ† s) : OrdConnected (s ∩ Icc x y) := ordConnected_of_Ioo fun _u ⟨_, hu, _⟩ _v ⟨_, _, hv⟩ _ ↦ Ioo_subset_Ioo hu hv |>.trans <| subset_inter h Ioo_subset_Icc_self lemma ordConnected_inter_Icc_iff (hx : x ∈ s) (hy : y ∈ s) : OrdConnected (s ∩ Icc x y) ↔ Ioo x y βŠ† s := by refine ⟨fun h ↦ Ioo_subset_Icc_self.trans fun z hz ↦ ?_, ordConnected_inter_Icc_of_subset⟩ have hxy : x ≀ y := hz.1.trans hz.2 exact h.out ⟨hx, left_mem_Icc.2 hxy⟩ ⟨hy, right_mem_Icc.2 hxy⟩ hz |>.1 lemma not_ordConnected_inter_Icc_iff (hx : x ∈ s) (hy : y ∈ s) : Β¬ OrdConnected (s ∩ Icc x y) ↔ βˆƒ z βˆ‰ s, z ∈ Ioo x y := by simp_rw [ordConnected_inter_Icc_iff hx hy, subset_def, not_forall, exists_prop, and_comm] end PartialOrder section LinearOrder open scoped Interval variable {Ξ± : Type*} [LinearOrder Ξ±] {s : Set Ξ±} {x : Ξ±} @[instance] theorem ordConnected_uIcc {a b : Ξ±} : OrdConnected [[a, b]] := ordConnected_Icc @[instance] theorem ordConnected_uIoc {a b : Ξ±} : OrdConnected (Ξ™ a b) := ordConnected_Ioc theorem OrdConnected.uIcc_subset (hs : OrdConnected s) ⦃x⦄ (hx : x ∈ s) ⦃y⦄ (hy : y ∈ s) : [[x, y]] βŠ† s := hs.out (min_rec' (Β· ∈ s) hx hy) (max_rec' (Β· ∈ s) hx hy) theorem OrdConnected.uIoc_subset (hs : OrdConnected s) ⦃x⦄ (hx : x ∈ s) ⦃y⦄ (hy : y ∈ s) : Ξ™ x y βŠ† s := Ioc_subset_Icc_self.trans <| hs.uIcc_subset hx hy theorem ordConnected_iff_uIcc_subset : OrdConnected s ↔ βˆ€ ⦃x⦄ (_ : x ∈ s) ⦃y⦄ (_ : y ∈ s), [[x, y]] βŠ† s := ⟨fun h => h.uIcc_subset, fun H => ⟨fun _ hx _ hy => Icc_subset_uIcc.trans <| H hx hy⟩⟩ theorem ordConnected_of_uIcc_subset_left (h : βˆ€ y ∈ s, [[x, y]] βŠ† s) : OrdConnected s := ordConnected_iff_uIcc_subset.2 fun y hy z hz => calc [[y, z]] βŠ† [[y, x]] βˆͺ [[x, z]] := uIcc_subset_uIcc_union_uIcc _ = [[x, y]] βˆͺ [[x, z]] := by rw [uIcc_comm] _ βŠ† s := union_subset (h y hy) (h z hz) theorem ordConnected_iff_uIcc_subset_left (hx : x ∈ s) : OrdConnected s ↔ βˆ€ ⦃y⦄, y ∈ s β†’ [[x, y]] βŠ† s := ⟨fun hs => hs.uIcc_subset hx, ordConnected_of_uIcc_subset_left⟩ theorem ordConnected_iff_uIcc_subset_right (hx : x ∈ s) : OrdConnected s ↔ βˆ€ ⦃y⦄, y ∈ s β†’ [[y, x]] βŠ† s := by simp_rw [ordConnected_iff_uIcc_subset_left hx, uIcc_comm] end LinearOrder end Set
Mathlib/Order/Interval/Set/OrdConnected.lean
353
355
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.Algebra.Group.Defs /-! # Invertible elements This file defines a typeclass `Invertible a` for elements `a` with a two-sided multiplicative inverse. The intent of the typeclass is to provide a way to write e.g. `β…Ÿ2` in a ring like `β„€[1/2]` where some inverses exist but there is no general `⁻¹` operator; or to specify that a field has characteristic `β‰  2`. It is the `Type`-valued analogue to the `Prop`-valued `IsUnit`. For constructions of the invertible element given a characteristic, see `Algebra/CharP/Invertible` and other lemmas in that file. ## Notation * `β…Ÿa` is `Invertible.invOf a`, the inverse of `a` ## Implementation notes The `Invertible` class lives in `Type`, not `Prop`, to make computation easier. If multiplication is associative, `Invertible` is a subsingleton anyway. The `simp` normal form tries to normalize `β…Ÿa` to `a ⁻¹`. Otherwise, it pushes `β…Ÿ` inside the expression as much as possible. Since `Invertible a` is not a `Prop` (but it is a `Subsingleton`), we have to be careful about coherence issues: we should avoid having multiple non-defeq instances for `Invertible a` in the same context. This file plays it safe and uses `def` rather than `instance` for most definitions, users can choose which instances to use at the point of use. For example, here's how you can use an `Invertible 1` instance: ```lean variable {Ξ± : Type*} [Monoid Ξ±] def something_that_needs_inverses (x : Ξ±) [Invertible x] := sorry section attribute [local instance] invertibleOne def something_one := something_that_needs_inverses 1 end ``` ### Typeclass search vs. unification for `simp` lemmas Note that since typeclass search searches the local context first, an instance argument like `[Invertible a]` might sometimes be filled by a different term than the one we'd find by unification (i.e., the one that's used as an implicit argument to `β…Ÿ`). This can cause issues with `simp`. Therefore, some lemmas are duplicated, with the `@[simp]` versions using unification and the user-facing ones using typeclass search. Since unification can make backwards rewriting (e.g. `rw [← mylemma]`) impractical, we still want the instance-argument versions; therefore the user-facing versions retain the instance arguments and the original lemma name, whereas the `@[simp]`/unification ones acquire a `'` at the end of their name. We modify this file according to the above pattern only as needed; therefore, most `@[simp]` lemmas here are not part of such a duplicate pair. This is not (yet) intended as a permanent solution. See Zulip: [https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Invertible.201.20simps/near/320558233] ## Tags invertible, inverse element, invOf, a half, one half, a third, one third, Β½, β…“ -/ assert_not_exists MonoidWithZero DenselyOrdered universe u variable {Ξ± : Type u} /-- `Invertible a` gives a two-sided multiplicative inverse of `a`. -/ class Invertible [Mul Ξ±] [One Ξ±] (a : Ξ±) : Type u where /-- The inverse of an `Invertible` element -/ invOf : Ξ± /-- `invOf a` is a left inverse of `a` -/ invOf_mul_self : invOf * a = 1 /-- `invOf a` is a right inverse of `a` -/ mul_invOf_self : a * invOf = 1 /-- The inverse of an `Invertible` element -/ -- This notation has the same precedence as `Inv.inv`. prefix:max "β…Ÿ " => Invertible.invOf @[simp] theorem invOf_mul_self' [Mul Ξ±] [One Ξ±] (a : Ξ±) {_ : Invertible a} : β…Ÿ a * a = 1 := Invertible.invOf_mul_self theorem invOf_mul_self [Mul Ξ±] [One Ξ±] (a : Ξ±) [Invertible a] : β…Ÿ a * a = 1 := invOf_mul_self' _ @[simp] theorem mul_invOf_self' [Mul Ξ±] [One Ξ±] (a : Ξ±) {_ : Invertible a} : a * β…Ÿ a = 1 := Invertible.mul_invOf_self theorem mul_invOf_self [Mul Ξ±] [One Ξ±] (a : Ξ±) [Invertible a] : a * β…Ÿ a = 1 := mul_invOf_self' _ @[simp] theorem invOf_mul_cancel_left' [Monoid Ξ±] (a b : Ξ±) {_ : Invertible a} : β…Ÿ a * (a * b) = b := by rw [← mul_assoc, invOf_mul_self, one_mul] example {G} [Group G] (a b : G) : a⁻¹ * (a * b) = b := inv_mul_cancel_left a b theorem invOf_mul_cancel_left [Monoid Ξ±] (a b : Ξ±) [Invertible a] : β…Ÿ a * (a * b) = b := invOf_mul_cancel_left' _ _ @[simp] theorem mul_invOf_cancel_left' [Monoid Ξ±] (a b : Ξ±) {_ : Invertible a} : a * (β…Ÿ a * b) = b := by rw [← mul_assoc, mul_invOf_self, one_mul] example {G} [Group G] (a b : G) : a * (a⁻¹ * b) = b := mul_inv_cancel_left a b theorem mul_invOf_cancel_left [Monoid Ξ±] (a b : Ξ±) [Invertible a] : a * (β…Ÿ a * b) = b := mul_invOf_cancel_left' a b @[simp] theorem invOf_mul_cancel_right' [Monoid Ξ±] (a b : Ξ±) {_ : Invertible b} : a * β…Ÿ b * b = a := by simp [mul_assoc] example {G} [Group G] (a b : G) : a * b⁻¹ * b = a := inv_mul_cancel_right a b theorem invOf_mul_cancel_right [Monoid Ξ±] (a b : Ξ±) [Invertible b] : a * β…Ÿ b * b = a := invOf_mul_cancel_right' _ _ @[simp] theorem mul_invOf_cancel_right' [Monoid Ξ±] (a b : Ξ±) {_ : Invertible b} : a * b * β…Ÿ b = a := by simp [mul_assoc] example {G} [Group G] (a b : G) : a * b * b⁻¹ = a := mul_inv_cancel_right a b
theorem mul_invOf_cancel_right [Monoid Ξ±] (a b : Ξ±) [Invertible b] : a * b * β…Ÿ b = a := mul_invOf_cancel_right' _ _
Mathlib/Algebra/Group/Invertible/Defs.lean
136
137
/- 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, Yury Kudryashov, RΓ©my Degenne -/ import Mathlib.Data.Set.Subsingleton import Mathlib.Order.Interval.Set.Defs /-! # Intervals In any preorder, we define intervals (which on each side can be either infinite, open or closed) using the following naming conventions: - `i`: infinite - `o`: open - `c`: closed Each interval has the name `I` + letter for left side + letter for right side. For instance, `Ioc a b` denotes the interval `(a, b]`. The definitions can be found in `Mathlib.Order.Interval.Set.Defs`. This file contains basic facts on inclusion of and set operations on intervals (where the precise statements depend on the order's properties; statements requiring `LinearOrder` are in `Mathlib.Order.Interval.Set.LinearOrder`). TODO: This is just the beginning; a lot of rules are missing -/ assert_not_exists RelIso open Function open OrderDual (toDual ofDual) variable {Ξ± : Type*} namespace Set section Preorder variable [Preorder Ξ±] {a a₁ aβ‚‚ b b₁ bβ‚‚ c x : Ξ±} instance decidableMemIoo [Decidable (a < x ∧ x < b)] : Decidable (x ∈ Ioo a b) := by assumption instance decidableMemIco [Decidable (a ≀ x ∧ x < b)] : Decidable (x ∈ Ico a b) := by assumption instance decidableMemIio [Decidable (x < b)] : Decidable (x ∈ Iio b) := by assumption instance decidableMemIcc [Decidable (a ≀ x ∧ x ≀ b)] : Decidable (x ∈ Icc a b) := by assumption instance decidableMemIic [Decidable (x ≀ b)] : Decidable (x ∈ Iic b) := by assumption instance decidableMemIoc [Decidable (a < x ∧ x ≀ b)] : Decidable (x ∈ Ioc a b) := by assumption instance decidableMemIci [Decidable (a ≀ x)] : Decidable (x ∈ Ici a) := by assumption instance decidableMemIoi [Decidable (a < x)] : Decidable (x ∈ Ioi a) := by assumption theorem left_mem_Ioo : a ∈ Ioo a b ↔ False := by simp [lt_irrefl] theorem left_mem_Ico : a ∈ Ico a b ↔ a < b := by simp [le_refl] theorem left_mem_Icc : a ∈ Icc a b ↔ a ≀ b := by simp [le_refl] theorem left_mem_Ioc : a ∈ Ioc a b ↔ False := by simp [lt_irrefl] theorem left_mem_Ici : a ∈ Ici a := by simp theorem right_mem_Ioo : b ∈ Ioo a b ↔ False := by simp [lt_irrefl] theorem right_mem_Ico : b ∈ Ico a b ↔ False := by simp [lt_irrefl] theorem right_mem_Icc : b ∈ Icc a b ↔ a ≀ b := by simp [le_refl] theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b := by simp [le_refl] theorem right_mem_Iic : a ∈ Iic a := by simp @[simp] theorem Ici_toDual : Ici (toDual a) = ofDual ⁻¹' Iic a := rfl @[deprecated (since := "2025-03-20")] alias dual_Ici := Ici_toDual @[simp] theorem Iic_toDual : Iic (toDual a) = ofDual ⁻¹' Ici a := rfl @[deprecated (since := "2025-03-20")] alias dual_Iic := Iic_toDual @[simp] theorem Ioi_toDual : Ioi (toDual a) = ofDual ⁻¹' Iio a := rfl @[deprecated (since := "2025-03-20")] alias dual_Ioi := Ioi_toDual @[simp] theorem Iio_toDual : Iio (toDual a) = ofDual ⁻¹' Ioi a := rfl @[deprecated (since := "2025-03-20")] alias dual_Iio := Iio_toDual @[simp] theorem Icc_toDual : Icc (toDual a) (toDual b) = ofDual ⁻¹' Icc b a := Set.ext fun _ => and_comm @[deprecated (since := "2025-03-20")] alias dual_Icc := Icc_toDual @[simp] theorem Ioc_toDual : Ioc (toDual a) (toDual b) = ofDual ⁻¹' Ico b a := Set.ext fun _ => and_comm @[deprecated (since := "2025-03-20")] alias dual_Ioc := Ioc_toDual @[simp] theorem Ico_toDual : Ico (toDual a) (toDual b) = ofDual ⁻¹' Ioc b a := Set.ext fun _ => and_comm @[deprecated (since := "2025-03-20")] alias dual_Ico := Ico_toDual @[simp] theorem Ioo_toDual : Ioo (toDual a) (toDual b) = ofDual ⁻¹' Ioo b a := Set.ext fun _ => and_comm @[deprecated (since := "2025-03-20")] alias dual_Ioo := Ioo_toDual @[simp] theorem Ici_ofDual {x : Ξ±α΅’α΅ˆ} : Ici (ofDual x) = toDual ⁻¹' Iic x := rfl @[simp] theorem Iic_ofDual {x : Ξ±α΅’α΅ˆ} : Iic (ofDual x) = toDual ⁻¹' Ici x := rfl @[simp] theorem Ioi_ofDual {x : Ξ±α΅’α΅ˆ} : Ioi (ofDual x) = toDual ⁻¹' Iio x := rfl @[simp] theorem Iio_ofDual {x : Ξ±α΅’α΅ˆ} : Iio (ofDual x) = toDual ⁻¹' Ioi x := rfl @[simp] theorem Icc_ofDual {x y : Ξ±α΅’α΅ˆ} : Icc (ofDual y) (ofDual x) = toDual ⁻¹' Icc x y := Set.ext fun _ => and_comm @[simp] theorem Ico_ofDual {x y : Ξ±α΅’α΅ˆ} : Ico (ofDual y) (ofDual x) = toDual ⁻¹' Ioc x y := Set.ext fun _ => and_comm @[simp] theorem Ioc_ofDual {x y : Ξ±α΅’α΅ˆ} : Ioc (ofDual y) (ofDual x) = toDual ⁻¹' Ico x y := Set.ext fun _ => and_comm @[simp] theorem Ioo_ofDual {x y : Ξ±α΅’α΅ˆ} : Ioo (ofDual y) (ofDual x) = toDual ⁻¹' Ioo x y := Set.ext fun _ => and_comm @[simp] theorem nonempty_Icc : (Icc a b).Nonempty ↔ a ≀ b := ⟨fun ⟨_, hx⟩ => hx.1.trans hx.2, fun h => ⟨a, left_mem_Icc.2 h⟩⟩ @[simp] theorem nonempty_Ico : (Ico a b).Nonempty ↔ a < b := ⟨fun ⟨_, hx⟩ => hx.1.trans_lt hx.2, fun h => ⟨a, left_mem_Ico.2 h⟩⟩ @[simp] theorem nonempty_Ioc : (Ioc a b).Nonempty ↔ a < b := ⟨fun ⟨_, hx⟩ => hx.1.trans_le hx.2, fun h => ⟨b, right_mem_Ioc.2 h⟩⟩ @[simp] theorem nonempty_Ici : (Ici a).Nonempty := ⟨a, left_mem_Ici⟩ @[simp] theorem nonempty_Iic : (Iic a).Nonempty := ⟨a, right_mem_Iic⟩ @[simp] theorem nonempty_Ioo [DenselyOrdered Ξ±] : (Ioo a b).Nonempty ↔ a < b := ⟨fun ⟨_, ha, hb⟩ => ha.trans hb, exists_between⟩ @[simp] theorem nonempty_Ioi [NoMaxOrder Ξ±] : (Ioi a).Nonempty := exists_gt a @[simp] theorem nonempty_Iio [NoMinOrder Ξ±] : (Iio a).Nonempty := exists_lt a theorem nonempty_Icc_subtype (h : a ≀ b) : Nonempty (Icc a b) := Nonempty.to_subtype (nonempty_Icc.mpr h) theorem nonempty_Ico_subtype (h : a < b) : Nonempty (Ico a b) := Nonempty.to_subtype (nonempty_Ico.mpr h) theorem nonempty_Ioc_subtype (h : a < b) : Nonempty (Ioc a b) := Nonempty.to_subtype (nonempty_Ioc.mpr h) /-- An interval `Ici a` is nonempty. -/ instance nonempty_Ici_subtype : Nonempty (Ici a) := Nonempty.to_subtype nonempty_Ici /-- An interval `Iic a` is nonempty. -/ instance nonempty_Iic_subtype : Nonempty (Iic a) := Nonempty.to_subtype nonempty_Iic theorem nonempty_Ioo_subtype [DenselyOrdered Ξ±] (h : a < b) : Nonempty (Ioo a b) := Nonempty.to_subtype (nonempty_Ioo.mpr h) /-- In an order without maximal elements, the intervals `Ioi` are nonempty. -/ instance nonempty_Ioi_subtype [NoMaxOrder Ξ±] : Nonempty (Ioi a) := Nonempty.to_subtype nonempty_Ioi /-- In an order without minimal elements, the intervals `Iio` are nonempty. -/ instance nonempty_Iio_subtype [NoMinOrder Ξ±] : Nonempty (Iio a) := Nonempty.to_subtype nonempty_Iio instance [NoMinOrder Ξ±] : NoMinOrder (Iio a) := ⟨fun a => let ⟨b, hb⟩ := exists_lt (a : Ξ±) ⟨⟨b, lt_trans hb a.2⟩, hb⟩⟩ instance [NoMinOrder Ξ±] : NoMinOrder (Iic a) := ⟨fun a => let ⟨b, hb⟩ := exists_lt (a : Ξ±) ⟨⟨b, hb.le.trans a.2⟩, hb⟩⟩ instance [NoMaxOrder Ξ±] : NoMaxOrder (Ioi a) := OrderDual.noMaxOrder (Ξ± := Iio (toDual a)) instance [NoMaxOrder Ξ±] : NoMaxOrder (Ici a) := OrderDual.noMaxOrder (Ξ± := Iic (toDual a)) @[simp] theorem Icc_eq_empty (h : Β¬a ≀ b) : Icc a b = βˆ… := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans hb) @[simp] theorem Ico_eq_empty (h : Β¬a < b) : Ico a b = βˆ… := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans_lt hb) @[simp] theorem Ioc_eq_empty (h : Β¬a < b) : Ioc a b = βˆ… := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans_le hb) @[simp] theorem Ioo_eq_empty (h : Β¬a < b) : Ioo a b = βˆ… := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans hb) @[simp] theorem Icc_eq_empty_of_lt (h : b < a) : Icc a b = βˆ… := Icc_eq_empty h.not_le @[simp] theorem Ico_eq_empty_of_le (h : b ≀ a) : Ico a b = βˆ… := Ico_eq_empty h.not_lt @[simp] theorem Ioc_eq_empty_of_le (h : b ≀ a) : Ioc a b = βˆ… := Ioc_eq_empty h.not_lt @[simp] theorem Ioo_eq_empty_of_le (h : b ≀ a) : Ioo a b = βˆ… := Ioo_eq_empty h.not_lt theorem Ico_self (a : Ξ±) : Ico a a = βˆ… := Ico_eq_empty <| lt_irrefl _ theorem Ioc_self (a : Ξ±) : Ioc a a = βˆ… := Ioc_eq_empty <| lt_irrefl _ theorem Ioo_self (a : Ξ±) : Ioo a a = βˆ… := Ioo_eq_empty <| lt_irrefl _ @[simp] theorem Ici_subset_Ici : Ici a βŠ† Ici b ↔ b ≀ a := ⟨fun h => h <| left_mem_Ici, fun h _ hx => h.trans hx⟩ @[gcongr] alias ⟨_, _root_.GCongr.Ici_subset_Ici_of_le⟩ := Ici_subset_Ici @[simp] theorem Ici_ssubset_Ici : Ici a βŠ‚ Ici b ↔ b < a where mp h := by obtain ⟨ab, c, cb, ac⟩ := ssubset_iff_exists.mp h exact lt_of_le_not_le (Ici_subset_Ici.mp ab) (fun h' ↦ ac (h'.trans cb)) mpr h := (ssubset_iff_of_subset (Ici_subset_Ici.mpr h.le)).mpr ⟨b, right_mem_Iic, fun h' => h.not_le h'⟩ @[gcongr] alias ⟨_, _root_.GCongr.Ici_ssubset_Ici_of_le⟩ := Ici_ssubset_Ici @[simp] theorem Iic_subset_Iic : Iic a βŠ† Iic b ↔ a ≀ b := @Ici_subset_Ici Ξ±α΅’α΅ˆ _ _ _ @[gcongr] alias ⟨_, _root_.GCongr.Iic_subset_Iic_of_le⟩ := Iic_subset_Iic @[simp] theorem Iic_ssubset_Iic : Iic a βŠ‚ Iic b ↔ a < b := @Ici_ssubset_Ici Ξ±α΅’α΅ˆ _ _ _ @[gcongr] alias ⟨_, _root_.GCongr.Iic_ssubset_Iic_of_le⟩ := Iic_ssubset_Iic @[simp] theorem Ici_subset_Ioi : Ici a βŠ† Ioi b ↔ b < a := ⟨fun h => h left_mem_Ici, fun h _ hx => h.trans_le hx⟩ @[simp] theorem Iic_subset_Iio : Iic a βŠ† Iio b ↔ a < b := ⟨fun h => h right_mem_Iic, fun h _ hx => lt_of_le_of_lt hx h⟩ @[gcongr] theorem Ioo_subset_Ioo (h₁ : aβ‚‚ ≀ a₁) (hβ‚‚ : b₁ ≀ bβ‚‚) : Ioo a₁ b₁ βŠ† Ioo aβ‚‚ bβ‚‚ := fun _ ⟨hx₁, hxβ‚‚βŸ© => ⟨h₁.trans_lt hx₁, hxβ‚‚.trans_le hβ‚‚βŸ© @[gcongr] theorem Ioo_subset_Ioo_left (h : a₁ ≀ aβ‚‚) : Ioo aβ‚‚ b βŠ† Ioo a₁ b := Ioo_subset_Ioo h le_rfl @[gcongr] theorem Ioo_subset_Ioo_right (h : b₁ ≀ bβ‚‚) : Ioo a b₁ βŠ† Ioo a bβ‚‚ := Ioo_subset_Ioo le_rfl h @[gcongr] theorem Ico_subset_Ico (h₁ : aβ‚‚ ≀ a₁) (hβ‚‚ : b₁ ≀ bβ‚‚) : Ico a₁ b₁ βŠ† Ico aβ‚‚ bβ‚‚ := fun _ ⟨hx₁, hxβ‚‚βŸ© => ⟨h₁.trans hx₁, hxβ‚‚.trans_le hβ‚‚βŸ© @[gcongr] theorem Ico_subset_Ico_left (h : a₁ ≀ aβ‚‚) : Ico aβ‚‚ b βŠ† Ico a₁ b := Ico_subset_Ico h le_rfl @[gcongr] theorem Ico_subset_Ico_right (h : b₁ ≀ bβ‚‚) : Ico a b₁ βŠ† Ico a bβ‚‚ := Ico_subset_Ico le_rfl h @[gcongr] theorem Icc_subset_Icc (h₁ : aβ‚‚ ≀ a₁) (hβ‚‚ : b₁ ≀ bβ‚‚) : Icc a₁ b₁ βŠ† Icc aβ‚‚ bβ‚‚ := fun _ ⟨hx₁, hxβ‚‚βŸ© => ⟨h₁.trans hx₁, le_trans hxβ‚‚ hβ‚‚βŸ© @[gcongr] theorem Icc_subset_Icc_left (h : a₁ ≀ aβ‚‚) : Icc aβ‚‚ b βŠ† Icc a₁ b := Icc_subset_Icc h le_rfl @[gcongr] theorem Icc_subset_Icc_right (h : b₁ ≀ bβ‚‚) : Icc a b₁ βŠ† Icc a bβ‚‚ := Icc_subset_Icc le_rfl h theorem Icc_subset_Ioo (ha : aβ‚‚ < a₁) (hb : b₁ < bβ‚‚) : Icc a₁ b₁ βŠ† Ioo aβ‚‚ bβ‚‚ := fun _ hx => ⟨ha.trans_le hx.1, hx.2.trans_lt hb⟩ theorem Icc_subset_Ici_self : Icc a b βŠ† Ici a := fun _ => And.left theorem Icc_subset_Iic_self : Icc a b βŠ† Iic b := fun _ => And.right theorem Ioc_subset_Iic_self : Ioc a b βŠ† Iic b := fun _ => And.right @[gcongr] theorem Ioc_subset_Ioc (h₁ : aβ‚‚ ≀ a₁) (hβ‚‚ : b₁ ≀ bβ‚‚) : Ioc a₁ b₁ βŠ† Ioc aβ‚‚ bβ‚‚ := fun _ ⟨hx₁, hxβ‚‚βŸ© => ⟨h₁.trans_lt hx₁, hxβ‚‚.trans hβ‚‚βŸ© @[gcongr] theorem Ioc_subset_Ioc_left (h : a₁ ≀ aβ‚‚) : Ioc aβ‚‚ b βŠ† Ioc a₁ b := Ioc_subset_Ioc h le_rfl @[gcongr] theorem Ioc_subset_Ioc_right (h : b₁ ≀ bβ‚‚) : Ioc a b₁ βŠ† Ioc a bβ‚‚ := Ioc_subset_Ioc le_rfl h theorem Ico_subset_Ioo_left (h₁ : a₁ < aβ‚‚) : Ico aβ‚‚ b βŠ† Ioo a₁ b := fun _ => And.imp_left h₁.trans_le theorem Ioc_subset_Ioo_right (h : b₁ < bβ‚‚) : Ioc a b₁ βŠ† Ioo a bβ‚‚ := fun _ => And.imp_right fun h' => h'.trans_lt h theorem Icc_subset_Ico_right (h₁ : b₁ < bβ‚‚) : Icc a b₁ βŠ† Ico a bβ‚‚ := fun _ => And.imp_right fun hβ‚‚ => hβ‚‚.trans_lt h₁ theorem Ioo_subset_Ico_self : Ioo a b βŠ† Ico a b := fun _ => And.imp_left le_of_lt theorem Ioo_subset_Ioc_self : Ioo a b βŠ† Ioc a b := fun _ => And.imp_right le_of_lt theorem Ico_subset_Icc_self : Ico a b βŠ† Icc a b := fun _ => And.imp_right le_of_lt theorem Ioc_subset_Icc_self : Ioc a b βŠ† Icc a b := fun _ => And.imp_left le_of_lt theorem Ioo_subset_Icc_self : Ioo a b βŠ† Icc a b := Subset.trans Ioo_subset_Ico_self Ico_subset_Icc_self theorem Ico_subset_Iio_self : Ico a b βŠ† Iio b := fun _ => And.right theorem Ioo_subset_Iio_self : Ioo a b βŠ† Iio b := fun _ => And.right theorem Ioc_subset_Ioi_self : Ioc a b βŠ† Ioi a := fun _ => And.left theorem Ioo_subset_Ioi_self : Ioo a b βŠ† Ioi a := fun _ => And.left theorem Ioi_subset_Ici_self : Ioi a βŠ† Ici a := fun _ hx => le_of_lt hx theorem Iio_subset_Iic_self : Iio a βŠ† Iic a := fun _ hx => le_of_lt hx theorem Ico_subset_Ici_self : Ico a b βŠ† Ici a := fun _ => And.left theorem Ioi_ssubset_Ici_self : Ioi a βŠ‚ Ici a := ⟨Ioi_subset_Ici_self, fun h => lt_irrefl a (h le_rfl)⟩ theorem Iio_ssubset_Iic_self : Iio a βŠ‚ Iic a := @Ioi_ssubset_Ici_self Ξ±α΅’α΅ˆ _ _ theorem Icc_subset_Icc_iff (h₁ : a₁ ≀ b₁) : Icc a₁ b₁ βŠ† Icc aβ‚‚ bβ‚‚ ↔ aβ‚‚ ≀ a₁ ∧ b₁ ≀ bβ‚‚ := ⟨fun h => ⟨(h ⟨le_rfl, hβ‚βŸ©).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans hx, hx'.trans h'⟩⟩ theorem Icc_subset_Ioo_iff (h₁ : a₁ ≀ b₁) : Icc a₁ b₁ βŠ† Ioo aβ‚‚ bβ‚‚ ↔ aβ‚‚ < a₁ ∧ b₁ < bβ‚‚ := ⟨fun h => ⟨(h ⟨le_rfl, hβ‚βŸ©).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans_le hx, hx'.trans_lt h'⟩⟩ theorem Icc_subset_Ico_iff (h₁ : a₁ ≀ b₁) : Icc a₁ b₁ βŠ† Ico aβ‚‚ bβ‚‚ ↔ aβ‚‚ ≀ a₁ ∧ b₁ < bβ‚‚ := ⟨fun h => ⟨(h ⟨le_rfl, hβ‚βŸ©).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans hx, hx'.trans_lt h'⟩⟩ theorem Icc_subset_Ioc_iff (h₁ : a₁ ≀ b₁) : Icc a₁ b₁ βŠ† Ioc aβ‚‚ bβ‚‚ ↔ aβ‚‚ < a₁ ∧ b₁ ≀ bβ‚‚ := ⟨fun h => ⟨(h ⟨le_rfl, hβ‚βŸ©).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans_le hx, hx'.trans h'⟩⟩ theorem Icc_subset_Iio_iff (h₁ : a₁ ≀ b₁) : Icc a₁ b₁ βŠ† Iio bβ‚‚ ↔ b₁ < bβ‚‚ := ⟨fun h => h ⟨h₁, le_rfl⟩, fun h _ ⟨_, hx'⟩ => hx'.trans_lt h⟩ theorem Icc_subset_Ioi_iff (h₁ : a₁ ≀ b₁) : Icc a₁ b₁ βŠ† Ioi aβ‚‚ ↔ aβ‚‚ < a₁ := ⟨fun h => h ⟨le_rfl, hβ‚βŸ©, fun h _ ⟨hx, _⟩ => h.trans_le hx⟩ theorem Icc_subset_Iic_iff (h₁ : a₁ ≀ b₁) : Icc a₁ b₁ βŠ† Iic bβ‚‚ ↔ b₁ ≀ bβ‚‚ := ⟨fun h => h ⟨h₁, le_rfl⟩, fun h _ ⟨_, hx'⟩ => hx'.trans h⟩ theorem Icc_subset_Ici_iff (h₁ : a₁ ≀ b₁) : Icc a₁ b₁ βŠ† Ici aβ‚‚ ↔ aβ‚‚ ≀ a₁ := ⟨fun h => h ⟨le_rfl, hβ‚βŸ©, fun h _ ⟨hx, _⟩ => h.trans hx⟩ theorem Icc_ssubset_Icc_left (hI : aβ‚‚ ≀ bβ‚‚) (ha : aβ‚‚ < a₁) (hb : b₁ ≀ bβ‚‚) : Icc a₁ b₁ βŠ‚ Icc aβ‚‚ bβ‚‚ := (ssubset_iff_of_subset (Icc_subset_Icc (le_of_lt ha) hb)).mpr ⟨aβ‚‚, left_mem_Icc.mpr hI, not_and.mpr fun f _ => lt_irrefl aβ‚‚ (ha.trans_le f)⟩ theorem Icc_ssubset_Icc_right (hI : aβ‚‚ ≀ bβ‚‚) (ha : aβ‚‚ ≀ a₁) (hb : b₁ < bβ‚‚) : Icc a₁ b₁ βŠ‚ Icc aβ‚‚ bβ‚‚ := (ssubset_iff_of_subset (Icc_subset_Icc ha (le_of_lt hb))).mpr ⟨bβ‚‚, right_mem_Icc.mpr hI, fun f => lt_irrefl b₁ (hb.trans_le f.2)⟩ /-- If `a ≀ b`, then `(b, +∞) βŠ† (a, +∞)`. In preorders, this is just an implication. If you need the equivalence in linear orders, use `Ioi_subset_Ioi_iff`. -/ @[gcongr] theorem Ioi_subset_Ioi (h : a ≀ b) : Ioi b βŠ† Ioi a := fun _ hx => h.trans_lt hx /-- If `a < b`, then `(b, +∞) βŠ‚ (a, +∞)`. In preorders, this is just an implication. If you need the equivalence in linear orders, use `Ioi_ssubset_Ioi_iff`. -/ @[gcongr] theorem Ioi_ssubset_Ioi (h : a < b) : Ioi b βŠ‚ Ioi a := (ssubset_iff_of_subset (Ioi_subset_Ioi h.le)).mpr ⟨b, h, lt_irrefl b⟩ /-- If `a ≀ b`, then `(b, +∞) βŠ† [a, +∞)`. In preorders, this is just an implication. If you need the equivalence in dense linear orders, use `Ioi_subset_Ici_iff`. -/ theorem Ioi_subset_Ici (h : a ≀ b) : Ioi b βŠ† Ici a := Subset.trans (Ioi_subset_Ioi h) Ioi_subset_Ici_self /-- If `a ≀ b`, then `(-∞, a) βŠ† (-∞, b)`. In preorders, this is just an implication. If you need the equivalence in linear orders, use `Iio_subset_Iio_iff`. -/ @[gcongr] theorem Iio_subset_Iio (h : a ≀ b) : Iio a βŠ† Iio b := fun _ hx => lt_of_lt_of_le hx h /-- If `a < b`, then `(-∞, a) βŠ‚ (-∞, b)`. In preorders, this is just an implication. If you need the equivalence in linear orders, use `Iio_ssubset_Iio_iff`. -/ @[gcongr] theorem Iio_ssubset_Iio (h : a < b) : Iio a βŠ‚ Iio b := (ssubset_iff_of_subset (Iio_subset_Iio h.le)).mpr ⟨a, h, lt_irrefl a⟩ /-- If `a ≀ b`, then `(-∞, a) βŠ† (-∞, b]`. In preorders, this is just an implication. If you need the equivalence in dense linear orders, use `Iio_subset_Iic_iff`. -/ theorem Iio_subset_Iic (h : a ≀ b) : Iio a βŠ† Iic b := Subset.trans (Iio_subset_Iio h) Iio_subset_Iic_self theorem Ici_inter_Iic : Ici a ∩ Iic b = Icc a b := rfl theorem Ici_inter_Iio : Ici a ∩ Iio b = Ico a b := rfl theorem Ioi_inter_Iic : Ioi a ∩ Iic b = Ioc a b := rfl theorem Ioi_inter_Iio : Ioi a ∩ Iio b = Ioo a b := rfl theorem Iic_inter_Ici : Iic a ∩ Ici b = Icc b a := inter_comm _ _ theorem Iio_inter_Ici : Iio a ∩ Ici b = Ico b a := inter_comm _ _ theorem Iic_inter_Ioi : Iic a ∩ Ioi b = Ioc b a := inter_comm _ _ theorem Iio_inter_Ioi : Iio a ∩ Ioi b = Ioo b a := inter_comm _ _ theorem mem_Icc_of_Ioo (h : x ∈ Ioo a b) : x ∈ Icc a b := Ioo_subset_Icc_self h theorem mem_Ico_of_Ioo (h : x ∈ Ioo a b) : x ∈ Ico a b := Ioo_subset_Ico_self h theorem mem_Ioc_of_Ioo (h : x ∈ Ioo a b) : x ∈ Ioc a b := Ioo_subset_Ioc_self h theorem mem_Icc_of_Ico (h : x ∈ Ico a b) : x ∈ Icc a b := Ico_subset_Icc_self h theorem mem_Icc_of_Ioc (h : x ∈ Ioc a b) : x ∈ Icc a b := Ioc_subset_Icc_self h theorem mem_Ici_of_Ioi (h : x ∈ Ioi a) : x ∈ Ici a := Ioi_subset_Ici_self h theorem mem_Iic_of_Iio (h : x ∈ Iio a) : x ∈ Iic a := Iio_subset_Iic_self h theorem Icc_eq_empty_iff : Icc a b = βˆ… ↔ Β¬a ≀ b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Icc] theorem Ico_eq_empty_iff : Ico a b = βˆ… ↔ Β¬a < b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ico] theorem Ioc_eq_empty_iff : Ioc a b = βˆ… ↔ Β¬a < b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ioc] theorem Ioo_eq_empty_iff [DenselyOrdered Ξ±] : Ioo a b = βˆ… ↔ Β¬a < b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ioo] theorem _root_.IsTop.Iic_eq (h : IsTop a) : Iic a = univ := eq_univ_of_forall h theorem _root_.IsBot.Ici_eq (h : IsBot a) : Ici a = univ := eq_univ_of_forall h @[simp] theorem Ioi_eq_empty_iff : Ioi a = βˆ… ↔ IsMax a := by simp only [isMax_iff_forall_not_lt, eq_empty_iff_forall_not_mem, mem_Ioi] @[simp] theorem Iio_eq_empty_iff : Iio a = βˆ… ↔ IsMin a := Ioi_eq_empty_iff (Ξ± := Ξ±α΅’α΅ˆ) @[simp] alias ⟨_, _root_.IsMax.Ioi_eq⟩ := Ioi_eq_empty_iff @[simp] alias ⟨_, _root_.IsMin.Iio_eq⟩ := Iio_eq_empty_iff @[simp] lemma Iio_nonempty : (Iio a).Nonempty ↔ Β¬ IsMin a := by simp [nonempty_iff_ne_empty] @[simp] lemma Ioi_nonempty : (Ioi a).Nonempty ↔ Β¬ IsMax a := by simp [nonempty_iff_ne_empty] theorem Iic_inter_Ioc_of_le (h : a ≀ c) : Iic a ∩ Ioc b c = Ioc b a := ext fun _ => ⟨fun H => ⟨H.2.1, H.1⟩, fun H => ⟨H.2, H.1, H.2.trans h⟩⟩ theorem not_mem_Icc_of_lt (ha : c < a) : c βˆ‰ Icc a b := fun h => ha.not_le h.1 theorem not_mem_Icc_of_gt (hb : b < c) : c βˆ‰ Icc a b := fun h => hb.not_le h.2 theorem not_mem_Ico_of_lt (ha : c < a) : c βˆ‰ Ico a b := fun h => ha.not_le h.1 theorem not_mem_Ioc_of_gt (hb : b < c) : c βˆ‰ Ioc a b := fun h => hb.not_le h.2 theorem not_mem_Ioi_self : a βˆ‰ Ioi a := lt_irrefl _ theorem not_mem_Iio_self : b βˆ‰ Iio b := lt_irrefl _ theorem not_mem_Ioc_of_le (ha : c ≀ a) : c βˆ‰ Ioc a b := fun h => lt_irrefl _ <| h.1.trans_le ha theorem not_mem_Ico_of_ge (hb : b ≀ c) : c βˆ‰ Ico a b := fun h => lt_irrefl _ <| h.2.trans_le hb theorem not_mem_Ioo_of_le (ha : c ≀ a) : c βˆ‰ Ioo a b := fun h => lt_irrefl _ <| h.1.trans_le ha theorem not_mem_Ioo_of_ge (hb : b ≀ c) : c βˆ‰ Ioo a b := fun h => lt_irrefl _ <| h.2.trans_le hb section matched_intervals @[simp] theorem Icc_eq_Ioc_same_iff : Icc a b = Ioc a b ↔ Β¬a ≀ b where mp h := by simpa using Set.ext_iff.mp h a mpr h := by rw [Icc_eq_empty h, Ioc_eq_empty (mt le_of_lt h)] @[simp] theorem Icc_eq_Ico_same_iff : Icc a b = Ico a b ↔ Β¬a ≀ b where mp h := by simpa using Set.ext_iff.mp h b mpr h := by rw [Icc_eq_empty h, Ico_eq_empty (mt le_of_lt h)] @[simp] theorem Icc_eq_Ioo_same_iff : Icc a b = Ioo a b ↔ Β¬a ≀ b where mp h := by simpa using Set.ext_iff.mp h b mpr h := by rw [Icc_eq_empty h, Ioo_eq_empty (mt le_of_lt h)] @[simp] theorem Ioc_eq_Ico_same_iff : Ioc a b = Ico a b ↔ Β¬a < b where mp h := by simpa using Set.ext_iff.mp h a mpr h := by rw [Ioc_eq_empty h, Ico_eq_empty h] @[simp] theorem Ioo_eq_Ioc_same_iff : Ioo a b = Ioc a b ↔ Β¬a < b where mp h := by simpa using Set.ext_iff.mp h b mpr h := by rw [Ioo_eq_empty h, Ioc_eq_empty h] @[simp] theorem Ioo_eq_Ico_same_iff : Ioo a b = Ico a b ↔ Β¬a < b where mp h := by simpa using Set.ext_iff.mp h a mpr h := by rw [Ioo_eq_empty h, Ico_eq_empty h] -- Mirrored versions of the above for `simp`. @[simp] theorem Ioc_eq_Icc_same_iff : Ioc a b = Icc a b ↔ Β¬a ≀ b := eq_comm.trans Icc_eq_Ioc_same_iff @[simp] theorem Ico_eq_Icc_same_iff : Ico a b = Icc a b ↔ Β¬a ≀ b := eq_comm.trans Icc_eq_Ico_same_iff @[simp] theorem Ioo_eq_Icc_same_iff : Ioo a b = Icc a b ↔ Β¬a ≀ b := eq_comm.trans Icc_eq_Ioo_same_iff @[simp] theorem Ico_eq_Ioc_same_iff : Ico a b = Ioc a b ↔ Β¬a < b := eq_comm.trans Ioc_eq_Ico_same_iff @[simp] theorem Ioc_eq_Ioo_same_iff : Ioc a b = Ioo a b ↔ Β¬a < b := eq_comm.trans Ioo_eq_Ioc_same_iff @[simp] theorem Ico_eq_Ioo_same_iff : Ico a b = Ioo a b ↔ Β¬a < b := eq_comm.trans Ioo_eq_Ico_same_iff end matched_intervals end Preorder section PartialOrder variable [PartialOrder Ξ±] {a b c : Ξ±} @[simp] theorem Icc_self (a : Ξ±) : Icc a a = {a} := Set.ext <| by simp [Icc, le_antisymm_iff, and_comm] instance instIccUnique : Unique (Set.Icc a a) where default := ⟨a, by simp⟩ uniq y := Subtype.ext <| by simpa using y.2 @[simp] theorem Icc_eq_singleton_iff : Icc a b = {c} ↔ a = c ∧ b = c := by refine ⟨fun h => ?_, ?_⟩ Β· have hab : a ≀ b := nonempty_Icc.1 (h.symm.subst <| singleton_nonempty c) exact ⟨eq_of_mem_singleton <| h β–Έ left_mem_Icc.2 hab, eq_of_mem_singleton <| h β–Έ right_mem_Icc.2 hab⟩ Β· rintro ⟨rfl, rfl⟩ exact Icc_self _ lemma subsingleton_Icc_of_ge (hba : b ≀ a) : Set.Subsingleton (Icc a b) := fun _x ⟨hax, hxb⟩ _y ⟨hay, hyb⟩ ↦ le_antisymm (le_implies_le_of_le_of_le hxb hay hba) (le_implies_le_of_le_of_le hyb hax hba) @[simp] lemma subsingleton_Icc_iff {Ξ± : Type*} [LinearOrder Ξ±] {a b : Ξ±} : Set.Subsingleton (Icc a b) ↔ b ≀ a := by refine ⟨fun h ↦ ?_, subsingleton_Icc_of_ge⟩ contrapose! h simp only [gt_iff_lt, not_subsingleton_iff] exact ⟨a, ⟨le_refl _, h.le⟩, b, ⟨h.le, le_refl _⟩, h.ne⟩ @[simp] theorem Icc_diff_left : Icc a b \ {a} = Ioc a b := ext fun x => by simp [lt_iff_le_and_ne, eq_comm, and_right_comm] @[simp] theorem Icc_diff_right : Icc a b \ {b} = Ico a b := ext fun x => by simp [lt_iff_le_and_ne, and_assoc] @[simp] theorem Ico_diff_left : Ico a b \ {a} = Ioo a b := ext fun x => by simp [and_right_comm, ← lt_iff_le_and_ne, eq_comm] @[simp] theorem Ioc_diff_right : Ioc a b \ {b} = Ioo a b := ext fun x => by simp [and_assoc, ← lt_iff_le_and_ne] @[simp] theorem Icc_diff_both : Icc a b \ {a, b} = Ioo a b := by rw [insert_eq, ← diff_diff, Icc_diff_left, Ioc_diff_right] @[simp] theorem Ici_diff_left : Ici a \ {a} = Ioi a := ext fun x => by simp [lt_iff_le_and_ne, eq_comm] @[simp] theorem Iic_diff_right : Iic a \ {a} = Iio a := ext fun x => by simp [lt_iff_le_and_ne] @[simp] theorem Ico_diff_Ioo_same (h : a < b) : Ico a b \ Ioo a b = {a} := by rw [← Ico_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 <| left_mem_Ico.2 h)] @[simp] theorem Ioc_diff_Ioo_same (h : a < b) : Ioc a b \ Ioo a b = {b} := by rw [← Ioc_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 <| right_mem_Ioc.2 h)] @[simp] theorem Icc_diff_Ico_same (h : a ≀ b) : Icc a b \ Ico a b = {b} := by rw [← Icc_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 <| right_mem_Icc.2 h)] @[simp] theorem Icc_diff_Ioc_same (h : a ≀ b) : Icc a b \ Ioc a b = {a} := by rw [← Icc_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 <| left_mem_Icc.2 h)] @[simp] theorem Icc_diff_Ioo_same (h : a ≀ b) : Icc a b \ Ioo a b = {a, b} := by rw [← Icc_diff_both, diff_diff_cancel_left] simp [insert_subset_iff, h] @[simp] theorem Ici_diff_Ioi_same : Ici a \ Ioi a = {a} := by rw [← Ici_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 left_mem_Ici)] @[simp] theorem Iic_diff_Iio_same : Iic a \ Iio a = {a} := by rw [← Iic_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 right_mem_Iic)] theorem Ioi_union_left : Ioi a βˆͺ {a} = Ici a := ext fun x => by simp [eq_comm, le_iff_eq_or_lt] theorem Iio_union_right : Iio a βˆͺ {a} = Iic a := ext fun _ => le_iff_lt_or_eq.symm theorem Ioo_union_left (hab : a < b) : Ioo a b βˆͺ {a} = Ico a b := by rw [← Ico_diff_left, diff_union_self, union_eq_self_of_subset_right (singleton_subset_iff.2 <| left_mem_Ico.2 hab)] theorem Ioo_union_right (hab : a < b) : Ioo a b βˆͺ {b} = Ioc a b := by simpa only [Ioo_toDual, Ico_toDual] using Ioo_union_left hab.dual theorem Ioo_union_both (h : a ≀ b) : Ioo a b βˆͺ {a, b} = Icc a b := by have : (Icc a b \ {a, b}) βˆͺ {a, b} = Icc a b := diff_union_of_subset fun | x, .inl rfl => left_mem_Icc.mpr h | x, .inr rfl => right_mem_Icc.mpr h rw [← this, Icc_diff_both] theorem Ioc_union_left (hab : a ≀ b) : Ioc a b βˆͺ {a} = Icc a b := by rw [← Icc_diff_left, diff_union_self, union_eq_self_of_subset_right (singleton_subset_iff.2 <| left_mem_Icc.2 hab)] theorem Ico_union_right (hab : a ≀ b) : Ico a b βˆͺ {b} = Icc a b := by simpa only [Ioc_toDual, Icc_toDual] using Ioc_union_left hab.dual @[simp] theorem Ico_insert_right (h : a ≀ b) : insert b (Ico a b) = Icc a b := by rw [insert_eq, union_comm, Ico_union_right h] @[simp] theorem Ioc_insert_left (h : a ≀ b) : insert a (Ioc a b) = Icc a b := by rw [insert_eq, union_comm, Ioc_union_left h] @[simp] theorem Ioo_insert_left (h : a < b) : insert a (Ioo a b) = Ico a b := by rw [insert_eq, union_comm, Ioo_union_left h] @[simp] theorem Ioo_insert_right (h : a < b) : insert b (Ioo a b) = Ioc a b := by rw [insert_eq, union_comm, Ioo_union_right h] @[simp] theorem Iio_insert : insert a (Iio a) = Iic a := ext fun _ => le_iff_eq_or_lt.symm @[simp] theorem Ioi_insert : insert a (Ioi a) = Ici a := ext fun _ => (or_congr_left eq_comm).trans le_iff_eq_or_lt.symm theorem mem_Ici_Ioi_of_subset_of_subset {s : Set Ξ±} (ho : Ioi a βŠ† s) (hc : s βŠ† Ici a) : s ∈ ({Ici a, Ioi a} : Set (Set Ξ±)) := by_cases (fun h : a ∈ s => Or.inl <| Subset.antisymm hc <| by rw [← Ioi_union_left, union_subset_iff]; simp [*]) fun h => Or.inr <| Subset.antisymm (fun _ hx => lt_of_le_of_ne (hc hx) fun heq => h <| heq.symm β–Έ hx) ho theorem mem_Iic_Iio_of_subset_of_subset {s : Set Ξ±} (ho : Iio a βŠ† s) (hc : s βŠ† Iic a) : s ∈ ({Iic a, Iio a} : Set (Set Ξ±)) := @mem_Ici_Ioi_of_subset_of_subset Ξ±α΅’α΅ˆ _ a s ho hc theorem mem_Icc_Ico_Ioc_Ioo_of_subset_of_subset {s : Set Ξ±} (ho : Ioo a b βŠ† s) (hc : s βŠ† Icc a b) : s ∈ ({Icc a b, Ico a b, Ioc a b, Ioo a b} : Set (Set Ξ±)) := by classical by_cases ha : a ∈ s <;> by_cases hb : b ∈ s Β· refine Or.inl (Subset.antisymm hc ?_) rwa [← Ico_diff_left, diff_singleton_subset_iff, insert_eq_of_mem ha, ← Icc_diff_right, diff_singleton_subset_iff, insert_eq_of_mem hb] at ho Β· refine Or.inr <| Or.inl <| Subset.antisymm ?_ ?_ Β· rw [← Icc_diff_right] exact subset_diff_singleton hc hb Β· rwa [← Ico_diff_left, diff_singleton_subset_iff, insert_eq_of_mem ha] at ho Β· refine Or.inr <| Or.inr <| Or.inl <| Subset.antisymm ?_ ?_ Β· rw [← Icc_diff_left] exact subset_diff_singleton hc ha Β· rwa [← Ioc_diff_right, diff_singleton_subset_iff, insert_eq_of_mem hb] at ho Β· refine Or.inr <| Or.inr <| Or.inr <| Subset.antisymm ?_ ho rw [← Ico_diff_left, ← Icc_diff_right] apply_rules [subset_diff_singleton] theorem eq_left_or_mem_Ioo_of_mem_Ico {x : Ξ±} (hmem : x ∈ Ico a b) : x = a ∨ x ∈ Ioo a b := hmem.1.eq_or_gt.imp_right fun h => ⟨h, hmem.2⟩ theorem eq_right_or_mem_Ioo_of_mem_Ioc {x : Ξ±} (hmem : x ∈ Ioc a b) : x = b ∨ x ∈ Ioo a b := hmem.2.eq_or_lt.imp_right <| And.intro hmem.1 theorem eq_endpoints_or_mem_Ioo_of_mem_Icc {x : Ξ±} (hmem : x ∈ Icc a b) : x = a ∨ x = b ∨ x ∈ Ioo a b := hmem.1.eq_or_gt.imp_right fun h => eq_right_or_mem_Ioo_of_mem_Ioc ⟨h, hmem.2⟩ theorem _root_.IsMax.Ici_eq (h : IsMax a) : Ici a = {a} := eq_singleton_iff_unique_mem.2 ⟨left_mem_Ici, fun _ => h.eq_of_ge⟩ theorem _root_.IsMin.Iic_eq (h : IsMin a) : Iic a = {a} := h.toDual.Ici_eq theorem Ici_injective : Injective (Ici : Ξ± β†’ Set Ξ±) := fun _ _ => eq_of_forall_ge_iff ∘ Set.ext_iff.1 theorem Iic_injective : Injective (Iic : Ξ± β†’ Set Ξ±) := fun _ _ => eq_of_forall_le_iff ∘ Set.ext_iff.1 theorem Ici_inj : Ici a = Ici b ↔ a = b := Ici_injective.eq_iff theorem Iic_inj : Iic a = Iic b ↔ a = b := Iic_injective.eq_iff @[simp] theorem Icc_inter_Icc_eq_singleton (hab : a ≀ b) (hbc : b ≀ c) : Icc a b ∩ Icc b c = {b} := by rw [← Ici_inter_Iic, ← Iic_inter_Ici, inter_inter_inter_comm, Iic_inter_Ici] simp [hab, hbc] lemma Icc_eq_Icc_iff {d : Ξ±} (h : a ≀ b) : Icc a b = Icc c d ↔ a = c ∧ b = d := by refine ⟨fun heq ↦ ?_, by rintro ⟨rfl, rfl⟩; rfl⟩ have h' : c ≀ d := by by_contra contra; rw [Icc_eq_empty_iff.mpr contra, Icc_eq_empty_iff] at heq; contradiction simp only [Set.ext_iff, mem_Icc] at heq obtain ⟨-, hβ‚βŸ© := (heq b).mp ⟨h, le_refl _⟩ obtain ⟨hβ‚‚, -⟩ := (heq a).mp ⟨le_refl _, h⟩ obtain ⟨h₃, -⟩ := (heq c).mpr ⟨le_refl _, h'⟩ obtain ⟨-, hβ‚„βŸ© := (heq d).mpr ⟨h', le_refl _⟩ exact ⟨le_antisymm h₃ hβ‚‚, le_antisymm h₁ hβ‚„βŸ© end PartialOrder section OrderTop @[simp] theorem Ici_top [PartialOrder Ξ±] [OrderTop Ξ±] : Ici (⊀ : Ξ±) = {⊀} := isMax_top.Ici_eq variable [Preorder Ξ±] [OrderTop Ξ±] {a : Ξ±} theorem Ioi_top : Ioi (⊀ : Ξ±) = βˆ… := isMax_top.Ioi_eq @[simp] theorem Iic_top : Iic (⊀ : Ξ±) = univ := isTop_top.Iic_eq @[simp] theorem Icc_top : Icc a ⊀ = Ici a := by simp [← Ici_inter_Iic] @[simp] theorem Ioc_top : Ioc a ⊀ = Ioi a := by simp [← Ioi_inter_Iic] end OrderTop section OrderBot @[simp] theorem Iic_bot [PartialOrder Ξ±] [OrderBot Ξ±] : Iic (βŠ₯ : Ξ±) = {βŠ₯} := isMin_bot.Iic_eq variable [Preorder Ξ±] [OrderBot Ξ±] {a : Ξ±} theorem Iio_bot : Iio (βŠ₯ : Ξ±) = βˆ… := isMin_bot.Iio_eq @[simp] theorem Ici_bot : Ici (βŠ₯ : Ξ±) = univ := isBot_bot.Ici_eq @[simp] theorem Icc_bot : Icc βŠ₯ a = Iic a := by simp [← Ici_inter_Iic] @[simp] theorem Ico_bot : Ico βŠ₯ a = Iio a := by simp [← Ici_inter_Iio] end OrderBot theorem Icc_bot_top [Preorder Ξ±] [BoundedOrder Ξ±] : Icc (βŠ₯ : Ξ±) ⊀ = univ := by simp section Lattice section Inf variable [SemilatticeInf Ξ±] @[simp] theorem Iic_inter_Iic {a b : Ξ±} : Iic a ∩ Iic b = Iic (a βŠ“ b) := by ext x simp [Iic] @[simp] theorem Ioc_inter_Iic (a b c : Ξ±) : Ioc a b ∩ Iic c = Ioc a (b βŠ“ c) := by rw [← Ioi_inter_Iic, ← Ioi_inter_Iic, inter_assoc, Iic_inter_Iic] end Inf section Sup variable [SemilatticeSup Ξ±] @[simp] theorem Ici_inter_Ici {a b : Ξ±} : Ici a ∩ Ici b = Ici (a βŠ” b) := by ext x simp [Ici] @[simp] theorem Ico_inter_Ici (a b c : Ξ±) : Ico a b ∩ Ici c = Ico (a βŠ” c) b := by rw [← Ici_inter_Iio, ← Ici_inter_Iio, ← Ici_inter_Ici, inter_right_comm] end Sup section Both variable [Lattice Ξ±] {a b c a₁ aβ‚‚ b₁ bβ‚‚ : Ξ±} theorem Icc_inter_Icc : Icc a₁ b₁ ∩ Icc aβ‚‚ bβ‚‚ = Icc (a₁ βŠ” aβ‚‚) (b₁ βŠ“ bβ‚‚) := by simp only [Ici_inter_Iic.symm, Ici_inter_Ici.symm, Iic_inter_Iic.symm]; ac_rfl end Both end Lattice /-! ### Closed intervals in `Ξ± Γ— Ξ²` -/ section Prod variable {Ξ² : Type*} [Preorder Ξ±] [Preorder Ξ²] @[simp] theorem Iic_prod_Iic (a : Ξ±) (b : Ξ²) : Iic a Γ—Λ’ Iic b = Iic (a, b) := rfl @[simp] theorem Ici_prod_Ici (a : Ξ±) (b : Ξ²) : Ici a Γ—Λ’ Ici b = Ici (a, b) := rfl theorem Ici_prod_eq (a : Ξ± Γ— Ξ²) : Ici a = Ici a.1 Γ—Λ’ Ici a.2 := rfl theorem Iic_prod_eq (a : Ξ± Γ— Ξ²) : Iic a = Iic a.1 Γ—Λ’ Iic a.2 := rfl @[simp] theorem Icc_prod_Icc (a₁ aβ‚‚ : Ξ±) (b₁ bβ‚‚ : Ξ²) : Icc a₁ aβ‚‚ Γ—Λ’ Icc b₁ bβ‚‚ = Icc (a₁, b₁) (aβ‚‚, bβ‚‚) := by ext ⟨x, y⟩ simp [and_assoc, and_comm, and_left_comm] theorem Icc_prod_eq (a b : Ξ± Γ— Ξ²) : Icc a b = Icc a.1 b.1 Γ—Λ’ Icc a.2 b.2 := by simp end Prod end Set /-! ### Lemmas about intervals in dense orders -/ section Dense variable (Ξ±) [Preorder Ξ±] [DenselyOrdered Ξ±] {x y : Ξ±} instance : NoMinOrder (Set.Ioo x y) := ⟨fun ⟨a, ha₁, haβ‚‚βŸ© => by rcases exists_between ha₁ with ⟨b, hb₁, hbβ‚‚βŸ© exact ⟨⟨b, hb₁, hbβ‚‚.trans haβ‚‚βŸ©, hbβ‚‚βŸ©βŸ© instance : NoMinOrder (Set.Ioc x y) := ⟨fun ⟨a, ha₁, haβ‚‚βŸ© => by rcases exists_between ha₁ with ⟨b, hb₁, hbβ‚‚βŸ© exact ⟨⟨b, hb₁, hbβ‚‚.le.trans haβ‚‚βŸ©, hbβ‚‚βŸ©βŸ© instance : NoMinOrder (Set.Ioi x) := ⟨fun ⟨a, ha⟩ => by rcases exists_between ha with ⟨b, hb₁, hbβ‚‚βŸ© exact ⟨⟨b, hbβ‚βŸ©, hbβ‚‚βŸ©βŸ© instance : NoMaxOrder (Set.Ioo x y) := ⟨fun ⟨a, ha₁, haβ‚‚βŸ© => by rcases exists_between haβ‚‚ with ⟨b, hb₁, hbβ‚‚βŸ© exact ⟨⟨b, ha₁.trans hb₁, hbβ‚‚βŸ©, hbβ‚βŸ©βŸ© instance : NoMaxOrder (Set.Ico x y) := ⟨fun ⟨a, ha₁, haβ‚‚βŸ© => by rcases exists_between haβ‚‚ with ⟨b, hb₁, hbβ‚‚βŸ© exact ⟨⟨b, ha₁.trans hb₁.le, hbβ‚‚βŸ©, hbβ‚βŸ©βŸ© instance : NoMaxOrder (Set.Iio x) := ⟨fun ⟨a, ha⟩ => by rcases exists_between ha with ⟨b, hb₁, hbβ‚‚βŸ© exact ⟨⟨b, hbβ‚‚βŸ©, hbβ‚βŸ©βŸ© end Dense /-! ### Intervals in `Prop` -/ namespace Set @[simp] lemma Iic_False : Iic False = {False} := by aesop @[simp] lemma Iic_True : Iic True = univ := by aesop @[simp] lemma Ici_False : Ici False = univ := by aesop @[simp] lemma Ici_True : Ici True = {True} := by aesop lemma Iio_False : Iio False = βˆ… := by aesop @[simp] lemma Iio_True : Iio True = {False} := by aesop (add simp [Ioi, lt_iff_le_not_le]) @[simp] lemma Ioi_False : Ioi False = {True} := by aesop (add simp [Ioi, lt_iff_le_not_le]) lemma Ioi_True : Ioi True = βˆ… := by aesop end Set
Mathlib/Order/Interval/Set/Basic.lean
1,842
1,843
/- 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.Probability.IdentDistrib import Mathlib.Probability.Independence.Integrable import Mathlib.MeasureTheory.Integral.DominatedConvergence import Mathlib.Analysis.SpecificLimits.FloorPow import Mathlib.Analysis.PSeries import Mathlib.Analysis.Asymptotics.SpecificAsymptotics /-! # The strong law of large numbers We prove the strong law of large numbers, in `ProbabilityTheory.strong_law_ae`: If `X n` is a sequence of independent identically distributed integrable random variables, then `βˆ‘ i ∈ range n, X i / n` converges almost surely to `𝔼[X 0]`. We give here the strong version, due to Etemadi, that only requires pairwise independence. This file also contains the Lα΅– version of the strong law of large numbers provided by `ProbabilityTheory.strong_law_Lp` which shows `βˆ‘ i ∈ range n, X i / n` converges in Lα΅– to `𝔼[X 0]` provided `X n` is independent identically distributed and is Lα΅–. ## Implementation The main point is to prove the result for real-valued random variables, as the general case of Banach-space valued random variables follows from this case and approximation by simple functions. The real version is given in `ProbabilityTheory.strong_law_ae_real`. We follow the proof by Etemadi [Etemadi, *An elementary proof of the strong law of large numbers*][etemadi_strong_law], which goes as follows. It suffices to prove the result for nonnegative `X`, as one can prove the general result by splitting a general `X` into its positive part and negative part. Consider `Xβ‚™` a sequence of nonnegative integrable identically distributed pairwise independent random variables. Let `Yβ‚™` be the truncation of `Xβ‚™` up to `n`. We claim that * Almost surely, `Xβ‚™ = Yβ‚™` for all but finitely many indices. Indeed, `βˆ‘ β„™ (Xβ‚™ β‰  Yβ‚™)` is bounded by `1 + 𝔼[X]` (see `sum_prob_mem_Ioc_le` and `tsum_prob_mem_Ioi_lt_top`). * Let `c > 1`. Along the sequence `n = c ^ k`, then `(βˆ‘_{i=0}^{n-1} Yα΅’ - 𝔼[Yα΅’])/n` converges almost surely to `0`. This follows from a variance control, as ``` βˆ‘_k β„™ (|βˆ‘_{i=0}^{c^k - 1} Yα΅’ - 𝔼[Yα΅’]| > c^k Ξ΅) ≀ βˆ‘_k (c^k Ξ΅)^{-2} βˆ‘_{i=0}^{c^k - 1} Var[Yα΅’] (by Markov inequality) ≀ βˆ‘_i (C/i^2) Var[Yα΅’] (as βˆ‘_{c^k > i} 1/(c^k)^2 ≀ C/i^2) ≀ βˆ‘_i (C/i^2) 𝔼[Yα΅’^2] ≀ 2C 𝔼[X^2] (see `sum_variance_truncation_le`) ``` * As `𝔼[Yα΅’]` converges to `𝔼[X]`, it follows from the two previous items and CesΓ ro that, along the sequence `n = c^k`, one has `(βˆ‘_{i=0}^{n-1} Xα΅’) / n β†’ 𝔼[X]` almost surely. * To generalize it to all indices, we use the fact that `βˆ‘_{i=0}^{n-1} Xα΅’` is nondecreasing and that, if `c` is close enough to `1`, the gap between `c^k` and `c^(k+1)` is small. -/ noncomputable section open MeasureTheory Filter Finset Asymptotics open Set (indicator) open scoped Topology MeasureTheory ProbabilityTheory ENNReal NNReal open scoped Function -- required for scoped `on` notation namespace ProbabilityTheory /-! ### Prerequisites on truncations -/ section Truncation variable {Ξ± : Type*} /-- Truncating a real-valued function to the interval `(-A, A]`. -/ def truncation (f : Ξ± β†’ ℝ) (A : ℝ) := indicator (Set.Ioc (-A) A) id ∘ f variable {m : MeasurableSpace Ξ±} {ΞΌ : Measure Ξ±} {f : Ξ± β†’ ℝ} theorem _root_.MeasureTheory.AEStronglyMeasurable.truncation (hf : AEStronglyMeasurable f ΞΌ) {A : ℝ} : AEStronglyMeasurable (truncation f A) ΞΌ := by apply AEStronglyMeasurable.comp_aemeasurable _ hf.aemeasurable exact (stronglyMeasurable_id.indicator measurableSet_Ioc).aestronglyMeasurable theorem abs_truncation_le_bound (f : Ξ± β†’ ℝ) (A : ℝ) (x : Ξ±) : |truncation f A x| ≀ |A| := by simp only [truncation, Set.indicator, Set.mem_Icc, id, Function.comp_apply] split_ifs with h Β· exact abs_le_abs h.2 (neg_le.2 h.1.le) Β· simp [abs_nonneg] @[simp] theorem truncation_zero (f : Ξ± β†’ ℝ) : truncation f 0 = 0 := by simp [truncation]; rfl theorem abs_truncation_le_abs_self (f : Ξ± β†’ ℝ) (A : ℝ) (x : Ξ±) : |truncation f A x| ≀ |f x| := by simp only [truncation, indicator, Set.mem_Icc, id, Function.comp_apply] split_ifs Β· exact le_rfl Β· simp [abs_nonneg] theorem truncation_eq_self {f : Ξ± β†’ ℝ} {A : ℝ} {x : Ξ±} (h : |f x| < A) : truncation f A x = f x := by simp only [truncation, indicator, Set.mem_Icc, id, Function.comp_apply, ite_eq_left_iff] intro H apply H.elim simp [(abs_lt.1 h).1, (abs_lt.1 h).2.le] theorem truncation_eq_of_nonneg {f : Ξ± β†’ ℝ} {A : ℝ} (h : βˆ€ x, 0 ≀ f x) : truncation f A = indicator (Set.Ioc 0 A) id ∘ f := by ext x rcases (h x).lt_or_eq with (hx | hx) Β· simp only [truncation, indicator, hx, Set.mem_Ioc, id, Function.comp_apply] by_cases h'x : f x ≀ A Β· have : -A < f x := by linarith [h x] simp only [this, true_and] Β· simp only [h'x, and_false] Β· simp only [truncation, indicator, hx, id, Function.comp_apply, ite_self] theorem truncation_nonneg {f : Ξ± β†’ ℝ} (A : ℝ) {x : Ξ±} (h : 0 ≀ f x) : 0 ≀ truncation f A x := Set.indicator_apply_nonneg fun _ => h theorem _root_.MeasureTheory.AEStronglyMeasurable.memLp_truncation [IsFiniteMeasure ΞΌ] (hf : AEStronglyMeasurable f ΞΌ) {A : ℝ} {p : ℝβ‰₯0∞} : MemLp (truncation f A) p ΞΌ := MemLp.of_bound hf.truncation |A| (Eventually.of_forall fun _ => abs_truncation_le_bound _ _ _) theorem _root_.MeasureTheory.AEStronglyMeasurable.integrable_truncation [IsFiniteMeasure ΞΌ] (hf : AEStronglyMeasurable f ΞΌ) {A : ℝ} : Integrable (truncation f A) ΞΌ := by rw [← memLp_one_iff_integrable]; exact hf.memLp_truncation theorem moment_truncation_eq_intervalIntegral (hf : AEStronglyMeasurable f ΞΌ) {A : ℝ} (hA : 0 ≀ A) {n : β„•} (hn : n β‰  0) : ∫ x, truncation f A x ^ n βˆ‚ΞΌ = ∫ y in -A..A, y ^ n βˆ‚Measure.map f ΞΌ := by have M : MeasurableSet (Set.Ioc (-A) A) := measurableSet_Ioc change ∫ x, (fun z => indicator (Set.Ioc (-A) A) id z ^ n) (f x) βˆ‚ΞΌ = _ rw [← integral_map (f := fun z => _ ^ n) hf.aemeasurable, intervalIntegral.integral_of_le, ← integral_indicator M] Β· simp only [indicator, zero_pow hn, id, ite_pow] Β· linarith Β· exact ((measurable_id.indicator M).pow_const n).aestronglyMeasurable theorem moment_truncation_eq_intervalIntegral_of_nonneg (hf : AEStronglyMeasurable f ΞΌ) {A : ℝ} {n : β„•} (hn : n β‰  0) (h'f : 0 ≀ f) : ∫ x, truncation f A x ^ n βˆ‚ΞΌ = ∫ y in (0)..A, y ^ n βˆ‚Measure.map f ΞΌ := by have M : MeasurableSet (Set.Ioc 0 A) := measurableSet_Ioc have M' : MeasurableSet (Set.Ioc A 0) := measurableSet_Ioc rw [truncation_eq_of_nonneg h'f] change ∫ x, (fun z => indicator (Set.Ioc 0 A) id z ^ n) (f x) βˆ‚ΞΌ = _ rcases le_or_lt 0 A with (hA | hA) Β· rw [← integral_map (f := fun z => _ ^ n) hf.aemeasurable, intervalIntegral.integral_of_le hA, ← integral_indicator M] Β· simp only [indicator, zero_pow hn, id, ite_pow] Β· exact ((measurable_id.indicator M).pow_const n).aestronglyMeasurable Β· rw [← integral_map (f := fun z => _ ^ n) hf.aemeasurable, intervalIntegral.integral_of_ge hA.le, ← integral_indicator M'] Β· simp only [Set.Ioc_eq_empty_of_le hA.le, zero_pow hn, Set.indicator_empty, integral_zero, zero_eq_neg] apply integral_eq_zero_of_ae have : βˆ€α΅ x βˆ‚Measure.map f ΞΌ, (0 : ℝ) ≀ x := (ae_map_iff hf.aemeasurable measurableSet_Ici).2 (Eventually.of_forall h'f) filter_upwards [this] with x hx simp only [indicator, Set.mem_Ioc, Pi.zero_apply, ite_eq_right_iff, and_imp] intro _ h''x have : x = 0 := by linarith simp [this, zero_pow hn] Β· exact ((measurable_id.indicator M).pow_const n).aestronglyMeasurable theorem integral_truncation_eq_intervalIntegral (hf : AEStronglyMeasurable f ΞΌ) {A : ℝ} (hA : 0 ≀ A) : ∫ x, truncation f A x βˆ‚ΞΌ = ∫ y in -A..A, y βˆ‚Measure.map f ΞΌ := by simpa using moment_truncation_eq_intervalIntegral hf hA one_ne_zero theorem integral_truncation_eq_intervalIntegral_of_nonneg (hf : AEStronglyMeasurable f ΞΌ) {A : ℝ} (h'f : 0 ≀ f) : ∫ x, truncation f A x βˆ‚ΞΌ = ∫ y in (0)..A, y βˆ‚Measure.map f ΞΌ := by simpa using moment_truncation_eq_intervalIntegral_of_nonneg hf one_ne_zero h'f theorem integral_truncation_le_integral_of_nonneg (hf : Integrable f ΞΌ) (h'f : 0 ≀ f) {A : ℝ} : ∫ x, truncation f A x βˆ‚ΞΌ ≀ ∫ x, f x βˆ‚ΞΌ := by apply integral_mono_of_nonneg (Eventually.of_forall fun x => ?_) hf (Eventually.of_forall fun x => ?_) Β· exact truncation_nonneg _ (h'f x) Β· calc truncation f A x ≀ |truncation f A x| := le_abs_self _ _ ≀ |f x| := abs_truncation_le_abs_self _ _ _ _ = f x := abs_of_nonneg (h'f x) /-- If a function is integrable, then the integral of its truncated versions converges to the integral of the whole function. -/ theorem tendsto_integral_truncation {f : Ξ± β†’ ℝ} (hf : Integrable f ΞΌ) : Tendsto (fun A => ∫ x, truncation f A x βˆ‚ΞΌ) atTop (𝓝 (∫ x, f x βˆ‚ΞΌ)) := by refine tendsto_integral_filter_of_dominated_convergence (fun x => abs (f x)) ?_ ?_ ?_ ?_ Β· exact Eventually.of_forall fun A ↦ hf.aestronglyMeasurable.truncation Β· filter_upwards with A filter_upwards with x rw [Real.norm_eq_abs] exact abs_truncation_le_abs_self _ _ _ Β· exact hf.abs Β· filter_upwards with x apply tendsto_const_nhds.congr' _ filter_upwards [Ioi_mem_atTop (abs (f x))] with A hA exact (truncation_eq_self hA).symm theorem IdentDistrib.truncation {Ξ² : Type*} [MeasurableSpace Ξ²] {Ξ½ : Measure Ξ²} {f : Ξ± β†’ ℝ} {g : Ξ² β†’ ℝ} (h : IdentDistrib f g ΞΌ Ξ½) {A : ℝ} : IdentDistrib (truncation f A) (truncation g A) ΞΌ Ξ½ := h.comp (measurable_id.indicator measurableSet_Ioc) end Truncation section StrongLawAeReal variable {Ξ© : Type*} [MeasureSpace Ξ©] [IsProbabilityMeasure (β„™ : Measure Ξ©)] section MomentEstimates theorem sum_prob_mem_Ioc_le {X : Ξ© β†’ ℝ} (hint : Integrable X) (hnonneg : 0 ≀ X) {K : β„•} {N : β„•} (hKN : K ≀ N) : βˆ‘ j ∈ range K, β„™ {Ο‰ | X Ο‰ ∈ Set.Ioc (j : ℝ) N} ≀ ENNReal.ofReal (𝔼[X] + 1) := by let ρ : Measure ℝ := Measure.map X β„™ haveI : IsProbabilityMeasure ρ := isProbabilityMeasure_map hint.aemeasurable have A : βˆ‘ j ∈ range K, ∫ _ in j..N, (1 : ℝ) βˆ‚Ο ≀ 𝔼[X] + 1 := calc βˆ‘ j ∈ range K, ∫ _ in j..N, (1 : ℝ) βˆ‚Ο = βˆ‘ j ∈ range K, βˆ‘ i ∈ Ico j N, ∫ _ in i..(i + 1 : β„•), (1 : ℝ) βˆ‚Ο := by apply sum_congr rfl fun j hj => ?_ rw [intervalIntegral.sum_integral_adjacent_intervals_Ico ((mem_range.1 hj).le.trans hKN)] intro k _ exact continuous_const.intervalIntegrable _ _ _ = βˆ‘ i ∈ range N, βˆ‘ j ∈ range (min (i + 1) K), ∫ _ in i..(i + 1 : β„•), (1 : ℝ) βˆ‚Ο := by simp_rw [sum_sigma'] refine sum_nbij' (fun p ↦ ⟨p.2, p.1⟩) (fun p ↦ ⟨p.2, p.1⟩) ?_ ?_ ?_ ?_ ?_ <;> aesop (add simp Nat.lt_succ_iff) _ ≀ βˆ‘ i ∈ range N, (i + 1) * ∫ _ in i..(i + 1 : β„•), (1 : ℝ) βˆ‚Ο := by apply sum_le_sum fun i _ => ?_ simp only [Nat.cast_add, Nat.cast_one, sum_const, card_range, nsmul_eq_mul, Nat.cast_min] refine mul_le_mul_of_nonneg_right (min_le_left _ _) ?_ apply intervalIntegral.integral_nonneg Β· simp only [le_add_iff_nonneg_right, zero_le_one] Β· simp only [zero_le_one, imp_true_iff] _ ≀ βˆ‘ i ∈ range N, ∫ x in i..(i + 1 : β„•), x + 1 βˆ‚Ο := by apply sum_le_sum fun i _ => ?_ have I : (i : ℝ) ≀ (i + 1 : β„•) := by simp only [Nat.cast_add, Nat.cast_one, le_add_iff_nonneg_right, zero_le_one] simp_rw [intervalIntegral.integral_of_le I, ← integral_const_mul] apply setIntegral_mono_on Β· exact continuous_const.integrableOn_Ioc Β· exact (continuous_id.add continuous_const).integrableOn_Ioc Β· exact measurableSet_Ioc Β· intro x hx simp only [Nat.cast_add, Nat.cast_one, Set.mem_Ioc] at hx simp [hx.1.le] _ = ∫ x in (0)..N, x + 1 βˆ‚Ο := by rw [intervalIntegral.sum_integral_adjacent_intervals fun k _ => ?_] Β· norm_cast Β· exact (continuous_id.add continuous_const).intervalIntegrable _ _ _ = ∫ x in (0)..N, x βˆ‚Ο + ∫ x in (0)..N, 1 βˆ‚Ο := by rw [intervalIntegral.integral_add] Β· exact continuous_id.intervalIntegrable _ _ Β· exact continuous_const.intervalIntegrable _ _ _ = 𝔼[truncation X N] + ∫ x in (0)..N, 1 βˆ‚Ο := by rw [integral_truncation_eq_intervalIntegral_of_nonneg hint.1 hnonneg] _ ≀ 𝔼[X] + ∫ x in (0)..N, 1 βˆ‚Ο := (add_le_add_right (integral_truncation_le_integral_of_nonneg hint hnonneg) _) _ ≀ 𝔼[X] + 1 := by refine add_le_add le_rfl ?_ rw [intervalIntegral.integral_of_le (Nat.cast_nonneg _)] simp only [integral_const, measureReal_restrict_apply', measurableSet_Ioc, Set.univ_inter, Algebra.id.smul_eq_mul, mul_one] rw [← ENNReal.toReal_one] exact ENNReal.toReal_mono ENNReal.one_ne_top prob_le_one have B : βˆ€ a b, β„™ {Ο‰ | X Ο‰ ∈ Set.Ioc a b} = ENNReal.ofReal (∫ _ in Set.Ioc a b, (1 : ℝ) βˆ‚Ο) := by intro a b rw [ofReal_setIntegral_one ρ _, Measure.map_apply_of_aemeasurable hint.aemeasurable measurableSet_Ioc] rfl calc βˆ‘ j ∈ range K, β„™ {Ο‰ | X Ο‰ ∈ Set.Ioc (j : ℝ) N} = βˆ‘ j ∈ range K, ENNReal.ofReal (∫ _ in Set.Ioc (j : ℝ) N, (1 : ℝ) βˆ‚Ο) := by simp_rw [B] _ = ENNReal.ofReal (βˆ‘ j ∈ range K, ∫ _ in Set.Ioc (j : ℝ) N, (1 : ℝ) βˆ‚Ο) := by simp [ENNReal.ofReal_sum_of_nonneg] _ = ENNReal.ofReal (βˆ‘ j ∈ range K, ∫ _ in (j : ℝ)..N, (1 : ℝ) βˆ‚Ο) := by congr 1 refine sum_congr rfl fun j hj => ?_ rw [intervalIntegral.integral_of_le (Nat.cast_le.2 ((mem_range.1 hj).le.trans hKN))] _ ≀ ENNReal.ofReal (𝔼[X] + 1) := ENNReal.ofReal_le_ofReal A theorem tsum_prob_mem_Ioi_lt_top {X : Ξ© β†’ ℝ} (hint : Integrable X) (hnonneg : 0 ≀ X) : (βˆ‘' j : β„•, β„™ {Ο‰ | X Ο‰ ∈ Set.Ioi (j : ℝ)}) < ∞ := by suffices βˆ€ K : β„•, βˆ‘ j ∈ range K, β„™ {Ο‰ | X Ο‰ ∈ Set.Ioi (j : ℝ)} ≀ ENNReal.ofReal (𝔼[X] + 1) from (le_of_tendsto_of_tendsto (ENNReal.tendsto_nat_tsum _) tendsto_const_nhds (Eventually.of_forall this)).trans_lt ENNReal.ofReal_lt_top intro K have A : Tendsto (fun N : β„• => βˆ‘ j ∈ range K, β„™ {Ο‰ | X Ο‰ ∈ Set.Ioc (j : ℝ) N}) atTop (𝓝 (βˆ‘ j ∈ range K, β„™ {Ο‰ | X Ο‰ ∈ Set.Ioi (j : ℝ)})) := by refine tendsto_finset_sum _ fun i _ => ?_ have : {Ο‰ | X Ο‰ ∈ Set.Ioi (i : ℝ)} = ⋃ N : β„•, {Ο‰ | X Ο‰ ∈ Set.Ioc (i : ℝ) N} := by apply Set.Subset.antisymm _ _ Β· intro Ο‰ hΟ‰ obtain ⟨N, hN⟩ : βˆƒ N : β„•, X Ο‰ ≀ N := exists_nat_ge (X Ο‰) exact Set.mem_iUnion.2 ⟨N, hΟ‰, hN⟩ Β· simp +contextual only [Set.mem_Ioc, Set.mem_Ioi, Set.iUnion_subset_iff, Set.setOf_subset_setOf, imp_true_iff] rw [this] apply tendsto_measure_iUnion_atTop intro m n hmn x hx exact ⟨hx.1, hx.2.trans (Nat.cast_le.2 hmn)⟩ apply le_of_tendsto_of_tendsto A tendsto_const_nhds filter_upwards [Ici_mem_atTop K] with N hN exact sum_prob_mem_Ioc_le hint hnonneg hN theorem sum_variance_truncation_le {X : Ξ© β†’ ℝ} (hint : Integrable X) (hnonneg : 0 ≀ X) (K : β„•) : βˆ‘ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * 𝔼[truncation X j ^ 2] ≀ 2 * 𝔼[X] := by set Y := fun n : β„• => truncation X n let ρ : Measure ℝ := Measure.map X β„™ have Y2 : βˆ€ n, 𝔼[Y n ^ 2] = ∫ x in (0)..n, x ^ 2 βˆ‚Ο := by intro n change 𝔼[fun x => Y n x ^ 2] = _ rw [moment_truncation_eq_intervalIntegral_of_nonneg hint.1 two_ne_zero hnonneg] calc βˆ‘ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * 𝔼[Y j ^ 2] = βˆ‘ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * ∫ x in (0)..j, x ^ 2 βˆ‚Ο := by simp_rw [Y2] _ = βˆ‘ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * βˆ‘ k ∈ range j, ∫ x in k..(k + 1 : β„•), x ^ 2 βˆ‚Ο := by congr 1 with j congr 1 rw [intervalIntegral.sum_integral_adjacent_intervals] Β· norm_cast intro k _ exact (continuous_id.pow _).intervalIntegrable _ _ _ = βˆ‘ k ∈ range K, (βˆ‘ j ∈ Ioo k K, ((j : ℝ) ^ 2)⁻¹) * ∫ x in k..(k + 1 : β„•), x ^ 2 βˆ‚Ο := by simp_rw [mul_sum, sum_mul, sum_sigma'] refine sum_nbij' (fun p ↦ ⟨p.2, p.1⟩) (fun p ↦ ⟨p.2, p.1⟩) ?_ ?_ ?_ ?_ ?_ <;> aesop (add unsafe lt_trans) _ ≀ βˆ‘ k ∈ range K, 2 / (k + 1 : ℝ) * ∫ x in k..(k + 1 : β„•), x ^ 2 βˆ‚Ο := by apply sum_le_sum fun k _ => ?_ refine mul_le_mul_of_nonneg_right (sum_Ioo_inv_sq_le _ _) ?_ refine intervalIntegral.integral_nonneg_of_forall ?_ fun u => sq_nonneg _ simp only [Nat.cast_add, Nat.cast_one, le_add_iff_nonneg_right, zero_le_one] _ ≀ βˆ‘ k ∈ range K, ∫ x in k..(k + 1 : β„•), 2 * x βˆ‚Ο := by apply sum_le_sum fun k _ => ?_ have Ik : (k : ℝ) ≀ (k + 1 : β„•) := by simp rw [← intervalIntegral.integral_const_mul, intervalIntegral.integral_of_le Ik, intervalIntegral.integral_of_le Ik] refine setIntegral_mono_on ?_ ?_ measurableSet_Ioc fun x hx => ?_ Β· apply Continuous.integrableOn_Ioc exact continuous_const.mul (continuous_pow 2) Β· apply Continuous.integrableOn_Ioc exact continuous_const.mul continuous_id' Β· calc ↑2 / (↑k + ↑1) * x ^ 2 = x / (k + 1) * (2 * x) := by ring _ ≀ 1 * (2 * x) := (mul_le_mul_of_nonneg_right (by convert (div_le_one _).2 hx.2 Β· norm_cast simp only [Nat.cast_add, Nat.cast_one] linarith only [show (0 : ℝ) ≀ k from Nat.cast_nonneg k]) (mul_nonneg zero_le_two ((Nat.cast_nonneg k).trans hx.1.le))) _ = 2 * x := by rw [one_mul] _ = 2 * ∫ x in (0 : ℝ)..K, x βˆ‚Ο := by rw [intervalIntegral.sum_integral_adjacent_intervals fun k _ => ?_] swap; Β· exact (continuous_const.mul continuous_id').intervalIntegrable _ _ rw [intervalIntegral.integral_const_mul] norm_cast _ ≀ 2 * 𝔼[X] := mul_le_mul_of_nonneg_left (by rw [← integral_truncation_eq_intervalIntegral_of_nonneg hint.1 hnonneg] exact integral_truncation_le_integral_of_nonneg hint hnonneg) zero_le_two end MomentEstimates /-! Proof of the strong law of large numbers (almost sure version, assuming only pairwise independence) for nonnegative random variables, following Etemadi's proof. -/ section StrongLawNonneg variable (X : β„• β†’ Ξ© β†’ ℝ) (hint : Integrable (X 0)) (hindep : Pairwise (IndepFun on X)) (hident : βˆ€ i, IdentDistrib (X i) (X 0)) (hnonneg : βˆ€ i Ο‰, 0 ≀ X i Ο‰) include hint hindep hident hnonneg in /-- The truncation of `Xα΅’` up to `i` satisfies the strong law of large numbers (with respect to the truncated expectation) along the sequence `c^n`, for any `c > 1`, up to a given `Ξ΅ > 0`. This follows from a variance control. -/ theorem strong_law_aux1 {c : ℝ} (c_one : 1 < c) {Ξ΅ : ℝ} (Ξ΅pos : 0 < Ξ΅) : βˆ€α΅ Ο‰, βˆ€αΆ  n : β„• in atTop, |βˆ‘ i ∈ range ⌊c ^ nβŒ‹β‚Š, truncation (X i) i Ο‰ - 𝔼[βˆ‘ i ∈ range ⌊c ^ nβŒ‹β‚Š, truncation (X i) i]| < Ξ΅ * ⌊c ^ nβŒ‹β‚Š := by /- Let `S n = βˆ‘ i ∈ range n, Y i` where `Y i = truncation (X i) i`. We should show that `|S k - 𝔼[S k]| / k ≀ Ξ΅` along the sequence of powers of `c`. For this, we apply Borel-Cantelli: it suffices to show that the converse probabilities are summable. From Chebyshev inequality, this will follow from a variance control `βˆ‘' Var[S (c^i)] / (c^i)^2 < ∞`. This is checked in `I2` using pairwise independence to expand the variance of the sum as the sum of the variances, and then a straightforward but tedious computation (essentially boiling down to the fact that the sum of `1/(c ^ i)^2` beyond a threshold `j` is comparable to `1/j^2`). Note that we have written `c^i` in the above proof sketch, but rigorously one should put integer parts everywhere, making things more painful. We write `u i = ⌊c^iβŒ‹β‚Š` for brevity. -/ have c_pos : 0 < c := zero_lt_one.trans c_one have hX : βˆ€ i, AEStronglyMeasurable (X i) β„™ := fun i => (hident i).symm.aestronglyMeasurable_snd hint.1 have A : βˆ€ i, StronglyMeasurable (indicator (Set.Ioc (-i : ℝ) i) id) := fun i => stronglyMeasurable_id.indicator measurableSet_Ioc set Y := fun n : β„• => truncation (X n) n set S := fun n => βˆ‘ i ∈ range n, Y i with hS let u : β„• β†’ β„• := fun n => ⌊c ^ nβŒ‹β‚Š have u_mono : Monotone u := fun i j hij => Nat.floor_mono (pow_right_monoβ‚€ c_one.le hij) have I1 : βˆ€ K, βˆ‘ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * Var[Y j] ≀ 2 * 𝔼[X 0] := by intro K calc βˆ‘ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * Var[Y j] ≀ βˆ‘ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * 𝔼[truncation (X 0) j ^ 2] := by apply sum_le_sum fun j _ => ?_ refine mul_le_mul_of_nonneg_left ?_ (inv_nonneg.2 (sq_nonneg _)) rw [(hident j).truncation.variance_eq] exact variance_le_expectation_sq (hX 0).truncation _ ≀ 2 * 𝔼[X 0] := sum_variance_truncation_le hint (hnonneg 0) K let C := c ^ 5 * (c - 1)⁻¹ ^ 3 * (2 * 𝔼[X 0]) have I2 : βˆ€ N, βˆ‘ i ∈ range N, ((u i : ℝ) ^ 2)⁻¹ * Var[S (u i)] ≀ C := by intro N calc βˆ‘ i ∈ range N, ((u i : ℝ) ^ 2)⁻¹ * Var[S (u i)] = βˆ‘ i ∈ range N, ((u i : ℝ) ^ 2)⁻¹ * βˆ‘ j ∈ range (u i), Var[Y j] := by congr 1 with i congr 1 rw [hS, IndepFun.variance_sum] Β· intro j _ exact (hident j).aestronglyMeasurable_fst.memLp_truncation Β· intro k _ l _ hkl exact (hindep hkl).comp (A k).measurable (A l).measurable _ = βˆ‘ j ∈ range (u (N - 1)), (βˆ‘ i ∈ range N with j < u i, ((u i : ℝ) ^ 2)⁻¹) * Var[Y j] := by simp_rw [mul_sum, sum_mul, sum_sigma'] refine sum_nbij' (fun p ↦ ⟨p.2, p.1⟩) (fun p ↦ ⟨p.2, p.1⟩) ?_ ?_ ?_ ?_ ?_ Β· simp only [mem_sigma, mem_range, filter_congr_decidable, mem_filter, and_imp, Sigma.forall] exact fun a b haN hb ↦ ⟨hb.trans_le <| u_mono <| Nat.le_pred_of_lt haN, haN, hb⟩ all_goals simp _ ≀ βˆ‘ j ∈ range (u (N - 1)), c ^ 5 * (c - 1)⁻¹ ^ 3 / ↑j ^ 2 * Var[Y j] := by apply sum_le_sum fun j hj => ?_ rcases eq_zero_or_pos j with (rfl | hj) Β· simp only [Nat.cast_zero, zero_pow, Ne, Nat.one_ne_zero, not_false_iff, div_zero, zero_mul] simp only [Y, Nat.cast_zero, truncation_zero, variance_zero, mul_zero, le_rfl] apply mul_le_mul_of_nonneg_right _ (variance_nonneg _ _) convert sum_div_nat_floor_pow_sq_le_div_sq N (Nat.cast_pos.2 hj) c_one using 2 Β· simp only [u, Nat.cast_lt] Β· simp only [Y, S, u, C, one_div] _ = c ^ 5 * (c - 1)⁻¹ ^ 3 * βˆ‘ j ∈ range (u (N - 1)), ((j : ℝ) ^ 2)⁻¹ * Var[Y j] := by simp_rw [mul_sum, div_eq_mul_inv, mul_assoc] _ ≀ c ^ 5 * (c - 1)⁻¹ ^ 3 * (2 * 𝔼[X 0]) := by apply mul_le_mul_of_nonneg_left (I1 _) apply mul_nonneg (pow_nonneg c_pos.le _) exact pow_nonneg (inv_nonneg.2 (sub_nonneg.2 c_one.le)) _ have I3 : βˆ€ N, βˆ‘ i ∈ range N, β„™ {Ο‰ | (u i * Ξ΅ : ℝ) ≀ |S (u i) Ο‰ - 𝔼[S (u i)]|} ≀ ENNReal.ofReal (Ρ⁻¹ ^ 2 * C) := by intro N calc βˆ‘ i ∈ range N, β„™ {Ο‰ | (u i * Ξ΅ : ℝ) ≀ |S (u i) Ο‰ - 𝔼[S (u i)]|} ≀ βˆ‘ i ∈ range N, ENNReal.ofReal (Var[S (u i)] / (u i * Ξ΅) ^ 2) := by refine sum_le_sum fun i _ => ?_ apply meas_ge_le_variance_div_sq Β· exact memLp_finset_sum' _ fun j _ => (hident j).aestronglyMeasurable_fst.memLp_truncation Β· apply mul_pos (Nat.cast_pos.2 _) Ξ΅pos refine zero_lt_one.trans_le ?_ apply Nat.le_floor rw [Nat.cast_one] apply one_le_powβ‚€ c_one.le _ = ENNReal.ofReal (βˆ‘ i ∈ range N, Var[S (u i)] / (u i * Ξ΅) ^ 2) := by rw [ENNReal.ofReal_sum_of_nonneg fun i _ => ?_] exact div_nonneg (variance_nonneg _ _) (sq_nonneg _) _ ≀ ENNReal.ofReal (Ρ⁻¹ ^ 2 * C) := by apply ENNReal.ofReal_le_ofReal -- Porting note: do most of the rewrites under `conv` so as not to expand `variance` conv_lhs => enter [2, i] rw [div_eq_inv_mul, ← inv_pow, mul_inv, mul_comm _ Ρ⁻¹, mul_pow, mul_assoc] rw [← mul_sum] refine mul_le_mul_of_nonneg_left ?_ (sq_nonneg _) conv_lhs => enter [2, i]; rw [inv_pow] exact I2 N have I4 : (βˆ‘' i, β„™ {Ο‰ | (u i * Ξ΅ : ℝ) ≀ |S (u i) Ο‰ - 𝔼[S (u i)]|}) < ∞ := (le_of_tendsto_of_tendsto' (ENNReal.tendsto_nat_tsum _) tendsto_const_nhds I3).trans_lt ENNReal.ofReal_lt_top filter_upwards [ae_eventually_not_mem I4.ne] with Ο‰ hΟ‰ simp_rw [S, not_le, mul_comm, sum_apply] at hΟ‰ convert hΟ‰; simp only [Y, S, u, C, sum_apply] include hint hindep hident hnonneg in /-- The truncation of `Xα΅’` up to `i` satisfies the strong law of large numbers (with respect to the truncated expectation) along the sequence `c^n`, for any `c > 1`. This follows from `strong_law_aux1` by varying `Ξ΅`. -/ theorem strong_law_aux2 {c : ℝ} (c_one : 1 < c) : βˆ€α΅ Ο‰, (fun n : β„• => βˆ‘ i ∈ range ⌊c ^ nβŒ‹β‚Š, truncation (X i) i Ο‰ - 𝔼[βˆ‘ i ∈ range ⌊c ^ nβŒ‹β‚Š, truncation (X i) i]) =o[atTop] fun n : β„• => (⌊c ^ nβŒ‹β‚Š : ℝ) := by obtain ⟨v, -, v_pos, v_lim⟩ : βˆƒ v : β„• β†’ ℝ, StrictAnti v ∧ (βˆ€ n : β„•, 0 < v n) ∧ Tendsto v atTop (𝓝 0) := exists_seq_strictAnti_tendsto (0 : ℝ) have := fun i => strong_law_aux1 X hint hindep hident hnonneg c_one (v_pos i) filter_upwards [ae_all_iff.2 this] with Ο‰ hΟ‰ apply Asymptotics.isLittleO_iff.2 fun Ξ΅ Ξ΅pos => ?_ obtain ⟨i, hi⟩ : βˆƒ i, v i < Ξ΅ := ((tendsto_order.1 v_lim).2 Ξ΅ Ξ΅pos).exists filter_upwards [hΟ‰ i] with n hn simp only [Real.norm_eq_abs, abs_abs, Nat.abs_cast] exact hn.le.trans (mul_le_mul_of_nonneg_right hi.le (Nat.cast_nonneg _)) include hint hident in /-- The expectation of the truncated version of `Xα΅’` behaves asymptotically like the whole expectation. This follows from convergence and CesΓ ro averaging. -/ theorem strong_law_aux3 : (fun n => 𝔼[βˆ‘ i ∈ range n, truncation (X i) i] - n * 𝔼[X 0]) =o[atTop] ((↑) : β„• β†’ ℝ) := by have A : Tendsto (fun i => 𝔼[truncation (X i) i]) atTop (𝓝 𝔼[X 0]) := by convert (tendsto_integral_truncation hint).comp tendsto_natCast_atTop_atTop using 1 ext i exact (hident i).truncation.integral_eq convert Asymptotics.isLittleO_sum_range_of_tendsto_zero (tendsto_sub_nhds_zero_iff.2 A) using 1 ext1 n simp only [sum_sub_distrib, sum_const, card_range, nsmul_eq_mul, sum_apply, sub_left_inj] rw [integral_finset_sum _ fun i _ => ?_] exact ((hident i).symm.integrable_snd hint).1.integrable_truncation include hint hindep hident hnonneg in /-- The truncation of `Xα΅’` up to `i` satisfies the strong law of large numbers (with respect to the original expectation) along the sequence `c^n`, for any `c > 1`. This follows from the version from the truncated expectation, and the fact that the truncated and the original expectations have the same asymptotic behavior. -/ theorem strong_law_aux4 {c : ℝ} (c_one : 1 < c) : βˆ€α΅ Ο‰, (fun n : β„• => βˆ‘ i ∈ range ⌊c ^ nβŒ‹β‚Š, truncation (X i) i Ο‰ - ⌊c ^ nβŒ‹β‚Š * 𝔼[X 0]) =o[atTop] fun n : β„• => (⌊c ^ nβŒ‹β‚Š : ℝ) := by filter_upwards [strong_law_aux2 X hint hindep hident hnonneg c_one] with Ο‰ hΟ‰
have A : Tendsto (fun n : β„• => ⌊c ^ nβŒ‹β‚Š) atTop atTop := tendsto_nat_floor_atTop.comp (tendsto_pow_atTop_atTop_of_one_lt c_one) convert hΟ‰.add ((strong_law_aux3 X hint hident).comp_tendsto A) using 1 ext1 n simp include hint hident hnonneg in /-- The truncated and non-truncated versions of `Xα΅’` have the same asymptotic behavior, as they almost surely coincide at all but finitely many steps. This follows from a probability computation and Borel-Cantelli. -/ theorem strong_law_aux5 :
Mathlib/Probability/StrongLaw.lean
522
532
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Alex Kontorovich, Heather Macbeth -/ import Mathlib.MeasureTheory.Group.Action import Mathlib.MeasureTheory.Group.Pointwise import Mathlib.MeasureTheory.Integral.Lebesgue.Map import Mathlib.MeasureTheory.Integral.Bochner.Set /-! # Fundamental domain of a group action A set `s` is said to be a *fundamental domain* of an action of a group `G` on a measurable space `Ξ±` with respect to a measure `ΞΌ` if * `s` is a measurable set; * the sets `g β€’ s` over all `g : G` cover almost all points of the whole space; * the sets `g β€’ s`, are pairwise a.e. disjoint, i.e., `ΞΌ (g₁ β€’ s ∩ gβ‚‚ β€’ s) = 0` whenever `g₁ β‰  gβ‚‚`; we require this for `gβ‚‚ = 1` in the definition, then deduce it for any two `g₁ β‰  gβ‚‚`. In this file we prove that in case of a countable group `G` and a measure preserving action, any two fundamental domains have the same measure, and for a `G`-invariant function, its integrals over any two fundamental domains are equal to each other. We also generate additive versions of all theorems in this file using the `to_additive` attribute. * We define the `HasFundamentalDomain` typeclass, in particular to be able to define the `covolume` of a quotient of `Ξ±` by a group `G`, which under reasonable conditions does not depend on the choice of fundamental domain. * We define the `QuotientMeasureEqMeasurePreimage` typeclass to describe a situation in which a measure `ΞΌ` on `Ξ± β§Έ G` can be computed by taking a measure `Ξ½` on `Ξ±` of the intersection of the pullback with a fundamental domain. ## Main declarations * `MeasureTheory.IsFundamentalDomain`: Predicate for a set to be a fundamental domain of the action of a group * `MeasureTheory.fundamentalFrontier`: Fundamental frontier of a set under the action of a group. Elements of `s` that belong to some other translate of `s`. * `MeasureTheory.fundamentalInterior`: Fundamental interior of a set under the action of a group. Elements of `s` that do not belong to any other translate of `s`. -/ open scoped ENNReal Pointwise Topology NNReal ENNReal MeasureTheory open MeasureTheory MeasureTheory.Measure Set Function TopologicalSpace Filter namespace MeasureTheory /-- A measurable set `s` is a *fundamental domain* for an additive action of an additive group `G` on a measurable space `Ξ±` with respect to a measure `Ξ±` if the sets `g +α΅₯ s`, `g : G`, are pairwise a.e. disjoint and cover the whole space. -/ structure IsAddFundamentalDomain (G : Type*) {Ξ± : Type*} [Zero G] [VAdd G Ξ±] [MeasurableSpace Ξ±] (s : Set Ξ±) (ΞΌ : Measure Ξ± := by volume_tac) : Prop where protected nullMeasurableSet : NullMeasurableSet s ΞΌ protected ae_covers : βˆ€α΅ x βˆ‚ΞΌ, βˆƒ g : G, g +α΅₯ x ∈ s protected aedisjoint : Pairwise <| (AEDisjoint ΞΌ on fun g : G => g +α΅₯ s) /-- A measurable set `s` is a *fundamental domain* for an action of a group `G` on a measurable space `Ξ±` with respect to a measure `Ξ±` if the sets `g β€’ s`, `g : G`, are pairwise a.e. disjoint and cover the whole space. -/ @[to_additive IsAddFundamentalDomain] structure IsFundamentalDomain (G : Type*) {Ξ± : Type*} [One G] [SMul G Ξ±] [MeasurableSpace Ξ±] (s : Set Ξ±) (ΞΌ : Measure Ξ± := by volume_tac) : Prop where protected nullMeasurableSet : NullMeasurableSet s ΞΌ protected ae_covers : βˆ€α΅ x βˆ‚ΞΌ, βˆƒ g : G, g β€’ x ∈ s protected aedisjoint : Pairwise <| (AEDisjoint ΞΌ on fun g : G => g β€’ s) variable {G H Ξ± Ξ² E : Type*} namespace IsFundamentalDomain variable [Group G] [Group H] [MulAction G Ξ±] [MeasurableSpace Ξ±] [MulAction H Ξ²] [MeasurableSpace Ξ²] [NormedAddCommGroup E] {s t : Set Ξ±} {ΞΌ : Measure Ξ±} /-- If for each `x : Ξ±`, exactly one of `g β€’ x`, `g : G`, belongs to a measurable set `s`, then `s` is a fundamental domain for the action of `G` on `Ξ±`. -/ @[to_additive "If for each `x : Ξ±`, exactly one of `g +α΅₯ x`, `g : G`, belongs to a measurable set `s`, then `s` is a fundamental domain for the additive action of `G` on `Ξ±`."] theorem mk' (h_meas : NullMeasurableSet s ΞΌ) (h_exists : βˆ€ x : Ξ±, βˆƒ! g : G, g β€’ x ∈ s) : IsFundamentalDomain G s ΞΌ where nullMeasurableSet := h_meas ae_covers := Eventually.of_forall fun x => (h_exists x).exists aedisjoint a b hab := Disjoint.aedisjoint <| disjoint_left.2 fun x hxa hxb => by rw [mem_smul_set_iff_inv_smul_mem] at hxa hxb exact hab (inv_injective <| (h_exists x).unique hxa hxb) /-- For `s` to be a fundamental domain, it's enough to check `MeasureTheory.AEDisjoint (g β€’ s) s` for `g β‰  1`. -/ @[to_additive "For `s` to be a fundamental domain, it's enough to check `MeasureTheory.AEDisjoint (g +α΅₯ s) s` for `g β‰  0`."] theorem mk'' (h_meas : NullMeasurableSet s ΞΌ) (h_ae_covers : βˆ€α΅ x βˆ‚ΞΌ, βˆƒ g : G, g β€’ x ∈ s) (h_ae_disjoint : βˆ€ g, g β‰  (1 : G) β†’ AEDisjoint ΞΌ (g β€’ s) s) (h_qmp : βˆ€ g : G, QuasiMeasurePreserving ((g β€’ Β·) : Ξ± β†’ Ξ±) ΞΌ ΞΌ) : IsFundamentalDomain G s ΞΌ where nullMeasurableSet := h_meas ae_covers := h_ae_covers aedisjoint := pairwise_aedisjoint_of_aedisjoint_forall_ne_one h_ae_disjoint h_qmp /-- If a measurable space has a finite measure `ΞΌ` and a countable group `G` acts quasi-measure-preservingly, then to show that a set `s` is a fundamental domain, it is sufficient to check that its translates `g β€’ s` are (almost) disjoint and that the sum `βˆ‘' g, ΞΌ (g β€’ s)` is sufficiently large. -/ @[to_additive "If a measurable space has a finite measure `ΞΌ` and a countable additive group `G` acts quasi-measure-preservingly, then to show that a set `s` is a fundamental domain, it is sufficient to check that its translates `g +α΅₯ s` are (almost) disjoint and that the sum `βˆ‘' g, ΞΌ (g +α΅₯ s)` is sufficiently large."] theorem mk_of_measure_univ_le [IsFiniteMeasure ΞΌ] [Countable G] (h_meas : NullMeasurableSet s ΞΌ) (h_ae_disjoint : βˆ€ g β‰  (1 : G), AEDisjoint ΞΌ (g β€’ s) s) (h_qmp : βˆ€ g : G, QuasiMeasurePreserving (g β€’ Β· : Ξ± β†’ Ξ±) ΞΌ ΞΌ) (h_measure_univ_le : ΞΌ (univ : Set Ξ±) ≀ βˆ‘' g : G, ΞΌ (g β€’ s)) : IsFundamentalDomain G s ΞΌ := have aedisjoint : Pairwise (AEDisjoint ΞΌ on fun g : G => g β€’ s) := pairwise_aedisjoint_of_aedisjoint_forall_ne_one h_ae_disjoint h_qmp { nullMeasurableSet := h_meas aedisjoint ae_covers := by replace h_meas : βˆ€ g : G, NullMeasurableSet (g β€’ s) ΞΌ := fun g => by rw [← inv_inv g, ← preimage_smul]; exact h_meas.preimage (h_qmp g⁻¹) have h_meas' : NullMeasurableSet {a | βˆƒ g : G, g β€’ a ∈ s} ΞΌ := by rw [← iUnion_smul_eq_setOf_exists]; exact .iUnion h_meas rw [ae_iff_measure_eq h_meas', ← iUnion_smul_eq_setOf_exists] refine le_antisymm (measure_mono <| subset_univ _) ?_ rw [measure_iUnionβ‚€ aedisjoint h_meas] exact h_measure_univ_le } @[to_additive] theorem iUnion_smul_ae_eq (h : IsFundamentalDomain G s ΞΌ) : ⋃ g : G, g β€’ s =ᡐ[ΞΌ] univ := eventuallyEq_univ.2 <| h.ae_covers.mono fun _ ⟨g, hg⟩ => mem_iUnion.2 ⟨g⁻¹, _, hg, inv_smul_smul _ _⟩ @[to_additive] theorem measure_ne_zero [Countable G] [SMulInvariantMeasure G Ξ± ΞΌ] (hΞΌ : ΞΌ β‰  0) (h : IsFundamentalDomain G s ΞΌ) : ΞΌ s β‰  0 := by have hc := measure_univ_pos.mpr hΞΌ contrapose! hc rw [← measure_congr h.iUnion_smul_ae_eq] refine le_trans (measure_iUnion_le _) ?_ simp_rw [measure_smul, hc, tsum_zero, le_refl] @[to_additive] theorem mono (h : IsFundamentalDomain G s ΞΌ) {Ξ½ : Measure Ξ±} (hle : Ξ½ β‰ͺ ΞΌ) : IsFundamentalDomain G s Ξ½ := ⟨h.1.mono_ac hle, hle h.2, h.aedisjoint.mono fun _ _ h => hle h⟩ @[to_additive] theorem preimage_of_equiv {Ξ½ : Measure Ξ²} (h : IsFundamentalDomain G s ΞΌ) {f : Ξ² β†’ Ξ±} (hf : QuasiMeasurePreserving f Ξ½ ΞΌ) {e : G β†’ H} (he : Bijective e) (hef : βˆ€ g, Semiconj f (e g β€’ Β·) (g β€’ Β·)) : IsFundamentalDomain H (f ⁻¹' s) Ξ½ where nullMeasurableSet := h.nullMeasurableSet.preimage hf ae_covers := (hf.ae h.ae_covers).mono fun x ⟨g, hg⟩ => ⟨e g, by rwa [mem_preimage, hef g x]⟩ aedisjoint a b hab := by lift e to G ≃ H using he have : (e.symm a⁻¹)⁻¹ β‰  (e.symm b⁻¹)⁻¹ := by simp [hab] have := (h.aedisjoint this).preimage hf simp only [Semiconj] at hef simpa only [onFun, ← preimage_smul_inv, preimage_preimage, ← hef, e.apply_symm_apply, inv_inv] using this @[to_additive] theorem image_of_equiv {Ξ½ : Measure Ξ²} (h : IsFundamentalDomain G s ΞΌ) (f : Ξ± ≃ Ξ²) (hf : QuasiMeasurePreserving f.symm Ξ½ ΞΌ) (e : H ≃ G) (hef : βˆ€ g, Semiconj f (e g β€’ Β·) (g β€’ Β·)) : IsFundamentalDomain H (f '' s) Ξ½ := by rw [f.image_eq_preimage] refine h.preimage_of_equiv hf e.symm.bijective fun g x => ?_ rcases f.surjective x with ⟨x, rfl⟩ rw [← hef _ _, f.symm_apply_apply, f.symm_apply_apply, e.apply_symm_apply] @[to_additive] theorem pairwise_aedisjoint_of_ac {Ξ½} (h : IsFundamentalDomain G s ΞΌ) (hΞ½ : Ξ½ β‰ͺ ΞΌ) : Pairwise fun g₁ gβ‚‚ : G => AEDisjoint Ξ½ (g₁ β€’ s) (gβ‚‚ β€’ s) := h.aedisjoint.mono fun _ _ H => hΞ½ H @[to_additive] theorem smul_of_comm {G' : Type*} [Group G'] [MulAction G' Ξ±] [MeasurableSpace G'] [MeasurableSMul G' Ξ±] [SMulInvariantMeasure G' Ξ± ΞΌ] [SMulCommClass G' G Ξ±] (h : IsFundamentalDomain G s ΞΌ) (g : G') : IsFundamentalDomain G (g β€’ s) ΞΌ := h.image_of_equiv (MulAction.toPerm g) (measurePreserving_smul _ _).quasiMeasurePreserving (Equiv.refl _) <| smul_comm g variable [MeasurableSpace G] [MeasurableSMul G Ξ±] [SMulInvariantMeasure G Ξ± ΞΌ] @[to_additive] theorem nullMeasurableSet_smul (h : IsFundamentalDomain G s ΞΌ) (g : G) : NullMeasurableSet (g β€’ s) ΞΌ := h.nullMeasurableSet.smul g @[to_additive] theorem restrict_restrict (h : IsFundamentalDomain G s ΞΌ) (g : G) (t : Set Ξ±) : (ΞΌ.restrict t).restrict (g β€’ s) = ΞΌ.restrict (g β€’ s ∩ t) := restrict_restrictβ‚€ ((h.nullMeasurableSet_smul g).mono restrict_le_self) @[to_additive] theorem smul (h : IsFundamentalDomain G s ΞΌ) (g : G) : IsFundamentalDomain G (g β€’ s) ΞΌ := h.image_of_equiv (MulAction.toPerm g) (measurePreserving_smul _ _).quasiMeasurePreserving ⟨fun g' => g⁻¹ * g' * g, fun g' => g * g' * g⁻¹, fun g' => by simp [mul_assoc], fun g' => by simp [mul_assoc]⟩ fun g' x => by simp [smul_smul, mul_assoc] variable [Countable G] {Ξ½ : Measure Ξ±} @[to_additive] theorem sum_restrict_of_ac (h : IsFundamentalDomain G s ΞΌ) (hΞ½ : Ξ½ β‰ͺ ΞΌ) : (sum fun g : G => Ξ½.restrict (g β€’ s)) = Ξ½ := by rw [← restrict_iUnion_ae (h.aedisjoint.mono fun i j h => hΞ½ h) fun g => (h.nullMeasurableSet_smul g).mono_ac hΞ½, restrict_congr_set (hΞ½ h.iUnion_smul_ae_eq), restrict_univ] @[to_additive] theorem lintegral_eq_tsum_of_ac (h : IsFundamentalDomain G s ΞΌ) (hΞ½ : Ξ½ β‰ͺ ΞΌ) (f : Ξ± β†’ ℝβ‰₯0∞) : ∫⁻ x, f x βˆ‚Ξ½ = βˆ‘' g : G, ∫⁻ x in g β€’ s, f x βˆ‚Ξ½ := by rw [← lintegral_sum_measure, h.sum_restrict_of_ac hΞ½] @[to_additive] theorem sum_restrict (h : IsFundamentalDomain G s ΞΌ) : (sum fun g : G => ΞΌ.restrict (g β€’ s)) = ΞΌ := h.sum_restrict_of_ac (refl _) @[to_additive] theorem lintegral_eq_tsum (h : IsFundamentalDomain G s ΞΌ) (f : Ξ± β†’ ℝβ‰₯0∞) : ∫⁻ x, f x βˆ‚ΞΌ = βˆ‘' g : G, ∫⁻ x in g β€’ s, f x βˆ‚ΞΌ := h.lintegral_eq_tsum_of_ac (refl _) f @[to_additive] theorem lintegral_eq_tsum' (h : IsFundamentalDomain G s ΞΌ) (f : Ξ± β†’ ℝβ‰₯0∞) : ∫⁻ x, f x βˆ‚ΞΌ = βˆ‘' g : G, ∫⁻ x in s, f (g⁻¹ β€’ x) βˆ‚ΞΌ := calc ∫⁻ x, f x βˆ‚ΞΌ = βˆ‘' g : G, ∫⁻ x in g β€’ s, f x βˆ‚ΞΌ := h.lintegral_eq_tsum f _ = βˆ‘' g : G, ∫⁻ x in g⁻¹ β€’ s, f x βˆ‚ΞΌ := ((Equiv.inv G).tsum_eq _).symm _ = βˆ‘' g : G, ∫⁻ x in s, f (g⁻¹ β€’ x) βˆ‚ΞΌ := tsum_congr fun g => Eq.symm <| (measurePreserving_smul g⁻¹ ΞΌ).setLIntegral_comp_emb (measurableEmbedding_const_smul _) _ _ @[to_additive] lemma lintegral_eq_tsum'' (h : IsFundamentalDomain G s ΞΌ) (f : Ξ± β†’ ℝβ‰₯0∞) : ∫⁻ x, f x βˆ‚ΞΌ = βˆ‘' g : G, ∫⁻ x in s, f (g β€’ x) βˆ‚ΞΌ := (lintegral_eq_tsum' h f).trans ((Equiv.inv G).tsum_eq (fun g ↦ ∫⁻ (x : Ξ±) in s, f (g β€’ x) βˆ‚ΞΌ)) @[to_additive] theorem setLIntegral_eq_tsum (h : IsFundamentalDomain G s ΞΌ) (f : Ξ± β†’ ℝβ‰₯0∞) (t : Set Ξ±) : ∫⁻ x in t, f x βˆ‚ΞΌ = βˆ‘' g : G, ∫⁻ x in t ∩ g β€’ s, f x βˆ‚ΞΌ := calc ∫⁻ x in t, f x βˆ‚ΞΌ = βˆ‘' g : G, ∫⁻ x in g β€’ s, f x βˆ‚ΞΌ.restrict t := h.lintegral_eq_tsum_of_ac restrict_le_self.absolutelyContinuous _ _ = βˆ‘' g : G, ∫⁻ x in t ∩ g β€’ s, f x βˆ‚ΞΌ := by simp only [h.restrict_restrict, inter_comm] @[to_additive] theorem setLIntegral_eq_tsum' (h : IsFundamentalDomain G s ΞΌ) (f : Ξ± β†’ ℝβ‰₯0∞) (t : Set Ξ±) : ∫⁻ x in t, f x βˆ‚ΞΌ = βˆ‘' g : G, ∫⁻ x in g β€’ t ∩ s, f (g⁻¹ β€’ x) βˆ‚ΞΌ := calc ∫⁻ x in t, f x βˆ‚ΞΌ = βˆ‘' g : G, ∫⁻ x in t ∩ g β€’ s, f x βˆ‚ΞΌ := h.setLIntegral_eq_tsum f t _ = βˆ‘' g : G, ∫⁻ x in t ∩ g⁻¹ β€’ s, f x βˆ‚ΞΌ := ((Equiv.inv G).tsum_eq _).symm _ = βˆ‘' g : G, ∫⁻ x in g⁻¹ β€’ (g β€’ t ∩ s), f x βˆ‚ΞΌ := by simp only [smul_set_inter, inv_smul_smul] _ = βˆ‘' g : G, ∫⁻ x in g β€’ t ∩ s, f (g⁻¹ β€’ x) βˆ‚ΞΌ := tsum_congr fun g => Eq.symm <| (measurePreserving_smul g⁻¹ ΞΌ).setLIntegral_comp_emb (measurableEmbedding_const_smul _) _ _ @[to_additive] theorem measure_eq_tsum_of_ac (h : IsFundamentalDomain G s ΞΌ) (hΞ½ : Ξ½ β‰ͺ ΞΌ) (t : Set Ξ±) : Ξ½ t = βˆ‘' g : G, Ξ½ (t ∩ g β€’ s) := by have H : Ξ½.restrict t β‰ͺ ΞΌ := Measure.restrict_le_self.absolutelyContinuous.trans hΞ½ simpa only [setLIntegral_one, Pi.one_def, Measure.restrict_applyβ‚€ ((h.nullMeasurableSet_smul _).mono_ac H), inter_comm] using h.lintegral_eq_tsum_of_ac H 1 @[to_additive] theorem measure_eq_tsum' (h : IsFundamentalDomain G s ΞΌ) (t : Set Ξ±) : ΞΌ t = βˆ‘' g : G, ΞΌ (t ∩ g β€’ s) := h.measure_eq_tsum_of_ac AbsolutelyContinuous.rfl t @[to_additive] theorem measure_eq_tsum (h : IsFundamentalDomain G s ΞΌ) (t : Set Ξ±) : ΞΌ t = βˆ‘' g : G, ΞΌ (g β€’ t ∩ s) := by simpa only [setLIntegral_one] using h.setLIntegral_eq_tsum' (fun _ => 1) t @[to_additive] theorem measure_zero_of_invariant (h : IsFundamentalDomain G s ΞΌ) (t : Set Ξ±) (ht : βˆ€ g : G, g β€’ t = t) (hts : ΞΌ (t ∩ s) = 0) : ΞΌ t = 0 := by rw [measure_eq_tsum h]; simp [ht, hts] /-- Given a measure space with an action of a finite group `G`, the measure of any `G`-invariant set is determined by the measure of its intersection with a fundamental domain for the action of `G`. -/ @[to_additive measure_eq_card_smul_of_vadd_ae_eq_self "Given a measure space with an action of a finite additive group `G`, the measure of any `G`-invariant set is determined by the measure of its intersection with a fundamental domain for the action of `G`."] theorem measure_eq_card_smul_of_smul_ae_eq_self [Finite G] (h : IsFundamentalDomain G s ΞΌ) (t : Set Ξ±) (ht : βˆ€ g : G, (g β€’ t : Set Ξ±) =ᡐ[ΞΌ] t) : ΞΌ t = Nat.card G β€’ ΞΌ (t ∩ s) := by haveI : Fintype G := Fintype.ofFinite G rw [h.measure_eq_tsum] replace ht : βˆ€ g : G, (g β€’ t ∩ s : Set Ξ±) =ᡐ[ΞΌ] (t ∩ s : Set Ξ±) := fun g => ae_eq_set_inter (ht g) (ae_eq_refl s) simp_rw [measure_congr (ht _), tsum_fintype, Finset.sum_const, Nat.card_eq_fintype_card, Finset.card_univ] @[to_additive] protected theorem setLIntegral_eq (hs : IsFundamentalDomain G s ΞΌ) (ht : IsFundamentalDomain G t ΞΌ) (f : Ξ± β†’ ℝβ‰₯0∞) (hf : βˆ€ (g : G) (x), f (g β€’ x) = f x) : ∫⁻ x in s, f x βˆ‚ΞΌ = ∫⁻ x in t, f x βˆ‚ΞΌ := calc ∫⁻ x in s, f x βˆ‚ΞΌ = βˆ‘' g : G, ∫⁻ x in s ∩ g β€’ t, f x βˆ‚ΞΌ := ht.setLIntegral_eq_tsum _ _ _ = βˆ‘' g : G, ∫⁻ x in g β€’ t ∩ s, f (g⁻¹ β€’ x) βˆ‚ΞΌ := by simp only [hf, inter_comm] _ = ∫⁻ x in t, f x βˆ‚ΞΌ := (hs.setLIntegral_eq_tsum' _ _).symm @[to_additive] theorem measure_set_eq (hs : IsFundamentalDomain G s ΞΌ) (ht : IsFundamentalDomain G t ΞΌ) {A : Set Ξ±} (hAβ‚€ : MeasurableSet A) (hA : βˆ€ g : G, (fun x => g β€’ x) ⁻¹' A = A) : ΞΌ (A ∩ s) = ΞΌ (A ∩ t) := by have : ∫⁻ x in s, A.indicator 1 x βˆ‚ΞΌ = ∫⁻ x in t, A.indicator 1 x βˆ‚ΞΌ := by refine hs.setLIntegral_eq ht (Set.indicator A fun _ => 1) fun g x ↦ ?_ convert (Set.indicator_comp_right (g β€’ Β· : Ξ± β†’ Ξ±) (g := fun _ ↦ (1 : ℝβ‰₯0∞))).symm rw [hA g] simpa [Measure.restrict_apply hAβ‚€, lintegral_indicator hAβ‚€] using this /-- If `s` and `t` are two fundamental domains of the same action, then their measures are equal. -/ @[to_additive "If `s` and `t` are two fundamental domains of the same action, then their measures are equal."] protected theorem measure_eq (hs : IsFundamentalDomain G s ΞΌ) (ht : IsFundamentalDomain G t ΞΌ) : ΞΌ s = ΞΌ t := by simpa only [setLIntegral_one] using hs.setLIntegral_eq ht (fun _ => 1) fun _ _ => rfl @[to_additive] protected theorem aestronglyMeasurable_on_iff {Ξ² : Type*} [TopologicalSpace Ξ²] [PseudoMetrizableSpace Ξ²] (hs : IsFundamentalDomain G s ΞΌ) (ht : IsFundamentalDomain G t ΞΌ) {f : Ξ± β†’ Ξ²} (hf : βˆ€ (g : G) (x), f (g β€’ x) = f x) : AEStronglyMeasurable f (ΞΌ.restrict s) ↔ AEStronglyMeasurable f (ΞΌ.restrict t) := calc AEStronglyMeasurable f (ΞΌ.restrict s) ↔ AEStronglyMeasurable f (Measure.sum fun g : G => ΞΌ.restrict (g β€’ t ∩ s)) := by simp only [← ht.restrict_restrict, ht.sum_restrict_of_ac restrict_le_self.absolutelyContinuous] _ ↔ βˆ€ g : G, AEStronglyMeasurable f (ΞΌ.restrict (g β€’ (g⁻¹ β€’ s ∩ t))) := by simp only [smul_set_inter, inter_comm, smul_inv_smul, aestronglyMeasurable_sum_measure_iff] _ ↔ βˆ€ g : G, AEStronglyMeasurable f (ΞΌ.restrict (g⁻¹ β€’ (g⁻¹⁻¹ β€’ s ∩ t))) := inv_surjective.forall _ ↔ βˆ€ g : G, AEStronglyMeasurable f (ΞΌ.restrict (g⁻¹ β€’ (g β€’ s ∩ t))) := by simp only [inv_inv] _ ↔ βˆ€ g : G, AEStronglyMeasurable f (ΞΌ.restrict (g β€’ s ∩ t)) := by refine forall_congr' fun g => ?_ have he : MeasurableEmbedding (g⁻¹ β€’ Β· : Ξ± β†’ Ξ±) := measurableEmbedding_const_smul _ rw [← image_smul, ← ((measurePreserving_smul g⁻¹ ΞΌ).restrict_image_emb he _).aestronglyMeasurable_comp_iff he] simp only [Function.comp_def, hf] _ ↔ AEStronglyMeasurable f (ΞΌ.restrict t) := by simp only [← aestronglyMeasurable_sum_measure_iff, ← hs.restrict_restrict, hs.sum_restrict_of_ac restrict_le_self.absolutelyContinuous] @[deprecated (since := "2025-04-09")] alias aEStronglyMeasurable_on_iff := MeasureTheory.IsFundamentalDomain.aestronglyMeasurable_on_iff @[deprecated (since := "2025-04-09")] alias _root_.MeasureTheory.IsAddFundamentalDomain.aEStronglyMeasurable_on_iff := MeasureTheory.IsAddFundamentalDomain.aestronglyMeasurable_on_iff @[to_additive] protected theorem hasFiniteIntegral_on_iff (hs : IsFundamentalDomain G s ΞΌ) (ht : IsFundamentalDomain G t ΞΌ) {f : Ξ± β†’ E} (hf : βˆ€ (g : G) (x), f (g β€’ x) = f x) : HasFiniteIntegral f (ΞΌ.restrict s) ↔ HasFiniteIntegral f (ΞΌ.restrict t) := by dsimp only [HasFiniteIntegral] rw [hs.setLIntegral_eq ht] intro g x; rw [hf] @[to_additive] protected theorem integrableOn_iff (hs : IsFundamentalDomain G s ΞΌ) (ht : IsFundamentalDomain G t ΞΌ) {f : Ξ± β†’ E} (hf : βˆ€ (g : G) (x), f (g β€’ x) = f x) : IntegrableOn f s ΞΌ ↔ IntegrableOn f t ΞΌ := and_congr (hs.aestronglyMeasurable_on_iff ht hf) (hs.hasFiniteIntegral_on_iff ht hf) variable [NormedSpace ℝ E] @[to_additive] theorem integral_eq_tsum_of_ac (h : IsFundamentalDomain G s ΞΌ) (hΞ½ : Ξ½ β‰ͺ ΞΌ) (f : Ξ± β†’ E) (hf : Integrable f Ξ½) : ∫ x, f x βˆ‚Ξ½ = βˆ‘' g : G, ∫ x in g β€’ s, f x βˆ‚Ξ½ := by rw [← MeasureTheory.integral_sum_measure, h.sum_restrict_of_ac hΞ½] rw [h.sum_restrict_of_ac hΞ½] exact hf @[to_additive] theorem integral_eq_tsum (h : IsFundamentalDomain G s ΞΌ) (f : Ξ± β†’ E) (hf : Integrable f ΞΌ) : ∫ x, f x βˆ‚ΞΌ = βˆ‘' g : G, ∫ x in g β€’ s, f x βˆ‚ΞΌ := integral_eq_tsum_of_ac h (by rfl) f hf @[to_additive] theorem integral_eq_tsum' (h : IsFundamentalDomain G s ΞΌ) (f : Ξ± β†’ E) (hf : Integrable f ΞΌ) : ∫ x, f x βˆ‚ΞΌ = βˆ‘' g : G, ∫ x in s, f (g⁻¹ β€’ x) βˆ‚ΞΌ := calc ∫ x, f x βˆ‚ΞΌ = βˆ‘' g : G, ∫ x in g β€’ s, f x βˆ‚ΞΌ := h.integral_eq_tsum f hf _ = βˆ‘' g : G, ∫ x in g⁻¹ β€’ s, f x βˆ‚ΞΌ := ((Equiv.inv G).tsum_eq _).symm _ = βˆ‘' g : G, ∫ x in s, f (g⁻¹ β€’ x) βˆ‚ΞΌ := tsum_congr fun g => (measurePreserving_smul g⁻¹ ΞΌ).setIntegral_image_emb (measurableEmbedding_const_smul _) _ _ @[to_additive] lemma integral_eq_tsum'' (h : IsFundamentalDomain G s ΞΌ) (f : Ξ± β†’ E) (hf : Integrable f ΞΌ) : ∫ x, f x βˆ‚ΞΌ = βˆ‘' g : G, ∫ x in s, f (g β€’ x) βˆ‚ΞΌ := (integral_eq_tsum' h f hf).trans ((Equiv.inv G).tsum_eq (fun g ↦ ∫ (x : Ξ±) in s, f (g β€’ x) βˆ‚ΞΌ)) @[to_additive] theorem setIntegral_eq_tsum (h : IsFundamentalDomain G s ΞΌ) {f : Ξ± β†’ E} {t : Set Ξ±} (hf : IntegrableOn f t ΞΌ) : ∫ x in t, f x βˆ‚ΞΌ = βˆ‘' g : G, ∫ x in t ∩ g β€’ s, f x βˆ‚ΞΌ := calc ∫ x in t, f x βˆ‚ΞΌ = βˆ‘' g : G, ∫ x in g β€’ s, f x βˆ‚ΞΌ.restrict t := h.integral_eq_tsum_of_ac restrict_le_self.absolutelyContinuous f hf _ = βˆ‘' g : G, ∫ x in t ∩ g β€’ s, f x βˆ‚ΞΌ := by simp only [h.restrict_restrict, measure_smul, inter_comm] @[to_additive] theorem setIntegral_eq_tsum' (h : IsFundamentalDomain G s ΞΌ) {f : Ξ± β†’ E} {t : Set Ξ±} (hf : IntegrableOn f t ΞΌ) : ∫ x in t, f x βˆ‚ΞΌ = βˆ‘' g : G, ∫ x in g β€’ t ∩ s, f (g⁻¹ β€’ x) βˆ‚ΞΌ := calc ∫ x in t, f x βˆ‚ΞΌ = βˆ‘' g : G, ∫ x in t ∩ g β€’ s, f x βˆ‚ΞΌ := h.setIntegral_eq_tsum hf _ = βˆ‘' g : G, ∫ x in t ∩ g⁻¹ β€’ s, f x βˆ‚ΞΌ := ((Equiv.inv G).tsum_eq _).symm _ = βˆ‘' g : G, ∫ x in g⁻¹ β€’ (g β€’ t ∩ s), f x βˆ‚ΞΌ := by simp only [smul_set_inter, inv_smul_smul] _ = βˆ‘' g : G, ∫ x in g β€’ t ∩ s, f (g⁻¹ β€’ x) βˆ‚ΞΌ := tsum_congr fun g => (measurePreserving_smul g⁻¹ ΞΌ).setIntegral_image_emb (measurableEmbedding_const_smul _) _ _ @[to_additive] protected theorem setIntegral_eq (hs : IsFundamentalDomain G s ΞΌ) (ht : IsFundamentalDomain G t ΞΌ) {f : Ξ± β†’ E} (hf : βˆ€ (g : G) (x), f (g β€’ x) = f x) : ∫ x in s, f x βˆ‚ΞΌ = ∫ x in t, f x βˆ‚ΞΌ := by by_cases hfs : IntegrableOn f s ΞΌ Β· have hft : IntegrableOn f t ΞΌ := by rwa [ht.integrableOn_iff hs hf] calc ∫ x in s, f x βˆ‚ΞΌ = βˆ‘' g : G, ∫ x in s ∩ g β€’ t, f x βˆ‚ΞΌ := ht.setIntegral_eq_tsum hfs _ = βˆ‘' g : G, ∫ x in g β€’ t ∩ s, f (g⁻¹ β€’ x) βˆ‚ΞΌ := by simp only [hf, inter_comm] _ = ∫ x in t, f x βˆ‚ΞΌ := (hs.setIntegral_eq_tsum' hft).symm Β· rw [integral_undef hfs, integral_undef] rwa [hs.integrableOn_iff ht hf] at hfs /-- If the action of a countable group `G` admits an invariant measure `ΞΌ` with a fundamental domain `s`, then every null-measurable set `t` such that the sets `g β€’ t ∩ s` are pairwise a.e.-disjoint has measure at most `ΞΌ s`. -/ @[to_additive "If the additive action of a countable group `G` admits an invariant measure `ΞΌ` with a fundamental domain `s`, then every null-measurable set `t` such that the sets `g +α΅₯ t ∩ s` are pairwise a.e.-disjoint has measure at most `ΞΌ s`."] theorem measure_le_of_pairwise_disjoint (hs : IsFundamentalDomain G s ΞΌ) (ht : NullMeasurableSet t ΞΌ) (hd : Pairwise (AEDisjoint ΞΌ on fun g : G => g β€’ t ∩ s)) : ΞΌ t ≀ ΞΌ s := calc ΞΌ t = βˆ‘' g : G, ΞΌ (g β€’ t ∩ s) := hs.measure_eq_tsum t _ = ΞΌ (⋃ g : G, g β€’ t ∩ s) := Eq.symm <| measure_iUnionβ‚€ hd fun _ => (ht.smul _).inter hs.nullMeasurableSet _ ≀ ΞΌ s := measure_mono (iUnion_subset fun _ => inter_subset_right) /-- If the action of a countable group `G` admits an invariant measure `ΞΌ` with a fundamental domain `s`, then every null-measurable set `t` of measure strictly greater than `ΞΌ s` contains two points `x y` such that `g β€’ x = y` for some `g β‰  1`. -/ @[to_additive "If the additive action of a countable group `G` admits an invariant measure `ΞΌ` with a fundamental domain `s`, then every null-measurable set `t` of measure strictly greater than `ΞΌ s` contains two points `x y` such that `g +α΅₯ x = y` for some `g β‰  0`."] theorem exists_ne_one_smul_eq (hs : IsFundamentalDomain G s ΞΌ) (htm : NullMeasurableSet t ΞΌ) (ht : ΞΌ s < ΞΌ t) : βˆƒ x ∈ t, βˆƒ y ∈ t, βˆƒ g, g β‰  (1 : G) ∧ g β€’ x = y := by contrapose! ht refine hs.measure_le_of_pairwise_disjoint htm (Pairwise.aedisjoint fun g₁ gβ‚‚ hne => ?_) dsimp [Function.onFun] refine (Disjoint.inf_left _ ?_).inf_right _ rw [Set.disjoint_left] rintro _ ⟨x, hx, rfl⟩ ⟨y, hy, hxy : gβ‚‚ β€’ y = g₁ β€’ x⟩ refine ht x hx y hy (g₂⁻¹ * g₁) (mt inv_mul_eq_one.1 hne.symm) ?_ rw [mul_smul, ← hxy, inv_smul_smul] /-- If `f` is invariant under the action of a countable group `G`, and `ΞΌ` is a `G`-invariant measure with a fundamental domain `s`, then the `essSup` of `f` restricted to `s` is the same as that of `f` on all of its domain. -/ @[to_additive "If `f` is invariant under the action of a countable additive group `G`, and `ΞΌ` is a `G`-invariant measure with a fundamental domain `s`, then the `essSup` of `f` restricted to `s` is the same as that of `f` on all of its domain."] theorem essSup_measure_restrict (hs : IsFundamentalDomain G s ΞΌ) {f : Ξ± β†’ ℝβ‰₯0∞} (hf : βˆ€ Ξ³ : G, βˆ€ x : Ξ±, f (Ξ³ β€’ x) = f x) : essSup f (ΞΌ.restrict s) = essSup f ΞΌ := by refine le_antisymm (essSup_mono_measure' Measure.restrict_le_self) ?_ rw [essSup_eq_sInf (ΞΌ.restrict s) f, essSup_eq_sInf ΞΌ f] refine sInf_le_sInf ?_ rintro a (ha : (ΞΌ.restrict s) {x : Ξ± | a < f x} = 0) rw [Measure.restrict_applyβ‚€' hs.nullMeasurableSet] at ha refine measure_zero_of_invariant hs _ ?_ ha intro Ξ³ ext x rw [mem_smul_set_iff_inv_smul_mem] simp only [mem_setOf_eq, hf γ⁻¹ x] end IsFundamentalDomain /-! ### Interior/frontier of a fundamental domain -/ section MeasurableSpace variable (G) [Group G] [MulAction G Ξ±] (s : Set Ξ±) {x : Ξ±} /-- The boundary of a fundamental domain, those points of the domain that also lie in a nontrivial translate. -/ @[to_additive MeasureTheory.addFundamentalFrontier "The boundary of a fundamental domain, those points of the domain that also lie in a nontrivial translate."] def fundamentalFrontier : Set Ξ± := s ∩ ⋃ (g : G) (_ : g β‰  1), g β€’ s /-- The interior of a fundamental domain, those points of the domain not lying in any translate. -/ @[to_additive MeasureTheory.addFundamentalInterior "The interior of a fundamental domain, those points of the domain not lying in any translate."] def fundamentalInterior : Set Ξ± := s \ ⋃ (g : G) (_ : g β‰  1), g β€’ s variable {G s} @[to_additive (attr := simp) MeasureTheory.mem_addFundamentalFrontier] theorem mem_fundamentalFrontier : x ∈ fundamentalFrontier G s ↔ x ∈ s ∧ βˆƒ g : G, g β‰  1 ∧ x ∈ g β€’ s := by simp [fundamentalFrontier] @[to_additive (attr := simp) MeasureTheory.mem_addFundamentalInterior] theorem mem_fundamentalInterior : x ∈ fundamentalInterior G s ↔ x ∈ s ∧ βˆ€ g : G, g β‰  1 β†’ x βˆ‰ g β€’ s := by simp [fundamentalInterior] @[to_additive MeasureTheory.addFundamentalFrontier_subset] theorem fundamentalFrontier_subset : fundamentalFrontier G s βŠ† s := inter_subset_left @[to_additive MeasureTheory.addFundamentalInterior_subset] theorem fundamentalInterior_subset : fundamentalInterior G s βŠ† s := diff_subset variable (G s) @[to_additive MeasureTheory.disjoint_addFundamentalInterior_addFundamentalFrontier] theorem disjoint_fundamentalInterior_fundamentalFrontier : Disjoint (fundamentalInterior G s) (fundamentalFrontier G s) := disjoint_sdiff_self_left.mono_right inf_le_right @[to_additive (attr := simp) MeasureTheory.addFundamentalInterior_union_addFundamentalFrontier] theorem fundamentalInterior_union_fundamentalFrontier : fundamentalInterior G s βˆͺ fundamentalFrontier G s = s := diff_union_inter _ _ @[to_additive (attr := simp) MeasureTheory.addFundamentalFrontier_union_addFundamentalInterior] theorem fundamentalFrontier_union_fundamentalInterior : fundamentalFrontier G s βˆͺ fundamentalInterior G s = s := inter_union_diff _ _ @[to_additive (attr := simp) MeasureTheory.sdiff_addFundamentalInterior] theorem sdiff_fundamentalInterior : s \ fundamentalInterior G s = fundamentalFrontier G s := sdiff_sdiff_right_self @[to_additive (attr := simp) MeasureTheory.sdiff_addFundamentalFrontier] theorem sdiff_fundamentalFrontier : s \ fundamentalFrontier G s = fundamentalInterior G s := diff_self_inter @[to_additive (attr := simp) MeasureTheory.addFundamentalFrontier_vadd] theorem fundamentalFrontier_smul [Group H] [MulAction H Ξ±] [SMulCommClass H G Ξ±] (g : H) : fundamentalFrontier G (g β€’ s) = g β€’ fundamentalFrontier G s := by simp_rw [fundamentalFrontier, smul_set_inter, smul_set_iUnion, smul_comm g (_ : G) (_ : Set Ξ±)] @[to_additive (attr := simp) MeasureTheory.addFundamentalInterior_vadd] theorem fundamentalInterior_smul [Group H] [MulAction H Ξ±] [SMulCommClass H G Ξ±] (g : H) : fundamentalInterior G (g β€’ s) = g β€’ fundamentalInterior G s := by simp_rw [fundamentalInterior, smul_set_sdiff, smul_set_iUnion, smul_comm g (_ : G) (_ : Set Ξ±)] @[to_additive MeasureTheory.pairwise_disjoint_addFundamentalInterior] theorem pairwise_disjoint_fundamentalInterior : Pairwise (Disjoint on fun g : G => g β€’ fundamentalInterior G s) := by refine fun a b hab => disjoint_left.2 ?_ rintro _ ⟨x, hx, rfl⟩ ⟨y, hy, hxy⟩ rw [mem_fundamentalInterior] at hx hy refine hx.2 (a⁻¹ * b) ?_ ?_ Β· rwa [Ne, inv_mul_eq_iff_eq_mul, mul_one, eq_comm] Β· simpa [mul_smul, ← hxy, mem_inv_smul_set_iff] using hy.1 variable [Countable G] [MeasurableSpace G] [MeasurableSpace Ξ±] [MeasurableSMul G Ξ±] {ΞΌ : Measure Ξ±} [SMulInvariantMeasure G Ξ± ΞΌ] @[to_additive MeasureTheory.NullMeasurableSet.addFundamentalFrontier] protected theorem NullMeasurableSet.fundamentalFrontier (hs : NullMeasurableSet s ΞΌ) : NullMeasurableSet (fundamentalFrontier G s) ΞΌ := hs.inter <| .iUnion fun _ => .iUnion fun _ => hs.smul _ @[to_additive MeasureTheory.NullMeasurableSet.addFundamentalInterior] protected theorem NullMeasurableSet.fundamentalInterior (hs : NullMeasurableSet s ΞΌ) : NullMeasurableSet (fundamentalInterior G s) ΞΌ := hs.diff <| .iUnion fun _ => .iUnion fun _ => hs.smul _ end MeasurableSpace namespace IsFundamentalDomain variable [Countable G] [Group G] [MulAction G Ξ±] [MeasurableSpace Ξ±] {ΞΌ : Measure Ξ±} {s : Set Ξ±} (hs : IsFundamentalDomain G s ΞΌ) include hs section Group @[to_additive MeasureTheory.IsAddFundamentalDomain.measure_addFundamentalFrontier] theorem measure_fundamentalFrontier : ΞΌ (fundamentalFrontier G s) = 0 := by simpa only [fundamentalFrontier, iUnionβ‚‚_inter, one_smul, measure_iUnion_null_iff, inter_comm s, Function.onFun] using fun g (hg : g β‰  1) => hs.aedisjoint hg @[to_additive MeasureTheory.IsAddFundamentalDomain.measure_addFundamentalInterior] theorem measure_fundamentalInterior : ΞΌ (fundamentalInterior G s) = ΞΌ s := measure_diff_null' hs.measure_fundamentalFrontier end Group variable [MeasurableSpace G] [MeasurableSMul G Ξ±] [SMulInvariantMeasure G Ξ± ΞΌ] protected theorem fundamentalInterior : IsFundamentalDomain G (fundamentalInterior G s) ΞΌ where nullMeasurableSet := hs.nullMeasurableSet.fundamentalInterior _ _ ae_covers := by simp_rw [ae_iff, not_exists, ← mem_inv_smul_set_iff, setOf_forall, ← compl_setOf, setOf_mem_eq, ← compl_iUnion] have : ((⋃ g : G, g⁻¹ β€’ s) \ ⋃ g : G, g⁻¹ β€’ fundamentalFrontier G s) βŠ† ⋃ g : G, g⁻¹ β€’ fundamentalInterior G s := by simp_rw [diff_subset_iff, ← iUnion_union_distrib, ← smul_set_union (Ξ± := G) (Ξ² := Ξ±), fundamentalFrontier_union_fundamentalInterior]; rfl refine eq_bot_mono (ΞΌ.mono <| compl_subset_compl.2 this) ?_ simp only [iUnion_inv_smul, compl_sdiff, ENNReal.bot_eq_zero, himp_eq, sup_eq_union, @iUnion_smul_eq_setOf_exists _ _ _ _ s] exact measure_union_null (measure_iUnion_null fun _ => measure_smul_null hs.measure_fundamentalFrontier _) hs.ae_covers aedisjoint := (pairwise_disjoint_fundamentalInterior _ _).mono fun _ _ => Disjoint.aedisjoint end IsFundamentalDomain section FundamentalDomainMeasure variable (G) [Group G] [MulAction G Ξ±] [MeasurableSpace Ξ±] (ΞΌ : Measure Ξ±) local notation "Ξ±_mod_G" => MulAction.orbitRel G Ξ± local notation "Ο€" => @Quotient.mk _ Ξ±_mod_G variable {G} @[to_additive addMeasure_map_restrict_apply] lemma measure_map_restrict_apply (s : Set Ξ±) {U : Set (Quotient Ξ±_mod_G)} (meas_U : MeasurableSet U) : (ΞΌ.restrict s).map Ο€ U = ΞΌ ((Ο€ ⁻¹' U) ∩ s) := by rw [map_apply (f := Ο€) (fun V hV ↦ measurableSet_quotient.mp hV) meas_U, Measure.restrict_apply (t := (Quotient.mk Ξ±_mod_G ⁻¹' U)) (measurableSet_quotient.mp meas_U)] @[to_additive] lemma IsFundamentalDomain.quotientMeasure_eq [Countable G] [MeasurableSpace G] {s t : Set Ξ±} [SMulInvariantMeasure G Ξ± ΞΌ] [MeasurableSMul G Ξ±] (fund_dom_s : IsFundamentalDomain G s ΞΌ) (fund_dom_t : IsFundamentalDomain G t ΞΌ) : (ΞΌ.restrict s).map Ο€ = (ΞΌ.restrict t).map Ο€ := by ext U meas_U rw [measure_map_restrict_apply (meas_U := meas_U), measure_map_restrict_apply (meas_U := meas_U)] apply MeasureTheory.IsFundamentalDomain.measure_set_eq fund_dom_s fund_dom_t Β· exact measurableSet_quotient.mp meas_U Β· intro g ext x have : Quotient.mk Ξ±_mod_G (g β€’ x) = Quotient.mk Ξ±_mod_G x := by apply Quotient.sound use g simp only [mem_preimage, this] end FundamentalDomainMeasure /-! ## `HasFundamentalDomain` typeclass We define `HasFundamentalDomain` in order to be able to define the `covolume` of a quotient of `Ξ±` by a group `G`, which under reasonable conditions does not depend on the choice of fundamental domain. Even though any "sensible" action should have a fundamental domain, this is a rather delicate question which was recently addressed by Misha Kapovich: https://arxiv.org/abs/2301.05325 TODO: Formalize the existence of a Dirichlet domain as in Kapovich's paper. -/ section HasFundamentalDomain /-- We say a quotient of `Ξ±` by `G` `HasAddFundamentalDomain` if there is a measurable set `s` for which `IsAddFundamentalDomain G s` holds. -/ class HasAddFundamentalDomain (G Ξ± : Type*) [Zero G] [VAdd G Ξ±] [MeasurableSpace Ξ±] (Ξ½ : Measure Ξ± := by volume_tac) : Prop where ExistsIsAddFundamentalDomain : βˆƒ s : Set Ξ±, IsAddFundamentalDomain G s Ξ½ /-- We say a quotient of `Ξ±` by `G` `HasFundamentalDomain` if there is a measurable set `s` for which `IsFundamentalDomain G s` holds. -/ class HasFundamentalDomain (G : Type*) (Ξ± : Type*) [One G] [SMul G Ξ±] [MeasurableSpace Ξ±] (Ξ½ : Measure Ξ± := by volume_tac) : Prop where ExistsIsFundamentalDomain : βˆƒ (s : Set Ξ±), IsFundamentalDomain G s Ξ½ attribute [to_additive existing] MeasureTheory.HasFundamentalDomain open Classical in /-- The `covolume` of an action of `G` on `Ξ±` the volume of some fundamental domain, or `0` if none exists. -/ @[to_additive addCovolume "The `addCovolume` of an action of `G` on `Ξ±` is the volume of some fundamental domain, or `0` if none exists."] noncomputable def covolume (G Ξ± : Type*) [One G] [SMul G Ξ±] [MeasurableSpace Ξ±] (Ξ½ : Measure Ξ± := by volume_tac) : ℝβ‰₯0∞ := if funDom : HasFundamentalDomain G Ξ± Ξ½ then Ξ½ funDom.ExistsIsFundamentalDomain.choose else 0 variable [Group G] [MulAction G Ξ±] [MeasurableSpace Ξ±] /-- If there is a fundamental domain `s`, then `HasFundamentalDomain` holds. -/ @[to_additive] lemma IsFundamentalDomain.hasFundamentalDomain (Ξ½ : Measure Ξ±) {s : Set Ξ±} (fund_dom_s : IsFundamentalDomain G s Ξ½) : HasFundamentalDomain G Ξ± Ξ½ := ⟨⟨s, fund_dom_s⟩⟩ /-- The `covolume` can be computed by taking the `volume` of any given fundamental domain `s`. -/ @[to_additive] lemma IsFundamentalDomain.covolume_eq_volume (Ξ½ : Measure Ξ±) [Countable G] [MeasurableSpace G] [MeasurableSMul G Ξ±] [SMulInvariantMeasure G Ξ± Ξ½] {s : Set Ξ±} (fund_dom_s : IsFundamentalDomain G s Ξ½) : covolume G Ξ± Ξ½ = Ξ½ s := by dsimp [covolume] simp only [(fund_dom_s.hasFundamentalDomain Ξ½), ↓reduceDIte] rw [fund_dom_s.measure_eq] exact (fund_dom_s.hasFundamentalDomain Ξ½).ExistsIsFundamentalDomain.choose_spec end HasFundamentalDomain /-! ## `QuotientMeasureEqMeasurePreimage` typeclass This typeclass describes a situation in which a measure `ΞΌ` on `Ξ± β§Έ G` can be computed by taking a measure `Ξ½` on `Ξ±` of the intersection of the pullback with a fundamental domain. It's curious that in measure theory, measures can be pushed forward, while in geometry, volumes can be pulled back. And yet here, we are describing a situation involving measures in a geometric way. Another viewpoint is that if a set is small enough to fit in a single fundamental domain, then its `Ξ½` measure in `Ξ±` is the same as the `ΞΌ` measure of its pushforward in `Ξ± β§Έ G`. -/ section QuotientMeasureEqMeasurePreimage section additive variable [AddGroup G] [AddAction G Ξ±] [MeasurableSpace Ξ±] local notation "Ξ±_mod_G" => AddAction.orbitRel G Ξ± local notation "Ο€" => @Quotient.mk _ Ξ±_mod_G /-- A measure `ΞΌ` on the `AddQuotient` of `Ξ±` mod `G` satisfies `AddQuotientMeasureEqMeasurePreimage` if: for any fundamental domain `t`, and any measurable subset `U` of the quotient, `ΞΌ U = volume ((Ο€ ⁻¹' U) ∩ t)`. -/ class AddQuotientMeasureEqMeasurePreimage (Ξ½ : Measure Ξ± := by volume_tac) (ΞΌ : Measure (Quotient Ξ±_mod_G)) : Prop where addProjection_respects_measure' : βˆ€ (t : Set Ξ±) (_ : IsAddFundamentalDomain G t Ξ½), ΞΌ = (Ξ½.restrict t).map Ο€ end additive variable [Group G] [MulAction G Ξ±] [MeasurableSpace Ξ±] local notation "Ξ±_mod_G" => MulAction.orbitRel G Ξ± local notation "Ο€" => @Quotient.mk _ Ξ±_mod_G /-- Measures `Ξ½` on `Ξ±` and `ΞΌ` on the `Quotient` of `Ξ±` mod `G` satisfy `QuotientMeasureEqMeasurePreimage` if: for any fundamental domain `t`, and any measurable subset `U` of the quotient, `ΞΌ U = Ξ½ ((Ο€ ⁻¹' U) ∩ t)`. -/ class QuotientMeasureEqMeasurePreimage (Ξ½ : Measure Ξ± := by volume_tac) (ΞΌ : Measure (Quotient Ξ±_mod_G)) : Prop where projection_respects_measure' (t : Set Ξ±) : IsFundamentalDomain G t Ξ½ β†’ ΞΌ = (Ξ½.restrict t).map Ο€ attribute [to_additive] MeasureTheory.QuotientMeasureEqMeasurePreimage @[to_additive addProjection_respects_measure] lemma IsFundamentalDomain.projection_respects_measure {Ξ½ : Measure Ξ±} (ΞΌ : Measure (Quotient Ξ±_mod_G)) [i : QuotientMeasureEqMeasurePreimage Ξ½ ΞΌ] {t : Set Ξ±} (fund_dom_t : IsFundamentalDomain G t Ξ½) : ΞΌ = (Ξ½.restrict t).map Ο€ := i.projection_respects_measure' t fund_dom_t @[to_additive addProjection_respects_measure_apply] lemma IsFundamentalDomain.projection_respects_measure_apply {Ξ½ : Measure Ξ±} (ΞΌ : Measure (Quotient Ξ±_mod_G)) [i : QuotientMeasureEqMeasurePreimage Ξ½ ΞΌ] {t : Set Ξ±} (fund_dom_t : IsFundamentalDomain G t Ξ½) {U : Set (Quotient Ξ±_mod_G)} (meas_U : MeasurableSet U) : ΞΌ U = Ξ½ (Ο€ ⁻¹' U ∩ t) := by rw [fund_dom_t.projection_respects_measure (ΞΌ := ΞΌ), measure_map_restrict_apply Ξ½ t meas_U] variable {Ξ½ : Measure Ξ±} /-- Any two measures satisfying `QuotientMeasureEqMeasurePreimage` are equal. -/ @[to_additive] lemma QuotientMeasureEqMeasurePreimage.unique [hasFun : HasFundamentalDomain G Ξ± Ξ½] (ΞΌ ΞΌ' : Measure (Quotient Ξ±_mod_G)) [QuotientMeasureEqMeasurePreimage Ξ½ ΞΌ] [QuotientMeasureEqMeasurePreimage Ξ½ ΞΌ'] : ΞΌ = ΞΌ' := by obtain βŸ¨π“•, hπ“•βŸ© := hasFun.ExistsIsFundamentalDomain rw [h𝓕.projection_respects_measure (ΞΌ := ΞΌ), h𝓕.projection_respects_measure (ΞΌ := ΞΌ')] /-- The quotient map to `Ξ± β§Έ G` is measure-preserving between the restriction of `volume` to a fundamental domain in `Ξ±` and a related measure satisfying `QuotientMeasureEqMeasurePreimage`. -/ @[to_additive IsAddFundamentalDomain.measurePreserving_add_quotient_mk] theorem IsFundamentalDomain.measurePreserving_quotient_mk {𝓕 : Set Ξ±} (h𝓕 : IsFundamentalDomain G 𝓕 Ξ½) (ΞΌ : Measure (Quotient Ξ±_mod_G)) [QuotientMeasureEqMeasurePreimage Ξ½ ΞΌ] : MeasurePreserving Ο€ (Ξ½.restrict 𝓕) ΞΌ where measurable := measurable_quotient_mk' (s := Ξ±_mod_G) map_eq := by haveI : HasFundamentalDomain G Ξ± Ξ½ := βŸ¨π“•, hπ“•βŸ© rw [h𝓕.projection_respects_measure (ΞΌ := ΞΌ)] variable [SMulInvariantMeasure G Ξ± Ξ½] [Countable G] [MeasurableSpace G] [MeasurableSMul G Ξ±] /-- Given a measure upstairs (i.e., on `Ξ±`), and a choice `s` of fundamental domain, there's always an artificial way to generate a measure downstairs such that the pair satisfies the `QuotientMeasureEqMeasurePreimage` typeclass. -/ @[to_additive] lemma IsFundamentalDomain.quotientMeasureEqMeasurePreimage_quotientMeasure {s : Set Ξ±} (fund_dom_s : IsFundamentalDomain G s Ξ½) : QuotientMeasureEqMeasurePreimage Ξ½ ((Ξ½.restrict s).map Ο€) where projection_respects_measure' t fund_dom_t := by rw [fund_dom_s.quotientMeasure_eq _ fund_dom_t] /-- One can prove `QuotientMeasureEqMeasurePreimage` by checking behavior with respect to a single fundamental domain. -/ @[to_additive] lemma IsFundamentalDomain.quotientMeasureEqMeasurePreimage {ΞΌ : Measure (Quotient Ξ±_mod_G)} {s : Set Ξ±} (fund_dom_s : IsFundamentalDomain G s Ξ½) (h : ΞΌ = (Ξ½.restrict s).map Ο€) : QuotientMeasureEqMeasurePreimage Ξ½ ΞΌ := by simpa [h] using fund_dom_s.quotientMeasureEqMeasurePreimage_quotientMeasure /-- If a fundamental domain has volume 0, then `QuotientMeasureEqMeasurePreimage` holds. -/ @[to_additive] theorem IsFundamentalDomain.quotientMeasureEqMeasurePreimage_of_zero {s : Set Ξ±} (fund_dom_s : IsFundamentalDomain G s Ξ½) (vol_s : Ξ½ s = 0) : QuotientMeasureEqMeasurePreimage Ξ½ (0 : Measure (Quotient Ξ±_mod_G)) := by apply fund_dom_s.quotientMeasureEqMeasurePreimage ext U meas_U simp only [Measure.coe_zero, Pi.zero_apply] convert (measure_inter_null_of_null_right (h := vol_s) (Quotient.mk Ξ±_mod_G ⁻¹' U)).symm rw [measure_map_restrict_apply (meas_U := meas_U)] /-- If a measure `ΞΌ` on a quotient satisfies `QuotientMeasureEqMeasurePreimage` with respect to a sigma-finite measure `Ξ½`, then it is itself `SigmaFinite`. -/ @[to_additive] lemma QuotientMeasureEqMeasurePreimage.sigmaFiniteQuotient [i : SigmaFinite Ξ½] [i' : HasFundamentalDomain G Ξ± Ξ½] (ΞΌ : Measure (Quotient Ξ±_mod_G)) [QuotientMeasureEqMeasurePreimage Ξ½ ΞΌ] : SigmaFinite ΞΌ := by rw [sigmaFinite_iff] obtain ⟨A, hA_meas, hA, hA'⟩ := Measure.toFiniteSpanningSetsIn (h := i) simp only [mem_setOf_eq] at hA_meas refine ⟨⟨fun n ↦ Ο€ '' (A n), by simp, fun n ↦ ?_, ?_⟩⟩ Β· obtain ⟨s, fund_dom_s⟩ := i' have : Ο€ ⁻¹' (Ο€ '' (A n)) = _ := MulAction.quotient_preimage_image_eq_union_mul (A n) (G := G) have measΟ€An : MeasurableSet (Ο€ '' A n) := by let _ : Setoid Ξ± := Ξ±_mod_G rw [measurableSet_quotient, Quotient.mk''_eq_mk, this] apply MeasurableSet.iUnion exact fun g ↦ MeasurableSet.const_smul (hA_meas n) g rw [fund_dom_s.projection_respects_measure_apply (ΞΌ := ΞΌ) measΟ€An, this, iUnion_inter] refine lt_of_le_of_lt ?_ (hA n) rw [fund_dom_s.measure_eq_tsum (A n)] exact measure_iUnion_le _ Β· rw [← image_iUnion, hA'] refine image_univ_of_surjective (by convert Quotient.mk'_surjective) /-- A measure `ΞΌ` on `Ξ± β§Έ G` satisfying `QuotientMeasureEqMeasurePreimage` and having finite covolume is a finite measure. -/ @[to_additive] theorem QuotientMeasureEqMeasurePreimage.isFiniteMeasure_quotient (ΞΌ : Measure (Quotient Ξ±_mod_G)) [QuotientMeasureEqMeasurePreimage Ξ½ ΞΌ] [hasFun : HasFundamentalDomain G Ξ± Ξ½] (h : covolume G Ξ± Ξ½ β‰  ∞) : IsFiniteMeasure ΞΌ := by obtain βŸ¨π“•, hπ“•βŸ© := hasFun.ExistsIsFundamentalDomain rw [h𝓕.projection_respects_measure (ΞΌ := ΞΌ)] have : Fact (Ξ½ 𝓕 < ∞) := by apply Fact.mk convert Ne.lt_top h exact (h𝓕.covolume_eq_volume Ξ½).symm infer_instance /-- A finite measure `ΞΌ` on `Ξ± β§Έ G` satisfying `QuotientMeasureEqMeasurePreimage` has finite covolume. -/ @[to_additive] theorem QuotientMeasureEqMeasurePreimage.covolume_ne_top (ΞΌ : Measure (Quotient Ξ±_mod_G)) [QuotientMeasureEqMeasurePreimage Ξ½ ΞΌ] [IsFiniteMeasure ΞΌ] : covolume G Ξ± Ξ½ < ∞ := by by_cases hasFun : HasFundamentalDomain G Ξ± Ξ½ Β· obtain βŸ¨π“•, hπ“•βŸ© := hasFun.ExistsIsFundamentalDomain have H : ΞΌ univ < ∞ := IsFiniteMeasure.measure_univ_lt_top rw [h𝓕.projection_respects_measure_apply (ΞΌ := ΞΌ) MeasurableSet.univ] at H simpa [h𝓕.covolume_eq_volume Ξ½] using H Β· simp [covolume, hasFun] end QuotientMeasureEqMeasurePreimage section QuotientMeasureEqMeasurePreimage variable [Group G] [MulAction G Ξ±] [MeasureSpace Ξ±] [Countable G] [MeasurableSpace G] [SMulInvariantMeasure G Ξ± volume] [MeasurableSMul G Ξ±] local notation "Ξ±_mod_G" => MulAction.orbitRel G Ξ± local notation "Ο€" => @Quotient.mk _ Ξ±_mod_G /-- If a measure `ΞΌ` on a quotient satisfies `QuotientVolumeEqVolumePreimage` with respect to a sigma-finite measure, then it is itself `SigmaFinite`. -/ @[to_additive MeasureTheory.instSigmaFiniteAddQuotientOrbitRelInstMeasurableSpaceToMeasurableSpace] instance [SigmaFinite (volume : Measure Ξ±)] [HasFundamentalDomain G Ξ±]
(ΞΌ : Measure (Quotient Ξ±_mod_G)) [QuotientMeasureEqMeasurePreimage volume ΞΌ] : SigmaFinite ΞΌ := QuotientMeasureEqMeasurePreimage.sigmaFiniteQuotient (Ξ½ := (volume : Measure Ξ±)) (ΞΌ := ΞΌ) end QuotientMeasureEqMeasurePreimage
Mathlib/MeasureTheory/Group/FundamentalDomain.lean
895
900
/- Copyright (c) 2024 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.SetTheory.Cardinal.Arithmetic import Mathlib.SetTheory.Ordinal.Principal /-! # Ordinal arithmetic with cardinals This file collects results about the cardinality of different ordinal operations. -/ universe u v open Cardinal Ordinal Set /-! ### Cardinal operations with ordinal indices -/ namespace Cardinal /-- Bounds the cardinal of an ordinal-indexed union of sets. -/ lemma mk_iUnion_Ordinal_lift_le_of_le {Ξ² : Type v} {o : Ordinal.{u}} {c : Cardinal.{v}} (ho : lift.{v} o.card ≀ lift.{u} c) (hc : β„΅β‚€ ≀ c) (A : Ordinal β†’ Set Ξ²) (hA : βˆ€ j < o, #(A j) ≀ c) : #(⋃ j < o, A j) ≀ c := by simp_rw [← mem_Iio, biUnion_eq_iUnion, iUnion, iSup, ← o.enumIsoToType.symm.surjective.range_comp] rw [← lift_le.{u}] apply ((mk_iUnion_le_lift _).trans _).trans_eq (mul_eq_self (aleph0_le_lift.2 hc)) rw [mk_toType] refine mul_le_mul' ho (ciSup_le' ?_) intro i simpa using hA _ (o.enumIsoToType.symm i).2 lemma mk_iUnion_Ordinal_le_of_le {Ξ² : Type*} {o : Ordinal} {c : Cardinal} (ho : o.card ≀ c) (hc : β„΅β‚€ ≀ c) (A : Ordinal β†’ Set Ξ²) (hA : βˆ€ j < o, #(A j) ≀ c) : #(⋃ j < o, A j) ≀ c := by apply mk_iUnion_Ordinal_lift_le_of_le _ hc A hA rwa [Cardinal.lift_le] end Cardinal @[deprecated mk_iUnion_Ordinal_le_of_le (since := "2024-11-02")] alias Ordinal.Cardinal.mk_iUnion_Ordinal_le_of_le := mk_iUnion_Ordinal_le_of_le /-! ### Cardinality of ordinals -/ namespace Ordinal theorem lift_card_iSup_le_sum_card {ΞΉ : Type u} [Small.{v} ΞΉ] (f : ΞΉ β†’ Ordinal.{v}) : Cardinal.lift.{u} (⨆ i, f i).card ≀ Cardinal.sum fun i ↦ (f i).card := by simp_rw [← mk_toType] rw [← mk_sigma, ← Cardinal.lift_id'.{v} #(Ξ£ _, _), ← Cardinal.lift_umax.{v, u}] apply lift_mk_le_lift_mk_of_surjective (f := enumIsoToType _ ∘ (⟨(enumIsoToType _).symm Β·.2, (mem_Iio.mp ((enumIsoToType _).symm _).2).trans_le (Ordinal.le_iSup _ _)⟩)) rw [EquivLike.comp_surjective] rintro ⟨x, hx⟩ obtain ⟨i, hi⟩ := Ordinal.lt_iSup_iff.mp hx exact ⟨⟨i, enumIsoToType _ ⟨x, hi⟩⟩, by simp⟩ theorem card_iSup_le_sum_card {ΞΉ : Type u} (f : ΞΉ β†’ Ordinal.{max u v}) : (⨆ i, f i).card ≀ Cardinal.sum (fun i ↦ (f i).card) := by have := lift_card_iSup_le_sum_card f rwa [Cardinal.lift_id'] at this theorem card_iSup_Iio_le_sum_card {o : Ordinal.{u}} (f : Iio o β†’ Ordinal.{max u v}) : (⨆ a : Iio o, f a).card ≀ Cardinal.sum fun i ↦ (f ((enumIsoToType o).symm i)).card := by apply le_of_eq_of_le (congr_arg _ _).symm (card_iSup_le_sum_card _) simpa using (enumIsoToType o).symm.iSup_comp (g := fun x ↦ f x) theorem card_iSup_Iio_le_card_mul_iSup {o : Ordinal.{u}} (f : Iio o β†’ Ordinal.{max u v}) : (⨆ a : Iio o, f a).card ≀ Cardinal.lift.{v} o.card * ⨆ a : Iio o, (f a).card := by apply (card_iSup_Iio_le_sum_card f).trans convert ← sum_le_iSup_lift _ Β· exact mk_toType o Β· exact (enumIsoToType o).symm.iSup_comp (g := fun x ↦ (f x).card) theorem card_opow_le_of_omega0_le_left {a : Ordinal} (ha : Ο‰ ≀ a) (b : Ordinal) : (a ^ b).card ≀ max a.card b.card := by refine limitRecOn b ?_ ?_ ?_ Β· simpa using one_lt_omega0.le.trans ha Β· intro b IH rw [opow_succ, card_mul, card_succ, Cardinal.mul_eq_max_of_aleph0_le_right, max_comm] Β· apply (max_le_max_left _ IH).trans rw [← max_assoc, max_self] exact max_le_max_left _ le_self_add Β· rw [ne_eq, card_eq_zero, opow_eq_zero] rintro ⟨rfl, -⟩ cases omega0_pos.not_le ha Β· rwa [aleph0_le_card] Β· intro b hb IH rw [(isNormal_opow (one_lt_omega0.trans_le ha)).apply_of_isLimit hb] apply (card_iSup_Iio_le_card_mul_iSup _).trans rw [Cardinal.lift_id, Cardinal.mul_eq_max_of_aleph0_le_right, max_comm] Β· apply max_le _ (le_max_right _ _) apply ciSup_le' intro c exact (IH c.1 c.2).trans (max_le_max_left _ (card_le_card c.2.le)) Β· simpa using hb.pos.ne' Β· refine le_ciSup_of_le ?_ ⟨1, one_lt_omega0.trans_le <| omega0_le_of_isLimit hb⟩ ?_ Β· exact Cardinal.bddAbove_of_small _ Β· simpa theorem card_opow_le_of_omega0_le_right (a : Ordinal) {b : Ordinal} (hb : Ο‰ ≀ b) : (a ^ b).card ≀ max a.card b.card := by obtain ⟨n, rfl⟩ | ha := eq_nat_or_omega0_le a Β· apply (card_le_card <| opow_le_opow_left b (nat_lt_omega0 n).le).trans apply (card_opow_le_of_omega0_le_left le_rfl _).trans simp [hb] Β· exact card_opow_le_of_omega0_le_left ha b theorem card_opow_le (a b : Ordinal) : (a ^ b).card ≀ max β„΅β‚€ (max a.card b.card) := by obtain ⟨n, rfl⟩ | ha := eq_nat_or_omega0_le a Β· obtain ⟨m, rfl⟩ | hb := eq_nat_or_omega0_le b Β· rw [← natCast_opow, card_nat] exact le_max_of_le_left (nat_lt_aleph0 _).le Β· exact (card_opow_le_of_omega0_le_right _ hb).trans (le_max_right _ _) Β· exact (card_opow_le_of_omega0_le_left ha _).trans (le_max_right _ _) theorem card_opow_eq_of_omega0_le_left {a b : Ordinal} (ha : Ο‰ ≀ a) (hb : 0 < b) : (a ^ b).card = max a.card b.card := by apply (card_opow_le_of_omega0_le_left ha b).antisymm (max_le _ _) <;> apply card_le_card Β· exact left_le_opow a hb Β· exact right_le_opow b (one_lt_omega0.trans_le ha) theorem card_opow_eq_of_omega0_le_right {a b : Ordinal} (ha : 1 < a) (hb : Ο‰ ≀ b) : (a ^ b).card = max a.card b.card := by apply (card_opow_le_of_omega0_le_right a hb).antisymm (max_le _ _) <;> apply card_le_card Β· exact left_le_opow a (omega0_pos.trans_le hb) Β· exact right_le_opow b ha theorem card_omega0_opow {a : Ordinal} (h : a β‰  0) : card (Ο‰ ^ a) = max β„΅β‚€ a.card := by rw [card_opow_eq_of_omega0_le_left le_rfl h.bot_lt, card_omega0] theorem card_opow_omega0 {a : Ordinal} (h : 1 < a) : card (a ^ Ο‰) = max β„΅β‚€ a.card := by rw [card_opow_eq_of_omega0_le_right h le_rfl, card_omega0, max_comm] theorem principal_opow_omega (o : Ordinal) : Principal (Β· ^ Β·) (Ο‰_ o) := by obtain rfl | ho := Ordinal.eq_zero_or_pos o Β· rw [omega_zero] exact principal_opow_omega0 Β· intro a b ha hb rw [lt_omega_iff_card_lt] at ha hb ⊒ apply (card_opow_le a b).trans_lt (max_lt _ (max_lt ha hb)) rwa [← aleph_zero, aleph_lt_aleph] theorem IsInitial.principal_opow {o : Ordinal} (h : IsInitial o) (ho : Ο‰ ≀ o) : Principal (Β· ^ Β·) o := by obtain ⟨a, rfl⟩ := mem_range_omega_iff.2 ⟨ho, h⟩ exact principal_opow_omega a theorem principal_opow_ord {c : Cardinal} (hc : β„΅β‚€ ≀ c) : Principal (Β· ^ Β·) c.ord := by apply (isInitial_ord c).principal_opow rwa [omega0_le_ord] /-! ### Initial ordinals are principal -/ theorem principal_add_ord {c : Cardinal} (hc : β„΅β‚€ ≀ c) : Principal (Β· + Β·) c.ord := by intro a b ha hb rw [lt_ord, card_add] at * exact add_lt_of_lt hc ha hb theorem IsInitial.principal_add {o : Ordinal} (h : IsInitial o) (ho : Ο‰ ≀ o) : Principal (Β· + Β·) o := by rw [← h.ord_card] apply principal_add_ord rwa [aleph0_le_card] theorem principal_add_omega (o : Ordinal) : Principal (Β· + Β·) (Ο‰_ o) := (isInitial_omega o).principal_add (omega0_le_omega o) theorem principal_mul_ord {c : Cardinal} (hc : β„΅β‚€ ≀ c) : Principal (Β· * Β·) c.ord := by intro a b ha hb rw [lt_ord, card_mul] at * exact mul_lt_of_lt hc ha hb theorem IsInitial.principal_mul {o : Ordinal} (h : IsInitial o) (ho : Ο‰ ≀ o) : Principal (Β· * Β·) o := by rw [← h.ord_card] apply principal_mul_ord rwa [aleph0_le_card] theorem principal_mul_omega (o : Ordinal) : Principal (Β· * Β·) (Ο‰_ o) := (isInitial_omega o).principal_mul (omega0_le_omega o) @[deprecated principal_add_omega (since := "2024-11-08")] theorem _root_.Cardinal.principal_add_aleph (o : Ordinal) : Principal (Β· + Β·) (β„΅_ o).ord := principal_add_ord <| aleph0_le_aleph o end Ordinal
Mathlib/SetTheory/Cardinal/Ordinal.lean
785
786
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.RingTheory.WittVector.Frobenius import Mathlib.RingTheory.WittVector.Verschiebung import Mathlib.RingTheory.WittVector.MulP /-! ## Identities between operations on the ring of Witt vectors In this file we derive common identities between the Frobenius and Verschiebung operators. ## Main declarations * `frobenius_verschiebung`: the composition of Frobenius and Verschiebung is multiplication by `p` * `verschiebung_mul_frobenius`: the β€œprojection formula”: `V(x * F y) = V x * y` * `iterate_verschiebung_mul_coeff`: an identity from [Haze09] 6.2 ## References * [Hazewinkel, *Witt Vectors*][Haze09] * [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21] -/ namespace WittVector variable {p : β„•} {R : Type*} [hp : Fact p.Prime] [CommRing R] -- type as `\bbW` local notation "π•Ž" => WittVector p noncomputable section -- Porting note: `ghost_calc` failure: `simp only []` and the manual instances had to be added. /-- The composition of Frobenius and Verschiebung is multiplication by `p`. -/ theorem frobenius_verschiebung (x : π•Ž R) : frobenius (verschiebung x) = x * p := by have : IsPoly p fun {R} [CommRing R] x ↦ frobenius (verschiebung x) :=
IsPoly.comp (hg := frobenius_isPoly p) (hf := verschiebung_isPoly) have : IsPoly p fun {R} [CommRing R] x ↦ x * p := mulN_isPoly p p ghost_calc x ghost_simp [mul_comm] /-- Verschiebung is the same as multiplication by `p` on the ring of Witt vectors of `ZMod p`. -/
Mathlib/RingTheory/WittVector/Identities.lean
42
47
/- Copyright (c) 2020 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.RingTheory.Polynomial.Cyclotomic.Basic import Mathlib.RingTheory.RootsOfUnity.Minpoly /-! # Roots of cyclotomic polynomials. We gather results about roots of cyclotomic polynomials. In particular we show in `Polynomial.cyclotomic_eq_minpoly` that `cyclotomic n R` is the minimal polynomial of a primitive root of unity. ## Main results * `IsPrimitiveRoot.isRoot_cyclotomic` : Any `n`-th primitive root of unity is a root of `cyclotomic n R`. * `isRoot_cyclotomic_iff` : if `NeZero (n : R)`, then `ΞΌ` is a root of `cyclotomic n R` if and only if `ΞΌ` is a primitive root of unity. * `Polynomial.cyclotomic_eq_minpoly` : `cyclotomic n β„€` is the minimal polynomial of a primitive `n`-th root of unity `ΞΌ`. * `Polynomial.cyclotomic.irreducible` : `cyclotomic n β„€` is irreducible. ## Implementation details To prove `Polynomial.cyclotomic.irreducible`, the irreducibility of `cyclotomic n β„€`, we show in `Polynomial.cyclotomic_eq_minpoly` that `cyclotomic n β„€` is the minimal polynomial of any `n`-th primitive root of unity `ΞΌ : K`, where `K` is a field of characteristic `0`. -/ namespace Polynomial variable {R : Type*} [CommRing R] {n : β„•} theorem isRoot_of_unity_of_root_cyclotomic {ΞΆ : R} {i : β„•} (hi : i ∈ n.divisors) (h : (cyclotomic i R).IsRoot ΞΆ) : ΞΆ ^ n = 1 := by rcases n.eq_zero_or_pos with (rfl | hn) Β· exact pow_zero _ have := congr_arg (eval ΞΆ) (prod_cyclotomic_eq_X_pow_sub_one hn R).symm rw [eval_sub, eval_pow, eval_X, eval_one] at this convert eq_add_of_sub_eq' this convert (add_zero (M := R) _).symm apply eval_eq_zero_of_dvd_of_eval_eq_zero _ h exact Finset.dvd_prod_of_mem _ hi section IsDomain variable [IsDomain R] theorem _root_.isRoot_of_unity_iff (h : 0 < n) (R : Type*) [CommRing R] [IsDomain R] {ΞΆ : R} : ΞΆ ^ n = 1 ↔ βˆƒ i ∈ n.divisors, (cyclotomic i R).IsRoot ΞΆ := by rw [← mem_nthRoots h, nthRoots, mem_roots <| X_pow_sub_C_ne_zero h _, C_1, ← prod_cyclotomic_eq_X_pow_sub_one h, isRoot_prod] /-- Any `n`-th primitive root of unity is a root of `cyclotomic n R`. -/ theorem _root_.IsPrimitiveRoot.isRoot_cyclotomic (hpos : 0 < n) {ΞΌ : R} (h : IsPrimitiveRoot ΞΌ n) : IsRoot (cyclotomic n R) ΞΌ := by rw [← mem_roots (cyclotomic_ne_zero n R), cyclotomic_eq_prod_X_sub_primitiveRoots h, roots_prod_X_sub_C, ← Finset.mem_def] rwa [← mem_primitiveRoots hpos] at h private theorem isRoot_cyclotomic_iff' {n : β„•} {K : Type*} [Field K] {ΞΌ : K} [NeZero (n : K)] : IsRoot (cyclotomic n K) ΞΌ ↔ IsPrimitiveRoot ΞΌ n := by -- in this proof, `o` stands for `orderOf ΞΌ` have hnpos : 0 < n := (NeZero.of_neZero_natCast K).out.bot_lt refine ⟨fun hΞΌ => ?_, IsPrimitiveRoot.isRoot_cyclotomic hnpos⟩ have hΞΌn : ΞΌ ^ n = 1 := by rw [isRoot_of_unity_iff hnpos _] exact ⟨n, n.mem_divisors_self hnpos.ne', hμ⟩ by_contra hnΞΌ have ho : 0 < orderOf ΞΌ := (isOfFinOrder_iff_pow_eq_one.2 <| ⟨n, hnpos, hΞΌn⟩).orderOf_pos have := pow_orderOf_eq_one ΞΌ rw [isRoot_of_unity_iff ho] at this obtain ⟨i, hio, hiμ⟩ := this replace hio := Nat.dvd_of_mem_divisors hio rw [IsPrimitiveRoot.not_iff] at hnΞΌ rw [← orderOf_dvd_iff_pow_eq_one] at hΞΌn have key : i < n := (Nat.le_of_dvd ho hio).trans_lt ((Nat.le_of_dvd hnpos hΞΌn).lt_of_ne hnΞΌ) have key' : i ∣ n := hio.trans hΞΌn rw [← Polynomial.dvd_iff_isRoot] at hΞΌ hiΞΌ have hni : {i, n} βŠ† n.divisors := by simpa [Finset.insert_subset_iff, key'] using hnpos.ne' obtain ⟨k, hk⟩ := hiΞΌ obtain ⟨j, hj⟩ := hΞΌ have := prod_cyclotomic_eq_X_pow_sub_one hnpos K rw [← Finset.prod_sdiff hni, Finset.prod_pair key.ne, hk, hj] at this have hn := (X_pow_sub_one_separable_iff.mpr <| NeZero.natCast_ne n K).squarefree rw [← this, Squarefree] at hn specialize hn (X - C ΞΌ) ⟨(∏ x ∈ n.divisors \ {i, n}, cyclotomic x K) * k * j, by ring⟩ simp [Polynomial.isUnit_iff_degree_eq_zero] at hn theorem isRoot_cyclotomic_iff [NeZero (n : R)] {ΞΌ : R} : IsRoot (cyclotomic n R) ΞΌ ↔ IsPrimitiveRoot ΞΌ n := by have hf : Function.Injective _ := IsFractionRing.injective R (FractionRing R) haveI : NeZero (n : FractionRing R) := NeZero.nat_of_injective hf rw [← isRoot_map_iff hf, ← IsPrimitiveRoot.map_iff_of_injective hf, map_cyclotomic, ← isRoot_cyclotomic_iff'] theorem roots_cyclotomic_nodup [NeZero (n : R)] : (cyclotomic n R).roots.Nodup := by obtain h | ⟨΢, h΢⟩ := (cyclotomic n R).roots.empty_or_exists_mem Β· exact h.symm β–Έ Multiset.nodup_zero rw [mem_roots <| cyclotomic_ne_zero n R, isRoot_cyclotomic_iff] at hΞΆ refine Multiset.nodup_of_le (roots.le_of_dvd (X_pow_sub_C_ne_zero (NeZero.pos_of_neZero_natCast R) 1) <| cyclotomic.dvd_X_pow_sub_one n R) hΞΆ.nthRoots_one_nodup theorem cyclotomic.roots_to_finset_eq_primitiveRoots [NeZero (n : R)] : (⟨(cyclotomic n R).roots, roots_cyclotomic_nodup⟩ : Finset _) = primitiveRoots n R := by ext a -- Porting note: was -- `simp [cyclotomic_ne_zero n R, isRoot_cyclotomic_iff, mem_primitiveRoots,` -- ` NeZero.pos_of_neZero_natCast R]` simp only [mem_primitiveRoots, NeZero.pos_of_neZero_natCast R] convert isRoot_cyclotomic_iff (n := n) (ΞΌ := a) using 0 simp [cyclotomic_ne_zero n R] theorem cyclotomic.roots_eq_primitiveRoots_val [NeZero (n : R)] : (cyclotomic n R).roots = (primitiveRoots n R).val := by rw [← cyclotomic.roots_to_finset_eq_primitiveRoots] /-- If `R` is of characteristic zero, then `ΞΆ` is a root of `cyclotomic n R` if and only if it is a primitive `n`-th root of unity. -/ theorem isRoot_cyclotomic_iff_charZero {n : β„•} {R : Type*} [CommRing R] [IsDomain R] [CharZero R] {ΞΌ : R} (hn : 0 < n) : (Polynomial.cyclotomic n R).IsRoot ΞΌ ↔ IsPrimitiveRoot ΞΌ n :=
letI := NeZero.of_gt hn isRoot_cyclotomic_iff
Mathlib/RingTheory/Polynomial/Cyclotomic/Roots.lean
127
129
/- Copyright (c) 2020 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Computability.Halting import Mathlib.Computability.TuringMachine import Mathlib.Data.Num.Lemmas import Mathlib.Tactic.DeriveFintype import Mathlib.Computability.TMConfig /-! # Modelling partial recursive functions using Turing machines The files `TMConfig` and `TMToPartrec` define a simplified basis for partial recursive functions, and a `Turing.TM2` model Turing machine for evaluating these functions. This amounts to a constructive proof that every `Partrec` function can be evaluated by a Turing machine. ## Main definitions * `PartrecToTM2.tr`: A TM2 turing machine which can evaluate `code` programs -/ open List (Vector) open Function (update) open Relation namespace Turing /-! ## Simulating sequentialized partial recursive functions in TM2 At this point we have a sequential model of partial recursive functions: the `Cfg` type and `step : Cfg β†’ Option Cfg` function from `TMConfig.lean`. The key feature of this model is that it does a finite amount of computation (in fact, an amount which is statically bounded by the size of the program) between each step, and no individual step can diverge (unlike the compositional semantics, where every sub-part of the computation is potentially divergent). So we can utilize the same techniques as in the other TM simulations in `Computability.TuringMachine` to prove that each step corresponds to a finite number of steps in a lower level model. (We don't prove it here, but in anticipation of the complexity class P, the simulation is actually polynomial-time as well.) The target model is `Turing.TM2`, which has a fixed finite set of stacks, a bit of local storage, with programs selected from a potentially infinite (but finitely accessible) set of program positions, or labels `Ξ›`, each of which executes a finite sequence of basic stack commands. For this program we will need four stacks, each on an alphabet `Ξ“'` like so: inductive Ξ“' | consβ‚— | cons | bit0 | bit1 We represent a number as a bit sequence, lists of numbers by putting `cons` after each element, and lists of lists of natural numbers by putting `consβ‚—` after each list. For example: 0 ~> [] 1 ~> [bit1] 6 ~> [bit0, bit1, bit1] [1, 2] ~> [bit1, cons, bit0, bit1, cons] [[], [1, 2]] ~> [consβ‚—, bit1, cons, bit0, bit1, cons, consβ‚—] The four stacks are `main`, `rev`, `aux`, `stack`. In normal mode, `main` contains the input to the current program (a `List β„•`) and `stack` contains data (a `List (List β„•)`) associated to the current continuation, and in `ret` mode `main` contains the value that is being passed to the continuation and `stack` contains the data for the continuation. The `rev` and `aux` stacks are usually empty; `rev` is used to store reversed data when e.g. moving a value from one stack to another, while `aux` is used as a temporary for a `main`/`stack` swap that happens during `cons₁` evaluation. The only local store we need is `Option Ξ“'`, which stores the result of the last pop operation. (Most of our working data are natural numbers, which are too large to fit in the local store.) The continuations from the previous section are data-carrying, containing all the values that have been computed and are awaiting other arguments. In order to have only a finite number of continuations appear in the program so that they can be used in machine states, we separate the data part (anything with type `List β„•`) from the `Cont` type, producing a `Cont'` type that lacks this information. The data is kept on the `stack` stack. Because we want to have subroutines for e.g. moving an entire stack to another place, we use an infinite inductive type `Ξ›'` so that we can execute a program and then return to do something else without having to define too many different kinds of intermediate states. (We must nevertheless prove that only finitely many labels are accessible.) The labels are: * `move p k₁ kβ‚‚ q`: move elements from stack `k₁` to `kβ‚‚` while `p` holds of the value being moved. The last element, that fails `p`, is placed in neither stack but left in the local store. At the end of the operation, `kβ‚‚` will have the elements of `k₁` in reverse order. Then do `q`. * `clear p k q`: delete elements from stack `k` until `p` is true. Like `move`, the last element is left in the local storage. Then do `q`. * `copy q`: Move all elements from `rev` to both `main` and `stack` (in reverse order), then do `q`. That is, it takes `(a, b, c, d)` to `(b.reverse ++ a, [], c, b.reverse ++ d)`. * `push k f q`: push `f s`, where `s` is the local store, to stack `k`, then do `q`. This is a duplicate of the `push` instruction that is part of the TM2 model, but by having a subroutine just for this purpose we can build up programs to execute inside a `goto` statement, where we have the flexibility to be general recursive. * `read (f : Option Ξ“' β†’ Ξ›')`: go to state `f s` where `s` is the local store. Again this is only here for convenience. * `succ q`: perform a successor operation. Assuming `[n]` is encoded on `main` before, `[n+1]` will be on main after. This implements successor for binary natural numbers. * `pred q₁ qβ‚‚`: perform a predecessor operation or `case` statement. If `[]` is encoded on `main` before, then we transition to `q₁` with `[]` on main; if `(0 :: v)` is on `main` before then `v` will be on `main` after and we transition to `q₁`; and if `(n+1 :: v)` is on `main` before then `n :: v` will be on `main` after and we transition to `qβ‚‚`. * `ret k`: call continuation `k`. Each continuation has its own interpretation of the data in `stack` and sets up the data for the next continuation. * `ret (cons₁ fs k)`: `v :: KData` on `stack` and `ns` on `main`, and the next step expects `v` on `main` and `ns :: KData` on `stack`. So we have to do a little dance here with six reverse-moves using the `aux` stack to perform a three-point swap, each of which involves two reversals. * `ret (consβ‚‚ k)`: `ns :: KData` is on `stack` and `v` is on `main`, and we have to put `ns.headI :: v` on `main` and `KData` on `stack`. This is done using the `head` subroutine. * `ret (fix f k)`: This stores no data, so we just check if `main` starts with `0` and if so, remove it and call `k`, otherwise `clear` the first value and call `f`. * `ret halt`: the stack is empty, and `main` has the output. Do nothing and halt. In addition to these basic states, we define some additional subroutines that are used in the above: * `push'`, `peek'`, `pop'` are special versions of the builtins that use the local store to supply inputs and outputs. * `unrev`: special case `move false rev main` to move everything from `rev` back to `main`. Used as a cleanup operation in several functions. * `moveExcl p k₁ kβ‚‚ q`: same as `move` but pushes the last value read back onto the source stack. * `moveβ‚‚ p k₁ kβ‚‚ q`: double `move`, so that the result comes out in the right order at the target stack. Implemented as `moveExcl p k rev; move false rev kβ‚‚`. Assumes that neither `k₁` nor `kβ‚‚` is `rev` and `rev` is initially empty. * `head k q`: get the first natural number from stack `k` and reverse-move it to `rev`, then clear the rest of the list at `k` and then `unrev` to reverse-move the head value to `main`. This is used with `k = main` to implement regular `head`, i.e. if `v` is on `main` before then `[v.headI]` will be on `main` after; and also with `k = stack` for the `cons` operation, which has `v` on `main` and `ns :: KData` on `stack`, and results in `KData` on `stack` and `ns.headI :: v` on `main`. * `trNormal` is the main entry point, defining states that perform a given `code` computation. It mostly just dispatches to functions written above. The main theorem of this section is `tr_eval`, which asserts that for each that for each code `c`, the state `init c v` steps to `halt v'` in finitely many steps if and only if `Code.eval c v = some v'`. -/ namespace PartrecToTM2 section open ToPartrec /-- The alphabet for the stacks in the program. `bit0` and `bit1` are used to represent `β„•` values as lists of binary digits, `cons` is used to separate `List β„•` values, and `consβ‚—` is used to separate `List (List β„•)` values. See the section documentation. -/ inductive Ξ“' | consβ‚— | cons | bit0 | bit1 deriving DecidableEq, Inhabited, Fintype /-- The four stacks used by the program. `main` is used to store the input value in `trNormal` mode and the output value in `Ξ›'.ret` mode, while `stack` is used to keep all the data for the continuations. `rev` is used to store reversed lists when transferring values between stacks, and `aux` is only used once in `cons₁`. See the section documentation. -/ inductive K' | main | rev | aux | stack deriving DecidableEq, Inhabited open K' /-- Continuations as in `ToPartrec.Cont` but with the data removed. This is done because we want the set of all continuations in the program to be finite (so that it can ultimately be encoded into the finite state machine of a Turing machine), but a continuation can handle a potentially infinite number of data values during execution. -/ inductive Cont' | halt | cons₁ : Code β†’ Cont' β†’ Cont' | consβ‚‚ : Cont' β†’ Cont' | comp : Code β†’ Cont' β†’ Cont' | fix : Code β†’ Cont' β†’ Cont' deriving DecidableEq, Inhabited /-- The set of program positions. We make extensive use of inductive types here to let us describe "subroutines"; for example `clear p k q` is a program that clears stack `k`, then does `q` where `q` is another label. In order to prevent this from resulting in an infinite number of distinct accessible states, we are careful to be non-recursive (although loops are okay). See the section documentation for a description of all the programs. -/ inductive Ξ›' | move (p : Ξ“' β†’ Bool) (k₁ kβ‚‚ : K') (q : Ξ›') | clear (p : Ξ“' β†’ Bool) (k : K') (q : Ξ›') | copy (q : Ξ›') | push (k : K') (s : Option Ξ“' β†’ Option Ξ“') (q : Ξ›') | read (f : Option Ξ“' β†’ Ξ›') | succ (q : Ξ›') | pred (q₁ qβ‚‚ : Ξ›') | ret (k : Cont') compile_inductive% Code compile_inductive% Cont' compile_inductive% K' compile_inductive% Ξ›' instance Ξ›'.instInhabited : Inhabited Ξ›' := βŸ¨Ξ›'.ret Cont'.halt⟩ instance Ξ›'.instDecidableEq : DecidableEq Ξ›' := fun a b => by induction a generalizing b <;> cases b <;> first | apply Decidable.isFalse; rintro ⟨⟨⟩⟩; done | exact decidable_of_iff' _ (by simp [funext_iff]; rfl) /-- The type of TM2 statements used by this machine. -/ def Stmt' := TM2.Stmt (fun _ : K' => Ξ“') Ξ›' (Option Ξ“') deriving Inhabited /-- The type of TM2 configurations used by this machine. -/ def Cfg' := TM2.Cfg (fun _ : K' => Ξ“') Ξ›' (Option Ξ“') deriving Inhabited open TM2.Stmt /-- A predicate that detects the end of a natural number, either `Ξ“'.cons` or `Ξ“'.consβ‚—` (or implicitly the end of the list), for use in predicate-taking functions like `move` and `clear`. -/ @[simp] def natEnd : Ξ“' β†’ Bool | Ξ“'.consβ‚— => true | Ξ“'.cons => true | _ => false attribute [nolint simpNF] natEnd.eq_3 /-- Pop a value from the stack and place the result in local store. -/ @[simp] def pop' (k : K') : Stmt' β†’ Stmt' := pop k fun _ v => v /-- Peek a value from the stack and place the result in local store. -/ @[simp] def peek' (k : K') : Stmt' β†’ Stmt' := peek k fun _ v => v /-- Push the value in the local store to the given stack. -/ @[simp] def push' (k : K') : Stmt' β†’ Stmt' := push k fun x => x.iget /-- Move everything from the `rev` stack to the `main` stack (reversed). -/ def unrev := Ξ›'.move (fun _ => false) rev main /-- Move elements from `k₁` to `kβ‚‚` while `p` holds, with the last element being left on `k₁`. -/ def moveExcl (p k₁ kβ‚‚ q) := Ξ›'.move p k₁ kβ‚‚ <| Ξ›'.push k₁ id q /-- Move elements from `k₁` to `kβ‚‚` without reversion, by performing a double move via the `rev` stack. -/ def moveβ‚‚ (p k₁ kβ‚‚ q) := moveExcl p k₁ rev <| Ξ›'.move (fun _ => false) rev kβ‚‚ q /-- Assuming `trList v` is on the front of stack `k`, remove it, and push `v.headI` onto `main`. See the section documentation. -/ def head (k : K') (q : Ξ›') : Ξ›' := Ξ›'.move natEnd k rev <| (Ξ›'.push rev fun _ => some Ξ“'.cons) <| Ξ›'.read fun s => (if s = some Ξ“'.consβ‚— then id else Ξ›'.clear (fun x => x = Ξ“'.consβ‚—) k) <| unrev q /-- The program that evaluates code `c` with continuation `k`. This expects an initial state where `trList v` is on `main`, `trContStack k` is on `stack`, and `aux` and `rev` are empty. See the section documentation for details. -/ @[simp] def trNormal : Code β†’ Cont' β†’ Ξ›' | Code.zero', k => (Ξ›'.push main fun _ => some Ξ“'.cons) <| Ξ›'.ret k | Code.succ, k => head main <| Ξ›'.succ <| Ξ›'.ret k | Code.tail, k => Ξ›'.clear natEnd main <| Ξ›'.ret k | Code.cons f fs, k => (Ξ›'.push stack fun _ => some Ξ“'.consβ‚—) <| Ξ›'.move (fun _ => false) main rev <| Ξ›'.copy <| trNormal f (Cont'.cons₁ fs k) | Code.comp f g, k => trNormal g (Cont'.comp f k) | Code.case f g, k => Ξ›'.pred (trNormal f k) (trNormal g k) | Code.fix f, k => trNormal f (Cont'.fix f k) /-- The main program. See the section documentation for details. -/ def tr : Ξ›' β†’ Stmt' | Ξ›'.move p k₁ kβ‚‚ q => pop' k₁ <| branch (fun s => s.elim true p) (goto fun _ => q) (push' kβ‚‚ <| goto fun _ => Ξ›'.move p k₁ kβ‚‚ q) | Ξ›'.push k f q => branch (fun s => (f s).isSome) ((push k fun s => (f s).iget) <| goto fun _ => q) (goto fun _ => q) | Ξ›'.read q => goto q | Ξ›'.clear p k q => pop' k <| branch (fun s => s.elim true p) (goto fun _ => q) (goto fun _ => Ξ›'.clear p k q) | Ξ›'.copy q => pop' rev <| branch Option.isSome (push' main <| push' stack <| goto fun _ => Ξ›'.copy q) (goto fun _ => q) | Ξ›'.succ q => pop' main <| branch (fun s => s = some Ξ“'.bit1) ((push rev fun _ => Ξ“'.bit0) <| goto fun _ => Ξ›'.succ q) <| branch (fun s => s = some Ξ“'.cons) ((push main fun _ => Ξ“'.cons) <| (push main fun _ => Ξ“'.bit1) <| goto fun _ => unrev q) ((push main fun _ => Ξ“'.bit1) <| goto fun _ => unrev q) | Ξ›'.pred q₁ qβ‚‚ => pop' main <| branch (fun s => s = some Ξ“'.bit0) ((push rev fun _ => Ξ“'.bit1) <| goto fun _ => Ξ›'.pred q₁ qβ‚‚) <| branch (fun s => natEnd s.iget) (goto fun _ => q₁) (peek' main <| branch (fun s => natEnd s.iget) (goto fun _ => unrev qβ‚‚) ((push rev fun _ => Ξ“'.bit0) <| goto fun _ => unrev qβ‚‚)) | Ξ›'.ret (Cont'.cons₁ fs k) => goto fun _ => moveβ‚‚ (fun _ => false) main aux <| moveβ‚‚ (fun s => s = Ξ“'.consβ‚—) stack main <| moveβ‚‚ (fun _ => false) aux stack <| trNormal fs (Cont'.consβ‚‚ k) | Ξ›'.ret (Cont'.consβ‚‚ k) => goto fun _ => head stack <| Ξ›'.ret k | Ξ›'.ret (Cont'.comp f k) => goto fun _ => trNormal f k | Ξ›'.ret (Cont'.fix f k) => pop' main <| goto fun s => cond (natEnd s.iget) (Ξ›'.ret k) <| Ξ›'.clear natEnd main <| trNormal f (Cont'.fix f k) | Ξ›'.ret Cont'.halt => (load fun _ => none) <| halt @[simp] theorem tr_move (p k₁ kβ‚‚ q) : tr (Ξ›'.move p k₁ kβ‚‚ q) = pop' k₁ (branch (fun s => s.elim true p) (goto fun _ => q) (push' kβ‚‚ <| goto fun _ => Ξ›'.move p k₁ kβ‚‚ q)) := rfl @[simp] theorem tr_push (k f q) : tr (Ξ›'.push k f q) = branch (fun s => (f s).isSome) ((push k fun s => (f s).iget) <| goto fun _ => q) (goto fun _ => q) := rfl @[simp] theorem tr_read (q) : tr (Ξ›'.read q) = goto q := rfl @[simp] theorem tr_clear (p k q) : tr (Ξ›'.clear p k q) = pop' k (branch (fun s => s.elim true p) (goto fun _ => q) (goto fun _ => Ξ›'.clear p k q)) := rfl @[simp] theorem tr_copy (q) : tr (Ξ›'.copy q) = pop' rev (branch Option.isSome (push' main <| push' stack <| goto fun _ => Ξ›'.copy q) (goto fun _ => q)) := rfl @[simp] theorem tr_succ (q) : tr (Ξ›'.succ q) = pop' main (branch (fun s => s = some Ξ“'.bit1) ((push rev fun _ => Ξ“'.bit0) <| goto fun _ => Ξ›'.succ q) <| branch (fun s => s = some Ξ“'.cons) ((push main fun _ => Ξ“'.cons) <| (push main fun _ => Ξ“'.bit1) <| goto fun _ => unrev q) ((push main fun _ => Ξ“'.bit1) <| goto fun _ => unrev q)) := rfl @[simp] theorem tr_pred (q₁ qβ‚‚) : tr (Ξ›'.pred q₁ qβ‚‚) = pop' main (branch (fun s => s = some Ξ“'.bit0) ((push rev fun _ => Ξ“'.bit1) <| goto fun _ => Ξ›'.pred q₁ qβ‚‚) <| branch (fun s => natEnd s.iget) (goto fun _ => q₁) (peek' main <| branch (fun s => natEnd s.iget) (goto fun _ => unrev qβ‚‚) ((push rev fun _ => Ξ“'.bit0) <| goto fun _ => unrev qβ‚‚))) := rfl @[simp] theorem tr_ret_cons₁ (fs k) : tr (Ξ›'.ret (Cont'.cons₁ fs k)) = goto fun _ => moveβ‚‚ (fun _ => false) main aux <| moveβ‚‚ (fun s => s = Ξ“'.consβ‚—) stack main <| moveβ‚‚ (fun _ => false) aux stack <| trNormal fs (Cont'.consβ‚‚ k) := rfl @[simp] theorem tr_ret_consβ‚‚ (k) : tr (Ξ›'.ret (Cont'.consβ‚‚ k)) = goto fun _ => head stack <| Ξ›'.ret k := rfl @[simp] theorem tr_ret_comp (f k) : tr (Ξ›'.ret (Cont'.comp f k)) = goto fun _ => trNormal f k := rfl @[simp] theorem tr_ret_fix (f k) : tr (Ξ›'.ret (Cont'.fix f k)) = pop' main (goto fun s => cond (natEnd s.iget) (Ξ›'.ret k) <| Ξ›'.clear natEnd main <| trNormal f (Cont'.fix f k)) := rfl @[simp] theorem tr_ret_halt : tr (Ξ›'.ret Cont'.halt) = (load fun _ => none) halt := rfl /-- Translating a `Cont` continuation to a `Cont'` continuation simply entails dropping all the data. This data is instead encoded in `trContStack` in the configuration. -/ def trCont : Cont β†’ Cont' | Cont.halt => Cont'.halt | Cont.cons₁ c _ k => Cont'.cons₁ c (trCont k) | Cont.consβ‚‚ _ k => Cont'.consβ‚‚ (trCont k) | Cont.comp c k => Cont'.comp c (trCont k) | Cont.fix c k => Cont'.fix c (trCont k) /-- We use `PosNum` to define the translation of binary natural numbers. A natural number is represented as a little-endian list of `bit0` and `bit1` elements: 1 = [bit1] 2 = [bit0, bit1] 3 = [bit1, bit1] 4 = [bit0, bit0, bit1] In particular, this representation guarantees no trailing `bit0`'s at the end of the list. -/ def trPosNum : PosNum β†’ List Ξ“' | PosNum.one => [Ξ“'.bit1] | PosNum.bit0 n => Ξ“'.bit0 :: trPosNum n | PosNum.bit1 n => Ξ“'.bit1 :: trPosNum n /-- We use `Num` to define the translation of binary natural numbers. Positive numbers are translated using `trPosNum`, and `trNum 0 = []`. So there are never any trailing `bit0`'s in a translated `Num`. 0 = [] 1 = [bit1] 2 = [bit0, bit1] 3 = [bit1, bit1] 4 = [bit0, bit0, bit1] -/ def trNum : Num β†’ List Ξ“' | Num.zero => [] | Num.pos n => trPosNum n /-- Because we use binary encoding, we define `trNat` in terms of `trNum`, using `Num`, which are binary natural numbers. (We could also use `Nat.binaryRecOn`, but `Num` and `PosNum` make for easy inductions.) -/ def trNat (n : β„•) : List Ξ“' := trNum n @[simp] theorem trNat_zero : trNat 0 = [] := by rw [trNat, Nat.cast_zero]; rfl theorem trNat_default : trNat default = [] := trNat_zero /-- Lists are translated with a `cons` after each encoded number. For example: [] = [] [0] = [cons] [1] = [bit1, cons] [6, 0] = [bit0, bit1, bit1, cons, cons] -/ @[simp] def trList : List β„• β†’ List Ξ“' | [] => [] | n::ns => trNat n ++ Ξ“'.cons :: trList ns /-- Lists of lists are translated with a `consβ‚—` after each encoded list. For example: [] = [] [[]] = [consβ‚—] [[], []] = [consβ‚—, consβ‚—] [[0]] = [cons, consβ‚—] [[1, 2], [0]] = [bit1, cons, bit0, bit1, cons, consβ‚—, cons, consβ‚—] -/ @[simp] def trLList : List (List β„•) β†’ List Ξ“' | [] => [] | l::ls => trList l ++ Ξ“'.consβ‚— :: trLList ls /-- The data part of a continuation is a list of lists, which is encoded on the `stack` stack using `trLList`. -/ @[simp] def contStack : Cont β†’ List (List β„•) | Cont.halt => [] | Cont.cons₁ _ ns k => ns :: contStack k | Cont.consβ‚‚ ns k => ns :: contStack k | Cont.comp _ k => contStack k | Cont.fix _ k => contStack k /-- The data part of a continuation is a list of lists, which is encoded on the `stack` stack using `trLList`. -/ def trContStack (k : Cont) := trLList (contStack k) /-- This is the nondependent eliminator for `K'`, but we use it specifically here in order to represent the stack data as four lists rather than as a function `K' β†’ List Ξ“'`, because this makes rewrites easier. The theorems `K'.elim_update_main` et. al. show how such a function is updated after an `update` to one of the components. -/ def K'.elim (a b c d : List Ξ“') : K' β†’ List Ξ“' | K'.main => a | K'.rev => b | K'.aux => c | K'.stack => d -- The equation lemma of `elim` simplifies to `match` structures. theorem K'.elim_main (a b c d) : K'.elim a b c d K'.main = a := rfl theorem K'.elim_rev (a b c d) : K'.elim a b c d K'.rev = b := rfl theorem K'.elim_aux (a b c d) : K'.elim a b c d K'.aux = c := rfl theorem K'.elim_stack (a b c d) : K'.elim a b c d K'.stack = d := rfl attribute [simp] K'.elim @[simp] theorem K'.elim_update_main {a b c d a'} : update (K'.elim a b c d) main a' = K'.elim a' b c d := by funext x; cases x <;> rfl @[simp] theorem K'.elim_update_rev {a b c d b'} : update (K'.elim a b c d) rev b' = K'.elim a b' c d := by funext x; cases x <;> rfl @[simp] theorem K'.elim_update_aux {a b c d c'} : update (K'.elim a b c d) aux c' = K'.elim a b c' d := by funext x; cases x <;> rfl @[simp] theorem K'.elim_update_stack {a b c d d'} : update (K'.elim a b c d) stack d' = K'.elim a b c d' := by funext x; cases x <;> rfl /-- The halting state corresponding to a `List β„•` output value. -/ def halt (v : List β„•) : Cfg' := ⟨none, none, K'.elim (trList v) [] [] []⟩ /-- The `Cfg` states map to `Cfg'` states almost one to one, except that in normal operation the local store contains an arbitrary garbage value. To make the final theorem cleaner we explicitly clear it in the halt state so that there is exactly one configuration corresponding to output `v`. -/ def TrCfg : Cfg β†’ Cfg' β†’ Prop | Cfg.ret k v, c' => βˆƒ s, c' = ⟨some (Ξ›'.ret (trCont k)), s, K'.elim (trList v) [] [] (trContStack k)⟩ | Cfg.halt v, c' => c' = halt v /-- This could be a general list definition, but it is also somewhat specialized to this application. `splitAtPred p L` will search `L` for the first element satisfying `p`. If it is found, say `L = l₁ ++ a :: lβ‚‚` where `a` satisfies `p` but `l₁` does not, then it returns `(l₁, some a, lβ‚‚)`. Otherwise, if there is no such element, it returns `(L, none, [])`. -/ def splitAtPred {Ξ±} (p : Ξ± β†’ Bool) : List Ξ± β†’ List Ξ± Γ— Option Ξ± Γ— List Ξ± | [] => ([], none, []) | a :: as => cond (p a) ([], some a, as) <| let ⟨l₁, o, lβ‚‚βŸ© := splitAtPred p as ⟨a::l₁, o, lβ‚‚βŸ© theorem splitAtPred_eq {Ξ±} (p : Ξ± β†’ Bool) : βˆ€ L l₁ o lβ‚‚, (βˆ€ x ∈ l₁, p x = false) β†’ Option.elim' (L = l₁ ∧ lβ‚‚ = []) (fun a => p a = true ∧ L = l₁ ++ a::lβ‚‚) o β†’ splitAtPred p L = (l₁, o, lβ‚‚) | [], _, none, _, _, ⟨rfl, rfl⟩ => rfl | [], l₁, some o, lβ‚‚, _, ⟨_, hβ‚ƒβŸ© => by simp at h₃ | a :: L, l₁, o, lβ‚‚, h₁, hβ‚‚ => by rw [splitAtPred] have IH := splitAtPred_eq p L rcases o with - | o Β· rcases l₁ with - | ⟨a', lβ‚βŸ© <;> rcases hβ‚‚ with ⟨⟨⟩, rfl⟩ rw [h₁ a (List.Mem.head _), cond, IH L none [] _ ⟨rfl, rfl⟩] exact fun x h => h₁ x (List.Mem.tail _ h) Β· rcases l₁ with - | ⟨a', lβ‚βŸ© <;> rcases hβ‚‚ with ⟨hβ‚‚, ⟨⟩⟩ Β· rw [hβ‚‚, cond] rw [h₁ a (List.Mem.head _), cond, IH l₁ (some o) lβ‚‚ _ ⟨hβ‚‚, _⟩] <;> try rfl exact fun x h => h₁ x (List.Mem.tail _ h) theorem splitAtPred_false {Ξ±} (L : List Ξ±) : splitAtPred (fun _ => false) L = (L, none, []) := splitAtPred_eq _ _ _ _ _ (fun _ _ => rfl) ⟨rfl, rfl⟩ theorem move_ok {p k₁ kβ‚‚ q s L₁ o Lβ‚‚} {S : K' β†’ List Ξ“'} (h₁ : k₁ β‰  kβ‚‚) (e : splitAtPred p (S k₁) = (L₁, o, Lβ‚‚)) : Reaches₁ (TM2.step tr) ⟨some (Ξ›'.move p k₁ kβ‚‚ q), s, S⟩ ⟨some q, o, update (update S k₁ Lβ‚‚) kβ‚‚ (L₁.reverseAux (S kβ‚‚))⟩ := by induction' L₁ with a L₁ IH generalizing S s Β· rw [(_ : [].reverseAux _ = _), Function.update_eq_self] swap Β· rw [Function.update_of_ne h₁.symm, List.reverseAux_nil] refine TransGen.head' rfl ?_ rw [tr]; simp only [pop', TM2.stepAux] revert e; rcases S k₁ with - | ⟨a, Sk⟩ <;> intro e Β· cases e rfl simp only [splitAtPred, Option.elim, List.head?, List.tail_cons, Option.iget_some] at e ⊒ revert e; cases p a <;> intro e <;> simp only [cond_false, cond_true, Prod.mk.injEq, true_and, false_and, reduceCtorEq] at e ⊒ simp only [e] rfl Β· refine TransGen.head rfl ?_ rw [tr]; simp only [pop', Option.elim, TM2.stepAux, push'] rcases e₁ : S k₁ with - | ⟨a', Sk⟩ <;> rw [e₁, splitAtPred] at e Β· cases e cases eβ‚‚ : p a' <;> simp only [eβ‚‚, cond] at e swap Β· cases e rcases e₃ : splitAtPred p Sk with ⟨_, _, _⟩ rw [e₃] at e cases e simp only [List.head?_cons, eβ‚‚, List.tail_cons, ne_eq, cond_false] convert @IH _ (update (update S k₁ Sk) kβ‚‚ (a :: S kβ‚‚)) _ using 2 <;> simp [Function.update_of_ne, h₁, h₁.symm, e₃, List.reverseAux] simp [Function.update_comm h₁.symm] theorem unrev_ok {q s} {S : K' β†’ List Ξ“'} : Reaches₁ (TM2.step tr) ⟨some (unrev q), s, S⟩ ⟨some q, none, update (update S rev []) main (List.reverseAux (S rev) (S main))⟩ := move_ok (by decide) <| splitAtPred_false _ theorem moveβ‚‚_ok {p k₁ kβ‚‚ q s L₁ o Lβ‚‚} {S : K' β†’ List Ξ“'} (h₁ : k₁ β‰  rev ∧ kβ‚‚ β‰  rev ∧ k₁ β‰  kβ‚‚) (hβ‚‚ : S rev = []) (e : splitAtPred p (S k₁) = (L₁, o, Lβ‚‚)) : Reaches₁ (TM2.step tr) ⟨some (moveβ‚‚ p k₁ kβ‚‚ q), s, S⟩ ⟨some q, none, update (update S k₁ (o.elim id List.cons Lβ‚‚)) kβ‚‚ (L₁ ++ S kβ‚‚)⟩ := by refine (move_ok h₁.1 e).trans (TransGen.head rfl ?_) simp only [TM2.step, Option.mem_def, TM2.stepAux, id_eq, ne_eq, Option.elim] cases o <;> simp only [Option.elim] <;> rw [tr] <;> simp only [id, TM2.stepAux, Option.isSome, cond_true, cond_false] Β· convert move_ok h₁.2.1.symm (splitAtPred_false _) using 2 simp only [Function.update_comm h₁.1, Function.update_idem] rw [show update S rev [] = S by rw [← hβ‚‚, Function.update_eq_self]] simp only [Function.update_of_ne h₁.2.2.symm, Function.update_of_ne h₁.2.1, Function.update_of_ne h₁.1.symm, List.reverseAux_eq, hβ‚‚, Function.update_self, List.append_nil, List.reverse_reverse] Β· convert move_ok h₁.2.1.symm (splitAtPred_false _) using 2 simp only [hβ‚‚, Function.update_comm h₁.1, List.reverseAux_eq, Function.update_self, List.append_nil, Function.update_idem] rw [show update S rev [] = S by rw [← hβ‚‚, Function.update_eq_self]] simp only [Function.update_of_ne h₁.1.symm, Function.update_of_ne h₁.2.2.symm, Function.update_of_ne h₁.2.1, Function.update_self, List.reverse_reverse] theorem clear_ok {p k q s L₁ o Lβ‚‚} {S : K' β†’ List Ξ“'} (e : splitAtPred p (S k) = (L₁, o, Lβ‚‚)) : Reaches₁ (TM2.step tr) ⟨some (Ξ›'.clear p k q), s, S⟩ ⟨some q, o, update S k Lβ‚‚βŸ© := by induction' L₁ with a L₁ IH generalizing S s Β· refine TransGen.head' rfl ?_ rw [tr]; simp only [pop', TM2.step, Option.mem_def, TM2.stepAux, Option.elim] revert e; rcases S k with - | ⟨a, Sk⟩ <;> intro e Β· cases e rfl simp only [splitAtPred, Option.elim, List.head?, List.tail_cons] at e ⊒ revert e; cases p a <;> intro e <;> simp only [cond_false, cond_true, Prod.mk.injEq, true_and, false_and, reduceCtorEq] at e ⊒ rcases e with ⟨e₁, eβ‚‚βŸ© rw [e₁, eβ‚‚] Β· refine TransGen.head rfl ?_ rw [tr]; simp only [pop', TM2.step, Option.mem_def, TM2.stepAux, Option.elim] rcases e₁ : S k with - | ⟨a', Sk⟩ <;> rw [e₁, splitAtPred] at e Β· cases e cases eβ‚‚ : p a' <;> simp only [eβ‚‚, cond] at e swap Β· cases e rcases e₃ : splitAtPred p Sk with ⟨_, _, _⟩ rw [e₃] at e cases e simp only [List.head?_cons, eβ‚‚, List.tail_cons, cond_false] convert @IH _ (update S k Sk) _ using 2 <;> simp [e₃] theorem copy_ok (q s a b c d) : Reaches₁ (TM2.step tr) ⟨some (Ξ›'.copy q), s, K'.elim a b c d⟩ ⟨some q, none, K'.elim (List.reverseAux b a) [] c (List.reverseAux b d)⟩ := by induction' b with x b IH generalizing a d s Β· refine TransGen.single ?_ simp refine TransGen.head rfl ?_ rw [tr] simp only [TM2.step, Option.mem_def, TM2.stepAux, elim_rev, List.head?_cons, Option.isSome_some, List.tail_cons, elim_update_rev, ne_eq, Function.update_of_ne, elim_main, elim_update_main, elim_stack, elim_update_stack, cond_true, List.reverseAux_cons, pop', push'] exact IH _ _ _ theorem trPosNum_natEnd : βˆ€ (n), βˆ€ x ∈ trPosNum n, natEnd x = false | PosNum.one, _, List.Mem.head _ => rfl | PosNum.bit0 _, _, List.Mem.head _ => rfl | PosNum.bit0 n, _, List.Mem.tail _ h => trPosNum_natEnd n _ h | PosNum.bit1 _, _, List.Mem.head _ => rfl | PosNum.bit1 n, _, List.Mem.tail _ h => trPosNum_natEnd n _ h theorem trNum_natEnd : βˆ€ (n), βˆ€ x ∈ trNum n, natEnd x = false | Num.pos n, x, h => trPosNum_natEnd n x h theorem trNat_natEnd (n) : βˆ€ x ∈ trNat n, natEnd x = false := trNum_natEnd _ theorem trList_ne_consβ‚— : βˆ€ (l), βˆ€ x ∈ trList l, x β‰  Ξ“'.consβ‚— | a :: l, x, h => by simp only [trList, List.mem_append, List.mem_cons] at h obtain h | rfl | h := h Β· rintro rfl cases trNat_natEnd _ _ h Β· rintro ⟨⟩ Β· exact trList_ne_consβ‚— l _ h theorem head_main_ok {q s L} {c d : List Ξ“'} : Reaches₁ (TM2.step tr) ⟨some (head main q), s, K'.elim (trList L) [] c d⟩ ⟨some q, none, K'.elim (trList [L.headI]) [] c d⟩ := by let o : Option Ξ“' := List.casesOn L none fun _ _ => some Ξ“'.cons refine (move_ok (by decide) (splitAtPred_eq _ _ (trNat L.headI) o (trList L.tail) (trNat_natEnd _) ?_)).trans (TransGen.head rfl (TransGen.head rfl ?_)) Β· cases L <;> simp [o] rw [tr] simp only [TM2.step, Option.mem_def, TM2.stepAux, elim_update_main, elim_rev, elim_update_rev, Function.update_self, trList] rw [if_neg (show o β‰  some Ξ“'.consβ‚— by cases L <;> simp [o])] refine (clear_ok (splitAtPred_eq _ _ _ none [] ?_ ⟨rfl, rfl⟩)).trans ?_ Β· exact fun x h => Bool.decide_false (trList_ne_consβ‚— _ _ h) convert unrev_ok using 2; simp [List.reverseAux_eq] theorem head_stack_ok {q s L₁ Lβ‚‚ L₃} : Reaches₁ (TM2.step tr) ⟨some (head stack q), s, K'.elim (trList L₁) [] [] (trList Lβ‚‚ ++ Ξ“'.consβ‚— :: L₃)⟩ ⟨some q, none, K'.elim (trList (Lβ‚‚.headI :: L₁)) [] [] Lβ‚ƒβŸ© := by rcases Lβ‚‚ with - | ⟨a, Lβ‚‚βŸ© Β· refine TransGen.trans (move_ok (by decide) (splitAtPred_eq _ _ [] (some Ξ“'.consβ‚—) L₃ (by rintro _ ⟨⟩) ⟨rfl, rfl⟩)) (TransGen.head rfl (TransGen.head rfl ?_)) rw [tr] simp only [TM2.step, Option.mem_def, TM2.stepAux, ite_true, id_eq, trList, List.nil_append, elim_update_stack, elim_rev, List.reverseAux_nil, elim_update_rev, Function.update_self, List.headI_nil, trNat_default] convert unrev_ok using 2 simp Β· refine TransGen.trans (move_ok (by decide) (splitAtPred_eq _ _ (trNat a) (some Ξ“'.cons) (trList Lβ‚‚ ++ Ξ“'.consβ‚— :: L₃) (trNat_natEnd _) ⟨rfl, by simp⟩)) (TransGen.head rfl (TransGen.head rfl ?_)) simp only [TM2.step, Option.mem_def, TM2.stepAux, ite_false, trList, List.append_assoc, List.cons_append, elim_update_stack, elim_rev, elim_update_rev, Function.update_self, List.headI_cons] refine TransGen.trans (clear_ok (splitAtPred_eq _ _ (trList Lβ‚‚) (some Ξ“'.consβ‚—) L₃ (fun x h => Bool.decide_false (trList_ne_consβ‚— _ _ h)) ⟨rfl, by simp⟩)) ?_ convert unrev_ok using 2 simp [List.reverseAux_eq] theorem succ_ok {q s n} {c d : List Ξ“'} : Reaches₁ (TM2.step tr) ⟨some (Ξ›'.succ q), s, K'.elim (trList [n]) [] c d⟩ ⟨some q, none, K'.elim (trList [n.succ]) [] c d⟩ := by simp only [TM2.step, trList, trNat.eq_1, Nat.cast_succ, Num.add_one] rcases (n : Num) with - | a Β· refine TransGen.head rfl ?_ simp only [Option.mem_def, TM2.stepAux, elim_main, decide_false, elim_update_main, ne_eq, Function.update_of_ne, elim_rev, elim_update_rev, decide_true, Function.update_self, cond_true, cond_false] convert unrev_ok using 1 simp only [elim_update_rev, elim_rev, elim_main, List.reverseAux_nil, elim_update_main] rfl simp only [trNum, Num.succ, Num.succ'] suffices βˆ€ l₁, βˆƒ l₁' lβ‚‚' s', List.reverseAux l₁ (trPosNum a.succ) = List.reverseAux l₁' lβ‚‚' ∧ Reaches₁ (TM2.step tr) ⟨some q.succ, s, K'.elim (trPosNum a ++ [Ξ“'.cons]) l₁ c d⟩ ⟨some (unrev q), s', K'.elim (lβ‚‚' ++ [Ξ“'.cons]) l₁' c d⟩ by obtain ⟨l₁', lβ‚‚', s', e, h⟩ := this [] simp? [List.reverseAux] at e says simp only [List.reverseAux, List.reverseAux_eq] at e refine h.trans ?_ convert unrev_ok using 2 simp [e, List.reverseAux_eq] induction' a with m IH m _ generalizing s <;> intro l₁ Β· refine βŸ¨Ξ“'.bit0 :: l₁, [Ξ“'.bit1], some Ξ“'.cons, rfl, TransGen.head rfl (TransGen.single ?_)⟩ simp [trPosNum] Β· obtain ⟨l₁', lβ‚‚', s', e, h⟩ := IH (Ξ“'.bit0 :: l₁) refine ⟨l₁', lβ‚‚', s', e, TransGen.head ?_ h⟩ simp [PosNum.succ, trPosNum] rfl Β· refine ⟨l₁, _, some Ξ“'.bit0, rfl, TransGen.single ?_⟩ simp only [TM2.step]; rw [tr] simp only [TM2.stepAux, pop', elim_main, elim_update_main, ne_eq, Function.update_of_ne, elim_rev, elim_update_rev, Function.update_self, Option.mem_def, Option.some.injEq] rfl theorem pred_ok (q₁ qβ‚‚ s v) (c d : List Ξ“') : βˆƒ s', Reaches₁ (TM2.step tr) ⟨some (Ξ›'.pred q₁ qβ‚‚), s, K'.elim (trList v) [] c d⟩ (v.headI.rec ⟨some q₁, s', K'.elim (trList v.tail) [] c d⟩ fun n _ => ⟨some qβ‚‚, s', K'.elim (trList (n::v.tail)) [] c d⟩) := by rcases v with (_ | ⟨_ | n, v⟩) Β· refine ⟨none, TransGen.single ?_⟩ simp Β· refine ⟨some Ξ“'.cons, TransGen.single ?_⟩ simp refine ⟨none, ?_⟩ simp only [TM2.step, trList, trNat.eq_1, trNum, Nat.cast_succ, Num.add_one, Num.succ, List.tail_cons, List.headI_cons] rcases (n : Num) with - | a Β· simp only [trPosNum, Num.succ', List.singleton_append, List.nil_append] refine TransGen.head rfl ?_ rw [tr]; simp only [pop', TM2.stepAux, cond_false] convert unrev_ok using 2 simp simp only [Num.succ'] suffices βˆ€ l₁, βˆƒ l₁' lβ‚‚' s', List.reverseAux l₁ (trPosNum a) = List.reverseAux l₁' lβ‚‚' ∧ Reaches₁ (TM2.step tr) ⟨some (q₁.pred qβ‚‚), s, K'.elim (trPosNum a.succ ++ Ξ“'.cons :: trList v) l₁ c d⟩ ⟨some (unrev qβ‚‚), s', K'.elim (lβ‚‚' ++ Ξ“'.cons :: trList v) l₁' c d⟩ by obtain ⟨l₁', lβ‚‚', s', e, h⟩ := this [] simp only [List.reverseAux] at e refine h.trans ?_ convert unrev_ok using 2 simp [e, List.reverseAux_eq] induction' a with m IH m IH generalizing s <;> intro l₁ Β· refine βŸ¨Ξ“'.bit1::l₁, [], some Ξ“'.cons, rfl, TransGen.head rfl (TransGen.single ?_)⟩ simp [trPosNum, show PosNum.one.succ = PosNum.one.bit0 from rfl] Β· obtain ⟨l₁', lβ‚‚', s', e, h⟩ := IH (some Ξ“'.bit0) (Ξ“'.bit1 :: l₁) refine ⟨l₁', lβ‚‚', s', e, TransGen.head ?_ h⟩ simp rfl Β· obtain ⟨a, l, e, h⟩ : βˆƒ a l, (trPosNum m = a::l) ∧ natEnd a = false := by cases m <;> refine ⟨_, _, rfl, rfl⟩ refine βŸ¨Ξ“'.bit0 :: l₁, _, some a, rfl, TransGen.single ?_⟩ simp [trPosNum, PosNum.succ, e, h, show some Ξ“'.bit1 β‰  some Ξ“'.bit0 by decide, Option.iget, -natEnd] rfl theorem trNormal_respects (c k v s) : βˆƒ bβ‚‚, TrCfg (stepNormal c k v) bβ‚‚ ∧ Reaches₁ (TM2.step tr) ⟨some (trNormal c (trCont k)), s, K'.elim (trList v) [] [] (trContStack k)⟩ bβ‚‚ := by induction c generalizing k v s with | zero' => refine ⟨_, ⟨s, rfl⟩, TransGen.single ?_⟩; simp | succ => refine ⟨_, ⟨none, rfl⟩, head_main_ok.trans succ_ok⟩ | tail => let o : Option Ξ“' := List.casesOn v none fun _ _ => some Ξ“'.cons refine ⟨_, ⟨o, rfl⟩, ?_⟩; convert clear_ok _ using 2 Β· simp; rfl swap refine splitAtPred_eq _ _ (trNat v.headI) _ _ (trNat_natEnd _) ?_ cases v <;> simp [o] | cons f fs IHf _ => obtain ⟨c, h₁, hβ‚‚βŸ© := IHf (Cont.cons₁ fs v k) v none refine ⟨c, h₁, TransGen.head rfl <| (move_ok (by decide) (splitAtPred_false _)).trans ?_⟩ simp only [TM2.step, Option.mem_def, elim_stack, elim_update_stack, elim_update_main, ne_eq, Function.update_of_ne, elim_main, elim_rev, elim_update_rev] refine (copy_ok _ none [] (trList v).reverse _ _).trans ?_ convert hβ‚‚ using 2 simp [List.reverseAux_eq, trContStack] | comp f _ _ IHg => exact IHg (Cont.comp f k) v s | case f g IHf IHg => rw [stepNormal] simp only obtain ⟨s', h⟩ := pred_ok _ _ s v _ _ revert h; rcases v.headI with - | n <;> intro h Β· obtain ⟨c, h₁, hβ‚‚βŸ© := IHf k _ s' exact ⟨_, h₁, h.trans hβ‚‚βŸ© Β· obtain ⟨c, h₁, hβ‚‚βŸ© := IHg k _ s' exact ⟨_, h₁, h.trans hβ‚‚βŸ© | fix f IH => apply IH theorem tr_ret_respects (k v s) : βˆƒ bβ‚‚, TrCfg (stepRet k v) bβ‚‚ ∧ Reaches₁ (TM2.step tr) ⟨some (Ξ›'.ret (trCont k)), s, K'.elim (trList v) [] [] (trContStack k)⟩ bβ‚‚ := by induction k generalizing v s with | halt => exact ⟨_, rfl, TransGen.single rfl⟩ | cons₁ fs as k _ => obtain ⟨s', h₁, hβ‚‚βŸ© := trNormal_respects fs (Cont.consβ‚‚ v k) as none refine ⟨s', h₁, TransGen.head rfl ?_⟩; simp refine (moveβ‚‚_ok (by decide) ?_ (splitAtPred_false _)).trans ?_; Β· rfl simp only [TM2.step, Option.mem_def, Option.elim, id_eq, elim_update_main, elim_main, elim_aux, List.append_nil, elim_update_aux] refine (moveβ‚‚_ok (L₁ := ?_) (o := ?_) (Lβ‚‚ := ?_) (by decide) rfl ?_).trans ?_ pick_goal 4 Β· exact splitAtPred_eq _ _ _ (some Ξ“'.consβ‚—) _ (fun x h => Bool.decide_false (trList_ne_consβ‚— _ _ h)) ⟨rfl, rfl⟩ refine (moveβ‚‚_ok (by decide) ?_ (splitAtPred_false _)).trans ?_; Β· rfl simp only [TM2.step, Option.mem_def, Option.elim, elim_update_stack, elim_main, List.append_nil, elim_update_main, id_eq, elim_update_aux, ne_eq, Function.update_of_ne, elim_aux, elim_stack] exact hβ‚‚ | consβ‚‚ ns k IH => obtain ⟨c, h₁, hβ‚‚βŸ© := IH (ns.headI :: v) none exact ⟨c, h₁, TransGen.head rfl <| head_stack_ok.trans hβ‚‚βŸ© | comp f k _ => obtain ⟨s', h₁, hβ‚‚βŸ© := trNormal_respects f k v s exact ⟨_, h₁, TransGen.head rfl hβ‚‚βŸ© | fix f k IH => rw [stepRet] have : if v.headI = 0 then natEnd (trList v).head?.iget = true ∧ (trList v).tail = trList v.tail else natEnd (trList v).head?.iget = false ∧ (trList v).tail = (trNat v.headI).tail ++ Ξ“'.cons :: trList v.tail := by obtain - | n := v Β· exact ⟨rfl, rfl⟩ rcases n with - | n Β· simp rw [trList, List.headI, trNat, Nat.cast_succ, Num.add_one, Num.succ, List.tail] cases (n : Num).succ' <;> exact ⟨rfl, rfl⟩ by_cases h : v.headI = 0 <;> simp only [h, ite_true, ite_false] at this ⊒ Β· obtain ⟨c, h₁, hβ‚‚βŸ© := IH v.tail (trList v).head? refine ⟨c, h₁, TransGen.head rfl ?_⟩ rw [trCont, tr]; simp only [pop', TM2.stepAux, elim_main, this, elim_update_main] exact hβ‚‚ Β· obtain ⟨s', h₁, hβ‚‚βŸ© := trNormal_respects f (Cont.fix f k) v.tail (some Ξ“'.cons) refine ⟨_, h₁, TransGen.head rfl <| TransGen.trans ?_ hβ‚‚βŸ© rw [trCont, tr]; simp only [pop', TM2.stepAux, elim_main, this.1] convert clear_ok (splitAtPred_eq _ _ (trNat v.headI).tail (some Ξ“'.cons) _ _ _) using 2 Β· simp convert rfl Β· exact fun x h => trNat_natEnd _ _ (List.tail_subset _ h) Β· exact ⟨rfl, this.2⟩ theorem tr_respects : Respects step (TM2.step tr) TrCfg | Cfg.ret _ _, _, ⟨_, rfl⟩ => tr_ret_respects _ _ _ | Cfg.halt _, _, rfl => rfl /-- The initial state, evaluating function `c` on input `v`. -/ def init (c : Code) (v : List β„•) : Cfg' := ⟨some (trNormal c Cont'.halt), none, K'.elim (trList v) [] [] []⟩ theorem tr_init (c v) : βˆƒ b, TrCfg (stepNormal c Cont.halt v) b ∧ Reaches₁ (TM2.step tr) (init c v) b := trNormal_respects _ _ _ _ theorem tr_eval (c v) : eval (TM2.step tr) (init c v) = halt <$> Code.eval c v := by obtain ⟨i, h₁, hβ‚‚βŸ© := tr_init c v refine Part.ext fun x => ?_ rw [reaches_eval hβ‚‚.to_reflTransGen]; simp only [Part.map_eq_map, Part.mem_map_iff] refine ⟨fun h => ?_, ?_⟩ Β· obtain ⟨c, hc₁, hcβ‚‚βŸ© := tr_eval_rev tr_respects h₁ h simp [stepNormal_eval] at hcβ‚‚ obtain ⟨v', hv, rfl⟩ := hcβ‚‚ exact ⟨_, hv, hc₁.symm⟩ Β· rintro ⟨v', hv, rfl⟩ have := Turing.tr_eval (b₁ := Cfg.halt v') tr_respects h₁ simp only [stepNormal_eval, Part.map_eq_map, Part.mem_map_iff, Cfg.halt.injEq, exists_eq_right] at this obtain ⟨_, ⟨⟩, h⟩ := this hv exact h /-- The set of machine states reachable via downward label jumps, discounting jumps via `ret`. -/ def trStmts₁ : Ξ›' β†’ Finset Ξ›' | Q@(Ξ›'.move _ _ _ q) => insert Q <| trStmts₁ q | Q@(Ξ›'.push _ _ q) => insert Q <| trStmts₁ q | Q@(Ξ›'.read q) => insert Q <| Finset.univ.biUnion fun s => trStmts₁ (q s) | Q@(Ξ›'.clear _ _ q) => insert Q <| trStmts₁ q | Q@(Ξ›'.copy q) => insert Q <| trStmts₁ q | Q@(Ξ›'.succ q) => insert Q <| insert (unrev q) <| trStmts₁ q | Q@(Ξ›'.pred q₁ qβ‚‚) => insert Q <| trStmts₁ q₁ βˆͺ insert (unrev qβ‚‚) (trStmts₁ qβ‚‚) | Q@(Ξ›'.ret _) => {Q} theorem trStmts₁_trans {q q'} : q' ∈ trStmts₁ q β†’ trStmts₁ q' βŠ† trStmts₁ q := by induction q with | move _ _ _ q q_ih => _ | clear _ _ q q_ih => _ | copy q q_ih => _ | push _ _ q q_ih => _ | read q q_ih => _ | succ q q_ih => _ | pred q₁ qβ‚‚ q₁_ih qβ‚‚_ih => _ | ret => _ <;> all_goals simp +contextual only [trStmts₁, Finset.mem_insert, Finset.mem_union, or_imp, Finset.mem_singleton, Finset.Subset.refl, imp_true_iff, true_and] repeat exact fun h => Finset.Subset.trans (q_ih h) (Finset.subset_insert _ _) Β· simp intro s h x h' simp only [Finset.mem_biUnion, Finset.mem_univ, true_and, Finset.mem_insert] exact Or.inr ⟨_, q_ih s h h'⟩ Β· constructor Β· rintro rfl apply Finset.subset_insert Β· intro h x h' simp only [Finset.mem_insert] exact Or.inr (Or.inr <| q_ih h h') Β· refine ⟨fun h x h' => ?_, fun _ x h' => ?_, fun h x h' => ?_⟩ <;> simp Β· exact Or.inr (Or.inr <| Or.inl <| q₁_ih h h') Β· rcases Finset.mem_insert.1 h' with h' | h' <;> simp [h', unrev] Β· exact Or.inr (Or.inr <| Or.inr <| qβ‚‚_ih h h') theorem trStmts₁_self (q) : q ∈ trStmts₁ q := by induction q <;> Β· first |apply Finset.mem_singleton_self|apply Finset.mem_insert_self /-- The (finite!) set of machine states visited during the course of evaluation of `c`, including the state `ret k` but not any states after that (that is, the states visited while evaluating `k`). -/ def codeSupp' : Code β†’ Cont' β†’ Finset Ξ›' | c@Code.zero', k => trStmts₁ (trNormal c k) | c@Code.succ, k => trStmts₁ (trNormal c k) | c@Code.tail, k => trStmts₁ (trNormal c k) | c@(Code.cons f fs), k => trStmts₁ (trNormal c k) βˆͺ (codeSupp' f (Cont'.cons₁ fs k) βˆͺ (trStmts₁ (moveβ‚‚ (fun _ => false) main aux <| moveβ‚‚ (fun s => s = Ξ“'.consβ‚—) stack main <| moveβ‚‚ (fun _ => false) aux stack <| trNormal fs (Cont'.consβ‚‚ k)) βˆͺ (codeSupp' fs (Cont'.consβ‚‚ k) βˆͺ trStmts₁ (head stack <| Ξ›'.ret k)))) | c@(Code.comp f g), k => trStmts₁ (trNormal c k) βˆͺ (codeSupp' g (Cont'.comp f k) βˆͺ (trStmts₁ (trNormal f k) βˆͺ codeSupp' f k)) | c@(Code.case f g), k => trStmts₁ (trNormal c k) βˆͺ (codeSupp' f k βˆͺ codeSupp' g k) | c@(Code.fix f), k => trStmts₁ (trNormal c k) βˆͺ (codeSupp' f (Cont'.fix f k) βˆͺ (trStmts₁ (Ξ›'.clear natEnd main <| trNormal f (Cont'.fix f k)) βˆͺ {Ξ›'.ret k})) @[simp] theorem codeSupp'_self (c k) : trStmts₁ (trNormal c k) βŠ† codeSupp' c k := by cases c <;> first | rfl | exact Finset.union_subset_left (fun _ a ↦ a) /-- The (finite!) set of machine states visited during the course of evaluation of a continuation `k`, not including the initial state `ret k`. -/ def contSupp : Cont' β†’ Finset Ξ›' | Cont'.cons₁ fs k => trStmts₁ (moveβ‚‚ (fun _ => false) main aux <| moveβ‚‚ (fun s => s = Ξ“'.consβ‚—) stack main <| moveβ‚‚ (fun _ => false) aux stack <| trNormal fs (Cont'.consβ‚‚ k)) βˆͺ (codeSupp' fs (Cont'.consβ‚‚ k) βˆͺ (trStmts₁ (head stack <| Ξ›'.ret k) βˆͺ contSupp k)) | Cont'.consβ‚‚ k => trStmts₁ (head stack <| Ξ›'.ret k) βˆͺ contSupp k | Cont'.comp f k => codeSupp' f k βˆͺ contSupp k | Cont'.fix f k => codeSupp' (Code.fix f) k βˆͺ contSupp k | Cont'.halt => βˆ… /-- The (finite!) set of machine states visited during the course of evaluation of `c` in continuation `k`. This is actually closed under forward simulation (see `tr_supports`), and the existence of this set means that the machine constructed in this section is in fact a proper Turing machine, with a finite set of states. -/ def codeSupp (c : Code) (k : Cont') : Finset Ξ›' := codeSupp' c k βˆͺ contSupp k @[simp] theorem codeSupp_self (c k) : trStmts₁ (trNormal c k) βŠ† codeSupp c k := Finset.Subset.trans (codeSupp'_self _ _) (Finset.union_subset_left fun _ a ↦ a) @[simp] theorem codeSupp_zero (k) : codeSupp Code.zero' k = trStmts₁ (trNormal Code.zero' k) βˆͺ contSupp k := rfl @[simp] theorem codeSupp_succ (k) : codeSupp Code.succ k = trStmts₁ (trNormal Code.succ k) βˆͺ contSupp k := rfl @[simp] theorem codeSupp_tail (k) : codeSupp Code.tail k = trStmts₁ (trNormal Code.tail k) βˆͺ contSupp k := rfl @[simp] theorem codeSupp_cons (f fs k) : codeSupp (Code.cons f fs) k = trStmts₁ (trNormal (Code.cons f fs) k) βˆͺ codeSupp f (Cont'.cons₁ fs k) := by simp [codeSupp, codeSupp', contSupp, Finset.union_assoc] @[simp] theorem codeSupp_comp (f g k) : codeSupp (Code.comp f g) k = trStmts₁ (trNormal (Code.comp f g) k) βˆͺ codeSupp g (Cont'.comp f k) := by simp only [codeSupp, codeSupp', trNormal, Finset.union_assoc, contSupp] rw [← Finset.union_assoc _ _ (contSupp k), Finset.union_eq_right.2 (codeSupp'_self _ _)] @[simp] theorem codeSupp_case (f g k) : codeSupp (Code.case f g) k = trStmts₁ (trNormal (Code.case f g) k) βˆͺ (codeSupp f k βˆͺ codeSupp g k) := by simp [codeSupp, codeSupp', contSupp, Finset.union_assoc, Finset.union_left_comm] @[simp] theorem codeSupp_fix (f k) : codeSupp (Code.fix f) k = trStmts₁ (trNormal (Code.fix f) k) βˆͺ codeSupp f (Cont'.fix f k) := by simp [codeSupp, codeSupp', contSupp, Finset.union_assoc, Finset.union_left_comm, Finset.union_left_idem] @[simp] theorem contSupp_cons₁ (fs k) : contSupp (Cont'.cons₁ fs k) = trStmts₁ (moveβ‚‚ (fun _ => false) main aux <| moveβ‚‚ (fun s => s = Ξ“'.consβ‚—) stack main <| moveβ‚‚ (fun _ => false) aux stack <| trNormal fs (Cont'.consβ‚‚ k)) βˆͺ codeSupp fs (Cont'.consβ‚‚ k) := by simp [codeSupp, codeSupp', contSupp, Finset.union_assoc] @[simp] theorem contSupp_consβ‚‚ (k) : contSupp (Cont'.consβ‚‚ k) = trStmts₁ (head stack <| Ξ›'.ret k) βˆͺ contSupp k := rfl @[simp] theorem contSupp_comp (f k) : contSupp (Cont'.comp f k) = codeSupp f k := rfl theorem contSupp_fix (f k) : contSupp (Cont'.fix f k) = codeSupp f (Cont'.fix f k) := by simp +contextual [codeSupp, codeSupp', contSupp, Finset.union_assoc, Finset.subset_iff] @[simp] theorem contSupp_halt : contSupp Cont'.halt = βˆ… := rfl /-- The statement `Ξ›'.Supports S q` means that `contSupp k βŠ† S` for any `ret k` reachable from `q`. (This is a technical condition used in the proof that the machine is supported.) -/ def Ξ›'.Supports (S : Finset Ξ›') : Ξ›' β†’ Prop | Ξ›'.move _ _ _ q => Ξ›'.Supports S q | Ξ›'.push _ _ q => Ξ›'.Supports S q | Ξ›'.read q => βˆ€ s, Ξ›'.Supports S (q s) | Ξ›'.clear _ _ q => Ξ›'.Supports S q | Ξ›'.copy q => Ξ›'.Supports S q | Ξ›'.succ q => Ξ›'.Supports S q | Ξ›'.pred q₁ qβ‚‚ => Ξ›'.Supports S q₁ ∧ Ξ›'.Supports S qβ‚‚ | Ξ›'.ret k => contSupp k βŠ† S /-- A shorthand for the predicate that we are proving in the main theorems `trStmts₁_supports`, `codeSupp'_supports`, `contSupp_supports`, `codeSupp_supports`. The set `S` is fixed throughout the proof, and denotes the full set of states in the machine, while `K` is a subset that we are currently proving a property about. The predicate asserts that every state in `K` is closed in `S` under forward simulation, i.e. stepping forward through evaluation starting from any state in `K` stays entirely within `S`. -/ def Supports (K S : Finset Ξ›') := βˆ€ q ∈ K, TM2.SupportsStmt S (tr q) theorem supports_insert {K S q} : Supports (insert q K) S ↔ TM2.SupportsStmt S (tr q) ∧ Supports K S := by simp [Supports] theorem supports_singleton {S q} : Supports {q} S ↔ TM2.SupportsStmt S (tr q) := by simp [Supports] theorem supports_union {K₁ Kβ‚‚ S} : Supports (K₁ βˆͺ Kβ‚‚) S ↔ Supports K₁ S ∧ Supports Kβ‚‚ S := by simp [Supports, or_imp, forall_and] theorem supports_biUnion {K : Option Ξ“' β†’ Finset Ξ›'} {S} : Supports (Finset.univ.biUnion K) S ↔ βˆ€ a, Supports (K a) S := by simpa [Supports] using forall_swap theorem head_supports {S k q} (H : (q : Ξ›').Supports S) : (head k q).Supports S := fun _ => by dsimp only; split_ifs <;> exact H theorem ret_supports {S k} (H₁ : contSupp k βŠ† S) : TM2.SupportsStmt S (tr (Ξ›'.ret k)) := by have W := fun {q} => trStmts₁_self q cases k with | halt => trivial | cons₁ => rw [contSupp_cons₁, Finset.union_subset_iff] at H₁; exact fun _ => H₁.1 W | consβ‚‚ => rw [contSupp_consβ‚‚, Finset.union_subset_iff] at H₁; exact fun _ => H₁.1 W | comp => rw [contSupp_comp] at H₁; exact fun _ => H₁ (codeSupp_self _ _ W) | fix => rw [contSupp_fix] at H₁ have L := @Finset.mem_union_left; have R := @Finset.mem_union_right intro s; dsimp only; cases natEnd s.iget Β· refine H₁ (R _ <| L _ <| R _ <| R _ <| L _ W) Β· exact H₁ (R _ <| L _ <| R _ <| R _ <| R _ <| Finset.mem_singleton_self _) theorem trStmts₁_supports {S q} (H₁ : (q : Ξ›').Supports S) (HS₁ : trStmts₁ q βŠ† S) : Supports (trStmts₁ q) S := by have W := fun {q} => trStmts₁_self q induction q with | move _ _ _ q q_ih => _ | clear _ _ q q_ih => _ | copy q q_ih => _ | push _ _ q q_ih => _ | read q q_ih => _ | succ q q_ih => _ | pred q₁ qβ‚‚ q₁_ih qβ‚‚_ih => _ | ret => _ <;> simp [trStmts₁, -Finset.singleton_subset_iff] at HS₁ ⊒ any_goals obtain ⟨h₁, hβ‚‚βŸ© := Finset.insert_subset_iff.1 HS₁ first | have h₃ := hβ‚‚ W | try simp [Finset.subset_iff] at hβ‚‚ Β· exact supports_insert.2 ⟨⟨fun _ => h₃, fun _ => hβ‚βŸ©, q_ih H₁ hβ‚‚βŸ© -- move Β· exact supports_insert.2 ⟨⟨fun _ => h₃, fun _ => hβ‚βŸ©, q_ih H₁ hβ‚‚βŸ© -- clear Β· exact supports_insert.2 ⟨⟨fun _ => h₁, fun _ => hβ‚ƒβŸ©, q_ih H₁ hβ‚‚βŸ© -- copy Β· exact supports_insert.2 ⟨⟨fun _ => h₃, fun _ => hβ‚ƒβŸ©, q_ih H₁ hβ‚‚βŸ© -- push Β· refine supports_insert.2 ⟨fun _ => hβ‚‚ _ W, ?_⟩ -- read exact supports_biUnion.2 fun _ => q_ih _ (H₁ _) fun _ h => hβ‚‚ _ h Β· refine supports_insert.2 ⟨⟨fun _ => h₁, fun _ => hβ‚‚.1, fun _ => hβ‚‚.1⟩, ?_⟩ -- succ exact supports_insert.2 ⟨⟨fun _ => hβ‚‚.2 _ W, fun _ => hβ‚‚.1⟩, q_ih H₁ hβ‚‚.2⟩ Β· refine -- pred supports_insert.2 ⟨⟨fun _ => h₁, fun _ => hβ‚‚.2 _ (Or.inl W), fun _ => hβ‚‚.1, fun _ => hβ‚‚.1⟩, ?_⟩ refine supports_insert.2 ⟨⟨fun _ => hβ‚‚.2 _ (Or.inr W), fun _ => hβ‚‚.1⟩, ?_⟩ refine supports_union.2 ⟨?_, ?_⟩ Β· exact q₁_ih H₁.1 fun _ h => hβ‚‚.2 _ (Or.inl h) Β· exact qβ‚‚_ih H₁.2 fun _ h => hβ‚‚.2 _ (Or.inr h) Β· exact supports_singleton.2 (ret_supports H₁) -- ret theorem trStmts₁_supports' {S q K} (H₁ : (q : Ξ›').Supports S) (Hβ‚‚ : trStmts₁ q βˆͺ K βŠ† S) (H₃ : K βŠ† S β†’ Supports K S) : Supports (trStmts₁ q βˆͺ K) S := by simp only [Finset.union_subset_iff] at Hβ‚‚ exact supports_union.2 ⟨trStmts₁_supports H₁ Hβ‚‚.1, H₃ Hβ‚‚.2⟩ theorem trNormal_supports {S c k} (Hk : codeSupp c k βŠ† S) : (trNormal c k).Supports S := by induction c generalizing k with simp [Ξ›'.Supports, head] | zero' => exact Finset.union_subset_right Hk | succ => intro; split_ifs <;> exact Finset.union_subset_right Hk | tail => exact Finset.union_subset_right Hk | cons f fs IHf _ => apply IHf rw [codeSupp_cons] at Hk exact Finset.union_subset_right Hk | comp f g _ IHg => apply IHg; rw [codeSupp_comp] at Hk; exact Finset.union_subset_right Hk | case f g IHf IHg => simp only [codeSupp_case, Finset.union_subset_iff] at Hk exact ⟨IHf Hk.2.1, IHg Hk.2.2⟩ | fix f IHf => apply IHf; rw [codeSupp_fix] at Hk; exact Finset.union_subset_right Hk theorem codeSupp'_supports {S c k} (H : codeSupp c k βŠ† S) : Supports (codeSupp' c k) S := by induction c generalizing k with | cons f fs IHf IHfs => have H' := H; simp only [codeSupp_cons, Finset.union_subset_iff] at H' refine trStmts₁_supports' (trNormal_supports H) (Finset.union_subset_left H) fun h => ?_ refine supports_union.2 ⟨IHf H'.2, ?_⟩ refine trStmts₁_supports' (trNormal_supports ?_) (Finset.union_subset_right h) fun h => ?_ Β· simp only [codeSupp, Finset.union_subset_iff, contSupp] at h H ⊒ exact ⟨h.2.2.1, h.2.2.2, H.2⟩ refine supports_union.2 ⟨IHfs ?_, ?_⟩ Β· rw [codeSupp, contSupp_cons₁] at H' exact Finset.union_subset_right (Finset.union_subset_right H'.2) exact trStmts₁_supports (head_supports <| Finset.union_subset_right H) (Finset.union_subset_right h) | comp f g IHf IHg => have H' := H; rw [codeSupp_comp] at H'; have H' := Finset.union_subset_right H' refine trStmts₁_supports' (trNormal_supports H) (Finset.union_subset_left H) fun h => ?_ refine supports_union.2 ⟨IHg H', ?_⟩ refine trStmts₁_supports' (trNormal_supports ?_) (Finset.union_subset_right h) fun _ => ?_ Β· simp only [codeSupp', codeSupp, Finset.union_subset_iff, contSupp] at h H ⊒ exact ⟨h.2.2, H.2⟩ exact IHf (Finset.union_subset_right H') | case f g IHf IHg => have H' := H; simp only [codeSupp_case, Finset.union_subset_iff] at H' refine trStmts₁_supports' (trNormal_supports H) (Finset.union_subset_left H) fun _ => ?_ exact supports_union.2 ⟨IHf H'.2.1, IHg H'.2.2⟩ | fix f IHf => have H' := H; simp only [codeSupp_fix, Finset.union_subset_iff] at H' refine trStmts₁_supports' (trNormal_supports H) (Finset.union_subset_left H) fun h => ?_ refine supports_union.2 ⟨IHf H'.2, ?_⟩ refine trStmts₁_supports' (trNormal_supports ?_) (Finset.union_subset_right h) fun _ => ?_ Β· simp only [codeSupp', codeSupp, Finset.union_subset_iff, contSupp, trStmts₁, Finset.insert_subset_iff] at h H ⊒ exact ⟨h.1, ⟨H.1.1, h⟩, H.2⟩ exact supports_singleton.2 (ret_supports <| Finset.union_subset_right H) | _ => exact trStmts₁_supports (trNormal_supports H) (Finset.Subset.trans (codeSupp_self _ _) H) theorem contSupp_supports {S k} (H : contSupp k βŠ† S) : Supports (contSupp k) S := by induction k with | halt => simp [contSupp_halt, Supports] | cons₁ f k IH => have H₁ := H; rw [contSupp_cons₁] at H₁; have Hβ‚‚ := Finset.union_subset_right H₁ refine trStmts₁_supports' (trNormal_supports Hβ‚‚) H₁ fun h => ?_ refine supports_union.2 ⟨codeSupp'_supports Hβ‚‚, ?_⟩ simp only [codeSupp, contSupp_consβ‚‚, Finset.union_subset_iff] at Hβ‚‚ exact trStmts₁_supports' (head_supports Hβ‚‚.2.2) (Finset.union_subset_right h) IH | consβ‚‚ k IH => have H' := H; rw [contSupp_consβ‚‚] at H' exact trStmts₁_supports' (head_supports <| Finset.union_subset_right H') H' IH | comp f k IH => have H' := H; rw [contSupp_comp] at H'; have Hβ‚‚ := Finset.union_subset_right H' exact supports_union.2 ⟨codeSupp'_supports H', IH Hβ‚‚βŸ© | fix f k IH => rw [contSupp] at H exact supports_union.2 ⟨codeSupp'_supports H, IH (Finset.union_subset_right H)⟩ theorem codeSupp_supports {S c k} (H : codeSupp c k βŠ† S) : Supports (codeSupp c k) S := supports_union.2 ⟨codeSupp'_supports H, contSupp_supports (Finset.union_subset_right H)⟩ /-- The set `codeSupp c k` is a finite set that witnesses the effective finiteness of the `tr` Turing machine. Starting from the initial state `trNormal c k`, forward simulation uses only states in `codeSupp c k`, so this is a finite state machine. Even though the underlying type of state labels `Ξ›'` is infinite, for a given partial recursive function `c` and continuation `k`, only finitely many states are accessed, corresponding roughly to subterms of `c`. -/ theorem tr_supports (c k) : @TM2.Supports _ _ _ _ ⟨trNormal c k⟩ tr (codeSupp c k) := ⟨codeSupp_self _ _ (trStmts₁_self _), fun _ => codeSupp_supports (Finset.Subset.refl _) _⟩ end end PartrecToTM2 end Turing
Mathlib/Computability/TMToPartrec.lean
1,510
1,542
/- 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 -/ import Mathlib.Topology.UniformSpace.Cauchy /-! # Uniform convergence A sequence of functions `Fβ‚™` (with values in a metric space) converges uniformly on a set `s` to a function `f` if, for all `Ξ΅ > 0`, for all large enough `n`, one has for all `y ∈ s` the inequality `dist (f y, Fβ‚™ y) < Ξ΅`. Under uniform convergence, many properties of the `Fβ‚™` pass to the limit, most notably continuity. We prove this in the file, defining the notion of uniform convergence in the more general setting of uniform spaces, and with respect to an arbitrary indexing set endowed with a filter (instead of just `β„•` with `atTop`). ## Main results Let `Ξ±` be a topological space, `Ξ²` a uniform space, `Fβ‚™` and `f` be functions from `Ξ±` to `Ξ²` (where the index `n` belongs to an indexing type `ΞΉ` endowed with a filter `p`). * `TendstoUniformlyOn F f p s`: the fact that `Fβ‚™` converges uniformly to `f` on `s`. This means that, for any entourage `u` of the diagonal, for large enough `n` (with respect to `p`), one has `(f y, Fβ‚™ y) ∈ u` for all `y ∈ s`. * `TendstoUniformly F f p`: same notion with `s = univ`. * `TendstoUniformlyOn.continuousOn`: a uniform limit on a set of functions which are continuous on this set is itself continuous on this set. * `TendstoUniformly.continuous`: a uniform limit of continuous functions is continuous. * `TendstoUniformlyOn.tendsto_comp`: If `Fβ‚™` tends uniformly to `f` on a set `s`, and `gβ‚™` tends to `x` within `s`, then `Fβ‚™ gβ‚™` tends to `f x` if `f` is continuous at `x` within `s`. * `TendstoUniformly.tendsto_comp`: If `Fβ‚™` tends uniformly to `f`, and `gβ‚™` tends to `x`, then `Fβ‚™ gβ‚™` tends to `f x`. Finally, we introduce the notion of a uniform Cauchy sequence, which is to uniform convergence what a Cauchy sequence is to the usual notion of convergence. ## Implementation notes We derive most of our initial results from an auxiliary definition `TendstoUniformlyOnFilter`. This definition in and of itself can sometimes be useful, e.g., when studying the local behavior of the `Fβ‚™` near a point, which would typically look like `TendstoUniformlyOnFilter F f p (𝓝 x)`. Still, while this may be the "correct" definition (see `tendstoUniformlyOn_iff_tendstoUniformlyOnFilter`), it is somewhat unwieldy to work with in practice. Thus, we provide the more traditional definition in `TendstoUniformlyOn`. ## Tags Uniform limit, uniform convergence, tends uniformly to -/ noncomputable section open Topology Uniformity Filter Set Uniform variable {Ξ± Ξ² Ξ³ ΞΉ : Type*} [UniformSpace Ξ²] variable {F : ΞΉ β†’ Ξ± β†’ Ξ²} {f : Ξ± β†’ Ξ²} {s s' : Set Ξ±} {x : Ξ±} {p : Filter ΞΉ} {p' : Filter Ξ±} /-! ### Different notions of uniform convergence We define uniform convergence, on a set or in the whole space. -/ /-- A sequence of functions `Fβ‚™` converges uniformly on a filter `p'` to a limiting function `f` with respect to the filter `p` if, for any entourage of the diagonal `u`, one has `p Γ—Λ’ p'`-eventually `(f x, Fβ‚™ x) ∈ u`. -/ def TendstoUniformlyOnFilter (F : ΞΉ β†’ Ξ± β†’ Ξ²) (f : Ξ± β†’ Ξ²) (p : Filter ΞΉ) (p' : Filter Ξ±) := βˆ€ u ∈ 𝓀 Ξ², βˆ€αΆ  n : ΞΉ Γ— Ξ± in p Γ—Λ’ p', (f n.snd, F n.fst n.snd) ∈ u /-- A sequence of functions `Fβ‚™` converges uniformly on a filter `p'` to a limiting function `f` w.r.t. filter `p` iff the function `(n, x) ↦ (f x, Fβ‚™ x)` converges along `p Γ—Λ’ p'` to the uniformity. In other words: one knows nothing about the behavior of `x` in this limit besides it being in `p'`. -/ theorem tendstoUniformlyOnFilter_iff_tendsto : TendstoUniformlyOnFilter F f p p' ↔ Tendsto (fun q : ΞΉ Γ— Ξ± => (f q.2, F q.1 q.2)) (p Γ—Λ’ p') (𝓀 Ξ²) := Iff.rfl /-- A sequence of functions `Fβ‚™` converges uniformly on a set `s` to a limiting function `f` with respect to the filter `p` if, for any entourage of the diagonal `u`, one has `p`-eventually `(f x, Fβ‚™ x) ∈ u` for all `x ∈ s`. -/ def TendstoUniformlyOn (F : ΞΉ β†’ Ξ± β†’ Ξ²) (f : Ξ± β†’ Ξ²) (p : Filter ΞΉ) (s : Set Ξ±) := βˆ€ u ∈ 𝓀 Ξ², βˆ€αΆ  n in p, βˆ€ x : Ξ±, x ∈ s β†’ (f x, F n x) ∈ u theorem tendstoUniformlyOn_iff_tendstoUniformlyOnFilter : TendstoUniformlyOn F f p s ↔ TendstoUniformlyOnFilter F f p (π“Ÿ s) := by simp only [TendstoUniformlyOn, TendstoUniformlyOnFilter] apply forallβ‚‚_congr simp_rw [eventually_prod_principal_iff] simp alias ⟨TendstoUniformlyOn.tendstoUniformlyOnFilter, TendstoUniformlyOnFilter.tendstoUniformlyOn⟩ := tendstoUniformlyOn_iff_tendstoUniformlyOnFilter /-- A sequence of functions `Fβ‚™` converges uniformly on a set `s` to a limiting function `f` w.r.t. filter `p` iff the function `(n, x) ↦ (f x, Fβ‚™ x)` converges along `p Γ—Λ’ π“Ÿ s` to the uniformity. In other words: one knows nothing about the behavior of `x` in this limit besides it being in `s`. -/ theorem tendstoUniformlyOn_iff_tendsto : TendstoUniformlyOn F f p s ↔ Tendsto (fun q : ΞΉ Γ— Ξ± => (f q.2, F q.1 q.2)) (p Γ—Λ’ π“Ÿ s) (𝓀 Ξ²) := by simp [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter, tendstoUniformlyOnFilter_iff_tendsto] /-- A sequence of functions `Fβ‚™` converges uniformly to a limiting function `f` with respect to a filter `p` if, for any entourage of the diagonal `u`, one has `p`-eventually `(f x, Fβ‚™ x) ∈ u` for all `x`. -/ def TendstoUniformly (F : ΞΉ β†’ Ξ± β†’ Ξ²) (f : Ξ± β†’ Ξ²) (p : Filter ΞΉ) := βˆ€ u ∈ 𝓀 Ξ², βˆ€αΆ  n in p, βˆ€ x : Ξ±, (f x, F n x) ∈ u theorem tendstoUniformlyOn_univ : TendstoUniformlyOn F f p univ ↔ TendstoUniformly F f p := by simp [TendstoUniformlyOn, TendstoUniformly] theorem tendstoUniformly_iff_tendstoUniformlyOnFilter : TendstoUniformly F f p ↔ TendstoUniformlyOnFilter F f p ⊀ := by rw [← tendstoUniformlyOn_univ, tendstoUniformlyOn_iff_tendstoUniformlyOnFilter, principal_univ] theorem TendstoUniformly.tendstoUniformlyOnFilter (h : TendstoUniformly F f p) : TendstoUniformlyOnFilter F f p ⊀ := by rwa [← tendstoUniformly_iff_tendstoUniformlyOnFilter] theorem tendstoUniformlyOn_iff_tendstoUniformly_comp_coe : TendstoUniformlyOn F f p s ↔ TendstoUniformly (fun i (x : s) => F i x) (f ∘ (↑)) p := forallβ‚‚_congr fun u _ => by simp /-- A sequence of functions `Fβ‚™` converges uniformly to a limiting function `f` w.r.t. filter `p` iff the function `(n, x) ↦ (f x, Fβ‚™ x)` converges along `p Γ—Λ’ ⊀` to the uniformity. In other words: one knows nothing about the behavior of `x` in this limit. -/ theorem tendstoUniformly_iff_tendsto : TendstoUniformly F f p ↔ Tendsto (fun q : ΞΉ Γ— Ξ± => (f q.2, F q.1 q.2)) (p Γ—Λ’ ⊀) (𝓀 Ξ²) := by simp [tendstoUniformly_iff_tendstoUniformlyOnFilter, tendstoUniformlyOnFilter_iff_tendsto] /-- Uniform convergence implies pointwise convergence. -/ theorem TendstoUniformlyOnFilter.tendsto_at (h : TendstoUniformlyOnFilter F f p p') (hx : π“Ÿ {x} ≀ p') : Tendsto (fun n => F n x) p <| 𝓝 (f x) := by refine Uniform.tendsto_nhds_right.mpr fun u hu => mem_map.mpr ?_ filter_upwards [(h u hu).curry] intro i h simpa using h.filter_mono hx /-- Uniform convergence implies pointwise convergence. -/ theorem TendstoUniformlyOn.tendsto_at (h : TendstoUniformlyOn F f p s) (hx : x ∈ s) : Tendsto (fun n => F n x) p <| 𝓝 (f x) := h.tendstoUniformlyOnFilter.tendsto_at (le_principal_iff.mpr <| mem_principal.mpr <| singleton_subset_iff.mpr <| hx) /-- Uniform convergence implies pointwise convergence. -/ theorem TendstoUniformly.tendsto_at (h : TendstoUniformly F f p) (x : Ξ±) : Tendsto (fun n => F n x) p <| 𝓝 (f x) := h.tendstoUniformlyOnFilter.tendsto_at le_top theorem TendstoUniformlyOnFilter.mono_left {p'' : Filter ΞΉ} (h : TendstoUniformlyOnFilter F f p p') (hp : p'' ≀ p) : TendstoUniformlyOnFilter F f p'' p' := fun u hu => (h u hu).filter_mono (p'.prod_mono_left hp) theorem TendstoUniformlyOnFilter.mono_right {p'' : Filter Ξ±} (h : TendstoUniformlyOnFilter F f p p') (hp : p'' ≀ p') : TendstoUniformlyOnFilter F f p p'' := fun u hu => (h u hu).filter_mono (p.prod_mono_right hp) theorem TendstoUniformlyOn.mono (h : TendstoUniformlyOn F f p s) (h' : s' βŠ† s) : TendstoUniformlyOn F f p s' := tendstoUniformlyOn_iff_tendstoUniformlyOnFilter.mpr (h.tendstoUniformlyOnFilter.mono_right (le_principal_iff.mpr <| mem_principal.mpr h')) theorem TendstoUniformlyOnFilter.congr {F' : ΞΉ β†’ Ξ± β†’ Ξ²} (hf : TendstoUniformlyOnFilter F f p p') (hff' : βˆ€αΆ  n : ΞΉ Γ— Ξ± in p Γ—Λ’ p', F n.fst n.snd = F' n.fst n.snd) : TendstoUniformlyOnFilter F' f p p' := by refine fun u hu => ((hf u hu).and hff').mono fun n h => ?_ rw [← h.right] exact h.left theorem TendstoUniformlyOn.congr {F' : ΞΉ β†’ Ξ± β†’ Ξ²} (hf : TendstoUniformlyOn F f p s) (hff' : βˆ€αΆ  n in p, Set.EqOn (F n) (F' n) s) : TendstoUniformlyOn F' f p s := by rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter] at hf ⊒ refine hf.congr ?_ rw [eventually_iff] at hff' ⊒ simp only [Set.EqOn] at hff' simp only [mem_prod_principal, hff', mem_setOf_eq] lemma tendstoUniformly_congr {F' : ΞΉ β†’ Ξ± β†’ Ξ²} (hF : F =αΆ [p] F') : TendstoUniformly F f p ↔ TendstoUniformly F' f p := by simp_rw [← tendstoUniformlyOn_univ] at * have HF := EventuallyEq.exists_mem hF exact ⟨fun h => h.congr (by aesop), fun h => h.congr (by simp_rw [eqOn_comm]; aesop)⟩ theorem TendstoUniformlyOn.congr_right {g : Ξ± β†’ Ξ²} (hf : TendstoUniformlyOn F f p s) (hfg : EqOn f g s) : TendstoUniformlyOn F g p s := fun u hu => by filter_upwards [hf u hu] with i hi a ha using hfg ha β–Έ hi a ha protected theorem TendstoUniformly.tendstoUniformlyOn (h : TendstoUniformly F f p) : TendstoUniformlyOn F f p s := (tendstoUniformlyOn_univ.2 h).mono (subset_univ s) /-- Composing on the right by a function preserves uniform convergence on a filter -/ theorem TendstoUniformlyOnFilter.comp (h : TendstoUniformlyOnFilter F f p p') (g : Ξ³ β†’ Ξ±) : TendstoUniformlyOnFilter (fun n => F n ∘ g) (f ∘ g) p (p'.comap g) := by rw [tendstoUniformlyOnFilter_iff_tendsto] at h ⊒ exact h.comp (tendsto_id.prodMap tendsto_comap) /-- Composing on the right by a function preserves uniform convergence on a set -/ theorem TendstoUniformlyOn.comp (h : TendstoUniformlyOn F f p s) (g : Ξ³ β†’ Ξ±) : TendstoUniformlyOn (fun n => F n ∘ g) (f ∘ g) p (g ⁻¹' s) := by rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter] at h ⊒ simpa [TendstoUniformlyOn, comap_principal] using TendstoUniformlyOnFilter.comp h g /-- Composing on the right by a function preserves uniform convergence -/ theorem TendstoUniformly.comp (h : TendstoUniformly F f p) (g : Ξ³ β†’ Ξ±) : TendstoUniformly (fun n => F n ∘ g) (f ∘ g) p := by rw [tendstoUniformly_iff_tendstoUniformlyOnFilter] at h ⊒ simpa [principal_univ, comap_principal] using h.comp g /-- Composing on the left by a uniformly continuous function preserves uniform convergence on a filter -/ theorem UniformContinuous.comp_tendstoUniformlyOnFilter [UniformSpace Ξ³] {g : Ξ² β†’ Ξ³} (hg : UniformContinuous g) (h : TendstoUniformlyOnFilter F f p p') : TendstoUniformlyOnFilter (fun i => g ∘ F i) (g ∘ f) p p' := fun _u hu => h _ (hg hu) /-- Composing on the left by a uniformly continuous function preserves uniform convergence on a set -/ theorem UniformContinuous.comp_tendstoUniformlyOn [UniformSpace Ξ³] {g : Ξ² β†’ Ξ³} (hg : UniformContinuous g) (h : TendstoUniformlyOn F f p s) : TendstoUniformlyOn (fun i => g ∘ F i) (g ∘ f) p s := fun _u hu => h _ (hg hu) /-- Composing on the left by a uniformly continuous function preserves uniform convergence -/ theorem UniformContinuous.comp_tendstoUniformly [UniformSpace Ξ³] {g : Ξ² β†’ Ξ³} (hg : UniformContinuous g) (h : TendstoUniformly F f p) : TendstoUniformly (fun i => g ∘ F i) (g ∘ f) p := fun _u hu => h _ (hg hu) theorem TendstoUniformlyOnFilter.prodMap {ΞΉ' Ξ±' Ξ²' : Type*} [UniformSpace Ξ²'] {F' : ΞΉ' β†’ Ξ±' β†’ Ξ²'} {f' : Ξ±' β†’ Ξ²'} {q : Filter ΞΉ'} {q' : Filter Ξ±'} (h : TendstoUniformlyOnFilter F f p p') (h' : TendstoUniformlyOnFilter F' f' q q') : TendstoUniformlyOnFilter (fun i : ΞΉ Γ— ΞΉ' => Prod.map (F i.1) (F' i.2)) (Prod.map f f') (p Γ—Λ’ q) (p' Γ—Λ’ q') := by rw [tendstoUniformlyOnFilter_iff_tendsto] at h h' ⊒ rw [uniformity_prod_eq_comap_prod, tendsto_comap_iff, ← map_swap4_prod, tendsto_map'_iff] simpa using h.prodMap h' @[deprecated (since := "2025-03-10")] alias TendstoUniformlyOnFilter.prod_map := TendstoUniformlyOnFilter.prodMap theorem TendstoUniformlyOn.prodMap {ΞΉ' Ξ±' Ξ²' : Type*} [UniformSpace Ξ²'] {F' : ΞΉ' β†’ Ξ±' β†’ Ξ²'} {f' : Ξ±' β†’ Ξ²'} {p' : Filter ΞΉ'} {s' : Set Ξ±'} (h : TendstoUniformlyOn F f p s) (h' : TendstoUniformlyOn F' f' p' s') : TendstoUniformlyOn (fun i : ΞΉ Γ— ΞΉ' => Prod.map (F i.1) (F' i.2)) (Prod.map f f') (p Γ—Λ’ p') (s Γ—Λ’ s') := by rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter] at h h' ⊒ simpa only [prod_principal_principal] using h.prodMap h' @[deprecated (since := "2025-03-10")] alias TendstoUniformlyOn.prod_map := TendstoUniformlyOn.prodMap theorem TendstoUniformly.prodMap {ΞΉ' Ξ±' Ξ²' : Type*} [UniformSpace Ξ²'] {F' : ΞΉ' β†’ Ξ±' β†’ Ξ²'} {f' : Ξ±' β†’ Ξ²'} {p' : Filter ΞΉ'} (h : TendstoUniformly F f p) (h' : TendstoUniformly F' f' p') : TendstoUniformly (fun i : ΞΉ Γ— ΞΉ' => Prod.map (F i.1) (F' i.2)) (Prod.map f f') (p Γ—Λ’ p') := by rw [← tendstoUniformlyOn_univ, ← univ_prod_univ] at * exact h.prodMap h' @[deprecated (since := "2025-03-10")] alias TendstoUniformly.prod_map := TendstoUniformly.prodMap theorem TendstoUniformlyOnFilter.prodMk {ΞΉ' Ξ²' : Type*} [UniformSpace Ξ²'] {F' : ΞΉ' β†’ Ξ± β†’ Ξ²'} {f' : Ξ± β†’ Ξ²'} {q : Filter ΞΉ'} (h : TendstoUniformlyOnFilter F f p p') (h' : TendstoUniformlyOnFilter F' f' q p') : TendstoUniformlyOnFilter (fun (i : ΞΉ Γ— ΞΉ') a => (F i.1 a, F' i.2 a)) (fun a => (f a, f' a)) (p Γ—Λ’ q) p' := fun u hu => ((h.prodMap h') u hu).diag_of_prod_right @[deprecated (since := "2025-03-10")] alias TendstoUniformlyOnFilter.prod := TendstoUniformlyOnFilter.prodMk protected theorem TendstoUniformlyOn.prodMk {ΞΉ' Ξ²' : Type*} [UniformSpace Ξ²'] {F' : ΞΉ' β†’ Ξ± β†’ Ξ²'} {f' : Ξ± β†’ Ξ²'} {p' : Filter ΞΉ'} (h : TendstoUniformlyOn F f p s) (h' : TendstoUniformlyOn F' f' p' s) : TendstoUniformlyOn (fun (i : ΞΉ Γ— ΞΉ') a => (F i.1 a, F' i.2 a)) (fun a => (f a, f' a)) (p Γ—Λ’ p') s := (congr_arg _ s.inter_self).mp ((h.prodMap h').comp fun a => (a, a)) @[deprecated (since := "2025-03-10")] alias TendstoUniformlyOn.prod := TendstoUniformlyOn.prodMk theorem TendstoUniformly.prodMk {ΞΉ' Ξ²' : Type*} [UniformSpace Ξ²'] {F' : ΞΉ' β†’ Ξ± β†’ Ξ²'} {f' : Ξ± β†’ Ξ²'} {p' : Filter ΞΉ'} (h : TendstoUniformly F f p) (h' : TendstoUniformly F' f' p') : TendstoUniformly (fun (i : ΞΉ Γ— ΞΉ') a => (F i.1 a, F' i.2 a)) (fun a => (f a, f' a)) (p Γ—Λ’ p') := (h.prodMap h').comp fun a => (a, a) @[deprecated (since := "2025-03-10")] alias TendstoUniformly.prod := TendstoUniformly.prodMk /-- Uniform convergence on a filter `p'` to a constant function is equivalent to convergence in `p Γ—Λ’ p'`. -/ theorem tendsto_prod_filter_iff {c : Ξ²} : Tendsto (β†ΏF) (p Γ—Λ’ p') (𝓝 c) ↔ TendstoUniformlyOnFilter F (fun _ => c) p p' := by simp_rw [nhds_eq_comap_uniformity, tendsto_comap_iff] rfl /-- Uniform convergence on a set `s` to a constant function is equivalent to convergence in `p Γ—Λ’ π“Ÿ s`. -/ theorem tendsto_prod_principal_iff {c : Ξ²} : Tendsto (β†ΏF) (p Γ—Λ’ π“Ÿ s) (𝓝 c) ↔ TendstoUniformlyOn F (fun _ => c) p s := by rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter] exact tendsto_prod_filter_iff /-- Uniform convergence to a constant function is equivalent to convergence in `p Γ—Λ’ ⊀`. -/ theorem tendsto_prod_top_iff {c : Ξ²} : Tendsto (β†ΏF) (p Γ—Λ’ ⊀) (𝓝 c) ↔ TendstoUniformly F (fun _ => c) p := by rw [tendstoUniformly_iff_tendstoUniformlyOnFilter] exact tendsto_prod_filter_iff /-- Uniform convergence on the empty set is vacuously true -/ theorem tendstoUniformlyOn_empty : TendstoUniformlyOn F f p βˆ… := fun u _ => by simp /-- Uniform convergence on a singleton is equivalent to regular convergence -/ theorem tendstoUniformlyOn_singleton_iff_tendsto : TendstoUniformlyOn F f p {x} ↔ Tendsto (fun n : ΞΉ => F n x) p (𝓝 (f x)) := by simp_rw [tendstoUniformlyOn_iff_tendsto, Uniform.tendsto_nhds_right, tendsto_def] exact forallβ‚‚_congr fun u _ => by simp [mem_prod_principal, preimage] /-- If a sequence `g` converges to some `b`, then the sequence of constant functions `fun n ↦ fun a ↦ g n` converges to the constant function `fun a ↦ b` on any set `s` -/ theorem Filter.Tendsto.tendstoUniformlyOnFilter_const {g : ΞΉ β†’ Ξ²} {b : Ξ²} (hg : Tendsto g p (𝓝 b)) (p' : Filter Ξ±) : TendstoUniformlyOnFilter (fun n : ΞΉ => fun _ : Ξ± => g n) (fun _ : Ξ± => b) p p' := by simpa only [nhds_eq_comap_uniformity, tendsto_comap_iff] using hg.comp (tendsto_fst (g := p')) /-- If a sequence `g` converges to some `b`, then the sequence of constant functions `fun n ↦ fun a ↦ g n` converges to the constant function `fun a ↦ b` on any set `s` -/ theorem Filter.Tendsto.tendstoUniformlyOn_const {g : ΞΉ β†’ Ξ²} {b : Ξ²} (hg : Tendsto g p (𝓝 b)) (s : Set Ξ±) : TendstoUniformlyOn (fun n : ΞΉ => fun _ : Ξ± => g n) (fun _ : Ξ± => b) p s := tendstoUniformlyOn_iff_tendstoUniformlyOnFilter.mpr (hg.tendstoUniformlyOnFilter_const (π“Ÿ s)) theorem UniformContinuousOn.tendstoUniformlyOn [UniformSpace Ξ±] [UniformSpace Ξ³] {U : Set Ξ±} {V : Set Ξ²} {F : Ξ± β†’ Ξ² β†’ Ξ³} (hF : UniformContinuousOn (β†ΏF) (U Γ—Λ’ V)) (hU : x ∈ U) : TendstoUniformlyOn F (F x) (𝓝[U] x) V := by set Ο† := fun q : Ξ± Γ— Ξ² => ((x, q.2), q) rw [tendstoUniformlyOn_iff_tendsto] change Tendsto (Prod.map (β†ΏF) β†ΏF ∘ Ο†) (𝓝[U] x Γ—Λ’ π“Ÿ V) (𝓀 Ξ³) simp only [nhdsWithin, Filter.prod_eq_inf, comap_inf, inf_assoc, comap_principal, inf_principal] refine hF.comp (Tendsto.inf ?_ <| tendsto_principal_principal.2 fun x hx => ⟨⟨hU, hx.2⟩, hx⟩) simp only [uniformity_prod_eq_comap_prod, tendsto_comap_iff, (Β· ∘ Β·), nhds_eq_comap_uniformity, comap_comap] exact tendsto_comap.prodMk (tendsto_diag_uniformity _ _) theorem UniformContinuousOn.tendstoUniformly [UniformSpace Ξ±] [UniformSpace Ξ³] {U : Set Ξ±} (hU : U ∈ 𝓝 x) {F : Ξ± β†’ Ξ² β†’ Ξ³} (hF : UniformContinuousOn (β†ΏF) (U Γ—Λ’ (univ : Set Ξ²))) : TendstoUniformly F (F x) (𝓝 x) := by simpa only [tendstoUniformlyOn_univ, nhdsWithin_eq_nhds.2 hU] using hF.tendstoUniformlyOn (mem_of_mem_nhds hU) theorem UniformContinuousβ‚‚.tendstoUniformly [UniformSpace Ξ±] [UniformSpace Ξ³] {f : Ξ± β†’ Ξ² β†’ Ξ³} (h : UniformContinuousβ‚‚ f) : TendstoUniformly f (f x) (𝓝 x) := UniformContinuousOn.tendstoUniformly univ_mem <| by rwa [univ_prod_univ, uniformContinuousOn_univ] /-- A sequence is uniformly Cauchy if eventually all of its pairwise differences are uniformly bounded -/ def UniformCauchySeqOnFilter (F : ΞΉ β†’ Ξ± β†’ Ξ²) (p : Filter ΞΉ) (p' : Filter Ξ±) : Prop := βˆ€ u ∈ 𝓀 Ξ², βˆ€αΆ  m : (ΞΉ Γ— ΞΉ) Γ— Ξ± in (p Γ—Λ’ p) Γ—Λ’ p', (F m.fst.fst m.snd, F m.fst.snd m.snd) ∈ u /-- A sequence is uniformly Cauchy if eventually all of its pairwise differences are uniformly bounded -/ def UniformCauchySeqOn (F : ΞΉ β†’ Ξ± β†’ Ξ²) (p : Filter ΞΉ) (s : Set Ξ±) : Prop := βˆ€ u ∈ 𝓀 Ξ², βˆ€αΆ  m : ΞΉ Γ— ΞΉ in p Γ—Λ’ p, βˆ€ x : Ξ±, x ∈ s β†’ (F m.fst x, F m.snd x) ∈ u theorem uniformCauchySeqOn_iff_uniformCauchySeqOnFilter : UniformCauchySeqOn F p s ↔ UniformCauchySeqOnFilter F p (π“Ÿ s) := by simp only [UniformCauchySeqOn, UniformCauchySeqOnFilter] refine forallβ‚‚_congr fun u hu => ?_ rw [eventually_prod_principal_iff] theorem UniformCauchySeqOn.uniformCauchySeqOnFilter (hF : UniformCauchySeqOn F p s) : UniformCauchySeqOnFilter F p (π“Ÿ s) := by rwa [← uniformCauchySeqOn_iff_uniformCauchySeqOnFilter] /-- A sequence that converges uniformly is also uniformly Cauchy -/ theorem TendstoUniformlyOnFilter.uniformCauchySeqOnFilter (hF : TendstoUniformlyOnFilter F f p p') : UniformCauchySeqOnFilter F p p' := by intro u hu rcases comp_symm_of_uniformity hu with ⟨t, ht, htsymm, htmem⟩ have := tendsto_swap4_prod.eventually ((hF t ht).prod_mk (hF t ht)) apply this.diag_of_prod_right.mono simp only [and_imp, Prod.forall] intro n1 n2 x hl hr exact Set.mem_of_mem_of_subset (prodMk_mem_compRel (htsymm hl) hr) htmem /-- A sequence that converges uniformly is also uniformly Cauchy -/ theorem TendstoUniformlyOn.uniformCauchySeqOn (hF : TendstoUniformlyOn F f p s) : UniformCauchySeqOn F p s := uniformCauchySeqOn_iff_uniformCauchySeqOnFilter.mpr hF.tendstoUniformlyOnFilter.uniformCauchySeqOnFilter /-- A uniformly Cauchy sequence converges uniformly to its limit -/ theorem UniformCauchySeqOnFilter.tendstoUniformlyOnFilter_of_tendsto (hF : UniformCauchySeqOnFilter F p p') (hF' : βˆ€αΆ  x : Ξ± in p', Tendsto (fun n => F n x) p (𝓝 (f x))) : TendstoUniformlyOnFilter F f p p' := by rcases p.eq_or_neBot with rfl | _ Β· simp only [TendstoUniformlyOnFilter, bot_prod, eventually_bot, implies_true] -- Proof idea: |f_n(x) - f(x)| ≀ |f_n(x) - f_m(x)| + |f_m(x) - f(x)|. We choose `n` -- so that |f_n(x) - f_m(x)| is uniformly small across `s` whenever `m β‰₯ n`. Then for -- a fixed `x`, we choose `m` sufficiently large such that |f_m(x) - f(x)| is small. intro u hu rcases comp_symm_of_uniformity hu with ⟨t, ht, htsymm, htmem⟩ -- We will choose n, x, and m simultaneously. n and x come from hF. m comes from hF' -- But we need to promote hF' to the full product filter to use it have hmc : βˆ€αΆ  x in (p Γ—Λ’ p) Γ—Λ’ p', Tendsto (fun n : ΞΉ => F n x.snd) p (𝓝 (f x.snd)) := by rw [eventually_prod_iff] exact ⟨fun _ => True, by simp, _, hF', by simp⟩
-- To apply filter operations we'll need to do some order manipulation rw [Filter.eventually_swap_iff] have := tendsto_prodAssoc.eventually (tendsto_prod_swap.eventually ((hF t ht).and hmc)) apply this.curry.mono simp only [Equiv.prodAssoc_apply, eventually_and, eventually_const, Prod.snd_swap, Prod.fst_swap,
Mathlib/Topology/UniformSpace/UniformConvergence.lean
407
411
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon -/ import Mathlib.Control.Applicative import Mathlib.Control.Traversable.Basic import Mathlib.Data.List.Forall2 import Mathlib.Data.Set.Functor /-! # LawfulTraversable instances This file provides instances of `LawfulTraversable` for types from the core library: `Option`, `List` and `Sum`. -/ universe u v section Option open Functor variable {F G : Type u β†’ Type u} variable [Applicative F] [Applicative G] variable [LawfulApplicative G] theorem Option.id_traverse {Ξ±} (x : Option Ξ±) : Option.traverse (pure : Ξ± β†’ Id Ξ±) x = x := by cases x <;> rfl theorem Option.comp_traverse {Ξ± Ξ² Ξ³} (f : Ξ² β†’ F Ξ³) (g : Ξ± β†’ G Ξ²) (x : Option Ξ±) : Option.traverse (Comp.mk ∘ (f <$> Β·) ∘ g) x = Comp.mk (Option.traverse f <$> Option.traverse g x) := by cases x <;> (simp! [functor_norm] <;> rfl) theorem Option.traverse_eq_map_id {Ξ± Ξ²} (f : Ξ± β†’ Ξ²) (x : Option Ξ±) : Option.traverse ((pure : _ β†’ Id _) ∘ f) x = (pure : _ β†’ Id _) (f <$> x) := by cases x <;> rfl variable (Ξ· : ApplicativeTransformation F G) theorem Option.naturality [LawfulApplicative F] {Ξ± Ξ²} (f : Ξ± β†’ F Ξ²) (x : Option Ξ±) : Ξ· (Option.traverse f x) = Option.traverse (@Ξ· _ ∘ f) x := by -- Porting note: added `ApplicativeTransformation` theorems rcases x with - | x <;> simp! [*, functor_norm, ApplicativeTransformation.preserves_map, ApplicativeTransformation.preserves_seq, ApplicativeTransformation.preserves_pure] end Option instance : LawfulTraversable Option := { show LawfulMonad Option from inferInstance with id_traverse := Option.id_traverse comp_traverse := Option.comp_traverse traverse_eq_map_id := Option.traverse_eq_map_id naturality := fun Ξ· _ _ f x => Option.naturality Ξ· f x } namespace List variable {F G : Type u β†’ Type u} variable [Applicative F] [Applicative G] section variable [LawfulApplicative G] open Applicative Functor List protected theorem id_traverse {Ξ±} (xs : List Ξ±) : List.traverse (pure : Ξ± β†’ Id Ξ±) xs = xs := by induction xs <;> simp! [*, List.traverse, functor_norm]; rfl protected theorem comp_traverse {Ξ± Ξ² Ξ³} (f : Ξ² β†’ F Ξ³) (g : Ξ± β†’ G Ξ²) (x : List Ξ±) : List.traverse (Comp.mk ∘ (f <$> Β·) ∘ g) x = Comp.mk (List.traverse f <$> List.traverse g x) := by induction x <;> simp! [*, functor_norm] <;> rfl protected theorem traverse_eq_map_id {Ξ± Ξ²} (f : Ξ± β†’ Ξ²) (x : List Ξ±) : List.traverse ((pure : _ β†’ Id _) ∘ f) x = (pure : _ β†’ Id _) (f <$> x) := by induction x <;> simp! [*, functor_norm]; rfl variable [LawfulApplicative F] (Ξ· : ApplicativeTransformation F G) protected theorem naturality {Ξ± Ξ²} (f : Ξ± β†’ F Ξ²) (x : List Ξ±) : Ξ· (List.traverse f x) = List.traverse (@Ξ· _ ∘ f) x := by -- Porting note: added `ApplicativeTransformation` theorems induction x <;> simp! [*, functor_norm, ApplicativeTransformation.preserves_map, ApplicativeTransformation.preserves_seq, ApplicativeTransformation.preserves_pure] instance : LawfulTraversable.{u} List := { show LawfulMonad List from inferInstance with id_traverse := List.id_traverse comp_traverse := List.comp_traverse traverse_eq_map_id := List.traverse_eq_map_id naturality := List.naturality } end section Traverse variable {Ξ±' Ξ²' : Type u} (f : Ξ±' β†’ F Ξ²') @[simp] theorem traverse_nil : traverse f ([] : List Ξ±') = (pure [] : F (List Ξ²')) := rfl @[simp] theorem traverse_cons (a : Ξ±') (l : List Ξ±') : traverse f (a :: l) = (Β· :: Β·) <$> f a <*> traverse f l := rfl variable [LawfulApplicative F] @[simp] theorem traverse_append : βˆ€ as bs : List Ξ±', traverse f (as ++ bs) = (Β· ++ Β·) <$> traverse f as <*> traverse f bs | [], bs => by simp [functor_norm] | a :: as, bs => by simp [traverse_append as bs, functor_norm]; congr theorem mem_traverse {f : Ξ±' β†’ Set Ξ²'} : βˆ€ (l : List Ξ±') (n : List Ξ²'), n ∈ traverse f l ↔ Forallβ‚‚ (fun b a => b ∈ f a) n l | [], [] => by simp | a :: as, [] => by simp | [], b :: bs => by simp | a :: as, b :: bs => by simp [mem_traverse as bs] end Traverse end List namespace Sum section Traverse variable {Οƒ : Type u} variable {F G : Type u β†’ Type u} variable [Applicative F] [Applicative G] open Applicative Functor protected theorem traverse_map {Ξ± Ξ² Ξ³ : Type u} (g : Ξ± β†’ Ξ²) (f : Ξ² β†’ G Ξ³) (x : Οƒ βŠ• Ξ±) : Sum.traverse f (g <$> x) = Sum.traverse (f ∘ g) x := by cases x <;> simp [Sum.traverse, id_map, functor_norm] <;> rfl protected theorem id_traverse {Οƒ Ξ±} (x : Οƒ βŠ• Ξ±) : Sum.traverse (pure : Ξ± β†’ Id Ξ±) x = x := by cases x <;> rfl variable [LawfulApplicative G] protected theorem comp_traverse {Ξ± Ξ² Ξ³ : Type u} (f : Ξ² β†’ F Ξ³) (g : Ξ± β†’ G Ξ²) (x : Οƒ βŠ• Ξ±) : Sum.traverse (Comp.mk ∘ (f <$> Β·) ∘ g) x = Comp.mk.{u} (Sum.traverse f <$> Sum.traverse g x) := by cases x <;> (simp! [Sum.traverse, map_id, functor_norm] <;> rfl) protected theorem traverse_eq_map_id {Ξ± Ξ²} (f : Ξ± β†’ Ξ²) (x : Οƒ βŠ• Ξ±) : Sum.traverse ((pure : _ β†’ Id _) ∘ f) x = (pure : _ β†’ Id _) (f <$> x) := by induction x <;> simp! [*, functor_norm] <;> rfl protected theorem map_traverse {Ξ± Ξ² Ξ³} (g : Ξ± β†’ G Ξ²) (f : Ξ² β†’ Ξ³) (x : Οƒ βŠ• Ξ±) : (f <$> Β·) <$> Sum.traverse g x = Sum.traverse (f <$> g Β·) x := by cases x <;> simp [Sum.traverse, id_map, functor_norm] <;> congr variable [LawfulApplicative F] (Ξ· : ApplicativeTransformation F G) protected theorem naturality {Ξ± Ξ²} (f : Ξ± β†’ F Ξ²) (x : Οƒ βŠ• Ξ±) :
η (Sum.traverse f x) = Sum.traverse (@η _ ∘ f) x := by -- Porting note: added `ApplicativeTransformation` theorems cases x <;> simp! [Sum.traverse, functor_norm, ApplicativeTransformation.preserves_map, ApplicativeTransformation.preserves_seq, ApplicativeTransformation.preserves_pure]
Mathlib/Control/Traversable/Instances.lean
164
167
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne, Benjamin Davidson -/ import Mathlib.Algebra.Field.NegOnePow import Mathlib.Algebra.Field.Periodic import Mathlib.Algebra.QuadraticDiscriminant import Mathlib.Analysis.SpecialFunctions.Exp /-! # Trigonometric functions ## Main definitions This file contains the definition of `Ο€`. See also `Analysis.SpecialFunctions.Trigonometric.Inverse` and `Analysis.SpecialFunctions.Trigonometric.Arctan` for the inverse trigonometric functions. See also `Analysis.SpecialFunctions.Complex.Arg` and `Analysis.SpecialFunctions.Complex.Log` for the complex argument function and the complex logarithm. ## Main statements Many basic inequalities on the real trigonometric functions are established. The continuity of the usual trigonometric functions is proved. Several facts about the real trigonometric functions have the proofs deferred to `Analysis.SpecialFunctions.Trigonometric.Complex`, as they are most easily proved by appealing to the corresponding fact for complex trigonometric functions. See also `Analysis.SpecialFunctions.Trigonometric.Chebyshev` for the multiple angle formulas in terms of Chebyshev polynomials. ## Tags sin, cos, tan, angle -/ noncomputable section open Topology Filter Set namespace Complex @[continuity, fun_prop] theorem continuous_sin : Continuous sin := by change Continuous fun z => (exp (-z * I) - exp (z * I)) * I / 2 fun_prop @[fun_prop] theorem continuousOn_sin {s : Set β„‚} : ContinuousOn sin s := continuous_sin.continuousOn @[continuity, fun_prop] theorem continuous_cos : Continuous cos := by change Continuous fun z => (exp (z * I) + exp (-z * I)) / 2 fun_prop @[fun_prop] theorem continuousOn_cos {s : Set β„‚} : ContinuousOn cos s := continuous_cos.continuousOn @[continuity, fun_prop] theorem continuous_sinh : Continuous sinh := by change Continuous fun z => (exp z - exp (-z)) / 2 fun_prop @[continuity, fun_prop] theorem continuous_cosh : Continuous cosh := by change Continuous fun z => (exp z + exp (-z)) / 2 fun_prop end Complex namespace Real variable {x y z : ℝ} @[continuity, fun_prop] theorem continuous_sin : Continuous sin := Complex.continuous_re.comp (Complex.continuous_sin.comp Complex.continuous_ofReal) @[fun_prop] theorem continuousOn_sin {s} : ContinuousOn sin s := continuous_sin.continuousOn @[continuity, fun_prop] theorem continuous_cos : Continuous cos := Complex.continuous_re.comp (Complex.continuous_cos.comp Complex.continuous_ofReal) @[fun_prop] theorem continuousOn_cos {s} : ContinuousOn cos s := continuous_cos.continuousOn @[continuity, fun_prop] theorem continuous_sinh : Continuous sinh := Complex.continuous_re.comp (Complex.continuous_sinh.comp Complex.continuous_ofReal) @[continuity, fun_prop] theorem continuous_cosh : Continuous cosh := Complex.continuous_re.comp (Complex.continuous_cosh.comp Complex.continuous_ofReal) end Real namespace Real theorem exists_cos_eq_zero : 0 ∈ cos '' Icc (1 : ℝ) 2 := intermediate_value_Icc' (by norm_num) continuousOn_cos ⟨le_of_lt cos_two_neg, le_of_lt cos_one_pos⟩ /-- The number Ο€ = 3.14159265... Defined here using choice as twice a zero of cos in [1,2], from which one can derive all its properties. For explicit bounds on Ο€, see `Data.Real.Pi.Bounds`. Denoted `Ο€`, once the `Real` namespace is opened. -/ protected noncomputable def pi : ℝ := 2 * Classical.choose exists_cos_eq_zero @[inherit_doc] scoped notation "Ο€" => Real.pi @[simp] theorem cos_pi_div_two : cos (Ο€ / 2) = 0 := by rw [Real.pi, mul_div_cancel_leftβ‚€ _ (two_ne_zero' ℝ)] exact (Classical.choose_spec exists_cos_eq_zero).2 theorem one_le_pi_div_two : (1 : ℝ) ≀ Ο€ / 2 := by rw [Real.pi, mul_div_cancel_leftβ‚€ _ (two_ne_zero' ℝ)] exact (Classical.choose_spec exists_cos_eq_zero).1.1 theorem pi_div_two_le_two : Ο€ / 2 ≀ 2 := by rw [Real.pi, mul_div_cancel_leftβ‚€ _ (two_ne_zero' ℝ)] exact (Classical.choose_spec exists_cos_eq_zero).1.2 theorem two_le_pi : (2 : ℝ) ≀ Ο€ := (div_le_div_iff_of_pos_right (show (0 : ℝ) < 2 by norm_num)).1 (by rw [div_self (two_ne_zero' ℝ)]; exact one_le_pi_div_two) theorem pi_le_four : Ο€ ≀ 4 := (div_le_div_iff_of_pos_right (show (0 : ℝ) < 2 by norm_num)).1 (calc Ο€ / 2 ≀ 2 := pi_div_two_le_two _ = 4 / 2 := by norm_num) @[bound] theorem pi_pos : 0 < Ο€ := lt_of_lt_of_le (by norm_num) two_le_pi @[bound] theorem pi_nonneg : 0 ≀ Ο€ := pi_pos.le theorem pi_ne_zero : Ο€ β‰  0 := pi_pos.ne' theorem pi_div_two_pos : 0 < Ο€ / 2 := half_pos pi_pos theorem two_pi_pos : 0 < 2 * Ο€ := by linarith [pi_pos] end Real namespace Mathlib.Meta.Positivity open Lean.Meta Qq /-- Extension for the `positivity` tactic: `Ο€` is always positive. -/ @[positivity Real.pi] def evalRealPi : PositivityExt where eval {u Ξ±} _zΞ± _pΞ± e := do match u, Ξ±, e with | 0, ~q(ℝ), ~q(Real.pi) => assertInstancesCommute pure (.positive q(Real.pi_pos)) | _, _, _ => throwError "not Real.pi" end Mathlib.Meta.Positivity namespace NNReal open Real open Real NNReal /-- `Ο€` considered as a nonnegative real. -/ noncomputable def pi : ℝβ‰₯0 := βŸ¨Ο€, Real.pi_pos.le⟩ @[simp] theorem coe_real_pi : (pi : ℝ) = Ο€ := rfl theorem pi_pos : 0 < pi := mod_cast Real.pi_pos theorem pi_ne_zero : pi β‰  0 := pi_pos.ne' end NNReal namespace Real @[simp] theorem sin_pi : sin Ο€ = 0 := by rw [← mul_div_cancel_leftβ‚€ Ο€ (two_ne_zero' ℝ), two_mul, add_div, sin_add, cos_pi_div_two]; simp @[simp] theorem cos_pi : cos Ο€ = -1 := by rw [← mul_div_cancel_leftβ‚€ Ο€ (two_ne_zero' ℝ), mul_div_assoc, cos_two_mul, cos_pi_div_two] norm_num @[simp] theorem sin_two_pi : sin (2 * Ο€) = 0 := by simp [two_mul, sin_add] @[simp] theorem cos_two_pi : cos (2 * Ο€) = 1 := by simp [two_mul, cos_add] theorem sin_antiperiodic : Function.Antiperiodic sin Ο€ := by simp [sin_add] theorem sin_periodic : Function.Periodic sin (2 * Ο€) := sin_antiperiodic.periodic_two_mul @[simp] theorem sin_add_pi (x : ℝ) : sin (x + Ο€) = -sin x := sin_antiperiodic x @[simp] theorem sin_add_two_pi (x : ℝ) : sin (x + 2 * Ο€) = sin x := sin_periodic x @[simp] theorem sin_sub_pi (x : ℝ) : sin (x - Ο€) = -sin x := sin_antiperiodic.sub_eq x @[simp] theorem sin_sub_two_pi (x : ℝ) : sin (x - 2 * Ο€) = sin x := sin_periodic.sub_eq x @[simp] theorem sin_pi_sub (x : ℝ) : sin (Ο€ - x) = sin x := neg_neg (sin x) β–Έ sin_neg x β–Έ sin_antiperiodic.sub_eq' @[simp] theorem sin_two_pi_sub (x : ℝ) : sin (2 * Ο€ - x) = -sin x := sin_neg x β–Έ sin_periodic.sub_eq' @[simp] theorem sin_nat_mul_pi (n : β„•) : sin (n * Ο€) = 0 := sin_antiperiodic.nat_mul_eq_of_eq_zero sin_zero n @[simp] theorem sin_int_mul_pi (n : β„€) : sin (n * Ο€) = 0 := sin_antiperiodic.int_mul_eq_of_eq_zero sin_zero n @[simp] theorem sin_add_nat_mul_two_pi (x : ℝ) (n : β„•) : sin (x + n * (2 * Ο€)) = sin x := sin_periodic.nat_mul n x @[simp] theorem sin_add_int_mul_two_pi (x : ℝ) (n : β„€) : sin (x + n * (2 * Ο€)) = sin x := sin_periodic.int_mul n x @[simp] theorem sin_sub_nat_mul_two_pi (x : ℝ) (n : β„•) : sin (x - n * (2 * Ο€)) = sin x := sin_periodic.sub_nat_mul_eq n @[simp] theorem sin_sub_int_mul_two_pi (x : ℝ) (n : β„€) : sin (x - n * (2 * Ο€)) = sin x := sin_periodic.sub_int_mul_eq n @[simp] theorem sin_nat_mul_two_pi_sub (x : ℝ) (n : β„•) : sin (n * (2 * Ο€) - x) = -sin x := sin_neg x β–Έ sin_periodic.nat_mul_sub_eq n @[simp] theorem sin_int_mul_two_pi_sub (x : ℝ) (n : β„€) : sin (n * (2 * Ο€) - x) = -sin x := sin_neg x β–Έ sin_periodic.int_mul_sub_eq n theorem sin_add_int_mul_pi (x : ℝ) (n : β„€) : sin (x + n * Ο€) = (-1) ^ n * sin x := n.cast_negOnePow ℝ β–Έ sin_antiperiodic.add_int_mul_eq n theorem sin_add_nat_mul_pi (x : ℝ) (n : β„•) : sin (x + n * Ο€) = (-1) ^ n * sin x := sin_antiperiodic.add_nat_mul_eq n theorem sin_sub_int_mul_pi (x : ℝ) (n : β„€) : sin (x - n * Ο€) = (-1) ^ n * sin x := n.cast_negOnePow ℝ β–Έ sin_antiperiodic.sub_int_mul_eq n theorem sin_sub_nat_mul_pi (x : ℝ) (n : β„•) : sin (x - n * Ο€) = (-1) ^ n * sin x := sin_antiperiodic.sub_nat_mul_eq n theorem sin_int_mul_pi_sub (x : ℝ) (n : β„€) : sin (n * Ο€ - x) = -((-1) ^ n * sin x) := by simpa only [sin_neg, mul_neg, Int.cast_negOnePow] using sin_antiperiodic.int_mul_sub_eq n theorem sin_nat_mul_pi_sub (x : ℝ) (n : β„•) : sin (n * Ο€ - x) = -((-1) ^ n * sin x) := by simpa only [sin_neg, mul_neg] using sin_antiperiodic.nat_mul_sub_eq n theorem cos_antiperiodic : Function.Antiperiodic cos Ο€ := by simp [cos_add] theorem cos_periodic : Function.Periodic cos (2 * Ο€) := cos_antiperiodic.periodic_two_mul @[simp] theorem abs_cos_int_mul_pi (k : β„€) : |cos (k * Ο€)| = 1 := by simp [abs_cos_eq_sqrt_one_sub_sin_sq] @[simp] theorem cos_add_pi (x : ℝ) : cos (x + Ο€) = -cos x := cos_antiperiodic x @[simp] theorem cos_add_two_pi (x : ℝ) : cos (x + 2 * Ο€) = cos x := cos_periodic x @[simp] theorem cos_sub_pi (x : ℝ) : cos (x - Ο€) = -cos x := cos_antiperiodic.sub_eq x @[simp] theorem cos_sub_two_pi (x : ℝ) : cos (x - 2 * Ο€) = cos x := cos_periodic.sub_eq x @[simp] theorem cos_pi_sub (x : ℝ) : cos (Ο€ - x) = -cos x := cos_neg x β–Έ cos_antiperiodic.sub_eq' @[simp] theorem cos_two_pi_sub (x : ℝ) : cos (2 * Ο€ - x) = cos x := cos_neg x β–Έ cos_periodic.sub_eq' @[simp] theorem cos_nat_mul_two_pi (n : β„•) : cos (n * (2 * Ο€)) = 1 := (cos_periodic.nat_mul_eq n).trans cos_zero @[simp] theorem cos_int_mul_two_pi (n : β„€) : cos (n * (2 * Ο€)) = 1 := (cos_periodic.int_mul_eq n).trans cos_zero @[simp] theorem cos_add_nat_mul_two_pi (x : ℝ) (n : β„•) : cos (x + n * (2 * Ο€)) = cos x := cos_periodic.nat_mul n x @[simp] theorem cos_add_int_mul_two_pi (x : ℝ) (n : β„€) : cos (x + n * (2 * Ο€)) = cos x := cos_periodic.int_mul n x @[simp] theorem cos_sub_nat_mul_two_pi (x : ℝ) (n : β„•) : cos (x - n * (2 * Ο€)) = cos x := cos_periodic.sub_nat_mul_eq n @[simp] theorem cos_sub_int_mul_two_pi (x : ℝ) (n : β„€) : cos (x - n * (2 * Ο€)) = cos x := cos_periodic.sub_int_mul_eq n @[simp] theorem cos_nat_mul_two_pi_sub (x : ℝ) (n : β„•) : cos (n * (2 * Ο€) - x) = cos x := cos_neg x β–Έ cos_periodic.nat_mul_sub_eq n @[simp] theorem cos_int_mul_two_pi_sub (x : ℝ) (n : β„€) : cos (n * (2 * Ο€) - x) = cos x := cos_neg x β–Έ cos_periodic.int_mul_sub_eq n theorem cos_add_int_mul_pi (x : ℝ) (n : β„€) : cos (x + n * Ο€) = (-1) ^ n * cos x := n.cast_negOnePow ℝ β–Έ cos_antiperiodic.add_int_mul_eq n theorem cos_add_nat_mul_pi (x : ℝ) (n : β„•) : cos (x + n * Ο€) = (-1) ^ n * cos x := cos_antiperiodic.add_nat_mul_eq n theorem cos_sub_int_mul_pi (x : ℝ) (n : β„€) : cos (x - n * Ο€) = (-1) ^ n * cos x := n.cast_negOnePow ℝ β–Έ cos_antiperiodic.sub_int_mul_eq n theorem cos_sub_nat_mul_pi (x : ℝ) (n : β„•) : cos (x - n * Ο€) = (-1) ^ n * cos x := cos_antiperiodic.sub_nat_mul_eq n theorem cos_int_mul_pi_sub (x : ℝ) (n : β„€) : cos (n * Ο€ - x) = (-1) ^ n * cos x := n.cast_negOnePow ℝ β–Έ cos_neg x β–Έ cos_antiperiodic.int_mul_sub_eq n theorem cos_nat_mul_pi_sub (x : ℝ) (n : β„•) : cos (n * Ο€ - x) = (-1) ^ n * cos x := cos_neg x β–Έ cos_antiperiodic.nat_mul_sub_eq n theorem cos_nat_mul_two_pi_add_pi (n : β„•) : cos (n * (2 * Ο€) + Ο€) = -1 := by simpa only [cos_zero] using (cos_periodic.nat_mul n).add_antiperiod_eq cos_antiperiodic theorem cos_int_mul_two_pi_add_pi (n : β„€) : cos (n * (2 * Ο€) + Ο€) = -1 := by simpa only [cos_zero] using (cos_periodic.int_mul n).add_antiperiod_eq cos_antiperiodic theorem cos_nat_mul_two_pi_sub_pi (n : β„•) : cos (n * (2 * Ο€) - Ο€) = -1 := by simpa only [cos_zero] using (cos_periodic.nat_mul n).sub_antiperiod_eq cos_antiperiodic theorem cos_int_mul_two_pi_sub_pi (n : β„€) : cos (n * (2 * Ο€) - Ο€) = -1 := by simpa only [cos_zero] using (cos_periodic.int_mul n).sub_antiperiod_eq cos_antiperiodic theorem sin_pos_of_pos_of_lt_pi {x : ℝ} (h0x : 0 < x) (hxp : x < Ο€) : 0 < sin x := if hx2 : x ≀ 2 then sin_pos_of_pos_of_le_two h0x hx2 else have : (2 : ℝ) + 2 = 4 := by norm_num have : Ο€ - x ≀ 2 := sub_le_iff_le_add.2 (le_trans pi_le_four (this β–Έ add_le_add_left (le_of_not_ge hx2) _)) sin_pi_sub x β–Έ sin_pos_of_pos_of_le_two (sub_pos.2 hxp) this theorem sin_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo 0 Ο€) : 0 < sin x := sin_pos_of_pos_of_lt_pi hx.1 hx.2 theorem sin_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc 0 Ο€) : 0 ≀ sin x := by rw [← closure_Ioo pi_ne_zero.symm] at hx exact closure_lt_subset_le continuous_const continuous_sin (closure_mono (fun y => sin_pos_of_mem_Ioo) hx) theorem sin_nonneg_of_nonneg_of_le_pi {x : ℝ} (h0x : 0 ≀ x) (hxp : x ≀ Ο€) : 0 ≀ sin x := sin_nonneg_of_mem_Icc ⟨h0x, hxp⟩ theorem sin_neg_of_neg_of_neg_pi_lt {x : ℝ} (hx0 : x < 0) (hpx : -Ο€ < x) : sin x < 0 := neg_pos.1 <| sin_neg x β–Έ sin_pos_of_pos_of_lt_pi (neg_pos.2 hx0) (neg_lt.1 hpx) theorem sin_nonpos_of_nonnpos_of_neg_pi_le {x : ℝ} (hx0 : x ≀ 0) (hpx : -Ο€ ≀ x) : sin x ≀ 0 := neg_nonneg.1 <| sin_neg x β–Έ sin_nonneg_of_nonneg_of_le_pi (neg_nonneg.2 hx0) (neg_le.1 hpx) @[simp] theorem sin_pi_div_two : sin (Ο€ / 2) = 1 := have : sin (Ο€ / 2) = 1 ∨ sin (Ο€ / 2) = -1 := by simpa [sq, mul_self_eq_one_iff] using sin_sq_add_cos_sq (Ο€ / 2) this.resolve_right fun h => show Β¬(0 : ℝ) < -1 by norm_num <| h β–Έ sin_pos_of_pos_of_lt_pi pi_div_two_pos (half_lt_self pi_pos) theorem sin_add_pi_div_two (x : ℝ) : sin (x + Ο€ / 2) = cos x := by simp [sin_add] theorem sin_sub_pi_div_two (x : ℝ) : sin (x - Ο€ / 2) = -cos x := by simp [sub_eq_add_neg, sin_add] theorem sin_pi_div_two_sub (x : ℝ) : sin (Ο€ / 2 - x) = cos x := by simp [sub_eq_add_neg, sin_add] theorem cos_add_pi_div_two (x : ℝ) : cos (x + Ο€ / 2) = -sin x := by simp [cos_add] theorem cos_sub_pi_div_two (x : ℝ) : cos (x - Ο€ / 2) = sin x := by simp [sub_eq_add_neg, cos_add] theorem cos_pi_div_two_sub (x : ℝ) : cos (Ο€ / 2 - x) = sin x := by rw [← cos_neg, neg_sub, cos_sub_pi_div_two] theorem cos_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo (-(Ο€ / 2)) (Ο€ / 2)) : 0 < cos x := sin_add_pi_div_two x β–Έ sin_pos_of_mem_Ioo ⟨by linarith [hx.1], by linarith [hx.2]⟩ theorem cos_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc (-(Ο€ / 2)) (Ο€ / 2)) : 0 ≀ cos x := sin_add_pi_div_two x β–Έ sin_nonneg_of_mem_Icc ⟨by linarith [hx.1], by linarith [hx.2]⟩ theorem cos_nonneg_of_neg_pi_div_two_le_of_le {x : ℝ} (hl : -(Ο€ / 2) ≀ x) (hu : x ≀ Ο€ / 2) : 0 ≀ cos x := cos_nonneg_of_mem_Icc ⟨hl, hu⟩ theorem cos_neg_of_pi_div_two_lt_of_lt {x : ℝ} (hx₁ : Ο€ / 2 < x) (hxβ‚‚ : x < Ο€ + Ο€ / 2) : cos x < 0 := neg_pos.1 <| cos_pi_sub x β–Έ cos_pos_of_mem_Ioo ⟨by linarith, by linarith⟩ theorem cos_nonpos_of_pi_div_two_le_of_le {x : ℝ} (hx₁ : Ο€ / 2 ≀ x) (hxβ‚‚ : x ≀ Ο€ + Ο€ / 2) : cos x ≀ 0 := neg_nonneg.1 <| cos_pi_sub x β–Έ cos_nonneg_of_mem_Icc ⟨by linarith, by linarith⟩ theorem sin_eq_sqrt_one_sub_cos_sq {x : ℝ} (hl : 0 ≀ x) (hu : x ≀ Ο€) : sin x = √(1 - cos x ^ 2) := by rw [← abs_sin_eq_sqrt_one_sub_cos_sq, abs_of_nonneg (sin_nonneg_of_nonneg_of_le_pi hl hu)] theorem cos_eq_sqrt_one_sub_sin_sq {x : ℝ} (hl : -(Ο€ / 2) ≀ x) (hu : x ≀ Ο€ / 2) : cos x = √(1 - sin x ^ 2) := by rw [← abs_cos_eq_sqrt_one_sub_sin_sq, abs_of_nonneg (cos_nonneg_of_mem_Icc ⟨hl, hu⟩)] lemma cos_half {x : ℝ} (hl : -Ο€ ≀ x) (hr : x ≀ Ο€) : cos (x / 2) = sqrt ((1 + cos x) / 2) := by have : 0 ≀ cos (x / 2) := cos_nonneg_of_mem_Icc <| by constructor <;> linarith rw [← sqrt_sq this, cos_sq, add_div, two_mul, add_halves] lemma abs_sin_half (x : ℝ) : |sin (x / 2)| = sqrt ((1 - cos x) / 2) := by rw [← sqrt_sq_eq_abs, sin_sq_eq_half_sub, two_mul, add_halves, sub_div] lemma sin_half_eq_sqrt {x : ℝ} (hl : 0 ≀ x) (hr : x ≀ 2 * Ο€) : sin (x / 2) = sqrt ((1 - cos x) / 2) := by rw [← abs_sin_half, abs_of_nonneg] apply sin_nonneg_of_nonneg_of_le_pi <;> linarith lemma sin_half_eq_neg_sqrt {x : ℝ} (hl : -(2 * Ο€) ≀ x) (hr : x ≀ 0) : sin (x / 2) = -sqrt ((1 - cos x) / 2) := by rw [← abs_sin_half, abs_of_nonpos, neg_neg] apply sin_nonpos_of_nonnpos_of_neg_pi_le <;> linarith theorem sin_eq_zero_iff_of_lt_of_lt {x : ℝ} (hx₁ : -Ο€ < x) (hxβ‚‚ : x < Ο€) : sin x = 0 ↔ x = 0 := ⟨fun h => by contrapose! h cases h.lt_or_lt with | inl h0 => exact (sin_neg_of_neg_of_neg_pi_lt h0 hx₁).ne | inr h0 => exact (sin_pos_of_pos_of_lt_pi h0 hxβ‚‚).ne', fun h => by simp [h]⟩ theorem sin_eq_zero_iff {x : ℝ} : sin x = 0 ↔ βˆƒ n : β„€, (n : ℝ) * Ο€ = x := ⟨fun h => ⟨⌊x / Ο€βŒ‹, le_antisymm (sub_nonneg.1 (Int.sub_floor_div_mul_nonneg _ pi_pos)) (sub_nonpos.1 <| le_of_not_gt fun h₃ => (sin_pos_of_pos_of_lt_pi h₃ (Int.sub_floor_div_mul_lt _ pi_pos)).ne (by simp [sub_eq_add_neg, sin_add, h, sin_int_mul_pi]))⟩, fun ⟨_, hn⟩ => hn β–Έ sin_int_mul_pi _⟩ theorem sin_ne_zero_iff {x : ℝ} : sin x β‰  0 ↔ βˆ€ n : β„€, (n : ℝ) * Ο€ β‰  x := by rw [← not_exists, not_iff_not, sin_eq_zero_iff] theorem sin_eq_zero_iff_cos_eq {x : ℝ} : sin x = 0 ↔ cos x = 1 ∨ cos x = -1 := by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq x, sq, sq, ← sub_eq_iff_eq_add, sub_self] exact ⟨fun h => by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ Eq.symm⟩ theorem cos_eq_one_iff (x : ℝ) : cos x = 1 ↔ βˆƒ n : β„€, (n : ℝ) * (2 * Ο€) = x := ⟨fun h => let ⟨n, hn⟩ := sin_eq_zero_iff.1 (sin_eq_zero_iff_cos_eq.2 (Or.inl h)) ⟨n / 2, (Int.emod_two_eq_zero_or_one n).elim (fun hn0 => by rwa [← mul_assoc, ← @Int.cast_two ℝ, ← Int.cast_mul, Int.ediv_mul_cancel (Int.dvd_iff_emod_eq_zero.2 hn0)]) fun hn1 => by rw [← Int.emod_add_ediv n 2, hn1, Int.cast_add, Int.cast_one, add_mul, one_mul, add_comm, mul_comm (2 : β„€), Int.cast_mul, mul_assoc, Int.cast_two] at hn rw [← hn, cos_int_mul_two_pi_add_pi] at h exact absurd h (by norm_num)⟩, fun ⟨_, hn⟩ => hn β–Έ cos_int_mul_two_pi _⟩ theorem cos_eq_one_iff_of_lt_of_lt {x : ℝ} (hx₁ : -(2 * Ο€) < x) (hxβ‚‚ : x < 2 * Ο€) : cos x = 1 ↔ x = 0 := ⟨fun h => by rcases (cos_eq_one_iff _).1 h with ⟨n, rfl⟩ rw [mul_lt_iff_lt_one_left two_pi_pos] at hxβ‚‚ rw [neg_lt, neg_mul_eq_neg_mul, mul_lt_iff_lt_one_left two_pi_pos] at hx₁ norm_cast at hx₁ hxβ‚‚ obtain rfl : n = 0 := le_antisymm (by omega) (by omega) simp, fun h => by simp [h]⟩ theorem sin_lt_sin_of_lt_of_le_pi_div_two {x y : ℝ} (hx₁ : -(Ο€ / 2) ≀ x) (hyβ‚‚ : y ≀ Ο€ / 2) (hxy : x < y) : sin x < sin y := by rw [← sub_pos, sin_sub_sin] have : 0 < sin ((y - x) / 2) := by apply sin_pos_of_pos_of_lt_pi <;> linarith have : 0 < cos ((y + x) / 2) := by refine cos_pos_of_mem_Ioo ⟨?_, ?_⟩ <;> linarith positivity theorem strictMonoOn_sin : StrictMonoOn sin (Icc (-(Ο€ / 2)) (Ο€ / 2)) := fun _ hx _ hy hxy => sin_lt_sin_of_lt_of_le_pi_div_two hx.1 hy.2 hxy theorem cos_lt_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≀ x) (hyβ‚‚ : y ≀ Ο€) (hxy : x < y) : cos y < cos x := by rw [← sin_pi_div_two_sub, ← sin_pi_div_two_sub] apply sin_lt_sin_of_lt_of_le_pi_div_two <;> linarith theorem cos_lt_cos_of_nonneg_of_le_pi_div_two {x y : ℝ} (hx₁ : 0 ≀ x) (hyβ‚‚ : y ≀ Ο€ / 2) (hxy : x < y) : cos y < cos x := cos_lt_cos_of_nonneg_of_le_pi hx₁ (hyβ‚‚.trans (by linarith)) hxy theorem strictAntiOn_cos : StrictAntiOn cos (Icc 0 Ο€) := fun _ hx _ hy hxy => cos_lt_cos_of_nonneg_of_le_pi hx.1 hy.2 hxy theorem cos_le_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≀ x) (hyβ‚‚ : y ≀ Ο€) (hxy : x ≀ y) : cos y ≀ cos x := (strictAntiOn_cos.le_iff_le ⟨hx₁.trans hxy, hyβ‚‚βŸ© ⟨hx₁, hxy.trans hyβ‚‚βŸ©).2 hxy theorem sin_le_sin_of_le_of_le_pi_div_two {x y : ℝ} (hx₁ : -(Ο€ / 2) ≀ x) (hyβ‚‚ : y ≀ Ο€ / 2) (hxy : x ≀ y) : sin x ≀ sin y := (strictMonoOn_sin.le_iff_le ⟨hx₁, hxy.trans hyβ‚‚βŸ© ⟨hx₁.trans hxy, hyβ‚‚βŸ©).2 hxy theorem injOn_sin : InjOn sin (Icc (-(Ο€ / 2)) (Ο€ / 2)) := strictMonoOn_sin.injOn theorem injOn_cos : InjOn cos (Icc 0 Ο€) := strictAntiOn_cos.injOn theorem surjOn_sin : SurjOn sin (Icc (-(Ο€ / 2)) (Ο€ / 2)) (Icc (-1) 1) := by simpa only [sin_neg, sin_pi_div_two] using intermediate_value_Icc (neg_le_self pi_div_two_pos.le) continuous_sin.continuousOn theorem surjOn_cos : SurjOn cos (Icc 0 Ο€) (Icc (-1) 1) := by simpa only [cos_zero, cos_pi] using intermediate_value_Icc' pi_pos.le continuous_cos.continuousOn theorem sin_mem_Icc (x : ℝ) : sin x ∈ Icc (-1 : ℝ) 1 := ⟨neg_one_le_sin x, sin_le_one x⟩ theorem cos_mem_Icc (x : ℝ) : cos x ∈ Icc (-1 : ℝ) 1 := ⟨neg_one_le_cos x, cos_le_one x⟩ theorem mapsTo_sin (s : Set ℝ) : MapsTo sin s (Icc (-1 : ℝ) 1) := fun x _ => sin_mem_Icc x theorem mapsTo_cos (s : Set ℝ) : MapsTo cos s (Icc (-1 : ℝ) 1) := fun x _ => cos_mem_Icc x theorem bijOn_sin : BijOn sin (Icc (-(Ο€ / 2)) (Ο€ / 2)) (Icc (-1) 1) := ⟨mapsTo_sin _, injOn_sin, surjOn_sin⟩ theorem bijOn_cos : BijOn cos (Icc 0 Ο€) (Icc (-1) 1) := ⟨mapsTo_cos _, injOn_cos, surjOn_cos⟩ @[simp] theorem range_cos : range cos = (Icc (-1) 1 : Set ℝ) := Subset.antisymm (range_subset_iff.2 cos_mem_Icc) surjOn_cos.subset_range @[simp] theorem range_sin : range sin = (Icc (-1) 1 : Set ℝ) := Subset.antisymm (range_subset_iff.2 sin_mem_Icc) surjOn_sin.subset_range theorem range_cos_infinite : (range Real.cos).Infinite := by rw [Real.range_cos] exact Icc_infinite (by norm_num) theorem range_sin_infinite : (range Real.sin).Infinite := by rw [Real.range_sin] exact Icc_infinite (by norm_num) section CosDivSq variable (x : ℝ) /-- the series `sqrtTwoAddSeries x n` is `sqrt(2 + sqrt(2 + ... ))` with `n` square roots, starting with `x`. We define it here because `cos (pi / 2 ^ (n+1)) = sqrtTwoAddSeries 0 n / 2` -/ @[simp] noncomputable def sqrtTwoAddSeries (x : ℝ) : β„• β†’ ℝ | 0 => x | n + 1 => √(2 + sqrtTwoAddSeries x n) theorem sqrtTwoAddSeries_zero : sqrtTwoAddSeries x 0 = x := by simp theorem sqrtTwoAddSeries_one : sqrtTwoAddSeries 0 1 = √2 := by simp theorem sqrtTwoAddSeries_two : sqrtTwoAddSeries 0 2 = √(2 + √2) := by simp theorem sqrtTwoAddSeries_zero_nonneg : βˆ€ n : β„•, 0 ≀ sqrtTwoAddSeries 0 n | 0 => le_refl 0 | _ + 1 => sqrt_nonneg _ theorem sqrtTwoAddSeries_nonneg {x : ℝ} (h : 0 ≀ x) : βˆ€ n : β„•, 0 ≀ sqrtTwoAddSeries x n | 0 => h | _ + 1 => sqrt_nonneg _ theorem sqrtTwoAddSeries_lt_two : βˆ€ n : β„•, sqrtTwoAddSeries 0 n < 2 | 0 => by norm_num | n + 1 => by refine lt_of_lt_of_le ?_ (sqrt_sq zero_lt_two.le).le rw [sqrtTwoAddSeries, sqrt_lt_sqrt_iff, ← lt_sub_iff_add_lt'] Β· refine (sqrtTwoAddSeries_lt_two n).trans_le ?_ norm_num Β· exact add_nonneg zero_le_two (sqrtTwoAddSeries_zero_nonneg n) theorem sqrtTwoAddSeries_succ (x : ℝ) : βˆ€ n : β„•, sqrtTwoAddSeries x (n + 1) = sqrtTwoAddSeries (√(2 + x)) n | 0 => rfl | n + 1 => by rw [sqrtTwoAddSeries, sqrtTwoAddSeries_succ _ _, sqrtTwoAddSeries] theorem sqrtTwoAddSeries_monotone_left {x y : ℝ} (h : x ≀ y) : βˆ€ n : β„•, sqrtTwoAddSeries x n ≀ sqrtTwoAddSeries y n | 0 => h | n + 1 => by rw [sqrtTwoAddSeries, sqrtTwoAddSeries] exact sqrt_le_sqrt (add_le_add_left (sqrtTwoAddSeries_monotone_left h _) _) @[simp] theorem cos_pi_over_two_pow : βˆ€ n : β„•, cos (Ο€ / 2 ^ (n + 1)) = sqrtTwoAddSeries 0 n / 2 | 0 => by simp | n + 1 => by have A : (1 : ℝ) < 2 ^ (n + 1) := one_lt_powβ‚€ one_lt_two n.succ_ne_zero have B : Ο€ / 2 ^ (n + 1) < Ο€ := div_lt_self pi_pos A have C : 0 < Ο€ / 2 ^ (n + 1) := by positivity rw [pow_succ, div_mul_eq_div_div, cos_half, cos_pi_over_two_pow n, sqrtTwoAddSeries, add_div_eq_mul_add_div, one_mul, ← div_mul_eq_div_div, sqrt_div, sqrt_mul_self] <;> linarith [sqrtTwoAddSeries_nonneg le_rfl n] theorem sin_sq_pi_over_two_pow (n : β„•) : sin (Ο€ / 2 ^ (n + 1)) ^ 2 = 1 - (sqrtTwoAddSeries 0 n / 2) ^ 2 := by rw [sin_sq, cos_pi_over_two_pow] theorem sin_sq_pi_over_two_pow_succ (n : β„•) : sin (Ο€ / 2 ^ (n + 2)) ^ 2 = 1 / 2 - sqrtTwoAddSeries 0 n / 4 := by rw [sin_sq_pi_over_two_pow, sqrtTwoAddSeries, div_pow, sq_sqrt, add_div, ← sub_sub] Β· congr Β· norm_num Β· norm_num Β· exact add_nonneg two_pos.le (sqrtTwoAddSeries_zero_nonneg _) @[simp] theorem sin_pi_over_two_pow_succ (n : β„•) : sin (Ο€ / 2 ^ (n + 2)) = √(2 - sqrtTwoAddSeries 0 n) / 2 := by rw [eq_div_iff_mul_eq two_ne_zero, eq_comm, sqrt_eq_iff_eq_sq, mul_pow, sin_sq_pi_over_two_pow_succ, sub_mul] Β· congr <;> norm_num Β· rw [sub_nonneg] exact (sqrtTwoAddSeries_lt_two _).le refine mul_nonneg (sin_nonneg_of_nonneg_of_le_pi ?_ ?_) zero_le_two Β· positivity Β· exact div_le_self pi_pos.le <| one_le_powβ‚€ one_le_two @[simp] theorem cos_pi_div_four : cos (Ο€ / 4) = √2 / 2 := by trans cos (Ο€ / 2 ^ 2) Β· congr norm_num Β· simp @[simp] theorem sin_pi_div_four : sin (Ο€ / 4) = √2 / 2 := by trans sin (Ο€ / 2 ^ 2) Β· congr norm_num Β· simp @[simp] theorem cos_pi_div_eight : cos (Ο€ / 8) = √(2 + √2) / 2 := by trans cos (Ο€ / 2 ^ 3) Β· congr norm_num Β· simp @[simp] theorem sin_pi_div_eight : sin (Ο€ / 8) = √(2 - √2) / 2 := by trans sin (Ο€ / 2 ^ 3) Β· congr norm_num Β· simp @[simp] theorem cos_pi_div_sixteen : cos (Ο€ / 16) = √(2 + √(2 + √2)) / 2 := by trans cos (Ο€ / 2 ^ 4) Β· congr norm_num Β· simp @[simp] theorem sin_pi_div_sixteen : sin (Ο€ / 16) = √(2 - √(2 + √2)) / 2 := by trans sin (Ο€ / 2 ^ 4) Β· congr norm_num Β· simp @[simp] theorem cos_pi_div_thirty_two : cos (Ο€ / 32) = √(2 + √(2 + √(2 + √2))) / 2 := by trans cos (Ο€ / 2 ^ 5) Β· congr norm_num Β· simp @[simp] theorem sin_pi_div_thirty_two : sin (Ο€ / 32) = √(2 - √(2 + √(2 + √2))) / 2 := by trans sin (Ο€ / 2 ^ 5) Β· congr norm_num Β· simp -- This section is also a convenient location for other explicit values of `sin` and `cos`. /-- The cosine of `Ο€ / 3` is `1 / 2`. -/ @[simp] theorem cos_pi_div_three : cos (Ο€ / 3) = 1 / 2 := by have h₁ : (2 * cos (Ο€ / 3) - 1) ^ 2 * (2 * cos (Ο€ / 3) + 2) = 0 := by have : cos (3 * (Ο€ / 3)) = cos Ο€ := by congr 1 ring linarith [cos_pi, cos_three_mul (Ο€ / 3)] rcases mul_eq_zero.mp h₁ with h | h Β· linarith [pow_eq_zero h] Β· have : cos Ο€ < cos (Ο€ / 3) := by refine cos_lt_cos_of_nonneg_of_le_pi ?_ le_rfl ?_ <;> linarith [pi_pos] linarith [cos_pi] /-- The cosine of `Ο€ / 6` is `√3 / 2`. -/ @[simp] theorem cos_pi_div_six : cos (Ο€ / 6) = √3 / 2 := by rw [show (6 : ℝ) = 3 * 2 by norm_num, div_mul_eq_div_div, cos_half, cos_pi_div_three, one_add_div, ← div_mul_eq_div_div, two_add_one_eq_three, sqrt_div, sqrt_mul_self] <;> linarith [pi_pos] /-- The square of the cosine of `Ο€ / 6` is `3 / 4` (this is sometimes more convenient than the result for cosine itself). -/ theorem sq_cos_pi_div_six : cos (Ο€ / 6) ^ 2 = 3 / 4 := by rw [cos_pi_div_six, div_pow, sq_sqrt] <;> norm_num /-- The sine of `Ο€ / 6` is `1 / 2`. -/ @[simp] theorem sin_pi_div_six : sin (Ο€ / 6) = 1 / 2 := by rw [← cos_pi_div_two_sub, ← cos_pi_div_three] congr ring /-- The square of the sine of `Ο€ / 3` is `3 / 4` (this is sometimes more convenient than the result for cosine itself). -/ theorem sq_sin_pi_div_three : sin (Ο€ / 3) ^ 2 = 3 / 4 := by rw [← cos_pi_div_two_sub, ← sq_cos_pi_div_six] congr ring /-- The sine of `Ο€ / 3` is `√3 / 2`. -/ @[simp] theorem sin_pi_div_three : sin (Ο€ / 3) = √3 / 2 := by rw [← cos_pi_div_two_sub, ← cos_pi_div_six] congr ring theorem quadratic_root_cos_pi_div_five : letI c := cos (Ο€ / 5) 4 * c ^ 2 - 2 * c - 1 = 0 := by set ΞΈ := Ο€ / 5 with hΞΈ set c := cos ΞΈ set s := sin ΞΈ suffices 2 * c = 4 * c ^ 2 - 1 by simp [this] have hs : s β‰  0 := by rw [ne_eq, sin_eq_zero_iff, hΞΈ] push_neg intro n hn replace hn : n * 5 = 1 := by field_simp [mul_comm _ Ο€, mul_assoc] at hn; norm_cast at hn omega suffices s * (2 * c) = s * (4 * c ^ 2 - 1) from mul_left_cancelβ‚€ hs this calc s * (2 * c) = 2 * s * c := by rw [← mul_assoc, mul_comm 2] _ = sin (2 * ΞΈ) := by rw [sin_two_mul] _ = sin (Ο€ - 2 * ΞΈ) := by rw [sin_pi_sub] _ = sin (2 * ΞΈ + ΞΈ) := by congr; field_simp [hΞΈ]; linarith _ = sin (2 * ΞΈ) * c + cos (2 * ΞΈ) * s := sin_add (2 * ΞΈ) ΞΈ _ = 2 * s * c * c + cos (2 * ΞΈ) * s := by rw [sin_two_mul] _ = 2 * s * c * c + (2 * c ^ 2 - 1) * s := by rw [cos_two_mul] _ = s * (2 * c * c) + s * (2 * c ^ 2 - 1) := by linarith _ = s * (4 * c ^ 2 - 1) := by linarith open Polynomial in theorem Polynomial.isRoot_cos_pi_div_five : (4 β€’ X ^ 2 - 2 β€’ X - C 1 : ℝ[X]).IsRoot (cos (Ο€ / 5)) := by simpa using quadratic_root_cos_pi_div_five /-- The cosine of `Ο€ / 5` is `(1 + √5) / 4`. -/ @[simp] theorem cos_pi_div_five : cos (Ο€ / 5) = (1 + √5) / 4 := by set c := cos (Ο€ / 5) have : 4 * (c * c) + (-2) * c + (-1) = 0 := by rw [← sq, neg_mul, ← sub_eq_add_neg, ← sub_eq_add_neg] exact quadratic_root_cos_pi_div_five have hd : discrim 4 (-2) (-1) = (2 * √5) * (2 * √5) := by norm_num [discrim, mul_mul_mul_comm] rcases (quadratic_eq_zero_iff (by norm_num) hd c).mp this with h | h Β· field_simp [h]; linarith Β· absurd (show 0 ≀ c from cos_nonneg_of_mem_Icc <| by constructor <;> linarith [pi_pos.le]) rw [not_le, h] exact div_neg_of_neg_of_pos (by norm_num [lt_sqrt]) (by positivity) end CosDivSq /-- `Real.sin` as an `OrderIso` between `[-(Ο€ / 2), Ο€ / 2]` and `[-1, 1]`. -/ def sinOrderIso : Icc (-(Ο€ / 2)) (Ο€ / 2) ≃o Icc (-1 : ℝ) 1 := (strictMonoOn_sin.orderIso _ _).trans <| OrderIso.setCongr _ _ bijOn_sin.image_eq @[simp] theorem coe_sinOrderIso_apply (x : Icc (-(Ο€ / 2)) (Ο€ / 2)) : (sinOrderIso x : ℝ) = sin x := rfl theorem sinOrderIso_apply (x : Icc (-(Ο€ / 2)) (Ο€ / 2)) : sinOrderIso x = ⟨sin x, sin_mem_Icc x⟩ := rfl @[simp] theorem tan_pi_div_four : tan (Ο€ / 4) = 1 := by rw [tan_eq_sin_div_cos, cos_pi_div_four, sin_pi_div_four] have h : √2 / 2 > 0 := by positivity exact div_self (ne_of_gt h) @[simp] theorem tan_pi_div_two : tan (Ο€ / 2) = 0 := by simp [tan_eq_sin_div_cos] @[simp] theorem tan_pi_div_six : tan (Ο€ / 6) = 1 / sqrt 3 := by rw [tan_eq_sin_div_cos, sin_pi_div_six, cos_pi_div_six] ring @[simp] theorem tan_pi_div_three : tan (Ο€ / 3) = sqrt 3 := by rw [tan_eq_sin_div_cos, sin_pi_div_three, cos_pi_div_three] ring theorem tan_pos_of_pos_of_lt_pi_div_two {x : ℝ} (h0x : 0 < x) (hxp : x < Ο€ / 2) : 0 < tan x := by rw [tan_eq_sin_div_cos] exact div_pos (sin_pos_of_pos_of_lt_pi h0x (by linarith)) (cos_pos_of_mem_Ioo ⟨by linarith, hxp⟩) theorem tan_nonneg_of_nonneg_of_le_pi_div_two {x : ℝ} (h0x : 0 ≀ x) (hxp : x ≀ Ο€ / 2) : 0 ≀ tan x := match lt_or_eq_of_le h0x, lt_or_eq_of_le hxp with | Or.inl hx0, Or.inl hxp => le_of_lt (tan_pos_of_pos_of_lt_pi_div_two hx0 hxp) | Or.inl _, Or.inr hxp => by simp [hxp, tan_eq_sin_div_cos] | Or.inr hx0, _ => by simp [hx0.symm] theorem tan_neg_of_neg_of_pi_div_two_lt {x : ℝ} (hx0 : x < 0) (hpx : -(Ο€ / 2) < x) : tan x < 0 := neg_pos.1 (tan_neg x β–Έ tan_pos_of_pos_of_lt_pi_div_two (by linarith) (by linarith [pi_pos])) theorem tan_nonpos_of_nonpos_of_neg_pi_div_two_le {x : ℝ} (hx0 : x ≀ 0) (hpx : -(Ο€ / 2) ≀ x) : tan x ≀ 0 := neg_nonneg.1 (tan_neg x β–Έ tan_nonneg_of_nonneg_of_le_pi_div_two (by linarith) (by linarith)) theorem strictMonoOn_tan : StrictMonoOn tan (Ioo (-(Ο€ / 2)) (Ο€ / 2)) := by rintro x hx y hy hlt rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos, div_lt_div_iffβ‚€ (cos_pos_of_mem_Ioo hx) (cos_pos_of_mem_Ioo hy), mul_comm, ← sub_pos, ← sin_sub] exact sin_pos_of_pos_of_lt_pi (sub_pos.2 hlt) <| by linarith [hx.1, hy.2] theorem tan_lt_tan_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(Ο€ / 2) < x) (hyβ‚‚ : y < Ο€ / 2) (hxy : x < y) : tan x < tan y := strictMonoOn_tan ⟨hx₁, hxy.trans hyβ‚‚βŸ© ⟨hx₁.trans hxy, hyβ‚‚βŸ© hxy theorem tan_lt_tan_of_nonneg_of_lt_pi_div_two {x y : ℝ} (hx₁ : 0 ≀ x) (hyβ‚‚ : y < Ο€ / 2) (hxy : x < y) : tan x < tan y := tan_lt_tan_of_lt_of_lt_pi_div_two (by linarith) hyβ‚‚ hxy theorem injOn_tan : InjOn tan (Ioo (-(Ο€ / 2)) (Ο€ / 2)) := strictMonoOn_tan.injOn theorem tan_inj_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(Ο€ / 2) < x) (hxβ‚‚ : x < Ο€ / 2) (hy₁ : -(Ο€ / 2) < y) (hyβ‚‚ : y < Ο€ / 2) (hxy : tan x = tan y) : x = y := injOn_tan ⟨hx₁, hxβ‚‚βŸ© ⟨hy₁, hyβ‚‚βŸ© hxy theorem tan_periodic : Function.Periodic tan Ο€ := by simpa only [Function.Periodic, tan_eq_sin_div_cos] using sin_antiperiodic.div cos_antiperiodic @[simp] theorem tan_pi : tan Ο€ = 0 := by rw [tan_periodic.eq, tan_zero] theorem tan_add_pi (x : ℝ) : tan (x + Ο€) = tan x := tan_periodic x theorem tan_sub_pi (x : ℝ) : tan (x - Ο€) = tan x := tan_periodic.sub_eq x theorem tan_pi_sub (x : ℝ) : tan (Ο€ - x) = -tan x := tan_neg x β–Έ tan_periodic.sub_eq' theorem tan_pi_div_two_sub (x : ℝ) : tan (Ο€ / 2 - x) = (tan x)⁻¹ := by rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos, inv_div, sin_pi_div_two_sub, cos_pi_div_two_sub] theorem tan_nat_mul_pi (n : β„•) : tan (n * Ο€) = 0 := tan_zero β–Έ tan_periodic.nat_mul_eq n theorem tan_int_mul_pi (n : β„€) : tan (n * Ο€) = 0 := tan_zero β–Έ tan_periodic.int_mul_eq n theorem tan_add_nat_mul_pi (x : ℝ) (n : β„•) : tan (x + n * Ο€) = tan x := tan_periodic.nat_mul n x theorem tan_add_int_mul_pi (x : ℝ) (n : β„€) : tan (x + n * Ο€) = tan x := tan_periodic.int_mul n x theorem tan_sub_nat_mul_pi (x : ℝ) (n : β„•) : tan (x - n * Ο€) = tan x := tan_periodic.sub_nat_mul_eq n theorem tan_sub_int_mul_pi (x : ℝ) (n : β„€) : tan (x - n * Ο€) = tan x := tan_periodic.sub_int_mul_eq n theorem tan_nat_mul_pi_sub (x : ℝ) (n : β„•) : tan (n * Ο€ - x) = -tan x := tan_neg x β–Έ tan_periodic.nat_mul_sub_eq n theorem tan_int_mul_pi_sub (x : ℝ) (n : β„€) : tan (n * Ο€ - x) = -tan x := tan_neg x β–Έ tan_periodic.int_mul_sub_eq n theorem tendsto_sin_pi_div_two : Tendsto sin (𝓝[<] (Ο€ / 2)) (𝓝 1) := by convert continuous_sin.continuousWithinAt.tendsto simp theorem tendsto_cos_pi_div_two : Tendsto cos (𝓝[<] (Ο€ / 2)) (𝓝[>] 0) := by apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within Β· convert continuous_cos.continuousWithinAt.tendsto simp Β· filter_upwards [Ioo_mem_nhdsLT (neg_lt_self pi_div_two_pos)] with x hx exact cos_pos_of_mem_Ioo hx theorem tendsto_tan_pi_div_two : Tendsto tan (𝓝[<] (Ο€ / 2)) atTop := by convert tendsto_cos_pi_div_two.inv_tendsto_nhdsGT_zero.atTop_mul_pos zero_lt_one tendsto_sin_pi_div_two using 1 simp only [Pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos] theorem tendsto_sin_neg_pi_div_two : Tendsto sin (𝓝[>] (-(Ο€ / 2))) (𝓝 (-1)) := by convert continuous_sin.continuousWithinAt.tendsto using 2 simp theorem tendsto_cos_neg_pi_div_two : Tendsto cos (𝓝[>] (-(Ο€ / 2))) (𝓝[>] 0) := by apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within Β· convert continuous_cos.continuousWithinAt.tendsto simp Β· filter_upwards [Ioo_mem_nhdsGT (neg_lt_self pi_div_two_pos)] with x hx exact cos_pos_of_mem_Ioo hx theorem tendsto_tan_neg_pi_div_two : Tendsto tan (𝓝[>] (-(Ο€ / 2))) atBot := by convert tendsto_cos_neg_pi_div_two.inv_tendsto_nhdsGT_zero.atTop_mul_neg (by norm_num) tendsto_sin_neg_pi_div_two using 1 simp only [Pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos] end Real namespace Complex open Real theorem sin_eq_zero_iff_cos_eq {z : β„‚} : sin z = 0 ↔ cos z = 1 ∨ cos z = -1 := by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq, sq, sq, ← sub_eq_iff_eq_add, sub_self] exact ⟨fun h => by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ Eq.symm⟩ @[simp] theorem cos_pi_div_two : cos (Ο€ / 2) = 0 := calc cos (Ο€ / 2) = Real.cos (Ο€ / 2) := by rw [ofReal_cos]; simp _ = 0 := by simp @[simp] theorem sin_pi_div_two : sin (Ο€ / 2) = 1 := calc sin (Ο€ / 2) = Real.sin (Ο€ / 2) := by rw [ofReal_sin]; simp _ = 1 := by simp @[simp] theorem sin_pi : sin Ο€ = 0 := by rw [← ofReal_sin, Real.sin_pi]; simp @[simp] theorem cos_pi : cos Ο€ = -1 := by rw [← ofReal_cos, Real.cos_pi]; simp @[simp] theorem sin_two_pi : sin (2 * Ο€) = 0 := by simp [two_mul, sin_add] @[simp] theorem cos_two_pi : cos (2 * Ο€) = 1 := by simp [two_mul, cos_add] theorem sin_antiperiodic : Function.Antiperiodic sin Ο€ := by simp [sin_add] theorem sin_periodic : Function.Periodic sin (2 * Ο€) := sin_antiperiodic.periodic_two_mul theorem sin_add_pi (x : β„‚) : sin (x + Ο€) = -sin x := sin_antiperiodic x theorem sin_add_two_pi (x : β„‚) : sin (x + 2 * Ο€) = sin x := sin_periodic x theorem sin_sub_pi (x : β„‚) : sin (x - Ο€) = -sin x := sin_antiperiodic.sub_eq x theorem sin_sub_two_pi (x : β„‚) : sin (x - 2 * Ο€) = sin x := sin_periodic.sub_eq x theorem sin_pi_sub (x : β„‚) : sin (Ο€ - x) = sin x := neg_neg (sin x) β–Έ sin_neg x β–Έ sin_antiperiodic.sub_eq' theorem sin_two_pi_sub (x : β„‚) : sin (2 * Ο€ - x) = -sin x := sin_neg x β–Έ sin_periodic.sub_eq' theorem sin_nat_mul_pi (n : β„•) : sin (n * Ο€) = 0 := sin_antiperiodic.nat_mul_eq_of_eq_zero sin_zero n theorem sin_int_mul_pi (n : β„€) : sin (n * Ο€) = 0 := sin_antiperiodic.int_mul_eq_of_eq_zero sin_zero n theorem sin_add_nat_mul_two_pi (x : β„‚) (n : β„•) : sin (x + n * (2 * Ο€)) = sin x := sin_periodic.nat_mul n x theorem sin_add_int_mul_two_pi (x : β„‚) (n : β„€) : sin (x + n * (2 * Ο€)) = sin x := sin_periodic.int_mul n x theorem sin_sub_nat_mul_two_pi (x : β„‚) (n : β„•) : sin (x - n * (2 * Ο€)) = sin x := sin_periodic.sub_nat_mul_eq n theorem sin_sub_int_mul_two_pi (x : β„‚) (n : β„€) : sin (x - n * (2 * Ο€)) = sin x := sin_periodic.sub_int_mul_eq n theorem sin_nat_mul_two_pi_sub (x : β„‚) (n : β„•) : sin (n * (2 * Ο€) - x) = -sin x := sin_neg x β–Έ sin_periodic.nat_mul_sub_eq n theorem sin_int_mul_two_pi_sub (x : β„‚) (n : β„€) : sin (n * (2 * Ο€) - x) = -sin x := sin_neg x β–Έ sin_periodic.int_mul_sub_eq n theorem cos_antiperiodic : Function.Antiperiodic cos Ο€ := by simp [cos_add] theorem cos_periodic : Function.Periodic cos (2 * Ο€) := cos_antiperiodic.periodic_two_mul theorem cos_add_pi (x : β„‚) : cos (x + Ο€) = -cos x := cos_antiperiodic x theorem cos_add_two_pi (x : β„‚) : cos (x + 2 * Ο€) = cos x := cos_periodic x theorem cos_sub_pi (x : β„‚) : cos (x - Ο€) = -cos x := cos_antiperiodic.sub_eq x theorem cos_sub_two_pi (x : β„‚) : cos (x - 2 * Ο€) = cos x := cos_periodic.sub_eq x theorem cos_pi_sub (x : β„‚) : cos (Ο€ - x) = -cos x := cos_neg x β–Έ cos_antiperiodic.sub_eq' theorem cos_two_pi_sub (x : β„‚) : cos (2 * Ο€ - x) = cos x := cos_neg x β–Έ cos_periodic.sub_eq' theorem cos_nat_mul_two_pi (n : β„•) : cos (n * (2 * Ο€)) = 1 := (cos_periodic.nat_mul_eq n).trans cos_zero theorem cos_int_mul_two_pi (n : β„€) : cos (n * (2 * Ο€)) = 1 := (cos_periodic.int_mul_eq n).trans cos_zero theorem cos_add_nat_mul_two_pi (x : β„‚) (n : β„•) : cos (x + n * (2 * Ο€)) = cos x := cos_periodic.nat_mul n x theorem cos_add_int_mul_two_pi (x : β„‚) (n : β„€) : cos (x + n * (2 * Ο€)) = cos x := cos_periodic.int_mul n x theorem cos_sub_nat_mul_two_pi (x : β„‚) (n : β„•) : cos (x - n * (2 * Ο€)) = cos x := cos_periodic.sub_nat_mul_eq n theorem cos_sub_int_mul_two_pi (x : β„‚) (n : β„€) : cos (x - n * (2 * Ο€)) = cos x := cos_periodic.sub_int_mul_eq n theorem cos_nat_mul_two_pi_sub (x : β„‚) (n : β„•) : cos (n * (2 * Ο€) - x) = cos x := cos_neg x β–Έ cos_periodic.nat_mul_sub_eq n theorem cos_int_mul_two_pi_sub (x : β„‚) (n : β„€) : cos (n * (2 * Ο€) - x) = cos x := cos_neg x β–Έ cos_periodic.int_mul_sub_eq n theorem cos_nat_mul_two_pi_add_pi (n : β„•) : cos (n * (2 * Ο€) + Ο€) = -1 := by simpa only [cos_zero] using (cos_periodic.nat_mul n).add_antiperiod_eq cos_antiperiodic theorem cos_int_mul_two_pi_add_pi (n : β„€) : cos (n * (2 * Ο€) + Ο€) = -1 := by simpa only [cos_zero] using (cos_periodic.int_mul n).add_antiperiod_eq cos_antiperiodic theorem cos_nat_mul_two_pi_sub_pi (n : β„•) : cos (n * (2 * Ο€) - Ο€) = -1 := by simpa only [cos_zero] using (cos_periodic.nat_mul n).sub_antiperiod_eq cos_antiperiodic theorem cos_int_mul_two_pi_sub_pi (n : β„€) : cos (n * (2 * Ο€) - Ο€) = -1 := by simpa only [cos_zero] using (cos_periodic.int_mul n).sub_antiperiod_eq cos_antiperiodic theorem sin_add_pi_div_two (x : β„‚) : sin (x + Ο€ / 2) = cos x := by simp [sin_add] theorem sin_sub_pi_div_two (x : β„‚) : sin (x - Ο€ / 2) = -cos x := by simp [sub_eq_add_neg, sin_add] theorem sin_pi_div_two_sub (x : β„‚) : sin (Ο€ / 2 - x) = cos x := by simp [sub_eq_add_neg, sin_add] theorem cos_add_pi_div_two (x : β„‚) : cos (x + Ο€ / 2) = -sin x := by simp [cos_add] theorem cos_sub_pi_div_two (x : β„‚) : cos (x - Ο€ / 2) = sin x := by simp [sub_eq_add_neg, cos_add] theorem cos_pi_div_two_sub (x : β„‚) : cos (Ο€ / 2 - x) = sin x := by rw [← cos_neg, neg_sub, cos_sub_pi_div_two] theorem tan_periodic : Function.Periodic tan Ο€ := by simpa only [tan_eq_sin_div_cos] using sin_antiperiodic.div cos_antiperiodic theorem tan_add_pi (x : β„‚) : tan (x + Ο€) = tan x := tan_periodic x theorem tan_sub_pi (x : β„‚) : tan (x - Ο€) = tan x := tan_periodic.sub_eq x theorem tan_pi_sub (x : β„‚) : tan (Ο€ - x) = -tan x := tan_neg x β–Έ tan_periodic.sub_eq' theorem tan_pi_div_two_sub (x : β„‚) : tan (Ο€ / 2 - x) = (tan x)⁻¹ := by rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos, inv_div, sin_pi_div_two_sub, cos_pi_div_two_sub] theorem tan_nat_mul_pi (n : β„•) : tan (n * Ο€) = 0 := tan_zero β–Έ tan_periodic.nat_mul_eq n theorem tan_int_mul_pi (n : β„€) : tan (n * Ο€) = 0 := tan_zero β–Έ tan_periodic.int_mul_eq n theorem tan_add_nat_mul_pi (x : β„‚) (n : β„•) : tan (x + n * Ο€) = tan x := tan_periodic.nat_mul n x theorem tan_add_int_mul_pi (x : β„‚) (n : β„€) : tan (x + n * Ο€) = tan x := tan_periodic.int_mul n x theorem tan_sub_nat_mul_pi (x : β„‚) (n : β„•) : tan (x - n * Ο€) = tan x := tan_periodic.sub_nat_mul_eq n theorem tan_sub_int_mul_pi (x : β„‚) (n : β„€) : tan (x - n * Ο€) = tan x := tan_periodic.sub_int_mul_eq n theorem tan_nat_mul_pi_sub (x : β„‚) (n : β„•) : tan (n * Ο€ - x) = -tan x := tan_neg x β–Έ tan_periodic.nat_mul_sub_eq n theorem tan_int_mul_pi_sub (x : β„‚) (n : β„€) : tan (n * Ο€ - x) = -tan x := tan_neg x β–Έ tan_periodic.int_mul_sub_eq n theorem exp_antiperiodic : Function.Antiperiodic exp (Ο€ * I) := by simp [exp_add, exp_mul_I] theorem exp_periodic : Function.Periodic exp (2 * Ο€ * I) := (mul_assoc (2 : β„‚) Ο€ I).symm β–Έ exp_antiperiodic.periodic_two_mul theorem exp_mul_I_antiperiodic : Function.Antiperiodic (fun x => exp (x * I)) Ο€ := by simpa only [mul_inv_cancel_rightβ‚€ I_ne_zero] using exp_antiperiodic.mul_const I_ne_zero theorem exp_mul_I_periodic : Function.Periodic (fun x => exp (x * I)) (2 * Ο€) := exp_mul_I_antiperiodic.periodic_two_mul @[simp] theorem exp_pi_mul_I : exp (Ο€ * I) = -1 := exp_zero β–Έ exp_antiperiodic.eq @[simp] theorem exp_two_pi_mul_I : exp (2 * Ο€ * I) = 1 := exp_periodic.eq.trans exp_zero @[simp] lemma exp_pi_div_two_mul_I : exp (Ο€ / 2 * I) = I := by rw [← cos_add_sin_I, cos_pi_div_two, sin_pi_div_two, one_mul, zero_add] @[simp] lemma exp_neg_pi_div_two_mul_I : exp (-Ο€ / 2 * I) = -I := by rw [← cos_add_sin_I, neg_div, cos_neg, cos_pi_div_two, sin_neg, sin_pi_div_two, zero_add, neg_mul, one_mul] @[simp] theorem exp_nat_mul_two_pi_mul_I (n : β„•) : exp (n * (2 * Ο€ * I)) = 1 := (exp_periodic.nat_mul_eq n).trans exp_zero @[simp] theorem exp_int_mul_two_pi_mul_I (n : β„€) : exp (n * (2 * Ο€ * I)) = 1 := (exp_periodic.int_mul_eq n).trans exp_zero @[simp] theorem exp_add_pi_mul_I (z : β„‚) : exp (z + Ο€ * I) = -exp z := exp_antiperiodic z @[simp] theorem exp_sub_pi_mul_I (z : β„‚) : exp (z - Ο€ * I) = -exp z := exp_antiperiodic.sub_eq z /-- A supporting lemma for the **Phragmen-LindelΓΆf principle** in a horizontal strip. If `z : β„‚` belongs to a horizontal strip `|Complex.im z| ≀ b`, `b ≀ Ο€ / 2`, and `a ≀ 0`, then $$\left|exp^{a\left(e^{z}+e^{-z}\right)}\right| \le e^{a\cos b \exp^{|re z|}}.$$ -/ theorem norm_exp_mul_exp_add_exp_neg_le_of_abs_im_le {a b : ℝ} (ha : a ≀ 0) {z : β„‚} (hz : |z.im| ≀ b) (hb : b ≀ Ο€ / 2) : β€–exp (a * (exp z + exp (-z)))β€– ≀ Real.exp (a * Real.cos b * Real.exp |z.re|) := by simp only [norm_exp, Real.exp_le_exp, re_ofReal_mul, add_re, exp_re, neg_im, Real.cos_neg, ← add_mul, mul_assoc, mul_comm (Real.cos b), neg_re, ← Real.cos_abs z.im] have : Real.exp |z.re| ≀ Real.exp z.re + Real.exp (-z.re) := apply_abs_le_add_of_nonneg (fun x => (Real.exp_pos x).le) z.re refine mul_le_mul_of_nonpos_left (mul_le_mul this ?_ ?_ ((Real.exp_pos _).le.trans this)) ha Β· exact Real.cos_le_cos_of_nonneg_of_le_pi (_root_.abs_nonneg _) (hb.trans <| half_le_self <| Real.pi_pos.le) hz Β· refine Real.cos_nonneg_of_mem_Icc ⟨?_, hb⟩ exact (neg_nonpos.2 <| Real.pi_div_two_pos.le).trans ((_root_.abs_nonneg _).trans hz) @[deprecated (since := "2025-02-16")] alias abs_exp_mul_exp_add_exp_neg_le_of_abs_im_le := norm_exp_mul_exp_add_exp_neg_le_of_abs_im_le end Complex
Mathlib/Analysis/SpecialFunctions/Trigonometric/Basic.lean
1,301
1,301
/- Copyright (c) 2020 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker -/ import Mathlib.Analysis.Calculus.Deriv.Inv import Mathlib.Analysis.Calculus.Deriv.MeanValue /-! # L'HΓ΄pital's rule for 0/0 indeterminate forms In this file, we prove several forms of "L'HΓ΄pital's rule" for computing 0/0 indeterminate forms. The proof of `HasDerivAt.lhopital_zero_right_on_Ioo` is based on the one given in the corresponding [Wikibooks](https://en.wikibooks.org/wiki/Calculus/L%27H%C3%B4pital%27s_Rule) chapter, and all other statements are derived from this one by composing by carefully chosen functions. Note that the filter `f'/g'` tends to isn't required to be one of `𝓝 a`, `atTop` or `atBot`. In fact, we give a slightly stronger statement by allowing it to be any filter on `ℝ`. Each statement is available in a `HasDerivAt` form and a `deriv` form, which is denoted by each statement being in either the `HasDerivAt` or the `deriv` namespace. ## Tags L'HΓ΄pital's rule, L'Hopital's rule -/ open Filter Set open scoped Filter Topology Pointwise variable {a b : ℝ} {l : Filter ℝ} {f f' g g' : ℝ β†’ ℝ} /-! ## Interval-based versions We start by proving statements where all conditions (derivability, `g' β‰  0`) have to be satisfied on an explicitly-provided interval. -/ namespace HasDerivAt theorem lhopital_zero_right_on_Ioo (hab : a < b) (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hg' : βˆ€ x ∈ Ioo a b, g' x β‰  0) (hfa : Tendsto f (𝓝[>] a) (𝓝 0)) (hga : Tendsto g (𝓝[>] a) (𝓝 0)) (hdiv : Tendsto (fun x => f' x / g' x) (𝓝[>] a) l) : Tendsto (fun x => f x / g x) (𝓝[>] a) l := by have sub : βˆ€ x ∈ Ioo a b, Ioo a x βŠ† Ioo a b := fun x hx => Ioo_subset_Ioo (le_refl a) (le_of_lt hx.2) have hg : βˆ€ x ∈ Ioo a b, g x β‰  0 := by intro x hx h have : Tendsto g (𝓝[<] x) (𝓝 0) := by rw [← h, ← nhdsWithin_Ioo_eq_nhdsLT hx.1] exact ((hgg' x hx).continuousAt.continuousWithinAt.mono <| sub x hx).tendsto obtain ⟨y, hyx, hy⟩ : βˆƒ c ∈ Ioo a x, g' c = 0 := exists_hasDerivAt_eq_zero' hx.1 hga this fun y hy => hgg' y <| sub x hx hy exact hg' y (sub x hx hyx) hy have : βˆ€ x ∈ Ioo a b, βˆƒ c ∈ Ioo a x, f x * g' c = g x * f' c := by intro x hx rw [← sub_zero (f x), ← sub_zero (g x)] exact exists_ratio_hasDerivAt_eq_ratio_slope' g g' hx.1 f f' (fun y hy => hgg' y <| sub x hx hy) (fun y hy => hff' y <| sub x hx hy) hga hfa (tendsto_nhdsWithin_of_tendsto_nhds (hgg' x hx).continuousAt.tendsto) (tendsto_nhdsWithin_of_tendsto_nhds (hff' x hx).continuousAt.tendsto) choose! c hc using this have : βˆ€ x ∈ Ioo a b, ((fun x' => f' x' / g' x') ∘ c) x = f x / g x := by intro x hx rcases hc x hx with ⟨h₁, hβ‚‚βŸ© field_simp [hg x hx, hg' (c x) ((sub x hx) h₁)] simp only [hβ‚‚] rw [mul_comm] have cmp : βˆ€ x ∈ Ioo a b, a < c x ∧ c x < x := fun x hx => (hc x hx).1 rw [← nhdsWithin_Ioo_eq_nhdsGT hab] apply tendsto_nhdsWithin_congr this apply hdiv.comp refine tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ (tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds (tendsto_nhdsWithin_of_tendsto_nhds tendsto_id) ?_ ?_) ?_ all_goals apply eventually_nhdsWithin_of_forall intro x hx have := cmp x hx try simp linarith [this] theorem lhopital_zero_right_on_Ico (hab : a < b) (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hcf : ContinuousOn f (Ico a b)) (hcg : ContinuousOn g (Ico a b)) (hg' : βˆ€ x ∈ Ioo a b, g' x β‰  0) (hfa : f a = 0) (hga : g a = 0) (hdiv : Tendsto (fun x => f' x / g' x) (𝓝[>] a) l) : Tendsto (fun x => f x / g x) (𝓝[>] a) l := by refine lhopital_zero_right_on_Ioo hab hff' hgg' hg' ?_ ?_ hdiv Β· rw [← hfa, ← nhdsWithin_Ioo_eq_nhdsGT hab] exact ((hcf a <| left_mem_Ico.mpr hab).mono Ioo_subset_Ico_self).tendsto Β· rw [← hga, ← nhdsWithin_Ioo_eq_nhdsGT hab] exact ((hcg a <| left_mem_Ico.mpr hab).mono Ioo_subset_Ico_self).tendsto theorem lhopital_zero_left_on_Ioo (hab : a < b) (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hg' : βˆ€ x ∈ Ioo a b, g' x β‰  0) (hfb : Tendsto f (𝓝[<] b) (𝓝 0)) (hgb : Tendsto g (𝓝[<] b) (𝓝 0)) (hdiv : Tendsto (fun x => f' x / g' x) (𝓝[<] b) l) : Tendsto (fun x => f x / g x) (𝓝[<] b) l := by -- Here, we essentially compose by `Neg.neg`. The following is mostly technical details. have hdnf : βˆ€ x ∈ -Ioo a b, HasDerivAt (f ∘ Neg.neg) (f' (-x) * -1) x := fun x hx => comp x (hff' (-x) hx) (hasDerivAt_neg x) have hdng : βˆ€ x ∈ -Ioo a b, HasDerivAt (g ∘ Neg.neg) (g' (-x) * -1) x := fun x hx => comp x (hgg' (-x) hx) (hasDerivAt_neg x) rw [neg_Ioo] at hdnf rw [neg_Ioo] at hdng have := lhopital_zero_right_on_Ioo (neg_lt_neg hab) hdnf hdng (by intro x hx h apply hg' _ (by rw [← neg_Ioo] at hx; exact hx) rwa [mul_comm, ← neg_eq_neg_one_mul, neg_eq_zero] at h) (hfb.comp tendsto_neg_nhdsGT_neg) (hgb.comp tendsto_neg_nhdsGT_neg) (by simp only [neg_div_neg_eq, mul_one, mul_neg] exact hdiv.comp tendsto_neg_nhdsGT_neg) have := this.comp tendsto_neg_nhdsLT unfold Function.comp at this simpa only [neg_neg] theorem lhopital_zero_left_on_Ioc (hab : a < b) (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hcf : ContinuousOn f (Ioc a b)) (hcg : ContinuousOn g (Ioc a b)) (hg' : βˆ€ x ∈ Ioo a b, g' x β‰  0) (hfb : f b = 0) (hgb : g b = 0) (hdiv : Tendsto (fun x => f' x / g' x) (𝓝[<] b) l) : Tendsto (fun x => f x / g x) (𝓝[<] b) l := by refine lhopital_zero_left_on_Ioo hab hff' hgg' hg' ?_ ?_ hdiv Β· rw [← hfb, ← nhdsWithin_Ioo_eq_nhdsLT hab] exact ((hcf b <| right_mem_Ioc.mpr hab).mono Ioo_subset_Ioc_self).tendsto Β· rw [← hgb, ← nhdsWithin_Ioo_eq_nhdsLT hab] exact ((hcg b <| right_mem_Ioc.mpr hab).mono Ioo_subset_Ioc_self).tendsto theorem lhopital_zero_atTop_on_Ioi (hff' : βˆ€ x ∈ Ioi a, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioi a, HasDerivAt g (g' x) x) (hg' : βˆ€ x ∈ Ioi a, g' x β‰  0) (hftop : Tendsto f atTop (𝓝 0)) (hgtop : Tendsto g atTop (𝓝 0)) (hdiv : Tendsto (fun x => f' x / g' x) atTop l) : Tendsto (fun x => f x / g x) atTop l := by obtain ⟨a', haa', ha'⟩ : βˆƒ a', a < a' ∧ 0 < a' := ⟨1 + max a 0, ⟨lt_of_le_of_lt (le_max_left a 0) (lt_one_add _), lt_of_le_of_lt (le_max_right a 0) (lt_one_add _)⟩⟩ have fact1 : βˆ€ x : ℝ, x ∈ Ioo 0 a'⁻¹ β†’ x β‰  0 := fun _ hx => (ne_of_lt hx.1).symm have fact2 (x) (hx : x ∈ Ioo 0 a'⁻¹) : a < x⁻¹ := lt_trans haa' ((lt_inv_commβ‚€ ha' hx.1).mpr hx.2) have hdnf : βˆ€ x ∈ Ioo 0 a'⁻¹, HasDerivAt (f ∘ Inv.inv) (f' x⁻¹ * -(x ^ 2)⁻¹) x := fun x hx => comp x (hff' x⁻¹ <| fact2 x hx) (hasDerivAt_inv <| fact1 x hx) have hdng : βˆ€ x ∈ Ioo 0 a'⁻¹, HasDerivAt (g ∘ Inv.inv) (g' x⁻¹ * -(x ^ 2)⁻¹) x := fun x hx => comp x (hgg' x⁻¹ <| fact2 x hx) (hasDerivAt_inv <| fact1 x hx) have := lhopital_zero_right_on_Ioo (inv_pos.mpr ha') hdnf hdng (by intro x hx refine mul_ne_zero ?_ (neg_ne_zero.mpr <| inv_ne_zero <| pow_ne_zero _ <| fact1 x hx) exact hg' _ (fact2 x hx)) (hftop.comp tendsto_inv_nhdsGT_zero) (hgtop.comp tendsto_inv_nhdsGT_zero) (by refine (tendsto_congr' ?_).mp (hdiv.comp tendsto_inv_nhdsGT_zero) filter_upwards [self_mem_nhdsWithin] with x (hx : 0 < x) simp only [Function.comp_def] rw [mul_div_mul_right] exact neg_ne_zero.mpr (by positivity)) have := this.comp tendsto_inv_atTop_nhdsGT_zero unfold Function.comp at this simpa only [inv_inv] theorem lhopital_zero_atBot_on_Iio (hff' : βˆ€ x ∈ Iio a, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Iio a, HasDerivAt g (g' x) x) (hg' : βˆ€ x ∈ Iio a, g' x β‰  0) (hfbot : Tendsto f atBot (𝓝 0)) (hgbot : Tendsto g atBot (𝓝 0)) (hdiv : Tendsto (fun x => f' x / g' x) atBot l) : Tendsto (fun x => f x / g x) atBot l := by -- Here, we essentially compose by `Neg.neg`. The following is mostly technical details. have hdnf : βˆ€ x ∈ -Iio a, HasDerivAt (f ∘ Neg.neg) (f' (-x) * -1) x := fun x hx => comp x (hff' (-x) hx) (hasDerivAt_neg x) have hdng : βˆ€ x ∈ -Iio a, HasDerivAt (g ∘ Neg.neg) (g' (-x) * -1) x := fun x hx => comp x (hgg' (-x) hx) (hasDerivAt_neg x) rw [neg_Iio] at hdnf rw [neg_Iio] at hdng have := lhopital_zero_atTop_on_Ioi hdnf hdng (by intro x hx h apply hg' _ (by rw [← neg_Iio] at hx; exact hx) rwa [mul_comm, ← neg_eq_neg_one_mul, neg_eq_zero] at h) (hfbot.comp tendsto_neg_atTop_atBot) (hgbot.comp tendsto_neg_atTop_atBot) (by simp only [mul_one, mul_neg, neg_div_neg_eq] exact (hdiv.comp tendsto_neg_atTop_atBot)) have := this.comp tendsto_neg_atBot_atTop unfold Function.comp at this simpa only [neg_neg] end HasDerivAt namespace deriv theorem lhopital_zero_right_on_Ioo (hab : a < b) (hdf : DifferentiableOn ℝ f (Ioo a b)) (hg' : βˆ€ x ∈ Ioo a b, deriv g x β‰  0) (hfa : Tendsto f (𝓝[>] a) (𝓝 0)) (hga : Tendsto g (𝓝[>] a) (𝓝 0)) (hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) (𝓝[>] a) l) : Tendsto (fun x => f x / g x) (𝓝[>] a) l := by have hdf : βˆ€ x ∈ Ioo a b, DifferentiableAt ℝ f x := fun x hx => (hdf x hx).differentiableAt (Ioo_mem_nhds hx.1 hx.2) have hdg : βˆ€ x ∈ Ioo a b, DifferentiableAt ℝ g x := fun x hx => by_contradiction fun h => hg' x hx (deriv_zero_of_not_differentiableAt h) exact HasDerivAt.lhopital_zero_right_on_Ioo hab (fun x hx => (hdf x hx).hasDerivAt) (fun x hx => (hdg x hx).hasDerivAt) hg' hfa hga hdiv theorem lhopital_zero_right_on_Ico (hab : a < b) (hdf : DifferentiableOn ℝ f (Ioo a b)) (hcf : ContinuousOn f (Ico a b)) (hcg : ContinuousOn g (Ico a b)) (hg' : βˆ€ x ∈ Ioo a b, (deriv g) x β‰  0) (hfa : f a = 0) (hga : g a = 0) (hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) (𝓝[>] a) l) : Tendsto (fun x => f x / g x) (𝓝[>] a) l := by refine lhopital_zero_right_on_Ioo hab hdf hg' ?_ ?_ hdiv Β· rw [← hfa, ← nhdsWithin_Ioo_eq_nhdsGT hab] exact ((hcf a <| left_mem_Ico.mpr hab).mono Ioo_subset_Ico_self).tendsto Β· rw [← hga, ← nhdsWithin_Ioo_eq_nhdsGT hab] exact ((hcg a <| left_mem_Ico.mpr hab).mono Ioo_subset_Ico_self).tendsto theorem lhopital_zero_left_on_Ioo (hab : a < b) (hdf : DifferentiableOn ℝ f (Ioo a b)) (hg' : βˆ€ x ∈ Ioo a b, (deriv g) x β‰  0) (hfb : Tendsto f (𝓝[<] b) (𝓝 0)) (hgb : Tendsto g (𝓝[<] b) (𝓝 0)) (hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) (𝓝[<] b) l) : Tendsto (fun x => f x / g x) (𝓝[<] b) l := by have hdf : βˆ€ x ∈ Ioo a b, DifferentiableAt ℝ f x := fun x hx => (hdf x hx).differentiableAt (Ioo_mem_nhds hx.1 hx.2) have hdg : βˆ€ x ∈ Ioo a b, DifferentiableAt ℝ g x := fun x hx => by_contradiction fun h => hg' x hx (deriv_zero_of_not_differentiableAt h) exact HasDerivAt.lhopital_zero_left_on_Ioo hab (fun x hx => (hdf x hx).hasDerivAt) (fun x hx => (hdg x hx).hasDerivAt) hg' hfb hgb hdiv theorem lhopital_zero_atTop_on_Ioi (hdf : DifferentiableOn ℝ f (Ioi a)) (hg' : βˆ€ x ∈ Ioi a, (deriv g) x β‰  0) (hftop : Tendsto f atTop (𝓝 0)) (hgtop : Tendsto g atTop (𝓝 0)) (hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) atTop l) : Tendsto (fun x => f x / g x) atTop l := by have hdf : βˆ€ x ∈ Ioi a, DifferentiableAt ℝ f x := fun x hx => (hdf x hx).differentiableAt (Ioi_mem_nhds hx) have hdg : βˆ€ x ∈ Ioi a, DifferentiableAt ℝ g x := fun x hx => by_contradiction fun h => hg' x hx (deriv_zero_of_not_differentiableAt h) exact HasDerivAt.lhopital_zero_atTop_on_Ioi (fun x hx => (hdf x hx).hasDerivAt) (fun x hx => (hdg x hx).hasDerivAt) hg' hftop hgtop hdiv theorem lhopital_zero_atBot_on_Iio (hdf : DifferentiableOn ℝ f (Iio a)) (hg' : βˆ€ x ∈ Iio a, (deriv g) x β‰  0) (hfbot : Tendsto f atBot (𝓝 0)) (hgbot : Tendsto g atBot (𝓝 0)) (hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) atBot l) : Tendsto (fun x => f x / g x) atBot l := by have hdf : βˆ€ x ∈ Iio a, DifferentiableAt ℝ f x := fun x hx => (hdf x hx).differentiableAt (Iio_mem_nhds hx) have hdg : βˆ€ x ∈ Iio a, DifferentiableAt ℝ g x := fun x hx => by_contradiction fun h => hg' x hx (deriv_zero_of_not_differentiableAt h) exact HasDerivAt.lhopital_zero_atBot_on_Iio (fun x hx => (hdf x hx).hasDerivAt) (fun x hx => (hdg x hx).hasDerivAt) hg' hfbot hgbot hdiv end deriv /-! ## Generic versions The following statements no longer any explicit interval, as they only require conditions holding eventually. -/ namespace HasDerivAt /-- L'HΓ΄pital's rule for approaching a real from the right, `HasDerivAt` version -/ theorem lhopital_zero_nhdsGT (hff' : βˆ€αΆ  x in 𝓝[>] a, HasDerivAt f (f' x) x) (hgg' : βˆ€αΆ  x in 𝓝[>] a, HasDerivAt g (g' x) x) (hg' : βˆ€αΆ  x in 𝓝[>] a, g' x β‰  0) (hfa : Tendsto f (𝓝[>] a) (𝓝 0)) (hga : Tendsto g (𝓝[>] a) (𝓝 0)) (hdiv : Tendsto (fun x => f' x / g' x) (𝓝[>] a) l) : Tendsto (fun x => f x / g x) (𝓝[>] a) l := by rw [eventually_iff_exists_mem] at * rcases hff' with ⟨s₁, hs₁, hff'⟩ rcases hgg' with ⟨sβ‚‚, hsβ‚‚, hgg'⟩ rcases hg' with ⟨s₃, hs₃, hg'⟩ let s := s₁ ∩ sβ‚‚ ∩ s₃ have hs : s ∈ 𝓝[>] a := inter_mem (inter_mem hs₁ hsβ‚‚) hs₃ rw [mem_nhdsGT_iff_exists_Ioo_subset] at hs rcases hs with ⟨u, hau, hu⟩ refine lhopital_zero_right_on_Ioo hau ?_ ?_ ?_ hfa hga hdiv <;> intro x hx <;> apply_assumption <;> first | exact (hu hx).1.1 | exact (hu hx).1.2 | exact (hu hx).2 @[deprecated (since := "2025-03-02")] alias lhopital_zero_nhds_right := lhopital_zero_nhdsGT /-- L'HΓ΄pital's rule for approaching a real from the left, `HasDerivAt` version -/ theorem lhopital_zero_nhdsLT (hff' : βˆ€αΆ  x in 𝓝[<] a, HasDerivAt f (f' x) x) (hgg' : βˆ€αΆ  x in 𝓝[<] a, HasDerivAt g (g' x) x) (hg' : βˆ€αΆ  x in 𝓝[<] a, g' x β‰  0) (hfa : Tendsto f (𝓝[<] a) (𝓝 0)) (hga : Tendsto g (𝓝[<] a) (𝓝 0)) (hdiv : Tendsto (fun x => f' x / g' x) (𝓝[<] a) l) : Tendsto (fun x => f x / g x) (𝓝[<] a) l := by rw [eventually_iff_exists_mem] at * rcases hff' with ⟨s₁, hs₁, hff'⟩ rcases hgg' with ⟨sβ‚‚, hsβ‚‚, hgg'⟩ rcases hg' with ⟨s₃, hs₃, hg'⟩ let s := s₁ ∩ sβ‚‚ ∩ s₃ have hs : s ∈ 𝓝[<] a := inter_mem (inter_mem hs₁ hsβ‚‚) hs₃ rw [mem_nhdsLT_iff_exists_Ioo_subset] at hs rcases hs with ⟨l, hal, hl⟩ refine lhopital_zero_left_on_Ioo hal ?_ ?_ ?_ hfa hga hdiv <;> intro x hx <;> apply_assumption <;> first | exact (hl hx).1.1| exact (hl hx).1.2| exact (hl hx).2
@[deprecated (since := "2025-03-02")] alias lhopital_zero_nhds_left := lhopital_zero_nhdsLT /-- L'HΓ΄pital's rule for approaching a real, `HasDerivAt` version. This does not require anything about the situation at `a` -/ theorem lhopital_zero_nhdsNE (hff' : βˆ€αΆ  x in 𝓝[β‰ ] a, HasDerivAt f (f' x) x) (hgg' : βˆ€αΆ  x in 𝓝[β‰ ] a, HasDerivAt g (g' x) x) (hg' : βˆ€αΆ  x in 𝓝[β‰ ] a, g' x β‰  0) (hfa : Tendsto f (𝓝[β‰ ] a) (𝓝 0)) (hga : Tendsto g (𝓝[β‰ ] a) (𝓝 0)) (hdiv : Tendsto (fun x => f' x / g' x) (𝓝[β‰ ] a) l) : Tendsto (fun x => f x / g x) (𝓝[β‰ ] a) l := by simp only [← Iio_union_Ioi, nhdsWithin_union, tendsto_sup, eventually_sup] at * exact ⟨lhopital_zero_nhdsLT hff'.1 hgg'.1 hg'.1 hfa.1 hga.1 hdiv.1, lhopital_zero_nhdsGT hff'.2 hgg'.2 hg'.2 hfa.2 hga.2 hdiv.2⟩
Mathlib/Analysis/Calculus/LHopital.lean
300
314
/- 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, Moritz Doll -/ import Mathlib.Algebra.GroupWithZero.Action.Opposite import Mathlib.LinearAlgebra.Finsupp.VectorSpace import Mathlib.LinearAlgebra.Matrix.Basis import Mathlib.LinearAlgebra.Matrix.Nondegenerate import Mathlib.LinearAlgebra.Matrix.NonsingularInverse import Mathlib.LinearAlgebra.Matrix.ToLinearEquiv import Mathlib.LinearAlgebra.SesquilinearForm import Mathlib.LinearAlgebra.Basis.Bilinear /-! # Sesquilinear form This file defines the conversion between sesquilinear maps and matrices. ## Main definitions * `Matrix.toLinearMapβ‚‚` given a basis define a bilinear map * `Matrix.toLinearMapβ‚‚'` define the bilinear map on `n β†’ R` * `LinearMap.toMatrixβ‚‚`: calculate the matrix coefficients of a bilinear map * `LinearMap.toMatrixβ‚‚'`: calculate the matrix coefficients of a bilinear map on `n β†’ R` ## TODO At the moment this is quite a literal port from `Matrix.BilinearForm`. Everything should be generalized to fully semibilinear forms. ## Tags Sesquilinear form, Sesquilinear map, matrix, basis -/ variable {R R₁ S₁ Rβ‚‚ Sβ‚‚ M₁ Mβ‚‚ M₁' Mβ‚‚' Nβ‚‚ n m n' m' ΞΉ : Type*} open Finset LinearMap Matrix open Matrix open scoped RightActions section AuxToLinearMap variable [Semiring R₁] [Semiring S₁] [Semiring Rβ‚‚] [Semiring Sβ‚‚] [AddCommMonoid Nβ‚‚] [Module S₁ Nβ‚‚] [Module Sβ‚‚ Nβ‚‚] [SMulCommClass Sβ‚‚ S₁ Nβ‚‚] variable [Fintype n] [Fintype m] variable (σ₁ : R₁ β†’+* S₁) (Οƒβ‚‚ : Rβ‚‚ β†’+* Sβ‚‚) /-- The map from `Matrix n n R` to bilinear maps on `n β†’ R`. This is an auxiliary definition for the equivalence `Matrix.toLinearMapβ‚‚'`. -/ def Matrix.toLinearMapβ‚‚'Aux (f : Matrix n m Nβ‚‚) : (n β†’ R₁) β†’β‚›β‚—[σ₁] (m β†’ Rβ‚‚) β†’β‚›β‚—[Οƒβ‚‚] Nβ‚‚ := -- porting note: we don't seem to have `βˆ‘ i j` as valid notation yet mkβ‚‚'β‚›β‚— σ₁ Οƒβ‚‚ (fun (v : n β†’ R₁) (w : m β†’ Rβ‚‚) => βˆ‘ i, βˆ‘ j, Οƒβ‚‚ (w j) β€’ σ₁ (v i) β€’ f i j) (fun _ _ _ => by simp only [Pi.add_apply, map_add, smul_add, sum_add_distrib, add_smul]) (fun c v w => by simp only [Pi.smul_apply, smul_sum, smul_eq_mul, σ₁.map_mul, ← smul_comm _ (σ₁ c), MulAction.mul_smul]) (fun _ _ _ => by simp only [Pi.add_apply, map_add, add_smul, smul_add, sum_add_distrib]) (fun _ v w => by simp only [Pi.smul_apply, smul_eq_mul, map_mul, MulAction.mul_smul, smul_sum]) variable [DecidableEq n] [DecidableEq m] theorem Matrix.toLinearMapβ‚‚'Aux_single (f : Matrix n m Nβ‚‚) (i : n) (j : m) : f.toLinearMapβ‚‚'Aux σ₁ Οƒβ‚‚ (Pi.single i 1) (Pi.single j 1) = f i j := by rw [Matrix.toLinearMapβ‚‚'Aux, mkβ‚‚'β‚›β‚—_apply] have : (βˆ‘ i', βˆ‘ j', (if i = i' then (1 : S₁) else (0 : S₁)) β€’ (if j = j' then (1 : Sβ‚‚) else (0 : Sβ‚‚)) β€’ f i' j') = f i j := by simp_rw [← Finset.smul_sum] simp only [op_smul_eq_smul, ite_smul, one_smul, zero_smul, sum_ite_eq, mem_univ, ↓reduceIte] rw [← this] exact Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ => by aesop end AuxToLinearMap section AuxToMatrix section CommSemiring variable [CommSemiring R] [Semiring R₁] [Semiring S₁] [Semiring Rβ‚‚] [Semiring Sβ‚‚] variable [AddCommMonoid M₁] [Module R₁ M₁] [AddCommMonoid Mβ‚‚] [Module Rβ‚‚ Mβ‚‚] [AddCommMonoid Nβ‚‚] [Module R Nβ‚‚] [Module S₁ Nβ‚‚] [Module Sβ‚‚ Nβ‚‚] [SMulCommClass S₁ R Nβ‚‚] [SMulCommClass Sβ‚‚ R Nβ‚‚] [SMulCommClass Sβ‚‚ S₁ Nβ‚‚] variable {σ₁ : R₁ β†’+* S₁} {Οƒβ‚‚ : Rβ‚‚ β†’+* Sβ‚‚} variable (R) /-- The linear map from sesquilinear maps to `Matrix n m Nβ‚‚` given an `n`-indexed basis for `M₁` and an `m`-indexed basis for `Mβ‚‚`. This is an auxiliary definition for the equivalence `Matrix.toLinearMapβ‚›β‚—β‚‚'`. -/ def LinearMap.toMatrixβ‚‚Aux (b₁ : n β†’ M₁) (bβ‚‚ : m β†’ Mβ‚‚) : (M₁ β†’β‚›β‚—[σ₁] Mβ‚‚ β†’β‚›β‚—[Οƒβ‚‚] Nβ‚‚) β†’β‚—[R] Matrix n m Nβ‚‚ where toFun f := of fun i j => f (b₁ i) (bβ‚‚ j) map_add' _f _g := rfl map_smul' _f _g := rfl @[simp] theorem LinearMap.toMatrixβ‚‚Aux_apply (f : M₁ β†’β‚›β‚—[σ₁] Mβ‚‚ β†’β‚›β‚—[Οƒβ‚‚] Nβ‚‚) (b₁ : n β†’ M₁) (bβ‚‚ : m β†’ Mβ‚‚) (i : n) (j : m) : LinearMap.toMatrixβ‚‚Aux R b₁ bβ‚‚ f i j = f (b₁ i) (bβ‚‚ j) := rfl variable [Fintype n] [Fintype m] variable [DecidableEq n] [DecidableEq m] theorem LinearMap.toLinearMapβ‚‚'Aux_toMatrixβ‚‚Aux (f : (n β†’ R₁) β†’β‚›β‚—[σ₁] (m β†’ Rβ‚‚) β†’β‚›β‚—[Οƒβ‚‚] Nβ‚‚) : Matrix.toLinearMapβ‚‚'Aux σ₁ Οƒβ‚‚ (LinearMap.toMatrixβ‚‚Aux R (fun i => Pi.single i 1) (fun j => Pi.single j 1) f) = f := by refine ext_basis (Pi.basisFun R₁ n) (Pi.basisFun Rβ‚‚ m) fun i j => ?_ simp_rw [Pi.basisFun_apply, Matrix.toLinearMapβ‚‚'Aux_single, LinearMap.toMatrixβ‚‚Aux_apply] theorem Matrix.toMatrixβ‚‚Aux_toLinearMapβ‚‚'Aux (f : Matrix n m Nβ‚‚) : LinearMap.toMatrixβ‚‚Aux R (fun i => Pi.single i 1) (fun j => Pi.single j 1) (f.toLinearMapβ‚‚'Aux σ₁ Οƒβ‚‚) = f := by ext i j simp_rw [LinearMap.toMatrixβ‚‚Aux_apply, Matrix.toLinearMapβ‚‚'Aux_single] end CommSemiring end AuxToMatrix section ToMatrix' /-! ### Bilinear maps over `n β†’ R` This section deals with the conversion between matrices and sesquilinear maps on `n β†’ R`. -/ variable [CommSemiring R] [AddCommMonoid Nβ‚‚] [Module R Nβ‚‚] [Semiring R₁] [Semiring Rβ‚‚] [Semiring S₁] [Semiring Sβ‚‚] [Module S₁ Nβ‚‚] [Module Sβ‚‚ Nβ‚‚] [SMulCommClass S₁ R Nβ‚‚] [SMulCommClass Sβ‚‚ R Nβ‚‚] [SMulCommClass Sβ‚‚ S₁ Nβ‚‚] variable {σ₁ : R₁ β†’+* S₁} {Οƒβ‚‚ : Rβ‚‚ β†’+* Sβ‚‚} variable [Fintype n] [Fintype m] variable [DecidableEq n] [DecidableEq m] variable (R) /-- The linear equivalence between sesquilinear maps and `n Γ— m` matrices -/ def LinearMap.toMatrixβ‚›β‚—β‚‚' : ((n β†’ R₁) β†’β‚›β‚—[σ₁] (m β†’ Rβ‚‚) β†’β‚›β‚—[Οƒβ‚‚] Nβ‚‚) ≃ₗ[R] Matrix n m Nβ‚‚ := { LinearMap.toMatrixβ‚‚Aux R (fun i => Pi.single i 1) (fun j => Pi.single j 1) with toFun := LinearMap.toMatrixβ‚‚Aux R _ _ invFun := Matrix.toLinearMapβ‚‚'Aux σ₁ Οƒβ‚‚ left_inv := LinearMap.toLinearMapβ‚‚'Aux_toMatrixβ‚‚Aux R right_inv := Matrix.toMatrixβ‚‚Aux_toLinearMapβ‚‚'Aux R } /-- The linear equivalence between bilinear maps and `n Γ— m` matrices -/ def LinearMap.toMatrixβ‚‚' : ((n β†’ S₁) β†’β‚—[S₁] (m β†’ Sβ‚‚) β†’β‚—[Sβ‚‚] Nβ‚‚) ≃ₗ[R] Matrix n m Nβ‚‚ := LinearMap.toMatrixβ‚›β‚—β‚‚' R variable (σ₁ Οƒβ‚‚) /-- The linear equivalence between `n Γ— n` matrices and sesquilinear maps on `n β†’ R` -/ def Matrix.toLinearMapβ‚›β‚—β‚‚' : Matrix n m Nβ‚‚ ≃ₗ[R] (n β†’ R₁) β†’β‚›β‚—[σ₁] (m β†’ Rβ‚‚) β†’β‚›β‚—[Οƒβ‚‚] Nβ‚‚ := (LinearMap.toMatrixβ‚›β‚—β‚‚' R).symm /-- The linear equivalence between `n Γ— n` matrices and bilinear maps on `n β†’ R` -/ def Matrix.toLinearMapβ‚‚' : Matrix n m Nβ‚‚ ≃ₗ[R] (n β†’ S₁) β†’β‚—[S₁] (m β†’ Sβ‚‚) β†’β‚—[Sβ‚‚] Nβ‚‚ := (LinearMap.toMatrixβ‚‚' R).symm variable {R} theorem Matrix.toLinearMapβ‚›β‚—β‚‚'_aux_eq (M : Matrix n m Nβ‚‚) : Matrix.toLinearMapβ‚‚'Aux σ₁ Οƒβ‚‚ M = Matrix.toLinearMapβ‚›β‚—β‚‚' R σ₁ Οƒβ‚‚ M := rfl theorem Matrix.toLinearMapβ‚›β‚—β‚‚'_apply (M : Matrix n m Nβ‚‚) (x : n β†’ R₁) (y : m β†’ Rβ‚‚) : -- porting note: we don't seem to have `βˆ‘ i j` as valid notation yet Matrix.toLinearMapβ‚›β‚—β‚‚' R σ₁ Οƒβ‚‚ M x y = βˆ‘ i, βˆ‘ j, σ₁ (x i) β€’ Οƒβ‚‚ (y j) β€’ M i j := by rw [toLinearMapβ‚›β‚—β‚‚', toMatrixβ‚›β‚—β‚‚', LinearEquiv.coe_symm_mk, toLinearMapβ‚‚'Aux, mkβ‚‚'β‚›β‚—_apply] apply Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ => by rw [smul_comm] theorem Matrix.toLinearMapβ‚‚'_apply (M : Matrix n m Nβ‚‚) (x : n β†’ S₁) (y : m β†’ Sβ‚‚) : -- porting note: we don't seem to have `βˆ‘ i j` as valid notation yet Matrix.toLinearMapβ‚‚' R M x y = βˆ‘ i, βˆ‘ j, x i β€’ y j β€’ M i j := Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ => by rw [RingHom.id_apply, RingHom.id_apply, smul_comm] theorem Matrix.toLinearMapβ‚‚'_apply' {T : Type*} [CommSemiring T] (M : Matrix n m T) (v : n β†’ T) (w : m β†’ T) : Matrix.toLinearMapβ‚‚' T M v w = dotProduct v (M *α΅₯ w) := by simp_rw [Matrix.toLinearMapβ‚‚'_apply, dotProduct, Matrix.mulVec, dotProduct] refine Finset.sum_congr rfl fun _ _ => ?_ rw [Finset.mul_sum] refine Finset.sum_congr rfl fun _ _ => ?_ rw [smul_eq_mul, smul_eq_mul, mul_comm (w _), ← mul_assoc] @[simp] theorem Matrix.toLinearMapβ‚›β‚—β‚‚'_single (M : Matrix n m Nβ‚‚) (i : n) (j : m) : Matrix.toLinearMapβ‚›β‚—β‚‚' R σ₁ Οƒβ‚‚ M (Pi.single i 1) (Pi.single j 1) = M i j := Matrix.toLinearMapβ‚‚'Aux_single σ₁ Οƒβ‚‚ M i j @[simp] theorem Matrix.toLinearMapβ‚‚'_single (M : Matrix n m Nβ‚‚) (i : n) (j : m) : Matrix.toLinearMapβ‚‚' R M (Pi.single i 1) (Pi.single j 1) = M i j := Matrix.toLinearMapβ‚‚'Aux_single _ _ M i j @[simp] theorem LinearMap.toMatrixβ‚›β‚—β‚‚'_symm : ((LinearMap.toMatrixβ‚›β‚—β‚‚' R).symm : Matrix n m Nβ‚‚ ≃ₗ[R] _) = Matrix.toLinearMapβ‚›β‚—β‚‚' R σ₁ Οƒβ‚‚ := rfl @[simp] theorem Matrix.toLinearMapβ‚›β‚—β‚‚'_symm : ((Matrix.toLinearMapβ‚›β‚—β‚‚' R σ₁ Οƒβ‚‚).symm : _ ≃ₗ[R] Matrix n m Nβ‚‚) = LinearMap.toMatrixβ‚›β‚—β‚‚' R := (LinearMap.toMatrixβ‚›β‚—β‚‚' R).symm_symm @[simp] theorem Matrix.toLinearMapβ‚›β‚—β‚‚'_toMatrix' (B : (n β†’ R₁) β†’β‚›β‚—[σ₁] (m β†’ Rβ‚‚) β†’β‚›β‚—[Οƒβ‚‚] Nβ‚‚) : Matrix.toLinearMapβ‚›β‚—β‚‚' R σ₁ Οƒβ‚‚ (LinearMap.toMatrixβ‚›β‚—β‚‚' R B) = B := (Matrix.toLinearMapβ‚›β‚—β‚‚' R σ₁ Οƒβ‚‚).apply_symm_apply B @[simp] theorem Matrix.toLinearMapβ‚‚'_toMatrix' (B : (n β†’ S₁) β†’β‚—[S₁] (m β†’ Sβ‚‚) β†’β‚—[Sβ‚‚] Nβ‚‚) : Matrix.toLinearMapβ‚‚' R (LinearMap.toMatrixβ‚‚' R B) = B := (Matrix.toLinearMapβ‚‚' R).apply_symm_apply B @[simp] theorem LinearMap.toMatrix'_toLinearMapβ‚›β‚—β‚‚' (M : Matrix n m Nβ‚‚) : LinearMap.toMatrixβ‚›β‚—β‚‚' R (Matrix.toLinearMapβ‚›β‚—β‚‚' R σ₁ Οƒβ‚‚ M) = M := (LinearMap.toMatrixβ‚›β‚—β‚‚' R).apply_symm_apply M @[simp] theorem LinearMap.toMatrix'_toLinearMapβ‚‚' (M : Matrix n m Nβ‚‚) : LinearMap.toMatrixβ‚‚' R (Matrix.toLinearMapβ‚‚' R (S₁ := S₁) (Sβ‚‚ := Sβ‚‚) M) = M := (LinearMap.toMatrixβ‚›β‚—β‚‚' R).apply_symm_apply M @[simp] theorem LinearMap.toMatrixβ‚›β‚—β‚‚'_apply (B : (n β†’ R₁) β†’β‚›β‚—[σ₁] (m β†’ Rβ‚‚) β†’β‚›β‚—[Οƒβ‚‚] Nβ‚‚) (i : n) (j : m) : LinearMap.toMatrixβ‚›β‚—β‚‚' R B i j = B (Pi.single i 1) (Pi.single j 1) := rfl @[simp] theorem LinearMap.toMatrixβ‚‚'_apply (B : (n β†’ S₁) β†’β‚—[S₁] (m β†’ Sβ‚‚) β†’β‚—[Sβ‚‚] Nβ‚‚) (i : n) (j : m) : LinearMap.toMatrixβ‚‚' R B i j = B (Pi.single i 1) (Pi.single j 1) := rfl end ToMatrix' section CommToMatrix' -- TODO: Introduce matrix multiplication by matrices of scalars variable {R : Type*} [CommSemiring R] variable [Fintype n] [Fintype m] variable [DecidableEq n] [DecidableEq m] variable [Fintype n'] [Fintype m'] variable [DecidableEq n'] [DecidableEq m'] @[simp] theorem LinearMap.toMatrixβ‚‚'_compl₁₂ (B : (n β†’ R) β†’β‚—[R] (m β†’ R) β†’β‚—[R] R) (l : (n' β†’ R) β†’β‚—[R] n β†’ R) (r : (m' β†’ R) β†’β‚—[R] m β†’ R) : toMatrixβ‚‚' R (B.compl₁₂ l r) = (toMatrix' l)α΅€ * toMatrixβ‚‚' R B * toMatrix' r := by ext i j simp only [LinearMap.toMatrixβ‚‚'_apply, LinearMap.compl₁₂_apply, transpose_apply, Matrix.mul_apply, LinearMap.toMatrix', LinearEquiv.coe_mk, sum_mul] rw [sum_comm] conv_lhs => rw [← LinearMap.sum_repr_mul_repr_mul (Pi.basisFun R n) (Pi.basisFun R m) (l _) (r _)] rw [Finsupp.sum_fintype] Β· apply sum_congr rfl rintro i' - rw [Finsupp.sum_fintype] Β· apply sum_congr rfl rintro j' - simp only [smul_eq_mul, Pi.basisFun_repr, mul_assoc, mul_comm, mul_left_comm, Pi.basisFun_apply, of_apply] Β· intros simp only [zero_smul, smul_zero] Β· intros simp only [zero_smul, Finsupp.sum_zero] theorem LinearMap.toMatrixβ‚‚'_comp (B : (n β†’ R) β†’β‚—[R] (m β†’ R) β†’β‚—[R] R) (f : (n' β†’ R) β†’β‚—[R] n β†’ R) : toMatrixβ‚‚' R (B.comp f) = (toMatrix' f)α΅€ * toMatrixβ‚‚' R B := by rw [← LinearMap.complβ‚‚_id (B.comp f), ← LinearMap.compl₁₂] simp theorem LinearMap.toMatrixβ‚‚'_complβ‚‚ (B : (n β†’ R) β†’β‚—[R] (m β†’ R) β†’β‚—[R] R) (f : (m' β†’ R) β†’β‚—[R] m β†’ R) : toMatrixβ‚‚' R (B.complβ‚‚ f) = toMatrixβ‚‚' R B * toMatrix' f := by rw [← LinearMap.comp_id B, ← LinearMap.compl₁₂] simp theorem LinearMap.mul_toMatrixβ‚‚'_mul (B : (n β†’ R) β†’β‚—[R] (m β†’ R) β†’β‚—[R] R) (M : Matrix n' n R) (N : Matrix m m' R) : M * toMatrixβ‚‚' R B * N = toMatrixβ‚‚' R (B.compl₁₂ (toLin' Mα΅€) (toLin' N)) := by simp theorem LinearMap.mul_toMatrix' (B : (n β†’ R) β†’β‚—[R] (m β†’ R) β†’β‚—[R] R) (M : Matrix n' n R) : M * toMatrixβ‚‚' R B = toMatrixβ‚‚' R (B.comp <| toLin' Mα΅€) := by simp only [B.toMatrixβ‚‚'_comp, transpose_transpose, toMatrix'_toLin'] theorem LinearMap.toMatrixβ‚‚'_mul (B : (n β†’ R) β†’β‚—[R] (m β†’ R) β†’β‚—[R] R) (M : Matrix m m' R) : toMatrixβ‚‚' R B * M = toMatrixβ‚‚' R (B.complβ‚‚ <| toLin' M) := by simp only [B.toMatrixβ‚‚'_complβ‚‚, toMatrix'_toLin'] theorem Matrix.toLinearMapβ‚‚'_comp (M : Matrix n m R) (P : Matrix n n' R) (Q : Matrix m m' R) : LinearMap.compl₁₂ (Matrix.toLinearMapβ‚‚' R M) (toLin' P) (toLin' Q) = toLinearMapβ‚‚' R (Pα΅€ * M * Q) := (LinearMap.toMatrixβ‚‚' R).injective (by simp) end CommToMatrix' section ToMatrix /-! ### Bilinear maps over arbitrary vector spaces This section deals with the conversion between matrices and bilinear maps on a module with a fixed basis. -/ variable [CommSemiring R] variable [AddCommMonoid M₁] [Module R M₁] [AddCommMonoid Mβ‚‚] [Module R Mβ‚‚] [AddCommMonoid Nβ‚‚] [Module R Nβ‚‚] variable [DecidableEq n] [Fintype n] variable [DecidableEq m] [Fintype m] section variable (b₁ : Basis n R M₁) (bβ‚‚ : Basis m R Mβ‚‚) /-- `LinearMap.toMatrixβ‚‚ b₁ bβ‚‚` is the equivalence between `R`-bilinear maps on `M` and `n`-by-`m` matrices with entries in `R`, if `b₁` and `bβ‚‚` are `R`-bases for `M₁` and `Mβ‚‚`, respectively. -/ noncomputable def LinearMap.toMatrixβ‚‚ : (M₁ β†’β‚—[R] Mβ‚‚ β†’β‚—[R] Nβ‚‚) ≃ₗ[R] Matrix n m Nβ‚‚ := (b₁.equivFun.arrowCongr (bβ‚‚.equivFun.arrowCongr (LinearEquiv.refl R Nβ‚‚))).trans (LinearMap.toMatrixβ‚‚' R) /-- `Matrix.toLinearMapβ‚‚ b₁ bβ‚‚` is the equivalence between `R`-bilinear maps on `M` and `n`-by-`m` matrices with entries in `R`, if `b₁` and `bβ‚‚` are `R`-bases for `M₁` and `Mβ‚‚`, respectively; this is the reverse direction of `LinearMap.toMatrixβ‚‚ b₁ bβ‚‚`. -/ noncomputable def Matrix.toLinearMapβ‚‚ : Matrix n m Nβ‚‚ ≃ₗ[R] M₁ β†’β‚—[R] Mβ‚‚ β†’β‚—[R] Nβ‚‚ := (LinearMap.toMatrixβ‚‚ b₁ bβ‚‚).symm -- We make this and not `LinearMap.toMatrixβ‚‚` a `simp` lemma to avoid timeouts @[simp] theorem LinearMap.toMatrixβ‚‚_apply (B : M₁ β†’β‚—[R] Mβ‚‚ β†’β‚—[R] Nβ‚‚) (i : n) (j : m) : LinearMap.toMatrixβ‚‚ b₁ bβ‚‚ B i j = B (b₁ i) (bβ‚‚ j) := by simp only [toMatrixβ‚‚, LinearEquiv.trans_apply, toMatrixβ‚‚'_apply, LinearEquiv.arrowCongr_apply, Basis.equivFun_symm_apply, Pi.single_apply, ite_smul, one_smul, zero_smul, sum_ite_eq', mem_univ, ↓reduceIte, LinearEquiv.refl_apply] @[simp] theorem Matrix.toLinearMapβ‚‚_apply (M : Matrix n m Nβ‚‚) (x : M₁) (y : Mβ‚‚) : Matrix.toLinearMapβ‚‚ b₁ bβ‚‚ M x y = βˆ‘ i, βˆ‘ j, b₁.repr x i β€’ bβ‚‚.repr y j β€’ M i j := Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ => smul_algebra_smul_comm ((RingHom.id R) ((Basis.equivFun b₁) x _)) ((RingHom.id R) ((Basis.equivFun bβ‚‚) y _)) (M _ _) -- Not a `simp` lemma since `LinearMap.toMatrixβ‚‚` needs an extra argument theorem LinearMap.toMatrixβ‚‚Aux_eq (B : M₁ β†’β‚—[R] Mβ‚‚ β†’β‚—[R] Nβ‚‚) : LinearMap.toMatrixβ‚‚Aux R b₁ bβ‚‚ B = LinearMap.toMatrixβ‚‚ b₁ bβ‚‚ B := Matrix.ext fun i j => by rw [LinearMap.toMatrixβ‚‚_apply, LinearMap.toMatrixβ‚‚Aux_apply] @[simp] theorem LinearMap.toMatrixβ‚‚_symm : (LinearMap.toMatrixβ‚‚ b₁ bβ‚‚).symm = Matrix.toLinearMapβ‚‚ (Nβ‚‚ := Nβ‚‚) b₁ bβ‚‚ := rfl @[simp] theorem Matrix.toLinearMapβ‚‚_symm : (Matrix.toLinearMapβ‚‚ b₁ bβ‚‚).symm = LinearMap.toMatrixβ‚‚ (Nβ‚‚ := Nβ‚‚) b₁ bβ‚‚ := (LinearMap.toMatrixβ‚‚ b₁ bβ‚‚).symm_symm theorem Matrix.toLinearMapβ‚‚_basisFun : Matrix.toLinearMapβ‚‚ (Pi.basisFun R n) (Pi.basisFun R m) = Matrix.toLinearMapβ‚‚' R (Nβ‚‚ := Nβ‚‚) := by ext M simp only [coe_comp, coe_single, Function.comp_apply, toLinearMapβ‚‚_apply, Pi.basisFun_repr, toLinearMapβ‚‚'_apply] theorem LinearMap.toMatrixβ‚‚_basisFun : LinearMap.toMatrixβ‚‚ (Pi.basisFun R n) (Pi.basisFun R m) = LinearMap.toMatrixβ‚‚' R (Nβ‚‚ := Nβ‚‚) := by ext B rw [LinearMap.toMatrixβ‚‚_apply, LinearMap.toMatrixβ‚‚'_apply, Pi.basisFun_apply, Pi.basisFun_apply] @[simp] theorem Matrix.toLinearMapβ‚‚_toMatrixβ‚‚ (B : M₁ β†’β‚—[R] Mβ‚‚ β†’β‚—[R] Nβ‚‚) : Matrix.toLinearMapβ‚‚ b₁ bβ‚‚ (LinearMap.toMatrixβ‚‚ b₁ bβ‚‚ B) = B := (Matrix.toLinearMapβ‚‚ b₁ bβ‚‚).apply_symm_apply B @[simp] theorem LinearMap.toMatrixβ‚‚_toLinearMapβ‚‚ (M : Matrix n m Nβ‚‚) : LinearMap.toMatrixβ‚‚ b₁ bβ‚‚ (Matrix.toLinearMapβ‚‚ b₁ bβ‚‚ M) = M := (LinearMap.toMatrixβ‚‚ b₁ bβ‚‚).apply_symm_apply M variable (b₁ : Basis n R M₁) (bβ‚‚ : Basis m R Mβ‚‚) variable [AddCommMonoid M₁'] [Module R M₁'] variable [AddCommMonoid Mβ‚‚'] [Module R Mβ‚‚'] variable (b₁' : Basis n' R M₁') variable (bβ‚‚' : Basis m' R Mβ‚‚') variable [Fintype n'] [Fintype m'] variable [DecidableEq n'] [DecidableEq m'] -- Cannot be a `simp` lemma because `b₁` and `bβ‚‚` must be inferred. theorem LinearMap.toMatrixβ‚‚_compl₁₂ (B : M₁ β†’β‚—[R] Mβ‚‚ β†’β‚—[R] R) (l : M₁' β†’β‚—[R] M₁) (r : Mβ‚‚' β†’β‚—[R] Mβ‚‚) : LinearMap.toMatrixβ‚‚ b₁' bβ‚‚' (B.compl₁₂ l r) = (toMatrix b₁' b₁ l)α΅€ * LinearMap.toMatrixβ‚‚ b₁ bβ‚‚ B * toMatrix bβ‚‚' bβ‚‚ r := by ext i j simp only [LinearMap.toMatrixβ‚‚_apply, compl₁₂_apply, transpose_apply, Matrix.mul_apply, LinearMap.toMatrix_apply, LinearEquiv.coe_mk, sum_mul] rw [sum_comm] conv_lhs => rw [← LinearMap.sum_repr_mul_repr_mul b₁ bβ‚‚] rw [Finsupp.sum_fintype] Β· apply sum_congr rfl rintro i' - rw [Finsupp.sum_fintype] Β· apply sum_congr rfl rintro j' - simp only [smul_eq_mul, LinearMap.toMatrix_apply, Basis.equivFun_apply, mul_assoc, mul_comm, mul_left_comm] Β· intros simp only [zero_smul, smul_zero] Β· intros simp only [zero_smul, Finsupp.sum_zero] theorem LinearMap.toMatrixβ‚‚_comp (B : M₁ β†’β‚—[R] Mβ‚‚ β†’β‚—[R] R) (f : M₁' β†’β‚—[R] M₁) : LinearMap.toMatrixβ‚‚ b₁' bβ‚‚ (B.comp f) = (toMatrix b₁' b₁ f)α΅€ * LinearMap.toMatrixβ‚‚ b₁ bβ‚‚ B := by rw [← LinearMap.complβ‚‚_id (B.comp f), ← LinearMap.compl₁₂, LinearMap.toMatrixβ‚‚_compl₁₂ b₁ bβ‚‚] simp theorem LinearMap.toMatrixβ‚‚_complβ‚‚ (B : M₁ β†’β‚—[R] Mβ‚‚ β†’β‚—[R] R) (f : Mβ‚‚' β†’β‚—[R] Mβ‚‚) : LinearMap.toMatrixβ‚‚ b₁ bβ‚‚' (B.complβ‚‚ f) = LinearMap.toMatrixβ‚‚ b₁ bβ‚‚ B * toMatrix bβ‚‚' bβ‚‚ f := by rw [← LinearMap.comp_id B, ← LinearMap.compl₁₂, LinearMap.toMatrixβ‚‚_compl₁₂ b₁ bβ‚‚] simp @[simp] theorem LinearMap.toMatrixβ‚‚_mul_basis_toMatrix (c₁ : Basis n' R M₁) (cβ‚‚ : Basis m' R Mβ‚‚) (B : M₁ β†’β‚—[R] Mβ‚‚ β†’β‚—[R] R) : (b₁.toMatrix c₁)α΅€ * LinearMap.toMatrixβ‚‚ b₁ bβ‚‚ B * bβ‚‚.toMatrix cβ‚‚ = LinearMap.toMatrixβ‚‚ c₁ cβ‚‚ B := by simp_rw [← LinearMap.toMatrix_id_eq_basis_toMatrix] rw [← LinearMap.toMatrixβ‚‚_compl₁₂, LinearMap.compl₁₂_id_id] theorem LinearMap.mul_toMatrixβ‚‚_mul (B : M₁ β†’β‚—[R] Mβ‚‚ β†’β‚—[R] R) (M : Matrix n' n R) (N : Matrix m m' R) : M * LinearMap.toMatrixβ‚‚ b₁ bβ‚‚ B * N = LinearMap.toMatrixβ‚‚ b₁' bβ‚‚' (B.compl₁₂ (toLin b₁' b₁ Mα΅€) (toLin bβ‚‚' bβ‚‚ N)) := by simp_rw [LinearMap.toMatrixβ‚‚_compl₁₂ b₁ bβ‚‚, toMatrix_toLin, transpose_transpose] theorem LinearMap.mul_toMatrixβ‚‚ (B : M₁ β†’β‚—[R] Mβ‚‚ β†’β‚—[R] R) (M : Matrix n' n R) : M * LinearMap.toMatrixβ‚‚ b₁ bβ‚‚ B = LinearMap.toMatrixβ‚‚ b₁' bβ‚‚ (B.comp (toLin b₁' b₁ Mα΅€)) := by rw [LinearMap.toMatrixβ‚‚_comp b₁, toMatrix_toLin, transpose_transpose] theorem LinearMap.toMatrixβ‚‚_mul (B : M₁ β†’β‚—[R] Mβ‚‚ β†’β‚—[R] R) (M : Matrix m m' R) : LinearMap.toMatrixβ‚‚ b₁ bβ‚‚ B * M = LinearMap.toMatrixβ‚‚ b₁ bβ‚‚' (B.complβ‚‚ (toLin bβ‚‚' bβ‚‚ M)) := by rw [LinearMap.toMatrixβ‚‚_complβ‚‚ b₁ bβ‚‚, toMatrix_toLin] theorem Matrix.toLinearMapβ‚‚_compl₁₂ (M : Matrix n m R) (P : Matrix n n' R) (Q : Matrix m m' R) : (Matrix.toLinearMapβ‚‚ b₁ bβ‚‚ M).compl₁₂ (toLin b₁' b₁ P) (toLin bβ‚‚' bβ‚‚ Q) = Matrix.toLinearMapβ‚‚ b₁' bβ‚‚' (Pα΅€ * M * Q) := (LinearMap.toMatrixβ‚‚ b₁' bβ‚‚').injective (by simp only [LinearMap.toMatrixβ‚‚_compl₁₂ b₁ bβ‚‚, LinearMap.toMatrixβ‚‚_toLinearMapβ‚‚, toMatrix_toLin]) end end ToMatrix /-! ### Adjoint pairs -/ section MatrixAdjoints open Matrix variable [CommRing R] variable [AddCommMonoid M₁] [Module R M₁] [AddCommMonoid Mβ‚‚] [Module R Mβ‚‚] variable [Fintype n] [Fintype n'] variable (b₁ : Basis n R M₁) (bβ‚‚ : Basis n' R Mβ‚‚) variable (J Jβ‚‚ : Matrix n n R) (J' : Matrix n' n' R) variable (A : Matrix n' n R) (A' : Matrix n n' R) variable (A₁ Aβ‚‚ : Matrix n n R) /-- The condition for the matrices `A`, `A'` to be an adjoint pair with respect to the square matrices `J`, `J₃`. -/ def Matrix.IsAdjointPair := Aα΅€ * J' = J * A' /-- The condition for a square matrix `A` to be self-adjoint with respect to the square matrix `J`. -/ def Matrix.IsSelfAdjoint := Matrix.IsAdjointPair J J A₁ A₁ /-- The condition for a square matrix `A` to be skew-adjoint with respect to the square matrix `J`. -/ def Matrix.IsSkewAdjoint := Matrix.IsAdjointPair J J A₁ (-A₁) variable [DecidableEq n] [DecidableEq n'] @[simp] theorem isAdjointPair_toLinearMapβ‚‚' : LinearMap.IsAdjointPair (Matrix.toLinearMapβ‚‚' R J) (Matrix.toLinearMapβ‚‚' R J') (Matrix.toLin' A) (Matrix.toLin' A') ↔ Matrix.IsAdjointPair J J' A A' := by rw [isAdjointPair_iff_comp_eq_complβ‚‚] have h : βˆ€ B B' : (n β†’ R) β†’β‚—[R] (n' β†’ R) β†’β‚—[R] R, B = B' ↔ LinearMap.toMatrixβ‚‚' R B = LinearMap.toMatrixβ‚‚' R B' := by intro B B' constructor <;> intro h Β· rw [h] Β· exact (LinearMap.toMatrixβ‚‚' R).injective h simp_rw [h, LinearMap.toMatrixβ‚‚'_comp, LinearMap.toMatrixβ‚‚'_complβ‚‚, LinearMap.toMatrix'_toLin', LinearMap.toMatrix'_toLinearMapβ‚‚'] rfl @[simp] theorem isAdjointPair_toLinearMapβ‚‚ : LinearMap.IsAdjointPair (Matrix.toLinearMapβ‚‚ b₁ b₁ J) (Matrix.toLinearMapβ‚‚ bβ‚‚ bβ‚‚ J') (Matrix.toLin b₁ bβ‚‚ A) (Matrix.toLin bβ‚‚ b₁ A') ↔ Matrix.IsAdjointPair J J' A A' := by rw [isAdjointPair_iff_comp_eq_complβ‚‚] have h : βˆ€ B B' : M₁ β†’β‚—[R] Mβ‚‚ β†’β‚—[R] R, B = B' ↔ LinearMap.toMatrixβ‚‚ b₁ bβ‚‚ B = LinearMap.toMatrixβ‚‚ b₁ bβ‚‚ B' := by intro B B' constructor <;> intro h Β· rw [h] Β· exact (LinearMap.toMatrixβ‚‚ b₁ bβ‚‚).injective h simp_rw [h, LinearMap.toMatrixβ‚‚_comp bβ‚‚ bβ‚‚, LinearMap.toMatrixβ‚‚_complβ‚‚ b₁ b₁, LinearMap.toMatrix_toLin, LinearMap.toMatrixβ‚‚_toLinearMapβ‚‚] rfl theorem Matrix.isAdjointPair_equiv (P : Matrix n n R) (h : IsUnit P) : (Pα΅€ * J * P).IsAdjointPair (Pα΅€ * J * P) A₁ Aβ‚‚ ↔ J.IsAdjointPair J (P * A₁ * P⁻¹) (P * Aβ‚‚ * P⁻¹) := by have h' : IsUnit P.det := P.isUnit_iff_isUnit_det.mp h let u := P.nonsingInvUnit h' let v := Pα΅€.nonsingInvUnit (P.isUnit_det_transpose h') let x := A₁ᡀ * Pα΅€ * J let y := J * P * Aβ‚‚ suffices x * u = v * y ↔ v⁻¹ * x = y * u⁻¹ by dsimp only [Matrix.IsAdjointPair] simp only [Matrix.transpose_mul] simp only [← mul_assoc, P.transpose_nonsing_inv] convert this using 2 Β· rw [mul_assoc, mul_assoc, ← mul_assoc J] rfl Β· rw [mul_assoc, mul_assoc, ← mul_assoc _ _ J] rfl rw [Units.eq_mul_inv_iff_mul_eq] conv_rhs => rw [mul_assoc] rw [v.inv_mul_eq_iff_eq_mul] /-- The submodule of pair-self-adjoint matrices with respect to bilinear forms corresponding to given matrices `J`, `Jβ‚‚`. -/ def pairSelfAdjointMatricesSubmodule : Submodule R (Matrix n n R) :=
(isPairSelfAdjointSubmodule (Matrix.toLinearMapβ‚‚' R J) (Matrix.toLinearMapβ‚‚' R Jβ‚‚)).map ((LinearMap.toMatrix' : ((n β†’ R) β†’β‚—[R] n β†’ R) ≃ₗ[R] Matrix n n R) : ((n β†’ R) β†’β‚—[R] n β†’ R) β†’β‚—[R] Matrix n n R) @[simp] theorem mem_pairSelfAdjointMatricesSubmodule : A₁ ∈ pairSelfAdjointMatricesSubmodule J Jβ‚‚ ↔ Matrix.IsAdjointPair J Jβ‚‚ A₁ A₁ := by simp only [pairSelfAdjointMatricesSubmodule, LinearEquiv.coe_coe, LinearMap.toMatrix'_apply, Submodule.mem_map, mem_isPairSelfAdjointSubmodule] constructor Β· rintro ⟨f, hf, hA⟩ have hf' : f = toLin' A₁ := by rw [← hA, Matrix.toLin'_toMatrix'] rw [hf'] at hf rw [← isAdjointPair_toLinearMapβ‚‚'] exact hf Β· intro h refine ⟨toLin' A₁, ?_, LinearMap.toMatrix'_toLin' _⟩ exact (isAdjointPair_toLinearMapβ‚‚' _ _ _ _).mpr h /-- The submodule of self-adjoint matrices with respect to the bilinear form corresponding to the matrix `J`. -/
Mathlib/LinearAlgebra/Matrix/SesquilinearForm.lean
563
584
/- Copyright (c) 2022 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Analysis.Normed.Group.Quotient import Mathlib.Analysis.NormedSpace.Pointwise import Mathlib.Topology.Instances.AddCircle /-! # The additive circle as a normed group We define the normed group structure on `AddCircle p`, for `p : ℝ`. For example if `p = 1` then: `β€–(x : AddCircle 1)β€– = |x - round x|` for any `x : ℝ` (see `UnitAddCircle.norm_eq`). ## Main definitions: * `AddCircle.norm_eq`: a characterisation of the norm on `AddCircle p` ## TODO * The fact `InnerProductGeometry.angle (Real.cos ΞΈ) (Real.sin ΞΈ) = β€–(ΞΈ : Real.Angle)β€–` -/ noncomputable section open Metric QuotientAddGroup Set open Int hiding mem_zmultiples_iff open AddSubgroup namespace AddCircle variable (p : ℝ) instance : NormedAddCommGroup (AddCircle p) := QuotientAddGroup.instNormedAddCommGroup _ @[simp] theorem norm_coe_mul (x : ℝ) (t : ℝ) : β€–(↑(t * x) : AddCircle (t * p))β€– = |t| * β€–(x : AddCircle p)β€– := by obtain rfl | ht := eq_or_ne t 0 Β· simp simp only [norm_eq_infDist, Real.norm_eq_abs, ← Real.norm_eq_abs, ← infDist_smulβ‚€ ht, smul_zero] congr with m simp only [zmultiples, eq_iff_sub_mem, zsmul_eq_mul, mem_mk, mem_setOf_eq, mem_smul_set_iff_inv_smul_memβ‚€ ht, smul_eq_mul] simp_rw [mul_left_comm, ← smul_eq_mul, Set.range_smul, mem_smul_set_iff_inv_smul_memβ‚€ ht] simp [mul_sub, ht, -mem_range] theorem norm_neg_period (x : ℝ) : β€–(x : AddCircle (-p))β€– = β€–(x : AddCircle p)β€– := by suffices β€–(↑(-1 * x) : AddCircle (-1 * p))β€– = β€–(x : AddCircle p)β€– by rw [← this, neg_one_mul] simp simp only [norm_coe_mul, abs_neg, abs_one, one_mul] @[simp] theorem norm_eq_of_zero {x : ℝ} : β€–(x : AddCircle (0 : ℝ))β€– = |x| := by suffices { y : ℝ | (y : AddCircle (0 : ℝ)) = (x : AddCircle (0 : ℝ)) } = {x} by simp [norm_eq_infDist, this] ext y simp [eq_iff_sub_mem, mem_zmultiples_iff, sub_eq_zero] theorem norm_eq {x : ℝ} : β€–(x : AddCircle p)β€– = |x - round (p⁻¹ * x) * p| := by suffices βˆ€ x : ℝ, β€–(x : AddCircle (1 : ℝ))β€– = |x - round x| by rcases eq_or_ne p 0 with (rfl | hp) Β· simp have hx := norm_coe_mul p x p⁻¹ rw [abs_inv, eq_inv_mul_iff_mul_eqβ‚€ ((not_congr abs_eq_zero).mpr hp)] at hx rw [← hx, inv_mul_cancelβ‚€ hp, this, ← abs_mul, mul_sub, mul_inv_cancel_leftβ‚€ hp, mul_comm p] clear! x p intros x simp only [le_antisymm_iff, le_norm_iff, Real.norm_eq_abs] refine ⟨le_of_forall_le fun r hr ↦ ?_, ?_⟩ Β· rw [abs_sub_round_eq_min, le_inf_iff] rw [le_norm_iff] at hr constructor Β· simpa [abs_of_nonneg] using hr (fract x) Β· simpa [abs_sub_comm (fract x)] using hr (fract x - 1) (by simp [← self_sub_floor, ← sub_eq_zero, sub_sub]; simp) Β· simpa [zmultiples, QuotientAddGroup.eq, zsmul_eq_mul, mul_one, mem_mk, mem_range, and_imp, forall_exists_index, eq_neg_add_iff_add_eq, ← eq_sub_iff_add_eq, forall_swap (Ξ± := β„•)] using round_le _ theorem norm_eq' (hp : 0 < p) {x : ℝ} : β€–(x : AddCircle p)β€– = p * |p⁻¹ * x - round (p⁻¹ * x)| := by conv_rhs => congr rw [← abs_eq_self.mpr hp.le] rw [← abs_mul, mul_sub, mul_inv_cancel_leftβ‚€ hp.ne.symm, norm_eq, mul_comm p] theorem norm_le_half_period {x : AddCircle p} (hp : p β‰  0) : β€–xβ€– ≀ |p| / 2 := by obtain ⟨x⟩ := x change β€–(x : AddCircle p)β€– ≀ |p| / 2 rw [norm_eq, ← mul_le_mul_left (abs_pos.mpr (inv_ne_zero hp)), ← abs_mul, mul_sub, mul_left_comm, ← mul_div_assoc, ← abs_mul, inv_mul_cancelβ‚€ hp, mul_one, abs_one] exact abs_sub_round (p⁻¹ * x) @[simp] theorem norm_half_period_eq : β€–(↑(p / 2) : AddCircle p)β€– = |p| / 2 := by rcases eq_or_ne p 0 with (rfl | hp); Β· simp rw [norm_eq, ← mul_div_assoc, inv_mul_cancelβ‚€ hp, one_div, round_two_inv, Int.cast_one, one_mul, (by linarith : p / 2 - p = -(p / 2)), abs_neg, abs_div, abs_two] theorem norm_coe_eq_abs_iff {x : ℝ} (hp : p β‰  0) : β€–(x : AddCircle p)β€– = |x| ↔ |x| ≀ |p| / 2 := by refine ⟨fun hx => hx β–Έ norm_le_half_period p hp, fun hx => ?_⟩ suffices βˆ€ p : ℝ, 0 < p β†’ |x| ≀ p / 2 β†’ β€–(x : AddCircle p)β€– = |x| by rcases hp.symm.lt_or_lt with (hp | hp) Β· rw [abs_eq_self.mpr hp.le] at hx exact this p hp hx Β· rw [← norm_neg_period] rw [abs_eq_neg_self.mpr hp.le] at hx exact this (-p) (neg_pos.mpr hp) hx clear hx intro p hp hx rcases eq_or_ne x (p / (2 : ℝ)) with (rfl | hx') Β· simp [abs_div, abs_two] suffices round (p⁻¹ * x) = 0 by simp [norm_eq, this] rw [round_eq_zero_iff] obtain ⟨hx₁, hxβ‚‚βŸ© := abs_le.mp hx replace hxβ‚‚ := Ne.lt_of_le hx' hxβ‚‚ constructor Β· rwa [← mul_le_mul_left hp, ← mul_assoc, mul_inv_cancelβ‚€ hp.ne.symm, one_mul, mul_neg, ← mul_div_assoc, mul_one] Β· rwa [← mul_lt_mul_left hp, ← mul_assoc, mul_inv_cancelβ‚€ hp.ne.symm, one_mul, ← mul_div_assoc, mul_one] open Metric theorem closedBall_eq_univ_of_half_period_le (hp : p β‰  0) (x : AddCircle p) {Ξ΅ : ℝ} (hΞ΅ : |p| / 2 ≀ Ξ΅) : closedBall x Ξ΅ = univ := eq_univ_iff_forall.mpr fun x => by simpa only [mem_closedBall, dist_eq_norm] using (norm_le_half_period p hp).trans hΞ΅ @[simp] theorem coe_real_preimage_closedBall_period_zero (x Ξ΅ : ℝ) : (↑) ⁻¹' closedBall (x : AddCircle (0 : ℝ)) Ξ΅ = closedBall x Ξ΅ := by ext y simp [dist_eq_norm, ← QuotientAddGroup.mk_sub] theorem coe_real_preimage_closedBall_eq_iUnion (x Ξ΅ : ℝ) : (↑) ⁻¹' closedBall (x : AddCircle p) Ξ΅ = ⋃ z : β„€, closedBall (x + z β€’ p) Ξ΅ := by rcases eq_or_ne p 0 with (rfl | hp) Β· simp [iUnion_const] ext y simp only [dist_eq_norm, mem_preimage, mem_closedBall, zsmul_eq_mul, mem_iUnion, Real.norm_eq_abs, ← QuotientAddGroup.mk_sub, norm_eq, ← sub_sub] refine ⟨fun h => ⟨round (p⁻¹ * (y - x)), h⟩, ?_⟩ rintro ⟨n, hn⟩ rw [← mul_le_mul_left (abs_pos.mpr <| inv_ne_zero hp), ← abs_mul, mul_sub, mul_comm _ p, inv_mul_cancel_leftβ‚€ hp] at hn ⊒ exact (round_le (p⁻¹ * (y - x)) n).trans hn theorem coe_real_preimage_closedBall_inter_eq {x Ξ΅ : ℝ} (s : Set ℝ) (hs : s βŠ† closedBall x (|p| / 2)) : (↑) ⁻¹' closedBall (x : AddCircle p) Ξ΅ ∩ s = if Ξ΅ < |p| / 2 then closedBall x Ξ΅ ∩ s else s := by rcases le_or_lt (|p| / 2) Ξ΅ with hΞ΅ | hΞ΅ Β· rcases eq_or_ne p 0 with (rfl | hp) Β· simp only [abs_zero, zero_div] at hΞ΅ simp only [not_lt.mpr hΞ΅, coe_real_preimage_closedBall_period_zero, abs_zero, zero_div, if_false, inter_eq_right] exact hs.trans (closedBall_subset_closedBall <| by simp [hΞ΅]) simp [closedBall_eq_univ_of_half_period_le p hp (↑x) hΞ΅, not_lt.mpr hΞ΅] Β· suffices βˆ€ z : β„€, closedBall (x + z β€’ p) Ξ΅ ∩ s = if z = 0 then closedBall x Ξ΅ ∩ s else βˆ… by simp [-zsmul_eq_mul, ← QuotientAddGroup.mk_zero, coe_real_preimage_closedBall_eq_iUnion, iUnion_inter, iUnion_ite, this, hΞ΅] intro z simp only [Real.closedBall_eq_Icc, zero_sub, zero_add] at hs ⊒ rcases eq_or_ne z 0 with (rfl | hz) Β· simp simp only [hz, zsmul_eq_mul, if_false, eq_empty_iff_forall_not_mem] rintro y ⟨⟨hy₁, hyβ‚‚βŸ©, hyβ‚€βŸ© obtain ⟨hy₃, hyβ‚„βŸ© := hs hyβ‚€ rcases lt_trichotomy 0 p with (hp | (rfl : 0 = p) | hp) Β· rcases Int.cast_le_neg_one_or_one_le_cast_of_ne_zero ℝ hz with hz' | hz' Β· have : ↑z * p ≀ -p := by nlinarith linarith [abs_eq_self.mpr hp.le] Β· have : p ≀ ↑z * p := by nlinarith linarith [abs_eq_self.mpr hp.le] Β· simp only [mul_zero, add_zero, abs_zero, zero_div] at hy₁ hyβ‚‚ hΞ΅ linarith Β· rcases Int.cast_le_neg_one_or_one_le_cast_of_ne_zero ℝ hz with hz' | hz' Β· have : -p ≀ ↑z * p := by nlinarith linarith [abs_eq_neg_self.mpr hp.le] Β· have : ↑z * p ≀ p := by nlinarith linarith [abs_eq_neg_self.mpr hp.le] section FiniteOrderPoints variable {p} [hp : Fact (0 < p)] theorem norm_div_natCast {m n : β„•} : β€–(↑(↑m / ↑n * p) : AddCircle p)β€– = p * (↑(min (m % n) (n - m % n)) / n) := by have : p⁻¹ * (↑m / ↑n * p) = ↑m / ↑n := by rw [mul_comm _ p, inv_mul_cancel_leftβ‚€ hp.out.ne.symm] rw [norm_eq' p hp.out, this, abs_sub_round_div_natCast_eq] theorem exists_norm_eq_of_isOfFinAddOrder {u : AddCircle p} (hu : IsOfFinAddOrder u) : βˆƒ k : β„•, β€–uβ€– = p * (k / addOrderOf u) := by let n := addOrderOf u change βˆƒ k : β„•, β€–uβ€– = p * (k / n) obtain ⟨m, -, -, hm⟩ := exists_gcd_eq_one_of_isOfFinAddOrder hu refine ⟨min (m % n) (n - m % n), ?_⟩ rw [← hm, norm_div_natCast] theorem le_add_order_smul_norm_of_isOfFinAddOrder {u : AddCircle p} (hu : IsOfFinAddOrder u) (hu' : u β‰  0) : p ≀ addOrderOf u β€’ β€–uβ€– := by obtain ⟨n, hn⟩ := exists_norm_eq_of_isOfFinAddOrder hu replace hu : (addOrderOf u : ℝ) β‰  0 := by norm_cast exact (addOrderOf_pos_iff.mpr hu).ne' conv_lhs => rw [← mul_one p] rw [hn, nsmul_eq_mul, ← mul_assoc, mul_comm _ p, mul_assoc, mul_div_cancelβ‚€ _ hu, mul_le_mul_left hp.out, Nat.one_le_cast, Nat.one_le_iff_ne_zero] contrapose! hu' simpa only [hu', Nat.cast_zero, zero_div, mul_zero, norm_eq_zero] using hn end FiniteOrderPoints end AddCircle namespace UnitAddCircle theorem norm_eq {x : ℝ} : β€–(x : UnitAddCircle)β€– = |x - round x| := by simp [AddCircle.norm_eq] end UnitAddCircle
Mathlib/Analysis/Normed/Group/AddCircle.lean
259
269
/- Copyright (c) 2014 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Leonardo de Moura, Johannes HΓΆlzl, Mario Carneiro -/ import Mathlib.Algebra.Field.Defs import Mathlib.Algebra.Ring.Commute import Mathlib.Algebra.Ring.Invertible import Mathlib.Order.Synonym /-! # Lemmas about division (semi)rings and (semi)fields -/ open Function OrderDual Set universe u variable {K L : Type*} section DivisionSemiring variable [DivisionSemiring K] {a b c d : K} theorem add_div (a b c : K) : (a + b) / c = a / c + b / c := by simp_rw [div_eq_mul_inv, add_mul] @[field_simps] theorem div_add_div_same (a b c : K) : a / c + b / c = (a + b) / c := (add_div _ _ _).symm theorem same_add_div (h : b β‰  0) : (b + a) / b = 1 + a / b := by rw [← div_self h, add_div] theorem div_add_same (h : b β‰  0) : (a + b) / b = a / b + 1 := by rw [← div_self h, add_div] theorem one_add_div (h : b β‰  0) : 1 + a / b = (b + a) / b := (same_add_div h).symm theorem div_add_one (h : b β‰  0) : a / b + 1 = (a + b) / b :=
(div_add_same h).symm
Mathlib/Algebra/Field/Basic.lean
40
40
/- 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, Kim Morrison, Jens Wagemaker -/ import Mathlib.Algebra.Polynomial.Reverse import Mathlib.Algebra.Regular.SMul /-! # Theory of monic polynomials We give several tools for proving that polynomials are monic, e.g. `Monic.mul`, `Monic.map`, `Monic.pow`. -/ noncomputable section open Finset open Polynomial namespace Polynomial universe u v y variable {R : Type u} {S : Type v} {a b : R} {m n : β„•} {ΞΉ : Type y} section Semiring variable [Semiring R] {p q r : R[X]} theorem monic_zero_iff_subsingleton : Monic (0 : R[X]) ↔ Subsingleton R := subsingleton_iff_zero_eq_one theorem not_monic_zero_iff : Β¬Monic (0 : R[X]) ↔ (0 : R) β‰  1 := (monic_zero_iff_subsingleton.trans subsingleton_iff_zero_eq_one.symm).not theorem monic_zero_iff_subsingleton' : Monic (0 : R[X]) ↔ (βˆ€ f g : R[X], f = g) ∧ βˆ€ a b : R, a = b := Polynomial.monic_zero_iff_subsingleton.trans ⟨by intro simp [eq_iff_true_of_subsingleton], fun h => subsingleton_iff.mpr h.2⟩ theorem Monic.as_sum (hp : p.Monic) : p = X ^ p.natDegree + βˆ‘ i ∈ range p.natDegree, C (p.coeff i) * X ^ i := by conv_lhs => rw [p.as_sum_range_C_mul_X_pow, sum_range_succ_comm] suffices C (p.coeff p.natDegree) = 1 by rw [this, one_mul] exact congr_arg C hp theorem ne_zero_of_ne_zero_of_monic (hp : p β‰  0) (hq : Monic q) : q β‰  0 := by rintro rfl rw [Monic.def, leadingCoeff_zero] at hq rw [← mul_one p, ← C_1, ← hq, C_0, mul_zero] at hp exact hp rfl theorem Monic.map [Semiring S] (f : R β†’+* S) (hp : Monic p) : Monic (p.map f) := by unfold Monic nontriviality have : f p.leadingCoeff β‰  0 := by rw [show _ = _ from hp, f.map_one] exact one_ne_zero rw [Polynomial.leadingCoeff, coeff_map] suffices p.coeff (p.map f).natDegree = 1 by simp [this] rwa [natDegree_eq_of_degree_eq (degree_map_eq_of_leadingCoeff_ne_zero f this)] theorem monic_C_mul_of_mul_leadingCoeff_eq_one {b : R} (hp : b * p.leadingCoeff = 1) : Monic (C b * p) := by unfold Monic nontriviality rw [leadingCoeff_mul' _] <;> simp [leadingCoeff_C b, hp] theorem monic_mul_C_of_leadingCoeff_mul_eq_one {b : R} (hp : p.leadingCoeff * b = 1) : Monic (p * C b) := by unfold Monic nontriviality rw [leadingCoeff_mul' _] <;> simp [leadingCoeff_C b, hp] theorem monic_of_degree_le (n : β„•) (H1 : degree p ≀ n) (H2 : coeff p n = 1) : Monic p := Decidable.byCases (fun H : degree p < n => eq_of_zero_eq_one (H2 β–Έ (coeff_eq_zero_of_degree_lt H).symm) _ _) fun H : Β¬degree p < n => by rwa [Monic, Polynomial.leadingCoeff, natDegree, (lt_or_eq_of_le H1).resolve_left H] theorem monic_X_pow_add {n : β„•} (H : degree p < n) : Monic (X ^ n + p) := monic_of_degree_le n (le_trans (degree_add_le _ _) (max_le (degree_X_pow_le _) (le_of_lt H))) (by rw [coeff_add, coeff_X_pow, if_pos rfl, coeff_eq_zero_of_degree_lt H, add_zero]) variable (a) in theorem monic_X_pow_add_C {n : β„•} (h : n β‰  0) : (X ^ n + C a).Monic := monic_X_pow_add <| (lt_of_le_of_lt degree_C_le (by simp only [Nat.cast_pos, Nat.pos_iff_ne_zero, ne_eq, h, not_false_eq_true])) theorem monic_X_add_C (x : R) : Monic (X + C x) := pow_one (X : R[X]) β–Έ monic_X_pow_add_C x one_ne_zero theorem Monic.mul (hp : Monic p) (hq : Monic q) : Monic (p * q) := letI := Classical.decEq R if h0 : (0 : R) = 1 then haveI := subsingleton_of_zero_eq_one h0 Subsingleton.elim _ _ else by have : p.leadingCoeff * q.leadingCoeff β‰  0 := by simp [Monic.def.1 hp, Monic.def.1 hq, Ne.symm h0] rw [Monic.def, leadingCoeff_mul' this, Monic.def.1 hp, Monic.def.1 hq, one_mul] theorem Monic.pow (hp : Monic p) : βˆ€ n : β„•, Monic (p ^ n) | 0 => monic_one | n + 1 => by rw [pow_succ] exact (Monic.pow hp n).mul hp theorem Monic.add_of_left (hp : Monic p) (hpq : degree q < degree p) : Monic (p + q) := by rwa [Monic, add_comm, leadingCoeff_add_of_degree_lt hpq] theorem Monic.add_of_right (hq : Monic q) (hpq : degree p < degree q) : Monic (p + q) := by rwa [Monic, leadingCoeff_add_of_degree_lt hpq] theorem Monic.of_mul_monic_left (hp : p.Monic) (hpq : (p * q).Monic) : q.Monic := by contrapose! hpq rw [Monic.def] at hpq ⊒ rwa [leadingCoeff_monic_mul hp] theorem Monic.of_mul_monic_right (hq : q.Monic) (hpq : (p * q).Monic) : p.Monic := by contrapose! hpq rw [Monic.def] at hpq ⊒ rwa [leadingCoeff_mul_monic hq] namespace Monic lemma comp (hp : p.Monic) (hq : q.Monic) (h : q.natDegree β‰  0) : (p.comp q).Monic := by nontriviality R have : (p.comp q).natDegree = p.natDegree * q.natDegree := natDegree_comp_eq_of_mul_ne_zero <| by simp [hp.leadingCoeff, hq.leadingCoeff] rw [Monic.def, Polynomial.leadingCoeff, this, coeff_comp_degree_mul_degree h, hp.leadingCoeff, hq.leadingCoeff, one_pow, mul_one] lemma comp_X_add_C (hp : p.Monic) (r : R) : (p.comp (X + C r)).Monic := by nontriviality R refine hp.comp (monic_X_add_C _) fun ha ↦ ?_ rw [natDegree_X_add_C] at ha exact one_ne_zero ha @[simp] theorem natDegree_eq_zero_iff_eq_one (hp : p.Monic) : p.natDegree = 0 ↔ p = 1 := by constructor <;> intro h swap Β· rw [h] exact natDegree_one have : p = C (p.coeff 0) := by rw [← Polynomial.degree_le_zero_iff] rwa [Polynomial.natDegree_eq_zero_iff_degree_le_zero] at h rw [this] rw [← h, ← Polynomial.leadingCoeff, Monic.def.1 hp, C_1] @[simp] theorem degree_le_zero_iff_eq_one (hp : p.Monic) : p.degree ≀ 0 ↔ p = 1 := by rw [← hp.natDegree_eq_zero_iff_eq_one, natDegree_eq_zero_iff_degree_le_zero] theorem natDegree_mul (hp : p.Monic) (hq : q.Monic) : (p * q).natDegree = p.natDegree + q.natDegree := by nontriviality R apply natDegree_mul' simp [hp.leadingCoeff, hq.leadingCoeff] theorem degree_mul_comm (hp : p.Monic) (q : R[X]) : (p * q).degree = (q * p).degree := by by_cases h : q = 0 Β· simp [h] rw [degree_mul', hp.degree_mul] Β· exact add_comm _ _ Β· rwa [hp.leadingCoeff, one_mul, leadingCoeff_ne_zero] nonrec theorem natDegree_mul' (hp : p.Monic) (hq : q β‰  0) : (p * q).natDegree = p.natDegree + q.natDegree := by rw [natDegree_mul'] simpa [hp.leadingCoeff, leadingCoeff_ne_zero] theorem natDegree_mul_comm (hp : p.Monic) (q : R[X]) : (p * q).natDegree = (q * p).natDegree := by by_cases h : q = 0 Β· simp [h] rw [hp.natDegree_mul' h, Polynomial.natDegree_mul', add_comm] simpa [hp.leadingCoeff, leadingCoeff_ne_zero] theorem not_dvd_of_natDegree_lt (hp : Monic p) (h0 : q β‰  0) (hl : natDegree q < natDegree p) : Β¬p ∣ q := by rintro ⟨r, rfl⟩ rw [hp.natDegree_mul' <| right_ne_zero_of_mul h0] at hl exact hl.not_le (Nat.le_add_right _ _) theorem not_dvd_of_degree_lt (hp : Monic p) (h0 : q β‰  0) (hl : degree q < degree p) : Β¬p ∣ q := Monic.not_dvd_of_natDegree_lt hp h0 <| natDegree_lt_natDegree h0 hl theorem nextCoeff_mul (hp : Monic p) (hq : Monic q) : nextCoeff (p * q) = nextCoeff p + nextCoeff q := by nontriviality simp only [← coeff_one_reverse] rw [reverse_mul] <;> simp [hp.leadingCoeff, hq.leadingCoeff, mul_coeff_one, add_comm] theorem nextCoeff_pow (hp : p.Monic) (n : β„•) : (p ^ n).nextCoeff = n β€’ p.nextCoeff := by induction n with
| zero => rw [pow_zero, zero_smul, ← map_one (f := C), nextCoeff_C_eq_zero] | succ n ih => rw [pow_succ, (hp.pow n).nextCoeff_mul hp, ih, succ_nsmul] theorem eq_one_of_map_eq_one {S : Type*} [Semiring S] [Nontrivial S] (f : R β†’+* S) (hp : p.Monic) (map_eq : p.map f = 1) : p = 1 := by
Mathlib/Algebra/Polynomial/Monic.lean
203
207
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes HΓΆlzl, Yuyang Zhao -/ import Mathlib.Algebra.Group.Units.Basic import Mathlib.Algebra.Order.Monoid.Defs import Mathlib.Algebra.Order.Monoid.Unbundled.ExistsOfLE import Mathlib.Algebra.NeZero import Mathlib.Order.BoundedOrder.Basic /-! # Canonically ordered monoids -/ universe u variable {Ξ± : Type u} /-- An ordered additive monoid is `CanonicallyOrderedAdd` if the ordering coincides with the subtractibility relation, which is to say, `a ≀ b` iff there exists `c` with `b = a + c`. This is satisfied by the natural numbers, for example, but not the integers or other nontrivial `OrderedAddCommGroup`s. -/ class CanonicallyOrderedAdd (Ξ± : Type*) [Add Ξ±] [LE Ξ±] : Prop extends ExistsAddOfLE Ξ± where /-- For any `a` and `b`, `a ≀ a + b` -/ protected le_self_add : βˆ€ a b : Ξ±, a ≀ a + b attribute [instance 50] CanonicallyOrderedAdd.toExistsAddOfLE /-- An ordered monoid is `CanonicallyOrderedMul` if the ordering coincides with the divisibility relation, which is to say, `a ≀ b` iff there exists `c` with `b = a * c`. Examples seem rare; it seems more likely that the `OrderDual` of a naturally-occurring lattice satisfies this than the lattice itself (for example, dual of the lattice of ideals of a PID or Dedekind domain satisfy this; collections of all things ≀ 1 seem to be more natural that collections of all things β‰₯ 1). -/ @[to_additive] class CanonicallyOrderedMul (Ξ± : Type*) [Mul Ξ±] [LE Ξ±] : Prop extends ExistsMulOfLE Ξ± where /-- For any `a` and `b`, `a ≀ a * b` -/ protected le_self_mul : βˆ€ a b : Ξ±, a ≀ a * b attribute [instance 50] CanonicallyOrderedMul.toExistsMulOfLE set_option linter.deprecated false in /-- A canonically ordered additive monoid is an ordered commutative additive monoid in which the ordering coincides with the subtractibility relation, which is to say, `a ≀ b` iff there exists `c` with `b = a + c`. This is satisfied by the natural numbers, for example, but not the integers or other nontrivial `OrderedAddCommGroup`s. -/ @[deprecated "Use `[OrderedAddCommMonoid Ξ±] [CanonicallyOrderedAdd Ξ±]` instead." (since := "2025-01-13")] structure CanonicallyOrderedAddCommMonoid (Ξ± : Type*) extends OrderedAddCommMonoid Ξ±, OrderBot Ξ± where /-- For `a ≀ b`, there is a `c` so `b = a + c`. -/ protected exists_add_of_le : βˆ€ {a b : Ξ±}, a ≀ b β†’ βˆƒ c, b = a + c /-- For any `a` and `b`, `a ≀ a + b` -/ protected le_self_add : βˆ€ a b : Ξ±, a ≀ a + b set_option linter.deprecated false in set_option linter.existingAttributeWarning false in /-- A canonically ordered monoid is an ordered commutative monoid in which the ordering coincides with the divisibility relation, which is to say, `a ≀ b` iff there exists `c` with `b = a * c`. Examples seem rare; it seems more likely that the `OrderDual` of a naturally-occurring lattice satisfies this than the lattice itself (for example, dual of the lattice of ideals of a PID or Dedekind domain satisfy this; collections of all things ≀ 1 seem to be more natural that collections of all things β‰₯ 1). -/ @[to_additive, deprecated "Use `[OrderedCommMonoid Ξ±] [CanonicallyOrderedMul Ξ±]` instead." (since := "2025-01-13")] structure CanonicallyOrderedCommMonoid (Ξ± : Type*) extends OrderedCommMonoid Ξ±, OrderBot Ξ± where /-- For `a ≀ b`, there is a `c` so `b = a * c`. -/ protected exists_mul_of_le : βˆ€ {a b : Ξ±}, a ≀ b β†’ βˆƒ c, b = a * c /-- For any `a` and `b`, `a ≀ a * b` -/ protected le_self_mul : βˆ€ a b : Ξ±, a ≀ a * b section Mul variable [Mul Ξ±] section LE variable [LE Ξ±] [CanonicallyOrderedMul Ξ±] {a b c : Ξ±} @[to_additive] theorem le_self_mul : a ≀ a * b := CanonicallyOrderedMul.le_self_mul _ _ @[to_additive (attr := simp)] theorem self_le_mul_right (a b : Ξ±) : a ≀ a * b := le_self_mul @[to_additive] theorem le_iff_exists_mul : a ≀ b ↔ βˆƒ c, b = a * c := ⟨exists_mul_of_le, by rintro ⟨c, rfl⟩ exact le_self_mul⟩ end LE section Preorder variable [Preorder Ξ±] [CanonicallyOrderedMul Ξ±] {a b c : Ξ±} @[to_additive] theorem le_of_mul_le_left : a * b ≀ c β†’ a ≀ c := le_self_mul.trans @[to_additive] theorem le_mul_of_le_left : a ≀ b β†’ a ≀ b * c := le_self_mul.trans' @[to_additive] alias le_mul_right := le_mul_of_le_left end Preorder end Mul section CommMagma variable [CommMagma Ξ±] section LE variable [LE Ξ±] [CanonicallyOrderedMul Ξ±] {a b : Ξ±} @[to_additive] theorem le_mul_self : a ≀ b * a := by rw [mul_comm] exact le_self_mul @[to_additive (attr := simp)] theorem self_le_mul_left (a b : Ξ±) : a ≀ b * a := le_mul_self end LE section Preorder variable [Preorder Ξ±] [CanonicallyOrderedMul Ξ±] {a b c : Ξ±} @[to_additive] theorem le_of_mul_le_right : a * b ≀ c β†’ b ≀ c := le_mul_self.trans @[to_additive] theorem le_mul_of_le_right : a ≀ c β†’ a ≀ b * c := le_mul_self.trans' @[to_additive] alias le_mul_left := le_mul_of_le_right @[to_additive] theorem le_iff_exists_mul' : a ≀ b ↔ βˆƒ c, b = c * a := by simp only [mul_comm _ a, le_iff_exists_mul] end Preorder end CommMagma section MulOneClass variable [MulOneClass Ξ±] section LE variable [LE Ξ±] [CanonicallyOrderedMul Ξ±] {a b : Ξ±} @[to_additive (attr := simp) zero_le] theorem one_le (a : Ξ±) : 1 ≀ a := le_self_mul.trans_eq (one_mul _) @[to_additive] instance (priority := 10) CanonicallyOrderedMul.toOrderBot : OrderBot Ξ± where bot := 1 bot_le := one_le @[to_additive] theorem bot_eq_one : (βŠ₯ : Ξ±) = 1 := rfl end LE section Preorder variable [Preorder Ξ±] [CanonicallyOrderedMul Ξ±] {a b : Ξ±} @[to_additive (attr := simp)] theorem one_lt_of_gt (h : a < b) : 1 < b := h.bot_lt alias LT.lt.pos := pos_of_gt @[to_additive existing] alias LT.lt.one_lt := one_lt_of_gt end Preorder section PartialOrder variable [PartialOrder Ξ±] [CanonicallyOrderedMul Ξ±] {a b c : Ξ±} @[to_additive (attr := simp)] theorem le_one_iff_eq_one : a ≀ 1 ↔ a = 1 := le_bot_iff @[to_additive] theorem one_lt_iff_ne_one : 1 < a ↔ a β‰  1 := bot_lt_iff_ne_bot @[to_additive] theorem one_lt_of_ne_one (h : a β‰  1) : 1 < a := h.bot_lt @[to_additive] theorem eq_one_or_one_lt (a : Ξ±) : a = 1 ∨ 1 < a := eq_bot_or_bot_lt a @[to_additive] lemma one_not_mem_iff {s : Set Ξ±} : 1 βˆ‰ s ↔ βˆ€ x ∈ s, 1 < x := bot_not_mem_iff alias NE.ne.pos := pos_of_ne_zero @[to_additive existing] alias NE.ne.one_lt := one_lt_of_ne_one @[to_additive] theorem exists_one_lt_mul_of_lt (h : a < b) : βˆƒ (c : _) (_ : 1 < c), a * c = b := by obtain ⟨c, hc⟩ := le_iff_exists_mul.1 h.le refine ⟨c, one_lt_iff_ne_one.2 ?_, hc.symm⟩ rintro rfl simp [hc, lt_irrefl] at h @[to_additive] theorem lt_iff_exists_mul [MulLeftStrictMono Ξ±] : a < b ↔ βˆƒ c > 1, b = a * c := by rw [lt_iff_le_and_ne, le_iff_exists_mul, ← exists_and_right] apply exists_congr intro c rw [and_comm, and_congr_left_iff, gt_iff_lt] rintro rfl constructor Β· rw [one_lt_iff_ne_one] apply mt rintro rfl rw [mul_one] Β· rw [← (self_le_mul_right a c).lt_iff_ne] apply lt_mul_of_one_lt_right' end PartialOrder end MulOneClass section Semigroup variable [Semigroup Ξ±] section LE variable [LE Ξ±] [CanonicallyOrderedMul Ξ±] -- see Note [lower instance priority] @[to_additive] instance (priority := 10) CanonicallyOrderedMul.toMulLeftMono : MulLeftMono Ξ± where elim a b c hbc := by obtain ⟨c, hc, rfl⟩ := exists_mul_of_le hbc rw [le_iff_exists_mul] exact ⟨c, (mul_assoc _ _ _).symm⟩ end LE end Semigroup -- TODO: make it an instance @[to_additive] lemma CanonicallyOrderedMul.toIsOrderedMonoid [CommMonoid Ξ±] [PartialOrder Ξ±] [CanonicallyOrderedMul Ξ±] : IsOrderedMonoid Ξ± where mul_le_mul_left _ _ := mul_le_mul_left' section Monoid variable [Monoid Ξ±] section PartialOrder variable [PartialOrder Ξ±] [CanonicallyOrderedMul Ξ±] {a b c : Ξ±} @[to_additive] instance CanonicallyOrderedCommMonoid.toUniqueUnits : Unique Ξ±Λ£ where uniq a := Units.ext <| le_one_iff_eq_one.mp (le_of_mul_le_left a.mul_inv.le) end PartialOrder end Monoid section CommMonoid variable [CommMonoid Ξ±] section PartialOrder variable [PartialOrder Ξ±] [CanonicallyOrderedMul Ξ±] {a b c : Ξ±} @[to_additive (attr := simp) add_pos_iff] theorem one_lt_mul_iff : 1 < a * b ↔ 1 < a ∨ 1 < b := by simp only [one_lt_iff_ne_one, Ne, mul_eq_one, not_and_or] end PartialOrder end CommMonoid namespace NeZero theorem pos {M} [AddZeroClass M] [PartialOrder M] [CanonicallyOrderedAdd M] (a : M) [NeZero a] : 0 < a := (zero_le a).lt_of_ne <| NeZero.out.symm theorem of_gt {M} [AddZeroClass M] [Preorder M] [CanonicallyOrderedAdd M] {x y : M} (h : x < y) : NeZero y := of_pos <| pos_of_gt h -- 1 < p is still an often-used `Fact`, due to `Nat.Prime` implying it, and it implying `Nontrivial` -- on `ZMod`'s ring structure. We cannot just set this to be any `x < y`, else that becomes a -- metavariable and it will hugely slow down typeclass inference. instance (priority := 10) of_gt' {M : Type*} [AddZeroClass M] [Preorder M] [CanonicallyOrderedAdd M] [One M] {y : M} [Fact (1 < y)] : NeZero y := of_gt <| @Fact.out (1 < y) _ end NeZero set_option linter.deprecated false in /-- A canonically linear-ordered additive monoid is a canonically ordered additive monoid whose ordering is a linear order. -/ @[deprecated "Use `[LinearOrderedAddCommMonoid Ξ±] [CanonicallyOrderedAdd Ξ±]` instead." (since := "2025-01-13")] structure CanonicallyLinearOrderedAddCommMonoid (Ξ± : Type*) extends CanonicallyOrderedAddCommMonoid Ξ±, LinearOrderedAddCommMonoid Ξ± set_option linter.deprecated false in set_option linter.existingAttributeWarning false in /-- A canonically linear-ordered monoid is a canonically ordered monoid whose ordering is a linear order. -/ @[to_additive, deprecated "Use `[LinearOrderedCommMonoid Ξ±] [CanonicallyOrderedMul Ξ±]` instead." (since := "2025-01-13")] structure CanonicallyLinearOrderedCommMonoid (Ξ± : Type*) extends CanonicallyOrderedCommMonoid Ξ±, LinearOrderedCommMonoid Ξ± attribute [nolint docBlame] CanonicallyLinearOrderedAddCommMonoid.toLinearOrderedAddCommMonoid attribute [nolint docBlame] CanonicallyLinearOrderedCommMonoid.toLinearOrderedCommMonoid section CanonicallyLinearOrderedCommMonoid variable [CommMonoid Ξ±] [LinearOrder Ξ±] [CanonicallyOrderedMul Ξ±] @[to_additive] theorem min_mul_distrib (a b c : Ξ±) : min a (b * c) = min a (min a b * min a c) := by rcases le_total a b with hb | hb Β· simp [hb, le_mul_right] Β· rcases le_total a c with hc | hc Β· simp [hc, le_mul_left] Β· simp [hb, hc] @[to_additive] theorem min_mul_distrib' (a b c : Ξ±) : min (a * b) c = min (min a c * min b c) c := by simpa [min_comm _ c] using min_mul_distrib c a b @[to_additive] theorem one_min (a : Ξ±) : min 1 a = 1 := min_eq_left (one_le a) @[to_additive] theorem min_one (a : Ξ±) : min a 1 = 1 := min_eq_right (one_le a)
/-- In a linearly ordered monoid, we are happy for `bot_eq_one` to be a `@[simp]` lemma. -/ @[to_additive (attr := simp) "In a linearly ordered monoid, we are happy for `bot_eq_zero` to be a `@[simp]` lemma"] theorem bot_eq_one' : (βŠ₯ : Ξ±) = 1 := bot_eq_one
Mathlib/Algebra/Order/Monoid/Canonical/Defs.lean
344
349
/- Copyright (c) 2021 Benjamin Davidson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Benjamin Davidson -/ import Mathlib.Analysis.SpecialFunctions.Log.NegMulLog import Mathlib.Analysis.SpecialFunctions.NonIntegrable import Mathlib.Analysis.SpecialFunctions.Pow.Deriv import Mathlib.Analysis.SpecialFunctions.Trigonometric.ArctanDeriv import Mathlib.MeasureTheory.Integral.IntervalIntegral.IntegrationByParts /-! # Integration of specific interval integrals This file contains proofs of the integrals of various specific functions. This includes: * Integrals of simple functions, such as `id`, `pow`, `inv`, `exp`, `log` * Integrals of some trigonometric functions, such as `sin`, `cos`, `1 / (1 + x^2)` * The integral of `cos x ^ 2 - sin x ^ 2` * Reduction formulae for the integrals of `sin x ^ n` and `cos x ^ n` for `n β‰₯ 2` * The computation of `∫ x in 0..Ο€, sin x ^ n` as a product for even and odd `n` (used in proving the Wallis product for pi) * Integrals of the form `sin x ^ m * cos x ^ n` With these lemmas, many simple integrals can be computed by `simp` or `norm_num`. This file also contains some facts about the interval integrability of specific functions. This file is still being developed. ## Tags integrate, integration, integrable, integrability -/ open Real Set Finset open scoped Real Interval variable {a b : ℝ} (n : β„•) namespace intervalIntegral open MeasureTheory variable {f : ℝ β†’ ℝ} {ΞΌ : Measure ℝ} [IsLocallyFiniteMeasure ΞΌ] (c d : ℝ) /-! ### Interval integrability -/ @[simp] theorem intervalIntegrable_pow : IntervalIntegrable (fun x => x ^ n) ΞΌ a b := (continuous_pow n).intervalIntegrable a b theorem intervalIntegrable_zpow {n : β„€} (h : 0 ≀ n ∨ (0 : ℝ) βˆ‰ [[a, b]]) : IntervalIntegrable (fun x => x ^ n) ΞΌ a b := (continuousOn_id.zpowβ‚€ n fun _ hx => h.symm.imp (ne_of_mem_of_not_mem hx) id).intervalIntegrable /-- See `intervalIntegrable_rpow'` for a version with a weaker hypothesis on `r`, but assuming the measure is volume. -/ theorem intervalIntegrable_rpow {r : ℝ} (h : 0 ≀ r ∨ (0 : ℝ) βˆ‰ [[a, b]]) : IntervalIntegrable (fun x => x ^ r) ΞΌ a b := (continuousOn_id.rpow_const fun _ hx => h.symm.imp (ne_of_mem_of_not_mem hx) id).intervalIntegrable /-- See `intervalIntegrable_rpow` for a version applying to any locally finite measure, but with a stronger hypothesis on `r`. -/ theorem intervalIntegrable_rpow' {r : ℝ} (h : -1 < r) : IntervalIntegrable (fun x => x ^ r) volume a b := by suffices βˆ€ c : ℝ, IntervalIntegrable (fun x => x ^ r) volume 0 c by exact IntervalIntegrable.trans (this a).symm (this b) have : βˆ€ c : ℝ, 0 ≀ c β†’ IntervalIntegrable (fun x => x ^ r) volume 0 c := by intro c hc rw [intervalIntegrable_iff, uIoc_of_le hc] have hderiv : βˆ€ x ∈ Ioo 0 c, HasDerivAt (fun x : ℝ => x ^ (r + 1) / (r + 1)) (x ^ r) x := by intro x hx convert (Real.hasDerivAt_rpow_const (p := r + 1) (Or.inl hx.1.ne')).div_const (r + 1) using 1 field_simp [(by linarith : r + 1 β‰  0)] apply integrableOn_deriv_of_nonneg _ hderiv Β· intro x hx; apply rpow_nonneg hx.1.le Β· refine (continuousOn_id.rpow_const ?_).div_const _; intro x _; right; linarith intro c; rcases le_total 0 c with (hc | hc) Β· exact this c hc Β· rw [IntervalIntegrable.iff_comp_neg, neg_zero] have m := (this (-c) (by linarith)).smul (cos (r * Ο€)) rw [intervalIntegrable_iff] at m ⊒ refine m.congr_fun ?_ measurableSet_Ioc; intro x hx rw [uIoc_of_le (by linarith : 0 ≀ -c)] at hx simp only [Pi.smul_apply, Algebra.id.smul_eq_mul, log_neg_eq_log, mul_comm, rpow_def_of_pos hx.1, rpow_def_of_neg (by linarith [hx.1] : -x < 0)] /-- The power function `x ↦ x^s` is integrable on `(0, t)` iff `-1 < s`. -/ lemma integrableOn_Ioo_rpow_iff {s t : ℝ} (ht : 0 < t) : IntegrableOn (fun x ↦ x ^ s) (Ioo (0 : ℝ) t) ↔ -1 < s := by refine ⟨fun h ↦ ?_, fun h ↦ by simpa [intervalIntegrable_iff_integrableOn_Ioo_of_le ht.le] using intervalIntegrable_rpow' h (a := 0) (b := t)⟩ contrapose! h intro H have I : 0 < min 1 t := lt_min zero_lt_one ht have H' : IntegrableOn (fun x ↦ x ^ s) (Ioo 0 (min 1 t)) := H.mono (Set.Ioo_subset_Ioo le_rfl (min_le_right _ _)) le_rfl have : IntegrableOn (fun x ↦ x⁻¹) (Ioo 0 (min 1 t)) := by apply H'.mono' measurable_inv.aestronglyMeasurable filter_upwards [ae_restrict_mem measurableSet_Ioo] with x hx simp only [norm_inv, Real.norm_eq_abs, abs_of_nonneg (le_of_lt hx.1)] rwa [← Real.rpow_neg_one x, Real.rpow_le_rpow_left_iff_of_base_lt_one hx.1] exact lt_of_lt_of_le hx.2 (min_le_left _ _) have : IntervalIntegrable (fun x ↦ x⁻¹) volume 0 (min 1 t) := by rwa [intervalIntegrable_iff_integrableOn_Ioo_of_le I.le] simp [intervalIntegrable_inv_iff, I.ne] at this /-- See `intervalIntegrable_cpow'` for a version with a weaker hypothesis on `r`, but assuming the measure is volume. -/ theorem intervalIntegrable_cpow {r : β„‚} (h : 0 ≀ r.re ∨ (0 : ℝ) βˆ‰ [[a, b]]) : IntervalIntegrable (fun x : ℝ => (x : β„‚) ^ r) ΞΌ a b := by by_cases h2 : (0 : ℝ) βˆ‰ [[a, b]] Β· -- Easy case #1: 0 βˆ‰ [a, b] -- use continuity. refine (continuousOn_of_forall_continuousAt fun x hx => ?_).intervalIntegrable exact Complex.continuousAt_ofReal_cpow_const _ _ (Or.inr <| ne_of_mem_of_not_mem hx h2) rw [eq_false h2, or_false] at h rcases lt_or_eq_of_le h with (h' | h') Β· -- Easy case #2: 0 < re r -- again use continuity exact (Complex.continuous_ofReal_cpow_const h').intervalIntegrable _ _ -- Now the hard case: re r = 0 and 0 is in the interval. refine (IntervalIntegrable.intervalIntegrable_norm_iff ?_).mp ?_ Β· refine (measurable_of_continuousOn_compl_singleton (0 : ℝ) ?_).aestronglyMeasurable exact continuousOn_of_forall_continuousAt fun x hx => Complex.continuousAt_ofReal_cpow_const x r (Or.inr hx) -- reduce to case of integral over `[0, c]` suffices βˆ€ c : ℝ, IntervalIntegrable (fun x : ℝ => β€–(x : β„‚) ^ rβ€–) ΞΌ 0 c from (this a).symm.trans (this b) intro c rcases le_or_lt 0 c with (hc | hc) Β· -- case `0 ≀ c`: integrand is identically 1 have : IntervalIntegrable (fun _ => 1 : ℝ β†’ ℝ) ΞΌ 0 c := intervalIntegrable_const rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hc] at this ⊒ refine IntegrableOn.congr_fun this (fun x hx => ?_) measurableSet_Ioc dsimp only rw [Complex.norm_cpow_eq_rpow_re_of_pos hx.1, ← h', rpow_zero] Β· -- case `c < 0`: integrand is identically constant, *except* at `x = 0` if `r β‰  0`. apply IntervalIntegrable.symm rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hc.le] rw [← Ioo_union_right hc, integrableOn_union, and_comm]; constructor Β· refine integrableOn_singleton_iff.mpr (Or.inr ?_) exact isFiniteMeasureOnCompacts_of_isLocallyFiniteMeasure.lt_top_of_isCompact isCompact_singleton Β· have : βˆ€ x : ℝ, x ∈ Ioo c 0 β†’ β€–Complex.exp (↑π * Complex.I * r)β€– = β€–(x : β„‚) ^ rβ€– := by intro x hx rw [Complex.ofReal_cpow_of_nonpos hx.2.le, norm_mul, ← Complex.ofReal_neg, Complex.norm_cpow_eq_rpow_re_of_pos (neg_pos.mpr hx.2), ← h', rpow_zero, one_mul] refine IntegrableOn.congr_fun ?_ this measurableSet_Ioo rw [integrableOn_const] refine Or.inr ((measure_mono Set.Ioo_subset_Icc_self).trans_lt ?_) exact isFiniteMeasureOnCompacts_of_isLocallyFiniteMeasure.lt_top_of_isCompact isCompact_Icc /-- See `intervalIntegrable_cpow` for a version applying to any locally finite measure, but with a stronger hypothesis on `r`. -/ theorem intervalIntegrable_cpow' {r : β„‚} (h : -1 < r.re) : IntervalIntegrable (fun x : ℝ => (x : β„‚) ^ r) volume a b := by suffices βˆ€ c : ℝ, IntervalIntegrable (fun x => (x : β„‚) ^ r) volume 0 c by exact IntervalIntegrable.trans (this a).symm (this b) have : βˆ€ c : ℝ, 0 ≀ c β†’ IntervalIntegrable (fun x => (x : β„‚) ^ r) volume 0 c := by intro c hc rw [← IntervalIntegrable.intervalIntegrable_norm_iff] Β· rw [intervalIntegrable_iff] apply IntegrableOn.congr_fun Β· rw [← intervalIntegrable_iff]; exact intervalIntegral.intervalIntegrable_rpow' h Β· intro x hx rw [uIoc_of_le hc] at hx dsimp only rw [Complex.norm_cpow_eq_rpow_re_of_pos hx.1] Β· exact measurableSet_uIoc Β· refine ContinuousOn.aestronglyMeasurable ?_ measurableSet_uIoc refine continuousOn_of_forall_continuousAt fun x hx => ?_ rw [uIoc_of_le hc] at hx refine (continuousAt_cpow_const (Or.inl ?_)).comp Complex.continuous_ofReal.continuousAt rw [Complex.ofReal_re] exact hx.1 intro c; rcases le_total 0 c with (hc | hc) Β· exact this c hc Β· rw [IntervalIntegrable.iff_comp_neg, neg_zero] have m := (this (-c) (by linarith)).const_mul (Complex.exp (Ο€ * Complex.I * r)) rw [intervalIntegrable_iff, uIoc_of_le (by linarith : 0 ≀ -c)] at m ⊒ refine m.congr_fun (fun x hx => ?_) measurableSet_Ioc dsimp only have : -x ≀ 0 := by linarith [hx.1] rw [Complex.ofReal_cpow_of_nonpos this, mul_comm] simp /-- The complex power function `x ↦ x^s` is integrable on `(0, t)` iff `-1 < s.re`. -/ theorem integrableOn_Ioo_cpow_iff {s : β„‚} {t : ℝ} (ht : 0 < t) : IntegrableOn (fun x : ℝ ↦ (x : β„‚) ^ s) (Ioo (0 : ℝ) t) ↔ -1 < s.re := by refine ⟨fun h ↦ ?_, fun h ↦ by simpa [intervalIntegrable_iff_integrableOn_Ioo_of_le ht.le] using intervalIntegrable_cpow' h (a := 0) (b := t)⟩ have B : IntegrableOn (fun a ↦ a ^ s.re) (Ioo 0 t) := by apply (integrableOn_congr_fun _ measurableSet_Ioo).1 h.norm intro a ha simp [Complex.norm_cpow_eq_rpow_re_of_pos ha.1] rwa [integrableOn_Ioo_rpow_iff ht] at B @[simp] theorem intervalIntegrable_id : IntervalIntegrable (fun x => x) ΞΌ a b := continuous_id.intervalIntegrable a b theorem intervalIntegrable_const : IntervalIntegrable (fun _ => c) ΞΌ a b := continuous_const.intervalIntegrable a b theorem intervalIntegrable_one_div (h : βˆ€ x : ℝ, x ∈ [[a, b]] β†’ f x β‰  0) (hf : ContinuousOn f [[a, b]]) : IntervalIntegrable (fun x => 1 / f x) ΞΌ a b := (continuousOn_const.div hf h).intervalIntegrable @[simp] theorem intervalIntegrable_inv (h : βˆ€ x : ℝ, x ∈ [[a, b]] β†’ f x β‰  0) (hf : ContinuousOn f [[a, b]]) : IntervalIntegrable (fun x => (f x)⁻¹) ΞΌ a b := by simpa only [one_div] using intervalIntegrable_one_div h hf @[simp] theorem intervalIntegrable_exp : IntervalIntegrable exp ΞΌ a b := continuous_exp.intervalIntegrable a b @[simp] theorem _root_.IntervalIntegrable.log (hf : ContinuousOn f [[a, b]]) (h : βˆ€ x : ℝ, x ∈ [[a, b]] β†’ f x β‰  0) : IntervalIntegrable (fun x => log (f x)) ΞΌ a b := (ContinuousOn.log hf h).intervalIntegrable /-- See `intervalIntegrable_log'` for a version without any hypothesis on the interval, but assuming the measure is volume. -/ @[simp] theorem intervalIntegrable_log (h : (0 : ℝ) βˆ‰ [[a, b]]) : IntervalIntegrable log ΞΌ a b := IntervalIntegrable.log continuousOn_id fun _ hx => ne_of_mem_of_not_mem hx h /-- The real logarithm is interval integrable (with respect to the volume measure) on every interval. See `intervalIntegrable_log` for a version applying to any locally finite measure, but with an additional hypothesis on the interval. -/ @[simp] theorem intervalIntegrable_log' : IntervalIntegrable log volume a b := by -- Log is even, so it suffices to consider the case 0 < a and b = 0 apply intervalIntegrable_of_even (log_neg_eq_log Β· |>.symm) intro x hx -- Split integral apply IntervalIntegrable.trans (b := 1) Β· -- Show integrability on [0…1] using non-negativity of the derivative rw [← neg_neg log] apply IntervalIntegrable.neg apply intervalIntegrable_deriv_of_nonneg (g := fun x ↦ -(x * log x - x)) Β· exact (continuous_mul_log.continuousOn.sub continuous_id.continuousOn).neg Β· intro s ⟨hs, _⟩ norm_num at * simpa using (hasDerivAt_id s).sub (hasDerivAt_mul_log hs.ne.symm) Β· intro s ⟨hs₁, hsβ‚‚βŸ© norm_num at * exact (log_nonpos_iff hs₁.le).mpr hsβ‚‚.le Β· -- Show integrability on [1…t] by continuity apply ContinuousOn.intervalIntegrable apply Real.continuousOn_log.mono apply Set.not_mem_uIcc_of_lt zero_lt_one at hx simpa @[simp] theorem intervalIntegrable_sin : IntervalIntegrable sin ΞΌ a b := continuous_sin.intervalIntegrable a b @[simp] theorem intervalIntegrable_cos : IntervalIntegrable cos ΞΌ a b := continuous_cos.intervalIntegrable a b theorem intervalIntegrable_one_div_one_add_sq : IntervalIntegrable (fun x : ℝ => 1 / (↑1 + x ^ 2)) ΞΌ a b := by refine (continuous_const.div ?_ fun x => ?_).intervalIntegrable a b Β· fun_prop Β· nlinarith @[simp] theorem intervalIntegrable_inv_one_add_sq : IntervalIntegrable (fun x : ℝ => (↑1 + x ^ 2)⁻¹) ΞΌ a b := by field_simp; exact mod_cast intervalIntegrable_one_div_one_add_sq /-! ### Integrals of the form `c * ∫ x in a..b, f (c * x + d)` -/ section @[simp] theorem mul_integral_comp_mul_right : (c * ∫ x in a..b, f (x * c)) = ∫ x in a * c..b * c, f x := smul_integral_comp_mul_right f c @[simp] theorem mul_integral_comp_mul_left : (c * ∫ x in a..b, f (c * x)) = ∫ x in c * a..c * b, f x := smul_integral_comp_mul_left f c @[simp] theorem inv_mul_integral_comp_div : (c⁻¹ * ∫ x in a..b, f (x / c)) = ∫ x in a / c..b / c, f x := inv_smul_integral_comp_div f c @[simp] theorem mul_integral_comp_mul_add : (c * ∫ x in a..b, f (c * x + d)) = ∫ x in c * a + d..c * b + d, f x := smul_integral_comp_mul_add f c d @[simp] theorem mul_integral_comp_add_mul : (c * ∫ x in a..b, f (d + c * x)) = ∫ x in d + c * a..d + c * b, f x := smul_integral_comp_add_mul f c d @[simp] theorem inv_mul_integral_comp_div_add : (c⁻¹ * ∫ x in a..b, f (x / c + d)) = ∫ x in a / c + d..b / c + d, f x := inv_smul_integral_comp_div_add f c d @[simp] theorem inv_mul_integral_comp_add_div : (c⁻¹ * ∫ x in a..b, f (d + x / c)) = ∫ x in d + a / c..d + b / c, f x := inv_smul_integral_comp_add_div f c d @[simp] theorem mul_integral_comp_mul_sub : (c * ∫ x in a..b, f (c * x - d)) = ∫ x in c * a - d..c * b - d, f x := smul_integral_comp_mul_sub f c d @[simp] theorem mul_integral_comp_sub_mul : (c * ∫ x in a..b, f (d - c * x)) = ∫ x in d - c * b..d - c * a, f x := smul_integral_comp_sub_mul f c d @[simp] theorem inv_mul_integral_comp_div_sub : (c⁻¹ * ∫ x in a..b, f (x / c - d)) = ∫ x in a / c - d..b / c - d, f x := inv_smul_integral_comp_div_sub f c d @[simp] theorem inv_mul_integral_comp_sub_div : (c⁻¹ * ∫ x in a..b, f (d - x / c)) = ∫ x in d - b / c..d - a / c, f x := inv_smul_integral_comp_sub_div f c d end end intervalIntegral open intervalIntegral /-! ### Integrals of simple functions -/ theorem integral_cpow {r : β„‚} (h : -1 < r.re ∨ r β‰  -1 ∧ (0 : ℝ) βˆ‰ [[a, b]]) : (∫ x : ℝ in a..b, (x : β„‚) ^ r) = ((b : β„‚) ^ (r + 1) - (a : β„‚) ^ (r + 1)) / (r + 1) := by rw [sub_div] have hr : r + 1 β‰  0 := by rcases h with h | h Β· apply_fun Complex.re rw [Complex.add_re, Complex.one_re, Complex.zero_re, Ne, add_eq_zero_iff_eq_neg] exact h.ne' Β· rw [Ne, ← add_eq_zero_iff_eq_neg] at h; exact h.1 by_cases hab : (0 : ℝ) βˆ‰ [[a, b]] Β· apply integral_eq_sub_of_hasDerivAt (fun x hx => ?_) (intervalIntegrable_cpow (r := r) <| Or.inr hab) refine hasDerivAt_ofReal_cpow_const' (ne_of_mem_of_not_mem hx hab) ?_ contrapose! hr; rwa [add_eq_zero_iff_eq_neg] replace h : -1 < r.re := by tauto suffices βˆ€ c : ℝ, (∫ x : ℝ in (0)..c, (x : β„‚) ^ r) = (c : β„‚) ^ (r + 1) / (r + 1) - (0 : β„‚) ^ (r + 1) / (r + 1) by rw [← integral_add_adjacent_intervals (@intervalIntegrable_cpow' a 0 r h) (@intervalIntegrable_cpow' 0 b r h), integral_symm, this a, this b, Complex.zero_cpow hr] ring intro c apply integral_eq_sub_of_hasDeriv_right Β· refine ((Complex.continuous_ofReal_cpow_const ?_).div_const _).continuousOn rwa [Complex.add_re, Complex.one_re, ← neg_lt_iff_pos_add] Β· refine fun x hx => (hasDerivAt_ofReal_cpow_const' ?_ ?_).hasDerivWithinAt Β· rcases le_total c 0 with (hc | hc) Β· rw [max_eq_left hc] at hx; exact hx.2.ne Β· rw [min_eq_left hc] at hx; exact hx.1.ne' Β· contrapose! hr; rw [hr]; ring Β· exact intervalIntegrable_cpow' h theorem integral_rpow {r : ℝ} (h : -1 < r ∨ r β‰  -1 ∧ (0 : ℝ) βˆ‰ [[a, b]]) : ∫ x in a..b, x ^ r = (b ^ (r + 1) - a ^ (r + 1)) / (r + 1) := by have h' : -1 < (r : β„‚).re ∨ (r : β„‚) β‰  -1 ∧ (0 : ℝ) βˆ‰ [[a, b]] := by cases h Β· left; rwa [Complex.ofReal_re] Β· right; rwa [← Complex.ofReal_one, ← Complex.ofReal_neg, Ne, Complex.ofReal_inj] have : (∫ x in a..b, (x : β„‚) ^ (r : β„‚)) = ((b : β„‚) ^ (r + 1 : β„‚) - (a : β„‚) ^ (r + 1 : β„‚)) / (r + 1) := integral_cpow h' apply_fun Complex.re at this; convert this Β· simp_rw [intervalIntegral_eq_integral_uIoc, Complex.real_smul, Complex.re_ofReal_mul, rpow_def, ← RCLike.re_eq_complex_re, smul_eq_mul] rw [integral_re] refine intervalIntegrable_iff.mp ?_ rcases h' with h' | h' Β· exact intervalIntegrable_cpow' h' Β· exact intervalIntegrable_cpow (Or.inr h'.2) Β· rw [(by push_cast; rfl : (r : β„‚) + 1 = ((r + 1 : ℝ) : β„‚))] simp_rw [div_eq_inv_mul, ← Complex.ofReal_inv, Complex.re_ofReal_mul, Complex.sub_re, rpow_def] theorem integral_zpow {n : β„€} (h : 0 ≀ n ∨ n β‰  -1 ∧ (0 : ℝ) βˆ‰ [[a, b]]) : ∫ x in a..b, x ^ n = (b ^ (n + 1) - a ^ (n + 1)) / (n + 1) := by replace h : -1 < (n : ℝ) ∨ (n : ℝ) β‰  -1 ∧ (0 : ℝ) βˆ‰ [[a, b]] := mod_cast h exact mod_cast integral_rpow h @[simp] theorem integral_pow : ∫ x in a..b, x ^ n = (b ^ (n + 1) - a ^ (n + 1)) / (n + 1) := by simpa only [← Int.natCast_succ, zpow_natCast] using integral_zpow (Or.inl n.cast_nonneg) /-- Integral of `|x - a| ^ n` over `Ξ™ a b`. This integral appears in the proof of the Picard-LindelΓΆf/Cauchy-Lipschitz theorem. -/ theorem integral_pow_abs_sub_uIoc : ∫ x in Ξ™ a b, |x - a| ^ n = |b - a| ^ (n + 1) / (n + 1) := by rcases le_or_lt a b with hab | hab Β· calc ∫ x in Ξ™ a b, |x - a| ^ n = ∫ x in a..b, |x - a| ^ n := by rw [uIoc_of_le hab, ← integral_of_le hab] _ = ∫ x in (0)..(b - a), x ^ n := by simp only [integral_comp_sub_right fun x => |x| ^ n, sub_self] refine integral_congr fun x hx => congr_argβ‚‚ Pow.pow (abs_of_nonneg <| ?_) rfl rw [uIcc_of_le (sub_nonneg.2 hab)] at hx exact hx.1 _ = |b - a| ^ (n + 1) / (n + 1) := by simp [abs_of_nonneg (sub_nonneg.2 hab)] Β· calc ∫ x in Ξ™ a b, |x - a| ^ n = ∫ x in b..a, |x - a| ^ n := by rw [uIoc_of_ge hab.le, ← integral_of_le hab.le] _ = ∫ x in b - a..0, (-x) ^ n := by simp only [integral_comp_sub_right fun x => |x| ^ n, sub_self] refine integral_congr fun x hx => congr_argβ‚‚ Pow.pow (abs_of_nonpos <| ?_) rfl rw [uIcc_of_le (sub_nonpos.2 hab.le)] at hx exact hx.2 _ = |b - a| ^ (n + 1) / (n + 1) := by simp [integral_comp_neg fun x => x ^ n, abs_of_neg (sub_neg.2 hab)] @[simp] theorem integral_id : ∫ x in a..b, x = (b ^ 2 - a ^ 2) / 2 := by have := @integral_pow a b 1 norm_num at this exact this theorem integral_one : (∫ _ in a..b, (1 : ℝ)) = b - a := by simp only [mul_one, smul_eq_mul, integral_const] theorem integral_const_on_unit_interval : ∫ _ in a..a + 1, b = b := by simp @[simp] theorem integral_inv (h : (0 : ℝ) βˆ‰ [[a, b]]) : ∫ x in a..b, x⁻¹ = log (b / a) := by have h' := fun x (hx : x ∈ [[a, b]]) => ne_of_mem_of_not_mem hx h rw [integral_deriv_eq_sub' _ deriv_log' (fun x hx => differentiableAt_log (h' x hx)) (continuousOn_invβ‚€.mono <| subset_compl_singleton_iff.mpr h), log_div (h' b right_mem_uIcc) (h' a left_mem_uIcc)] @[simp] theorem integral_inv_of_pos (ha : 0 < a) (hb : 0 < b) : ∫ x in a..b, x⁻¹ = log (b / a) := integral_inv <| not_mem_uIcc_of_lt ha hb @[simp] theorem integral_inv_of_neg (ha : a < 0) (hb : b < 0) : ∫ x in a..b, x⁻¹ = log (b / a) := integral_inv <| not_mem_uIcc_of_gt ha hb theorem integral_one_div (h : (0 : ℝ) βˆ‰ [[a, b]]) : ∫ x : ℝ in a..b, 1 / x = log (b / a) := by simp only [one_div, integral_inv h] theorem integral_one_div_of_pos (ha : 0 < a) (hb : 0 < b) : ∫ x : ℝ in a..b, 1 / x = log (b / a) := by simp only [one_div, integral_inv_of_pos ha hb] theorem integral_one_div_of_neg (ha : a < 0) (hb : b < 0) : ∫ x : ℝ in a..b, 1 / x = log (b / a) := by simp only [one_div, integral_inv_of_neg ha hb] @[simp] theorem integral_exp : ∫ x in a..b, exp x = exp b - exp a := by rw [integral_deriv_eq_sub'] Β· simp Β· exact fun _ _ => differentiableAt_exp Β· exact continuousOn_exp theorem integral_exp_mul_complex {c : β„‚} (hc : c β‰  0) : (∫ x in a..b, Complex.exp (c * x)) = (Complex.exp (c * b) - Complex.exp (c * a)) / c := by have D : βˆ€ x : ℝ, HasDerivAt (fun y : ℝ => Complex.exp (c * y) / c) (Complex.exp (c * x)) x := by intro x conv => congr rw [← mul_div_cancel_rightβ‚€ (Complex.exp (c * x)) hc] apply ((Complex.hasDerivAt_exp _).comp x _).div_const c simpa only [mul_one] using ((hasDerivAt_id (x : β„‚)).const_mul _).comp_ofReal rw [integral_deriv_eq_sub' _ (funext fun x => (D x).deriv) fun x _ => (D x).differentiableAt] Β· ring Β· fun_prop /-- Helper lemma for `integral_log`: case where `a = 0` and `b` is positive. -/ lemma integral_log_from_zero_of_pos (ht : 0 < b) : ∫ s in (0)..b, log s = b * log b - b := by -- Compute the integral by giving a primitive and considering it limit as x approaches 0 from the -- right. The following lines were suggested by Gareth Ma on Zulip. rw [integral_eq_sub_of_hasDerivAt_of_tendsto (f := fun x ↦ x * log x - x) (fa := 0) (fb := b * log b - b) (hint := intervalIntegrable_log')] Β· abel Β· exact ht Β· intro s ⟨hs, _ ⟩ simpa using (hasDerivAt_mul_log hs.ne.symm).sub (hasDerivAt_id s) Β· simpa [mul_comm] using ((tendsto_log_mul_rpow_nhdsGT_zero zero_lt_one).sub (tendsto_nhdsWithin_of_tendsto_nhds Filter.tendsto_id)) Β· exact tendsto_nhdsWithin_of_tendsto_nhds (ContinuousAt.tendsto (by fun_prop)) /-- Helper lemma for `integral_log`: case where `a = 0`. -/ lemma integral_log_from_zero {b : ℝ} : ∫ s in (0)..b, log s = b * log b - b := by rcases lt_trichotomy b 0 with h | h | h Β· -- If t is negative, use that log is an even function to reduce to the positive case. conv => arg 1; arg 1; intro t; rw [← log_neg_eq_log] rw [intervalIntegral.integral_comp_neg, intervalIntegral.integral_symm, neg_zero, integral_log_from_zero_of_pos (Left.neg_pos_iff.mpr h), log_neg_eq_log] ring Β· simp [h] Β· exact integral_log_from_zero_of_pos h @[simp] theorem integral_log : ∫ s in a..b, log s = b * log b - a * log a - b + a := by rw [← intervalIntegral.integral_add_adjacent_intervals (b := 0)] Β· rw [intervalIntegral.integral_symm, integral_log_from_zero, integral_log_from_zero] ring all_goals exact intervalIntegrable_log' @[deprecated (since := "2025-01-12")] alias integral_log_of_pos := integral_log @[deprecated (since := "2025-01-12")] alias integral_log_of_neg := integral_log @[simp] theorem integral_sin : ∫ x in a..b, sin x = cos a - cos b := by rw [integral_deriv_eq_sub' fun x => -cos x] Β· ring Β· norm_num Β· simp only [differentiableAt_neg_iff, differentiableAt_cos, implies_true] Β· exact continuousOn_sin @[simp] theorem integral_cos : ∫ x in a..b, cos x = sin b - sin a := by rw [integral_deriv_eq_sub'] Β· norm_num Β· simp only [differentiableAt_sin, implies_true] Β· exact continuousOn_cos theorem integral_cos_mul_complex {z : β„‚} (hz : z β‰  0) (a b : ℝ) : (∫ x in a..b, Complex.cos (z * x)) = Complex.sin (z * b) / z - Complex.sin (z * a) / z := by apply integral_eq_sub_of_hasDerivAt swap Β· apply Continuous.intervalIntegrable exact Complex.continuous_cos.comp (continuous_const.mul Complex.continuous_ofReal) intro x _ have a := Complex.hasDerivAt_sin (↑x * z) have b : HasDerivAt (fun y => y * z : β„‚ β†’ β„‚) z ↑x := hasDerivAt_mul_const _ have c : HasDerivAt (Complex.sin ∘ fun y : β„‚ => (y * z)) _ ↑x := HasDerivAt.comp (π•œ := β„‚) x a b have d := HasDerivAt.comp_ofReal (c.div_const z) simp only [mul_comm] at d
convert d using 1 conv_rhs => arg 1; rw [mul_comm] rw [mul_div_cancel_rightβ‚€ _ hz] theorem integral_cos_sq_sub_sin_sq : ∫ x in a..b, cos x ^ 2 - sin x ^ 2 = sin b * cos b - sin a * cos a := by simpa only [sq, sub_eq_add_neg, neg_mul_eq_mul_neg] using integral_deriv_mul_eq_sub (fun x _ => hasDerivAt_sin x) (fun x _ => hasDerivAt_cos x) continuousOn_cos.intervalIntegrable continuousOn_sin.neg.intervalIntegrable theorem integral_one_div_one_add_sq : (∫ x : ℝ in a..b, ↑1 / (↑1 + x ^ 2)) = arctan b - arctan a := by refine integral_deriv_eq_sub' _ Real.deriv_arctan (fun _ _ => differentiableAt_arctan _) (continuous_const.div ?_ fun x => ?_).continuousOn Β· fun_prop
Mathlib/Analysis/SpecialFunctions/Integrals.lean
547
561
/- 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, Kim Morrison -/ import Mathlib.SetTheory.Cardinal.Cofinality import Mathlib.LinearAlgebra.FreeModule.Finite.Basic import Mathlib.LinearAlgebra.Dimension.StrongRankCondition import Mathlib.LinearAlgebra.Dimension.Constructions /-! # 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 Basis Cardinal Function Module Set Submodule /-- If every finite set of linearly independent vectors has cardinality at most `n`, then the same is true for arbitrary sets of linearly independent vectors. -/ theorem linearIndependent_bounded_of_finset_linearIndependent_bounded {n : β„•} (H : βˆ€ s : Finset M, (LinearIndependent R fun i : s => (i : M)) β†’ s.card ≀ n) : βˆ€ s : Set M, LinearIndependent R ((↑) : s β†’ M) β†’ #s ≀ n := by intro s li apply Cardinal.card_le_of intro t rw [← Finset.card_map (Embedding.subtype s)] apply H apply linearIndependent_finset_map_embedding_subtype _ li 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 section RankZero /-- See `rank_zero_iff` for a stronger version with `NoZeroSMulDivisor R M`. -/ lemma rank_eq_zero_iff : Module.rank R M = 0 ↔ βˆ€ x : M, βˆƒ a : R, a β‰  0 ∧ a β€’ x = 0 := by nontriviality R constructor Β· contrapose! rintro ⟨x, hx⟩ rw [← Cardinal.one_le_iff_ne_zero] have : LinearIndependent R (fun _ : Unit ↦ x) := linearIndependent_iff.mpr (fun l hl ↦ Finsupp.unique_ext <| not_not.mp fun H ↦ hx _ H ((Finsupp.linearCombination_unique _ _ _).symm.trans hl)) simpa using this.cardinal_lift_le_rank Β· intro h rw [← le_zero_iff, Module.rank_def] apply ciSup_le' intro ⟨s, hs⟩ rw [nonpos_iff_eq_zero, Cardinal.mk_eq_zero_iff, ← not_nonempty_iff] rintro ⟨i : s⟩ obtain ⟨a, ha, ha'⟩ := h i apply ha simpa using DFunLike.congr_fun (linearIndependent_iff.mp hs (Finsupp.single i a) (by simpa)) i theorem rank_pos_of_free [Module.Free R M] [Nontrivial M] : 0 < Module.rank R M := have := Module.nontrivial R M (pos_of_ne_zero <| Cardinal.mk_ne_zero _).trans_le (Free.chooseBasis R M).linearIndependent.cardinal_le_rank variable [Nontrivial R] section variable [NoZeroSMulDivisors R M] theorem rank_zero_iff_forall_zero : Module.rank R M = 0 ↔ βˆ€ x : M, x = 0 := by simp_rw [rank_eq_zero_iff, smul_eq_zero, and_or_left, not_and_self_iff, false_or, exists_and_right, and_iff_right (exists_ne (0 : R))] /-- See `rank_subsingleton` for the reason that `Nontrivial R` is needed. Also see `rank_eq_zero_iff` for the version without `NoZeroSMulDivisor R M`. -/ theorem rank_zero_iff : Module.rank R M = 0 ↔ Subsingleton M := rank_zero_iff_forall_zero.trans (subsingleton_iff_forall_eq 0).symm theorem rank_pos_iff_exists_ne_zero : 0 < Module.rank R M ↔ βˆƒ x : M, x β‰  0 := by rw [← not_iff_not] simpa using rank_zero_iff_forall_zero theorem rank_pos_iff_nontrivial : 0 < Module.rank R M ↔ Nontrivial M := rank_pos_iff_exists_ne_zero.trans (nontrivial_iff_exists_ne 0).symm theorem rank_pos [Nontrivial M] : 0 < Module.rank R M := rank_pos_iff_nontrivial.mpr β€Ή_β€Ί end variable (R M) /-- See `rank_subsingleton` that assumes `Subsingleton R` instead. -/ @[nontriviality] theorem rank_subsingleton' [Subsingleton M] : Module.rank R M = 0 := rank_eq_zero_iff.mpr fun _ ↦ ⟨1, one_ne_zero, Subsingleton.elim _ _⟩ @[simp] theorem rank_punit : Module.rank R PUnit = 0 := rank_subsingleton' _ _ @[simp] theorem rank_bot : Module.rank R (βŠ₯ : Submodule R M) = 0 := rank_subsingleton' _ _ variable {R M} theorem exists_mem_ne_zero_of_rank_pos {s : Submodule R M} (h : 0 < Module.rank R s) : βˆƒ b : M, b ∈ s ∧ b β‰  0 := exists_mem_ne_zero_of_ne_bot fun eq => by rw [eq, rank_bot] at h; exact lt_irrefl _ h end RankZero section Finite theorem Module.finite_of_rank_eq_nat [Module.Free R M] {n : β„•} (h : Module.rank R M = n) : Module.Finite R M := by nontriviality R obtain ⟨⟨ι, b⟩⟩ := Module.Free.exists_basis (R := R) (M := M) have := mk_lt_aleph0_iff.mp <| b.linearIndependent.cardinal_le_rank |>.trans_eq h |>.trans_lt <| nat_lt_aleph0 n exact Module.Finite.of_basis b theorem Module.finite_of_rank_eq_zero [NoZeroSMulDivisors R M] (h : Module.rank R M = 0) : Module.Finite R M := by nontriviality R rw [rank_zero_iff] at h infer_instance theorem Module.finite_of_rank_eq_one [Module.Free R M] (h : Module.rank R M = 1) : Module.Finite R M := Module.finite_of_rank_eq_nat <| h.trans Nat.cast_one.symm section variable [StrongRankCondition R] /-- If a module has a finite dimension, all bases are indexed by a finite type. -/ theorem Basis.nonempty_fintype_index_of_rank_lt_aleph0 {ΞΉ : Type*} (b : Basis ΞΉ R M) (h : Module.rank R M < β„΅β‚€) : Nonempty (Fintype ΞΉ) := by rwa [← Cardinal.lift_lt, ← b.mk_eq_rank, Cardinal.lift_aleph0, Cardinal.lift_lt_aleph0, Cardinal.lt_aleph0_iff_fintype] at h /-- If a module has a finite dimension, all bases are indexed by a finite type. -/ noncomputable def Basis.fintypeIndexOfRankLtAleph0 {ΞΉ : Type*} (b : Basis ΞΉ R M) (h : Module.rank R M < β„΅β‚€) : Fintype ΞΉ := Classical.choice (b.nonempty_fintype_index_of_rank_lt_aleph0 h) /-- If a module has a finite dimension, all bases are indexed by a finite set. -/ theorem Basis.finite_index_of_rank_lt_aleph0 {ΞΉ : Type*} {s : Set ΞΉ} (b : Basis s R M) (h : Module.rank R M < β„΅β‚€) : s.Finite := finite_def.2 (b.nonempty_fintype_index_of_rank_lt_aleph0 h) end namespace LinearIndependent variable [StrongRankCondition R] theorem cardinalMk_le_finrank [Module.Finite R M] {ΞΉ : Type w} {b : ΞΉ β†’ M} (h : LinearIndependent R b) : #ΞΉ ≀ finrank R M := by rw [← lift_le.{max v w}] simpa only [← finrank_eq_rank, lift_natCast, lift_le_nat_iff] using h.cardinal_lift_le_rank @[deprecated (since := "2024-11-10")] alias cardinal_mk_le_finrank := cardinalMk_le_finrank theorem fintype_card_le_finrank [Module.Finite R M] {ΞΉ : Type*} [Fintype ΞΉ] {b : ΞΉ β†’ M} (h : LinearIndependent R b) : Fintype.card ΞΉ ≀ finrank R M := by simpa using h.cardinalMk_le_finrank theorem finset_card_le_finrank [Module.Finite R M] {b : Finset M} (h : LinearIndependent R (fun x => x : b β†’ M)) : b.card ≀ finrank R M := by rw [← Fintype.card_coe] exact h.fintype_card_le_finrank theorem lt_aleph0_of_finite {ΞΉ : Type w} [Module.Finite R M] {v : ΞΉ β†’ M} (h : LinearIndependent R v) : #ΞΉ < β„΅β‚€ := by apply Cardinal.lift_lt.1 apply lt_of_le_of_lt Β· apply h.cardinal_lift_le_rank Β· rw [← finrank_eq_rank, Cardinal.lift_aleph0, Cardinal.lift_natCast] apply Cardinal.nat_lt_aleph0 theorem finite [Module.Finite R M] {ΞΉ : Type*} {f : ΞΉ β†’ M} (h : LinearIndependent R f) : Finite ΞΉ := Cardinal.lt_aleph0_iff_finite.1 <| h.lt_aleph0_of_finite theorem setFinite [Module.Finite R M] {b : Set M} (h : LinearIndependent R fun x : b => (x : M)) : b.Finite := Cardinal.lt_aleph0_iff_set_finite.mp h.lt_aleph0_of_finite end LinearIndependent lemma exists_set_linearIndependent_of_lt_rank {n : Cardinal} (hn : n < Module.rank R M) : βˆƒ s : Set M, #s = n ∧ LinearIndepOn R id s := by obtain ⟨⟨s, hs⟩, hs'⟩ := exists_lt_of_lt_ciSup' (hn.trans_eq (Module.rank_def R M)) obtain ⟨t, ht, ht'⟩ := le_mk_iff_exists_subset.mp hs'.le exact ⟨t, ht', hs.mono ht⟩ lemma exists_finset_linearIndependent_of_le_rank {n : β„•} (hn : n ≀ Module.rank R M) : βˆƒ s : Finset M, s.card = n ∧ LinearIndepOn R id (s : Set M) := by have := nonempty_linearIndependent_set rcases hn.eq_or_lt with h | h Β· obtain ⟨⟨s, hs⟩, hs'⟩ := Cardinal.exists_eq_natCast_of_iSup_eq _ (Cardinal.bddAbove_range _) _ (h.trans (Module.rank_def R M)).symm have : Finite s := lt_aleph0_iff_finite.mp (hs' β–Έ nat_lt_aleph0 n) cases nonempty_fintype s refine ⟨s.toFinset, by simpa using hs', by simpa⟩ Β· obtain ⟨s, hs, hs'⟩ := exists_set_linearIndependent_of_lt_rank h have : Finite s := lt_aleph0_iff_finite.mp (hs β–Έ nat_lt_aleph0 n) cases nonempty_fintype s exact ⟨s.toFinset, by simpa using hs, by simpa⟩ lemma exists_linearIndependent_of_le_rank {n : β„•} (hn : n ≀ Module.rank R M) : βˆƒ f : Fin n β†’ M, LinearIndependent R f := have ⟨_, hs, hs'⟩ := exists_finset_linearIndependent_of_le_rank hn ⟨_, (linearIndependent_equiv (Finset.equivFinOfCardEq hs).symm).mpr hs'⟩ lemma natCast_le_rank_iff [Nontrivial R] {n : β„•} : n ≀ Module.rank R M ↔ βˆƒ f : Fin n β†’ M, LinearIndependent R f := ⟨exists_linearIndependent_of_le_rank, fun H ↦ by simpa using H.choose_spec.cardinal_lift_le_rank⟩ lemma natCast_le_rank_iff_finset [Nontrivial R] {n : β„•} : n ≀ Module.rank R M ↔ βˆƒ s : Finset M, s.card = n ∧ LinearIndependent R ((↑) : s β†’ M) := ⟨exists_finset_linearIndependent_of_le_rank, fun ⟨s, h₁, hβ‚‚βŸ© ↦ by simpa [h₁] using hβ‚‚.cardinal_le_rank⟩ lemma exists_finset_linearIndependent_of_le_finrank {n : β„•} (hn : n ≀ finrank R M) : βˆƒ s : Finset M, s.card = n ∧ LinearIndependent R ((↑) : s β†’ M) := by by_cases h : finrank R M = 0 Β· rw [le_zero_iff.mp (hn.trans_eq h)] exact βŸ¨βˆ…, rfl, by convert linearIndependent_empty R M using 2 <;> aesop⟩ exact exists_finset_linearIndependent_of_le_rank ((Nat.cast_le.mpr hn).trans_eq (cast_toNat_of_lt_aleph0 (toNat_ne_zero.mp h).2)) lemma exists_linearIndependent_of_le_finrank {n : β„•} (hn : n ≀ finrank R M) : βˆƒ f : Fin n β†’ M, LinearIndependent R f := have ⟨_, hs, hs'⟩ := exists_finset_linearIndependent_of_le_finrank hn ⟨_, (linearIndependent_equiv (Finset.equivFinOfCardEq hs).symm).mpr hs'⟩ variable [Module.Finite R M] [StrongRankCondition R] in theorem Module.Finite.not_linearIndependent_of_infinite {ΞΉ : Type*} [Infinite ΞΉ] (v : ΞΉ β†’ M) : Β¬LinearIndependent R v := mt LinearIndependent.finite <| @not_finite _ _ section variable [NoZeroSMulDivisors R M] theorem iSupIndep.subtype_ne_bot_le_rank [Nontrivial R] {V : ΞΉ β†’ Submodule R M} (hV : iSupIndep V) : Cardinal.lift.{v} #{ i : ΞΉ // V i β‰  βŠ₯ } ≀ Cardinal.lift.{w} (Module.rank R M) := by set I := { i : ΞΉ // V i β‰  βŠ₯ } have hI : βˆ€ i : I, βˆƒ v ∈ V i, v β‰  (0 : M) := by intro i rw [← Submodule.ne_bot_iff] exact i.prop choose v hvV hv using hI have : LinearIndependent R v := (hV.comp Subtype.coe_injective).linearIndependent _ hvV hv exact this.cardinal_lift_le_rank @[deprecated (since := "2024-11-24")] alias CompleteLattice.Independent.subtype_ne_bot_le_rank := iSupIndep.subtype_ne_bot_le_rank variable [Module.Finite R M] [StrongRankCondition R] theorem iSupIndep.subtype_ne_bot_le_finrank_aux {p : ΞΉ β†’ Submodule R M} (hp : iSupIndep p) : #{ i // p i β‰  βŠ₯ } ≀ (finrank R M : Cardinal.{w}) := by suffices Cardinal.lift.{v} #{ i // p i β‰  βŠ₯ } ≀ Cardinal.lift.{v} (finrank R M : Cardinal.{w}) by rwa [Cardinal.lift_le] at this calc Cardinal.lift.{v} #{ i // p i β‰  βŠ₯ } ≀ Cardinal.lift.{w} (Module.rank R M) := hp.subtype_ne_bot_le_rank _ = Cardinal.lift.{w} (finrank R M : Cardinal.{v}) := by rw [finrank_eq_rank] _ = Cardinal.lift.{v} (finrank R M : Cardinal.{w}) := by simp /-- If `p` is an independent family of submodules of a `R`-finite module `M`, then the number of nontrivial subspaces in the family `p` is finite. -/ noncomputable def iSupIndep.fintypeNeBotOfFiniteDimensional {p : ΞΉ β†’ Submodule R M} (hp : iSupIndep p) : Fintype { i : ΞΉ // p i β‰  βŠ₯ } := by suffices #{ i // p i β‰  βŠ₯ } < (β„΅β‚€ : Cardinal.{w}) by rw [Cardinal.lt_aleph0_iff_fintype] at this exact this.some refine lt_of_le_of_lt hp.subtype_ne_bot_le_finrank_aux ?_ simp [Cardinal.nat_lt_aleph0] /-- If `p` is an independent family of submodules of a `R`-finite module `M`, then the number of nontrivial subspaces in the family `p` is bounded above by the dimension of `M`. Note that the `Fintype` hypothesis required here can be provided by `iSupIndep.fintypeNeBotOfFiniteDimensional`. -/ theorem iSupIndep.subtype_ne_bot_le_finrank {p : ΞΉ β†’ Submodule R M} (hp : iSupIndep p) [Fintype { i // p i β‰  βŠ₯ }] : Fintype.card { i // p i β‰  βŠ₯ } ≀ finrank R M := by simpa using hp.subtype_ne_bot_le_finrank_aux end variable [Module.Finite R M] [StrongRankCondition R] section open Finset /-- If a finset has cardinality larger than the rank of a module, then there is a nontrivial linear relation amongst its elements. -/ theorem Module.exists_nontrivial_relation_of_finrank_lt_card {t : Finset M} (h : finrank R M < t.card) : βˆƒ f : M β†’ R, βˆ‘ e ∈ t, f e β€’ e = 0 ∧ βˆƒ x ∈ t, f x β‰  0 := by obtain ⟨g, sum, z, nonzero⟩ := Fintype.not_linearIndependent_iff.mp (mt LinearIndependent.finset_card_le_finrank h.not_le) refine ⟨Subtype.val.extend g 0, ?_, z, z.2, by rwa [Subtype.val_injective.extend_apply]⟩ rw [← Finset.sum_finset_coe]; convert sum; apply Subtype.val_injective.extend_apply /-- If a finset has cardinality larger than `finrank + 1`, then there is a nontrivial linear relation amongst its elements, such that the coefficients of the relation sum to zero. -/ theorem Module.exists_nontrivial_relation_sum_zero_of_finrank_succ_lt_card {t : Finset M} (h : finrank R M + 1 < t.card) : βˆƒ f : M β†’ R, βˆ‘ e ∈ t, f e β€’ e = 0 ∧ βˆ‘ e ∈ t, f e = 0 ∧ βˆƒ x ∈ t, f x β‰  0 := by -- Pick an element xβ‚€ ∈ t, obtain ⟨xβ‚€, xβ‚€_mem⟩ := card_pos.1 ((Nat.succ_pos _).trans h) -- and apply the previous lemma to the {xα΅’ - xβ‚€} let shift : M β†ͺ M := ⟨(Β· - xβ‚€), sub_left_injective⟩ classical let t' := (t.erase xβ‚€).map shift have h' : finrank R M < t'.card := by rw [card_map, card_erase_of_mem xβ‚€_mem] exact Nat.lt_pred_iff.mpr h -- to obtain a function `g`. obtain ⟨g, gsum, x₁, x₁_mem, nz⟩ := exists_nontrivial_relation_of_finrank_lt_card h' -- Then obtain `f` by translating back by `xβ‚€`, -- and setting the value of `f` at `xβ‚€` to ensure `βˆ‘ e ∈ t, f e = 0`. let f : M β†’ R := fun z ↦ if z = xβ‚€ then -βˆ‘ z ∈ t.erase xβ‚€, g (z - xβ‚€) else g (z - xβ‚€) refine ⟨f, ?_, ?_, ?_⟩ -- After this, it's a matter of verifying the properties, -- based on the corresponding properties for `g`. Β· rw [sum_map, Embedding.coeFn_mk] at gsum simp_rw [f, ← t.sum_erase_add _ xβ‚€_mem, if_pos, neg_smul, sum_smul, ← sub_eq_add_neg, ← sum_sub_distrib, ← gsum, smul_sub] refine sum_congr rfl fun x x_mem ↦ ?_ rw [if_neg (mem_erase.mp x_mem).1] Β· simp_rw [f, ← t.sum_erase_add _ xβ‚€_mem, if_pos, add_neg_eq_zero] exact sum_congr rfl fun x x_mem ↦ if_neg (mem_erase.mp x_mem).1 Β· obtain ⟨x₁, x₁_mem', rfl⟩ := Finset.mem_map.mp x₁_mem have := mem_erase.mp x₁_mem' exact ⟨x₁, by simpa only [f, Embedding.coeFn_mk, sub_add_cancel, this.2, true_and, if_neg this.1]⟩ end end Finite section FinrankZero section variable [Nontrivial R] /-- A (finite dimensional) space that is a subsingleton has zero `finrank`. -/ @[nontriviality] theorem Module.finrank_zero_of_subsingleton [Subsingleton M] : finrank R M = 0 := by rw [finrank, rank_subsingleton', map_zero] lemma LinearIndependent.finrank_eq_zero_of_infinite {ΞΉ} [Infinite ΞΉ] {v : ΞΉ β†’ M} (hv : LinearIndependent R v) : finrank R M = 0 := toNat_eq_zero.mpr <| .inr hv.aleph0_le_rank section variable [NoZeroSMulDivisors R M] /-- A finite dimensional space is nontrivial if it has positive `finrank`. -/ theorem Module.nontrivial_of_finrank_pos (h : 0 < finrank R M) : Nontrivial M := rank_pos_iff_nontrivial.mp (lt_rank_of_lt_finrank h) /-- A finite dimensional space is nontrivial if it has `finrank` equal to the successor of a natural number. -/ theorem Module.nontrivial_of_finrank_eq_succ {n : β„•} (hn : finrank R M = n.succ) : Nontrivial M := nontrivial_of_finrank_pos (R := R) (by rw [hn]; exact n.succ_pos) end variable (R M) @[simp] theorem finrank_bot : finrank R (βŠ₯ : Submodule R M) = 0 := finrank_eq_of_rank_eq (rank_bot _ _) end section StrongRankCondition variable [StrongRankCondition R] [Module.Finite R M] /-- A finite rank torsion-free module has positive `finrank` iff it has a nonzero element. -/ theorem Module.finrank_pos_iff_exists_ne_zero [NoZeroSMulDivisors R M] : 0 < finrank R M ↔ βˆƒ x : M, x β‰  0 := by rw [← @rank_pos_iff_exists_ne_zero R M, ← finrank_eq_rank] norm_cast /-- An `R`-finite torsion-free module has positive `finrank` iff it is nontrivial. -/ theorem Module.finrank_pos_iff [NoZeroSMulDivisors R M] : 0 < finrank R M ↔ Nontrivial M := by rw [← rank_pos_iff_nontrivial (R := R), ← finrank_eq_rank] norm_cast /-- A nontrivial finite dimensional space has positive `finrank`. -/ theorem Module.finrank_pos [NoZeroSMulDivisors R M] [h : Nontrivial M] : 0 < finrank R M := finrank_pos_iff.mpr h /-- See `Module.finrank_zero_iff` for the stronger version with `NoZeroSMulDivisors R M`. -/ theorem Module.finrank_eq_zero_iff : finrank R M = 0 ↔ βˆ€ x : M, βˆƒ a : R, a β‰  0 ∧ a β€’ x = 0 := by rw [← rank_eq_zero_iff (R := R), ← finrank_eq_rank] norm_cast /-- A finite dimensional space has zero `finrank` iff it is a subsingleton. This is the `finrank` version of `rank_zero_iff`. -/ theorem Module.finrank_zero_iff [NoZeroSMulDivisors R M] : finrank R M = 0 ↔ Subsingleton M := by rw [← rank_zero_iff (R := R), ← finrank_eq_rank] norm_cast /-- Similar to `rank_quotient_add_rank_le` but for `finrank` and a finite `M`. -/ lemma Module.finrank_quotient_add_finrank_le (N : Submodule R M) : finrank R (M β§Έ N) + finrank R N ≀ finrank R M := by haveI := nontrivial_of_invariantBasisNumber R have := rank_quotient_add_rank_le N rw [← finrank_eq_rank R M, ← finrank_eq_rank R, ← N.finrank_eq_rank] at this exact mod_cast this end StrongRankCondition theorem Module.finrank_eq_zero_of_rank_eq_zero (h : Module.rank R M = 0) : finrank R M = 0 := by delta finrank rw [h, zero_toNat] theorem Submodule.bot_eq_top_of_rank_eq_zero [NoZeroSMulDivisors R M] (h : Module.rank R M = 0) : (βŠ₯ : Submodule R M) = ⊀ := by nontriviality R rw [rank_zero_iff] at h subsingleton /-- See `rank_subsingleton` for the reason that `Nontrivial R` is needed. -/ @[simp] theorem Submodule.rank_eq_zero [Nontrivial R] [NoZeroSMulDivisors R M] {S : Submodule R M} : Module.rank R S = 0 ↔ S = βŠ₯ := ⟨fun h => (Submodule.eq_bot_iff _).2 fun x hx => congr_arg Subtype.val <| ((Submodule.eq_bot_iff _).1 <| Eq.symm <| Submodule.bot_eq_top_of_rank_eq_zero h) ⟨x, hx⟩ Submodule.mem_top, fun h => by rw [h, rank_bot]⟩ @[simp] theorem Submodule.finrank_eq_zero [StrongRankCondition R] [NoZeroSMulDivisors R M] {S : Submodule R M} [Module.Finite R S] : finrank R S = 0 ↔ S = βŠ₯ := by rw [← Submodule.rank_eq_zero, ← finrank_eq_rank, ← @Nat.cast_zero Cardinal, Nat.cast_inj]
@[simp] lemma Submodule.one_le_finrank_iff [StrongRankCondition R] [NoZeroSMulDivisors R M] {S : Submodule R M} [Module.Finite R S] : 1 ≀ finrank R S ↔ S β‰  βŠ₯ := by
Mathlib/LinearAlgebra/Dimension/Finite.lean
479
482
/- 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 -/ import Mathlib.Algebra.Module.Card import Mathlib.Analysis.SpecificLimits.Normed import Mathlib.SetTheory.Cardinal.Continuum import Mathlib.SetTheory.Cardinal.CountableCover import Mathlib.LinearAlgebra.Basis.VectorSpace import Mathlib.Topology.MetricSpace.Perfect /-! # Cardinality of open subsets of vector spaces Any nonempty open subset of a topological vector space over a nontrivially normed field has the same cardinality as the whole space. This is proved in `cardinal_eq_of_isOpen`. We deduce that a countable set in a nontrivial vector space over a complete nontrivially normed field has dense complement, in `Set.Countable.dense_compl`. This follows from the previous argument and the fact that a complete nontrivially normed field has cardinality at least continuum, proved in `continuum_le_cardinal_of_nontriviallyNormedField`. -/ universe u v open Filter Pointwise Set Function Cardinal open scoped Cardinal Topology /-- A complete nontrivially normed field has cardinality at least continuum. -/ theorem continuum_le_cardinal_of_nontriviallyNormedField (π•œ : Type*) [NontriviallyNormedField π•œ] [CompleteSpace π•œ] : 𝔠 ≀ #π•œ := by suffices βˆƒ f : (β„• β†’ Bool) β†’ π•œ, range f βŠ† univ ∧ Continuous f ∧ Injective f by rcases this with ⟨f, -, -, f_inj⟩ simpa using lift_mk_le_lift_mk_of_injective f_inj apply Perfect.exists_nat_bool_injection _ univ_nonempty refine ⟨isClosed_univ, preperfect_iff_nhds.2 (fun x _ U hU ↦ ?_)⟩ rcases NormedField.exists_norm_lt_one π•œ with ⟨c, c_pos, hc⟩ have A : Tendsto (fun n ↦ x + c^n) atTop (𝓝 (x + 0)) := tendsto_const_nhds.add (tendsto_pow_atTop_nhds_zero_of_norm_lt_one hc) rw [add_zero] at A have B : βˆ€αΆ  n in atTop, x + c^n ∈ U := tendsto_def.1 A U hU rcases B.exists with ⟨n, hn⟩ refine ⟨x + c^n, by simpa using hn, ?_⟩ simp only [add_ne_left] apply pow_ne_zero simpa using c_pos /-- A nontrivial module over a complete nontrivially normed field has cardinality at least continuum. -/ theorem continuum_le_cardinal_of_module (π•œ : Type u) (E : Type v) [NontriviallyNormedField π•œ] [CompleteSpace π•œ] [AddCommGroup E] [Module π•œ E] [Nontrivial E] : 𝔠 ≀ #E := by have A : lift.{v} (𝔠 : Cardinal.{u}) ≀ lift.{v} (#π•œ) := by simpa using continuum_le_cardinal_of_nontriviallyNormedField π•œ simpa using A.trans (Cardinal.mk_le_of_module π•œ E) /-- In a topological vector space over a nontrivially normed field, any neighborhood of zero has the same cardinality as the whole space. See also `cardinal_eq_of_mem_nhds`. -/ lemma cardinal_eq_of_mem_nhds_zero {E : Type*} (π•œ : Type*) [NontriviallyNormedField π•œ] [Zero E] [MulActionWithZero π•œ E] [TopologicalSpace E] [ContinuousSMul π•œ E] {s : Set E} (hs : s ∈ 𝓝 (0 : E)) : #s = #E := by /- As `s` is a neighborhood of `0`, the space is covered by the rescaled sets `c^n β€’ s`, where `c` is any element of `π•œ` with norm `> 1`. All these sets are in bijection and have therefore the same cardinality. The conclusion follows. -/ obtain ⟨c, hc⟩ : βˆƒ x : π•œ , 1 < β€–xβ€– := NormedField.exists_lt_norm π•œ 1 have cn_ne : βˆ€ n, c^n β‰  0 := by intro n apply pow_ne_zero rintro rfl simp only [norm_zero] at hc exact lt_irrefl _ (hc.trans zero_lt_one) have A : βˆ€ (x : E), βˆ€αΆ  n in (atTop : Filter β„•), x ∈ c^n β€’ s := by intro x have : Tendsto (fun n ↦ (c^n) ⁻¹ β€’ x) atTop (𝓝 ((0 : π•œ) β€’ x)) := by have : Tendsto (fun n ↦ (c^n)⁻¹) atTop (𝓝 0) := by simp_rw [← inv_pow] apply tendsto_pow_atTop_nhds_zero_of_norm_lt_one rw [norm_inv] exact inv_lt_one_of_one_ltβ‚€ hc exact Tendsto.smul_const this x rw [zero_smul] at this filter_upwards [this hs] with n (hn : (c ^ n)⁻¹ β€’ x ∈ s) exact (mem_smul_set_iff_inv_smul_memβ‚€ (cn_ne n) _ _).2 hn have B : βˆ€ n, #(c^n β€’ s :) = #s := by intro n have : (c^n β€’ s :) ≃ s := { toFun := fun x ↦ ⟨(c^n)⁻¹ β€’ x.1, (mem_smul_set_iff_inv_smul_memβ‚€ (cn_ne n) _ _).1 x.2⟩ invFun := fun x ↦ ⟨(c^n) β€’ x.1, smul_mem_smul_set x.2⟩ left_inv := fun x ↦ by simp [smul_smul, mul_inv_cancelβ‚€ (cn_ne n)] right_inv := fun x ↦ by simp [smul_smul, inv_mul_cancelβ‚€ (cn_ne n)] } exact Cardinal.mk_congr this apply (Cardinal.mk_of_countable_eventually_mem A B).symm /-- In a topological vector space over a nontrivially normed field, any neighborhood of a point has the same cardinality as the whole space. -/ theorem cardinal_eq_of_mem_nhds {E : Type*} (π•œ : Type*) [NontriviallyNormedField π•œ] [AddGroup E] [MulActionWithZero π•œ E] [TopologicalSpace E] [ContinuousAdd E] [ContinuousSMul π•œ E] {s : Set E} {x : E} (hs : s ∈ 𝓝 x) : #s = #E := by let g := Homeomorph.addLeft x let t := g ⁻¹' s have : t ∈ 𝓝 0 := g.continuous.continuousAt.preimage_mem_nhds (by simpa [g] using hs) have A : #t = #E := cardinal_eq_of_mem_nhds_zero π•œ this have B : #t = #s := Cardinal.mk_subtype_of_equiv s g.toEquiv rwa [B] at A /-- In a topological vector space over a nontrivially normed field, any nonempty open set has the same cardinality as the whole space. -/ theorem cardinal_eq_of_isOpen {E : Type*} (π•œ : Type*) [NontriviallyNormedField π•œ] [AddGroup E] [MulActionWithZero π•œ E] [TopologicalSpace E] [ContinuousAdd E] [ContinuousSMul π•œ E] {s : Set E} (hs : IsOpen s) (h's : s.Nonempty) : #s = #E := by rcases h's with ⟨x, hx⟩ exact cardinal_eq_of_mem_nhds π•œ (hs.mem_nhds hx) /-- In a nontrivial topological vector space over a complete nontrivially normed field, any nonempty open set has cardinality at least continuum. -/ theorem continuum_le_cardinal_of_isOpen {E : Type*} (π•œ : Type*) [NontriviallyNormedField π•œ] [CompleteSpace π•œ] [AddCommGroup E] [Module π•œ E] [Nontrivial E] [TopologicalSpace E] [ContinuousAdd E] [ContinuousSMul π•œ E] {s : Set E} (hs : IsOpen s) (h's : s.Nonempty) : 𝔠 ≀ #s := by simpa [cardinal_eq_of_isOpen π•œ hs h's] using continuum_le_cardinal_of_module π•œ E /-- In a nontrivial topological vector space over a complete nontrivially normed field, any
countable set has dense complement. -/ theorem Set.Countable.dense_compl {E : Type u} (π•œ : Type*) [NontriviallyNormedField π•œ] [CompleteSpace π•œ] [AddCommGroup E] [Module π•œ E] [Nontrivial E] [TopologicalSpace E] [ContinuousAdd E] [ContinuousSMul π•œ E] {s : Set E} (hs : s.Countable) : Dense sᢜ := by rw [← interior_eq_empty_iff_dense_compl] by_contra H apply lt_irrefl (β„΅β‚€ : Cardinal.{u}) calc (β„΅β‚€ : Cardinal.{u}) < 𝔠 := aleph0_lt_continuum _ ≀ #(interior s) := continuum_le_cardinal_of_isOpen π•œ isOpen_interior (nmem_singleton_empty.1 H) _ ≀ #s := mk_le_mk_of_subset interior_subset
Mathlib/Topology/Algebra/Module/Cardinality.lean
127
139
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.WSeq.Basic import Mathlib.Data.WSeq.Defs import Mathlib.Data.WSeq.Productive import Mathlib.Data.WSeq.Relation deprecated_module (since := "2025-04-13")
Mathlib/Data/Seq/WSeq.lean
1,091
1,094
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.Algebra.Category.MonCat.Basic import Mathlib.CategoryTheory.Limits.HasLimits import Mathlib.CategoryTheory.ConcreteCategory.Elementwise /-! # The category of monoids has all colimits. We do this construction knowing nothing about monoids. In particular, I want to claim that this file could be produced by a python script that just looks at what Lean 3's `#print monoid` printed a long time ago (it no longer looks like this due to the addition of `npow` fields): ``` structure monoid : Type u β†’ Type u fields: monoid.mul : Ξ  {M : Type u} [self : monoid M], M β†’ M β†’ M monoid.mul_assoc : βˆ€ {M : Type u} [self : monoid M] (a b c : M), a * b * c = a * (b * c) monoid.one : Ξ  {M : Type u} [self : monoid M], M monoid.one_mul : βˆ€ {M : Type u} [self : monoid M] (a : M), 1 * a = a monoid.mul_one : βˆ€ {M : Type u} [self : monoid M] (a : M), a * 1 = a ``` and if we'd fed it the output of Lean 3's `#print comm_ring`, this file would instead build colimits of commutative rings. A slightly bolder claim is that we could do this with tactics, as well. Note: `Monoid` and `CommRing` are no longer flat structures in Mathlib4, and so `#print Monoid` gives the less clear ``` inductive Monoid.{u} : Type u β†’ Type u number of parameters: 1 constructors: Monoid.mk : {M : Type u} β†’ [toSemigroup : Semigroup M] β†’ [toOne : One M] β†’ (βˆ€ (a : M), 1 * a = a) β†’ (βˆ€ (a : M), a * 1 = a) β†’ (npow : β„• β†’ M β†’ M) β†’ autoParam (βˆ€ (x : M), npow 0 x = 1) _auto✝ β†’ autoParam (βˆ€ (n : β„•) (x : M), npow (n + 1) x = x * npow n x) _auto✝¹ β†’ Monoid M ``` -/ assert_not_exists MonoidWithZero universe v u open CategoryTheory open CategoryTheory.Limits namespace MonCat.Colimits /-! We build the colimit of a diagram in `MonCat` by constructing the free monoid on the disjoint union of all the monoids in the diagram, then taking the quotient by the monoid laws within each monoid, and the identifications given by the morphisms in the diagram. -/ variable {J : Type v} [Category.{u} J] (F : J β₯€ MonCat.{v}) /-- An inductive type representing all monoid expressions (without relations) on a collection of types indexed by the objects of `J`. -/ inductive Prequotient -- There's always `of` | of : βˆ€ (j : J) (_ : F.obj j), Prequotient -- Then one generator for each operation | one : Prequotient | mul : Prequotient β†’ Prequotient β†’ Prequotient instance : Inhabited (Prequotient F) := ⟨Prequotient.one⟩ open Prequotient /-- The relation on `Prequotient` saying when two expressions are equal because of the monoid laws, or because one element is mapped to another by a morphism in the diagram. -/ inductive Relation : Prequotient F β†’ Prequotient F β†’ Prop-- Make it an equivalence relation: | refl : βˆ€ x, Relation x x | symm : βˆ€ (x y) (_ : Relation x y), Relation y x | trans : βˆ€ (x y z) (_ : Relation x y) (_ : Relation y z), Relation x z-- There's always a `map` relation | map : βˆ€ (j j' : J) (f : j ⟢ j') (x : F.obj j), Relation (Prequotient.of j' ((F.map f) x)) (Prequotient.of j x)-- Then one relation per operation, describing the interaction with `of` | mul : βˆ€ (j) (x y : F.obj j), Relation (Prequotient.of j (x * y)) (mul (Prequotient.of j x) (Prequotient.of j y)) | one : βˆ€ j, Relation (Prequotient.of j 1) one-- Then one relation per argument of each operation | mul_1 : βˆ€ (x x' y) (_ : Relation x x'), Relation (mul x y) (mul x' y) | mul_2 : βˆ€ (x y y') (_ : Relation y y'), Relation (mul x y) (mul x y') -- And one relation per axiom | mul_assoc : βˆ€ x y z, Relation (mul (mul x y) z) (mul x (mul y z)) | one_mul : βˆ€ x, Relation (mul one x) x | mul_one : βˆ€ x, Relation (mul x one) x /-- The setoid corresponding to monoid expressions modulo monoid relations and identifications. -/ def colimitSetoid : Setoid (Prequotient F) where r := Relation F iseqv := ⟨Relation.refl, Relation.symm _ _, Relation.trans _ _ _⟩ attribute [instance] colimitSetoid /-- The underlying type of the colimit of a diagram in `MonCat`. -/ def ColimitType : Type v := Quotient (colimitSetoid F) instance : Inhabited (ColimitType F) := by dsimp [ColimitType] infer_instance instance monoidColimitType : Monoid (ColimitType F) where one := Quotient.mk _ one mul := Quotient.mapβ‚‚ mul fun _ x' rx y _ ry => Setoid.trans (Relation.mul_1 _ _ y rx) (Relation.mul_2 x' _ _ ry) one_mul := Quotient.ind fun _ => Quotient.sound <| Relation.one_mul _ mul_one := Quotient.ind fun _ => Quotient.sound <| Relation.mul_one _ mul_assoc := Quotient.ind fun _ => Quotient.indβ‚‚ fun _ _ => Quotient.sound <| Relation.mul_assoc _ _ _ @[simp] theorem quot_one : Quot.mk Setoid.r one = (1 : ColimitType F) := rfl @[simp] theorem quot_mul (x y : Prequotient F) : Quot.mk Setoid.r (mul x y) = @HMul.hMul (ColimitType F) (ColimitType F) (ColimitType F) _ (Quot.mk Setoid.r x) (Quot.mk Setoid.r y) := rfl /-- The bundled monoid giving the colimit of a diagram. -/ def colimit : MonCat := of (ColimitType F) /-- The function from a given monoid in the diagram to the colimit monoid. -/ def coconeFun (j : J) (x : F.obj j) : ColimitType F := Quot.mk _ (Prequotient.of j x) /-- The monoid homomorphism from a given monoid in the diagram to the colimit monoid. -/ def coconeMorphism (j : J) : F.obj j ⟢ colimit F := ofHom { toFun := coconeFun F j map_one' := Quot.sound (Relation.one _) map_mul' _ _ := Quot.sound (Relation.mul _ _ _) } @[simp] theorem cocone_naturality {j j' : J} (f : j ⟢ j') : F.map f ≫ coconeMorphism F j' = coconeMorphism F j := by ext apply Quot.sound apply Relation.map @[simp] theorem cocone_naturality_components (j j' : J) (f : j ⟢ j') (x : F.obj j) : (coconeMorphism F j') (F.map f x) = (coconeMorphism F j) x := by rw [← cocone_naturality F f] rfl /-- The cocone over the proposed colimit monoid. -/ def colimitCocone : Cocone F where pt := colimit F ΞΉ := { app := coconeMorphism F } /-- The function from the free monoid on the diagram to the cone point of any other cocone. -/ @[simp] def descFunLift (s : Cocone F) : Prequotient F β†’ s.pt | Prequotient.of j x => (s.ΞΉ.app j) x | one => 1 | mul x y => descFunLift _ x * descFunLift _ y /-- The function from the colimit monoid to the cone point of any other cocone. -/ def descFun (s : Cocone F) : ColimitType F β†’ s.pt := by fapply Quot.lift Β· exact descFunLift F s Β· intro x y r
induction r with | refl x => rfl | symm x y _ h => exact h.symm | trans x y z _ _ h₁ hβ‚‚ => exact h₁.trans hβ‚‚
Mathlib/Algebra/Category/MonCat/Colimits.lean
188
191
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, SΓ©bastien GouΓ«zel, FrΓ©dΓ©ric Dupuis -/ import Mathlib.Algebra.BigOperators.Field import Mathlib.Analysis.Complex.Basic import Mathlib.Analysis.InnerProductSpace.Defs import Mathlib.GroupTheory.MonoidLocalization.Basic /-! # Properties of inner product spaces This file proves many basic properties of inner product spaces (real or complex). ## Main results - `inner_mul_inner_self_le`: the Cauchy-Schwartz inequality (one of many variants). - `norm_inner_eq_norm_iff`: the equality criteion in the Cauchy-Schwartz inequality (also in many variants). - `inner_eq_sum_norm_sq_div_four`: the polarization identity. ## Tags inner product space, Hilbert space, norm -/ noncomputable section open RCLike Real Filter Topology ComplexConjugate Finsupp open LinearMap (BilinForm) variable {π•œ E F : Type*} [RCLike π•œ] section BasicProperties_Seminormed open scoped InnerProductSpace variable [SeminormedAddCommGroup E] [InnerProductSpace π•œ E] variable [SeminormedAddCommGroup F] [InnerProductSpace ℝ F] local notation "βŸͺ" x ", " y "⟫" => @inner π•œ _ _ x y local postfix:90 "†" => starRingEnd _ export InnerProductSpace (norm_sq_eq_re_inner) @[simp] theorem inner_conj_symm (x y : E) : βŸͺy, xβŸ«β€  = βŸͺx, y⟫ := InnerProductSpace.conj_inner_symm _ _ theorem real_inner_comm (x y : F) : βŸͺy, x⟫_ℝ = βŸͺx, y⟫_ℝ := @inner_conj_symm ℝ _ _ _ _ x y theorem inner_eq_zero_symm {x y : E} : βŸͺx, y⟫ = 0 ↔ βŸͺy, x⟫ = 0 := by rw [← inner_conj_symm] exact star_eq_zero @[simp] theorem inner_self_im (x : E) : im βŸͺx, x⟫ = 0 := by rw [← @ofReal_inj π•œ, im_eq_conj_sub]; simp theorem inner_add_left (x y z : E) : βŸͺx + y, z⟫ = βŸͺx, z⟫ + βŸͺy, z⟫ := InnerProductSpace.add_left _ _ _ theorem inner_add_right (x y z : E) : βŸͺx, y + z⟫ = βŸͺx, y⟫ + βŸͺx, z⟫ := by rw [← inner_conj_symm, inner_add_left, RingHom.map_add] simp only [inner_conj_symm] theorem inner_re_symm (x y : E) : re βŸͺx, y⟫ = re βŸͺy, x⟫ := by rw [← inner_conj_symm, conj_re] theorem inner_im_symm (x y : E) : im βŸͺx, y⟫ = -im βŸͺy, x⟫ := by rw [← inner_conj_symm, conj_im] section Algebra variable {𝕝 : Type*} [CommSemiring 𝕝] [StarRing 𝕝] [Algebra 𝕝 π•œ] [Module 𝕝 E] [IsScalarTower 𝕝 π•œ E] [StarModule 𝕝 π•œ] /-- See `inner_smul_left` for the common special when `π•œ = 𝕝`. -/ lemma inner_smul_left_eq_star_smul (x y : E) (r : 𝕝) : βŸͺr β€’ x, y⟫ = r† β€’ βŸͺx, y⟫ := by rw [← algebraMap_smul π•œ r, InnerProductSpace.smul_left, starRingEnd_apply, starRingEnd_apply, ← algebraMap_star_comm, ← smul_eq_mul, algebraMap_smul] /-- Special case of `inner_smul_left_eq_star_smul` when the acting ring has a trivial star (eg `β„•`, `β„€`, `β„šβ‰₯0`, `β„š`, `ℝ`). -/ lemma inner_smul_left_eq_smul [TrivialStar 𝕝] (x y : E) (r : 𝕝) : βŸͺr β€’ x, y⟫ = r β€’ βŸͺx, y⟫ := by rw [inner_smul_left_eq_star_smul, starRingEnd_apply, star_trivial] /-- See `inner_smul_right` for the common special when `π•œ = 𝕝`. -/ lemma inner_smul_right_eq_smul (x y : E) (r : 𝕝) : βŸͺx, r β€’ y⟫ = r β€’ βŸͺx, y⟫ := by rw [← inner_conj_symm, inner_smul_left_eq_star_smul, starRingEnd_apply, starRingEnd_apply, star_smul, star_star, ← starRingEnd_apply, inner_conj_symm] end Algebra /-- See `inner_smul_left_eq_star_smul` for the case of a general algebra action. -/ theorem inner_smul_left (x y : E) (r : π•œ) : βŸͺr β€’ x, y⟫ = r† * βŸͺx, y⟫ := inner_smul_left_eq_star_smul .. theorem real_inner_smul_left (x y : F) (r : ℝ) : βŸͺr β€’ x, y⟫_ℝ = r * βŸͺx, y⟫_ℝ := inner_smul_left _ _ _ theorem inner_smul_real_left (x y : E) (r : ℝ) : βŸͺ(r : π•œ) β€’ x, y⟫ = r β€’ βŸͺx, y⟫ := by rw [inner_smul_left, conj_ofReal, Algebra.smul_def] /-- See `inner_smul_right_eq_smul` for the case of a general algebra action. -/ theorem inner_smul_right (x y : E) (r : π•œ) : βŸͺx, r β€’ y⟫ = r * βŸͺx, y⟫ := inner_smul_right_eq_smul .. theorem real_inner_smul_right (x y : F) (r : ℝ) : βŸͺx, r β€’ y⟫_ℝ = r * βŸͺx, y⟫_ℝ := inner_smul_right _ _ _ theorem inner_smul_real_right (x y : E) (r : ℝ) : βŸͺx, (r : π•œ) β€’ y⟫ = r β€’ βŸͺx, y⟫ := by rw [inner_smul_right, Algebra.smul_def] /-- The inner product as a sesquilinear form. Note that in the case `π•œ = ℝ` this is a bilinear form. -/ @[simps!] def sesqFormOfInner : E β†’β‚—[π•œ] E →ₗ⋆[π•œ] π•œ := LinearMap.mkβ‚‚'β‚›β‚— (RingHom.id π•œ) (starRingEnd _) (fun x y => βŸͺy, x⟫) (fun _x _y _z => inner_add_right _ _ _) (fun _r _x _y => inner_smul_right _ _ _) (fun _x _y _z => inner_add_left _ _ _) fun _r _x _y => inner_smul_left _ _ _ /-- The real inner product as a bilinear form. Note that unlike `sesqFormOfInner`, this does not reverse the order of the arguments. -/ @[simps!] def bilinFormOfRealInner : BilinForm ℝ F := sesqFormOfInner.flip /-- An inner product with a sum on the left. -/ theorem sum_inner {ΞΉ : Type*} (s : Finset ΞΉ) (f : ΞΉ β†’ E) (x : E) : βŸͺβˆ‘ i ∈ s, f i, x⟫ = βˆ‘ i ∈ s, βŸͺf i, x⟫ := map_sum (sesqFormOfInner (π•œ := π•œ) (E := E) x) _ _ /-- An inner product with a sum on the right. -/ theorem inner_sum {ΞΉ : Type*} (s : Finset ΞΉ) (f : ΞΉ β†’ E) (x : E) : βŸͺx, βˆ‘ i ∈ s, f i⟫ = βˆ‘ i ∈ s, βŸͺx, f i⟫ := map_sum (LinearMap.flip sesqFormOfInner x) _ _ /-- An inner product with a sum on the left, `Finsupp` version. -/ protected theorem Finsupp.sum_inner {ΞΉ : Type*} (l : ΞΉ β†’β‚€ π•œ) (v : ΞΉ β†’ E) (x : E) : βŸͺl.sum fun (i : ΞΉ) (a : π•œ) => a β€’ v i, x⟫ = l.sum fun (i : ΞΉ) (a : π•œ) => conj a β€’ βŸͺv i, x⟫ := by convert sum_inner (π•œ := π•œ) l.support (fun a => l a β€’ v a) x simp only [inner_smul_left, Finsupp.sum, smul_eq_mul] /-- An inner product with a sum on the right, `Finsupp` version. -/ protected theorem Finsupp.inner_sum {ΞΉ : Type*} (l : ΞΉ β†’β‚€ π•œ) (v : ΞΉ β†’ E) (x : E) : βŸͺx, l.sum fun (i : ΞΉ) (a : π•œ) => a β€’ v i⟫ = l.sum fun (i : ΞΉ) (a : π•œ) => a β€’ βŸͺx, v i⟫ := by convert inner_sum (π•œ := π•œ) l.support (fun a => l a β€’ v a) x simp only [inner_smul_right, Finsupp.sum, smul_eq_mul] protected theorem DFinsupp.sum_inner {ΞΉ : Type*} [DecidableEq ΞΉ] {Ξ± : ΞΉ β†’ Type*} [βˆ€ i, AddZeroClass (Ξ± i)] [βˆ€ (i) (x : Ξ± i), Decidable (x β‰  0)] (f : βˆ€ i, Ξ± i β†’ E) (l : Ξ β‚€ i, Ξ± i) (x : E) : βŸͺl.sum f, x⟫ = l.sum fun i a => βŸͺf i a, x⟫ := by simp +contextual only [DFinsupp.sum, sum_inner, smul_eq_mul] protected theorem DFinsupp.inner_sum {ΞΉ : Type*} [DecidableEq ΞΉ] {Ξ± : ΞΉ β†’ Type*} [βˆ€ i, AddZeroClass (Ξ± i)] [βˆ€ (i) (x : Ξ± i), Decidable (x β‰  0)] (f : βˆ€ i, Ξ± i β†’ E) (l : Ξ β‚€ i, Ξ± i) (x : E) : βŸͺx, l.sum f⟫ = l.sum fun i a => βŸͺx, f i a⟫ := by simp +contextual only [DFinsupp.sum, inner_sum, smul_eq_mul] @[simp] theorem inner_zero_left (x : E) : βŸͺ0, x⟫ = 0 := by rw [← zero_smul π•œ (0 : E), inner_smul_left, RingHom.map_zero, zero_mul] theorem inner_re_zero_left (x : E) : re βŸͺ0, x⟫ = 0 := by simp only [inner_zero_left, AddMonoidHom.map_zero] @[simp] theorem inner_zero_right (x : E) : βŸͺx, 0⟫ = 0 := by rw [← inner_conj_symm, inner_zero_left, RingHom.map_zero] theorem inner_re_zero_right (x : E) : re βŸͺx, 0⟫ = 0 := by simp only [inner_zero_right, AddMonoidHom.map_zero] theorem inner_self_nonneg {x : E} : 0 ≀ re βŸͺx, x⟫ := PreInnerProductSpace.toCore.re_inner_nonneg x theorem real_inner_self_nonneg {x : F} : 0 ≀ βŸͺx, x⟫_ℝ := @inner_self_nonneg ℝ F _ _ _ x @[simp] theorem inner_self_ofReal_re (x : E) : (re βŸͺx, x⟫ : π•œ) = βŸͺx, x⟫ := ((RCLike.is_real_TFAE (βŸͺx, x⟫ : π•œ)).out 2 3).2 (inner_self_im (π•œ := π•œ) x) theorem inner_self_eq_norm_sq_to_K (x : E) : βŸͺx, x⟫ = (β€–xβ€– : π•œ) ^ 2 := by rw [← inner_self_ofReal_re, ← norm_sq_eq_re_inner, ofReal_pow] theorem inner_self_re_eq_norm (x : E) : re βŸͺx, x⟫ = β€–βŸͺx, xβŸ«β€– := by conv_rhs => rw [← inner_self_ofReal_re] symm exact norm_of_nonneg inner_self_nonneg theorem inner_self_ofReal_norm (x : E) : (β€–βŸͺx, xβŸ«β€– : π•œ) = βŸͺx, x⟫ := by rw [← inner_self_re_eq_norm] exact inner_self_ofReal_re _ theorem real_inner_self_abs (x : F) : |βŸͺx, x⟫_ℝ| = βŸͺx, x⟫_ℝ := @inner_self_ofReal_norm ℝ F _ _ _ x theorem norm_inner_symm (x y : E) : β€–βŸͺx, yβŸ«β€– = β€–βŸͺy, xβŸ«β€– := by rw [← inner_conj_symm, norm_conj] @[simp] theorem inner_neg_left (x y : E) : βŸͺ-x, y⟫ = -βŸͺx, y⟫ := by rw [← neg_one_smul π•œ x, inner_smul_left] simp @[simp] theorem inner_neg_right (x y : E) : βŸͺx, -y⟫ = -βŸͺx, y⟫ := by rw [← inner_conj_symm, inner_neg_left]; simp only [RingHom.map_neg, inner_conj_symm] theorem inner_neg_neg (x y : E) : βŸͺ-x, -y⟫ = βŸͺx, y⟫ := by simp theorem inner_self_conj (x : E) : βŸͺx, xβŸ«β€  = βŸͺx, x⟫ := inner_conj_symm _ _ theorem inner_sub_left (x y z : E) : βŸͺx - y, z⟫ = βŸͺx, z⟫ - βŸͺy, z⟫ := by simp [sub_eq_add_neg, inner_add_left] theorem inner_sub_right (x y z : E) : βŸͺx, y - z⟫ = βŸͺx, y⟫ - βŸͺx, z⟫ := by simp [sub_eq_add_neg, inner_add_right] theorem inner_mul_symm_re_eq_norm (x y : E) : re (βŸͺx, y⟫ * βŸͺy, x⟫) = β€–βŸͺx, y⟫ * βŸͺy, xβŸ«β€– := by rw [← inner_conj_symm, mul_comm] exact re_eq_norm_of_mul_conj (inner y x) /-- Expand `βŸͺx + y, x + y⟫` -/ theorem inner_add_add_self (x y : E) : βŸͺx + y, x + y⟫ = βŸͺx, x⟫ + βŸͺx, y⟫ + βŸͺy, x⟫ + βŸͺy, y⟫ := by simp only [inner_add_left, inner_add_right]; ring /-- Expand `βŸͺx + y, x + y⟫_ℝ` -/ theorem real_inner_add_add_self (x y : F) : βŸͺx + y, x + y⟫_ℝ = βŸͺx, x⟫_ℝ + 2 * βŸͺx, y⟫_ℝ + βŸͺy, y⟫_ℝ := by have : βŸͺy, x⟫_ℝ = βŸͺx, y⟫_ℝ := by rw [← inner_conj_symm]; rfl simp only [inner_add_add_self, this, add_left_inj] ring -- Expand `βŸͺx - y, x - y⟫` theorem inner_sub_sub_self (x y : E) : βŸͺx - y, x - y⟫ = βŸͺx, x⟫ - βŸͺx, y⟫ - βŸͺy, x⟫ + βŸͺy, y⟫ := by simp only [inner_sub_left, inner_sub_right]; ring /-- Expand `βŸͺx - y, x - y⟫_ℝ` -/ theorem real_inner_sub_sub_self (x y : F) : βŸͺx - y, x - y⟫_ℝ = βŸͺx, x⟫_ℝ - 2 * βŸͺx, y⟫_ℝ + βŸͺy, y⟫_ℝ := by have : βŸͺy, x⟫_ℝ = βŸͺx, y⟫_ℝ := by rw [← inner_conj_symm]; rfl simp only [inner_sub_sub_self, this, add_left_inj] ring /-- Parallelogram law -/ theorem parallelogram_law {x y : E} : βŸͺx + y, x + y⟫ + βŸͺx - y, x - y⟫ = 2 * (βŸͺx, x⟫ + βŸͺy, y⟫) := by simp only [inner_add_add_self, inner_sub_sub_self] ring /-- **Cauchy–Schwarz inequality**. -/ theorem inner_mul_inner_self_le (x y : E) : β€–βŸͺx, yβŸ«β€– * β€–βŸͺy, xβŸ«β€– ≀ re βŸͺx, x⟫ * re βŸͺy, y⟫ := letI cd : PreInnerProductSpace.Core π•œ E := PreInnerProductSpace.toCore InnerProductSpace.Core.inner_mul_inner_self_le x y /-- Cauchy–Schwarz inequality for real inner products. -/ theorem real_inner_mul_inner_self_le (x y : F) : βŸͺx, y⟫_ℝ * βŸͺx, y⟫_ℝ ≀ βŸͺx, x⟫_ℝ * βŸͺy, y⟫_ℝ := calc βŸͺx, y⟫_ℝ * βŸͺx, y⟫_ℝ ≀ β€–βŸͺx, y⟫_ℝ‖ * β€–βŸͺy, x⟫_ℝ‖ := by rw [real_inner_comm y, ← norm_mul] exact le_abs_self _ _ ≀ βŸͺx, x⟫_ℝ * βŸͺy, y⟫_ℝ := @inner_mul_inner_self_le ℝ _ _ _ _ x y end BasicProperties_Seminormed section BasicProperties variable [NormedAddCommGroup E] [InnerProductSpace π•œ E] variable [NormedAddCommGroup F] [InnerProductSpace ℝ F] local notation "βŸͺ" x ", " y "⟫" => @inner π•œ _ _ x y export InnerProductSpace (norm_sq_eq_re_inner) @[simp] theorem inner_self_eq_zero {x : E} : βŸͺx, x⟫ = 0 ↔ x = 0 := by rw [inner_self_eq_norm_sq_to_K, sq_eq_zero_iff, ofReal_eq_zero, norm_eq_zero] theorem inner_self_ne_zero {x : E} : βŸͺx, x⟫ β‰  0 ↔ x β‰  0 := inner_self_eq_zero.not variable (π•œ) theorem ext_inner_left {x y : E} (h : βˆ€ v, βŸͺv, x⟫ = βŸͺv, y⟫) : x = y := by rw [← sub_eq_zero, ← @inner_self_eq_zero π•œ, inner_sub_right, sub_eq_zero, h (x - y)] theorem ext_inner_right {x y : E} (h : βˆ€ v, βŸͺx, v⟫ = βŸͺy, v⟫) : x = y := by rw [← sub_eq_zero, ← @inner_self_eq_zero π•œ, inner_sub_left, sub_eq_zero, h (x - y)] variable {π•œ} @[simp] theorem re_inner_self_nonpos {x : E} : re βŸͺx, x⟫ ≀ 0 ↔ x = 0 := by rw [← norm_sq_eq_re_inner, (sq_nonneg _).le_iff_eq, sq_eq_zero_iff, norm_eq_zero] @[simp] lemma re_inner_self_pos {x : E} : 0 < re βŸͺx, x⟫ ↔ x β‰  0 := by simpa [-re_inner_self_nonpos] using re_inner_self_nonpos (π•œ := π•œ) (x := x).not @[deprecated (since := "2025-04-22")] alias inner_self_nonpos := re_inner_self_nonpos @[deprecated (since := "2025-04-22")] alias inner_self_pos := re_inner_self_pos open scoped InnerProductSpace in theorem real_inner_self_nonpos {x : F} : βŸͺx, x⟫_ℝ ≀ 0 ↔ x = 0 := re_inner_self_nonpos (π•œ := ℝ) open scoped InnerProductSpace in theorem real_inner_self_pos {x : F} : 0 < βŸͺx, x⟫_ℝ ↔ x β‰  0 := re_inner_self_pos (π•œ := ℝ) /-- A family of vectors is linearly independent if they are nonzero and orthogonal. -/ theorem linearIndependent_of_ne_zero_of_inner_eq_zero {ΞΉ : Type*} {v : ΞΉ β†’ E} (hz : βˆ€ i, v i β‰  0) (ho : Pairwise fun i j => βŸͺv i, v j⟫ = 0) : LinearIndependent π•œ v := by rw [linearIndependent_iff'] intro s g hg i hi have h' : g i * inner (v i) (v i) = inner (v i) (βˆ‘ j ∈ s, g j β€’ v j) := by rw [inner_sum] symm convert Finset.sum_eq_single (M := π•œ) i ?_ ?_ Β· rw [inner_smul_right] Β· intro j _hj hji rw [inner_smul_right, ho hji.symm, mul_zero] Β· exact fun h => False.elim (h hi) simpa [hg, hz] using h' end BasicProperties section Norm_Seminormed open scoped InnerProductSpace variable [SeminormedAddCommGroup E] [InnerProductSpace π•œ E] variable [SeminormedAddCommGroup F] [InnerProductSpace ℝ F] local notation "βŸͺ" x ", " y "⟫" => @inner π•œ _ _ x y local notation "IK" => @RCLike.I π•œ _ theorem norm_eq_sqrt_re_inner (x : E) : β€–xβ€– = √(re βŸͺx, x⟫) := calc β€–xβ€– = √(β€–xβ€– ^ 2) := (sqrt_sq (norm_nonneg _)).symm _ = √(re βŸͺx, x⟫) := congr_arg _ (norm_sq_eq_re_inner _) @[deprecated (since := "2025-04-22")] alias norm_eq_sqrt_inner := norm_eq_sqrt_re_inner theorem norm_eq_sqrt_real_inner (x : F) : β€–xβ€– = √βŸͺx, x⟫_ℝ := @norm_eq_sqrt_re_inner ℝ _ _ _ _ x theorem inner_self_eq_norm_mul_norm (x : E) : re βŸͺx, x⟫ = β€–xβ€– * β€–xβ€– := by rw [@norm_eq_sqrt_re_inner π•œ, ← sqrt_mul inner_self_nonneg (re βŸͺx, x⟫), sqrt_mul_self inner_self_nonneg] theorem inner_self_eq_norm_sq (x : E) : re βŸͺx, x⟫ = β€–xβ€– ^ 2 := by rw [pow_two, inner_self_eq_norm_mul_norm] theorem real_inner_self_eq_norm_mul_norm (x : F) : βŸͺx, x⟫_ℝ = β€–xβ€– * β€–xβ€– := by have h := @inner_self_eq_norm_mul_norm ℝ F _ _ _ x simpa using h theorem real_inner_self_eq_norm_sq (x : F) : βŸͺx, x⟫_ℝ = β€–xβ€– ^ 2 := by rw [pow_two, real_inner_self_eq_norm_mul_norm] /-- Expand the square -/ theorem norm_add_sq (x y : E) : β€–x + yβ€– ^ 2 = β€–xβ€– ^ 2 + 2 * re βŸͺx, y⟫ + β€–yβ€– ^ 2 := by repeat' rw [sq (M := ℝ), ← @inner_self_eq_norm_mul_norm π•œ] rw [inner_add_add_self, two_mul] simp only [add_assoc, add_left_inj, add_right_inj, AddMonoidHom.map_add] rw [← inner_conj_symm, conj_re] alias norm_add_pow_two := norm_add_sq /-- Expand the square -/ theorem norm_add_sq_real (x y : F) : β€–x + yβ€– ^ 2 = β€–xβ€– ^ 2 + 2 * βŸͺx, y⟫_ℝ + β€–yβ€– ^ 2 := by have h := @norm_add_sq ℝ _ _ _ _ x y simpa using h alias norm_add_pow_two_real := norm_add_sq_real /-- Expand the square -/ theorem norm_add_mul_self (x y : E) : β€–x + yβ€– * β€–x + yβ€– = β€–xβ€– * β€–xβ€– + 2 * re βŸͺx, y⟫ + β€–yβ€– * β€–yβ€– := by repeat' rw [← sq (M := ℝ)] exact norm_add_sq _ _ /-- Expand the square -/ theorem norm_add_mul_self_real (x y : F) : β€–x + yβ€– * β€–x + yβ€– = β€–xβ€– * β€–xβ€– + 2 * βŸͺx, y⟫_ℝ + β€–yβ€– * β€–yβ€– := by have h := @norm_add_mul_self ℝ _ _ _ _ x y simpa using h /-- Expand the square -/ theorem norm_sub_sq (x y : E) : β€–x - yβ€– ^ 2 = β€–xβ€– ^ 2 - 2 * re βŸͺx, y⟫ + β€–yβ€– ^ 2 := by rw [sub_eq_add_neg, @norm_add_sq π•œ _ _ _ _ x (-y), norm_neg, inner_neg_right, map_neg, mul_neg, sub_eq_add_neg] alias norm_sub_pow_two := norm_sub_sq /-- Expand the square -/ theorem norm_sub_sq_real (x y : F) : β€–x - yβ€– ^ 2 = β€–xβ€– ^ 2 - 2 * βŸͺx, y⟫_ℝ + β€–yβ€– ^ 2 := @norm_sub_sq ℝ _ _ _ _ _ _ alias norm_sub_pow_two_real := norm_sub_sq_real /-- Expand the square -/ theorem norm_sub_mul_self (x y : E) : β€–x - yβ€– * β€–x - yβ€– = β€–xβ€– * β€–xβ€– - 2 * re βŸͺx, y⟫ + β€–yβ€– * β€–yβ€– := by repeat' rw [← sq (M := ℝ)] exact norm_sub_sq _ _ /-- Expand the square -/ theorem norm_sub_mul_self_real (x y : F) : β€–x - yβ€– * β€–x - yβ€– = β€–xβ€– * β€–xβ€– - 2 * βŸͺx, y⟫_ℝ + β€–yβ€– * β€–yβ€– := by have h := @norm_sub_mul_self ℝ _ _ _ _ x y simpa using h /-- Cauchy–Schwarz inequality with norm -/ theorem norm_inner_le_norm (x y : E) : β€–βŸͺx, yβŸ«β€– ≀ β€–xβ€– * β€–yβ€– := by rw [norm_eq_sqrt_re_inner (π•œ := π•œ) x, norm_eq_sqrt_re_inner (π•œ := π•œ) y] letI : PreInnerProductSpace.Core π•œ E := PreInnerProductSpace.toCore exact InnerProductSpace.Core.norm_inner_le_norm x y theorem nnnorm_inner_le_nnnorm (x y : E) : β€–βŸͺx, yβŸ«β€–β‚Š ≀ β€–xβ€–β‚Š * β€–yβ€–β‚Š := norm_inner_le_norm x y theorem re_inner_le_norm (x y : E) : re βŸͺx, y⟫ ≀ β€–xβ€– * β€–yβ€– := le_trans (re_le_norm (inner x y)) (norm_inner_le_norm x y) /-- Cauchy–Schwarz inequality with norm -/ theorem abs_real_inner_le_norm (x y : F) : |βŸͺx, y⟫_ℝ| ≀ β€–xβ€– * β€–yβ€– := (Real.norm_eq_abs _).ge.trans (norm_inner_le_norm x y) /-- Cauchy–Schwarz inequality with norm -/ theorem real_inner_le_norm (x y : F) : βŸͺx, y⟫_ℝ ≀ β€–xβ€– * β€–yβ€– := le_trans (le_abs_self _) (abs_real_inner_le_norm _ _) lemma inner_eq_zero_of_left {x : E} (y : E) (h : β€–xβ€– = 0) : βŸͺx, y⟫_π•œ = 0 := by rw [← norm_eq_zero] refine le_antisymm ?_ (by positivity) exact norm_inner_le_norm _ _ |>.trans <| by simp [h] lemma inner_eq_zero_of_right (x : E) {y : E} (h : β€–yβ€– = 0) : βŸͺx, y⟫_π•œ = 0 := by rw [inner_eq_zero_symm, inner_eq_zero_of_left _ h] variable (π•œ) include π•œ in theorem parallelogram_law_with_norm (x y : E) : β€–x + yβ€– * β€–x + yβ€– + β€–x - yβ€– * β€–x - yβ€– = 2 * (β€–xβ€– * β€–xβ€– + β€–yβ€– * β€–yβ€–) := by simp only [← @inner_self_eq_norm_mul_norm π•œ] rw [← re.map_add, parallelogram_law, two_mul, two_mul] simp only [re.map_add] include π•œ in theorem parallelogram_law_with_nnnorm (x y : E) : β€–x + yβ€–β‚Š * β€–x + yβ€–β‚Š + β€–x - yβ€–β‚Š * β€–x - yβ€–β‚Š = 2 * (β€–xβ€–β‚Š * β€–xβ€–β‚Š + β€–yβ€–β‚Š * β€–yβ€–β‚Š) := Subtype.ext <| parallelogram_law_with_norm π•œ x y variable {π•œ} /-- Polarization identity: The real part of the inner product, in terms of the norm. -/ theorem re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two (x y : E) : re βŸͺx, y⟫ = (β€–x + yβ€– * β€–x + yβ€– - β€–xβ€– * β€–xβ€– - β€–yβ€– * β€–yβ€–) / 2 := by rw [@norm_add_mul_self π•œ] ring /-- Polarization identity: The real part of the inner product, in terms of the norm. -/ theorem re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two (x y : E) : re βŸͺx, y⟫ = (β€–xβ€– * β€–xβ€– + β€–yβ€– * β€–yβ€– - β€–x - yβ€– * β€–x - yβ€–) / 2 := by rw [@norm_sub_mul_self π•œ] ring /-- Polarization identity: The real part of the inner product, in terms of the norm. -/ theorem re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four (x y : E) : re βŸͺx, y⟫ = (β€–x + yβ€– * β€–x + yβ€– - β€–x - yβ€– * β€–x - yβ€–) / 4 := by rw [@norm_add_mul_self π•œ, @norm_sub_mul_self π•œ] ring /-- Polarization identity: The imaginary part of the inner product, in terms of the norm. -/ theorem im_inner_eq_norm_sub_i_smul_mul_self_sub_norm_add_i_smul_mul_self_div_four (x y : E) : im βŸͺx, y⟫ = (β€–x - IK β€’ yβ€– * β€–x - IK β€’ yβ€– - β€–x + IK β€’ yβ€– * β€–x + IK β€’ yβ€–) / 4 := by simp only [@norm_add_mul_self π•œ, @norm_sub_mul_self π•œ, inner_smul_right, I_mul_re] ring /-- Polarization identity: The inner product, in terms of the norm. -/ theorem inner_eq_sum_norm_sq_div_four (x y : E) : βŸͺx, y⟫ = ((β€–x + yβ€– : π•œ) ^ 2 - (β€–x - yβ€– : π•œ) ^ 2 + ((β€–x - IK β€’ yβ€– : π•œ) ^ 2 - (β€–x + IK β€’ yβ€– : π•œ) ^ 2) * IK) / 4 := by rw [← re_add_im βŸͺx, y⟫, re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four, im_inner_eq_norm_sub_i_smul_mul_self_sub_norm_add_i_smul_mul_self_div_four] push_cast simp only [sq, ← mul_div_right_comm, ← add_div] /-- Polarization identity: The real inner product, in terms of the norm. -/ theorem real_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two (x y : F) : βŸͺx, y⟫_ℝ = (β€–x + yβ€– * β€–x + yβ€– - β€–xβ€– * β€–xβ€– - β€–yβ€– * β€–yβ€–) / 2 := re_to_real.symm.trans <| re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two x y /-- Polarization identity: The real inner product, in terms of the norm. -/ theorem real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two (x y : F) : βŸͺx, y⟫_ℝ = (β€–xβ€– * β€–xβ€– + β€–yβ€– * β€–yβ€– - β€–x - yβ€– * β€–x - yβ€–) / 2 := re_to_real.symm.trans <| re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two x y /-- Pythagorean theorem, if-and-only-if vector inner product form. -/ theorem norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero (x y : F) : β€–x + yβ€– * β€–x + yβ€– = β€–xβ€– * β€–xβ€– + β€–yβ€– * β€–yβ€– ↔ βŸͺx, y⟫_ℝ = 0 := by rw [@norm_add_mul_self ℝ, add_right_cancel_iff, add_eq_left, mul_eq_zero] norm_num /-- Pythagorean theorem, if-and-if vector inner product form using square roots. -/ theorem norm_add_eq_sqrt_iff_real_inner_eq_zero {x y : F} : β€–x + yβ€– = √(β€–xβ€– * β€–xβ€– + β€–yβ€– * β€–yβ€–) ↔ βŸͺx, y⟫_ℝ = 0 := by rw [← norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero, eq_comm, sqrt_eq_iff_mul_self_eq, eq_comm] <;> positivity /-- Pythagorean theorem, vector inner product form. -/ theorem norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (x y : E) (h : βŸͺx, y⟫ = 0) : β€–x + yβ€– * β€–x + yβ€– = β€–xβ€– * β€–xβ€– + β€–yβ€– * β€–yβ€– := by rw [@norm_add_mul_self π•œ, add_right_cancel_iff, add_eq_left, mul_eq_zero] apply Or.inr simp only [h, zero_re'] /-- Pythagorean theorem, vector inner product form. -/ theorem norm_add_sq_eq_norm_sq_add_norm_sq_real {x y : F} (h : βŸͺx, y⟫_ℝ = 0) : β€–x + yβ€– * β€–x + yβ€– = β€–xβ€– * β€–xβ€– + β€–yβ€– * β€–yβ€– := (norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero x y).2 h /-- Pythagorean theorem, subtracting vectors, if-and-only-if vector inner product form. -/ theorem norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero (x y : F) : β€–x - yβ€– * β€–x - yβ€– = β€–xβ€– * β€–xβ€– + β€–yβ€– * β€–yβ€– ↔ βŸͺx, y⟫_ℝ = 0 := by rw [@norm_sub_mul_self ℝ, add_right_cancel_iff, sub_eq_add_neg, add_eq_left, neg_eq_zero, mul_eq_zero] norm_num /-- Pythagorean theorem, subtracting vectors, if-and-if vector inner product form using square roots. -/ theorem norm_sub_eq_sqrt_iff_real_inner_eq_zero {x y : F} : β€–x - yβ€– = √(β€–xβ€– * β€–xβ€– + β€–yβ€– * β€–yβ€–) ↔ βŸͺx, y⟫_ℝ = 0 := by rw [← norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero, eq_comm, sqrt_eq_iff_mul_self_eq, eq_comm] <;> positivity /-- Pythagorean theorem, subtracting vectors, vector inner product form. -/ theorem norm_sub_sq_eq_norm_sq_add_norm_sq_real {x y : F} (h : βŸͺx, y⟫_ℝ = 0) : β€–x - yβ€– * β€–x - yβ€– = β€–xβ€– * β€–xβ€– + β€–yβ€– * β€–yβ€– := (norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero x y).2 h /-- The sum and difference of two vectors are orthogonal if and only if they have the same norm. -/ theorem real_inner_add_sub_eq_zero_iff (x y : F) : βŸͺx + y, x - y⟫_ℝ = 0 ↔ β€–xβ€– = β€–yβ€– := by conv_rhs => rw [← mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _)] simp only [← @inner_self_eq_norm_mul_norm ℝ, inner_add_left, inner_sub_right, real_inner_comm y x, sub_eq_zero, re_to_real] constructor Β· intro h rw [add_comm] at h linarith Β· intro h linarith /-- Given two orthogonal vectors, their sum and difference have equal norms. -/ theorem norm_sub_eq_norm_add {v w : E} (h : βŸͺv, w⟫ = 0) : β€–w - vβ€– = β€–w + vβ€– := by rw [← mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _)] simp only [h, ← @inner_self_eq_norm_mul_norm π•œ, sub_neg_eq_add, sub_zero, map_sub, zero_re', zero_sub, add_zero, map_add, inner_add_right, inner_sub_left, inner_sub_right, inner_re_symm, zero_add] /-- The real inner product of two vectors, divided by the product of their norms, has absolute value at most 1. -/ theorem abs_real_inner_div_norm_mul_norm_le_one (x y : F) : |βŸͺx, y⟫_ℝ / (β€–xβ€– * β€–yβ€–)| ≀ 1 := by rw [abs_div, abs_mul, abs_norm, abs_norm] exact div_le_one_of_leβ‚€ (abs_real_inner_le_norm x y) (by positivity) /-- The inner product of a vector with a multiple of itself. -/ theorem real_inner_smul_self_left (x : F) (r : ℝ) : βŸͺr β€’ x, x⟫_ℝ = r * (β€–xβ€– * β€–xβ€–) := by rw [real_inner_smul_left, ← real_inner_self_eq_norm_mul_norm] /-- The inner product of a vector with a multiple of itself. -/ theorem real_inner_smul_self_right (x : F) (r : ℝ) : βŸͺx, r β€’ x⟫_ℝ = r * (β€–xβ€– * β€–xβ€–) := by rw [inner_smul_right, ← real_inner_self_eq_norm_mul_norm] /-- The inner product of two weighted sums, where the weights in each sum add to 0, in terms of the norms of pairwise differences. -/ theorem inner_sum_smul_sum_smul_of_sum_eq_zero {ι₁ : Type*} {s₁ : Finset ι₁} {w₁ : ι₁ β†’ ℝ} (v₁ : ι₁ β†’ F) (h₁ : βˆ‘ i ∈ s₁, w₁ i = 0) {ΞΉβ‚‚ : Type*} {sβ‚‚ : Finset ΞΉβ‚‚} {wβ‚‚ : ΞΉβ‚‚ β†’ ℝ} (vβ‚‚ : ΞΉβ‚‚ β†’ F) (hβ‚‚ : βˆ‘ i ∈ sβ‚‚, wβ‚‚ i = 0) : βŸͺβˆ‘ i₁ ∈ s₁, w₁ i₁ β€’ v₁ i₁, βˆ‘ iβ‚‚ ∈ sβ‚‚, wβ‚‚ iβ‚‚ β€’ vβ‚‚ iβ‚‚βŸ«_ℝ = (-βˆ‘ i₁ ∈ s₁, βˆ‘ iβ‚‚ ∈ sβ‚‚, w₁ i₁ * wβ‚‚ iβ‚‚ * (β€–v₁ i₁ - vβ‚‚ iβ‚‚β€– * β€–v₁ i₁ - vβ‚‚ iβ‚‚β€–)) / 2 := by simp_rw [sum_inner, inner_sum, real_inner_smul_left, real_inner_smul_right, real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two, ← div_sub_div_same, ← div_add_div_same, mul_sub_left_distrib, left_distrib, Finset.sum_sub_distrib, Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.sum_mul, h₁, hβ‚‚, zero_mul, mul_zero, Finset.sum_const_zero, zero_add, zero_sub, Finset.mul_sum, neg_div, Finset.sum_div, mul_div_assoc, mul_assoc] end Norm_Seminormed section Norm open scoped InnerProductSpace variable [NormedAddCommGroup E] [InnerProductSpace π•œ E] variable [NormedAddCommGroup F] [InnerProductSpace ℝ F] variable {ΞΉ : Type*} local notation "βŸͺ" x ", " y "⟫" => @inner π•œ _ _ x y /-- Formula for the distance between the images of two nonzero points under an inversion with center zero. See also `EuclideanGeometry.dist_inversion_inversion` for inversions around a general point. -/ theorem dist_div_norm_sq_smul {x y : F} (hx : x β‰  0) (hy : y β‰  0) (R : ℝ) : dist ((R / β€–xβ€–) ^ 2 β€’ x) ((R / β€–yβ€–) ^ 2 β€’ y) = R ^ 2 / (β€–xβ€– * β€–yβ€–) * dist x y := calc dist ((R / β€–xβ€–) ^ 2 β€’ x) ((R / β€–yβ€–) ^ 2 β€’ y) = √(β€–(R / β€–xβ€–) ^ 2 β€’ x - (R / β€–yβ€–) ^ 2 β€’ yβ€– ^ 2) := by rw [dist_eq_norm, sqrt_sq (norm_nonneg _)] _ = √((R ^ 2 / (β€–xβ€– * β€–yβ€–)) ^ 2 * β€–x - yβ€– ^ 2) := congr_arg sqrt <| by field_simp [sq, norm_sub_mul_self_real, norm_smul, real_inner_smul_left, inner_smul_right, Real.norm_of_nonneg (mul_self_nonneg _)] ring _ = R ^ 2 / (β€–xβ€– * β€–yβ€–) * dist x y := by rw [sqrt_mul, sqrt_sq, sqrt_sq, dist_eq_norm] <;> positivity /-- The inner product of a nonzero vector with a nonzero multiple of itself, divided by the product of their norms, has absolute value 1. -/ theorem norm_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul {x : E} {r : π•œ} (hx : x β‰  0) (hr : r β‰  0) : β€–βŸͺx, r β€’ xβŸ«β€– / (β€–xβ€– * β€–r β€’ xβ€–) = 1 := by have hx' : β€–xβ€– β‰  0 := by simp [hx] have hr' : β€–rβ€– β‰  0 := by simp [hr] rw [inner_smul_right, norm_mul, ← inner_self_re_eq_norm, inner_self_eq_norm_mul_norm, norm_smul] rw [← mul_assoc, ← div_div, mul_div_cancel_rightβ‚€ _ hx', ← div_div, mul_comm, mul_div_cancel_rightβ‚€ _ hr', div_self hx'] /-- The inner product of a nonzero vector with a nonzero multiple of itself, divided by the product of their norms, has absolute value 1. -/ theorem abs_real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul {x : F} {r : ℝ} (hx : x β‰  0) (hr : r β‰  0) : |βŸͺx, r β€’ x⟫_ℝ| / (β€–xβ€– * β€–r β€’ xβ€–) = 1 := norm_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul hx hr /-- The inner product of a nonzero vector with a positive multiple of itself, divided by the product of their norms, has value 1. -/ theorem real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul {x : F} {r : ℝ} (hx : x β‰  0) (hr : 0 < r) : βŸͺx, r β€’ x⟫_ℝ / (β€–xβ€– * β€–r β€’ xβ€–) = 1 := by rw [real_inner_smul_self_right, norm_smul, Real.norm_eq_abs, ← mul_assoc β€–xβ€–, mul_comm _ |r|, mul_assoc, abs_of_nonneg hr.le, div_self] exact mul_ne_zero hr.ne' (mul_self_ne_zero.2 (norm_ne_zero_iff.2 hx)) /-- The inner product of a nonzero vector with a negative multiple of itself, divided by the product of their norms, has value -1. -/ theorem real_inner_div_norm_mul_norm_eq_neg_one_of_ne_zero_of_neg_mul {x : F} {r : ℝ} (hx : x β‰  0) (hr : r < 0) : βŸͺx, r β€’ x⟫_ℝ / (β€–xβ€– * β€–r β€’ xβ€–) = -1 := by rw [real_inner_smul_self_right, norm_smul, Real.norm_eq_abs, ← mul_assoc β€–xβ€–, mul_comm _ |r|, mul_assoc, abs_of_neg hr, neg_mul, div_neg_eq_neg_div, div_self] exact mul_ne_zero hr.ne (mul_self_ne_zero.2 (norm_ne_zero_iff.2 hx)) theorem norm_inner_eq_norm_tfae (x y : E) : List.TFAE [β€–βŸͺx, yβŸ«β€– = β€–xβ€– * β€–yβ€–, x = 0 ∨ y = (βŸͺx, y⟫ / βŸͺx, x⟫) β€’ x, x = 0 ∨ βˆƒ r : π•œ, y = r β€’ x, x = 0 ∨ y ∈ π•œ βˆ™ x] := by tfae_have 1 β†’ 2 := by refine fun h => or_iff_not_imp_left.2 fun hxβ‚€ => ?_ have : β€–xβ€– ^ 2 β‰  0 := pow_ne_zero _ (norm_ne_zero_iff.2 hxβ‚€) rw [← sq_eq_sqβ‚€, mul_pow, ← mul_right_inj' this, eq_comm, ← sub_eq_zero, ← mul_sub] at h <;> try positivity simp only [@norm_sq_eq_re_inner π•œ] at h letI : InnerProductSpace.Core π•œ E := InnerProductSpace.toCore erw [← InnerProductSpace.Core.cauchy_schwarz_aux (π•œ := π•œ) (F := E)] at h rw [InnerProductSpace.Core.normSq_eq_zero, sub_eq_zero] at h rw [div_eq_inv_mul, mul_smul, h, inv_smul_smulβ‚€] rwa [inner_self_ne_zero] tfae_have 2 β†’ 3 := fun h => h.imp_right fun h' => ⟨_, h'⟩ tfae_have 3 β†’ 1 := by rintro (rfl | ⟨r, rfl⟩) <;> simp [inner_smul_right, norm_smul, inner_self_eq_norm_sq_to_K, inner_self_eq_norm_mul_norm, sq, mul_left_comm] tfae_have 3 ↔ 4 := by simp only [Submodule.mem_span_singleton, eq_comm] tfae_finish /-- If the inner product of two vectors is equal to the product of their norms, then the two vectors are multiples of each other. One form of the equality case for Cauchy-Schwarz. Compare `inner_eq_norm_mul_iff`, which takes the stronger hypothesis `βŸͺx, y⟫ = β€–xβ€– * β€–yβ€–`. -/ theorem norm_inner_eq_norm_iff {x y : E} (hxβ‚€ : x β‰  0) (hyβ‚€ : y β‰  0) : β€–βŸͺx, yβŸ«β€– = β€–xβ€– * β€–yβ€– ↔ βˆƒ r : π•œ, r β‰  0 ∧ y = r β€’ x := calc β€–βŸͺx, yβŸ«β€– = β€–xβ€– * β€–yβ€– ↔ x = 0 ∨ βˆƒ r : π•œ, y = r β€’ x := (@norm_inner_eq_norm_tfae π•œ _ _ _ _ x y).out 0 2 _ ↔ βˆƒ r : π•œ, y = r β€’ x := or_iff_right hxβ‚€ _ ↔ βˆƒ r : π•œ, r β‰  0 ∧ y = r β€’ x := ⟨fun ⟨r, h⟩ => ⟨r, fun hrβ‚€ => hyβ‚€ <| h.symm β–Έ smul_eq_zero.2 <| Or.inl hrβ‚€, h⟩, fun ⟨r, _hrβ‚€, h⟩ => ⟨r, h⟩⟩ /-- The inner product of two vectors, divided by the product of their norms, has absolute value 1 if and only if they are nonzero and one is a multiple of the other. One form of equality case for Cauchy-Schwarz. -/ theorem norm_inner_div_norm_mul_norm_eq_one_iff (x y : E) : β€–βŸͺx, y⟫ / (β€–xβ€– * β€–yβ€–)β€– = 1 ↔ x β‰  0 ∧ βˆƒ r : π•œ, r β‰  0 ∧ y = r β€’ x := by constructor Β· intro h have hxβ‚€ : x β‰  0 := fun hβ‚€ => by simp [hβ‚€] at h have hyβ‚€ : y β‰  0 := fun hβ‚€ => by simp [hβ‚€] at h refine ⟨hxβ‚€, (norm_inner_eq_norm_iff hxβ‚€ hyβ‚€).1 <| eq_of_div_eq_one ?_⟩ simpa using h Β· rintro ⟨hx, ⟨r, ⟨hr, rfl⟩⟩⟩ simp only [norm_div, norm_mul, norm_ofReal, abs_norm] exact norm_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul hx hr /-- The inner product of two vectors, divided by the product of their norms, has absolute value 1 if and only if they are nonzero and one is a multiple of the other. One form of equality case for Cauchy-Schwarz. -/ theorem abs_real_inner_div_norm_mul_norm_eq_one_iff (x y : F) : |βŸͺx, y⟫_ℝ / (β€–xβ€– * β€–yβ€–)| = 1 ↔ x β‰  0 ∧ βˆƒ r : ℝ, r β‰  0 ∧ y = r β€’ x := @norm_inner_div_norm_mul_norm_eq_one_iff ℝ F _ _ _ x y theorem inner_eq_norm_mul_iff_div {x y : E} (hβ‚€ : x β‰  0) : βŸͺx, y⟫ = (β€–xβ€– : π•œ) * β€–yβ€– ↔ (β€–yβ€– / β€–xβ€– : π•œ) β€’ x = y := by have hβ‚€' := hβ‚€ rw [← norm_ne_zero_iff, Ne, ← @ofReal_eq_zero π•œ] at hβ‚€' constructor <;> intro h Β· have : x = 0 ∨ y = (βŸͺx, y⟫ / βŸͺx, x⟫ : π•œ) β€’ x := ((@norm_inner_eq_norm_tfae π•œ _ _ _ _ x y).out 0 1).1 (by simp [h]) rw [this.resolve_left hβ‚€, h] simp [norm_smul, inner_self_ofReal_norm, mul_div_cancel_rightβ‚€ _ hβ‚€'] Β· conv_lhs => rw [← h, inner_smul_right, inner_self_eq_norm_sq_to_K] field_simp [sq, mul_left_comm] /-- If the inner product of two vectors is equal to the product of their norms (i.e., `βŸͺx, y⟫ = β€–xβ€– * β€–yβ€–`), then the two vectors are nonnegative real multiples of each other. One form of the equality case for Cauchy-Schwarz. Compare `norm_inner_eq_norm_iff`, which takes the weaker hypothesis `abs βŸͺx, y⟫ = β€–xβ€– * β€–yβ€–`. -/ theorem inner_eq_norm_mul_iff {x y : E} : βŸͺx, y⟫ = (β€–xβ€– : π•œ) * β€–yβ€– ↔ (β€–yβ€– : π•œ) β€’ x = (β€–xβ€– : π•œ) β€’ y := by rcases eq_or_ne x 0 with (rfl | hβ‚€) Β· simp Β· rw [inner_eq_norm_mul_iff_div hβ‚€, div_eq_inv_mul, mul_smul, inv_smul_eq_iffβ‚€] rwa [Ne, ofReal_eq_zero, norm_eq_zero] /-- If the inner product of two vectors is equal to the product of their norms (i.e., `βŸͺx, y⟫ = β€–xβ€– * β€–yβ€–`), then the two vectors are nonnegative real multiples of each other. One form of the equality case for Cauchy-Schwarz. Compare `norm_inner_eq_norm_iff`, which takes the weaker hypothesis `abs βŸͺx, y⟫ = β€–xβ€– * β€–yβ€–`. -/ theorem inner_eq_norm_mul_iff_real {x y : F} : βŸͺx, y⟫_ℝ = β€–xβ€– * β€–yβ€– ↔ β€–yβ€– β€’ x = β€–xβ€– β€’ y := inner_eq_norm_mul_iff /-- The inner product of two vectors, divided by the product of their norms, has value 1 if and only if they are nonzero and one is a positive multiple of the other. -/ theorem real_inner_div_norm_mul_norm_eq_one_iff (x y : F) : βŸͺx, y⟫_ℝ / (β€–xβ€– * β€–yβ€–) = 1 ↔ x β‰  0 ∧ βˆƒ r : ℝ, 0 < r ∧ y = r β€’ x := by constructor Β· intro h have hxβ‚€ : x β‰  0 := fun hβ‚€ => by simp [hβ‚€] at h have hyβ‚€ : y β‰  0 := fun hβ‚€ => by simp [hβ‚€] at h refine ⟨hxβ‚€, β€–yβ€– / β€–xβ€–, div_pos (norm_pos_iff.2 hyβ‚€) (norm_pos_iff.2 hxβ‚€), ?_⟩ exact ((inner_eq_norm_mul_iff_div hxβ‚€).1 (eq_of_div_eq_one h)).symm Β· rintro ⟨hx, ⟨r, ⟨hr, rfl⟩⟩⟩ exact real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul hx hr /-- The inner product of two vectors, divided by the product of their norms, has value -1 if and only if they are nonzero and one is a negative multiple of the other. -/ theorem real_inner_div_norm_mul_norm_eq_neg_one_iff (x y : F) : βŸͺx, y⟫_ℝ / (β€–xβ€– * β€–yβ€–) = -1 ↔ x β‰  0 ∧ βˆƒ r : ℝ, r < 0 ∧ y = r β€’ x := by rw [← neg_eq_iff_eq_neg, ← neg_div, ← inner_neg_right, ← norm_neg y, real_inner_div_norm_mul_norm_eq_one_iff, (@neg_surjective ℝ _).exists] refine Iff.rfl.and (exists_congr fun r => ?_) rw [neg_pos, neg_smul, neg_inj] /-- If the inner product of two unit vectors is `1`, then the two vectors are equal. One form of the equality case for Cauchy-Schwarz. -/ theorem inner_eq_one_iff_of_norm_one {x y : E} (hx : β€–xβ€– = 1) (hy : β€–yβ€– = 1) : βŸͺx, y⟫ = 1 ↔ x = y := by convert inner_eq_norm_mul_iff (π•œ := π•œ) (E := E) using 2 <;> simp [hx, hy] theorem inner_lt_norm_mul_iff_real {x y : F} : βŸͺx, y⟫_ℝ < β€–xβ€– * β€–yβ€– ↔ β€–yβ€– β€’ x β‰  β€–xβ€– β€’ y := calc βŸͺx, y⟫_ℝ < β€–xβ€– * β€–yβ€– ↔ βŸͺx, y⟫_ℝ β‰  β€–xβ€– * β€–yβ€– := ⟨ne_of_lt, lt_of_le_of_ne (real_inner_le_norm _ _)⟩ _ ↔ β€–yβ€– β€’ x β‰  β€–xβ€– β€’ y := not_congr inner_eq_norm_mul_iff_real /-- If the inner product of two unit vectors is strictly less than `1`, then the two vectors are distinct. One form of the equality case for Cauchy-Schwarz. -/ theorem inner_lt_one_iff_real_of_norm_one {x y : F} (hx : β€–xβ€– = 1) (hy : β€–yβ€– = 1) : βŸͺx, y⟫_ℝ < 1 ↔ x β‰  y := by convert inner_lt_norm_mul_iff_real (F := F) <;> simp [hx, hy] /-- The sphere of radius `r = β€–yβ€–` is tangent to the plane `βŸͺx, y⟫ = β€–yβ€– ^ 2` at `x = y`. -/ theorem eq_of_norm_le_re_inner_eq_norm_sq {x y : E} (hle : β€–xβ€– ≀ β€–yβ€–) (h : re βŸͺx, y⟫ = β€–yβ€– ^ 2) : x = y := by suffices H : re βŸͺx - y, x - y⟫ ≀ 0 by rwa [re_inner_self_nonpos, sub_eq_zero] at H have H₁ : β€–xβ€– ^ 2 ≀ β€–yβ€– ^ 2 := by gcongr have Hβ‚‚ : re βŸͺy, x⟫ = β€–yβ€– ^ 2 := by rwa [← inner_conj_symm, conj_re] simpa [inner_sub_left, inner_sub_right, ← norm_sq_eq_re_inner, h, Hβ‚‚] using H₁ end Norm section RCLike local notation "βŸͺ" x ", " y "⟫" => @inner π•œ _ _ x y /-- A field `π•œ` satisfying `RCLike` is itself a `π•œ`-inner product space. -/ instance RCLike.innerProductSpace : InnerProductSpace π•œ π•œ where inner x y := y * conj x norm_sq_eq_re_inner x := by simp only [inner, mul_conj, ← ofReal_pow, ofReal_re] conj_inner_symm x y := by simp only [mul_comm, map_mul, starRingEnd_self_apply] add_left x y z := by simp only [mul_add, map_add] smul_left x y z := by simp only [mul_comm (conj z), mul_assoc, smul_eq_mul, map_mul] @[simp] theorem RCLike.inner_apply (x y : π•œ) : βŸͺx, y⟫ = y * conj x := rfl /-- A version of `RCLike.inner_apply` that swaps the order of multiplication. -/ theorem RCLike.inner_apply' (x y : π•œ) : βŸͺx, y⟫ = conj x * y := mul_comm _ _ end RCLike section RCLikeToReal open scoped InnerProductSpace variable {G : Type*} variable (π•œ E) variable [SeminormedAddCommGroup E] [InnerProductSpace π•œ E] local notation "βŸͺ" x ", " y "⟫" => @inner π•œ _ _ x y /-- A general inner product implies a real inner product. This is not registered as an instance since `π•œ` does not appear in the return type `Inner ℝ E`. -/ def Inner.rclikeToReal : Inner ℝ E where inner x y := re βŸͺx, y⟫ /-- A general inner product space structure implies a real inner product structure. This is not registered as an instance since * `π•œ` does not appear in the return type `InnerProductSpace ℝ E`, * It is likely to create instance diamonds, as it builds upon the diamond-prone `NormedSpace.restrictScalars`. However, it can be used in a proof to obtain a real inner product space structure from a given `π•œ`-inner product space structure. -/ -- See note [reducible non instances] abbrev InnerProductSpace.rclikeToReal : InnerProductSpace ℝ E := { Inner.rclikeToReal π•œ E, NormedSpace.restrictScalars ℝ π•œ E with norm_sq_eq_re_inner := norm_sq_eq_re_inner conj_inner_symm := fun _ _ => inner_re_symm _ _ add_left := fun x y z => by change re βŸͺx + y, z⟫ = re βŸͺx, z⟫ + re βŸͺy, z⟫ simp only [inner_add_left, map_add] smul_left := fun x y r => by change re βŸͺ(r : π•œ) β€’ x, y⟫ = r * re βŸͺx, y⟫ simp only [inner_smul_left, conj_ofReal, re_ofReal_mul] } variable {E} theorem real_inner_eq_re_inner (x y : E) : @Inner.inner ℝ E (Inner.rclikeToReal π•œ E) x y = re βŸͺx, y⟫ := rfl theorem real_inner_I_smul_self (x : E) : @Inner.inner ℝ E (Inner.rclikeToReal π•œ E) x ((I : π•œ) β€’ x) = 0 := by simp [real_inner_eq_re_inner π•œ, inner_smul_right] /-- A complex inner product implies a real inner product. This cannot be an instance since it creates a diamond with `PiLp.innerProductSpace` because `re (sum i, inner (x i) (y i))` and `sum i, re (inner (x i) (y i))` are not defeq. -/ def InnerProductSpace.complexToReal [SeminormedAddCommGroup G] [InnerProductSpace β„‚ G] : InnerProductSpace ℝ G := InnerProductSpace.rclikeToReal β„‚ G instance : InnerProductSpace ℝ β„‚ := InnerProductSpace.complexToReal @[simp] protected theorem Complex.inner (w z : β„‚) : βŸͺw, z⟫_ℝ = (z * conj w).re := rfl end RCLikeToReal /-- An `RCLike` field is a real inner product space. -/ noncomputable instance RCLike.toInnerProductSpaceReal : InnerProductSpace ℝ π•œ where __ := Inner.rclikeToReal π•œ π•œ norm_sq_eq_re_inner := norm_sq_eq_re_inner conj_inner_symm x y := inner_re_symm .. add_left x y z := show re (_ * _) = re (_ * _) + re (_ * _) by simp only [map_add, mul_re, conj_re, conj_im]; ring smul_left x y r := show re (_ * _) = _ * re (_ * _) by simp only [mul_re, conj_re, conj_im, conj_trivial, smul_re, smul_im]; ring -- The instance above does not create diamonds for concrete `π•œ`: example : (innerProductSpace : InnerProductSpace ℝ ℝ) = RCLike.toInnerProductSpaceReal := rfl example : (instInnerProductSpaceRealComplex : InnerProductSpace ℝ β„‚) = RCLike.toInnerProductSpaceReal := rfl
Mathlib/Analysis/InnerProductSpace/Basic.lean
902
910
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.CharP.Reduced import Mathlib.RingTheory.IntegralDomain -- TODO: remove Mathlib.Algebra.CharP.Reduced and move the last two lemmas to Lemmas /-! # Roots of unity We define roots of unity in the context of an arbitrary commutative monoid, as a subgroup of the group of units. ## Main definitions * `rootsOfUnity n M`, for `n : β„•` is the subgroup of the units of a commutative monoid `M` consisting of elements `x` that satisfy `x ^ n = 1`. ## Main results * `rootsOfUnity.isCyclic`: the roots of unity in an integral domain form a cyclic group. ## Implementation details It is desirable that `rootsOfUnity` is a subgroup, and it will mainly be applied to rings (e.g. the ring of integers in a number field) and fields. We therefore implement it as a subgroup of the units of a commutative monoid. We have chosen to define `rootsOfUnity n` for `n : β„•` and add a `[NeZero n]` typeclass assumption when we need `n` to be non-zero (which is the case for most interesting statements). Note that `rootsOfUnity 0 M` is the top subgroup of `MΛ£` (as the condition `ΞΆ^0 = 1` is satisfied for all units). -/ noncomputable section open Polynomial open Finset variable {M N G R S F : Type*} variable [CommMonoid M] [CommMonoid N] [DivisionCommMonoid G] section rootsOfUnity variable {k l : β„•} /-- `rootsOfUnity k M` is the subgroup of elements `m : MΛ£` that satisfy `m ^ k = 1`. -/ def rootsOfUnity (k : β„•) (M : Type*) [CommMonoid M] : Subgroup MΛ£ where carrier := {ΞΆ | ΞΆ ^ k = 1} one_mem' := one_pow _ mul_mem' _ _ := by simp_all only [Set.mem_setOf_eq, mul_pow, one_mul] inv_mem' _ := by simp_all only [Set.mem_setOf_eq, inv_pow, inv_one] @[simp] theorem mem_rootsOfUnity (k : β„•) (ΞΆ : MΛ£) : ΞΆ ∈ rootsOfUnity k M ↔ ΞΆ ^ k = 1 := Iff.rfl /-- A variant of `mem_rootsOfUnity` using `ΞΆ : MΛ£`. -/ theorem mem_rootsOfUnity' (k : β„•) (ΞΆ : MΛ£) : ΞΆ ∈ rootsOfUnity k M ↔ (ΞΆ : M) ^ k = 1 := by rw [mem_rootsOfUnity]; norm_cast @[simp] theorem rootsOfUnity_one (M : Type*) [CommMonoid M] : rootsOfUnity 1 M = βŠ₯ := by ext1 simp only [mem_rootsOfUnity, pow_one, Subgroup.mem_bot] @[simp] lemma rootsOfUnity_zero (M : Type*) [CommMonoid M] : rootsOfUnity 0 M = ⊀ := by ext1 simp only [mem_rootsOfUnity, pow_zero, Subgroup.mem_top] theorem rootsOfUnity.coe_injective {n : β„•} : Function.Injective (fun x : rootsOfUnity n M ↦ x.val.val) := Units.ext.comp fun _ _ ↦ Subtype.eq /-- Make an element of `rootsOfUnity` from a member of the base ring, and a proof that it has a positive power equal to one. -/ @[simps! coe_val] def rootsOfUnity.mkOfPowEq (ΞΆ : M) {n : β„•} [NeZero n] (h : ΞΆ ^ n = 1) : rootsOfUnity n M := ⟨Units.ofPowEqOne ΞΆ n h <| NeZero.ne n, Units.pow_ofPowEqOne _ _⟩ @[simp] theorem rootsOfUnity.coe_mkOfPowEq {ΞΆ : M} {n : β„•} [NeZero n] (h : ΞΆ ^ n = 1) : ((rootsOfUnity.mkOfPowEq _ h : MΛ£) : M) = ΞΆ := rfl theorem rootsOfUnity_le_of_dvd (h : k ∣ l) : rootsOfUnity k M ≀ rootsOfUnity l M := by obtain ⟨d, rfl⟩ := h intro ΞΆ h simp_all only [mem_rootsOfUnity, pow_mul, one_pow] theorem map_rootsOfUnity (f : MΛ£ β†’* NΛ£) (k : β„•) : (rootsOfUnity k M).map f ≀ rootsOfUnity k N := by rintro _ ⟨΢, h, rfl⟩ simp_all only [← map_pow, mem_rootsOfUnity, SetLike.mem_coe, MonoidHom.map_one] @[norm_cast] theorem rootsOfUnity.coe_pow [CommMonoid R] (ΞΆ : rootsOfUnity k R) (m : β„•) : (((ΞΆ ^ m :) : RΛ£) : R) = ((ΞΆ : RΛ£) : R) ^ m := by rw [Subgroup.coe_pow, Units.val_pow_eq_pow_val] /-- The canonical isomorphism from the `n`th roots of unity in `MΛ£` to the `n`th roots of unity in `M`. -/ def rootsOfUnityUnitsMulEquiv (M : Type*) [CommMonoid M] (n : β„•) : rootsOfUnity n MΛ£ ≃* rootsOfUnity n M where toFun ΞΆ := ⟨΢.val, (mem_rootsOfUnity ..).mpr <| (mem_rootsOfUnity' ..).mp ΞΆ.prop⟩ invFun ΞΆ := ⟨toUnits ΞΆ.val, by simp only [mem_rootsOfUnity, ← map_pow, EmbeddingLike.map_eq_one_iff] exact (mem_rootsOfUnity ..).mp ΞΆ.prop⟩ left_inv ΞΆ := by simp only [toUnits_val_apply, Subtype.coe_eta] right_inv ΞΆ := by simp only [val_toUnits_apply, Subtype.coe_eta] map_mul' ΞΆ ΞΆ' := by simp only [Subgroup.coe_mul, Units.val_mul, MulMemClass.mk_mul_mk] section CommMonoid variable [CommMonoid R] [CommMonoid S] [FunLike F R S] /-- Restrict a ring homomorphism to the nth roots of unity. -/ def restrictRootsOfUnity [MonoidHomClass F R S] (Οƒ : F) (n : β„•) : rootsOfUnity n R β†’* rootsOfUnity n S := { toFun := fun ΞΎ ↦ ⟨Units.map Οƒ (ΞΎ : RΛ£), by rw [mem_rootsOfUnity, ← map_pow, Units.ext_iff, Units.coe_map, ΞΎ.prop] exact map_one ΟƒβŸ© map_one' := by ext1; simp only [OneMemClass.coe_one, map_one] map_mul' := fun ξ₁ ΞΎβ‚‚ ↦ by ext1; simp only [Subgroup.coe_mul, map_mul, MulMemClass.mk_mul_mk] } @[simp] theorem restrictRootsOfUnity_coe_apply [MonoidHomClass F R S] (Οƒ : F) (ΞΆ : rootsOfUnity k R) : (restrictRootsOfUnity Οƒ k ΞΆ : SΛ£) = Οƒ (ΞΆ : RΛ£) := rfl /-- Restrict a monoid isomorphism to the nth roots of unity. -/ nonrec def MulEquiv.restrictRootsOfUnity (Οƒ : R ≃* S) (n : β„•) : rootsOfUnity n R ≃* rootsOfUnity n S where toFun := restrictRootsOfUnity Οƒ n invFun := restrictRootsOfUnity Οƒ.symm n left_inv ΞΎ := by ext; exact Οƒ.symm_apply_apply _ right_inv ΞΎ := by ext; exact Οƒ.apply_symm_apply _ map_mul' := (restrictRootsOfUnity _ n).map_mul @[simp] theorem MulEquiv.restrictRootsOfUnity_coe_apply (Οƒ : R ≃* S) (ΞΆ : rootsOfUnity k R) : (Οƒ.restrictRootsOfUnity k ΞΆ : SΛ£) = Οƒ (ΞΆ : RΛ£) := rfl @[simp] theorem MulEquiv.restrictRootsOfUnity_symm (Οƒ : R ≃* S) : (Οƒ.restrictRootsOfUnity k).symm = Οƒ.symm.restrictRootsOfUnity k := rfl end CommMonoid section IsDomain -- The following results need `k` to be nonzero. variable [NeZero k] [CommRing R] [IsDomain R] theorem mem_rootsOfUnity_iff_mem_nthRoots {ΞΆ : RΛ£} : ΞΆ ∈ rootsOfUnity k R ↔ (ΞΆ : R) ∈ nthRoots k (1 : R) := by simp only [mem_rootsOfUnity, mem_nthRoots (NeZero.pos k), Units.ext_iff, Units.val_one, Units.val_pow_eq_pow_val] variable (k R) /-- Equivalence between the `k`-th roots of unity in `R` and the `k`-th roots of `1`. This is implemented as equivalence of subtypes, because `rootsOfUnity` is a subgroup of the group of units, whereas `nthRoots` is a multiset. -/ def rootsOfUnityEquivNthRoots : rootsOfUnity k R ≃ { x // x ∈ nthRoots k (1 : R) } where toFun x := ⟨(x : RΛ£), mem_rootsOfUnity_iff_mem_nthRoots.mp x.2⟩ invFun x := by refine ⟨⟨x, ↑x ^ (k - 1 : β„•), ?_, ?_⟩, ?_⟩ all_goals rcases x with ⟨x, hx⟩; rw [mem_nthRoots <| NeZero.pos k] at hx simp only [← pow_succ, ← pow_succ', hx, tsub_add_cancel_of_le NeZero.one_le] simp only [mem_rootsOfUnity, Units.ext_iff, Units.val_pow_eq_pow_val, hx, Units.val_one] left_inv := by rintro ⟨x, hx⟩; ext; rfl right_inv := by rintro ⟨x, hx⟩; ext; rfl variable {k R} @[simp] theorem rootsOfUnityEquivNthRoots_apply (x : rootsOfUnity k R) : (rootsOfUnityEquivNthRoots R k x : R) = ((x : RΛ£) : R) := rfl @[simp] theorem rootsOfUnityEquivNthRoots_symm_apply (x : { x // x ∈ nthRoots k (1 : R) }) : (((rootsOfUnityEquivNthRoots R k).symm x : RΛ£) : R) = (x : R) := rfl variable (k R) instance rootsOfUnity.fintype : Fintype (rootsOfUnity k R) := by classical exact Fintype.ofEquiv { x // x ∈ nthRoots k (1 : R) } (rootsOfUnityEquivNthRoots R k).symm instance rootsOfUnity.isCyclic : IsCyclic (rootsOfUnity k R) := isCyclic_of_subgroup_isDomain ((Units.coeHom R).comp (rootsOfUnity k R).subtype) coe_injective theorem card_rootsOfUnity : Fintype.card (rootsOfUnity k R) ≀ k := by classical calc Fintype.card (rootsOfUnity k R) = Fintype.card { x // x ∈ nthRoots k (1 : R) } := Fintype.card_congr (rootsOfUnityEquivNthRoots R k) _ ≀ Multiset.card (nthRoots k (1 : R)).attach := Multiset.card_le_card (Multiset.dedup_le _) _ = Multiset.card (nthRoots k (1 : R)) := Multiset.card_attach _ ≀ k := card_nthRoots k 1 variable {k R} theorem map_rootsOfUnity_eq_pow_self [FunLike F R R] [MonoidHomClass F R R] (Οƒ : F) (ΞΆ : rootsOfUnity k R) : βˆƒ m : β„•, Οƒ (ΞΆ : RΛ£) = ((ΞΆ : RΛ£) : R) ^ m := by obtain ⟨m, hm⟩ := MonoidHom.map_cyclic (restrictRootsOfUnity Οƒ k) rw [← restrictRootsOfUnity_coe_apply, hm, ← zpow_mod_orderOf, ← Int.toNat_of_nonneg (m.emod_nonneg (Int.natCast_ne_zero.mpr (pos_iff_ne_zero.mp (orderOf_pos ΞΆ)))), zpow_natCast, rootsOfUnity.coe_pow] exact ⟨(m % orderOf ΞΆ).toNat, rfl⟩ end IsDomain section Reduced variable (R) [CommRing R] [IsReduced R] -- @[simp] -- Porting note: simp normal form is `mem_rootsOfUnity_prime_pow_mul_iff'` theorem mem_rootsOfUnity_prime_pow_mul_iff (p k : β„•) (m : β„•) [ExpChar R p] {ΞΆ : RΛ£} : ΞΆ ∈ rootsOfUnity (p ^ k * m) R ↔ ΞΆ ∈ rootsOfUnity m R := by simp only [mem_rootsOfUnity', ExpChar.pow_prime_pow_mul_eq_one_iff] /-- A variant of `mem_rootsOfUnity_prime_pow_mul_iff` in terms of `ΞΆ ^ _` -/ @[simp] theorem mem_rootsOfUnity_prime_pow_mul_iff' (p k : β„•) (m : β„•) [ExpChar R p] {ΞΆ : RΛ£} : ΞΆ ^ (p ^ k * m) = 1 ↔ ΞΆ ∈ rootsOfUnity m R := by rw [← mem_rootsOfUnity, mem_rootsOfUnity_prime_pow_mul_iff] end Reduced end rootsOfUnity section cyclic namespace IsCyclic /-- The isomorphism from the group of group homomorphisms from a finite cyclic group `G` of order `n` into another group `G'` to the group of `n`th roots of unity in `G'` determined by a generator `g` of `G`. It sends `Ο† : G β†’* G'` to `Ο† g`. -/ noncomputable def monoidHomMulEquivRootsOfUnityOfGenerator {G : Type*} [CommGroup G] {g : G} (hg : βˆ€ (x : G), x ∈ Subgroup.zpowers g) (G' : Type*) [CommGroup G'] : (G β†’* G') ≃* rootsOfUnity (Nat.card G) G' where toFun Ο† := ⟨(IsUnit.map Ο† <| Group.isUnit g).unit, by simp only [mem_rootsOfUnity, Units.ext_iff, Units.val_pow_eq_pow_val, IsUnit.unit_spec, ← map_pow, pow_card_eq_one', map_one, Units.val_one]⟩ invFun ΞΆ := monoidHomOfForallMemZpowers hg (g' := (ΞΆ.val : G')) <| by simpa only [orderOf_eq_card_of_forall_mem_zpowers hg, orderOf_dvd_iff_pow_eq_one, ← Units.val_pow_eq_pow_val, Units.val_eq_one] using ΞΆ.prop left_inv Ο† := (MonoidHom.eq_iff_eq_on_generator hg _ Ο†).mpr <| by simp only [IsUnit.unit_spec, monoidHomOfForallMemZpowers_apply_gen] right_inv Ο† := Subtype.ext <| by simp only [monoidHomOfForallMemZpowers_apply_gen, IsUnit.unit_of_val_units] map_mul' x y := by simp only [MonoidHom.mul_apply, MulMemClass.mk_mul_mk, Subtype.mk.injEq, Units.ext_iff, IsUnit.unit_spec, Units.val_mul] /-- The group of group homomorphisms from a finite cyclic group `G` of order `n` into another group `G'` is (noncanonically) isomorphic to the group of `n`th roots of unity in `G'`. -/ lemma monoidHom_mulEquiv_rootsOfUnity (G : Type*) [CommGroup G] [IsCyclic G] (G' : Type*) [CommGroup G'] : Nonempty <| (G β†’* G') ≃* rootsOfUnity (Nat.card G) G' := by obtain ⟨g, hg⟩ := IsCyclic.exists_generator (Ξ± := G) exact ⟨monoidHomMulEquivRootsOfUnityOfGenerator hg G'⟩ end IsCyclic end cyclic
Mathlib/RingTheory/RootsOfUnity/Basic.lean
779
790
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Algebra.BigOperators.Field import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`. -/ @[pp_nodot] noncomputable def logb (b x : ℝ) : ℝ := log x / log b theorem log_div_log : log x / log b = logb b x := rfl @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] @[simp]
theorem logb_one : logb b 1 = 0 := by simp [logb]
Mathlib/Analysis/SpecialFunctions/Log/Base.lean
49
49
/- 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.Data.ENNReal.Action import Mathlib.MeasureTheory.MeasurableSpace.Constructions import Mathlib.MeasureTheory.OuterMeasure.Caratheodory /-! # Induced Outer Measure We can extend a function defined on a subset of `Set Ξ±` to an outer measure. The underlying function is called `extend`, and the measure it induces is called `inducedOuterMeasure`. Some lemmas below are proven twice, once in the general case, and one where the function `m` is only defined on measurable sets (i.e. when `P = MeasurableSet`). In the latter cases, we can remove some hypotheses in the statement. The general version has the same name, but with a prime at the end. ## Tags outer measure -/ noncomputable section open Set Function Filter open scoped NNReal Topology ENNReal namespace MeasureTheory open OuterMeasure section Extend variable {Ξ± : Type*} {P : Ξ± β†’ Prop} variable (m : βˆ€ s : Ξ±, P s β†’ ℝβ‰₯0∞) /-- We can trivially extend a function defined on a subclass of objects (with codomain `ℝβ‰₯0∞`) to all objects by defining it to be `∞` on the objects not in the class. -/ def extend (s : Ξ±) : ℝβ‰₯0∞ := β¨… h : P s, m s h theorem extend_eq {s : Ξ±} (h : P s) : extend m s = m s h := by simp [extend, h] theorem extend_eq_top {s : Ξ±} (h : Β¬P s) : extend m s = ∞ := by simp [extend, h] theorem smul_extend {R} [Zero R] [SMulWithZero R ℝβ‰₯0∞] [IsScalarTower R ℝβ‰₯0∞ ℝβ‰₯0∞] [NoZeroSMulDivisors R ℝβ‰₯0∞] {c : R} (hc : c β‰  0) : c β€’ extend m = extend fun s h => c β€’ m s h := by classical ext1 s dsimp [extend] by_cases h : P s Β· simp [h] Β· simp [h, ENNReal.smul_top, hc] theorem le_extend {s : Ξ±} (h : P s) : m s h ≀ extend m s := by simp only [extend, le_iInf_iff] intro
rfl -- TODO: why this is a bad `congr` lemma? theorem extend_congr {Ξ² : Type*} {Pb : Ξ² β†’ Prop} {mb : βˆ€ s : Ξ², Pb s β†’ ℝβ‰₯0∞} {sa : Ξ±} {sb : Ξ²}
Mathlib/MeasureTheory/OuterMeasure/Induced.lean
65
68
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, JoΓ«l Riou -/ import Mathlib.CategoryTheory.Comma.Presheaf.Basic import Mathlib.CategoryTheory.Elements import Mathlib.CategoryTheory.Functor.KanExtension.Adjunction import Mathlib.CategoryTheory.Limits.Final import Mathlib.CategoryTheory.Limits.Over /-! # Colimit of representables This file constructs an adjunction `Presheaf.yonedaAdjunction` between `(Cα΅’α΅– β₯€ Type u)` and `β„°` given a functor `A : C β₯€ β„°`, where the right adjoint `restrictedYoneda` sends `(E : β„°)` to `c ↦ (A.obj c ⟢ E)`, and the left adjoint `(Cα΅’α΅– β₯€ Type v₁) β₯€ β„°` is a pointwise left Kan extension of `A` along the Yoneda embedding, which exists provided `β„°` has colimits) We also show that every presheaf is a colimit of representables. This result is also known as the density theorem, the co-Yoneda lemma and the Ninja Yoneda lemma. Two formulations are given: * `colimitOfRepresentable` uses the category of elements of a functor to types; * `isColimitTautologicalCocone` uses the category of costructured arrows. In the lemma `isLeftKanExtension_along_yoneda_iff`, we show that if `L : (Cα΅’α΅– β₯€ Type v₁) β₯€ β„°)` and `Ξ± : A ⟢ yoneda β‹™ L`, then `Ξ±` makes `L` the left Kan extension of `L` along yoneda if and only if `Ξ±` is an isomorphism (i.e. `L` extends `A`) and `L` preserves colimits. `uniqueExtensionAlongYoneda` shows `yoneda.leftKanExtension A` is unique amongst functors preserving colimits with this property, establishing the presheaf category as the free cocompletion of a category. Given a functor `F : C β₯€ D`, we also show construct an isomorphism `compYonedaIsoYonedaCompLan : F β‹™ yoneda β‰… yoneda β‹™ F.op.lan`, and show that it makes `F.op.lan` a left Kan extension of `F β‹™ yoneda`. ## Tags colimit, representable, presheaf, free cocompletion ## References * [S. MacLane, I. Moerdijk, *Sheaves in Geometry and Logic*][MM92] * https://ncatlab.org/nlab/show/Yoneda+extension -/ namespace CategoryTheory open Category Limits universe v₁ vβ‚‚ v₃ u₁ uβ‚‚ u₃ namespace Presheaf variable {C : Type u₁} [Category.{v₁} C] variable {β„° : Type uβ‚‚} [Category.{v₁} β„°] (A : C β₯€ β„°) /-- The functor taking `(E : β„°) (c : Cα΅’α΅–)` to the homset `(A.obj C ⟢ E)`. It is shown in `L_adjunction` that this functor has a left adjoint (provided `E` has colimits) given by taking colimits over categories of elements. In the case where `β„° = Cα΅’α΅– β₯€ Type u` and `A = yoneda`, this functor is isomorphic to the identity. Defined as in [MM92], Chapter I, Section 5, Theorem 2. -/ @[simps!] def restrictedYoneda : β„° β₯€ Cα΅’α΅– β₯€ Type v₁ := yoneda β‹™ (whiskeringLeft _ _ (Type v₁)).obj (Functor.op A) /-- Auxiliary definition for `restrictedYonedaHomEquiv`. -/ def restrictedYonedaHomEquiv' (P : Cα΅’α΅– β₯€ Type v₁) (E : β„°) : (CostructuredArrow.proj yoneda P β‹™ A ⟢ (Functor.const (CostructuredArrow yoneda P)).obj E) ≃ (P ⟢ (restrictedYoneda A).obj E) where toFun f := { app := fun _ x => f.app (CostructuredArrow.mk (yonedaEquiv.symm x)) naturality := fun {X₁ Xβ‚‚} Ο† => by ext x let ψ : CostructuredArrow.mk (yonedaEquiv.symm (P.toPrefunctor.map Ο† x)) ⟢ CostructuredArrow.mk (yonedaEquiv.symm x) := CostructuredArrow.homMk Ο†.unop (by dsimp [yonedaEquiv] aesop_cat ) simpa using (f.naturality ψ).symm } invFun g := { app := fun y => yonedaEquiv (y.hom ≫ g) naturality := fun {X₁ Xβ‚‚} Ο† => by dsimp rw [← CostructuredArrow.w Ο†] dsimp [yonedaEquiv] simp only [comp_id, id_comp] refine (congr_fun (g.naturality Ο†.left.op) (Xβ‚‚.hom.app (Opposite.op Xβ‚‚.left) (πŸ™ _))).symm.trans ?_ dsimp apply congr_arg simpa using congr_fun (Xβ‚‚.hom.naturality Ο†.left.op).symm (πŸ™ _) } left_inv f := by ext ⟨X, ⟨⟨⟩⟩, Ο†βŸ© suffices yonedaEquiv.symm (Ο†.app (Opposite.op X) (πŸ™ X)) = Ο† by dsimp erw [yonedaEquiv_apply] dsimp [CostructuredArrow.mk] erw [this] exact yonedaEquiv.injective (by aesop_cat) right_inv g := by ext X x dsimp erw [yonedaEquiv_apply] dsimp rw [yonedaEquiv_symm_app_apply] simp section example [HasColimitsOfSize.{v₁, max u₁ v₁} β„°] : yoneda.HasPointwiseLeftKanExtension A := inferInstance variable [yoneda.HasPointwiseLeftKanExtension A] variable {A} variable (L : (Cα΅’α΅– β₯€ Type v₁) β₯€ β„°) (Ξ± : A ⟢ yoneda β‹™ L) [L.IsLeftKanExtension Ξ±] /-- Auxiliary definition for `yonedaAdjunction`. -/ noncomputable def restrictedYonedaHomEquiv (P : Cα΅’α΅– β₯€ Type v₁) (E : β„°) : (L.obj P ⟢ E) ≃ (P ⟢ (restrictedYoneda A).obj E) := ((Functor.isPointwiseLeftKanExtensionOfIsLeftKanExtension _ Ξ± P).homEquiv E).trans (restrictedYonedaHomEquiv' A P E) /-- If `L : (Cα΅’α΅– β₯€ Type v₁) β₯€ β„°` is a pointwise left Kan extension of a functor `A : C β₯€ β„°` along the Yoneda embedding, then `L` is a left adjoint of `restrictedYoneda A : β„° β₯€ Cα΅’α΅– β₯€ Type v₁` -/ noncomputable def yonedaAdjunction : L ⊣ restrictedYoneda A := Adjunction.mkOfHomEquiv { homEquiv := restrictedYonedaHomEquiv L Ξ± homEquiv_naturality_left_symm := fun {P Q X} f g => by obtain ⟨g, rfl⟩ := (restrictedYonedaHomEquiv L Ξ± Q X).surjective g apply (restrictedYonedaHomEquiv L Ξ± P X).injective simp only [Equiv.apply_symm_apply, Equiv.symm_apply_apply] ext Y y dsimp [restrictedYonedaHomEquiv, restrictedYonedaHomEquiv', IsColimit.homEquiv] rw [assoc, assoc, ← L.map_comp_assoc] congr 3 apply yonedaEquiv.injective simp [yonedaEquiv] homEquiv_naturality_right := fun {P X Y} f g => by apply (restrictedYonedaHomEquiv L Ξ± P Y).symm.injective simp only [Equiv.symm_apply_apply] dsimp [restrictedYonedaHomEquiv, restrictedYonedaHomEquiv', IsColimit.homEquiv] apply (Functor.isPointwiseLeftKanExtensionOfIsLeftKanExtension L Ξ± P).hom_ext intro p rw [IsColimit.fac] dsimp [restrictedYoneda, yonedaEquiv] simp only [assoc] congr 3 apply yonedaEquiv.injective simp [yonedaEquiv] }
include Ξ± in /-- Any left Kan extension along the Yoneda embedding preserves colimits. -/ lemma preservesColimitsOfSize_of_isLeftKanExtension : PreservesColimitsOfSize.{v₃, u₃} L := (yonedaAdjunction L Ξ±).leftAdjoint_preservesColimits lemma isIso_of_isLeftKanExtension : IsIso Ξ± := (Functor.isPointwiseLeftKanExtensionOfIsLeftKanExtension _ Ξ±).isIso_hom variable (A) /-- See Property 2 of https://ncatlab.org/nlab/show/Yoneda+extension#properties. -/ noncomputable instance preservesColimitsOfSize_leftKanExtension : PreservesColimitsOfSize.{v₃, u₃} (yoneda.leftKanExtension A) := (yonedaAdjunction _ (yoneda.leftKanExtensionUnit A)).leftAdjoint_preservesColimits instance : IsIso (yoneda.leftKanExtensionUnit A) :=
Mathlib/CategoryTheory/Limits/Presheaf.lean
157
174
/- 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, Johan Commelin -/ import Mathlib.Analysis.Analytic.Basic import Mathlib.Combinatorics.Enumerative.Composition /-! # Composition of analytic functions In this file we prove that the composition of analytic functions is analytic. The argument is the following. Assume `g z = βˆ‘' qβ‚™ (z, ..., z)` and `f y = βˆ‘' pβ‚– (y, ..., y)`. Then `g (f y) = βˆ‘' qβ‚™ (βˆ‘' pβ‚– (y, ..., y), ..., βˆ‘' pβ‚– (y, ..., y)) = βˆ‘' qβ‚™ (p_{i₁} (y, ..., y), ..., p_{iβ‚™} (y, ..., y))`. For each `n` and `i₁, ..., iβ‚™`, define a `i₁ + ... + iβ‚™` multilinear function mapping `(yβ‚€, ..., y_{i₁ + ... + iβ‚™ - 1})` to `qβ‚™ (p_{i₁} (yβ‚€, ..., y_{i₁-1}), p_{iβ‚‚} (y_{i₁}, ..., y_{i₁ + iβ‚‚ - 1}), ..., p_{iβ‚™} (....)))`. Then `g ∘ f` is obtained by summing all these multilinear functions. To formalize this, we use compositions of an integer `N`, i.e., its decompositions into a sum `i₁ + ... + iβ‚™` of positive integers. Given such a composition `c` and two formal multilinear series `q` and `p`, let `q.compAlongComposition p c` be the above multilinear function. Then the `N`-th coefficient in the power series expansion of `g ∘ f` is the sum of these terms over all `c : Composition N`. To complete the proof, we need to show that this power series has a positive radius of convergence. This follows from the fact that `Composition N` has cardinality `2^(N-1)` and estimates on the norm of `qβ‚™` and `pβ‚–`, which give summability. We also need to show that it indeed converges to `g ∘ f`. For this, we note that the composition of partial sums converges to `g ∘ f`, and that it corresponds to a part of the whole sum, on a subset that increases to the whole space. By summability of the norms, this implies the overall convergence. ## Main results * `q.comp p` is the formal composition of the formal multilinear series `q` and `p`. * `HasFPowerSeriesAt.comp` states that if two functions `g` and `f` admit power series expansions `q` and `p`, then `g ∘ f` admits a power series expansion given by `q.comp p`. * `AnalyticAt.comp` states that the composition of analytic functions is analytic. * `FormalMultilinearSeries.comp_assoc` states that composition is associative on formal multilinear series. ## Implementation details The main technical difficulty is to write down things. In particular, we need to define precisely `q.compAlongComposition p c` and to show that it is indeed a continuous multilinear function. This requires a whole interface built on the class `Composition`. Once this is set, the main difficulty is to reorder the sums, writing the composition of the partial sums as a sum over some subset of `Ξ£ n, Composition n`. We need to check that the reordering is a bijection, running over difficulties due to the dependent nature of the types under consideration, that are controlled thanks to the interface for `Composition`. The associativity of composition on formal multilinear series is a nontrivial result: it does not follow from the associativity of composition of analytic functions, as there is no uniqueness for the formal multilinear series representing a function (and also, it holds even when the radius of convergence of the series is `0`). Instead, we give a direct proof, which amounts to reordering double sums in a careful way. The change of variables is a canonical (combinatorial) bijection `Composition.sigmaEquivSigmaPi` between `(Ξ£ (a : Composition n), Composition a.length)` and `(Ξ£ (c : Composition n), Ξ  (i : Fin c.length), Composition (c.blocksFun i))`, and is described in more details below in the paragraph on associativity. -/ noncomputable section variable {π•œ : Type*} {E F G H : Type*} open Filter List open scoped Topology NNReal ENNReal section Topological variable [CommRing π•œ] [AddCommGroup E] [AddCommGroup F] [AddCommGroup G] variable [Module π•œ E] [Module π•œ F] [Module π•œ G] variable [TopologicalSpace E] [TopologicalSpace F] [TopologicalSpace G] /-! ### Composing formal multilinear series -/ namespace FormalMultilinearSeries variable [IsTopologicalAddGroup E] [ContinuousConstSMul π•œ E] variable [IsTopologicalAddGroup F] [ContinuousConstSMul π•œ F] variable [IsTopologicalAddGroup G] [ContinuousConstSMul π•œ G] /-! In this paragraph, we define the composition of formal multilinear series, by summing over all possible compositions of `n`. -/ /-- Given a formal multilinear series `p`, a composition `c` of `n` and the index `i` of a block of `c`, we may define a function on `Fin n β†’ E` by picking the variables in the `i`-th block of `n`, and applying the corresponding coefficient of `p` to these variables. This function is called `p.applyComposition c v i` for `v : Fin n β†’ E` and `i : Fin c.length`. -/ def applyComposition (p : FormalMultilinearSeries π•œ E F) {n : β„•} (c : Composition n) : (Fin n β†’ E) β†’ Fin c.length β†’ F := fun v i => p (c.blocksFun i) (v ∘ c.embedding i) theorem applyComposition_ones (p : FormalMultilinearSeries π•œ E F) (n : β„•) : p.applyComposition (Composition.ones n) = fun v i => p 1 fun _ => v (Fin.castLE (Composition.length_le _) i) := by funext v i apply p.congr (Composition.ones_blocksFun _ _) intro j hjn hj1 obtain rfl : j = 0 := by omega refine congr_arg v ?_ rw [Fin.ext_iff, Fin.coe_castLE, Composition.ones_embedding, Fin.val_mk] theorem applyComposition_single (p : FormalMultilinearSeries π•œ E F) {n : β„•} (hn : 0 < n) (v : Fin n β†’ E) : p.applyComposition (Composition.single n hn) v = fun _j => p n v := by ext j refine p.congr (by simp) fun i hi1 hi2 => ?_ dsimp congr 1 convert Composition.single_embedding hn ⟨i, hi2⟩ using 1 obtain ⟨j_val, j_property⟩ := j have : j_val = 0 := le_bot_iff.1 (Nat.lt_succ_iff.1 j_property) congr! simp @[simp] theorem removeZero_applyComposition (p : FormalMultilinearSeries π•œ E F) {n : β„•} (c : Composition n) : p.removeZero.applyComposition c = p.applyComposition c := by ext v i simp [applyComposition, zero_lt_one.trans_le (c.one_le_blocksFun i), removeZero_of_pos] /-- Technical lemma stating how `p.applyComposition` commutes with updating variables. This will be the key point to show that functions constructed from `applyComposition` retain multilinearity. -/ theorem applyComposition_update (p : FormalMultilinearSeries π•œ E F) {n : β„•} (c : Composition n) (j : Fin n) (v : Fin n β†’ E) (z : E) : p.applyComposition c (Function.update v j z) = Function.update (p.applyComposition c v) (c.index j) (p (c.blocksFun (c.index j)) (Function.update (v ∘ c.embedding (c.index j)) (c.invEmbedding j) z)) := by ext k by_cases h : k = c.index j Β· rw [h] let r : Fin (c.blocksFun (c.index j)) β†’ Fin n := c.embedding (c.index j) simp only [Function.update_self] change p (c.blocksFun (c.index j)) (Function.update v j z ∘ r) = _ let j' := c.invEmbedding j suffices B : Function.update v j z ∘ r = Function.update (v ∘ r) j' z by rw [B] suffices C : Function.update v (r j') z ∘ r = Function.update (v ∘ r) j' z by convert C; exact (c.embedding_comp_inv j).symm exact Function.update_comp_eq_of_injective _ (c.embedding _).injective _ _ Β· simp only [h, Function.update_eq_self, Function.update_of_ne, Ne, not_false_iff] let r : Fin (c.blocksFun k) β†’ Fin n := c.embedding k change p (c.blocksFun k) (Function.update v j z ∘ r) = p (c.blocksFun k) (v ∘ r) suffices B : Function.update v j z ∘ r = v ∘ r by rw [B] apply Function.update_comp_eq_of_not_mem_range rwa [c.mem_range_embedding_iff'] @[simp] theorem compContinuousLinearMap_applyComposition {n : β„•} (p : FormalMultilinearSeries π•œ F G) (f : E β†’L[π•œ] F) (c : Composition n) (v : Fin n β†’ E) : (p.compContinuousLinearMap f).applyComposition c v = p.applyComposition c (f ∘ v) := by simp (config := {unfoldPartialApp := true}) [applyComposition]; rfl end FormalMultilinearSeries namespace ContinuousMultilinearMap open FormalMultilinearSeries variable [IsTopologicalAddGroup E] [ContinuousConstSMul π•œ E] variable [IsTopologicalAddGroup F] [ContinuousConstSMul π•œ F] /-- Given a formal multilinear series `p`, a composition `c` of `n` and a continuous multilinear map `f` in `c.length` variables, one may form a continuous multilinear map in `n` variables by applying the right coefficient of `p` to each block of the composition, and then applying `f` to the resulting vector. It is called `f.compAlongComposition p c`. -/ def compAlongComposition {n : β„•} (p : FormalMultilinearSeries π•œ E F) (c : Composition n) (f : F [Γ—c.length]β†’L[π•œ] G) : E [Γ—n]β†’L[π•œ] G where toMultilinearMap := MultilinearMap.mk' (fun v ↦ f (p.applyComposition c v)) (fun v i x y ↦ by simp only [applyComposition_update, map_update_add]) (fun v i c x ↦ by simp only [applyComposition_update, map_update_smul]) cont := f.cont.comp <| continuous_pi fun _ => (coe_continuous _).comp <| continuous_pi fun _ => continuous_apply _ @[simp] theorem compAlongComposition_apply {n : β„•} (p : FormalMultilinearSeries π•œ E F) (c : Composition n) (f : F [Γ—c.length]β†’L[π•œ] G) (v : Fin n β†’ E) : (f.compAlongComposition p c) v = f (p.applyComposition c v) := rfl end ContinuousMultilinearMap namespace FormalMultilinearSeries variable [IsTopologicalAddGroup E] [ContinuousConstSMul π•œ E] variable [IsTopologicalAddGroup F] [ContinuousConstSMul π•œ F] variable [IsTopologicalAddGroup G] [ContinuousConstSMul π•œ G] /-- Given two formal multilinear series `q` and `p` and a composition `c` of `n`, one may form a continuous multilinear map in `n` variables by applying the right coefficient of `p` to each block of the composition, and then applying `q c.length` to the resulting vector. It is called `q.compAlongComposition p c`. -/ def compAlongComposition {n : β„•} (q : FormalMultilinearSeries π•œ F G) (p : FormalMultilinearSeries π•œ E F) (c : Composition n) : (E [Γ—n]β†’L[π•œ] G) := (q c.length).compAlongComposition p c @[simp] theorem compAlongComposition_apply {n : β„•} (q : FormalMultilinearSeries π•œ F G) (p : FormalMultilinearSeries π•œ E F) (c : Composition n) (v : Fin n β†’ E) : (q.compAlongComposition p c) v = q c.length (p.applyComposition c v) := rfl /-- Formal composition of two formal multilinear series. The `n`-th coefficient in the composition is defined to be the sum of `q.compAlongComposition p c` over all compositions of `n`. In other words, this term (as a multilinear function applied to `v_0, ..., v_{n-1}`) is `βˆ‘'_{k} βˆ‘'_{i₁ + ... + iβ‚– = n} qβ‚– (p_{i_1} (...), ..., p_{i_k} (...))`, where one puts all variables `v_0, ..., v_{n-1}` in increasing order in the dots. In general, the composition `q ∘ p` only makes sense when the constant coefficient of `p` vanishes. We give a general formula but which ignores the value of `p 0` instead. -/ protected def comp (q : FormalMultilinearSeries π•œ F G) (p : FormalMultilinearSeries π•œ E F) : FormalMultilinearSeries π•œ E G := fun n => βˆ‘ c : Composition n, q.compAlongComposition p c /-- The `0`-th coefficient of `q.comp p` is `q 0`. Since these maps are multilinear maps in zero variables, but on different spaces, we can not state this directly, so we state it when applied to arbitrary vectors (which have to be the zero vector). -/ theorem comp_coeff_zero (q : FormalMultilinearSeries π•œ F G) (p : FormalMultilinearSeries π•œ E F) (v : Fin 0 β†’ E) (v' : Fin 0 β†’ F) : (q.comp p) 0 v = q 0 v' := by let c : Composition 0 := Composition.ones 0 dsimp [FormalMultilinearSeries.comp] have : {c} = (Finset.univ : Finset (Composition 0)) := by apply Finset.eq_of_subset_of_card_le <;> simp [Finset.card_univ, composition_card 0] rw [← this, Finset.sum_singleton, compAlongComposition_apply] symm; congr! -- Porting note: needed the stronger `congr!`! @[simp] theorem comp_coeff_zero' (q : FormalMultilinearSeries π•œ F G) (p : FormalMultilinearSeries π•œ E F) (v : Fin 0 β†’ E) : (q.comp p) 0 v = q 0 fun _i => 0 := q.comp_coeff_zero p v _ /-- The `0`-th coefficient of `q.comp p` is `q 0`. When `p` goes from `E` to `E`, this can be expressed as a direct equality -/ theorem comp_coeff_zero'' (q : FormalMultilinearSeries π•œ E F) (p : FormalMultilinearSeries π•œ E E) : (q.comp p) 0 = q 0 := by ext v; exact q.comp_coeff_zero p _ _ /-- The first coefficient of a composition of formal multilinear series is the composition of the first coefficients seen as continuous linear maps. -/ theorem comp_coeff_one (q : FormalMultilinearSeries π•œ F G) (p : FormalMultilinearSeries π•œ E F) (v : Fin 1 β†’ E) : (q.comp p) 1 v = q 1 fun _i => p 1 v := by have : {Composition.ones 1} = (Finset.univ : Finset (Composition 1)) := Finset.eq_univ_of_card _ (by simp [composition_card]) simp only [FormalMultilinearSeries.comp, compAlongComposition_apply, ← this, Finset.sum_singleton] refine q.congr (by simp) fun i hi1 hi2 => ?_ simp only [applyComposition_ones] exact p.congr rfl fun j _hj1 hj2 => by congr! -- Porting note: needed the stronger `congr!` /-- Only `0`-th coefficient of `q.comp p` depends on `q 0`. -/ theorem removeZero_comp_of_pos (q : FormalMultilinearSeries π•œ F G) (p : FormalMultilinearSeries π•œ E F) {n : β„•} (hn : 0 < n) : q.removeZero.comp p n = q.comp p n := by ext v simp only [FormalMultilinearSeries.comp, compAlongComposition, ContinuousMultilinearMap.compAlongComposition_apply, ContinuousMultilinearMap.sum_apply] refine Finset.sum_congr rfl fun c _hc => ?_ rw [removeZero_of_pos _ (c.length_pos_of_pos hn)] @[simp] theorem comp_removeZero (q : FormalMultilinearSeries π•œ F G) (p : FormalMultilinearSeries π•œ E F) : q.comp p.removeZero = q.comp p := by ext n; simp [FormalMultilinearSeries.comp] end FormalMultilinearSeries end Topological variable [NontriviallyNormedField π•œ] [NormedAddCommGroup E] [NormedSpace π•œ E] [NormedAddCommGroup F] [NormedSpace π•œ F] [NormedAddCommGroup G] [NormedSpace π•œ G] [NormedAddCommGroup H] [NormedSpace π•œ H] namespace FormalMultilinearSeries /-- The norm of `f.compAlongComposition p c` is controlled by the product of the norms of the relevant bits of `f` and `p`. -/ theorem compAlongComposition_bound {n : β„•} (p : FormalMultilinearSeries π•œ E F) (c : Composition n) (f : F [Γ—c.length]β†’L[π•œ] G) (v : Fin n β†’ E) : β€–f.compAlongComposition p c vβ€– ≀ (β€–fβ€– * ∏ i, β€–p (c.blocksFun i)β€–) * ∏ i : Fin n, β€–v iβ€– := calc β€–f.compAlongComposition p c vβ€– = β€–f (p.applyComposition c v)β€– := rfl _ ≀ β€–fβ€– * ∏ i, β€–p.applyComposition c v iβ€– := ContinuousMultilinearMap.le_opNorm _ _ _ ≀ β€–fβ€– * ∏ i, β€–p (c.blocksFun i)β€– * ∏ j : Fin (c.blocksFun i), β€–(v ∘ c.embedding i) jβ€– := by apply mul_le_mul_of_nonneg_left _ (norm_nonneg _) refine Finset.prod_le_prod (fun i _hi => norm_nonneg _) fun i _hi => ?_ apply ContinuousMultilinearMap.le_opNorm _ = (β€–fβ€– * ∏ i, β€–p (c.blocksFun i)β€–) * ∏ i, ∏ j : Fin (c.blocksFun i), β€–(v ∘ c.embedding i) jβ€– := by rw [Finset.prod_mul_distrib, mul_assoc] _ = (β€–fβ€– * ∏ i, β€–p (c.blocksFun i)β€–) * ∏ i : Fin n, β€–v iβ€– := by rw [← c.blocksFinEquiv.prod_comp, ← Finset.univ_sigma_univ, Finset.prod_sigma] congr /-- The norm of `q.compAlongComposition p c` is controlled by the product of the norms of the relevant bits of `q` and `p`. -/ theorem compAlongComposition_norm {n : β„•} (q : FormalMultilinearSeries π•œ F G) (p : FormalMultilinearSeries π•œ E F) (c : Composition n) : β€–q.compAlongComposition p cβ€– ≀ β€–q c.lengthβ€– * ∏ i, β€–p (c.blocksFun i)β€– := ContinuousMultilinearMap.opNorm_le_bound (by positivity) (compAlongComposition_bound _ _ _) theorem compAlongComposition_nnnorm {n : β„•} (q : FormalMultilinearSeries π•œ F G) (p : FormalMultilinearSeries π•œ E F) (c : Composition n) : β€–q.compAlongComposition p cβ€–β‚Š ≀ β€–q c.lengthβ€–β‚Š * ∏ i, β€–p (c.blocksFun i)β€–β‚Š := by rw [← NNReal.coe_le_coe]; push_cast; exact q.compAlongComposition_norm p c /-! ### The identity formal power series We will now define the identity power series, and show that it is a neutral element for left and right composition. -/ section variable (π•œ E) /-- The identity formal multilinear series, with all coefficients equal to `0` except for `n = 1` where it is (the continuous multilinear version of) the identity. We allow an arbitrary constant coefficient `x`. -/ def id (x : E) : FormalMultilinearSeries π•œ E E | 0 => ContinuousMultilinearMap.uncurry0 π•œ _ x | 1 => (continuousMultilinearCurryFin1 π•œ E E).symm (ContinuousLinearMap.id π•œ E) | _ => 0 @[simp] theorem id_apply_zero (x : E) (v : Fin 0 β†’ E) : (FormalMultilinearSeries.id π•œ E x) 0 v = x := rfl /-- The first coefficient of `id π•œ E` is the identity. -/ @[simp] theorem id_apply_one (x : E) (v : Fin 1 β†’ E) : (FormalMultilinearSeries.id π•œ E x) 1 v = v 0 := rfl /-- The `n`th coefficient of `id π•œ E` is the identity when `n = 1`. We state this in a dependent way, as it will often appear in this form. -/ theorem id_apply_one' (x : E) {n : β„•} (h : n = 1) (v : Fin n β†’ E) : (id π•œ E x) n v = v ⟨0, h.symm β–Έ zero_lt_one⟩ := by subst n apply id_apply_one /-- For `n β‰  1`, the `n`-th coefficient of `id π•œ E` is zero, by definition. -/ @[simp] theorem id_apply_of_one_lt (x : E) {n : β„•} (h : 1 < n) : (FormalMultilinearSeries.id π•œ E x) n = 0 := by match n with | 0 => contradiction | 1 => contradiction | n + 2 => rfl end @[simp] theorem comp_id (p : FormalMultilinearSeries π•œ E F) (x : E) : p.comp (id π•œ E x) = p := by ext1 n dsimp [FormalMultilinearSeries.comp] rw [Finset.sum_eq_single (Composition.ones n)] Β· show compAlongComposition p (id π•œ E x) (Composition.ones n) = p n ext v rw [compAlongComposition_apply] apply p.congr (Composition.ones_length n) intros rw [applyComposition_ones] refine congr_arg v ?_ rw [Fin.ext_iff, Fin.coe_castLE, Fin.val_mk] Β· show βˆ€ b : Composition n, b ∈ Finset.univ β†’ b β‰  Composition.ones n β†’ compAlongComposition p (id π•œ E x) b = 0 intro b _ hb obtain ⟨k, hk, lt_k⟩ : βˆƒ (k : β„•), k ∈ Composition.blocks b ∧ 1 < k := Composition.ne_ones_iff.1 hb obtain ⟨i, hi⟩ : βˆƒ (i : Fin b.blocks.length), b.blocks[i] = k := List.get_of_mem hk let j : Fin b.length := ⟨i.val, b.blocks_length β–Έ i.prop⟩ have A : 1 < b.blocksFun j := by convert lt_k ext v rw [compAlongComposition_apply, ContinuousMultilinearMap.zero_apply] apply ContinuousMultilinearMap.map_coord_zero _ j dsimp [applyComposition] rw [id_apply_of_one_lt _ _ _ A, ContinuousMultilinearMap.zero_apply] Β· simp @[simp] theorem id_comp (p : FormalMultilinearSeries π•œ E F) (v0 : Fin 0 β†’ E) : (id π•œ F (p 0 v0)).comp p = p := by ext1 n obtain rfl | n_pos := n.eq_zero_or_pos Β· ext v simp only [comp_coeff_zero', id_apply_zero] congr with i exact i.elim0 Β· dsimp [FormalMultilinearSeries.comp] rw [Finset.sum_eq_single (Composition.single n n_pos)] Β· show compAlongComposition (id π•œ F (p 0 v0)) p (Composition.single n n_pos) = p n ext v rw [compAlongComposition_apply, id_apply_one' _ _ _ (Composition.single_length n_pos)] dsimp [applyComposition] refine p.congr rfl fun i him hin => congr_arg v <| ?_ ext; simp Β· show βˆ€ b : Composition n, b ∈ Finset.univ β†’ b β‰  Composition.single n n_pos β†’ compAlongComposition (id π•œ F (p 0 v0)) p b = 0 intro b _ hb have A : 1 < b.length := by have : b.length β‰  1 := by simpa [Composition.eq_single_iff_length] using hb have : 0 < b.length := Composition.length_pos_of_pos b n_pos omega ext v rw [compAlongComposition_apply, id_apply_of_one_lt _ _ _ A, ContinuousMultilinearMap.zero_apply, ContinuousMultilinearMap.zero_apply] Β· simp /-- Variant of `id_comp` in which the zero coefficient is given by an equality hypothesis instead of a definitional equality. Useful for rewriting or simplifying out in some situations. -/ theorem id_comp' (p : FormalMultilinearSeries π•œ E F) (x : F) (v0 : Fin 0 β†’ E) (h : x = p 0 v0) : (id π•œ F x).comp p = p := by simp [h] /-! ### Summability properties of the composition of formal power series -/ section /-- If two formal multilinear series have positive radius of convergence, then the terms appearing in the definition of their composition are also summable (when multiplied by a suitable positive geometric term). -/ theorem comp_summable_nnreal (q : FormalMultilinearSeries π•œ F G) (p : FormalMultilinearSeries π•œ E F) (hq : 0 < q.radius) (hp : 0 < p.radius) : βˆƒ r > (0 : ℝβ‰₯0), Summable fun i : Ξ£ n, Composition n => β€–q.compAlongComposition p i.2β€–β‚Š * r ^ i.1 := by /- This follows from the fact that the growth rate of `β€–qβ‚™β€–` and `β€–pβ‚™β€–` is at most geometric, giving a geometric bound on each `β€–q.compAlongComposition p opβ€–`, together with the fact that there are `2^(n-1)` compositions of `n`, giving at most a geometric loss. -/ rcases ENNReal.lt_iff_exists_nnreal_btwn.1 (lt_min zero_lt_one hq) with ⟨rq, rq_pos, hrq⟩ rcases ENNReal.lt_iff_exists_nnreal_btwn.1 (lt_min zero_lt_one hp) with ⟨rp, rp_pos, hrp⟩ simp only [lt_min_iff, ENNReal.coe_lt_one_iff, ENNReal.coe_pos] at hrp hrq rp_pos rq_pos obtain ⟨Cq, _hCq0, hCq⟩ : βˆƒ Cq > 0, βˆ€ n, β€–q nβ€–β‚Š * rq ^ n ≀ Cq := q.nnnorm_mul_pow_le_of_lt_radius hrq.2 obtain ⟨Cp, hCp1, hCp⟩ : βˆƒ Cp β‰₯ 1, βˆ€ n, β€–p nβ€–β‚Š * rp ^ n ≀ Cp := by rcases p.nnnorm_mul_pow_le_of_lt_radius hrp.2 with ⟨Cp, -, hCp⟩ exact ⟨max Cp 1, le_max_right _ _, fun n => (hCp n).trans (le_max_left _ _)⟩ let r0 : ℝβ‰₯0 := (4 * Cp)⁻¹ have r0_pos : 0 < r0 := inv_pos.2 (mul_pos zero_lt_four (zero_lt_one.trans_le hCp1)) set r : ℝβ‰₯0 := rp * rq * r0 have r_pos : 0 < r := mul_pos (mul_pos rp_pos rq_pos) r0_pos have I : βˆ€ i : Ξ£ n : β„•, Composition n, β€–q.compAlongComposition p i.2β€–β‚Š * r ^ i.1 ≀ Cq / 4 ^ i.1 := by rintro ⟨n, c⟩ have A := calc β€–q c.lengthβ€–β‚Š * rq ^ n ≀ β€–q c.lengthβ€–β‚Š * rq ^ c.length := mul_le_mul' le_rfl (pow_le_pow_of_le_one rq.2 hrq.1.le c.length_le) _ ≀ Cq := hCq _ have B := calc (∏ i, β€–p (c.blocksFun i)β€–β‚Š) * rp ^ n = ∏ i, β€–p (c.blocksFun i)β€–β‚Š * rp ^ c.blocksFun i := by simp only [Finset.prod_mul_distrib, Finset.prod_pow_eq_pow_sum, c.sum_blocksFun] _ ≀ ∏ _i : Fin c.length, Cp := Finset.prod_le_prod' fun i _ => hCp _ _ = Cp ^ c.length := by simp _ ≀ Cp ^ n := pow_right_monoβ‚€ hCp1 c.length_le calc β€–q.compAlongComposition p cβ€–β‚Š * r ^ n ≀ (β€–q c.lengthβ€–β‚Š * ∏ i, β€–p (c.blocksFun i)β€–β‚Š) * r ^ n := mul_le_mul' (q.compAlongComposition_nnnorm p c) le_rfl _ = β€–q c.lengthβ€–β‚Š * rq ^ n * ((∏ i, β€–p (c.blocksFun i)β€–β‚Š) * rp ^ n) * r0 ^ n := by ring _ ≀ Cq * Cp ^ n * r0 ^ n := mul_le_mul' (mul_le_mul' A B) le_rfl _ = Cq / 4 ^ n := by simp only [r0] field_simp [mul_pow, (zero_lt_one.trans_le hCp1).ne'] ring refine ⟨r, r_pos, NNReal.summable_of_le I ?_⟩ simp_rw [div_eq_mul_inv] refine Summable.mul_left _ ?_ have : βˆ€ n : β„•, HasSum (fun c : Composition n => (4 ^ n : ℝβ‰₯0)⁻¹) (2 ^ (n - 1) / 4 ^ n) := by intro n convert hasSum_fintype fun c : Composition n => (4 ^ n : ℝβ‰₯0)⁻¹ simp [Finset.card_univ, composition_card, div_eq_mul_inv] refine NNReal.summable_sigma.2 ⟨fun n => (this n).summable, (NNReal.summable_nat_add_iff 1).1 ?_⟩ convert (NNReal.summable_geometric (NNReal.div_lt_one_of_lt one_lt_two)).mul_left (1 / 4) using 1 ext1 n rw [(this _).tsum_eq, add_tsub_cancel_right] field_simp [← mul_assoc, pow_succ, mul_pow, show (4 : ℝβ‰₯0) = 2 * 2 by norm_num, mul_right_comm] end /-- Bounding below the radius of the composition of two formal multilinear series assuming summability over all compositions. -/ theorem le_comp_radius_of_summable (q : FormalMultilinearSeries π•œ F G) (p : FormalMultilinearSeries π•œ E F) (r : ℝβ‰₯0) (hr : Summable fun i : Ξ£ n, Composition n => β€–q.compAlongComposition p i.2β€–β‚Š * r ^ i.1) : (r : ℝβ‰₯0∞) ≀ (q.comp p).radius := by refine le_radius_of_bound_nnreal _ (βˆ‘' i : Ξ£ n, Composition n, β€–compAlongComposition q p i.sndβ€–β‚Š * r ^ i.fst) fun n => ?_ calc β€–FormalMultilinearSeries.comp q p nβ€–β‚Š * r ^ n ≀ βˆ‘' c : Composition n, β€–compAlongComposition q p cβ€–β‚Š * r ^ n := by rw [tsum_fintype, ← Finset.sum_mul] exact mul_le_mul' (nnnorm_sum_le _ _) le_rfl _ ≀ βˆ‘' i : Ξ£ n : β„•, Composition n, β€–compAlongComposition q p i.sndβ€–β‚Š * r ^ i.fst := NNReal.tsum_comp_le_tsum_of_inj hr sigma_mk_injective /-! ### Composing analytic functions Now, we will prove that the composition of the partial sums of `q` and `p` up to order `N` is given by a sum over some large subset of `Ξ£ n, Composition n` of `q.compAlongComposition p`, to deduce that the series for `q.comp p` indeed converges to `g ∘ f` when `q` is a power series for `g` and `p` is a power series for `f`. This proof is a big reindexing argument of a sum. Since it is a bit involved, we define first the source of the change of variables (`compPartialSumSource`), its target (`compPartialSumTarget`) and the change of variables itself (`compChangeOfVariables`) before giving the main statement in `comp_partialSum`. -/ /-- Source set in the change of variables to compute the composition of partial sums of formal power series. See also `comp_partialSum`. -/ def compPartialSumSource (m M N : β„•) : Finset (Ξ£ n, Fin n β†’ β„•) := Finset.sigma (Finset.Ico m M) (fun n : β„• => Fintype.piFinset fun _i : Fin n => Finset.Ico 1 N :) @[simp] theorem mem_compPartialSumSource_iff (m M N : β„•) (i : Ξ£ n, Fin n β†’ β„•) : i ∈ compPartialSumSource m M N ↔ (m ≀ i.1 ∧ i.1 < M) ∧ βˆ€ a : Fin i.1, 1 ≀ i.2 a ∧ i.2 a < N := by simp only [compPartialSumSource, Finset.mem_Ico, Fintype.mem_piFinset, Finset.mem_sigma] /-- Change of variables appearing to compute the composition of partial sums of formal power series -/ def compChangeOfVariables (m M N : β„•) (i : Ξ£ n, Fin n β†’ β„•) (hi : i ∈ compPartialSumSource m M N) : Ξ£ n, Composition n := by rcases i with ⟨n, f⟩ rw [mem_compPartialSumSource_iff] at hi refine βŸ¨βˆ‘ j, f j, ofFn fun a => f a, fun {i} hi' => ?_, by simp [sum_ofFn]⟩ obtain ⟨j, rfl⟩ : βˆƒ j : Fin n, f j = i := by rwa [mem_ofFn', Set.mem_range] at hi' exact (hi.2 j).1 @[simp] theorem compChangeOfVariables_length (m M N : β„•) {i : Ξ£ n, Fin n β†’ β„•} (hi : i ∈ compPartialSumSource m M N) : Composition.length (compChangeOfVariables m M N i hi).2 = i.1 := by rcases i with ⟨k, blocks_fun⟩ dsimp [compChangeOfVariables] simp only [Composition.length, map_ofFn, length_ofFn] theorem compChangeOfVariables_blocksFun (m M N : β„•) {i : Ξ£ n, Fin n β†’ β„•} (hi : i ∈ compPartialSumSource m M N) (j : Fin i.1) : (compChangeOfVariables m M N i hi).2.blocksFun ⟨j, (compChangeOfVariables_length m M N hi).symm β–Έ j.2⟩ = i.2 j := by rcases i with ⟨n, f⟩ dsimp [Composition.blocksFun, Composition.blocks, compChangeOfVariables] simp only [map_ofFn, List.getElem_ofFn, Function.comp_apply] /-- Target set in the change of variables to compute the composition of partial sums of formal power series, here given a a set. -/ def compPartialSumTargetSet (m M N : β„•) : Set (Ξ£ n, Composition n) := {i | m ≀ i.2.length ∧ i.2.length < M ∧ βˆ€ j : Fin i.2.length, i.2.blocksFun j < N} theorem compPartialSumTargetSet_image_compPartialSumSource (m M N : β„•) (i : Ξ£ n, Composition n) (hi : i ∈ compPartialSumTargetSet m M N) : βˆƒ (j : _) (hj : j ∈ compPartialSumSource m M N), compChangeOfVariables m M N j hj = i := by rcases i with ⟨n, c⟩ refine ⟨⟨c.length, c.blocksFun⟩, ?_, ?_⟩ Β· simp only [compPartialSumTargetSet, Set.mem_setOf_eq] at hi simp only [mem_compPartialSumSource_iff, hi.left, hi.right, true_and, and_true] exact fun a => c.one_le_blocks' _ Β· dsimp [compChangeOfVariables] rw [Composition.sigma_eq_iff_blocks_eq] simp only [Composition.blocksFun, Composition.blocks, Subtype.coe_eta] conv_rhs => rw [← List.ofFn_get c.blocks] /-- Target set in the change of variables to compute the composition of partial sums of formal power series, here given a a finset. See also `comp_partialSum`. -/ def compPartialSumTarget (m M N : β„•) : Finset (Ξ£ n, Composition n) := Set.Finite.toFinset <| ((Finset.finite_toSet _).dependent_image _).subset <| compPartialSumTargetSet_image_compPartialSumSource m M N @[simp] theorem mem_compPartialSumTarget_iff {m M N : β„•} {a : Ξ£ n, Composition n} : a ∈ compPartialSumTarget m M N ↔ m ≀ a.2.length ∧ a.2.length < M ∧ βˆ€ j : Fin a.2.length, a.2.blocksFun j < N := by simp [compPartialSumTarget, compPartialSumTargetSet] /-- `compChangeOfVariables m M N` is a bijection between `compPartialSumSource m M N` and `compPartialSumTarget m M N`, yielding equal sums for functions that correspond to each other under the bijection. As `compChangeOfVariables m M N` is a dependent function, stating that it is a bijection is not directly possible, but the consequence on sums can be stated more easily. -/ theorem compChangeOfVariables_sum {Ξ± : Type*} [AddCommMonoid Ξ±] (m M N : β„•) (f : (Ξ£ n : β„•, Fin n β†’ β„•) β†’ Ξ±) (g : (Ξ£ n, Composition n) β†’ Ξ±) (h : βˆ€ (e) (he : e ∈ compPartialSumSource m M N), f e = g (compChangeOfVariables m M N e he)) : βˆ‘ e ∈ compPartialSumSource m M N, f e = βˆ‘ e ∈ compPartialSumTarget m M N, g e := by apply Finset.sum_bij (compChangeOfVariables m M N) -- We should show that the correspondence we have set up is indeed a bijection -- between the index sets of the two sums. -- 1 - show that the image belongs to `compPartialSumTarget m N N` Β· rintro ⟨k, blocks_fun⟩ H rw [mem_compPartialSumSource_iff] at H simp only [mem_compPartialSumTarget_iff, Composition.length, Composition.blocks, H.left, map_ofFn, length_ofFn, true_and, compChangeOfVariables] intro j simp only [Composition.blocksFun, (H.right _).right, List.get_ofFn] -- 2 - show that the map is injective Β· rintro ⟨k, blocks_fun⟩ H ⟨k', blocks_fun'⟩ H' heq obtain rfl : k = k' := by have := (compChangeOfVariables_length m M N H).symm rwa [heq, compChangeOfVariables_length] at this congr funext i calc blocks_fun i = (compChangeOfVariables m M N _ H).2.blocksFun _ := (compChangeOfVariables_blocksFun m M N H i).symm _ = (compChangeOfVariables m M N _ H').2.blocksFun _ := by apply Composition.blocksFun_congr <;> first | rw [heq] | rfl _ = blocks_fun' i := compChangeOfVariables_blocksFun m M N H' i -- 3 - show that the map is surjective Β· intro i hi apply compPartialSumTargetSet_image_compPartialSumSource m M N i simpa [compPartialSumTarget] using hi -- 4 - show that the composition gives the `compAlongComposition` application Β· rintro ⟨k, blocks_fun⟩ H rw [h] /-- The auxiliary set corresponding to the composition of partial sums asymptotically contains all possible compositions. -/ theorem compPartialSumTarget_tendsto_prod_atTop : Tendsto (fun (p : β„• Γ— β„•) => compPartialSumTarget 0 p.1 p.2) atTop atTop := by apply Monotone.tendsto_atTop_finset Β· intro m n hmn a ha have : βˆ€ i, i < m.1 β†’ i < n.1 := fun i hi => lt_of_lt_of_le hi hmn.1 have : βˆ€ i, i < m.2 β†’ i < n.2 := fun i hi => lt_of_lt_of_le hi hmn.2 aesop Β· rintro ⟨n, c⟩ simp only [mem_compPartialSumTarget_iff] obtain ⟨n, hn⟩ : BddAbove ((Finset.univ.image fun i : Fin c.length => c.blocksFun i) : Set β„•) := Finset.bddAbove _ refine ⟨max n c.length + 1, bot_le, lt_of_le_of_lt (le_max_right n c.length) (lt_add_one _), fun j => lt_of_le_of_lt (le_trans ?_ (le_max_left _ _)) (lt_add_one _)⟩ apply hn simp only [Finset.mem_image_of_mem, Finset.mem_coe, Finset.mem_univ] /-- The auxiliary set corresponding to the composition of partial sums asymptotically contains all possible compositions. -/ theorem compPartialSumTarget_tendsto_atTop : Tendsto (fun N => compPartialSumTarget 0 N N) atTop atTop := by apply Tendsto.comp compPartialSumTarget_tendsto_prod_atTop tendsto_atTop_diagonal /-- Composing the partial sums of two multilinear series coincides with the sum over all compositions in `compPartialSumTarget 0 N N`. This is precisely the motivation for the definition of `compPartialSumTarget`. -/ theorem comp_partialSum (q : FormalMultilinearSeries π•œ F G) (p : FormalMultilinearSeries π•œ E F) (M N : β„•) (z : E) : q.partialSum M (βˆ‘ i ∈ Finset.Ico 1 N, p i fun _j => z) = βˆ‘ i ∈ compPartialSumTarget 0 M N, q.compAlongComposition p i.2 fun _j => z := by -- we expand the composition, using the multilinearity of `q` to expand along each coordinate. suffices H : (βˆ‘ n ∈ Finset.range M, βˆ‘ r ∈ Fintype.piFinset fun i : Fin n => Finset.Ico 1 N, q n fun i : Fin n => p (r i) fun _j => z) = βˆ‘ i ∈ compPartialSumTarget 0 M N, q.compAlongComposition p i.2 fun _j => z by simpa only [FormalMultilinearSeries.partialSum, ContinuousMultilinearMap.map_sum_finset] using H -- rewrite the first sum as a big sum over a sigma type, in the finset -- `compPartialSumTarget 0 N N` rw [Finset.range_eq_Ico, Finset.sum_sigma'] -- use `compChangeOfVariables_sum`, saying that this change of variables respects sums apply compChangeOfVariables_sum 0 M N rintro ⟨k, blocks_fun⟩ H apply congr _ (compChangeOfVariables_length 0 M N H).symm intros rw [← compChangeOfVariables_blocksFun 0 M N H, applyComposition, Function.comp_def] end FormalMultilinearSeries open FormalMultilinearSeries /-- If two functions `g` and `f` have power series `q` and `p` respectively at `f x` and `x`, within two sets `s` and `t` such that `f` maps `s` to `t`, then `g ∘ f` admits the power series `q.comp p` at `x` within `s`. -/ theorem HasFPowerSeriesWithinAt.comp {g : F β†’ G} {f : E β†’ F} {q : FormalMultilinearSeries π•œ F G} {p : FormalMultilinearSeries π•œ E F} {x : E} {t : Set F} {s : Set E} (hg : HasFPowerSeriesWithinAt g q t (f x)) (hf : HasFPowerSeriesWithinAt f p s x) (hs : Set.MapsTo f s t) : HasFPowerSeriesWithinAt (g ∘ f) (q.comp p) s x := by /- Consider `rf` and `rg` such that `f` and `g` have power series expansion on the disks of radius `rf` and `rg`. -/ rcases hg with ⟨rg, Hg⟩ rcases hf with ⟨rf, Hf⟩ -- The terms defining `q.comp p` are geometrically summable in a disk of some radius `r`. rcases q.comp_summable_nnreal p Hg.radius_pos Hf.radius_pos with ⟨r, r_pos : 0 < r, hr⟩ /- We will consider `y` which is smaller than `r` and `rf`, and also small enough that `f (x + y)` is close enough to `f x` to be in the disk where `g` is well behaved. Let `min (r, rf, Ξ΄)` be this new radius. -/ obtain ⟨δ, Ξ΄pos, hδ⟩ : βˆƒ Ξ΄ : ℝβ‰₯0∞, 0 < Ξ΄ ∧ βˆ€ {z : E}, z ∈ insert x s ∩ EMetric.ball x Ξ΄ β†’ f z ∈ insert (f x) t ∩ EMetric.ball (f x) rg := by have : insert (f x) t ∩ EMetric.ball (f x) rg ∈ 𝓝[insert (f x) t] (f x) := by apply inter_mem_nhdsWithin exact EMetric.ball_mem_nhds _ Hg.r_pos have := Hf.analyticWithinAt.continuousWithinAt_insert.tendsto_nhdsWithin (hs.insert x) this rcases EMetric.mem_nhdsWithin_iff.1 this with ⟨δ, Ξ΄pos, Hδ⟩ exact ⟨δ, Ξ΄pos, fun {z} hz => HΞ΄ (by rwa [Set.inter_comm])⟩ let rf' := min rf Ξ΄ have min_pos : 0 < min rf' r := by simp only [rf', r_pos, Hf.r_pos, Ξ΄pos, lt_min_iff, ENNReal.coe_pos, and_self_iff] /- We will show that `g ∘ f` admits the power series `q.comp p` in the disk of radius `min (r, rf', Ξ΄)`. -/ refine ⟨min rf' r, ?_⟩ refine ⟨le_trans (min_le_right rf' r) (FormalMultilinearSeries.le_comp_radius_of_summable q p r hr), min_pos, fun {y} h'y hy ↦ ?_⟩ /- Let `y` satisfy `β€–yβ€– < min (r, rf', Ξ΄)`. We want to show that `g (f (x + y))` is the sum of `q.comp p` applied to `y`. -/ -- First, check that `y` is small enough so that estimates for `f` and `g` apply. have y_mem : y ∈ EMetric.ball (0 : E) rf := (EMetric.ball_subset_ball (le_trans (min_le_left _ _) (min_le_left _ _))) hy have fy_mem : f (x + y) ∈ insert (f x) t ∩ EMetric.ball (f x) rg := by apply hΞ΄ have : y ∈ EMetric.ball (0 : E) Ξ΄ := (EMetric.ball_subset_ball (le_trans (min_le_left _ _) (min_le_right _ _))) hy simpa [-Set.mem_insert_iff, edist_eq_enorm_sub, h'y] /- Now the proof starts. To show that the sum of `q.comp p` at `y` is `g (f (x + y))`, we will write `q.comp p` applied to `y` as a big sum over all compositions. Since the sum is summable, to get its convergence it suffices to get the convergence along some increasing sequence of sets. We will use the sequence of sets `compPartialSumTarget 0 n n`, along which the sum is exactly the composition of the partial sums of `q` and `p`, by design. To show that it converges to `g (f (x + y))`, pointwise convergence would not be enough, but we have uniform convergence to save the day. -/ -- First step: the partial sum of `p` converges to `f (x + y)`. have A : Tendsto (fun n ↦ (n, βˆ‘ a ∈ Finset.Ico 1 n, p a fun _ ↦ y)) atTop (atTop Γ—Λ’ 𝓝 (f (x + y) - f x)) := by apply Tendsto.prodMk tendsto_id have L : βˆ€αΆ  n in atTop, (βˆ‘ a ∈ Finset.range n, p a fun _b ↦ y) - f x = βˆ‘ a ∈ Finset.Ico 1 n, p a fun _b ↦ y := by rw [eventually_atTop] refine ⟨1, fun n hn => ?_⟩ symm rw [eq_sub_iff_add_eq', Finset.range_eq_Ico, ← Hf.coeff_zero fun _i => y, Finset.sum_eq_sum_Ico_succ_bot hn] have : Tendsto (fun n => (βˆ‘ a ∈ Finset.range n, p a fun _b => y) - f x) atTop (𝓝 (f (x + y) - f x)) := (Hf.hasSum h'y y_mem).tendsto_sum_nat.sub tendsto_const_nhds exact Tendsto.congr' L this -- Second step: the composition of the partial sums of `q` and `p` converges to `g (f (x + y))`. have B : Tendsto (fun n => q.partialSum n (βˆ‘ a ∈ Finset.Ico 1 n, p a fun _b ↦ y)) atTop (𝓝 (g (f (x + y)))) := by -- we use the fact that the partial sums of `q` converge to `g (f (x + y))`, uniformly on a -- neighborhood of `f (x + y)`. have : Tendsto (fun (z : β„• Γ— F) ↦ q.partialSum z.1 z.2) (atTop Γ—Λ’ 𝓝 (f (x + y) - f x)) (𝓝 (g (f x + (f (x + y) - f x)))) := by apply Hg.tendsto_partialSum_prod (y := f (x + y) - f x) Β· simpa [edist_eq_enorm_sub] using fy_mem.2 Β· simpa using fy_mem.1 simpa using this.comp A -- Third step: the sum over all compositions in `compPartialSumTarget 0 n n` converges to -- `g (f (x + y))`. As this sum is exactly the composition of the partial sum, this is a direct -- consequence of the second step have C : Tendsto (fun n => βˆ‘ i ∈ compPartialSumTarget 0 n n, q.compAlongComposition p i.2 fun _j => y) atTop (𝓝 (g (f (x + y)))) := by simpa [comp_partialSum] using B -- Fourth step: the sum over all compositions is `g (f (x + y))`. This follows from the -- convergence along a subsequence proved in the third step, and the fact that the sum is Cauchy -- thanks to the summability properties. have D : HasSum (fun i : Ξ£ n, Composition n => q.compAlongComposition p i.2 fun _j => y) (g (f (x + y))) := haveI cau : CauchySeq fun s : Finset (Ξ£ n, Composition n) => βˆ‘ i ∈ s, q.compAlongComposition p i.2 fun _j => y := by apply cauchySeq_finset_of_norm_bounded _ (NNReal.summable_coe.2 hr) _ simp only [coe_nnnorm, NNReal.coe_mul, NNReal.coe_pow] rintro ⟨n, c⟩ calc β€–(compAlongComposition q p c) fun _j : Fin n => yβ€– ≀ β€–compAlongComposition q p cβ€– * ∏ _j : Fin n, β€–yβ€– := by apply ContinuousMultilinearMap.le_opNorm _ ≀ β€–compAlongComposition q p cβ€– * (r : ℝ) ^ n := by rw [Finset.prod_const, Finset.card_fin] gcongr rw [EMetric.mem_ball, edist_zero_eq_enorm] at hy have := le_trans (le_of_lt hy) (min_le_right _ _) rwa [enorm_le_coe, ← NNReal.coe_le_coe, coe_nnnorm] at this tendsto_nhds_of_cauchySeq_of_subseq cau compPartialSumTarget_tendsto_atTop C -- Fifth step: the sum over `n` of `q.comp p n` can be expressed as a particular resummation of -- the sum over all compositions, by grouping together the compositions of the same -- integer `n`. The convergence of the whole sum therefore implies the converence of the sum -- of `q.comp p n` have E : HasSum (fun n => (q.comp p) n fun _j => y) (g (f (x + y))) := by apply D.sigma intro n simp only [compAlongComposition_apply, FormalMultilinearSeries.comp, ContinuousMultilinearMap.sum_apply] exact hasSum_fintype _ rw [Function.comp_apply] exact E /-- If two functions `g` and `f` have power series `q` and `p` respectively at `f x` and `x`, then `g ∘ f` admits the power series `q.comp p` at `x` within `s`. -/ theorem HasFPowerSeriesAt.comp {g : F β†’ G} {f : E β†’ F} {q : FormalMultilinearSeries π•œ F G} {p : FormalMultilinearSeries π•œ E F} {x : E} (hg : HasFPowerSeriesAt g q (f x)) (hf : HasFPowerSeriesAt f p x) : HasFPowerSeriesAt (g ∘ f) (q.comp p) x := by rw [← hasFPowerSeriesWithinAt_univ] at hf hg ⊒ apply hg.comp hf (by simp) /-- If two functions `g` and `f` are analytic respectively at `f x` and `x`, within two sets `s` and `t` such that `f` maps `s` to `t`, then `g ∘ f` is analytic at `x` within `s`. -/ theorem AnalyticWithinAt.comp {g : F β†’ G} {f : E β†’ F} {x : E} {t : Set F} {s : Set E} (hg : AnalyticWithinAt π•œ g t (f x)) (hf : AnalyticWithinAt π•œ f s x) (h : Set.MapsTo f s t) : AnalyticWithinAt π•œ (g ∘ f) s x := by let ⟨_q, hq⟩ := hg let ⟨_p, hp⟩ := hf exact (hq.comp hp h).analyticWithinAt /-- Version of `AnalyticWithinAt.comp` where point equality is a separate hypothesis. -/ theorem AnalyticWithinAt.comp_of_eq {g : F β†’ G} {f : E β†’ F} {y : F} {x : E} {t : Set F} {s : Set E} (hg : AnalyticWithinAt π•œ g t y) (hf : AnalyticWithinAt π•œ f s x) (h : Set.MapsTo f s t) (hy : f x = y) : AnalyticWithinAt π•œ (g ∘ f) s x := by rw [← hy] at hg exact hg.comp hf h lemma AnalyticOn.comp {f : F β†’ G} {g : E β†’ F} {s : Set F} {t : Set E} (hf : AnalyticOn π•œ f s) (hg : AnalyticOn π•œ g t) (h : Set.MapsTo g t s) : AnalyticOn π•œ (f ∘ g) t := fun x m ↦ (hf _ (h m)).comp (hg x m) h /-- If two functions `g` and `f` are analytic respectively at `f x` and `x`, then `g ∘ f` is analytic at `x`. -/ @[fun_prop] theorem AnalyticAt.comp {g : F β†’ G} {f : E β†’ F} {x : E} (hg : AnalyticAt π•œ g (f x)) (hf : AnalyticAt π•œ f x) : AnalyticAt π•œ (g ∘ f) x := by rw [← analyticWithinAt_univ] at hg hf ⊒ apply hg.comp hf (by simp) /-- If two functions `g` and `f` are analytic respectively at `f x` and `x`, then `g ∘ f` is analytic at `x`. -/ @[fun_prop] theorem AnalyticAt.comp' {g : F β†’ G} {f : E β†’ F} {x : E} (hg : AnalyticAt π•œ g (f x)) (hf : AnalyticAt π•œ f x) : AnalyticAt π•œ (fun z ↦ g (f z)) x := hg.comp hf /-- Version of `AnalyticAt.comp` where point equality is a separate hypothesis. -/ theorem AnalyticAt.comp_of_eq {g : F β†’ G} {f : E β†’ F} {y : F} {x : E} (hg : AnalyticAt π•œ g y) (hf : AnalyticAt π•œ f x) (hy : f x = y) : AnalyticAt π•œ (g ∘ f) x := by rw [← hy] at hg exact hg.comp hf /-- Version of `AnalyticAt.comp` where point equality is a separate hypothesis. -/ theorem AnalyticAt.comp_of_eq' {g : F β†’ G} {f : E β†’ F} {y : F} {x : E} (hg : AnalyticAt π•œ g y) (hf : AnalyticAt π•œ f x) (hy : f x = y) : AnalyticAt π•œ (fun z ↦ g (f z)) x := by apply hg.comp_of_eq hf hy theorem AnalyticAt.comp_analyticWithinAt {g : F β†’ G} {f : E β†’ F} {x : E} {s : Set E} (hg : AnalyticAt π•œ g (f x)) (hf : AnalyticWithinAt π•œ f s x) : AnalyticWithinAt π•œ (g ∘ f) s x := by rw [← analyticWithinAt_univ] at hg exact hg.comp hf (Set.mapsTo_univ _ _) theorem AnalyticAt.comp_analyticWithinAt_of_eq {g : F β†’ G} {f : E β†’ F} {x : E} {y : F} {s : Set E} (hg : AnalyticAt π•œ g y) (hf : AnalyticWithinAt π•œ f s x) (h : f x = y) : AnalyticWithinAt π•œ (g ∘ f) s x := by rw [← h] at hg exact hg.comp_analyticWithinAt hf /-- If two functions `g` and `f` are analytic respectively on `s.image f` and `s`, then `g ∘ f` is analytic on `s`. -/ theorem AnalyticOnNhd.comp' {s : Set E} {g : F β†’ G} {f : E β†’ F} (hg : AnalyticOnNhd π•œ g (s.image f)) (hf : AnalyticOnNhd π•œ f s) : AnalyticOnNhd π•œ (g ∘ f) s := fun z hz => (hg (f z) (Set.mem_image_of_mem f hz)).comp (hf z hz) theorem AnalyticOnNhd.comp {s : Set E} {t : Set F} {g : F β†’ G} {f : E β†’ F} (hg : AnalyticOnNhd π•œ g t) (hf : AnalyticOnNhd π•œ f s) (st : Set.MapsTo f s t) : AnalyticOnNhd π•œ (g ∘ f) s := comp' (mono hg (Set.mapsTo'.mp st)) hf lemma AnalyticOnNhd.comp_analyticOn {f : F β†’ G} {g : E β†’ F} {s : Set F} {t : Set E} (hf : AnalyticOnNhd π•œ f s) (hg : AnalyticOn π•œ g t) (h : Set.MapsTo g t s) : AnalyticOn π•œ (f ∘ g) t := fun x m ↦ (hf _ (h m)).comp_analyticWithinAt (hg x m) /-! ### Associativity of the composition of formal multilinear series In this paragraph, we prove the associativity of the composition of formal power series. By definition, ``` (r.comp q).comp p n v = βˆ‘_{i₁ + ... + iβ‚– = n} (r.comp q)β‚– (p_{i₁} (vβ‚€, ..., v_{i₁ -1}), p_{iβ‚‚} (...), ..., p_{iβ‚–}(...)) = βˆ‘_{a : Composition n} (r.comp q) a.length (applyComposition p a v) ``` decomposing `r.comp q` in the same way, we get ``` (r.comp q).comp p n v = βˆ‘_{a : Composition n} βˆ‘_{b : Composition a.length} r b.length (applyComposition q b (applyComposition p a v)) ``` On the other hand, ``` r.comp (q.comp p) n v = βˆ‘_{c : Composition n} r c.length (applyComposition (q.comp p) c v) ``` Here, `applyComposition (q.comp p) c v` is a vector of length `c.length`, whose `i`-th term is given by `(q.comp p) (c.blocksFun i) (v_l, v_{l+1}, ..., v_{m-1})` where `{l, ..., m-1}` is the `i`-th block in the composition `c`, of length `c.blocksFun i` by definition. To compute this term, we expand it as `βˆ‘_{dα΅’ : Composition (c.blocksFun i)} q dα΅’.length (applyComposition p dα΅’ v')`, where `v' = (v_l, v_{l+1}, ..., v_{m-1})`. Therefore, we get ``` r.comp (q.comp p) n v = βˆ‘_{c : Composition n} βˆ‘_{dβ‚€ : Composition (c.blocksFun 0), ..., d_{c.length - 1} : Composition (c.blocksFun (c.length - 1))} r c.length (fun i ↦ q dα΅’.length (applyComposition p dα΅’ v'α΅’)) ``` To show that these terms coincide, we need to explain how to reindex the sums to put them in bijection (and then the terms we are summing will correspond to each other). Suppose we have a composition `a` of `n`, and a composition `b` of `a.length`. Then `b` indicates how to group together some blocks of `a`, giving altogether `b.length` blocks of blocks. These blocks of blocks can be called `dβ‚€, ..., d_{a.length - 1}`, and one obtains a composition `c` of `n` by saying that each `dα΅’` is one single block. Conversely, if one starts from `c` and the `dα΅’`s, one can concatenate the `dα΅’`s to obtain a composition `a` of `n`, and register the lengths of the `dα΅’`s in a composition `b` of `a.length`. An example might be enlightening. Suppose `a = [2, 2, 3, 4, 2]`. It is a composition of length 5 of 13. The content of the blocks may be represented as `0011222333344`. Now take `b = [2, 3]` as a composition of `a.length = 5`. It says that the first 2 blocks of `a` should be merged, and the last 3 blocks of `a` should be merged, giving a new composition of `13` made of two blocks of length `4` and `9`, i.e., `c = [4, 9]`. But one can also remember that the new first block was initially made of two blocks of size `2`, so `dβ‚€ = [2, 2]`, and the new second block was initially made of three blocks of size `3`, `4` and `2`, so `d₁ = [3, 4, 2]`. This equivalence is called `Composition.sigmaEquivSigmaPi n` below. We start with preliminary results on compositions, of a very specialized nature, then define the equivalence `Composition.sigmaEquivSigmaPi n`, and we deduce finally the associativity of composition of formal multilinear series in `FormalMultilinearSeries.comp_assoc`. -/ namespace Composition variable {n : β„•} /-- Rewriting equality in the dependent type `Ξ£ (a : Composition n), Composition a.length)` in non-dependent terms with lists, requiring that the blocks coincide. -/ theorem sigma_composition_eq_iff (i j : Ξ£ a : Composition n, Composition a.length) : i = j ↔ i.1.blocks = j.1.blocks ∧ i.2.blocks = j.2.blocks := by refine ⟨by rintro rfl; exact ⟨rfl, rfl⟩, ?_⟩ rcases i with ⟨a, b⟩ rcases j with ⟨a', b'⟩ rintro ⟨h, h'⟩ obtain rfl : a = a' := by ext1; exact h obtain rfl : b = b' := by ext1; exact h' rfl /-- Rewriting equality in the dependent type `Ξ£ (c : Composition n), Ξ  (i : Fin c.length), Composition (c.blocksFun i)` in non-dependent terms with lists, requiring that the lists of blocks coincide. -/ theorem sigma_pi_composition_eq_iff (u v : Ξ£ c : Composition n, βˆ€ i : Fin c.length, Composition (c.blocksFun i)) : u = v ↔ (ofFn fun i => (u.2 i).blocks) = ofFn fun i => (v.2 i).blocks := by refine ⟨fun H => by rw [H], fun H => ?_⟩ rcases u with ⟨a, b⟩ rcases v with ⟨a', b'⟩ dsimp at H obtain rfl : a = a' := by ext1 have : map List.sum (ofFn fun i : Fin (Composition.length a) => (b i).blocks) = map List.sum (ofFn fun i : Fin (Composition.length a') => (b' i).blocks) := by rw [H] simp only [map_ofFn] at this change (ofFn fun i : Fin (Composition.length a) => (b i).blocks.sum) = ofFn fun i : Fin (Composition.length a') => (b' i).blocks.sum at this simpa [Composition.blocks_sum, Composition.ofFn_blocksFun] using this ext1 Β· rfl Β· simp only [heq_eq_eq, ofFn_inj] at H ⊒ ext1 i ext1 exact congrFun H i /-- When `a` is a composition of `n` and `b` is a composition of `a.length`, `a.gather b` is the composition of `n` obtained by gathering all the blocks of `a` corresponding to a block of `b`. For instance, if `a = [6, 5, 3, 5, 2]` and `b = [2, 3]`, one should gather together the first two blocks of `a` and its last three blocks, giving `a.gather b = [11, 10]`. -/ def gather (a : Composition n) (b : Composition a.length) : Composition n where blocks := (a.blocks.splitWrtComposition b).map sum blocks_pos := by rw [forall_mem_map] intro j hj suffices H : βˆ€ i ∈ j, 1 ≀ i from calc 0 < j.length := length_pos_of_mem_splitWrtComposition hj _ ≀ j.sum := length_le_sum_of_one_le _ H intro i hi apply a.one_le_blocks rw [← a.blocks.flatten_splitWrtComposition b] exact mem_flatten_of_mem hj hi blocks_sum := by rw [← sum_flatten, flatten_splitWrtComposition, a.blocks_sum] theorem length_gather (a : Composition n) (b : Composition a.length) : length (a.gather b) = b.length := show (map List.sum (a.blocks.splitWrtComposition b)).length = b.blocks.length by rw [length_map, length_splitWrtComposition] /-- An auxiliary function used in the definition of `sigmaEquivSigmaPi` below, associating to two compositions `a` of `n` and `b` of `a.length`, and an index `i` bounded by the length of `a.gather b`, the subcomposition of `a` made of those blocks belonging to the `i`-th block of `a.gather b`. -/ def sigmaCompositionAux (a : Composition n) (b : Composition a.length) (i : Fin (a.gather b).length) : Composition ((a.gather b).blocksFun i) where
blocks := (a.blocks.splitWrtComposition b)[i.val]'(by rw [length_splitWrtComposition, ← length_gather]; exact i.2) blocks_pos {i} hi := a.blocks_pos (by rw [← a.blocks.flatten_splitWrtComposition b]
Mathlib/Analysis/Analytic/Composition.lean
1,028
1,034
/- 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.Basic import Mathlib.Data.Finset.Image import Mathlib.Data.Multiset.Fold /-! # The fold operation for a commutative associative operation over a finset. -/ assert_not_exists Monoid namespace Finset open Multiset variable {Ξ± Ξ² Ξ³ : Type*} /-! ### fold -/ section Fold variable (op : Ξ² β†’ Ξ² β†’ Ξ²) [hc : Std.Commutative op] [ha : Std.Associative op] local notation a " * " b => op a b /-- `fold op b f s` folds the commutative associative operation `op` over the `f`-image of `s`, i.e. `fold (+) b f {1,2,3} = f 1 + f 2 + f 3 + b`. -/ def fold (b : Ξ²) (f : Ξ± β†’ Ξ²) (s : Finset Ξ±) : Ξ² := (s.1.map f).fold op b variable {op} {f : Ξ± β†’ Ξ²} {b : Ξ²} {s : Finset Ξ±} {a : Ξ±} @[simp] theorem fold_empty : (βˆ… : Finset Ξ±).fold op b f = b := rfl @[simp] theorem fold_cons (h : a βˆ‰ s) : (cons a s h).fold op b f = f a * s.fold op b f := by dsimp only [fold] rw [cons_val, Multiset.map_cons, fold_cons_left] @[simp] theorem fold_insert [DecidableEq Ξ±] (h : a βˆ‰ s) : (insert a s).fold op b f = f a * s.fold op b f := by unfold fold rw [insert_val, ndinsert_of_not_mem h, Multiset.map_cons, fold_cons_left] @[simp] theorem fold_singleton : ({a} : Finset Ξ±).fold op b f = f a * b := rfl @[simp] theorem fold_map {g : Ξ³ β†ͺ Ξ±} {s : Finset Ξ³} : (s.map g).fold op b f = s.fold op b (f ∘ g) := by simp only [fold, map, Multiset.map_map] @[simp] theorem fold_image [DecidableEq Ξ±] {g : Ξ³ β†’ Ξ±} {s : Finset Ξ³} (H : βˆ€ x ∈ s, βˆ€ y ∈ s, g x = g y β†’ x = y) : (s.image g).fold op b f = s.fold op b (f ∘ g) := by simp only [fold, image_val_of_injOn H, Multiset.map_map] @[congr] theorem fold_congr {g : Ξ± β†’ Ξ²} (H : βˆ€ x ∈ s, f x = g x) : s.fold op b f = s.fold op b g := by rw [fold, fold, map_congr rfl H] theorem fold_op_distrib {f g : Ξ± β†’ Ξ²} {b₁ bβ‚‚ : Ξ²} : (s.fold op (b₁ * bβ‚‚) fun x => f x * g x) = s.fold op b₁ f * s.fold op bβ‚‚ g := by simp only [fold, fold_distrib] theorem fold_const [hd : Decidable (s = βˆ…)] (c : Ξ²) (h : op c (op b c) = op b c) : Finset.fold op b (fun _ => c) s = if s = βˆ… then b else op b c := by classical induction' s using Finset.induction_on with x s hx IH generalizing hd Β· simp Β· simp only [Finset.fold_insert hx, IH, if_false, Finset.insert_ne_empty] split_ifs Β· rw [hc.comm] Β· exact h theorem fold_hom {op' : Ξ³ β†’ Ξ³ β†’ Ξ³} [Std.Commutative op'] [Std.Associative op'] {m : Ξ² β†’ Ξ³} (hm : βˆ€ x y, m (op x y) = op' (m x) (m y)) : (s.fold op' (m b) fun x => m (f x)) = m (s.fold op b f) := by rw [fold, fold, ← Multiset.fold_hom op hm, Multiset.map_map] simp only [Function.comp_apply] theorem fold_disjUnion {s₁ sβ‚‚ : Finset Ξ±} {b₁ bβ‚‚ : Ξ²} (h) : (s₁.disjUnion sβ‚‚ h).fold op (b₁ * bβ‚‚) f = s₁.fold op b₁ f * sβ‚‚.fold op bβ‚‚ f := (congr_arg _ <| Multiset.map_add _ _ _).trans (Multiset.fold_add _ _ _ _ _) theorem fold_union_inter [DecidableEq Ξ±] {s₁ sβ‚‚ : Finset Ξ±} {b₁ bβ‚‚ : Ξ²} : ((s₁ βˆͺ sβ‚‚).fold op b₁ f * (s₁ ∩ sβ‚‚).fold op bβ‚‚ f) = s₁.fold op bβ‚‚ f * sβ‚‚.fold op b₁ f := by unfold fold rw [← fold_add op, ← Multiset.map_add, union_val, inter_val, union_add_inter, Multiset.map_add, hc.comm, fold_add] @[simp] theorem fold_insert_idem [DecidableEq Ξ±] [hi : Std.IdempotentOp op] : (insert a s).fold op b f = f a * s.fold op b f := by by_cases h : a ∈ s Β· rw [← insert_erase h] simp [← ha.assoc, hi.idempotent] Β· apply fold_insert h theorem fold_image_idem [DecidableEq Ξ±] {g : Ξ³ β†’ Ξ±} {s : Finset Ξ³} [hi : Std.IdempotentOp op] : (image g s).fold op b f = s.fold op b (f ∘ g) := by induction' s using Finset.cons_induction with x xs hx ih Β· rw [fold_empty, image_empty, fold_empty] Β· haveI := Classical.decEq Ξ³ rw [fold_cons, cons_eq_insert, image_insert, fold_insert_idem, ih] simp only [Function.comp_apply] /-- A stronger version of `Finset.fold_ite`, but relies on an explicit proof of idempotency on the seed element, rather than relying on typeclass idempotency over the whole type. -/ theorem fold_ite' {g : Ξ± β†’ Ξ²} (hb : op b b = b) (p : Ξ± β†’ Prop) [DecidablePred p] : Finset.fold op b (fun i => ite (p i) (f i) (g i)) s = op (Finset.fold op b f (s.filter p)) (Finset.fold op b g (s.filter fun i => Β¬p i)) := by classical induction' s using Finset.induction_on with x s hx IH Β· simp [hb] Β· simp only [Finset.fold_insert hx] split_ifs with h Β· have : x βˆ‰ Finset.filter p s := by simp [hx] simp [Finset.filter_insert, h, Finset.fold_insert this, ha.assoc, IH] Β· have : x βˆ‰ Finset.filter (fun i => Β¬ p i) s := by simp [hx] simp [Finset.filter_insert, h, Finset.fold_insert this, IH, ← ha.assoc, hc.comm] /-- A weaker version of `Finset.fold_ite'`, relying on typeclass idempotency over the whole type, instead of solely on the seed element. However, this is easier to use because it does not generate side goals. -/ theorem fold_ite [Std.IdempotentOp op] {g : Ξ± β†’ Ξ²} (p : Ξ± β†’ Prop) [DecidablePred p] : Finset.fold op b (fun i => ite (p i) (f i) (g i)) s = op (Finset.fold op b f (s.filter p)) (Finset.fold op b g (s.filter fun i => Β¬p i)) := fold_ite' (Std.IdempotentOp.idempotent _) _ theorem fold_op_rel_iff_and {r : Ξ² β†’ Ξ² β†’ Prop} (hr : βˆ€ {x y z}, r x (op y z) ↔ r x y ∧ r x z) {c : Ξ²} : r c (s.fold op b f) ↔ r c b ∧ βˆ€ x ∈ s, r c (f x) := by classical induction' s using Finset.induction_on with a s ha IH Β· simp rw [Finset.fold_insert ha, hr, IH, ← and_assoc, @and_comm (r c (f a)), and_assoc] apply and_congr Iff.rfl constructor Β· rintro ⟨h₁, hβ‚‚βŸ© intro b hb rw [Finset.mem_insert] at hb rcases hb with (rfl | hb) <;> solve_by_elim Β· intro h constructor Β· exact h a (Finset.mem_insert_self _ _) Β· exact fun b hb => h b <| Finset.mem_insert_of_mem hb theorem fold_op_rel_iff_or {r : Ξ² β†’ Ξ² β†’ Prop} (hr : βˆ€ {x y z}, r x (op y z) ↔ r x y ∨ r x z) {c : Ξ²} : r c (s.fold op b f) ↔ r c b ∨ βˆƒ x ∈ s, r c (f x) := by classical induction' s using Finset.induction_on with a s ha IH Β· simp rw [Finset.fold_insert ha, hr, IH, ← or_assoc, @or_comm (r c (f a)), or_assoc] apply or_congr Iff.rfl constructor Β· rintro (h₁ | ⟨x, hx, hβ‚‚βŸ©) Β· use a simp [h₁] Β· refine ⟨x, by simp [hx], hβ‚‚βŸ© Β· rintro ⟨x, hx, h⟩ exact (mem_insert.mp hx).imp (fun hx => by rwa [hx] at h) (fun hx => ⟨x, hx, h⟩) @[simp] theorem fold_union_empty_singleton [DecidableEq Ξ±] (s : Finset Ξ±) : Finset.fold (Β· βˆͺ Β·) βˆ… singleton s = s := by induction' s using Finset.induction_on with a s has ih Β· simp only [fold_empty] Β· rw [fold_insert has, ih, insert_eq] theorem fold_sup_bot_singleton [DecidableEq Ξ±] (s : Finset Ξ±) : Finset.fold (Β· βŠ” Β·) βŠ₯ singleton s = s := fold_union_empty_singleton s section Order variable [LinearOrder Ξ²] (c : Ξ²) theorem le_fold_min : c ≀ s.fold min b f ↔ c ≀ b ∧ βˆ€ x ∈ s, c ≀ f x := fold_op_rel_iff_and le_min_iff theorem fold_min_le : s.fold min b f ≀ c ↔ b ≀ c ∨ βˆƒ x ∈ s, f x ≀ c := by show _ β‰₯ _ ↔ _ apply fold_op_rel_iff_or intro x y z show _ ≀ _ ↔ _ exact min_le_iff theorem lt_fold_min : c < s.fold min b f ↔ c < b ∧ βˆ€ x ∈ s, c < f x := fold_op_rel_iff_and lt_min_iff theorem fold_min_lt : s.fold min b f < c ↔ b < c ∨ βˆƒ x ∈ s, f x < c := by show _ > _ ↔ _ apply fold_op_rel_iff_or intro x y z show _ < _ ↔ _ exact min_lt_iff theorem fold_max_le : s.fold max b f ≀ c ↔ b ≀ c ∧ βˆ€ x ∈ s, f x ≀ c := by show _ β‰₯ _ ↔ _ apply fold_op_rel_iff_and intro x y z show _ ≀ _ ↔ _ exact max_le_iff theorem le_fold_max : c ≀ s.fold max b f ↔ c ≀ b ∨ βˆƒ x ∈ s, c ≀ f x := fold_op_rel_iff_or le_max_iff theorem fold_max_lt : s.fold max b f < c ↔ b < c ∧ βˆ€ x ∈ s, f x < c := by show _ > _ ↔ _ apply fold_op_rel_iff_and intro x y z show _ < _ ↔ _
exact max_lt_iff theorem lt_fold_max : c < s.fold max b f ↔ c < b ∨ βˆƒ x ∈ s, c < f x := fold_op_rel_iff_or lt_max_iff end Order
Mathlib/Data/Finset/Fold.lean
223
228
/- Copyright (c) 2018 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.BigOperators.Expect import Mathlib.Algebra.Order.BigOperators.Ring.Finset import Mathlib.Algebra.Order.Field.Canonical import Mathlib.Algebra.Order.Nonneg.Floor import Mathlib.Data.Real.Pointwise import Mathlib.Data.NNReal.Defs import Mathlib.Order.ConditionallyCompleteLattice.Group /-! # Basic results on nonnegative real numbers This file contains all results on `NNReal` that do not directly follow from its basic structure. As a consequence, it is a bit of a random collection of results, and is a good target for cleanup. ## Notations This file uses `ℝβ‰₯0` as a localized notation for `NNReal`. -/ assert_not_exists Star open Function open scoped BigOperators namespace NNReal noncomputable instance : FloorSemiring ℝβ‰₯0 := Nonneg.floorSemiring @[simp, norm_cast] theorem coe_indicator {Ξ±} (s : Set Ξ±) (f : Ξ± β†’ ℝβ‰₯0) (a : Ξ±) : ((s.indicator f a : ℝβ‰₯0) : ℝ) = s.indicator (fun x => ↑(f x)) a := (toRealHom : ℝβ‰₯0 β†’+ ℝ).map_indicator _ _ _ @[norm_cast] theorem coe_list_sum (l : List ℝβ‰₯0) : ((l.sum : ℝβ‰₯0) : ℝ) = (l.map (↑)).sum := map_list_sum toRealHom l @[norm_cast] theorem coe_list_prod (l : List ℝβ‰₯0) : ((l.prod : ℝβ‰₯0) : ℝ) = (l.map (↑)).prod := map_list_prod toRealHom l @[norm_cast] theorem coe_multiset_sum (s : Multiset ℝβ‰₯0) : ((s.sum : ℝβ‰₯0) : ℝ) = (s.map (↑)).sum := map_multiset_sum toRealHom s @[norm_cast] theorem coe_multiset_prod (s : Multiset ℝβ‰₯0) : ((s.prod : ℝβ‰₯0) : ℝ) = (s.map (↑)).prod := map_multiset_prod toRealHom s variable {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ ℝ} @[simp, norm_cast] theorem coe_sum (s : Finset ΞΉ) (f : ΞΉ β†’ ℝβ‰₯0) : βˆ‘ i ∈ s, f i = βˆ‘ i ∈ s, (f i : ℝ) := map_sum toRealHom _ _ @[simp, norm_cast] lemma coe_expect (s : Finset ΞΉ) (f : ΞΉ β†’ ℝβ‰₯0) : 𝔼 i ∈ s, f i = 𝔼 i ∈ s, (f i : ℝ) := map_expect toRealHom .. theorem _root_.Real.toNNReal_sum_of_nonneg (hf : βˆ€ i ∈ s, 0 ≀ f i) : Real.toNNReal (βˆ‘ a ∈ s, f a) = βˆ‘ a ∈ s, Real.toNNReal (f a) := by rw [← coe_inj, NNReal.coe_sum, Real.coe_toNNReal _ (Finset.sum_nonneg hf)] exact Finset.sum_congr rfl fun x hxs => by rw [Real.coe_toNNReal _ (hf x hxs)] @[simp, norm_cast] theorem coe_prod (s : Finset ΞΉ) (f : ΞΉ β†’ ℝβ‰₯0) : ↑(∏ a ∈ s, f a) = ∏ a ∈ s, (f a : ℝ) := map_prod toRealHom _ _ theorem _root_.Real.toNNReal_prod_of_nonneg (hf : βˆ€ a, a ∈ s β†’ 0 ≀ f a) : Real.toNNReal (∏ a ∈ s, f a) = ∏ a ∈ s, Real.toNNReal (f a) := by rw [← coe_inj, NNReal.coe_prod, Real.coe_toNNReal _ (Finset.prod_nonneg hf)] exact Finset.prod_congr rfl fun x hxs => by rw [Real.coe_toNNReal _ (hf x hxs)] theorem le_iInf_add_iInf {ΞΉ ΞΉ' : Sort*} [Nonempty ΞΉ] [Nonempty ΞΉ'] {f : ΞΉ β†’ ℝβ‰₯0} {g : ΞΉ' β†’ ℝβ‰₯0} {a : ℝβ‰₯0} (h : βˆ€ i j, a ≀ f i + g j) : a ≀ (β¨… i, f i) + β¨… j, g j := by rw [← NNReal.coe_le_coe, NNReal.coe_add, coe_iInf, coe_iInf] exact le_ciInf_add_ciInf h theorem mul_finset_sup {Ξ±} (r : ℝβ‰₯0) (s : Finset Ξ±) (f : Ξ± β†’ ℝβ‰₯0) : r * s.sup f = s.sup fun a => r * f a := Finset.comp_sup_eq_sup_comp _ (NNReal.mul_sup r) (mul_zero r) theorem finset_sup_mul {Ξ±} (s : Finset Ξ±) (f : Ξ± β†’ ℝβ‰₯0) (r : ℝβ‰₯0) : s.sup f * r = s.sup fun a => f a * r := Finset.comp_sup_eq_sup_comp (Β· * r) (fun x y => NNReal.sup_mul x y r) (zero_mul r) theorem finset_sup_div {Ξ±} {f : Ξ± β†’ ℝβ‰₯0} {s : Finset Ξ±} (r : ℝβ‰₯0) : s.sup f / r = s.sup fun a => f a / r := by simp only [div_eq_inv_mul, mul_finset_sup] open Real section Sub /-! ### Lemmas about subtraction In this section we provide a few lemmas about subtraction that do not fit well into any other typeclass. For lemmas about subtraction and addition see lemmas about `OrderedSub` in the file `Mathlib.Algebra.Order.Sub.Basic`. See also `mul_tsub` and `tsub_mul`. -/ theorem sub_div (a b c : ℝβ‰₯0) : (a - b) / c = a / c - b / c := tsub_div _ _ _ end Sub section Csupr open Set variable {ΞΉ : Sort*} {f : ΞΉ β†’ ℝβ‰₯0} theorem iInf_mul (f : ΞΉ β†’ ℝβ‰₯0) (a : ℝβ‰₯0) : iInf f * a = β¨… i, f i * a := by rw [← coe_inj, NNReal.coe_mul, coe_iInf, coe_iInf] exact Real.iInf_mul_of_nonneg (NNReal.coe_nonneg _) _ theorem mul_iInf (f : ΞΉ β†’ ℝβ‰₯0) (a : ℝβ‰₯0) : a * iInf f = β¨… i, a * f i := by simpa only [mul_comm] using iInf_mul f a theorem mul_iSup (f : ΞΉ β†’ ℝβ‰₯0) (a : ℝβ‰₯0) : (a * ⨆ i, f i) = ⨆ i, a * f i := by rw [← coe_inj, NNReal.coe_mul, NNReal.coe_iSup, NNReal.coe_iSup] exact Real.mul_iSup_of_nonneg (NNReal.coe_nonneg _) _ theorem iSup_mul (f : ΞΉ β†’ ℝβ‰₯0) (a : ℝβ‰₯0) : (⨆ i, f i) * a = ⨆ i, f i * a := by rw [mul_comm, mul_iSup] simp_rw [mul_comm] theorem iSup_div (f : ΞΉ β†’ ℝβ‰₯0) (a : ℝβ‰₯0) : (⨆ i, f i) / a = ⨆ i, f i / a := by simp only [div_eq_mul_inv, iSup_mul] theorem mul_iSup_le {a : ℝβ‰₯0} {g : ℝβ‰₯0} {h : ΞΉ β†’ ℝβ‰₯0} (H : βˆ€ j, g * h j ≀ a) : g * iSup h ≀ a := by rw [mul_iSup] exact ciSup_le' H theorem iSup_mul_le {a : ℝβ‰₯0} {g : ΞΉ β†’ ℝβ‰₯0} {h : ℝβ‰₯0} (H : βˆ€ i, g i * h ≀ a) : iSup g * h ≀ a := by rw [iSup_mul] exact ciSup_le' H theorem iSup_mul_iSup_le {a : ℝβ‰₯0} {g h : ΞΉ β†’ ℝβ‰₯0} (H : βˆ€ i j, g i * h j ≀ a) : iSup g * iSup h ≀ a := iSup_mul_le fun _ => mul_iSup_le <| H _ variable [Nonempty ΞΉ] theorem le_mul_iInf {a : ℝβ‰₯0} {g : ℝβ‰₯0} {h : ΞΉ β†’ ℝβ‰₯0} (H : βˆ€ j, a ≀ g * h j) : a ≀ g * iInf h := by rw [mul_iInf] exact le_ciInf H theorem le_iInf_mul {a : ℝβ‰₯0} {g : ΞΉ β†’ ℝβ‰₯0} {h : ℝβ‰₯0} (H : βˆ€ i, a ≀ g i * h) : a ≀ iInf g * h := by rw [iInf_mul] exact le_ciInf H theorem le_iInf_mul_iInf {a : ℝβ‰₯0} {g h : ΞΉ β†’ ℝβ‰₯0} (H : βˆ€ i j, a ≀ g i * h j) : a ≀ iInf g * iInf h := le_iInf_mul fun i => le_mul_iInf <| H i end Csupr end NNReal
Mathlib/Data/NNReal/Basic.lean
1,104
1,105
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.SpecialFunctions.Pow.NNReal import Mathlib.Analysis.SpecialFunctions.Pow.Continuity import Mathlib.Analysis.SumOverResidueClass /-! # Convergence of `p`-series In this file we prove that the series `βˆ‘' k in β„•, 1 / k ^ p` converges if and only if `p > 1`. The proof is based on the [Cauchy condensation test](https://en.wikipedia.org/wiki/Cauchy_condensation_test): `βˆ‘ k, f k` converges if and only if so does `βˆ‘ k, 2 ^ k f (2 ^ k)`. We prove this test in `NNReal.summable_condensed_iff` and `summable_condensed_iff_of_nonneg`, then use it to prove `summable_one_div_rpow`. After this transformation, a `p`-series turns into a geometric series. ## Tags p-series, Cauchy condensation test -/ /-! ### SchlΓΆmilch's generalization of the Cauchy condensation test In this section we prove the SchlΓΆmilch's generalization of the Cauchy condensation test: for a strictly increasing `u : β„• β†’ β„•` with ratio of successive differences bounded and an antitone `f : β„• β†’ ℝβ‰₯0` or `f : β„• β†’ ℝ`, `βˆ‘ k, f k` converges if and only if so does `βˆ‘ k, (u (k + 1) - u k) * f (u k)`. Instead of giving a monolithic proof, we split it into a series of lemmas with explicit estimates of partial sums of each series in terms of the partial sums of the other series. -/ /-- A sequence `u` has the property that its ratio of successive differences is bounded when there is a positive real number `C` such that, for all n ∈ β„•, (u (n + 2) - u (n + 1)) ≀ C * (u (n + 1) - u n) -/ def SuccDiffBounded (C : β„•) (u : β„• β†’ β„•) : Prop := βˆ€ n : β„•, u (n + 2) - u (n + 1) ≀ C β€’ (u (n + 1) - u n) namespace Finset variable {M : Type*} [AddCommMonoid M] [PartialOrder M] [IsOrderedAddMonoid M] {f : β„• β†’ M} {u : β„• β†’ β„•} theorem le_sum_schlomilch' (hf : βˆ€ ⦃m n⦄, 0 < m β†’ m ≀ n β†’ f n ≀ f m) (h_pos : βˆ€ n, 0 < u n) (hu : Monotone u) (n : β„•) : (βˆ‘ k ∈ Ico (u 0) (u n), f k) ≀ βˆ‘ k ∈ range n, (u (k + 1) - u k) β€’ f (u k) := by induction n with | zero => simp | succ n ihn => suffices (βˆ‘ k ∈ Ico (u n) (u (n + 1)), f k) ≀ (u (n + 1) - u n) β€’ f (u n) by rw [sum_range_succ, ← sum_Ico_consecutive] Β· exact add_le_add ihn this exacts [hu n.zero_le, hu n.le_succ] have : βˆ€ k ∈ Ico (u n) (u (n + 1)), f k ≀ f (u n) := fun k hk => hf (Nat.succ_le_of_lt (h_pos n)) (mem_Ico.mp hk).1 convert sum_le_sum this simp [pow_succ, mul_two] theorem le_sum_condensed' (hf : βˆ€ ⦃m n⦄, 0 < m β†’ m ≀ n β†’ f n ≀ f m) (n : β„•) : (βˆ‘ k ∈ Ico 1 (2 ^ n), f k) ≀ βˆ‘ k ∈ range n, 2 ^ k β€’ f (2 ^ k) := by convert le_sum_schlomilch' hf (fun n => pow_pos zero_lt_two n) (fun m n hm => pow_right_monoβ‚€ one_le_two hm) n using 2 simp [pow_succ, mul_two, two_mul] theorem le_sum_schlomilch (hf : βˆ€ ⦃m n⦄, 0 < m β†’ m ≀ n β†’ f n ≀ f m) (h_pos : βˆ€ n, 0 < u n) (hu : Monotone u) (n : β„•) : (βˆ‘ k ∈ range (u n), f k) ≀ βˆ‘ k ∈ range (u 0), f k + βˆ‘ k ∈ range n, (u (k + 1) - u k) β€’ f (u k) := by convert add_le_add_left (le_sum_schlomilch' hf h_pos hu n) (βˆ‘ k ∈ range (u 0), f k) rw [← sum_range_add_sum_Ico _ (hu n.zero_le)] theorem le_sum_condensed (hf : βˆ€ ⦃m n⦄, 0 < m β†’ m ≀ n β†’ f n ≀ f m) (n : β„•) : (βˆ‘ k ∈ range (2 ^ n), f k) ≀ f 0 + βˆ‘ k ∈ range n, 2 ^ k β€’ f (2 ^ k) := by convert add_le_add_left (le_sum_condensed' hf n) (f 0) rw [← sum_range_add_sum_Ico _ n.one_le_two_pow, sum_range_succ, sum_range_zero, zero_add] theorem sum_schlomilch_le' (hf : βˆ€ ⦃m n⦄, 1 < m β†’ m ≀ n β†’ f n ≀ f m) (h_pos : βˆ€ n, 0 < u n) (hu : Monotone u) (n : β„•) : (βˆ‘ k ∈ range n, (u (k + 1) - u k) β€’ f (u (k + 1))) ≀ βˆ‘ k ∈ Ico (u 0 + 1) (u n + 1), f k := by induction n with | zero => simp | succ n ihn => suffices (u (n + 1) - u n) β€’ f (u (n + 1)) ≀ βˆ‘ k ∈ Ico (u n + 1) (u (n + 1) + 1), f k by rw [sum_range_succ, ← sum_Ico_consecutive] exacts [add_le_add ihn this, (add_le_add_right (hu n.zero_le) _ : u 0 + 1 ≀ u n + 1), add_le_add_right (hu n.le_succ) _] have : βˆ€ k ∈ Ico (u n + 1) (u (n + 1) + 1), f (u (n + 1)) ≀ f k := fun k hk => hf (Nat.lt_of_le_of_lt (Nat.succ_le_of_lt (h_pos n)) <| (Nat.lt_succ_of_le le_rfl).trans_le (mem_Ico.mp hk).1) (Nat.le_of_lt_succ <| (mem_Ico.mp hk).2) convert sum_le_sum this simp [pow_succ, mul_two] theorem sum_condensed_le' (hf : βˆ€ ⦃m n⦄, 1 < m β†’ m ≀ n β†’ f n ≀ f m) (n : β„•) : (βˆ‘ k ∈ range n, 2 ^ k β€’ f (2 ^ (k + 1))) ≀ βˆ‘ k ∈ Ico 2 (2 ^ n + 1), f k := by convert sum_schlomilch_le' hf (fun n => pow_pos zero_lt_two n) (fun m n hm => pow_right_monoβ‚€ one_le_two hm) n using 2 simp [pow_succ, mul_two, two_mul] theorem sum_schlomilch_le {C : β„•} (hf : βˆ€ ⦃m n⦄, 1 < m β†’ m ≀ n β†’ f n ≀ f m) (h_pos : βˆ€ n, 0 < u n) (h_nonneg : βˆ€ n, 0 ≀ f n) (hu : Monotone u) (h_succ_diff : SuccDiffBounded C u) (n : β„•) : βˆ‘ k ∈ range (n + 1), (u (k + 1) - u k) β€’ f (u k) ≀ (u 1 - u 0) β€’ f (u 0) + C β€’ βˆ‘ k ∈ Ico (u 0 + 1) (u n + 1), f k := by rw [sum_range_succ', add_comm] gcongr suffices βˆ‘ k ∈ range n, (u (k + 2) - u (k + 1)) β€’ f (u (k + 1)) ≀ C β€’ βˆ‘ k ∈ range n, ((u (k + 1) - u k) β€’ f (u (k + 1))) by refine this.trans (nsmul_le_nsmul_right ?_ _) exact sum_schlomilch_le' hf h_pos hu n have : βˆ€ k ∈ range n, (u (k + 2) - u (k + 1)) β€’ f (u (k + 1)) ≀ C β€’ ((u (k + 1) - u k) β€’ f (u (k + 1))) := by intro k _ rw [smul_smul] gcongr Β· exact h_nonneg (u (k + 1)) exact mod_cast h_succ_diff k convert sum_le_sum this simp [smul_sum] theorem sum_condensed_le (hf : βˆ€ ⦃m n⦄, 1 < m β†’ m ≀ n β†’ f n ≀ f m) (n : β„•) : (βˆ‘ k ∈ range (n + 1), 2 ^ k β€’ f (2 ^ k)) ≀ f 1 + 2 β€’ βˆ‘ k ∈ Ico 2 (2 ^ n + 1), f k := by convert add_le_add_left (nsmul_le_nsmul_right (sum_condensed_le' hf n) 2) (f 1) simp [sum_range_succ', add_comm, pow_succ', mul_nsmul', sum_nsmul] end Finset namespace ENNReal open Filter Finset variable {u : β„• β†’ β„•} {f : β„• β†’ ℝβ‰₯0∞} open NNReal in theorem le_tsum_schlomilch (hf : βˆ€ ⦃m n⦄, 0 < m β†’ m ≀ n β†’ f n ≀ f m) (h_pos : βˆ€ n, 0 < u n) (hu : StrictMono u) : βˆ‘' k , f k ≀ βˆ‘ k ∈ range (u 0), f k + βˆ‘' k : β„•, (u (k + 1) - u k) * f (u k) := by rw [ENNReal.tsum_eq_iSup_nat' hu.tendsto_atTop] refine iSup_le fun n => (Finset.le_sum_schlomilch hf h_pos hu.monotone n).trans (add_le_add_left ?_ _) have (k : β„•) : (u (k + 1) - u k : ℝβ‰₯0∞) = (u (k + 1) - (u k : β„•) : β„•) := by simp [NNReal.coe_sub (Nat.cast_le (Ξ± := ℝβ‰₯0).mpr <| (hu k.lt_succ_self).le)] simp only [nsmul_eq_mul, this] apply ENNReal.sum_le_tsum theorem le_tsum_condensed (hf : βˆ€ ⦃m n⦄, 0 < m β†’ m ≀ n β†’ f n ≀ f m) : βˆ‘' k, f k ≀ f 0 + βˆ‘' k : β„•, 2 ^ k * f (2 ^ k) := by rw [ENNReal.tsum_eq_iSup_nat' (Nat.tendsto_pow_atTop_atTop_of_one_lt _root_.one_lt_two)] refine iSup_le fun n => (Finset.le_sum_condensed hf n).trans (add_le_add_left ?_ _) simp only [nsmul_eq_mul, Nat.cast_pow, Nat.cast_two] apply ENNReal.sum_le_tsum theorem tsum_schlomilch_le {C : β„•} (hf : βˆ€ ⦃m n⦄, 1 < m β†’ m ≀ n β†’ f n ≀ f m) (h_pos : βˆ€ n, 0 < u n) (h_nonneg : βˆ€ n, 0 ≀ f n) (hu : Monotone u) (h_succ_diff : SuccDiffBounded C u) : βˆ‘' k : β„•, (u (k + 1) - u k) * f (u k) ≀ (u 1 - u 0) * f (u 0) + C * βˆ‘' k, f k := by rw [ENNReal.tsum_eq_iSup_nat' (tendsto_atTop_mono Nat.le_succ tendsto_id)] refine iSup_le fun n => le_trans ?_ (add_le_add_left (mul_le_mul_of_nonneg_left (ENNReal.sum_le_tsum <| Finset.Ico (u 0 + 1) (u n + 1)) ?_) _) Β· simpa using Finset.sum_schlomilch_le hf h_pos h_nonneg hu h_succ_diff n Β· exact zero_le _ theorem tsum_condensed_le (hf : βˆ€ ⦃m n⦄, 1 < m β†’ m ≀ n β†’ f n ≀ f m) : (βˆ‘' k : β„•, 2 ^ k * f (2 ^ k)) ≀ f 1 + 2 * βˆ‘' k, f k := by rw [ENNReal.tsum_eq_iSup_nat' (tendsto_atTop_mono Nat.le_succ tendsto_id), two_mul, ← two_nsmul] refine iSup_le fun n => le_trans ?_ (add_le_add_left (nsmul_le_nsmul_right (ENNReal.sum_le_tsum <| Finset.Ico 2 (2 ^ n + 1)) _) _) simpa using Finset.sum_condensed_le hf n end ENNReal namespace NNReal open Finset open ENNReal in /-- for a series of `NNReal` version. -/ theorem summable_schlomilch_iff {C : β„•} {u : β„• β†’ β„•} {f : β„• β†’ ℝβ‰₯0} (hf : βˆ€ ⦃m n⦄, 0 < m β†’ m ≀ n β†’ f n ≀ f m) (h_pos : βˆ€ n, 0 < u n) (hu_strict : StrictMono u) (hC_nonzero : C β‰  0) (h_succ_diff : SuccDiffBounded C u) : (Summable fun k : β„• => (u (k + 1) - (u k : ℝβ‰₯0)) * f (u k)) ↔ Summable f := by simp only [← tsum_coe_ne_top_iff_summable, Ne, not_iff_not, ENNReal.coe_mul] constructor <;> intro h Β· replace hf : βˆ€ m n, 1 < m β†’ m ≀ n β†’ (f n : ℝβ‰₯0∞) ≀ f m := fun m n hm hmn => ENNReal.coe_le_coe.2 (hf (zero_lt_one.trans hm) hmn) have h_nonneg : βˆ€ n, 0 ≀ (f n : ℝβ‰₯0∞) := fun n => ENNReal.coe_le_coe.2 (f n).2 obtain hC := tsum_schlomilch_le hf h_pos h_nonneg hu_strict.monotone h_succ_diff simpa [add_eq_top, mul_ne_top, mul_eq_top, hC_nonzero] using eq_top_mono hC h Β· replace hf : βˆ€ m n, 0 < m β†’ m ≀ n β†’ (f n : ℝβ‰₯0∞) ≀ f m := fun m n hm hmn => ENNReal.coe_le_coe.2 (hf hm hmn) have : βˆ‘ k ∈ range (u 0), (f k : ℝβ‰₯0∞) β‰  ∞ := sum_ne_top.2 fun a _ => coe_ne_top simpa [h, add_eq_top, this] using le_tsum_schlomilch hf h_pos hu_strict open ENNReal in theorem summable_condensed_iff {f : β„• β†’ ℝβ‰₯0} (hf : βˆ€ ⦃m n⦄, 0 < m β†’ m ≀ n β†’ f n ≀ f m) : (Summable fun k : β„• => (2 : ℝβ‰₯0) ^ k * f (2 ^ k)) ↔ Summable f := by have h_succ_diff : SuccDiffBounded 2 (2 ^ Β·) := by intro n simp [pow_succ, mul_two, two_mul] convert summable_schlomilch_iff hf (pow_pos zero_lt_two) (pow_right_strictMonoβ‚€ _root_.one_lt_two) two_ne_zero h_succ_diff simp [pow_succ, mul_two, two_mul] end NNReal open NNReal in /-- for series of nonnegative real numbers. -/ theorem summable_schlomilch_iff_of_nonneg {C : β„•} {u : β„• β†’ β„•} {f : β„• β†’ ℝ} (h_nonneg : βˆ€ n, 0 ≀ f n) (hf : βˆ€ ⦃m n⦄, 0 < m β†’ m ≀ n β†’ f n ≀ f m) (h_pos : βˆ€ n, 0 < u n) (hu_strict : StrictMono u) (hC_nonzero : C β‰  0) (h_succ_diff : SuccDiffBounded C u) : (Summable fun k : β„• => (u (k + 1) - (u k : ℝ)) * f (u k)) ↔ Summable f := by lift f to β„• β†’ ℝβ‰₯0 using h_nonneg simp only [NNReal.coe_le_coe] at * have (k : β„•) : (u (k + 1) - (u k : ℝ)) = ((u (k + 1) : ℝβ‰₯0) - (u k : ℝβ‰₯0) : ℝβ‰₯0) := by have := Nat.cast_le (Ξ± := ℝβ‰₯0).mpr <| (hu_strict k.lt_succ_self).le simp [NNReal.coe_sub this] simp_rw [this] exact_mod_cast NNReal.summable_schlomilch_iff hf h_pos hu_strict hC_nonzero h_succ_diff /-- Cauchy condensation test for antitone series of nonnegative real numbers. -/ theorem summable_condensed_iff_of_nonneg {f : β„• β†’ ℝ} (h_nonneg : βˆ€ n, 0 ≀ f n) (h_mono : βˆ€ ⦃m n⦄, 0 < m β†’ m ≀ n β†’ f n ≀ f m) : (Summable fun k : β„• => (2 : ℝ) ^ k * f (2 ^ k)) ↔ Summable f := by have h_succ_diff : SuccDiffBounded 2 (2 ^ Β·) := by intro n simp [pow_succ, mul_two, two_mul] convert summable_schlomilch_iff_of_nonneg h_nonneg h_mono (pow_pos zero_lt_two) (pow_right_strictMonoβ‚€ one_lt_two) two_ne_zero h_succ_diff simp [pow_succ, mul_two, two_mul] section p_series /-! ### Convergence of the `p`-series In this section we prove that for a real number `p`, the series `βˆ‘' n : β„•, 1 / (n ^ p)` converges if and only if `1 < p`. There are many different proofs of this fact. The proof in this file uses the Cauchy condensation test we formalized above. This test implies that `βˆ‘ n, 1 / (n ^ p)` converges if and only if `βˆ‘ n, 2 ^ n / ((2 ^ n) ^ p)` converges, and the latter series is a geometric series with common ratio `2 ^ {1 - p}`. -/ namespace Real open Filter /-- Test for convergence of the `p`-series: the real-valued series `βˆ‘' n : β„•, (n ^ p)⁻¹` converges if and only if `1 < p`. -/ @[simp] theorem summable_nat_rpow_inv {p : ℝ} : Summable (fun n => ((n : ℝ) ^ p)⁻¹ : β„• β†’ ℝ) ↔ 1 < p := by rcases le_or_lt 0 p with hp | hp /- Cauchy condensation test applies only to antitone sequences, so we consider the cases `0 ≀ p` and `p < 0` separately. -/ Β· rw [← summable_condensed_iff_of_nonneg] Β· simp_rw [Nat.cast_pow, Nat.cast_two, ← rpow_natCast, ← rpow_mul zero_lt_two.le, mul_comm _ p, rpow_mul zero_lt_two.le, rpow_natCast, ← inv_pow, ← mul_pow, summable_geometric_iff_norm_lt_one] nth_rw 1 [← rpow_one 2] rw [← division_def, ← rpow_sub zero_lt_two, norm_eq_abs, abs_of_pos (rpow_pos_of_pos zero_lt_two _), rpow_lt_one_iff zero_lt_two.le] norm_num Β· intro n positivity Β· intro m n hm hmn gcongr -- If `p < 0`, then `1 / n ^ p` tends to infinity, thus the series diverges. Β· suffices Β¬Summable (fun n => ((n : ℝ) ^ p)⁻¹ : β„• β†’ ℝ) by have : Β¬1 < p := fun hp₁ => hp.not_le (zero_le_one.trans hp₁.le) simpa only [this, iff_false] intro h obtain ⟨k : β„•, hk₁ : ((k : ℝ) ^ p)⁻¹ < 1, hkβ‚€ : k β‰  0⟩ := ((h.tendsto_cofinite_zero.eventually (gt_mem_nhds zero_lt_one)).and (eventually_cofinite_ne 0)).exists apply hkβ‚€ rw [← pos_iff_ne_zero, ← @Nat.cast_pos ℝ] at hkβ‚€ simpa [inv_lt_oneβ‚€ (rpow_pos_of_pos hkβ‚€ _), one_lt_rpow_iff_of_pos hkβ‚€, hp, hp.not_lt, hkβ‚€] using hk₁ @[simp] theorem summable_nat_rpow {p : ℝ} : Summable (fun n => (n : ℝ) ^ p : β„• β†’ ℝ) ↔ p < -1 := by rcases neg_surjective p with ⟨p, rfl⟩ simp [rpow_neg] /-- Test for convergence of the `p`-series: the real-valued series `βˆ‘' n : β„•, 1 / n ^ p` converges if and only if `1 < p`. -/ theorem summable_one_div_nat_rpow {p : ℝ} : Summable (fun n => 1 / (n : ℝ) ^ p : β„• β†’ ℝ) ↔ 1 < p := by simp /-- Test for convergence of the `p`-series: the real-valued series `βˆ‘' n : β„•, (n ^ p)⁻¹` converges if and only if `1 < p`. -/ @[simp] theorem summable_nat_pow_inv {p : β„•} : Summable (fun n => ((n : ℝ) ^ p)⁻¹ : β„• β†’ ℝ) ↔ 1 < p := by simp only [← rpow_natCast, summable_nat_rpow_inv, Nat.one_lt_cast] /-- Test for convergence of the `p`-series: the real-valued series `βˆ‘' n : β„•, 1 / n ^ p` converges if and only if `1 < p`. -/ theorem summable_one_div_nat_pow {p : β„•} : Summable (fun n => 1 / (n : ℝ) ^ p : β„• β†’ ℝ) ↔ 1 < p := by simp only [one_div, Real.summable_nat_pow_inv] /-- Summability of the `p`-series over `β„€`. -/ theorem summable_one_div_int_pow {p : β„•} : (Summable fun n : β„€ ↦ 1 / (n : ℝ) ^ p) ↔ 1 < p := by refine ⟨fun h ↦ summable_one_div_nat_pow.mp (h.comp_injective Nat.cast_injective), fun h ↦ .of_nat_of_neg (summable_one_div_nat_pow.mpr h) (((summable_one_div_nat_pow.mpr h).mul_left <| 1 / (-1 : ℝ) ^ p).congr fun n ↦ ?_)⟩ rw [Int.cast_neg, Int.cast_natCast, neg_eq_neg_one_mul (n : ℝ), mul_pow, mul_one_div, div_div] theorem summable_abs_int_rpow {b : ℝ} (hb : 1 < b) : Summable fun n : β„€ => |(n : ℝ)| ^ (-b) := by apply Summable.of_nat_of_neg on_goal 2 => simp_rw [Int.cast_neg, abs_neg] all_goals simp_rw [Int.cast_natCast, fun n : β„• => abs_of_nonneg (n.cast_nonneg : 0 ≀ (n : ℝ))] rwa [summable_nat_rpow, neg_lt_neg_iff] /-- Harmonic series is not unconditionally summable. -/ theorem not_summable_natCast_inv : Β¬Summable (fun n => n⁻¹ : β„• β†’ ℝ) := by have : Β¬Summable (fun n => ((n : ℝ) ^ 1)⁻¹ : β„• β†’ ℝ) := mt (summable_nat_pow_inv (p := 1)).1 (lt_irrefl 1) simpa /-- Harmonic series is not unconditionally summable. -/ theorem not_summable_one_div_natCast : Β¬Summable (fun n => 1 / n : β„• β†’ ℝ) := by simpa only [inv_eq_one_div] using not_summable_natCast_inv /-- **Divergence of the Harmonic Series** -/ theorem tendsto_sum_range_one_div_nat_succ_atTop : Tendsto (fun n => βˆ‘ i ∈ Finset.range n, (1 / (i + 1) : ℝ)) atTop atTop := by rw [← not_summable_iff_tendsto_nat_atTop_of_nonneg] Β· exact_mod_cast mt (_root_.summable_nat_add_iff 1).1 not_summable_one_div_natCast Β· exact fun i => by positivity end Real namespace NNReal @[simp] theorem summable_rpow_inv {p : ℝ} : Summable (fun n => ((n : ℝβ‰₯0) ^ p)⁻¹ : β„• β†’ ℝβ‰₯0) ↔ 1 < p := by simp [← NNReal.summable_coe] @[simp] theorem summable_rpow {p : ℝ} : Summable (fun n => (n : ℝβ‰₯0) ^ p : β„• β†’ ℝβ‰₯0) ↔ p < -1 := by simp [← NNReal.summable_coe] theorem summable_one_div_rpow {p : ℝ} : Summable (fun n => 1 / (n : ℝβ‰₯0) ^ p : β„• β†’ ℝβ‰₯0) ↔ 1 < p := by simp
end NNReal end p_series
Mathlib/Analysis/PSeries.lean
363
367