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) 2021 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Data.Set.Basic import Mathlib.Tactic.Order /-! # Circular order hierarchy This file defines circular preorders, circular partial orders and circular orders. ## Hierarchy * A ternary "betweenness" relation `btw : α → α → α → Prop` forms a `CircularOrder` if it is - reflexive: `btw a a a` - cyclic: `btw a b c → btw b c a` - antisymmetric: `btw a b c → btw c b a → a = b ∨ b = c ∨ c = a` - total: `btw a b c ∨ btw c b a` along with a strict betweenness relation `sbtw : α → α → α → Prop` which respects `sbtw a b c ↔ btw a b c ∧ ¬ btw c b a`, analogously to how `<` and `≤` are related, and is - transitive: `sbtw a b c → sbtw b d c → sbtw a d c`. * A `CircularPartialOrder` drops totality. * A `CircularPreorder` further drops antisymmetry. The intuition is that a circular order is a circle and `btw a b c` means that going around clockwise from `a` you reach `b` before `c` (`b` is between `a` and `c` is meaningless on an unoriented circle). A circular partial order is several, potentially intersecting, circles. A circular preorder is like a circular partial order, but several points can coexist. Note that the relations between `CircularPreorder`, `CircularPartialOrder` and `CircularOrder` are subtler than between `Preorder`, `PartialOrder`, `LinearOrder`. In particular, one cannot simply extend the `Btw` of a `CircularPartialOrder` to make it a `CircularOrder`. One can translate from usual orders to circular ones by "closing the necklace at infinity". See `LE.toBtw` and `LT.toSBtw`. Going the other way involves "cutting the necklace" or "rolling the necklace open". ## Examples Some concrete circular orders one encounters in the wild are `ZMod n` for `0 < n`, `Circle`, `Real.Angle`... ## Main definitions * `Set.cIcc`: Closed-closed circular interval. * `Set.cIoo`: Open-open circular interval. ## Notes There's an unsolved diamond on `OrderDual α` here. The instances `LE α → Btw αᵒᵈ` and `LT α → SBtw αᵒᵈ` can each be inferred in two ways: * `LE α` → `Btw α` → `Btw αᵒᵈ` vs `LE α` → `LE αᵒᵈ` → `Btw αᵒᵈ` * `LT α` → `SBtw α` → `SBtw αᵒᵈ` vs `LT α` → `LT αᵒᵈ` → `SBtw αᵒᵈ` The fields are propeq, but not defeq. It is temporarily fixed by turning the circularizing instances into definitions. ## TODO Antisymmetry is quite weak in the sense that there's no way to discriminate which two points are equal. This prevents defining closed-open intervals `cIco` and `cIoc` in the neat `=`-less way. We currently haven't defined them at all. What is the correct generality of "rolling the necklace" open? At least, this works for `α × β` and `β × α` where `α` is a circular order and `β` is a linear order. What's next is to define circular groups and provide instances for `ZMod n`, the usual circle group `Circle`, and `RootsOfUnity M`. What conditions do we need on `M` for this last one to work? We should have circular order homomorphisms. The typical example is `daysToMonth : DaysOfTheYear →c MonthsOfTheYear` which relates the circular order of days and the circular order of months. Is `α →c β` a good notation? ## References * https://en.wikipedia.org/wiki/Cyclic_order * https://en.wikipedia.org/wiki/Partial_cyclic_order ## Tags circular order, cyclic order, circularly ordered set, cyclically ordered set -/ assert_not_exists RelIso /-- Syntax typeclass for a betweenness relation. -/ class Btw (α : Type*) where /-- Betweenness for circular orders. `btw a b c` states that `b` is between `a` and `c` (in that order). -/ btw : α → α → α → Prop export Btw (btw) /-- Syntax typeclass for a strict betweenness relation. -/ class SBtw (α : Type*) where /-- Strict betweenness for circular orders. `sbtw a b c` states that `b` is strictly between `a` and `c` (in that order). -/ sbtw : α → α → α → Prop export SBtw (sbtw) /-- A circular preorder is the analogue of a preorder where you can loop around. `≤` and `<` are replaced by ternary relations `btw` and `sbtw`. `btw` is reflexive and cyclic. `sbtw` is transitive. -/ class CircularPreorder (α : Type*) extends Btw α, SBtw α where /-- `a` is between `a` and `a`. -/ btw_refl (a : α) : btw a a a /-- If `b` is between `a` and `c`, then `c` is between `b` and `a`. This is motivated by imagining three points on a circle. -/ btw_cyclic_left {a b c : α} : btw a b c → btw b c a sbtw := fun a b c => btw a b c ∧ ¬btw c b a /-- Strict betweenness is given by betweenness in one direction and non-betweenness in the other. I.e., if `b` is between `a` and `c` but not between `c` and `a`, then we say `b` is strictly between `a` and `c`. -/ sbtw_iff_btw_not_btw {a b c : α} : sbtw a b c ↔ btw a b c ∧ ¬btw c b a := by intros; rfl /-- For any fixed `c`, `fun a b ↦ sbtw a b c` is a transitive relation. I.e., given `a` `b` `d` `c` in that "order", if we have `b` strictly between `a` and `c`, and `d` strictly between `b` and `c`, then `d` is strictly between `a` and `c`. -/ sbtw_trans_left {a b c d : α} : sbtw a b c → sbtw b d c → sbtw a d c export CircularPreorder (btw_refl btw_cyclic_left sbtw_trans_left) /-- A circular partial order is the analogue of a partial order where you can loop around. `≤` and `<` are replaced by ternary relations `btw` and `sbtw`. `btw` is reflexive, cyclic and antisymmetric. `sbtw` is transitive. -/ class CircularPartialOrder (α : Type*) extends CircularPreorder α where /-- If `b` is between `a` and `c` and also between `c` and `a`, then at least one pair of points among `a`, `b`, `c` are identical. -/ btw_antisymm {a b c : α} : btw a b c → btw c b a → a = b ∨ b = c ∨ c = a export CircularPartialOrder (btw_antisymm) /-- A circular order is the analogue of a linear order where you can loop around. `≤` and `<` are replaced by ternary relations `btw` and `sbtw`. `btw` is reflexive, cyclic, antisymmetric and total. `sbtw` is transitive. -/ class CircularOrder (α : Type*) extends CircularPartialOrder α where /-- For any triple of points, the second is between the other two one way or another. -/ btw_total : ∀ a b c : α, btw a b c ∨ btw c b a export CircularOrder (btw_total) /-! ### Circular preorders -/ section CircularPreorder variable {α : Type*} [CircularPreorder α] theorem btw_rfl {a : α} : btw a a a := btw_refl _ -- TODO: `alias` creates a def instead of a lemma (because `btw_cyclic_left` is a def). -- alias btw_cyclic_left ← Btw.btw.cyclic_left theorem Btw.btw.cyclic_left {a b c : α} (h : btw a b c) : btw b c a := btw_cyclic_left h theorem btw_cyclic_right {a b c : α} (h : btw a b c) : btw c a b := h.cyclic_left.cyclic_left alias Btw.btw.cyclic_right := btw_cyclic_right /-- The order of the `↔` has been chosen so that `rw [btw_cyclic]` cycles to the right while `rw [← btw_cyclic]` cycles to the left (thus following the prepended arrow). -/ theorem btw_cyclic {a b c : α} : btw a b c ↔ btw c a b := ⟨btw_cyclic_right, btw_cyclic_left⟩ theorem sbtw_iff_btw_not_btw {a b c : α} : sbtw a b c ↔ btw a b c ∧ ¬btw c b a := CircularPreorder.sbtw_iff_btw_not_btw theorem btw_of_sbtw {a b c : α} (h : sbtw a b c) : btw a b c := (sbtw_iff_btw_not_btw.1 h).1 alias SBtw.sbtw.btw := btw_of_sbtw theorem not_btw_of_sbtw {a b c : α} (h : sbtw a b c) : ¬btw c b a := (sbtw_iff_btw_not_btw.1 h).2 alias SBtw.sbtw.not_btw := not_btw_of_sbtw theorem not_sbtw_of_btw {a b c : α} (h : btw a b c) : ¬sbtw c b a := fun h' => h'.not_btw h alias Btw.btw.not_sbtw := not_sbtw_of_btw theorem sbtw_of_btw_not_btw {a b c : α} (habc : btw a b c) (hcba : ¬btw c b a) : sbtw a b c := sbtw_iff_btw_not_btw.2 ⟨habc, hcba⟩ alias Btw.btw.sbtw_of_not_btw := sbtw_of_btw_not_btw theorem sbtw_cyclic_left {a b c : α} (h : sbtw a b c) : sbtw b c a := h.btw.cyclic_left.sbtw_of_not_btw fun h' => h.not_btw h'.cyclic_left alias SBtw.sbtw.cyclic_left := sbtw_cyclic_left theorem sbtw_cyclic_right {a b c : α} (h : sbtw a b c) : sbtw c a b := h.cyclic_left.cyclic_left alias SBtw.sbtw.cyclic_right := sbtw_cyclic_right /-- The order of the `↔` has been chosen so that `rw [sbtw_cyclic]` cycles to the right while `rw [← sbtw_cyclic]` cycles to the left (thus following the prepended arrow). -/ theorem sbtw_cyclic {a b c : α} : sbtw a b c ↔ sbtw c a b := ⟨sbtw_cyclic_right, sbtw_cyclic_left⟩ -- TODO: `alias` creates a def instead of a lemma (because `sbtw_trans_left` is a def). -- alias btw_trans_left ← SBtw.sbtw.trans_left theorem SBtw.sbtw.trans_left {a b c d : α} (h : sbtw a b c) : sbtw b d c → sbtw a d c := sbtw_trans_left h theorem sbtw_trans_right {a b c d : α} (hbc : sbtw a b c) (hcd : sbtw a c d) : sbtw a b d := (hbc.cyclic_left.trans_left hcd.cyclic_left).cyclic_right alias SBtw.sbtw.trans_right := sbtw_trans_right theorem sbtw_asymm {a b c : α} (h : sbtw a b c) : ¬sbtw c b a := h.btw.not_sbtw alias SBtw.sbtw.not_sbtw := sbtw_asymm theorem sbtw_irrefl_left_right {a b : α} : ¬sbtw a b a := fun h => h.not_btw h.btw theorem sbtw_irrefl_left {a b : α} : ¬sbtw a a b := fun h => sbtw_irrefl_left_right h.cyclic_left theorem sbtw_irrefl_right {a b : α} : ¬sbtw a b b := fun h => sbtw_irrefl_left_right h.cyclic_right theorem sbtw_irrefl (a : α) : ¬sbtw a a a := sbtw_irrefl_left_right end CircularPreorder /-! ### Circular partial orders -/ section CircularPartialOrder variable {α : Type*} [CircularPartialOrder α] -- TODO: `alias` creates a def instead of a lemma (because `btw_antisymm` is a def). -- alias btw_antisymm ← Btw.btw.antisymm theorem Btw.btw.antisymm {a b c : α} (h : btw a b c) : btw c b a → a = b ∨ b = c ∨ c = a := btw_antisymm h end CircularPartialOrder /-! ### Circular orders -/ section CircularOrder variable {α : Type*} [CircularOrder α] theorem btw_refl_left_right (a b : α) : btw a b a := or_self_iff.1 (btw_total a b a) theorem btw_rfl_left_right {a b : α} : btw a b a := btw_refl_left_right _ _ theorem btw_refl_left (a b : α) : btw a a b := btw_rfl_left_right.cyclic_right theorem btw_rfl_left {a b : α} : btw a a b := btw_refl_left _ _ theorem btw_refl_right (a b : α) : btw a b b := btw_rfl_left_right.cyclic_left theorem btw_rfl_right {a b : α} : btw a b b := btw_refl_right _ _ theorem sbtw_iff_not_btw {a b c : α} : sbtw a b c ↔ ¬btw c b a := by rw [sbtw_iff_btw_not_btw] exact and_iff_right_of_imp (btw_total _ _ _).resolve_left theorem btw_iff_not_sbtw {a b c : α} : btw a b c ↔ ¬sbtw c b a := iff_not_comm.1 sbtw_iff_not_btw end CircularOrder /-! ### Circular intervals -/ namespace Set section CircularPreorder variable {α : Type*} [CircularPreorder α] /-- Closed-closed circular interval -/ def cIcc (a b : α) : Set α := { x | btw a x b } /-- Open-open circular interval -/ def cIoo (a b : α) : Set α := { x | sbtw a x b } @[simp] theorem mem_cIcc {a b x : α} : x ∈ cIcc a b ↔ btw a x b := Iff.rfl @[simp] theorem mem_cIoo {a b x : α} : x ∈ cIoo a b ↔ sbtw a x b := Iff.rfl end CircularPreorder section CircularOrder variable {α : Type*} [CircularOrder α]
theorem left_mem_cIcc (a b : α) : a ∈ cIcc a b := btw_rfl_left
Mathlib/Order/Circular.lean
315
317
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad -/ import Batteries.Data.List.Perm import Mathlib.Data.List.OfFn import Mathlib.Data.List.Nodup import Mathlib.Data.List.TakeWhile import Mathlib.Order.Fin.Basic /-! # Sorting algorithms on lists In this file we define `List.Sorted r l` to be an alias for `List.Pairwise r l`. This alias is preferred in the case that `r` is a `<` or `≤`-like relation. Then we define the sorting algorithm `List.insertionSort` and prove its correctness. -/ open List.Perm universe u v namespace List /-! ### The predicate `List.Sorted` -/ section Sorted variable {α : Type u} {r : α → α → Prop} {a : α} {l : List α} /-- `Sorted r l` is the same as `List.Pairwise r l`, preferred in the case that `r` is a `<` or `≤`-like relation (transitive and antisymmetric or asymmetric) -/ def Sorted := @Pairwise instance decidableSorted [DecidableRel r] (l : List α) : Decidable (Sorted r l) := List.instDecidablePairwise _ protected theorem Sorted.le_of_lt [Preorder α] {l : List α} (h : l.Sorted (· < ·)) : l.Sorted (· ≤ ·) := h.imp le_of_lt protected theorem Sorted.lt_of_le [PartialOrder α] {l : List α} (h₁ : l.Sorted (· ≤ ·)) (h₂ : l.Nodup) : l.Sorted (· < ·) := h₁.imp₂ (fun _ _ => lt_of_le_of_ne) h₂ protected theorem Sorted.ge_of_gt [Preorder α] {l : List α} (h : l.Sorted (· > ·)) : l.Sorted (· ≥ ·) := h.imp le_of_lt protected theorem Sorted.gt_of_ge [PartialOrder α] {l : List α} (h₁ : l.Sorted (· ≥ ·)) (h₂ : l.Nodup) : l.Sorted (· > ·) := h₁.imp₂ (fun _ _ => lt_of_le_of_ne) <| by simp_rw [ne_comm]; exact h₂ @[simp] theorem sorted_nil : Sorted r [] := Pairwise.nil theorem Sorted.of_cons : Sorted r (a :: l) → Sorted r l := Pairwise.of_cons theorem Sorted.tail {r : α → α → Prop} {l : List α} (h : Sorted r l) : Sorted r l.tail := Pairwise.tail h theorem rel_of_sorted_cons {a : α} {l : List α} : Sorted r (a :: l) → ∀ b ∈ l, r a b := rel_of_pairwise_cons nonrec theorem Sorted.cons {r : α → α → Prop} [IsTrans α r] {l : List α} {a b : α} (hab : r a b) (h : Sorted r (b :: l)) : Sorted r (a :: b :: l) := h.cons <| forall_mem_cons.2 ⟨hab, fun _ hx => _root_.trans hab <| rel_of_sorted_cons h _ hx⟩ theorem sorted_cons_cons {r : α → α → Prop} [IsTrans α r] {l : List α} {a b : α} : Sorted r (b :: a :: l) ↔ r b a ∧ Sorted r (a :: l) := by constructor · intro h exact ⟨rel_of_sorted_cons h _ mem_cons_self, h.of_cons⟩ · rintro ⟨h, ha⟩ exact ha.cons h theorem Sorted.head!_le [Inhabited α] [Preorder α] {a : α} {l : List α} (h : Sorted (· < ·) l) (ha : a ∈ l) : l.head! ≤ a := by rw [← List.cons_head!_tail (List.ne_nil_of_mem ha)] at h ha cases ha · exact le_rfl · exact le_of_lt (rel_of_sorted_cons h a (by assumption)) theorem Sorted.le_head! [Inhabited α] [Preorder α] {a : α} {l : List α} (h : Sorted (· > ·) l) (ha : a ∈ l) : a ≤ l.head! := by rw [← List.cons_head!_tail (List.ne_nil_of_mem ha)] at h ha cases ha · exact le_rfl · exact le_of_lt (rel_of_sorted_cons h a (by assumption)) @[simp] theorem sorted_cons {a : α} {l : List α} : Sorted r (a :: l) ↔ (∀ b ∈ l, r a b) ∧ Sorted r l := pairwise_cons protected theorem Sorted.nodup {r : α → α → Prop} [IsIrrefl α r] {l : List α} (h : Sorted r l) : Nodup l := Pairwise.nodup h protected theorem Sorted.filter {l : List α} (f : α → Bool) (h : Sorted r l) : Sorted r (filter f l) := h.sublist filter_sublist theorem eq_of_perm_of_sorted [IsAntisymm α r] {l₁ l₂ : List α} (hp : l₁ ~ l₂) (hs₁ : Sorted r l₁) (hs₂ : Sorted r l₂) : l₁ = l₂ := by induction hs₁ generalizing l₂ with | nil => exact hp.nil_eq | @cons a l₁ h₁ hs₁ IH => have : a ∈ l₂ := hp.subset mem_cons_self rcases append_of_mem this with ⟨u₂, v₂, rfl⟩ have hp' := (perm_cons a).1 (hp.trans perm_middle) obtain rfl := IH hp' (hs₂.sublist <| by simp) change a :: u₂ ++ v₂ = u₂ ++ ([a] ++ v₂) rw [← append_assoc] congr have : ∀ x ∈ u₂, x = a := fun x m => antisymm ((pairwise_append.1 hs₂).2.2 _ m a mem_cons_self) (h₁ _ (by simp [m])) rw [(@eq_replicate_iff _ a (length u₂ + 1) (a :: u₂)).2, (@eq_replicate_iff _ a (length u₂ + 1) (u₂ ++ [a])).2] <;> constructor <;> simp [iff_true_intro this, or_comm] theorem Sorted.eq_of_mem_iff [IsAntisymm α r] [IsIrrefl α r] {l₁ l₂ : List α} (h₁ : Sorted r l₁) (h₂ : Sorted r l₂) (h : ∀ a : α, a ∈ l₁ ↔ a ∈ l₂) : l₁ = l₂ := eq_of_perm_of_sorted ((perm_ext_iff_of_nodup h₁.nodup h₂.nodup).2 h) h₁ h₂ theorem sublist_of_subperm_of_sorted [IsAntisymm α r] {l₁ l₂ : List α} (hp : l₁ <+~ l₂) (hs₁ : l₁.Sorted r) (hs₂ : l₂.Sorted r) : l₁ <+ l₂ := by let ⟨_, h, h'⟩ := hp rwa [← eq_of_perm_of_sorted h (hs₂.sublist h') hs₁] @[simp 1100] -- Higher priority shortcut lemma. theorem sorted_singleton (a : α) : Sorted r [a] := by simp theorem sorted_lt_range (n : ℕ) : Sorted (· < ·) (range n) := by rw [Sorted, pairwise_iff_get] simp theorem sorted_replicate (n : ℕ) (a : α) : Sorted r (replicate n a) ↔ n ≤ 1 ∨ r a a := pairwise_replicate theorem sorted_le_replicate (n : ℕ) (a : α) [Preorder α] : Sorted (· ≤ ·) (replicate n a) := by simp [sorted_replicate] theorem sorted_le_range (n : ℕ) : Sorted (· ≤ ·) (range n) := (sorted_lt_range n).le_of_lt lemma sorted_lt_range' (a b) {s} (hs : s ≠ 0) : Sorted (· < ·) (range' a b s) := by induction b generalizing a with | zero => simp | succ n ih => rw [List.range'_succ] refine List.sorted_cons.mpr ⟨fun b hb ↦ ?_, @ih (a + s)⟩ exact lt_of_lt_of_le (Nat.lt_add_of_pos_right (Nat.zero_lt_of_ne_zero hs)) (List.left_le_of_mem_range' hb) lemma sorted_le_range' (a b s) : Sorted (· ≤ ·) (range' a b s) := by by_cases hs : s ≠ 0 · exact (sorted_lt_range' a b hs).le_of_lt · rw [ne_eq, Decidable.not_not] at hs simpa [hs] using sorted_le_replicate b a theorem Sorted.rel_get_of_lt {l : List α} (h : l.Sorted r) {a b : Fin l.length} (hab : a < b) : r (l.get a) (l.get b) := List.pairwise_iff_get.1 h _ _ hab theorem Sorted.rel_get_of_le [IsRefl α r] {l : List α} (h : l.Sorted r) {a b : Fin l.length} (hab : a ≤ b) : r (l.get a) (l.get b) := by obtain rfl | hlt := Fin.eq_or_lt_of_le hab; exacts [refl _, h.rel_get_of_lt hlt] theorem Sorted.rel_of_mem_take_of_mem_drop {l : List α} (h : List.Sorted r l) {k : ℕ} {x y : α} (hx : x ∈ List.take k l) (hy : y ∈ List.drop k l) : r x y := by obtain ⟨iy, hiy, rfl⟩ := getElem_of_mem hy obtain ⟨ix, hix, rfl⟩ := getElem_of_mem hx rw [getElem_take, getElem_drop] rw [length_take] at hix exact h.rel_get_of_lt (Nat.lt_add_right _ (Nat.lt_min.mp hix).left) /-- If a list is sorted with respect to a decidable relation, then it is sorted with respect to the corresponding Bool-valued relation. -/ theorem Sorted.decide [DecidableRel r] (l : List α) (h : Sorted r l) : Sorted (fun a b => decide (r a b) = true) l := by refine h.imp fun {a b} h => by simpa using h end Sorted section Monotone variable {n : ℕ} {α : Type u} {f : Fin n → α} open scoped Relator in theorem sorted_ofFn_iff {r : α → α → Prop} : (ofFn f).Sorted r ↔ ((· < ·) ⇒ r) f f := by simp_rw [Sorted, pairwise_iff_get, get_ofFn, Relator.LiftFun] exact Iff.symm (Fin.rightInverse_cast _).surjective.forall₂ variable [Preorder α] /-- The list `List.ofFn f` is strictly sorted with respect to `(· ≤ ·)` if and only if `f` is strictly monotone. -/ @[simp] theorem sorted_lt_ofFn_iff : (ofFn f).Sorted (· < ·) ↔ StrictMono f := sorted_ofFn_iff /-- The list `List.ofFn f` is strictly sorted with respect to `(· ≥ ·)` if and only if `f` is strictly antitone. -/ @[simp] theorem sorted_gt_ofFn_iff : (ofFn f).Sorted (· > ·) ↔ StrictAnti f := sorted_ofFn_iff /-- The list `List.ofFn f` is sorted with respect to `(· ≤ ·)` if and only if `f` is monotone. -/ @[simp] theorem sorted_le_ofFn_iff : (ofFn f).Sorted (· ≤ ·) ↔ Monotone f := sorted_ofFn_iff.trans monotone_iff_forall_lt.symm /-- The list obtained from a monotone tuple is sorted. -/ alias ⟨_, _root_.Monotone.ofFn_sorted⟩ := sorted_le_ofFn_iff /-- The list `List.ofFn f` is sorted with respect to `(· ≥ ·)` if and only if `f` is antitone. -/ @[simp] theorem sorted_ge_ofFn_iff : (ofFn f).Sorted (· ≥ ·) ↔ Antitone f := sorted_ofFn_iff.trans antitone_iff_forall_lt.symm /-- The list obtained from an antitone tuple is sorted. -/ alias ⟨_, _root_.Antitone.ofFn_sorted⟩ := sorted_ge_ofFn_iff end Monotone lemma Sorted.filterMap {α β : Type*} {p : α → Option β} {l : List α} {r : α → α → Prop} {r' : β → β → Prop} (hl : l.Sorted r) (hp : ∀ (a b : α) (c d : β), p a = some c → p b = some d → r a b → r' c d) : (l.filterMap p).Sorted r' := by induction l with | nil => simp | cons a l ih => rw [List.filterMap_cons] cases ha : p a with | none => exact ih (List.sorted_cons.mp hl).right | some b => rw [List.sorted_cons] refine ⟨fun x hx ↦ ?_, ih (List.sorted_cons.mp hl).right⟩ obtain ⟨u, hu, hu'⟩ := List.mem_filterMap.mp hx exact hp a u b x ha hu' <| (List.sorted_cons.mp hl).left u hu end List open List namespace RelEmbedding variable {α β : Type*} {ra : α → α → Prop} {rb : β → β → Prop} @[simp] theorem sorted_listMap (e : ra ↪r rb) {l : List α} : (l.map e).Sorted rb ↔ l.Sorted ra := by simp [Sorted, pairwise_map, e.map_rel_iff] @[simp] theorem sorted_swap_listMap (e : ra ↪r rb) {l : List α} : (l.map e).Sorted (Function.swap rb) ↔ l.Sorted (Function.swap ra) := by simp [Sorted, pairwise_map, e.map_rel_iff] end RelEmbedding namespace OrderEmbedding variable {α β : Type*} [Preorder α] [Preorder β] @[simp] theorem sorted_lt_listMap (e : α ↪o β) {l : List α} : (l.map e).Sorted (· < ·) ↔ l.Sorted (· < ·) := e.ltEmbedding.sorted_listMap @[simp] theorem sorted_gt_listMap (e : α ↪o β) {l : List α} : (l.map e).Sorted (· > ·) ↔ l.Sorted (· > ·) := e.ltEmbedding.sorted_swap_listMap end OrderEmbedding namespace RelIso variable {α β : Type*} {ra : α → α → Prop} {rb : β → β → Prop} @[simp] theorem sorted_listMap (e : ra ≃r rb) {l : List α} : (l.map e).Sorted rb ↔ l.Sorted ra := e.toRelEmbedding.sorted_listMap @[simp] theorem sorted_swap_listMap (e : ra ≃r rb) {l : List α} : (l.map e).Sorted (Function.swap rb) ↔ l.Sorted (Function.swap ra) := e.toRelEmbedding.sorted_swap_listMap
end RelIso namespace OrderIso variable {α β : Type*} [Preorder α] [Preorder β]
Mathlib/Data/List/Sort.lean
297
303
/- Copyright (c) 2024 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.Order.Hom.Ring import Mathlib.Data.ENat.Basic import Mathlib.SetTheory.Cardinal.Basic /-! # Conversion between `Cardinal` and `ℕ∞` In this file we define a coercion `Cardinal.ofENat : ℕ∞ → Cardinal` and a projection `Cardinal.toENat : Cardinal →+*o ℕ∞`. We also prove basic theorems about these definitions. ## Implementation notes We define `Cardinal.ofENat` as a function instead of a bundled homomorphism so that we can use it as a coercion and delaborate its application to `↑n`. We define `Cardinal.toENat` as a bundled homomorphism so that we can use all the theorems about homomorphisms without specializing them to this function. Since it is not registered as a coercion, the argument about delaboration does not apply. ## Keywords set theory, cardinals, extended natural numbers -/ assert_not_exists Field open Function Set universe u v namespace Cardinal /-- Coercion `ℕ∞ → Cardinal`. It sends natural numbers to natural numbers and `⊤` to `ℵ₀`. See also `Cardinal.ofENatHom` for a bundled homomorphism version. -/ @[coe] def ofENat : ℕ∞ → Cardinal | (n : ℕ) => n | ⊤ => ℵ₀ instance : Coe ENat Cardinal := ⟨Cardinal.ofENat⟩ @[simp, norm_cast] lemma ofENat_top : ofENat ⊤ = ℵ₀ := rfl @[simp, norm_cast] lemma ofENat_nat (n : ℕ) : ofENat n = n := rfl @[simp, norm_cast] lemma ofENat_zero : ofENat 0 = 0 := rfl @[simp, norm_cast] lemma ofENat_one : ofENat 1 = 1 := rfl @[simp, norm_cast] lemma ofENat_ofNat (n : ℕ) [n.AtLeastTwo] : ((ofNat(n) : ℕ∞) : Cardinal) = OfNat.ofNat n := rfl lemma ofENat_strictMono : StrictMono ofENat := WithTop.strictMono_iff.2 ⟨Nat.strictMono_cast, nat_lt_aleph0⟩ @[simp, norm_cast] lemma ofENat_lt_ofENat {m n : ℕ∞} : (m : Cardinal) < n ↔ m < n := ofENat_strictMono.lt_iff_lt @[gcongr, mono] alias ⟨_, ofENat_lt_ofENat_of_lt⟩ := ofENat_lt_ofENat @[simp, norm_cast] lemma ofENat_lt_aleph0 {m : ℕ∞} : (m : Cardinal) < ℵ₀ ↔ m < ⊤ := ofENat_lt_ofENat (n := ⊤) @[simp] lemma ofENat_lt_nat {m : ℕ∞} {n : ℕ} : ofENat m < n ↔ m < n := by norm_cast @[simp] lemma ofENat_lt_ofNat {m : ℕ∞} {n : ℕ} [n.AtLeastTwo] : ofENat m < ofNat(n) ↔ m < OfNat.ofNat n := ofENat_lt_nat @[simp] lemma nat_lt_ofENat {m : ℕ} {n : ℕ∞} : (m : Cardinal) < n ↔ m < n := by norm_cast @[simp] lemma ofENat_pos {m : ℕ∞} : 0 < (m : Cardinal) ↔ 0 < m := by norm_cast @[simp] lemma one_lt_ofENat {m : ℕ∞} : 1 < (m : Cardinal) ↔ 1 < m := by norm_cast @[simp, norm_cast] lemma ofNat_lt_ofENat {m : ℕ} [m.AtLeastTwo] {n : ℕ∞} : (ofNat(m) : Cardinal) < n ↔ OfNat.ofNat m < n := nat_lt_ofENat lemma ofENat_mono : Monotone ofENat := ofENat_strictMono.monotone @[simp, norm_cast] lemma ofENat_le_ofENat {m n : ℕ∞} : (m : Cardinal) ≤ n ↔ m ≤ n := ofENat_strictMono.le_iff_le @[gcongr, mono] alias ⟨_, ofENat_le_ofENat_of_le⟩ := ofENat_le_ofENat @[simp] lemma ofENat_le_aleph0 (n : ℕ∞) : ↑n ≤ ℵ₀ := ofENat_le_ofENat.2 le_top @[simp] lemma ofENat_le_nat {m : ℕ∞} {n : ℕ} : ofENat m ≤ n ↔ m ≤ n := by norm_cast @[simp] lemma ofENat_le_one {m : ℕ∞} : ofENat m ≤ 1 ↔ m ≤ 1 := by norm_cast @[simp] lemma ofENat_le_ofNat {m : ℕ∞} {n : ℕ} [n.AtLeastTwo] : ofENat m ≤ ofNat(n) ↔ m ≤ OfNat.ofNat n := ofENat_le_nat @[simp] lemma nat_le_ofENat {m : ℕ} {n : ℕ∞} : (m : Cardinal) ≤ n ↔ m ≤ n := by norm_cast @[simp] lemma one_le_ofENat {n : ℕ∞} : 1 ≤ (n : Cardinal) ↔ 1 ≤ n := by norm_cast @[simp] lemma ofNat_le_ofENat {m : ℕ} [m.AtLeastTwo] {n : ℕ∞} : (ofNat(m) : Cardinal) ≤ n ↔ OfNat.ofNat m ≤ n := nat_le_ofENat lemma ofENat_injective : Injective ofENat := ofENat_strictMono.injective @[simp, norm_cast] lemma ofENat_inj {m n : ℕ∞} : (m : Cardinal) = n ↔ m = n := ofENat_injective.eq_iff @[simp] lemma ofENat_eq_nat {m : ℕ∞} {n : ℕ} : (m : Cardinal) = n ↔ m = n := by norm_cast @[simp] lemma nat_eq_ofENat {m : ℕ} {n : ℕ∞} : (m : Cardinal) = n ↔ m = n := by norm_cast @[simp] lemma ofENat_eq_zero {m : ℕ∞} : (m : Cardinal) = 0 ↔ m = 0 := by norm_cast @[simp] lemma zero_eq_ofENat {m : ℕ∞} : 0 = (m : Cardinal) ↔ m = 0 := by norm_cast; apply eq_comm @[simp] lemma ofENat_eq_one {m : ℕ∞} : (m : Cardinal) = 1 ↔ m = 1 := by norm_cast @[simp] lemma one_eq_ofENat {m : ℕ∞} : 1 = (m : Cardinal) ↔ m = 1 := by norm_cast; apply eq_comm @[simp] lemma ofENat_eq_ofNat {m : ℕ∞} {n : ℕ} [n.AtLeastTwo] : (m : Cardinal) = ofNat(n) ↔ m = OfNat.ofNat n := ofENat_eq_nat @[simp] lemma ofNat_eq_ofENat {m : ℕ} {n : ℕ∞} [m.AtLeastTwo] : ofNat(m) = (n : Cardinal) ↔ OfNat.ofNat m = n := nat_eq_ofENat @[simp, norm_cast] lemma lift_ofENat : ∀ m : ℕ∞, lift.{u, v} m = m | (m : ℕ) => lift_natCast m | ⊤ => lift_aleph0 @[simp] lemma lift_lt_ofENat {x : Cardinal.{v}} {m : ℕ∞} : lift.{u} x < m ↔ x < m := by rw [← lift_ofENat.{u, v}, lift_lt] @[simp] lemma lift_le_ofENat {x : Cardinal.{v}} {m : ℕ∞} : lift.{u} x ≤ m ↔ x ≤ m := by rw [← lift_ofENat.{u, v}, lift_le] @[simp] lemma lift_eq_ofENat {x : Cardinal.{v}} {m : ℕ∞} : lift.{u} x = m ↔ x = m := by rw [← lift_ofENat.{u, v}, lift_inj] @[simp] lemma ofENat_lt_lift {x : Cardinal.{v}} {m : ℕ∞} : m < lift.{u} x ↔ m < x := by rw [← lift_ofENat.{u, v}, lift_lt] @[simp] lemma ofENat_le_lift {x : Cardinal.{v}} {m : ℕ∞} : m ≤ lift.{u} x ↔ m ≤ x := by rw [← lift_ofENat.{u, v}, lift_le] @[simp] lemma ofENat_eq_lift {x : Cardinal.{v}} {m : ℕ∞} : m = lift.{u} x ↔ m = x := by rw [← lift_ofENat.{u, v}, lift_inj] @[simp] lemma range_ofENat : range ofENat = Iic ℵ₀ := by refine (range_subset_iff.2 ofENat_le_aleph0).antisymm fun x (hx : x ≤ ℵ₀) ↦ ?_ rcases hx.lt_or_eq with hlt | rfl · lift x to ℕ using hlt exact mem_range_self (x : ℕ∞) · exact mem_range_self (⊤ : ℕ∞) instance : CanLift Cardinal ℕ∞ (↑) (· ≤ ℵ₀) where prf x := (Set.ext_iff.1 range_ofENat x).2 /-- Unbundled version of `Cardinal.toENat`. -/ noncomputable def toENatAux : Cardinal.{u} → ℕ∞ := extend Nat.cast Nat.cast fun _ ↦ ⊤ lemma toENatAux_nat (n : ℕ) : toENatAux n = n := Nat.cast_injective.extend_apply .. lemma toENatAux_zero : toENatAux 0 = 0 := toENatAux_nat 0 lemma toENatAux_eq_top {a : Cardinal} (ha : ℵ₀ ≤ a) : toENatAux a = ⊤ := extend_apply' _ _ _ fun ⟨n, hn⟩ ↦ ha.not_lt <| hn ▸ nat_lt_aleph0 n lemma toENatAux_ofENat : ∀ n : ℕ∞, toENatAux n = n | (n : ℕ) => toENatAux_nat n | ⊤ => toENatAux_eq_top le_rfl attribute [local simp] toENatAux_nat toENatAux_zero toENatAux_ofENat lemma toENatAux_gc : GaloisConnection (↑) toENatAux := fun n x ↦ by cases lt_or_le x ℵ₀ with | inl hx => lift x to ℕ using hx; simp | inr hx => simp [toENatAux_eq_top hx, (ofENat_le_aleph0 n).trans hx] theorem toENatAux_le_nat {x : Cardinal} {n : ℕ} : toENatAux x ≤ n ↔ x ≤ n := by cases lt_or_le x ℵ₀ with | inl hx => lift x to ℕ using hx; simp | inr hx => simp [toENatAux_eq_top hx, (nat_lt_aleph0 n).trans_le hx] lemma toENatAux_eq_nat {x : Cardinal} {n : ℕ} : toENatAux x = n ↔ x = n := by simp only [le_antisymm_iff, toENatAux_le_nat, ← toENatAux_gc _, ofENat_nat] lemma toENatAux_eq_zero {x : Cardinal} : toENatAux x = 0 ↔ x = 0 := toENatAux_eq_nat /-- Projection from cardinals to `ℕ∞`. Sends all infinite cardinals to `⊤`. We define this function as a bundled monotone ring homomorphism. -/ noncomputable def toENat : Cardinal.{u} →+*o ℕ∞ where toFun := toENatAux map_one' := toENatAux_nat 1 map_mul' x y := by wlog hle : x ≤ y; · rw [mul_comm, this y x (le_of_not_le hle), mul_comm] cases lt_or_le y ℵ₀ with | inl hy => lift x to ℕ using hle.trans_lt hy; lift y to ℕ using hy simp only [← Nat.cast_mul, toENatAux_nat] | inr hy => rcases eq_or_ne x 0 with rfl | hx · simp · simp only [toENatAux_eq_top hy] rw [toENatAux_eq_top, ENat.mul_top] · rwa [Ne, toENatAux_eq_zero] · exact le_mul_of_one_le_of_le (one_le_iff_ne_zero.2 hx) hy map_add' x y := by wlog hle : x ≤ y; · rw [add_comm, this y x (le_of_not_le hle), add_comm] cases lt_or_le y ℵ₀ with | inl hy => lift x to ℕ using hle.trans_lt hy; lift y to ℕ using hy simp only [← Nat.cast_add, toENatAux_nat] | inr hy => simp only [toENatAux_eq_top hy, add_top] exact toENatAux_eq_top <| le_add_left hy map_zero' := toENatAux_zero monotone' := toENatAux_gc.monotone_u /-- The coercion `Cardinal.ofENat` and the projection `Cardinal.toENat` form a Galois connection. See also `Cardinal.gciENat`. -/ lemma enat_gc : GaloisConnection (↑) toENat := toENatAux_gc @[simp] lemma toENat_ofENat (n : ℕ∞) : toENat n = n := toENatAux_ofENat n @[simp] lemma toENat_comp_ofENat : toENat ∘ (↑) = id := funext toENat_ofENat /-- The coercion `Cardinal.ofENat` and the projection `Cardinal.toENat` form a Galois coinsertion. -/ noncomputable def gciENat : GaloisCoinsertion (↑) toENat :=
enat_gc.toGaloisCoinsertion fun n ↦ (toENat_ofENat n).le lemma toENat_strictMonoOn : StrictMonoOn toENat (Iic ℵ₀) := by
Mathlib/SetTheory/Cardinal/ENat.lean
226
228
/- 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
478
486
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel, Jakob von Raumer -/ import Mathlib.Algebra.Group.Hom.Defs import Mathlib.Algebra.Group.Action.Units import Mathlib.Algebra.Module.End import Mathlib.CategoryTheory.Endomorphism import Mathlib.CategoryTheory.Limits.Shapes.Kernels import Mathlib.Algebra.BigOperators.Group.Finset.Defs /-! # Preadditive categories A preadditive category is a category in which `X ⟶ Y` is an abelian group in such a way that composition of morphisms is linear in both variables. This file contains a definition of preadditive category that directly encodes the definition given above. The definition could also be phrased as follows: A preadditive category is a category enriched over the category of Abelian groups. Once the general framework to state this in Lean is available, the contents of this file should become obsolete. ## Main results * Definition of preadditive categories and basic properties * In a preadditive category, `f : Q ⟶ R` is mono if and only if `g ≫ f = 0 → g = 0` for all composable `g`. * A preadditive category with kernels has equalizers. ## Implementation notes The simp normal form for negation and composition is to push negations as far as possible to the outside. For example, `f ≫ (-g)` and `(-f) ≫ g` both become `-(f ≫ g)`, and `(-f) ≫ (-g)` is simplified to `f ≫ g`. ## References * [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2] ## Tags additive, preadditive, Hom group, Ab-category, Ab-enriched -/ universe v u open CategoryTheory.Limits namespace CategoryTheory variable (C : Type u) [Category.{v} C] /-- A category is called preadditive if `P ⟶ Q` is an abelian group such that composition is linear in both variables. -/ @[stacks 00ZY] class Preadditive where homGroup : ∀ P Q : C, AddCommGroup (P ⟶ Q) := by infer_instance add_comp : ∀ (P Q R : C) (f f' : P ⟶ Q) (g : Q ⟶ R), (f + f') ≫ g = f ≫ g + f' ≫ g := by aesop_cat comp_add : ∀ (P Q R : C) (f : P ⟶ Q) (g g' : Q ⟶ R), f ≫ (g + g') = f ≫ g + f ≫ g' := by aesop_cat attribute [inherit_doc Preadditive] Preadditive.homGroup Preadditive.add_comp Preadditive.comp_add attribute [instance] Preadditive.homGroup -- simp can already prove reassoc version attribute [reassoc, simp] Preadditive.add_comp attribute [reassoc] Preadditive.comp_add attribute [simp] Preadditive.comp_add end CategoryTheory open CategoryTheory namespace CategoryTheory namespace Preadditive section Preadditive open AddMonoidHom variable {C : Type u} [Category.{v} C] [Preadditive C] section InducedCategory universe u' variable {D : Type u'} (F : D → C) instance inducedCategory : Preadditive.{v} (InducedCategory C F) where homGroup P Q := @Preadditive.homGroup C _ _ (F P) (F Q) add_comp _ _ _ _ _ _ := add_comp _ _ _ _ _ _ comp_add _ _ _ _ _ _ := comp_add _ _ _ _ _ _ end InducedCategory instance fullSubcategory (Z : ObjectProperty C) : Preadditive Z.FullSubcategory where homGroup P Q := @Preadditive.homGroup C _ _ P.obj Q.obj add_comp _ _ _ _ _ _ := add_comp _ _ _ _ _ _ comp_add _ _ _ _ _ _ := comp_add _ _ _ _ _ _ instance (X : C) : AddCommGroup (End X) := by dsimp [End] infer_instance /-- Composition by a fixed left argument as a group homomorphism -/ def leftComp {P Q : C} (R : C) (f : P ⟶ Q) : (Q ⟶ R) →+ (P ⟶ R) := mk' (fun g => f ≫ g) fun g g' => by simp /-- Composition by a fixed right argument as a group homomorphism -/ def rightComp (P : C) {Q R : C} (g : Q ⟶ R) : (P ⟶ Q) →+ (P ⟶ R) := mk' (fun f => f ≫ g) fun f f' => by simp variable {P Q R : C} (f f' : P ⟶ Q) (g g' : Q ⟶ R) /-- Composition as a bilinear group homomorphism -/ def compHom : (P ⟶ Q) →+ (Q ⟶ R) →+ (P ⟶ R) := AddMonoidHom.mk' (fun f => leftComp _ f) fun f₁ f₂ => AddMonoidHom.ext fun g => (rightComp _ g).map_add f₁ f₂ -- simp can prove the reassoc version @[reassoc, simp] theorem sub_comp : (f - f') ≫ g = f ≫ g - f' ≫ g := map_sub (rightComp P g) f f' -- simp can prove the reassoc version @[reassoc, simp] theorem comp_sub : f ≫ (g - g') = f ≫ g - f ≫ g' := map_sub (leftComp R f) g g' -- simp can prove the reassoc version @[reassoc, simp] theorem neg_comp : (-f) ≫ g = -f ≫ g := map_neg (rightComp P g) f -- simp can prove the reassoc version @[reassoc, simp] theorem comp_neg : f ≫ (-g) = -f ≫ g := map_neg (leftComp R f) g @[reassoc] theorem neg_comp_neg : (-f) ≫ (-g) = f ≫ g := by simp theorem nsmul_comp (n : ℕ) : (n • f) ≫ g = n • f ≫ g := map_nsmul (rightComp P g) n f theorem comp_nsmul (n : ℕ) : f ≫ (n • g) = n • f ≫ g := map_nsmul (leftComp R f) n g theorem zsmul_comp (n : ℤ) : (n • f) ≫ g = n • f ≫ g := map_zsmul (rightComp P g) n f theorem comp_zsmul (n : ℤ) : f ≫ (n • g) = n • f ≫ g := map_zsmul (leftComp R f) n g @[reassoc] theorem comp_sum {P Q R : C} {J : Type*} (s : Finset J) (f : P ⟶ Q) (g : J → (Q ⟶ R)) : (f ≫ ∑ j ∈ s, g j) = ∑ j ∈ s, f ≫ g j := map_sum (leftComp R f) _ _ @[reassoc] theorem sum_comp {P Q R : C} {J : Type*} (s : Finset J) (f : J → (P ⟶ Q)) (g : Q ⟶ R) : (∑ j ∈ s, f j) ≫ g = ∑ j ∈ s, f j ≫ g := map_sum (rightComp P g) _ _ @[reassoc] theorem sum_comp' {P Q R S : C} {J : Type*} (s : Finset J) (f : J → (P ⟶ Q)) (g : J → (Q ⟶ R)) (h : R ⟶ S) : (∑ j ∈ s, f j ≫ g j) ≫ h = ∑ j ∈ s, f j ≫ g j ≫ h := by simp only [← Category.assoc] apply sum_comp instance {P Q : C} {f : P ⟶ Q} [Epi f] : Epi (-f) := ⟨fun g g' H => by rwa [neg_comp, neg_comp, ← comp_neg, ← comp_neg, cancel_epi, neg_inj] at H⟩ instance {P Q : C} {f : P ⟶ Q} [Mono f] : Mono (-f) := ⟨fun g g' H => by rwa [comp_neg, comp_neg, ← neg_comp, ← neg_comp, cancel_mono, neg_inj] at H⟩ instance (priority := 100) preadditiveHasZeroMorphisms : HasZeroMorphisms C where zero := inferInstance comp_zero f R := show leftComp R f 0 = 0 from map_zero _ zero_comp P _ _ f := show rightComp P f 0 = 0 from map_zero _ /-- Porting note: adding this before the ring instance allowed moduleEndRight to find the correct Monoid structure on End. Moved both down after preadditiveHasZeroMorphisms to make use of them -/ instance {X : C} : Semiring (End X) := { End.monoid with zero_mul := fun f => by dsimp [mul]; exact HasZeroMorphisms.comp_zero f _ mul_zero := fun f => by dsimp [mul]; exact HasZeroMorphisms.zero_comp _ f left_distrib := fun f g h => Preadditive.add_comp X X X g h f right_distrib := fun f g h => Preadditive.comp_add X X X h f g } /-- Porting note: It looks like Ring's parent classes changed in Lean 4 so the previous instance needed modification. Was following my nose here. -/ instance {X : C} : Ring (End X) := { (inferInstance : Semiring (End X)), (inferInstance : AddCommGroup (End X)) with neg_add_cancel := neg_add_cancel } instance moduleEndRight {X Y : C} : Module (End Y) (X ⟶ Y) where smul_add _ _ _ := add_comp _ _ _ _ _ _ smul_zero _ := zero_comp add_smul _ _ _ := comp_add _ _ _ _ _ _ zero_smul _ := comp_zero theorem mono_of_cancel_zero {Q R : C} (f : Q ⟶ R) (h : ∀ {P : C} (g : P ⟶ Q), g ≫ f = 0 → g = 0) : Mono f where right_cancellation := fun {Z} g₁ g₂ hg => sub_eq_zero.1 <| h _ <| (map_sub (rightComp Z f) g₁ g₂).trans <| sub_eq_zero.2 hg theorem mono_iff_cancel_zero {Q R : C} (f : Q ⟶ R) : Mono f ↔ ∀ (P : C) (g : P ⟶ Q), g ≫ f = 0 → g = 0 := ⟨fun _ _ _ => zero_of_comp_mono _, mono_of_cancel_zero f⟩ theorem mono_of_kernel_zero {X Y : C} {f : X ⟶ Y} [HasLimit (parallelPair f 0)] (w : kernel.ι f = 0) : Mono f := mono_of_cancel_zero f fun g h => by rw [← kernel.lift_ι f g h, w, Limits.comp_zero] lemma mono_of_isZero_kernel' {X Y : C} {f : X ⟶ Y} (c : KernelFork f) (hc : IsLimit c) (h : IsZero c.pt) : Mono f := mono_of_cancel_zero _ (fun g hg => by obtain ⟨a, ha⟩ := KernelFork.IsLimit.lift' hc _ hg rw [← ha, h.eq_of_tgt a 0, Limits.zero_comp]) lemma mono_of_isZero_kernel {X Y : C} (f : X ⟶ Y) [HasKernel f] (h : IsZero (kernel f)) : Mono f := mono_of_isZero_kernel' _ (kernelIsKernel _) h theorem epi_of_cancel_zero {P Q : C} (f : P ⟶ Q) (h : ∀ {R : C} (g : Q ⟶ R), f ≫ g = 0 → g = 0) : Epi f := ⟨fun {Z} g g' hg => sub_eq_zero.1 <| h _ <| (map_sub (leftComp Z f) g g').trans <| sub_eq_zero.2 hg⟩ theorem epi_iff_cancel_zero {P Q : C} (f : P ⟶ Q) : Epi f ↔ ∀ (R : C) (g : Q ⟶ R), f ≫ g = 0 → g = 0 := ⟨fun _ _ _ => zero_of_epi_comp _, epi_of_cancel_zero f⟩ theorem epi_of_cokernel_zero {X Y : C} {f : X ⟶ Y} [HasColimit (parallelPair f 0)] (w : cokernel.π f = 0) : Epi f := epi_of_cancel_zero f fun g h => by rw [← cokernel.π_desc f g h, w, Limits.zero_comp] lemma epi_of_isZero_cokernel' {X Y : C} {f : X ⟶ Y} (c : CokernelCofork f) (hc : IsColimit c) (h : IsZero c.pt) : Epi f := epi_of_cancel_zero _ (fun g hg => by obtain ⟨a, ha⟩ := CokernelCofork.IsColimit.desc' hc _ hg rw [← ha, h.eq_of_src a 0, Limits.comp_zero]) lemma epi_of_isZero_cokernel {X Y : C} (f : X ⟶ Y) [HasCokernel f] (h : IsZero (cokernel f)) : Epi f := epi_of_isZero_cokernel' _ (cokernelIsCokernel _) h namespace IsIso @[simp] theorem comp_left_eq_zero [IsIso f] : f ≫ g = 0 ↔ g = 0 := by rw [← IsIso.eq_inv_comp, Limits.comp_zero] @[simp] theorem comp_right_eq_zero [IsIso g] : f ≫ g = 0 ↔ f = 0 := by rw [← IsIso.eq_comp_inv, Limits.zero_comp] end IsIso open ZeroObject variable [HasZeroObject C] theorem mono_of_kernel_iso_zero {X Y : C} {f : X ⟶ Y} [HasLimit (parallelPair f 0)] (w : kernel f ≅ 0) : Mono f := mono_of_kernel_zero (zero_of_source_iso_zero _ w) theorem epi_of_cokernel_iso_zero {X Y : C} {f : X ⟶ Y} [HasColimit (parallelPair f 0)] (w : cokernel f ≅ 0) : Epi f := epi_of_cokernel_zero (zero_of_target_iso_zero _ w) end Preadditive section Equalizers variable {C : Type u} [Category.{v} C] [Preadditive C] section variable {X Y : C} {f : X ⟶ Y} {g : X ⟶ Y} /-- Map a kernel cone on the difference of two morphisms to the equalizer fork. -/ @[simps! pt] def forkOfKernelFork (c : KernelFork (f - g)) : Fork f g := Fork.ofι c.ι <| by rw [← sub_eq_zero, ← comp_sub, c.condition] @[simp] theorem forkOfKernelFork_ι (c : KernelFork (f - g)) : (forkOfKernelFork c).ι = c.ι := rfl /-- Map any equalizer fork to a cone on the difference of the two morphisms. -/ def kernelForkOfFork (c : Fork f g) : KernelFork (f - g) := Fork.ofι c.ι <| by rw [comp_sub, comp_zero, sub_eq_zero, c.condition] @[simp] theorem kernelForkOfFork_ι (c : Fork f g) : (kernelForkOfFork c).ι = c.ι := rfl @[simp] theorem kernelForkOfFork_ofι {P : C} (ι : P ⟶ X) (w : ι ≫ f = ι ≫ g) : kernelForkOfFork (Fork.ofι ι w) = KernelFork.ofι ι (by simp [w]) := rfl /-- A kernel of `f - g` is an equalizer of `f` and `g`. -/ def isLimitForkOfKernelFork {c : KernelFork (f - g)} (i : IsLimit c) : IsLimit (forkOfKernelFork c) := Fork.IsLimit.mk' _ fun s => ⟨i.lift (kernelForkOfFork s), i.fac _ _, fun h => by apply Fork.IsLimit.hom_ext i; aesop_cat⟩ @[simp] theorem isLimitForkOfKernelFork_lift {c : KernelFork (f - g)} (i : IsLimit c) (s : Fork f g) : (isLimitForkOfKernelFork i).lift s = i.lift (kernelForkOfFork s) := rfl /-- An equalizer of `f` and `g` is a kernel of `f - g`. -/ def isLimitKernelForkOfFork {c : Fork f g} (i : IsLimit c) : IsLimit (kernelForkOfFork c) := Fork.IsLimit.mk' _ fun s => ⟨i.lift (forkOfKernelFork s), i.fac _ _, fun h => by apply Fork.IsLimit.hom_ext i; aesop_cat⟩ variable (f g) /-- A preadditive category has an equalizer for `f` and `g` if it has a kernel for `f - g`. -/ theorem hasEqualizer_of_hasKernel [HasKernel (f - g)] : HasEqualizer f g := HasLimit.mk { cone := forkOfKernelFork _ isLimit := isLimitForkOfKernelFork (equalizerIsEqualizer (f - g) 0) } /-- A preadditive category has a kernel for `f - g` if it has an equalizer for `f` and `g`. -/ theorem hasKernel_of_hasEqualizer [HasEqualizer f g] : HasKernel (f - g) := HasLimit.mk { cone := kernelForkOfFork (equalizer.fork f g) isLimit := isLimitKernelForkOfFork (limit.isLimit (parallelPair f g)) } variable {f g} /-- Map a cokernel cocone on the difference of two morphisms to the coequalizer cofork. -/ @[simps! pt] def coforkOfCokernelCofork (c : CokernelCofork (f - g)) : Cofork f g := Cofork.ofπ c.π <| by rw [← sub_eq_zero, ← sub_comp, c.condition] @[simp] theorem coforkOfCokernelCofork_π (c : CokernelCofork (f - g)) : (coforkOfCokernelCofork c).π = c.π := rfl /-- Map any coequalizer cofork to a cocone on the difference of the two morphisms. -/ def cokernelCoforkOfCofork (c : Cofork f g) : CokernelCofork (f - g) := Cofork.ofπ c.π <| by rw [sub_comp, zero_comp, sub_eq_zero, c.condition] @[simp] theorem cokernelCoforkOfCofork_π (c : Cofork f g) : (cokernelCoforkOfCofork c).π = c.π := rfl @[simp] theorem cokernelCoforkOfCofork_ofπ {P : C} (π : Y ⟶ P) (w : f ≫ π = g ≫ π) : cokernelCoforkOfCofork (Cofork.ofπ π w) = CokernelCofork.ofπ π (by simp [w]) := rfl /-- A cokernel of `f - g` is a coequalizer of `f` and `g`. -/ def isColimitCoforkOfCokernelCofork {c : CokernelCofork (f - g)} (i : IsColimit c) : IsColimit (coforkOfCokernelCofork c) := Cofork.IsColimit.mk' _ fun s => ⟨i.desc (cokernelCoforkOfCofork s), i.fac _ _, fun h => by apply Cofork.IsColimit.hom_ext i; aesop_cat⟩ @[simp] theorem isColimitCoforkOfCokernelCofork_desc {c : CokernelCofork (f - g)} (i : IsColimit c) (s : Cofork f g) : (isColimitCoforkOfCokernelCofork i).desc s = i.desc (cokernelCoforkOfCofork s) := rfl /-- A coequalizer of `f` and `g` is a cokernel of `f - g`. -/ def isColimitCokernelCoforkOfCofork {c : Cofork f g} (i : IsColimit c) : IsColimit (cokernelCoforkOfCofork c) := Cofork.IsColimit.mk' _ fun s => ⟨i.desc (coforkOfCokernelCofork s), i.fac _ _, fun h => by apply Cofork.IsColimit.hom_ext i; aesop_cat⟩ variable (f g) /-- A preadditive category has a coequalizer for `f` and `g` if it has a cokernel for `f - g`. -/ theorem hasCoequalizer_of_hasCokernel [HasCokernel (f - g)] : HasCoequalizer f g := HasColimit.mk { cocone := coforkOfCokernelCofork _ isColimit := isColimitCoforkOfCokernelCofork (coequalizerIsCoequalizer (f - g) 0) } /-- A preadditive category has a cokernel for `f - g` if it has a coequalizer for `f` and `g`. -/ theorem hasCokernel_of_hasCoequalizer [HasCoequalizer f g] : HasCokernel (f - g) := HasColimit.mk { cocone := cokernelCoforkOfCofork (coequalizer.cofork f g) isColimit := isColimitCokernelCoforkOfCofork (colimit.isColimit (parallelPair f g)) } end
/-- If a preadditive category has all kernels, then it also has all equalizers. -/ theorem hasEqualizers_of_hasKernels [HasKernels C] : HasEqualizers C := @hasEqualizers_of_hasLimit_parallelPair _ _ fun {_} {_} f g => hasEqualizer_of_hasKernel f g
Mathlib/CategoryTheory/Preadditive/Basic.lean
403
405
/- 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.Ring.Associated import Mathlib.Algebra.Star.Unitary import Mathlib.RingTheory.PrincipalIdealDomain import Mathlib.Tactic.Ring import Mathlib.Algebra.EuclideanDomain.Int /-! # ℤ[√d] The ring of integers adjoined with a square root of `d : ℤ`. After defining the norm, we show that it is a linearly ordered commutative ring, as well as an integral domain. We provide the universal property, that ring homomorphisms `ℤ√d →+* R` correspond to choices of square roots of `d` in `R`. -/ /-- The ring of integers adjoined with a square root of `d`. These have the form `a + b √d` where `a b : ℤ`. The components are called `re` and `im` by analogy to the negative `d` case. -/ @[ext] structure Zsqrtd (d : ℤ) where /-- Component of the integer not multiplied by `√d` -/ re : ℤ /-- Component of the integer multiplied by `√d` -/ im : ℤ deriving DecidableEq @[inherit_doc] prefix:100 "ℤ√" => Zsqrtd namespace Zsqrtd section variable {d : ℤ} /-- Convert an integer to a `ℤ√d` -/ def ofInt (n : ℤ) : ℤ√d := ⟨n, 0⟩ theorem ofInt_re (n : ℤ) : (ofInt n : ℤ√d).re = n := rfl theorem ofInt_im (n : ℤ) : (ofInt n : ℤ√d).im = 0 := rfl /-- The zero of the ring -/ instance : Zero (ℤ√d) := ⟨ofInt 0⟩ @[simp] theorem zero_re : (0 : ℤ√d).re = 0 := rfl @[simp] theorem zero_im : (0 : ℤ√d).im = 0 := rfl instance : Inhabited (ℤ√d) := ⟨0⟩ /-- The one of the ring -/ instance : One (ℤ√d) := ⟨ofInt 1⟩ @[simp] theorem one_re : (1 : ℤ√d).re = 1 := rfl @[simp] theorem one_im : (1 : ℤ√d).im = 0 := rfl /-- The representative of `√d` in the ring -/ def sqrtd : ℤ√d := ⟨0, 1⟩ @[simp] theorem sqrtd_re : (sqrtd : ℤ√d).re = 0 := rfl @[simp] theorem sqrtd_im : (sqrtd : ℤ√d).im = 1 := rfl /-- Addition of elements of `ℤ√d` -/ instance : Add (ℤ√d) := ⟨fun z w => ⟨z.1 + w.1, z.2 + w.2⟩⟩ @[simp] theorem add_def (x y x' y' : ℤ) : (⟨x, y⟩ + ⟨x', y'⟩ : ℤ√d) = ⟨x + x', y + y'⟩ := rfl @[simp] theorem add_re (z w : ℤ√d) : (z + w).re = z.re + w.re := rfl @[simp] theorem add_im (z w : ℤ√d) : (z + w).im = z.im + w.im := rfl /-- Negation in `ℤ√d` -/ instance : Neg (ℤ√d) := ⟨fun z => ⟨-z.1, -z.2⟩⟩ @[simp] theorem neg_re (z : ℤ√d) : (-z).re = -z.re := rfl @[simp] theorem neg_im (z : ℤ√d) : (-z).im = -z.im := rfl /-- Multiplication in `ℤ√d` -/ instance : Mul (ℤ√d) := ⟨fun z w => ⟨z.1 * w.1 + d * z.2 * w.2, z.1 * w.2 + z.2 * w.1⟩⟩ @[simp] theorem mul_re (z w : ℤ√d) : (z * w).re = z.re * w.re + d * z.im * w.im := rfl @[simp] theorem mul_im (z w : ℤ√d) : (z * w).im = z.re * w.im + z.im * w.re := rfl instance addCommGroup : AddCommGroup (ℤ√d) := by refine { add := (· + ·) zero := (0 : ℤ√d) sub := fun a b => a + -b neg := Neg.neg nsmul := @nsmulRec (ℤ√d) ⟨0⟩ ⟨(· + ·)⟩ zsmul := @zsmulRec (ℤ√d) ⟨0⟩ ⟨(· + ·)⟩ ⟨Neg.neg⟩ (@nsmulRec (ℤ√d) ⟨0⟩ ⟨(· + ·)⟩) add_assoc := ?_ zero_add := ?_ add_zero := ?_ neg_add_cancel := ?_ add_comm := ?_ } <;> intros <;> ext <;> simp [add_comm, add_left_comm] @[simp] theorem sub_re (z w : ℤ√d) : (z - w).re = z.re - w.re := rfl @[simp] theorem sub_im (z w : ℤ√d) : (z - w).im = z.im - w.im := rfl instance addGroupWithOne : AddGroupWithOne (ℤ√d) := { Zsqrtd.addCommGroup with natCast := fun n => ofInt n intCast := ofInt one := 1 } instance commRing : CommRing (ℤ√d) := by refine { Zsqrtd.addGroupWithOne with mul := (· * ·) npow := @npowRec (ℤ√d) ⟨1⟩ ⟨(· * ·)⟩, add_comm := ?_ left_distrib := ?_ right_distrib := ?_ zero_mul := ?_ mul_zero := ?_ mul_assoc := ?_ one_mul := ?_ mul_one := ?_ mul_comm := ?_ } <;> intros <;> ext <;> simp <;> ring instance : AddMonoid (ℤ√d) := by infer_instance instance : Monoid (ℤ√d) := by infer_instance instance : CommMonoid (ℤ√d) := by infer_instance instance : CommSemigroup (ℤ√d) := by infer_instance instance : Semigroup (ℤ√d) := by infer_instance instance : AddCommSemigroup (ℤ√d) := by infer_instance instance : AddSemigroup (ℤ√d) := by infer_instance instance : CommSemiring (ℤ√d) := by infer_instance instance : Semiring (ℤ√d) := by infer_instance instance : Ring (ℤ√d) := by infer_instance instance : Distrib (ℤ√d) := by infer_instance /-- Conjugation in `ℤ√d`. The conjugate of `a + b √d` is `a - b √d`. -/ instance : Star (ℤ√d) where star z := ⟨z.1, -z.2⟩ @[simp] theorem star_mk (x y : ℤ) : star (⟨x, y⟩ : ℤ√d) = ⟨x, -y⟩ := rfl @[simp] theorem star_re (z : ℤ√d) : (star z).re = z.re := rfl @[simp] theorem star_im (z : ℤ√d) : (star z).im = -z.im := rfl instance : StarRing (ℤ√d) where star_involutive _ := Zsqrtd.ext rfl (neg_neg _) star_mul a b := by ext <;> simp <;> ring star_add _ _ := Zsqrtd.ext rfl (neg_add _ _) -- Porting note: proof was `by decide` instance nontrivial : Nontrivial (ℤ√d) := ⟨⟨0, 1, Zsqrtd.ext_iff.not.mpr (by simp)⟩⟩ @[simp] theorem natCast_re (n : ℕ) : (n : ℤ√d).re = n := rfl @[simp] theorem ofNat_re (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℤ√d).re = n := rfl @[simp] theorem natCast_im (n : ℕ) : (n : ℤ√d).im = 0 := rfl @[simp] theorem ofNat_im (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℤ√d).im = 0 := rfl theorem natCast_val (n : ℕ) : (n : ℤ√d) = ⟨n, 0⟩ := rfl @[simp] theorem intCast_re (n : ℤ) : (n : ℤ√d).re = n := by cases n <;> rfl @[simp] theorem intCast_im (n : ℤ) : (n : ℤ√d).im = 0 := by cases n <;> rfl theorem intCast_val (n : ℤ) : (n : ℤ√d) = ⟨n, 0⟩ := by ext <;> simp instance : CharZero (ℤ√d) where cast_injective m n := by simp [Zsqrtd.ext_iff] @[simp] theorem ofInt_eq_intCast (n : ℤ) : (ofInt n : ℤ√d) = n := by ext <;> simp [ofInt_re, ofInt_im] @[simp] theorem nsmul_val (n : ℕ) (x y : ℤ) : (n : ℤ√d) * ⟨x, y⟩ = ⟨n * x, n * y⟩ := by ext <;> simp @[simp] theorem smul_val (n x y : ℤ) : (n : ℤ√d) * ⟨x, y⟩ = ⟨n * x, n * y⟩ := by ext <;> simp theorem smul_re (a : ℤ) (b : ℤ√d) : (↑a * b).re = a * b.re := by simp theorem smul_im (a : ℤ) (b : ℤ√d) : (↑a * b).im = a * b.im := by simp @[simp] theorem muld_val (x y : ℤ) : sqrtd (d := d) * ⟨x, y⟩ = ⟨d * y, x⟩ := by ext <;> simp @[simp] theorem dmuld : sqrtd (d := d) * sqrtd (d := d) = d := by ext <;> simp @[simp] theorem smuld_val (n x y : ℤ) : sqrtd * (n : ℤ√d) * ⟨x, y⟩ = ⟨d * n * y, n * x⟩ := by ext <;> simp theorem decompose {x y : ℤ} : (⟨x, y⟩ : ℤ√d) = x + sqrtd (d := d) * y := by ext <;> simp theorem mul_star {x y : ℤ} : (⟨x, y⟩ * star ⟨x, y⟩ : ℤ√d) = x * x - d * y * y := by ext <;> simp [sub_eq_add_neg, mul_comm] theorem intCast_dvd (z : ℤ) (a : ℤ√d) : ↑z ∣ a ↔ z ∣ a.re ∧ z ∣ a.im := by constructor · rintro ⟨x, rfl⟩ simp only [add_zero, intCast_re, zero_mul, mul_im, dvd_mul_right, and_self_iff, mul_re, mul_zero, intCast_im] · rintro ⟨⟨r, hr⟩, ⟨i, hi⟩⟩ use ⟨r, i⟩ rw [smul_val, Zsqrtd.ext_iff] exact ⟨hr, hi⟩ @[simp, norm_cast] theorem intCast_dvd_intCast (a b : ℤ) : (a : ℤ√d) ∣ b ↔ a ∣ b := by rw [intCast_dvd] constructor · rintro ⟨hre, -⟩ rwa [intCast_re] at hre · rw [intCast_re, intCast_im] exact fun hc => ⟨hc, dvd_zero a⟩ protected theorem eq_of_smul_eq_smul_left {a : ℤ} {b c : ℤ√d} (ha : a ≠ 0) (h : ↑a * b = a * c) : b = c := by rw [Zsqrtd.ext_iff] at h ⊢ apply And.imp _ _ h <;> simpa only [smul_re, smul_im] using mul_left_cancel₀ ha section Gcd theorem gcd_eq_zero_iff (a : ℤ√d) : Int.gcd a.re a.im = 0 ↔ a = 0 := by simp only [Int.gcd_eq_zero_iff, Zsqrtd.ext_iff, eq_self_iff_true, zero_im, zero_re] theorem gcd_pos_iff (a : ℤ√d) : 0 < Int.gcd a.re a.im ↔ a ≠ 0 := pos_iff_ne_zero.trans <| not_congr a.gcd_eq_zero_iff theorem isCoprime_of_dvd_isCoprime {a b : ℤ√d} (hcoprime : IsCoprime a.re a.im) (hdvd : b ∣ a) : IsCoprime b.re b.im := by apply isCoprime_of_dvd · rintro ⟨hre, him⟩ obtain rfl : b = 0 := Zsqrtd.ext hre him rw [zero_dvd_iff] at hdvd simp [hdvd, zero_im, zero_re, not_isCoprime_zero_zero] at hcoprime · rintro z hz - hzdvdu hzdvdv apply hz obtain ⟨ha, hb⟩ : z ∣ a.re ∧ z ∣ a.im := by rw [← intCast_dvd] apply dvd_trans _ hdvd rw [intCast_dvd] exact ⟨hzdvdu, hzdvdv⟩ exact hcoprime.isUnit_of_dvd' ha hb @[deprecated (since := "2025-01-23")] alias coprime_of_dvd_coprime := isCoprime_of_dvd_isCoprime theorem exists_coprime_of_gcd_pos {a : ℤ√d} (hgcd : 0 < Int.gcd a.re a.im) : ∃ b : ℤ√d, a = ((Int.gcd a.re a.im : ℤ) : ℤ√d) * b ∧ IsCoprime b.re b.im := by obtain ⟨re, im, H1, Hre, Him⟩ := Int.exists_gcd_one hgcd rw [mul_comm] at Hre Him refine ⟨⟨re, im⟩, ?_, ?_⟩ · rw [smul_val, ← Hre, ← Him] · rw [Int.isCoprime_iff_gcd_eq_one, H1] end Gcd /-- Read `SqLe a c b d` as `a √c ≤ b √d` -/ def SqLe (a c b d : ℕ) : Prop := c * a * a ≤ d * b * b theorem sqLe_of_le {c d x y z w : ℕ} (xz : z ≤ x) (yw : y ≤ w) (xy : SqLe x c y d) : SqLe z c w d := le_trans (mul_le_mul (Nat.mul_le_mul_left _ xz) xz (Nat.zero_le _) (Nat.zero_le _)) <| le_trans xy (mul_le_mul (Nat.mul_le_mul_left _ yw) yw (Nat.zero_le _) (Nat.zero_le _)) theorem sqLe_add_mixed {c d x y z w : ℕ} (xy : SqLe x c y d) (zw : SqLe z c w d) : c * (x * z) ≤ d * (y * w) := Nat.mul_self_le_mul_self_iff.1 <| by simpa [mul_comm, mul_left_comm] using mul_le_mul xy zw (Nat.zero_le _) (Nat.zero_le _) theorem sqLe_add {c d x y z w : ℕ} (xy : SqLe x c y d) (zw : SqLe z c w d) : SqLe (x + z) c (y + w) d := by have xz := sqLe_add_mixed xy zw simp? [SqLe, mul_assoc] at xy zw says simp only [SqLe, mul_assoc] at xy zw simp [SqLe, mul_add, mul_comm, mul_left_comm, add_le_add, *] theorem sqLe_cancel {c d x y z w : ℕ} (zw : SqLe y d x c) (h : SqLe (x + z) c (y + w) d) : SqLe z c w d := by apply le_of_not_gt intro l refine not_le_of_gt ?_ h simp only [SqLe, mul_add, mul_comm, mul_left_comm, add_assoc, gt_iff_lt] have hm := sqLe_add_mixed zw (le_of_lt l) simp only [SqLe, mul_assoc, gt_iff_lt] at l zw exact lt_of_le_of_lt (add_le_add_right zw _) (add_lt_add_left (add_lt_add_of_le_of_lt hm (add_lt_add_of_le_of_lt hm l)) _) theorem sqLe_smul {c d x y : ℕ} (n : ℕ) (xy : SqLe x c y d) : SqLe (n * x) c (n * y) d := by simpa [SqLe, mul_left_comm, mul_assoc] using Nat.mul_le_mul_left (n * n) xy theorem sqLe_mul {d x y z w : ℕ} : (SqLe x 1 y d → SqLe z 1 w d → SqLe (x * w + y * z) d (x * z + d * y * w) 1) ∧ (SqLe x 1 y d → SqLe w d z 1 → SqLe (x * z + d * y * w) 1 (x * w + y * z) d) ∧ (SqLe y d x 1 → SqLe z 1 w d → SqLe (x * z + d * y * w) 1 (x * w + y * z) d) ∧ (SqLe y d x 1 → SqLe w d z 1 → SqLe (x * w + y * z) d (x * z + d * y * w) 1) := by refine ⟨?_, ?_, ?_, ?_⟩ <;> · intro xy zw have := Int.mul_nonneg (sub_nonneg_of_le (Int.ofNat_le_ofNat_of_le xy)) (sub_nonneg_of_le (Int.ofNat_le_ofNat_of_le zw)) refine Int.le_of_ofNat_le_ofNat (le_of_sub_nonneg ?_) convert this using 1 simp only [one_mul, Int.natCast_add, Int.natCast_mul] ring open Int in /-- "Generalized" `nonneg`. `nonnegg c d x y` means `a √c + b √d ≥ 0`; we are interested in the case `c = 1` but this is more symmetric -/ def Nonnegg (c d : ℕ) : ℤ → ℤ → Prop | (a : ℕ), (b : ℕ) => True | (a : ℕ), -[b+1] => SqLe (b + 1) c a d | -[a+1], (b : ℕ) => SqLe (a + 1) d b c | -[_+1], -[_+1] => False theorem nonnegg_comm {c d : ℕ} {x y : ℤ} : Nonnegg c d x y = Nonnegg d c y x := by cases x <;> cases y <;> rfl theorem nonnegg_neg_pos {c d} : ∀ {a b : ℕ}, Nonnegg c d (-a) b ↔ SqLe a d b c | 0, b => ⟨by simp [SqLe, Nat.zero_le], fun _ => trivial⟩ | a + 1, b => by rfl theorem nonnegg_pos_neg {c d} {a b : ℕ} : Nonnegg c d a (-b) ↔ SqLe b c a d := by rw [nonnegg_comm]; exact nonnegg_neg_pos open Int in theorem nonnegg_cases_right {c d} {a : ℕ} : ∀ {b : ℤ}, (∀ x : ℕ, b = -x → SqLe x c a d) → Nonnegg c d a b | (b : Nat), _ => trivial | -[b+1], h => h (b + 1) rfl theorem nonnegg_cases_left {c d} {b : ℕ} {a : ℤ} (h : ∀ x : ℕ, a = -x → SqLe x d b c) : Nonnegg c d a b := cast nonnegg_comm (nonnegg_cases_right h) section Norm /-- The norm of an element of `ℤ[√d]`. -/ def norm (n : ℤ√d) : ℤ := n.re * n.re - d * n.im * n.im theorem norm_def (n : ℤ√d) : n.norm = n.re * n.re - d * n.im * n.im := rfl @[simp] theorem norm_zero : norm (0 : ℤ√d) = 0 := by simp [norm] @[simp] theorem norm_one : norm (1 : ℤ√d) = 1 := by simp [norm] @[simp] theorem norm_intCast (n : ℤ) : norm (n : ℤ√d) = n * n := by simp [norm] @[simp] theorem norm_natCast (n : ℕ) : norm (n : ℤ√d) = n * n := norm_intCast n @[simp] theorem norm_mul (n m : ℤ√d) : norm (n * m) = norm n * norm m := by simp only [norm, mul_im, mul_re] ring /-- `norm` as a `MonoidHom`. -/ def normMonoidHom : ℤ√d →* ℤ where toFun := norm map_mul' := norm_mul map_one' := norm_one theorem norm_eq_mul_conj (n : ℤ√d) : (norm n : ℤ√d) = n * star n := by ext <;> simp [norm, star, mul_comm, sub_eq_add_neg] @[simp] theorem norm_neg (x : ℤ√d) : (-x).norm = x.norm := (Int.cast_inj (α := ℤ√d)).1 <| by simp [norm_eq_mul_conj] @[simp] theorem norm_conj (x : ℤ√d) : (star x).norm = x.norm := (Int.cast_inj (α := ℤ√d)).1 <| by simp [norm_eq_mul_conj, mul_comm] theorem norm_nonneg (hd : d ≤ 0) (n : ℤ√d) : 0 ≤ n.norm := add_nonneg (mul_self_nonneg _) (by rw [mul_assoc, neg_mul_eq_neg_mul] exact mul_nonneg (neg_nonneg.2 hd) (mul_self_nonneg _)) theorem norm_eq_one_iff {x : ℤ√d} : x.norm.natAbs = 1 ↔ IsUnit x := ⟨fun h => isUnit_iff_dvd_one.2 <| (le_total 0 (norm x)).casesOn (fun hx => ⟨star x, by rwa [← Int.natCast_inj, Int.natAbs_of_nonneg hx, ← @Int.cast_inj (ℤ√d) _ _, norm_eq_mul_conj, eq_comm] at h⟩) fun hx => ⟨-star x, by rwa [← Int.natCast_inj, Int.ofNat_natAbs_of_nonpos hx, ← @Int.cast_inj (ℤ√d) _ _, Int.cast_neg, norm_eq_mul_conj, neg_mul_eq_mul_neg, eq_comm] at h⟩, fun h => by let ⟨y, hy⟩ := isUnit_iff_dvd_one.1 h have := congr_arg (Int.natAbs ∘ norm) hy rw [Function.comp_apply, Function.comp_apply, norm_mul, Int.natAbs_mul, norm_one, Int.natAbs_one, eq_comm, mul_eq_one] at this exact this.1⟩ theorem isUnit_iff_norm_isUnit {d : ℤ} (z : ℤ√d) : IsUnit z ↔ IsUnit z.norm := by rw [Int.isUnit_iff_natAbs_eq, norm_eq_one_iff] theorem norm_eq_one_iff' {d : ℤ} (hd : d ≤ 0) (z : ℤ√d) : z.norm = 1 ↔ IsUnit z := by rw [← norm_eq_one_iff, ← Int.natCast_inj, Int.natAbs_of_nonneg (norm_nonneg hd z), Int.ofNat_one] theorem norm_eq_zero_iff {d : ℤ} (hd : d < 0) (z : ℤ√d) : z.norm = 0 ↔ z = 0 := by constructor · intro h rw [norm_def, sub_eq_add_neg, mul_assoc] at h have left := mul_self_nonneg z.re have right := neg_nonneg.mpr (mul_nonpos_of_nonpos_of_nonneg hd.le (mul_self_nonneg z.im)) obtain ⟨ha, hb⟩ := (add_eq_zero_iff_of_nonneg left right).mp h ext <;> apply eq_zero_of_mul_self_eq_zero · exact ha · rw [neg_eq_zero, mul_eq_zero] at hb exact hb.resolve_left hd.ne · rintro rfl exact norm_zero theorem norm_eq_of_associated {d : ℤ} (hd : d ≤ 0) {x y : ℤ√d} (h : Associated x y) : x.norm = y.norm := by obtain ⟨u, rfl⟩ := h rw [norm_mul, (norm_eq_one_iff' hd _).mpr u.isUnit, mul_one] end Norm end section variable {d : ℕ} /-- Nonnegativity of an element of `ℤ√d`. -/ def Nonneg : ℤ√d → Prop | ⟨a, b⟩ => Nonnegg d 1 a b instance : LE (ℤ√d) := ⟨fun a b => Nonneg (b - a)⟩ instance : LT (ℤ√d) := ⟨fun a b => ¬b ≤ a⟩ instance decidableNonnegg (c d a b) : Decidable (Nonnegg c d a b) := by cases a <;> cases b <;> unfold Nonnegg SqLe <;> infer_instance instance decidableNonneg : ∀ a : ℤ√d, Decidable (Nonneg a) | ⟨_, _⟩ => Zsqrtd.decidableNonnegg _ _ _ _ instance decidableLE : DecidableLE (ℤ√d) := fun _ _ => decidableNonneg _ open Int in theorem nonneg_cases : ∀ {a : ℤ√d}, Nonneg a → ∃ x y : ℕ, a = ⟨x, y⟩ ∨ a = ⟨x, -y⟩ ∨ a = ⟨-x, y⟩ | ⟨(x : ℕ), (y : ℕ)⟩, _ => ⟨x, y, Or.inl rfl⟩ | ⟨(x : ℕ), -[y+1]⟩, _ => ⟨x, y + 1, Or.inr <| Or.inl rfl⟩ | ⟨-[x+1], (y : ℕ)⟩, _ => ⟨x + 1, y, Or.inr <| Or.inr rfl⟩ | ⟨-[_+1], -[_+1]⟩, h => False.elim h open Int in theorem nonneg_add_lem {x y z w : ℕ} (xy : Nonneg (⟨x, -y⟩ : ℤ√d)) (zw : Nonneg (⟨-z, w⟩ : ℤ√d)) : Nonneg (⟨x, -y⟩ + ⟨-z, w⟩ : ℤ√d) := by have : Nonneg ⟨Int.subNatNat x z, Int.subNatNat w y⟩ := Int.subNatNat_elim x z (fun m n i => SqLe y d m 1 → SqLe n 1 w d → Nonneg ⟨i, Int.subNatNat w y⟩) (fun j k => Int.subNatNat_elim w y (fun m n i => SqLe n d (k + j) 1 → SqLe k 1 m d → Nonneg ⟨Int.ofNat j, i⟩) (fun _ _ _ _ => trivial) fun m n xy zw => sqLe_cancel zw xy) (fun j k => Int.subNatNat_elim w y (fun m n i => SqLe n d k 1 → SqLe (k + j + 1) 1 m d → Nonneg ⟨-[j+1], i⟩) (fun m n xy zw => sqLe_cancel xy zw) fun m n xy zw => let t := Nat.le_trans zw (sqLe_of_le (Nat.le_add_right n (m + 1)) le_rfl xy) have : k + j + 1 ≤ k := Nat.mul_self_le_mul_self_iff.1 (by simpa [one_mul] using t) absurd this (not_le_of_gt <| Nat.succ_le_succ <| Nat.le_add_right _ _)) (nonnegg_pos_neg.1 xy) (nonnegg_neg_pos.1 zw) rw [add_def, neg_add_eq_sub] rwa [Int.subNatNat_eq_coe, Int.subNatNat_eq_coe] at this theorem Nonneg.add {a b : ℤ√d} (ha : Nonneg a) (hb : Nonneg b) : Nonneg (a + b) := by rcases nonneg_cases ha with ⟨x, y, rfl | rfl | rfl⟩ <;> rcases nonneg_cases hb with ⟨z, w, rfl | rfl | rfl⟩ · trivial · refine nonnegg_cases_right fun i h => sqLe_of_le ?_ ?_ (nonnegg_pos_neg.1 hb) · dsimp only at h exact Int.ofNat_le.1 (le_of_neg_le_neg (Int.le.intro y (by simp [add_comm, *]))) · apply Nat.le_add_left · refine nonnegg_cases_left fun i h => sqLe_of_le ?_ ?_ (nonnegg_neg_pos.1 hb) · dsimp only at h exact Int.ofNat_le.1 (le_of_neg_le_neg (Int.le.intro x (by simp [add_comm, *]))) · apply Nat.le_add_left · refine nonnegg_cases_right fun i h => sqLe_of_le ?_ ?_ (nonnegg_pos_neg.1 ha) · dsimp only at h exact Int.ofNat_le.1 (le_of_neg_le_neg (Int.le.intro w (by simp [*]))) · apply Nat.le_add_right · have : Nonneg ⟨_, _⟩ := nonnegg_pos_neg.2 (sqLe_add (nonnegg_pos_neg.1 ha) (nonnegg_pos_neg.1 hb)) rw [Nat.cast_add, Nat.cast_add, neg_add] at this rwa [add_def] · exact nonneg_add_lem ha hb · refine nonnegg_cases_left fun i h => sqLe_of_le ?_ ?_ (nonnegg_neg_pos.1 ha) · dsimp only at h exact Int.ofNat_le.1 (le_of_neg_le_neg (Int.le.intro _ h)) · apply Nat.le_add_right · dsimp rw [add_comm, add_comm (y : ℤ)] exact nonneg_add_lem hb ha · have : Nonneg ⟨_, _⟩ := nonnegg_neg_pos.2 (sqLe_add (nonnegg_neg_pos.1 ha) (nonnegg_neg_pos.1 hb)) rw [Nat.cast_add, Nat.cast_add, neg_add] at this rwa [add_def] theorem nonneg_iff_zero_le {a : ℤ√d} : Nonneg a ↔ 0 ≤ a := show _ ↔ Nonneg _ by simp theorem le_of_le_le {x y z w : ℤ} (xz : x ≤ z) (yw : y ≤ w) : (⟨x, y⟩ : ℤ√d) ≤ ⟨z, w⟩ := show Nonneg ⟨z - x, w - y⟩ from match z - x, w - y, Int.le.dest_sub xz, Int.le.dest_sub yw with | _, _, ⟨_, rfl⟩, ⟨_, rfl⟩ => trivial open Int in protected theorem nonneg_total : ∀ a : ℤ√d, Nonneg a ∨ Nonneg (-a) | ⟨(x : ℕ), (y : ℕ)⟩ => Or.inl trivial | ⟨-[_+1], -[_+1]⟩ => Or.inr trivial | ⟨0, -[_+1]⟩ => Or.inr trivial | ⟨-[_+1], 0⟩ => Or.inr trivial | ⟨(_ + 1 : ℕ), -[_+1]⟩ => Nat.le_total _ _ | ⟨-[_+1], (_ + 1 : ℕ)⟩ => Nat.le_total _ _ protected theorem le_total (a b : ℤ√d) : a ≤ b ∨ b ≤ a := by have t := (b - a).nonneg_total rwa [neg_sub] at t instance preorder : Preorder (ℤ√d) where le := (· ≤ ·) le_refl a := show Nonneg (a - a) by simp only [sub_self]; trivial le_trans a b c hab hbc := by simpa [sub_add_sub_cancel'] using hab.add hbc lt := (· < ·) lt_iff_le_not_le _ _ := (and_iff_right_of_imp (Zsqrtd.le_total _ _).resolve_left).symm open Int in theorem le_arch (a : ℤ√d) : ∃ n : ℕ, a ≤ n := by obtain ⟨x, y, (h : a ≤ ⟨x, y⟩)⟩ : ∃ x y : ℕ, Nonneg (⟨x, y⟩ + -a) := match -a with | ⟨Int.ofNat x, Int.ofNat y⟩ => ⟨0, 0, by trivial⟩ | ⟨Int.ofNat x, -[y+1]⟩ => ⟨0, y + 1, by simp [add_def, Int.negSucc_eq, add_assoc]; trivial⟩ | ⟨-[x+1], Int.ofNat y⟩ => ⟨x + 1, 0, by simp [Int.negSucc_eq, add_assoc]; trivial⟩ | ⟨-[x+1], -[y+1]⟩ => ⟨x + 1, y + 1, by simp [Int.negSucc_eq, add_assoc]; trivial⟩ refine ⟨x + d * y, h.trans ?_⟩ change Nonneg ⟨↑x + d * y - ↑x, 0 - ↑y⟩ rcases y with - | y · simp trivial have h : ∀ y, SqLe y d (d * y) 1 := fun y => by simpa [SqLe, mul_comm, mul_left_comm] using Nat.mul_le_mul_right (y * y) (Nat.le_mul_self d) rw [show (x : ℤ) + d * Nat.succ y - x = d * Nat.succ y by simp] exact h (y + 1) protected theorem add_le_add_left (a b : ℤ√d) (ab : a ≤ b) (c : ℤ√d) : c + a ≤ c + b := show Nonneg _ by rw [add_sub_add_left_eq_sub]; exact ab protected theorem le_of_add_le_add_left (a b c : ℤ√d) (h : c + a ≤ c + b) : a ≤ b := by simpa using Zsqrtd.add_le_add_left _ _ h (-c) protected theorem add_lt_add_left (a b : ℤ√d) (h : a < b) (c) : c + a < c + b := fun h' => h (Zsqrtd.le_of_add_le_add_left _ _ _ h') theorem nonneg_smul {a : ℤ√d} {n : ℕ} (ha : Nonneg a) : Nonneg ((n : ℤ√d) * a) := by rw [← Int.cast_natCast n] exact match a, nonneg_cases ha, ha with | _, ⟨x, y, Or.inl rfl⟩, _ => by rw [smul_val]; trivial | _, ⟨x, y, Or.inr <| Or.inl rfl⟩, ha => by rw [smul_val]; simpa using nonnegg_pos_neg.2 (sqLe_smul n <| nonnegg_pos_neg.1 ha) | _, ⟨x, y, Or.inr <| Or.inr rfl⟩, ha => by rw [smul_val]; simpa using nonnegg_neg_pos.2 (sqLe_smul n <| nonnegg_neg_pos.1 ha) theorem nonneg_muld {a : ℤ√d} (ha : Nonneg a) : Nonneg (sqrtd * a) := match a, nonneg_cases ha, ha with | _, ⟨_, _, Or.inl rfl⟩, _ => trivial | _, ⟨x, y, Or.inr <| Or.inl rfl⟩, ha => by simp only [muld_val, mul_neg] apply nonnegg_neg_pos.2 simpa [SqLe, mul_comm, mul_left_comm] using Nat.mul_le_mul_left d (nonnegg_pos_neg.1 ha) | _, ⟨x, y, Or.inr <| Or.inr rfl⟩, ha => by simp only [muld_val] apply nonnegg_pos_neg.2 simpa [SqLe, mul_comm, mul_left_comm] using Nat.mul_le_mul_left d (nonnegg_neg_pos.1 ha) theorem nonneg_mul_lem {x y : ℕ} {a : ℤ√d} (ha : Nonneg a) : Nonneg (⟨x, y⟩ * a) := by have : (⟨x, y⟩ * a : ℤ√d) = (x : ℤ√d) * a + sqrtd * ((y : ℤ√d) * a) := by rw [decompose, right_distrib, mul_assoc, Int.cast_natCast, Int.cast_natCast] rw [this] exact (nonneg_smul ha).add (nonneg_muld <| nonneg_smul ha) theorem nonneg_mul {a b : ℤ√d} (ha : Nonneg a) (hb : Nonneg b) : Nonneg (a * b) := match a, b, nonneg_cases ha, nonneg_cases hb, ha, hb with | _, _, ⟨_, _, Or.inl rfl⟩, ⟨_, _, Or.inl rfl⟩, _, _ => trivial | _, _, ⟨x, y, Or.inl rfl⟩, ⟨z, w, Or.inr <| Or.inr rfl⟩, _, hb => nonneg_mul_lem hb | _, _, ⟨x, y, Or.inl rfl⟩, ⟨z, w, Or.inr <| Or.inl rfl⟩, _, hb => nonneg_mul_lem hb | _, _, ⟨x, y, Or.inr <| Or.inr rfl⟩, ⟨z, w, Or.inl rfl⟩, ha, _ => by rw [mul_comm]; exact nonneg_mul_lem ha | _, _, ⟨x, y, Or.inr <| Or.inl rfl⟩, ⟨z, w, Or.inl rfl⟩, ha, _ => by rw [mul_comm]; exact nonneg_mul_lem ha | _, _, ⟨x, y, Or.inr <| Or.inr rfl⟩, ⟨z, w, Or.inr <| Or.inr rfl⟩, ha, hb => by rw [calc (⟨-x, y⟩ * ⟨-z, w⟩ : ℤ√d) = ⟨_, _⟩ := rfl _ = ⟨x * z + d * y * w, -(x * w + y * z)⟩ := by simp [add_comm] ] exact nonnegg_pos_neg.2 (sqLe_mul.left (nonnegg_neg_pos.1 ha) (nonnegg_neg_pos.1 hb)) | _, _, ⟨x, y, Or.inr <| Or.inr rfl⟩, ⟨z, w, Or.inr <| Or.inl rfl⟩, ha, hb => by rw [calc (⟨-x, y⟩ * ⟨z, -w⟩ : ℤ√d) = ⟨_, _⟩ := rfl _ = ⟨-(x * z + d * y * w), x * w + y * z⟩ := by simp [add_comm] ] exact nonnegg_neg_pos.2 (sqLe_mul.right.left (nonnegg_neg_pos.1 ha) (nonnegg_pos_neg.1 hb)) | _, _, ⟨x, y, Or.inr <| Or.inl rfl⟩, ⟨z, w, Or.inr <| Or.inr rfl⟩, ha, hb => by rw [calc (⟨x, -y⟩ * ⟨-z, w⟩ : ℤ√d) = ⟨_, _⟩ := rfl _ = ⟨-(x * z + d * y * w), x * w + y * z⟩ := by simp [add_comm] ] exact nonnegg_neg_pos.2 (sqLe_mul.right.right.left (nonnegg_pos_neg.1 ha) (nonnegg_neg_pos.1 hb)) | _, _, ⟨x, y, Or.inr <| Or.inl rfl⟩, ⟨z, w, Or.inr <| Or.inl rfl⟩, ha, hb => by rw [calc (⟨x, -y⟩ * ⟨z, -w⟩ : ℤ√d) = ⟨_, _⟩ := rfl _ = ⟨x * z + d * y * w, -(x * w + y * z)⟩ := by simp [add_comm] ] exact nonnegg_pos_neg.2 (sqLe_mul.right.right.right (nonnegg_pos_neg.1 ha) (nonnegg_pos_neg.1 hb)) protected theorem mul_nonneg (a b : ℤ√d) : 0 ≤ a → 0 ≤ b → 0 ≤ a * b := by simp_rw [← nonneg_iff_zero_le] exact nonneg_mul theorem not_sqLe_succ (c d y) (h : 0 < c) : ¬SqLe (y + 1) c 0 d := not_le_of_gt <| mul_pos (mul_pos h <| Nat.succ_pos _) <| Nat.succ_pos _ -- Porting note: renamed field and added theorem to make `x` explicit /-- A nonsquare is a natural number that is not equal to the square of an integer. This is implemented as a typeclass because it's a necessary condition for much of the Pell equation theory. -/ class Nonsquare (x : ℕ) : Prop where ns' : ∀ n : ℕ, x ≠ n * n theorem Nonsquare.ns (x : ℕ) [Nonsquare x] : ∀ n : ℕ, x ≠ n * n := ns' variable [dnsq : Nonsquare d] theorem d_pos : 0 < d := lt_of_le_of_ne (Nat.zero_le _) <| Ne.symm <| Nonsquare.ns d 0 theorem divides_sq_eq_zero {x y} (h : x * x = d * y * y) : x = 0 ∧ y = 0 := let g := x.gcd y Or.elim g.eq_zero_or_pos (fun H => ⟨Nat.eq_zero_of_gcd_eq_zero_left H, Nat.eq_zero_of_gcd_eq_zero_right H⟩) fun gpos => False.elim <| by let ⟨m, n, co, (hx : x = m * g), (hy : y = n * g)⟩ := Nat.exists_coprime _ _ rw [hx, hy] at h have : m * m = d * (n * n) := by refine mul_left_cancel₀ (mul_pos gpos gpos).ne' ?_ -- Porting note: was `simpa [mul_comm, mul_left_comm] using h` calc g * g * (m * m) _ = m * g * (m * g) := by ring _ = d * (n * g) * (n * g) := h _ = g * g * (d * (n * n)) := by ring have co2 := let co1 := co.mul_right co co1.mul co1 exact Nonsquare.ns d m (Nat.dvd_antisymm (by rw [this]; apply dvd_mul_right) <| co2.dvd_of_dvd_mul_right <| by simp [this]) theorem divides_sq_eq_zero_z {x y : ℤ} (h : x * x = d * y * y) : x = 0 ∧ y = 0 := by rw [mul_assoc, ← Int.natAbs_mul_self, ← Int.natAbs_mul_self, ← Int.natCast_mul, ← mul_assoc] at h exact let ⟨h1, h2⟩ := divides_sq_eq_zero (Int.ofNat.inj h) ⟨Int.natAbs_eq_zero.mp h1, Int.natAbs_eq_zero.mp h2⟩ theorem not_divides_sq (x y) : (x + 1) * (x + 1) ≠ d * (y + 1) * (y + 1) := fun e => by have t := (divides_sq_eq_zero e).left contradiction open Int in theorem nonneg_antisymm : ∀ {a : ℤ√d}, Nonneg a → Nonneg (-a) → a = 0 | ⟨0, 0⟩, _, _ => rfl | ⟨-[_+1], -[_+1]⟩, xy, _ => False.elim xy | ⟨(_ + 1 : Nat), (_ + 1 : Nat)⟩, _, yx => False.elim yx | ⟨-[_+1], 0⟩, xy, _ => absurd xy (not_sqLe_succ _ _ _ (by decide)) | ⟨(_ + 1 : Nat), 0⟩, _, yx => absurd yx (not_sqLe_succ _ _ _ (by decide)) | ⟨0, -[_+1]⟩, xy, _ => absurd xy (not_sqLe_succ _ _ _ d_pos) | ⟨0, (_ + 1 : Nat)⟩, _, yx => absurd yx (not_sqLe_succ _ _ _ d_pos) | ⟨(x + 1 : Nat), -[y+1]⟩, (xy : SqLe _ _ _ _), (yx : SqLe _ _ _ _) => by let t := le_antisymm yx xy rw [one_mul] at t exact absurd t (not_divides_sq _ _) | ⟨-[x+1], (y + 1 : Nat)⟩, (xy : SqLe _ _ _ _), (yx : SqLe _ _ _ _) => by let t := le_antisymm xy yx rw [one_mul] at t exact absurd t (not_divides_sq _ _) theorem le_antisymm {a b : ℤ√d} (ab : a ≤ b) (ba : b ≤ a) : a = b := eq_of_sub_eq_zero <| nonneg_antisymm ba (by rwa [neg_sub]) instance linearOrder : LinearOrder (ℤ√d) := { Zsqrtd.preorder with le_antisymm := fun _ _ => Zsqrtd.le_antisymm le_total := Zsqrtd.le_total toDecidableLE := Zsqrtd.decidableLE toDecidableEq := inferInstance } protected theorem eq_zero_or_eq_zero_of_mul_eq_zero : ∀ {a b : ℤ√d}, a * b = 0 → a = 0 ∨ b = 0 | ⟨x, y⟩, ⟨z, w⟩, h => by injection h with h1 h2 have h1 : x * z = -(d * y * w) := eq_neg_of_add_eq_zero_left h1 have h2 : x * w = -(y * z) := eq_neg_of_add_eq_zero_left h2 have fin : x * x = d * y * y → (⟨x, y⟩ : ℤ√d) = 0 := fun e => match x, y, divides_sq_eq_zero_z e with | _, _, ⟨rfl, rfl⟩ => rfl exact if z0 : z = 0 then if w0 : w = 0 then Or.inr (match z, w, z0, w0 with | _, _, rfl, rfl => rfl) else Or.inl <| fin <| mul_right_cancel₀ w0 <| calc x * x * w = -y * (x * z) := by simp [h2, mul_assoc, mul_left_comm] _ = d * y * y * w := by simp [h1, mul_assoc, mul_left_comm] else Or.inl <| fin <| mul_right_cancel₀ z0 <| calc x * x * z = d * -y * (x * w) := by simp [h1, mul_assoc, mul_left_comm] _ = d * y * y * z := by simp [h2, mul_assoc, mul_left_comm] instance : NoZeroDivisors (ℤ√d) where eq_zero_or_eq_zero_of_mul_eq_zero := Zsqrtd.eq_zero_or_eq_zero_of_mul_eq_zero instance : IsDomain (ℤ√d) := NoZeroDivisors.to_isDomain _ protected theorem mul_pos (a b : ℤ√d) (a0 : 0 < a) (b0 : 0 < b) : 0 < a * b := fun ab => Or.elim (eq_zero_or_eq_zero_of_mul_eq_zero (le_antisymm ab (Zsqrtd.mul_nonneg _ _ (le_of_lt a0) (le_of_lt b0)))) (fun e => ne_of_gt a0 e) fun e => ne_of_gt b0 e instance : ZeroLEOneClass (ℤ√d) := { zero_le_one := by trivial } instance : IsOrderedAddMonoid (ℤ√d) := { add_le_add_left := Zsqrtd.add_le_add_left } instance : IsStrictOrderedRing (ℤ√d) := .of_mul_pos Zsqrtd.mul_pos end theorem norm_eq_zero {d : ℤ} (h_nonsquare : ∀ n : ℤ, d ≠ n * n) (a : ℤ√d) : norm a = 0 ↔ a = 0 := by refine ⟨fun ha => Zsqrtd.ext_iff.mpr ?_, fun h => by rw [h, norm_zero]⟩ dsimp only [norm] at ha rw [sub_eq_zero] at ha by_cases h : 0 ≤ d · obtain ⟨d', rfl⟩ := Int.eq_ofNat_of_zero_le h haveI : Nonsquare d' := ⟨fun n h => h_nonsquare n <| mod_cast h⟩ exact divides_sq_eq_zero_z ha · push_neg at h suffices a.re * a.re = 0 by rw [eq_zero_of_mul_self_eq_zero this] at ha ⊢ simpa only [true_and, or_self_right, zero_re, zero_im, eq_self_iff_true, zero_eq_mul, mul_zero, mul_eq_zero, h.ne, false_or, or_self_iff] using ha apply _root_.le_antisymm _ (mul_self_nonneg _) rw [ha, mul_assoc] exact mul_nonpos_of_nonpos_of_nonneg h.le (mul_self_nonneg _)
variable {R : Type} @[ext] theorem hom_ext [NonAssocRing R] {d : ℤ} (f g : ℤ√d →+* R) (h : f sqrtd = g sqrtd) : f = g := by ext ⟨x_re, x_im⟩ simp [decompose, h] variable [CommRing R] /-- The unique `RingHom` from `ℤ√d` to a ring `R`, constructed by replacing `√d` with the provided root. Conversely, this associates to every mapping `ℤ√d →+* R` a value of `√d` in `R`. -/ @[simps] def lift {d : ℤ} : { r : R // r * r = ↑d } ≃ (ℤ√d →+* R) where toFun r := { toFun := fun a => a.1 + a.2 * (r : R) map_zero' := by simp map_add' := fun a b => by simp only [add_re, Int.cast_add, add_im] ring map_one' := by simp map_mul' := fun a b => by
Mathlib/NumberTheory/Zsqrtd/Basic.lean
876
897
/- Copyright (c) 2015 Leonardo de Moura. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Mario Carneiro -/ import Mathlib.Data.List.Basic import Mathlib.Data.Prod.Basic /-! # Lists in product and sigma types This file proves basic properties of `List.product` and `List.sigma`, which are list constructions living in `Prod` and `Sigma` types respectively. Their definitions can be found in [`Data.List.Defs`](./defs). Beware, this is not about `List.prod`, the multiplicative product. -/ variable {α β : Type*} namespace List /-! ### product -/ @[simp] theorem nil_product (l : List β) : (@nil α) ×ˢ l = [] := rfl @[simp] theorem product_cons (a : α) (l₁ : List α) (l₂ : List β) : (a :: l₁) ×ˢ l₂ = map (fun b => (a, b)) l₂ ++ (l₁ ×ˢ l₂) := rfl @[simp] theorem product_nil : ∀ l : List α, l ×ˢ (@nil β) = [] | [] => rfl | _ :: l => by simp [product_cons, product_nil l] @[simp] theorem mem_product {l₁ : List α} {l₂ : List β} {a : α} {b : β} : (a, b) ∈ l₁ ×ˢ l₂ ↔ a ∈ l₁ ∧ b ∈ l₂ := by simp_all [SProd.sprod, product, mem_flatMap, mem_map, Prod.ext_iff, exists_prop, and_left_comm, exists_and_left, exists_eq_left, exists_eq_right] theorem length_product (l₁ : List α) (l₂ : List β) : length (l₁ ×ˢ l₂) = length l₁ * length l₂ := by induction' l₁ with x l₁ IH · exact (Nat.zero_mul _).symm · simp only [length, product_cons, length_append, IH, Nat.add_mul, Nat.one_mul, length_map, Nat.add_comm]
/-! ### sigma -/ variable {σ : α → Type*}
Mathlib/Data/List/ProdSigma.lean
51
56
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.MeasureTheory.Integral.Bochner.Set import Mathlib.MeasureTheory.Measure.Lebesgue.Basic import Mathlib.MeasureTheory.Measure.Haar.Unique /-! # Properties of integration with respect to the Lebesgue measure -/ open Set Filter MeasureTheory MeasureTheory.Measure TopologicalSpace section regionBetween variable {α : Type*} variable [MeasurableSpace α] {μ : Measure α} {f g : α → ℝ} {s : Set α} theorem volume_regionBetween_eq_integral' [SigmaFinite μ] (f_int : IntegrableOn f s μ) (g_int : IntegrableOn g s μ) (hs : MeasurableSet s) (hfg : f ≤ᵐ[μ.restrict s] g) : μ.prod volume (regionBetween f g s) = ENNReal.ofReal (∫ y in s, (g - f) y ∂μ) := by have h : g - f =ᵐ[μ.restrict s] fun x => Real.toNNReal (g x - f x) := hfg.mono fun x hx => (Real.coe_toNNReal _ <| sub_nonneg.2 hx).symm rw [volume_regionBetween_eq_lintegral f_int.aemeasurable g_int.aemeasurable hs, integral_congr_ae h, lintegral_congr_ae, lintegral_coe_eq_integral _ ((integrable_congr h).mp (g_int.sub f_int))] dsimp only rfl /-- If two functions are integrable on a measurable set, and one function is less than or equal to the other on that set, then the volume of the region between the two functions can be represented as an integral. -/ theorem volume_regionBetween_eq_integral [SigmaFinite μ] (f_int : IntegrableOn f s μ) (g_int : IntegrableOn g s μ) (hs : MeasurableSet s) (hfg : ∀ x ∈ s, f x ≤ g x) : μ.prod volume (regionBetween f g s) = ENNReal.ofReal (∫ y in s, (g - f) y ∂μ) := volume_regionBetween_eq_integral' f_int g_int hs ((ae_restrict_iff' hs).mpr (Eventually.of_forall hfg)) end regionBetween section SummableNormIcc open ContinuousMap /- The following lemma is a minor variation on `integrable_of_summable_norm_restrict` in `Mathlib/MeasureTheory/Integral/SetIntegral.lean`, but it is placed here because it needs to know that `Icc a b` has volume `b - a`. -/ /-- If the sequence with `n`-th term the sup norm of `fun x ↦ f (x + n)` on the interval `Icc 0 1`, for `n ∈ ℤ`, is summable, then `f` is integrable on `ℝ`. -/ theorem Real.integrable_of_summable_norm_Icc {E : Type*} [NormedAddCommGroup E] {f : C(ℝ, E)} (hf : Summable fun n : ℤ => ‖(f.comp <| ContinuousMap.addRight n).restrict (Icc 0 1)‖) : Integrable f := by refine integrable_of_summable_norm_restrict (.of_nonneg_of_le (fun n : ℤ => mul_nonneg (norm_nonneg (f.restrict (⟨Icc (n : ℝ) ((n : ℝ) + 1), isCompact_Icc⟩ : Compacts ℝ))) ENNReal.toReal_nonneg) (fun n => ?_) hf) ?_ · simp only [Compacts.coe_mk, le_add_iff_nonneg_right, zero_le_one, volume_real_Icc_of_le, add_sub_cancel_left, mul_one, norm_le _ (norm_nonneg _), ContinuousMap.restrict_apply, mem_Icc, and_imp] intro x have := ((f.comp <| ContinuousMap.addRight n).restrict (Icc 0 1)).norm_coe_le_norm ⟨x - n, ⟨sub_nonneg.mpr x.2.1, sub_le_iff_le_add'.mpr x.2.2⟩⟩ simpa only [ContinuousMap.restrict_apply, comp_apply, coe_addRight, Subtype.coe_mk, sub_add_cancel] using this · exact iUnion_Icc_intCast ℝ end SummableNormIcc /-! ### Substituting `-x` for `x` These lemmas are stated in terms of either `Iic` or `Ioi` (neglecting `Iio` and `Ici`) to match mathlib's conventions for integrals over finite intervals (see `intervalIntegral`). For the case of finite integrals, see `intervalIntegral.integral_comp_neg`. -/ /- @[simp] Porting note: Linter complains it does not apply to itself. Although it does apply to itself, it does not apply when `f` is more complicated -/ theorem integral_comp_neg_Iic {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] (c : ℝ) (f : ℝ → E) : (∫ x in Iic c, f (-x)) = ∫ x in Ioi (-c), f x := by have A : MeasurableEmbedding fun x : ℝ => -x := (Homeomorph.neg ℝ).isClosedEmbedding.measurableEmbedding have := MeasurableEmbedding.setIntegral_map (μ := volume) A f (Ici (-c)) rw [Measure.map_neg_eq_self (volume : Measure ℝ)] at this simp_rw [← integral_Ici_eq_integral_Ioi, this, neg_preimage, neg_Ici, neg_neg] /- @[simp] Porting note: Linter complains it does not apply to itself. Although it does apply to itself, it does not apply when `f` is more complicated -/ theorem integral_comp_neg_Ioi {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] (c : ℝ) (f : ℝ → E) : (∫ x in Ioi c, f (-x)) = ∫ x in Iic (-c), f x := by rw [← neg_neg c, ← integral_comp_neg_Iic] simp only [neg_neg] theorem integral_comp_abs {f : ℝ → ℝ} : ∫ x, f |x| = 2 * ∫ x in Ioi (0 : ℝ), f x := by have eq : ∫ (x : ℝ) in Ioi 0, f |x| = ∫ (x : ℝ) in Ioi 0, f x := by refine setIntegral_congr_fun measurableSet_Ioi (fun _ hx => ?_) rw [abs_eq_self.mpr (le_of_lt (by exact hx))] by_cases hf : IntegrableOn (fun x => f |x|) (Ioi 0)
· have int_Iic : IntegrableOn (fun x ↦ f |x|) (Iic 0) := by rw [← Measure.map_neg_eq_self (volume : Measure ℝ)] let m : MeasurableEmbedding fun x : ℝ => -x := (Homeomorph.neg ℝ).measurableEmbedding rw [m.integrableOn_map_iff] simp_rw [Function.comp_def, abs_neg, neg_preimage, neg_Iic, neg_zero] exact integrableOn_Ici_iff_integrableOn_Ioi.mpr hf calc _ = (∫ x in Iic 0, f |x|) + ∫ x in Ioi 0, f |x| := by rw [← setIntegral_union (Iic_disjoint_Ioi le_rfl) measurableSet_Ioi int_Iic hf, Iic_union_Ioi, restrict_univ] _ = 2 * ∫ x in Ioi 0, f x := by rw [two_mul, eq] congr! 1 rw [← neg_zero, ← integral_comp_neg_Iic, neg_zero] refine setIntegral_congr_fun measurableSet_Iic (fun _ hx => ?_) rw [abs_eq_neg_self.mpr (by exact hx)] · have : ¬ Integrable (fun x => f |x|) := by contrapose! hf exact hf.integrableOn rw [← eq, integral_undef hf, integral_undef this, mul_zero]
Mathlib/MeasureTheory/Measure/Lebesgue/Integral.lean
102
127
/- Copyright (c) 2022 Xavier Roblot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alex J. Best, Xavier Roblot -/ import Mathlib.Algebra.Algebra.Hom.Rat import Mathlib.Analysis.Complex.Polynomial.Basic import Mathlib.NumberTheory.NumberField.Norm import Mathlib.RingTheory.RootsOfUnity.PrimitiveRoots import Mathlib.Topology.Instances.Complex /-! # Embeddings of number fields This file defines the embeddings of a number field into an algebraic closed field. ## Main Definitions and Results * `NumberField.Embeddings.range_eval_eq_rootSet_minpoly`: let `x ∈ K` with `K` number field and let `A` be an algebraic closed field of char. 0, then the images of `x` by the embeddings of `K` in `A` are exactly the roots in `A` of the minimal polynomial of `x` over `ℚ`. * `NumberField.Embeddings.pow_eq_one_of_norm_eq_one`: an algebraic integer whose conjugates are all of norm one is a root of unity. * `NumberField.InfinitePlace`: the type of infinite places of a number field `K`. * `NumberField.InfinitePlace.mk_eq_iff`: two complex embeddings define the same infinite place iff they are equal or complex conjugates. * `NumberField.InfinitePlace.prod_eq_abs_norm`: the infinite part of the product formula, that is for `x ∈ K`, we have `Π_w ‖x‖_w = |norm(x)|` where the product is over the infinite place `w` and `‖·‖_w` is the normalized absolute value for `w`. ## Tags number field, embeddings, places, infinite places -/ open scoped Finset namespace NumberField.Embeddings section Fintype open Module variable (K : Type*) [Field K] [NumberField K] variable (A : Type*) [Field A] [CharZero A] /-- There are finitely many embeddings of a number field. -/ noncomputable instance : Fintype (K →+* A) := Fintype.ofEquiv (K →ₐ[ℚ] A) RingHom.equivRatAlgHom.symm variable [IsAlgClosed A] /-- The number of embeddings of a number field is equal to its finrank. -/ theorem card : Fintype.card (K →+* A) = finrank ℚ K := by rw [Fintype.ofEquiv_card RingHom.equivRatAlgHom.symm, AlgHom.card] instance : Nonempty (K →+* A) := by rw [← Fintype.card_pos_iff, NumberField.Embeddings.card K A] exact Module.finrank_pos end Fintype section Roots open Set Polynomial variable (K A : Type*) [Field K] [NumberField K] [Field A] [Algebra ℚ A] [IsAlgClosed A] (x : K) /-- Let `A` be an algebraically closed field and let `x ∈ K`, with `K` a number field. The images of `x` by the embeddings of `K` in `A` are exactly the roots in `A` of the minimal polynomial of `x` over `ℚ`. -/ theorem range_eval_eq_rootSet_minpoly : (range fun φ : K →+* A => φ x) = (minpoly ℚ x).rootSet A := by convert (NumberField.isAlgebraic K).range_eval_eq_rootSet_minpoly A x using 1 ext a exact ⟨fun ⟨φ, hφ⟩ => ⟨φ.toRatAlgHom, hφ⟩, fun ⟨φ, hφ⟩ => ⟨φ.toRingHom, hφ⟩⟩ end Roots section Bounded open Module Polynomial Set variable {K : Type*} [Field K] [NumberField K] variable {A : Type*} [NormedField A] [IsAlgClosed A] [NormedAlgebra ℚ A] theorem coeff_bdd_of_norm_le {B : ℝ} {x : K} (h : ∀ φ : K →+* A, ‖φ x‖ ≤ B) (i : ℕ) : ‖(minpoly ℚ x).coeff i‖ ≤ max B 1 ^ finrank ℚ K * (finrank ℚ K).choose (finrank ℚ K / 2) := by have hx := Algebra.IsSeparable.isIntegral ℚ x rw [← norm_algebraMap' A, ← coeff_map (algebraMap ℚ A)] refine coeff_bdd_of_roots_le _ (minpoly.monic hx) (IsAlgClosed.splits_codomain _) (minpoly.natDegree_le x) (fun z hz => ?_) i classical rw [← Multiset.mem_toFinset] at hz obtain ⟨φ, rfl⟩ := (range_eval_eq_rootSet_minpoly K A x).symm.subset hz exact h φ variable (K A) /-- Let `B` be a real number. The set of algebraic integers in `K` whose conjugates are all smaller in norm than `B` is finite. -/ theorem finite_of_norm_le (B : ℝ) : {x : K | IsIntegral ℤ x ∧ ∀ φ : K →+* A, ‖φ x‖ ≤ B}.Finite := by classical let C := Nat.ceil (max B 1 ^ finrank ℚ K * (finrank ℚ K).choose (finrank ℚ K / 2)) have := bUnion_roots_finite (algebraMap ℤ K) (finrank ℚ K) (finite_Icc (-C : ℤ) C) refine this.subset fun x hx => ?_; simp_rw [mem_iUnion] have h_map_ℚ_minpoly := minpoly.isIntegrallyClosed_eq_field_fractions' ℚ hx.1 refine ⟨_, ⟨?_, fun i => ?_⟩, mem_rootSet.2 ⟨minpoly.ne_zero hx.1, minpoly.aeval ℤ x⟩⟩ · rw [← (minpoly.monic hx.1).natDegree_map (algebraMap ℤ ℚ), ← h_map_ℚ_minpoly] exact minpoly.natDegree_le x rw [mem_Icc, ← abs_le, ← @Int.cast_le ℝ] refine (Eq.trans_le ?_ <| coeff_bdd_of_norm_le hx.2 i).trans (Nat.le_ceil _) rw [h_map_ℚ_minpoly, coeff_map, eq_intCast, Int.norm_cast_rat, Int.norm_eq_abs, Int.cast_abs] /-- An algebraic integer whose conjugates are all of norm one is a root of unity. -/ theorem pow_eq_one_of_norm_eq_one {x : K} (hxi : IsIntegral ℤ x) (hx : ∀ φ : K →+* A, ‖φ x‖ = 1) : ∃ (n : ℕ) (_ : 0 < n), x ^ n = 1 := by obtain ⟨a, -, b, -, habne, h⟩ := @Set.Infinite.exists_ne_map_eq_of_mapsTo _ _ _ _ (x ^ · : ℕ → K) Set.infinite_univ (by exact fun a _ => ⟨hxi.pow a, fun φ => by simp [hx φ]⟩) (finite_of_norm_le K A (1 : ℝ)) wlog hlt : b < a · exact this K A hxi hx b a habne.symm h.symm (habne.lt_or_lt.resolve_right hlt) refine ⟨a - b, tsub_pos_of_lt hlt, ?_⟩ rw [← Nat.sub_add_cancel hlt.le, pow_add, mul_left_eq_self₀] at h refine h.resolve_right fun hp => ?_ specialize hx (IsAlgClosed.lift (R := ℚ)).toRingHom rw [pow_eq_zero hp, map_zero, norm_zero] at hx; norm_num at hx end Bounded end NumberField.Embeddings section Place variable {K : Type*} [Field K] {A : Type*} [NormedDivisionRing A] [Nontrivial A] (φ : K →+* A) /-- An embedding into a normed division ring defines a place of `K` -/ def NumberField.place : AbsoluteValue K ℝ := (IsAbsoluteValue.toAbsoluteValue (norm : A → ℝ)).comp φ.injective @[simp] theorem NumberField.place_apply (x : K) : (NumberField.place φ) x = norm (φ x) := rfl end Place namespace NumberField.ComplexEmbedding open Complex NumberField open scoped ComplexConjugate variable {K : Type*} [Field K] {k : Type*} [Field k] variable (K) in /-- A (random) lift of the complex embedding `φ : k →+* ℂ` to an extension `K` of `k`. -/ noncomputable def lift [Algebra k K] [Algebra.IsAlgebraic k K] (φ : k →+* ℂ) : K →+* ℂ := by letI := φ.toAlgebra exact (IsAlgClosed.lift (R := k)).toRingHom @[simp] theorem lift_comp_algebraMap [Algebra k K] [Algebra.IsAlgebraic k K] (φ : k →+* ℂ) : (lift K φ).comp (algebraMap k K) = φ := by unfold lift letI := φ.toAlgebra rw [AlgHom.toRingHom_eq_coe, AlgHom.comp_algebraMap_of_tower, RingHom.algebraMap_toAlgebra'] @[simp] theorem lift_algebraMap_apply [Algebra k K] [Algebra.IsAlgebraic k K] (φ : k →+* ℂ) (x : k) : lift K φ (algebraMap k K x) = φ x := RingHom.congr_fun (lift_comp_algebraMap φ) x /-- The conjugate of a complex embedding as a complex embedding. -/ abbrev conjugate (φ : K →+* ℂ) : K →+* ℂ := star φ @[simp] theorem conjugate_coe_eq (φ : K →+* ℂ) (x : K) : (conjugate φ) x = conj (φ x) := rfl theorem place_conjugate (φ : K →+* ℂ) : place (conjugate φ) = place φ := by ext; simp only [place_apply, norm_conj, conjugate_coe_eq] /-- An embedding into `ℂ` is real if it is fixed by complex conjugation. -/ abbrev IsReal (φ : K →+* ℂ) : Prop := IsSelfAdjoint φ theorem isReal_iff {φ : K →+* ℂ} : IsReal φ ↔ conjugate φ = φ := isSelfAdjoint_iff theorem isReal_conjugate_iff {φ : K →+* ℂ} : IsReal (conjugate φ) ↔ IsReal φ := IsSelfAdjoint.star_iff /-- A real embedding as a ring homomorphism from `K` to `ℝ` . -/ def IsReal.embedding {φ : K →+* ℂ} (hφ : IsReal φ) : K →+* ℝ where toFun x := (φ x).re map_one' := by simp only [map_one, one_re] map_mul' := by simp only [Complex.conj_eq_iff_im.mp (RingHom.congr_fun hφ _), map_mul, mul_re, mul_zero, tsub_zero, eq_self_iff_true, forall_const] map_zero' := by simp only [map_zero, zero_re] map_add' := by simp only [map_add, add_re, eq_self_iff_true, forall_const] @[simp] theorem IsReal.coe_embedding_apply {φ : K →+* ℂ} (hφ : IsReal φ) (x : K) : (hφ.embedding x : ℂ) = φ x := by apply Complex.ext · rfl · rw [ofReal_im, eq_comm, ← Complex.conj_eq_iff_im] exact RingHom.congr_fun hφ x lemma IsReal.comp (f : k →+* K) {φ : K →+* ℂ} (hφ : IsReal φ) : IsReal (φ.comp f) := by ext1 x; simpa using RingHom.congr_fun hφ (f x) lemma isReal_comp_iff {f : k ≃+* K} {φ : K →+* ℂ} : IsReal (φ.comp (f : k →+* K)) ↔ IsReal φ := ⟨fun H ↦ by convert H.comp f.symm.toRingHom; ext1; simp, IsReal.comp _⟩ lemma exists_comp_symm_eq_of_comp_eq [Algebra k K] [IsGalois k K] (φ ψ : K →+* ℂ) (h : φ.comp (algebraMap k K) = ψ.comp (algebraMap k K)) : ∃ σ : K ≃ₐ[k] K, φ.comp σ.symm = ψ := by letI := (φ.comp (algebraMap k K)).toAlgebra letI := φ.toAlgebra have : IsScalarTower k K ℂ := IsScalarTower.of_algebraMap_eq' rfl let ψ' : K →ₐ[k] ℂ := { ψ with commutes' := fun r ↦ (RingHom.congr_fun h r).symm } use (AlgHom.restrictNormal' ψ' K).symm ext1 x exact AlgHom.restrictNormal_commutes ψ' K x variable [Algebra k K] (φ : K →+* ℂ) (σ : K ≃ₐ[k] K) /-- `IsConj φ σ` states that `σ : K ≃ₐ[k] K` is the conjugation under the embedding `φ : K →+* ℂ`. -/ def IsConj : Prop := conjugate φ = φ.comp σ variable {φ σ} lemma IsConj.eq (h : IsConj φ σ) (x) : φ (σ x) = star (φ x) := RingHom.congr_fun h.symm x lemma IsConj.ext {σ₁ σ₂ : K ≃ₐ[k] K} (h₁ : IsConj φ σ₁) (h₂ : IsConj φ σ₂) : σ₁ = σ₂ := AlgEquiv.ext fun x ↦ φ.injective ((h₁.eq x).trans (h₂.eq x).symm) lemma IsConj.ext_iff {σ₁ σ₂ : K ≃ₐ[k] K} (h₁ : IsConj φ σ₁) : σ₁ = σ₂ ↔ IsConj φ σ₂ := ⟨fun e ↦ e ▸ h₁, h₁.ext⟩ lemma IsConj.isReal_comp (h : IsConj φ σ) : IsReal (φ.comp (algebraMap k K)) := by ext1 x simp only [conjugate_coe_eq, RingHom.coe_comp, Function.comp_apply, ← h.eq, starRingEnd_apply, AlgEquiv.commutes] lemma isConj_one_iff : IsConj φ (1 : K ≃ₐ[k] K) ↔ IsReal φ := Iff.rfl alias ⟨_, IsReal.isConjGal_one⟩ := ComplexEmbedding.isConj_one_iff lemma IsConj.symm (hσ : IsConj φ σ) : IsConj φ σ.symm := RingHom.ext fun x ↦ by simpa using congr_arg star (hσ.eq (σ.symm x)) lemma isConj_symm : IsConj φ σ.symm ↔ IsConj φ σ := ⟨IsConj.symm, IsConj.symm⟩ end NumberField.ComplexEmbedding section InfinitePlace open NumberField variable {k : Type*} [Field k] (K : Type*) [Field K] {F : Type*} [Field F] /-- An infinite place of a number field `K` is a place associated to a complex embedding. -/ def NumberField.InfinitePlace := { w : AbsoluteValue K ℝ // ∃ φ : K →+* ℂ, place φ = w } instance [NumberField K] : Nonempty (NumberField.InfinitePlace K) := Set.instNonemptyRange _ variable {K} /-- Return the infinite place defined by a complex embedding `φ`. -/ noncomputable def NumberField.InfinitePlace.mk (φ : K →+* ℂ) : NumberField.InfinitePlace K := ⟨place φ, ⟨φ, rfl⟩⟩ namespace NumberField.InfinitePlace open NumberField instance {K : Type*} [Field K] : FunLike (InfinitePlace K) K ℝ where coe w x := w.1 x coe_injective' _ _ h := Subtype.eq (AbsoluteValue.ext fun x => congr_fun h x) lemma coe_apply {K : Type*} [Field K] (v : InfinitePlace K) (x : K) : v x = v.1 x := rfl @[ext] lemma ext {K : Type*} [Field K] (v₁ v₂ : InfinitePlace K) (h : ∀ k, v₁ k = v₂ k) : v₁ = v₂ := Subtype.ext <| AbsoluteValue.ext h instance : MonoidWithZeroHomClass (InfinitePlace K) K ℝ where map_mul w _ _ := w.1.map_mul _ _ map_one w := w.1.map_one map_zero w := w.1.map_zero instance : NonnegHomClass (InfinitePlace K) K ℝ where apply_nonneg w _ := w.1.nonneg _ @[simp] theorem apply (φ : K →+* ℂ) (x : K) : (mk φ) x = ‖φ x‖ := rfl /-- For an infinite place `w`, return an embedding `φ` such that `w = infinite_place φ` . -/ noncomputable def embedding (w : InfinitePlace K) : K →+* ℂ := w.2.choose @[simp] theorem mk_embedding (w : InfinitePlace K) : mk (embedding w) = w := Subtype.ext w.2.choose_spec @[simp] theorem mk_conjugate_eq (φ : K →+* ℂ) : mk (ComplexEmbedding.conjugate φ) = mk φ := by refine DFunLike.ext _ _ (fun x => ?_) rw [apply, apply, ComplexEmbedding.conjugate_coe_eq, Complex.norm_conj] theorem norm_embedding_eq (w : InfinitePlace K) (x : K) : ‖(embedding w) x‖ = w x := by nth_rewrite 2 [← mk_embedding w] rfl theorem eq_iff_eq (x : K) (r : ℝ) : (∀ w : InfinitePlace K, w x = r) ↔ ∀ φ : K →+* ℂ, ‖φ x‖ = r := ⟨fun hw φ => hw (mk φ), by rintro hφ ⟨w, ⟨φ, rfl⟩⟩; exact hφ φ⟩ theorem le_iff_le (x : K) (r : ℝ) : (∀ w : InfinitePlace K, w x ≤ r) ↔ ∀ φ : K →+* ℂ, ‖φ x‖ ≤ r := ⟨fun hw φ => hw (mk φ), by rintro hφ ⟨w, ⟨φ, rfl⟩⟩; exact hφ φ⟩ theorem pos_iff {w : InfinitePlace K} {x : K} : 0 < w x ↔ x ≠ 0 := AbsoluteValue.pos_iff w.1 @[simp] theorem mk_eq_iff {φ ψ : K →+* ℂ} : mk φ = mk ψ ↔ φ = ψ ∨ ComplexEmbedding.conjugate φ = ψ := by constructor · -- We prove that the map ψ ∘ φ⁻¹ between φ(K) and ℂ is uniform continuous, thus it is either the -- inclusion or the complex conjugation using `Complex.uniformContinuous_ringHom_eq_id_or_conj` intro h₀ obtain ⟨j, hiφ⟩ := (φ.injective).hasLeftInverse let ι := RingEquiv.ofLeftInverse hiφ have hlip : LipschitzWith 1 (RingHom.comp ψ ι.symm.toRingHom) := by change LipschitzWith 1 (ψ ∘ ι.symm) apply LipschitzWith.of_dist_le_mul intro x y rw [NNReal.coe_one, one_mul, NormedField.dist_eq, Function.comp_apply, Function.comp_apply, ← map_sub, ← map_sub] apply le_of_eq suffices ‖φ (ι.symm (x - y))‖ = ‖ψ (ι.symm (x - y))‖ by rw [← this, ← RingEquiv.ofLeftInverse_apply hiφ _, RingEquiv.apply_symm_apply ι _] rfl exact congrFun (congrArg (↑) h₀) _ cases Complex.uniformContinuous_ringHom_eq_id_or_conj φ.fieldRange hlip.uniformContinuous with | inl h => left; ext1 x conv_rhs => rw [← hiφ x] exact (congrFun h (ι x)).symm | inr h => right; ext1 x conv_rhs => rw [← hiφ x] exact (congrFun h (ι x)).symm · rintro (⟨h⟩ | ⟨h⟩) · exact congr_arg mk h · rw [← mk_conjugate_eq] exact congr_arg mk h /-- An infinite place is real if it is defined by a real embedding. -/ def IsReal (w : InfinitePlace K) : Prop := ∃ φ : K →+* ℂ, ComplexEmbedding.IsReal φ ∧ mk φ = w /-- An infinite place is complex if it is defined by a complex (ie. not real) embedding. -/ def IsComplex (w : InfinitePlace K) : Prop := ∃ φ : K →+* ℂ, ¬ComplexEmbedding.IsReal φ ∧ mk φ = w theorem embedding_mk_eq (φ : K →+* ℂ) : embedding (mk φ) = φ ∨ embedding (mk φ) = ComplexEmbedding.conjugate φ := by rw [@eq_comm _ _ φ, @eq_comm _ _ (ComplexEmbedding.conjugate φ), ← mk_eq_iff, mk_embedding] @[simp] theorem embedding_mk_eq_of_isReal {φ : K →+* ℂ} (h : ComplexEmbedding.IsReal φ) : embedding (mk φ) = φ := by have := embedding_mk_eq φ rwa [ComplexEmbedding.isReal_iff.mp h, or_self] at this theorem isReal_iff {w : InfinitePlace K} : IsReal w ↔ ComplexEmbedding.IsReal (embedding w) := by refine ⟨?_, fun h => ⟨embedding w, h, mk_embedding w⟩⟩ rintro ⟨φ, ⟨hφ, rfl⟩⟩ rwa [embedding_mk_eq_of_isReal hφ] theorem isComplex_iff {w : InfinitePlace K} : IsComplex w ↔ ¬ComplexEmbedding.IsReal (embedding w) := by refine ⟨?_, fun h => ⟨embedding w, h, mk_embedding w⟩⟩ rintro ⟨φ, ⟨hφ, rfl⟩⟩ contrapose! hφ cases mk_eq_iff.mp (mk_embedding (mk φ)) with | inl h => rwa [h] at hφ | inr h => rwa [← ComplexEmbedding.isReal_conjugate_iff, h] at hφ @[simp] theorem conjugate_embedding_eq_of_isReal {w : InfinitePlace K} (h : IsReal w) : ComplexEmbedding.conjugate (embedding w) = embedding w := ComplexEmbedding.isReal_iff.mpr (isReal_iff.mp h) @[simp] theorem not_isReal_iff_isComplex {w : InfinitePlace K} : ¬IsReal w ↔ IsComplex w := by rw [isComplex_iff, isReal_iff] @[simp] theorem not_isComplex_iff_isReal {w : InfinitePlace K} : ¬IsComplex w ↔ IsReal w := by rw [isComplex_iff, isReal_iff, not_not] theorem isReal_or_isComplex (w : InfinitePlace K) : IsReal w ∨ IsComplex w := by rw [← not_isReal_iff_isComplex]; exact em _ theorem ne_of_isReal_isComplex {w w' : InfinitePlace K} (h : IsReal w) (h' : IsComplex w') : w ≠ w' := fun h_eq ↦ not_isReal_iff_isComplex.mpr h' (h_eq ▸ h) variable (K) in theorem disjoint_isReal_isComplex : Disjoint {(w : InfinitePlace K) | IsReal w} {(w : InfinitePlace K) | IsComplex w} := Set.disjoint_iff.2 <| fun _ hw ↦ not_isReal_iff_isComplex.2 hw.2 hw.1 /-- The real embedding associated to a real infinite place. -/ noncomputable def embedding_of_isReal {w : InfinitePlace K} (hw : IsReal w) : K →+* ℝ := ComplexEmbedding.IsReal.embedding (isReal_iff.mp hw) @[simp] theorem embedding_of_isReal_apply {w : InfinitePlace K} (hw : IsReal w) (x : K) : ((embedding_of_isReal hw) x : ℂ) = (embedding w) x := ComplexEmbedding.IsReal.coe_embedding_apply (isReal_iff.mp hw) x theorem norm_embedding_of_isReal {w : InfinitePlace K} (hw : IsReal w) (x : K) : ‖embedding_of_isReal hw x‖ = w x := by rw [← norm_embedding_eq, ← embedding_of_isReal_apply hw, Complex.norm_real] @[simp] theorem isReal_of_mk_isReal {φ : K →+* ℂ} (h : IsReal (mk φ)) : ComplexEmbedding.IsReal φ := by contrapose! h rw [not_isReal_iff_isComplex] exact ⟨φ, h, rfl⟩ lemma isReal_mk_iff {φ : K →+* ℂ} : IsReal (mk φ) ↔ ComplexEmbedding.IsReal φ := ⟨isReal_of_mk_isReal, fun H ↦ ⟨_, H, rfl⟩⟩ lemma isComplex_mk_iff {φ : K →+* ℂ} : IsComplex (mk φ) ↔ ¬ ComplexEmbedding.IsReal φ := not_isReal_iff_isComplex.symm.trans isReal_mk_iff.not @[simp] theorem not_isReal_of_mk_isComplex {φ : K →+* ℂ} (h : IsComplex (mk φ)) : ¬ ComplexEmbedding.IsReal φ := by rwa [← isComplex_mk_iff] open scoped Classical in /-- The multiplicity of an infinite place, that is the number of distinct complex embeddings that define it, see `card_filter_mk_eq`. -/ noncomputable def mult (w : InfinitePlace K) : ℕ := if (IsReal w) then 1 else 2 @[simp] theorem mult_isReal (w : {w : InfinitePlace K // IsReal w}) : mult w.1 = 1 := by rw [mult, if_pos w.prop] @[simp] theorem mult_isComplex (w : {w : InfinitePlace K // IsComplex w}) : mult w.1 = 2 := by rw [mult, if_neg (not_isReal_iff_isComplex.mpr w.prop)] theorem mult_pos {w : InfinitePlace K} : 0 < mult w := by rw [mult] split_ifs <;> norm_num @[simp] theorem mult_ne_zero {w : InfinitePlace K} : mult w ≠ 0 := ne_of_gt mult_pos theorem mult_coe_ne_zero {w : InfinitePlace K} : (mult w : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr mult_ne_zero theorem one_le_mult {w : InfinitePlace K} : (1 : ℝ) ≤ mult w := by rw [← Nat.cast_one, Nat.cast_le] exact mult_pos open scoped Classical in theorem card_filter_mk_eq [NumberField K] (w : InfinitePlace K) : #{φ | mk φ = w} = mult w := by conv_lhs => congr; congr; ext rw [← mk_embedding w, mk_eq_iff, ComplexEmbedding.conjugate, star_involutive.eq_iff] simp_rw [Finset.filter_or, Finset.filter_eq' _ (embedding w), Finset.filter_eq' _ (ComplexEmbedding.conjugate (embedding w)), Finset.mem_univ, ite_true, mult] split_ifs with hw · rw [ComplexEmbedding.isReal_iff.mp (isReal_iff.mp hw), Finset.union_idempotent, Finset.card_singleton] · refine Finset.card_pair ?_ rwa [Ne, eq_comm, ← ComplexEmbedding.isReal_iff, ← isReal_iff] open scoped Classical in noncomputable instance NumberField.InfinitePlace.fintype [NumberField K] : Fintype (InfinitePlace K) := Set.fintypeRange _ open scoped Classical in @[to_additive] theorem prod_eq_prod_mul_prod {α : Type*} [CommMonoid α] [NumberField K] (f : InfinitePlace K → α) : ∏ w, f w = (∏ w : {w // IsReal w}, f w.1) * (∏ w : {w // IsComplex w}, f w.1) := by rw [← Equiv.prod_comp (Equiv.subtypeEquivRight (fun _ ↦ not_isReal_iff_isComplex))] simp [Fintype.prod_subtype_mul_prod_subtype] theorem sum_mult_eq [NumberField K] : ∑ w : InfinitePlace K, mult w = Module.finrank ℚ K := by classical rw [← Embeddings.card K ℂ, Fintype.card, Finset.card_eq_sum_ones, ← Finset.univ.sum_fiberwise (fun φ => InfinitePlace.mk φ)] exact Finset.sum_congr rfl (fun _ _ => by rw [Finset.sum_const, smul_eq_mul, mul_one, card_filter_mk_eq]) /-- The map from real embeddings to real infinite places as an equiv -/ noncomputable def mkReal : { φ : K →+* ℂ // ComplexEmbedding.IsReal φ } ≃ { w : InfinitePlace K // IsReal w } := by refine (Equiv.ofBijective (fun φ => ⟨mk φ, ?_⟩) ⟨fun φ ψ h => ?_, fun w => ?_⟩) · exact ⟨φ, φ.prop, rfl⟩ · rwa [Subtype.mk.injEq, mk_eq_iff, ComplexEmbedding.isReal_iff.mp φ.prop, or_self, ← Subtype.ext_iff] at h · exact ⟨⟨embedding w, isReal_iff.mp w.prop⟩, by simp⟩ /-- The map from nonreal embeddings to complex infinite places -/ noncomputable def mkComplex : { φ : K →+* ℂ // ¬ComplexEmbedding.IsReal φ } → { w : InfinitePlace K // IsComplex w } := Subtype.map mk fun φ hφ => ⟨φ, hφ, rfl⟩ @[simp] theorem mkReal_coe (φ : { φ : K →+* ℂ // ComplexEmbedding.IsReal φ }) : (mkReal φ : InfinitePlace K) = mk (φ : K →+* ℂ) := rfl @[simp] theorem mkComplex_coe (φ : { φ : K →+* ℂ // ¬ComplexEmbedding.IsReal φ }) : (mkComplex φ : InfinitePlace K) = mk (φ : K →+* ℂ) := rfl section NumberField variable [NumberField K] /-- The infinite part of the product formula : for `x ∈ K`, we have `Π_w ‖x‖_w = |norm(x)|` where `‖·‖_w` is the normalized absolute value for `w`. -/ theorem prod_eq_abs_norm (x : K) : ∏ w : InfinitePlace K, w x ^ mult w = abs (Algebra.norm ℚ x) := by classical convert (congr_arg (‖·‖) (@Algebra.norm_eq_prod_embeddings ℚ _ _ _ _ ℂ _ _ _ _ _ x)).symm · rw [norm_prod, ← Fintype.prod_equiv RingHom.equivRatAlgHom (fun f => ‖f x‖) (fun φ => ‖φ x‖) fun _ => by simp [RingHom.equivRatAlgHom_apply]] rw [← Finset.prod_fiberwise Finset.univ mk (fun φ => ‖φ x‖)] have (w : InfinitePlace K) (φ) (hφ : φ ∈ ({φ | mk φ = w} : Finset _)) : ‖φ x‖ = w x := by rw [← (Finset.mem_filter.mp hφ).2, apply] simp_rw [Finset.prod_congr rfl (this _), Finset.prod_const, card_filter_mk_eq] · rw [eq_ratCast, Rat.cast_abs, ← Real.norm_eq_abs, ← Complex.norm_real, Complex.ofReal_ratCast] theorem one_le_of_lt_one {w : InfinitePlace K} {a : (𝓞 K)} (ha : a ≠ 0) (h : ∀ ⦃z⦄, z ≠ w → z a < 1) : 1 ≤ w a := by suffices (1 : ℝ) ≤ |Algebra.norm ℚ (a : K)| by contrapose! this rw [← InfinitePlace.prod_eq_abs_norm, ← Finset.prod_const_one] refine Finset.prod_lt_prod_of_nonempty (fun _ _ ↦ ?_) (fun z _ ↦ ?_) Finset.univ_nonempty · exact pow_pos (pos_iff.mpr ((Subalgebra.coe_eq_zero _).not.mpr ha)) _ · refine pow_lt_one₀ (apply_nonneg _ _) ?_ (by rw [mult]; split_ifs <;> norm_num) by_cases hz : z = w · rwa [hz] · exact h hz rw [← Algebra.coe_norm_int, ← Int.cast_one, ← Int.cast_abs, Rat.cast_intCast, Int.cast_le] exact Int.one_le_abs (Algebra.norm_ne_zero_iff.mpr ha) open scoped IntermediateField in theorem _root_.NumberField.is_primitive_element_of_infinitePlace_lt {x : 𝓞 K} {w : InfinitePlace K} (h₁ : x ≠ 0) (h₂ : ∀ ⦃w'⦄, w' ≠ w → w' x < 1) (h₃ : IsReal w ∨ |(w.embedding x).re| < 1) : ℚ⟮(x : K)⟯ = ⊤ := by rw [Field.primitive_element_iff_algHom_eq_of_eval ℚ ℂ ?_ _ w.embedding.toRatAlgHom] · intro ψ hψ have h : 1 ≤ w x := one_le_of_lt_one h₁ h₂ have main : w = InfinitePlace.mk ψ.toRingHom := by simp at hψ rw [← norm_embedding_eq, hψ] at h contrapose! h exact h₂ h.symm rw [(mk_embedding w).symm, mk_eq_iff] at main cases h₃ with | inl hw => rw [conjugate_embedding_eq_of_isReal hw, or_self] at main exact congr_arg RingHom.toRatAlgHom main | inr hw => refine congr_arg RingHom.toRatAlgHom (main.resolve_right fun h' ↦ hw.not_le ?_) have : (embedding w x).im = 0 := by rw [← Complex.conj_eq_iff_im] have := RingHom.congr_fun h' x simp at this rw [this] exact hψ.symm rwa [← norm_embedding_eq, ← Complex.re_add_im (embedding w x), this, Complex.ofReal_zero, zero_mul, add_zero, Complex.norm_real] at h · exact fun x ↦ IsAlgClosed.splits_codomain (minpoly ℚ x) theorem _root_.NumberField.adjoin_eq_top_of_infinitePlace_lt {x : 𝓞 K} {w : InfinitePlace K} (h₁ : x ≠ 0) (h₂ : ∀ ⦃w'⦄, w' ≠ w → w' x < 1) (h₃ : IsReal w ∨ |(w.embedding x).re| < 1) : Algebra.adjoin ℚ {(x : K)} = ⊤ := by rw [← IntermediateField.adjoin_simple_toSubalgebra_of_integral (IsIntegral.of_finite ℚ _)] exact congr_arg IntermediateField.toSubalgebra <| NumberField.is_primitive_element_of_infinitePlace_lt h₁ h₂ h₃ end NumberField open Fintype Module variable (K) section NumberField variable [NumberField K] open scoped Classical in /-- The number of infinite real places of the number field `K`. -/ noncomputable abbrev nrRealPlaces := card { w : InfinitePlace K // IsReal w } @[deprecated (since := "2024-10-24")] alias NrRealPlaces := nrRealPlaces open scoped Classical in /-- The number of infinite complex places of the number field `K`. -/ noncomputable abbrev nrComplexPlaces := card { w : InfinitePlace K // IsComplex w } @[deprecated (since := "2024-10-24")] alias NrComplexPlaces := nrComplexPlaces open scoped Classical in theorem card_real_embeddings : card { φ : K →+* ℂ // ComplexEmbedding.IsReal φ } = nrRealPlaces K := Fintype.card_congr mkReal theorem card_eq_nrRealPlaces_add_nrComplexPlaces : Fintype.card (InfinitePlace K) = nrRealPlaces K + nrComplexPlaces K := by classical convert Fintype.card_subtype_or_disjoint (IsReal (K := K)) (IsComplex (K := K)) (disjoint_isReal_isComplex K) using 1 exact (Fintype.card_of_subtype _ (fun w ↦ ⟨fun _ ↦ isReal_or_isComplex w, fun _ ↦ by simp⟩)).symm open scoped Classical in theorem card_complex_embeddings : card { φ : K →+* ℂ // ¬ComplexEmbedding.IsReal φ } = 2 * nrComplexPlaces K := by suffices ∀ w : { w : InfinitePlace K // IsComplex w }, #{φ : {φ //¬ ComplexEmbedding.IsReal φ} | mkComplex φ = w} = 2 by rw [Fintype.card, Finset.card_eq_sum_ones, ← Finset.sum_fiberwise _ (fun φ => mkComplex φ)] simp_rw [Finset.sum_const, this, smul_eq_mul, mul_one, Fintype.card, Finset.card_eq_sum_ones, Finset.mul_sum, Finset.sum_const, smul_eq_mul, mul_one] rintro ⟨w, hw⟩ convert card_filter_mk_eq w · rw [← Fintype.card_subtype, ← Fintype.card_subtype] refine Fintype.card_congr (Equiv.ofBijective ?_ ⟨fun _ _ h => ?_, fun ⟨φ, hφ⟩ => ?_⟩) · exact fun ⟨φ, hφ⟩ => ⟨φ.val, by rwa [Subtype.ext_iff] at hφ⟩ · rwa [Subtype.mk_eq_mk, ← Subtype.ext_iff, ← Subtype.ext_iff] at h · refine ⟨⟨⟨φ, not_isReal_of_mk_isComplex (hφ.symm ▸ hw)⟩, ?_⟩, rfl⟩ rwa [Subtype.ext_iff, mkComplex_coe] · simp_rw [mult, not_isReal_iff_isComplex.mpr hw, ite_false] theorem card_add_two_mul_card_eq_rank : nrRealPlaces K + 2 * nrComplexPlaces K = finrank ℚ K := by classical rw [← card_real_embeddings, ← card_complex_embeddings, Fintype.card_subtype_compl, ← Embeddings.card K ℂ, Nat.add_sub_of_le] exact Fintype.card_subtype_le _ variable {K} theorem nrComplexPlaces_eq_zero_of_finrank_eq_one (h : finrank ℚ K = 1) : nrComplexPlaces K = 0 := by linarith [card_add_two_mul_card_eq_rank K]
theorem nrRealPlaces_eq_one_of_finrank_eq_one (h : finrank ℚ K = 1) : nrRealPlaces K = 1 := by have := card_add_two_mul_card_eq_rank K rwa [nrComplexPlaces_eq_zero_of_finrank_eq_one h, h, mul_zero, add_zero] at this
Mathlib/NumberTheory/NumberField/Embeddings.lean
661
665
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Data.Finset.Sort import Mathlib.Data.Fin.VecNotation import Mathlib.Data.Sign import Mathlib.LinearAlgebra.AffineSpace.Combination import Mathlib.LinearAlgebra.AffineSpace.AffineEquiv import Mathlib.LinearAlgebra.Basis.VectorSpace /-! # Affine independence This file defines affinely independent families of points. ## Main definitions * `AffineIndependent` defines affinely independent families of points as those where no nontrivial weighted subtraction is `0`. This is proved equivalent to two other formulations: linear independence of the results of subtracting a base point in the family from the other points in the family, or any equal affine combinations having the same weights. A bundled type `Simplex` is provided for finite affinely independent families of points, with an abbreviation `Triangle` for the case of three points. ## References * https://en.wikipedia.org/wiki/Affine_space -/ noncomputable section open Finset Function open scoped Affine section AffineIndependent variable (k : Type*) {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] variable [AffineSpace V P] {ι : Type*} /-- An indexed family is said to be affinely independent if no nontrivial weighted subtractions (where the sum of weights is 0) are 0. -/ def AffineIndependent (p : ι → P) : Prop := ∀ (s : Finset ι) (w : ι → k), ∑ i ∈ s, w i = 0 → s.weightedVSub p w = (0 : V) → ∀ i ∈ s, w i = 0 /-- The definition of `AffineIndependent`. -/ theorem affineIndependent_def (p : ι → P) : AffineIndependent k p ↔ ∀ (s : Finset ι) (w : ι → k), ∑ i ∈ s, w i = 0 → s.weightedVSub p w = (0 : V) → ∀ i ∈ s, w i = 0 := Iff.rfl /-- A family with at most one point is affinely independent. -/ theorem affineIndependent_of_subsingleton [Subsingleton ι] (p : ι → P) : AffineIndependent k p := fun _ _ h _ i hi => Fintype.eq_of_subsingleton_of_sum_eq h i hi /-- A family indexed by a `Fintype` is affinely independent if and only if no nontrivial weighted subtractions over `Finset.univ` (where the sum of the weights is 0) are 0. -/ theorem affineIndependent_iff_of_fintype [Fintype ι] (p : ι → P) : AffineIndependent k p ↔ ∀ w : ι → k, ∑ i, w i = 0 → Finset.univ.weightedVSub p w = (0 : V) → ∀ i, w i = 0 := by constructor · exact fun h w hw hs i => h Finset.univ w hw hs i (Finset.mem_univ _) · intro h s w hw hs i hi rw [Finset.weightedVSub_indicator_subset _ _ (Finset.subset_univ s)] at hs rw [← Finset.sum_indicator_subset _ (Finset.subset_univ s)] at hw replace h := h ((↑s : Set ι).indicator w) hw hs i simpa [hi] using h @[simp] lemma affineIndependent_vadd {p : ι → P} {v : V} : AffineIndependent k (v +ᵥ p) ↔ AffineIndependent k p := by simp +contextual [AffineIndependent, weightedVSub_vadd] protected alias ⟨AffineIndependent.of_vadd, AffineIndependent.vadd⟩ := affineIndependent_vadd @[simp] lemma affineIndependent_smul {G : Type*} [Group G] [DistribMulAction G V] [SMulCommClass G k V] {p : ι → V} {a : G} : AffineIndependent k (a • p) ↔ AffineIndependent k p := by simp +contextual [AffineIndependent, weightedVSub_smul, ← smul_comm (α := V) a, ← smul_sum, smul_eq_zero_iff_eq] protected alias ⟨AffineIndependent.of_smul, AffineIndependent.smul⟩ := affineIndependent_smul /-- A family is affinely independent if and only if the differences from a base point in that family are linearly independent. -/ theorem affineIndependent_iff_linearIndependent_vsub (p : ι → P) (i1 : ι) : AffineIndependent k p ↔ LinearIndependent k fun i : { x // x ≠ i1 } => (p i -ᵥ p i1 : V) := by classical constructor · intro h rw [linearIndependent_iff'] intro s g hg i hi set f : ι → k := fun x => if hx : x = i1 then -∑ y ∈ s, g y else g ⟨x, hx⟩ with hfdef let s2 : Finset ι := insert i1 (s.map (Embedding.subtype _)) have hfg : ∀ x : { x // x ≠ i1 }, g x = f x := by intro x rw [hfdef] dsimp only rw [dif_neg x.property, Subtype.coe_eta] rw [hfg] have hf : ∑ ι ∈ s2, f ι = 0 := by rw [Finset.sum_insert (Finset.not_mem_map_subtype_of_not_property s (Classical.not_not.2 rfl)), Finset.sum_subtype_map_embedding fun x _ => (hfg x).symm] rw [hfdef] dsimp only rw [dif_pos rfl] exact neg_add_cancel _ have hs2 : s2.weightedVSub p f = (0 : V) := by set f2 : ι → V := fun x => f x • (p x -ᵥ p i1) with hf2def set g2 : { x // x ≠ i1 } → V := fun x => g x • (p x -ᵥ p i1) have hf2g2 : ∀ x : { x // x ≠ i1 }, f2 x = g2 x := by simp only [g2, hf2def] refine fun x => ?_ rw [hfg] rw [Finset.weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero s2 f p hf (p i1), Finset.weightedVSubOfPoint_insert, Finset.weightedVSubOfPoint_apply, Finset.sum_subtype_map_embedding fun x _ => hf2g2 x] exact hg exact h s2 f hf hs2 i (Finset.mem_insert_of_mem (Finset.mem_map.2 ⟨i, hi, rfl⟩)) · intro h rw [linearIndependent_iff'] at h intro s w hw hs i hi rw [Finset.weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero s w p hw (p i1), ← s.weightedVSubOfPoint_erase w p i1, Finset.weightedVSubOfPoint_apply] at hs let f : ι → V := fun i => w i • (p i -ᵥ p i1) have hs2 : (∑ i ∈ (s.erase i1).subtype fun i => i ≠ i1, f i) = 0 := by rw [← hs] convert Finset.sum_subtype_of_mem f fun x => Finset.ne_of_mem_erase have h2 := h ((s.erase i1).subtype fun i => i ≠ i1) (fun x => w x) hs2 simp_rw [Finset.mem_subtype] at h2 have h2b : ∀ i ∈ s, i ≠ i1 → w i = 0 := fun i his hi => h2 ⟨i, hi⟩ (Finset.mem_erase_of_ne_of_mem hi his) exact Finset.eq_zero_of_sum_eq_zero hw h2b i hi /-- A set is affinely independent if and only if the differences from a base point in that set are linearly independent. -/ theorem affineIndependent_set_iff_linearIndependent_vsub {s : Set P} {p₁ : P} (hp₁ : p₁ ∈ s) : AffineIndependent k (fun p => p : s → P) ↔ LinearIndependent k (fun v => v : (fun p => (p -ᵥ p₁ : V)) '' (s \ {p₁}) → V) := by rw [affineIndependent_iff_linearIndependent_vsub k (fun p => p : s → P) ⟨p₁, hp₁⟩] constructor · intro h have hv : ∀ v : (fun p => (p -ᵥ p₁ : V)) '' (s \ {p₁}), (v : V) +ᵥ p₁ ∈ s \ {p₁} := fun v => (vsub_left_injective p₁).mem_set_image.1 ((vadd_vsub (v : V) p₁).symm ▸ v.property) let f : (fun p : P => (p -ᵥ p₁ : V)) '' (s \ {p₁}) → { x : s // x ≠ ⟨p₁, hp₁⟩ } := fun x => ⟨⟨(x : V) +ᵥ p₁, Set.mem_of_mem_diff (hv x)⟩, fun hx => Set.not_mem_of_mem_diff (hv x) (Subtype.ext_iff.1 hx)⟩ convert h.comp f fun x1 x2 hx => Subtype.ext (vadd_right_cancel p₁ (Subtype.ext_iff.1 (Subtype.ext_iff.1 hx))) ext v exact (vadd_vsub (v : V) p₁).symm · intro h let f : { x : s // x ≠ ⟨p₁, hp₁⟩ } → (fun p : P => (p -ᵥ p₁ : V)) '' (s \ {p₁}) := fun x => ⟨((x : s) : P) -ᵥ p₁, ⟨x, ⟨⟨(x : s).property, fun hx => x.property (Subtype.ext hx)⟩, rfl⟩⟩⟩ convert h.comp f fun x1 x2 hx => Subtype.ext (Subtype.ext (vsub_left_cancel (Subtype.ext_iff.1 hx))) /-- A set of nonzero vectors is linearly independent if and only if, given a point `p₁`, the vectors added to `p₁` and `p₁` itself are affinely independent. -/ theorem linearIndependent_set_iff_affineIndependent_vadd_union_singleton {s : Set V} (hs : ∀ v ∈ s, v ≠ (0 : V)) (p₁ : P) : LinearIndependent k (fun v => v : s → V) ↔ AffineIndependent k (fun p => p : ({p₁} ∪ (fun v => v +ᵥ p₁) '' s : Set P) → P) := by rw [affineIndependent_set_iff_linearIndependent_vsub k (Set.mem_union_left _ (Set.mem_singleton p₁))] have h : (fun p => (p -ᵥ p₁ : V)) '' (({p₁} ∪ (fun v => v +ᵥ p₁) '' s) \ {p₁}) = s := by simp_rw [Set.union_diff_left, Set.image_diff (vsub_left_injective p₁), Set.image_image, Set.image_singleton, vsub_self, vadd_vsub, Set.image_id'] exact Set.diff_singleton_eq_self fun h => hs 0 h rfl rw [h] /-- A family is affinely independent if and only if any affine combinations (with sum of weights 1) that evaluate to the same point have equal `Set.indicator`. -/ theorem affineIndependent_iff_indicator_eq_of_affineCombination_eq (p : ι → P) : AffineIndependent k p ↔ ∀ (s1 s2 : Finset ι) (w1 w2 : ι → k), ∑ i ∈ s1, w1 i = 1 → ∑ i ∈ s2, w2 i = 1 → s1.affineCombination k p w1 = s2.affineCombination k p w2 → Set.indicator (↑s1) w1 = Set.indicator (↑s2) w2 := by classical constructor · intro ha s1 s2 w1 w2 hw1 hw2 heq ext i by_cases hi : i ∈ s1 ∪ s2 · rw [← sub_eq_zero] rw [← Finset.sum_indicator_subset w1 (s1.subset_union_left (s₂ := s2))] at hw1 rw [← Finset.sum_indicator_subset w2 (s1.subset_union_right)] at hw2 have hws : (∑ i ∈ s1 ∪ s2, (Set.indicator (↑s1) w1 - Set.indicator (↑s2) w2) i) = 0 := by simp [hw1, hw2] rw [Finset.affineCombination_indicator_subset w1 p (s1.subset_union_left (s₂ := s2)), Finset.affineCombination_indicator_subset w2 p s1.subset_union_right, ← @vsub_eq_zero_iff_eq V, Finset.affineCombination_vsub] at heq exact ha (s1 ∪ s2) (Set.indicator (↑s1) w1 - Set.indicator (↑s2) w2) hws heq i hi · rw [← Finset.mem_coe, Finset.coe_union] at hi have h₁ : Set.indicator (↑s1) w1 i = 0 := by simp only [Set.indicator, Finset.mem_coe, ite_eq_right_iff] intro h by_contra exact (mt (@Set.mem_union_left _ i ↑s1 ↑s2) hi) h have h₂ : Set.indicator (↑s2) w2 i = 0 := by simp only [Set.indicator, Finset.mem_coe, ite_eq_right_iff] intro h by_contra exact (mt (@Set.mem_union_right _ i ↑s2 ↑s1) hi) h simp [h₁, h₂] · intro ha s w hw hs i0 hi0 let w1 : ι → k := Function.update (Function.const ι 0) i0 1 have hw1 : ∑ i ∈ s, w1 i = 1 := by rw [Finset.sum_update_of_mem hi0] simp only [Finset.sum_const_zero, add_zero, const_apply] have hw1s : s.affineCombination k p w1 = p i0 := s.affineCombination_of_eq_one_of_eq_zero w1 p hi0 (Function.update_self ..) fun _ _ hne => Function.update_of_ne hne .. let w2 := w + w1 have hw2 : ∑ i ∈ s, w2 i = 1 := by simp_all only [w2, Pi.add_apply, Finset.sum_add_distrib, zero_add] have hw2s : s.affineCombination k p w2 = p i0 := by simp_all only [w2, ← Finset.weightedVSub_vadd_affineCombination, zero_vadd] replace ha := ha s s w2 w1 hw2 hw1 (hw1s.symm ▸ hw2s) have hws : w2 i0 - w1 i0 = 0 := by rw [← Finset.mem_coe] at hi0 rw [← Set.indicator_of_mem hi0 w2, ← Set.indicator_of_mem hi0 w1, ha, sub_self] simpa [w2] using hws /-- A finite family is affinely independent if and only if any affine combinations (with sum of weights 1) that evaluate to the same point are equal. -/ theorem affineIndependent_iff_eq_of_fintype_affineCombination_eq [Fintype ι] (p : ι → P) : AffineIndependent k p ↔ ∀ w1 w2 : ι → k, ∑ i, w1 i = 1 → ∑ i, w2 i = 1 → Finset.univ.affineCombination k p w1 = Finset.univ.affineCombination k p w2 → w1 = w2 := by rw [affineIndependent_iff_indicator_eq_of_affineCombination_eq] constructor · intro h w1 w2 hw1 hw2 hweq simpa only [Set.indicator_univ, Finset.coe_univ] using h _ _ w1 w2 hw1 hw2 hweq · intro h s1 s2 w1 w2 hw1 hw2 hweq have hw1' : (∑ i, (s1 : Set ι).indicator w1 i) = 1 := by rwa [Finset.sum_indicator_subset _ (Finset.subset_univ s1)] have hw2' : (∑ i, (s2 : Set ι).indicator w2 i) = 1 := by rwa [Finset.sum_indicator_subset _ (Finset.subset_univ s2)] rw [Finset.affineCombination_indicator_subset w1 p (Finset.subset_univ s1), Finset.affineCombination_indicator_subset w2 p (Finset.subset_univ s2)] at hweq exact h _ _ hw1' hw2' hweq variable {k} /-- If we single out one member of an affine-independent family of points and affinely transport all others along the line joining them to this member, the resulting new family of points is affine- independent. This is the affine version of `LinearIndependent.units_smul`. -/ theorem AffineIndependent.units_lineMap {p : ι → P} (hp : AffineIndependent k p) (j : ι) (w : ι → Units k) : AffineIndependent k fun i => AffineMap.lineMap (p j) (p i) (w i : k) := by rw [affineIndependent_iff_linearIndependent_vsub k _ j] at hp ⊢ simp only [AffineMap.lineMap_vsub_left, AffineMap.coe_const, AffineMap.lineMap_same, const_apply] exact hp.units_smul fun i => w i theorem AffineIndependent.indicator_eq_of_affineCombination_eq {p : ι → P} (ha : AffineIndependent k p) (s₁ s₂ : Finset ι) (w₁ w₂ : ι → k) (hw₁ : ∑ i ∈ s₁, w₁ i = 1) (hw₂ : ∑ i ∈ s₂, w₂ i = 1) (h : s₁.affineCombination k p w₁ = s₂.affineCombination k p w₂) : Set.indicator (↑s₁) w₁ = Set.indicator (↑s₂) w₂ := (affineIndependent_iff_indicator_eq_of_affineCombination_eq k p).1 ha s₁ s₂ w₁ w₂ hw₁ hw₂ h /-- An affinely independent family is injective, if the underlying ring is nontrivial. -/ protected theorem AffineIndependent.injective [Nontrivial k] {p : ι → P} (ha : AffineIndependent k p) : Function.Injective p := by intro i j hij rw [affineIndependent_iff_linearIndependent_vsub _ _ j] at ha by_contra hij' refine ha.ne_zero ⟨i, hij'⟩ (vsub_eq_zero_iff_eq.mpr ?_) simp_all only [ne_eq] /-- If a family is affinely independent, so is any subfamily given by composition of an embedding into index type with the original family. -/ theorem AffineIndependent.comp_embedding {ι2 : Type*} (f : ι2 ↪ ι) {p : ι → P} (ha : AffineIndependent k p) : AffineIndependent k (p ∘ f) := by classical intro fs w hw hs i0 hi0 let fs' := fs.map f let w' i := if h : ∃ i2, f i2 = i then w h.choose else 0 have hw' : ∀ i2 : ι2, w' (f i2) = w i2 := by intro i2 have h : ∃ i : ι2, f i = f i2 := ⟨i2, rfl⟩ have hs : h.choose = i2 := f.injective h.choose_spec simp_rw [w', dif_pos h, hs] have hw's : ∑ i ∈ fs', w' i = 0 := by rw [← hw, Finset.sum_map] simp [hw'] have hs' : fs'.weightedVSub p w' = (0 : V) := by rw [← hs, Finset.weightedVSub_map] congr with i simp_all only [comp_apply, EmbeddingLike.apply_eq_iff_eq, exists_eq, dite_true] rw [← ha fs' w' hw's hs' (f i0) ((Finset.mem_map' _).2 hi0), hw'] /-- If a family is affinely independent, so is any subfamily indexed by a subtype of the index type. -/ protected theorem AffineIndependent.subtype {p : ι → P} (ha : AffineIndependent k p) (s : Set ι) : AffineIndependent k fun i : s => p i := ha.comp_embedding (Embedding.subtype _) /-- If an indexed family of points is affinely independent, so is the corresponding set of points. -/ protected theorem AffineIndependent.range {p : ι → P} (ha : AffineIndependent k p) : AffineIndependent k (fun x => x : Set.range p → P) := by let f : Set.range p → ι := fun x => x.property.choose have hf : ∀ x, p (f x) = x := fun x => x.property.choose_spec let fe : Set.range p ↪ ι := ⟨f, fun x₁ x₂ he => Subtype.ext (hf x₁ ▸ hf x₂ ▸ he ▸ rfl)⟩ convert ha.comp_embedding fe ext simp [fe, hf] theorem affineIndependent_equiv {ι' : Type*} (e : ι ≃ ι') {p : ι' → P} : AffineIndependent k (p ∘ e) ↔ AffineIndependent k p := by refine ⟨?_, AffineIndependent.comp_embedding e.toEmbedding⟩ intro h have : p = p ∘ e ∘ e.symm.toEmbedding := by ext simp rw [this] exact h.comp_embedding e.symm.toEmbedding /-- If a set of points is affinely independent, so is any subset. -/ protected theorem AffineIndependent.mono {s t : Set P} (ha : AffineIndependent k (fun x => x : t → P)) (hs : s ⊆ t) : AffineIndependent k (fun x => x : s → P) := ha.comp_embedding (s.embeddingOfSubset t hs) /-- If the range of an injective indexed family of points is affinely independent, so is that family. -/ theorem AffineIndependent.of_set_of_injective {p : ι → P} (ha : AffineIndependent k (fun x => x : Set.range p → P)) (hi : Function.Injective p) : AffineIndependent k p := ha.comp_embedding (⟨fun i => ⟨p i, Set.mem_range_self _⟩, fun _ _ h => hi (Subtype.mk_eq_mk.1 h)⟩ : ι ↪ Set.range p) section Composition variable {V₂ P₂ : Type*} [AddCommGroup V₂] [Module k V₂] [AffineSpace V₂ P₂] /-- If the image of a family of points in affine space under an affine transformation is affine- independent, then the original family of points is also affine-independent. -/ theorem AffineIndependent.of_comp {p : ι → P} (f : P →ᵃ[k] P₂) (hai : AffineIndependent k (f ∘ p)) : AffineIndependent k p := by rcases isEmpty_or_nonempty ι with h | h · haveI := h apply affineIndependent_of_subsingleton obtain ⟨i⟩ := h rw [affineIndependent_iff_linearIndependent_vsub k p i] simp_rw [affineIndependent_iff_linearIndependent_vsub k (f ∘ p) i, Function.comp_apply, ← f.linearMap_vsub] at hai exact LinearIndependent.of_comp f.linear hai /-- The image of a family of points in affine space, under an injective affine transformation, is affine-independent. -/ theorem AffineIndependent.map' {p : ι → P} (hai : AffineIndependent k p) (f : P →ᵃ[k] P₂) (hf : Function.Injective f) : AffineIndependent k (f ∘ p) := by rcases isEmpty_or_nonempty ι with h | h · haveI := h apply affineIndependent_of_subsingleton obtain ⟨i⟩ := h rw [affineIndependent_iff_linearIndependent_vsub k p i] at hai simp_rw [affineIndependent_iff_linearIndependent_vsub k (f ∘ p) i, Function.comp_apply, ← f.linearMap_vsub] have hf' : LinearMap.ker f.linear = ⊥ := by rwa [LinearMap.ker_eq_bot, f.linear_injective_iff] exact LinearIndependent.map' hai f.linear hf' /-- Injective affine maps preserve affine independence. -/ theorem AffineMap.affineIndependent_iff {p : ι → P} (f : P →ᵃ[k] P₂) (hf : Function.Injective f) : AffineIndependent k (f ∘ p) ↔ AffineIndependent k p := ⟨AffineIndependent.of_comp f, fun hai => AffineIndependent.map' hai f hf⟩ /-- Affine equivalences preserve affine independence of families of points. -/ theorem AffineEquiv.affineIndependent_iff {p : ι → P} (e : P ≃ᵃ[k] P₂) : AffineIndependent k (e ∘ p) ↔ AffineIndependent k p := e.toAffineMap.affineIndependent_iff e.toEquiv.injective /-- Affine equivalences preserve affine independence of subsets. -/ theorem AffineEquiv.affineIndependent_set_of_eq_iff {s : Set P} (e : P ≃ᵃ[k] P₂) : AffineIndependent k ((↑) : e '' s → P₂) ↔ AffineIndependent k ((↑) : s → P) := by have : e ∘ ((↑) : s → P) = ((↑) : e '' s → P₂) ∘ (e : P ≃ P₂).image s := rfl -- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644 erw [← e.affineIndependent_iff, this, affineIndependent_equiv] end Composition /-- If a family is affinely independent, and the spans of points indexed by two subsets of the index type have a point in common, those subsets of the index type have an element in common, if the underlying ring is nontrivial. -/ theorem AffineIndependent.exists_mem_inter_of_exists_mem_inter_affineSpan [Nontrivial k] {p : ι → P} (ha : AffineIndependent k p) {s1 s2 : Set ι} {p0 : P} (hp0s1 : p0 ∈ affineSpan k (p '' s1)) (hp0s2 : p0 ∈ affineSpan k (p '' s2)) : ∃ i : ι, i ∈ s1 ∩ s2 := by rw [Set.image_eq_range] at hp0s1 hp0s2 rw [mem_affineSpan_iff_eq_affineCombination, ← Finset.eq_affineCombination_subset_iff_eq_affineCombination_subtype] at hp0s1 hp0s2 rcases hp0s1 with ⟨fs1, hfs1, w1, hw1, hp0s1⟩ rcases hp0s2 with ⟨fs2, hfs2, w2, hw2, hp0s2⟩ rw [affineIndependent_iff_indicator_eq_of_affineCombination_eq] at ha replace ha := ha fs1 fs2 w1 w2 hw1 hw2 (hp0s1 ▸ hp0s2) have hnz : ∑ i ∈ fs1, w1 i ≠ 0 := hw1.symm ▸ one_ne_zero rcases Finset.exists_ne_zero_of_sum_ne_zero hnz with ⟨i, hifs1, hinz⟩ simp_rw [← Set.indicator_of_mem (Finset.mem_coe.2 hifs1) w1, ha] at hinz use i, hfs1 hifs1 exact hfs2 (Set.mem_of_indicator_ne_zero hinz) /-- If a family is affinely independent, the spans of points indexed by disjoint subsets of the index type are disjoint, if the underlying ring is nontrivial. -/ theorem AffineIndependent.affineSpan_disjoint_of_disjoint [Nontrivial k] {p : ι → P} (ha : AffineIndependent k p) {s1 s2 : Set ι} (hd : Disjoint s1 s2) : Disjoint (affineSpan k (p '' s1) : Set P) (affineSpan k (p '' s2)) := by refine Set.disjoint_left.2 fun p0 hp0s1 hp0s2 => ?_ obtain ⟨i, hi⟩ := ha.exists_mem_inter_of_exists_mem_inter_affineSpan hp0s1 hp0s2 exact Set.disjoint_iff.1 hd hi /-- If a family is affinely independent, a point in the family is in the span of some of the points given by a subset of the index type if and only if that point's index is in the subset, if the underlying ring is nontrivial. -/ @[simp] protected theorem AffineIndependent.mem_affineSpan_iff [Nontrivial k] {p : ι → P} (ha : AffineIndependent k p) (i : ι) (s : Set ι) : p i ∈ affineSpan k (p '' s) ↔ i ∈ s := by constructor · intro hs have h := AffineIndependent.exists_mem_inter_of_exists_mem_inter_affineSpan ha hs (mem_affineSpan k (Set.mem_image_of_mem _ (Set.mem_singleton _))) rwa [← Set.nonempty_def, Set.inter_singleton_nonempty] at h · exact fun h => mem_affineSpan k (Set.mem_image_of_mem p h) /-- If a family is affinely independent, a point in the family is not in the affine span of the other points, if the underlying ring is nontrivial. -/ theorem AffineIndependent.not_mem_affineSpan_diff [Nontrivial k] {p : ι → P} (ha : AffineIndependent k p) (i : ι) (s : Set ι) : p i ∉ affineSpan k (p '' (s \ {i})) := by simp [ha] theorem exists_nontrivial_relation_sum_zero_of_not_affine_ind {t : Finset V} (h : ¬AffineIndependent k ((↑) : t → V)) : ∃ f : V → k, ∑ e ∈ t, f e • e = 0 ∧ ∑ e ∈ t, f e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by classical rw [affineIndependent_iff_of_fintype] at h simp only [exists_prop, not_forall] at h obtain ⟨w, hw, hwt, i, hi⟩ := h simp only [Finset.weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero _ w ((↑) : t → V) hw 0, vsub_eq_sub, Finset.weightedVSubOfPoint_apply, sub_zero] at hwt let f : ∀ x : V, x ∈ t → k := fun x hx => w ⟨x, hx⟩ refine ⟨fun x => if hx : x ∈ t then f x hx else (0 : k), ?_, ?_, by use i; simp [f, hi]⟩ on_goal 1 => suffices (∑ e ∈ t, dite (e ∈ t) (fun hx => f e hx • e) fun _ => 0) = 0 by convert this rename V => x by_cases hx : x ∈ t <;> simp [hx] all_goals simp only [f, Finset.sum_dite_of_true fun _ h => h, Finset.mk_coe, hwt, hw] variable {s : Finset ι} {w w₁ w₂ : ι → k} {p : ι → V} /-- Viewing a module as an affine space modelled on itself, we can characterise affine independence in terms of linear combinations. -/ theorem affineIndependent_iff {ι} {p : ι → V} : AffineIndependent k p ↔ ∀ (s : Finset ι) (w : ι → k), s.sum w = 0 → ∑ e ∈ s, w e • p e = 0 → ∀ e ∈ s, w e = 0 := forall₃_congr fun s w hw => by simp [s.weightedVSub_eq_linear_combination hw] lemma AffineIndependent.eq_zero_of_sum_eq_zero (hp : AffineIndependent k p) (hw₀ : ∑ i ∈ s, w i = 0) (hw₁ : ∑ i ∈ s, w i • p i = 0) : ∀ i ∈ s, w i = 0 := affineIndependent_iff.1 hp _ _ hw₀ hw₁ lemma AffineIndependent.eq_of_sum_eq_sum (hp : AffineIndependent k p) (hw : ∑ i ∈ s, w₁ i = ∑ i ∈ s, w₂ i) (hwp : ∑ i ∈ s, w₁ i • p i = ∑ i ∈ s, w₂ i • p i) : ∀ i ∈ s, w₁ i = w₂ i := by refine fun i hi ↦ sub_eq_zero.1 (hp.eq_zero_of_sum_eq_zero (w := w₁ - w₂) ?_ ?_ _ hi) <;> simpa [sub_mul, sub_smul, sub_eq_zero] lemma AffineIndependent.eq_zero_of_sum_eq_zero_subtype {s : Finset V} (hp : AffineIndependent k ((↑) : s → V)) {w : V → k} (hw₀ : ∑ x ∈ s, w x = 0) (hw₁ : ∑ x ∈ s, w x • x = 0) : ∀ x ∈ s, w x = 0 := by rw [← sum_attach] at hw₀ hw₁ exact fun x hx ↦ hp.eq_zero_of_sum_eq_zero hw₀ hw₁ ⟨x, hx⟩ (mem_univ _) lemma AffineIndependent.eq_of_sum_eq_sum_subtype {s : Finset V} (hp : AffineIndependent k ((↑) : s → V)) {w₁ w₂ : V → k} (hw : ∑ i ∈ s, w₁ i = ∑ i ∈ s, w₂ i) (hwp : ∑ i ∈ s, w₁ i • i = ∑ i ∈ s, w₂ i • i) : ∀ i ∈ s, w₁ i = w₂ i := by refine fun i hi => sub_eq_zero.1 (hp.eq_zero_of_sum_eq_zero_subtype (w := w₁ - w₂) ?_ ?_ _ hi) <;> simpa [sub_mul, sub_smul, sub_eq_zero] /-- Given an affinely independent family of points, a weighted subtraction lies in the `vectorSpan` of two points given as affine combinations if and only if it is a weighted subtraction with weights a multiple of the difference between the weights of the two points. -/ theorem weightedVSub_mem_vectorSpan_pair {p : ι → P} (h : AffineIndependent k p) {w w₁ w₂ : ι → k} {s : Finset ι} (hw : ∑ i ∈ s, w i = 0) (hw₁ : ∑ i ∈ s, w₁ i = 1) (hw₂ : ∑ i ∈ s, w₂ i = 1) : s.weightedVSub p w ∈ vectorSpan k ({s.affineCombination k p w₁, s.affineCombination k p w₂} : Set P) ↔ ∃ r : k, ∀ i ∈ s, w i = r * (w₁ i - w₂ i) := by rw [mem_vectorSpan_pair] refine ⟨fun h => ?_, fun h => ?_⟩ · rcases h with ⟨r, hr⟩ refine ⟨r, fun i hi => ?_⟩ rw [s.affineCombination_vsub, ← s.weightedVSub_const_smul, ← sub_eq_zero, ← map_sub] at hr have hw' : (∑ j ∈ s, (r • (w₁ - w₂) - w) j) = 0 := by simp_rw [Pi.sub_apply, Pi.smul_apply, Pi.sub_apply, smul_sub, Finset.sum_sub_distrib, ← Finset.smul_sum, hw, hw₁, hw₂, sub_self] have hr' := h s _ hw' hr i hi rw [eq_comm, ← sub_eq_zero, ← smul_eq_mul] exact hr' · rcases h with ⟨r, hr⟩ refine ⟨r, ?_⟩ let w' i := r * (w₁ i - w₂ i) change ∀ i ∈ s, w i = w' i at hr rw [s.weightedVSub_congr hr fun _ _ => rfl, s.affineCombination_vsub, ← s.weightedVSub_const_smul] congr /-- Given an affinely independent family of points, an affine combination lies in the span of two points given as affine combinations if and only if it is an affine combination with weights those of one point plus a multiple of the difference between the weights of the two points. -/ theorem affineCombination_mem_affineSpan_pair {p : ι → P} (h : AffineIndependent k p) {w w₁ w₂ : ι → k} {s : Finset ι} (_ : ∑ i ∈ s, w i = 1) (hw₁ : ∑ i ∈ s, w₁ i = 1) (hw₂ : ∑ i ∈ s, w₂ i = 1) : s.affineCombination k p w ∈ line[k, s.affineCombination k p w₁, s.affineCombination k p w₂] ↔ ∃ r : k, ∀ i ∈ s, w i = r * (w₂ i - w₁ i) + w₁ i := by rw [← vsub_vadd (s.affineCombination k p w) (s.affineCombination k p w₁), AffineSubspace.vadd_mem_iff_mem_direction _ (left_mem_affineSpan_pair _ _ _), direction_affineSpan, s.affineCombination_vsub, Set.pair_comm, weightedVSub_mem_vectorSpan_pair h _ hw₂ hw₁] · simp only [Pi.sub_apply, sub_eq_iff_eq_add] · simp_all only [Pi.sub_apply, Finset.sum_sub_distrib, sub_self] end AffineIndependent section DivisionRing variable {k : Type*} {V : Type*} {P : Type*} [DivisionRing k] [AddCommGroup V] [Module k V] variable [AffineSpace V P] {ι : Type*} /-- An affinely independent set of points can be extended to such a set that spans the whole space. -/ theorem exists_subset_affineIndependent_affineSpan_eq_top {s : Set P} (h : AffineIndependent k (fun p => p : s → P)) : ∃ t : Set P, s ⊆ t ∧ AffineIndependent k (fun p => p : t → P) ∧ affineSpan k t = ⊤ := by rcases s.eq_empty_or_nonempty with (rfl | ⟨p₁, hp₁⟩) · have p₁ : P := AddTorsor.nonempty.some let hsv := Basis.ofVectorSpace k V have hsvi := hsv.linearIndependent have hsvt := hsv.span_eq rw [Basis.coe_ofVectorSpace] at hsvi hsvt have h0 : ∀ v : V, v ∈ Basis.ofVectorSpaceIndex k V → v ≠ 0 := by intro v hv simpa [hsv] using hsv.ne_zero ⟨v, hv⟩ rw [linearIndependent_set_iff_affineIndependent_vadd_union_singleton k h0 p₁] at hsvi exact ⟨{p₁} ∪ (fun v => v +ᵥ p₁) '' _, Set.empty_subset _, hsvi, affineSpan_singleton_union_vadd_eq_top_of_span_eq_top p₁ hsvt⟩ · rw [affineIndependent_set_iff_linearIndependent_vsub k hp₁] at h let bsv := Basis.extend h have hsvi := bsv.linearIndependent have hsvt := bsv.span_eq rw [Basis.coe_extend] at hsvi hsvt rw [linearIndependent_subtype_iff] at hsvi h have hsv := h.subset_extend (Set.subset_univ _) have h0 : ∀ v : V, v ∈ h.extend (Set.subset_univ _) → v ≠ 0 := by intro v hv simpa [bsv] using bsv.ne_zero ⟨v, hv⟩ rw [← linearIndependent_subtype_iff, linearIndependent_set_iff_affineIndependent_vadd_union_singleton k h0 p₁] at hsvi refine ⟨{p₁} ∪ (fun v => v +ᵥ p₁) '' h.extend (Set.subset_univ _), ?_, ?_⟩ · refine Set.Subset.trans ?_ (Set.union_subset_union_right _ (Set.image_subset _ hsv)) simp [Set.image_image] · use hsvi exact affineSpan_singleton_union_vadd_eq_top_of_span_eq_top p₁ hsvt variable (k V) theorem exists_affineIndependent (s : Set P) : ∃ t ⊆ s, affineSpan k t = affineSpan k s ∧ AffineIndependent k ((↑) : t → P) := by rcases s.eq_empty_or_nonempty with (rfl | ⟨p, hp⟩) · exact ⟨∅, Set.empty_subset ∅, rfl, affineIndependent_of_subsingleton k _⟩ obtain ⟨b, hb₁, hb₂, hb₃⟩ := exists_linearIndependent k ((Equiv.vaddConst p).symm '' s) have hb₀ : ∀ v : V, v ∈ b → v ≠ 0 := fun v hv => hb₃.ne_zero (⟨v, hv⟩ : b) rw [linearIndependent_set_iff_affineIndependent_vadd_union_singleton k hb₀ p] at hb₃ refine ⟨{p} ∪ Equiv.vaddConst p '' b, ?_, ?_, hb₃⟩ · apply Set.union_subset (Set.singleton_subset_iff.mpr hp) rwa [← (Equiv.vaddConst p).subset_symm_image b s] · rw [Equiv.coe_vaddConst_symm, ← vectorSpan_eq_span_vsub_set_right k hp] at hb₂ apply AffineSubspace.ext_of_direction_eq · have : Submodule.span k b = Submodule.span k (insert 0 b) := by simp simp only [direction_affineSpan, ← hb₂, Equiv.coe_vaddConst, Set.singleton_union, vectorSpan_eq_span_vsub_set_right k (Set.mem_insert p _), this] congr change (Equiv.vaddConst p).symm '' insert p (Equiv.vaddConst p '' b) = _ rw [Set.image_insert_eq, ← Set.image_comp] simp · use p simp only [Equiv.coe_vaddConst, Set.singleton_union, Set.mem_inter_iff] exact ⟨mem_affineSpan k (Set.mem_insert p _), mem_affineSpan k hp⟩ variable {V} /-- Two different points are affinely independent. -/ theorem affineIndependent_of_ne {p₁ p₂ : P} (h : p₁ ≠ p₂) : AffineIndependent k ![p₁, p₂] := by rw [affineIndependent_iff_linearIndependent_vsub k ![p₁, p₂] 0] let i₁ : { x // x ≠ (0 : Fin 2) } := ⟨1, by norm_num⟩ have he' : ∀ i, i = i₁ := by rintro ⟨i, hi⟩ ext fin_cases i · simp at hi · simp [i₁] haveI : Unique { x // x ≠ (0 : Fin 2) } := ⟨⟨i₁⟩, he'⟩ apply linearIndependent_unique rw [he' default] simpa using h.symm variable {k} /-- If all but one point of a family are affinely independent, and that point does not lie in the affine span of that family, the family is affinely independent. -/ theorem AffineIndependent.affineIndependent_of_not_mem_span {p : ι → P} {i : ι} (ha : AffineIndependent k fun x : { y // y ≠ i } => p x) (hi : p i ∉ affineSpan k (p '' { x | x ≠ i })) : AffineIndependent k p := by classical intro s w hw hs let s' : Finset { y // y ≠ i } := s.subtype (· ≠ i) let p' : { y // y ≠ i } → P := fun x => p x by_cases his : i ∈ s ∧ w i ≠ 0 · refine False.elim (hi ?_) let wm : ι → k := -(w i)⁻¹ • w have hms : s.weightedVSub p wm = (0 : V) := by simp [wm, hs] have hwm : ∑ i ∈ s, wm i = 0 := by simp [wm, ← Finset.mul_sum, hw] have hwmi : wm i = -1 := by simp [wm, his.2] let w' : { y // y ≠ i } → k := fun x => wm x have hw' : ∑ x ∈ s', w' x = 1 := by simp_rw [w', s', Finset.sum_subtype_eq_sum_filter] rw [← s.sum_filter_add_sum_filter_not (· ≠ i)] at hwm simpa only [not_not, Finset.filter_eq' _ i, if_pos his.1, sum_singleton, hwmi, add_neg_eq_zero] using hwm rw [← s.affineCombination_eq_of_weightedVSub_eq_zero_of_eq_neg_one hms his.1 hwmi, ←
(Subtype.range_coe : _ = { x | x ≠ i }), ← Set.range_comp, ← s.affineCombination_subtype_eq_filter] exact affineCombination_mem_affineSpan hw' p' · rw [not_and_or, Classical.not_not] at his let w' : { y // y ≠ i } → k := fun x => w x have hw' : ∑ x ∈ s', w' x = 0 := by simp_rw [w', s', Finset.sum_subtype_eq_sum_filter] rw [Finset.sum_filter_of_ne, hw] rintro x hxs hwx rfl exact hwx (his.neg_resolve_left hxs) have hs' : s'.weightedVSub p' w' = (0 : V) := by simp_rw [w', s', p', Finset.weightedVSub_subtype_eq_filter] rw [Finset.weightedVSub_filter_of_ne, hs] rintro x hxs hwx rfl exact hwx (his.neg_resolve_left hxs) intro j hj by_cases hji : j = i · rw [hji] at hj exact hji.symm ▸ his.neg_resolve_left hj · exact ha s' w' hw' hs' ⟨j, hji⟩ (Finset.mem_subtype.2 hj) /-- If distinct points `p₁` and `p₂` lie in `s` but `p₃` does not, the three points are affinely independent. -/ theorem affineIndependent_of_ne_of_mem_of_mem_of_not_mem {s : AffineSubspace k P} {p₁ p₂ p₃ : P} (hp₁p₂ : p₁ ≠ p₂) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (hp₃ : p₃ ∉ s) : AffineIndependent k ![p₁, p₂, p₃] := by have ha : AffineIndependent k fun x : { x : Fin 3 // x ≠ 2 } => ![p₁, p₂, p₃] x := by rw [← affineIndependent_equiv (finSuccAboveEquiv (2 : Fin 3))] convert affineIndependent_of_ne k hp₁p₂ ext x fin_cases x <;> rfl refine ha.affineIndependent_of_not_mem_span ?_ intro h refine hp₃ ((AffineSubspace.le_def' _ s).1 ?_ p₃ h) simp_rw [affineSpan_le, Set.image_subset_iff, Set.subset_def, Set.mem_preimage] intro x fin_cases x <;> simp +decide [hp₁, hp₂] /-- If distinct points `p₁` and `p₃` lie in `s` but `p₂` does not, the three points are affinely independent. -/ theorem affineIndependent_of_ne_of_mem_of_not_mem_of_mem {s : AffineSubspace k P} {p₁ p₂ p₃ : P} (hp₁p₃ : p₁ ≠ p₃) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∉ s) (hp₃ : p₃ ∈ s) : AffineIndependent k ![p₁, p₂, p₃] := by
Mathlib/LinearAlgebra/AffineSpace/Independent.lean
653
695
/- 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 -/ import Mathlib.Data.Fintype.Card import Mathlib.Algebra.Order.BigOperators.Group.Multiset import Mathlib.Algebra.Order.Group.Nat import Mathlib.Data.Multiset.OrderedMonoid import Mathlib.Tactic.Bound.Attribute import Mathlib.Algebra.BigOperators.Group.Finset.Sigma import Mathlib.Data.Multiset.Powerset /-! # Big operators on a finset in ordered groups This file contains the results concerning the interaction of multiset big operators with ordered groups/monoids. -/ assert_not_exists Ring open Function variable {ι α β M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [CommMonoid N] [PartialOrder N] [IsOrderedMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map submultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then `f (∏ x ∈ s, g x) ≤ ∏ x ∈ s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y)) (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) : f (∏ i ∈ s, g i) ≤ ∏ i ∈ s, f (g i) := by refine le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ ?_ ?_) ?_ · simp [hs_nonempty.ne_empty] · exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then `f (∑ i ∈ s, g i) ≤ ∑ i ∈ s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i ∈ s, g i) ≤ ∏ i ∈ s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y) {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i ∈ s, g i) ≤ ∏ i ∈ s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial /-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∑ i ∈ s, g i) ≤ ∑ i ∈ s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then `f (∏ i ∈ s, g i) ≤ ∏ i ∈ s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1) (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y)) (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i ∈ s, g i) ≤ ∏ i ∈ s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) · simp [h_one] · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map such that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then `f (∑ x ∈ s, g x) ≤ ∑ x ∈ s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i ∈ s, g i) ≤ ∏ i ∈ s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1) (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) : f (∏ i ∈ s, g i) ≤ ∏ i ∈ s, f (g i) := by refine le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) ?_ rw [Multiset.map_map] rfl /-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∑ i ∈ s, g i) ≤ ∑ i ∈ s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ι → N} {s t : Finset ι} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i ∈ s, f i ≤ ∏ i ∈ s, g i`. -/ @[to_additive (attr := gcongr) sum_le_sum] theorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i ∈ s, f i ≤ ∏ i ∈ s, g i := Multiset.prod_map_le_prod_map f g h attribute [bound] sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `∑ i ∈ s, f i ≤ ∑ i ∈ s, g i`. -/ add_decl_doc sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i ∈ s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i ∈ s, f i := Finset.one_le_prod' fun i _ ↦ h i @[to_additive sum_nonpos] theorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i ∈ s, f i ≤ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) @[to_additive (attr := gcongr) sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) : ∏ i ∈ s, f i ≤ ∏ i ∈ t, f i := by classical calc ∏ i ∈ s, f i ≤ (∏ i ∈ t \ s, f i) * ∏ i ∈ s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i ∈ t \ s ∪ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i ∈ t, f i := by rw [sdiff_union_of_subset h] @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x ∈ s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) : ∏ x ∈ s, f x ≤ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (∀ i ∈ s, 1 ≤ f i) → ((∏ i ∈ s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff_of_one_le (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] @[to_additive sum_eq_zero_iff_of_nonpos] theorem prod_eq_one_iff_of_le_one' : (∀ i ∈ s, f i ≤ 1) → ((∏ i ∈ s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := prod_eq_one_iff_of_one_le' (N := Nᵒᵈ) @[to_additive single_le_sum] theorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x ∈ s, f x := calc f a = ∏ i ∈ {a}, f i := (prod_singleton _ _).symm _ ≤ ∏ i ∈ s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi @[to_additive] lemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) : f i * f j ≤ ∏ k ∈ s, f k := calc f i * f j = ∏ k ∈ .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≤ ∏ k ∈ s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) : s.prod f ≤ n ^ #s := by refine (Multiset.prod_le_pow_card (s.val.map f) n ?_).trans ?_ · simpa using h · simp @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) : n ^ #s ≤ s.prod f := Finset.prod_le_pow_card (N := Nᵒᵈ) _ _ _ h theorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ) (h : ∀ a ∈ s, #(f a) ≤ n) : #(s.biUnion f) ≤ #s * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h variable {ι' : Type*} [DecidableEq ι'] @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N} (h : ∀ y ∉ t, (1 : N) ≤ ∏ x ∈ s with g x = y, f x) : (∏ y ∈ t, ∏ x ∈ s with g x = y, f x) ≤ ∏ x ∈ s, f x := calc (∏ y ∈ t, ∏ x ∈ s with g x = y, f x) ≤ ∏ y ∈ t ∪ s.image g, ∏ x ∈ s with g x = y, f x := prod_le_prod_of_subset_of_one_le' subset_union_left fun y _ ↦ h y _ = ∏ x ∈ s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N} (h : ∀ y ∉ t, ∏ x ∈ s with g x = y, f x ≤ 1) : ∏ x ∈ s, f x ≤ ∏ y ∈ t, ∏ x ∈ s with g x = y, f x := prod_fiberwise_le_prod_of_one_le_prod_fiber' (N := Nᵒᵈ) h @[to_additive] lemma prod_image_le_of_one_le {g : ι → ι'} {f : ι' → N} (hf : ∀ u ∈ s.image g, 1 ≤ f u) : ∏ u ∈ s.image g, f u ≤ ∏ u ∈ s, f (g u) := by rw [prod_comp f g] refine prod_le_prod' fun a hag ↦ ?_ obtain ⟨i, hi, hig⟩ := Finset.mem_image.mp hag apply le_self_pow (hf a hag) rw [← Nat.pos_iff_ne_zero, card_pos] exact ⟨i, mem_filter.mpr ⟨hi, hig⟩⟩ end OrderedCommMonoid @[to_additive] lemma max_prod_le [CommMonoid M] [LinearOrder M] [IsOrderedMonoid M] {f g : ι → M} {s : Finset ι} : max (s.prod f) (s.prod g) ≤ s.prod (fun i ↦ max (f i) (g i)) := Multiset.max_prod_le @[to_additive] lemma prod_min_le [CommMonoid M] [LinearOrder M] [IsOrderedMonoid M] {f g : ι → M} {s : Finset ι} : s.prod (fun i ↦ min (f i) (g i)) ≤ min (s.prod f) (s.prod g) := Multiset.prod_min_le theorem abs_sum_le_sum_abs {G : Type*} [AddCommGroup G] [LinearOrder G] [IsOrderedAddMonoid G] (f : ι → G) (s : Finset ι) : |∑ i ∈ s, f i| ≤ ∑ i ∈ s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f theorem abs_sum_of_nonneg {G : Type*} [AddCommGroup G] [LinearOrder G] [IsOrderedAddMonoid G] {f : ι → G} {s : Finset ι} (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i ∈ s, f i| = ∑ i ∈ s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] theorem abs_sum_of_nonneg' {G : Type*} [AddCommGroup G] [LinearOrder G] [IsOrderedAddMonoid G] {f : ι → G} {s : Finset ι} (hf : ∀ i, 0 ≤ f i) : |∑ i ∈ s, f i| = ∑ i ∈ s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] section CommMonoid variable [CommMonoid α] [LE α] [MulLeftMono α] {s : Finset ι} {f : ι → α} @[to_additive (attr := simp)] lemma mulLECancellable_prod : MulLECancellable (∏ i ∈ s, f i) ↔ ∀ ⦃i⦄, i ∈ s → MulLECancellable (f i) := by induction' s using Finset.cons_induction with i s hi ih <;> simp [*] end CommMonoid section Pigeonhole variable [DecidableEq β] theorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β} (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ b ∈ t, #{a ∈ s | f a = b} ≤ n) : #s ≤ n * #t := calc #s = ∑ b ∈ t, #{a ∈ s | f a = b} := card_eq_sum_card_fiberwise Hf _ ≤ ∑ _b ∈ t, n := sum_le_sum hn _ = _ := by simp [mul_comm] theorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ) (hn : ∀ b ∈ s.image f, #{a ∈ s | f a = b} ≤ n) : #s ≤ n * #(s.image f) := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn theorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β} (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ b ∈ t, n ≤ #{a ∈ s | f a = b}) : n * #t ≤ #s := calc n * #t = ∑ _a ∈ t, n := by simp [mul_comm] _ ≤ ∑ b ∈ t, #{a ∈ s | f a = b} := sum_le_sum hn _ = #s := by rw [← card_eq_sum_card_fiberwise Hf] theorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ) (hn : ∀ b ∈ s.image f, n ≤ #{a ∈ s | f a = b}) : n * #(s.image f) ≤ #s := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn end Pigeonhole section DoubleCounting variable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : ∀ a ∈ s, #{b ∈ B | a ∈ b} ≤ n) : (∑ t ∈ B, #(s ∩ t)) ≤ #s * n := by refine le_trans ?_ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ lemma sum_card_le [Fintype α] (h : ∀ a, #{b ∈ B | a ∈ b} ≤ n) : ∑ s ∈ B, #s ≤ Fintype.card α * n := calc ∑ s ∈ B, #s = ∑ s ∈ B, #(univ ∩ s) := by simp_rw [univ_inter] _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ #{b ∈ B | a ∈ b}) : #s * n ≤ ∑ t ∈ B, #(s ∩ t) := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype α] (h : ∀ a, n ≤ #{b ∈ B | a ∈ b}) : Fintype.card α * n ≤ ∑ s ∈ B, #s := calc Fintype.card α * n ≤ ∑ s ∈ B, #(univ ∩ s) := le_sum_card_inter fun a _ ↦ h a _ = ∑ s ∈ B, #s := by simp_rw [univ_inter] /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : ∀ a ∈ s, #{b ∈ B | a ∈ b} = n) : (∑ t ∈ B, #(s ∩ t)) = #s * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype α] (h : ∀ a, #{b ∈ B | a ∈ b} = n) : ∑ s ∈ B, #s = Fintype.card α * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] theorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f) (hf : ∀ i ∈ s, (f i).Nonempty) : #s ≤ #(s.biUnion f) := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos theorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f) : #s ≤ #(s.biUnion f) + #{i ∈ s | f i = ∅} := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_card <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ theorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f) (hs : (s : Set ι).PairwiseDisjoint f) : #s ≤ #(s.biUnion f) + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ end DoubleCounting section CanonicallyOrderedMul variable [CommMonoid M] [PartialOrder M] [IsOrderedMonoid M] [CanonicallyOrderedMul M] {f : ι → M} {s t : Finset ι} /-- In a canonically-ordered monoid, a product bounds each of its terms. See also `Finset.single_le_prod'`. -/ @[to_additive "In a canonically-ordered additive monoid, a sum bounds each of its terms. See also `Finset.single_le_sum`."] lemma _root_.CanonicallyOrderedCommMonoid.single_le_prod {i : ι} (hi : i ∈ s) : f i ≤ ∏ j ∈ s, f j := single_le_prod' (fun _ _ ↦ one_le _) hi @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x ∈ s, f x ≤ ∏ x ∈ t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ @[to_additive sum_mono_set] theorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x ∈ s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) : ∏ x ∈ s, f x ≤ ∏ x ∈ t, f x := by classical calc ∏ x ∈ s, f x = (∏ x ∈ s with f x = 1, f x) * ∏ x ∈ s with f x ≠ 1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≤ ∏ x ∈ t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) end CanonicallyOrderedMul section OrderedCancelCommMonoid variable [CommMonoid M] [PartialOrder M] [IsOrderedCancelMonoid M] {f g : ι → M} {s t : Finset ι} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) : ∏ i ∈ s, f i < ∏ i ∈ s, g i := Multiset.prod_lt_prod' hle hlt /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. -/ @[to_additive (attr := gcongr) sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) : ∏ i ∈ s, f i < ∏ i ∈ s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. -/ add_decl_doc sum_lt_sum_of_nonempty @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i) (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j ∈ s, f j < ∏ j ∈ t, f j := by classical calc ∏ j ∈ s, f j < ∏ j ∈ insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j ∈ s, f j) hlt _ ≤ ∏ j ∈ t, f j := by apply prod_le_prod_of_subset_of_one_le' · simp [Finset.insert_subset_iff, h, ht] · intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k ∈ s, f k := calc f i = ∏ k ∈ {i}, f k := by rw [prod_singleton] _ < ∏ k ∈ s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) @[to_additive sum_pos] theorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i ∈ s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h @[to_additive] theorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i ∈ s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) @[to_additive sum_pos'] theorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i ∈ s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs @[to_additive] theorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i ∈ s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) : ((∏ i ∈ s, f i) = ∏ i ∈ s, g i) ↔ ∀ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) variable [DecidableEq ι] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i ∈ s \ t, f i ≤ ∏ i ∈ t \ s, f i ↔ ∏ i ∈ s, f i ≤ ∏ i ∈ t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter] simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i ∈ s \ t, f i < ∏ i ∈ t \ s, f i ↔ ∏ i ∈ s, f i < ∏ i ∈ t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter] simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [CommMonoid M] [LinearOrder M] [IsOrderedCancelMonoid M] {f g : ι → M} {s t : Finset ι} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i ∈ s, f i < ∏ i ∈ s, g i) : ∃ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i ∈ s, f i ≤ ∏ i ∈ s, g i) : ∃ i ∈ s, f i ≤ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i ∈ s, f i = 1) (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂ apply ne_of_lt calc ∏ j ∈ s, f j < ∏ j ∈ s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one end LinearOrderedCancelCommMonoid end Finset namespace Fintype section OrderedCommMonoid variable [Fintype ι] [CommMonoid M] [PartialOrder M] [IsOrderedMonoid M] {f : ι → M} @[to_additive (attr := mono) sum_mono] theorem prod_mono' : Monotone fun f : ι → M ↦ ∏ i, f i := fun _ _ hfg ↦ Finset.prod_le_prod' fun x _ ↦ hfg x @[to_additive sum_nonneg] lemma one_le_prod (hf : 1 ≤ f) : 1 ≤ ∏ i, f i := Finset.one_le_prod' fun _ _ ↦ hf _ @[to_additive] lemma prod_le_one (hf : f ≤ 1) : ∏ i, f i ≤ 1 := Finset.prod_le_one' fun _ _ ↦ hf _ @[to_additive] lemma prod_eq_one_iff_of_one_le (hf : 1 ≤ f) : ∏ i, f i = 1 ↔ f = 1 := (Finset.prod_eq_one_iff_of_one_le' fun i _ ↦ hf i).trans <| by simp [funext_iff] @[to_additive] lemma prod_eq_one_iff_of_le_one (hf : f ≤ 1) : ∏ i, f i = 1 ↔ f = 1 := (Finset.prod_eq_one_iff_of_le_one' fun i _ ↦ hf i).trans <| by simp [funext_iff]
end OrderedCommMonoid section OrderedCancelCommMonoid variable [Fintype ι] [CommMonoid M] [PartialOrder M] [IsOrderedCancelMonoid M] {f : ι → M} @[to_additive sum_strictMono] theorem prod_strictMono' : StrictMono fun f : ι → M ↦ ∏ x, f x := fun _ _ hfg ↦ let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩
Mathlib/Algebra/Order/BigOperators/Group/Finset.lean
531
541
/- 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, ← sub_eq_add_neg, mul_neg] at this refine this.congr_fun fun n ↦ ?_ push_cast rw [Complex.cos, mul_div_cancel₀ _ two_ne_zero] congr 3 <;> ring /-! ## Asymptotics of the kernels as `t → ∞` -/ /-- The function `evenKernel a - L` has exponential decay at `+∞`, where `L = 1` if `a = 0` and `L = 0` otherwise. -/ lemma isBigO_atTop_evenKernel_sub (a : UnitAddCircle) : ∃ p : ℝ, 0 < p ∧ (evenKernel a · - (if a = 0 then 1 else 0)) =O[atTop] (rexp <| -p * ·) := by induction a using QuotientAddGroup.induction_on with | H b => obtain ⟨p, hp, hp'⟩ := HurwitzKernelBounds.isBigO_atTop_F_int_zero_sub b refine ⟨p, hp, (EventuallyEq.isBigO ?_).trans hp'⟩ filter_upwards [eventually_gt_atTop 0] with t h simp [← (hasSum_int_evenKernel b h).tsum_eq, HurwitzKernelBounds.F_int, HurwitzKernelBounds.f_int] /-- The function `cosKernel a - 1` has exponential decay at `+∞`, for any `a`. -/ lemma isBigO_atTop_cosKernel_sub (a : UnitAddCircle) : ∃ p, 0 < p ∧ IsBigO atTop (cosKernel a · - 1) (fun x ↦ Real.exp (-p * x)) := by induction a using QuotientAddGroup.induction_on with | H a => obtain ⟨p, hp, hp'⟩ := HurwitzKernelBounds.isBigO_atTop_F_nat_zero_sub zero_le_one refine ⟨p, hp, (Eventually.isBigO ?_).trans (hp'.const_mul_left 2)⟩ filter_upwards [eventually_gt_atTop 0] with t ht simp only [eq_false_intro one_ne_zero, if_false, sub_zero, ← (hasSum_nat_cosKernel₀ a ht).tsum_eq, HurwitzKernelBounds.F_nat] apply tsum_of_norm_bounded ((HurwitzKernelBounds.summable_f_nat 0 1 ht).hasSum.mul_left 2) intro n rw [norm_mul, norm_mul, norm_two, mul_assoc, mul_le_mul_iff_of_pos_left two_pos, norm_of_nonneg (exp_pos _).le, HurwitzKernelBounds.f_nat, pow_zero, one_mul, Real.norm_eq_abs] exact mul_le_of_le_one_left (exp_pos _).le (abs_cos_le_one _) end asymp section FEPair /-! ## Construction of a FE-pair -/ /-- A `WeakFEPair` structure with `f = evenKernel a` and `g = cosKernel a`. -/ def hurwitzEvenFEPair (a : UnitAddCircle) : WeakFEPair ℂ where f := ofReal ∘ evenKernel a g := ofReal ∘ cosKernel a hf_int := (continuous_ofReal.comp_continuousOn (continuousOn_evenKernel a)).locallyIntegrableOn measurableSet_Ioi hg_int := (continuous_ofReal.comp_continuousOn (continuousOn_cosKernel a)).locallyIntegrableOn measurableSet_Ioi k := 1 / 2 hk := one_half_pos ε := 1 hε := one_ne_zero f₀ := if a = 0 then 1 else 0 hf_top r := by let ⟨v, hv, hv'⟩ := isBigO_atTop_evenKernel_sub a rw [← isBigO_norm_left] at hv' ⊢ conv at hv' => enter [2, x]; rw [← norm_real, ofReal_sub, apply_ite ((↑) : ℝ → ℂ), ofReal_one, ofReal_zero] exact hv'.trans (isLittleO_exp_neg_mul_rpow_atTop hv _).isBigO g₀ := 1 hg_top r := by obtain ⟨p, hp, hp'⟩ := isBigO_atTop_cosKernel_sub a simpa using isBigO_ofReal_left.mpr <| hp'.trans (isLittleO_exp_neg_mul_rpow_atTop hp r).isBigO h_feq x hx := by simp [← ofReal_mul, evenKernel_functional_equation, inv_rpow (le_of_lt hx)] @[simp] lemma hurwitzEvenFEPair_zero_symm : (hurwitzEvenFEPair 0).symm = hurwitzEvenFEPair 0 := by unfold hurwitzEvenFEPair WeakFEPair.symm congr 1 <;> simp [evenKernel_eq_cosKernel_of_zero] @[simp] lemma hurwitzEvenFEPair_neg (a : UnitAddCircle) : hurwitzEvenFEPair (-a) = hurwitzEvenFEPair a := by unfold hurwitzEvenFEPair congr 1 <;> simp [Function.comp_def] /-! ## Definition of the completed even Hurwitz zeta function -/ /-- The meromorphic function of `s` which agrees with `1 / 2 * Gamma (s / 2) * π ^ (-s / 2) * ∑' (n : ℤ), 1 / |n + a| ^ s` for `1 < re s`. -/ def completedHurwitzZetaEven (a : UnitAddCircle) (s : ℂ) : ℂ := ((hurwitzEvenFEPair a).Λ (s / 2)) / 2 /-- The entire function differing from `completedHurwitzZetaEven a s` by a linear combination of `1 / s` and `1 / (1 - s)`. -/ def completedHurwitzZetaEven₀ (a : UnitAddCircle) (s : ℂ) : ℂ := ((hurwitzEvenFEPair a).Λ₀ (s / 2)) / 2 lemma completedHurwitzZetaEven_eq (a : UnitAddCircle) (s : ℂ) : completedHurwitzZetaEven a s = completedHurwitzZetaEven₀ a s - (if a = 0 then 1 else 0) / s - 1 / (1 - s) := by rw [completedHurwitzZetaEven, WeakFEPair.Λ, sub_div, sub_div] congr 1 · change completedHurwitzZetaEven₀ a s - (1 / (s / 2)) • (if a = 0 then 1 else 0) / 2 = completedHurwitzZetaEven₀ a s - (if a = 0 then 1 else 0) / s rw [smul_eq_mul, mul_comm, mul_div_assoc, div_div, div_mul_cancel₀ _ two_ne_zero, mul_one_div] · change (1 / (↑(1 / 2 : ℝ) - s / 2)) • 1 / 2 = 1 / (1 - s) push_cast rw [smul_eq_mul, mul_one, ← sub_div, div_div, div_mul_cancel₀ _ two_ne_zero] /-- The meromorphic function of `s` which agrees with `Gamma (s / 2) * π ^ (-s / 2) * ∑' n : ℕ, cos (2 * π * a * n) / n ^ s` for `1 < re s`. -/ def completedCosZeta (a : UnitAddCircle) (s : ℂ) : ℂ := ((hurwitzEvenFEPair a).symm.Λ (s / 2)) / 2 /-- The entire function differing from `completedCosZeta a s` by a linear combination of `1 / s` and `1 / (1 - s)`. -/ def completedCosZeta₀ (a : UnitAddCircle) (s : ℂ) : ℂ := ((hurwitzEvenFEPair a).symm.Λ₀ (s / 2)) / 2 lemma completedCosZeta_eq (a : UnitAddCircle) (s : ℂ) : completedCosZeta a s = completedCosZeta₀ a s - 1 / s - (if a = 0 then 1 else 0) / (1 - s) := by rw [completedCosZeta, WeakFEPair.Λ, sub_div, sub_div] congr 1 · rw [completedCosZeta₀, WeakFEPair.symm, hurwitzEvenFEPair, smul_eq_mul, mul_one, div_div, div_mul_cancel₀ _ (two_ne_zero' ℂ)] · simp_rw [WeakFEPair.symm, hurwitzEvenFEPair, push_cast, inv_one, smul_eq_mul, mul_comm _ (if _ then _ else _), mul_div_assoc, div_div, ← sub_div, div_mul_cancel₀ _ (two_ne_zero' ℂ), mul_one_div] /-! ## Parity and functional equations -/ @[simp] lemma completedHurwitzZetaEven_neg (a : UnitAddCircle) (s : ℂ) : completedHurwitzZetaEven (-a) s = completedHurwitzZetaEven a s := by simp [completedHurwitzZetaEven] @[simp] lemma completedHurwitzZetaEven₀_neg (a : UnitAddCircle) (s : ℂ) : completedHurwitzZetaEven₀ (-a) s = completedHurwitzZetaEven₀ a s := by simp [completedHurwitzZetaEven₀] @[simp] lemma completedCosZeta_neg (a : UnitAddCircle) (s : ℂ) : completedCosZeta (-a) s = completedCosZeta a s := by simp [completedCosZeta] @[simp] lemma completedCosZeta₀_neg (a : UnitAddCircle) (s : ℂ) : completedCosZeta₀ (-a) s = completedCosZeta₀ a s := by simp [completedCosZeta₀] /-- Functional equation for the even Hurwitz zeta function. -/ lemma completedHurwitzZetaEven_one_sub (a : UnitAddCircle) (s : ℂ) : completedHurwitzZetaEven a (1 - s) = completedCosZeta a s := by rw [completedHurwitzZetaEven, completedCosZeta, sub_div, (by norm_num : (1 / 2 : ℂ) = ↑(1 / 2 : ℝ)), (by rfl : (1 / 2 : ℝ) = (hurwitzEvenFEPair a).k), (hurwitzEvenFEPair a).functional_equation (s / 2), (by rfl : (hurwitzEvenFEPair a).ε = 1), one_smul] /-- Functional equation for the even Hurwitz zeta function with poles removed. -/ lemma completedHurwitzZetaEven₀_one_sub (a : UnitAddCircle) (s : ℂ) : completedHurwitzZetaEven₀ a (1 - s) = completedCosZeta₀ a s := by rw [completedHurwitzZetaEven₀, completedCosZeta₀, sub_div, (by norm_num : (1 / 2 : ℂ) = ↑(1 / 2 : ℝ)), (by rfl : (1 / 2 : ℝ) = (hurwitzEvenFEPair a).k), (hurwitzEvenFEPair a).functional_equation₀ (s / 2), (by rfl : (hurwitzEvenFEPair a).ε = 1), one_smul] /-- Functional equation for the even Hurwitz zeta function (alternative form). -/ lemma completedCosZeta_one_sub (a : UnitAddCircle) (s : ℂ) : completedCosZeta a (1 - s) = completedHurwitzZetaEven a s := by rw [← completedHurwitzZetaEven_one_sub, sub_sub_cancel] /-- Functional equation for the even Hurwitz zeta function with poles removed (alternative form). -/ lemma completedCosZeta₀_one_sub (a : UnitAddCircle) (s : ℂ) : completedCosZeta₀ a (1 - s) = completedHurwitzZetaEven₀ a s := by rw [← completedHurwitzZetaEven₀_one_sub, sub_sub_cancel] end FEPair /-! ## Differentiability and residues -/ section FEPair /-- The even Hurwitz completed zeta is differentiable away from `s = 0` and `s = 1` (and also at `s = 0` if `a ≠ 0`) -/ lemma differentiableAt_completedHurwitzZetaEven (a : UnitAddCircle) {s : ℂ} (hs : s ≠ 0 ∨ a ≠ 0) (hs' : s ≠ 1) : DifferentiableAt ℂ (completedHurwitzZetaEven a) s := by refine (((hurwitzEvenFEPair a).differentiableAt_Λ ?_ (Or.inl ?_)).comp s (differentiableAt_id.div_const _)).div_const _ · rcases hs with h | h <;> simp [hurwitzEvenFEPair, h] · change s / 2 ≠ ↑(1 / 2 : ℝ) rw [ofReal_div, ofReal_one, ofReal_ofNat] exact hs' ∘ (div_left_inj' two_ne_zero).mp lemma differentiable_completedHurwitzZetaEven₀ (a : UnitAddCircle) : Differentiable ℂ (completedHurwitzZetaEven₀ a) := ((hurwitzEvenFEPair a).differentiable_Λ₀.comp (differentiable_id.div_const _)).div_const _ /-- The difference of two completed even Hurwitz zeta functions is differentiable at `s = 1`. -/ lemma differentiableAt_one_completedHurwitzZetaEven_sub_completedHurwitzZetaEven (a b : UnitAddCircle) : DifferentiableAt ℂ (fun s ↦ completedHurwitzZetaEven a s - completedHurwitzZetaEven b s) 1 := by have (s) : completedHurwitzZetaEven a s - completedHurwitzZetaEven b s = completedHurwitzZetaEven₀ a s - completedHurwitzZetaEven₀ b s - ((if a = 0 then 1 else 0) - (if b = 0 then 1 else 0)) / s := by simp_rw [completedHurwitzZetaEven_eq, sub_div] abel rw [funext this] refine .sub ?_ <| (differentiable_const _ _).div (differentiable_id _) one_ne_zero apply DifferentiableAt.sub <;> apply differentiable_completedHurwitzZetaEven₀ lemma differentiableAt_completedCosZeta (a : UnitAddCircle) {s : ℂ} (hs : s ≠ 0) (hs' : s ≠ 1 ∨ a ≠ 0) : DifferentiableAt ℂ (completedCosZeta a) s := by refine (((hurwitzEvenFEPair a).symm.differentiableAt_Λ (Or.inl ?_) ?_).comp s (differentiableAt_id.div_const _)).div_const _ · exact div_ne_zero_iff.mpr ⟨hs, two_ne_zero⟩ · change s / 2 ≠ ↑(1 / 2 : ℝ) ∨ (if a = 0 then 1 else 0) = 0 refine Or.imp (fun h ↦ ?_) (fun ha ↦ ?_) hs' · simpa [push_cast] using h ∘ (div_left_inj' two_ne_zero).mp · simpa lemma differentiable_completedCosZeta₀ (a : UnitAddCircle) : Differentiable ℂ (completedCosZeta₀ a) := ((hurwitzEvenFEPair a).symm.differentiable_Λ₀.comp (differentiable_id.div_const _)).div_const _ private lemma tendsto_div_two_punctured_nhds (a : ℂ) : Tendsto (fun s : ℂ ↦ s / 2) (𝓝[≠] a) (𝓝[≠] (a / 2)) := le_of_eq ((Homeomorph.mulRight₀ _ (inv_ne_zero (two_ne_zero' ℂ))).map_punctured_nhds_eq a) /-- The residue of `completedHurwitzZetaEven a s` at `s = 1` is equal to `1`. -/ lemma completedHurwitzZetaEven_residue_one (a : UnitAddCircle) : Tendsto (fun s ↦ (s - 1) * completedHurwitzZetaEven a s) (𝓝[≠] 1) (𝓝 1) := by have h1 : Tendsto (fun s : ℂ ↦ (s - ↑(1 / 2 : ℝ)) * _) (𝓝[≠] ↑(1 / 2 : ℝ)) (𝓝 ((1 : ℂ) * (1 : ℂ))) := (hurwitzEvenFEPair a).Λ_residue_k simp only [push_cast, one_mul] at h1 refine (h1.comp <| tendsto_div_two_punctured_nhds 1).congr (fun s ↦ ?_) rw [completedHurwitzZetaEven, Function.comp_apply, ← sub_div, div_mul_eq_mul_div, mul_div_assoc] /-- The residue of `completedHurwitzZetaEven a s` at `s = 0` is equal to `-1` if `a = 0`, and `0` otherwise. -/ lemma completedHurwitzZetaEven_residue_zero (a : UnitAddCircle) : Tendsto (fun s ↦ s * completedHurwitzZetaEven a s) (𝓝[≠] 0) (𝓝 (if a = 0 then -1 else 0)) := by have h1 : Tendsto (fun s : ℂ ↦ s * _) (𝓝[≠] 0) (𝓝 (-(if a = 0 then 1 else 0))) := (hurwitzEvenFEPair a).Λ_residue_zero have : -(if a = 0 then (1 : ℂ) else 0) = (if a = 0 then -1 else 0) := by { split_ifs <;> simp } simp only [this, push_cast, one_mul] at h1 refine (h1.comp <| zero_div (2 : ℂ) ▸ (tendsto_div_two_punctured_nhds 0)).congr (fun s ↦ ?_) simp [completedHurwitzZetaEven, div_mul_eq_mul_div, mul_div_assoc] lemma completedCosZeta_residue_zero (a : UnitAddCircle) : Tendsto (fun s ↦ s * completedCosZeta a s) (𝓝[≠] 0) (𝓝 (-1)) := by have h1 : Tendsto (fun s : ℂ ↦ s * _) (𝓝[≠] 0) (𝓝 (-1)) := (hurwitzEvenFEPair a).symm.Λ_residue_zero refine (h1.comp <| zero_div (2 : ℂ) ▸ (tendsto_div_two_punctured_nhds 0)).congr (fun s ↦ ?_) simp [completedCosZeta, div_mul_eq_mul_div, mul_div_assoc] end FEPair /-! ## Relation to the Dirichlet series for `1 < re s` -/ /-- Formula for `completedCosZeta` as a Dirichlet series in the convergence range (first version, with sum over `ℤ`). -/ lemma hasSum_int_completedCosZeta (a : ℝ) {s : ℂ} (hs : 1 < re s) : HasSum (fun n : ℤ ↦ Gammaℝ s * cexp (2 * π * I * a * n) / (↑|n| : ℂ) ^ s / 2) (completedCosZeta a s) := by let c (n : ℤ) : ℂ := cexp (2 * π * I * a * n) / 2 have hF t (ht : 0 < t) : HasSum (fun n : ℤ ↦ if n = 0 then 0 else c n * rexp (-π * n ^ 2 * t)) ((cosKernel a t - 1) / 2) := by refine ((hasSum_int_cosKernel₀ a ht).div_const 2).congr_fun fun n ↦ ?_ split_ifs <;> simp [c, div_mul_eq_mul_div] simp only [← Int.cast_eq_zero (α := ℝ)] at hF rw [show completedCosZeta a s = mellin (fun t ↦ (cosKernel a t - 1 : ℂ) / 2) (s / 2) by rw [mellin_div_const, completedCosZeta] congr 1 refine ((hurwitzEvenFEPair a).symm.hasMellin (?_ : 1 / 2 < (s / 2).re)).2.symm rwa [div_ofNat_re, div_lt_div_iff_of_pos_right two_pos]] refine (hasSum_mellin_pi_mul_sq (zero_lt_one.trans hs) hF ?_).congr_fun fun n ↦ ?_ · apply (((summable_one_div_int_add_rpow 0 s.re).mpr hs).div_const 2).of_norm_bounded intro i simp only [c, (by { push_cast; ring } : 2 * π * I * a * i = ↑(2 * π * a * i) * I), norm_div, RCLike.norm_ofNat, norm_norm, Complex.norm_exp_ofReal_mul_I, add_zero, norm_one, norm_of_nonneg (by positivity : 0 ≤ |(i : ℝ)| ^ s.re), div_right_comm, le_rfl] · simp [c, ← Int.cast_abs, div_right_comm, mul_div_assoc] /-- Formula for `completedCosZeta` as a Dirichlet series in the convergence range (second version, with sum over `ℕ`). -/ lemma hasSum_nat_completedCosZeta (a : ℝ) {s : ℂ} (hs : 1 < re s) : HasSum (fun n : ℕ ↦ if n = 0 then 0 else Gammaℝ s * Real.cos (2 * π * a * n) / (n : ℂ) ^ s) (completedCosZeta a s) := by have aux : ((|0| : ℤ) : ℂ) ^ s = 0 := by rw [abs_zero, Int.cast_zero, zero_cpow (ne_zero_of_one_lt_re hs)] have hint := (hasSum_int_completedCosZeta a hs).nat_add_neg rw [aux, div_zero, zero_div, add_zero] at hint refine hint.congr_fun fun n ↦ ?_ split_ifs with h · simp only [h, Nat.cast_zero, aux, div_zero, zero_div, neg_zero, zero_add] · simp only [ofReal_cos, ofReal_mul, ofReal_ofNat, ofReal_natCast, Complex.cos, show 2 * π * a * n * I = 2 * π * I * a * n by ring, neg_mul, mul_div_assoc, div_right_comm _ (2 : ℂ), Int.cast_natCast, Nat.abs_cast, Int.cast_neg, mul_neg, abs_neg, ← mul_add, ← add_div] /-- Formula for `completedHurwitzZetaEven` as a Dirichlet series in the convergence range. -/ lemma hasSum_int_completedHurwitzZetaEven (a : ℝ) {s : ℂ} (hs : 1 < re s) : HasSum (fun n : ℤ ↦ Gammaℝ s / (↑|n + a| : ℂ) ^ s / 2) (completedHurwitzZetaEven a s) := by have hF (t : ℝ) (ht : 0 < t) : HasSum (fun n : ℤ ↦ if n + a = 0 then 0 else (1 / 2 : ℂ) * rexp (-π * (n + a) ^ 2 * t)) ((evenKernel a t - (if (a : UnitAddCircle) = 0 then 1 else 0 : ℝ)) / 2) := by refine (ofReal_sub .. ▸ (hasSum_ofReal.mpr (hasSum_int_evenKernel₀ a ht)).div_const 2).congr_fun fun n ↦ ?_ split_ifs · rw [ofReal_zero, zero_div] · rw [mul_comm, mul_one_div] rw [show completedHurwitzZetaEven a s = mellin (fun t ↦ ((evenKernel (↑a) t : ℂ) - ↑(if (a : UnitAddCircle) = 0 then 1 else 0 : ℝ)) / 2) (s / 2) by simp_rw [mellin_div_const, apply_ite ofReal, ofReal_one, ofReal_zero] refine congr_arg (· / 2) ((hurwitzEvenFEPair a).hasMellin (?_ : 1 / 2 < (s / 2).re)).2.symm rwa [div_ofNat_re, div_lt_div_iff_of_pos_right two_pos]] refine (hasSum_mellin_pi_mul_sq (zero_lt_one.trans hs) hF ?_).congr_fun fun n ↦ ?_ · simp_rw [← mul_one_div ‖_‖] apply Summable.mul_left rwa [summable_one_div_int_add_rpow] · rw [mul_one_div, div_right_comm] /-! ## The un-completed even Hurwitz zeta -/ /-- Technical lemma which will give us differentiability of Hurwitz zeta at `s = 0`. -/ lemma differentiableAt_update_of_residue {Λ : ℂ → ℂ} (hf : ∀ (s : ℂ) (_ : s ≠ 0) (_ : s ≠ 1), DifferentiableAt ℂ Λ s) {L : ℂ} (h_lim : Tendsto (fun s ↦ s * Λ s) (𝓝[≠] 0) (𝓝 L)) (s : ℂ) (hs' : s ≠ 1) : DifferentiableAt ℂ (Function.update (fun s ↦ Λ s / Gammaℝ s) 0 (L / 2)) s := by have claim (t) (ht : t ≠ 0) (ht' : t ≠ 1) : DifferentiableAt ℂ (fun u : ℂ ↦ Λ u / Gammaℝ u) t := (hf t ht ht').mul differentiable_Gammaℝ_inv.differentiableAt have claim2 : Tendsto (fun s : ℂ ↦ Λ s / Gammaℝ s) (𝓝[≠] 0) (𝓝 <| L / 2) := by refine Tendsto.congr' ?_ (h_lim.div Gammaℝ_residue_zero two_ne_zero) filter_upwards [self_mem_nhdsWithin] with s (hs : s ≠ 0) rw [Pi.div_apply, ← div_div, mul_div_cancel_left₀ _ hs] rcases ne_or_eq s 0 with hs | rfl · -- Easy case : `s ≠ 0` refine (claim s hs hs').congr_of_eventuallyEq ?_ filter_upwards [isOpen_compl_singleton.mem_nhds hs] with x hx simp [Function.update_of_ne hx] · -- Hard case : `s = 0` simp_rw [← claim2.limUnder_eq] have S_nhds : {(1 : ℂ)}ᶜ ∈ 𝓝 (0 : ℂ) := isOpen_compl_singleton.mem_nhds hs' refine ((Complex.differentiableOn_update_limUnder_of_isLittleO S_nhds (fun t ht ↦ (claim t ht.2 ht.1).differentiableWithinAt) ?_) 0 hs').differentiableAt S_nhds simp only [Gammaℝ, zero_div, div_zero, Complex.Gamma_zero, mul_zero, cpow_zero, sub_zero] -- Remains to show completed zeta is `o (s ^ (-1))` near 0. refine (isBigO_const_of_tendsto claim2 <| one_ne_zero' ℂ).trans_isLittleO ?_ rw [isLittleO_iff_tendsto'] · exact Tendsto.congr (fun x ↦ by rw [← one_div, one_div_one_div]) nhdsWithin_le_nhds · exact eventually_of_mem self_mem_nhdsWithin fun x hx hx' ↦ (hx <| inv_eq_zero.mp hx').elim /-- The even part of the Hurwitz zeta function, i.e. the meromorphic function of `s` which agrees with `1 / 2 * ∑' (n : ℤ), 1 / |n + a| ^ s` for `1 < re s` -/ noncomputable def hurwitzZetaEven (a : UnitAddCircle) := Function.update (fun s ↦ completedHurwitzZetaEven a s / Gammaℝ s) 0 (if a = 0 then -1 / 2 else 0) lemma hurwitzZetaEven_def_of_ne_or_ne {a : UnitAddCircle} {s : ℂ} (h : a ≠ 0 ∨ s ≠ 0) : hurwitzZetaEven a s = completedHurwitzZetaEven a s / Gammaℝ s := by rw [hurwitzZetaEven] rcases ne_or_eq s 0 with h' | rfl · rw [Function.update_of_ne h'] · simpa [Gammaℝ] using h lemma hurwitzZetaEven_apply_zero (a : UnitAddCircle) : hurwitzZetaEven a 0 = if a = 0 then -1 / 2 else 0 := Function.update_self .. lemma hurwitzZetaEven_neg (a : UnitAddCircle) (s : ℂ) : hurwitzZetaEven (-a) s = hurwitzZetaEven a s := by simp [hurwitzZetaEven] /-- The trivial zeroes of the even Hurwitz zeta function. -/ theorem hurwitzZetaEven_neg_two_mul_nat_add_one (a : UnitAddCircle) (n : ℕ) : hurwitzZetaEven a (-2 * (n + 1)) = 0 := by have : (-2 : ℂ) * (n + 1) ≠ 0 := mul_ne_zero (neg_ne_zero.mpr two_ne_zero) (Nat.cast_add_one_ne_zero n) rw [hurwitzZetaEven, Function.update_of_ne this, Gammaℝ_eq_zero_iff.mpr ⟨n + 1, by simp⟩, div_zero] /-- The Hurwitz zeta function is differentiable everywhere except at `s = 1`. This is true even in the delicate case `a = 0` and `s = 0` (where the completed zeta has a pole, but this is cancelled out by the Gamma factor). -/ lemma differentiableAt_hurwitzZetaEven (a : UnitAddCircle) {s : ℂ} (hs' : s ≠ 1) : DifferentiableAt ℂ (hurwitzZetaEven a) s := by have := differentiableAt_update_of_residue (fun t ht ht' ↦ differentiableAt_completedHurwitzZetaEven a (Or.inl ht) ht') (completedHurwitzZetaEven_residue_zero a) s hs' simp_rw [div_eq_mul_inv, ite_mul, zero_mul, ← div_eq_mul_inv] at this exact this lemma hurwitzZetaEven_residue_one (a : UnitAddCircle) : Tendsto (fun s ↦ (s - 1) * hurwitzZetaEven a s) (𝓝[≠] 1) (𝓝 1) := by have : Tendsto (fun s ↦ (s - 1) * completedHurwitzZetaEven a s / Gammaℝ s) (𝓝[≠] 1) (𝓝 1) := by simpa only [Gammaℝ_one, inv_one, mul_one] using (completedHurwitzZetaEven_residue_one a).mul <| (differentiable_Gammaℝ_inv.continuous.tendsto _).mono_left nhdsWithin_le_nhds refine this.congr' ?_ filter_upwards [eventually_ne_nhdsWithin one_ne_zero] with s hs simp [hurwitzZetaEven_def_of_ne_or_ne (Or.inr hs), mul_div_assoc] lemma differentiableAt_hurwitzZetaEven_sub_one_div (a : UnitAddCircle) : DifferentiableAt ℂ (fun s ↦ hurwitzZetaEven a s - 1 / (s - 1) / Gammaℝ s) 1 := by suffices DifferentiableAt ℂ (fun s ↦ completedHurwitzZetaEven a s / Gammaℝ s - 1 / (s - 1) / Gammaℝ s) 1 by apply this.congr_of_eventuallyEq filter_upwards [eventually_ne_nhds one_ne_zero] with x hx rw [hurwitzZetaEven, Function.update_of_ne hx] simp_rw [← sub_div, div_eq_mul_inv _ (Gammaℝ _)] refine DifferentiableAt.mul ?_ differentiable_Gammaℝ_inv.differentiableAt simp_rw [completedHurwitzZetaEven_eq, sub_sub, add_assoc] conv => enter [2, s, 2]; rw [← neg_sub, div_neg, neg_add_cancel, add_zero] exact (differentiable_completedHurwitzZetaEven₀ a _).sub <| (differentiableAt_const _).div differentiableAt_id one_ne_zero /-- Expression for `hurwitzZetaEven a 1` as a limit. (Mathematically `hurwitzZetaEven a 1` is undefined, but our construction assigns some value to it; this lemma is mostly of interest for determining what that value is). -/ lemma tendsto_hurwitzZetaEven_sub_one_div_nhds_one (a : UnitAddCircle) : Tendsto (fun s ↦ hurwitzZetaEven a s - 1 / (s - 1) / Gammaℝ s) (𝓝 1) (𝓝 (hurwitzZetaEven a 1)) := by simpa using (differentiableAt_hurwitzZetaEven_sub_one_div a).continuousAt.tendsto lemma differentiable_hurwitzZetaEven_sub_hurwitzZetaEven (a b : UnitAddCircle) :
Differentiable ℂ (fun s ↦ hurwitzZetaEven a s - hurwitzZetaEven b s) := by intro z rcases ne_or_eq z 1 with hz | rfl · exact (differentiableAt_hurwitzZetaEven a hz).sub (differentiableAt_hurwitzZetaEven b hz) · convert (differentiableAt_hurwitzZetaEven_sub_one_div a).sub (differentiableAt_hurwitzZetaEven_sub_one_div b) using 2 with s abel /-- Formula for `hurwitzZetaEven` as a Dirichlet series in the convergence range, with sum over `ℤ`. -/ lemma hasSum_int_hurwitzZetaEven (a : ℝ) {s : ℂ} (hs : 1 < re s) : HasSum (fun n : ℤ ↦ 1 / (↑|n + a| : ℂ) ^ s / 2) (hurwitzZetaEven a s) := by
Mathlib/NumberTheory/LSeries/HurwitzZetaEven.lean
650
662
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Yaël Dillies -/ import Mathlib.Order.Cover import Mathlib.Order.Interval.Finset.Defs /-! # Intervals as finsets This file provides basic results about all the `Finset.Ixx`, which are defined in `Order.Interval.Finset.Defs`. In addition, it shows that in a locally finite order `≤` and `<` are the transitive closures of, respectively, `⩿` and `⋖`, which then leads to a characterization of monotone and strictly functions whose domain is a locally finite order. In particular, this file proves: * `le_iff_transGen_wcovBy`: `≤` is the transitive closure of `⩿` * `lt_iff_transGen_covBy`: `<` is the transitive closure of `⋖` * `monotone_iff_forall_wcovBy`: Characterization of monotone functions * `strictMono_iff_forall_covBy`: Characterization of strictly monotone functions ## TODO This file was originally only about `Finset.Ico a b` where `a b : ℕ`. No care has yet been taken to generalize these lemmas properly and many lemmas about `Icc`, `Ioc`, `Ioo` are missing. In general, what's to do is taking the lemmas in `Data.X.Intervals` and abstract away the concrete structure. Complete the API. See https://github.com/leanprover-community/mathlib/pull/14448#discussion_r906109235 for some ideas. -/ assert_not_exists MonoidWithZero Finset.sum open Function OrderDual open FinsetInterval variable {ι α : Type*} {a a₁ a₂ b b₁ b₂ c x : α} namespace Finset section Preorder variable [Preorder α] section LocallyFiniteOrder variable [LocallyFiniteOrder α] @[simp] theorem nonempty_Icc : (Icc a b).Nonempty ↔ a ≤ b := by rw [← coe_nonempty, coe_Icc, Set.nonempty_Icc] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Icc_of_le⟩ := nonempty_Icc @[simp] theorem nonempty_Ico : (Ico a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ico, Set.nonempty_Ico] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Ico_of_lt⟩ := nonempty_Ico @[simp] theorem nonempty_Ioc : (Ioc a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ioc, Set.nonempty_Ioc] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Ioc_of_lt⟩ := nonempty_Ioc -- TODO: This is nonsense. A locally finite order is never densely ordered @[simp] theorem nonempty_Ioo [DenselyOrdered α] : (Ioo a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ioo, Set.nonempty_Ioo] @[simp] theorem Icc_eq_empty_iff : Icc a b = ∅ ↔ ¬a ≤ b := by rw [← coe_eq_empty, coe_Icc, Set.Icc_eq_empty_iff] @[simp] theorem Ico_eq_empty_iff : Ico a b = ∅ ↔ ¬a < b := by rw [← coe_eq_empty, coe_Ico, Set.Ico_eq_empty_iff] @[simp] theorem Ioc_eq_empty_iff : Ioc a b = ∅ ↔ ¬a < b := by rw [← coe_eq_empty, coe_Ioc, Set.Ioc_eq_empty_iff] -- TODO: This is nonsense. A locally finite order is never densely ordered @[simp] theorem Ioo_eq_empty_iff [DenselyOrdered α] : Ioo a b = ∅ ↔ ¬a < b := by rw [← coe_eq_empty, coe_Ioo, Set.Ioo_eq_empty_iff] alias ⟨_, Icc_eq_empty⟩ := Icc_eq_empty_iff alias ⟨_, Ico_eq_empty⟩ := Ico_eq_empty_iff alias ⟨_, Ioc_eq_empty⟩ := Ioc_eq_empty_iff @[simp] theorem Ioo_eq_empty (h : ¬a < b) : Ioo a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ hx => h ((mem_Ioo.1 hx).1.trans (mem_Ioo.1 hx).2) @[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 left_mem_Icc : a ∈ Icc a b ↔ a ≤ b := by simp only [mem_Icc, true_and, le_rfl] theorem left_mem_Ico : a ∈ Ico a b ↔ a < b := by simp only [mem_Ico, true_and, le_refl] theorem right_mem_Icc : b ∈ Icc a b ↔ a ≤ b := by simp only [mem_Icc, and_true, le_rfl] theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b := by simp only [mem_Ioc, and_true, le_rfl] theorem left_not_mem_Ioc : a ∉ Ioc a b := fun h => lt_irrefl _ (mem_Ioc.1 h).1 theorem left_not_mem_Ioo : a ∉ Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).1 theorem right_not_mem_Ico : b ∉ Ico a b := fun h => lt_irrefl _ (mem_Ico.1 h).2 theorem right_not_mem_Ioo : b ∉ Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).2 @[gcongr] theorem Icc_subset_Icc (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊆ Icc a₂ b₂ := by simpa [← coe_subset] using Set.Icc_subset_Icc ha hb @[gcongr] theorem Ico_subset_Ico (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ico a₁ b₁ ⊆ Ico a₂ b₂ := by simpa [← coe_subset] using Set.Ico_subset_Ico ha hb @[gcongr] theorem Ioc_subset_Ioc (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ioc a₁ b₁ ⊆ Ioc a₂ b₂ := by simpa [← coe_subset] using Set.Ioc_subset_Ioc ha hb @[gcongr] theorem Ioo_subset_Ioo (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ioo a₁ b₁ ⊆ Ioo a₂ b₂ := by simpa [← coe_subset] using Set.Ioo_subset_Ioo ha hb @[gcongr] theorem Icc_subset_Icc_left (h : a₁ ≤ a₂) : Icc a₂ b ⊆ Icc a₁ b := Icc_subset_Icc h le_rfl @[gcongr] theorem Ico_subset_Ico_left (h : a₁ ≤ a₂) : Ico a₂ b ⊆ Ico a₁ b := Ico_subset_Ico h le_rfl @[gcongr] theorem Ioc_subset_Ioc_left (h : a₁ ≤ a₂) : Ioc a₂ b ⊆ Ioc a₁ b := Ioc_subset_Ioc h le_rfl @[gcongr] theorem Ioo_subset_Ioo_left (h : a₁ ≤ a₂) : Ioo a₂ b ⊆ Ioo a₁ b := Ioo_subset_Ioo h le_rfl @[gcongr] theorem Icc_subset_Icc_right (h : b₁ ≤ b₂) : Icc a b₁ ⊆ Icc a b₂ := Icc_subset_Icc le_rfl h @[gcongr] theorem Ico_subset_Ico_right (h : b₁ ≤ b₂) : Ico a b₁ ⊆ Ico a b₂ := Ico_subset_Ico le_rfl h @[gcongr] theorem Ioc_subset_Ioc_right (h : b₁ ≤ b₂) : Ioc a b₁ ⊆ Ioc a b₂ := Ioc_subset_Ioc le_rfl h @[gcongr] theorem Ioo_subset_Ioo_right (h : b₁ ≤ b₂) : Ioo a b₁ ⊆ Ioo a b₂ := Ioo_subset_Ioo le_rfl h theorem Ico_subset_Ioo_left (h : a₁ < a₂) : Ico a₂ b ⊆ Ioo a₁ b := by rw [← coe_subset, coe_Ico, coe_Ioo] exact Set.Ico_subset_Ioo_left h theorem Ioc_subset_Ioo_right (h : b₁ < b₂) : Ioc a b₁ ⊆ Ioo a b₂ := by rw [← coe_subset, coe_Ioc, coe_Ioo] exact Set.Ioc_subset_Ioo_right h theorem Icc_subset_Ico_right (h : b₁ < b₂) : Icc a b₁ ⊆ Ico a b₂ := by rw [← coe_subset, coe_Icc, coe_Ico] exact Set.Icc_subset_Ico_right h theorem Ioo_subset_Ico_self : Ioo a b ⊆ Ico a b := by rw [← coe_subset, coe_Ioo, coe_Ico] exact Set.Ioo_subset_Ico_self theorem Ioo_subset_Ioc_self : Ioo a b ⊆ Ioc a b := by rw [← coe_subset, coe_Ioo, coe_Ioc] exact Set.Ioo_subset_Ioc_self theorem Ico_subset_Icc_self : Ico a b ⊆ Icc a b := by rw [← coe_subset, coe_Ico, coe_Icc] exact Set.Ico_subset_Icc_self theorem Ioc_subset_Icc_self : Ioc a b ⊆ Icc a b := by rw [← coe_subset, coe_Ioc, coe_Icc] exact Set.Ioc_subset_Icc_self theorem Ioo_subset_Icc_self : Ioo a b ⊆ Icc a b := Ioo_subset_Ico_self.trans Ico_subset_Icc_self theorem Icc_subset_Icc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Icc a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := by rw [← coe_subset, coe_Icc, coe_Icc, Set.Icc_subset_Icc_iff h₁] theorem Icc_subset_Ioo_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ ↔ a₂ < a₁ ∧ b₁ < b₂ := by rw [← coe_subset, coe_Icc, coe_Ioo, Set.Icc_subset_Ioo_iff h₁] theorem Icc_subset_Ico_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ < b₂ := by rw [← coe_subset, coe_Icc, coe_Ico, Set.Icc_subset_Ico_iff h₁] theorem Icc_subset_Ioc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioc a₂ b₂ ↔ a₂ < a₁ ∧ b₁ ≤ b₂ := (Icc_subset_Ico_iff h₁.dual).trans and_comm --TODO: `Ico_subset_Ioo_iff`, `Ioc_subset_Ioo_iff` theorem Icc_ssubset_Icc_left (hI : a₂ ≤ b₂) (ha : a₂ < a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := by rw [← coe_ssubset, coe_Icc, coe_Icc] exact Set.Icc_ssubset_Icc_left hI ha hb theorem Icc_ssubset_Icc_right (hI : a₂ ≤ b₂) (ha : a₂ ≤ a₁) (hb : b₁ < b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := by rw [← coe_ssubset, coe_Icc, coe_Icc] exact Set.Icc_ssubset_Icc_right hI ha hb @[simp] theorem Ioc_disjoint_Ioc_of_le {d : α} (hbc : b ≤ c) : Disjoint (Ioc a b) (Ioc c d) := disjoint_left.2 fun _ h1 h2 ↦ not_and_of_not_left _ ((mem_Ioc.1 h1).2.trans hbc).not_lt (mem_Ioc.1 h2) variable (a) theorem Ico_self : Ico a a = ∅ := Ico_eq_empty <| lt_irrefl _ theorem Ioc_self : Ioc a a = ∅ := Ioc_eq_empty <| lt_irrefl _ theorem Ioo_self : Ioo a a = ∅ := Ioo_eq_empty <| lt_irrefl _ variable {a} /-- A set with upper and lower bounds in a locally finite order is a fintype -/ def _root_.Set.fintypeOfMemBounds {s : Set α} [DecidablePred (· ∈ s)] (ha : a ∈ lowerBounds s) (hb : b ∈ upperBounds s) : Fintype s := Set.fintypeSubset (Set.Icc a b) fun _ hx => ⟨ha hx, hb hx⟩ section Filter theorem Ico_filter_lt_of_le_left [DecidablePred (· < c)] (hca : c ≤ a) : {x ∈ Ico a b | x < c} = ∅ := filter_false_of_mem fun _ hx => (hca.trans (mem_Ico.1 hx).1).not_lt theorem Ico_filter_lt_of_right_le [DecidablePred (· < c)] (hbc : b ≤ c) : {x ∈ Ico a b | x < c} = Ico a b := filter_true_of_mem fun _ hx => (mem_Ico.1 hx).2.trans_le hbc theorem Ico_filter_lt_of_le_right [DecidablePred (· < c)] (hcb : c ≤ b) : {x ∈ Ico a b | x < c} = Ico a c := by ext x rw [mem_filter, mem_Ico, mem_Ico, and_right_comm] exact and_iff_left_of_imp fun h => h.2.trans_le hcb theorem Ico_filter_le_of_le_left {a b c : α} [DecidablePred (c ≤ ·)] (hca : c ≤ a) : {x ∈ Ico a b | c ≤ x} = Ico a b := filter_true_of_mem fun _ hx => hca.trans (mem_Ico.1 hx).1 theorem Ico_filter_le_of_right_le {a b : α} [DecidablePred (b ≤ ·)] : {x ∈ Ico a b | b ≤ x} = ∅ := filter_false_of_mem fun _ hx => (mem_Ico.1 hx).2.not_le theorem Ico_filter_le_of_left_le {a b c : α} [DecidablePred (c ≤ ·)] (hac : a ≤ c) : {x ∈ Ico a b | c ≤ x} = Ico c b := by ext x rw [mem_filter, mem_Ico, mem_Ico, and_comm, and_left_comm] exact and_iff_right_of_imp fun h => hac.trans h.1 theorem Icc_filter_lt_of_lt_right {a b c : α} [DecidablePred (· < c)] (h : b < c) : {x ∈ Icc a b | x < c} = Icc a b := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Icc.1 hx).2 h theorem Ioc_filter_lt_of_lt_right {a b c : α} [DecidablePred (· < c)] (h : b < c) : {x ∈ Ioc a b | x < c} = Ioc a b := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Ioc.1 hx).2 h theorem Iic_filter_lt_of_lt_right {α} [Preorder α] [LocallyFiniteOrderBot α] {a c : α} [DecidablePred (· < c)] (h : a < c) : {x ∈ Iic a | x < c} = Iic a := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Iic.1 hx) h variable (a b) [Fintype α] theorem filter_lt_lt_eq_Ioo [DecidablePred fun j => a < j ∧ j < b] : ({j | a < j ∧ j < b} : Finset _) = Ioo a b := by ext; simp theorem filter_lt_le_eq_Ioc [DecidablePred fun j => a < j ∧ j ≤ b] : ({j | a < j ∧ j ≤ b} : Finset _) = Ioc a b := by ext; simp theorem filter_le_lt_eq_Ico [DecidablePred fun j => a ≤ j ∧ j < b] : ({j | a ≤ j ∧ j < b} : Finset _) = Ico a b := by ext; simp theorem filter_le_le_eq_Icc [DecidablePred fun j => a ≤ j ∧ j ≤ b] : ({j | a ≤ j ∧ j ≤ b} : Finset _) = Icc a b := by ext; simp end Filter end LocallyFiniteOrder section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop α] @[simp] theorem Ioi_eq_empty : Ioi a = ∅ ↔ IsMax a := by rw [← coe_eq_empty, coe_Ioi, Set.Ioi_eq_empty_iff] @[simp] alias ⟨_, _root_.IsMax.finsetIoi_eq⟩ := Ioi_eq_empty @[simp] lemma Ioi_nonempty : (Ioi a).Nonempty ↔ ¬ IsMax a := by simp [nonempty_iff_ne_empty] theorem Ioi_top [OrderTop α] : Ioi (⊤ : α) = ∅ := Ioi_eq_empty.mpr isMax_top @[simp] theorem Ici_bot [OrderBot α] [Fintype α] : Ici (⊥ : α) = univ := by ext a; simp only [mem_Ici, bot_le, mem_univ] @[simp, aesop safe apply (rule_sets := [finsetNonempty])] lemma nonempty_Ici : (Ici a).Nonempty := ⟨a, mem_Ici.2 le_rfl⟩ lemma nonempty_Ioi : (Ioi a).Nonempty ↔ ¬ IsMax a := by simp [Finset.Nonempty] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Ioi_of_not_isMax⟩ := nonempty_Ioi @[simp] theorem Ici_subset_Ici : Ici a ⊆ Ici b ↔ b ≤ a := by simp [← coe_subset] @[gcongr] alias ⟨_, _root_.GCongr.Finset.Ici_subset_Ici⟩ := Ici_subset_Ici @[simp] theorem Ici_ssubset_Ici : Ici a ⊂ Ici b ↔ b < a := by simp [← coe_ssubset] @[gcongr] alias ⟨_, _root_.GCongr.Finset.Ici_ssubset_Ici⟩ := Ici_ssubset_Ici @[gcongr] theorem Ioi_subset_Ioi (h : a ≤ b) : Ioi b ⊆ Ioi a := by simpa [← coe_subset] using Set.Ioi_subset_Ioi h @[gcongr] theorem Ioi_ssubset_Ioi (h : a < b) : Ioi b ⊂ Ioi a := by simpa [← coe_ssubset] using Set.Ioi_ssubset_Ioi h variable [LocallyFiniteOrder α] theorem Icc_subset_Ici_self : Icc a b ⊆ Ici a := by simpa [← coe_subset] using Set.Icc_subset_Ici_self theorem Ico_subset_Ici_self : Ico a b ⊆ Ici a := by simpa [← coe_subset] using Set.Ico_subset_Ici_self theorem Ioc_subset_Ioi_self : Ioc a b ⊆ Ioi a := by simpa [← coe_subset] using Set.Ioc_subset_Ioi_self theorem Ioo_subset_Ioi_self : Ioo a b ⊆ Ioi a := by simpa [← coe_subset] using Set.Ioo_subset_Ioi_self theorem Ioc_subset_Ici_self : Ioc a b ⊆ Ici a := Ioc_subset_Icc_self.trans Icc_subset_Ici_self theorem Ioo_subset_Ici_self : Ioo a b ⊆ Ici a := Ioo_subset_Ico_self.trans Ico_subset_Ici_self end LocallyFiniteOrderTop section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot α] @[simp] theorem Iio_eq_empty : Iio a = ∅ ↔ IsMin a := Ioi_eq_empty (α := αᵒᵈ) @[simp] alias ⟨_, _root_.IsMin.finsetIio_eq⟩ := Iio_eq_empty @[simp] lemma Iio_nonempty : (Iio a).Nonempty ↔ ¬ IsMin a := by simp [nonempty_iff_ne_empty] theorem Iio_bot [OrderBot α] : Iio (⊥ : α) = ∅ := Iio_eq_empty.mpr isMin_bot @[simp] theorem Iic_top [OrderTop α] [Fintype α] : Iic (⊤ : α) = univ := by ext a; simp only [mem_Iic, le_top, mem_univ] @[simp, aesop safe apply (rule_sets := [finsetNonempty])] lemma nonempty_Iic : (Iic a).Nonempty := ⟨a, mem_Iic.2 le_rfl⟩ lemma nonempty_Iio : (Iio a).Nonempty ↔ ¬ IsMin a := by simp [Finset.Nonempty] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Iio_of_not_isMin⟩ := nonempty_Iio @[simp] theorem Iic_subset_Iic : Iic a ⊆ Iic b ↔ a ≤ b := by simp [← coe_subset] @[gcongr] alias ⟨_, _root_.GCongr.Finset.Iic_subset_Iic⟩ := Iic_subset_Iic @[simp] theorem Iic_ssubset_Iic : Iic a ⊂ Iic b ↔ a < b := by simp [← coe_ssubset] @[gcongr] alias ⟨_, _root_.GCongr.Finset.Iic_ssubset_Iic⟩ := Iic_ssubset_Iic @[gcongr] theorem Iio_subset_Iio (h : a ≤ b) : Iio a ⊆ Iio b := by simpa [← coe_subset] using Set.Iio_subset_Iio h @[gcongr] theorem Iio_ssubset_Iio (h : a < b) : Iio a ⊂ Iio b := by simpa [← coe_ssubset] using Set.Iio_ssubset_Iio h variable [LocallyFiniteOrder α] theorem Icc_subset_Iic_self : Icc a b ⊆ Iic b := by simpa [← coe_subset] using Set.Icc_subset_Iic_self theorem Ioc_subset_Iic_self : Ioc a b ⊆ Iic b := by simpa [← coe_subset] using Set.Ioc_subset_Iic_self theorem Ico_subset_Iio_self : Ico a b ⊆ Iio b := by simpa [← coe_subset] using Set.Ico_subset_Iio_self theorem Ioo_subset_Iio_self : Ioo a b ⊆ Iio b := by simpa [← coe_subset] using Set.Ioo_subset_Iio_self theorem Ico_subset_Iic_self : Ico a b ⊆ Iic b := Ico_subset_Icc_self.trans Icc_subset_Iic_self theorem Ioo_subset_Iic_self : Ioo a b ⊆ Iic b := Ioo_subset_Ioc_self.trans Ioc_subset_Iic_self theorem Iic_disjoint_Ioc (h : a ≤ b) : Disjoint (Iic a) (Ioc b c) := disjoint_left.2 fun _ hax hbcx ↦ (mem_Iic.1 hax).not_lt <| lt_of_le_of_lt h (mem_Ioc.1 hbcx).1 /-- An equivalence between `Finset.Iic a` and `Set.Iic a`. -/ def _root_.Equiv.IicFinsetSet (a : α) : Iic a ≃ Set.Iic a where toFun b := ⟨b.1, coe_Iic a ▸ mem_coe.2 b.2⟩ invFun b := ⟨b.1, by rw [← mem_coe, coe_Iic a]; exact b.2⟩ left_inv := fun _ ↦ rfl right_inv := fun _ ↦ rfl end LocallyFiniteOrderBot section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop α] {a : α} theorem Ioi_subset_Ici_self : Ioi a ⊆ Ici a := by simpa [← coe_subset] using Set.Ioi_subset_Ici_self theorem _root_.BddBelow.finite {s : Set α} (hs : BddBelow s) : s.Finite := let ⟨a, ha⟩ := hs (Ici a).finite_toSet.subset fun _ hx => mem_Ici.2 <| ha hx theorem _root_.Set.Infinite.not_bddBelow {s : Set α} : s.Infinite → ¬BddBelow s := mt BddBelow.finite variable [Fintype α] theorem filter_lt_eq_Ioi [DecidablePred (a < ·)] : ({x | a < x} : Finset _) = Ioi a := by ext; simp theorem filter_le_eq_Ici [DecidablePred (a ≤ ·)] : ({x | a ≤ x} : Finset _) = Ici a := by ext; simp end LocallyFiniteOrderTop section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot α] {a : α} theorem Iio_subset_Iic_self : Iio a ⊆ Iic a := by simpa [← coe_subset] using Set.Iio_subset_Iic_self theorem _root_.BddAbove.finite {s : Set α} (hs : BddAbove s) : s.Finite := hs.dual.finite theorem _root_.Set.Infinite.not_bddAbove {s : Set α} : s.Infinite → ¬BddAbove s := mt BddAbove.finite variable [Fintype α] theorem filter_gt_eq_Iio [DecidablePred (· < a)] : ({x | x < a} : Finset _) = Iio a := by ext; simp theorem filter_ge_eq_Iic [DecidablePred (· ≤ a)] : ({x | x ≤ a} : Finset _) = Iic a := by ext; simp end LocallyFiniteOrderBot section LocallyFiniteOrder variable [LocallyFiniteOrder α] @[simp] theorem Icc_bot [OrderBot α] : Icc (⊥ : α) a = Iic a := rfl @[simp] theorem Icc_top [OrderTop α] : Icc a (⊤ : α) = Ici a := rfl @[simp] theorem Ico_bot [OrderBot α] : Ico (⊥ : α) a = Iio a := rfl @[simp] theorem Ioc_top [OrderTop α] : Ioc a (⊤ : α) = Ioi a := rfl theorem Icc_bot_top [BoundedOrder α] [Fintype α] : Icc (⊥ : α) (⊤ : α) = univ := by rw [Icc_bot, Iic_top] end LocallyFiniteOrder variable [LocallyFiniteOrderTop α] [LocallyFiniteOrderBot α] theorem disjoint_Ioi_Iio (a : α) : Disjoint (Ioi a) (Iio a) := disjoint_left.2 fun _ hab hba => (mem_Ioi.1 hab).not_lt <| mem_Iio.1 hba end Preorder section PartialOrder variable [PartialOrder α] [LocallyFiniteOrder α] {a b c : α} @[simp] theorem Icc_self (a : α) : Icc a a = {a} := by rw [← coe_eq_singleton, coe_Icc, Set.Icc_self] @[simp] theorem Icc_eq_singleton_iff : Icc a b = {c} ↔ a = c ∧ b = c := by rw [← coe_eq_singleton, coe_Icc, Set.Icc_eq_singleton_iff] theorem Ico_disjoint_Ico_consecutive (a b c : α) : Disjoint (Ico a b) (Ico b c) := disjoint_left.2 fun _ hab hbc => (mem_Ico.mp hab).2.not_le (mem_Ico.mp hbc).1 @[simp] theorem Ici_top [OrderTop α] : Ici (⊤ : α) = {⊤} := Icc_eq_singleton_iff.2 ⟨rfl, rfl⟩ @[simp] theorem Iic_bot [OrderBot α] : Iic (⊥ : α) = {⊥} := Icc_eq_singleton_iff.2 ⟨rfl, rfl⟩ section DecidableEq variable [DecidableEq α] @[simp] theorem Icc_erase_left (a b : α) : (Icc a b).erase a = Ioc a b := by simp [← coe_inj] @[simp] theorem Icc_erase_right (a b : α) : (Icc a b).erase b = Ico a b := by simp [← coe_inj] @[simp] theorem Ico_erase_left (a b : α) : (Ico a b).erase a = Ioo a b := by simp [← coe_inj] @[simp] theorem Ioc_erase_right (a b : α) : (Ioc a b).erase b = Ioo a b := by simp [← coe_inj] @[simp] theorem Icc_diff_both (a b : α) : Icc a b \ {a, b} = Ioo a b := by simp [← coe_inj] @[simp] theorem Ico_insert_right (h : a ≤ b) : insert b (Ico a b) = Icc a b := by rw [← coe_inj, coe_insert, coe_Icc, coe_Ico, Set.insert_eq, Set.union_comm, Set.Ico_union_right h] @[simp] theorem Ioc_insert_left (h : a ≤ b) : insert a (Ioc a b) = Icc a b := by rw [← coe_inj, coe_insert, coe_Ioc, coe_Icc, Set.insert_eq, Set.union_comm, Set.Ioc_union_left h] @[simp] theorem Ioo_insert_left (h : a < b) : insert a (Ioo a b) = Ico a b := by rw [← coe_inj, coe_insert, coe_Ioo, coe_Ico, Set.insert_eq, Set.union_comm, Set.Ioo_union_left h] @[simp] theorem Ioo_insert_right (h : a < b) : insert b (Ioo a b) = Ioc a b := by rw [← coe_inj, coe_insert, coe_Ioo, coe_Ioc, Set.insert_eq, Set.union_comm, Set.Ioo_union_right h] @[simp] theorem Icc_diff_Ico_self (h : a ≤ b) : Icc a b \ Ico a b = {b} := by simp [← coe_inj, h] @[simp] theorem Icc_diff_Ioc_self (h : a ≤ b) : Icc a b \ Ioc a b = {a} := by simp [← coe_inj, h] @[simp] theorem Icc_diff_Ioo_self (h : a ≤ b) : Icc a b \ Ioo a b = {a, b} := by simp [← coe_inj, h] @[simp] theorem Ico_diff_Ioo_self (h : a < b) : Ico a b \ Ioo a b = {a} := by simp [← coe_inj, h] @[simp] theorem Ioc_diff_Ioo_self (h : a < b) : Ioc a b \ Ioo a b = {b} := by simp [← coe_inj, h] @[simp] theorem Ico_inter_Ico_consecutive (a b c : α) : Ico a b ∩ Ico b c = ∅ := (Ico_disjoint_Ico_consecutive a b c).eq_bot end DecidableEq -- Those lemmas are purposefully the other way around /-- `Finset.cons` version of `Finset.Ico_insert_right`. -/ theorem Icc_eq_cons_Ico (h : a ≤ b) : Icc a b = (Ico a b).cons b right_not_mem_Ico := by classical rw [cons_eq_insert, Ico_insert_right h] /-- `Finset.cons` version of `Finset.Ioc_insert_left`. -/ theorem Icc_eq_cons_Ioc (h : a ≤ b) : Icc a b = (Ioc a b).cons a left_not_mem_Ioc := by classical rw [cons_eq_insert, Ioc_insert_left h] /-- `Finset.cons` version of `Finset.Ioo_insert_right`. -/ theorem Ioc_eq_cons_Ioo (h : a < b) : Ioc a b = (Ioo a b).cons b right_not_mem_Ioo := by classical rw [cons_eq_insert, Ioo_insert_right h] /-- `Finset.cons` version of `Finset.Ioo_insert_left`. -/ theorem Ico_eq_cons_Ioo (h : a < b) : Ico a b = (Ioo a b).cons a left_not_mem_Ioo := by classical rw [cons_eq_insert, Ioo_insert_left h] theorem Ico_filter_le_left {a b : α} [DecidablePred (· ≤ a)] (hab : a < b) : {x ∈ Ico a b | x ≤ a} = {a} := by ext x rw [mem_filter, mem_Ico, mem_singleton, and_right_comm, ← le_antisymm_iff, eq_comm] exact and_iff_left_of_imp fun h => h.le.trans_lt hab theorem card_Ico_eq_card_Icc_sub_one (a b : α) : #(Ico a b) = #(Icc a b) - 1 := by classical by_cases h : a ≤ b · rw [Icc_eq_cons_Ico h, card_cons] exact (Nat.add_sub_cancel _ _).symm · rw [Ico_eq_empty fun h' => h h'.le, Icc_eq_empty h, card_empty, Nat.zero_sub] theorem card_Ioc_eq_card_Icc_sub_one (a b : α) : #(Ioc a b) = #(Icc a b) - 1 := @card_Ico_eq_card_Icc_sub_one αᵒᵈ _ _ _ _ theorem card_Ioo_eq_card_Ico_sub_one (a b : α) : #(Ioo a b) = #(Ico a b) - 1 := by classical by_cases h : a < b · rw [Ico_eq_cons_Ioo h, card_cons] exact (Nat.add_sub_cancel _ _).symm · rw [Ioo_eq_empty h, Ico_eq_empty h, card_empty, Nat.zero_sub] theorem card_Ioo_eq_card_Ioc_sub_one (a b : α) : #(Ioo a b) = #(Ioc a b) - 1 := @card_Ioo_eq_card_Ico_sub_one αᵒᵈ _ _ _ _ theorem card_Ioo_eq_card_Icc_sub_two (a b : α) : #(Ioo a b) = #(Icc a b) - 2 := by rw [card_Ioo_eq_card_Ico_sub_one, card_Ico_eq_card_Icc_sub_one] rfl end PartialOrder section Prod variable {β : Type*} section sectL lemma uIcc_map_sectL [Lattice α] [Lattice β] [LocallyFiniteOrder α] [LocallyFiniteOrder β] [DecidableLE (α × β)] (a b : α) (c : β) : (uIcc a b).map (.sectL _ c) = uIcc (a, c) (b, c) := by aesop (add safe forward [le_antisymm]) variable [Preorder α] [PartialOrder β] [LocallyFiniteOrder α] [LocallyFiniteOrder β] [DecidableLE (α × β)] (a b : α) (c : β) lemma Icc_map_sectL : (Icc a b).map (.sectL _ c) = Icc (a, c) (b, c) := by aesop (add safe forward [le_antisymm]) lemma Ioc_map_sectL : (Ioc a b).map (.sectL _ c) = Ioc (a, c) (b, c) := by aesop (add safe forward [le_antisymm, le_of_lt]) lemma Ico_map_sectL : (Ico a b).map (.sectL _ c) = Ico (a, c) (b, c) := by aesop (add safe forward [le_antisymm, le_of_lt]) lemma Ioo_map_sectL : (Ioo a b).map (.sectL _ c) = Ioo (a, c) (b, c) := by aesop (add safe forward [le_antisymm, le_of_lt]) end sectL section sectR lemma uIcc_map_sectR [Lattice α] [Lattice β] [LocallyFiniteOrder α] [LocallyFiniteOrder β] [DecidableLE (α × β)] (c : α) (a b : β) : (uIcc a b).map (.sectR c _) = uIcc (c, a) (c, b) := by aesop (add safe forward [le_antisymm]) variable [PartialOrder α] [Preorder β] [LocallyFiniteOrder α] [LocallyFiniteOrder β] [DecidableLE (α × β)] (c : α) (a b : β) lemma Icc_map_sectR : (Icc a b).map (.sectR c _) = Icc (c, a) (c, b) := by aesop (add safe forward [le_antisymm]) lemma Ioc_map_sectR : (Ioc a b).map (.sectR c _) = Ioc (c, a) (c, b) := by aesop (add safe forward [le_antisymm, le_of_lt]) lemma Ico_map_sectR : (Ico a b).map (.sectR c _) = Ico (c, a) (c, b) := by aesop (add safe forward [le_antisymm, le_of_lt]) lemma Ioo_map_sectR : (Ioo a b).map (.sectR c _) = Ioo (c, a) (c, b) := by aesop (add safe forward [le_antisymm, le_of_lt]) end sectR end Prod section BoundedPartialOrder variable [PartialOrder α] section OrderTop variable [LocallyFiniteOrderTop α] @[simp] theorem Ici_erase [DecidableEq α] (a : α) : (Ici a).erase a = Ioi a := by ext simp_rw [Finset.mem_erase, mem_Ici, mem_Ioi, lt_iff_le_and_ne, and_comm, ne_comm] @[simp] theorem Ioi_insert [DecidableEq α] (a : α) : insert a (Ioi a) = Ici a := by ext simp_rw [Finset.mem_insert, mem_Ici, mem_Ioi, le_iff_lt_or_eq, or_comm, eq_comm] theorem not_mem_Ioi_self {b : α} : b ∉ Ioi b := fun h => lt_irrefl _ (mem_Ioi.1 h) -- Purposefully written the other way around /-- `Finset.cons` version of `Finset.Ioi_insert`. -/ theorem Ici_eq_cons_Ioi (a : α) : Ici a = (Ioi a).cons a not_mem_Ioi_self := by classical rw [cons_eq_insert, Ioi_insert] theorem card_Ioi_eq_card_Ici_sub_one (a : α) : #(Ioi a) = #(Ici a) - 1 := by rw [Ici_eq_cons_Ioi, card_cons, Nat.add_sub_cancel_right] end OrderTop section OrderBot variable [LocallyFiniteOrderBot α] @[simp] theorem Iic_erase [DecidableEq α] (b : α) : (Iic b).erase b = Iio b := by ext simp_rw [Finset.mem_erase, mem_Iic, mem_Iio, lt_iff_le_and_ne, and_comm] @[simp] theorem Iio_insert [DecidableEq α] (b : α) : insert b (Iio b) = Iic b := by ext simp_rw [Finset.mem_insert, mem_Iic, mem_Iio, le_iff_lt_or_eq, or_comm] theorem not_mem_Iio_self {b : α} : b ∉ Iio b := fun h => lt_irrefl _ (mem_Iio.1 h) -- Purposefully written the other way around /-- `Finset.cons` version of `Finset.Iio_insert`. -/ theorem Iic_eq_cons_Iio (b : α) : Iic b = (Iio b).cons b not_mem_Iio_self := by classical rw [cons_eq_insert, Iio_insert] theorem card_Iio_eq_card_Iic_sub_one (a : α) : #(Iio a) = #(Iic a) - 1 := by rw [Iic_eq_cons_Iio, card_cons, Nat.add_sub_cancel_right] end OrderBot end BoundedPartialOrder section SemilatticeSup variable [SemilatticeSup α] [LocallyFiniteOrderBot α] -- TODO: Why does `id_eq` simplify the LHS here but not the LHS of `Finset.sup_Iic`? lemma sup'_Iic (a : α) : (Iic a).sup' nonempty_Iic id = a := le_antisymm (sup'_le _ _ fun _ ↦ mem_Iic.1) <| le_sup' (f := id) <| mem_Iic.2 <| le_refl a @[simp] lemma sup_Iic [OrderBot α] (a : α) : (Iic a).sup id = a := le_antisymm (Finset.sup_le fun _ ↦ mem_Iic.1) <| le_sup (f := id) <| mem_Iic.2 <| le_refl a lemma image_subset_Iic_sup [OrderBot α] [DecidableEq α] (f : ι → α) (s : Finset ι) : s.image f ⊆ Iic (s.sup f) := by refine fun i hi ↦ mem_Iic.2 ?_ obtain ⟨j, hj, rfl⟩ := mem_image.1 hi exact le_sup hj lemma subset_Iic_sup_id [OrderBot α] (s : Finset α) : s ⊆ Iic (s.sup id) := fun _ h ↦ mem_Iic.2 <| le_sup (f := id) h end SemilatticeSup section SemilatticeInf variable [SemilatticeInf α] [LocallyFiniteOrderTop α] lemma inf'_Ici (a : α) : (Ici a).inf' nonempty_Ici id = a := ge_antisymm (le_inf' _ _ fun _ ↦ mem_Ici.1) <| inf'_le (f := id) <| mem_Ici.2 <| le_refl a @[simp] lemma inf_Ici [OrderTop α] (a : α) : (Ici a).inf id = a := le_antisymm (inf_le (f := id) <| mem_Ici.2 <| le_refl a) <| Finset.le_inf fun _ ↦ mem_Ici.1 end SemilatticeInf section LinearOrder variable [LinearOrder α] section LocallyFiniteOrder variable [LocallyFiniteOrder α] theorem Ico_subset_Ico_iff {a₁ b₁ a₂ b₂ : α} (h : a₁ < b₁) : Ico a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := by rw [← coe_subset, coe_Ico, coe_Ico, Set.Ico_subset_Ico_iff h] theorem Ico_union_Ico_eq_Ico {a b c : α} (hab : a ≤ b) (hbc : b ≤ c) : Ico a b ∪ Ico b c = Ico a c := by rw [← coe_inj, coe_union, coe_Ico, coe_Ico, coe_Ico, Set.Ico_union_Ico_eq_Ico hab hbc] @[simp] theorem Ioc_union_Ioc_eq_Ioc {a b c : α} (h₁ : a ≤ b) (h₂ : b ≤ c) : Ioc a b ∪ Ioc b c = Ioc a c := by rw [← coe_inj, coe_union, coe_Ioc, coe_Ioc, coe_Ioc, Set.Ioc_union_Ioc_eq_Ioc h₁ h₂] theorem Ico_subset_Ico_union_Ico {a b c : α} : Ico a c ⊆ Ico a b ∪ Ico b c := by rw [← coe_subset, coe_union, coe_Ico, coe_Ico, coe_Ico] exact Set.Ico_subset_Ico_union_Ico theorem Ico_union_Ico' {a b c d : α} (hcb : c ≤ b) (had : a ≤ d) : Ico a b ∪ Ico c d = Ico (min a c) (max b d) := by rw [← coe_inj, coe_union, coe_Ico, coe_Ico, coe_Ico, Set.Ico_union_Ico' hcb had] theorem Ico_union_Ico {a b c d : α} (h₁ : min a b ≤ max c d) (h₂ : min c d ≤ max a b) : Ico a b ∪ Ico c d = Ico (min a c) (max b d) := by rw [← coe_inj, coe_union, coe_Ico, coe_Ico, coe_Ico, Set.Ico_union_Ico h₁ h₂] theorem Ico_inter_Ico {a b c d : α} : Ico a b ∩ Ico c d = Ico (max a c) (min b d) := by rw [← coe_inj, coe_inter, coe_Ico, coe_Ico, coe_Ico, Set.Ico_inter_Ico] theorem Ioc_inter_Ioc {a b c d : α} : Ioc a b ∩ Ioc c d = Ioc (max a c) (min b d) := by rw [← coe_inj] push_cast exact Set.Ioc_inter_Ioc @[simp] theorem Ico_filter_lt (a b c : α) : {x ∈ Ico a b | x < c} = Ico a (min b c) := by cases le_total b c with | inl h => rw [Ico_filter_lt_of_right_le h, min_eq_left h] | inr h => rw [Ico_filter_lt_of_le_right h, min_eq_right h] @[simp] theorem Ico_filter_le (a b c : α) : {x ∈ Ico a b | c ≤ x} = Ico (max a c) b := by cases le_total a c with | inl h => rw [Ico_filter_le_of_left_le h, max_eq_right h] | inr h => rw [Ico_filter_le_of_le_left h, max_eq_left h] @[simp] theorem Ioo_filter_lt (a b c : α) : {x ∈ Ioo a b | x < c} = Ioo a (min b c) := by ext simp [and_assoc] @[simp] theorem Iio_filter_lt {α} [LinearOrder α] [LocallyFiniteOrderBot α] (a b : α) : {x ∈ Iio a | x < b} = Iio (min a b) := by ext simp [and_assoc] @[simp] theorem Ico_diff_Ico_left (a b c : α) : Ico a b \ Ico a c = Ico (max a c) b := by cases le_total a c with | inl h => ext x rw [mem_sdiff, mem_Ico, mem_Ico, mem_Ico, max_eq_right h, and_right_comm, not_and, not_lt] exact and_congr_left' ⟨fun hx => hx.2 hx.1, fun hx => ⟨h.trans hx, fun _ => hx⟩⟩ | inr h => rw [Ico_eq_empty_of_le h, sdiff_empty, max_eq_left h] @[simp] theorem Ico_diff_Ico_right (a b c : α) : Ico a b \ Ico c b = Ico a (min b c) := by cases le_total b c with | inl h => rw [Ico_eq_empty_of_le h, sdiff_empty, min_eq_left h] | inr h => ext x rw [mem_sdiff, mem_Ico, mem_Ico, mem_Ico, min_eq_right h, and_assoc, not_and', not_le] exact and_congr_right' ⟨fun hx => hx.2 hx.1, fun hx => ⟨hx.trans_le h, fun _ => hx⟩⟩ @[simp] theorem Ioc_disjoint_Ioc : Disjoint (Ioc a₁ a₂) (Ioc b₁ b₂) ↔ min a₂ b₂ ≤ max a₁ b₁ := by simp_rw [disjoint_iff_inter_eq_empty, Ioc_inter_Ioc, Ioc_eq_empty_iff, not_lt] section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot α] theorem Iic_diff_Ioc : Iic b \ Ioc a b = Iic (a ⊓ b) := by rw [← coe_inj] push_cast exact Set.Iic_diff_Ioc theorem Iic_diff_Ioc_self_of_le (hab : a ≤ b) : Iic b \ Ioc a b = Iic a := by rw [Iic_diff_Ioc, min_eq_left hab] theorem Iic_union_Ioc_eq_Iic (h : a ≤ b) : Iic a ∪ Ioc a b = Iic b := by rw [← coe_inj] push_cast exact Set.Iic_union_Ioc_eq_Iic h end LocallyFiniteOrderBot end LocallyFiniteOrder section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot α] {s : Set α} theorem _root_.Set.Infinite.exists_gt (hs : s.Infinite) : ∀ a, ∃ b ∈ s, a < b := not_bddAbove_iff.1 hs.not_bddAbove theorem _root_.Set.infinite_iff_exists_gt [Nonempty α] : s.Infinite ↔ ∀ a, ∃ b ∈ s, a < b := ⟨Set.Infinite.exists_gt, Set.infinite_of_forall_exists_gt⟩
end LocallyFiniteOrderBot
Mathlib/Order/Interval/Finset/Basic.lean
924
925
/- Copyright (c) 2022 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Combinatorics.SetFamily.Compression.Down import Mathlib.Data.Fintype.Powerset import Mathlib.Order.Interval.Finset.Nat import Mathlib.Algebra.BigOperators.Group.Finset.Basic /-! # Shattering families This file defines the shattering property and VC-dimension of set families. ## Main declarations * `Finset.Shatters`: The shattering property. * `Finset.shatterer`: The set family of sets shattered by a set family. * `Finset.vcDim`: The Vapnik-Chervonenkis dimension. ## TODO * Order-shattering * Strong shattering -/ open scoped FinsetFamily namespace Finset variable {α : Type*} [DecidableEq α] {𝒜 ℬ : Finset (Finset α)} {s t : Finset α} {a : α} /-- A set family `𝒜` shatters a set `s` if all subsets of `s` can be obtained as the intersection of `s` and some element of the set family, and we denote this `𝒜.Shatters s`. We also say that `s` is *traced* by `𝒜`. -/ def Shatters (𝒜 : Finset (Finset α)) (s : Finset α) : Prop := ∀ ⦃t⦄, t ⊆ s → ∃ u ∈ 𝒜, s ∩ u = t instance : DecidablePred 𝒜.Shatters := fun _s ↦ decidableForallOfDecidableSubsets lemma Shatters.exists_inter_eq_singleton (hs : Shatters 𝒜 s) (ha : a ∈ s) : ∃ t ∈ 𝒜, s ∩ t = {a} := hs <| singleton_subset_iff.2 ha lemma Shatters.mono_left (h : 𝒜 ⊆ ℬ) (h𝒜 : 𝒜.Shatters s) : ℬ.Shatters s := fun _t ht ↦ let ⟨u, hu, hut⟩ := h𝒜 ht; ⟨u, h hu, hut⟩ lemma Shatters.mono_right (h : t ⊆ s) (hs : 𝒜.Shatters s) : 𝒜.Shatters t := fun u hu ↦ by obtain ⟨v, hv, rfl⟩ := hs (hu.trans h); exact ⟨v, hv, inf_congr_right hu <| inf_le_of_left_le h⟩ lemma Shatters.exists_superset (h : 𝒜.Shatters s) : ∃ t ∈ 𝒜, s ⊆ t := let ⟨t, ht, hst⟩ := h Subset.rfl; ⟨t, ht, inter_eq_left.1 hst⟩ lemma shatters_of_forall_subset (h : ∀ t, t ⊆ s → t ∈ 𝒜) : 𝒜.Shatters s := fun t ht ↦ ⟨t, h _ ht, inter_eq_right.2 ht⟩ protected lemma Shatters.nonempty (h : 𝒜.Shatters s) : 𝒜.Nonempty := let ⟨t, ht, _⟩ := h Subset.rfl; ⟨t, ht⟩ @[simp] lemma shatters_empty : 𝒜.Shatters ∅ ↔ 𝒜.Nonempty := ⟨Shatters.nonempty, fun ⟨s, hs⟩ t ht ↦ ⟨s, hs, by rwa [empty_inter, eq_comm, ← subset_empty]⟩⟩ protected lemma Shatters.subset_iff (h : 𝒜.Shatters s) : t ⊆ s ↔ ∃ u ∈ 𝒜, s ∩ u = t := ⟨fun ht ↦ h ht, by rintro ⟨u, _, rfl⟩; exact inter_subset_left⟩ lemma shatters_iff : 𝒜.Shatters s ↔ 𝒜.image (fun t ↦ s ∩ t) = s.powerset := ⟨fun h ↦ by ext t; rw [mem_image, mem_powerset, h.subset_iff], fun h t ht ↦ by rwa [← mem_powerset, ← h, mem_image] at ht⟩ lemma univ_shatters [Fintype α] : univ.Shatters s := shatters_of_forall_subset fun _ _ ↦ mem_univ _ @[simp] lemma shatters_univ [Fintype α] : 𝒜.Shatters univ ↔ 𝒜 = univ := by rw [shatters_iff, powerset_univ]; simp_rw [univ_inter, image_id'] /-- The set family of sets that are shattered by `𝒜`. -/ def shatterer (𝒜 : Finset (Finset α)) : Finset (Finset α) := {s ∈ 𝒜.biUnion powerset | 𝒜.Shatters s} @[simp] lemma mem_shatterer : s ∈ 𝒜.shatterer ↔ 𝒜.Shatters s := by refine mem_filter.trans <| and_iff_right_of_imp fun h ↦ ?_ simp_rw [mem_biUnion, mem_powerset] exact h.exists_superset @[gcongr] lemma shatterer_mono (h : 𝒜 ⊆ ℬ) : 𝒜.shatterer ⊆ ℬ.shatterer := fun _ ↦ by simpa using Shatters.mono_left h lemma subset_shatterer (h : IsLowerSet (𝒜 : Set (Finset α))) : 𝒜 ⊆ 𝒜.shatterer := fun _s hs ↦ mem_shatterer.2 fun t ht ↦ ⟨t, h ht hs, inter_eq_right.2 ht⟩
@[simp] lemma isLowerSet_shatterer (𝒜 : Finset (Finset α)) :
Mathlib/Combinatorics/SetFamily/Shatter.lean
88
89
/- Copyright (c) 2024 Josha Dekker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Josha Dekker -/ import Mathlib.Analysis.SpecialFunctions.Exponential import Mathlib.Probability.ProbabilityMassFunction.Basic import Mathlib.MeasureTheory.Function.StronglyMeasurable.Basic /-! # Poisson distributions over ℕ Define the Poisson measure over the natural numbers ## Main definitions * `poissonPMFReal`: the function `fun n ↦ exp (- λ) * λ ^ n / n!` for `n ∈ ℕ`, which is the probability density function of a Poisson distribution with rate `λ > 0`. * `poissonPMF`: `ℝ≥0∞`-valued pdf, `poissonPMF λ = ENNReal.ofReal (poissonPMFReal λ)`. * `poissonMeasure`: a Poisson measure on `ℕ`, parametrized by its rate `λ`. -/ open scoped ENNReal NNReal Nat open MeasureTheory Real Set Filter Topology namespace ProbabilityTheory section PoissonPMF /-- The pmf of the Poisson distribution depending on its rate, as a function to ℝ -/ noncomputable def poissonPMFReal (r : ℝ≥0) (n : ℕ) : ℝ := exp (- r) * r ^ n / n ! lemma poissonPMFRealSum (r : ℝ≥0) : HasSum (fun n ↦ poissonPMFReal r n) 1 := by let r := r.toReal unfold poissonPMFReal apply (hasSum_mul_left_iff (exp_ne_zero r)).mp simp only [mul_one] have : (fun i ↦ rexp r * (rexp (-r) * r ^ i / ↑(Nat.factorial i))) = fun i ↦ r ^ i / ↑(Nat.factorial i) := by ext n rw [mul_div_assoc, exp_neg, ← mul_assoc, ← div_eq_mul_inv, div_self (exp_ne_zero r), one_mul] rw [this, exp_eq_exp_ℝ] exact NormedSpace.expSeries_div_hasSum_exp ℝ r /-- The Poisson pmf is positive for all natural numbers -/ lemma poissonPMFReal_pos {r : ℝ≥0} {n : ℕ} (hr : 0 < r) : 0 < poissonPMFReal r n := by rw [poissonPMFReal] positivity lemma poissonPMFReal_nonneg {r : ℝ≥0} {n : ℕ} : 0 ≤ poissonPMFReal r n := by unfold poissonPMFReal positivity /-- The pmf of the Poisson distribution depending on its rate, as a PMF. -/ noncomputable def poissonPMF (r : ℝ≥0) : PMF ℕ := by refine ⟨fun n ↦ ENNReal.ofReal (poissonPMFReal r n), ?_⟩ apply ENNReal.hasSum_coe.mpr rw [← toNNReal_one] exact (poissonPMFRealSum r).toNNReal (fun n ↦ poissonPMFReal_nonneg) /-- The Poisson pmf is measurable. -/
@[measurability] lemma measurable_poissonPMFReal (r : ℝ≥0) : Measurable (poissonPMFReal r) := by measurability
Mathlib/Probability/Distributions/Poisson.lean
66
68
/- 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.MonoidAlgebra.Degree import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.Polynomial.Basic import Mathlib.Data.Nat.Cast.WithTop import Mathlib.Data.Nat.SuccPred import Mathlib.Order.SuccPred.WithBot /-! # Degree of univariate polynomials ## Main definitions * `Polynomial.degree`: the degree of a polynomial, where `0` has degree `⊥` * `Polynomial.natDegree`: the degree of a polynomial, where `0` has degree `0` * `Polynomial.leadingCoeff`: the leading coefficient of a polynomial * `Polynomial.Monic`: a polynomial is monic if its leading coefficient is 0 * `Polynomial.nextCoeff`: the next coefficient after the leading coefficient ## Main results * `Polynomial.degree_eq_natDegree`: the degree and natDegree coincide for nonzero polynomials -/ noncomputable section open Finsupp Finset open Polynomial namespace Polynomial universe u v variable {R : Type u} {S : Type v} {a b c d : R} {n m : ℕ} section Semiring variable [Semiring R] {p q r : R[X]} /-- `degree p` is the degree of the polynomial `p`, i.e. the largest `X`-exponent in `p`. `degree p = some n` when `p ≠ 0` and `n` is the highest power of `X` that appears in `p`, otherwise `degree 0 = ⊥`. -/ def degree (p : R[X]) : WithBot ℕ := p.support.max /-- `natDegree p` forces `degree p` to ℕ, by defining `natDegree 0 = 0`. -/ def natDegree (p : R[X]) : ℕ := (degree p).unbotD 0 /-- `leadingCoeff p` gives the coefficient of the highest power of `X` in `p`. -/ def leadingCoeff (p : R[X]) : R := coeff p (natDegree p) /-- a polynomial is `Monic` if its leading coefficient is 1 -/ def Monic (p : R[X]) := leadingCoeff p = (1 : R) theorem Monic.def : Monic p ↔ leadingCoeff p = 1 := Iff.rfl instance Monic.decidable [DecidableEq R] : Decidable (Monic p) := by unfold Monic; infer_instance @[simp] theorem Monic.leadingCoeff {p : R[X]} (hp : p.Monic) : leadingCoeff p = 1 := hp theorem Monic.coeff_natDegree {p : R[X]} (hp : p.Monic) : p.coeff p.natDegree = 1 := hp @[simp] theorem degree_zero : degree (0 : R[X]) = ⊥ := rfl @[simp] theorem natDegree_zero : natDegree (0 : R[X]) = 0 := rfl @[simp] theorem coeff_natDegree : coeff p (natDegree p) = leadingCoeff p := rfl @[simp] theorem degree_eq_bot : degree p = ⊥ ↔ p = 0 := ⟨fun h => support_eq_empty.1 (Finset.max_eq_bot.1 h), fun h => h.symm ▸ rfl⟩ theorem degree_ne_bot : degree p ≠ ⊥ ↔ p ≠ 0 := degree_eq_bot.not theorem degree_eq_natDegree (hp : p ≠ 0) : degree p = (natDegree p : WithBot ℕ) := by let ⟨n, hn⟩ := not_forall.1 (mt Option.eq_none_iff_forall_not_mem.2 (mt degree_eq_bot.1 hp)) have hn : degree p = some n := Classical.not_not.1 hn rw [natDegree, hn]; rfl theorem degree_eq_iff_natDegree_eq {p : R[X]} {n : ℕ} (hp : p ≠ 0) : p.degree = n ↔ p.natDegree = n := by rw [degree_eq_natDegree hp]; exact WithBot.coe_eq_coe theorem degree_eq_iff_natDegree_eq_of_pos {p : R[X]} {n : ℕ} (hn : 0 < n) : p.degree = n ↔ p.natDegree = n := by obtain rfl|h := eq_or_ne p 0 · simp [hn.ne] · exact degree_eq_iff_natDegree_eq h theorem natDegree_eq_of_degree_eq_some {p : R[X]} {n : ℕ} (h : degree p = n) : natDegree p = n := by rw [natDegree, h, Nat.cast_withBot, WithBot.unbotD_coe] theorem degree_ne_of_natDegree_ne {n : ℕ} : p.natDegree ≠ n → degree p ≠ n := mt natDegree_eq_of_degree_eq_some @[simp] theorem degree_le_natDegree : degree p ≤ natDegree p := WithBot.giUnbotDBot.gc.le_u_l _ theorem natDegree_eq_of_degree_eq [Semiring S] {q : S[X]} (h : degree p = degree q) : natDegree p = natDegree q := by unfold natDegree; rw [h] theorem le_degree_of_ne_zero (h : coeff p n ≠ 0) : (n : WithBot ℕ) ≤ degree p := by rw [Nat.cast_withBot] exact Finset.le_sup (mem_support_iff.2 h) theorem degree_mono [Semiring S] {f : R[X]} {g : S[X]} (h : f.support ⊆ g.support) : f.degree ≤ g.degree := Finset.sup_mono h theorem degree_le_degree (h : coeff q (natDegree p) ≠ 0) : degree p ≤ degree q := by by_cases hp : p = 0 · rw [hp, degree_zero] exact bot_le · rw [degree_eq_natDegree hp] exact le_degree_of_ne_zero h theorem natDegree_le_iff_degree_le {n : ℕ} : natDegree p ≤ n ↔ degree p ≤ n := WithBot.unbotD_le_iff (fun _ ↦ bot_le) theorem natDegree_lt_iff_degree_lt (hp : p ≠ 0) : p.natDegree < n ↔ p.degree < ↑n := WithBot.unbotD_lt_iff (absurd · (degree_eq_bot.not.mpr hp)) alias ⟨degree_le_of_natDegree_le, natDegree_le_of_degree_le⟩ := natDegree_le_iff_degree_le theorem natDegree_le_natDegree [Semiring S] {q : S[X]} (hpq : p.degree ≤ q.degree) : p.natDegree ≤ q.natDegree := WithBot.giUnbotDBot.gc.monotone_l hpq @[simp] theorem degree_C (ha : a ≠ 0) : degree (C a) = (0 : WithBot ℕ) := by rw [degree, ← monomial_zero_left, support_monomial 0 ha, max_eq_sup_coe, sup_singleton, WithBot.coe_zero] theorem degree_C_le : degree (C a) ≤ 0 := by by_cases h : a = 0 · rw [h, C_0] exact bot_le · rw [degree_C h] theorem degree_C_lt : degree (C a) < 1 := degree_C_le.trans_lt <| WithBot.coe_lt_coe.mpr zero_lt_one theorem degree_one_le : degree (1 : R[X]) ≤ (0 : WithBot ℕ) := by rw [← C_1]; exact degree_C_le @[simp] theorem natDegree_C (a : R) : natDegree (C a) = 0 := by by_cases ha : a = 0 · have : C a = 0 := by rw [ha, C_0] rw [natDegree, degree_eq_bot.2 this, WithBot.unbotD_bot] · rw [natDegree, degree_C ha, WithBot.unbotD_zero] @[simp] theorem natDegree_one : natDegree (1 : R[X]) = 0 := natDegree_C 1 @[simp] theorem natDegree_natCast (n : ℕ) : natDegree (n : R[X]) = 0 := by simp only [← C_eq_natCast, natDegree_C] @[simp] theorem natDegree_ofNat (n : ℕ) [Nat.AtLeastTwo n] : natDegree (ofNat(n) : R[X]) = 0 := natDegree_natCast _ theorem degree_natCast_le (n : ℕ) : degree (n : R[X]) ≤ 0 := degree_le_of_natDegree_le (by simp) @[simp] theorem degree_monomial (n : ℕ) (ha : a ≠ 0) : degree (monomial n a) = n := by rw [degree, support_monomial n ha, max_singleton, Nat.cast_withBot] @[simp] theorem degree_C_mul_X_pow (n : ℕ) (ha : a ≠ 0) : degree (C a * X ^ n) = n := by rw [C_mul_X_pow_eq_monomial, degree_monomial n ha] theorem degree_C_mul_X (ha : a ≠ 0) : degree (C a * X) = 1 := by simpa only [pow_one] using degree_C_mul_X_pow 1 ha theorem degree_monomial_le (n : ℕ) (a : R) : degree (monomial n a) ≤ n := letI := Classical.decEq R if h : a = 0 then by rw [h, (monomial n).map_zero, degree_zero]; exact bot_le else le_of_eq (degree_monomial n h) theorem degree_C_mul_X_pow_le (n : ℕ) (a : R) : degree (C a * X ^ n) ≤ n := by rw [C_mul_X_pow_eq_monomial] apply degree_monomial_le theorem degree_C_mul_X_le (a : R) : degree (C a * X) ≤ 1 := by simpa only [pow_one] using degree_C_mul_X_pow_le 1 a @[simp] theorem natDegree_C_mul_X_pow (n : ℕ) (a : R) (ha : a ≠ 0) : natDegree (C a * X ^ n) = n := natDegree_eq_of_degree_eq_some (degree_C_mul_X_pow n ha) @[simp] theorem natDegree_C_mul_X (a : R) (ha : a ≠ 0) : natDegree (C a * X) = 1 := by simpa only [pow_one] using natDegree_C_mul_X_pow 1 a ha @[simp] theorem natDegree_monomial [DecidableEq R] (i : ℕ) (r : R) : natDegree (monomial i r) = if r = 0 then 0 else i := by split_ifs with hr · simp [hr] · rw [← C_mul_X_pow_eq_monomial, natDegree_C_mul_X_pow i r hr] theorem natDegree_monomial_le (a : R) {m : ℕ} : (monomial m a).natDegree ≤ m := by classical rw [Polynomial.natDegree_monomial] split_ifs exacts [Nat.zero_le _, le_rfl] theorem natDegree_monomial_eq (i : ℕ) {r : R} (r0 : r ≠ 0) : (monomial i r).natDegree = i := letI := Classical.decEq R Eq.trans (natDegree_monomial _ _) (if_neg r0) theorem coeff_ne_zero_of_eq_degree (hn : degree p = n) : coeff p n ≠ 0 := fun h => mem_support_iff.mp (mem_of_max hn) h theorem degree_X_pow_le (n : ℕ) : degree (X ^ n : R[X]) ≤ n := by simpa only [C_1, one_mul] using degree_C_mul_X_pow_le n (1 : R) theorem degree_X_le : degree (X : R[X]) ≤ 1 := degree_monomial_le _ _ theorem natDegree_X_le : (X : R[X]).natDegree ≤ 1 := natDegree_le_of_degree_le degree_X_le theorem withBotSucc_degree_eq_natDegree_add_one (h : p ≠ 0) : p.degree.succ = p.natDegree + 1 := by rw [degree_eq_natDegree h] exact WithBot.succ_coe p.natDegree end Semiring section NonzeroSemiring variable [Semiring R] [Nontrivial R] {p q : R[X]} @[simp] theorem degree_one : degree (1 : R[X]) = (0 : WithBot ℕ) := degree_C one_ne_zero @[simp] theorem degree_X : degree (X : R[X]) = 1 := degree_monomial _ one_ne_zero @[simp] theorem natDegree_X : (X : R[X]).natDegree = 1 := natDegree_eq_of_degree_eq_some degree_X end NonzeroSemiring section Ring variable [Ring R] @[simp] theorem degree_neg (p : R[X]) : degree (-p) = degree p := by unfold degree; rw [support_neg] theorem degree_neg_le_of_le {a : WithBot ℕ} {p : R[X]} (hp : degree p ≤ a) : degree (-p) ≤ a := p.degree_neg.le.trans hp @[simp] theorem natDegree_neg (p : R[X]) : natDegree (-p) = natDegree p := by simp [natDegree] theorem natDegree_neg_le_of_le {p : R[X]} (hp : natDegree p ≤ m) : natDegree (-p) ≤ m := (natDegree_neg p).le.trans hp @[simp] theorem natDegree_intCast (n : ℤ) : natDegree (n : R[X]) = 0 := by rw [← C_eq_intCast, natDegree_C] theorem degree_intCast_le (n : ℤ) : degree (n : R[X]) ≤ 0 := degree_le_of_natDegree_le (by simp) @[simp] theorem leadingCoeff_neg (p : R[X]) : (-p).leadingCoeff = -p.leadingCoeff := by rw [leadingCoeff, leadingCoeff, natDegree_neg, coeff_neg] end Ring section Semiring variable [Semiring R] {p : R[X]} /-- The second-highest coefficient, or 0 for constants -/ def nextCoeff (p : R[X]) : R := if p.natDegree = 0 then 0 else p.coeff (p.natDegree - 1) lemma nextCoeff_eq_zero : p.nextCoeff = 0 ↔ p.natDegree = 0 ∨ 0 < p.natDegree ∧ p.coeff (p.natDegree - 1) = 0 := by simp [nextCoeff, or_iff_not_imp_left, pos_iff_ne_zero]; aesop lemma nextCoeff_ne_zero : p.nextCoeff ≠ 0 ↔ p.natDegree ≠ 0 ∧ p.coeff (p.natDegree - 1) ≠ 0 := by simp [nextCoeff] @[simp] theorem nextCoeff_C_eq_zero (c : R) : nextCoeff (C c) = 0 := by rw [nextCoeff] simp theorem nextCoeff_of_natDegree_pos (hp : 0 < p.natDegree) : nextCoeff p = p.coeff (p.natDegree - 1) := by rw [nextCoeff, if_neg] contrapose! hp simpa variable {p q : R[X]} {ι : Type*} theorem degree_add_le (p q : R[X]) : degree (p + q) ≤ max (degree p) (degree q) := by simpa only [degree, ← support_toFinsupp, toFinsupp_add] using AddMonoidAlgebra.sup_support_add_le _ _ _ theorem degree_add_le_of_degree_le {p q : R[X]} {n : ℕ} (hp : degree p ≤ n) (hq : degree q ≤ n) : degree (p + q) ≤ n := (degree_add_le p q).trans <| max_le hp hq theorem degree_add_le_of_le {a b : WithBot ℕ} (hp : degree p ≤ a) (hq : degree q ≤ b) : degree (p + q) ≤ max a b := (p.degree_add_le q).trans <| max_le_max ‹_› ‹_› theorem natDegree_add_le (p q : R[X]) : natDegree (p + q) ≤ max (natDegree p) (natDegree q) := by rcases le_max_iff.1 (degree_add_le p q) with h | h <;> simp [natDegree_le_natDegree h] theorem natDegree_add_le_of_degree_le {p q : R[X]} {n : ℕ} (hp : natDegree p ≤ n) (hq : natDegree q ≤ n) : natDegree (p + q) ≤ n := (natDegree_add_le p q).trans <| max_le hp hq theorem natDegree_add_le_of_le (hp : natDegree p ≤ m) (hq : natDegree q ≤ n) : natDegree (p + q) ≤ max m n := (p.natDegree_add_le q).trans <| max_le_max ‹_› ‹_› @[simp] theorem leadingCoeff_zero : leadingCoeff (0 : R[X]) = 0 := rfl @[simp] theorem leadingCoeff_eq_zero : leadingCoeff p = 0 ↔ p = 0 := ⟨fun h => Classical.by_contradiction fun hp => mt mem_support_iff.1 (Classical.not_not.2 h) (mem_of_max (degree_eq_natDegree hp)), fun h => h.symm ▸ leadingCoeff_zero⟩ theorem leadingCoeff_ne_zero : leadingCoeff p ≠ 0 ↔ p ≠ 0 := by rw [Ne, leadingCoeff_eq_zero] theorem leadingCoeff_eq_zero_iff_deg_eq_bot : leadingCoeff p = 0 ↔ degree p = ⊥ := by rw [leadingCoeff_eq_zero, degree_eq_bot] theorem natDegree_C_mul_X_pow_le (a : R) (n : ℕ) : natDegree (C a * X ^ n) ≤ n := natDegree_le_iff_degree_le.2 <| degree_C_mul_X_pow_le _ _ theorem degree_erase_le (p : R[X]) (n : ℕ) : degree (p.erase n) ≤ degree p := by rcases p with ⟨p⟩ simp only [erase_def, degree, coeff, support] apply sup_mono rw [Finsupp.support_erase] apply Finset.erase_subset theorem degree_erase_lt (hp : p ≠ 0) : degree (p.erase (natDegree p)) < degree p := by apply lt_of_le_of_ne (degree_erase_le _ _) rw [degree_eq_natDegree hp, degree, support_erase] exact fun h => not_mem_erase _ _ (mem_of_max h) theorem degree_update_le (p : R[X]) (n : ℕ) (a : R) : degree (p.update n a) ≤ max (degree p) n := by classical rw [degree, support_update] split_ifs · exact (Finset.max_mono (erase_subset _ _)).trans (le_max_left _ _) · rw [max_insert, max_comm] exact le_rfl theorem degree_sum_le (s : Finset ι) (f : ι → R[X]) : degree (∑ i ∈ s, f i) ≤ s.sup fun b => degree (f b) := Finset.cons_induction_on s (by simp only [sum_empty, sup_empty, degree_zero, le_refl]) fun a s has ih => calc degree (∑ i ∈ cons a s has, f i) ≤ max (degree (f a)) (degree (∑ i ∈ s, f i)) := by rw [Finset.sum_cons]; exact degree_add_le _ _ _ ≤ _ := by rw [sup_cons]; exact max_le_max le_rfl ih theorem degree_mul_le (p q : R[X]) : degree (p * q) ≤ degree p + degree q := by simpa only [degree, ← support_toFinsupp, toFinsupp_mul] using AddMonoidAlgebra.sup_support_mul_le (WithBot.coe_add _ _).le _ _ theorem degree_mul_le_of_le {a b : WithBot ℕ} (hp : degree p ≤ a) (hq : degree q ≤ b) : degree (p * q) ≤ a + b := (p.degree_mul_le _).trans <| add_le_add ‹_› ‹_› theorem degree_pow_le (p : R[X]) : ∀ n : ℕ, degree (p ^ n) ≤ n • degree p | 0 => by rw [pow_zero, zero_nsmul]; exact degree_one_le | n + 1 => calc degree (p ^ (n + 1)) ≤ degree (p ^ n) + degree p := by rw [pow_succ]; exact degree_mul_le _ _ _ ≤ _ := by rw [succ_nsmul]; exact add_le_add_right (degree_pow_le _ _) _ theorem degree_pow_le_of_le {a : WithBot ℕ} (b : ℕ) (hp : degree p ≤ a) : degree (p ^ b) ≤ b * a := by induction b with | zero => simp [degree_one_le] | succ n hn => rw [Nat.cast_succ, add_mul, one_mul, pow_succ] exact degree_mul_le_of_le hn hp @[simp] theorem leadingCoeff_monomial (a : R) (n : ℕ) : leadingCoeff (monomial n a) = a := by classical by_cases ha : a = 0 · simp only [ha, (monomial n).map_zero, leadingCoeff_zero] · rw [leadingCoeff, natDegree_monomial, if_neg ha, coeff_monomial] simp theorem leadingCoeff_C_mul_X_pow (a : R) (n : ℕ) : leadingCoeff (C a * X ^ n) = a := by rw [C_mul_X_pow_eq_monomial, leadingCoeff_monomial] theorem leadingCoeff_C_mul_X (a : R) : leadingCoeff (C a * X) = a := by simpa only [pow_one] using leadingCoeff_C_mul_X_pow a 1 @[simp] theorem leadingCoeff_C (a : R) : leadingCoeff (C a) = a := leadingCoeff_monomial a 0 theorem leadingCoeff_X_pow (n : ℕ) : leadingCoeff ((X : R[X]) ^ n) = 1 := by simpa only [C_1, one_mul] using leadingCoeff_C_mul_X_pow (1 : R) n theorem leadingCoeff_X : leadingCoeff (X : R[X]) = 1 := by simpa only [pow_one] using @leadingCoeff_X_pow R _ 1 @[simp] theorem monic_X_pow (n : ℕ) : Monic (X ^ n : R[X]) := leadingCoeff_X_pow n @[simp] theorem monic_X : Monic (X : R[X]) := leadingCoeff_X theorem leadingCoeff_one : leadingCoeff (1 : R[X]) = 1 := leadingCoeff_C 1 @[simp] theorem monic_one : Monic (1 : R[X]) := leadingCoeff_C _ theorem Monic.ne_zero {R : Type*} [Semiring R] [Nontrivial R] {p : R[X]} (hp : p.Monic) : p ≠ 0 := by rintro rfl simp [Monic] at hp theorem Monic.ne_zero_of_ne (h : (0 : R) ≠ 1) {p : R[X]} (hp : p.Monic) : p ≠ 0 := by nontriviality R exact hp.ne_zero theorem Monic.ne_zero_of_polynomial_ne {r} (hp : Monic p) (hne : q ≠ r) : p ≠ 0 := haveI := Nontrivial.of_polynomial_ne hne hp.ne_zero theorem natDegree_mul_le {p q : R[X]} : natDegree (p * q) ≤ natDegree p + natDegree q := by apply natDegree_le_of_degree_le apply le_trans (degree_mul_le p q) rw [Nat.cast_add] apply add_le_add <;> apply degree_le_natDegree theorem natDegree_mul_le_of_le (hp : natDegree p ≤ m) (hg : natDegree q ≤ n) : natDegree (p * q) ≤ m + n := natDegree_mul_le.trans <| add_le_add ‹_› ‹_› theorem natDegree_pow_le {p : R[X]} {n : ℕ} : (p ^ n).natDegree ≤ n * p.natDegree := by induction n with | zero => simp | succ i hi => rw [pow_succ, Nat.succ_mul] apply le_trans natDegree_mul_le (add_le_add_right hi _) theorem natDegree_pow_le_of_le (n : ℕ) (hp : natDegree p ≤ m) : natDegree (p ^ n) ≤ n * m := natDegree_pow_le.trans (Nat.mul_le_mul le_rfl ‹_›) theorem natDegree_eq_zero_iff_degree_le_zero : p.natDegree = 0 ↔ p.degree ≤ 0 := by rw [← nonpos_iff_eq_zero, natDegree_le_iff_degree_le, Nat.cast_zero] theorem degree_zero_le : degree (0 : R[X]) ≤ 0 := natDegree_eq_zero_iff_degree_le_zero.mp rfl theorem degree_le_iff_coeff_zero (f : R[X]) (n : WithBot ℕ) : degree f ≤ n ↔ ∀ m : ℕ, n < m → coeff f m = 0 := by simp only [degree, Finset.max, Finset.sup_le_iff, mem_support_iff, Ne, ← not_le, not_imp_comm, Nat.cast_withBot] theorem degree_lt_iff_coeff_zero (f : R[X]) (n : ℕ) : degree f < n ↔ ∀ m : ℕ, n ≤ m → coeff f m = 0 := by simp only [degree, Finset.sup_lt_iff (WithBot.bot_lt_coe n), mem_support_iff, WithBot.coe_lt_coe, ← @not_le ℕ, max_eq_sup_coe, Nat.cast_withBot, Ne, not_imp_not] theorem natDegree_pos_iff_degree_pos : 0 < natDegree p ↔ 0 < degree p := lt_iff_lt_of_le_iff_le natDegree_le_iff_degree_le end Semiring section NontrivialSemiring variable [Semiring R] [Nontrivial R] {p q : R[X]} (n : ℕ) @[simp] theorem degree_X_pow : degree ((X : R[X]) ^ n) = n := by rw [X_pow_eq_monomial, degree_monomial _ (one_ne_zero' R)] @[simp] theorem natDegree_X_pow : natDegree ((X : R[X]) ^ n) = n := natDegree_eq_of_degree_eq_some (degree_X_pow n) end NontrivialSemiring section Ring variable [Ring R] {p q : R[X]} theorem degree_sub_le (p q : R[X]) : degree (p - q) ≤ max (degree p) (degree q) := by simpa only [degree_neg q] using degree_add_le p (-q) theorem degree_sub_le_of_le {a b : WithBot ℕ} (hp : degree p ≤ a) (hq : degree q ≤ b) : degree (p - q) ≤ max a b := (p.degree_sub_le q).trans <| max_le_max ‹_› ‹_› theorem natDegree_sub_le (p q : R[X]) : natDegree (p - q) ≤ max (natDegree p) (natDegree q) := by simpa only [← natDegree_neg q] using natDegree_add_le p (-q) theorem natDegree_sub_le_of_le (hp : natDegree p ≤ m) (hq : natDegree q ≤ n) : natDegree (p - q) ≤ max m n := (p.natDegree_sub_le q).trans <| max_le_max ‹_› ‹_› theorem degree_sub_lt (hd : degree p = degree q) (hp0 : p ≠ 0) (hlc : leadingCoeff p = leadingCoeff q) : degree (p - q) < degree p := have hp : monomial (natDegree p) (leadingCoeff p) + p.erase (natDegree p) = p := monomial_add_erase _ _ have hq : monomial (natDegree q) (leadingCoeff q) + q.erase (natDegree q) = q := monomial_add_erase _ _ have hd' : natDegree p = natDegree q := by unfold natDegree; rw [hd] have hq0 : q ≠ 0 := mt degree_eq_bot.2 (hd ▸ mt degree_eq_bot.1 hp0) calc degree (p - q) = degree (erase (natDegree q) p + -erase (natDegree q) q) := by conv =>
lhs rw [← hp, ← hq, hlc, hd', add_sub_add_left_eq_sub, sub_eq_add_neg]
Mathlib/Algebra/Polynomial/Degree/Definitions.lean
556
557
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Data.Matrix.Mul import Mathlib.Data.PEquiv /-! # partial equivalences for matrices Using partial equivalences to represent matrices. This file introduces the function `PEquiv.toMatrix`, which returns a matrix containing ones and zeros. For any partial equivalence `f`, `f.toMatrix i j = 1 ↔ f i = some j`. The following important properties of this function are proved `toMatrix_trans : (f.trans g).toMatrix = f.toMatrix * g.toMatrix` `toMatrix_symm : f.symm.toMatrix = f.toMatrixᵀ` `toMatrix_refl : (PEquiv.refl n).toMatrix = 1` `toMatrix_bot : ⊥.toMatrix = 0` This theory gives the matrix representation of projection linear maps, and their right inverses. For example, the matrix `(single (0 : Fin 1) (i : Fin n)).toMatrix` corresponds to the ith projection map from R^n to R. Any injective function `Fin m → Fin n` gives rise to a `PEquiv`, whose matrix is the projection map from R^m → R^n represented by the same function. The transpose of this matrix is the right inverse of this map, sending anything not in the image to zero. ## notations This file uses `ᵀ` for `Matrix.transpose`. -/ assert_not_exists Field namespace PEquiv open Matrix universe u v variable {k l m n : Type*} variable {α β : Type*} open Matrix /-- `toMatrix` returns a matrix containing ones and zeros. `f.toMatrix i j` is `1` if `f i = some j` and `0` otherwise -/ def toMatrix [DecidableEq n] [Zero α] [One α] (f : m ≃. n) : Matrix m n α := of fun i j => if j ∈ f i then (1 : α) else 0 -- TODO: set as an equation lemma for `toMatrix`, see https://github.com/leanprover-community/mathlib4/pull/3024 @[simp] theorem toMatrix_apply [DecidableEq n] [Zero α] [One α] (f : m ≃. n) (i j) : toMatrix f i j = if j ∈ f i then (1 : α) else 0 := rfl theorem toMatrix_mul_apply [Fintype m] [DecidableEq m] [NonAssocSemiring α] (f : l ≃. m) (i j) (M : Matrix m n α) : (f.toMatrix * M :) i j = Option.casesOn (f i) 0 fun fi => M fi j := by dsimp [toMatrix, Matrix.mul_apply] rcases h : f i with - | fi · simp [h] · rw [Finset.sum_eq_single fi] <;> simp +contextual [h, eq_comm] @[deprecated (since := "2025-01-27")] alias mul_matrix_apply := toMatrix_mul_apply theorem mul_toMatrix_apply [Fintype m] [NonAssocSemiring α] [DecidableEq n] (M : Matrix l m α) (f : m ≃. n) (i j) : (M * f.toMatrix :) i j = Option.casesOn (f.symm j) 0 (M i) := by
dsimp [Matrix.mul_apply, toMatrix_apply] rcases h : f.symm j with - | fj · simp [h, ← f.eq_some_iff] · rw [Finset.sum_eq_single fj] · simp [h, ← f.eq_some_iff]
Mathlib/Data/Matrix/PEquiv.lean
70
74
/- Copyright (c) 2019 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.Group.Units.Equiv import Mathlib.CategoryTheory.Endomorphism import Mathlib.CategoryTheory.HomCongr /-! # Conjugate morphisms by isomorphisms An isomorphism `α : X ≅ Y` defines - a monoid isomorphism `CategoryTheory.Iso.conj : End X ≃* End Y` by `α.conj f = α.inv ≫ f ≫ α.hom`; - a group isomorphism `CategoryTheory.Iso.conjAut : Aut X ≃* Aut Y` by `α.conjAut f = α.symm ≪≫ f ≪≫ α` using `CategoryTheory.Iso.homCongr : (X ≅ X₁) → (Y ≅ Y₁) → (X ⟶ Y) ≃ (X₁ ⟶ Y₁)` and `CategoryTheory.Iso.isoCongr : (f : X₁ ≅ X₂) → (g : Y₁ ≅ Y₂) → (X₁ ≅ Y₁) ≃ (X₂ ≅ Y₂)` which are defined in `CategoryTheory.HomCongr`. -/ universe v u namespace CategoryTheory namespace Iso variable {C : Type u} [Category.{v} C] variable {X Y : C} (α : X ≅ Y) /-- An isomorphism between two objects defines a monoid isomorphism between their monoid of endomorphisms. -/ def conj : End X ≃* End Y := { homCongr α α with map_mul' := fun f g => homCongr_comp α α α g f } theorem conj_apply (f : End X) : α.conj f = α.inv ≫ f ≫ α.hom := rfl @[simp] theorem conj_comp (f g : End X) : α.conj (f ≫ g) = α.conj f ≫ α.conj g := map_mul α.conj g f @[simp] theorem conj_id : α.conj (𝟙 X) = 𝟙 Y := map_one α.conj @[simp] theorem refl_conj (f : End X) : (Iso.refl X).conj f = f := by rw [conj_apply, Iso.refl_inv, Iso.refl_hom, Category.id_comp, Category.comp_id] @[simp] theorem trans_conj {Z : C} (β : Y ≅ Z) (f : End X) : (α ≪≫ β).conj f = β.conj (α.conj f) := homCongr_trans α α β β f @[simp] theorem symm_self_conj (f : End X) : α.symm.conj (α.conj f) = f := by rw [← trans_conj, α.self_symm_id, refl_conj] @[simp] theorem self_symm_conj (f : End Y) : α.conj (α.symm.conj f) = f := α.symm.symm_self_conj f @[simp] theorem conj_pow (f : End X) (n : ℕ) : α.conj (f ^ n) = α.conj f ^ n := α.conj.toMonoidHom.map_pow f n -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: change definition so that `conjAut_apply` becomes a `rfl`? /-- `conj` defines a group isomorphisms between groups of automorphisms -/ def conjAut : Aut X ≃* Aut Y := (Aut.unitsEndEquivAut X).symm.trans <| (Units.mapEquiv α.conj).trans <| Aut.unitsEndEquivAut Y theorem conjAut_apply (f : Aut X) : α.conjAut f = α.symm ≪≫ f ≪≫ α := by aesop_cat @[simp] theorem conjAut_hom (f : Aut X) : (α.conjAut f).hom = α.conj f.hom := rfl @[simp] theorem trans_conjAut {Z : C} (β : Y ≅ Z) (f : Aut X) : (α ≪≫ β).conjAut f = β.conjAut (α.conjAut f) := by simp only [conjAut_apply, Iso.trans_symm, Iso.trans_assoc] @[simp] theorem conjAut_mul (f g : Aut X) : α.conjAut (f * g) = α.conjAut f * α.conjAut g := map_mul α.conjAut f g @[simp] theorem conjAut_trans (f g : Aut X) : α.conjAut (f ≪≫ g) = α.conjAut f ≪≫ α.conjAut g := conjAut_mul α g f @[simp] theorem conjAut_pow (f : Aut X) (n : ℕ) : α.conjAut (f ^ n) = α.conjAut f ^ n := map_pow α.conjAut f n @[simp] theorem conjAut_zpow (f : Aut X) (n : ℤ) : α.conjAut (f ^ n) = α.conjAut f ^ n := map_zpow α.conjAut f n end Iso namespace Functor universe v₁ u₁ variable {C : Type u} [Category.{v} C] {D : Type u₁} [Category.{v₁} D] (F : C ⥤ D) theorem map_conj {X Y : C} (α : X ≅ Y) (f : End X) : F.map (α.conj f) = (F.mapIso α).conj (F.map f) := map_homCongr F α α f
theorem map_conjAut (F : C ⥤ D) {X Y : C} (α : X ≅ Y) (f : Aut X) : F.mapIso (α.conjAut f) = (F.mapIso α).conjAut (F.mapIso f) := by
Mathlib/CategoryTheory/Conj.lean
114
115
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro -/ import Mathlib.Algebra.BigOperators.Ring.List import Mathlib.Data.Nat.GCD.Basic import Mathlib.Data.Nat.Prime.Basic import Mathlib.Data.List.Prime import Mathlib.Data.List.Sort import Mathlib.Data.List.Perm.Subperm /-! # Prime numbers This file deals with the factors of natural numbers. ## Important declarations - `Nat.factors n`: the prime factorization of `n` - `Nat.factors_unique`: uniqueness of the prime factorisation -/ assert_not_exists Multiset open Bool Subtype open Nat namespace Nat /-- `primeFactorsList n` is the prime factorization of `n`, listed in increasing order. -/ def primeFactorsList : ℕ → List ℕ | 0 => [] | 1 => [] | k + 2 => let m := minFac (k + 2) m :: primeFactorsList ((k + 2) / m) decreasing_by exact factors_lemma @[simp] theorem primeFactorsList_zero : primeFactorsList 0 = [] := by rw [primeFactorsList] @[simp] theorem primeFactorsList_one : primeFactorsList 1 = [] := by rw [primeFactorsList] @[simp] theorem primeFactorsList_two : primeFactorsList 2 = [2] := by simp [primeFactorsList] theorem prime_of_mem_primeFactorsList {n : ℕ} : ∀ {p : ℕ}, p ∈ primeFactorsList n → Prime p := by match n with | 0 => simp | 1 => simp | k + 2 => intro p h let m := minFac (k + 2) have : (k + 2) / m < (k + 2) := factors_lemma have h₁ : p = m ∨ p ∈ primeFactorsList ((k + 2) / m) := List.mem_cons.1 (by rwa [primeFactorsList] at h) exact Or.casesOn h₁ (fun h₂ => h₂.symm ▸ minFac_prime (by simp)) prime_of_mem_primeFactorsList theorem pos_of_mem_primeFactorsList {n p : ℕ} (h : p ∈ primeFactorsList n) : 0 < p := Prime.pos (prime_of_mem_primeFactorsList h) theorem prod_primeFactorsList : ∀ {n}, n ≠ 0 → List.prod (primeFactorsList n) = n | 0 => by simp | 1 => by simp | k + 2 => fun _ => let m := minFac (k + 2) have : (k + 2) / m < (k + 2) := factors_lemma show (primeFactorsList (k + 2)).prod = (k + 2) by have h₁ : (k + 2) / m ≠ 0 := fun h => by have : (k + 2) = 0 * m := (Nat.div_eq_iff_eq_mul_left (minFac_pos _) (minFac_dvd _)).1 h rw [zero_mul] at this; exact (show k + 2 ≠ 0 by simp) this rw [primeFactorsList, List.prod_cons, prod_primeFactorsList h₁, Nat.mul_div_cancel' (minFac_dvd _)] theorem primeFactorsList_prime {p : ℕ} (hp : Nat.Prime p) : p.primeFactorsList = [p] := by have : p = p - 2 + 2 := Nat.eq_add_of_sub_eq hp.two_le rfl rw [this, primeFactorsList] simp only [Eq.symm this] have : Nat.minFac p = p := (Nat.prime_def_minFac.mp hp).2 simp only [this, primeFactorsList, Nat.div_self (Nat.Prime.pos hp)] theorem primeFactorsList_chain {n : ℕ} : ∀ {a}, (∀ p, Prime p → p ∣ n → a ≤ p) → List.Chain (· ≤ ·) a (primeFactorsList n) := by match n with | 0 => simp | 1 => simp | k + 2 => intro a h let m := minFac (k + 2) have : (k + 2) / m < (k + 2) := factors_lemma rw [primeFactorsList] refine List.Chain.cons ((le_minFac.2 h).resolve_left (by simp)) (primeFactorsList_chain ?_) exact fun p pp d => minFac_le_of_dvd pp.two_le (d.trans <| div_dvd_of_dvd <| minFac_dvd _) theorem primeFactorsList_chain_2 (n) : List.Chain (· ≤ ·) 2 (primeFactorsList n) := primeFactorsList_chain fun _ pp _ => pp.two_le theorem primeFactorsList_chain' (n) : List.Chain' (· ≤ ·) (primeFactorsList n) := @List.Chain'.tail _ _ (_ :: _) (primeFactorsList_chain_2 _) theorem primeFactorsList_sorted (n : ℕ) : List.Sorted (· ≤ ·) (primeFactorsList n) := List.chain'_iff_pairwise.1 (primeFactorsList_chain' _) /-- `primeFactorsList` can be constructed inductively by extracting `minFac`, for sufficiently large `n`. -/ theorem primeFactorsList_add_two (n : ℕ) : primeFactorsList (n + 2) = minFac (n + 2) :: primeFactorsList ((n + 2) / minFac (n + 2)) := by rw [primeFactorsList] @[simp] theorem primeFactorsList_eq_nil (n : ℕ) : n.primeFactorsList = [] ↔ n = 0 ∨ n = 1 := by constructor <;> intro h · rcases n with (_ | _ | n) · exact Or.inl rfl · exact Or.inr rfl · rw [primeFactorsList] at h injection h · rcases h with (rfl | rfl) · exact primeFactorsList_zero · exact primeFactorsList_one open scoped List in theorem eq_of_perm_primeFactorsList {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) (h : a.primeFactorsList ~ b.primeFactorsList) : a = b := by simpa [prod_primeFactorsList ha, prod_primeFactorsList hb] using List.Perm.prod_eq h section open List theorem mem_primeFactorsList_iff_dvd {n p : ℕ} (hn : n ≠ 0) (hp : Prime p) : p ∈ primeFactorsList n ↔ p ∣ n where mp h := prod_primeFactorsList hn ▸ List.dvd_prod h mpr h := mem_list_primes_of_dvd_prod (prime_iff.mp hp) (fun _ h ↦ prime_iff.mp (prime_of_mem_primeFactorsList h)) ((prod_primeFactorsList hn).symm ▸ h) theorem dvd_of_mem_primeFactorsList {n p : ℕ} (h : p ∈ n.primeFactorsList) : p ∣ n := by rcases n.eq_zero_or_pos with (rfl | hn) · exact dvd_zero p · rwa [← mem_primeFactorsList_iff_dvd hn.ne' (prime_of_mem_primeFactorsList h)] theorem mem_primeFactorsList {n p} (hn : n ≠ 0) : p ∈ primeFactorsList n ↔ Prime p ∧ p ∣ n := ⟨fun h => ⟨prime_of_mem_primeFactorsList h, dvd_of_mem_primeFactorsList h⟩, fun ⟨hprime, hdvd⟩ => (mem_primeFactorsList_iff_dvd hn hprime).mpr hdvd⟩ @[simp] lemma mem_primeFactorsList' {n p} : p ∈ n.primeFactorsList ↔ p.Prime ∧ p ∣ n ∧ n ≠ 0 := by cases n <;> simp [mem_primeFactorsList, *] theorem le_of_mem_primeFactorsList {n p : ℕ} (h : p ∈ n.primeFactorsList) : p ≤ n := by rcases n.eq_zero_or_pos with (rfl | hn) · rw [primeFactorsList_zero] at h cases h · exact le_of_dvd hn (dvd_of_mem_primeFactorsList h) /-- **Fundamental theorem of arithmetic** -/ theorem primeFactorsList_unique {n : ℕ} {l : List ℕ} (h₁ : prod l = n) (h₂ : ∀ p ∈ l, Prime p) : l ~ primeFactorsList n := by refine perm_of_prod_eq_prod ?_ ?_ ?_ · rw [h₁] refine (prod_primeFactorsList ?_).symm rintro rfl
rw [prod_eq_zero_iff] at h₁ exact Prime.ne_zero (h₂ 0 h₁) rfl · simp_rw [← prime_iff] exact h₂ · simp_rw [← prime_iff]
Mathlib/Data/Nat/Factors.lean
166
170
/- 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 theorem le_one_div (ha : 0 < a) (hb : 0 < b) : a ≤ 1 / b ↔ b ≤ 1 / a := by simpa using le_inv_comm₀ ha hb theorem lt_one_div (ha : 0 < a) (hb : 0 < b) : a < 1 / b ↔ b < 1 / a := by simpa using lt_inv_comm₀ ha hb @[bound] lemma Bound.one_lt_div_of_pos_of_lt (b0 : 0 < b) : b < a → 1 < a / b := (one_lt_div b0).mpr @[bound] lemma Bound.div_lt_one_of_pos_of_lt (b0 : 0 < b) : a < b → a / b < 1 := (div_lt_one b0).mpr /-! ### Relating two divisions, involving `1` -/ theorem one_div_le_one_div_of_le (ha : 0 < a) (h : a ≤ b) : 1 / b ≤ 1 / a := by simpa using inv_anti₀ ha h theorem one_div_lt_one_div_of_lt (ha : 0 < a) (h : a < b) : 1 / b < 1 / a := by rwa [lt_div_iff₀' ha, ← div_eq_mul_one_div, div_lt_one (ha.trans h)] theorem le_of_one_div_le_one_div (ha : 0 < a) (h : 1 / a ≤ 1 / b) : b ≤ a := le_imp_le_of_lt_imp_lt (one_div_lt_one_div_of_lt ha) h theorem lt_of_one_div_lt_one_div (ha : 0 < a) (h : 1 / a < 1 / b) : b < a := lt_imp_lt_of_le_imp_le (one_div_le_one_div_of_le ha) h /-- For the single implications with fewer assumptions, see `one_div_le_one_div_of_le` and `le_of_one_div_le_one_div` -/ theorem one_div_le_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a ≤ 1 / b ↔ b ≤ a := div_le_div_iff_of_pos_left zero_lt_one ha hb /-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_lt` and `lt_of_one_div_lt_one_div` -/ theorem one_div_lt_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a < 1 / b ↔ b < a := div_lt_div_iff_of_pos_left zero_lt_one ha hb theorem one_lt_one_div (h1 : 0 < a) (h2 : a < 1) : 1 < 1 / a := by rwa [lt_one_div (@zero_lt_one α _ _ _ _ _) h1, one_div_one] theorem one_le_one_div (h1 : 0 < a) (h2 : a ≤ 1) : 1 ≤ 1 / a := by rwa [le_one_div (@zero_lt_one α _ _ _ _ _) h1, one_div_one] /-! ### Results about halving. The equalities also hold in semifields of characteristic `0`. -/ theorem half_pos (h : 0 < a) : 0 < a / 2 := div_pos h zero_lt_two theorem one_half_pos : (0 : α) < 1 / 2 := half_pos zero_lt_one @[simp] theorem half_le_self_iff : a / 2 ≤ a ↔ 0 ≤ a := by rw [div_le_iff₀ (zero_lt_two' α), mul_two, le_add_iff_nonneg_left] @[simp] theorem half_lt_self_iff : a / 2 < a ↔ 0 < a := by rw [div_lt_iff₀ (zero_lt_two' α), mul_two, lt_add_iff_pos_left] alias ⟨_, half_le_self⟩ := half_le_self_iff alias ⟨_, half_lt_self⟩ := half_lt_self_iff alias div_two_lt_of_pos := half_lt_self theorem one_half_lt_one : (1 / 2 : α) < 1 := half_lt_self zero_lt_one theorem two_inv_lt_one : (2⁻¹ : α) < 1 := (one_div _).symm.trans_lt one_half_lt_one theorem left_lt_add_div_two : a < (a + b) / 2 ↔ a < b := by simp [lt_div_iff₀, mul_two] theorem add_div_two_lt_right : (a + b) / 2 < b ↔ a < b := by simp [div_lt_iff₀, mul_two] theorem add_thirds (a : α) : a / 3 + a / 3 + a / 3 = a := by rw [div_add_div_same, div_add_div_same, ← two_mul, ← add_one_mul 2 a, two_add_one_eq_three, mul_div_cancel_left₀ a three_ne_zero] /-! ### Miscellaneous lemmas -/ @[simp] lemma div_pos_iff_of_pos_left (ha : 0 < a) : 0 < a / b ↔ 0 < b := by simp only [div_eq_mul_inv, mul_pos_iff_of_pos_left ha, inv_pos] @[simp] lemma div_pos_iff_of_pos_right (hb : 0 < b) : 0 < a / b ↔ 0 < a := by simp only [div_eq_mul_inv, mul_pos_iff_of_pos_right (inv_pos.2 hb)] theorem mul_le_mul_of_mul_div_le (h : a * (b / c) ≤ d) (hc : 0 < c) : b * a ≤ d * c := by rw [← mul_div_assoc] at h rwa [mul_comm b, ← div_le_iff₀ hc] theorem div_mul_le_div_mul_of_div_le_div (h : a / b ≤ c / d) (he : 0 ≤ e) : a / (b * e) ≤ c / (d * e) := by rw [div_mul_eq_div_mul_one_div, div_mul_eq_div_mul_one_div] exact mul_le_mul_of_nonneg_right h (one_div_nonneg.2 he) theorem exists_pos_mul_lt {a : α} (h : 0 < a) (b : α) : ∃ c : α, 0 < c ∧ b * c < a := by have : 0 < a / max (b + 1) 1 := div_pos h (lt_max_iff.2 (Or.inr zero_lt_one)) refine ⟨a / max (b + 1) 1, this, ?_⟩ rw [← lt_div_iff₀ this, div_div_cancel₀ h.ne'] exact lt_max_iff.2 (Or.inl <| lt_add_one _) theorem exists_pos_lt_mul {a : α} (h : 0 < a) (b : α) : ∃ c : α, 0 < c ∧ b < c * a := let ⟨c, hc₀, hc⟩ := exists_pos_mul_lt h b; ⟨c⁻¹, inv_pos.2 hc₀, by rwa [← div_eq_inv_mul, lt_div_iff₀ hc₀]⟩ lemma monotone_div_right_of_nonneg (ha : 0 ≤ a) : Monotone (· / a) := fun _b _c hbc ↦ div_le_div_of_nonneg_right hbc ha lemma strictMono_div_right_of_pos (ha : 0 < a) : StrictMono (· / a) := fun _b _c hbc ↦ div_lt_div_of_pos_right hbc ha theorem Monotone.div_const {β : Type*} [Preorder β] {f : β → α} (hf : Monotone f) {c : α} (hc : 0 ≤ c) : Monotone fun x => f x / c := (monotone_div_right_of_nonneg hc).comp hf theorem StrictMono.div_const {β : Type*} [Preorder β] {f : β → α} (hf : StrictMono f) {c : α} (hc : 0 < c) : StrictMono fun x => f x / c := by simpa only [div_eq_mul_inv] using hf.mul_const (inv_pos.2 hc) -- see Note [lower instance priority] instance (priority := 100) LinearOrderedSemiField.toDenselyOrdered : DenselyOrdered α where dense a₁ a₂ h := ⟨(a₁ + a₂) / 2, calc a₁ = (a₁ + a₁) / 2 := (add_self_div_two a₁).symm _ < (a₁ + a₂) / 2 := div_lt_div_of_pos_right (add_lt_add_left h _) zero_lt_two , calc (a₁ + a₂) / 2 < (a₂ + a₂) / 2 := div_lt_div_of_pos_right (add_lt_add_right h _) zero_lt_two _ = a₂ := add_self_div_two a₂ ⟩ theorem min_div_div_right {c : α} (hc : 0 ≤ c) (a b : α) : min (a / c) (b / c) = min a b / c := (monotone_div_right_of_nonneg hc).map_min.symm theorem max_div_div_right {c : α} (hc : 0 ≤ c) (a b : α) : max (a / c) (b / c) = max a b / c := (monotone_div_right_of_nonneg hc).map_max.symm theorem one_div_strictAntiOn : StrictAntiOn (fun x : α => 1 / x) (Set.Ioi 0) := fun _ x1 _ y1 xy => (one_div_lt_one_div (Set.mem_Ioi.mp y1) (Set.mem_Ioi.mp x1)).mpr xy theorem one_div_pow_le_one_div_pow_of_le (a1 : 1 ≤ a) {m n : ℕ} (mn : m ≤ n) : 1 / a ^ n ≤ 1 / a ^ m := by refine (one_div_le_one_div ?_ ?_).mpr (pow_right_mono₀ a1 mn) <;> exact pow_pos (zero_lt_one.trans_le a1) _ theorem one_div_pow_lt_one_div_pow_of_lt (a1 : 1 < a) {m n : ℕ} (mn : m < n) : 1 / a ^ n < 1 / a ^ m := by refine (one_div_lt_one_div ?_ ?_).2 (pow_lt_pow_right₀ a1 mn) <;> exact pow_pos (zero_lt_one.trans a1) _ theorem one_div_pow_anti (a1 : 1 ≤ a) : Antitone fun n : ℕ => 1 / a ^ n := fun _ _ => one_div_pow_le_one_div_pow_of_le a1 theorem one_div_pow_strictAnti (a1 : 1 < a) : StrictAnti fun n : ℕ => 1 / a ^ n := fun _ _ => one_div_pow_lt_one_div_pow_of_lt a1 theorem inv_strictAntiOn : StrictAntiOn (fun x : α => x⁻¹) (Set.Ioi 0) := fun _ hx _ hy xy => (inv_lt_inv₀ hy hx).2 xy theorem inv_pow_le_inv_pow_of_le (a1 : 1 ≤ a) {m n : ℕ} (mn : m ≤ n) : (a ^ n)⁻¹ ≤ (a ^ m)⁻¹ := by convert one_div_pow_le_one_div_pow_of_le a1 mn using 1 <;> simp theorem inv_pow_lt_inv_pow_of_lt (a1 : 1 < a) {m n : ℕ} (mn : m < n) : (a ^ n)⁻¹ < (a ^ m)⁻¹ := by convert one_div_pow_lt_one_div_pow_of_lt a1 mn using 1 <;> simp theorem inv_pow_anti (a1 : 1 ≤ a) : Antitone fun n : ℕ => (a ^ n)⁻¹ := fun _ _ => inv_pow_le_inv_pow_of_le a1 theorem inv_pow_strictAnti (a1 : 1 < a) : StrictAnti fun n : ℕ => (a ^ n)⁻¹ := fun _ _ => inv_pow_lt_inv_pow_of_lt a1 theorem le_iff_forall_one_lt_le_mul₀ {α : Type*} [Semifield α] [LinearOrder α] [IsStrictOrderedRing α] {a b : α} (hb : 0 ≤ b) : a ≤ b ↔ ∀ ε, 1 < ε → a ≤ b * ε := by refine ⟨fun h _ hε ↦ h.trans <| le_mul_of_one_le_right hb hε.le, fun h ↦ ?_⟩ obtain rfl|hb := hb.eq_or_lt · simp_rw [zero_mul] at h exact h 2 one_lt_two refine le_of_forall_gt_imp_ge_of_dense fun x hbx => ?_ convert h (x / b) ((one_lt_div hb).mpr hbx) rw [mul_div_cancel₀ _ hb.ne'] /-! ### Results about `IsGLB` -/ theorem IsGLB.mul_left {s : Set α} (ha : 0 ≤ a) (hs : IsGLB s b) : IsGLB ((fun b => a * b) '' s) (a * b) := by rcases lt_or_eq_of_le ha with (ha | rfl) · exact (OrderIso.mulLeft₀ _ ha).isGLB_image'.2 hs · simp_rw [zero_mul] rw [hs.nonempty.image_const] exact isGLB_singleton theorem IsGLB.mul_right {s : Set α} (ha : 0 ≤ a) (hs : IsGLB s b) : IsGLB ((fun b => b * a) '' s) (b * a) := by simpa [mul_comm] using hs.mul_left ha end LinearOrderedSemifield section variable [Field α] [LinearOrder α] [IsStrictOrderedRing α] {a b c d : α} {n : ℤ} /-! ### Lemmas about pos, nonneg, nonpos, neg -/ theorem div_pos_iff : 0 < a / b ↔ 0 < a ∧ 0 < b ∨ a < 0 ∧ b < 0 := by simp only [division_def, mul_pos_iff, inv_pos, inv_lt_zero] theorem div_neg_iff : a / b < 0 ↔ 0 < a ∧ b < 0 ∨ a < 0 ∧ 0 < b := by simp [division_def, mul_neg_iff] theorem div_nonneg_iff : 0 ≤ a / b ↔ 0 ≤ a ∧ 0 ≤ b ∨ a ≤ 0 ∧ b ≤ 0 := by simp [division_def, mul_nonneg_iff] theorem div_nonpos_iff : a / b ≤ 0 ↔ 0 ≤ a ∧ b ≤ 0 ∨ a ≤ 0 ∧ 0 ≤ b := by simp [division_def, mul_nonpos_iff] theorem div_nonneg_of_nonpos (ha : a ≤ 0) (hb : b ≤ 0) : 0 ≤ a / b := div_nonneg_iff.2 <| Or.inr ⟨ha, hb⟩ theorem div_pos_of_neg_of_neg (ha : a < 0) (hb : b < 0) : 0 < a / b := div_pos_iff.2 <| Or.inr ⟨ha, hb⟩ theorem div_neg_of_neg_of_pos (ha : a < 0) (hb : 0 < b) : a / b < 0 := div_neg_iff.2 <| Or.inr ⟨ha, hb⟩ theorem div_neg_of_pos_of_neg (ha : 0 < a) (hb : b < 0) : a / b < 0 := div_neg_iff.2 <| Or.inl ⟨ha, hb⟩ /-! ### Relating one division with another term -/ theorem div_le_iff_of_neg (hc : c < 0) : b / c ≤ a ↔ a * c ≤ b := ⟨fun h => div_mul_cancel₀ b (ne_of_lt hc) ▸ mul_le_mul_of_nonpos_right h hc.le, fun h => calc a = a * c * (1 / c) := mul_mul_div a (ne_of_lt hc) _ ≥ b * (1 / c) := mul_le_mul_of_nonpos_right h (one_div_neg.2 hc).le _ = b / c := (div_eq_mul_one_div b c).symm ⟩ theorem div_le_iff_of_neg' (hc : c < 0) : b / c ≤ a ↔ c * a ≤ b := by rw [mul_comm, div_le_iff_of_neg hc] theorem le_div_iff_of_neg (hc : c < 0) : a ≤ b / c ↔ b ≤ a * c := by rw [← neg_neg c, mul_neg, div_neg, le_neg, div_le_iff₀ (neg_pos.2 hc), neg_mul] theorem le_div_iff_of_neg' (hc : c < 0) : a ≤ b / c ↔ b ≤ c * a := by rw [mul_comm, le_div_iff_of_neg hc] theorem div_lt_iff_of_neg (hc : c < 0) : b / c < a ↔ a * c < b := lt_iff_lt_of_le_iff_le <| le_div_iff_of_neg hc theorem div_lt_iff_of_neg' (hc : c < 0) : b / c < a ↔ c * a < b := by rw [mul_comm, div_lt_iff_of_neg hc] theorem lt_div_iff_of_neg (hc : c < 0) : a < b / c ↔ b < a * c := lt_iff_lt_of_le_iff_le <| div_le_iff_of_neg hc theorem lt_div_iff_of_neg' (hc : c < 0) : a < b / c ↔ b < c * a := by rw [mul_comm, lt_div_iff_of_neg hc] theorem div_le_one_of_ge (h : b ≤ a) (hb : b ≤ 0) : a / b ≤ 1 := by simpa only [neg_div_neg_eq] using div_le_one_of_le₀ (neg_le_neg h) (neg_nonneg_of_nonpos hb) /-! ### Bi-implications of inequalities using inversions -/ theorem inv_le_inv_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ ≤ b⁻¹ ↔ b ≤ a := by rw [← one_div, div_le_iff_of_neg ha, ← div_eq_inv_mul, div_le_iff_of_neg hb, one_mul] theorem inv_le_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ ≤ b ↔ b⁻¹ ≤ a := by rw [← inv_le_inv_of_neg hb (inv_lt_zero.2 ha), inv_inv] theorem le_inv_of_neg (ha : a < 0) (hb : b < 0) : a ≤ b⁻¹ ↔ b ≤ a⁻¹ := by rw [← inv_le_inv_of_neg (inv_lt_zero.2 hb) ha, inv_inv] theorem inv_lt_inv_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ < b⁻¹ ↔ b < a := lt_iff_lt_of_le_iff_le (inv_le_inv_of_neg hb ha) theorem inv_lt_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ < b ↔ b⁻¹ < a := lt_iff_lt_of_le_iff_le (le_inv_of_neg hb ha) theorem lt_inv_of_neg (ha : a < 0) (hb : b < 0) : a < b⁻¹ ↔ b < a⁻¹ := lt_iff_lt_of_le_iff_le (inv_le_of_neg hb ha) /-! ### Monotonicity results involving inversion -/ theorem sub_inv_antitoneOn_Ioi : AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Ioi c) := antitoneOn_iff_forall_lt.mpr fun _ ha _ hb hab ↦ inv_le_inv₀ (sub_pos.mpr hb) (sub_pos.mpr ha) |>.mpr <| sub_le_sub (le_of_lt hab) le_rfl theorem sub_inv_antitoneOn_Iio : AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Iio c) := antitoneOn_iff_forall_lt.mpr fun _ ha _ hb hab ↦ inv_le_inv_of_neg (sub_neg.mpr hb) (sub_neg.mpr ha) |>.mpr <| sub_le_sub (le_of_lt hab) le_rfl theorem sub_inv_antitoneOn_Icc_right (ha : c < a) : AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Icc a b) := by by_cases hab : a ≤ b · exact sub_inv_antitoneOn_Ioi.mono <| (Set.Icc_subset_Ioi_iff hab).mpr ha · simp [hab, Set.Subsingleton.antitoneOn] theorem sub_inv_antitoneOn_Icc_left (ha : b < c) : AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Icc a b) := by by_cases hab : a ≤ b · exact sub_inv_antitoneOn_Iio.mono <| (Set.Icc_subset_Iio_iff hab).mpr ha · simp [hab, Set.Subsingleton.antitoneOn] theorem inv_antitoneOn_Ioi : AntitoneOn (fun x : α ↦ x⁻¹) (Set.Ioi 0) := by convert sub_inv_antitoneOn_Ioi (α := α) exact (sub_zero _).symm theorem inv_antitoneOn_Iio : AntitoneOn (fun x : α ↦ x⁻¹) (Set.Iio 0) := by convert sub_inv_antitoneOn_Iio (α := α) exact (sub_zero _).symm theorem inv_antitoneOn_Icc_right (ha : 0 < a) : AntitoneOn (fun x : α ↦ x⁻¹) (Set.Icc a b) := by convert sub_inv_antitoneOn_Icc_right ha exact (sub_zero _).symm theorem inv_antitoneOn_Icc_left (hb : b < 0) : AntitoneOn (fun x : α ↦ x⁻¹) (Set.Icc a b) := by convert sub_inv_antitoneOn_Icc_left hb exact (sub_zero _).symm /-! ### Relating two divisions -/ theorem div_le_div_of_nonpos_of_le (hc : c ≤ 0) (h : b ≤ a) : a / c ≤ b / c := by rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c] exact mul_le_mul_of_nonpos_right h (one_div_nonpos.2 hc) theorem div_lt_div_of_neg_of_lt (hc : c < 0) (h : b < a) : a / c < b / c := by rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c] exact mul_lt_mul_of_neg_right h (one_div_neg.2 hc) theorem div_le_div_right_of_neg (hc : c < 0) : a / c ≤ b / c ↔ b ≤ a := ⟨le_imp_le_of_lt_imp_lt <| div_lt_div_of_neg_of_lt hc, div_le_div_of_nonpos_of_le <| hc.le⟩ theorem div_lt_div_right_of_neg (hc : c < 0) : a / c < b / c ↔ b < a := lt_iff_lt_of_le_iff_le <| div_le_div_right_of_neg hc /-! ### Relating one division and involving `1` -/ theorem one_le_div_of_neg (hb : b < 0) : 1 ≤ a / b ↔ a ≤ b := by rw [le_div_iff_of_neg hb, one_mul] theorem div_le_one_of_neg (hb : b < 0) : a / b ≤ 1 ↔ b ≤ a := by rw [div_le_iff_of_neg hb, one_mul] theorem one_lt_div_of_neg (hb : b < 0) : 1 < a / b ↔ a < b := by rw [lt_div_iff_of_neg hb, one_mul] theorem div_lt_one_of_neg (hb : b < 0) : a / b < 1 ↔ b < a := by rw [div_lt_iff_of_neg hb, one_mul] theorem one_div_le_of_neg (ha : a < 0) (hb : b < 0) : 1 / a ≤ b ↔ 1 / b ≤ a := by simpa using inv_le_of_neg ha hb theorem one_div_lt_of_neg (ha : a < 0) (hb : b < 0) : 1 / a < b ↔ 1 / b < a := by simpa using inv_lt_of_neg ha hb theorem le_one_div_of_neg (ha : a < 0) (hb : b < 0) : a ≤ 1 / b ↔ b ≤ 1 / a := by simpa using le_inv_of_neg ha hb theorem lt_one_div_of_neg (ha : a < 0) (hb : b < 0) : a < 1 / b ↔ b < 1 / a := by simpa using lt_inv_of_neg ha hb theorem one_lt_div_iff : 1 < a / b ↔ 0 < b ∧ b < a ∨ b < 0 ∧ a < b := by rcases lt_trichotomy b 0 with (hb | rfl | hb) · simp [hb, hb.not_lt, one_lt_div_of_neg] · simp [lt_irrefl, zero_le_one] · simp [hb, hb.not_lt, one_lt_div] theorem one_le_div_iff : 1 ≤ a / b ↔ 0 < b ∧ b ≤ a ∨ b < 0 ∧ a ≤ b := by rcases lt_trichotomy b 0 with (hb | rfl | hb) · simp [hb, hb.not_lt, one_le_div_of_neg] · simp [lt_irrefl, zero_lt_one.not_le, zero_lt_one] · simp [hb, hb.not_lt, one_le_div] theorem div_lt_one_iff : a / b < 1 ↔ 0 < b ∧ a < b ∨ b = 0 ∨ b < 0 ∧ b < a := by rcases lt_trichotomy b 0 with (hb | rfl | hb) · simp [hb, hb.not_lt, hb.ne, div_lt_one_of_neg] · simp [zero_lt_one] · simp [hb, hb.not_lt, div_lt_one, hb.ne.symm] theorem div_le_one_iff : a / b ≤ 1 ↔ 0 < b ∧ a ≤ b ∨ b = 0 ∨ b < 0 ∧ b ≤ a := by rcases lt_trichotomy b 0 with (hb | rfl | hb) · simp [hb, hb.not_lt, hb.ne, div_le_one_of_neg] · simp [zero_le_one] · simp [hb, hb.not_lt, div_le_one, hb.ne.symm] /-! ### Relating two divisions, involving `1` -/ theorem one_div_le_one_div_of_neg_of_le (hb : b < 0) (h : a ≤ b) : 1 / b ≤ 1 / a := by rwa [div_le_iff_of_neg' hb, ← div_eq_mul_one_div, div_le_one_of_neg (h.trans_lt hb)] theorem one_div_lt_one_div_of_neg_of_lt (hb : b < 0) (h : a < b) : 1 / b < 1 / a := by rwa [div_lt_iff_of_neg' hb, ← div_eq_mul_one_div, div_lt_one_of_neg (h.trans hb)] theorem le_of_neg_of_one_div_le_one_div (hb : b < 0) (h : 1 / a ≤ 1 / b) : b ≤ a := le_imp_le_of_lt_imp_lt (one_div_lt_one_div_of_neg_of_lt hb) h theorem lt_of_neg_of_one_div_lt_one_div (hb : b < 0) (h : 1 / a < 1 / b) : b < a := lt_imp_lt_of_le_imp_le (one_div_le_one_div_of_neg_of_le hb) h /-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_neg_of_lt` and `lt_of_one_div_lt_one_div` -/ theorem one_div_le_one_div_of_neg (ha : a < 0) (hb : b < 0) : 1 / a ≤ 1 / b ↔ b ≤ a := by simpa [one_div] using inv_le_inv_of_neg ha hb /-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_lt` and `lt_of_one_div_lt_one_div` -/ theorem one_div_lt_one_div_of_neg (ha : a < 0) (hb : b < 0) : 1 / a < 1 / b ↔ b < a := lt_iff_lt_of_le_iff_le (one_div_le_one_div_of_neg hb ha) theorem one_div_lt_neg_one (h1 : a < 0) (h2 : -1 < a) : 1 / a < -1 := suffices 1 / a < 1 / -1 by rwa [one_div_neg_one_eq_neg_one] at this one_div_lt_one_div_of_neg_of_lt h1 h2 theorem one_div_le_neg_one (h1 : a < 0) (h2 : -1 ≤ a) : 1 / a ≤ -1 := suffices 1 / a ≤ 1 / -1 by rwa [one_div_neg_one_eq_neg_one] at this one_div_le_one_div_of_neg_of_le h1 h2 /-! ### Results about halving -/ theorem sub_self_div_two (a : α) : a - a / 2 = a / 2 := by suffices a / 2 + a / 2 - a / 2 = a / 2 by rwa [add_halves] at this rw [add_sub_cancel_right] theorem div_two_sub_self (a : α) : a / 2 - a = -(a / 2) := by suffices a / 2 - (a / 2 + a / 2) = -(a / 2) by rwa [add_halves] at this rw [sub_add_eq_sub_sub, sub_self, zero_sub] theorem add_sub_div_two_lt (h : a < b) : a + (b - a) / 2 < b := by rwa [← div_sub_div_same, sub_eq_add_neg, add_comm (b / 2), ← add_assoc, ← sub_eq_add_neg, ← lt_sub_iff_add_lt, sub_self_div_two, sub_self_div_two, div_lt_div_iff_of_pos_right (zero_lt_two' α)] /-- An inequality involving `2`. -/ theorem sub_one_div_inv_le_two (a2 : 2 ≤ a) : (1 - 1 / a)⁻¹ ≤ 2 := by -- Take inverses on both sides to obtain `2⁻¹ ≤ 1 - 1 / a` refine (inv_anti₀ (inv_pos.2 <| zero_lt_two' α) ?_).trans_eq (inv_inv (2 : α)) -- move `1 / a` to the left and `2⁻¹` to the right. rw [le_sub_iff_add_le, add_comm, ← le_sub_iff_add_le] -- take inverses on both sides and use the assumption `2 ≤ a`. convert (one_div a).le.trans (inv_anti₀ zero_lt_two a2) using 1 -- show `1 - 1 / 2 = 1 / 2`. rw [sub_eq_iff_eq_add, ← two_mul, mul_inv_cancel₀ two_ne_zero] /-! ### Results about `IsLUB` -/ -- TODO: Generalize to `LinearOrderedSemifield` theorem IsLUB.mul_left {s : Set α} (ha : 0 ≤ a) (hs : IsLUB s b) : IsLUB ((fun b => a * b) '' s) (a * b) := by rcases lt_or_eq_of_le ha with (ha | rfl) · exact (OrderIso.mulLeft₀ _ ha).isLUB_image'.2 hs · simp_rw [zero_mul] rw [hs.nonempty.image_const] exact isLUB_singleton -- TODO: Generalize to `LinearOrderedSemifield` theorem IsLUB.mul_right {s : Set α} (ha : 0 ≤ a) (hs : IsLUB s b) : IsLUB ((fun b => b * a) '' s) (b * a) := by simpa [mul_comm] using hs.mul_left ha /-! ### Miscellaneous lemmas -/ theorem mul_sub_mul_div_mul_neg_iff (hc : c ≠ 0) (hd : d ≠ 0) : (a * d - b * c) / (c * d) < 0 ↔ a / c < b / d := by rw [mul_comm b c, ← div_sub_div _ _ hc hd, sub_lt_zero] theorem mul_sub_mul_div_mul_nonpos_iff (hc : c ≠ 0) (hd : d ≠ 0) : (a * d - b * c) / (c * d) ≤ 0 ↔ a / c ≤ b / d := by rw [mul_comm b c, ← div_sub_div _ _ hc hd, sub_nonpos] alias ⟨div_lt_div_of_mul_sub_mul_div_neg, mul_sub_mul_div_mul_neg⟩ := mul_sub_mul_div_mul_neg_iff alias ⟨div_le_div_of_mul_sub_mul_div_nonpos, mul_sub_mul_div_mul_nonpos⟩ := mul_sub_mul_div_mul_nonpos_iff theorem exists_add_lt_and_pos_of_lt (h : b < a) : ∃ c, b + c < a ∧ 0 < c := ⟨(a - b) / 2, add_sub_div_two_lt h, div_pos (sub_pos_of_lt h) zero_lt_two⟩ theorem le_of_forall_sub_le (h : ∀ ε > 0, b - ε ≤ a) : b ≤ a := by contrapose! h simpa only [@and_comm ((0 : α) < _), lt_sub_iff_add_lt, gt_iff_lt] using exists_add_lt_and_pos_of_lt h private lemma exists_lt_mul_left_of_nonneg {a b c : α} (ha : 0 ≤ a) (hc : 0 ≤ c) (h : c < a * b) : ∃ a' ∈ Set.Ico 0 a, c < a' * b := by have hb : 0 < b := pos_of_mul_pos_right (hc.trans_lt h) ha obtain ⟨a', ha', a_a'⟩ := exists_between ((div_lt_iff₀ hb).2 h) exact ⟨a', ⟨(div_nonneg hc hb.le).trans ha'.le, a_a'⟩, (div_lt_iff₀ hb).1 ha'⟩ private lemma exists_lt_mul_right_of_nonneg {a b c : α} (ha : 0 ≤ a) (hc : 0 ≤ c) (h : c < a * b) : ∃ b' ∈ Set.Ico 0 b, c < a * b' := by have hb : 0 < b := pos_of_mul_pos_right (hc.trans_lt h) ha simp_rw [mul_comm a] at h ⊢ exact exists_lt_mul_left_of_nonneg hb.le hc h private lemma exists_mul_left_lt₀ {a b c : α} (hc : a * b < c) : ∃ a' > a, a' * b < c := by rcases le_or_lt b 0 with hb | hb · obtain ⟨a', ha'⟩ := exists_gt a exact ⟨a', ha', hc.trans_le' (antitone_mul_right hb ha'.le)⟩ · obtain ⟨a', ha', hc'⟩ := exists_between ((lt_div_iff₀ hb).2 hc) exact ⟨a', ha', (lt_div_iff₀ hb).1 hc'⟩ private lemma exists_mul_right_lt₀ {a b c : α} (hc : a * b < c) : ∃ b' > b, a * b' < c := by simp_rw [mul_comm a] at hc ⊢; exact exists_mul_left_lt₀ hc lemma le_mul_of_forall_lt₀ {a b c : α} (h : ∀ a' > a, ∀ b' > b, c ≤ a' * b') : c ≤ a * b := by refine le_of_forall_gt_imp_ge_of_dense fun d hd ↦ ?_ obtain ⟨a', ha', hd⟩ := exists_mul_left_lt₀ hd obtain ⟨b', hb', hd⟩ := exists_mul_right_lt₀ hd exact (h a' ha' b' hb').trans hd.le lemma mul_le_of_forall_lt_of_nonneg {a b c : α} (ha : 0 ≤ a) (hc : 0 ≤ c) (h : ∀ a' ≥ 0, a' < a → ∀ b' ≥ 0, b' < b → a' * b' ≤ c) : a * b ≤ c := by refine le_of_forall_lt_imp_le_of_dense fun d d_ab ↦ ?_ rcases lt_or_le d 0 with hd | hd · exact hd.le.trans hc obtain ⟨a', ha', d_ab⟩ := exists_lt_mul_left_of_nonneg ha hd d_ab obtain ⟨b', hb', d_ab⟩ := exists_lt_mul_right_of_nonneg ha'.1 hd d_ab exact d_ab.le.trans (h a' ha'.1 ha'.2 b' hb'.1 hb'.2) theorem mul_self_inj_of_nonneg (a0 : 0 ≤ a) (b0 : 0 ≤ b) : a * a = b * b ↔ a = b := mul_self_eq_mul_self_iff.trans <| or_iff_left_of_imp fun h => by subst a have : b = 0 := le_antisymm (neg_nonneg.1 a0) b0 rw [this, neg_zero] theorem min_div_div_right_of_nonpos (hc : c ≤ 0) (a b : α) : min (a / c) (b / c) = max a b / c := Eq.symm <| Antitone.map_max fun _ _ => div_le_div_of_nonpos_of_le hc theorem max_div_div_right_of_nonpos (hc : c ≤ 0) (a b : α) : max (a / c) (b / c) = min a b / c := Eq.symm <| Antitone.map_min fun _ _ => div_le_div_of_nonpos_of_le hc theorem abs_inv (a : α) : |a⁻¹| = |a|⁻¹ := map_inv₀ (absHom : α →*₀ α) a theorem abs_div (a b : α) : |a / b| = |a| / |b| := map_div₀ (absHom : α →*₀ α) a b theorem abs_one_div (a : α) : |1 / a| = 1 / |a| := by rw [abs_div, abs_one] theorem uniform_continuous_npow_on_bounded (B : α) {ε : α} (hε : 0 < ε) (n : ℕ) : ∃ δ > 0, ∀ q r : α, |r| ≤ B → |q - r| ≤ δ → |q ^ n - r ^ n| < ε := by wlog B_pos : 0 < B generalizing B · have ⟨δ, δ_pos, cont⟩ := this 1 zero_lt_one exact ⟨δ, δ_pos, fun q r hr ↦ cont q r (hr.trans ((le_of_not_lt B_pos).trans zero_le_one))⟩ have pos : 0 < 1 + ↑n * (B + 1) ^ (n - 1) := zero_lt_one.trans_le <| le_add_of_nonneg_right <| mul_nonneg n.cast_nonneg <| (pow_pos (B_pos.trans <| lt_add_of_pos_right _ zero_lt_one) _).le refine ⟨min 1 (ε / (1 + n * (B + 1) ^ (n - 1))), lt_min zero_lt_one (div_pos hε pos), fun q r hr hqr ↦ (abs_pow_sub_pow_le ..).trans_lt ?_⟩ rw [le_inf_iff, le_div_iff₀ pos, mul_one_add, ← mul_assoc] at hqr obtain h | h := (abs_nonneg (q - r)).eq_or_lt · simpa only [← h, zero_mul] using hε refine (lt_of_le_of_lt ?_ <| lt_add_of_pos_left _ h).trans_le hqr.2 refine mul_le_mul_of_nonneg_left (pow_le_pow_left₀ ((abs_nonneg _).trans le_sup_left) ?_ _) (mul_nonneg (abs_nonneg _) n.cast_nonneg) refine max_le ?_ (hr.trans <| le_add_of_nonneg_right zero_le_one) exact add_sub_cancel r q ▸ (abs_add_le ..).trans (add_le_add hr hqr.1)
end
Mathlib/Algebra/Order/Field/Basic.lean
673
674
/- 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.Basic import Mathlib.Topology.Order.ProjIcc /-! # Inverse trigonometric functions. See also `Analysis.SpecialFunctions.Trigonometric.Arctan` for the inverse tan function. (This is delayed as it is easier to set up after developing complex trigonometric functions.) Basic inequalities on trigonometric functions. -/ noncomputable section open Topology Filter Set Filter Real namespace Real variable {x y : ℝ} /-- Inverse of the `sin` function, returns values in the range `-π / 2 ≤ arcsin x ≤ π / 2`. It defaults to `-π / 2` on `(-∞, -1)` and to `π / 2` to `(1, ∞)`. -/ @[pp_nodot] noncomputable def arcsin : ℝ → ℝ := Subtype.val ∘ IccExtend (neg_le_self zero_le_one) sinOrderIso.symm theorem arcsin_mem_Icc (x : ℝ) : arcsin x ∈ Icc (-(π / 2)) (π / 2) := Subtype.coe_prop _ @[simp] theorem range_arcsin : range arcsin = Icc (-(π / 2)) (π / 2) := by rw [arcsin, range_comp Subtype.val] simp [Icc] theorem arcsin_le_pi_div_two (x : ℝ) : arcsin x ≤ π / 2 := (arcsin_mem_Icc x).2 theorem neg_pi_div_two_le_arcsin (x : ℝ) : -(π / 2) ≤ arcsin x := (arcsin_mem_Icc x).1 theorem arcsin_projIcc (x : ℝ) : arcsin (projIcc (-1) 1 (neg_le_self zero_le_one) x) = arcsin x := by rw [arcsin, Function.comp_apply, IccExtend_val, Function.comp_apply, IccExtend, Function.comp_apply] theorem sin_arcsin' {x : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) : sin (arcsin x) = x := by simpa [arcsin, IccExtend_of_mem _ _ hx, -OrderIso.apply_symm_apply] using Subtype.ext_iff.1 (sinOrderIso.apply_symm_apply ⟨x, hx⟩) theorem sin_arcsin {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : sin (arcsin x) = x := sin_arcsin' ⟨hx₁, hx₂⟩ theorem arcsin_sin' {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : arcsin (sin x) = x := injOn_sin (arcsin_mem_Icc _) hx <| by rw [sin_arcsin (neg_one_le_sin _) (sin_le_one _)] theorem arcsin_sin {x : ℝ} (hx₁ : -(π / 2) ≤ x) (hx₂ : x ≤ π / 2) : arcsin (sin x) = x := arcsin_sin' ⟨hx₁, hx₂⟩ theorem strictMonoOn_arcsin : StrictMonoOn arcsin (Icc (-1) 1) := (Subtype.strictMono_coe _).comp_strictMonoOn <| sinOrderIso.symm.strictMono.strictMonoOn_IccExtend _ @[gcongr] theorem arcsin_lt_arcsin {x y : ℝ} (hx : -1 ≤ x) (hlt : x < y) (hy : y ≤ 1) : arcsin x < arcsin y := strictMonoOn_arcsin ⟨hx, hlt.le.trans hy⟩ ⟨hx.trans hlt.le, hy⟩ hlt theorem monotone_arcsin : Monotone arcsin := (Subtype.mono_coe _).comp <| sinOrderIso.symm.monotone.IccExtend _ @[gcongr] theorem arcsin_le_arcsin {x y : ℝ} (h : x ≤ y) : arcsin x ≤ arcsin y := monotone_arcsin h theorem injOn_arcsin : InjOn arcsin (Icc (-1) 1) := strictMonoOn_arcsin.injOn theorem arcsin_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) : arcsin x = arcsin y ↔ x = y := injOn_arcsin.eq_iff ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ @[continuity, fun_prop] theorem continuous_arcsin : Continuous arcsin := continuous_subtype_val.comp sinOrderIso.symm.continuous.Icc_extend' @[fun_prop] theorem continuousAt_arcsin {x : ℝ} : ContinuousAt arcsin x := continuous_arcsin.continuousAt theorem arcsin_eq_of_sin_eq {x y : ℝ} (h₁ : sin x = y) (h₂ : x ∈ Icc (-(π / 2)) (π / 2)) : arcsin y = x := by subst y exact injOn_sin (arcsin_mem_Icc _) h₂ (sin_arcsin' (sin_mem_Icc x)) @[simp] theorem arcsin_zero : arcsin 0 = 0 := arcsin_eq_of_sin_eq sin_zero ⟨neg_nonpos.2 pi_div_two_pos.le, pi_div_two_pos.le⟩ @[simp] theorem arcsin_one : arcsin 1 = π / 2 := arcsin_eq_of_sin_eq sin_pi_div_two <| right_mem_Icc.2 (neg_le_self pi_div_two_pos.le) theorem arcsin_of_one_le {x : ℝ} (hx : 1 ≤ x) : arcsin x = π / 2 := by rw [← arcsin_projIcc, projIcc_of_right_le _ hx, Subtype.coe_mk, arcsin_one] theorem arcsin_neg_one : arcsin (-1) = -(π / 2) := arcsin_eq_of_sin_eq (by rw [sin_neg, sin_pi_div_two]) <| left_mem_Icc.2 (neg_le_self pi_div_two_pos.le) theorem arcsin_of_le_neg_one {x : ℝ} (hx : x ≤ -1) : arcsin x = -(π / 2) := by rw [← arcsin_projIcc, projIcc_of_le_left _ hx, Subtype.coe_mk, arcsin_neg_one] @[simp] theorem arcsin_neg (x : ℝ) : arcsin (-x) = -arcsin x := by rcases le_total x (-1) with hx₁ | hx₁ · rw [arcsin_of_le_neg_one hx₁, neg_neg, arcsin_of_one_le (le_neg.2 hx₁)] rcases le_total 1 x with hx₂ | hx₂ · rw [arcsin_of_one_le hx₂, arcsin_of_le_neg_one (neg_le_neg hx₂)] refine arcsin_eq_of_sin_eq ?_ ?_ · rw [sin_neg, sin_arcsin hx₁ hx₂] · exact ⟨neg_le_neg (arcsin_le_pi_div_two _), neg_le.2 (neg_pi_div_two_le_arcsin _)⟩ theorem arcsin_le_iff_le_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) : arcsin x ≤ y ↔ x ≤ sin y := by rw [← arcsin_sin' hy, strictMonoOn_arcsin.le_iff_le hx (sin_mem_Icc _), arcsin_sin' hy] theorem arcsin_le_iff_le_sin' {x y : ℝ} (hy : y ∈ Ico (-(π / 2)) (π / 2)) : arcsin x ≤ y ↔ x ≤ sin y := by rcases le_total x (-1) with hx₁ | hx₁ · simp [arcsin_of_le_neg_one hx₁, hy.1, hx₁.trans (neg_one_le_sin _)] rcases lt_or_le 1 x with hx₂ | hx₂ · simp [arcsin_of_one_le hx₂.le, hy.2.not_le, (sin_le_one y).trans_lt hx₂] exact arcsin_le_iff_le_sin ⟨hx₁, hx₂⟩ (mem_Icc_of_Ico hy) theorem le_arcsin_iff_sin_le {x y : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) : x ≤ arcsin y ↔ sin x ≤ y := by rw [← neg_le_neg_iff, ← arcsin_neg, arcsin_le_iff_le_sin ⟨neg_le_neg hy.2, neg_le.2 hy.1⟩ ⟨neg_le_neg hx.2, neg_le.2 hx.1⟩, sin_neg, neg_le_neg_iff] theorem le_arcsin_iff_sin_le' {x y : ℝ} (hx : x ∈ Ioc (-(π / 2)) (π / 2)) : x ≤ arcsin y ↔ sin x ≤ y := by rw [← neg_le_neg_iff, ← arcsin_neg, arcsin_le_iff_le_sin' ⟨neg_le_neg hx.2, neg_lt.2 hx.1⟩, sin_neg, neg_le_neg_iff] theorem arcsin_lt_iff_lt_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) : arcsin x < y ↔ x < sin y := not_le.symm.trans <| (not_congr <| le_arcsin_iff_sin_le hy hx).trans not_le theorem arcsin_lt_iff_lt_sin' {x y : ℝ} (hy : y ∈ Ioc (-(π / 2)) (π / 2)) : arcsin x < y ↔ x < sin y := not_le.symm.trans <| (not_congr <| le_arcsin_iff_sin_le' hy).trans not_le theorem lt_arcsin_iff_sin_lt {x y : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) : x < arcsin y ↔ sin x < y := not_le.symm.trans <| (not_congr <| arcsin_le_iff_le_sin hy hx).trans not_le theorem lt_arcsin_iff_sin_lt' {x y : ℝ} (hx : x ∈ Ico (-(π / 2)) (π / 2)) : x < arcsin y ↔ sin x < y := not_le.symm.trans <| (not_congr <| arcsin_le_iff_le_sin' hx).trans not_le theorem arcsin_eq_iff_eq_sin {x y : ℝ} (hy : y ∈ Ioo (-(π / 2)) (π / 2)) : arcsin x = y ↔ x = sin y := by simp only [le_antisymm_iff, arcsin_le_iff_le_sin' (mem_Ico_of_Ioo hy), le_arcsin_iff_sin_le' (mem_Ioc_of_Ioo hy)] @[simp] theorem arcsin_nonneg {x : ℝ} : 0 ≤ arcsin x ↔ 0 ≤ x := (le_arcsin_iff_sin_le' ⟨neg_lt_zero.2 pi_div_two_pos, pi_div_two_pos.le⟩).trans <| by rw [sin_zero] @[simp] theorem arcsin_nonpos {x : ℝ} : arcsin x ≤ 0 ↔ x ≤ 0 := neg_nonneg.symm.trans <| arcsin_neg x ▸ arcsin_nonneg.trans neg_nonneg @[simp] theorem arcsin_eq_zero_iff {x : ℝ} : arcsin x = 0 ↔ x = 0 := by simp [le_antisymm_iff] @[simp] theorem zero_eq_arcsin_iff {x} : 0 = arcsin x ↔ x = 0 := eq_comm.trans arcsin_eq_zero_iff @[simp] theorem arcsin_pos {x : ℝ} : 0 < arcsin x ↔ 0 < x := lt_iff_lt_of_le_iff_le arcsin_nonpos @[simp] theorem arcsin_lt_zero {x : ℝ} : arcsin x < 0 ↔ x < 0 := lt_iff_lt_of_le_iff_le arcsin_nonneg @[simp] theorem arcsin_lt_pi_div_two {x : ℝ} : arcsin x < π / 2 ↔ x < 1 := (arcsin_lt_iff_lt_sin' (right_mem_Ioc.2 <| neg_lt_self pi_div_two_pos)).trans <| by rw [sin_pi_div_two] @[simp] theorem neg_pi_div_two_lt_arcsin {x : ℝ} : -(π / 2) < arcsin x ↔ -1 < x := (lt_arcsin_iff_sin_lt' <| left_mem_Ico.2 <| neg_lt_self pi_div_two_pos).trans <| by rw [sin_neg, sin_pi_div_two] @[simp] theorem arcsin_eq_pi_div_two {x : ℝ} : arcsin x = π / 2 ↔ 1 ≤ x := ⟨fun h => not_lt.1 fun h' => (arcsin_lt_pi_div_two.2 h').ne h, arcsin_of_one_le⟩ @[simp] theorem pi_div_two_eq_arcsin {x} : π / 2 = arcsin x ↔ 1 ≤ x := eq_comm.trans arcsin_eq_pi_div_two @[simp] theorem pi_div_two_le_arcsin {x} : π / 2 ≤ arcsin x ↔ 1 ≤ x := (arcsin_le_pi_div_two x).le_iff_eq.trans pi_div_two_eq_arcsin @[simp] theorem arcsin_eq_neg_pi_div_two {x : ℝ} : arcsin x = -(π / 2) ↔ x ≤ -1 := ⟨fun h => not_lt.1 fun h' => (neg_pi_div_two_lt_arcsin.2 h').ne' h, arcsin_of_le_neg_one⟩ @[simp] theorem neg_pi_div_two_eq_arcsin {x} : -(π / 2) = arcsin x ↔ x ≤ -1 := eq_comm.trans arcsin_eq_neg_pi_div_two @[simp] theorem arcsin_le_neg_pi_div_two {x} : arcsin x ≤ -(π / 2) ↔ x ≤ -1 := (neg_pi_div_two_le_arcsin x).le_iff_eq.trans arcsin_eq_neg_pi_div_two @[simp] theorem pi_div_four_le_arcsin {x} : π / 4 ≤ arcsin x ↔ √2 / 2 ≤ x := by rw [← sin_pi_div_four, le_arcsin_iff_sin_le'] have := pi_pos constructor <;> linarith theorem mapsTo_sin_Ioo : MapsTo sin (Ioo (-(π / 2)) (π / 2)) (Ioo (-1) 1) := fun x h => by rwa [mem_Ioo, ← arcsin_lt_pi_div_two, ← neg_pi_div_two_lt_arcsin, arcsin_sin h.1.le h.2.le] /-- `Real.sin` as a `PartialHomeomorph` between `(-π / 2, π / 2)` and `(-1, 1)`. -/ @[simp] def sinPartialHomeomorph : PartialHomeomorph ℝ ℝ where toFun := sin invFun := arcsin source := Ioo (-(π / 2)) (π / 2) target := Ioo (-1) 1 map_source' := mapsTo_sin_Ioo map_target' _ hy := ⟨neg_pi_div_two_lt_arcsin.2 hy.1, arcsin_lt_pi_div_two.2 hy.2⟩ left_inv' _ hx := arcsin_sin hx.1.le hx.2.le right_inv' _ hy := sin_arcsin hy.1.le hy.2.le open_source := isOpen_Ioo open_target := isOpen_Ioo continuousOn_toFun := continuous_sin.continuousOn continuousOn_invFun := continuous_arcsin.continuousOn theorem cos_arcsin_nonneg (x : ℝ) : 0 ≤ cos (arcsin x) := cos_nonneg_of_mem_Icc ⟨neg_pi_div_two_le_arcsin _, arcsin_le_pi_div_two _⟩ -- The junk values for `arcsin` and `sqrt` make this true even outside `[-1, 1]`. theorem cos_arcsin (x : ℝ) : cos (arcsin x) = √(1 - x ^ 2) := by by_cases hx₁ : -1 ≤ x; swap · rw [not_le] at hx₁ rw [arcsin_of_le_neg_one hx₁.le, cos_neg, cos_pi_div_two, sqrt_eq_zero_of_nonpos] nlinarith by_cases hx₂ : x ≤ 1; swap · rw [not_le] at hx₂ rw [arcsin_of_one_le hx₂.le, cos_pi_div_two, sqrt_eq_zero_of_nonpos] nlinarith have : sin (arcsin x) ^ 2 + cos (arcsin x) ^ 2 = 1 := sin_sq_add_cos_sq (arcsin x) rw [← eq_sub_iff_add_eq', ← sqrt_inj (sq_nonneg _) (sub_nonneg.2 (sin_sq_le_one (arcsin x))), sq, sqrt_mul_self (cos_arcsin_nonneg _)] at this rw [this, sin_arcsin hx₁ hx₂] -- The junk values for `arcsin` and `sqrt` make this true even outside `[-1, 1]`. theorem tan_arcsin (x : ℝ) : tan (arcsin x) = x / √(1 - x ^ 2) := by rw [tan_eq_sin_div_cos, cos_arcsin] by_cases hx₁ : -1 ≤ x; swap · have h : √(1 - x ^ 2) = 0 := sqrt_eq_zero_of_nonpos (by nlinarith) rw [h] simp by_cases hx₂ : x ≤ 1; swap · have h : √(1 - x ^ 2) = 0 := sqrt_eq_zero_of_nonpos (by nlinarith) rw [h] simp rw [sin_arcsin hx₁ hx₂] /-- Inverse of the `cos` function, returns values in the range `0 ≤ arccos x` and `arccos x ≤ π`. It defaults to `π` on `(-∞, -1)` and to `0` to `(1, ∞)`. -/ @[pp_nodot] noncomputable def arccos (x : ℝ) : ℝ := π / 2 - arcsin x theorem arccos_eq_pi_div_two_sub_arcsin (x : ℝ) : arccos x = π / 2 - arcsin x := rfl theorem arcsin_eq_pi_div_two_sub_arccos (x : ℝ) : arcsin x = π / 2 - arccos x := by simp [arccos] theorem arccos_le_pi (x : ℝ) : arccos x ≤ π := by unfold arccos; linarith [neg_pi_div_two_le_arcsin x] theorem arccos_nonneg (x : ℝ) : 0 ≤ arccos x := by unfold arccos; linarith [arcsin_le_pi_div_two x] @[simp] theorem arccos_pos {x : ℝ} : 0 < arccos x ↔ x < 1 := by simp [arccos] theorem cos_arccos {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : cos (arccos x) = x := by rw [arccos, cos_pi_div_two_sub, sin_arcsin hx₁ hx₂] theorem arccos_cos {x : ℝ} (hx₁ : 0 ≤ x) (hx₂ : x ≤ π) : arccos (cos x) = x := by rw [arccos, ← sin_pi_div_two_sub, arcsin_sin] <;> simp [sub_eq_add_neg] <;> linarith lemma arccos_eq_of_eq_cos (hy₀ : 0 ≤ y) (hy₁ : y ≤ π) (hxy : x = cos y) : arccos x = y := by rw [hxy, arccos_cos hy₀ hy₁] theorem strictAntiOn_arccos : StrictAntiOn arccos (Icc (-1) 1) := fun _ hx _ hy h => sub_lt_sub_left (strictMonoOn_arcsin hx hy h) _ @[gcongr] lemma arccos_lt_arccos {x y : ℝ} (hx : -1 ≤ x) (hlt : x < y) (hy : y ≤ 1) : arccos y < arccos x := by unfold arccos; gcongr <;> assumption @[gcongr] lemma arccos_le_arccos {x y : ℝ} (hlt : x ≤ y) : arccos y ≤ arccos x := by unfold arccos; gcongr theorem antitone_arccos : Antitone arccos := fun _ _ ↦ arccos_le_arccos theorem arccos_injOn : InjOn arccos (Icc (-1) 1) := strictAntiOn_arccos.injOn theorem arccos_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) : arccos x = arccos y ↔ x = y := arccos_injOn.eq_iff ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ @[simp] theorem arccos_zero : arccos 0 = π / 2 := by simp [arccos] @[simp] theorem arccos_one : arccos 1 = 0 := by simp [arccos] @[simp] theorem arccos_neg_one : arccos (-1) = π := by simp [arccos, add_halves] @[simp] theorem arccos_eq_zero {x} : arccos x = 0 ↔ 1 ≤ x := by simp [arccos, sub_eq_zero] @[simp] theorem arccos_eq_pi_div_two {x} : arccos x = π / 2 ↔ x = 0 := by simp [arccos] @[simp] theorem arccos_eq_pi {x} : arccos x = π ↔ x ≤ -1 := by rw [arccos, sub_eq_iff_eq_add, ← sub_eq_iff_eq_add', div_two_sub_self, neg_pi_div_two_eq_arcsin] theorem arccos_neg (x : ℝ) : arccos (-x) = π - arccos x := by rw [← add_halves π, arccos, arcsin_neg, arccos, add_sub_assoc, sub_sub_self, sub_neg_eq_add] theorem arccos_of_one_le {x : ℝ} (hx : 1 ≤ x) : arccos x = 0 := by rw [arccos, arcsin_of_one_le hx, sub_self] theorem arccos_of_le_neg_one {x : ℝ} (hx : x ≤ -1) : arccos x = π := by rw [arccos, arcsin_of_le_neg_one hx, sub_neg_eq_add, add_halves] -- The junk values for `arccos` and `sqrt` make this true even outside `[-1, 1]`. theorem sin_arccos (x : ℝ) : sin (arccos x) = √(1 - x ^ 2) := by by_cases hx₁ : -1 ≤ x; swap · rw [not_le] at hx₁ rw [arccos_of_le_neg_one hx₁.le, sin_pi, sqrt_eq_zero_of_nonpos] nlinarith by_cases hx₂ : x ≤ 1; swap · rw [not_le] at hx₂ rw [arccos_of_one_le hx₂.le, sin_zero, sqrt_eq_zero_of_nonpos] nlinarith rw [arccos_eq_pi_div_two_sub_arcsin, sin_pi_div_two_sub, cos_arcsin] @[simp] theorem arccos_le_pi_div_two {x} : arccos x ≤ π / 2 ↔ 0 ≤ x := by simp [arccos] @[simp] theorem arccos_lt_pi_div_two {x : ℝ} : arccos x < π / 2 ↔ 0 < x := by simp [arccos] @[simp] theorem arccos_le_pi_div_four {x} : arccos x ≤ π / 4 ↔ √2 / 2 ≤ x := by rw [arccos, ← pi_div_four_le_arcsin] constructor <;> · intro linarith @[continuity, fun_prop] theorem continuous_arccos : Continuous arccos := continuous_const.sub continuous_arcsin -- The junk values for `arccos` and `sqrt` make this true even outside `[-1, 1]`. theorem tan_arccos (x : ℝ) : tan (arccos x) = √(1 - x ^ 2) / x := by rw [arccos, tan_pi_div_two_sub, tan_arcsin, inv_div] -- The junk values for `arccos` and `sqrt` make this true even for `1 < x`. theorem arccos_eq_arcsin {x : ℝ} (h : 0 ≤ x) : arccos x = arcsin (√(1 - x ^ 2)) := (arcsin_eq_of_sin_eq (sin_arccos _) ⟨(Left.neg_nonpos_iff.2 (div_nonneg pi_pos.le (by norm_num))).trans (arccos_nonneg _), arccos_le_pi_div_two.2 h⟩).symm -- The junk values for `arcsin` and `sqrt` make this true even for `1 < x`. theorem arcsin_eq_arccos {x : ℝ} (h : 0 ≤ x) : arcsin x = arccos (√(1 - x ^ 2)) := by rw [eq_comm, ← cos_arcsin] exact arccos_cos (arcsin_nonneg.2 h) ((arcsin_le_pi_div_two _).trans (div_le_self pi_pos.le one_le_two)) end Real open Real /-! ### Convenience dot notation lemmas -/ namespace Filter.Tendsto variable {α : Type*} {l : Filter α} {x : ℝ} {f : α → ℝ} protected theorem arcsin (h : Tendsto f l (𝓝 x)) : Tendsto (arcsin <| f ·) l (𝓝 (arcsin x)) := (continuous_arcsin.tendsto _).comp h theorem arcsin_nhdsLE (h : Tendsto f l (𝓝[≤] x)) : Tendsto (arcsin <| f ·) l (𝓝[≤] (arcsin x)) := by refine ((continuous_arcsin.tendsto _).inf <| MapsTo.tendsto fun y hy ↦ ?_).comp h exact monotone_arcsin hy theorem arcsin_nhdsGE (h : Tendsto f l (𝓝[≥] x)) : Tendsto (arcsin <| f ·) l (𝓝[≥] (arcsin x)) := ((continuous_arcsin.tendsto _).inf <| MapsTo.tendsto fun _ ↦ arcsin_le_arcsin).comp h protected theorem arccos (h : Tendsto f l (𝓝 x)) : Tendsto (arccos <| f ·) l (𝓝 (arccos x)) := (continuous_arccos.tendsto _).comp h theorem arccos_nhdsLE (h : Tendsto f l (𝓝[≤] x)) : Tendsto (arccos <| f ·) l (𝓝[≥] (arccos x)) := ((continuous_arccos.tendsto _).inf <| MapsTo.tendsto fun _ ↦ arccos_le_arccos).comp h theorem arccos_nhdsGE (h : Tendsto f l (𝓝[≥] x)) : Tendsto (arccos <| f ·) l (𝓝[≤] (arccos x)) := by refine ((continuous_arccos.tendsto _).inf <| MapsTo.tendsto fun y hy ↦ ?_).comp h
simp only [mem_Ici, mem_Iic] at hy ⊢
Mathlib/Analysis/SpecialFunctions/Trigonometric/Inverse.lean
440
440
/- Copyright (c) 2023 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.Group.PUnit import Mathlib.Algebra.Group.Subgroup.Ker import Mathlib.Algebra.Group.Submonoid.Membership import Mathlib.GroupTheory.Congruence.Basic /-! # Coproduct (free product) of two monoids or groups In this file we define `Monoid.Coprod M N` (notation: `M ∗ N`) to be the coproduct (a.k.a. free product) of two monoids. The same type is used for the coproduct of two monoids and for the coproduct of two groups. The coproduct `M ∗ N` has the following universal property: for any monoid `P` and homomorphisms `f : M →* P`, `g : N →* P`, there exists a unique homomorphism `fg : M ∗ N →* P` such that `fg ∘ Monoid.Coprod.inl = f` and `fg ∘ Monoid.Coprod.inr = g`, where `Monoid.Coprod.inl : M →* M ∗ N` and `Monoid.Coprod.inr : N →* M ∗ N` are canonical embeddings. This homomorphism `fg` is given by `Monoid.Coprod.lift f g`. We also define some homomorphisms and isomorphisms about `M ∗ N`, and provide additive versions of all definitions and theorems. ## Main definitions ### Types * `Monoid.Coprod M N` (a.k.a. `M ∗ N`): the free product (a.k.a. coproduct) of two monoids `M` and `N`. * `AddMonoid.Coprod M N` (no notation): the additive version of `Monoid.Coprod`. In other sections, we only list multiplicative definitions. ### Instances * `MulOneClass`, `Monoid`, and `Group` structures on the coproduct `M ∗ N`. ### Monoid homomorphisms * `Monoid.Coprod.mk`: the projection `FreeMonoid (M ⊕ N) →* M ∗ N`. * `Monoid.Coprod.inl`, `Monoid.Coprod.inr`: canonical embeddings `M →* M ∗ N` and `N →* M ∗ N`. * `Monoid.Coprod.lift`: construct a monoid homomorphism `M ∗ N →* P` from homomorphisms `M →* P` and `N →* P`; see also `Monoid.Coprod.liftEquiv`. * `Monoid.Coprod.clift`: a constructor for homomorphisms `M ∗ N →* P` that allows the user to control the computational behavior. * `Monoid.Coprod.map`: combine two homomorphisms `f : M →* N` and `g : M' →* N'` into `M ∗ M' →* N ∗ N'`. * `Monoid.Coprod.swap`: the natural homomorphism `M ∗ N →* N ∗ M`. * `Monoid.Coprod.fst`, `Monoid.Coprod.snd`, and `Monoid.Coprod.toProd`: natural projections `M ∗ N →* M`, `M ∗ N →* N`, and `M ∗ N →* M × N`. ### Monoid isomorphisms * `MulEquiv.coprodCongr`: a `MulEquiv` version of `Monoid.Coprod.map`. * `MulEquiv.coprodComm`: a `MulEquiv` version of `Monoid.Coprod.swap`. * `MulEquiv.coprodAssoc`: associativity of the coproduct. * `MulEquiv.coprodPUnit`, `MulEquiv.punitCoprod`: free product by `PUnit` on the left or on the right is isomorphic to the original monoid. ## Main results The universal property of the coproduct is given by the definition `Monoid.Coprod.lift` and the lemma `Monoid.Coprod.lift_unique`. We also prove a slightly more general extensionality lemma `Monoid.Coprod.hom_ext` for homomorphisms `M ∗ N →* P` and prove lots of basic lemmas like `Monoid.Coprod.fst_comp_inl`. ## Implementation details The definition of the coproduct of an indexed family of monoids is formalized in `Monoid.CoprodI`. While mathematically `M ∗ N` is a particular case of the coproduct of an indexed family of monoids, it is easier to build API from scratch instead of using something like ``` def Monoid.Coprod M N := Monoid.CoprodI ![M, N] ``` or ``` def Monoid.Coprod M N := Monoid.CoprodI (fun b : Bool => cond b M N) ``` There are several reasons to build an API from scratch. - API about `Con` makes it easy to define the required type and prove the universal property, so there is little overhead compared to transferring API from `Monoid.CoprodI`. - If `M` and `N` live in different universes, then the definition has to add `ULift`s; this makes it harder to transfer API and definitions. - As of now, we have no way to automatically build an instance of `(k : Fin 2) → Monoid (![M, N] k)` from `[Monoid M]` and `[Monoid N]`, not even speaking about more advanced typeclass assumptions that involve both `M` and `N`. - Using a list of `M ⊕ N` instead of, e.g., a list of `Σ k : Fin 2, ![M, N] k` as the underlying type makes it possible to write computationally effective code (though this point is not tested yet). ## TODO - Prove `Monoid.CoprodI (f : Fin 2 → Type*) ≃* f 0 ∗ f 1` and `Monoid.CoprodI (f : Bool → Type*) ≃* f false ∗ f true`. ## Tags group, monoid, coproduct, free product -/ assert_not_exists MonoidWithZero open FreeMonoid Function List Set namespace Monoid /-- The minimal congruence relation `c` on `FreeMonoid (M ⊕ N)` such that `FreeMonoid.of ∘ Sum.inl` and `FreeMonoid.of ∘ Sum.inr` are monoid homomorphisms to the quotient by `c`. -/ @[to_additive "The minimal additive congruence relation `c` on `FreeAddMonoid (M ⊕ N)` such that `FreeAddMonoid.of ∘ Sum.inl` and `FreeAddMonoid.of ∘ Sum.inr` are additive monoid homomorphisms to the quotient by `c`."] def coprodCon (M N : Type*) [MulOneClass M] [MulOneClass N] : Con (FreeMonoid (M ⊕ N)) := sInf {c | (∀ x y : M, c (of (Sum.inl (x * y))) (of (Sum.inl x) * of (Sum.inl y))) ∧ (∀ x y : N, c (of (Sum.inr (x * y))) (of (Sum.inr x) * of (Sum.inr y))) ∧ c (of <| Sum.inl 1) 1 ∧ c (of <| Sum.inr 1) 1} /-- Coproduct of two monoids or groups. -/ @[to_additive "Coproduct of two additive monoids or groups."] def Coprod (M N : Type*) [MulOneClass M] [MulOneClass N] := (coprodCon M N).Quotient namespace Coprod @[inherit_doc] scoped infix:30 " ∗ " => Coprod section MulOneClass variable {M N M' N' P : Type*} [MulOneClass M] [MulOneClass N] [MulOneClass M'] [MulOneClass N'] [MulOneClass P] @[to_additive] protected instance : MulOneClass (M ∗ N) := Con.mulOneClass _ /-- The natural projection `FreeMonoid (M ⊕ N) →* M ∗ N`. -/ @[to_additive "The natural projection `FreeAddMonoid (M ⊕ N) →+ AddMonoid.Coprod M N`."] def mk : FreeMonoid (M ⊕ N) →* M ∗ N := Con.mk' _ @[to_additive (attr := simp)] theorem con_ker_mk : Con.ker mk = coprodCon M N := Con.mk'_ker _ @[to_additive] theorem mk_surjective : Surjective (@mk M N _ _) := Quot.mk_surjective @[to_additive (attr := simp)] theorem mrange_mk : MonoidHom.mrange (@mk M N _ _) = ⊤ := Con.mrange_mk' @[to_additive] theorem mk_eq_mk {w₁ w₂ : FreeMonoid (M ⊕ N)} : mk w₁ = mk w₂ ↔ coprodCon M N w₁ w₂ := Con.eq _ /-- The natural embedding `M →* M ∗ N`. -/ @[to_additive "The natural embedding `M →+ AddMonoid.Coprod M N`."] def inl : M →* M ∗ N where toFun := fun x => mk (of (.inl x)) map_one' := mk_eq_mk.2 fun _c hc => hc.2.2.1 map_mul' := fun x y => mk_eq_mk.2 fun _c hc => hc.1 x y /-- The natural embedding `N →* M ∗ N`. -/ @[to_additive "The natural embedding `N →+ AddMonoid.Coprod M N`."] def inr : N →* M ∗ N where toFun := fun x => mk (of (.inr x)) map_one' := mk_eq_mk.2 fun _c hc => hc.2.2.2 map_mul' := fun x y => mk_eq_mk.2 fun _c hc => hc.2.1 x y @[to_additive (attr := simp)] theorem mk_of_inl (x : M) : (mk (of (.inl x)) : M ∗ N) = inl x := rfl @[to_additive (attr := simp)] theorem mk_of_inr (x : N) : (mk (of (.inr x)) : M ∗ N) = inr x := rfl @[to_additive (attr := elab_as_elim)] theorem induction_on' {C : M ∗ N → Prop} (m : M ∗ N) (one : C 1) (inl_mul : ∀ m x, C x → C (inl m * x)) (inr_mul : ∀ n x, C x → C (inr n * x)) : C m := by rcases mk_surjective m with ⟨x, rfl⟩ induction x using FreeMonoid.inductionOn' with | one => exact one | mul_of x xs ih => cases x with | inl m => simpa using inl_mul m _ ih | inr n => simpa using inr_mul n _ ih @[to_additive (attr := elab_as_elim)] theorem induction_on {C : M ∗ N → Prop} (m : M ∗ N) (inl : ∀ m, C (inl m)) (inr : ∀ n, C (inr n)) (mul : ∀ x y, C x → C y → C (x * y)) : C m := induction_on' m (by simpa using inl 1) (fun _ _ ↦ mul _ _ (inl _)) fun _ _ ↦ mul _ _ (inr _) /-- Lift a monoid homomorphism `FreeMonoid (M ⊕ N) →* P` satisfying additional properties to `M ∗ N →* P`. In many cases, `Coprod.lift` is more convenient. Compared to `Coprod.lift`, this definition allows a user to provide a custom computational behavior. Also, it only needs `MulOneclass` assumptions while `Coprod.lift` needs a `Monoid` structure. -/ @[to_additive "Lift an additive monoid homomorphism `FreeAddMonoid (M ⊕ N) →+ P` satisfying additional properties to `AddMonoid.Coprod M N →+ P`. Compared to `AddMonoid.Coprod.lift`, this definition allows a user to provide a custom computational behavior. Also, it only needs `AddZeroclass` assumptions while `AddMonoid.Coprod.lift` needs an `AddMonoid` structure. "] def clift (f : FreeMonoid (M ⊕ N) →* P) (hM₁ : f (of (.inl 1)) = 1) (hN₁ : f (of (.inr 1)) = 1) (hM : ∀ x y, f (of (.inl (x * y))) = f (of (.inl x) * of (.inl y))) (hN : ∀ x y, f (of (.inr (x * y))) = f (of (.inr x) * of (.inr y))) : M ∗ N →* P := Con.lift _ f <| sInf_le ⟨hM, hN, hM₁.trans (map_one f).symm, hN₁.trans (map_one f).symm⟩ @[to_additive (attr := simp)] theorem clift_apply_inl (f : FreeMonoid (M ⊕ N) →* P) (hM₁ hN₁ hM hN) (x : M) : clift f hM₁ hN₁ hM hN (inl x) = f (of (.inl x)) := rfl @[to_additive (attr := simp)] theorem clift_apply_inr (f : FreeMonoid (M ⊕ N) →* P) (hM₁ hN₁ hM hN) (x : N) : clift f hM₁ hN₁ hM hN (inr x) = f (of (.inr x)) := rfl @[to_additive (attr := simp)] theorem clift_apply_mk (f : FreeMonoid (M ⊕ N) →* P) (hM₁ hN₁ hM hN w) : clift f hM₁ hN₁ hM hN (mk w) = f w := rfl @[to_additive (attr := simp)] theorem clift_comp_mk (f : FreeMonoid (M ⊕ N) →* P) (hM₁ hN₁ hM hN) : (clift f hM₁ hN₁ hM hN).comp mk = f := DFunLike.ext' rfl @[to_additive (attr := simp)] theorem mclosure_range_inl_union_inr : Submonoid.closure (range (inl : M →* M ∗ N) ∪ range (inr : N →* M ∗ N)) = ⊤ := by rw [← mrange_mk, MonoidHom.mrange_eq_map, ← closure_range_of, MonoidHom.map_mclosure, ← range_comp, Sum.range_eq]; rfl @[to_additive (attr := simp)] theorem mrange_inl_sup_mrange_inr : MonoidHom.mrange (inl : M →* M ∗ N) ⊔ MonoidHom.mrange (inr : N →* M ∗ N) = ⊤ := by rw [← mclosure_range_inl_union_inr, Submonoid.closure_union, ← MonoidHom.coe_mrange, ← MonoidHom.coe_mrange, Submonoid.closure_eq, Submonoid.closure_eq] @[to_additive] theorem codisjoint_mrange_inl_mrange_inr : Codisjoint (MonoidHom.mrange (inl : M →* M ∗ N)) (MonoidHom.mrange inr) := codisjoint_iff.2 mrange_inl_sup_mrange_inr @[to_additive] theorem mrange_eq (f : M ∗ N →* P) : MonoidHom.mrange f = MonoidHom.mrange (f.comp inl) ⊔ MonoidHom.mrange (f.comp inr) := by rw [MonoidHom.mrange_eq_map, ← mrange_inl_sup_mrange_inr, Submonoid.map_sup, MonoidHom.map_mrange, MonoidHom.map_mrange] /-- Extensionality lemma for monoid homomorphisms `M ∗ N →* P`. If two homomorphisms agree on the ranges of `Monoid.Coprod.inl` and `Monoid.Coprod.inr`, then they are equal. -/ @[to_additive (attr := ext 1100) "Extensionality lemma for additive monoid homomorphisms `AddMonoid.Coprod M N →+ P`. If two homomorphisms agree on the ranges of `AddMonoid.Coprod.inl` and `AddMonoid.Coprod.inr`, then they are equal."] theorem hom_ext {f g : M ∗ N →* P} (h₁ : f.comp inl = g.comp inl) (h₂ : f.comp inr = g.comp inr) : f = g := MonoidHom.eq_of_eqOn_denseM mclosure_range_inl_union_inr <| eqOn_union.2 ⟨eqOn_range.2 <| DFunLike.ext'_iff.1 h₁, eqOn_range.2 <| DFunLike.ext'_iff.1 h₂⟩ @[to_additive (attr := simp)] theorem clift_mk : clift (mk : FreeMonoid (M ⊕ N) →* M ∗ N) (map_one inl) (map_one inr) (map_mul inl) (map_mul inr) = .id _ := hom_ext rfl rfl /-- Map `M ∗ N` to `M' ∗ N'` by applying `Sum.map f g` to each element of the underlying list. -/ @[to_additive "Map `AddMonoid.Coprod M N` to `AddMonoid.Coprod M' N'` by applying `Sum.map f g` to each element of the underlying list."] def map (f : M →* M') (g : N →* N') : M ∗ N →* M' ∗ N' := clift (mk.comp <| FreeMonoid.map <| Sum.map f g) (by simp only [MonoidHom.comp_apply, map_of, Sum.map_inl, map_one, mk_of_inl]) (by simp only [MonoidHom.comp_apply, map_of, Sum.map_inr, map_one, mk_of_inr]) (fun x y => by simp only [MonoidHom.comp_apply, map_of, Sum.map_inl, map_mul, mk_of_inl]) fun x y => by simp only [MonoidHom.comp_apply, map_of, Sum.map_inr, map_mul, mk_of_inr] @[to_additive (attr := simp)] theorem map_mk_ofList (f : M →* M') (g : N →* N') (l : List (M ⊕ N)) : map f g (mk (ofList l)) = mk (ofList (l.map (Sum.map f g))) := rfl @[to_additive (attr := simp)] theorem map_apply_inl (f : M →* M') (g : N →* N') (x : M) : map f g (inl x) = inl (f x) := rfl @[to_additive (attr := simp)] theorem map_apply_inr (f : M →* M') (g : N →* N') (x : N) : map f g (inr x) = inr (g x) := rfl @[to_additive (attr := simp)] theorem map_comp_inl (f : M →* M') (g : N →* N') : (map f g).comp inl = inl.comp f := rfl @[to_additive (attr := simp)] theorem map_comp_inr (f : M →* M') (g : N →* N') : (map f g).comp inr = inr.comp g := rfl @[to_additive (attr := simp)] theorem map_id_id : map (.id M) (.id N) = .id (M ∗ N) := hom_ext rfl rfl @[to_additive] theorem map_comp_map {M'' N''} [MulOneClass M''] [MulOneClass N''] (f' : M' →* M'') (g' : N' →* N'') (f : M →* M') (g : N →* N') : (map f' g').comp (map f g) = map (f'.comp f) (g'.comp g) := hom_ext rfl rfl @[to_additive] theorem map_map {M'' N''} [MulOneClass M''] [MulOneClass N''] (f' : M' →* M'') (g' : N' →* N'') (f : M →* M') (g : N →* N') (x : M ∗ N) : map f' g' (map f g x) = map (f'.comp f) (g'.comp g) x := DFunLike.congr_fun (map_comp_map f' g' f g) x variable (M N) /-- Map `M ∗ N` to `N ∗ M` by applying `Sum.swap` to each element of the underlying list. See also `MulEquiv.coprodComm` for a `MulEquiv` version. -/ @[to_additive "Map `AddMonoid.Coprod M N` to `AddMonoid.Coprod N M` by applying `Sum.swap` to each element of the underlying list. See also `AddEquiv.coprodComm` for an `AddEquiv` version."] def swap : M ∗ N →* N ∗ M := clift (mk.comp <| FreeMonoid.map Sum.swap) (by simp only [MonoidHom.comp_apply, map_of, Sum.swap_inl, mk_of_inr, map_one]) (by simp only [MonoidHom.comp_apply, map_of, Sum.swap_inr, mk_of_inl, map_one]) (fun x y => by simp only [MonoidHom.comp_apply, map_of, Sum.swap_inl, mk_of_inr, map_mul]) (fun x y => by simp only [MonoidHom.comp_apply, map_of, Sum.swap_inr, mk_of_inl, map_mul]) @[to_additive (attr := simp)] theorem swap_comp_swap : (swap M N).comp (swap N M) = .id _ := hom_ext rfl rfl variable {M N} @[to_additive (attr := simp)] theorem swap_swap (x : M ∗ N) : swap N M (swap M N x) = x := DFunLike.congr_fun (swap_comp_swap _ _) x @[to_additive] theorem swap_comp_map (f : M →* M') (g : N →* N') : (swap M' N').comp (map f g) = (map g f).comp (swap M N) := hom_ext rfl rfl @[to_additive] theorem swap_map (f : M →* M') (g : N →* N') (x : M ∗ N) : swap M' N' (map f g x) = map g f (swap M N x) := DFunLike.congr_fun (swap_comp_map f g) x @[to_additive (attr := simp)] theorem swap_comp_inl : (swap M N).comp inl = inr := rfl @[to_additive (attr := simp)] theorem swap_inl (x : M) : swap M N (inl x) = inr x := rfl @[to_additive (attr := simp)] theorem swap_comp_inr : (swap M N).comp inr = inl := rfl @[to_additive (attr := simp)] theorem swap_inr (x : N) : swap M N (inr x) = inl x := rfl @[to_additive] theorem swap_injective : Injective (swap M N) := LeftInverse.injective swap_swap @[to_additive (attr := simp)] theorem swap_inj {x y : M ∗ N} : swap M N x = swap M N y ↔ x = y := swap_injective.eq_iff @[to_additive (attr := simp)] theorem swap_eq_one {x : M ∗ N} : swap M N x = 1 ↔ x = 1 := swap_injective.eq_iff' (map_one _) @[to_additive] theorem swap_surjective : Surjective (swap M N) := LeftInverse.surjective swap_swap @[to_additive] theorem swap_bijective : Bijective (swap M N) := ⟨swap_injective, swap_surjective⟩ @[to_additive (attr := simp)] theorem mker_swap : MonoidHom.mker (swap M N) = ⊥ := Submonoid.ext fun _ ↦ swap_eq_one @[to_additive (attr := simp)] theorem mrange_swap : MonoidHom.mrange (swap M N) = ⊤ := MonoidHom.mrange_eq_top_of_surjective _ swap_surjective end MulOneClass section Lift variable {M N P : Type*} [MulOneClass M] [MulOneClass N] [Monoid P] /-- Lift a pair of monoid homomorphisms `f : M →* P`, `g : N →* P` to a monoid homomorphism `M ∗ N →* P`. See also `Coprod.clift` for a version that allows custom computational behavior and works for a `MulOneClass` codomain. -/ @[to_additive "Lift a pair of additive monoid homomorphisms `f : M →+ P`, `g : N →+ P` to an additive monoid homomorphism `AddMonoid.Coprod M N →+ P`. See also `AddMonoid.Coprod.clift` for a version that allows custom computational behavior and works for an `AddZeroClass` codomain."] def lift (f : M →* P) (g : N →* P) : (M ∗ N) →* P := clift (FreeMonoid.lift <| Sum.elim f g) (map_one f) (map_one g) (map_mul f) (map_mul g) @[to_additive (attr := simp)] theorem lift_apply_mk (f : M →* P) (g : N →* P) (x : FreeMonoid (M ⊕ N)) : lift f g (mk x) = FreeMonoid.lift (Sum.elim f g) x := rfl @[to_additive (attr := simp)] theorem lift_apply_inl (f : M →* P) (g : N →* P) (x : M) : lift f g (inl x) = f x := rfl @[to_additive] theorem lift_unique {f : M →* P} {g : N →* P} {fg : M ∗ N →* P} (h₁ : fg.comp inl = f) (h₂ : fg.comp inr = g) : fg = lift f g := hom_ext h₁ h₂ @[to_additive (attr := simp)] theorem lift_comp_inl (f : M →* P) (g : N →* P) : (lift f g).comp inl = f := rfl @[to_additive (attr := simp)] theorem lift_apply_inr (f : M →* P) (g : N →* P) (x : N) : lift f g (inr x) = g x := rfl @[to_additive (attr := simp)] theorem lift_comp_inr (f : M →* P) (g : N →* P) : (lift f g).comp inr = g := rfl @[to_additive (attr := simp)] theorem lift_comp_swap (f : M →* P) (g : N →* P) : (lift f g).comp (swap N M) = lift g f := hom_ext rfl rfl @[to_additive (attr := simp)] theorem lift_swap (f : M →* P) (g : N →* P) (x : N ∗ M) : lift f g (swap N M x) = lift g f x := DFunLike.congr_fun (lift_comp_swap f g) x @[to_additive] theorem comp_lift {P' : Type*} [Monoid P'] (f : P →* P') (g₁ : M →* P) (g₂ : N →* P) : f.comp (lift g₁ g₂) = lift (f.comp g₁) (f.comp g₂) := hom_ext (by rw [MonoidHom.comp_assoc, lift_comp_inl, lift_comp_inl]) <| by rw [MonoidHom.comp_assoc, lift_comp_inr, lift_comp_inr] /-- `Coprod.lift` as an equivalence. -/ @[to_additive "`AddMonoid.Coprod.lift` as an equivalence."] def liftEquiv : (M →* P) × (N →* P) ≃ (M ∗ N →* P) where toFun fg := lift fg.1 fg.2 invFun f := (f.comp inl, f.comp inr) left_inv _ := rfl right_inv _ := Eq.symm <| lift_unique rfl rfl @[to_additive (attr := simp)] theorem mrange_lift (f : M →* P) (g : N →* P) : MonoidHom.mrange (lift f g) = MonoidHom.mrange f ⊔ MonoidHom.mrange g := by simp [mrange_eq] end Lift section ToProd variable {M N : Type*} [Monoid M] [Monoid N] @[to_additive] instance : Monoid (M ∗ N) := { mul_assoc := (Con.monoid _).mul_assoc one_mul := (Con.monoid _).one_mul mul_one := (Con.monoid _).mul_one } /-- The natural projection `M ∗ N →* M`. -/ @[to_additive "The natural projection `AddMonoid.Coprod M N →+ M`."] def fst : M ∗ N →* M := lift (.id M) 1 /-- The natural projection `M ∗ N →* N`. -/ @[to_additive "The natural projection `AddMonoid.Coprod M N →+ N`."] def snd : M ∗ N →* N := lift 1 (.id N) /-- The natural projection `M ∗ N →* M × N`. -/ @[to_additive toProd "The natural projection `AddMonoid.Coprod M N →+ M × N`."] def toProd : M ∗ N →* M × N := lift (.inl _ _) (.inr _ _) @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.toSum := AddMonoid.Coprod.toProd @[to_additive (attr := simp)] theorem fst_comp_inl : (fst : M ∗ N →* M).comp inl = .id _ := rfl @[to_additive (attr := simp)] theorem fst_apply_inl (x : M) : fst (inl x : M ∗ N) = x := rfl @[to_additive (attr := simp)] theorem fst_comp_inr : (fst : M ∗ N →* M).comp inr = 1 := rfl @[to_additive (attr := simp)] theorem fst_apply_inr (x : N) : fst (inr x : M ∗ N) = 1 := rfl @[to_additive (attr := simp)] theorem snd_comp_inl : (snd : M ∗ N →* N).comp inl = 1 := rfl @[to_additive (attr := simp)] theorem snd_apply_inl (x : M) : snd (inl x : M ∗ N) = 1 := rfl @[to_additive (attr := simp)] theorem snd_comp_inr : (snd : M ∗ N →* N).comp inr = .id _ := rfl @[to_additive (attr := simp)] theorem snd_apply_inr (x : N) : snd (inr x : M ∗ N) = x := rfl @[to_additive (attr := simp) toProd_comp_inl] theorem toProd_comp_inl : (toProd : M ∗ N →* M × N).comp inl = .inl _ _ := rfl @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.toSum_comp_inl := AddMonoid.Coprod.toProd_comp_inl @[to_additive (attr := simp) toProd_comp_inr] theorem toProd_comp_inr : (toProd : M ∗ N →* M × N).comp inr = .inr _ _ := rfl @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.toSum_comp_inr := AddMonoid.Coprod.toProd_comp_inr @[to_additive (attr := simp) toProd_apply_inl] theorem toProd_apply_inl (x : M) : toProd (inl x : M ∗ N) = (x, 1) := rfl @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.toSum_apply_inl := AddMonoid.Coprod.toProd_apply_inl @[to_additive (attr := simp) toProd_apply_inr] theorem toProd_apply_inr (x : N) : toProd (inr x : M ∗ N) = (1, x) := rfl @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.toSum_apply_inr := AddMonoid.Coprod.toProd_apply_inr @[to_additive (attr := simp) fst_prod_snd] theorem fst_prod_snd : (fst : M ∗ N →* M).prod snd = toProd := by ext1 <;> rfl @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.fst_sum_snd := AddMonoid.Coprod.fst_prod_snd @[to_additive (attr := simp) prod_mk_fst_snd] theorem prod_mk_fst_snd (x : M ∗ N) : (fst x, snd x) = toProd x := by rw [← fst_prod_snd, MonoidHom.prod_apply] @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.sum_mk_fst_snd := AddMonoid.Coprod.prod_mk_fst_snd @[to_additive (attr := simp) fst_comp_toProd] theorem fst_comp_toProd : (MonoidHom.fst M N).comp toProd = fst := by rw [← fst_prod_snd, MonoidHom.fst_comp_prod] @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.fst_comp_toSum := AddMonoid.Coprod.fst_comp_toProd @[to_additive (attr := simp) fst_toProd] theorem fst_toProd (x : M ∗ N) : (toProd x).1 = fst x := by rw [← fst_comp_toProd]; rfl @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.fst_toSum := AddMonoid.Coprod.fst_toProd @[to_additive (attr := simp) snd_comp_toProd] theorem snd_comp_toProd : (MonoidHom.snd M N).comp toProd = snd := by rw [← fst_prod_snd, MonoidHom.snd_comp_prod] @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.snd_comp_toSum := AddMonoid.Coprod.snd_comp_toProd @[to_additive (attr := simp) snd_toProd] theorem snd_toProd (x : M ∗ N) : (toProd x).2 = snd x := by rw [← snd_comp_toProd]; rfl
@[deprecated (since := "2025-03-11")]
Mathlib/GroupTheory/Coprod/Basic.lean
558
559
/- 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 -/ import Mathlib.Algebra.CharP.Defs import Mathlib.Algebra.Order.CauSeq.BigOperators import Mathlib.Algebra.Order.Star.Basic import Mathlib.Data.Complex.BigOperators import Mathlib.Data.Complex.Norm import Mathlib.Data.Nat.Choose.Sum /-! # Exponential Function This file contains the definitions of the real and complex exponential function. ## Main definitions * `Complex.exp`: The complex exponential function, defined via its Taylor series * `Real.exp`: The real exponential function, defined as the real part of the complex exponential -/ open CauSeq Finset IsAbsoluteValue open scoped ComplexConjugate namespace Complex theorem isCauSeq_norm_exp (z : ℂ) : IsCauSeq abs fun n => ∑ m ∈ range n, ‖z ^ m / m.factorial‖ := let ⟨n, hn⟩ := exists_nat_gt ‖z‖ have hn0 : (0 : ℝ) < n := lt_of_le_of_lt (norm_nonneg _) hn IsCauSeq.series_ratio_test n (‖z‖ / n) (div_nonneg (norm_nonneg _) (le_of_lt hn0)) (by rwa [div_lt_iff₀ hn0, one_mul]) fun m hm => by rw [abs_norm, abs_norm, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul, ← div_div, mul_div_assoc, mul_div_right_comm, Complex.norm_mul, Complex.norm_div, norm_natCast] gcongr exact le_trans hm (Nat.le_succ _) @[deprecated (since := "2025-02-16")] alias isCauSeq_abs_exp := isCauSeq_norm_exp noncomputable section theorem isCauSeq_exp (z : ℂ) : IsCauSeq (‖·‖) fun n => ∑ m ∈ range n, z ^ m / m.factorial := (isCauSeq_norm_exp z).of_abv /-- The Cauchy sequence consisting of partial sums of the Taylor series of the complex exponential function -/ @[pp_nodot] def exp' (z : ℂ) : CauSeq ℂ (‖·‖) := ⟨fun n => ∑ m ∈ range n, z ^ m / m.factorial, isCauSeq_exp z⟩ /-- The complex exponential function, defined via its Taylor series -/ @[pp_nodot] def exp (z : ℂ) : ℂ := CauSeq.lim (exp' z) /-- scoped notation for the complex exponential function -/ scoped notation "cexp" => Complex.exp end end Complex namespace Real open Complex noncomputable section /-- The real exponential function, defined as the real part of the complex exponential -/ @[pp_nodot] nonrec def exp (x : ℝ) : ℝ := (exp x).re /-- scoped notation for the real exponential function -/ scoped notation "rexp" => Real.exp end end Real namespace Complex variable (x y : ℂ) @[simp] theorem exp_zero : exp 0 = 1 := by rw [exp] refine lim_eq_of_equiv_const fun ε ε0 => ⟨1, fun j hj => ?_⟩ convert (config := .unfoldSameFun) ε0 -- ε0 : ε > 0 but goal is _ < ε rcases j with - | j · exact absurd hj (not_le_of_gt zero_lt_one) · dsimp [exp'] induction' j with j ih · dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl] · rw [← ih (by simp [Nat.succ_le_succ])] simp only [sum_range_succ, pow_succ] simp theorem exp_add : exp (x + y) = exp x * exp y := by have hj : ∀ j : ℕ, (∑ m ∈ range j, (x + y) ^ m / m.factorial) = ∑ i ∈ range j, ∑ k ∈ range (i + 1), x ^ k / k.factorial * (y ^ (i - k) / (i - k).factorial) := by intro j refine Finset.sum_congr rfl fun m _ => ?_ rw [add_pow, div_eq_mul_inv, sum_mul] refine Finset.sum_congr rfl fun I hi => ?_ have h₁ : (m.choose I : ℂ) ≠ 0 := Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi)))) have h₂ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi) rw [← h₂, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv] simp only [mul_left_comm (m.choose I : ℂ), mul_assoc, mul_left_comm (m.choose I : ℂ)⁻¹, mul_comm (m.choose I : ℂ)] rw [inv_mul_cancel₀ h₁] simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm] simp_rw [exp, exp', lim_mul_lim] apply (lim_eq_lim_of_equiv _).symm simp only [hj] exact cauchy_product (isCauSeq_norm_exp x) (isCauSeq_exp y) /-- the exponential function as a monoid hom from `Multiplicative ℂ` to `ℂ` -/ @[simps] noncomputable def expMonoidHom : MonoidHom (Multiplicative ℂ) ℂ := { toFun := fun z => exp z.toAdd, map_one' := by simp, map_mul' := by simp [exp_add] } theorem exp_list_sum (l : List ℂ) : exp l.sum = (l.map exp).prod := map_list_prod (M := Multiplicative ℂ) expMonoidHom l theorem exp_multiset_sum (s : Multiset ℂ) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative ℂ) ℂ _ _ expMonoidHom s theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℂ) : exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (β := Multiplicative ℂ) expMonoidHom f s lemma exp_nsmul (x : ℂ) (n : ℕ) : exp (n • x) = exp x ^ n := @MonoidHom.map_pow (Multiplicative ℂ) ℂ _ _ expMonoidHom _ _ theorem exp_nat_mul (x : ℂ) : ∀ n : ℕ, exp (n * x) = exp x ^ n | 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero] | Nat.succ n => by rw [pow_succ, Nat.cast_add_one, add_mul, exp_add, ← exp_nat_mul _ n, one_mul] @[simp] theorem exp_ne_zero : exp x ≠ 0 := fun h => zero_ne_one (α := ℂ) <| by rw [← exp_zero, ← add_neg_cancel x, exp_add, h]; simp theorem exp_neg : exp (-x) = (exp x)⁻¹ := by rw [← mul_right_inj' (exp_ne_zero x), ← exp_add]; simp [mul_inv_cancel₀ (exp_ne_zero x)] theorem exp_sub : exp (x - y) = exp x / exp y := by simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv] theorem exp_int_mul (z : ℂ) (n : ℤ) : Complex.exp (n * z) = Complex.exp z ^ n := by cases n · simp [exp_nat_mul] · simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul] @[simp] theorem exp_conj : exp (conj x) = conj (exp x) := by dsimp [exp] rw [← lim_conj] refine congr_arg CauSeq.lim (CauSeq.ext fun _ => ?_) dsimp [exp', Function.comp_def, cauSeqConj] rw [map_sum (starRingEnd _)] refine sum_congr rfl fun n _ => ?_ rw [map_div₀, map_pow, ← ofReal_natCast, conj_ofReal] @[simp] theorem ofReal_exp_ofReal_re (x : ℝ) : ((exp x).re : ℂ) = exp x := conj_eq_iff_re.1 <| by rw [← exp_conj, conj_ofReal] @[simp, norm_cast] theorem ofReal_exp (x : ℝ) : (Real.exp x : ℂ) = exp x := ofReal_exp_ofReal_re _ @[simp] theorem exp_ofReal_im (x : ℝ) : (exp x).im = 0 := by rw [← ofReal_exp_ofReal_re, ofReal_im] theorem exp_ofReal_re (x : ℝ) : (exp x).re = Real.exp x := rfl end Complex namespace Real open Complex variable (x y : ℝ) @[simp] theorem exp_zero : exp 0 = 1 := by simp [Real.exp] nonrec theorem exp_add : exp (x + y) = exp x * exp y := by simp [exp_add, exp] /-- the exponential function as a monoid hom from `Multiplicative ℝ` to `ℝ` -/ @[simps] noncomputable def expMonoidHom : MonoidHom (Multiplicative ℝ) ℝ := { toFun := fun x => exp x.toAdd, map_one' := by simp, map_mul' := by simp [exp_add] } theorem exp_list_sum (l : List ℝ) : exp l.sum = (l.map exp).prod := map_list_prod (M := Multiplicative ℝ) expMonoidHom l theorem exp_multiset_sum (s : Multiset ℝ) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative ℝ) ℝ _ _ expMonoidHom s theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℝ) : exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (β := Multiplicative ℝ) expMonoidHom f s lemma exp_nsmul (x : ℝ) (n : ℕ) : exp (n • x) = exp x ^ n := @MonoidHom.map_pow (Multiplicative ℝ) ℝ _ _ expMonoidHom _ _ nonrec theorem exp_nat_mul (x : ℝ) (n : ℕ) : exp (n * x) = exp x ^ n := ofReal_injective (by simp [exp_nat_mul]) @[simp] nonrec theorem exp_ne_zero : exp x ≠ 0 := fun h => exp_ne_zero x <| by rw [exp, ← ofReal_inj] at h; simp_all nonrec theorem exp_neg : exp (-x) = (exp x)⁻¹ := ofReal_injective <| by simp [exp_neg] theorem exp_sub : exp (x - y) = exp x / exp y := by simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv] open IsAbsoluteValue Nat theorem sum_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) (n : ℕ) : ∑ i ∈ range n, x ^ i / i ! ≤ exp x := calc ∑ i ∈ range n, x ^ i / i ! ≤ lim (⟨_, isCauSeq_re (exp' x)⟩ : CauSeq ℝ abs) := by refine le_lim (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp only [exp', const_apply, re_sum] norm_cast refine sum_le_sum_of_subset_of_nonneg (range_mono hj) fun _ _ _ ↦ ?_ positivity _ = exp x := by rw [exp, Complex.exp, ← cauSeqRe, lim_re] lemma pow_div_factorial_le_exp (hx : 0 ≤ x) (n : ℕ) : x ^ n / n ! ≤ exp x := calc x ^ n / n ! ≤ ∑ k ∈ range (n + 1), x ^ k / k ! := single_le_sum (f := fun k ↦ x ^ k / k !) (fun k _ ↦ by positivity) (self_mem_range_succ n) _ ≤ exp x := sum_le_exp_of_nonneg hx _ theorem quadratic_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : 1 + x + x ^ 2 / 2 ≤ exp x := calc 1 + x + x ^ 2 / 2 = ∑ i ∈ range 3, x ^ i / i ! := by simp only [sum_range_succ, range_one, sum_singleton, _root_.pow_zero, factorial, cast_one, ne_eq, one_ne_zero, not_false_eq_true, div_self, pow_one, mul_one, div_one, Nat.mul_one, cast_succ, add_right_inj] ring_nf _ ≤ exp x := sum_le_exp_of_nonneg hx 3 private theorem add_one_lt_exp_of_pos {x : ℝ} (hx : 0 < x) : x + 1 < exp x := (by nlinarith : x + 1 < 1 + x + x ^ 2 / 2).trans_le (quadratic_le_exp_of_nonneg hx.le) private theorem add_one_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : x + 1 ≤ exp x := by rcases eq_or_lt_of_le hx with (rfl | h) · simp exact (add_one_lt_exp_of_pos h).le theorem one_le_exp {x : ℝ} (hx : 0 ≤ x) : 1 ≤ exp x := by linarith [add_one_le_exp_of_nonneg hx] @[bound] theorem exp_pos (x : ℝ) : 0 < exp x := (le_total 0 x).elim (lt_of_lt_of_le zero_lt_one ∘ one_le_exp) fun h => by rw [← neg_neg x, Real.exp_neg] exact inv_pos.2 (lt_of_lt_of_le zero_lt_one (one_le_exp (neg_nonneg.2 h))) @[bound] lemma exp_nonneg (x : ℝ) : 0 ≤ exp x := x.exp_pos.le @[simp] theorem abs_exp (x : ℝ) : |exp x| = exp x := abs_of_pos (exp_pos _) lemma exp_abs_le (x : ℝ) : exp |x| ≤ exp x + exp (-x) := by cases le_total x 0 <;> simp [abs_of_nonpos, abs_of_nonneg, exp_nonneg, *] @[mono] theorem exp_strictMono : StrictMono exp := fun x y h => by rw [← sub_add_cancel y x, Real.exp_add] exact (lt_mul_iff_one_lt_left (exp_pos _)).2 (lt_of_lt_of_le (by linarith) (add_one_le_exp_of_nonneg (by linarith))) @[gcongr] theorem exp_lt_exp_of_lt {x y : ℝ} (h : x < y) : exp x < exp y := exp_strictMono h @[mono] theorem exp_monotone : Monotone exp := exp_strictMono.monotone @[gcongr, bound] theorem exp_le_exp_of_le {x y : ℝ} (h : x ≤ y) : exp x ≤ exp y := exp_monotone h @[simp] theorem exp_lt_exp {x y : ℝ} : exp x < exp y ↔ x < y := exp_strictMono.lt_iff_lt @[simp] theorem exp_le_exp {x y : ℝ} : exp x ≤ exp y ↔ x ≤ y := exp_strictMono.le_iff_le theorem exp_injective : Function.Injective exp := exp_strictMono.injective @[simp] theorem exp_eq_exp {x y : ℝ} : exp x = exp y ↔ x = y := exp_injective.eq_iff @[simp] theorem exp_eq_one_iff : exp x = 1 ↔ x = 0 := exp_injective.eq_iff' exp_zero @[simp] theorem one_lt_exp_iff {x : ℝ} : 1 < exp x ↔ 0 < x := by rw [← exp_zero, exp_lt_exp] @[bound] private alias ⟨_, Bound.one_lt_exp_of_pos⟩ := one_lt_exp_iff @[simp] theorem exp_lt_one_iff {x : ℝ} : exp x < 1 ↔ x < 0 := by rw [← exp_zero, exp_lt_exp] @[simp] theorem exp_le_one_iff {x : ℝ} : exp x ≤ 1 ↔ x ≤ 0 := exp_zero ▸ exp_le_exp @[simp] theorem one_le_exp_iff {x : ℝ} : 1 ≤ exp x ↔ 0 ≤ x := exp_zero ▸ exp_le_exp end Real namespace Complex theorem sum_div_factorial_le {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α] (n j : ℕ) (hn : 0 < n) : (∑ m ∈ range j with n ≤ m, (1 / m.factorial : α)) ≤ n.succ / (n.factorial * n) := calc (∑ m ∈ range j with n ≤ m, (1 / m.factorial : α)) = ∑ m ∈ range (j - n), (1 / ((m + n).factorial : α)) := by refine sum_nbij' (· - n) (· + n) ?_ ?_ ?_ ?_ ?_ <;> simp +contextual [lt_tsub_iff_right, tsub_add_cancel_of_le] _ ≤ ∑ m ∈ range (j - n), ((n.factorial : α) * (n.succ : α) ^ m)⁻¹ := by simp_rw [one_div] gcongr rw [← Nat.cast_pow, ← Nat.cast_mul, Nat.cast_le, add_comm] exact Nat.factorial_mul_pow_le_factorial _ = (n.factorial : α)⁻¹ * ∑ m ∈ range (j - n), (n.succ : α)⁻¹ ^ m := by simp [mul_inv, ← mul_sum, ← sum_mul, mul_comm, inv_pow] _ = ((n.succ : α) - n.succ * (n.succ : α)⁻¹ ^ (j - n)) / (n.factorial * n) := by have h₁ : (n.succ : α) ≠ 1 := @Nat.cast_one α _ ▸ mt Nat.cast_inj.1 (mt Nat.succ.inj (pos_iff_ne_zero.1 hn)) have h₂ : (n.succ : α) ≠ 0 := by positivity have h₃ : (n.factorial * n : α) ≠ 0 := by positivity have h₄ : (n.succ - 1 : α) = n := by simp rw [geom_sum_inv h₁ h₂, eq_div_iff_mul_eq h₃, mul_comm _ (n.factorial * n : α), ← mul_assoc (n.factorial⁻¹ : α), ← mul_inv_rev, h₄, ← mul_assoc (n.factorial * n : α), mul_comm (n : α) n.factorial, mul_inv_cancel₀ h₃, one_mul, mul_comm] _ ≤ n.succ / (n.factorial * n : α) := by gcongr; apply sub_le_self; positivity theorem exp_bound {x : ℂ} (hx : ‖x‖ ≤ 1) {n : ℕ} (hn : 0 < n) : ‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹) := by rw [← lim_const (abv := norm) (∑ m ∈ range n, _), exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_norm] refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹) rw [sum_range_sub_sum_range hj] calc ‖∑ m ∈ range j with n ≤ m, (x ^ m / m.factorial : ℂ)‖ = ‖∑ m ∈ range j with n ≤ m, (x ^ n * (x ^ (m - n) / m.factorial) : ℂ)‖ := by refine congr_arg norm (sum_congr rfl fun m hm => ?_) rw [mem_filter, mem_range] at hm rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2] _ ≤ ∑ m ∈ range j with n ≤ m, ‖x ^ n * (x ^ (m - n) / m.factorial)‖ := IsAbsoluteValue.abv_sum norm .. _ ≤ ∑ m ∈ range j with n ≤ m, ‖x‖ ^ n * (1 / m.factorial) := by simp_rw [Complex.norm_mul, Complex.norm_pow, Complex.norm_div, norm_natCast] gcongr rw [Complex.norm_pow] exact pow_le_one₀ (norm_nonneg _) hx _ = ‖x‖ ^ n * ∑ m ∈ range j with n ≤ m, (1 / m.factorial : ℝ) := by simp [abs_mul, abv_pow abs, abs_div, ← mul_sum] _ ≤ ‖x‖ ^ n * (n.succ * (n.factorial * n : ℝ)⁻¹) := by gcongr exact sum_div_factorial_le _ _ hn theorem exp_bound' {x : ℂ} {n : ℕ} (hx : ‖x‖ / n.succ ≤ 1 / 2) : ‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n / n.factorial * 2 := by rw [← lim_const (abv := norm) (∑ m ∈ range n, _), exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_norm] refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n / n.factorial * 2 let k := j - n have hj : j = n + k := (add_tsub_cancel_of_le hj).symm rw [hj, sum_range_add_sub_sum_range] calc ‖∑ i ∈ range k, x ^ (n + i) / ((n + i).factorial : ℂ)‖ ≤ ∑ i ∈ range k, ‖x ^ (n + i) / ((n + i).factorial : ℂ)‖ := IsAbsoluteValue.abv_sum _ _ _ _ ≤ ∑ i ∈ range k, ‖x‖ ^ (n + i) / (n + i).factorial := by simp [norm_natCast, Complex.norm_pow] _ ≤ ∑ i ∈ range k, ‖x‖ ^ (n + i) / ((n.factorial : ℝ) * (n.succ : ℝ) ^ i) := ?_ _ = ∑ i ∈ range k, ‖x‖ ^ n / n.factorial * (‖x‖ ^ i / (n.succ : ℝ) ^ i) := ?_ _ ≤ ‖x‖ ^ n / ↑n.factorial * 2 := ?_ · gcongr exact mod_cast Nat.factorial_mul_pow_le_factorial · refine Finset.sum_congr rfl fun _ _ => ?_ simp only [pow_add, div_eq_inv_mul, mul_inv, mul_left_comm, mul_assoc] · rw [← mul_sum] gcongr simp_rw [← div_pow] rw [geom_sum_eq, div_le_iff_of_neg] · trans (-1 : ℝ) · linarith · simp only [neg_le_sub_iff_le_add, div_pow, Nat.cast_succ, le_add_iff_nonneg_left] positivity · linarith · linarith theorem norm_exp_sub_one_le {x : ℂ} (hx : ‖x‖ ≤ 1) : ‖exp x - 1‖ ≤ 2 * ‖x‖ := calc ‖exp x - 1‖ = ‖exp x - ∑ m ∈ range 1, x ^ m / m.factorial‖ := by simp [sum_range_succ] _ ≤ ‖x‖ ^ 1 * ((Nat.succ 1 : ℝ) * ((Nat.factorial 1) * (1 : ℕ) : ℝ)⁻¹) := (exp_bound hx (by decide)) _ = 2 * ‖x‖ := by simp [two_mul, mul_two, mul_add, mul_comm, add_mul, Nat.factorial] theorem norm_exp_sub_one_sub_id_le {x : ℂ} (hx : ‖x‖ ≤ 1) : ‖exp x - 1 - x‖ ≤ ‖x‖ ^ 2 := calc ‖exp x - 1 - x‖ = ‖exp x - ∑ m ∈ range 2, x ^ m / m.factorial‖ := by simp [sub_eq_add_neg, sum_range_succ_comm, add_assoc, Nat.factorial] _ ≤ ‖x‖ ^ 2 * ((Nat.succ 2 : ℝ) * (Nat.factorial 2 * (2 : ℕ) : ℝ)⁻¹) := (exp_bound hx (by decide)) _ ≤ ‖x‖ ^ 2 * 1 := by gcongr; norm_num [Nat.factorial] _ = ‖x‖ ^ 2 := by rw [mul_one] lemma norm_exp_sub_sum_le_exp_norm_sub_sum (x : ℂ) (n : ℕ) : ‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ Real.exp ‖x‖ - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by rw [← CauSeq.lim_const (abv := norm) (∑ m ∈ range n, _), Complex.exp, sub_eq_add_neg, ← CauSeq.lim_neg, CauSeq.lim_add, ← lim_norm] refine CauSeq.lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] calc ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ _ ≤ (∑ m ∈ range j, ‖x‖ ^ m / m.factorial) - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by rw [sum_range_sub_sum_range hj, sum_range_sub_sum_range hj] refine (IsAbsoluteValue.abv_sum norm ..).trans_eq ?_ congr with i simp [Complex.norm_pow] _ ≤ Real.exp ‖x‖ - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by gcongr exact Real.sum_le_exp_of_nonneg (norm_nonneg _) _ lemma norm_exp_le_exp_norm (x : ℂ) : ‖exp x‖ ≤ Real.exp ‖x‖ := by convert norm_exp_sub_sum_le_exp_norm_sub_sum x 0 using 1 <;> simp lemma norm_exp_sub_sum_le_norm_mul_exp (x : ℂ) (n : ℕ) : ‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n * Real.exp ‖x‖ := by rw [← CauSeq.lim_const (abv := norm) (∑ m ∈ range n, _), Complex.exp, sub_eq_add_neg, ← CauSeq.lim_neg, CauSeq.lim_add, ← lim_norm] refine CauSeq.lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ _ rw [sum_range_sub_sum_range hj] calc ‖∑ m ∈ range j with n ≤ m, (x ^ m / m.factorial : ℂ)‖ = ‖∑ m ∈ range j with n ≤ m, (x ^ n * (x ^ (m - n) / m.factorial) : ℂ)‖ := by refine congr_arg norm (sum_congr rfl fun m hm => ?_) rw [mem_filter, mem_range] at hm rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2] _ ≤ ∑ m ∈ range j with n ≤ m, ‖x ^ n * (x ^ (m - n) / m.factorial)‖ := IsAbsoluteValue.abv_sum norm .. _ ≤ ∑ m ∈ range j with n ≤ m, ‖x‖ ^ n * (‖x‖ ^ (m - n) / (m - n).factorial) := by simp_rw [Complex.norm_mul, Complex.norm_pow, Complex.norm_div, norm_natCast] gcongr with i hi · rw [Complex.norm_pow] · simp _ = ‖x‖ ^ n * ∑ m ∈ range j with n ≤ m, (‖x‖ ^ (m - n) / (m - n).factorial) := by rw [← mul_sum] _ = ‖x‖ ^ n * ∑ m ∈ range (j - n), (‖x‖ ^ m / m.factorial) := by congr 1 refine (sum_bij (fun m hm ↦ m + n) ?_ ?_ ?_ ?_).symm · intro a ha simp only [mem_filter, mem_range, le_add_iff_nonneg_left, zero_le, and_true] simp only [mem_range] at ha rwa [← lt_tsub_iff_right] · intro a ha b hb hab simpa using hab · intro b hb simp only [mem_range, exists_prop] simp only [mem_filter, mem_range] at hb refine ⟨b - n, ?_, ?_⟩ · rw [tsub_lt_tsub_iff_right hb.2] exact hb.1 · rw [tsub_add_cancel_of_le hb.2] · simp _ ≤ ‖x‖ ^ n * Real.exp ‖x‖ := by gcongr refine Real.sum_le_exp_of_nonneg ?_ _ exact norm_nonneg _ @[deprecated (since := "2025-02-16")] alias abs_exp_sub_one_le := norm_exp_sub_one_le @[deprecated (since := "2025-02-16")] alias abs_exp_sub_one_sub_id_le := norm_exp_sub_one_sub_id_le @[deprecated (since := "2025-02-16")] alias abs_exp_sub_sum_le_exp_abs_sub_sum := norm_exp_sub_sum_le_exp_norm_sub_sum @[deprecated (since := "2025-02-16")] alias abs_exp_le_exp_abs := norm_exp_le_exp_norm @[deprecated (since := "2025-02-16")] alias abs_exp_sub_sum_le_abs_mul_exp := norm_exp_sub_sum_le_norm_mul_exp end Complex namespace Real open Complex Finset nonrec theorem exp_bound {x : ℝ} (hx : |x| ≤ 1) {n : ℕ} (hn : 0 < n) : |exp x - ∑ m ∈ range n, x ^ m / m.factorial| ≤ |x| ^ n * (n.succ / (n.factorial * n)) := by have hxc : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx convert exp_bound hxc hn using 2 <;> norm_cast theorem exp_bound' {x : ℝ} (h1 : 0 ≤ x) (h2 : x ≤ 1) {n : ℕ} (hn : 0 < n) : Real.exp x ≤ (∑ m ∈ Finset.range n, x ^ m / m.factorial) + x ^ n * (n + 1) / (n.factorial * n) := by have h3 : |x| = x := by simpa have h4 : |x| ≤ 1 := by rwa [h3] have h' := Real.exp_bound h4 hn rw [h3] at h' have h'' := (abs_sub_le_iff.1 h').1 have t := sub_le_iff_le_add'.1 h'' simpa [mul_div_assoc] using t theorem abs_exp_sub_one_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1| ≤ 2 * |x| := by have : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx exact_mod_cast Complex.norm_exp_sub_one_le (x := x) this theorem abs_exp_sub_one_sub_id_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1 - x| ≤ x ^ 2 := by rw [← sq_abs] have : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx exact_mod_cast Complex.norm_exp_sub_one_sub_id_le this /-- A finite initial segment of the exponential series, followed by an arbitrary tail. For fixed `n` this is just a linear map wrt `r`, and each map is a simple linear function of the previous (see `expNear_succ`), with `expNear n x r ⟶ exp x` as `n ⟶ ∞`, for any `r`. -/ noncomputable def expNear (n : ℕ) (x r : ℝ) : ℝ := (∑ m ∈ range n, x ^ m / m.factorial) + x ^ n / n.factorial * r @[simp] theorem expNear_zero (x r) : expNear 0 x r = r := by simp [expNear] @[simp] theorem expNear_succ (n x r) : expNear (n + 1) x r = expNear n x (1 + x / (n + 1) * r) := by simp [expNear, range_succ, mul_add, add_left_comm, add_assoc, pow_succ, div_eq_mul_inv, mul_inv, Nat.factorial] ac_rfl theorem expNear_sub (n x r₁ r₂) : expNear n x r₁ - expNear n x r₂ = x ^ n / n.factorial * (r₁ - r₂) := by simp [expNear, mul_sub] theorem exp_approx_end (n m : ℕ) (x : ℝ) (e₁ : n + 1 = m) (h : |x| ≤ 1) : |exp x - expNear m x 0| ≤ |x| ^ m / m.factorial * ((m + 1) / m) := by simp only [expNear, mul_zero, add_zero] convert exp_bound (n := m) h ?_ using 1 · field_simp [mul_comm] · omega theorem exp_approx_succ {n} {x a₁ b₁ : ℝ} (m : ℕ) (e₁ : n + 1 = m) (a₂ b₂ : ℝ) (e : |1 + x / m * a₂ - a₁| ≤ b₁ - |x| / m * b₂) (h : |exp x - expNear m x a₂| ≤ |x| ^ m / m.factorial * b₂) : |exp x - expNear n x a₁| ≤ |x| ^ n / n.factorial * b₁ := by refine (abs_sub_le _ _ _).trans ((add_le_add_right h _).trans ?_) subst e₁; rw [expNear_succ, expNear_sub, abs_mul] convert mul_le_mul_of_nonneg_left (a := |x| ^ n / ↑(Nat.factorial n)) (le_sub_iff_add_le'.1 e) ?_ using 1 · simp [mul_add, pow_succ', div_eq_mul_inv, abs_mul, abs_inv, ← pow_abs, mul_inv, Nat.factorial] ac_rfl · simp [div_nonneg, abs_nonneg] theorem exp_approx_end' {n} {x a b : ℝ} (m : ℕ) (e₁ : n + 1 = m) (rm : ℝ) (er : ↑m = rm) (h : |x| ≤ 1) (e : |1 - a| ≤ b - |x| / rm * ((rm + 1) / rm)) : |exp x - expNear n x a| ≤ |x| ^ n / n.factorial * b := by subst er exact exp_approx_succ _ e₁ _ _ (by simpa using e) (exp_approx_end _ _ _ e₁ h) theorem exp_1_approx_succ_eq {n} {a₁ b₁ : ℝ} {m : ℕ} (en : n + 1 = m) {rm : ℝ} (er : ↑m = rm) (h : |exp 1 - expNear m 1 ((a₁ - 1) * rm)| ≤ |1| ^ m / m.factorial * (b₁ * rm)) : |exp 1 - expNear n 1 a₁| ≤ |1| ^ n / n.factorial * b₁ := by subst er refine exp_approx_succ _ en _ _ ?_ h field_simp [show (m : ℝ) ≠ 0 by norm_cast; omega] theorem exp_approx_start (x a b : ℝ) (h : |exp x - expNear 0 x a| ≤ |x| ^ 0 / Nat.factorial 0 * b) : |exp x - a| ≤ b := by simpa using h theorem exp_bound_div_one_sub_of_interval' {x : ℝ} (h1 : 0 < x) (h2 : x < 1) : Real.exp x < 1 / (1 - x) := by have H : 0 < 1 - (1 + x + x ^ 2) * (1 - x) := calc 0 < x ^ 3 := by positivity _ = 1 - (1 + x + x ^ 2) * (1 - x) := by ring calc exp x ≤ _ := exp_bound' h1.le h2.le zero_lt_three _ ≤ 1 + x + x ^ 2 := by -- Porting note: was `norm_num [Finset.sum] <;> nlinarith` -- This proof should be restored after the norm_num plugin for big operators is ported. -- (It may also need the positivity extensions in https://github.com/leanprover-community/mathlib4/pull/3907.) rw [show 3 = 1 + 1 + 1 from rfl] repeat rw [Finset.sum_range_succ] norm_num [Nat.factorial] nlinarith _ < 1 / (1 - x) := by rw [lt_div_iff₀] <;> nlinarith theorem exp_bound_div_one_sub_of_interval {x : ℝ} (h1 : 0 ≤ x) (h2 : x < 1) : Real.exp x ≤ 1 / (1 - x) := by rcases eq_or_lt_of_le h1 with (rfl | h1) · simp · exact (exp_bound_div_one_sub_of_interval' h1 h2).le theorem add_one_lt_exp {x : ℝ} (hx : x ≠ 0) : x + 1 < Real.exp x := by obtain hx | hx := hx.symm.lt_or_lt · exact add_one_lt_exp_of_pos hx obtain h' | h' := le_or_lt 1 (-x) · linarith [x.exp_pos] have hx' : 0 < x + 1 := by linarith simpa [add_comm, exp_neg, inv_lt_inv₀ (exp_pos _) hx'] using exp_bound_div_one_sub_of_interval' (neg_pos.2 hx) h' theorem add_one_le_exp (x : ℝ) : x + 1 ≤ Real.exp x := by obtain rfl | hx := eq_or_ne x 0 · simp · exact (add_one_lt_exp hx).le lemma one_sub_lt_exp_neg {x : ℝ} (hx : x ≠ 0) : 1 - x < exp (-x) := (sub_eq_neg_add _ _).trans_lt <| add_one_lt_exp <| neg_ne_zero.2 hx lemma one_sub_le_exp_neg (x : ℝ) : 1 - x ≤ exp (-x) := (sub_eq_neg_add _ _).trans_le <| add_one_le_exp _ theorem one_sub_div_pow_le_exp_neg {n : ℕ} {t : ℝ} (ht' : t ≤ n) : (1 - t / n) ^ n ≤ exp (-t) := by rcases eq_or_ne n 0 with (rfl | hn) · simp rwa [Nat.cast_zero] at ht' calc (1 - t / n) ^ n ≤ rexp (-(t / n)) ^ n := by gcongr · exact sub_nonneg.2 <| div_le_one_of_le₀ ht' n.cast_nonneg · exact one_sub_le_exp_neg _ _ = rexp (-t) := by rw [← Real.exp_nat_mul, mul_neg, mul_comm, div_mul_cancel₀]; positivity lemma le_inv_mul_exp (x : ℝ) {c : ℝ} (hc : 0 < c) : x ≤ c⁻¹ * exp (c * x) := by rw [le_inv_mul_iff₀ hc] calc c * x _ ≤ c * x + 1 := le_add_of_nonneg_right zero_le_one _ ≤ _ := Real.add_one_le_exp (c * x) end Real namespace Mathlib.Meta.Positivity open Lean.Meta Qq /-- Extension for the `positivity` tactic: `Real.exp` is always positive. -/ @[positivity Real.exp _] def evalExp : PositivityExt where eval {u α} _ _ e := do match u, α, e with | 0, ~q(ℝ), ~q(Real.exp $a) => assertInstancesCommute pure (.positive q(Real.exp_pos $a)) | _, _, _ => throwError "not Real.exp" end Mathlib.Meta.Positivity namespace Complex @[simp] theorem norm_exp_ofReal (x : ℝ) : ‖exp x‖ = Real.exp x := by rw [← ofReal_exp] exact Complex.norm_of_nonneg (le_of_lt (Real.exp_pos _)) @[deprecated (since := "2025-02-16")] alias abs_exp_ofReal := norm_exp_ofReal end Complex
Mathlib/Data/Complex/Exponential.lean
1,075
1,076
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Lie.Semisimple.Defs import Mathlib.Order.BooleanGenerators /-! # Semisimple Lie algebras The famous Cartan-Dynkin-Killing classification of semisimple Lie algebras renders them one of the most important classes of Lie algebras. In this file we prove basic results about simple and semisimple Lie algebras. ## Main declarations * `LieAlgebra.IsSemisimple.instHasTrivialRadical`: A semisimple Lie algebra has trivial radical. * `LieAlgebra.IsSemisimple.instBooleanAlgebra`: The lattice of ideals in a semisimple Lie algebra is a boolean algebra. In particular, this implies that the lattice of ideals is atomistic: every ideal is a direct sum of atoms (simple ideals) in a unique way. * `LieAlgebra.hasTrivialRadical_iff_no_solvable_ideals` * `LieAlgebra.hasTrivialRadical_iff_no_abelian_ideals` * `LieAlgebra.abelian_radical_iff_solvable_is_abelian` ## Tags lie algebra, radical, simple, semisimple -/ section Irreducible variable (R L M : Type*) [CommRing R] [LieRing L] [AddCommGroup M] [Module R M] [LieRingModule L M] lemma LieModule.nontrivial_of_isIrreducible [LieModule.IsIrreducible R L M] : Nontrivial M where exists_pair_ne := by have aux : (⊥ : LieSubmodule R L M) ≠ ⊤ := bot_ne_top contrapose! aux ext m simpa using aux m 0 end Irreducible namespace LieAlgebra variable (R L : Type*) [CommRing R] [LieRing L] [LieAlgebra R L] variable {R L} in theorem HasTrivialRadical.eq_bot_of_isSolvable [HasTrivialRadical R L] (I : LieIdeal R L) [hI : IsSolvable I] : I = ⊥ := sSup_eq_bot.mp radical_eq_bot _ hI instance [HasTrivialRadical R L] : LieModule.IsFaithful R L L := by rw [isFaithful_self_iff] exact HasTrivialRadical.eq_bot_of_isSolvable _ variable {R L} in theorem hasTrivialRadical_of_no_solvable_ideals (h : ∀ I : LieIdeal R L, IsSolvable I → I = ⊥) : HasTrivialRadical R L := ⟨sSup_eq_bot.mpr h⟩ theorem hasTrivialRadical_iff_no_solvable_ideals : HasTrivialRadical R L ↔ ∀ I : LieIdeal R L, IsSolvable I → I = ⊥ := ⟨@HasTrivialRadical.eq_bot_of_isSolvable _ _ _ _ _, hasTrivialRadical_of_no_solvable_ideals⟩ theorem hasTrivialRadical_iff_no_abelian_ideals : HasTrivialRadical R L ↔ ∀ I : LieIdeal R L, IsLieAbelian I → I = ⊥ := by rw [hasTrivialRadical_iff_no_solvable_ideals] constructor <;> intro h₁ I h₂ · exact h₁ _ <| LieAlgebra.ofAbelianIsSolvable I · rw [← abelian_of_solvable_ideal_eq_bot_iff] exact h₁ _ <| abelian_derivedAbelianOfIdeal I namespace IsSimple variable [IsSimple R L] instance : LieModule.IsIrreducible R L L := by suffices Nontrivial (LieIdeal R L) from ⟨IsSimple.eq_bot_or_eq_top⟩ rw [LieSubmodule.nontrivial_iff, ← not_subsingleton_iff_nontrivial] have _i : ¬ IsLieAbelian L := IsSimple.non_abelian R contrapose! _i infer_instance protected lemma isAtom_top : IsAtom (⊤ : LieIdeal R L) := isAtom_top variable {R L} in protected lemma isAtom_iff_eq_top (I : LieIdeal R L) : IsAtom I ↔ I = ⊤ := isAtom_iff_eq_top variable {R L} in lemma eq_top_of_isAtom (I : LieIdeal R L) (hI : IsAtom I) : I = ⊤ := isAtom_iff_eq_top.mp hI instance : HasTrivialRadical R L := by rw [hasTrivialRadical_iff_no_abelian_ideals] intro I hI apply (IsSimple.eq_bot_or_eq_top I).resolve_right rintro rfl rw [lie_abelian_iff_equiv_lie_abelian LieIdeal.topEquiv] at hI exact IsSimple.non_abelian R (L := L) hI end IsSimple namespace IsSemisimple open CompleteLattice IsCompactlyGenerated variable {R L} variable [IsSemisimple R L] lemma isSimple_of_isAtom (I : LieIdeal R L) (hI : IsAtom I) : IsSimple R I where non_abelian := IsSemisimple.non_abelian_of_isAtom I hI eq_bot_or_eq_top := by -- Suppose that `J` is an ideal of `I`. intro J -- We first show that `J` is also an ideal of the ambient Lie algebra `L`. let J' : LieIdeal R L := { __ := J.toSubmodule.map I.incl.toLinearMap lie_mem := by rintro x _ ⟨y, hy, rfl⟩ -- We need to show that `⁅x, y⁆ ∈ J` for any `x ∈ L` and `y ∈ J`. -- Since `L` is semisimple, `x` is contained -- in the supremum of `I` and the atoms not equal to `I`. have hx : x ∈ I ⊔ sSup ({I' : LieIdeal R L | IsAtom I'} \ {I}) := by nth_rewrite 1 [← sSup_singleton (a := I)] rw [← sSup_union, Set.union_diff_self, Set.union_eq_self_of_subset_left, IsSemisimple.sSup_atoms_eq_top] · apply LieSubmodule.mem_top · simp only [Set.singleton_subset_iff, Set.mem_setOf_eq, hI] -- Hence we can write `x` as `a + b` with `a ∈ I` -- and `b` in the supremum of the atoms not equal to `I`. rw [LieSubmodule.mem_sup] at hx obtain ⟨a, ha, b, hb, rfl⟩ := hx -- Therefore it suffices to show that `⁅a, y⁆ ∈ J` and `⁅b, y⁆ ∈ J`. simp only [Submodule.carrier_eq_coe, add_lie, SetLike.mem_coe] apply add_mem -- Now `⁅a, y⁆ ∈ J` since `a ∈ I`, `y ∈ J`, and `J` is an ideal of `I`. · simp only [Submodule.mem_map, LieSubmodule.mem_toSubmodule, Subtype.exists] erw [Submodule.coe_subtype] simp only [exists_and_right, exists_eq_right, ha, lie_mem_left, exists_true_left] exact lie_mem_right R I J ⟨a, ha⟩ y hy -- Finally `⁅b, y⁆ = 0`, by the independence of the atoms. · suffices ⁅b, y.val⁆ = 0 by erw [this]; simp only [zero_mem] rw [← LieSubmodule.mem_bot (R := R) (L := L), ← (IsSemisimple.sSupIndep_isAtom hI).eq_bot] exact ⟨lie_mem_right R L I b y y.2, lie_mem_left _ _ _ _ _ hb⟩ } -- Now that we know that `J` is an ideal of `L`, -- we start with the proof that `I` is a simple Lie algebra. -- Assume that `J ≠ ⊤`. rw [or_iff_not_imp_right] intro hJ suffices J' = ⊥ by rw [eq_bot_iff] at this ⊢ intro x hx suffices x ∈ J → x = 0 from this hx have := @this x.1 simp only [LieIdeal.incl_coe, LieIdeal.toLieSubalgebra_toSubmodule, LieSubmodule.mem_mk_iff', Submodule.mem_map, LieSubmodule.mem_toSubmodule, Subtype.exists, LieSubmodule.mem_bot, ZeroMemClass.coe_eq_zero, forall_exists_index, and_imp, J'] at this exact fun _ ↦ this (↑x) x.property hx rfl -- We need to show that `J = ⊥`. -- Since `J` is an ideal of `L`, and `I` is an atom, -- it suffices to show that `J < I`. apply hI.2 rw [lt_iff_le_and_ne] constructor -- We know that `J ≤ I` since `J` is an ideal of `I`. · rintro _ ⟨x, -, rfl⟩ exact x.2 -- So we need to show `J ≠ I` as ideals of `L`. -- This follows from our assumption that `J ≠ ⊤` as ideals of `I`. contrapose! hJ rw [eq_top_iff] rintro ⟨x, hx⟩ - rw [← hJ] at hx rcases hx with ⟨y, hy, rfl⟩ exact hy /-- In a semisimple Lie algebra, Lie ideals that are contained in the supremum of a finite collection of atoms are themselves the supremum of a finite subcollection of those atoms. By a compactness argument, this statement can be extended to arbitrary sets of atoms. See `atomistic`. The proof is by induction on the finite set of atoms. -/ private lemma finitelyAtomistic : ∀ s : Finset (LieIdeal R L), ↑s ⊆ {I : LieIdeal R L | IsAtom I} → ∀ I : LieIdeal R L, I ≤ s.sup id → ∃ t ⊆ s, I = t.sup id := by intro s hs I hI let S := {I : LieIdeal R L | IsAtom I} obtain rfl | hI := hI.eq_or_lt · exact ⟨s, Finset.Subset.rfl, rfl⟩ -- We assume that `I` is strictly smaller than the supremum of `s`. -- Hence there must exist an atom `J` that is not contained in `I`. obtain ⟨J, hJs, hJI⟩ : ∃ J ∈ s, ¬ J ≤ I := by by_contra! H exact hI.ne (le_antisymm hI.le (s.sup_le H)) classical let s' := s.erase J have hs' : s' ⊂ s := Finset.erase_ssubset hJs have hs'S : ↑s' ⊆ S := Set.Subset.trans (Finset.coe_subset.mpr hs'.subset) hs -- If we show that `I` is contained in the supremum `K` of the complement of `J` in `s`, -- then we are done by recursion. set K := s'.sup id suffices I ≤ K by obtain ⟨t, hts', htI⟩ := finitelyAtomistic s' hs'S I this #adaptation_note /-- https://github.com/leanprover/lean4/pull/6024 we could write `hts'.trans hs'.subset` instead of `Finset.Subset.trans hts' hs'.subset` in the next line. -/ exact ⟨t, Finset.Subset.trans hts' hs'.subset, htI⟩ -- Since `I` is contained in the supremum of `J` with the supremum of `s'`, -- any element `x` of `I` can be written as `y + z` for some `y ∈ J` and `z ∈ K`. intro x hx obtain ⟨y, hy, z, hz, rfl⟩ : ∃ y ∈ id J, ∃ z ∈ K, y + z = x := by rw [← LieSubmodule.mem_sup, ← Finset.sup_insert, Finset.insert_erase hJs] exact hI.le hx -- If we show that `y` is contained in the center of `J`, -- then we find `x = z`, and hence `x` is contained in the supremum of `s'`. -- Since `x` was arbitrary, we have shown that `I` is contained in the supremum of `s'`. suffices ⟨y, hy⟩ ∈ LieAlgebra.center R J by have _inst := isSimple_of_isAtom J (hs hJs) rw [center_eq_bot R J, LieSubmodule.mem_bot] at this apply_fun Subtype.val at this dsimp at this rwa [this, zero_add] -- To show that `y` is in the center of `J`, -- we show that any `j ∈ J` brackets to `0` with `z` and with `x = y + z`. -- By a simple computation, that implies `⁅j, y⁆ = 0`, for all `j`, as desired. intro j suffices ⁅(j : L), z⁆ = 0 ∧ ⁅(j : L), y + z⁆ = 0 by rw [lie_add, this.1, add_zero] at this ext exact this.2 rw [← LieSubmodule.mem_bot (R := R) (L := L), ← LieSubmodule.mem_bot (R := R) (L := L)] constructor -- `j` brackets to `0` with `z`, since `⁅j, z⁆` is contained in `⁅J, K⁆ ≤ J ⊓ K`, -- and `J ⊓ K = ⊥` by the independence of the atoms. · apply (sSupIndep_isAtom.disjoint_sSup (hs hJs) hs'S (Finset.not_mem_erase _ _)).le_bot apply LieSubmodule.lie_le_inf apply LieSubmodule.lie_mem_lie j.2 simpa only [K, Finset.sup_id_eq_sSup] using hz -- By similar reasoning, `j` brackets to `0` with `x = y + z ∈ I`, if we show `J ⊓ I = ⊥`. suffices J ⊓ I = ⊥ by apply this.le apply LieSubmodule.lie_le_inf exact LieSubmodule.lie_mem_lie j.2 hx -- Indeed `J ⊓ I = ⊥`, since `J` is an atom that is not contained in `I`. apply ((hs hJs).le_iff.mp _).resolve_right · contrapose! hJI rw [← hJI] exact inf_le_right exact inf_le_left termination_by s => s.card decreasing_by exact Finset.card_lt_card hs' variable (R L) in lemma booleanGenerators : BooleanGenerators {I : LieIdeal R L | IsAtom I} where isAtom _ hI := hI finitelyAtomistic _ _ hs _ hIs := finitelyAtomistic _ hs _ hIs instance (priority := 100) instDistribLattice : DistribLattice (LieIdeal R L) := (booleanGenerators R L).distribLattice_of_sSup_eq_top sSup_atoms_eq_top noncomputable instance (priority := 100) instBooleanAlgebra : BooleanAlgebra (LieIdeal R L) := (booleanGenerators R L).booleanAlgebra_of_sSup_eq_top sSup_atoms_eq_top /-- A semisimple Lie algebra has trivial radical. -/ instance (priority := 100) instHasTrivialRadical : HasTrivialRadical R L := by rw [hasTrivialRadical_iff_no_abelian_ideals] intro I hI apply (eq_bot_or_exists_atom_le I).resolve_right rintro ⟨J, hJ, hJ'⟩ apply IsSemisimple.non_abelian_of_isAtom J hJ constructor intro x y ext simp only [LieIdeal.coe_bracket_of_module, LieSubmodule.coe_bracket, ZeroMemClass.coe_zero] have : (⁅(⟨x, hJ' x.2⟩ : I), ⟨y, hJ' y.2⟩⁆ : I) = 0 := trivial_lie_zero _ _ _ _ apply_fun Subtype.val at this exact this end IsSemisimple /-- A simple Lie algebra is semisimple. -/ instance (priority := 100) IsSimple.instIsSemisimple [IsSimple R L] : IsSemisimple R L := by constructor · simp · simpa using sSupIndep_singleton _ · intro I hI₁ hI₂ apply IsSimple.non_abelian (R := R) (L := L) rw [IsSimple.isAtom_iff_eq_top] at hI₁ rwa [hI₁, lie_abelian_iff_equiv_lie_abelian LieIdeal.topEquiv] at hI₂ /-- An abelian Lie algebra with trivial radical is trivial. -/ theorem subsingleton_of_hasTrivialRadical_lie_abelian [HasTrivialRadical R L] [h : IsLieAbelian L] : Subsingleton L := by rw [isLieAbelian_iff_center_eq_top R L, center_eq_bot] at h exact (LieSubmodule.subsingleton_iff R L L).mp (subsingleton_of_bot_eq_top h) theorem abelian_radical_of_hasTrivialRadical [HasTrivialRadical R L] : IsLieAbelian (radical R L) := by rw [HasTrivialRadical.radical_eq_bot]; exact LieIdeal.isLieAbelian_of_trivial .. theorem abelian_radical_iff_solvable_is_abelian [IsNoetherian R L] : IsLieAbelian (radical R L) ↔ ∀ I : LieIdeal R L, IsSolvable I → IsLieAbelian I := by constructor · rintro h₁ I h₂ rw [LieIdeal.solvable_iff_le_radical] at h₂ exact (LieIdeal.inclusion_injective h₂).isLieAbelian h₁ · intro h; apply h; infer_instance theorem ad_ker_eq_bot_of_hasTrivialRadical [HasTrivialRadical R L] : (ad R L).ker = ⊥ := by simp end LieAlgebra
Mathlib/Algebra/Lie/Semisimple/Basic.lean
327
327
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Justus Springer -/ import Mathlib.Topology.Category.TopCat.OpenNhds import Mathlib.Topology.Sheaves.SheafCondition.UniqueGluing /-! # Stalks For a presheaf `F` on a topological space `X`, valued in some category `C`, the *stalk* of `F` at the point `x : X` is defined as the colimit of the composition of the inclusion of categories `(OpenNhds x)ᵒᵖ ⥤ (Opens X)ᵒᵖ` and the functor `F : (Opens X)ᵒᵖ ⥤ C`. For an open neighborhood `U` of `x`, we define the map `F.germ x : F.obj (op U) ⟶ F.stalk x` as the canonical morphism into this colimit. Taking stalks is functorial: For every point `x : X` we define a functor `stalkFunctor C x`, sending presheaves on `X` to objects of `C`. Furthermore, for a map `f : X ⟶ Y` between topological spaces, we define `stalkPushforward` as the induced map on the stalks `(f _* ℱ).stalk (f x) ⟶ ℱ.stalk x`. Some lemmas about stalks and germs only hold for certain classes of concrete categories. A basic property of forgetful functors of categories of algebraic structures (like `MonCat`, `CommRingCat`,...) is that they preserve filtered colimits. Since stalks are filtered colimits, this ensures that the stalks of presheaves valued in these categories behave exactly as for `Type`-valued presheaves. For example, in `germ_exist` we prove that in such a category, every element of the stalk is the germ of a section. Furthermore, if we require the forgetful functor to reflect isomorphisms and preserve limits (as is the case for most algebraic structures), we have access to the unique gluing API and can prove further properties. Most notably, in `is_iso_iff_stalk_functor_map_iso`, we prove that in such a category, a morphism of sheaves is an isomorphism if and only if all of its stalk maps are isomorphisms. See also the definition of "algebraic structures" in the stacks project: https://stacks.math.columbia.edu/tag/007L -/ assert_not_exists OrderedCommMonoid noncomputable section universe v u v' u' open CategoryTheory open TopCat open CategoryTheory.Limits open TopologicalSpace Topology open Opposite open scoped AlgebraicGeometry variable {C : Type u} [Category.{v} C] variable [HasColimits.{v} C] variable {X Y Z : TopCat.{v}} namespace TopCat.Presheaf variable (C) in /-- Stalks are functorial with respect to morphisms of presheaves over a fixed `X`. -/ def stalkFunctor (x : X) : X.Presheaf C ⥤ C := (whiskeringLeft _ _ C).obj (OpenNhds.inclusion x).op ⋙ colim /-- The stalk of a presheaf `F` at a point `x` is calculated as the colimit of the functor nbhds x ⥤ opens F.X ⥤ C -/ def stalk (ℱ : X.Presheaf C) (x : X) : C := (stalkFunctor C x).obj ℱ -- -- colimit ((open_nhds.inclusion x).op ⋙ ℱ) @[simp] theorem stalkFunctor_obj (ℱ : X.Presheaf C) (x : X) : (stalkFunctor C x).obj ℱ = ℱ.stalk x := rfl /-- The germ of a section of a presheaf over an open at a point of that open. -/ def germ (F : X.Presheaf C) (U : Opens X) (x : X) (hx : x ∈ U) : F.obj (op U) ⟶ stalk F x := colimit.ι ((OpenNhds.inclusion x).op ⋙ F) (op ⟨U, hx⟩) /-- The germ of a global section of a presheaf at a point. -/ def Γgerm (F : X.Presheaf C) (x : X) : F.obj (op ⊤) ⟶ stalk F x := F.germ ⊤ x True.intro @[reassoc] theorem germ_res (F : X.Presheaf C) {U V : Opens X} (i : U ⟶ V) (x : X) (hx : x ∈ U) : F.map i.op ≫ F.germ U x hx = F.germ V x (i.le hx) := let i' : (⟨U, hx⟩ : OpenNhds x) ⟶ ⟨V, i.le hx⟩ := i colimit.w ((OpenNhds.inclusion x).op ⋙ F) i'.op /-- A variant of `germ_res` with `op V ⟶ op U` so that the LHS is more general and simp fires more easier. -/ @[reassoc (attr := simp)] theorem germ_res' (F : X.Presheaf C) {U V : Opens X} (i : op V ⟶ op U) (x : X) (hx : x ∈ U) : F.map i ≫ F.germ U x hx = F.germ V x (i.unop.le hx) := let i' : (⟨U, hx⟩ : OpenNhds x) ⟶ ⟨V, i.unop.le hx⟩ := i.unop colimit.w ((OpenNhds.inclusion x).op ⋙ F) i'.op @[reassoc] lemma map_germ_eq_Γgerm (F : X.Presheaf C) {U : Opens X} {i : U ⟶ ⊤} (x : X) (hx : x ∈ U) : F.map i.op ≫ F.germ U x hx = F.Γgerm x := germ_res F i x hx variable {FC : C → C → Type*} {CC : C → Type*} [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] theorem germ_res_apply (F : X.Presheaf C) {U V : Opens X} (i : U ⟶ V) (x : X) (hx : x ∈ U) [ConcreteCategory C FC] (s) : F.germ U x hx (F.map i.op s) = F.germ V x (i.le hx) s := by rw [← ConcreteCategory.comp_apply, germ_res] theorem germ_res_apply' (F : X.Presheaf C) {U V : Opens X} (i : op V ⟶ op U) (x : X) (hx : x ∈ U) [ConcreteCategory C FC] (s) : F.germ U x hx (F.map i s) = F.germ V x (i.unop.le hx) s := by rw [← ConcreteCategory.comp_apply, germ_res'] lemma Γgerm_res_apply (F : X.Presheaf C) {U : Opens X} {i : U ⟶ ⊤} (x : X) (hx : x ∈ U) [ConcreteCategory C FC] (s) : F.germ U x hx (F.map i.op s) = F.Γgerm x s := F.germ_res_apply i x hx s /-- A morphism from the stalk of `F` at `x` to some object `Y` is completely determined by its composition with the `germ` morphisms. -/ @[ext] theorem stalk_hom_ext (F : X.Presheaf C) {x} {Y : C} {f₁ f₂ : F.stalk x ⟶ Y} (ih : ∀ (U : Opens X) (hxU : x ∈ U), F.germ U x hxU ≫ f₁ = F.germ U x hxU ≫ f₂) : f₁ = f₂ := colimit.hom_ext fun U => by induction U with | op U => obtain ⟨U, hxU⟩ := U; exact ih U hxU @[reassoc (attr := simp)] theorem stalkFunctor_map_germ {F G : X.Presheaf C} (U : Opens X) (x : X) (hx : x ∈ U) (f : F ⟶ G) : F.germ U x hx ≫ (stalkFunctor C x).map f = f.app (op U) ≫ G.germ U x hx := colimit.ι_map (whiskerLeft (OpenNhds.inclusion x).op f) (op ⟨U, hx⟩) theorem stalkFunctor_map_germ_apply [ConcreteCategory C FC] {F G : X.Presheaf C} (U : Opens X) (x : X) (hx : x ∈ U) (f : F ⟶ G) (s) : (stalkFunctor C x).map f (F.germ U x hx s) = G.germ U x hx (f.app (op U) s) := by rw [← ConcreteCategory.comp_apply, ← stalkFunctor_map_germ, ConcreteCategory.comp_apply] rfl -- a variant of `stalkFunctor_map_germ_apply` that makes simpNF happy. @[simp] theorem stalkFunctor_map_germ_apply' [ConcreteCategory C FC] {F G : X.Presheaf C} (U : Opens X) (x : X) (hx : x ∈ U) (f : F ⟶ G) (s) : DFunLike.coe (F := ToHom (F.stalk x) (G.stalk x)) (ConcreteCategory.hom ((stalkFunctor C x).map f)) (F.germ U x hx s) = G.germ U x hx (f.app (op U) s) := stalkFunctor_map_germ_apply U x hx f s variable (C) /-- For a presheaf `F` on a space `X`, a continuous map `f : X ⟶ Y` induces a morphisms between the stalk of `f _ * F` at `f x` and the stalk of `F` at `x`. -/ def stalkPushforward (f : X ⟶ Y) (F : X.Presheaf C) (x : X) : (f _* F).stalk (f x) ⟶ F.stalk x := by -- This is a hack; Lean doesn't like to elaborate the term written directly. refine ?_ ≫ colimit.pre _ (OpenNhds.map f x).op exact colim.map (whiskerRight (NatTrans.op (OpenNhds.inclusionMapIso f x).inv) F) @[reassoc (attr := simp), elementwise (attr := simp)] theorem stalkPushforward_germ (f : X ⟶ Y) (F : X.Presheaf C) (U : Opens Y) (x : X) (hx : f x ∈ U) : (f _* F).germ U (f x) hx ≫ F.stalkPushforward C f x = F.germ ((Opens.map f).obj U) x hx := by simp [germ, stalkPushforward] -- Here are two other potential solutions, suggested by @fpvandoorn at -- <https://github.com/leanprover-community/mathlib/pull/1018#discussion_r283978240> -- However, I can't get the subsequent two proofs to work with either one. -- def stalkPushforward'' (f : X ⟶ Y) (ℱ : X.Presheaf C) (x : X) : -- (f _* ℱ).stalk (f x) ⟶ ℱ.stalk x := -- colim.map ((Functor.associator _ _ _).inv ≫ -- whiskerRight (NatTrans.op (OpenNhds.inclusionMapIso f x).inv) ℱ) ≫ -- colimit.pre ((OpenNhds.inclusion x).op ⋙ ℱ) (OpenNhds.map f x).op -- def stalkPushforward''' (f : X ⟶ Y) (ℱ : X.Presheaf C) (x : X) : -- (f _* ℱ).stalk (f x) ⟶ ℱ.stalk x := -- (colim.map (whiskerRight (NatTrans.op (OpenNhds.inclusionMapIso f x).inv) ℱ) : -- colim.obj ((OpenNhds.inclusion (f x) ⋙ Opens.map f).op ⋙ ℱ) ⟶ _) ≫ -- colimit.pre ((OpenNhds.inclusion x).op ⋙ ℱ) (OpenNhds.map f x).op namespace stalkPushforward @[simp] theorem id (ℱ : X.Presheaf C) (x : X) : ℱ.stalkPushforward C (𝟙 X) x = (stalkFunctor C x).map (Pushforward.id ℱ).hom := by ext simp only [stalkPushforward, germ, colim_map, ι_colimMap_assoc, whiskerRight_app] erw [CategoryTheory.Functor.map_id] simp [stalkFunctor] @[simp] theorem comp (ℱ : X.Presheaf C) (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : ℱ.stalkPushforward C (f ≫ g) x = (f _* ℱ).stalkPushforward C g (f x) ≫ ℱ.stalkPushforward C f x := by ext simp [germ, stalkPushforward] theorem stalkPushforward_iso_of_isInducing {f : X ⟶ Y} (hf : IsInducing f) (F : X.Presheaf C) (x : X) : IsIso (F.stalkPushforward _ f x) := by haveI := Functor.initial_of_adjunction (hf.adjunctionNhds x) convert (Functor.Final.colimitIso (OpenNhds.map f x).op ((OpenNhds.inclusion x).op ⋙ F)).isIso_hom refine stalk_hom_ext _ fun U hU ↦ (stalkPushforward_germ _ f F _ x hU).trans ?_ symm exact colimit.ι_pre ((OpenNhds.inclusion x).op ⋙ F) (OpenNhds.map f x).op _ @[deprecated (since := "2024-10-27")] alias stalkPushforward_iso_of_isOpenEmbedding := stalkPushforward_iso_of_isInducing end stalkPushforward section stalkPullback /-- The morphism `ℱ_{f x} ⟶ (f⁻¹ℱ)ₓ` that factors through `(f_*f⁻¹ℱ)_{f x}`. -/ def stalkPullbackHom (f : X ⟶ Y) (F : Y.Presheaf C) (x : X) : F.stalk (f x) ⟶ ((pullback C f).obj F).stalk x := (stalkFunctor _ (f x)).map ((pushforwardPullbackAdjunction C f).unit.app F) ≫ stalkPushforward _ _ _ x @[reassoc (attr := simp)] lemma germ_stalkPullbackHom (f : X ⟶ Y) (F : Y.Presheaf C) (x : X) (U : Opens Y) (hU : f x ∈ U) : F.germ U (f x) hU ≫ stalkPullbackHom C f F x = ((pushforwardPullbackAdjunction C f).unit.app F).app _ ≫ ((pullback C f).obj F).germ ((Opens.map f).obj U) x hU := by simp [stalkPullbackHom, germ, stalkFunctor, stalkPushforward] /-- The morphism `(f⁻¹ℱ)(U) ⟶ ℱ_{f(x)}` for some `U ∋ x`. -/ def germToPullbackStalk (f : X ⟶ Y) (F : Y.Presheaf C) (U : Opens X) (x : X) (hx : x ∈ U) : ((pullback C f).obj F).obj (op U) ⟶ F.stalk (f x) := ((Opens.map f).op.isPointwiseLeftKanExtensionLeftKanExtensionUnit F (op U)).desc { pt := F.stalk ((f : X → Y) (x : X)) ι := { app := fun V => F.germ _ (f x) (V.hom.unop.le hx) naturality := fun _ _ i => by simp } } variable {C} in @[ext] lemma pullback_obj_obj_ext {Z : C} {f : X ⟶ Y} {F : Y.Presheaf C} (U : (Opens X)ᵒᵖ) {φ ψ : ((pullback C f).obj F).obj U ⟶ Z} (h : ∀ (V : Opens Y) (hV : U.unop ≤ (Opens.map f).obj V), ((pushforwardPullbackAdjunction C f).unit.app F).app (op V) ≫ ((pullback C f).obj F).map (homOfLE hV).op ≫ φ = ((pushforwardPullbackAdjunction C f).unit.app F).app (op V) ≫ ((pullback C f).obj F).map (homOfLE hV).op ≫ ψ) : φ = ψ := by obtain ⟨U⟩ := U apply ((Opens.map f).op.isPointwiseLeftKanExtensionLeftKanExtensionUnit F _).hom_ext rintro ⟨⟨V⟩, ⟨⟩, ⟨b⟩⟩ simpa [pushforwardPullbackAdjunction, Functor.lanAdjunction_unit] using h V (leOfHom b) @[reassoc (attr := simp)] lemma pushforwardPullbackAdjunction_unit_pullback_map_germToPullbackStalk (f : X ⟶ Y) (F : Y.Presheaf C) (U : Opens X) (x : X) (hx : x ∈ U) (V : Opens Y) (hV : U ≤ (Opens.map f).obj V) : ((pushforwardPullbackAdjunction C f).unit.app F).app (op V) ≫ ((pullback C f).obj F).map (homOfLE hV).op ≫ germToPullbackStalk C f F U x hx = F.germ _ (f x) (hV hx) := by simpa [pushforwardPullbackAdjunction] using ((Opens.map f).op.isPointwiseLeftKanExtensionLeftKanExtensionUnit F (op U)).fac _ (CostructuredArrow.mk (homOfLE hV).op) @[reassoc (attr := simp)] lemma germToPullbackStalk_stalkPullbackHom (f : X ⟶ Y) (F : Y.Presheaf C) (U : Opens X) (x : X) (hx : x ∈ U) : germToPullbackStalk C f F U x hx ≫ stalkPullbackHom C f F x = ((pullback C f).obj F).germ _ x hx := by ext V hV dsimp simp only [pushforwardPullbackAdjunction_unit_pullback_map_germToPullbackStalk_assoc, germ_stalkPullbackHom, germ_res] @[reassoc (attr := simp)] lemma pushforwardPullbackAdjunction_unit_app_app_germToPullbackStalk (f : X ⟶ Y) (F : Y.Presheaf C) (V : (Opens Y)ᵒᵖ) (x : X) (hx : f x ∈ V.unop) : ((pushforwardPullbackAdjunction C f).unit.app F).app V ≫ germToPullbackStalk C f F _ x hx = F.germ _ (f x) hx := by simpa using pushforwardPullbackAdjunction_unit_pullback_map_germToPullbackStalk C f F ((Opens.map f).obj V.unop) x hx V.unop (by rfl) /-- The morphism `(f⁻¹ℱ)ₓ ⟶ ℱ_{f(x)}`. -/ def stalkPullbackInv (f : X ⟶ Y) (F : Y.Presheaf C) (x : X) : ((pullback C f).obj F).stalk x ⟶ F.stalk (f x) := colimit.desc ((OpenNhds.inclusion x).op ⋙ (Presheaf.pullback C f).obj F) { pt := F.stalk (f x) ι := { app := fun U => F.germToPullbackStalk _ f (unop U).1 x (unop U).2 naturality := fun U V i => by dsimp ext W hW dsimp [OpenNhds.inclusion] rw [Category.comp_id, ← Functor.map_comp_assoc, pushforwardPullbackAdjunction_unit_pullback_map_germToPullbackStalk] erw [pushforwardPullbackAdjunction_unit_pullback_map_germToPullbackStalk] } } @[reassoc (attr := simp)] lemma germ_stalkPullbackInv (f : X ⟶ Y) (F : Y.Presheaf C) (x : X) (V : Opens X) (hV : x ∈ V) : ((pullback C f).obj F).germ _ x hV ≫ stalkPullbackInv C f F x = F.germToPullbackStalk _ f V x hV := by apply colimit.ι_desc /-- The isomorphism `ℱ_{f(x)} ≅ (f⁻¹ℱ)ₓ`. -/ def stalkPullbackIso (f : X ⟶ Y) (F : Y.Presheaf C) (x : X) : F.stalk (f x) ≅ ((pullback C f).obj F).stalk x where hom := stalkPullbackHom _ _ _ _ inv := stalkPullbackInv _ _ _ _ hom_inv_id := by ext U hU dsimp rw [germ_stalkPullbackHom_assoc, germ_stalkPullbackInv, Category.comp_id, pushforwardPullbackAdjunction_unit_app_app_germToPullbackStalk] inv_hom_id := by ext V hV dsimp rw [germ_stalkPullbackInv_assoc, Category.comp_id, germToPullbackStalk_stalkPullbackHom] end stalkPullback section stalkSpecializes variable {C} /-- If `x` specializes to `y`, then there is a natural map `F.stalk y ⟶ F.stalk x`. -/ noncomputable def stalkSpecializes (F : X.Presheaf C) {x y : X} (h : x ⤳ y) : F.stalk y ⟶ F.stalk x := by refine colimit.desc _ ⟨_, fun U => ?_, ?_⟩ · exact colimit.ι ((OpenNhds.inclusion x).op ⋙ F) (op ⟨(unop U).1, (specializes_iff_forall_open.mp h _ (unop U).1.2 (unop U).2 :)⟩) · intro U V i dsimp rw [Category.comp_id] let U' : OpenNhds x := ⟨_, (specializes_iff_forall_open.mp h _ (unop U).1.2 (unop U).2 :)⟩ let V' : OpenNhds x := ⟨_, (specializes_iff_forall_open.mp h _ (unop V).1.2 (unop V).2 :)⟩ exact colimit.w ((OpenNhds.inclusion x).op ⋙ F) (show V' ⟶ U' from i.unop).op @[reassoc (attr := simp), elementwise nosimp] theorem germ_stalkSpecializes (F : X.Presheaf C) {U : Opens X} {y : X} (hy : y ∈ U) {x : X} (h : x ⤳ y) : F.germ U y hy ≫ F.stalkSpecializes h = F.germ U x (h.mem_open U.isOpen hy) := colimit.ι_desc _ _ @[simp] theorem stalkSpecializes_refl {C : Type*} [Category C] [Limits.HasColimits C] {X : TopCat} (F : X.Presheaf C) (x : X) : F.stalkSpecializes (specializes_refl x) = 𝟙 _ := by ext simp @[reassoc (attr := simp), elementwise (attr := simp)] theorem stalkSpecializes_comp {C : Type*} [Category C] [Limits.HasColimits C] {X : TopCat} (F : X.Presheaf C) {x y z : X} (h : x ⤳ y) (h' : y ⤳ z) : F.stalkSpecializes h' ≫ F.stalkSpecializes h = F.stalkSpecializes (h.trans h') := by ext simp @[reassoc (attr := simp), elementwise (attr := simp)] theorem stalkSpecializes_stalkFunctor_map {F G : X.Presheaf C} (f : F ⟶ G) {x y : X} (h : x ⤳ y) : F.stalkSpecializes h ≫ (stalkFunctor C x).map f = (stalkFunctor C y).map f ≫ G.stalkSpecializes h := by change (_ : colimit _ ⟶ _) = (_ : colimit _ ⟶ _) ext; delta stalkFunctor; simpa [stalkSpecializes] using by rfl -- See https://github.com/leanprover-community/batteries/issues/365 for the simpNF issue. -- It seems the side condition `h` is not applied by `simpNF`. @[reassoc, elementwise, simp, nolint simpNF] theorem stalkSpecializes_stalkPushforward (f : X ⟶ Y) (F : X.Presheaf C) {x y : X} (h : x ⤳ y) : (f _* F).stalkSpecializes (f.hom.map_specializes h) ≫ F.stalkPushforward _ f x = F.stalkPushforward _ f y ≫ F.stalkSpecializes h := by change (_ : colimit _ ⟶ _) = (_ : colimit _ ⟶ _) ext; delta stalkPushforward simp only [stalkSpecializes, colimit.ι_desc_assoc, colimit.ι_map_assoc, colimit.ι_pre, Category.assoc, colimit.pre_desc, colimit.ι_desc] rfl /-- The stalks are isomorphic on inseparable points -/ @[simps] def stalkCongr {X : TopCat} {C : Type*} [Category C] [HasColimits C] (F : X.Presheaf C) {x y : X} (e : Inseparable x y) : F.stalk x ≅ F.stalk y := ⟨F.stalkSpecializes e.ge, F.stalkSpecializes e.le, by simp, by simp⟩ end stalkSpecializes section Concrete variable {C} {CC : C → Type v} [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] variable [instCC : ConcreteCategory.{v} C FC] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: @[ext] attribute only applies to structures or lemmas proving x = y -- @[ext] theorem germ_ext (F : X.Presheaf C) {U V : Opens X} {x : X} {hxU : x ∈ U} {hxV : x ∈ V} (W : Opens X) (hxW : x ∈ W) (iWU : W ⟶ U) (iWV : W ⟶ V) {sU : ToType (F.obj (op U))} {sV : ToType (F.obj (op V))} (ih : F.map iWU.op sU = F.map iWV.op sV) : F.germ _ x hxU sU = F.germ _ x hxV sV := by rw [← F.germ_res iWU x hxW, ← F.germ_res iWV x hxW, ConcreteCategory.comp_apply, ConcreteCategory.comp_apply, ih] variable [PreservesFilteredColimits (forget C)] /-- For presheaves valued in a concrete category whose forgetful functor preserves filtered colimits, every element of the stalk is the germ of a section. -/ theorem germ_exist (F : X.Presheaf C) (x : X) (t : ToType (stalk.{v, u} F x)) : ∃ (U : Opens X) (m : x ∈ U) (s : ToType (F.obj (op U))), F.germ _ x m s = t := by obtain ⟨U, s, e⟩ := Types.jointly_surjective.{v, v} _ (isColimitOfPreserves (forget C) (colimit.isColimit _)) t revert s e induction U with | op U => ?_ obtain ⟨V, m⟩ := U intro s e exact ⟨V, m, s, e⟩ theorem germ_eq (F : X.Presheaf C) {U V : Opens X} (x : X) (mU : x ∈ U) (mV : x ∈ V) (s : ToType (F.obj (op U))) (t : ToType (F.obj (op V))) (h : F.germ U x mU s = F.germ V x mV t) : ∃ (W : Opens X) (_m : x ∈ W) (iU : W ⟶ U) (iV : W ⟶ V), F.map iU.op s = F.map iV.op t := by obtain ⟨W, iU, iV, e⟩ := (Types.FilteredColimit.isColimit_eq_iff.{v, v} _ (isColimitOfPreserves (forget C) (colimit.isColimit ((OpenNhds.inclusion x).op ⋙ F)))).mp h exact ⟨(unop W).1, (unop W).2, iU.unop, iV.unop, e⟩ theorem stalkFunctor_map_injective_of_app_injective {F G : Presheaf C X} (f : F ⟶ G) (h : ∀ U : Opens X, Function.Injective (f.app (op U))) (x : X) : Function.Injective ((stalkFunctor C x).map f) := fun s t hst => by rcases germ_exist F x s with ⟨U₁, hxU₁, s, rfl⟩ rcases germ_exist F x t with ⟨U₂, hxU₂, t, rfl⟩ rw [stalkFunctor_map_germ_apply, stalkFunctor_map_germ_apply] at hst obtain ⟨W, hxW, iWU₁, iWU₂, heq⟩ := G.germ_eq x hxU₁ hxU₂ _ _ hst rw [← ConcreteCategory.comp_apply, ← ConcreteCategory.comp_apply, ← f.naturality, ← f.naturality, ConcreteCategory.comp_apply, ConcreteCategory.comp_apply] at heq replace heq := h W heq convert congr_arg (F.germ _ x hxW) heq using 1 exacts [(F.germ_res_apply iWU₁ x hxW s).symm, (F.germ_res_apply iWU₂ x hxW t).symm] variable [HasLimits C] [PreservesLimits (forget C)] [(forget C).ReflectsIsomorphisms] /-- Let `F` be a sheaf valued in a concrete category, whose forgetful functor reflects isomorphisms, preserves limits and filtered colimits. Then two sections who agree on every stalk must be equal. -/ theorem section_ext (F : Sheaf C X) (U : Opens X) (s t : ToType (F.1.obj (op U))) (h : ∀ (x : X) (hx : x ∈ U), F.presheaf.germ U x hx s = F.presheaf.germ U x hx t) : s = t := by -- We use `germ_eq` and the axiom of choice, to pick for every point `x` a neighbourhood -- `V x`, such that the restrictions of `s` and `t` to `V x` coincide. choose V m i₁ i₂ heq using fun x : U => F.presheaf.germ_eq x.1 x.2 x.2 s t (h x.1 x.2) -- Since `F` is a sheaf, we can prove the equality locally, if we can show that these -- neighborhoods form a cover of `U`. apply F.eq_of_locally_eq' V U i₁ · intro x hxU simp only [Opens.coe_iSup, Set.mem_iUnion, SetLike.mem_coe] exact ⟨⟨x, hxU⟩, m ⟨x, hxU⟩⟩ · intro x rw [heq, Subsingleton.elim (i₁ x) (i₂ x)] /- Note that the analogous statement for surjectivity is false: Surjectivity on stalks does not imply surjectivity of the components of a sheaf morphism. However it does imply that the morphism is an epi, but this fact is not yet formalized. -/ theorem app_injective_of_stalkFunctor_map_injective {F : Sheaf C X} {G : Presheaf C X} (f : F.1 ⟶ G) (U : Opens X) (h : ∀ x ∈ U, Function.Injective ((stalkFunctor C x).map f)) : Function.Injective (f.app (op U)) := fun s t hst => section_ext F _ _ _ fun x hx => h x hx <| by rw [stalkFunctor_map_germ_apply, stalkFunctor_map_germ_apply, hst] theorem app_injective_iff_stalkFunctor_map_injective {F : Sheaf C X} {G : Presheaf C X} (f : F.1 ⟶ G) : (∀ x : X, Function.Injective ((stalkFunctor C x).map f)) ↔ ∀ U : Opens X, Function.Injective (f.app (op U)) := ⟨fun h U => app_injective_of_stalkFunctor_map_injective f U fun x _ => h x, stalkFunctor_map_injective_of_app_injective f⟩ instance stalkFunctor_preserves_mono (x : X) : Functor.PreservesMonomorphisms (Sheaf.forget.{v} C X ⋙ stalkFunctor C x) := ⟨@fun _𝓐 _𝓑 f _ => ConcreteCategory.mono_of_injective _ <| (app_injective_iff_stalkFunctor_map_injective f.1).mpr (fun c => (ConcreteCategory.mono_iff_injective_of_preservesPullback (f.1.app (op c))).mp ((NatTrans.mono_iff_mono_app f.1).mp (CategoryTheory.presheaf_mono_of_mono ..) <| op c)) x⟩ include instCC in theorem stalk_mono_of_mono {F G : Sheaf C X} (f : F ⟶ G) [Mono f] : ∀ x, Mono <| (stalkFunctor C x).map f.1 := fun x => Functor.map_mono (Sheaf.forget.{v} C X ⋙ stalkFunctor C x) f include instCC in theorem mono_of_stalk_mono {F G : Sheaf C X} (f : F ⟶ G) [∀ x, Mono <| (stalkFunctor C x).map f.1] : Mono f := (Sheaf.Hom.mono_iff_presheaf_mono _ _ _).mpr <| (NatTrans.mono_iff_mono_app _).mpr fun U => (ConcreteCategory.mono_iff_injective_of_preservesPullback _).mpr <| app_injective_of_stalkFunctor_map_injective f.1 U.unop fun _x _hx => (ConcreteCategory.mono_iff_injective_of_preservesPullback ((stalkFunctor C _).map f.val)).mp <| inferInstance include instCC in theorem mono_iff_stalk_mono {F G : Sheaf C X} (f : F ⟶ G) : Mono f ↔ ∀ x, Mono ((stalkFunctor C x).map f.1) := ⟨fun _ => stalk_mono_of_mono _, fun _ => mono_of_stalk_mono _⟩ /-- For surjectivity, we are given an arbitrary section `t` and need to find a preimage for it. We claim that it suffices to find preimages *locally*. That is, for each `x : U` we construct a neighborhood `V ≤ U` and a section `s : F.obj (op V))` such that `f.app (op V) s` and `t` agree on `V`. -/ theorem app_surjective_of_injective_of_locally_surjective {F G : Sheaf C X} (f : F ⟶ G) (U : Opens X) (hinj : ∀ x ∈ U, Function.Injective ((stalkFunctor C x).map f.1)) (hsurj : ∀ (t x) (_ : x ∈ U), ∃ (V : Opens X) (_ : x ∈ V) (iVU : V ⟶ U) (s : ToType (F.1.obj (op V))), f.1.app (op V) s = G.1.map iVU.op t) : Function.Surjective (f.1.app (op U)) := by conv at hsurj => enter [t] rw [Subtype.forall' (p := (· ∈ U))] intro t -- We use the axiom of choice to pick around each point `x` an open neighborhood `V` and a -- preimage under `f` on `V`. choose V mV iVU sf heq using hsurj t -- These neighborhoods clearly cover all of `U`. have V_cover : U ≤ iSup V := by intro x hxU simp only [Opens.coe_iSup, Set.mem_iUnion, SetLike.mem_coe] exact ⟨⟨x, hxU⟩, mV ⟨x, hxU⟩⟩ suffices IsCompatible F.val V sf by -- Since `F` is a sheaf, we can glue all the local preimages together to get a global preimage. obtain ⟨s, s_spec, -⟩ := F.existsUnique_gluing' V U iVU V_cover sf this · use s apply G.eq_of_locally_eq' V U iVU V_cover intro x rw [← ConcreteCategory.comp_apply, ← f.1.naturality, ConcreteCategory.comp_apply, s_spec, heq] intro x y -- What's left to show here is that the sections `sf` are compatible, i.e. they agree on -- the intersections `V x ⊓ V y`. We prove this by showing that all germs are equal. apply section_ext intro z hz -- Here, we need to use injectivity of the stalk maps. apply hinj z ((iVU x).le ((inf_le_left : V x ⊓ V y ≤ V x) hz)) dsimp only rw [stalkFunctor_map_germ_apply, stalkFunctor_map_germ_apply] simp_rw [← ConcreteCategory.comp_apply, f.1.naturality, ConcreteCategory.comp_apply, heq, ← ConcreteCategory.comp_apply, ← G.1.map_comp] rfl theorem app_surjective_of_stalkFunctor_map_bijective {F G : Sheaf C X} (f : F ⟶ G) (U : Opens X) (h : ∀ x ∈ U, Function.Bijective ((stalkFunctor C x).map f.1)) : Function.Surjective (f.1.app (op U)) := by refine app_surjective_of_injective_of_locally_surjective f U (And.left <| h · ·) fun t x hx => ?_ -- Now we need to prove our initial claim: That we can find preimages of `t` locally. -- Since `f` is surjective on stalks, we can find a preimage `s₀` of the germ of `t` at `x` obtain ⟨s₀, hs₀⟩ := (h x hx).2 (G.presheaf.germ U x hx t) -- ... and this preimage must come from some section `s₁` defined on some open neighborhood `V₁` obtain ⟨V₁, hxV₁, s₁, hs₁⟩ := F.presheaf.germ_exist x s₀ subst hs₁; rename' hs₀ => hs₁ rw [stalkFunctor_map_germ_apply V₁ x hxV₁ f.1 s₁] at hs₁ -- Now, the germ of `f.app (op V₁) s₁` equals the germ of `t`, hence they must coincide on -- some open neighborhood `V₂`. obtain ⟨V₂, hxV₂, iV₂V₁, iV₂U, heq⟩ := G.presheaf.germ_eq x hxV₁ hx _ _ hs₁ -- The restriction of `s₁` to that neighborhood is our desired local preimage. use V₂, hxV₂, iV₂U, F.1.map iV₂V₁.op s₁ rw [← ConcreteCategory.comp_apply, f.1.naturality, ConcreteCategory.comp_apply, heq] theorem app_bijective_of_stalkFunctor_map_bijective {F G : Sheaf C X} (f : F ⟶ G) (U : Opens X) (h : ∀ x ∈ U, Function.Bijective ((stalkFunctor C x).map f.1)) : Function.Bijective (f.1.app (op U)) := ⟨app_injective_of_stalkFunctor_map_injective f.1 U fun x hx => (h x hx).1, app_surjective_of_stalkFunctor_map_bijective f U h⟩ include instCC in theorem app_isIso_of_stalkFunctor_map_iso {F G : Sheaf C X} (f : F ⟶ G) (U : Opens X) [∀ x : U, IsIso ((stalkFunctor C x.val).map f.1)] : IsIso (f.1.app (op U)) := by -- Since the forgetful functor of `C` reflects isomorphisms, it suffices to see that the -- underlying map between types is an isomorphism, i.e. bijective. suffices IsIso ((forget C).map (f.1.app (op U))) by exact isIso_of_reflects_iso (f.1.app (op U)) (forget C) rw [isIso_iff_bijective] apply app_bijective_of_stalkFunctor_map_bijective intro x hx apply (isIso_iff_bijective _).mp exact Functor.map_isIso (forget C) ((stalkFunctor C (⟨x, hx⟩ : U).1).map f.1) include instCC in -- Making this an instance would cause a loop in typeclass resolution with `Functor.map_isIso` /-- Let `F` and `G` be sheaves valued in a concrete category, whose forgetful functor reflects isomorphisms, preserves limits and filtered colimits. Then if the stalk maps of a morphism
`f : F ⟶ G` are all isomorphisms, `f` must be an isomorphism. -/ theorem isIso_of_stalkFunctor_map_iso {F G : Sheaf C X} (f : F ⟶ G) [∀ x : X, IsIso ((stalkFunctor C x).map f.1)] : IsIso f := by -- Since the inclusion functor from sheaves to presheaves is fully faithful, it suffices to -- show that `f`, as a morphism between _presheaves_, is an isomorphism. suffices IsIso ((Sheaf.forget C X).map f) by exact isIso_of_fully_faithful (Sheaf.forget C X) f -- We show that all components of `f` are isomorphisms. suffices ∀ U : (Opens X)ᵒᵖ, IsIso (f.1.app U) by exact @NatIso.isIso_of_isIso_app _ _ _ _ F.1 G.1 f.1 this intro U; induction U
Mathlib/Topology/Sheaves/Stalks.lean
590
600
/- Copyright (c) 2022 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jujian Zhang -/ import Mathlib.LinearAlgebra.LinearPMap import Mathlib.Algebra.Equiv.TransferInstance import Mathlib.Logic.Small.Basic import Mathlib.RingTheory.Ideal.Defs /-! # Injective modules ## Main definitions * `Module.Injective`: an `R`-module `Q` is injective if and only if every injective `R`-linear map descends to a linear map to `Q`, i.e. in the following diagram, if `f` is injective then there is an `R`-linear map `h : Y ⟶ Q` such that `g = h ∘ f` ``` X --- f ---> Y | | g v Q ``` * `Module.Baer`: an `R`-module `Q` satisfies Baer's criterion if any `R`-linear map from an `Ideal R` extends to an `R`-linear map `R ⟶ Q` ## Main statements * `Module.Baer.injective`: an `R`-module is injective if it is Baer. -/ assert_not_exists ModuleCat noncomputable section universe u v v' variable (R : Type u) [Ring R] (Q : Type v) [AddCommGroup Q] [Module R Q] /-- An `R`-module `Q` is injective if and only if every injective `R`-linear map descends to a linear map to `Q`, i.e. in the following diagram, if `f` is injective then there is an `R`-linear map `h : Y ⟶ Q` such that `g = h ∘ f` ``` X --- f ---> Y | | g v Q ``` -/ @[mk_iff] class Module.Injective : Prop where out : ∀ ⦃X Y : Type v⦄ [AddCommGroup X] [AddCommGroup Y] [Module R X] [Module R Y] (f : X →ₗ[R] Y) (_ : Function.Injective f) (g : X →ₗ[R] Q), ∃ h : Y →ₗ[R] Q, ∀ x, h (f x) = g x /-- An `R`-module `Q` satisfies Baer's criterion if any `R`-linear map from an `Ideal R` extends to an `R`-linear map `R ⟶ Q` -/ def Module.Baer : Prop := ∀ (I : Ideal R) (g : I →ₗ[R] Q), ∃ g' : R →ₗ[R] Q, ∀ (x : R) (mem : x ∈ I), g' x = g ⟨x, mem⟩ namespace Module.Baer variable {R Q} {M N : Type*} [AddCommGroup M] [AddCommGroup N] variable [Module R M] [Module R N] (i : M →ₗ[R] N) (f : M →ₗ[R] Q) lemma of_equiv (e : Q ≃ₗ[R] M) (h : Module.Baer R Q) : Module.Baer R M := fun I g ↦ have ⟨g', h'⟩ := h I (e.symm ∘ₗ g) ⟨e ∘ₗ g', by simpa [LinearEquiv.eq_symm_apply] using h'⟩ lemma congr (e : Q ≃ₗ[R] M) : Module.Baer R Q ↔ Module.Baer R M := ⟨of_equiv e, of_equiv e.symm⟩ /-- If we view `M` as a submodule of `N` via the injective linear map `i : M ↪ N`, then a submodule between `M` and `N` is a submodule `N'` of `N`. To prove Baer's criterion, we need to consider pairs of `(N', f')` such that `M ≤ N' ≤ N` and `f'` extends `f`. -/ structure ExtensionOf extends LinearPMap R N Q where le : LinearMap.range i ≤ domain is_extension : ∀ m : M, f m = toLinearPMap ⟨i m, le ⟨m, rfl⟩⟩ section Ext variable {i f} @[ext (iff := false)] theorem ExtensionOf.ext {a b : ExtensionOf i f} (domain_eq : a.domain = b.domain) (to_fun_eq : ∀ ⦃x : N⦄ ⦃ha : x ∈ a.domain⦄ ⦃hb : x ∈ b.domain⦄, a.toLinearPMap ⟨x, ha⟩ = b.toLinearPMap ⟨x, hb⟩) : a = b := by rcases a with ⟨a, a_le, e1⟩ rcases b with ⟨b, b_le, e2⟩ congr exact LinearPMap.ext domain_eq to_fun_eq /-- A dependent version of `ExtensionOf.ext` -/ theorem ExtensionOf.dExt {a b : ExtensionOf i f} (domain_eq : a.domain = b.domain) (to_fun_eq : ∀ ⦃x : a.domain⦄ ⦃y : b.domain⦄, (x : N) = y → a.toLinearPMap x = b.toLinearPMap y) : a = b := ext domain_eq fun _ _ _ ↦ to_fun_eq rfl theorem ExtensionOf.dExt_iff {a b : ExtensionOf i f} : a = b ↔ ∃ _ : a.domain = b.domain, ∀ ⦃x : a.domain⦄ ⦃y : b.domain⦄, (x : N) = y → a.toLinearPMap x = b.toLinearPMap y := ⟨fun r => r ▸ ⟨rfl, fun _ _ h => congr_arg a.toFun <| mod_cast h⟩, fun ⟨h1, h2⟩ => ExtensionOf.dExt h1 h2⟩ end Ext instance : Min (ExtensionOf i f) where min X1 X2 := { X1.toLinearPMap ⊓ X2.toLinearPMap with le := fun x hx => (by rcases hx with ⟨x, rfl⟩ refine ⟨X1.le (Set.mem_range_self _), X2.le (Set.mem_range_self _), ?_⟩ rw [← X1.is_extension x, ← X2.is_extension x] : x ∈ X1.toLinearPMap.eqLocus X2.toLinearPMap) is_extension := fun _ => X1.is_extension _ } instance : SemilatticeInf (ExtensionOf i f) := Function.Injective.semilatticeInf ExtensionOf.toLinearPMap (fun X Y h ↦ ExtensionOf.ext (by rw [h]) <| by rw [h] intros rfl) fun X Y ↦ LinearPMap.ext rfl fun x y h => by congr variable {i f} theorem chain_linearPMap_of_chain_extensionOf {c : Set (ExtensionOf i f)} (hchain : IsChain (· ≤ ·) c) : IsChain (· ≤ ·) <| (fun x : ExtensionOf i f => x.toLinearPMap) '' c := by rintro _ ⟨a, a_mem, rfl⟩ _ ⟨b, b_mem, rfl⟩ neq exact hchain a_mem b_mem (ne_of_apply_ne _ neq) /-- The maximal element of every nonempty chain of `extension_of i f`. -/ def ExtensionOf.max {c : Set (ExtensionOf i f)} (hchain : IsChain (· ≤ ·) c) (hnonempty : c.Nonempty) : ExtensionOf i f := { LinearPMap.sSup _ (IsChain.directedOn <| chain_linearPMap_of_chain_extensionOf hchain) with le := by refine le_trans hnonempty.some.le <| (LinearPMap.le_sSup _ <| (Set.mem_image _ _ _).mpr ⟨hnonempty.some, hnonempty.choose_spec, rfl⟩).1 is_extension := fun m => by refine Eq.trans (hnonempty.some.is_extension m) ?_ symm generalize_proofs _ _ h1 exact LinearPMap.sSup_apply (IsChain.directedOn <| chain_linearPMap_of_chain_extensionOf hchain) ((Set.mem_image _ _ _).mpr ⟨hnonempty.some, hnonempty.choose_spec, rfl⟩) ⟨i m, h1⟩ } theorem ExtensionOf.le_max {c : Set (ExtensionOf i f)} (hchain : IsChain (· ≤ ·) c) (hnonempty : c.Nonempty) (a : ExtensionOf i f) (ha : a ∈ c) : a ≤ ExtensionOf.max hchain hnonempty := LinearPMap.le_sSup (IsChain.directedOn <| chain_linearPMap_of_chain_extensionOf hchain) <| (Set.mem_image _ _ _).mpr ⟨a, ha, rfl⟩ variable (i f) [Fact <| Function.Injective i] instance ExtensionOf.inhabited : Inhabited (ExtensionOf i f) where default := { domain := LinearMap.range i toFun := { toFun := fun x => f x.2.choose map_add' := fun x y => by have eq1 : _ + _ = (x + y).1 := congr_arg₂ (· + ·) x.2.choose_spec y.2.choose_spec rw [← map_add, ← (x + y).2.choose_spec] at eq1 dsimp rw [← Fact.out (p := Function.Injective i) eq1, map_add] map_smul' := fun r x => by have eq1 : r • _ = (r • x).1 := congr_arg (r • ·) x.2.choose_spec rw [← LinearMap.map_smul, ← (r • x).2.choose_spec] at eq1 dsimp rw [← Fact.out (p := Function.Injective i) eq1, LinearMap.map_smul] } le := le_refl _ is_extension := fun m => by simp only [LinearPMap.mk_apply, LinearMap.coe_mk] dsimp apply congrArg exact Fact.out (p := Function.Injective i) (⟨i m, ⟨_, rfl⟩⟩ : LinearMap.range i).2.choose_spec.symm } /-- Since every nonempty chain has a maximal element, by Zorn's lemma, there is a maximal `extension_of i f`. -/ def extensionOfMax : ExtensionOf i f := (@zorn_le_nonempty (ExtensionOf i f) _ ⟨Inhabited.default⟩ fun _ hchain hnonempty => ⟨ExtensionOf.max hchain hnonempty, ExtensionOf.le_max hchain hnonempty⟩).choose theorem extensionOfMax_is_max : ∀ (a : ExtensionOf i f), extensionOfMax i f ≤ a → a = extensionOfMax i f := fun _ ↦ (@zorn_le_nonempty (ExtensionOf i f) _ ⟨Inhabited.default⟩ fun _ hchain hnonempty => ⟨ExtensionOf.max hchain hnonempty, ExtensionOf.le_max hchain hnonempty⟩).choose_spec.eq_of_ge -- Porting note: helper function. Lean looks for an instance of `Sup (Type u)` when the -- right hand side is substituted in directly abbrev supExtensionOfMaxSingleton (y : N) : Submodule R N := (extensionOfMax i f).domain ⊔ (Submodule.span R {y}) variable {f} private theorem extensionOfMax_adjoin.aux1 {y : N} (x : supExtensionOfMaxSingleton i f y) : ∃ (a : (extensionOfMax i f).domain) (b : R), x.1 = a.1 + b • y := by have mem1 : x.1 ∈ (_ : Set _) := x.2 rw [Submodule.coe_sup] at mem1 rcases mem1 with ⟨a, a_mem, b, b_mem : b ∈ (Submodule.span R _ : Submodule R N), eq1⟩ rw [Submodule.mem_span_singleton] at b_mem rcases b_mem with ⟨z, eq2⟩ exact ⟨⟨a, a_mem⟩, z, by rw [← eq1, ← eq2]⟩ /-- If `x ∈ M ⊔ ⟨y⟩`, then `x = m + r • y`, `fst` pick an arbitrary such `m`. -/ def ExtensionOfMaxAdjoin.fst {y : N} (x : supExtensionOfMaxSingleton i f y) : (extensionOfMax i f).domain := (extensionOfMax_adjoin.aux1 i x).choose /-- If `x ∈ M ⊔ ⟨y⟩`, then `x = m + r • y`, `snd` pick an arbitrary such `r`. -/ def ExtensionOfMaxAdjoin.snd {y : N} (x : supExtensionOfMaxSingleton i f y) : R := (extensionOfMax_adjoin.aux1 i x).choose_spec.choose theorem ExtensionOfMaxAdjoin.eqn {y : N} (x : supExtensionOfMaxSingleton i f y) : ↑x = ↑(ExtensionOfMaxAdjoin.fst i x) + ExtensionOfMaxAdjoin.snd i x • y := (extensionOfMax_adjoin.aux1 i x).choose_spec.choose_spec variable (f) -- TODO: refactor to use colon ideals? /-- The ideal `I = {r | r • y ∈ N}` -/ def ExtensionOfMaxAdjoin.ideal (y : N) : Ideal R := (extensionOfMax i f).domain.comap ((LinearMap.id : R →ₗ[R] R).smulRight y) /-- A linear map `I ⟶ Q` by `x ↦ f' (x • y)` where `f'` is the maximal extension -/ def ExtensionOfMaxAdjoin.idealTo (y : N) : ExtensionOfMaxAdjoin.ideal i f y →ₗ[R] Q where toFun (z : { x // x ∈ ideal i f y }) := (extensionOfMax i f).toLinearPMap ⟨(↑z : R) • y, z.prop⟩ map_add' (z1 z2 : { x // x ∈ ideal i f y }) := by simp_rw [← (extensionOfMax i f).toLinearPMap.map_add] congr apply add_smul map_smul' z1 (z2 : {x // x ∈ ideal i f y}) := by simp_rw [← (extensionOfMax i f).toLinearPMap.map_smul] congr 2 apply mul_smul /-- Since we assumed `Q` being Baer, the linear map `x ↦ f' (x • y) : I ⟶ Q` extends to `R ⟶ Q`, call this extended map `φ` -/ def ExtensionOfMaxAdjoin.extendIdealTo (h : Module.Baer R Q) (y : N) : R →ₗ[R] Q := (h (ExtensionOfMaxAdjoin.ideal i f y) (ExtensionOfMaxAdjoin.idealTo i f y)).choose theorem ExtensionOfMaxAdjoin.extendIdealTo_is_extension (h : Module.Baer R Q) (y : N) : ∀ (x : R) (mem : x ∈ ExtensionOfMaxAdjoin.ideal i f y), ExtensionOfMaxAdjoin.extendIdealTo i f h y x = ExtensionOfMaxAdjoin.idealTo i f y ⟨x, mem⟩ := (h (ExtensionOfMaxAdjoin.ideal i f y) (ExtensionOfMaxAdjoin.idealTo i f y)).choose_spec theorem ExtensionOfMaxAdjoin.extendIdealTo_wd' (h : Module.Baer R Q) {y : N} (r : R) (eq1 : r • y = 0) : ExtensionOfMaxAdjoin.extendIdealTo i f h y r = 0 := by have : r ∈ ideal i f y := by change (r • y) ∈ (extensionOfMax i f).toLinearPMap.domain rw [eq1] apply Submodule.zero_mem _ rw [ExtensionOfMaxAdjoin.extendIdealTo_is_extension i f h y r this] dsimp [ExtensionOfMaxAdjoin.idealTo] simp only [LinearMap.coe_mk, eq1, Subtype.coe_mk, ← ZeroMemClass.zero_def, (extensionOfMax i f).toLinearPMap.map_zero] theorem ExtensionOfMaxAdjoin.extendIdealTo_wd (h : Module.Baer R Q) {y : N} (r r' : R) (eq1 : r • y = r' • y) : ExtensionOfMaxAdjoin.extendIdealTo i f h y r = ExtensionOfMaxAdjoin.extendIdealTo i f h y r' := by rw [← sub_eq_zero, ← map_sub] convert ExtensionOfMaxAdjoin.extendIdealTo_wd' i f h (r - r') _ rw [sub_smul, sub_eq_zero, eq1] theorem ExtensionOfMaxAdjoin.extendIdealTo_eq (h : Module.Baer R Q) {y : N} (r : R) (hr : r • y ∈ (extensionOfMax i f).domain) : ExtensionOfMaxAdjoin.extendIdealTo i f h y r = (extensionOfMax i f).toLinearPMap ⟨r • y, hr⟩ := by simp only [ExtensionOfMaxAdjoin.extendIdealTo_is_extension i f h _ _ hr, ExtensionOfMaxAdjoin.idealTo, LinearMap.coe_mk, Subtype.coe_mk, AddHom.coe_mk] /-- We can finally define a linear map `M ⊔ ⟨y⟩ ⟶ Q` by `x + r • y ↦ f x + φ r` -/ def ExtensionOfMaxAdjoin.extensionToFun (h : Module.Baer R Q) {y : N} : supExtensionOfMaxSingleton i f y → Q := fun x => (extensionOfMax i f).toLinearPMap (ExtensionOfMaxAdjoin.fst i x) + ExtensionOfMaxAdjoin.extendIdealTo i f h y (ExtensionOfMaxAdjoin.snd i x) theorem ExtensionOfMaxAdjoin.extensionToFun_wd (h : Module.Baer R Q) {y : N} (x : supExtensionOfMaxSingleton i f y) (a : (extensionOfMax i f).domain) (r : R) (eq1 : ↑x = ↑a + r • y) : ExtensionOfMaxAdjoin.extensionToFun i f h x = (extensionOfMax i f).toLinearPMap a + ExtensionOfMaxAdjoin.extendIdealTo i f h y r := by obtain ⟨a, ha⟩ := a have eq2 : (ExtensionOfMaxAdjoin.fst i x - a : N) = (r - ExtensionOfMaxAdjoin.snd i x) • y := by change x = a + r • y at eq1 rwa [ExtensionOfMaxAdjoin.eqn, ← sub_eq_zero, ← sub_sub_sub_eq, sub_eq_zero, ← sub_smul] at eq1 have eq3 := ExtensionOfMaxAdjoin.extendIdealTo_eq i f h (r - ExtensionOfMaxAdjoin.snd i x) (by rw [← eq2]; exact Submodule.sub_mem _ (ExtensionOfMaxAdjoin.fst i x).2 ha) simp only [map_sub, sub_smul, sub_eq_iff_eq_add] at eq3 unfold ExtensionOfMaxAdjoin.extensionToFun rw [eq3, ← add_assoc, ← (extensionOfMax i f).toLinearPMap.map_add, AddMemClass.mk_add_mk] congr ext dsimp rw [Subtype.coe_mk, add_sub, ← eq1] exact eq_sub_of_add_eq (ExtensionOfMaxAdjoin.eqn i x).symm /-- The linear map `M ⊔ ⟨y⟩ ⟶ Q` by `x + r • y ↦ f x + φ r` is an extension of `f` -/ def extensionOfMaxAdjoin (h : Module.Baer R Q) (y : N) : ExtensionOf i f where domain := supExtensionOfMaxSingleton i f y -- (extensionOfMax i f).domain ⊔ Submodule.span R {y} le := le_trans (extensionOfMax i f).le le_sup_left toFun := { toFun := ExtensionOfMaxAdjoin.extensionToFun i f h map_add' := fun a b => by have eq1 : ↑a + ↑b = ↑(ExtensionOfMaxAdjoin.fst i a + ExtensionOfMaxAdjoin.fst i b) + (ExtensionOfMaxAdjoin.snd i a + ExtensionOfMaxAdjoin.snd i b) • y := by rw [ExtensionOfMaxAdjoin.eqn, ExtensionOfMaxAdjoin.eqn, add_smul, Submodule.coe_add] ac_rfl rw [ExtensionOfMaxAdjoin.extensionToFun_wd (y := y) i f h (a + b) _ _ eq1, LinearPMap.map_add, map_add] unfold ExtensionOfMaxAdjoin.extensionToFun abel map_smul' := fun r a => by dsimp have eq1 : r • (a : N) = ↑(r • ExtensionOfMaxAdjoin.fst i a) + (r • ExtensionOfMaxAdjoin.snd i a) • y := by rw [ExtensionOfMaxAdjoin.eqn, smul_add, smul_eq_mul, mul_smul] rfl rw [ExtensionOfMaxAdjoin.extensionToFun_wd i f h (r • a :) _ _ eq1, LinearMap.map_smul, LinearPMap.map_smul, ← smul_add] congr } is_extension m := by dsimp rw [(extensionOfMax i f).is_extension, ExtensionOfMaxAdjoin.extensionToFun_wd i f h _ ⟨i m, _⟩ 0 _, map_zero, add_zero] simp theorem extensionOfMax_le (h : Module.Baer R Q) {y : N} : extensionOfMax i f ≤ extensionOfMaxAdjoin i f h y := ⟨le_sup_left, fun x x' EQ => by symm change ExtensionOfMaxAdjoin.extensionToFun i f h _ = _ rw [ExtensionOfMaxAdjoin.extensionToFun_wd i f h x' x 0 (by simp [EQ]), map_zero, add_zero]⟩ theorem extensionOfMax_to_submodule_eq_top (h : Module.Baer R Q) : (extensionOfMax i f).domain = ⊤ := by refine Submodule.eq_top_iff'.mpr fun y => ?_ dsimp rw [← extensionOfMax_is_max i f _ (extensionOfMax_le i f h), extensionOfMaxAdjoin, Submodule.mem_sup] exact ⟨0, Submodule.zero_mem _, y, Submodule.mem_span_singleton_self _, zero_add _⟩ protected theorem extension_property (h : Module.Baer R Q) (f : M →ₗ[R] N) (hf : Function.Injective f) (g : M →ₗ[R] Q) : ∃ h, h ∘ₗ f = g := haveI : Fact (Function.Injective f) := ⟨hf⟩ Exists.intro { toFun := ((extensionOfMax f g).toLinearPMap ⟨·, (extensionOfMax_to_submodule_eq_top f g h).symm ▸ ⟨⟩⟩) map_add' := fun x y ↦ by rw [← LinearPMap.map_add]; congr map_smul' := fun r x ↦ by rw [← LinearPMap.map_smul]; dsimp } <| LinearMap.ext fun x ↦ ((extensionOfMax f g).is_extension x).symm theorem extension_property_addMonoidHom (h : Module.Baer ℤ Q) (f : M →+ N) (hf : Function.Injective f) (g : M →+ Q) : ∃ h : N →+ Q, h.comp f = g := have ⟨g', hg'⟩ := h.extension_property f.toIntLinearMap hf g.toIntLinearMap ⟨g', congr(LinearMap.toAddMonoidHom $hg')⟩ /-- **Baer's criterion** for injective module : a Baer module is an injective module, i.e. if every linear map from an ideal can be extended, then the module is injective. -/ protected theorem injective (h : Module.Baer R Q) : Module.Injective R Q where out X Y _ _ _ _ i hi f := by obtain ⟨h, H⟩ := Module.Baer.extension_property h i hi f exact ⟨h, DFunLike.congr_fun H⟩ protected theorem of_injective [Small.{v} R] (inj : Module.Injective R Q) : Module.Baer R Q := by intro I g let eI := Shrink.linearEquiv I R let eR := Shrink.linearEquiv R R obtain ⟨g', hg'⟩ := Module.Injective.out (eR.symm.toLinearMap ∘ₗ I.subtype ∘ₗ eI.toLinearMap) (eR.symm.injective.comp <| Subtype.val_injective.comp eI.injective) (g ∘ₗ eI.toLinearMap) exact ⟨g' ∘ₗ eR.symm.toLinearMap, fun x mx ↦ by simpa [eI, eR] using hg' (equivShrink I ⟨x, mx⟩)⟩ protected theorem iff_injective [Small.{v} R] : Module.Baer R Q ↔ Module.Injective R Q := ⟨Module.Baer.injective, Module.Baer.of_injective⟩ end Module.Baer section ULift variable {M : Type v} [AddCommGroup M] [Module R M] lemma Module.ulift_injective_of_injective [Small.{v} R] (inj : Module.Injective R M) : Module.Injective R (ULift.{v'} M) := Module.Baer.injective fun I g ↦ have ⟨g', hg'⟩ := Module.Baer.iff_injective.mpr inj I (ULift.moduleEquiv.toLinearMap ∘ₗ g) ⟨ULift.moduleEquiv.symm.toLinearMap ∘ₗ g', fun r hr ↦ ULift.ext _ _ <| hg' r hr⟩ lemma Module.injective_of_ulift_injective (inj : Module.Injective R (ULift.{v'} M)) : Module.Injective R M where out X Y _ _ _ _ f hf g := let eX := ULift.moduleEquiv.{_,_,v'} (R := R) (M := X) have ⟨g', hg'⟩ := inj.out (ULift.moduleEquiv.{_,_,v'}.symm.toLinearMap ∘ₗ f ∘ₗ eX.toLinearMap) (by exact ULift.moduleEquiv.symm.injective.comp <| hf.comp eX.injective) (ULift.moduleEquiv.symm.toLinearMap ∘ₗ g ∘ₗ eX.toLinearMap) ⟨ULift.moduleEquiv.toLinearMap ∘ₗ g' ∘ₗ ULift.moduleEquiv.symm.toLinearMap, fun x ↦ by exact congr(ULift.down $(hg' ⟨x⟩))⟩ variable (M) [Small.{v} R] lemma Module.injective_iff_ulift_injective : Module.Injective R M ↔ Module.Injective R (ULift.{v'} M) := ⟨Module.ulift_injective_of_injective R, Module.injective_of_ulift_injective R⟩ end ULift section lifting_property universe uR uM uP uP'
variable (R : Type uR) [Ring R] [Small.{uM} R] variable (M : Type uM) [AddCommGroup M] [Module R M] [inj : Module.Injective R M] variable (P : Type uP) [AddCommGroup P] [Module R P] variable (P' : Type uP') [AddCommGroup P'] [Module R P'] lemma Module.Injective.extension_property (f : P →ₗ[R] P') (hf : Function.Injective f)
Mathlib/Algebra/Module/Injective.lean
429
435
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.CharP.Frobenius import Mathlib.Algebra.CharP.Pi import Mathlib.Algebra.CharP.Quotient import Mathlib.Algebra.CharP.Subring import Mathlib.Analysis.SpecialFunctions.Pow.NNReal import Mathlib.FieldTheory.Perfect import Mathlib.RingTheory.Valuation.Integers /-! # Ring Perfection and Tilt In this file we define the perfection of a ring of characteristic p, and the tilt of a field given a valuation to `ℝ≥0`. ## TODO Define the valuation on the tilt, and define a characteristic predicate for the tilt. -/ universe u₁ u₂ u₃ u₄ open scoped NNReal /-- The perfection of a monoid `M`, defined to be the projective limit of `M` using the `p`-th power maps `M → M` indexed by the natural numbers, implemented as `{ f : ℕ → M | ∀ n, f (n + 1) ^ p = f n }`. -/ def Monoid.perfection (M : Type u₁) [CommMonoid M] (p : ℕ) : Submonoid (ℕ → M) where carrier := { f | ∀ n, f (n + 1) ^ p = f n } one_mem' _ := one_pow _ mul_mem' hf hg n := (mul_pow _ _ _).trans <| congr_arg₂ _ (hf n) (hg n) /-- The perfection of a ring `R` with characteristic `p`, as a subsemiring, defined to be the projective limit of `R` using the Frobenius maps `R → R` indexed by the natural numbers, implemented as `{ f : ℕ → R | ∀ n, f (n + 1) ^ p = f n }`. -/ def Ring.perfectionSubsemiring (R : Type u₁) [CommSemiring R] (p : ℕ) [hp : Fact p.Prime] [CharP R p] : Subsemiring (ℕ → R) := { Monoid.perfection R p with zero_mem' := fun _ ↦ zero_pow hp.1.ne_zero add_mem' := fun hf hg n => (frobenius_add R p _ _).trans <| congr_arg₂ _ (hf n) (hg n) } /-- The perfection of a ring `R` with characteristic `p`, as a subring, defined to be the projective limit of `R` using the Frobenius maps `R → R` indexed by the natural numbers, implemented as `{ f : ℕ → R | ∀ n, f (n + 1) ^ p = f n }`. -/ def Ring.perfectionSubring (R : Type u₁) [CommRing R] (p : ℕ) [hp : Fact p.Prime] [CharP R p] : Subring (ℕ → R) := (Ring.perfectionSubsemiring R p).toSubring fun n => by simp_rw [← frobenius_def, Pi.neg_apply, Pi.one_apply, RingHom.map_neg, RingHom.map_one] /-- The perfection of a ring `R` with characteristic `p`, defined to be the projective limit of `R` using the Frobenius maps `R → R` indexed by the natural numbers, implemented as `{f : ℕ → R // ∀ n, f (n + 1) ^ p = f n}`. -/ def Ring.Perfection (R : Type u₁) [CommSemiring R] (p : ℕ) : Type u₁ := { f // ∀ n : ℕ, (f : ℕ → R) (n + 1) ^ p = f n } namespace Perfection variable (R : Type u₁) [CommSemiring R] (p : ℕ) [hp : Fact p.Prime] [CharP R p] instance commSemiring : CommSemiring (Ring.Perfection R p) := (Ring.perfectionSubsemiring R p).toCommSemiring instance charP : CharP (Ring.Perfection R p) p := CharP.subsemiring (ℕ → R) p (Ring.perfectionSubsemiring R p) instance ring (R : Type u₁) [CommRing R] [CharP R p] : Ring (Ring.Perfection R p) := (Ring.perfectionSubring R p).toRing instance commRing (R : Type u₁) [CommRing R] [CharP R p] : CommRing (Ring.Perfection R p) := (Ring.perfectionSubring R p).toCommRing instance : Inhabited (Ring.Perfection R p) := ⟨0⟩ /-- The `n`-th coefficient of an element of the perfection. -/ def coeff (n : ℕ) : Ring.Perfection R p →+* R where toFun f := f.1 n map_one' := rfl map_mul' _ _ := rfl map_zero' := rfl map_add' _ _ := rfl variable {R p} @[ext] theorem ext {f g : Ring.Perfection R p} (h : ∀ n, coeff R p n f = coeff R p n g) : f = g := Subtype.eq <| funext h variable (R p) /-- The `p`-th root of an element of the perfection. -/ def pthRoot : Ring.Perfection R p →+* Ring.Perfection R p where toFun f := ⟨fun n => coeff R p (n + 1) f, fun _ => f.2 _⟩ map_one' := rfl map_mul' _ _ := rfl map_zero' := rfl map_add' _ _ := rfl variable {R p} @[simp] theorem coeff_mk (f : ℕ → R) (hf) (n : ℕ) : coeff R p n ⟨f, hf⟩ = f n := rfl theorem coeff_pthRoot (f : Ring.Perfection R p) (n : ℕ) : coeff R p n (pthRoot R p f) = coeff R p (n + 1) f := rfl theorem coeff_pow_p (f : Ring.Perfection R p) (n : ℕ) : coeff R p (n + 1) (f ^ p) = coeff R p n f := by rw [RingHom.map_pow]; exact f.2 n theorem coeff_pow_p' (f : Ring.Perfection R p) (n : ℕ) : coeff R p (n + 1) f ^ p = coeff R p n f := f.2 n theorem coeff_frobenius (f : Ring.Perfection R p) (n : ℕ) : coeff R p (n + 1) (frobenius _ p f) = coeff R p n f := by apply coeff_pow_p f n -- `coeff_pow_p f n` also works but is slow! theorem coeff_iterate_frobenius (f : Ring.Perfection R p) (n m : ℕ) : coeff R p (n + m) ((frobenius _ p)^[m] f) = coeff R p n f := Nat.recOn m rfl fun m ih => by rw [Function.iterate_succ_apply', Nat.add_succ, coeff_frobenius, ih] theorem coeff_iterate_frobenius' (f : Ring.Perfection R p) (n m : ℕ) (hmn : m ≤ n) : coeff R p n ((frobenius _ p)^[m] f) = coeff R p (n - m) f := Eq.symm <| (coeff_iterate_frobenius _ _ m).symm.trans <| (tsub_add_cancel_of_le hmn).symm ▸ rfl theorem pthRoot_frobenius : (pthRoot R p).comp (frobenius _ p) = RingHom.id _ := RingHom.ext fun x => ext fun n => by rw [RingHom.comp_apply, RingHom.id_apply, coeff_pthRoot, coeff_frobenius] theorem frobenius_pthRoot : (frobenius _ p).comp (pthRoot R p) = RingHom.id _ := RingHom.ext fun x => ext fun n => by rw [RingHom.comp_apply, RingHom.id_apply, RingHom.map_frobenius, coeff_pthRoot, ← @RingHom.map_frobenius (Ring.Perfection R p) _ R, coeff_frobenius] theorem coeff_add_ne_zero {f : Ring.Perfection R p} {n : ℕ} (hfn : coeff R p n f ≠ 0) (k : ℕ) : coeff R p (n + k) f ≠ 0 := Nat.recOn k hfn fun k ih h => ih <| by rw [Nat.add_succ] at h rw [← coeff_pow_p, RingHom.map_pow, h, zero_pow hp.1.ne_zero] theorem coeff_ne_zero_of_le {f : Ring.Perfection R p} {m n : ℕ} (hfm : coeff R p m f ≠ 0) (hmn : m ≤ n) : coeff R p n f ≠ 0 := let ⟨k, hk⟩ := Nat.exists_eq_add_of_le hmn hk.symm ▸ coeff_add_ne_zero hfm k
variable (R p) instance perfectRing : PerfectRing (Ring.Perfection R p) p where
Mathlib/RingTheory/Perfection.lean
152
154
/- 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
Mathlib/Analysis/Calculus/LHopital.lean
132
141
/- Copyright (c) 2019 Gabriel Ebner. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Gabriel Ebner, Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.FDeriv.Basic import Mathlib.Analysis.NormedSpace.OperatorNorm.NormedSpace /-! # One-dimensional derivatives This file defines the derivative of a function `f : 𝕜 → F` where `𝕜` is a normed field and `F` is a normed space over this field. The derivative of such a function `f` at a point `x` is given by an element `f' : F`. The theory is developed analogously to the [Fréchet derivatives](./fderiv.html). We first introduce predicates defined in terms of the corresponding predicates for Fréchet derivatives: - `HasDerivAtFilter f f' x L` states that the function `f` has the derivative `f'` at the point `x` as `x` goes along the filter `L`. - `HasDerivWithinAt f f' s x` states that the function `f` has the derivative `f'` at the point `x` within the subset `s`. - `HasDerivAt f f' x` states that the function `f` has the derivative `f'` at the point `x`. - `HasStrictDerivAt f f' x` states that the function `f` has the derivative `f'` at the point `x` in the sense of strict differentiability, i.e., `f y - f z = (y - z) • f' + o (y - z)` as `y, z → x`. For the last two notions we also define a functional version: - `derivWithin f s x` is a derivative of `f` at `x` within `s`. If the derivative does not exist, then `derivWithin f s x` equals zero. - `deriv f x` is a derivative of `f` at `x`. If the derivative does not exist, then `deriv f x` equals zero. The theorems `fderivWithin_derivWithin` and `fderiv_deriv` show that the one-dimensional derivatives coincide with the general Fréchet derivatives. We also show the existence and compute the derivatives of: - constants - the identity function - linear maps (in `Linear.lean`) - addition (in `Add.lean`) - sum of finitely many functions (in `Add.lean`) - negation (in `Add.lean`) - subtraction (in `Add.lean`) - star (in `Star.lean`) - multiplication of two functions in `𝕜 → 𝕜` (in `Mul.lean`) - multiplication of a function in `𝕜 → 𝕜` and of a function in `𝕜 → E` (in `Mul.lean`) - powers of a function (in `Pow.lean` and `ZPow.lean`) - inverse `x → x⁻¹` (in `Inv.lean`) - division (in `Inv.lean`) - composition of a function in `𝕜 → F` with a function in `𝕜 → 𝕜` (in `Comp.lean`) - composition of a function in `F → E` with a function in `𝕜 → F` (in `Comp.lean`) - inverse function (assuming that it exists; the inverse function theorem is in `Inverse.lean`) - polynomials (in `Polynomial.lean`) For most binary operations we also define `const_op` and `op_const` theorems for the cases when the first or second argument is a constant. This makes writing chains of `HasDerivAt`'s easier, and they more frequently lead to the desired result. We set up the simplifier so that it can compute the derivative of simple functions. For instance, ```lean example (x : ℝ) : deriv (fun x ↦ cos (sin x) * exp x) x = (cos (sin x) - sin (sin x) * cos x) * exp x := by simp; ring ``` The relationship between the derivative of a function and its definition from a standard undergraduate course as the limit of the slope `(f y - f x) / (y - x)` as `y` tends to `𝓝[≠] x` is developed in the file `Slope.lean`. ## Implementation notes Most of the theorems are direct restatements of the corresponding theorems for Fréchet derivatives. The strategy to construct simp lemmas that give the simplifier the possibility to compute derivatives is the same as the one for differentiability statements, as explained in `FDeriv/Basic.lean`. See the explanations there. -/ universe u v w noncomputable section open scoped Topology ENNReal NNReal open Filter Asymptotics Set open ContinuousLinearMap (smulRight smulRight_one_eq_iff) section TVS variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] variable {F : Type v} [AddCommGroup F] [Module 𝕜 F] [TopologicalSpace F] section variable [ContinuousSMul 𝕜 F] /-- `f` has the derivative `f'` at the point `x` as `x` goes along the filter `L`. That is, `f x' = f x + (x' - x) • f' + o(x' - x)` where `x'` converges along the filter `L`. -/ def HasDerivAtFilter (f : 𝕜 → F) (f' : F) (x : 𝕜) (L : Filter 𝕜) := HasFDerivAtFilter f (smulRight (1 : 𝕜 →L[𝕜] 𝕜) f') x L /-- `f` has the derivative `f'` at the point `x` within the subset `s`. That is, `f x' = f x + (x' - x) • f' + o(x' - x)` where `x'` converges to `x` inside `s`. -/ def HasDerivWithinAt (f : 𝕜 → F) (f' : F) (s : Set 𝕜) (x : 𝕜) := HasDerivAtFilter f f' x (𝓝[s] x) /-- `f` has the derivative `f'` at the point `x`. That is, `f x' = f x + (x' - x) • f' + o(x' - x)` where `x'` converges to `x`. -/ def HasDerivAt (f : 𝕜 → F) (f' : F) (x : 𝕜) := HasDerivAtFilter f f' x (𝓝 x) /-- `f` has the derivative `f'` at the point `x` in the sense of strict differentiability. That is, `f y - f z = (y - z) • f' + o(y - z)` as `y, z → x`. -/ def HasStrictDerivAt (f : 𝕜 → F) (f' : F) (x : 𝕜) := HasStrictFDerivAt f (smulRight (1 : 𝕜 →L[𝕜] 𝕜) f') x end /-- Derivative of `f` at the point `x` within the set `s`, if it exists. Zero otherwise. If the derivative exists (i.e., `∃ f', HasDerivWithinAt f f' s x`), then `f x' = f x + (x' - x) • derivWithin f s x + o(x' - x)` where `x'` converges to `x` inside `s`. -/ def derivWithin (f : 𝕜 → F) (s : Set 𝕜) (x : 𝕜) := fderivWithin 𝕜 f s x 1 /-- Derivative of `f` at the point `x`, if it exists. Zero otherwise. If the derivative exists (i.e., `∃ f', HasDerivAt f f' x`), then `f x' = f x + (x' - x) • deriv f x + o(x' - x)` where `x'` converges to `x`. -/ def deriv (f : 𝕜 → F) (x : 𝕜) := fderiv 𝕜 f x 1 variable {f f₀ f₁ : 𝕜 → F} variable {f' f₀' f₁' g' : F} variable {x : 𝕜} variable {s t : Set 𝕜} variable {L L₁ L₂ : Filter 𝕜} section variable [ContinuousSMul 𝕜 F] /-- Expressing `HasFDerivAtFilter f f' x L` in terms of `HasDerivAtFilter` -/ theorem hasFDerivAtFilter_iff_hasDerivAtFilter {f' : 𝕜 →L[𝕜] F} : HasFDerivAtFilter f f' x L ↔ HasDerivAtFilter f (f' 1) x L := by simp [HasDerivAtFilter] theorem HasFDerivAtFilter.hasDerivAtFilter {f' : 𝕜 →L[𝕜] F} : HasFDerivAtFilter f f' x L → HasDerivAtFilter f (f' 1) x L := hasFDerivAtFilter_iff_hasDerivAtFilter.mp /-- Expressing `HasFDerivWithinAt f f' s x` in terms of `HasDerivWithinAt` -/ theorem hasFDerivWithinAt_iff_hasDerivWithinAt {f' : 𝕜 →L[𝕜] F} : HasFDerivWithinAt f f' s x ↔ HasDerivWithinAt f (f' 1) s x := hasFDerivAtFilter_iff_hasDerivAtFilter /-- Expressing `HasDerivWithinAt f f' s x` in terms of `HasFDerivWithinAt` -/ theorem hasDerivWithinAt_iff_hasFDerivWithinAt {f' : F} : HasDerivWithinAt f f' s x ↔ HasFDerivWithinAt f (smulRight (1 : 𝕜 →L[𝕜] 𝕜) f') s x := Iff.rfl theorem HasFDerivWithinAt.hasDerivWithinAt {f' : 𝕜 →L[𝕜] F} : HasFDerivWithinAt f f' s x → HasDerivWithinAt f (f' 1) s x := hasFDerivWithinAt_iff_hasDerivWithinAt.mp theorem HasDerivWithinAt.hasFDerivWithinAt {f' : F} : HasDerivWithinAt f f' s x → HasFDerivWithinAt f (smulRight (1 : 𝕜 →L[𝕜] 𝕜) f') s x := hasDerivWithinAt_iff_hasFDerivWithinAt.mp /-- Expressing `HasFDerivAt f f' x` in terms of `HasDerivAt` -/ theorem hasFDerivAt_iff_hasDerivAt {f' : 𝕜 →L[𝕜] F} : HasFDerivAt f f' x ↔ HasDerivAt f (f' 1) x := hasFDerivAtFilter_iff_hasDerivAtFilter theorem HasFDerivAt.hasDerivAt {f' : 𝕜 →L[𝕜] F} : HasFDerivAt f f' x → HasDerivAt f (f' 1) x := hasFDerivAt_iff_hasDerivAt.mp theorem hasStrictFDerivAt_iff_hasStrictDerivAt {f' : 𝕜 →L[𝕜] F} : HasStrictFDerivAt f f' x ↔ HasStrictDerivAt f (f' 1) x := by simp [HasStrictDerivAt, HasStrictFDerivAt] protected theorem HasStrictFDerivAt.hasStrictDerivAt {f' : 𝕜 →L[𝕜] F} : HasStrictFDerivAt f f' x → HasStrictDerivAt f (f' 1) x := hasStrictFDerivAt_iff_hasStrictDerivAt.mp theorem hasStrictDerivAt_iff_hasStrictFDerivAt : HasStrictDerivAt f f' x ↔ HasStrictFDerivAt f (smulRight (1 : 𝕜 →L[𝕜] 𝕜) f') x := Iff.rfl alias ⟨HasStrictDerivAt.hasStrictFDerivAt, _⟩ := hasStrictDerivAt_iff_hasStrictFDerivAt /-- Expressing `HasDerivAt f f' x` in terms of `HasFDerivAt` -/ theorem hasDerivAt_iff_hasFDerivAt {f' : F} : HasDerivAt f f' x ↔ HasFDerivAt f (smulRight (1 : 𝕜 →L[𝕜] 𝕜) f') x := Iff.rfl alias ⟨HasDerivAt.hasFDerivAt, _⟩ := hasDerivAt_iff_hasFDerivAt end theorem derivWithin_zero_of_not_differentiableWithinAt (h : ¬DifferentiableWithinAt 𝕜 f s x) : derivWithin f s x = 0 := by unfold derivWithin rw [fderivWithin_zero_of_not_differentiableWithinAt h] simp theorem differentiableWithinAt_of_derivWithin_ne_zero (h : derivWithin f s x ≠ 0) : DifferentiableWithinAt 𝕜 f s x := not_imp_comm.1 derivWithin_zero_of_not_differentiableWithinAt h end TVS variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {f f₀ f₁ : 𝕜 → F} variable {f' f₀' f₁' g' : F} variable {x : 𝕜} variable {s t : Set 𝕜} variable {L L₁ L₂ : Filter 𝕜} theorem derivWithin_zero_of_not_accPt (h : ¬AccPt x (𝓟 s)) : derivWithin f s x = 0 := by rw [derivWithin, fderivWithin_zero_of_not_accPt h, ContinuousLinearMap.zero_apply] theorem derivWithin_zero_of_not_uniqueDiffWithinAt (h : ¬UniqueDiffWithinAt 𝕜 s x) : derivWithin f s x = 0 := derivWithin_zero_of_not_accPt <| mt AccPt.uniqueDiffWithinAt h set_option linter.deprecated false in @[deprecated derivWithin_zero_of_not_accPt (since := "2025-04-20")] theorem derivWithin_zero_of_isolated (h : 𝓝[s \ {x}] x = ⊥) : derivWithin f s x = 0 := by rw [derivWithin, fderivWithin_zero_of_isolated h, ContinuousLinearMap.zero_apply] theorem derivWithin_zero_of_nmem_closure (h : x ∉ closure s) : derivWithin f s x = 0 := by rw [derivWithin, fderivWithin_zero_of_nmem_closure h, ContinuousLinearMap.zero_apply] theorem deriv_zero_of_not_differentiableAt (h : ¬DifferentiableAt 𝕜 f x) : deriv f x = 0 := by unfold deriv rw [fderiv_zero_of_not_differentiableAt h] simp theorem differentiableAt_of_deriv_ne_zero (h : deriv f x ≠ 0) : DifferentiableAt 𝕜 f x := not_imp_comm.1 deriv_zero_of_not_differentiableAt h theorem UniqueDiffWithinAt.eq_deriv (s : Set 𝕜) (H : UniqueDiffWithinAt 𝕜 s x) (h : HasDerivWithinAt f f' s x) (h₁ : HasDerivWithinAt f f₁' s x) : f' = f₁' := smulRight_one_eq_iff.mp <| UniqueDiffWithinAt.eq H h h₁ theorem hasDerivAtFilter_iff_isLittleO : HasDerivAtFilter f f' x L ↔ (fun x' : 𝕜 => f x' - f x - (x' - x) • f') =o[L] fun x' => x' - x := hasFDerivAtFilter_iff_isLittleO .. theorem hasDerivAtFilter_iff_tendsto : HasDerivAtFilter f f' x L ↔ Tendsto (fun x' : 𝕜 => ‖x' - x‖⁻¹ * ‖f x' - f x - (x' - x) • f'‖) L (𝓝 0) := hasFDerivAtFilter_iff_tendsto theorem hasDerivWithinAt_iff_isLittleO : HasDerivWithinAt f f' s x ↔ (fun x' : 𝕜 => f x' - f x - (x' - x) • f') =o[𝓝[s] x] fun x' => x' - x := hasFDerivAtFilter_iff_isLittleO .. theorem hasDerivWithinAt_iff_tendsto : HasDerivWithinAt f f' s x ↔ Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - (x' - x) • f'‖) (𝓝[s] x) (𝓝 0) := hasFDerivAtFilter_iff_tendsto theorem hasDerivAt_iff_isLittleO : HasDerivAt f f' x ↔ (fun x' : 𝕜 => f x' - f x - (x' - x) • f') =o[𝓝 x] fun x' => x' - x := hasFDerivAtFilter_iff_isLittleO .. theorem hasDerivAt_iff_tendsto : HasDerivAt f f' x ↔ Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - (x' - x) • f'‖) (𝓝 x) (𝓝 0) := hasFDerivAtFilter_iff_tendsto theorem HasDerivAtFilter.isBigO_sub (h : HasDerivAtFilter f f' x L) : (fun x' => f x' - f x) =O[L] fun x' => x' - x := HasFDerivAtFilter.isBigO_sub h nonrec theorem HasDerivAtFilter.isBigO_sub_rev (hf : HasDerivAtFilter f f' x L) (hf' : f' ≠ 0) : (fun x' => x' - x) =O[L] fun x' => f x' - f x := suffices AntilipschitzWith ‖f'‖₊⁻¹ (smulRight (1 : 𝕜 →L[𝕜] 𝕜) f') from hf.isBigO_sub_rev this AddMonoidHomClass.antilipschitz_of_bound (smulRight (1 : 𝕜 →L[𝕜] 𝕜) f') fun x => by simp [norm_smul, ← div_eq_inv_mul, mul_div_cancel_right₀ _ (mt norm_eq_zero.1 hf')] theorem HasStrictDerivAt.hasDerivAt (h : HasStrictDerivAt f f' x) : HasDerivAt f f' x := h.hasFDerivAt theorem hasDerivWithinAt_congr_set' {s t : Set 𝕜} (y : 𝕜) (h : s =ᶠ[𝓝[{y}ᶜ] x] t) : HasDerivWithinAt f f' s x ↔ HasDerivWithinAt f f' t x := hasFDerivWithinAt_congr_set' y h theorem hasDerivWithinAt_congr_set {s t : Set 𝕜} (h : s =ᶠ[𝓝 x] t) : HasDerivWithinAt f f' s x ↔ HasDerivWithinAt f f' t x := hasFDerivWithinAt_congr_set h alias ⟨HasDerivWithinAt.congr_set, _⟩ := hasDerivWithinAt_congr_set @[simp] theorem hasDerivWithinAt_diff_singleton : HasDerivWithinAt f f' (s \ {x}) x ↔ HasDerivWithinAt f f' s x := hasFDerivWithinAt_diff_singleton _ @[simp] theorem hasDerivWithinAt_Ioi_iff_Ici [PartialOrder 𝕜] : HasDerivWithinAt f f' (Ioi x) x ↔ HasDerivWithinAt f f' (Ici x) x := by rw [← Ici_diff_left, hasDerivWithinAt_diff_singleton] alias ⟨HasDerivWithinAt.Ici_of_Ioi, HasDerivWithinAt.Ioi_of_Ici⟩ := hasDerivWithinAt_Ioi_iff_Ici @[simp] theorem hasDerivWithinAt_Iio_iff_Iic [PartialOrder 𝕜] : HasDerivWithinAt f f' (Iio x) x ↔ HasDerivWithinAt f f' (Iic x) x := by rw [← Iic_diff_right, hasDerivWithinAt_diff_singleton] alias ⟨HasDerivWithinAt.Iic_of_Iio, HasDerivWithinAt.Iio_of_Iic⟩ := hasDerivWithinAt_Iio_iff_Iic theorem HasDerivWithinAt.Ioi_iff_Ioo [LinearOrder 𝕜] [OrderClosedTopology 𝕜] {x y : 𝕜} (h : x < y) : HasDerivWithinAt f f' (Ioo x y) x ↔ HasDerivWithinAt f f' (Ioi x) x := hasFDerivWithinAt_inter <| Iio_mem_nhds h alias ⟨HasDerivWithinAt.Ioi_of_Ioo, HasDerivWithinAt.Ioo_of_Ioi⟩ := HasDerivWithinAt.Ioi_iff_Ioo theorem hasDerivAt_iff_isLittleO_nhds_zero : HasDerivAt f f' x ↔ (fun h => f (x + h) - f x - h • f') =o[𝓝 0] fun h => h := hasFDerivAt_iff_isLittleO_nhds_zero theorem HasDerivAtFilter.mono (h : HasDerivAtFilter f f' x L₂) (hst : L₁ ≤ L₂) : HasDerivAtFilter f f' x L₁ := HasFDerivAtFilter.mono h hst theorem HasDerivWithinAt.mono (h : HasDerivWithinAt f f' t x) (hst : s ⊆ t) : HasDerivWithinAt f f' s x := HasFDerivWithinAt.mono h hst theorem HasDerivWithinAt.mono_of_mem_nhdsWithin (h : HasDerivWithinAt f f' t x) (hst : t ∈ 𝓝[s] x) : HasDerivWithinAt f f' s x := HasFDerivWithinAt.mono_of_mem_nhdsWithin h hst @[deprecated (since := "2024-10-31")] alias HasDerivWithinAt.mono_of_mem := HasDerivWithinAt.mono_of_mem_nhdsWithin theorem HasDerivAt.hasDerivAtFilter (h : HasDerivAt f f' x) (hL : L ≤ 𝓝 x) : HasDerivAtFilter f f' x L := HasFDerivAt.hasFDerivAtFilter h hL theorem HasDerivAt.hasDerivWithinAt (h : HasDerivAt f f' x) : HasDerivWithinAt f f' s x := HasFDerivAt.hasFDerivWithinAt h theorem HasDerivWithinAt.differentiableWithinAt (h : HasDerivWithinAt f f' s x) : DifferentiableWithinAt 𝕜 f s x := HasFDerivWithinAt.differentiableWithinAt h theorem HasDerivAt.differentiableAt (h : HasDerivAt f f' x) : DifferentiableAt 𝕜 f x := HasFDerivAt.differentiableAt h @[simp] theorem hasDerivWithinAt_univ : HasDerivWithinAt f f' univ x ↔ HasDerivAt f f' x := hasFDerivWithinAt_univ theorem HasDerivAt.unique (h₀ : HasDerivAt f f₀' x) (h₁ : HasDerivAt f f₁' x) : f₀' = f₁' := smulRight_one_eq_iff.mp <| h₀.hasFDerivAt.unique h₁ theorem hasDerivWithinAt_inter' (h : t ∈ 𝓝[s] x) : HasDerivWithinAt f f' (s ∩ t) x ↔ HasDerivWithinAt f f' s x := hasFDerivWithinAt_inter' h theorem hasDerivWithinAt_inter (h : t ∈ 𝓝 x) : HasDerivWithinAt f f' (s ∩ t) x ↔ HasDerivWithinAt f f' s x := hasFDerivWithinAt_inter h theorem HasDerivWithinAt.union (hs : HasDerivWithinAt f f' s x) (ht : HasDerivWithinAt f f' t x) : HasDerivWithinAt f f' (s ∪ t) x := hs.hasFDerivWithinAt.union ht.hasFDerivWithinAt theorem HasDerivWithinAt.hasDerivAt (h : HasDerivWithinAt f f' s x) (hs : s ∈ 𝓝 x) : HasDerivAt f f' x := HasFDerivWithinAt.hasFDerivAt h hs theorem DifferentiableWithinAt.hasDerivWithinAt (h : DifferentiableWithinAt 𝕜 f s x) : HasDerivWithinAt f (derivWithin f s x) s x := h.hasFDerivWithinAt.hasDerivWithinAt theorem DifferentiableAt.hasDerivAt (h : DifferentiableAt 𝕜 f x) : HasDerivAt f (deriv f x) x := h.hasFDerivAt.hasDerivAt @[simp] theorem hasDerivAt_deriv_iff : HasDerivAt f (deriv f x) x ↔ DifferentiableAt 𝕜 f x := ⟨fun h => h.differentiableAt, fun h => h.hasDerivAt⟩ @[simp] theorem hasDerivWithinAt_derivWithin_iff : HasDerivWithinAt f (derivWithin f s x) s x ↔ DifferentiableWithinAt 𝕜 f s x := ⟨fun h => h.differentiableWithinAt, fun h => h.hasDerivWithinAt⟩ theorem DifferentiableOn.hasDerivAt (h : DifferentiableOn 𝕜 f s) (hs : s ∈ 𝓝 x) : HasDerivAt f (deriv f x) x := (h.hasFDerivAt hs).hasDerivAt theorem HasDerivAt.deriv (h : HasDerivAt f f' x) : deriv f x = f' := h.differentiableAt.hasDerivAt.unique h theorem deriv_eq {f' : 𝕜 → F} (h : ∀ x, HasDerivAt f (f' x) x) : deriv f = f' := funext fun x => (h x).deriv theorem HasDerivWithinAt.derivWithin (h : HasDerivWithinAt f f' s x) (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin f s x = f' := hxs.eq_deriv _ h.differentiableWithinAt.hasDerivWithinAt h theorem fderivWithin_derivWithin : (fderivWithin 𝕜 f s x : 𝕜 → F) 1 = derivWithin f s x := rfl theorem derivWithin_fderivWithin : smulRight (1 : 𝕜 →L[𝕜] 𝕜) (derivWithin f s x) = fderivWithin 𝕜 f s x := by simp [derivWithin] theorem norm_derivWithin_eq_norm_fderivWithin : ‖derivWithin f s x‖ = ‖fderivWithin 𝕜 f s x‖ := by simp [← derivWithin_fderivWithin] theorem fderiv_deriv : (fderiv 𝕜 f x : 𝕜 → F) 1 = deriv f x := rfl @[simp] theorem fderiv_eq_smul_deriv (y : 𝕜) : (fderiv 𝕜 f x : 𝕜 → F) y = y • deriv f x := by rw [← fderiv_deriv, ← ContinuousLinearMap.map_smul] simp only [smul_eq_mul, mul_one] theorem deriv_fderiv : smulRight (1 : 𝕜 →L[𝕜] 𝕜) (deriv f x) = fderiv 𝕜 f x := by simp only [deriv, ContinuousLinearMap.smulRight_one_one] lemma fderiv_eq_deriv_mul {f : 𝕜 → 𝕜} {x y : 𝕜} : (fderiv 𝕜 f x : 𝕜 → 𝕜) y = (deriv f x) * y := by simp [mul_comm] theorem norm_deriv_eq_norm_fderiv : ‖deriv f x‖ = ‖fderiv 𝕜 f x‖ := by simp [← deriv_fderiv] theorem DifferentiableAt.derivWithin (h : DifferentiableAt 𝕜 f x) (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin f s x = deriv f x := by unfold _root_.derivWithin deriv rw [h.fderivWithin hxs] theorem HasDerivWithinAt.deriv_eq_zero (hd : HasDerivWithinAt f 0 s x) (H : UniqueDiffWithinAt 𝕜 s x) : deriv f x = 0 := (em' (DifferentiableAt 𝕜 f x)).elim deriv_zero_of_not_differentiableAt fun h => H.eq_deriv _ h.hasDerivAt.hasDerivWithinAt hd theorem derivWithin_of_mem_nhdsWithin (st : t ∈ 𝓝[s] x) (ht : UniqueDiffWithinAt 𝕜 s x) (h : DifferentiableWithinAt 𝕜 f t x) : derivWithin f s x = derivWithin f t x := ((DifferentiableWithinAt.hasDerivWithinAt h).mono_of_mem_nhdsWithin st).derivWithin ht @[deprecated (since := "2024-10-31")] alias derivWithin_of_mem := derivWithin_of_mem_nhdsWithin theorem derivWithin_subset (st : s ⊆ t) (ht : UniqueDiffWithinAt 𝕜 s x) (h : DifferentiableWithinAt 𝕜 f t x) : derivWithin f s x = derivWithin f t x := ((DifferentiableWithinAt.hasDerivWithinAt h).mono st).derivWithin ht theorem derivWithin_congr_set' (y : 𝕜) (h : s =ᶠ[𝓝[{y}ᶜ] x] t) : derivWithin f s x = derivWithin f t x := by simp only [derivWithin, fderivWithin_congr_set' y h] theorem derivWithin_congr_set (h : s =ᶠ[𝓝 x] t) : derivWithin f s x = derivWithin f t x := by simp only [derivWithin, fderivWithin_congr_set h] @[simp]
theorem derivWithin_univ : derivWithin f univ = deriv f := by ext
Mathlib/Analysis/Calculus/Deriv/Basic.lean
474
475
/- 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.MeasureTheory.Measure.Doubling import Mathlib.MeasureTheory.Covering.Vitali import Mathlib.MeasureTheory.Covering.Differentiation /-! # Uniformly locally doubling measures and Lebesgue's density theorem Lebesgue's density theorem states that given a set `S` in a sigma compact metric space with locally-finite uniformly locally doubling measure `μ` then for almost all points `x` in `S`, for any sequence of closed balls `B₀, B₁, B₂, ...` containing `x`, the limit `μ (S ∩ Bⱼ) / μ (Bⱼ) → 1` as `j → ∞`. In this file we combine general results about existence of Vitali families for uniformly locally doubling measures with results about differentiation along a Vitali family to obtain an explicit form of Lebesgue's density theorem. ## Main results * `IsUnifLocDoublingMeasure.ae_tendsto_measure_inter_div`: a version of Lebesgue's density theorem for sequences of balls converging on a point but whose centres are not required to be fixed. -/ noncomputable section open Set Filter Metric MeasureTheory TopologicalSpace open scoped NNReal Topology namespace IsUnifLocDoublingMeasure variable {α : Type*} [PseudoMetricSpace α] [MeasurableSpace α] (μ : Measure α) [IsUnifLocDoublingMeasure μ] section variable [SecondCountableTopology α] [BorelSpace α] [IsLocallyFiniteMeasure μ] open scoped Topology /-- A Vitali family in a space with a uniformly locally doubling measure, designed so that the sets at `x` contain all `closedBall y r` when `dist x y ≤ K * r`. -/ irreducible_def vitaliFamily (K : ℝ) : VitaliFamily μ := by /- the Vitali covering theorem gives a family that works well at small scales, thanks to the doubling property. We enlarge this family to add large sets, to make sure that all balls and not only small ones belong to the family, for convenience. -/ let R := scalingScaleOf μ (max (4 * K + 3) 3) have Rpos : 0 < R := scalingScaleOf_pos _ _ have A : ∀ x : α, ∃ᶠ r in 𝓝[>] (0 : ℝ), μ (closedBall x (3 * r)) ≤ scalingConstantOf μ (max (4 * K + 3) 3) * μ (closedBall x r) := by intro x apply frequently_iff.2 fun {U} hU => ?_ obtain ⟨ε, εpos, hε⟩ := mem_nhdsGT_iff_exists_Ioc_subset.1 hU refine ⟨min ε R, hε ⟨lt_min εpos Rpos, min_le_left _ _⟩, ?_⟩ exact measure_mul_le_scalingConstantOf_mul μ ⟨zero_lt_three, le_max_right _ _⟩ (min_le_right _ _) exact (Vitali.vitaliFamily μ (scalingConstantOf μ (max (4 * K + 3) 3)) A).enlarge (R / 4) (by linarith) /-- In the Vitali family `IsUnifLocDoublingMeasure.vitaliFamily K`, the sets based at `x` contain all balls `closedBall y r` when `dist x y ≤ K * r`. -/ theorem closedBall_mem_vitaliFamily_of_dist_le_mul {K : ℝ} {x y : α} {r : ℝ} (h : dist x y ≤ K * r) (rpos : 0 < r) : closedBall y r ∈ (vitaliFamily μ K).setsAt x := by let R := scalingScaleOf μ (max (4 * K + 3) 3) simp only [vitaliFamily, VitaliFamily.enlarge, Vitali.vitaliFamily, mem_union, mem_setOf_eq, isClosed_closedBall, true_and, (nonempty_ball.2 rpos).mono ball_subset_interior_closedBall, measurableSet_closedBall] /- The measure is doubling on scales smaller than `R`. Therefore, we treat differently small and large balls. For large balls, this follows directly from the enlargement we used in the definition. -/ by_cases H : closedBall y r ⊆ closedBall x (R / 4) swap; · exact Or.inr H left /- For small balls, there is the difficulty that `r` could be large but still the ball could be small, if the annulus `{y | ε ≤ dist y x ≤ R/4}` is empty. We split between the cases `r ≤ R` and `r > R`, and use the doubling for the former and rough estimates for the latter. -/ rcases le_or_lt r R with (hr | hr) · refine ⟨(K + 1) * r, ?_⟩ constructor · apply closedBall_subset_closedBall' rw [dist_comm] linarith · have I1 : closedBall x (3 * ((K + 1) * r)) ⊆ closedBall y ((4 * K + 3) * r) := by apply closedBall_subset_closedBall' linarith have I2 : closedBall y ((4 * K + 3) * r) ⊆ closedBall y (max (4 * K + 3) 3 * r) := by apply closedBall_subset_closedBall exact mul_le_mul_of_nonneg_right (le_max_left _ _) rpos.le apply (measure_mono (I1.trans I2)).trans exact measure_mul_le_scalingConstantOf_mul _ ⟨zero_lt_three.trans_le (le_max_right _ _), le_rfl⟩ hr · refine ⟨R / 4, H, ?_⟩ have : closedBall x (3 * (R / 4)) ⊆ closedBall y r := by apply closedBall_subset_closedBall' have A : y ∈ closedBall y r := mem_closedBall_self rpos.le have B := mem_closedBall'.1 (H A) linarith apply (measure_mono this).trans _ refine le_mul_of_one_le_left (zero_le _) ?_ exact ENNReal.one_le_coe_iff.2 (le_max_right _ _) theorem tendsto_closedBall_filterAt {K : ℝ} {x : α} {ι : Type*} {l : Filter ι} (w : ι → α) (δ : ι → ℝ) (δlim : Tendsto δ l (𝓝[>] 0)) (xmem : ∀ᶠ j in l, x ∈ closedBall (w j) (K * δ j)) : Tendsto (fun j => closedBall (w j) (δ j)) l ((vitaliFamily μ K).filterAt x) := by refine (vitaliFamily μ K).tendsto_filterAt_iff.mpr ⟨?_, fun ε hε => ?_⟩ · filter_upwards [xmem, δlim self_mem_nhdsWithin] with j hj h'j exact closedBall_mem_vitaliFamily_of_dist_le_mul μ hj h'j · rcases l.eq_or_neBot with rfl | h · simp have hK : 0 ≤ K := by rcases (xmem.and (δlim self_mem_nhdsWithin)).exists with ⟨j, hj, h'j⟩ have : 0 ≤ K * δ j := nonempty_closedBall.1 ⟨x, hj⟩ exact (mul_nonneg_iff_left_nonneg_of_pos (mem_Ioi.1 h'j)).1 this have δpos := eventually_mem_of_tendsto_nhdsWithin δlim replace δlim := tendsto_nhds_of_tendsto_nhdsWithin δlim replace hK : 0 < K + 1 := by linarith apply (((Metric.tendsto_nhds.mp δlim _ (div_pos hε hK)).and δpos).and xmem).mono rintro j ⟨⟨hjε, hj₀ : 0 < δ j⟩, hx⟩ y hy replace hjε : (K + 1) * δ j < ε := by simpa [abs_eq_self.mpr hj₀.le] using (lt_div_iff₀' hK).mp hjε simp only [mem_closedBall] at hx hy ⊢ linarith [dist_triangle_right y x (w j)] end section Applications variable [SecondCountableTopology α] [BorelSpace α] [IsLocallyFiniteMeasure μ] {E : Type*} [NormedAddCommGroup E] /-- A version of **Lebesgue's density theorem** for a sequence of closed balls whose centers are not required to be fixed. See also `Besicovitch.ae_tendsto_measure_inter_div`. -/ theorem ae_tendsto_measure_inter_div (S : Set α) (K : ℝ) : ∀ᵐ x ∂μ.restrict S, ∀ {ι : Type*} {l : Filter ι} (w : ι → α) (δ : ι → ℝ) (_ : Tendsto δ l (𝓝[>] 0)) (_ : ∀ᶠ j in l, x ∈ closedBall (w j) (K * δ j)), Tendsto (fun j => μ (S ∩ closedBall (w j) (δ j)) / μ (closedBall (w j) (δ j))) l (𝓝 1) := by filter_upwards [(vitaliFamily μ K).ae_tendsto_measure_inter_div S] with x hx ι l w δ δlim
xmem using hx.comp (tendsto_closedBall_filterAt μ _ _ δlim xmem) /-- A version of **Lebesgue differentiation theorem** for a sequence of closed balls whose centers are not required to be fixed. -/ theorem ae_tendsto_average_norm_sub {f : α → E} (hf : LocallyIntegrable f μ) (K : ℝ) : ∀ᵐ x ∂μ, ∀ {ι : Type*} {l : Filter ι} (w : ι → α) (δ : ι → ℝ) (_ : Tendsto δ l (𝓝[>] 0))
Mathlib/MeasureTheory/Covering/DensityTheorem.lean
146
151
/- Copyright (c) 2023 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.Probability.ConditionalProbability import Mathlib.Probability.Kernel.Basic import Mathlib.Probability.Kernel.Composition.MeasureComp import Mathlib.Tactic.Peel import Mathlib.MeasureTheory.MeasurableSpace.Pi /-! # Independence with respect to a kernel and a measure A family of sets of sets `π : ι → Set (Set Ω)` is independent with respect to a kernel `κ : Kernel α Ω` and a measure `μ` on `α` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ π i_1, ..., f i_n ∈ π i_n`, then for `μ`-almost every `a : α`, `κ a (⋂ i in s, f i) = ∏ i ∈ s, κ a (f i)`. This notion of independence is a generalization of both independence and conditional independence. For conditional independence, `κ` is the conditional kernel `ProbabilityTheory.condExpKernel` and `μ` is the ambient measure. For (non-conditional) independence, `κ = Kernel.const Unit μ` and the measure is the Dirac measure on `Unit`. The main purpose of this file is to prove only once the properties that hold for both conditional and non-conditional independence. ## Main definitions * `ProbabilityTheory.Kernel.iIndepSets`: independence of a family of sets of sets. Variant for two sets of sets: `ProbabilityTheory.Kernel.IndepSets`. * `ProbabilityTheory.Kernel.iIndep`: independence of a family of σ-algebras. Variant for two σ-algebras: `Indep`. * `ProbabilityTheory.Kernel.iIndepSet`: independence of a family of sets. Variant for two sets: `ProbabilityTheory.Kernel.IndepSet`. * `ProbabilityTheory.Kernel.iIndepFun`: independence of a family of functions (random variables). Variant for two functions: `ProbabilityTheory.Kernel.IndepFun`. See the file `Mathlib/Probability/Kernel/Basic.lean` for a more detailed discussion of these definitions in the particular case of the usual independence notion. ## Main statements * `ProbabilityTheory.Kernel.iIndepSets.iIndep`: if π-systems are independent as sets of sets, then the measurable space structures they generate are independent. * `ProbabilityTheory.Kernel.IndepSets.Indep`: variant with two π-systems. -/ open Set MeasureTheory MeasurableSpace open scoped MeasureTheory ENNReal namespace ProbabilityTheory.Kernel variable {α Ω ι : Type*} section Definitions variable {_mα : MeasurableSpace α} /-- A family of sets of sets `π : ι → Set (Set Ω)` is independent with respect to a kernel `κ` and a measure `μ` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ π i_1, ..., f i_n ∈ π i_n`, then `∀ᵐ a ∂μ, κ a (⋂ i in s, f i) = ∏ i ∈ s, κ a (f i)`. It will be used for families of pi_systems. -/ def iIndepSets {_mΩ : MeasurableSpace Ω} (π : ι → Set (Set Ω)) (κ : Kernel α Ω) (μ : Measure α := by volume_tac) : Prop := ∀ (s : Finset ι) {f : ι → Set Ω} (_H : ∀ i, i ∈ s → f i ∈ π i), ∀ᵐ a ∂μ, κ a (⋂ i ∈ s, f i) = ∏ i ∈ s, κ a (f i) /-- Two sets of sets `s₁, s₂` are independent with respect to a kernel `κ` and a measure `μ` if for any sets `t₁ ∈ s₁, t₂ ∈ s₂`, then `∀ᵐ a ∂μ, κ a (t₁ ∩ t₂) = κ a (t₁) * κ a (t₂)` -/ def IndepSets {_mΩ : MeasurableSpace Ω} (s1 s2 : Set (Set Ω)) (κ : Kernel α Ω) (μ : Measure α := by volume_tac) : Prop := ∀ t1 t2 : Set Ω, t1 ∈ s1 → t2 ∈ s2 → (∀ᵐ a ∂μ, κ a (t1 ∩ t2) = κ a t1 * κ a t2) /-- A family of measurable space structures (i.e. of σ-algebras) is independent with respect to a kernel `κ` and a measure `μ` if the family of sets of measurable sets they define is independent. -/ def iIndep (m : ι → MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (κ : Kernel α Ω) (μ : Measure α := by volume_tac) : Prop := iIndepSets (fun x ↦ {s | MeasurableSet[m x] s}) κ μ /-- Two measurable space structures (or σ-algebras) `m₁, m₂` are independent with respect to a kernel `κ` and a measure `μ` if for any sets `t₁ ∈ m₁, t₂ ∈ m₂`, `∀ᵐ a ∂μ, κ a (t₁ ∩ t₂) = κ a (t₁) * κ a (t₂)` -/ def Indep (m₁ m₂ : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (κ : Kernel α Ω) (μ : Measure α := by volume_tac) : Prop := IndepSets {s | MeasurableSet[m₁] s} {s | MeasurableSet[m₂] s} κ μ /-- A family of sets is independent if the family of measurable space structures they generate is independent. For a set `s`, the generated measurable space has measurable sets `∅, s, sᶜ, univ`. -/ def iIndepSet {_mΩ : MeasurableSpace Ω} (s : ι → Set Ω) (κ : Kernel α Ω) (μ : Measure α := by volume_tac) : Prop := iIndep (m := fun i ↦ generateFrom {s i}) κ μ /-- Two sets are independent if the two measurable space structures they generate are independent. For a set `s`, the generated measurable space structure has measurable sets `∅, s, sᶜ, univ`. -/ def IndepSet {_mΩ : MeasurableSpace Ω} (s t : Set Ω) (κ : Kernel α Ω) (μ : Measure α := by volume_tac) : Prop := Indep (generateFrom {s}) (generateFrom {t}) κ μ /-- A family of functions defined on the same space `Ω` and taking values in possibly different spaces, each with a measurable space structure, is independent if the family of measurable space structures they generate on `Ω` is independent. For a function `g` with codomain having measurable space structure `m`, the generated measurable space structure is `MeasurableSpace.comap g m`. -/ def iIndepFun {_mΩ : MeasurableSpace Ω} {β : ι → Type*} [m : ∀ x : ι, MeasurableSpace (β x)] (f : ∀ x : ι, Ω → β x) (κ : Kernel α Ω) (μ : Measure α := by volume_tac) : Prop := iIndep (m := fun x ↦ MeasurableSpace.comap (f x) (m x)) κ μ /-- Two functions are independent if the two measurable space structures they generate are independent. For a function `f` with codomain having measurable space structure `m`, the generated measurable space structure is `MeasurableSpace.comap f m`. -/ def IndepFun {β γ} {_mΩ : MeasurableSpace Ω} [mβ : MeasurableSpace β] [mγ : MeasurableSpace γ] (f : Ω → β) (g : Ω → γ) (κ : Kernel α Ω) (μ : Measure α := by volume_tac) : Prop := Indep (MeasurableSpace.comap f mβ) (MeasurableSpace.comap g mγ) κ μ end Definitions section ByDefinition variable {β : ι → Type*} {mβ : ∀ i, MeasurableSpace (β i)} {_mα : MeasurableSpace α} {m : ι → MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {κ η : Kernel α Ω} {μ : Measure α} {π : ι → Set (Set Ω)} {s : ι → Set Ω} {S : Finset ι} {f : ∀ x : ι, Ω → β x} {s1 s2 : Set (Set Ω)} @[simp] lemma iIndepSets_zero_right : iIndepSets π κ 0 := by simp [iIndepSets] @[simp] lemma indepSets_zero_right : IndepSets s1 s2 κ 0 := by simp [IndepSets] @[simp] lemma indepSets_zero_left : IndepSets s1 s2 (0 : Kernel α Ω) μ := by simp [IndepSets] @[simp] lemma iIndep_zero_right : iIndep m κ 0 := by simp [iIndep] @[simp] lemma indep_zero_right {m₁ m₂ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} : Indep m₁ m₂ κ 0 := by simp [Indep] @[simp] lemma indep_zero_left {m₁ m₂ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} : Indep m₁ m₂ (0 : Kernel α Ω) μ := by simp [Indep] @[simp] lemma iIndepSet_zero_right : iIndepSet s κ 0 := by simp [iIndepSet] @[simp] lemma indepSet_zero_right {s t : Set Ω} : IndepSet s t κ 0 := by simp [IndepSet] @[simp] lemma indepSet_zero_left {s t : Set Ω} : IndepSet s t (0 : Kernel α Ω) μ := by simp [IndepSet] @[simp] lemma iIndepFun_zero_right {β : ι → Type*} {m : ∀ x : ι, MeasurableSpace (β x)} {f : ∀ x : ι, Ω → β x} : iIndepFun f κ 0 := by simp [iIndepFun] @[simp] lemma indepFun_zero_right {β γ} [MeasurableSpace β] [MeasurableSpace γ] {f : Ω → β} {g : Ω → γ} : IndepFun f g κ 0 := by simp [IndepFun] @[simp] lemma indepFun_zero_left {β γ} [MeasurableSpace β] [MeasurableSpace γ] {f : Ω → β} {g : Ω → γ} : IndepFun f g (0 : Kernel α Ω) μ := by simp [IndepFun] lemma iIndepSets_congr (h : κ =ᵐ[μ] η) : iIndepSets π κ μ ↔ iIndepSets π η μ := by peel 3 refine ⟨fun h' ↦ ?_, fun h' ↦ ?_⟩ <;> · filter_upwards [h, h'] with a ha h'a simpa [ha] using h'a alias ⟨iIndepSets.congr, _⟩ := iIndepSets_congr lemma indepSets_congr (h : κ =ᵐ[μ] η) : IndepSets s1 s2 κ μ ↔ IndepSets s1 s2 η μ := by peel 4 refine ⟨fun h' ↦ ?_, fun h' ↦ ?_⟩ <;> · filter_upwards [h, h'] with a ha h'a simpa [ha] using h'a alias ⟨IndepSets.congr, _⟩ := indepSets_congr lemma iIndep_congr (h : κ =ᵐ[μ] η) : iIndep m κ μ ↔ iIndep m η μ := iIndepSets_congr h alias ⟨iIndep.congr, _⟩ := iIndep_congr lemma indep_congr {m₁ m₂ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {κ η : Kernel α Ω} (h : κ =ᵐ[μ] η) : Indep m₁ m₂ κ μ ↔ Indep m₁ m₂ η μ := indepSets_congr h alias ⟨Indep.congr, _⟩ := indep_congr lemma iIndepSet_congr (h : κ =ᵐ[μ] η) : iIndepSet s κ μ ↔ iIndepSet s η μ := iIndep_congr h alias ⟨iIndepSet.congr, _⟩ := iIndepSet_congr lemma indepSet_congr {s t : Set Ω} (h : κ =ᵐ[μ] η) : IndepSet s t κ μ ↔ IndepSet s t η μ := indep_congr h alias ⟨indepSet.congr, _⟩ := indepSet_congr lemma iIndepFun_congr {β : ι → Type*} {m : ∀ x : ι, MeasurableSpace (β x)} {f : ∀ x : ι, Ω → β x} (h : κ =ᵐ[μ] η) : iIndepFun f κ μ ↔ iIndepFun f η μ := iIndep_congr h alias ⟨iIndepFun.congr, _⟩ := iIndepFun_congr lemma indepFun_congr {β γ} [MeasurableSpace β] [MeasurableSpace γ] {f : Ω → β} {g : Ω → γ} (h : κ =ᵐ[μ] η) : IndepFun f g κ μ ↔ IndepFun f g η μ := indep_congr h alias ⟨IndepFun.congr, _⟩ := indepFun_congr lemma iIndepSets.meas_biInter (h : iIndepSets π κ μ) (s : Finset ι) {f : ι → Set Ω} (hf : ∀ i, i ∈ s → f i ∈ π i) : ∀ᵐ a ∂μ, κ a (⋂ i ∈ s, f i) = ∏ i ∈ s, κ a (f i) := h s hf lemma iIndepSets.ae_isProbabilityMeasure (h : iIndepSets π κ μ) : ∀ᵐ a ∂μ, IsProbabilityMeasure (κ a) := by filter_upwards [h.meas_biInter ∅ (f := fun _ ↦ Set.univ) (by simp)] with a ha exact ⟨by simpa using ha⟩ lemma iIndepSets.meas_iInter [Fintype ι] (h : iIndepSets π κ μ) (hs : ∀ i, s i ∈ π i) : ∀ᵐ a ∂μ, κ a (⋂ i, s i) = ∏ i, κ a (s i) := by filter_upwards [h.meas_biInter Finset.univ (fun _i _ ↦ hs _)] with a ha using by simp [← ha] lemma iIndep.iIndepSets' (hμ : iIndep m κ μ) : iIndepSets (fun x ↦ {s | MeasurableSet[m x] s}) κ μ := hμ lemma iIndep.ae_isProbabilityMeasure (h : iIndep m κ μ) : ∀ᵐ a ∂μ, IsProbabilityMeasure (κ a) := h.iIndepSets'.ae_isProbabilityMeasure lemma iIndep.meas_biInter (hμ : iIndep m κ μ) (hs : ∀ i, i ∈ S → MeasurableSet[m i] (s i)) : ∀ᵐ a ∂μ, κ a (⋂ i ∈ S, s i) = ∏ i ∈ S, κ a (s i) := hμ _ hs lemma iIndep.meas_iInter [Fintype ι] (h : iIndep m κ μ) (hs : ∀ i, MeasurableSet[m i] (s i)) : ∀ᵐ a ∂μ, κ a (⋂ i, s i) = ∏ i, κ a (s i) := by filter_upwards [h.meas_biInter (fun i (_ : i ∈ Finset.univ) ↦ hs _)] with a ha simp [← ha] @[nontriviality, simp] lemma iIndepSets.of_subsingleton [Subsingleton ι] {m : ι → Set (Set Ω)} {κ : Kernel α Ω} [IsMarkovKernel κ] : iIndepSets m κ μ := by rintro s f hf obtain rfl | ⟨i, rfl⟩ : s = ∅ ∨ ∃ i, s = {i} := by simpa using (subsingleton_of_subsingleton (s := s.toSet)).eq_empty_or_singleton all_goals simp @[nontriviality, simp] lemma iIndep.of_subsingleton [Subsingleton ι] {m : ι → MeasurableSpace Ω} {κ : Kernel α Ω} [IsMarkovKernel κ] : iIndep m κ μ := by simp [iIndep] @[nontriviality, simp] lemma iIndepFun.of_subsingleton [Subsingleton ι] {β : ι → Type*} {m : ∀ i, MeasurableSpace (β i)} {f : ∀ i, Ω → β i} [IsMarkovKernel κ] : iIndepFun f κ μ := by simp [iIndepFun] protected lemma iIndepFun.iIndep (hf : iIndepFun f κ μ) : iIndep (fun x ↦ (mβ x).comap (f x)) κ μ := hf lemma iIndepFun.ae_isProbabilityMeasure (h : iIndepFun f κ μ) : ∀ᵐ a ∂μ, IsProbabilityMeasure (κ a) := h.iIndep.ae_isProbabilityMeasure lemma iIndepFun.meas_biInter (hf : iIndepFun f κ μ) (hs : ∀ i, i ∈ S → MeasurableSet[(mβ i).comap (f i)] (s i)) : ∀ᵐ a ∂μ, κ a (⋂ i ∈ S, s i) = ∏ i ∈ S, κ a (s i) := hf.iIndep.meas_biInter hs lemma iIndepFun.meas_iInter [Fintype ι] (hf : iIndepFun f κ μ) (hs : ∀ i, MeasurableSet[(mβ i).comap (f i)] (s i)) : ∀ᵐ a ∂μ, κ a (⋂ i, s i) = ∏ i, κ a (s i) := hf.iIndep.meas_iInter hs lemma IndepFun.meas_inter {β γ : Type*} [mβ : MeasurableSpace β] [mγ : MeasurableSpace γ] {f : Ω → β} {g : Ω → γ} (hfg : IndepFun f g κ μ) {s t : Set Ω} (hs : MeasurableSet[mβ.comap f] s) (ht : MeasurableSet[mγ.comap g] t) : ∀ᵐ a ∂μ, κ a (s ∩ t) = κ a s * κ a t := hfg _ _ hs ht end ByDefinition section Indep variable {_mα : MeasurableSpace α} @[symm] theorem IndepSets.symm {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} {s₁ s₂ : Set (Set Ω)} (h : IndepSets s₁ s₂ κ μ) : IndepSets s₂ s₁ κ μ := by intros t1 t2 ht1 ht2 filter_upwards [h t2 t1 ht2 ht1] with a ha rwa [Set.inter_comm, mul_comm] @[symm] theorem Indep.symm {m₁ m₂ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (h : Indep m₁ m₂ κ μ) : Indep m₂ m₁ κ μ := IndepSets.symm h theorem indep_bot_right (m' : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} [IsZeroOrMarkovKernel κ] : Indep m' ⊥ κ μ := by intros s t _ ht rw [Set.mem_setOf_eq, MeasurableSpace.measurableSet_bot_iff] at ht rcases eq_zero_or_isMarkovKernel κ with rfl| h · simp refine Filter.Eventually.of_forall (fun a ↦ ?_) rcases ht with ht | ht · rw [ht, Set.inter_empty, measure_empty, mul_zero] · rw [ht, Set.inter_univ, measure_univ, mul_one] theorem indep_bot_left (m' : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} [IsZeroOrMarkovKernel κ] : Indep ⊥ m' κ μ := (indep_bot_right m').symm theorem indepSet_empty_right {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} [IsZeroOrMarkovKernel κ] (s : Set Ω) : IndepSet s ∅ κ μ := by simp only [IndepSet, generateFrom_singleton_empty] exact indep_bot_right _ theorem indepSet_empty_left {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} [IsZeroOrMarkovKernel κ] (s : Set Ω) : IndepSet ∅ s κ μ := (indepSet_empty_right s).symm theorem indepSets_of_indepSets_of_le_left {s₁ s₂ s₃ : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (h_indep : IndepSets s₁ s₂ κ μ) (h31 : s₃ ⊆ s₁) : IndepSets s₃ s₂ κ μ := fun t1 t2 ht1 ht2 => h_indep t1 t2 (Set.mem_of_subset_of_mem h31 ht1) ht2 theorem indepSets_of_indepSets_of_le_right {s₁ s₂ s₃ : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (h_indep : IndepSets s₁ s₂ κ μ) (h32 : s₃ ⊆ s₂) : IndepSets s₁ s₃ κ μ := fun t1 t2 ht1 ht2 => h_indep t1 t2 ht1 (Set.mem_of_subset_of_mem h32 ht2) theorem indep_of_indep_of_le_left {m₁ m₂ m₃ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (h_indep : Indep m₁ m₂ κ μ) (h31 : m₃ ≤ m₁) : Indep m₃ m₂ κ μ := fun t1 t2 ht1 ht2 => h_indep t1 t2 (h31 _ ht1) ht2 theorem indep_of_indep_of_le_right {m₁ m₂ m₃ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (h_indep : Indep m₁ m₂ κ μ) (h32 : m₃ ≤ m₂) : Indep m₁ m₃ κ μ := fun t1 t2 ht1 ht2 => h_indep t1 t2 ht1 (h32 _ ht2) theorem IndepSets.union {s₁ s₂ s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (h₁ : IndepSets s₁ s' κ μ) (h₂ : IndepSets s₂ s' κ μ) : IndepSets (s₁ ∪ s₂) s' κ μ := by intro t1 t2 ht1 ht2 rcases (Set.mem_union _ _ _).mp ht1 with ht1₁ | ht1₂ · exact h₁ t1 t2 ht1₁ ht2 · exact h₂ t1 t2 ht1₂ ht2 @[simp] theorem IndepSets.union_iff {s₁ s₂ s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} : IndepSets (s₁ ∪ s₂) s' κ μ ↔ IndepSets s₁ s' κ μ ∧ IndepSets s₂ s' κ μ := ⟨fun h => ⟨indepSets_of_indepSets_of_le_left h Set.subset_union_left, indepSets_of_indepSets_of_le_left h Set.subset_union_right⟩, fun h => IndepSets.union h.left h.right⟩ theorem IndepSets.iUnion {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (hyp : ∀ n, IndepSets (s n) s' κ μ) : IndepSets (⋃ n, s n) s' κ μ := by intro t1 t2 ht1 ht2 rw [Set.mem_iUnion] at ht1 obtain ⟨n, ht1⟩ := ht1 exact hyp n t1 t2 ht1 ht2 theorem IndepSets.bUnion {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} {u : Set ι} (hyp : ∀ n ∈ u, IndepSets (s n) s' κ μ) : IndepSets (⋃ n ∈ u, s n) s' κ μ := by intro t1 t2 ht1 ht2 simp_rw [Set.mem_iUnion] at ht1 rcases ht1 with ⟨n, hpn, ht1⟩ exact hyp n hpn t1 t2 ht1 ht2 theorem IndepSets.inter {s₁ s' : Set (Set Ω)} (s₂ : Set (Set Ω)) {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (h₁ : IndepSets s₁ s' κ μ) : IndepSets (s₁ ∩ s₂) s' κ μ := fun t1 t2 ht1 ht2 => h₁ t1 t2 ((Set.mem_inter_iff _ _ _).mp ht1).left ht2 theorem IndepSets.iInter {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (h : ∃ n, IndepSets (s n) s' κ μ) : IndepSets (⋂ n, s n) s' κ μ := by intro t1 t2 ht1 ht2; obtain ⟨n, h⟩ := h; exact h t1 t2 (Set.mem_iInter.mp ht1 n) ht2 theorem IndepSets.bInter {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} {u : Set ι} (h : ∃ n ∈ u, IndepSets (s n) s' κ μ) : IndepSets (⋂ n ∈ u, s n) s' κ μ := by intro t1 t2 ht1 ht2 rcases h with ⟨n, hn, h⟩ exact h t1 t2 (Set.biInter_subset_of_mem hn ht1) ht2 theorem iIndep_comap_mem_iff {f : ι → Set Ω} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} : iIndep (fun i => MeasurableSpace.comap (· ∈ f i) ⊤) κ μ ↔ iIndepSet f κ μ := by simp_rw [← generateFrom_singleton, iIndepSet] theorem iIndepSets_singleton_iff {s : ι → Set Ω} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} : iIndepSets (fun i ↦ {s i}) κ μ ↔ ∀ S : Finset ι, ∀ᵐ a ∂μ, κ a (⋂ i ∈ S, s i) = ∏ i ∈ S, κ a (s i) := by refine ⟨fun h S ↦ h S (fun i _ ↦ rfl), fun h S f hf ↦ ?_⟩ filter_upwards [h S] with a ha have : ∀ i ∈ S, κ a (f i) = κ a (s i) := fun i hi ↦ by rw [hf i hi] rwa [Finset.prod_congr rfl this, Set.iInter₂_congr hf] theorem indepSets_singleton_iff {s t : Set Ω} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} : IndepSets {s} {t} κ μ ↔ ∀ᵐ a ∂μ, κ a (s ∩ t) = κ a s * κ a t := ⟨fun h ↦ h s t rfl rfl, fun h s1 t1 hs1 ht1 ↦ by rwa [Set.mem_singleton_iff.mp hs1, Set.mem_singleton_iff.mp ht1]⟩ end Indep /-! ### Deducing `Indep` from `iIndep` -/ section FromiIndepToIndep variable {_mα : MeasurableSpace α} theorem iIndepSets.indepSets {s : ι → Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (h_indep : iIndepSets s κ μ) {i j : ι} (hij : i ≠ j) : IndepSets (s i) (s j) κ μ := by classical intro t₁ t₂ ht₁ ht₂ have hf_m : ∀ x : ι, x ∈ ({i, j} : Finset ι) → ite (x = i) t₁ t₂ ∈ s x := by intro x hx rcases Finset.mem_insert.mp hx with hx | hx · simp [hx, ht₁] · simp [Finset.mem_singleton.mp hx, hij.symm, ht₂] have h1 : t₁ = ite (i = i) t₁ t₂ := by simp only [if_true, eq_self_iff_true] have h2 : t₂ = ite (j = i) t₁ t₂ := by simp only [hij.symm, if_false] have h_inter : ⋂ (t : ι) (_ : t ∈ ({i, j} : Finset ι)), ite (t = i) t₁ t₂ = ite (i = i) t₁ t₂ ∩ ite (j = i) t₁ t₂ := by simp only [Finset.set_biInter_singleton, Finset.set_biInter_insert] filter_upwards [h_indep {i, j} hf_m] with a h_indep' have h_prod : (∏ t ∈ ({i, j} : Finset ι), κ a (ite (t = i) t₁ t₂)) = κ a (ite (i = i) t₁ t₂) * κ a (ite (j = i) t₁ t₂) := by simp only [hij, Finset.prod_singleton, Finset.prod_insert, not_false_iff, Finset.mem_singleton] rw [h1] nth_rw 2 [h2] nth_rw 4 [h2] rw [← h_inter, ← h_prod, h_indep'] theorem iIndep.indep {m : ι → MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (h_indep : iIndep m κ μ) {i j : ι} (hij : i ≠ j) : Indep (m i) (m j) κ μ := iIndepSets.indepSets h_indep hij theorem iIndepFun.indepFun {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} {β : ι → Type*} {m : ∀ x, MeasurableSpace (β x)} {f : ∀ i, Ω → β i} (hf_Indep : iIndepFun f κ μ) {i j : ι} (hij : i ≠ j) : IndepFun (f i) (f j) κ μ := hf_Indep.indep hij end FromiIndepToIndep /-! ## π-system lemma Independence of measurable spaces is equivalent to independence of generating π-systems. -/ section FromMeasurableSpacesToSetsOfSets /-! ### Independence of measurable space structures implies independence of generating π-systems -/ variable {_mα : MeasurableSpace α} theorem iIndep.iIndepSets {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} {m : ι → MeasurableSpace Ω} {s : ι → Set (Set Ω)} (hms : ∀ n, m n = generateFrom (s n)) (h_indep : iIndep m κ μ) : iIndepSets s κ μ := fun S f hfs => h_indep S fun x hxS => ((hms x).symm ▸ measurableSet_generateFrom (hfs x hxS) : MeasurableSet[m x] (f x)) theorem Indep.indepSets {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} {s1 s2 : Set (Set Ω)} (h_indep : Indep (generateFrom s1) (generateFrom s2) κ μ) : IndepSets s1 s2 κ μ := fun t1 t2 ht1 ht2 => h_indep t1 t2 (measurableSet_generateFrom ht1) (measurableSet_generateFrom ht2) end FromMeasurableSpacesToSetsOfSets section FromPiSystemsToMeasurableSpaces /-! ### Independence of generating π-systems implies independence of measurable space structures -/ variable {_mα : MeasurableSpace α} theorem IndepSets.indep_aux {m₂ m : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} [IsZeroOrMarkovKernel κ] {p1 p2 : Set (Set Ω)} (h2 : m₂ ≤ m) (hp2 : IsPiSystem p2) (hpm2 : m₂ = generateFrom p2) (hyp : IndepSets p1 p2 κ μ) {t1 t2 : Set Ω} (ht1 : t1 ∈ p1) (ht1m : MeasurableSet[m] t1) (ht2m : MeasurableSet[m₂] t2) : ∀ᵐ a ∂μ, κ a (t1 ∩ t2) = κ a t1 * κ a t2 := by rcases eq_zero_or_isMarkovKernel κ with rfl | h · simp induction t2, ht2m using induction_on_inter hpm2 hp2 with | empty => simp | basic u hu => exact hyp t1 u ht1 hu | compl u hu ihu => filter_upwards [ihu] with a ha rw [← Set.diff_eq, ← Set.diff_self_inter, measure_diff inter_subset_left (ht1m.inter (h2 _ hu)).nullMeasurableSet (measure_ne_top _ _), ha, measure_compl (h2 _ hu) (measure_ne_top _ _), measure_univ, ENNReal.mul_sub, mul_one] exact fun _ _ ↦ measure_ne_top _ _ | iUnion f hfd hfm ihf => rw [← ae_all_iff] at ihf filter_upwards [ihf] with a ha rw [inter_iUnion, measure_iUnion, measure_iUnion hfd fun i ↦ h2 _ (hfm i)] · simp only [ENNReal.tsum_mul_left, ha] · exact hfd.mono fun i j h ↦ (h.inter_left' _).inter_right' _ · exact fun i ↦ .inter ht1m (h2 _ <| hfm i) /-- The measurable space structures generated by independent pi-systems are independent. -/ theorem IndepSets.indep {m1 m2 m : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} [IsZeroOrMarkovKernel κ] {p1 p2 : Set (Set Ω)} (h1 : m1 ≤ m) (h2 : m2 ≤ m) (hp1 : IsPiSystem p1) (hp2 : IsPiSystem p2) (hpm1 : m1 = generateFrom p1) (hpm2 : m2 = generateFrom p2) (hyp : IndepSets p1 p2 κ μ) : Indep m1 m2 κ μ := by rcases eq_zero_or_isMarkovKernel κ with rfl | h · simp intros t1 t2 ht1 ht2 induction t1, ht1 using induction_on_inter hpm1 hp1 with | empty => simp only [Set.empty_inter, measure_empty, zero_mul, eq_self_iff_true, Filter.eventually_true] | basic t ht => refine IndepSets.indep_aux h2 hp2 hpm2 hyp ht (h1 _ ?_) ht2 rw [hpm1] exact measurableSet_generateFrom ht | compl t ht iht => filter_upwards [iht] with a ha have : tᶜ ∩ t2 = t2 \ (t ∩ t2) := by rw [Set.inter_comm t, Set.diff_self_inter, Set.diff_eq_compl_inter] rw [this, Set.inter_comm t t2, measure_diff Set.inter_subset_left ((h2 _ ht2).inter (h1 _ ht)).nullMeasurableSet (measure_ne_top (κ a) _), Set.inter_comm, ha, measure_compl (h1 _ ht) (measure_ne_top (κ a) t), measure_univ, mul_comm (1 - κ a t), ENNReal.mul_sub (fun _ _ ↦ measure_ne_top (κ a) _), mul_one, mul_comm] | iUnion f hf_disj hf_meas h => rw [← ae_all_iff] at h filter_upwards [h] with a ha rw [Set.inter_comm, Set.inter_iUnion, measure_iUnion] · rw [measure_iUnion hf_disj (fun i ↦ h1 _ (hf_meas i))] rw [← ENNReal.tsum_mul_right] congr 1 with i rw [Set.inter_comm t2, ha i] · intros i j hij rw [Function.onFun, Set.inter_comm t2, Set.inter_comm t2] exact Disjoint.inter_left _ (Disjoint.inter_right _ (hf_disj hij)) · exact fun i ↦ (h2 _ ht2).inter (h1 _ (hf_meas i)) theorem IndepSets.indep' {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} [IsZeroOrMarkovKernel κ] {p1 p2 : Set (Set Ω)} (hp1m : ∀ s ∈ p1, MeasurableSet s) (hp2m : ∀ s ∈ p2, MeasurableSet s) (hp1 : IsPiSystem p1) (hp2 : IsPiSystem p2) (hyp : IndepSets p1 p2 κ μ) : Indep (generateFrom p1) (generateFrom p2) κ μ := hyp.indep (generateFrom_le hp1m) (generateFrom_le hp2m) hp1 hp2 rfl rfl variable {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} theorem indepSets_piiUnionInter_of_disjoint {s : ι → Set (Set Ω)} {S T : Set ι} (h_indep : iIndepSets s κ μ) (hST : Disjoint S T) : IndepSets (piiUnionInter s S) (piiUnionInter s T) κ μ := by rintro t1 t2 ⟨p1, hp1, f1, ht1_m, ht1_eq⟩ ⟨p2, hp2, f2, ht2_m, ht2_eq⟩ classical let g i := ite (i ∈ p1) (f1 i) Set.univ ∩ ite (i ∈ p2) (f2 i) Set.univ have h_P_inter : ∀ᵐ a ∂μ, κ a (t1 ∩ t2) = ∏ n ∈ p1 ∪ p2, κ a (g n) := by have hgm : ∀ i ∈ p1 ∪ p2, g i ∈ s i := by intro i hi_mem_union rw [Finset.mem_union] at hi_mem_union rcases hi_mem_union with hi1 | hi2 · have hi2 : i ∉ p2 := fun hip2 => Set.disjoint_left.mp hST (hp1 hi1) (hp2 hip2) simp_rw [g, if_pos hi1, if_neg hi2, Set.inter_univ] exact ht1_m i hi1 · have hi1 : i ∉ p1 := fun hip1 => Set.disjoint_right.mp hST (hp2 hi2) (hp1 hip1) simp_rw [g, if_neg hi1, if_pos hi2, Set.univ_inter] exact ht2_m i hi2 have h_p1_inter_p2 : ((⋂ x ∈ p1, f1 x) ∩ ⋂ x ∈ p2, f2 x) = ⋂ i ∈ p1 ∪ p2, ite (i ∈ p1) (f1 i) Set.univ ∩ ite (i ∈ p2) (f2 i) Set.univ := by ext1 x simp only [Set.mem_ite_univ_right, Set.mem_inter_iff, Set.mem_iInter, Finset.mem_union] exact ⟨fun h i _ => ⟨h.1 i, h.2 i⟩, fun h => ⟨fun i hi => (h i (Or.inl hi)).1 hi, fun i hi => (h i (Or.inr hi)).2 hi⟩⟩ filter_upwards [h_indep _ hgm] with a ha rw [ht1_eq, ht2_eq, h_p1_inter_p2, ← ha] filter_upwards [h_P_inter, h_indep p1 ht1_m, h_indep p2 ht2_m, h_indep.ae_isProbabilityMeasure] with a h_P_inter ha1 ha2 h' have h_μg : ∀ n, κ a (g n) = (ite (n ∈ p1) (κ a (f1 n)) 1) * (ite (n ∈ p2) (κ a (f2 n)) 1) := by intro n dsimp only [g] split_ifs with h1 h2 · exact absurd rfl (Set.disjoint_iff_forall_ne.mp hST (hp1 h1) (hp2 h2)) all_goals simp only [measure_univ, one_mul, mul_one, Set.inter_univ, Set.univ_inter] simp_rw [h_P_inter, h_μg, Finset.prod_mul_distrib, Finset.prod_ite_mem (p1 ∪ p2) p1 (fun x ↦ κ a (f1 x)), Finset.union_inter_cancel_left, Finset.prod_ite_mem (p1 ∪ p2) p2 (fun x => κ a (f2 x)), Finset.union_inter_cancel_right, ht1_eq, ← ha1, ht2_eq, ← ha2] theorem iIndepSet.indep_generateFrom_of_disjoint {s : ι → Set Ω} (hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s κ μ) (S T : Set ι) (hST : Disjoint S T) : Indep (generateFrom { t | ∃ n ∈ S, s n = t }) (generateFrom { t | ∃ k ∈ T, s k = t }) κ μ := by classical rcases eq_or_ne μ 0 with rfl | hμ · simp obtain ⟨η, η_eq, hη⟩ : ∃ (η : Kernel α Ω), κ =ᵐ[μ] η ∧ IsMarkovKernel η := exists_ae_eq_isMarkovKernel hs.ae_isProbabilityMeasure hμ apply Indep.congr (Filter.EventuallyEq.symm η_eq) rw [← generateFrom_piiUnionInter_singleton_left, ← generateFrom_piiUnionInter_singleton_left] refine IndepSets.indep' (fun t ht => generateFrom_piiUnionInter_le _ ?_ _ _ (measurableSet_generateFrom ht)) (fun t ht => generateFrom_piiUnionInter_le _ ?_ _ _ (measurableSet_generateFrom ht)) ?_ ?_ ?_ · exact fun k => generateFrom_le fun t ht => (Set.mem_singleton_iff.1 ht).symm ▸ hsm k · exact fun k => generateFrom_le fun t ht => (Set.mem_singleton_iff.1 ht).symm ▸ hsm k · exact isPiSystem_piiUnionInter _ (fun k => IsPiSystem.singleton _) _ · exact isPiSystem_piiUnionInter _ (fun k => IsPiSystem.singleton _) _ · exact indepSets_piiUnionInter_of_disjoint (iIndep.iIndepSets (fun n => rfl) (hs.congr η_eq)) hST theorem indep_iSup_of_disjoint {m : ι → MeasurableSpace Ω} (h_le : ∀ i, m i ≤ _mΩ) (h_indep : iIndep m κ μ) {S T : Set ι} (hST : Disjoint S T) : Indep (⨆ i ∈ S, m i) (⨆ i ∈ T, m i) κ μ := by classical rcases eq_or_ne μ 0 with rfl | hμ · simp obtain ⟨η, η_eq, hη⟩ : ∃ (η : Kernel α Ω), κ =ᵐ[μ] η ∧ IsMarkovKernel η := exists_ae_eq_isMarkovKernel h_indep.ae_isProbabilityMeasure hμ apply Indep.congr (Filter.EventuallyEq.symm η_eq) refine IndepSets.indep (iSup₂_le fun i _ => h_le i) (iSup₂_le fun i _ => h_le i) ?_ ?_ (generateFrom_piiUnionInter_measurableSet m S).symm (generateFrom_piiUnionInter_measurableSet m T).symm ?_ · exact isPiSystem_piiUnionInter _ (fun n => @isPiSystem_measurableSet Ω (m n)) _ · exact isPiSystem_piiUnionInter _ (fun n => @isPiSystem_measurableSet Ω (m n)) _ · exact indepSets_piiUnionInter_of_disjoint (h_indep.congr η_eq) hST theorem indep_iSup_of_directed_le {Ω} {m : ι → MeasurableSpace Ω} {m' m0 : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} [IsZeroOrMarkovKernel κ] (h_indep : ∀ i, Indep (m i) m' κ μ) (h_le : ∀ i, m i ≤ m0) (h_le' : m' ≤ m0) (hm : Directed (· ≤ ·) m) : Indep (⨆ i, m i) m' κ μ := by let p : ι → Set (Set Ω) := fun n => { t | MeasurableSet[m n] t } have hp : ∀ n, IsPiSystem (p n) := fun n => @isPiSystem_measurableSet Ω (m n) have h_gen_n : ∀ n, m n = generateFrom (p n) := fun n => (@generateFrom_measurableSet Ω (m n)).symm have hp_supr_pi : IsPiSystem (⋃ n, p n) := isPiSystem_iUnion_of_directed_le p hp hm let p' := { t : Set Ω | MeasurableSet[m'] t } have hp'_pi : IsPiSystem p' := @isPiSystem_measurableSet Ω m' have h_gen' : m' = generateFrom p' := (@generateFrom_measurableSet Ω m').symm -- the π-systems defined are independent have h_pi_system_indep : IndepSets (⋃ n, p n) p' κ μ := by refine IndepSets.iUnion ?_ conv at h_indep => intro i rw [h_gen_n i, h_gen'] exact fun n => (h_indep n).indepSets -- now go from π-systems to σ-algebras refine IndepSets.indep (iSup_le h_le) h_le' hp_supr_pi hp'_pi ?_ h_gen' h_pi_system_indep exact (generateFrom_iUnion_measurableSet _).symm theorem iIndepSet.indep_generateFrom_lt [Preorder ι] {s : ι → Set Ω} (hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s κ μ) (i : ι) : Indep (generateFrom {s i}) (generateFrom { t | ∃ j < i, s j = t }) κ μ := by convert iIndepSet.indep_generateFrom_of_disjoint hsm hs {i} { j | j < i } (Set.disjoint_singleton_left.mpr (lt_irrefl _)) using 1 simp only [Set.mem_singleton_iff, exists_prop, exists_eq_left, Set.setOf_eq_eq_singleton'] theorem iIndepSet.indep_generateFrom_le [Preorder ι] {s : ι → Set Ω} (hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s κ μ) (i : ι) {k : ι} (hk : i < k) : Indep (generateFrom {s k}) (generateFrom { t | ∃ j ≤ i, s j = t }) κ μ := by convert iIndepSet.indep_generateFrom_of_disjoint hsm hs {k} { j | j ≤ i } (Set.disjoint_singleton_left.mpr hk.not_le) using 1 simp only [Set.mem_singleton_iff, exists_prop, exists_eq_left, Set.setOf_eq_eq_singleton'] theorem iIndepSet.indep_generateFrom_le_nat {s : ℕ → Set Ω} (hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s κ μ) (n : ℕ) : Indep (generateFrom {s (n + 1)}) (generateFrom { t | ∃ k ≤ n, s k = t }) κ μ := iIndepSet.indep_generateFrom_le hsm hs _ n.lt_succ_self theorem indep_iSup_of_monotone [SemilatticeSup ι] {Ω} {m : ι → MeasurableSpace Ω} {m' m0 : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} [IsZeroOrMarkovKernel κ] (h_indep : ∀ i, Indep (m i) m' κ μ) (h_le : ∀ i, m i ≤ m0) (h_le' : m' ≤ m0) (hm : Monotone m) : Indep (⨆ i, m i) m' κ μ := indep_iSup_of_directed_le h_indep h_le h_le' (Monotone.directed_le hm) theorem indep_iSup_of_antitone [SemilatticeInf ι] {Ω} {m : ι → MeasurableSpace Ω} {m' m0 : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} [IsZeroOrMarkovKernel κ] (h_indep : ∀ i, Indep (m i) m' κ μ) (h_le : ∀ i, m i ≤ m0) (h_le' : m' ≤ m0) (hm : Antitone m) : Indep (⨆ i, m i) m' κ μ := indep_iSup_of_directed_le h_indep h_le h_le' hm.directed_le theorem iIndepSets.piiUnionInter_of_not_mem {π : ι → Set (Set Ω)} {a : ι} {S : Finset ι} (hp_ind : iIndepSets π κ μ) (haS : a ∉ S) : IndepSets (piiUnionInter π S) (π a) κ μ := by rintro t1 t2 ⟨s, hs_mem, ft1, hft1_mem, ht1_eq⟩ ht2_mem_pia rw [Finset.coe_subset] at hs_mem classical let f := fun n => ite (n = a) t2 (ite (n ∈ s) (ft1 n) Set.univ) have h_f_mem : ∀ n ∈ insert a s, f n ∈ π n := by intro n hn_mem_insert dsimp only [f] rcases Finset.mem_insert.mp hn_mem_insert with hn_mem | hn_mem · simp [hn_mem, ht2_mem_pia] · have hn_ne_a : n ≠ a := by rintro rfl; exact haS (hs_mem hn_mem) simp [hn_ne_a, hn_mem, hft1_mem n hn_mem] have h_f_mem_pi : ∀ n ∈ s, f n ∈ π n := fun x hxS => h_f_mem x (by simp [hxS]) have h_t1 : t1 = ⋂ n ∈ s, f n := by suffices h_forall : ∀ n ∈ s, f n = ft1 n by rw [ht1_eq] ext x simp_rw [Set.mem_iInter] conv => lhs; intro i hns; rw [← h_forall i hns] intro n hnS have hn_ne_a : n ≠ a := by rintro rfl; exact haS (hs_mem hnS) simp_rw [f, if_pos hnS, if_neg hn_ne_a] have h_μ_t1 : ∀ᵐ a' ∂μ, κ a' t1 = ∏ n ∈ s, κ a' (f n) := by filter_upwards [hp_ind s h_f_mem_pi] with a' ha' rw [h_t1, ← ha'] have h_t2 : t2 = f a := by simp [f] have h_μ_inter : ∀ᵐ a' ∂μ, κ a' (t1 ∩ t2) = ∏ n ∈ insert a s, κ a' (f n) := by have h_t1_inter_t2 : t1 ∩ t2 = ⋂ n ∈ insert a s, f n := by rw [h_t1, h_t2, Finset.set_biInter_insert, Set.inter_comm] filter_upwards [hp_ind (insert a s) h_f_mem] with a' ha' rw [h_t1_inter_t2, ← ha'] have has : a ∉ s := fun has_mem => haS (hs_mem has_mem) filter_upwards [h_μ_t1, h_μ_inter] with a' ha1 ha2 rw [ha2, Finset.prod_insert has, h_t2, mul_comm, ha1] /-- The measurable space structures generated by independent pi-systems are independent. -/ theorem iIndepSets.iIndep (m : ι → MeasurableSpace Ω) (h_le : ∀ i, m i ≤ _mΩ) (π : ι → Set (Set Ω)) (h_pi : ∀ n, IsPiSystem (π n)) (h_generate : ∀ i, m i = generateFrom (π i)) (h_ind : iIndepSets π κ μ) : iIndep m κ μ := by classical rcases eq_or_ne μ 0 with rfl | hμ · simp obtain ⟨η, η_eq, hη⟩ : ∃ (η : Kernel α Ω), κ =ᵐ[μ] η ∧ IsMarkovKernel η := exists_ae_eq_isMarkovKernel h_ind.ae_isProbabilityMeasure hμ apply iIndep.congr (Filter.EventuallyEq.symm η_eq) intro s f refine Finset.induction ?_ ?_ s · simp only [Finset.not_mem_empty, Set.mem_setOf_eq, IsEmpty.forall_iff, implies_true, Set.iInter_of_empty, Set.iInter_univ, measure_univ, Finset.prod_empty, Filter.eventually_true, forall_true_left] · intro a S ha_notin_S h_rec hf_m have hf_m_S : ∀ x ∈ S, MeasurableSet[m x] (f x) := fun x hx => hf_m x (by simp [hx]) let p := piiUnionInter π S set m_p := generateFrom p with hS_eq_generate have h_indep : Indep m_p (m a) η μ := by have hp : IsPiSystem p := isPiSystem_piiUnionInter π h_pi S have h_le' : ∀ i, generateFrom (π i) ≤ _mΩ := fun i ↦ (h_generate i).symm.trans_le (h_le i) have hm_p : m_p ≤ _mΩ := generateFrom_piiUnionInter_le π h_le' S exact IndepSets.indep hm_p (h_le a) hp (h_pi a) hS_eq_generate (h_generate a) (iIndepSets.piiUnionInter_of_not_mem (h_ind.congr η_eq) ha_notin_S) have h := h_indep.symm (f a) (⋂ n ∈ S, f n) (hf_m a (Finset.mem_insert_self a S)) ?_ · filter_upwards [h_rec hf_m_S, h] with a' ha' h' rwa [Finset.set_biInter_insert, Finset.prod_insert ha_notin_S, ← ha'] · have h_le_p : ∀ i ∈ S, m i ≤ m_p := by intros n hn rw [hS_eq_generate, h_generate n] exact le_generateFrom_piiUnionInter (S : Set ι) hn have h_S_f : ∀ i ∈ S, MeasurableSet[m_p] (f i) := fun i hi ↦ (h_le_p i hi) (f i) (hf_m_S i hi) exact S.measurableSet_biInter h_S_f end FromPiSystemsToMeasurableSpaces section IndepSet /-! ### Independence of measurable sets We prove the following equivalences on `IndepSet`, for measurable sets `s, t`. * `IndepSet s t κ μ ↔ ∀ᵐ a ∂μ, κ a (s ∩ t) = κ a s * κ a t`, * `IndepSet s t κ μ ↔ IndepSets {s} {t} κ μ`. -/ variable {_mα : MeasurableSpace α} theorem iIndepSet_iff_iIndepSets_singleton {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} {f : ι → Set Ω} (hf : ∀ i, MeasurableSet (f i)) : iIndepSet f κ μ ↔ iIndepSets (fun i ↦ {f i}) κ μ := ⟨iIndep.iIndepSets fun _ ↦ rfl, iIndepSets.iIndep _ (fun i ↦ generateFrom_le <| by rintro t (rfl : t = _); exact hf _) _ (fun _ ↦ IsPiSystem.singleton _) fun _ ↦ rfl⟩ theorem iIndepSet.meas_biInter {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} {f : ι → Set Ω} (h : iIndepSet f κ μ) (s : Finset ι) :
∀ᵐ a ∂μ, κ a (⋂ i ∈ s, f i) = ∏ i ∈ s, κ a (f i) := iIndep.iIndepSets (fun _ ↦ rfl) h _ (by simp) theorem iIndepSet_iff_meas_biInter {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} {f : ι → Set Ω} (hf : ∀ i, MeasurableSet (f i)) : iIndepSet f κ μ ↔ ∀ s, ∀ᵐ a ∂μ, κ a (⋂ i ∈ s, f i) = ∏ i ∈ s, κ a (f i) := (iIndepSet_iff_iIndepSets_singleton hf).trans iIndepSets_singleton_iff theorem iIndepSets.iIndepSet_of_mem {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω}
Mathlib/Probability/Independence/Kernel.lean
793
801
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.CharP.Algebra import Mathlib.Data.Multiset.Fintype import Mathlib.FieldTheory.IsAlgClosed.Basic import Mathlib.FieldTheory.SplittingField.Construction /-! # Algebraic Closure In this file we construct the algebraic closure of a field ## Main Definitions - `AlgebraicClosure k` is an algebraic closure of `k` (in the same universe). It is constructed by taking the polynomial ring generated by indeterminates $X_{f,1}, \dots, X_{f,\deg f}$ corresponding to roots of monic irreducible polynomials `f` with coefficients in `k`, and quotienting out by a maximal ideal containing every $f - \prod_i (X - X_{f,i})$. The proof follows https://kconrad.math.uconn.edu/blurbs/galoistheory/algclosureshorter.pdf. ## Tags algebraic closure, algebraically closed -/ universe u v w noncomputable section open Polynomial variable (k : Type u) [Field k] namespace AlgebraicClosure /-- The subtype of monic polynomials. -/ def Monics : Type u := {f : k[X] // f.Monic} /-- `Vars k` provides `n` variables $X_{f,1}, \dots, X_{f,n}$ for each monic polynomial `f : k[X]` of degree `n`. -/ def Vars : Type u := Σ f : Monics k, Fin f.1.natDegree variable {k} in /-- Given a monic polynomial `f : k[X]`, `subProdXSubC f` is the polynomial $f - \prod_i (X - X_{f,i})$. -/ def subProdXSubC (f : Monics k) : (MvPolynomial (Vars k) k)[X] := f.1.map (algebraMap _ _) - ∏ i : Fin f.1.natDegree, (X - C (MvPolynomial.X ⟨f, i⟩)) /-- The span of all coefficients of `subProdXSubC f` as `f` ranges all polynomials in `k[X]`. -/ def spanCoeffs : Ideal (MvPolynomial (Vars k) k) := Ideal.span <| Set.range fun fn : Monics k × ℕ ↦ (subProdXSubC fn.1).coeff fn.2 variable {k} /-- If a monic polynomial `f : k[X]` splits in `K`, then it has as many roots (counting multiplicity) as its degree. -/ def finEquivRoots {K} [Field K] [DecidableEq K] {i : k →+* K} {f : Monics k} (hf : f.1.Splits i) : Fin f.1.natDegree ≃ (f.1.map i).roots.toEnumFinset := .symm <| Finset.equivFinOfCardEq <| by rwa [← splits_id_iff_splits, splits_iff_card_roots, ← Multiset.card_toEnumFinset, f.2.natDegree_map] at hf lemma Monics.splits_finsetProd {s : Finset (Monics k)} {f : Monics k} (hf : f ∈ s) : f.1.Splits (algebraMap k (SplittingField (∏ f ∈ s, f.1))) := (splits_prod_iff _ fun j _ ↦ j.2.ne_zero).1 (SplittingField.splits _) _ hf open Classical in /-- Given a finite set of monic polynomials, construct an algebra homomorphism to the splitting field of the product of the polynomials sending indeterminates $X_{f_i}$ to the distinct roots of `f`. -/ def toSplittingField (s : Finset (Monics k)) : MvPolynomial (Vars k) k →ₐ[k] SplittingField (∏ f ∈ s, f.1) := MvPolynomial.aeval fun fi ↦ if hf : fi.1 ∈ s then (finEquivRoots (Monics.splits_finsetProd hf) fi.2).1.1 else 37 theorem toSplittingField_coeff {s : Finset (Monics k)} {f} (h : f ∈ s) (n) : toSplittingField s ((subProdXSubC f).coeff n) = 0 := by classical simp_rw [← AlgHom.coe_toRingHom, ← coeff_map, subProdXSubC, Polynomial.map_sub, Polynomial.map_prod, Polynomial.map_sub, map_X, map_C, toSplittingField, AlgHom.coe_toRingHom, MvPolynomial.aeval_X, dif_pos h, ← (finEquivRoots (Monics.splits_finsetProd h)).symm.prod_comp, Equiv.apply_symm_apply] rw [Finset.prod_coe_sort (f := fun x : _ × ℕ ↦ X - C x.1), (Multiset.toEnumFinset _) |>.prod_eq_multiset_prod, ← Function.comp_def (X - C ·) Prod.fst, ← Multiset.map_map, Multiset.map_toEnumFinset_fst, map_map, AlgHom.comp_algebraMap] conv in map _ _ => rw [eq_prod_roots_of_splits (Monics.splits_finsetProd h)] rw [f.2, map_one, C_1, one_mul, sub_self, coeff_zero] variable (k) theorem spanCoeffs_ne_top : spanCoeffs k ≠ ⊤ := by rw [Ideal.ne_top_iff_one, spanCoeffs, Ideal.span, ← Set.image_univ, Finsupp.mem_span_image_iff_linearCombination] rintro ⟨v, _, hv⟩ classical replace hv := congr_arg (toSplittingField <| v.support.image Prod.fst) hv rw [map_one, Finsupp.linearCombination_apply, Finsupp.sum, map_sum, Finset.sum_eq_zero] at hv · exact zero_ne_one hv intro j hj rw [smul_eq_mul, map_mul, toSplittingField_coeff (Finset.mem_image_of_mem _ hj), mul_zero] /-- A random maximal ideal that contains `spanEval k` -/ def maxIdeal : Ideal (MvPolynomial (Vars k) k) := Classical.choose <| Ideal.exists_le_maximal _ <| spanCoeffs_ne_top k instance maxIdeal.isMaximal : (maxIdeal k).IsMaximal := (Classical.choose_spec <| Ideal.exists_le_maximal _ <| spanCoeffs_ne_top k).1 theorem le_maxIdeal : spanCoeffs k ≤ maxIdeal k := (Classical.choose_spec <| Ideal.exists_le_maximal _ <| spanCoeffs_ne_top k).2 end AlgebraicClosure open AlgebraicClosure in /-- The canonical algebraic closure of a field, the direct limit of adding roots to the field for each polynomial over the field. -/ @[stacks 09GT] def AlgebraicClosure : Type u := MvPolynomial (Vars k) k ⧸ maxIdeal k namespace AlgebraicClosure instance instCommRing : CommRing (AlgebraicClosure k) := Ideal.Quotient.commRing _ instance instInhabited : Inhabited (AlgebraicClosure k) := ⟨37⟩ instance {S : Type*} [DistribSMul S k] [IsScalarTower S k k] : SMul S (AlgebraicClosure k) := Submodule.Quotient.instSMul' _ instance instAlgebra {R : Type*} [CommSemiring R] [Algebra R k] : Algebra R (AlgebraicClosure k) := Ideal.Quotient.algebra _ instance {R S : Type*} [CommSemiring R] [CommSemiring S] [Algebra R S] [Algebra S k] [Algebra R k] [IsScalarTower R S k] : IsScalarTower R S (AlgebraicClosure k) := Ideal.Quotient.isScalarTower _ _ _ instance instGroupWithZero : GroupWithZero (AlgebraicClosure k) where __ := Ideal.Quotient.field _ instance instField : Field (AlgebraicClosure k) where __ := instCommRing _ __ := instGroupWithZero _ nnqsmul := (· • ·) qsmul := (· • ·) nnratCast q := algebraMap k _ q ratCast q := algebraMap k _ q nnratCast_def q := by change algebraMap k _ _ = _; simp_rw [NNRat.cast_def, map_div₀, map_natCast] ratCast_def q := by change algebraMap k _ _ = _; rw [Rat.cast_def, map_div₀, map_intCast, map_natCast] nnqsmul_def q x := Quotient.inductionOn x fun p ↦ congr_arg Quotient.mk'' <| by ext; simp [MvPolynomial.algebraMap_eq, NNRat.smul_def] qsmul_def q x := Quotient.inductionOn x fun p ↦ congr_arg Quotient.mk'' <| by ext; simp [MvPolynomial.algebraMap_eq, Rat.smul_def] theorem Monics.map_eq_prod {f : Monics k} : f.1.map (algebraMap k (AlgebraicClosure k)) = ∏ i, map (Ideal.Quotient.mk <| maxIdeal k) (X - C (MvPolynomial.X ⟨f, i⟩)) := by ext dsimp [AlgebraicClosure] rw [← Ideal.Quotient.mk_comp_algebraMap, ← map_map, ← Polynomial.map_prod, ← sub_eq_zero, ← coeff_sub, ← Polynomial.map_sub, ← subProdXSubC, coeff_map, Ideal.Quotient.eq_zero_iff_mem] refine le_maxIdeal _ (Ideal.subset_span ⟨⟨f, _⟩, rfl⟩) instance isAlgebraic : Algebra.IsAlgebraic k (AlgebraicClosure k) := ⟨fun z => IsIntegral.isAlgebraic <| by let ⟨p, hp⟩ := Ideal.Quotient.mk_surjective z rw [← hp] induction p using MvPolynomial.induction_on generalizing z with | C => exact isIntegral_algebraMap | add _ _ ha hb => exact (ha _ rfl).add (hb _ rfl) | mul_X p fi ih => rw [map_mul] refine (ih _ rfl).mul ⟨_, fi.1.2, ?_⟩ simp_rw [← eval_map, Monics.map_eq_prod, eval_prod, Polynomial.map_sub, eval_sub] apply Finset.prod_eq_zero (Finset.mem_univ fi.2) rw [map_C] -- The `erw` is needed here because the `R` in `eval` is `AlgebraicClosure k`, -- but this has been unfolded in the arguments of `eval`. erw [eval_C] simp⟩ instance : IsAlgClosure k (AlgebraicClosure k) := .of_splits fun f hf _ ↦ by rw [show f = (⟨f, hf⟩ : Monics k) from rfl, ← splits_id_iff_splits, Monics.map_eq_prod] exact splits_prod _ fun _ _ ↦ (splits_id_iff_splits _).mpr (splits_X_sub_C _) instance isAlgClosed : IsAlgClosed (AlgebraicClosure k) := IsAlgClosure.isAlgClosed k instance [CharZero k] : CharZero (AlgebraicClosure k) := charZero_of_injective_algebraMap (RingHom.injective (algebraMap k (AlgebraicClosure k))) instance {p : ℕ} [CharP k p] : CharP (AlgebraicClosure k) p := charP_of_injective_algebraMap (RingHom.injective (algebraMap k (AlgebraicClosure k))) p instance {L : Type*} [Field k] [Field L] [Algebra k L] [Algebra.IsAlgebraic k L] : IsAlgClosure k (AlgebraicClosure L) where isAlgebraic := .trans k L _ isAlgClosed := inferInstance end AlgebraicClosure
Mathlib/FieldTheory/IsAlgClosed/AlgebraicClosure.lean
348
357
/- 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
Mathlib/Probability/StrongLaw.lean
201
213
/- Copyright (c) 2021 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Algebra.BigOperators.Fin import Mathlib.Algebra.Order.Module.Algebra import Mathlib.Algebra.Ring.Subring.Units import Mathlib.LinearAlgebra.LinearIndependent.Defs import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Module import Mathlib.Tactic.Positivity.Basic /-! # Rays in modules This file defines rays in modules. ## Main definitions * `SameRay`: two vectors belong to the same ray if they are proportional with a nonnegative coefficient. * `Module.Ray` is a type for the equivalence class of nonzero vectors in a module with some common positive multiple. -/ noncomputable section section StrictOrderedCommSemiring -- TODO: remove `[IsStrictOrderedRing R]` and `@[nolint unusedArguments]`. /-- Two vectors are in the same ray if either one of them is zero or some positive multiples of them are equal (in the typical case over a field, this means one of them is a nonnegative multiple of the other). -/ @[nolint unusedArguments] def SameRay (R : Type*) [CommSemiring R] [PartialOrder R] [IsStrictOrderedRing R] {M : Type*} [AddCommMonoid M] [Module R M] (v₁ v₂ : M) : Prop := v₁ = 0 ∨ v₂ = 0 ∨ ∃ r₁ r₂ : R, 0 < r₁ ∧ 0 < r₂ ∧ r₁ • v₁ = r₂ • v₂ variable {R : Type*} [CommSemiring R] [PartialOrder R] [IsStrictOrderedRing R] variable {M : Type*} [AddCommMonoid M] [Module R M] variable {N : Type*} [AddCommMonoid N] [Module R N] variable (ι : Type*) [DecidableEq ι] namespace SameRay variable {x y z : M} @[simp] theorem zero_left (y : M) : SameRay R 0 y := Or.inl rfl @[simp] theorem zero_right (x : M) : SameRay R x 0 := Or.inr <| Or.inl rfl @[nontriviality] theorem of_subsingleton [Subsingleton M] (x y : M) : SameRay R x y := by rw [Subsingleton.elim x 0] exact zero_left _ @[nontriviality] theorem of_subsingleton' [Subsingleton R] (x y : M) : SameRay R x y := haveI := Module.subsingleton R M of_subsingleton x y /-- `SameRay` is reflexive. -/ @[refl] theorem refl (x : M) : SameRay R x x := by nontriviality R exact Or.inr (Or.inr <| ⟨1, 1, zero_lt_one, zero_lt_one, rfl⟩) protected theorem rfl : SameRay R x x := refl _ /-- `SameRay` is symmetric. -/ @[symm] theorem symm (h : SameRay R x y) : SameRay R y x := (or_left_comm.1 h).imp_right <| Or.imp_right fun ⟨r₁, r₂, h₁, h₂, h⟩ => ⟨r₂, r₁, h₂, h₁, h.symm⟩ /-- If `x` and `y` are nonzero vectors on the same ray, then there exist positive numbers `r₁ r₂` such that `r₁ • x = r₂ • y`. -/ theorem exists_pos (h : SameRay R x y) (hx : x ≠ 0) (hy : y ≠ 0) : ∃ r₁ r₂ : R, 0 < r₁ ∧ 0 < r₂ ∧ r₁ • x = r₂ • y := (h.resolve_left hx).resolve_left hy theorem sameRay_comm : SameRay R x y ↔ SameRay R y x := ⟨SameRay.symm, SameRay.symm⟩ /-- `SameRay` is transitive unless the vector in the middle is zero and both other vectors are nonzero. -/ theorem trans (hxy : SameRay R x y) (hyz : SameRay R y z) (hy : y = 0 → x = 0 ∨ z = 0) : SameRay R x z := by rcases eq_or_ne x 0 with (rfl | hx); · exact zero_left z rcases eq_or_ne z 0 with (rfl | hz); · exact zero_right x rcases eq_or_ne y 0 with (rfl | hy) · exact (hy rfl).elim (fun h => (hx h).elim) fun h => (hz h).elim rcases hxy.exists_pos hx hy with ⟨r₁, r₂, hr₁, hr₂, h₁⟩ rcases hyz.exists_pos hy hz with ⟨r₃, r₄, hr₃, hr₄, h₂⟩ refine Or.inr (Or.inr <| ⟨r₃ * r₁, r₂ * r₄, mul_pos hr₃ hr₁, mul_pos hr₂ hr₄, ?_⟩) rw [mul_smul, mul_smul, h₁, ← h₂, smul_comm] variable {S : Type*} [CommSemiring S] [PartialOrder S] [Algebra S R] [Module S M] [SMulPosMono S R] [IsScalarTower S R M] {a : S} /-- A vector is in the same ray as a nonnegative multiple of itself. -/ lemma sameRay_nonneg_smul_right (v : M) (h : 0 ≤ a) : SameRay R v (a • v) := by obtain h | h := (algebraMap_nonneg R h).eq_or_gt · rw [← algebraMap_smul R a v, h, zero_smul] exact zero_right _ · refine Or.inr <| Or.inr ⟨algebraMap S R a, 1, h, by nontriviality R; exact zero_lt_one, ?_⟩ module /-- A nonnegative multiple of a vector is in the same ray as that vector. -/ lemma sameRay_nonneg_smul_left (v : M) (ha : 0 ≤ a) : SameRay R (a • v) v := (sameRay_nonneg_smul_right v ha).symm /-- A vector is in the same ray as a positive multiple of itself. -/ lemma sameRay_pos_smul_right (v : M) (ha : 0 < a) : SameRay R v (a • v) := sameRay_nonneg_smul_right v ha.le /-- A positive multiple of a vector is in the same ray as that vector. -/ lemma sameRay_pos_smul_left (v : M) (ha : 0 < a) : SameRay R (a • v) v := sameRay_nonneg_smul_left v ha.le /-- A vector is in the same ray as a nonnegative multiple of one it is in the same ray as. -/ lemma nonneg_smul_right (h : SameRay R x y) (ha : 0 ≤ a) : SameRay R x (a • y) := h.trans (sameRay_nonneg_smul_right y ha) fun hy => Or.inr <| by rw [hy, smul_zero] /-- A nonnegative multiple of a vector is in the same ray as one it is in the same ray as. -/ lemma nonneg_smul_left (h : SameRay R x y) (ha : 0 ≤ a) : SameRay R (a • x) y := (h.symm.nonneg_smul_right ha).symm /-- A vector is in the same ray as a positive multiple of one it is in the same ray as. -/ theorem pos_smul_right (h : SameRay R x y) (ha : 0 < a) : SameRay R x (a • y) := h.nonneg_smul_right ha.le /-- A positive multiple of a vector is in the same ray as one it is in the same ray as. -/ theorem pos_smul_left (h : SameRay R x y) (hr : 0 < a) : SameRay R (a • x) y := h.nonneg_smul_left hr.le /-- If two vectors are on the same ray then they remain so after applying a linear map. -/ theorem map (f : M →ₗ[R] N) (h : SameRay R x y) : SameRay R (f x) (f y) := (h.imp fun hx => by rw [hx, map_zero]) <| Or.imp (fun hy => by rw [hy, map_zero]) fun ⟨r₁, r₂, hr₁, hr₂, h⟩ => ⟨r₁, r₂, hr₁, hr₂, by rw [← f.map_smul, ← f.map_smul, h]⟩ /-- The images of two vectors under an injective linear map are on the same ray if and only if the original vectors are on the same ray. -/ theorem _root_.Function.Injective.sameRay_map_iff {F : Type*} [FunLike F M N] [LinearMapClass F R M N] {f : F} (hf : Function.Injective f) : SameRay R (f x) (f y) ↔ SameRay R x y := by simp only [SameRay, map_zero, ← hf.eq_iff, map_smul] /-- The images of two vectors under a linear equivalence are on the same ray if and only if the original vectors are on the same ray. -/ @[simp] theorem sameRay_map_iff (e : M ≃ₗ[R] N) : SameRay R (e x) (e y) ↔ SameRay R x y := Function.Injective.sameRay_map_iff (EquivLike.injective e) /-- If two vectors are on the same ray then both scaled by the same action are also on the same ray. -/ theorem smul {S : Type*} [Monoid S] [DistribMulAction S M] [SMulCommClass R S M] (h : SameRay R x y) (s : S) : SameRay R (s • x) (s • y) := h.map (s • (LinearMap.id : M →ₗ[R] M)) /-- If `x` and `y` are on the same ray as `z`, then so is `x + y`. -/ theorem add_left (hx : SameRay R x z) (hy : SameRay R y z) : SameRay R (x + y) z := by rcases eq_or_ne x 0 with (rfl | hx₀); · rwa [zero_add] rcases eq_or_ne y 0 with (rfl | hy₀); · rwa [add_zero] rcases eq_or_ne z 0 with (rfl | hz₀); · apply zero_right rcases hx.exists_pos hx₀ hz₀ with ⟨rx, rz₁, hrx, hrz₁, Hx⟩ rcases hy.exists_pos hy₀ hz₀ with ⟨ry, rz₂, hry, hrz₂, Hy⟩ refine Or.inr (Or.inr ⟨rx * ry, ry * rz₁ + rx * rz₂, mul_pos hrx hry, ?_, ?_⟩) · positivity · convert congr(ry • $Hx + rx • $Hy) using 1 <;> module /-- If `y` and `z` are on the same ray as `x`, then so is `y + z`. -/ theorem add_right (hy : SameRay R x y) (hz : SameRay R x z) : SameRay R x (y + z) := (hy.symm.add_left hz.symm).symm end SameRay set_option linter.unusedVariables false in /-- Nonzero vectors, as used to define rays. This type depends on an unused argument `R` so that `RayVector.Setoid` can be an instance. -/ @[nolint unusedArguments] def RayVector (R M : Type*) [Zero M] := { v : M // v ≠ 0 } instance RayVector.coe [Zero M] : CoeOut (RayVector R M) M where coe := Subtype.val instance {R M : Type*} [Zero M] [Nontrivial M] : Nonempty (RayVector R M) := let ⟨x, hx⟩ := exists_ne (0 : M) ⟨⟨x, hx⟩⟩ variable (R M) /-- The setoid of the `SameRay` relation for the subtype of nonzero vectors. -/ instance RayVector.Setoid : Setoid (RayVector R M) where r x y := SameRay R (x : M) y iseqv := ⟨fun _ => SameRay.refl _, fun h => h.symm, by intros x y z hxy hyz exact hxy.trans hyz fun hy => (y.2 hy).elim⟩ /-- A ray (equivalence class of nonzero vectors with common positive multiples) in a module. -/ def Module.Ray := Quotient (RayVector.Setoid R M) variable {R M} /-- Equivalence of nonzero vectors, in terms of `SameRay`. -/ theorem equiv_iff_sameRay {v₁ v₂ : RayVector R M} : v₁ ≈ v₂ ↔ SameRay R (v₁ : M) v₂ := Iff.rfl variable (R) /-- The ray given by a nonzero vector. -/ def rayOfNeZero (v : M) (h : v ≠ 0) : Module.Ray R M := ⟦⟨v, h⟩⟧ /-- An induction principle for `Module.Ray`, used as `induction x using Module.Ray.ind`. -/ theorem Module.Ray.ind {C : Module.Ray R M → Prop} (h : ∀ (v) (hv : v ≠ 0), C (rayOfNeZero R v hv)) (x : Module.Ray R M) : C x := Quotient.ind (Subtype.rec <| h) x variable {R} instance [Nontrivial M] : Nonempty (Module.Ray R M) := Nonempty.map Quotient.mk' inferInstance /-- The rays given by two nonzero vectors are equal if and only if those vectors satisfy `SameRay`. -/ theorem ray_eq_iff {v₁ v₂ : M} (hv₁ : v₁ ≠ 0) (hv₂ : v₂ ≠ 0) : rayOfNeZero R _ hv₁ = rayOfNeZero R _ hv₂ ↔ SameRay R v₁ v₂ := Quotient.eq' /-- The ray given by a positive multiple of a nonzero vector. -/ @[simp] theorem ray_pos_smul {v : M} (h : v ≠ 0) {r : R} (hr : 0 < r) (hrv : r • v ≠ 0) : rayOfNeZero R (r • v) hrv = rayOfNeZero R v h := (ray_eq_iff _ _).2 <| SameRay.sameRay_pos_smul_left v hr /-- An equivalence between modules implies an equivalence between ray vectors. -/ def RayVector.mapLinearEquiv (e : M ≃ₗ[R] N) : RayVector R M ≃ RayVector R N := Equiv.subtypeEquiv e.toEquiv fun _ => e.map_ne_zero_iff.symm /-- An equivalence between modules implies an equivalence between rays. -/ def Module.Ray.map (e : M ≃ₗ[R] N) : Module.Ray R M ≃ Module.Ray R N := Quotient.congr (RayVector.mapLinearEquiv e) fun _ _=> (SameRay.sameRay_map_iff _).symm @[simp] theorem Module.Ray.map_apply (e : M ≃ₗ[R] N) (v : M) (hv : v ≠ 0) : Module.Ray.map e (rayOfNeZero _ v hv) = rayOfNeZero _ (e v) (e.map_ne_zero_iff.2 hv) := rfl @[simp] theorem Module.Ray.map_refl : (Module.Ray.map <| LinearEquiv.refl R M) = Equiv.refl _ := Equiv.ext <| Module.Ray.ind R fun _ _ => rfl @[simp] theorem Module.Ray.map_symm (e : M ≃ₗ[R] N) : (Module.Ray.map e).symm = Module.Ray.map e.symm := rfl section Action variable {G : Type*} [Group G] [DistribMulAction G M] /-- Any invertible action preserves the non-zeroness of ray vectors. This is primarily of interest when `G = Rˣ` -/ instance {R : Type*} : MulAction G (RayVector R M) where smul r := Subtype.map (r • ·) fun _ => (smul_ne_zero_iff_ne _).2 mul_smul a b _ := Subtype.ext <| mul_smul a b _ one_smul _ := Subtype.ext <| one_smul _ _ variable [SMulCommClass R G M] /-- Any invertible action preserves the non-zeroness of rays. This is primarily of interest when `G = Rˣ` -/ instance : MulAction G (Module.Ray R M) where smul r := Quotient.map (r • ·) fun _ _ h => h.smul _ mul_smul a b := Quotient.ind fun _ => congr_arg Quotient.mk' <| mul_smul a b _ one_smul := Quotient.ind fun _ => congr_arg Quotient.mk' <| one_smul _ _ /-- The action via `LinearEquiv.apply_distribMulAction` corresponds to `Module.Ray.map`. -/ @[simp] theorem Module.Ray.linearEquiv_smul_eq_map (e : M ≃ₗ[R] M) (v : Module.Ray R M) : e • v = Module.Ray.map e v := rfl @[simp] theorem smul_rayOfNeZero (g : G) (v : M) (hv) : g • rayOfNeZero R v hv = rayOfNeZero R (g • v) ((smul_ne_zero_iff_ne _).2 hv) := rfl end Action namespace Module.Ray /-- Scaling by a positive unit is a no-op. -/ theorem units_smul_of_pos (u : Rˣ) (hu : 0 < (u : R)) (v : Module.Ray R M) : u • v = v := by induction v using Module.Ray.ind rw [smul_rayOfNeZero, ray_eq_iff] exact SameRay.sameRay_pos_smul_left _ hu /-- An arbitrary `RayVector` giving a ray. -/ def someRayVector (x : Module.Ray R M) : RayVector R M := Quotient.out x /-- The ray of `someRayVector`. -/ @[simp] theorem someRayVector_ray (x : Module.Ray R M) : (⟦x.someRayVector⟧ : Module.Ray R M) = x := Quotient.out_eq _ /-- An arbitrary nonzero vector giving a ray. -/ def someVector (x : Module.Ray R M) : M := x.someRayVector /-- `someVector` is nonzero. -/ @[simp] theorem someVector_ne_zero (x : Module.Ray R M) : x.someVector ≠ 0 := x.someRayVector.property /-- The ray of `someVector`. -/ @[simp] theorem someVector_ray (x : Module.Ray R M) : rayOfNeZero R _ x.someVector_ne_zero = x := (congr_arg _ (Subtype.coe_eta _ _) :).trans x.out_eq end Module.Ray end StrictOrderedCommSemiring section StrictOrderedCommRing variable {R : Type*} [CommRing R] [PartialOrder R] [IsStrictOrderedRing R] variable {M N : Type*} [AddCommGroup M] [AddCommGroup N] [Module R M] [Module R N] {x y : M} /-- `SameRay.neg` as an `iff`. -/ @[simp] theorem sameRay_neg_iff : SameRay R (-x) (-y) ↔ SameRay R x y := by simp only [SameRay, neg_eq_zero, smul_neg, neg_inj] alias ⟨SameRay.of_neg, SameRay.neg⟩ := sameRay_neg_iff theorem sameRay_neg_swap : SameRay R (-x) y ↔ SameRay R x (-y) := by rw [← sameRay_neg_iff, neg_neg] theorem eq_zero_of_sameRay_neg_smul_right [NoZeroSMulDivisors R M] {r : R} (hr : r < 0) (h : SameRay R x (r • x)) : x = 0 := by rcases h with (rfl | h₀ | ⟨r₁, r₂, hr₁, hr₂, h⟩) · rfl · simpa [hr.ne] using h₀ · rw [← sub_eq_zero, smul_smul, ← sub_smul, smul_eq_zero] at h refine h.resolve_left (ne_of_gt <| sub_pos.2 ?_) exact (mul_neg_of_pos_of_neg hr₂ hr).trans hr₁ /-- If a vector is in the same ray as its negation, that vector is zero. -/ theorem eq_zero_of_sameRay_self_neg [NoZeroSMulDivisors R M] (h : SameRay R x (-x)) : x = 0 := by nontriviality M; haveI : Nontrivial R := Module.nontrivial R M refine eq_zero_of_sameRay_neg_smul_right (neg_lt_zero.2 (zero_lt_one' R)) ?_ rwa [neg_one_smul] namespace RayVector /-- Negating a nonzero vector. -/ instance {R : Type*} : Neg (RayVector R M) := ⟨fun v => ⟨-v, neg_ne_zero.2 v.prop⟩⟩ /-- Negating a nonzero vector commutes with coercion to the underlying module. -/ @[simp, norm_cast] theorem coe_neg {R : Type*} (v : RayVector R M) : ↑(-v) = -(v : M) := rfl /-- Negating a nonzero vector twice produces the original vector. -/ instance {R : Type*} : InvolutiveNeg (RayVector R M) where neg := Neg.neg neg_neg v := by rw [Subtype.ext_iff, coe_neg, coe_neg, neg_neg] /-- If two nonzero vectors are equivalent, so are their negations. -/ @[simp] theorem equiv_neg_iff {v₁ v₂ : RayVector R M} : -v₁ ≈ -v₂ ↔ v₁ ≈ v₂ := sameRay_neg_iff end RayVector variable (R) /-- Negating a ray. -/ instance : Neg (Module.Ray R M) := ⟨Quotient.map (fun v => -v) fun _ _ => RayVector.equiv_neg_iff.2⟩ /-- The ray given by the negation of a nonzero vector. -/ @[simp] theorem neg_rayOfNeZero (v : M) (h : v ≠ 0) : -rayOfNeZero R _ h = rayOfNeZero R (-v) (neg_ne_zero.2 h) := rfl namespace Module.Ray variable {R} /-- Negating a ray twice produces the original ray. -/ instance : InvolutiveNeg (Module.Ray R M) where neg := Neg.neg neg_neg x := by apply ind R (by simp) x -- Quotient.ind (fun a => congr_arg Quotient.mk' <| neg_neg _) x /-- A ray does not equal its own negation. -/ theorem ne_neg_self [NoZeroSMulDivisors R M] (x : Module.Ray R M) : x ≠ -x := by induction x using Module.Ray.ind with | h x hx => rw [neg_rayOfNeZero, Ne, ray_eq_iff] exact mt eq_zero_of_sameRay_self_neg hx theorem neg_units_smul (u : Rˣ) (v : Module.Ray R M) : -u • v = -(u • v) := by induction v using Module.Ray.ind simp only [smul_rayOfNeZero, Units.smul_def, Units.val_neg, neg_smul, neg_rayOfNeZero] /-- Scaling by a negative unit is negation. -/ theorem units_smul_of_neg (u : Rˣ) (hu : (u : R) < 0) (v : Module.Ray R M) : u • v = -v := by rw [← neg_inj, neg_neg, ← neg_units_smul, units_smul_of_pos] rwa [Units.val_neg, Right.neg_pos_iff] @[simp] protected theorem map_neg (f : M ≃ₗ[R] N) (v : Module.Ray R M) : map f (-v) = -map f v := by induction v using Module.Ray.ind with | h g hg => simp end Module.Ray end StrictOrderedCommRing section LinearOrderedCommRing variable {R : Type*} [CommRing R] [LinearOrder R] [IsStrictOrderedRing R] variable {M : Type*} [AddCommGroup M] [Module R M] /-- `SameRay` follows from membership of `MulAction.orbit` for the `Units.posSubgroup`. -/ theorem sameRay_of_mem_orbit {v₁ v₂ : M} (h : v₁ ∈ MulAction.orbit (Units.posSubgroup R) v₂) : SameRay R v₁ v₂ := by rcases h with ⟨⟨r, hr : 0 < r.1⟩, rfl : r • v₂ = v₁⟩ exact SameRay.sameRay_pos_smul_left _ hr /-- Scaling by an inverse unit is the same as scaling by itself. -/ @[simp] theorem units_inv_smul (u : Rˣ) (v : Module.Ray R M) : u⁻¹ • v = u • v := have := mul_self_pos.2 u.ne_zero calc u⁻¹ • v = (u * u) • u⁻¹ • v := Eq.symm <| (u⁻¹ • v).units_smul_of_pos _ (by exact this) _ = u • v := by rw [mul_smul, smul_inv_smul] section variable [NoZeroSMulDivisors R M] @[simp] theorem sameRay_smul_right_iff {v : M} {r : R} : SameRay R v (r • v) ↔ 0 ≤ r ∨ v = 0 := ⟨fun hrv => or_iff_not_imp_left.2 fun hr => eq_zero_of_sameRay_neg_smul_right (not_le.1 hr) hrv, or_imp.2 ⟨SameRay.sameRay_nonneg_smul_right v, fun h => h.symm ▸ SameRay.zero_left _⟩⟩ /-- A nonzero vector is in the same ray as a multiple of itself if and only if that multiple is positive. -/ theorem sameRay_smul_right_iff_of_ne {v : M} (hv : v ≠ 0) {r : R} (hr : r ≠ 0) : SameRay R v (r • v) ↔ 0 < r := by simp only [sameRay_smul_right_iff, hv, or_false, hr.symm.le_iff_lt] @[simp] theorem sameRay_smul_left_iff {v : M} {r : R} : SameRay R (r • v) v ↔ 0 ≤ r ∨ v = 0 := SameRay.sameRay_comm.trans sameRay_smul_right_iff /-- A multiple of a nonzero vector is in the same ray as that vector if and only if that multiple is positive. -/ theorem sameRay_smul_left_iff_of_ne {v : M} (hv : v ≠ 0) {r : R} (hr : r ≠ 0) : SameRay R (r • v) v ↔ 0 < r := SameRay.sameRay_comm.trans (sameRay_smul_right_iff_of_ne hv hr) @[simp] theorem sameRay_neg_smul_right_iff {v : M} {r : R} : SameRay R (-v) (r • v) ↔ r ≤ 0 ∨ v = 0 := by rw [← sameRay_neg_iff, neg_neg, ← neg_smul, sameRay_smul_right_iff, neg_nonneg] theorem sameRay_neg_smul_right_iff_of_ne {v : M} {r : R} (hv : v ≠ 0) (hr : r ≠ 0) : SameRay R (-v) (r • v) ↔ r < 0 := by simp only [sameRay_neg_smul_right_iff, hv, or_false, hr.le_iff_lt] @[simp] theorem sameRay_neg_smul_left_iff {v : M} {r : R} : SameRay R (r • v) (-v) ↔ r ≤ 0 ∨ v = 0 := SameRay.sameRay_comm.trans sameRay_neg_smul_right_iff theorem sameRay_neg_smul_left_iff_of_ne {v : M} {r : R} (hv : v ≠ 0) (hr : r ≠ 0) : SameRay R (r • v) (-v) ↔ r < 0 := SameRay.sameRay_comm.trans <| sameRay_neg_smul_right_iff_of_ne hv hr @[simp] theorem units_smul_eq_self_iff {u : Rˣ} {v : Module.Ray R M} : u • v = v ↔ 0 < (u : R) := by induction v using Module.Ray.ind with | h v hv => simp only [smul_rayOfNeZero, ray_eq_iff, Units.smul_def, sameRay_smul_left_iff_of_ne hv u.ne_zero] @[simp] theorem units_smul_eq_neg_iff {u : Rˣ} {v : Module.Ray R M} : u • v = -v ↔ u.1 < 0 := by rw [← neg_inj, neg_neg, ← Module.Ray.neg_units_smul, units_smul_eq_self_iff, Units.val_neg, neg_pos] /-- Two vectors are in the same ray, or the first is in the same ray as the negation of the second, if and only if they are not linearly independent. -/ theorem sameRay_or_sameRay_neg_iff_not_linearIndependent {x y : M} : SameRay R x y ∨ SameRay R x (-y) ↔ ¬LinearIndependent R ![x, y] := by by_cases hx : x = 0; · simpa [hx] using fun h : LinearIndependent R ![0, y] => h.ne_zero 0 rfl by_cases hy : y = 0; · simpa [hy] using fun h : LinearIndependent R ![x, 0] => h.ne_zero 1 rfl simp_rw [Fintype.not_linearIndependent_iff] refine ⟨fun h => ?_, fun h => ?_⟩ · rcases h with ((hx0 | hy0 | ⟨r₁, r₂, hr₁, _, h⟩) | (hx0 | hy0 | ⟨r₁, r₂, hr₁, _, h⟩)) · exact False.elim (hx hx0) · exact False.elim (hy hy0) · refine ⟨![r₁, -r₂], ?_⟩ rw [Fin.sum_univ_two, Fin.exists_fin_two] simp [h, hr₁.ne.symm] · exact False.elim (hx hx0) · exact False.elim (hy (neg_eq_zero.1 hy0)) · refine ⟨![r₁, r₂], ?_⟩ rw [Fin.sum_univ_two, Fin.exists_fin_two] simp [h, hr₁.ne.symm] · rcases h with ⟨m, hm, hmne⟩ rw [Fin.sum_univ_two, add_eq_zero_iff_eq_neg] at hm dsimp only [Matrix.cons_val] at hm rcases lt_trichotomy (m 0) 0 with (hm0 | hm0 | hm0) <;> rcases lt_trichotomy (m 1) 0 with (hm1 | hm1 | hm1) · refine Or.inr (Or.inr (Or.inr ⟨-m 0, -m 1, Left.neg_pos_iff.2 hm0, Left.neg_pos_iff.2 hm1, ?_⟩)) linear_combination (norm := module) -hm · exfalso simp [hm1, hx, hm0.ne] at hm · refine Or.inl (Or.inr (Or.inr ⟨-m 0, m 1, Left.neg_pos_iff.2 hm0, hm1, ?_⟩)) linear_combination (norm := module) -hm · exfalso simp [hm0, hy, hm1.ne] at hm · rw [Fin.exists_fin_two] at hmne exact False.elim (not_and_or.2 hmne ⟨hm0, hm1⟩) · exfalso simp [hm0, hy, hm1.ne.symm] at hm · refine Or.inl (Or.inr (Or.inr ⟨m 0, -m 1, hm0, Left.neg_pos_iff.2 hm1, ?_⟩)) rwa [neg_smul] · exfalso simp [hm1, hx, hm0.ne.symm] at hm · refine Or.inr (Or.inr (Or.inr ⟨m 0, m 1, hm0, hm1, ?_⟩)) rwa [smul_neg] /-- Two vectors are in the same ray, or they are nonzero and the first is in the same ray as the negation of the second, if and only if they are not linearly independent. -/ theorem sameRay_or_ne_zero_and_sameRay_neg_iff_not_linearIndependent {x y : M} : SameRay R x y ∨ x ≠ 0 ∧ y ≠ 0 ∧ SameRay R x (-y) ↔ ¬LinearIndependent R ![x, y] := by rw [← sameRay_or_sameRay_neg_iff_not_linearIndependent] by_cases hx : x = 0; · simp [hx] by_cases hy : y = 0 <;> simp [hx, hy] end end LinearOrderedCommRing namespace SameRay variable {R : Type*} [Field R] [LinearOrder R] [IsStrictOrderedRing R] variable {M : Type*} [AddCommGroup M] [Module R M] {x y v₁ v₂ : M} theorem exists_pos_left (h : SameRay R x y) (hx : x ≠ 0) (hy : y ≠ 0) : ∃ r : R, 0 < r ∧ r • x = y := let ⟨r₁, r₂, hr₁, hr₂, h⟩ := h.exists_pos hx hy ⟨r₂⁻¹ * r₁, mul_pos (inv_pos.2 hr₂) hr₁, by rw [mul_smul, h, inv_smul_smul₀ hr₂.ne']⟩ theorem exists_pos_right (h : SameRay R x y) (hx : x ≠ 0) (hy : y ≠ 0) : ∃ r : R, 0 < r ∧ x = r • y := (h.symm.exists_pos_left hy hx).imp fun _ => And.imp_right Eq.symm /-- If a vector `v₂` is on the same ray as a nonzero vector `v₁`, then it is equal to `c • v₁` for some nonnegative `c`. -/ theorem exists_nonneg_left (h : SameRay R x y) (hx : x ≠ 0) : ∃ r : R, 0 ≤ r ∧ r • x = y := by obtain rfl | hy := eq_or_ne y 0 · exact ⟨0, le_rfl, zero_smul _ _⟩ · exact (h.exists_pos_left hx hy).imp fun _ => And.imp_left le_of_lt /-- If a vector `v₁` is on the same ray as a nonzero vector `v₂`, then it is equal to `c • v₂` for some nonnegative `c`. -/ theorem exists_nonneg_right (h : SameRay R x y) (hy : y ≠ 0) : ∃ r : R, 0 ≤ r ∧ x = r • y := (h.symm.exists_nonneg_left hy).imp fun _ => And.imp_right Eq.symm /-- If vectors `v₁` and `v₂` are on the same ray, then for some nonnegative `a b`, `a + b = 1`, we have `v₁ = a • (v₁ + v₂)` and `v₂ = b • (v₁ + v₂)`. -/ theorem exists_eq_smul_add (h : SameRay R v₁ v₂) : ∃ a b : R, 0 ≤ a ∧ 0 ≤ b ∧ a + b = 1 ∧ v₁ = a • (v₁ + v₂) ∧ v₂ = b • (v₁ + v₂) := by rcases h with (rfl | rfl | ⟨r₁, r₂, h₁, h₂, H⟩) · use 0, 1 simp · use 1, 0 simp · have h₁₂ : 0 < r₁ + r₂ := add_pos h₁ h₂ refine ⟨r₂ / (r₁ + r₂), r₁ / (r₁ + r₂), div_nonneg h₂.le h₁₂.le, div_nonneg h₁.le h₁₂.le, ?_, ?_, ?_⟩ · rw [← add_div, add_comm, div_self h₁₂.ne'] · rw [div_eq_inv_mul, mul_smul, smul_add, ← H, ← add_smul, add_comm r₂, inv_smul_smul₀ h₁₂.ne'] · rw [div_eq_inv_mul, mul_smul, smul_add, H, ← add_smul, add_comm r₂, inv_smul_smul₀ h₁₂.ne'] /-- If vectors `v₁` and `v₂` are on the same ray, then they are nonnegative multiples of the same vector. Actually, this vector can be assumed to be `v₁ + v₂`, see `SameRay.exists_eq_smul_add`. -/ theorem exists_eq_smul (h : SameRay R v₁ v₂) : ∃ (u : M) (a b : R), 0 ≤ a ∧ 0 ≤ b ∧ a + b = 1 ∧ v₁ = a • u ∧ v₂ = b • u := ⟨v₁ + v₂, h.exists_eq_smul_add⟩ end SameRay section LinearOrderedField variable {R : Type*} [Field R] [LinearOrder R] [IsStrictOrderedRing R] variable {M : Type*} [AddCommGroup M] [Module R M] {x y : M} theorem exists_pos_left_iff_sameRay (hx : x ≠ 0) (hy : y ≠ 0) : (∃ r : R, 0 < r ∧ r • x = y) ↔ SameRay R x y := by refine ⟨fun h => ?_, fun h => h.exists_pos_left hx hy⟩ rcases h with ⟨r, hr, rfl⟩ exact SameRay.sameRay_pos_smul_right x hr theorem exists_pos_left_iff_sameRay_and_ne_zero (hx : x ≠ 0) : (∃ r : R, 0 < r ∧ r • x = y) ↔ SameRay R x y ∧ y ≠ 0 := by constructor · rintro ⟨r, hr, rfl⟩ simp [hx, hr.le, hr.ne'] · rintro ⟨hxy, hy⟩ exact (exists_pos_left_iff_sameRay hx hy).2 hxy theorem exists_nonneg_left_iff_sameRay (hx : x ≠ 0) : (∃ r : R, 0 ≤ r ∧ r • x = y) ↔ SameRay R x y := by refine ⟨fun h => ?_, fun h => h.exists_nonneg_left hx⟩ rcases h with ⟨r, hr, rfl⟩ exact SameRay.sameRay_nonneg_smul_right x hr theorem exists_pos_right_iff_sameRay (hx : x ≠ 0) (hy : y ≠ 0) : (∃ r : R, 0 < r ∧ x = r • y) ↔ SameRay R x y := by rw [SameRay.sameRay_comm] simp_rw [eq_comm (a := x)] exact exists_pos_left_iff_sameRay hy hx theorem exists_pos_right_iff_sameRay_and_ne_zero (hy : y ≠ 0) : (∃ r : R, 0 < r ∧ x = r • y) ↔ SameRay R x y ∧ x ≠ 0 := by rw [SameRay.sameRay_comm] simp_rw [eq_comm (a := x)] exact exists_pos_left_iff_sameRay_and_ne_zero hy theorem exists_nonneg_right_iff_sameRay (hy : y ≠ 0) : (∃ r : R, 0 ≤ r ∧ x = r • y) ↔ SameRay R x y := by rw [SameRay.sameRay_comm] simp_rw [eq_comm (a := x)] exact exists_nonneg_left_iff_sameRay (R := R) hy end LinearOrderedField
Mathlib/LinearAlgebra/Ray.lean
658
661
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen, Wen Yang -/ import Mathlib.LinearAlgebra.Matrix.Transvection import Mathlib.LinearAlgebra.Matrix.NonsingularInverse import Mathlib.Tactic.FinCases /-! # Block matrices and their determinant This file defines a predicate `Matrix.BlockTriangular` saying a matrix is block triangular, and proves the value of the determinant for various matrices built out of blocks. ## Main definitions * `Matrix.BlockTriangular` expresses that an `o` by `o` matrix is block triangular, if the rows and columns are ordered according to some order `b : o → α` ## Main results * `Matrix.det_of_blockTriangular`: the determinant of a block triangular matrix is equal to the product of the determinants of all the blocks * `Matrix.det_of_upperTriangular` and `Matrix.det_of_lowerTriangular`: the determinant of a triangular matrix is the product of the entries along the diagonal ## Tags matrix, diagonal, det, block triangular -/ open Finset Function OrderDual open Matrix universe v variable {α β m n o : Type*} {m' n' : α → Type*} variable {R : Type v} {M N : Matrix m m R} {b : m → α} namespace Matrix section LT variable [LT α] section Zero variable [Zero R] /-- Let `b` map rows and columns of a square matrix `M` to blocks indexed by `α`s. Then `BlockTriangular M n b` says the matrix is block triangular. -/ def BlockTriangular (M : Matrix m m R) (b : m → α) : Prop := ∀ ⦃i j⦄, b j < b i → M i j = 0 @[simp] protected theorem BlockTriangular.submatrix {f : n → m} (h : M.BlockTriangular b) : (M.submatrix f f).BlockTriangular (b ∘ f) := fun _ _ hij => h hij
theorem blockTriangular_reindex_iff {b : n → α} {e : m ≃ n} : (reindex e e M).BlockTriangular b ↔ M.BlockTriangular (b ∘ e) := by refine ⟨fun h => ?_, fun h => ?_⟩ · convert h.submatrix simp only [reindex_apply, submatrix_submatrix, submatrix_id_id, Equiv.symm_comp_self] · convert h.submatrix simp only [comp_assoc b e e.symm, Equiv.self_comp_symm, comp_id]
Mathlib/LinearAlgebra/Matrix/Block.lean
63
69
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Robert Y. Lewis -/ import Mathlib.Algebra.CharP.Invertible import Mathlib.Algebra.MvPolynomial.Variables import Mathlib.Algebra.MvPolynomial.CommRing import Mathlib.Algebra.MvPolynomial.Expand import Mathlib.Algebra.Order.Ring.Rat import Mathlib.Data.Fintype.BigOperators import Mathlib.Data.ZMod.Basic /-! # Witt polynomials To endow `WittVector p R` with a ring structure, we need to study the so-called Witt polynomials. Fix a base value `p : ℕ`. The `p`-adic Witt polynomials are an infinite family of polynomials indexed by a natural number `n`, taking values in an arbitrary ring `R`. The variables of these polynomials are represented by natural numbers. The variable set of the `n`th Witt polynomial contains at most `n+1` elements `{0, ..., n}`, with exactly these variables when `R` has characteristic `0`. These polynomials are used to define the addition and multiplication operators on the type of Witt vectors. (While this type itself is not complicated, the ring operations are what make it interesting.) When the base `p` is invertible in `R`, the `p`-adic Witt polynomials form a basis for `MvPolynomial ℕ R`, equivalent to the standard basis. ## Main declarations * `WittPolynomial p R n`: the `n`-th Witt polynomial, viewed as polynomial over the ring `R` * `xInTermsOfW p R n`: if `p` is invertible, the polynomial `X n` is contained in the subalgebra generated by the Witt polynomials. `xInTermsOfW p R n` is the explicit polynomial, which upon being bound to the Witt polynomials yields `X n`. * `bind₁_wittPolynomial_xInTermsOfW`: the proof of the claim that `bind₁ (xInTermsOfW p R) (W_ R n) = X n` * `bind₁_xInTermsOfW_wittPolynomial`: the converse of the above statement ## Notation In this file we use the following notation * `p` is a natural number, typically assumed to be prime. * `R` and `S` are commutative rings * `W n` (and `W_ R n` when the ring needs to be explicit) denotes the `n`th Witt polynomial ## References * [Hazewinkel, *Witt Vectors*][Haze09] * [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21] -/ open MvPolynomial open Finset hiding map open Finsupp (single) --attribute [-simp] coe_eval₂_hom variable (p : ℕ) variable (R : Type*) [CommRing R] /-- `wittPolynomial p R n` is the `n`-th Witt polynomial with respect to a prime `p` with coefficients in a commutative ring `R`. It is defined as: `∑_{i ≤ n} p^i X_i^{p^{n-i}} ∈ R[X_0, X_1, X_2, …]`. -/ noncomputable def wittPolynomial (n : ℕ) : MvPolynomial ℕ R := ∑ i ∈ range (n + 1), monomial (single i (p ^ (n - i))) ((p : R) ^ i) theorem wittPolynomial_eq_sum_C_mul_X_pow (n : ℕ) : wittPolynomial p R n = ∑ i ∈ range (n + 1), C ((p : R) ^ i) * X i ^ p ^ (n - i) := by apply sum_congr rfl rintro i - rw [monomial_eq, Finsupp.prod_single_index] rw [pow_zero] /-! We set up notation locally to this file, to keep statements short and comprehensible. This allows us to simply write `W n` or `W_ ℤ n`. -/ -- Notation with ring of coefficients explicit set_option quotPrecheck false in @[inherit_doc] scoped[Witt] notation "W_" => wittPolynomial p -- Notation with ring of coefficients implicit set_option quotPrecheck false in @[inherit_doc] scoped[Witt] notation "W" => wittPolynomial p _ open Witt open MvPolynomial /-! The first observation is that the Witt polynomial doesn't really depend on the coefficient ring. If we map the coefficients through a ring homomorphism, we obtain the corresponding Witt polynomial over the target ring. -/ section variable {R} {S : Type*} [CommRing S] @[simp] theorem map_wittPolynomial (f : R →+* S) (n : ℕ) : map f (W n) = W n := by rw [wittPolynomial, map_sum, wittPolynomial] refine sum_congr rfl fun i _ => ?_ rw [map_monomial, RingHom.map_pow, map_natCast] variable (R) @[simp] theorem constantCoeff_wittPolynomial [hp : Fact p.Prime] (n : ℕ) : constantCoeff (wittPolynomial p R n) = 0 := by simp only [wittPolynomial, map_sum, constantCoeff_monomial] rw [sum_eq_zero] rintro i _ rw [if_neg] rw [Finsupp.single_eq_zero] exact ne_of_gt (pow_pos hp.1.pos _) @[simp] theorem wittPolynomial_zero : wittPolynomial p R 0 = X 0 := by simp only [wittPolynomial, X, sum_singleton, range_one, pow_zero, zero_add, tsub_self] @[simp] theorem wittPolynomial_one : wittPolynomial p R 1 = C (p : R) * X 1 + X 0 ^ p := by simp only [wittPolynomial_eq_sum_C_mul_X_pow, sum_range_succ_comm, range_one, sum_singleton, one_mul, pow_one, C_1, pow_zero, tsub_self, tsub_zero] theorem aeval_wittPolynomial {A : Type*} [CommRing A] [Algebra R A] (f : ℕ → A) (n : ℕ) : aeval f (W_ R n) = ∑ i ∈ range (n + 1), (p : A) ^ i * f i ^ p ^ (n - i) := by simp [wittPolynomial, map_sum, aeval_monomial, Finsupp.prod_single_index]
/-- Over the ring `ZMod (p^(n+1))`, we produce the `n+1`st Witt polynomial by expanding the `n`th Witt polynomial by `p`. -/
Mathlib/RingTheory/WittVector/WittPolynomial.lean
141
143
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Yaël Dillies -/ import Mathlib.Order.Cover import Mathlib.Order.Interval.Finset.Defs /-! # Intervals as finsets This file provides basic results about all the `Finset.Ixx`, which are defined in `Order.Interval.Finset.Defs`. In addition, it shows that in a locally finite order `≤` and `<` are the transitive closures of, respectively, `⩿` and `⋖`, which then leads to a characterization of monotone and strictly functions whose domain is a locally finite order. In particular, this file proves: * `le_iff_transGen_wcovBy`: `≤` is the transitive closure of `⩿` * `lt_iff_transGen_covBy`: `<` is the transitive closure of `⋖` * `monotone_iff_forall_wcovBy`: Characterization of monotone functions * `strictMono_iff_forall_covBy`: Characterization of strictly monotone functions ## TODO This file was originally only about `Finset.Ico a b` where `a b : ℕ`. No care has yet been taken to generalize these lemmas properly and many lemmas about `Icc`, `Ioc`, `Ioo` are missing. In general, what's to do is taking the lemmas in `Data.X.Intervals` and abstract away the concrete structure. Complete the API. See https://github.com/leanprover-community/mathlib/pull/14448#discussion_r906109235 for some ideas. -/ assert_not_exists MonoidWithZero Finset.sum open Function OrderDual open FinsetInterval variable {ι α : Type*} {a a₁ a₂ b b₁ b₂ c x : α} namespace Finset section Preorder variable [Preorder α] section LocallyFiniteOrder variable [LocallyFiniteOrder α] @[simp] theorem nonempty_Icc : (Icc a b).Nonempty ↔ a ≤ b := by rw [← coe_nonempty, coe_Icc, Set.nonempty_Icc] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Icc_of_le⟩ := nonempty_Icc @[simp] theorem nonempty_Ico : (Ico a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ico, Set.nonempty_Ico] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Ico_of_lt⟩ := nonempty_Ico @[simp] theorem nonempty_Ioc : (Ioc a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ioc, Set.nonempty_Ioc] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Ioc_of_lt⟩ := nonempty_Ioc -- TODO: This is nonsense. A locally finite order is never densely ordered @[simp] theorem nonempty_Ioo [DenselyOrdered α] : (Ioo a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ioo, Set.nonempty_Ioo] @[simp] theorem Icc_eq_empty_iff : Icc a b = ∅ ↔ ¬a ≤ b := by rw [← coe_eq_empty, coe_Icc, Set.Icc_eq_empty_iff] @[simp] theorem Ico_eq_empty_iff : Ico a b = ∅ ↔ ¬a < b := by rw [← coe_eq_empty, coe_Ico, Set.Ico_eq_empty_iff] @[simp] theorem Ioc_eq_empty_iff : Ioc a b = ∅ ↔ ¬a < b := by rw [← coe_eq_empty, coe_Ioc, Set.Ioc_eq_empty_iff] -- TODO: This is nonsense. A locally finite order is never densely ordered @[simp] theorem Ioo_eq_empty_iff [DenselyOrdered α] : Ioo a b = ∅ ↔ ¬a < b := by rw [← coe_eq_empty, coe_Ioo, Set.Ioo_eq_empty_iff] alias ⟨_, Icc_eq_empty⟩ := Icc_eq_empty_iff alias ⟨_, Ico_eq_empty⟩ := Ico_eq_empty_iff alias ⟨_, Ioc_eq_empty⟩ := Ioc_eq_empty_iff @[simp] theorem Ioo_eq_empty (h : ¬a < b) : Ioo a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ hx => h ((mem_Ioo.1 hx).1.trans (mem_Ioo.1 hx).2) @[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 left_mem_Icc : a ∈ Icc a b ↔ a ≤ b := by simp only [mem_Icc, true_and, le_rfl] theorem left_mem_Ico : a ∈ Ico a b ↔ a < b := by simp only [mem_Ico, true_and, le_refl] theorem right_mem_Icc : b ∈ Icc a b ↔ a ≤ b := by simp only [mem_Icc, and_true, le_rfl] theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b := by simp only [mem_Ioc, and_true, le_rfl] theorem left_not_mem_Ioc : a ∉ Ioc a b := fun h => lt_irrefl _ (mem_Ioc.1 h).1 theorem left_not_mem_Ioo : a ∉ Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).1 theorem right_not_mem_Ico : b ∉ Ico a b := fun h => lt_irrefl _ (mem_Ico.1 h).2 theorem right_not_mem_Ioo : b ∉ Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).2 @[gcongr] theorem Icc_subset_Icc (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊆ Icc a₂ b₂ := by simpa [← coe_subset] using Set.Icc_subset_Icc ha hb @[gcongr] theorem Ico_subset_Ico (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ico a₁ b₁ ⊆ Ico a₂ b₂ := by simpa [← coe_subset] using Set.Ico_subset_Ico ha hb @[gcongr] theorem Ioc_subset_Ioc (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ioc a₁ b₁ ⊆ Ioc a₂ b₂ := by simpa [← coe_subset] using Set.Ioc_subset_Ioc ha hb @[gcongr] theorem Ioo_subset_Ioo (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ioo a₁ b₁ ⊆ Ioo a₂ b₂ := by simpa [← coe_subset] using Set.Ioo_subset_Ioo ha hb @[gcongr] theorem Icc_subset_Icc_left (h : a₁ ≤ a₂) : Icc a₂ b ⊆ Icc a₁ b := Icc_subset_Icc h le_rfl @[gcongr] theorem Ico_subset_Ico_left (h : a₁ ≤ a₂) : Ico a₂ b ⊆ Ico a₁ b := Ico_subset_Ico h le_rfl @[gcongr] theorem Ioc_subset_Ioc_left (h : a₁ ≤ a₂) : Ioc a₂ b ⊆ Ioc a₁ b := Ioc_subset_Ioc h le_rfl @[gcongr] theorem Ioo_subset_Ioo_left (h : a₁ ≤ a₂) : Ioo a₂ b ⊆ Ioo a₁ b := Ioo_subset_Ioo h le_rfl @[gcongr] theorem Icc_subset_Icc_right (h : b₁ ≤ b₂) : Icc a b₁ ⊆ Icc a b₂ := Icc_subset_Icc le_rfl h @[gcongr] theorem Ico_subset_Ico_right (h : b₁ ≤ b₂) : Ico a b₁ ⊆ Ico a b₂ := Ico_subset_Ico le_rfl h @[gcongr] theorem Ioc_subset_Ioc_right (h : b₁ ≤ b₂) : Ioc a b₁ ⊆ Ioc a b₂ := Ioc_subset_Ioc le_rfl h @[gcongr] theorem Ioo_subset_Ioo_right (h : b₁ ≤ b₂) : Ioo a b₁ ⊆ Ioo a b₂ := Ioo_subset_Ioo le_rfl h theorem Ico_subset_Ioo_left (h : a₁ < a₂) : Ico a₂ b ⊆ Ioo a₁ b := by rw [← coe_subset, coe_Ico, coe_Ioo] exact Set.Ico_subset_Ioo_left h theorem Ioc_subset_Ioo_right (h : b₁ < b₂) : Ioc a b₁ ⊆ Ioo a b₂ := by rw [← coe_subset, coe_Ioc, coe_Ioo] exact Set.Ioc_subset_Ioo_right h theorem Icc_subset_Ico_right (h : b₁ < b₂) : Icc a b₁ ⊆ Ico a b₂ := by rw [← coe_subset, coe_Icc, coe_Ico] exact Set.Icc_subset_Ico_right h theorem Ioo_subset_Ico_self : Ioo a b ⊆ Ico a b := by rw [← coe_subset, coe_Ioo, coe_Ico] exact Set.Ioo_subset_Ico_self theorem Ioo_subset_Ioc_self : Ioo a b ⊆ Ioc a b := by rw [← coe_subset, coe_Ioo, coe_Ioc] exact Set.Ioo_subset_Ioc_self theorem Ico_subset_Icc_self : Ico a b ⊆ Icc a b := by rw [← coe_subset, coe_Ico, coe_Icc] exact Set.Ico_subset_Icc_self theorem Ioc_subset_Icc_self : Ioc a b ⊆ Icc a b := by rw [← coe_subset, coe_Ioc, coe_Icc] exact Set.Ioc_subset_Icc_self theorem Ioo_subset_Icc_self : Ioo a b ⊆ Icc a b := Ioo_subset_Ico_self.trans Ico_subset_Icc_self theorem Icc_subset_Icc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Icc a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := by rw [← coe_subset, coe_Icc, coe_Icc, Set.Icc_subset_Icc_iff h₁] theorem Icc_subset_Ioo_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ ↔ a₂ < a₁ ∧ b₁ < b₂ := by rw [← coe_subset, coe_Icc, coe_Ioo, Set.Icc_subset_Ioo_iff h₁] theorem Icc_subset_Ico_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ < b₂ := by rw [← coe_subset, coe_Icc, coe_Ico, Set.Icc_subset_Ico_iff h₁] theorem Icc_subset_Ioc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioc a₂ b₂ ↔ a₂ < a₁ ∧ b₁ ≤ b₂ := (Icc_subset_Ico_iff h₁.dual).trans and_comm --TODO: `Ico_subset_Ioo_iff`, `Ioc_subset_Ioo_iff` theorem Icc_ssubset_Icc_left (hI : a₂ ≤ b₂) (ha : a₂ < a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := by rw [← coe_ssubset, coe_Icc, coe_Icc] exact Set.Icc_ssubset_Icc_left hI ha hb theorem Icc_ssubset_Icc_right (hI : a₂ ≤ b₂) (ha : a₂ ≤ a₁) (hb : b₁ < b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := by rw [← coe_ssubset, coe_Icc, coe_Icc] exact Set.Icc_ssubset_Icc_right hI ha hb @[simp] theorem Ioc_disjoint_Ioc_of_le {d : α} (hbc : b ≤ c) : Disjoint (Ioc a b) (Ioc c d) := disjoint_left.2 fun _ h1 h2 ↦ not_and_of_not_left _ ((mem_Ioc.1 h1).2.trans hbc).not_lt (mem_Ioc.1 h2) variable (a) theorem Ico_self : Ico a a = ∅ := Ico_eq_empty <| lt_irrefl _ theorem Ioc_self : Ioc a a = ∅ := Ioc_eq_empty <| lt_irrefl _ theorem Ioo_self : Ioo a a = ∅ := Ioo_eq_empty <| lt_irrefl _ variable {a} /-- A set with upper and lower bounds in a locally finite order is a fintype -/ def _root_.Set.fintypeOfMemBounds {s : Set α} [DecidablePred (· ∈ s)] (ha : a ∈ lowerBounds s) (hb : b ∈ upperBounds s) : Fintype s := Set.fintypeSubset (Set.Icc a b) fun _ hx => ⟨ha hx, hb hx⟩ section Filter theorem Ico_filter_lt_of_le_left [DecidablePred (· < c)] (hca : c ≤ a) : {x ∈ Ico a b | x < c} = ∅ := filter_false_of_mem fun _ hx => (hca.trans (mem_Ico.1 hx).1).not_lt theorem Ico_filter_lt_of_right_le [DecidablePred (· < c)] (hbc : b ≤ c) : {x ∈ Ico a b | x < c} = Ico a b := filter_true_of_mem fun _ hx => (mem_Ico.1 hx).2.trans_le hbc theorem Ico_filter_lt_of_le_right [DecidablePred (· < c)] (hcb : c ≤ b) : {x ∈ Ico a b | x < c} = Ico a c := by ext x rw [mem_filter, mem_Ico, mem_Ico, and_right_comm] exact and_iff_left_of_imp fun h => h.2.trans_le hcb theorem Ico_filter_le_of_le_left {a b c : α} [DecidablePred (c ≤ ·)] (hca : c ≤ a) : {x ∈ Ico a b | c ≤ x} = Ico a b := filter_true_of_mem fun _ hx => hca.trans (mem_Ico.1 hx).1 theorem Ico_filter_le_of_right_le {a b : α} [DecidablePred (b ≤ ·)] : {x ∈ Ico a b | b ≤ x} = ∅ := filter_false_of_mem fun _ hx => (mem_Ico.1 hx).2.not_le theorem Ico_filter_le_of_left_le {a b c : α} [DecidablePred (c ≤ ·)] (hac : a ≤ c) : {x ∈ Ico a b | c ≤ x} = Ico c b := by ext x rw [mem_filter, mem_Ico, mem_Ico, and_comm, and_left_comm] exact and_iff_right_of_imp fun h => hac.trans h.1 theorem Icc_filter_lt_of_lt_right {a b c : α} [DecidablePred (· < c)] (h : b < c) : {x ∈ Icc a b | x < c} = Icc a b := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Icc.1 hx).2 h theorem Ioc_filter_lt_of_lt_right {a b c : α} [DecidablePred (· < c)] (h : b < c) : {x ∈ Ioc a b | x < c} = Ioc a b := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Ioc.1 hx).2 h theorem Iic_filter_lt_of_lt_right {α} [Preorder α] [LocallyFiniteOrderBot α] {a c : α} [DecidablePred (· < c)] (h : a < c) : {x ∈ Iic a | x < c} = Iic a := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Iic.1 hx) h variable (a b) [Fintype α] theorem filter_lt_lt_eq_Ioo [DecidablePred fun j => a < j ∧ j < b] : ({j | a < j ∧ j < b} : Finset _) = Ioo a b := by ext; simp theorem filter_lt_le_eq_Ioc [DecidablePred fun j => a < j ∧ j ≤ b] : ({j | a < j ∧ j ≤ b} : Finset _) = Ioc a b := by ext; simp theorem filter_le_lt_eq_Ico [DecidablePred fun j => a ≤ j ∧ j < b] : ({j | a ≤ j ∧ j < b} : Finset _) = Ico a b := by ext; simp theorem filter_le_le_eq_Icc [DecidablePred fun j => a ≤ j ∧ j ≤ b] : ({j | a ≤ j ∧ j ≤ b} : Finset _) = Icc a b := by ext; simp end Filter end LocallyFiniteOrder section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop α] @[simp] theorem Ioi_eq_empty : Ioi a = ∅ ↔ IsMax a := by rw [← coe_eq_empty, coe_Ioi, Set.Ioi_eq_empty_iff] @[simp] alias ⟨_, _root_.IsMax.finsetIoi_eq⟩ := Ioi_eq_empty @[simp] lemma Ioi_nonempty : (Ioi a).Nonempty ↔ ¬ IsMax a := by simp [nonempty_iff_ne_empty] theorem Ioi_top [OrderTop α] : Ioi (⊤ : α) = ∅ := Ioi_eq_empty.mpr isMax_top @[simp] theorem Ici_bot [OrderBot α] [Fintype α] : Ici (⊥ : α) = univ := by ext a; simp only [mem_Ici, bot_le, mem_univ] @[simp, aesop safe apply (rule_sets := [finsetNonempty])] lemma nonempty_Ici : (Ici a).Nonempty := ⟨a, mem_Ici.2 le_rfl⟩ lemma nonempty_Ioi : (Ioi a).Nonempty ↔ ¬ IsMax a := by simp [Finset.Nonempty] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Ioi_of_not_isMax⟩ := nonempty_Ioi @[simp] theorem Ici_subset_Ici : Ici a ⊆ Ici b ↔ b ≤ a := by simp [← coe_subset] @[gcongr] alias ⟨_, _root_.GCongr.Finset.Ici_subset_Ici⟩ := Ici_subset_Ici @[simp] theorem Ici_ssubset_Ici : Ici a ⊂ Ici b ↔ b < a := by simp [← coe_ssubset] @[gcongr] alias ⟨_, _root_.GCongr.Finset.Ici_ssubset_Ici⟩ := Ici_ssubset_Ici @[gcongr] theorem Ioi_subset_Ioi (h : a ≤ b) : Ioi b ⊆ Ioi a := by simpa [← coe_subset] using Set.Ioi_subset_Ioi h @[gcongr] theorem Ioi_ssubset_Ioi (h : a < b) : Ioi b ⊂ Ioi a := by simpa [← coe_ssubset] using Set.Ioi_ssubset_Ioi h variable [LocallyFiniteOrder α] theorem Icc_subset_Ici_self : Icc a b ⊆ Ici a := by simpa [← coe_subset] using Set.Icc_subset_Ici_self theorem Ico_subset_Ici_self : Ico a b ⊆ Ici a := by simpa [← coe_subset] using Set.Ico_subset_Ici_self theorem Ioc_subset_Ioi_self : Ioc a b ⊆ Ioi a := by simpa [← coe_subset] using Set.Ioc_subset_Ioi_self theorem Ioo_subset_Ioi_self : Ioo a b ⊆ Ioi a := by simpa [← coe_subset] using Set.Ioo_subset_Ioi_self theorem Ioc_subset_Ici_self : Ioc a b ⊆ Ici a := Ioc_subset_Icc_self.trans Icc_subset_Ici_self theorem Ioo_subset_Ici_self : Ioo a b ⊆ Ici a := Ioo_subset_Ico_self.trans Ico_subset_Ici_self end LocallyFiniteOrderTop section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot α] @[simp] theorem Iio_eq_empty : Iio a = ∅ ↔ IsMin a := Ioi_eq_empty (α := αᵒᵈ) @[simp] alias ⟨_, _root_.IsMin.finsetIio_eq⟩ := Iio_eq_empty @[simp] lemma Iio_nonempty : (Iio a).Nonempty ↔ ¬ IsMin a := by simp [nonempty_iff_ne_empty] theorem Iio_bot [OrderBot α] : Iio (⊥ : α) = ∅ := Iio_eq_empty.mpr isMin_bot @[simp] theorem Iic_top [OrderTop α] [Fintype α] : Iic (⊤ : α) = univ := by ext a; simp only [mem_Iic, le_top, mem_univ] @[simp, aesop safe apply (rule_sets := [finsetNonempty])] lemma nonempty_Iic : (Iic a).Nonempty := ⟨a, mem_Iic.2 le_rfl⟩ lemma nonempty_Iio : (Iio a).Nonempty ↔ ¬ IsMin a := by simp [Finset.Nonempty] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Iio_of_not_isMin⟩ := nonempty_Iio @[simp] theorem Iic_subset_Iic : Iic a ⊆ Iic b ↔ a ≤ b := by simp [← coe_subset] @[gcongr] alias ⟨_, _root_.GCongr.Finset.Iic_subset_Iic⟩ := Iic_subset_Iic @[simp] theorem Iic_ssubset_Iic : Iic a ⊂ Iic b ↔ a < b := by simp [← coe_ssubset] @[gcongr] alias ⟨_, _root_.GCongr.Finset.Iic_ssubset_Iic⟩ := Iic_ssubset_Iic @[gcongr] theorem Iio_subset_Iio (h : a ≤ b) : Iio a ⊆ Iio b := by simpa [← coe_subset] using Set.Iio_subset_Iio h @[gcongr] theorem Iio_ssubset_Iio (h : a < b) : Iio a ⊂ Iio b := by simpa [← coe_ssubset] using Set.Iio_ssubset_Iio h variable [LocallyFiniteOrder α] theorem Icc_subset_Iic_self : Icc a b ⊆ Iic b := by simpa [← coe_subset] using Set.Icc_subset_Iic_self theorem Ioc_subset_Iic_self : Ioc a b ⊆ Iic b := by simpa [← coe_subset] using Set.Ioc_subset_Iic_self theorem Ico_subset_Iio_self : Ico a b ⊆ Iio b := by simpa [← coe_subset] using Set.Ico_subset_Iio_self theorem Ioo_subset_Iio_self : Ioo a b ⊆ Iio b := by simpa [← coe_subset] using Set.Ioo_subset_Iio_self theorem Ico_subset_Iic_self : Ico a b ⊆ Iic b := Ico_subset_Icc_self.trans Icc_subset_Iic_self theorem Ioo_subset_Iic_self : Ioo a b ⊆ Iic b := Ioo_subset_Ioc_self.trans Ioc_subset_Iic_self theorem Iic_disjoint_Ioc (h : a ≤ b) : Disjoint (Iic a) (Ioc b c) := disjoint_left.2 fun _ hax hbcx ↦ (mem_Iic.1 hax).not_lt <| lt_of_le_of_lt h (mem_Ioc.1 hbcx).1 /-- An equivalence between `Finset.Iic a` and `Set.Iic a`. -/ def _root_.Equiv.IicFinsetSet (a : α) : Iic a ≃ Set.Iic a where toFun b := ⟨b.1, coe_Iic a ▸ mem_coe.2 b.2⟩ invFun b := ⟨b.1, by rw [← mem_coe, coe_Iic a]; exact b.2⟩ left_inv := fun _ ↦ rfl right_inv := fun _ ↦ rfl end LocallyFiniteOrderBot section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop α] {a : α} theorem Ioi_subset_Ici_self : Ioi a ⊆ Ici a := by simpa [← coe_subset] using Set.Ioi_subset_Ici_self theorem _root_.BddBelow.finite {s : Set α} (hs : BddBelow s) : s.Finite := let ⟨a, ha⟩ := hs (Ici a).finite_toSet.subset fun _ hx => mem_Ici.2 <| ha hx theorem _root_.Set.Infinite.not_bddBelow {s : Set α} : s.Infinite → ¬BddBelow s := mt BddBelow.finite variable [Fintype α] theorem filter_lt_eq_Ioi [DecidablePred (a < ·)] : ({x | a < x} : Finset _) = Ioi a := by ext; simp theorem filter_le_eq_Ici [DecidablePred (a ≤ ·)] : ({x | a ≤ x} : Finset _) = Ici a := by ext; simp end LocallyFiniteOrderTop section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot α] {a : α} theorem Iio_subset_Iic_self : Iio a ⊆ Iic a := by simpa [← coe_subset] using Set.Iio_subset_Iic_self theorem _root_.BddAbove.finite {s : Set α} (hs : BddAbove s) : s.Finite := hs.dual.finite theorem _root_.Set.Infinite.not_bddAbove {s : Set α} : s.Infinite → ¬BddAbove s := mt BddAbove.finite variable [Fintype α] theorem filter_gt_eq_Iio [DecidablePred (· < a)] : ({x | x < a} : Finset _) = Iio a := by ext; simp theorem filter_ge_eq_Iic [DecidablePred (· ≤ a)] : ({x | x ≤ a} : Finset _) = Iic a := by ext; simp end LocallyFiniteOrderBot section LocallyFiniteOrder variable [LocallyFiniteOrder α] @[simp] theorem Icc_bot [OrderBot α] : Icc (⊥ : α) a = Iic a := rfl @[simp] theorem Icc_top [OrderTop α] : Icc a (⊤ : α) = Ici a := rfl @[simp] theorem Ico_bot [OrderBot α] : Ico (⊥ : α) a = Iio a := rfl @[simp] theorem Ioc_top [OrderTop α] : Ioc a (⊤ : α) = Ioi a := rfl theorem Icc_bot_top [BoundedOrder α] [Fintype α] : Icc (⊥ : α) (⊤ : α) = univ := by rw [Icc_bot, Iic_top] end LocallyFiniteOrder variable [LocallyFiniteOrderTop α] [LocallyFiniteOrderBot α] theorem disjoint_Ioi_Iio (a : α) : Disjoint (Ioi a) (Iio a) := disjoint_left.2 fun _ hab hba => (mem_Ioi.1 hab).not_lt <| mem_Iio.1 hba end Preorder section PartialOrder variable [PartialOrder α] [LocallyFiniteOrder α] {a b c : α} @[simp] theorem Icc_self (a : α) : Icc a a = {a} := by rw [← coe_eq_singleton, coe_Icc, Set.Icc_self] @[simp] theorem Icc_eq_singleton_iff : Icc a b = {c} ↔ a = c ∧ b = c := by rw [← coe_eq_singleton, coe_Icc, Set.Icc_eq_singleton_iff] theorem Ico_disjoint_Ico_consecutive (a b c : α) : Disjoint (Ico a b) (Ico b c) := disjoint_left.2 fun _ hab hbc => (mem_Ico.mp hab).2.not_le (mem_Ico.mp hbc).1 @[simp] theorem Ici_top [OrderTop α] : Ici (⊤ : α) = {⊤} := Icc_eq_singleton_iff.2 ⟨rfl, rfl⟩ @[simp] theorem Iic_bot [OrderBot α] : Iic (⊥ : α) = {⊥} := Icc_eq_singleton_iff.2 ⟨rfl, rfl⟩ section DecidableEq variable [DecidableEq α] @[simp] theorem Icc_erase_left (a b : α) : (Icc a b).erase a = Ioc a b := by simp [← coe_inj] @[simp] theorem Icc_erase_right (a b : α) : (Icc a b).erase b = Ico a b := by simp [← coe_inj] @[simp] theorem Ico_erase_left (a b : α) : (Ico a b).erase a = Ioo a b := by simp [← coe_inj]
@[simp]
Mathlib/Order/Interval/Finset/Basic.lean
572
572
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, Kim Morrison -/ import Mathlib.CategoryTheory.Subobject.MonoOver import Mathlib.CategoryTheory.Skeletal import Mathlib.CategoryTheory.ConcreteCategory.Basic import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq import Mathlib.Tactic.ApplyFun import Mathlib.Tactic.CategoryTheory.Elementwise /-! # Subobjects We define `Subobject X` as the quotient (by isomorphisms) of `MonoOver X := {f : Over X // Mono f.hom}`. Here `MonoOver X` is a thin category (a pair of objects has at most one morphism between them), so we can think of it as a preorder. However as it is not skeletal, it is not a partial order. There is a coercion from `Subobject X` back to the ambient category `C` (using choice to pick a representative), and for `P : Subobject X`, `P.arrow : (P : C) ⟶ X` is the inclusion morphism. We provide * `def pullback [HasPullbacks C] (f : X ⟶ Y) : Subobject Y ⥤ Subobject X` * `def map (f : X ⟶ Y) [Mono f] : Subobject X ⥤ Subobject Y` * `def «exists_» [HasImages C] (f : X ⟶ Y) : Subobject X ⥤ Subobject Y` and prove their basic properties and relationships. These are all easy consequences of the earlier development of the corresponding functors for `MonoOver`. The subobjects of `X` form a preorder making them into a category. We have `X ≤ Y` if and only if `X.arrow` factors through `Y.arrow`: see `ofLE`/`ofLEMk`/`ofMkLE`/`ofMkLEMk` and `le_of_comm`. Similarly, to show that two subobjects are equal, we can supply an isomorphism between the underlying objects that commutes with the arrows (`eq_of_comm`). See also * `CategoryTheory.Subobject.factorThru` : an API describing factorization of morphisms through subobjects. * `CategoryTheory.Subobject.lattice` : the lattice structures on subobjects. ## Notes This development originally appeared in Bhavik Mehta's "Topos theory for Lean" repository, and was ported to mathlib by Kim Morrison. ### Implementation note Currently we describe `pullback`, `map`, etc., as functors. It may be better to just say that they are monotone functions, and even avoid using categorical language entirely when describing `Subobject X`. (It's worth keeping this in mind in future use; it should be a relatively easy change here if it looks preferable.) ### Relation to pseudoelements There is a separate development of pseudoelements in `CategoryTheory.Abelian.Pseudoelements`, as a quotient (but not by isomorphism) of `Over X`. When a morphism `f` has an image, the image represents the same pseudoelement. In a category with images `Pseudoelements X` could be constructed as a quotient of `MonoOver X`. In fact, in an abelian category (I'm not sure in what generality beyond that), `Pseudoelements X` agrees with `Subobject X`, but we haven't developed this in mathlib yet. -/ universe v₁ v₂ u₁ u₂ noncomputable section namespace CategoryTheory open CategoryTheory CategoryTheory.Category CategoryTheory.Limits variable {C : Type u₁} [Category.{v₁} C] {X Y Z : C} variable {D : Type u₂} [Category.{v₂} D] /-! We now construct the subobject lattice for `X : C`, as the quotient by isomorphisms of `MonoOver X`. Since `MonoOver X` is a thin category, we use `ThinSkeleton` to take the quotient. Essentially all the structure defined above on `MonoOver X` descends to `Subobject X`, with morphisms becoming inequalities, and isomorphisms becoming equations. -/ /-- The category of subobjects of `X : C`, defined as isomorphism classes of monomorphisms into `X`. -/ def Subobject (X : C) := ThinSkeleton (MonoOver X) instance (X : C) : PartialOrder (Subobject X) := inferInstanceAs <| PartialOrder (ThinSkeleton (MonoOver X)) namespace Subobject -- Porting note: made it a def rather than an abbreviation -- because Lean would make it too transparent /-- Convenience constructor for a subobject. -/ def mk {X A : C} (f : A ⟶ X) [Mono f] : Subobject X := (toThinSkeleton _).obj (MonoOver.mk' f) section attribute [local ext] CategoryTheory.Comma protected theorem ind {X : C} (p : Subobject X → Prop) (h : ∀ ⦃A : C⦄ (f : A ⟶ X) [Mono f], p (Subobject.mk f)) (P : Subobject X) : p P := by apply Quotient.inductionOn' intro a exact h a.arrow protected theorem ind₂ {X : C} (p : Subobject X → Subobject X → Prop) (h : ∀ ⦃A B : C⦄ (f : A ⟶ X) (g : B ⟶ X) [Mono f] [Mono g], p (Subobject.mk f) (Subobject.mk g)) (P Q : Subobject X) : p P Q := by apply Quotient.inductionOn₂' intro a b exact h a.arrow b.arrow end /-- Declare a function on subobjects of `X` by specifying a function on monomorphisms with codomain `X`. -/ protected def lift {α : Sort*} {X : C} (F : ∀ ⦃A : C⦄ (f : A ⟶ X) [Mono f], α) (h : ∀ ⦃A B : C⦄ (f : A ⟶ X) (g : B ⟶ X) [Mono f] [Mono g] (i : A ≅ B), i.hom ≫ g = f → F f = F g) : Subobject X → α := fun P => Quotient.liftOn' P (fun m => F m.arrow) fun m n ⟨i⟩ => h m.arrow n.arrow ((MonoOver.forget X ⋙ Over.forget X).mapIso i) (Over.w i.hom) @[simp] protected theorem lift_mk {α : Sort*} {X : C} (F : ∀ ⦃A : C⦄ (f : A ⟶ X) [Mono f], α) {h A} (f : A ⟶ X) [Mono f] : Subobject.lift F h (Subobject.mk f) = F f := rfl /-- The category of subobjects is equivalent to the `MonoOver` category. It is more convenient to use the former due to the partial order instance, but oftentimes it is easier to define structures on the latter. -/ noncomputable def equivMonoOver (X : C) : Subobject X ≌ MonoOver X := ThinSkeleton.equivalence _ /-- Use choice to pick a representative `MonoOver X` for each `Subobject X`. -/ noncomputable def representative {X : C} : Subobject X ⥤ MonoOver X := (equivMonoOver X).functor instance : (representative (X := X)).IsEquivalence := (equivMonoOver X).isEquivalence_functor /-- Starting with `A : MonoOver X`, we can take its equivalence class in `Subobject X` then pick an arbitrary representative using `representative.obj`. This is isomorphic (in `MonoOver X`) to the original `A`. -/ noncomputable def representativeIso {X : C} (A : MonoOver X) : representative.obj ((toThinSkeleton _).obj A) ≅ A := (equivMonoOver X).counitIso.app A /-- Use choice to pick a representative underlying object in `C` for any `Subobject X`. Prefer to use the coercion `P : C` rather than explicitly writing `underlying.obj P`. -/ noncomputable def underlying {X : C} : Subobject X ⥤ C := representative ⋙ MonoOver.forget _ ⋙ Over.forget _ instance : CoeOut (Subobject X) C where coe Y := underlying.obj Y -- Porting note: removed as it has become a syntactic tautology -- @[simp] -- theorem underlying_as_coe {X : C} (P : Subobject X) : underlying.obj P = P := -- rfl /-- If we construct a `Subobject Y` from an explicit `f : X ⟶ Y` with `[Mono f]`, then pick an arbitrary choice of underlying object `(Subobject.mk f : C)` back in `C`, it is isomorphic (in `C`) to the original `X`. -/ noncomputable def underlyingIso {X Y : C} (f : X ⟶ Y) [Mono f] : (Subobject.mk f : C) ≅ X := (MonoOver.forget _ ⋙ Over.forget _).mapIso (representativeIso (MonoOver.mk' f)) /-- The morphism in `C` from the arbitrarily chosen underlying object to the ambient object. -/ noncomputable def arrow {X : C} (Y : Subobject X) : (Y : C) ⟶ X := (representative.obj Y).obj.hom instance arrow_mono {X : C} (Y : Subobject X) : Mono Y.arrow := (representative.obj Y).property @[simp] theorem arrow_congr {A : C} (X Y : Subobject A) (h : X = Y) : eqToHom (congr_arg (fun X : Subobject A => (X : C)) h) ≫ Y.arrow = X.arrow := by induction h simp @[simp] theorem representative_coe (Y : Subobject X) : (representative.obj Y : C) = (Y : C) := rfl @[simp] theorem representative_arrow (Y : Subobject X) : (representative.obj Y).arrow = Y.arrow := rfl @[reassoc (attr := simp)] theorem underlying_arrow {X : C} {Y Z : Subobject X} (f : Y ⟶ Z) : underlying.map f ≫ arrow Z = arrow Y := Over.w (representative.map f) @[reassoc (attr := simp), elementwise (attr := simp)] theorem underlyingIso_arrow {X Y : C} (f : X ⟶ Y) [Mono f] : (underlyingIso f).inv ≫ (Subobject.mk f).arrow = f := Over.w _ @[reassoc (attr := simp)] theorem underlyingIso_hom_comp_eq_mk {X Y : C} (f : X ⟶ Y) [Mono f] : (underlyingIso f).hom ≫ f = (mk f).arrow := (Iso.eq_inv_comp _).1 (underlyingIso_arrow f).symm /-- Two morphisms into a subobject are equal exactly if the morphisms into the ambient object are equal -/ @[ext] theorem eq_of_comp_arrow_eq {X Y : C} {P : Subobject Y} {f g : X ⟶ P} (h : f ≫ P.arrow = g ≫ P.arrow) : f = g := (cancel_mono P.arrow).mp h theorem mk_le_mk_of_comm {B A₁ A₂ : C} {f₁ : A₁ ⟶ B} {f₂ : A₂ ⟶ B} [Mono f₁] [Mono f₂] (g : A₁ ⟶ A₂) (w : g ≫ f₂ = f₁) : mk f₁ ≤ mk f₂ := ⟨MonoOver.homMk _ w⟩ @[simp] theorem mk_arrow (P : Subobject X) : mk P.arrow = P := Quotient.inductionOn' P fun Q => by obtain ⟨e⟩ := @Quotient.mk_out' _ (isIsomorphicSetoid _) Q exact Quotient.sound' ⟨MonoOver.isoMk (Iso.refl _) ≪≫ e⟩ theorem le_of_comm {B : C} {X Y : Subobject B} (f : (X : C) ⟶ (Y : C)) (w : f ≫ Y.arrow = X.arrow) : X ≤ Y := by convert mk_le_mk_of_comm _ w <;> simp theorem le_mk_of_comm {B A : C} {X : Subobject B} {f : A ⟶ B} [Mono f] (g : (X : C) ⟶ A) (w : g ≫ f = X.arrow) : X ≤ mk f := le_of_comm (g ≫ (underlyingIso f).inv) <| by simp [w] theorem mk_le_of_comm {B A : C} {X : Subobject B} {f : A ⟶ B} [Mono f] (g : A ⟶ (X : C)) (w : g ≫ X.arrow = f) : mk f ≤ X := le_of_comm ((underlyingIso f).hom ≫ g) <| by simp [w] /-- To show that two subobjects are equal, it suffices to exhibit an isomorphism commuting with the arrows. -/ @[ext (iff := false)] theorem eq_of_comm {B : C} {X Y : Subobject B} (f : (X : C) ≅ (Y : C)) (w : f.hom ≫ Y.arrow = X.arrow) : X = Y := le_antisymm (le_of_comm f.hom w) <| le_of_comm f.inv <| f.inv_comp_eq.2 w.symm /-- To show that two subobjects are equal, it suffices to exhibit an isomorphism commuting with the arrows. -/ theorem eq_mk_of_comm {B A : C} {X : Subobject B} (f : A ⟶ B) [Mono f] (i : (X : C) ≅ A) (w : i.hom ≫ f = X.arrow) : X = mk f := eq_of_comm (i.trans (underlyingIso f).symm) <| by simp [w] /-- To show that two subobjects are equal, it suffices to exhibit an isomorphism commuting with the arrows. -/ theorem mk_eq_of_comm {B A : C} {X : Subobject B} (f : A ⟶ B) [Mono f] (i : A ≅ (X : C)) (w : i.hom ≫ X.arrow = f) : mk f = X := Eq.symm <| eq_mk_of_comm _ i.symm <| by rw [Iso.symm_hom, Iso.inv_comp_eq, w] /-- To show that two subobjects are equal, it suffices to exhibit an isomorphism commuting with the arrows. -/ theorem mk_eq_mk_of_comm {B A₁ A₂ : C} (f : A₁ ⟶ B) (g : A₂ ⟶ B) [Mono f] [Mono g] (i : A₁ ≅ A₂) (w : i.hom ≫ g = f) : mk f = mk g := eq_mk_of_comm _ ((underlyingIso f).trans i) <| by simp [w] lemma mk_surjective {X : C} (S : Subobject X) : ∃ (A : C) (i : A ⟶ X) (_ : Mono i), S = Subobject.mk i := ⟨_, S.arrow, inferInstance, by simp⟩ -- We make `X` and `Y` explicit arguments here so that when `ofLE` appears in goal statements -- it is possible to see its source and target -- (`h` will just display as `_`, because it is in `Prop`). /-- An inequality of subobjects is witnessed by some morphism between the corresponding objects. -/ def ofLE {B : C} (X Y : Subobject B) (h : X ≤ Y) : (X : C) ⟶ (Y : C) := underlying.map <| h.hom @[reassoc (attr := simp)] theorem ofLE_arrow {B : C} {X Y : Subobject B} (h : X ≤ Y) : ofLE X Y h ≫ Y.arrow = X.arrow := underlying_arrow _ instance {B : C} (X Y : Subobject B) (h : X ≤ Y) : Mono (ofLE X Y h) := by fconstructor intro Z f g w replace w := w =≫ Y.arrow ext simpa using w theorem ofLE_mk_le_mk_of_comm {B A₁ A₂ : C} {f₁ : A₁ ⟶ B} {f₂ : A₂ ⟶ B} [Mono f₁] [Mono f₂] (g : A₁ ⟶ A₂) (w : g ≫ f₂ = f₁) : ofLE _ _ (mk_le_mk_of_comm g w) = (underlyingIso _).hom ≫ g ≫ (underlyingIso _).inv := by ext simp [w] /-- An inequality of subobjects is witnessed by some morphism between the corresponding objects. -/ def ofLEMk {B A : C} (X : Subobject B) (f : A ⟶ B) [Mono f] (h : X ≤ mk f) : (X : C) ⟶ A := ofLE X (mk f) h ≫ (underlyingIso f).hom instance {B A : C} (X : Subobject B) (f : A ⟶ B) [Mono f] (h : X ≤ mk f) : Mono (ofLEMk X f h) := by dsimp only [ofLEMk] infer_instance @[simp] theorem ofLEMk_comp {B A : C} {X : Subobject B} {f : A ⟶ B} [Mono f] (h : X ≤ mk f) : ofLEMk X f h ≫ f = X.arrow := by simp [ofLEMk] /-- An inequality of subobjects is witnessed by some morphism between the corresponding objects. -/ def ofMkLE {B A : C} (f : A ⟶ B) [Mono f] (X : Subobject B) (h : mk f ≤ X) : A ⟶ (X : C) := (underlyingIso f).inv ≫ ofLE (mk f) X h instance {B A : C} (f : A ⟶ B) [Mono f] (X : Subobject B) (h : mk f ≤ X) : Mono (ofMkLE f X h) := by dsimp only [ofMkLE] infer_instance @[simp] theorem ofMkLE_arrow {B A : C} {f : A ⟶ B} [Mono f] {X : Subobject B} (h : mk f ≤ X) : ofMkLE f X h ≫ X.arrow = f := by simp [ofMkLE] /-- An inequality of subobjects is witnessed by some morphism between the corresponding objects. -/ def ofMkLEMk {B A₁ A₂ : C} (f : A₁ ⟶ B) (g : A₂ ⟶ B) [Mono f] [Mono g] (h : mk f ≤ mk g) : A₁ ⟶ A₂ := (underlyingIso f).inv ≫ ofLE (mk f) (mk g) h ≫ (underlyingIso g).hom instance {B A₁ A₂ : C} (f : A₁ ⟶ B) (g : A₂ ⟶ B) [Mono f] [Mono g] (h : mk f ≤ mk g) : Mono (ofMkLEMk f g h) := by dsimp only [ofMkLEMk] infer_instance @[simp] theorem ofMkLEMk_comp {B A₁ A₂ : C} {f : A₁ ⟶ B} {g : A₂ ⟶ B} [Mono f] [Mono g] (h : mk f ≤ mk g) : ofMkLEMk f g h ≫ g = f := by simp [ofMkLEMk] @[reassoc (attr := simp)] theorem ofLE_comp_ofLE {B : C} (X Y Z : Subobject B) (h₁ : X ≤ Y) (h₂ : Y ≤ Z) : ofLE X Y h₁ ≫ ofLE Y Z h₂ = ofLE X Z (h₁.trans h₂) := by simp only [ofLE, ← Functor.map_comp underlying] congr 1 @[reassoc (attr := simp)] theorem ofLE_comp_ofLEMk {B A : C} (X Y : Subobject B) (f : A ⟶ B) [Mono f] (h₁ : X ≤ Y) (h₂ : Y ≤ mk f) : ofLE X Y h₁ ≫ ofLEMk Y f h₂ = ofLEMk X f (h₁.trans h₂) := by simp only [ofMkLE, ofLEMk, ofLE, ← Functor.map_comp_assoc underlying] congr 1 @[reassoc (attr := simp)] theorem ofLEMk_comp_ofMkLE {B A : C} (X : Subobject B) (f : A ⟶ B) [Mono f] (Y : Subobject B) (h₁ : X ≤ mk f) (h₂ : mk f ≤ Y) : ofLEMk X f h₁ ≫ ofMkLE f Y h₂ = ofLE X Y (h₁.trans h₂) := by simp only [ofMkLE, ofLEMk, ofLE, ← Functor.map_comp underlying, assoc, Iso.hom_inv_id_assoc] congr 1 @[reassoc (attr := simp)] theorem ofLEMk_comp_ofMkLEMk {B A₁ A₂ : C} (X : Subobject B) (f : A₁ ⟶ B) [Mono f] (g : A₂ ⟶ B) [Mono g] (h₁ : X ≤ mk f) (h₂ : mk f ≤ mk g) : ofLEMk X f h₁ ≫ ofMkLEMk f g h₂ = ofLEMk X g (h₁.trans h₂) := by simp only [ofMkLE, ofLEMk, ofLE, ofMkLEMk, ← Functor.map_comp_assoc underlying, assoc, Iso.hom_inv_id_assoc] congr 1 @[reassoc (attr := simp)] theorem ofMkLE_comp_ofLE {B A₁ : C} (f : A₁ ⟶ B) [Mono f] (X Y : Subobject B) (h₁ : mk f ≤ X) (h₂ : X ≤ Y) : ofMkLE f X h₁ ≫ ofLE X Y h₂ = ofMkLE f Y (h₁.trans h₂) := by simp only [ofMkLE, ofLEMk, ofLE, ofMkLEMk, ← Functor.map_comp underlying, assoc] congr 1 @[reassoc (attr := simp)] theorem ofMkLE_comp_ofLEMk {B A₁ A₂ : C} (f : A₁ ⟶ B) [Mono f] (X : Subobject B) (g : A₂ ⟶ B) [Mono g] (h₁ : mk f ≤ X) (h₂ : X ≤ mk g) : ofMkLE f X h₁ ≫ ofLEMk X g h₂ = ofMkLEMk f g (h₁.trans h₂) := by simp only [ofMkLE, ofLEMk, ofLE, ofMkLEMk, ← Functor.map_comp_assoc underlying, assoc] congr 1 @[reassoc (attr := simp)] theorem ofMkLEMk_comp_ofMkLE {B A₁ A₂ : C} (f : A₁ ⟶ B) [Mono f] (g : A₂ ⟶ B) [Mono g] (X : Subobject B) (h₁ : mk f ≤ mk g) (h₂ : mk g ≤ X) : ofMkLEMk f g h₁ ≫ ofMkLE g X h₂ = ofMkLE f X (h₁.trans h₂) := by simp only [ofMkLE, ofLEMk, ofLE, ofMkLEMk, ← Functor.map_comp underlying, assoc, Iso.hom_inv_id_assoc] congr 1 @[reassoc (attr := simp)] theorem ofMkLEMk_comp_ofMkLEMk {B A₁ A₂ A₃ : C} (f : A₁ ⟶ B) [Mono f] (g : A₂ ⟶ B) [Mono g] (h : A₃ ⟶ B) [Mono h] (h₁ : mk f ≤ mk g) (h₂ : mk g ≤ mk h) : ofMkLEMk f g h₁ ≫ ofMkLEMk g h h₂ = ofMkLEMk f h (h₁.trans h₂) := by simp only [ofMkLE, ofLEMk, ofLE, ofMkLEMk, ← Functor.map_comp_assoc underlying, assoc, Iso.hom_inv_id_assoc] congr 1 @[simp] theorem ofLE_refl {B : C} (X : Subobject B) : ofLE X X le_rfl = 𝟙 _ := by apply (cancel_mono X.arrow).mp simp @[simp] theorem ofMkLEMk_refl {B A₁ : C} (f : A₁ ⟶ B) [Mono f] : ofMkLEMk f f le_rfl = 𝟙 _ := by apply (cancel_mono f).mp simp -- As with `ofLE`, we have `X` and `Y` as explicit arguments for readability. /-- An equality of subobjects gives an isomorphism of the corresponding objects. (One could use `underlying.mapIso (eqToIso h))` here, but this is more readable.) -/ @[simps] def isoOfEq {B : C} (X Y : Subobject B) (h : X = Y) : (X : C) ≅ (Y : C) where hom := ofLE _ _ h.le inv := ofLE _ _ h.ge /-- An equality of subobjects gives an isomorphism of the corresponding objects. -/ @[simps] def isoOfEqMk {B A : C} (X : Subobject B) (f : A ⟶ B) [Mono f] (h : X = mk f) : (X : C) ≅ A where hom := ofLEMk X f h.le inv := ofMkLE f X h.ge /-- An equality of subobjects gives an isomorphism of the corresponding objects. -/ @[simps] def isoOfMkEq {B A : C} (f : A ⟶ B) [Mono f] (X : Subobject B) (h : mk f = X) : A ≅ (X : C) where hom := ofMkLE f X h.le inv := ofLEMk X f h.ge /-- An equality of subobjects gives an isomorphism of the corresponding objects. -/ @[simps] def isoOfMkEqMk {B A₁ A₂ : C} (f : A₁ ⟶ B) (g : A₂ ⟶ B) [Mono f] [Mono g] (h : mk f = mk g) : A₁ ≅ A₂ where hom := ofMkLEMk f g h.le inv := ofMkLEMk g f h.ge lemma mk_lt_mk_of_comm {X A₁ A₂ : C} {i₁ : A₁ ⟶ X} {i₂ : A₂ ⟶ X} [Mono i₁] [Mono i₂] (f : A₁ ⟶ A₂) (fac : f ≫ i₂ = i₁) (hf : ¬ IsIso f) : Subobject.mk i₁ < Subobject.mk i₂ := by obtain _ | h := (mk_le_mk_of_comm _ fac).lt_or_eq · assumption · exfalso apply hf convert (isoOfMkEqMk i₁ i₂ h).isIso_hom rw [← cancel_mono i₂, isoOfMkEqMk_hom, ofMkLEMk_comp, fac] lemma mk_lt_mk_iff_of_comm {X A₁ A₂ : C} {i₁ : A₁ ⟶ X} {i₂ : A₂ ⟶ X} [Mono i₁] [Mono i₂] (f : A₁ ⟶ A₂) (fac : f ≫ i₂ = i₁) : Subobject.mk i₁ < Subobject.mk i₂ ↔ ¬ IsIso f := ⟨fun h hf ↦ by simp only [mk_eq_mk_of_comm i₁ i₂ (asIso f) fac, lt_self_iff_false] at h, mk_lt_mk_of_comm f fac⟩ end Subobject namespace MonoOver variable {P Q : MonoOver X} (f : P ⟶ Q) include f in lemma subobjectMk_le_mk_of_hom : Subobject.mk P.obj.hom ≤ Subobject.mk Q.obj.hom := Subobject.mk_le_mk_of_comm f.left (by simp) lemma isIso_left_iff_subobjectMk_eq : IsIso f.left ↔ Subobject.mk P.1.hom = Subobject.mk Q.1.hom := ⟨fun _ ↦ Subobject.mk_eq_mk_of_comm _ _ (asIso f.left) (by simp), fun h ↦ ⟨Subobject.ofMkLEMk _ _ h.symm.le, by simp [← cancel_mono P.1.hom], by simp [← cancel_mono Q.1.hom]⟩⟩ lemma isIso_iff_subobjectMk_eq : IsIso f ↔ Subobject.mk P.1.hom = Subobject.mk Q.1.hom := by rw [isIso_iff_isIso_left, isIso_left_iff_subobjectMk_eq] end MonoOver open CategoryTheory.Limits namespace Subobject /-- Any functor `MonoOver X ⥤ MonoOver Y` descends to a functor `Subobject X ⥤ Subobject Y`, because `MonoOver Y` is thin. -/ def lower {Y : D} (F : MonoOver X ⥤ MonoOver Y) : Subobject X ⥤ Subobject Y := ThinSkeleton.map F /-- Isomorphic functors become equal when lowered to `Subobject`. (It's not as evil as usual to talk about equality between functors because the categories are thin and skeletal.) -/ theorem lower_iso (F₁ F₂ : MonoOver X ⥤ MonoOver Y) (h : F₁ ≅ F₂) : lower F₁ = lower F₂ := ThinSkeleton.map_iso_eq h /-- A ternary version of `Subobject.lower`. -/ def lower₂ (F : MonoOver X ⥤ MonoOver Y ⥤ MonoOver Z) : Subobject X ⥤ Subobject Y ⥤ Subobject Z := ThinSkeleton.map₂ F @[simp] theorem lower_comm (F : MonoOver Y ⥤ MonoOver X) : toThinSkeleton _ ⋙ lower F = F ⋙ toThinSkeleton _ := rfl /-- An adjunction between `MonoOver A` and `MonoOver B` gives an adjunction between `Subobject A` and `Subobject B`. -/ def lowerAdjunction {A : C} {B : D} {L : MonoOver A ⥤ MonoOver B} {R : MonoOver B ⥤ MonoOver A} (h : L ⊣ R) : lower L ⊣ lower R := ThinSkeleton.lowerAdjunction _ _ h /-- An equivalence between `MonoOver A` and `MonoOver B` gives an equivalence between `Subobject A` and `Subobject B`. -/ @[simps] def lowerEquivalence {A : C} {B : D} (e : MonoOver A ≌ MonoOver B) : Subobject A ≌ Subobject B where functor := lower e.functor inverse := lower e.inverse unitIso := by apply eqToIso convert ThinSkeleton.map_iso_eq e.unitIso · exact ThinSkeleton.map_id_eq.symm · exact (ThinSkeleton.map_comp_eq _ _).symm counitIso := by apply eqToIso convert ThinSkeleton.map_iso_eq e.counitIso · exact (ThinSkeleton.map_comp_eq _ _).symm · exact ThinSkeleton.map_id_eq.symm section Pullback variable [HasPullbacks C] /-- When `C` has pullbacks, a morphism `f : X ⟶ Y` induces a functor `Subobject Y ⥤ Subobject X`, by pulling back a monomorphism along `f`. -/ def pullback (f : X ⟶ Y) : Subobject Y ⥤ Subobject X := lower (MonoOver.pullback f) theorem pullback_id (x : Subobject X) : (pullback (𝟙 X)).obj x = x := by induction' x using Quotient.inductionOn' with f exact Quotient.sound ⟨MonoOver.pullbackId.app f⟩ theorem pullback_comp (f : X ⟶ Y) (g : Y ⟶ Z) (x : Subobject Z) : (pullback (f ≫ g)).obj x = (pullback f).obj ((pullback g).obj x) := by induction' x using Quotient.inductionOn' with t exact Quotient.sound ⟨(MonoOver.pullbackComp _ _).app t⟩ theorem pullback_obj_mk {A B X Y : C} {f : Y ⟶ X} {i : A ⟶ X} [Mono i] {j : B ⟶ Y} [Mono j] {f' : B ⟶ A} (h : IsPullback f' j i f) : (pullback f).obj (mk i) = mk j := ((equivMonoOver Y).inverse.mapIso (MonoOver.pullbackObjIsoOfIsPullback _ _ _ _ h)).to_eq theorem pullback_obj {X Y : C} (f : Y ⟶ X) (x : Subobject X) : (pullback f).obj x = mk (pullback.snd x.arrow f) := by obtain ⟨Z, i, _, rfl⟩ := mk_surjective x rw [pullback_obj_mk (IsPullback.of_hasPullback i f)] exact mk_eq_mk_of_comm _ _ (asIso (pullback.map i f (mk i).arrow f (underlyingIso i).inv (𝟙 _) (𝟙 _) (by simp) (by simp))) (by simp) instance (f : X ⟶ Y) : (pullback f).Faithful where end Pullback section Map /-- We can map subobjects of `X` to subobjects of `Y` by post-composition with a monomorphism `f : X ⟶ Y`. -/ def map (f : X ⟶ Y) [Mono f] : Subobject X ⥤ Subobject Y := lower (MonoOver.map f) lemma map_mk {A X Y : C} (i : A ⟶ X) [Mono i] (f : X ⟶ Y) [Mono f] : (map f).obj (mk i) = mk (i ≫ f) := rfl theorem map_id (x : Subobject X) : (map (𝟙 X)).obj x = x := by induction' x using Quotient.inductionOn' with f exact Quotient.sound ⟨(MonoOver.mapId _).app f⟩ theorem map_comp (f : X ⟶ Y) (g : Y ⟶ Z) [Mono f] [Mono g] (x : Subobject X) :
(map (f ≫ g)).obj x = (map g).obj ((map f).obj x) := by induction' x using Quotient.inductionOn' with t exact Quotient.sound ⟨(MonoOver.mapComp _ _).app t⟩
Mathlib/CategoryTheory/Subobject/Basic.lean
580
582
/- 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, Kevin Buzzard, Yury Kudryashov, Frédéric Dupuis, Heather Macbeth -/ import Mathlib.Algebra.Module.Submodule.Ker import Mathlib.Algebra.Module.Submodule.RestrictScalars import Mathlib.Data.Set.Finite.Range /-! # Range of linear maps The range `LinearMap.range` of a (semi)linear map `f : M → M₂` is a submodule of `M₂`. More specifically, `LinearMap.range` applies to any `SemilinearMapClass` over a `RingHomSurjective` ring homomorphism. Note that this also means that dot notation (i.e. `f.range` for a linear map `f`) does not work. ## Notations * We continue to use the notations `M →ₛₗ[σ] M₂` and `M →ₗ[R] M₂` for the type of semilinear (resp. linear) maps from `M` to `M₂` over the ring homomorphism `σ` (resp. over the ring `R`). ## Tags linear algebra, vector space, module, range -/ open Function variable {R : Type*} {R₂ : Type*} {R₃ : Type*} variable {K : Type*} variable {M : Type*} {M₂ : Type*} {M₃ : Type*} variable {V : Type*} {V₂ : Type*} namespace LinearMap section AddCommMonoid variable [Semiring R] [Semiring R₂] [Semiring R₃] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M] [Module R₂ M₂] [Module R₃ M₃] open Submodule variable {τ₁₂ : R →+* R₂} {τ₂₃ : R₂ →+* R₃} {τ₁₃ : R →+* R₃} variable [RingHomCompTriple τ₁₂ τ₂₃ τ₁₃] section variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂] /-- The range of a linear map `f : M → M₂` is a submodule of `M₂`. See Note [range copy pattern]. -/ def range [RingHomSurjective τ₁₂] (f : F) : Submodule R₂ M₂ := (map f ⊤).copy (Set.range f) Set.image_univ.symm theorem range_coe [RingHomSurjective τ₁₂] (f : F) : (range f : Set M₂) = Set.range f := rfl theorem range_toAddSubmonoid [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : (range f).toAddSubmonoid = AddMonoidHom.mrange f := rfl @[simp] theorem mem_range [RingHomSurjective τ₁₂] {f : F} {x} : x ∈ range f ↔ ∃ y, f y = x := Iff.rfl theorem range_eq_map [RingHomSurjective τ₁₂] (f : F) : range f = map f ⊤ := by ext simp theorem mem_range_self [RingHomSurjective τ₁₂] (f : F) (x : M) : f x ∈ range f := ⟨x, rfl⟩ @[simp] theorem range_id : range (LinearMap.id : M →ₗ[R] M) = ⊤ := SetLike.coe_injective Set.range_id theorem range_comp [RingHomSurjective τ₁₂] [RingHomSurjective τ₂₃] [RingHomSurjective τ₁₃] (f : M →ₛₗ[τ₁₂] M₂) (g : M₂ →ₛₗ[τ₂₃] M₃) : range (g.comp f : M →ₛₗ[τ₁₃] M₃) = map g (range f) := SetLike.coe_injective (Set.range_comp g f) theorem range_comp_le_range [RingHomSurjective τ₂₃] [RingHomSurjective τ₁₃] (f : M →ₛₗ[τ₁₂] M₂) (g : M₂ →ₛₗ[τ₂₃] M₃) : range (g.comp f : M →ₛₗ[τ₁₃] M₃) ≤ range g := SetLike.coe_mono (Set.range_comp_subset_range f g) theorem range_eq_top [RingHomSurjective τ₁₂] {f : F} : range f = ⊤ ↔ Surjective f := by rw [SetLike.ext'_iff, range_coe, top_coe, Set.range_eq_univ] theorem range_eq_top_of_surjective [RingHomSurjective τ₁₂] (f : F) (hf : Surjective f) : range f = ⊤ := range_eq_top.2 hf theorem range_le_iff_comap [RingHomSurjective τ₁₂] {f : F} {p : Submodule R₂ M₂} : range f ≤ p ↔ comap f p = ⊤ := by rw [range_eq_map, map_le_iff_le_comap, eq_top_iff] theorem map_le_range [RingHomSurjective τ₁₂] {f : F} {p : Submodule R M} : map f p ≤ range f := SetLike.coe_mono (Set.image_subset_range f p) @[simp] theorem range_neg {R : Type*} {R₂ : Type*} {M : Type*} {M₂ : Type*} [Semiring R] [Ring R₂] [AddCommMonoid M] [AddCommGroup M₂] [Module R M] [Module R₂ M₂] {τ₁₂ : R →+* R₂} [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : LinearMap.range (-f) = LinearMap.range f := by change range ((-LinearMap.id : M₂ →ₗ[R₂] M₂).comp f) = _ rw [range_comp, Submodule.map_neg, Submodule.map_id] @[simp] lemma range_domRestrict [Module R M₂] (K : Submodule R M) (f : M →ₗ[R] M₂) : range (domRestrict f K) = K.map f := by ext; simp lemma range_domRestrict_le_range [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) (S : Submodule R M) : LinearMap.range (f.domRestrict S) ≤ LinearMap.range f := by rintro x ⟨⟨y, hy⟩, rfl⟩ exact LinearMap.mem_range_self f y @[simp] theorem _root_.AddMonoidHom.coe_toIntLinearMap_range {M M₂ : Type*} [AddCommGroup M] [AddCommGroup M₂] (f : M →+ M₂) : LinearMap.range f.toIntLinearMap = AddSubgroup.toIntSubmodule f.range := rfl lemma _root_.Submodule.map_comap_eq_of_le [RingHomSurjective τ₁₂] {f : F} {p : Submodule R₂ M₂} (h : p ≤ LinearMap.range f) : (p.comap f).map f = p := SetLike.coe_injective <| Set.image_preimage_eq_of_subset h lemma range_restrictScalars [SMul R R₂] [Module R₂ M] [Module R M₂] [CompatibleSMul M M₂ R R₂] [IsScalarTower R R₂ M₂] (f : M →ₗ[R₂] M₂) : LinearMap.range (f.restrictScalars R) = (LinearMap.range f).restrictScalars R := rfl end /-- The decreasing sequence of submodules consisting of the ranges of the iterates of a linear map. -/ @[simps] def iterateRange (f : M →ₗ[R] M) : ℕ →o (Submodule R M)ᵒᵈ where toFun n := LinearMap.range (f ^ n) monotone' n m w x h := by obtain ⟨c, rfl⟩ := Nat.exists_eq_add_of_le w rw [LinearMap.mem_range] at h obtain ⟨m, rfl⟩ := h rw [LinearMap.mem_range] use (f ^ c) m rw [pow_add, Module.End.mul_apply] /-- Restrict the codomain of a linear map `f` to `f.range`. This is the bundled version of `Set.rangeFactorization`. -/ abbrev rangeRestrict [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : M →ₛₗ[τ₁₂] LinearMap.range f := f.codRestrict (LinearMap.range f) (LinearMap.mem_range_self f) /-- The range of a linear map is finite if the domain is finite. Note: this instance can form a diamond with `Subtype.fintype` in the presence of `Fintype M₂`. -/ instance fintypeRange [Fintype M] [DecidableEq M₂] [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : Fintype (range f) := Set.fintypeRange f variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂] theorem range_codRestrict {τ₂₁ : R₂ →+* R} [RingHomSurjective τ₂₁] (p : Submodule R M) (f : M₂ →ₛₗ[τ₂₁] M) (hf) : range (codRestrict p f hf) = comap p.subtype (LinearMap.range f) := by simpa only [range_eq_map] using map_codRestrict _ _ _ _ theorem _root_.Submodule.map_comap_eq [RingHomSurjective τ₁₂] (f : F) (q : Submodule R₂ M₂) : map f (comap f q) = range f ⊓ q := le_antisymm (le_inf map_le_range (map_comap_le _ _)) <| by rintro _ ⟨⟨x, _, rfl⟩, hx⟩; exact ⟨x, hx, rfl⟩ theorem _root_.Submodule.map_comap_eq_self [RingHomSurjective τ₁₂] {f : F} {q : Submodule R₂ M₂} (h : q ≤ range f) : map f (comap f q) = q := by rwa [Submodule.map_comap_eq, inf_eq_right] @[simp] theorem range_zero [RingHomSurjective τ₁₂] : range (0 : M →ₛₗ[τ₁₂] M₂) = ⊥ := by simpa only [range_eq_map] using Submodule.map_zero _ section variable [RingHomSurjective τ₁₂] theorem range_le_bot_iff (f : M →ₛₗ[τ₁₂] M₂) : range f ≤ ⊥ ↔ f = 0 := by rw [range_le_iff_comap]; exact ker_eq_top theorem range_eq_bot {f : M →ₛₗ[τ₁₂] M₂} : range f = ⊥ ↔ f = 0 := by rw [← range_le_bot_iff, le_bot_iff] theorem range_le_ker_iff {f : M →ₛₗ[τ₁₂] M₂} {g : M₂ →ₛₗ[τ₂₃] M₃} : range f ≤ ker g ↔ (g.comp f : M →ₛₗ[τ₁₃] M₃) = 0 := ⟨fun h => ker_eq_top.1 <| eq_top_iff'.2 fun _ => h <| ⟨_, rfl⟩, fun h x hx => mem_ker.2 <| Exists.elim hx fun y hy => by rw [← hy, ← comp_apply, h, zero_apply]⟩ theorem comap_le_comap_iff {f : F} (hf : range f = ⊤) {p p'} : comap f p ≤ comap f p' ↔ p ≤ p' := ⟨fun H ↦ by rwa [SetLike.le_def, (range_eq_top.1 hf).forall], comap_mono⟩ theorem comap_injective {f : F} (hf : range f = ⊤) : Injective (comap f) := fun _ _ h => le_antisymm ((comap_le_comap_iff hf).1 (le_of_eq h)) ((comap_le_comap_iff hf).1 (ge_of_eq h)) -- TODO (?): generalize to semilinear maps with `f ∘ₗ g` bijective. theorem ker_eq_range_of_comp_eq_id {M P} [AddCommGroup M] [Module R M] [AddCommGroup P] [Module R P] {f : M →ₗ[R] P} {g : P →ₗ[R] M} (h : f ∘ₗ g = .id) : ker f = range (LinearMap.id - g ∘ₗ f) := le_antisymm (fun x hx ↦ ⟨x, show x - g (f x) = x by rw [hx, map_zero, sub_zero]⟩) <| range_le_ker_iff.mpr <| by rw [comp_sub, comp_id, ← comp_assoc, h, id_comp, sub_self] end
end AddCommMonoid
Mathlib/Algebra/Module/Submodule/Range.lean
206
207
/- Copyright (c) 2019 Calle Sönne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Calle Sönne -/ import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic import Mathlib.Analysis.Normed.Group.AddCircle import Mathlib.Algebra.CharZero.Quotient import Mathlib.Topology.Instances.Sign /-! # The type of angles In this file we define `Real.Angle` to be the quotient group `ℝ/2πℤ` and prove a few simple lemmas about trigonometric functions and angles. -/ open Real noncomputable section namespace Real /-- The type of angles -/ def Angle : Type := AddCircle (2 * π) -- The `NormedAddCommGroup, Inhabited` instances should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 namespace Angle instance : NormedAddCommGroup Angle := inferInstanceAs (NormedAddCommGroup (AddCircle (2 * π))) instance : Inhabited Angle := inferInstanceAs (Inhabited (AddCircle (2 * π))) /-- The canonical map from `ℝ` to the quotient `Angle`. -/ @[coe] protected def coe (r : ℝ) : Angle := QuotientAddGroup.mk r instance : Coe ℝ Angle := ⟨Angle.coe⟩ instance : CircularOrder Real.Angle := QuotientAddGroup.circularOrder (hp' := ⟨by norm_num [pi_pos]⟩) @[continuity] theorem continuous_coe : Continuous ((↑) : ℝ → Angle) := continuous_quotient_mk' /-- Coercion `ℝ → Angle` as an additive homomorphism. -/ def coeHom : ℝ →+ Angle := QuotientAddGroup.mk' _ @[simp] theorem coe_coeHom : (coeHom : ℝ → Angle) = ((↑) : ℝ → Angle) := rfl /-- An induction principle to deduce results for `Angle` from those for `ℝ`, used with `induction θ using Real.Angle.induction_on`. -/ @[elab_as_elim] protected theorem induction_on {p : Angle → Prop} (θ : Angle) (h : ∀ x : ℝ, p x) : p θ := Quotient.inductionOn' θ h @[simp] theorem coe_zero : ↑(0 : ℝ) = (0 : Angle) := rfl @[simp] theorem coe_add (x y : ℝ) : ↑(x + y : ℝ) = (↑x + ↑y : Angle) := rfl @[simp] theorem coe_neg (x : ℝ) : ↑(-x : ℝ) = -(↑x : Angle) := rfl @[simp] theorem coe_sub (x y : ℝ) : ↑(x - y : ℝ) = (↑x - ↑y : Angle) := rfl theorem coe_nsmul (n : ℕ) (x : ℝ) : ↑(n • x : ℝ) = n • (↑x : Angle) := rfl theorem coe_zsmul (z : ℤ) (x : ℝ) : ↑(z • x : ℝ) = z • (↑x : Angle) := rfl theorem coe_eq_zero_iff {x : ℝ} : (x : Angle) = 0 ↔ ∃ n : ℤ, n • (2 * π) = x := AddCircle.coe_eq_zero_iff (2 * π) @[simp, norm_cast] theorem natCast_mul_eq_nsmul (x : ℝ) (n : ℕ) : ↑((n : ℝ) * x) = n • (↑x : Angle) := by simpa only [nsmul_eq_mul] using coeHom.map_nsmul x n @[simp, norm_cast] theorem intCast_mul_eq_zsmul (x : ℝ) (n : ℤ) : ↑((n : ℝ) * x : ℝ) = n • (↑x : Angle) := by simpa only [zsmul_eq_mul] using coeHom.map_zsmul x n theorem angle_eq_iff_two_pi_dvd_sub {ψ θ : ℝ} : (θ : Angle) = ψ ↔ ∃ k : ℤ, θ - ψ = 2 * π * k := by simp only [QuotientAddGroup.eq, AddSubgroup.zmultiples_eq_closure, AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm] rw [Angle.coe, Angle.coe, QuotientAddGroup.eq] simp only [AddSubgroup.zmultiples_eq_closure, AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm] @[simp] theorem coe_two_pi : ↑(2 * π : ℝ) = (0 : Angle) := angle_eq_iff_two_pi_dvd_sub.2 ⟨1, by rw [sub_zero, Int.cast_one, mul_one]⟩ @[simp] theorem neg_coe_pi : -(π : Angle) = π := by rw [← coe_neg, angle_eq_iff_two_pi_dvd_sub] use -1 simp [two_mul, sub_eq_add_neg] @[simp] theorem two_nsmul_coe_div_two (θ : ℝ) : (2 : ℕ) • (↑(θ / 2) : Angle) = θ := by rw [← coe_nsmul, two_nsmul, add_halves] @[simp] theorem two_zsmul_coe_div_two (θ : ℝ) : (2 : ℤ) • (↑(θ / 2) : Angle) = θ := by rw [← coe_zsmul, two_zsmul, add_halves] theorem two_nsmul_neg_pi_div_two : (2 : ℕ) • (↑(-π / 2) : Angle) = π := by rw [two_nsmul_coe_div_two, coe_neg, neg_coe_pi] theorem two_zsmul_neg_pi_div_two : (2 : ℤ) • (↑(-π / 2) : Angle) = π := by rw [two_zsmul, ← two_nsmul, two_nsmul_neg_pi_div_two] theorem sub_coe_pi_eq_add_coe_pi (θ : Angle) : θ - π = θ + π := by rw [sub_eq_add_neg, neg_coe_pi] @[simp] theorem two_nsmul_coe_pi : (2 : ℕ) • (π : Angle) = 0 := by simp [← natCast_mul_eq_nsmul] @[simp] theorem two_zsmul_coe_pi : (2 : ℤ) • (π : Angle) = 0 := by simp [← intCast_mul_eq_zsmul] @[simp] theorem coe_pi_add_coe_pi : (π : Real.Angle) + π = 0 := by rw [← two_nsmul, two_nsmul_coe_pi] theorem zsmul_eq_iff {ψ θ : Angle} {z : ℤ} (hz : z ≠ 0) : z • ψ = z • θ ↔ ∃ k : Fin z.natAbs, ψ = θ + (k : ℕ) • (2 * π / z : ℝ) := QuotientAddGroup.zmultiples_zsmul_eq_zsmul_iff hz theorem nsmul_eq_iff {ψ θ : Angle} {n : ℕ} (hz : n ≠ 0) : n • ψ = n • θ ↔ ∃ k : Fin n, ψ = θ + (k : ℕ) • (2 * π / n : ℝ) := QuotientAddGroup.zmultiples_nsmul_eq_nsmul_iff hz theorem two_zsmul_eq_iff {ψ θ : Angle} : (2 : ℤ) • ψ = (2 : ℤ) • θ ↔ ψ = θ ∨ ψ = θ + ↑π := by have : Int.natAbs 2 = 2 := rfl rw [zsmul_eq_iff two_ne_zero, this, Fin.exists_fin_two, Fin.val_zero, Fin.val_one, zero_smul, add_zero, one_smul, Int.cast_two, mul_div_cancel_left₀ (_ : ℝ) two_ne_zero] theorem two_nsmul_eq_iff {ψ θ : Angle} : (2 : ℕ) • ψ = (2 : ℕ) • θ ↔ ψ = θ ∨ ψ = θ + ↑π := by simp_rw [← natCast_zsmul, Nat.cast_ofNat, two_zsmul_eq_iff] theorem two_nsmul_eq_zero_iff {θ : Angle} : (2 : ℕ) • θ = 0 ↔ θ = 0 ∨ θ = π := by convert two_nsmul_eq_iff <;> simp theorem two_nsmul_ne_zero_iff {θ : Angle} : (2 : ℕ) • θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← two_nsmul_eq_zero_iff] theorem two_zsmul_eq_zero_iff {θ : Angle} : (2 : ℤ) • θ = 0 ↔ θ = 0 ∨ θ = π := by simp_rw [two_zsmul, ← two_nsmul, two_nsmul_eq_zero_iff] theorem two_zsmul_ne_zero_iff {θ : Angle} : (2 : ℤ) • θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← two_zsmul_eq_zero_iff] theorem eq_neg_self_iff {θ : Angle} : θ = -θ ↔ θ = 0 ∨ θ = π := by rw [← add_eq_zero_iff_eq_neg, ← two_nsmul, two_nsmul_eq_zero_iff] theorem ne_neg_self_iff {θ : Angle} : θ ≠ -θ ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← eq_neg_self_iff.not] theorem neg_eq_self_iff {θ : Angle} : -θ = θ ↔ θ = 0 ∨ θ = π := by rw [eq_comm, eq_neg_self_iff] theorem neg_ne_self_iff {θ : Angle} : -θ ≠ θ ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← neg_eq_self_iff.not] theorem two_nsmul_eq_pi_iff {θ : Angle} : (2 : ℕ) • θ = π ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by have h : (π : Angle) = ((2 : ℕ) • (π / 2 : ℝ):) := by rw [two_nsmul, add_halves] nth_rw 1 [h] rw [coe_nsmul, two_nsmul_eq_iff] -- Porting note: `congr` didn't simplify the goal of iff of `Or`s convert Iff.rfl rw [add_comm, ← coe_add, ← sub_eq_zero, ← coe_sub, neg_div, ← neg_sub, sub_neg_eq_add, add_assoc, add_halves, ← two_mul, coe_neg, coe_two_pi, neg_zero] theorem two_zsmul_eq_pi_iff {θ : Angle} : (2 : ℤ) • θ = π ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by rw [two_zsmul, ← two_nsmul, two_nsmul_eq_pi_iff] theorem cos_eq_iff_coe_eq_or_eq_neg {θ ψ : ℝ} : cos θ = cos ψ ↔ (θ : Angle) = ψ ∨ (θ : Angle) = -ψ := by constructor · intro Hcos rw [← sub_eq_zero, cos_sub_cos, mul_eq_zero, mul_eq_zero, neg_eq_zero, eq_false (two_ne_zero' ℝ), false_or, sin_eq_zero_iff, sin_eq_zero_iff] at Hcos rcases Hcos with (⟨n, hn⟩ | ⟨n, hn⟩) · right rw [eq_div_iff_mul_eq (two_ne_zero' ℝ), ← sub_eq_iff_eq_add] at hn rw [← hn, coe_sub, eq_neg_iff_add_eq_zero, sub_add_cancel, mul_assoc, intCast_mul_eq_zsmul, mul_comm, coe_two_pi, zsmul_zero] · left rw [eq_div_iff_mul_eq (two_ne_zero' ℝ), eq_sub_iff_add_eq] at hn rw [← hn, coe_add, mul_assoc, intCast_mul_eq_zsmul, mul_comm, coe_two_pi, zsmul_zero, zero_add] · rw [angle_eq_iff_two_pi_dvd_sub, ← coe_neg, angle_eq_iff_two_pi_dvd_sub] rintro (⟨k, H⟩ | ⟨k, H⟩) · rw [← sub_eq_zero, cos_sub_cos, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero] rw [← sub_eq_zero, cos_sub_cos, ← sub_neg_eq_add, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul] theorem sin_eq_iff_coe_eq_or_add_eq_pi {θ ψ : ℝ} : sin θ = sin ψ ↔ (θ : Angle) = ψ ∨ (θ : Angle) + ψ = π := by constructor · intro Hsin rw [← cos_pi_div_two_sub, ← cos_pi_div_two_sub] at Hsin rcases cos_eq_iff_coe_eq_or_eq_neg.mp Hsin with h | h · left rw [coe_sub, coe_sub] at h exact sub_right_inj.1 h right rw [coe_sub, coe_sub, eq_neg_iff_add_eq_zero, add_sub, sub_add_eq_add_sub, ← coe_add, add_halves, sub_sub, sub_eq_zero] at h exact h.symm · rw [angle_eq_iff_two_pi_dvd_sub, ← eq_sub_iff_add_eq, ← coe_sub, angle_eq_iff_two_pi_dvd_sub] rintro (⟨k, H⟩ | ⟨k, H⟩) · rw [← sub_eq_zero, sin_sub_sin, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul] have H' : θ + ψ = 2 * k * π + π := by rwa [← sub_add, sub_add_eq_add_sub, sub_eq_iff_eq_add, mul_assoc, mul_comm π _, ← mul_assoc] at H rw [← sub_eq_zero, sin_sub_sin, H', add_div, mul_assoc 2 _ π,
mul_div_cancel_left₀ _ (two_ne_zero' ℝ), cos_add_pi_div_two, sin_int_mul_pi, neg_zero, mul_zero]
Mathlib/Analysis/SpecialFunctions/Trigonometric/Angle.lean
239
240
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.Fintype.List import Mathlib.Data.Fintype.OfMap /-! # Cycles of a list Lists have an equivalence relation of whether they are rotational permutations of one another. This relation is defined as `IsRotated`. Based on this, we define the quotient of lists by the rotation relation, called `Cycle`. We also define a representation of concrete cycles, available when viewing them in a goal state or via `#eval`, when over representable types. For example, the cycle `(2 1 4 3)` will be shown as `c[2, 1, 4, 3]`. Two equal cycles may be printed differently if their internal representation is different. -/ assert_not_exists MonoidWithZero namespace List variable {α : Type*} [DecidableEq α] /-- Return the `z` such that `x :: z :: _` appears in `xs`, or `default` if there is no such `z`. -/ def nextOr : ∀ (_ : List α) (_ _ : α), α | [], _, default => default | [_], _, default => default -- Handles the not-found and the wraparound case | y :: z :: xs, x, default => if x = y then z else nextOr (z :: xs) x default @[simp] theorem nextOr_nil (x d : α) : nextOr [] x d = d := rfl @[simp] theorem nextOr_singleton (x y d : α) : nextOr [y] x d = d := rfl @[simp] theorem nextOr_self_cons_cons (xs : List α) (x y d : α) : nextOr (x :: y :: xs) x d = y := if_pos rfl theorem nextOr_cons_of_ne (xs : List α) (y x d : α) (h : x ≠ y) : nextOr (y :: xs) x d = nextOr xs x d := by rcases xs with - | ⟨z, zs⟩ · rfl · exact if_neg h /-- `nextOr` does not depend on the default value, if the next value appears. -/ theorem nextOr_eq_nextOr_of_mem_of_ne (xs : List α) (x d d' : α) (x_mem : x ∈ xs) (x_ne : x ≠ xs.getLast (ne_nil_of_mem x_mem)) : nextOr xs x d = nextOr xs x d' := by induction' xs with y ys IH · cases x_mem rcases ys with - | ⟨z, zs⟩ · simp at x_mem x_ne contradiction by_cases h : x = y · rw [h, nextOr_self_cons_cons, nextOr_self_cons_cons] · rw [nextOr, nextOr, IH] · simpa [h] using x_mem · simpa using x_ne theorem mem_of_nextOr_ne {xs : List α} {x d : α} (h : nextOr xs x d ≠ d) : x ∈ xs := by induction' xs with y ys IH · simp at h rcases ys with - | ⟨z, zs⟩ · simp at h · by_cases hx : x = y · simp [hx] · rw [nextOr_cons_of_ne _ _ _ _ hx] at h simpa [hx] using IH h theorem nextOr_concat {xs : List α} {x : α} (d : α) (h : x ∉ xs) : nextOr (xs ++ [x]) x d = d := by induction' xs with z zs IH · simp · obtain ⟨hz, hzs⟩ := not_or.mp (mt mem_cons.2 h) rw [cons_append, nextOr_cons_of_ne _ _ _ _ hz, IH hzs] theorem nextOr_mem {xs : List α} {x d : α} (hd : d ∈ xs) : nextOr xs x d ∈ xs := by revert hd suffices ∀ xs' : List α, (∀ x ∈ xs, x ∈ xs') → d ∈ xs' → nextOr xs x d ∈ xs' by exact this xs fun _ => id intro xs' hxs' hd induction' xs with y ys ih · exact hd rcases ys with - | ⟨z, zs⟩ · exact hd rw [nextOr] split_ifs with h · exact hxs' _ (mem_cons_of_mem _ mem_cons_self) · exact ih fun _ h => hxs' _ (mem_cons_of_mem _ h) /-- Given an element `x : α` of `l : List α` such that `x ∈ l`, get the next element of `l`. This works from head to tail, (including a check for last element) so it will match on first hit, ignoring later duplicates. For example: * `next [1, 2, 3] 2 _ = 3` * `next [1, 2, 3] 3 _ = 1` * `next [1, 2, 3, 2, 4] 2 _ = 3` * `next [1, 2, 3, 2] 2 _ = 3` * `next [1, 1, 2, 3, 2] 1 _ = 1` -/ def next (l : List α) (x : α) (h : x ∈ l) : α := nextOr l x (l.get ⟨0, length_pos_of_mem h⟩) /-- Given an element `x : α` of `l : List α` such that `x ∈ l`, get the previous element of `l`. This works from head to tail, (including a check for last element) so it will match on first hit, ignoring later duplicates. * `prev [1, 2, 3] 2 _ = 1` * `prev [1, 2, 3] 1 _ = 3` * `prev [1, 2, 3, 2, 4] 2 _ = 1` * `prev [1, 2, 3, 4, 2] 2 _ = 1` * `prev [1, 1, 2] 1 _ = 2` -/ def prev : ∀ l : List α, ∀ x ∈ l, α | [], _, h => by simp at h | [y], _, _ => y | y :: z :: xs, x, h => if hx : x = y then getLast (z :: xs) (cons_ne_nil _ _) else if x = z then y else prev (z :: xs) x (by simpa [hx] using h) variable (l : List α) (x : α) @[simp] theorem next_singleton (x y : α) (h : x ∈ [y]) : next [y] x h = y := rfl @[simp] theorem prev_singleton (x y : α) (h : x ∈ [y]) : prev [y] x h = y := rfl theorem next_cons_cons_eq' (y z : α) (h : x ∈ y :: z :: l) (hx : x = y) : next (y :: z :: l) x h = z := by rw [next, nextOr, if_pos hx] @[simp] theorem next_cons_cons_eq (z : α) (h : x ∈ x :: z :: l) : next (x :: z :: l) x h = z := next_cons_cons_eq' l x x z h rfl theorem next_ne_head_ne_getLast (h : x ∈ l) (y : α) (h : x ∈ y :: l) (hy : x ≠ y) (hx : x ≠ getLast (y :: l) (cons_ne_nil _ _)) : next (y :: l) x h = next l x (by simpa [hy] using h) := by rw [next, next, nextOr_cons_of_ne _ _ _ _ hy, nextOr_eq_nextOr_of_mem_of_ne] · rwa [getLast_cons] at hx exact ne_nil_of_mem (by assumption) · rwa [getLast_cons] at hx theorem next_cons_concat (y : α) (hy : x ≠ y) (hx : x ∉ l) (h : x ∈ y :: l ++ [x] := mem_append_right _ (mem_singleton_self x)) : next (y :: l ++ [x]) x h = y := by rw [next, nextOr_concat] · rfl · simp [hy, hx] theorem next_getLast_cons (h : x ∈ l) (y : α) (h : x ∈ y :: l) (hy : x ≠ y) (hx : x = getLast (y :: l) (cons_ne_nil _ _)) (hl : Nodup l) : next (y :: l) x h = y := by rw [next, get, ← dropLast_append_getLast (cons_ne_nil y l), hx, nextOr_concat] subst hx intro H obtain ⟨_ | k, hk, hk'⟩ := getElem_of_mem H · rw [← Option.some_inj] at hk' rw [← getElem?_eq_getElem, dropLast_eq_take, getElem?_take_of_lt, getElem?_cons_zero, Option.some_inj] at hk' · exact hy (Eq.symm hk') rw [length_cons] exact length_pos_of_mem (by assumption) suffices k + 1 = l.length by simp [this] at hk rcases l with - | ⟨hd, tl⟩ · simp at hk · rw [nodup_iff_injective_get] at hl rw [length, Nat.succ_inj] refine Fin.val_eq_of_eq <| @hl ⟨k, Nat.lt_of_succ_lt <| by simpa using hk⟩ ⟨tl.length, by simp⟩ ?_ rw [← Option.some_inj] at hk' rw [← getElem?_eq_getElem, dropLast_eq_take, getElem?_take_of_lt, getElem?_cons_succ, getElem?_eq_getElem, Option.some_inj] at hk' · rw [get_eq_getElem, hk'] simp only [getLast_eq_getElem, length_cons, Nat.succ_eq_add_one, Nat.succ_sub_succ_eq_sub, Nat.sub_zero, get_eq_getElem, getElem_cons_succ] simpa using hk theorem prev_getLast_cons' (y : α) (hxy : x ∈ y :: l) (hx : x = y) : prev (y :: l) x hxy = getLast (y :: l) (cons_ne_nil _ _) := by cases l <;> simp [prev, hx] @[simp] theorem prev_getLast_cons (h : x ∈ x :: l) : prev (x :: l) x h = getLast (x :: l) (cons_ne_nil _ _) := prev_getLast_cons' l x x h rfl theorem prev_cons_cons_eq' (y z : α) (h : x ∈ y :: z :: l) (hx : x = y) : prev (y :: z :: l) x h = getLast (z :: l) (cons_ne_nil _ _) := by rw [prev, dif_pos hx] theorem prev_cons_cons_eq (z : α) (h : x ∈ x :: z :: l) : prev (x :: z :: l) x h = getLast (z :: l) (cons_ne_nil _ _) := prev_cons_cons_eq' l x x z h rfl theorem prev_cons_cons_of_ne' (y z : α) (h : x ∈ y :: z :: l) (hy : x ≠ y) (hz : x = z) : prev (y :: z :: l) x h = y := by cases l · simp [prev, hy, hz] · rw [prev, dif_neg hy, if_pos hz] theorem prev_cons_cons_of_ne (y : α) (h : x ∈ y :: x :: l) (hy : x ≠ y) : prev (y :: x :: l) x h = y := prev_cons_cons_of_ne' _ _ _ _ _ hy rfl theorem prev_ne_cons_cons (y z : α) (h : x ∈ y :: z :: l) (hy : x ≠ y) (hz : x ≠ z) : prev (y :: z :: l) x h = prev (z :: l) x (by simpa [hy] using h) := by cases l · simp [hy, hz] at h · rw [prev, dif_neg hy, if_neg hz] theorem next_mem (h : x ∈ l) : l.next x h ∈ l := nextOr_mem (get_mem _ _) theorem prev_mem (h : x ∈ l) : l.prev x h ∈ l := by rcases l with - | ⟨hd, tl⟩ · simp at h induction' tl with hd' tl hl generalizing hd · simp · by_cases hx : x = hd · simp only [hx, prev_cons_cons_eq] exact mem_cons_of_mem _ (getLast_mem _) · rw [prev, dif_neg hx] split_ifs with hm · exact mem_cons_self · exact mem_cons_of_mem _ (hl _ _) theorem next_getElem (l : List α) (h : Nodup l) (i : Nat) (hi : i < l.length) : next l l[i] (get_mem _ _) = (l[(i + 1) % l.length]'(Nat.mod_lt _ (i.zero_le.trans_lt hi))) := match l, h, i, hi with | [], _, i, hi => by simp at hi | [_], _, _, _ => by simp | x::y::l, _h, 0, h0 => by have h₁ : (x :: y :: l)[0] = x := by simp rw [next_cons_cons_eq' _ _ _ _ _ h₁] simp | x::y::l, hn, i+1, hi => by have hx' : (x :: y :: l)[i+1] ≠ x := by intro H suffices (i + 1 : ℕ) = 0 by simpa rw [nodup_iff_injective_get] at hn refine Fin.val_eq_of_eq (@hn ⟨i + 1, hi⟩ ⟨0, by simp⟩ ?_) simpa using H have hi' : i ≤ l.length := Nat.le_of_lt_succ (Nat.succ_lt_succ_iff.1 hi) rcases hi'.eq_or_lt with (hi' | hi') · subst hi' rw [next_getLast_cons] · simp [hi', get] · rw [getElem_cons_succ]; exact get_mem _ _ · exact hx' · simp [getLast_eq_getElem] · exact hn.of_cons · rw [next_ne_head_ne_getLast _ _ _ _ _ hx'] · simp only [getElem_cons_succ] rw [next_getElem (y::l), ← getElem_cons_succ (a := x)] · congr dsimp rw [Nat.mod_eq_of_lt (Nat.succ_lt_succ_iff.2 hi'), Nat.mod_eq_of_lt (Nat.succ_lt_succ_iff.2 (Nat.succ_lt_succ_iff.2 hi'))] · simp [Nat.mod_eq_of_lt (Nat.succ_lt_succ_iff.2 hi'), hi'] · exact hn.of_cons · rw [getLast_eq_getElem] intro h have := nodup_iff_injective_get.1 hn h simp at this; simp [this] at hi' · rw [getElem_cons_succ]; exact get_mem _ _ @[deprecated (since := "2025-02-015")] alias next_get := next_getElem -- Unused variable linter incorrectly reports that `h` is unused here. set_option linter.unusedVariables false in theorem prev_getElem (l : List α) (h : Nodup l) (i : Nat) (hi : i < l.length) : prev l l[i] (get_mem _ _) = (l[(i + (l.length - 1)) % l.length]'(Nat.mod_lt _ (by omega))) := match l with | [] => by simp at hi | x::l => by induction l generalizing i x with | nil => simp | cons y l hl => rcases i with (_ | _ | i) · simp [getLast_eq_getElem] · simp only [mem_cons, nodup_cons] at h push_neg at h simp only [zero_add, getElem_cons_succ, getElem_cons_zero, List.prev_cons_cons_of_ne _ _ _ _ h.left.left.symm, length, add_comm, Nat.add_sub_cancel_left, Nat.mod_self] · rw [prev_ne_cons_cons] · convert hl i.succ y h.of_cons (Nat.le_of_succ_le_succ hi) using 1 have : ∀ k hk, (y :: l)[k] = (x :: y :: l)[k + 1]'(Nat.succ_lt_succ hk) := by simp rw [this] congr simp only [Nat.add_succ_sub_one, add_zero, length] simp only [length, Nat.succ_lt_succ_iff] at hi set k := l.length rw [Nat.succ_add, ← Nat.add_succ, Nat.add_mod_right, Nat.succ_add, ← Nat.add_succ _ k, Nat.add_mod_right, Nat.mod_eq_of_lt, Nat.mod_eq_of_lt] · exact Nat.lt_succ_of_lt hi · exact Nat.succ_lt_succ (Nat.lt_succ_of_lt hi) · intro H suffices i.succ.succ = 0 by simpa suffices Fin.mk _ hi = ⟨0, by omega⟩ by rwa [Fin.mk.inj_iff] at this rw [nodup_iff_injective_get] at h apply h; rw [← H]; simp · intro H suffices i.succ.succ = 1 by simpa suffices Fin.mk _ hi = ⟨1, by omega⟩ by rwa [Fin.mk.inj_iff] at this rw [nodup_iff_injective_get] at h apply h; rw [← H]; simp @[deprecated (since := "2025-02-15")] alias prev_get := prev_getElem theorem pmap_next_eq_rotate_one (h : Nodup l) : (l.pmap l.next fun _ h => h) = l.rotate 1 := by apply List.ext_getElem · simp · intros rw [getElem_pmap, getElem_rotate, next_getElem _ h] theorem pmap_prev_eq_rotate_length_sub_one (h : Nodup l) : (l.pmap l.prev fun _ h => h) = l.rotate (l.length - 1) := by apply List.ext_getElem · simp · intro n hn hn' rw [getElem_rotate, getElem_pmap, prev_getElem _ h] theorem prev_next (l : List α) (h : Nodup l) (x : α) (hx : x ∈ l) : prev l (next l x hx) (next_mem _ _ _) = x := by obtain ⟨n, hn, rfl⟩ := getElem_of_mem hx simp only [next_getElem, prev_getElem, h, Nat.mod_add_mod] rcases l with - | ⟨hd, tl⟩ · simp at hn · have : (n + 1 + length tl) % (length tl + 1) = n := by rw [length_cons] at hn rw [add_assoc, add_comm 1, Nat.add_mod_right, Nat.mod_eq_of_lt hn] simp only [length_cons, Nat.succ_sub_succ_eq_sub, Nat.sub_zero, Nat.succ_eq_add_one, this] theorem next_prev (l : List α) (h : Nodup l) (x : α) (hx : x ∈ l) : next l (prev l x hx) (prev_mem _ _ _) = x := by obtain ⟨n, hn, rfl⟩ := getElem_of_mem hx simp only [next_getElem, prev_getElem, h, Nat.mod_add_mod] rcases l with - | ⟨hd, tl⟩ · simp at hn · have : (n + length tl + 1) % (length tl + 1) = n := by rw [length_cons] at hn rw [add_assoc, Nat.add_mod_right, Nat.mod_eq_of_lt hn] simp [this] theorem prev_reverse_eq_next (l : List α) (h : Nodup l) (x : α) (hx : x ∈ l) : prev l.reverse x (mem_reverse.mpr hx) = next l x hx := by obtain ⟨k, hk, rfl⟩ := getElem_of_mem hx have lpos : 0 < l.length := k.zero_le.trans_lt hk have key : l.length - 1 - k < l.length := by omega rw [← getElem_pmap l.next (fun _ h => h) (by simpa using hk)] simp_rw [getElem_eq_getElem_reverse (l := l), pmap_next_eq_rotate_one _ h] rw [← getElem_pmap l.reverse.prev fun _ h => h] · simp_rw [pmap_prev_eq_rotate_length_sub_one _ (nodup_reverse.mpr h), rotate_reverse, length_reverse, Nat.mod_eq_of_lt (Nat.sub_lt lpos Nat.succ_pos'), Nat.sub_sub_self (Nat.succ_le_of_lt lpos)] rw [getElem_eq_getElem_reverse] · simp [Nat.sub_sub_self (Nat.le_sub_one_of_lt hk)] · simpa theorem next_reverse_eq_prev (l : List α) (h : Nodup l) (x : α) (hx : x ∈ l) : next l.reverse x (mem_reverse.mpr hx) = prev l x hx := by convert (prev_reverse_eq_next l.reverse (nodup_reverse.mpr h) x (mem_reverse.mpr hx)).symm exact (reverse_reverse l).symm theorem isRotated_next_eq {l l' : List α} (h : l ~r l') (hn : Nodup l) {x : α} (hx : x ∈ l) : l.next x hx = l'.next x (h.mem_iff.mp hx) := by obtain ⟨k, hk, rfl⟩ := getElem_of_mem hx obtain ⟨n, rfl⟩ := id h rw [next_getElem _ hn] simp_rw [getElem_eq_getElem_rotate _ n k] rw [next_getElem _ (h.nodup_iff.mp hn), getElem_eq_getElem_rotate _ n] simp [add_assoc] theorem isRotated_prev_eq {l l' : List α} (h : l ~r l') (hn : Nodup l) {x : α} (hx : x ∈ l) : l.prev x hx = l'.prev x (h.mem_iff.mp hx) := by rw [← next_reverse_eq_prev _ hn, ← next_reverse_eq_prev _ (h.nodup_iff.mp hn)] exact isRotated_next_eq h.reverse (nodup_reverse.mpr hn) _ end List open List /-- `Cycle α` is the quotient of `List α` by cyclic permutation. Duplicates are allowed. -/ def Cycle (α : Type*) : Type _ := Quotient (IsRotated.setoid α) namespace Cycle variable {α : Type*} /-- The coercion from `List α` to `Cycle α` -/ @[coe] def ofList : List α → Cycle α := Quot.mk _ instance : Coe (List α) (Cycle α) := ⟨ofList⟩ @[simp] theorem coe_eq_coe {l₁ l₂ : List α} : (l₁ : Cycle α) = (l₂ : Cycle α) ↔ l₁ ~r l₂ := @Quotient.eq _ (IsRotated.setoid _) _ _ @[simp] theorem mk_eq_coe (l : List α) : Quot.mk _ l = (l : Cycle α) := rfl @[simp] theorem mk''_eq_coe (l : List α) : Quotient.mk'' l = (l : Cycle α) := rfl theorem coe_cons_eq_coe_append (l : List α) (a : α) : (↑(a :: l) : Cycle α) = (↑(l ++ [a]) : Cycle α) := Quot.sound ⟨1, by rw [rotate_cons_succ, rotate_zero]⟩ /-- The unique empty cycle. -/ def nil : Cycle α := ([] : List α) @[simp] theorem coe_nil : ↑([] : List α) = @nil α := rfl @[simp] theorem coe_eq_nil (l : List α) : (l : Cycle α) = nil ↔ l = [] := coe_eq_coe.trans isRotated_nil_iff /-- For consistency with `EmptyCollection (List α)`. -/ instance : EmptyCollection (Cycle α) := ⟨nil⟩ @[simp] theorem empty_eq : ∅ = @nil α := rfl instance : Inhabited (Cycle α) := ⟨nil⟩ /-- An induction principle for `Cycle`. Use as `induction s`. -/ @[elab_as_elim, induction_eliminator] theorem induction_on {C : Cycle α → Prop} (s : Cycle α) (H0 : C nil) (HI : ∀ (a) (l : List α), C ↑l → C ↑(a :: l)) : C s := Quotient.inductionOn' s fun l => by refine List.recOn l ?_ ?_ <;> simp only [mk''_eq_coe, coe_nil] assumption' /-- For `x : α`, `s : Cycle α`, `x ∈ s` indicates that `x` occurs at least once in `s`. -/ def Mem (s : Cycle α) (a : α) : Prop := Quot.liftOn s (fun l => a ∈ l) fun _ _ e => propext <| e.mem_iff instance : Membership α (Cycle α) := ⟨Mem⟩ @[simp] theorem mem_coe_iff {a : α} {l : List α} : a ∈ (↑l : Cycle α) ↔ a ∈ l := Iff.rfl @[simp] theorem not_mem_nil (a : α) : a ∉ nil := List.not_mem_nil instance [DecidableEq α] : DecidableEq (Cycle α) := fun s₁ s₂ => Quotient.recOnSubsingleton₂' s₁ s₂ fun _ _ => decidable_of_iff' _ Quotient.eq'' instance [DecidableEq α] (x : α) (s : Cycle α) : Decidable (x ∈ s) := Quotient.recOnSubsingleton' s fun l => show Decidable (x ∈ l) from inferInstance /-- Reverse a `s : Cycle α` by reversing the underlying `List`. -/ nonrec def reverse (s : Cycle α) : Cycle α := Quot.map reverse (fun _ _ => IsRotated.reverse) s @[simp] theorem reverse_coe (l : List α) : (l : Cycle α).reverse = l.reverse := rfl @[simp] theorem mem_reverse_iff {a : α} {s : Cycle α} : a ∈ s.reverse ↔ a ∈ s := Quot.inductionOn s fun _ => mem_reverse @[simp] theorem reverse_reverse (s : Cycle α) : s.reverse.reverse = s := Quot.inductionOn s fun _ => by simp @[simp] theorem reverse_nil : nil.reverse = @nil α := rfl /-- The length of the `s : Cycle α`, which is the number of elements, counting duplicates. -/ def length (s : Cycle α) : ℕ := Quot.liftOn s List.length fun _ _ e => e.perm.length_eq @[simp] theorem length_coe (l : List α) : length (l : Cycle α) = l.length := rfl @[simp] theorem length_nil : length (@nil α) = 0 := rfl @[simp] theorem length_reverse (s : Cycle α) : s.reverse.length = s.length := Quot.inductionOn s fun _ => List.length_reverse /-- A `s : Cycle α` that is at most one element. -/ def Subsingleton (s : Cycle α) : Prop := s.length ≤ 1 theorem subsingleton_nil : Subsingleton (@nil α) := Nat.zero_le _ theorem length_subsingleton_iff {s : Cycle α} : Subsingleton s ↔ length s ≤ 1 := Iff.rfl @[simp] theorem subsingleton_reverse_iff {s : Cycle α} : s.reverse.Subsingleton ↔ s.Subsingleton := by simp [length_subsingleton_iff] theorem Subsingleton.congr {s : Cycle α} (h : Subsingleton s) : ∀ ⦃x⦄ (_hx : x ∈ s) ⦃y⦄ (_hy : y ∈ s), x = y := by induction' s using Quot.inductionOn with l simp only [length_subsingleton_iff, length_coe, mk_eq_coe, le_iff_lt_or_eq, Nat.lt_add_one_iff, length_eq_zero_iff, length_eq_one_iff, Nat.not_lt_zero, false_or] at h rcases h with (rfl | ⟨z, rfl⟩) <;> simp /-- A `s : Cycle α` that is made up of at least two unique elements. -/ def Nontrivial (s : Cycle α) : Prop := ∃ x y : α, x ≠ y ∧ x ∈ s ∧ y ∈ s @[simp] theorem nontrivial_coe_nodup_iff {l : List α} (hl : l.Nodup) : Nontrivial (l : Cycle α) ↔ 2 ≤ l.length := by rw [Nontrivial] rcases l with (_ | ⟨hd, _ | ⟨hd', tl⟩⟩) · simp · simp · simp only [mem_cons, exists_prop, mem_coe_iff, List.length, Ne, Nat.succ_le_succ_iff, Nat.zero_le, iff_true] refine ⟨hd, hd', ?_, by simp⟩ simp only [not_or, mem_cons, nodup_cons] at hl exact hl.left.left @[simp] theorem nontrivial_reverse_iff {s : Cycle α} : s.reverse.Nontrivial ↔ s.Nontrivial := by simp [Nontrivial] theorem length_nontrivial {s : Cycle α} (h : Nontrivial s) : 2 ≤ length s := by obtain ⟨x, y, hxy, hx, hy⟩ := h induction' s using Quot.inductionOn with l rcases l with (_ | ⟨hd, _ | ⟨hd', tl⟩⟩) · simp at hx · simp only [mem_coe_iff, mk_eq_coe, mem_singleton] at hx hy simp [hx, hy] at hxy · simp [Nat.succ_le_succ_iff] /-- The `s : Cycle α` contains no duplicates. -/ nonrec def Nodup (s : Cycle α) : Prop := Quot.liftOn s Nodup fun _l₁ _l₂ e => propext <| e.nodup_iff @[simp] nonrec theorem nodup_nil : Nodup (@nil α) := nodup_nil @[simp] theorem nodup_coe_iff {l : List α} : Nodup (l : Cycle α) ↔ l.Nodup := Iff.rfl @[simp] theorem nodup_reverse_iff {s : Cycle α} : s.reverse.Nodup ↔ s.Nodup := Quot.inductionOn s fun _ => nodup_reverse theorem Subsingleton.nodup {s : Cycle α} (h : Subsingleton s) : Nodup s := by induction' s using Quot.inductionOn with l obtain - | ⟨hd, tl⟩ := l · simp · have : tl = [] := by simpa [Subsingleton, length_eq_zero_iff, Nat.succ_le_succ_iff] using h simp [this] theorem Nodup.nontrivial_iff {s : Cycle α} (h : Nodup s) : Nontrivial s ↔ ¬Subsingleton s := by rw [length_subsingleton_iff] induction s using Quotient.inductionOn' simp only [mk''_eq_coe, nodup_coe_iff] at h simp [h, Nat.succ_le_iff] /-- The `s : Cycle α` as a `Multiset α`. -/ def toMultiset (s : Cycle α) : Multiset α := Quotient.liftOn' s (↑) fun _ _ h => Multiset.coe_eq_coe.mpr h.perm @[simp] theorem coe_toMultiset (l : List α) : (l : Cycle α).toMultiset = l := rfl @[simp] theorem nil_toMultiset : nil.toMultiset = (0 : Multiset α) := rfl @[simp] theorem card_toMultiset (s : Cycle α) : Multiset.card s.toMultiset = s.length := Quotient.inductionOn' s (by simp) @[simp] theorem toMultiset_eq_nil {s : Cycle α} : s.toMultiset = 0 ↔ s = Cycle.nil := Quotient.inductionOn' s (by simp) /-- The lift of `list.map`. -/ def map {β : Type*} (f : α → β) : Cycle α → Cycle β := Quotient.map' (List.map f) fun _ _ h => h.map _ @[simp] theorem map_nil {β : Type*} (f : α → β) : map f nil = nil := rfl @[simp] theorem map_coe {β : Type*} (f : α → β) (l : List α) : map f ↑l = List.map f l := rfl @[simp] theorem map_eq_nil {β : Type*} (f : α → β) (s : Cycle α) : map f s = nil ↔ s = nil := Quotient.inductionOn' s (by simp) @[simp] theorem mem_map {β : Type*} {f : α → β} {b : β} {s : Cycle α} : b ∈ s.map f ↔ ∃ a, a ∈ s ∧ f a = b := Quotient.inductionOn' s (by simp) /-- The `Multiset` of lists that can make the cycle. -/ def lists (s : Cycle α) : Multiset (List α) := Quotient.liftOn' s (fun l => (l.cyclicPermutations : Multiset (List α))) fun l₁ l₂ h => by simpa using h.cyclicPermutations.perm @[simp] theorem lists_coe (l : List α) : lists (l : Cycle α) = ↑l.cyclicPermutations := rfl @[simp] theorem mem_lists_iff_coe_eq {s : Cycle α} {l : List α} : l ∈ s.lists ↔ (l : Cycle α) = s := Quotient.inductionOn' s fun l => by rw [lists, Quotient.liftOn'_mk''] simp @[simp] theorem lists_nil : lists (@nil α) = {([] : List α)} := by rw [nil, lists_coe, cyclicPermutations_nil, Multiset.coe_singleton] section Decidable variable [DecidableEq α] /-- Auxiliary decidability algorithm for lists that contain at least two unique elements. -/ def decidableNontrivialCoe : ∀ l : List α, Decidable (Nontrivial (l : Cycle α)) | [] => isFalse (by simp [Nontrivial]) | [x] => isFalse (by simp [Nontrivial]) | x :: y :: l => if h : x = y then @decidable_of_iff' _ (Nontrivial (x :: l : Cycle α)) (by simp [h, Nontrivial]) (decidableNontrivialCoe (x :: l)) else isTrue ⟨x, y, h, by simp, by simp⟩ instance {s : Cycle α} : Decidable (Nontrivial s) := Quot.recOnSubsingleton s decidableNontrivialCoe instance {s : Cycle α} : Decidable (Nodup s) := Quot.recOnSubsingleton s List.nodupDecidable instance fintypeNodupCycle [Fintype α] : Fintype { s : Cycle α // s.Nodup } := Fintype.ofSurjective (fun l : { l : List α // l.Nodup } => ⟨l.val, by simpa using l.prop⟩) fun ⟨s, hs⟩ => by induction' s using Quotient.inductionOn' with s hs exact ⟨⟨s, hs⟩, by simp⟩ instance fintypeNodupNontrivialCycle [Fintype α] : Fintype { s : Cycle α // s.Nodup ∧ s.Nontrivial } := Fintype.subtype (((Finset.univ : Finset { s : Cycle α // s.Nodup }).map (Function.Embedding.subtype _)).filter Cycle.Nontrivial) (by simp) /-- The `s : Cycle α` as a `Finset α`. -/ def toFinset (s : Cycle α) : Finset α := s.toMultiset.toFinset @[simp] theorem toFinset_toMultiset (s : Cycle α) : s.toMultiset.toFinset = s.toFinset := rfl @[simp] theorem coe_toFinset (l : List α) : (l : Cycle α).toFinset = l.toFinset := rfl @[simp] theorem nil_toFinset : (@nil α).toFinset = ∅ := rfl @[simp] theorem toFinset_eq_nil {s : Cycle α} : s.toFinset = ∅ ↔ s = Cycle.nil := Quotient.inductionOn' s (by simp) /-- Given a `s : Cycle α` such that `Nodup s`, retrieve the next element after `x ∈ s`. -/ nonrec def next : ∀ (s : Cycle α) (_hs : Nodup s) (x : α) (_hx : x ∈ s), α := fun s => Quot.hrecOn (motive := fun (s : Cycle α) => ∀ (_hs : Cycle.Nodup s) (x : α) (_hx : x ∈ s), α) s (fun l _hn x hx => next l x hx) fun l₁ l₂ h => Function.hfunext (propext h.nodup_iff) fun h₁ h₂ _he => Function.hfunext rfl fun x y hxy => Function.hfunext (propext (by rw [eq_of_heq hxy]; simpa [eq_of_heq hxy] using h.mem_iff)) fun hm hm' he' => heq_of_eq (by rw [heq_iff_eq] at hxy; subst x; simpa using isRotated_next_eq h h₁ _) /-- Given a `s : Cycle α` such that `Nodup s`, retrieve the previous element before `x ∈ s`. -/ nonrec def prev : ∀ (s : Cycle α) (_hs : Nodup s) (x : α) (_hx : x ∈ s), α := fun s => Quot.hrecOn (motive := fun (s : Cycle α) => ∀ (_hs : Cycle.Nodup s) (x : α) (_hx : x ∈ s), α) s (fun l _hn x hx => prev l x hx) fun l₁ l₂ h => Function.hfunext (propext h.nodup_iff) fun h₁ h₂ _he => Function.hfunext rfl fun x y hxy => Function.hfunext (propext (by rw [eq_of_heq hxy]; simpa [eq_of_heq hxy] using h.mem_iff)) fun hm hm' he' => heq_of_eq (by rw [heq_iff_eq] at hxy; subst x; simpa using isRotated_prev_eq h h₁ _) -- `simp` cannot infer the proofs: see `prev_reverse_eq_next'` for `@[simp]` lemma. nonrec theorem prev_reverse_eq_next (s : Cycle α) : ∀ (hs : Nodup s) (x : α) (hx : x ∈ s), s.reverse.prev (nodup_reverse_iff.mpr hs) x (mem_reverse_iff.mpr hx) = s.next hs x hx := Quotient.inductionOn' s prev_reverse_eq_next @[simp] nonrec theorem prev_reverse_eq_next' (s : Cycle α) (hs : Nodup s.reverse) (x : α) (hx : x ∈ s.reverse) : s.reverse.prev hs x hx = s.next (nodup_reverse_iff.mp hs) x (mem_reverse_iff.mp hx) := prev_reverse_eq_next s (nodup_reverse_iff.mp hs) x (mem_reverse_iff.mp hx) -- `simp` cannot infer the proofs: see `next_reverse_eq_prev'` for `@[simp]` lemma. theorem next_reverse_eq_prev (s : Cycle α) (hs : Nodup s) (x : α) (hx : x ∈ s) : s.reverse.next (nodup_reverse_iff.mpr hs) x (mem_reverse_iff.mpr hx) = s.prev hs x hx := by simp [← prev_reverse_eq_next] @[simp] theorem next_reverse_eq_prev' (s : Cycle α) (hs : Nodup s.reverse) (x : α) (hx : x ∈ s.reverse) : s.reverse.next hs x hx = s.prev (nodup_reverse_iff.mp hs) x (mem_reverse_iff.mp hx) := by simp [← prev_reverse_eq_next] @[simp] nonrec theorem next_mem (s : Cycle α) (hs : Nodup s) (x : α) (hx : x ∈ s) : s.next hs x hx ∈ s := by induction s using Quot.inductionOn apply next_mem; assumption theorem prev_mem (s : Cycle α) (hs : Nodup s) (x : α) (hx : x ∈ s) : s.prev hs x hx ∈ s := by rw [← next_reverse_eq_prev, ← mem_reverse_iff] apply next_mem @[simp] nonrec theorem prev_next (s : Cycle α) : ∀ (hs : Nodup s) (x : α) (hx : x ∈ s), s.prev hs (s.next hs x hx) (next_mem s hs x hx) = x := Quotient.inductionOn' s prev_next @[simp] nonrec theorem next_prev (s : Cycle α) : ∀ (hs : Nodup s) (x : α) (hx : x ∈ s), s.next hs (s.prev hs x hx) (prev_mem s hs x hx) = x := Quotient.inductionOn' s next_prev end Decidable /-- We define a representation of concrete cycles, available when viewing them in a goal state or via `#eval`, when over representable types. For example, the cycle `(2 1 4 3)` will be shown as `c[2, 1, 4, 3]`. Two equal cycles may be printed differently if their internal representation is different. -/ unsafe instance [Repr α] : Repr (Cycle α) := ⟨fun s _ => "c[" ++ Std.Format.joinSep (s.map repr).lists.unquot.head! ", " ++ "]"⟩ /-- `chain R s` means that `R` holds between adjacent elements of `s`. `chain R ([a, b, c] : Cycle α) ↔ R a b ∧ R b c ∧ R c a` -/ nonrec def Chain (r : α → α → Prop) (c : Cycle α) : Prop := Quotient.liftOn' c (fun l => match l with | [] => True | a :: m => Chain r a (m ++ [a])) fun a b hab => propext <| by rcases a with - | ⟨a, l⟩ <;> rcases b with - | ⟨b, m⟩ · rfl · have := isRotated_nil_iff'.1 hab contradiction · have := isRotated_nil_iff.1 hab contradiction · dsimp only obtain ⟨n, hn⟩ := hab induction' n with d hd generalizing a b l m · simp only [rotate_zero, cons.injEq] at hn rw [hn.1, hn.2] · rcases l with - | ⟨c, s⟩ · simp only [rotate_cons_succ, nil_append, rotate_singleton, cons.injEq] at hn rw [hn.1, hn.2] · rw [Nat.add_comm, ← rotate_rotate, rotate_cons_succ, rotate_zero, cons_append] at hn rw [← hd c _ _ _ hn] simp [and_comm] @[simp] theorem Chain.nil (r : α → α → Prop) : Cycle.Chain r (@nil α) := by trivial @[simp] theorem chain_coe_cons (r : α → α → Prop) (a : α) (l : List α) : Chain r (a :: l) ↔ List.Chain r a (l ++ [a]) := Iff.rfl theorem chain_singleton (r : α → α → Prop) (a : α) : Chain r [a] ↔ r a a := by rw [chain_coe_cons, nil_append, List.chain_singleton] theorem chain_ne_nil (r : α → α → Prop) {l : List α} : ∀ hl : l ≠ [], Chain r l ↔ List.Chain r (getLast l hl) l := l.reverseRecOn (fun hm => hm.irrefl.elim) (by intro m a _H _ rw [← coe_cons_eq_coe_append, chain_coe_cons, getLast_append_singleton]) theorem chain_map {β : Type*} {r : α → α → Prop} (f : β → α) {s : Cycle β} : Chain r (s.map f) ↔ Chain (fun a b => r (f a) (f b)) s := Quotient.inductionOn s fun l => by rcases l with - | ⟨a, l⟩ · rfl · simp [← concat_eq_append, ← List.map_concat, List.chain_map f] nonrec theorem chain_range_succ (r : ℕ → ℕ → Prop) (n : ℕ) : Chain r (List.range n.succ) ↔ r n 0 ∧ ∀ m < n, r m m.succ := by rw [range_succ, ← coe_cons_eq_coe_append, chain_coe_cons, ← range_succ, chain_range_succ] variable {r : α → α → Prop} {s : Cycle α} theorem Chain.imp {r₁ r₂ : α → α → Prop} (H : ∀ a b, r₁ a b → r₂ a b) (p : Chain r₁ s) : Chain r₂ s := by induction s · trivial · rw [chain_coe_cons] at p ⊢ exact p.imp H /-- As a function from a relation to a predicate, `chain` is monotonic. -/ theorem chain_mono : Monotone (Chain : (α → α → Prop) → Cycle α → Prop) := fun _a _b hab _s => Chain.imp hab theorem chain_of_pairwise : (∀ a ∈ s, ∀ b ∈ s, r a b) → Chain r s := by induction' s with a l _ · exact fun _ => Cycle.Chain.nil r intro hs have Ha : a ∈ (a :: l : Cycle α) := by simp have Hl : ∀ {b} (_hb : b ∈ l), b ∈ (a :: l : Cycle α) := @fun b hb => by simp [hb] rw [Cycle.chain_coe_cons] apply Pairwise.chain rw [pairwise_cons] refine ⟨fun b hb => ?_, pairwise_append.2 ⟨pairwise_of_forall_mem_list fun b hb c hc => hs b (Hl hb) c (Hl hc), pairwise_singleton r a, fun b hb c hc => ?_⟩⟩ · rw [mem_append] at hb rcases hb with hb | hb · exact hs a Ha b (Hl hb) · rw [mem_singleton] at hb rw [hb] exact hs a Ha a Ha · rw [mem_singleton] at hc rw [hc] exact hs b (Hl hb) a Ha theorem chain_iff_pairwise [IsTrans α r] : Chain r s ↔ ∀ a ∈ s, ∀ b ∈ s, r a b := ⟨by induction' s with a l _ · exact fun _ b hb => (not_mem_nil _ hb).elim intro hs b hb c hc rw [Cycle.chain_coe_cons, List.chain_iff_pairwise] at hs simp only [pairwise_append, pairwise_cons, mem_append, mem_singleton, List.not_mem_nil, IsEmpty.forall_iff, imp_true_iff, Pairwise.nil, forall_eq, true_and] at hs simp only [mem_coe_iff, mem_cons] at hb hc rcases hb with (rfl | hb) <;> rcases hc with (rfl | hc) · exact hs.1 c (Or.inr rfl) · exact hs.1 c (Or.inl hc) · exact hs.2.2 b hb · exact _root_.trans (hs.2.2 b hb) (hs.1 c (Or.inl hc)), Cycle.chain_of_pairwise⟩ theorem Chain.eq_nil_of_irrefl [IsTrans α r] [IsIrrefl α r] (h : Chain r s) : s = Cycle.nil := by induction' s with a l _ h · rfl · have ha : a ∈ a :: l := mem_cons_self exact (irrefl_of r a <| chain_iff_pairwise.1 h a ha a ha).elim theorem Chain.eq_nil_of_well_founded [IsWellFounded α r] (h : Chain r s) : s = Cycle.nil := Chain.eq_nil_of_irrefl <| h.imp fun _ _ => Relation.TransGen.single theorem forall_eq_of_chain [IsTrans α r] [IsAntisymm α r] (hs : Chain r s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : a = b := by rw [chain_iff_pairwise] at hs exact antisymm (hs a ha b hb) (hs b hb a ha) end Cycle
Mathlib/Data/List/Cycle.lean
966
971
/- 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.MeasurableSpace.MeasurablyGenerated import Mathlib.MeasureTheory.Measure.NullMeasurable import Mathlib.Order.Interval.Set.Monotone /-! # Measure spaces The definition of a measure and a measure space are in `MeasureTheory.MeasureSpaceDef`, with only a few basic properties. This file provides many more properties of these objects. This separation allows the measurability tactic to import only the file `MeasureSpaceDef`, and to be available in `MeasureSpace` (through `MeasurableSpace`). Given a measurable space `α`, a measure on `α` is a function that sends measurable sets to the extended nonnegative reals that satisfies the following conditions: 1. `μ ∅ = 0`; 2. `μ` is countably additive. This means that the measure of a countable union of pairwise disjoint sets is equal to the measure of the individual sets. Every measure can be canonically extended to an outer measure, so that it assigns values to all subsets, not just the measurable subsets. On the other hand, a measure that is countably additive on measurable sets can be restricted to measurable sets to obtain a measure. In this file a measure is defined to be an outer measure that is countably additive on measurable sets, with the additional assumption that the outer measure is the canonical extension of the restricted measure. Measures on `α` form a complete lattice, and are closed under scalar multiplication with `ℝ≥0∞`. Given a measure, the null sets are the sets where `μ s = 0`, where `μ` denotes the corresponding outer measure (so `s` might not be measurable). We can then define the completion of `μ` as the measure on the least `σ`-algebra that also contains all null sets, by defining the measure to be `0` on the null sets. ## Main statements * `completion` is the completion of a measure to all null measurable sets. * `Measure.ofMeasurable` and `OuterMeasure.toMeasure` are two important ways to define a measure. ## Implementation notes Given `μ : Measure α`, `μ s` is the value of the *outer measure* applied to `s`. This conveniently allows us to apply the measure to sets without proving that they are measurable. We get countable subadditivity for all sets, but only countable additivity for measurable sets. You often don't want to define a measure via its constructor. Two ways that are sometimes more convenient: * `Measure.ofMeasurable` is a way to define a measure by only giving its value on measurable sets and proving the properties (1) and (2) mentioned above. * `OuterMeasure.toMeasure` is a way of obtaining a measure from an outer measure by showing that all measurable sets in the measurable space are Carathéodory measurable. To prove that two measures are equal, there are multiple options: * `ext`: two measures are equal if they are equal on all measurable sets. * `ext_of_generateFrom_of_iUnion`: two measures are equal if they are equal on a π-system generating the measurable sets, if the π-system contains a spanning increasing sequence of sets where the measures take finite value (in particular the measures are σ-finite). This is a special case of the more general `ext_of_generateFrom_of_cover` * `ext_of_generate_finite`: two finite measures are equal if they are equal on a π-system generating the measurable sets. This is a special case of `ext_of_generateFrom_of_iUnion` using `C ∪ {univ}`, but is easier to work with. A `MeasureSpace` is a class that is a measurable space with a canonical measure. The measure is denoted `volume`. ## References * <https://en.wikipedia.org/wiki/Measure_(mathematics)> * <https://en.wikipedia.org/wiki/Complete_measure> * <https://en.wikipedia.org/wiki/Almost_everywhere> ## Tags measure, almost everywhere, measure space, completion, null set, null measurable set -/ noncomputable section open Set open Filter hiding map open Function MeasurableSpace Topology Filter ENNReal NNReal Interval MeasureTheory open scoped symmDiff variable {α β γ δ ι R R' : Type*} namespace MeasureTheory section variable {m : MeasurableSpace α} {μ μ₁ μ₂ : Measure α} {s s₁ s₂ t : Set α} instance ae_isMeasurablyGenerated : IsMeasurablyGenerated (ae μ) := ⟨fun _s hs => let ⟨t, hst, htm, htμ⟩ := exists_measurable_superset_of_null hs ⟨tᶜ, compl_mem_ae_iff.2 htμ, htm.compl, compl_subset_comm.1 hst⟩⟩ /-- See also `MeasureTheory.ae_restrict_uIoc_iff`. -/ theorem ae_uIoc_iff [LinearOrder α] {a b : α} {P : α → Prop} : (∀ᵐ x ∂μ, x ∈ Ι a b → P x) ↔ (∀ᵐ x ∂μ, x ∈ Ioc a b → P x) ∧ ∀ᵐ x ∂μ, x ∈ Ioc b a → P x := by simp only [uIoc_eq_union, mem_union, or_imp, eventually_and] theorem measure_union (hd : Disjoint s₁ s₂) (h : MeasurableSet s₂) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ := measure_union₀ h.nullMeasurableSet hd.aedisjoint theorem measure_union' (hd : Disjoint s₁ s₂) (h : MeasurableSet s₁) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ := measure_union₀' h.nullMeasurableSet hd.aedisjoint theorem measure_inter_add_diff (s : Set α) (ht : MeasurableSet t) : μ (s ∩ t) + μ (s \ t) = μ s := measure_inter_add_diff₀ _ ht.nullMeasurableSet theorem measure_diff_add_inter (s : Set α) (ht : MeasurableSet t) : μ (s \ t) + μ (s ∩ t) = μ s := (add_comm _ _).trans (measure_inter_add_diff s ht) theorem measure_diff_eq_top (hs : μ s = ∞) (ht : μ t ≠ ∞) : μ (s \ t) = ∞ := by contrapose! hs exact ((measure_mono (subset_diff_union s t)).trans_lt ((measure_union_le _ _).trans_lt (ENNReal.add_lt_top.2 ⟨hs.lt_top, ht.lt_top⟩))).ne theorem measure_union_add_inter (s : Set α) (ht : MeasurableSet t) : μ (s ∪ t) + μ (s ∩ t) = μ s + μ t := by rw [← measure_inter_add_diff (s ∪ t) ht, Set.union_inter_cancel_right, union_diff_right, ← measure_inter_add_diff s ht] ac_rfl theorem measure_union_add_inter' (hs : MeasurableSet s) (t : Set α) : μ (s ∪ t) + μ (s ∩ t) = μ s + μ t := by rw [union_comm, inter_comm, measure_union_add_inter t hs, add_comm] lemma measure_symmDiff_eq (hs : NullMeasurableSet s μ) (ht : NullMeasurableSet t μ) : μ (s ∆ t) = μ (s \ t) + μ (t \ s) := by simpa only [symmDiff_def, sup_eq_union] using measure_union₀ (ht.diff hs) disjoint_sdiff_sdiff.aedisjoint lemma measure_symmDiff_le (s t u : Set α) : μ (s ∆ u) ≤ μ (s ∆ t) + μ (t ∆ u) := le_trans (μ.mono <| symmDiff_triangle s t u) (measure_union_le (s ∆ t) (t ∆ u)) theorem measure_symmDiff_eq_top (hs : μ s ≠ ∞) (ht : μ t = ∞) : μ (s ∆ t) = ∞ := measure_mono_top subset_union_right (measure_diff_eq_top ht hs) theorem measure_add_measure_compl (h : MeasurableSet s) : μ s + μ sᶜ = μ univ := measure_add_measure_compl₀ h.nullMeasurableSet theorem measure_biUnion₀ {s : Set β} {f : β → Set α} (hs : s.Countable) (hd : s.Pairwise (AEDisjoint μ on f)) (h : ∀ b ∈ s, NullMeasurableSet (f b) μ) : μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) := by haveI := hs.toEncodable rw [biUnion_eq_iUnion] exact measure_iUnion₀ (hd.on_injective Subtype.coe_injective fun x => x.2) fun x => h x x.2 theorem measure_biUnion {s : Set β} {f : β → Set α} (hs : s.Countable) (hd : s.PairwiseDisjoint f) (h : ∀ b ∈ s, MeasurableSet (f b)) : μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) := measure_biUnion₀ hs hd.aedisjoint fun b hb => (h b hb).nullMeasurableSet theorem measure_sUnion₀ {S : Set (Set α)} (hs : S.Countable) (hd : S.Pairwise (AEDisjoint μ)) (h : ∀ s ∈ S, NullMeasurableSet s μ) : μ (⋃₀ S) = ∑' s : S, μ s := by rw [sUnion_eq_biUnion, measure_biUnion₀ hs hd h] theorem measure_sUnion {S : Set (Set α)} (hs : S.Countable) (hd : S.Pairwise Disjoint) (h : ∀ s ∈ S, MeasurableSet s) : μ (⋃₀ S) = ∑' s : S, μ s := by rw [sUnion_eq_biUnion, measure_biUnion hs hd h] theorem measure_biUnion_finset₀ {s : Finset ι} {f : ι → Set α} (hd : Set.Pairwise (↑s) (AEDisjoint μ on f)) (hm : ∀ b ∈ s, NullMeasurableSet (f b) μ) : μ (⋃ b ∈ s, f b) = ∑ p ∈ s, μ (f p) := by rw [← Finset.sum_attach, Finset.attach_eq_univ, ← tsum_fintype] exact measure_biUnion₀ s.countable_toSet hd hm theorem measure_biUnion_finset {s : Finset ι} {f : ι → Set α} (hd : PairwiseDisjoint (↑s) f) (hm : ∀ b ∈ s, MeasurableSet (f b)) : μ (⋃ b ∈ s, f b) = ∑ p ∈ s, μ (f p) := measure_biUnion_finset₀ hd.aedisjoint fun b hb => (hm b hb).nullMeasurableSet /-- The measure of an a.e. disjoint union (even uncountable) of null-measurable sets is at least the sum of the measures of the sets. -/ theorem tsum_meas_le_meas_iUnion_of_disjoint₀ {ι : Type*} {_ : MeasurableSpace α} (μ : Measure α) {As : ι → Set α} (As_mble : ∀ i : ι, NullMeasurableSet (As i) μ) (As_disj : Pairwise (AEDisjoint μ on As)) : (∑' i, μ (As i)) ≤ μ (⋃ i, As i) := by rw [ENNReal.tsum_eq_iSup_sum, iSup_le_iff] intro s simp only [← measure_biUnion_finset₀ (fun _i _hi _j _hj hij => As_disj hij) fun i _ => As_mble i] gcongr exact iUnion_subset fun _ ↦ Subset.rfl /-- The measure of a disjoint union (even uncountable) of measurable sets is at least the sum of the measures of the sets. -/ theorem tsum_meas_le_meas_iUnion_of_disjoint {ι : Type*} {_ : MeasurableSpace α} (μ : Measure α) {As : ι → Set α} (As_mble : ∀ i : ι, MeasurableSet (As i)) (As_disj : Pairwise (Disjoint on As)) : (∑' i, μ (As i)) ≤ μ (⋃ i, As i) := tsum_meas_le_meas_iUnion_of_disjoint₀ μ (fun i ↦ (As_mble i).nullMeasurableSet) (fun _ _ h ↦ Disjoint.aedisjoint (As_disj h)) /-- If `s` is a countable set, then the measure of its preimage can be found as the sum of measures of the fibers `f ⁻¹' {y}`. -/ theorem tsum_measure_preimage_singleton {s : Set β} (hs : s.Countable) {f : α → β} (hf : ∀ y ∈ s, MeasurableSet (f ⁻¹' {y})) : (∑' b : s, μ (f ⁻¹' {↑b})) = μ (f ⁻¹' s) := by rw [← Set.biUnion_preimage_singleton, measure_biUnion hs (pairwiseDisjoint_fiber f s) hf] lemma measure_preimage_eq_zero_iff_of_countable {s : Set β} {f : α → β} (hs : s.Countable) : μ (f ⁻¹' s) = 0 ↔ ∀ x ∈ s, μ (f ⁻¹' {x}) = 0 := by rw [← biUnion_preimage_singleton, measure_biUnion_null_iff hs] /-- If `s` is a `Finset`, then the measure of its preimage can be found as the sum of measures of the fibers `f ⁻¹' {y}`. -/ theorem sum_measure_preimage_singleton (s : Finset β) {f : α → β} (hf : ∀ y ∈ s, MeasurableSet (f ⁻¹' {y})) : (∑ b ∈ s, μ (f ⁻¹' {b})) = μ (f ⁻¹' ↑s) := by simp only [← measure_biUnion_finset (pairwiseDisjoint_fiber f s) hf, Finset.set_biUnion_preimage_singleton] @[simp] lemma sum_measure_singleton {s : Finset α} [MeasurableSingletonClass α] : ∑ x ∈ s, μ {x} = μ s := by trans ∑ x ∈ s, μ (id ⁻¹' {x}) · simp rw [sum_measure_preimage_singleton] · simp · simp theorem measure_diff_null' (h : μ (s₁ ∩ s₂) = 0) : μ (s₁ \ s₂) = μ s₁ := measure_congr <| diff_ae_eq_self.2 h theorem measure_add_diff (hs : NullMeasurableSet s μ) (t : Set α) : μ s + μ (t \ s) = μ (s ∪ t) := by rw [← measure_union₀' hs disjoint_sdiff_right.aedisjoint, union_diff_self] theorem measure_diff' (s : Set α) (hm : NullMeasurableSet t μ) (h_fin : μ t ≠ ∞) : μ (s \ t) = μ (s ∪ t) - μ t := ENNReal.eq_sub_of_add_eq h_fin <| by rw [add_comm, measure_add_diff hm, union_comm] theorem measure_diff (h : s₂ ⊆ s₁) (h₂ : NullMeasurableSet s₂ μ) (h_fin : μ s₂ ≠ ∞) : μ (s₁ \ s₂) = μ s₁ - μ s₂ := by rw [measure_diff' _ h₂ h_fin, union_eq_self_of_subset_right h] theorem le_measure_diff : μ s₁ - μ s₂ ≤ μ (s₁ \ s₂) := tsub_le_iff_left.2 <| (measure_le_inter_add_diff μ s₁ s₂).trans <| by gcongr; apply inter_subset_right /-- If the measure of the symmetric difference of two sets is finite, then one has infinite measure if and only if the other one does. -/ theorem measure_eq_top_iff_of_symmDiff (hμst : μ (s ∆ t) ≠ ∞) : μ s = ∞ ↔ μ t = ∞ := by suffices h : ∀ u v, μ (u ∆ v) ≠ ∞ → μ u = ∞ → μ v = ∞ from ⟨h s t hμst, h t s (symmDiff_comm s t ▸ hμst)⟩ intro u v hμuv hμu by_contra! hμv apply hμuv rw [Set.symmDiff_def, eq_top_iff] calc ∞ = μ u - μ v := by rw [ENNReal.sub_eq_top_iff.2 ⟨hμu, hμv⟩] _ ≤ μ (u \ v) := le_measure_diff _ ≤ μ (u \ v ∪ v \ u) := measure_mono subset_union_left /-- If the measure of the symmetric difference of two sets is finite, then one has finite measure if and only if the other one does. -/ theorem measure_ne_top_iff_of_symmDiff (hμst : μ (s ∆ t) ≠ ∞) : μ s ≠ ∞ ↔ μ t ≠ ∞ := (measure_eq_top_iff_of_symmDiff hμst).ne theorem measure_diff_lt_of_lt_add (hs : NullMeasurableSet s μ) (hst : s ⊆ t) (hs' : μ s ≠ ∞) {ε : ℝ≥0∞} (h : μ t < μ s + ε) : μ (t \ s) < ε := by rw [measure_diff hst hs hs']; rw [add_comm] at h exact ENNReal.sub_lt_of_lt_add (measure_mono hst) h theorem measure_diff_le_iff_le_add (hs : NullMeasurableSet s μ) (hst : s ⊆ t) (hs' : μ s ≠ ∞) {ε : ℝ≥0∞} : μ (t \ s) ≤ ε ↔ μ t ≤ μ s + ε := by rw [measure_diff hst hs hs', tsub_le_iff_left] theorem measure_eq_measure_of_null_diff {s t : Set α} (hst : s ⊆ t) (h_nulldiff : μ (t \ s) = 0) : μ s = μ t := measure_congr <| EventuallyLE.antisymm (HasSubset.Subset.eventuallyLE hst) (ae_le_set.mpr h_nulldiff) theorem measure_eq_measure_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₁ = μ s₂ ∧ μ s₂ = μ s₃ := by have le12 : μ s₁ ≤ μ s₂ := measure_mono h12 have le23 : μ s₂ ≤ μ s₃ := measure_mono h23 have key : μ s₃ ≤ μ s₁ := calc μ s₃ = μ (s₃ \ s₁ ∪ s₁) := by rw [diff_union_of_subset (h12.trans h23)] _ ≤ μ (s₃ \ s₁) + μ s₁ := measure_union_le _ _ _ = μ s₁ := by simp only [h_nulldiff, zero_add] exact ⟨le12.antisymm (le23.trans key), le23.antisymm (key.trans le12)⟩ theorem measure_eq_measure_smaller_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₁ = μ s₂ := (measure_eq_measure_of_between_null_diff h12 h23 h_nulldiff).1 theorem measure_eq_measure_larger_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₂ = μ s₃ := (measure_eq_measure_of_between_null_diff h12 h23 h_nulldiff).2 lemma measure_compl₀ (h : NullMeasurableSet s μ) (hs : μ s ≠ ∞) : μ sᶜ = μ Set.univ - μ s := by rw [← measure_add_measure_compl₀ h, ENNReal.add_sub_cancel_left hs] theorem measure_compl (h₁ : MeasurableSet s) (h_fin : μ s ≠ ∞) : μ sᶜ = μ univ - μ s := measure_compl₀ h₁.nullMeasurableSet h_fin lemma measure_inter_conull' (ht : μ (s \ t) = 0) : μ (s ∩ t) = μ s := by rw [← diff_compl, measure_diff_null']; rwa [← diff_eq] lemma measure_inter_conull (ht : μ tᶜ = 0) : μ (s ∩ t) = μ s := by rw [← diff_compl, measure_diff_null ht] @[simp] theorem union_ae_eq_left_iff_ae_subset : (s ∪ t : Set α) =ᵐ[μ] s ↔ t ≤ᵐ[μ] s := by rw [ae_le_set] refine ⟨fun h => by simpa only [union_diff_left] using (ae_eq_set.mp h).1, fun h => eventuallyLE_antisymm_iff.mpr ⟨by rwa [ae_le_set, union_diff_left], HasSubset.Subset.eventuallyLE subset_union_left⟩⟩ @[simp] theorem union_ae_eq_right_iff_ae_subset : (s ∪ t : Set α) =ᵐ[μ] t ↔ s ≤ᵐ[μ] t := by rw [union_comm, union_ae_eq_left_iff_ae_subset] theorem ae_eq_of_ae_subset_of_measure_ge (h₁ : s ≤ᵐ[μ] t) (h₂ : μ t ≤ μ s) (hsm : NullMeasurableSet s μ) (ht : μ t ≠ ∞) : s =ᵐ[μ] t := by refine eventuallyLE_antisymm_iff.mpr ⟨h₁, ae_le_set.mpr ?_⟩ replace h₂ : μ t = μ s := h₂.antisymm (measure_mono_ae h₁) replace ht : μ s ≠ ∞ := h₂ ▸ ht rw [measure_diff' t hsm ht, measure_congr (union_ae_eq_left_iff_ae_subset.mpr h₁), h₂, tsub_self] /-- If `s ⊆ t`, `μ t ≤ μ s`, `μ t ≠ ∞`, and `s` is measurable, then `s =ᵐ[μ] t`. -/ theorem ae_eq_of_subset_of_measure_ge (h₁ : s ⊆ t) (h₂ : μ t ≤ μ s) (hsm : NullMeasurableSet s μ) (ht : μ t ≠ ∞) : s =ᵐ[μ] t := ae_eq_of_ae_subset_of_measure_ge (HasSubset.Subset.eventuallyLE h₁) h₂ hsm ht theorem measure_iUnion_congr_of_subset {ι : Sort*} [Countable ι] {s : ι → Set α} {t : ι → Set α} (hsub : ∀ i, s i ⊆ t i) (h_le : ∀ i, μ (t i) ≤ μ (s i)) : μ (⋃ i, s i) = μ (⋃ i, t i) := by refine le_antisymm (by gcongr; apply hsub) ?_ rcases Classical.em (∃ i, μ (t i) = ∞) with (⟨i, hi⟩ | htop) · calc μ (⋃ i, t i) ≤ ∞ := le_top _ ≤ μ (s i) := hi ▸ h_le i _ ≤ μ (⋃ i, s i) := measure_mono <| subset_iUnion _ _ push_neg at htop set M := toMeasurable μ have H : ∀ b, (M (t b) ∩ M (⋃ b, s b) : Set α) =ᵐ[μ] M (t b) := by refine fun b => ae_eq_of_subset_of_measure_ge inter_subset_left ?_ ?_ ?_ · calc μ (M (t b)) = μ (t b) := measure_toMeasurable _ _ ≤ μ (s b) := h_le b _ ≤ μ (M (t b) ∩ M (⋃ b, s b)) := measure_mono <| subset_inter ((hsub b).trans <| subset_toMeasurable _ _) ((subset_iUnion _ _).trans <| subset_toMeasurable _ _) · measurability · rw [measure_toMeasurable] exact htop b calc μ (⋃ b, t b) ≤ μ (⋃ b, M (t b)) := measure_mono (iUnion_mono fun b => subset_toMeasurable _ _) _ = μ (⋃ b, M (t b) ∩ M (⋃ b, s b)) := measure_congr (EventuallyEq.countable_iUnion H).symm _ ≤ μ (M (⋃ b, s b)) := measure_mono (iUnion_subset fun b => inter_subset_right) _ = μ (⋃ b, s b) := measure_toMeasurable _ theorem measure_union_congr_of_subset {t₁ t₂ : Set α} (hs : s₁ ⊆ s₂) (hsμ : μ s₂ ≤ μ s₁) (ht : t₁ ⊆ t₂) (htμ : μ t₂ ≤ μ t₁) : μ (s₁ ∪ t₁) = μ (s₂ ∪ t₂) := by rw [union_eq_iUnion, union_eq_iUnion] exact measure_iUnion_congr_of_subset (Bool.forall_bool.2 ⟨ht, hs⟩) (Bool.forall_bool.2 ⟨htμ, hsμ⟩) @[simp] theorem measure_iUnion_toMeasurable {ι : Sort*} [Countable ι] (s : ι → Set α) : μ (⋃ i, toMeasurable μ (s i)) = μ (⋃ i, s i) := Eq.symm <| measure_iUnion_congr_of_subset (fun _i => subset_toMeasurable _ _) fun _i ↦ (measure_toMeasurable _).le theorem measure_biUnion_toMeasurable {I : Set β} (hc : I.Countable) (s : β → Set α) : μ (⋃ b ∈ I, toMeasurable μ (s b)) = μ (⋃ b ∈ I, s b) := by haveI := hc.toEncodable simp only [biUnion_eq_iUnion, measure_iUnion_toMeasurable] @[simp] theorem measure_toMeasurable_union : μ (toMeasurable μ s ∪ t) = μ (s ∪ t) := Eq.symm <| measure_union_congr_of_subset (subset_toMeasurable _ _) (measure_toMeasurable _).le Subset.rfl le_rfl @[simp] theorem measure_union_toMeasurable : μ (s ∪ toMeasurable μ t) = μ (s ∪ t) := Eq.symm <| measure_union_congr_of_subset Subset.rfl le_rfl (subset_toMeasurable _ _) (measure_toMeasurable _).le theorem sum_measure_le_measure_univ {s : Finset ι} {t : ι → Set α} (h : ∀ i ∈ s, NullMeasurableSet (t i) μ) (H : Set.Pairwise s (AEDisjoint μ on t)) : (∑ i ∈ s, μ (t i)) ≤ μ (univ : Set α) := by rw [← measure_biUnion_finset₀ H h] exact measure_mono (subset_univ _) theorem tsum_measure_le_measure_univ {s : ι → Set α} (hs : ∀ i, NullMeasurableSet (s i) μ) (H : Pairwise (AEDisjoint μ on s)) : ∑' i, μ (s i) ≤ μ (univ : Set α) := by rw [ENNReal.tsum_eq_iSup_sum] exact iSup_le fun s => sum_measure_le_measure_univ (fun i _hi => hs i) fun i _hi j _hj hij => H hij /-- Pigeonhole principle for measure spaces: if `∑' i, μ (s i) > μ univ`, then one of the intersections `s i ∩ s j` is not empty. -/ theorem exists_nonempty_inter_of_measure_univ_lt_tsum_measure {m : MeasurableSpace α} (μ : Measure α) {s : ι → Set α} (hs : ∀ i, NullMeasurableSet (s i) μ) (H : μ (univ : Set α) < ∑' i, μ (s i)) : ∃ i j, i ≠ j ∧ (s i ∩ s j).Nonempty := by contrapose! H apply tsum_measure_le_measure_univ hs intro i j hij exact (disjoint_iff_inter_eq_empty.mpr (H i j hij)).aedisjoint /-- Pigeonhole principle for measure spaces: if `s` is a `Finset` and `∑ i ∈ s, μ (t i) > μ univ`, then one of the intersections `t i ∩ t j` is not empty. -/ theorem exists_nonempty_inter_of_measure_univ_lt_sum_measure {m : MeasurableSpace α} (μ : Measure α) {s : Finset ι} {t : ι → Set α} (h : ∀ i ∈ s, NullMeasurableSet (t i) μ) (H : μ (univ : Set α) < ∑ i ∈ s, μ (t i)) : ∃ i ∈ s, ∃ j ∈ s, ∃ _h : i ≠ j, (t i ∩ t j).Nonempty := by contrapose! H apply sum_measure_le_measure_univ h intro i hi j hj hij exact (disjoint_iff_inter_eq_empty.mpr (H i hi j hj hij)).aedisjoint /-- If two sets `s` and `t` are included in a set `u`, and `μ s + μ t > μ u`, then `s` intersects `t`. Version assuming that `t` is measurable. -/ theorem nonempty_inter_of_measure_lt_add {m : MeasurableSpace α} (μ : Measure α) {s t u : Set α} (ht : MeasurableSet t) (h's : s ⊆ u) (h't : t ⊆ u) (h : μ u < μ s + μ t) : (s ∩ t).Nonempty := by rw [← Set.not_disjoint_iff_nonempty_inter] contrapose! h
calc μ s + μ t = μ (s ∪ t) := (measure_union h ht).symm _ ≤ μ u := measure_mono (union_subset h's h't) /-- If two sets `s` and `t` are included in a set `u`, and `μ s + μ t > μ u`, then `s` intersects `t`. Version assuming that `s` is measurable. -/ theorem nonempty_inter_of_measure_lt_add' {m : MeasurableSpace α} (μ : Measure α) {s t u : Set α}
Mathlib/MeasureTheory/Measure/MeasureSpace.lean
425
431
/- Copyright (c) 2021 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.Convex.Topology import Mathlib.Analysis.NormedSpace.Pointwise import Mathlib.Analysis.Seminorm import Mathlib.Analysis.LocallyConvex.Bounded import Mathlib.Analysis.RCLike.Basic /-! # The Minkowski functional This file defines the Minkowski functional, aka gauge. The Minkowski functional of a set `s` is the function which associates each point to how much you need to scale `s` for `x` to be inside it. When `s` is symmetric, convex and absorbent, its gauge is a seminorm. Reciprocally, any seminorm arises as the gauge of some set, namely its unit ball. This induces the equivalence of seminorms and locally convex topological vector spaces. ## Main declarations For a real vector space, * `gauge`: Aka Minkowski functional. `gauge s x` is the least (actually, an infimum) `r` such that `x ∈ r • s`. * `gaugeSeminorm`: The Minkowski functional as a seminorm, when `s` is symmetric, convex and absorbent. ## References * [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966] ## Tags Minkowski functional, gauge -/ open NormedField Set open scoped Pointwise Topology NNReal noncomputable section variable {𝕜 E : Type*} section AddCommGroup variable [AddCommGroup E] [Module ℝ E] /-- The Minkowski functional. Given a set `s` in a real vector space, `gauge s` is the functional which sends `x : E` to the smallest `r : ℝ` such that `x` is in `s` scaled by `r`. -/ def gauge (s : Set E) (x : E) : ℝ := sInf { r : ℝ | 0 < r ∧ x ∈ r • s } variable {s t : Set E} {x : E} {a : ℝ} theorem gauge_def : gauge s x = sInf ({ r ∈ Set.Ioi (0 : ℝ) | x ∈ r • s }) := rfl /-- An alternative definition of the gauge using scalar multiplication on the element rather than on the set. -/ theorem gauge_def' : gauge s x = sInf {r ∈ Set.Ioi (0 : ℝ) | r⁻¹ • x ∈ s} := by congrm sInf {r | ?_} exact and_congr_right fun hr => mem_smul_set_iff_inv_smul_mem₀ hr.ne' _ _ private theorem gauge_set_bddBelow : BddBelow { r : ℝ | 0 < r ∧ x ∈ r • s } := ⟨0, fun _ hr => hr.1.le⟩ /-- If the given subset is `Absorbent` then the set we take an infimum over in `gauge` is nonempty, which is useful for proving many properties about the gauge. -/ theorem Absorbent.gauge_set_nonempty (absorbs : Absorbent ℝ s) : { r : ℝ | 0 < r ∧ x ∈ r • s }.Nonempty := let ⟨r, hr₁, hr₂⟩ := (absorbs x).exists_pos ⟨r, hr₁, hr₂ r (Real.norm_of_nonneg hr₁.le).ge rfl⟩ theorem gauge_mono (hs : Absorbent ℝ s) (h : s ⊆ t) : gauge t ≤ gauge s := fun _ => csInf_le_csInf gauge_set_bddBelow hs.gauge_set_nonempty fun _ hr => ⟨hr.1, smul_set_mono h hr.2⟩ theorem exists_lt_of_gauge_lt (absorbs : Absorbent ℝ s) (h : gauge s x < a) : ∃ b, 0 < b ∧ b < a ∧ x ∈ b • s := by obtain ⟨b, ⟨hb, hx⟩, hba⟩ := exists_lt_of_csInf_lt absorbs.gauge_set_nonempty h exact ⟨b, hb, hba, hx⟩ /-- The gauge evaluated at `0` is always zero (mathematically this requires `0` to be in the set `s` but, the real infimum of the empty set in Lean being defined as `0`, it holds unconditionally). -/ @[simp] theorem gauge_zero : gauge s 0 = 0 := by rw [gauge_def'] by_cases h : (0 : E) ∈ s · simp only [smul_zero, sep_true, h, csInf_Ioi] · simp only [smul_zero, sep_false, h, Real.sInf_empty] @[simp] theorem gauge_zero' : gauge (0 : Set E) = 0 := by ext x rw [gauge_def'] obtain rfl | hx := eq_or_ne x 0 · simp only [csInf_Ioi, mem_zero, Pi.zero_apply, eq_self_iff_true, sep_true, smul_zero] · simp only [mem_zero, Pi.zero_apply, inv_eq_zero, smul_eq_zero] convert Real.sInf_empty exact eq_empty_iff_forall_not_mem.2 fun r hr => hr.2.elim (ne_of_gt hr.1) hx @[simp] theorem gauge_empty : gauge (∅ : Set E) = 0 := by ext simp only [gauge_def', Real.sInf_empty, mem_empty_iff_false, Pi.zero_apply, sep_false] theorem gauge_of_subset_zero (h : s ⊆ 0) : gauge s = 0 := by obtain rfl | rfl := subset_singleton_iff_eq.1 h exacts [gauge_empty, gauge_zero'] /-- The gauge is always nonnegative. -/ theorem gauge_nonneg (x : E) : 0 ≤ gauge s x := Real.sInf_nonneg fun _ hx => hx.1.le theorem gauge_neg (symmetric : ∀ x ∈ s, -x ∈ s) (x : E) : gauge s (-x) = gauge s x := by have : ∀ x, -x ∈ s ↔ x ∈ s := fun x => ⟨fun h => by simpa using symmetric _ h, symmetric x⟩ simp_rw [gauge_def', smul_neg, this] theorem gauge_neg_set_neg (x : E) : gauge (-s) (-x) = gauge s x := by simp_rw [gauge_def', smul_neg, neg_mem_neg] theorem gauge_neg_set_eq_gauge_neg (x : E) : gauge (-s) x = gauge s (-x) := by rw [← gauge_neg_set_neg, neg_neg] theorem gauge_le_of_mem (ha : 0 ≤ a) (hx : x ∈ a • s) : gauge s x ≤ a := by obtain rfl | ha' := ha.eq_or_lt · rw [mem_singleton_iff.1 (zero_smul_set_subset _ hx), gauge_zero] · exact csInf_le gauge_set_bddBelow ⟨ha', hx⟩ theorem gauge_le_eq (hs₁ : Convex ℝ s) (hs₀ : (0 : E) ∈ s) (hs₂ : Absorbent ℝ s) (ha : 0 ≤ a) : { x | gauge s x ≤ a } = ⋂ (r : ℝ) (_ : a < r), r • s := by ext x simp_rw [Set.mem_iInter, Set.mem_setOf_eq] refine ⟨fun h r hr => ?_, fun h => le_of_forall_pos_lt_add fun ε hε => ?_⟩ · have hr' := ha.trans_lt hr rw [mem_smul_set_iff_inv_smul_mem₀ hr'.ne'] obtain ⟨δ, δ_pos, hδr, hδ⟩ := exists_lt_of_gauge_lt hs₂ (h.trans_lt hr) suffices (r⁻¹ * δ) • δ⁻¹ • x ∈ s by rwa [smul_smul, mul_inv_cancel_right₀ δ_pos.ne'] at this rw [mem_smul_set_iff_inv_smul_mem₀ δ_pos.ne'] at hδ refine hs₁.smul_mem_of_zero_mem hs₀ hδ ⟨by positivity, ?_⟩ rw [inv_mul_le_iff₀ hr', mul_one] exact hδr.le · have hε' := (lt_add_iff_pos_right a).2 (half_pos hε) exact (gauge_le_of_mem (ha.trans hε'.le) <| h _ hε').trans_lt (add_lt_add_left (half_lt_self hε) _) theorem gauge_lt_eq' (absorbs : Absorbent ℝ s) (a : ℝ) : { x | gauge s x < a } = ⋃ (r : ℝ) (_ : 0 < r) (_ : r < a), r • s := by ext simp_rw [mem_setOf, mem_iUnion, exists_prop] exact ⟨exists_lt_of_gauge_lt absorbs, fun ⟨r, hr₀, hr₁, hx⟩ => (gauge_le_of_mem hr₀.le hx).trans_lt hr₁⟩ theorem gauge_lt_eq (absorbs : Absorbent ℝ s) (a : ℝ) : { x | gauge s x < a } = ⋃ r ∈ Set.Ioo 0 (a : ℝ), r • s := by ext simp_rw [mem_setOf, mem_iUnion, exists_prop, mem_Ioo, and_assoc] exact ⟨exists_lt_of_gauge_lt absorbs, fun ⟨r, hr₀, hr₁, hx⟩ => (gauge_le_of_mem hr₀.le hx).trans_lt hr₁⟩ theorem mem_openSegment_of_gauge_lt_one (absorbs : Absorbent ℝ s) (hgauge : gauge s x < 1) : ∃ y ∈ s, x ∈ openSegment ℝ 0 y := by rcases exists_lt_of_gauge_lt absorbs hgauge with ⟨r, hr₀, hr₁, y, hy, rfl⟩ refine ⟨y, hy, 1 - r, r, ?_⟩ simp [*] theorem gauge_lt_one_subset_self (hs : Convex ℝ s) (h₀ : (0 : E) ∈ s) (absorbs : Absorbent ℝ s) : { x | gauge s x < 1 } ⊆ s := fun _x hx ↦ let ⟨_y, hys, hx⟩ := mem_openSegment_of_gauge_lt_one absorbs hx hs.openSegment_subset h₀ hys hx theorem gauge_le_one_of_mem {x : E} (hx : x ∈ s) : gauge s x ≤ 1 := gauge_le_of_mem zero_le_one <| by rwa [one_smul] /-- Gauge is subadditive. -/ theorem gauge_add_le (hs : Convex ℝ s) (absorbs : Absorbent ℝ s) (x y : E) : gauge s (x + y) ≤ gauge s x + gauge s y := by refine le_of_forall_pos_lt_add fun ε hε => ?_ obtain ⟨a, ha, ha', x, hx, rfl⟩ := exists_lt_of_gauge_lt absorbs (lt_add_of_pos_right (gauge s x) (half_pos hε)) obtain ⟨b, hb, hb', y, hy, rfl⟩ := exists_lt_of_gauge_lt absorbs (lt_add_of_pos_right (gauge s y) (half_pos hε)) calc gauge s (a • x + b • y) ≤ a + b := gauge_le_of_mem (by positivity) <| by rw [hs.add_smul ha.le hb.le] exact add_mem_add (smul_mem_smul_set hx) (smul_mem_smul_set hy) _ < gauge s (a • x) + gauge s (b • y) + ε := by linarith theorem self_subset_gauge_le_one : s ⊆ { x | gauge s x ≤ 1 } := fun _ => gauge_le_one_of_mem theorem Convex.gauge_le (hs : Convex ℝ s) (h₀ : (0 : E) ∈ s) (absorbs : Absorbent ℝ s) (a : ℝ) : Convex ℝ { x | gauge s x ≤ a } := by by_cases ha : 0 ≤ a · rw [gauge_le_eq hs h₀ absorbs ha] exact convex_iInter fun i => convex_iInter fun _ => hs.smul _ · convert convex_empty (𝕜 := ℝ) exact eq_empty_iff_forall_not_mem.2 fun x hx => ha <| (gauge_nonneg _).trans hx theorem Balanced.starConvex (hs : Balanced ℝ s) : StarConvex ℝ 0 s := starConvex_zero_iff.2 fun _ hx a ha₀ ha₁ => hs _ (by rwa [Real.norm_of_nonneg ha₀]) (smul_mem_smul_set hx) theorem le_gauge_of_not_mem (hs₀ : StarConvex ℝ 0 s) (hs₂ : Absorbs ℝ s {x}) (hx : x ∉ a • s) : a ≤ gauge s x := by rw [starConvex_zero_iff] at hs₀ obtain ⟨r, hr, h⟩ := hs₂.exists_pos refine le_csInf ⟨r, hr, singleton_subset_iff.1 <| h _ (Real.norm_of_nonneg hr.le).ge⟩ ?_ rintro b ⟨hb, x, hx', rfl⟩ refine not_lt.1 fun hba => hx ?_ have ha := hb.trans hba refine ⟨(a⁻¹ * b) • x, hs₀ hx' (by positivity) ?_, ?_⟩ · rw [← div_eq_inv_mul] exact div_le_one_of_le₀ hba.le ha.le · dsimp only rw [← mul_smul, mul_inv_cancel_left₀ ha.ne'] theorem one_le_gauge_of_not_mem (hs₁ : StarConvex ℝ 0 s) (hs₂ : Absorbs ℝ s {x}) (hx : x ∉ s) : 1 ≤ gauge s x := le_gauge_of_not_mem hs₁ hs₂ <| by rwa [one_smul] section LinearOrderedField variable {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α] [MulActionWithZero α ℝ] [OrderedSMul α ℝ] theorem gauge_smul_of_nonneg [MulActionWithZero α E] [IsScalarTower α ℝ (Set E)] {s : Set E} {a : α} (ha : 0 ≤ a) (x : E) : gauge s (a • x) = a • gauge s x := by obtain rfl | ha' := ha.eq_or_lt · rw [zero_smul, gauge_zero, zero_smul] rw [gauge_def', gauge_def', ← Real.sInf_smul_of_nonneg ha] congr 1 ext r simp_rw [Set.mem_smul_set, Set.mem_sep_iff] constructor · rintro ⟨hr, hx⟩ simp_rw [mem_Ioi] at hr ⊢ rw [← mem_smul_set_iff_inv_smul_mem₀ hr.ne'] at hx have := smul_pos (inv_pos.2 ha') hr refine ⟨a⁻¹ • r, ⟨this, ?_⟩, smul_inv_smul₀ ha'.ne' _⟩ rwa [← mem_smul_set_iff_inv_smul_mem₀ this.ne', smul_assoc, mem_smul_set_iff_inv_smul_mem₀ (inv_ne_zero ha'.ne'), inv_inv] · rintro ⟨r, ⟨hr, hx⟩, rfl⟩ rw [mem_Ioi] at hr ⊢ rw [← mem_smul_set_iff_inv_smul_mem₀ hr.ne'] at hx have := smul_pos ha' hr refine ⟨this, ?_⟩ rw [← mem_smul_set_iff_inv_smul_mem₀ this.ne', smul_assoc] exact smul_mem_smul_set hx theorem gauge_smul_left_of_nonneg [MulActionWithZero α E] [SMulCommClass α ℝ ℝ] [IsScalarTower α ℝ ℝ] [IsScalarTower α ℝ E] {s : Set E} {a : α} (ha : 0 ≤ a) : gauge (a • s) = a⁻¹ • gauge s := by obtain rfl | ha' := ha.eq_or_lt · rw [inv_zero, zero_smul, gauge_of_subset_zero (zero_smul_set_subset _)] ext x rw [gauge_def', Pi.smul_apply, gauge_def', ← Real.sInf_smul_of_nonneg (inv_nonneg.2 ha)] congr 1 ext r simp_rw [Set.mem_smul_set, Set.mem_sep_iff] constructor · rintro ⟨hr, y, hy, h⟩ simp_rw [mem_Ioi] at hr ⊢ refine ⟨a • r, ⟨smul_pos ha' hr, ?_⟩, inv_smul_smul₀ ha'.ne' _⟩ rwa [smul_inv₀, smul_assoc, ← h, inv_smul_smul₀ ha'.ne'] · rintro ⟨r, ⟨hr, hx⟩, rfl⟩ rw [mem_Ioi] at hr ⊢ refine ⟨smul_pos (inv_pos.2 ha') hr, r⁻¹ • x, hx, ?_⟩ rw [smul_inv₀, smul_assoc, inv_inv] theorem gauge_smul_left [Module α E] [SMulCommClass α ℝ ℝ] [IsScalarTower α ℝ ℝ] [IsScalarTower α ℝ E] {s : Set E} (symmetric : ∀ x ∈ s, -x ∈ s) (a : α) : gauge (a • s) = |a|⁻¹ • gauge s := by rw [← gauge_smul_left_of_nonneg (abs_nonneg a)] obtain h | h := abs_choice a · rw [h] · rw [h, Set.neg_smul_set, ← Set.smul_set_neg] -- Porting note: was congr apply congr_arg apply congr_arg ext y refine ⟨symmetric _, fun hy => ?_⟩ rw [← neg_neg y] exact symmetric _ hy end LinearOrderedField section RCLike variable [RCLike 𝕜] [Module 𝕜 E] [IsScalarTower ℝ 𝕜 E] theorem gauge_norm_smul (hs : Balanced 𝕜 s) (r : 𝕜) (x : E) : gauge s (‖r‖ • x) = gauge s (r • x) := by unfold gauge congr with θ rw [@RCLike.real_smul_eq_coe_smul 𝕜] refine and_congr_right fun hθ => (hs.smul _).smul_mem_iff ?_ rw [RCLike.norm_ofReal, abs_norm] /-- If `s` is balanced, then the Minkowski functional is ℂ-homogeneous. -/ theorem gauge_smul (hs : Balanced 𝕜 s) (r : 𝕜) (x : E) : gauge s (r • x) = ‖r‖ * gauge s x := by rw [← smul_eq_mul, ← gauge_smul_of_nonneg (norm_nonneg r), gauge_norm_smul hs] end RCLike open Filter section TopologicalSpace variable [TopologicalSpace E] theorem comap_gauge_nhds_zero_le (ha : Absorbent ℝ s) (hb : Bornology.IsVonNBounded ℝ s) : comap (gauge s) (𝓝 0) ≤ 𝓝 0 := fun u hu ↦ by rcases (hb hu).exists_pos with ⟨r, hr₀, hr⟩ filter_upwards [preimage_mem_comap (gt_mem_nhds (inv_pos.2 hr₀))] with x (hx : gauge s x < r⁻¹) rcases exists_lt_of_gauge_lt ha hx with ⟨c, hc₀, hcr, y, hy, rfl⟩ have hrc := (lt_inv_comm₀ hr₀ hc₀).2 hcr rcases hr c⁻¹ (hrc.le.trans (le_abs_self _)) hy with ⟨z, hz, rfl⟩ simpa only [smul_inv_smul₀ hc₀.ne'] variable [T1Space E] theorem gauge_eq_zero (hs : Absorbent ℝ s) (hb : Bornology.IsVonNBounded ℝ s) : gauge s x = 0 ↔ x = 0 := by refine ⟨fun h₀ ↦ by_contra fun (hne : x ≠ 0) ↦ ?_, fun h ↦ h.symm ▸ gauge_zero⟩ have : {x}ᶜ ∈ comap (gauge s) (𝓝 0) := comap_gauge_nhds_zero_le hs hb (isOpen_compl_singleton.mem_nhds hne.symm) rcases ((nhds_basis_zero_abs_lt _).comap _).mem_iff.1 this with ⟨r, hr₀, hr⟩ exact hr (by simpa [h₀]) rfl theorem gauge_pos (hs : Absorbent ℝ s) (hb : Bornology.IsVonNBounded ℝ s) : 0 < gauge s x ↔ x ≠ 0 := by simp only [(gauge_nonneg _).gt_iff_ne, Ne, gauge_eq_zero hs hb] end TopologicalSpace section ContinuousSMul variable [TopologicalSpace E] [ContinuousSMul ℝ E] open Filter in theorem interior_subset_gauge_lt_one (s : Set E) : interior s ⊆ { x | gauge s x < 1 } := by intro x hx have H₁ : Tendsto (fun r : ℝ ↦ r⁻¹ • x) (𝓝[<] 1) (𝓝 ((1 : ℝ)⁻¹ • x)) := ((tendsto_id.inv₀ one_ne_zero).smul tendsto_const_nhds).mono_left inf_le_left rw [inv_one, one_smul] at H₁ have H₂ : ∀ᶠ r in 𝓝[<] (1 : ℝ), x ∈ r • s ∧ 0 < r ∧ r < 1 := by filter_upwards [H₁ (mem_interior_iff_mem_nhds.1 hx), Ioo_mem_nhdsLT one_pos] with r h₁ h₂ exact ⟨(mem_smul_set_iff_inv_smul_mem₀ h₂.1.ne' _ _).2 h₁, h₂⟩ rcases H₂.exists with ⟨r, hxr, hr₀, hr₁⟩ exact (gauge_le_of_mem hr₀.le hxr).trans_lt hr₁ theorem gauge_lt_one_eq_self_of_isOpen (hs₁ : Convex ℝ s) (hs₀ : (0 : E) ∈ s) (hs₂ : IsOpen s) : { x | gauge s x < 1 } = s := by refine (gauge_lt_one_subset_self hs₁ ‹_› <| absorbent_nhds_zero <| hs₂.mem_nhds hs₀).antisymm ?_ convert interior_subset_gauge_lt_one s exact hs₂.interior_eq.symm theorem gauge_lt_one_of_mem_of_isOpen (hs₂ : IsOpen s) {x : E} (hx : x ∈ s) : gauge s x < 1 := interior_subset_gauge_lt_one s <| by rwa [hs₂.interior_eq] theorem gauge_lt_of_mem_smul (x : E) (ε : ℝ) (hε : 0 < ε) (hs₂ : IsOpen s) (hx : x ∈ ε • s) : gauge s x < ε := by have : ε⁻¹ • x ∈ s := by rwa [← mem_smul_set_iff_inv_smul_mem₀ hε.ne'] have h_gauge_lt := gauge_lt_one_of_mem_of_isOpen hs₂ this rwa [gauge_smul_of_nonneg (inv_nonneg.2 hε.le), smul_eq_mul, inv_mul_lt_iff₀ hε, mul_one] at h_gauge_lt theorem mem_closure_of_gauge_le_one (hc : Convex ℝ s) (hs₀ : 0 ∈ s) (ha : Absorbent ℝ s) (h : gauge s x ≤ 1) : x ∈ closure s := by have : ∀ᶠ r : ℝ in 𝓝[<] 1, r • x ∈ s := by filter_upwards [Ico_mem_nhdsLT one_pos] with r ⟨hr₀, hr₁⟩ apply gauge_lt_one_subset_self hc hs₀ ha rw [mem_setOf_eq, gauge_smul_of_nonneg hr₀] exact mul_lt_one_of_nonneg_of_lt_one_left hr₀ hr₁ h refine mem_closure_of_tendsto ?_ this exact Filter.Tendsto.mono_left (Continuous.tendsto' (by fun_prop) _ _ (one_smul _ _)) inf_le_left theorem mem_frontier_of_gauge_eq_one (hc : Convex ℝ s) (hs₀ : 0 ∈ s) (ha : Absorbent ℝ s) (h : gauge s x = 1) : x ∈ frontier s := ⟨mem_closure_of_gauge_le_one hc hs₀ ha h.le, fun h' ↦ (interior_subset_gauge_lt_one s h').out.ne h⟩ theorem tendsto_gauge_nhds_zero_nhdsGE (hs : s ∈ 𝓝 0) : Tendsto (gauge s) (𝓝 0) (𝓝[≥] 0) := by refine nhdsGE_basis_Icc.tendsto_right_iff.2 fun ε hε ↦ ?_ rw [← set_smul_mem_nhds_zero_iff hε.ne'] at hs filter_upwards [hs] with x hx exact ⟨gauge_nonneg _, gauge_le_of_mem hε.le hx⟩ @[deprecated (since := "2025-03-02")] alias tendsto_gauge_nhds_zero' := tendsto_gauge_nhds_zero_nhdsGE theorem tendsto_gauge_nhds_zero (hs : s ∈ 𝓝 0) : Tendsto (gauge s) (𝓝 0) (𝓝 0) := (tendsto_gauge_nhds_zero_nhdsGE hs).mono_right inf_le_left /-- If `s` is a neighborhood of the origin, then `gauge s` is continuous at the origin. See also `continuousAt_gauge`. -/ theorem continuousAt_gauge_zero (hs : s ∈ 𝓝 0) : ContinuousAt (gauge s) 0 := by rw [ContinuousAt, gauge_zero] exact tendsto_gauge_nhds_zero hs theorem comap_gauge_nhds_zero (hb : Bornology.IsVonNBounded ℝ s) (h₀ : s ∈ 𝓝 0) : comap (gauge s) (𝓝 0) = 𝓝 0 := (comap_gauge_nhds_zero_le (absorbent_nhds_zero h₀) hb).antisymm (tendsto_gauge_nhds_zero h₀).le_comap end ContinuousSMul section TopologicalVectorSpace open Filter variable [TopologicalSpace E] [IsTopologicalAddGroup E] [ContinuousSMul ℝ E] /-- If `s` is a convex neighborhood of the origin in a topological real vector space, then `gauge s` is continuous. If the ambient space is a normed space, then `gauge s` is Lipschitz continuous, see `Convex.lipschitz_gauge`. -/ theorem continuousAt_gauge (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) : ContinuousAt (gauge s) x := by have ha : Absorbent ℝ s := absorbent_nhds_zero hs₀ refine (nhds_basis_Icc_pos _).tendsto_right_iff.2 fun ε hε₀ ↦ ?_ rw [← map_add_left_nhds_zero, eventually_map] have : ε • s ∩ -(ε • s) ∈ 𝓝 0 := inter_mem ((set_smul_mem_nhds_zero_iff hε₀.ne').2 hs₀) (neg_mem_nhds_zero _ ((set_smul_mem_nhds_zero_iff hε₀.ne').2 hs₀)) filter_upwards [this] with y hy constructor · rw [sub_le_iff_le_add] calc gauge s x = gauge s (x + y + (-y)) := by simp _ ≤ gauge s (x + y) + gauge s (-y) := gauge_add_le hc ha _ _ _ ≤ gauge s (x + y) + ε := add_le_add_left (gauge_le_of_mem hε₀.le (mem_neg.1 hy.2)) _ · calc gauge s (x + y) ≤ gauge s x + gauge s y := gauge_add_le hc ha _ _ _ ≤ gauge s x + ε := add_le_add_left (gauge_le_of_mem hε₀.le hy.1) _ /-- If `s` is a convex neighborhood of the origin in a topological real vector space, then `gauge s` is continuous. If the ambient space is a normed space, then `gauge s` is Lipschitz continuous, see `Convex.lipschitz_gauge`. -/ @[continuity] theorem continuous_gauge (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) : Continuous (gauge s) := continuous_iff_continuousAt.2 fun _ ↦ continuousAt_gauge hc hs₀ theorem gauge_lt_one_eq_interior (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) : { x | gauge s x < 1 } = interior s := by refine Subset.antisymm (fun x hx ↦ ?_) (interior_subset_gauge_lt_one s) rcases mem_openSegment_of_gauge_lt_one (absorbent_nhds_zero hs₀) hx with ⟨y, hys, hxy⟩ exact hc.openSegment_interior_self_subset_interior (mem_interior_iff_mem_nhds.2 hs₀) hys hxy theorem gauge_lt_one_iff_mem_interior (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) : gauge s x < 1 ↔ x ∈ interior s := Set.ext_iff.1 (gauge_lt_one_eq_interior hc hs₀) _ theorem gauge_le_one_iff_mem_closure (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) : gauge s x ≤ 1 ↔ x ∈ closure s := ⟨mem_closure_of_gauge_le_one hc (mem_of_mem_nhds hs₀) (absorbent_nhds_zero hs₀), fun h ↦ le_on_closure (fun _ ↦ gauge_le_one_of_mem) (continuous_gauge hc hs₀).continuousOn continuousOn_const h⟩ theorem gauge_eq_one_iff_mem_frontier (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) : gauge s x = 1 ↔ x ∈ frontier s := by rw [eq_iff_le_not_lt, gauge_le_one_iff_mem_closure hc hs₀, gauge_lt_one_iff_mem_interior hc hs₀] rfl end TopologicalVectorSpace section RCLike variable [RCLike 𝕜] [Module 𝕜 E] [IsScalarTower ℝ 𝕜 E] /-- `gauge s` as a seminorm when `s` is balanced, convex and absorbent. -/ @[simps!] def gaugeSeminorm (hs₀ : Balanced 𝕜 s) (hs₁ : Convex ℝ s) (hs₂ : Absorbent ℝ s) : Seminorm 𝕜 E := Seminorm.of (gauge s) (gauge_add_le hs₁ hs₂) (gauge_smul hs₀) variable {hs₀ : Balanced 𝕜 s} {hs₁ : Convex ℝ s} {hs₂ : Absorbent ℝ s} [TopologicalSpace E] [ContinuousSMul ℝ E] theorem gaugeSeminorm_lt_one_of_isOpen (hs : IsOpen s) {x : E} (hx : x ∈ s) : gaugeSeminorm hs₀ hs₁ hs₂ x < 1 := gauge_lt_one_of_mem_of_isOpen hs hx theorem gaugeSeminorm_ball_one (hs : IsOpen s) : (gaugeSeminorm hs₀ hs₁ hs₂).ball 0 1 = s := by rw [Seminorm.ball_zero_eq] exact gauge_lt_one_eq_self_of_isOpen hs₁ hs₂.zero_mem hs end RCLike /-- Any seminorm arises as the gauge of its unit ball. -/ @[simp] protected theorem Seminorm.gauge_ball (p : Seminorm ℝ E) : gauge (p.ball 0 1) = p := by ext x obtain hp | hp := { r : ℝ | 0 < r ∧ x ∈ r • p.ball 0 1 }.eq_empty_or_nonempty · rw [gauge, hp, Real.sInf_empty] by_contra h have hpx : 0 < p x := (apply_nonneg _ _).lt_of_ne h have hpx₂ : 0 < 2 * p x := mul_pos zero_lt_two hpx refine hp.subset ⟨hpx₂, (2 * p x)⁻¹ • x, ?_, smul_inv_smul₀ hpx₂.ne' _⟩ rw [p.mem_ball_zero, map_smul_eq_mul, Real.norm_eq_abs, abs_of_pos (inv_pos.2 hpx₂), inv_mul_lt_iff₀ hpx₂, mul_one] exact lt_mul_of_one_lt_left hpx one_lt_two refine IsGLB.csInf_eq ⟨fun r => ?_, fun r hr => le_of_forall_pos_le_add fun ε hε => ?_⟩ hp · rintro ⟨hr, y, hy, rfl⟩ rw [p.mem_ball_zero] at hy rw [map_smul_eq_mul, Real.norm_eq_abs, abs_of_pos hr] exact mul_le_of_le_one_right hr.le hy.le · have hpε : 0 < p x + ε := by positivity refine hr ⟨hpε, (p x + ε)⁻¹ • x, ?_, smul_inv_smul₀ hpε.ne' _⟩ rw [p.mem_ball_zero, map_smul_eq_mul, Real.norm_eq_abs, abs_of_pos (inv_pos.2 hpε), inv_mul_lt_iff₀ hpε, mul_one] exact lt_add_of_pos_right _ hε theorem Seminorm.gaugeSeminorm_ball (p : Seminorm ℝ E) : gaugeSeminorm (p.balanced_ball_zero 1) (p.convex_ball 0 1) (p.absorbent_ball_zero zero_lt_one) = p := DFunLike.coe_injective p.gauge_ball end AddCommGroup section Seminormed variable [SeminormedAddCommGroup E] [NormedSpace ℝ E] {s : Set E} {r : ℝ} {x : E} open Metric theorem gauge_unit_ball (x : E) : gauge (ball (0 : E) 1) x = ‖x‖ := by rw [← ball_normSeminorm ℝ, Seminorm.gauge_ball, coe_normSeminorm] theorem gauge_ball (hr : 0 ≤ r) (x : E) : gauge (ball (0 : E) r) x = ‖x‖ / r := by rcases hr.eq_or_lt with rfl | hr · simp · rw [← smul_unitBall_of_pos hr, gauge_smul_left, Pi.smul_apply, gauge_unit_ball, smul_eq_mul, abs_of_nonneg hr.le, div_eq_inv_mul] simp_rw [mem_ball_zero_iff, norm_neg] exact fun _ => id @[simp] theorem gauge_closure_zero : gauge (closure (0 : Set E)) = 0 := funext fun x ↦ by simp only [← singleton_zero, gauge_def', mem_closure_zero_iff_norm, norm_smul, mul_eq_zero, norm_eq_zero, inv_eq_zero] rcases (norm_nonneg x).eq_or_gt with hx | hx · convert csInf_Ioi (a := (0 : ℝ)) exact Set.ext fun r ↦ and_iff_left (.inr hx) · convert Real.sInf_empty exact eq_empty_of_forall_not_mem fun r ⟨hr₀, hr⟩ ↦ hx.ne' <| hr.resolve_left hr₀.out.ne' @[simp] theorem gauge_closedBall (hr : 0 ≤ r) (x : E) : gauge (closedBall (0 : E) r) x = ‖x‖ / r := by rcases hr.eq_or_lt with rfl | hr' · rw [div_zero, closedBall_zero', singleton_zero, gauge_closure_zero]; rfl · apply le_antisymm · rw [← gauge_ball hr] exact gauge_mono (absorbent_ball_zero hr') ball_subset_closedBall x · suffices ∀ᶠ R in 𝓝[>] r, ‖x‖ / R ≤ gauge (closedBall 0 r) x by refine le_of_tendsto ?_ this exact tendsto_const_nhds.div inf_le_left hr'.ne' filter_upwards [self_mem_nhdsWithin] with R hR rw [← gauge_ball (hr.trans hR.out.le)] refine gauge_mono ?_ (closedBall_subset_ball hR) _ exact (absorbent_ball_zero hr').mono ball_subset_closedBall theorem mul_gauge_le_norm (hs : Metric.ball (0 : E) r ⊆ s) : r * gauge s x ≤ ‖x‖ := by obtain hr | hr := le_or_lt r 0 · exact (mul_nonpos_of_nonpos_of_nonneg hr <| gauge_nonneg _).trans (norm_nonneg _) rw [mul_comm, ← le_div_iff₀ hr, ← gauge_ball hr.le] exact gauge_mono (absorbent_ball_zero hr) hs x theorem Convex.lipschitzWith_gauge {r : ℝ≥0} (hc : Convex ℝ s) (hr : 0 < r) (hs : Metric.ball (0 : E) r ⊆ s) : LipschitzWith r⁻¹ (gauge s) :=
have : Absorbent ℝ (Metric.ball (0 : E) r) := absorbent_ball_zero hr LipschitzWith.of_le_add_mul _ fun x y =>
Mathlib/Analysis/Convex/Gauge.lean
572
573
/- Copyright (c) 2019 Minchao Wu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Minchao Wu, Mario Carneiro -/ import Mathlib.Computability.Halting /-! # Strong reducibility and degrees. This file defines the notions of computable many-one reduction and one-one reduction between sets, and shows that the corresponding degrees form a semilattice. ## Notations This file uses the local notation `⊕'` for `Sum.elim` to denote the disjoint union of two degrees. ## References * [Robert Soare, *Recursively enumerable sets and degrees*][soare1987] ## Tags computability, reducibility, reduction -/ universe u v w open Function /-- `p` is many-one reducible to `q` if there is a computable function translating questions about `p` to questions about `q`. -/ def ManyOneReducible {α β} [Primcodable α] [Primcodable β] (p : α → Prop) (q : β → Prop) := ∃ f, Computable f ∧ ∀ a, p a ↔ q (f a) @[inherit_doc ManyOneReducible] infixl:1000 " ≤₀ " => ManyOneReducible theorem ManyOneReducible.mk {α β} [Primcodable α] [Primcodable β] {f : α → β} (q : β → Prop) (h : Computable f) : (fun a => q (f a)) ≤₀ q := ⟨f, h, fun _ => Iff.rfl⟩ @[refl] theorem manyOneReducible_refl {α} [Primcodable α] (p : α → Prop) : p ≤₀ p := ⟨id, Computable.id, by simp⟩ @[trans] theorem ManyOneReducible.trans {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} : p ≤₀ q → q ≤₀ r → p ≤₀ r | ⟨f, c₁, h₁⟩, ⟨g, c₂, h₂⟩ => ⟨g ∘ f, c₂.comp c₁, fun a => ⟨fun h => by rw [comp_apply, ← h₂, ← h₁]; assumption, fun h => by rwa [h₁, h₂]⟩⟩ theorem reflexive_manyOneReducible {α} [Primcodable α] : Reflexive (@ManyOneReducible α α _ _) := manyOneReducible_refl theorem transitive_manyOneReducible {α} [Primcodable α] : Transitive (@ManyOneReducible α α _ _) := fun _ _ _ => ManyOneReducible.trans /-- `p` is one-one reducible to `q` if there is an injective computable function translating questions about `p` to questions about `q`. -/ def OneOneReducible {α β} [Primcodable α] [Primcodable β] (p : α → Prop) (q : β → Prop) := ∃ f, Computable f ∧ Injective f ∧ ∀ a, p a ↔ q (f a) @[inherit_doc OneOneReducible] infixl:1000 " ≤₁ " => OneOneReducible theorem OneOneReducible.mk {α β} [Primcodable α] [Primcodable β] {f : α → β} (q : β → Prop) (h : Computable f) (i : Injective f) : (fun a => q (f a)) ≤₁ q := ⟨f, h, i, fun _ => Iff.rfl⟩ @[refl] theorem oneOneReducible_refl {α} [Primcodable α] (p : α → Prop) : p ≤₁ p := ⟨id, Computable.id, injective_id, by simp⟩ @[trans] theorem OneOneReducible.trans {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} : p ≤₁ q → q ≤₁ r → p ≤₁ r | ⟨f, c₁, i₁, h₁⟩, ⟨g, c₂, i₂, h₂⟩ => ⟨g ∘ f, c₂.comp c₁, i₂.comp i₁, fun a => ⟨fun h => by rw [comp_apply, ← h₂, ← h₁]; assumption, fun h => by rwa [h₁, h₂]⟩⟩ theorem OneOneReducible.to_many_one {α β} [Primcodable α] [Primcodable β] {p : α → Prop} {q : β → Prop} : p ≤₁ q → p ≤₀ q | ⟨f, c, _, h⟩ => ⟨f, c, h⟩ theorem OneOneReducible.of_equiv {α β} [Primcodable α] [Primcodable β] {e : α ≃ β} (q : β → Prop) (h : Computable e) : (q ∘ e) ≤₁ q := OneOneReducible.mk _ h e.injective theorem OneOneReducible.of_equiv_symm {α β} [Primcodable α] [Primcodable β] {e : α ≃ β} (q : β → Prop) (h : Computable e.symm) : q ≤₁ (q ∘ e) := by convert OneOneReducible.of_equiv _ h; funext; simp theorem reflexive_oneOneReducible {α} [Primcodable α] : Reflexive (@OneOneReducible α α _ _) := oneOneReducible_refl theorem transitive_oneOneReducible {α} [Primcodable α] : Transitive (@OneOneReducible α α _ _) := fun _ _ _ => OneOneReducible.trans namespace ComputablePred variable {α : Type*} {β : Type*} [Primcodable α] [Primcodable β] open Computable theorem computable_of_manyOneReducible {p : α → Prop} {q : β → Prop} (h₁ : p ≤₀ q) (h₂ : ComputablePred q) : ComputablePred p := by rcases h₁ with ⟨f, c, hf⟩ rw [show p = fun a => q (f a) from Set.ext hf] rcases computable_iff.1 h₂ with ⟨g, hg, rfl⟩ exact ⟨by infer_instance, by simpa using hg.comp c⟩ theorem computable_of_oneOneReducible {p : α → Prop} {q : β → Prop} (h : p ≤₁ q) : ComputablePred q → ComputablePred p := computable_of_manyOneReducible h.to_many_one end ComputablePred /-- `p` and `q` are many-one equivalent if each one is many-one reducible to the other. -/ def ManyOneEquiv {α β} [Primcodable α] [Primcodable β] (p : α → Prop) (q : β → Prop) := p ≤₀ q ∧ q ≤₀ p /-- `p` and `q` are one-one equivalent if each one is one-one reducible to the other. -/ def OneOneEquiv {α β} [Primcodable α] [Primcodable β] (p : α → Prop) (q : β → Prop) := p ≤₁ q ∧ q ≤₁ p @[refl] theorem manyOneEquiv_refl {α} [Primcodable α] (p : α → Prop) : ManyOneEquiv p p := ⟨manyOneReducible_refl _, manyOneReducible_refl _⟩ @[symm] theorem ManyOneEquiv.symm {α β} [Primcodable α] [Primcodable β] {p : α → Prop} {q : β → Prop} : ManyOneEquiv p q → ManyOneEquiv q p := And.symm @[trans] theorem ManyOneEquiv.trans {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} : ManyOneEquiv p q → ManyOneEquiv q r → ManyOneEquiv p r | ⟨pq, qp⟩, ⟨qr, rq⟩ => ⟨pq.trans qr, rq.trans qp⟩ theorem equivalence_of_manyOneEquiv {α} [Primcodable α] : Equivalence (@ManyOneEquiv α α _ _) := ⟨manyOneEquiv_refl, fun {_ _} => ManyOneEquiv.symm, fun {_ _ _} => ManyOneEquiv.trans⟩ @[refl] theorem oneOneEquiv_refl {α} [Primcodable α] (p : α → Prop) : OneOneEquiv p p := ⟨oneOneReducible_refl _, oneOneReducible_refl _⟩ @[symm] theorem OneOneEquiv.symm {α β} [Primcodable α] [Primcodable β] {p : α → Prop} {q : β → Prop} : OneOneEquiv p q → OneOneEquiv q p := And.symm @[trans] theorem OneOneEquiv.trans {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} : OneOneEquiv p q → OneOneEquiv q r → OneOneEquiv p r | ⟨pq, qp⟩, ⟨qr, rq⟩ => ⟨pq.trans qr, rq.trans qp⟩ theorem equivalence_of_oneOneEquiv {α} [Primcodable α] : Equivalence (@OneOneEquiv α α _ _) := ⟨oneOneEquiv_refl, fun {_ _} => OneOneEquiv.symm, fun {_ _ _} => OneOneEquiv.trans⟩ theorem OneOneEquiv.to_many_one {α β} [Primcodable α] [Primcodable β] {p : α → Prop} {q : β → Prop} : OneOneEquiv p q → ManyOneEquiv p q | ⟨pq, qp⟩ => ⟨pq.to_many_one, qp.to_many_one⟩ /-- a computable bijection -/ nonrec def Equiv.Computable {α β} [Primcodable α] [Primcodable β] (e : α ≃ β) := Computable e ∧ Computable e.symm theorem Equiv.Computable.symm {α β} [Primcodable α] [Primcodable β] {e : α ≃ β} : e.Computable → e.symm.Computable := And.symm theorem Equiv.Computable.trans {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {e₁ : α ≃ β} {e₂ : β ≃ γ} : e₁.Computable → e₂.Computable → (e₁.trans e₂).Computable | ⟨l₁, r₁⟩, ⟨l₂, r₂⟩ => ⟨l₂.comp l₁, r₁.comp r₂⟩ theorem Computable.eqv (α) [Denumerable α] : (Denumerable.eqv α).Computable := ⟨Computable.encode, Computable.ofNat _⟩ theorem Computable.equiv₂ (α β) [Denumerable α] [Denumerable β] : (Denumerable.equiv₂ α β).Computable := (Computable.eqv _).trans (Computable.eqv _).symm theorem OneOneEquiv.of_equiv {α β} [Primcodable α] [Primcodable β] {e : α ≃ β} (h : e.Computable) {p} : OneOneEquiv (p ∘ e) p := ⟨OneOneReducible.of_equiv _ h.1, OneOneReducible.of_equiv_symm _ h.2⟩ theorem ManyOneEquiv.of_equiv {α β} [Primcodable α] [Primcodable β] {e : α ≃ β} (h : e.Computable) {p} : ManyOneEquiv (p ∘ e) p := (OneOneEquiv.of_equiv h).to_many_one theorem ManyOneEquiv.le_congr_left {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : ManyOneEquiv p q) : p ≤₀ r ↔ q ≤₀ r := ⟨h.2.trans, h.1.trans⟩ theorem ManyOneEquiv.le_congr_right {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : ManyOneEquiv q r) : p ≤₀ q ↔ p ≤₀ r := ⟨fun h' => h'.trans h.1, fun h' => h'.trans h.2⟩ theorem OneOneEquiv.le_congr_left {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : OneOneEquiv p q) : p ≤₁ r ↔ q ≤₁ r := ⟨h.2.trans, h.1.trans⟩ theorem OneOneEquiv.le_congr_right {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : OneOneEquiv q r) : p ≤₁ q ↔ p ≤₁ r := ⟨fun h' => h'.trans h.1, fun h' => h'.trans h.2⟩ theorem ManyOneEquiv.congr_left {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : ManyOneEquiv p q) : ManyOneEquiv p r ↔ ManyOneEquiv q r := and_congr h.le_congr_left h.le_congr_right theorem ManyOneEquiv.congr_right {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : ManyOneEquiv q r) : ManyOneEquiv p q ↔ ManyOneEquiv p r := and_congr h.le_congr_right h.le_congr_left theorem OneOneEquiv.congr_left {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : OneOneEquiv p q) : OneOneEquiv p r ↔ OneOneEquiv q r := and_congr h.le_congr_left h.le_congr_right theorem OneOneEquiv.congr_right {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : OneOneEquiv q r) : OneOneEquiv p q ↔ OneOneEquiv p r := and_congr h.le_congr_right h.le_congr_left @[simp] theorem ULower.down_computable {α} [Primcodable α] : (ULower.equiv α).Computable := ⟨Primrec.ulower_down.to_comp, Primrec.ulower_up.to_comp⟩ theorem manyOneEquiv_up {α} [Primcodable α] {p : α → Prop} : ManyOneEquiv (p ∘ ULower.up) p := ManyOneEquiv.of_equiv ULower.down_computable.symm local infixl:1001 " ⊕' " => Sum.elim open Nat.Primrec theorem OneOneReducible.disjoin_left {α β} [Primcodable α] [Primcodable β] {p : α → Prop} {q : β → Prop} : p ≤₁ p ⊕' q := ⟨Sum.inl, Computable.sumInl, fun _ _ => Sum.inl.inj_iff.1, fun _ => Iff.rfl⟩ theorem OneOneReducible.disjoin_right {α β} [Primcodable α] [Primcodable β] {p : α → Prop} {q : β → Prop} : q ≤₁ p ⊕' q := ⟨Sum.inr, Computable.sumInr, fun _ _ => Sum.inr.inj_iff.1, fun _ => Iff.rfl⟩ theorem disjoin_manyOneReducible {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} : p ≤₀ r → q ≤₀ r → (p ⊕' q) ≤₀ r | ⟨f, c₁, h₁⟩, ⟨g, c₂, h₂⟩ => ⟨Sum.elim f g, Computable.id.sumCasesOn (c₁.comp Computable.snd).to₂ (c₂.comp Computable.snd).to₂, fun x => by cases x <;> [apply h₁; apply h₂]⟩ theorem disjoin_le {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} : (p ⊕' q) ≤₀ r ↔ p ≤₀ r ∧ q ≤₀ r := ⟨fun h => ⟨OneOneReducible.disjoin_left.to_many_one.trans h, OneOneReducible.disjoin_right.to_many_one.trans h⟩, fun ⟨h₁, h₂⟩ => disjoin_manyOneReducible h₁ h₂⟩ variable {α : Type u} [Primcodable α] [Inhabited α] {β : Type v} [Primcodable β] [Inhabited β] /-- Computable and injective mapping of predicates to sets of natural numbers. -/ def toNat (p : Set α) : Set ℕ := { n | p ((Encodable.decode (α := α) n).getD default) } @[simp] theorem toNat_manyOneReducible {p : Set α} : toNat p ≤₀ p := ⟨fun n => (Encodable.decode (α := α) n).getD default, Computable.option_getD Computable.decode (Computable.const _), fun _ => Iff.rfl⟩ @[simp] theorem manyOneReducible_toNat {p : Set α} : p ≤₀ toNat p := ⟨Encodable.encode, Computable.encode, by simp [toNat, setOf]⟩ @[simp] theorem manyOneReducible_toNat_toNat {p : Set α} {q : Set β} : toNat p ≤₀ toNat q ↔ p ≤₀ q := ⟨fun h => manyOneReducible_toNat.trans (h.trans toNat_manyOneReducible), fun h => toNat_manyOneReducible.trans (h.trans manyOneReducible_toNat)⟩ @[simp] theorem toNat_manyOneEquiv {p : Set α} : ManyOneEquiv (toNat p) p := by simp [ManyOneEquiv] @[simp] theorem manyOneEquiv_toNat (p : Set α) (q : Set β) : ManyOneEquiv (toNat p) (toNat q) ↔ ManyOneEquiv p q := by simp [ManyOneEquiv] /-- A many-one degree is an equivalence class of sets up to many-one equivalence. -/ def ManyOneDegree : Type := Quotient (⟨ManyOneEquiv, equivalence_of_manyOneEquiv⟩ : Setoid (Set ℕ)) namespace ManyOneDegree /-- The many-one degree of a set on a primcodable type. -/ def of (p : α → Prop) : ManyOneDegree := Quotient.mk'' (toNat p) @[elab_as_elim] protected theorem ind_on {C : ManyOneDegree → Prop} (d : ManyOneDegree) (h : ∀ p : Set ℕ, C (of p)) : C d := Quotient.inductionOn' d h /-- Lifts a function on sets of natural numbers to many-one degrees. -/ protected abbrev liftOn {φ} (d : ManyOneDegree) (f : Set ℕ → φ) (h : ∀ p q, ManyOneEquiv p q → f p = f q) : φ := Quotient.liftOn' d f h @[simp] protected theorem liftOn_eq {φ} (p : Set ℕ) (f : Set ℕ → φ) (h : ∀ p q, ManyOneEquiv p q → f p = f q) : (of p).liftOn f h = f p := rfl /-- Lifts a binary function on sets of natural numbers to many-one degrees. -/ @[reducible, simp] protected def liftOn₂ {φ} (d₁ d₂ : ManyOneDegree) (f : Set ℕ → Set ℕ → φ) (h : ∀ p₁ p₂ q₁ q₂, ManyOneEquiv p₁ p₂ → ManyOneEquiv q₁ q₂ → f p₁ q₁ = f p₂ q₂) : φ := d₁.liftOn (fun p => d₂.liftOn (f p) fun _ _ hq => h _ _ _ _ (by rfl) hq) (by intro p₁ p₂ hp induction d₂ using ManyOneDegree.ind_on apply h · assumption · rfl) @[simp] protected theorem liftOn₂_eq {φ} (p q : Set ℕ) (f : Set ℕ → Set ℕ → φ) (h : ∀ p₁ p₂ q₁ q₂, ManyOneEquiv p₁ p₂ → ManyOneEquiv q₁ q₂ → f p₁ q₁ = f p₂ q₂) : (of p).liftOn₂ (of q) f h = f p q := rfl @[simp] theorem of_eq_of {p : α → Prop} {q : β → Prop} : of p = of q ↔ ManyOneEquiv p q := by rw [of, of, Quotient.eq''] simp instance instInhabited : Inhabited ManyOneDegree := ⟨of (∅ : Set ℕ)⟩ /-- For many-one degrees `d₁` and `d₂`, `d₁ ≤ d₂` if the sets in `d₁` are many-one reducible to the sets in `d₂`. -/ instance instLE : LE ManyOneDegree := ⟨fun d₁ d₂ => ManyOneDegree.liftOn₂ d₁ d₂ (· ≤₀ ·) fun _p₁ _p₂ _q₁ _q₂ hp hq => propext (hp.le_congr_left.trans hq.le_congr_right)⟩ @[simp] theorem of_le_of {p : α → Prop} {q : β → Prop} : of p ≤ of q ↔ p ≤₀ q := manyOneReducible_toNat_toNat private theorem le_refl (d : ManyOneDegree) : d ≤ d := by induction d using ManyOneDegree.ind_on; simp; rfl private theorem le_antisymm {d₁ d₂ : ManyOneDegree} : d₁ ≤ d₂ → d₂ ≤ d₁ → d₁ = d₂ := by induction d₁ using ManyOneDegree.ind_on induction d₂ using ManyOneDegree.ind_on intro hp hq simp_all only [ManyOneEquiv, of_le_of, of_eq_of, true_and] private theorem le_trans {d₁ d₂ d₃ : ManyOneDegree} : d₁ ≤ d₂ → d₂ ≤ d₃ → d₁ ≤ d₃ := by induction d₁ using ManyOneDegree.ind_on induction d₂ using ManyOneDegree.ind_on induction d₃ using ManyOneDegree.ind_on apply ManyOneReducible.trans instance instPartialOrder : PartialOrder ManyOneDegree where le := (· ≤ ·) le_refl := le_refl le_trans _ _ _ := le_trans le_antisymm _ _ := le_antisymm /-- The join of two degrees, induced by the disjoint union of two underlying sets. -/ instance instAdd : Add ManyOneDegree := ⟨fun d₁ d₂ => d₁.liftOn₂ d₂ (fun a b => of (a ⊕' b)) (by rintro a b c d ⟨hl₁, hr₁⟩ ⟨hl₂, hr₂⟩ rw [of_eq_of] exact ⟨disjoin_manyOneReducible (hl₁.trans OneOneReducible.disjoin_left.to_many_one) (hl₂.trans OneOneReducible.disjoin_right.to_many_one), disjoin_manyOneReducible (hr₁.trans OneOneReducible.disjoin_left.to_many_one) (hr₂.trans OneOneReducible.disjoin_right.to_many_one)⟩)⟩ @[simp] theorem add_of (p : Set α) (q : Set β) : of (p ⊕' q) = of p + of q := of_eq_of.mpr ⟨disjoin_manyOneReducible (manyOneReducible_toNat.trans OneOneReducible.disjoin_left.to_many_one) (manyOneReducible_toNat.trans OneOneReducible.disjoin_right.to_many_one), disjoin_manyOneReducible (toNat_manyOneReducible.trans OneOneReducible.disjoin_left.to_many_one) (toNat_manyOneReducible.trans OneOneReducible.disjoin_right.to_many_one)⟩ @[simp] protected theorem add_le {d₁ d₂ d₃ : ManyOneDegree} : d₁ + d₂ ≤ d₃ ↔ d₁ ≤ d₃ ∧ d₂ ≤ d₃ := by induction d₁ using ManyOneDegree.ind_on induction d₂ using ManyOneDegree.ind_on induction d₃ using ManyOneDegree.ind_on simpa only [← add_of, of_le_of] using disjoin_le @[simp] protected theorem le_add_left (d₁ d₂ : ManyOneDegree) : d₁ ≤ d₁ + d₂ := (ManyOneDegree.add_le.1 (le_refl _)).1 @[simp] protected theorem le_add_right (d₁ d₂ : ManyOneDegree) : d₂ ≤ d₁ + d₂ := (ManyOneDegree.add_le.1 (le_refl _)).2 instance instSemilatticeSup : SemilatticeSup ManyOneDegree := { ManyOneDegree.instPartialOrder with sup := (· + ·) le_sup_left := ManyOneDegree.le_add_left le_sup_right := ManyOneDegree.le_add_right sup_le := fun _ _ _ h₁ h₂ => ManyOneDegree.add_le.2 ⟨h₁, h₂⟩ } end ManyOneDegree
Mathlib/Computability/Reduce.lean
443
447
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Order.Interval.Set.IsoIoo import Mathlib.Topology.ContinuousMap.Bounded.Normed import Mathlib.Topology.UrysohnsBounded /-! # Tietze extension theorem In this file we prove a few version of the Tietze extension theorem. The theorem says that a continuous function `s → ℝ` defined on a closed set in a normal topological space `Y` can be extended to a continuous function on the whole space. Moreover, if all values of the original function belong to some (finite or infinite, open or closed) interval, then the extension can be chosen so that it takes values in the same interval. In particular, if the original function is a bounded function, then there exists a bounded extension of the same norm. The proof mostly follows <https://ncatlab.org/nlab/show/Tietze+extension+theorem>. We patch a small gap in the proof for unbounded functions, see `exists_extension_forall_exists_le_ge_of_isClosedEmbedding`. In addition we provide a class `TietzeExtension` encoding the idea that a topological space satisfies the Tietze extension theorem. This allows us to get a version of the Tietze extension theorem that simultaneously applies to `ℝ`, `ℝ × ℝ`, `ℂ`, `ι → ℝ`, `ℝ≥0` et cetera. At some point in the future, it may be desirable to provide instead a more general approach via *absolute retracts*, but the current implementation covers the most common use cases easily. ## Implementation notes We first prove the theorems for a closed embedding `e : X → Y` of a topological space into a normal topological space, then specialize them to the case `X = s : Set Y`, `e = (↑)`. ## Tags Tietze extension theorem, Urysohn's lemma, normal topological space -/ open Topology /-! ### The `TietzeExtension` class -/ section TietzeExtensionClass universe u u₁ u₂ v w -- TODO: define *absolute retracts* and then prove they satisfy Tietze extension. -- Then make instances of that instead and remove this class. /-- A class encoding the concept that a space satisfies the Tietze extension property. -/ class TietzeExtension (Y : Type v) [TopologicalSpace Y] : Prop where exists_restrict_eq' {X : Type u} [TopologicalSpace X] [NormalSpace X] (s : Set X) (hs : IsClosed s) (f : C(s, Y)) : ∃ (g : C(X, Y)), g.restrict s = f variable {X₁ : Type u₁} [TopologicalSpace X₁] variable {X : Type u} [TopologicalSpace X] [NormalSpace X] {s : Set X} variable {e : X₁ → X} variable {Y : Type v} [TopologicalSpace Y] [TietzeExtension.{u, v} Y] /-- **Tietze extension theorem** for `TietzeExtension` spaces, a version for a closed set. Let `s` be a closed set in a normal topological space `X`. Let `f` be a continuous function on `s` with values in a `TietzeExtension` space `Y`. Then there exists a continuous function `g : C(X, Y)` such that `g.restrict s = f`. -/ theorem ContinuousMap.exists_restrict_eq (hs : IsClosed s) (f : C(s, Y)) : ∃ (g : C(X, Y)), g.restrict s = f := TietzeExtension.exists_restrict_eq' s hs f /-- **Tietze extension theorem** for `TietzeExtension` spaces. Let `e` be a closed embedding of a nonempty topological space `X₁` into a normal topological space `X`. Let `f` be a continuous function on `X₁` with values in a `TietzeExtension` space `Y`. Then there exists a continuous function `g : C(X, Y)` such that `g ∘ e = f`. -/ theorem ContinuousMap.exists_extension (he : IsClosedEmbedding e) (f : C(X₁, Y)) : ∃ (g : C(X, Y)), g.comp ⟨e, he.continuous⟩ = f := by let e' : X₁ ≃ₜ Set.range e := he.isEmbedding.toHomeomorph obtain ⟨g, hg⟩ := (f.comp e'.symm).exists_restrict_eq he.isClosed_range exact ⟨g, by ext x; simpa using congr($(hg) ⟨e' x, x, rfl⟩)⟩ /-- **Tietze extension theorem** for `TietzeExtension` spaces. Let `e` be a closed embedding of a nonempty topological space `X₁` into a normal topological space `X`. Let `f` be a continuous function on `X₁` with values in a `TietzeExtension` space `Y`. Then there exists a continuous function `g : C(X, Y)` such that `g ∘ e = f`. This version is provided for convenience and backwards compatibility. Here the composition is phrased in terms of bare functions. -/ theorem ContinuousMap.exists_extension' (he : IsClosedEmbedding e) (f : C(X₁, Y)) : ∃ (g : C(X, Y)), g ∘ e = f := f.exists_extension he |>.imp fun g hg ↦ by ext x; congrm($(hg) x) /-- This theorem is not intended to be used directly because it is rare for a set alone to satisfy `[TietzeExtension t]`. For example, `Metric.ball` in `ℝ` only satisfies it when the radius is strictly positive, so finding this as an instance will fail. Instead, it is intended to be used as a constructor for theorems about sets which *do* satisfy `[TietzeExtension t]` under some hypotheses. -/ theorem ContinuousMap.exists_forall_mem_restrict_eq (hs : IsClosed s) {Y : Type v} [TopologicalSpace Y] (f : C(s, Y)) {t : Set Y} (hf : ∀ x, f x ∈ t) [ht : TietzeExtension.{u, v} t] : ∃ (g : C(X, Y)), (∀ x, g x ∈ t) ∧ g.restrict s = f := by obtain ⟨g, hg⟩ := mk _ (map_continuous f |>.codRestrict hf) |>.exists_restrict_eq hs exact ⟨comp ⟨Subtype.val, by continuity⟩ g, by simp, by ext x; congrm(($(hg) x : Y))⟩ /-- This theorem is not intended to be used directly because it is rare for a set alone to satisfy `[TietzeExtension t]`. For example, `Metric.ball` in `ℝ` only satisfies it when the radius is strictly positive, so finding this as an instance will fail. Instead, it is intended to be used as a constructor for theorems about sets which *do* satisfy `[TietzeExtension t]` under some hypotheses. -/ theorem ContinuousMap.exists_extension_forall_mem (he : IsClosedEmbedding e) {Y : Type v} [TopologicalSpace Y] (f : C(X₁, Y)) {t : Set Y} (hf : ∀ x, f x ∈ t) [ht : TietzeExtension.{u, v} t] : ∃ (g : C(X, Y)), (∀ x, g x ∈ t) ∧ g.comp ⟨e, he.continuous⟩ = f := by obtain ⟨g, hg⟩ := mk _ (map_continuous f |>.codRestrict hf) |>.exists_extension he exact ⟨comp ⟨Subtype.val, by continuity⟩ g, by simp, by ext x; congrm(($(hg) x : Y))⟩ instance Pi.instTietzeExtension {ι : Type*} {Y : ι → Type v} [∀ i, TopologicalSpace (Y i)] [∀ i, TietzeExtension.{u} (Y i)] : TietzeExtension.{u} (∀ i, Y i) where exists_restrict_eq' s hs f := by obtain ⟨g', hg'⟩ := Classical.skolem.mp <| fun i ↦ ContinuousMap.exists_restrict_eq hs (ContinuousMap.piEquiv _ _ |>.symm f i) exact ⟨ContinuousMap.piEquiv _ _ g', by ext x i; congrm($(hg' i) x)⟩ instance Prod.instTietzeExtension {Y : Type v} {Z : Type w} [TopologicalSpace Y] [TietzeExtension.{u, v} Y] [TopologicalSpace Z] [TietzeExtension.{u, w} Z] : TietzeExtension.{u, max w v} (Y × Z) where exists_restrict_eq' s hs f := by obtain ⟨g₁, hg₁⟩ := (ContinuousMap.fst.comp f).exists_restrict_eq hs obtain ⟨g₂, hg₂⟩ := (ContinuousMap.snd.comp f).exists_restrict_eq hs exact ⟨g₁.prodMk g₂, by ext1 x; congrm(($(hg₁) x), $(hg₂) x)⟩ instance Unique.instTietzeExtension {Y : Type v} [TopologicalSpace Y] [Nonempty Y] [Subsingleton Y] : TietzeExtension.{u, v} Y where exists_restrict_eq' _ _ f := ‹Nonempty Y›.elim fun y ↦ ⟨.const _ y, by ext; subsingleton⟩ /-- Any retract of a `TietzeExtension` space is one itself. -/ theorem TietzeExtension.of_retract {Y : Type v} {Z : Type w} [TopologicalSpace Y] [TopologicalSpace Z] [TietzeExtension.{u, w} Z] (ι : C(Y, Z)) (r : C(Z, Y)) (h : r.comp ι = .id Y) : TietzeExtension.{u, v} Y where exists_restrict_eq' s hs f := by obtain ⟨g, hg⟩ := (ι.comp f).exists_restrict_eq hs use r.comp g ext1 x have := congr(r.comp $(hg)) rw [← r.comp_assoc ι, h, f.id_comp] at this congrm($this x) /-- Any homeomorphism from a `TietzeExtension` space is one itself. -/ theorem TietzeExtension.of_homeo {Y : Type v} {Z : Type w} [TopologicalSpace Y] [TopologicalSpace Z] [TietzeExtension.{u, w} Z] (e : Y ≃ₜ Z) : TietzeExtension.{u, v} Y := .of_retract (e : C(Y, Z)) (e.symm : C(Z, Y)) <| by simp end TietzeExtensionClass /-! The Tietze extension theorem for `ℝ`. -/ variable {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] [NormalSpace Y] open Metric Set Filter open BoundedContinuousFunction Topology noncomputable section namespace BoundedContinuousFunction /-- One step in the proof of the Tietze extension theorem. If `e : C(X, Y)` is a closed embedding of a topological space into a normal topological space and `f : X →ᵇ ℝ` is a bounded continuous function, then there exists a bounded continuous function `g : Y →ᵇ ℝ` of the norm `‖g‖ ≤ ‖f‖ / 3` such that the distance between `g ∘ e` and `f` is at most `(2 / 3) * ‖f‖`. -/ theorem tietze_extension_step (f : X →ᵇ ℝ) (e : C(X, Y)) (he : IsClosedEmbedding e) : ∃ g : Y →ᵇ ℝ, ‖g‖ ≤ ‖f‖ / 3 ∧ dist (g.compContinuous e) f ≤ 2 / 3 * ‖f‖ := by have h3 : (0 : ℝ) < 3 := by norm_num1 have h23 : 0 < (2 / 3 : ℝ) := by norm_num1 -- In the trivial case `f = 0`, we take `g = 0` rcases eq_or_ne f 0 with (rfl | hf) · use 0 simp replace hf : 0 < ‖f‖ := norm_pos_iff.2 hf /- Otherwise, the closed sets `e '' (f ⁻¹' (Iic (-‖f‖ / 3)))` and `e '' (f ⁻¹' (Ici (‖f‖ / 3)))` are disjoint, hence by Urysohn's lemma there exists a function `g` that is equal to `-‖f‖ / 3` on the former set and is equal to `‖f‖ / 3` on the latter set. This function `g` satisfies the assertions of the lemma. -/ have hf3 : -‖f‖ / 3 < ‖f‖ / 3 := (div_lt_div_iff_of_pos_right h3).2 (Left.neg_lt_self hf) have hc₁ : IsClosed (e '' (f ⁻¹' Iic (-‖f‖ / 3))) := he.isClosedMap _ (isClosed_Iic.preimage f.continuous) have hc₂ : IsClosed (e '' (f ⁻¹' Ici (‖f‖ / 3))) := he.isClosedMap _ (isClosed_Ici.preimage f.continuous) have hd : Disjoint (e '' (f ⁻¹' Iic (-‖f‖ / 3))) (e '' (f ⁻¹' Ici (‖f‖ / 3))) := by refine disjoint_image_of_injective he.injective (Disjoint.preimage _ ?_) rwa [Iic_disjoint_Ici, not_le] rcases exists_bounded_mem_Icc_of_closed_of_le hc₁ hc₂ hd hf3.le with ⟨g, hg₁, hg₂, hgf⟩ refine ⟨g, ?_, ?_⟩ · refine (norm_le <| div_nonneg hf.le h3.le).mpr fun y => ?_ simpa [abs_le, neg_div] using hgf y · refine (dist_le <| mul_nonneg h23.le hf.le).mpr fun x => ?_ have hfx : -‖f‖ ≤ f x ∧ f x ≤ ‖f‖ := by simpa only [Real.norm_eq_abs, abs_le] using f.norm_coe_le_norm x rcases le_total (f x) (-‖f‖ / 3) with hle₁ | hle₁ · calc |g (e x) - f x| = -‖f‖ / 3 - f x := by rw [hg₁ (mem_image_of_mem _ hle₁), Function.const_apply, abs_of_nonneg (sub_nonneg.2 hle₁)] _ ≤ 2 / 3 * ‖f‖ := by linarith · rcases le_total (f x) (‖f‖ / 3) with hle₂ | hle₂ · simp only [neg_div] at * calc dist (g (e x)) (f x) ≤ |g (e x)| + |f x| := dist_le_norm_add_norm _ _ _ ≤ ‖f‖ / 3 + ‖f‖ / 3 := (add_le_add (abs_le.2 <| hgf _) (abs_le.2 ⟨hle₁, hle₂⟩)) _ = 2 / 3 * ‖f‖ := by linarith · calc |g (e x) - f x| = f x - ‖f‖ / 3 := by rw [hg₂ (mem_image_of_mem _ hle₂), abs_sub_comm, Function.const_apply, abs_of_nonneg (sub_nonneg.2 hle₂)] _ ≤ 2 / 3 * ‖f‖ := by linarith /-- **Tietze extension theorem** for real-valued bounded continuous maps, a version with a closed embedding and bundled composition. If `e : C(X, Y)` is a closed embedding of a topological space into a normal topological space and `f : X →ᵇ ℝ` is a bounded continuous function, then there exists a bounded continuous function `g : Y →ᵇ ℝ` of the same norm such that `g ∘ e = f`. -/ theorem exists_extension_norm_eq_of_isClosedEmbedding' (f : X →ᵇ ℝ) (e : C(X, Y)) (he : IsClosedEmbedding e) : ∃ g : Y →ᵇ ℝ, ‖g‖ = ‖f‖ ∧ g.compContinuous e = f := by /- For the proof, we iterate `tietze_extension_step`. Each time we apply it to the difference between the previous approximation and `f`. -/ choose F hF_norm hF_dist using fun f : X →ᵇ ℝ => tietze_extension_step f e he set g : ℕ → Y →ᵇ ℝ := fun n => (fun g => g + F (f - g.compContinuous e))^[n] 0 have g0 : g 0 = 0 := rfl have g_succ : ∀ n, g (n + 1) = g n + F (f - (g n).compContinuous e) := fun n => Function.iterate_succ_apply' _ _ _ have hgf : ∀ n, dist ((g n).compContinuous e) f ≤ (2 / 3) ^ n * ‖f‖ := by intro n induction n with | zero => simp [g0] | succ n ihn => rw [g_succ n, add_compContinuous, ← dist_sub_right, add_sub_cancel_left, pow_succ', mul_assoc] refine (hF_dist _).trans (mul_le_mul_of_nonneg_left ?_ (by norm_num1)) rwa [← dist_eq_norm'] have hg_dist : ∀ n, dist (g n) (g (n + 1)) ≤ 1 / 3 * ‖f‖ * (2 / 3) ^ n := by intro n calc dist (g n) (g (n + 1)) = ‖F (f - (g n).compContinuous e)‖ := by rw [g_succ, dist_eq_norm', add_sub_cancel_left] _ ≤ ‖f - (g n).compContinuous e‖ / 3 := hF_norm _ _ = 1 / 3 * dist ((g n).compContinuous e) f := by rw [dist_eq_norm', one_div, div_eq_inv_mul] _ ≤ 1 / 3 * ((2 / 3) ^ n * ‖f‖) := mul_le_mul_of_nonneg_left (hgf n) (by norm_num1) _ = 1 / 3 * ‖f‖ * (2 / 3) ^ n := by ac_rfl have hg_cau : CauchySeq g := cauchySeq_of_le_geometric _ _ (by norm_num1) hg_dist have : Tendsto (fun n => (g n).compContinuous e) atTop (𝓝 <| (limUnder atTop g).compContinuous e) := ((continuous_compContinuous e).tendsto _).comp hg_cau.tendsto_limUnder have hge : (limUnder atTop g).compContinuous e = f := by refine tendsto_nhds_unique this (tendsto_iff_dist_tendsto_zero.2 ?_) refine squeeze_zero (fun _ => dist_nonneg) hgf ?_ rw [← zero_mul ‖f‖] refine (tendsto_pow_atTop_nhds_zero_of_lt_one ?_ ?_).mul tendsto_const_nhds <;> norm_num1 refine ⟨limUnder atTop g, le_antisymm ?_ ?_, hge⟩ · rw [← dist_zero_left, ← g0] refine (dist_le_of_le_geometric_of_tendsto₀ _ _ (by norm_num1) hg_dist hg_cau.tendsto_limUnder).trans_eq ?_ field_simp [show (3 - 2 : ℝ) = 1 by norm_num1] · rw [← hge] exact norm_compContinuous_le _ _ /-- **Tietze extension theorem** for real-valued bounded continuous maps, a version with a closed embedding and unbundled composition. If `e : C(X, Y)` is a closed embedding of a topological space into a normal topological space and `f : X →ᵇ ℝ` is a bounded continuous function, then there exists a bounded continuous function `g : Y →ᵇ ℝ` of the same norm such that `g ∘ e = f`. -/
theorem exists_extension_norm_eq_of_isClosedEmbedding (f : X →ᵇ ℝ) {e : X → Y} (he : IsClosedEmbedding e) : ∃ g : Y →ᵇ ℝ, ‖g‖ = ‖f‖ ∧ g ∘ e = f := by rcases exists_extension_norm_eq_of_isClosedEmbedding' f ⟨e, he.continuous⟩ he with ⟨g, hg, rfl⟩ exact ⟨g, hg, rfl⟩
Mathlib/Topology/TietzeExtension.lean
269
272
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Geometry.Manifold.Algebra.Structures import Mathlib.Geometry.Manifold.BumpFunction import Mathlib.Topology.MetricSpace.PartitionOfUnity import Mathlib.Topology.ShrinkingLemma /-! # Smooth partition of unity In this file we define two structures, `SmoothBumpCovering` and `SmoothPartitionOfUnity`. Both structures describe coverings of a set by a locally finite family of supports of smooth functions with some additional properties. The former structure is mostly useful as an intermediate step in the construction of a smooth partition of unity but some proofs that traditionally deal with a partition of unity can use a `SmoothBumpCovering` as well. Given a real manifold `M` and its subset `s`, a `SmoothBumpCovering ι I M s` is a collection of `SmoothBumpFunction`s `f i` indexed by `i : ι` such that * the center of each `f i` belongs to `s`; * the family of sets `support (f i)` is locally finite; * for each `x ∈ s`, there exists `i : ι` such that `f i =ᶠ[𝓝 x] 1`. In the same settings, a `SmoothPartitionOfUnity ι I M s` is a collection of smooth nonnegative functions `f i : C^∞⟮I, M; 𝓘(ℝ), ℝ⟯`, `i : ι`, such that * the family of sets `support (f i)` is locally finite; * for each `x ∈ s`, the sum `∑ᶠ i, f i x` equals one; * for each `x`, the sum `∑ᶠ i, f i x` is less than or equal to one. We say that `f : SmoothBumpCovering ι I M s` is *subordinate* to a map `U : M → Set M` if for each index `i`, we have `tsupport (f i) ⊆ U (f i).c`. This notion is a bit more general than being subordinate to an open covering of `M`, because we make no assumption about the way `U x` depends on `x`. We prove that on a smooth finitely dimensional real manifold with `σ`-compact Hausdorff topology, for any `U : M → Set M` such that `∀ x ∈ s, U x ∈ 𝓝 x` there exists a `SmoothBumpCovering ι I M s` subordinate to `U`. Then we use this fact to prove a similar statement about smooth partitions of unity, see `SmoothPartitionOfUnity.exists_isSubordinate`. Finally, we use existence of a partition of unity to prove lemma `exists_smooth_forall_mem_convex_of_local` that allows us to construct a globally defined smooth function from local functions. ## TODO * Build a framework for to transfer local definitions to global using partition of unity and use it to define, e.g., the integral of a differential form over a manifold. Lemma `exists_smooth_forall_mem_convex_of_local` is a first step in this direction. ## Tags smooth bump function, partition of unity -/ universe uι uE uH uM uF open Function Filter Module Set open scoped Topology Manifold ContDiff noncomputable section variable {ι : Type uι} {E : Type uE} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type uF} [NormedAddCommGroup F] [NormedSpace ℝ F] {H : Type uH} [TopologicalSpace H] (I : ModelWithCorners ℝ E H) {M : Type uM} [TopologicalSpace M] [ChartedSpace H M] /-! ### Covering by supports of smooth bump functions In this section we define `SmoothBumpCovering ι I M s` to be a collection of `SmoothBumpFunction`s such that their supports is a locally finite family of sets and for each `x ∈ s` some function `f i` from the collection is equal to `1` in a neighborhood of `x`. A covering of this type is useful to construct a smooth partition of unity and can be used instead of a partition of unity in some proofs. We prove that on a smooth finite dimensional real manifold with `σ`-compact Hausdorff topology, for any `U : M → Set M` such that `∀ x ∈ s, U x ∈ 𝓝 x` there exists a `SmoothBumpCovering ι I M s` subordinate to `U`. -/ variable (ι M) /-- We say that a collection of `SmoothBumpFunction`s is a `SmoothBumpCovering` of a set `s` if * `(f i).c ∈ s` for all `i`; * the family `fun i ↦ support (f i)` is locally finite; * for each point `x ∈ s` there exists `i` such that `f i =ᶠ[𝓝 x] 1`; in other words, `x` belongs to the interior of `{y | f i y = 1}`; If `M` is a finite dimensional real manifold which is a `σ`-compact Hausdorff topological space, then for every covering `U : M → Set M`, `∀ x, U x ∈ 𝓝 x`, there exists a `SmoothBumpCovering` subordinate to `U`, see `SmoothBumpCovering.exists_isSubordinate`. This covering can be used, e.g., to construct a partition of unity and to prove the weak Whitney embedding theorem. -/ structure SmoothBumpCovering [FiniteDimensional ℝ E] (s : Set M := univ) where /-- The center point of each bump in the smooth covering. -/ c : ι → M /-- A smooth bump function around `c i`. -/ toFun : ∀ i, SmoothBumpFunction I (c i) /-- All the bump functions in the covering are centered at points in `s`. -/ c_mem' : ∀ i, c i ∈ s /-- Around each point, there are only finitely many nonzero bump functions in the family. -/ locallyFinite' : LocallyFinite fun i => support (toFun i) /-- Around each point in `s`, one of the bump functions is equal to `1`. -/ eventuallyEq_one' : ∀ x ∈ s, ∃ i, toFun i =ᶠ[𝓝 x] 1 /-- We say that a collection of functions form a smooth partition of unity on a set `s` if * all functions are infinitely smooth and nonnegative; * the family `fun i ↦ support (f i)` is locally finite; * for all `x ∈ s` the sum `∑ᶠ i, f i x` equals one; * for all `x`, the sum `∑ᶠ i, f i x` is less than or equal to one. -/ structure SmoothPartitionOfUnity (s : Set M := univ) where /-- The family of functions forming the partition of unity. -/ toFun : ι → C^∞⟮I, M; 𝓘(ℝ), ℝ⟯ /-- Around each point, there are only finitely many nonzero functions in the family. -/ locallyFinite' : LocallyFinite fun i => support (toFun i) /-- All the functions in the partition of unity are nonnegative. -/ nonneg' : ∀ i x, 0 ≤ toFun i x /-- The functions in the partition of unity add up to `1` at any point of `s`. -/ sum_eq_one' : ∀ x ∈ s, ∑ᶠ i, toFun i x = 1 /-- The functions in the partition of unity add up to at most `1` everywhere. -/ sum_le_one' : ∀ x, ∑ᶠ i, toFun i x ≤ 1 variable {ι I M} namespace SmoothPartitionOfUnity variable {s : Set M} (f : SmoothPartitionOfUnity ι I M s) {n : ℕ∞} instance {s : Set M} : FunLike (SmoothPartitionOfUnity ι I M s) ι C^∞⟮I, M; 𝓘(ℝ), ℝ⟯ where coe := toFun coe_injective' f g h := by cases f; cases g; congr protected theorem locallyFinite : LocallyFinite fun i => support (f i) := f.locallyFinite' theorem nonneg (i : ι) (x : M) : 0 ≤ f i x := f.nonneg' i x theorem sum_eq_one {x} (hx : x ∈ s) : ∑ᶠ i, f i x = 1 := f.sum_eq_one' x hx theorem exists_pos_of_mem {x} (hx : x ∈ s) : ∃ i, 0 < f i x := by by_contra! h have H : ∀ i, f i x = 0 := fun i ↦ le_antisymm (h i) (f.nonneg i x) have := f.sum_eq_one hx simp_rw [H] at this simpa theorem sum_le_one (x : M) : ∑ᶠ i, f i x ≤ 1 := f.sum_le_one' x /-- Reinterpret a smooth partition of unity as a continuous partition of unity. -/ @[simps] def toPartitionOfUnity : PartitionOfUnity ι M s := { f with toFun := fun i => f i } theorem contMDiff_sum : ContMDiff I 𝓘(ℝ) ∞ fun x => ∑ᶠ i, f i x := contMDiff_finsum (fun i => (f i).contMDiff) f.locallyFinite @[deprecated (since := "2024-11-21")] alias smooth_sum := contMDiff_sum theorem le_one (i : ι) (x : M) : f i x ≤ 1 := f.toPartitionOfUnity.le_one i x theorem sum_nonneg (x : M) : 0 ≤ ∑ᶠ i, f i x := f.toPartitionOfUnity.sum_nonneg x theorem finsum_smul_mem_convex {g : ι → M → F} {t : Set F} {x : M} (hx : x ∈ s) (hg : ∀ i, f i x ≠ 0 → g i x ∈ t) (ht : Convex ℝ t) : ∑ᶠ i, f i x • g i x ∈ t := ht.finsum_mem (fun _ => f.nonneg _ _) (f.sum_eq_one hx) hg theorem contMDiff_smul {g : M → F} {i} (hg : ∀ x ∈ tsupport (f i), ContMDiffAt I 𝓘(ℝ, F) n g x) : ContMDiff I 𝓘(ℝ, F) n fun x => f i x • g x := contMDiff_of_tsupport fun x hx => ((f i).contMDiff.contMDiffAt.of_le (mod_cast le_top)).smul <| hg x <| tsupport_smul_subset_left _ _ hx @[deprecated (since := "2024-11-21")] alias smooth_smul := contMDiff_smul /-- If `f` is a smooth partition of unity on a set `s : Set M` and `g : ι → M → F` is a family of functions such that `g i` is $C^n$ smooth at every point of the topological support of `f i`, then the sum `fun x ↦ ∑ᶠ i, f i x • g i x` is smooth on the whole manifold. -/ theorem contMDiff_finsum_smul {g : ι → M → F} (hg : ∀ (i), ∀ x ∈ tsupport (f i), ContMDiffAt I 𝓘(ℝ, F) n (g i) x) : ContMDiff I 𝓘(ℝ, F) n fun x => ∑ᶠ i, f i x • g i x := (contMDiff_finsum fun i => f.contMDiff_smul (hg i)) <| f.locallyFinite.subset fun _ => support_smul_subset_left _ _ @[deprecated (since := "2024-11-21")] alias smooth_finsum_smul := contMDiff_finsum_smul theorem contMDiffAt_finsum {x₀ : M} {g : ι → M → F} (hφ : ∀ i, x₀ ∈ tsupport (f i) → ContMDiffAt I 𝓘(ℝ, F) n (g i) x₀) : ContMDiffAt I 𝓘(ℝ, F) n (fun x ↦ ∑ᶠ i, f i x • g i x) x₀ := by refine _root_.contMDiffAt_finsum (f.locallyFinite.smul_left _) fun i ↦ ?_ by_cases hx : x₀ ∈ tsupport (f i) · exact ContMDiffAt.smul ((f i).contMDiff.of_le (mod_cast le_top)).contMDiffAt (hφ i hx) · exact contMDiffAt_of_not_mem (compl_subset_compl.mpr (tsupport_smul_subset_left (f i) (g i)) hx) n theorem contDiffAt_finsum {s : Set E} (f : SmoothPartitionOfUnity ι 𝓘(ℝ, E) E s) {x₀ : E} {g : ι → E → F} (hφ : ∀ i, x₀ ∈ tsupport (f i) → ContDiffAt ℝ n (g i) x₀) : ContDiffAt ℝ n (fun x ↦ ∑ᶠ i, f i x • g i x) x₀ := by simp only [← contMDiffAt_iff_contDiffAt] at * exact f.contMDiffAt_finsum hφ section finsupport variable {s : Set M} (ρ : SmoothPartitionOfUnity ι I M s) (x₀ : M) /-- The support of a smooth partition of unity at a point `x₀` as a `Finset`. This is the set of `i : ι` such that `x₀ ∈ support f i`, i.e. `f i ≠ x₀`. -/ def finsupport : Finset ι := ρ.toPartitionOfUnity.finsupport x₀ @[simp] theorem mem_finsupport {i : ι} : i ∈ ρ.finsupport x₀ ↔ i ∈ support fun i ↦ ρ i x₀ := ρ.toPartitionOfUnity.mem_finsupport x₀ @[simp] theorem coe_finsupport : (ρ.finsupport x₀ : Set ι) = support fun i ↦ ρ i x₀ := ρ.toPartitionOfUnity.coe_finsupport x₀ theorem sum_finsupport (hx₀ : x₀ ∈ s) : ∑ i ∈ ρ.finsupport x₀, ρ i x₀ = 1 := ρ.toPartitionOfUnity.sum_finsupport hx₀ theorem sum_finsupport' (hx₀ : x₀ ∈ s) {I : Finset ι} (hI : ρ.finsupport x₀ ⊆ I) : ∑ i ∈ I, ρ i x₀ = 1 := ρ.toPartitionOfUnity.sum_finsupport' hx₀ hI theorem sum_finsupport_smul_eq_finsum {A : Type*} [AddCommGroup A] [Module ℝ A] (φ : ι → M → A) : ∑ i ∈ ρ.finsupport x₀, ρ i x₀ • φ i x₀ = ∑ᶠ i, ρ i x₀ • φ i x₀ := ρ.toPartitionOfUnity.sum_finsupport_smul_eq_finsum φ end finsupport section fintsupport -- smooth partitions of unity have locally finite `tsupport` variable {s : Set M} (ρ : SmoothPartitionOfUnity ι I M s) (x₀ : M) /-- The `tsupport`s of a smooth partition of unity are locally finite. -/ theorem finite_tsupport : {i | x₀ ∈ tsupport (ρ i)}.Finite := ρ.toPartitionOfUnity.finite_tsupport _ /-- The tsupport of a partition of unity at a point `x₀` as a `Finset`. This is the set of `i : ι` such that `x₀ ∈ tsupport f i`. -/ def fintsupport (x : M) : Finset ι := (ρ.finite_tsupport x).toFinset theorem mem_fintsupport_iff (i : ι) : i ∈ ρ.fintsupport x₀ ↔ x₀ ∈ tsupport (ρ i) := Finite.mem_toFinset _ theorem eventually_fintsupport_subset : ∀ᶠ y in 𝓝 x₀, ρ.fintsupport y ⊆ ρ.fintsupport x₀ := ρ.toPartitionOfUnity.eventually_fintsupport_subset _ theorem finsupport_subset_fintsupport : ρ.finsupport x₀ ⊆ ρ.fintsupport x₀ := ρ.toPartitionOfUnity.finsupport_subset_fintsupport x₀ theorem eventually_finsupport_subset : ∀ᶠ y in 𝓝 x₀, ρ.finsupport y ⊆ ρ.fintsupport x₀ := ρ.toPartitionOfUnity.eventually_finsupport_subset x₀ end fintsupport section IsSubordinate /-- A smooth partition of unity `f i` is subordinate to a family of sets `U i` indexed by the same type if for each `i` the closure of the support of `f i` is a subset of `U i`. -/ def IsSubordinate (f : SmoothPartitionOfUnity ι I M s) (U : ι → Set M) := ∀ i, tsupport (f i) ⊆ U i variable {f} variable {U : ι → Set M} @[simp] theorem isSubordinate_toPartitionOfUnity : f.toPartitionOfUnity.IsSubordinate U ↔ f.IsSubordinate U := Iff.rfl alias ⟨_, IsSubordinate.toPartitionOfUnity⟩ := isSubordinate_toPartitionOfUnity /-- If `f` is a smooth partition of unity on a set `s : Set M` subordinate to a family of open sets `U : ι → Set M` and `g : ι → M → F` is a family of functions such that `g i` is $C^n$ smooth on `U i`, then the sum `fun x ↦ ∑ᶠ i, f i x • g i x` is $C^n$ smooth on the whole manifold. -/ theorem IsSubordinate.contMDiff_finsum_smul {g : ι → M → F} (hf : f.IsSubordinate U) (ho : ∀ i, IsOpen (U i)) (hg : ∀ i, ContMDiffOn I 𝓘(ℝ, F) n (g i) (U i)) : ContMDiff I 𝓘(ℝ, F) n fun x => ∑ᶠ i, f i x • g i x := f.contMDiff_finsum_smul fun i _ hx => (hg i).contMDiffAt <| (ho i).mem_nhds (hf i hx) @[deprecated (since := "2024-11-21")] alias IsSubordinate.smooth_finsum_smul := IsSubordinate.contMDiff_finsum_smul end IsSubordinate end SmoothPartitionOfUnity namespace BumpCovering -- Repeat variables to drop `[FiniteDimensional ℝ E]` and `[IsManifold I ∞ M]` theorem contMDiff_toPartitionOfUnity {E : Type uE} [NormedAddCommGroup E] [NormedSpace ℝ E] {H : Type uH} [TopologicalSpace H] {I : ModelWithCorners ℝ E H} {M : Type uM} [TopologicalSpace M] [ChartedSpace H M] {s : Set M} (f : BumpCovering ι M s) (hf : ∀ i, ContMDiff I 𝓘(ℝ) ∞ (f i)) (i : ι) : ContMDiff I 𝓘(ℝ) ∞ (f.toPartitionOfUnity i) := (hf i).mul <| (contMDiff_finprod_cond fun j _ => contMDiff_const.sub (hf j)) <| by simp only [Pi.sub_def, mulSupport_one_sub] exact f.locallyFinite @[deprecated (since := "2024-11-21")] alias smooth_toPartitionOfUnity := contMDiff_toPartitionOfUnity variable {s : Set M} /-- A `BumpCovering` such that all functions in this covering are smooth generates a smooth partition of unity. In our formalization, not every `f : BumpCovering ι M s` with smooth functions `f i` is a `SmoothBumpCovering`; instead, a `SmoothBumpCovering` is a covering by supports of `SmoothBumpFunction`s. So, we define `BumpCovering.toSmoothPartitionOfUnity`, then reuse it in `SmoothBumpCovering.toSmoothPartitionOfUnity`. -/ def toSmoothPartitionOfUnity (f : BumpCovering ι M s) (hf : ∀ i, ContMDiff I 𝓘(ℝ) ∞ (f i)) : SmoothPartitionOfUnity ι I M s := { f.toPartitionOfUnity with toFun := fun i => ⟨f.toPartitionOfUnity i, f.contMDiff_toPartitionOfUnity hf i⟩ } @[simp] theorem toSmoothPartitionOfUnity_toPartitionOfUnity (f : BumpCovering ι M s) (hf : ∀ i, ContMDiff I 𝓘(ℝ) ∞ (f i)) : (f.toSmoothPartitionOfUnity hf).toPartitionOfUnity = f.toPartitionOfUnity := rfl @[simp] theorem coe_toSmoothPartitionOfUnity (f : BumpCovering ι M s) (hf : ∀ i, ContMDiff I 𝓘(ℝ) ∞ (f i)) (i : ι) : ⇑(f.toSmoothPartitionOfUnity hf i) = f.toPartitionOfUnity i := rfl theorem IsSubordinate.toSmoothPartitionOfUnity {f : BumpCovering ι M s} {U : ι → Set M} (h : f.IsSubordinate U) (hf : ∀ i, ContMDiff I 𝓘(ℝ) ∞ (f i)) : (f.toSmoothPartitionOfUnity hf).IsSubordinate U := h.toPartitionOfUnity end BumpCovering namespace SmoothBumpCovering variable [FiniteDimensional ℝ E] variable {s : Set M} {U : M → Set M} (fs : SmoothBumpCovering ι I M s) instance : CoeFun (SmoothBumpCovering ι I M s) fun x => ∀ i : ι, SmoothBumpFunction I (x.c i) := ⟨toFun⟩ /-- We say that `f : SmoothBumpCovering ι I M s` is *subordinate* to a map `U : M → Set M` if for each index `i`, we have `tsupport (f i) ⊆ U (f i).c`. This notion is a bit more general than being subordinate to an open covering of `M`, because we make no assumption about the way `U x` depends on `x`. -/ def IsSubordinate {s : Set M} (f : SmoothBumpCovering ι I M s) (U : M → Set M) := ∀ i, tsupport (f i) ⊆ U (f.c i) theorem IsSubordinate.support_subset {fs : SmoothBumpCovering ι I M s} {U : M → Set M} (h : fs.IsSubordinate U) (i : ι) : support (fs i) ⊆ U (fs.c i) := Subset.trans subset_closure (h i) variable (I) in /-- Let `M` be a smooth manifold modelled on a finite dimensional real vector space. Suppose also that `M` is a Hausdorff `σ`-compact topological space. Let `s` be a closed set in `M` and `U : M → Set M` be a collection of sets such that `U x ∈ 𝓝 x` for every `x ∈ s`. Then there exists a smooth bump covering of `s` that is subordinate to `U`. -/ theorem exists_isSubordinate [T2Space M] [SigmaCompactSpace M] (hs : IsClosed s) (hU : ∀ x ∈ s, U x ∈ 𝓝 x) : ∃ (ι : Type uM) (f : SmoothBumpCovering ι I M s), f.IsSubordinate U := by -- First we deduce some missing instances haveI : LocallyCompactSpace H := I.locallyCompactSpace haveI : LocallyCompactSpace M := ChartedSpace.locallyCompactSpace H M -- Next we choose a covering by supports of smooth bump functions have hB := fun x hx => SmoothBumpFunction.nhds_basis_support (I := I) (hU x hx) rcases refinement_of_locallyCompact_sigmaCompact_of_nhds_basis_set hs hB with ⟨ι, c, f, hf, hsub', hfin⟩ choose hcs hfU using hf -- Then we use the shrinking lemma to get a covering by smaller open rcases exists_subset_iUnion_closed_subset hs (fun i => (f i).isOpen_support) (fun x _ => hfin.point_finite x) hsub' with ⟨V, hsV, hVc, hVf⟩ choose r hrR hr using fun i => (f i).exists_r_pos_lt_subset_ball (hVc i) (hVf i) refine ⟨ι, ⟨c, fun i => (f i).updateRIn (r i) (hrR i), hcs, ?_, fun x hx => ?_⟩, fun i => ?_⟩ · simpa only [SmoothBumpFunction.support_updateRIn] · refine (mem_iUnion.1 <| hsV hx).imp fun i hi => ?_ exact ((f i).updateRIn _ _).eventuallyEq_one_of_dist_lt ((f i).support_subset_source <| hVf _ hi) (hr i hi).2 · simpa only [SmoothBumpFunction.support_updateRIn, tsupport] using hfU i protected theorem locallyFinite : LocallyFinite fun i => support (fs i) := fs.locallyFinite' protected theorem point_finite (x : M) : {i | fs i x ≠ 0}.Finite := fs.locallyFinite.point_finite x /-- Index of a bump function such that `fs i =ᶠ[𝓝 x] 1`. -/ def ind (x : M) (hx : x ∈ s) : ι := (fs.eventuallyEq_one' x hx).choose theorem eventuallyEq_one (x : M) (hx : x ∈ s) : fs (fs.ind x hx) =ᶠ[𝓝 x] 1 := (fs.eventuallyEq_one' x hx).choose_spec theorem apply_ind (x : M) (hx : x ∈ s) : fs (fs.ind x hx) x = 1 := (fs.eventuallyEq_one x hx).eq_of_nhds theorem mem_support_ind (x : M) (hx : x ∈ s) : x ∈ support (fs <| fs.ind x hx) := by simp [fs.apply_ind x hx] theorem mem_chartAt_source_of_eq_one {i : ι} {x : M} (h : fs i x = 1) : x ∈ (chartAt H (fs.c i)).source := (fs i).support_subset_source <| by simp [h] theorem mem_extChartAt_source_of_eq_one {i : ι} {x : M} (h : fs i x = 1) : x ∈ (extChartAt I (fs.c i)).source := by rw [extChartAt_source]; exact fs.mem_chartAt_source_of_eq_one h theorem mem_chartAt_ind_source (x : M) (hx : x ∈ s) : x ∈ (chartAt H (fs.c (fs.ind x hx))).source := fs.mem_chartAt_source_of_eq_one (fs.apply_ind x hx) theorem mem_extChartAt_ind_source (x : M) (hx : x ∈ s) : x ∈ (extChartAt I (fs.c (fs.ind x hx))).source := fs.mem_extChartAt_source_of_eq_one (fs.apply_ind x hx) /-- The index type of a `SmoothBumpCovering` of a compact manifold is finite. -/ protected def fintype [CompactSpace M] : Fintype ι := fs.locallyFinite.fintypeOfCompact fun i => (fs i).nonempty_support variable [T2Space M] variable [IsManifold I ∞ M] /-- Reinterpret a `SmoothBumpCovering` as a continuous `BumpCovering`. Note that not every `f : BumpCovering ι M s` with smooth functions `f i` is a `SmoothBumpCovering`. -/ def toBumpCovering : BumpCovering ι M s where toFun i := ⟨fs i, (fs i).continuous⟩ locallyFinite' := fs.locallyFinite nonneg' i _ := (fs i).nonneg le_one' i _ := (fs i).le_one eventuallyEq_one' := fs.eventuallyEq_one' @[simp] theorem isSubordinate_toBumpCovering {f : SmoothBumpCovering ι I M s} {U : M → Set M} : (f.toBumpCovering.IsSubordinate fun i => U (f.c i)) ↔ f.IsSubordinate U := Iff.rfl alias ⟨_, IsSubordinate.toBumpCovering⟩ := isSubordinate_toBumpCovering /-- Every `SmoothBumpCovering` defines a smooth partition of unity. -/ def toSmoothPartitionOfUnity : SmoothPartitionOfUnity ι I M s := fs.toBumpCovering.toSmoothPartitionOfUnity fun i => (fs i).contMDiff theorem toSmoothPartitionOfUnity_apply (i : ι) (x : M) : fs.toSmoothPartitionOfUnity i x = fs i x * ∏ᶠ (j) (_ : WellOrderingRel j i), (1 - fs j x) := rfl open Classical in theorem toSmoothPartitionOfUnity_eq_mul_prod (i : ι) (x : M) (t : Finset ι) (ht : ∀ j, WellOrderingRel j i → fs j x ≠ 0 → j ∈ t) : fs.toSmoothPartitionOfUnity i x = fs i x * ∏ j ∈ t with WellOrderingRel j i, (1 - fs j x) := fs.toBumpCovering.toPartitionOfUnity_eq_mul_prod i x t ht open Classical in theorem exists_finset_toSmoothPartitionOfUnity_eventuallyEq (i : ι) (x : M) : ∃ t : Finset ι, fs.toSmoothPartitionOfUnity i =ᶠ[𝓝 x] fs i * ∏ j ∈ t with WellOrderingRel j i, ((1 : M → ℝ) - fs j) := by -- Porting note: was defeq, now the continuous lemma uses bundled homs simpa using fs.toBumpCovering.exists_finset_toPartitionOfUnity_eventuallyEq i x theorem toSmoothPartitionOfUnity_zero_of_zero {i : ι} {x : M} (h : fs i x = 0) : fs.toSmoothPartitionOfUnity i x = 0 := fs.toBumpCovering.toPartitionOfUnity_zero_of_zero h theorem support_toSmoothPartitionOfUnity_subset (i : ι) : support (fs.toSmoothPartitionOfUnity i) ⊆ support (fs i) := fs.toBumpCovering.support_toPartitionOfUnity_subset i theorem IsSubordinate.toSmoothPartitionOfUnity {f : SmoothBumpCovering ι I M s} {U : M → Set M} (h : f.IsSubordinate U) : f.toSmoothPartitionOfUnity.IsSubordinate fun i => U (f.c i) := h.toBumpCovering.toPartitionOfUnity theorem sum_toSmoothPartitionOfUnity_eq (x : M) : ∑ᶠ i, fs.toSmoothPartitionOfUnity i x = 1 - ∏ᶠ i, (1 - fs i x) := fs.toBumpCovering.sum_toPartitionOfUnity_eq x end SmoothBumpCovering variable (I) variable [FiniteDimensional ℝ E] variable [IsManifold I ∞ M] /-- Given two disjoint closed sets `s, t` in a Hausdorff σ-compact finite dimensional manifold, there exists an infinitely smooth function that is equal to `0` on `s` and to `1` on `t`. See also `exists_msmooth_zero_iff_one_iff_of_isClosed`, which ensures additionally that `f` is equal to `0` exactly on `s` and to `1` exactly on `t`. -/ theorem exists_smooth_zero_one_of_isClosed [T2Space M] [SigmaCompactSpace M] {s t : Set M} (hs : IsClosed s) (ht : IsClosed t) (hd : Disjoint s t) : ∃ f : C^∞⟮I, M; 𝓘(ℝ), ℝ⟯, EqOn f 0 s ∧ EqOn f 1 t ∧ ∀ x, f x ∈ Icc 0 1 := by have : ∀ x ∈ t, sᶜ ∈ 𝓝 x := fun x hx => hs.isOpen_compl.mem_nhds (disjoint_right.1 hd hx) rcases SmoothBumpCovering.exists_isSubordinate I ht this with ⟨ι, f, hf⟩ set g := f.toSmoothPartitionOfUnity refine ⟨⟨_, g.contMDiff_sum⟩, fun x hx => ?_, fun x => g.sum_eq_one, fun x => ⟨g.sum_nonneg x, g.sum_le_one x⟩⟩ suffices ∀ i, g i x = 0 by simp only [this, ContMDiffMap.coeFn_mk, finsum_zero, Pi.zero_apply] refine fun i => f.toSmoothPartitionOfUnity_zero_of_zero ?_ exact nmem_support.1 (subset_compl_comm.1 (hf.support_subset i) hx) /-- Given two disjoint closed sets `s, t` in a Hausdorff normal σ-compact finite dimensional manifold `M`, there exists a smooth function `f : M → [0,1]` that vanishes in a neighbourhood of `s` and is equal to `1` in a neighbourhood of `t`. -/ theorem exists_smooth_zero_one_nhds_of_isClosed [T2Space M] [NormalSpace M] [SigmaCompactSpace M] {s t : Set M} (hs : IsClosed s) (ht : IsClosed t) (hd : Disjoint s t) : ∃ f : C^∞⟮I, M; 𝓘(ℝ), ℝ⟯, (∀ᶠ x in 𝓝ˢ s, f x = 0) ∧ (∀ᶠ x in 𝓝ˢ t, f x = 1) ∧ ∀ x, f x ∈ Icc 0 1 := by obtain ⟨u, u_op, hsu, hut⟩ := normal_exists_closure_subset hs ht.isOpen_compl (subset_compl_iff_disjoint_left.mpr hd.symm) obtain ⟨v, v_op, htv, hvu⟩ := normal_exists_closure_subset ht isClosed_closure.isOpen_compl (subset_compl_comm.mp hut) obtain ⟨f, hfu, hfv, hf⟩ := exists_smooth_zero_one_of_isClosed I isClosed_closure isClosed_closure (subset_compl_iff_disjoint_left.mp hvu) refine ⟨f, ?_, ?_, hf⟩ · exact eventually_of_mem (mem_of_superset (u_op.mem_nhdsSet.mpr hsu) subset_closure) hfu · exact eventually_of_mem (mem_of_superset (v_op.mem_nhdsSet.mpr htv) subset_closure) hfv /-- Given two sets `s, t` in a Hausdorff normal σ-compact finite-dimensional manifold `M` with `s` open and `s ⊆ interior t`, there is a smooth function `f : M → [0,1]` which is equal to `s` in a neighbourhood of `s` and has support contained in `t`. -/ theorem exists_smooth_one_nhds_of_subset_interior [T2Space M] [NormalSpace M] [SigmaCompactSpace M] {s t : Set M} (hs : IsClosed s) (hd : s ⊆ interior t) : ∃ f : C^∞⟮I, M; 𝓘(ℝ), ℝ⟯, (∀ᶠ x in 𝓝ˢ s, f x = 1) ∧ (∀ x ∉ t, f x = 0) ∧ ∀ x, f x ∈ Icc 0 1 := by rcases exists_smooth_zero_one_nhds_of_isClosed I isOpen_interior.isClosed_compl hs (by rwa [← subset_compl_iff_disjoint_left, compl_compl]) with ⟨f, h0, h1, hf⟩ refine ⟨f, h1, fun x hx ↦ ?_, hf⟩ exact h0.self_of_nhdsSet _ fun hx' ↦ hx <| interior_subset hx' namespace SmoothPartitionOfUnity /-- A `SmoothPartitionOfUnity` that consists of a single function, uniformly equal to one, defined as an example for `Inhabited` instance. -/ def single (i : ι) (s : Set M) : SmoothPartitionOfUnity ι I M s := (BumpCovering.single i s).toSmoothPartitionOfUnity fun j => by classical rcases eq_or_ne j i with (rfl | h) · simp only [contMDiff_one, ContinuousMap.coe_one, BumpCovering.coe_single, Pi.single_eq_same] · simp only [contMDiff_zero, BumpCovering.coe_single, Pi.single_eq_of_ne h, ContinuousMap.coe_zero] instance [Inhabited ι] (s : Set M) : Inhabited (SmoothPartitionOfUnity ι I M s) := ⟨single I default s⟩ variable [T2Space M] [SigmaCompactSpace M] /-- If `X` is a paracompact normal topological space and `U` is an open covering of a closed set `s`, then there exists a `SmoothPartitionOfUnity ι M s` that is subordinate to `U`. -/ theorem exists_isSubordinate {s : Set M} (hs : IsClosed s) (U : ι → Set M) (ho : ∀ i, IsOpen (U i)) (hU : s ⊆ ⋃ i, U i) : ∃ f : SmoothPartitionOfUnity ι I M s, f.IsSubordinate U := by haveI : LocallyCompactSpace H := I.locallyCompactSpace haveI : LocallyCompactSpace M := ChartedSpace.locallyCompactSpace H M -- porting note(https://github.com/leanprover/std4/issues/116): -- split `rcases` into `have` + `rcases` have := BumpCovering.exists_isSubordinate_of_prop (ContMDiff I 𝓘(ℝ) ∞) ?_ hs U ho hU · rcases this with ⟨f, hf, hfU⟩ exact ⟨f.toSmoothPartitionOfUnity hf, hfU.toSmoothPartitionOfUnity hf⟩ · intro s t hs ht hd rcases exists_smooth_zero_one_of_isClosed I hs ht hd with ⟨f, hf⟩ exact ⟨f, f.contMDiff, hf⟩ theorem exists_isSubordinate_chartAt_source_of_isClosed {s : Set M} (hs : IsClosed s) : ∃ f : SmoothPartitionOfUnity s I M s, f.IsSubordinate (fun x ↦ (chartAt H (x : M)).source) := by apply exists_isSubordinate _ hs _ (fun i ↦ (chartAt H _).open_source) (fun x hx ↦ ?_) exact mem_iUnion_of_mem ⟨x, hx⟩ (mem_chart_source H x)
variable (M) theorem exists_isSubordinate_chartAt_source : ∃ f : SmoothPartitionOfUnity M I M univ, f.IsSubordinate (fun x ↦ (chartAt H x).source) := by apply exists_isSubordinate _ isClosed_univ _ (fun i ↦ (chartAt H _).open_source) (fun x _ ↦ ?_) exact mem_iUnion_of_mem x (mem_chart_source H x) end SmoothPartitionOfUnity variable [SigmaCompactSpace M] [T2Space M] {t : M → Set F} {n : ℕ∞} /-- Let `M` be a σ-compact Hausdorff finite dimensional topological manifold. Let `t : M → Set F` be a family of convex sets. Suppose that for each point `x : M` there exists a neighborhood
Mathlib/Geometry/Manifold/PartitionOfUnity.lean
576
588
/- 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.Analysis.Convex.Deriv import Mathlib.Analysis.SpecialFunctions.Gamma.Deligne import Mathlib.Data.Nat.Factorial.Basic import Mathlib.NumberTheory.Harmonic.EulerMascheroni /-! # Derivative of Γ at positive integers We prove the formula for the derivative of `Real.Gamma` at a positive integer: `deriv Real.Gamma (n + 1) = Nat.factorial n * (-Real.eulerMascheroniConstant + harmonic n)` -/ open Nat Set Filter Topology local notation "γ" => Real.eulerMascheroniConstant namespace Real
/-- Explicit formula for the derivative of the Gamma function at positive integers, in terms of harmonic numbers and the Euler-Mascheroni constant `γ`. -/ lemma deriv_Gamma_nat (n : ℕ) : deriv Gamma (n + 1) = n ! * (-γ + harmonic n) := by /- This follows from two properties of the function `f n = log (Gamma n)`: firstly, the elementary computation that `deriv f (n + 1) = deriv f n + 1 / n`, so that `deriv f n = deriv f 1 + harmonic n`; secondly, the convexity of `f` (the Bohr-Mollerup theorem), which shows that `deriv f n` is `log n + o(1)` as `n → ∞`. -/ let f := log ∘ Gamma -- First reduce to computing derivative of `log ∘ Gamma`. suffices deriv (log ∘ Gamma) (n + 1) = -γ + harmonic n by rwa [Function.comp_def, deriv.log (differentiableAt_Gamma (fun m ↦ by linarith)) (by positivity), Gamma_nat_eq_factorial, div_eq_iff_mul_eq (by positivity), mul_comm, Eq.comm] at this have hc : ConvexOn ℝ (Ioi 0) f := convexOn_log_Gamma have h_rec (x : ℝ) (hx : 0 < x) : f (x + 1) = f x + log x := by simp only [f, Function.comp_apply, Gamma_add_one hx.ne', log_mul hx.ne' (Gamma_pos_of_pos hx).ne', add_comm] have hder {x : ℝ} (hx : 0 < x) : DifferentiableAt ℝ f x := by refine ((differentiableAt_Gamma ?_).log (Gamma_ne_zero ?_)) <;> exact fun m ↦ ne_of_gt (by linarith) -- Express derivative at general `n` in terms of value at `1` using recurrence relation have hder_rec (x : ℝ) (hx : 0 < x) : deriv f (x + 1) = deriv f x + 1 / x := by rw [← deriv_comp_add_const, one_div, ← deriv_log, ← deriv_add (hder <| by positivity) (differentiableAt_log hx.ne')] apply EventuallyEq.deriv_eq filter_upwards [eventually_gt_nhds hx] using h_rec have hder_nat (n : ℕ) : deriv f (n + 1) = deriv f 1 + harmonic n := by induction n with | zero => simp | succ n hn => rw [cast_succ, hder_rec (n + 1) (by positivity), hn, harmonic_succ] push_cast ring suffices -deriv f 1 = γ by rw [hder_nat n, ← this, neg_neg] -- Use convexity to show derivative of `f` at `n + 1` is between `log n` and `log (n + 1)` have derivLB (n : ℕ) (hn : 0 < n) : log n ≤ deriv f (n + 1) := by refine (le_of_eq ?_).trans <| hc.slope_le_deriv (mem_Ioi.mpr <| Nat.cast_pos.mpr hn) (by positivity : _ < (_ : ℝ)) (by linarith) (hder <| by positivity) rw [slope_def_field, show n + 1 - n = (1 : ℝ) by ring, div_one, h_rec n (by positivity), add_sub_cancel_left] have derivUB (n : ℕ) : deriv f (n + 1) ≤ log (n + 1) := by refine (hc.deriv_le_slope (by positivity : (0 : ℝ) < n + 1) (by positivity : (0 : ℝ) < n + 2) (by linarith) (hder <| by positivity)).trans (le_of_eq ?_) rw [slope_def_field, show n + 2 - (n + 1) = (1 : ℝ) by ring, div_one, show n + 2 = (n + 1) + (1 : ℝ) by ring, h_rec (n + 1) (by positivity), add_sub_cancel_left] -- deduce `-deriv f 1` is bounded above + below by sequences which both tend to `γ` apply le_antisymm · apply ge_of_tendsto tendsto_harmonic_sub_log filter_upwards [eventually_gt_atTop 0] with n hn rw [le_sub_iff_add_le', ← sub_eq_add_neg, sub_le_iff_le_add', ← hder_nat] exact derivLB n hn · apply le_of_tendsto tendsto_harmonic_sub_log_add_one filter_upwards with n rw [sub_le_iff_le_add', ← sub_eq_add_neg, le_sub_iff_add_le', ← hder_nat]
Mathlib/NumberTheory/Harmonic/GammaDeriv.lean
26
80
/- 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
1,249
1,249
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.RingTheory.DedekindDomain.Ideal /-! # The ideal class group This file defines the ideal class group `ClassGroup R` of fractional ideals of `R` inside its field of fractions. ## Main definitions - `toPrincipalIdeal` sends an invertible `x : K` to an invertible fractional ideal - `ClassGroup` is the quotient of invertible fractional ideals modulo `toPrincipalIdeal.range` - `ClassGroup.mk0` sends a nonzero integral ideal in a Dedekind domain to its class ## Main results - `ClassGroup.mk0_eq_mk0_iff` shows the equivalence with the "classical" definition, where `I ~ J` iff `x I = y J` for `x y ≠ (0 : R)` ## Implementation details The definition of `ClassGroup R` involves `FractionRing R`. However, the API should be completely identical no matter the choice of field of fractions for `R`. -/ variable {R K : Type*} [CommRing R] [Field K] [Algebra R K] [IsFractionRing R K] open scoped nonZeroDivisors open IsLocalization IsFractionRing FractionalIdeal Units section variable (R K) /-- `toPrincipalIdeal R K x` sends `x ≠ 0 : K` to the fractional `R`-ideal generated by `x` -/ irreducible_def toPrincipalIdeal : Kˣ →* (FractionalIdeal R⁰ K)ˣ := { toFun := fun x => ⟨spanSingleton _ x, spanSingleton _ x⁻¹, by simp only [spanSingleton_one, Units.mul_inv', spanSingleton_mul_spanSingleton], by simp only [spanSingleton_one, Units.inv_mul', spanSingleton_mul_spanSingleton]⟩ map_mul' := fun x y => ext (by simp only [Units.val_mk, Units.val_mul, spanSingleton_mul_spanSingleton]) map_one' := ext (by simp only [spanSingleton_one, Units.val_mk, Units.val_one]) } variable {R K} @[simp] theorem coe_toPrincipalIdeal (x : Kˣ) : (toPrincipalIdeal R K x : FractionalIdeal R⁰ K) = spanSingleton _ (x : K) := by simp only [toPrincipalIdeal]; rfl @[simp] theorem toPrincipalIdeal_eq_iff {I : (FractionalIdeal R⁰ K)ˣ} {x : Kˣ} : toPrincipalIdeal R K x = I ↔ spanSingleton R⁰ (x : K) = I := by simp only [toPrincipalIdeal]; exact Units.ext_iff theorem mem_principal_ideals_iff {I : (FractionalIdeal R⁰ K)ˣ} : I ∈ (toPrincipalIdeal R K).range ↔ ∃ x : K, spanSingleton R⁰ x = I := by simp only [MonoidHom.mem_range, toPrincipalIdeal_eq_iff] constructor <;> rintro ⟨x, hx⟩ · exact ⟨x, hx⟩ · refine ⟨Units.mk0 x ?_, hx⟩ rintro rfl simp [I.ne_zero.symm] at hx instance PrincipalIdeals.normal : (toPrincipalIdeal R K).range.Normal := Subgroup.normal_of_comm _ end variable (R) variable [IsDomain R] /-- The ideal class group of `R` is the group of invertible fractional ideals modulo the principal ideals. -/ def ClassGroup := (FractionalIdeal R⁰ (FractionRing R))ˣ ⧸ (toPrincipalIdeal R (FractionRing R)).range noncomputable instance : CommGroup (ClassGroup R) := QuotientGroup.Quotient.commGroup (toPrincipalIdeal R (FractionRing R)).range noncomputable instance : Inhabited (ClassGroup R) := ⟨1⟩ variable {R} /-- Send a nonzero fractional ideal to the corresponding class in the class group. -/ noncomputable def ClassGroup.mk : (FractionalIdeal R⁰ K)ˣ →* ClassGroup R := (QuotientGroup.mk' (toPrincipalIdeal R (FractionRing R)).range).comp (Units.map (FractionalIdeal.canonicalEquiv R⁰ K (FractionRing R))) lemma ClassGroup.mk_def (I : (FractionalIdeal R⁰ K)ˣ) : ClassGroup.mk I = (QuotientGroup.mk' (toPrincipalIdeal R (FractionRing R)).range) (Units.map (FractionalIdeal.canonicalEquiv R⁰ K (FractionRing R)) I) := rfl -- Can't be `@[simp]` because it can't figure out the quotient relation. theorem ClassGroup.Quot_mk_eq_mk (I : (FractionalIdeal R⁰ (FractionRing R))ˣ) : Quot.mk _ I = ClassGroup.mk I := by rw [ClassGroup.mk_def, canonicalEquiv_self, RingEquiv.coe_monoidHom_refl, Units.map_id, MonoidHom.id_apply, QuotientGroup.mk'_apply] rfl theorem ClassGroup.mk_eq_mk {I J : (FractionalIdeal R⁰ <| FractionRing R)ˣ} : ClassGroup.mk I = ClassGroup.mk J ↔ ∃ x : (FractionRing R)ˣ, I * toPrincipalIdeal R (FractionRing R) x = J := by rw [mk_def, mk_def, QuotientGroup.mk'_eq_mk'] simp [RingEquiv.coe_monoidHom_refl, MonoidHom.mem_range, -toPrincipalIdeal_eq_iff] theorem ClassGroup.mk_eq_mk_of_coe_ideal {I J : (FractionalIdeal R⁰ <| FractionRing R)ˣ} {I' J' : Ideal R} (hI : (I : FractionalIdeal R⁰ <| FractionRing R) = I') (hJ : (J : FractionalIdeal R⁰ <| FractionRing R) = J') : ClassGroup.mk I = ClassGroup.mk J ↔ ∃ x y : R, x ≠ 0 ∧ y ≠ 0 ∧ Ideal.span {x} * I' = Ideal.span {y} * J' := by rw [ClassGroup.mk_eq_mk] constructor · rintro ⟨x, rfl⟩ rw [Units.val_mul, hI, coe_toPrincipalIdeal, mul_comm, spanSingleton_mul_coeIdeal_eq_coeIdeal] at hJ exact ⟨_, _, sec_fst_ne_zero x.ne_zero, sec_snd_ne_zero (R := R) le_rfl (x : FractionRing R), hJ⟩ · rintro ⟨x, y, hx, hy, h⟩ have : IsUnit (mk' (FractionRing R) x ⟨y, mem_nonZeroDivisors_of_ne_zero hy⟩) := by simpa only [isUnit_iff_ne_zero, ne_eq, mk'_eq_zero_iff_eq_zero] using hx refine ⟨this.unit, ?_⟩ rw [mul_comm, ← Units.eq_iff, Units.val_mul, coe_toPrincipalIdeal] convert (mk'_mul_coeIdeal_eq_coeIdeal (FractionRing R) <| mem_nonZeroDivisors_of_ne_zero hy).2 h theorem ClassGroup.mk_eq_one_of_coe_ideal {I : (FractionalIdeal R⁰ <| FractionRing R)ˣ} {I' : Ideal R} (hI : (I : FractionalIdeal R⁰ <| FractionRing R) = I') : ClassGroup.mk I = 1 ↔ ∃ x : R, x ≠ 0 ∧ I' = Ideal.span {x} := by rw [← map_one (ClassGroup.mk (R := R) (K := FractionRing R)), ClassGroup.mk_eq_mk_of_coe_ideal hI] any_goals rfl constructor · rintro ⟨x, y, hx, hy, h⟩ rw [Ideal.mul_top] at h rcases Ideal.mem_span_singleton_mul.mp ((Ideal.span_singleton_le_iff_mem _).mp h.ge) with ⟨i, _hi, rfl⟩ rw [← Ideal.span_singleton_mul_span_singleton, Ideal.span_singleton_mul_right_inj hx] at h exact ⟨i, right_ne_zero_of_mul hy, h⟩ · rintro ⟨x, hx, rfl⟩ exact ⟨1, x, one_ne_zero, hx, by rw [Ideal.span_singleton_one, Ideal.top_mul, Ideal.mul_top]⟩ variable (K) /-- Induction principle for the class group: to show something holds for all `x : ClassGroup R`, we can choose a fraction field `K` and show it holds for the equivalence class of each `I : FractionalIdeal R⁰ K`. -/ @[elab_as_elim] theorem ClassGroup.induction {P : ClassGroup R → Prop} (h : ∀ I : (FractionalIdeal R⁰ K)ˣ, P (ClassGroup.mk I)) (x : ClassGroup R) : P x := QuotientGroup.induction_on x fun I => by have : I = (Units.mapEquiv (canonicalEquiv R⁰ K (FractionRing R)).toMulEquiv) (Units.mapEquiv (canonicalEquiv R⁰ (FractionRing R) K).toMulEquiv I) := by simp [← Units.eq_iff] rw [congr_arg (QuotientGroup.mk (s := (toPrincipalIdeal R (FractionRing R)).range)) this] exact h _ /-- The definition of the class group does not depend on the choice of field of fractions. -/ noncomputable def ClassGroup.equiv : ClassGroup R ≃* (FractionalIdeal R⁰ K)ˣ ⧸ (toPrincipalIdeal R K).range := by haveI : Subgroup.map (Units.mapEquiv (canonicalEquiv R⁰ (FractionRing R) K).toMulEquiv).toMonoidHom (toPrincipalIdeal R (FractionRing R)).range = (toPrincipalIdeal R K).range := by ext I simp only [Subgroup.mem_map, mem_principal_ideals_iff] constructor · rintro ⟨I, ⟨x, hx⟩, rfl⟩ refine ⟨FractionRing.algEquiv R K x, ?_⟩ simp only [RingEquiv.toMulEquiv_eq_coe, MulEquiv.coe_toMonoidHom, coe_mapEquiv, ← hx, RingEquiv.coe_toMulEquiv, canonicalEquiv_spanSingleton] rfl · rintro ⟨x, hx⟩ refine ⟨Units.mapEquiv (canonicalEquiv R⁰ K (FractionRing R)).toMulEquiv I, ⟨(FractionRing.algEquiv R K).symm x, ?_⟩, Units.ext ?_⟩ · simp only [RingEquiv.toMulEquiv_eq_coe, coe_mapEquiv, ← hx, RingEquiv.coe_toMulEquiv, canonicalEquiv_spanSingleton] rfl · simp only [RingEquiv.toMulEquiv_eq_coe, MulEquiv.coe_toMonoidHom, coe_mapEquiv, RingEquiv.coe_toMulEquiv, canonicalEquiv_canonicalEquiv, canonicalEquiv_self, RingEquiv.refl_apply] exact @QuotientGroup.congr (FractionalIdeal R⁰ (FractionRing R))ˣ _ (FractionalIdeal R⁰ K)ˣ _ (toPrincipalIdeal R (FractionRing R)).range (toPrincipalIdeal R K).range _ _ (Units.mapEquiv (FractionalIdeal.canonicalEquiv R⁰ (FractionRing R) K).toMulEquiv) this @[simp] theorem ClassGroup.equiv_mk (K' : Type*) [Field K'] [Algebra R K'] [IsFractionRing R K'] (I : (FractionalIdeal R⁰ K)ˣ) : ClassGroup.equiv K' (ClassGroup.mk I) = QuotientGroup.mk' _ (Units.mapEquiv (↑(FractionalIdeal.canonicalEquiv R⁰ K K')) I) := by -- `simp` can't apply `ClassGroup.mk_def` and `rw` can't unfold `ClassGroup`. rw [ClassGroup.equiv, ClassGroup.mk_def] simp only [ClassGroup, QuotientGroup.congr_mk'] congr rw [← Units.eq_iff, Units.coe_mapEquiv, Units.coe_mapEquiv, Units.coe_map] exact FractionalIdeal.canonicalEquiv_canonicalEquiv _ _ _ _ _ @[simp] theorem ClassGroup.mk_canonicalEquiv (K' : Type*) [Field K'] [Algebra R K'] [IsFractionRing R K'] (I : (FractionalIdeal R⁰ K)ˣ) : ClassGroup.mk (Units.map (↑(canonicalEquiv R⁰ K K')) I : (FractionalIdeal R⁰ K')ˣ) = ClassGroup.mk I := by rw [ClassGroup.mk_def, ClassGroup.mk_def, ← MonoidHom.comp_apply (Units.map _), ← Units.map_comp, ← RingEquiv.coe_monoidHom_trans, FractionalIdeal.canonicalEquiv_trans_canonicalEquiv] /-- Send a nonzero integral ideal to an invertible fractional ideal. -/ noncomputable def FractionalIdeal.mk0 [IsDedekindDomain R] : (Ideal R)⁰ →* (FractionalIdeal R⁰ K)ˣ where toFun I := Units.mk0 I (coeIdeal_ne_zero.mpr <| mem_nonZeroDivisors_iff_ne_zero.mp I.2) map_one' := by simp map_mul' x y := by simp @[simp] theorem FractionalIdeal.coe_mk0 [IsDedekindDomain R] (I : (Ideal R)⁰) : (FractionalIdeal.mk0 K I : FractionalIdeal R⁰ K) = I := rfl theorem FractionalIdeal.canonicalEquiv_mk0 [IsDedekindDomain R] (K' : Type*) [Field K'] [Algebra R K'] [IsFractionRing R K'] (I : (Ideal R)⁰) : FractionalIdeal.canonicalEquiv R⁰ K K' (FractionalIdeal.mk0 K I) = FractionalIdeal.mk0 K' I := by simp only [FractionalIdeal.coe_mk0, FractionalIdeal.canonicalEquiv_coeIdeal] @[simp] theorem FractionalIdeal.map_canonicalEquiv_mk0 [IsDedekindDomain R] (K' : Type*) [Field K'] [Algebra R K'] [IsFractionRing R K'] (I : (Ideal R)⁰) : Units.map (↑(FractionalIdeal.canonicalEquiv R⁰ K K')) (FractionalIdeal.mk0 K I) = FractionalIdeal.mk0 K' I := Units.ext (FractionalIdeal.canonicalEquiv_mk0 K K' I) /-- Send a nonzero ideal to the corresponding class in the class group. -/ noncomputable def ClassGroup.mk0 [IsDedekindDomain R] : (Ideal R)⁰ →* ClassGroup R := ClassGroup.mk.comp (FractionalIdeal.mk0 (FractionRing R)) @[simp] theorem ClassGroup.mk_mk0 [IsDedekindDomain R] (I : (Ideal R)⁰) : ClassGroup.mk (FractionalIdeal.mk0 K I) = ClassGroup.mk0 I := by rw [ClassGroup.mk0, MonoidHom.comp_apply, ← ClassGroup.mk_canonicalEquiv K (FractionRing R), FractionalIdeal.map_canonicalEquiv_mk0] @[simp] theorem ClassGroup.equiv_mk0 [IsDedekindDomain R] (I : (Ideal R)⁰) : ClassGroup.equiv K (ClassGroup.mk0 I) = QuotientGroup.mk' (toPrincipalIdeal R K).range (FractionalIdeal.mk0 K I) := by rw [ClassGroup.mk0, MonoidHom.comp_apply, ClassGroup.equiv_mk] congr 1 simp [← Units.eq_iff] theorem ClassGroup.mk0_eq_mk0_iff_exists_fraction_ring [IsDedekindDomain R] {I J : (Ideal R)⁰} : ClassGroup.mk0 I = ClassGroup.mk0 J ↔ ∃ (x : _) (_ : x ≠ (0 : K)), spanSingleton R⁰ x * I = J := by refine (ClassGroup.equiv K).injective.eq_iff.symm.trans ?_ simp only [ClassGroup.equiv_mk0, QuotientGroup.mk'_eq_mk', mem_principal_ideals_iff, Units.ext_iff, Units.val_mul, FractionalIdeal.coe_mk0, exists_prop] constructor · rintro ⟨X, ⟨x, hX⟩, hx⟩ refine ⟨x, ?_, ?_⟩ · rintro rfl; simp [X.ne_zero.symm] at hX simpa only [hX, mul_comm] using hx · rintro ⟨x, hx, eq_J⟩ refine ⟨Units.mk0 _ (spanSingleton_ne_zero_iff.mpr hx), ⟨x, rfl⟩, ?_⟩ simpa only [mul_comm] using eq_J variable {K} theorem ClassGroup.mk0_eq_mk0_iff [IsDedekindDomain R] {I J : (Ideal R)⁰} : ClassGroup.mk0 I = ClassGroup.mk0 J ↔ ∃ (x y : R) (_hx : x ≠ 0) (_hy : y ≠ 0), Ideal.span {x} * (I : Ideal R) = Ideal.span {y} * J := by refine (ClassGroup.mk0_eq_mk0_iff_exists_fraction_ring (FractionRing R)).trans ⟨?_, ?_⟩ · rintro ⟨z, hz, h⟩ obtain ⟨x, ⟨y, hy⟩, rfl⟩ := IsLocalization.mk'_surjective R⁰ z refine ⟨x, y, ?_, mem_nonZeroDivisors_iff_ne_zero.mp hy, ?_⟩ · rintro hx; apply hz rw [hx, IsFractionRing.mk'_eq_div, map_zero, zero_div] · exact (FractionalIdeal.mk'_mul_coeIdeal_eq_coeIdeal _ hy).mp h · rintro ⟨x, y, hx, hy, h⟩ have hy' : y ∈ R⁰ := mem_nonZeroDivisors_iff_ne_zero.mpr hy refine ⟨IsLocalization.mk' _ x ⟨y, hy'⟩, ?_, ?_⟩ · contrapose! hx rwa [mk'_eq_iff_eq_mul, zero_mul, ← (algebraMap R (FractionRing R)).map_zero, (IsFractionRing.injective R (FractionRing R)).eq_iff] at hx · exact (FractionalIdeal.mk'_mul_coeIdeal_eq_coeIdeal _ hy').mpr h /-- Maps a nonzero fractional ideal to an integral representative in the class group. -/ noncomputable def ClassGroup.integralRep (I : FractionalIdeal R⁰ (FractionRing R)) : Ideal R := I.num theorem ClassGroup.integralRep_mem_nonZeroDivisors {I : FractionalIdeal R⁰ (FractionRing R)} (hI : I ≠ 0) : I.num ∈ (Ideal R)⁰ := by rwa [mem_nonZeroDivisors_iff_ne_zero, ne_eq, FractionalIdeal.num_eq_zero_iff] theorem ClassGroup.mk0_integralRep [IsDedekindDomain R] (I : (FractionalIdeal R⁰ (FractionRing R))ˣ) : ClassGroup.mk0 ⟨ClassGroup.integralRep I, ClassGroup.integralRep_mem_nonZeroDivisors I.ne_zero⟩ = ClassGroup.mk I := by rw [← ClassGroup.mk_mk0 (FractionRing R), eq_comm, ClassGroup.mk_eq_mk] have fd_ne_zero : (algebraMap R (FractionRing R)) I.1.den ≠ 0 := by exact IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors (SetLike.coe_mem _) refine ⟨Units.mk0 (algebraMap R _ I.1.den) fd_ne_zero, ?_⟩ apply Units.ext rw [mul_comm, val_mul, coe_toPrincipalIdeal, val_mk0] exact FractionalIdeal.den_mul_self_eq_num' R⁰ (FractionRing R) I theorem ClassGroup.mk0_surjective [IsDedekindDomain R] : Function.Surjective (ClassGroup.mk0 : (Ideal R)⁰ → ClassGroup R) := by rintro ⟨I⟩ refine ⟨⟨ClassGroup.integralRep I.1, ClassGroup.integralRep_mem_nonZeroDivisors I.ne_zero⟩, ?_⟩ rw [ClassGroup.mk0_integralRep, ClassGroup.Quot_mk_eq_mk] theorem ClassGroup.mk_eq_one_iff {I : (FractionalIdeal R⁰ K)ˣ} : ClassGroup.mk I = 1 ↔ (I : Submodule R K).IsPrincipal := by rw [← (ClassGroup.equiv K).injective.eq_iff] simp only [equiv_mk, canonicalEquiv_self, RingEquiv.coe_mulEquiv_refl, QuotientGroup.mk'_apply, map_one, QuotientGroup.eq_one_iff, MonoidHom.mem_range, Units.ext_iff, coe_toPrincipalIdeal, coe_mapEquiv, MulEquiv.refl_apply] refine ⟨fun ⟨x, hx⟩ => ⟨⟨x, by rw [← hx, coe_spanSingleton]⟩⟩, ?_⟩ intro hI obtain ⟨x, hx⟩ := @Submodule.IsPrincipal.principal _ _ _ _ _ _ hI have hx' : (I : FractionalIdeal R⁰ K) = spanSingleton R⁰ x := by apply Subtype.coe_injective simp only [val_eq_coe, hx, coe_spanSingleton] refine ⟨Units.mk0 x ?_, ?_⟩ · intro x_eq; apply Units.ne_zero I; simp [hx', x_eq] · simp [hx'] theorem ClassGroup.mk0_eq_one_iff [IsDedekindDomain R] {I : Ideal R} (hI : I ∈ (Ideal R)⁰) : ClassGroup.mk0 ⟨I, hI⟩ = 1 ↔ I.IsPrincipal := ClassGroup.mk_eq_one_iff.trans (coeSubmodule_isPrincipal R _) theorem ClassGroup.mk0_eq_mk0_inv_iff [IsDedekindDomain R] {I J : (Ideal R)⁰} : ClassGroup.mk0 I = (ClassGroup.mk0 J)⁻¹ ↔ ∃ x ≠ (0 : R), I * J = Ideal.span {x} := by rw [eq_inv_iff_mul_eq_one, ← map_mul, ClassGroup.mk0_eq_one_iff, Submodule.isPrincipal_iff, Submonoid.coe_mul] refine ⟨fun ⟨a, ha⟩ ↦ ⟨a, ?_, ha⟩, fun ⟨a, _, ha⟩ ↦ ⟨a, ha⟩⟩ by_contra! rw [this, Submodule.span_zero_singleton] at ha exact nonZeroDivisors.coe_ne_zero _ <| J.prop _ ha /-- The class group of principal ideal domain is finite (in fact a singleton). See `ClassGroup.fintypeOfAdmissibleOfFinite` for a finiteness proof that works for rings of integers of global fields. -/ noncomputable instance [IsPrincipalIdealRing R] : Fintype (ClassGroup R) where elems := {1} complete := by refine ClassGroup.induction (R := R) (FractionRing R) (fun I => ?_) rw [Finset.mem_singleton] exact ClassGroup.mk_eq_one_iff.mpr (I : FractionalIdeal R⁰ (FractionRing R)).isPrincipal /-- The class number of a principal ideal domain is `1`. -/ theorem card_classGroup_eq_one [IsPrincipalIdealRing R] : Fintype.card (ClassGroup R) = 1 := by rw [Fintype.card_eq_one_iff] use 1 refine ClassGroup.induction (R := R) (FractionRing R) (fun I => ?_) exact ClassGroup.mk_eq_one_iff.mpr (I : FractionalIdeal R⁰ (FractionRing R)).isPrincipal /-- The class number is `1` iff the ring of integers is a principal ideal domain. -/ theorem card_classGroup_eq_one_iff [IsDedekindDomain R] [Fintype (ClassGroup R)] :
Fintype.card (ClassGroup R) = 1 ↔ IsPrincipalIdealRing R := by constructor; swap; · intros; convert card_classGroup_eq_one (R := R) rw [Fintype.card_eq_one_iff] rintro ⟨I, hI⟩ have eq_one : ∀ J : ClassGroup R, J = 1 := fun J => (hI J).trans (hI 1).symm refine ⟨fun I => ?_⟩ by_cases hI : I = ⊥ · rw [hI]; exact bot_isPrincipal · exact (ClassGroup.mk0_eq_one_iff (mem_nonZeroDivisors_iff_ne_zero.mpr hI)).mp (eq_one _)
Mathlib/RingTheory/ClassGroup.lean
369
377
/- 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, Joachim Breitner -/ import Mathlib.Algebra.Group.Action.End import Mathlib.Algebra.Group.Action.Pointwise.Set.Basic import Mathlib.Algebra.Group.Submonoid.Membership import Mathlib.GroupTheory.Congruence.Basic import Mathlib.GroupTheory.FreeGroup.IsFreeGroup import Mathlib.SetTheory.Cardinal.Basic /-! # The coproduct (a.k.a. the free product) of groups or monoids Given an `ι`-indexed family `M` of monoids, we define their coproduct (a.k.a. free product) `Monoid.CoprodI M`. As usual, we use the suffix `I` for an indexed (co)product, leaving `Coprod` for the coproduct of two monoids. When `ι` and all `M i` have decidable equality, the free product bijects with the type `Monoid.CoprodI.Word M` of reduced words. This bijection is constructed by defining an action of `Monoid.CoprodI M` on `Monoid.CoprodI.Word M`. When `M i` are all groups, `Monoid.CoprodI M` is also a group (and the coproduct in the category of groups). ## Main definitions - `Monoid.CoprodI M`: the free product, defined as a quotient of a free monoid. - `Monoid.CoprodI.of {i} : M i →* Monoid.CoprodI M`. - `Monoid.CoprodI.lift : (∀ {i}, M i →* N) ≃ (Monoid.CoprodI M →* N)`: the universal property. - `Monoid.CoprodI.Word M`: the type of reduced words. - `Monoid.CoprodI.Word.equiv M : Monoid.CoprodI M ≃ word M`. - `Monoid.CoprodI.NeWord M i j`: an inductive description of non-empty words with first letter from `M i` and last letter from `M j`, together with an API (`singleton`, `append`, `head`, `tail`, `to_word`, `Prod`, `inv`). Used in the proof of the Ping-Pong-lemma. - `Monoid.CoprodI.lift_injective_of_ping_pong`: The Ping-Pong-lemma, proving injectivity of the `lift`. See the documentation of that theorem for more information. ## Remarks There are many answers to the question "what is the coproduct of a family `M` of monoids?", and they are all equivalent but not obviously equivalent. We provide two answers. The first, almost tautological answer is given by `Monoid.CoprodI M`, which is a quotient of the type of words in the alphabet `Σ i, M i`. It's straightforward to define and easy to prove its universal property. But this answer is not completely satisfactory, because it's difficult to tell when two elements `x y : Monoid.CoprodI M` are distinct since `Monoid.CoprodI M` is defined as a quotient. The second, maximally efficient answer is given by `Monoid.CoprodI.Word M`. An element of `Monoid.CoprodI.Word M` is a word in the alphabet `Σ i, M i`, where the letter `⟨i, 1⟩` doesn't occur and no adjacent letters share an index `i`. Since we only work with reduced words, there is no need for quotienting, and it is easy to tell when two elements are distinct. However it's not obvious that this is even a monoid! We prove that every element of `Monoid.CoprodI M` can be represented by a unique reduced word, i.e. `Monoid.CoprodI M` and `Monoid.CoprodI.Word M` are equivalent types. This means that `Monoid.CoprodI.Word M` can be given a monoid structure, and it lets us tell when two elements of `Monoid.CoprodI M` are distinct. There is also a completely tautological, maximally inefficient answer given by `MonCat.Colimits.ColimitType`. Whereas `Monoid.CoprodI M` at least ensures that (any instance of) associativity holds by reflexivity, in this answer associativity holds because of quotienting. Yet another answer, which is constructively more satisfying, could be obtained by showing that `Monoid.CoprodI.Rel` is confluent. ## References [van der Waerden, *Free products of groups*][MR25465] -/ open Set variable {ι : Type*} (M : ι → Type*) [∀ i, Monoid (M i)] /-- A relation on the free monoid on alphabet `Σ i, M i`, relating `⟨i, 1⟩` with `1` and `⟨i, x⟩ * ⟨i, y⟩` with `⟨i, x * y⟩`. -/ inductive Monoid.CoprodI.Rel : FreeMonoid (Σ i, M i) → FreeMonoid (Σ i, M i) → Prop | of_one (i : ι) : Monoid.CoprodI.Rel (FreeMonoid.of ⟨i, 1⟩) 1 | of_mul {i : ι} (x y : M i) : Monoid.CoprodI.Rel (FreeMonoid.of ⟨i, x⟩ * FreeMonoid.of ⟨i, y⟩) (FreeMonoid.of ⟨i, x * y⟩) /-- The free product (categorical coproduct) of an indexed family of monoids. -/ def Monoid.CoprodI : Type _ := (conGen (Monoid.CoprodI.Rel M)).Quotient -- The `Monoid` instance should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 instance : Monoid (Monoid.CoprodI M) := by delta Monoid.CoprodI; infer_instance instance : Inhabited (Monoid.CoprodI M) := ⟨1⟩ namespace Monoid.CoprodI /-- The type of reduced words. A reduced word cannot contain a letter `1`, and no two adjacent letters can come from the same summand. -/ @[ext] structure Word where /-- A `Word` is a `List (Σ i, M i)`, such that `1` is not in the list, and no two adjacent letters are from the same summand -/ toList : List (Σi, M i) /-- A reduced word does not contain `1` -/ ne_one : ∀ l ∈ toList, Sigma.snd l ≠ 1 /-- Adjacent letters are not from the same summand. -/ chain_ne : toList.Chain' fun l l' => Sigma.fst l ≠ Sigma.fst l' variable {M} /-- The inclusion of a summand into the free product. -/ def of {i : ι} : M i →* CoprodI M where toFun x := Con.mk' _ (FreeMonoid.of <| Sigma.mk i x) map_one' := (Con.eq _).mpr (ConGen.Rel.of _ _ (CoprodI.Rel.of_one i)) map_mul' x y := Eq.symm <| (Con.eq _).mpr (ConGen.Rel.of _ _ (CoprodI.Rel.of_mul x y)) theorem of_apply {i} (m : M i) : of m = Con.mk' _ (FreeMonoid.of <| Sigma.mk i m) := rfl variable {N : Type*} [Monoid N] /-- See note [partially-applied ext lemmas]. -/ -- Porting note: higher `ext` priority @[ext 1100] theorem ext_hom (f g : CoprodI M →* N) (h : ∀ i, f.comp (of : M i →* _) = g.comp of) : f = g := (MonoidHom.cancel_right Con.mk'_surjective).mp <| FreeMonoid.hom_eq fun ⟨i, x⟩ => by rw [MonoidHom.comp_apply, MonoidHom.comp_apply, ← of_apply] unfold CoprodI rw [← MonoidHom.comp_apply, ← MonoidHom.comp_apply, h] /-- A map out of the free product corresponds to a family of maps out of the summands. This is the universal property of the free product, characterizing it as a categorical coproduct. -/ @[simps symm_apply] def lift : (∀ i, M i →* N) ≃ (CoprodI M →* N) where toFun fi := Con.lift _ (FreeMonoid.lift fun p : Σi, M i => fi p.fst p.snd) <| Con.conGen_le <| by simp_rw [Con.ker_rel] rintro _ _ (i | ⟨x, y⟩) <;> simp invFun f _ := f.comp of left_inv := by intro fi ext i x rfl right_inv := by intro f ext i x rfl @[simp] theorem lift_comp_of {N} [Monoid N] (fi : ∀ i, M i →* N) i : (lift fi).comp of = fi i := congr_fun (lift.symm_apply_apply fi) i @[simp] theorem lift_of {N} [Monoid N] (fi : ∀ i, M i →* N) {i} (m : M i) : lift fi (of m) = fi i m := DFunLike.congr_fun (lift_comp_of ..) m @[simp] theorem lift_comp_of' {N} [Monoid N] (f : CoprodI M →* N) : lift (fun i ↦ f.comp (of (i := i))) = f := lift.apply_symm_apply f @[simp] theorem lift_of' : lift (fun i ↦ (of : M i →* CoprodI M)) = .id (CoprodI M) := lift_comp_of' (.id _) theorem of_leftInverse [DecidableEq ι] (i : ι) : Function.LeftInverse (lift <| Pi.mulSingle i (MonoidHom.id (M i))) of := fun x => by simp only [lift_of, Pi.mulSingle_eq_same, MonoidHom.id_apply] theorem of_injective (i : ι) : Function.Injective (of : M i →* _) := by classical exact (of_leftInverse i).injective theorem mrange_eq_iSup {N} [Monoid N] (f : ∀ i, M i →* N) : MonoidHom.mrange (lift f) = ⨆ i, MonoidHom.mrange (f i) := by rw [lift, Equiv.coe_fn_mk, Con.lift_range, FreeMonoid.mrange_lift, range_sigma_eq_iUnion_range, Submonoid.closure_iUnion] simp only [MonoidHom.mclosure_range] theorem lift_mrange_le {N} [Monoid N] (f : ∀ i, M i →* N) {s : Submonoid N} : MonoidHom.mrange (lift f) ≤ s ↔ ∀ i, MonoidHom.mrange (f i) ≤ s := by simp [mrange_eq_iSup] @[simp] theorem iSup_mrange_of : ⨆ i, MonoidHom.mrange (of : M i →* CoprodI M) = ⊤ := by simp [← mrange_eq_iSup] @[simp] theorem mclosure_iUnion_range_of : Submonoid.closure (⋃ i, Set.range (of : M i →* CoprodI M)) = ⊤ := by simp [Submonoid.closure_iUnion] @[elab_as_elim] theorem induction_left {motive : CoprodI M → Prop} (m : CoprodI M) (one : motive 1) (mul : ∀ {i} (m : M i) x, motive x → motive (of m * x)) : motive m := by induction m using Submonoid.induction_of_closure_eq_top_left mclosure_iUnion_range_of with | one => exact one | mul x hx y ihy => obtain ⟨i, m, rfl⟩ : ∃ (i : ι) (m : M i), of m = x := by simpa using hx exact mul m y ihy @[elab_as_elim] theorem induction_on {motive : CoprodI M → Prop} (m : CoprodI M) (one : motive 1) (of : ∀ (i) (m : M i), motive (of m)) (mul : ∀ x y, motive x → motive y → motive (x * y)) : motive m := by induction m using CoprodI.induction_left with | one => exact one | mul m x hx => exact mul _ _ (of _ _) hx section Group variable (G : ι → Type*) [∀ i, Group (G i)] instance : Inv (CoprodI G) where inv := MulOpposite.unop ∘ lift fun i => (of : G i →* _).op.comp (MulEquiv.inv' (G i)).toMonoidHom theorem inv_def (x : CoprodI G) : x⁻¹ = MulOpposite.unop (lift (fun i => (of : G i →* _).op.comp (MulEquiv.inv' (G i)).toMonoidHom) x) := rfl instance : Group (CoprodI G) := { inv_mul_cancel := by intro m rw [inv_def] induction m using CoprodI.induction_on with | one => rw [MonoidHom.map_one, MulOpposite.unop_one, one_mul] | of m ih => change of _⁻¹ * of _ = 1 rw [← of.map_mul, inv_mul_cancel, of.map_one] | mul x y ihx ihy => rw [MonoidHom.map_mul, MulOpposite.unop_mul, mul_assoc, ← mul_assoc _ x y, ihx, one_mul, ihy] } theorem lift_range_le {N} [Group N] (f : ∀ i, G i →* N) {s : Subgroup N} (h : ∀ i, (f i).range ≤ s) : (lift f).range ≤ s := by rintro _ ⟨x, rfl⟩ induction x using CoprodI.induction_on with | one => exact s.one_mem | of i x => simp only [lift_of, SetLike.mem_coe] exact h i (Set.mem_range_self x) | mul x y hx hy => simp only [map_mul, SetLike.mem_coe] exact s.mul_mem hx hy theorem range_eq_iSup {N} [Group N] (f : ∀ i, G i →* N) : (lift f).range = ⨆ i, (f i).range := by apply le_antisymm (lift_range_le _ f fun i => le_iSup (fun i => MonoidHom.range (f i)) i) apply iSup_le _ rintro i _ ⟨x, rfl⟩ exact ⟨of x, by simp only [lift_of]⟩ end Group namespace Word /-- The empty reduced word. -/ @[simps] def empty : Word M where toList := [] ne_one := by simp chain_ne := List.chain'_nil instance : Inhabited (Word M) := ⟨empty⟩ /-- A reduced word determines an element of the free product, given by multiplication. -/ def prod (w : Word M) : CoprodI M := List.prod (w.toList.map fun l => of l.snd) @[simp] theorem prod_empty : prod (empty : Word M) = 1 := rfl /-- `fstIdx w` is `some i` if the first letter of `w` is `⟨i, m⟩` with `m : M i`. If `w` is empty then it's `none`. -/ def fstIdx (w : Word M) : Option ι := w.toList.head?.map Sigma.fst theorem fstIdx_ne_iff {w : Word M} {i} : fstIdx w ≠ some i ↔ ∀ l ∈ w.toList.head?, i ≠ Sigma.fst l := not_iff_not.mp <| by simp [fstIdx] variable (M) /-- Given an index `i : ι`, `Pair M i` is the type of pairs `(head, tail)` where `head : M i` and `tail : Word M`, subject to the constraint that first letter of `tail` can't be `⟨i, m⟩`. By prepending `head` to `tail`, one obtains a new word. We'll show that any word can be uniquely obtained in this way. -/ @[ext] structure Pair (i : ι) where /-- An element of `M i`, the first letter of the word. -/ head : M i /-- The remaining letters of the word, excluding the first letter -/ tail : Word M /-- The index first letter of tail of a `Pair M i` is not equal to `i` -/ fstIdx_ne : fstIdx tail ≠ some i instance (i : ι) : Inhabited (Pair M i) := ⟨⟨1, empty, by tauto⟩⟩ variable {M} /-- Construct a new `Word` without any reduction. The underlying list of `cons m w _ _` is `⟨_, m⟩::w` -/ @[simps] def cons {i} (m : M i) (w : Word M) (hmw : w.fstIdx ≠ some i) (h1 : m ≠ 1) : Word M := { toList := ⟨i, m⟩ :: w.toList, ne_one := by simp only [List.mem_cons] rintro l (rfl | hl) · exact h1 · exact w.ne_one l hl chain_ne := w.chain_ne.cons' (fstIdx_ne_iff.mp hmw) } @[simp] theorem fstIdx_cons {i} (m : M i) (w : Word M) (hmw : w.fstIdx ≠ some i) (h1 : m ≠ 1) : fstIdx (cons m w hmw h1) = some i := by simp [cons, fstIdx] @[simp] theorem prod_cons (i) (m : M i) (w : Word M) (h1 : m ≠ 1) (h2 : w.fstIdx ≠ some i) : prod (cons m w h2 h1) = of m * prod w := by simp [cons, prod, List.map_cons, List.prod_cons] section variable [∀ i, DecidableEq (M i)] /-- Given a pair `(head, tail)`, we can form a word by prepending `head` to `tail`, except if `head` is `1 : M i` then we have to just return `Word` since we need the result to be reduced. -/ def rcons {i} (p : Pair M i) : Word M := if h : p.head = 1 then p.tail else cons p.head p.tail p.fstIdx_ne h @[simp] theorem prod_rcons {i} (p : Pair M i) : prod (rcons p) = of p.head * prod p.tail := if hm : p.head = 1 then by rw [rcons, dif_pos hm, hm, MonoidHom.map_one, one_mul] else by rw [rcons, dif_neg hm, cons, prod, List.map_cons, List.prod_cons, prod] theorem rcons_inj {i} : Function.Injective (rcons : Pair M i → Word M) := by rintro ⟨m, w, h⟩ ⟨m', w', h'⟩ he by_cases hm : m = 1 <;> by_cases hm' : m' = 1 · simp only [rcons, dif_pos hm, dif_pos hm'] at he aesop · exfalso simp only [rcons, dif_pos hm, dif_neg hm'] at he rw [he] at h exact h rfl · exfalso simp only [rcons, dif_pos hm', dif_neg hm] at he rw [← he] at h' exact h' rfl · have : m = m' ∧ w.toList = w'.toList := by simpa [cons, rcons, dif_neg hm, dif_neg hm', eq_self_iff_true, Subtype.mk_eq_mk, heq_iff_eq, ← Subtype.ext_iff_val] using he rcases this with ⟨rfl, h⟩ congr exact Word.ext h theorem mem_rcons_iff {i j : ι} (p : Pair M i) (m : M j) : ⟨_, m⟩ ∈ (rcons p).toList ↔ ⟨_, m⟩ ∈ p.tail.toList ∨ m ≠ 1 ∧ (∃ h : i = j, m = h ▸ p.head) := by simp only [rcons, cons, ne_eq] by_cases hij : i = j · subst i by_cases hm : m = p.head · subst m split_ifs <;> simp_all · split_ifs <;> simp_all · split_ifs <;> simp_all [Ne.symm hij] end /-- Induct on a word by adding letters one at a time without reduction, effectively inducting on the underlying `List`. -/ @[elab_as_elim] def consRecOn {motive : Word M → Sort*} (w : Word M) (empty : motive empty) (cons : ∀ (i) (m : M i) (w) h1 h2, motive w → motive (cons m w h1 h2)) : motive w := by rcases w with ⟨w, h1, h2⟩ induction w with | nil => exact empty | cons m w ih => refine cons m.1 m.2 ⟨w, fun _ hl => h1 _ (List.mem_cons_of_mem _ hl), h2.tail⟩ ?_ ?_ (ih _ _) · rw [List.chain'_cons'] at h2 simp only [fstIdx, ne_eq, Option.map_eq_some_iff, Sigma.exists, exists_and_right, exists_eq_right, not_exists] intro m' hm' exact h2.1 _ hm' rfl · exact h1 _ List.mem_cons_self @[simp] theorem consRecOn_empty {motive : Word M → Sort*} (h_empty : motive empty) (h_cons : ∀ (i) (m : M i) (w) h1 h2, motive w → motive (cons m w h1 h2)) : consRecOn empty h_empty h_cons = h_empty := rfl @[simp] theorem consRecOn_cons {motive : Word M → Sort*} (i) (m : M i) (w : Word M) h1 h2 (h_empty : motive empty) (h_cons : ∀ (i) (m : M i) (w) h1 h2, motive w → motive (cons m w h1 h2)) : consRecOn (cons m w h1 h2) h_empty h_cons = h_cons i m w h1 h2 (consRecOn w h_empty h_cons) := rfl variable [DecidableEq ι] [∀ i, DecidableEq (M i)] -- This definition is computable but not very nice to look at. Thankfully we don't have to inspect -- it, since `rcons` is known to be injective. /-- Given `i : ι`, any reduced word can be decomposed into a pair `p` such that `w = rcons p`. -/ private def equivPairAux (i) (w : Word M) : { p : Pair M i // rcons p = w } := consRecOn w ⟨⟨1, .empty, by simp [fstIdx, empty]⟩, by simp [rcons]⟩ <| fun j m w h1 h2 _ => if ij : i = j then { val := { head := ij ▸ m tail := w fstIdx_ne := ij ▸ h1 } property := by subst ij; simp [rcons, h2] } else ⟨⟨1, cons m w h1 h2, by simp [cons, fstIdx, Ne.symm ij]⟩, by simp [rcons]⟩ /-- The equivalence between words and pairs. Given a word, it decomposes it as a pair by removing the first letter if it comes from `M i`. Given a pair, it prepends the head to the tail. -/ def equivPair (i) : Word M ≃ Pair M i where toFun w := (equivPairAux i w).val invFun := rcons left_inv w := (equivPairAux i w).property right_inv _ := rcons_inj (equivPairAux i _).property theorem equivPair_symm (i) (p : Pair M i) : (equivPair i).symm p = rcons p := rfl theorem equivPair_eq_of_fstIdx_ne {i} {w : Word M} (h : fstIdx w ≠ some i) : equivPair i w = ⟨1, w, h⟩ := (equivPair i).apply_eq_iff_eq_symm_apply.mpr <| Eq.symm (dif_pos rfl) theorem mem_equivPair_tail_iff {i j : ι} {w : Word M} (m : M i) : (⟨i, m⟩ ∈ (equivPair j w).tail.toList) ↔ ⟨i, m⟩ ∈ w.toList.tail ∨ i ≠ j ∧ ∃ h : w.toList ≠ [], w.toList.head h = ⟨i, m⟩ := by simp only [equivPair, equivPairAux, ne_eq, Equiv.coe_fn_mk] induction w using consRecOn with | empty => simp | cons k g tail h1 h2 ih => simp only [consRecOn_cons] split_ifs with h · subst k by_cases hij : j = i <;> simp_all · by_cases hik : i = k · subst i; simp_all [@eq_comm _ m g, @eq_comm _ k j, or_comm] · simp [hik, Ne.symm hik] theorem mem_of_mem_equivPair_tail {i j : ι} {w : Word M} (m : M i) : (⟨i, m⟩ ∈ (equivPair j w).tail.toList) → ⟨i, m⟩ ∈ w.toList := by rw [mem_equivPair_tail_iff] rintro (h | h) · exact List.mem_of_mem_tail h · revert h; cases w.toList <;> simp +contextual theorem equivPair_head {i : ι} {w : Word M} : (equivPair i w).head = if h : ∃ (h : w.toList ≠ []), (w.toList.head h).1 = i then h.snd ▸ (w.toList.head h.1).2 else 1 := by simp only [equivPair, equivPairAux] induction w using consRecOn with | empty => simp | cons head => by_cases hi : i = head · subst hi; simp · simp [hi, Ne.symm hi] instance summandAction (i) : MulAction (M i) (Word M) where smul m w := rcons { equivPair i w with head := m * (equivPair i w).head } one_smul w := by apply (equivPair i).symm_apply_eq.mpr simp [equivPair] mul_smul m m' w := by dsimp [instHSMul] simp [mul_assoc, ← equivPair_symm, Equiv.apply_symm_apply] instance : MulAction (CoprodI M) (Word M) := MulAction.ofEndHom (lift fun _ => MulAction.toEndHom) theorem smul_def {i} (m : M i) (w : Word M) : m • w = rcons { equivPair i w with head := m * (equivPair i w).head } := rfl theorem of_smul_def (i) (w : Word M) (m : M i) : of m • w = rcons { equivPair i w with head := m * (equivPair i w).head } := rfl theorem equivPair_smul_same {i} (m : M i) (w : Word M) : equivPair i (of m • w) = ⟨m * (equivPair i w).head, (equivPair i w).tail, (equivPair i w).fstIdx_ne⟩ := by rw [of_smul_def, ← equivPair_symm] simp @[simp] theorem equivPair_tail {i} (p : Pair M i) : equivPair i p.tail = ⟨1, p.tail, p.fstIdx_ne⟩ := equivPair_eq_of_fstIdx_ne _ theorem smul_eq_of_smul {i} (m : M i) (w : Word M) : m • w = of m • w := rfl theorem mem_smul_iff {i j : ι} {m₁ : M i} {m₂ : M j} {w : Word M} : ⟨_, m₁⟩ ∈ (of m₂ • w).toList ↔ (¬i = j ∧ ⟨i, m₁⟩ ∈ w.toList) ∨ (m₁ ≠ 1 ∧ ∃ (hij : i = j),(⟨i, m₁⟩ ∈ w.toList.tail) ∨ (∃ m', ⟨j, m'⟩ ∈ w.toList.head? ∧ m₁ = hij ▸ (m₂ * m')) ∨ (w.fstIdx ≠ some j ∧ m₁ = hij ▸ m₂)) := by rw [of_smul_def, mem_rcons_iff, mem_equivPair_tail_iff, equivPair_head, or_assoc] by_cases hij : i = j · subst i simp only [not_true, ne_eq, false_and, exists_prop, true_and, false_or] by_cases hw : ⟨j, m₁⟩ ∈ w.toList.tail · simp [hw, show m₁ ≠ 1 from w.ne_one _ (List.mem_of_mem_tail hw)] · simp only [hw, false_or, Option.mem_def, ne_eq, and_congr_right_iff] intro hm1 split_ifs with h · rcases h with ⟨hnil, rfl⟩ simp only [List.head?_eq_head hnil, Option.some.injEq, ne_eq] constructor · rintro rfl exact Or.inl ⟨_, rfl, rfl⟩ · rintro (⟨_, h, rfl⟩ | hm') · simp only [Sigma.ext_iff, heq_eq_eq, true_and] at h subst h rfl · simp only [fstIdx, Option.map_eq_some_iff, Sigma.exists, exists_and_right, exists_eq_right, not_exists, ne_eq] at hm' exact (hm'.1 (w.toList.head hnil).2 (by rw [List.head?_eq_head])).elim · revert h rw [fstIdx] cases w.toList · simp · simp +contextual [Sigma.ext_iff] · rcases w with ⟨_ | _, _, _⟩ <;> simp [or_comm, hij, Ne.symm hij]; rw [eq_comm] theorem mem_smul_iff_of_ne {i j : ι} (hij : i ≠ j) {m₁ : M i} {m₂ : M j} {w : Word M} : ⟨_, m₁⟩ ∈ (of m₂ • w).toList ↔ ⟨i, m₁⟩ ∈ w.toList := by simp [mem_smul_iff, *] theorem cons_eq_smul {i} {m : M i} {ls h1 h2} : cons m ls h1 h2 = of m • ls := by rw [of_smul_def, equivPair_eq_of_fstIdx_ne _] · simp [cons, rcons, h2] · exact h1 theorem rcons_eq_smul {i} (p : Pair M i) : rcons p = of p.head • p.tail := by simp [of_smul_def] @[simp] theorem equivPair_head_smul_equivPair_tail {i : ι} (w : Word M) : of (equivPair i w).head • (equivPair i w).tail = w := by rw [← rcons_eq_smul, ← equivPair_symm, Equiv.symm_apply_apply] theorem equivPair_tail_eq_inv_smul {G : ι → Type*} [∀ i, Group (G i)] [∀ i, DecidableEq (G i)] {i} (w : Word G) : (equivPair i w).tail = (of (equivPair i w).head)⁻¹ • w := Eq.symm <| inv_smul_eq_iff.2 (equivPair_head_smul_equivPair_tail w).symm @[elab_as_elim] theorem smul_induction {motive : Word M → Prop} (empty : motive empty) (smul : ∀ (i) (m : M i) (w), motive w → motive (of m • w)) (w : Word M) : motive w := by induction w using consRecOn with | empty => exact empty | cons _ _ _ _ _ ih => rw [cons_eq_smul] exact smul _ _ _ ih @[simp] theorem prod_smul (m) : ∀ w : Word M, prod (m • w) = m * prod w := by induction m using CoprodI.induction_on with | one => intro rw [one_smul, one_mul] | of _ => intros rw [of_smul_def, prod_rcons, of.map_mul, mul_assoc, ← prod_rcons, ← equivPair_symm, Equiv.symm_apply_apply] | mul x y hx hy => intro w rw [mul_smul, hx, hy, mul_assoc] /-- Each element of the free product corresponds to a unique reduced word. -/ def equiv : CoprodI M ≃ Word M where toFun m := m • empty
invFun w := prod w left_inv m := by dsimp only; rw [prod_smul, prod_empty, mul_one] right_inv := by
Mathlib/GroupTheory/CoprodI.lean
600
602
/- Copyright (c) 2023 Yaël Dillies, Christopher Hoskin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Christopher Hoskin -/ import Mathlib.Data.Finset.Lattice.Prod import Mathlib.Data.Finset.Powerset import Mathlib.Data.Set.Finite.Basic import Mathlib.Order.Closure import Mathlib.Order.ConditionallyCompleteLattice.Finset /-! # Sets closed under join/meet This file defines predicates for sets closed under `⊔` and shows that each set in a join-semilattice generates a join-closed set and that a semilattice where every directed set has a least upper bound is automatically complete. All dually for `⊓`. ## Main declarations * `SupClosed`: Predicate for a set to be closed under join (`a ∈ s` and `b ∈ s` imply `a ⊔ b ∈ s`). * `InfClosed`: Predicate for a set to be closed under meet (`a ∈ s` and `b ∈ s` imply `a ⊓ b ∈ s`). * `IsSublattice`: Predicate for a set to be closed under meet and join. * `supClosure`: Sup-closure. Smallest sup-closed set containing a given set. * `infClosure`: Inf-closure. Smallest inf-closed set containing a given set. * `latticeClosure`: Smallest sublattice containing a given set. * `SemilatticeSup.toCompleteSemilatticeSup`: A join-semilattice where every sup-closed set has a least upper bound is automatically complete. * `SemilatticeInf.toCompleteSemilatticeInf`: A meet-semilattice where every inf-closed set has a greatest lower bound is automatically complete. -/ variable {ι : Sort*} {F α β : Type*} section SemilatticeSup variable [SemilatticeSup α] [SemilatticeSup β] section Set variable {ι : Sort*} {S : Set (Set α)} {f : ι → Set α} {s t : Set α} {a : α} open Set /-- A set `s` is *sup-closed* if `a ⊔ b ∈ s` for all `a ∈ s`, `b ∈ s`. -/ def SupClosed (s : Set α) : Prop := ∀ ⦃a⦄, a ∈ s → ∀ ⦃b⦄, b ∈ s → a ⊔ b ∈ s @[simp] lemma supClosed_empty : SupClosed (∅ : Set α) := by simp [SupClosed] @[simp] lemma supClosed_singleton : SupClosed ({a} : Set α) := by simp [SupClosed] @[simp] lemma supClosed_univ : SupClosed (univ : Set α) := by simp [SupClosed] lemma SupClosed.inter (hs : SupClosed s) (ht : SupClosed t) : SupClosed (s ∩ t) := fun _a ha _b hb ↦ ⟨hs ha.1 hb.1, ht ha.2 hb.2⟩ lemma supClosed_sInter (hS : ∀ s ∈ S, SupClosed s) : SupClosed (⋂₀ S) := fun _a ha _b hb _s hs ↦ hS _ hs (ha _ hs) (hb _ hs) lemma supClosed_iInter (hf : ∀ i, SupClosed (f i)) : SupClosed (⋂ i, f i) := supClosed_sInter <| forall_mem_range.2 hf lemma SupClosed.directedOn (hs : SupClosed s) : DirectedOn (· ≤ ·) s := fun _a ha _b hb ↦ ⟨_, hs ha hb, le_sup_left, le_sup_right⟩ lemma IsUpperSet.supClosed (hs : IsUpperSet s) : SupClosed s := fun _a _ _b ↦ hs le_sup_right lemma SupClosed.preimage [FunLike F β α] [SupHomClass F β α] (hs : SupClosed s) (f : F) : SupClosed (f ⁻¹' s) := fun a ha b hb ↦ by simpa [map_sup] using hs ha hb lemma SupClosed.image [FunLike F α β] [SupHomClass F α β] (hs : SupClosed s) (f : F) : SupClosed (f '' s) := by rintro _ ⟨a, ha, rfl⟩ _ ⟨b, hb, rfl⟩ rw [← map_sup] exact Set.mem_image_of_mem _ <| hs ha hb lemma supClosed_range [FunLike F α β] [SupHomClass F α β] (f : F) : SupClosed (Set.range f) := by simpa using supClosed_univ.image f lemma SupClosed.prod {t : Set β} (hs : SupClosed s) (ht : SupClosed t) : SupClosed (s ×ˢ t) := fun _a ha _b hb ↦ ⟨hs ha.1 hb.1, ht ha.2 hb.2⟩ lemma supClosed_pi {ι : Type*} {α : ι → Type*} [∀ i, SemilatticeSup (α i)] {s : Set ι} {t : ∀ i, Set (α i)} (ht : ∀ i ∈ s, SupClosed (t i)) : SupClosed (s.pi t) := fun _a ha _b hb _i hi ↦ ht _ hi (ha _ hi) (hb _ hi) lemma SupClosed.insert_upperBounds {s : Set α} {a : α} (hs : SupClosed s) (ha : a ∈ upperBounds s) : SupClosed (insert a s) := by rw [SupClosed] aesop lemma SupClosed.insert_lowerBounds {s : Set α} {a : α} (h : SupClosed s) (ha : a ∈ lowerBounds s) : SupClosed (insert a s) := by rw [SupClosed] have ha' : ∀ b ∈ s, a ≤ b := fun _ a ↦ ha a aesop end Set section Finset variable {ι : Type*} {f : ι → α} {s : Set α} {t : Finset ι} {a : α} open Finset lemma SupClosed.finsetSup'_mem (hs : SupClosed s) (ht : t.Nonempty) : (∀ i ∈ t, f i ∈ s) → t.sup' ht f ∈ s := sup'_induction _ _ hs lemma SupClosed.finsetSup_mem [OrderBot α] (hs : SupClosed s) (ht : t.Nonempty) : (∀ i ∈ t, f i ∈ s) → t.sup f ∈ s := sup'_eq_sup ht f ▸ hs.finsetSup'_mem ht end Finset end SemilatticeSup section SemilatticeInf variable [SemilatticeInf α] [SemilatticeInf β] section Set variable {ι : Sort*} {S : Set (Set α)} {f : ι → Set α} {s t : Set α} {a : α} open Set /-- A set `s` is *inf-closed* if `a ⊓ b ∈ s` for all `a ∈ s`, `b ∈ s`. -/ def InfClosed (s : Set α) : Prop := ∀ ⦃a⦄, a ∈ s → ∀ ⦃b⦄, b ∈ s → a ⊓ b ∈ s @[simp] lemma infClosed_empty : InfClosed (∅ : Set α) := by simp [InfClosed] @[simp] lemma infClosed_singleton : InfClosed ({a} : Set α) := by simp [InfClosed] @[simp] lemma infClosed_univ : InfClosed (univ : Set α) := by simp [InfClosed] lemma InfClosed.inter (hs : InfClosed s) (ht : InfClosed t) : InfClosed (s ∩ t) := fun _a ha _b hb ↦ ⟨hs ha.1 hb.1, ht ha.2 hb.2⟩ lemma infClosed_sInter (hS : ∀ s ∈ S, InfClosed s) : InfClosed (⋂₀ S) := fun _a ha _b hb _s hs ↦ hS _ hs (ha _ hs) (hb _ hs) lemma infClosed_iInter (hf : ∀ i, InfClosed (f i)) : InfClosed (⋂ i, f i) := infClosed_sInter <| forall_mem_range.2 hf lemma InfClosed.codirectedOn (hs : InfClosed s) : DirectedOn (· ≥ ·) s := fun _a ha _b hb ↦ ⟨_, hs ha hb, inf_le_left, inf_le_right⟩ lemma IsLowerSet.infClosed (hs : IsLowerSet s) : InfClosed s := fun _a _ _b ↦ hs inf_le_right lemma InfClosed.preimage [FunLike F β α] [InfHomClass F β α] (hs : InfClosed s) (f : F) : InfClosed (f ⁻¹' s) := fun a ha b hb ↦ by simpa [map_inf] using hs ha hb lemma InfClosed.image [FunLike F α β] [InfHomClass F α β] (hs : InfClosed s) (f : F) : InfClosed (f '' s) := by rintro _ ⟨a, ha, rfl⟩ _ ⟨b, hb, rfl⟩ rw [← map_inf] exact Set.mem_image_of_mem _ <| hs ha hb lemma infClosed_range [FunLike F α β] [InfHomClass F α β] (f : F) : InfClosed (Set.range f) := by simpa using infClosed_univ.image f lemma InfClosed.prod {t : Set β} (hs : InfClosed s) (ht : InfClosed t) : InfClosed (s ×ˢ t) := fun _a ha _b hb ↦ ⟨hs ha.1 hb.1, ht ha.2 hb.2⟩ lemma infClosed_pi {ι : Type*} {α : ι → Type*} [∀ i, SemilatticeInf (α i)] {s : Set ι} {t : ∀ i, Set (α i)} (ht : ∀ i ∈ s, InfClosed (t i)) : InfClosed (s.pi t) := fun _a ha _b hb _i hi ↦ ht _ hi (ha _ hi) (hb _ hi) lemma InfClosed.insert_upperBounds {s : Set α} {a : α} (hs : InfClosed s) (ha : a ∈ upperBounds s) : InfClosed (insert a s) := by rw [InfClosed] have ha' : ∀ b ∈ s, b ≤ a := fun _ a ↦ ha a aesop lemma InfClosed.insert_lowerBounds {s : Set α} {a : α} (h : InfClosed s) (ha : a ∈ lowerBounds s) : InfClosed (insert a s) := by rw [InfClosed] aesop end Set section Finset variable {ι : Type*} {f : ι → α} {s : Set α} {t : Finset ι} {a : α} open Finset lemma InfClosed.finsetInf'_mem (hs : InfClosed s) (ht : t.Nonempty) : (∀ i ∈ t, f i ∈ s) → t.inf' ht f ∈ s := inf'_induction _ _ hs lemma InfClosed.finsetInf_mem [OrderTop α] (hs : InfClosed s) (ht : t.Nonempty) : (∀ i ∈ t, f i ∈ s) → t.inf f ∈ s := inf'_eq_inf ht f ▸ hs.finsetInf'_mem ht end Finset end SemilatticeInf open Finset OrderDual section Lattice variable {ι : Sort*} [Lattice α] [Lattice β] {S : Set (Set α)} {f : ι → Set α} {s t : Set α} {a : α} open Set /-- A set `s` is a *sublattice* if `a ⊔ b ∈ s` and `a ⊓ b ∈ s` for all `a ∈ s`, `b ∈ s`. Note: This is not the preferred way to declare a sublattice. One should instead use `Sublattice`. TODO: Define `Sublattice`. -/ structure IsSublattice (s : Set α) : Prop where supClosed : SupClosed s infClosed : InfClosed s @[simp] lemma isSublattice_empty : IsSublattice (∅ : Set α) := ⟨supClosed_empty, infClosed_empty⟩ @[simp] lemma isSublattice_singleton : IsSublattice ({a} : Set α) := ⟨supClosed_singleton, infClosed_singleton⟩ @[simp] lemma isSublattice_univ : IsSublattice (Set.univ : Set α) := ⟨supClosed_univ, infClosed_univ⟩ lemma IsSublattice.inter (hs : IsSublattice s) (ht : IsSublattice t) : IsSublattice (s ∩ t) := ⟨hs.1.inter ht.1, hs.2.inter ht.2⟩ lemma isSublattice_sInter (hS : ∀ s ∈ S, IsSublattice s) : IsSublattice (⋂₀ S) := ⟨supClosed_sInter fun _s hs ↦ (hS _ hs).1, infClosed_sInter fun _s hs ↦ (hS _ hs).2⟩ lemma isSublattice_iInter (hf : ∀ i, IsSublattice (f i)) : IsSublattice (⋂ i, f i) := ⟨supClosed_iInter fun _i ↦ (hf _).1, infClosed_iInter fun _i ↦ (hf _).2⟩ lemma IsSublattice.preimage [FunLike F β α] [LatticeHomClass F β α] (hs : IsSublattice s) (f : F) : IsSublattice (f ⁻¹' s) := ⟨hs.1.preimage _, hs.2.preimage _⟩ lemma IsSublattice.image [FunLike F α β] [LatticeHomClass F α β] (hs : IsSublattice s) (f : F) : IsSublattice (f '' s) := ⟨hs.1.image _, hs.2.image _⟩ lemma IsSublattice_range [FunLike F α β] [LatticeHomClass F α β] (f : F) : IsSublattice (Set.range f) := ⟨supClosed_range _, infClosed_range _⟩ lemma IsSublattice.prod {t : Set β} (hs : IsSublattice s) (ht : IsSublattice t) : IsSublattice (s ×ˢ t) := ⟨hs.1.prod ht.1, hs.2.prod ht.2⟩ lemma isSublattice_pi {ι : Type*} {α : ι → Type*} [∀ i, Lattice (α i)] {s : Set ι} {t : ∀ i, Set (α i)} (ht : ∀ i ∈ s, IsSublattice (t i)) : IsSublattice (s.pi t) := ⟨supClosed_pi fun _i hi ↦ (ht _ hi).1, infClosed_pi fun _i hi ↦ (ht _ hi).2⟩ @[simp] lemma supClosed_preimage_toDual {s : Set αᵒᵈ} : SupClosed (toDual ⁻¹' s) ↔ InfClosed s := Iff.rfl @[simp] lemma infClosed_preimage_toDual {s : Set αᵒᵈ} : InfClosed (toDual ⁻¹' s) ↔ SupClosed s := Iff.rfl @[simp] lemma supClosed_preimage_ofDual {s : Set α} : SupClosed (ofDual ⁻¹' s) ↔ InfClosed s := Iff.rfl @[simp] lemma infClosed_preimage_ofDual {s : Set α} : InfClosed (ofDual ⁻¹' s) ↔ SupClosed s := Iff.rfl @[simp] lemma isSublattice_preimage_toDual {s : Set αᵒᵈ} : IsSublattice (toDual ⁻¹' s) ↔ IsSublattice s := ⟨fun h ↦ ⟨h.2, h.1⟩, fun h ↦ ⟨h.2, h.1⟩⟩ @[simp] lemma isSublattice_preimage_ofDual : IsSublattice (ofDual ⁻¹' s) ↔ IsSublattice s := ⟨fun h ↦ ⟨h.2, h.1⟩, fun h ↦ ⟨h.2, h.1⟩⟩ alias ⟨_, InfClosed.dual⟩ := supClosed_preimage_ofDual alias ⟨_, SupClosed.dual⟩ := infClosed_preimage_ofDual alias ⟨_, IsSublattice.dual⟩ := isSublattice_preimage_ofDual alias ⟨_, IsSublattice.of_dual⟩ := isSublattice_preimage_toDual end Lattice section LinearOrder variable [LinearOrder α] @[simp] protected lemma LinearOrder.supClosed (s : Set α) : SupClosed s := fun a ha b hb ↦ by cases le_total a b <;> simp [*] @[simp] protected lemma LinearOrder.infClosed (s : Set α) : InfClosed s := fun a ha b hb ↦ by cases le_total a b <;> simp [*] @[simp] protected lemma LinearOrder.isSublattice (s : Set α) : IsSublattice s := ⟨LinearOrder.supClosed _, LinearOrder.infClosed _⟩ end LinearOrder /-! ## Closure -/ open Finset section SemilatticeSup variable [SemilatticeSup α] [SemilatticeSup β] {s t : Set α} {a b : α} /-- Every set in a join-semilattice generates a set closed under join. -/ @[simps! isClosed] def supClosure : ClosureOperator (Set α) := .ofPred (fun s ↦ {a | ∃ (t : Finset α) (ht : t.Nonempty), ↑t ⊆ s ∧ t.sup' ht id = a}) SupClosed (fun s a ha ↦ ⟨{a}, singleton_nonempty _, by simpa⟩) (by classical rintro s _ ⟨t, ht, hts, rfl⟩ _ ⟨u, hu, hus, rfl⟩ refine ⟨_, ht.mono subset_union_left, ?_, sup'_union ht hu _⟩ rw [coe_union] exact Set.union_subset hts hus) (by rintro s₁ s₂ hs h₂ _ ⟨t, ht, hts, rfl⟩; exact h₂.finsetSup'_mem ht fun i hi ↦ hs <| hts hi) @[simp] lemma subset_supClosure {s : Set α} : s ⊆ supClosure s := supClosure.le_closure _ @[simp] lemma supClosed_supClosure : SupClosed (supClosure s) := supClosure.isClosed_closure _ lemma supClosure_mono : Monotone (supClosure : Set α → Set α) := supClosure.monotone @[simp] lemma supClosure_eq_self : supClosure s = s ↔ SupClosed s := supClosure.isClosed_iff.symm alias ⟨_, SupClosed.supClosure_eq⟩ := supClosure_eq_self lemma supClosure_idem (s : Set α) : supClosure (supClosure s) = supClosure s := supClosure.idempotent _ @[simp] lemma supClosure_empty : supClosure (∅ : Set α) = ∅ := by simp @[simp] lemma supClosure_singleton : supClosure {a} = {a} := by simp @[simp] lemma supClosure_univ : supClosure (Set.univ : Set α) = Set.univ := by simp @[simp] lemma upperBounds_supClosure (s : Set α) : upperBounds (supClosure s) = upperBounds s := (upperBounds_mono_set subset_supClosure).antisymm <| by rintro a ha _ ⟨t, ht, hts, rfl⟩ exact sup'_le _ _ fun b hb ↦ ha <| hts hb @[simp] lemma isLUB_supClosure : IsLUB (supClosure s) a ↔ IsLUB s a := by simp [IsLUB] lemma sup_mem_supClosure (ha : a ∈ s) (hb : b ∈ s) : a ⊔ b ∈ supClosure s := supClosed_supClosure (subset_supClosure ha) (subset_supClosure hb) lemma finsetSup'_mem_supClosure {ι : Type*} {t : Finset ι} (ht : t.Nonempty) {f : ι → α} (hf : ∀ i ∈ t, f i ∈ s) : t.sup' ht f ∈ supClosure s := supClosed_supClosure.finsetSup'_mem _ fun _i hi ↦ subset_supClosure <| hf _ hi lemma supClosure_min : s ⊆ t → SupClosed t → supClosure s ⊆ t := supClosure.closure_min /-- The semilatice generated by a finite set is finite. -/ protected lemma Set.Finite.supClosure (hs : s.Finite) : (supClosure s).Finite := by lift s to Finset α using hs classical refine ({t ∈ s.powerset | t.Nonempty}.attach.image fun t ↦ t.1.sup' (mem_filter.1 t.2).2 id).finite_toSet.subset ?_ rintro _ ⟨t, ht, hts, rfl⟩ simp only [id_eq, coe_image, mem_image, mem_coe, mem_attach, true_and, Subtype.exists, Finset.mem_powerset, Finset.not_nonempty_iff_eq_empty, mem_filter] exact ⟨t, ⟨hts, ht⟩, rfl⟩ @[simp] lemma supClosure_prod (s : Set α) (t : Set β) : supClosure (s ×ˢ t) = supClosure s ×ˢ supClosure t := le_antisymm (supClosure_min (Set.prod_mono subset_supClosure subset_supClosure) <| supClosed_supClosure.prod supClosed_supClosure) <| by rintro ⟨_, _⟩ ⟨⟨u, hu, hus, rfl⟩, v, hv, hvt, rfl⟩ refine ⟨u ×ˢ v, hu.product hv, ?_, ?_⟩ · simpa only [coe_product] using Set.prod_mono hus hvt · simp [prodMk_sup'_sup'] end SemilatticeSup section SemilatticeInf
variable [SemilatticeInf α] [SemilatticeInf β] {s t : Set α} {a b : α}
Mathlib/Order/SupClosed.lean
351
351
/- 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) :
Mathlib/Geometry/Euclidean/Angle/Oriented/Basic.lean
447
466
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.Logic.Relator import Mathlib.Tactic.Use import Mathlib.Tactic.MkIffOfInductiveProp import Mathlib.Tactic.SimpRw import Mathlib.Logic.Basic import Mathlib.Order.Defs.Unbundled /-! # Relation closures This file defines the reflexive, transitive, reflexive transitive and equivalence closures of relations and proves some basic results on them. Note that this is about unbundled relations, that is terms of types of the form `α → β → Prop`. For the bundled version, see `Rel`. ## Definitions * `Relation.ReflGen`: Reflexive closure. `ReflGen r` relates everything `r` related, plus for all `a` it relates `a` with itself. So `ReflGen r a b ↔ r a b ∨ a = b`. * `Relation.TransGen`: Transitive closure. `TransGen r` relates everything `r` related transitively. So `TransGen r a b ↔ ∃ x₀ ... xₙ, r a x₀ ∧ r x₀ x₁ ∧ ... ∧ r xₙ b`. * `Relation.ReflTransGen`: Reflexive transitive closure. `ReflTransGen r` relates everything `r` related transitively, plus for all `a` it relates `a` with itself. So `ReflTransGen r a b ↔ (∃ x₀ ... xₙ, r a x₀ ∧ r x₀ x₁ ∧ ... ∧ r xₙ b) ∨ a = b`. It is the same as the reflexive closure of the transitive closure, or the transitive closure of the reflexive closure. In terms of rewriting systems, this means that `a` can be rewritten to `b` in a number of rewrites. * `Relation.EqvGen`: Equivalence closure. `EqvGen r` relates everything `ReflTransGen r` relates, plus for all related pairs it relates them in the opposite order. * `Relation.Comp`: Relation composition. We provide notation `∘r`. For `r : α → β → Prop` and `s : β → γ → Prop`, `r ∘r s`relates `a : α` and `c : γ` iff there exists `b : β` that's related to both. * `Relation.Map`: Image of a relation under a pair of maps. For `r : α → β → Prop`, `f : α → γ`, `g : β → δ`, `Map r f g` is the relation `γ → δ → Prop` relating `f a` and `g b` for all `a`, `b` related by `r`. * `Relation.Join`: Join of a relation. For `r : α → α → Prop`, `Join r a b ↔ ∃ c, r a c ∧ r b c`. In terms of rewriting systems, this means that `a` and `b` can be rewritten to the same term. -/ open Function variable {α β γ δ ε ζ : Type*} section NeImp variable {r : α → α → Prop} theorem IsRefl.reflexive [IsRefl α r] : Reflexive r := fun x ↦ IsRefl.refl x /-- To show a reflexive relation `r : α → α → Prop` holds over `x y : α`, it suffices to show it holds when `x ≠ y`. -/ theorem Reflexive.rel_of_ne_imp (h : Reflexive r) {x y : α} (hr : x ≠ y → r x y) : r x y := by by_cases hxy : x = y · exact hxy ▸ h x · exact hr hxy /-- If a reflexive relation `r : α → α → Prop` holds over `x y : α`, then it holds whether or not `x ≠ y`. -/ theorem Reflexive.ne_imp_iff (h : Reflexive r) {x y : α} : x ≠ y → r x y ↔ r x y := ⟨h.rel_of_ne_imp, fun hr _ ↦ hr⟩ /-- If a reflexive relation `r : α → α → Prop` holds over `x y : α`, then it holds whether or not `x ≠ y`. Unlike `Reflexive.ne_imp_iff`, this uses `[IsRefl α r]`. -/ theorem reflexive_ne_imp_iff [IsRefl α r] {x y : α} : x ≠ y → r x y ↔ r x y := IsRefl.reflexive.ne_imp_iff protected theorem Symmetric.iff (H : Symmetric r) (x y : α) : r x y ↔ r y x := ⟨fun h ↦ H h, fun h ↦ H h⟩ theorem Symmetric.flip_eq (h : Symmetric r) : flip r = r := funext₂ fun _ _ ↦ propext <| h.iff _ _ theorem Symmetric.swap_eq : Symmetric r → swap r = r := Symmetric.flip_eq theorem flip_eq_iff : flip r = r ↔ Symmetric r := ⟨fun h _ _ ↦ (congr_fun₂ h _ _).mp, Symmetric.flip_eq⟩ theorem swap_eq_iff : swap r = r ↔ Symmetric r := flip_eq_iff end NeImp section Comap variable {r : β → β → Prop} theorem Reflexive.comap (h : Reflexive r) (f : α → β) : Reflexive (r on f) := fun a ↦ h (f a) theorem Symmetric.comap (h : Symmetric r) (f : α → β) : Symmetric (r on f) := fun _ _ hab ↦ h hab theorem Transitive.comap (h : Transitive r) (f : α → β) : Transitive (r on f) := fun _ _ _ hab hbc ↦ h hab hbc theorem Equivalence.comap (h : Equivalence r) (f : α → β) : Equivalence (r on f) := ⟨fun a ↦ h.refl (f a), h.symm, h.trans⟩ end Comap namespace Relation section Comp variable {r : α → β → Prop} {p : β → γ → Prop} {q : γ → δ → Prop} /-- The composition of two relations, yielding a new relation. The result relates a term of `α` and a term of `γ` if there is an intermediate term of `β` related to both. -/ def Comp (r : α → β → Prop) (p : β → γ → Prop) (a : α) (c : γ) : Prop := ∃ b, r a b ∧ p b c @[inherit_doc] local infixr:80 " ∘r " => Relation.Comp @[simp] theorem comp_eq_fun (f : γ → β) : r ∘r (· = f ·) = (r · <| f ·) := by ext x y simp [Comp] @[simp] theorem comp_eq : r ∘r (· = ·) = r := comp_eq_fun .. @[simp] theorem fun_eq_comp (f : γ → α) : (f · = ·) ∘r r = (r <| f ·) := by ext x y simp [Comp] @[simp] theorem eq_comp : (· = ·) ∘r r = r := fun_eq_comp .. @[simp] theorem iff_comp {r : Prop → α → Prop} : (· ↔ ·) ∘r r = r := by have : (· ↔ ·) = (· = ·) := by funext a b; exact iff_eq_eq rw [this, eq_comp] @[simp] theorem comp_iff {r : α → Prop → Prop} : r ∘r (· ↔ ·) = r := by have : (· ↔ ·) = (· = ·) := by funext a b; exact iff_eq_eq rw [this, comp_eq] theorem comp_assoc : (r ∘r p) ∘r q = r ∘r p ∘r q := by funext a d apply propext constructor · exact fun ⟨c, ⟨b, hab, hbc⟩, hcd⟩ ↦ ⟨b, hab, c, hbc, hcd⟩ · exact fun ⟨b, hab, c, hbc, hcd⟩ ↦ ⟨c, ⟨b, hab, hbc⟩, hcd⟩ theorem flip_comp : flip (r ∘r p) = flip p ∘r flip r := by funext c a apply propext constructor · exact fun ⟨b, hab, hbc⟩ ↦ ⟨b, hbc, hab⟩ · exact fun ⟨b, hbc, hab⟩ ↦ ⟨b, hab, hbc⟩ end Comp section Fibration variable (rα : α → α → Prop) (rβ : β → β → Prop) (f : α → β) /-- A function `f : α → β` is a fibration between the relation `rα` and `rβ` if for all `a : α` and `b : β`, whenever `b : β` and `f a` are related by `rβ`, `b` is the image of some `a' : α` under `f`, and `a'` and `a` are related by `rα`. -/ def Fibration := ∀ ⦃a b⦄, rβ b (f a) → ∃ a', rα a' a ∧ f a' = b variable {rα rβ} /-- If `f : α → β` is a fibration between relations `rα` and `rβ`, and `a : α` is accessible under `rα`, then `f a` is accessible under `rβ`. -/ theorem _root_.Acc.of_fibration (fib : Fibration rα rβ f) {a} (ha : Acc rα a) : Acc rβ (f a) := by induction ha with | intro a _ ih => ?_ refine Acc.intro (f a) fun b hr ↦ ?_ obtain ⟨a', hr', rfl⟩ := fib hr exact ih a' hr' theorem _root_.Acc.of_downward_closed (dc : ∀ {a b}, rβ b (f a) → ∃ c, f c = b) (a : α) (ha : Acc (InvImage rβ f) a) : Acc rβ (f a) := ha.of_fibration f fun a _ h ↦ let ⟨a', he⟩ := dc h ⟨a', by simp_all [InvImage], he⟩ end Fibration section Map variable {r : α → β → Prop} {f : α → γ} {g : β → δ} {c : γ} {d : δ} /-- The map of a relation `r` through a pair of functions pushes the relation to the codomains of the functions. The resulting relation is defined by having pairs of terms related if they have preimages related by `r`. -/ protected def Map (r : α → β → Prop) (f : α → γ) (g : β → δ) : γ → δ → Prop := fun c d ↦ ∃ a b, r a b ∧ f a = c ∧ g b = d lemma map_apply : Relation.Map r f g c d ↔ ∃ a b, r a b ∧ f a = c ∧ g b = d := Iff.rfl @[simp] lemma map_map (r : α → β → Prop) (f₁ : α → γ) (g₁ : β → δ) (f₂ : γ → ε) (g₂ : δ → ζ) : Relation.Map (Relation.Map r f₁ g₁) f₂ g₂ = Relation.Map r (f₂ ∘ f₁) (g₂ ∘ g₁) := by ext a b simp_rw [Relation.Map, Function.comp_apply, ← exists_and_right, @exists_comm γ, @exists_comm δ] refine exists₂_congr fun a b ↦ ⟨?_, fun h ↦ ⟨_, _, ⟨⟨h.1, rfl, rfl⟩, h.2⟩⟩⟩ rintro ⟨_, _, ⟨hab, rfl, rfl⟩, h⟩ exact ⟨hab, h⟩ @[simp] lemma map_apply_apply (hf : Injective f) (hg : Injective g) (r : α → β → Prop) (a : α) (b : β) : Relation.Map r f g (f a) (g b) ↔ r a b := by simp [Relation.Map, hf.eq_iff, hg.eq_iff] @[simp] lemma map_id_id (r : α → β → Prop) : Relation.Map r id id = r := by ext; simp [Relation.Map] instance [Decidable (∃ a b, r a b ∧ f a = c ∧ g b = d)] : Decidable (Relation.Map r f g c d) := ‹Decidable _› lemma map_reflexive {r : α → α → Prop} (hr : Reflexive r) {f : α → β} (hf : f.Surjective) : Reflexive (Relation.Map r f f) := by intro x obtain ⟨y, rfl⟩ := hf x exact ⟨y, y, hr y, rfl, rfl⟩ lemma map_symmetric {r : α → α → Prop} (hr : Symmetric r) (f : α → β) : Symmetric (Relation.Map r f f) := by rintro _ _ ⟨x, y, hxy, rfl, rfl⟩; exact ⟨_, _, hr hxy, rfl, rfl⟩ lemma map_transitive {r : α → α → Prop} (hr : Transitive r) {f : α → β} (hf : ∀ x y, f x = f y → r x y) : Transitive (Relation.Map r f f) := by rintro _ _ _ ⟨x, y, hxy, rfl, rfl⟩ ⟨y', z, hyz, hy, rfl⟩ exact ⟨x, z, hr hxy <| hr (hf _ _ hy.symm) hyz, rfl, rfl⟩ lemma map_equivalence {r : α → α → Prop} (hr : Equivalence r) (f : α → β) (hf : f.Surjective) (hf_ker : ∀ x y, f x = f y → r x y) : Equivalence (Relation.Map r f f) where refl := map_reflexive hr.reflexive hf symm := @(map_symmetric hr.symmetric _) trans := @(map_transitive hr.transitive hf_ker) -- TODO: state this using `≤`, after adjusting imports. lemma map_mono {r s : α → β → Prop} {f : α → γ} {g : β → δ} (h : ∀ x y, r x y → s x y) : ∀ x y, Relation.Map r f g x y → Relation.Map s f g x y := fun _ _ ⟨x, y, hxy, hx, hy⟩ => ⟨x, y, h _ _ hxy, hx, hy⟩ end Map variable {r : α → α → Prop} {a b c : α} /-- `ReflTransGen r`: reflexive transitive closure of `r` -/ @[mk_iff ReflTransGen.cases_tail_iff] inductive ReflTransGen (r : α → α → Prop) (a : α) : α → Prop | refl : ReflTransGen r a a | tail {b c} : ReflTransGen r a b → r b c → ReflTransGen r a c attribute [refl] ReflTransGen.refl /-- `ReflGen r`: reflexive closure of `r` -/ @[mk_iff] inductive ReflGen (r : α → α → Prop) (a : α) : α → Prop | refl : ReflGen r a a | single {b} : r a b → ReflGen r a b variable (r) in /-- `EqvGen r`: equivalence closure of `r`. -/ @[mk_iff] inductive EqvGen : α → α → Prop | rel x y : r x y → EqvGen x y | refl x : EqvGen x x | symm x y : EqvGen x y → EqvGen y x | trans x y z : EqvGen x y → EqvGen y z → EqvGen x z attribute [mk_iff] TransGen attribute [refl] ReflGen.refl namespace ReflGen theorem to_reflTransGen : ∀ {a b}, ReflGen r a b → ReflTransGen r a b | a, _, refl => by rfl | _, _, single h => ReflTransGen.tail ReflTransGen.refl h theorem mono {p : α → α → Prop} (hp : ∀ a b, r a b → p a b) : ∀ {a b}, ReflGen r a b → ReflGen p a b | a, _, ReflGen.refl => by rfl | a, b, single h => single (hp a b h) instance : IsRefl α (ReflGen r) := ⟨@refl α r⟩ end ReflGen namespace ReflTransGen @[trans] theorem trans (hab : ReflTransGen r a b) (hbc : ReflTransGen r b c) : ReflTransGen r a c := by induction hbc with | refl => assumption | tail _ hcd hac => exact hac.tail hcd theorem single (hab : r a b) : ReflTransGen r a b := refl.tail hab theorem head (hab : r a b) (hbc : ReflTransGen r b c) : ReflTransGen r a c := by induction hbc with | refl => exact refl.tail hab | tail _ hcd hac => exact hac.tail hcd theorem symmetric (h : Symmetric r) : Symmetric (ReflTransGen r) := by intro x y h induction h with | refl => rfl | tail _ b c => apply Relation.ReflTransGen.head (h b) c theorem cases_tail : ReflTransGen r a b → b = a ∨ ∃ c, ReflTransGen r a c ∧ r c b := (cases_tail_iff r a b).1 @[elab_as_elim] theorem head_induction_on {P : ∀ a : α, ReflTransGen r a b → Prop} {a : α} (h : ReflTransGen r a b) (refl : P b refl) (head : ∀ {a c} (h' : r a c) (h : ReflTransGen r c b), P c h → P a (h.head h')) : P a h := by induction h with | refl => exact refl | @tail b c _ hbc ih => apply ih · exact head hbc _ refl · exact fun h1 h2 ↦ head h1 (h2.tail hbc) @[elab_as_elim] theorem trans_induction_on {P : ∀ {a b : α}, ReflTransGen r a b → Prop} {a b : α} (h : ReflTransGen r a b) (ih₁ : ∀ a, @P a a refl) (ih₂ : ∀ {a b} (h : r a b), P (single h)) (ih₃ : ∀ {a b c} (h₁ : ReflTransGen r a b) (h₂ : ReflTransGen r b c), P h₁ → P h₂ → P (h₁.trans h₂)) : P h := by induction h with | refl => exact ih₁ a | tail hab hbc ih => exact ih₃ hab (single hbc) ih (ih₂ hbc) theorem cases_head (h : ReflTransGen r a b) : a = b ∨ ∃ c, r a c ∧ ReflTransGen r c b := by induction h using Relation.ReflTransGen.head_induction_on · left rfl · right exact ⟨_, by assumption, by assumption⟩ theorem cases_head_iff : ReflTransGen r a b ↔ a = b ∨ ∃ c, r a c ∧ ReflTransGen r c b := by use cases_head rintro (rfl | ⟨c, hac, hcb⟩) · rfl · exact head hac hcb theorem total_of_right_unique (U : Relator.RightUnique r) (ab : ReflTransGen r a b) (ac : ReflTransGen r a c) : ReflTransGen r b c ∨ ReflTransGen r c b := by induction ab with | refl => exact Or.inl ac | tail _ bd IH => rcases IH with (IH | IH) · rcases cases_head IH with (rfl | ⟨e, be, ec⟩) · exact Or.inr (single bd) · cases U bd be exact Or.inl ec · exact Or.inr (IH.tail bd) end ReflTransGen namespace TransGen theorem to_reflTransGen {a b} (h : TransGen r a b) : ReflTransGen r a b := by induction h with | single h => exact ReflTransGen.single h | tail _ bc ab => exact ReflTransGen.tail ab bc theorem trans_left (hab : TransGen r a b) (hbc : ReflTransGen r b c) : TransGen r a c := by induction hbc with | refl => assumption | tail _ hcd hac => exact hac.tail hcd instance : Trans (TransGen r) (ReflTransGen r) (TransGen r) := ⟨trans_left⟩ attribute [trans] trans instance : Trans (TransGen r) (TransGen r) (TransGen r) := ⟨trans⟩ theorem head' (hab : r a b) (hbc : ReflTransGen r b c) : TransGen r a c := trans_left (single hab) hbc theorem tail' (hab : ReflTransGen r a b) (hbc : r b c) : TransGen r a c := by induction hab generalizing c with | refl => exact single hbc | tail _ hdb IH => exact tail (IH hdb) hbc theorem head (hab : r a b) (hbc : TransGen r b c) : TransGen r a c := head' hab hbc.to_reflTransGen @[elab_as_elim] theorem head_induction_on {P : ∀ a : α, TransGen r a b → Prop} {a : α} (h : TransGen r a b) (base : ∀ {a} (h : r a b), P a (single h)) (ih : ∀ {a c} (h' : r a c) (h : TransGen r c b), P c h → P a (h.head h')) : P a h := by induction h with | single h => exact base h | @tail b c _ hbc h_ih => apply h_ih · exact fun h ↦ ih h (single hbc) (base hbc) · exact fun hab hbc ↦ ih hab _ @[elab_as_elim] theorem trans_induction_on {P : ∀ {a b : α}, TransGen r a b → Prop} {a b : α} (h : TransGen r a b) (base : ∀ {a b} (h : r a b), P (single h)) (ih : ∀ {a b c} (h₁ : TransGen r a b) (h₂ : TransGen r b c), P h₁ → P h₂ → P (h₁.trans h₂)) : P h := by induction h with | single h => exact base h | tail hab hbc h_ih => exact ih hab (single hbc) h_ih (base hbc) theorem trans_right (hab : ReflTransGen r a b) (hbc : TransGen r b c) : TransGen r a c := by induction hbc with | single hbc => exact tail' hab hbc | tail _ hcd hac => exact hac.tail hcd instance : Trans (ReflTransGen r) (TransGen r) (TransGen r) := ⟨trans_right⟩ theorem tail'_iff : TransGen r a c ↔ ∃ b, ReflTransGen r a b ∧ r b c := by refine ⟨fun h ↦ ?_, fun ⟨b, hab, hbc⟩ ↦ tail' hab hbc⟩ cases h with | single hac => exact ⟨_, by rfl, hac⟩ | tail hab hbc => exact ⟨_, hab.to_reflTransGen, hbc⟩ theorem head'_iff : TransGen r a c ↔ ∃ b, r a b ∧ ReflTransGen r b c := by refine ⟨fun h ↦ ?_, fun ⟨b, hab, hbc⟩ ↦ head' hab hbc⟩ induction h with | single hac => exact ⟨_, hac, by rfl⟩ | tail _ hbc IH => rcases IH with ⟨d, had, hdb⟩ exact ⟨_, had, hdb.tail hbc⟩ end TransGen section reflGen lemma reflGen_eq_self (hr : Reflexive r) : ReflGen r = r := by ext x y simpa only [reflGen_iff, or_iff_right_iff_imp] using fun h ↦ h ▸ hr y lemma reflexive_reflGen : Reflexive (ReflGen r) := fun _ ↦ .refl lemma reflGen_minimal {r' : α → α → Prop} (hr' : Reflexive r') (h : ∀ x y, r x y → r' x y) {x y : α} (hxy : ReflGen r x y) : r' x y := by simpa [reflGen_eq_self hr'] using ReflGen.mono h hxy end reflGen section TransGen theorem transGen_eq_self (trans : Transitive r) : TransGen r = r := funext fun a ↦ funext fun b ↦ propext <| ⟨fun h ↦ by induction h with | single hc => exact hc | tail _ hcd hac => exact trans hac hcd, TransGen.single⟩ theorem transitive_transGen : Transitive (TransGen r) := fun _ _ _ ↦ TransGen.trans instance : IsTrans α (TransGen r) := ⟨@TransGen.trans α r⟩ theorem transGen_idem : TransGen (TransGen r) = TransGen r := transGen_eq_self transitive_transGen theorem TransGen.lift {p : β → β → Prop} {a b : α} (f : α → β) (h : ∀ a b, r a b → p (f a) (f b)) (hab : TransGen r a b) : TransGen p (f a) (f b) := by induction hab with | single hac => exact TransGen.single (h a _ hac) | tail _ hcd hac => exact TransGen.tail hac (h _ _ hcd) theorem TransGen.lift' {p : β → β → Prop} {a b : α} (f : α → β) (h : ∀ a b, r a b → TransGen p (f a) (f b)) (hab : TransGen r a b) : TransGen p (f a) (f b) := by simpa [transGen_idem] using hab.lift f h theorem TransGen.closed {p : α → α → Prop} : (∀ a b, r a b → TransGen p a b) → TransGen r a b → TransGen p a b := TransGen.lift' id lemma TransGen.closed' {P : α → Prop} (dc : ∀ {a b}, r a b → P b → P a) {a b : α} (h : TransGen r a b) : P b → P a := h.head_induction_on dc fun hr _ hi ↦ dc hr ∘ hi theorem TransGen.mono {p : α → α → Prop} : (∀ a b, r a b → p a b) → TransGen r a b → TransGen p a b := TransGen.lift id lemma transGen_minimal {r' : α → α → Prop} (hr' : Transitive r') (h : ∀ x y, r x y → r' x y) {x y : α} (hxy : TransGen r x y) : r' x y := by simpa [transGen_eq_self hr'] using TransGen.mono h hxy theorem TransGen.swap (h : TransGen r b a) : TransGen (swap r) a b := by induction h with | single h => exact TransGen.single h | tail _ hbc ih => exact ih.head hbc theorem transGen_swap : TransGen (swap r) a b ↔ TransGen r b a := ⟨TransGen.swap, TransGen.swap⟩ end TransGen section ReflTransGen open ReflTransGen theorem reflTransGen_iff_eq (h : ∀ b, ¬r a b) : ReflTransGen r a b ↔ b = a := by rw [cases_head_iff]; simp [h, eq_comm] theorem reflTransGen_iff_eq_or_transGen : ReflTransGen r a b ↔ b = a ∨ TransGen r a b := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · cases h with | refl => exact Or.inl rfl | tail hac hcb => exact Or.inr (TransGen.tail' hac hcb) · rcases h with (rfl | h) · rfl · exact h.to_reflTransGen theorem ReflTransGen.lift {p : β → β → Prop} {a b : α} (f : α → β) (h : ∀ a b, r a b → p (f a) (f b)) (hab : ReflTransGen r a b) : ReflTransGen p (f a) (f b) := ReflTransGen.trans_induction_on hab (fun _ ↦ refl) (ReflTransGen.single ∘ h _ _) fun _ _ ↦ trans theorem ReflTransGen.mono {p : α → α → Prop} : (∀ a b, r a b → p a b) → ReflTransGen r a b → ReflTransGen p a b := ReflTransGen.lift id theorem reflTransGen_eq_self (refl : Reflexive r) (trans : Transitive r) : ReflTransGen r = r := funext fun a ↦ funext fun b ↦ propext <| ⟨fun h ↦ by induction h with | refl => apply refl | tail _ h₂ IH => exact trans IH h₂, single⟩ lemma reflTransGen_minimal {r' : α → α → Prop} (hr₁ : Reflexive r') (hr₂ : Transitive r') (h : ∀ x y, r x y → r' x y) {x y : α} (hxy : ReflTransGen r x y) : r' x y := by simpa [reflTransGen_eq_self hr₁ hr₂] using ReflTransGen.mono h hxy theorem reflexive_reflTransGen : Reflexive (ReflTransGen r) := fun _ ↦ refl theorem transitive_reflTransGen : Transitive (ReflTransGen r) := fun _ _ _ ↦ trans instance : IsRefl α (ReflTransGen r) := ⟨@ReflTransGen.refl α r⟩ instance : IsTrans α (ReflTransGen r) := ⟨@ReflTransGen.trans α r⟩ theorem reflTransGen_idem : ReflTransGen (ReflTransGen r) = ReflTransGen r := reflTransGen_eq_self reflexive_reflTransGen transitive_reflTransGen theorem ReflTransGen.lift' {p : β → β → Prop} {a b : α} (f : α → β) (h : ∀ a b, r a b → ReflTransGen p (f a) (f b)) (hab : ReflTransGen r a b) : ReflTransGen p (f a) (f b) := by simpa [reflTransGen_idem] using hab.lift f h theorem reflTransGen_closed {p : α → α → Prop} : (∀ a b, r a b → ReflTransGen p a b) → ReflTransGen r a b → ReflTransGen p a b := ReflTransGen.lift' id theorem ReflTransGen.swap (h : ReflTransGen r b a) : ReflTransGen (swap r) a b := by induction h with | refl => rfl | tail _ hbc ih => exact ih.head hbc theorem reflTransGen_swap : ReflTransGen (swap r) a b ↔ ReflTransGen r b a := ⟨ReflTransGen.swap, ReflTransGen.swap⟩ @[simp] lemma reflGen_transGen : ReflGen (TransGen r) = ReflTransGen r := by ext x y simp_rw [reflTransGen_iff_eq_or_transGen, reflGen_iff] @[simp] lemma transGen_reflGen : TransGen (ReflGen r) = ReflTransGen r := by ext x y refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · simpa [reflTransGen_idem] using TransGen.to_reflTransGen <| TransGen.mono (fun _ _ ↦ ReflGen.to_reflTransGen) h · obtain (rfl | h) := reflTransGen_iff_eq_or_transGen.mp h · exact .single .refl · exact TransGen.mono (fun _ _ ↦ .single) h @[simp] lemma reflTransGen_reflGen : ReflTransGen (ReflGen r) = ReflTransGen r := by simp only [← transGen_reflGen, reflGen_eq_self reflexive_reflGen] @[simp] lemma reflTransGen_transGen : ReflTransGen (TransGen r) = ReflTransGen r := by simp only [← reflGen_transGen, transGen_idem] lemma reflTransGen_eq_transGen (hr : Reflexive r) : ReflTransGen r = TransGen r := by rw [← transGen_reflGen, reflGen_eq_self hr] lemma reflTransGen_eq_reflGen (hr : Transitive r) : ReflTransGen r = ReflGen r := by rw [← reflGen_transGen, transGen_eq_self hr] end ReflTransGen namespace EqvGen variable (r)
theorem is_equivalence : Equivalence (@EqvGen α r) := Equivalence.mk EqvGen.refl (EqvGen.symm _ _) (EqvGen.trans _ _ _) /-- `EqvGen.setoid r` is the setoid generated by a relation `r`.
Mathlib/Logic/Relation.lean
611
614
/- 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.HomotopyCofiber /-! # The mapping cone of a morphism of cochain complexes In this file, we study the homotopy cofiber `HomologicalComplex.homotopyCofiber` of a morphism `φ : F ⟶ G` of cochain complexes indexed by `ℤ`. In this case, we redefine it as `CochainComplex.mappingCone φ`. The API involves definitions - `mappingCone.inl φ : Cochain F (mappingCone φ) (-1)`, - `mappingCone.inr φ : G ⟶ mappingCone φ`, - `mappingCone.fst φ : Cocycle (mappingCone φ) F 1` and - `mappingCone.snd φ : Cochain (mappingCone φ) G 0`. -/ assert_not_exists TwoSidedIdeal open CategoryTheory Limits variable {C D : Type*} [Category C] [Category D] [Preadditive C] [Preadditive D] namespace CochainComplex open HomologicalComplex section variable {ι : Type*} [AddRightCancelSemigroup ι] [One ι] {F G : CochainComplex C ι} (φ : F ⟶ G) instance [∀ p, HasBinaryBiproduct (F.X (p + 1)) (G.X p)] : HasHomotopyCofiber φ where hasBinaryBiproduct := by rintro i _ rfl infer_instance end variable {F G : CochainComplex C ℤ} (φ : F ⟶ G) variable [HasHomotopyCofiber φ] /-- The mapping cone of a morphism of cochain complexes indexed by `ℤ`. -/ noncomputable def mappingCone := homotopyCofiber φ namespace mappingCone open HomComplex /-- The left inclusion in the mapping cone, as a cochain of degree `-1`. -/ noncomputable def inl : Cochain F (mappingCone φ) (-1) := Cochain.mk (fun p q hpq => homotopyCofiber.inlX φ p q (by dsimp; omega)) /-- The right inclusion in the mapping cone. -/ noncomputable def inr : G ⟶ mappingCone φ := homotopyCofiber.inr φ /-- The first projection from the mapping cone, as a cocyle of degree `1`. -/ noncomputable def fst : Cocycle (mappingCone φ) F 1 := Cocycle.mk (Cochain.mk (fun p q hpq => homotopyCofiber.fstX φ p q hpq)) 2 (by omega) (by ext p _ rfl simp [δ_v 1 2 (by omega) _ p (p + 2) (by omega) (p + 1) (p + 1) (by omega) rfl, homotopyCofiber.d_fstX φ p (p + 1) (p + 2) rfl, mappingCone, show Int.negOnePow 2 = 1 by rfl]) /-- The second projection from the mapping cone, as a cochain of degree `0`. -/ noncomputable def snd : Cochain (mappingCone φ) G 0 := Cochain.ofHoms (homotopyCofiber.sndX φ) @[reassoc (attr := simp)] lemma inl_v_fst_v (p q : ℤ) (hpq : q + 1 = p) : (inl φ).v p q (by rw [← hpq, add_neg_cancel_right]) ≫ (fst φ : Cochain (mappingCone φ) F 1).v q p hpq = 𝟙 _ := by simp [inl, fst] @[reassoc (attr := simp)] lemma inl_v_snd_v (p q : ℤ) (hpq : p + (-1) = q) : (inl φ).v p q hpq ≫ (snd φ).v q q (add_zero q) = 0 := by simp [inl, snd] @[reassoc (attr := simp)] lemma inr_f_fst_v (p q : ℤ) (hpq : p + 1 = q) : (inr φ).f p ≫ (fst φ).1.v p q hpq = 0 := by simp [inr, fst] @[reassoc (attr := simp)] lemma inr_f_snd_v (p : ℤ) : (inr φ).f p ≫ (snd φ).v p p (add_zero p) = 𝟙 _ := by simp [inr, snd] @[simp] lemma inl_fst : (inl φ).comp (fst φ).1 (neg_add_cancel 1) = Cochain.ofHom (𝟙 F) := by ext p simp [Cochain.comp_v _ _ (neg_add_cancel 1) p (p-1) p rfl (by omega)] @[simp] lemma inl_snd : (inl φ).comp (snd φ) (add_zero (-1)) = 0 := by ext p q hpq simp [Cochain.comp_v _ _ (add_zero (-1)) p q q (by omega) (by omega)] @[simp] lemma inr_fst : (Cochain.ofHom (inr φ)).comp (fst φ).1 (zero_add 1) = 0 := by ext p q hpq simp [Cochain.comp_v _ _ (zero_add 1) p p q (by omega) (by omega)] @[simp] lemma inr_snd : (Cochain.ofHom (inr φ)).comp (snd φ) (zero_add 0) = Cochain.ofHom (𝟙 G) := by aesop_cat /-! In order to obtain identities of cochains involving `inl`, `inr`, `fst` and `snd`, it is often convenient to use an `ext` lemma, and use simp lemmas like `inl_v_f_fst_v`, but it is sometimes possible to get identities of cochains by using rewrites of identities of cochains like `inl_fst`. Then, similarly as in category theory, if we associate the compositions of cochains to the right as much as possible, it is also interesting to have `reassoc` variants of lemmas, like `inl_fst_assoc`. -/ @[simp] lemma inl_fst_assoc {K : CochainComplex C ℤ} {d e : ℤ} (γ : Cochain F K d) (he : 1 + d = e) : (inl φ).comp ((fst φ).1.comp γ he) (by rw [← he, neg_add_cancel_left]) = γ := by rw [← Cochain.comp_assoc _ _ _ (neg_add_cancel 1) (by omega) (by omega), inl_fst, Cochain.id_comp] @[simp] lemma inl_snd_assoc {K : CochainComplex C ℤ} {d e f : ℤ} (γ : Cochain G K d) (he : 0 + d = e) (hf : -1 + e = f) : (inl φ).comp ((snd φ).comp γ he) hf = 0 := by obtain rfl : e = d := by omega rw [← Cochain.comp_assoc_of_second_is_zero_cochain, inl_snd, Cochain.zero_comp] @[simp] lemma inr_fst_assoc {K : CochainComplex C ℤ} {d e f : ℤ} (γ : Cochain F K d) (he : 1 + d = e) (hf : 0 + e = f) : (Cochain.ofHom (inr φ)).comp ((fst φ).1.comp γ he) hf = 0 := by obtain rfl : e = f := by omega rw [← Cochain.comp_assoc_of_first_is_zero_cochain, inr_fst, Cochain.zero_comp] @[simp] lemma inr_snd_assoc {K : CochainComplex C ℤ} {d e : ℤ} (γ : Cochain G K d) (he : 0 + d = e) : (Cochain.ofHom (inr φ)).comp ((snd φ).comp γ he) (by simp only [← he, zero_add]) = γ := by obtain rfl : d = e := by omega rw [← Cochain.comp_assoc_of_first_is_zero_cochain, inr_snd, Cochain.id_comp] lemma ext_to (i j : ℤ) (hij : i + 1 = j) {A : C} {f g : A ⟶ (mappingCone φ).X i} (h₁ : f ≫ (fst φ).1.v i j hij = g ≫ (fst φ).1.v i j hij) (h₂ : f ≫ (snd φ).v i i (add_zero i) = g ≫ (snd φ).v i i (add_zero i)) : f = g := homotopyCofiber.ext_to_X φ i j hij h₁ (by simpa [snd] using h₂) lemma ext_to_iff (i j : ℤ) (hij : i + 1 = j) {A : C} (f g : A ⟶ (mappingCone φ).X i) : f = g ↔ f ≫ (fst φ).1.v i j hij = g ≫ (fst φ).1.v i j hij ∧ f ≫ (snd φ).v i i (add_zero i) = g ≫ (snd φ).v i i (add_zero i) := by constructor · rintro rfl tauto · rintro ⟨h₁, h₂⟩ exact ext_to φ i j hij h₁ h₂ lemma ext_from (i j : ℤ) (hij : j + 1 = i) {A : C} {f g : (mappingCone φ).X j ⟶ A} (h₁ : (inl φ).v i j (by omega) ≫ f = (inl φ).v i j (by omega) ≫ g) (h₂ : (inr φ).f j ≫ f = (inr φ).f j ≫ g) : f = g := homotopyCofiber.ext_from_X φ i j hij h₁ h₂ lemma ext_from_iff (i j : ℤ) (hij : j + 1 = i) {A : C} (f g : (mappingCone φ).X j ⟶ A) : f = g ↔ (inl φ).v i j (by omega) ≫ f = (inl φ).v i j (by omega) ≫ g ∧ (inr φ).f j ≫ f = (inr φ).f j ≫ g := by constructor · rintro rfl tauto · rintro ⟨h₁, h₂⟩ exact ext_from φ i j hij h₁ h₂ lemma decomp_to {i : ℤ} {A : C} (f : A ⟶ (mappingCone φ).X i) (j : ℤ) (hij : i + 1 = j) : ∃ (a : A ⟶ F.X j) (b : A ⟶ G.X i), f = a ≫ (inl φ).v j i (by omega) + b ≫ (inr φ).f i := ⟨f ≫ (fst φ).1.v i j hij, f ≫ (snd φ).v i i (add_zero i), by apply ext_to φ i j hij <;> simp⟩ lemma decomp_from {j : ℤ} {A : C} (f : (mappingCone φ).X j ⟶ A) (i : ℤ) (hij : j + 1 = i) : ∃ (a : F.X i ⟶ A) (b : G.X j ⟶ A), f = (fst φ).1.v j i hij ≫ a + (snd φ).v j j (add_zero j) ≫ b := ⟨(inl φ).v i j (by omega) ≫ f, (inr φ).f j ≫ f, by apply ext_from φ i j hij <;> simp⟩ lemma ext_cochain_to_iff (i j : ℤ) (hij : i + 1 = j) {K : CochainComplex C ℤ} {γ₁ γ₂ : Cochain K (mappingCone φ) i} : γ₁ = γ₂ ↔ γ₁.comp (fst φ).1 hij = γ₂.comp (fst φ).1 hij ∧ γ₁.comp (snd φ) (add_zero i) = γ₂.comp (snd φ) (add_zero i) := by constructor · rintro rfl tauto · rintro ⟨h₁, h₂⟩ ext p q hpq rw [ext_to_iff φ q (q + 1) rfl] replace h₁ := Cochain.congr_v h₁ p (q + 1) (by omega) replace h₂ := Cochain.congr_v h₂ p q hpq simp only [Cochain.comp_v _ _ _ p q (q + 1) hpq rfl] at h₁ simp only [Cochain.comp_zero_cochain_v] at h₂ exact ⟨h₁, h₂⟩ lemma ext_cochain_from_iff (i j : ℤ) (hij : i + 1 = j) {K : CochainComplex C ℤ} {γ₁ γ₂ : Cochain (mappingCone φ) K j} : γ₁ = γ₂ ↔ (inl φ).comp γ₁ (show _ = i by omega) = (inl φ).comp γ₂ (by omega) ∧ (Cochain.ofHom (inr φ)).comp γ₁ (zero_add j) = (Cochain.ofHom (inr φ)).comp γ₂ (zero_add j) := by constructor · rintro rfl tauto · rintro ⟨h₁, h₂⟩ ext p q hpq rw [ext_from_iff φ (p + 1) p rfl] replace h₁ := Cochain.congr_v h₁ (p + 1) q (by omega) replace h₂ := Cochain.congr_v h₂ p q (by omega) simp only [Cochain.comp_v (inl φ) _ _ (p + 1) p q (by omega) hpq] at h₁ simp only [Cochain.zero_cochain_comp_v, Cochain.ofHom_v] at h₂ exact ⟨h₁, h₂⟩ lemma id : (fst φ).1.comp (inl φ) (add_neg_cancel 1) + (snd φ).comp (Cochain.ofHom (inr φ)) (add_zero 0) = Cochain.ofHom (𝟙 _) := by simp [ext_cochain_from_iff φ (-1) 0 (neg_add_cancel 1)] lemma id_X (p q : ℤ) (hpq : p + 1 = q) : (fst φ).1.v p q hpq ≫ (inl φ).v q p (by omega) + (snd φ).v p p (add_zero p) ≫ (inr φ).f p = 𝟙 ((mappingCone φ).X p) := by simpa only [Cochain.add_v, Cochain.comp_zero_cochain_v, Cochain.ofHom_v, id_f, Cochain.comp_v _ _ (add_neg_cancel 1) p q p hpq (by omega)] using Cochain.congr_v (id φ) p p (add_zero p) @[reassoc] lemma inl_v_d (i j k : ℤ) (hij : i + (-1) = j) (hik : k + (-1) = i) : (inl φ).v i j hij ≫ (mappingCone φ).d j i = φ.f i ≫ (inr φ).f i - F.d i k ≫ (inl φ).v _ _ hik := by dsimp [mappingCone, inl, inr] rw [homotopyCofiber.inlX_d φ j i k (by dsimp; omega) (by dsimp; omega)] abel @[reassoc] lemma inr_f_d (n₁ n₂ : ℤ) : (inr φ).f n₁ ≫ (mappingCone φ).d n₁ n₂ = G.d n₁ n₂ ≫ (inr φ).f n₂ := by simp @[reassoc] lemma d_fst_v (i j k : ℤ) (hij : i + 1 = j) (hjk : j + 1 = k) : (mappingCone φ).d i j ≫ (fst φ).1.v j k hjk = -(fst φ).1.v i j hij ≫ F.d j k := by apply homotopyCofiber.d_fstX @[reassoc (attr := simp)] lemma d_fst_v' (i j : ℤ) (hij : i + 1 = j) : (mappingCone φ).d (i - 1) i ≫ (fst φ).1.v i j hij = -(fst φ).1.v (i - 1) i (by omega) ≫ F.d i j := d_fst_v φ (i - 1) i j (by omega) hij @[reassoc] lemma d_snd_v (i j : ℤ) (hij : i + 1 = j) : (mappingCone φ).d i j ≫ (snd φ).v j j (add_zero _) = (fst φ).1.v i j hij ≫ φ.f j + (snd φ).v i i (add_zero i) ≫ G.d i j := by dsimp [mappingCone, snd, fst] simp only [Cochain.ofHoms_v] apply homotopyCofiber.d_sndX @[reassoc (attr := simp)] lemma d_snd_v' (n : ℤ) : (mappingCone φ).d (n - 1) n ≫ (snd φ).v n n (add_zero n) = (fst φ : Cochain (mappingCone φ) F 1).v (n - 1) n (by omega) ≫ φ.f n + (snd φ).v (n - 1) (n - 1) (add_zero _) ≫ G.d (n - 1) n := by apply d_snd_v @[simp] lemma δ_inl : δ (-1) 0 (inl φ) = Cochain.ofHom (φ ≫ inr φ) := by ext p simp [δ_v (-1) 0 (neg_add_cancel 1) (inl φ) p p (add_zero p) _ _ rfl rfl, inl_v_d φ p (p - 1) (p + 1) (by omega) (by omega)] @[simp] lemma δ_snd : δ 0 1 (snd φ) = -(fst φ).1.comp (Cochain.ofHom φ) (add_zero 1) := by ext p q hpq simp [d_snd_v φ p q hpq] section variable {K : CochainComplex C ℤ} {n m : ℤ} /-- Given `φ : F ⟶ G`, this is the cochain in `Cochain (mappingCone φ) K n` that is constructed from two cochains `α : Cochain F K m` (with `m + 1 = n`) and `β : Cochain F K n`. -/ noncomputable def descCochain (α : Cochain F K m) (β : Cochain G K n) (h : m + 1 = n) : Cochain (mappingCone φ) K n := (fst φ).1.comp α (by rw [← h, add_comm]) + (snd φ).comp β (zero_add n) variable (α : Cochain F K m) (β : Cochain G K n) (h : m + 1 = n) @[simp] lemma inl_descCochain : (inl φ).comp (descCochain φ α β h) (by omega) = α := by simp [descCochain] @[simp] lemma inr_descCochain : (Cochain.ofHom (inr φ)).comp (descCochain φ α β h) (zero_add n) = β := by simp [descCochain] @[reassoc (attr := simp)] lemma inl_v_descCochain_v (p₁ p₂ p₃ : ℤ) (h₁₂ : p₁ + (-1) = p₂) (h₂₃ : p₂ + n = p₃) : (inl φ).v p₁ p₂ h₁₂ ≫ (descCochain φ α β h).v p₂ p₃ h₂₃ = α.v p₁ p₃ (by rw [← h₂₃, ← h₁₂, ← h, add_comm m, add_assoc, neg_add_cancel_left]) := by simpa only [Cochain.comp_v _ _ (show -1 + n = m by omega) p₁ p₂ p₃ (by omega) (by omega)] using Cochain.congr_v (inl_descCochain φ α β h) p₁ p₃ (by omega) @[reassoc (attr := simp)] lemma inr_f_descCochain_v (p₁ p₂ : ℤ) (h₁₂ : p₁ + n = p₂) : (inr φ).f p₁ ≫ (descCochain φ α β h).v p₁ p₂ h₁₂ = β.v p₁ p₂ h₁₂ := by simpa only [Cochain.comp_v _ _ (zero_add n) p₁ p₁ p₂ (add_zero p₁) h₁₂, Cochain.ofHom_v] using Cochain.congr_v (inr_descCochain φ α β h) p₁ p₂ (by omega) lemma δ_descCochain (n' : ℤ) (hn' : n + 1 = n') : δ n n' (descCochain φ α β h) = (fst φ).1.comp (δ m n α + n'.negOnePow • (Cochain.ofHom φ).comp β (zero_add n)) (by omega) + (snd φ).comp (δ n n' β) (zero_add n') := by dsimp only [descCochain] simp only [δ_add, Cochain.comp_add, δ_comp (fst φ).1 α _ 2 n n' hn' (by omega) (by omega), Cocycle.δ_eq_zero, Cochain.zero_comp, smul_zero, add_zero, δ_comp (snd φ) β (zero_add n) 1 n' n' hn' (zero_add 1) hn', δ_snd, Cochain.neg_comp, smul_neg, Cochain.comp_assoc_of_second_is_zero_cochain, Cochain.comp_units_smul, ← hn', Int.negOnePow_succ, Units.neg_smul, Cochain.comp_neg] abel end /-- Given `φ : F ⟶ G`, this is the cocycle in `Cocycle (mappingCone φ) K n` that is constructed from `α : Cochain F K m` (with `m + 1 = n`) and `β : Cocycle F K n`, when a suitable cocycle relation is satisfied. -/ @[simps!] noncomputable def descCocycle {K : CochainComplex C ℤ} {n m : ℤ} (α : Cochain F K m) (β : Cocycle G K n) (h : m + 1 = n) (eq : δ m n α = n.negOnePow • (Cochain.ofHom φ).comp β.1 (zero_add n)) : Cocycle (mappingCone φ) K n := Cocycle.mk (descCochain φ α β.1 h) (n + 1) rfl (by simp [δ_descCochain _ _ _ _ _ rfl, eq, Int.negOnePow_succ]) section variable {K : CochainComplex C ℤ} /-- Given `φ : F ⟶ G`, this is the morphism `mappingCone φ ⟶ K` that is constructed from a cochain `α : Cochain F K (-1)` and a morphism `β : G ⟶ K` such that `δ (-1) 0 α = Cochain.ofHom (φ ≫ β)`. -/ noncomputable def desc (α : Cochain F K (-1)) (β : G ⟶ K) (eq : δ (-1) 0 α = Cochain.ofHom (φ ≫ β)) : mappingCone φ ⟶ K := Cocycle.homOf (descCocycle φ α (Cocycle.ofHom β) (neg_add_cancel 1) (by simp [eq])) variable (α : Cochain F K (-1)) (β : G ⟶ K) (eq : δ (-1) 0 α = Cochain.ofHom (φ ≫ β)) @[simp] lemma ofHom_desc : Cochain.ofHom (desc φ α β eq) = descCochain φ α (Cochain.ofHom β) (neg_add_cancel 1) := by simp [desc] @[reassoc (attr := simp)] lemma inl_v_desc_f (p q : ℤ) (h : p + (-1) = q) : (inl φ).v p q h ≫ (desc φ α β eq).f q = α.v p q h := by simp [desc] lemma inl_desc : (inl φ).comp (Cochain.ofHom (desc φ α β eq)) (add_zero _) = α := by simp @[reassoc (attr := simp)] lemma inr_f_desc_f (p : ℤ) : (inr φ).f p ≫ (desc φ α β eq).f p = β.f p := by simp [desc] @[reassoc (attr := simp)] lemma inr_desc : inr φ ≫ desc φ α β eq = β := by aesop_cat lemma desc_f (p q : ℤ) (hpq : p + 1 = q) : (desc φ α β eq).f p = (fst φ).1.v p q hpq ≫ α.v q p (by omega) + (snd φ).v p p (add_zero p) ≫ β.f p := by simp [ext_from_iff _ _ _ hpq] end /-- Constructor for homotopies between morphisms from a mapping cone. -/ noncomputable def descHomotopy {K : CochainComplex C ℤ} (f₁ f₂ : mappingCone φ ⟶ K) (γ₁ : Cochain F K (-2)) (γ₂ : Cochain G K (-1)) (h₁ : (inl φ).comp (Cochain.ofHom f₁) (add_zero (-1)) = δ (-2) (-1) γ₁ + (Cochain.ofHom φ).comp γ₂ (zero_add (-1)) + (inl φ).comp (Cochain.ofHom f₂) (add_zero (-1))) (h₂ : Cochain.ofHom (inr φ ≫ f₁) = δ (-1) 0 γ₂ + Cochain.ofHom (inr φ ≫ f₂)) : Homotopy f₁ f₂ := (Cochain.equivHomotopy f₁ f₂).symm ⟨descCochain φ γ₁ γ₂ (by norm_num), by simp only [Cochain.ofHom_comp] at h₂ simp [ext_cochain_from_iff _ _ _ (neg_add_cancel 1), δ_descCochain _ _ _ _ _ (neg_add_cancel 1), h₁, h₂]⟩ section variable {K : CochainComplex C ℤ} {n m : ℤ} /-- Given `φ : F ⟶ G`, this is the cochain in `Cochain (mappingCone φ) K n` that is constructed from two cochains `α : Cochain F K m` (with `m + 1 = n`) and `β : Cochain F K n`. -/ noncomputable def liftCochain (α : Cochain K F m) (β : Cochain K G n) (h : n + 1 = m) : Cochain K (mappingCone φ) n := α.comp (inl φ) (by omega) + β.comp (Cochain.ofHom (inr φ)) (add_zero n) variable (α : Cochain K F m) (β : Cochain K G n) (h : n + 1 = m) @[simp] lemma liftCochain_fst : (liftCochain φ α β h).comp (fst φ).1 h = α := by simp [liftCochain] @[simp] lemma liftCochain_snd : (liftCochain φ α β h).comp (snd φ) (add_zero n) = β := by simp [liftCochain] @[reassoc (attr := simp)] lemma liftCochain_v_fst_v (p₁ p₂ p₃ : ℤ) (h₁₂ : p₁ + n = p₂) (h₂₃ : p₂ + 1 = p₃) : (liftCochain φ α β h).v p₁ p₂ h₁₂ ≫ (fst φ).1.v p₂ p₃ h₂₃ = α.v p₁ p₃ (by omega) := by simpa only [Cochain.comp_v _ _ h p₁ p₂ p₃ h₁₂ h₂₃] using Cochain.congr_v (liftCochain_fst φ α β h) p₁ p₃ (by omega) @[reassoc (attr := simp)] lemma liftCochain_v_snd_v (p₁ p₂ : ℤ) (h₁₂ : p₁ + n = p₂) : (liftCochain φ α β h).v p₁ p₂ h₁₂ ≫ (snd φ).v p₂ p₂ (add_zero p₂) = β.v p₁ p₂ h₁₂ := by simpa only [Cochain.comp_v _ _ (add_zero n) p₁ p₂ p₂ h₁₂ (add_zero p₂)] using Cochain.congr_v (liftCochain_snd φ α β h) p₁ p₂ (by omega) lemma δ_liftCochain (m' : ℤ) (hm' : m + 1 = m') : δ n m (liftCochain φ α β h) = -(δ m m' α).comp (inl φ) (by omega) + (δ n m β + α.comp (Cochain.ofHom φ) (add_zero m)).comp (Cochain.ofHom (inr φ)) (add_zero m) := by dsimp only [liftCochain] simp only [δ_add, δ_comp α (inl φ) _ m' _ _ h hm' (neg_add_cancel 1), δ_comp_zero_cochain _ _ _ h, δ_inl, Cochain.ofHom_comp, Int.negOnePow_neg, Int.negOnePow_one, Units.neg_smul, one_smul, δ_ofHom, Cochain.comp_zero, zero_add, Cochain.add_comp, Cochain.comp_assoc_of_second_is_zero_cochain] abel end /-- Given `φ : F ⟶ G`, this is the cocycle in `Cocycle K (mappingCone φ) n` that is constructed from `α : Cochain K F m` (with `n + 1 = m`) and `β : Cocycle K G n`, when a suitable cocycle relation is satisfied. -/ @[simps!] noncomputable def liftCocycle {K : CochainComplex C ℤ} {n m : ℤ} (α : Cocycle K F m) (β : Cochain K G n) (h : n + 1 = m) (eq : δ n m β + α.1.comp (Cochain.ofHom φ) (add_zero m) = 0) : Cocycle K (mappingCone φ) n := Cocycle.mk (liftCochain φ α β h) m h (by simp only [δ_liftCochain φ α β h (m+1) rfl, eq, Cocycle.δ_eq_zero, Cochain.zero_comp, neg_zero, add_zero]) section variable {K : CochainComplex C ℤ} (α : Cocycle K F 1) (β : Cochain K G 0) (eq : δ 0 1 β + α.1.comp (Cochain.ofHom φ) (add_zero 1) = 0) /-- Given `φ : F ⟶ G`, this is the morphism `K ⟶ mappingCone φ` that is constructed from a cocycle `α : Cochain K F 1` and a cochain `β : Cochain K G 0` when a suitable cocycle relation is satisfied. -/ noncomputable def lift : K ⟶ mappingCone φ := Cocycle.homOf (liftCocycle φ α β (zero_add 1) eq) @[simp] lemma ofHom_lift : Cochain.ofHom (lift φ α β eq) = liftCochain φ α β (zero_add 1) := by simp only [lift, Cocycle.cochain_ofHom_homOf_eq_coe, liftCocycle_coe]
@[reassoc (attr := simp)] lemma lift_f_fst_v (p q : ℤ) (hpq : p + 1 = q) : (lift φ α β eq).f p ≫ (fst φ).1.v p q hpq = α.1.v p q hpq := by simp [lift]
Mathlib/Algebra/Homology/HomotopyCategory/MappingCone.lean
483
487
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Fin.Tuple.Basic /-! # Lists from functions Theorems and lemmas for dealing with `List.ofFn`, which converts a function on `Fin n` to a list of length `n`. ## Main Statements The main statements pertain to lists generated using `List.ofFn` - `List.get?_ofFn`, which tells us the nth element of such a list - `List.equivSigmaTuple`, which is an `Equiv` between lists and the functions that generate them via `List.ofFn`. -/ assert_not_exists Monoid universe u variable {α : Type u} open Nat namespace List theorem get_ofFn {n} (f : Fin n → α) (i) : get (ofFn f) i = f (Fin.cast (by simp) i) := by simp; congr @[deprecated (since := "2025-02-15")] alias get?_ofFn := List.getElem?_ofFn @[simp] theorem map_ofFn {β : Type*} {n : ℕ} (f : Fin n → α) (g : α → β) : map g (ofFn f) = ofFn (g ∘ f) := ext_get (by simp) fun i h h' => by simp @[congr] theorem ofFn_congr {m n : ℕ} (h : m = n) (f : Fin m → α) : ofFn f = ofFn fun i : Fin n => f (Fin.cast h.symm i) := by subst h simp_rw [Fin.cast_refl, id] theorem ofFn_succ' {n} (f : Fin (succ n) → α) : ofFn f = (ofFn fun i => f (Fin.castSucc i)).concat (f (Fin.last _)) := by induction' n with n IH · rw [ofFn_zero, concat_nil, ofFn_succ, ofFn_zero] rfl · rw [ofFn_succ, IH, ofFn_succ, concat_cons, Fin.castSucc_zero] congr /-- Note this matches the convention of `List.ofFn_succ'`, putting the `Fin m` elements first. -/ theorem ofFn_add {m n} (f : Fin (m + n) → α) : List.ofFn f = (List.ofFn fun i => f (Fin.castAdd n i)) ++ List.ofFn fun j => f (Fin.natAdd m j) := by induction' n with n IH · rw [ofFn_zero, append_nil, Fin.castAdd_zero, Fin.cast_refl] rfl · rw [ofFn_succ', ofFn_succ', IH, append_concat] rfl @[simp] theorem ofFn_fin_append {m n} (a : Fin m → α) (b : Fin n → α) : List.ofFn (Fin.append a b) = List.ofFn a ++ List.ofFn b := by simp_rw [ofFn_add, Fin.append_left, Fin.append_right] /-- This breaks a list of `m*n` items into `m` groups each containing `n` elements. -/ theorem ofFn_mul {m n} (f : Fin (m * n) → α) : List.ofFn f = List.flatten (List.ofFn fun i : Fin m => List.ofFn fun j : Fin n => f ⟨i * n + j, calc ↑i * n + j < (i + 1) * n := (Nat.add_lt_add_left j.prop _).trans_eq (by rw [Nat.add_mul, Nat.one_mul]) _ ≤ _ := Nat.mul_le_mul_right _ i.prop⟩) := by induction' m with m IH · simp [ofFn_zero, Nat.zero_mul, ofFn_zero, flatten] · simp_rw [ofFn_succ', succ_mul] simp [flatten_concat, ofFn_add, IH] rfl /-- This breaks a list of `m*n` items into `n` groups each containing `m` elements. -/ theorem ofFn_mul' {m n} (f : Fin (m * n) → α) : List.ofFn f = List.flatten (List.ofFn fun i : Fin n => List.ofFn fun j : Fin m => f ⟨m * i + j, calc m * i + j < m * (i + 1) := (Nat.add_lt_add_left j.prop _).trans_eq (by rw [Nat.mul_add, Nat.mul_one]) _ ≤ _ := Nat.mul_le_mul_left _ i.prop⟩) := by simp_rw [m.mul_comm, ofFn_mul, Fin.cast_mk] @[simp] theorem ofFn_get : ∀ l : List α, (ofFn (get l)) = l | [] => by rw [ofFn_zero] | a :: l => by rw [ofFn_succ] congr exact ofFn_get l @[simp] theorem ofFn_getElem : ∀ l : List α, (ofFn (fun i : Fin l.length => l[(i : Nat)])) = l | [] => by rw [ofFn_zero] | a :: l => by rw [ofFn_succ] congr exact ofFn_get l @[simp] theorem ofFn_getElem_eq_map {β : Type*} (l : List α) (f : α → β) : ofFn (fun i : Fin l.length => f <| l[(i : Nat)]) = l.map f := by rw [← Function.comp_def, ← map_ofFn, ofFn_getElem] -- Note there is a now another `mem_ofFn` defined in Lean, with an existential on the RHS, -- which is marked as a simp lemma. theorem mem_ofFn' {n} (f : Fin n → α) (a : α) : a ∈ ofFn f ↔ a ∈ Set.range f := by simp only [mem_iff_get, Set.mem_range, get_ofFn] exact ⟨fun ⟨i, hi⟩ => ⟨Fin.cast (by simp) i, hi⟩, fun ⟨i, hi⟩ => ⟨Fin.cast (by simp) i, hi⟩⟩ theorem forall_mem_ofFn_iff {n : ℕ} {f : Fin n → α} {P : α → Prop} : (∀ i ∈ ofFn f, P i) ↔ ∀ j : Fin n, P (f j) := by simp @[simp] theorem ofFn_const : ∀ (n : ℕ) (c : α), (ofFn fun _ : Fin n => c) = replicate n c | 0, c => by rw [ofFn_zero, replicate_zero] | n+1, c => by rw [replicate, ← ofFn_const n]; simp @[simp] theorem ofFn_fin_repeat {m} (a : Fin m → α) (n : ℕ) : List.ofFn (Fin.repeat n a) = (List.replicate n (List.ofFn a)).flatten := by simp_rw [ofFn_mul, ← ofFn_const, Fin.repeat, Fin.modNat, Nat.add_comm, Nat.add_mul_mod_self_right, Nat.mod_eq_of_lt (Fin.is_lt _)] @[simp] theorem pairwise_ofFn {R : α → α → Prop} {n} {f : Fin n → α} : (ofFn f).Pairwise R ↔ ∀ ⦃i j⦄, i < j → R (f i) (f j) := by simp only [pairwise_iff_getElem, length_ofFn, List.getElem_ofFn, (Fin.rightInverse_cast length_ofFn).surjective.forall, Fin.forall_iff, Fin.cast_mk, Fin.mk_lt_mk, forall_comm (α := (_ : Prop)) (β := ℕ)] lemma getLast_ofFn_succ {n : ℕ} (f : Fin n.succ → α) : (ofFn f).getLast (mt ofFn_eq_nil_iff.1 (Nat.succ_ne_zero _)) = f (Fin.last _) := getLast_ofFn _ @[deprecated getLast_ofFn (since := "2024-11-06")] theorem last_ofFn {n : ℕ} (f : Fin n → α) (h : ofFn f ≠ []) (hn : n - 1 < n := Nat.pred_lt <| ofFn_eq_nil_iff.not.mp h) : getLast (ofFn f) h = f ⟨n - 1, hn⟩ := by simp [getLast_eq_getElem] @[deprecated getLast_ofFn_succ (since := "2024-11-06")] theorem last_ofFn_succ {n : ℕ} (f : Fin n.succ → α) (h : ofFn f ≠ [] := mt ofFn_eq_nil_iff.mp (Nat.succ_ne_zero _)) : getLast (ofFn f) h = f (Fin.last _) := getLast_ofFn_succ _ lemma ofFn_cons {n} (a : α) (f : Fin n → α) : ofFn (Fin.cons a f) = a :: ofFn f := by rw [ofFn_succ] rfl lemma find?_ofFn_eq_some {n} {f : Fin n → α} {p : α → Bool} {b : α} : (ofFn f).find? p = some b ↔ p b = true ∧ ∃ i, f i = b ∧ ∀ j < i, ¬(p (f j) = true) := by rw [find?_eq_some_iff_getElem] exact ⟨fun ⟨hpb, i, hi, hfb, h⟩ ↦ ⟨hpb, ⟨⟨i, length_ofFn (f := f) ▸ hi⟩, by simpa using hfb, fun j hj ↦ by simpa using h j hj⟩⟩, fun ⟨hpb, i, hfb, h⟩ ↦ ⟨hpb, ⟨i, (length_ofFn (f := f)).symm ▸ i.isLt, by simpa using hfb, fun j hj ↦ by simpa using h ⟨j, by omega⟩ (by simpa using hj)⟩⟩⟩ lemma find?_ofFn_eq_some_of_injective {n} {f : Fin n → α} {p : α → Bool} {i : Fin n} (h : Function.Injective f) : (ofFn f).find? p = some (f i) ↔ p (f i) = true ∧ ∀ j < i, ¬(p (f j) = true) := by simp only [find?_ofFn_eq_some, h.eq_iff, Bool.not_eq_true, exists_eq_left] /-- Lists are equivalent to the sigma type of tuples of a given length. -/ @[simps] def equivSigmaTuple : List α ≃ Σn, Fin n → α where toFun l := ⟨l.length, l.get⟩ invFun f := List.ofFn f.2 left_inv := List.ofFn_get right_inv := fun ⟨_, f⟩ => Fin.sigma_eq_of_eq_comp_cast length_ofFn <| funext fun i => get_ofFn f i /-- A recursor for lists that expands a list into a function mapping to its elements. This can be used with `induction l using List.ofFnRec`. -/ @[elab_as_elim] def ofFnRec {C : List α → Sort*} (h : ∀ (n) (f : Fin n → α), C (List.ofFn f)) (l : List α) : C l := cast (congr_arg C l.ofFn_get) <| h l.length l.get @[simp] theorem ofFnRec_ofFn {C : List α → Sort*} (h : ∀ (n) (f : Fin n → α), C (List.ofFn f)) {n : ℕ} (f : Fin n → α) : @ofFnRec _ C h (List.ofFn f) = h _ f := equivSigmaTuple.rightInverse_symm.cast_eq (fun s => h s.1 s.2) ⟨n, f⟩ theorem exists_iff_exists_tuple {P : List α → Prop} : (∃ l : List α, P l) ↔ ∃ (n : _) (f : Fin n → α), P (List.ofFn f) := equivSigmaTuple.symm.surjective.exists.trans Sigma.exists theorem forall_iff_forall_tuple {P : List α → Prop} : (∀ l : List α, P l) ↔ ∀ (n) (f : Fin n → α), P (List.ofFn f) := equivSigmaTuple.symm.surjective.forall.trans Sigma.forall /-- `Fin.sigma_eq_iff_eq_comp_cast` may be useful to work with the RHS of this expression. -/ theorem ofFn_inj' {m n : ℕ} {f : Fin m → α} {g : Fin n → α} : ofFn f = ofFn g ↔ (⟨m, f⟩ : Σn, Fin n → α) = ⟨n, g⟩ := Iff.symm <| equivSigmaTuple.symm.injective.eq_iff.symm /-- Note we can only state this when the two functions are indexed by defeq `n`. -/ theorem ofFn_injective {n : ℕ} : Function.Injective (ofFn : (Fin n → α) → List α) := fun f g h => eq_of_heq <| by rw [ofFn_inj'] at h; cases h; rfl /-- A special case of `List.ofFn_inj` for when the two functions are indexed by defeq `n`. -/ @[simp] theorem ofFn_inj {n : ℕ} {f g : Fin n → α} : ofFn f = ofFn g ↔ f = g := ofFn_injective.eq_iff end List
Mathlib/Data/List/OfFn.lean
233
235
/- Copyright (c) 2022 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Jireh Loreaux -/ import Mathlib.Algebra.Algebra.Subalgebra.Lattice import Mathlib.Algebra.Algebra.Tower import Mathlib.Algebra.Star.Module import Mathlib.Algebra.Star.NonUnitalSubalgebra /-! # Star subalgebras A *-subalgebra is a subalgebra of a *-algebra which is closed under *. The centralizer of a *-closed set is a *-subalgebra. -/ universe u v /-- A *-subalgebra is a subalgebra of a *-algebra which is closed under *. -/ structure StarSubalgebra (R : Type u) (A : Type v) [CommSemiring R] [StarRing R] [Semiring A] [StarRing A] [Algebra R A] [StarModule R A] : Type v extends Subalgebra R A where /-- The `carrier` is closed under the `star` operation. -/ star_mem' {a} : a ∈ carrier → star a ∈ carrier namespace StarSubalgebra /-- Forgetting that a *-subalgebra is closed under *. -/ add_decl_doc StarSubalgebra.toSubalgebra variable {F R A B C : Type*} [CommSemiring R] [StarRing R] variable [Semiring A] [StarRing A] [Algebra R A] [StarModule R A] variable [Semiring B] [StarRing B] [Algebra R B] [StarModule R B] variable [Semiring C] [StarRing C] [Algebra R C] [StarModule R C] instance setLike : SetLike (StarSubalgebra R A) A where coe S := S.carrier coe_injective' p q h := by obtain ⟨⟨⟨⟨⟨_, _⟩, _⟩, _⟩, _⟩, _⟩ := p; cases q; congr /-- The actual `StarSubalgebra` obtained from an element of a type satisfying `SubsemiringClass`, `SMulMemClass` and `StarMemClass`. -/ @[simps] def ofClass {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [StarRing R] [StarRing A] [StarModule R A] [SetLike S A] [SubsemiringClass S A] [SMulMemClass S R A] [StarMemClass S A] (s : S) : StarSubalgebra R A where carrier := s add_mem' := add_mem zero_mem' := zero_mem _ mul_mem' := mul_mem one_mem' := one_mem _ algebraMap_mem' := algebraMap_mem s star_mem' := star_mem instance (priority := 100) : CanLift (Set A) (StarSubalgebra R A) (↑) (fun s ↦ (∀ {x y}, x ∈ s → y ∈ s → x + y ∈ s) ∧ (∀ {x y}, x ∈ s → y ∈ s → x * y ∈ s) ∧ (∀ (r : R), algebraMap R A r ∈ s) ∧ ∀ {x}, x ∈ s → star x ∈ s) where prf s h := ⟨ { carrier := s zero_mem' := by simpa using h.2.2.1 0 add_mem' := h.1 one_mem' := by simpa using h.2.2.1 1 mul_mem' := h.2.1 algebraMap_mem' := h.2.2.1 star_mem' := h.2.2.2 }, rfl ⟩ instance starMemClass : StarMemClass (StarSubalgebra R A) A where star_mem {s} := s.star_mem' instance subsemiringClass : SubsemiringClass (StarSubalgebra R A) A where add_mem {s} := s.add_mem' mul_mem {s} := s.mul_mem' one_mem {s} := s.one_mem' zero_mem {s} := s.zero_mem' instance smulMemClass : SMulMemClass (StarSubalgebra R A) R A where smul_mem {s} r a (ha : a ∈ s.toSubalgebra) := (SMulMemClass.smul_mem r ha : r • a ∈ s.toSubalgebra) instance subringClass {R A} [CommRing R] [StarRing R] [Ring A] [StarRing A] [Algebra R A] [StarModule R A] : SubringClass (StarSubalgebra R A) A where neg_mem {s a} ha := show -a ∈ s.toSubalgebra from neg_mem ha -- this uses the `Star` instance `s` inherits from `StarMemClass (StarSubalgebra R A) A` instance starRing (s : StarSubalgebra R A) : StarRing s := { StarMemClass.instStar s with star_involutive := fun r => Subtype.ext (star_star (r : A)) star_mul := fun r₁ r₂ => Subtype.ext (star_mul (r₁ : A) (r₂ : A)) star_add := fun r₁ r₂ => Subtype.ext (star_add (r₁ : A) (r₂ : A)) } instance algebra (s : StarSubalgebra R A) : Algebra R s := s.toSubalgebra.algebra' instance starModule (s : StarSubalgebra R A) : StarModule R s where star_smul r a := Subtype.ext (star_smul r (a : A)) /-- Turn a `StarSubalgebra` into a `NonUnitalStarSubalgebra` by forgetting that it contains `1`. -/ def toNonUnitalStarSubalgebra (S : StarSubalgebra R A) : NonUnitalStarSubalgebra R A where __ := S smul_mem' r _x hx := S.smul_mem hx r lemma one_mem_toNonUnitalStarSubalgebra (S : StarSubalgebra R A) : 1 ∈ S.toNonUnitalStarSubalgebra := S.one_mem' theorem mem_carrier {s : StarSubalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl @[ext] theorem ext {S T : StarSubalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h @[simp] lemma coe_mk (S : Subalgebra R A) (h) : ((⟨S, h⟩ : StarSubalgebra R A) : Set A) = S := rfl @[simp] theorem mem_toSubalgebra {S : StarSubalgebra R A} {x} : x ∈ S.toSubalgebra ↔ x ∈ S := Iff.rfl @[simp] theorem coe_toSubalgebra (S : StarSubalgebra R A) : (S.toSubalgebra : Set A) = S := rfl theorem toSubalgebra_injective : Function.Injective (toSubalgebra : StarSubalgebra R A → Subalgebra R A) := fun S T h => ext fun x => by rw [← mem_toSubalgebra, ← mem_toSubalgebra, h] theorem toSubalgebra_inj {S U : StarSubalgebra R A} : S.toSubalgebra = U.toSubalgebra ↔ S = U := toSubalgebra_injective.eq_iff theorem toSubalgebra_le_iff {S₁ S₂ : StarSubalgebra R A} : S₁.toSubalgebra ≤ S₂.toSubalgebra ↔ S₁ ≤ S₂ := Iff.rfl /-- Copy of a star subalgebra with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (S : StarSubalgebra R A) (s : Set A) (hs : s = ↑S) : StarSubalgebra R A where toSubalgebra := Subalgebra.copy S.toSubalgebra s hs star_mem' {a} ha := hs ▸ S.star_mem' (by simpa [hs] using ha) @[simp] theorem coe_copy (S : StarSubalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s := rfl theorem copy_eq (S : StarSubalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S := SetLike.coe_injective hs variable (S : StarSubalgebra R A) protected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S := S.algebraMap_mem' r theorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubalgebra.toSubsemiring := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r theorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r theorem range_le : Set.range (algebraMap R A) ≤ S := S.range_subset protected theorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem r) hx /-- Embedding of a subalgebra into the algebra. -/ def subtype : S →⋆ₐ[R] A where toFun := ((↑) : S → A) map_one' := rfl map_mul' _ _ := rfl map_zero' := rfl map_add' _ _ := rfl commutes' _ := rfl map_star' _ := rfl @[simp] theorem coe_subtype : (S.subtype : S → A) = Subtype.val := rfl theorem subtype_apply (x : S) : S.subtype x = (x : A) := rfl @[simp] theorem toSubalgebra_subtype : S.toSubalgebra.val = S.subtype.toAlgHom := rfl /-- The inclusion map between `StarSubalgebra`s given by `Subtype.map id` as a `StarAlgHom`. -/ @[simps] def inclusion {S₁ S₂ : StarSubalgebra R A} (h : S₁ ≤ S₂) : S₁ →⋆ₐ[R] S₂ where toFun := Subtype.map id h map_one' := rfl map_mul' _ _ := rfl map_zero' := rfl map_add' _ _ := rfl commutes' _ := rfl map_star' _ := rfl theorem inclusion_injective {S₁ S₂ : StarSubalgebra R A} (h : S₁ ≤ S₂) : Function.Injective <| inclusion h := Set.inclusion_injective h @[simp] theorem subtype_comp_inclusion {S₁ S₂ : StarSubalgebra R A} (h : S₁ ≤ S₂) : S₂.subtype.comp (inclusion h) = S₁.subtype := rfl section Map /-- Transport a star subalgebra via a star algebra homomorphism. -/ def map (f : A →⋆ₐ[R] B) (S : StarSubalgebra R A) : StarSubalgebra R B := { S.toSubalgebra.map f.toAlgHom with star_mem' := by rintro _ ⟨a, ha, rfl⟩ exact map_star f a ▸ Set.mem_image_of_mem _ (S.star_mem' ha) } theorem map_mono {S₁ S₂ : StarSubalgebra R A} {f : A →⋆ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f := Set.image_subset f theorem map_injective {f : A →⋆ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) := fun _S₁ _S₂ ih => ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih @[simp] theorem map_id (S : StarSubalgebra R A) : S.map (StarAlgHom.id R A) = S := SetLike.coe_injective <| Set.image_id _ theorem map_map (S : StarSubalgebra R A) (g : B →⋆ₐ[R] C) (f : A →⋆ₐ[R] B) : (S.map f).map g = S.map (g.comp f) := SetLike.coe_injective <| Set.image_image _ _ _ @[simp] theorem mem_map {S : StarSubalgebra R A} {f : A →⋆ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y := Subsemiring.mem_map theorem map_toSubalgebra {S : StarSubalgebra R A} {f : A →⋆ₐ[R] B} : (S.map f).toSubalgebra = S.toSubalgebra.map f.toAlgHom := SetLike.coe_injective rfl @[simp] theorem coe_map (S : StarSubalgebra R A) (f : A →⋆ₐ[R] B) : (S.map f : Set B) = f '' S := rfl /-- Preimage of a star subalgebra under a star algebra homomorphism. -/ def comap (f : A →⋆ₐ[R] B) (S : StarSubalgebra R B) : StarSubalgebra R A := { S.toSubalgebra.comap f.toAlgHom with star_mem' := @fun a ha => show f (star a) ∈ S from (map_star f a).symm ▸ star_mem ha } theorem map_le_iff_le_comap {S : StarSubalgebra R A} {f : A →⋆ₐ[R] B} {U : StarSubalgebra R B} : map f S ≤ U ↔ S ≤ comap f U := Set.image_subset_iff theorem gc_map_comap (f : A →⋆ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le_iff_le_comap theorem comap_mono {S₁ S₂ : StarSubalgebra R B} {f : A →⋆ₐ[R] B} : S₁ ≤ S₂ → S₁.comap f ≤ S₂.comap f := Set.preimage_mono theorem comap_injective {f : A →⋆ₐ[R] B} (hf : Function.Surjective f) : Function.Injective (comap f) := fun _S₁ _S₂ h => ext fun b => let ⟨x, hx⟩ := hf b let this := SetLike.ext_iff.1 h x hx ▸ this @[simp] theorem comap_id (S : StarSubalgebra R A) : S.comap (StarAlgHom.id R A) = S := SetLike.coe_injective <| Set.preimage_id theorem comap_comap (S : StarSubalgebra R C) (g : B →⋆ₐ[R] C) (f : A →⋆ₐ[R] B) : (S.comap g).comap f = S.comap (g.comp f) := SetLike.coe_injective <| by exact Set.preimage_preimage @[simp] theorem mem_comap (S : StarSubalgebra R B) (f : A →⋆ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S := Iff.rfl @[simp, norm_cast] theorem coe_comap (S : StarSubalgebra R B) (f : A →⋆ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) := rfl end Map section Centralizer variable (R) /-- The centralizer, or commutant, of the star-closure of a set as a star subalgebra. -/ def centralizer (s : Set A) : StarSubalgebra R A where toSubalgebra := Subalgebra.centralizer R (s ∪ star s) star_mem' := Set.star_mem_centralizer @[simp, norm_cast] theorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = (s ∪ star s).centralizer := rfl open Set in nonrec theorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g ∧ star g * z = z * star g := by simp [← SetLike.mem_coe, centralizer_union, ← image_star, mem_centralizer_iff, forall_and] theorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s := Set.centralizer_subset (Set.union_subset_union h <| Set.preimage_mono h) theorem centralizer_toSubalgebra (s : Set A) : (centralizer R s).toSubalgebra = Subalgebra.centralizer R (s ∪ star s):= rfl theorem coe_centralizer_centralizer (s : Set A) : (centralizer R (centralizer R s : Set A)) = (s ∪ star s).centralizer.centralizer := by rw [coe_centralizer, StarMemClass.star_coe_eq, Set.union_self, coe_centralizer] end Centralizer end StarSubalgebra /-! ### The star closure of a subalgebra -/ namespace Subalgebra open Pointwise variable {F R A B : Type*} [CommSemiring R] [StarRing R] variable [Semiring A] [Algebra R A] [StarRing A] [StarModule R A] variable [Semiring B] [Algebra R B] [StarRing B] [StarModule R B] /-- The pointwise `star` of a subalgebra is a subalgebra. -/ instance involutiveStar : InvolutiveStar (Subalgebra R A) where star S := { carrier := star S.carrier mul_mem' := fun {x y} hx hy => by simp only [Set.mem_star, Subalgebra.mem_carrier] at * exact (star_mul x y).symm ▸ mul_mem hy hx one_mem' := Set.mem_star.mp ((star_one A).symm ▸ one_mem S : star (1 : A) ∈ S) add_mem' := fun {x y} hx hy => by simp only [Set.mem_star, Subalgebra.mem_carrier] at * exact (star_add x y).symm ▸ add_mem hx hy zero_mem' := Set.mem_star.mp ((star_zero A).symm ▸ zero_mem S : star (0 : A) ∈ S) algebraMap_mem' := fun r => by simpa only [Set.mem_star, Subalgebra.mem_carrier, ← algebraMap_star_comm] using S.algebraMap_mem (star r) } star_involutive S := Subalgebra.ext fun x => ⟨fun hx => star_star x ▸ hx, fun hx => ((star_star x).symm ▸ hx : star (star x) ∈ S)⟩ @[simp] theorem mem_star_iff (S : Subalgebra R A) (x : A) : x ∈ star S ↔ star x ∈ S := Iff.rfl theorem star_mem_star_iff (S : Subalgebra R A) (x : A) : star x ∈ star S ↔ x ∈ S := by simp @[simp] theorem coe_star (S : Subalgebra R A) : ((star S : Subalgebra R A) : Set A) = star (S : Set A) := rfl theorem star_mono : Monotone (star : Subalgebra R A → Subalgebra R A) := fun _ _ h _ hx => h hx variable (R) in /-- The star operation on `Subalgebra` commutes with `Algebra.adjoin`. -/ theorem star_adjoin_comm (s : Set A) : star (Algebra.adjoin R s) = Algebra.adjoin R (star s) := have this : ∀ t : Set A, Algebra.adjoin R (star t) ≤ star (Algebra.adjoin R t) := fun _ => Algebra.adjoin_le fun _ hx => Algebra.subset_adjoin hx le_antisymm (by simpa only [star_star] using Subalgebra.star_mono (this (star s))) (this s) /-- The `StarSubalgebra` obtained from `S : Subalgebra R A` by taking the smallest subalgebra containing both `S` and `star S`. -/ @[simps!] def starClosure (S : Subalgebra R A) : StarSubalgebra R A where toSubalgebra := S ⊔ star S star_mem' := fun {a} ha => by simp only [Subalgebra.mem_carrier, ← (@Algebra.gi R A _ _ _).l_sup_u _ _] at * rw [← mem_star_iff _ a, star_adjoin_comm, sup_comm] simpa using ha theorem starClosure_toSubalgebra (S : Subalgebra R A) : S.starClosure.toSubalgebra = S ⊔ star S := rfl theorem starClosure_le {S₁ : Subalgebra R A} {S₂ : StarSubalgebra R A} (h : S₁ ≤ S₂.toSubalgebra) : S₁.starClosure ≤ S₂ := StarSubalgebra.toSubalgebra_le_iff.1 <| sup_le h fun x hx => (star_star x ▸ star_mem (show star x ∈ S₂ from h <| (S₁.mem_star_iff _).1 hx) : x ∈ S₂) theorem starClosure_le_iff {S₁ : Subalgebra R A} {S₂ : StarSubalgebra R A} : S₁.starClosure ≤ S₂ ↔ S₁ ≤ S₂.toSubalgebra := ⟨fun h => le_sup_left.trans h, starClosure_le⟩ end Subalgebra /-! ### The star subalgebra generated by a set -/ namespace StarAlgebra open StarSubalgebra variable {F R A B : Type*} [CommSemiring R] [StarRing R] variable [Semiring A] [Algebra R A] [StarRing A] [StarModule R A] variable [Semiring B] [Algebra R B] [StarRing B] [StarModule R B] variable (R) /-- The minimal star subalgebra that contains `s`. -/ @[simps!] def adjoin (s : Set A) : StarSubalgebra R A := { Algebra.adjoin R (s ∪ star s) with star_mem' := fun hx => by rwa [Subalgebra.mem_carrier, ← Subalgebra.mem_star_iff, Subalgebra.star_adjoin_comm, Set.union_star, star_star, Set.union_comm] } theorem adjoin_eq_starClosure_adjoin (s : Set A) : adjoin R s = (Algebra.adjoin R s).starClosure := toSubalgebra_injective <| show Algebra.adjoin R (s ∪ star s) = Algebra.adjoin R s ⊔ star (Algebra.adjoin R s) from (Subalgebra.star_adjoin_comm R s).symm ▸ Algebra.adjoin_union s (star s) theorem adjoin_toSubalgebra (s : Set A) : (adjoin R s).toSubalgebra = Algebra.adjoin R (s ∪ star s) := rfl @[aesop safe 20 apply (rule_sets := [SetLike])] theorem subset_adjoin (s : Set A) : s ⊆ adjoin R s := Set.subset_union_left.trans Algebra.subset_adjoin theorem star_subset_adjoin (s : Set A) : star s ⊆ adjoin R s := Set.subset_union_right.trans Algebra.subset_adjoin theorem self_mem_adjoin_singleton (x : A) : x ∈ adjoin R ({x} : Set A) := Algebra.subset_adjoin <| Set.mem_union_left _ (Set.mem_singleton x) theorem star_self_mem_adjoin_singleton (x : A) : star x ∈ adjoin R ({x} : Set A) := star_mem <| self_mem_adjoin_singleton R x variable {R} protected theorem gc : GaloisConnection (adjoin R : Set A → StarSubalgebra R A) (↑) := by intro s S rw [← toSubalgebra_le_iff, adjoin_toSubalgebra, Algebra.adjoin_le_iff, coe_toSubalgebra] exact ⟨fun h => Set.subset_union_left.trans h, fun h => Set.union_subset h fun x hx => star_star x ▸ star_mem (show star x ∈ S from h hx)⟩ /-- Galois insertion between `adjoin` and `coe`. -/ protected def gi : GaloisInsertion (adjoin R : Set A → StarSubalgebra R A) (↑) where choice s hs := (adjoin R s).copy s <| le_antisymm (StarAlgebra.gc.le_u_l s) hs gc := StarAlgebra.gc le_l_u S := (StarAlgebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl choice_eq _ _ := StarSubalgebra.copy_eq _ _ _ theorem adjoin_le {S : StarSubalgebra R A} {s : Set A} (hs : s ⊆ S) : adjoin R s ≤ S := StarAlgebra.gc.l_le hs theorem adjoin_le_iff {S : StarSubalgebra R A} {s : Set A} : adjoin R s ≤ S ↔ s ⊆ S := StarAlgebra.gc _ _ lemma adjoin_eq (S : StarSubalgebra R A) : adjoin R (S : Set A) = S := le_antisymm (adjoin_le le_rfl) (subset_adjoin R (S : Set A)) open Submodule in lemma adjoin_eq_span (s : Set A) : Subalgebra.toSubmodule (adjoin R s).toSubalgebra = span R (Submonoid.closure (s ∪ star s)) := by rw [adjoin_toSubalgebra, Algebra.adjoin_eq_span] open Submodule in lemma adjoin_nonUnitalStarSubalgebra_eq_span (s : NonUnitalStarSubalgebra R A) : (adjoin R (s : Set A)).toSubalgebra.toSubmodule = span R {1} ⊔ s.toSubmodule := by rw [adjoin_eq_span, Submonoid.closure_eq_one_union, span_union, ← NonUnitalStarAlgebra.adjoin_eq_span, NonUnitalStarAlgebra.adjoin_eq] theorem _root_.Subalgebra.starClosure_eq_adjoin (S : Subalgebra R A) : S.starClosure = adjoin R (S : Set A) := le_antisymm (Subalgebra.starClosure_le_iff.2 <| subset_adjoin R (S : Set A)) (adjoin_le (le_sup_left : S ≤ S ⊔ star S)) /-- If some predicate holds for all `x ∈ (s : Set A)` and this predicate is closed under the `algebraMap`, addition, multiplication and star operations, then it holds for `a ∈ adjoin R s`. -/ @[elab_as_elim] theorem adjoin_induction {s : Set A} {p : (x : A) → x ∈ adjoin R s → Prop} (mem : ∀ (x) (h : x ∈ s), p x (subset_adjoin R s h)) (algebraMap : ∀ r, p (_root_.algebraMap R _ r) (_root_.algebraMap_mem _ r)) (add : ∀ x y hx hy, p x hx → p y hy → p (x + y) (add_mem hx hy)) (mul : ∀ x y hx hy, p x hx → p y hy → p (x * y) (mul_mem hx hy)) (star : ∀ x hx, p x hx → p (star x) (star_mem hx)) {a : A} (ha : a ∈ adjoin R s) : p a ha := by refine Algebra.adjoin_induction (fun x hx ↦ ?_) algebraMap add mul ha simp only [Set.mem_union, Set.mem_star] at hx obtain (hx | hx) := hx · exact mem x hx · simpa using star _ (Algebra.subset_adjoin (by simpa using Or.inl hx)) (mem _ hx) @[elab_as_elim] theorem adjoin_induction₂ {s : Set A} {p : (x y : A) → x ∈ adjoin R s → y ∈ adjoin R s → Prop} (mem_mem : ∀ (x) (y) (hx : x ∈ s) (hy : y ∈ s), p x y (subset_adjoin R s hx) (subset_adjoin R s hy)) (algebraMap_both : ∀ r₁ r₂, p (algebraMap R A r₁) (algebraMap R A r₂) (_root_.algebraMap_mem _ r₁) (_root_.algebraMap_mem _ r₂)) (algebraMap_left : ∀ (r) (x) (hx : x ∈ s), p (algebraMap R A r) x (_root_.algebraMap_mem _ r) (subset_adjoin R s hx)) (algebraMap_right : ∀ (r) (x) (hx : x ∈ s), p x (algebraMap R A r) (subset_adjoin R s hx) (_root_.algebraMap_mem _ r)) (add_left : ∀ x y z hx hy hz, p x z hx hz → p y z hy hz → p (x + y) z (add_mem hx hy) hz) (add_right : ∀ x y z hx hy hz, p x y hx hy → p x z hx hz → p x (y + z) hx (add_mem hy hz)) (mul_left : ∀ x y z hx hy hz, p x z hx hz → p y z hy hz → p (x * y) z (mul_mem hx hy) hz) (mul_right : ∀ x y z hx hy hz, p x y hx hy → p x z hx hz → p x (y * z) hx (mul_mem hy hz)) (star_left : ∀ x y hx hy, p x y hx hy → p (star x) y (star_mem hx) hy) (star_right : ∀ x y hx hy, p x y hx hy → p x (star y) hx (star_mem hy)) {a b : A} (ha : a ∈ adjoin R s) (hb : b ∈ adjoin R s) : p a b ha hb := by induction hb using adjoin_induction with | mem z hz => induction ha using adjoin_induction with | mem _ h => exact mem_mem _ _ h hz | algebraMap _ => exact algebraMap_left _ _ hz | mul _ _ _ _ h₁ h₂ => exact mul_left _ _ _ _ _ _ h₁ h₂ | add _ _ _ _ h₁ h₂ => exact add_left _ _ _ _ _ _ h₁ h₂ | star _ _ h => exact star_left _ _ _ _ h | algebraMap r =>
induction ha using adjoin_induction with | mem _ h => exact algebraMap_right _ _ h | algebraMap _ => exact algebraMap_both _ _ | mul _ _ _ _ h₁ h₂ => exact mul_left _ _ _ _ _ _ h₁ h₂ | add _ _ _ _ h₁ h₂ => exact add_left _ _ _ _ _ _ h₁ h₂ | star _ _ h => exact star_left _ _ _ _ h | mul _ _ _ _ h₁ h₂ => exact mul_right _ _ _ _ _ _ h₁ h₂ | add _ _ _ _ h₁ h₂ => exact add_right _ _ _ _ _ _ h₁ h₂ | star _ _ h => exact star_right _ _ _ _ h /-- The difference with `StarSubalgebra.adjoin_induction` is that this acts on the subtype. -/ @[elab_as_elim] theorem adjoin_induction_subtype {s : Set A} {p : adjoin R s → Prop} (a : adjoin R s) (mem : ∀ (x) (h : x ∈ s), p ⟨x, subset_adjoin R s h⟩) (algebraMap : ∀ r, p (algebraMap R _ r)) (add : ∀ x y, p x → p y → p (x + y)) (mul : ∀ x y, p x → p y → p (x * y)) (star : ∀ x, p x → p (star x)) : p a := Subtype.recOn a fun b hb => by induction hb using adjoin_induction with | mem _ h => exact mem _ h | algebraMap _ => exact algebraMap _ | mul _ _ _ _ h₁ h₂ => exact mul _ _ h₁ h₂ | add _ _ _ _ h₁ h₂ => exact add _ _ h₁ h₂ | star _ _ h => exact star _ h variable (R)
Mathlib/Algebra/Star/Subalgebra.lean
519
543
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl -/ import Mathlib.MeasureTheory.Integral.Lebesgue.Basic import Mathlib.MeasureTheory.Integral.Lebesgue.Countable import Mathlib.MeasureTheory.Integral.Lebesgue.MeasurePreserving import Mathlib.MeasureTheory.Integral.Lebesgue.Norm deprecated_module (since := "2025-04-13")
Mathlib/MeasureTheory/Integral/Lebesgue.lean
928
933
/- 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] @[rclike_simps] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11119): was `simp` theorem normSq_inv (z : K) : normSq z⁻¹ = (normSq z)⁻¹ := map_inv₀ normSq z @[rclike_simps] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11119): was `simp` theorem normSq_div (z w : K) : normSq (z / w) = normSq z / normSq w := map_div₀ normSq z w @[simp 1100, rclike_simps] theorem norm_conj (z : K) : ‖conj z‖ = ‖z‖ := by simp only [← sqrt_normSq_eq_norm, normSq_conj] @[simp, rclike_simps] lemma nnnorm_conj (z : K) : ‖conj z‖₊ = ‖z‖₊ := by simp [nnnorm] @[simp, rclike_simps] lemma enorm_conj (z : K) : ‖conj z‖ₑ = ‖z‖ₑ := by simp [enorm] instance (priority := 100) : CStarRing K where norm_mul_self_le x := le_of_eq <| ((norm_mul _ _).trans <| congr_arg (· * ‖x‖) (norm_conj _)).symm instance : StarModule ℝ K where star_smul r a := by apply RCLike.ext <;> simp [RCLike.smul_re, RCLike.smul_im] /-! ### Cast lemmas -/ @[rclike_simps, norm_cast] theorem ofReal_natCast (n : ℕ) : ((n : ℝ) : K) = n := map_natCast (algebraMap ℝ K) n @[rclike_simps, norm_cast] lemma ofReal_nnratCast (q : ℚ≥0) : ((q : ℝ) : K) = q := map_nnratCast (algebraMap ℝ K) _ @[simp, rclike_simps] -- Porting note: removed `norm_cast` theorem natCast_re (n : ℕ) : re (n : K) = n := by rw [← ofReal_natCast, ofReal_re] @[simp, rclike_simps, norm_cast] theorem natCast_im (n : ℕ) : im (n : K) = 0 := by rw [← ofReal_natCast, ofReal_im] @[simp, rclike_simps] theorem ofNat_re (n : ℕ) [n.AtLeastTwo] : re (ofNat(n) : K) = ofNat(n) := natCast_re n @[simp, rclike_simps] theorem ofNat_im (n : ℕ) [n.AtLeastTwo] : im (ofNat(n) : K) = 0 := natCast_im n @[rclike_simps, norm_cast] theorem ofReal_ofNat (n : ℕ) [n.AtLeastTwo] : ((ofNat(n) : ℝ) : K) = ofNat(n) := ofReal_natCast n theorem ofNat_mul_re (n : ℕ) [n.AtLeastTwo] (z : K) : re (ofNat(n) * z) = ofNat(n) * re z := by rw [← ofReal_ofNat, re_ofReal_mul] theorem ofNat_mul_im (n : ℕ) [n.AtLeastTwo] (z : K) : im (ofNat(n) * z) = ofNat(n) * im z := by rw [← ofReal_ofNat, im_ofReal_mul] @[rclike_simps, norm_cast] theorem ofReal_intCast (n : ℤ) : ((n : ℝ) : K) = n := map_intCast _ n @[simp, rclike_simps] -- Porting note: removed `norm_cast` theorem intCast_re (n : ℤ) : re (n : K) = n := by rw [← ofReal_intCast, ofReal_re] @[simp, rclike_simps, norm_cast] theorem intCast_im (n : ℤ) : im (n : K) = 0 := by rw [← ofReal_intCast, ofReal_im] @[rclike_simps, norm_cast] theorem ofReal_ratCast (n : ℚ) : ((n : ℝ) : K) = n := map_ratCast _ n @[simp, rclike_simps] -- Porting note: removed `norm_cast` theorem ratCast_re (q : ℚ) : re (q : K) = q := by rw [← ofReal_ratCast, ofReal_re] @[simp, rclike_simps, norm_cast] theorem ratCast_im (q : ℚ) : im (q : K) = 0 := by rw [← ofReal_ratCast, ofReal_im] /-! ### Norm -/ theorem norm_of_nonneg {r : ℝ} (h : 0 ≤ r) : ‖(r : K)‖ = r := (norm_ofReal _).trans (abs_of_nonneg h) @[simp, rclike_simps, norm_cast] theorem norm_natCast (n : ℕ) : ‖(n : K)‖ = n := by rw [← ofReal_natCast] exact norm_of_nonneg (Nat.cast_nonneg n) @[simp, rclike_simps, norm_cast] lemma nnnorm_natCast (n : ℕ) : ‖(n : K)‖₊ = n := by simp [nnnorm] @[simp, rclike_simps] theorem norm_ofNat (n : ℕ) [n.AtLeastTwo] : ‖(ofNat(n) : K)‖ = ofNat(n) := norm_natCast n @[simp, rclike_simps] lemma nnnorm_ofNat (n : ℕ) [n.AtLeastTwo] : ‖(ofNat(n) : K)‖₊ = ofNat(n) := nnnorm_natCast n lemma norm_two : ‖(2 : K)‖ = 2 := norm_ofNat 2 lemma nnnorm_two : ‖(2 : K)‖₊ = 2 := nnnorm_ofNat 2 @[simp, rclike_simps, norm_cast] lemma norm_nnratCast (q : ℚ≥0) : ‖(q : K)‖ = q := by rw [← ofReal_nnratCast]; exact norm_of_nonneg q.cast_nonneg @[simp, rclike_simps, norm_cast] lemma nnnorm_nnratCast (q : ℚ≥0) : ‖(q : K)‖₊ = q := by simp [nnnorm] variable (K) in lemma norm_nsmul [NormedAddCommGroup E] [NormedSpace K E] (n : ℕ) (x : E) : ‖n • x‖ = n • ‖x‖ := by simpa [Nat.cast_smul_eq_nsmul] using norm_smul (n : K) x variable (K) in lemma nnnorm_nsmul [NormedAddCommGroup E] [NormedSpace K E] (n : ℕ) (x : E) : ‖n • x‖₊ = n • ‖x‖₊ := by simpa [Nat.cast_smul_eq_nsmul] using nnnorm_smul (n : K) x section NormedField variable [NormedField E] [CharZero E] [NormedSpace K E] include K variable (K) in lemma norm_nnqsmul (q : ℚ≥0) (x : E) : ‖q • x‖ = q • ‖x‖ := by simpa [NNRat.cast_smul_eq_nnqsmul] using norm_smul (q : K) x variable (K) in lemma nnnorm_nnqsmul (q : ℚ≥0) (x : E) : ‖q • x‖₊ = q • ‖x‖₊ := by simpa [NNRat.cast_smul_eq_nnqsmul] using nnnorm_smul (q : K) x @[bound] lemma norm_expect_le {ι : Type*} {s : Finset ι} {f : ι → E} : ‖𝔼 i ∈ s, f i‖ ≤ 𝔼 i ∈ s, ‖f i‖ := Finset.le_expect_of_subadditive norm_zero norm_add_le fun _ _ ↦ by rw [norm_nnqsmul K] end NormedField theorem mul_self_norm (z : K) : ‖z‖ * ‖z‖ = normSq z := by rw [normSq_eq_def', sq] attribute [rclike_simps] norm_zero norm_one norm_eq_zero abs_norm norm_inv norm_div theorem abs_re_le_norm (z : K) : |re z| ≤ ‖z‖ := by rw [mul_self_le_mul_self_iff (abs_nonneg _) (norm_nonneg _), abs_mul_abs_self, mul_self_norm] apply re_sq_le_normSq theorem abs_im_le_norm (z : K) : |im z| ≤ ‖z‖ := by rw [mul_self_le_mul_self_iff (abs_nonneg _) (norm_nonneg _), abs_mul_abs_self, mul_self_norm] apply im_sq_le_normSq theorem norm_re_le_norm (z : K) : ‖re z‖ ≤ ‖z‖ := abs_re_le_norm z theorem norm_im_le_norm (z : K) : ‖im z‖ ≤ ‖z‖ := abs_im_le_norm z theorem re_le_norm (z : K) : re z ≤ ‖z‖ := (abs_le.1 (abs_re_le_norm z)).2 theorem im_le_norm (z : K) : im z ≤ ‖z‖ := (abs_le.1 (abs_im_le_norm _)).2 theorem im_eq_zero_of_le {a : K} (h : ‖a‖ ≤ re a) : im a = 0 := by simpa only [mul_self_norm a, normSq_apply, left_eq_add, mul_self_eq_zero] using congr_arg (fun z => z * z) ((re_le_norm a).antisymm h) theorem re_eq_self_of_le {a : K} (h : ‖a‖ ≤ re a) : (re a : K) = a := by rw [← conj_eq_iff_re, conj_eq_iff_im, im_eq_zero_of_le h] open IsAbsoluteValue theorem abs_re_div_norm_le_one (z : K) : |re z / ‖z‖| ≤ 1 := by rw [abs_div, abs_norm] exact div_le_one_of_le₀ (abs_re_le_norm _) (norm_nonneg _) theorem abs_im_div_norm_le_one (z : K) : |im z / ‖z‖| ≤ 1 := by rw [abs_div, abs_norm] exact div_le_one_of_le₀ (abs_im_le_norm _) (norm_nonneg _) theorem norm_I_of_ne_zero (hI : (I : K) ≠ 0) : ‖(I : K)‖ = 1 := by rw [← mul_self_inj_of_nonneg (norm_nonneg I) zero_le_one, one_mul, ← norm_mul, I_mul_I_of_nonzero hI, norm_neg, norm_one] theorem re_eq_norm_of_mul_conj (x : K) : re (x * conj x) = ‖x * conj x‖ := by rw [mul_conj, ← ofReal_pow]; simp [-map_pow] theorem norm_sq_re_add_conj (x : K) : ‖x + conj x‖ ^ 2 = re (x + conj x) ^ 2 := by rw [add_conj, ← ofReal_ofNat, ← ofReal_mul, norm_ofReal, sq_abs, ofReal_re] theorem norm_sq_re_conj_add (x : K) : ‖conj x + x‖ ^ 2 = re (conj x + x) ^ 2 := by rw [add_comm, norm_sq_re_add_conj] /-! ### Cauchy sequences -/
theorem isCauSeq_re (f : CauSeq K norm) : IsCauSeq abs fun n => re (f n) := fun _ ε0 => (f.cauchy ε0).imp fun i H j ij => lt_of_le_of_lt (by simpa only [map_sub] using abs_re_le_norm (f j - f i)) (H _ ij)
Mathlib/Analysis/RCLike/Basic.lean
700
702
/- Copyright (c) 2020 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.Algebra.Squarefree.Basic import Mathlib.Data.Nat.Factorization.PrimePow import Mathlib.RingTheory.UniqueFactorizationDomain.Nat /-! # Lemmas about squarefreeness of natural numbers A number is squarefree when it is not divisible by any squares except the squares of units. ## Main Results - `Nat.squarefree_iff_nodup_primeFactorsList`: A positive natural number `x` is squarefree iff the list `factors x` has no duplicate factors. ## Tags squarefree, multiplicity -/ open Finset namespace Nat theorem squarefree_iff_nodup_primeFactorsList {n : ℕ} (h0 : n ≠ 0) : Squarefree n ↔ n.primeFactorsList.Nodup := by rw [UniqueFactorizationMonoid.squarefree_iff_nodup_normalizedFactors h0, Nat.factors_eq] simp end Nat theorem Squarefree.nodup_primeFactorsList {n : ℕ} (hn : Squarefree n) : n.primeFactorsList.Nodup := (Nat.squarefree_iff_nodup_primeFactorsList hn.ne_zero).mp hn namespace Nat variable {s : Finset ℕ} {m n p : ℕ} theorem squarefree_iff_prime_squarefree {n : ℕ} : Squarefree n ↔ ∀ x, Prime x → ¬x * x ∣ n := squarefree_iff_irreducible_sq_not_dvd_of_exists_irreducible ⟨_, prime_two⟩ theorem _root_.Squarefree.natFactorization_le_one {n : ℕ} (p : ℕ) (hn : Squarefree n) : n.factorization p ≤ 1 := by rcases eq_or_ne n 0 with (rfl | hn') · simp rw [squarefree_iff_emultiplicity_le_one] at hn by_cases hp : p.Prime · have := hn p rw [← multiplicity_eq_factorization hp hn'] simp only [Nat.isUnit_iff, hp.ne_one, or_false] at this exact multiplicity_le_of_emultiplicity_le this · rw [factorization_eq_zero_of_non_prime _ hp] exact zero_le_one lemma factorization_eq_one_of_squarefree (hn : Squarefree n) (hp : p.Prime) (hpn : p ∣ n) : factorization n p = 1 := (hn.natFactorization_le_one _).antisymm <| (hp.dvd_iff_one_le_factorization hn.ne_zero).1 hpn theorem squarefree_of_factorization_le_one {n : ℕ} (hn : n ≠ 0) (hn' : ∀ p, n.factorization p ≤ 1) : Squarefree n := by rw [squarefree_iff_nodup_primeFactorsList hn, List.nodup_iff_count_le_one] intro a rw [primeFactorsList_count_eq] apply hn' theorem squarefree_iff_factorization_le_one {n : ℕ} (hn : n ≠ 0) : Squarefree n ↔ ∀ p, n.factorization p ≤ 1 := ⟨fun hn => hn.natFactorization_le_one, squarefree_of_factorization_le_one hn⟩ theorem Squarefree.ext_iff {n m : ℕ} (hn : Squarefree n) (hm : Squarefree m) : n = m ↔ ∀ p, Prime p → (p ∣ n ↔ p ∣ m) := by refine ⟨by rintro rfl; simp, fun h => eq_of_factorization_eq hn.ne_zero hm.ne_zero fun p => ?_⟩ by_cases hp : p.Prime · have h₁ := h _ hp rw [← not_iff_not, hp.dvd_iff_one_le_factorization hn.ne_zero, not_le, lt_one_iff, hp.dvd_iff_one_le_factorization hm.ne_zero, not_le, lt_one_iff] at h₁ have h₂ := hn.natFactorization_le_one p have h₃ := hm.natFactorization_le_one p omega rw [factorization_eq_zero_of_non_prime _ hp, factorization_eq_zero_of_non_prime _ hp] theorem squarefree_pow_iff {n k : ℕ} (hn : n ≠ 1) (hk : k ≠ 0) : Squarefree (n ^ k) ↔ Squarefree n ∧ k = 1 := by refine ⟨fun h => ?_, by rintro ⟨hn, rfl⟩; simpa⟩ rcases eq_or_ne n 0 with (rfl | -) · simp [zero_pow hk] at h refine ⟨h.squarefree_of_dvd (dvd_pow_self _ hk), by_contradiction fun h₁ => ?_⟩ have : 2 ≤ k := k.two_le_iff.mpr ⟨hk, h₁⟩ apply hn (Nat.isUnit_iff.1 (h _ _)) rw [← sq] exact pow_dvd_pow _ this theorem squarefree_and_prime_pow_iff_prime {n : ℕ} : Squarefree n ∧ IsPrimePow n ↔ Prime n := by refine ⟨?_, fun hn => ⟨hn.squarefree, hn.isPrimePow⟩⟩ rw [isPrimePow_nat_iff] rintro ⟨h, p, k, hp, hk, rfl⟩ rw [squarefree_pow_iff hp.ne_one hk.ne'] at h rwa [h.2, pow_one] /-- Assuming that `n` has no factors less than `k`, returns the smallest prime `p` such that `p^2 ∣ n`. -/ def minSqFacAux : ℕ → ℕ → Option ℕ | n, k => if h : n < k * k then none else have : Nat.sqrt n - k < Nat.sqrt n + 2 - k := by exact Nat.minFac_lemma n k h if k ∣ n then let n' := n / k have : Nat.sqrt n' - k < Nat.sqrt n + 2 - k := lt_of_le_of_lt (Nat.sub_le_sub_right (Nat.sqrt_le_sqrt <| Nat.div_le_self _ _) k) this if k ∣ n' then some k else minSqFacAux n' (k + 2) else minSqFacAux n (k + 2) termination_by n k => sqrt n + 2 - k /-- Returns the smallest prime factor `p` of `n` such that `p^2 ∣ n`, or `none` if there is no such `p` (that is, `n` is squarefree). See also `Nat.squarefree_iff_minSqFac`. -/ def minSqFac (n : ℕ) : Option ℕ := if 2 ∣ n then let n' := n / 2 if 2 ∣ n' then some 2 else minSqFacAux n' 3 else minSqFacAux n 3 /-- The correctness property of the return value of `minSqFac`. * If `none`, then `n` is squarefree; * If `some d`, then `d` is a minimal square factor of `n` -/ def MinSqFacProp (n : ℕ) : Option ℕ → Prop | none => Squarefree n | some d => Prime d ∧ d * d ∣ n ∧ ∀ p, Prime p → p * p ∣ n → d ≤ p theorem minSqFacProp_div (n) {k} (pk : Prime k) (dk : k ∣ n) (dkk : ¬k * k ∣ n) {o} (H : MinSqFacProp (n / k) o) : MinSqFacProp n o := by have : ∀ p, Prime p → p * p ∣ n → k * (p * p) ∣ n := fun p pp dp => have := (coprime_primes pk pp).2 fun e => by subst e contradiction (coprime_mul_iff_right.2 ⟨this, this⟩).mul_dvd_of_dvd_of_dvd dk dp rcases o with - | d · rw [MinSqFacProp, squarefree_iff_prime_squarefree] at H ⊢ exact fun p pp dp => H p pp ((dvd_div_iff_mul_dvd dk).2 (this _ pp dp)) · obtain ⟨H1, H2, H3⟩ := H simp only [dvd_div_iff_mul_dvd dk] at H2 H3 exact ⟨H1, dvd_trans (dvd_mul_left _ _) H2, fun p pp dp => H3 _ pp (this _ pp dp)⟩ theorem minSqFacAux_has_prop {n : ℕ} (k) (n0 : 0 < n) (i) (e : k = 2 * i + 3) (ih : ∀ m, Prime m → m ∣ n → k ≤ m) : MinSqFacProp n (minSqFacAux n k) := by rw [minSqFacAux] by_cases h : n < k * k <;> simp only [h, ↓reduceDIte] · refine squarefree_iff_prime_squarefree.2 fun p pp d => ?_ have := ih p pp (dvd_trans ⟨_, rfl⟩ d) have := Nat.mul_le_mul this this exact not_le_of_lt h (le_trans this (le_of_dvd n0 d)) have k2 : 2 ≤ k := by omega have k0 : 0 < k := lt_of_lt_of_le (by decide) k2 have IH : ∀ n', n' ∣ n → ¬k ∣ n' → MinSqFacProp n' (n'.minSqFacAux (k + 2)) := by intro n' nd' nk have hn' := le_of_dvd n0 nd' refine have : Nat.sqrt n' - k < Nat.sqrt n + 2 - k := lt_of_le_of_lt (Nat.sub_le_sub_right (Nat.sqrt_le_sqrt hn') _) (Nat.minFac_lemma n k h) @minSqFacAux_has_prop n' (k + 2) (pos_of_dvd_of_pos nd' n0) (i + 1) (by simp [e, left_distrib]) fun m m2 d => ?_ rcases Nat.eq_or_lt_of_le (ih m m2 (dvd_trans d nd')) with me | ml · subst me contradiction apply (Nat.eq_or_lt_of_le ml).resolve_left intro me rw [← me, e] at d change 2 * (i + 2) ∣ n' at d have := ih _ prime_two (dvd_trans (dvd_of_mul_right_dvd d) nd') rw [e] at this exact absurd this (by omega) have pk : k ∣ n → Prime k := by refine fun dk => prime_def_minFac.2 ⟨k2, le_antisymm (minFac_le k0) ?_⟩ exact ih _ (minFac_prime (ne_of_gt k2)) (dvd_trans (minFac_dvd _) dk) split_ifs with dk dkk · exact ⟨pk dk, (Nat.dvd_div_iff_mul_dvd dk).1 dkk, fun p pp d => ih p pp (dvd_trans ⟨_, rfl⟩ d)⟩ · specialize IH (n / k) (div_dvd_of_dvd dk) dkk exact minSqFacProp_div _ (pk dk) dk (mt (Nat.dvd_div_iff_mul_dvd dk).2 dkk) IH · exact IH n (dvd_refl _) dk termination_by n.sqrt + 2 - k theorem minSqFac_has_prop (n : ℕ) : MinSqFacProp n (minSqFac n) := by dsimp only [minSqFac]; split_ifs with d2 d4 · exact ⟨prime_two, (dvd_div_iff_mul_dvd d2).1 d4, fun p pp _ => pp.two_le⟩ · rcases Nat.eq_zero_or_pos n with n0 | n0 · subst n0 cases d4 (by decide) refine minSqFacProp_div _ prime_two d2 (mt (dvd_div_iff_mul_dvd d2).2 d4) ?_ refine minSqFacAux_has_prop 3 (Nat.div_pos (le_of_dvd n0 d2) (by decide)) 0 rfl ?_ refine fun p pp dp => succ_le_of_lt (lt_of_le_of_ne pp.two_le ?_) rintro rfl contradiction · rcases Nat.eq_zero_or_pos n with n0 | n0 · subst n0 cases d2 (by decide) refine minSqFacAux_has_prop _ n0 0 rfl ?_ refine fun p pp dp => succ_le_of_lt (lt_of_le_of_ne pp.two_le ?_) rintro rfl contradiction theorem minSqFac_prime {n d : ℕ} (h : n.minSqFac = some d) : Prime d := by have := minSqFac_has_prop n rw [h] at this exact this.1 theorem minSqFac_dvd {n d : ℕ} (h : n.minSqFac = some d) : d * d ∣ n := by have := minSqFac_has_prop n rw [h] at this exact this.2.1 theorem minSqFac_le_of_dvd {n d : ℕ} (h : n.minSqFac = some d) {m} (m2 : 2 ≤ m) (md : m * m ∣ n) : d ≤ m := by have := minSqFac_has_prop n; rw [h] at this have fd := minFac_dvd m exact le_trans (this.2.2 _ (minFac_prime <| ne_of_gt m2) (dvd_trans (mul_dvd_mul fd fd) md)) (minFac_le <| lt_of_lt_of_le (by decide) m2) theorem squarefree_iff_minSqFac {n : ℕ} : Squarefree n ↔ n.minSqFac = none := by have := minSqFac_has_prop n constructor <;> intro H · rcases e : n.minSqFac with - | d · rfl rw [e] at this cases squarefree_iff_prime_squarefree.1 H _ this.1 this.2.1 · rwa [H] at this instance : DecidablePred (Squarefree : ℕ → Prop) := fun _ => decidable_of_iff' _ squarefree_iff_minSqFac theorem squarefree_two : Squarefree 2 := by rw [squarefree_iff_nodup_primeFactorsList] <;> simp theorem divisors_filter_squarefree_of_squarefree {n : ℕ} (hn : Squarefree n) : {d ∈ n.divisors | Squarefree d} = n.divisors := Finset.ext fun d => ⟨@Finset.filter_subset _ _ _ _ d, fun hd => Finset.mem_filter.mpr ⟨hd, hn.squarefree_of_dvd (Nat.dvd_of_mem_divisors hd) ⟩⟩ open UniqueFactorizationMonoid theorem divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) : {d ∈ n.divisors | Squarefree d}.val = (UniqueFactorizationMonoid.normalizedFactors n).toFinset.powerset.val.map fun x => x.val.prod := by rw [(Finset.nodup _).ext ((Finset.nodup _).map_on _)] · intro a simp only [Multiset.mem_filter, id, Multiset.mem_map, Finset.filter_val, ← Finset.mem_def, mem_divisors] constructor · rintro ⟨⟨an, h0⟩, hsq⟩ use (UniqueFactorizationMonoid.normalizedFactors a).toFinset simp only [id, Finset.mem_powerset] rcases an with ⟨b, rfl⟩ rw [mul_ne_zero_iff] at h0 rw [UniqueFactorizationMonoid.squarefree_iff_nodup_normalizedFactors h0.1] at hsq rw [Multiset.toFinset_subset, Multiset.toFinset_val, hsq.dedup, ← associated_iff_eq, normalizedFactors_mul h0.1 h0.2] exact ⟨Multiset.subset_of_le (Multiset.le_add_right _ _), prod_normalizedFactors h0.1⟩ · rintro ⟨s, hs, rfl⟩ rw [Finset.mem_powerset, ← Finset.val_le_iff, Multiset.toFinset_val] at hs have hs0 : s.val.prod ≠ 0 := by rw [Ne, Multiset.prod_eq_zero_iff] intro con apply not_irreducible_zero (irreducible_of_normalized_factor 0 (Multiset.mem_dedup.1 (Multiset.mem_of_le hs con))) rw [(prod_normalizedFactors h0).symm.dvd_iff_dvd_right] refine ⟨⟨Multiset.prod_dvd_prod_of_le (le_trans hs (Multiset.dedup_le _)), h0⟩, ?_⟩ have h := UniqueFactorizationMonoid.factors_unique irreducible_of_normalized_factor (fun x hx => irreducible_of_normalized_factor x (Multiset.mem_of_le (le_trans hs (Multiset.dedup_le _)) hx)) (prod_normalizedFactors hs0) rw [associated_eq_eq, Multiset.rel_eq] at h rw [UniqueFactorizationMonoid.squarefree_iff_nodup_normalizedFactors hs0, h] apply s.nodup · intro x hx y hy h rw [← Finset.val_inj, ← Multiset.rel_eq, ← associated_eq_eq] rw [← Finset.mem_def, Finset.mem_powerset] at hx hy apply UniqueFactorizationMonoid.factors_unique _ _ (associated_iff_eq.2 h) · intro z hz apply irreducible_of_normalized_factor z · rw [← Multiset.mem_toFinset] apply hx hz · intro z hz apply irreducible_of_normalized_factor z · rw [← Multiset.mem_toFinset] apply hy hz theorem sum_divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) {α : Type*} [AddCommMonoid α] {f : ℕ → α} : ∑ d ∈ n.divisors with Squarefree d, f d = ∑ i ∈ (UniqueFactorizationMonoid.normalizedFactors n).toFinset.powerset, f i.val.prod := by rw [Finset.sum_eq_multiset_sum, divisors_filter_squarefree h0, Multiset.map_map, Finset.sum_eq_multiset_sum] rfl theorem sq_mul_squarefree_of_pos {n : ℕ} (hn : 0 < n) : ∃ a b : ℕ, 0 < a ∧ 0 < b ∧ b ^ 2 * a = n ∧ Squarefree a := by classical set S := {s ∈ range (n + 1) | s ∣ n ∧ ∃ x, s = x ^ 2} have hSne : S.Nonempty := by use 1 have h1 : 0 < n ∧ ∃ x : ℕ, 1 = x ^ 2 := ⟨hn, ⟨1, (one_pow 2).symm⟩⟩ simp [S, h1] let s := Finset.max' S hSne have hs : s ∈ S := Finset.max'_mem S hSne simp only [S, Finset.mem_filter, Finset.mem_range] at hs obtain ⟨-, ⟨a, hsa⟩, ⟨b, hsb⟩⟩ := hs rw [hsa] at hn obtain ⟨hlts, hlta⟩ := CanonicallyOrderedAdd.mul_pos.mp hn rw [hsb] at hsa hn hlts refine ⟨a, b, hlta, (pow_pos_iff two_ne_zero).mp hlts, hsa.symm, ?_⟩ rintro x ⟨y, hy⟩ rw [Nat.isUnit_iff] by_contra hx refine Nat.lt_le_asymm ?_ (Finset.le_max' S ((b * x) ^ 2) ?_) · convert lt_mul_of_one_lt_right hlts (one_lt_pow two_ne_zero (one_lt_iff_ne_zero_and_ne_one.mpr ⟨fun h => by simp_all, hx⟩)) using 1 rw [mul_pow] · simp_rw [S, hsa, Finset.mem_filter, Finset.mem_range] refine ⟨Nat.lt_succ_iff.mpr (le_of_dvd hn ?_), ?_, ⟨b * x, rfl⟩⟩ <;> use y <;> rw [hy] <;> ring theorem sq_mul_squarefree_of_pos' {n : ℕ} (h : 0 < n) : ∃ a b : ℕ, (b + 1) ^ 2 * (a + 1) = n ∧ Squarefree (a + 1) := by obtain ⟨a₁, b₁, ha₁, hb₁, hab₁, hab₂⟩ := sq_mul_squarefree_of_pos h refine ⟨a₁.pred, b₁.pred, ?_, ?_⟩ <;> simpa only [add_one, succ_pred_eq_of_pos, ha₁, hb₁] theorem sq_mul_squarefree (n : ℕ) : ∃ a b : ℕ, b ^ 2 * a = n ∧ Squarefree a := by rcases n with - | n · exact ⟨1, 0, by simp, squarefree_one⟩ · obtain ⟨a, b, -, -, h₁, h₂⟩ := sq_mul_squarefree_of_pos (succ_pos n) exact ⟨a, b, h₁, h₂⟩ /-- `Squarefree` is multiplicative. Note that the → direction does not require `hmn` and generalizes to arbitrary commutative monoids. See `Squarefree.of_mul_left` and `Squarefree.of_mul_right` above for auxiliary lemmas. -/ theorem squarefree_mul {m n : ℕ} (hmn : m.Coprime n) : Squarefree (m * n) ↔ Squarefree m ∧ Squarefree n := by simp only [squarefree_iff_prime_squarefree, ← sq, ← forall_and] refine forall₂_congr fun p hp => ?_ simp only [hmn.isPrimePow_dvd_mul (hp.isPrimePow.pow two_ne_zero), not_or] theorem coprime_of_squarefree_mul {m n : ℕ} (h : Squarefree (m * n)) : m.Coprime n := coprime_of_dvd fun p hp hm hn => squarefree_iff_prime_squarefree.mp h p hp (mul_dvd_mul hm hn) theorem squarefree_mul_iff {m n : ℕ} : Squarefree (m * n) ↔ m.Coprime n ∧ Squarefree m ∧ Squarefree n := ⟨fun h => ⟨coprime_of_squarefree_mul h, (squarefree_mul <| coprime_of_squarefree_mul h).mp h⟩, fun h => (squarefree_mul h.1).mpr h.2⟩ lemma coprime_div_gcd_of_squarefree (hm : Squarefree m) (hn : n ≠ 0) : Coprime (m / gcd m n) n := by have : Coprime (m / gcd m n) (gcd m n) := coprime_of_squarefree_mul <| by simpa [Nat.div_mul_cancel, gcd_dvd_left] simpa [Nat.div_mul_cancel, gcd_dvd_right] using (coprime_div_gcd_div_gcd (m := m) (gcd_ne_zero_right hn).bot_lt).mul_right this lemma prod_primeFactors_of_squarefree (hn : Squarefree n) : ∏ p ∈ n.primeFactors, p = n := by rw [← toFinset_factors, List.prod_toFinset _ hn.nodup_primeFactorsList, List.map_id', Nat.prod_primeFactorsList hn.ne_zero] lemma primeFactors_prod (hs : ∀ p ∈ s, p.Prime) : primeFactors (∏ p ∈ s, p) = s := by have hn : ∏ p ∈ s, p ≠ 0 := prod_ne_zero_iff.2 fun p hp ↦ (hs _ hp).ne_zero ext p rw [mem_primeFactors_of_ne_zero hn, and_congr_right (fun hp ↦ hp.prime.dvd_finset_prod_iff _)] refine ⟨?_, fun hp ↦ ⟨hs _ hp, _, hp, dvd_rfl⟩⟩ rintro ⟨hp, q, hq, hpq⟩ rwa [← ((hs _ hq).dvd_iff_eq hp.ne_one).1 hpq] lemma primeFactors_div_gcd (hm : Squarefree m) (hn : n ≠ 0) : primeFactors (m / m.gcd n) = primeFactors m \ primeFactors n := by ext p have : m / m.gcd n ≠ 0 := by simp [gcd_ne_zero_right hn, gcd_le_left _ hm.ne_zero.bot_lt] simp only [mem_primeFactors, ne_eq, this, not_false_eq_true, and_true, not_and, mem_sdiff, hm.ne_zero, hn, dvd_div_iff_mul_dvd (gcd_dvd_left _ _)] refine ⟨fun hp ↦ ⟨⟨hp.1, dvd_of_mul_left_dvd hp.2⟩, fun _ hpn ↦ hp.1.not_isUnit <| hm _ <| (mul_dvd_mul_right (dvd_gcd (dvd_of_mul_left_dvd hp.2) hpn) _).trans hp.2⟩, fun hp ↦ ⟨hp.1.1, Coprime.mul_dvd_of_dvd_of_dvd ?_ (gcd_dvd_left _ _) hp.1.2⟩⟩ rw [coprime_comm, hp.1.1.coprime_iff_not_dvd] exact fun hpn ↦ hp.2 hp.1.1 <| hpn.trans <| gcd_dvd_right _ _ lemma prod_primeFactors_invOn_squarefree : Set.InvOn (fun n : ℕ ↦ (factorization n).support) (fun s ↦ ∏ p ∈ s, p) {s | ∀ p ∈ s, p.Prime} {n | Squarefree n} := ⟨fun _s ↦ primeFactors_prod, fun _n ↦ prod_primeFactors_of_squarefree⟩ theorem prod_primeFactors_sdiff_of_squarefree {n : ℕ} (hn : Squarefree n) {t : Finset ℕ} (ht : t ⊆ n.primeFactors) :
∏ a ∈ (n.primeFactors \ t), a = n / ∏ a ∈ t, a := by refine symm <| Nat.div_eq_of_eq_mul_left (Finset.prod_pos fun p hp => (prime_of_mem_primeFactorsList (List.mem_toFinset.mp (ht hp))).pos) ?_
Mathlib/Data/Nat/Squarefree.lean
394
396
/- Copyright (c) 2021 Christopher Hoskin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christopher Hoskin -/ import Mathlib.Analysis.Normed.Group.Constructions import Mathlib.Analysis.Normed.Group.Rat import Mathlib.Analysis.Normed.Group.Uniform import Mathlib.Topology.Order.Lattice /-! # Normed lattice ordered groups Motivated by the theory of Banach Lattices, we then define `NormedLatticeAddCommGroup` as a lattice with a covariant normed group addition satisfying the solid axiom. ## Main statements We show that a normed lattice ordered group is a topological lattice with respect to the norm topology. ## References * [Meyer-Nieberg, Banach lattices][MeyerNieberg1991] ## Tags normed, lattice, ordered, group -/ /-! ### Normed lattice ordered groups Motivated by the theory of Banach Lattices, this section introduces normed lattice ordered groups. -/ section SolidNorm /-- Let `α` be an `AddCommGroup` with a `Lattice` structure. A norm on `α` is *solid* if, for `a` and `b` in `α`, with absolute values `|a|` and `|b|` respectively, `|a| ≤ |b|` implies `‖a‖ ≤ ‖b‖`. -/ class HasSolidNorm (α : Type*) [NormedAddCommGroup α] [Lattice α] : Prop where solid : ∀ ⦃x y : α⦄, |x| ≤ |y| → ‖x‖ ≤ ‖y‖ variable {α : Type*} [NormedAddCommGroup α] [Lattice α] [HasSolidNorm α] theorem norm_le_norm_of_abs_le_abs {a b : α} (h : |a| ≤ |b|) : ‖a‖ ≤ ‖b‖ := HasSolidNorm.solid h /-- If `α` has a solid norm, then the balls centered at the origin of `α` are solid sets. -/ theorem LatticeOrderedAddCommGroup.isSolid_ball (r : ℝ) : LatticeOrderedAddCommGroup.IsSolid (Metric.ball (0 : α) r) := fun _ hx _ hxy => mem_ball_zero_iff.mpr ((HasSolidNorm.solid hxy).trans_lt (mem_ball_zero_iff.mp hx)) instance : HasSolidNorm ℝ := ⟨fun _ _ => id⟩ instance : HasSolidNorm ℚ := ⟨fun _ _ _ => by simpa only [norm, ← Rat.cast_abs, Rat.cast_le]⟩ end SolidNorm /-- Let `α` be a normed commutative group equipped with a partial order covariant with addition, with respect which `α` forms a lattice. Suppose that `α` is *solid*, that is to say, for `a` and `b` in `α`, with absolute values `|a|` and `|b|` respectively, `|a| ≤ |b|` implies `‖a‖ ≤ ‖b‖`. Then `α` is said to be a normed lattice ordered group. -/ @[deprecated "Use `[NormedAddCommGroup α] [Lattice α] [HasSolidNorm α] [IsOrderedAddMonoid α]` instead." (since := "2025-04-10")] structure NormedLatticeAddCommGroup (α : Type*) extends NormedAddCommGroup α, Lattice α, HasSolidNorm α where add_le_add_left : ∀ a b : α, a ≤ b → ∀ c : α, c + a ≤ c + b instance Int.hasSolidNorm : HasSolidNorm ℤ where solid x y h := by simpa [← Int.norm_cast_real, ← Int.cast_abs] using h instance Rat.hasSolidNorm : HasSolidNorm ℚ where solid x y h := by simpa [← Rat.norm_cast_real, ← Rat.cast_abs] using h variable {α : Type*} [NormedAddCommGroup α] [Lattice α] [HasSolidNorm α] [IsOrderedAddMonoid α] open HasSolidNorm theorem dual_solid (a b : α) (h : b ⊓ -b ≤ a ⊓ -a) : ‖a‖ ≤ ‖b‖ := by apply solid rw [abs] nth_rw 1 [← neg_neg a] rw [← neg_inf] rw [abs] nth_rw 1 [← neg_neg b] rwa [← neg_inf, neg_le_neg_iff, inf_comm _ b, inf_comm _ a] -- see Note [lower instance priority] /-- Let `α` be a normed lattice ordered group, then the order dual is also a normed lattice ordered group. -/ instance (priority := 100) OrderDual.instHasSolidNorm : HasSolidNorm αᵒᵈ := { solid := dual_solid (α := α) } theorem norm_abs_eq_norm (a : α) : ‖|a|‖ = ‖a‖ := (solid (abs_abs a).le).antisymm (solid (abs_abs a).symm.le) theorem norm_inf_sub_inf_le_add_norm (a b c d : α) : ‖a ⊓ b - c ⊓ d‖ ≤ ‖a - c‖ + ‖b - d‖ := by rw [← norm_abs_eq_norm (a - c), ← norm_abs_eq_norm (b - d)] refine le_trans (solid ?_) (norm_add_le |a - c| |b - d|) rw [abs_of_nonneg (add_nonneg (abs_nonneg (a - c)) (abs_nonneg (b - d)))] calc |a ⊓ b - c ⊓ d| = |a ⊓ b - c ⊓ b + (c ⊓ b - c ⊓ d)| := by rw [sub_add_sub_cancel] _ ≤ |a ⊓ b - c ⊓ b| + |c ⊓ b - c ⊓ d| := abs_add_le _ _ _ ≤ |a - c| + |b - d| := by apply add_le_add · exact abs_inf_sub_inf_le_abs _ _ _ · rw [inf_comm c, inf_comm c] exact abs_inf_sub_inf_le_abs _ _ _ theorem norm_sup_sub_sup_le_add_norm (a b c d : α) : ‖a ⊔ b - c ⊔ d‖ ≤ ‖a - c‖ + ‖b - d‖ := by rw [← norm_abs_eq_norm (a - c), ← norm_abs_eq_norm (b - d)] refine le_trans (solid ?_) (norm_add_le |a - c| |b - d|) rw [abs_of_nonneg (add_nonneg (abs_nonneg (a - c)) (abs_nonneg (b - d)))] calc |a ⊔ b - c ⊔ d| = |a ⊔ b - c ⊔ b + (c ⊔ b - c ⊔ d)| := by rw [sub_add_sub_cancel] _ ≤ |a ⊔ b - c ⊔ b| + |c ⊔ b - c ⊔ d| := abs_add_le _ _ _ ≤ |a - c| + |b - d| := by apply add_le_add · exact abs_sup_sub_sup_le_abs _ _ _ · rw [sup_comm c, sup_comm c] exact abs_sup_sub_sup_le_abs _ _ _ theorem norm_inf_le_add (x y : α) : ‖x ⊓ y‖ ≤ ‖x‖ + ‖y‖ := by have h : ‖x ⊓ y - 0 ⊓ 0‖ ≤ ‖x - 0‖ + ‖y - 0‖ := norm_inf_sub_inf_le_add_norm x y 0 0 simpa only [inf_idem, sub_zero] using h theorem norm_sup_le_add (x y : α) : ‖x ⊔ y‖ ≤ ‖x‖ + ‖y‖ := by have h : ‖x ⊔ y - 0 ⊔ 0‖ ≤ ‖x - 0‖ + ‖y - 0‖ := norm_sup_sub_sup_le_add_norm x y 0 0 simpa only [sup_idem, sub_zero] using h -- see Note [lower instance priority] /-- Let `α` be a normed lattice ordered group. Then the infimum is jointly continuous. -/ instance (priority := 100) HasSolidNorm.continuousInf : ContinuousInf α := by refine ⟨continuous_iff_continuousAt.2 fun q => tendsto_iff_norm_sub_tendsto_zero.2 <| ?_⟩ have : ∀ p : α × α, ‖p.1 ⊓ p.2 - q.1 ⊓ q.2‖ ≤ ‖p.1 - q.1‖ + ‖p.2 - q.2‖ := fun _ => norm_inf_sub_inf_le_add_norm _ _ _ _ refine squeeze_zero (fun e => norm_nonneg _) this ?_ convert ((continuous_fst.tendsto q).sub <| tendsto_const_nhds).norm.add ((continuous_snd.tendsto q).sub <| tendsto_const_nhds).norm simp -- see Note [lower instance priority] instance (priority := 100) HasSolidNorm.continuousSup {α : Type*}
[NormedAddCommGroup α] [Lattice α] [HasSolidNorm α] [IsOrderedAddMonoid α] : ContinuousSup α := OrderDual.continuousSup αᵒᵈ
Mathlib/Analysis/Normed/Order/Lattice.lean
153
155
/- 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 -/ import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.Topology.MetricSpace.IsometricSMul /-! # Hausdorff distance The Hausdorff distance on subsets of a metric (or emetric) space. Given two subsets `s` and `t` of a metric space, their Hausdorff distance is the smallest `d` such that any point `s` is within `d` of a point in `t`, and conversely. This quantity is often infinite (think of `s` bounded and `t` unbounded), and therefore better expressed in the setting of emetric spaces. ## Main definitions This files introduces: * `EMetric.infEdist x s`, the infimum edistance of a point `x` to a set `s` in an emetric space * `EMetric.hausdorffEdist s t`, the Hausdorff edistance of two sets in an emetric space * Versions of these notions on metric spaces, called respectively `Metric.infDist` and `Metric.hausdorffDist` ## Main results * `infEdist_closure`: the edistance to a set and its closure coincide * `EMetric.mem_closure_iff_infEdist_zero`: a point `x` belongs to the closure of `s` iff `infEdist x s = 0` * `IsCompact.exists_infEdist_eq_edist`: if `s` is compact and non-empty, there exists a point `y` which attains this edistance * `IsOpen.exists_iUnion_isClosed`: every open set `U` can be written as the increasing union of countably many closed subsets of `U` * `hausdorffEdist_closure`: replacing a set by its closure does not change the Hausdorff edistance * `hausdorffEdist_zero_iff_closure_eq_closure`: two sets have Hausdorff edistance zero iff their closures coincide * the Hausdorff edistance is symmetric and satisfies the triangle inequality * in particular, closed sets in an emetric space are an emetric space (this is shown in `EMetricSpace.closeds.emetricspace`) * versions of these notions on metric spaces * `hausdorffEdist_ne_top_of_nonempty_of_bounded`: if two sets in a metric space are nonempty and bounded in a metric space, they are at finite Hausdorff edistance. ## Tags metric space, Hausdorff distance -/ noncomputable section open NNReal ENNReal Topology Set Filter Pointwise Bornology universe u v w variable {ι : Sort*} {α : Type u} {β : Type v} namespace EMetric section InfEdist variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] {x y : α} {s t : Set α} {Φ : α → β} /-! ### Distance of a point to a set as a function into `ℝ≥0∞`. -/ /-- The minimal edistance of a point to a set -/ def infEdist (x : α) (s : Set α) : ℝ≥0∞ := ⨅ y ∈ s, edist x y @[simp] theorem infEdist_empty : infEdist x ∅ = ∞ := iInf_emptyset theorem le_infEdist {d} : d ≤ infEdist x s ↔ ∀ y ∈ s, d ≤ edist x y := by simp only [infEdist, le_iInf_iff] /-- The edist to a union is the minimum of the edists -/ @[simp] theorem infEdist_union : infEdist x (s ∪ t) = infEdist x s ⊓ infEdist x t := iInf_union @[simp] theorem infEdist_iUnion (f : ι → Set α) (x : α) : infEdist x (⋃ i, f i) = ⨅ i, infEdist x (f i) := iInf_iUnion f _ lemma infEdist_biUnion {ι : Type*} (f : ι → Set α) (I : Set ι) (x : α) : infEdist x (⋃ i ∈ I, f i) = ⨅ i ∈ I, infEdist x (f i) := by simp only [infEdist_iUnion] /-- The edist to a singleton is the edistance to the single point of this singleton -/ @[simp] theorem infEdist_singleton : infEdist x {y} = edist x y := iInf_singleton /-- The edist to a set is bounded above by the edist to any of its points -/ theorem infEdist_le_edist_of_mem (h : y ∈ s) : infEdist x s ≤ edist x y := iInf₂_le y h /-- If a point `x` belongs to `s`, then its edist to `s` vanishes -/ theorem infEdist_zero_of_mem (h : x ∈ s) : infEdist x s = 0 := nonpos_iff_eq_zero.1 <| @edist_self _ _ x ▸ infEdist_le_edist_of_mem h /-- The edist is antitone with respect to inclusion. -/ theorem infEdist_anti (h : s ⊆ t) : infEdist x t ≤ infEdist x s := iInf_le_iInf_of_subset h /-- The edist to a set is `< r` iff there exists a point in the set at edistance `< r` -/ theorem infEdist_lt_iff {r : ℝ≥0∞} : infEdist x s < r ↔ ∃ y ∈ s, edist x y < r := by simp_rw [infEdist, iInf_lt_iff, exists_prop] /-- The edist of `x` to `s` is bounded by the sum of the edist of `y` to `s` and the edist from `x` to `y` -/ theorem infEdist_le_infEdist_add_edist : infEdist x s ≤ infEdist y s + edist x y := calc ⨅ z ∈ s, edist x z ≤ ⨅ z ∈ s, edist y z + edist x y := iInf₂_mono fun _ _ => (edist_triangle _ _ _).trans_eq (add_comm _ _) _ = (⨅ z ∈ s, edist y z) + edist x y := by simp only [ENNReal.iInf_add] theorem infEdist_le_edist_add_infEdist : infEdist x s ≤ edist x y + infEdist y s := by rw [add_comm] exact infEdist_le_infEdist_add_edist theorem edist_le_infEdist_add_ediam (hy : y ∈ s) : edist x y ≤ infEdist x s + diam s := by simp_rw [infEdist, ENNReal.iInf_add] refine le_iInf₂ fun i hi => ?_ calc edist x y ≤ edist x i + edist i y := edist_triangle _ _ _ _ ≤ edist x i + diam s := add_le_add le_rfl (edist_le_diam_of_mem hi hy) /-- The edist to a set depends continuously on the point -/ @[continuity] theorem continuous_infEdist : Continuous fun x => infEdist x s := continuous_of_le_add_edist 1 (by simp) <| by simp only [one_mul, infEdist_le_infEdist_add_edist, forall₂_true_iff] /-- The edist to a set and to its closure coincide -/ theorem infEdist_closure : infEdist x (closure s) = infEdist x s := by refine le_antisymm (infEdist_anti subset_closure) ?_ refine ENNReal.le_of_forall_pos_le_add fun ε εpos h => ?_ have ε0 : 0 < (ε / 2 : ℝ≥0∞) := by simpa [pos_iff_ne_zero] using εpos have : infEdist x (closure s) < infEdist x (closure s) + ε / 2 := ENNReal.lt_add_right h.ne ε0.ne' obtain ⟨y : α, ycs : y ∈ closure s, hy : edist x y < infEdist x (closure s) + ↑ε / 2⟩ := infEdist_lt_iff.mp this obtain ⟨z : α, zs : z ∈ s, dyz : edist y z < ↑ε / 2⟩ := EMetric.mem_closure_iff.1 ycs (ε / 2) ε0 calc infEdist x s ≤ edist x z := infEdist_le_edist_of_mem zs _ ≤ edist x y + edist y z := edist_triangle _ _ _ _ ≤ infEdist x (closure s) + ε / 2 + ε / 2 := add_le_add (le_of_lt hy) (le_of_lt dyz) _ = infEdist x (closure s) + ↑ε := by rw [add_assoc, ENNReal.add_halves] /-- A point belongs to the closure of `s` iff its infimum edistance to this set vanishes -/ theorem mem_closure_iff_infEdist_zero : x ∈ closure s ↔ infEdist x s = 0 := ⟨fun h => by rw [← infEdist_closure] exact infEdist_zero_of_mem h, fun h => EMetric.mem_closure_iff.2 fun ε εpos => infEdist_lt_iff.mp <| by rwa [h]⟩ /-- Given a closed set `s`, a point belongs to `s` iff its infimum edistance to this set vanishes -/ theorem mem_iff_infEdist_zero_of_closed (h : IsClosed s) : x ∈ s ↔ infEdist x s = 0 := by rw [← mem_closure_iff_infEdist_zero, h.closure_eq] /-- The infimum edistance of a point to a set is positive if and only if the point is not in the closure of the set. -/ theorem infEdist_pos_iff_not_mem_closure {x : α} {E : Set α} : 0 < infEdist x E ↔ x ∉ closure E := by rw [mem_closure_iff_infEdist_zero, pos_iff_ne_zero] theorem infEdist_closure_pos_iff_not_mem_closure {x : α} {E : Set α} : 0 < infEdist x (closure E) ↔ x ∉ closure E := by rw [infEdist_closure, infEdist_pos_iff_not_mem_closure] theorem exists_real_pos_lt_infEdist_of_not_mem_closure {x : α} {E : Set α} (h : x ∉ closure E) : ∃ ε : ℝ, 0 < ε ∧ ENNReal.ofReal ε < infEdist x E := by rw [← infEdist_pos_iff_not_mem_closure, ENNReal.lt_iff_exists_real_btwn] at h rcases h with ⟨ε, ⟨_, ⟨ε_pos, ε_lt⟩⟩⟩ exact ⟨ε, ⟨ENNReal.ofReal_pos.mp ε_pos, ε_lt⟩⟩ theorem disjoint_closedBall_of_lt_infEdist {r : ℝ≥0∞} (h : r < infEdist x s) : Disjoint (closedBall x r) s := by rw [disjoint_left] intro y hy h'y apply lt_irrefl (infEdist x s) calc infEdist x s ≤ edist x y := infEdist_le_edist_of_mem h'y _ ≤ r := by rwa [mem_closedBall, edist_comm] at hy _ < infEdist x s := h /-- The infimum edistance is invariant under isometries -/ theorem infEdist_image (hΦ : Isometry Φ) : infEdist (Φ x) (Φ '' t) = infEdist x t := by simp only [infEdist, iInf_image, hΦ.edist_eq] @[to_additive (attr := simp)] theorem infEdist_smul {M} [SMul M α] [IsIsometricSMul M α] (c : M) (x : α) (s : Set α) : infEdist (c • x) (c • s) = infEdist x s := infEdist_image (isometry_smul _ _) theorem _root_.IsOpen.exists_iUnion_isClosed {U : Set α} (hU : IsOpen U) : ∃ F : ℕ → Set α, (∀ n, IsClosed (F n)) ∧ (∀ n, F n ⊆ U) ∧ ⋃ n, F n = U ∧ Monotone F := by obtain ⟨a, a_pos, a_lt_one⟩ : ∃ a : ℝ≥0∞, 0 < a ∧ a < 1 := exists_between zero_lt_one let F := fun n : ℕ => (fun x => infEdist x Uᶜ) ⁻¹' Ici (a ^ n) have F_subset : ∀ n, F n ⊆ U := fun n x hx ↦ by by_contra h have : infEdist x Uᶜ ≠ 0 := ((ENNReal.pow_pos a_pos _).trans_le hx).ne' exact this (infEdist_zero_of_mem h) refine ⟨F, fun n => IsClosed.preimage continuous_infEdist isClosed_Ici, F_subset, ?_, ?_⟩ · show ⋃ n, F n = U refine Subset.antisymm (by simp only [iUnion_subset_iff, F_subset, forall_const]) fun x hx => ?_ have : ¬x ∈ Uᶜ := by simpa using hx rw [mem_iff_infEdist_zero_of_closed hU.isClosed_compl] at this have B : 0 < infEdist x Uᶜ := by simpa [pos_iff_ne_zero] using this have : Filter.Tendsto (fun n => a ^ n) atTop (𝓝 0) := ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one a_lt_one rcases ((tendsto_order.1 this).2 _ B).exists with ⟨n, hn⟩ simp only [mem_iUnion, mem_Ici, mem_preimage] exact ⟨n, hn.le⟩ show Monotone F intro m n hmn x hx simp only [F, mem_Ici, mem_preimage] at hx ⊢ apply le_trans (pow_le_pow_right_of_le_one' a_lt_one.le hmn) hx theorem _root_.IsCompact.exists_infEdist_eq_edist (hs : IsCompact s) (hne : s.Nonempty) (x : α) : ∃ y ∈ s, infEdist x s = edist x y := by have A : Continuous fun y => edist x y := continuous_const.edist continuous_id obtain ⟨y, ys, hy⟩ := hs.exists_isMinOn hne A.continuousOn exact ⟨y, ys, le_antisymm (infEdist_le_edist_of_mem ys) (by rwa [le_infEdist])⟩ theorem exists_pos_forall_lt_edist (hs : IsCompact s) (ht : IsClosed t) (hst : Disjoint s t) : ∃ r : ℝ≥0, 0 < r ∧ ∀ x ∈ s, ∀ y ∈ t, (r : ℝ≥0∞) < edist x y := by rcases s.eq_empty_or_nonempty with (rfl | hne) · use 1 simp obtain ⟨x, hx, h⟩ := hs.exists_isMinOn hne continuous_infEdist.continuousOn have : 0 < infEdist x t := pos_iff_ne_zero.2 fun H => hst.le_bot ⟨hx, (mem_iff_infEdist_zero_of_closed ht).mpr H⟩ rcases ENNReal.lt_iff_exists_nnreal_btwn.1 this with ⟨r, h₀, hr⟩ exact ⟨r, ENNReal.coe_pos.mp h₀, fun y hy z hz => hr.trans_le <| le_infEdist.1 (h hy) z hz⟩ end InfEdist /-! ### The Hausdorff distance as a function into `ℝ≥0∞`. -/ /-- The Hausdorff edistance between two sets is the smallest `r` such that each set is contained in the `r`-neighborhood of the other one -/ irreducible_def hausdorffEdist {α : Type u} [PseudoEMetricSpace α] (s t : Set α) : ℝ≥0∞ := (⨆ x ∈ s, infEdist x t) ⊔ ⨆ y ∈ t, infEdist y s section HausdorffEdist variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] {x : α} {s t u : Set α} {Φ : α → β} /-- The Hausdorff edistance of a set to itself vanishes. -/ @[simp] theorem hausdorffEdist_self : hausdorffEdist s s = 0 := by simp only [hausdorffEdist_def, sup_idem, ENNReal.iSup_eq_zero] exact fun x hx => infEdist_zero_of_mem hx /-- The Haudorff edistances of `s` to `t` and of `t` to `s` coincide. -/ theorem hausdorffEdist_comm : hausdorffEdist s t = hausdorffEdist t s := by simp only [hausdorffEdist_def]; apply sup_comm /-- Bounding the Hausdorff edistance by bounding the edistance of any point in each set to the other set -/ theorem hausdorffEdist_le_of_infEdist {r : ℝ≥0∞} (H1 : ∀ x ∈ s, infEdist x t ≤ r) (H2 : ∀ x ∈ t, infEdist x s ≤ r) : hausdorffEdist s t ≤ r := by simp only [hausdorffEdist_def, sup_le_iff, iSup_le_iff] exact ⟨H1, H2⟩ /-- Bounding the Hausdorff edistance by exhibiting, for any point in each set, another point in the other set at controlled distance -/ theorem hausdorffEdist_le_of_mem_edist {r : ℝ≥0∞} (H1 : ∀ x ∈ s, ∃ y ∈ t, edist x y ≤ r) (H2 : ∀ x ∈ t, ∃ y ∈ s, edist x y ≤ r) : hausdorffEdist s t ≤ r := by refine hausdorffEdist_le_of_infEdist (fun x xs ↦ ?_) (fun x xt ↦ ?_) · rcases H1 x xs with ⟨y, yt, hy⟩ exact le_trans (infEdist_le_edist_of_mem yt) hy · rcases H2 x xt with ⟨y, ys, hy⟩ exact le_trans (infEdist_le_edist_of_mem ys) hy /-- The distance to a set is controlled by the Hausdorff distance. -/ theorem infEdist_le_hausdorffEdist_of_mem (h : x ∈ s) : infEdist x t ≤ hausdorffEdist s t := by rw [hausdorffEdist_def] refine le_trans ?_ le_sup_left exact le_iSup₂ (α := ℝ≥0∞) x h /-- If the Hausdorff distance is `< r`, then any point in one of the sets has a corresponding point at distance `< r` in the other set. -/ theorem exists_edist_lt_of_hausdorffEdist_lt {r : ℝ≥0∞} (h : x ∈ s) (H : hausdorffEdist s t < r) : ∃ y ∈ t, edist x y < r := infEdist_lt_iff.mp <| calc infEdist x t ≤ hausdorffEdist s t := infEdist_le_hausdorffEdist_of_mem h _ < r := H /-- The distance from `x` to `s` or `t` is controlled in terms of the Hausdorff distance between `s` and `t`. -/ theorem infEdist_le_infEdist_add_hausdorffEdist : infEdist x t ≤ infEdist x s + hausdorffEdist s t := ENNReal.le_of_forall_pos_le_add fun ε εpos h => by have ε0 : (ε / 2 : ℝ≥0∞) ≠ 0 := by simpa [pos_iff_ne_zero] using εpos have : infEdist x s < infEdist x s + ε / 2 := ENNReal.lt_add_right (ENNReal.add_lt_top.1 h).1.ne ε0 obtain ⟨y : α, ys : y ∈ s, dxy : edist x y < infEdist x s + ↑ε / 2⟩ := infEdist_lt_iff.mp this have : hausdorffEdist s t < hausdorffEdist s t + ε / 2 := ENNReal.lt_add_right (ENNReal.add_lt_top.1 h).2.ne ε0 obtain ⟨z : α, zt : z ∈ t, dyz : edist y z < hausdorffEdist s t + ↑ε / 2⟩ := exists_edist_lt_of_hausdorffEdist_lt ys this calc infEdist x t ≤ edist x z := infEdist_le_edist_of_mem zt _ ≤ edist x y + edist y z := edist_triangle _ _ _ _ ≤ infEdist x s + ε / 2 + (hausdorffEdist s t + ε / 2) := add_le_add dxy.le dyz.le _ = infEdist x s + hausdorffEdist s t + ε := by simp [ENNReal.add_halves, add_comm, add_left_comm] /-- The Hausdorff edistance is invariant under isometries. -/ theorem hausdorffEdist_image (h : Isometry Φ) : hausdorffEdist (Φ '' s) (Φ '' t) = hausdorffEdist s t := by simp only [hausdorffEdist_def, iSup_image, infEdist_image h] /-- The Hausdorff distance is controlled by the diameter of the union. -/ theorem hausdorffEdist_le_ediam (hs : s.Nonempty) (ht : t.Nonempty) : hausdorffEdist s t ≤ diam (s ∪ t) := by rcases hs with ⟨x, xs⟩ rcases ht with ⟨y, yt⟩ refine hausdorffEdist_le_of_mem_edist ?_ ?_ · intro z hz exact ⟨y, yt, edist_le_diam_of_mem (subset_union_left hz) (subset_union_right yt)⟩ · intro z hz exact ⟨x, xs, edist_le_diam_of_mem (subset_union_right hz) (subset_union_left xs)⟩ /-- The Hausdorff distance satisfies the triangle inequality. -/ theorem hausdorffEdist_triangle : hausdorffEdist s u ≤ hausdorffEdist s t + hausdorffEdist t u := by rw [hausdorffEdist_def] simp only [sup_le_iff, iSup_le_iff] constructor · show ∀ x ∈ s, infEdist x u ≤ hausdorffEdist s t + hausdorffEdist t u exact fun x xs => calc infEdist x u ≤ infEdist x t + hausdorffEdist t u := infEdist_le_infEdist_add_hausdorffEdist _ ≤ hausdorffEdist s t + hausdorffEdist t u := add_le_add_right (infEdist_le_hausdorffEdist_of_mem xs) _ · show ∀ x ∈ u, infEdist x s ≤ hausdorffEdist s t + hausdorffEdist t u exact fun x xu => calc infEdist x s ≤ infEdist x t + hausdorffEdist t s := infEdist_le_infEdist_add_hausdorffEdist _ ≤ hausdorffEdist u t + hausdorffEdist t s := add_le_add_right (infEdist_le_hausdorffEdist_of_mem xu) _ _ = hausdorffEdist s t + hausdorffEdist t u := by simp [hausdorffEdist_comm, add_comm] /-- Two sets are at zero Hausdorff edistance if and only if they have the same closure. -/ theorem hausdorffEdist_zero_iff_closure_eq_closure : hausdorffEdist s t = 0 ↔ closure s = closure t := by simp only [hausdorffEdist_def, ENNReal.sup_eq_zero, ENNReal.iSup_eq_zero, ← subset_def, ← mem_closure_iff_infEdist_zero, subset_antisymm_iff, isClosed_closure.closure_subset_iff] /-- The Hausdorff edistance between a set and its closure vanishes. -/ @[simp] theorem hausdorffEdist_self_closure : hausdorffEdist s (closure s) = 0 := by rw [hausdorffEdist_zero_iff_closure_eq_closure, closure_closure] /-- Replacing a set by its closure does not change the Hausdorff edistance. -/ @[simp] theorem hausdorffEdist_closure₁ : hausdorffEdist (closure s) t = hausdorffEdist s t := by refine le_antisymm ?_ ?_ · calc _ ≤ hausdorffEdist (closure s) s + hausdorffEdist s t := hausdorffEdist_triangle _ = hausdorffEdist s t := by simp [hausdorffEdist_comm] · calc _ ≤ hausdorffEdist s (closure s) + hausdorffEdist (closure s) t := hausdorffEdist_triangle _ = hausdorffEdist (closure s) t := by simp /-- Replacing a set by its closure does not change the Hausdorff edistance. -/ @[simp] theorem hausdorffEdist_closure₂ : hausdorffEdist s (closure t) = hausdorffEdist s t := by simp [@hausdorffEdist_comm _ _ s _] /-- The Hausdorff edistance between sets or their closures is the same. -/ theorem hausdorffEdist_closure : hausdorffEdist (closure s) (closure t) = hausdorffEdist s t := by simp /-- Two closed sets are at zero Hausdorff edistance if and only if they coincide. -/ theorem hausdorffEdist_zero_iff_eq_of_closed (hs : IsClosed s) (ht : IsClosed t) : hausdorffEdist s t = 0 ↔ s = t := by rw [hausdorffEdist_zero_iff_closure_eq_closure, hs.closure_eq, ht.closure_eq] /-- The Haudorff edistance to the empty set is infinite. -/ theorem hausdorffEdist_empty (ne : s.Nonempty) : hausdorffEdist s ∅ = ∞ := by rcases ne with ⟨x, xs⟩ have : infEdist x ∅ ≤ hausdorffEdist s ∅ := infEdist_le_hausdorffEdist_of_mem xs simpa using this /-- If a set is at finite Hausdorff edistance of a nonempty set, it is nonempty. -/ theorem nonempty_of_hausdorffEdist_ne_top (hs : s.Nonempty) (fin : hausdorffEdist s t ≠ ⊤) : t.Nonempty := t.eq_empty_or_nonempty.resolve_left fun ht ↦ fin (ht.symm ▸ hausdorffEdist_empty hs) theorem empty_or_nonempty_of_hausdorffEdist_ne_top (fin : hausdorffEdist s t ≠ ⊤) : (s = ∅ ∧ t = ∅) ∨ (s.Nonempty ∧ t.Nonempty) := by rcases s.eq_empty_or_nonempty with hs | hs · rcases t.eq_empty_or_nonempty with ht | ht · exact Or.inl ⟨hs, ht⟩ · rw [hausdorffEdist_comm] at fin exact Or.inr ⟨nonempty_of_hausdorffEdist_ne_top ht fin, ht⟩ · exact Or.inr ⟨hs, nonempty_of_hausdorffEdist_ne_top hs fin⟩ end HausdorffEdist -- section end EMetric /-! Now, we turn to the same notions in metric spaces. To avoid the difficulties related to `sInf` and `sSup` on `ℝ` (which is only conditionally complete), we use the notions in `ℝ≥0∞` formulated in terms of the edistance, and coerce them to `ℝ`. Then their properties follow readily from the corresponding properties in `ℝ≥0∞`, modulo some tedious rewriting of inequalities from one to the other. -/ --namespace namespace Metric section variable [PseudoMetricSpace α] [PseudoMetricSpace β] {s t u : Set α} {x y : α} {Φ : α → β} open EMetric /-! ### Distance of a point to a set as a function into `ℝ`. -/ /-- The minimal distance of a point to a set -/ def infDist (x : α) (s : Set α) : ℝ := ENNReal.toReal (infEdist x s) theorem infDist_eq_iInf : infDist x s = ⨅ y : s, dist x y := by rw [infDist, infEdist, iInf_subtype', ENNReal.toReal_iInf] · simp only [dist_edist] · exact fun _ ↦ edist_ne_top _ _ /-- The minimal distance is always nonnegative -/ theorem infDist_nonneg : 0 ≤ infDist x s := toReal_nonneg /-- The minimal distance to the empty set is 0 (if you want to have the more reasonable value `∞` instead, use `EMetric.infEdist`, which takes values in `ℝ≥0∞`) -/ @[simp] theorem infDist_empty : infDist x ∅ = 0 := by simp [infDist] lemma isGLB_infDist (hs : s.Nonempty) : IsGLB ((dist x ·) '' s) (infDist x s) := by simpa [infDist_eq_iInf, sInf_image'] using isGLB_csInf (hs.image _) ⟨0, by simp [lowerBounds, dist_nonneg]⟩ /-- In a metric space, the minimal edistance to a nonempty set is finite. -/ theorem infEdist_ne_top (h : s.Nonempty) : infEdist x s ≠ ⊤ := by rcases h with ⟨y, hy⟩ exact ne_top_of_le_ne_top (edist_ne_top _ _) (infEdist_le_edist_of_mem hy) @[simp] theorem infEdist_eq_top_iff : infEdist x s = ∞ ↔ s = ∅ := by rcases s.eq_empty_or_nonempty with rfl | hs <;> simp [*, Nonempty.ne_empty, infEdist_ne_top] /-- The minimal distance of a point to a set containing it vanishes. -/ theorem infDist_zero_of_mem (h : x ∈ s) : infDist x s = 0 := by simp [infEdist_zero_of_mem h, infDist] /-- The minimal distance to a singleton is the distance to the unique point in this singleton. -/ @[simp] theorem infDist_singleton : infDist x {y} = dist x y := by simp [infDist, dist_edist] /-- The minimal distance to a set is bounded by the distance to any point in this set. -/ theorem infDist_le_dist_of_mem (h : y ∈ s) : infDist x s ≤ dist x y := by rw [dist_edist, infDist] exact ENNReal.toReal_mono (edist_ne_top _ _) (infEdist_le_edist_of_mem h) /-- The minimal distance is monotone with respect to inclusion. -/ theorem infDist_le_infDist_of_subset (h : s ⊆ t) (hs : s.Nonempty) : infDist x t ≤ infDist x s := ENNReal.toReal_mono (infEdist_ne_top hs) (infEdist_anti h) lemma le_infDist {r : ℝ} (hs : s.Nonempty) : r ≤ infDist x s ↔ ∀ ⦃y⦄, y ∈ s → r ≤ dist x y := by simp_rw [infDist, ← ENNReal.ofReal_le_iff_le_toReal (infEdist_ne_top hs), le_infEdist, ENNReal.ofReal_le_iff_le_toReal (edist_ne_top _ _), ← dist_edist] /-- The minimal distance to a set `s` is `< r` iff there exists a point in `s` at distance `< r`. -/ theorem infDist_lt_iff {r : ℝ} (hs : s.Nonempty) : infDist x s < r ↔ ∃ y ∈ s, dist x y < r := by simp [← not_le, le_infDist hs] /-- The minimal distance from `x` to `s` is bounded by the distance from `y` to `s`, modulo the distance between `x` and `y`. -/ theorem infDist_le_infDist_add_dist : infDist x s ≤ infDist y s + dist x y := by rw [infDist, infDist, dist_edist] refine ENNReal.toReal_le_add' infEdist_le_infEdist_add_edist ?_ (flip absurd (edist_ne_top _ _)) simp only [infEdist_eq_top_iff, imp_self] theorem not_mem_of_dist_lt_infDist (h : dist x y < infDist x s) : y ∉ s := fun hy => h.not_le <| infDist_le_dist_of_mem hy theorem disjoint_ball_infDist : Disjoint (ball x (infDist x s)) s := disjoint_left.2 fun _y hy => not_mem_of_dist_lt_infDist <| mem_ball'.1 hy theorem ball_infDist_subset_compl : ball x (infDist x s) ⊆ sᶜ := (disjoint_ball_infDist (s := s)).subset_compl_right theorem ball_infDist_compl_subset : ball x (infDist x sᶜ) ⊆ s := ball_infDist_subset_compl.trans_eq (compl_compl s) theorem disjoint_closedBall_of_lt_infDist {r : ℝ} (h : r < infDist x s) : Disjoint (closedBall x r) s := disjoint_ball_infDist.mono_left <| closedBall_subset_ball h theorem dist_le_infDist_add_diam (hs : IsBounded s) (hy : y ∈ s) : dist x y ≤ infDist x s + diam s := by rw [infDist, diam, dist_edist] exact toReal_le_add (edist_le_infEdist_add_ediam hy) (infEdist_ne_top ⟨y, hy⟩) hs.ediam_ne_top variable (s) /-- The minimal distance to a set is Lipschitz in point with constant 1 -/ theorem lipschitz_infDist_pt : LipschitzWith 1 (infDist · s) := LipschitzWith.of_le_add fun _ _ => infDist_le_infDist_add_dist /-- The minimal distance to a set is uniformly continuous in point -/ theorem uniformContinuous_infDist_pt : UniformContinuous (infDist · s) := (lipschitz_infDist_pt s).uniformContinuous /-- The minimal distance to a set is continuous in point -/ @[continuity] theorem continuous_infDist_pt : Continuous (infDist · s) := (uniformContinuous_infDist_pt s).continuous variable {s} /-- The minimal distances to a set and its closure coincide. -/ theorem infDist_closure : infDist x (closure s) = infDist x s := by simp [infDist, infEdist_closure] /-- If a point belongs to the closure of `s`, then its infimum distance to `s` equals zero. The converse is true provided that `s` is nonempty, see `Metric.mem_closure_iff_infDist_zero`. -/ theorem infDist_zero_of_mem_closure (hx : x ∈ closure s) : infDist x s = 0 := by rw [← infDist_closure] exact infDist_zero_of_mem hx /-- A point belongs to the closure of `s` iff its infimum distance to this set vanishes. -/ theorem mem_closure_iff_infDist_zero (h : s.Nonempty) : x ∈ closure s ↔ infDist x s = 0 := by simp [mem_closure_iff_infEdist_zero, infDist, ENNReal.toReal_eq_zero_iff, infEdist_ne_top h] theorem infDist_pos_iff_not_mem_closure (hs : s.Nonempty) : x ∉ closure s ↔ 0 < infDist x s := (mem_closure_iff_infDist_zero hs).not.trans infDist_nonneg.gt_iff_ne.symm /-- Given a closed set `s`, a point belongs to `s` iff its infimum distance to this set vanishes -/ theorem _root_.IsClosed.mem_iff_infDist_zero (h : IsClosed s) (hs : s.Nonempty) : x ∈ s ↔ infDist x s = 0 := by rw [← mem_closure_iff_infDist_zero hs, h.closure_eq] /-- Given a closed set `s`, a point belongs to `s` iff its infimum distance to this set vanishes. -/ theorem _root_.IsClosed.not_mem_iff_infDist_pos (h : IsClosed s) (hs : s.Nonempty) : x ∉ s ↔ 0 < infDist x s := by simp [h.mem_iff_infDist_zero hs, infDist_nonneg.gt_iff_ne] theorem continuousAt_inv_infDist_pt (h : x ∉ closure s) : ContinuousAt (fun x ↦ (infDist x s)⁻¹) x := by rcases s.eq_empty_or_nonempty with (rfl | hs) · simp only [infDist_empty, continuousAt_const] · refine (continuous_infDist_pt s).continuousAt.inv₀ ?_ rwa [Ne, ← mem_closure_iff_infDist_zero hs] /-- The infimum distance is invariant under isometries. -/ theorem infDist_image (hΦ : Isometry Φ) : infDist (Φ x) (Φ '' t) = infDist x t := by simp [infDist, infEdist_image hΦ] theorem infDist_inter_closedBall_of_mem (h : y ∈ s) : infDist x (s ∩ closedBall x (dist y x)) = infDist x s := by replace h : y ∈ s ∩ closedBall x (dist y x) := ⟨h, mem_closedBall.2 le_rfl⟩ refine le_antisymm ?_ (infDist_le_infDist_of_subset inter_subset_left ⟨y, h⟩) refine not_lt.1 fun hlt => ?_ rcases (infDist_lt_iff ⟨y, h.1⟩).mp hlt with ⟨z, hzs, hz⟩ rcases le_or_lt (dist z x) (dist y x) with hle | hlt · exact hz.not_le (infDist_le_dist_of_mem ⟨hzs, hle⟩) · rw [dist_comm z, dist_comm y] at hlt exact (hlt.trans hz).not_le (infDist_le_dist_of_mem h) theorem _root_.IsCompact.exists_infDist_eq_dist (h : IsCompact s) (hne : s.Nonempty) (x : α) : ∃ y ∈ s, infDist x s = dist x y := let ⟨y, hys, hy⟩ := h.exists_infEdist_eq_edist hne x ⟨y, hys, by rw [infDist, dist_edist, hy]⟩ theorem _root_.IsClosed.exists_infDist_eq_dist [ProperSpace α] (h : IsClosed s) (hne : s.Nonempty) (x : α) : ∃ y ∈ s, infDist x s = dist x y := by rcases hne with ⟨z, hz⟩ rw [← infDist_inter_closedBall_of_mem hz] set t := s ∩ closedBall x (dist z x) have htc : IsCompact t := (isCompact_closedBall x (dist z x)).inter_left h have htne : t.Nonempty := ⟨z, hz, mem_closedBall.2 le_rfl⟩ obtain ⟨y, ⟨hys, -⟩, hyd⟩ : ∃ y ∈ t, infDist x t = dist x y := htc.exists_infDist_eq_dist htne x exact ⟨y, hys, hyd⟩ theorem exists_mem_closure_infDist_eq_dist [ProperSpace α] (hne : s.Nonempty) (x : α) : ∃ y ∈ closure s, infDist x s = dist x y := by simpa only [infDist_closure] using isClosed_closure.exists_infDist_eq_dist hne.closure x /-! ### Distance of a point to a set as a function into `ℝ≥0`. -/ /-- The minimal distance of a point to a set as a `ℝ≥0` -/ def infNndist (x : α) (s : Set α) : ℝ≥0 := ENNReal.toNNReal (infEdist x s) @[simp] theorem coe_infNndist : (infNndist x s : ℝ) = infDist x s := rfl
/-- The minimal distance to a set (as `ℝ≥0`) is Lipschitz in point with constant 1 -/ theorem lipschitz_infNndist_pt (s : Set α) : LipschitzWith 1 fun x => infNndist x s :=
Mathlib/Topology/MetricSpace/HausdorffDistance.lean
609
610
/- 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 -/ import Aesop import Mathlib.Order.BoundedOrder.Lattice /-! # Disjointness and complements This file defines `Disjoint`, `Codisjoint`, and the `IsCompl` predicate. ## Main declarations * `Disjoint x y`: two elements of a lattice are disjoint if their `inf` is the bottom element. * `Codisjoint x y`: two elements of a lattice are codisjoint if their `join` is the top element. * `IsCompl x y`: In a bounded lattice, predicate for "`x` is a complement of `y`". Note that in a non distributive lattice, an element can have several complements. * `ComplementedLattice α`: Typeclass stating that any element of a lattice has a complement. -/ open Function variable {α : Type*} section Disjoint section PartialOrderBot variable [PartialOrder α] [OrderBot α] {a b c d : α} /-- Two elements of a lattice are disjoint if their inf is the bottom element. (This generalizes disjoint sets, viewed as members of the subset lattice.) Note that we define this without reference to `⊓`, as this allows us to talk about orders where the infimum is not unique, or where implementing `Inf` would require additional `Decidable` arguments. -/ def Disjoint (a b : α) : Prop := ∀ ⦃x⦄, x ≤ a → x ≤ b → x ≤ ⊥ @[simp] theorem disjoint_of_subsingleton [Subsingleton α] : Disjoint a b := fun x _ _ ↦ le_of_eq (Subsingleton.elim x ⊥) theorem disjoint_comm : Disjoint a b ↔ Disjoint b a := forall_congr' fun _ ↦ forall_swap @[symm] theorem Disjoint.symm ⦃a b : α⦄ : Disjoint a b → Disjoint b a := disjoint_comm.1 theorem symmetric_disjoint : Symmetric (Disjoint : α → α → Prop) := Disjoint.symm @[simp] theorem disjoint_bot_left : Disjoint ⊥ a := fun _ hbot _ ↦ hbot @[simp] theorem disjoint_bot_right : Disjoint a ⊥ := fun _ _ hbot ↦ hbot theorem Disjoint.mono (h₁ : a ≤ b) (h₂ : c ≤ d) : Disjoint b d → Disjoint a c := fun h _ ha hc ↦ h (ha.trans h₁) (hc.trans h₂) theorem Disjoint.mono_left (h : a ≤ b) : Disjoint b c → Disjoint a c := Disjoint.mono h le_rfl theorem Disjoint.mono_right : b ≤ c → Disjoint a c → Disjoint a b := Disjoint.mono le_rfl @[simp] theorem disjoint_self : Disjoint a a ↔ a = ⊥ := ⟨fun hd ↦ bot_unique <| hd le_rfl le_rfl, fun h _ ha _ ↦ ha.trans_eq h⟩ /- TODO: Rename `Disjoint.eq_bot` to `Disjoint.inf_eq` and `Disjoint.eq_bot_of_self` to `Disjoint.eq_bot` -/ alias ⟨Disjoint.eq_bot_of_self, _⟩ := disjoint_self theorem Disjoint.ne (ha : a ≠ ⊥) (hab : Disjoint a b) : a ≠ b := fun h ↦ ha <| disjoint_self.1 <| by rwa [← h] at hab theorem Disjoint.eq_bot_of_le (hab : Disjoint a b) (h : a ≤ b) : a = ⊥ := eq_bot_iff.2 <| hab le_rfl h theorem Disjoint.eq_bot_of_ge (hab : Disjoint a b) : b ≤ a → b = ⊥ := hab.symm.eq_bot_of_le lemma Disjoint.eq_iff (hab : Disjoint a b) : a = b ↔ a = ⊥ ∧ b = ⊥ := by aesop lemma Disjoint.ne_iff (hab : Disjoint a b) : a ≠ b ↔ a ≠ ⊥ ∨ b ≠ ⊥ := hab.eq_iff.not.trans not_and_or theorem disjoint_of_le_iff_left_eq_bot (h : a ≤ b) : Disjoint a b ↔ a = ⊥ := ⟨fun hd ↦ hd.eq_bot_of_le h, fun h ↦ h ▸ disjoint_bot_left⟩ end PartialOrderBot section PartialBoundedOrder variable [PartialOrder α] [BoundedOrder α] {a : α} @[simp] theorem disjoint_top : Disjoint a ⊤ ↔ a = ⊥ := ⟨fun h ↦ bot_unique <| h le_rfl le_top, fun h _ ha _ ↦ ha.trans_eq h⟩ @[simp] theorem top_disjoint : Disjoint ⊤ a ↔ a = ⊥ := ⟨fun h ↦ bot_unique <| h le_top le_rfl, fun h _ _ ha ↦ ha.trans_eq h⟩ end PartialBoundedOrder section SemilatticeInfBot variable [SemilatticeInf α] [OrderBot α] {a b c : α} theorem disjoint_iff_inf_le : Disjoint a b ↔ a ⊓ b ≤ ⊥ := ⟨fun hd ↦ hd inf_le_left inf_le_right, fun h _ ha hb ↦ (le_inf ha hb).trans h⟩ theorem disjoint_iff : Disjoint a b ↔ a ⊓ b = ⊥ := disjoint_iff_inf_le.trans le_bot_iff theorem Disjoint.le_bot : Disjoint a b → a ⊓ b ≤ ⊥ := disjoint_iff_inf_le.mp theorem Disjoint.eq_bot : Disjoint a b → a ⊓ b = ⊥ := bot_unique ∘ Disjoint.le_bot theorem disjoint_assoc : Disjoint (a ⊓ b) c ↔ Disjoint a (b ⊓ c) := by rw [disjoint_iff_inf_le, disjoint_iff_inf_le, inf_assoc] theorem disjoint_left_comm : Disjoint a (b ⊓ c) ↔ Disjoint b (a ⊓ c) := by simp_rw [disjoint_iff_inf_le, inf_left_comm] theorem disjoint_right_comm : Disjoint (a ⊓ b) c ↔ Disjoint (a ⊓ c) b := by simp_rw [disjoint_iff_inf_le, inf_right_comm] variable (c) theorem Disjoint.inf_left (h : Disjoint a b) : Disjoint (a ⊓ c) b := h.mono_left inf_le_left theorem Disjoint.inf_left' (h : Disjoint a b) : Disjoint (c ⊓ a) b := h.mono_left inf_le_right theorem Disjoint.inf_right (h : Disjoint a b) : Disjoint a (b ⊓ c) := h.mono_right inf_le_left theorem Disjoint.inf_right' (h : Disjoint a b) : Disjoint a (c ⊓ b) := h.mono_right inf_le_right variable {c} theorem Disjoint.of_disjoint_inf_of_le (h : Disjoint (a ⊓ b) c) (hle : a ≤ c) : Disjoint a b := disjoint_iff.2 <| h.eq_bot_of_le <| inf_le_of_left_le hle theorem Disjoint.of_disjoint_inf_of_le' (h : Disjoint (a ⊓ b) c) (hle : b ≤ c) : Disjoint a b := disjoint_iff.2 <| h.eq_bot_of_le <| inf_le_of_right_le hle end SemilatticeInfBot theorem Disjoint.right_lt_sup_of_left_ne_bot [SemilatticeSup α] [OrderBot α] {a b : α} (h : Disjoint a b) (ha : a ≠ ⊥) : b < a ⊔ b := le_sup_right.lt_of_ne fun eq ↦ ha (le_bot_iff.mp <| h le_rfl <| sup_eq_right.mp eq.symm) section DistribLatticeBot variable [DistribLattice α] [OrderBot α] {a b c : α} @[simp] theorem disjoint_sup_left : Disjoint (a ⊔ b) c ↔ Disjoint a c ∧ Disjoint b c := by simp only [disjoint_iff, inf_sup_right, sup_eq_bot_iff] @[simp] theorem disjoint_sup_right : Disjoint a (b ⊔ c) ↔ Disjoint a b ∧ Disjoint a c := by simp only [disjoint_iff, inf_sup_left, sup_eq_bot_iff] theorem Disjoint.sup_left (ha : Disjoint a c) (hb : Disjoint b c) : Disjoint (a ⊔ b) c := disjoint_sup_left.2 ⟨ha, hb⟩ theorem Disjoint.sup_right (hb : Disjoint a b) (hc : Disjoint a c) : Disjoint a (b ⊔ c) := disjoint_sup_right.2 ⟨hb, hc⟩ theorem Disjoint.left_le_of_le_sup_right (h : a ≤ b ⊔ c) (hd : Disjoint a c) : a ≤ b := le_of_inf_le_sup_le (le_trans hd.le_bot bot_le) <| sup_le h le_sup_right theorem Disjoint.left_le_of_le_sup_left (h : a ≤ c ⊔ b) (hd : Disjoint a c) : a ≤ b := hd.left_le_of_le_sup_right <| by rwa [sup_comm] end DistribLatticeBot end Disjoint section Codisjoint section PartialOrderTop variable [PartialOrder α] [OrderTop α] {a b c d : α} /-- Two elements of a lattice are codisjoint if their sup is the top element. Note that we define this without reference to `⊔`, as this allows us to talk about orders where the supremum is not unique, or where implement `Sup` would require additional `Decidable` arguments. -/ def Codisjoint (a b : α) : Prop := ∀ ⦃x⦄, a ≤ x → b ≤ x → ⊤ ≤ x theorem codisjoint_comm : Codisjoint a b ↔ Codisjoint b a := forall_congr' fun _ ↦ forall_swap @[deprecated (since := "2024-11-23")] alias Codisjoint_comm := codisjoint_comm @[symm] theorem Codisjoint.symm ⦃a b : α⦄ : Codisjoint a b → Codisjoint b a := codisjoint_comm.1 theorem symmetric_codisjoint : Symmetric (Codisjoint : α → α → Prop) := Codisjoint.symm @[simp] theorem codisjoint_top_left : Codisjoint ⊤ a := fun _ htop _ ↦ htop @[simp] theorem codisjoint_top_right : Codisjoint a ⊤ := fun _ _ htop ↦ htop theorem Codisjoint.mono (h₁ : a ≤ b) (h₂ : c ≤ d) : Codisjoint a c → Codisjoint b d := fun h _ ha hc ↦ h (h₁.trans ha) (h₂.trans hc) theorem Codisjoint.mono_left (h : a ≤ b) : Codisjoint a c → Codisjoint b c := Codisjoint.mono h le_rfl theorem Codisjoint.mono_right : b ≤ c → Codisjoint a b → Codisjoint a c := Codisjoint.mono le_rfl @[simp] theorem codisjoint_self : Codisjoint a a ↔ a = ⊤ := ⟨fun hd ↦ top_unique <| hd le_rfl le_rfl, fun h _ ha _ ↦ h.symm.trans_le ha⟩ /- TODO: Rename `Codisjoint.eq_top` to `Codisjoint.sup_eq` and `Codisjoint.eq_top_of_self` to `Codisjoint.eq_top` -/ alias ⟨Codisjoint.eq_top_of_self, _⟩ := codisjoint_self theorem Codisjoint.ne (ha : a ≠ ⊤) (hab : Codisjoint a b) : a ≠ b := fun h ↦ ha <| codisjoint_self.1 <| by rwa [← h] at hab theorem Codisjoint.eq_top_of_le (hab : Codisjoint a b) (h : b ≤ a) : a = ⊤ := eq_top_iff.2 <| hab le_rfl h theorem Codisjoint.eq_top_of_ge (hab : Codisjoint a b) : a ≤ b → b = ⊤ := hab.symm.eq_top_of_le lemma Codisjoint.eq_iff (hab : Codisjoint a b) : a = b ↔ a = ⊤ ∧ b = ⊤ := by aesop lemma Codisjoint.ne_iff (hab : Codisjoint a b) : a ≠ b ↔ a ≠ ⊤ ∨ b ≠ ⊤ := hab.eq_iff.not.trans not_and_or end PartialOrderTop section PartialBoundedOrder variable [PartialOrder α] [BoundedOrder α] {a b : α} @[simp] theorem codisjoint_bot : Codisjoint a ⊥ ↔ a = ⊤ := ⟨fun h ↦ top_unique <| h le_rfl bot_le, fun h _ ha _ ↦ h.symm.trans_le ha⟩ @[simp] theorem bot_codisjoint : Codisjoint ⊥ a ↔ a = ⊤ := ⟨fun h ↦ top_unique <| h bot_le le_rfl, fun h _ _ ha ↦ h.symm.trans_le ha⟩ lemma Codisjoint.ne_bot_of_ne_top (h : Codisjoint a b) (ha : a ≠ ⊤) : b ≠ ⊥ := by rintro rfl; exact ha <| by simpa using h lemma Codisjoint.ne_bot_of_ne_top' (h : Codisjoint a b) (hb : b ≠ ⊤) : a ≠ ⊥ := by rintro rfl; exact hb <| by simpa using h end PartialBoundedOrder section SemilatticeSupTop variable [SemilatticeSup α] [OrderTop α] {a b c : α} theorem codisjoint_iff_le_sup : Codisjoint a b ↔ ⊤ ≤ a ⊔ b := @disjoint_iff_inf_le αᵒᵈ _ _ _ _ theorem codisjoint_iff : Codisjoint a b ↔ a ⊔ b = ⊤ := @disjoint_iff αᵒᵈ _ _ _ _ theorem Codisjoint.top_le : Codisjoint a b → ⊤ ≤ a ⊔ b := @Disjoint.le_bot αᵒᵈ _ _ _ _ theorem Codisjoint.eq_top : Codisjoint a b → a ⊔ b = ⊤ := @Disjoint.eq_bot αᵒᵈ _ _ _ _ theorem codisjoint_assoc : Codisjoint (a ⊔ b) c ↔ Codisjoint a (b ⊔ c) := @disjoint_assoc αᵒᵈ _ _ _ _ _ theorem codisjoint_left_comm : Codisjoint a (b ⊔ c) ↔ Codisjoint b (a ⊔ c) := @disjoint_left_comm αᵒᵈ _ _ _ _ _ theorem codisjoint_right_comm : Codisjoint (a ⊔ b) c ↔ Codisjoint (a ⊔ c) b := @disjoint_right_comm αᵒᵈ _ _ _ _ _ variable (c) theorem Codisjoint.sup_left (h : Codisjoint a b) : Codisjoint (a ⊔ c) b := h.mono_left le_sup_left theorem Codisjoint.sup_left' (h : Codisjoint a b) : Codisjoint (c ⊔ a) b := h.mono_left le_sup_right theorem Codisjoint.sup_right (h : Codisjoint a b) : Codisjoint a (b ⊔ c) := h.mono_right le_sup_left theorem Codisjoint.sup_right' (h : Codisjoint a b) : Codisjoint a (c ⊔ b) := h.mono_right le_sup_right variable {c} theorem Codisjoint.of_codisjoint_sup_of_le (h : Codisjoint (a ⊔ b) c) (hle : c ≤ a) : Codisjoint a b := @Disjoint.of_disjoint_inf_of_le αᵒᵈ _ _ _ _ _ h hle theorem Codisjoint.of_codisjoint_sup_of_le' (h : Codisjoint (a ⊔ b) c) (hle : c ≤ b) : Codisjoint a b := @Disjoint.of_disjoint_inf_of_le' αᵒᵈ _ _ _ _ _ h hle end SemilatticeSupTop section DistribLatticeTop variable [DistribLattice α] [OrderTop α] {a b c : α} @[simp] theorem codisjoint_inf_left : Codisjoint (a ⊓ b) c ↔ Codisjoint a c ∧ Codisjoint b c := by simp only [codisjoint_iff, sup_inf_right, inf_eq_top_iff] @[simp] theorem codisjoint_inf_right : Codisjoint a (b ⊓ c) ↔ Codisjoint a b ∧ Codisjoint a c := by simp only [codisjoint_iff, sup_inf_left, inf_eq_top_iff] theorem Codisjoint.inf_left (ha : Codisjoint a c) (hb : Codisjoint b c) : Codisjoint (a ⊓ b) c := codisjoint_inf_left.2 ⟨ha, hb⟩ theorem Codisjoint.inf_right (hb : Codisjoint a b) (hc : Codisjoint a c) : Codisjoint a (b ⊓ c) := codisjoint_inf_right.2 ⟨hb, hc⟩ theorem Codisjoint.left_le_of_le_inf_right (h : a ⊓ b ≤ c) (hd : Codisjoint b c) : a ≤ c := @Disjoint.left_le_of_le_sup_right αᵒᵈ _ _ _ _ _ h hd.symm theorem Codisjoint.left_le_of_le_inf_left (h : b ⊓ a ≤ c) (hd : Codisjoint b c) : a ≤ c := hd.left_le_of_le_inf_right <| by rwa [inf_comm] end DistribLatticeTop end Codisjoint open OrderDual theorem Disjoint.dual [PartialOrder α] [OrderBot α] {a b : α} : Disjoint a b → Codisjoint (toDual a) (toDual b) := id theorem Codisjoint.dual [PartialOrder α] [OrderTop α] {a b : α} : Codisjoint a b → Disjoint (toDual a) (toDual b) := id @[simp] theorem disjoint_toDual_iff [PartialOrder α] [OrderTop α] {a b : α} : Disjoint (toDual a) (toDual b) ↔ Codisjoint a b := Iff.rfl @[simp] theorem disjoint_ofDual_iff [PartialOrder α] [OrderBot α] {a b : αᵒᵈ} : Disjoint (ofDual a) (ofDual b) ↔ Codisjoint a b := Iff.rfl @[simp] theorem codisjoint_toDual_iff [PartialOrder α] [OrderBot α] {a b : α} : Codisjoint (toDual a) (toDual b) ↔ Disjoint a b := Iff.rfl @[simp] theorem codisjoint_ofDual_iff [PartialOrder α] [OrderTop α] {a b : αᵒᵈ} : Codisjoint (ofDual a) (ofDual b) ↔ Disjoint a b := Iff.rfl section DistribLattice variable [DistribLattice α] [BoundedOrder α] {a b c : α} theorem Disjoint.le_of_codisjoint (hab : Disjoint a b) (hbc : Codisjoint b c) : a ≤ c := by rw [← @inf_top_eq _ _ _ a, ← @bot_sup_eq _ _ _ c, ← hab.eq_bot, ← hbc.eq_top, sup_inf_right] exact inf_le_inf_right _ le_sup_left end DistribLattice section IsCompl /-- Two elements `x` and `y` are complements of each other if `x ⊔ y = ⊤` and `x ⊓ y = ⊥`. -/ structure IsCompl [PartialOrder α] [BoundedOrder α] (x y : α) : Prop where /-- If `x` and `y` are to be complementary in an order, they should be disjoint. -/ protected disjoint : Disjoint x y /-- If `x` and `y` are to be complementary in an order, they should be codisjoint. -/ protected codisjoint : Codisjoint x y theorem isCompl_iff [PartialOrder α] [BoundedOrder α] {a b : α} : IsCompl a b ↔ Disjoint a b ∧ Codisjoint a b := ⟨fun h ↦ ⟨h.1, h.2⟩, fun h ↦ ⟨h.1, h.2⟩⟩ namespace IsCompl section BoundedPartialOrder variable [PartialOrder α] [BoundedOrder α] {x y : α} @[symm] protected theorem symm (h : IsCompl x y) : IsCompl y x := ⟨h.1.symm, h.2.symm⟩ lemma _root_.isCompl_comm : IsCompl x y ↔ IsCompl y x := ⟨IsCompl.symm, IsCompl.symm⟩ theorem dual (h : IsCompl x y) : IsCompl (toDual x) (toDual y) := ⟨h.2, h.1⟩ theorem ofDual {a b : αᵒᵈ} (h : IsCompl a b) : IsCompl (ofDual a) (ofDual b) := ⟨h.2, h.1⟩ end BoundedPartialOrder section BoundedLattice variable [Lattice α] [BoundedOrder α] {x y : α} theorem of_le (h₁ : x ⊓ y ≤ ⊥) (h₂ : ⊤ ≤ x ⊔ y) : IsCompl x y := ⟨disjoint_iff_inf_le.mpr h₁, codisjoint_iff_le_sup.mpr h₂⟩ theorem of_eq (h₁ : x ⊓ y = ⊥) (h₂ : x ⊔ y = ⊤) : IsCompl x y := ⟨disjoint_iff.mpr h₁, codisjoint_iff.mpr h₂⟩ theorem inf_eq_bot (h : IsCompl x y) : x ⊓ y = ⊥ := h.disjoint.eq_bot theorem sup_eq_top (h : IsCompl x y) : x ⊔ y = ⊤ := h.codisjoint.eq_top end BoundedLattice variable [DistribLattice α] [BoundedOrder α] {a b x y z : α} theorem inf_left_le_of_le_sup_right (h : IsCompl x y) (hle : a ≤ b ⊔ y) : a ⊓ x ≤ b := calc a ⊓ x ≤ (b ⊔ y) ⊓ x := inf_le_inf hle le_rfl _ = b ⊓ x ⊔ y ⊓ x := inf_sup_right _ _ _ _ = b ⊓ x := by rw [h.symm.inf_eq_bot, sup_bot_eq] _ ≤ b := inf_le_left theorem le_sup_right_iff_inf_left_le {a b} (h : IsCompl x y) : a ≤ b ⊔ y ↔ a ⊓ x ≤ b := ⟨h.inf_left_le_of_le_sup_right, h.symm.dual.inf_left_le_of_le_sup_right⟩ theorem inf_left_eq_bot_iff (h : IsCompl y z) : x ⊓ y = ⊥ ↔ x ≤ z := by rw [← le_bot_iff, ← h.le_sup_right_iff_inf_left_le, bot_sup_eq] theorem inf_right_eq_bot_iff (h : IsCompl y z) : x ⊓ z = ⊥ ↔ x ≤ y := h.symm.inf_left_eq_bot_iff theorem disjoint_left_iff (h : IsCompl y z) : Disjoint x y ↔ x ≤ z := by rw [disjoint_iff] exact h.inf_left_eq_bot_iff theorem disjoint_right_iff (h : IsCompl y z) : Disjoint x z ↔ x ≤ y := h.symm.disjoint_left_iff theorem le_left_iff (h : IsCompl x y) : z ≤ x ↔ Disjoint z y := h.disjoint_right_iff.symm theorem le_right_iff (h : IsCompl x y) : z ≤ y ↔ Disjoint z x := h.symm.le_left_iff theorem left_le_iff (h : IsCompl x y) : x ≤ z ↔ Codisjoint z y := h.dual.le_left_iff theorem right_le_iff (h : IsCompl x y) : y ≤ z ↔ Codisjoint z x := h.symm.left_le_iff protected theorem Antitone {x' y'} (h : IsCompl x y) (h' : IsCompl x' y') (hx : x ≤ x') : y' ≤ y := h'.right_le_iff.2 <| h.symm.codisjoint.mono_right hx theorem right_unique (hxy : IsCompl x y) (hxz : IsCompl x z) : y = z := le_antisymm (hxz.Antitone hxy <| le_refl x) (hxy.Antitone hxz <| le_refl x) theorem left_unique (hxz : IsCompl x z) (hyz : IsCompl y z) : x = y := hxz.symm.right_unique hyz.symm theorem sup_inf {x' y'} (h : IsCompl x y) (h' : IsCompl x' y') : IsCompl (x ⊔ x') (y ⊓ y') := of_eq (by rw [inf_sup_right, ← inf_assoc, h.inf_eq_bot, bot_inf_eq, bot_sup_eq, inf_left_comm, h'.inf_eq_bot, inf_bot_eq]) (by rw [sup_inf_left, sup_comm x, sup_assoc, h.sup_eq_top, sup_top_eq, top_inf_eq, sup_assoc, sup_left_comm, h'.sup_eq_top, sup_top_eq]) theorem inf_sup {x' y'} (h : IsCompl x y) (h' : IsCompl x' y') : IsCompl (x ⊓ x') (y ⊔ y') := (h.symm.sup_inf h'.symm).symm end IsCompl namespace Prod variable {β : Type*} [PartialOrder α] [PartialOrder β] protected theorem disjoint_iff [OrderBot α] [OrderBot β] {x y : α × β} : Disjoint x y ↔ Disjoint x.1 y.1 ∧ Disjoint x.2 y.2 := by constructor · intro h refine ⟨fun a hx hy ↦ (@h (a, ⊥) ⟨hx, ?_⟩ ⟨hy, ?_⟩).1, fun b hx hy ↦ (@h (⊥, b) ⟨?_, hx⟩ ⟨?_, hy⟩).2⟩ all_goals exact bot_le · rintro ⟨ha, hb⟩ z hza hzb exact ⟨ha hza.1 hzb.1, hb hza.2 hzb.2⟩ protected theorem codisjoint_iff [OrderTop α] [OrderTop β] {x y : α × β} : Codisjoint x y ↔ Codisjoint x.1 y.1 ∧ Codisjoint x.2 y.2 := @Prod.disjoint_iff αᵒᵈ βᵒᵈ _ _ _ _ _ _ protected theorem isCompl_iff [BoundedOrder α] [BoundedOrder β] {x y : α × β} : IsCompl x y ↔ IsCompl x.1 y.1 ∧ IsCompl x.2 y.2 := by simp_rw [isCompl_iff, Prod.disjoint_iff, Prod.codisjoint_iff, and_and_and_comm] end Prod section variable [Lattice α] [BoundedOrder α] {a b x : α} @[simp] theorem isCompl_toDual_iff : IsCompl (toDual a) (toDual b) ↔ IsCompl a b := ⟨IsCompl.ofDual, IsCompl.dual⟩ @[simp] theorem isCompl_ofDual_iff {a b : αᵒᵈ} : IsCompl (ofDual a) (ofDual b) ↔ IsCompl a b := ⟨IsCompl.dual, IsCompl.ofDual⟩ theorem isCompl_bot_top : IsCompl (⊥ : α) ⊤ := IsCompl.of_eq (bot_inf_eq _) (sup_top_eq _) theorem isCompl_top_bot : IsCompl (⊤ : α) ⊥ := IsCompl.of_eq (inf_bot_eq _) (top_sup_eq _) theorem eq_top_of_isCompl_bot (h : IsCompl x ⊥) : x = ⊤ := by rw [← sup_bot_eq x, h.sup_eq_top] theorem eq_top_of_bot_isCompl (h : IsCompl ⊥ x) : x = ⊤ := eq_top_of_isCompl_bot h.symm theorem eq_bot_of_isCompl_top (h : IsCompl x ⊤) : x = ⊥ := eq_top_of_isCompl_bot h.dual theorem eq_bot_of_top_isCompl (h : IsCompl ⊤ x) : x = ⊥ := eq_top_of_bot_isCompl h.dual end section IsComplemented section Lattice variable [Lattice α] [BoundedOrder α] /-- An element is *complemented* if it has a complement. -/ def IsComplemented (a : α) : Prop := ∃ b, IsCompl a b theorem isComplemented_bot : IsComplemented (⊥ : α) := ⟨⊤, isCompl_bot_top⟩ theorem isComplemented_top : IsComplemented (⊤ : α) := ⟨⊥, isCompl_top_bot⟩ end Lattice variable [DistribLattice α] [BoundedOrder α] {a b : α} theorem IsComplemented.sup : IsComplemented a → IsComplemented b → IsComplemented (a ⊔ b) := fun ⟨a', ha⟩ ⟨b', hb⟩ => ⟨a' ⊓ b', ha.sup_inf hb⟩ theorem IsComplemented.inf : IsComplemented a → IsComplemented b → IsComplemented (a ⊓ b) := fun ⟨a', ha⟩ ⟨b', hb⟩ => ⟨a' ⊔ b', ha.inf_sup hb⟩ end IsComplemented /-- A complemented bounded lattice is one where every element has a (not necessarily unique) complement. -/ class ComplementedLattice (α) [Lattice α] [BoundedOrder α] : Prop where /-- In a `ComplementedLattice`, every element admits a complement. -/ exists_isCompl : ∀ a : α, ∃ b : α, IsCompl a b lemma complementedLattice_iff (α) [Lattice α] [BoundedOrder α] : ComplementedLattice α ↔ ∀ a : α, ∃ b : α, IsCompl a b := ⟨fun ⟨h⟩ ↦ h, fun h ↦ ⟨h⟩⟩ export ComplementedLattice (exists_isCompl) instance Subsingleton.instComplementedLattice [Lattice α] [BoundedOrder α] [Subsingleton α] : ComplementedLattice α := by refine ⟨fun a ↦ ⟨⊥, disjoint_bot_right, ?_⟩⟩ rw [Subsingleton.elim ⊥ ⊤] exact codisjoint_top_right namespace ComplementedLattice variable [Lattice α] [BoundedOrder α] [ComplementedLattice α] instance : ComplementedLattice αᵒᵈ := ⟨fun a ↦ let ⟨b, hb⟩ := exists_isCompl (show α from a) ⟨b, hb.dual⟩⟩ end ComplementedLattice -- TODO: Define as a sublattice? /-- The sublattice of complemented elements. -/ abbrev Complementeds (α : Type*) [Lattice α] [BoundedOrder α] : Type _ := {a : α // IsComplemented a} namespace Complementeds section Lattice variable [Lattice α] [BoundedOrder α] {a b : Complementeds α} instance hasCoeT : CoeTC (Complementeds α) α := ⟨Subtype.val⟩ theorem coe_injective : Injective ((↑) : Complementeds α → α) := Subtype.coe_injective @[simp, norm_cast] theorem coe_inj : (a : α) = b ↔ a = b := Subtype.coe_inj @[norm_cast] theorem coe_le_coe : (a : α) ≤ b ↔ a ≤ b := by simp @[norm_cast] theorem coe_lt_coe : (a : α) < b ↔ a < b := by simp instance : BoundedOrder (Complementeds α) := Subtype.boundedOrder isComplemented_bot isComplemented_top @[simp, norm_cast] theorem coe_bot : ((⊥ : Complementeds α) : α) = ⊥ := rfl @[simp, norm_cast] theorem coe_top : ((⊤ : Complementeds α) : α) = ⊤ := rfl theorem mk_bot : (⟨⊥, isComplemented_bot⟩ : Complementeds α) = ⊥ := by simp theorem mk_top : (⟨⊤, isComplemented_top⟩ : Complementeds α) = ⊤ := by simp instance : Inhabited (Complementeds α) := ⟨⊥⟩ end Lattice variable [DistribLattice α] [BoundedOrder α] {a b : Complementeds α} instance : Max (Complementeds α) := ⟨fun a b => ⟨a ⊔ b, a.2.sup b.2⟩⟩ instance : Min (Complementeds α) := ⟨fun a b => ⟨a ⊓ b, a.2.inf b.2⟩⟩ @[simp, norm_cast] theorem coe_sup (a b : Complementeds α) : ↑(a ⊔ b) = (a : α) ⊔ b := rfl @[simp, norm_cast] theorem coe_inf (a b : Complementeds α) : ↑(a ⊓ b) = (a : α) ⊓ b := rfl @[simp] theorem mk_sup_mk {a b : α} (ha : IsComplemented a) (hb : IsComplemented b) : (⟨a, ha⟩ ⊔ ⟨b, hb⟩ : Complementeds α) = ⟨a ⊔ b, ha.sup hb⟩ := rfl @[simp] theorem mk_inf_mk {a b : α} (ha : IsComplemented a) (hb : IsComplemented b) : (⟨a, ha⟩ ⊓ ⟨b, hb⟩ : Complementeds α) = ⟨a ⊓ b, ha.inf hb⟩ := rfl instance : DistribLattice (Complementeds α) := Complementeds.coe_injective.distribLattice _ coe_sup coe_inf @[simp, norm_cast] theorem disjoint_coe : Disjoint (a : α) b ↔ Disjoint a b := by rw [disjoint_iff, disjoint_iff, ← coe_inf, ← coe_bot, coe_inj] @[simp, norm_cast] theorem codisjoint_coe : Codisjoint (a : α) b ↔ Codisjoint a b := by rw [codisjoint_iff, codisjoint_iff, ← coe_sup, ← coe_top, coe_inj] @[simp, norm_cast] theorem isCompl_coe : IsCompl (a : α) b ↔ IsCompl a b := by simp_rw [isCompl_iff, disjoint_coe, codisjoint_coe] instance : ComplementedLattice (Complementeds α) := ⟨fun ⟨a, b, h⟩ => ⟨⟨b, a, h.symm⟩, isCompl_coe.1 h⟩⟩ end Complementeds end IsCompl
Mathlib/Order/Disjoint.lean
809
810
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Nat.Bits import Mathlib.Data.Nat.Pairing /-! # Equivalences involving `ℕ` This file defines some additional constructive equivalences using `Encodable` and the pairing function on `ℕ`. -/ assert_not_exists Monoid open Nat Function namespace Equiv variable {α : Type*} /-- An equivalence between `Bool × ℕ` and `ℕ`, by mapping `(true, x)` to `2 * x + 1` and `(false, x)` to `2 * x`. -/ @[simps] def boolProdNatEquivNat : Bool × ℕ ≃ ℕ where toFun := uncurry bit invFun := boddDiv2 left_inv := fun ⟨b, n⟩ => by simp only [bodd_bit, div2_bit, uncurry_apply_pair, boddDiv2_eq] right_inv n := by simp only [bit_decomp, boddDiv2_eq, uncurry_apply_pair] /-- An equivalence between `ℕ ⊕ ℕ` and `ℕ`, by mapping `(Sum.inl x)` to `2 * x` and `(Sum.inr x)` to `2 * x + 1`. -/ @[simps! symm_apply] def natSumNatEquivNat : ℕ ⊕ ℕ ≃ ℕ := (boolProdEquivSum ℕ).symm.trans boolProdNatEquivNat @[simp] theorem natSumNatEquivNat_apply : ⇑natSumNatEquivNat = Sum.elim (2 * ·) (2 * · + 1) := by ext (x | x) <;> rfl /-- An equivalence between `ℤ` and `ℕ`, through `ℤ ≃ ℕ ⊕ ℕ` and `ℕ ⊕ ℕ ≃ ℕ`. -/ def intEquivNat : ℤ ≃ ℕ := intEquivNatSumNat.trans natSumNatEquivNat
/-- An equivalence between `α × α` and `α`, given that there is an equivalence between `α` and `ℕ`.
Mathlib/Logic/Equiv/Nat.lean
48
49
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.TangentCone import Mathlib.Analysis.NormedSpace.OperatorNorm.Asymptotics import Mathlib.Analysis.Asymptotics.TVS import Mathlib.Analysis.Asymptotics.Lemmas /-! # The Fréchet derivative Let `E` and `F` be normed spaces, `f : E → F`, and `f' : E →L[𝕜] F` a continuous 𝕜-linear map, where `𝕜` is a non-discrete normed field. Then `HasFDerivWithinAt f f' s x` says that `f` has derivative `f'` at `x`, where the domain of interest is restricted to `s`. We also have `HasFDerivAt f f' x := HasFDerivWithinAt f f' x univ` Finally, `HasStrictFDerivAt f f' x` means that `f : E → F` has derivative `f' : E →L[𝕜] F` in the sense of strict differentiability, i.e., `f y - f z - f'(y - z) = o(y - z)` as `y, z → x`. This notion is used in the inverse function theorem, and is defined here only to avoid proving theorems like `IsBoundedBilinearMap.hasFDerivAt` twice: first for `HasFDerivAt`, then for `HasStrictFDerivAt`. ## Main results In addition to the definition and basic properties of the derivative, the folder `Analysis/Calculus/FDeriv/` contains the usual formulas (and existence assertions) for the derivative of * constants * the identity * bounded linear maps (`Linear.lean`) * bounded bilinear maps (`Bilinear.lean`) * sum of two functions (`Add.lean`) * sum of finitely many functions (`Add.lean`) * multiplication of a function by a scalar constant (`Add.lean`) * negative of a function (`Add.lean`) * subtraction of two functions (`Add.lean`) * multiplication of a function by a scalar function (`Mul.lean`) * multiplication of two scalar functions (`Mul.lean`) * composition of functions (the chain rule) (`Comp.lean`) * inverse function (`Mul.lean`) (assuming that it exists; the inverse function theorem is in `../Inverse.lean`) For most binary operations we also define `const_op` and `op_const` theorems for the cases when the first or second argument is a constant. This makes writing chains of `HasDerivAt`'s easier, and they more frequently lead to the desired result. One can also interpret the derivative of a function `f : 𝕜 → E` as an element of `E` (by identifying a linear function from `𝕜` to `E` with its value at `1`). Results on the Fréchet derivative are translated to this more elementary point of view on the derivative in the file `Deriv.lean`. The derivative of polynomials is handled there, as it is naturally one-dimensional. The simplifier is set up to prove automatically that some functions are differentiable, or differentiable at a point (but not differentiable on a set or within a set at a point, as checking automatically that the good domains are mapped one to the other when using composition is not something the simplifier can easily do). This means that one can write `example (x : ℝ) : Differentiable ℝ (fun x ↦ sin (exp (3 + x^2)) - 5 * cos x) := by simp`. If there are divisions, one needs to supply to the simplifier proofs that the denominators do not vanish, as in ```lean example (x : ℝ) (h : 1 + sin x ≠ 0) : DifferentiableAt ℝ (fun x ↦ exp x / (1 + sin x)) x := by simp [h] ``` Of course, these examples only work once `exp`, `cos` and `sin` have been shown to be differentiable, in `Mathlib.Analysis.SpecialFunctions.Trigonometric.Deriv`. The simplifier is not set up to compute the Fréchet derivative of maps (as these are in general complicated multidimensional linear maps), but it will compute one-dimensional derivatives, see `Deriv.lean`. ## Implementation details The derivative is defined in terms of the `IsLittleOTVS` relation to ensure the definition does not ingrain a choice of norm, and is then quickly translated to the more convenient `IsLittleO` in the subsequent theorems. It is also characterized in terms of the `Tendsto` relation. We also introduce predicates `DifferentiableWithinAt 𝕜 f s x` (where `𝕜` is the base field, `f` the function to be differentiated, `x` the point at which the derivative is asserted to exist, and `s` the set along which the derivative is defined), as well as `DifferentiableAt 𝕜 f x`, `DifferentiableOn 𝕜 f s` and `Differentiable 𝕜 f` to express the existence of a derivative. To be able to compute with derivatives, we write `fderivWithin 𝕜 f s x` and `fderiv 𝕜 f x` for some choice of a derivative if it exists, and the zero function otherwise. This choice only behaves well along sets for which the derivative is unique, i.e., those for which the tangent directions span a dense subset of the whole space. The predicates `UniqueDiffWithinAt s x` and `UniqueDiffOn s`, defined in `TangentCone.lean` express this property. We prove that indeed they imply the uniqueness of the derivative. This is satisfied for open subsets, and in particular for `univ`. This uniqueness only holds when the field is non-discrete, which we request at the very beginning: otherwise, a derivative can be defined, but it has no interesting properties whatsoever. To make sure that the simplifier can prove automatically that functions are differentiable, we tag many lemmas with the `simp` attribute, for instance those saying that the sum of differentiable functions is differentiable, as well as their product, their cartesian product, and so on. A notable exception is the chain rule: we do not mark as a simp lemma the fact that, if `f` and `g` are differentiable, then their composition also is: `simp` would always be able to match this lemma, by taking `f` or `g` to be the identity. Instead, for every reasonable function (say, `exp`), we add a lemma that if `f` is differentiable then so is `(fun x ↦ exp (f x))`. This means adding some boilerplate lemmas, but these can also be useful in their own right. Tests for this ability of the simplifier (with more examples) are provided in `Tests/Differentiable.lean`. ## TODO Generalize more results to topological vector spaces. ## Tags derivative, differentiable, Fréchet, calculus -/ open Filter Asymptotics ContinuousLinearMap Set Metric Topology NNReal ENNReal noncomputable section section TVS variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] variable {F : Type*} [AddCommGroup F] [Module 𝕜 F] [TopologicalSpace F] /-- A function `f` has the continuous linear map `f'` as derivative along the filter `L` if `f x' = f x + f' (x' - x) + o (x' - x)` when `x'` converges along the filter `L`. This definition is designed to be specialized for `L = 𝓝 x` (in `HasFDerivAt`), giving rise to the usual notion of Fréchet derivative, and for `L = 𝓝[s] x` (in `HasFDerivWithinAt`), giving rise to the notion of Fréchet derivative along the set `s`. -/ @[mk_iff hasFDerivAtFilter_iff_isLittleOTVS] structure HasFDerivAtFilter (f : E → F) (f' : E →L[𝕜] F) (x : E) (L : Filter E) : Prop where of_isLittleOTVS :: isLittleOTVS : (fun x' => f x' - f x - f' (x' - x)) =o[𝕜; L] (fun x' => x' - x) /-- A function `f` has the continuous linear map `f'` as derivative at `x` within a set `s` if `f x' = f x + f' (x' - x) + o (x' - x)` when `x'` tends to `x` inside `s`. -/ @[fun_prop] def HasFDerivWithinAt (f : E → F) (f' : E →L[𝕜] F) (s : Set E) (x : E) := HasFDerivAtFilter f f' x (𝓝[s] x) /-- A function `f` has the continuous linear map `f'` as derivative at `x` if `f x' = f x + f' (x' - x) + o (x' - x)` when `x'` tends to `x`. -/ @[fun_prop] def HasFDerivAt (f : E → F) (f' : E →L[𝕜] F) (x : E) := HasFDerivAtFilter f f' x (𝓝 x) /-- A function `f` has derivative `f'` at `a` in the sense of *strict differentiability* if `f x - f y - f' (x - y) = o(x - y)` as `x, y → a`. This form of differentiability is required, e.g., by the inverse function theorem. Any `C^1` function on a vector space over `ℝ` is strictly differentiable but this definition works, e.g., for vector spaces over `p`-adic numbers. -/ @[fun_prop, mk_iff hasStrictFDerivAt_iff_isLittleOTVS] structure HasStrictFDerivAt (f : E → F) (f' : E →L[𝕜] F) (x : E) where of_isLittleOTVS :: isLittleOTVS : (fun p : E × E => f p.1 - f p.2 - f' (p.1 - p.2)) =o[𝕜; 𝓝 (x, x)] (fun p : E × E => p.1 - p.2) variable (𝕜) /-- A function `f` is differentiable at a point `x` within a set `s` if it admits a derivative there (possibly non-unique). -/ @[fun_prop] def DifferentiableWithinAt (f : E → F) (s : Set E) (x : E) := ∃ f' : E →L[𝕜] F, HasFDerivWithinAt f f' s x /-- A function `f` is differentiable at a point `x` if it admits a derivative there (possibly non-unique). -/ @[fun_prop] def DifferentiableAt (f : E → F) (x : E) := ∃ f' : E →L[𝕜] F, HasFDerivAt f f' x open scoped Classical in /-- If `f` has a derivative at `x` within `s`, then `fderivWithin 𝕜 f s x` is such a derivative. Otherwise, it is set to `0`. We also set it to be zero, if zero is one of possible derivatives. -/ irreducible_def fderivWithin (f : E → F) (s : Set E) (x : E) : E →L[𝕜] F := if HasFDerivWithinAt f (0 : E →L[𝕜] F) s x then 0 else if h : DifferentiableWithinAt 𝕜 f s x then Classical.choose h else 0 /-- If `f` has a derivative at `x`, then `fderiv 𝕜 f x` is such a derivative. Otherwise, it is set to `0`. -/ irreducible_def fderiv (f : E → F) (x : E) : E →L[𝕜] F := fderivWithin 𝕜 f univ x /-- `DifferentiableOn 𝕜 f s` means that `f` is differentiable within `s` at any point of `s`. -/ @[fun_prop] def DifferentiableOn (f : E → F) (s : Set E) := ∀ x ∈ s, DifferentiableWithinAt 𝕜 f s x /-- `Differentiable 𝕜 f` means that `f` is differentiable at any point. -/ @[fun_prop] def Differentiable (f : E → F) := ∀ x, DifferentiableAt 𝕜 f x variable {𝕜} variable {f f₀ f₁ g : E → F} variable {f' f₀' f₁' g' : E →L[𝕜] F} variable {x : E} variable {s t : Set E} variable {L L₁ L₂ : Filter E} theorem fderivWithin_zero_of_not_differentiableWithinAt (h : ¬DifferentiableWithinAt 𝕜 f s x) : fderivWithin 𝕜 f s x = 0 := by simp [fderivWithin, h] @[simp] theorem fderivWithin_univ : fderivWithin 𝕜 f univ = fderiv 𝕜 f := by ext rw [fderiv] end TVS section variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {f f₀ f₁ g : E → F} variable {f' f₀' f₁' g' : E →L[𝕜] F} variable {x : E} variable {s t : Set E} variable {L L₁ L₂ : Filter E} theorem hasFDerivAtFilter_iff_isLittleO : HasFDerivAtFilter f f' x L ↔ (fun x' => f x' - f x - f' (x' - x)) =o[L] fun x' => x' - x := (hasFDerivAtFilter_iff_isLittleOTVS ..).trans isLittleOTVS_iff_isLittleO alias ⟨HasFDerivAtFilter.isLittleO, HasFDerivAtFilter.of_isLittleO⟩ := hasFDerivAtFilter_iff_isLittleO theorem hasStrictFDerivAt_iff_isLittleO : HasStrictFDerivAt f f' x ↔ (fun p : E × E => f p.1 - f p.2 - f' (p.1 - p.2)) =o[𝓝 (x, x)] fun p : E × E => p.1 - p.2 := (hasStrictFDerivAt_iff_isLittleOTVS ..).trans isLittleOTVS_iff_isLittleO alias ⟨HasStrictFDerivAt.isLittleO, HasStrictFDerivAt.of_isLittleO⟩ := hasStrictFDerivAt_iff_isLittleO section DerivativeUniqueness /- In this section, we discuss the uniqueness of the derivative. We prove that the definitions `UniqueDiffWithinAt` and `UniqueDiffOn` indeed imply the uniqueness of the derivative. -/ /-- If a function f has a derivative f' at x, a rescaled version of f around x converges to f', i.e., `n (f (x + (1/n) v) - f x)` converges to `f' v`. More generally, if `c n` tends to infinity and `c n * d n` tends to `v`, then `c n * (f (x + d n) - f x)` tends to `f' v`. This lemma expresses this fact, for functions having a derivative within a set. Its specific formulation is useful for tangent cone related discussions. -/ theorem HasFDerivWithinAt.lim (h : HasFDerivWithinAt f f' s x) {α : Type*} (l : Filter α) {c : α → 𝕜} {d : α → E} {v : E} (dtop : ∀ᶠ n in l, x + d n ∈ s) (clim : Tendsto (fun n => ‖c n‖) l atTop) (cdlim : Tendsto (fun n => c n • d n) l (𝓝 v)) : Tendsto (fun n => c n • (f (x + d n) - f x)) l (𝓝 (f' v)) := by have tendsto_arg : Tendsto (fun n => x + d n) l (𝓝[s] x) := by conv in 𝓝[s] x => rw [← add_zero x] rw [nhdsWithin, tendsto_inf] constructor · apply tendsto_const_nhds.add (tangentConeAt.lim_zero l clim cdlim) · rwa [tendsto_principal] have : (fun y => f y - f x - f' (y - x)) =o[𝓝[s] x] fun y => y - x := h.isLittleO have : (fun n => f (x + d n) - f x - f' (x + d n - x)) =o[l] fun n => x + d n - x := this.comp_tendsto tendsto_arg have : (fun n => f (x + d n) - f x - f' (d n)) =o[l] d := by simpa only [add_sub_cancel_left] have : (fun n => c n • (f (x + d n) - f x - f' (d n))) =o[l] fun n => c n • d n := (isBigO_refl c l).smul_isLittleO this have : (fun n => c n • (f (x + d n) - f x - f' (d n))) =o[l] fun _ => (1 : ℝ) := this.trans_isBigO (cdlim.isBigO_one ℝ) have L1 : Tendsto (fun n => c n • (f (x + d n) - f x - f' (d n))) l (𝓝 0) := (isLittleO_one_iff ℝ).1 this have L2 : Tendsto (fun n => f' (c n • d n)) l (𝓝 (f' v)) := Tendsto.comp f'.cont.continuousAt cdlim have L3 : Tendsto (fun n => c n • (f (x + d n) - f x - f' (d n)) + f' (c n • d n)) l (𝓝 (0 + f' v)) := L1.add L2 have : (fun n => c n • (f (x + d n) - f x - f' (d n)) + f' (c n • d n)) = fun n => c n • (f (x + d n) - f x) := by ext n simp [smul_add, smul_sub] rwa [this, zero_add] at L3 /-- If `f'` and `f₁'` are two derivatives of `f` within `s` at `x`, then they are equal on the tangent cone to `s` at `x` -/ theorem HasFDerivWithinAt.unique_on (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt f f₁' s x) : EqOn f' f₁' (tangentConeAt 𝕜 s x) := fun _ ⟨_, _, dtop, clim, cdlim⟩ => tendsto_nhds_unique (hf.lim atTop dtop clim cdlim) (hg.lim atTop dtop clim cdlim) /-- `UniqueDiffWithinAt` achieves its goal: it implies the uniqueness of the derivative. -/ theorem UniqueDiffWithinAt.eq (H : UniqueDiffWithinAt 𝕜 s x) (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt f f₁' s x) : f' = f₁' := ContinuousLinearMap.ext_on H.1 (hf.unique_on hg) theorem UniqueDiffOn.eq (H : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (h : HasFDerivWithinAt f f' s x) (h₁ : HasFDerivWithinAt f f₁' s x) : f' = f₁' := (H x hx).eq h h₁ end DerivativeUniqueness section FDerivProperties /-! ### Basic properties of the derivative -/ theorem hasFDerivAtFilter_iff_tendsto : HasFDerivAtFilter f f' x L ↔ Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) L (𝓝 0) := by have h : ∀ x', ‖x' - x‖ = 0 → ‖f x' - f x - f' (x' - x)‖ = 0 := fun x' hx' => by rw [sub_eq_zero.1 (norm_eq_zero.1 hx')] simp rw [hasFDerivAtFilter_iff_isLittleO, ← isLittleO_norm_left, ← isLittleO_norm_right, isLittleO_iff_tendsto h] exact tendsto_congr fun _ => div_eq_inv_mul _ _ theorem hasFDerivWithinAt_iff_tendsto : HasFDerivWithinAt f f' s x ↔ Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) (𝓝[s] x) (𝓝 0) := hasFDerivAtFilter_iff_tendsto theorem hasFDerivAt_iff_tendsto : HasFDerivAt f f' x ↔ Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) (𝓝 x) (𝓝 0) := hasFDerivAtFilter_iff_tendsto theorem hasFDerivAt_iff_isLittleO_nhds_zero : HasFDerivAt f f' x ↔ (fun h : E => f (x + h) - f x - f' h) =o[𝓝 0] fun h => h := by rw [HasFDerivAt, hasFDerivAtFilter_iff_isLittleO, ← map_add_left_nhds_zero x, isLittleO_map] simp [Function.comp_def] nonrec theorem HasFDerivAtFilter.mono (h : HasFDerivAtFilter f f' x L₂) (hst : L₁ ≤ L₂) : HasFDerivAtFilter f f' x L₁ := .of_isLittleOTVS <| h.isLittleOTVS.mono hst theorem HasFDerivWithinAt.mono_of_mem_nhdsWithin (h : HasFDerivWithinAt f f' t x) (hst : t ∈ 𝓝[s] x) : HasFDerivWithinAt f f' s x := h.mono <| nhdsWithin_le_iff.mpr hst @[deprecated (since := "2024-10-31")] alias HasFDerivWithinAt.mono_of_mem := HasFDerivWithinAt.mono_of_mem_nhdsWithin nonrec theorem HasFDerivWithinAt.mono (h : HasFDerivWithinAt f f' t x) (hst : s ⊆ t) : HasFDerivWithinAt f f' s x := h.mono <| nhdsWithin_mono _ hst theorem HasFDerivAt.hasFDerivAtFilter (h : HasFDerivAt f f' x) (hL : L ≤ 𝓝 x) : HasFDerivAtFilter f f' x L := h.mono hL @[fun_prop] theorem HasFDerivAt.hasFDerivWithinAt (h : HasFDerivAt f f' x) : HasFDerivWithinAt f f' s x := h.hasFDerivAtFilter inf_le_left @[fun_prop] theorem HasFDerivWithinAt.differentiableWithinAt (h : HasFDerivWithinAt f f' s x) : DifferentiableWithinAt 𝕜 f s x := ⟨f', h⟩ @[fun_prop] theorem HasFDerivAt.differentiableAt (h : HasFDerivAt f f' x) : DifferentiableAt 𝕜 f x := ⟨f', h⟩ @[simp] theorem hasFDerivWithinAt_univ : HasFDerivWithinAt f f' univ x ↔ HasFDerivAt f f' x := by simp only [HasFDerivWithinAt, nhdsWithin_univ, HasFDerivAt] alias ⟨HasFDerivWithinAt.hasFDerivAt_of_univ, _⟩ := hasFDerivWithinAt_univ theorem differentiableWithinAt_univ : DifferentiableWithinAt 𝕜 f univ x ↔ DifferentiableAt 𝕜 f x := by simp only [DifferentiableWithinAt, hasFDerivWithinAt_univ, DifferentiableAt] theorem fderiv_zero_of_not_differentiableAt (h : ¬DifferentiableAt 𝕜 f x) : fderiv 𝕜 f x = 0 := by rw [fderiv, fderivWithin_zero_of_not_differentiableWithinAt] rwa [differentiableWithinAt_univ] theorem hasFDerivWithinAt_of_mem_nhds (h : s ∈ 𝓝 x) : HasFDerivWithinAt f f' s x ↔ HasFDerivAt f f' x := by rw [HasFDerivAt, HasFDerivWithinAt, nhdsWithin_eq_nhds.mpr h] lemma hasFDerivWithinAt_of_isOpen (h : IsOpen s) (hx : x ∈ s) : HasFDerivWithinAt f f' s x ↔ HasFDerivAt f f' x := hasFDerivWithinAt_of_mem_nhds (h.mem_nhds hx) @[simp] theorem hasFDerivWithinAt_insert {y : E} : HasFDerivWithinAt f f' (insert y s) x ↔ HasFDerivWithinAt f f' s x := by rcases eq_or_ne x y with (rfl | h) · simp_rw [HasFDerivWithinAt, hasFDerivAtFilter_iff_isLittleOTVS] apply isLittleOTVS_insert simp only [sub_self, map_zero] refine ⟨fun h => h.mono <| subset_insert y s, fun hf => hf.mono_of_mem_nhdsWithin ?_⟩ simp_rw [nhdsWithin_insert_of_ne h, self_mem_nhdsWithin] alias ⟨HasFDerivWithinAt.of_insert, HasFDerivWithinAt.insert'⟩ := hasFDerivWithinAt_insert protected theorem HasFDerivWithinAt.insert (h : HasFDerivWithinAt g g' s x) : HasFDerivWithinAt g g' (insert x s) x := h.insert' @[simp] theorem hasFDerivWithinAt_diff_singleton (y : E) : HasFDerivWithinAt f f' (s \ {y}) x ↔ HasFDerivWithinAt f f' s x := by rw [← hasFDerivWithinAt_insert, insert_diff_singleton, hasFDerivWithinAt_insert] @[simp] protected theorem HasFDerivWithinAt.empty : HasFDerivWithinAt f f' ∅ x := by simp [HasFDerivWithinAt, hasFDerivAtFilter_iff_isLittleOTVS] @[simp] protected theorem DifferentiableWithinAt.empty : DifferentiableWithinAt 𝕜 f ∅ x := ⟨0, .empty⟩ theorem HasFDerivWithinAt.of_finite (h : s.Finite) : HasFDerivWithinAt f f' s x := by induction s, h using Set.Finite.induction_on with | empty => exact .empty | insert _ _ ih => exact ih.insert' theorem DifferentiableWithinAt.of_finite (h : s.Finite) : DifferentiableWithinAt 𝕜 f s x := ⟨0, .of_finite h⟩ @[simp] protected theorem HasFDerivWithinAt.singleton {y} : HasFDerivWithinAt f f' {x} y := .of_finite <| finite_singleton _ @[simp] protected theorem DifferentiableWithinAt.singleton {y} : DifferentiableWithinAt 𝕜 f {x} y := ⟨0, .singleton⟩ theorem HasFDerivWithinAt.of_subsingleton (h : s.Subsingleton) : HasFDerivWithinAt f f' s x := .of_finite h.finite theorem DifferentiableWithinAt.of_subsingleton (h : s.Subsingleton) : DifferentiableWithinAt 𝕜 f s x := .of_finite h.finite theorem HasStrictFDerivAt.isBigO_sub (hf : HasStrictFDerivAt f f' x) : (fun p : E × E => f p.1 - f p.2) =O[𝓝 (x, x)] fun p : E × E => p.1 - p.2 := hf.isLittleO.isBigO.congr_of_sub.2 (f'.isBigO_comp _ _) theorem HasFDerivAtFilter.isBigO_sub (h : HasFDerivAtFilter f f' x L) : (fun x' => f x' - f x) =O[L] fun x' => x' - x := h.isLittleO.isBigO.congr_of_sub.2 (f'.isBigO_sub _ _) @[fun_prop] protected theorem HasStrictFDerivAt.hasFDerivAt (hf : HasStrictFDerivAt f f' x) : HasFDerivAt f f' x := .of_isLittleOTVS <| by simpa only using hf.isLittleOTVS.comp_tendsto (tendsto_id.prodMk_nhds tendsto_const_nhds) protected theorem HasStrictFDerivAt.differentiableAt (hf : HasStrictFDerivAt f f' x) : DifferentiableAt 𝕜 f x := hf.hasFDerivAt.differentiableAt /-- If `f` is strictly differentiable at `x` with derivative `f'` and `K > ‖f'‖₊`, then `f` is `K`-Lipschitz in a neighborhood of `x`. -/ theorem HasStrictFDerivAt.exists_lipschitzOnWith_of_nnnorm_lt (hf : HasStrictFDerivAt f f' x) (K : ℝ≥0) (hK : ‖f'‖₊ < K) : ∃ s ∈ 𝓝 x, LipschitzOnWith K f s := by have := hf.isLittleO.add_isBigOWith (f'.isBigOWith_comp _ _) hK simp only [sub_add_cancel, IsBigOWith] at this rcases exists_nhds_square this with ⟨U, Uo, xU, hU⟩ exact ⟨U, Uo.mem_nhds xU, lipschitzOnWith_iff_norm_sub_le.2 fun x hx y hy => hU (mk_mem_prod hx hy)⟩ /-- If `f` is strictly differentiable at `x` with derivative `f'`, then `f` is Lipschitz in a neighborhood of `x`. See also `HasStrictFDerivAt.exists_lipschitzOnWith_of_nnnorm_lt` for a more precise statement. -/ theorem HasStrictFDerivAt.exists_lipschitzOnWith (hf : HasStrictFDerivAt f f' x) : ∃ K, ∃ s ∈ 𝓝 x, LipschitzOnWith K f s := (exists_gt _).imp hf.exists_lipschitzOnWith_of_nnnorm_lt /-- Directional derivative agrees with `HasFDeriv`. -/ theorem HasFDerivAt.lim (hf : HasFDerivAt f f' x) (v : E) {α : Type*} {c : α → 𝕜} {l : Filter α} (hc : Tendsto (fun n => ‖c n‖) l atTop) : Tendsto (fun n => c n • (f (x + (c n)⁻¹ • v) - f x)) l (𝓝 (f' v)) := by refine (hasFDerivWithinAt_univ.2 hf).lim _ univ_mem hc ?_ intro U hU refine (eventually_ne_of_tendsto_norm_atTop hc (0 : 𝕜)).mono fun y hy => ?_ convert mem_of_mem_nhds hU dsimp only rw [← mul_smul, mul_inv_cancel₀ hy, one_smul] theorem HasFDerivAt.unique (h₀ : HasFDerivAt f f₀' x) (h₁ : HasFDerivAt f f₁' x) : f₀' = f₁' := by rw [← hasFDerivWithinAt_univ] at h₀ h₁ exact uniqueDiffWithinAt_univ.eq h₀ h₁ theorem hasFDerivWithinAt_inter' (h : t ∈ 𝓝[s] x) : HasFDerivWithinAt f f' (s ∩ t) x ↔ HasFDerivWithinAt f f' s x := by simp [HasFDerivWithinAt, nhdsWithin_restrict'' s h] theorem hasFDerivWithinAt_inter (h : t ∈ 𝓝 x) : HasFDerivWithinAt f f' (s ∩ t) x ↔ HasFDerivWithinAt f f' s x := by simp [HasFDerivWithinAt, nhdsWithin_restrict' s h] theorem HasFDerivWithinAt.union (hs : HasFDerivWithinAt f f' s x) (ht : HasFDerivWithinAt f f' t x) : HasFDerivWithinAt f f' (s ∪ t) x := by simp only [HasFDerivWithinAt, nhdsWithin_union] exact .of_isLittleOTVS <| hs.isLittleOTVS.sup ht.isLittleOTVS theorem HasFDerivWithinAt.hasFDerivAt (h : HasFDerivWithinAt f f' s x) (hs : s ∈ 𝓝 x) : HasFDerivAt f f' x := by rwa [← univ_inter s, hasFDerivWithinAt_inter hs, hasFDerivWithinAt_univ] at h theorem DifferentiableWithinAt.differentiableAt (h : DifferentiableWithinAt 𝕜 f s x) (hs : s ∈ 𝓝 x) : DifferentiableAt 𝕜 f x := h.imp fun _ hf' => hf'.hasFDerivAt hs /-- If `x` is isolated in `s`, then `f` has any derivative at `x` within `s`, as this statement is empty. -/ theorem HasFDerivWithinAt.of_not_accPt (h : ¬AccPt x (𝓟 s)) : HasFDerivWithinAt f f' s x := by rw [accPt_principal_iff_nhdsWithin, not_neBot] at h rw [← hasFDerivWithinAt_diff_singleton x, HasFDerivWithinAt, h, hasFDerivAtFilter_iff_isLittleOTVS] exact .bot /-- If `x` is isolated in `s`, then `f` has any derivative at `x` within `s`, as this statement is empty. -/ @[deprecated HasFDerivWithinAt.of_not_accPt (since := "2025-04-20")] theorem HasFDerivWithinAt.of_nhdsWithin_eq_bot (h : 𝓝[s \ {x}] x = ⊥) : HasFDerivWithinAt f f' s x := .of_not_accPt <| by rwa [accPt_principal_iff_nhdsWithin, not_neBot] /-- If `x` is not in the closure of `s`, then `f` has any derivative at `x` within `s`, as this statement is empty. -/ theorem HasFDerivWithinAt.of_not_mem_closure (h : x ∉ closure s) : HasFDerivWithinAt f f' s x := .of_not_accPt (h ·.clusterPt.mem_closure) @[deprecated (since := "2025-04-20")] alias hasFDerivWithinAt_of_nmem_closure := HasFDerivWithinAt.of_not_mem_closure theorem fderivWithin_zero_of_not_accPt (h : ¬AccPt x (𝓟 s)) : fderivWithin 𝕜 f s x = 0 := by rw [fderivWithin, if_pos (.of_not_accPt h)] set_option linter.deprecated false in @[deprecated fderivWithin_zero_of_not_accPt (since := "2025-04-20")] theorem fderivWithin_zero_of_isolated (h : 𝓝[s \ {x}] x = ⊥) : fderivWithin 𝕜 f s x = 0 := by rw [fderivWithin, if_pos (.of_nhdsWithin_eq_bot h)] theorem fderivWithin_zero_of_nmem_closure (h : x ∉ closure s) : fderivWithin 𝕜 f s x = 0 := fderivWithin_zero_of_not_accPt (h ·.clusterPt.mem_closure) theorem DifferentiableWithinAt.hasFDerivWithinAt (h : DifferentiableWithinAt 𝕜 f s x) : HasFDerivWithinAt f (fderivWithin 𝕜 f s x) s x := by simp only [fderivWithin, dif_pos h] split_ifs with h₀ exacts [h₀, Classical.choose_spec h] theorem DifferentiableAt.hasFDerivAt (h : DifferentiableAt 𝕜 f x) : HasFDerivAt f (fderiv 𝕜 f x) x := by rw [fderiv, ← hasFDerivWithinAt_univ] rw [← differentiableWithinAt_univ] at h exact h.hasFDerivWithinAt theorem DifferentiableOn.hasFDerivAt (h : DifferentiableOn 𝕜 f s) (hs : s ∈ 𝓝 x) : HasFDerivAt f (fderiv 𝕜 f x) x := ((h x (mem_of_mem_nhds hs)).differentiableAt hs).hasFDerivAt theorem DifferentiableOn.differentiableAt (h : DifferentiableOn 𝕜 f s) (hs : s ∈ 𝓝 x) : DifferentiableAt 𝕜 f x := (h.hasFDerivAt hs).differentiableAt theorem DifferentiableOn.eventually_differentiableAt (h : DifferentiableOn 𝕜 f s) (hs : s ∈ 𝓝 x) : ∀ᶠ y in 𝓝 x, DifferentiableAt 𝕜 f y := (eventually_eventually_nhds.2 hs).mono fun _ => h.differentiableAt protected theorem HasFDerivAt.fderiv (h : HasFDerivAt f f' x) : fderiv 𝕜 f x = f' := by ext rw [h.unique h.differentiableAt.hasFDerivAt] theorem fderiv_eq {f' : E → E →L[𝕜] F} (h : ∀ x, HasFDerivAt f (f' x) x) : fderiv 𝕜 f = f' := funext fun x => (h x).fderiv protected theorem HasFDerivWithinAt.fderivWithin (h : HasFDerivWithinAt f f' s x) (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 f s x = f' := (hxs.eq h h.differentiableWithinAt.hasFDerivWithinAt).symm theorem DifferentiableWithinAt.mono (h : DifferentiableWithinAt 𝕜 f t x) (st : s ⊆ t) : DifferentiableWithinAt 𝕜 f s x := by rcases h with ⟨f', hf'⟩ exact ⟨f', hf'.mono st⟩ theorem DifferentiableWithinAt.mono_of_mem_nhdsWithin (h : DifferentiableWithinAt 𝕜 f s x) {t : Set E} (hst : s ∈ 𝓝[t] x) : DifferentiableWithinAt 𝕜 f t x := (h.hasFDerivWithinAt.mono_of_mem_nhdsWithin hst).differentiableWithinAt @[deprecated (since := "2024-10-31")] alias DifferentiableWithinAt.mono_of_mem := DifferentiableWithinAt.mono_of_mem_nhdsWithin theorem DifferentiableWithinAt.congr_nhds (h : DifferentiableWithinAt 𝕜 f s x) {t : Set E} (hst : 𝓝[s] x = 𝓝[t] x) : DifferentiableWithinAt 𝕜 f t x := h.mono_of_mem_nhdsWithin <| hst ▸ self_mem_nhdsWithin theorem differentiableWithinAt_congr_nhds {t : Set E} (hst : 𝓝[s] x = 𝓝[t] x) : DifferentiableWithinAt 𝕜 f s x ↔ DifferentiableWithinAt 𝕜 f t x := ⟨fun h => h.congr_nhds hst, fun h => h.congr_nhds hst.symm⟩ theorem differentiableWithinAt_inter (ht : t ∈ 𝓝 x) : DifferentiableWithinAt 𝕜 f (s ∩ t) x ↔ DifferentiableWithinAt 𝕜 f s x := by simp only [DifferentiableWithinAt, hasFDerivWithinAt_inter ht] theorem differentiableWithinAt_inter' (ht : t ∈ 𝓝[s] x) : DifferentiableWithinAt 𝕜 f (s ∩ t) x ↔ DifferentiableWithinAt 𝕜 f s x := by simp only [DifferentiableWithinAt, hasFDerivWithinAt_inter' ht] theorem differentiableWithinAt_insert_self : DifferentiableWithinAt 𝕜 f (insert x s) x ↔ DifferentiableWithinAt 𝕜 f s x := ⟨fun h ↦ h.mono (subset_insert x s), fun h ↦ h.hasFDerivWithinAt.insert.differentiableWithinAt⟩ theorem differentiableWithinAt_insert {y : E} : DifferentiableWithinAt 𝕜 f (insert y s) x ↔ DifferentiableWithinAt 𝕜 f s x := by rcases eq_or_ne x y with (rfl | h) · exact differentiableWithinAt_insert_self apply differentiableWithinAt_congr_nhds exact nhdsWithin_insert_of_ne h alias ⟨DifferentiableWithinAt.of_insert, DifferentiableWithinAt.insert'⟩ := differentiableWithinAt_insert protected theorem DifferentiableWithinAt.insert (h : DifferentiableWithinAt 𝕜 f s x) : DifferentiableWithinAt 𝕜 f (insert x s) x := h.insert' theorem DifferentiableAt.differentiableWithinAt (h : DifferentiableAt 𝕜 f x) : DifferentiableWithinAt 𝕜 f s x := (differentiableWithinAt_univ.2 h).mono (subset_univ _) @[fun_prop] theorem Differentiable.differentiableAt (h : Differentiable 𝕜 f) : DifferentiableAt 𝕜 f x := h x protected theorem DifferentiableAt.fderivWithin (h : DifferentiableAt 𝕜 f x) (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 f s x = fderiv 𝕜 f x := h.hasFDerivAt.hasFDerivWithinAt.fderivWithin hxs theorem DifferentiableOn.mono (h : DifferentiableOn 𝕜 f t) (st : s ⊆ t) : DifferentiableOn 𝕜 f s := fun x hx => (h x (st hx)).mono st theorem differentiableOn_univ : DifferentiableOn 𝕜 f univ ↔ Differentiable 𝕜 f := by simp only [DifferentiableOn, Differentiable, differentiableWithinAt_univ, mem_univ, forall_true_left] @[fun_prop] theorem Differentiable.differentiableOn (h : Differentiable 𝕜 f) : DifferentiableOn 𝕜 f s := (differentiableOn_univ.2 h).mono (subset_univ _) theorem differentiableOn_of_locally_differentiableOn (h : ∀ x ∈ s, ∃ u, IsOpen u ∧ x ∈ u ∧ DifferentiableOn 𝕜 f (s ∩ u)) : DifferentiableOn 𝕜 f s := by intro x xs rcases h x xs with ⟨t, t_open, xt, ht⟩ exact (differentiableWithinAt_inter (IsOpen.mem_nhds t_open xt)).1 (ht x ⟨xs, xt⟩) theorem fderivWithin_of_mem_nhdsWithin (st : t ∈ 𝓝[s] x) (ht : UniqueDiffWithinAt 𝕜 s x) (h : DifferentiableWithinAt 𝕜 f t x) : fderivWithin 𝕜 f s x = fderivWithin 𝕜 f t x := ((DifferentiableWithinAt.hasFDerivWithinAt h).mono_of_mem_nhdsWithin st).fderivWithin ht @[deprecated (since := "2024-10-31")] alias fderivWithin_of_mem := fderivWithin_of_mem_nhdsWithin theorem fderivWithin_subset (st : s ⊆ t) (ht : UniqueDiffWithinAt 𝕜 s x) (h : DifferentiableWithinAt 𝕜 f t x) : fderivWithin 𝕜 f s x = fderivWithin 𝕜 f t x := fderivWithin_of_mem_nhdsWithin (nhdsWithin_mono _ st self_mem_nhdsWithin) ht h theorem fderivWithin_inter (ht : t ∈ 𝓝 x) : fderivWithin 𝕜 f (s ∩ t) x = fderivWithin 𝕜 f s x := by classical simp [fderivWithin, hasFDerivWithinAt_inter ht, DifferentiableWithinAt] theorem fderivWithin_of_mem_nhds (h : s ∈ 𝓝 x) : fderivWithin 𝕜 f s x = fderiv 𝕜 f x := by rw [← fderivWithin_univ, ← univ_inter s, fderivWithin_inter h] theorem fderivWithin_of_isOpen (hs : IsOpen s) (hx : x ∈ s) : fderivWithin 𝕜 f s x = fderiv 𝕜 f x := fderivWithin_of_mem_nhds (hs.mem_nhds hx) theorem fderivWithin_eq_fderiv (hs : UniqueDiffWithinAt 𝕜 s x) (h : DifferentiableAt 𝕜 f x) : fderivWithin 𝕜 f s x = fderiv 𝕜 f x := by rw [← fderivWithin_univ] exact fderivWithin_subset (subset_univ _) hs h.differentiableWithinAt theorem fderiv_mem_iff {f : E → F} {s : Set (E →L[𝕜] F)} {x : E} : fderiv 𝕜 f x ∈ s ↔ DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ s ∨ ¬DifferentiableAt 𝕜 f x ∧ (0 : E →L[𝕜] F) ∈ s := by by_cases hx : DifferentiableAt 𝕜 f x <;> simp [fderiv_zero_of_not_differentiableAt, *] theorem fderivWithin_mem_iff {f : E → F} {t : Set E} {s : Set (E →L[𝕜] F)} {x : E} : fderivWithin 𝕜 f t x ∈ s ↔ DifferentiableWithinAt 𝕜 f t x ∧ fderivWithin 𝕜 f t x ∈ s ∨ ¬DifferentiableWithinAt 𝕜 f t x ∧ (0 : E →L[𝕜] F) ∈ s := by by_cases hx : DifferentiableWithinAt 𝕜 f t x <;> simp [fderivWithin_zero_of_not_differentiableWithinAt, *] theorem Asymptotics.IsBigO.hasFDerivWithinAt {s : Set E} {x₀ : E} {n : ℕ} (h : f =O[𝓝[s] x₀] fun x => ‖x - x₀‖ ^ n) (hx₀ : x₀ ∈ s) (hn : 1 < n) : HasFDerivWithinAt f (0 : E →L[𝕜] F) s x₀ := by simp_rw [HasFDerivWithinAt, hasFDerivAtFilter_iff_isLittleO, h.eq_zero_of_norm_pow_within hx₀ hn.ne_bot, zero_apply, sub_zero, h.trans_isLittleO ((isLittleO_pow_sub_sub x₀ hn).mono nhdsWithin_le_nhds)] theorem Asymptotics.IsBigO.hasFDerivAt {x₀ : E} {n : ℕ} (h : f =O[𝓝 x₀] fun x => ‖x - x₀‖ ^ n) (hn : 1 < n) : HasFDerivAt f (0 : E →L[𝕜] F) x₀ := by rw [← nhdsWithin_univ] at h exact (h.hasFDerivWithinAt (mem_univ _) hn).hasFDerivAt_of_univ nonrec theorem HasFDerivWithinAt.isBigO_sub {f : E → F} {s : Set E} {x₀ : E} {f' : E →L[𝕜] F} (h : HasFDerivWithinAt f f' s x₀) : (f · - f x₀) =O[𝓝[s] x₀] (· - x₀) := h.isBigO_sub lemma DifferentiableWithinAt.isBigO_sub {f : E → F} {s : Set E} {x₀ : E} (h : DifferentiableWithinAt 𝕜 f s x₀) : (f · - f x₀) =O[𝓝[s] x₀] (· - x₀) := h.hasFDerivWithinAt.isBigO_sub nonrec theorem HasFDerivAt.isBigO_sub {f : E → F} {x₀ : E} {f' : E →L[𝕜] F} (h : HasFDerivAt f f' x₀) : (f · - f x₀) =O[𝓝 x₀] (· - x₀) := h.isBigO_sub nonrec theorem DifferentiableAt.isBigO_sub {f : E → F} {x₀ : E} (h : DifferentiableAt 𝕜 f x₀) : (f · - f x₀) =O[𝓝 x₀] (· - x₀) := h.hasFDerivAt.isBigO_sub end FDerivProperties section Continuous /-! ### Deducing continuity from differentiability -/ theorem HasFDerivAtFilter.tendsto_nhds (hL : L ≤ 𝓝 x) (h : HasFDerivAtFilter f f' x L) : Tendsto f L (𝓝 (f x)) := by have : Tendsto (fun x' => f x' - f x) L (𝓝 0) := by refine h.isBigO_sub.trans_tendsto (Tendsto.mono_left ?_ hL) rw [← sub_self x] exact tendsto_id.sub tendsto_const_nhds have := this.add (tendsto_const_nhds (x := f x)) rw [zero_add (f x)] at this exact this.congr (by simp only [sub_add_cancel, eq_self_iff_true, forall_const]) theorem HasFDerivWithinAt.continuousWithinAt (h : HasFDerivWithinAt f f' s x) : ContinuousWithinAt f s x := HasFDerivAtFilter.tendsto_nhds inf_le_left h theorem HasFDerivAt.continuousAt (h : HasFDerivAt f f' x) : ContinuousAt f x := HasFDerivAtFilter.tendsto_nhds le_rfl h @[fun_prop] theorem DifferentiableWithinAt.continuousWithinAt (h : DifferentiableWithinAt 𝕜 f s x) : ContinuousWithinAt f s x := let ⟨_, hf'⟩ := h hf'.continuousWithinAt @[fun_prop] theorem DifferentiableAt.continuousAt (h : DifferentiableAt 𝕜 f x) : ContinuousAt f x := let ⟨_, hf'⟩ := h hf'.continuousAt @[fun_prop] theorem DifferentiableOn.continuousOn (h : DifferentiableOn 𝕜 f s) : ContinuousOn f s := fun x hx => (h x hx).continuousWithinAt @[fun_prop] theorem Differentiable.continuous (h : Differentiable 𝕜 f) : Continuous f := continuous_iff_continuousAt.2 fun x => (h x).continuousAt protected theorem HasStrictFDerivAt.continuousAt (hf : HasStrictFDerivAt f f' x) : ContinuousAt f x := hf.hasFDerivAt.continuousAt theorem HasStrictFDerivAt.isBigO_sub_rev {f' : E ≃L[𝕜] F} (hf : HasStrictFDerivAt f (f' : E →L[𝕜] F) x) : (fun p : E × E => p.1 - p.2) =O[𝓝 (x, x)] fun p : E × E => f p.1 - f p.2 := ((f'.isBigO_comp_rev _ _).trans (hf.isLittleO.trans_isBigO (f'.isBigO_comp_rev _ _)).right_isBigO_add).congr (fun _ => rfl) fun _ => sub_add_cancel _ _ theorem HasFDerivAtFilter.isBigO_sub_rev (hf : HasFDerivAtFilter f f' x L) {C} (hf' : AntilipschitzWith C f') : (fun x' => x' - x) =O[L] fun x' => f x' - f x := have : (fun x' => x' - x) =O[L] fun x' => f' (x' - x) := isBigO_iff.2 ⟨C, Eventually.of_forall fun _ => ZeroHomClass.bound_of_antilipschitz f' hf' _⟩ (this.trans (hf.isLittleO.trans_isBigO this).right_isBigO_add).congr (fun _ => rfl) fun _ => sub_add_cancel _ _ end Continuous section congr /-! ### congr properties of the derivative -/ theorem hasFDerivWithinAt_congr_set' (y : E) (h : s =ᶠ[𝓝[{y}ᶜ] x] t) : HasFDerivWithinAt f f' s x ↔ HasFDerivWithinAt f f' t x := calc HasFDerivWithinAt f f' s x ↔ HasFDerivWithinAt f f' (s \ {y}) x := (hasFDerivWithinAt_diff_singleton _).symm _ ↔ HasFDerivWithinAt f f' (t \ {y}) x := by suffices 𝓝[s \ {y}] x = 𝓝[t \ {y}] x by simp only [HasFDerivWithinAt, this] simpa only [set_eventuallyEq_iff_inf_principal, ← nhdsWithin_inter', diff_eq, inter_comm] using h _ ↔ HasFDerivWithinAt f f' t x := hasFDerivWithinAt_diff_singleton _ theorem hasFDerivWithinAt_congr_set (h : s =ᶠ[𝓝 x] t) : HasFDerivWithinAt f f' s x ↔ HasFDerivWithinAt f f' t x := hasFDerivWithinAt_congr_set' x <| h.filter_mono inf_le_left theorem differentiableWithinAt_congr_set' (y : E) (h : s =ᶠ[𝓝[{y}ᶜ] x] t) : DifferentiableWithinAt 𝕜 f s x ↔ DifferentiableWithinAt 𝕜 f t x := exists_congr fun _ => hasFDerivWithinAt_congr_set' _ h theorem differentiableWithinAt_congr_set (h : s =ᶠ[𝓝 x] t) : DifferentiableWithinAt 𝕜 f s x ↔ DifferentiableWithinAt 𝕜 f t x := exists_congr fun _ => hasFDerivWithinAt_congr_set h theorem fderivWithin_congr_set' (y : E) (h : s =ᶠ[𝓝[{y}ᶜ] x] t) : fderivWithin 𝕜 f s x = fderivWithin 𝕜 f t x := by classical simp only [fderivWithin, differentiableWithinAt_congr_set' _ h, hasFDerivWithinAt_congr_set' _ h] theorem fderivWithin_congr_set (h : s =ᶠ[𝓝 x] t) : fderivWithin 𝕜 f s x = fderivWithin 𝕜 f t x := fderivWithin_congr_set' x <| h.filter_mono inf_le_left theorem fderivWithin_eventually_congr_set' (y : E) (h : s =ᶠ[𝓝[{y}ᶜ] x] t) : fderivWithin 𝕜 f s =ᶠ[𝓝 x] fderivWithin 𝕜 f t := (eventually_nhds_nhdsWithin.2 h).mono fun _ => fderivWithin_congr_set' y theorem fderivWithin_eventually_congr_set (h : s =ᶠ[𝓝 x] t) : fderivWithin 𝕜 f s =ᶠ[𝓝 x] fderivWithin 𝕜 f t := fderivWithin_eventually_congr_set' x <| h.filter_mono inf_le_left theorem Filter.EventuallyEq.hasStrictFDerivAt_iff (h : f₀ =ᶠ[𝓝 x] f₁) (h' : ∀ y, f₀' y = f₁' y) : HasStrictFDerivAt f₀ f₀' x ↔ HasStrictFDerivAt f₁ f₁' x := by rw [hasStrictFDerivAt_iff_isLittleOTVS, hasStrictFDerivAt_iff_isLittleOTVS] refine isLittleOTVS_congr ((h.prodMk_nhds h).mono ?_) .rfl rintro p ⟨hp₁, hp₂⟩ simp only [*] theorem HasStrictFDerivAt.congr_fderiv (h : HasStrictFDerivAt f f' x) (h' : f' = g') : HasStrictFDerivAt f g' x := h' ▸ h theorem HasFDerivAt.congr_fderiv (h : HasFDerivAt f f' x) (h' : f' = g') : HasFDerivAt f g' x := h' ▸ h theorem HasFDerivWithinAt.congr_fderiv (h : HasFDerivWithinAt f f' s x) (h' : f' = g') : HasFDerivWithinAt f g' s x := h' ▸ h theorem HasStrictFDerivAt.congr_of_eventuallyEq (h : HasStrictFDerivAt f f' x) (h₁ : f =ᶠ[𝓝 x] f₁) : HasStrictFDerivAt f₁ f' x := (h₁.hasStrictFDerivAt_iff fun _ => rfl).1 h theorem Filter.EventuallyEq.hasFDerivAtFilter_iff (h₀ : f₀ =ᶠ[L] f₁) (hx : f₀ x = f₁ x) (h₁ : ∀ x, f₀' x = f₁' x) : HasFDerivAtFilter f₀ f₀' x L ↔ HasFDerivAtFilter f₁ f₁' x L := by simp only [hasFDerivAtFilter_iff_isLittleOTVS] exact isLittleOTVS_congr (h₀.mono fun y hy => by simp only [hy, h₁, hx]) .rfl theorem HasFDerivAtFilter.congr_of_eventuallyEq (h : HasFDerivAtFilter f f' x L) (hL : f₁ =ᶠ[L] f) (hx : f₁ x = f x) : HasFDerivAtFilter f₁ f' x L := (hL.hasFDerivAtFilter_iff hx fun _ => rfl).2 h theorem Filter.EventuallyEq.hasFDerivAt_iff (h : f₀ =ᶠ[𝓝 x] f₁) : HasFDerivAt f₀ f' x ↔ HasFDerivAt f₁ f' x := h.hasFDerivAtFilter_iff h.eq_of_nhds fun _ => _root_.rfl theorem Filter.EventuallyEq.differentiableAt_iff (h : f₀ =ᶠ[𝓝 x] f₁) : DifferentiableAt 𝕜 f₀ x ↔ DifferentiableAt 𝕜 f₁ x := exists_congr fun _ => h.hasFDerivAt_iff theorem Filter.EventuallyEq.hasFDerivWithinAt_iff (h : f₀ =ᶠ[𝓝[s] x] f₁) (hx : f₀ x = f₁ x) : HasFDerivWithinAt f₀ f' s x ↔ HasFDerivWithinAt f₁ f' s x := h.hasFDerivAtFilter_iff hx fun _ => _root_.rfl theorem Filter.EventuallyEq.hasFDerivWithinAt_iff_of_mem (h : f₀ =ᶠ[𝓝[s] x] f₁) (hx : x ∈ s) : HasFDerivWithinAt f₀ f' s x ↔ HasFDerivWithinAt f₁ f' s x := h.hasFDerivWithinAt_iff (h.eq_of_nhdsWithin hx) theorem Filter.EventuallyEq.differentiableWithinAt_iff (h : f₀ =ᶠ[𝓝[s] x] f₁) (hx : f₀ x = f₁ x) : DifferentiableWithinAt 𝕜 f₀ s x ↔ DifferentiableWithinAt 𝕜 f₁ s x := exists_congr fun _ => h.hasFDerivWithinAt_iff hx theorem Filter.EventuallyEq.differentiableWithinAt_iff_of_mem (h : f₀ =ᶠ[𝓝[s] x] f₁) (hx : x ∈ s) : DifferentiableWithinAt 𝕜 f₀ s x ↔ DifferentiableWithinAt 𝕜 f₁ s x := h.differentiableWithinAt_iff (h.eq_of_nhdsWithin hx) theorem HasFDerivWithinAt.congr_mono (h : HasFDerivWithinAt f f' s x) (ht : EqOn f₁ f t) (hx : f₁ x = f x) (h₁ : t ⊆ s) : HasFDerivWithinAt f₁ f' t x := HasFDerivAtFilter.congr_of_eventuallyEq (h.mono h₁) (Filter.mem_inf_of_right ht) hx theorem HasFDerivWithinAt.congr (h : HasFDerivWithinAt f f' s x) (hs : EqOn f₁ f s) (hx : f₁ x = f x) : HasFDerivWithinAt f₁ f' s x := h.congr_mono hs hx (Subset.refl _) theorem HasFDerivWithinAt.congr' (h : HasFDerivWithinAt f f' s x) (hs : EqOn f₁ f s) (hx : x ∈ s) : HasFDerivWithinAt f₁ f' s x := h.congr hs (hs hx) theorem HasFDerivWithinAt.congr_of_eventuallyEq (h : HasFDerivWithinAt f f' s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : HasFDerivWithinAt f₁ f' s x := HasFDerivAtFilter.congr_of_eventuallyEq h h₁ hx theorem HasFDerivAt.congr_of_eventuallyEq (h : HasFDerivAt f f' x) (h₁ : f₁ =ᶠ[𝓝 x] f) : HasFDerivAt f₁ f' x := HasFDerivAtFilter.congr_of_eventuallyEq h h₁ (mem_of_mem_nhds h₁ :) theorem DifferentiableWithinAt.congr_mono (h : DifferentiableWithinAt 𝕜 f s x) (ht : EqOn f₁ f t) (hx : f₁ x = f x) (h₁ : t ⊆ s) : DifferentiableWithinAt 𝕜 f₁ t x := (HasFDerivWithinAt.congr_mono h.hasFDerivWithinAt ht hx h₁).differentiableWithinAt theorem DifferentiableWithinAt.congr (h : DifferentiableWithinAt 𝕜 f s x) (ht : ∀ x ∈ s, f₁ x = f x) (hx : f₁ x = f x) : DifferentiableWithinAt 𝕜 f₁ s x := DifferentiableWithinAt.congr_mono h ht hx (Subset.refl _) theorem DifferentiableWithinAt.congr_of_eventuallyEq (h : DifferentiableWithinAt 𝕜 f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : DifferentiableWithinAt 𝕜 f₁ s x := (h.hasFDerivWithinAt.congr_of_eventuallyEq h₁ hx).differentiableWithinAt theorem DifferentiableWithinAt.congr_of_eventuallyEq_of_mem (h : DifferentiableWithinAt 𝕜 f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s) : DifferentiableWithinAt 𝕜 f₁ s x := h.congr_of_eventuallyEq h₁ (mem_of_mem_nhdsWithin hx h₁ :) theorem DifferentiableWithinAt.congr_of_eventuallyEq_insert (h : DifferentiableWithinAt 𝕜 f s x) (h₁ : f₁ =ᶠ[𝓝[insert x s] x] f) : DifferentiableWithinAt 𝕜 f₁ s x := (h.insert.congr_of_eventuallyEq_of_mem h₁ (mem_insert _ _)).of_insert theorem DifferentiableOn.congr_mono (h : DifferentiableOn 𝕜 f s) (h' : ∀ x ∈ t, f₁ x = f x) (h₁ : t ⊆ s) : DifferentiableOn 𝕜 f₁ t := fun x hx => (h x (h₁ hx)).congr_mono h' (h' x hx) h₁ theorem DifferentiableOn.congr (h : DifferentiableOn 𝕜 f s) (h' : ∀ x ∈ s, f₁ x = f x) : DifferentiableOn 𝕜 f₁ s := fun x hx => (h x hx).congr h' (h' x hx) theorem differentiableOn_congr (h' : ∀ x ∈ s, f₁ x = f x) : DifferentiableOn 𝕜 f₁ s ↔ DifferentiableOn 𝕜 f s := ⟨fun h => DifferentiableOn.congr h fun y hy => (h' y hy).symm, fun h => DifferentiableOn.congr h h'⟩ theorem DifferentiableAt.congr_of_eventuallyEq (h : DifferentiableAt 𝕜 f x) (hL : f₁ =ᶠ[𝓝 x] f) : DifferentiableAt 𝕜 f₁ x := hL.differentiableAt_iff.2 h theorem DifferentiableWithinAt.fderivWithin_congr_mono (h : DifferentiableWithinAt 𝕜 f s x) (hs : EqOn f₁ f t) (hx : f₁ x = f x) (hxt : UniqueDiffWithinAt 𝕜 t x) (h₁ : t ⊆ s) : fderivWithin 𝕜 f₁ t x = fderivWithin 𝕜 f s x := (HasFDerivWithinAt.congr_mono h.hasFDerivWithinAt hs hx h₁).fderivWithin hxt theorem Filter.EventuallyEq.fderivWithin_eq (hs : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : fderivWithin 𝕜 f₁ s x = fderivWithin 𝕜 f s x := by classical simp only [fderivWithin, DifferentiableWithinAt, hs.hasFDerivWithinAt_iff hx] theorem Filter.EventuallyEq.fderivWithin_eq_of_mem (hs : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s) : fderivWithin 𝕜 f₁ s x = fderivWithin 𝕜 f s x := hs.fderivWithin_eq (mem_of_mem_nhdsWithin hx hs :) theorem Filter.EventuallyEq.fderivWithin_eq_of_insert (hs : f₁ =ᶠ[𝓝[insert x s] x] f) : fderivWithin 𝕜 f₁ s x = fderivWithin 𝕜 f s x := by apply Filter.EventuallyEq.fderivWithin_eq (nhdsWithin_mono _ (subset_insert x s) hs) exact (mem_of_mem_nhdsWithin (mem_insert x s) hs :) theorem Filter.EventuallyEq.fderivWithin' (hs : f₁ =ᶠ[𝓝[s] x] f) (ht : t ⊆ s) : fderivWithin 𝕜 f₁ t =ᶠ[𝓝[s] x] fderivWithin 𝕜 f t := (eventually_eventually_nhdsWithin.2 hs).mp <| eventually_mem_nhdsWithin.mono fun _y hys hs => EventuallyEq.fderivWithin_eq (hs.filter_mono <| nhdsWithin_mono _ ht) (hs.self_of_nhdsWithin hys) protected theorem Filter.EventuallyEq.fderivWithin (hs : f₁ =ᶠ[𝓝[s] x] f) : fderivWithin 𝕜 f₁ s =ᶠ[𝓝[s] x] fderivWithin 𝕜 f s := hs.fderivWithin' Subset.rfl theorem Filter.EventuallyEq.fderivWithin_eq_nhds (h : f₁ =ᶠ[𝓝 x] f) : fderivWithin 𝕜 f₁ s x = fderivWithin 𝕜 f s x := (h.filter_mono nhdsWithin_le_nhds).fderivWithin_eq h.self_of_nhds theorem fderivWithin_congr (hs : EqOn f₁ f s) (hx : f₁ x = f x) : fderivWithin 𝕜 f₁ s x = fderivWithin 𝕜 f s x := (hs.eventuallyEq.filter_mono inf_le_right).fderivWithin_eq hx theorem fderivWithin_congr' (hs : EqOn f₁ f s) (hx : x ∈ s) : fderivWithin 𝕜 f₁ s x = fderivWithin 𝕜 f s x := fderivWithin_congr hs (hs hx) theorem Filter.EventuallyEq.fderiv_eq (h : f₁ =ᶠ[𝓝 x] f) : fderiv 𝕜 f₁ x = fderiv 𝕜 f x := by rw [← fderivWithin_univ, ← fderivWithin_univ, h.fderivWithin_eq_nhds] protected theorem Filter.EventuallyEq.fderiv (h : f₁ =ᶠ[𝓝 x] f) : fderiv 𝕜 f₁ =ᶠ[𝓝 x] fderiv 𝕜 f := h.eventuallyEq_nhds.mono fun _ h => h.fderiv_eq end congr section id /-! ### Derivative of the identity -/ @[fun_prop] theorem hasStrictFDerivAt_id (x : E) : HasStrictFDerivAt id (id 𝕜 E) x := .of_isLittleOTVS <| (IsLittleOTVS.zero _ _).congr_left <| by simp theorem hasFDerivAtFilter_id (x : E) (L : Filter E) : HasFDerivAtFilter id (id 𝕜 E) x L := .of_isLittleOTVS <| (IsLittleOTVS.zero _ _).congr_left <| by simp @[fun_prop] theorem hasFDerivWithinAt_id (x : E) (s : Set E) : HasFDerivWithinAt id (id 𝕜 E) s x := hasFDerivAtFilter_id _ _ @[fun_prop] theorem hasFDerivAt_id (x : E) : HasFDerivAt id (id 𝕜 E) x := hasFDerivAtFilter_id _ _ @[simp, fun_prop] theorem differentiableAt_id : DifferentiableAt 𝕜 id x := (hasFDerivAt_id x).differentiableAt /-- Variant with `fun x => x` rather than `id` -/ @[simp] theorem differentiableAt_id' : DifferentiableAt 𝕜 (fun x => x) x := (hasFDerivAt_id x).differentiableAt @[fun_prop] theorem differentiableWithinAt_id : DifferentiableWithinAt 𝕜 id s x := differentiableAt_id.differentiableWithinAt /-- Variant with `fun x => x` rather than `id` -/ @[fun_prop] theorem differentiableWithinAt_id' : DifferentiableWithinAt 𝕜 (fun x => x) s x := differentiableWithinAt_id @[simp, fun_prop] theorem differentiable_id : Differentiable 𝕜 (id : E → E) := fun _ => differentiableAt_id /-- Variant with `fun x => x` rather than `id` -/ @[simp] theorem differentiable_id' : Differentiable 𝕜 fun x : E => x := fun _ => differentiableAt_id @[fun_prop] theorem differentiableOn_id : DifferentiableOn 𝕜 id s := differentiable_id.differentiableOn @[simp] theorem fderiv_id : fderiv 𝕜 id x = id 𝕜 E := HasFDerivAt.fderiv (hasFDerivAt_id x) @[simp] theorem fderiv_id' : fderiv 𝕜 (fun x : E => x) x = ContinuousLinearMap.id 𝕜 E := fderiv_id theorem fderivWithin_id (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 id s x = id 𝕜 E := by rw [DifferentiableAt.fderivWithin differentiableAt_id hxs] exact fderiv_id theorem fderivWithin_id' (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (fun x : E => x) s x = ContinuousLinearMap.id 𝕜 E := fderivWithin_id hxs end id section Const /-! ### Derivative of constant functions This include the constant functions `0`, `1`, `Nat.cast n`, `Int.cast z`, and other numerals. -/ @[fun_prop] theorem hasStrictFDerivAt_const (c : F) (x : E) : HasStrictFDerivAt (fun _ => c) (0 : E →L[𝕜] F) x := .of_isLittleOTVS <| (IsLittleOTVS.zero _ _).congr_left fun _ => by simp only [zero_apply, sub_self, Pi.zero_apply] @[fun_prop] theorem hasStrictFDerivAt_zero (x : E) : HasStrictFDerivAt (0 : E → F) (0 : E →L[𝕜] F) x := hasStrictFDerivAt_const _ _ @[fun_prop] theorem hasStrictFDerivAt_one [One F] (x : E) : HasStrictFDerivAt (1 : E → F) (0 : E →L[𝕜] F) x := hasStrictFDerivAt_const _ _ @[fun_prop]
theorem hasStrictFDerivAt_natCast [NatCast F] (n : ℕ) (x : E) : HasStrictFDerivAt (n : E → F) (0 : E →L[𝕜] F) x := hasStrictFDerivAt_const _ _
Mathlib/Analysis/Calculus/FDeriv/Basic.lean
1,081
1,082
/- Copyright (c) 2023 Kalle Kytölä. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kalle Kytölä -/ import Mathlib.MeasureTheory.Measure.ProbabilityMeasure import Mathlib.MeasureTheory.Measure.Prod /-! # Products of finite measures and probability measures This file introduces binary products of finite measures and probability measures. The constructions are obtained from special cases of products of general measures. Taking products nevertheless has specific properties in the cases of finite measures and probability measures, notably the fact that the product measures depend continuously on their factors in the topology of weak convergence when the underlying space is metrizable and separable. ## Main definitions * `MeasureTheory.FiniteMeasure.prod`: The product of two finite measures. * `MeasureTheory.ProbabilityMeasure.prod`: The product of two probability measures. ## TODO * Add continuous dependence of the product measures on the factors. -/ open MeasureTheory Topology Metric Filter Set ENNReal NNReal open scoped Topology ENNReal NNReal BoundedContinuousFunction namespace MeasureTheory section FiniteMeasure_product namespace FiniteMeasure variable {α : Type*} [MeasurableSpace α] {β : Type*} [MeasurableSpace β] /-- The binary product of finite measures. -/ noncomputable def prod (μ : FiniteMeasure α) (ν : FiniteMeasure β) : FiniteMeasure (α × β) := ⟨μ.toMeasure.prod ν.toMeasure, inferInstance⟩ variable (μ : FiniteMeasure α) (ν : FiniteMeasure β) @[simp] lemma toMeasure_prod : (μ.prod ν).toMeasure = μ.toMeasure.prod ν.toMeasure := rfl lemma prod_apply (s : Set (α × β)) (s_mble : MeasurableSet s) : μ.prod ν s = ENNReal.toNNReal (∫⁻ x, ν.toMeasure (Prod.mk x ⁻¹' s) ∂μ) := by simp [coeFn_def, Measure.prod_apply s_mble] lemma prod_apply_symm (s : Set (α × β)) (s_mble : MeasurableSet s) : μ.prod ν s = ENNReal.toNNReal (∫⁻ y, μ.toMeasure ((fun x ↦ ⟨x, y⟩) ⁻¹' s) ∂ν) := by simp [coeFn_def, Measure.prod_apply_symm s_mble] lemma prod_prod (s : Set α) (t : Set β) : μ.prod ν (s ×ˢ t) = μ s * ν t := by simp [coeFn_def]
@[simp] lemma mass_prod : (μ.prod ν).mass = μ.mass * ν.mass := by simp only [coeFn_def, mass, univ_prod_univ.symm, toMeasure_prod] rw [← ENNReal.toNNReal_mul] exact congr_arg ENNReal.toNNReal (Measure.prod_prod univ univ)
Mathlib/MeasureTheory/Measure/FiniteMeasureProd.lean
59
62
/- 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] /-- Compute `(f ⋆ g) x₀` if the support of the `f` is within `Metric.ball 0 R`, and `g` is constant on `Metric.ball x₀ R`. We can simplify the RHS further if we assume `f` is integrable, but also if `L = (•)` or more generally if `L` has an `AntilipschitzWith`-condition. -/ theorem convolution_eq_right' {x₀ : G} {R : ℝ} (hf : support f ⊆ ball (0 : G) R) (hg : ∀ x ∈ ball x₀ R, g x = g x₀) : (f ⋆[L, μ] g) x₀ = ∫ t, L (f t) (g x₀) ∂μ := by have h2 : ∀ t, L (f t) (g (x₀ - t)) = L (f t) (g x₀) := fun t ↦ by by_cases ht : t ∈ support f · have h2t := hf ht rw [mem_ball_zero_iff] at h2t specialize hg (x₀ - t) rw [sub_eq_add_neg, add_mem_ball_iff_norm, norm_neg, ← sub_eq_add_neg] at hg rw [hg h2t] · rw [nmem_support] at ht simp_rw [ht, L.map_zero₂] simp_rw [convolution_def, h2] variable [BorelSpace G] [SecondCountableTopology G] variable [IsAddLeftInvariant μ] [SFinite μ] /-- Approximate `(f ⋆ g) x₀` if the support of the `f` is bounded within a ball, and `g` is near `g x₀` on a ball with the same radius around `x₀`. See `dist_convolution_le` for a special case. We can simplify the second argument of `dist` further if we add some extra type-classes on `E` and `𝕜` or if `L` is scalar multiplication. -/ theorem dist_convolution_le' {x₀ : G} {R ε : ℝ} {z₀ : E'} (hε : 0 ≤ ε) (hif : Integrable f μ) (hf : support f ⊆ ball (0 : G) R) (hmg : AEStronglyMeasurable g μ) (hg : ∀ x ∈ ball x₀ R, dist (g x) z₀ ≤ ε) : dist ((f ⋆[L, μ] g : G → F) x₀) (∫ t, L (f t) z₀ ∂μ) ≤ (‖L‖ * ∫ x, ‖f x‖ ∂μ) * ε := by have hfg : ConvolutionExistsAt f g x₀ L μ := by refine BddAbove.convolutionExistsAt L ?_ Metric.isOpen_ball.measurableSet (Subset.trans ?_ hf) hif.integrableOn hmg swap; · refine fun t => mt fun ht : f t = 0 => ?_; simp_rw [ht, L.map_zero₂] rw [bddAbove_def] refine ⟨‖z₀‖ + ε, ?_⟩ rintro _ ⟨x, hx, rfl⟩ refine norm_le_norm_add_const_of_dist_le (hg x ?_) rwa [mem_ball_iff_norm, norm_sub_rev, ← mem_ball_zero_iff] have h2 : ∀ t, dist (L (f t) (g (x₀ - t))) (L (f t) z₀) ≤ ‖L (f t)‖ * ε := by intro t; by_cases ht : t ∈ support f · have h2t := hf ht rw [mem_ball_zero_iff] at h2t specialize hg (x₀ - t) rw [sub_eq_add_neg, add_mem_ball_iff_norm, norm_neg, ← sub_eq_add_neg] at hg refine ((L (f t)).dist_le_opNorm _ _).trans ?_ exact mul_le_mul_of_nonneg_left (hg h2t) (norm_nonneg _) · rw [nmem_support] at ht simp_rw [ht, L.map_zero₂, L.map_zero, norm_zero, zero_mul, dist_self] rfl simp_rw [convolution_def] simp_rw [dist_eq_norm] at h2 ⊢ rw [← integral_sub hfg.integrable]; swap; · exact (L.flip z₀).integrable_comp hif refine (norm_integral_le_of_norm_le ((L.integrable_comp hif).norm.mul_const ε) (Eventually.of_forall h2)).trans ?_ rw [integral_mul_const] refine mul_le_mul_of_nonneg_right ?_ hε have h3 : ∀ t, ‖L (f t)‖ ≤ ‖L‖ * ‖f t‖ := by intro t exact L.le_opNorm (f t) refine (integral_mono (L.integrable_comp hif).norm (hif.norm.const_mul _) h3).trans_eq ?_ rw [integral_const_mul] variable [NormedSpace ℝ E] [NormedSpace ℝ E'] [CompleteSpace E'] /-- Approximate `f ⋆ g` if the support of the `f` is bounded within a ball, and `g` is near `g x₀` on a ball with the same radius around `x₀`. This is a special case of `dist_convolution_le'` where `L` is `(•)`, `f` has integral 1 and `f` is nonnegative. -/ theorem dist_convolution_le {f : G → ℝ} {x₀ : G} {R ε : ℝ} {z₀ : E'} (hε : 0 ≤ ε) (hf : support f ⊆ ball (0 : G) R) (hnf : ∀ x, 0 ≤ f x) (hintf : ∫ x, f x ∂μ = 1) (hmg : AEStronglyMeasurable g μ) (hg : ∀ x ∈ ball x₀ R, dist (g x) z₀ ≤ ε) : dist ((f ⋆[lsmul ℝ ℝ, μ] g : G → E') x₀) z₀ ≤ ε := by have hif : Integrable f μ := integrable_of_integral_eq_one hintf convert (dist_convolution_le' (lsmul ℝ ℝ) hε hif hf hmg hg).trans _ · simp_rw [lsmul_apply, integral_smul_const, hintf, one_smul] · simp_rw [Real.norm_of_nonneg (hnf _), hintf, mul_one] exact (mul_le_mul_of_nonneg_right opNorm_lsmul_le hε).trans_eq (one_mul ε) /-- `(φ i ⋆ g i) (k i)` tends to `z₀` as `i` tends to some filter `l` if * `φ` is a sequence of nonnegative functions with integral `1` as `i` tends to `l`; * The support of `φ` tends to small neighborhoods around `(0 : G)` as `i` tends to `l`; * `g i` is `mu`-a.e. strongly measurable as `i` tends to `l`; * `g i x` tends to `z₀` as `(i, x)` tends to `l ×ˢ 𝓝 x₀`; * `k i` tends to `x₀`. See also `ContDiffBump.convolution_tendsto_right`. -/ theorem convolution_tendsto_right {ι} {g : ι → G → E'} {l : Filter ι} {x₀ : G} {z₀ : E'} {φ : ι → G → ℝ} {k : ι → G} (hnφ : ∀ᶠ i in l, ∀ x, 0 ≤ φ i x) (hiφ : ∀ᶠ i in l, ∫ x, φ i x ∂μ = 1) -- todo: we could weaken this to "the integral tends to 1" (hφ : Tendsto (fun n => support (φ n)) l (𝓝 0).smallSets) (hmg : ∀ᶠ i in l, AEStronglyMeasurable (g i) μ) (hcg : Tendsto (uncurry g) (l ×ˢ 𝓝 x₀) (𝓝 z₀)) (hk : Tendsto k l (𝓝 x₀)) : Tendsto (fun i : ι => (φ i ⋆[lsmul ℝ ℝ, μ] g i : G → E') (k i)) l (𝓝 z₀) := by simp_rw [tendsto_smallSets_iff] at hφ rw [Metric.tendsto_nhds] at hcg ⊢ simp_rw [Metric.eventually_prod_nhds_iff] at hcg intro ε hε have h2ε : 0 < ε / 3 := div_pos hε (by norm_num) obtain ⟨p, hp, δ, hδ, hgδ⟩ := hcg _ h2ε dsimp only [uncurry] at hgδ have h2k := hk.eventually (ball_mem_nhds x₀ <| half_pos hδ) have h2φ := hφ (ball (0 : G) _) <| ball_mem_nhds _ (half_pos hδ) filter_upwards [hp, h2k, h2φ, hnφ, hiφ, hmg] with i hpi hki hφi hnφi hiφi hmgi have hgi : dist (g i (k i)) z₀ < ε / 3 := hgδ hpi (hki.trans <| half_lt_self hδ) have h1 : ∀ x' ∈ ball (k i) (δ / 2), dist (g i x') (g i (k i)) ≤ ε / 3 + ε / 3 := by intro x' hx' refine (dist_triangle_right _ _ _).trans (add_le_add (hgδ hpi ?_).le hgi.le) exact ((dist_triangle _ _ _).trans_lt (add_lt_add hx'.out hki)).trans_eq (add_halves δ) have := dist_convolution_le (add_pos h2ε h2ε).le hφi hnφi hiφi hmgi h1 refine ((dist_triangle _ _ _).trans_lt (add_lt_add_of_le_of_lt this hgi)).trans_eq ?_ field_simp; ring_nf end NormedAddCommGroup end Measurability end NontriviallyNormedField open scoped Convolution section RCLike variable [RCLike 𝕜] variable [NormedSpace 𝕜 E] variable [NormedSpace 𝕜 E'] variable [NormedSpace 𝕜 E''] variable [NormedSpace ℝ F] [NormedSpace 𝕜 F] variable {n : ℕ∞} variable [MeasurableSpace G] {μ ν : Measure G} variable (L : E →L[𝕜] E' →L[𝕜] F) section Assoc variable [CompleteSpace F] variable [NormedAddCommGroup F'] [NormedSpace ℝ F'] [NormedSpace 𝕜 F'] [CompleteSpace F'] variable [NormedAddCommGroup F''] [NormedSpace ℝ F''] [NormedSpace 𝕜 F''] [CompleteSpace F''] variable {k : G → E''} variable (L₂ : F →L[𝕜] E'' →L[𝕜] F') variable (L₃ : E →L[𝕜] F'' →L[𝕜] F') variable (L₄ : E' →L[𝕜] E'' →L[𝕜] F'') variable [AddGroup G] variable [SFinite μ] [SFinite ν] [IsAddRightInvariant μ] theorem integral_convolution [MeasurableAdd₂ G] [MeasurableNeg G] [NormedSpace ℝ E] [NormedSpace ℝ E'] [CompleteSpace E] [CompleteSpace E'] (hf : Integrable f ν) (hg : Integrable g μ) : ∫ x, (f ⋆[L, ν] g) x ∂μ = L (∫ x, f x ∂ν) (∫ x, g x ∂μ) := by refine (integral_integral_swap (by apply hf.convolution_integrand L hg)).trans ?_ simp_rw [integral_comp_comm _ (hg.comp_sub_right _), integral_sub_right_eq_self] exact (L.flip (∫ x, g x ∂μ)).integral_comp_comm hf variable [MeasurableAdd₂ G] [IsAddRightInvariant ν] [MeasurableNeg G] /-- Convolution is associative. This has a weak but inconvenient integrability condition. See also `MeasureTheory.convolution_assoc`. -/ theorem convolution_assoc' (hL : ∀ (x : E) (y : E') (z : E''), L₂ (L x y) z = L₃ x (L₄ y z)) {x₀ : G} (hfg : ∀ᵐ y ∂μ, ConvolutionExistsAt f g y L ν) (hgk : ∀ᵐ x ∂ν, ConvolutionExistsAt g k x L₄ μ) (hi : Integrable (uncurry fun x y => (L₃ (f y)) ((L₄ (g (x - y))) (k (x₀ - x)))) (μ.prod ν)) : ((f ⋆[L, ν] g) ⋆[L₂, μ] k) x₀ = (f ⋆[L₃, ν] g ⋆[L₄, μ] k) x₀ := calc ((f ⋆[L, ν] g) ⋆[L₂, μ] k) x₀ = ∫ t, L₂ (∫ s, L (f s) (g (t - s)) ∂ν) (k (x₀ - t)) ∂μ := rfl _ = ∫ t, ∫ s, L₂ (L (f s) (g (t - s))) (k (x₀ - t)) ∂ν ∂μ := (integral_congr_ae (hfg.mono fun t ht => ((L₂.flip (k (x₀ - t))).integral_comp_comm ht).symm)) _ = ∫ t, ∫ s, L₃ (f s) (L₄ (g (t - s)) (k (x₀ - t))) ∂ν ∂μ := by simp_rw [hL] _ = ∫ s, ∫ t, L₃ (f s) (L₄ (g (t - s)) (k (x₀ - t))) ∂μ ∂ν := by rw [integral_integral_swap hi] _ = ∫ s, ∫ u, L₃ (f s) (L₄ (g u) (k (x₀ - s - u))) ∂μ ∂ν := by congr; ext t rw [eq_comm, ← integral_sub_right_eq_self _ t] simp_rw [sub_sub_sub_cancel_right] _ = ∫ s, L₃ (f s) (∫ u, L₄ (g u) (k (x₀ - s - u)) ∂μ) ∂ν := by refine integral_congr_ae ?_ refine ((quasiMeasurePreserving_sub_left_of_right_invariant ν x₀).ae hgk).mono fun t ht => ?_ exact (L₃ (f t)).integral_comp_comm ht _ = (f ⋆[L₃, ν] g ⋆[L₄, μ] k) x₀ := rfl /-- Convolution is associative. This requires that * all maps are a.e. strongly measurable w.r.t one of the measures * `f ⋆[L, ν] g` exists almost everywhere * `‖g‖ ⋆[μ] ‖k‖` exists almost everywhere * `‖f‖ ⋆[ν] (‖g‖ ⋆[μ] ‖k‖)` exists at `x₀` -/ theorem convolution_assoc (hL : ∀ (x : E) (y : E') (z : E''), L₂ (L x y) z = L₃ x (L₄ y z)) {x₀ : G} (hf : AEStronglyMeasurable f ν) (hg : AEStronglyMeasurable g μ) (hk : AEStronglyMeasurable k μ) (hfg : ∀ᵐ y ∂μ, ConvolutionExistsAt f g y L ν) (hgk : ∀ᵐ x ∂ν, ConvolutionExistsAt (fun x => ‖g x‖) (fun x => ‖k x‖) x (mul ℝ ℝ) μ) (hfgk : ConvolutionExistsAt (fun x => ‖f x‖) ((fun x => ‖g x‖) ⋆[mul ℝ ℝ, μ] fun x => ‖k x‖) x₀ (mul ℝ ℝ) ν) : ((f ⋆[L, ν] g) ⋆[L₂, μ] k) x₀ = (f ⋆[L₃, ν] g ⋆[L₄, μ] k) x₀ := by refine convolution_assoc' L L₂ L₃ L₄ hL hfg (hgk.mono fun x hx => hx.of_norm L₄ hg hk) ?_ -- the following is similar to `Integrable.convolution_integrand` have h_meas : AEStronglyMeasurable (uncurry fun x y => L₃ (f y) (L₄ (g x) (k (x₀ - y - x)))) (μ.prod ν) := by refine L₃.aestronglyMeasurable_comp₂ hf.snd ?_ refine L₄.aestronglyMeasurable_comp₂ hg.fst ?_ refine (hk.mono_ac ?_).comp_measurable ((measurable_const.sub measurable_snd).sub measurable_fst) refine QuasiMeasurePreserving.absolutelyContinuous ?_ refine QuasiMeasurePreserving.prod_of_left ((measurable_const.sub measurable_snd).sub measurable_fst) (Eventually.of_forall fun y => ?_) dsimp only exact quasiMeasurePreserving_sub_left_of_right_invariant μ _ have h2_meas : AEStronglyMeasurable (fun y => ∫ x, ‖L₃ (f y) (L₄ (g x) (k (x₀ - y - x)))‖ ∂μ) ν := h_meas.prod_swap.norm.integral_prod_right' have h3 : map (fun z : G × G => (z.1 - z.2, z.2)) (μ.prod ν) = μ.prod ν := (measurePreserving_sub_prod μ ν).map_eq suffices Integrable (uncurry fun x y => L₃ (f y) (L₄ (g x) (k (x₀ - y - x)))) (μ.prod ν) by rw [← h3] at this convert this.comp_measurable (measurable_sub.prodMk measurable_snd) ext ⟨x, y⟩ simp +unfoldPartialApp only [uncurry, Function.comp_apply, sub_sub_sub_cancel_right] simp_rw [integrable_prod_iff' h_meas] refine ⟨((quasiMeasurePreserving_sub_left_of_right_invariant ν x₀).ae hgk).mono fun t ht => (L₃ (f t)).integrable_comp <| ht.of_norm L₄ hg hk, ?_⟩ refine (hfgk.const_mul (‖L₃‖ * ‖L₄‖)).mono' h2_meas (((quasiMeasurePreserving_sub_left_of_right_invariant ν x₀).ae hgk).mono fun t ht => ?_) simp_rw [convolution_def, mul_apply', mul_mul_mul_comm ‖L₃‖ ‖L₄‖, ← integral_const_mul] rw [Real.norm_of_nonneg (by positivity)] refine integral_mono_of_nonneg (Eventually.of_forall fun t => norm_nonneg _) ((ht.const_mul _).const_mul _) (Eventually.of_forall fun s => ?_) simp only [← mul_assoc ‖L₄‖] apply_rules [ContinuousLinearMap.le_of_opNorm₂_le_of_le, le_rfl] end Assoc variable [NormedAddCommGroup G] [BorelSpace G] theorem convolution_precompR_apply {g : G → E'' →L[𝕜] E'} (hf : LocallyIntegrable f μ) (hcg : HasCompactSupport g) (hg : Continuous g) (x₀ : G) (x : E'') : (f ⋆[L.precompR E'', μ] g) x₀ x = (f ⋆[L, μ] fun a => g a x) x₀ := by have := hcg.convolutionExists_right (L.precompR E'' :) hf hg x₀ simp_rw [convolution_def, ContinuousLinearMap.integral_apply this] rfl variable [NormedSpace 𝕜 G] [SFinite μ] [IsAddLeftInvariant μ] /-- Compute the total derivative of `f ⋆ g` if `g` is `C^1` with compact support and `f` is locally integrable. To write down the total derivative as a convolution, we use `ContinuousLinearMap.precompR`. -/ theorem _root_.HasCompactSupport.hasFDerivAt_convolution_right (hcg : HasCompactSupport g) (hf : LocallyIntegrable f μ) (hg : ContDiff 𝕜 1 g) (x₀ : G) : HasFDerivAt (f ⋆[L, μ] g) ((f ⋆[L.precompR G, μ] fderiv 𝕜 g) x₀) x₀ := by rcases hcg.eq_zero_or_finiteDimensional 𝕜 hg.continuous with (rfl | fin_dim) · have : fderiv 𝕜 (0 : G → E') = 0 := fderiv_const (0 : E') simp only [this, convolution_zero, Pi.zero_apply] exact hasFDerivAt_const (0 : F) x₀ have : ProperSpace G := FiniteDimensional.proper_rclike 𝕜 G set L' := L.precompR G have h1 : ∀ᶠ x in 𝓝 x₀, AEStronglyMeasurable (fun t => L (f t) (g (x - t))) μ := Eventually.of_forall (hf.aestronglyMeasurable.convolution_integrand_snd L hg.continuous.aestronglyMeasurable) have h2 : ∀ x, AEStronglyMeasurable (fun t => L' (f t) (fderiv 𝕜 g (x - t))) μ := hf.aestronglyMeasurable.convolution_integrand_snd L' (hg.continuous_fderiv le_rfl).aestronglyMeasurable have h3 : ∀ x t, HasFDerivAt (fun x => g (x - t)) (fderiv 𝕜 g (x - t)) x := fun x t ↦ by simpa using (hg.differentiable le_rfl).differentiableAt.hasFDerivAt.comp x ((hasFDerivAt_id x).sub (hasFDerivAt_const t x)) let K' := -tsupport (fderiv 𝕜 g) + closedBall x₀ 1 have hK' : IsCompact K' := (hcg.fderiv 𝕜).neg.add (isCompact_closedBall x₀ 1) apply hasFDerivAt_integral_of_dominated_of_fderiv_le zero_lt_one h1 _ (h2 x₀) · filter_upwards with t x hx using (hcg.fderiv 𝕜).convolution_integrand_bound_right L' (hg.continuous_fderiv le_rfl) (ball_subset_closedBall hx) · rw [integrable_indicator_iff hK'.measurableSet] exact ((hf.integrableOn_isCompact hK').norm.const_mul _).mul_const _ · exact Eventually.of_forall fun t x _ => (L _).hasFDerivAt.comp x (h3 x t) · exact hcg.convolutionExists_right L hf hg.continuous x₀ theorem _root_.HasCompactSupport.hasFDerivAt_convolution_left [IsNegInvariant μ] (hcf : HasCompactSupport f) (hf : ContDiff 𝕜 1 f) (hg : LocallyIntegrable g μ) (x₀ : G) : HasFDerivAt (f ⋆[L, μ] g) ((fderiv 𝕜 f ⋆[L.precompL G, μ] g) x₀) x₀ := by simp +singlePass only [← convolution_flip] exact hcf.hasFDerivAt_convolution_right L.flip hg hf x₀ end RCLike section Real /-! The one-variable case -/ variable [RCLike 𝕜] variable [NormedSpace 𝕜 E] variable [NormedSpace 𝕜 E'] variable [NormedSpace ℝ F] [NormedSpace 𝕜 F] variable {f₀ : 𝕜 → E} {g₀ : 𝕜 → E'} variable {n : ℕ∞} variable (L : E →L[𝕜] E' →L[𝕜] F) variable {μ : Measure 𝕜} variable [IsAddLeftInvariant μ] [SFinite μ] theorem _root_.HasCompactSupport.hasDerivAt_convolution_right (hf : LocallyIntegrable f₀ μ) (hcg : HasCompactSupport g₀) (hg : ContDiff 𝕜 1 g₀) (x₀ : 𝕜) : HasDerivAt (f₀ ⋆[L, μ] g₀) ((f₀ ⋆[L, μ] deriv g₀) x₀) x₀ := by convert (hcg.hasFDerivAt_convolution_right L hf hg x₀).hasDerivAt using 1 rw [convolution_precompR_apply L hf (hcg.fderiv 𝕜) (hg.continuous_fderiv le_rfl)] rfl theorem _root_.HasCompactSupport.hasDerivAt_convolution_left [IsNegInvariant μ] (hcf : HasCompactSupport f₀) (hf : ContDiff 𝕜 1 f₀) (hg : LocallyIntegrable g₀ μ) (x₀ : 𝕜) : HasDerivAt (f₀ ⋆[L, μ] g₀) ((deriv f₀ ⋆[L, μ] g₀) x₀) x₀ := by simp +singlePass only [← convolution_flip] exact hcf.hasDerivAt_convolution_right L.flip hg hf x₀ end Real section WithParam variable [RCLike 𝕜] [NormedSpace 𝕜 E] [NormedSpace 𝕜 E'] [NormedSpace 𝕜 E''] [NormedSpace ℝ F] [NormedSpace 𝕜 F] [MeasurableSpace G] [NormedAddCommGroup G] [BorelSpace G] [NormedSpace 𝕜 G] [NormedAddCommGroup P] [NormedSpace 𝕜 P] {μ : Measure G} (L : E →L[𝕜] E' →L[𝕜] F) /-- The derivative of the convolution `f * g` is given by `f * Dg`, when `f` is locally integrable and `g` is `C^1` 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`). -/ theorem hasFDerivAt_convolution_right_with_param {g : P → G → E'} {s : Set P} {k : Set G} (hs : IsOpen s) (hk : IsCompact k) (hgs : ∀ p, ∀ x, p ∈ s → x ∉ k → g p x = 0) (hf : LocallyIntegrable f μ) (hg : ContDiffOn 𝕜 1 (↿g) (s ×ˢ univ)) (q₀ : P × G) (hq₀ : q₀.1 ∈ s) : HasFDerivAt (fun q : P × G => (f ⋆[L, μ] g q.1) q.2) ((f ⋆[L.precompR (P × G), μ] fun x : G => fderiv 𝕜 (↿g) (q₀.1, x)) q₀.2) q₀ := by let g' := fderiv 𝕜 ↿g have A : ∀ p ∈ s, Continuous (g p) := fun p hp ↦ by refine hg.continuousOn.comp_continuous (.prodMk_right _) fun x => ?_ simpa only [prodMk_mem_set_prod_eq, mem_univ, and_true] using hp have A' : ∀ q : P × G, q.1 ∈ s → s ×ˢ univ ∈ 𝓝 q := fun q hq ↦ by apply (hs.prod isOpen_univ).mem_nhds simpa only [mem_prod, mem_univ, and_true] using hq -- The derivative of `g` vanishes away from `k`. have g'_zero : ∀ p x, p ∈ s → x ∉ k → g' (p, x) = 0 := by intro p x hp hx refine (hasFDerivAt_zero_of_eventually_const 0 ?_).fderiv have M2 : kᶜ ∈ 𝓝 x := hk.isClosed.isOpen_compl.mem_nhds hx have M1 : s ∈ 𝓝 p := hs.mem_nhds hp rw [nhds_prod_eq] filter_upwards [prod_mem_prod M1 M2] rintro ⟨p, y⟩ ⟨hp, hy⟩ exact hgs p y hp hy /- We find a small neighborhood of `{q₀.1} × k` on which the derivative is uniformly bounded. This follows from the continuity at all points of the compact set `k`. -/ obtain ⟨ε, C, εpos, h₀ε, hε⟩ : ∃ ε C, 0 < ε ∧ ball q₀.1 ε ⊆ s ∧ ∀ p x, ‖p - q₀.1‖ < ε → ‖g' (p, x)‖ ≤ C := by have A : IsCompact ({q₀.1} ×ˢ k) := isCompact_singleton.prod hk obtain ⟨t, kt, t_open, ht⟩ : ∃ t, {q₀.1} ×ˢ k ⊆ t ∧ IsOpen t ∧ IsBounded (g' '' t) := by have B : ContinuousOn g' (s ×ˢ univ) := hg.continuousOn_fderiv_of_isOpen (hs.prod isOpen_univ) le_rfl apply exists_isOpen_isBounded_image_of_isCompact_of_continuousOn A (hs.prod isOpen_univ) _ B simp only [prod_subset_prod_iff, hq₀, singleton_subset_iff, subset_univ, and_self_iff, true_or] obtain ⟨ε, εpos, hε, h'ε⟩ : ∃ ε : ℝ, 0 < ε ∧ thickening ε ({q₀.fst} ×ˢ k) ⊆ t ∧ ball q₀.1 ε ⊆ s := by obtain ⟨ε, εpos, hε⟩ : ∃ ε : ℝ, 0 < ε ∧ thickening ε (({q₀.fst} : Set P) ×ˢ k) ⊆ t := A.exists_thickening_subset_open t_open kt obtain ⟨δ, δpos, hδ⟩ : ∃ δ : ℝ, 0 < δ ∧ ball q₀.1 δ ⊆ s := Metric.isOpen_iff.1 hs _ hq₀ refine ⟨min ε δ, lt_min εpos δpos, ?_, ?_⟩ · exact Subset.trans (thickening_mono (min_le_left _ _) _) hε · exact Subset.trans (ball_subset_ball (min_le_right _ _)) hδ obtain ⟨C, Cpos, hC⟩ : ∃ C, 0 < C ∧ g' '' t ⊆ closedBall 0 C := ht.subset_closedBall_lt 0 0 refine ⟨ε, C, εpos, h'ε, fun p x hp => ?_⟩ have hps : p ∈ s := h'ε (mem_ball_iff_norm.2 hp) by_cases hx : x ∈ k · have H : (p, x) ∈ t := by apply hε refine mem_thickening_iff.2 ⟨(q₀.1, x), ?_, ?_⟩ · simp only [hx, singleton_prod, mem_image, Prod.mk_inj, eq_self_iff_true, true_and, exists_eq_right] · rw [← dist_eq_norm] at hp simpa only [Prod.dist_eq, εpos, dist_self, max_lt_iff, and_true] using hp have : g' (p, x) ∈ closedBall (0 : P × G →L[𝕜] E') C := hC (mem_image_of_mem _ H) rwa [mem_closedBall_zero_iff] at this · have : g' (p, x) = 0 := g'_zero _ _ hps hx rw [this] simpa only [norm_zero] using Cpos.le /- Now, we wish to apply a theorem on differentiation of integrals. For this, we need to check trivial measurability or integrability assumptions (in `I1`, `I2`, `I3`), as well as a uniform integrability assumption over the derivative (in `I4` and `I5`) and pointwise differentiability in `I6`. -/ have I1 : ∀ᶠ x : P × G in 𝓝 q₀, AEStronglyMeasurable (fun a : G => L (f a) (g x.1 (x.2 - a))) μ := by filter_upwards [A' q₀ hq₀] rintro ⟨p, x⟩ ⟨hp, -⟩ refine (HasCompactSupport.convolutionExists_right L ?_ hf (A _ hp) _).1 apply hk.of_isClosed_subset (isClosed_tsupport _) exact closure_minimal (support_subset_iff'.2 fun z hz => hgs _ _ hp hz) hk.isClosed have I2 : Integrable (fun a : G => L (f a) (g q₀.1 (q₀.2 - a))) μ := by have M : HasCompactSupport (g q₀.1) := HasCompactSupport.intro hk fun x hx => hgs q₀.1 x hq₀ hx apply M.convolutionExists_right L hf (A q₀.1 hq₀) q₀.2 have I3 : AEStronglyMeasurable (fun a : G => (L (f a)).comp (g' (q₀.fst, q₀.snd - a))) μ := by have T : HasCompactSupport fun y => g' (q₀.1, y) := HasCompactSupport.intro hk fun x hx => g'_zero q₀.1 x hq₀ hx apply (HasCompactSupport.convolutionExists_right (L.precompR (P × G) :) T hf _ q₀.2).1 have : ContinuousOn g' (s ×ˢ univ) := hg.continuousOn_fderiv_of_isOpen (hs.prod isOpen_univ) le_rfl apply this.comp_continuous (.prodMk_right _) intro x simpa only [prodMk_mem_set_prod_eq, mem_univ, and_true] using hq₀ set K' := (-k + {q₀.2} : Set G) with K'_def have hK' : IsCompact K' := hk.neg.add isCompact_singleton obtain ⟨U, U_open, K'U, hU⟩ : ∃ U, IsOpen U ∧ K' ⊆ U ∧ IntegrableOn f U μ := hf.integrableOn_nhds_isCompact hK' obtain ⟨δ, δpos, δε, hδ⟩ : ∃ δ, (0 : ℝ) < δ ∧ δ ≤ ε ∧ K' + ball 0 δ ⊆ U := by obtain ⟨V, V_mem, hV⟩ : ∃ V ∈ 𝓝 (0 : G), K' + V ⊆ U := compact_open_separated_add_right hK' U_open K'U rcases Metric.mem_nhds_iff.1 V_mem with ⟨δ, δpos, hδ⟩ refine ⟨min δ ε, lt_min δpos εpos, min_le_right δ ε, ?_⟩ exact (add_subset_add_left ((ball_subset_ball (min_le_left _ _)).trans hδ)).trans hV letI := ContinuousLinearMap.hasOpNorm (𝕜 := 𝕜) (𝕜₂ := 𝕜) (E := E) (F := (P × G →L[𝕜] E') →L[𝕜] P × G →L[𝕜] F) (σ₁₂ := RingHom.id 𝕜) let bound : G → ℝ := indicator U fun t => ‖(L.precompR (P × G))‖ * ‖f t‖ * C have I4 : ∀ᵐ a : G ∂μ, ∀ x : P × G, dist x q₀ < δ → ‖L.precompR (P × G) (f a) (g' (x.fst, x.snd - a))‖ ≤ bound a := by filter_upwards with a x hx rw [Prod.dist_eq, dist_eq_norm, dist_eq_norm] at hx have : (-tsupport fun a => g' (x.1, a)) + ball q₀.2 δ ⊆ U := by apply Subset.trans _ hδ rw [K'_def, add_assoc] apply add_subset_add · rw [neg_subset_neg] refine closure_minimal (support_subset_iff'.2 fun z hz => ?_) hk.isClosed apply g'_zero x.1 z (h₀ε _) hz rw [mem_ball_iff_norm] exact ((le_max_left _ _).trans_lt hx).trans_le δε · simp only [add_ball, thickening_singleton, zero_vadd, subset_rfl] apply convolution_integrand_bound_right_of_le_of_subset _ _ _ this · intro y exact hε _ _ (((le_max_left _ _).trans_lt hx).trans_le δε) · rw [mem_ball_iff_norm] exact (le_max_right _ _).trans_lt hx have I5 : Integrable bound μ := by rw [integrable_indicator_iff U_open.measurableSet] exact (hU.norm.const_mul _).mul_const _ have I6 : ∀ᵐ a : G ∂μ, ∀ x : P × G, dist x q₀ < δ → HasFDerivAt (fun x : P × G => L (f a) (g x.1 (x.2 - a))) ((L (f a)).comp (g' (x.fst, x.snd - a))) x := by filter_upwards with a x hx apply (L _).hasFDerivAt.comp x have N : s ×ˢ univ ∈ 𝓝 (x.1, x.2 - a) := by apply A' apply h₀ε rw [Prod.dist_eq] at hx exact lt_of_lt_of_le (lt_of_le_of_lt (le_max_left _ _) hx) δε have Z := ((hg.differentiableOn le_rfl).differentiableAt N).hasFDerivAt have Z' : HasFDerivAt (fun x : P × G => (x.1, x.2 - a)) (ContinuousLinearMap.id 𝕜 (P × G)) x := by have : (fun x : P × G => (x.1, x.2 - a)) = _root_.id - fun x => (0, a) := by ext x <;> simp only [Pi.sub_apply, _root_.id, Prod.fst_sub, sub_zero, Prod.snd_sub] rw [this] exact (hasFDerivAt_id x).sub_const (0, a) exact Z.comp x Z' exact hasFDerivAt_integral_of_dominated_of_fderiv_le δpos I1 I2 I3 I4 I5 I6 /-- The convolution `f * g` is `C^n` when `f` is locally integrable and `g` is `C^n` 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`). In this version, all the types belong to the same universe (to get an induction working in the proof). Use instead `contDiffOn_convolution_right_with_param`, which removes this restriction. -/ theorem contDiffOn_convolution_right_with_param_aux {G : Type uP} {E' : Type uP} {F : Type uP} {P : Type uP} [NormedAddCommGroup E'] [NormedAddCommGroup F] [NormedSpace 𝕜 E'] [NormedSpace ℝ F] [NormedSpace 𝕜 F] [MeasurableSpace G] {μ : Measure G} [NormedAddCommGroup G] [BorelSpace G] [NormedSpace 𝕜 G] [NormedAddCommGroup P] [NormedSpace 𝕜 P] {f : G → E} {n : ℕ∞} (L : E →L[𝕜] E' →L[𝕜] F) {g : P → G → E'} {s : Set P} {k : Set G} (hs : IsOpen s) (hk : IsCompact k) (hgs : ∀ p, ∀ x, p ∈ s → x ∉ k → g p x = 0) (hf : LocallyIntegrable f μ) (hg : ContDiffOn 𝕜 n (↿g) (s ×ˢ univ)) : ContDiffOn 𝕜 n (fun q : P × G => (f ⋆[L, μ] g q.1) q.2) (s ×ˢ univ) := by /- We have a formula for the derivation of `f * g`, which is of the same form, thanks to `hasFDerivAt_convolution_right_with_param`. Therefore, we can prove the result by induction on `n` (but for this we need the spaces at the different steps of the induction to live in the same universe, which is why we make the assumption in the lemma that all the relevant spaces come from the same universe). -/ induction n using ENat.nat_induction generalizing g E' F with | h0 => rw [WithTop.coe_zero, contDiffOn_zero] at hg ⊢ exact continuousOn_convolution_right_with_param L hk hgs hf hg | hsuc n ih => simp only [Nat.succ_eq_add_one, Nat.cast_add, Nat.cast_one, WithTop.coe_add, WithTop.coe_natCast, WithTop.coe_one] at hg ⊢ let f' : P → G → P × G →L[𝕜] F := fun p a => (f ⋆[L.precompR (P × G), μ] fun x : G => fderiv 𝕜 (uncurry g) (p, x)) a have A : ∀ q₀ : P × G, q₀.1 ∈ s → HasFDerivAt (fun q : P × G => (f ⋆[L, μ] g q.1) q.2) (f' q₀.1 q₀.2) q₀ := hasFDerivAt_convolution_right_with_param L hs hk hgs hf hg.one_of_succ rw [contDiffOn_succ_iff_fderiv_of_isOpen (hs.prod (@isOpen_univ G _))] at hg ⊢ refine ⟨?_, by simp, ?_⟩ · rintro ⟨p, x⟩ ⟨hp, -⟩ exact (A (p, x) hp).differentiableAt.differentiableWithinAt · suffices H : ContDiffOn 𝕜 n (↿f') (s ×ˢ univ) by apply H.congr rintro ⟨p, x⟩ ⟨hp, -⟩ exact (A (p, x) hp).fderiv have B : ∀ (p : P) (x : G), p ∈ s → x ∉ k → fderiv 𝕜 (uncurry g) (p, x) = 0 := by intro p x hp hx apply (hasFDerivAt_zero_of_eventually_const (0 : E') _).fderiv have M2 : kᶜ ∈ 𝓝 x := IsOpen.mem_nhds hk.isClosed.isOpen_compl hx have M1 : s ∈ 𝓝 p := hs.mem_nhds hp rw [nhds_prod_eq] filter_upwards [prod_mem_prod M1 M2] rintro ⟨p, y⟩ ⟨hp, hy⟩ exact hgs p y hp hy apply ih (L.precompR (P × G) :) B convert hg.2.2 | htop ih => rw [contDiffOn_infty] at hg ⊢ exact fun n ↦ ih n L hgs (hg n) /-- The convolution `f * g` is `C^n` when `f` is locally integrable and `g` is `C^n` 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`). -/ theorem contDiffOn_convolution_right_with_param {f : G → E} {n : ℕ∞} (L : E →L[𝕜] E' →L[𝕜] F) {g : P → G → E'} {s : Set P} {k : Set G} (hs : IsOpen s) (hk : IsCompact k) (hgs : ∀ p, ∀ x, p ∈ s → x ∉ k → g p x = 0) (hf : LocallyIntegrable f μ) (hg : ContDiffOn 𝕜 n (↿g) (s ×ˢ univ)) : ContDiffOn 𝕜 n (fun q : P × G => (f ⋆[L, μ] g q.1) q.2) (s ×ˢ univ) := by /- The result is known when all the universes are the same, from `contDiffOn_convolution_right_with_param_aux`. We reduce to this situation by pushing everything through `ULift` continuous linear equivalences. -/ let eG : Type max uG uE' uF uP := ULift.{max uE' uF uP} G borelize eG let eE' : Type max uE' uG uF uP := ULift.{max uG uF uP} E' let eF : Type max uF uG uE' uP := ULift.{max uG uE' uP} F let eP : Type max uP uG uE' uF := ULift.{max uG uE' uF} P let isoG : eG ≃L[𝕜] G := ContinuousLinearEquiv.ulift let isoE' : eE' ≃L[𝕜] E' := ContinuousLinearEquiv.ulift let isoF : eF ≃L[𝕜] F := ContinuousLinearEquiv.ulift let isoP : eP ≃L[𝕜] P := ContinuousLinearEquiv.ulift let ef := f ∘ isoG let eμ : Measure eG := Measure.map isoG.symm μ let eg : eP → eG → eE' := fun ep ex => isoE'.symm (g (isoP ep) (isoG ex)) let eL := ContinuousLinearMap.comp ((ContinuousLinearEquiv.arrowCongr isoE' isoF).symm : (E' →L[𝕜] F) →L[𝕜] eE' →L[𝕜] eF) L let R := fun q : eP × eG => (ef ⋆[eL, eμ] eg q.1) q.2 have R_contdiff : ContDiffOn 𝕜 n R ((isoP ⁻¹' s) ×ˢ univ) := by have hek : IsCompact (isoG ⁻¹' k) := isoG.toHomeomorph.isClosedEmbedding.isCompact_preimage hk have hes : IsOpen (isoP ⁻¹' s) := isoP.continuous.isOpen_preimage _ hs refine contDiffOn_convolution_right_with_param_aux eL hes hek ?_ ?_ ?_ · intro p x hp hx simp only [eg, (· ∘ ·), ContinuousLinearEquiv.prod_apply, LinearIsometryEquiv.coe_coe, ContinuousLinearEquiv.map_eq_zero_iff] exact hgs _ _ hp hx · exact (locallyIntegrable_map_homeomorph isoG.symm.toHomeomorph).2 hf · apply isoE'.symm.contDiff.comp_contDiffOn apply hg.comp (isoP.prod isoG).contDiff.contDiffOn rintro ⟨p, x⟩ ⟨hp, -⟩ simpa only [mem_preimage, ContinuousLinearEquiv.prod_apply, prodMk_mem_set_prod_eq, mem_univ, and_true] using hp have A : ContDiffOn 𝕜 n (isoF ∘ R ∘ (isoP.prod isoG).symm) (s ×ˢ univ) := by apply isoF.contDiff.comp_contDiffOn apply R_contdiff.comp (ContinuousLinearEquiv.contDiff _).contDiffOn rintro ⟨p, x⟩ ⟨hp, -⟩ simpa only [mem_preimage, mem_prod, mem_univ, and_true, ContinuousLinearEquiv.prod_symm, ContinuousLinearEquiv.prod_apply, ContinuousLinearEquiv.apply_symm_apply] using hp have : isoF ∘ R ∘ (isoP.prod isoG).symm = fun q : P × G => (f ⋆[L, μ] g q.1) q.2 := by apply funext rintro ⟨p, x⟩ simp only [LinearIsometryEquiv.coe_coe, (· ∘ ·), ContinuousLinearEquiv.prod_symm, ContinuousLinearEquiv.prod_apply] simp only [R, convolution, coe_comp', ContinuousLinearEquiv.coe_coe, (· ∘ ·)] rw [IsClosedEmbedding.integral_map, ← isoF.integral_comp_comm] · rfl · exact isoG.symm.toHomeomorph.isClosedEmbedding simp_rw [this] at A exact A /-- The convolution `f * g` is `C^n` when `f` is locally integrable and `g` is `C^n` 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 composition with an additional `C^n` function. -/ theorem contDiffOn_convolution_right_with_param_comp {n : ℕ∞} (L : E →L[𝕜] E' →L[𝕜] F) {s : Set P} {v : P → G} (hv : ContDiffOn 𝕜 n v s) {f : G → E} {g : P → G → E'} {k : Set G} (hs : IsOpen s) (hk : IsCompact k) (hgs : ∀ p, ∀ x, p ∈ s → x ∉ k → g p x = 0) (hf : LocallyIntegrable f μ) (hg : ContDiffOn 𝕜 n (↿g) (s ×ˢ univ)) : ContDiffOn 𝕜 n (fun x => (f ⋆[L, μ] g x) (v x)) s := by apply (contDiffOn_convolution_right_with_param L hs hk hgs hf hg).comp (contDiffOn_id.prodMk hv) intro x hx simp only [hx, mem_preimage, prodMk_mem_set_prod_eq, mem_univ, and_self_iff, _root_.id] /-- The convolution `g * f` is `C^n` when `f` is locally integrable and `g` is `C^n` 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`). -/ theorem contDiffOn_convolution_left_with_param [μ.IsAddLeftInvariant] [μ.IsNegInvariant] (L : E' →L[𝕜] E →L[𝕜] F) {f : G → E} {n : ℕ∞} {g : P → G → E'} {s : Set P} {k : Set G} (hs : IsOpen s) (hk : IsCompact k) (hgs : ∀ p, ∀ x, p ∈ s → x ∉ k → g p x = 0) (hf : LocallyIntegrable f μ) (hg : ContDiffOn 𝕜 n (↿g) (s ×ˢ univ)) : ContDiffOn 𝕜 n (fun q : P × G => (g q.1 ⋆[L, μ] f) q.2) (s ×ˢ univ) := by simpa only [convolution_flip] using contDiffOn_convolution_right_with_param L.flip hs hk hgs hf hg /-- The convolution `g * f` is `C^n` when `f` is locally integrable and `g` is `C^n` 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 composition with additional `C^n` functions. -/ theorem contDiffOn_convolution_left_with_param_comp [μ.IsAddLeftInvariant] [μ.IsNegInvariant] (L : E' →L[𝕜] E →L[𝕜] F) {s : Set P} {n : ℕ∞} {v : P → G} (hv : ContDiffOn 𝕜 n v s) {f : G → E} {g : P → G → E'} {k : Set G} (hs : IsOpen s) (hk : IsCompact k) (hgs : ∀ p, ∀ x, p ∈ s → x ∉ k → g p x = 0) (hf : LocallyIntegrable f μ) (hg : ContDiffOn 𝕜 n (↿g) (s ×ˢ univ)) : ContDiffOn 𝕜 n (fun x => (g x ⋆[L, μ] f) (v x)) s := by apply (contDiffOn_convolution_left_with_param L hs hk hgs hf hg).comp (contDiffOn_id.prodMk hv) intro x hx simp only [hx, mem_preimage, prodMk_mem_set_prod_eq, mem_univ, and_self_iff, _root_.id] theorem _root_.HasCompactSupport.contDiff_convolution_right {n : ℕ∞} (hcg : HasCompactSupport g) (hf : LocallyIntegrable f μ) (hg : ContDiff 𝕜 n g) : ContDiff 𝕜 n (f ⋆[L, μ] g) := by rcases exists_compact_iff_hasCompactSupport.2 hcg with ⟨k, hk, h'k⟩ rw [← contDiffOn_univ] exact contDiffOn_convolution_right_with_param_comp L contDiffOn_id isOpen_univ hk (fun p x _ hx => h'k x hx) hf (hg.comp contDiff_snd).contDiffOn theorem _root_.HasCompactSupport.contDiff_convolution_left [μ.IsAddLeftInvariant] [μ.IsNegInvariant] {n : ℕ∞} (hcf : HasCompactSupport f) (hf : ContDiff 𝕜 n f) (hg : LocallyIntegrable g μ) : ContDiff 𝕜 n (f ⋆[L, μ] g) := by rw [← convolution_flip] exact hcf.contDiff_convolution_right L.flip hg hf end WithParam section Nonneg variable [NormedSpace ℝ E] [NormedSpace ℝ E'] [NormedSpace ℝ F] /-- The forward convolution of two functions `f` and `g` on `ℝ`, with respect to a continuous bilinear map `L` and measure `ν`. It is defined to be the function mapping `x` to `∫ t in 0..x, L (f t) (g (x - t)) ∂ν` if `0 < x`, and 0 otherwise. -/ noncomputable def posConvolution (f : ℝ → E) (g : ℝ → E') (L : E →L[ℝ] E' →L[ℝ] F) (ν : Measure ℝ := by volume_tac) : ℝ → F := indicator (Ioi (0 : ℝ)) fun x => ∫ t in (0)..x, L (f t) (g (x - t)) ∂ν theorem posConvolution_eq_convolution_indicator (f : ℝ → E) (g : ℝ → E') (L : E →L[ℝ] E' →L[ℝ] F) (ν : Measure ℝ := by volume_tac) [NoAtoms ν] : posConvolution f g L ν = convolution (indicator (Ioi 0) f) (indicator (Ioi 0) g) L ν := by ext1 x rw [convolution, posConvolution, indicator] split_ifs with h · rw [intervalIntegral.integral_of_le (le_of_lt h), integral_Ioc_eq_integral_Ioo, ← integral_indicator (measurableSet_Ioo : MeasurableSet (Ioo 0 x))] congr 1 with t : 1 have : t ≤ 0 ∨ t ∈ Ioo 0 x ∨ x ≤ t := by rcases le_or_lt t 0 with (h | h) · exact Or.inl h · rcases lt_or_le t x with (h' | h') exacts [Or.inr (Or.inl ⟨h, h'⟩), Or.inr (Or.inr h')] rcases this with (ht | ht | ht) · rw [indicator_of_not_mem (not_mem_Ioo_of_le ht), indicator_of_not_mem (not_mem_Ioi.mpr ht), ContinuousLinearMap.map_zero, ContinuousLinearMap.zero_apply] · rw [indicator_of_mem ht, indicator_of_mem (mem_Ioi.mpr ht.1), indicator_of_mem (mem_Ioi.mpr <| sub_pos.mpr ht.2)] · rw [indicator_of_not_mem (not_mem_Ioo_of_ge ht), indicator_of_not_mem (not_mem_Ioi.mpr (sub_nonpos_of_le ht)), ContinuousLinearMap.map_zero] · convert (integral_zero ℝ F).symm with t by_cases ht : 0 < t · rw [indicator_of_not_mem (_ : x - t ∉ Ioi 0), ContinuousLinearMap.map_zero] rw [not_mem_Ioi] at h ⊢ exact sub_nonpos.mpr (h.trans ht.le) · rw [indicator_of_not_mem (mem_Ioi.not.mpr ht), ContinuousLinearMap.map_zero, ContinuousLinearMap.zero_apply] theorem integrable_posConvolution {f : ℝ → E} {g : ℝ → E'} {μ ν : Measure ℝ} [SFinite μ] [SFinite ν] [IsAddRightInvariant μ] [NoAtoms ν] (hf : IntegrableOn f (Ioi 0) ν) (hg : IntegrableOn g (Ioi 0) μ) (L : E →L[ℝ] E' →L[ℝ] F) : Integrable (posConvolution f g L ν) μ := by rw [← integrable_indicator_iff (measurableSet_Ioi : MeasurableSet (Ioi (0 : ℝ)))] at hf hg rw [posConvolution_eq_convolution_indicator f g L ν] exact (hf.convolution_integrand L hg).integral_prod_left /-- The integral over `Ioi 0` of a forward convolution of two functions is equal to the product of their integrals over this set. (Compare `integral_convolution` for the two-sided convolution.) -/ theorem integral_posConvolution [CompleteSpace E] [CompleteSpace E'] [CompleteSpace F] {μ ν : Measure ℝ} [SFinite μ] [SFinite ν] [IsAddRightInvariant μ] [NoAtoms ν] {f : ℝ → E} {g : ℝ → E'} (hf : IntegrableOn f (Ioi 0) ν) (hg : IntegrableOn g (Ioi 0) μ) (L : E →L[ℝ] E' →L[ℝ] F) : ∫ x : ℝ in Ioi 0, ∫ t : ℝ in (0)..x, L (f t) (g (x - t)) ∂ν ∂μ = L (∫ x : ℝ in Ioi 0, f x ∂ν) (∫ x : ℝ in Ioi 0, g x ∂μ) := by rw [← integrable_indicator_iff measurableSet_Ioi] at hf hg simp_rw [← integral_indicator measurableSet_Ioi]
convert integral_convolution L hf hg using 4 with x apply posConvolution_eq_convolution_indicator end Nonneg end MeasureTheory
Mathlib/Analysis/Convolution.lean
1,392
1,399
/- Copyright (c) 2021 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.LinearAlgebra.Basis.Basic import Mathlib.LinearAlgebra.Basis.Submodule import Mathlib.LinearAlgebra.Dimension.Finrank import Mathlib.LinearAlgebra.InvariantBasisNumber /-! # Lemmas about rank and finrank in rings satisfying strong rank condition. ## Main statements For modules over rings satisfying the rank condition * `Basis.le_span`: the cardinality of a basis is bounded by the cardinality of any spanning set For modules over rings satisfying the strong rank condition * `linearIndependent_le_span`: For any linearly independent family `v : ι → M` and any finite spanning set `w : Set M`, the cardinality of `ι` is bounded by the cardinality of `w`. * `linearIndependent_le_basis`: If `b` is a basis for a module `M`, and `s` is a linearly independent set, then the cardinality of `s` is bounded by the cardinality of `b`. For modules over rings with invariant basis number (including all commutative rings and all noetherian rings) * `mk_eq_mk_of_basis`: the dimension theorem, any two bases of the same vector space have the same cardinality. ## Additional definition * `Algebra.IsQuadraticExtension`: An extension of rings `R ⊆ S` is quadratic if `S` is a free `R`-algebra of rank `2`. -/ noncomputable section universe u v w w' variable {R : Type u} {M : Type v} [Semiring R] [AddCommMonoid M] [Module R M] variable {ι : Type w} {ι' : Type w'} open Cardinal Basis Submodule Function Set Module attribute [local instance] nontrivial_of_invariantBasisNumber section InvariantBasisNumber variable [InvariantBasisNumber R] /-- The dimension theorem: if `v` and `v'` are two bases, their index types have the same cardinalities. -/ theorem mk_eq_mk_of_basis (v : Basis ι R M) (v' : Basis ι' R M) : Cardinal.lift.{w'} #ι = Cardinal.lift.{w} #ι' := by classical haveI := nontrivial_of_invariantBasisNumber R cases fintypeOrInfinite ι · -- `v` is a finite basis, so by `basis_finite_of_finite_spans` so is `v'`. -- haveI : Finite (range v) := Set.finite_range v haveI := basis_finite_of_finite_spans (Set.finite_range v) v.span_eq v' cases nonempty_fintype ι' -- We clean up a little: rw [Cardinal.mk_fintype, Cardinal.mk_fintype] simp only [Cardinal.lift_natCast, Nat.cast_inj] -- Now we can use invariant basis number to show they have the same cardinality. apply card_eq_of_linearEquiv R exact (Finsupp.linearEquivFunOnFinite R R ι).symm.trans v.repr.symm ≪≫ₗ v'.repr ≪≫ₗ Finsupp.linearEquivFunOnFinite R R ι' · -- `v` is an infinite basis, -- so by `infinite_basis_le_maximal_linearIndependent`, `v'` is at least as big, -- and then applying `infinite_basis_le_maximal_linearIndependent` again -- we see they have the same cardinality. have w₁ := infinite_basis_le_maximal_linearIndependent' v _ v'.linearIndependent v'.maximal rcases Cardinal.lift_mk_le'.mp w₁ with ⟨f⟩ haveI : Infinite ι' := Infinite.of_injective f f.2 have w₂ := infinite_basis_le_maximal_linearIndependent' v' _ v.linearIndependent v.maximal exact le_antisymm w₁ w₂ /-- Given two bases indexed by `ι` and `ι'` of an `R`-module, where `R` satisfies the invariant basis number property, an equiv `ι ≃ ι'`. -/ def Basis.indexEquiv (v : Basis ι R M) (v' : Basis ι' R M) : ι ≃ ι' := (Cardinal.lift_mk_eq'.1 <| mk_eq_mk_of_basis v v').some theorem mk_eq_mk_of_basis' {ι' : Type w} (v : Basis ι R M) (v' : Basis ι' R M) : #ι = #ι' := Cardinal.lift_inj.1 <| mk_eq_mk_of_basis v v' end InvariantBasisNumber section RankCondition variable [RankCondition R] /-- An auxiliary lemma for `Basis.le_span`. If `R` satisfies the rank condition, then for any finite basis `b : Basis ι R M`, and any finite spanning set `w : Set M`, the cardinality of `ι` is bounded by the cardinality of `w`. -/ theorem Basis.le_span'' {ι : Type*} [Fintype ι] (b : Basis ι R M) {w : Set M} [Fintype w] (s : span R w = ⊤) : Fintype.card ι ≤ Fintype.card w := by -- We construct a surjective linear map `(w → R) →ₗ[R] (ι → R)`, -- by expressing a linear combination in `w` as a linear combination in `ι`. fapply card_le_of_surjective' R · exact b.repr.toLinearMap.comp (Finsupp.linearCombination R (↑)) · apply Surjective.comp (g := b.repr.toLinearMap) · apply LinearEquiv.surjective rw [← LinearMap.range_eq_top, Finsupp.range_linearCombination] simpa using s /-- Another auxiliary lemma for `Basis.le_span`, which does not require assuming the basis is finite, but still assumes we have a finite spanning set. -/ theorem basis_le_span' {ι : Type*} (b : Basis ι R M) {w : Set M} [Fintype w] (s : span R w = ⊤) : #ι ≤ Fintype.card w := by haveI := nontrivial_of_invariantBasisNumber R haveI := basis_finite_of_finite_spans w.toFinite s b cases nonempty_fintype ι rw [Cardinal.mk_fintype ι] simp only [Nat.cast_le] exact Basis.le_span'' b s -- Note that if `R` satisfies the strong rank condition, -- this also follows from `linearIndependent_le_span` below. /-- If `R` satisfies the rank condition, then the cardinality of any basis is bounded by the cardinality of any spanning set. -/ theorem Basis.le_span {J : Set M} (v : Basis ι R M) (hJ : span R J = ⊤) : #(range v) ≤ #J := by haveI := nontrivial_of_invariantBasisNumber R cases fintypeOrInfinite J · rw [← Cardinal.lift_le, Cardinal.mk_range_eq_of_injective v.injective, Cardinal.mk_fintype J] convert Cardinal.lift_le.{v}.2 (basis_le_span' v hJ) simp · let S : J → Set ι := fun j => ↑(v.repr j).support let S' : J → Set M := fun j => v '' S j have hs : range v ⊆ ⋃ j, S' j := by intro b hb rcases mem_range.1 hb with ⟨i, hi⟩ have : span R J ≤ comap v.repr.toLinearMap (Finsupp.supported R R (⋃ j, S j)) := span_le.2 fun j hj x hx => ⟨_, ⟨⟨j, hj⟩, rfl⟩, hx⟩ rw [hJ] at this replace : v.repr (v i) ∈ Finsupp.supported R R (⋃ j, S j) := this trivial rw [v.repr_self, Finsupp.mem_supported, Finsupp.support_single_ne_zero _ one_ne_zero] at this · subst b rcases mem_iUnion.1 (this (Finset.mem_singleton_self _)) with ⟨j, hj⟩ exact mem_iUnion.2 ⟨j, (mem_image _ _ _).2 ⟨i, hj, rfl⟩⟩ refine le_of_not_lt fun IJ => ?_ suffices #(⋃ j, S' j) < #(range v) by exact not_le_of_lt this ⟨Set.embeddingOfSubset _ _ hs⟩ refine lt_of_le_of_lt (le_trans Cardinal.mk_iUnion_le_sum_mk (Cardinal.sum_le_sum _ (fun _ => ℵ₀) ?_)) ?_ · exact fun j => (Cardinal.lt_aleph0_of_finite _).le · simpa end RankCondition section StrongRankCondition variable [StrongRankCondition R] open Submodule Finsupp -- An auxiliary lemma for `linearIndependent_le_span'`, -- with the additional assumption that the linearly independent family is finite. theorem linearIndependent_le_span_aux' {ι : Type*} [Fintype ι] (v : ι → M) (i : LinearIndependent R v) (w : Set M) [Fintype w] (s : range v ≤ span R w) : Fintype.card ι ≤ Fintype.card w := by -- We construct an injective linear map `(ι → R) →ₗ[R] (w → R)`, -- by thinking of `f : ι → R` as a linear combination of the finite family `v`, -- and expressing that (using the axiom of choice) as a linear combination over `w`. -- We can do this linearly by constructing the map on a basis. fapply card_le_of_injective' R · apply Finsupp.linearCombination exact fun i => Span.repr R w ⟨v i, s (mem_range_self i)⟩ · intro f g h apply_fun linearCombination R ((↑) : w → M) at h simp only [linearCombination_linearCombination, Submodule.coe_mk, Span.finsupp_linearCombination_repr] at h exact i h /-- If `R` satisfies the strong rank condition, then any linearly independent family `v : ι → M` contained in the span of some finite `w : Set M`, is itself finite. -/ lemma LinearIndependent.finite_of_le_span_finite {ι : Type*} (v : ι → M) (i : LinearIndependent R v) (w : Set M) [Finite w] (s : range v ≤ span R w) : Finite ι := letI := Fintype.ofFinite w Fintype.finite <| fintypeOfFinsetCardLe (Fintype.card w) fun t => by let v' := fun x : (t : Set ι) => v x have i' : LinearIndependent R v' := i.comp _ Subtype.val_injective have s' : range v' ≤ span R w := (range_comp_subset_range _ _).trans s simpa using linearIndependent_le_span_aux' v' i' w s' /-- If `R` satisfies the strong rank condition, then for any linearly independent family `v : ι → M` contained in the span of some finite `w : Set M`, the cardinality of `ι` is bounded by the cardinality of `w`. -/ theorem linearIndependent_le_span' {ι : Type*} (v : ι → M) (i : LinearIndependent R v) (w : Set M) [Fintype w] (s : range v ≤ span R w) : #ι ≤ Fintype.card w := by haveI : Finite ι := i.finite_of_le_span_finite v w s letI := Fintype.ofFinite ι rw [Cardinal.mk_fintype] simp only [Nat.cast_le] exact linearIndependent_le_span_aux' v i w s /-- If `R` satisfies the strong rank condition, then for any linearly independent family `v : ι → M` and any finite spanning set `w : Set M`, the cardinality of `ι` is bounded by the cardinality of `w`. -/ theorem linearIndependent_le_span {ι : Type*} (v : ι → M) (i : LinearIndependent R v) (w : Set M) [Fintype w] (s : span R w = ⊤) : #ι ≤ Fintype.card w := by apply linearIndependent_le_span' v i w rw [s] exact le_top /-- A version of `linearIndependent_le_span` for `Finset`. -/ theorem linearIndependent_le_span_finset {ι : Type*} (v : ι → M) (i : LinearIndependent R v) (w : Finset M) (s : span R (w : Set M) = ⊤) : #ι ≤ w.card := by simpa only [Finset.coe_sort_coe, Fintype.card_coe] using linearIndependent_le_span v i w s /-- An auxiliary lemma for `linearIndependent_le_basis`: we handle the case where the basis `b` is infinite. -/ theorem linearIndependent_le_infinite_basis {ι : Type w} (b : Basis ι R M) [Infinite ι] {κ : Type w} (v : κ → M) (i : LinearIndependent R v) : #κ ≤ #ι := by classical by_contra h rw [not_le, ← Cardinal.mk_finset_of_infinite ι] at h let Φ := fun k : κ => (b.repr (v k)).support obtain ⟨s, w : Infinite ↑(Φ ⁻¹' {s})⟩ := Cardinal.exists_infinite_fiber Φ h (by infer_instance) let v' := fun k : Φ ⁻¹' {s} => v k have i' : LinearIndependent R v' := i.comp _ Subtype.val_injective have w' : Finite (Φ ⁻¹' {s}) := by apply i'.finite_of_le_span_finite v' (s.image b) rintro m ⟨⟨p, ⟨rfl⟩⟩, rfl⟩ simp only [SetLike.mem_coe, Subtype.coe_mk, Finset.coe_image] apply Basis.mem_span_repr_support exact w.false /-- Over any ring `R` satisfying the strong rank condition, if `b` is a basis for a module `M`, and `s` is a linearly independent set, then the cardinality of `s` is bounded by the cardinality of `b`. -/ theorem linearIndependent_le_basis {ι : Type w} (b : Basis ι R M) {κ : Type w} (v : κ → M) (i : LinearIndependent R v) : #κ ≤ #ι := by classical -- We split into cases depending on whether `ι` is infinite. cases fintypeOrInfinite ι · rw [Cardinal.mk_fintype ι] -- When `ι` is finite, we have `linearIndependent_le_span`, haveI : Nontrivial R := nontrivial_of_invariantBasisNumber R rw [Fintype.card_congr (Equiv.ofInjective b b.injective)] exact linearIndependent_le_span v i (range b) b.span_eq · -- and otherwise we have `linearIndependent_le_infinite_basis`. exact linearIndependent_le_infinite_basis b v i /-- `StrongRankCondition` implies that if there is an injective linear map `(α →₀ R) →ₗ[R] β →₀ R`, then the cardinal of `α` is smaller than or equal to the cardinal of `β`. -/ theorem card_le_of_injective'' {α : Type v} {β : Type v} (f : (α →₀ R) →ₗ[R] β →₀ R) (i : Injective f) : #α ≤ #β := by let b : Basis β R (β →₀ R) := ⟨1⟩ apply linearIndependent_le_basis b (fun (i : α) ↦ f (Finsupp.single i 1)) rw [LinearIndependent] have : (linearCombination R fun i ↦ f (Finsupp.single i 1)) = f := by ext a b; simp exact this.symm ▸ i /-- If `R` satisfies the strong rank condition, then for any linearly independent family `v : ι → M` and spanning set `w : Set M`, the cardinality of `ι` is bounded by the cardinality of `w`. -/ theorem linearIndependent_le_span'' {ι : Type v} {v : ι → M} (i : LinearIndependent R v) (w : Set M) (s : span R w = ⊤) : #ι ≤ #w := by fapply card_le_of_injective'' (R := R) · apply Finsupp.linearCombination exact fun i ↦ Span.repr R w ⟨v i, s ▸ trivial⟩ · intro f g h apply_fun linearCombination R ((↑) : w → M) at h simp only [linearCombination_linearCombination, Submodule.coe_mk, Span.finsupp_linearCombination_repr] at h exact i h /-- Let `R` satisfy the strong rank condition. If `m` elements of a free rank `n` `R`-module are linearly independent, then `m ≤ n`. -/ theorem Basis.card_le_card_of_linearIndependent_aux {R : Type*} [Semiring R] [StrongRankCondition R] (n : ℕ) {m : ℕ} (v : Fin m → Fin n → R) : LinearIndependent R v → m ≤ n := fun h => by simpa using linearIndependent_le_basis (Pi.basisFun R (Fin n)) v h -- When the basis is not infinite this need not be true! /-- Over any ring `R` satisfying the strong rank condition, if `b` is an infinite basis for a module `M`, then every maximal linearly independent set has the same cardinality as `b`. This proof (along with some of the lemmas above) comes from [Les familles libres maximales d'un module ont-elles le meme cardinal?][lazarus1973] -/ theorem maximal_linearIndependent_eq_infinite_basis {ι : Type w} (b : Basis ι R M) [Infinite ι] {κ : Type w} (v : κ → M) (i : LinearIndependent R v) (m : i.Maximal) : #κ = #ι := by apply le_antisymm · exact linearIndependent_le_basis b v i · haveI : Nontrivial R := nontrivial_of_invariantBasisNumber R exact infinite_basis_le_maximal_linearIndependent b v i m theorem Basis.mk_eq_rank'' {ι : Type v} (v : Basis ι R M) : #ι = Module.rank R M := by haveI := nontrivial_of_invariantBasisNumber R rw [Module.rank_def] apply le_antisymm · trans swap · apply le_ciSup (Cardinal.bddAbove_range _) exact ⟨Set.range v, by rw [LinearIndepOn] convert v.reindexRange.linearIndependent simp⟩ · exact (Cardinal.mk_range_eq v v.injective).ge · apply ciSup_le' rintro ⟨s, li⟩ apply linearIndependent_le_basis v _ li
theorem Basis.mk_range_eq_rank (v : Basis ι R M) : #(range v) = Module.rank R M := v.reindexRange.mk_eq_rank'' /-- If a vector space has a finite basis, then its dimension (seen as a cardinal) is equal to the
Mathlib/LinearAlgebra/Dimension/StrongRankCondition.lean
333
337
/- 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 simp [← not_iff_not] variable [Module.Free R M] theorem finrank_eq_zero_of_basis_imp_not_finite (h : ∀ s : Set M, Basis.{v} (s : Set M) R M → ¬s.Finite) : finrank R M = 0 := by cases subsingleton_or_nontrivial R · have := Module.subsingleton R M exact (h ∅ ⟨LinearEquiv.ofSubsingleton _ _⟩ Set.finite_empty).elim obtain ⟨_, ⟨b⟩⟩ := (Module.free_iff_set R M).mp ‹_› have := Set.Infinite.to_subtype (h _ b) exact b.linearIndependent.finrank_eq_zero_of_infinite theorem finrank_eq_zero_of_basis_imp_false (h : ∀ s : Finset M, Basis.{v} (s : Set M) R M → False) : finrank R M = 0 := finrank_eq_zero_of_basis_imp_not_finite fun s b hs => h hs.toFinset (by convert b simp)
theorem finrank_eq_zero_of_not_exists_basis (h : ¬∃ s : Finset M, Nonempty (Basis (s : Set M) R M)) : finrank R M = 0 := finrank_eq_zero_of_basis_imp_false fun s b => h ⟨s, ⟨b⟩⟩ theorem finrank_eq_zero_of_not_exists_basis_finite (h : ¬∃ (s : Set M) (_ : Basis.{v} (s : Set M) R M), s.Finite) : finrank R M = 0 :=
Mathlib/LinearAlgebra/Dimension/Finite.lean
503
509
/- Copyright (c) 2018 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad -/ import Mathlib.Data.PFunctor.Univariate.M /-! # Quotients of Polynomial Functors We assume the following: * `P`: a polynomial functor * `W`: its W-type * `M`: its M-type * `F`: a functor We define: * `q`: `QPF` data, representing `F` as a quotient of `P` The main goal is to construct: * `Fix`: the initial algebra with structure map `F Fix → Fix`. * `Cofix`: the final coalgebra with structure map `Cofix → F Cofix` We also show that the composition of qpfs is a qpf, and that the quotient of a qpf is a qpf. The present theory focuses on the univariate case for qpfs ## References * [Jeremy Avigad, Mario M. Carneiro and Simon Hudon, *Data Types as Quotients of Polynomial Functors*][avigad-carneiro-hudon2019] -/ universe u /-- Quotients of polynomial functors. Roughly speaking, saying that `F` is a quotient of a polynomial functor means that for each `α`, elements of `F α` are represented by pairs `⟨a, f⟩`, where `a` is the shape of the object and `f` indexes the relevant elements of `α`, in a suitably natural manner. -/ class QPF (F : Type u → Type u) extends Functor F where P : PFunctor.{u} abs : ∀ {α}, P α → F α repr : ∀ {α}, F α → P α abs_repr : ∀ {α} (x : F α), abs (repr x) = x abs_map : ∀ {α β} (f : α → β) (p : P α), abs (P.map f p) = f <$> abs p namespace QPF variable {F : Type u → Type u} [q : QPF F] open Functor (Liftp Liftr) /- Show that every qpf is a lawful functor. Note: every functor has a field, `map_const`, and `lawfulFunctor` has the defining characterization. We can only propagate the assumption. -/ theorem id_map {α : Type _} (x : F α) : id <$> x = x := by rw [← abs_repr x] obtain ⟨a, f⟩ := repr x rw [← abs_map] rfl theorem comp_map {α β γ : Type _} (f : α → β) (g : β → γ) (x : F α) : (g ∘ f) <$> x = g <$> f <$> x := by rw [← abs_repr x] obtain ⟨a, f⟩ := repr x rw [← abs_map, ← abs_map, ← abs_map] rfl theorem lawfulFunctor (h : ∀ α β : Type u, @Functor.mapConst F _ α _ = Functor.map ∘ Function.const β) : LawfulFunctor F := { map_const := @h id_map := @id_map F _ comp_map := @comp_map F _ } /- Lifting predicates and relations -/ section open Functor theorem liftp_iff {α : Type u} (p : α → Prop) (x : F α) : Liftp p x ↔ ∃ a f, x = abs ⟨a, f⟩ ∧ ∀ i, p (f i) := by constructor · rintro ⟨y, hy⟩ rcases h : repr y with ⟨a, f⟩ use a, fun i => (f i).val constructor · rw [← hy, ← abs_repr y, h, ← abs_map] rfl intro i apply (f i).property rintro ⟨a, f, h₀, h₁⟩ use abs ⟨a, fun i => ⟨f i, h₁ i⟩⟩ rw [← abs_map, h₀]; rfl theorem liftp_iff' {α : Type u} (p : α → Prop) (x : F α) : Liftp p x ↔ ∃ u : q.P α, abs u = x ∧ ∀ i, p (u.snd i) := by constructor · rintro ⟨y, hy⟩ rcases h : repr y with ⟨a, f⟩ use ⟨a, fun i => (f i).val⟩ dsimp constructor · rw [← hy, ← abs_repr y, h, ← abs_map] rfl intro i apply (f i).property rintro ⟨⟨a, f⟩, h₀, h₁⟩; dsimp at * use abs ⟨a, fun i => ⟨f i, h₁ i⟩⟩ rw [← abs_map, ← h₀]; rfl theorem liftr_iff {α : Type u} (r : α → α → Prop) (x y : F α) : Liftr r x y ↔ ∃ a f₀ f₁, x = abs ⟨a, f₀⟩ ∧ y = abs ⟨a, f₁⟩ ∧ ∀ i, r (f₀ i) (f₁ i) := by constructor · rintro ⟨u, xeq, yeq⟩ rcases h : repr u with ⟨a, f⟩ use a, fun i => (f i).val.fst, fun i => (f i).val.snd constructor · rw [← xeq, ← abs_repr u, h, ← abs_map] rfl constructor · rw [← yeq, ← abs_repr u, h, ← abs_map] rfl intro i exact (f i).property rintro ⟨a, f₀, f₁, xeq, yeq, h⟩ use abs ⟨a, fun i => ⟨(f₀ i, f₁ i), h i⟩⟩ constructor · rw [xeq, ← abs_map] rfl rw [yeq, ← abs_map]; rfl end /- Think of trees in the `W` type corresponding to `P` as representatives of elements of the least fixed point of `F`, and assign a canonical representative to each equivalence class of trees. -/ /-- does recursion on `q.P.W` using `g : F α → α` rather than `g : P α → α` -/ def recF {α : Type _} (g : F α → α) : q.P.W → α | ⟨a, f⟩ => g (abs ⟨a, fun x => recF g (f x)⟩) theorem recF_eq {α : Type _} (g : F α → α) (x : q.P.W) : recF g x = g (abs (q.P.map (recF g) x.dest)) := by cases x rfl theorem recF_eq' {α : Type _} (g : F α → α) (a : q.P.A) (f : q.P.B a → q.P.W) : recF g ⟨a, f⟩ = g (abs (q.P.map (recF g) ⟨a, f⟩)) := rfl /-- two trees are equivalent if their F-abstractions are -/ inductive Wequiv : q.P.W → q.P.W → Prop | ind (a : q.P.A) (f f' : q.P.B a → q.P.W) : (∀ x, Wequiv (f x) (f' x)) → Wequiv ⟨a, f⟩ ⟨a, f'⟩ | abs (a : q.P.A) (f : q.P.B a → q.P.W) (a' : q.P.A) (f' : q.P.B a' → q.P.W) : abs ⟨a, f⟩ = abs ⟨a', f'⟩ → Wequiv ⟨a, f⟩ ⟨a', f'⟩ | trans (u v w : q.P.W) : Wequiv u v → Wequiv v w → Wequiv u w /-- `recF` is insensitive to the representation -/ theorem recF_eq_of_Wequiv {α : Type u} (u : F α → α) (x y : q.P.W) : Wequiv x y → recF u x = recF u y := by intro h induction h with | ind a f f' _ ih => simp only [recF_eq', PFunctor.map_eq, Function.comp_def, ih] | abs a f a' f' h => simp only [recF_eq', abs_map, h] | trans x y z _ _ ih₁ ih₂ => exact Eq.trans ih₁ ih₂ theorem Wequiv.abs' (x y : q.P.W) (h : QPF.abs x.dest = QPF.abs y.dest) : Wequiv x y := by cases x cases y apply Wequiv.abs apply h theorem Wequiv.refl (x : q.P.W) : Wequiv x x := by obtain ⟨a, f⟩ := x exact Wequiv.abs a f a f rfl theorem Wequiv.symm (x y : q.P.W) : Wequiv x y → Wequiv y x := by intro h induction h with | ind a f f' _ ih => exact Wequiv.ind _ _ _ ih | abs a f a' f' h => exact Wequiv.abs _ _ _ _ h.symm | trans x y z _ _ ih₁ ih₂ => exact QPF.Wequiv.trans _ _ _ ih₂ ih₁ /-- maps every element of the W type to a canonical representative -/ def Wrepr : q.P.W → q.P.W := recF (PFunctor.W.mk ∘ repr) theorem Wrepr_equiv (x : q.P.W) : Wequiv (Wrepr x) x := by induction' x with a f ih apply Wequiv.trans · change Wequiv (Wrepr ⟨a, f⟩) (PFunctor.W.mk (q.P.map Wrepr ⟨a, f⟩)) apply Wequiv.abs' have : Wrepr ⟨a, f⟩ = PFunctor.W.mk (repr (abs (q.P.map Wrepr ⟨a, f⟩))) := rfl rw [this, PFunctor.W.dest_mk, abs_repr] rfl apply Wequiv.ind; exact ih /-- Define the fixed point as the quotient of trees under the equivalence relation `Wequiv`. -/ def Wsetoid : Setoid q.P.W := ⟨Wequiv, @Wequiv.refl _ _, @Wequiv.symm _ _, @Wequiv.trans _ _⟩ attribute [local instance] Wsetoid /-- inductive type defined as initial algebra of a Quotient of Polynomial Functor -/ def Fix (F : Type u → Type u) [q : QPF F] := Quotient (Wsetoid : Setoid q.P.W) /-- recursor of a type defined by a qpf -/ def Fix.rec {α : Type _} (g : F α → α) : Fix F → α := Quot.lift (recF g) (recF_eq_of_Wequiv g) /-- access the underlying W-type of a fixpoint data type -/ def fixToW : Fix F → q.P.W := Quotient.lift Wrepr (recF_eq_of_Wequiv fun x => @PFunctor.W.mk q.P (repr x)) /-- constructor of a type defined by a qpf -/ def Fix.mk (x : F (Fix F)) : Fix F := Quot.mk _ (PFunctor.W.mk (q.P.map fixToW (repr x))) /-- destructor of a type defined by a qpf -/ def Fix.dest : Fix F → F (Fix F) := Fix.rec (Functor.map Fix.mk) theorem Fix.rec_eq {α : Type _} (g : F α → α) (x : F (Fix F)) : Fix.rec g (Fix.mk x) = g (Fix.rec g <$> x) := by have : recF g ∘ fixToW = Fix.rec g := by ext ⟨x⟩ apply recF_eq_of_Wequiv rw [fixToW] apply Wrepr_equiv conv => lhs rw [Fix.rec, Fix.mk] dsimp rcases h : repr x with ⟨a, f⟩ rw [PFunctor.map_eq, recF_eq, ← PFunctor.map_eq, PFunctor.W.dest_mk, PFunctor.map_map, abs_map, ← h, abs_repr, this] theorem Fix.ind_aux (a : q.P.A) (f : q.P.B a → q.P.W) : Fix.mk (abs ⟨a, fun x => ⟦f x⟧⟩) = ⟦⟨a, f⟩⟧ := by have : Fix.mk (abs ⟨a, fun x => ⟦f x⟧⟩) = ⟦Wrepr ⟨a, f⟩⟧ := by apply Quot.sound; apply Wequiv.abs' rw [PFunctor.W.dest_mk, abs_map, abs_repr, ← abs_map, PFunctor.map_eq] simp only [Wrepr, recF_eq, PFunctor.W.dest_mk, abs_repr, Function.comp] rfl rw [this] apply Quot.sound apply Wrepr_equiv theorem Fix.ind_rec {α : Type u} (g₁ g₂ : Fix F → α) (h : ∀ x : F (Fix F), g₁ <$> x = g₂ <$> x → g₁ (Fix.mk x) = g₂ (Fix.mk x)) : ∀ x, g₁ x = g₂ x := by rintro ⟨x⟩ induction' x with a f ih change g₁ ⟦⟨a, f⟩⟧ = g₂ ⟦⟨a, f⟩⟧ rw [← Fix.ind_aux a f]; apply h rw [← abs_map, ← abs_map, PFunctor.map_eq, PFunctor.map_eq] congr with x apply ih theorem Fix.rec_unique {α : Type u} (g : F α → α) (h : Fix F → α) (hyp : ∀ x, h (Fix.mk x) = g (h <$> x)) : Fix.rec g = h := by ext x apply Fix.ind_rec intro x hyp' rw [hyp, ← hyp', Fix.rec_eq] theorem Fix.mk_dest (x : Fix F) : Fix.mk (Fix.dest x) = x := by change (Fix.mk ∘ Fix.dest) x = id x apply Fix.ind_rec (mk ∘ dest) id intro x rw [Function.comp_apply, id_eq, Fix.dest, Fix.rec_eq, id_map, comp_map] intro h rw [h] theorem Fix.dest_mk (x : F (Fix F)) : Fix.dest (Fix.mk x) = x := by unfold Fix.dest; rw [Fix.rec_eq, ← Fix.dest, ← comp_map] conv => rhs rw [← id_map x] congr with x apply Fix.mk_dest theorem Fix.ind (p : Fix F → Prop) (h : ∀ x : F (Fix F), Liftp p x → p (Fix.mk x)) : ∀ x, p x := by rintro ⟨x⟩ induction' x with a f ih change p ⟦⟨a, f⟩⟧ rw [← Fix.ind_aux a f] apply h rw [liftp_iff] refine ⟨_, _, rfl, ?_⟩ convert ih end QPF /- Construct the final coalgebra to a qpf. -/ namespace QPF variable {F : Type u → Type u} [q : QPF F] open Functor (Liftp Liftr) /-- does recursion on `q.P.M` using `g : α → F α` rather than `g : α → P α` -/
def corecF {α : Type _} (g : α → F α) : α → q.P.M := PFunctor.M.corec fun x => repr (g x) theorem corecF_eq {α : Type _} (g : α → F α) (x : α) : PFunctor.M.dest (corecF g x) = q.P.map (corecF g) (repr (g x)) := by rw [corecF, PFunctor.M.dest_corec]
Mathlib/Data/QPF/Univariate/Basic.lean
322
327
/- Copyright (c) 2020 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot -/ import Mathlib.Topology.Path /-! # Path connectedness Continuing from `Mathlib.Topology.Path`, this file defines path components and path-connected spaces. ## Main definitions In the file the unit interval `[0, 1]` in `ℝ` is denoted by `I`, and `X` is a topological space. * `Joined (x y : X)` means there is a path between `x` and `y`. * `Joined.somePath (h : Joined x y)` selects some path between two points `x` and `y`. * `pathComponent (x : X)` is the set of points joined to `x`. * `PathConnectedSpace X` is a predicate class asserting that `X` is non-empty and every two points of `X` are joined. Then there are corresponding relative notions for `F : Set X`. * `JoinedIn F (x y : X)` means there is a path `γ` joining `x` to `y` with values in `F`. * `JoinedIn.somePath (h : JoinedIn F x y)` selects a path from `x` to `y` inside `F`. * `pathComponentIn F (x : X)` is the set of points joined to `x` in `F`. * `IsPathConnected F` asserts that `F` is non-empty and every two points of `F` are joined in `F`. ## Main theorems * `Joined` is an equivalence relation, while `JoinedIn F` is at least symmetric and transitive. One can link the absolute and relative version in two directions, using `(univ : Set X)` or the subtype `↥F`. * `pathConnectedSpace_iff_univ : PathConnectedSpace X ↔ IsPathConnected (univ : Set X)` * `isPathConnected_iff_pathConnectedSpace : IsPathConnected F ↔ PathConnectedSpace ↥F` Furthermore, it is shown that continuous images and quotients of path-connected sets/spaces are path-connected, and that every path-connected set/space is also connected. -/ noncomputable section open Topology Filter unitInterval Set Function variable {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] {x y z : X} {ι : Type*} /-! ### Being joined by a path -/ /-- The relation "being joined by a path". This is an equivalence relation. -/ def Joined (x y : X) : Prop := Nonempty (Path x y) @[refl] theorem Joined.refl (x : X) : Joined x x := ⟨Path.refl x⟩ /-- When two points are joined, choose some path from `x` to `y`. -/ def Joined.somePath (h : Joined x y) : Path x y := Nonempty.some h @[symm] theorem Joined.symm {x y : X} (h : Joined x y) : Joined y x := ⟨h.somePath.symm⟩ @[trans] theorem Joined.trans {x y z : X} (hxy : Joined x y) (hyz : Joined y z) : Joined x z := ⟨hxy.somePath.trans hyz.somePath⟩ variable (X) /-- The setoid corresponding the equivalence relation of being joined by a continuous path. -/ def pathSetoid : Setoid X where r := Joined iseqv := Equivalence.mk Joined.refl Joined.symm Joined.trans /-- The quotient type of points of a topological space modulo being joined by a continuous path. -/ def ZerothHomotopy := Quotient (pathSetoid X) instance ZerothHomotopy.inhabited : Inhabited (ZerothHomotopy ℝ) := ⟨@Quotient.mk' ℝ (pathSetoid ℝ) 0⟩ variable {X} /-! ### Being joined by a path inside a set -/ /-- The relation "being joined by a path in `F`". Not quite an equivalence relation since it's not reflexive for points that do not belong to `F`. -/ def JoinedIn (F : Set X) (x y : X) : Prop := ∃ γ : Path x y, ∀ t, γ t ∈ F variable {F : Set X} theorem JoinedIn.mem (h : JoinedIn F x y) : x ∈ F ∧ y ∈ F := by rcases h with ⟨γ, γ_in⟩ have : γ 0 ∈ F ∧ γ 1 ∈ F := by constructor <;> apply γ_in simpa using this theorem JoinedIn.source_mem (h : JoinedIn F x y) : x ∈ F := h.mem.1 theorem JoinedIn.target_mem (h : JoinedIn F x y) : y ∈ F := h.mem.2 /-- When `x` and `y` are joined in `F`, choose a path from `x` to `y` inside `F` -/ def JoinedIn.somePath (h : JoinedIn F x y) : Path x y := Classical.choose h theorem JoinedIn.somePath_mem (h : JoinedIn F x y) (t : I) : h.somePath t ∈ F := Classical.choose_spec h t /-- If `x` and `y` are joined in the set `F`, then they are joined in the subtype `F`. -/ theorem JoinedIn.joined_subtype (h : JoinedIn F x y) : Joined (⟨x, h.source_mem⟩ : F) (⟨y, h.target_mem⟩ : F) := ⟨{ toFun := fun t => ⟨h.somePath t, h.somePath_mem t⟩ continuous_toFun := by fun_prop source' := by simp target' := by simp }⟩ theorem JoinedIn.ofLine {f : ℝ → X} (hf : ContinuousOn f I) (h₀ : f 0 = x) (h₁ : f 1 = y) (hF : f '' I ⊆ F) : JoinedIn F x y := ⟨Path.ofLine hf h₀ h₁, fun t => hF <| Path.ofLine_mem hf h₀ h₁ t⟩ theorem JoinedIn.joined (h : JoinedIn F x y) : Joined x y := ⟨h.somePath⟩ theorem joinedIn_iff_joined (x_in : x ∈ F) (y_in : y ∈ F) : JoinedIn F x y ↔ Joined (⟨x, x_in⟩ : F) (⟨y, y_in⟩ : F) := ⟨fun h => h.joined_subtype, fun h => ⟨h.somePath.map continuous_subtype_val, by simp⟩⟩ @[simp] theorem joinedIn_univ : JoinedIn univ x y ↔ Joined x y := by simp [JoinedIn, Joined, exists_true_iff_nonempty] theorem JoinedIn.mono {U V : Set X} (h : JoinedIn U x y) (hUV : U ⊆ V) : JoinedIn V x y := ⟨h.somePath, fun t => hUV (h.somePath_mem t)⟩ theorem JoinedIn.refl (h : x ∈ F) : JoinedIn F x x := ⟨Path.refl x, fun _t => h⟩ @[symm] theorem JoinedIn.symm (h : JoinedIn F x y) : JoinedIn F y x := by obtain ⟨hx, hy⟩ := h.mem simp_all only [joinedIn_iff_joined] exact h.symm theorem JoinedIn.trans (hxy : JoinedIn F x y) (hyz : JoinedIn F y z) : JoinedIn F x z := by obtain ⟨hx, hy⟩ := hxy.mem obtain ⟨hx, hy⟩ := hyz.mem simp_all only [joinedIn_iff_joined] exact hxy.trans hyz theorem Specializes.joinedIn (h : x ⤳ y) (hx : x ∈ F) (hy : y ∈ F) : JoinedIn F x y := by refine ⟨⟨⟨Set.piecewise {1} (const I y) (const I x), ?_⟩, by simp, by simp⟩, fun t ↦ ?_⟩ · exact isClosed_singleton.continuous_piecewise_of_specializes continuous_const continuous_const fun _ ↦ h · simp only [Path.coe_mk_mk, piecewise] split_ifs <;> assumption theorem Inseparable.joinedIn (h : Inseparable x y) (hx : x ∈ F) (hy : y ∈ F) : JoinedIn F x y := h.specializes.joinedIn hx hy theorem JoinedIn.map_continuousOn (h : JoinedIn F x y) {f : X → Y} (hf : ContinuousOn f F) : JoinedIn (f '' F) (f x) (f y) := let ⟨γ, hγ⟩ := h ⟨γ.map' <| hf.mono (range_subset_iff.mpr hγ), fun t ↦ mem_image_of_mem _ (hγ t)⟩ theorem JoinedIn.map (h : JoinedIn F x y) {f : X → Y} (hf : Continuous f) : JoinedIn (f '' F) (f x) (f y) := h.map_continuousOn hf.continuousOn theorem Topology.IsInducing.joinedIn_image {f : X → Y} (hf : IsInducing f) (hx : x ∈ F) (hy : y ∈ F) : JoinedIn (f '' F) (f x) (f y) ↔ JoinedIn F x y := by refine ⟨?_, (.map · hf.continuous)⟩ rintro ⟨γ, hγ⟩ choose γ' hγ'F hγ' using hγ have h₀ : x ⤳ γ' 0 := by rw [← hf.specializes_iff, hγ', γ.source] have h₁ : γ' 1 ⤳ y := by rw [← hf.specializes_iff, hγ', γ.target] have h : JoinedIn F (γ' 0) (γ' 1) := by refine ⟨⟨⟨γ', ?_⟩, rfl, rfl⟩, hγ'F⟩ simpa only [hf.continuous_iff, comp_def, hγ'] using map_continuous γ exact (h₀.joinedIn hx (hγ'F _)).trans <| h.trans <| h₁.joinedIn (hγ'F _) hy @[deprecated (since := "2024-10-28")] alias Inducing.joinedIn_image := IsInducing.joinedIn_image /-! ### Path component -/ /-- The path component of `x` is the set of points that can be joined to `x`. -/ def pathComponent (x : X) := { y | Joined x y } theorem mem_pathComponent_iff : x ∈ pathComponent y ↔ Joined y x := .rfl @[simp] theorem mem_pathComponent_self (x : X) : x ∈ pathComponent x := Joined.refl x @[simp] theorem pathComponent.nonempty (x : X) : (pathComponent x).Nonempty := ⟨x, mem_pathComponent_self x⟩ theorem mem_pathComponent_of_mem (h : x ∈ pathComponent y) : y ∈ pathComponent x := Joined.symm h theorem pathComponent_symm : x ∈ pathComponent y ↔ y ∈ pathComponent x := ⟨fun h => mem_pathComponent_of_mem h, fun h => mem_pathComponent_of_mem h⟩ theorem pathComponent_congr (h : x ∈ pathComponent y) : pathComponent x = pathComponent y := by ext z constructor · intro h' rw [pathComponent_symm] exact (h.trans h').symm · intro h' rw [pathComponent_symm] at h' ⊢ exact h'.trans h theorem pathComponent_subset_component (x : X) : pathComponent x ⊆ connectedComponent x := fun y h => (isConnected_range h.somePath.continuous).subset_connectedComponent ⟨0, by simp⟩ ⟨1, by simp⟩ /-- The path component of `x` in `F` is the set of points that can be joined to `x` in `F`. -/ def pathComponentIn (x : X) (F : Set X) := { y | JoinedIn F x y } @[simp] theorem pathComponentIn_univ (x : X) : pathComponentIn x univ = pathComponent x := by simp [pathComponentIn, pathComponent, JoinedIn, Joined, exists_true_iff_nonempty] theorem Joined.mem_pathComponent (hyz : Joined y z) (hxy : y ∈ pathComponent x) : z ∈ pathComponent x := hxy.trans hyz theorem mem_pathComponentIn_self (h : x ∈ F) : x ∈ pathComponentIn x F := JoinedIn.refl h theorem pathComponentIn_subset : pathComponentIn x F ⊆ F := fun _ hy ↦ hy.target_mem theorem pathComponentIn_nonempty_iff : (pathComponentIn x F).Nonempty ↔ x ∈ F := ⟨fun ⟨_, ⟨γ, hγ⟩⟩ ↦ γ.source ▸ hγ 0, fun hx ↦ ⟨x, mem_pathComponentIn_self hx⟩⟩ theorem pathComponentIn_congr (h : x ∈ pathComponentIn y F) : pathComponentIn x F = pathComponentIn y F := by ext; exact ⟨h.trans, h.symm.trans⟩ @[gcongr] theorem pathComponentIn_mono {G : Set X} (h : F ⊆ G) : pathComponentIn x F ⊆ pathComponentIn x G := fun _ ⟨γ, hγ⟩ ↦ ⟨γ, fun t ↦ h (hγ t)⟩ /-! ### Path connected sets -/ /-- A set `F` is path connected if it contains a point that can be joined to all other in `F`. -/ def IsPathConnected (F : Set X) : Prop := ∃ x ∈ F, ∀ {y}, y ∈ F → JoinedIn F x y theorem isPathConnected_iff_eq : IsPathConnected F ↔ ∃ x ∈ F, pathComponentIn x F = F := by constructor <;> rintro ⟨x, x_in, h⟩ <;> use x, x_in · ext y exact ⟨fun hy => hy.mem.2, h⟩ · intro y y_in rwa [← h] at y_in theorem IsPathConnected.joinedIn (h : IsPathConnected F) : ∀ᵉ (x ∈ F) (y ∈ F), JoinedIn F x y := fun _x x_in _y y_in => let ⟨_b, _b_in, hb⟩ := h (hb x_in).symm.trans (hb y_in) theorem isPathConnected_iff : IsPathConnected F ↔ F.Nonempty ∧ ∀ᵉ (x ∈ F) (y ∈ F), JoinedIn F x y := ⟨fun h => ⟨let ⟨b, b_in, _hb⟩ := h; ⟨b, b_in⟩, h.joinedIn⟩, fun ⟨⟨b, b_in⟩, h⟩ => ⟨b, b_in, fun x_in => h _ b_in _ x_in⟩⟩ /-- If `f` is continuous on `F` and `F` is path-connected, so is `f(F)`. -/ theorem IsPathConnected.image' (hF : IsPathConnected F) {f : X → Y} (hf : ContinuousOn f F) : IsPathConnected (f '' F) := by rcases hF with ⟨x, x_in, hx⟩ use f x, mem_image_of_mem f x_in rintro _ ⟨y, y_in, rfl⟩ refine ⟨(hx y_in).somePath.map' ?_, fun t ↦ ⟨_, (hx y_in).somePath_mem t, rfl⟩⟩ exact hf.mono (range_subset_iff.2 (hx y_in).somePath_mem) /-- If `f` is continuous and `F` is path-connected, so is `f(F)`. -/ theorem IsPathConnected.image (hF : IsPathConnected F) {f : X → Y} (hf : Continuous f) : IsPathConnected (f '' F) := hF.image' hf.continuousOn /-- If `f : X → Y` is an inducing map, `f(F)` is path-connected iff `F` is. -/ nonrec theorem Topology.IsInducing.isPathConnected_iff {f : X → Y} (hf : IsInducing f) : IsPathConnected F ↔ IsPathConnected (f '' F) := by simp only [IsPathConnected, forall_mem_image, exists_mem_image] refine exists_congr fun x ↦ and_congr_right fun hx ↦ forall₂_congr fun y hy ↦ ?_ rw [hf.joinedIn_image hx hy] @[deprecated (since := "2024-10-28")] alias Inducing.isPathConnected_iff := IsInducing.isPathConnected_iff /-- If `h : X → Y` is a homeomorphism, `h(s)` is path-connected iff `s` is. -/ @[simp] theorem Homeomorph.isPathConnected_image {s : Set X} (h : X ≃ₜ Y) : IsPathConnected (h '' s) ↔ IsPathConnected s := h.isInducing.isPathConnected_iff.symm /-- If `h : X → Y` is a homeomorphism, `h⁻¹(s)` is path-connected iff `s` is. -/ @[simp] theorem Homeomorph.isPathConnected_preimage {s : Set Y} (h : X ≃ₜ Y) : IsPathConnected (h ⁻¹' s) ↔ IsPathConnected s := by rw [← Homeomorph.image_symm]; exact h.symm.isPathConnected_image theorem IsPathConnected.mem_pathComponent (h : IsPathConnected F) (x_in : x ∈ F) (y_in : y ∈ F) : y ∈ pathComponent x := (h.joinedIn x x_in y y_in).joined theorem IsPathConnected.subset_pathComponent (h : IsPathConnected F) (x_in : x ∈ F) : F ⊆ pathComponent x := fun _y y_in => h.mem_pathComponent x_in y_in theorem IsPathConnected.subset_pathComponentIn {s : Set X} (hs : IsPathConnected s) (hxs : x ∈ s) (hsF : s ⊆ F) : s ⊆ pathComponentIn x F := fun y hys ↦ (hs.joinedIn x hxs y hys).mono hsF theorem isPathConnected_singleton (x : X) : IsPathConnected ({x} : Set X) := by refine ⟨x, rfl, ?_⟩ rintro y rfl exact JoinedIn.refl rfl theorem isPathConnected_pathComponentIn (h : x ∈ F) : IsPathConnected (pathComponentIn x F) := ⟨x, mem_pathComponentIn_self h, fun ⟨γ, hγ⟩ ↦ by refine ⟨γ, fun t ↦ ⟨(γ.truncateOfLE t.2.1).cast (γ.extend_zero.symm) (γ.extend_extends' t).symm, fun t' ↦ ?_⟩⟩ dsimp [Path.truncateOfLE, Path.truncate] exact γ.extend_extends' ⟨min (max t'.1 0) t.1, by simp [t.2.1, t.2.2]⟩ ▸ hγ _⟩ theorem isPathConnected_pathComponent : IsPathConnected (pathComponent x) := by rw [← pathComponentIn_univ] exact isPathConnected_pathComponentIn (mem_univ x) theorem IsPathConnected.union {U V : Set X} (hU : IsPathConnected U) (hV : IsPathConnected V) (hUV : (U ∩ V).Nonempty) : IsPathConnected (U ∪ V) := by rcases hUV with ⟨x, xU, xV⟩ use x, Or.inl xU rintro y (yU | yV) · exact (hU.joinedIn x xU y yU).mono subset_union_left · exact (hV.joinedIn x xV y yV).mono subset_union_right /-- If a set `W` is path-connected, then it is also path-connected when seen as a set in a smaller ambient type `U` (when `U` contains `W`). -/ theorem IsPathConnected.preimage_coe {U W : Set X} (hW : IsPathConnected W) (hWU : W ⊆ U) : IsPathConnected (((↑) : U → X) ⁻¹' W) := by rwa [IsInducing.subtypeVal.isPathConnected_iff, Subtype.image_preimage_val, inter_eq_right.2 hWU] theorem IsPathConnected.exists_path_through_family {n : ℕ} {s : Set X} (h : IsPathConnected s) (p : Fin (n + 1) → X) (hp : ∀ i, p i ∈ s) : ∃ γ : Path (p 0) (p n), range γ ⊆ s ∧ ∀ i, p i ∈ range γ := by let p' : ℕ → X := fun k => if h : k < n + 1 then p ⟨k, h⟩ else p ⟨0, n.zero_lt_succ⟩ obtain ⟨γ, hγ⟩ : ∃ γ : Path (p' 0) (p' n), (∀ i ≤ n, p' i ∈ range γ) ∧ range γ ⊆ s := by have hp' : ∀ i ≤ n, p' i ∈ s := by intro i hi simp [p', Nat.lt_succ_of_le hi, hp] clear_value p' clear hp p induction n with | zero => use Path.refl (p' 0) constructor · rintro i hi rw [Nat.le_zero.mp hi] exact ⟨0, rfl⟩ · rw [range_subset_iff] rintro _x exact hp' 0 le_rfl | succ n hn => rcases hn fun i hi => hp' i <| Nat.le_succ_of_le hi with ⟨γ₀, hγ₀⟩ rcases h.joinedIn (p' n) (hp' n n.le_succ) (p' <| n + 1) (hp' (n + 1) <| le_rfl) with ⟨γ₁, hγ₁⟩ let γ : Path (p' 0) (p' <| n + 1) := γ₀.trans γ₁ use γ have range_eq : range γ = range γ₀ ∪ range γ₁ := γ₀.trans_range γ₁ constructor · rintro i hi by_cases hi' : i ≤ n · rw [range_eq] left exact hγ₀.1 i hi' · rw [not_le, ← Nat.succ_le_iff] at hi' have : i = n.succ := le_antisymm hi hi' rw [this] use 1 exact γ.target · rw [range_eq] apply union_subset hγ₀.2 rw [range_subset_iff] exact hγ₁ have hpp' : ∀ k < n + 1, p k = p' k := by intro k hk simp only [p', hk, dif_pos] congr ext rw [Fin.val_cast_of_lt hk] use γ.cast (hpp' 0 n.zero_lt_succ) (hpp' n n.lt_succ_self) simp only [γ.cast_coe] refine And.intro hγ.2 ?_ rintro ⟨i, hi⟩ suffices p ⟨i, hi⟩ = p' i by convert hγ.1 i (Nat.le_of_lt_succ hi) rw [← hpp' i hi] suffices i = i % n.succ by congr rw [Nat.mod_eq_of_lt hi] theorem IsPathConnected.exists_path_through_family' {n : ℕ} {s : Set X} (h : IsPathConnected s) (p : Fin (n + 1) → X) (hp : ∀ i, p i ∈ s) : ∃ (γ : Path (p 0) (p n)) (t : Fin (n + 1) → I), (∀ t, γ t ∈ s) ∧ ∀ i, γ (t i) = p i := by rcases h.exists_path_through_family p hp with ⟨γ, hγ⟩ rcases hγ with ⟨h₁, h₂⟩ simp only [range, mem_setOf_eq] at h₂ rw [range_subset_iff] at h₁ choose! t ht using h₂ exact ⟨γ, t, h₁, ht⟩ /-! ### Path connected spaces -/ /-- A topological space is path-connected if it is non-empty and every two points can be joined by a continuous path. -/ @[mk_iff] class PathConnectedSpace (X : Type*) [TopologicalSpace X] : Prop where /-- A path-connected space must be nonempty. -/ nonempty : Nonempty X /-- Any two points in a path-connected space must be joined by a continuous path. -/ joined : ∀ x y : X, Joined x y theorem pathConnectedSpace_iff_zerothHomotopy : PathConnectedSpace X ↔ Nonempty (ZerothHomotopy X) ∧ Subsingleton (ZerothHomotopy X) := by letI := pathSetoid X constructor · intro h refine ⟨(nonempty_quotient_iff _).mpr h.1, ⟨?_⟩⟩ rintro ⟨x⟩ ⟨y⟩ exact Quotient.sound (PathConnectedSpace.joined x y) · unfold ZerothHomotopy rintro ⟨h, h'⟩ exact ⟨(nonempty_quotient_iff _).mp h, fun x y => Quotient.exact <| Subsingleton.elim ⟦x⟧ ⟦y⟧⟩ namespace PathConnectedSpace variable [PathConnectedSpace X] /-- Use path-connectedness to build a path between two points. -/ def somePath (x y : X) : Path x y := Nonempty.some (joined x y) end PathConnectedSpace theorem pathConnectedSpace_iff_univ : PathConnectedSpace X ↔ IsPathConnected (univ : Set X) := by simp [pathConnectedSpace_iff, isPathConnected_iff, nonempty_iff_univ_nonempty] theorem isPathConnected_iff_pathConnectedSpace : IsPathConnected F ↔ PathConnectedSpace F := by rw [pathConnectedSpace_iff_univ, IsInducing.subtypeVal.isPathConnected_iff, image_univ, Subtype.range_val_subtype, setOf_mem_eq] theorem isPathConnected_univ [PathConnectedSpace X] : IsPathConnected (univ : Set X) := pathConnectedSpace_iff_univ.mp inferInstance theorem isPathConnected_range [PathConnectedSpace X] {f : X → Y} (hf : Continuous f) : IsPathConnected (range f) := by rw [← image_univ] exact isPathConnected_univ.image hf theorem Function.Surjective.pathConnectedSpace [PathConnectedSpace X] {f : X → Y} (hf : Surjective f) (hf' : Continuous f) : PathConnectedSpace Y := by rw [pathConnectedSpace_iff_univ, ← hf.range_eq] exact isPathConnected_range hf' instance Quotient.instPathConnectedSpace {s : Setoid X} [PathConnectedSpace X] : PathConnectedSpace (Quotient s) := Quotient.mk'_surjective.pathConnectedSpace continuous_coinduced_rng /-- This is a special case of `NormedSpace.instPathConnectedSpace` (and `IsTopologicalAddGroup.pathConnectedSpace`). It exists only to simplify dependencies. -/ instance Real.instPathConnectedSpace : PathConnectedSpace ℝ where joined x y := ⟨⟨⟨fun (t : I) ↦ (1 - t) * x + t * y, by fun_prop⟩, by simp, by simp⟩⟩ nonempty := inferInstance theorem pathConnectedSpace_iff_eq : PathConnectedSpace X ↔ ∃ x : X, pathComponent x = univ := by simp [pathConnectedSpace_iff_univ, isPathConnected_iff_eq] -- see Note [lower instance priority] instance (priority := 100) PathConnectedSpace.connectedSpace [PathConnectedSpace X] : ConnectedSpace X := by rw [connectedSpace_iff_connectedComponent] rcases isPathConnected_iff_eq.mp (pathConnectedSpace_iff_univ.mp ‹_›) with ⟨x, _x_in, hx⟩ use x rw [← univ_subset_iff] exact (by simpa using hx : pathComponent x = univ) ▸ pathComponent_subset_component x theorem IsPathConnected.isConnected (hF : IsPathConnected F) : IsConnected F := by rw [isConnected_iff_connectedSpace] rw [isPathConnected_iff_pathConnectedSpace] at hF exact @PathConnectedSpace.connectedSpace _ _ hF namespace PathConnectedSpace variable [PathConnectedSpace X] theorem exists_path_through_family {n : ℕ} (p : Fin (n + 1) → X) : ∃ γ : Path (p 0) (p n), ∀ i, p i ∈ range γ := by have : IsPathConnected (univ : Set X) := pathConnectedSpace_iff_univ.mp (by infer_instance) rcases this.exists_path_through_family p fun _i => True.intro with ⟨γ, -, h⟩ exact ⟨γ, h⟩ theorem exists_path_through_family' {n : ℕ} (p : Fin (n + 1) → X) : ∃ (γ : Path (p 0) (p n)) (t : Fin (n + 1) → I), ∀ i, γ (t i) = p i := by have : IsPathConnected (univ : Set X) := pathConnectedSpace_iff_univ.mp (by infer_instance) rcases this.exists_path_through_family' p fun _i => True.intro with ⟨γ, t, -, h⟩ exact ⟨γ, t, h⟩ end PathConnectedSpace
Mathlib/Topology/Connected/PathConnected.lean
857
858
/- Copyright (c) 2019 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Topology.Constructions /-! # Neighborhoods and continuity relative to a subset This file develops API on the relative versions * `nhdsWithin` of `nhds` * `ContinuousOn` of `Continuous` * `ContinuousWithinAt` of `ContinuousAt` related to continuity, which are defined in previous definition files. Their basic properties studied in this file include the relationships between these restricted notions and the corresponding notions for the subtype equipped with the subspace topology. ## Notation * `𝓝 x`: the filter of neighborhoods of a point `x`; * `𝓟 s`: the principal filter of a set `s`; * `𝓝[s] x`: the filter `nhdsWithin x s` of neighborhoods of a point `x` within a set `s`. -/ open Set Filter Function Topology Filter variable {α β γ δ : Type*} variable [TopologicalSpace α] /-! ## Properties of the neighborhood-within filter -/ @[simp] theorem nhds_bind_nhdsWithin {a : α} {s : Set α} : ((𝓝 a).bind fun x => 𝓝[s] x) = 𝓝[s] a := bind_inf_principal.trans <| congr_arg₂ _ nhds_bind_nhds rfl @[simp] theorem eventually_nhds_nhdsWithin {a : α} {s : Set α} {p : α → Prop} : (∀ᶠ y in 𝓝 a, ∀ᶠ x in 𝓝[s] y, p x) ↔ ∀ᶠ x in 𝓝[s] a, p x := Filter.ext_iff.1 nhds_bind_nhdsWithin { x | p x } theorem eventually_nhdsWithin_iff {a : α} {s : Set α} {p : α → Prop} : (∀ᶠ x in 𝓝[s] a, p x) ↔ ∀ᶠ x in 𝓝 a, x ∈ s → p x := eventually_inf_principal theorem frequently_nhdsWithin_iff {z : α} {s : Set α} {p : α → Prop} : (∃ᶠ x in 𝓝[s] z, p x) ↔ ∃ᶠ x in 𝓝 z, p x ∧ x ∈ s := frequently_inf_principal.trans <| by simp only [and_comm] theorem mem_closure_ne_iff_frequently_within {z : α} {s : Set α} : z ∈ closure (s \ {z}) ↔ ∃ᶠ x in 𝓝[≠] z, x ∈ s := by simp [mem_closure_iff_frequently, frequently_nhdsWithin_iff] @[simp] theorem eventually_eventually_nhdsWithin {a : α} {s : Set α} {p : α → Prop} : (∀ᶠ y in 𝓝[s] a, ∀ᶠ x in 𝓝[s] y, p x) ↔ ∀ᶠ x in 𝓝[s] a, p x := by refine ⟨fun h => ?_, fun h => (eventually_nhds_nhdsWithin.2 h).filter_mono inf_le_left⟩ simp only [eventually_nhdsWithin_iff] at h ⊢ exact h.mono fun x hx hxs => (hx hxs).self_of_nhds hxs @[simp] theorem eventually_mem_nhdsWithin_iff {x : α} {s t : Set α} : (∀ᶠ x' in 𝓝[s] x, t ∈ 𝓝[s] x') ↔ t ∈ 𝓝[s] x := eventually_eventually_nhdsWithin theorem nhdsWithin_eq (a : α) (s : Set α) : 𝓝[s] a = ⨅ t ∈ { t : Set α | a ∈ t ∧ IsOpen t }, 𝓟 (t ∩ s) := ((nhds_basis_opens a).inf_principal s).eq_biInf @[simp] lemma nhdsWithin_univ (a : α) : 𝓝[Set.univ] a = 𝓝 a := by rw [nhdsWithin, principal_univ, inf_top_eq] theorem nhdsWithin_hasBasis {ι : Sort*} {p : ι → Prop} {s : ι → Set α} {a : α} (h : (𝓝 a).HasBasis p s) (t : Set α) : (𝓝[t] a).HasBasis p fun i => s i ∩ t := h.inf_principal t theorem nhdsWithin_basis_open (a : α) (t : Set α) : (𝓝[t] a).HasBasis (fun u => a ∈ u ∧ IsOpen u) fun u => u ∩ t := nhdsWithin_hasBasis (nhds_basis_opens a) t theorem mem_nhdsWithin {t : Set α} {a : α} {s : Set α} : t ∈ 𝓝[s] a ↔ ∃ u, IsOpen u ∧ a ∈ u ∧ u ∩ s ⊆ t := by simpa only [and_assoc, and_left_comm] using (nhdsWithin_basis_open a s).mem_iff theorem mem_nhdsWithin_iff_exists_mem_nhds_inter {t : Set α} {a : α} {s : Set α} : t ∈ 𝓝[s] a ↔ ∃ u ∈ 𝓝 a, u ∩ s ⊆ t := (nhdsWithin_hasBasis (𝓝 a).basis_sets s).mem_iff theorem diff_mem_nhdsWithin_compl {x : α} {s : Set α} (hs : s ∈ 𝓝 x) (t : Set α) : s \ t ∈ 𝓝[tᶜ] x := diff_mem_inf_principal_compl hs t theorem diff_mem_nhdsWithin_diff {x : α} {s t : Set α} (hs : s ∈ 𝓝[t] x) (t' : Set α) : s \ t' ∈ 𝓝[t \ t'] x := by rw [nhdsWithin, diff_eq, diff_eq, ← inf_principal, ← inf_assoc] exact inter_mem_inf hs (mem_principal_self _) theorem nhds_of_nhdsWithin_of_nhds {s t : Set α} {a : α} (h1 : s ∈ 𝓝 a) (h2 : t ∈ 𝓝[s] a) : t ∈ 𝓝 a := by rcases mem_nhdsWithin_iff_exists_mem_nhds_inter.mp h2 with ⟨_, Hw, hw⟩ exact (𝓝 a).sets_of_superset ((𝓝 a).inter_sets Hw h1) hw theorem mem_nhdsWithin_iff_eventually {s t : Set α} {x : α} :
t ∈ 𝓝[s] x ↔ ∀ᶠ y in 𝓝 x, y ∈ s → y ∈ t := eventually_inf_principal theorem mem_nhdsWithin_iff_eventuallyEq {s t : Set α} {x : α} :
Mathlib/Topology/ContinuousOn.lean
110
113
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Analytic.CPolynomial import Mathlib.Analysis.Analytic.Inverse import Mathlib.Analysis.Analytic.Within import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.Analysis.Calculus.ContDiff.FTaylorSeries import Mathlib.Analysis.Calculus.FDeriv.Add import Mathlib.Analysis.Calculus.FDeriv.Prod import Mathlib.Analysis.Normed.Module.Completion /-! # Frechet derivatives of analytic functions. A function expressible as a power series at a point has a Frechet derivative there. Also the special case in terms of `deriv` when the domain is 1-dimensional. As an application, we show that continuous multilinear maps are smooth. We also compute their iterated derivatives, in `ContinuousMultilinearMap.iteratedFDeriv_eq`. ## Main definitions and results * `AnalyticAt.differentiableAt` : an analytic function at a point is differentiable there. * `AnalyticOnNhd.fderiv` : in a complete space, if a function is analytic on a neighborhood of a set `s`, so is its derivative. * `AnalyticOnNhd.fderiv_of_isOpen` : if a function is analytic on a neighborhood of an open set `s`, so is its derivative. * `AnalyticOn.fderivWithin` : if a function is analytic on a set of unique differentiability, so is its derivative within this set. * `PartialHomeomorph.analyticAt_symm` : if a partial homeomorphism `f` is analytic at a point `f.symm a`, with invertible derivative, then its inverse is analytic at `a`. ## Comments on completeness Some theorems need a complete space, some don't, for the following reason.
(1) If a function is analytic at a point `x`, then it is differentiable there (with derivative given by the first term in the power series). There is no issue of convergence here. (2) If a function has a power series on a ball `B (x, r)`, there is no guarantee that the power series for the derivative will converge at `y ≠ x`, if the space is not complete. So, to deduce
Mathlib/Analysis/Calculus/FDeriv/Analytic.lean
39
44
/- 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, Simon Hudon, Mario Carneiro -/ import Aesop import Mathlib.Algebra.Group.Defs import Mathlib.Data.Nat.Init import Mathlib.Data.Int.Init import Mathlib.Logic.Function.Iterate import Mathlib.Tactic.SimpRw import Mathlib.Tactic.SplitIfs /-! # Basic lemmas about semigroups, monoids, and groups This file lists various basic lemmas about semigroups, monoids, and groups. Most proofs are one-liners from the corresponding axioms. For the definitions of semigroups, monoids and groups, see `Algebra/Group/Defs.lean`. -/ assert_not_exists MonoidWithZero DenselyOrdered open Function variable {α β G M : Type*} section ite variable [Pow α β] @[to_additive (attr := simp) dite_smul] lemma pow_dite (p : Prop) [Decidable p] (a : α) (b : p → β) (c : ¬ p → β) : a ^ (if h : p then b h else c h) = if h : p then a ^ b h else a ^ c h := by split_ifs <;> rfl @[to_additive (attr := simp) smul_dite] lemma dite_pow (p : Prop) [Decidable p] (a : p → α) (b : ¬ p → α) (c : β) : (if h : p then a h else b h) ^ c = if h : p then a h ^ c else b h ^ c := by split_ifs <;> rfl @[to_additive (attr := simp) ite_smul] lemma pow_ite (p : Prop) [Decidable p] (a : α) (b c : β) : a ^ (if p then b else c) = if p then a ^ b else a ^ c := pow_dite _ _ _ _ @[to_additive (attr := simp) smul_ite] lemma ite_pow (p : Prop) [Decidable p] (a b : α) (c : β) : (if p then a else b) ^ c = if p then a ^ c else b ^ c := dite_pow _ _ _ _ set_option linter.existingAttributeWarning false in attribute [to_additive (attr := simp)] dite_smul smul_dite ite_smul smul_ite end ite section Semigroup variable [Semigroup α] @[to_additive] instance Semigroup.to_isAssociative : Std.Associative (α := α) (· * ·) := ⟨mul_assoc⟩ /-- Composing two multiplications on the left by `y` then `x` is equal to a multiplication on the left by `x * y`. -/ @[to_additive (attr := simp) "Composing two additions on the left by `y` then `x` is equal to an addition on the left by `x + y`."] theorem comp_mul_left (x y : α) : (x * ·) ∘ (y * ·) = (x * y * ·) := by ext z simp [mul_assoc] /-- Composing two multiplications on the right by `y` and `x` is equal to a multiplication on the right by `y * x`. -/ @[to_additive (attr := simp) "Composing two additions on the right by `y` and `x` is equal to an addition on the right by `y + x`."] theorem comp_mul_right (x y : α) : (· * x) ∘ (· * y) = (· * (y * x)) := by ext z simp [mul_assoc] end Semigroup @[to_additive] instance CommMagma.to_isCommutative [CommMagma G] : Std.Commutative (α := G) (· * ·) := ⟨mul_comm⟩ section MulOneClass variable [MulOneClass M] @[to_additive] theorem ite_mul_one {P : Prop} [Decidable P] {a b : M} : ite P (a * b) 1 = ite P a 1 * ite P b 1 := by by_cases h : P <;> simp [h] @[to_additive] theorem ite_one_mul {P : Prop} [Decidable P] {a b : M} : ite P 1 (a * b) = ite P 1 a * ite P 1 b := by by_cases h : P <;> simp [h] @[to_additive] theorem eq_one_iff_eq_one_of_mul_eq_one {a b : M} (h : a * b = 1) : a = 1 ↔ b = 1 := by constructor <;> (rintro rfl; simpa using h) @[to_additive] theorem one_mul_eq_id : ((1 : M) * ·) = id := funext one_mul @[to_additive] theorem mul_one_eq_id : (· * (1 : M)) = id := funext mul_one end MulOneClass section CommSemigroup variable [CommSemigroup G] @[to_additive] theorem mul_left_comm (a b c : G) : a * (b * c) = b * (a * c) := by rw [← mul_assoc, mul_comm a, mul_assoc] @[to_additive] theorem mul_right_comm (a b c : G) : a * b * c = a * c * b := by rw [mul_assoc, mul_comm b, mul_assoc] @[to_additive] theorem mul_mul_mul_comm (a b c d : G) : a * b * (c * d) = a * c * (b * d) := by simp only [mul_left_comm, mul_assoc] @[to_additive] theorem mul_rotate (a b c : G) : a * b * c = b * c * a := by simp only [mul_left_comm, mul_comm] @[to_additive] theorem mul_rotate' (a b c : G) : a * (b * c) = b * (c * a) := by simp only [mul_left_comm, mul_comm] end CommSemigroup attribute [local simp] mul_assoc sub_eq_add_neg section Monoid variable [Monoid M] {a b : M} {m n : ℕ} @[to_additive boole_nsmul] lemma pow_boole (P : Prop) [Decidable P] (a : M) : (a ^ if P then 1 else 0) = if P then a else 1 := by simp only [pow_ite, pow_one, pow_zero] @[to_additive nsmul_add_sub_nsmul] lemma pow_mul_pow_sub (a : M) (h : m ≤ n) : a ^ m * a ^ (n - m) = a ^ n := by rw [← pow_add, Nat.add_comm, Nat.sub_add_cancel h] @[to_additive sub_nsmul_nsmul_add] lemma pow_sub_mul_pow (a : M) (h : m ≤ n) : a ^ (n - m) * a ^ m = a ^ n := by rw [← pow_add, Nat.sub_add_cancel h] @[to_additive sub_one_nsmul_add] lemma mul_pow_sub_one (hn : n ≠ 0) (a : M) : a * a ^ (n - 1) = a ^ n := by rw [← pow_succ', Nat.sub_add_cancel <| Nat.one_le_iff_ne_zero.2 hn] @[to_additive add_sub_one_nsmul] lemma pow_sub_one_mul (hn : n ≠ 0) (a : M) : a ^ (n - 1) * a = a ^ n := by rw [← pow_succ, Nat.sub_add_cancel <| Nat.one_le_iff_ne_zero.2 hn] /-- If `x ^ n = 1`, then `x ^ m` is the same as `x ^ (m % n)` -/ @[to_additive nsmul_eq_mod_nsmul "If `n • x = 0`, then `m • x` is the same as `(m % n) • x`"] lemma pow_eq_pow_mod (m : ℕ) (ha : a ^ n = 1) : a ^ m = a ^ (m % n) := by calc a ^ m = a ^ (m % n + n * (m / n)) := by rw [Nat.mod_add_div] _ = a ^ (m % n) := by simp [pow_add, pow_mul, ha] @[to_additive] lemma pow_mul_pow_eq_one : ∀ n, a * b = 1 → a ^ n * b ^ n = 1 | 0, _ => by simp | n + 1, h => calc a ^ n.succ * b ^ n.succ = a ^ n * a * (b * b ^ n) := by rw [pow_succ, pow_succ'] _ = a ^ n * (a * b) * b ^ n := by simp only [mul_assoc] _ = 1 := by simp [h, pow_mul_pow_eq_one] @[to_additive (attr := simp)] lemma mul_left_iterate (a : M) : ∀ n : ℕ, (a * ·)^[n] = (a ^ n * ·) | 0 => by ext; simp | n + 1 => by ext; simp [pow_succ, mul_left_iterate] @[to_additive (attr := simp)] lemma mul_right_iterate (a : M) : ∀ n : ℕ, (· * a)^[n] = (· * a ^ n) | 0 => by ext; simp | n + 1 => by ext; simp [pow_succ', mul_right_iterate] @[to_additive] lemma mul_left_iterate_apply_one (a : M) : (a * ·)^[n] 1 = a ^ n := by simp [mul_right_iterate] @[to_additive] lemma mul_right_iterate_apply_one (a : M) : (· * a)^[n] 1 = a ^ n := by simp [mul_right_iterate] @[to_additive (attr := simp)] lemma pow_iterate (k : ℕ) : ∀ n : ℕ, (fun x : M ↦ x ^ k)^[n] = (· ^ k ^ n) | 0 => by ext; simp | n + 1 => by ext; simp [pow_iterate, Nat.pow_succ', pow_mul] end Monoid section CommMonoid variable [CommMonoid M] {x y z : M} @[to_additive] theorem inv_unique (hy : x * y = 1) (hz : x * z = 1) : y = z := left_inv_eq_right_inv (Trans.trans (mul_comm _ _) hy) hz @[to_additive nsmul_add] lemma mul_pow (a b : M) : ∀ n, (a * b) ^ n = a ^ n * b ^ n | 0 => by rw [pow_zero, pow_zero, pow_zero, one_mul] | n + 1 => by rw [pow_succ', pow_succ', pow_succ', mul_pow, mul_mul_mul_comm] end CommMonoid section LeftCancelMonoid variable [Monoid M] [IsLeftCancelMul M] {a b : M} @[to_additive (attr := simp)] theorem mul_eq_left : a * b = a ↔ b = 1 := calc a * b = a ↔ a * b = a * 1 := by rw [mul_one] _ ↔ b = 1 := mul_left_cancel_iff @[deprecated (since := "2025-03-05")] alias mul_right_eq_self := mul_eq_left @[deprecated (since := "2025-03-05")] alias add_right_eq_self := add_eq_left set_option linter.existingAttributeWarning false in attribute [to_additive existing] mul_right_eq_self @[to_additive (attr := simp)] theorem left_eq_mul : a = a * b ↔ b = 1 := eq_comm.trans mul_eq_left @[deprecated (since := "2025-03-05")] alias self_eq_mul_right := left_eq_mul @[deprecated (since := "2025-03-05")] alias self_eq_add_right := left_eq_add set_option linter.existingAttributeWarning false in attribute [to_additive existing] self_eq_mul_right @[to_additive] theorem mul_ne_left : a * b ≠ a ↔ b ≠ 1 := mul_eq_left.not @[deprecated (since := "2025-03-05")] alias mul_right_ne_self := mul_ne_left @[deprecated (since := "2025-03-05")] alias add_right_ne_self := add_ne_left set_option linter.existingAttributeWarning false in attribute [to_additive existing] mul_right_ne_self @[to_additive] theorem left_ne_mul : a ≠ a * b ↔ b ≠ 1 := left_eq_mul.not @[deprecated (since := "2025-03-05")] alias self_ne_mul_right := left_ne_mul @[deprecated (since := "2025-03-05")] alias self_ne_add_right := left_ne_add set_option linter.existingAttributeWarning false in attribute [to_additive existing] self_ne_mul_right end LeftCancelMonoid section RightCancelMonoid variable [RightCancelMonoid M] {a b : M} @[to_additive (attr := simp)] theorem mul_eq_right : a * b = b ↔ a = 1 := calc a * b = b ↔ a * b = 1 * b := by rw [one_mul] _ ↔ a = 1 := mul_right_cancel_iff @[deprecated (since := "2025-03-05")] alias mul_left_eq_self := mul_eq_right @[deprecated (since := "2025-03-05")] alias add_left_eq_self := add_eq_right set_option linter.existingAttributeWarning false in attribute [to_additive existing] mul_left_eq_self @[to_additive (attr := simp)] theorem right_eq_mul : b = a * b ↔ a = 1 := eq_comm.trans mul_eq_right @[deprecated (since := "2025-03-05")] alias self_eq_mul_left := right_eq_mul @[deprecated (since := "2025-03-05")] alias self_eq_add_left := right_eq_add set_option linter.existingAttributeWarning false in attribute [to_additive existing] self_eq_mul_left @[to_additive] theorem mul_ne_right : a * b ≠ b ↔ a ≠ 1 := mul_eq_right.not @[deprecated (since := "2025-03-05")] alias mul_left_ne_self := mul_ne_right @[deprecated (since := "2025-03-05")] alias add_left_ne_self := add_ne_right set_option linter.existingAttributeWarning false in attribute [to_additive existing] mul_left_ne_self @[to_additive] theorem right_ne_mul : b ≠ a * b ↔ a ≠ 1 := right_eq_mul.not @[deprecated (since := "2025-03-05")] alias self_ne_mul_left := right_ne_mul @[deprecated (since := "2025-03-05")] alias self_ne_add_left := right_ne_add set_option linter.existingAttributeWarning false in attribute [to_additive existing] self_ne_mul_left end RightCancelMonoid section CancelCommMonoid variable [CancelCommMonoid α] {a b c d : α} @[to_additive] lemma eq_iff_eq_of_mul_eq_mul (h : a * b = c * d) : a = c ↔ b = d := by aesop @[to_additive] lemma ne_iff_ne_of_mul_eq_mul (h : a * b = c * d) : a ≠ c ↔ b ≠ d := by aesop end CancelCommMonoid section InvolutiveInv variable [InvolutiveInv G] {a b : G} @[to_additive (attr := simp)] theorem inv_involutive : Function.Involutive (Inv.inv : G → G) := inv_inv @[to_additive (attr := simp)] theorem inv_surjective : Function.Surjective (Inv.inv : G → G) := inv_involutive.surjective @[to_additive] theorem inv_injective : Function.Injective (Inv.inv : G → G) := inv_involutive.injective @[to_additive (attr := simp)] theorem inv_inj : a⁻¹ = b⁻¹ ↔ a = b := inv_injective.eq_iff @[to_additive] theorem inv_eq_iff_eq_inv : a⁻¹ = b ↔ a = b⁻¹ := ⟨fun h => h ▸ (inv_inv a).symm, fun h => h.symm ▸ inv_inv b⟩ variable (G) @[to_additive] theorem inv_comp_inv : Inv.inv ∘ Inv.inv = @id G := inv_involutive.comp_self @[to_additive] theorem leftInverse_inv : LeftInverse (fun a : G ↦ a⁻¹) fun a ↦ a⁻¹ := inv_inv @[to_additive] theorem rightInverse_inv : RightInverse (fun a : G ↦ a⁻¹) fun a ↦ a⁻¹ := inv_inv end InvolutiveInv section DivInvMonoid variable [DivInvMonoid G] @[to_additive] theorem mul_one_div (x y : G) : x * (1 / y) = x / y := by rw [div_eq_mul_inv, one_mul, div_eq_mul_inv] @[to_additive, field_simps] -- The attributes are out of order on purpose theorem mul_div_assoc' (a b c : G) : a * (b / c) = a * b / c := (mul_div_assoc _ _ _).symm @[to_additive] theorem mul_div (a b c : G) : a * (b / c) = a * b / c := by simp only [mul_assoc, div_eq_mul_inv] @[to_additive] theorem div_eq_mul_one_div (a b : G) : a / b = a * (1 / b) := by rw [div_eq_mul_inv, one_div] end DivInvMonoid section DivInvOneMonoid variable [DivInvOneMonoid G] @[to_additive (attr := simp)] theorem div_one (a : G) : a / 1 = a := by simp [div_eq_mul_inv] @[to_additive] theorem one_div_one : (1 : G) / 1 = 1 := div_one _ end DivInvOneMonoid section DivisionMonoid variable [DivisionMonoid α] {a b c d : α} attribute [local simp] mul_assoc div_eq_mul_inv @[to_additive] theorem eq_inv_of_mul_eq_one_right (h : a * b = 1) : b = a⁻¹ := (inv_eq_of_mul_eq_one_right h).symm @[to_additive] theorem eq_one_div_of_mul_eq_one_left (h : b * a = 1) : b = 1 / a := by rw [eq_inv_of_mul_eq_one_left h, one_div] @[to_additive] theorem eq_one_div_of_mul_eq_one_right (h : a * b = 1) : b = 1 / a := by rw [eq_inv_of_mul_eq_one_right h, one_div] @[to_additive] theorem eq_of_div_eq_one (h : a / b = 1) : a = b := inv_injective <| inv_eq_of_mul_eq_one_right <| by rwa [← div_eq_mul_inv] @[to_additive] lemma eq_of_inv_mul_eq_one (h : a⁻¹ * b = 1) : a = b := by simpa using eq_inv_of_mul_eq_one_left h @[to_additive] lemma eq_of_mul_inv_eq_one (h : a * b⁻¹ = 1) : a = b := by simpa using eq_inv_of_mul_eq_one_left h @[to_additive] theorem div_ne_one_of_ne : a ≠ b → a / b ≠ 1 := mt eq_of_div_eq_one variable (a b c) @[to_additive] theorem one_div_mul_one_div_rev : 1 / a * (1 / b) = 1 / (b * a) := by simp @[to_additive] theorem inv_div_left : a⁻¹ / b = (b * a)⁻¹ := by simp @[to_additive (attr := simp)] theorem inv_div : (a / b)⁻¹ = b / a := by simp @[to_additive] theorem one_div_div : 1 / (a / b) = b / a := by simp @[to_additive] theorem one_div_one_div : 1 / (1 / a) = a := by simp @[to_additive] theorem div_eq_div_iff_comm : a / b = c / d ↔ b / a = d / c := inv_inj.symm.trans <| by simp only [inv_div] @[to_additive] instance (priority := 100) DivisionMonoid.toDivInvOneMonoid : DivInvOneMonoid α := { DivisionMonoid.toDivInvMonoid with inv_one := by simpa only [one_div, inv_inv] using (inv_div (1 : α) 1).symm } @[to_additive (attr := simp)] lemma inv_pow (a : α) : ∀ n : ℕ, a⁻¹ ^ n = (a ^ n)⁻¹ | 0 => by rw [pow_zero, pow_zero, inv_one] | n + 1 => by rw [pow_succ', pow_succ, inv_pow _ n, mul_inv_rev] -- the attributes are intentionally out of order. `smul_zero` proves `zsmul_zero`. @[to_additive zsmul_zero, simp] lemma one_zpow : ∀ n : ℤ, (1 : α) ^ n = 1 | (n : ℕ) => by rw [zpow_natCast, one_pow] | .negSucc n => by rw [zpow_negSucc, one_pow, inv_one] @[to_additive (attr := simp) neg_zsmul] lemma zpow_neg (a : α) : ∀ n : ℤ, a ^ (-n) = (a ^ n)⁻¹ | (_ + 1 : ℕ) => DivInvMonoid.zpow_neg' _ _ | 0 => by simp | Int.negSucc n => by rw [zpow_negSucc, inv_inv, ← zpow_natCast] rfl @[to_additive neg_one_zsmul_add] lemma mul_zpow_neg_one (a b : α) : (a * b) ^ (-1 : ℤ) = b ^ (-1 : ℤ) * a ^ (-1 : ℤ) := by simp only [zpow_neg, zpow_one, mul_inv_rev] @[to_additive zsmul_neg] lemma inv_zpow (a : α) : ∀ n : ℤ, a⁻¹ ^ n = (a ^ n)⁻¹ | (n : ℕ) => by rw [zpow_natCast, zpow_natCast, inv_pow] | .negSucc n => by rw [zpow_negSucc, zpow_negSucc, inv_pow] @[to_additive (attr := simp) zsmul_neg'] lemma inv_zpow' (a : α) (n : ℤ) : a⁻¹ ^ n = a ^ (-n) := by rw [inv_zpow, zpow_neg] @[to_additive nsmul_zero_sub] lemma one_div_pow (a : α) (n : ℕ) : (1 / a) ^ n = 1 / a ^ n := by simp only [one_div, inv_pow] @[to_additive zsmul_zero_sub] lemma one_div_zpow (a : α) (n : ℤ) : (1 / a) ^ n = 1 / a ^ n := by simp only [one_div, inv_zpow] variable {a b c} @[to_additive (attr := simp)] theorem inv_eq_one : a⁻¹ = 1 ↔ a = 1 := inv_injective.eq_iff' inv_one @[to_additive (attr := simp)] theorem one_eq_inv : 1 = a⁻¹ ↔ a = 1 := eq_comm.trans inv_eq_one @[to_additive] theorem inv_ne_one : a⁻¹ ≠ 1 ↔ a ≠ 1 := inv_eq_one.not @[to_additive] theorem eq_of_one_div_eq_one_div (h : 1 / a = 1 / b) : a = b := by rw [← one_div_one_div a, h, one_div_one_div] -- Note that `mul_zsmul` and `zpow_mul` have the primes swapped -- when additivised since their argument order, -- and therefore the more "natural" choice of lemma, is reversed. @[to_additive mul_zsmul'] lemma zpow_mul (a : α) : ∀ m n : ℤ, a ^ (m * n) = (a ^ m) ^ n | (m : ℕ), (n : ℕ) => by rw [zpow_natCast, zpow_natCast, ← pow_mul, ← zpow_natCast] rfl | (m : ℕ), .negSucc n => by rw [zpow_natCast, zpow_negSucc, ← pow_mul, Int.ofNat_mul_negSucc, zpow_neg, inv_inj, ← zpow_natCast] | .negSucc m, (n : ℕ) => by rw [zpow_natCast, zpow_negSucc, ← inv_pow, ← pow_mul, Int.negSucc_mul_ofNat, zpow_neg, inv_pow, inv_inj, ← zpow_natCast] | .negSucc m, .negSucc n => by rw [zpow_negSucc, zpow_negSucc, Int.negSucc_mul_negSucc, inv_pow, inv_inv, ← pow_mul, ← zpow_natCast] rfl @[to_additive mul_zsmul] lemma zpow_mul' (a : α) (m n : ℤ) : a ^ (m * n) = (a ^ n) ^ m := by rw [Int.mul_comm, zpow_mul] @[to_additive] theorem zpow_comm (a : α) (m n : ℤ) : (a ^ m) ^ n = (a ^ n) ^ m := by rw [← zpow_mul, zpow_mul'] variable (a b c) @[to_additive, field_simps] -- The attributes are out of order on purpose theorem div_div_eq_mul_div : a / (b / c) = a * c / b := by simp @[to_additive (attr := simp)] theorem div_inv_eq_mul : a / b⁻¹ = a * b := by simp @[to_additive] theorem div_mul_eq_div_div_swap : a / (b * c) = a / c / b := by simp only [mul_assoc, mul_inv_rev, div_eq_mul_inv] end DivisionMonoid section DivisionCommMonoid variable [DivisionCommMonoid α] (a b c d : α) attribute [local simp] mul_assoc mul_comm mul_left_comm div_eq_mul_inv @[to_additive neg_add] theorem mul_inv : (a * b)⁻¹ = a⁻¹ * b⁻¹ := by simp @[to_additive] theorem inv_div' : (a / b)⁻¹ = a⁻¹ / b⁻¹ := by simp @[to_additive] theorem div_eq_inv_mul : a / b = b⁻¹ * a := by simp @[to_additive] theorem inv_mul_eq_div : a⁻¹ * b = b / a := by simp @[to_additive] lemma inv_div_comm (a b : α) : a⁻¹ / b = b⁻¹ / a := by simp @[to_additive] theorem inv_mul' : (a * b)⁻¹ = a⁻¹ / b := by simp @[to_additive] theorem inv_div_inv : a⁻¹ / b⁻¹ = b / a := by simp @[to_additive] theorem inv_inv_div_inv : (a⁻¹ / b⁻¹)⁻¹ = a / b := by simp @[to_additive] theorem one_div_mul_one_div : 1 / a * (1 / b) = 1 / (a * b) := by simp @[to_additive] theorem div_right_comm : a / b / c = a / c / b := by simp @[to_additive, field_simps] theorem div_div : a / b / c = a / (b * c) := by simp @[to_additive] theorem div_mul : a / b * c = a / (b / c) := by simp @[to_additive] theorem mul_div_left_comm : a * (b / c) = b * (a / c) := by simp @[to_additive] theorem mul_div_right_comm : a * b / c = a / c * b := by simp @[to_additive] theorem div_mul_eq_div_div : a / (b * c) = a / b / c := by simp @[to_additive, field_simps] theorem div_mul_eq_mul_div : a / b * c = a * c / b := by simp @[to_additive] theorem one_div_mul_eq_div : 1 / a * b = b / a := by simp @[to_additive] theorem mul_comm_div : a / b * c = a * (c / b) := by simp @[to_additive] theorem div_mul_comm : a / b * c = c / b * a := by simp @[to_additive] theorem div_mul_eq_div_mul_one_div : a / (b * c) = a / b * (1 / c) := by simp @[to_additive] theorem div_div_div_eq : a / b / (c / d) = a * d / (b * c) := by simp @[to_additive] theorem div_div_div_comm : a / b / (c / d) = a / c / (b / d) := by simp @[to_additive] theorem div_mul_div_comm : a / b * (c / d) = a * c / (b * d) := by simp @[to_additive] theorem mul_div_mul_comm : a * b / (c * d) = a / c * (b / d) := by simp @[to_additive zsmul_add] lemma mul_zpow : ∀ n : ℤ, (a * b) ^ n = a ^ n * b ^ n | (n : ℕ) => by simp_rw [zpow_natCast, mul_pow] | .negSucc n => by simp_rw [zpow_negSucc, ← inv_pow, mul_inv, mul_pow] @[to_additive nsmul_sub] lemma div_pow (a b : α) (n : ℕ) : (a / b) ^ n = a ^ n / b ^ n := by simp only [div_eq_mul_inv, mul_pow, inv_pow] @[to_additive zsmul_sub] lemma div_zpow (a b : α) (n : ℤ) : (a / b) ^ n = a ^ n / b ^ n := by simp only [div_eq_mul_inv, mul_zpow, inv_zpow] attribute [field_simps] div_pow div_zpow end DivisionCommMonoid section Group variable [Group G] {a b c d : G} {n : ℤ} @[to_additive (attr := simp)] theorem div_eq_inv_self : a / b = b⁻¹ ↔ a = 1 := by rw [div_eq_mul_inv, mul_eq_right] @[to_additive] theorem mul_left_surjective (a : G) : Surjective (a * ·) := fun x ↦ ⟨a⁻¹ * x, mul_inv_cancel_left a x⟩ @[to_additive] theorem mul_right_surjective (a : G) : Function.Surjective fun x ↦ x * a := fun x ↦ ⟨x * a⁻¹, inv_mul_cancel_right x a⟩ @[to_additive] theorem eq_mul_inv_of_mul_eq (h : a * c = b) : a = b * c⁻¹ := by simp [h.symm] @[to_additive] theorem eq_inv_mul_of_mul_eq (h : b * a = c) : a = b⁻¹ * c := by simp [h.symm] @[to_additive] theorem inv_mul_eq_of_eq_mul (h : b = a * c) : a⁻¹ * b = c := by simp [h] @[to_additive] theorem mul_inv_eq_of_eq_mul (h : a = c * b) : a * b⁻¹ = c := by simp [h] @[to_additive] theorem eq_mul_of_mul_inv_eq (h : a * c⁻¹ = b) : a = b * c := by simp [h.symm] @[to_additive] theorem eq_mul_of_inv_mul_eq (h : b⁻¹ * a = c) : a = b * c := by simp [h.symm, mul_inv_cancel_left] @[to_additive] theorem mul_eq_of_eq_inv_mul (h : b = a⁻¹ * c) : a * b = c := by rw [h, mul_inv_cancel_left] @[to_additive] theorem mul_eq_of_eq_mul_inv (h : a = c * b⁻¹) : a * b = c := by simp [h] @[to_additive] theorem mul_eq_one_iff_eq_inv : a * b = 1 ↔ a = b⁻¹ := ⟨eq_inv_of_mul_eq_one_left, fun h ↦ by rw [h, inv_mul_cancel]⟩ @[to_additive] theorem mul_eq_one_iff_inv_eq : a * b = 1 ↔ a⁻¹ = b := by rw [mul_eq_one_iff_eq_inv, inv_eq_iff_eq_inv] /-- Variant of `mul_eq_one_iff_eq_inv` with swapped equality. -/ @[to_additive] theorem mul_eq_one_iff_eq_inv' : a * b = 1 ↔ b = a⁻¹ := by rw [mul_eq_one_iff_inv_eq, eq_comm] /-- Variant of `mul_eq_one_iff_inv_eq` with swapped equality. -/ @[to_additive] theorem mul_eq_one_iff_inv_eq' : a * b = 1 ↔ b⁻¹ = a := by rw [mul_eq_one_iff_eq_inv, eq_comm] @[to_additive] theorem eq_inv_iff_mul_eq_one : a = b⁻¹ ↔ a * b = 1 := mul_eq_one_iff_eq_inv.symm @[to_additive] theorem inv_eq_iff_mul_eq_one : a⁻¹ = b ↔ a * b = 1 := mul_eq_one_iff_inv_eq.symm @[to_additive] theorem eq_mul_inv_iff_mul_eq : a = b * c⁻¹ ↔ a * c = b := ⟨fun h ↦ by rw [h, inv_mul_cancel_right], fun h ↦ by rw [← h, mul_inv_cancel_right]⟩ @[to_additive] theorem eq_inv_mul_iff_mul_eq : a = b⁻¹ * c ↔ b * a = c := ⟨fun h ↦ by rw [h, mul_inv_cancel_left], fun h ↦ by rw [← h, inv_mul_cancel_left]⟩ @[to_additive] theorem inv_mul_eq_iff_eq_mul : a⁻¹ * b = c ↔ b = a * c := ⟨fun h ↦ by rw [← h, mul_inv_cancel_left], fun h ↦ by rw [h, inv_mul_cancel_left]⟩ @[to_additive] theorem mul_inv_eq_iff_eq_mul : a * b⁻¹ = c ↔ a = c * b := ⟨fun h ↦ by rw [← h, inv_mul_cancel_right], fun h ↦ by rw [h, mul_inv_cancel_right]⟩ @[to_additive] theorem mul_inv_eq_one : a * b⁻¹ = 1 ↔ a = b := by rw [mul_eq_one_iff_eq_inv, inv_inv] @[to_additive] theorem inv_mul_eq_one : a⁻¹ * b = 1 ↔ a = b := by rw [mul_eq_one_iff_eq_inv, inv_inj] @[to_additive (attr := simp)] theorem conj_eq_one_iff : a * b * a⁻¹ = 1 ↔ b = 1 := by rw [mul_inv_eq_one, mul_eq_left] @[to_additive] theorem div_left_injective : Function.Injective fun a ↦ a / b := by -- FIXME this could be by `simpa`, but it fails. This is probably a bug in `simpa`. simp only [div_eq_mul_inv] exact fun a a' h ↦ mul_left_injective b⁻¹ h @[to_additive] theorem div_right_injective : Function.Injective fun a ↦ b / a := by -- FIXME see above simp only [div_eq_mul_inv] exact fun a a' h ↦ inv_injective (mul_right_injective b h) @[to_additive (attr := simp)] lemma div_mul_cancel_right (a b : G) : a / (b * a) = b⁻¹ := by rw [← inv_div, mul_div_cancel_right] @[to_additive (attr := simp)] theorem mul_div_mul_right_eq_div (a b c : G) : a * c / (b * c) = a / b := by rw [div_mul_eq_div_div_swap]; simp only [mul_left_inj, eq_self_iff_true, mul_div_cancel_right] @[to_additive eq_sub_of_add_eq] theorem eq_div_of_mul_eq' (h : a * c = b) : a = b / c := by simp [← h] @[to_additive sub_eq_of_eq_add] theorem div_eq_of_eq_mul'' (h : a = c * b) : a / b = c := by simp [h] @[to_additive] theorem eq_mul_of_div_eq (h : a / c = b) : a = b * c := by simp [← h] @[to_additive] theorem mul_eq_of_eq_div (h : a = c / b) : a * b = c := by simp [h] @[to_additive (attr := simp)] theorem div_right_inj : a / b = a / c ↔ b = c := div_right_injective.eq_iff @[to_additive (attr := simp)] theorem div_left_inj : b / a = c / a ↔ b = c := by rw [div_eq_mul_inv, div_eq_mul_inv] exact mul_left_inj _ @[to_additive (attr := simp)] theorem div_mul_div_cancel (a b c : G) : a / b * (b / c) = a / c := by rw [← mul_div_assoc, div_mul_cancel] @[to_additive (attr := simp)] theorem div_div_div_cancel_right (a b c : G) : a / c / (b / c) = a / b := by rw [← inv_div c b, div_inv_eq_mul, div_mul_div_cancel] @[to_additive]
theorem div_eq_one : a / b = 1 ↔ a = b :=
Mathlib/Algebra/Group/Basic.lean
766
766
/- Copyright (c) 2019 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Eric Wieser -/ import Mathlib.Data.Matrix.ConjTranspose /-! # Row and column matrices This file provides results about row and column matrices. ## Main definitions * `Matrix.replicateRow ι r : Matrix ι n α`: the matrix where every row is the vector `r : n → α` * `Matrix.replicateCol ι c : Matrix m ι α`: the matrix where every column is the vector `c : m → α` * `Matrix.updateRow M i r`: update the `i`th row of `M` to `r` * `Matrix.updateCol M j c`: update the `j`th column of `M` to `c` -/ variable {l m n o : Type*} universe u v w variable {R : Type*} {α : Type v} {β : Type w} namespace Matrix /-- `Matrix.replicateCol ι u` is the matrix with all columns equal to the vector `u`. To get a column matrix with exactly one column, `Matrix.replicateCol (Fin 1) u` is the canonical choice. -/ def replicateCol (ι : Type*) (w : m → α) : Matrix m ι α := of fun x _ => w x -- TODO: set as an equation lemma for `replicateCol`, see https://github.com/leanprover-community/mathlib4/pull/3024 @[simp] theorem replicateCol_apply {ι : Type*} (w : m → α) (i) (j : ι) : replicateCol ι w i j = w i := rfl /-- `Matrix.replicateRow ι u` is the matrix with all rows equal to the vector `u`. To get a row matrix with exactly one row, `Matrix.replicateRow (Fin 1) u` is the canonical choice. -/ def replicateRow (ι : Type*) (v : n → α) : Matrix ι n α := of fun _ y => v y variable {ι : Type*} -- TODO: set as an equation lemma for `replicateRow`, see https://github.com/leanprover-community/mathlib4/pull/3024 @[simp] theorem replicateRow_apply (v : n → α) (i : ι) (j) : replicateRow ι v i j = v j := rfl theorem replicateCol_injective [Nonempty ι] : Function.Injective (replicateCol ι : (m → α) → Matrix m ι α) := by inhabit ι exact fun _x _y h => funext fun i => congr_fun₂ h i default @[deprecated (since := "2025-03-20")] alias col_injective := replicateCol_injective @[simp] theorem replicateCol_inj [Nonempty ι] {v w : m → α} : replicateCol ι v = replicateCol ι w ↔ v = w := replicateCol_injective.eq_iff @[deprecated (since := "2025-03-20")] alias col_inj := replicateCol_inj @[simp] theorem replicateCol_zero [Zero α] : replicateCol ι (0 : m → α) = 0 := rfl @[deprecated (since := "2025-03-20")] alias col_zero := replicateCol_zero @[simp] theorem replicateCol_eq_zero [Zero α] [Nonempty ι] (v : m → α) : replicateCol ι v = 0 ↔ v = 0 := replicateCol_inj @[deprecated (since := "2025-03-20")] alias col_eq_zero := replicateCol_eq_zero @[simp] theorem replicateCol_add [Add α] (v w : m → α) : replicateCol ι (v + w) = replicateCol ι v + replicateCol ι w := by ext rfl @[deprecated (since := "2025-03-20")] alias col_add := replicateCol_add @[simp] theorem replicateCol_smul [SMul R α] (x : R) (v : m → α) : replicateCol ι (x • v) = x • replicateCol ι v := by ext rfl @[deprecated (since := "2025-03-20")] alias col_smul := replicateCol_smul theorem replicateRow_injective [Nonempty ι] : Function.Injective (replicateRow ι : (n → α) → Matrix ι n α) := by inhabit ι exact fun _x _y h => funext fun j => congr_fun₂ h default j @[deprecated (since := "2025-03-20")] alias row_injective := replicateRow_injective @[simp] theorem replicateRow_inj [Nonempty ι] {v w : n → α} : replicateRow ι v = replicateRow ι w ↔ v = w := replicateRow_injective.eq_iff @[simp] theorem replicateRow_zero [Zero α] : replicateRow ι (0 : n → α) = 0 := rfl @[deprecated (since := "2025-03-20")] alias row_zero := replicateRow_zero @[simp] theorem replicateRow_eq_zero [Zero α] [Nonempty ι] (v : n → α) : replicateRow ι v = 0 ↔ v = 0 := replicateRow_inj @[deprecated (since := "2025-03-20")] alias row_eq_zero := replicateRow_eq_zero @[simp] theorem replicateRow_add [Add α] (v w : m → α) : replicateRow ι (v + w) = replicateRow ι v + replicateRow ι w := by ext rfl @[deprecated (since := "2025-03-20")] alias row_add := replicateRow_add @[simp] theorem replicateRow_smul [SMul R α] (x : R) (v : m → α) : replicateRow ι (x • v) = x • replicateRow ι v := by ext rfl @[deprecated (since := "2025-03-20")] alias row_smul := replicateRow_smul @[simp] theorem transpose_replicateCol (v : m → α) : (replicateCol ι v)ᵀ = replicateRow ι v := by ext rfl @[simp] theorem transpose_replicateRow (v : m → α) : (replicateRow ι v)ᵀ = replicateCol ι v := by ext rfl @[simp] theorem conjTranspose_replicateCol [Star α] (v : m → α) : (replicateCol ι v)ᴴ = replicateRow ι (star v) := by ext rfl @[deprecated (since := "2025-03-20")] alias conjTranspose_col := conjTranspose_replicateCol @[simp] theorem conjTranspose_replicateRow [Star α] (v : m → α) : (replicateRow ι v)ᴴ = replicateCol ι (star v) := by ext rfl @[deprecated (since := "2025-03-20")] alias conjTranspose_row := conjTranspose_replicateRow theorem replicateRow_vecMul [Fintype m] [NonUnitalNonAssocSemiring α] (M : Matrix m n α) (v : m → α) : replicateRow ι (v ᵥ* M) = replicateRow ι v * M := by ext rfl @[deprecated (since := "2025-03-20")] alias row_vecMul := replicateRow_vecMul theorem replicateCol_vecMul [Fintype m] [NonUnitalNonAssocSemiring α] (M : Matrix m n α) (v : m → α) : replicateCol ι (v ᵥ* M) = (replicateRow ι v * M)ᵀ := by ext rfl @[deprecated (since := "2025-03-20")] alias col_vecMul := replicateCol_vecMul theorem replicateCol_mulVec [Fintype n] [NonUnitalNonAssocSemiring α] (M : Matrix m n α) (v : n → α) : replicateCol ι (M *ᵥ v) = M * replicateCol ι v := by ext rfl @[deprecated (since := "2025-03-20")] alias col_mulVec := replicateCol_mulVec theorem replicateRow_mulVec [Fintype n] [NonUnitalNonAssocSemiring α] (M : Matrix m n α) (v : n → α) : replicateRow ι (M *ᵥ v) = (M * replicateCol ι v)ᵀ := by ext rfl @[deprecated (since := "2025-03-20")] alias row_mulVec := replicateRow_mulVec theorem replicateRow_mulVec_eq_const [Fintype m] [NonUnitalNonAssocSemiring α] (v w : m → α) : replicateRow ι v *ᵥ w = Function.const _ (v ⬝ᵥ w) := rfl @[deprecated (since := "2025-03-20")] alias row_mulVec_eq_const := replicateRow_mulVec_eq_const theorem mulVec_replicateCol_eq_const [Fintype m] [NonUnitalNonAssocSemiring α] (v w : m → α) : v ᵥ* replicateCol ι w = Function.const _ (v ⬝ᵥ w) := rfl @[deprecated (since := "2025-03-20")] alias mulVec_col_eq_const := mulVec_replicateCol_eq_const theorem replicateRow_mul_replicateCol [Fintype m] [Mul α] [AddCommMonoid α] (v w : m → α) : replicateRow ι v * replicateCol ι w = of fun _ _ => v ⬝ᵥ w := rfl @[deprecated (since := "2025-03-20")] alias row_mul_col := replicateRow_mul_replicateCol @[simp] theorem replicateRow_mul_replicateCol_apply [Fintype m] [Mul α] [AddCommMonoid α] (v w : m → α) (i j) : (replicateRow ι v * replicateCol ι w) i j = v ⬝ᵥ w := rfl @[deprecated (since := "2025-03-20")] alias row_mul_col_apply := replicateRow_mul_replicateCol_apply @[simp] theorem diag_replicateCol_mul_replicateRow [Mul α] [AddCommMonoid α] [Unique ι] (a b : n → α) : diag (replicateCol ι a * replicateRow ι b) = a * b := by ext simp [Matrix.mul_apply, replicateCol, replicateRow] @[deprecated (since := "2025-03-20")] alias diag_col_mul_row := diag_replicateCol_mul_replicateRow variable (ι)
theorem vecMulVec_eq [Mul α] [AddCommMonoid α] [Unique ι] (w : m → α) (v : n → α) : vecMulVec w v = replicateCol ι w * replicateRow ι v := by ext simp [vecMulVec, mul_apply]
Mathlib/Data/Matrix/RowCol.lean
220
224
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl -/ import Mathlib.MeasureTheory.Integral.Lebesgue.Basic import Mathlib.MeasureTheory.Integral.Lebesgue.Countable import Mathlib.MeasureTheory.Integral.Lebesgue.MeasurePreserving import Mathlib.MeasureTheory.Integral.Lebesgue.Norm deprecated_module (since := "2025-04-13")
Mathlib/MeasureTheory/Integral/Lebesgue.lean
1,919
1,936
/- 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.BigOperators.Group.Finset.Piecewise import Mathlib.Algebra.BigOperators.Group.Finset.Sigma import Mathlib.Algebra.BigOperators.Option import Mathlib.Data.Fintype.Option import Mathlib.Data.Fintype.Prod import Mathlib.Data.Fintype.Sigma import Mathlib.Data.Fintype.Sum import Mathlib.Data.Fintype.Vector /-! Results about "big operations" over a `Fintype`, and consequent results about cardinalities of certain types. ## Implementation note This content had previously been in `Data.Fintype.Basic`, but was moved here to avoid requiring `Algebra.BigOperators` (and hence many other imports) as a dependency of `Fintype`. However many of the results here really belong in `Algebra.BigOperators.Group.Finset` and should be moved at some point. -/ assert_not_exists MulAction open Mathlib universe u v variable {α : Type*} {β : Type*} {γ : Type*} namespace Fintype @[to_additive] theorem prod_bool [CommMonoid α] (f : Bool → α) : ∏ b, f b = f true * f false := by simp theorem card_eq_sum_ones {α} [Fintype α] : Fintype.card α = ∑ _a : α, 1 := Finset.card_eq_sum_ones _ section open Finset variable {ι : Type*} [DecidableEq ι] [Fintype ι] @[to_additive] theorem prod_extend_by_one [CommMonoid α] (s : Finset ι) (f : ι → α) : ∏ i, (if i ∈ s then f i else 1) = ∏ i ∈ s, f i := by rw [← prod_filter, filter_mem_eq_inter, univ_inter] end section variable {M : Type*} [Fintype α] [CommMonoid M] @[to_additive] theorem prod_eq_one (f : α → M) (h : ∀ a, f a = 1) : ∏ a, f a = 1 := Finset.prod_eq_one fun a _ha => h a @[to_additive] theorem prod_congr (f g : α → M) (h : ∀ a, f a = g a) : ∏ a, f a = ∏ a, g a := Finset.prod_congr rfl fun a _ha => h a @[to_additive] theorem prod_eq_single {f : α → M} (a : α) (h : ∀ x ≠ a, f x = 1) : ∏ x, f x = f a := Finset.prod_eq_single a (fun x _ hx => h x hx) fun ha => (ha (Finset.mem_univ a)).elim @[to_additive] theorem prod_eq_mul {f : α → M} (a b : α) (h₁ : a ≠ b) (h₂ : ∀ x, x ≠ a ∧ x ≠ b → f x = 1) : ∏ x, f x = f a * f b := by apply Finset.prod_eq_mul a b h₁ fun x _ hx => h₂ x hx <;> exact fun hc => (hc (Finset.mem_univ _)).elim /-- If a product of a `Finset` of a subsingleton type has a given value, so do the terms in that product. -/ @[to_additive "If a sum of a `Finset` of a subsingleton type has a given value, so do the terms in that sum."] theorem eq_of_subsingleton_of_prod_eq {ι : Type*} [Subsingleton ι] {s : Finset ι} {f : ι → M} {b : M} (h : ∏ i ∈ s, f i = b) : ∀ i ∈ s, f i = b := Finset.eq_of_card_le_one_of_prod_eq (Finset.card_le_one_of_subsingleton s) h end end Fintype open Finset section variable {M : Type*} [Fintype α] [CommMonoid M] @[to_additive (attr := simp)] theorem Fintype.prod_option (f : Option α → M) : ∏ i, f i = f none * ∏ i, f (some i) := Finset.prod_insertNone f univ @[to_additive] theorem Fintype.prod_eq_mul_prod_subtype_ne [DecidableEq α] (f : α → M) (a : α) : ∏ i, f i = f a * ∏ i : {i // i ≠ a}, f i.1 := by simp_rw [← (Equiv.optionSubtypeNe a).prod_comp, prod_option, Equiv.optionSubtypeNe_none, Equiv.optionSubtypeNe_some] end open Finset section Pi variable {ι κ : Type*} {α : ι → Type*} [DecidableEq ι] [DecidableEq κ] @[simp] lemma Finset.card_pi (s : Finset ι) (t : ∀ i, Finset (α i)) : #(s.pi t) = ∏ i ∈ s, #(t i) := Multiset.card_pi _ _ namespace Fintype variable [Fintype ι] @[simp] lemma card_piFinset (s : ∀ i, Finset (α i)) : #(piFinset s) = ∏ i, #(s i) := by simp [piFinset, card_map] /-- This lemma is specifically designed to be used backwards, whence the specialisation to `Fin n` as the indexing type doesn't matter in practice. The more general forward direction lemma here is `Fintype.card_piFinset`. -/ lemma card_piFinset_const {α : Type*} (s : Finset α) (n : ℕ) : #(piFinset fun _ : Fin n ↦ s) = #s ^ n := by simp @[simp] lemma card_pi [∀ i, Fintype (α i)] : card (∀ i, α i) = ∏ i, card (α i) := card_piFinset _ /-- This lemma is specifically designed to be used backwards, whence the specialisation to `Fin n` as the indexing type doesn't matter in practice. The more general forward direction lemma here is `Fintype.card_pi`. -/ lemma card_pi_const (α : Type*) [Fintype α] (n : ℕ) : card (Fin n → α) = card α ^ n := card_piFinset_const _ _ /-- Product over a sigma type equals the repeated product. This is a version of `Finset.prod_sigma` specialized to the case of multiplication over `Finset.univ`. -/ @[to_additive "Sum over a sigma type equals the repeated sum. This is a version of `Finset.sum_sigma` specialized to the case of summation over `Finset.univ`."] theorem prod_sigma {ι} {α : ι → Type*} {M : Type*} [Fintype ι] [∀ i, Fintype (α i)] [CommMonoid M] (f : Sigma α → M) : ∏ x, f x = ∏ x, ∏ y, f ⟨x, y⟩ := Finset.prod_sigma .. /-- Product over a sigma type equals the repeated product, curried version. This version is useful to rewrite from right to left. -/ @[to_additive "Sum over a sigma type equals the repeated sum, curried version. This version is useful to rewrite from right to left."] theorem prod_sigma' {ι} {α : ι → Type*} {M : Type*} [Fintype ι] [∀ i, Fintype (α i)] [CommMonoid M] (f : (i : ι) → α i → M) : ∏ x : Sigma α, f x.1 x.2 = ∏ x, ∏ y, f x y := prod_sigma .. @[simp] nonrec lemma card_sigma {ι} {α : ι → Type*} [Fintype ι] [∀ i, Fintype (α i)] : card (Sigma α) = ∑ i, card (α i) := card_sigma _ _ /-- The number of dependent maps `f : Π j, s j` for which the `i` component is `a` is the product over all `j ≠ i` of `#(s j)`. Note that this is just a composition of easier lemmas, but there's some glue missing to make that smooth enough not to need this lemma. -/ lemma card_filter_piFinset_eq_of_mem [∀ i, DecidableEq (α i)] (s : ∀ i, Finset (α i)) (i : ι) {a : α i} (ha : a ∈ s i) : #{f ∈ piFinset s | f i = a} = ∏ j ∈ univ.erase i, #(s j) := by calc _ = ∏ j, #(Function.update s i {a} j) := by rw [← piFinset_update_singleton_eq_filter_piFinset_eq _ _ ha, Fintype.card_piFinset] _ = ∏ j, Function.update (fun j ↦ #(s j)) i 1 j := Fintype.prod_congr _ _ fun j ↦ by obtain rfl | hji := eq_or_ne j i <;> simp [*] _ = _ := by simp [prod_update_of_mem, erase_eq] lemma card_filter_piFinset_const_eq_of_mem (s : Finset κ) (i : ι) {x : κ} (hx : x ∈ s) : #{f ∈ piFinset fun _ ↦ s | f i = x} = #s ^ (card ι - 1) := (card_filter_piFinset_eq_of_mem _ _ hx).trans <| by
rw [prod_const #s, card_erase_of_mem (mem_univ _), card_univ] lemma card_filter_piFinset_eq [∀ i, DecidableEq (α i)] (s : ∀ i, Finset (α i)) (i : ι) (a : α i) :
Mathlib/Data/Fintype/BigOperators.lean
179
181
/- Copyright (c) 2018 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Johannes Hölzl, Rémy Degenne -/ import Mathlib.Order.ConditionallyCompleteLattice.Indexed import Mathlib.Order.Filter.IsBounded import Mathlib.Order.Hom.CompleteLattice /-! # liminfs and limsups of functions and filters Defines the liminf/limsup of a function taking values in a conditionally complete lattice, with respect to an arbitrary filter. We define `limsSup f` (`limsInf f`) where `f` is a filter taking values in a conditionally complete lattice. `limsSup f` is the smallest element `a` such that, eventually, `u ≤ a` (and vice versa for `limsInf f`). To work with the Limsup along a function `u` use `limsSup (map u f)`. Usually, one defines the Limsup as `inf (sup s)` where the Inf is taken over all sets in the filter. For instance, in ℕ along a function `u`, this is `inf_n (sup_{k ≥ n} u k)` (and the latter quantity decreases with `n`, so this is in fact a limit.). There is however a difficulty: it is well possible that `u` is not bounded on the whole space, only eventually (think of `limsup (fun x ↦ 1/x)` on ℝ. Then there is no guarantee that the quantity above really decreases (the value of the `sup` beforehand is not really well defined, as one can not use ∞), so that the Inf could be anything. So one can not use this `inf sup ...` definition in conditionally complete lattices, and one has to use a less tractable definition. In conditionally complete lattices, the definition is only useful for filters which are eventually bounded above (otherwise, the Limsup would morally be +∞, which does not belong to the space) and which are frequently bounded below (otherwise, the Limsup would morally be -∞, which is not in the space either). We start with definitions of these concepts for arbitrary filters, before turning to the definitions of Limsup and Liminf. In complete lattices, however, it coincides with the `Inf Sup` definition. -/ open Filter Set Function variable {α β γ ι ι' : Type*} namespace Filter section ConditionallyCompleteLattice variable [ConditionallyCompleteLattice α] {s : Set α} {u : β → α} /-- The `limsSup` of a filter `f` is the infimum of the `a` such that, eventually for `f`, holds `x ≤ a`. -/ def limsSup (f : Filter α) : α := sInf { a | ∀ᶠ n in f, n ≤ a } /-- The `limsInf` of a filter `f` is the supremum of the `a` such that, eventually for `f`, holds `x ≥ a`. -/ def limsInf (f : Filter α) : α := sSup { a | ∀ᶠ n in f, a ≤ n } /-- The `limsup` of a function `u` along a filter `f` is the infimum of the `a` such that, eventually for `f`, holds `u x ≤ a`. -/ def limsup (u : β → α) (f : Filter β) : α := limsSup (map u f) /-- The `liminf` of a function `u` along a filter `f` is the supremum of the `a` such that, eventually for `f`, holds `u x ≥ a`. -/ def liminf (u : β → α) (f : Filter β) : α := limsInf (map u f) /-- The `blimsup` of a function `u` along a filter `f`, bounded by a predicate `p`, is the infimum of the `a` such that, eventually for `f`, `u x ≤ a` whenever `p x` holds. -/ def blimsup (u : β → α) (f : Filter β) (p : β → Prop) := sInf { a | ∀ᶠ x in f, p x → u x ≤ a } /-- The `bliminf` of a function `u` along a filter `f`, bounded by a predicate `p`, is the supremum of the `a` such that, eventually for `f`, `a ≤ u x` whenever `p x` holds. -/ def bliminf (u : β → α) (f : Filter β) (p : β → Prop) := sSup { a | ∀ᶠ x in f, p x → a ≤ u x } section variable {f : Filter β} {u : β → α} {p : β → Prop} theorem limsup_eq : limsup u f = sInf { a | ∀ᶠ n in f, u n ≤ a } := rfl theorem liminf_eq : liminf u f = sSup { a | ∀ᶠ n in f, a ≤ u n } := rfl theorem blimsup_eq : blimsup u f p = sInf { a | ∀ᶠ x in f, p x → u x ≤ a } := rfl theorem bliminf_eq : bliminf u f p = sSup { a | ∀ᶠ x in f, p x → a ≤ u x } := rfl lemma liminf_comp (u : β → α) (v : γ → β) (f : Filter γ) : liminf (u ∘ v) f = liminf u (map v f) := rfl lemma limsup_comp (u : β → α) (v : γ → β) (f : Filter γ) : limsup (u ∘ v) f = limsup u (map v f) := rfl end @[simp] theorem blimsup_true (f : Filter β) (u : β → α) : (blimsup u f fun _ => True) = limsup u f := by simp [blimsup_eq, limsup_eq] @[simp] theorem bliminf_true (f : Filter β) (u : β → α) : (bliminf u f fun _ => True) = liminf u f := by simp [bliminf_eq, liminf_eq] lemma blimsup_eq_limsup {f : Filter β} {u : β → α} {p : β → Prop} : blimsup u f p = limsup u (f ⊓ 𝓟 {x | p x}) := by simp only [blimsup_eq, limsup_eq, eventually_inf_principal, mem_setOf_eq] lemma bliminf_eq_liminf {f : Filter β} {u : β → α} {p : β → Prop} : bliminf u f p = liminf u (f ⊓ 𝓟 {x | p x}) := blimsup_eq_limsup (α := αᵒᵈ) theorem blimsup_eq_limsup_subtype {f : Filter β} {u : β → α} {p : β → Prop} : blimsup u f p = limsup (u ∘ ((↑) : { x | p x } → β)) (comap (↑) f) := by rw [blimsup_eq_limsup, limsup, limsup, ← map_map, map_comap_setCoe_val] theorem bliminf_eq_liminf_subtype {f : Filter β} {u : β → α} {p : β → Prop} : bliminf u f p = liminf (u ∘ ((↑) : { x | p x } → β)) (comap (↑) f) := blimsup_eq_limsup_subtype (α := αᵒᵈ) theorem limsSup_le_of_le {f : Filter α} {a} (hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault) (h : ∀ᶠ n in f, n ≤ a) : limsSup f ≤ a := csInf_le hf h theorem le_limsInf_of_le {f : Filter α} {a} (hf : f.IsCobounded (· ≥ ·) := by isBoundedDefault) (h : ∀ᶠ n in f, a ≤ n) : a ≤ limsInf f := le_csSup hf h theorem limsup_le_of_le {f : Filter β} {u : β → α} {a} (hf : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (h : ∀ᶠ n in f, u n ≤ a) : limsup u f ≤ a := csInf_le hf h theorem le_liminf_of_le {f : Filter β} {u : β → α} {a} (hf : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) (h : ∀ᶠ n in f, a ≤ u n) : a ≤ liminf u f := le_csSup hf h theorem le_limsSup_of_le {f : Filter α} {a} (hf : f.IsBounded (· ≤ ·) := by isBoundedDefault) (h : ∀ b, (∀ᶠ n in f, n ≤ b) → a ≤ b) : a ≤ limsSup f := le_csInf hf h theorem limsInf_le_of_le {f : Filter α} {a} (hf : f.IsBounded (· ≥ ·) := by isBoundedDefault) (h : ∀ b, (∀ᶠ n in f, b ≤ n) → b ≤ a) : limsInf f ≤ a := csSup_le hf h theorem le_limsup_of_le {f : Filter β} {u : β → α} {a} (hf : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) (h : ∀ b, (∀ᶠ n in f, u n ≤ b) → a ≤ b) : a ≤ limsup u f := le_csInf hf h theorem liminf_le_of_le {f : Filter β} {u : β → α} {a} (hf : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) (h : ∀ b, (∀ᶠ n in f, b ≤ u n) → b ≤ a) : liminf u f ≤ a := csSup_le hf h theorem limsInf_le_limsSup {f : Filter α} [NeBot f] (h₁ : f.IsBounded (· ≤ ·) := by isBoundedDefault) (h₂ : f.IsBounded (· ≥ ·) := by isBoundedDefault) : limsInf f ≤ limsSup f := liminf_le_of_le h₂ fun a₀ ha₀ => le_limsup_of_le h₁ fun a₁ ha₁ => show a₀ ≤ a₁ from let ⟨_, hb₀, hb₁⟩ := (ha₀.and ha₁).exists le_trans hb₀ hb₁ theorem liminf_le_limsup {f : Filter β} [NeBot f] {u : β → α} (h : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) (h' : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : liminf u f ≤ limsup u f := limsInf_le_limsSup h h' theorem limsSup_le_limsSup {f g : Filter α} (hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault) (hg : g.IsBounded (· ≤ ·) := by isBoundedDefault) (h : ∀ a, (∀ᶠ n in g, n ≤ a) → ∀ᶠ n in f, n ≤ a) : limsSup f ≤ limsSup g := csInf_le_csInf hf hg h theorem limsInf_le_limsInf {f g : Filter α} (hf : f.IsBounded (· ≥ ·) := by isBoundedDefault) (hg : g.IsCobounded (· ≥ ·) := by isBoundedDefault) (h : ∀ a, (∀ᶠ n in f, a ≤ n) → ∀ᶠ n in g, a ≤ n) : limsInf f ≤ limsInf g := csSup_le_csSup hg hf h theorem limsup_le_limsup {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β} (h : u ≤ᶠ[f] v) (hu : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (hv : f.IsBoundedUnder (· ≤ ·) v := by isBoundedDefault) : limsup u f ≤ limsup v f := limsSup_le_limsSup hu hv fun _ => h.trans theorem liminf_le_liminf {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β} (h : ∀ᶠ a in f, u a ≤ v a) (hu : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) (hv : f.IsCoboundedUnder (· ≥ ·) v := by isBoundedDefault) : liminf u f ≤ liminf v f := limsup_le_limsup (β := βᵒᵈ) h hv hu theorem limsSup_le_limsSup_of_le {f g : Filter α} (h : f ≤ g) (hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault) (hg : g.IsBounded (· ≤ ·) := by isBoundedDefault) : limsSup f ≤ limsSup g := limsSup_le_limsSup hf hg fun _ ha => h ha theorem limsInf_le_limsInf_of_le {f g : Filter α} (h : g ≤ f) (hf : f.IsBounded (· ≥ ·) := by isBoundedDefault) (hg : g.IsCobounded (· ≥ ·) := by isBoundedDefault) : limsInf f ≤ limsInf g := limsInf_le_limsInf hf hg fun _ ha => h ha theorem limsup_le_limsup_of_le {α β} [ConditionallyCompleteLattice β] {f g : Filter α} (h : f ≤ g) {u : α → β} (hf : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (hg : g.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) : limsup u f ≤ limsup u g := limsSup_le_limsSup_of_le (map_mono h) hf hg theorem liminf_le_liminf_of_le {α β} [ConditionallyCompleteLattice β] {f g : Filter α} (h : g ≤ f) {u : α → β} (hf : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) (hg : g.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) : liminf u f ≤ liminf u g := limsInf_le_limsInf_of_le (map_mono h) hf hg lemma limsSup_principal_eq_csSup (h : BddAbove s) (hs : s.Nonempty) : limsSup (𝓟 s) = sSup s := by simp only [limsSup, eventually_principal]; exact csInf_upperBounds_eq_csSup h hs lemma limsInf_principal_eq_csSup (h : BddBelow s) (hs : s.Nonempty) : limsInf (𝓟 s) = sInf s := limsSup_principal_eq_csSup (α := αᵒᵈ) h hs lemma limsup_top_eq_ciSup [Nonempty β] (hu : BddAbove (range u)) : limsup u ⊤ = ⨆ i, u i := by rw [limsup, map_top, limsSup_principal_eq_csSup hu (range_nonempty _), sSup_range] lemma liminf_top_eq_ciInf [Nonempty β] (hu : BddBelow (range u)) : liminf u ⊤ = ⨅ i, u i := by rw [liminf, map_top, limsInf_principal_eq_csSup hu (range_nonempty _), sInf_range] theorem limsup_congr {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β} (h : ∀ᶠ a in f, u a = v a) : limsup u f = limsup v f := by rw [limsup_eq] congr with b exact eventually_congr (h.mono fun x hx => by simp [hx]) theorem blimsup_congr {f : Filter β} {u v : β → α} {p : β → Prop} (h : ∀ᶠ a in f, p a → u a = v a) : blimsup u f p = blimsup v f p := by simpa only [blimsup_eq_limsup] using limsup_congr <| eventually_inf_principal.2 h theorem bliminf_congr {f : Filter β} {u v : β → α} {p : β → Prop} (h : ∀ᶠ a in f, p a → u a = v a) : bliminf u f p = bliminf v f p := blimsup_congr (α := αᵒᵈ) h theorem liminf_congr {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β} (h : ∀ᶠ a in f, u a = v a) : liminf u f = liminf v f := limsup_congr (β := βᵒᵈ) h @[simp] theorem limsup_const {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} [NeBot f] (b : β) : limsup (fun _ => b) f = b := by simpa only [limsup_eq, eventually_const] using csInf_Ici @[simp] theorem liminf_const {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} [NeBot f] (b : β) : liminf (fun _ => b) f = b := limsup_const (β := βᵒᵈ) b theorem HasBasis.liminf_eq_sSup_iUnion_iInter {ι ι' : Type*} {f : ι → α} {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) : liminf f v = sSup (⋃ (j : Subtype p), ⋂ (i : s j), Iic (f i)) := by simp_rw [liminf_eq, hv.eventually_iff] congr ext x simp only [mem_setOf_eq, iInter_coe_set, mem_iUnion, mem_iInter, mem_Iic, Subtype.exists, exists_prop] theorem HasBasis.liminf_eq_sSup_univ_of_empty {f : ι → α} {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) (i : ι') (hi : p i) (h'i : s i = ∅) : liminf f v = sSup univ := by simp [hv.eq_bot_iff.2 ⟨i, hi, h'i⟩, liminf_eq] theorem HasBasis.limsup_eq_sInf_iUnion_iInter {ι ι' : Type*} {f : ι → α} {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) : limsup f v = sInf (⋃ (j : Subtype p), ⋂ (i : s j), Ici (f i)) := HasBasis.liminf_eq_sSup_iUnion_iInter (α := αᵒᵈ) hv theorem HasBasis.limsup_eq_sInf_univ_of_empty {f : ι → α} {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) (i : ι') (hi : p i) (h'i : s i = ∅) : limsup f v = sInf univ := HasBasis.liminf_eq_sSup_univ_of_empty (α := αᵒᵈ) hv i hi h'i @[simp] theorem liminf_nat_add (f : ℕ → α) (k : ℕ) : liminf (fun i => f (i + k)) atTop = liminf f atTop := by rw [← Function.comp_def, liminf, liminf, ← map_map, map_add_atTop_eq_nat] @[simp] theorem limsup_nat_add (f : ℕ → α) (k : ℕ) : limsup (fun i => f (i + k)) atTop = limsup f atTop := @liminf_nat_add αᵒᵈ _ f k end ConditionallyCompleteLattice section CompleteLattice variable [CompleteLattice α] @[simp] theorem limsSup_bot : limsSup (⊥ : Filter α) = ⊥ := bot_unique <| sInf_le <| by simp @[simp] theorem limsup_bot (f : β → α) : limsup f ⊥ = ⊥ := by simp [limsup] @[simp] theorem limsInf_bot : limsInf (⊥ : Filter α) = ⊤ := top_unique <| le_sSup <| by simp @[simp] theorem liminf_bot (f : β → α) : liminf f ⊥ = ⊤ := by simp [liminf] @[simp] theorem limsSup_top : limsSup (⊤ : Filter α) = ⊤ := top_unique <| le_sInf <| by simpa [eq_univ_iff_forall] using fun b hb => top_unique <| hb _ @[simp] theorem limsInf_top : limsInf (⊤ : Filter α) = ⊥ := bot_unique <| sSup_le <| by simpa [eq_univ_iff_forall] using fun b hb => bot_unique <| hb _ @[simp] theorem blimsup_false {f : Filter β} {u : β → α} : (blimsup u f fun _ => False) = ⊥ := by simp [blimsup_eq] @[simp] theorem bliminf_false {f : Filter β} {u : β → α} : (bliminf u f fun _ => False) = ⊤ := by simp [bliminf_eq] /-- Same as limsup_const applied to `⊥` but without the `NeBot f` assumption -/ @[simp] theorem limsup_const_bot {f : Filter β} : limsup (fun _ : β => (⊥ : α)) f = (⊥ : α) := by rw [limsup_eq, eq_bot_iff] exact sInf_le (Eventually.of_forall fun _ => le_rfl) /-- Same as limsup_const applied to `⊤` but without the `NeBot f` assumption -/ @[simp] theorem liminf_const_top {f : Filter β} : liminf (fun _ : β => (⊤ : α)) f = (⊤ : α) := limsup_const_bot (α := αᵒᵈ) theorem HasBasis.limsSup_eq_iInf_sSup {ι} {p : ι → Prop} {s} {f : Filter α} (h : f.HasBasis p s) : limsSup f = ⨅ (i) (_ : p i), sSup (s i) := le_antisymm (le_iInf₂ fun i hi => sInf_le <| h.eventually_iff.2 ⟨i, hi, fun _ => le_sSup⟩) (le_sInf fun _ ha => let ⟨_, hi, ha⟩ := h.eventually_iff.1 ha iInf₂_le_of_le _ hi <| sSup_le ha) theorem HasBasis.limsInf_eq_iSup_sInf {p : ι → Prop} {s : ι → Set α} {f : Filter α} (h : f.HasBasis p s) : limsInf f = ⨆ (i) (_ : p i), sInf (s i) := HasBasis.limsSup_eq_iInf_sSup (α := αᵒᵈ) h theorem limsSup_eq_iInf_sSup {f : Filter α} : limsSup f = ⨅ s ∈ f, sSup s := f.basis_sets.limsSup_eq_iInf_sSup theorem limsInf_eq_iSup_sInf {f : Filter α} : limsInf f = ⨆ s ∈ f, sInf s := limsSup_eq_iInf_sSup (α := αᵒᵈ) theorem limsup_le_iSup {f : Filter β} {u : β → α} : limsup u f ≤ ⨆ n, u n := limsup_le_of_le (by isBoundedDefault) (Eventually.of_forall (le_iSup u)) theorem iInf_le_liminf {f : Filter β} {u : β → α} : ⨅ n, u n ≤ liminf u f := le_liminf_of_le (by isBoundedDefault) (Eventually.of_forall (iInf_le u)) /-- In a complete lattice, the limsup of a function is the infimum over sets `s` in the filter of the supremum of the function over `s` -/ theorem limsup_eq_iInf_iSup {f : Filter β} {u : β → α} : limsup u f = ⨅ s ∈ f, ⨆ a ∈ s, u a := (f.basis_sets.map u).limsSup_eq_iInf_sSup.trans <| by simp only [sSup_image, id] theorem limsup_eq_iInf_iSup_of_nat {u : ℕ → α} : limsup u atTop = ⨅ n : ℕ, ⨆ i ≥ n, u i := (atTop_basis.map u).limsSup_eq_iInf_sSup.trans <| by simp only [sSup_image, iInf_const]; rfl theorem limsup_eq_iInf_iSup_of_nat' {u : ℕ → α} : limsup u atTop = ⨅ n : ℕ, ⨆ i : ℕ, u (i + n) := by simp only [limsup_eq_iInf_iSup_of_nat, iSup_ge_eq_iSup_nat_add] theorem HasBasis.limsup_eq_iInf_iSup {p : ι → Prop} {s : ι → Set β} {f : Filter β} {u : β → α} (h : f.HasBasis p s) : limsup u f = ⨅ (i) (_ : p i), ⨆ a ∈ s i, u a := (h.map u).limsSup_eq_iInf_sSup.trans <| by simp only [sSup_image, id] lemma limsSup_principal_eq_sSup (s : Set α) : limsSup (𝓟 s) = sSup s := by simpa only [limsSup, eventually_principal] using sInf_upperBounds_eq_csSup s lemma limsInf_principal_eq_sInf (s : Set α) : limsInf (𝓟 s) = sInf s := by simpa only [limsInf, eventually_principal] using sSup_lowerBounds_eq_sInf s @[simp] lemma limsup_top_eq_iSup (u : β → α) : limsup u ⊤ = ⨆ i, u i := by rw [limsup, map_top, limsSup_principal_eq_sSup, sSup_range] @[simp] lemma liminf_top_eq_iInf (u : β → α) : liminf u ⊤ = ⨅ i, u i := by rw [liminf, map_top, limsInf_principal_eq_sInf, sInf_range] theorem blimsup_congr' {f : Filter β} {p q : β → Prop} {u : β → α} (h : ∀ᶠ x in f, u x ≠ ⊥ → (p x ↔ q x)) : blimsup u f p = blimsup u f q := by simp only [blimsup_eq] congr with a refine eventually_congr (h.mono fun b hb => ?_) rcases eq_or_ne (u b) ⊥ with hu | hu; · simp [hu] rw [hb hu] theorem bliminf_congr' {f : Filter β} {p q : β → Prop} {u : β → α} (h : ∀ᶠ x in f, u x ≠ ⊤ → (p x ↔ q x)) : bliminf u f p = bliminf u f q := blimsup_congr' (α := αᵒᵈ) h lemma HasBasis.blimsup_eq_iInf_iSup {p : ι → Prop} {s : ι → Set β} {f : Filter β} {u : β → α} (hf : f.HasBasis p s) {q : β → Prop} : blimsup u f q = ⨅ (i) (_ : p i), ⨆ a ∈ s i, ⨆ (_ : q a), u a := by simp only [blimsup_eq_limsup, (hf.inf_principal _).limsup_eq_iInf_iSup, mem_inter_iff, iSup_and, mem_setOf_eq] theorem blimsup_eq_iInf_biSup {f : Filter β} {p : β → Prop} {u : β → α} : blimsup u f p = ⨅ s ∈ f, ⨆ (b) (_ : p b ∧ b ∈ s), u b := by simp only [f.basis_sets.blimsup_eq_iInf_iSup, iSup_and', id, and_comm] theorem blimsup_eq_iInf_biSup_of_nat {p : ℕ → Prop} {u : ℕ → α} : blimsup u atTop p = ⨅ i, ⨆ (j) (_ : p j ∧ i ≤ j), u j := by simp only [atTop_basis.blimsup_eq_iInf_iSup, @and_comm (p _), iSup_and, mem_Ici, iInf_true] /-- In a complete lattice, the liminf of a function is the infimum over sets `s` in the filter of the supremum of the function over `s` -/ theorem liminf_eq_iSup_iInf {f : Filter β} {u : β → α} : liminf u f = ⨆ s ∈ f, ⨅ a ∈ s, u a := limsup_eq_iInf_iSup (α := αᵒᵈ) theorem liminf_eq_iSup_iInf_of_nat {u : ℕ → α} : liminf u atTop = ⨆ n : ℕ, ⨅ i ≥ n, u i := @limsup_eq_iInf_iSup_of_nat αᵒᵈ _ u theorem liminf_eq_iSup_iInf_of_nat' {u : ℕ → α} : liminf u atTop = ⨆ n : ℕ, ⨅ i : ℕ, u (i + n) := @limsup_eq_iInf_iSup_of_nat' αᵒᵈ _ _ theorem HasBasis.liminf_eq_iSup_iInf {p : ι → Prop} {s : ι → Set β} {f : Filter β} {u : β → α} (h : f.HasBasis p s) : liminf u f = ⨆ (i) (_ : p i), ⨅ a ∈ s i, u a := HasBasis.limsup_eq_iInf_iSup (α := αᵒᵈ) h theorem bliminf_eq_iSup_biInf {f : Filter β} {p : β → Prop} {u : β → α} : bliminf u f p = ⨆ s ∈ f, ⨅ (b) (_ : p b ∧ b ∈ s), u b := @blimsup_eq_iInf_biSup αᵒᵈ β _ f p u theorem bliminf_eq_iSup_biInf_of_nat {p : ℕ → Prop} {u : ℕ → α} : bliminf u atTop p = ⨆ i, ⨅ (j) (_ : p j ∧ i ≤ j), u j := @blimsup_eq_iInf_biSup_of_nat αᵒᵈ _ p u theorem limsup_eq_sInf_sSup {ι R : Type*} (F : Filter ι) [CompleteLattice R] (a : ι → R) : limsup a F = sInf ((fun I => sSup (a '' I)) '' F.sets) := by apply le_antisymm · rw [limsup_eq] refine sInf_le_sInf fun x hx => ?_ rcases (mem_image _ F.sets x).mp hx with ⟨I, ⟨I_mem_F, hI⟩⟩ filter_upwards [I_mem_F] with i hi exact hI ▸ le_sSup (mem_image_of_mem _ hi) · refine le_sInf fun b hb => sInf_le_of_le (mem_image_of_mem _ hb) <| sSup_le ?_ rintro _ ⟨_, h, rfl⟩ exact h theorem liminf_eq_sSup_sInf {ι R : Type*} (F : Filter ι) [CompleteLattice R] (a : ι → R) : liminf a F = sSup ((fun I => sInf (a '' I)) '' F.sets) := @Filter.limsup_eq_sInf_sSup ι (OrderDual R) _ _ a theorem liminf_le_of_frequently_le' {α β} [CompleteLattice β] {f : Filter α} {u : α → β} {x : β} (h : ∃ᶠ a in f, u a ≤ x) : liminf u f ≤ x := by rw [liminf_eq] refine sSup_le fun b hb => ?_ have hbx : ∃ᶠ _ in f, b ≤ x := by revert h rw [← not_imp_not, not_frequently, not_frequently] exact fun h => hb.mp (h.mono fun a hbx hba hax => hbx (hba.trans hax)) exact hbx.exists.choose_spec theorem le_limsup_of_frequently_le' {α β} [CompleteLattice β] {f : Filter α} {u : α → β} {x : β} (h : ∃ᶠ a in f, x ≤ u a) : x ≤ limsup u f := liminf_le_of_frequently_le' (β := βᵒᵈ) h /-- If `f : α → α` is a morphism of complete lattices, then the limsup of its iterates of any `a : α` is a fixed point. -/ @[simp] theorem _root_.CompleteLatticeHom.apply_limsup_iterate (f : CompleteLatticeHom α α) (a : α) : f (limsup (fun n => f^[n] a) atTop) = limsup (fun n => f^[n] a) atTop := by rw [limsup_eq_iInf_iSup_of_nat', map_iInf] simp_rw [_root_.map_iSup, ← Function.comp_apply (f := f), ← Function.iterate_succ' f, ← Nat.add_succ] conv_rhs => rw [iInf_split _ (0 < ·)] simp only [not_lt, Nat.le_zero, iInf_iInf_eq_left, add_zero, iInf_nat_gt_zero_eq, left_eq_inf] refine (iInf_le (fun i => ⨆ j, f^[j + (i + 1)] a) 0).trans ?_ simp only [zero_add, Function.comp_apply, iSup_le_iff] exact fun i => le_iSup (fun i => f^[i] a) (i + 1) /-- If `f : α → α` is a morphism of complete lattices, then the liminf of its iterates of any `a : α` is a fixed point. -/ theorem _root_.CompleteLatticeHom.apply_liminf_iterate (f : CompleteLatticeHom α α) (a : α) : f (liminf (fun n => f^[n] a) atTop) = liminf (fun n => f^[n] a) atTop := (CompleteLatticeHom.dual f).apply_limsup_iterate _ variable {f g : Filter β} {p q : β → Prop} {u v : β → α} theorem blimsup_mono (h : ∀ x, p x → q x) : blimsup u f p ≤ blimsup u f q := sInf_le_sInf fun a ha => ha.mono <| by tauto theorem bliminf_antitone (h : ∀ x, p x → q x) : bliminf u f q ≤ bliminf u f p := sSup_le_sSup fun a ha => ha.mono <| by tauto theorem mono_blimsup' (h : ∀ᶠ x in f, p x → u x ≤ v x) : blimsup u f p ≤ blimsup v f p := sInf_le_sInf fun _ ha => (ha.and h).mono fun _ hx hx' => (hx.2 hx').trans (hx.1 hx') theorem mono_blimsup (h : ∀ x, p x → u x ≤ v x) : blimsup u f p ≤ blimsup v f p := mono_blimsup' <| Eventually.of_forall h theorem mono_bliminf' (h : ∀ᶠ x in f, p x → u x ≤ v x) : bliminf u f p ≤ bliminf v f p := sSup_le_sSup fun _ ha => (ha.and h).mono fun _ hx hx' => (hx.1 hx').trans (hx.2 hx') theorem mono_bliminf (h : ∀ x, p x → u x ≤ v x) : bliminf u f p ≤ bliminf v f p := mono_bliminf' <| Eventually.of_forall h theorem bliminf_antitone_filter (h : f ≤ g) : bliminf u g p ≤ bliminf u f p := sSup_le_sSup fun _ ha => ha.filter_mono h theorem blimsup_monotone_filter (h : f ≤ g) : blimsup u f p ≤ blimsup u g p := sInf_le_sInf fun _ ha => ha.filter_mono h theorem blimsup_and_le_inf : (blimsup u f fun x => p x ∧ q x) ≤ blimsup u f p ⊓ blimsup u f q := le_inf (blimsup_mono <| by tauto) (blimsup_mono <| by tauto) @[simp] theorem bliminf_sup_le_inf_aux_left : (blimsup u f fun x => p x ∧ q x) ≤ blimsup u f p := blimsup_and_le_inf.trans inf_le_left @[simp] theorem bliminf_sup_le_inf_aux_right : (blimsup u f fun x => p x ∧ q x) ≤ blimsup u f q := blimsup_and_le_inf.trans inf_le_right theorem bliminf_sup_le_and : bliminf u f p ⊔ bliminf u f q ≤ bliminf u f fun x => p x ∧ q x := blimsup_and_le_inf (α := αᵒᵈ) @[simp] theorem bliminf_sup_le_and_aux_left : bliminf u f p ≤ bliminf u f fun x => p x ∧ q x := le_sup_left.trans bliminf_sup_le_and @[simp] theorem bliminf_sup_le_and_aux_right : bliminf u f q ≤ bliminf u f fun x => p x ∧ q x := le_sup_right.trans bliminf_sup_le_and /-- See also `Filter.blimsup_or_eq_sup`. -/ theorem blimsup_sup_le_or : blimsup u f p ⊔ blimsup u f q ≤ blimsup u f fun x => p x ∨ q x := sup_le (blimsup_mono <| by tauto) (blimsup_mono <| by tauto) @[simp] theorem bliminf_sup_le_or_aux_left : blimsup u f p ≤ blimsup u f fun x => p x ∨ q x := le_sup_left.trans blimsup_sup_le_or @[simp] theorem bliminf_sup_le_or_aux_right : blimsup u f q ≤ blimsup u f fun x => p x ∨ q x := le_sup_right.trans blimsup_sup_le_or /-- See also `Filter.bliminf_or_eq_inf`. -/ theorem bliminf_or_le_inf : (bliminf u f fun x => p x ∨ q x) ≤ bliminf u f p ⊓ bliminf u f q := blimsup_sup_le_or (α := αᵒᵈ) @[simp] theorem bliminf_or_le_inf_aux_left : (bliminf u f fun x => p x ∨ q x) ≤ bliminf u f p := bliminf_or_le_inf.trans inf_le_left @[simp] theorem bliminf_or_le_inf_aux_right : (bliminf u f fun x => p x ∨ q x) ≤ bliminf u f q := bliminf_or_le_inf.trans inf_le_right theorem _root_.OrderIso.apply_blimsup [CompleteLattice γ] (e : α ≃o γ) : e (blimsup u f p) = blimsup (e ∘ u) f p := by simp only [blimsup_eq, map_sInf, Function.comp_apply, e.image_eq_preimage, Set.preimage_setOf_eq, e.le_symm_apply] theorem _root_.OrderIso.apply_bliminf [CompleteLattice γ] (e : α ≃o γ) : e (bliminf u f p) = bliminf (e ∘ u) f p := e.dual.apply_blimsup theorem _root_.sSupHom.apply_blimsup_le [CompleteLattice γ] (g : sSupHom α γ) : g (blimsup u f p) ≤ blimsup (g ∘ u) f p := by simp only [blimsup_eq_iInf_biSup, Function.comp] refine ((OrderHomClass.mono g).map_iInf₂_le _).trans ?_ simp only [_root_.map_iSup, le_refl] theorem _root_.sInfHom.le_apply_bliminf [CompleteLattice γ] (g : sInfHom α γ) : bliminf (g ∘ u) f p ≤ g (bliminf u f p) := (sInfHom.dual g).apply_blimsup_le end CompleteLattice section CompleteDistribLattice variable [CompleteDistribLattice α] {f : Filter β} {p q : β → Prop} {u : β → α} lemma limsup_sup_filter {g} : limsup u (f ⊔ g) = limsup u f ⊔ limsup u g := by refine le_antisymm ?_ (sup_le (limsup_le_limsup_of_le le_sup_left) (limsup_le_limsup_of_le le_sup_right)) simp_rw [limsup_eq, sInf_sup_eq, sup_sInf_eq, mem_setOf_eq, le_iInf₂_iff] intro a ha b hb exact sInf_le ⟨ha.mono fun _ h ↦ h.trans le_sup_left, hb.mono fun _ h ↦ h.trans le_sup_right⟩ lemma liminf_sup_filter {g} : liminf u (f ⊔ g) = liminf u f ⊓ liminf u g := limsup_sup_filter (α := αᵒᵈ) @[simp] theorem blimsup_or_eq_sup : (blimsup u f fun x => p x ∨ q x) = blimsup u f p ⊔ blimsup u f q := by simp only [blimsup_eq_limsup, ← limsup_sup_filter, ← inf_sup_left, sup_principal, setOf_or] @[simp] theorem bliminf_or_eq_inf : (bliminf u f fun x => p x ∨ q x) = bliminf u f p ⊓ bliminf u f q := blimsup_or_eq_sup (α := αᵒᵈ) @[simp] lemma blimsup_sup_not : blimsup u f p ⊔ blimsup u f (¬p ·) = limsup u f := by simp_rw [← blimsup_or_eq_sup, or_not, blimsup_true] @[simp] lemma bliminf_inf_not : bliminf u f p ⊓ bliminf u f (¬p ·) = liminf u f := blimsup_sup_not (α := αᵒᵈ) @[simp] lemma blimsup_not_sup : blimsup u f (¬p ·) ⊔ blimsup u f p = limsup u f := by simpa only [not_not] using blimsup_sup_not (p := (¬p ·)) @[simp] lemma bliminf_not_inf : bliminf u f (¬p ·) ⊓ bliminf u f p = liminf u f := blimsup_not_sup (α := αᵒᵈ) lemma limsup_piecewise {s : Set β} [DecidablePred (· ∈ s)] {v} : limsup (s.piecewise u v) f = blimsup u f (· ∈ s) ⊔ blimsup v f (· ∉ s) := by rw [← blimsup_sup_not (p := (· ∈ s))] refine congr_arg₂ _ (blimsup_congr ?_) (blimsup_congr ?_) <;> filter_upwards with _ h using by simp [h] lemma liminf_piecewise {s : Set β} [DecidablePred (· ∈ s)] {v} : liminf (s.piecewise u v) f = bliminf u f (· ∈ s) ⊓ bliminf v f (· ∉ s) := limsup_piecewise (α := αᵒᵈ) theorem sup_limsup [NeBot f] (a : α) : a ⊔ limsup u f = limsup (fun x => a ⊔ u x) f := by simp only [limsup_eq_iInf_iSup, iSup_sup_eq, sup_iInf₂_eq] congr; ext s; congr; ext hs; congr exact (biSup_const (nonempty_of_mem hs)).symm theorem inf_liminf [NeBot f] (a : α) : a ⊓ liminf u f = liminf (fun x => a ⊓ u x) f := sup_limsup (α := αᵒᵈ) a theorem sup_liminf (a : α) : a ⊔ liminf u f = liminf (fun x => a ⊔ u x) f := by simp only [liminf_eq_iSup_iInf] rw [sup_comm, biSup_sup (⟨univ, univ_mem⟩ : ∃ i : Set β, i ∈ f)] simp_rw [iInf₂_sup_eq, sup_comm (a := a)] theorem inf_limsup (a : α) : a ⊓ limsup u f = limsup (fun x => a ⊓ u x) f := sup_liminf (α := αᵒᵈ) a end CompleteDistribLattice section CompleteBooleanAlgebra variable [CompleteBooleanAlgebra α] (f : Filter β) (u : β → α) theorem limsup_compl : (limsup u f)ᶜ = liminf (compl ∘ u) f := by simp only [limsup_eq_iInf_iSup, compl_iInf, compl_iSup, liminf_eq_iSup_iInf, Function.comp_apply] theorem liminf_compl : (liminf u f)ᶜ = limsup (compl ∘ u) f := by simp only [limsup_eq_iInf_iSup, compl_iInf, compl_iSup, liminf_eq_iSup_iInf, Function.comp_apply] theorem limsup_sdiff (a : α) : limsup u f \ a = limsup (fun b => u b \ a) f := by simp only [limsup_eq_iInf_iSup, sdiff_eq] rw [biInf_inf (⟨univ, univ_mem⟩ : ∃ i : Set β, i ∈ f)] simp_rw [inf_comm, inf_iSup₂_eq, inf_comm] theorem liminf_sdiff [NeBot f] (a : α) : liminf u f \ a = liminf (fun b => u b \ a) f := by simp only [sdiff_eq, inf_comm _ aᶜ, inf_liminf] theorem sdiff_limsup [NeBot f] (a : α) : a \ limsup u f = liminf (fun b => a \ u b) f := by rw [← compl_inj_iff] simp only [sdiff_eq, liminf_compl, comp_def, compl_inf, compl_compl, sup_limsup] theorem sdiff_liminf (a : α) : a \ liminf u f = limsup (fun b => a \ u b) f := by rw [← compl_inj_iff] simp only [sdiff_eq, limsup_compl, comp_def, compl_inf, compl_compl, sup_liminf] end CompleteBooleanAlgebra section SetLattice variable {p : ι → Prop} {s : ι → Set α} {𝓕 : Filter ι} {a : α} lemma mem_liminf_iff_eventually_mem : (a ∈ liminf s 𝓕) ↔ (∀ᶠ i in 𝓕, a ∈ s i) := by simpa only [liminf_eq_iSup_iInf, iSup_eq_iUnion, iInf_eq_iInter, mem_iUnion, mem_iInter] using ⟨fun ⟨S, hS, hS'⟩ ↦ mem_of_superset hS (by tauto), fun h ↦ ⟨{i | a ∈ s i}, h, by tauto⟩⟩ lemma mem_limsup_iff_frequently_mem : (a ∈ limsup s 𝓕) ↔ (∃ᶠ i in 𝓕, a ∈ s i) := by simp only [Filter.Frequently, iff_not_comm, ← mem_compl_iff, limsup_compl, comp_apply, mem_liminf_iff_eventually_mem] theorem cofinite.blimsup_set_eq : blimsup s cofinite p = { x | { n | p n ∧ x ∈ s n }.Infinite } := by simp only [blimsup_eq, le_eq_subset, eventually_cofinite, not_forall, sInf_eq_sInter, exists_prop] ext x refine ⟨fun h => ?_, fun hx t h => ?_⟩ <;> contrapose! h · simp only [mem_sInter, mem_setOf_eq, not_forall, exists_prop] exact ⟨{x}ᶜ, by simpa using h, by simp⟩ · exact hx.mono fun i hi => ⟨hi.1, fun hit => h (hit hi.2)⟩ theorem cofinite.bliminf_set_eq : bliminf s cofinite p = { x | { n | p n ∧ x ∉ s n }.Finite } := by rw [← compl_inj_iff] simp only [bliminf_eq_iSup_biInf, compl_iInf, compl_iSup, ← blimsup_eq_iInf_biSup, cofinite.blimsup_set_eq] rfl /-- In other words, `limsup cofinite s` is the set of elements lying inside the family `s` infinitely often. -/ theorem cofinite.limsup_set_eq : limsup s cofinite = { x | { n | x ∈ s n }.Infinite } := by simp only [← cofinite.blimsup_true s, cofinite.blimsup_set_eq, true_and] /-- In other words, `liminf cofinite s` is the set of elements lying outside the family `s` finitely often. -/ theorem cofinite.liminf_set_eq : liminf s cofinite = { x | { n | x ∉ s n }.Finite } := by simp only [← cofinite.bliminf_true s, cofinite.bliminf_set_eq, true_and] theorem exists_forall_mem_of_hasBasis_mem_blimsup {l : Filter β} {b : ι → Set β} {q : ι → Prop} (hl : l.HasBasis q b) {u : β → Set α} {p : β → Prop} {x : α} (hx : x ∈ blimsup u l p) : ∃ f : { i | q i } → β, ∀ i, x ∈ u (f i) ∧ p (f i) ∧ f i ∈ b i := by rw [blimsup_eq_iInf_biSup] at hx simp only [iSup_eq_iUnion, iInf_eq_iInter, mem_iInter, mem_iUnion, exists_prop] at hx choose g hg hg' using hx refine ⟨fun i : { i | q i } => g (b i) (hl.mem_of_mem i.2), fun i => ⟨?_, ?_⟩⟩ · exact hg' (b i) (hl.mem_of_mem i.2) · exact hg (b i) (hl.mem_of_mem i.2) theorem exists_forall_mem_of_hasBasis_mem_blimsup' {l : Filter β} {b : ι → Set β} (hl : l.HasBasis (fun _ => True) b) {u : β → Set α} {p : β → Prop} {x : α} (hx : x ∈ blimsup u l p) : ∃ f : ι → β, ∀ i, x ∈ u (f i) ∧ p (f i) ∧ f i ∈ b i := by obtain ⟨f, hf⟩ := exists_forall_mem_of_hasBasis_mem_blimsup hl hx exact ⟨fun i => f ⟨i, trivial⟩, fun i => hf ⟨i, trivial⟩⟩ end SetLattice section ConditionallyCompleteLinearOrder theorem frequently_lt_of_lt_limsSup {f : Filter α} [ConditionallyCompleteLinearOrder α] {a : α} (hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault) (h : a < limsSup f) : ∃ᶠ n in f, a < n := by contrapose! h simp only [not_frequently, not_lt] at h exact limsSup_le_of_le hf h theorem frequently_lt_of_limsInf_lt {f : Filter α} [ConditionallyCompleteLinearOrder α] {a : α} (hf : f.IsCobounded (· ≥ ·) := by isBoundedDefault) (h : limsInf f < a) : ∃ᶠ n in f, n < a := frequently_lt_of_lt_limsSup (α := OrderDual α) hf h theorem eventually_lt_of_lt_liminf {f : Filter α} [ConditionallyCompleteLinearOrder β] {u : α → β} {b : β} (h : b < liminf u f) (hu : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : ∀ᶠ a in f, b < u a := by obtain ⟨c, hc, hbc⟩ : ∃ (c : β) (_ : c ∈ { c : β | ∀ᶠ n : α in f, c ≤ u n }), b < c := by simp_rw [exists_prop] exact exists_lt_of_lt_csSup hu h exact hc.mono fun x hx => lt_of_lt_of_le hbc hx theorem eventually_lt_of_limsup_lt {f : Filter α} [ConditionallyCompleteLinearOrder β] {u : α → β} {b : β} (h : limsup u f < b) (hu : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) : ∀ᶠ a in f, u a < b := eventually_lt_of_lt_liminf (β := βᵒᵈ) h hu section ConditionallyCompleteLinearOrder variable [ConditionallyCompleteLinearOrder α] /-- If `Filter.limsup u atTop ≤ x`, then for all `ε > 0`, eventually we have `u b < x + ε`. -/ theorem eventually_lt_add_pos_of_limsup_le [Preorder β] [AddZeroClass α] [AddLeftStrictMono α] {x ε : α} {u : β → α} (hu_bdd : IsBoundedUnder LE.le atTop u) (hu : Filter.limsup u atTop ≤ x) (hε : 0 < ε) : ∀ᶠ b : β in atTop, u b < x + ε := eventually_lt_of_limsup_lt (lt_of_le_of_lt hu (lt_add_of_pos_right x hε)) hu_bdd /-- If `x ≤ Filter.liminf u atTop`, then for all `ε < 0`, eventually we have `x + ε < u b`. -/ theorem eventually_add_neg_lt_of_le_liminf [Preorder β] [AddZeroClass α] [AddLeftStrictMono α] {x ε : α} {u : β → α} (hu_bdd : IsBoundedUnder GE.ge atTop u) (hu : x ≤ Filter.liminf u atTop) (hε : ε < 0) : ∀ᶠ b : β in atTop, x + ε < u b := eventually_lt_of_lt_liminf (lt_of_lt_of_le (add_lt_of_neg_right x hε) hu) hu_bdd /-- If `Filter.limsup u atTop ≤ x`, then for all `ε > 0`, there exists a positive natural number `n` such that `u n < x + ε`. -/ theorem exists_lt_of_limsup_le [AddZeroClass α] [AddLeftStrictMono α] {x ε : α} {u : ℕ → α} (hu_bdd : IsBoundedUnder LE.le atTop u) (hu : Filter.limsup u atTop ≤ x) (hε : 0 < ε) : ∃ n : PNat, u n < x + ε := by have h : ∀ᶠ n : ℕ in atTop, u n < x + ε := eventually_lt_add_pos_of_limsup_le hu_bdd hu hε simp only [eventually_atTop] at h obtain ⟨n, hn⟩ := h exact ⟨⟨n + 1, Nat.succ_pos _⟩, hn (n + 1) (Nat.le_succ _)⟩ /-- If `x ≤ Filter.liminf u atTop`, then for all `ε < 0`, there exists a positive natural number `n` such that ` x + ε < u n`. -/ theorem exists_lt_of_le_liminf [AddZeroClass α] [AddLeftStrictMono α] {x ε : α} {u : ℕ → α} (hu_bdd : IsBoundedUnder GE.ge atTop u) (hu : x ≤ Filter.liminf u atTop) (hε : ε < 0) : ∃ n : PNat, x + ε < u n := by have h : ∀ᶠ n : ℕ in atTop, x + ε < u n := eventually_add_neg_lt_of_le_liminf hu_bdd hu hε simp only [eventually_atTop] at h obtain ⟨n, hn⟩ := h exact ⟨⟨n + 1, Nat.succ_pos _⟩, hn (n + 1) (Nat.le_succ _)⟩ end ConditionallyCompleteLinearOrder variable [ConditionallyCompleteLinearOrder β] {f : Filter α} {u : α → β} theorem le_limsup_of_frequently_le {b : β} (hu_le : ∃ᶠ x in f, b ≤ u x) (hu : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) : b ≤ limsup u f := by revert hu_le rw [← not_imp_not, not_frequently] simp_rw [← lt_iff_not_ge] exact fun h => eventually_lt_of_limsup_lt h hu theorem liminf_le_of_frequently_le {b : β} (hu_le : ∃ᶠ x in f, u x ≤ b) (hu : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : liminf u f ≤ b := le_limsup_of_frequently_le (β := βᵒᵈ) hu_le hu theorem frequently_lt_of_lt_limsup {b : β} (hu : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (h : b < limsup u f) : ∃ᶠ x in f, b < u x := by contrapose! h apply limsSup_le_of_le hu simpa using h theorem frequently_lt_of_liminf_lt {b : β} (hu : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) (h : liminf u f < b) : ∃ᶠ x in f, u x < b := frequently_lt_of_lt_limsup (β := βᵒᵈ) hu h theorem limsup_le_iff {x : β} (h₁ : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (h₂ : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) : limsup u f ≤ x ↔ ∀ y > x, ∀ᶠ a in f, u a < y := by refine ⟨fun h _ h' ↦ eventually_lt_of_limsup_lt (h.trans_lt h') h₂, fun h ↦ ?_⟩ --Two cases: Either `x` is a cluster point from above, or it is not. --In the first case, we use `forall_lt_iff_le'` and split an interval. --In the second case, the function `u` must eventually be smaller or equal to `x`. by_cases h' : ∀ y > x, ∃ z, x < z ∧ z < y · rw [← forall_lt_iff_le'] intro y x_y rcases h' y x_y with ⟨z, x_z, z_y⟩ exact (limsup_le_of_le h₁ ((h z x_z).mono (fun _ ↦ le_of_lt))).trans_lt z_y · apply limsup_le_of_le h₁ set_option push_neg.use_distrib true in push_neg at h' rcases h' with ⟨z, x_z, hz⟩ exact (h z x_z).mono <| fun w hw ↦ (or_iff_left (not_le_of_lt hw)).1 (hz (u w)) /- A version of `limsup_le_iff` with large inequalities in densely ordered spaces.-/ lemma limsup_le_iff' [DenselyOrdered β] {x : β} (h₁ : IsCoboundedUnder (· ≤ ·) f u := by isBoundedDefault) (h₂ : IsBoundedUnder (· ≤ ·) f u := by isBoundedDefault) : limsup u f ≤ x ↔ ∀ y > x, ∀ᶠ (a : α) in f, u a ≤ y := by refine ⟨fun h _ h' ↦ (eventually_lt_of_limsup_lt (h.trans_lt h') h₂).mono fun _ ↦ le_of_lt, ?_⟩ rw [← forall_lt_iff_le'] intro h y x_y obtain ⟨z, x_z, z_y⟩ := exists_between x_y exact (limsup_le_of_le h₁ (h z x_z)).trans_lt z_y theorem le_limsup_iff {x : β} (h₁ : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (h₂ : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) : x ≤ limsup u f ↔ ∀ y < x, ∃ᶠ a in f, y < u a := by refine ⟨fun h _ h' ↦ frequently_lt_of_lt_limsup h₁ (h'.trans_le h), fun h ↦ ?_⟩ --Two cases: Either `x` is a cluster point from below, or it is not. --In the first case, we use `forall_lt_iff_le` and split an interval. --In the second case, the function `u` must frequently be larger or equal to `x`. by_cases h' : ∀ y < x, ∃ z, y < z ∧ z < x · rw [← forall_lt_iff_le] intro y y_x obtain ⟨z, y_z, z_x⟩ := h' y y_x exact y_z.trans_le (le_limsup_of_frequently_le ((h z z_x).mono (fun _ ↦ le_of_lt)) h₂) · apply le_limsup_of_frequently_le _ h₂ set_option push_neg.use_distrib true in push_neg at h' rcases h' with ⟨z, z_x, hz⟩ exact (h z z_x).mono <| fun w hw ↦ (or_iff_right (not_le_of_lt hw)).1 (hz (u w)) /- A version of `le_limsup_iff` with large inequalities in densely ordered spaces.-/ lemma le_limsup_iff' [DenselyOrdered β] {x : β} (h₁ : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (h₂ : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) : x ≤ limsup u f ↔ ∀ y < x, ∃ᶠ a in f, y ≤ u a := by refine ⟨fun h _ h' ↦ (frequently_lt_of_lt_limsup h₁ (h'.trans_le h)).mono fun _ ↦ le_of_lt, ?_⟩ rw [← forall_lt_iff_le] intro h y y_x obtain ⟨z, y_z, z_x⟩ := exists_between y_x exact y_z.trans_le (le_limsup_of_frequently_le (h z z_x) h₂) theorem le_liminf_iff {x : β} (h₁ : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) (h₂ : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : x ≤ liminf u f ↔ ∀ y < x, ∀ᶠ a in f, y < u a := limsup_le_iff (β := βᵒᵈ) h₁ h₂ /- A version of `le_liminf_iff` with large inequalities in densely ordered spaces.-/ theorem le_liminf_iff' [DenselyOrdered β] {x : β} (h₁ : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) (h₂ : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : x ≤ liminf u f ↔ ∀ y < x, ∀ᶠ a in f, y ≤ u a := limsup_le_iff' (β := βᵒᵈ) h₁ h₂ theorem liminf_le_iff {x : β} (h₁ : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) (h₂ : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : liminf u f ≤ x ↔ ∀ y > x, ∃ᶠ a in f, u a < y := le_limsup_iff (β := βᵒᵈ) h₁ h₂ /- A version of `liminf_le_iff` with large inequalities in densely ordered spaces.-/ theorem liminf_le_iff' [DenselyOrdered β] {x : β} (h₁ : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) (h₂ : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : liminf u f ≤ x ↔ ∀ y > x, ∃ᶠ a in f, u a ≤ y := le_limsup_iff' (β := βᵒᵈ) h₁ h₂ lemma liminf_le_limsup_of_frequently_le {v : α → β} (h : ∃ᶠ x in f, u x ≤ v x) (h₁ : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) (h₂ : f.IsBoundedUnder (· ≤ ·) v := by isBoundedDefault) : liminf u f ≤ limsup v f := by rcases f.eq_or_neBot with rfl | _ · exact (frequently_bot h).rec have h₃ : f.IsCoboundedUnder (· ≥ ·) u := by obtain ⟨a, ha⟩ := h₂.eventually_le apply IsCoboundedUnder.of_frequently_le (a := a) exact (h.and_eventually ha).mono fun x ⟨u_x, v_x⟩ ↦ u_x.trans v_x have h₄ : f.IsCoboundedUnder (· ≤ ·) v := by obtain ⟨a, ha⟩ := h₁.eventually_ge apply IsCoboundedUnder.of_frequently_ge (a := a) exact (ha.and_frequently h).mono fun x ⟨u_x, v_x⟩ ↦ u_x.trans v_x refine (le_limsup_iff h₄ h₂).2 fun y y_v ↦ ?_ have := (le_liminf_iff h₃ h₁).1 (le_refl (liminf u f)) y y_v exact (h.and_eventually this).mono fun x ⟨ux_vx, y_ux⟩ ↦ y_ux.trans_le ux_vx variable [ConditionallyCompleteLinearOrder α] {f : Filter α} {b : α} -- The linter erroneously claims that I'm not referring to `c` set_option linter.unusedVariables false in theorem lt_mem_sets_of_limsSup_lt (h : f.IsBounded (· ≤ ·)) (l : f.limsSup < b) : ∀ᶠ a in f, a < b := let ⟨c, (h : ∀ᶠ a in f, a ≤ c), hcb⟩ := exists_lt_of_csInf_lt h l mem_of_superset h fun _a => hcb.trans_le' theorem gt_mem_sets_of_limsInf_gt : f.IsBounded (· ≥ ·) → b < f.limsInf → ∀ᶠ a in f, b < a := @lt_mem_sets_of_limsSup_lt αᵒᵈ _ _ _ section Classical open Classical in /-- Given an indexed family of sets `s j` over `j : Subtype p` and a function `f`, then `liminf_reparam j` is equal to `j` if `f` is bounded below on `s j`, and otherwise to some index `k` such that `f` is bounded below on `s k` (if there exists one). To ensure good measurability behavior, this index `k` is chosen as the minimal suitable index. This function is used to write down a liminf in a measurable way, in `Filter.HasBasis.liminf_eq_ciSup_ciInf` and `Filter.HasBasis.liminf_eq_ite`. -/ noncomputable def liminf_reparam (f : ι → α) (s : ι' → Set ι) (p : ι' → Prop) [Countable (Subtype p)] [Nonempty (Subtype p)] (j : Subtype p) : Subtype p := let m : Set (Subtype p) := {j | BddBelow (range (fun (i : s j) ↦ f i))} let g : ℕ → Subtype p := (exists_surjective_nat _).choose have Z : ∃ n, g n ∈ m ∨ ∀ j, j ∉ m := by by_cases H : ∃ j, j ∈ m · rcases H with ⟨j, hj⟩ rcases (exists_surjective_nat (Subtype p)).choose_spec j with ⟨n, rfl⟩ exact ⟨n, Or.inl hj⟩ · push_neg at H exact ⟨0, Or.inr H⟩ if j ∈ m then j else g (Nat.find Z) /-- Writing a liminf as a supremum of infimum, in a (possibly non-complete) conditionally complete linear order. A reparametrization trick is needed to avoid taking the infimum of sets which are not bounded below. -/ theorem HasBasis.liminf_eq_ciSup_ciInf {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} [Countable (Subtype p)] [Nonempty (Subtype p)] (hv : v.HasBasis p s) {f : ι → α} (hs : ∀ (j : Subtype p), (s j).Nonempty) (H : ∃ (j : Subtype p), BddBelow (range (fun (i : s j) ↦ f i))) : liminf f v = ⨆ (j : Subtype p), ⨅ (i : s (liminf_reparam f s p j)), f i := by classical rcases H with ⟨j0, hj0⟩ let m : Set (Subtype p) := {j | BddBelow (range (fun (i : s j) ↦ f i))} have : ∀ (j : Subtype p), Nonempty (s j) := fun j ↦ Nonempty.coe_sort (hs j) have A : ⋃ (j : Subtype p), ⋂ (i : s j), Iic (f i) = ⋃ (j : Subtype p), ⋂ (i : s (liminf_reparam f s p j)), Iic (f i) := by apply Subset.antisymm · apply iUnion_subset (fun j ↦ ?_) by_cases hj : j ∈ m · have : j = liminf_reparam f s p j := by simp only [m, liminf_reparam, hj, ite_true] conv_lhs => rw [this] apply subset_iUnion _ j · simp only [m, mem_setOf_eq, ← nonempty_iInter_Iic_iff, not_nonempty_iff_eq_empty] at hj simp only [hj, empty_subset] · apply iUnion_subset (fun j ↦ ?_) exact subset_iUnion (fun (k : Subtype p) ↦ (⋂ (i : s k), Iic (f i))) (liminf_reparam f s p j) have B : ∀ (j : Subtype p), ⋂ (i : s (liminf_reparam f s p j)), Iic (f i) = Iic (⨅ (i : s (liminf_reparam f s p j)), f i) := by intro j apply (Iic_ciInf _).symm change liminf_reparam f s p j ∈ m by_cases Hj : j ∈ m · simpa only [m, liminf_reparam, if_pos Hj] using Hj · simp only [m, liminf_reparam, if_neg Hj] have Z : ∃ n, (exists_surjective_nat (Subtype p)).choose n ∈ m ∨ ∀ j, j ∉ m := by rcases (exists_surjective_nat (Subtype p)).choose_spec j0 with ⟨n, rfl⟩ exact ⟨n, Or.inl hj0⟩ rcases Nat.find_spec Z with hZ|hZ · exact hZ · exact (hZ j0 hj0).elim simp_rw [hv.liminf_eq_sSup_iUnion_iInter, A, B, sSup_iUnion_Iic] open Classical in /-- Writing a liminf as a supremum of infimum, in a (possibly non-complete) conditionally complete linear order. A reparametrization trick is needed to avoid taking the infimum of sets which are not bounded below. -/ theorem HasBasis.liminf_eq_ite {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} [Countable (Subtype p)] [Nonempty (Subtype p)] (hv : v.HasBasis p s) (f : ι → α) : liminf f v = if ∃ (j : Subtype p), s j = ∅ then sSup univ else if ∀ (j : Subtype p), ¬BddBelow (range (fun (i : s j) ↦ f i)) then sSup ∅ else ⨆ (j : Subtype p), ⨅ (i : s (liminf_reparam f s p j)), f i := by by_cases H : ∃ (j : Subtype p), s j = ∅ · rw [if_pos H] rcases H with ⟨j, hj⟩ simp [hv.liminf_eq_sSup_univ_of_empty j j.2 hj] rw [if_neg H] by_cases H' : ∀ (j : Subtype p), ¬BddBelow (range (fun (i : s j) ↦ f i)) · have A : ∀ (j : Subtype p), ⋂ (i : s j), Iic (f i) = ∅ := by simp_rw [← not_nonempty_iff_eq_empty, nonempty_iInter_Iic_iff] exact H' simp_rw [if_pos H', hv.liminf_eq_sSup_iUnion_iInter, A, iUnion_empty] rw [if_neg H'] apply hv.liminf_eq_ciSup_ciInf · push_neg at H simpa only [nonempty_iff_ne_empty] using H · push_neg at H' exact H' /-- Given an indexed family of sets `s j` and a function `f`, then `limsup_reparam j` is equal to `j` if `f` is bounded above on `s j`, and otherwise to some index `k` such that `f` is bounded above on `s k` (if there exists one). To ensure good measurability behavior, this index `k` is chosen as the minimal suitable index. This function is used to write down a limsup in a measurable way, in `Filter.HasBasis.limsup_eq_ciInf_ciSup` and `Filter.HasBasis.limsup_eq_ite`. -/ noncomputable def limsup_reparam (f : ι → α) (s : ι' → Set ι) (p : ι' → Prop) [Countable (Subtype p)] [Nonempty (Subtype p)] (j : Subtype p) : Subtype p := liminf_reparam (α := αᵒᵈ) f s p j /-- Writing a limsup as an infimum of supremum, in a (possibly non-complete) conditionally complete linear order. A reparametrization trick is needed to avoid taking the supremum of sets which are not bounded above. -/ theorem HasBasis.limsup_eq_ciInf_ciSup {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} [Countable (Subtype p)] [Nonempty (Subtype p)] (hv : v.HasBasis p s) {f : ι → α} (hs : ∀ (j : Subtype p), (s j).Nonempty) (H : ∃ (j : Subtype p), BddAbove (range (fun (i : s j) ↦ f i))) : limsup f v = ⨅ (j : Subtype p), ⨆ (i : s (limsup_reparam f s p j)), f i := HasBasis.liminf_eq_ciSup_ciInf (α := αᵒᵈ) hv hs H open Classical in /-- Writing a limsup as an infimum of supremum, in a (possibly non-complete) conditionally complete linear order. A reparametrization trick is needed to avoid taking the supremum of sets which are not bounded below. -/ theorem HasBasis.limsup_eq_ite {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} [Countable (Subtype p)] [Nonempty (Subtype p)] (hv : v.HasBasis p s) (f : ι → α) : limsup f v = if ∃ (j : Subtype p), s j = ∅ then sInf univ else if ∀ (j : Subtype p), ¬BddAbove (range (fun (i : s j) ↦ f i)) then sInf ∅ else ⨅ (j : Subtype p), ⨆ (i : s (limsup_reparam f s p j)), f i := HasBasis.liminf_eq_ite (α := αᵒᵈ) hv f end Classical end ConditionallyCompleteLinearOrder end Filter section Order theorem GaloisConnection.l_limsup_le [ConditionallyCompleteLattice β] [ConditionallyCompleteLattice γ] {f : Filter α} {v : α → β} {l : β → γ} {u : γ → β} (gc : GaloisConnection l u) (hlv : f.IsBoundedUnder (· ≤ ·) fun x => l (v x) := by isBoundedDefault) (hv_co : f.IsCoboundedUnder (· ≤ ·) v := by isBoundedDefault) : l (limsup v f) ≤ limsup (fun x => l (v x)) f := by refine le_limsSup_of_le hlv fun c hc => ?_ rw [Filter.eventually_map] at hc simp_rw [gc _ _] at hc ⊢ exact limsSup_le_of_le hv_co hc theorem OrderIso.limsup_apply {γ} [ConditionallyCompleteLattice β] [ConditionallyCompleteLattice γ] {f : Filter α} {u : α → β} (g : β ≃o γ) (hu : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) (hu_co : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (hgu : f.IsBoundedUnder (· ≤ ·) fun x => g (u x) := by isBoundedDefault) (hgu_co : f.IsCoboundedUnder (· ≤ ·) fun x => g (u x) := by isBoundedDefault) : g (limsup u f) = limsup (fun x => g (u x)) f := by refine le_antisymm ((OrderIso.to_galoisConnection g).l_limsup_le hgu hu_co) ?_
rw [← g.symm.symm_apply_apply <| limsup (fun x => g (u x)) f, g.symm_symm] refine g.monotone ?_ have hf : u = fun i => g.symm (g (u i)) := funext fun i => (g.symm_apply_apply (u i)).symm nth_rw 2 [hf] refine (OrderIso.to_galoisConnection g.symm).l_limsup_le ?_ hgu_co simp_rw [g.symm_apply_apply]
Mathlib/Order/LiminfLimsup.lean
1,093
1,098
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.LinearAlgebra.Matrix.ToLin import Mathlib.LinearAlgebra.Quotient.Basic import Mathlib.RingTheory.Ideal.Maps import Mathlib.RingTheory.Nilpotent.Defs /-! # Nilpotent elements This file contains results about nilpotent elements that involve ring theory. -/ universe u v open Function Set variable {R S : Type*} {x y : R} theorem RingHom.ker_isRadical_iff_reduced_of_surjective {S F} [CommSemiring R] [Semiring S] [FunLike F R S] [RingHomClass F R S] {f : F} (hf : Function.Surjective f) : (RingHom.ker f).IsRadical ↔ IsReduced S := by simp_rw [isReduced_iff, hf.forall, IsNilpotent, ← map_pow, ← RingHom.mem_ker] rfl theorem isRadical_iff_span_singleton [CommSemiring R] : IsRadical y ↔ (Ideal.span ({y} : Set R)).IsRadical := by simp_rw [IsRadical, ← Ideal.mem_span_singleton] exact forall_swap.trans (forall_congr' fun r => exists_imp.symm) theorem isNilpotent_iff_zero_mem_powers [Monoid R] [Zero R] {x : R} : IsNilpotent x ↔ 0 ∈ Submonoid.powers x := Iff.rfl section CommSemiring variable [CommSemiring R] {x y : R} /-- The nilradical of a commutative semiring is the ideal of nilpotent elements. -/ def nilradical (R : Type*) [CommSemiring R] : Ideal R := (0 : Ideal R).radical theorem mem_nilradical : x ∈ nilradical R ↔ IsNilpotent x := Iff.rfl theorem nilradical_eq_sInf (R : Type*) [CommSemiring R] : nilradical R = sInf { J : Ideal R | J.IsPrime } := (Ideal.radical_eq_sInf ⊥).trans <| by simp_rw [and_iff_right bot_le] theorem nilpotent_iff_mem_prime : IsNilpotent x ↔ ∀ J : Ideal R, J.IsPrime → x ∈ J := by rw [← mem_nilradical, nilradical_eq_sInf, Submodule.mem_sInf] rfl theorem nilradical_le_prime (J : Ideal R) [H : J.IsPrime] : nilradical R ≤ J := (nilradical_eq_sInf R).symm ▸ sInf_le H @[simp] theorem nilradical_eq_zero (R : Type*) [CommSemiring R] [IsReduced R] : nilradical R = 0 :=
Ideal.ext fun _ => isNilpotent_iff_eq_zero theorem nilradical_eq_bot_iff {R : Type*} [CommSemiring R] : nilradical R = ⊥ ↔ IsReduced R := by
Mathlib/RingTheory/Nilpotent/Lemmas.lean
61
63
/- 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,119
1,119
/- Copyright (c) 2019 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.Order.BigOperators.Ring.Finset import Mathlib.Analysis.Convex.Hull import Mathlib.LinearAlgebra.AffineSpace.Basis /-! # Convex combinations This file defines convex combinations of points in a vector space. ## Main declarations * `Finset.centerMass`: Center of mass of a finite family of points. ## Implementation notes We divide by the sum of the weights in the definition of `Finset.centerMass` because of the way mathematical arguments go: one doesn't change weights, but merely adds some. This also makes a few lemmas unconditional on the sum of the weights being `1`. -/ open Set Function Pointwise universe u u' section variable {R R' E F ι ι' α : Type*} [Field R] [Field R'] [AddCommGroup E] [AddCommGroup F] [AddCommGroup α] [LinearOrder α] [Module R E] [Module R F] [Module R α] {s : Set E} /-- Center of mass of a finite collection of points with prescribed weights. Note that we require neither `0 ≤ w i` nor `∑ w = 1`. -/ def Finset.centerMass (t : Finset ι) (w : ι → R) (z : ι → E) : E := (∑ i ∈ t, w i)⁻¹ • ∑ i ∈ t, w i • z i variable (i j : ι) (c : R) (t : Finset ι) (w : ι → R) (z : ι → E) open Finset theorem Finset.centerMass_empty : (∅ : Finset ι).centerMass w z = 0 := by simp only [centerMass, sum_empty, smul_zero] theorem Finset.centerMass_pair [DecidableEq ι] (hne : i ≠ j) : ({i, j} : Finset ι).centerMass w z = (w i / (w i + w j)) • z i + (w j / (w i + w j)) • z j := by simp only [centerMass, sum_pair hne] module variable {w} theorem Finset.centerMass_insert [DecidableEq ι] (ha : i ∉ t) (hw : ∑ j ∈ t, w j ≠ 0) : (insert i t).centerMass w z = (w i / (w i + ∑ j ∈ t, w j)) • z i + ((∑ j ∈ t, w j) / (w i + ∑ j ∈ t, w j)) • t.centerMass w z := by simp only [centerMass, sum_insert ha, smul_add, (mul_smul _ _ _).symm, ← div_eq_inv_mul] congr 2 rw [div_mul_eq_mul_div, mul_inv_cancel₀ hw, one_div] theorem Finset.centerMass_singleton (hw : w i ≠ 0) : ({i} : Finset ι).centerMass w z = z i := by rw [centerMass, sum_singleton, sum_singleton] match_scalars field_simp @[simp] lemma Finset.centerMass_neg_left : t.centerMass (-w) z = t.centerMass w z := by simp [centerMass, inv_neg] lemma Finset.centerMass_smul_left {c : R'} [Module R' R] [Module R' E] [SMulCommClass R' R R] [IsScalarTower R' R R] [SMulCommClass R R' E] [IsScalarTower R' R E] (hc : c ≠ 0) : t.centerMass (c • w) z = t.centerMass w z := by simp [centerMass, -smul_assoc, smul_assoc c, ← smul_sum, smul_inv₀, smul_smul_smul_comm, hc] theorem Finset.centerMass_eq_of_sum_1 (hw : ∑ i ∈ t, w i = 1) : t.centerMass w z = ∑ i ∈ t, w i • z i := by simp only [Finset.centerMass, hw, inv_one, one_smul] theorem Finset.centerMass_smul : (t.centerMass w fun i => c • z i) = c • t.centerMass w z := by simp only [Finset.centerMass, Finset.smul_sum, (mul_smul _ _ _).symm, mul_comm c, mul_assoc] /-- A convex combination of two centers of mass is a center of mass as well. This version deals with two different index types. -/ theorem Finset.centerMass_segment' (s : Finset ι) (t : Finset ι') (ws : ι → R) (zs : ι → E) (wt : ι' → R) (zt : ι' → E) (hws : ∑ i ∈ s, ws i = 1) (hwt : ∑ i ∈ t, wt i = 1) (a b : R) (hab : a + b = 1) : a • s.centerMass ws zs + b • t.centerMass wt zt = (s.disjSum t).centerMass (Sum.elim (fun i => a * ws i) fun j => b * wt j) (Sum.elim zs zt) := by rw [s.centerMass_eq_of_sum_1 _ hws, t.centerMass_eq_of_sum_1 _ hwt, smul_sum, smul_sum, ← Finset.sum_sumElim, Finset.centerMass_eq_of_sum_1] · congr with ⟨⟩ <;> simp only [Sum.elim_inl, Sum.elim_inr, mul_smul] · rw [sum_sumElim, ← mul_sum, ← mul_sum, hws, hwt, mul_one, mul_one, hab]
/-- A convex combination of two centers of mass is a center of mass as well. This version works if two centers of mass share the set of original points. -/ theorem Finset.centerMass_segment (s : Finset ι) (w₁ w₂ : ι → R) (z : ι → E) (hw₁ : ∑ i ∈ s, w₁ i = 1) (hw₂ : ∑ i ∈ s, w₂ i = 1) (a b : R) (hab : a + b = 1) : a • s.centerMass w₁ z + b • s.centerMass w₂ z = s.centerMass (fun i => a * w₁ i + b * w₂ i) z := by have hw : (∑ i ∈ s, (a * w₁ i + b * w₂ i)) = 1 := by simp only [← mul_sum, sum_add_distrib, mul_one, *]
Mathlib/Analysis/Convex/Combination.lean
93
100
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl -/ import Mathlib.MeasureTheory.Integral.Lebesgue.Countable import Mathlib.MeasureTheory.Measure.Decomposition.Exhaustion import Mathlib.MeasureTheory.Measure.Prod /-! # Measure with a given density with respect to another measure For a measure `μ` on `α` and a function `f : α → ℝ≥0∞`, we define a new measure `μ.withDensity f`. On a measurable set `s`, that measure has value `∫⁻ a in s, f a ∂μ`. An important result about `withDensity` is the Radon-Nikodym theorem. It states that, given measures `μ, ν`, if `HaveLebesgueDecomposition μ ν` then `μ` is absolutely continuous with respect to `ν` if and only if there exists a measurable function `f : α → ℝ≥0∞` such that `μ = ν.withDensity f`. See `MeasureTheory.Measure.absolutelyContinuous_iff_withDensity_rnDeriv_eq`. -/ open Set hiding restrict restrict_apply open Filter ENNReal NNReal MeasureTheory.Measure namespace MeasureTheory variable {α : Type*} {m0 : MeasurableSpace α} {μ : Measure α} /-- Given a measure `μ : Measure α` and a function `f : α → ℝ≥0∞`, `μ.withDensity f` is the measure such that for a measurable set `s` we have `μ.withDensity f s = ∫⁻ a in s, f a ∂μ`. -/ noncomputable def Measure.withDensity {m : MeasurableSpace α} (μ : Measure α) (f : α → ℝ≥0∞) : Measure α := Measure.ofMeasurable (fun s _ => ∫⁻ a in s, f a ∂μ) (by simp) fun _ hs hd => lintegral_iUnion hs hd _ @[simp] theorem withDensity_apply (f : α → ℝ≥0∞) {s : Set α} (hs : MeasurableSet s) : μ.withDensity f s = ∫⁻ a in s, f a ∂μ := Measure.ofMeasurable_apply s hs theorem withDensity_apply_le (f : α → ℝ≥0∞) (s : Set α) : ∫⁻ a in s, f a ∂μ ≤ μ.withDensity f s := by let t := toMeasurable (μ.withDensity f) s calc ∫⁻ a in s, f a ∂μ ≤ ∫⁻ a in t, f a ∂μ := lintegral_mono_set (subset_toMeasurable (withDensity μ f) s) _ = μ.withDensity f t := (withDensity_apply f (measurableSet_toMeasurable (withDensity μ f) s)).symm _ = μ.withDensity f s := measure_toMeasurable s /-! In the next theorem, the s-finiteness assumption is necessary. Here is a counterexample without this assumption. Let `α` be an uncountable space, let `x₀` be some fixed point, and consider the σ-algebra made of those sets which are countable and do not contain `x₀`, and of their complements. This is the σ-algebra generated by the sets `{x}` for `x ≠ x₀`. Define a measure equal to `+∞` on nonempty sets. Let `s = {x₀}` and `f` the indicator of `sᶜ`. Then * `∫⁻ a in s, f a ∂μ = 0`. Indeed, consider a simple function `g ≤ f`. It vanishes on `s`. Then `∫⁻ a in s, g a ∂μ = 0`. Taking the supremum over `g` gives the claim. * `μ.withDensity f s = +∞`. Indeed, this is the infimum of `μ.withDensity f t` over measurable sets `t` containing `s`. As `s` is not measurable, such a set `t` contains a point `x ≠ x₀`. Then `μ.withDensity f t ≥ μ.withDensity f {x} = ∫⁻ a in {x}, f a ∂μ = μ {x} = +∞`. One checks that `μ.withDensity f = μ`, while `μ.restrict s` gives zero mass to sets not containing `x₀`, and infinite mass to those that contain it. -/
theorem withDensity_apply' [SFinite μ] (f : α → ℝ≥0∞) (s : Set α) : μ.withDensity f s = ∫⁻ a in s, f a ∂μ := by apply le_antisymm ?_ (withDensity_apply_le f s) let t := toMeasurable μ s calc μ.withDensity f s ≤ μ.withDensity f t := measure_mono (subset_toMeasurable μ s) _ = ∫⁻ a in t, f a ∂μ := withDensity_apply f (measurableSet_toMeasurable μ s) _ = ∫⁻ a in s, f a ∂μ := by congr 1; exact restrict_toMeasurable_of_sFinite s
Mathlib/MeasureTheory/Measure/WithDensity.lean
68
75
/- 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 -/ import Mathlib.Algebra.CharP.Defs import Mathlib.Algebra.Order.CauSeq.BigOperators import Mathlib.Algebra.Order.Star.Basic import Mathlib.Data.Complex.BigOperators import Mathlib.Data.Complex.Norm import Mathlib.Data.Nat.Choose.Sum /-! # Exponential Function This file contains the definitions of the real and complex exponential function. ## Main definitions * `Complex.exp`: The complex exponential function, defined via its Taylor series * `Real.exp`: The real exponential function, defined as the real part of the complex exponential -/ open CauSeq Finset IsAbsoluteValue open scoped ComplexConjugate namespace Complex theorem isCauSeq_norm_exp (z : ℂ) : IsCauSeq abs fun n => ∑ m ∈ range n, ‖z ^ m / m.factorial‖ := let ⟨n, hn⟩ := exists_nat_gt ‖z‖ have hn0 : (0 : ℝ) < n := lt_of_le_of_lt (norm_nonneg _) hn IsCauSeq.series_ratio_test n (‖z‖ / n) (div_nonneg (norm_nonneg _) (le_of_lt hn0)) (by rwa [div_lt_iff₀ hn0, one_mul]) fun m hm => by rw [abs_norm, abs_norm, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul, ← div_div, mul_div_assoc, mul_div_right_comm, Complex.norm_mul, Complex.norm_div, norm_natCast] gcongr exact le_trans hm (Nat.le_succ _) @[deprecated (since := "2025-02-16")] alias isCauSeq_abs_exp := isCauSeq_norm_exp noncomputable section theorem isCauSeq_exp (z : ℂ) : IsCauSeq (‖·‖) fun n => ∑ m ∈ range n, z ^ m / m.factorial := (isCauSeq_norm_exp z).of_abv /-- The Cauchy sequence consisting of partial sums of the Taylor series of the complex exponential function -/ @[pp_nodot] def exp' (z : ℂ) : CauSeq ℂ (‖·‖) := ⟨fun n => ∑ m ∈ range n, z ^ m / m.factorial, isCauSeq_exp z⟩ /-- The complex exponential function, defined via its Taylor series -/ @[pp_nodot] def exp (z : ℂ) : ℂ := CauSeq.lim (exp' z) /-- scoped notation for the complex exponential function -/ scoped notation "cexp" => Complex.exp end end Complex namespace Real open Complex noncomputable section /-- The real exponential function, defined as the real part of the complex exponential -/ @[pp_nodot] nonrec def exp (x : ℝ) : ℝ := (exp x).re /-- scoped notation for the real exponential function -/ scoped notation "rexp" => Real.exp end end Real namespace Complex variable (x y : ℂ) @[simp] theorem exp_zero : exp 0 = 1 := by rw [exp] refine lim_eq_of_equiv_const fun ε ε0 => ⟨1, fun j hj => ?_⟩ convert (config := .unfoldSameFun) ε0 -- ε0 : ε > 0 but goal is _ < ε rcases j with - | j · exact absurd hj (not_le_of_gt zero_lt_one) · dsimp [exp'] induction' j with j ih · dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl] · rw [← ih (by simp [Nat.succ_le_succ])] simp only [sum_range_succ, pow_succ] simp theorem exp_add : exp (x + y) = exp x * exp y := by have hj : ∀ j : ℕ, (∑ m ∈ range j, (x + y) ^ m / m.factorial) = ∑ i ∈ range j, ∑ k ∈ range (i + 1), x ^ k / k.factorial * (y ^ (i - k) / (i - k).factorial) := by intro j refine Finset.sum_congr rfl fun m _ => ?_ rw [add_pow, div_eq_mul_inv, sum_mul] refine Finset.sum_congr rfl fun I hi => ?_ have h₁ : (m.choose I : ℂ) ≠ 0 := Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi)))) have h₂ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi) rw [← h₂, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv] simp only [mul_left_comm (m.choose I : ℂ), mul_assoc, mul_left_comm (m.choose I : ℂ)⁻¹, mul_comm (m.choose I : ℂ)] rw [inv_mul_cancel₀ h₁] simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm] simp_rw [exp, exp', lim_mul_lim] apply (lim_eq_lim_of_equiv _).symm simp only [hj] exact cauchy_product (isCauSeq_norm_exp x) (isCauSeq_exp y) /-- the exponential function as a monoid hom from `Multiplicative ℂ` to `ℂ` -/ @[simps] noncomputable def expMonoidHom : MonoidHom (Multiplicative ℂ) ℂ := { toFun := fun z => exp z.toAdd, map_one' := by simp, map_mul' := by simp [exp_add] } theorem exp_list_sum (l : List ℂ) : exp l.sum = (l.map exp).prod := map_list_prod (M := Multiplicative ℂ) expMonoidHom l theorem exp_multiset_sum (s : Multiset ℂ) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative ℂ) ℂ _ _ expMonoidHom s theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℂ) : exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (β := Multiplicative ℂ) expMonoidHom f s lemma exp_nsmul (x : ℂ) (n : ℕ) : exp (n • x) = exp x ^ n := @MonoidHom.map_pow (Multiplicative ℂ) ℂ _ _ expMonoidHom _ _ theorem exp_nat_mul (x : ℂ) : ∀ n : ℕ, exp (n * x) = exp x ^ n | 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero] | Nat.succ n => by rw [pow_succ, Nat.cast_add_one, add_mul, exp_add, ← exp_nat_mul _ n, one_mul] @[simp] theorem exp_ne_zero : exp x ≠ 0 := fun h => zero_ne_one (α := ℂ) <| by rw [← exp_zero, ← add_neg_cancel x, exp_add, h]; simp theorem exp_neg : exp (-x) = (exp x)⁻¹ := by rw [← mul_right_inj' (exp_ne_zero x), ← exp_add]; simp [mul_inv_cancel₀ (exp_ne_zero x)] theorem exp_sub : exp (x - y) = exp x / exp y := by simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv] theorem exp_int_mul (z : ℂ) (n : ℤ) : Complex.exp (n * z) = Complex.exp z ^ n := by cases n · simp [exp_nat_mul] · simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul] @[simp] theorem exp_conj : exp (conj x) = conj (exp x) := by dsimp [exp] rw [← lim_conj] refine congr_arg CauSeq.lim (CauSeq.ext fun _ => ?_) dsimp [exp', Function.comp_def, cauSeqConj] rw [map_sum (starRingEnd _)] refine sum_congr rfl fun n _ => ?_ rw [map_div₀, map_pow, ← ofReal_natCast, conj_ofReal] @[simp] theorem ofReal_exp_ofReal_re (x : ℝ) : ((exp x).re : ℂ) = exp x := conj_eq_iff_re.1 <| by rw [← exp_conj, conj_ofReal] @[simp, norm_cast] theorem ofReal_exp (x : ℝ) : (Real.exp x : ℂ) = exp x := ofReal_exp_ofReal_re _ @[simp] theorem exp_ofReal_im (x : ℝ) : (exp x).im = 0 := by rw [← ofReal_exp_ofReal_re, ofReal_im] theorem exp_ofReal_re (x : ℝ) : (exp x).re = Real.exp x := rfl end Complex namespace Real open Complex variable (x y : ℝ) @[simp] theorem exp_zero : exp 0 = 1 := by simp [Real.exp] nonrec theorem exp_add : exp (x + y) = exp x * exp y := by simp [exp_add, exp] /-- the exponential function as a monoid hom from `Multiplicative ℝ` to `ℝ` -/ @[simps] noncomputable def expMonoidHom : MonoidHom (Multiplicative ℝ) ℝ := { toFun := fun x => exp x.toAdd, map_one' := by simp, map_mul' := by simp [exp_add] } theorem exp_list_sum (l : List ℝ) : exp l.sum = (l.map exp).prod := map_list_prod (M := Multiplicative ℝ) expMonoidHom l theorem exp_multiset_sum (s : Multiset ℝ) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative ℝ) ℝ _ _ expMonoidHom s theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℝ) : exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (β := Multiplicative ℝ) expMonoidHom f s lemma exp_nsmul (x : ℝ) (n : ℕ) : exp (n • x) = exp x ^ n := @MonoidHom.map_pow (Multiplicative ℝ) ℝ _ _ expMonoidHom _ _ nonrec theorem exp_nat_mul (x : ℝ) (n : ℕ) : exp (n * x) = exp x ^ n := ofReal_injective (by simp [exp_nat_mul]) @[simp] nonrec theorem exp_ne_zero : exp x ≠ 0 := fun h => exp_ne_zero x <| by rw [exp, ← ofReal_inj] at h; simp_all nonrec theorem exp_neg : exp (-x) = (exp x)⁻¹ := ofReal_injective <| by simp [exp_neg] theorem exp_sub : exp (x - y) = exp x / exp y := by simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv] open IsAbsoluteValue Nat theorem sum_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) (n : ℕ) : ∑ i ∈ range n, x ^ i / i ! ≤ exp x := calc ∑ i ∈ range n, x ^ i / i ! ≤ lim (⟨_, isCauSeq_re (exp' x)⟩ : CauSeq ℝ abs) := by refine le_lim (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp only [exp', const_apply, re_sum] norm_cast refine sum_le_sum_of_subset_of_nonneg (range_mono hj) fun _ _ _ ↦ ?_ positivity _ = exp x := by rw [exp, Complex.exp, ← cauSeqRe, lim_re] lemma pow_div_factorial_le_exp (hx : 0 ≤ x) (n : ℕ) : x ^ n / n ! ≤ exp x := calc x ^ n / n ! ≤ ∑ k ∈ range (n + 1), x ^ k / k ! := single_le_sum (f := fun k ↦ x ^ k / k !) (fun k _ ↦ by positivity) (self_mem_range_succ n) _ ≤ exp x := sum_le_exp_of_nonneg hx _ theorem quadratic_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : 1 + x + x ^ 2 / 2 ≤ exp x := calc 1 + x + x ^ 2 / 2 = ∑ i ∈ range 3, x ^ i / i ! := by simp only [sum_range_succ, range_one, sum_singleton, _root_.pow_zero, factorial, cast_one, ne_eq, one_ne_zero, not_false_eq_true, div_self, pow_one, mul_one, div_one, Nat.mul_one, cast_succ, add_right_inj] ring_nf _ ≤ exp x := sum_le_exp_of_nonneg hx 3 private theorem add_one_lt_exp_of_pos {x : ℝ} (hx : 0 < x) : x + 1 < exp x := (by nlinarith : x + 1 < 1 + x + x ^ 2 / 2).trans_le (quadratic_le_exp_of_nonneg hx.le) private theorem add_one_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : x + 1 ≤ exp x := by rcases eq_or_lt_of_le hx with (rfl | h) · simp exact (add_one_lt_exp_of_pos h).le theorem one_le_exp {x : ℝ} (hx : 0 ≤ x) : 1 ≤ exp x := by linarith [add_one_le_exp_of_nonneg hx] @[bound] theorem exp_pos (x : ℝ) : 0 < exp x := (le_total 0 x).elim (lt_of_lt_of_le zero_lt_one ∘ one_le_exp) fun h => by rw [← neg_neg x, Real.exp_neg] exact inv_pos.2 (lt_of_lt_of_le zero_lt_one (one_le_exp (neg_nonneg.2 h))) @[bound] lemma exp_nonneg (x : ℝ) : 0 ≤ exp x := x.exp_pos.le @[simp] theorem abs_exp (x : ℝ) : |exp x| = exp x := abs_of_pos (exp_pos _) lemma exp_abs_le (x : ℝ) : exp |x| ≤ exp x + exp (-x) := by cases le_total x 0 <;> simp [abs_of_nonpos, abs_of_nonneg, exp_nonneg, *] @[mono] theorem exp_strictMono : StrictMono exp := fun x y h => by rw [← sub_add_cancel y x, Real.exp_add] exact (lt_mul_iff_one_lt_left (exp_pos _)).2 (lt_of_lt_of_le (by linarith) (add_one_le_exp_of_nonneg (by linarith))) @[gcongr] theorem exp_lt_exp_of_lt {x y : ℝ} (h : x < y) : exp x < exp y := exp_strictMono h @[mono] theorem exp_monotone : Monotone exp := exp_strictMono.monotone @[gcongr, bound] theorem exp_le_exp_of_le {x y : ℝ} (h : x ≤ y) : exp x ≤ exp y := exp_monotone h @[simp] theorem exp_lt_exp {x y : ℝ} : exp x < exp y ↔ x < y := exp_strictMono.lt_iff_lt @[simp] theorem exp_le_exp {x y : ℝ} : exp x ≤ exp y ↔ x ≤ y := exp_strictMono.le_iff_le theorem exp_injective : Function.Injective exp := exp_strictMono.injective @[simp] theorem exp_eq_exp {x y : ℝ} : exp x = exp y ↔ x = y := exp_injective.eq_iff @[simp] theorem exp_eq_one_iff : exp x = 1 ↔ x = 0 := exp_injective.eq_iff' exp_zero @[simp] theorem one_lt_exp_iff {x : ℝ} : 1 < exp x ↔ 0 < x := by rw [← exp_zero, exp_lt_exp] @[bound] private alias ⟨_, Bound.one_lt_exp_of_pos⟩ := one_lt_exp_iff @[simp] theorem exp_lt_one_iff {x : ℝ} : exp x < 1 ↔ x < 0 := by rw [← exp_zero, exp_lt_exp] @[simp] theorem exp_le_one_iff {x : ℝ} : exp x ≤ 1 ↔ x ≤ 0 := exp_zero ▸ exp_le_exp @[simp] theorem one_le_exp_iff {x : ℝ} : 1 ≤ exp x ↔ 0 ≤ x := exp_zero ▸ exp_le_exp end Real namespace Complex theorem sum_div_factorial_le {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α] (n j : ℕ) (hn : 0 < n) : (∑ m ∈ range j with n ≤ m, (1 / m.factorial : α)) ≤ n.succ / (n.factorial * n) := calc (∑ m ∈ range j with n ≤ m, (1 / m.factorial : α)) = ∑ m ∈ range (j - n), (1 / ((m + n).factorial : α)) := by refine sum_nbij' (· - n) (· + n) ?_ ?_ ?_ ?_ ?_ <;> simp +contextual [lt_tsub_iff_right, tsub_add_cancel_of_le] _ ≤ ∑ m ∈ range (j - n), ((n.factorial : α) * (n.succ : α) ^ m)⁻¹ := by simp_rw [one_div] gcongr rw [← Nat.cast_pow, ← Nat.cast_mul, Nat.cast_le, add_comm] exact Nat.factorial_mul_pow_le_factorial _ = (n.factorial : α)⁻¹ * ∑ m ∈ range (j - n), (n.succ : α)⁻¹ ^ m := by simp [mul_inv, ← mul_sum, ← sum_mul, mul_comm, inv_pow] _ = ((n.succ : α) - n.succ * (n.succ : α)⁻¹ ^ (j - n)) / (n.factorial * n) := by have h₁ : (n.succ : α) ≠ 1 := @Nat.cast_one α _ ▸ mt Nat.cast_inj.1 (mt Nat.succ.inj (pos_iff_ne_zero.1 hn)) have h₂ : (n.succ : α) ≠ 0 := by positivity have h₃ : (n.factorial * n : α) ≠ 0 := by positivity have h₄ : (n.succ - 1 : α) = n := by simp rw [geom_sum_inv h₁ h₂, eq_div_iff_mul_eq h₃, mul_comm _ (n.factorial * n : α), ← mul_assoc (n.factorial⁻¹ : α), ← mul_inv_rev, h₄, ← mul_assoc (n.factorial * n : α), mul_comm (n : α) n.factorial, mul_inv_cancel₀ h₃, one_mul, mul_comm] _ ≤ n.succ / (n.factorial * n : α) := by gcongr; apply sub_le_self; positivity theorem exp_bound {x : ℂ} (hx : ‖x‖ ≤ 1) {n : ℕ} (hn : 0 < n) : ‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹) := by rw [← lim_const (abv := norm) (∑ m ∈ range n, _), exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_norm] refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹) rw [sum_range_sub_sum_range hj] calc ‖∑ m ∈ range j with n ≤ m, (x ^ m / m.factorial : ℂ)‖ = ‖∑ m ∈ range j with n ≤ m, (x ^ n * (x ^ (m - n) / m.factorial) : ℂ)‖ := by refine congr_arg norm (sum_congr rfl fun m hm => ?_) rw [mem_filter, mem_range] at hm rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2] _ ≤ ∑ m ∈ range j with n ≤ m, ‖x ^ n * (x ^ (m - n) / m.factorial)‖ := IsAbsoluteValue.abv_sum norm .. _ ≤ ∑ m ∈ range j with n ≤ m, ‖x‖ ^ n * (1 / m.factorial) := by simp_rw [Complex.norm_mul, Complex.norm_pow, Complex.norm_div, norm_natCast] gcongr rw [Complex.norm_pow] exact pow_le_one₀ (norm_nonneg _) hx _ = ‖x‖ ^ n * ∑ m ∈ range j with n ≤ m, (1 / m.factorial : ℝ) := by simp [abs_mul, abv_pow abs, abs_div, ← mul_sum] _ ≤ ‖x‖ ^ n * (n.succ * (n.factorial * n : ℝ)⁻¹) := by gcongr exact sum_div_factorial_le _ _ hn theorem exp_bound' {x : ℂ} {n : ℕ} (hx : ‖x‖ / n.succ ≤ 1 / 2) : ‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n / n.factorial * 2 := by rw [← lim_const (abv := norm) (∑ m ∈ range n, _), exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_norm] refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n / n.factorial * 2 let k := j - n have hj : j = n + k := (add_tsub_cancel_of_le hj).symm rw [hj, sum_range_add_sub_sum_range] calc ‖∑ i ∈ range k, x ^ (n + i) / ((n + i).factorial : ℂ)‖ ≤ ∑ i ∈ range k, ‖x ^ (n + i) / ((n + i).factorial : ℂ)‖ := IsAbsoluteValue.abv_sum _ _ _ _ ≤ ∑ i ∈ range k, ‖x‖ ^ (n + i) / (n + i).factorial := by simp [norm_natCast, Complex.norm_pow] _ ≤ ∑ i ∈ range k, ‖x‖ ^ (n + i) / ((n.factorial : ℝ) * (n.succ : ℝ) ^ i) := ?_ _ = ∑ i ∈ range k, ‖x‖ ^ n / n.factorial * (‖x‖ ^ i / (n.succ : ℝ) ^ i) := ?_ _ ≤ ‖x‖ ^ n / ↑n.factorial * 2 := ?_ · gcongr exact mod_cast Nat.factorial_mul_pow_le_factorial · refine Finset.sum_congr rfl fun _ _ => ?_ simp only [pow_add, div_eq_inv_mul, mul_inv, mul_left_comm, mul_assoc] · rw [← mul_sum] gcongr simp_rw [← div_pow] rw [geom_sum_eq, div_le_iff_of_neg] · trans (-1 : ℝ) · linarith · simp only [neg_le_sub_iff_le_add, div_pow, Nat.cast_succ, le_add_iff_nonneg_left] positivity · linarith · linarith theorem norm_exp_sub_one_le {x : ℂ} (hx : ‖x‖ ≤ 1) : ‖exp x - 1‖ ≤ 2 * ‖x‖ := calc ‖exp x - 1‖ = ‖exp x - ∑ m ∈ range 1, x ^ m / m.factorial‖ := by simp [sum_range_succ] _ ≤ ‖x‖ ^ 1 * ((Nat.succ 1 : ℝ) * ((Nat.factorial 1) * (1 : ℕ) : ℝ)⁻¹) := (exp_bound hx (by decide)) _ = 2 * ‖x‖ := by simp [two_mul, mul_two, mul_add, mul_comm, add_mul, Nat.factorial] theorem norm_exp_sub_one_sub_id_le {x : ℂ} (hx : ‖x‖ ≤ 1) : ‖exp x - 1 - x‖ ≤ ‖x‖ ^ 2 := calc ‖exp x - 1 - x‖ = ‖exp x - ∑ m ∈ range 2, x ^ m / m.factorial‖ := by simp [sub_eq_add_neg, sum_range_succ_comm, add_assoc, Nat.factorial] _ ≤ ‖x‖ ^ 2 * ((Nat.succ 2 : ℝ) * (Nat.factorial 2 * (2 : ℕ) : ℝ)⁻¹) := (exp_bound hx (by decide)) _ ≤ ‖x‖ ^ 2 * 1 := by gcongr; norm_num [Nat.factorial] _ = ‖x‖ ^ 2 := by rw [mul_one] lemma norm_exp_sub_sum_le_exp_norm_sub_sum (x : ℂ) (n : ℕ) : ‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ Real.exp ‖x‖ - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by rw [← CauSeq.lim_const (abv := norm) (∑ m ∈ range n, _), Complex.exp, sub_eq_add_neg, ← CauSeq.lim_neg, CauSeq.lim_add, ← lim_norm] refine CauSeq.lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] calc ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ _ ≤ (∑ m ∈ range j, ‖x‖ ^ m / m.factorial) - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by rw [sum_range_sub_sum_range hj, sum_range_sub_sum_range hj] refine (IsAbsoluteValue.abv_sum norm ..).trans_eq ?_ congr with i simp [Complex.norm_pow] _ ≤ Real.exp ‖x‖ - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by gcongr exact Real.sum_le_exp_of_nonneg (norm_nonneg _) _ lemma norm_exp_le_exp_norm (x : ℂ) : ‖exp x‖ ≤ Real.exp ‖x‖ := by convert norm_exp_sub_sum_le_exp_norm_sub_sum x 0 using 1 <;> simp lemma norm_exp_sub_sum_le_norm_mul_exp (x : ℂ) (n : ℕ) : ‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n * Real.exp ‖x‖ := by rw [← CauSeq.lim_const (abv := norm) (∑ m ∈ range n, _), Complex.exp, sub_eq_add_neg, ← CauSeq.lim_neg, CauSeq.lim_add, ← lim_norm] refine CauSeq.lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ _ rw [sum_range_sub_sum_range hj] calc ‖∑ m ∈ range j with n ≤ m, (x ^ m / m.factorial : ℂ)‖ = ‖∑ m ∈ range j with n ≤ m, (x ^ n * (x ^ (m - n) / m.factorial) : ℂ)‖ := by refine congr_arg norm (sum_congr rfl fun m hm => ?_) rw [mem_filter, mem_range] at hm rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2] _ ≤ ∑ m ∈ range j with n ≤ m, ‖x ^ n * (x ^ (m - n) / m.factorial)‖ := IsAbsoluteValue.abv_sum norm .. _ ≤ ∑ m ∈ range j with n ≤ m, ‖x‖ ^ n * (‖x‖ ^ (m - n) / (m - n).factorial) := by simp_rw [Complex.norm_mul, Complex.norm_pow, Complex.norm_div, norm_natCast] gcongr with i hi · rw [Complex.norm_pow] · simp _ = ‖x‖ ^ n * ∑ m ∈ range j with n ≤ m, (‖x‖ ^ (m - n) / (m - n).factorial) := by rw [← mul_sum] _ = ‖x‖ ^ n * ∑ m ∈ range (j - n), (‖x‖ ^ m / m.factorial) := by congr 1 refine (sum_bij (fun m hm ↦ m + n) ?_ ?_ ?_ ?_).symm · intro a ha simp only [mem_filter, mem_range, le_add_iff_nonneg_left, zero_le, and_true] simp only [mem_range] at ha rwa [← lt_tsub_iff_right] · intro a ha b hb hab simpa using hab · intro b hb simp only [mem_range, exists_prop] simp only [mem_filter, mem_range] at hb refine ⟨b - n, ?_, ?_⟩ · rw [tsub_lt_tsub_iff_right hb.2] exact hb.1 · rw [tsub_add_cancel_of_le hb.2] · simp _ ≤ ‖x‖ ^ n * Real.exp ‖x‖ := by gcongr refine Real.sum_le_exp_of_nonneg ?_ _ exact norm_nonneg _ @[deprecated (since := "2025-02-16")] alias abs_exp_sub_one_le := norm_exp_sub_one_le @[deprecated (since := "2025-02-16")] alias abs_exp_sub_one_sub_id_le := norm_exp_sub_one_sub_id_le @[deprecated (since := "2025-02-16")] alias abs_exp_sub_sum_le_exp_abs_sub_sum := norm_exp_sub_sum_le_exp_norm_sub_sum @[deprecated (since := "2025-02-16")] alias abs_exp_le_exp_abs := norm_exp_le_exp_norm @[deprecated (since := "2025-02-16")] alias abs_exp_sub_sum_le_abs_mul_exp := norm_exp_sub_sum_le_norm_mul_exp end Complex namespace Real open Complex Finset nonrec theorem exp_bound {x : ℝ} (hx : |x| ≤ 1) {n : ℕ} (hn : 0 < n) : |exp x - ∑ m ∈ range n, x ^ m / m.factorial| ≤ |x| ^ n * (n.succ / (n.factorial * n)) := by have hxc : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx convert exp_bound hxc hn using 2 <;> norm_cast theorem exp_bound' {x : ℝ} (h1 : 0 ≤ x) (h2 : x ≤ 1) {n : ℕ} (hn : 0 < n) : Real.exp x ≤ (∑ m ∈ Finset.range n, x ^ m / m.factorial) + x ^ n * (n + 1) / (n.factorial * n) := by have h3 : |x| = x := by simpa have h4 : |x| ≤ 1 := by rwa [h3] have h' := Real.exp_bound h4 hn rw [h3] at h' have h'' := (abs_sub_le_iff.1 h').1 have t := sub_le_iff_le_add'.1 h'' simpa [mul_div_assoc] using t theorem abs_exp_sub_one_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1| ≤ 2 * |x| := by have : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx exact_mod_cast Complex.norm_exp_sub_one_le (x := x) this theorem abs_exp_sub_one_sub_id_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1 - x| ≤ x ^ 2 := by rw [← sq_abs] have : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx exact_mod_cast Complex.norm_exp_sub_one_sub_id_le this /-- A finite initial segment of the exponential series, followed by an arbitrary tail. For fixed `n` this is just a linear map wrt `r`, and each map is a simple linear function of the previous (see `expNear_succ`), with `expNear n x r ⟶ exp x` as `n ⟶ ∞`, for any `r`. -/ noncomputable def expNear (n : ℕ) (x r : ℝ) : ℝ := (∑ m ∈ range n, x ^ m / m.factorial) + x ^ n / n.factorial * r @[simp] theorem expNear_zero (x r) : expNear 0 x r = r := by simp [expNear] @[simp] theorem expNear_succ (n x r) : expNear (n + 1) x r = expNear n x (1 + x / (n + 1) * r) := by simp [expNear, range_succ, mul_add, add_left_comm, add_assoc, pow_succ, div_eq_mul_inv, mul_inv, Nat.factorial] ac_rfl theorem expNear_sub (n x r₁ r₂) : expNear n x r₁ - expNear n x r₂ = x ^ n / n.factorial * (r₁ - r₂) := by simp [expNear, mul_sub] theorem exp_approx_end (n m : ℕ) (x : ℝ) (e₁ : n + 1 = m) (h : |x| ≤ 1) : |exp x - expNear m x 0| ≤ |x| ^ m / m.factorial * ((m + 1) / m) := by simp only [expNear, mul_zero, add_zero] convert exp_bound (n := m) h ?_ using 1 · field_simp [mul_comm] · omega theorem exp_approx_succ {n} {x a₁ b₁ : ℝ} (m : ℕ) (e₁ : n + 1 = m) (a₂ b₂ : ℝ) (e : |1 + x / m * a₂ - a₁| ≤ b₁ - |x| / m * b₂) (h : |exp x - expNear m x a₂| ≤ |x| ^ m / m.factorial * b₂) : |exp x - expNear n x a₁| ≤ |x| ^ n / n.factorial * b₁ := by refine (abs_sub_le _ _ _).trans ((add_le_add_right h _).trans ?_) subst e₁; rw [expNear_succ, expNear_sub, abs_mul] convert mul_le_mul_of_nonneg_left (a := |x| ^ n / ↑(Nat.factorial n)) (le_sub_iff_add_le'.1 e) ?_ using 1 · simp [mul_add, pow_succ', div_eq_mul_inv, abs_mul, abs_inv, ← pow_abs, mul_inv, Nat.factorial] ac_rfl · simp [div_nonneg, abs_nonneg] theorem exp_approx_end' {n} {x a b : ℝ} (m : ℕ) (e₁ : n + 1 = m) (rm : ℝ) (er : ↑m = rm) (h : |x| ≤ 1) (e : |1 - a| ≤ b - |x| / rm * ((rm + 1) / rm)) : |exp x - expNear n x a| ≤ |x| ^ n / n.factorial * b := by subst er exact exp_approx_succ _ e₁ _ _ (by simpa using e) (exp_approx_end _ _ _ e₁ h) theorem exp_1_approx_succ_eq {n} {a₁ b₁ : ℝ} {m : ℕ} (en : n + 1 = m) {rm : ℝ} (er : ↑m = rm) (h : |exp 1 - expNear m 1 ((a₁ - 1) * rm)| ≤ |1| ^ m / m.factorial * (b₁ * rm)) : |exp 1 - expNear n 1 a₁| ≤ |1| ^ n / n.factorial * b₁ := by subst er refine exp_approx_succ _ en _ _ ?_ h field_simp [show (m : ℝ) ≠ 0 by norm_cast; omega] theorem exp_approx_start (x a b : ℝ) (h : |exp x - expNear 0 x a| ≤ |x| ^ 0 / Nat.factorial 0 * b) : |exp x - a| ≤ b := by simpa using h theorem exp_bound_div_one_sub_of_interval' {x : ℝ} (h1 : 0 < x) (h2 : x < 1) : Real.exp x < 1 / (1 - x) := by have H : 0 < 1 - (1 + x + x ^ 2) * (1 - x) := calc 0 < x ^ 3 := by positivity _ = 1 - (1 + x + x ^ 2) * (1 - x) := by ring calc exp x ≤ _ := exp_bound' h1.le h2.le zero_lt_three _ ≤ 1 + x + x ^ 2 := by -- Porting note: was `norm_num [Finset.sum] <;> nlinarith` -- This proof should be restored after the norm_num plugin for big operators is ported. -- (It may also need the positivity extensions in https://github.com/leanprover-community/mathlib4/pull/3907.) rw [show 3 = 1 + 1 + 1 from rfl] repeat rw [Finset.sum_range_succ] norm_num [Nat.factorial] nlinarith _ < 1 / (1 - x) := by rw [lt_div_iff₀] <;> nlinarith theorem exp_bound_div_one_sub_of_interval {x : ℝ} (h1 : 0 ≤ x) (h2 : x < 1) : Real.exp x ≤ 1 / (1 - x) := by rcases eq_or_lt_of_le h1 with (rfl | h1) · simp · exact (exp_bound_div_one_sub_of_interval' h1 h2).le theorem add_one_lt_exp {x : ℝ} (hx : x ≠ 0) : x + 1 < Real.exp x := by obtain hx | hx := hx.symm.lt_or_lt · exact add_one_lt_exp_of_pos hx obtain h' | h' := le_or_lt 1 (-x) · linarith [x.exp_pos] have hx' : 0 < x + 1 := by linarith simpa [add_comm, exp_neg, inv_lt_inv₀ (exp_pos _) hx'] using exp_bound_div_one_sub_of_interval' (neg_pos.2 hx) h' theorem add_one_le_exp (x : ℝ) : x + 1 ≤ Real.exp x := by obtain rfl | hx := eq_or_ne x 0 · simp · exact (add_one_lt_exp hx).le lemma one_sub_lt_exp_neg {x : ℝ} (hx : x ≠ 0) : 1 - x < exp (-x) := (sub_eq_neg_add _ _).trans_lt <| add_one_lt_exp <| neg_ne_zero.2 hx lemma one_sub_le_exp_neg (x : ℝ) : 1 - x ≤ exp (-x) := (sub_eq_neg_add _ _).trans_le <| add_one_le_exp _ theorem one_sub_div_pow_le_exp_neg {n : ℕ} {t : ℝ} (ht' : t ≤ n) : (1 - t / n) ^ n ≤ exp (-t) := by rcases eq_or_ne n 0 with (rfl | hn) · simp rwa [Nat.cast_zero] at ht' calc (1 - t / n) ^ n ≤ rexp (-(t / n)) ^ n := by gcongr · exact sub_nonneg.2 <| div_le_one_of_le₀ ht' n.cast_nonneg · exact one_sub_le_exp_neg _ _ = rexp (-t) := by rw [← Real.exp_nat_mul, mul_neg, mul_comm, div_mul_cancel₀]; positivity lemma le_inv_mul_exp (x : ℝ) {c : ℝ} (hc : 0 < c) : x ≤ c⁻¹ * exp (c * x) := by rw [le_inv_mul_iff₀ hc] calc c * x _ ≤ c * x + 1 := le_add_of_nonneg_right zero_le_one _ ≤ _ := Real.add_one_le_exp (c * x) end Real namespace Mathlib.Meta.Positivity open Lean.Meta Qq /-- Extension for the `positivity` tactic: `Real.exp` is always positive. -/ @[positivity Real.exp _] def evalExp : PositivityExt where eval {u α} _ _ e := do match u, α, e with | 0, ~q(ℝ), ~q(Real.exp $a) => assertInstancesCommute pure (.positive q(Real.exp_pos $a)) | _, _, _ => throwError "not Real.exp" end Mathlib.Meta.Positivity namespace Complex @[simp] theorem norm_exp_ofReal (x : ℝ) : ‖exp x‖ = Real.exp x := by rw [← ofReal_exp] exact Complex.norm_of_nonneg (le_of_lt (Real.exp_pos _)) @[deprecated (since := "2025-02-16")] alias abs_exp_ofReal := norm_exp_ofReal end Complex
Mathlib/Data/Complex/Exponential.lean
1,573
1,584
/- 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.Analysis.Convex.Between import Mathlib.Analysis.Normed.Group.AddTorsor import Mathlib.Analysis.Normed.Module.Convex /-! # Sides of affine subspaces This file defines notions of two points being on the same or opposite sides of an affine subspace. ## Main definitions * `s.WSameSide x y`: The points `x` and `y` are weakly on the same side of the affine subspace `s`. * `s.SSameSide x y`: The points `x` and `y` are strictly on the same side of the affine subspace `s`. * `s.WOppSide x y`: The points `x` and `y` are weakly on opposite sides of the affine subspace `s`. * `s.SOppSide x y`: The points `x` and `y` are strictly on opposite sides of the affine subspace `s`. -/ variable {R V V' P P' : Type*} open AffineEquiv AffineMap namespace AffineSubspace section StrictOrderedCommRing variable [CommRing R] [PartialOrder R] [IsStrictOrderedRing R] [AddCommGroup V] [Module R V] [AddTorsor V P] variable [AddCommGroup V'] [Module R V'] [AddTorsor V' P'] /-- The points `x` and `y` are weakly on the same side of `s`. -/ def WSameSide (s : AffineSubspace R P) (x y : P) : Prop := ∃ᵉ (p₁ ∈ s) (p₂ ∈ s), SameRay R (x -ᵥ p₁) (y -ᵥ p₂) /-- The points `x` and `y` are strictly on the same side of `s`. -/ def SSameSide (s : AffineSubspace R P) (x y : P) : Prop := s.WSameSide x y ∧ x ∉ s ∧ y ∉ s /-- The points `x` and `y` are weakly on opposite sides of `s`. -/ def WOppSide (s : AffineSubspace R P) (x y : P) : Prop := ∃ᵉ (p₁ ∈ s) (p₂ ∈ s), SameRay R (x -ᵥ p₁) (p₂ -ᵥ y) /-- The points `x` and `y` are strictly on opposite sides of `s`. -/ def SOppSide (s : AffineSubspace R P) (x y : P) : Prop := s.WOppSide x y ∧ x ∉ s ∧ y ∉ s theorem WSameSide.map {s : AffineSubspace R P} {x y : P} (h : s.WSameSide x y) (f : P →ᵃ[R] P') : (s.map f).WSameSide (f x) (f y) := by rcases h with ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨f p₁, mem_map_of_mem f hp₁, f p₂, mem_map_of_mem f hp₂, ?_⟩ simp_rw [← linearMap_vsub] exact h.map f.linear theorem _root_.Function.Injective.wSameSide_map_iff {s : AffineSubspace R P} {x y : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : (s.map f).WSameSide (f x) (f y) ↔ s.WSameSide x y := by refine ⟨fun h => ?_, fun h => h.map _⟩ rcases h with ⟨fp₁, hfp₁, fp₂, hfp₂, h⟩ rw [mem_map] at hfp₁ hfp₂ rcases hfp₁ with ⟨p₁, hp₁, rfl⟩ rcases hfp₂ with ⟨p₂, hp₂, rfl⟩ refine ⟨p₁, hp₁, p₂, hp₂, ?_⟩ simp_rw [← linearMap_vsub, (f.linear_injective_iff.2 hf).sameRay_map_iff] at h exact h theorem _root_.Function.Injective.sSameSide_map_iff {s : AffineSubspace R P} {x y : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : (s.map f).SSameSide (f x) (f y) ↔ s.SSameSide x y := by simp_rw [SSameSide, hf.wSameSide_map_iff, mem_map_iff_mem_of_injective hf] @[simp] theorem _root_.AffineEquiv.wSameSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') : (s.map ↑f).WSameSide (f x) (f y) ↔ s.WSameSide x y := (show Function.Injective f.toAffineMap from f.injective).wSameSide_map_iff @[simp] theorem _root_.AffineEquiv.sSameSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') : (s.map ↑f).SSameSide (f x) (f y) ↔ s.SSameSide x y := (show Function.Injective f.toAffineMap from f.injective).sSameSide_map_iff theorem WOppSide.map {s : AffineSubspace R P} {x y : P} (h : s.WOppSide x y) (f : P →ᵃ[R] P') : (s.map f).WOppSide (f x) (f y) := by rcases h with ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨f p₁, mem_map_of_mem f hp₁, f p₂, mem_map_of_mem f hp₂, ?_⟩ simp_rw [← linearMap_vsub] exact h.map f.linear theorem _root_.Function.Injective.wOppSide_map_iff {s : AffineSubspace R P} {x y : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : (s.map f).WOppSide (f x) (f y) ↔ s.WOppSide x y := by refine ⟨fun h => ?_, fun h => h.map _⟩ rcases h with ⟨fp₁, hfp₁, fp₂, hfp₂, h⟩ rw [mem_map] at hfp₁ hfp₂ rcases hfp₁ with ⟨p₁, hp₁, rfl⟩ rcases hfp₂ with ⟨p₂, hp₂, rfl⟩ refine ⟨p₁, hp₁, p₂, hp₂, ?_⟩ simp_rw [← linearMap_vsub, (f.linear_injective_iff.2 hf).sameRay_map_iff] at h exact h theorem _root_.Function.Injective.sOppSide_map_iff {s : AffineSubspace R P} {x y : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : (s.map f).SOppSide (f x) (f y) ↔ s.SOppSide x y := by simp_rw [SOppSide, hf.wOppSide_map_iff, mem_map_iff_mem_of_injective hf] @[simp] theorem _root_.AffineEquiv.wOppSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') : (s.map ↑f).WOppSide (f x) (f y) ↔ s.WOppSide x y := (show Function.Injective f.toAffineMap from f.injective).wOppSide_map_iff @[simp] theorem _root_.AffineEquiv.sOppSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') : (s.map ↑f).SOppSide (f x) (f y) ↔ s.SOppSide x y := (show Function.Injective f.toAffineMap from f.injective).sOppSide_map_iff theorem WSameSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.WSameSide x y) : (s : Set P).Nonempty := ⟨h.choose, h.choose_spec.left⟩ theorem SSameSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : (s : Set P).Nonempty := ⟨h.1.choose, h.1.choose_spec.left⟩ theorem WOppSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.WOppSide x y) : (s : Set P).Nonempty := ⟨h.choose, h.choose_spec.left⟩ theorem SOppSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : (s : Set P).Nonempty := ⟨h.1.choose, h.1.choose_spec.left⟩ theorem SSameSide.wSameSide {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : s.WSameSide x y := h.1 theorem SSameSide.left_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : x ∉ s := h.2.1 theorem SSameSide.right_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : y ∉ s := h.2.2 theorem SOppSide.wOppSide {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : s.WOppSide x y := h.1 theorem SOppSide.left_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : x ∉ s := h.2.1 theorem SOppSide.right_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : y ∉ s := h.2.2 theorem wSameSide_comm {s : AffineSubspace R P} {x y : P} : s.WSameSide x y ↔ s.WSameSide y x := ⟨fun ⟨p₁, hp₁, p₂, hp₂, h⟩ => ⟨p₂, hp₂, p₁, hp₁, h.symm⟩, fun ⟨p₁, hp₁, p₂, hp₂, h⟩ => ⟨p₂, hp₂, p₁, hp₁, h.symm⟩⟩ alias ⟨WSameSide.symm, _⟩ := wSameSide_comm theorem sSameSide_comm {s : AffineSubspace R P} {x y : P} : s.SSameSide x y ↔ s.SSameSide y x := by rw [SSameSide, SSameSide, wSameSide_comm, and_comm (b := x ∉ s)] alias ⟨SSameSide.symm, _⟩ := sSameSide_comm theorem wOppSide_comm {s : AffineSubspace R P} {x y : P} : s.WOppSide x y ↔ s.WOppSide y x := by constructor · rintro ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨p₂, hp₂, p₁, hp₁, ?_⟩ rwa [SameRay.sameRay_comm, ← sameRay_neg_iff, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev] · rintro ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨p₂, hp₂, p₁, hp₁, ?_⟩ rwa [SameRay.sameRay_comm, ← sameRay_neg_iff, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev] alias ⟨WOppSide.symm, _⟩ := wOppSide_comm theorem sOppSide_comm {s : AffineSubspace R P} {x y : P} : s.SOppSide x y ↔ s.SOppSide y x := by rw [SOppSide, SOppSide, wOppSide_comm, and_comm (b := x ∉ s)] alias ⟨SOppSide.symm, _⟩ := sOppSide_comm theorem not_wSameSide_bot (x y : P) : ¬(⊥ : AffineSubspace R P).WSameSide x y := fun ⟨_, h, _⟩ => h.elim theorem not_sSameSide_bot (x y : P) : ¬(⊥ : AffineSubspace R P).SSameSide x y := fun h => not_wSameSide_bot x y h.wSameSide theorem not_wOppSide_bot (x y : P) : ¬(⊥ : AffineSubspace R P).WOppSide x y := fun ⟨_, h, _⟩ => h.elim theorem not_sOppSide_bot (x y : P) : ¬(⊥ : AffineSubspace R P).SOppSide x y := fun h => not_wOppSide_bot x y h.wOppSide @[simp] theorem wSameSide_self_iff {s : AffineSubspace R P} {x : P} : s.WSameSide x x ↔ (s : Set P).Nonempty := ⟨fun h => h.nonempty, fun ⟨p, hp⟩ => ⟨p, hp, p, hp, SameRay.rfl⟩⟩ theorem sSameSide_self_iff {s : AffineSubspace R P} {x : P} : s.SSameSide x x ↔ (s : Set P).Nonempty ∧ x ∉ s := ⟨fun ⟨h, hx, _⟩ => ⟨wSameSide_self_iff.1 h, hx⟩, fun ⟨h, hx⟩ => ⟨wSameSide_self_iff.2 h, hx, hx⟩⟩ theorem wSameSide_of_left_mem {s : AffineSubspace R P} {x : P} (y : P) (hx : x ∈ s) : s.WSameSide x y := by refine ⟨x, hx, x, hx, ?_⟩ rw [vsub_self] apply SameRay.zero_left
theorem wSameSide_of_right_mem {s : AffineSubspace R P} (x : P) {y : P} (hy : y ∈ s) :
Mathlib/Analysis/Convex/Side.lean
214
215
/- Copyright (c) 2021 Martin Zinkevich. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Martin Zinkevich, Rémy Degenne -/ import Mathlib.Logic.Encodable.Lattice import Mathlib.MeasureTheory.MeasurableSpace.Defs import Mathlib.Order.Disjointed /-! # Induction principles for measurable sets, related to π-systems and λ-systems. ## Main statements * The main theorem of this file is Dynkin's π-λ theorem, which appears here as an induction principle `induction_on_inter`. Suppose `s` is a collection of subsets of `α` such that the intersection of two members of `s` belongs to `s` whenever it is nonempty. Let `m` be the σ-algebra generated by `s`. In order to check that a predicate `C` holds on every member of `m`, it suffices to check that `C` holds on the members of `s` and that `C` is preserved by complementation and *disjoint* countable unions. * The proof of this theorem relies on the notion of `IsPiSystem`, i.e., a collection of sets which is closed under binary non-empty intersections. Note that this is a small variation around the usual notion in the literature, which often requires that a π-system is non-empty, and closed also under disjoint intersections. This variation turns out to be convenient for the formalization. * The proof of Dynkin's π-λ theorem also requires the notion of `DynkinSystem`, i.e., a collection of sets which contains the empty set, is closed under complementation and under countable union of pairwise disjoint sets. The disjointness condition is the only difference with `σ`-algebras. * `generatePiSystem g` gives the minimal π-system containing `g`. This can be considered a Galois insertion into both measurable spaces and sets. * `generateFrom_generatePiSystem_eq` proves that if you start from a collection of sets `g`, take the generated π-system, and then the generated σ-algebra, you get the same result as the σ-algebra generated from `g`. This is useful because there are connections between independent sets that are π-systems and the generated independent spaces. * `mem_generatePiSystem_iUnion_elim` and `mem_generatePiSystem_iUnion_elim'` show that any element of the π-system generated from the union of a set of π-systems can be represented as the intersection of a finite number of elements from these sets. * `piiUnionInter` defines a new π-system from a family of π-systems `π : ι → Set (Set α)` and a set of indices `S : Set ι`. `piiUnionInter π S` is the set of sets that can be written as `⋂ x ∈ t, f x` for some finset `t ∈ S` and sets `f x ∈ π x`. ## Implementation details * `IsPiSystem` is a predicate, not a type. Thus, we don't explicitly define the galois insertion, nor do we define a complete lattice. In theory, we could define a complete lattice and galois insertion on the subtype corresponding to `IsPiSystem`. -/ open MeasurableSpace Set open MeasureTheory variable {α β : Type*} /-- A π-system is a collection of subsets of `α` that is closed under binary intersection of non-disjoint sets. Usually it is also required that the collection is nonempty, but we don't do that here. -/ def IsPiSystem (C : Set (Set α)) : Prop := ∀ᵉ (s ∈ C) (t ∈ C), (s ∩ t : Set α).Nonempty → s ∩ t ∈ C namespace MeasurableSpace theorem isPiSystem_measurableSet {α : Type*} [MeasurableSpace α] : IsPiSystem { s : Set α | MeasurableSet s } := fun _ hs _ ht _ => hs.inter ht end MeasurableSpace theorem IsPiSystem.singleton (S : Set α) : IsPiSystem ({S} : Set (Set α)) := by intro s h_s t h_t _ rw [Set.mem_singleton_iff.1 h_s, Set.mem_singleton_iff.1 h_t, Set.inter_self, Set.mem_singleton_iff] theorem IsPiSystem.insert_empty {S : Set (Set α)} (h_pi : IsPiSystem S) : IsPiSystem (insert ∅ S) := by intro s hs t ht hst rcases hs with hs | hs · simp [hs] · rcases ht with ht | ht · simp [ht] · exact Set.mem_insert_of_mem _ (h_pi s hs t ht hst) theorem IsPiSystem.insert_univ {S : Set (Set α)} (h_pi : IsPiSystem S) : IsPiSystem (insert Set.univ S) := by intro s hs t ht hst rcases hs with hs | hs · rcases ht with ht | ht <;> simp [hs, ht] · rcases ht with ht | ht · simp [hs, ht] · exact Set.mem_insert_of_mem _ (h_pi s hs t ht hst) theorem IsPiSystem.comap {α β} {S : Set (Set β)} (h_pi : IsPiSystem S) (f : α → β) : IsPiSystem { s : Set α | ∃ t ∈ S, f ⁻¹' t = s } := by rintro _ ⟨s, hs_mem, rfl⟩ _ ⟨t, ht_mem, rfl⟩ hst rw [← Set.preimage_inter] at hst ⊢ exact ⟨s ∩ t, h_pi s hs_mem t ht_mem (nonempty_of_nonempty_preimage hst), rfl⟩
theorem isPiSystem_iUnion_of_directed_le {α ι} (p : ι → Set (Set α)) (hp_pi : ∀ n, IsPiSystem (p n)) (hp_directed : Directed (· ≤ ·) p) : IsPiSystem (⋃ n, p n) := by intro t1 ht1 t2 ht2 h
Mathlib/MeasureTheory/PiSystem.lean
105
109
/- Copyright (c) 2014 Parikshit Khanna. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro -/ import Mathlib.Data.List.Lemmas import Mathlib.Data.Nat.Factorial.Basic import Mathlib.Data.List.Count import Mathlib.Data.List.Duplicate import Mathlib.Data.List.InsertIdx import Mathlib.Data.List.Induction import Batteries.Data.List.Perm import Mathlib.Data.List.Perm.Basic /-! # Permutations of a list In this file we prove properties about `List.Permutations`, a list of all permutations of a list. It is defined in `Data.List.Defs`. ## Order of the permutations Designed for performance, the order in which the permutations appear in `List.Permutations` is rather intricate and not very amenable to induction. That's why we also provide `List.Permutations'` as a less efficient but more straightforward way of listing permutations. ### `List.Permutations` TODO. In the meantime, you can try decrypting the docstrings. ### `List.Permutations'` The list of partitions is built by recursion. The permutations of `[]` are `[[]]`. Then, the permutations of `a :: l` are obtained by taking all permutations of `l` in order and adding `a` in all positions. Hence, to build `[0, 1, 2, 3].permutations'`, it does * `[[]]` * `[[3]]` * `[[2, 3], [3, 2]]]` * `[[1, 2, 3], [2, 1, 3], [2, 3, 1], [1, 3, 2], [3, 1, 2], [3, 2, 1]]` * `[[0, 1, 2, 3], [1, 0, 2, 3], [1, 2, 0, 3], [1, 2, 3, 0],` `[0, 2, 1, 3], [2, 0, 1, 3], [2, 1, 0, 3], [2, 1, 3, 0],` `[0, 2, 3, 1], [2, 0, 3, 1], [2, 3, 0, 1], [2, 3, 1, 0],` `[0, 1, 3, 2], [1, 0, 3, 2], [1, 3, 0, 2], [1, 3, 2, 0],` `[0, 3, 1, 2], [3, 0, 1, 2], [3, 1, 0, 2], [3, 1, 2, 0],` `[0, 3, 2, 1], [3, 0, 2, 1], [3, 2, 0, 1], [3, 2, 1, 0]]` -/ -- Make sure we don't import algebra assert_not_exists Monoid open Nat Function variable {α β : Type*} namespace List theorem permutationsAux2_fst (t : α) (ts : List α) (r : List β) : ∀ (ys : List α) (f : List α → β), (permutationsAux2 t ts r ys f).1 = ys ++ ts | [], _ => rfl | y :: ys, f => by simp [permutationsAux2, permutationsAux2_fst t _ _ ys] @[simp] theorem permutationsAux2_snd_nil (t : α) (ts : List α) (r : List β) (f : List α → β) : (permutationsAux2 t ts r [] f).2 = r := rfl @[simp] theorem permutationsAux2_snd_cons (t : α) (ts : List α) (r : List β) (y : α) (ys : List α)
(f : List α → β) : (permutationsAux2 t ts r (y :: ys) f).2 = f (t :: y :: ys ++ ts) :: (permutationsAux2 t ts r ys fun x : List α => f (y :: x)).2 := by simp [permutationsAux2, permutationsAux2_fst t _ _ ys]
Mathlib/Data/List/Permutation.lean
69
73
/- Copyright (c) 2022 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.ContDiff.Operations import Mathlib.Analysis.Calculus.UniformLimitsDeriv import Mathlib.Topology.Algebra.InfiniteSum.Module import Mathlib.Analysis.NormedSpace.FunctionSeries /-! # Smoothness of series We show that series of functions are differentiable, or smooth, when each individual function in the series is and additionally suitable uniform summable bounds are satisfied. More specifically, * `differentiable_tsum` ensures that a series of differentiable functions is differentiable. * `contDiff_tsum` ensures that a series of `C^n` functions is `C^n`. We also give versions of these statements which are localized to a set. -/ open Set Metric TopologicalSpace Function Asymptotics Filter open scoped Topology NNReal variable {α β 𝕜 E F : Type*} [NontriviallyNormedField 𝕜] [IsRCLikeNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [CompleteSpace F] {u : α → ℝ} /-! ### Differentiability -/ variable [NormedSpace 𝕜 F] variable {f : α → E → F} {f' : α → E → E →L[𝕜] F} {g : α → 𝕜 → F} {g' : α → 𝕜 → F} {v : ℕ → α → ℝ} {s : Set E} {t : Set 𝕜} {x₀ x : E} {y₀ y : 𝕜} {N : ℕ∞} /-- Consider a series of functions `∑' n, f n x` on a preconnected open set. If the series converges at a point, and all functions in the series are differentiable with a summable bound on the derivatives, then the series converges everywhere on the set. -/ theorem summable_of_summable_hasFDerivAt_of_isPreconnected (hu : Summable u) (hs : IsOpen s) (h's : IsPreconnected s) (hf : ∀ n x, x ∈ s → HasFDerivAt (f n) (f' n x) x) (hf' : ∀ n x, x ∈ s → ‖f' n x‖ ≤ u n) (hx₀ : x₀ ∈ s) (hf0 : Summable (f · x₀)) (hx : x ∈ s) : Summable fun n => f n x := by haveI := Classical.decEq α rw [summable_iff_cauchySeq_finset] at hf0 ⊢ have A : UniformCauchySeqOn (fun t : Finset α => fun x => ∑ i ∈ t, f' i x) atTop s := (tendstoUniformlyOn_tsum hu hf').uniformCauchySeqOn refine cauchy_map_of_uniformCauchySeqOn_fderiv (f := fun t x ↦ ∑ i ∈ t, f i x) hs h's A (fun t y hy => ?_) hx₀ hx hf0 exact HasFDerivAt.sum fun i _ => hf i y hy /-- Consider a series of functions `∑' n, f n x` on a preconnected open set. If the series converges at a point, and all functions in the series are differentiable with a summable bound on the derivatives, then the series converges everywhere on the set. -/ theorem summable_of_summable_hasDerivAt_of_isPreconnected (hu : Summable u) (ht : IsOpen t) (h't : IsPreconnected t) (hg : ∀ n y, y ∈ t → HasDerivAt (g n) (g' n y) y) (hg' : ∀ n y, y ∈ t → ‖g' n y‖ ≤ u n) (hy₀ : y₀ ∈ t) (hg0 : Summable (g · y₀)) (hy : y ∈ t) : Summable fun n => g n y := by simp_rw [hasDerivAt_iff_hasFDerivAt] at hg refine summable_of_summable_hasFDerivAt_of_isPreconnected hu ht h't hg ?_ hy₀ hg0 hy simpa? says simpa only [ContinuousLinearMap.norm_smulRight_apply, norm_one, one_mul] /-- Consider a series of functions `∑' n, f n x` on a preconnected open set. If the series converges at a point, and all functions in the series are differentiable with a summable bound on the derivatives, then the series is differentiable on the set and its derivative is the sum of the derivatives. -/ theorem hasFDerivAt_tsum_of_isPreconnected (hu : Summable u) (hs : IsOpen s) (h's : IsPreconnected s) (hf : ∀ n x, x ∈ s → HasFDerivAt (f n) (f' n x) x) (hf' : ∀ n x, x ∈ s → ‖f' n x‖ ≤ u n) (hx₀ : x₀ ∈ s) (hf0 : Summable fun n => f n x₀) (hx : x ∈ s) : HasFDerivAt (fun y => ∑' n, f n y) (∑' n, f' n x) x := by classical have A : ∀ x : E, x ∈ s → Tendsto (fun t : Finset α => ∑ n ∈ t, f n x) atTop (𝓝 (∑' n, f n x)) := by intro y hy apply Summable.hasSum exact summable_of_summable_hasFDerivAt_of_isPreconnected hu hs h's hf hf' hx₀ hf0 hy refine hasFDerivAt_of_tendstoUniformlyOn hs (tendstoUniformlyOn_tsum hu hf') (fun t y hy => ?_) A hx exact HasFDerivAt.sum fun n _ => hf n y hy /-- Consider a series of functions `∑' n, f n x` on a preconnected open set. If the series converges at a point, and all functions in the series are differentiable with a summable bound on the derivatives, then the series is differentiable on the set and its derivative is the sum of the derivatives. -/ theorem hasDerivAt_tsum_of_isPreconnected (hu : Summable u) (ht : IsOpen t) (h't : IsPreconnected t) (hg : ∀ n y, y ∈ t → HasDerivAt (g n) (g' n y) y) (hg' : ∀ n y, y ∈ t → ‖g' n y‖ ≤ u n) (hy₀ : y₀ ∈ t) (hg0 : Summable fun n => g n y₀) (hy : y ∈ t) : HasDerivAt (fun z => ∑' n, g n z) (∑' n, g' n y) y := by simp_rw [hasDerivAt_iff_hasFDerivAt] at hg ⊢ convert hasFDerivAt_tsum_of_isPreconnected hu ht h't hg ?_ hy₀ hg0 hy · exact (ContinuousLinearMap.smulRightL 𝕜 𝕜 F 1).map_tsum <| .of_norm_bounded u hu fun n ↦ hg' n y hy · simpa? says simpa only [ContinuousLinearMap.norm_smulRight_apply, norm_one, one_mul] /-- Consider a series of functions `∑' n, f n x`. If the series converges at a point, and all functions in the series are differentiable with a summable bound on the derivatives, then the series converges everywhere. -/ theorem summable_of_summable_hasFDerivAt (hu : Summable u) (hf : ∀ n x, HasFDerivAt (f n) (f' n x) x) (hf' : ∀ n x, ‖f' n x‖ ≤ u n) (hf0 : Summable fun n => f n x₀) (x : E) : Summable fun n => f n x := by letI : RCLike 𝕜 := IsRCLikeNormedField.rclike 𝕜 let _ : NormedSpace ℝ E := NormedSpace.restrictScalars ℝ 𝕜 _ exact summable_of_summable_hasFDerivAt_of_isPreconnected hu isOpen_univ isPreconnected_univ (fun n x _ => hf n x) (fun n x _ => hf' n x) (mem_univ _) hf0 (mem_univ _) /-- Consider a series of functions `∑' n, f n x`. If the series converges at a point, and all functions in the series are differentiable with a summable bound on the derivatives, then the series converges everywhere. -/ theorem summable_of_summable_hasDerivAt (hu : Summable u) (hg : ∀ n y, HasDerivAt (g n) (g' n y) y) (hg' : ∀ n y, ‖g' n y‖ ≤ u n) (hg0 : Summable fun n => g n y₀) (y : 𝕜) : Summable fun n => g n y := by exact summable_of_summable_hasDerivAt_of_isPreconnected hu isOpen_univ isPreconnected_univ (fun n x _ => hg n x) (fun n x _ => hg' n x) (mem_univ _) hg0 (mem_univ _) /-- Consider a series of functions `∑' n, f n x`. If the series converges at a point, and all functions in the series are differentiable with a summable bound on the derivatives, then the series is differentiable and its derivative is the sum of the derivatives. -/ theorem hasFDerivAt_tsum (hu : Summable u) (hf : ∀ n x, HasFDerivAt (f n) (f' n x) x) (hf' : ∀ n x, ‖f' n x‖ ≤ u n) (hf0 : Summable fun n => f n x₀) (x : E) : HasFDerivAt (fun y => ∑' n, f n y) (∑' n, f' n x) x := by letI : RCLike 𝕜 := IsRCLikeNormedField.rclike 𝕜 let A : NormedSpace ℝ E := NormedSpace.restrictScalars ℝ 𝕜 _ exact hasFDerivAt_tsum_of_isPreconnected hu isOpen_univ isPreconnected_univ (fun n x _ => hf n x) (fun n x _ => hf' n x) (mem_univ _) hf0 (mem_univ _) /-- Consider a series of functions `∑' n, f n x`. If the series converges at a point, and all functions in the series are differentiable with a summable bound on the derivatives, then the series is differentiable and its derivative is the sum of the derivatives. -/ theorem hasDerivAt_tsum (hu : Summable u) (hg : ∀ n y, HasDerivAt (g n) (g' n y) y) (hg' : ∀ n y, ‖g' n y‖ ≤ u n) (hg0 : Summable fun n => g n y₀) (y : 𝕜) : HasDerivAt (fun z => ∑' n, g n z) (∑' n, g' n y) y := by exact hasDerivAt_tsum_of_isPreconnected hu isOpen_univ isPreconnected_univ (fun n y _ => hg n y) (fun n y _ => hg' n y) (mem_univ _) hg0 (mem_univ _) /-- Consider a series of functions `∑' n, f n x`. If all functions in the series are differentiable with a summable bound on the derivatives, then the series is differentiable. Note that our assumptions do not ensure the pointwise convergence, but if there is no pointwise convergence then the series is zero everywhere so the result still holds. -/ theorem differentiable_tsum (hu : Summable u) (hf : ∀ n x, HasFDerivAt (f n) (f' n x) x) (hf' : ∀ n x, ‖f' n x‖ ≤ u n) : Differentiable 𝕜 fun y => ∑' n, f n y := by by_cases h : ∃ x₀, Summable fun n => f n x₀ · rcases h with ⟨x₀, hf0⟩ intro x exact (hasFDerivAt_tsum hu hf hf' hf0 x).differentiableAt · push_neg at h have : (fun x => ∑' n, f n x) = 0 := by ext1 x; exact tsum_eq_zero_of_not_summable (h x) rw [this] exact differentiable_const 0 /-- Consider a series of functions `∑' n, f n x`. If all functions in the series are differentiable with a summable bound on the derivatives, then the series is differentiable. Note that our assumptions do not ensure the pointwise convergence, but if there is no pointwise convergence then the series is zero everywhere so the result still holds. -/ theorem differentiable_tsum' (hu : Summable u) (hg : ∀ n y, HasDerivAt (g n) (g' n y) y) (hg' : ∀ n y, ‖g' n y‖ ≤ u n) : Differentiable 𝕜 fun z => ∑' n, g n z := by simp_rw [hasDerivAt_iff_hasFDerivAt] at hg refine differentiable_tsum hu hg ?_ simpa? says simpa only [ContinuousLinearMap.norm_smulRight_apply, norm_one, one_mul] theorem fderiv_tsum_apply (hu : Summable u) (hf : ∀ n, Differentiable 𝕜 (f n)) (hf' : ∀ n x, ‖fderiv 𝕜 (f n) x‖ ≤ u n) (hf0 : Summable fun n => f n x₀) (x : E) : fderiv 𝕜 (fun y => ∑' n, f n y) x = ∑' n, fderiv 𝕜 (f n) x := (hasFDerivAt_tsum hu (fun n x => (hf n x).hasFDerivAt) hf' hf0 _).fderiv theorem deriv_tsum_apply (hu : Summable u) (hg : ∀ n, Differentiable 𝕜 (g n)) (hg' : ∀ n y, ‖deriv (g n) y‖ ≤ u n) (hg0 : Summable fun n => g n y₀) (y : 𝕜) : deriv (fun z => ∑' n, g n z) y = ∑' n, deriv (g n) y := (hasDerivAt_tsum hu (fun n y => (hg n y).hasDerivAt) hg' hg0 _).deriv theorem fderiv_tsum (hu : Summable u) (hf : ∀ n, Differentiable 𝕜 (f n)) (hf' : ∀ n x, ‖fderiv 𝕜 (f n) x‖ ≤ u n) (hf0 : Summable fun n => f n x₀) : (fderiv 𝕜 fun y => ∑' n, f n y) = fun x => ∑' n, fderiv 𝕜 (f n) x := by ext1 x exact fderiv_tsum_apply hu hf hf' hf0 x theorem deriv_tsum (hu : Summable u) (hg : ∀ n, Differentiable 𝕜 (g n)) (hg' : ∀ n y, ‖deriv (g n) y‖ ≤ u n) (hg0 : Summable fun n => g n y₀) : (deriv fun y => ∑' n, g n y) = fun y => ∑' n, deriv (g n) y := by ext1 x exact deriv_tsum_apply hu hg hg' hg0 x /-! ### Higher smoothness -/
/-- Consider a series of `C^n` functions, with summable uniform bounds on the successive derivatives. Then the iterated derivative of the sum is the sum of the iterated derivative. -/ theorem iteratedFDeriv_tsum (hf : ∀ i, ContDiff 𝕜 N (f i)) (hv : ∀ k : ℕ, (k : ℕ∞) ≤ N → Summable (v k)) (h'f : ∀ (k : ℕ) (i : α) (x : E), (k : ℕ∞) ≤ N → ‖iteratedFDeriv 𝕜 k (f i) x‖ ≤ v k i) {k : ℕ}
Mathlib/Analysis/Calculus/SmoothSeries.lean
185
189
/- Copyright (c) 2022 Wrenna Robson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Wrenna Robson -/ import Mathlib.Topology.MetricSpace.Basic /-! # Infimum separation This file defines the extended infimum separation of a set. This is approximately dual to the diameter of a set, but where the extended diameter of a set is the supremum of the extended distance between elements of the set, the extended infimum separation is the infimum of the (extended) distance between *distinct* elements in the set. We also define the infimum separation as the cast of the extended infimum separation to the reals. This is the infimum of the distance between distinct elements of the set when in a pseudometric space. All lemmas and definitions are in the `Set` namespace to give access to dot notation. ## Main definitions * `Set.einfsep`: Extended infimum separation of a set. * `Set.infsep`: Infimum separation of a set (when in a pseudometric space). -/ variable {α β : Type*} namespace Set section Einfsep open ENNReal open Function /-- The "extended infimum separation" of a set with an edist function. -/ noncomputable def einfsep [EDist α] (s : Set α) : ℝ≥0∞ := ⨅ (x ∈ s) (y ∈ s) (_ : x ≠ y), edist x y section EDist variable [EDist α] {x y : α} {s t : Set α} theorem le_einfsep_iff {d} : d ≤ s.einfsep ↔ ∀ x ∈ s, ∀ y ∈ s, x ≠ y → d ≤ edist x y := by simp_rw [einfsep, le_iInf_iff] theorem einfsep_zero : s.einfsep = 0 ↔ ∀ C > 0, ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ edist x y < C := by simp_rw [einfsep, ← _root_.bot_eq_zero, iInf_eq_bot, iInf_lt_iff, exists_prop] theorem einfsep_pos : 0 < s.einfsep ↔ ∃ C > 0, ∀ x ∈ s, ∀ y ∈ s, x ≠ y → C ≤ edist x y := by rw [pos_iff_ne_zero, Ne, einfsep_zero] simp only [not_forall, not_exists, not_lt, exists_prop, not_and] theorem einfsep_top : s.einfsep = ∞ ↔ ∀ x ∈ s, ∀ y ∈ s, x ≠ y → edist x y = ∞ := by simp_rw [einfsep, iInf_eq_top] theorem einfsep_lt_top : s.einfsep < ∞ ↔ ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ edist x y < ∞ := by simp_rw [einfsep, iInf_lt_iff, exists_prop] theorem einfsep_ne_top : s.einfsep ≠ ∞ ↔ ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ edist x y ≠ ∞ := by simp_rw [← lt_top_iff_ne_top, einfsep_lt_top] theorem einfsep_lt_iff {d} : s.einfsep < d ↔ ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ edist x y < d := by simp_rw [einfsep, iInf_lt_iff, exists_prop] theorem nontrivial_of_einfsep_lt_top (hs : s.einfsep < ∞) : s.Nontrivial := by rcases einfsep_lt_top.1 hs with ⟨_, hx, _, hy, hxy, _⟩ exact ⟨_, hx, _, hy, hxy⟩ theorem nontrivial_of_einfsep_ne_top (hs : s.einfsep ≠ ∞) : s.Nontrivial := nontrivial_of_einfsep_lt_top (lt_top_iff_ne_top.mpr hs) theorem Subsingleton.einfsep (hs : s.Subsingleton) : s.einfsep = ∞ := by rw [einfsep_top] exact fun _ hx _ hy hxy => (hxy <| hs hx hy).elim theorem le_einfsep_image_iff {d} {f : β → α} {s : Set β} : d ≤ einfsep (f '' s) ↔ ∀ x ∈ s, ∀ y ∈ s, f x ≠ f y → d ≤ edist (f x) (f y) := by simp_rw [le_einfsep_iff, forall_mem_image] theorem le_edist_of_le_einfsep {d x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y) (hd : d ≤ s.einfsep) : d ≤ edist x y := le_einfsep_iff.1 hd x hx y hy hxy theorem einfsep_le_edist_of_mem {x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y) : s.einfsep ≤ edist x y := le_edist_of_le_einfsep hx hy hxy le_rfl theorem einfsep_le_of_mem_of_edist_le {d x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y) (hxy' : edist x y ≤ d) : s.einfsep ≤ d := le_trans (einfsep_le_edist_of_mem hx hy hxy) hxy' theorem le_einfsep {d} (h : ∀ x ∈ s, ∀ y ∈ s, x ≠ y → d ≤ edist x y) : d ≤ s.einfsep := le_einfsep_iff.2 h @[simp] theorem einfsep_empty : (∅ : Set α).einfsep = ∞ := subsingleton_empty.einfsep @[simp] theorem einfsep_singleton : ({x} : Set α).einfsep = ∞ := subsingleton_singleton.einfsep theorem einfsep_iUnion_mem_option {ι : Type*} (o : Option ι) (s : ι → Set α) : (⋃ i ∈ o, s i).einfsep = ⨅ i ∈ o, (s i).einfsep := by cases o <;> simp theorem einfsep_anti (hst : s ⊆ t) : t.einfsep ≤ s.einfsep := le_einfsep fun _x hx _y hy => einfsep_le_edist_of_mem (hst hx) (hst hy) theorem einfsep_insert_le : (insert x s).einfsep ≤ ⨅ (y ∈ s) (_ : x ≠ y), edist x y := by simp_rw [le_iInf_iff] exact fun _ hy hxy => einfsep_le_edist_of_mem (mem_insert _ _) (mem_insert_of_mem _ hy) hxy theorem le_einfsep_pair : edist x y ⊓ edist y x ≤ ({x, y} : Set α).einfsep := by simp_rw [le_einfsep_iff, inf_le_iff, mem_insert_iff, mem_singleton_iff] rintro a (rfl | rfl) b (rfl | rfl) hab <;> (try simp only [le_refl, true_or, or_true]) <;> contradiction theorem einfsep_pair_le_left (hxy : x ≠ y) : ({x, y} : Set α).einfsep ≤ edist x y := einfsep_le_edist_of_mem (mem_insert _ _) (mem_insert_of_mem _ (mem_singleton _)) hxy theorem einfsep_pair_le_right (hxy : x ≠ y) : ({x, y} : Set α).einfsep ≤ edist y x := by rw [pair_comm]; exact einfsep_pair_le_left hxy.symm theorem einfsep_pair_eq_inf (hxy : x ≠ y) : ({x, y} : Set α).einfsep = edist x y ⊓ edist y x := le_antisymm (le_inf (einfsep_pair_le_left hxy) (einfsep_pair_le_right hxy)) le_einfsep_pair theorem einfsep_eq_iInf : s.einfsep = ⨅ d : s.offDiag, (uncurry edist) (d : α × α) := by refine eq_of_forall_le_iff fun _ => ?_ simp_rw [le_einfsep_iff, le_iInf_iff, imp_forall_iff, SetCoe.forall, mem_offDiag, Prod.forall, uncurry_apply_pair, and_imp] theorem einfsep_of_fintype [DecidableEq α] [Fintype s] : s.einfsep = s.offDiag.toFinset.inf (uncurry edist) := by refine eq_of_forall_le_iff fun _ => ?_ simp_rw [le_einfsep_iff, imp_forall_iff, Finset.le_inf_iff, mem_toFinset, mem_offDiag, Prod.forall, uncurry_apply_pair, and_imp] theorem Finite.einfsep (hs : s.Finite) : s.einfsep = hs.offDiag.toFinset.inf (uncurry edist) := by refine eq_of_forall_le_iff fun _ => ?_ simp_rw [le_einfsep_iff, imp_forall_iff, Finset.le_inf_iff, Finite.mem_toFinset, mem_offDiag, Prod.forall, uncurry_apply_pair, and_imp] theorem Finset.coe_einfsep [DecidableEq α] {s : Finset α} : (s : Set α).einfsep = s.offDiag.inf (uncurry edist) := by simp_rw [einfsep_of_fintype, ← Finset.coe_offDiag, Finset.toFinset_coe] theorem Nontrivial.einfsep_exists_of_finite [Finite s] (hs : s.Nontrivial) : ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ s.einfsep = edist x y := by classical cases nonempty_fintype s simp_rw [einfsep_of_fintype] rcases Finset.exists_mem_eq_inf s.offDiag.toFinset (by simpa) (uncurry edist) with ⟨w, hxy, hed⟩ simp_rw [mem_toFinset] at hxy exact ⟨w.fst, hxy.1, w.snd, hxy.2.1, hxy.2.2, hed⟩ theorem Finite.einfsep_exists_of_nontrivial (hsf : s.Finite) (hs : s.Nontrivial) : ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ s.einfsep = edist x y := letI := hsf.fintype hs.einfsep_exists_of_finite end EDist section PseudoEMetricSpace variable [PseudoEMetricSpace α] {x y z : α} {s : Set α} theorem einfsep_pair (hxy : x ≠ y) : ({x, y} : Set α).einfsep = edist x y := by nth_rw 1 [← min_self (edist x y)] convert einfsep_pair_eq_inf hxy using 2 rw [edist_comm] theorem einfsep_insert : einfsep (insert x s) = (⨅ (y ∈ s) (_ : x ≠ y), edist x y) ⊓ s.einfsep := by refine le_antisymm (le_min einfsep_insert_le (einfsep_anti (subset_insert _ _))) ?_ simp_rw [le_einfsep_iff, inf_le_iff, mem_insert_iff] rintro y (rfl | hy) z (rfl | hz) hyz · exact False.elim (hyz rfl) · exact Or.inl (iInf_le_of_le _ (iInf₂_le hz hyz)) · rw [edist_comm] exact Or.inl (iInf_le_of_le _ (iInf₂_le hy hyz.symm)) · exact Or.inr (einfsep_le_edist_of_mem hy hz hyz) theorem einfsep_triple (hxy : x ≠ y) (hyz : y ≠ z) (hxz : x ≠ z) : einfsep ({x, y, z} : Set α) = edist x y ⊓ edist x z ⊓ edist y z := by simp_rw [einfsep_insert, iInf_insert, iInf_singleton, einfsep_singleton, inf_top_eq, ciInf_pos hxy, ciInf_pos hyz, ciInf_pos hxz] theorem le_einfsep_pi_of_le {π : β → Type*} [Fintype β] [∀ b, PseudoEMetricSpace (π b)] {s : ∀ b : β, Set (π b)} {c : ℝ≥0∞} (h : ∀ b, c ≤ einfsep (s b)) : c ≤ einfsep (Set.pi univ s) := by refine le_einfsep fun x hx y hy hxy => ?_ rw [mem_univ_pi] at hx hy rcases Function.ne_iff.mp hxy with ⟨i, hi⟩ exact le_trans (le_einfsep_iff.1 (h i) _ (hx _) _ (hy _) hi) (edist_le_pi_edist _ _ i) end PseudoEMetricSpace section PseudoMetricSpace variable [PseudoMetricSpace α] {s : Set α} theorem subsingleton_of_einfsep_eq_top (hs : s.einfsep = ∞) : s.Subsingleton := by rw [einfsep_top] at hs exact fun _ hx _ hy => of_not_not fun hxy => edist_ne_top _ _ (hs _ hx _ hy hxy) theorem einfsep_eq_top_iff : s.einfsep = ∞ ↔ s.Subsingleton := ⟨subsingleton_of_einfsep_eq_top, Subsingleton.einfsep⟩ theorem Nontrivial.einfsep_ne_top (hs : s.Nontrivial) : s.einfsep ≠ ∞ := by contrapose! hs rw [not_nontrivial_iff] exact subsingleton_of_einfsep_eq_top hs theorem Nontrivial.einfsep_lt_top (hs : s.Nontrivial) : s.einfsep < ∞ := by rw [lt_top_iff_ne_top] exact hs.einfsep_ne_top theorem einfsep_lt_top_iff : s.einfsep < ∞ ↔ s.Nontrivial := ⟨nontrivial_of_einfsep_lt_top, Nontrivial.einfsep_lt_top⟩ theorem einfsep_ne_top_iff : s.einfsep ≠ ∞ ↔ s.Nontrivial := ⟨nontrivial_of_einfsep_ne_top, Nontrivial.einfsep_ne_top⟩ theorem le_einfsep_of_forall_dist_le {d} (h : ∀ x ∈ s, ∀ y ∈ s, x ≠ y → d ≤ dist x y) : ENNReal.ofReal d ≤ s.einfsep := le_einfsep fun x hx y hy hxy => (edist_dist x y).symm ▸ ENNReal.ofReal_le_ofReal (h x hx y hy hxy) end PseudoMetricSpace section EMetricSpace variable [EMetricSpace α] {s : Set α} theorem einfsep_pos_of_finite [Finite s] : 0 < s.einfsep := by cases nonempty_fintype s by_cases hs : s.Nontrivial · rcases hs.einfsep_exists_of_finite with ⟨x, _hx, y, _hy, hxy, hxy'⟩ exact hxy'.symm ▸ edist_pos.2 hxy · rw [not_nontrivial_iff] at hs exact hs.einfsep.symm ▸ WithTop.top_pos theorem relatively_discrete_of_finite [Finite s] : ∃ C > 0, ∀ x ∈ s, ∀ y ∈ s, x ≠ y → C ≤ edist x y := by rw [← einfsep_pos] exact einfsep_pos_of_finite theorem Finite.einfsep_pos (hs : s.Finite) : 0 < s.einfsep := letI := hs.fintype einfsep_pos_of_finite theorem Finite.relatively_discrete (hs : s.Finite) : ∃ C > 0, ∀ x ∈ s, ∀ y ∈ s, x ≠ y → C ≤ edist x y := letI := hs.fintype relatively_discrete_of_finite end EMetricSpace end Einfsep section Infsep open ENNReal open Set Function /-- The "infimum separation" of a set with an edist function. -/ noncomputable def infsep [EDist α] (s : Set α) : ℝ := ENNReal.toReal s.einfsep section EDist variable [EDist α] {x y : α} {s : Set α} theorem infsep_zero : s.infsep = 0 ↔ s.einfsep = 0 ∨ s.einfsep = ∞ := by rw [infsep, ENNReal.toReal_eq_zero_iff] theorem infsep_nonneg : 0 ≤ s.infsep := ENNReal.toReal_nonneg theorem infsep_pos : 0 < s.infsep ↔ 0 < s.einfsep ∧ s.einfsep < ∞ := by simp_rw [infsep, ENNReal.toReal_pos_iff] theorem Subsingleton.infsep_zero (hs : s.Subsingleton) : s.infsep = 0 := Set.infsep_zero.mpr <| Or.inr hs.einfsep theorem nontrivial_of_infsep_pos (hs : 0 < s.infsep) : s.Nontrivial := by contrapose hs rw [not_nontrivial_iff] at hs exact hs.infsep_zero ▸ lt_irrefl _ theorem infsep_empty : (∅ : Set α).infsep = 0 := subsingleton_empty.infsep_zero theorem infsep_singleton : ({x} : Set α).infsep = 0 := subsingleton_singleton.infsep_zero theorem infsep_pair_le_toReal_inf (hxy : x ≠ y) : ({x, y} : Set α).infsep ≤ (edist x y ⊓ edist y x).toReal := by simp_rw [infsep, einfsep_pair_eq_inf hxy] simp end EDist section PseudoEMetricSpace variable [PseudoEMetricSpace α] {x y : α} theorem infsep_pair_eq_toReal : ({x, y} : Set α).infsep = (edist x y).toReal := by by_cases hxy : x = y · rw [hxy] simp only [infsep_singleton, pair_eq_singleton, edist_self, ENNReal.toReal_zero] · rw [infsep, einfsep_pair hxy] end PseudoEMetricSpace section PseudoMetricSpace variable [PseudoMetricSpace α] {x y z : α} {s t : Set α} theorem Nontrivial.le_infsep_iff {d} (hs : s.Nontrivial) : d ≤ s.infsep ↔ ∀ x ∈ s, ∀ y ∈ s, x ≠ y → d ≤ dist x y := by simp_rw [infsep, ← ENNReal.ofReal_le_iff_le_toReal hs.einfsep_ne_top, le_einfsep_iff, edist_dist, ENNReal.ofReal_le_ofReal_iff dist_nonneg] theorem Nontrivial.infsep_lt_iff {d} (hs : s.Nontrivial) : s.infsep < d ↔ ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ dist x y < d := by rw [← not_iff_not] push_neg exact hs.le_infsep_iff theorem Nontrivial.le_infsep {d} (hs : s.Nontrivial) (h : ∀ x ∈ s, ∀ y ∈ s, x ≠ y → d ≤ dist x y) : d ≤ s.infsep := hs.le_infsep_iff.2 h theorem le_edist_of_le_infsep {d x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y) (hd : d ≤ s.infsep) : d ≤ dist x y := by by_cases hs : s.Nontrivial · exact hs.le_infsep_iff.1 hd x hx y hy hxy · rw [not_nontrivial_iff] at hs rw [hs.infsep_zero] at hd exact le_trans hd dist_nonneg theorem infsep_le_dist_of_mem (hx : x ∈ s) (hy : y ∈ s) (hxy : x ≠ y) : s.infsep ≤ dist x y := le_edist_of_le_infsep hx hy hxy le_rfl theorem infsep_le_of_mem_of_edist_le {d x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y) (hxy' : dist x y ≤ d) : s.infsep ≤ d := le_trans (infsep_le_dist_of_mem hx hy hxy) hxy' theorem infsep_pair : ({x, y} : Set α).infsep = dist x y := by rw [infsep_pair_eq_toReal, edist_dist] exact ENNReal.toReal_ofReal dist_nonneg theorem infsep_triple (hxy : x ≠ y) (hyz : y ≠ z) (hxz : x ≠ z) : ({x, y, z} : Set α).infsep = dist x y ⊓ dist x z ⊓ dist y z := by simp only [infsep, einfsep_triple hxy hyz hxz, ENNReal.toReal_inf, edist_ne_top x y, edist_ne_top x z, edist_ne_top y z, dist_edist, Ne, inf_eq_top_iff, and_self_iff, not_false_iff] theorem Nontrivial.infsep_anti (hs : s.Nontrivial) (hst : s ⊆ t) : t.infsep ≤ s.infsep := ENNReal.toReal_mono hs.einfsep_ne_top (einfsep_anti hst) theorem infsep_eq_iInf [Decidable s.Nontrivial] : s.infsep = if s.Nontrivial then ⨅ d : s.offDiag, (uncurry dist) (d : α × α) else 0 := by split_ifs with hs · have hb : BddBelow (uncurry dist '' s.offDiag) := by refine ⟨0, fun d h => ?_⟩ simp_rw [mem_image, Prod.exists, uncurry_apply_pair] at h rcases h with ⟨_, _, _, rfl⟩ exact dist_nonneg refine eq_of_forall_le_iff fun _ => ?_ simp_rw [hs.le_infsep_iff, le_ciInf_set_iff (offDiag_nonempty.mpr hs) hb, imp_forall_iff, mem_offDiag, Prod.forall, uncurry_apply_pair, and_imp] · exact (not_nontrivial_iff.mp hs).infsep_zero theorem Nontrivial.infsep_eq_iInf (hs : s.Nontrivial) : s.infsep = ⨅ d : s.offDiag, (uncurry dist) (d : α × α) := by classical rw [Set.infsep_eq_iInf, if_pos hs] theorem infsep_of_fintype [Decidable s.Nontrivial] [DecidableEq α] [Fintype s] : s.infsep = if hs : s.Nontrivial then s.offDiag.toFinset.inf' (by simpa) (uncurry dist) else 0 := by split_ifs with hs · refine eq_of_forall_le_iff fun _ => ?_ simp_rw [hs.le_infsep_iff, imp_forall_iff, Finset.le_inf'_iff, mem_toFinset, mem_offDiag, Prod.forall, uncurry_apply_pair, and_imp] · rw [not_nontrivial_iff] at hs exact hs.infsep_zero theorem Nontrivial.infsep_of_fintype [DecidableEq α] [Fintype s] (hs : s.Nontrivial) : s.infsep = s.offDiag.toFinset.inf' (by simpa) (uncurry dist) := by classical rw [Set.infsep_of_fintype, dif_pos hs] theorem Finite.infsep [Decidable s.Nontrivial] (hsf : s.Finite) : s.infsep = if hs : s.Nontrivial then hsf.offDiag.toFinset.inf' (by simpa) (uncurry dist) else 0 := by split_ifs with hs · refine eq_of_forall_le_iff fun _ => ?_ simp_rw [hs.le_infsep_iff, imp_forall_iff, Finset.le_inf'_iff, Finite.mem_toFinset, mem_offDiag, Prod.forall, uncurry_apply_pair, and_imp] · rw [not_nontrivial_iff] at hs exact hs.infsep_zero theorem Finite.infsep_of_nontrivial (hsf : s.Finite) (hs : s.Nontrivial) : s.infsep = hsf.offDiag.toFinset.inf' (by simpa) (uncurry dist) := by classical simp_rw [hsf.infsep, dif_pos hs] theorem _root_.Finset.coe_infsep [DecidableEq α] (s : Finset α) : (s : Set α).infsep = if hs : s.offDiag.Nonempty then s.offDiag.inf' hs (uncurry dist) else 0 := by have H : (s : Set α).Nontrivial ↔ s.offDiag.Nonempty := by rw [← Set.offDiag_nonempty, ← Finset.coe_offDiag, Finset.coe_nonempty] split_ifs with hs · simp_rw [(H.mpr hs).infsep_of_fintype, ← Finset.coe_offDiag, Finset.toFinset_coe] · exact (not_nontrivial_iff.mp (H.mp.mt hs)).infsep_zero theorem _root_.Finset.coe_infsep_of_offDiag_nonempty [DecidableEq α] {s : Finset α} (hs : s.offDiag.Nonempty) : (s : Set α).infsep = s.offDiag.inf' hs (uncurry dist) := by rw [Finset.coe_infsep, dif_pos hs] theorem _root_.Finset.coe_infsep_of_offDiag_empty [DecidableEq α] {s : Finset α} (hs : s.offDiag = ∅) : (s : Set α).infsep = 0 := by rw [← Finset.not_nonempty_iff_eq_empty] at hs rw [Finset.coe_infsep, dif_neg hs] theorem Nontrivial.infsep_exists_of_finite [Finite s] (hs : s.Nontrivial) : ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ s.infsep = dist x y := by classical cases nonempty_fintype s simp_rw [hs.infsep_of_fintype] rcases Finset.exists_mem_eq_inf' (s := s.offDiag.toFinset) (by simpa) (uncurry dist) with ⟨w, hxy, hed⟩ simp_rw [mem_toFinset] at hxy exact ⟨w.fst, hxy.1, w.snd, hxy.2.1, hxy.2.2, hed⟩ theorem Finite.infsep_exists_of_nontrivial (hsf : s.Finite) (hs : s.Nontrivial) : ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ s.infsep = dist x y := letI := hsf.fintype hs.infsep_exists_of_finite end PseudoMetricSpace section MetricSpace variable [MetricSpace α] {s : Set α}
theorem infsep_zero_iff_subsingleton_of_finite [Finite s] : s.infsep = 0 ↔ s.Subsingleton := by rw [infsep_zero, einfsep_eq_top_iff, or_iff_right_iff_imp]
Mathlib/Topology/MetricSpace/Infsep.lean
453
455
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Patrick Massot, Sébastien Gouëzel -/ import Mathlib.MeasureTheory.Integral.IntervalIntegral.Basic import Mathlib.MeasureTheory.Integral.IntervalIntegral.FundThmCalculus import Mathlib.MeasureTheory.Integral.IntervalIntegral.IntegrationByParts deprecated_module (since := "2025-04-13")
Mathlib/MeasureTheory/Integral/IntervalIntegral.lean
1,124
1,132
/- Copyright (c) 2022 Julian Kuelshammer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Julian Kuelshammer -/ import Mathlib.Algebra.BigOperators.Fin import Mathlib.Algebra.BigOperators.NatAntidiagonal import Mathlib.Data.Nat.Choose.Central import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.GCongr import Mathlib.Tactic.Positivity /-! # Catalan numbers The Catalan numbers (http://oeis.org/A000108) are probably the most ubiquitous sequence of integers in mathematics. They enumerate several important objects like binary trees, Dyck paths, and triangulations of convex polygons. ## Main definitions * `catalan n`: the `n`th Catalan number, defined recursively as `catalan (n + 1) = ∑ i : Fin n.succ, catalan i * catalan (n - i)`. ## Main results * `catalan_eq_centralBinom_div`: The explicit formula for the Catalan number using the central binomial coefficient, `catalan n = Nat.centralBinom n / (n + 1)`. * `treesOfNumNodesEq_card_eq_catalan`: The number of binary trees with `n` internal nodes is `catalan n` ## Implementation details The proof of `catalan_eq_centralBinom_div` follows https://math.stackexchange.com/questions/3304415 ## TODO * Prove that the Catalan numbers enumerate many interesting objects. * Provide the many variants of Catalan numbers, e.g. associated to complex reflection groups, Fuss-Catalan, etc. -/ open Finset open Finset.antidiagonal (fst_le snd_le) /-- The recursive definition of the sequence of Catalan numbers: `catalan (n + 1) = ∑ i : Fin n.succ, catalan i * catalan (n - i)` -/ def catalan : ℕ → ℕ | 0 => 1 | n + 1 => ∑ i : Fin n.succ, catalan i * catalan (n - i) @[simp] theorem catalan_zero : catalan 0 = 1 := by rw [catalan] theorem catalan_succ (n : ℕ) : catalan (n + 1) = ∑ i : Fin n.succ, catalan i * catalan (n - i) := by rw [catalan] theorem catalan_succ' (n : ℕ) : catalan (n + 1) = ∑ ij ∈ antidiagonal n, catalan ij.1 * catalan ij.2 := by rw [catalan_succ, Nat.sum_antidiagonal_eq_sum_range_succ (fun x y => catalan x * catalan y) n, sum_range] @[simp] theorem catalan_one : catalan 1 = 1 := by simp [catalan_succ] /-- A helper sequence that can be used to prove the equality of the recursive and the explicit definition using a telescoping sum argument. -/ private def gosperCatalan (n j : ℕ) : ℚ := Nat.centralBinom j * Nat.centralBinom (n - j) * (2 * j - n) / (2 * n * (n + 1)) private theorem gosper_trick {n i : ℕ} (h : i ≤ n) : gosperCatalan (n + 1) (i + 1) - gosperCatalan (n + 1) i = Nat.centralBinom i / (i + 1) * Nat.centralBinom (n - i) / (n - i + 1) := by have l₁ : (i : ℚ) + 1 ≠ 0 := by norm_cast have l₂ : (n : ℚ) - i + 1 ≠ 0 := by norm_cast have h₁ := (mul_div_cancel_left₀ (↑(Nat.centralBinom (i + 1))) l₁).symm have h₂ := (mul_div_cancel_left₀ (↑(Nat.centralBinom (n - i + 1))) l₂).symm have h₃ : ((i : ℚ) + 1) * (i + 1).centralBinom = 2 * (2 * i + 1) * i.centralBinom := mod_cast Nat.succ_mul_centralBinom_succ i have h₄ : ((n : ℚ) - i + 1) * (n - i + 1).centralBinom = 2 * (2 * (n - i) + 1) * (n - i).centralBinom := mod_cast Nat.succ_mul_centralBinom_succ (n - i) simp only [gosperCatalan] push_cast rw [show n + 1 - i = n - i + 1 by rw [Nat.add_comm (n - i) 1, ← (Nat.add_sub_assoc h 1), add_comm]] rw [h₁, h₂, h₃, h₄] field_simp ring private theorem gosper_catalan_sub_eq_central_binom_div (n : ℕ) : gosperCatalan (n + 1) (n + 1) - gosperCatalan (n + 1) 0 = Nat.centralBinom (n + 1) / (n + 2) := by have : (n : ℚ) + 1 ≠ 0 := by norm_cast have : (n : ℚ) + 1 + 1 ≠ 0 := by norm_cast have h : (n : ℚ) + 2 ≠ 0 := by norm_cast simp only [gosperCatalan, Nat.sub_zero, Nat.centralBinom_zero, Nat.sub_self] field_simp ring theorem catalan_eq_centralBinom_div (n : ℕ) : catalan n = n.centralBinom / (n + 1) := by
suffices (catalan n : ℚ) = Nat.centralBinom n / (n + 1) by have h := Nat.succ_dvd_centralBinom n exact mod_cast this induction n using Nat.caseStrongRecOn with | zero => simp | ind d hd => simp_rw [catalan_succ, Nat.cast_sum, Nat.cast_mul] trans (∑ i : Fin d.succ, Nat.centralBinom i / (i + 1) *
Mathlib/Combinatorics/Enumerative/Catalan.lean
107
114
/- Copyright (c) 2018 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Johan Commelin, Bhavik Mehta -/ import Mathlib.CategoryTheory.Iso import Mathlib.CategoryTheory.Functor.Category import Mathlib.CategoryTheory.EqToHom import Mathlib.CategoryTheory.Products.Unitor /-! # Comma categories A comma category is a construction in category theory, which builds a category out of two functors with a common codomain. Specifically, for functors `L : A ⥤ T` and `R : B ⥤ T`, an object in `Comma L R` is a morphism `hom : L.obj left ⟶ R.obj right` for some objects `left : A` and `right : B`, and a morphism in `Comma L R` between `hom : L.obj left ⟶ R.obj right` and `hom' : L.obj left' ⟶ R.obj right'` is a commutative square ``` L.obj left ⟶ L.obj left' | | hom | | hom' ↓ ↓ R.obj right ⟶ R.obj right', ``` where the top and bottom morphism come from morphisms `left ⟶ left'` and `right ⟶ right'`, respectively. ## Main definitions * `Comma L R`: the comma category of the functors `L` and `R`. * `Over X`: the over category of the object `X` (developed in `Over.lean`). * `Under X`: the under category of the object `X` (also developed in `Over.lean`). * `Arrow T`: the arrow category of the category `T` (developed in `Arrow.lean`). ## References * <https://ncatlab.org/nlab/show/comma+category> ## Tags comma, slice, coslice, over, under, arrow -/ namespace CategoryTheory open Category -- declare the `v`'s first; see `CategoryTheory.Category` for an explanation universe v₁ v₂ v₃ v₄ v₅ v₆ u₁ u₂ u₃ u₄ u₅ u₆ variable {A : Type u₁} [Category.{v₁} A] variable {B : Type u₂} [Category.{v₂} B] variable {T : Type u₃} [Category.{v₃} T] variable {A' : Type u₄} [Category.{v₄} A'] variable {B' : Type u₅} [Category.{v₅} B'] variable {T' : Type u₆} [Category.{v₆} T'] /-- The objects of the comma category are triples of an object `left : A`, an object `right : B` and a morphism `hom : L.obj left ⟶ R.obj right`. -/ structure Comma (L : A ⥤ T) (R : B ⥤ T) : Type max u₁ u₂ v₃ where /-- The left subobject -/ left : A /-- The right subobject -/ right : B /-- A morphism from `L.obj left` to `R.obj right` -/ hom : L.obj left ⟶ R.obj right -- Satisfying the inhabited linter instance Comma.inhabited [Inhabited T] : Inhabited (Comma (𝟭 T) (𝟭 T)) where default := { left := default right := default hom := 𝟙 default } variable {L : A ⥤ T} {R : B ⥤ T} /-- A morphism between two objects in the comma category is a commutative square connecting the morphisms coming from the two objects using morphisms in the image of the functors `L` and `R`. -/ @[ext] structure CommaMorphism (X Y : Comma L R) where /-- Morphism on left objects -/ left : X.left ⟶ Y.left /-- Morphism on right objects -/ right : X.right ⟶ Y.right w : L.map left ≫ Y.hom = X.hom ≫ R.map right := by aesop_cat -- Satisfying the inhabited linter instance CommaMorphism.inhabited [Inhabited (Comma L R)] : Inhabited (CommaMorphism (default : Comma L R) default) := ⟨{ left := 𝟙 _, right := 𝟙 _}⟩ attribute [reassoc (attr := simp)] CommaMorphism.w instance commaCategory : Category (Comma L R) where Hom X Y := CommaMorphism X Y id X := { left := 𝟙 X.left right := 𝟙 X.right } comp f g := { left := f.left ≫ g.left right := f.right ≫ g.right } namespace Comma section variable {X Y Z : Comma L R} {f : X ⟶ Y} {g : Y ⟶ Z} @[ext] lemma hom_ext (f g : X ⟶ Y) (h₁ : f.left = g.left) (h₂ : f.right = g.right) : f = g := CommaMorphism.ext h₁ h₂ @[simp] theorem id_left : (𝟙 X : CommaMorphism X X).left = 𝟙 X.left := rfl @[simp] theorem id_right : (𝟙 X : CommaMorphism X X).right = 𝟙 X.right := rfl @[simp] theorem comp_left : (f ≫ g).left = f.left ≫ g.left := rfl @[simp] theorem comp_right : (f ≫ g).right = f.right ≫ g.right := rfl end variable (L) (R) /-- The functor sending an object `X` in the comma category to `X.left`. -/ @[simps] def fst : Comma L R ⥤ A where obj X := X.left map f := f.left /-- The functor sending an object `X` in the comma category to `X.right`. -/ @[simps] def snd : Comma L R ⥤ B where obj X := X.right map f := f.right /-- We can interpret the commutative square constituting a morphism in the comma category as a natural transformation between the functors `fst ⋙ L` and `snd ⋙ R` from the comma category to `T`, where the components are given by the morphism that constitutes an object of the comma category. -/ @[simps] def natTrans : fst L R ⋙ L ⟶ snd L R ⋙ R where app X := X.hom @[simp] theorem eqToHom_left (X Y : Comma L R) (H : X = Y) : CommaMorphism.left (eqToHom H) = eqToHom (by cases H; rfl) := by cases H rfl @[simp] theorem eqToHom_right (X Y : Comma L R) (H : X = Y) : CommaMorphism.right (eqToHom H) = eqToHom (by cases H; rfl) := by
cases H rfl section
Mathlib/CategoryTheory/Comma/Basic.lean
166
169
/- Copyright (c) 2020 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.Algebra.Group.TypeTags.Finite import Mathlib.Algebra.MonoidAlgebra.Basic import Mathlib.LinearAlgebra.Basis.VectorSpace import Mathlib.RingTheory.SimpleModule.Basic /-! # Maschke's theorem We prove **Maschke's theorem** for finite groups, in the formulation that every submodule of a `k[G]` module has a complement, when `k` is a field with `Fintype.card G` invertible in `k`. We do the core computation in greater generality. For any commutative ring `k` in which `Fintype.card G` is invertible, and a `k[G]`-linear map `i : V → W` which admits a `k`-linear retraction `π`, we produce a `k[G]`-linear retraction by taking the average over `G` of the conjugates of `π`. ## Implementation Notes * These results assume `IsUnit (Fintype.card G : k)` which is equivalent to the more familiar `¬(ringChar k ∣ Fintype.card G)`. ## Future work It's not so far to give the usual statement, that every finite dimensional representation of a finite group is semisimple (i.e. a direct sum of irreducibles). -/ universe u v w noncomputable section open Module MonoidAlgebra /-! We now do the key calculation in Maschke's theorem. Given `V → W`, an inclusion of `k[G]` modules, assume we have some retraction `π` (i.e. `∀ v, π (i v) = v`), just as a `k`-linear map. (When `k` is a field, this will be available cheaply, by choosing a basis.) We now construct a retraction of the inclusion as a `k[G]`-linear map, by the formula $$ \frac{1}{|G|} \sum_{g \in G} g⁻¹ • π(g • -). $$ -/ namespace LinearMap -- At first we work with any `[CommRing k]`, and add the assumption that -- `IsUnit (Fintype.card G : k)` when it is required. variable {k : Type u} [CommRing k] {G : Type u} [Group G] variable {V : Type v} [AddCommGroup V] [Module k V] [Module (MonoidAlgebra k G) V] variable [IsScalarTower k (MonoidAlgebra k G) V] variable {W : Type w} [AddCommGroup W] [Module k W] [Module (MonoidAlgebra k G) W] variable [IsScalarTower k (MonoidAlgebra k G) W] variable (π : W →ₗ[k] V) /-- We define the conjugate of `π` by `g`, as a `k`-linear map. -/ def conjugate (g : G) : W →ₗ[k] V := GroupSMul.linearMap k V g⁻¹ ∘ₗ π ∘ₗ GroupSMul.linearMap k W g theorem conjugate_apply (g : G) (v : W) : π.conjugate g v = MonoidAlgebra.single g⁻¹ (1 : k) • π (MonoidAlgebra.single g (1 : k) • v) := rfl variable (i : V →ₗ[MonoidAlgebra k G] W) section theorem conjugate_i (h : ∀ v : V, π (i v) = v) (g : G) (v : V) : (conjugate π g : W → V) (i v) = v := by rw [conjugate_apply, ← i.map_smul, h, ← mul_smul, single_mul_single, mul_one, inv_mul_cancel,
← one_def, one_smul] end
Mathlib/RepresentationTheory/Maschke.lean
81
83
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Ashvni Narayanan -/ import Mathlib.FieldTheory.RatFunc.Degree import Mathlib.RingTheory.DedekindDomain.IntegralClosure import Mathlib.RingTheory.IntegralClosure.IntegrallyClosed import Mathlib.Topology.Algebra.Valued.ValuedField /-! # Function fields This file defines a function field and the ring of integers corresponding to it. ## Main definitions - `FunctionField Fq F` states that `F` is a function field over the (finite) field `Fq`, i.e. it is a finite extension of the field of rational functions in one variable over `Fq`. - `FunctionField.ringOfIntegers` defines the ring of integers corresponding to a function field as the integral closure of `Fq[X]` in the function field. - `FunctionField.inftyValuation` : The place at infinity on `Fq(t)` is the nonarchimedean valuation on `Fq(t)` with uniformizer `1/t`. - `FunctionField.FqtInfty` : The completion `Fq((t⁻¹))` of `Fq(t)` with respect to the valuation at infinity. ## Implementation notes The definitions that involve a field of fractions choose a canonical field of fractions, but are independent of that choice. We also omit assumptions like `Finite Fq` or `IsScalarTower Fq[X] (FractionRing Fq[X]) F` in definitions, adding them back in lemmas when they are needed. ## References * [D. Marcus, *Number Fields*][marcus1977number] * [J.W.S. Cassels, A. Fröhlich, *Algebraic Number Theory*][cassels1967algebraic] * [P. Samuel, *Algebraic Theory of Numbers*][samuel1967] ## Tags function field, ring of integers -/ noncomputable section open scoped nonZeroDivisors Polynomial Multiplicative variable (Fq F : Type*) [Field Fq] [Field F] /-- `F` is a function field over the finite field `Fq` if it is a finite extension of the field of rational functions in one variable over `Fq`. Note that `F` can be a function field over multiple, non-isomorphic, `Fq`. -/ abbrev FunctionField [Algebra (RatFunc Fq) F] : Prop := FiniteDimensional (RatFunc Fq) F /-- `F` is a function field over `Fq` iff it is a finite extension of `Fq(t)`. -/ theorem functionField_iff (Fqt : Type*) [Field Fqt] [Algebra Fq[X] Fqt] [IsFractionRing Fq[X] Fqt] [Algebra (RatFunc Fq) F] [Algebra Fqt F] [Algebra Fq[X] F] [IsScalarTower Fq[X] Fqt F] [IsScalarTower Fq[X] (RatFunc Fq) F] : FunctionField Fq F ↔ FiniteDimensional Fqt F := by let e := IsLocalization.algEquiv Fq[X]⁰ (RatFunc Fq) Fqt have : ∀ (c) (x : F), e c • x = c • x := by intro c x rw [Algebra.smul_def, Algebra.smul_def] congr refine congr_fun (f := fun c => algebraMap Fqt F (e c)) ?_ c refine IsLocalization.ext (nonZeroDivisors Fq[X]) _ _ ?_ ?_ ?_ ?_ ?_ <;> intros <;> simp only [map_one, map_mul, AlgEquiv.commutes, ← IsScalarTower.algebraMap_apply] constructor <;> intro h · let b := Module.finBasis (RatFunc Fq) F exact FiniteDimensional.of_fintype_basis (b.mapCoeffs e this) · let b := Module.finBasis Fqt F refine FiniteDimensional.of_fintype_basis (b.mapCoeffs e.symm ?_) intro c x; convert (this (e.symm c) x).symm; simp only [e.apply_symm_apply] namespace FunctionField theorem algebraMap_injective [Algebra Fq[X] F] [Algebra (RatFunc Fq) F] [IsScalarTower Fq[X] (RatFunc Fq) F] : Function.Injective (⇑(algebraMap Fq[X] F)) := by rw [IsScalarTower.algebraMap_eq Fq[X] (RatFunc Fq) F] exact (algebraMap (RatFunc Fq) F).injective.comp (IsFractionRing.injective Fq[X] (RatFunc Fq)) @[deprecated (since := "2025-03-03")] alias _root_.algebraMap_injective := FunctionField.algebraMap_injective /-- The function field analogue of `NumberField.ringOfIntegers`: `FunctionField.ringOfIntegers Fq Fqt F` is the integral closure of `Fq[t]` in `F`. We don't actually assume `F` is a function field over `Fq` in the definition, only when proving its properties. -/ def ringOfIntegers [Algebra Fq[X] F] := integralClosure Fq[X] F namespace ringOfIntegers variable [Algebra Fq[X] F] instance : IsDomain (ringOfIntegers Fq F) := (ringOfIntegers Fq F).isDomain instance : IsIntegralClosure (ringOfIntegers Fq F) Fq[X] F := integralClosure.isIntegralClosure _ _ variable [Algebra (RatFunc Fq) F] [IsScalarTower Fq[X] (RatFunc Fq) F] theorem algebraMap_injective : Function.Injective (⇑(algebraMap Fq[X] (ringOfIntegers Fq F))) := by have hinj : Function.Injective (⇑(algebraMap Fq[X] F)) := by rw [IsScalarTower.algebraMap_eq Fq[X] (RatFunc Fq) F] exact (algebraMap (RatFunc Fq) F).injective.comp (IsFractionRing.injective Fq[X] (RatFunc Fq)) rw [injective_iff_map_eq_zero (algebraMap Fq[X] (↥(ringOfIntegers Fq F)))] intro p hp rw [← Subtype.coe_inj, Subalgebra.coe_zero] at hp rw [injective_iff_map_eq_zero (algebraMap Fq[X] F)] at hinj exact hinj p hp theorem not_isField : ¬IsField (ringOfIntegers Fq F) := by simpa [← (IsIntegralClosure.isIntegral_algebra Fq[X] F).isField_iff_isField (algebraMap_injective Fq F)] using Polynomial.not_isField Fq variable [FunctionField Fq F] instance : IsFractionRing (ringOfIntegers Fq F) F := integralClosure.isFractionRing_of_finite_extension (RatFunc Fq) F instance : IsIntegrallyClosed (ringOfIntegers Fq F) := integralClosure.isIntegrallyClosedOfFiniteExtension (RatFunc Fq) instance [Algebra.IsSeparable (RatFunc Fq) F] : IsNoetherian Fq[X] (ringOfIntegers Fq F) := IsIntegralClosure.isNoetherian _ (RatFunc Fq) F _ instance [Algebra.IsSeparable (RatFunc Fq) F] : IsDedekindDomain (ringOfIntegers Fq F) := IsIntegralClosure.isDedekindDomain Fq[X] (RatFunc Fq) F _ end ringOfIntegers /-! ### The place at infinity on Fq(t) -/ section InftyValuation variable [DecidableEq (RatFunc Fq)] /-- The valuation at infinity is the nonarchimedean valuation on `Fq(t)` with uniformizer `1/t`. Explicitly, if `f/g ∈ Fq(t)` is a nonzero quotient of polynomials, its valuation at infinity is `Multiplicative.ofAdd(degree(f) - degree(g))`. -/ def inftyValuationDef (r : RatFunc Fq) : ℤₘ₀ := if r = 0 then 0 else ↑(Multiplicative.ofAdd r.intDegree) theorem InftyValuation.map_zero' : inftyValuationDef Fq 0 = 0 := if_pos rfl theorem InftyValuation.map_one' : inftyValuationDef Fq 1 = 1 := (if_neg one_ne_zero).trans <| by rw [RatFunc.intDegree_one, ofAdd_zero, WithZero.coe_one] theorem InftyValuation.map_mul' (x y : RatFunc Fq) : inftyValuationDef Fq (x * y) = inftyValuationDef Fq x * inftyValuationDef Fq y := by rw [inftyValuationDef, inftyValuationDef, inftyValuationDef] by_cases hx : x = 0 · rw [hx, zero_mul, if_pos (Eq.refl _), zero_mul] · by_cases hy : y = 0 · rw [hy, mul_zero, if_pos (Eq.refl _), mul_zero] · rw [if_neg hx, if_neg hy, if_neg (mul_ne_zero hx hy), ← WithZero.coe_mul, WithZero.coe_inj, ← ofAdd_add, RatFunc.intDegree_mul hx hy] theorem InftyValuation.map_add_le_max' (x y : RatFunc Fq) : inftyValuationDef Fq (x + y) ≤ max (inftyValuationDef Fq x) (inftyValuationDef Fq y) := by by_cases hx : x = 0 · rw [hx, zero_add] conv_rhs => rw [inftyValuationDef, if_pos (Eq.refl _)] rw [max_eq_right (WithZero.zero_le (inftyValuationDef Fq y))] · by_cases hy : y = 0 · rw [hy, add_zero] conv_rhs => rw [max_comm, inftyValuationDef, if_pos (Eq.refl _)] rw [max_eq_right (WithZero.zero_le (inftyValuationDef Fq x))] · by_cases hxy : x + y = 0 · rw [inftyValuationDef, if_pos hxy]; exact zero_le' · rw [inftyValuationDef, inftyValuationDef, inftyValuationDef, if_neg hx, if_neg hy, if_neg hxy] rw [le_max_iff, WithZero.coe_le_coe, Multiplicative.ofAdd_le, WithZero.coe_le_coe, Multiplicative.ofAdd_le, ← le_max_iff] exact RatFunc.intDegree_add_le hy hxy @[simp] theorem inftyValuation_of_nonzero {x : RatFunc Fq} (hx : x ≠ 0) : inftyValuationDef Fq x = Multiplicative.ofAdd x.intDegree := by rw [inftyValuationDef, if_neg hx] /-- The valuation at infinity on `Fq(t)`. -/ def inftyValuation : Valuation (RatFunc Fq) ℤₘ₀ where toFun := inftyValuationDef Fq map_zero' := InftyValuation.map_zero' Fq map_one' := InftyValuation.map_one' Fq map_mul' := InftyValuation.map_mul' Fq map_add_le_max' := InftyValuation.map_add_le_max' Fq @[simp] theorem inftyValuation_apply {x : RatFunc Fq} : inftyValuation Fq x = inftyValuationDef Fq x := rfl @[simp] theorem inftyValuation.C {k : Fq} (hk : k ≠ 0) : inftyValuationDef Fq (RatFunc.C k) = Multiplicative.ofAdd (0 : ℤ) := by have hCk : RatFunc.C k ≠ 0 := (map_ne_zero _).mpr hk rw [inftyValuationDef, if_neg hCk, RatFunc.intDegree_C] @[simp] theorem inftyValuation.X : inftyValuationDef Fq RatFunc.X = Multiplicative.ofAdd (1 : ℤ) := by rw [inftyValuationDef, if_neg RatFunc.X_ne_zero, RatFunc.intDegree_X] -- Dropped attribute `@[simp]` due to issue described here: -- https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/.60synthInstance.2EmaxHeartbeats.60.20error.20but.20only.20in.20.60simpNF.60 theorem inftyValuation.polynomial {p : Fq[X]} (hp : p ≠ 0) : inftyValuationDef Fq (algebraMap Fq[X] (RatFunc Fq) p) = Multiplicative.ofAdd (p.natDegree : ℤ) := by have hp' : algebraMap Fq[X] (RatFunc Fq) p ≠ 0 := by simpa rw [inftyValuationDef, if_neg hp', RatFunc.intDegree_polynomial] /-- The valued field `Fq(t)` with the valuation at infinity. -/ def inftyValuedFqt : Valued (RatFunc Fq) ℤₘ₀ := Valued.mk' <| inftyValuation Fq theorem inftyValuedFqt.def {x : RatFunc Fq} : @Valued.v (RatFunc Fq) _ _ _ (inftyValuedFqt Fq) x = inftyValuationDef Fq x := rfl /-- The completion `Fq((t⁻¹))` of `Fq(t)` with respect to the valuation at infinity. -/ def FqtInfty := @UniformSpace.Completion (RatFunc Fq) <| (inftyValuedFqt Fq).toUniformSpace
instance : Field (FqtInfty Fq) := letI := inftyValuedFqt Fq UniformSpace.Completion.instField instance : Inhabited (FqtInfty Fq) := ⟨(0 : FqtInfty Fq)⟩
Mathlib/NumberTheory/FunctionField.lean
232
237
/- 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, Jeremy Avigad -/ import Mathlib.Algebra.Group.Basic import Mathlib.Algebra.Notation.Pi import Mathlib.Data.Set.Lattice import Mathlib.Order.Filter.Defs /-! # Theory of filters on sets A *filter* on a type `α` is a collection of sets of `α` which contains the whole `α`, is upwards-closed, and is stable under intersection. They are mostly used to abstract two related kinds of ideas: * *limits*, including finite or infinite limits of sequences, finite or infinite limits of functions at a point or at infinity, etc... * *things happening eventually*, including things happening for large enough `n : ℕ`, or near enough a point `x`, or for close enough pairs of points, or things happening almost everywhere in the sense of measure theory. Dually, filters can also express the idea of *things happening often*: for arbitrarily large `n`, or at a point in any neighborhood of given a point etc... ## Main definitions In this file, we endow `Filter α` it with a complete lattice structure. This structure is lifted from the lattice structure on `Set (Set X)` using the Galois insertion which maps a filter to its elements in one direction, and an arbitrary set of sets to the smallest filter containing it in the other direction. We also prove `Filter` is a monadic functor, with a push-forward operation `Filter.map` and a pull-back operation `Filter.comap` that form a Galois connections for the order on filters. The examples of filters appearing in the description of the two motivating ideas are: * `(Filter.atTop : Filter ℕ)` : made of sets of `ℕ` containing `{n | n ≥ N}` for some `N` * `𝓝 x` : made of neighborhoods of `x` in a topological space (defined in topology.basic) * `𝓤 X` : made of entourages of a uniform space (those space are generalizations of metric spaces defined in `Mathlib/Topology/UniformSpace/Basic.lean`) * `MeasureTheory.ae` : made of sets whose complement has zero measure with respect to `μ` (defined in `Mathlib/MeasureTheory/OuterMeasure/AE`) The predicate "happening eventually" is `Filter.Eventually`, and "happening often" is `Filter.Frequently`, whose definitions are immediate after `Filter` is defined (but they come rather late in this file in order to immediately relate them to the lattice structure). ## Notations * `∀ᶠ x in f, p x` : `f.Eventually p`; * `∃ᶠ x in f, p x` : `f.Frequently p`; * `f =ᶠ[l] g` : `∀ᶠ x in l, f x = g x`; * `f ≤ᶠ[l] g` : `∀ᶠ x in l, f x ≤ g x`; * `𝓟 s` : `Filter.Principal s`, localized in `Filter`. ## References * [N. Bourbaki, *General Topology*][bourbaki1966] Important note: Bourbaki requires that a filter on `X` cannot contain all sets of `X`, which we do *not* require. This gives `Filter X` better formal properties, in particular a bottom element `⊥` for its lattice structure, at the cost of including the assumption `[NeBot f]` in a number of lemmas and definitions. -/ assert_not_exists OrderedSemiring Fintype open Function Set Order open scoped symmDiff universe u v w x y namespace Filter variable {α : Type u} {f g : Filter α} {s t : Set α} instance inhabitedMem : Inhabited { s : Set α // s ∈ f } := ⟨⟨univ, f.univ_sets⟩⟩ theorem filter_eq_iff : f = g ↔ f.sets = g.sets := ⟨congr_arg _, filter_eq⟩ @[simp] theorem sets_subset_sets : f.sets ⊆ g.sets ↔ g ≤ f := .rfl @[simp] theorem sets_ssubset_sets : f.sets ⊂ g.sets ↔ g < f := .rfl /-- An extensionality lemma that is useful for filters with good lemmas about `sᶜ ∈ f` (e.g., `Filter.comap`, `Filter.coprod`, `Filter.Coprod`, `Filter.cofinite`). -/ protected theorem coext (h : ∀ s, sᶜ ∈ f ↔ sᶜ ∈ g) : f = g := Filter.ext <| compl_surjective.forall.2 h instance : Trans (· ⊇ ·) ((· ∈ ·) : Set α → Filter α → Prop) (· ∈ ·) where trans h₁ h₂ := mem_of_superset h₂ h₁ instance : Trans Membership.mem (· ⊆ ·) (Membership.mem : Filter α → Set α → Prop) where trans h₁ h₂ := mem_of_superset h₁ h₂ @[simp] theorem inter_mem_iff {s t : Set α} : s ∩ t ∈ f ↔ s ∈ f ∧ t ∈ f := ⟨fun h => ⟨mem_of_superset h inter_subset_left, mem_of_superset h inter_subset_right⟩, and_imp.2 inter_mem⟩ theorem diff_mem {s t : Set α} (hs : s ∈ f) (ht : tᶜ ∈ f) : s \ t ∈ f := inter_mem hs ht theorem congr_sets (h : { x | x ∈ s ↔ x ∈ t } ∈ f) : s ∈ f ↔ t ∈ f := ⟨fun hs => mp_mem hs (mem_of_superset h fun _ => Iff.mp), fun hs => mp_mem hs (mem_of_superset h fun _ => Iff.mpr)⟩ lemma copy_eq {S} (hmem : ∀ s, s ∈ S ↔ s ∈ f) : f.copy S hmem = f := Filter.ext hmem /-- Weaker version of `Filter.biInter_mem` that assumes `Subsingleton β` rather than `Finite β`. -/ theorem biInter_mem' {β : Type v} {s : β → Set α} {is : Set β} (hf : is.Subsingleton) : (⋂ i ∈ is, s i) ∈ f ↔ ∀ i ∈ is, s i ∈ f := by apply Subsingleton.induction_on hf <;> simp /-- Weaker version of `Filter.iInter_mem` that assumes `Subsingleton β` rather than `Finite β`. -/ theorem iInter_mem' {β : Sort v} {s : β → Set α} [Subsingleton β] : (⋂ i, s i) ∈ f ↔ ∀ i, s i ∈ f := by rw [← sInter_range, sInter_eq_biInter, biInter_mem' (subsingleton_range s), forall_mem_range] theorem exists_mem_subset_iff : (∃ t ∈ f, t ⊆ s) ↔ s ∈ f := ⟨fun ⟨_, ht, ts⟩ => mem_of_superset ht ts, fun hs => ⟨s, hs, Subset.rfl⟩⟩ theorem monotone_mem {f : Filter α} : Monotone fun s => s ∈ f := fun _ _ hst h => mem_of_superset h hst theorem exists_mem_and_iff {P : Set α → Prop} {Q : Set α → Prop} (hP : Antitone P) (hQ : Antitone Q) : ((∃ u ∈ f, P u) ∧ ∃ u ∈ f, Q u) ↔ ∃ u ∈ f, P u ∧ Q u := by constructor · rintro ⟨⟨u, huf, hPu⟩, v, hvf, hQv⟩ exact ⟨u ∩ v, inter_mem huf hvf, hP inter_subset_left hPu, hQ inter_subset_right hQv⟩ · rintro ⟨u, huf, hPu, hQu⟩ exact ⟨⟨u, huf, hPu⟩, u, huf, hQu⟩ theorem forall_in_swap {β : Type*} {p : Set α → β → Prop} : (∀ a ∈ f, ∀ (b), p a b) ↔ ∀ (b), ∀ a ∈ f, p a b := Set.forall_in_swap end Filter namespace Filter variable {α : Type u} {β : Type v} {γ : Type w} {δ : Type*} {ι : Sort x} theorem mem_principal_self (s : Set α) : s ∈ 𝓟 s := Subset.rfl section Lattice variable {f g : Filter α} {s t : Set α} protected theorem not_le : ¬f ≤ g ↔ ∃ s ∈ g, s ∉ f := by simp_rw [le_def, not_forall, exists_prop] /-- `GenerateSets g s`: `s` is in the filter closure of `g`. -/ inductive GenerateSets (g : Set (Set α)) : Set α → Prop | basic {s : Set α} : s ∈ g → GenerateSets g s | univ : GenerateSets g univ | superset {s t : Set α} : GenerateSets g s → s ⊆ t → GenerateSets g t | inter {s t : Set α} : GenerateSets g s → GenerateSets g t → GenerateSets g (s ∩ t) /-- `generate g` is the largest filter containing the sets `g`. -/ def generate (g : Set (Set α)) : Filter α where sets := {s | GenerateSets g s} univ_sets := GenerateSets.univ sets_of_superset := GenerateSets.superset inter_sets := GenerateSets.inter lemma mem_generate_of_mem {s : Set <| Set α} {U : Set α} (h : U ∈ s) : U ∈ generate s := GenerateSets.basic h theorem le_generate_iff {s : Set (Set α)} {f : Filter α} : f ≤ generate s ↔ s ⊆ f.sets := Iff.intro (fun h _ hu => h <| GenerateSets.basic <| hu) fun h _ hu => hu.recOn (fun h' => h h') univ_mem (fun _ hxy hx => mem_of_superset hx hxy) fun _ _ hx hy => inter_mem hx hy @[simp] lemma generate_singleton (s : Set α) : generate {s} = 𝓟 s := le_antisymm (fun _t ht ↦ mem_of_superset (mem_generate_of_mem <| mem_singleton _) ht) <| le_generate_iff.2 <| singleton_subset_iff.2 Subset.rfl /-- `mkOfClosure s hs` constructs a filter on `α` whose elements set is exactly `s : Set (Set α)`, provided one gives the assumption `hs : (generate s).sets = s`. -/ protected def mkOfClosure (s : Set (Set α)) (hs : (generate s).sets = s) : Filter α where sets := s univ_sets := hs ▸ univ_mem sets_of_superset := hs ▸ mem_of_superset inter_sets := hs ▸ inter_mem theorem mkOfClosure_sets {s : Set (Set α)} {hs : (generate s).sets = s} : Filter.mkOfClosure s hs = generate s := Filter.ext fun u => show u ∈ (Filter.mkOfClosure s hs).sets ↔ u ∈ (generate s).sets from hs.symm ▸ Iff.rfl /-- Galois insertion from sets of sets into filters. -/ def giGenerate (α : Type*) : @GaloisInsertion (Set (Set α)) (Filter α)ᵒᵈ _ _ Filter.generate Filter.sets where gc _ _ := le_generate_iff le_l_u _ _ h := GenerateSets.basic h choice s hs := Filter.mkOfClosure s (le_antisymm hs <| le_generate_iff.1 <| le_rfl) choice_eq _ _ := mkOfClosure_sets theorem mem_inf_iff {f g : Filter α} {s : Set α} : s ∈ f ⊓ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, s = t₁ ∩ t₂ := Iff.rfl theorem mem_inf_of_left {f g : Filter α} {s : Set α} (h : s ∈ f) : s ∈ f ⊓ g := ⟨s, h, univ, univ_mem, (inter_univ s).symm⟩ theorem mem_inf_of_right {f g : Filter α} {s : Set α} (h : s ∈ g) : s ∈ f ⊓ g := ⟨univ, univ_mem, s, h, (univ_inter s).symm⟩ theorem inter_mem_inf {α : Type u} {f g : Filter α} {s t : Set α} (hs : s ∈ f) (ht : t ∈ g) : s ∩ t ∈ f ⊓ g := ⟨s, hs, t, ht, rfl⟩ theorem mem_inf_of_inter {f g : Filter α} {s t u : Set α} (hs : s ∈ f) (ht : t ∈ g) (h : s ∩ t ⊆ u) : u ∈ f ⊓ g := mem_of_superset (inter_mem_inf hs ht) h theorem mem_inf_iff_superset {f g : Filter α} {s : Set α} : s ∈ f ⊓ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ ∩ t₂ ⊆ s := ⟨fun ⟨t₁, h₁, t₂, h₂, Eq⟩ => ⟨t₁, h₁, t₂, h₂, Eq ▸ Subset.rfl⟩, fun ⟨_, h₁, _, h₂, sub⟩ => mem_inf_of_inter h₁ h₂ sub⟩ section CompleteLattice /-- Complete lattice structure on `Filter α`. -/ instance instCompleteLatticeFilter : CompleteLattice (Filter α) where inf a b := min a b sup a b := max a b le_sup_left _ _ _ h := h.1 le_sup_right _ _ _ h := h.2 sup_le _ _ _ h₁ h₂ _ h := ⟨h₁ h, h₂ h⟩ inf_le_left _ _ _ := mem_inf_of_left inf_le_right _ _ _ := mem_inf_of_right le_inf := fun _ _ _ h₁ h₂ _s ⟨_a, ha, _b, hb, hs⟩ => hs.symm ▸ inter_mem (h₁ ha) (h₂ hb) le_sSup _ _ h₁ _ h₂ := h₂ h₁ sSup_le _ _ h₁ _ h₂ _ h₃ := h₁ _ h₃ h₂ sInf_le _ _ h₁ _ h₂ := by rw [← Filter.sSup_lowerBounds]; exact fun _ h₃ ↦ h₃ h₁ h₂ le_sInf _ _ h₁ _ h₂ := by rw [← Filter.sSup_lowerBounds] at h₂; exact h₂ h₁ le_top _ _ := univ_mem' bot_le _ _ _ := trivial instance : Inhabited (Filter α) := ⟨⊥⟩ end CompleteLattice theorem NeBot.ne {f : Filter α} (hf : NeBot f) : f ≠ ⊥ := hf.ne' @[simp] theorem not_neBot {f : Filter α} : ¬f.NeBot ↔ f = ⊥ := neBot_iff.not_left theorem NeBot.mono {f g : Filter α} (hf : NeBot f) (hg : f ≤ g) : NeBot g := ⟨ne_bot_of_le_ne_bot hf.1 hg⟩ theorem neBot_of_le {f g : Filter α} [hf : NeBot f] (hg : f ≤ g) : NeBot g := hf.mono hg @[simp] theorem sup_neBot {f g : Filter α} : NeBot (f ⊔ g) ↔ NeBot f ∨ NeBot g := by simp only [neBot_iff, not_and_or, Ne, sup_eq_bot_iff] theorem not_disjoint_self_iff : ¬Disjoint f f ↔ f.NeBot := by rw [disjoint_self, neBot_iff] theorem bot_sets_eq : (⊥ : Filter α).sets = univ := rfl /-- Either `f = ⊥` or `Filter.NeBot f`. This is a version of `eq_or_ne` that uses `Filter.NeBot` as the second alternative, to be used as an instance. -/ theorem eq_or_neBot (f : Filter α) : f = ⊥ ∨ NeBot f := (eq_or_ne f ⊥).imp_right NeBot.mk theorem sup_sets_eq {f g : Filter α} : (f ⊔ g).sets = f.sets ∩ g.sets := (giGenerate α).gc.u_inf theorem sSup_sets_eq {s : Set (Filter α)} : (sSup s).sets = ⋂ f ∈ s, (f : Filter α).sets := (giGenerate α).gc.u_sInf theorem iSup_sets_eq {f : ι → Filter α} : (iSup f).sets = ⋂ i, (f i).sets := (giGenerate α).gc.u_iInf theorem generate_empty : Filter.generate ∅ = (⊤ : Filter α) := (giGenerate α).gc.l_bot theorem generate_univ : Filter.generate univ = (⊥ : Filter α) := bot_unique fun _ _ => GenerateSets.basic (mem_univ _) theorem generate_union {s t : Set (Set α)} : Filter.generate (s ∪ t) = Filter.generate s ⊓ Filter.generate t := (giGenerate α).gc.l_sup theorem generate_iUnion {s : ι → Set (Set α)} : Filter.generate (⋃ i, s i) = ⨅ i, Filter.generate (s i) := (giGenerate α).gc.l_iSup @[simp] theorem mem_sup {f g : Filter α} {s : Set α} : s ∈ f ⊔ g ↔ s ∈ f ∧ s ∈ g := Iff.rfl theorem union_mem_sup {f g : Filter α} {s t : Set α} (hs : s ∈ f) (ht : t ∈ g) : s ∪ t ∈ f ⊔ g := ⟨mem_of_superset hs subset_union_left, mem_of_superset ht subset_union_right⟩ @[simp] theorem mem_iSup {x : Set α} {f : ι → Filter α} : x ∈ iSup f ↔ ∀ i, x ∈ f i := by simp only [← Filter.mem_sets, iSup_sets_eq, mem_iInter] @[simp] theorem iSup_neBot {f : ι → Filter α} : (⨆ i, f i).NeBot ↔ ∃ i, (f i).NeBot := by simp [neBot_iff] theorem iInf_eq_generate (s : ι → Filter α) : iInf s = generate (⋃ i, (s i).sets) := eq_of_forall_le_iff fun _ ↦ by simp [le_generate_iff] theorem mem_iInf_of_mem {f : ι → Filter α} (i : ι) {s} (hs : s ∈ f i) : s ∈ ⨅ i, f i := iInf_le f i hs @[simp] theorem le_principal_iff {s : Set α} {f : Filter α} : f ≤ 𝓟 s ↔ s ∈ f := ⟨fun h => h Subset.rfl, fun hs _ ht => mem_of_superset hs ht⟩ theorem Iic_principal (s : Set α) : Iic (𝓟 s) = { l | s ∈ l } := Set.ext fun _ => le_principal_iff theorem principal_mono {s t : Set α} : 𝓟 s ≤ 𝓟 t ↔ s ⊆ t := by simp only [le_principal_iff, mem_principal] @[gcongr] alias ⟨_, _root_.GCongr.filter_principal_mono⟩ := principal_mono @[mono] theorem monotone_principal : Monotone (𝓟 : Set α → Filter α) := fun _ _ => principal_mono.2 @[simp] theorem principal_eq_iff_eq {s t : Set α} : 𝓟 s = 𝓟 t ↔ s = t := by simp only [le_antisymm_iff, le_principal_iff, mem_principal]; rfl @[simp] theorem join_principal_eq_sSup {s : Set (Filter α)} : join (𝓟 s) = sSup s := rfl @[simp] theorem principal_univ : 𝓟 (univ : Set α) = ⊤ := top_unique <| by simp only [le_principal_iff, mem_top, eq_self_iff_true] @[simp] theorem principal_empty : 𝓟 (∅ : Set α) = ⊥ := bot_unique fun _ _ => empty_subset _ theorem generate_eq_biInf (S : Set (Set α)) : generate S = ⨅ s ∈ S, 𝓟 s := eq_of_forall_le_iff fun f => by simp [le_generate_iff, le_principal_iff, subset_def] /-! ### Lattice equations -/ theorem empty_mem_iff_bot {f : Filter α} : ∅ ∈ f ↔ f = ⊥ := ⟨fun h => bot_unique fun s _ => mem_of_superset h (empty_subset s), fun h => h.symm ▸ mem_bot⟩ theorem nonempty_of_mem {f : Filter α} [hf : NeBot f] {s : Set α} (hs : s ∈ f) : s.Nonempty := s.eq_empty_or_nonempty.elim (fun h => absurd hs (h.symm ▸ mt empty_mem_iff_bot.mp hf.1)) id theorem NeBot.nonempty_of_mem {f : Filter α} (hf : NeBot f) {s : Set α} (hs : s ∈ f) : s.Nonempty := @Filter.nonempty_of_mem α f hf s hs @[simp] theorem empty_not_mem (f : Filter α) [NeBot f] : ¬∅ ∈ f := fun h => (nonempty_of_mem h).ne_empty rfl theorem nonempty_of_neBot (f : Filter α) [NeBot f] : Nonempty α := nonempty_of_exists <| nonempty_of_mem (univ_mem : univ ∈ f) theorem compl_not_mem {f : Filter α} {s : Set α} [NeBot f] (h : s ∈ f) : sᶜ ∉ f := fun hsc => (nonempty_of_mem (inter_mem h hsc)).ne_empty <| inter_compl_self s theorem filter_eq_bot_of_isEmpty [IsEmpty α] (f : Filter α) : f = ⊥ := empty_mem_iff_bot.mp <| univ_mem' isEmptyElim protected lemma disjoint_iff {f g : Filter α} : Disjoint f g ↔ ∃ s ∈ f, ∃ t ∈ g, Disjoint s t := by simp only [disjoint_iff, ← empty_mem_iff_bot, mem_inf_iff, inf_eq_inter, bot_eq_empty, @eq_comm _ ∅] theorem disjoint_of_disjoint_of_mem {f g : Filter α} {s t : Set α} (h : Disjoint s t) (hs : s ∈ f) (ht : t ∈ g) : Disjoint f g := Filter.disjoint_iff.mpr ⟨s, hs, t, ht, h⟩ theorem NeBot.not_disjoint (hf : f.NeBot) (hs : s ∈ f) (ht : t ∈ f) : ¬Disjoint s t := fun h => not_disjoint_self_iff.2 hf <| Filter.disjoint_iff.2 ⟨s, hs, t, ht, h⟩ theorem inf_eq_bot_iff {f g : Filter α} : f ⊓ g = ⊥ ↔ ∃ U ∈ f, ∃ V ∈ g, U ∩ V = ∅ := by simp only [← disjoint_iff, Filter.disjoint_iff, Set.disjoint_iff_inter_eq_empty] /-- There is exactly one filter on an empty type. -/ instance unique [IsEmpty α] : Unique (Filter α) where default := ⊥ uniq := filter_eq_bot_of_isEmpty theorem NeBot.nonempty (f : Filter α) [hf : f.NeBot] : Nonempty α := not_isEmpty_iff.mp fun _ ↦ hf.ne (Subsingleton.elim _ _) /-- There are only two filters on a `Subsingleton`: `⊥` and `⊤`. If the type is empty, then they are equal. -/ theorem eq_top_of_neBot [Subsingleton α] (l : Filter α) [NeBot l] : l = ⊤ := by refine top_unique fun s hs => ?_ obtain rfl : s = univ := Subsingleton.eq_univ_of_nonempty (nonempty_of_mem hs) exact univ_mem theorem forall_mem_nonempty_iff_neBot {f : Filter α} : (∀ s : Set α, s ∈ f → s.Nonempty) ↔ NeBot f := ⟨fun h => ⟨fun hf => not_nonempty_empty (h ∅ <| hf.symm ▸ mem_bot)⟩, @nonempty_of_mem _ _⟩ instance instNeBotTop [Nonempty α] : NeBot (⊤ : Filter α) := forall_mem_nonempty_iff_neBot.1 fun s hs => by rwa [mem_top.1 hs, ← nonempty_iff_univ_nonempty] instance instNontrivialFilter [Nonempty α] : Nontrivial (Filter α) := ⟨⟨⊤, ⊥, instNeBotTop.ne⟩⟩ theorem nontrivial_iff_nonempty : Nontrivial (Filter α) ↔ Nonempty α := ⟨fun _ => by_contra fun h' => haveI := not_nonempty_iff.1 h' not_subsingleton (Filter α) inferInstance, @Filter.instNontrivialFilter α⟩ theorem eq_sInf_of_mem_iff_exists_mem {S : Set (Filter α)} {l : Filter α} (h : ∀ {s}, s ∈ l ↔ ∃ f ∈ S, s ∈ f) : l = sInf S := le_antisymm (le_sInf fun f hf _ hs => h.2 ⟨f, hf, hs⟩) fun _ hs => let ⟨_, hf, hs⟩ := h.1 hs; (sInf_le hf) hs theorem eq_iInf_of_mem_iff_exists_mem {f : ι → Filter α} {l : Filter α} (h : ∀ {s}, s ∈ l ↔ ∃ i, s ∈ f i) : l = iInf f := eq_sInf_of_mem_iff_exists_mem <| h.trans (exists_range_iff (p := (_ ∈ ·))).symm theorem eq_biInf_of_mem_iff_exists_mem {f : ι → Filter α} {p : ι → Prop} {l : Filter α} (h : ∀ {s}, s ∈ l ↔ ∃ i, p i ∧ s ∈ f i) : l = ⨅ (i) (_ : p i), f i := by rw [iInf_subtype'] exact eq_iInf_of_mem_iff_exists_mem fun {_} => by simp only [Subtype.exists, h, exists_prop] theorem iInf_sets_eq {f : ι → Filter α} (h : Directed (· ≥ ·) f) [ne : Nonempty ι] : (iInf f).sets = ⋃ i, (f i).sets := let ⟨i⟩ := ne let u := { sets := ⋃ i, (f i).sets univ_sets := mem_iUnion.2 ⟨i, univ_mem⟩ sets_of_superset := by simp only [mem_iUnion, exists_imp] exact fun i hx hxy => ⟨i, mem_of_superset hx hxy⟩ inter_sets := by simp only [mem_iUnion, exists_imp] intro x y a hx b hy rcases h a b with ⟨c, ha, hb⟩ exact ⟨c, inter_mem (ha hx) (hb hy)⟩ } have : u = iInf f := eq_iInf_of_mem_iff_exists_mem mem_iUnion congr_arg Filter.sets this.symm theorem mem_iInf_of_directed {f : ι → Filter α} (h : Directed (· ≥ ·) f) [Nonempty ι] (s) : s ∈ iInf f ↔ ∃ i, s ∈ f i := by simp only [← Filter.mem_sets, iInf_sets_eq h, mem_iUnion] theorem mem_biInf_of_directed {f : β → Filter α} {s : Set β} (h : DirectedOn (f ⁻¹'o (· ≥ ·)) s) (ne : s.Nonempty) {t : Set α} : (t ∈ ⨅ i ∈ s, f i) ↔ ∃ i ∈ s, t ∈ f i := by haveI := ne.to_subtype simp_rw [iInf_subtype', mem_iInf_of_directed h.directed_val, Subtype.exists, exists_prop] theorem biInf_sets_eq {f : β → Filter α} {s : Set β} (h : DirectedOn (f ⁻¹'o (· ≥ ·)) s) (ne : s.Nonempty) : (⨅ i ∈ s, f i).sets = ⋃ i ∈ s, (f i).sets := ext fun t => by simp [mem_biInf_of_directed h ne] @[simp] theorem sup_join {f₁ f₂ : Filter (Filter α)} : join f₁ ⊔ join f₂ = join (f₁ ⊔ f₂) := Filter.ext fun x => by simp only [mem_sup, mem_join] @[simp] theorem iSup_join {ι : Sort w} {f : ι → Filter (Filter α)} : ⨆ x, join (f x) = join (⨆ x, f x) := Filter.ext fun x => by simp only [mem_iSup, mem_join] instance : DistribLattice (Filter α) := { Filter.instCompleteLatticeFilter with le_sup_inf := by intro x y z s simp only [and_assoc, mem_inf_iff, mem_sup, exists_prop, exists_imp, and_imp] rintro hs t₁ ht₁ t₂ ht₂ rfl exact ⟨t₁, x.sets_of_superset hs inter_subset_left, ht₁, t₂, x.sets_of_superset hs inter_subset_right, ht₂, rfl⟩ } /-- If `f : ι → Filter α` is directed, `ι` is not empty, and `∀ i, f i ≠ ⊥`, then `iInf f ≠ ⊥`. See also `iInf_neBot_of_directed` for a version assuming `Nonempty α` instead of `Nonempty ι`. -/ theorem iInf_neBot_of_directed' {f : ι → Filter α} [Nonempty ι] (hd : Directed (· ≥ ·) f) : (∀ i, NeBot (f i)) → NeBot (iInf f) := not_imp_not.1 <| by simpa only [not_forall, not_neBot, ← empty_mem_iff_bot, mem_iInf_of_directed hd] using id /-- If `f : ι → Filter α` is directed, `α` is not empty, and `∀ i, f i ≠ ⊥`, then `iInf f ≠ ⊥`. See also `iInf_neBot_of_directed'` for a version assuming `Nonempty ι` instead of `Nonempty α`. -/ theorem iInf_neBot_of_directed {f : ι → Filter α} [hn : Nonempty α] (hd : Directed (· ≥ ·) f) (hb : ∀ i, NeBot (f i)) : NeBot (iInf f) := by cases isEmpty_or_nonempty ι · constructor simp [iInf_of_empty f, top_ne_bot] · exact iInf_neBot_of_directed' hd hb theorem sInf_neBot_of_directed' {s : Set (Filter α)} (hne : s.Nonempty) (hd : DirectedOn (· ≥ ·) s) (hbot : ⊥ ∉ s) : NeBot (sInf s) := (sInf_eq_iInf' s).symm ▸ @iInf_neBot_of_directed' _ _ _ hne.to_subtype hd.directed_val fun ⟨_, hf⟩ => ⟨ne_of_mem_of_not_mem hf hbot⟩ theorem sInf_neBot_of_directed [Nonempty α] {s : Set (Filter α)} (hd : DirectedOn (· ≥ ·) s) (hbot : ⊥ ∉ s) : NeBot (sInf s) := (sInf_eq_iInf' s).symm ▸ iInf_neBot_of_directed hd.directed_val fun ⟨_, hf⟩ => ⟨ne_of_mem_of_not_mem hf hbot⟩ theorem iInf_neBot_iff_of_directed' {f : ι → Filter α} [Nonempty ι] (hd : Directed (· ≥ ·) f) : NeBot (iInf f) ↔ ∀ i, NeBot (f i) := ⟨fun H i => H.mono (iInf_le _ i), iInf_neBot_of_directed' hd⟩ theorem iInf_neBot_iff_of_directed {f : ι → Filter α} [Nonempty α] (hd : Directed (· ≥ ·) f) : NeBot (iInf f) ↔ ∀ i, NeBot (f i) := ⟨fun H i => H.mono (iInf_le _ i), iInf_neBot_of_directed hd⟩ /-! #### `principal` equations -/ @[simp] theorem inf_principal {s t : Set α} : 𝓟 s ⊓ 𝓟 t = 𝓟 (s ∩ t) := le_antisymm (by simp only [le_principal_iff, mem_inf_iff]; exact ⟨s, Subset.rfl, t, Subset.rfl, rfl⟩) (by simp [le_inf_iff, inter_subset_left, inter_subset_right]) @[simp] theorem sup_principal {s t : Set α} : 𝓟 s ⊔ 𝓟 t = 𝓟 (s ∪ t) := Filter.ext fun u => by simp only [union_subset_iff, mem_sup, mem_principal] @[simp] theorem iSup_principal {ι : Sort w} {s : ι → Set α} : ⨆ x, 𝓟 (s x) = 𝓟 (⋃ i, s i) := Filter.ext fun x => by simp only [mem_iSup, mem_principal, iUnion_subset_iff] @[simp] theorem principal_eq_bot_iff {s : Set α} : 𝓟 s = ⊥ ↔ s = ∅ := empty_mem_iff_bot.symm.trans <| mem_principal.trans subset_empty_iff @[simp] theorem principal_neBot_iff {s : Set α} : NeBot (𝓟 s) ↔ s.Nonempty := neBot_iff.trans <| (not_congr principal_eq_bot_iff).trans nonempty_iff_ne_empty.symm alias ⟨_, _root_.Set.Nonempty.principal_neBot⟩ := principal_neBot_iff theorem isCompl_principal (s : Set α) : IsCompl (𝓟 s) (𝓟 sᶜ) := IsCompl.of_eq (by rw [inf_principal, inter_compl_self, principal_empty]) <| by rw [sup_principal, union_compl_self, principal_univ] theorem mem_inf_principal' {f : Filter α} {s t : Set α} : s ∈ f ⊓ 𝓟 t ↔ tᶜ ∪ s ∈ f := by simp only [← le_principal_iff, (isCompl_principal s).le_left_iff, disjoint_assoc, inf_principal, ← (isCompl_principal (t ∩ sᶜ)).le_right_iff, compl_inter, compl_compl] lemma mem_inf_principal {f : Filter α} {s t : Set α} : s ∈ f ⊓ 𝓟 t ↔ { x | x ∈ t → x ∈ s } ∈ f := by simp only [mem_inf_principal', imp_iff_not_or, setOf_or, compl_def, setOf_mem_eq] lemma iSup_inf_principal (f : ι → Filter α) (s : Set α) : ⨆ i, f i ⊓ 𝓟 s = (⨆ i, f i) ⊓ 𝓟 s := by ext simp only [mem_iSup, mem_inf_principal] theorem inf_principal_eq_bot {f : Filter α} {s : Set α} : f ⊓ 𝓟 s = ⊥ ↔ sᶜ ∈ f := by rw [← empty_mem_iff_bot, mem_inf_principal] simp only [mem_empty_iff_false, imp_false, compl_def] theorem mem_of_eq_bot {f : Filter α} {s : Set α} (h : f ⊓ 𝓟 sᶜ = ⊥) : s ∈ f := by rwa [inf_principal_eq_bot, compl_compl] at h theorem diff_mem_inf_principal_compl {f : Filter α} {s : Set α} (hs : s ∈ f) (t : Set α) : s \ t ∈ f ⊓ 𝓟 tᶜ := inter_mem_inf hs <| mem_principal_self tᶜ theorem principal_le_iff {s : Set α} {f : Filter α} : 𝓟 s ≤ f ↔ ∀ V ∈ f, s ⊆ V := by simp_rw [le_def, mem_principal] end Lattice @[mono, gcongr] theorem join_mono {f₁ f₂ : Filter (Filter α)} (h : f₁ ≤ f₂) : join f₁ ≤ join f₂ := fun _ hs => h hs /-! ### Eventually -/ theorem eventually_iff {f : Filter α} {P : α → Prop} : (∀ᶠ x in f, P x) ↔ { x | P x } ∈ f := Iff.rfl @[simp] theorem eventually_mem_set {s : Set α} {l : Filter α} : (∀ᶠ x in l, x ∈ s) ↔ s ∈ l := Iff.rfl protected theorem ext' {f₁ f₂ : Filter α} (h : ∀ p : α → Prop, (∀ᶠ x in f₁, p x) ↔ ∀ᶠ x in f₂, p x) : f₁ = f₂ := Filter.ext h theorem Eventually.filter_mono {f₁ f₂ : Filter α} (h : f₁ ≤ f₂) {p : α → Prop} (hp : ∀ᶠ x in f₂, p x) : ∀ᶠ x in f₁, p x := h hp theorem eventually_of_mem {f : Filter α} {P : α → Prop} {U : Set α} (hU : U ∈ f) (h : ∀ x ∈ U, P x) : ∀ᶠ x in f, P x := mem_of_superset hU h protected theorem Eventually.and {p q : α → Prop} {f : Filter α} : f.Eventually p → f.Eventually q → ∀ᶠ x in f, p x ∧ q x := inter_mem @[simp] theorem eventually_true (f : Filter α) : ∀ᶠ _ in f, True := univ_mem theorem Eventually.of_forall {p : α → Prop} {f : Filter α} (hp : ∀ x, p x) : ∀ᶠ x in f, p x := univ_mem' hp @[simp] theorem eventually_false_iff_eq_bot {f : Filter α} : (∀ᶠ _ in f, False) ↔ f = ⊥ := empty_mem_iff_bot @[simp] theorem eventually_const {f : Filter α} [t : NeBot f] {p : Prop} : (∀ᶠ _ in f, p) ↔ p := by by_cases h : p <;> simp [h, t.ne] theorem eventually_iff_exists_mem {p : α → Prop} {f : Filter α} : (∀ᶠ x in f, p x) ↔ ∃ v ∈ f, ∀ y ∈ v, p y := exists_mem_subset_iff.symm theorem Eventually.exists_mem {p : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) : ∃ v ∈ f, ∀ y ∈ v, p y := eventually_iff_exists_mem.1 hp theorem Eventually.mp {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) (hq : ∀ᶠ x in f, p x → q x) : ∀ᶠ x in f, q x := mp_mem hp hq theorem Eventually.mono {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) (hq : ∀ x, p x → q x) : ∀ᶠ x in f, q x := hp.mp (Eventually.of_forall hq) theorem forall_eventually_of_eventually_forall {f : Filter α} {p : α → β → Prop} (h : ∀ᶠ x in f, ∀ y, p x y) : ∀ y, ∀ᶠ x in f, p x y := fun y => h.mono fun _ h => h y @[simp] theorem eventually_and {p q : α → Prop} {f : Filter α} : (∀ᶠ x in f, p x ∧ q x) ↔ (∀ᶠ x in f, p x) ∧ ∀ᶠ x in f, q x := inter_mem_iff theorem Eventually.congr {f : Filter α} {p q : α → Prop} (h' : ∀ᶠ x in f, p x) (h : ∀ᶠ x in f, p x ↔ q x) : ∀ᶠ x in f, q x := h'.mp (h.mono fun _ hx => hx.mp) theorem eventually_congr {f : Filter α} {p q : α → Prop} (h : ∀ᶠ x in f, p x ↔ q x) : (∀ᶠ x in f, p x) ↔ ∀ᶠ x in f, q x := ⟨fun hp => hp.congr h, fun hq => hq.congr <| by simpa only [Iff.comm] using h⟩ @[simp] theorem eventually_or_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} : (∀ᶠ x in f, p ∨ q x) ↔ p ∨ ∀ᶠ x in f, q x := by_cases (fun h : p => by simp [h]) fun h => by simp [h] @[simp] theorem eventually_or_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} : (∀ᶠ x in f, p x ∨ q) ↔ (∀ᶠ x in f, p x) ∨ q := by simp only [@or_comm _ q, eventually_or_distrib_left] theorem eventually_imp_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} : (∀ᶠ x in f, p → q x) ↔ p → ∀ᶠ x in f, q x := by simp only [imp_iff_not_or, eventually_or_distrib_left] @[simp] theorem eventually_bot {p : α → Prop} : ∀ᶠ x in ⊥, p x := ⟨⟩ @[simp] theorem eventually_top {p : α → Prop} : (∀ᶠ x in ⊤, p x) ↔ ∀ x, p x := Iff.rfl @[simp] theorem eventually_sup {p : α → Prop} {f g : Filter α} :
(∀ᶠ x in f ⊔ g, p x) ↔ (∀ᶠ x in f, p x) ∧ ∀ᶠ x in g, p x := Iff.rfl @[simp] theorem eventually_sSup {p : α → Prop} {fs : Set (Filter α)} :
Mathlib/Order/Filter/Basic.lean
660
664
/- Copyright (c) 2020 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Lie.Matrix import Mathlib.LinearAlgebra.Matrix.SesquilinearForm import Mathlib.Tactic.NoncommRing /-! # Lie algebras of skew-adjoint endomorphisms of a bilinear form When a module carries a bilinear form, the Lie algebra of endomorphisms of the module contains a distinguished Lie subalgebra: the skew-adjoint endomorphisms. Such subalgebras are important because they provide a simple, explicit construction of the so-called classical Lie algebras. This file defines the Lie subalgebra of skew-adjoint endomorphisms cut out by a bilinear form on a module and proves some basic related results. It also provides the corresponding definitions and results for the Lie algebra of square matrices. ## Main definitions * `skewAdjointLieSubalgebra` * `skewAdjointLieSubalgebraEquiv` * `skewAdjointMatricesLieSubalgebra` * `skewAdjointMatricesLieSubalgebraEquiv` ## Tags lie algebra, skew-adjoint, bilinear form -/ universe u v w w₁ section SkewAdjointEndomorphisms open LinearMap (BilinForm) variable {R : Type u} {M : Type v} [CommRing R] [AddCommGroup M] [Module R M] variable (B : BilinForm R M) theorem LinearMap.BilinForm.isSkewAdjoint_bracket {f g : Module.End R M} (hf : f ∈ B.skewAdjointSubmodule) (hg : g ∈ B.skewAdjointSubmodule) : ⁅f, g⁆ ∈ B.skewAdjointSubmodule := by rw [mem_skewAdjointSubmodule] at * have hfg : IsAdjointPair B B (f * g) (g * f) := by rw [← neg_mul_neg g f]; exact hg.comp hf have hgf : IsAdjointPair B B (g * f) (f * g) := by rw [← neg_mul_neg f g]; exact hf.comp hg change IsAdjointPair B B (f * g - g * f) (-(f * g - g * f)); rw [neg_sub] exact hfg.sub hgf /-- Given an `R`-module `M`, equipped with a bilinear form, the skew-adjoint endomorphisms form a Lie subalgebra of the Lie algebra of endomorphisms. -/ def skewAdjointLieSubalgebra : LieSubalgebra R (Module.End R M) := { B.skewAdjointSubmodule with lie_mem' := B.isSkewAdjoint_bracket } variable {N : Type w} [AddCommGroup N] [Module R N] (e : N ≃ₗ[R] M) /-- An equivalence of modules with bilinear forms gives equivalence of Lie algebras of skew-adjoint endomorphisms. -/ def skewAdjointLieSubalgebraEquiv : skewAdjointLieSubalgebra (B.compl₁₂ (e : N →ₗ[R] M) e) ≃ₗ⁅R⁆ skewAdjointLieSubalgebra B := by apply LieEquiv.ofSubalgebras _ _ e.lieConj ext f simp only [LieSubalgebra.mem_coe, Submodule.mem_map_equiv, LieSubalgebra.mem_map_submodule, LinearEquiv.coe_coe] exact (LinearMap.isPairSelfAdjoint_equiv (B := -B) (F := B) e f).symm @[simp] theorem skewAdjointLieSubalgebraEquiv_apply (f : skewAdjointLieSubalgebra (B.compl₁₂ (Qₗ := N) (Qₗ' := N) ↑e ↑e)) : ↑(skewAdjointLieSubalgebraEquiv B e f) = e.lieConj f := by simp [skewAdjointLieSubalgebraEquiv] @[simp]
theorem skewAdjointLieSubalgebraEquiv_symm_apply (f : skewAdjointLieSubalgebra B) : ↑((skewAdjointLieSubalgebraEquiv B e).symm f) = e.symm.lieConj f := by simp [skewAdjointLieSubalgebraEquiv]
Mathlib/Algebra/Lie/SkewAdjoint.lean
77
80
/- Copyright (c) 2021 Aaron Anderson, Jesse Michael Han, Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Jesse Michael Han, Floris van Doorn -/ import Mathlib.Data.Finset.Basic import Mathlib.ModelTheory.Syntax import Mathlib.Data.List.ProdSigma /-! # Basics on First-Order Semantics This file defines the interpretations of first-order terms, formulas, sentences, and theories in a style inspired by the [Flypitch project](https://flypitch.github.io/). ## Main Definitions - `FirstOrder.Language.Term.realize` is defined so that `t.realize v` is the term `t` evaluated at variables `v`. - `FirstOrder.Language.BoundedFormula.Realize` is defined so that `φ.Realize v xs` is the bounded formula `φ` evaluated at tuples of variables `v` and `xs`. - `FirstOrder.Language.Formula.Realize` is defined so that `φ.Realize v` is the formula `φ` evaluated at variables `v`. - `FirstOrder.Language.Sentence.Realize` is defined so that `φ.Realize M` is the sentence `φ` evaluated in the structure `M`. Also denoted `M ⊨ φ`. - `FirstOrder.Language.Theory.Model` is defined so that `T.Model M` is true if and only if every sentence of `T` is realized in `M`. Also denoted `T ⊨ φ`. ## Main Results - Several results in this file show that syntactic constructions such as `relabel`, `castLE`, `liftAt`, `subst`, and the actions of language maps commute with realization of terms, formulas, sentences, and theories. ## Implementation Notes - Formulas use a modified version of de Bruijn variables. Specifically, a `L.BoundedFormula α n` is a formula with some variables indexed by a type `α`, which cannot be quantified over, and some indexed by `Fin n`, which can. For any `φ : L.BoundedFormula α (n + 1)`, we define the formula `∀' φ : L.BoundedFormula α n` by universally quantifying over the variable indexed by `n : Fin (n + 1)`. ## References For the Flypitch project: - [J. Han, F. van Doorn, *A formal proof of the independence of the continuum hypothesis*] [flypitch_cpp] - [J. Han, F. van Doorn, *A formalization of forcing and the unprovability of the continuum hypothesis*][flypitch_itp] -/ universe u v w u' v' namespace FirstOrder namespace Language variable {L : Language.{u, v}} {L' : Language} variable {M : Type w} {N P : Type*} [L.Structure M] [L.Structure N] [L.Structure P] variable {α : Type u'} {β : Type v'} {γ : Type*} open FirstOrder Cardinal open Structure Cardinal Fin namespace Term /-- A term `t` with variables indexed by `α` can be evaluated by giving a value to each variable. -/ def realize (v : α → M) : ∀ _t : L.Term α, M | var k => v k | func f ts => funMap f fun i => (ts i).realize v @[simp] theorem realize_var (v : α → M) (k) : realize v (var k : L.Term α) = v k := rfl @[simp] theorem realize_func (v : α → M) {n} (f : L.Functions n) (ts) : realize v (func f ts : L.Term α) = funMap f fun i => (ts i).realize v := rfl @[simp] theorem realize_relabel {t : L.Term α} {g : α → β} {v : β → M} : (t.relabel g).realize v = t.realize (v ∘ g) := by induction t with | var => rfl | func f ts ih => simp [ih] @[simp] theorem realize_liftAt {n n' m : ℕ} {t : L.Term (α ⊕ (Fin n))} {v : α ⊕ (Fin (n + n')) → M} : (t.liftAt n' m).realize v = t.realize (v ∘ Sum.map id fun i : Fin _ => if ↑i < m then Fin.castAdd n' i else Fin.addNat i n') := realize_relabel @[simp] theorem realize_constants {c : L.Constants} {v : α → M} : c.term.realize v = c := funMap_eq_coe_constants @[simp] theorem realize_functions_apply₁ {f : L.Functions 1} {t : L.Term α} {v : α → M} : (f.apply₁ t).realize v = funMap f ![t.realize v] := by rw [Functions.apply₁, Term.realize] refine congr rfl (funext fun i => ?_) simp only [Matrix.cons_val_fin_one] @[simp] theorem realize_functions_apply₂ {f : L.Functions 2} {t₁ t₂ : L.Term α} {v : α → M} : (f.apply₂ t₁ t₂).realize v = funMap f ![t₁.realize v, t₂.realize v] := by rw [Functions.apply₂, Term.realize] refine congr rfl (funext (Fin.cases ?_ ?_)) · simp only [Matrix.cons_val_zero] · simp only [Matrix.cons_val_succ, Matrix.cons_val_fin_one, forall_const] theorem realize_con {A : Set M} {a : A} {v : α → M} : (L.con a).term.realize v = a := rfl @[simp] theorem realize_subst {t : L.Term α} {tf : α → L.Term β} {v : β → M} : (t.subst tf).realize v = t.realize fun a => (tf a).realize v := by induction t with | var => rfl | func _ _ ih => simp [ih] theorem realize_restrictVar [DecidableEq α] {t : L.Term α} {f : t.varFinset → β} {v : β → M} (v' : α → M) (hv' : ∀ a, v (f a) = v' a) : (t.restrictVar f).realize v = t.realize v' := by induction t with | var => simp [restrictVar, hv'] | func _ _ ih => exact congr rfl (funext fun i => ih i ((by simp [Function.comp_apply, hv']))) /-- A special case of `realize_restrictVar`, included because we can add the `simp` attribute to it -/ @[simp] theorem realize_restrictVar' [DecidableEq α] {t : L.Term α} {s : Set α} (h : ↑t.varFinset ⊆ s) {v : α → M} : (t.restrictVar (Set.inclusion h)).realize (v ∘ (↑)) = t.realize v := realize_restrictVar _ (by simp) theorem realize_restrictVarLeft [DecidableEq α] {γ : Type*} {t : L.Term (α ⊕ γ)} {f : t.varFinsetLeft → β} {xs : β ⊕ γ → M} (xs' : α → M) (hxs' : ∀ a, xs (Sum.inl (f a)) = xs' a) : (t.restrictVarLeft f).realize xs = t.realize (Sum.elim xs' (xs ∘ Sum.inr)) := by induction t with | var a => cases a <;> simp [restrictVarLeft, hxs'] | func _ _ ih => exact congr rfl (funext fun i => ih i (by simp [hxs'])) /-- A special case of `realize_restrictVarLeft`, included because we can add the `simp` attribute to it -/ @[simp] theorem realize_restrictVarLeft' [DecidableEq α] {γ : Type*} {t : L.Term (α ⊕ γ)} {s : Set α} (h : ↑t.varFinsetLeft ⊆ s) {v : α → M} {xs : γ → M} : (t.restrictVarLeft (Set.inclusion h)).realize (Sum.elim (v ∘ (↑)) xs) = t.realize (Sum.elim v xs) := realize_restrictVarLeft _ (by simp) @[simp] theorem realize_constantsToVars [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M] {t : L[[α]].Term β} {v : β → M} : t.constantsToVars.realize (Sum.elim (fun a => ↑(L.con a)) v) = t.realize v := by induction t with | var => simp | @func n f ts ih => cases n · cases f · simp only [realize, ih, constantsOn, constantsOnFunc, constantsToVars] -- Porting note: below lemma does not work with simp for some reason rw [withConstants_funMap_sumInl] · simp only [realize, constantsToVars, Sum.elim_inl, funMap_eq_coe_constants] rfl · obtain - | f := f · simp only [realize, ih, constantsOn, constantsOnFunc, constantsToVars] -- Porting note: below lemma does not work with simp for some reason rw [withConstants_funMap_sumInl] · exact isEmptyElim f @[simp] theorem realize_varsToConstants [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M] {t : L.Term (α ⊕ β)} {v : β → M} : t.varsToConstants.realize v = t.realize (Sum.elim (fun a => ↑(L.con a)) v) := by induction t with | var ab => rcases ab with a | b <;> simp [Language.con] | func f ts ih => simp only [realize, constantsOn, constantsOnFunc, ih, varsToConstants] -- Porting note: below lemma does not work with simp for some reason rw [withConstants_funMap_sumInl] theorem realize_constantsVarsEquivLeft [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M] {n} {t : L[[α]].Term (β ⊕ (Fin n))} {v : β → M} {xs : Fin n → M} : (constantsVarsEquivLeft t).realize (Sum.elim (Sum.elim (fun a => ↑(L.con a)) v) xs) = t.realize (Sum.elim v xs) := by simp only [constantsVarsEquivLeft, realize_relabel, Equiv.coe_trans, Function.comp_apply, constantsVarsEquiv_apply, relabelEquiv_symm_apply] refine _root_.trans ?_ realize_constantsToVars rcongr x rcases x with (a | (b | i)) <;> simp end Term namespace LHom @[simp] theorem realize_onTerm [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (t : L.Term α) (v : α → M) : (φ.onTerm t).realize v = t.realize v := by induction t with | var => rfl | func f ts ih => simp only [Term.realize, LHom.onTerm, LHom.map_onFunction, ih] end LHom @[simp] theorem HomClass.realize_term {F : Type*} [FunLike F M N] [HomClass L F M N] (g : F) {t : L.Term α} {v : α → M} : t.realize (g ∘ v) = g (t.realize v) := by induction t · rfl · rw [Term.realize, Term.realize, HomClass.map_fun] refine congr rfl ?_ ext x simp [*] variable {n : ℕ} namespace BoundedFormula open Term /-- A bounded formula can be evaluated as true or false by giving values to each free variable. -/ def Realize : ∀ {l} (_f : L.BoundedFormula α l) (_v : α → M) (_xs : Fin l → M), Prop | _, falsum, _v, _xs => False | _, equal t₁ t₂, v, xs => t₁.realize (Sum.elim v xs) = t₂.realize (Sum.elim v xs) | _, rel R ts, v, xs => RelMap R fun i => (ts i).realize (Sum.elim v xs) | _, imp f₁ f₂, v, xs => Realize f₁ v xs → Realize f₂ v xs | _, all f, v, xs => ∀ x : M, Realize f v (snoc xs x) variable {l : ℕ} {φ ψ : L.BoundedFormula α l} {θ : L.BoundedFormula α l.succ} variable {v : α → M} {xs : Fin l → M} @[simp] theorem realize_bot : (⊥ : L.BoundedFormula α l).Realize v xs ↔ False := Iff.rfl @[simp] theorem realize_not : φ.not.Realize v xs ↔ ¬φ.Realize v xs := Iff.rfl @[simp] theorem realize_bdEqual (t₁ t₂ : L.Term (α ⊕ (Fin l))) : (t₁.bdEqual t₂).Realize v xs ↔ t₁.realize (Sum.elim v xs) = t₂.realize (Sum.elim v xs) := Iff.rfl @[simp] theorem realize_top : (⊤ : L.BoundedFormula α l).Realize v xs ↔ True := by simp [Top.top] @[simp] theorem realize_inf : (φ ⊓ ψ).Realize v xs ↔ φ.Realize v xs ∧ ψ.Realize v xs := by simp [Inf.inf, Realize] @[simp] theorem realize_foldr_inf (l : List (L.BoundedFormula α n)) (v : α → M) (xs : Fin n → M) : (l.foldr (· ⊓ ·) ⊤).Realize v xs ↔ ∀ φ ∈ l, BoundedFormula.Realize φ v xs := by induction' l with φ l ih · simp · simp [ih] @[simp] theorem realize_imp : (φ.imp ψ).Realize v xs ↔ φ.Realize v xs → ψ.Realize v xs := by simp only [Realize] @[simp] theorem realize_rel {k : ℕ} {R : L.Relations k} {ts : Fin k → L.Term _} : (R.boundedFormula ts).Realize v xs ↔ RelMap R fun i => (ts i).realize (Sum.elim v xs) := Iff.rfl @[simp] theorem realize_rel₁ {R : L.Relations 1} {t : L.Term _} : (R.boundedFormula₁ t).Realize v xs ↔ RelMap R ![t.realize (Sum.elim v xs)] := by rw [Relations.boundedFormula₁, realize_rel, iff_eq_eq] refine congr rfl (funext fun _ => ?_) simp only [Matrix.cons_val_fin_one] @[simp] theorem realize_rel₂ {R : L.Relations 2} {t₁ t₂ : L.Term _} : (R.boundedFormula₂ t₁ t₂).Realize v xs ↔ RelMap R ![t₁.realize (Sum.elim v xs), t₂.realize (Sum.elim v xs)] := by rw [Relations.boundedFormula₂, realize_rel, iff_eq_eq] refine congr rfl (funext (Fin.cases ?_ ?_)) · simp only [Matrix.cons_val_zero] · simp only [Matrix.cons_val_succ, Matrix.cons_val_fin_one, forall_const] @[simp] theorem realize_sup : (φ ⊔ ψ).Realize v xs ↔ φ.Realize v xs ∨ ψ.Realize v xs := by simp only [realize, max, realize_not, eq_iff_iff] tauto @[simp] theorem realize_foldr_sup (l : List (L.BoundedFormula α n)) (v : α → M) (xs : Fin n → M) : (l.foldr (· ⊔ ·) ⊥).Realize v xs ↔ ∃ φ ∈ l, BoundedFormula.Realize φ v xs := by induction' l with φ l ih · simp · simp_rw [List.foldr_cons, realize_sup, ih, List.mem_cons, or_and_right, exists_or, exists_eq_left] @[simp] theorem realize_all : (all θ).Realize v xs ↔ ∀ a : M, θ.Realize v (Fin.snoc xs a) := Iff.rfl @[simp] theorem realize_ex : θ.ex.Realize v xs ↔ ∃ a : M, θ.Realize v (Fin.snoc xs a) := by rw [BoundedFormula.ex, realize_not, realize_all, not_forall] simp_rw [realize_not, Classical.not_not] @[simp] theorem realize_iff : (φ.iff ψ).Realize v xs ↔ (φ.Realize v xs ↔ ψ.Realize v xs) := by simp only [BoundedFormula.iff, realize_inf, realize_imp, and_imp, ← iff_def] theorem realize_castLE_of_eq {m n : ℕ} (h : m = n) {h' : m ≤ n} {φ : L.BoundedFormula α m} {v : α → M} {xs : Fin n → M} : (φ.castLE h').Realize v xs ↔ φ.Realize v (xs ∘ Fin.cast h) := by subst h simp only [castLE_rfl, cast_refl, OrderIso.coe_refl, Function.comp_id] theorem realize_mapTermRel_id [L'.Structure M] {ft : ∀ n, L.Term (α ⊕ (Fin n)) → L'.Term (β ⊕ (Fin n))} {fr : ∀ n, L.Relations n → L'.Relations n} {n} {φ : L.BoundedFormula α n} {v : α → M} {v' : β → M} {xs : Fin n → M} (h1 : ∀ (n) (t : L.Term (α ⊕ (Fin n))) (xs : Fin n → M), (ft n t).realize (Sum.elim v' xs) = t.realize (Sum.elim v xs)) (h2 : ∀ (n) (R : L.Relations n) (x : Fin n → M), RelMap (fr n R) x = RelMap R x) : (φ.mapTermRel ft fr fun _ => id).Realize v' xs ↔ φ.Realize v xs := by induction φ with | falsum => rfl | equal => simp [mapTermRel, Realize, h1] | rel => simp [mapTermRel, Realize, h1, h2] | imp _ _ ih1 ih2 => simp [mapTermRel, Realize, ih1, ih2] | all _ ih => simp only [mapTermRel, Realize, ih, id] theorem realize_mapTermRel_add_castLe [L'.Structure M] {k : ℕ} {ft : ∀ n, L.Term (α ⊕ (Fin n)) → L'.Term (β ⊕ (Fin (k + n)))} {fr : ∀ n, L.Relations n → L'.Relations n} {n} {φ : L.BoundedFormula α n} (v : ∀ {n}, (Fin (k + n) → M) → α → M) {v' : β → M} (xs : Fin (k + n) → M) (h1 : ∀ (n) (t : L.Term (α ⊕ (Fin n))) (xs' : Fin (k + n) → M), (ft n t).realize (Sum.elim v' xs') = t.realize (Sum.elim (v xs') (xs' ∘ Fin.natAdd _))) (h2 : ∀ (n) (R : L.Relations n) (x : Fin n → M), RelMap (fr n R) x = RelMap R x) (hv : ∀ (n) (xs : Fin (k + n) → M) (x : M), @v (n + 1) (snoc xs x : Fin _ → M) = v xs) : (φ.mapTermRel ft fr fun _ => castLE (add_assoc _ _ _).symm.le).Realize v' xs ↔ φ.Realize (v xs) (xs ∘ Fin.natAdd _) := by induction φ with | falsum => rfl | equal => simp [mapTermRel, Realize, h1] | rel => simp [mapTermRel, Realize, h1, h2] | imp _ _ ih1 ih2 => simp [mapTermRel, Realize, ih1, ih2] | all _ ih => simp [mapTermRel, Realize, ih, hv] @[simp] theorem realize_relabel {m n : ℕ} {φ : L.BoundedFormula α n} {g : α → β ⊕ (Fin m)} {v : β → M} {xs : Fin (m + n) → M} : (φ.relabel g).Realize v xs ↔ φ.Realize (Sum.elim v (xs ∘ Fin.castAdd n) ∘ g) (xs ∘ Fin.natAdd m) := by apply realize_mapTermRel_add_castLe <;> simp theorem realize_liftAt {n n' m : ℕ} {φ : L.BoundedFormula α n} {v : α → M} {xs : Fin (n + n') → M} (hmn : m + n' ≤ n + 1) : (φ.liftAt n' m).Realize v xs ↔ φ.Realize v (xs ∘ fun i => if ↑i < m then Fin.castAdd n' i else Fin.addNat i n') := by rw [liftAt] induction φ with | falsum => simp [mapTermRel, Realize] | equal => simp [mapTermRel, Realize, realize_rel, realize_liftAt, Sum.elim_comp_map] | rel => simp [mapTermRel, Realize, realize_rel, realize_liftAt, Sum.elim_comp_map] | imp _ _ ih1 ih2 => simp only [mapTermRel, Realize, ih1 hmn, ih2 hmn] | @all k _ ih3 => have h : k + 1 + n' = k + n' + 1 := by rw [add_assoc, add_comm 1 n', ← add_assoc] simp only [mapTermRel, Realize, realize_castLE_of_eq h, ih3 (hmn.trans k.succ.le_succ)] refine forall_congr' fun x => iff_eq_eq.mpr (congr rfl (funext (Fin.lastCases ?_ fun i => ?_))) · simp only [Function.comp_apply, val_last, snoc_last] refine (congr rfl (Fin.ext ?_)).trans (snoc_last _ _) split_ifs <;> dsimp; omega · simp only [Function.comp_apply, Fin.snoc_castSucc] refine (congr rfl (Fin.ext ?_)).trans (snoc_castSucc _ _ _) simp only [coe_castSucc, coe_cast] split_ifs <;> simp theorem realize_liftAt_one {n m : ℕ} {φ : L.BoundedFormula α n} {v : α → M} {xs : Fin (n + 1) → M} (hmn : m ≤ n) : (φ.liftAt 1 m).Realize v xs ↔ φ.Realize v (xs ∘ fun i => if ↑i < m then castSucc i else i.succ) := by simp [realize_liftAt (add_le_add_right hmn 1), castSucc] @[simp] theorem realize_liftAt_one_self {n : ℕ} {φ : L.BoundedFormula α n} {v : α → M} {xs : Fin (n + 1) → M} : (φ.liftAt 1 n).Realize v xs ↔ φ.Realize v (xs ∘ castSucc) := by rw [realize_liftAt_one (refl n), iff_eq_eq] refine congr rfl (congr rfl (funext fun i => ?_)) rw [if_pos i.is_lt] @[simp] theorem realize_subst {φ : L.BoundedFormula α n} {tf : α → L.Term β} {v : β → M} {xs : Fin n → M} : (φ.subst tf).Realize v xs ↔ φ.Realize (fun a => (tf a).realize v) xs := realize_mapTermRel_id (fun n t x => by rw [Term.realize_subst] rcongr a cases a · simp only [Sum.elim_inl, Function.comp_apply, Term.realize_relabel, Sum.elim_comp_inl] · rfl) (by simp) theorem realize_restrictFreeVar [DecidableEq α] {n : ℕ} {φ : L.BoundedFormula α n} {f : φ.freeVarFinset → β} {v : β → M} {xs : Fin n → M} (v' : α → M) (hv' : ∀ a, v (f a) = v' a) : (φ.restrictFreeVar f).Realize v xs ↔ φ.Realize v' xs := by induction φ with | falsum => rfl | equal => simp only [Realize, restrictFreeVar, freeVarFinset.eq_2] rw [realize_restrictVarLeft v' (by simp [hv']), realize_restrictVarLeft v' (by simp [hv'])] simp [Function.comp_apply] | rel => simp only [Realize, freeVarFinset.eq_3, Finset.biUnion_val, restrictFreeVar] congr! rw [realize_restrictVarLeft v' (by simp [hv'])] simp [Function.comp_apply] | imp _ _ ih1 ih2 => simp only [Realize, restrictFreeVar, freeVarFinset.eq_4] rw [ih1, ih2] <;> simp [hv'] | all _ ih3 => simp only [restrictFreeVar, Realize] refine forall_congr' (fun _ => ?_) rw [ih3]; simp [hv'] /-- A special case of `realize_restrictFreeVar`, included because we can add the `simp` attribute to it -/ @[simp] theorem realize_restrictFreeVar' [DecidableEq α] {n : ℕ} {φ : L.BoundedFormula α n} {s : Set α} (h : ↑φ.freeVarFinset ⊆ s) {v : α → M} {xs : Fin n → M} : (φ.restrictFreeVar (Set.inclusion h)).Realize (v ∘ (↑)) xs ↔ φ.Realize v xs := realize_restrictFreeVar _ (by simp) theorem realize_constantsVarsEquiv [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M] {n} {φ : L[[α]].BoundedFormula β n} {v : β → M} {xs : Fin n → M} : (constantsVarsEquiv φ).Realize (Sum.elim (fun a => ↑(L.con a)) v) xs ↔ φ.Realize v xs := by refine realize_mapTermRel_id (fun n t xs => realize_constantsVarsEquivLeft) fun n R xs => ?_ -- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644 erw [← (lhomWithConstants L α).map_onRelation (Equiv.sumEmpty (L.Relations n) ((constantsOn α).Relations n) R) xs] rcongr obtain - | R := R · simp · exact isEmptyElim R @[simp] theorem realize_relabelEquiv {g : α ≃ β} {k} {φ : L.BoundedFormula α k} {v : β → M} {xs : Fin k → M} : (relabelEquiv g φ).Realize v xs ↔ φ.Realize (v ∘ g) xs := by simp only [relabelEquiv, mapTermRelEquiv_apply, Equiv.coe_refl] refine realize_mapTermRel_id (fun n t xs => ?_) fun _ _ _ => rfl simp only [relabelEquiv_apply, Term.realize_relabel] refine congr (congr rfl ?_) rfl ext (i | i) <;> rfl variable [Nonempty M] theorem realize_all_liftAt_one_self {n : ℕ} {φ : L.BoundedFormula α n} {v : α → M} {xs : Fin n → M} : (φ.liftAt 1 n).all.Realize v xs ↔ φ.Realize v xs := by inhabit M simp only [realize_all, realize_liftAt_one_self] refine ⟨fun h => ?_, fun h a => ?_⟩ · refine (congr rfl (funext fun i => ?_)).mp (h default) simp · refine (congr rfl (funext fun i => ?_)).mp h simp end BoundedFormula namespace LHom open BoundedFormula @[simp] theorem realize_onBoundedFormula [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] {n : ℕ} (ψ : L.BoundedFormula α n) {v : α → M} {xs : Fin n → M} : (φ.onBoundedFormula ψ).Realize v xs ↔ ψ.Realize v xs := by induction ψ with | falsum => rfl | equal => simp only [onBoundedFormula, realize_bdEqual, realize_onTerm]; rfl | rel => simp only [onBoundedFormula, realize_rel, LHom.map_onRelation, Function.comp_apply, realize_onTerm] rfl | imp _ _ ih1 ih2 => simp only [onBoundedFormula, ih1, ih2, realize_imp] | all _ ih3 => simp only [onBoundedFormula, ih3, realize_all] end LHom namespace Formula /-- A formula can be evaluated as true or false by giving values to each free variable. -/ nonrec def Realize (φ : L.Formula α) (v : α → M) : Prop := φ.Realize v default variable {φ ψ : L.Formula α} {v : α → M} @[simp] theorem realize_not : φ.not.Realize v ↔ ¬φ.Realize v := Iff.rfl @[simp] theorem realize_bot : (⊥ : L.Formula α).Realize v ↔ False := Iff.rfl @[simp] theorem realize_top : (⊤ : L.Formula α).Realize v ↔ True := BoundedFormula.realize_top @[simp] theorem realize_inf : (φ ⊓ ψ).Realize v ↔ φ.Realize v ∧ ψ.Realize v := BoundedFormula.realize_inf @[simp] theorem realize_imp : (φ.imp ψ).Realize v ↔ φ.Realize v → ψ.Realize v := BoundedFormula.realize_imp @[simp] theorem realize_rel {k : ℕ} {R : L.Relations k} {ts : Fin k → L.Term α} : (R.formula ts).Realize v ↔ RelMap R fun i => (ts i).realize v := BoundedFormula.realize_rel.trans (by simp) @[simp] theorem realize_rel₁ {R : L.Relations 1} {t : L.Term _} : (R.formula₁ t).Realize v ↔ RelMap R ![t.realize v] := by rw [Relations.formula₁, realize_rel, iff_eq_eq] refine congr rfl (funext fun _ => ?_) simp only [Matrix.cons_val_fin_one] @[simp] theorem realize_rel₂ {R : L.Relations 2} {t₁ t₂ : L.Term _} : (R.formula₂ t₁ t₂).Realize v ↔ RelMap R ![t₁.realize v, t₂.realize v] := by rw [Relations.formula₂, realize_rel, iff_eq_eq] refine congr rfl (funext (Fin.cases ?_ ?_)) · simp only [Matrix.cons_val_zero] · simp only [Matrix.cons_val_succ, Matrix.cons_val_fin_one, forall_const] @[simp] theorem realize_sup : (φ ⊔ ψ).Realize v ↔ φ.Realize v ∨ ψ.Realize v := BoundedFormula.realize_sup @[simp] theorem realize_iff : (φ.iff ψ).Realize v ↔ (φ.Realize v ↔ ψ.Realize v) := BoundedFormula.realize_iff @[simp] theorem realize_relabel {φ : L.Formula α} {g : α → β} {v : β → M} : (φ.relabel g).Realize v ↔ φ.Realize (v ∘ g) := by rw [Realize, Realize, relabel, BoundedFormula.realize_relabel, iff_eq_eq, Fin.castAdd_zero] exact congr rfl (funext finZeroElim) theorem realize_relabel_sumInr (φ : L.Formula (Fin n)) {v : Empty → M} {x : Fin n → M} : (BoundedFormula.relabel Sum.inr φ).Realize v x ↔ φ.Realize x := by rw [BoundedFormula.realize_relabel, Formula.Realize, Sum.elim_comp_inr, Fin.castAdd_zero, cast_refl, Function.comp_id, Subsingleton.elim (x ∘ (natAdd n : Fin 0 → Fin n)) default] @[deprecated (since := "2025-02-21")] alias realize_relabel_sum_inr := realize_relabel_sumInr @[simp] theorem realize_equal {t₁ t₂ : L.Term α} {x : α → M} : (t₁.equal t₂).Realize x ↔ t₁.realize x = t₂.realize x := by simp [Term.equal, Realize] @[simp] theorem realize_graph {f : L.Functions n} {x : Fin n → M} {y : M} : (Formula.graph f).Realize (Fin.cons y x : _ → M) ↔ funMap f x = y := by simp only [Formula.graph, Term.realize, realize_equal, Fin.cons_zero, Fin.cons_succ] rw [eq_comm] theorem boundedFormula_realize_eq_realize (φ : L.Formula α) (x : α → M) (y : Fin 0 → M) : BoundedFormula.Realize φ x y ↔ φ.Realize x := by rw [Formula.Realize, iff_iff_eq] congr ext i; exact Fin.elim0 i end Formula @[simp] theorem LHom.realize_onFormula [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (ψ : L.Formula α) {v : α → M} : (φ.onFormula ψ).Realize v ↔ ψ.Realize v := φ.realize_onBoundedFormula ψ @[simp] theorem LHom.setOf_realize_onFormula [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (ψ : L.Formula α) : (setOf (φ.onFormula ψ).Realize : Set (α → M)) = setOf ψ.Realize := by ext simp variable (M) /-- A sentence can be evaluated as true or false in a structure. -/ nonrec def Sentence.Realize (φ : L.Sentence) : Prop := φ.Realize (default : _ → M) -- input using \|= or \vDash, but not using \models @[inherit_doc Sentence.Realize] infixl:51 " ⊨ " => Sentence.Realize @[simp] theorem Sentence.realize_not {φ : L.Sentence} : M ⊨ φ.not ↔ ¬M ⊨ φ := Iff.rfl namespace Formula @[simp] theorem realize_equivSentence_symm_con [L[[α]].Structure M] [(L.lhomWithConstants α).IsExpansionOn M] (φ : L[[α]].Sentence) : ((equivSentence.symm φ).Realize fun a => (L.con a : M)) ↔ φ.Realize M := by simp only [equivSentence, _root_.Equiv.symm_symm, Equiv.coe_trans, Realize, BoundedFormula.realize_relabelEquiv, Function.comp] refine _root_.trans ?_ BoundedFormula.realize_constantsVarsEquiv rw [iff_iff_eq] congr with (_ | a) · simp · cases a @[simp] theorem realize_equivSentence [L[[α]].Structure M] [(L.lhomWithConstants α).IsExpansionOn M] (φ : L.Formula α) : (equivSentence φ).Realize M ↔ φ.Realize fun a => (L.con a : M) := by rw [← realize_equivSentence_symm_con M (equivSentence φ), _root_.Equiv.symm_apply_apply] theorem realize_equivSentence_symm (φ : L[[α]].Sentence) (v : α → M) : (equivSentence.symm φ).Realize v ↔ @Sentence.Realize _ M (@Language.withConstantsStructure L M _ α (constantsOn.structure v)) φ := letI := constantsOn.structure v realize_equivSentence_symm_con M φ end Formula @[simp] theorem LHom.realize_onSentence [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (ψ : L.Sentence) : M ⊨ φ.onSentence ψ ↔ M ⊨ ψ := φ.realize_onFormula ψ variable (L) /-- The complete theory of a structure `M` is the set of all sentences `M` satisfies. -/ def completeTheory : L.Theory := { φ | M ⊨ φ } variable (N) /-- Two structures are elementarily equivalent when they satisfy the same sentences. -/ def ElementarilyEquivalent : Prop := L.completeTheory M = L.completeTheory N @[inherit_doc FirstOrder.Language.ElementarilyEquivalent] scoped[FirstOrder] notation:25 A " ≅[" L "] " B:50 => FirstOrder.Language.ElementarilyEquivalent L A B variable {L} {M} {N} @[simp] theorem mem_completeTheory {φ : Sentence L} : φ ∈ L.completeTheory M ↔ M ⊨ φ := Iff.rfl theorem elementarilyEquivalent_iff : M ≅[L] N ↔ ∀ φ : L.Sentence, M ⊨ φ ↔ N ⊨ φ := by simp only [ElementarilyEquivalent, Set.ext_iff, completeTheory, Set.mem_setOf_eq] variable (M) /-- A model of a theory is a structure in which every sentence is realized as true. -/ class Theory.Model (T : L.Theory) : Prop where realize_of_mem : ∀ φ ∈ T, M ⊨ φ -- input using \|= or \vDash, but not using \models @[inherit_doc Theory.Model] infixl:51 " ⊨ " => Theory.Model
variable {M} (T : L.Theory) @[simp default - 10] theorem Theory.model_iff : M ⊨ T ↔ ∀ φ ∈ T, M ⊨ φ :=
Mathlib/ModelTheory/Semantics.lean
677
681
/- Copyright (c) 2024 Jz Pan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jz Pan -/ import Mathlib.FieldTheory.PurelyInseparable.Basic import Mathlib.FieldTheory.PerfectClosure /-! # `IsPerfectClosure` predicate This file contains `IsPerfectClosure` which asserts that `L` is a perfect closure of `K` under a ring homomorphism `i : K →+* L`, as well as its basic properties. ## Main definitions - `pNilradical`: given a natural number `p`, the `p`-nilradical of a ring is defined to be the nilradical if `p > 1` (`pNilradical_eq_nilradical`), and defined to be the zero ideal if `p ≤ 1` (`pNilradical_eq_bot'`). Equivalently, it is the ideal consisting of elements `x` such that `x ^ p ^ n = 0` for some `n` (`mem_pNilradical`). - `IsPRadical`: a ring homomorphism `i : K →+* L` of characteristic `p` rings is called `p`-radical, if or any element `x` of `L` there is `n : ℕ` such that `x ^ (p ^ n)` is contained in `K`, and the kernel of `i` is contained in the `p`-nilradical of `K`. A generalization of purely inseparable extension for fields. - `IsPerfectClosure`: if `i : K →+* L` is `p`-radical ring homomorphism, then it makes `L` a perfect closure of `K`, if `L` is perfect. Our definition makes it synonymous to `IsPRadical` if `PerfectRing L p` is present. A caveat is that you need to write `[PerfectRing L p] [IsPerfectClosure i p]`. This is similar to `PerfectRing` which has `ExpChar` as a prerequisite. - `PerfectRing.lift`: if a `p`-radical ring homomorphism `K →+* L` is given, `M` is a perfect ring, then any ring homomorphism `K →+* M` can be lifted to `L →+* M`. This is similar to `IsAlgClosed.lift` and `IsSepClosed.lift`. - `PerfectRing.liftEquiv`: `K →+* M` is one-to-one correspondence to `L →+* M`, given by `PerfectRing.lift`. This is a generalization to `PerfectClosure.lift`. - `IsPerfectClosure.equiv`: perfect closures of a ring are isomorphic. ## Main results - `IsPRadical.trans`: composition of `p`-radical ring homomorphisms is also `p`-radical. - `PerfectClosure.isPRadical`: the absolute perfect closure `PerfectClosure` is a `p`-radical extension over the base ring, in particular, it is a perfect closure of the base ring. - `IsPRadical.isPurelyInseparable`, `IsPurelyInseparable.isPRadical`: `p`-radical and purely inseparable are equivalent for fields. - The (relative) perfect closure `perfectClosure` is a perfect closure (inferred from `IsPurelyInseparable.isPRadical` automatically by Lean). ## Tags perfect ring, perfect closure, purely inseparable -/ open Module Polynomial IntermediateField Field noncomputable section /-- Given a natural number `p`, the `p`-nilradical of a ring is defined to be the nilradical if `p > 1` (`pNilradical_eq_nilradical`), and defined to be the zero ideal if `p ≤ 1` (`pNilradical_eq_bot'`). Equivalently, it is the ideal consisting of elements `x` such that `x ^ p ^ n = 0` for some `n` (`mem_pNilradical`). -/ def pNilradical (R : Type*) [CommSemiring R] (p : ℕ) : Ideal R := if 1 < p then nilradical R else ⊥ theorem pNilradical_le_nilradical {R : Type*} [CommSemiring R] {p : ℕ} : pNilradical R p ≤ nilradical R := by by_cases hp : 1 < p · rw [pNilradical, if_pos hp] simp_rw [pNilradical, if_neg hp, bot_le] theorem pNilradical_eq_nilradical {R : Type*} [CommSemiring R] {p : ℕ} (hp : 1 < p) : pNilradical R p = nilradical R := by rw [pNilradical, if_pos hp] theorem pNilradical_eq_bot {R : Type*} [CommSemiring R] {p : ℕ} (hp : ¬ 1 < p) : pNilradical R p = ⊥ := by rw [pNilradical, if_neg hp] theorem pNilradical_eq_bot' {R : Type*} [CommSemiring R] {p : ℕ} (hp : p ≤ 1) : pNilradical R p = ⊥ := pNilradical_eq_bot (not_lt.2 hp) theorem pNilradical_prime {R : Type*} [CommSemiring R] {p : ℕ} (hp : p.Prime) : pNilradical R p = nilradical R := pNilradical_eq_nilradical hp.one_lt theorem pNilradical_one {R : Type*} [CommSemiring R] : pNilradical R 1 = ⊥ := pNilradical_eq_bot' rfl.le theorem mem_pNilradical {R : Type*} [CommSemiring R] {p : ℕ} {x : R} : x ∈ pNilradical R p ↔ ∃ n : ℕ, x ^ p ^ n = 0 := by by_cases hp : 1 < p · rw [pNilradical_eq_nilradical hp] refine ⟨fun ⟨n, h⟩ ↦ ⟨n, ?_⟩, fun ⟨n, h⟩ ↦ ⟨p ^ n, h⟩⟩ rw [← Nat.sub_add_cancel ((n.lt_pow_self hp).le), pow_add, h, mul_zero] rw [pNilradical_eq_bot hp, Ideal.mem_bot] refine ⟨fun h ↦ ⟨0, by rw [pow_zero, pow_one, h]⟩, fun ⟨n, h⟩ ↦ ?_⟩ rcases Nat.le_one_iff_eq_zero_or_eq_one.1 (not_lt.1 hp) with hp | hp · by_cases hn : n = 0 · rwa [hn, pow_zero, pow_one] at h rw [hp, zero_pow hn, pow_zero] at h subsingleton [subsingleton_of_zero_eq_one h.symm] rwa [hp, one_pow, pow_one] at h theorem sub_mem_pNilradical_iff_pow_expChar_pow_eq {R : Type*} [CommRing R] {p : ℕ} [ExpChar R p] {x y : R} : x - y ∈ pNilradical R p ↔ ∃ n : ℕ, x ^ p ^ n = y ^ p ^ n := by simp_rw [mem_pNilradical, sub_pow_expChar_pow, sub_eq_zero] theorem pow_expChar_pow_inj_of_pNilradical_eq_bot (R : Type*) [CommRing R] (p : ℕ) [ExpChar R p] (h : pNilradical R p = ⊥) (n : ℕ) : Function.Injective fun x : R ↦ x ^ p ^ n := fun _ _ H ↦ sub_eq_zero.1 <| Ideal.mem_bot.1 <| h ▸ sub_mem_pNilradical_iff_pow_expChar_pow_eq.2 ⟨n, H⟩ theorem pNilradical_eq_bot_of_frobenius_inj (R : Type*) [CommSemiring R] (p : ℕ) [ExpChar R p] (h : Function.Injective (frobenius R p)) : pNilradical R p = ⊥ := bot_unique fun x ↦ by rw [mem_pNilradical, Ideal.mem_bot] exact fun ⟨n, _⟩ ↦ h.iterate n (by rwa [← coe_iterateFrobenius, map_zero]) theorem PerfectRing.pNilradical_eq_bot (R : Type*) [CommSemiring R] (p : ℕ) [ExpChar R p] [PerfectRing R p] : pNilradical R p = ⊥ := pNilradical_eq_bot_of_frobenius_inj R p (injective_frobenius R p) section IsPerfectClosure variable {K L M N : Type*} section CommSemiring variable [CommSemiring K] [CommSemiring L] [CommSemiring M] (i : K →+* L) (j : K →+* M) (f : L →+* M) (p : ℕ) /-- If `i : K →+* L` is a ring homomorphism of characteristic `p` rings, then it is called `p`-radical if the following conditions are satisfied: - For any element `x` of `L` there is `n : ℕ` such that `x ^ (p ^ n)` is contained in `K`. - The kernel of `i` is contained in the `p`-nilradical of `K`. It is a generalization of purely inseparable extension for fields. -/ @[mk_iff] class IsPRadical : Prop where pow_mem' : ∀ x : L, ∃ (n : ℕ) (y : K), i y = x ^ p ^ n ker_le' : RingHom.ker i ≤ pNilradical K p theorem IsPRadical.pow_mem [IsPRadical i p] (x : L) : ∃ (n : ℕ) (y : K), i y = x ^ p ^ n := pow_mem' x theorem IsPRadical.ker_le [IsPRadical i p] : RingHom.ker i ≤ pNilradical K p := ker_le' theorem IsPRadical.comap_pNilradical [IsPRadical i p] : (pNilradical L p).comap i = pNilradical K p := by refine le_antisymm (fun x h ↦ mem_pNilradical.2 ?_) (fun x h ↦ ?_) · obtain ⟨n, h⟩ := mem_pNilradical.1 <| Ideal.mem_comap.1 h obtain ⟨m, h⟩ := mem_pNilradical.1 <| ker_le i p ((map_pow i x _).symm ▸ h) exact ⟨n + m, by rwa [pow_add, pow_mul]⟩ simp only [Ideal.mem_comap, mem_pNilradical] at h ⊢ obtain ⟨n, h⟩ := h exact ⟨n, by simpa only [map_pow, map_zero] using congr(i $h)⟩ variable (K) in instance IsPRadical.of_id : IsPRadical (RingHom.id K) p where pow_mem' x := ⟨0, x, by simp⟩ ker_le' x h := by convert Ideal.zero_mem _ /-- Composition of `p`-radical ring homomorphisms is also `p`-radical. -/ theorem IsPRadical.trans [IsPRadical i p] [IsPRadical f p] : IsPRadical (f.comp i) p where pow_mem' x := by obtain ⟨n, y, hy⟩ := pow_mem f p x
obtain ⟨m, z, hz⟩ := pow_mem i p y exact ⟨n + m, z, by rw [RingHom.comp_apply, hz, map_pow, hy, pow_add, pow_mul]⟩ ker_le' x h := by rw [RingHom.mem_ker, RingHom.comp_apply, ← RingHom.mem_ker] at h simpa only [← Ideal.mem_comap, comap_pNilradical] using ker_le f p h /-- If `i : K →+* L` is a `p`-radical ring homomorphism, then it makes `L` a perfect closure of `K`, if `L` is perfect. In this case the kernel of `i` is equal to the `p`-nilradical of `K`
Mathlib/FieldTheory/IsPerfectClosure.lean
173
181
/- Copyright (c) 2020 Jannis Limperg. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jannis Limperg -/ import Mathlib.Data.List.Induction /-! # Lemmas about List.*Idx functions. Some specification lemmas for `List.mapIdx`, `List.mapIdxM`, `List.foldlIdx` and `List.foldrIdx`. As of 2025-01-29, these are not used anywhere in Mathlib. Moreover, with `List.enum` and `List.enumFrom` being replaced by `List.zipIdx` in Lean's `nightly-2025-01-29` release, they now use deprecated functions and theorems. Rather than updating this unused material, we are deprecating it. Anyone wanting to restore this material is welcome to do so, but will need to update uses of `List.enum` and `List.enumFrom` to use `List.zipIdx` instead. However, note that this material will later be implemented in the Lean standard library. -/ assert_not_exists MonoidWithZero universe u v open Function namespace List variable {α : Type u} {β : Type v} section MapIdx @[deprecated reverseRecOn (since := "2025-01-28")] theorem list_reverse_induction (p : List α → Prop) (base : p []) (ind : ∀ (l : List α) (e : α), p l → p (l ++ [e])) : (∀ (l : List α), p l) := fun l => l.reverseRecOn base ind theorem mapIdx_append_one : ∀ {f : ℕ → α → β} {l : List α} {e : α}, mapIdx f (l ++ [e]) = mapIdx f l ++ [f l.length e] := mapIdx_concat set_option linter.deprecated false in @[deprecated "Deprecated without replacement." (since := "2025-01-29"), local simp] theorem map_enumFrom_eq_zipWith : ∀ (l : List α) (n : ℕ) (f : ℕ → α → β), map (uncurry f) (enumFrom n l) = zipWith (fun i ↦ f (i + n)) (range (length l)) l := by intro l generalize e : l.length = len revert l induction' len with len ih <;> intros l e n f · have : l = [] := by cases l · rfl · contradiction rw [this]; rfl · rcases l with - | ⟨head, tail⟩ · contradiction · simp only [enumFrom_cons, map_cons, range_succ_eq_map, zipWith_cons_cons, Nat.zero_add, zipWith_map_left, true_and] rw [ih] · suffices (fun i ↦ f (i + (n + 1))) = ((fun i ↦ f (i + n)) ∘ Nat.succ) by rw [this] rfl funext n' a simp only [comp, Nat.add_assoc, Nat.add_comm, Nat.add_succ] simp only [length_cons, Nat.succ.injEq] at e; exact e set_option linter.deprecated false in @[deprecated "Deprecated without replacement." (since := "2025-01-29")] theorem get_mapIdx (l : List α) (f : ℕ → α → β) (i : ℕ) (h : i < l.length) (h' : i < (l.mapIdx f).length := h.trans_le length_mapIdx.ge) : (l.mapIdx f).get ⟨i, h'⟩ = f i (l.get ⟨i, h⟩) := by simp [mapIdx_eq_zipIdx_map, enum_eq_zip_range] theorem mapIdx_eq_ofFn (l : List α) (f : ℕ → α → β) : l.mapIdx f = ofFn fun i : Fin l.length ↦ f (i : ℕ) (l.get i) := by induction l generalizing f with | nil => simp | cons _ _ IH => simp [IH] end MapIdx section FoldrIdx -- Porting note: Changed argument order of `foldrIdxSpec` to align better with `foldrIdx`. set_option linter.deprecated false in /-- Specification of `foldrIdx`. -/ @[deprecated "Deprecated without replacement." (since := "2025-01-29")] def foldrIdxSpec (f : ℕ → α → β → β) (b : β) (as : List α) (start : ℕ) : β := foldr (uncurry f) b <| enumFrom start as set_option linter.deprecated false in @[deprecated "Deprecated without replacement." (since := "2025-01-29")] theorem foldrIdxSpec_cons (f : ℕ → α → β → β) (b a as start) : foldrIdxSpec f b (a :: as) start = f start a (foldrIdxSpec f b as (start + 1)) := rfl set_option linter.deprecated false in @[deprecated "Deprecated without replacement." (since := "2025-01-29")] theorem foldrIdx_eq_foldrIdxSpec (f : ℕ → α → β → β) (b as start) : foldrIdx f b as start = foldrIdxSpec f b as start := by induction as generalizing start · rfl · simp only [foldrIdx, foldrIdxSpec_cons, *] set_option linter.deprecated false in @[deprecated "Deprecated without replacement." (since := "2025-01-29")] theorem foldrIdx_eq_foldr_enum (f : ℕ → α → β → β) (b : β) (as : List α) : foldrIdx f b as = foldr (uncurry f) b (enum as) := by simp only [foldrIdx, foldrIdxSpec, foldrIdx_eq_foldrIdxSpec, enum] end FoldrIdx set_option linter.deprecated false in @[deprecated "Deprecated without replacement." (since := "2025-01-29")] theorem indexesValues_eq_filter_enum (p : α → Prop) [DecidablePred p] (as : List α) : indexesValues p as = filter (p ∘ Prod.snd) (enum as) := by simp +unfoldPartialApp [indexesValues, foldrIdx_eq_foldr_enum, uncurry, filter_eq_foldr, cond_eq_if] set_option linter.deprecated false in @[deprecated "Deprecated without replacement." (since := "2025-01-29")] theorem findIdxs_eq_map_indexesValues (p : α → Prop) [DecidablePred p] (as : List α) : findIdxs p as = map Prod.fst (indexesValues p as) := by simp +unfoldPartialApp only [indexesValues_eq_filter_enum, map_filter_eq_foldr, findIdxs, uncurry, foldrIdx_eq_foldr_enum, decide_eq_true_eq, comp_apply, Bool.cond_decide] section FoldlIdx -- Porting note: Changed argument order of `foldlIdxSpec` to align better with `foldlIdx`. set_option linter.deprecated false in /-- Specification of `foldlIdx`. -/ @[deprecated "Deprecated without replacement." (since := "2025-01-29")] def foldlIdxSpec (f : ℕ → α → β → α) (a : α) (bs : List β) (start : ℕ) : α := foldl (fun a p ↦ f p.fst a p.snd) a <| enumFrom start bs set_option linter.deprecated false in @[deprecated "Deprecated without replacement." (since := "2025-01-29")] theorem foldlIdxSpec_cons (f : ℕ → α → β → α) (a b bs start) : foldlIdxSpec f a (b :: bs) start = foldlIdxSpec f (f start a b) bs (start + 1) := rfl set_option linter.deprecated false in @[deprecated "Deprecated without replacement." (since := "2025-01-29")] theorem foldlIdx_eq_foldlIdxSpec (f : ℕ → α → β → α) (a bs start) : foldlIdx f a bs start = foldlIdxSpec f a bs start := by induction bs generalizing start a · rfl · simp [foldlIdxSpec, *] set_option linter.deprecated false in @[deprecated "Deprecated without replacement." (since := "2025-01-29")] theorem foldlIdx_eq_foldl_enum (f : ℕ → α → β → α) (a : α) (bs : List β) : foldlIdx f a bs = foldl (fun a p ↦ f p.fst a p.snd) a (enum bs) := by simp only [foldlIdx, foldlIdxSpec, foldlIdx_eq_foldlIdxSpec, enum] end FoldlIdx section FoldIdxM -- Porting note: `foldrM_eq_foldr` now depends on `[LawfulMonad m]` variable {m : Type u → Type v} [Monad m] set_option linter.deprecated false in @[deprecated "Deprecated without replacement." (since := "2025-01-29")] theorem foldrIdxM_eq_foldrM_enum {β} (f : ℕ → α → β → m β) (b : β) (as : List α) [LawfulMonad m] : foldrIdxM f b as = foldrM (uncurry f) b (enum as) := by simp +unfoldPartialApp only [foldrIdxM, foldrM_eq_foldr, foldrIdx_eq_foldr_enum, uncurry] set_option linter.deprecated false in @[deprecated "Deprecated without replacement." (since := "2025-01-29")] theorem foldlIdxM_eq_foldlM_enum [LawfulMonad m] {β} (f : ℕ → β → α → m β) (b : β) (as : List α) : foldlIdxM f b as = List.foldlM (fun b p ↦ f p.fst b p.snd) b (enum as) := by rw [foldlIdxM, foldlM_eq_foldl, foldlIdx_eq_foldl_enum] end FoldIdxM section MapIdxM -- Porting note: `[Applicative m]` replaced by `[Monad m] [LawfulMonad m]` variable {m : Type u → Type v} [Monad m] set_option linter.deprecated false in /-- Specification of `mapIdxMAux`. -/ @[deprecated "Deprecated without replacement." (since := "2025-01-29")] def mapIdxMAuxSpec {β} (f : ℕ → α → m β) (start : ℕ) (as : List α) : m (List β) := List.traverse (uncurry f) <| enumFrom start as -- Note: `traverse` the class method would require a less universe-polymorphic -- `m : Type u → Type u`. set_option linter.deprecated false in @[deprecated "Deprecated without replacement." (since := "2025-01-29")] theorem mapIdxMAuxSpec_cons {β} (f : ℕ → α → m β) (start : ℕ) (a : α) (as : List α) : mapIdxMAuxSpec f start (a :: as) = cons <$> f start a <*> mapIdxMAuxSpec f (start + 1) as := rfl
set_option linter.deprecated false in @[deprecated "Deprecated without replacement." (since := "2025-01-29")] theorem mapIdxMGo_eq_mapIdxMAuxSpec
Mathlib/Data/List/Indexes.lean
198
201
/- 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.Operations import Mathlib.Analysis.SpecificLimits.Basic /-! # Outer measures from functions Given an arbitrary function `m : Set α → ℝ≥0∞` that sends `∅` to `0` we can define an outer measure on `α` that on `s` is defined to be the infimum of `∑ᵢ, m (sᵢ)` for all collections of sets `sᵢ` that cover `s`. This is the unique maximal outer measure that is at most the given function. 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 * `OuterMeasure.boundedBy` is the greatest outer measure that is at most the given function. If you know that the given function sends `∅` to `0`, then `OuterMeasure.ofFunction` is a special case. * `sInf_eq_boundedBy_sInfGen` is a characterization of the infimum of outer measures. ## References * <https://en.wikipedia.org/wiki/Outer_measure> * <https://en.wikipedia.org/wiki/Carath%C3%A9odory%27s_criterion> ## Tags outer measure, Carathéodory-measurable, Carathéodory's criterion -/ assert_not_exists Basis noncomputable section open Set Function Filter open scoped NNReal Topology ENNReal namespace MeasureTheory namespace OuterMeasure section OfFunction variable {α : Type*} /-- Given any function `m` assigning measures to sets satisfying `m ∅ = 0`, there is a unique maximal outer measure `μ` satisfying `μ s ≤ m s` for all `s : Set α`. -/ protected def ofFunction (m : Set α → ℝ≥0∞) (m_empty : m ∅ = 0) : OuterMeasure α := let μ s := ⨅ (f : ℕ → Set α) (_ : s ⊆ ⋃ i, f i), ∑' i, m (f i) { measureOf := μ empty := le_antisymm ((iInf_le_of_le fun _ => ∅) <| iInf_le_of_le (empty_subset _) <| by simp [m_empty]) (zero_le _) mono := fun {_ _} hs => iInf_mono fun _ => iInf_mono' fun hb => ⟨hs.trans hb, le_rfl⟩ iUnion_nat := fun s _ => ENNReal.le_of_forall_pos_le_add <| by intro ε hε (hb : (∑' i, μ (s i)) < ∞) rcases ENNReal.exists_pos_sum_of_countable (ENNReal.coe_pos.2 hε).ne' ℕ with ⟨ε', hε', hl⟩ refine le_trans ?_ (add_le_add_left (le_of_lt hl) _) rw [← ENNReal.tsum_add] choose f hf using show ∀ i, ∃ f : ℕ → Set α, (s i ⊆ ⋃ i, f i) ∧ (∑' i, m (f i)) < μ (s i) + ε' i by intro i have : μ (s i) < μ (s i) + ε' i := ENNReal.lt_add_right (ne_top_of_le_ne_top hb.ne <| ENNReal.le_tsum _) (by simpa using (hε' i).ne') rcases iInf_lt_iff.mp this with ⟨t, ht⟩ exists t contrapose! ht exact le_iInf ht refine le_trans ?_ (ENNReal.tsum_le_tsum fun i => le_of_lt (hf i).2) rw [← ENNReal.tsum_prod, ← Nat.pairEquiv.symm.tsum_eq] refine iInf_le_of_le _ (iInf_le _ ?_) apply iUnion_subset intro i apply Subset.trans (hf i).1 apply iUnion_subset simp only [Nat.pairEquiv_symm_apply] rw [iUnion_unpair] intro j apply subset_iUnion₂ i } variable (m : Set α → ℝ≥0∞) (m_empty : m ∅ = 0) /-- `ofFunction` of a set `s` is the infimum of `∑ᵢ, m (tᵢ)` for all collections of sets `tᵢ` that cover `s`. -/ theorem ofFunction_apply (s : Set α) : OuterMeasure.ofFunction m m_empty s = ⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, m (t n) := rfl /-- `ofFunction` of a set `s` is the infimum of `∑ᵢ, m (tᵢ)` for all collections of sets `tᵢ` that cover `s`, with all `tᵢ` satisfying a predicate `P` such that `m` is infinite for sets that don't satisfy `P`. This is similar to `ofFunction_apply`, except that the sets `tᵢ` satisfy `P`. The hypothesis `m_top` applies in particular to a function of the form `extend m'`. -/ theorem ofFunction_eq_iInf_mem {P : Set α → Prop} (m_top : ∀ s, ¬ P s → m s = ∞) (s : Set α) : OuterMeasure.ofFunction m m_empty s = ⨅ (t : ℕ → Set α) (_ : ∀ i, P (t i)) (_ : s ⊆ ⋃ i, t i), ∑' i, m (t i) := by rw [OuterMeasure.ofFunction_apply] apply le_antisymm · exact le_iInf fun t ↦ le_iInf fun _ ↦ le_iInf fun h ↦ iInf₂_le _ (by exact h) · simp_rw [le_iInf_iff] refine fun t ht_subset ↦ iInf_le_of_le t ?_ by_cases ht : ∀ i, P (t i) · exact iInf_le_of_le ht (iInf_le_of_le ht_subset le_rfl) · simp only [ht, not_false_eq_true, iInf_neg, top_le_iff] push_neg at ht obtain ⟨i, hti_not_mem⟩ := ht have hfi_top : m (t i) = ∞ := m_top _ hti_not_mem exact ENNReal.tsum_eq_top_of_eq_top ⟨i, hfi_top⟩ variable {m m_empty} theorem ofFunction_le (s : Set α) : OuterMeasure.ofFunction m m_empty s ≤ m s := let f : ℕ → Set α := fun i => Nat.casesOn i s fun _ => ∅ iInf_le_of_le f <| iInf_le_of_le (subset_iUnion f 0) <| le_of_eq <| tsum_eq_single 0 <| by rintro (_ | i) · simp · simp [f, m_empty] theorem ofFunction_eq (s : Set α) (m_mono : ∀ ⦃t : Set α⦄, s ⊆ t → m s ≤ m t) (m_subadd : ∀ s : ℕ → Set α, m (⋃ i, s i) ≤ ∑' i, m (s i)) : OuterMeasure.ofFunction m m_empty s = m s := le_antisymm (ofFunction_le s) <| le_iInf fun f => le_iInf fun hf => le_trans (m_mono hf) (m_subadd f) theorem le_ofFunction {μ : OuterMeasure α} : μ ≤ OuterMeasure.ofFunction m m_empty ↔ ∀ s, μ s ≤ m s := ⟨fun H s => le_trans (H s) (ofFunction_le s), fun H _ => le_iInf fun f => le_iInf fun hs => le_trans (μ.mono hs) <| le_trans (measure_iUnion_le f) <| ENNReal.tsum_le_tsum fun _ => H _⟩ theorem isGreatest_ofFunction : IsGreatest { μ : OuterMeasure α | ∀ s, μ s ≤ m s } (OuterMeasure.ofFunction m m_empty) := ⟨fun _ => ofFunction_le _, fun _ => le_ofFunction.2⟩ theorem ofFunction_eq_sSup : OuterMeasure.ofFunction m m_empty = sSup { μ | ∀ s, μ s ≤ m s } := (@isGreatest_ofFunction α m m_empty).isLUB.sSup_eq.symm /-- If `m u = ∞` for any set `u` that has nonempty intersection both with `s` and `t`, then `μ (s ∪ t) = μ s + μ t`, where `μ = MeasureTheory.OuterMeasure.ofFunction m m_empty`. E.g., if `α` is an (e)metric space and `m u = ∞` on any set of diameter `≥ r`, then this lemma implies that `μ (s ∪ t) = μ s + μ t` on any two sets such that `r ≤ edist x y` for all `x ∈ s` and `y ∈ t`. -/ theorem ofFunction_union_of_top_of_nonempty_inter {s t : Set α} (h : ∀ u, (s ∩ u).Nonempty → (t ∩ u).Nonempty → m u = ∞) : OuterMeasure.ofFunction m m_empty (s ∪ t) = OuterMeasure.ofFunction m m_empty s + OuterMeasure.ofFunction m m_empty t := by refine le_antisymm (measure_union_le _ _) (le_iInf₂ fun f hf ↦ ?_) set μ := OuterMeasure.ofFunction m m_empty rcases Classical.em (∃ i, (s ∩ f i).Nonempty ∧ (t ∩ f i).Nonempty) with (⟨i, hs, ht⟩ | he) · calc μ s + μ t ≤ ∞ := le_top _ = m (f i) := (h (f i) hs ht).symm _ ≤ ∑' i, m (f i) := ENNReal.le_tsum i set I := fun s => { i : ℕ | (s ∩ f i).Nonempty } have hd : Disjoint (I s) (I t) := disjoint_iff_inf_le.mpr fun i hi => he ⟨i, hi⟩ have hI : ∀ u ⊆ s ∪ t, μ u ≤ ∑' i : I u, μ (f i) := fun u hu => calc μ u ≤ μ (⋃ i : I u, f i) := μ.mono fun x hx => let ⟨i, hi⟩ := mem_iUnion.1 (hf (hu hx)) mem_iUnion.2 ⟨⟨i, ⟨x, hx, hi⟩⟩, hi⟩ _ ≤ ∑' i : I u, μ (f i) := measure_iUnion_le _ calc μ s + μ t ≤ (∑' i : I s, μ (f i)) + ∑' i : I t, μ (f i) := add_le_add (hI _ subset_union_left) (hI _ subset_union_right) _ = ∑' i : ↑(I s ∪ I t), μ (f i) := (ENNReal.summable.tsum_union_disjoint (f := fun i => μ (f i)) hd ENNReal.summable).symm _ ≤ ∑' i, μ (f i) := (ENNReal.summable.tsum_le_tsum_of_inj (↑) Subtype.coe_injective (fun _ _ => zero_le _) (fun _ => le_rfl) ENNReal.summable) _ ≤ ∑' i, m (f i) := ENNReal.tsum_le_tsum fun i => ofFunction_le _ theorem comap_ofFunction {β} (f : β → α) (h : Monotone m ∨ Surjective f) : comap f (OuterMeasure.ofFunction m m_empty) = OuterMeasure.ofFunction (fun s => m (f '' s)) (by simp; simp [m_empty]) := by refine le_antisymm (le_ofFunction.2 fun s => ?_) fun s => ?_ · rw [comap_apply] apply ofFunction_le · rw [comap_apply, ofFunction_apply, ofFunction_apply] refine iInf_mono' fun t => ⟨fun k => f ⁻¹' t k, ?_⟩ refine iInf_mono' fun ht => ?_ rw [Set.image_subset_iff, preimage_iUnion] at ht refine ⟨ht, ENNReal.tsum_le_tsum fun n => ?_⟩ rcases h with hl | hr exacts [hl (image_preimage_subset _ _), (congr_arg m (hr.image_preimage (t n))).le] theorem map_ofFunction_le {β} (f : α → β) : map f (OuterMeasure.ofFunction m m_empty) ≤ OuterMeasure.ofFunction (fun s => m (f ⁻¹' s)) m_empty := le_ofFunction.2 fun s => by rw [map_apply] apply ofFunction_le theorem map_ofFunction {β} {f : α → β} (hf : Injective f) : map f (OuterMeasure.ofFunction m m_empty) = OuterMeasure.ofFunction (fun s => m (f ⁻¹' s)) m_empty := by refine (map_ofFunction_le _).antisymm fun s => ?_ simp only [ofFunction_apply, map_apply, le_iInf_iff] intro t ht refine iInf_le_of_le (fun n => (range f)ᶜ ∪ f '' t n) (iInf_le_of_le ?_ ?_) · rw [← union_iUnion, ← inter_subset, ← image_preimage_eq_inter_range, ← image_iUnion] exact image_subset _ ht · refine ENNReal.tsum_le_tsum fun n => le_of_eq ?_ simp [hf.preimage_image] -- TODO (kmill): change `m (t ∩ s)` to `m (s ∩ t)` theorem restrict_ofFunction (s : Set α) (hm : Monotone m) : restrict s (OuterMeasure.ofFunction m m_empty) = OuterMeasure.ofFunction (fun t => m (t ∩ s)) (by simp; simp [m_empty]) := by rw [restrict] simp only [inter_comm _ s, LinearMap.comp_apply] rw [comap_ofFunction _ (Or.inl hm)] simp only [map_ofFunction Subtype.coe_injective, Subtype.image_preimage_coe] theorem smul_ofFunction {c : ℝ≥0∞} (hc : c ≠ ∞) : c • OuterMeasure.ofFunction m m_empty = OuterMeasure.ofFunction (c • m) (by simp [m_empty]) := by ext1 s haveI : Nonempty { t : ℕ → Set α // s ⊆ ⋃ i, t i } := ⟨⟨fun _ => s, subset_iUnion (fun _ => s) 0⟩⟩ simp only [smul_apply, ofFunction_apply, ENNReal.tsum_mul_left, Pi.smul_apply, smul_eq_mul, iInf_subtype'] rw [ENNReal.mul_iInf fun h => (hc h).elim] end OfFunction section BoundedBy variable {α : Type*} (m : Set α → ℝ≥0∞) /-- Given any function `m` assigning measures to sets, there is a unique maximal outer measure `μ` satisfying `μ s ≤ m s` for all `s : Set α`. This is the same as `OuterMeasure.ofFunction`, except that it doesn't require `m ∅ = 0`. -/ def boundedBy : OuterMeasure α := OuterMeasure.ofFunction (fun s => ⨆ _ : s.Nonempty, m s) (by simp [Set.not_nonempty_empty]) variable {m} theorem boundedBy_le (s : Set α) : boundedBy m s ≤ m s := (ofFunction_le _).trans iSup_const_le theorem boundedBy_eq_ofFunction (m_empty : m ∅ = 0) (s : Set α) : boundedBy m s = OuterMeasure.ofFunction m m_empty s := by have : (fun s : Set α => ⨆ _ : s.Nonempty, m s) = m := by ext1 t rcases t.eq_empty_or_nonempty with h | h <;> simp [h, Set.not_nonempty_empty, m_empty] simp [boundedBy, this]
theorem boundedBy_apply (s : Set α) : boundedBy m s = ⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t),
Mathlib/MeasureTheory/OuterMeasure/OfFunction.lean
260
262
/- Copyright (c) 2021 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Order.ConditionallyCompleteLattice.Basic import Mathlib.Order.Cover import Mathlib.Order.Iterate /-! # Successor and predecessor This file defines successor and predecessor orders. `succ a`, the successor of an element `a : α` is the least element greater than `a`. `pred a` is the greatest element less than `a`. Typical examples include `ℕ`, `ℤ`, `ℕ+`, `Fin n`, but also `ENat`, the lexicographic order of a successor/predecessor order... ## Typeclasses * `SuccOrder`: Order equipped with a sensible successor function. * `PredOrder`: Order equipped with a sensible predecessor function. ## Implementation notes Maximal elements don't have a sensible successor. Thus the naïve typeclass ```lean class NaiveSuccOrder (α : Type*) [Preorder α] where (succ : α → α) (succ_le_iff : ∀ {a b}, succ a ≤ b ↔ a < b) (lt_succ_iff : ∀ {a b}, a < succ b ↔ a ≤ b) ``` can't apply to an `OrderTop` because plugging in `a = b = ⊤` into either of `succ_le_iff` and `lt_succ_iff` yields `⊤ < ⊤` (or more generally `m < m` for a maximal element `m`). The solution taken here is to remove the implications `≤ → <` and instead require that `a < succ a` for all non maximal elements (enforced by the combination of `le_succ` and the contrapositive of `max_of_succ_le`). The stricter condition of every element having a sensible successor can be obtained through the combination of `SuccOrder α` and `NoMaxOrder α`. -/ open Function OrderDual Set variable {α β : Type*} /-- Order equipped with a sensible successor function. -/ @[ext] class SuccOrder (α : Type*) [Preorder α] where /-- Successor function -/ succ : α → α /-- Proof of basic ordering with respect to `succ` -/ le_succ : ∀ a, a ≤ succ a /-- Proof of interaction between `succ` and maximal element -/ max_of_succ_le {a} : succ a ≤ a → IsMax a /-- Proof that `succ a` is the least element greater than `a` -/ succ_le_of_lt {a b} : a < b → succ a ≤ b /-- Order equipped with a sensible predecessor function. -/ @[ext] class PredOrder (α : Type*) [Preorder α] where /-- Predecessor function -/ pred : α → α /-- Proof of basic ordering with respect to `pred` -/ pred_le : ∀ a, pred a ≤ a /-- Proof of interaction between `pred` and minimal element -/ min_of_le_pred {a} : a ≤ pred a → IsMin a /-- Proof that `pred b` is the greatest element less than `b` -/ le_pred_of_lt {a b} : a < b → a ≤ pred b instance [Preorder α] [SuccOrder α] : PredOrder αᵒᵈ where pred := toDual ∘ SuccOrder.succ ∘ ofDual pred_le := by simp only [comp, OrderDual.forall, ofDual_toDual, toDual_le_toDual, SuccOrder.le_succ, implies_true] min_of_le_pred h := by apply SuccOrder.max_of_succ_le h le_pred_of_lt := by intro a b h; exact SuccOrder.succ_le_of_lt h instance [Preorder α] [PredOrder α] : SuccOrder αᵒᵈ where succ := toDual ∘ PredOrder.pred ∘ ofDual le_succ := by simp only [comp, OrderDual.forall, ofDual_toDual, toDual_le_toDual, PredOrder.pred_le, implies_true] max_of_succ_le h := by apply PredOrder.min_of_le_pred h succ_le_of_lt := by intro a b h; exact PredOrder.le_pred_of_lt h section Preorder variable [Preorder α] /-- A constructor for `SuccOrder α` usable when `α` has no maximal element. -/ def SuccOrder.ofSuccLeIff (succ : α → α) (hsucc_le_iff : ∀ {a b}, succ a ≤ b ↔ a < b) : SuccOrder α := { succ le_succ := fun _ => (hsucc_le_iff.1 le_rfl).le max_of_succ_le := fun ha => (lt_irrefl _ <| hsucc_le_iff.1 ha).elim succ_le_of_lt := fun h => hsucc_le_iff.2 h } /-- A constructor for `PredOrder α` usable when `α` has no minimal element. -/ def PredOrder.ofLePredIff (pred : α → α) (hle_pred_iff : ∀ {a b}, a ≤ pred b ↔ a < b) : PredOrder α := { pred pred_le := fun _ => (hle_pred_iff.1 le_rfl).le min_of_le_pred := fun ha => (lt_irrefl _ <| hle_pred_iff.1 ha).elim le_pred_of_lt := fun h => hle_pred_iff.2 h } end Preorder section LinearOrder variable [LinearOrder α] /-- A constructor for `SuccOrder α` for `α` a linear order. -/ @[simps] def SuccOrder.ofCore (succ : α → α) (hn : ∀ {a}, ¬IsMax a → ∀ b, a < b ↔ succ a ≤ b) (hm : ∀ a, IsMax a → succ a = a) : SuccOrder α := { succ succ_le_of_lt := fun {a b} => by_cases (fun h hab => (hm a h).symm ▸ hab.le) fun h => (hn h b).mp le_succ := fun a => by_cases (fun h => (hm a h).symm.le) fun h => le_of_lt <| by simpa using (hn h a).not max_of_succ_le := fun {a} => not_imp_not.mp fun h => by simpa using (hn h a).not } /-- A constructor for `PredOrder α` for `α` a linear order. -/ @[simps] def PredOrder.ofCore (pred : α → α) (hn : ∀ {a}, ¬IsMin a → ∀ b, b ≤ pred a ↔ b < a) (hm : ∀ a, IsMin a → pred a = a) : PredOrder α := { pred le_pred_of_lt := fun {a b} => by_cases (fun h hab => (hm b h).symm ▸ hab.le) fun h => (hn h a).mpr pred_le := fun a => by_cases (fun h => (hm a h).le) fun h => le_of_lt <| by simpa using (hn h a).not min_of_le_pred := fun {a} => not_imp_not.mp fun h => by simpa using (hn h a).not } variable (α) open Classical in /-- A well-order is a `SuccOrder`. -/ noncomputable def SuccOrder.ofLinearWellFoundedLT [WellFoundedLT α] : SuccOrder α := ofCore (fun a ↦ if h : (Ioi a).Nonempty then wellFounded_lt.min _ h else a) (fun ha _ ↦ by rw [not_isMax_iff] at ha simp_rw [Set.Nonempty, mem_Ioi, dif_pos ha] exact ⟨(wellFounded_lt.min_le · ha), lt_of_lt_of_le (wellFounded_lt.min_mem _ ha)⟩) fun _ ha ↦ dif_neg (not_not_intro ha <| not_isMax_iff.mpr ·) /-- A linear order with well-founded greater-than relation is a `PredOrder`. -/ noncomputable def PredOrder.ofLinearWellFoundedGT (α) [LinearOrder α] [WellFoundedGT α] : PredOrder α := letI := SuccOrder.ofLinearWellFoundedLT αᵒᵈ; inferInstanceAs (PredOrder αᵒᵈᵒᵈ) end LinearOrder /-! ### Successor order -/ namespace Order section Preorder variable [Preorder α] [SuccOrder α] {a b : α} /-- The successor of an element. If `a` is not maximal, then `succ a` is the least element greater than `a`. If `a` is maximal, then `succ a = a`. -/ def succ : α → α := SuccOrder.succ theorem le_succ : ∀ a : α, a ≤ succ a := SuccOrder.le_succ theorem max_of_succ_le {a : α} : succ a ≤ a → IsMax a := SuccOrder.max_of_succ_le theorem succ_le_of_lt {a b : α} : a < b → succ a ≤ b := SuccOrder.succ_le_of_lt alias _root_.LT.lt.succ_le := succ_le_of_lt @[simp] theorem succ_le_iff_isMax : succ a ≤ a ↔ IsMax a := ⟨max_of_succ_le, fun h => h <| le_succ _⟩ alias ⟨_root_.IsMax.of_succ_le, _root_.IsMax.succ_le⟩ := succ_le_iff_isMax @[simp] theorem lt_succ_iff_not_isMax : a < succ a ↔ ¬IsMax a := ⟨not_isMax_of_lt, fun ha => (le_succ a).lt_of_not_le fun h => ha <| max_of_succ_le h⟩ alias ⟨_, lt_succ_of_not_isMax⟩ := lt_succ_iff_not_isMax theorem wcovBy_succ (a : α) : a ⩿ succ a := ⟨le_succ a, fun _ hb => (succ_le_of_lt hb).not_lt⟩ theorem covBy_succ_of_not_isMax (h : ¬IsMax a) : a ⋖ succ a := (wcovBy_succ a).covBy_of_lt <| lt_succ_of_not_isMax h theorem lt_succ_of_le_of_not_isMax (hab : b ≤ a) (ha : ¬IsMax a) : b < succ a := hab.trans_lt <| lt_succ_of_not_isMax ha theorem succ_le_iff_of_not_isMax (ha : ¬IsMax a) : succ a ≤ b ↔ a < b := ⟨(lt_succ_of_not_isMax ha).trans_le, succ_le_of_lt⟩ lemma succ_lt_succ_of_not_isMax (h : a < b) (hb : ¬ IsMax b) : succ a < succ b := lt_succ_of_le_of_not_isMax (succ_le_of_lt h) hb @[simp, mono, gcongr] theorem succ_le_succ (h : a ≤ b) : succ a ≤ succ b := by by_cases hb : IsMax b · by_cases hba : b ≤ a · exact (hb <| hba.trans <| le_succ _).trans (le_succ _) · exact succ_le_of_lt ((h.lt_of_not_le hba).trans_le <| le_succ b) · rw [succ_le_iff_of_not_isMax fun ha => hb <| ha.mono h] apply lt_succ_of_le_of_not_isMax h hb theorem succ_mono : Monotone (succ : α → α) := fun _ _ => succ_le_succ /-- See also `Order.succ_eq_of_covBy`. -/ lemma le_succ_of_wcovBy (h : a ⩿ b) : b ≤ succ a := by obtain hab | ⟨-, hba⟩ := h.covBy_or_le_and_le · by_contra hba exact h.2 (lt_succ_of_not_isMax hab.lt.not_isMax) <| hab.lt.succ_le.lt_of_not_le hba · exact hba.trans (le_succ _) alias _root_.WCovBy.le_succ := le_succ_of_wcovBy theorem le_succ_iterate (k : ℕ) (x : α) : x ≤ succ^[k] x := id_le_iterate_of_id_le le_succ _ _ theorem isMax_iterate_succ_of_eq_of_lt {n m : ℕ} (h_eq : succ^[n] a = succ^[m] a) (h_lt : n < m) : IsMax (succ^[n] a) := by refine max_of_succ_le (le_trans ?_ h_eq.symm.le) rw [← iterate_succ_apply' succ] have h_le : n + 1 ≤ m := Nat.succ_le_of_lt h_lt exact Monotone.monotone_iterate_of_le_map succ_mono (le_succ a) h_le theorem isMax_iterate_succ_of_eq_of_ne {n m : ℕ} (h_eq : succ^[n] a = succ^[m] a) (h_ne : n ≠ m) : IsMax (succ^[n] a) := by rcases le_total n m with h | h · exact isMax_iterate_succ_of_eq_of_lt h_eq (lt_of_le_of_ne h h_ne) · rw [h_eq] exact isMax_iterate_succ_of_eq_of_lt h_eq.symm (lt_of_le_of_ne h h_ne.symm) theorem Iic_subset_Iio_succ_of_not_isMax (ha : ¬IsMax a) : Iic a ⊆ Iio (succ a) := fun _ => (lt_succ_of_le_of_not_isMax · ha) theorem Ici_succ_of_not_isMax (ha : ¬IsMax a) : Ici (succ a) = Ioi a := Set.ext fun _ => succ_le_iff_of_not_isMax ha theorem Icc_subset_Ico_succ_right_of_not_isMax (hb : ¬IsMax b) : Icc a b ⊆ Ico a (succ b) := by rw [← Ici_inter_Iio, ← Ici_inter_Iic] gcongr intro _ h apply lt_succ_of_le_of_not_isMax h hb theorem Ioc_subset_Ioo_succ_right_of_not_isMax (hb : ¬IsMax b) : Ioc a b ⊆ Ioo a (succ b) := by rw [← Ioi_inter_Iio, ← Ioi_inter_Iic] gcongr intro _ h apply Iic_subset_Iio_succ_of_not_isMax hb h theorem Icc_succ_left_of_not_isMax (ha : ¬IsMax a) : Icc (succ a) b = Ioc a b := by rw [← Ici_inter_Iic, Ici_succ_of_not_isMax ha, Ioi_inter_Iic] theorem Ico_succ_left_of_not_isMax (ha : ¬IsMax a) : Ico (succ a) b = Ioo a b := by rw [← Ici_inter_Iio, Ici_succ_of_not_isMax ha, Ioi_inter_Iio] section NoMaxOrder variable [NoMaxOrder α] theorem lt_succ (a : α) : a < succ a := lt_succ_of_not_isMax <| not_isMax a @[simp] theorem lt_succ_of_le : a ≤ b → a < succ b := (lt_succ_of_le_of_not_isMax · <| not_isMax b) @[simp] theorem succ_le_iff : succ a ≤ b ↔ a < b := succ_le_iff_of_not_isMax <| not_isMax a @[gcongr] theorem succ_lt_succ (hab : a < b) : succ a < succ b := by simp [hab] theorem succ_strictMono : StrictMono (succ : α → α) := fun _ _ => succ_lt_succ theorem covBy_succ (a : α) : a ⋖ succ a := covBy_succ_of_not_isMax <| not_isMax a theorem Iic_subset_Iio_succ (a : α) : Iic a ⊆ Iio (succ a) := by simp @[simp] theorem Ici_succ (a : α) : Ici (succ a) = Ioi a := Ici_succ_of_not_isMax <| not_isMax _ @[simp] theorem Icc_subset_Ico_succ_right (a b : α) : Icc a b ⊆ Ico a (succ b) := Icc_subset_Ico_succ_right_of_not_isMax <| not_isMax _ @[simp] theorem Ioc_subset_Ioo_succ_right (a b : α) : Ioc a b ⊆ Ioo a (succ b) := Ioc_subset_Ioo_succ_right_of_not_isMax <| not_isMax _ @[simp] theorem Icc_succ_left (a b : α) : Icc (succ a) b = Ioc a b := Icc_succ_left_of_not_isMax <| not_isMax _ @[simp] theorem Ico_succ_left (a b : α) : Ico (succ a) b = Ioo a b := Ico_succ_left_of_not_isMax <| not_isMax _ end NoMaxOrder end Preorder section PartialOrder variable [PartialOrder α] [SuccOrder α] {a b : α} @[simp] theorem succ_eq_iff_isMax : succ a = a ↔ IsMax a := ⟨fun h => max_of_succ_le h.le, fun h => h.eq_of_ge <| le_succ _⟩ alias ⟨_, _root_.IsMax.succ_eq⟩ := succ_eq_iff_isMax lemma le_iff_eq_or_succ_le : a ≤ b ↔ a = b ∨ succ a ≤ b := by by_cases ha : IsMax a · simpa [ha.succ_eq] using le_of_eq · rw [succ_le_iff_of_not_isMax ha, le_iff_eq_or_lt] theorem le_le_succ_iff : a ≤ b ∧ b ≤ succ a ↔ b = a ∨ b = succ a := by refine ⟨fun h => or_iff_not_imp_left.2 fun hba : b ≠ a => h.2.antisymm (succ_le_of_lt <| h.1.lt_of_ne <| hba.symm), ?_⟩ rintro (rfl | rfl) · exact ⟨le_rfl, le_succ b⟩ · exact ⟨le_succ a, le_rfl⟩ /-- See also `Order.le_succ_of_wcovBy`. -/ lemma succ_eq_of_covBy (h : a ⋖ b) : succ a = b := (succ_le_of_lt h.lt).antisymm h.wcovBy.le_succ alias _root_.CovBy.succ_eq := succ_eq_of_covBy theorem _root_.OrderIso.map_succ [PartialOrder β] [SuccOrder β] (f : α ≃o β) (a : α) : f (succ a) = succ (f a) := by by_cases h : IsMax a · rw [h.succ_eq, (f.isMax_apply.2 h).succ_eq] · exact (f.map_covBy.2 <| covBy_succ_of_not_isMax h).succ_eq.symm section NoMaxOrder variable [NoMaxOrder α] theorem succ_eq_iff_covBy : succ a = b ↔ a ⋖ b := ⟨by rintro rfl; exact covBy_succ _, CovBy.succ_eq⟩ end NoMaxOrder section OrderTop variable [OrderTop α] @[simp] theorem succ_top : succ (⊤ : α) = ⊤ := by rw [succ_eq_iff_isMax, isMax_iff_eq_top] theorem succ_le_iff_eq_top : succ a ≤ a ↔ a = ⊤ := succ_le_iff_isMax.trans isMax_iff_eq_top theorem lt_succ_iff_ne_top : a < succ a ↔ a ≠ ⊤ := lt_succ_iff_not_isMax.trans not_isMax_iff_ne_top end OrderTop section OrderBot variable [OrderBot α] [Nontrivial α] theorem bot_lt_succ (a : α) : ⊥ < succ a := (lt_succ_of_not_isMax not_isMax_bot).trans_le <| succ_mono bot_le theorem succ_ne_bot (a : α) : succ a ≠ ⊥ := (bot_lt_succ a).ne' end OrderBot end PartialOrder section LinearOrder variable [LinearOrder α] [SuccOrder α] {a b : α} theorem le_of_lt_succ {a b : α} : a < succ b → a ≤ b := fun h ↦ by by_contra! nh exact (h.trans_le (succ_le_of_lt nh)).false theorem lt_succ_iff_of_not_isMax (ha : ¬IsMax a) : b < succ a ↔ b ≤ a := ⟨le_of_lt_succ, fun h => h.trans_lt <| lt_succ_of_not_isMax ha⟩ theorem succ_lt_succ_iff_of_not_isMax (ha : ¬IsMax a) (hb : ¬IsMax b) : succ a < succ b ↔ a < b := by rw [lt_succ_iff_of_not_isMax hb, succ_le_iff_of_not_isMax ha] theorem succ_le_succ_iff_of_not_isMax (ha : ¬IsMax a) (hb : ¬IsMax b) : succ a ≤ succ b ↔ a ≤ b := by rw [succ_le_iff_of_not_isMax ha, lt_succ_iff_of_not_isMax hb] theorem Iio_succ_of_not_isMax (ha : ¬IsMax a) : Iio (succ a) = Iic a := Set.ext fun _ => lt_succ_iff_of_not_isMax ha theorem Ico_succ_right_of_not_isMax (hb : ¬IsMax b) : Ico a (succ b) = Icc a b := by rw [← Ici_inter_Iio, Iio_succ_of_not_isMax hb, Ici_inter_Iic] theorem Ioo_succ_right_of_not_isMax (hb : ¬IsMax b) : Ioo a (succ b) = Ioc a b := by rw [← Ioi_inter_Iio, Iio_succ_of_not_isMax hb, Ioi_inter_Iic] theorem succ_eq_succ_iff_of_not_isMax (ha : ¬IsMax a) (hb : ¬IsMax b) : succ a = succ b ↔ a = b := by rw [eq_iff_le_not_lt, eq_iff_le_not_lt, succ_le_succ_iff_of_not_isMax ha hb, succ_lt_succ_iff_of_not_isMax ha hb] theorem le_succ_iff_eq_or_le : a ≤ succ b ↔ a = succ b ∨ a ≤ b := by by_cases hb : IsMax b · rw [hb.succ_eq, or_iff_right_of_imp le_of_eq] · rw [← lt_succ_iff_of_not_isMax hb, le_iff_eq_or_lt] theorem lt_succ_iff_eq_or_lt_of_not_isMax (hb : ¬IsMax b) : a < succ b ↔ a = b ∨ a < b := (lt_succ_iff_of_not_isMax hb).trans le_iff_eq_or_lt theorem not_isMin_succ [Nontrivial α] (a : α) : ¬ IsMin (succ a) := by obtain ha | ha := (le_succ a).eq_or_lt · exact (ha ▸ succ_eq_iff_isMax.1 ha.symm).not_isMin · exact not_isMin_of_lt ha theorem Iic_succ (a : α) : Iic (succ a) = insert (succ a) (Iic a) := ext fun _ => le_succ_iff_eq_or_le theorem Icc_succ_right (h : a ≤ succ b) : Icc a (succ b) = insert (succ b) (Icc a b) := by simp_rw [← Ici_inter_Iic, Iic_succ, inter_insert_of_mem (mem_Ici.2 h)] theorem Ioc_succ_right (h : a < succ b) : Ioc a (succ b) = insert (succ b) (Ioc a b) := by simp_rw [← Ioi_inter_Iic, Iic_succ, inter_insert_of_mem (mem_Ioi.2 h)] theorem Iio_succ_eq_insert_of_not_isMax (h : ¬IsMax a) : Iio (succ a) = insert a (Iio a) := ext fun _ => lt_succ_iff_eq_or_lt_of_not_isMax h theorem Ico_succ_right_eq_insert_of_not_isMax (h₁ : a ≤ b) (h₂ : ¬IsMax b) : Ico a (succ b) = insert b (Ico a b) := by simp_rw [← Iio_inter_Ici, Iio_succ_eq_insert_of_not_isMax h₂, insert_inter_of_mem (mem_Ici.2 h₁)] theorem Ioo_succ_right_eq_insert_of_not_isMax (h₁ : a < b) (h₂ : ¬IsMax b) : Ioo a (succ b) = insert b (Ioo a b) := by simp_rw [← Iio_inter_Ioi, Iio_succ_eq_insert_of_not_isMax h₂, insert_inter_of_mem (mem_Ioi.2 h₁)] section NoMaxOrder variable [NoMaxOrder α] @[simp] theorem lt_succ_iff : a < succ b ↔ a ≤ b := lt_succ_iff_of_not_isMax <| not_isMax b theorem succ_le_succ_iff : succ a ≤ succ b ↔ a ≤ b := by simp theorem succ_lt_succ_iff : succ a < succ b ↔ a < b := by simp alias ⟨le_of_succ_le_succ, _⟩ := succ_le_succ_iff alias ⟨lt_of_succ_lt_succ, _⟩ := succ_lt_succ_iff -- TODO: prove for a succ-archimedean non-linear order with bottom @[simp] theorem Iio_succ (a : α) : Iio (succ a) = Iic a := Iio_succ_of_not_isMax <| not_isMax _ @[simp] theorem Ico_succ_right (a b : α) : Ico a (succ b) = Icc a b := Ico_succ_right_of_not_isMax <| not_isMax _ -- TODO: prove for a succ-archimedean non-linear order @[simp] theorem Ioo_succ_right (a b : α) : Ioo a (succ b) = Ioc a b := Ioo_succ_right_of_not_isMax <| not_isMax _ @[simp] theorem succ_eq_succ_iff : succ a = succ b ↔ a = b := succ_eq_succ_iff_of_not_isMax (not_isMax a) (not_isMax b) theorem succ_injective : Injective (succ : α → α) := fun _ _ => succ_eq_succ_iff.1 theorem succ_ne_succ_iff : succ a ≠ succ b ↔ a ≠ b := succ_injective.ne_iff alias ⟨_, succ_ne_succ⟩ := succ_ne_succ_iff theorem lt_succ_iff_eq_or_lt : a < succ b ↔ a = b ∨ a < b := lt_succ_iff.trans le_iff_eq_or_lt theorem Iio_succ_eq_insert (a : α) : Iio (succ a) = insert a (Iio a) := Iio_succ_eq_insert_of_not_isMax <| not_isMax a theorem Ico_succ_right_eq_insert (h : a ≤ b) : Ico a (succ b) = insert b (Ico a b) := Ico_succ_right_eq_insert_of_not_isMax h <| not_isMax b theorem Ioo_succ_right_eq_insert (h : a < b) : Ioo a (succ b) = insert b (Ioo a b) := Ioo_succ_right_eq_insert_of_not_isMax h <| not_isMax b @[simp] theorem Ioo_eq_empty_iff_le_succ : Ioo a b = ∅ ↔ b ≤ succ a := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · contrapose! h exact ⟨succ a, lt_succ_iff_not_isMax.mpr (not_isMax a), h⟩ · ext x suffices a < x → b ≤ x by simpa exact fun hx ↦ le_of_lt_succ <| lt_of_le_of_lt h <| succ_strictMono hx end NoMaxOrder section OrderBot variable [OrderBot α] theorem lt_succ_bot_iff [NoMaxOrder α] : a < succ ⊥ ↔ a = ⊥ := by rw [lt_succ_iff, le_bot_iff] theorem le_succ_bot_iff : a ≤ succ ⊥ ↔ a = ⊥ ∨ a = succ ⊥ := by rw [le_succ_iff_eq_or_le, le_bot_iff, or_comm] end OrderBot end LinearOrder /-- There is at most one way to define the successors in a `PartialOrder`. -/ instance [PartialOrder α] : Subsingleton (SuccOrder α) := ⟨by intro h₀ h₁ ext a by_cases ha : IsMax a · exact (@IsMax.succ_eq _ _ h₀ _ ha).trans ha.succ_eq.symm · exact @CovBy.succ_eq _ _ h₀ _ _ (covBy_succ_of_not_isMax ha)⟩ theorem succ_eq_sInf [CompleteLattice α] [SuccOrder α] (a : α) : succ a = sInf (Set.Ioi a) := by apply (le_sInf fun b => succ_le_of_lt).antisymm obtain rfl | ha := eq_or_ne a ⊤ · rw [succ_top] exact le_top · exact sInf_le (lt_succ_iff_ne_top.2 ha) theorem succ_eq_iInf [CompleteLattice α] [SuccOrder α] (a : α) : succ a = ⨅ b > a, b := by rw [succ_eq_sInf, iInf_subtype', iInf, Subtype.range_coe_subtype, Ioi] theorem succ_eq_csInf [ConditionallyCompleteLattice α] [SuccOrder α] [NoMaxOrder α] (a : α) : succ a = sInf (Set.Ioi a) := by apply (le_csInf nonempty_Ioi fun b => succ_le_of_lt).antisymm exact csInf_le ⟨a, fun b => le_of_lt⟩ <| lt_succ a /-! ### Predecessor order -/ section Preorder variable [Preorder α] [PredOrder α] {a b : α} /-- The predecessor of an element. If `a` is not minimal, then `pred a` is the greatest element less than `a`. If `a` is minimal, then `pred a = a`. -/ def pred : α → α := PredOrder.pred theorem pred_le : ∀ a : α, pred a ≤ a := PredOrder.pred_le theorem min_of_le_pred {a : α} : a ≤ pred a → IsMin a := PredOrder.min_of_le_pred theorem le_pred_of_lt {a b : α} : a < b → a ≤ pred b := PredOrder.le_pred_of_lt alias _root_.LT.lt.le_pred := le_pred_of_lt @[simp] theorem le_pred_iff_isMin : a ≤ pred a ↔ IsMin a := ⟨min_of_le_pred, fun h => h <| pred_le _⟩ alias ⟨_root_.IsMin.of_le_pred, _root_.IsMin.le_pred⟩ := le_pred_iff_isMin @[simp] theorem pred_lt_iff_not_isMin : pred a < a ↔ ¬IsMin a := ⟨not_isMin_of_lt, fun ha => (pred_le a).lt_of_not_le fun h => ha <| min_of_le_pred h⟩ alias ⟨_, pred_lt_of_not_isMin⟩ := pred_lt_iff_not_isMin theorem pred_wcovBy (a : α) : pred a ⩿ a := ⟨pred_le a, fun _ hb nh => (le_pred_of_lt nh).not_lt hb⟩ theorem pred_covBy_of_not_isMin (h : ¬IsMin a) : pred a ⋖ a := (pred_wcovBy a).covBy_of_lt <| pred_lt_of_not_isMin h theorem pred_lt_of_not_isMin_of_le (ha : ¬IsMin a) : a ≤ b → pred a < b := (pred_lt_of_not_isMin ha).trans_le theorem le_pred_iff_of_not_isMin (ha : ¬IsMin a) : b ≤ pred a ↔ b < a := ⟨fun h => h.trans_lt <| pred_lt_of_not_isMin ha, le_pred_of_lt⟩ lemma pred_lt_pred_of_not_isMin (h : a < b) (ha : ¬ IsMin a) : pred a < pred b := pred_lt_of_not_isMin_of_le ha <| le_pred_of_lt h theorem pred_le_pred_of_not_isMin_of_le (ha : ¬IsMin a) (hb : ¬IsMin b) : a ≤ b → pred a ≤ pred b := by rw [le_pred_iff_of_not_isMin hb] apply pred_lt_of_not_isMin_of_le ha @[simp, mono, gcongr] theorem pred_le_pred {a b : α} (h : a ≤ b) : pred a ≤ pred b := succ_le_succ h.dual theorem pred_mono : Monotone (pred : α → α) := fun _ _ => pred_le_pred /-- See also `Order.pred_eq_of_covBy`. -/ lemma pred_le_of_wcovBy (h : a ⩿ b) : pred b ≤ a := by obtain hab | ⟨-, hba⟩ := h.covBy_or_le_and_le · by_contra hba exact h.2 (hab.lt.le_pred.lt_of_not_le hba) (pred_lt_of_not_isMin hab.lt.not_isMin) · exact (pred_le _).trans hba alias _root_.WCovBy.pred_le := pred_le_of_wcovBy theorem pred_iterate_le (k : ℕ) (x : α) : pred^[k] x ≤ x := by conv_rhs => rw [(by simp only [Function.iterate_id, id] : x = id^[k] x)] exact Monotone.iterate_le_of_le pred_mono pred_le k x theorem isMin_iterate_pred_of_eq_of_lt {n m : ℕ} (h_eq : pred^[n] a = pred^[m] a) (h_lt : n < m) : IsMin (pred^[n] a) := @isMax_iterate_succ_of_eq_of_lt αᵒᵈ _ _ _ _ _ h_eq h_lt theorem isMin_iterate_pred_of_eq_of_ne {n m : ℕ} (h_eq : pred^[n] a = pred^[m] a) (h_ne : n ≠ m) : IsMin (pred^[n] a) := @isMax_iterate_succ_of_eq_of_ne αᵒᵈ _ _ _ _ _ h_eq h_ne theorem Ici_subset_Ioi_pred_of_not_isMin (ha : ¬IsMin a) : Ici a ⊆ Ioi (pred a) := fun _ ↦ pred_lt_of_not_isMin_of_le ha theorem Iic_pred_of_not_isMin (ha : ¬IsMin a) : Iic (pred a) = Iio a := Set.ext fun _ => le_pred_iff_of_not_isMin ha theorem Icc_subset_Ioc_pred_left_of_not_isMin (ha : ¬IsMin a) : Icc a b ⊆ Ioc (pred a) b := by rw [← Ioi_inter_Iic, ← Ici_inter_Iic] gcongr apply Ici_subset_Ioi_pred_of_not_isMin ha theorem Ico_subset_Ioo_pred_left_of_not_isMin (ha : ¬IsMin a) : Ico a b ⊆ Ioo (pred a) b := by rw [← Ioi_inter_Iio, ← Ici_inter_Iio] gcongr apply Ici_subset_Ioi_pred_of_not_isMin ha theorem Icc_pred_right_of_not_isMin (ha : ¬IsMin b) : Icc a (pred b) = Ico a b := by rw [← Ici_inter_Iic, Iic_pred_of_not_isMin ha, Ici_inter_Iio] theorem Ioc_pred_right_of_not_isMin (ha : ¬IsMin b) : Ioc a (pred b) = Ioo a b := by rw [← Ioi_inter_Iic, Iic_pred_of_not_isMin ha, Ioi_inter_Iio] section NoMinOrder variable [NoMinOrder α] theorem pred_lt (a : α) : pred a < a := pred_lt_of_not_isMin <| not_isMin a @[simp] theorem pred_lt_of_le : a ≤ b → pred a < b := pred_lt_of_not_isMin_of_le <| not_isMin a @[simp] theorem le_pred_iff : a ≤ pred b ↔ a < b := le_pred_iff_of_not_isMin <| not_isMin b theorem pred_le_pred_of_le : a ≤ b → pred a ≤ pred b := by intro; simp_all theorem pred_lt_pred : a < b → pred a < pred b := by intro; simp_all theorem pred_strictMono : StrictMono (pred : α → α) := fun _ _ => pred_lt_pred theorem pred_covBy (a : α) : pred a ⋖ a := pred_covBy_of_not_isMin <| not_isMin a theorem Ici_subset_Ioi_pred (a : α) : Ici a ⊆ Ioi (pred a) := by simp @[simp] theorem Iic_pred (a : α) : Iic (pred a) = Iio a := Iic_pred_of_not_isMin <| not_isMin a @[simp] theorem Icc_subset_Ioc_pred_left (a b : α) : Icc a b ⊆ Ioc (pred a) b := Icc_subset_Ioc_pred_left_of_not_isMin <| not_isMin _ @[simp] theorem Ico_subset_Ioo_pred_left (a b : α) : Ico a b ⊆ Ioo (pred a) b := Ico_subset_Ioo_pred_left_of_not_isMin <| not_isMin _ @[simp] theorem Icc_pred_right (a b : α) : Icc a (pred b) = Ico a b := Icc_pred_right_of_not_isMin <| not_isMin _ @[simp] theorem Ioc_pred_right (a b : α) : Ioc a (pred b) = Ioo a b := Ioc_pred_right_of_not_isMin <| not_isMin _ end NoMinOrder end Preorder section PartialOrder variable [PartialOrder α] [PredOrder α] {a b : α} @[simp] theorem pred_eq_iff_isMin : pred a = a ↔ IsMin a := ⟨fun h => min_of_le_pred h.ge, fun h => h.eq_of_le <| pred_le _⟩ alias ⟨_, _root_.IsMin.pred_eq⟩ := pred_eq_iff_isMin lemma le_iff_eq_or_le_pred : a ≤ b ↔ a = b ∨ a ≤ pred b := by by_cases hb : IsMin b · simpa [hb.pred_eq] using le_of_eq · rw [le_pred_iff_of_not_isMin hb, le_iff_eq_or_lt] theorem pred_le_le_iff {a b : α} : pred a ≤ b ∧ b ≤ a ↔ b = a ∨ b = pred a := by refine ⟨fun h => or_iff_not_imp_left.2 fun hba : b ≠ a => (le_pred_of_lt <| h.2.lt_of_ne hba).antisymm h.1, ?_⟩ rintro (rfl | rfl) · exact ⟨pred_le b, le_rfl⟩ · exact ⟨le_rfl, pred_le a⟩ /-- See also `Order.pred_le_of_wcovBy`. -/ lemma pred_eq_of_covBy (h : a ⋖ b) : pred b = a := h.wcovBy.pred_le.antisymm (le_pred_of_lt h.lt) alias _root_.CovBy.pred_eq := pred_eq_of_covBy theorem _root_.OrderIso.map_pred {β : Type*} [PartialOrder β] [PredOrder β] (f : α ≃o β) (a : α) : f (pred a) = pred (f a) := f.dual.map_succ a section NoMinOrder
variable [NoMinOrder α]
Mathlib/Order/SuccPred/Basic.lean
743
743
/- 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.Algebra.NeZero 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 /-! # Image and map operations on finite sets This file provides the finite analog of `Set.image`, along with some other similar functions. Note there are two ways to take the image over a finset; via `Finset.image` which applies the function then removes duplicates (requiring `DecidableEq`), or via `Finset.map` which exploits injectivity of the function to avoid needing to deduplicate. Choosing between these is similar to choosing between `insert` and `Finset.cons`, or between `Finset.union` and `Finset.disjUnion`. ## Main definitions * `Finset.image`: Given a function `f : α → β`, `s.image f` is the image finset in `β`. * `Finset.map`: Given an embedding `f : α ↪ β`, `s.map f` is the image finset in `β`. * `Finset.filterMap` Given a function `f : α → Option β`, `s.filterMap f` is the image finset in `β`, filtering out `none`s. * `Finset.subtype`: `s.subtype p` is the finset of `Subtype p` whose elements belong to `s`. * `Finset.fin`:`s.fin n` is the finset of all elements of `s` less than `n`. -/ assert_not_exists Monoid OrderedCommMonoid variable {α β γ : Type*} open Multiset open Function namespace Finset /-! ### map -/ section Map open Function /-- When `f` is an embedding of `α` in `β` and `s` is a finset in `α`, then `s.map f` is the image finset in `β`. The embedding condition guarantees that there are no duplicates in the image. -/ def map (f : α ↪ β) (s : Finset α) : Finset β := ⟨s.1.map f, s.2.map f.2⟩ @[simp] theorem map_val (f : α ↪ β) (s : Finset α) : (map f s).1 = s.1.map f := rfl @[simp] theorem map_empty (f : α ↪ β) : (∅ : Finset α).map f = ∅ := rfl variable {f : α ↪ β} {s : Finset α} @[simp] theorem mem_map {b : β} : b ∈ s.map f ↔ ∃ a ∈ s, f a = b := Multiset.mem_map -- Higher priority to apply before `mem_map`. @[simp 1100] theorem mem_map_equiv {f : α ≃ β} {b : β} : b ∈ s.map f.toEmbedding ↔ f.symm b ∈ s := by rw [mem_map] exact ⟨by rintro ⟨a, H, rfl⟩ simpa, fun h => ⟨_, h, by simp⟩⟩ @[simp 1100] theorem mem_map' (f : α ↪ β) {a} {s : Finset α} : f a ∈ s.map f ↔ a ∈ s := mem_map_of_injective f.2 theorem mem_map_of_mem (f : α ↪ β) {a} {s : Finset α} : a ∈ s → f a ∈ s.map f := (mem_map' _).2 theorem forall_mem_map {f : α ↪ β} {s : Finset α} {p : ∀ a, a ∈ s.map f → Prop} : (∀ y (H : y ∈ s.map f), p y H) ↔ ∀ x (H : x ∈ s), p (f x) (mem_map_of_mem _ H) := ⟨fun h y hy => h (f y) (mem_map_of_mem _ hy), fun h x hx => by obtain ⟨y, hy, rfl⟩ := mem_map.1 hx exact h _ hy⟩ theorem apply_coe_mem_map (f : α ↪ β) (s : Finset α) (x : s) : f x ∈ s.map f := mem_map_of_mem f x.prop @[simp, norm_cast] theorem coe_map (f : α ↪ β) (s : Finset α) : (s.map f : Set β) = f '' s := Set.ext (by simp only [mem_coe, mem_map, Set.mem_image, implies_true]) theorem coe_map_subset_range (f : α ↪ β) (s : Finset α) : (s.map f : Set β) ⊆ Set.range f := calc ↑(s.map f) = f '' s := coe_map f s _ ⊆ Set.range f := Set.image_subset_range f ↑s /-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect. -/ theorem map_perm {σ : Equiv.Perm α} (hs : { a | σ a ≠ a } ⊆ s) : s.map (σ : α ↪ α) = s := coe_injective <| (coe_map _ _).trans <| Set.image_perm hs theorem map_toFinset [DecidableEq α] [DecidableEq β] {s : Multiset α} : s.toFinset.map f = (s.map f).toFinset := ext fun _ => by simp only [mem_map, Multiset.mem_map, exists_prop, Multiset.mem_toFinset] @[simp] theorem map_refl : s.map (Embedding.refl _) = s := ext fun _ => by simpa only [mem_map, exists_prop] using exists_eq_right @[simp] theorem map_cast_heq {α β} (h : α = β) (s : Finset α) : HEq (s.map (Equiv.cast h).toEmbedding) s := by subst h simp theorem map_map (f : α ↪ β) (g : β ↪ γ) (s : Finset α) : (s.map f).map g = s.map (f.trans g) := eq_of_veq <| by simp only [map_val, Multiset.map_map]; rfl theorem map_comm {β'} {f : β ↪ γ} {g : α ↪ β} {f' : α ↪ β'} {g' : β' ↪ γ} (h_comm : ∀ a, f (g a) = g' (f' a)) : (s.map g).map f = (s.map f').map g' := by simp_rw [map_map, Embedding.trans, Function.comp_def, h_comm] theorem _root_.Function.Semiconj.finset_map {f : α ↪ β} {ga : α ↪ α} {gb : β ↪ β} (h : Function.Semiconj f ga gb) : Function.Semiconj (map f) (map ga) (map gb) := fun _ => map_comm h theorem _root_.Function.Commute.finset_map {f g : α ↪ α} (h : Function.Commute f g) : Function.Commute (map f) (map g) := Function.Semiconj.finset_map h @[simp] theorem map_subset_map {s₁ s₂ : Finset α} : s₁.map f ⊆ s₂.map f ↔ s₁ ⊆ s₂ := ⟨fun h _ xs => (mem_map' _).1 <| h <| (mem_map' f).2 xs, fun h => by simp [subset_def, Multiset.map_subset_map h]⟩ @[gcongr] alias ⟨_, _root_.GCongr.finsetMap_subset⟩ := map_subset_map /-- The `Finset` version of `Equiv.subset_symm_image`. -/ theorem subset_map_symm {t : Finset β} {f : α ≃ β} : s ⊆ t.map f.symm ↔ s.map f ⊆ t := by constructor <;> intro h x hx · simp only [mem_map_equiv, Equiv.symm_symm] at hx simpa using h hx · simp only [mem_map_equiv] exact h (by simp [hx]) /-- The `Finset` version of `Equiv.symm_image_subset`. -/ theorem map_symm_subset {t : Finset β} {f : α ≃ β} : t.map f.symm ⊆ s ↔ t ⊆ s.map f := by simp only [← subset_map_symm, Equiv.symm_symm] /-- Associate to an embedding `f` from `α` to `β` the order embedding that maps a finset to its image under `f`. -/ def mapEmbedding (f : α ↪ β) : Finset α ↪o Finset β := OrderEmbedding.ofMapLEIff (map f) fun _ _ => map_subset_map @[simp] theorem map_inj {s₁ s₂ : Finset α} : s₁.map f = s₂.map f ↔ s₁ = s₂ := (mapEmbedding f).injective.eq_iff theorem map_injective (f : α ↪ β) : Injective (map f) := (mapEmbedding f).injective @[simp] theorem map_ssubset_map {s t : Finset α} : s.map f ⊂ t.map f ↔ s ⊂ t := (mapEmbedding f).lt_iff_lt @[gcongr] alias ⟨_, _root_.GCongr.finsetMap_ssubset⟩ := map_ssubset_map @[simp] theorem mapEmbedding_apply : mapEmbedding f s = map f s := rfl theorem filter_map {p : β → Prop} [DecidablePred p] : (s.map f).filter p = (s.filter (p ∘ f)).map f := eq_of_veq (Multiset.filter_map _ _ _) lemma map_filter' (p : α → Prop) [DecidablePred p] (f : α ↪ β) (s : Finset α) [DecidablePred (∃ a, p a ∧ f a = ·)] : (s.filter p).map f = (s.map f).filter fun b => ∃ a, p a ∧ f a = b := by simp [Function.comp_def, filter_map, f.injective.eq_iff] lemma filter_attach' [DecidableEq α] (s : Finset α) (p : s → Prop) [DecidablePred p] : s.attach.filter p = (s.filter fun x => ∃ h, p ⟨x, h⟩).attach.map ⟨Subtype.map id <| filter_subset _ _, Subtype.map_injective _ injective_id⟩ := eq_of_veq <| Multiset.filter_attach' _ _ lemma filter_attach (p : α → Prop) [DecidablePred p] (s : Finset α) : s.attach.filter (fun a : s ↦ p a) = (s.filter p).attach.map ((Embedding.refl _).subtypeMap mem_of_mem_filter) := eq_of_veq <| Multiset.filter_attach _ _ theorem map_filter {f : α ≃ β} {p : α → Prop} [DecidablePred p] : (s.filter p).map f.toEmbedding = (s.map f.toEmbedding).filter (p ∘ f.symm) := by simp only [filter_map, Function.comp_def, Equiv.toEmbedding_apply, Equiv.symm_apply_apply] @[simp] theorem disjoint_map {s t : Finset α} (f : α ↪ β) : Disjoint (s.map f) (t.map f) ↔ Disjoint s t := mod_cast Set.disjoint_image_iff f.injective (s := s) (t := t) theorem map_disjUnion {f : α ↪ β} (s₁ s₂ : Finset α) (h) (h' := (disjoint_map _).mpr h) : (s₁.disjUnion s₂ h).map f = (s₁.map f).disjUnion (s₂.map f) h' := eq_of_veq <| Multiset.map_add _ _ _ /-- A version of `Finset.map_disjUnion` for writing in the other direction. -/ theorem map_disjUnion' {f : α ↪ β} (s₁ s₂ : Finset α) (h') (h := (disjoint_map _).mp h') : (s₁.disjUnion s₂ h).map f = (s₁.map f).disjUnion (s₂.map f) h' := map_disjUnion _ _ _ theorem map_union [DecidableEq α] [DecidableEq β] {f : α ↪ β} (s₁ s₂ : Finset α) : (s₁ ∪ s₂).map f = s₁.map f ∪ s₂.map f := mod_cast Set.image_union f s₁ s₂ theorem map_inter [DecidableEq α] [DecidableEq β] {f : α ↪ β} (s₁ s₂ : Finset α) : (s₁ ∩ s₂).map f = s₁.map f ∩ s₂.map f := mod_cast Set.image_inter f.injective (s := s₁) (t := s₂) @[simp] theorem map_singleton (f : α ↪ β) (a : α) : map f {a} = {f a} := coe_injective <| by simp only [coe_map, coe_singleton, Set.image_singleton] @[simp] theorem map_insert [DecidableEq α] [DecidableEq β] (f : α ↪ β) (a : α) (s : Finset α) : (insert a s).map f = insert (f a) (s.map f) := by simp only [insert_eq, map_union, map_singleton] @[simp] theorem map_cons (f : α ↪ β) (a : α) (s : Finset α) (ha : a ∉ s) : (cons a s ha).map f = cons (f a) (s.map f) (by simpa using ha) := eq_of_veq <| Multiset.map_cons f a s.val @[simp] theorem map_eq_empty : s.map f = ∅ ↔ s = ∅ := (map_injective f).eq_iff' (map_empty f) @[simp] theorem map_nonempty : (s.map f).Nonempty ↔ s.Nonempty := mod_cast Set.image_nonempty (f := f) (s := s) @[aesop safe apply (rule_sets := [finsetNonempty])] protected alias ⟨_, Nonempty.map⟩ := map_nonempty @[simp] theorem map_nontrivial : (s.map f).Nontrivial ↔ s.Nontrivial := mod_cast Set.image_nontrivial f.injective (s := s) theorem attach_map_val {s : Finset α} : s.attach.map (Embedding.subtype _) = s := eq_of_veq <| by rw [map_val, attach_val]; exact Multiset.attach_map_val _ end Map theorem range_add_one' (n : ℕ) : range (n + 1) = insert 0 ((range n).map ⟨fun i => i + 1, fun i j => by simp⟩) := by ext (⟨⟩ | ⟨n⟩) <;> simp [Nat.zero_lt_succ n] /-! ### image -/ section Image variable [DecidableEq β] /-- `image f s` is the forward image of `s` under `f`. -/ def image (f : α → β) (s : Finset α) : Finset β := (s.1.map f).toFinset @[simp] theorem image_val (f : α → β) (s : Finset α) : (image f s).1 = (s.1.map f).dedup := rfl @[simp] theorem image_empty (f : α → β) : (∅ : Finset α).image f = ∅ := rfl variable {f g : α → β} {s : Finset α} {t : Finset β} {a : α} {b c : β} @[simp] theorem mem_image : b ∈ s.image f ↔ ∃ a ∈ s, f a = b := by simp only [mem_def, image_val, mem_dedup, Multiset.mem_map, exists_prop] theorem mem_image_of_mem (f : α → β) {a} (h : a ∈ s) : f a ∈ s.image f := mem_image.2 ⟨_, h, rfl⟩ lemma forall_mem_image {p : β → Prop} : (∀ y ∈ s.image f, p y) ↔ ∀ ⦃x⦄, x ∈ s → p (f x) := by simp lemma exists_mem_image {p : β → Prop} : (∃ y ∈ s.image f, p y) ↔ ∃ x ∈ s, p (f x) := by simp @[deprecated (since := "2024-11-23")] alias forall_image := forall_mem_image theorem map_eq_image (f : α ↪ β) (s : Finset α) : s.map f = s.image f := eq_of_veq (s.map f).2.dedup.symm -- Not `@[simp]` since `mem_image` already gets most of the way there. theorem mem_image_const : c ∈ s.image (const α b) ↔ s.Nonempty ∧ b = c := by rw [mem_image] simp only [exists_prop, const_apply, exists_and_right] rfl theorem mem_image_const_self : b ∈ s.image (const α b) ↔ s.Nonempty := mem_image_const.trans <| and_iff_left rfl instance canLift (c) (p) [CanLift β α c p] : CanLift (Finset β) (Finset α) (image c) fun s => ∀ x ∈ s, p x where prf := by rintro ⟨⟨l⟩, hd : l.Nodup⟩ hl lift l to List α using hl exact ⟨⟨l, hd.of_map _⟩, ext fun a => by simp⟩ theorem image_congr (h : (s : Set α).EqOn f g) : Finset.image f s = Finset.image g s := by ext simp_rw [mem_image, ← bex_def] exact exists₂_congr fun x hx => by rw [h hx] theorem _root_.Function.Injective.mem_finset_image (hf : Injective f) : f a ∈ s.image f ↔ a ∈ s := by refine ⟨fun h => ?_, Finset.mem_image_of_mem f⟩ obtain ⟨y, hy, heq⟩ := mem_image.1 h exact hf heq ▸ hy @[simp, norm_cast] theorem coe_image : ↑(s.image f) = f '' ↑s := Set.ext <| by simp only [mem_coe, mem_image, Set.mem_image, implies_true] @[simp] lemma image_nonempty : (s.image f).Nonempty ↔ s.Nonempty := mod_cast Set.image_nonempty (f := f) (s := (s : Set α)) @[aesop safe apply (rule_sets := [finsetNonempty])] protected theorem Nonempty.image (h : s.Nonempty) (f : α → β) : (s.image f).Nonempty := image_nonempty.2 h alias ⟨Nonempty.of_image, _⟩ := image_nonempty theorem image_toFinset [DecidableEq α] {s : Multiset α} : s.toFinset.image f = (s.map f).toFinset := ext fun _ => by simp only [mem_image, Multiset.mem_toFinset, exists_prop, Multiset.mem_map] theorem image_val_of_injOn (H : Set.InjOn f s) : (image f s).1 = s.1.map f := (s.2.map_on H).dedup @[simp] theorem image_id [DecidableEq α] : s.image id = s := ext fun _ => by simp only [mem_image, exists_prop, id, exists_eq_right] @[simp] theorem image_id' [DecidableEq α] : (s.image fun x => x) = s := image_id theorem image_image [DecidableEq γ] {g : β → γ} : (s.image f).image g = s.image (g ∘ f) := eq_of_veq <| by simp only [image_val, dedup_map_dedup_eq, Multiset.map_map] theorem image_comm {β'} [DecidableEq β'] [DecidableEq γ] {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ} (h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by simp_rw [image_image, comp_def, h_comm] theorem _root_.Function.Semiconj.finset_image [DecidableEq α] {f : α → β} {ga : α → α} {gb : β → β} (h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ => image_comm h theorem _root_.Function.Commute.finset_image [DecidableEq α] {f g : α → α} (h : Function.Commute f g) : Function.Commute (image f) (image g) := Function.Semiconj.finset_image h theorem image_subset_image {s₁ s₂ : Finset α} (h : s₁ ⊆ s₂) : s₁.image f ⊆ s₂.image f := by simp only [subset_def, image_val, subset_dedup', dedup_subset', Multiset.map_subset_map h] theorem image_subset_iff : s.image f ⊆ t ↔ ∀ x ∈ s, f x ∈ t := calc s.image f ⊆ t ↔ f '' ↑s ⊆ ↑t := by norm_cast _ ↔ _ := Set.image_subset_iff theorem image_mono (f : α → β) : Monotone (Finset.image f) := fun _ _ => image_subset_image lemma image_injective (hf : Injective f) : Injective (image f) := by simpa only [funext (map_eq_image _)] using map_injective ⟨f, hf⟩ lemma image_inj {t : Finset α} (hf : Injective f) : s.image f = t.image f ↔ s = t := (image_injective hf).eq_iff theorem image_subset_image_iff {t : Finset α} (hf : Injective f) : s.image f ⊆ t.image f ↔ s ⊆ t := mod_cast Set.image_subset_image_iff hf (s := s) (t := t) lemma image_ssubset_image {t : Finset α} (hf : Injective f) : s.image f ⊂ t.image f ↔ s ⊂ t := by simp_rw [← lt_iff_ssubset] exact lt_iff_lt_of_le_iff_le' (image_subset_image_iff hf) (image_subset_image_iff hf) theorem coe_image_subset_range : ↑(s.image f) ⊆ Set.range f := calc ↑(s.image f) = f '' ↑s := coe_image _ ⊆ Set.range f := Set.image_subset_range f ↑s theorem filter_image {p : β → Prop} [DecidablePred p] : (s.image f).filter p = (s.filter fun a ↦ p (f a)).image f := ext fun b => by simp only [mem_filter, mem_image, exists_prop] exact ⟨by rintro ⟨⟨x, h1, rfl⟩, h2⟩; exact ⟨x, ⟨h1, h2⟩, rfl⟩, by rintro ⟨x, ⟨h1, h2⟩, rfl⟩; exact ⟨⟨x, h1, rfl⟩, h2⟩⟩ theorem fiber_nonempty_iff_mem_image {y : β} : (s.filter (f · = y)).Nonempty ↔ y ∈ s.image f := by simp [Finset.Nonempty] theorem image_union [DecidableEq α] {f : α → β} (s₁ s₂ : Finset α) : (s₁ ∪ s₂).image f = s₁.image f ∪ s₂.image f := mod_cast Set.image_union f s₁ s₂ theorem image_inter_subset [DecidableEq α] (f : α → β) (s t : Finset α) : (s ∩ t).image f ⊆ s.image f ∩ t.image f := (image_mono f).map_inf_le s t theorem image_inter_of_injOn [DecidableEq α] {f : α → β} (s t : Finset α) (hf : Set.InjOn f (s ∪ t)) : (s ∩ t).image f = s.image f ∩ t.image f := coe_injective <| by push_cast exact Set.image_inter_on fun a ha b hb => hf (Or.inr ha) <| Or.inl hb theorem image_inter [DecidableEq α] (s₁ s₂ : Finset α) (hf : Injective f) : (s₁ ∩ s₂).image f = s₁.image f ∩ s₂.image f := image_inter_of_injOn _ _ hf.injOn @[simp] theorem image_singleton (f : α → β) (a : α) : image f {a} = {f a} := ext fun x => by simpa only [mem_image, exists_prop, mem_singleton, exists_eq_left] using eq_comm @[simp] theorem image_insert [DecidableEq α] (f : α → β) (a : α) (s : Finset α) : (insert a s).image f = insert (f a) (s.image f) := by simp only [insert_eq, image_singleton, image_union] theorem erase_image_subset_image_erase [DecidableEq α] (f : α → β) (s : Finset α) (a : α) : (s.image f).erase (f a) ⊆ (s.erase a).image f := by simp only [subset_iff, and_imp, exists_prop, mem_image, exists_imp, mem_erase] rintro b hb x hx rfl exact ⟨_, ⟨ne_of_apply_ne f hb, hx⟩, rfl⟩ @[simp] theorem image_erase [DecidableEq α] {f : α → β} (hf : Injective f) (s : Finset α) (a : α) : (s.erase a).image f = (s.image f).erase (f a) := coe_injective <| by push_cast [Set.image_diff hf, Set.image_singleton]; rfl @[simp] theorem image_eq_empty : s.image f = ∅ ↔ s = ∅ := mod_cast Set.image_eq_empty (f := f) (s := s) theorem image_sdiff [DecidableEq α] {f : α → β} (s t : Finset α) (hf : Injective f) : (s \ t).image f = s.image f \ t.image f := mod_cast Set.image_diff hf s t lemma image_sdiff_of_injOn [DecidableEq α] {t : Finset α} (hf : Set.InjOn f s) (hts : t ⊆ s) : (s \ t).image f = s.image f \ t.image f := mod_cast Set.image_diff_of_injOn hf <| coe_subset.2 hts theorem _root_.Disjoint.of_image_finset {s t : Finset α} {f : α → β} (h : Disjoint (s.image f) (t.image f)) : Disjoint s t := disjoint_iff_ne.2 fun _ ha _ hb => ne_of_apply_ne f <| h.forall_ne_finset (mem_image_of_mem _ ha) (mem_image_of_mem _ hb) theorem mem_range_iff_mem_finset_range_of_mod_eq' [DecidableEq α] {f : ℕ → α} {a : α} {n : ℕ} (hn : 0 < n) (h : ∀ i, f (i % n) = f i) : a ∈ Set.range f ↔ a ∈ (Finset.range n).image fun i => f i := by constructor · rintro ⟨i, hi⟩ simp only [mem_image, exists_prop, mem_range] exact ⟨i % n, Nat.mod_lt i hn, (rfl.congr hi).mp (h i)⟩ · rintro h simp only [mem_image, exists_prop, Set.mem_range, mem_range] at * rcases h with ⟨i, _, ha⟩ exact ⟨i, ha⟩ theorem mem_range_iff_mem_finset_range_of_mod_eq [DecidableEq α] {f : ℤ → α} {a : α} {n : ℕ} (hn : 0 < n) (h : ∀ i, f (i % n) = f i) : a ∈ Set.range f ↔ a ∈ (Finset.range n).image (fun (i : ℕ) => f i) := suffices (∃ i, f (i % n) = a) ↔ ∃ i, i < n ∧ f ↑i = a by simpa [h] have hn' : 0 < (n : ℤ) := Int.ofNat_lt.mpr hn Iff.intro (fun ⟨i, hi⟩ => have : 0 ≤ i % ↑n := Int.emod_nonneg _ (ne_of_gt hn') ⟨Int.toNat (i % n), by rw [← Int.ofNat_lt, Int.toNat_of_nonneg this]; exact ⟨Int.emod_lt_of_pos i hn', hi⟩⟩) fun ⟨i, hi, ha⟩ => ⟨i, by rw [Int.emod_eq_of_lt (Int.ofNat_zero_le _) (Int.ofNat_lt_ofNat_of_lt hi), ha]⟩ @[simp] theorem attach_image_val [DecidableEq α] {s : Finset α} : s.attach.image Subtype.val = s := eq_of_veq <| by rw [image_val, attach_val, Multiset.attach_map_val, dedup_eq_self] @[simp] theorem attach_insert [DecidableEq α] {a : α} {s : Finset α} : attach (insert a s) = insert (⟨a, mem_insert_self a s⟩ : { x // x ∈ insert a s }) ((attach s).image fun x => ⟨x.1, mem_insert_of_mem x.2⟩) := ext fun ⟨x, hx⟩ => ⟨Or.casesOn (mem_insert.1 hx) (fun h : x = a => fun _ => mem_insert.2 <| Or.inl <| Subtype.eq h) fun h : x ∈ s => fun _ => mem_insert_of_mem <| mem_image.2 <| ⟨⟨x, h⟩, mem_attach _ _, Subtype.eq rfl⟩, fun _ => Finset.mem_attach _ _⟩ @[simp] theorem disjoint_image {s t : Finset α} {f : α → β} (hf : Injective f) : Disjoint (s.image f) (t.image f) ↔ Disjoint s t := mod_cast Set.disjoint_image_iff hf (s := s) (t := t) theorem image_const {s : Finset α} (h : s.Nonempty) (b : β) : (s.image fun _ => b) = singleton b := mod_cast Set.Nonempty.image_const (coe_nonempty.2 h) b @[simp] theorem map_erase [DecidableEq α] (f : α ↪ β) (s : Finset α) (a : α) : (s.erase a).map f = (s.map f).erase (f a) := by simp_rw [map_eq_image] exact s.image_erase f.2 a end Image /-! ### filterMap -/ section FilterMap /-- `filterMap f s` is a combination filter/map operation on `s`. The function `f : α → Option β` is applied to each element of `s`; if `f a` is `some b` then `b` is included in the result, otherwise `a` is excluded from the resulting finset. In notation, `filterMap f s` is the finset `{b : β | ∃ a ∈ s , f a = some b}`. -/ -- TODO: should there be `filterImage` too? def filterMap (f : α → Option β) (s : Finset α) (f_inj : ∀ a a' b, b ∈ f a → b ∈ f a' → a = a') : Finset β := ⟨s.val.filterMap f, s.nodup.filterMap f f_inj⟩ variable (f : α → Option β) (s' : Finset α) {s t : Finset α} {f_inj : ∀ a a' b, b ∈ f a → b ∈ f a' → a = a'} @[simp] theorem filterMap_val : (filterMap f s' f_inj).1 = s'.1.filterMap f := rfl @[simp] theorem filterMap_empty : (∅ : Finset α).filterMap f f_inj = ∅ := rfl @[simp] theorem mem_filterMap {b : β} : b ∈ s.filterMap f f_inj ↔ ∃ a ∈ s, f a = some b := s.val.mem_filterMap f @[simp, norm_cast] theorem coe_filterMap : (s.filterMap f f_inj : Set β) = {b | ∃ a ∈ s, f a = some b} := Set.ext (by simp only [mem_coe, mem_filterMap, Option.mem_def, Set.mem_setOf_eq, implies_true]) @[simp] theorem filterMap_some : s.filterMap some (by simp) = s := ext fun _ => by simp only [mem_filterMap, Option.some.injEq, exists_eq_right] theorem filterMap_mono (h : s ⊆ t) : filterMap f s f_inj ⊆ filterMap f t f_inj := by rw [← val_le_iff] at h ⊢ exact Multiset.filterMap_le_filterMap f h @[simp] theorem _root_.List.toFinset_filterMap [DecidableEq α] [DecidableEq β] (s : List α) : (s.filterMap f).toFinset = s.toFinset.filterMap f f_inj := by simp [← Finset.coe_inj] end FilterMap /-! ### Subtype -/ section Subtype /-- Given a finset `s` and a predicate `p`, `s.subtype p` is the finset of `Subtype p` whose elements belong to `s`. -/ protected def subtype {α} (p : α → Prop) [DecidablePred p] (s : Finset α) : Finset (Subtype p) := (s.filter p).attach.map ⟨fun x => ⟨x.1, by simpa using (Finset.mem_filter.1 x.2).2⟩, fun _ _ H => Subtype.eq <| Subtype.mk.inj H⟩ @[simp] theorem mem_subtype {p : α → Prop} [DecidablePred p] {s : Finset α} : ∀ {a : Subtype p}, a ∈ s.subtype p ↔ (a : α) ∈ s | ⟨a, ha⟩ => by simp [Finset.subtype, ha] theorem subtype_eq_empty {p : α → Prop} [DecidablePred p] {s : Finset α} : s.subtype p = ∅ ↔ ∀ x, p x → x ∉ s := by simp [Finset.ext_iff, Subtype.forall, Subtype.coe_mk] @[mono] theorem subtype_mono {p : α → Prop} [DecidablePred p] : Monotone (Finset.subtype p) := fun _ _ h _ hx => mem_subtype.2 <| h <| mem_subtype.1 hx /-- `s.subtype p` converts back to `s.filter p` with `Embedding.subtype`. -/ @[simp] theorem subtype_map (p : α → Prop) [DecidablePred p] {s : Finset α} : (s.subtype p).map (Embedding.subtype _) = s.filter p := by ext x simp [@and_comm _ (_ = _), @and_left_comm _ (_ = _), @and_comm (p x) (x ∈ s)] /-- If all elements of a `Finset` satisfy the predicate `p`, `s.subtype p` converts back to `s` with `Embedding.subtype`. -/ theorem subtype_map_of_mem {p : α → Prop} [DecidablePred p] {s : Finset α} (h : ∀ x ∈ s, p x) : (s.subtype p).map (Embedding.subtype _) = s := ext <| by simpa [subtype_map] using h /-- If a `Finset` of a subtype is converted to the main type with `Embedding.subtype`, all elements of the result have the property of the subtype. -/ theorem property_of_mem_map_subtype {p : α → Prop} (s : Finset { x // p x }) {a : α} (h : a ∈ s.map (Embedding.subtype _)) : p a := by rcases mem_map.1 h with ⟨x, _, rfl⟩ exact x.2 /-- If a `Finset` of a subtype is converted to the main type with `Embedding.subtype`, the result does not contain any value that does not satisfy the property of the subtype. -/ theorem not_mem_map_subtype_of_not_property {p : α → Prop} (s : Finset { x // p x }) {a : α} (h : ¬p a) : a ∉ s.map (Embedding.subtype _) := mt s.property_of_mem_map_subtype h /-- If a `Finset` of a subtype is converted to the main type with `Embedding.subtype`, the result is a subset of the set giving the subtype. -/ theorem map_subtype_subset {t : Set α} (s : Finset t) : ↑(s.map (Embedding.subtype _)) ⊆ t := by intro a ha rw [mem_coe] at ha convert property_of_mem_map_subtype s ha end Subtype /-- If a `Finset` is a subset of the image of a `Set` under `f`, then it is equal to the `Finset.image` of a `Finset` subset of that `Set`. -/ theorem subset_set_image_iff [DecidableEq β] {s : Set α} {t : Finset β} {f : α → β} : ↑t ⊆ f '' s ↔ ∃ s' : Finset α, ↑s' ⊆ s ∧ s'.image f = t := by constructor · intro h letI : CanLift β s (f ∘ (↑)) fun y => y ∈ f '' s := ⟨fun y ⟨x, hxt, hy⟩ => ⟨⟨x, hxt⟩, hy⟩⟩ lift t to Finset s using h refine ⟨t.map (Embedding.subtype _), map_subtype_subset _, ?_⟩ ext y; simp · rintro ⟨t, ht, rfl⟩ rw [coe_image] exact Set.image_subset f ht /-- If a finset `t` is a subset of the image of another finset `s` under `f`, then it is equal to the image of a subset of `s`. For the version where `s` is a set, see `subset_set_image_iff`. -/
theorem subset_image_iff [DecidableEq β] {s : Finset α} {t : Finset β} {f : α → β} : t ⊆ s.image f ↔ ∃ s' : Finset α, s' ⊆ s ∧ s'.image f = t := by simp only [← coe_subset, coe_image, subset_set_image_iff]
Mathlib/Data/Finset/Image.lean
648
651