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 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import Mathlib.Algebra.Group.Commute.Defs import Mathlib.Algebra.Group.Units.Defs import Mathlib.Algebra.GroupWithZero.Defs import Mathlib.Algebra.Order.Monoid.Unbundled.Basic import Mathlib.Tactic.NthRewrite /-! # Regular elements We introduce left-regular, right-regular and regular elements, along with their `to_additive` analogues add-left-regular, add-right-regular and add-regular elements. By definition, a regular element in a commutative ring is a non-zero divisor. Lemma `isRegular_of_ne_zero` implies that every non-zero element of an integral domain is regular. Since it assumes that the ring is a `CancelMonoidWithZero` it applies also, for instance, to `ℕ`. The lemmas in Section `MulZeroClass` show that the `0` element is (left/right-)regular if and only if the `MulZeroClass` is trivial. This is useful when figuring out stopping conditions for regular sequences: if `0` is ever an element of a regular sequence, then we can extend the sequence by adding one further `0`. The final goal is to develop part of the API to prove, eventually, results about non-zero-divisors. -/ variable {R : Type*} section Mul variable [Mul R] /-- A left-regular element is an element `c` such that multiplication on the left by `c` is injective. -/ @[to_additive "An add-left-regular element is an element `c` such that addition on the left by `c` is injective."] def IsLeftRegular (c : R) := (c * ·).Injective /-- A right-regular element is an element `c` such that multiplication on the right by `c` is injective. -/ @[to_additive "An add-right-regular element is an element `c` such that addition on the right by `c` is injective."] def IsRightRegular (c : R) := (· * c).Injective /-- An add-regular element is an element `c` such that addition by `c` both on the left and on the right is injective. -/ structure IsAddRegular {R : Type*} [Add R] (c : R) : Prop where /-- An add-regular element `c` is left-regular -/ left : IsAddLeftRegular c -- Porting note: It seems like to_additive is misbehaving /-- An add-regular element `c` is right-regular -/ right : IsAddRightRegular c /-- A regular element is an element `c` such that multiplication by `c` both on the left and on the right is injective. -/ structure IsRegular (c : R) : Prop where /-- A regular element `c` is left-regular -/ left : IsLeftRegular c /-- A regular element `c` is right-regular -/ right : IsRightRegular c attribute [simp] IsRegular.left IsRegular.right attribute [to_additive] IsRegular @[to_additive] theorem isRegular_iff {c : R} : IsRegular c ↔ IsLeftRegular c ∧ IsRightRegular c := ⟨fun ⟨h1, h2⟩ => ⟨h1, h2⟩, fun ⟨h1, h2⟩ => ⟨h1, h2⟩⟩ @[to_additive] protected theorem MulLECancellable.isLeftRegular [PartialOrder R] {a : R} (ha : MulLECancellable a) : IsLeftRegular a := ha.Injective theorem IsLeftRegular.right_of_commute {a : R} (ca : ∀ b, Commute a b) (h : IsLeftRegular a) : IsRightRegular a := fun x y xy => h <| (ca x).trans <| xy.trans <| (ca y).symm theorem IsRightRegular.left_of_commute {a : R} (ca : ∀ b, Commute a b) (h : IsRightRegular a) : IsLeftRegular a := by simp_rw [@Commute.symm_iff R _ a] at ca exact fun x y xy => h <| (ca x).trans <| xy.trans <| (ca y).symm theorem Commute.isRightRegular_iff {a : R} (ca : ∀ b, Commute a b) : IsRightRegular a ↔ IsLeftRegular a := ⟨IsRightRegular.left_of_commute ca, IsLeftRegular.right_of_commute ca⟩ theorem Commute.isRegular_iff {a : R} (ca : ∀ b, Commute a b) : IsRegular a ↔ IsLeftRegular a := ⟨fun h => h.left, fun h => ⟨h, h.right_of_commute ca⟩⟩ end Mul section Semigroup variable [Semigroup R] {a b : R} /-- In a semigroup, the product of left-regular elements is left-regular. -/ @[to_additive "In an additive semigroup, the sum of add-left-regular elements is add-left.regular."] theorem IsLeftRegular.mul (lra : IsLeftRegular a) (lrb : IsLeftRegular b) : IsLeftRegular (a * b) := show Function.Injective (((a * b) * ·)) from comp_mul_left a b ▸ lra.comp lrb /-- In a semigroup, the product of right-regular elements is right-regular. -/ @[to_additive "In an additive semigroup, the sum of add-right-regular elements is add-right-regular."] theorem IsRightRegular.mul (rra : IsRightRegular a) (rrb : IsRightRegular b) : IsRightRegular (a * b) := show Function.Injective (· * (a * b)) from comp_mul_right b a ▸ rrb.comp rra /-- In a semigroup, the product of regular elements is regular. -/ @[to_additive "In an additive semigroup, the sum of add-regular elements is add-regular."] theorem IsRegular.mul (rra : IsRegular a) (rrb : IsRegular b) : IsRegular (a * b) := ⟨rra.left.mul rrb.left, rra.right.mul rrb.right⟩ /-- If an element `b` becomes left-regular after multiplying it on the left by a left-regular element, then `b` is left-regular. -/ @[to_additive "If an element `b` becomes add-left-regular after adding to it on the left an add-left-regular element, then `b` is add-left-regular."] theorem IsLeftRegular.of_mul (ab : IsLeftRegular (a * b)) : IsLeftRegular b := Function.Injective.of_comp (f := (a * ·)) (by rwa [comp_mul_left a b]) /-- An element is left-regular if and only if multiplying it on the left by a left-regular element is left-regular. -/ @[to_additive (attr := simp) "An element is add-left-regular if and only if adding to it on the left an add-left-regular element is add-left-regular."] theorem mul_isLeftRegular_iff (b : R) (ha : IsLeftRegular a) : IsLeftRegular (a * b) ↔ IsLeftRegular b := ⟨fun ab => IsLeftRegular.of_mul ab, fun ab => IsLeftRegular.mul ha ab⟩ /-- If an element `b` becomes right-regular after multiplying it on the right by a right-regular element, then `b` is right-regular. -/ @[to_additive "If an element `b` becomes add-right-regular after adding to it on the right an add-right-regular element, then `b` is add-right-regular."] theorem IsRightRegular.of_mul (ab : IsRightRegular (b * a)) : IsRightRegular b := by refine fun x y xy => ab (?_ : x * (b * a) = y * (b * a)) rw [← mul_assoc, ← mul_assoc] exact congr_arg (· * a) xy /-- An element is right-regular if and only if multiplying it on the right with a right-regular element is right-regular. -/ @[to_additive (attr := simp) "An element is add-right-regular if and only if adding it on the right to an add-right-regular element is add-right-regular."] theorem mul_isRightRegular_iff (b : R) (ha : IsRightRegular a) : IsRightRegular (b * a) ↔ IsRightRegular b := ⟨fun ab => IsRightRegular.of_mul ab, fun ab => IsRightRegular.mul ab ha⟩ /-- Two elements `a` and `b` are regular if and only if both products `a * b` and `b * a` are regular. -/ @[to_additive "Two elements `a` and `b` are add-regular if and only if both sums `a + b` and `b + a` are add-regular."] theorem isRegular_mul_and_mul_iff : IsRegular (a * b) ∧ IsRegular (b * a) ↔ IsRegular a ∧ IsRegular b := by refine ⟨?_, ?_⟩ · rintro ⟨ab, ba⟩ exact ⟨⟨IsLeftRegular.of_mul ba.left, IsRightRegular.of_mul ab.right⟩, ⟨IsLeftRegular.of_mul ab.left, IsRightRegular.of_mul ba.right⟩⟩ · rintro ⟨ha, hb⟩ exact ⟨ha.mul hb, hb.mul ha⟩ /-- The "most used" implication of `mul_and_mul_iff`, with split hypotheses, instead of `∧`. -/ @[to_additive "The \"most used\" implication of `add_and_add_iff`, with split hypotheses, instead of `∧`."] theorem IsRegular.and_of_mul_of_mul (ab : IsRegular (a * b)) (ba : IsRegular (b * a)) : IsRegular a ∧ IsRegular b := isRegular_mul_and_mul_iff.mp ⟨ab, ba⟩ end Semigroup section MulZeroClass variable [MulZeroClass R] {a b : R} /-- The element `0` is left-regular if and only if `R` is trivial. -/ theorem IsLeftRegular.subsingleton (h : IsLeftRegular (0 : R)) : Subsingleton R := ⟨fun a b => h <| Eq.trans (zero_mul a) (zero_mul b).symm⟩ /-- The element `0` is right-regular if and only if `R` is trivial. -/ theorem IsRightRegular.subsingleton (h : IsRightRegular (0 : R)) : Subsingleton R := ⟨fun a b => h <| Eq.trans (mul_zero a) (mul_zero b).symm⟩ /-- The element `0` is regular if and only if `R` is trivial. -/ theorem IsRegular.subsingleton (h : IsRegular (0 : R)) : Subsingleton R := h.left.subsingleton /-- The element `0` is left-regular if and only if `R` is trivial. -/ theorem isLeftRegular_zero_iff_subsingleton : IsLeftRegular (0 : R) ↔ Subsingleton R := ⟨fun h => h.subsingleton, fun H a b _ => @Subsingleton.elim _ H a b⟩ /-- In a non-trivial `MulZeroClass`, the `0` element is not left-regular. -/ theorem not_isLeftRegular_zero_iff : ¬IsLeftRegular (0 : R) ↔ Nontrivial R := by rw [nontrivial_iff, not_iff_comm, isLeftRegular_zero_iff_subsingleton, subsingleton_iff] push_neg exact Iff.rfl /-- The element `0` is right-regular if and only if `R` is trivial. -/ theorem isRightRegular_zero_iff_subsingleton : IsRightRegular (0 : R) ↔ Subsingleton R := ⟨fun h => h.subsingleton, fun H a b _ => @Subsingleton.elim _ H a b⟩ /-- In a non-trivial `MulZeroClass`, the `0` element is not right-regular. -/ theorem not_isRightRegular_zero_iff : ¬IsRightRegular (0 : R) ↔ Nontrivial R := by rw [nontrivial_iff, not_iff_comm, isRightRegular_zero_iff_subsingleton, subsingleton_iff] push_neg exact Iff.rfl /-- The element `0` is regular if and only if `R` is trivial. -/ theorem isRegular_iff_subsingleton : IsRegular (0 : R) ↔ Subsingleton R := ⟨fun h => h.left.subsingleton, fun h => ⟨isLeftRegular_zero_iff_subsingleton.mpr h, isRightRegular_zero_iff_subsingleton.mpr h⟩⟩ /-- A left-regular element of a `Nontrivial` `MulZeroClass` is non-zero. -/ theorem IsLeftRegular.ne_zero [Nontrivial R] (la : IsLeftRegular a) : a ≠ 0 := by rintro rfl rcases exists_pair_ne R with ⟨x, y, xy⟩ refine xy (la (?_ : 0 * x = 0 * y)) -- Porting note: lean4 seems to need the type signature rw [zero_mul, zero_mul] /-- A right-regular element of a `Nontrivial` `MulZeroClass` is non-zero. -/ theorem IsRightRegular.ne_zero [Nontrivial R] (ra : IsRightRegular a) : a ≠ 0 := by rintro rfl rcases exists_pair_ne R with ⟨x, y, xy⟩ refine xy (ra (?_ : x * 0 = y * 0)) rw [mul_zero, mul_zero] /-- A regular element of a `Nontrivial` `MulZeroClass` is non-zero. -/ theorem IsRegular.ne_zero [Nontrivial R] (la : IsRegular a) : a ≠ 0 := la.left.ne_zero /-- In a non-trivial ring, the element `0` is not left-regular -- with typeclasses. -/ theorem not_isLeftRegular_zero [nR : Nontrivial R] : ¬IsLeftRegular (0 : R) := not_isLeftRegular_zero_iff.mpr nR /-- In a non-trivial ring, the element `0` is not right-regular -- with typeclasses. -/ theorem not_isRightRegular_zero [nR : Nontrivial R] : ¬IsRightRegular (0 : R) := not_isRightRegular_zero_iff.mpr nR /-- In a non-trivial ring, the element `0` is not regular -- with typeclasses. -/ theorem not_isRegular_zero [Nontrivial R] : ¬IsRegular (0 : R) := fun h => IsRegular.ne_zero h rfl @[simp] lemma IsLeftRegular.mul_left_eq_zero_iff (hb : IsLeftRegular b) : b * a = 0 ↔ a = 0 := by nth_rw 1 [← mul_zero b] exact ⟨fun h ↦ hb h, fun ha ↦ by rw [ha]⟩ @[simp] lemma IsRightRegular.mul_right_eq_zero_iff (hb : IsRightRegular b) : a * b = 0 ↔ a = 0 := by nth_rw 1 [← zero_mul b] exact ⟨fun h ↦ hb h, fun ha ↦ by rw [ha]⟩ end MulZeroClass section MulOneClass variable [MulOneClass R] /-- If multiplying by `1` on either side is the identity, `1` is regular. -/ @[to_additive "If adding `0` on either side is the identity, `0` is regular."] theorem isRegular_one : IsRegular (1 : R) := ⟨fun a b ab => (one_mul a).symm.trans (Eq.trans ab (one_mul b)), fun a b ab => (mul_one a).symm.trans (Eq.trans ab (mul_one b))⟩ end MulOneClass section CommSemigroup variable [CommSemigroup R] {a b : R} /-- A product is regular if and only if the factors are. -/ @[to_additive "A sum is add-regular if and only if the summands are."] theorem isRegular_mul_iff : IsRegular (a * b) ↔ IsRegular a ∧ IsRegular b := by refine Iff.trans ?_ isRegular_mul_and_mul_iff exact ⟨fun ab => ⟨ab, by rwa [mul_comm]⟩, fun rab => rab.1⟩ end CommSemigroup section Monoid variable [Monoid R] {a b : R} {n : ℕ} /-- An element admitting a left inverse is left-regular. -/ @[to_additive "An element admitting a left additive opposite is add-left-regular."] theorem isLeftRegular_of_mul_eq_one (h : b * a = 1) : IsLeftRegular a := IsLeftRegular.of_mul (a := b) (by rw [h]; exact isRegular_one.left) /-- An element admitting a right inverse is right-regular. -/ @[to_additive "An element admitting a right additive opposite is add-right-regular."] theorem isRightRegular_of_mul_eq_one (h : a * b = 1) : IsRightRegular a := IsRightRegular.of_mul (a := b) (by rw [h]; exact isRegular_one.right) /-- If `R` is a monoid, an element in `Rˣ` is regular. -/ @[to_additive "If `R` is an additive monoid, an element in `add_units R` is add-regular."] theorem Units.isRegular (a : Rˣ) : IsRegular (a : R) := ⟨isLeftRegular_of_mul_eq_one a.inv_mul, isRightRegular_of_mul_eq_one a.mul_inv⟩ /-- A unit in a monoid is regular. -/ @[to_additive "An additive unit in an additive monoid is add-regular."] theorem IsUnit.isRegular (ua : IsUnit a) : IsRegular a := by rcases ua with ⟨a, rfl⟩ exact Units.isRegular a /-- Any power of a left-regular element is left-regular. -/ lemma IsLeftRegular.pow (n : ℕ) (rla : IsLeftRegular a) : IsLeftRegular (a ^ n) := by simp only [IsLeftRegular, ← mul_left_iterate, rla.iterate n] /-- Any power of a right-regular element is right-regular. -/ lemma IsRightRegular.pow (n : ℕ) (rra : IsRightRegular a) : IsRightRegular (a ^ n) := by rw [IsRightRegular, ← mul_right_iterate] exact rra.iterate n /-- Any power of a regular element is regular. -/ lemma IsRegular.pow (n : ℕ) (ra : IsRegular a) : IsRegular (a ^ n) := ⟨IsLeftRegular.pow n ra.left, IsRightRegular.pow n ra.right⟩
/-- An element `a` is left-regular if and only if a positive power of `a` is left-regular. -/ lemma IsLeftRegular.pow_iff (n0 : 0 < n) : IsLeftRegular (a ^ n) ↔ IsLeftRegular a where mp := by rw [← Nat.succ_pred_eq_of_pos n0, pow_succ]; exact .of_mul
Mathlib/Algebra/Regular/Basic.lean
318
320
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.Data.Set.Prod /-! # N-ary images of sets This file defines `Set.image2`, the binary image of sets. This is mostly useful to define pointwise operations and `Set.seq`. ## Notes This file is very similar to `Data.Finset.NAry`, to `Order.Filter.NAry`, and to `Data.Option.NAry`. Please keep them in sync. -/ open Function namespace Set variable {α α' β β' γ γ' δ δ' ε ε' ζ ζ' ν : Type*} {f f' : α → β → γ} variable {s s' : Set α} {t t' : Set β} {u : Set γ} {v : Set δ} {a : α} {b : β} theorem mem_image2_iff (hf : Injective2 f) : f a b ∈ image2 f s t ↔ a ∈ s ∧ b ∈ t := ⟨by rintro ⟨a', ha', b', hb', h⟩ rcases hf h with ⟨rfl, rfl⟩ exact ⟨ha', hb'⟩, fun ⟨ha, hb⟩ => mem_image2_of_mem ha hb⟩ /-- image2 is monotone with respect to `⊆`. -/ @[gcongr] theorem image2_subset (hs : s ⊆ s') (ht : t ⊆ t') : image2 f s t ⊆ image2 f s' t' := by rintro _ ⟨a, ha, b, hb, rfl⟩ exact mem_image2_of_mem (hs ha) (ht hb) @[gcongr] theorem image2_subset_left (ht : t ⊆ t') : image2 f s t ⊆ image2 f s t' := image2_subset Subset.rfl ht @[gcongr] theorem image2_subset_right (hs : s ⊆ s') : image2 f s t ⊆ image2 f s' t := image2_subset hs Subset.rfl theorem image_subset_image2_left (hb : b ∈ t) : (fun a => f a b) '' s ⊆ image2 f s t := forall_mem_image.2 fun _ ha => mem_image2_of_mem ha hb theorem image_subset_image2_right (ha : a ∈ s) : f a '' t ⊆ image2 f s t := forall_mem_image.2 fun _ => mem_image2_of_mem ha lemma forall_mem_image2 {p : γ → Prop} : (∀ z ∈ image2 f s t, p z) ↔ ∀ x ∈ s, ∀ y ∈ t, p (f x y) := by aesop lemma exists_mem_image2 {p : γ → Prop} : (∃ z ∈ image2 f s t, p z) ↔ ∃ x ∈ s, ∃ y ∈ t, p (f x y) := by aesop @[deprecated (since := "2024-11-23")] alias forall_image2_iff := forall_mem_image2 @[simp] theorem image2_subset_iff {u : Set γ} : image2 f s t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, f x y ∈ u := forall_mem_image2 theorem image2_subset_iff_left : image2 f s t ⊆ u ↔ ∀ a ∈ s, (fun b => f a b) '' t ⊆ u := by simp_rw [image2_subset_iff, image_subset_iff, subset_def, mem_preimage] theorem image2_subset_iff_right : image2 f s t ⊆ u ↔ ∀ b ∈ t, (fun a => f a b) '' s ⊆ u := by simp_rw [image2_subset_iff, image_subset_iff, subset_def, mem_preimage, @forall₂_swap α] variable (f) @[simp] lemma image_prod : (fun x : α × β ↦ f x.1 x.2) '' s ×ˢ t = image2 f s t := ext fun _ ↦ by simp [and_assoc] @[simp] lemma image_uncurry_prod (s : Set α) (t : Set β) : uncurry f '' s ×ˢ t = image2 f s t := image_prod _ @[simp] lemma image2_mk_eq_prod : image2 Prod.mk s t = s ×ˢ t := ext <| by simp @[simp] lemma image2_curry (f : α × β → γ) (s : Set α) (t : Set β) : image2 (fun a b ↦ f (a, b)) s t = f '' s ×ˢ t := by simp [← image_uncurry_prod, uncurry] theorem image2_swap (s : Set α) (t : Set β) : image2 f s t = image2 (fun a b => f b a) t s := by ext constructor <;> rintro ⟨a, ha, b, hb, rfl⟩ <;> exact ⟨b, hb, a, ha, rfl⟩ variable {f} theorem image2_union_left : image2 f (s ∪ s') t = image2 f s t ∪ image2 f s' t := by simp_rw [← image_prod, union_prod, image_union] theorem image2_union_right : image2 f s (t ∪ t') = image2 f s t ∪ image2 f s t' := by rw [← image2_swap, image2_union_left, image2_swap f, image2_swap f] lemma image2_inter_left (hf : Injective2 f) : image2 f (s ∩ s') t = image2 f s t ∩ image2 f s' t := by simp_rw [← image_uncurry_prod, inter_prod, image_inter hf.uncurry] lemma image2_inter_right (hf : Injective2 f) : image2 f s (t ∩ t') = image2 f s t ∩ image2 f s t' := by simp_rw [← image_uncurry_prod, prod_inter, image_inter hf.uncurry] @[simp] theorem image2_empty_left : image2 f ∅ t = ∅ := ext <| by simp @[simp] theorem image2_empty_right : image2 f s ∅ = ∅ := ext <| by simp theorem Nonempty.image2 : s.Nonempty → t.Nonempty → (image2 f s t).Nonempty := fun ⟨_, ha⟩ ⟨_, hb⟩ => ⟨_, mem_image2_of_mem ha hb⟩ @[simp] theorem image2_nonempty_iff : (image2 f s t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := ⟨fun ⟨_, a, ha, b, hb, _⟩ => ⟨⟨a, ha⟩, b, hb⟩, fun h => h.1.image2 h.2⟩ theorem Nonempty.of_image2_left (h : (Set.image2 f s t).Nonempty) : s.Nonempty := (image2_nonempty_iff.1 h).1 theorem Nonempty.of_image2_right (h : (Set.image2 f s t).Nonempty) : t.Nonempty := (image2_nonempty_iff.1 h).2 @[simp] theorem image2_eq_empty_iff : image2 f s t = ∅ ↔ s = ∅ ∨ t = ∅ := by rw [← not_nonempty_iff_eq_empty, image2_nonempty_iff, not_and_or] simp [not_nonempty_iff_eq_empty] theorem Subsingleton.image2 (hs : s.Subsingleton) (ht : t.Subsingleton) (f : α → β → γ) : (image2 f s t).Subsingleton := by rw [← image_prod] apply (hs.prod ht).image theorem image2_inter_subset_left : image2 f (s ∩ s') t ⊆ image2 f s t ∩ image2 f s' t := Monotone.map_inf_le (fun _ _ ↦ image2_subset_right) s s' theorem image2_inter_subset_right : image2 f s (t ∩ t') ⊆ image2 f s t ∩ image2 f s t' := Monotone.map_inf_le (fun _ _ ↦ image2_subset_left) t t' @[simp] theorem image2_singleton_left : image2 f {a} t = f a '' t := ext fun x => by simp @[simp] theorem image2_singleton_right : image2 f s {b} = (fun a => f a b) '' s := ext fun x => by simp theorem image2_singleton : image2 f {a} {b} = {f a b} := by simp @[simp] theorem image2_insert_left : image2 f (insert a s) t = (fun b => f a b) '' t ∪ image2 f s t := by rw [insert_eq, image2_union_left, image2_singleton_left] @[simp] theorem image2_insert_right : image2 f s (insert b t) = (fun a => f a b) '' s ∪ image2 f s t := by rw [insert_eq, image2_union_right, image2_singleton_right] @[congr] theorem image2_congr (h : ∀ a ∈ s, ∀ b ∈ t, f a b = f' a b) : image2 f s t = image2 f' s t := by ext constructor <;> rintro ⟨a, ha, b, hb, rfl⟩ <;> exact ⟨a, ha, b, hb, by rw [h a ha b hb]⟩ /-- A common special case of `image2_congr` -/ theorem image2_congr' (h : ∀ a b, f a b = f' a b) : image2 f s t = image2 f' s t := image2_congr fun a _ b _ => h a b theorem image_image2 (f : α → β → γ) (g : γ → δ) : g '' image2 f s t = image2 (fun a b => g (f a b)) s t := by simp only [← image_prod, image_image] theorem image2_image_left (f : γ → β → δ) (g : α → γ) : image2 f (g '' s) t = image2 (fun a b => f (g a) b) s t := by ext; simp theorem image2_image_right (f : α → γ → δ) (g : β → γ) : image2 f s (g '' t) = image2 (fun a b => f a (g b)) s t := by ext; simp @[simp] theorem image2_left (h : t.Nonempty) : image2 (fun x _ => x) s t = s := by simp [nonempty_def.mp h, Set.ext_iff] @[simp] theorem image2_right (h : s.Nonempty) : image2 (fun _ y => y) s t = t := by simp [nonempty_def.mp h, Set.ext_iff] lemma image2_range (f : α' → β' → γ) (g : α → α') (h : β → β') : image2 f (range g) (range h) = range fun x : α × β ↦ f (g x.1) (h x.2) := by simp_rw [← image_univ, image2_image_left, image2_image_right, ← image_prod, univ_prod_univ] theorem image2_assoc {f : δ → γ → ε} {g : α → β → δ} {f' : α → ε' → ε} {g' : β → γ → ε'} (h_assoc : ∀ a b c, f (g a b) c = f' a (g' b c)) : image2 f (image2 g s t) u = image2 f' s (image2 g' t u) := eq_of_forall_subset_iff fun _ ↦ by simp only [image2_subset_iff, forall_mem_image2, h_assoc] theorem image2_comm {g : β → α → γ} (h_comm : ∀ a b, f a b = g b a) : image2 f s t = image2 g t s := (image2_swap _ _ _).trans <| by simp_rw [h_comm] theorem image2_left_comm {f : α → δ → ε} {g : β → γ → δ} {f' : α → γ → δ'} {g' : β → δ' → ε} (h_left_comm : ∀ a b c, f a (g b c) = g' b (f' a c)) : image2 f s (image2 g t u) = image2 g' t (image2 f' s u) := by rw [image2_swap f', image2_swap f] exact image2_assoc fun _ _ _ => h_left_comm _ _ _ theorem image2_right_comm {f : δ → γ → ε} {g : α → β → δ} {f' : α → γ → δ'} {g' : δ' → β → ε} (h_right_comm : ∀ a b c, f (g a b) c = g' (f' a c) b) : image2 f (image2 g s t) u = image2 g' (image2 f' s u) t := by rw [image2_swap g, image2_swap g'] exact image2_assoc fun _ _ _ => h_right_comm _ _ _ theorem image2_image2_image2_comm {f : ε → ζ → ν} {g : α → β → ε} {h : γ → δ → ζ} {f' : ε' → ζ' → ν} {g' : α → γ → ε'} {h' : β → δ → ζ'} (h_comm : ∀ a b c d, f (g a b) (h c d) = f' (g' a c) (h' b d)) : image2 f (image2 g s t) (image2 h u v) = image2 f' (image2 g' s u) (image2 h' t v) := by ext; constructor · rintro ⟨_, ⟨a, ha, b, hb, rfl⟩, _, ⟨c, hc, d, hd, rfl⟩, rfl⟩ exact ⟨_, ⟨a, ha, c, hc, rfl⟩, _, ⟨b, hb, d, hd, rfl⟩, (h_comm _ _ _ _).symm⟩ · rintro ⟨_, ⟨a, ha, c, hc, rfl⟩, _, ⟨b, hb, d, hd, rfl⟩, rfl⟩ exact ⟨_, ⟨a, ha, b, hb, rfl⟩, _, ⟨c, hc, d, hd, rfl⟩, h_comm _ _ _ _⟩ theorem image_image2_distrib {g : γ → δ} {f' : α' → β' → δ} {g₁ : α → α'} {g₂ : β → β'} (h_distrib : ∀ a b, g (f a b) = f' (g₁ a) (g₂ b)) : (image2 f s t).image g = image2 f' (s.image g₁) (t.image g₂) := by simp_rw [image_image2, image2_image_left, image2_image_right, h_distrib] /-- Symmetric statement to `Set.image2_image_left_comm`. -/ theorem image_image2_distrib_left {g : γ → δ} {f' : α' → β → δ} {g' : α → α'} (h_distrib : ∀ a b, g (f a b) = f' (g' a) b) : (image2 f s t).image g = image2 f' (s.image g') t := (image_image2_distrib h_distrib).trans <| by rw [image_id'] /-- Symmetric statement to `Set.image_image2_right_comm`. -/ theorem image_image2_distrib_right {g : γ → δ} {f' : α → β' → δ} {g' : β → β'} (h_distrib : ∀ a b, g (f a b) = f' a (g' b)) : (image2 f s t).image g = image2 f' s (t.image g') := (image_image2_distrib h_distrib).trans <| by rw [image_id'] /-- Symmetric statement to `Set.image_image2_distrib_left`. -/ theorem image2_image_left_comm {f : α' → β → γ} {g : α → α'} {f' : α → β → δ} {g' : δ → γ} (h_left_comm : ∀ a b, f (g a) b = g' (f' a b)) : image2 f (s.image g) t = (image2 f' s t).image g' := (image_image2_distrib_left fun a b => (h_left_comm a b).symm).symm /-- Symmetric statement to `Set.image_image2_distrib_right`. -/ theorem image_image2_right_comm {f : α → β' → γ} {g : β → β'} {f' : α → β → δ} {g' : δ → γ} (h_right_comm : ∀ a b, f a (g b) = g' (f' a b)) : image2 f s (t.image g) = (image2 f' s t).image g' := (image_image2_distrib_right fun a b => (h_right_comm a b).symm).symm /-- The other direction does not hold because of the `s`-`s` cross terms on the RHS. -/ theorem image2_distrib_subset_left {f : α → δ → ε} {g : β → γ → δ} {f₁ : α → β → β'} {f₂ : α → γ → γ'} {g' : β' → γ' → ε} (h_distrib : ∀ a b c, f a (g b c) = g' (f₁ a b) (f₂ a c)) : image2 f s (image2 g t u) ⊆ image2 g' (image2 f₁ s t) (image2 f₂ s u) := by rintro _ ⟨a, ha, _, ⟨b, hb, c, hc, rfl⟩, rfl⟩ rw [h_distrib] exact mem_image2_of_mem (mem_image2_of_mem ha hb) (mem_image2_of_mem ha hc) /-- The other direction does not hold because of the `u`-`u` cross terms on the RHS. -/
theorem image2_distrib_subset_right {f : δ → γ → ε} {g : α → β → δ} {f₁ : α → γ → α'} {f₂ : β → γ → β'} {g' : α' → β' → ε} (h_distrib : ∀ a b c, f (g a b) c = g' (f₁ a c) (f₂ b c)) : image2 f (image2 g s t) u ⊆ image2 g' (image2 f₁ s u) (image2 f₂ t u) := by rintro _ ⟨_, ⟨a, ha, b, hb, rfl⟩, c, hc, rfl⟩ rw [h_distrib] exact mem_image2_of_mem (mem_image2_of_mem ha hc) (mem_image2_of_mem hb hc) theorem image_image2_antidistrib {g : γ → δ} {f' : β' → α' → δ} {g₁ : β → β'} {g₂ : α → α'} (h_antidistrib : ∀ a b, g (f a b) = f' (g₁ b) (g₂ a)) :
Mathlib/Data/Set/NAry.lean
262
270
/- Copyright (c) 2023 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.MeasureTheory.Measure.Decomposition.RadonNikodym /-! # Exponentially tilted measures The exponential tilting of a measure `μ` on `α` by a function `f : α → ℝ` is the measure with density `x ↦ exp (f x) / ∫ y, exp (f y) ∂μ` with respect to `μ`. This is sometimes also called the Esscher transform. The definition is mostly used for `f` linear, in which case the exponentially tilted measure belongs to the natural exponential family of the base measure. Exponentially tilted measures for general `f` can be used for example to establish variational expressions for the Kullback-Leibler divergence. ## Main definitions * `Measure.tilted μ f`: exponential tilting of `μ` by `f`, equal to `μ.withDensity (fun x ↦ ENNReal.ofReal (exp (f x) / ∫ x, exp (f x) ∂μ))`. -/ open Real open scoped ENNReal NNReal namespace MeasureTheory variable {α : Type*} {mα : MeasurableSpace α} {μ : Measure α} {f : α → ℝ} /-- Exponentially tilted measure. When `x ↦ exp (f x)` is integrable, `μ.tilted f` is the probability measure with density with respect to `μ` proportional to `exp (f x)`. Otherwise it is 0. -/ noncomputable def Measure.tilted (μ : Measure α) (f : α → ℝ) : Measure α := μ.withDensity (fun x ↦ ENNReal.ofReal (exp (f x) / ∫ x, exp (f x) ∂μ)) @[simp] lemma tilted_of_not_integrable (hf : ¬ Integrable (fun x ↦ exp (f x)) μ) : μ.tilted f = 0 := by rw [Measure.tilted, integral_undef hf] simp @[simp] lemma tilted_of_not_aemeasurable (hf : ¬ AEMeasurable f μ) : μ.tilted f = 0 := by refine tilted_of_not_integrable ?_ suffices ¬ AEMeasurable (fun x ↦ exp (f x)) μ by exact fun h ↦ this h.1.aemeasurable exact fun h ↦ hf (aemeasurable_of_aemeasurable_exp h) @[simp] lemma tilted_zero_measure (f : α → ℝ) : (0 : Measure α).tilted f = 0 := by simp [Measure.tilted] @[simp] lemma tilted_const' (μ : Measure α) (c : ℝ) : μ.tilted (fun _ ↦ c) = (μ Set.univ)⁻¹ • μ := by cases eq_zero_or_neZero μ with | inl h => rw [h]; simp | inr h0 => simp only [Measure.tilted, withDensity_const, integral_const, smul_eq_mul] by_cases h_univ : μ Set.univ = ∞ · simp only [measureReal_def, h_univ, ENNReal.toReal_top, zero_mul, div_zero, ENNReal.ofReal_zero, zero_smul, ENNReal.inv_top] congr rw [div_eq_mul_inv, mul_inv, mul_comm, mul_assoc, inv_mul_cancel₀ (exp_pos _).ne', mul_one, measureReal_def, ← ENNReal.toReal_inv, ENNReal.ofReal_toReal] simp [h0.out] lemma tilted_const (μ : Measure α) [IsProbabilityMeasure μ] (c : ℝ) : μ.tilted (fun _ ↦ c) = μ := by simp @[simp] lemma tilted_zero' (μ : Measure α) : μ.tilted 0 = (μ Set.univ)⁻¹ • μ := by change μ.tilted (fun _ ↦ 0) = (μ Set.univ)⁻¹ • μ simp lemma tilted_zero (μ : Measure α) [IsProbabilityMeasure μ] : μ.tilted 0 = μ := by simp
lemma tilted_congr {g : α → ℝ} (hfg : f =ᵐ[μ] g) : μ.tilted f = μ.tilted g := by have h_int_eq : ∫ x, exp (f x) ∂μ = ∫ x, exp (g x) ∂μ := by refine integral_congr_ae ?_ filter_upwards [hfg] with x hx rw [hx] refine withDensity_congr_ae ?_ filter_upwards [hfg] with x hx rw [h_int_eq, hx]
Mathlib/MeasureTheory/Measure/Tilted.lean
80
88
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson -/ import Mathlib.Algebra.Field.NegOnePow import Mathlib.Algebra.Field.Periodic import Mathlib.Algebra.QuadraticDiscriminant import Mathlib.Analysis.SpecialFunctions.Exp /-! # Trigonometric functions ## Main definitions This file contains the definition of `π`. See also `Analysis.SpecialFunctions.Trigonometric.Inverse` and `Analysis.SpecialFunctions.Trigonometric.Arctan` for the inverse trigonometric functions. See also `Analysis.SpecialFunctions.Complex.Arg` and `Analysis.SpecialFunctions.Complex.Log` for the complex argument function and the complex logarithm. ## Main statements Many basic inequalities on the real trigonometric functions are established. The continuity of the usual trigonometric functions is proved. Several facts about the real trigonometric functions have the proofs deferred to `Analysis.SpecialFunctions.Trigonometric.Complex`, as they are most easily proved by appealing to the corresponding fact for complex trigonometric functions. See also `Analysis.SpecialFunctions.Trigonometric.Chebyshev` for the multiple angle formulas in terms of Chebyshev polynomials. ## Tags sin, cos, tan, angle -/ noncomputable section open Topology Filter Set namespace Complex @[continuity, fun_prop] theorem continuous_sin : Continuous sin := by change Continuous fun z => (exp (-z * I) - exp (z * I)) * I / 2 fun_prop @[fun_prop] theorem continuousOn_sin {s : Set ℂ} : ContinuousOn sin s := continuous_sin.continuousOn @[continuity, fun_prop] theorem continuous_cos : Continuous cos := by change Continuous fun z => (exp (z * I) + exp (-z * I)) / 2 fun_prop @[fun_prop] theorem continuousOn_cos {s : Set ℂ} : ContinuousOn cos s := continuous_cos.continuousOn @[continuity, fun_prop] theorem continuous_sinh : Continuous sinh := by change Continuous fun z => (exp z - exp (-z)) / 2 fun_prop @[continuity, fun_prop] theorem continuous_cosh : Continuous cosh := by change Continuous fun z => (exp z + exp (-z)) / 2 fun_prop end Complex namespace Real variable {x y z : ℝ} @[continuity, fun_prop] theorem continuous_sin : Continuous sin := Complex.continuous_re.comp (Complex.continuous_sin.comp Complex.continuous_ofReal) @[fun_prop] theorem continuousOn_sin {s} : ContinuousOn sin s := continuous_sin.continuousOn @[continuity, fun_prop] theorem continuous_cos : Continuous cos := Complex.continuous_re.comp (Complex.continuous_cos.comp Complex.continuous_ofReal) @[fun_prop] theorem continuousOn_cos {s} : ContinuousOn cos s := continuous_cos.continuousOn @[continuity, fun_prop] theorem continuous_sinh : Continuous sinh := Complex.continuous_re.comp (Complex.continuous_sinh.comp Complex.continuous_ofReal) @[continuity, fun_prop] theorem continuous_cosh : Continuous cosh := Complex.continuous_re.comp (Complex.continuous_cosh.comp Complex.continuous_ofReal) end Real namespace Real theorem exists_cos_eq_zero : 0 ∈ cos '' Icc (1 : ℝ) 2 := intermediate_value_Icc' (by norm_num) continuousOn_cos ⟨le_of_lt cos_two_neg, le_of_lt cos_one_pos⟩ /-- The number π = 3.14159265... Defined here using choice as twice a zero of cos in [1,2], from which one can derive all its properties. For explicit bounds on π, see `Data.Real.Pi.Bounds`. Denoted `π`, once the `Real` namespace is opened. -/ protected noncomputable def pi : ℝ := 2 * Classical.choose exists_cos_eq_zero @[inherit_doc] scoped notation "π" => Real.pi @[simp] theorem cos_pi_div_two : cos (π / 2) = 0 := by rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)] exact (Classical.choose_spec exists_cos_eq_zero).2 theorem one_le_pi_div_two : (1 : ℝ) ≤ π / 2 := by rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)] exact (Classical.choose_spec exists_cos_eq_zero).1.1 theorem pi_div_two_le_two : π / 2 ≤ 2 := by rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)] exact (Classical.choose_spec exists_cos_eq_zero).1.2 theorem two_le_pi : (2 : ℝ) ≤ π := (div_le_div_iff_of_pos_right (show (0 : ℝ) < 2 by norm_num)).1 (by rw [div_self (two_ne_zero' ℝ)]; exact one_le_pi_div_two) theorem pi_le_four : π ≤ 4 := (div_le_div_iff_of_pos_right (show (0 : ℝ) < 2 by norm_num)).1 (calc π / 2 ≤ 2 := pi_div_two_le_two _ = 4 / 2 := by norm_num) @[bound] theorem pi_pos : 0 < π := lt_of_lt_of_le (by norm_num) two_le_pi @[bound] theorem pi_nonneg : 0 ≤ π := pi_pos.le theorem pi_ne_zero : π ≠ 0 := pi_pos.ne' theorem pi_div_two_pos : 0 < π / 2 := half_pos pi_pos theorem two_pi_pos : 0 < 2 * π := by linarith [pi_pos] end Real namespace Mathlib.Meta.Positivity open Lean.Meta Qq /-- Extension for the `positivity` tactic: `π` is always positive. -/ @[positivity Real.pi] def evalRealPi : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(Real.pi) => assertInstancesCommute pure (.positive q(Real.pi_pos)) | _, _, _ => throwError "not Real.pi" end Mathlib.Meta.Positivity namespace NNReal open Real open Real NNReal /-- `π` considered as a nonnegative real. -/ noncomputable def pi : ℝ≥0 := ⟨π, Real.pi_pos.le⟩ @[simp] theorem coe_real_pi : (pi : ℝ) = π := rfl theorem pi_pos : 0 < pi := mod_cast Real.pi_pos theorem pi_ne_zero : pi ≠ 0 := pi_pos.ne' end NNReal namespace Real @[simp] theorem sin_pi : sin π = 0 := by rw [← mul_div_cancel_left₀ π (two_ne_zero' ℝ), two_mul, add_div, sin_add, cos_pi_div_two]; simp @[simp] theorem cos_pi : cos π = -1 := by rw [← mul_div_cancel_left₀ π (two_ne_zero' ℝ), mul_div_assoc, cos_two_mul, cos_pi_div_two] norm_num @[simp] theorem sin_two_pi : sin (2 * π) = 0 := by simp [two_mul, sin_add] @[simp] theorem cos_two_pi : cos (2 * π) = 1 := by simp [two_mul, cos_add] theorem sin_antiperiodic : Function.Antiperiodic sin π := by simp [sin_add] theorem sin_periodic : Function.Periodic sin (2 * π) := sin_antiperiodic.periodic_two_mul @[simp] theorem sin_add_pi (x : ℝ) : sin (x + π) = -sin x := sin_antiperiodic x @[simp] theorem sin_add_two_pi (x : ℝ) : sin (x + 2 * π) = sin x := sin_periodic x @[simp] theorem sin_sub_pi (x : ℝ) : sin (x - π) = -sin x := sin_antiperiodic.sub_eq x @[simp] theorem sin_sub_two_pi (x : ℝ) : sin (x - 2 * π) = sin x := sin_periodic.sub_eq x @[simp] theorem sin_pi_sub (x : ℝ) : sin (π - x) = sin x := neg_neg (sin x) ▸ sin_neg x ▸ sin_antiperiodic.sub_eq' @[simp] theorem sin_two_pi_sub (x : ℝ) : sin (2 * π - x) = -sin x := sin_neg x ▸ sin_periodic.sub_eq' @[simp] theorem sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 := sin_antiperiodic.nat_mul_eq_of_eq_zero sin_zero n @[simp] theorem sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 := sin_antiperiodic.int_mul_eq_of_eq_zero sin_zero n @[simp] theorem sin_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x + n * (2 * π)) = sin x := sin_periodic.nat_mul n x @[simp] theorem sin_add_int_mul_two_pi (x : ℝ) (n : ℤ) : sin (x + n * (2 * π)) = sin x := sin_periodic.int_mul n x @[simp] theorem sin_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x - n * (2 * π)) = sin x := sin_periodic.sub_nat_mul_eq n @[simp] theorem sin_sub_int_mul_two_pi (x : ℝ) (n : ℤ) : sin (x - n * (2 * π)) = sin x := sin_periodic.sub_int_mul_eq n @[simp] theorem sin_nat_mul_two_pi_sub (x : ℝ) (n : ℕ) : sin (n * (2 * π) - x) = -sin x := sin_neg x ▸ sin_periodic.nat_mul_sub_eq n @[simp] theorem sin_int_mul_two_pi_sub (x : ℝ) (n : ℤ) : sin (n * (2 * π) - x) = -sin x := sin_neg x ▸ sin_periodic.int_mul_sub_eq n theorem sin_add_int_mul_pi (x : ℝ) (n : ℤ) : sin (x + n * π) = (-1) ^ n * sin x := n.cast_negOnePow ℝ ▸ sin_antiperiodic.add_int_mul_eq n theorem sin_add_nat_mul_pi (x : ℝ) (n : ℕ) : sin (x + n * π) = (-1) ^ n * sin x := sin_antiperiodic.add_nat_mul_eq n theorem sin_sub_int_mul_pi (x : ℝ) (n : ℤ) : sin (x - n * π) = (-1) ^ n * sin x := n.cast_negOnePow ℝ ▸ sin_antiperiodic.sub_int_mul_eq n theorem sin_sub_nat_mul_pi (x : ℝ) (n : ℕ) : sin (x - n * π) = (-1) ^ n * sin x := sin_antiperiodic.sub_nat_mul_eq n theorem sin_int_mul_pi_sub (x : ℝ) (n : ℤ) : sin (n * π - x) = -((-1) ^ n * sin x) := by simpa only [sin_neg, mul_neg, Int.cast_negOnePow] using sin_antiperiodic.int_mul_sub_eq n theorem sin_nat_mul_pi_sub (x : ℝ) (n : ℕ) : sin (n * π - x) = -((-1) ^ n * sin x) := by simpa only [sin_neg, mul_neg] using sin_antiperiodic.nat_mul_sub_eq n theorem cos_antiperiodic : Function.Antiperiodic cos π := by simp [cos_add] theorem cos_periodic : Function.Periodic cos (2 * π) := cos_antiperiodic.periodic_two_mul @[simp] theorem abs_cos_int_mul_pi (k : ℤ) : |cos (k * π)| = 1 := by simp [abs_cos_eq_sqrt_one_sub_sin_sq] @[simp] theorem cos_add_pi (x : ℝ) : cos (x + π) = -cos x := cos_antiperiodic x @[simp] theorem cos_add_two_pi (x : ℝ) : cos (x + 2 * π) = cos x := cos_periodic x @[simp] theorem cos_sub_pi (x : ℝ) : cos (x - π) = -cos x := cos_antiperiodic.sub_eq x @[simp] theorem cos_sub_two_pi (x : ℝ) : cos (x - 2 * π) = cos x := cos_periodic.sub_eq x @[simp] theorem cos_pi_sub (x : ℝ) : cos (π - x) = -cos x := cos_neg x ▸ cos_antiperiodic.sub_eq' @[simp] theorem cos_two_pi_sub (x : ℝ) : cos (2 * π - x) = cos x := cos_neg x ▸ cos_periodic.sub_eq' @[simp] theorem cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 := (cos_periodic.nat_mul_eq n).trans cos_zero @[simp] theorem cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 := (cos_periodic.int_mul_eq n).trans cos_zero @[simp] theorem cos_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x + n * (2 * π)) = cos x := cos_periodic.nat_mul n x @[simp] theorem cos_add_int_mul_two_pi (x : ℝ) (n : ℤ) : cos (x + n * (2 * π)) = cos x := cos_periodic.int_mul n x @[simp] theorem cos_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x - n * (2 * π)) = cos x := cos_periodic.sub_nat_mul_eq n @[simp] theorem cos_sub_int_mul_two_pi (x : ℝ) (n : ℤ) : cos (x - n * (2 * π)) = cos x := cos_periodic.sub_int_mul_eq n @[simp] theorem cos_nat_mul_two_pi_sub (x : ℝ) (n : ℕ) : cos (n * (2 * π) - x) = cos x := cos_neg x ▸ cos_periodic.nat_mul_sub_eq n @[simp] theorem cos_int_mul_two_pi_sub (x : ℝ) (n : ℤ) : cos (n * (2 * π) - x) = cos x := cos_neg x ▸ cos_periodic.int_mul_sub_eq n theorem cos_add_int_mul_pi (x : ℝ) (n : ℤ) : cos (x + n * π) = (-1) ^ n * cos x := n.cast_negOnePow ℝ ▸ cos_antiperiodic.add_int_mul_eq n theorem cos_add_nat_mul_pi (x : ℝ) (n : ℕ) : cos (x + n * π) = (-1) ^ n * cos x := cos_antiperiodic.add_nat_mul_eq n theorem cos_sub_int_mul_pi (x : ℝ) (n : ℤ) : cos (x - n * π) = (-1) ^ n * cos x := n.cast_negOnePow ℝ ▸ cos_antiperiodic.sub_int_mul_eq n theorem cos_sub_nat_mul_pi (x : ℝ) (n : ℕ) : cos (x - n * π) = (-1) ^ n * cos x := cos_antiperiodic.sub_nat_mul_eq n theorem cos_int_mul_pi_sub (x : ℝ) (n : ℤ) : cos (n * π - x) = (-1) ^ n * cos x := n.cast_negOnePow ℝ ▸ cos_neg x ▸ cos_antiperiodic.int_mul_sub_eq n theorem cos_nat_mul_pi_sub (x : ℝ) (n : ℕ) : cos (n * π - x) = (-1) ^ n * cos x := cos_neg x ▸ cos_antiperiodic.nat_mul_sub_eq n theorem cos_nat_mul_two_pi_add_pi (n : ℕ) : cos (n * (2 * π) + π) = -1 := by simpa only [cos_zero] using (cos_periodic.nat_mul n).add_antiperiod_eq cos_antiperiodic theorem cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 := by simpa only [cos_zero] using (cos_periodic.int_mul n).add_antiperiod_eq cos_antiperiodic theorem cos_nat_mul_two_pi_sub_pi (n : ℕ) : cos (n * (2 * π) - π) = -1 := by simpa only [cos_zero] using (cos_periodic.nat_mul n).sub_antiperiod_eq cos_antiperiodic theorem cos_int_mul_two_pi_sub_pi (n : ℤ) : cos (n * (2 * π) - π) = -1 := by simpa only [cos_zero] using (cos_periodic.int_mul n).sub_antiperiod_eq cos_antiperiodic theorem sin_pos_of_pos_of_lt_pi {x : ℝ} (h0x : 0 < x) (hxp : x < π) : 0 < sin x := if hx2 : x ≤ 2 then sin_pos_of_pos_of_le_two h0x hx2 else have : (2 : ℝ) + 2 = 4 := by norm_num have : π - x ≤ 2 := sub_le_iff_le_add.2 (le_trans pi_le_four (this ▸ add_le_add_left (le_of_not_ge hx2) _)) sin_pi_sub x ▸ sin_pos_of_pos_of_le_two (sub_pos.2 hxp) this theorem sin_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo 0 π) : 0 < sin x := sin_pos_of_pos_of_lt_pi hx.1 hx.2 theorem sin_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc 0 π) : 0 ≤ sin x := by rw [← closure_Ioo pi_ne_zero.symm] at hx exact closure_lt_subset_le continuous_const continuous_sin (closure_mono (fun y => sin_pos_of_mem_Ioo) hx) theorem sin_nonneg_of_nonneg_of_le_pi {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π) : 0 ≤ sin x := sin_nonneg_of_mem_Icc ⟨h0x, hxp⟩ theorem sin_neg_of_neg_of_neg_pi_lt {x : ℝ} (hx0 : x < 0) (hpx : -π < x) : sin x < 0 := neg_pos.1 <| sin_neg x ▸ sin_pos_of_pos_of_lt_pi (neg_pos.2 hx0) (neg_lt.1 hpx) theorem sin_nonpos_of_nonnpos_of_neg_pi_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -π ≤ x) : sin x ≤ 0 := neg_nonneg.1 <| sin_neg x ▸ sin_nonneg_of_nonneg_of_le_pi (neg_nonneg.2 hx0) (neg_le.1 hpx) @[simp] theorem sin_pi_div_two : sin (π / 2) = 1 := have : sin (π / 2) = 1 ∨ sin (π / 2) = -1 := by simpa [sq, mul_self_eq_one_iff] using sin_sq_add_cos_sq (π / 2) this.resolve_right fun h => show ¬(0 : ℝ) < -1 by norm_num <| h ▸ sin_pos_of_pos_of_lt_pi pi_div_two_pos (half_lt_self pi_pos) theorem sin_add_pi_div_two (x : ℝ) : sin (x + π / 2) = cos x := by simp [sin_add] theorem sin_sub_pi_div_two (x : ℝ) : sin (x - π / 2) = -cos x := by simp [sub_eq_add_neg, sin_add] theorem sin_pi_div_two_sub (x : ℝ) : sin (π / 2 - x) = cos x := by simp [sub_eq_add_neg, sin_add] theorem cos_add_pi_div_two (x : ℝ) : cos (x + π / 2) = -sin x := by simp [cos_add] theorem cos_sub_pi_div_two (x : ℝ) : cos (x - π / 2) = sin x := by simp [sub_eq_add_neg, cos_add] theorem cos_pi_div_two_sub (x : ℝ) : cos (π / 2 - x) = sin x := by rw [← cos_neg, neg_sub, cos_sub_pi_div_two] theorem cos_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo (-(π / 2)) (π / 2)) : 0 < cos x := sin_add_pi_div_two x ▸ sin_pos_of_mem_Ioo ⟨by linarith [hx.1], by linarith [hx.2]⟩ theorem cos_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : 0 ≤ cos x := sin_add_pi_div_two x ▸ sin_nonneg_of_mem_Icc ⟨by linarith [hx.1], by linarith [hx.2]⟩ theorem cos_nonneg_of_neg_pi_div_two_le_of_le {x : ℝ} (hl : -(π / 2) ≤ x) (hu : x ≤ π / 2) : 0 ≤ cos x := cos_nonneg_of_mem_Icc ⟨hl, hu⟩ theorem cos_neg_of_pi_div_two_lt_of_lt {x : ℝ} (hx₁ : π / 2 < x) (hx₂ : x < π + π / 2) : cos x < 0 := neg_pos.1 <| cos_pi_sub x ▸ cos_pos_of_mem_Ioo ⟨by linarith, by linarith⟩ theorem cos_nonpos_of_pi_div_two_le_of_le {x : ℝ} (hx₁ : π / 2 ≤ x) (hx₂ : x ≤ π + π / 2) : cos x ≤ 0 := neg_nonneg.1 <| cos_pi_sub x ▸ cos_nonneg_of_mem_Icc ⟨by linarith, by linarith⟩ theorem sin_eq_sqrt_one_sub_cos_sq {x : ℝ} (hl : 0 ≤ x) (hu : x ≤ π) : sin x = √(1 - cos x ^ 2) := by rw [← abs_sin_eq_sqrt_one_sub_cos_sq, abs_of_nonneg (sin_nonneg_of_nonneg_of_le_pi hl hu)] theorem cos_eq_sqrt_one_sub_sin_sq {x : ℝ} (hl : -(π / 2) ≤ x) (hu : x ≤ π / 2) : cos x = √(1 - sin x ^ 2) := by rw [← abs_cos_eq_sqrt_one_sub_sin_sq, abs_of_nonneg (cos_nonneg_of_mem_Icc ⟨hl, hu⟩)] lemma cos_half {x : ℝ} (hl : -π ≤ x) (hr : x ≤ π) : cos (x / 2) = sqrt ((1 + cos x) / 2) := by have : 0 ≤ cos (x / 2) := cos_nonneg_of_mem_Icc <| by constructor <;> linarith rw [← sqrt_sq this, cos_sq, add_div, two_mul, add_halves] lemma abs_sin_half (x : ℝ) : |sin (x / 2)| = sqrt ((1 - cos x) / 2) := by rw [← sqrt_sq_eq_abs, sin_sq_eq_half_sub, two_mul, add_halves, sub_div] lemma sin_half_eq_sqrt {x : ℝ} (hl : 0 ≤ x) (hr : x ≤ 2 * π) : sin (x / 2) = sqrt ((1 - cos x) / 2) := by rw [← abs_sin_half, abs_of_nonneg] apply sin_nonneg_of_nonneg_of_le_pi <;> linarith lemma sin_half_eq_neg_sqrt {x : ℝ} (hl : -(2 * π) ≤ x) (hr : x ≤ 0) : sin (x / 2) = -sqrt ((1 - cos x) / 2) := by rw [← abs_sin_half, abs_of_nonpos, neg_neg] apply sin_nonpos_of_nonnpos_of_neg_pi_le <;> linarith theorem sin_eq_zero_iff_of_lt_of_lt {x : ℝ} (hx₁ : -π < x) (hx₂ : x < π) : sin x = 0 ↔ x = 0 := ⟨fun h => by contrapose! h cases h.lt_or_lt with | inl h0 => exact (sin_neg_of_neg_of_neg_pi_lt h0 hx₁).ne | inr h0 => exact (sin_pos_of_pos_of_lt_pi h0 hx₂).ne', fun h => by simp [h]⟩ theorem sin_eq_zero_iff {x : ℝ} : sin x = 0 ↔ ∃ n : ℤ, (n : ℝ) * π = x := ⟨fun h => ⟨⌊x / π⌋, le_antisymm (sub_nonneg.1 (Int.sub_floor_div_mul_nonneg _ pi_pos)) (sub_nonpos.1 <| le_of_not_gt fun h₃ => (sin_pos_of_pos_of_lt_pi h₃ (Int.sub_floor_div_mul_lt _ pi_pos)).ne (by simp [sub_eq_add_neg, sin_add, h, sin_int_mul_pi]))⟩, fun ⟨_, hn⟩ => hn ▸ sin_int_mul_pi _⟩ theorem sin_ne_zero_iff {x : ℝ} : sin x ≠ 0 ↔ ∀ n : ℤ, (n : ℝ) * π ≠ x := by rw [← not_exists, not_iff_not, sin_eq_zero_iff] theorem sin_eq_zero_iff_cos_eq {x : ℝ} : sin x = 0 ↔ cos x = 1 ∨ cos x = -1 := by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq x, sq, sq, ← sub_eq_iff_eq_add, sub_self] exact ⟨fun h => by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ Eq.symm⟩ theorem cos_eq_one_iff (x : ℝ) : cos x = 1 ↔ ∃ n : ℤ, (n : ℝ) * (2 * π) = x := ⟨fun h => let ⟨n, hn⟩ := sin_eq_zero_iff.1 (sin_eq_zero_iff_cos_eq.2 (Or.inl h)) ⟨n / 2, (Int.emod_two_eq_zero_or_one n).elim (fun hn0 => by rwa [← mul_assoc, ← @Int.cast_two ℝ, ← Int.cast_mul, Int.ediv_mul_cancel (Int.dvd_iff_emod_eq_zero.2 hn0)]) fun hn1 => by rw [← Int.emod_add_ediv n 2, hn1, Int.cast_add, Int.cast_one, add_mul, one_mul, add_comm, mul_comm (2 : ℤ), Int.cast_mul, mul_assoc, Int.cast_two] at hn rw [← hn, cos_int_mul_two_pi_add_pi] at h exact absurd h (by norm_num)⟩, fun ⟨_, hn⟩ => hn ▸ cos_int_mul_two_pi _⟩ theorem cos_eq_one_iff_of_lt_of_lt {x : ℝ} (hx₁ : -(2 * π) < x) (hx₂ : x < 2 * π) : cos x = 1 ↔ x = 0 := ⟨fun h => by rcases (cos_eq_one_iff _).1 h with ⟨n, rfl⟩ rw [mul_lt_iff_lt_one_left two_pi_pos] at hx₂ rw [neg_lt, neg_mul_eq_neg_mul, mul_lt_iff_lt_one_left two_pi_pos] at hx₁ norm_cast at hx₁ hx₂ obtain rfl : n = 0 := le_antisymm (by omega) (by omega) simp, fun h => by simp [h]⟩ theorem sin_lt_sin_of_lt_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x) (hy₂ : y ≤ π / 2) (hxy : x < y) : sin x < sin y := by rw [← sub_pos, sin_sub_sin] have : 0 < sin ((y - x) / 2) := by apply sin_pos_of_pos_of_lt_pi <;> linarith have : 0 < cos ((y + x) / 2) := by refine cos_pos_of_mem_Ioo ⟨?_, ?_⟩ <;> linarith positivity theorem strictMonoOn_sin : StrictMonoOn sin (Icc (-(π / 2)) (π / 2)) := fun _ hx _ hy hxy => sin_lt_sin_of_lt_of_le_pi_div_two hx.1 hy.2 hxy theorem cos_lt_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x < y) : cos y < cos x := by rw [← sin_pi_div_two_sub, ← sin_pi_div_two_sub] apply sin_lt_sin_of_lt_of_le_pi_div_two <;> linarith theorem cos_lt_cos_of_nonneg_of_le_pi_div_two {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π / 2) (hxy : x < y) : cos y < cos x := cos_lt_cos_of_nonneg_of_le_pi hx₁ (hy₂.trans (by linarith)) hxy theorem strictAntiOn_cos : StrictAntiOn cos (Icc 0 π) := fun _ hx _ hy hxy => cos_lt_cos_of_nonneg_of_le_pi hx.1 hy.2 hxy theorem cos_le_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x ≤ y) : cos y ≤ cos x := (strictAntiOn_cos.le_iff_le ⟨hx₁.trans hxy, hy₂⟩ ⟨hx₁, hxy.trans hy₂⟩).2 hxy theorem sin_le_sin_of_le_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x) (hy₂ : y ≤ π / 2) (hxy : x ≤ y) : sin x ≤ sin y := (strictMonoOn_sin.le_iff_le ⟨hx₁, hxy.trans hy₂⟩ ⟨hx₁.trans hxy, hy₂⟩).2 hxy theorem injOn_sin : InjOn sin (Icc (-(π / 2)) (π / 2)) := strictMonoOn_sin.injOn theorem injOn_cos : InjOn cos (Icc 0 π) := strictAntiOn_cos.injOn theorem surjOn_sin : SurjOn sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) := by simpa only [sin_neg, sin_pi_div_two] using intermediate_value_Icc (neg_le_self pi_div_two_pos.le) continuous_sin.continuousOn theorem surjOn_cos : SurjOn cos (Icc 0 π) (Icc (-1) 1) := by simpa only [cos_zero, cos_pi] using intermediate_value_Icc' pi_pos.le continuous_cos.continuousOn theorem sin_mem_Icc (x : ℝ) : sin x ∈ Icc (-1 : ℝ) 1 := ⟨neg_one_le_sin x, sin_le_one x⟩ theorem cos_mem_Icc (x : ℝ) : cos x ∈ Icc (-1 : ℝ) 1 := ⟨neg_one_le_cos x, cos_le_one x⟩ theorem mapsTo_sin (s : Set ℝ) : MapsTo sin s (Icc (-1 : ℝ) 1) := fun x _ => sin_mem_Icc x theorem mapsTo_cos (s : Set ℝ) : MapsTo cos s (Icc (-1 : ℝ) 1) := fun x _ => cos_mem_Icc x theorem bijOn_sin : BijOn sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) := ⟨mapsTo_sin _, injOn_sin, surjOn_sin⟩ theorem bijOn_cos : BijOn cos (Icc 0 π) (Icc (-1) 1) := ⟨mapsTo_cos _, injOn_cos, surjOn_cos⟩ @[simp] theorem range_cos : range cos = (Icc (-1) 1 : Set ℝ) := Subset.antisymm (range_subset_iff.2 cos_mem_Icc) surjOn_cos.subset_range @[simp] theorem range_sin : range sin = (Icc (-1) 1 : Set ℝ) := Subset.antisymm (range_subset_iff.2 sin_mem_Icc) surjOn_sin.subset_range theorem range_cos_infinite : (range Real.cos).Infinite := by rw [Real.range_cos] exact Icc_infinite (by norm_num) theorem range_sin_infinite : (range Real.sin).Infinite := by rw [Real.range_sin] exact Icc_infinite (by norm_num) section CosDivSq variable (x : ℝ) /-- the series `sqrtTwoAddSeries x n` is `sqrt(2 + sqrt(2 + ... ))` with `n` square roots, starting with `x`. We define it here because `cos (pi / 2 ^ (n+1)) = sqrtTwoAddSeries 0 n / 2` -/ @[simp] noncomputable def sqrtTwoAddSeries (x : ℝ) : ℕ → ℝ | 0 => x | n + 1 => √(2 + sqrtTwoAddSeries x n) theorem sqrtTwoAddSeries_zero : sqrtTwoAddSeries x 0 = x := by simp theorem sqrtTwoAddSeries_one : sqrtTwoAddSeries 0 1 = √2 := by simp theorem sqrtTwoAddSeries_two : sqrtTwoAddSeries 0 2 = √(2 + √2) := by simp theorem sqrtTwoAddSeries_zero_nonneg : ∀ n : ℕ, 0 ≤ sqrtTwoAddSeries 0 n | 0 => le_refl 0 | _ + 1 => sqrt_nonneg _ theorem sqrtTwoAddSeries_nonneg {x : ℝ} (h : 0 ≤ x) : ∀ n : ℕ, 0 ≤ sqrtTwoAddSeries x n | 0 => h | _ + 1 => sqrt_nonneg _ theorem sqrtTwoAddSeries_lt_two : ∀ n : ℕ, sqrtTwoAddSeries 0 n < 2 | 0 => by norm_num | n + 1 => by refine lt_of_lt_of_le ?_ (sqrt_sq zero_lt_two.le).le rw [sqrtTwoAddSeries, sqrt_lt_sqrt_iff, ← lt_sub_iff_add_lt'] · refine (sqrtTwoAddSeries_lt_two n).trans_le ?_ norm_num · exact add_nonneg zero_le_two (sqrtTwoAddSeries_zero_nonneg n) theorem sqrtTwoAddSeries_succ (x : ℝ) : ∀ n : ℕ, sqrtTwoAddSeries x (n + 1) = sqrtTwoAddSeries (√(2 + x)) n | 0 => rfl | n + 1 => by rw [sqrtTwoAddSeries, sqrtTwoAddSeries_succ _ _, sqrtTwoAddSeries] theorem sqrtTwoAddSeries_monotone_left {x y : ℝ} (h : x ≤ y) : ∀ n : ℕ, sqrtTwoAddSeries x n ≤ sqrtTwoAddSeries y n | 0 => h | n + 1 => by rw [sqrtTwoAddSeries, sqrtTwoAddSeries] exact sqrt_le_sqrt (add_le_add_left (sqrtTwoAddSeries_monotone_left h _) _) @[simp] theorem cos_pi_over_two_pow : ∀ n : ℕ, cos (π / 2 ^ (n + 1)) = sqrtTwoAddSeries 0 n / 2 | 0 => by simp | n + 1 => by have A : (1 : ℝ) < 2 ^ (n + 1) := one_lt_pow₀ one_lt_two n.succ_ne_zero have B : π / 2 ^ (n + 1) < π := div_lt_self pi_pos A have C : 0 < π / 2 ^ (n + 1) := by positivity rw [pow_succ, div_mul_eq_div_div, cos_half, cos_pi_over_two_pow n, sqrtTwoAddSeries, add_div_eq_mul_add_div, one_mul, ← div_mul_eq_div_div, sqrt_div, sqrt_mul_self] <;> linarith [sqrtTwoAddSeries_nonneg le_rfl n] theorem sin_sq_pi_over_two_pow (n : ℕ) : sin (π / 2 ^ (n + 1)) ^ 2 = 1 - (sqrtTwoAddSeries 0 n / 2) ^ 2 := by rw [sin_sq, cos_pi_over_two_pow] theorem sin_sq_pi_over_two_pow_succ (n : ℕ) : sin (π / 2 ^ (n + 2)) ^ 2 = 1 / 2 - sqrtTwoAddSeries 0 n / 4 := by rw [sin_sq_pi_over_two_pow, sqrtTwoAddSeries, div_pow, sq_sqrt, add_div, ← sub_sub] · congr · norm_num · norm_num · exact add_nonneg two_pos.le (sqrtTwoAddSeries_zero_nonneg _) @[simp] theorem sin_pi_over_two_pow_succ (n : ℕ) : sin (π / 2 ^ (n + 2)) = √(2 - sqrtTwoAddSeries 0 n) / 2 := by rw [eq_div_iff_mul_eq two_ne_zero, eq_comm, sqrt_eq_iff_eq_sq, mul_pow, sin_sq_pi_over_two_pow_succ, sub_mul] · congr <;> norm_num · rw [sub_nonneg] exact (sqrtTwoAddSeries_lt_two _).le refine mul_nonneg (sin_nonneg_of_nonneg_of_le_pi ?_ ?_) zero_le_two · positivity · exact div_le_self pi_pos.le <| one_le_pow₀ one_le_two @[simp] theorem cos_pi_div_four : cos (π / 4) = √2 / 2 := by trans cos (π / 2 ^ 2) · congr norm_num · simp @[simp] theorem sin_pi_div_four : sin (π / 4) = √2 / 2 := by trans sin (π / 2 ^ 2) · congr norm_num · simp @[simp] theorem cos_pi_div_eight : cos (π / 8) = √(2 + √2) / 2 := by trans cos (π / 2 ^ 3) · congr norm_num · simp @[simp] theorem sin_pi_div_eight : sin (π / 8) = √(2 - √2) / 2 := by trans sin (π / 2 ^ 3) · congr norm_num · simp @[simp] theorem cos_pi_div_sixteen : cos (π / 16) = √(2 + √(2 + √2)) / 2 := by trans cos (π / 2 ^ 4) · congr norm_num · simp @[simp] theorem sin_pi_div_sixteen : sin (π / 16) = √(2 - √(2 + √2)) / 2 := by trans sin (π / 2 ^ 4) · congr norm_num · simp @[simp] theorem cos_pi_div_thirty_two : cos (π / 32) = √(2 + √(2 + √(2 + √2))) / 2 := by trans cos (π / 2 ^ 5) · congr norm_num · simp @[simp] theorem sin_pi_div_thirty_two : sin (π / 32) = √(2 - √(2 + √(2 + √2))) / 2 := by trans sin (π / 2 ^ 5) · congr norm_num · simp -- This section is also a convenient location for other explicit values of `sin` and `cos`. /-- The cosine of `π / 3` is `1 / 2`. -/ @[simp] theorem cos_pi_div_three : cos (π / 3) = 1 / 2 := by have h₁ : (2 * cos (π / 3) - 1) ^ 2 * (2 * cos (π / 3) + 2) = 0 := by have : cos (3 * (π / 3)) = cos π := by congr 1 ring linarith [cos_pi, cos_three_mul (π / 3)] rcases mul_eq_zero.mp h₁ with h | h · linarith [pow_eq_zero h] · have : cos π < cos (π / 3) := by refine cos_lt_cos_of_nonneg_of_le_pi ?_ le_rfl ?_ <;> linarith [pi_pos] linarith [cos_pi] /-- The cosine of `π / 6` is `√3 / 2`. -/ @[simp] theorem cos_pi_div_six : cos (π / 6) = √3 / 2 := by rw [show (6 : ℝ) = 3 * 2 by norm_num, div_mul_eq_div_div, cos_half, cos_pi_div_three, one_add_div, ← div_mul_eq_div_div, two_add_one_eq_three, sqrt_div, sqrt_mul_self] <;> linarith [pi_pos] /-- The square of the cosine of `π / 6` is `3 / 4` (this is sometimes more convenient than the result for cosine itself). -/ theorem sq_cos_pi_div_six : cos (π / 6) ^ 2 = 3 / 4 := by rw [cos_pi_div_six, div_pow, sq_sqrt] <;> norm_num /-- The sine of `π / 6` is `1 / 2`. -/ @[simp] theorem sin_pi_div_six : sin (π / 6) = 1 / 2 := by rw [← cos_pi_div_two_sub, ← cos_pi_div_three] congr ring /-- The square of the sine of `π / 3` is `3 / 4` (this is sometimes more convenient than the result for cosine itself). -/ theorem sq_sin_pi_div_three : sin (π / 3) ^ 2 = 3 / 4 := by rw [← cos_pi_div_two_sub, ← sq_cos_pi_div_six] congr ring /-- The sine of `π / 3` is `√3 / 2`. -/ @[simp] theorem sin_pi_div_three : sin (π / 3) = √3 / 2 := by rw [← cos_pi_div_two_sub, ← cos_pi_div_six] congr ring theorem quadratic_root_cos_pi_div_five : letI c := cos (π / 5) 4 * c ^ 2 - 2 * c - 1 = 0 := by set θ := π / 5 with hθ set c := cos θ set s := sin θ suffices 2 * c = 4 * c ^ 2 - 1 by simp [this] have hs : s ≠ 0 := by rw [ne_eq, sin_eq_zero_iff, hθ] push_neg intro n hn replace hn : n * 5 = 1 := by field_simp [mul_comm _ π, mul_assoc] at hn; norm_cast at hn omega suffices s * (2 * c) = s * (4 * c ^ 2 - 1) from mul_left_cancel₀ hs this calc s * (2 * c) = 2 * s * c := by rw [← mul_assoc, mul_comm 2] _ = sin (2 * θ) := by rw [sin_two_mul] _ = sin (π - 2 * θ) := by rw [sin_pi_sub] _ = sin (2 * θ + θ) := by congr; field_simp [hθ]; linarith _ = sin (2 * θ) * c + cos (2 * θ) * s := sin_add (2 * θ) θ _ = 2 * s * c * c + cos (2 * θ) * s := by rw [sin_two_mul] _ = 2 * s * c * c + (2 * c ^ 2 - 1) * s := by rw [cos_two_mul] _ = s * (2 * c * c) + s * (2 * c ^ 2 - 1) := by linarith _ = s * (4 * c ^ 2 - 1) := by linarith open Polynomial in theorem Polynomial.isRoot_cos_pi_div_five : (4 • X ^ 2 - 2 • X - C 1 : ℝ[X]).IsRoot (cos (π / 5)) := by simpa using quadratic_root_cos_pi_div_five /-- The cosine of `π / 5` is `(1 + √5) / 4`. -/ @[simp] theorem cos_pi_div_five : cos (π / 5) = (1 + √5) / 4 := by set c := cos (π / 5) have : 4 * (c * c) + (-2) * c + (-1) = 0 := by rw [← sq, neg_mul, ← sub_eq_add_neg, ← sub_eq_add_neg] exact quadratic_root_cos_pi_div_five have hd : discrim 4 (-2) (-1) = (2 * √5) * (2 * √5) := by norm_num [discrim, mul_mul_mul_comm] rcases (quadratic_eq_zero_iff (by norm_num) hd c).mp this with h | h · field_simp [h]; linarith · absurd (show 0 ≤ c from cos_nonneg_of_mem_Icc <| by constructor <;> linarith [pi_pos.le]) rw [not_le, h] exact div_neg_of_neg_of_pos (by norm_num [lt_sqrt]) (by positivity) end CosDivSq /-- `Real.sin` as an `OrderIso` between `[-(π / 2), π / 2]` and `[-1, 1]`. -/ def sinOrderIso : Icc (-(π / 2)) (π / 2) ≃o Icc (-1 : ℝ) 1 := (strictMonoOn_sin.orderIso _ _).trans <| OrderIso.setCongr _ _ bijOn_sin.image_eq @[simp] theorem coe_sinOrderIso_apply (x : Icc (-(π / 2)) (π / 2)) : (sinOrderIso x : ℝ) = sin x := rfl theorem sinOrderIso_apply (x : Icc (-(π / 2)) (π / 2)) : sinOrderIso x = ⟨sin x, sin_mem_Icc x⟩ := rfl @[simp] theorem tan_pi_div_four : tan (π / 4) = 1 := by rw [tan_eq_sin_div_cos, cos_pi_div_four, sin_pi_div_four] have h : √2 / 2 > 0 := by positivity exact div_self (ne_of_gt h) @[simp] theorem tan_pi_div_two : tan (π / 2) = 0 := by simp [tan_eq_sin_div_cos] @[simp] theorem tan_pi_div_six : tan (π / 6) = 1 / sqrt 3 := by rw [tan_eq_sin_div_cos, sin_pi_div_six, cos_pi_div_six] ring @[simp] theorem tan_pi_div_three : tan (π / 3) = sqrt 3 := by rw [tan_eq_sin_div_cos, sin_pi_div_three, cos_pi_div_three] ring theorem tan_pos_of_pos_of_lt_pi_div_two {x : ℝ} (h0x : 0 < x) (hxp : x < π / 2) : 0 < tan x := by rw [tan_eq_sin_div_cos] exact div_pos (sin_pos_of_pos_of_lt_pi h0x (by linarith)) (cos_pos_of_mem_Ioo ⟨by linarith, hxp⟩) theorem tan_nonneg_of_nonneg_of_le_pi_div_two {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π / 2) : 0 ≤ tan x := match lt_or_eq_of_le h0x, lt_or_eq_of_le hxp with | Or.inl hx0, Or.inl hxp => le_of_lt (tan_pos_of_pos_of_lt_pi_div_two hx0 hxp) | Or.inl _, Or.inr hxp => by simp [hxp, tan_eq_sin_div_cos] | Or.inr hx0, _ => by simp [hx0.symm] theorem tan_neg_of_neg_of_pi_div_two_lt {x : ℝ} (hx0 : x < 0) (hpx : -(π / 2) < x) : tan x < 0 := neg_pos.1 (tan_neg x ▸ tan_pos_of_pos_of_lt_pi_div_two (by linarith) (by linarith [pi_pos])) theorem tan_nonpos_of_nonpos_of_neg_pi_div_two_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -(π / 2) ≤ x) : tan x ≤ 0 := neg_nonneg.1 (tan_neg x ▸ tan_nonneg_of_nonneg_of_le_pi_div_two (by linarith) (by linarith)) theorem strictMonoOn_tan : StrictMonoOn tan (Ioo (-(π / 2)) (π / 2)) := by rintro x hx y hy hlt rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos, div_lt_div_iff₀ (cos_pos_of_mem_Ioo hx) (cos_pos_of_mem_Ioo hy), mul_comm, ← sub_pos, ← sin_sub] exact sin_pos_of_pos_of_lt_pi (sub_pos.2 hlt) <| by linarith [hx.1, hy.2] theorem tan_lt_tan_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) < x) (hy₂ : y < π / 2) (hxy : x < y) : tan x < tan y := strictMonoOn_tan ⟨hx₁, hxy.trans hy₂⟩ ⟨hx₁.trans hxy, hy₂⟩ hxy theorem tan_lt_tan_of_nonneg_of_lt_pi_div_two {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y < π / 2) (hxy : x < y) : tan x < tan y := tan_lt_tan_of_lt_of_lt_pi_div_two (by linarith) hy₂ hxy theorem injOn_tan : InjOn tan (Ioo (-(π / 2)) (π / 2)) := strictMonoOn_tan.injOn theorem tan_inj_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2) (hy₁ : -(π / 2) < y) (hy₂ : y < π / 2) (hxy : tan x = tan y) : x = y := injOn_tan ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ hxy theorem tan_periodic : Function.Periodic tan π := by simpa only [Function.Periodic, tan_eq_sin_div_cos] using sin_antiperiodic.div cos_antiperiodic @[simp] theorem tan_pi : tan π = 0 := by rw [tan_periodic.eq, tan_zero] theorem tan_add_pi (x : ℝ) : tan (x + π) = tan x := tan_periodic x theorem tan_sub_pi (x : ℝ) : tan (x - π) = tan x := tan_periodic.sub_eq x theorem tan_pi_sub (x : ℝ) : tan (π - x) = -tan x := tan_neg x ▸ tan_periodic.sub_eq' theorem tan_pi_div_two_sub (x : ℝ) : tan (π / 2 - x) = (tan x)⁻¹ := by rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos, inv_div, sin_pi_div_two_sub, cos_pi_div_two_sub] theorem tan_nat_mul_pi (n : ℕ) : tan (n * π) = 0 := tan_zero ▸ tan_periodic.nat_mul_eq n theorem tan_int_mul_pi (n : ℤ) : tan (n * π) = 0 := tan_zero ▸ tan_periodic.int_mul_eq n theorem tan_add_nat_mul_pi (x : ℝ) (n : ℕ) : tan (x + n * π) = tan x := tan_periodic.nat_mul n x theorem tan_add_int_mul_pi (x : ℝ) (n : ℤ) : tan (x + n * π) = tan x := tan_periodic.int_mul n x theorem tan_sub_nat_mul_pi (x : ℝ) (n : ℕ) : tan (x - n * π) = tan x := tan_periodic.sub_nat_mul_eq n theorem tan_sub_int_mul_pi (x : ℝ) (n : ℤ) : tan (x - n * π) = tan x := tan_periodic.sub_int_mul_eq n theorem tan_nat_mul_pi_sub (x : ℝ) (n : ℕ) : tan (n * π - x) = -tan x := tan_neg x ▸ tan_periodic.nat_mul_sub_eq n theorem tan_int_mul_pi_sub (x : ℝ) (n : ℤ) : tan (n * π - x) = -tan x := tan_neg x ▸ tan_periodic.int_mul_sub_eq n theorem tendsto_sin_pi_div_two : Tendsto sin (𝓝[<] (π / 2)) (𝓝 1) := by convert continuous_sin.continuousWithinAt.tendsto simp theorem tendsto_cos_pi_div_two : Tendsto cos (𝓝[<] (π / 2)) (𝓝[>] 0) := by apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within · convert continuous_cos.continuousWithinAt.tendsto simp · filter_upwards [Ioo_mem_nhdsLT (neg_lt_self pi_div_two_pos)] with x hx exact cos_pos_of_mem_Ioo hx theorem tendsto_tan_pi_div_two : Tendsto tan (𝓝[<] (π / 2)) atTop := by convert tendsto_cos_pi_div_two.inv_tendsto_nhdsGT_zero.atTop_mul_pos zero_lt_one tendsto_sin_pi_div_two using 1 simp only [Pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos] theorem tendsto_sin_neg_pi_div_two : Tendsto sin (𝓝[>] (-(π / 2))) (𝓝 (-1)) := by convert continuous_sin.continuousWithinAt.tendsto using 2 simp theorem tendsto_cos_neg_pi_div_two : Tendsto cos (𝓝[>] (-(π / 2))) (𝓝[>] 0) := by apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within · convert continuous_cos.continuousWithinAt.tendsto simp · filter_upwards [Ioo_mem_nhdsGT (neg_lt_self pi_div_two_pos)] with x hx exact cos_pos_of_mem_Ioo hx theorem tendsto_tan_neg_pi_div_two : Tendsto tan (𝓝[>] (-(π / 2))) atBot := by convert tendsto_cos_neg_pi_div_two.inv_tendsto_nhdsGT_zero.atTop_mul_neg (by norm_num) tendsto_sin_neg_pi_div_two using 1 simp only [Pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos] end Real namespace Complex open Real theorem sin_eq_zero_iff_cos_eq {z : ℂ} : sin z = 0 ↔ cos z = 1 ∨ cos z = -1 := by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq, sq, sq, ← sub_eq_iff_eq_add, sub_self] exact ⟨fun h => by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ Eq.symm⟩ @[simp] theorem cos_pi_div_two : cos (π / 2) = 0 := calc cos (π / 2) = Real.cos (π / 2) := by rw [ofReal_cos]; simp _ = 0 := by simp @[simp] theorem sin_pi_div_two : sin (π / 2) = 1 := calc sin (π / 2) = Real.sin (π / 2) := by rw [ofReal_sin]; simp _ = 1 := by simp @[simp] theorem sin_pi : sin π = 0 := by rw [← ofReal_sin, Real.sin_pi]; simp @[simp] theorem cos_pi : cos π = -1 := by rw [← ofReal_cos, Real.cos_pi]; simp @[simp] theorem sin_two_pi : sin (2 * π) = 0 := by simp [two_mul, sin_add] @[simp] theorem cos_two_pi : cos (2 * π) = 1 := by simp [two_mul, cos_add] theorem sin_antiperiodic : Function.Antiperiodic sin π := by simp [sin_add] theorem sin_periodic : Function.Periodic sin (2 * π) := sin_antiperiodic.periodic_two_mul theorem sin_add_pi (x : ℂ) : sin (x + π) = -sin x := sin_antiperiodic x theorem sin_add_two_pi (x : ℂ) : sin (x + 2 * π) = sin x := sin_periodic x theorem sin_sub_pi (x : ℂ) : sin (x - π) = -sin x := sin_antiperiodic.sub_eq x theorem sin_sub_two_pi (x : ℂ) : sin (x - 2 * π) = sin x := sin_periodic.sub_eq x theorem sin_pi_sub (x : ℂ) : sin (π - x) = sin x := neg_neg (sin x) ▸ sin_neg x ▸ sin_antiperiodic.sub_eq' theorem sin_two_pi_sub (x : ℂ) : sin (2 * π - x) = -sin x := sin_neg x ▸ sin_periodic.sub_eq' theorem sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 := sin_antiperiodic.nat_mul_eq_of_eq_zero sin_zero n theorem sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 := sin_antiperiodic.int_mul_eq_of_eq_zero sin_zero n theorem sin_add_nat_mul_two_pi (x : ℂ) (n : ℕ) : sin (x + n * (2 * π)) = sin x := sin_periodic.nat_mul n x theorem sin_add_int_mul_two_pi (x : ℂ) (n : ℤ) : sin (x + n * (2 * π)) = sin x := sin_periodic.int_mul n x theorem sin_sub_nat_mul_two_pi (x : ℂ) (n : ℕ) : sin (x - n * (2 * π)) = sin x := sin_periodic.sub_nat_mul_eq n theorem sin_sub_int_mul_two_pi (x : ℂ) (n : ℤ) : sin (x - n * (2 * π)) = sin x := sin_periodic.sub_int_mul_eq n theorem sin_nat_mul_two_pi_sub (x : ℂ) (n : ℕ) : sin (n * (2 * π) - x) = -sin x := sin_neg x ▸ sin_periodic.nat_mul_sub_eq n theorem sin_int_mul_two_pi_sub (x : ℂ) (n : ℤ) : sin (n * (2 * π) - x) = -sin x := sin_neg x ▸ sin_periodic.int_mul_sub_eq n theorem cos_antiperiodic : Function.Antiperiodic cos π := by simp [cos_add] theorem cos_periodic : Function.Periodic cos (2 * π) := cos_antiperiodic.periodic_two_mul theorem cos_add_pi (x : ℂ) : cos (x + π) = -cos x := cos_antiperiodic x theorem cos_add_two_pi (x : ℂ) : cos (x + 2 * π) = cos x := cos_periodic x theorem cos_sub_pi (x : ℂ) : cos (x - π) = -cos x := cos_antiperiodic.sub_eq x theorem cos_sub_two_pi (x : ℂ) : cos (x - 2 * π) = cos x := cos_periodic.sub_eq x theorem cos_pi_sub (x : ℂ) : cos (π - x) = -cos x := cos_neg x ▸ cos_antiperiodic.sub_eq' theorem cos_two_pi_sub (x : ℂ) : cos (2 * π - x) = cos x := cos_neg x ▸ cos_periodic.sub_eq' theorem cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 := (cos_periodic.nat_mul_eq n).trans cos_zero theorem cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 := (cos_periodic.int_mul_eq n).trans cos_zero theorem cos_add_nat_mul_two_pi (x : ℂ) (n : ℕ) : cos (x + n * (2 * π)) = cos x := cos_periodic.nat_mul n x theorem cos_add_int_mul_two_pi (x : ℂ) (n : ℤ) : cos (x + n * (2 * π)) = cos x := cos_periodic.int_mul n x theorem cos_sub_nat_mul_two_pi (x : ℂ) (n : ℕ) : cos (x - n * (2 * π)) = cos x := cos_periodic.sub_nat_mul_eq n theorem cos_sub_int_mul_two_pi (x : ℂ) (n : ℤ) : cos (x - n * (2 * π)) = cos x := cos_periodic.sub_int_mul_eq n theorem cos_nat_mul_two_pi_sub (x : ℂ) (n : ℕ) : cos (n * (2 * π) - x) = cos x := cos_neg x ▸ cos_periodic.nat_mul_sub_eq n theorem cos_int_mul_two_pi_sub (x : ℂ) (n : ℤ) : cos (n * (2 * π) - x) = cos x := cos_neg x ▸ cos_periodic.int_mul_sub_eq n theorem cos_nat_mul_two_pi_add_pi (n : ℕ) : cos (n * (2 * π) + π) = -1 := by simpa only [cos_zero] using (cos_periodic.nat_mul n).add_antiperiod_eq cos_antiperiodic theorem cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 := by simpa only [cos_zero] using (cos_periodic.int_mul n).add_antiperiod_eq cos_antiperiodic theorem cos_nat_mul_two_pi_sub_pi (n : ℕ) : cos (n * (2 * π) - π) = -1 := by simpa only [cos_zero] using (cos_periodic.nat_mul n).sub_antiperiod_eq cos_antiperiodic theorem cos_int_mul_two_pi_sub_pi (n : ℤ) : cos (n * (2 * π) - π) = -1 := by simpa only [cos_zero] using (cos_periodic.int_mul n).sub_antiperiod_eq cos_antiperiodic theorem sin_add_pi_div_two (x : ℂ) : sin (x + π / 2) = cos x := by simp [sin_add] theorem sin_sub_pi_div_two (x : ℂ) : sin (x - π / 2) = -cos x := by simp [sub_eq_add_neg, sin_add] theorem sin_pi_div_two_sub (x : ℂ) : sin (π / 2 - x) = cos x := by simp [sub_eq_add_neg, sin_add] theorem cos_add_pi_div_two (x : ℂ) : cos (x + π / 2) = -sin x := by simp [cos_add] theorem cos_sub_pi_div_two (x : ℂ) : cos (x - π / 2) = sin x := by simp [sub_eq_add_neg, cos_add] theorem cos_pi_div_two_sub (x : ℂ) : cos (π / 2 - x) = sin x := by rw [← cos_neg, neg_sub, cos_sub_pi_div_two] theorem tan_periodic : Function.Periodic tan π := by simpa only [tan_eq_sin_div_cos] using sin_antiperiodic.div cos_antiperiodic theorem tan_add_pi (x : ℂ) : tan (x + π) = tan x := tan_periodic x theorem tan_sub_pi (x : ℂ) : tan (x - π) = tan x := tan_periodic.sub_eq x theorem tan_pi_sub (x : ℂ) : tan (π - x) = -tan x := tan_neg x ▸ tan_periodic.sub_eq' theorem tan_pi_div_two_sub (x : ℂ) : tan (π / 2 - x) = (tan x)⁻¹ := by rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos, inv_div, sin_pi_div_two_sub, cos_pi_div_two_sub] theorem tan_nat_mul_pi (n : ℕ) : tan (n * π) = 0 := tan_zero ▸ tan_periodic.nat_mul_eq n theorem tan_int_mul_pi (n : ℤ) : tan (n * π) = 0 := tan_zero ▸ tan_periodic.int_mul_eq n theorem tan_add_nat_mul_pi (x : ℂ) (n : ℕ) : tan (x + n * π) = tan x := tan_periodic.nat_mul n x theorem tan_add_int_mul_pi (x : ℂ) (n : ℤ) : tan (x + n * π) = tan x := tan_periodic.int_mul n x theorem tan_sub_nat_mul_pi (x : ℂ) (n : ℕ) : tan (x - n * π) = tan x := tan_periodic.sub_nat_mul_eq n theorem tan_sub_int_mul_pi (x : ℂ) (n : ℤ) : tan (x - n * π) = tan x := tan_periodic.sub_int_mul_eq n theorem tan_nat_mul_pi_sub (x : ℂ) (n : ℕ) : tan (n * π - x) = -tan x := tan_neg x ▸ tan_periodic.nat_mul_sub_eq n theorem tan_int_mul_pi_sub (x : ℂ) (n : ℤ) : tan (n * π - x) = -tan x := tan_neg x ▸ tan_periodic.int_mul_sub_eq n theorem exp_antiperiodic : Function.Antiperiodic exp (π * I) := by simp [exp_add, exp_mul_I] theorem exp_periodic : Function.Periodic exp (2 * π * I) := (mul_assoc (2 : ℂ) π I).symm ▸ exp_antiperiodic.periodic_two_mul theorem exp_mul_I_antiperiodic : Function.Antiperiodic (fun x => exp (x * I)) π := by simpa only [mul_inv_cancel_right₀ I_ne_zero] using exp_antiperiodic.mul_const I_ne_zero theorem exp_mul_I_periodic : Function.Periodic (fun x => exp (x * I)) (2 * π) := exp_mul_I_antiperiodic.periodic_two_mul @[simp] theorem exp_pi_mul_I : exp (π * I) = -1 := exp_zero ▸ exp_antiperiodic.eq @[simp] theorem exp_two_pi_mul_I : exp (2 * π * I) = 1 := exp_periodic.eq.trans exp_zero @[simp] lemma exp_pi_div_two_mul_I : exp (π / 2 * I) = I := by rw [← cos_add_sin_I, cos_pi_div_two, sin_pi_div_two, one_mul, zero_add] @[simp] lemma exp_neg_pi_div_two_mul_I : exp (-π / 2 * I) = -I := by rw [← cos_add_sin_I, neg_div, cos_neg, cos_pi_div_two, sin_neg, sin_pi_div_two, zero_add, neg_mul, one_mul] @[simp] theorem exp_nat_mul_two_pi_mul_I (n : ℕ) : exp (n * (2 * π * I)) = 1 := (exp_periodic.nat_mul_eq n).trans exp_zero @[simp] theorem exp_int_mul_two_pi_mul_I (n : ℤ) : exp (n * (2 * π * I)) = 1 := (exp_periodic.int_mul_eq n).trans exp_zero @[simp] theorem exp_add_pi_mul_I (z : ℂ) : exp (z + π * I) = -exp z := exp_antiperiodic z @[simp] theorem exp_sub_pi_mul_I (z : ℂ) : exp (z - π * I) = -exp z := exp_antiperiodic.sub_eq z /-- A supporting lemma for the **Phragmen-Lindelöf principle** in a horizontal strip. If `z : ℂ` belongs to a horizontal strip `|Complex.im z| ≤ b`, `b ≤ π / 2`, and `a ≤ 0`, then $$\left|exp^{a\left(e^{z}+e^{-z}\right)}\right| \le e^{a\cos b \exp^{|re z|}}.$$ -/ theorem norm_exp_mul_exp_add_exp_neg_le_of_abs_im_le {a b : ℝ} (ha : a ≤ 0) {z : ℂ} (hz : |z.im| ≤ b) (hb : b ≤ π / 2) : ‖exp (a * (exp z + exp (-z)))‖ ≤ Real.exp (a * Real.cos b * Real.exp |z.re|) := by simp only [norm_exp, Real.exp_le_exp, re_ofReal_mul, add_re, exp_re, neg_im, Real.cos_neg, ← add_mul, mul_assoc, mul_comm (Real.cos b), neg_re, ← Real.cos_abs z.im] have : Real.exp |z.re| ≤ Real.exp z.re + Real.exp (-z.re) := apply_abs_le_add_of_nonneg (fun x => (Real.exp_pos x).le) z.re refine mul_le_mul_of_nonpos_left (mul_le_mul this ?_ ?_ ((Real.exp_pos _).le.trans this)) ha · exact Real.cos_le_cos_of_nonneg_of_le_pi (_root_.abs_nonneg _) (hb.trans <| half_le_self <| Real.pi_pos.le) hz · refine Real.cos_nonneg_of_mem_Icc ⟨?_, hb⟩ exact (neg_nonpos.2 <| Real.pi_div_two_pos.le).trans ((_root_.abs_nonneg _).trans hz) @[deprecated (since := "2025-02-16")] alias abs_exp_mul_exp_add_exp_neg_le_of_abs_im_le := norm_exp_mul_exp_add_exp_neg_le_of_abs_im_le end Complex
Mathlib/Analysis/SpecialFunctions/Trigonometric/Basic.lean
1,304
1,304
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Option.NAry import Mathlib.Data.Seq.Computation import Mathlib.Tactic.ApplyFun import Mathlib.Data.List.Basic /-! # Possibly infinite lists This file provides a `Seq α` type representing possibly infinite lists (referred here as sequences). It is encoded as an infinite stream of options such that if `f n = none`, then `f m = none` for all `m ≥ n`. -/ namespace Stream' universe u v w /- coinductive seq (α : Type u) : Type u | nil : seq α | cons : α → seq α → seq α -/ /-- A stream `s : Option α` is a sequence if `s.get n = none` implies `s.get (n + 1) = none`. -/ def IsSeq {α : Type u} (s : Stream' (Option α)) : Prop := ∀ {n : ℕ}, s n = none → s (n + 1) = none /-- `Seq α` is the type of possibly infinite lists (referred here as sequences). It is encoded as an infinite stream of options such that if `f n = none`, then `f m = none` for all `m ≥ n`. -/ def Seq (α : Type u) : Type u := { f : Stream' (Option α) // f.IsSeq } /-- `Seq1 α` is the type of nonempty sequences. -/ def Seq1 (α) := α × Seq α namespace Seq variable {α : Type u} {β : Type v} {γ : Type w} /-- The empty sequence -/ def nil : Seq α := ⟨Stream'.const none, fun {_} _ => rfl⟩ instance : Inhabited (Seq α) := ⟨nil⟩ /-- Prepend an element to a sequence -/ def cons (a : α) (s : Seq α) : Seq α := ⟨some a::s.1, by rintro (n | _) h · contradiction · exact s.2 h⟩ @[simp] theorem val_cons (s : Seq α) (x : α) : (cons x s).val = some x::s.val := rfl /-- Get the nth element of a sequence (if it exists) -/ def get? : Seq α → ℕ → Option α := Subtype.val @[simp] theorem val_eq_get (s : Seq α) (n : ℕ) : s.val n = s.get? n := by rfl @[simp] theorem get?_mk (f hf) : @get? α ⟨f, hf⟩ = f := rfl @[simp] theorem get?_nil (n : ℕ) : (@nil α).get? n = none := rfl @[simp] theorem get?_cons_zero (a : α) (s : Seq α) : (cons a s).get? 0 = some a := rfl @[simp] theorem get?_cons_succ (a : α) (s : Seq α) (n : ℕ) : (cons a s).get? (n + 1) = s.get? n := rfl @[ext] protected theorem ext {s t : Seq α} (h : ∀ n : ℕ, s.get? n = t.get? n) : s = t := Subtype.eq <| funext h theorem cons_injective2 : Function.Injective2 (cons : α → Seq α → Seq α) := fun x y s t h => ⟨by rw [← Option.some_inj, ← get?_cons_zero, h, get?_cons_zero], Seq.ext fun n => by simp_rw [← get?_cons_succ x s n, h, get?_cons_succ]⟩ theorem cons_left_injective (s : Seq α) : Function.Injective fun x => cons x s := cons_injective2.left _ theorem cons_right_injective (x : α) : Function.Injective (cons x) := cons_injective2.right _ /-- A sequence has terminated at position `n` if the value at position `n` equals `none`. -/ def TerminatedAt (s : Seq α) (n : ℕ) : Prop := s.get? n = none /-- It is decidable whether a sequence terminates at a given position. -/ instance terminatedAtDecidable (s : Seq α) (n : ℕ) : Decidable (s.TerminatedAt n) := decidable_of_iff' (s.get? n).isNone <| by unfold TerminatedAt; cases s.get? n <;> simp /-- A sequence terminates if there is some position `n` at which it has terminated. -/ def Terminates (s : Seq α) : Prop := ∃ n : ℕ, s.TerminatedAt n theorem not_terminates_iff {s : Seq α} : ¬s.Terminates ↔ ∀ n, (s.get? n).isSome := by simp only [Terminates, TerminatedAt, ← Ne.eq_def, Option.ne_none_iff_isSome, not_exists, iff_self] /-- Functorial action of the functor `Option (α × _)` -/ @[simp] def omap (f : β → γ) : Option (α × β) → Option (α × γ) | none => none | some (a, b) => some (a, f b) /-- Get the first element of a sequence -/ def head (s : Seq α) : Option α := get? s 0 /-- Get the tail of a sequence (or `nil` if the sequence is `nil`) -/ def tail (s : Seq α) : Seq α := ⟨s.1.tail, fun n' => by obtain ⟨f, al⟩ := s exact al n'⟩ /-- member definition for `Seq` -/ protected def Mem (s : Seq α) (a : α) := some a ∈ s.1 instance : Membership α (Seq α) := ⟨Seq.Mem⟩ theorem le_stable (s : Seq α) {m n} (h : m ≤ n) : s.get? m = none → s.get? n = none := by obtain ⟨f, al⟩ := s induction' h with n _ IH exacts [id, fun h2 => al (IH h2)] /-- If a sequence terminated at position `n`, it also terminated at `m ≥ n`. -/ theorem terminated_stable : ∀ (s : Seq α) {m n : ℕ}, m ≤ n → s.TerminatedAt m → s.TerminatedAt n := le_stable /-- If `s.get? n = some aₙ` for some value `aₙ`, then there is also some value `aₘ` such that `s.get? = some aₘ` for `m ≤ n`. -/ theorem ge_stable (s : Seq α) {aₙ : α} {n m : ℕ} (m_le_n : m ≤ n) (s_nth_eq_some : s.get? n = some aₙ) : ∃ aₘ : α, s.get? m = some aₘ := have : s.get? n ≠ none := by simp [s_nth_eq_some] have : s.get? m ≠ none := mt (s.le_stable m_le_n) this Option.ne_none_iff_exists'.mp this theorem not_mem_nil (a : α) : a ∉ @nil α := fun ⟨_, (h : some a = none)⟩ => by injection h
theorem mem_cons (a : α) : ∀ s : Seq α, a ∈ cons a s | ⟨_, _⟩ => Stream'.mem_cons (some a) _
Mathlib/Data/Seq/Seq.lean
160
163
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Yury Kudryashov, Heather Macbeth -/ import Mathlib.MeasureTheory.Function.SimpleFunc import Mathlib.MeasureTheory.Constructions.BorelSpace.Metrizable /-! # Density of simple functions Show that each Borel measurable function can be approximated pointwise by a sequence of simple functions. ## Main definitions * `MeasureTheory.SimpleFunc.nearestPt (e : ℕ → α) (N : ℕ) : α →ₛ ℕ`: the `SimpleFunc` sending each `x : α` to the point `e k` which is the nearest to `x` among `e 0`, ..., `e N`. * `MeasureTheory.SimpleFunc.approxOn (f : β → α) (hf : Measurable f) (s : Set α) (y₀ : α) (h₀ : y₀ ∈ s) [SeparableSpace s] (n : ℕ) : β →ₛ α` : a simple function that takes values in `s` and approximates `f`. ## Main results * `tendsto_approxOn` (pointwise convergence): If `f x ∈ s`, then the sequence of simple approximations `MeasureTheory.SimpleFunc.approxOn f hf s y₀ h₀ n`, evaluated at `x`, tends to `f x` as `n` tends to `∞`. ## Notations * `α →ₛ β` (local notation): the type of simple functions `α → β`. -/ open Set Function Filter TopologicalSpace ENNReal EMetric Finset open Topology ENNReal MeasureTheory variable {α β ι E F 𝕜 : Type*} noncomputable section namespace MeasureTheory local infixr:25 " →ₛ " => SimpleFunc namespace SimpleFunc /-! ### Pointwise approximation by simple functions -/ variable [MeasurableSpace α] [PseudoEMetricSpace α] [OpensMeasurableSpace α] /-- `nearestPtInd e N x` is the index `k` such that `e k` is the nearest point to `x` among the points `e 0`, ..., `e N`. If more than one point are at the same distance from `x`, then `nearestPtInd e N x` returns the least of their indexes. -/ noncomputable def nearestPtInd (e : ℕ → α) : ℕ → α →ₛ ℕ | 0 => const α 0 | N + 1 => piecewise (⋂ k ≤ N, { x | edist (e (N + 1)) x < edist (e k) x }) (MeasurableSet.iInter fun _ => MeasurableSet.iInter fun _ => measurableSet_lt measurable_edist_right measurable_edist_right) (const α <| N + 1) (nearestPtInd e N) /-- `nearestPt e N x` is the nearest point to `x` among the points `e 0`, ..., `e N`. If more than one point are at the same distance from `x`, then `nearestPt e N x` returns the point with the least possible index. -/ noncomputable def nearestPt (e : ℕ → α) (N : ℕ) : α →ₛ α := (nearestPtInd e N).map e @[simp] theorem nearestPtInd_zero (e : ℕ → α) : nearestPtInd e 0 = const α 0 := rfl @[simp] theorem nearestPt_zero (e : ℕ → α) : nearestPt e 0 = const α (e 0) := rfl theorem nearestPtInd_succ (e : ℕ → α) (N : ℕ) (x : α) : nearestPtInd e (N + 1) x = if ∀ k ≤ N, edist (e (N + 1)) x < edist (e k) x then N + 1 else nearestPtInd e N x := by simp only [nearestPtInd, coe_piecewise, Set.piecewise] congr simp theorem nearestPtInd_le (e : ℕ → α) (N : ℕ) (x : α) : nearestPtInd e N x ≤ N := by induction' N with N ihN; · simp simp only [nearestPtInd_succ] split_ifs exacts [le_rfl, ihN.trans N.le_succ] theorem edist_nearestPt_le (e : ℕ → α) (x : α) {k N : ℕ} (hk : k ≤ N) : edist (nearestPt e N x) x ≤ edist (e k) x := by
induction' N with N ihN generalizing k · simp [nonpos_iff_eq_zero.1 hk, le_refl] · simp only [nearestPt, nearestPtInd_succ, map_apply] split_ifs with h · rcases hk.eq_or_lt with (rfl | hk)
Mathlib/MeasureTheory/Function/SimpleFuncDense.lean
95
99
/- 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.Bool.Basic import Mathlib.Order.Monotone.Basic import Mathlib.Order.ULift import Mathlib.Tactic.GCongr.CoreAttrs /-! # (Semi-)lattices Semilattices are partially ordered sets with join (least upper bound, or `sup`) or meet (greatest lower bound, or `inf`) operations. Lattices are posets that are both join-semilattices and meet-semilattices. Distributive lattices are lattices which satisfy any of four equivalent distributivity properties, of `sup` over `inf`, on the left or on the right. ## Main declarations * `SemilatticeSup`: a type class for join semilattices * `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `⊔` is commutative, associative and idempotent. * `SemilatticeInf`: a type class for meet semilattices * `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `⊓` is commutative, associative and idempotent. * `Lattice`: a type class for lattices * `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `⊔` and `⊓` are commutative, associative and satisfy a pair of "absorption laws". * `DistribLattice`: a type class for distributive lattices. ## Notations * `a ⊔ b`: the supremum or join of `a` and `b` * `a ⊓ b`: the infimum or meet of `a` and `b` ## TODO * (Semi-)lattice homomorphisms * Alternative constructors for distributive lattices from the other distributive properties ## Tags semilattice, lattice -/ /-- See if the term is `a ⊂ b` and the goal is `a ⊆ b`. -/ @[gcongr_forward] def exactSubsetOfSSubset : Mathlib.Tactic.GCongr.ForwardExt where eval h goal := do goal.assignIfDefEq (← Lean.Meta.mkAppM ``subset_of_ssubset #[h]) universe u v w variable {α : Type u} {β : Type v} /-! ### Join-semilattices -/ -- TODO: automatic construction of dual definitions / theorems /-- A `SemilatticeSup` is a join-semilattice, that is, a partial order with a join (a.k.a. lub / least upper bound, sup / supremum) operation `⊔` which is the least element larger than both factors. -/ class SemilatticeSup (α : Type u) extends PartialOrder α where /-- The binary supremum, used to derive `Max α` -/ sup : α → α → α /-- The supremum is an upper bound on the first argument -/ protected le_sup_left : ∀ a b : α, a ≤ sup a b /-- The supremum is an upper bound on the second argument -/ protected le_sup_right : ∀ a b : α, b ≤ sup a b /-- The supremum is the *least* upper bound -/ protected sup_le : ∀ a b c : α, a ≤ c → b ≤ c → sup a b ≤ c instance SemilatticeSup.toMax [SemilatticeSup α] : Max α where max a b := SemilatticeSup.sup a b /-- A type with a commutative, associative and idempotent binary `sup` operation has the structure of a join-semilattice. The partial order is defined so that `a ≤ b` unfolds to `a ⊔ b = b`; cf. `sup_eq_right`. -/ def SemilatticeSup.mk' {α : Type*} [Max α] (sup_comm : ∀ a b : α, a ⊔ b = b ⊔ a) (sup_assoc : ∀ a b c : α, a ⊔ b ⊔ c = a ⊔ (b ⊔ c)) (sup_idem : ∀ a : α, a ⊔ a = a) : SemilatticeSup α where sup := (· ⊔ ·) le a b := a ⊔ b = b le_refl := sup_idem le_trans a b c hab hbc := by rw [← hbc, ← sup_assoc, hab] le_antisymm a b hab hba := by rwa [← hba, sup_comm] le_sup_left a b := by rw [← sup_assoc, sup_idem] le_sup_right a b := by rw [sup_comm, sup_assoc, sup_idem] sup_le a b c hac hbc := by rwa [sup_assoc, hbc] section SemilatticeSup variable [SemilatticeSup α] {a b c d : α} @[simp] theorem le_sup_left : a ≤ a ⊔ b := SemilatticeSup.le_sup_left a b @[simp] theorem le_sup_right : b ≤ a ⊔ b := SemilatticeSup.le_sup_right a b theorem le_sup_of_le_left (h : c ≤ a) : c ≤ a ⊔ b := le_trans h le_sup_left theorem le_sup_of_le_right (h : c ≤ b) : c ≤ a ⊔ b := le_trans h le_sup_right theorem lt_sup_of_lt_left (h : c < a) : c < a ⊔ b := h.trans_le le_sup_left theorem lt_sup_of_lt_right (h : c < b) : c < a ⊔ b := h.trans_le le_sup_right theorem sup_le : a ≤ c → b ≤ c → a ⊔ b ≤ c := SemilatticeSup.sup_le a b c @[simp] theorem sup_le_iff : a ⊔ b ≤ c ↔ a ≤ c ∧ b ≤ c := ⟨fun h : a ⊔ b ≤ c => ⟨le_trans le_sup_left h, le_trans le_sup_right h⟩, fun ⟨h₁, h₂⟩ => sup_le h₁ h₂⟩ @[simp] theorem sup_eq_left : a ⊔ b = a ↔ b ≤ a := le_antisymm_iff.trans <| by simp [le_rfl] @[simp] theorem sup_eq_right : a ⊔ b = b ↔ a ≤ b := le_antisymm_iff.trans <| by simp [le_rfl] @[simp] theorem left_eq_sup : a = a ⊔ b ↔ b ≤ a := eq_comm.trans sup_eq_left @[simp] theorem right_eq_sup : b = a ⊔ b ↔ a ≤ b := eq_comm.trans sup_eq_right alias ⟨_, sup_of_le_left⟩ := sup_eq_left alias ⟨le_of_sup_eq, sup_of_le_right⟩ := sup_eq_right attribute [simp] sup_of_le_left sup_of_le_right @[simp] theorem left_lt_sup : a < a ⊔ b ↔ ¬b ≤ a :=
le_sup_left.lt_iff_ne.trans <| not_congr left_eq_sup
Mathlib/Order/Lattice.lean
154
155
/- 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, Alexander Bentkamp -/ import Mathlib.LinearAlgebra.FreeModule.Basic import Mathlib.LinearAlgebra.LinearIndependent.Lemmas import Mathlib.LinearAlgebra.LinearPMap import Mathlib.LinearAlgebra.Projection /-! # Bases in a vector space This file provides results for bases of a vector space. Some of these results should be merged with the results on free modules. We state these results in a separate file to the results on modules to avoid an import cycle. ## Main statements * `Basis.ofVectorSpace` states that every vector space has a basis. * `Module.Free.of_divisionRing` states that every vector space is a free module. ## Tags basis, bases -/ open Function Set Submodule variable {ι : Type*} {ι' : Type*} {K : Type*} {V : Type*} {V' : Type*} section DivisionRing variable [DivisionRing K] [AddCommGroup V] [AddCommGroup V'] [Module K V] [Module K V'] variable {v : ι → V} {s t : Set V} {x y z : V} open Submodule namespace Basis section ExistsBasis /-- If `s` is a linear independent set of vectors, we can extend it to a basis. -/ noncomputable def extend (hs : LinearIndepOn K id s) : Basis (hs.extend (subset_univ s)) K V := Basis.mk (hs.linearIndepOn_extend _).linearIndependent_restrict (SetLike.coe_subset_coe.mp <| by simpa using hs.subset_span_extend (subset_univ s)) theorem extend_apply_self (hs : LinearIndepOn K id s) (x : hs.extend _) : Basis.extend hs x = x := Basis.mk_apply _ _ _ @[simp] theorem coe_extend (hs : LinearIndepOn K id s) : ⇑(Basis.extend hs) = ((↑) : _ → _) := funext (extend_apply_self hs) theorem range_extend (hs : LinearIndepOn K id s) : range (Basis.extend hs) = hs.extend (subset_univ _) := by rw [coe_extend, Subtype.range_coe_subtype, setOf_mem_eq] /-- Auxiliary definition: the index for the new basis vectors in `Basis.sumExtend`. The specific value of this definition should be considered an implementation detail. -/ def sumExtendIndex (hs : LinearIndependent K v) : Set V := LinearIndepOn.extend hs.linearIndepOn_id (subset_univ _) \ range v /-- If `v` is a linear independent family of vectors, extend it to a basis indexed by a sum type. -/ noncomputable def sumExtend (hs : LinearIndependent K v) : Basis (ι ⊕ sumExtendIndex hs) K V := let s := Set.range v let e : ι ≃ s := Equiv.ofInjective v hs.injective let b := hs.linearIndepOn_id.extend (subset_univ (Set.range v)) (Basis.extend hs.linearIndepOn_id).reindex <| Equiv.symm <| calc ι ⊕ (b \ s : Set V) ≃ s ⊕ (b \ s : Set V) := Equiv.sumCongr e (Equiv.refl _) _ ≃ b := haveI := Classical.decPred (· ∈ s) Equiv.Set.sumDiffSubset (hs.linearIndepOn_id.subset_extend _) theorem subset_extend {s : Set V} (hs : LinearIndepOn K id s) : s ⊆ hs.extend (Set.subset_univ _) := hs.subset_extend _ /-- If `s` is a family of linearly independent vectors contained in a set `t` spanning `V`, then one can get a basis of `V` containing `s` and contained in `t`. -/ noncomputable def extendLe (hs : LinearIndepOn K id s) (hst : s ⊆ t) (ht : ⊤ ≤ span K t) : Basis (hs.extend hst) K V := Basis.mk ((hs.linearIndepOn_extend _).linearIndependent ..) (le_trans ht <| Submodule.span_le.2 <| by simpa using hs.subset_span_extend hst) theorem extendLe_apply_self (hs : LinearIndepOn K id s) (hst : s ⊆ t) (ht : ⊤ ≤ span K t) (x : hs.extend hst) : Basis.extendLe hs hst ht x = x := Basis.mk_apply _ _ _ @[simp] theorem coe_extendLe (hs : LinearIndepOn K id s) (hst : s ⊆ t) (ht : ⊤ ≤ span K t) : ⇑(Basis.extendLe hs hst ht) = ((↑) : _ → _) := funext (extendLe_apply_self hs hst ht) theorem range_extendLe (hs : LinearIndepOn K id s) (hst : s ⊆ t) (ht : ⊤ ≤ span K t) : range (Basis.extendLe hs hst ht) = hs.extend hst := by rw [coe_extendLe, Subtype.range_coe_subtype, setOf_mem_eq] theorem subset_extendLe (hs : LinearIndepOn K id s) (hst : s ⊆ t) (ht : ⊤ ≤ span K t) : s ⊆ range (Basis.extendLe hs hst ht) := (range_extendLe hs hst ht).symm ▸ hs.subset_extend hst theorem extendLe_subset (hs : LinearIndepOn K id s) (hst : s ⊆ t) (ht : ⊤ ≤ span K t) : range (Basis.extendLe hs hst ht) ⊆ t := (range_extendLe hs hst ht).symm ▸ hs.extend_subset hst /-- If a set `s` spans the space, this is a basis contained in `s`. -/ noncomputable def ofSpan (hs : ⊤ ≤ span K s) : Basis ((linearIndepOn_empty K id).extend (empty_subset s)) K V := extendLe (linearIndependent_empty K V) (empty_subset s) hs theorem ofSpan_apply_self (hs : ⊤ ≤ span K s) (x : (linearIndepOn_empty K id).extend (empty_subset s)) : Basis.ofSpan hs x = x := extendLe_apply_self (linearIndependent_empty K V) (empty_subset s) hs x @[simp] theorem coe_ofSpan (hs : ⊤ ≤ span K s) : ⇑(ofSpan hs) = ((↑) : _ → _) :=
funext (ofSpan_apply_self hs) theorem range_ofSpan (hs : ⊤ ≤ span K s) : range (ofSpan hs) = (linearIndepOn_empty K id).extend (empty_subset s) := by rw [coe_ofSpan, Subtype.range_coe_subtype, setOf_mem_eq]
Mathlib/LinearAlgebra/Basis/VectorSpace.lean
127
131
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Markus Himmel -/ import Mathlib.CategoryTheory.Limits.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Mono import Mathlib.CategoryTheory.Limits.Shapes.StrongEpi import Mathlib.CategoryTheory.MorphismProperty.Factorization /-! # Categorical images We define the categorical image of `f` as a factorisation `f = e ≫ m` through a monomorphism `m`, so that `m` factors through the `m'` in any other such factorisation. ## Main definitions * A `MonoFactorisation` is a factorisation `f = e ≫ m`, where `m` is a monomorphism * `IsImage F` means that a given mono factorisation `F` has the universal property of the image. * `HasImage f` means that there is some image factorization for the morphism `f : X ⟶ Y`. * In this case, `image f` is some image object (selected with choice), `image.ι f : image f ⟶ Y` is the monomorphism `m` of the factorisation and `factorThruImage f : X ⟶ image f` is the morphism `e`. * `HasImages C` means that every morphism in `C` has an image. * Let `f : X ⟶ Y` and `g : P ⟶ Q` be morphisms in `C`, which we will represent as objects of the arrow category `Arrow C`. Then `sq : f ⟶ g` is a commutative square in `C`. If `f` and `g` have images, then `HasImageMap sq` represents the fact that there is a morphism `i : image f ⟶ image g` making the diagram X ----→ image f ----→ Y | | | | | | ↓ ↓ ↓ P ----→ image g ----→ Q commute, where the top row is the image factorisation of `f`, the bottom row is the image factorisation of `g`, and the outer rectangle is the commutative square `sq`. * If a category `HasImages`, then `HasImageMaps` means that every commutative square admits an image map. * If a category `HasImages`, then `HasStrongEpiImages` means that the morphism to the image is always a strong epimorphism. ## Main statements * When `C` has equalizers, the morphism `e` appearing in an image factorisation is an epimorphism. * When `C` has strong epi images, then these images admit image maps. ## Future work * TODO: coimages, and abelian categories. * TODO: connect this with existing working in the group theory and ring theory libraries. -/ noncomputable section universe v u open CategoryTheory open CategoryTheory.Limits.WalkingParallelPair namespace CategoryTheory.Limits variable {C : Type u} [Category.{v} C] variable {X Y : C} (f : X ⟶ Y) /-- A factorisation of a morphism `f = e ≫ m`, with `m` monic. -/ structure MonoFactorisation (f : X ⟶ Y) where I : C -- Porting note: violates naming conventions but can't think a better replacement m : I ⟶ Y [m_mono : Mono m] e : X ⟶ I fac : e ≫ m = f := by aesop_cat attribute [inherit_doc MonoFactorisation] MonoFactorisation.I MonoFactorisation.m MonoFactorisation.m_mono MonoFactorisation.e MonoFactorisation.fac attribute [reassoc (attr := simp)] MonoFactorisation.fac attribute [instance] MonoFactorisation.m_mono namespace MonoFactorisation /-- The obvious factorisation of a monomorphism through itself. -/ def self [Mono f] : MonoFactorisation f where I := X m := f e := 𝟙 X -- I'm not sure we really need this, but the linter says that an inhabited instance -- ought to exist... instance [Mono f] : Inhabited (MonoFactorisation f) := ⟨self f⟩ variable {f} /-- The morphism `m` in a factorisation `f = e ≫ m` through a monomorphism is uniquely determined. -/ @[ext (iff := false)] theorem ext {F F' : MonoFactorisation f} (hI : F.I = F'.I) (hm : F.m = eqToHom hI ≫ F'.m) : F = F' := by obtain ⟨_, Fm, _, Ffac⟩ := F; obtain ⟨_, Fm', _, Ffac'⟩ := F' cases hI simp? at hm says simp only [eqToHom_refl, Category.id_comp] at hm congr apply (cancel_mono Fm).1 rw [Ffac, hm, Ffac'] /-- Any mono factorisation of `f` gives a mono factorisation of `f ≫ g` when `g` is a mono. -/ @[simps] def compMono (F : MonoFactorisation f) {Y' : C} (g : Y ⟶ Y') [Mono g] : MonoFactorisation (f ≫ g) where I := F.I m := F.m ≫ g m_mono := mono_comp _ _ e := F.e /-- A mono factorisation of `f ≫ g`, where `g` is an isomorphism, gives a mono factorisation of `f`. -/ @[simps] def ofCompIso {Y' : C} {g : Y ⟶ Y'} [IsIso g] (F : MonoFactorisation (f ≫ g)) : MonoFactorisation f where I := F.I m := F.m ≫ inv g m_mono := mono_comp _ _ e := F.e /-- Any mono factorisation of `f` gives a mono factorisation of `g ≫ f`. -/ @[simps] def isoComp (F : MonoFactorisation f) {X' : C} (g : X' ⟶ X) : MonoFactorisation (g ≫ f) where I := F.I m := F.m e := g ≫ F.e /-- A mono factorisation of `g ≫ f`, where `g` is an isomorphism, gives a mono factorisation of `f`. -/ @[simps] def ofIsoComp {X' : C} (g : X' ⟶ X) [IsIso g] (F : MonoFactorisation (g ≫ f)) : MonoFactorisation f where I := F.I m := F.m e := inv g ≫ F.e /-- If `f` and `g` are isomorphic arrows, then a mono factorisation of `f` gives a mono factorisation of `g` -/ @[simps] def ofArrowIso {f g : Arrow C} (F : MonoFactorisation f.hom) (sq : f ⟶ g) [IsIso sq] : MonoFactorisation g.hom where I := F.I m := F.m ≫ sq.right e := inv sq.left ≫ F.e m_mono := mono_comp _ _ fac := by simp only [fac_assoc, Arrow.w, IsIso.inv_comp_eq, Category.assoc] end MonoFactorisation variable {f} /-- Data exhibiting that a given factorisation through a mono is initial. -/ structure IsImage (F : MonoFactorisation f) where lift : ∀ F' : MonoFactorisation f, F.I ⟶ F'.I lift_fac : ∀ F' : MonoFactorisation f, lift F' ≫ F'.m = F.m := by aesop_cat attribute [inherit_doc IsImage] IsImage.lift IsImage.lift_fac attribute [reassoc (attr := simp)] IsImage.lift_fac namespace IsImage @[reassoc (attr := simp)] theorem fac_lift {F : MonoFactorisation f} (hF : IsImage F) (F' : MonoFactorisation f) : F.e ≫ hF.lift F' = F'.e := (cancel_mono F'.m).1 <| by simp variable (f) /-- The trivial factorisation of a monomorphism satisfies the universal property. -/ @[simps] def self [Mono f] : IsImage (MonoFactorisation.self f) where lift F' := F'.e instance [Mono f] : Inhabited (IsImage (MonoFactorisation.self f)) := ⟨self f⟩ variable {f} -- TODO this is another good candidate for a future `UniqueUpToCanonicalIso`. /-- Two factorisations through monomorphisms satisfying the universal property must factor through isomorphic objects. -/ @[simps] def isoExt {F F' : MonoFactorisation f} (hF : IsImage F) (hF' : IsImage F') : F.I ≅ F'.I where hom := hF.lift F' inv := hF'.lift F hom_inv_id := (cancel_mono F.m).1 (by simp) inv_hom_id := (cancel_mono F'.m).1 (by simp) variable {F F' : MonoFactorisation f} (hF : IsImage F) (hF' : IsImage F') theorem isoExt_hom_m : (isoExt hF hF').hom ≫ F'.m = F.m := by simp theorem isoExt_inv_m : (isoExt hF hF').inv ≫ F.m = F'.m := by simp theorem e_isoExt_hom : F.e ≫ (isoExt hF hF').hom = F'.e := by simp theorem e_isoExt_inv : F'.e ≫ (isoExt hF hF').inv = F.e := by simp /-- If `f` and `g` are isomorphic arrows, then a mono factorisation of `f` that is an image gives a mono factorisation of `g` that is an image -/ @[simps] def ofArrowIso {f g : Arrow C} {F : MonoFactorisation f.hom} (hF : IsImage F) (sq : f ⟶ g) [IsIso sq] : IsImage (F.ofArrowIso sq) where lift F' := hF.lift (F'.ofArrowIso (inv sq)) lift_fac F' := by simpa only [MonoFactorisation.ofArrowIso_m, Arrow.inv_right, ← Category.assoc, IsIso.comp_inv_eq] using hF.lift_fac (F'.ofArrowIso (inv sq))
end IsImage
Mathlib/CategoryTheory/Limits/Shapes/Images.lean
218
218
/- 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
1,054
1,107
/- Copyright (c) 2022 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker -/ import Mathlib.Analysis.InnerProductSpace.Adjoint /-! # Positive operators In this file we define positive operators in a Hilbert space. We follow Bourbaki's choice of requiring self adjointness in the definition. ## Main definitions * `IsPositive` : a continuous linear map is positive if it is self adjoint and `∀ x, 0 ≤ re ⟪T x, x⟫` ## Main statements * `ContinuousLinearMap.IsPositive.conj_adjoint` : if `T : E →L[𝕜] E` is positive, then for any `S : E →L[𝕜] F`, `S ∘L T ∘L S†` is also positive. * `ContinuousLinearMap.isPositive_iff_complex` : in a ***complex*** Hilbert space, checking that `⟪T x, x⟫` is a nonnegative real number for all `x` suffices to prove that `T` is positive ## References * [Bourbaki, *Topological Vector Spaces*][bourbaki1987] ## Tags Positive operator -/ open InnerProductSpace RCLike ContinuousLinearMap open scoped InnerProduct ComplexConjugate namespace ContinuousLinearMap variable {𝕜 E F : Type*} [RCLike 𝕜] variable [NormedAddCommGroup E] [NormedAddCommGroup F] variable [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 F] variable [CompleteSpace E] [CompleteSpace F] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y /-- A continuous linear endomorphism `T` of a Hilbert space is **positive** if it is self adjoint and `∀ x, 0 ≤ re ⟪T x, x⟫`. -/ def IsPositive (T : E →L[𝕜] E) : Prop := IsSelfAdjoint T ∧ ∀ x, 0 ≤ T.reApplyInnerSelf x theorem IsPositive.isSelfAdjoint {T : E →L[𝕜] E} (hT : IsPositive T) : IsSelfAdjoint T := hT.1 theorem IsPositive.inner_nonneg_left {T : E →L[𝕜] E} (hT : IsPositive T) (x : E) : 0 ≤ re ⟪T x, x⟫ := hT.2 x theorem IsPositive.inner_nonneg_right {T : E →L[𝕜] E} (hT : IsPositive T) (x : E) : 0 ≤ re ⟪x, T x⟫ := by rw [inner_re_symm]; exact hT.inner_nonneg_left x theorem isPositive_zero : IsPositive (0 : E →L[𝕜] E) := by refine ⟨.zero _, fun x => ?_⟩ change 0 ≤ re ⟪_, _⟫ rw [zero_apply, inner_zero_left, ZeroHomClass.map_zero] theorem isPositive_one : IsPositive (1 : E →L[𝕜] E) := ⟨.one _, fun _ => inner_self_nonneg⟩ theorem IsPositive.add {T S : E →L[𝕜] E} (hT : T.IsPositive) (hS : S.IsPositive) : (T + S).IsPositive := by refine ⟨hT.isSelfAdjoint.add hS.isSelfAdjoint, fun x => ?_⟩ rw [reApplyInnerSelf, add_apply, inner_add_left, map_add] exact add_nonneg (hT.inner_nonneg_left x) (hS.inner_nonneg_left x) theorem IsPositive.conj_adjoint {T : E →L[𝕜] E} (hT : T.IsPositive) (S : E →L[𝕜] F) : (S ∘L T ∘L S†).IsPositive := by refine ⟨hT.isSelfAdjoint.conj_adjoint S, fun x => ?_⟩ rw [reApplyInnerSelf, comp_apply, ← adjoint_inner_right] exact hT.inner_nonneg_left _ theorem IsPositive.adjoint_conj {T : E →L[𝕜] E} (hT : T.IsPositive) (S : F →L[𝕜] E) : (S† ∘L T ∘L S).IsPositive := by convert hT.conj_adjoint (S†)
rw [adjoint_adjoint] theorem IsPositive.conj_orthogonalProjection (U : Submodule 𝕜 E) {T : E →L[𝕜] E} (hT : T.IsPositive) [CompleteSpace U] : (U.subtypeL ∘L
Mathlib/Analysis/InnerProductSpace/Positive.lean
88
92
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.Data.ENat.Lattice import Mathlib.Order.OrderIsoNat import Mathlib.Tactic.TFAE /-! # Maximal length of chains This file contains lemmas to work with the maximal length of strictly descending finite sequences (chains) in a partial order. ## Main definition - `Set.subchain`: The set of strictly ascending lists of `α` contained in a `Set α`. - `Set.chainHeight`: The maximal length of a strictly ascending sequence in a partial order. This is defined as the maximum of the lengths of `Set.subchain`s, valued in `ℕ∞`. ## Main results - `Set.exists_chain_of_le_chainHeight`: For each `n : ℕ` such that `n ≤ s.chainHeight`, there exists `s.subchain` of length `n`. - `Set.chainHeight_mono`: If `s ⊆ t` then `s.chainHeight ≤ t.chainHeight`. - `Set.chainHeight_image`: If `f` is an order embedding, then `(f '' s).chainHeight = s.chainHeight`. - `Set.chainHeight_insert_of_forall_lt`: If `∀ y ∈ s, y < x`, then `(insert x s).chainHeight = s.chainHeight + 1`. - `Set.chainHeight_insert_of_forall_gt`: If `∀ y ∈ s, x < y`, then `(insert x s).chainHeight = s.chainHeight + 1`. - `Set.chainHeight_union_eq`: If `∀ x ∈ s, ∀ y ∈ t, s ≤ t`, then `(s ∪ t).chainHeight = s.chainHeight + t.chainHeight`. - `Set.wellFoundedGT_of_chainHeight_ne_top`: If `s` has finite height, then `>` is well-founded on `s`. - `Set.wellFoundedLT_of_chainHeight_ne_top`: If `s` has finite height, then `<` is well-founded on `s`. -/ assert_not_exists Field open List hiding le_antisymm open OrderDual universe u v variable {α β : Type*} namespace Set section LT variable [LT α] [LT β] (s t : Set α) /-- The set of strictly ascending lists of `α` contained in a `Set α`. -/ def subchain : Set (List α) := { l | l.Chain' (· < ·) ∧ ∀ i ∈ l, i ∈ s } @[simp] theorem nil_mem_subchain : [] ∈ s.subchain := ⟨trivial, fun _ ↦ nofun⟩ variable {s} {l : List α} {a : α} theorem cons_mem_subchain_iff : (a::l) ∈ s.subchain ↔ a ∈ s ∧ l ∈ s.subchain ∧ ∀ b ∈ l.head?, a < b := by simp only [subchain, mem_setOf_eq, forall_mem_cons, chain'_cons', and_left_comm, and_comm, and_assoc] @[simp] theorem singleton_mem_subchain_iff : [a] ∈ s.subchain ↔ a ∈ s := by simp [cons_mem_subchain_iff] instance : Nonempty s.subchain := ⟨⟨[], s.nil_mem_subchain⟩⟩ variable (s) /-- The maximal length of a strictly ascending sequence in a partial order. -/ noncomputable def chainHeight : ℕ∞ := ⨆ l ∈ s.subchain, length l theorem chainHeight_eq_iSup_subtype : s.chainHeight = ⨆ l : s.subchain, ↑l.1.length := iSup_subtype' theorem exists_chain_of_le_chainHeight {n : ℕ} (hn : ↑n ≤ s.chainHeight) : ∃ l ∈ s.subchain, length l = n := by rcases (le_top : s.chainHeight ≤ ⊤).eq_or_lt with ha | ha <;> rw [chainHeight_eq_iSup_subtype] at ha · obtain ⟨_, ⟨⟨l, h₁, h₂⟩, rfl⟩, h₃⟩ := not_bddAbove_iff'.mp (WithTop.iSup_coe_eq_top.1 ha) n exact ⟨l.take n, ⟨h₁.take _, fun x h ↦ h₂ _ <| take_subset _ _ h⟩, (l.length_take).trans <| min_eq_left <| le_of_not_ge h₃⟩ · rw [ENat.iSup_coe_lt_top] at ha obtain ⟨⟨l, h₁, h₂⟩, e : l.length = _⟩ := Nat.sSup_mem (Set.range_nonempty _) ha refine ⟨l.take n, ⟨h₁.take _, fun x h ↦ h₂ _ <| take_subset _ _ h⟩, (l.length_take).trans <| min_eq_left <| ?_⟩ rwa [e, ← Nat.cast_le (α := ℕ∞), sSup_range, ENat.coe_iSup ha, ← chainHeight_eq_iSup_subtype] theorem le_chainHeight_TFAE (n : ℕ) : TFAE [↑n ≤ s.chainHeight, ∃ l ∈ s.subchain, length l = n, ∃ l ∈ s.subchain, n ≤ length l] := by tfae_have 1 → 2 := s.exists_chain_of_le_chainHeight tfae_have 2 → 3 := fun ⟨l, hls, he⟩ ↦ ⟨l, hls, he.ge⟩ tfae_have 3 → 1 := fun ⟨l, hs, hn⟩ ↦ le_iSup₂_of_le l hs (WithTop.coe_le_coe.2 hn) tfae_finish variable {s t} theorem le_chainHeight_iff {n : ℕ} : ↑n ≤ s.chainHeight ↔ ∃ l ∈ s.subchain, length l = n := (le_chainHeight_TFAE s n).out 0 1 theorem length_le_chainHeight_of_mem_subchain (hl : l ∈ s.subchain) : ↑l.length ≤ s.chainHeight := le_chainHeight_iff.mpr ⟨l, hl, rfl⟩ theorem chainHeight_eq_top_iff : s.chainHeight = ⊤ ↔ ∀ n, ∃ l ∈ s.subchain, length l = n := by refine ⟨fun h n ↦ le_chainHeight_iff.1 (le_top.trans_eq h.symm), fun h ↦ ?_⟩ contrapose! h; obtain ⟨n, hn⟩ := WithTop.ne_top_iff_exists.1 h exact ⟨n + 1, fun l hs ↦ (Nat.lt_succ_iff.2 <| Nat.cast_le.1 <| (length_le_chainHeight_of_mem_subchain hs).trans_eq hn.symm).ne⟩ @[simp] theorem one_le_chainHeight_iff : 1 ≤ s.chainHeight ↔ s.Nonempty := by rw [← Nat.cast_one, Set.le_chainHeight_iff] simp only [length_eq_one_iff, @and_comm (_ ∈ _), @eq_comm _ _ [_], exists_exists_eq_and, singleton_mem_subchain_iff, Set.Nonempty] @[simp] theorem chainHeight_eq_zero_iff : s.chainHeight = 0 ↔ s = ∅ := by rw [← not_iff_not, ← Ne, ← ENat.one_le_iff_ne_zero, one_le_chainHeight_iff, nonempty_iff_ne_empty] @[simp]
theorem chainHeight_empty : (∅ : Set α).chainHeight = 0 := chainHeight_eq_zero_iff.2 rfl @[simp]
Mathlib/Order/Height.lean
135
138
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Finset.Sigma import Mathlib.Data.Fintype.OfMap /-! # fintype instances for sigma types -/ open Function open Nat universe u v variable {ι α : Type*} {κ : ι → Type*} [Π i, Fintype (κ i)] open Finset Function lemma Set.biUnion_finsetSigma_univ (s : Finset ι) (f : Sigma κ → Set α) : ⋃ ij ∈ s.sigma fun _ ↦ Finset.univ, f ij = ⋃ i ∈ s, ⋃ j, f ⟨i, j⟩ := by aesop lemma Set.biUnion_finsetSigma_univ' (s : Finset ι) (f : Π i, κ i → Set α) : ⋃ i ∈ s, ⋃ j, f i j = ⋃ ij ∈ s.sigma fun _ ↦ Finset.univ, f ij.1 ij.2 := by aesop
lemma Set.biInter_finsetSigma_univ (s : Finset ι) (f : Sigma κ → Set α) :
Mathlib/Data/Fintype/Sigma.lean
29
30
/- 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.Vector.Defs import Mathlib.Data.List.Nodup import Mathlib.Data.List.OfFn import Mathlib.Data.List.Scan import Mathlib.Control.Applicative import Mathlib.Control.Traversable.Basic import Mathlib.Algebra.BigOperators.Group.List.Basic /-! # Additional theorems and definitions about the `Vector` type This file introduces the infix notation `::ᵥ` for `Vector.cons`. -/ universe u variable {α β γ σ φ : Type*} {m n : ℕ} namespace List.Vector @[inherit_doc] infixr:67 " ::ᵥ " => Vector.cons attribute [simp] head_cons tail_cons instance [Inhabited α] : Inhabited (Vector α n) := ⟨ofFn default⟩ theorem toList_injective : Function.Injective (@toList α n) := Subtype.val_injective /-- Two `v w : Vector α n` are equal iff they are equal at every single index. -/ @[ext] theorem ext : ∀ {v w : Vector α n} (_ : ∀ m : Fin n, Vector.get v m = Vector.get w m), v = w | ⟨v, hv⟩, ⟨w, hw⟩, h => Subtype.eq (List.ext_get (by rw [hv, hw]) fun m hm _ => h ⟨m, hv ▸ hm⟩) /-- The empty `Vector` is a `Subsingleton`. -/ instance zero_subsingleton : Subsingleton (Vector α 0) := ⟨fun _ _ => Vector.ext fun m => Fin.elim0 m⟩ @[simp] theorem cons_val (a : α) : ∀ v : Vector α n, (a ::ᵥ v).val = a :: v.val | ⟨_, _⟩ => rfl theorem eq_cons_iff (a : α) (v : Vector α n.succ) (v' : Vector α n) : v = a ::ᵥ v' ↔ v.head = a ∧ v.tail = v' := ⟨fun h => h.symm ▸ ⟨head_cons a v', tail_cons a v'⟩, fun h => _root_.trans (cons_head_tail v).symm (by rw [h.1, h.2])⟩ theorem ne_cons_iff (a : α) (v : Vector α n.succ) (v' : Vector α n) : v ≠ a ::ᵥ v' ↔ v.head ≠ a ∨ v.tail ≠ v' := by rw [Ne, eq_cons_iff a v v', not_and_or] theorem exists_eq_cons (v : Vector α n.succ) : ∃ (a : α) (as : Vector α n), v = a ::ᵥ as := ⟨v.head, v.tail, (eq_cons_iff v.head v v.tail).2 ⟨rfl, rfl⟩⟩ @[simp] theorem toList_ofFn : ∀ {n} (f : Fin n → α), toList (ofFn f) = List.ofFn f | 0, f => by rw [ofFn, List.ofFn_zero, toList, nil] | n + 1, f => by rw [ofFn, List.ofFn_succ, toList_cons, toList_ofFn] @[simp] theorem mk_toList : ∀ (v : Vector α n) (h), (⟨toList v, h⟩ : Vector α n) = v | ⟨_, _⟩, _ => rfl @[simp] theorem length_val (v : Vector α n) : v.val.length = n := v.2 @[simp] theorem pmap_cons {p : α → Prop} (f : (a : α) → p a → β) (a : α) (v : Vector α n) (hp : ∀ x ∈ (cons a v).toList, p x) : (cons a v).pmap f hp = cons (f a (by simp only [Nat.succ_eq_add_one, toList_cons, List.mem_cons, forall_eq_or_imp] at hp exact hp.1)) (v.pmap f (by simp only [Nat.succ_eq_add_one, toList_cons, List.mem_cons, forall_eq_or_imp] at hp exact hp.2)) := rfl /-- Opposite direction of `Vector.pmap_cons` -/ theorem pmap_cons' {p : α → Prop} (f : (a : α) → p a → β) (a : α) (v : Vector α n) (ha : p a) (hp : ∀ x ∈ v.toList, p x) : cons (f a ha) (v.pmap f hp) = (cons a v).pmap f (by simpa [ha]) := rfl @[simp] theorem toList_map {β : Type*} (v : Vector α n) (f : α → β) : (v.map f).toList = v.toList.map f := by cases v; rfl @[simp] theorem head_map {β : Type*} (v : Vector α (n + 1)) (f : α → β) : (v.map f).head = f v.head := by obtain ⟨a, v', h⟩ := Vector.exists_eq_cons v rw [h, map_cons, head_cons, head_cons] @[simp] theorem tail_map {β : Type*} (v : Vector α (n + 1)) (f : α → β) : (v.map f).tail = v.tail.map f := by obtain ⟨a, v', h⟩ := Vector.exists_eq_cons v rw [h, map_cons, tail_cons, tail_cons] @[simp] theorem getElem_map {β : Type*} (v : Vector α n) (f : α → β) {i : ℕ} (hi : i < n) : (v.map f)[i] = f v[i] := by simp only [getElem_def, toList_map, List.getElem_map] @[simp] theorem toList_pmap {p : α → Prop} (f : (a : α) → p a → β) (v : Vector α n) (hp : ∀ x ∈ v.toList, p x) : (v.pmap f hp).toList = v.toList.pmap f hp := by cases v; rfl @[simp] theorem head_pmap {p : α → Prop} (f : (a : α) → p a → β) (v : Vector α (n + 1)) (hp : ∀ x ∈ v.toList, p x) : (v.pmap f hp).head = f v.head (hp _ <| by rw [← cons_head_tail v, toList_cons, head_cons, List.mem_cons]; exact .inl rfl) := by obtain ⟨a, v', h⟩ := Vector.exists_eq_cons v simp_rw [h, pmap_cons, head_cons] @[simp] theorem tail_pmap {p : α → Prop} (f : (a : α) → p a → β) (v : Vector α (n + 1)) (hp : ∀ x ∈ v.toList, p x) : (v.pmap f hp).tail = v.tail.pmap f (fun x hx ↦ hp _ <| by rw [← cons_head_tail v, toList_cons, List.mem_cons]; exact .inr hx) := by obtain ⟨a, v', h⟩ := Vector.exists_eq_cons v simp_rw [h, pmap_cons, tail_cons] @[simp] theorem getElem_pmap {p : α → Prop} (f : (a : α) → p a → β) (v : Vector α n) (hp : ∀ x ∈ v.toList, p x) {i : ℕ} (hi : i < n) : (v.pmap f hp)[i] = f v[i] (hp _ (by simp [getElem_def, List.getElem_mem])) := by simp only [getElem_def, toList_pmap, List.getElem_pmap] theorem get_eq_get_toList (v : Vector α n) (i : Fin n) : v.get i = v.toList.get (Fin.cast v.toList_length.symm i) := rfl @[deprecated (since := "2024-12-20")] alias get_eq_get := get_eq_get_toList @[simp] theorem get_replicate (a : α) (i : Fin n) : (Vector.replicate n a).get i = a := by apply List.getElem_replicate @[simp] theorem get_map {β : Type*} (v : Vector α n) (f : α → β) (i : Fin n) : (v.map f).get i = f (v.get i) := by cases v; simp [Vector.map, get_eq_get_toList] @[simp] theorem map₂_nil (f : α → β → γ) : Vector.map₂ f nil nil = nil := rfl @[simp] theorem map₂_cons (hd₁ : α) (tl₁ : Vector α n) (hd₂ : β) (tl₂ : Vector β n) (f : α → β → γ) : Vector.map₂ f (hd₁ ::ᵥ tl₁) (hd₂ ::ᵥ tl₂) = f hd₁ hd₂ ::ᵥ (Vector.map₂ f tl₁ tl₂) := rfl @[simp] theorem get_ofFn {n} (f : Fin n → α) (i) : get (ofFn f) i = f i := by conv_rhs => erw [← List.get_ofFn f ⟨i, by simp⟩] simp only [get_eq_get_toList] congr <;> simp [Fin.heq_ext_iff] @[simp] theorem ofFn_get (v : Vector α n) : ofFn (get v) = v := by rcases v with ⟨l, rfl⟩ apply toList_injective dsimp simpa only [toList_ofFn] using List.ofFn_get _ /-- The natural equivalence between length-`n` vectors and functions from `Fin n`. -/ def _root_.Equiv.vectorEquivFin (α : Type*) (n : ℕ) : Vector α n ≃ (Fin n → α) := ⟨Vector.get, Vector.ofFn, Vector.ofFn_get, fun f => funext <| Vector.get_ofFn f⟩ theorem get_tail (x : Vector α n) (i) : x.tail.get i = x.get ⟨i.1 + 1, by omega⟩ := by obtain ⟨i, ih⟩ := i; dsimp rcases x with ⟨_ | _, h⟩ <;> try rfl rw [List.length] at h rw [← h] at ih contradiction @[simp] theorem get_tail_succ : ∀ (v : Vector α n.succ) (i : Fin n), get (tail v) i = get v i.succ | ⟨a :: l, e⟩, ⟨i, h⟩ => by simp [get_eq_get_toList]; rfl @[simp] theorem tail_val : ∀ v : Vector α n.succ, v.tail.val = v.val.tail | ⟨_ :: _, _⟩ => rfl /-- The `tail` of a `nil` vector is `nil`. -/ @[simp] theorem tail_nil : (@nil α).tail = nil := rfl /-- The `tail` of a vector made up of one element is `nil`. -/ @[simp] theorem singleton_tail : ∀ (v : Vector α 1), v.tail = Vector.nil | ⟨[_], _⟩ => rfl @[simp] theorem tail_ofFn {n : ℕ} (f : Fin n.succ → α) : tail (ofFn f) = ofFn fun i => f i.succ := (ofFn_get _).symm.trans <| by congr funext i rw [get_tail, get_ofFn] rfl @[simp] theorem toList_empty (v : Vector α 0) : v.toList = [] := List.length_eq_zero_iff.mp v.2 /-- The list that makes up a `Vector` made up of a single element, retrieved via `toList`, is equal to the list of that single element. -/ @[simp] theorem toList_singleton (v : Vector α 1) : v.toList = [v.head] := by rw [← v.cons_head_tail] simp only [toList_cons, toList_nil, head_cons, eq_self_iff_true, and_self_iff, singleton_tail] @[simp] theorem empty_toList_eq_ff (v : Vector α (n + 1)) : v.toList.isEmpty = false := match v with | ⟨_ :: _, _⟩ => rfl theorem not_empty_toList (v : Vector α (n + 1)) : ¬v.toList.isEmpty := by simp only [empty_toList_eq_ff, Bool.coe_sort_false, not_false_iff] /-- Mapping under `id` does not change a vector. -/ @[simp] theorem map_id {n : ℕ} (v : Vector α n) : Vector.map id v = v := Vector.eq _ _ (by simp only [List.map_id, Vector.toList_map]) theorem nodup_iff_injective_get {v : Vector α n} : v.toList.Nodup ↔ Function.Injective v.get := by obtain ⟨l, hl⟩ := v subst hl exact List.nodup_iff_injective_get theorem head?_toList : ∀ v : Vector α n.succ, (toList v).head? = some (head v) | ⟨_ :: _, _⟩ => rfl /-- Reverse a vector. -/ def reverse (v : Vector α n) : Vector α n := ⟨v.toList.reverse, by simp⟩ /-- The `List` of a vector after a `reverse`, retrieved by `toList` is equal to the `List.reverse` after retrieving a vector's `toList`. -/ theorem toList_reverse {v : Vector α n} : v.reverse.toList = v.toList.reverse := rfl @[simp] theorem reverse_reverse {v : Vector α n} : v.reverse.reverse = v := by cases v simp [Vector.reverse] @[simp] theorem get_zero : ∀ v : Vector α n.succ, get v 0 = head v | ⟨_ :: _, _⟩ => rfl @[simp] theorem head_ofFn {n : ℕ} (f : Fin n.succ → α) : head (ofFn f) = f 0 := by rw [← get_zero, get_ofFn] theorem get_cons_zero (a : α) (v : Vector α n) : get (a ::ᵥ v) 0 = a := by simp [get_zero] /-- Accessing the nth element of a vector made up of one element `x : α` is `x` itself. -/ @[simp] theorem get_cons_nil : ∀ {ix : Fin 1} (x : α), get (x ::ᵥ nil) ix = x | ⟨0, _⟩, _ => rfl @[simp] theorem get_cons_succ (a : α) (v : Vector α n) (i : Fin n) : get (a ::ᵥ v) i.succ = get v i := by rw [← get_tail_succ, tail_cons] /-- The last element of a `Vector`, given that the vector is at least one element. -/ def last (v : Vector α (n + 1)) : α := v.get (Fin.last n) /-- The last element of a `Vector`, given that the vector is at least one element. -/ theorem last_def {v : Vector α (n + 1)} : v.last = v.get (Fin.last n) := rfl /-- The `last` element of a vector is the `head` of the `reverse` vector. -/ theorem reverse_get_zero {v : Vector α (n + 1)} : v.reverse.head = v.last := by rw [← get_zero, last_def, get_eq_get_toList, get_eq_get_toList] simp_rw [toList_reverse] rw [List.get_eq_getElem, List.get_eq_getElem, ← Option.some_inj, Fin.cast, Fin.cast, ← List.getElem?_eq_getElem, ← List.getElem?_eq_getElem, List.getElem?_reverse] · congr simp · simp section Scan variable {β : Type*} variable (f : β → α → β) (b : β) variable (v : Vector α n) /-- Construct a `Vector β (n + 1)` from a `Vector α n` by scanning `f : β → α → β` from the "left", that is, from 0 to `Fin.last n`, using `b : β` as the starting value. -/ def scanl : Vector β (n + 1) := ⟨List.scanl f b v.toList, by rw [List.length_scanl, toList_length]⟩ /-- Providing an empty vector to `scanl` gives the starting value `b : β`. -/ @[simp] theorem scanl_nil : scanl f b nil = b ::ᵥ nil := rfl /-- The recursive step of `scanl` splits a vector `x ::ᵥ v : Vector α (n + 1)` into the provided starting value `b : β` and the recursed `scanl` `f b x : β` as the starting value. This lemma is the `cons` version of `scanl_get`. -/ @[simp] theorem scanl_cons (x : α) : scanl f b (x ::ᵥ v) = b ::ᵥ scanl f (f b x) v := by simp only [scanl, toList_cons, List.scanl]; dsimp simp only [cons] /-- The underlying `List` of a `Vector` after a `scanl` is the `List.scanl` of the underlying `List` of the original `Vector`. -/ @[simp] theorem scanl_val : ∀ {v : Vector α n}, (scanl f b v).val = List.scanl f b v.val | _ => rfl /-- The `toList` of a `Vector` after a `scanl` is the `List.scanl` of the `toList` of the original `Vector`. -/ @[simp] theorem toList_scanl : (scanl f b v).toList = List.scanl f b v.toList := rfl /-- The recursive step of `scanl` splits a vector made up of a single element `x ::ᵥ nil : Vector α 1` into a `Vector` of the provided starting value `b : β` and the mapped `f b x : β` as the last value. -/ @[simp] theorem scanl_singleton (v : Vector α 1) : scanl f b v = b ::ᵥ f b v.head ::ᵥ nil := by rw [← cons_head_tail v] simp only [scanl_cons, scanl_nil, head_cons, singleton_tail] /-- The first element of `scanl` of a vector `v : Vector α n`, retrieved via `head`, is the starting value `b : β`. -/ @[simp] theorem scanl_head : (scanl f b v).head = b := by cases n · have : v = nil := by simp only [eq_iff_true_of_subsingleton] simp only [this, scanl_nil, head_cons] · rw [← cons_head_tail v] simp [← get_zero, get_eq_get_toList] /-- For an index `i : Fin n`, the nth element of `scanl` of a vector `v : Vector α n` at `i.succ`, is equal to the application function `f : β → α → β` of the `castSucc i` element of `scanl f b v` and `get v i`. This lemma is the `get` version of `scanl_cons`. -/ @[simp] theorem scanl_get (i : Fin n) : (scanl f b v).get i.succ = f ((scanl f b v).get (Fin.castSucc i)) (v.get i) := by rcases n with - | n · exact i.elim0 induction' n with n hn generalizing b · have i0 : i = 0 := Fin.eq_zero _ simp [scanl_singleton, i0, get_zero]; simp [get_eq_get_toList, List.get] · rw [← cons_head_tail v, scanl_cons, get_cons_succ] refine Fin.cases ?_ ?_ i · simp only [get_zero, scanl_head, Fin.castSucc_zero, head_cons] · intro i' simp only [hn, Fin.castSucc_fin_succ, get_cons_succ] end Scan /-- Monadic analog of `Vector.ofFn`. Given a monadic function on `Fin n`, return a `Vector α n` inside the monad. -/ def mOfFn {m} [Monad m] {α : Type u} : ∀ {n}, (Fin n → m α) → m (Vector α n) | 0, _ => pure nil | _ + 1, f => do let a ← f 0 let v ← mOfFn fun i => f i.succ pure (a ::ᵥ v) theorem mOfFn_pure {m} [Monad m] [LawfulMonad m] {α} : ∀ {n} (f : Fin n → α), (@mOfFn m _ _ _ fun i => pure (f i)) = pure (ofFn f) | 0, _ => rfl | n + 1, f => by rw [mOfFn, @mOfFn_pure m _ _ _ n _, ofFn] simp /-- Apply a monadic function to each component of a vector, returning a vector inside the monad. -/ def mmap {m} [Monad m] {α} {β : Type u} (f : α → m β) : ∀ {n}, Vector α n → m (Vector β n) | 0, _ => pure nil | _ + 1, xs => do let h' ← f xs.head let t' ← mmap f xs.tail pure (h' ::ᵥ t') @[simp] theorem mmap_nil {m} [Monad m] {α β} (f : α → m β) : mmap f nil = pure nil := rfl @[simp] theorem mmap_cons {m} [Monad m] {α β} (f : α → m β) (a) : ∀ {n} (v : Vector α n), mmap f (a ::ᵥ v) = do let h' ← f a let t' ← mmap f v pure (h' ::ᵥ t') | _, ⟨_, rfl⟩ => rfl /-- Define `C v` by induction on `v : Vector α n`. This function has two arguments: `nil` handles the base case on `C nil`, and `cons` defines the inductive step using `∀ x : α, C w → C (x ::ᵥ w)`. It is used as the default induction principle for the `induction` tactic. -/ @[elab_as_elim, induction_eliminator] def inductionOn {C : ∀ {n : ℕ}, Vector α n → Sort*} {n : ℕ} (v : Vector α n) (nil : C nil) (cons : ∀ {n : ℕ} {x : α} {w : Vector α n}, C w → C (x ::ᵥ w)) : C v := by induction' n with n ih · rcases v with ⟨_ | ⟨-, -⟩, - | -⟩ exact nil · rcases v with ⟨_ | ⟨a, v⟩, v_property⟩ cases v_property exact cons (ih ⟨v, (add_left_inj 1).mp v_property⟩) @[simp] theorem inductionOn_nil {C : ∀ {n : ℕ}, Vector α n → Sort*} (nil : C nil) (cons : ∀ {n : ℕ} {x : α} {w : Vector α n}, C w → C (x ::ᵥ w)) : Vector.nil.inductionOn nil cons = nil := rfl @[simp] theorem inductionOn_cons {C : ∀ {n : ℕ}, Vector α n → Sort*} {n : ℕ} (x : α) (v : Vector α n) (nil : C nil) (cons : ∀ {n : ℕ} {x : α} {w : Vector α n}, C w → C (x ::ᵥ w)) : (x ::ᵥ v).inductionOn nil cons = cons (v.inductionOn nil cons : C v) := rfl variable {β γ : Type*} /-- Define `C v w` by induction on a pair of vectors `v : Vector α n` and `w : Vector β n`. -/ @[elab_as_elim] def inductionOn₂ {C : ∀ {n}, Vector α n → Vector β n → Sort*} (v : Vector α n) (w : Vector β n) (nil : C nil nil) (cons : ∀ {n a b} {x : Vector α n} {y}, C x y → C (a ::ᵥ x) (b ::ᵥ y)) : C v w := by induction' n with n ih · rcases v with ⟨_ | ⟨-, -⟩, - | -⟩ rcases w with ⟨_ | ⟨-, -⟩, - | -⟩ exact nil · rcases v with ⟨_ | ⟨a, v⟩, v_property⟩ cases v_property rcases w with ⟨_ | ⟨b, w⟩, w_property⟩ cases w_property apply @cons n _ _ ⟨v, (add_left_inj 1).mp v_property⟩ ⟨w, (add_left_inj 1).mp w_property⟩ apply ih /-- Define `C u v w` by induction on a triplet of vectors `u : Vector α n`, `v : Vector β n`, and `w : Vector γ b`. -/ @[elab_as_elim] def inductionOn₃ {C : ∀ {n}, Vector α n → Vector β n → Vector γ n → Sort*} (u : Vector α n) (v : Vector β n) (w : Vector γ n) (nil : C nil nil nil) (cons : ∀ {n a b c} {x : Vector α n} {y z}, C x y z → C (a ::ᵥ x) (b ::ᵥ y) (c ::ᵥ z)) : C u v w := by induction' n with n ih · rcases u with ⟨_ | ⟨-, -⟩, - | -⟩ rcases v with ⟨_ | ⟨-, -⟩, - | -⟩ rcases w with ⟨_ | ⟨-, -⟩, - | -⟩ exact nil · rcases u with ⟨_ | ⟨a, u⟩, u_property⟩ cases u_property rcases v with ⟨_ | ⟨b, v⟩, v_property⟩ cases v_property rcases w with ⟨_ | ⟨c, w⟩, w_property⟩ cases w_property apply @cons n _ _ _ ⟨u, (add_left_inj 1).mp u_property⟩ ⟨v, (add_left_inj 1).mp v_property⟩ ⟨w, (add_left_inj 1).mp w_property⟩ apply ih /-- Define `motive v` by case-analysis on `v : Vector α n`. -/ def casesOn {motive : ∀ {n}, Vector α n → Sort*} (v : Vector α m) (nil : motive nil) (cons : ∀ {n}, (hd : α) → (tl : Vector α n) → motive (Vector.cons hd tl)) : motive v := inductionOn (C := motive) v nil @fun _ hd tl _ => cons hd tl /-- Define `motive v₁ v₂` by case-analysis on `v₁ : Vector α n` and `v₂ : Vector β n`. -/ def casesOn₂ {motive : ∀ {n}, Vector α n → Vector β n → Sort*} (v₁ : Vector α m) (v₂ : Vector β m) (nil : motive nil nil) (cons : ∀ {n}, (x : α) → (y : β) → (xs : Vector α n) → (ys : Vector β n) → motive (x ::ᵥ xs) (y ::ᵥ ys)) : motive v₁ v₂ := inductionOn₂ (C := motive) v₁ v₂ nil @fun _ x y xs ys _ => cons x y xs ys /-- Define `motive v₁ v₂ v₃` by case-analysis on `v₁ : Vector α n`, `v₂ : Vector β n`, and `v₃ : Vector γ n`. -/ def casesOn₃ {motive : ∀ {n}, Vector α n → Vector β n → Vector γ n → Sort*} (v₁ : Vector α m) (v₂ : Vector β m) (v₃ : Vector γ m) (nil : motive nil nil nil) (cons : ∀ {n}, (x : α) → (y : β) → (z : γ) → (xs : Vector α n) → (ys : Vector β n) → (zs : Vector γ n) → motive (x ::ᵥ xs) (y ::ᵥ ys) (z ::ᵥ zs)) : motive v₁ v₂ v₃ := inductionOn₃ (C := motive) v₁ v₂ v₃ nil @fun _ x y z xs ys zs _ => cons x y z xs ys zs /-- Cast a vector to an array. -/ def toArray : Vector α n → Array α | ⟨xs, _⟩ => cast (by rfl) xs.toArray section InsertIdx variable {a : α} /-- `v.insertIdx a i` inserts `a` into the vector `v` at position `i` (and shifting later components to the right). -/ def insertIdx (a : α) (i : Fin (n + 1)) (v : Vector α n) : Vector α (n + 1) := ⟨v.1.insertIdx i a, by rw [List.length_insertIdx, v.2] split <;> omega⟩ theorem insertIdx_val {i : Fin (n + 1)} {v : Vector α n} : (v.insertIdx a i).val = v.val.insertIdx i.1 a := rfl @[simp] theorem eraseIdx_val {i : Fin n} : ∀ {v : Vector α n}, (eraseIdx i v).val = v.val.eraseIdx i | _ => rfl theorem eraseIdx_insertIdx {v : Vector α n} {i : Fin (n + 1)} : eraseIdx i (insertIdx a i v) = v := Subtype.eq (List.eraseIdx_insertIdx ..) /-- Erasing an element after inserting an element, at different indices. -/ theorem eraseIdx_insertIdx' {v : Vector α (n + 1)} : ∀ {i : Fin (n + 1)} {j : Fin (n + 2)}, eraseIdx (j.succAbove i) (insertIdx a j v) = insertIdx a (i.predAbove j) (eraseIdx i v) | ⟨i, hi⟩, ⟨j, hj⟩ => by dsimp [insertIdx, eraseIdx, Fin.succAbove, Fin.predAbove] rw [Subtype.mk_eq_mk] simp only [Fin.lt_iff_val_lt_val] split_ifs with hij · rcases Nat.exists_eq_succ_of_ne_zero (Nat.pos_iff_ne_zero.1 (lt_of_le_of_lt (Nat.zero_le _) hij)) with ⟨j, rfl⟩ rw [← List.insertIdx_eraseIdx_of_ge] · simp; rfl · simpa · simpa [Nat.lt_succ_iff] using hij · dsimp rw [← List.insertIdx_eraseIdx_of_le] · rfl · simpa · simpa [not_lt] using hij theorem insertIdx_comm (a b : α) (i j : Fin (n + 1)) (h : i ≤ j) : ∀ v : Vector α n, (v.insertIdx a i).insertIdx b j.succ = (v.insertIdx b j).insertIdx a (Fin.castSucc i) | ⟨l, hl⟩ => by refine Subtype.eq ?_ simp only [insertIdx_val, Fin.val_succ, Fin.castSucc, Fin.coe_castAdd] apply List.insertIdx_comm · assumption · rw [hl] exact Nat.le_of_succ_le_succ j.2 end InsertIdx section Set /-- `set v n a` replaces the `n`th element of `v` with `a`. -/ def set (v : Vector α n) (i : Fin n) (a : α) : Vector α n := ⟨v.1.set i.1 a, by simp⟩ @[simp] theorem toList_set (v : Vector α n) (i : Fin n) (a : α) : (v.set i a).toList = v.toList.set i a := rfl @[simp] theorem get_set_same (v : Vector α n) (i : Fin n) (a : α) : (v.set i a).get i = a := by cases v; cases i; simp [Vector.set, get_eq_get_toList] theorem get_set_of_ne {v : Vector α n} {i j : Fin n} (h : i ≠ j) (a : α) : (v.set i a).get j = v.get j := by cases v; cases i; cases j simp only [get_eq_get_toList, toList_set, toList_mk, Fin.cast_mk, List.get_eq_getElem] rw [List.getElem_set_of_ne] · simpa using h theorem get_set_eq_if {v : Vector α n} {i j : Fin n} (a : α) : (v.set i a).get j = if i = j then a else v.get j := by split_ifs <;> (try simp [*]); rwa [get_set_of_ne] @[to_additive] theorem prod_set [Monoid α] (v : Vector α n) (i : Fin n) (a : α) : (v.set i a).toList.prod = (v.take i).toList.prod * a * (v.drop (i + 1)).toList.prod := by refine (List.prod_set v.toList i a).trans ?_ simp_all /-- Variant of `List.Vector.prod_set` that multiplies by the inverse of the replaced element -/ @[to_additive "Variant of `List.Vector.sum_set` that subtracts the inverse of the replaced element"] theorem prod_set' [CommGroup α] (v : Vector α n) (i : Fin n) (a : α) : (v.set i a).toList.prod = v.toList.prod * (v.get i)⁻¹ * a := by refine (List.prod_set' v.toList i a).trans ?_ simp [get_eq_get_toList, mul_assoc] end Set end Vector namespace Vector section Traverse variable {F G : Type u → Type u} variable [Applicative F] [Applicative G] open Applicative Functor open List (cons) open Nat private def traverseAux {α β : Type u} (f : α → F β) : ∀ x : List α, F (Vector β x.length)
| [] => pure Vector.nil | x :: xs => Vector.cons <$> f x <*> traverseAux f xs
Mathlib/Data/Vector/Basic.lean
633
634
/- Copyright (c) 2021 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Alex J. Best, Johan Commelin, Eric Rodriguez, Ruben Van de Velde -/ import Mathlib.Algebra.Algebra.ZMod import Mathlib.FieldTheory.Finite.Basic import Mathlib.FieldTheory.Galois.Basic import Mathlib.RingTheory.Norm.Basic /-! # Galois fields If `p` is a prime number, and `n` a natural number, then `GaloisField p n` is defined as the splitting field of `X^(p^n) - X` over `ZMod p`. It is a finite field with `p ^ n` elements. ## Main definition * `GaloisField p n` is a field with `p ^ n` elements ## Main Results - `GaloisField.algEquivGaloisField`: Any finite field is isomorphic to some Galois field - `FiniteField.algEquivOfCardEq`: Uniqueness of finite fields : algebra isomorphism - `FiniteField.ringEquivOfCardEq`: Uniqueness of finite fields : ring isomorphism -/ noncomputable section open Polynomial Finset open scoped Polynomial instance FiniteField.isSplittingField_sub (K F : Type*) [Field K] [Fintype K] [Field F] [Algebra F K] : IsSplittingField F K (X ^ Fintype.card K - X) where splits' := by have h : (X ^ Fintype.card K - X : K[X]).natDegree = Fintype.card K := FiniteField.X_pow_card_sub_X_natDegree_eq K Fintype.one_lt_card rw [← splits_id_iff_splits, splits_iff_card_roots, Polynomial.map_sub, Polynomial.map_pow, map_X, h, FiniteField.roots_X_pow_card_sub_X K, ← Finset.card_def, Finset.card_univ] adjoin_rootSet' := by classical trans Algebra.adjoin F ((roots (X ^ Fintype.card K - X : K[X])).toFinset : Set K) · simp only [rootSet, aroots, Polynomial.map_pow, map_X, Polynomial.map_sub] · rw [FiniteField.roots_X_pow_card_sub_X, val_toFinset, coe_univ, Algebra.adjoin_univ] theorem galois_poly_separable {K : Type*} [CommRing K] (p q : ℕ) [CharP K p] (h : p ∣ q) : Separable (X ^ q - X : K[X]) := by use 1, X ^ q - X - 1 rw [← CharP.cast_eq_zero_iff K[X] p] at h rw [derivative_sub, derivative_X_pow, derivative_X, C_eq_natCast, h] ring variable (p : ℕ) [Fact p.Prime] (n : ℕ) /-- A finite field with `p ^ n` elements. Every field with the same cardinality is (non-canonically) isomorphic to this field. -/ def GaloisField := SplittingField (X ^ p ^ n - X : (ZMod p)[X]) -- The `Field` instance should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 instance : Field (GaloisField p n) := inferInstanceAs (Field (SplittingField _)) instance : Inhabited (@GaloisField 2 (Fact.mk Nat.prime_two) 1) := ⟨37⟩ namespace GaloisField variable (p : ℕ) [h_prime : Fact p.Prime] (n : ℕ) instance : Algebra (ZMod p) (GaloisField p n) := SplittingField.algebra _ instance : IsSplittingField (ZMod p) (GaloisField p n) (X ^ p ^ n - X) := Polynomial.IsSplittingField.splittingField _ instance : CharP (GaloisField p n) p := (Algebra.charP_iff (ZMod p) (GaloisField p n) p).mp (by infer_instance) instance : FiniteDimensional (ZMod p) (GaloisField p n) := by dsimp only [GaloisField]; infer_instance instance : Finite (GaloisField p n) := Module.finite_of_finite (ZMod p) theorem finrank {n} (h : n ≠ 0) : Module.finrank (ZMod p) (GaloisField p n) = n := by haveI : Fintype (GaloisField p n) := Fintype.ofFinite (GaloisField p n) set g_poly := (X ^ p ^ n - X : (ZMod p)[X]) have hp : 1 < p := h_prime.out.one_lt have aux : g_poly ≠ 0 := FiniteField.X_pow_card_pow_sub_X_ne_zero _ h hp have key : Fintype.card (g_poly.rootSet (GaloisField p n)) = g_poly.natDegree := card_rootSet_eq_natDegree (galois_poly_separable p _ (dvd_pow (dvd_refl p) h)) (SplittingField.splits (g_poly : (ZMod p)[X])) have nat_degree_eq : g_poly.natDegree = p ^ n := FiniteField.X_pow_card_pow_sub_X_natDegree_eq _ h hp rw [nat_degree_eq] at key suffices g_poly.rootSet (GaloisField p n) = Set.univ by simp_rw [this, ← Fintype.ofEquiv_card (Equiv.Set.univ _)] at key -- Porting note: prevents `card_eq_pow_finrank` from using a wrong instance for `Fintype` rw [@Module.card_eq_pow_finrank (ZMod p) _ _ _ _ _ (_), ZMod.card] at key exact Nat.pow_right_injective (Nat.Prime.one_lt' p).out key rw [Set.eq_univ_iff_forall] suffices ∀ (x) (hx : x ∈ (⊤ : Subalgebra (ZMod p) (GaloisField p n))), x ∈ (X ^ p ^ n - X : (ZMod p)[X]).rootSet (GaloisField p n) by simpa rw [← SplittingField.adjoin_rootSet] simp_rw [Algebra.mem_adjoin_iff] intro x hx -- We discharge the `p = 0` separately, to avoid typeclass issues on `ZMod p`. cases p; cases hp simp only [g_poly] at aux refine Subring.closure_induction ?_ ?_ ?_ ?_ ?_ ?_ hx <;> simp_rw [mem_rootSet_of_ne aux] · rintro x (⟨r, rfl⟩ | hx) · simp only [g_poly, map_sub, map_pow, aeval_X] rw [← map_pow, ZMod.pow_card_pow, sub_self] · dsimp only [GaloisField] at hx rwa [mem_rootSet_of_ne aux] at hx · rw [← coeff_zero_eq_aeval_zero'] simp only [g_poly, coeff_X_pow, coeff_X_zero, sub_zero, _root_.map_eq_zero, ite_eq_right_iff, one_ne_zero, coeff_sub] intro hn exact Nat.not_lt_zero 1 (pow_eq_zero hn.symm ▸ hp) · simp [g_poly] · simp only [g_poly, aeval_X_pow, aeval_X, map_sub, add_pow_char_pow, sub_eq_zero] intro x y _ _ hx hy rw [hx, hy] · intro x _ hx simp only [g_poly, sub_eq_zero, aeval_X_pow, aeval_X, map_sub, sub_neg_eq_add] at * rw [neg_pow, hx, neg_one_pow_char_pow] simp · simp only [g_poly, aeval_X_pow, aeval_X, map_sub, mul_pow, sub_eq_zero] intro x y _ _ hx hy rw [hx, hy] theorem card (h : n ≠ 0) : Nat.card (GaloisField p n) = p ^ n := by let b := IsNoetherian.finsetBasis (ZMod p) (GaloisField p n) haveI : Fintype (GaloisField p n) := Fintype.ofFinite (GaloisField p n) rw [Nat.card_eq_fintype_card, Module.card_fintype b, ← Module.finrank_eq_card_basis b, ZMod.card, finrank p h] theorem splits_zmod_X_pow_sub_X : Splits (RingHom.id (ZMod p)) (X ^ p - X) := by have hp : 1 < p := h_prime.out.one_lt have h1 : roots (X ^ p - X : (ZMod p)[X]) = Finset.univ.val := by convert FiniteField.roots_X_pow_card_sub_X (ZMod p) exact (ZMod.card p).symm
have h2 := FiniteField.X_pow_card_sub_X_natDegree_eq (ZMod p) hp -- We discharge the `p = 0` separately, to avoid typeclass issues on `ZMod p`. cases p; cases hp rw [splits_iff_card_roots, h1, ← Finset.card_def, Finset.card_univ, h2, ZMod.card] /-- A Galois field with exponent 1 is equivalent to `ZMod` -/ def equivZmodP : GaloisField p 1 ≃ₐ[ZMod p] ZMod p := let h : (X ^ p ^ 1 : (ZMod p)[X]) = X ^ Fintype.card (ZMod p) := by rw [pow_one, ZMod.card p] let inst : IsSplittingField (ZMod p) (ZMod p) (X ^ p ^ 1 - X) := by rw [h]; infer_instance
Mathlib/FieldTheory/Finite/GaloisField.lean
151
159
/- Copyright (c) 2018 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Mario Carneiro, Reid Barton, Andrew Yang -/ import Mathlib.Topology.Category.TopCat.Opens import Mathlib.CategoryTheory.Adjunction.Unique import Mathlib.CategoryTheory.Functor.KanExtension.Adjunction import Mathlib.Topology.Sheaves.Init import Mathlib.Data.Set.Subsingleton /-! # Presheaves on a topological space We define `TopCat.Presheaf C X` simply as `(TopologicalSpace.Opens X)ᵒᵖ ⥤ C`, and inherit the category structure with natural transformations as morphisms. We define * Given `{X Y : TopCat.{w}}` and `f : X ⟶ Y`, we define `TopCat.Presheaf.pushforward C f : X.Presheaf C ⥤ Y.Presheaf C`, with notation `f _* ℱ` for `ℱ : X.Presheaf C`. and for `ℱ : X.Presheaf C` provide the natural isomorphisms * `TopCat.Presheaf.Pushforward.id : (𝟙 X) _* ℱ ≅ ℱ` * `TopCat.Presheaf.Pushforward.comp : (f ≫ g) _* ℱ ≅ g _* (f _* ℱ)` along with their `@[simp]` lemmas. We also define the functors `pullback C f : Y.Presheaf C ⥤ X.Presheaf c`, and provide their adjunction at `TopCat.Presheaf.pushforwardPullbackAdjunction`. -/ universe w v u open CategoryTheory TopologicalSpace Opposite variable (C : Type u) [Category.{v} C] namespace TopCat /-- The category of `C`-valued presheaves on a (bundled) topological space `X`. -/ def Presheaf (X : TopCat.{w}) : Type max u v w := (Opens X)ᵒᵖ ⥤ C instance (X : TopCat.{w}) : Category (Presheaf.{w, v, u} C X) := inferInstanceAs (Category ((Opens X)ᵒᵖ ⥤ C : Type max u v w)) variable {C} namespace Presheaf @[simp] theorem comp_app {X : TopCat} {U : (Opens X)ᵒᵖ} {P Q R : Presheaf C X} (f : P ⟶ Q) (g : Q ⟶ R) : (f ≫ g).app U = f.app U ≫ g.app U := rfl @[ext] lemma ext {X : TopCat} {P Q : Presheaf C X} {f g : P ⟶ Q} (w : ∀ U : Opens X, f.app (op U) = g.app (op U)) : f = g := by apply NatTrans.ext ext U induction U with | _ U => ?_ apply w /-- attribute `sheaf_restrict` to mark lemmas related to restricting sheaves -/ macro "sheaf_restrict" : attr => `(attr|aesop safe 50 apply (rule_sets := [$(Lean.mkIdent `Restrict):ident])) attribute [sheaf_restrict] bot_le le_top le_refl inf_le_left inf_le_right le_sup_left le_sup_right /-- `restrict_tac` solves relations among subsets (copied from `aesop cat`) -/ macro (name := restrict_tac) "restrict_tac" c:Aesop.tactic_clause* : tactic => `(tactic| first | assumption | aesop $c* (config := { terminal := true assumptionTransparency := .reducible enableSimp := false }) (rule_sets := [-default, -builtin, $(Lean.mkIdent `Restrict):ident])) /-- `restrict_tac?` passes along `Try this` from `aesop` -/ macro (name := restrict_tac?) "restrict_tac?" c:Aesop.tactic_clause* : tactic => `(tactic| aesop? $c* (config := { terminal := true assumptionTransparency := .reducible enableSimp := false maxRuleApplications := 300 }) (rule_sets := [-default, -builtin, $(Lean.mkIdent `Restrict):ident])) attribute[aesop 10% (rule_sets := [Restrict])] le_trans attribute[aesop safe destruct (rule_sets := [Restrict])] Eq.trans_le attribute[aesop safe -50 (rule_sets := [Restrict])] Aesop.BuiltinRules.assumption example {X} [CompleteLattice X] (v : Nat → X) (w x y z : X) (e : v 0 = v 1) (_ : v 1 = v 2) (h₀ : v 1 ≤ x) (_ : x ≤ z ⊓ w) (h₂ : x ≤ y ⊓ z) : v 0 ≤ y := by restrict_tac variable {X : TopCat} {C : Type*} [Category C] {FC : C → C → Type*} {CC : C → Type*} variable [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] [ConcreteCategory C FC] /-- The restriction of a section along an inclusion of open sets. For `x : F.obj (op V)`, we provide the notation `x |_ₕ i` (`h` stands for `hom`) for `i : U ⟶ V`, and the notation `x |_ₗ U ⟪i⟫` (`l` stands for `le`) for `i : U ≤ V`. -/ def restrict {F : X.Presheaf C} {V : Opens X} (x : ToType (F.obj (op V))) {U : Opens X} (h : U ⟶ V) : ToType (F.obj (op U)) := F.map h.op x /-- restriction of a section along an inclusion -/ scoped[AlgebraicGeometry] infixl:80 " |_ₕ " => TopCat.Presheaf.restrict /-- restriction of a section along a subset relation -/ scoped[AlgebraicGeometry] notation:80 x " |_ₗ " U " ⟪" e "⟫ " => @TopCat.Presheaf.restrict _ _ _ _ _ _ _ _ _ x U (@homOfLE (Opens _) _ U _ e) open AlgebraicGeometry /-- The restriction of a section along an inclusion of open sets. For `x : F.obj (op V)`, we provide the notation `x |_ U`, where the proof `U ≤ V` is inferred by the tactic `Top.presheaf.restrict_tac'` -/ abbrev restrictOpen {F : X.Presheaf C} {V : Opens X} (x : ToType (F.obj (op V))) (U : Opens X) (e : U ≤ V := by restrict_tac) : ToType (F.obj (op U)) := x |_ₗ U ⟪e⟫ /-- restriction of a section to open subset -/ scoped[AlgebraicGeometry] infixl:80 " |_ " => TopCat.Presheaf.restrictOpen theorem restrict_restrict {F : X.Presheaf C} {U V W : Opens X} (e₁ : U ≤ V) (e₂ : V ≤ W) (x : ToType (F.obj (op W))) : x |_ V |_ U = x |_ U := by delta restrictOpen restrict rw [← ConcreteCategory.comp_apply, ← Functor.map_comp] rfl theorem map_restrict {F G : X.Presheaf C} (e : F ⟶ G) {U V : Opens X} (h : U ≤ V) (x : ToType (F.obj (op V))) : e.app _ (x |_ U) = e.app _ x |_ U := by delta restrictOpen restrict rw [← ConcreteCategory.comp_apply, NatTrans.naturality, ConcreteCategory.comp_apply] open CategoryTheory.Limits variable (C) /-- The pushforward functor. -/ @[simps!] def pushforward {X Y : TopCat.{w}} (f : X ⟶ Y) : X.Presheaf C ⥤ Y.Presheaf C := (whiskeringLeft _ _ _).obj (Opens.map f).op /-- push forward of a presheaf -/ scoped[AlgebraicGeometry] notation f:80 " _* " P:81 => Prefunctor.obj (Functor.toPrefunctor (TopCat.Presheaf.pushforward _ f)) P @[simp] theorem pushforward_map_app' {X Y : TopCat.{w}} (f : X ⟶ Y) {ℱ 𝒢 : X.Presheaf C} (α : ℱ ⟶ 𝒢) {U : (Opens Y)ᵒᵖ} : ((pushforward C f).map α).app U = α.app (op <| (Opens.map f).obj U.unop) := rfl lemma id_pushforward (X : TopCat.{w}) : pushforward C (𝟙 X) = 𝟭 (X.Presheaf C) := rfl variable {C} namespace Pushforward /-- The natural isomorphism between the pushforward of a presheaf along the identity continuous map and the original presheaf. -/ def id {X : TopCat.{w}} (ℱ : X.Presheaf C) : 𝟙 X _* ℱ ≅ ℱ := Iso.refl _ @[simp] theorem id_hom_app {X : TopCat.{w}} (ℱ : X.Presheaf C) (U) : (id ℱ).hom.app U = 𝟙 _ := rfl @[simp] theorem id_inv_app {X : TopCat.{w}} (ℱ : X.Presheaf C) (U) : (id ℱ).inv.app U = 𝟙 _ := rfl theorem id_eq {X : TopCat.{w}} (ℱ : X.Presheaf C) : 𝟙 X _* ℱ = ℱ := rfl /-- The natural isomorphism between the pushforward of a presheaf along the composition of two continuous maps and the corresponding pushforward of a pushforward. -/ def comp {X Y Z : TopCat.{w}} (f : X ⟶ Y) (g : Y ⟶ Z) (ℱ : X.Presheaf C) : (f ≫ g) _* ℱ ≅ g _* (f _* ℱ) := Iso.refl _ theorem comp_eq {X Y Z : TopCat.{w}} (f : X ⟶ Y) (g : Y ⟶ Z) (ℱ : X.Presheaf C) : (f ≫ g) _* ℱ = g _* (f _* ℱ) := rfl @[simp] theorem comp_hom_app {X Y Z : TopCat.{w}} (f : X ⟶ Y) (g : Y ⟶ Z) (ℱ : X.Presheaf C) (U) : (comp f g ℱ).hom.app U = 𝟙 _ := rfl @[simp] theorem comp_inv_app {X Y Z : TopCat.{w}} (f : X ⟶ Y) (g : Y ⟶ Z) (ℱ : X.Presheaf C) (U) : (comp f g ℱ).inv.app U = 𝟙 _ := rfl end Pushforward /-- An equality of continuous maps induces a natural isomorphism between the pushforwards of a presheaf along those maps. -/ def pushforwardEq {X Y : TopCat.{w}} {f g : X ⟶ Y} (h : f = g) (ℱ : X.Presheaf C) : f _* ℱ ≅ g _* ℱ := isoWhiskerRight (NatIso.op (Opens.mapIso f g h).symm) ℱ theorem pushforward_eq' {X Y : TopCat.{w}} {f g : X ⟶ Y} (h : f = g) (ℱ : X.Presheaf C) : f _* ℱ = g _* ℱ := by rw [h] @[simp] theorem pushforwardEq_hom_app {X Y : TopCat.{w}} {f g : X ⟶ Y} (h : f = g) (ℱ : X.Presheaf C) (U) : (pushforwardEq h ℱ).hom.app U = ℱ.map (eqToHom (by aesop_cat)) := by
simp [pushforwardEq] variable (C)
Mathlib/Topology/Sheaves/Presheaf.lean
214
217
/- 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.FundThmCalculus deprecated_module (since := "2025-04-06")
Mathlib/MeasureTheory/Integral/FundThmCalculus.lean
1,600
1,604
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker -/ import Mathlib.Algebra.Polynomial.Reverse import Mathlib.Algebra.Regular.SMul /-! # Theory of monic polynomials We give several tools for proving that polynomials are monic, e.g. `Monic.mul`, `Monic.map`, `Monic.pow`. -/ noncomputable section open Finset open Polynomial namespace Polynomial universe u v y variable {R : Type u} {S : Type v} {a b : R} {m n : ℕ} {ι : Type y} section Semiring variable [Semiring R] {p q r : R[X]} theorem monic_zero_iff_subsingleton : Monic (0 : R[X]) ↔ Subsingleton R := subsingleton_iff_zero_eq_one theorem not_monic_zero_iff : ¬Monic (0 : R[X]) ↔ (0 : R) ≠ 1 := (monic_zero_iff_subsingleton.trans subsingleton_iff_zero_eq_one.symm).not theorem monic_zero_iff_subsingleton' : Monic (0 : R[X]) ↔ (∀ f g : R[X], f = g) ∧ ∀ a b : R, a = b := Polynomial.monic_zero_iff_subsingleton.trans ⟨by intro simp [eq_iff_true_of_subsingleton], fun h => subsingleton_iff.mpr h.2⟩ theorem Monic.as_sum (hp : p.Monic) : p = X ^ p.natDegree + ∑ i ∈ range p.natDegree, C (p.coeff i) * X ^ i := by conv_lhs => rw [p.as_sum_range_C_mul_X_pow, sum_range_succ_comm] suffices C (p.coeff p.natDegree) = 1 by rw [this, one_mul] exact congr_arg C hp theorem ne_zero_of_ne_zero_of_monic (hp : p ≠ 0) (hq : Monic q) : q ≠ 0 := by rintro rfl rw [Monic.def, leadingCoeff_zero] at hq rw [← mul_one p, ← C_1, ← hq, C_0, mul_zero] at hp exact hp rfl theorem Monic.map [Semiring S] (f : R →+* S) (hp : Monic p) : Monic (p.map f) := by unfold Monic nontriviality have : f p.leadingCoeff ≠ 0 := by rw [show _ = _ from hp, f.map_one] exact one_ne_zero rw [Polynomial.leadingCoeff, coeff_map] suffices p.coeff (p.map f).natDegree = 1 by simp [this] rwa [natDegree_eq_of_degree_eq (degree_map_eq_of_leadingCoeff_ne_zero f this)] theorem monic_C_mul_of_mul_leadingCoeff_eq_one {b : R} (hp : b * p.leadingCoeff = 1) : Monic (C b * p) := by unfold Monic nontriviality rw [leadingCoeff_mul' _] <;> simp [leadingCoeff_C b, hp] theorem monic_mul_C_of_leadingCoeff_mul_eq_one {b : R} (hp : p.leadingCoeff * b = 1) : Monic (p * C b) := by unfold Monic nontriviality rw [leadingCoeff_mul' _] <;> simp [leadingCoeff_C b, hp] theorem monic_of_degree_le (n : ℕ) (H1 : degree p ≤ n) (H2 : coeff p n = 1) : Monic p := Decidable.byCases (fun H : degree p < n => eq_of_zero_eq_one (H2 ▸ (coeff_eq_zero_of_degree_lt H).symm) _ _) fun H : ¬degree p < n => by rwa [Monic, Polynomial.leadingCoeff, natDegree, (lt_or_eq_of_le H1).resolve_left H] theorem monic_X_pow_add {n : ℕ} (H : degree p < n) : Monic (X ^ n + p) := monic_of_degree_le n (le_trans (degree_add_le _ _) (max_le (degree_X_pow_le _) (le_of_lt H))) (by rw [coeff_add, coeff_X_pow, if_pos rfl, coeff_eq_zero_of_degree_lt H, add_zero]) variable (a) in theorem monic_X_pow_add_C {n : ℕ} (h : n ≠ 0) : (X ^ n + C a).Monic := monic_X_pow_add <| (lt_of_le_of_lt degree_C_le (by simp only [Nat.cast_pos, Nat.pos_iff_ne_zero, ne_eq, h, not_false_eq_true])) theorem monic_X_add_C (x : R) : Monic (X + C x) := pow_one (X : R[X]) ▸ monic_X_pow_add_C x one_ne_zero theorem Monic.mul (hp : Monic p) (hq : Monic q) : Monic (p * q) := letI := Classical.decEq R if h0 : (0 : R) = 1 then haveI := subsingleton_of_zero_eq_one h0 Subsingleton.elim _ _ else by have : p.leadingCoeff * q.leadingCoeff ≠ 0 := by simp [Monic.def.1 hp, Monic.def.1 hq, Ne.symm h0] rw [Monic.def, leadingCoeff_mul' this, Monic.def.1 hp, Monic.def.1 hq, one_mul] theorem Monic.pow (hp : Monic p) : ∀ n : ℕ, Monic (p ^ n) | 0 => monic_one | n + 1 => by rw [pow_succ] exact (Monic.pow hp n).mul hp theorem Monic.add_of_left (hp : Monic p) (hpq : degree q < degree p) : Monic (p + q) := by rwa [Monic, add_comm, leadingCoeff_add_of_degree_lt hpq] theorem Monic.add_of_right (hq : Monic q) (hpq : degree p < degree q) : Monic (p + q) := by rwa [Monic, leadingCoeff_add_of_degree_lt hpq] theorem Monic.of_mul_monic_left (hp : p.Monic) (hpq : (p * q).Monic) : q.Monic := by contrapose! hpq rw [Monic.def] at hpq ⊢ rwa [leadingCoeff_monic_mul hp] theorem Monic.of_mul_monic_right (hq : q.Monic) (hpq : (p * q).Monic) : p.Monic := by contrapose! hpq
rw [Monic.def] at hpq ⊢ rwa [leadingCoeff_mul_monic hq] namespace Monic
Mathlib/Algebra/Polynomial/Monic.lean
128
132
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Algebra.ModEq import Mathlib.Algebra.Order.Archimedean.Basic import Mathlib.Algebra.Ring.Periodic import Mathlib.Data.Int.SuccPred import Mathlib.Order.Circular /-! # Reducing to an interval modulo its length This file defines operations that reduce a number (in an `Archimedean` `LinearOrderedAddCommGroup`) to a number in a given interval, modulo the length of that interval. ## Main definitions * `toIcoDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ico a (a + p)`. * `toIcoMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ico a (a + p)`. * `toIocDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ioc a (a + p)`. * `toIocMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ioc a (a + p)`. -/ assert_not_exists TwoSidedIdeal noncomputable section section LinearOrderedAddCommGroup variable {α : Type*} [AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α] [hα : Archimedean α] {p : α} (hp : 0 < p) {a b c : α} {n : ℤ} section include hp /-- The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ico a (a + p)`. -/ def toIcoDiv (a b : α) : ℤ := (existsUnique_sub_zsmul_mem_Ico hp b a).choose theorem sub_toIcoDiv_zsmul_mem_Ico (a b : α) : b - toIcoDiv hp a b • p ∈ Set.Ico a (a + p) := (existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.1 theorem toIcoDiv_eq_of_sub_zsmul_mem_Ico (h : b - n • p ∈ Set.Ico a (a + p)) : toIcoDiv hp a b = n := ((existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.2 _ h).symm /-- The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ioc a (a + p)`. -/ def toIocDiv (a b : α) : ℤ := (existsUnique_sub_zsmul_mem_Ioc hp b a).choose theorem sub_toIocDiv_zsmul_mem_Ioc (a b : α) : b - toIocDiv hp a b • p ∈ Set.Ioc a (a + p) := (existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.1 theorem toIocDiv_eq_of_sub_zsmul_mem_Ioc (h : b - n • p ∈ Set.Ioc a (a + p)) : toIocDiv hp a b = n := ((existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.2 _ h).symm /-- Reduce `b` to the interval `Ico a (a + p)`. -/ def toIcoMod (a b : α) : α := b - toIcoDiv hp a b • p /-- Reduce `b` to the interval `Ioc a (a + p)`. -/ def toIocMod (a b : α) : α := b - toIocDiv hp a b • p theorem toIcoMod_mem_Ico (a b : α) : toIcoMod hp a b ∈ Set.Ico a (a + p) := sub_toIcoDiv_zsmul_mem_Ico hp a b theorem toIcoMod_mem_Ico' (b : α) : toIcoMod hp 0 b ∈ Set.Ico 0 p := by convert toIcoMod_mem_Ico hp 0 b exact (zero_add p).symm theorem toIocMod_mem_Ioc (a b : α) : toIocMod hp a b ∈ Set.Ioc a (a + p) := sub_toIocDiv_zsmul_mem_Ioc hp a b theorem left_le_toIcoMod (a b : α) : a ≤ toIcoMod hp a b := (Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).1 theorem left_lt_toIocMod (a b : α) : a < toIocMod hp a b := (Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).1 theorem toIcoMod_lt_right (a b : α) : toIcoMod hp a b < a + p := (Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).2 theorem toIocMod_le_right (a b : α) : toIocMod hp a b ≤ a + p := (Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).2 @[simp] theorem self_sub_toIcoDiv_zsmul (a b : α) : b - toIcoDiv hp a b • p = toIcoMod hp a b := rfl @[simp] theorem self_sub_toIocDiv_zsmul (a b : α) : b - toIocDiv hp a b • p = toIocMod hp a b := rfl @[simp] theorem toIcoDiv_zsmul_sub_self (a b : α) : toIcoDiv hp a b • p - b = -toIcoMod hp a b := by rw [toIcoMod, neg_sub] @[simp] theorem toIocDiv_zsmul_sub_self (a b : α) : toIocDiv hp a b • p - b = -toIocMod hp a b := by rw [toIocMod, neg_sub] @[simp] theorem toIcoMod_sub_self (a b : α) : toIcoMod hp a b - b = -toIcoDiv hp a b • p := by rw [toIcoMod, sub_sub_cancel_left, neg_smul] @[simp] theorem toIocMod_sub_self (a b : α) : toIocMod hp a b - b = -toIocDiv hp a b • p := by rw [toIocMod, sub_sub_cancel_left, neg_smul] @[simp] theorem self_sub_toIcoMod (a b : α) : b - toIcoMod hp a b = toIcoDiv hp a b • p := by rw [toIcoMod, sub_sub_cancel] @[simp] theorem self_sub_toIocMod (a b : α) : b - toIocMod hp a b = toIocDiv hp a b • p := by rw [toIocMod, sub_sub_cancel] @[simp] theorem toIcoMod_add_toIcoDiv_zsmul (a b : α) : toIcoMod hp a b + toIcoDiv hp a b • p = b := by rw [toIcoMod, sub_add_cancel] @[simp] theorem toIocMod_add_toIocDiv_zsmul (a b : α) : toIocMod hp a b + toIocDiv hp a b • p = b := by rw [toIocMod, sub_add_cancel] @[simp] theorem toIcoDiv_zsmul_sub_toIcoMod (a b : α) : toIcoDiv hp a b • p + toIcoMod hp a b = b := by rw [add_comm, toIcoMod_add_toIcoDiv_zsmul] @[simp] theorem toIocDiv_zsmul_sub_toIocMod (a b : α) : toIocDiv hp a b • p + toIocMod hp a b = b := by rw [add_comm, toIocMod_add_toIocDiv_zsmul] theorem toIcoMod_eq_iff : toIcoMod hp a b = c ↔ c ∈ Set.Ico a (a + p) ∧ ∃ z : ℤ, b = c + z • p := by refine ⟨fun h => ⟨h ▸ toIcoMod_mem_Ico hp a b, toIcoDiv hp a b, h ▸ (toIcoMod_add_toIcoDiv_zsmul _ _ _).symm⟩, ?_⟩ simp_rw [← @sub_eq_iff_eq_add] rintro ⟨hc, n, rfl⟩ rw [← toIcoDiv_eq_of_sub_zsmul_mem_Ico hp hc, toIcoMod] theorem toIocMod_eq_iff : toIocMod hp a b = c ↔ c ∈ Set.Ioc a (a + p) ∧ ∃ z : ℤ, b = c + z • p := by refine ⟨fun h => ⟨h ▸ toIocMod_mem_Ioc hp a b, toIocDiv hp a b, h ▸ (toIocMod_add_toIocDiv_zsmul hp _ _).symm⟩, ?_⟩ simp_rw [← @sub_eq_iff_eq_add] rintro ⟨hc, n, rfl⟩ rw [← toIocDiv_eq_of_sub_zsmul_mem_Ioc hp hc, toIocMod] @[simp] theorem toIcoDiv_apply_left (a : α) : toIcoDiv hp a a = 0 := toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp] @[simp] theorem toIocDiv_apply_left (a : α) : toIocDiv hp a a = -1 := toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp] @[simp] theorem toIcoMod_apply_left (a : α) : toIcoMod hp a a = a := by rw [toIcoMod_eq_iff hp, Set.left_mem_Ico] exact ⟨lt_add_of_pos_right _ hp, 0, by simp⟩ @[simp] theorem toIocMod_apply_left (a : α) : toIocMod hp a a = a + p := by rw [toIocMod_eq_iff hp, Set.right_mem_Ioc] exact ⟨lt_add_of_pos_right _ hp, -1, by simp⟩ theorem toIcoDiv_apply_right (a : α) : toIcoDiv hp a (a + p) = 1 := toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp] theorem toIocDiv_apply_right (a : α) : toIocDiv hp a (a + p) = 0 := toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp] theorem toIcoMod_apply_right (a : α) : toIcoMod hp a (a + p) = a := by rw [toIcoMod_eq_iff hp, Set.left_mem_Ico] exact ⟨lt_add_of_pos_right _ hp, 1, by simp⟩ theorem toIocMod_apply_right (a : α) : toIocMod hp a (a + p) = a + p := by rw [toIocMod_eq_iff hp, Set.right_mem_Ioc] exact ⟨lt_add_of_pos_right _ hp, 0, by simp⟩ @[simp] theorem toIcoDiv_add_zsmul (a b : α) (m : ℤ) : toIcoDiv hp a (b + m • p) = toIcoDiv hp a b + m := toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIcoDiv_zsmul_mem_Ico hp a b @[simp] theorem toIcoDiv_add_zsmul' (a b : α) (m : ℤ) : toIcoDiv hp (a + m • p) b = toIcoDiv hp a b - m := by refine toIcoDiv_eq_of_sub_zsmul_mem_Ico _ ?_ rw [sub_smul, ← sub_add, add_right_comm] simpa using sub_toIcoDiv_zsmul_mem_Ico hp a b @[simp] theorem toIocDiv_add_zsmul (a b : α) (m : ℤ) : toIocDiv hp a (b + m • p) = toIocDiv hp a b + m := toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIocDiv_zsmul_mem_Ioc hp a b @[simp] theorem toIocDiv_add_zsmul' (a b : α) (m : ℤ) : toIocDiv hp (a + m • p) b = toIocDiv hp a b - m := by refine toIocDiv_eq_of_sub_zsmul_mem_Ioc _ ?_ rw [sub_smul, ← sub_add, add_right_comm] simpa using sub_toIocDiv_zsmul_mem_Ioc hp a b @[simp] theorem toIcoDiv_zsmul_add (a b : α) (m : ℤ) : toIcoDiv hp a (m • p + b) = m + toIcoDiv hp a b := by rw [add_comm, toIcoDiv_add_zsmul, add_comm] /-! Note we omit `toIcoDiv_zsmul_add'` as `-m + toIcoDiv hp a b` is not very convenient. -/ @[simp] theorem toIocDiv_zsmul_add (a b : α) (m : ℤ) : toIocDiv hp a (m • p + b) = m + toIocDiv hp a b := by rw [add_comm, toIocDiv_add_zsmul, add_comm] /-! Note we omit `toIocDiv_zsmul_add'` as `-m + toIocDiv hp a b` is not very convenient. -/ @[simp] theorem toIcoDiv_sub_zsmul (a b : α) (m : ℤ) : toIcoDiv hp a (b - m • p) = toIcoDiv hp a b - m := by rw [sub_eq_add_neg, ← neg_smul, toIcoDiv_add_zsmul, sub_eq_add_neg] @[simp] theorem toIcoDiv_sub_zsmul' (a b : α) (m : ℤ) : toIcoDiv hp (a - m • p) b = toIcoDiv hp a b + m := by rw [sub_eq_add_neg, ← neg_smul, toIcoDiv_add_zsmul', sub_neg_eq_add] @[simp] theorem toIocDiv_sub_zsmul (a b : α) (m : ℤ) : toIocDiv hp a (b - m • p) = toIocDiv hp a b - m := by rw [sub_eq_add_neg, ← neg_smul, toIocDiv_add_zsmul, sub_eq_add_neg] @[simp] theorem toIocDiv_sub_zsmul' (a b : α) (m : ℤ) : toIocDiv hp (a - m • p) b = toIocDiv hp a b + m := by rw [sub_eq_add_neg, ← neg_smul, toIocDiv_add_zsmul', sub_neg_eq_add] @[simp] theorem toIcoDiv_add_right (a b : α) : toIcoDiv hp a (b + p) = toIcoDiv hp a b + 1 := by simpa only [one_zsmul] using toIcoDiv_add_zsmul hp a b 1 @[simp] theorem toIcoDiv_add_right' (a b : α) : toIcoDiv hp (a + p) b = toIcoDiv hp a b - 1 := by simpa only [one_zsmul] using toIcoDiv_add_zsmul' hp a b 1 @[simp] theorem toIocDiv_add_right (a b : α) : toIocDiv hp a (b + p) = toIocDiv hp a b + 1 := by simpa only [one_zsmul] using toIocDiv_add_zsmul hp a b 1 @[simp] theorem toIocDiv_add_right' (a b : α) : toIocDiv hp (a + p) b = toIocDiv hp a b - 1 := by simpa only [one_zsmul] using toIocDiv_add_zsmul' hp a b 1 @[simp] theorem toIcoDiv_add_left (a b : α) : toIcoDiv hp a (p + b) = toIcoDiv hp a b + 1 := by rw [add_comm, toIcoDiv_add_right] @[simp] theorem toIcoDiv_add_left' (a b : α) : toIcoDiv hp (p + a) b = toIcoDiv hp a b - 1 := by rw [add_comm, toIcoDiv_add_right'] @[simp] theorem toIocDiv_add_left (a b : α) : toIocDiv hp a (p + b) = toIocDiv hp a b + 1 := by rw [add_comm, toIocDiv_add_right] @[simp] theorem toIocDiv_add_left' (a b : α) : toIocDiv hp (p + a) b = toIocDiv hp a b - 1 := by rw [add_comm, toIocDiv_add_right'] @[simp] theorem toIcoDiv_sub (a b : α) : toIcoDiv hp a (b - p) = toIcoDiv hp a b - 1 := by simpa only [one_zsmul] using toIcoDiv_sub_zsmul hp a b 1 @[simp] theorem toIcoDiv_sub' (a b : α) : toIcoDiv hp (a - p) b = toIcoDiv hp a b + 1 := by simpa only [one_zsmul] using toIcoDiv_sub_zsmul' hp a b 1 @[simp] theorem toIocDiv_sub (a b : α) : toIocDiv hp a (b - p) = toIocDiv hp a b - 1 := by simpa only [one_zsmul] using toIocDiv_sub_zsmul hp a b 1 @[simp] theorem toIocDiv_sub' (a b : α) : toIocDiv hp (a - p) b = toIocDiv hp a b + 1 := by simpa only [one_zsmul] using toIocDiv_sub_zsmul' hp a b 1 theorem toIcoDiv_sub_eq_toIcoDiv_add (a b c : α) : toIcoDiv hp a (b - c) = toIcoDiv hp (a + c) b := by apply toIcoDiv_eq_of_sub_zsmul_mem_Ico rw [← sub_right_comm, Set.sub_mem_Ico_iff_left, add_right_comm] exact sub_toIcoDiv_zsmul_mem_Ico hp (a + c) b theorem toIocDiv_sub_eq_toIocDiv_add (a b c : α) : toIocDiv hp a (b - c) = toIocDiv hp (a + c) b := by apply toIocDiv_eq_of_sub_zsmul_mem_Ioc rw [← sub_right_comm, Set.sub_mem_Ioc_iff_left, add_right_comm] exact sub_toIocDiv_zsmul_mem_Ioc hp (a + c) b theorem toIcoDiv_sub_eq_toIcoDiv_add' (a b c : α) : toIcoDiv hp (a - c) b = toIcoDiv hp a (b + c) := by rw [← sub_neg_eq_add, toIcoDiv_sub_eq_toIcoDiv_add, sub_eq_add_neg] theorem toIocDiv_sub_eq_toIocDiv_add' (a b c : α) : toIocDiv hp (a - c) b = toIocDiv hp a (b + c) := by rw [← sub_neg_eq_add, toIocDiv_sub_eq_toIocDiv_add, sub_eq_add_neg] theorem toIcoDiv_neg (a b : α) : toIcoDiv hp a (-b) = -(toIocDiv hp (-a) b + 1) := by suffices toIcoDiv hp a (-b) = -toIocDiv hp (-(a + p)) b by rwa [neg_add, ← sub_eq_add_neg, toIocDiv_sub_eq_toIocDiv_add', toIocDiv_add_right] at this rw [← neg_eq_iff_eq_neg, eq_comm] apply toIocDiv_eq_of_sub_zsmul_mem_Ioc obtain ⟨hc, ho⟩ := sub_toIcoDiv_zsmul_mem_Ico hp a (-b) rw [← neg_lt_neg_iff, neg_sub' (-b), neg_neg, ← neg_smul] at ho rw [← neg_le_neg_iff, neg_sub' (-b), neg_neg, ← neg_smul] at hc refine ⟨ho, hc.trans_eq ?_⟩ rw [neg_add, neg_add_cancel_right] theorem toIcoDiv_neg' (a b : α) : toIcoDiv hp (-a) b = -(toIocDiv hp a (-b) + 1) := by simpa only [neg_neg] using toIcoDiv_neg hp (-a) (-b) theorem toIocDiv_neg (a b : α) : toIocDiv hp a (-b) = -(toIcoDiv hp (-a) b + 1) := by rw [← neg_neg b, toIcoDiv_neg, neg_neg, neg_neg, neg_add', neg_neg, add_sub_cancel_right] theorem toIocDiv_neg' (a b : α) : toIocDiv hp (-a) b = -(toIcoDiv hp a (-b) + 1) := by simpa only [neg_neg] using toIocDiv_neg hp (-a) (-b) @[simp] theorem toIcoMod_add_zsmul (a b : α) (m : ℤ) : toIcoMod hp a (b + m • p) = toIcoMod hp a b := by rw [toIcoMod, toIcoDiv_add_zsmul, toIcoMod, add_smul] abel @[simp] theorem toIcoMod_add_zsmul' (a b : α) (m : ℤ) : toIcoMod hp (a + m • p) b = toIcoMod hp a b + m • p := by simp only [toIcoMod, toIcoDiv_add_zsmul', sub_smul, sub_add] @[simp] theorem toIocMod_add_zsmul (a b : α) (m : ℤ) : toIocMod hp a (b + m • p) = toIocMod hp a b := by rw [toIocMod, toIocDiv_add_zsmul, toIocMod, add_smul] abel @[simp] theorem toIocMod_add_zsmul' (a b : α) (m : ℤ) : toIocMod hp (a + m • p) b = toIocMod hp a b + m • p := by simp only [toIocMod, toIocDiv_add_zsmul', sub_smul, sub_add] @[simp] theorem toIcoMod_zsmul_add (a b : α) (m : ℤ) : toIcoMod hp a (m • p + b) = toIcoMod hp a b := by rw [add_comm, toIcoMod_add_zsmul] @[simp] theorem toIcoMod_zsmul_add' (a b : α) (m : ℤ) : toIcoMod hp (m • p + a) b = m • p + toIcoMod hp a b := by rw [add_comm, toIcoMod_add_zsmul', add_comm] @[simp] theorem toIocMod_zsmul_add (a b : α) (m : ℤ) : toIocMod hp a (m • p + b) = toIocMod hp a b := by rw [add_comm, toIocMod_add_zsmul] @[simp] theorem toIocMod_zsmul_add' (a b : α) (m : ℤ) : toIocMod hp (m • p + a) b = m • p + toIocMod hp a b := by rw [add_comm, toIocMod_add_zsmul', add_comm] @[simp] theorem toIcoMod_sub_zsmul (a b : α) (m : ℤ) : toIcoMod hp a (b - m • p) = toIcoMod hp a b := by rw [sub_eq_add_neg, ← neg_smul, toIcoMod_add_zsmul] @[simp] theorem toIcoMod_sub_zsmul' (a b : α) (m : ℤ) : toIcoMod hp (a - m • p) b = toIcoMod hp a b - m • p := by simp_rw [sub_eq_add_neg, ← neg_smul, toIcoMod_add_zsmul'] @[simp] theorem toIocMod_sub_zsmul (a b : α) (m : ℤ) : toIocMod hp a (b - m • p) = toIocMod hp a b := by rw [sub_eq_add_neg, ← neg_smul, toIocMod_add_zsmul] @[simp] theorem toIocMod_sub_zsmul' (a b : α) (m : ℤ) : toIocMod hp (a - m • p) b = toIocMod hp a b - m • p := by simp_rw [sub_eq_add_neg, ← neg_smul, toIocMod_add_zsmul'] @[simp] theorem toIcoMod_add_right (a b : α) : toIcoMod hp a (b + p) = toIcoMod hp a b := by simpa only [one_zsmul] using toIcoMod_add_zsmul hp a b 1 @[simp] theorem toIcoMod_add_right' (a b : α) : toIcoMod hp (a + p) b = toIcoMod hp a b + p := by simpa only [one_zsmul] using toIcoMod_add_zsmul' hp a b 1 @[simp] theorem toIocMod_add_right (a b : α) : toIocMod hp a (b + p) = toIocMod hp a b := by simpa only [one_zsmul] using toIocMod_add_zsmul hp a b 1 @[simp] theorem toIocMod_add_right' (a b : α) : toIocMod hp (a + p) b = toIocMod hp a b + p := by simpa only [one_zsmul] using toIocMod_add_zsmul' hp a b 1 @[simp] theorem toIcoMod_add_left (a b : α) : toIcoMod hp a (p + b) = toIcoMod hp a b := by rw [add_comm, toIcoMod_add_right] @[simp] theorem toIcoMod_add_left' (a b : α) : toIcoMod hp (p + a) b = p + toIcoMod hp a b := by rw [add_comm, toIcoMod_add_right', add_comm] @[simp] theorem toIocMod_add_left (a b : α) : toIocMod hp a (p + b) = toIocMod hp a b := by rw [add_comm, toIocMod_add_right] @[simp] theorem toIocMod_add_left' (a b : α) : toIocMod hp (p + a) b = p + toIocMod hp a b := by rw [add_comm, toIocMod_add_right', add_comm] @[simp] theorem toIcoMod_sub (a b : α) : toIcoMod hp a (b - p) = toIcoMod hp a b := by simpa only [one_zsmul] using toIcoMod_sub_zsmul hp a b 1 @[simp] theorem toIcoMod_sub' (a b : α) : toIcoMod hp (a - p) b = toIcoMod hp a b - p := by simpa only [one_zsmul] using toIcoMod_sub_zsmul' hp a b 1 @[simp] theorem toIocMod_sub (a b : α) : toIocMod hp a (b - p) = toIocMod hp a b := by simpa only [one_zsmul] using toIocMod_sub_zsmul hp a b 1 @[simp] theorem toIocMod_sub' (a b : α) : toIocMod hp (a - p) b = toIocMod hp a b - p := by simpa only [one_zsmul] using toIocMod_sub_zsmul' hp a b 1 theorem toIcoMod_sub_eq_sub (a b c : α) : toIcoMod hp a (b - c) = toIcoMod hp (a + c) b - c := by simp_rw [toIcoMod, toIcoDiv_sub_eq_toIcoDiv_add, sub_right_comm] theorem toIocMod_sub_eq_sub (a b c : α) : toIocMod hp a (b - c) = toIocMod hp (a + c) b - c := by simp_rw [toIocMod, toIocDiv_sub_eq_toIocDiv_add, sub_right_comm] theorem toIcoMod_add_right_eq_add (a b c : α) : toIcoMod hp a (b + c) = toIcoMod hp (a - c) b + c := by simp_rw [toIcoMod, toIcoDiv_sub_eq_toIcoDiv_add', sub_add_eq_add_sub] theorem toIocMod_add_right_eq_add (a b c : α) : toIocMod hp a (b + c) = toIocMod hp (a - c) b + c := by simp_rw [toIocMod, toIocDiv_sub_eq_toIocDiv_add', sub_add_eq_add_sub] theorem toIcoMod_neg (a b : α) : toIcoMod hp a (-b) = p - toIocMod hp (-a) b := by simp_rw [toIcoMod, toIocMod, toIcoDiv_neg, neg_smul, add_smul] abel theorem toIcoMod_neg' (a b : α) : toIcoMod hp (-a) b = p - toIocMod hp a (-b) := by simpa only [neg_neg] using toIcoMod_neg hp (-a) (-b) theorem toIocMod_neg (a b : α) : toIocMod hp a (-b) = p - toIcoMod hp (-a) b := by simp_rw [toIocMod, toIcoMod, toIocDiv_neg, neg_smul, add_smul] abel theorem toIocMod_neg' (a b : α) : toIocMod hp (-a) b = p - toIcoMod hp a (-b) := by simpa only [neg_neg] using toIocMod_neg hp (-a) (-b) theorem toIcoMod_eq_toIcoMod : toIcoMod hp a b = toIcoMod hp a c ↔ ∃ n : ℤ, c - b = n • p := by refine ⟨fun h => ⟨toIcoDiv hp a c - toIcoDiv hp a b, ?_⟩, fun h => ?_⟩ · conv_lhs => rw [← toIcoMod_add_toIcoDiv_zsmul hp a b, ← toIcoMod_add_toIcoDiv_zsmul hp a c] rw [h, sub_smul] abel · rcases h with ⟨z, hz⟩ rw [sub_eq_iff_eq_add] at hz rw [hz, toIcoMod_zsmul_add] theorem toIocMod_eq_toIocMod : toIocMod hp a b = toIocMod hp a c ↔ ∃ n : ℤ, c - b = n • p := by refine ⟨fun h => ⟨toIocDiv hp a c - toIocDiv hp a b, ?_⟩, fun h => ?_⟩ · conv_lhs => rw [← toIocMod_add_toIocDiv_zsmul hp a b, ← toIocMod_add_toIocDiv_zsmul hp a c] rw [h, sub_smul] abel · rcases h with ⟨z, hz⟩ rw [sub_eq_iff_eq_add] at hz rw [hz, toIocMod_zsmul_add] /-! ### Links between the `Ico` and `Ioc` variants applied to the same element -/ section IcoIoc namespace AddCommGroup theorem modEq_iff_toIcoMod_eq_left : a ≡ b [PMOD p] ↔ toIcoMod hp a b = a := modEq_iff_eq_add_zsmul.trans ⟨by rintro ⟨n, rfl⟩ rw [toIcoMod_add_zsmul, toIcoMod_apply_left], fun h => ⟨toIcoDiv hp a b, eq_add_of_sub_eq h⟩⟩ theorem modEq_iff_toIocMod_eq_right : a ≡ b [PMOD p] ↔ toIocMod hp a b = a + p := by refine modEq_iff_eq_add_zsmul.trans ⟨?_, fun h => ⟨toIocDiv hp a b + 1, ?_⟩⟩ · rintro ⟨z, rfl⟩ rw [toIocMod_add_zsmul, toIocMod_apply_left] · rwa [add_one_zsmul, add_left_comm, ← sub_eq_iff_eq_add'] alias ⟨ModEq.toIcoMod_eq_left, _⟩ := modEq_iff_toIcoMod_eq_left alias ⟨ModEq.toIcoMod_eq_right, _⟩ := modEq_iff_toIocMod_eq_right variable (a b) open List in theorem tfae_modEq : TFAE [a ≡ b [PMOD p], ∀ z : ℤ, b - z • p ∉ Set.Ioo a (a + p), toIcoMod hp a b ≠ toIocMod hp a b, toIcoMod hp a b + p = toIocMod hp a b] := by rw [modEq_iff_toIcoMod_eq_left hp] tfae_have 3 → 2 := by rw [← not_exists, not_imp_not] exact fun ⟨i, hi⟩ => ((toIcoMod_eq_iff hp).2 ⟨Set.Ioo_subset_Ico_self hi, i, (sub_add_cancel b _).symm⟩).trans ((toIocMod_eq_iff hp).2 ⟨Set.Ioo_subset_Ioc_self hi, i, (sub_add_cancel b _).symm⟩).symm tfae_have 4 → 3 | h => by rw [← h, Ne, eq_comm, add_eq_left] exact hp.ne' tfae_have 1 → 4 | h => by rw [h, eq_comm, toIocMod_eq_iff, Set.right_mem_Ioc] refine ⟨lt_add_of_pos_right a hp, toIcoDiv hp a b - 1, ?_⟩ rw [sub_one_zsmul, add_add_add_comm, add_neg_cancel, add_zero] conv_lhs => rw [← toIcoMod_add_toIcoDiv_zsmul hp a b, h] tfae_have 2 → 1 := by rw [← not_exists, not_imp_comm] have h' := toIcoMod_mem_Ico hp a b exact fun h => ⟨_, h'.1.lt_of_ne' h, h'.2⟩ tfae_finish variable {a b} theorem modEq_iff_not_forall_mem_Ioo_mod : a ≡ b [PMOD p] ↔ ∀ z : ℤ, b - z • p ∉ Set.Ioo a (a + p) := (tfae_modEq hp a b).out 0 1 theorem modEq_iff_toIcoMod_ne_toIocMod : a ≡ b [PMOD p] ↔ toIcoMod hp a b ≠ toIocMod hp a b := (tfae_modEq hp a b).out 0 2 theorem modEq_iff_toIcoMod_add_period_eq_toIocMod : a ≡ b [PMOD p] ↔ toIcoMod hp a b + p = toIocMod hp a b := (tfae_modEq hp a b).out 0 3 theorem not_modEq_iff_toIcoMod_eq_toIocMod : ¬a ≡ b [PMOD p] ↔ toIcoMod hp a b = toIocMod hp a b := (modEq_iff_toIcoMod_ne_toIocMod _).not_left theorem not_modEq_iff_toIcoDiv_eq_toIocDiv : ¬a ≡ b [PMOD p] ↔ toIcoDiv hp a b = toIocDiv hp a b := by rw [not_modEq_iff_toIcoMod_eq_toIocMod hp, toIcoMod, toIocMod, sub_right_inj, zsmul_left_inj hp] theorem modEq_iff_toIcoDiv_eq_toIocDiv_add_one : a ≡ b [PMOD p] ↔ toIcoDiv hp a b = toIocDiv hp a b + 1 := by rw [modEq_iff_toIcoMod_add_period_eq_toIocMod hp, toIcoMod, toIocMod, ← eq_sub_iff_add_eq, sub_sub, sub_right_inj, ← add_one_zsmul, zsmul_left_inj hp] end AddCommGroup open AddCommGroup /-- If `a` and `b` fall within the same cycle WRT `c`, then they are congruent modulo `p`. -/ @[simp] theorem toIcoMod_inj {c : α} : toIcoMod hp c a = toIcoMod hp c b ↔ a ≡ b [PMOD p] := by simp_rw [toIcoMod_eq_toIcoMod, modEq_iff_eq_add_zsmul, sub_eq_iff_eq_add'] alias ⟨_, AddCommGroup.ModEq.toIcoMod_eq_toIcoMod⟩ := toIcoMod_inj theorem Ico_eq_locus_Ioc_eq_iUnion_Ioo : { b | toIcoMod hp a b = toIocMod hp a b } = ⋃ z : ℤ, Set.Ioo (a + z • p) (a + p + z • p) := by ext1
simp_rw [Set.mem_setOf, Set.mem_iUnion, ← Set.sub_mem_Ioo_iff_left, ← not_modEq_iff_toIcoMod_eq_toIocMod, modEq_iff_not_forall_mem_Ioo_mod hp, not_forall, Classical.not_not] theorem toIocDiv_wcovBy_toIcoDiv (a b : α) : toIocDiv hp a b ⩿ toIcoDiv hp a b := by suffices toIocDiv hp a b = toIcoDiv hp a b ∨ toIocDiv hp a b + 1 = toIcoDiv hp a b by rwa [wcovBy_iff_eq_or_covBy, ← Order.succ_eq_iff_covBy] rw [eq_comm, ← not_modEq_iff_toIcoDiv_eq_toIocDiv, eq_comm, ←
Mathlib/Algebra/Order/ToIntervalMod.lean
580
587
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Set.Lattice /-! # Semiquotients A data type for semiquotients, which are classically equivalent to nonempty sets, but are useful for programming; the idea is that a semiquotient set `S` represents some (particular but unknown) element of `S`. This can be used to model nondeterministic functions, which return something in a range of values (represented by the predicate `S`) but are not completely determined. -/ /-- A member of `Semiquot α` is classically a nonempty `Set α`, and in the VM is represented by an element of `α`; the relation between these is that the VM element is required to be a member of the set `s`. The specific element of `s` that the VM computes is hidden by a quotient construction, allowing for the representation of nondeterministic functions. -/ structure Semiquot (α : Type*) where mk' :: /-- Set containing some element of `α` -/ s : Set α /-- Assertion of non-emptiness via `Trunc` -/ val : Trunc s namespace Semiquot variable {α : Type*} {β : Type*} instance : Membership α (Semiquot α) := ⟨fun q a => a ∈ q.s⟩ /-- Construct a `Semiquot α` from `h : a ∈ s` where `s : Set α`. -/ def mk {a : α} {s : Set α} (h : a ∈ s) : Semiquot α := ⟨s, Trunc.mk ⟨a, h⟩⟩ theorem ext_s {q₁ q₂ : Semiquot α} : q₁ = q₂ ↔ q₁.s = q₂.s := by refine ⟨congr_arg _, fun h => ?_⟩ obtain ⟨_, v₁⟩ := q₁; obtain ⟨_, v₂⟩ := q₂; congr exact Subsingleton.helim (congrArg Trunc (congrArg Set.Elem h)) v₁ v₂ theorem ext {q₁ q₂ : Semiquot α} : q₁ = q₂ ↔ ∀ a, a ∈ q₁ ↔ a ∈ q₂ := ext_s.trans Set.ext_iff theorem exists_mem (q : Semiquot α) : ∃ a, a ∈ q := let ⟨⟨a, h⟩, _⟩ := q.2.exists_rep ⟨a, h⟩ theorem eq_mk_of_mem {q : Semiquot α} {a : α} (h : a ∈ q) : q = @mk _ a q.1 h := ext_s.2 rfl theorem nonempty (q : Semiquot α) : q.s.Nonempty := q.exists_mem /-- `pure a` is `a` reinterpreted as an unspecified element of `{a}`. -/ protected def pure (a : α) : Semiquot α := mk (Set.mem_singleton a) @[simp] theorem mem_pure' {a b : α} : a ∈ Semiquot.pure b ↔ a = b := Set.mem_singleton_iff /-- Replace `s` in a `Semiquot` with a superset. -/ def blur' (q : Semiquot α) {s : Set α} (h : q.s ⊆ s) : Semiquot α := ⟨s, Trunc.lift (fun a : q.s => Trunc.mk ⟨a.1, h a.2⟩) (fun _ _ => Trunc.eq _ _) q.2⟩ /-- Replace `s` in a `q : Semiquot α` with a union `s ∪ q.s` -/ def blur (s : Set α) (q : Semiquot α) : Semiquot α := blur' q (s.subset_union_right (t := q.s)) theorem blur_eq_blur' (q : Semiquot α) (s : Set α) (h : q.s ⊆ s) : blur s q = blur' q h := by unfold blur; congr; exact Set.union_eq_self_of_subset_right h @[simp] theorem mem_blur' (q : Semiquot α) {s : Set α} (h : q.s ⊆ s) {a : α} : a ∈ blur' q h ↔ a ∈ s := Iff.rfl /-- Convert a `Trunc α` to a `Semiquot α`. -/ def ofTrunc (q : Trunc α) : Semiquot α := ⟨Set.univ, q.map fun a => ⟨a, trivial⟩⟩ /-- Convert a `Semiquot α` to a `Trunc α`. -/ def toTrunc (q : Semiquot α) : Trunc α := q.2.map Subtype.val /-- If `f` is a constant on `q.s`, then `q.liftOn f` is the value of `f` at any point of `q`. -/ def liftOn (q : Semiquot α) (f : α → β) (h : ∀ a ∈ q, ∀ b ∈ q, f a = f b) : β := Trunc.liftOn q.2 (fun x => f x.1) fun x y => h _ x.2 _ y.2 theorem liftOn_ofMem (q : Semiquot α) (f : α → β) (h : ∀ a ∈ q, ∀ b ∈ q, f a = f b) (a : α) (aq : a ∈ q) : liftOn q f h = f a := by revert h; rw [eq_mk_of_mem aq]; intro; rfl /-- Apply a function to the unknown value stored in a `Semiquot α`. -/ def map (f : α → β) (q : Semiquot α) : Semiquot β := ⟨f '' q.1, q.2.map fun x => ⟨f x.1, Set.mem_image_of_mem _ x.2⟩⟩ @[simp] theorem mem_map (f : α → β) (q : Semiquot α) (b : β) : b ∈ map f q ↔ ∃ a, a ∈ q ∧ f a = b := Set.mem_image _ _ _ /-- Apply a function returning a `Semiquot` to a `Semiquot`. -/ def bind (q : Semiquot α) (f : α → Semiquot β) : Semiquot β := ⟨⋃ a ∈ q.1, (f a).1, q.2.bind fun a => (f a.1).2.map fun b => ⟨b.1, Set.mem_biUnion a.2 b.2⟩⟩ @[simp] theorem mem_bind (q : Semiquot α) (f : α → Semiquot β) (b : β) : b ∈ bind q f ↔ ∃ a ∈ q, b ∈ f a := by simp_rw [← exists_prop]; exact Set.mem_iUnion₂ instance : Monad Semiquot where pure := @Semiquot.pure map := @Semiquot.map bind := @Semiquot.bind @[simp] theorem map_def {β} : ((· <$> ·) : (α → β) → Semiquot α → Semiquot β) = map := rfl @[simp] theorem bind_def {β} : ((· >>= ·) : Semiquot α → (α → Semiquot β) → Semiquot β) = bind := rfl @[simp] theorem mem_pure {a b : α} : a ∈ (pure b : Semiquot α) ↔ a = b := Set.mem_singleton_iff theorem mem_pure_self (a : α) : a ∈ (pure a : Semiquot α) := Set.mem_singleton a @[simp] theorem pure_inj {a b : α} : (pure a : Semiquot α) = pure b ↔ a = b := ext_s.trans Set.singleton_eq_singleton_iff instance : LawfulMonad Semiquot := LawfulMonad.mk' (pure_bind := fun {α β} x f => ext.2 <| by simp) (bind_assoc := fun {α β} γ s f g => ext.2 <| by simp only [bind_def, mem_bind] exact fun c => ⟨fun ⟨b, ⟨a, as, bf⟩, cg⟩ => ⟨a, as, b, bf, cg⟩, fun ⟨a, as, b, bf, cg⟩ => ⟨b, ⟨a, as, bf⟩, cg⟩⟩) (id_map := fun {α} q => ext.2 <| by simp) (bind_pure_comp := fun {α β} f s => ext.2 <| by simp [eq_comm]) instance : LE (Semiquot α) := ⟨fun s t => s.s ⊆ t.s⟩ instance partialOrder : PartialOrder (Semiquot α) where le s t := ∀ ⦃x⦄, x ∈ s → x ∈ t le_refl _ := Set.Subset.refl _ le_trans _ _ _ := Set.Subset.trans le_antisymm _ _ h₁ h₂ := ext_s.2 (Set.Subset.antisymm h₁ h₂) instance : SemilatticeSup (Semiquot α) := { Semiquot.partialOrder with sup := fun s => blur s.s le_sup_left := fun _ _ => Set.subset_union_left le_sup_right := fun _ _ => Set.subset_union_right sup_le := fun _ _ _ => Set.union_subset } @[simp] theorem pure_le {a : α} {s : Semiquot α} : pure a ≤ s ↔ a ∈ s := Set.singleton_subset_iff /-- Assert that a `Semiquot` contains only one possible value. -/ def IsPure (q : Semiquot α) : Prop := ∀ a ∈ q, ∀ b ∈ q, a = b /-- Extract the value from an `IsPure` semiquotient. -/ def get (q : Semiquot α) (h : q.IsPure) : α := liftOn q id h theorem get_mem {q : Semiquot α} (p) : get q p ∈ q := by let ⟨a, h⟩ := exists_mem q unfold get; rw [liftOn_ofMem q _ _ a h]; exact h theorem eq_pure {q : Semiquot α} (p) : q = pure (get q p) := ext.2 fun a => by simpa using ⟨fun h => p _ h _ (get_mem _), fun e => e.symm ▸ get_mem _⟩ @[simp] theorem pure_isPure (a : α) : IsPure (pure a) | b, ab, c, ac => by rw [mem_pure] at ab ac rwa [← ac] at ab theorem isPure_iff {s : Semiquot α} : IsPure s ↔ ∃ a, s = pure a := ⟨fun h => ⟨_, eq_pure h⟩, fun ⟨_, e⟩ => e.symm ▸ pure_isPure _⟩ theorem IsPure.mono {s t : Semiquot α} (st : s ≤ t) (h : IsPure t) : IsPure s | _, as, _, bs => h _ (st as) _ (st bs) theorem IsPure.min {s t : Semiquot α} (h : IsPure t) : s ≤ t ↔ s = t := ⟨fun st => le_antisymm st <| by rw [eq_pure h, eq_pure (h.mono st)]; simpa using h _ (get_mem _) _ (st <| get_mem _), le_of_eq⟩ theorem isPure_of_subsingleton [Subsingleton α] (q : Semiquot α) : IsPure q | _, _, _, _ => Subsingleton.elim _ _ /-- `univ : Semiquot α` represents an unspecified element of `univ : Set α`. -/ def univ [Inhabited α] : Semiquot α := mk <| Set.mem_univ default instance [Inhabited α] : Inhabited (Semiquot α) := ⟨univ⟩ @[simp] theorem mem_univ [Inhabited α] : ∀ a, a ∈ @univ α _ := @Set.mem_univ α @[congr] theorem univ_unique (I J : Inhabited α) : @univ _ I = @univ _ J := ext.2 fun a => refl (a ∈ univ)
@[simp] theorem isPure_univ [Inhabited α] : @IsPure α univ ↔ Subsingleton α := ⟨fun h => ⟨fun a b => h a trivial b trivial⟩, fun ⟨h⟩ a _ b _ => h a b⟩
Mathlib/Data/Semiquot.lean
220
223
/- 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, Mitchell Lee -/ import Mathlib.Algebra.BigOperators.Group.Finset.Indicator import Mathlib.Data.Fintype.BigOperators import Mathlib.Topology.Algebra.InfiniteSum.Defs import Mathlib.Topology.Algebra.Monoid.Defs /-! # Lemmas on infinite sums and products in topological monoids This file contains many simple lemmas on `tsum`, `HasSum` etc, which are placed here in order to keep the basic file of definitions as short as possible. Results requiring a group (rather than monoid) structure on the target should go in `Group.lean`. -/ noncomputable section open Filter Finset Function Topology variable {α β γ : Type*} section HasProd variable [CommMonoid α] [TopologicalSpace α] variable {f g : β → α} {a b : α} /-- Constant one function has product `1` -/ @[to_additive "Constant zero function has sum `0`"] theorem hasProd_one : HasProd (fun _ ↦ 1 : β → α) 1 := by simp [HasProd, tendsto_const_nhds] @[to_additive] theorem hasProd_empty [IsEmpty β] : HasProd f 1 := by convert @hasProd_one α β _ _ @[to_additive] theorem multipliable_one : Multipliable (fun _ ↦ 1 : β → α) := hasProd_one.multipliable @[to_additive] theorem multipliable_empty [IsEmpty β] : Multipliable f := hasProd_empty.multipliable /-- See `multipliable_congr_cofinite` for a version allowing the functions to disagree on a finite set. -/ @[to_additive "See `summable_congr_cofinite` for a version allowing the functions to disagree on a finite set."] theorem multipliable_congr (hfg : ∀ b, f b = g b) : Multipliable f ↔ Multipliable g := iff_of_eq (congr_arg Multipliable <| funext hfg) /-- See `Multipliable.congr_cofinite` for a version allowing the functions to disagree on a finite set. -/ @[to_additive "See `Summable.congr_cofinite` for a version allowing the functions to disagree on a finite set."] theorem Multipliable.congr (hf : Multipliable f) (hfg : ∀ b, f b = g b) : Multipliable g := (multipliable_congr hfg).mp hf @[to_additive] lemma HasProd.congr_fun (hf : HasProd f a) (h : ∀ x : β, g x = f x) : HasProd g a := (funext h : g = f) ▸ hf @[to_additive] theorem HasProd.hasProd_of_prod_eq {g : γ → α} (h_eq : ∀ u : Finset γ, ∃ v : Finset β, ∀ v', v ⊆ v' → ∃ u', u ⊆ u' ∧ ∏ x ∈ u', g x = ∏ b ∈ v', f b) (hf : HasProd g a) : HasProd f a := le_trans (map_atTop_finset_prod_le_of_prod_eq h_eq) hf @[to_additive] theorem hasProd_iff_hasProd {g : γ → α} (h₁ : ∀ u : Finset γ, ∃ v : Finset β, ∀ v', v ⊆ v' → ∃ u', u ⊆ u' ∧ ∏ x ∈ u', g x = ∏ b ∈ v', f b) (h₂ : ∀ v : Finset β, ∃ u : Finset γ, ∀ u', u ⊆ u' → ∃ v', v ⊆ v' ∧ ∏ b ∈ v', f b = ∏ x ∈ u', g x) : HasProd f a ↔ HasProd g a := ⟨HasProd.hasProd_of_prod_eq h₂, HasProd.hasProd_of_prod_eq h₁⟩ @[to_additive] theorem Function.Injective.multipliable_iff {g : γ → β} (hg : Injective g) (hf : ∀ x ∉ Set.range g, f x = 1) : Multipliable (f ∘ g) ↔ Multipliable f := exists_congr fun _ ↦ hg.hasProd_iff hf @[to_additive (attr := simp)] theorem hasProd_extend_one {g : β → γ} (hg : Injective g) : HasProd (extend g f 1) a ↔ HasProd f a := by rw [← hg.hasProd_iff, extend_comp hg] exact extend_apply' _ _ @[to_additive (attr := simp)] theorem multipliable_extend_one {g : β → γ} (hg : Injective g) : Multipliable (extend g f 1) ↔ Multipliable f := exists_congr fun _ ↦ hasProd_extend_one hg @[to_additive] theorem hasProd_subtype_iff_mulIndicator {s : Set β} : HasProd (f ∘ (↑) : s → α) a ↔ HasProd (s.mulIndicator f) a := by rw [← Set.mulIndicator_range_comp, Subtype.range_coe, hasProd_subtype_iff_of_mulSupport_subset Set.mulSupport_mulIndicator_subset] @[to_additive] theorem multipliable_subtype_iff_mulIndicator {s : Set β} : Multipliable (f ∘ (↑) : s → α) ↔ Multipliable (s.mulIndicator f) := exists_congr fun _ ↦ hasProd_subtype_iff_mulIndicator @[to_additive (attr := simp)] theorem hasProd_subtype_mulSupport : HasProd (f ∘ (↑) : mulSupport f → α) a ↔ HasProd f a := hasProd_subtype_iff_of_mulSupport_subset <| Set.Subset.refl _ @[to_additive] protected theorem Finset.multipliable (s : Finset β) (f : β → α) : Multipliable (f ∘ (↑) : (↑s : Set β) → α) := (s.hasProd f).multipliable @[to_additive] protected theorem Set.Finite.multipliable {s : Set β} (hs : s.Finite) (f : β → α) : Multipliable (f ∘ (↑) : s → α) := by have := hs.toFinset.multipliable f rwa [hs.coe_toFinset] at this @[to_additive] theorem multipliable_of_finite_mulSupport (h : (mulSupport f).Finite) : Multipliable f := by apply multipliable_of_ne_finset_one (s := h.toFinset); simp @[to_additive] lemma Multipliable.of_finite [Finite β] {f : β → α} : Multipliable f := multipliable_of_finite_mulSupport <| Set.finite_univ.subset (Set.subset_univ _) @[to_additive] theorem hasProd_single {f : β → α} (b : β) (hf : ∀ (b') (_ : b' ≠ b), f b' = 1) : HasProd f (f b) := suffices HasProd f (∏ b' ∈ {b}, f b') by simpa using this hasProd_prod_of_ne_finset_one <| by simpa [hf] @[to_additive (attr := simp)] lemma hasProd_unique [Unique β] (f : β → α) : HasProd f (f default) := hasProd_single default (fun _ hb ↦ False.elim <| hb <| Unique.uniq ..) @[to_additive (attr := simp)] lemma hasProd_singleton (m : β) (f : β → α) : HasProd (({m} : Set β).restrict f) (f m) := hasProd_unique (Set.restrict {m} f) @[to_additive] theorem hasProd_ite_eq (b : β) [DecidablePred (· = b)] (a : α) : HasProd (fun b' ↦ if b' = b then a else 1) a := by convert @hasProd_single _ _ _ _ (fun b' ↦ if b' = b then a else 1) b (fun b' hb' ↦ if_neg hb') exact (if_pos rfl).symm @[to_additive] theorem Equiv.hasProd_iff (e : γ ≃ β) : HasProd (f ∘ e) a ↔ HasProd f a := e.injective.hasProd_iff <| by simp @[to_additive] theorem Function.Injective.hasProd_range_iff {g : γ → β} (hg : Injective g) : HasProd (fun x : Set.range g ↦ f x) a ↔ HasProd (f ∘ g) a := (Equiv.ofInjective g hg).hasProd_iff.symm @[to_additive] theorem Equiv.multipliable_iff (e : γ ≃ β) : Multipliable (f ∘ e) ↔ Multipliable f := exists_congr fun _ ↦ e.hasProd_iff @[to_additive] theorem Equiv.hasProd_iff_of_mulSupport {g : γ → α} (e : mulSupport f ≃ mulSupport g) (he : ∀ x : mulSupport f, g (e x) = f x) : HasProd f a ↔ HasProd g a := by have : (g ∘ (↑)) ∘ e = f ∘ (↑) := funext he rw [← hasProd_subtype_mulSupport, ← this, e.hasProd_iff, hasProd_subtype_mulSupport] @[to_additive] theorem hasProd_iff_hasProd_of_ne_one_bij {g : γ → α} (i : mulSupport g → β) (hi : Injective i) (hf : mulSupport f ⊆ Set.range i) (hfg : ∀ x, f (i x) = g x) : HasProd f a ↔ HasProd g a := Iff.symm <| Equiv.hasProd_iff_of_mulSupport (Equiv.ofBijective (fun x ↦ ⟨i x, fun hx ↦ x.coe_prop <| hfg x ▸ hx⟩) ⟨fun _ _ h ↦ hi <| Subtype.ext_iff.1 h, fun y ↦ (hf y.coe_prop).imp fun _ hx ↦ Subtype.ext hx⟩) hfg @[to_additive] theorem Equiv.multipliable_iff_of_mulSupport {g : γ → α} (e : mulSupport f ≃ mulSupport g) (he : ∀ x : mulSupport f, g (e x) = f x) : Multipliable f ↔ Multipliable g := exists_congr fun _ ↦ e.hasProd_iff_of_mulSupport he @[to_additive] protected theorem HasProd.map [CommMonoid γ] [TopologicalSpace γ] (hf : HasProd f a) {G} [FunLike G α γ] [MonoidHomClass G α γ] (g : G) (hg : Continuous g) : HasProd (g ∘ f) (g a) := by have : (g ∘ fun s : Finset β ↦ ∏ b ∈ s, f b) = fun s : Finset β ↦ ∏ b ∈ s, (g ∘ f) b := funext <| map_prod g _ unfold HasProd rw [← this] exact (hg.tendsto a).comp hf @[to_additive] protected theorem Topology.IsInducing.hasProd_iff [CommMonoid γ] [TopologicalSpace γ] {G} [FunLike G α γ] [MonoidHomClass G α γ] {g : G} (hg : IsInducing g) (f : β → α) (a : α) : HasProd (g ∘ f) (g a) ↔ HasProd f a := by simp_rw [HasProd, comp_apply, ← map_prod] exact hg.tendsto_nhds_iff.symm @[deprecated (since := "2024-10-28")] alias Inducing.hasProd_iff := IsInducing.hasProd_iff @[to_additive] protected theorem Multipliable.map [CommMonoid γ] [TopologicalSpace γ] (hf : Multipliable f) {G} [FunLike G α γ] [MonoidHomClass G α γ] (g : G) (hg : Continuous g) : Multipliable (g ∘ f) := (hf.hasProd.map g hg).multipliable @[to_additive] protected theorem Multipliable.map_iff_of_leftInverse [CommMonoid γ] [TopologicalSpace γ] {G G'} [FunLike G α γ] [MonoidHomClass G α γ] [FunLike G' γ α] [MonoidHomClass G' γ α] (g : G) (g' : G') (hg : Continuous g) (hg' : Continuous g') (hinv : Function.LeftInverse g' g) : Multipliable (g ∘ f) ↔ Multipliable f := ⟨fun h ↦ by have := h.map _ hg' rwa [← Function.comp_assoc, hinv.id] at this, fun h ↦ h.map _ hg⟩ @[to_additive] theorem Multipliable.map_tprod [CommMonoid γ] [TopologicalSpace γ] [T2Space γ] (hf : Multipliable f) {G} [FunLike G α γ] [MonoidHomClass G α γ] (g : G) (hg : Continuous g) : g (∏' i, f i) = ∏' i, g (f i) := (HasProd.tprod_eq (HasProd.map hf.hasProd g hg)).symm @[to_additive] lemma Topology.IsInducing.multipliable_iff_tprod_comp_mem_range [CommMonoid γ] [TopologicalSpace γ] [T2Space γ] {G} [FunLike G α γ] [MonoidHomClass G α γ] {g : G} (hg : IsInducing g) (f : β → α) : Multipliable f ↔ Multipliable (g ∘ f) ∧ ∏' i, g (f i) ∈ Set.range g := by constructor · intro hf constructor · exact hf.map g hg.continuous · use ∏' i, f i exact hf.map_tprod g hg.continuous · rintro ⟨hgf, a, ha⟩ use a have := hgf.hasProd simp_rw [comp_apply, ← ha] at this exact (hg.hasProd_iff f a).mp this @[deprecated (since := "2024-10-28")] alias Inducing.multipliable_iff_tprod_comp_mem_range := IsInducing.multipliable_iff_tprod_comp_mem_range /-- "A special case of `Multipliable.map_iff_of_leftInverse` for convenience" -/ @[to_additive "A special case of `Summable.map_iff_of_leftInverse` for convenience"] protected theorem Multipliable.map_iff_of_equiv [CommMonoid γ] [TopologicalSpace γ] {G} [EquivLike G α γ] [MulEquivClass G α γ] (g : G) (hg : Continuous g) (hg' : Continuous (EquivLike.inv g : γ → α)) : Multipliable (g ∘ f) ↔ Multipliable f := Multipliable.map_iff_of_leftInverse g (g : α ≃* γ).symm hg hg' (EquivLike.left_inv g) @[to_additive] theorem Function.Surjective.multipliable_iff_of_hasProd_iff {α' : Type*} [CommMonoid α'] [TopologicalSpace α'] {e : α' → α} (hes : Function.Surjective e) {f : β → α} {g : γ → α'} (he : ∀ {a}, HasProd f (e a) ↔ HasProd g a) : Multipliable f ↔ Multipliable g := hes.exists.trans <| exists_congr <| @he variable [ContinuousMul α] @[to_additive] theorem HasProd.mul (hf : HasProd f a) (hg : HasProd g b) : HasProd (fun b ↦ f b * g b) (a * b) := by dsimp only [HasProd] at hf hg ⊢ simp_rw [prod_mul_distrib] exact hf.mul hg @[to_additive] theorem Multipliable.mul (hf : Multipliable f) (hg : Multipliable g) : Multipliable fun b ↦ f b * g b := (hf.hasProd.mul hg.hasProd).multipliable @[to_additive] theorem hasProd_prod {f : γ → β → α} {a : γ → α} {s : Finset γ} : (∀ i ∈ s, HasProd (f i) (a i)) → HasProd (fun b ↦ ∏ i ∈ s, f i b) (∏ i ∈ s, a i) := by classical exact Finset.induction_on s (by simp only [hasProd_one, prod_empty, forall_true_iff]) <| by simp +contextual only [mem_insert, forall_eq_or_imp, not_false_iff, prod_insert, and_imp] exact fun x s _ IH hx h ↦ hx.mul (IH h) @[to_additive] theorem multipliable_prod {f : γ → β → α} {s : Finset γ} (hf : ∀ i ∈ s, Multipliable (f i)) : Multipliable fun b ↦ ∏ i ∈ s, f i b := (hasProd_prod fun i hi ↦ (hf i hi).hasProd).multipliable @[to_additive] theorem HasProd.mul_disjoint {s t : Set β} (hs : Disjoint s t) (ha : HasProd (f ∘ (↑) : s → α) a) (hb : HasProd (f ∘ (↑) : t → α) b) : HasProd (f ∘ (↑) : (s ∪ t : Set β) → α) (a * b) := by rw [hasProd_subtype_iff_mulIndicator] at * rw [Set.mulIndicator_union_of_disjoint hs] exact ha.mul hb @[to_additive] theorem hasProd_prod_disjoint {ι} (s : Finset ι) {t : ι → Set β} {a : ι → α} (hs : (s : Set ι).Pairwise (Disjoint on t)) (hf : ∀ i ∈ s, HasProd (f ∘ (↑) : t i → α) (a i)) : HasProd (f ∘ (↑) : (⋃ i ∈ s, t i) → α) (∏ i ∈ s, a i) := by simp_rw [hasProd_subtype_iff_mulIndicator] at * rw [Finset.mulIndicator_biUnion _ _ hs] exact hasProd_prod hf @[to_additive] theorem HasProd.mul_isCompl {s t : Set β} (hs : IsCompl s t) (ha : HasProd (f ∘ (↑) : s → α) a) (hb : HasProd (f ∘ (↑) : t → α) b) : HasProd f (a * b) := by simpa [← hs.compl_eq] using (hasProd_subtype_iff_mulIndicator.1 ha).mul (hasProd_subtype_iff_mulIndicator.1 hb) @[to_additive] theorem HasProd.mul_compl {s : Set β} (ha : HasProd (f ∘ (↑) : s → α) a) (hb : HasProd (f ∘ (↑) : (sᶜ : Set β) → α) b) : HasProd f (a * b) := ha.mul_isCompl isCompl_compl hb @[to_additive] theorem Multipliable.mul_compl {s : Set β} (hs : Multipliable (f ∘ (↑) : s → α)) (hsc : Multipliable (f ∘ (↑) : (sᶜ : Set β) → α)) : Multipliable f := (hs.hasProd.mul_compl hsc.hasProd).multipliable @[to_additive] theorem HasProd.compl_mul {s : Set β} (ha : HasProd (f ∘ (↑) : (sᶜ : Set β) → α) a) (hb : HasProd (f ∘ (↑) : s → α) b) : HasProd f (a * b) := ha.mul_isCompl isCompl_compl.symm hb @[to_additive] theorem Multipliable.compl_add {s : Set β} (hs : Multipliable (f ∘ (↑) : (sᶜ : Set β) → α)) (hsc : Multipliable (f ∘ (↑) : s → α)) : Multipliable f := (hs.hasProd.compl_mul hsc.hasProd).multipliable /-- Version of `HasProd.update` for `CommMonoid` rather than `CommGroup`. Rather than showing that `f.update` has a specific product in terms of `HasProd`, it gives a relationship between the products of `f` and `f.update` given that both exist. -/ @[to_additive "Version of `HasSum.update` for `AddCommMonoid` rather than `AddCommGroup`. Rather than showing that `f.update` has a specific sum in terms of `HasSum`, it gives a relationship between the sums of `f` and `f.update` given that both exist."] theorem HasProd.update' {α β : Type*} [TopologicalSpace α] [CommMonoid α] [T2Space α] [ContinuousMul α] [DecidableEq β] {f : β → α} {a a' : α} (hf : HasProd f a) (b : β) (x : α) (hf' : HasProd (update f b x) a') : a * x = a' * f b := by have : ∀ b', f b' * ite (b' = b) x 1 = update f b x b' * ite (b' = b) (f b) 1 := by intro b' split_ifs with hb' · simpa only [Function.update_apply, hb', eq_self_iff_true] using mul_comm (f b) x · simp only [Function.update_apply, hb', if_false] have h := hf.mul (hasProd_ite_eq b x) simp_rw [this] at h exact HasProd.unique h (hf'.mul (hasProd_ite_eq b (f b))) /-- Version of `hasProd_ite_div_hasProd` for `CommMonoid` rather than `CommGroup`. Rather than showing that the `ite` expression has a specific product in terms of `HasProd`, it gives a relationship between the products of `f` and `ite (n = b) 0 (f n)` given that both exist. -/ @[to_additive "Version of `hasSum_ite_sub_hasSum` for `AddCommMonoid` rather than `AddCommGroup`. Rather than showing that the `ite` expression has a specific sum in terms of `HasSum`, it gives a relationship between the sums of `f` and `ite (n = b) 0 (f n)` given that both exist."] theorem eq_mul_of_hasProd_ite {α β : Type*} [TopologicalSpace α] [CommMonoid α] [T2Space α] [ContinuousMul α] [DecidableEq β] {f : β → α} {a : α} (hf : HasProd f a) (b : β) (a' : α) (hf' : HasProd (fun n ↦ ite (n = b) 1 (f n)) a') : a = a' * f b := by refine (mul_one a).symm.trans (hf.update' b 1 ?_) convert hf' apply update_apply end HasProd section tprod variable [CommMonoid α] [TopologicalSpace α] {f g : β → α} @[to_additive] theorem tprod_congr_set_coe (f : β → α) {s t : Set β} (h : s = t) : ∏' x : s, f x = ∏' x : t, f x := by rw [h] @[to_additive] theorem tprod_congr_subtype (f : β → α) {P Q : β → Prop} (h : ∀ x, P x ↔ Q x) : ∏' x : {x // P x}, f x = ∏' x : {x // Q x}, f x := tprod_congr_set_coe f <| Set.ext h @[to_additive] theorem tprod_eq_finprod (hf : (mulSupport f).Finite) : ∏' b, f b = ∏ᶠ b, f b := by simp [tprod_def, multipliable_of_finite_mulSupport hf, hf] @[to_additive] theorem tprod_eq_prod' {s : Finset β} (hf : mulSupport f ⊆ s) : ∏' b, f b = ∏ b ∈ s, f b := by rw [tprod_eq_finprod (s.finite_toSet.subset hf), finprod_eq_prod_of_mulSupport_subset _ hf] @[to_additive] theorem tprod_eq_prod {s : Finset β} (hf : ∀ b ∉ s, f b = 1) : ∏' b, f b = ∏ b ∈ s, f b := tprod_eq_prod' <| mulSupport_subset_iff'.2 hf @[to_additive (attr := simp)] theorem tprod_one : ∏' _ : β, (1 : α) = 1 := by rw [tprod_eq_finprod] <;> simp @[to_additive (attr := simp)] theorem tprod_empty [IsEmpty β] : ∏' b, f b = 1 := by rw [tprod_eq_prod (s := (∅ : Finset β))] <;> simp @[to_additive] theorem tprod_congr {f g : β → α} (hfg : ∀ b, f b = g b) : ∏' b, f b = ∏' b, g b := congr_arg tprod (funext hfg) @[to_additive] theorem tprod_fintype [Fintype β] (f : β → α) : ∏' b, f b = ∏ b, f b := by apply tprod_eq_prod; simp @[to_additive] theorem prod_eq_tprod_mulIndicator (f : β → α) (s : Finset β) : ∏ x ∈ s, f x = ∏' x, Set.mulIndicator (↑s) f x := by rw [tprod_eq_prod' (Set.mulSupport_mulIndicator_subset), Finset.prod_mulIndicator_subset _ Finset.Subset.rfl] @[to_additive] theorem tprod_bool (f : Bool → α) : ∏' i : Bool, f i = f false * f true := by rw [tprod_fintype, Fintype.prod_bool, mul_comm] @[to_additive] theorem tprod_eq_mulSingle {f : β → α} (b : β) (hf : ∀ b' ≠ b, f b' = 1) : ∏' b, f b = f b := by rw [tprod_eq_prod (s := {b}), prod_singleton] exact fun b' hb' ↦ hf b' (by simpa using hb') @[to_additive] theorem tprod_tprod_eq_mulSingle (f : β → γ → α) (b : β) (c : γ) (hfb : ∀ b' ≠ b, f b' c = 1) (hfc : ∀ b', ∀ c' ≠ c, f b' c' = 1) : ∏' (b') (c'), f b' c' = f b c := calc ∏' (b') (c'), f b' c' = ∏' b', f b' c := tprod_congr fun b' ↦ tprod_eq_mulSingle _ (hfc b') _ = f b c := tprod_eq_mulSingle _ hfb @[to_additive (attr := simp)] theorem tprod_ite_eq (b : β) [DecidablePred (· = b)] (a : α) : ∏' b', (if b' = b then a else 1) = a := by rw [tprod_eq_mulSingle b] · simp · intro b' hb'; simp [hb'] @[to_additive (attr := simp)] theorem Finset.tprod_subtype (s : Finset β) (f : β → α) : ∏' x : { x // x ∈ s }, f x = ∏ x ∈ s, f x := by rw [← prod_attach]; exact tprod_fintype _ @[to_additive] theorem Finset.tprod_subtype' (s : Finset β) (f : β → α) : ∏' x : (s : Set β), f x = ∏ x ∈ s, f x := by simp @[to_additive (attr := simp)] theorem tprod_singleton (b : β) (f : β → α) : ∏' x : ({b} : Set β), f x = f b := by rw [← coe_singleton, Finset.tprod_subtype', prod_singleton] open scoped Classical in @[to_additive] theorem Function.Injective.tprod_eq {g : γ → β} (hg : Injective g) {f : β → α} (hf : mulSupport f ⊆ Set.range g) : ∏' c, f (g c) = ∏' b, f b := by have : mulSupport f = g '' mulSupport (f ∘ g) := by rw [mulSupport_comp_eq_preimage, Set.image_preimage_eq_iff.2 hf] rw [← Function.comp_def] by_cases hf_fin : (mulSupport f).Finite · have hfg_fin : (mulSupport (f ∘ g)).Finite := hf_fin.preimage hg.injOn lift g to γ ↪ β using hg simp_rw [tprod_eq_prod' hf_fin.coe_toFinset.ge, tprod_eq_prod' hfg_fin.coe_toFinset.ge, comp_apply, ← Finset.prod_map] refine Finset.prod_congr (Finset.coe_injective ?_) fun _ _ ↦ rfl simp [this] · have hf_fin' : ¬ Set.Finite (mulSupport (f ∘ g)) := by rwa [this, Set.finite_image_iff hg.injOn] at hf_fin simp_rw [tprod_def, if_neg hf_fin, if_neg hf_fin', Multipliable, funext fun a => propext <| hg.hasProd_iff (mulSupport_subset_iff'.1 hf) (a := a)] @[to_additive] theorem Equiv.tprod_eq (e : γ ≃ β) (f : β → α) : ∏' c, f (e c) = ∏' b, f b := e.injective.tprod_eq <| by simp /-! ### `tprod` on subsets - part 1 -/ @[to_additive] theorem tprod_subtype_eq_of_mulSupport_subset {f : β → α} {s : Set β} (hs : mulSupport f ⊆ s) : ∏' x : s, f x = ∏' x, f x := Subtype.val_injective.tprod_eq <| by simpa @[to_additive] theorem tprod_subtype_mulSupport (f : β → α) : ∏' x : mulSupport f, f x = ∏' x, f x := tprod_subtype_eq_of_mulSupport_subset Set.Subset.rfl @[to_additive] theorem tprod_subtype (s : Set β) (f : β → α) : ∏' x : s, f x = ∏' x, s.mulIndicator f x := by rw [← tprod_subtype_eq_of_mulSupport_subset Set.mulSupport_mulIndicator_subset, tprod_congr] simp @[to_additive (attr := simp)] theorem tprod_univ (f : β → α) : ∏' x : (Set.univ : Set β), f x = ∏' x, f x := tprod_subtype_eq_of_mulSupport_subset <| Set.subset_univ _ @[to_additive] theorem tprod_image {g : γ → β} (f : β → α) {s : Set γ} (hg : Set.InjOn g s) : ∏' x : g '' s, f x = ∏' x : s, f (g x) := ((Equiv.Set.imageOfInjOn _ _ hg).tprod_eq fun x ↦ f x).symm @[to_additive] theorem tprod_range {g : γ → β} (f : β → α) (hg : Injective g) : ∏' x : Set.range g, f x = ∏' x, f (g x) := by rw [← Set.image_univ, tprod_image f hg.injOn] simp_rw [← comp_apply (g := g), tprod_univ (f ∘ g)] /-- If `f b = 1` for all `b ∈ t`, then the product of `f a` with `a ∈ s` is the same as the product of `f a` with `a ∈ s ∖ t`. -/ @[to_additive "If `f b = 0` for all `b ∈ t`, then the sum of `f a` with `a ∈ s` is the same as the sum of `f a` with `a ∈ s ∖ t`."] lemma tprod_setElem_eq_tprod_setElem_diff {f : β → α} (s t : Set β) (hf₀ : ∀ b ∈ t, f b = 1) : ∏' a : s, f a = ∏' a : (s \ t : Set β), f a := .symm <| (Set.inclusion_injective (t := s) Set.diff_subset).tprod_eq (f := f ∘ (↑)) <| mulSupport_subset_iff'.2 fun b hb ↦ hf₀ b <| by simpa using hb /-- If `f b = 1`, then the product of `f a` with `a ∈ s` is the same as the product of `f a` for `a ∈ s ∖ {b}`. -/ @[to_additive "If `f b = 0`, then the sum of `f a` with `a ∈ s` is the same as the sum of `f a` for `a ∈ s ∖ {b}`."] lemma tprod_eq_tprod_diff_singleton {f : β → α} (s : Set β) {b : β} (hf₀ : f b = 1) : ∏' a : s, f a = ∏' a : (s \ {b} : Set β), f a := tprod_setElem_eq_tprod_setElem_diff s {b} fun _ ha ↦ ha ▸ hf₀ @[to_additive] theorem tprod_eq_tprod_of_ne_one_bij {g : γ → α} (i : mulSupport g → β) (hi : Injective i) (hf : mulSupport f ⊆ Set.range i) (hfg : ∀ x, f (i x) = g x) : ∏' x, f x = ∏' y, g y := by rw [← tprod_subtype_mulSupport g, ← hi.tprod_eq hf] simp only [hfg] @[to_additive] theorem Equiv.tprod_eq_tprod_of_mulSupport {f : β → α} {g : γ → α} (e : mulSupport f ≃ mulSupport g) (he : ∀ x, g (e x) = f x) : ∏' x, f x = ∏' y, g y := .symm <| tprod_eq_tprod_of_ne_one_bij _ (Subtype.val_injective.comp e.injective) (by simp) he @[to_additive] theorem tprod_dite_right (P : Prop) [Decidable P] (x : β → ¬P → α) : ∏' b : β, (if h : P then (1 : α) else x b h) = if h : P then (1 : α) else ∏' b : β, x b h := by by_cases hP : P <;> simp [hP] @[to_additive] theorem tprod_dite_left (P : Prop) [Decidable P] (x : β → P → α) : ∏' b : β, (if h : P then x b h else 1) = if h : P then ∏' b : β, x b h else 1 := by by_cases hP : P <;> simp [hP] @[to_additive (attr := simp)] lemma tprod_extend_one {γ : Type*} {g : γ → β} (hg : Injective g) (f : γ → α) : ∏' y, extend g f 1 y = ∏' x, f x := by have : mulSupport (extend g f 1) ⊆ Set.range g := mulSupport_subset_iff'.2 <| extend_apply' _ _ simp_rw [← hg.tprod_eq this, hg.extend_apply] variable [T2Space α] @[to_additive] theorem Function.Surjective.tprod_eq_tprod_of_hasProd_iff_hasProd {α' : Type*} [CommMonoid α'] [TopologicalSpace α'] {e : α' → α} (hes : Function.Surjective e) (h1 : e 1 = 1) {f : β → α} {g : γ → α'} (h : ∀ {a}, HasProd f (e a) ↔ HasProd g a) : ∏' b, f b = e (∏' c, g c) := by_cases (fun x ↦ (h.mpr x.hasProd).tprod_eq) fun hg : ¬Multipliable g ↦ by have hf : ¬Multipliable f := mt (hes.multipliable_iff_of_hasProd_iff @h).1 hg simp [tprod_def, hf, hg, h1] @[to_additive] theorem tprod_eq_tprod_of_hasProd_iff_hasProd {f : β → α} {g : γ → α} (h : ∀ {a}, HasProd f a ↔ HasProd g a) : ∏' b, f b = ∏' c, g c := surjective_id.tprod_eq_tprod_of_hasProd_iff_hasProd rfl @h section ContinuousMul variable [ContinuousMul α] @[to_additive] protected theorem Multipliable.tprod_mul (hf : Multipliable f) (hg : Multipliable g) : ∏' b, (f b * g b) = (∏' b, f b) * ∏' b, g b := (hf.hasProd.mul hg.hasProd).tprod_eq @[deprecated (since := "2025-04-12")] alias tsum_add := Summable.tsum_add @[to_additive existing, deprecated (since := "2025-04-12")] alias tprod_mul := Multipliable.tprod_mul @[to_additive] protected theorem Multipliable.tprod_finsetProd {f : γ → β → α} {s : Finset γ} (hf : ∀ i ∈ s, Multipliable (f i)) : ∏' b, ∏ i ∈ s, f i b = ∏ i ∈ s, ∏' b, f i b := (hasProd_prod fun i hi ↦ (hf i hi).hasProd).tprod_eq @[deprecated (since := "2025-02-13")]
alias tprod_of_prod := Multipliable.tprod_finsetProd @[deprecated (since := "2025-04-12")] alias tsum_finsetSum := Summable.tsum_finsetSum @[to_additive existing, deprecated (since := "2025-04-12")] alias tprod_finsetProd :=
Mathlib/Topology/Algebra/InfiniteSum/Basic.lean
576
579
/- Copyright (c) 2016 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Data.Set.Defs import Mathlib.Logic.Basic import Mathlib.Logic.ExistsUnique import Mathlib.Logic.Nonempty import Mathlib.Logic.Nontrivial.Defs import Batteries.Tactic.Init import Mathlib.Order.Defs.Unbundled /-! # Miscellaneous function constructions and lemmas -/ open Function universe u v w namespace Function section variable {α β γ : Sort*} {f : α → β} /-- Evaluate a function at an argument. Useful if you want to talk about the partially applied `Function.eval x : (∀ x, β x) → β x`. -/ @[reducible, simp] def eval {β : α → Sort*} (x : α) (f : ∀ x, β x) : β x := f x theorem eval_apply {β : α → Sort*} (x : α) (f : ∀ x, β x) : eval x f = f x := rfl theorem const_def {y : β} : (fun _ : α ↦ y) = const α y := rfl theorem const_injective [Nonempty α] : Injective (const α : β → α → β) := fun _ _ h ↦ let ⟨x⟩ := ‹Nonempty α› congr_fun h x @[simp] theorem const_inj [Nonempty α] {y₁ y₂ : β} : const α y₁ = const α y₂ ↔ y₁ = y₂ := ⟨fun h ↦ const_injective h, fun h ↦ h ▸ rfl⟩ theorem onFun_apply (f : β → β → γ) (g : α → β) (a b : α) : onFun f g a b = f (g a) (g b) := rfl lemma hfunext {α α' : Sort u} {β : α → Sort v} {β' : α' → Sort v} {f : ∀a, β a} {f' : ∀a, β' a} (hα : α = α') (h : ∀a a', HEq a a' → HEq (f a) (f' a')) : HEq f f' := by subst hα have : ∀a, HEq (f a) (f' a) := fun a ↦ h a a (HEq.refl a) have : β = β' := by funext a; exact type_eq_of_heq (this a) subst this apply heq_of_eq funext a exact eq_of_heq (this a) theorem ne_iff {β : α → Sort*} {f₁ f₂ : ∀ a, β a} : f₁ ≠ f₂ ↔ ∃ a, f₁ a ≠ f₂ a := funext_iff.not.trans not_forall lemma funext_iff_of_subsingleton [Subsingleton α] {g : α → β} (x y : α) : f x = g y ↔ f = g := by refine ⟨fun h ↦ funext fun z ↦ ?_, fun h ↦ ?_⟩ · rwa [Subsingleton.elim x z, Subsingleton.elim y z] at h · rw [h, Subsingleton.elim x y] theorem swap_lt {α} [LT α] : swap (· < · : α → α → _) = (· > ·) := rfl theorem swap_le {α} [LE α] : swap (· ≤ · : α → α → _) = (· ≥ ·) := rfl theorem swap_gt {α} [LT α] : swap (· > · : α → α → _) = (· < ·) := rfl theorem swap_ge {α} [LE α] : swap (· ≥ · : α → α → _) = (· ≤ ·) := rfl protected theorem Bijective.injective {f : α → β} (hf : Bijective f) : Injective f := hf.1 protected theorem Bijective.surjective {f : α → β} (hf : Bijective f) : Surjective f := hf.2 theorem not_injective_iff : ¬ Injective f ↔ ∃ a b, f a = f b ∧ a ≠ b := by simp only [Injective, not_forall, exists_prop] /-- If the co-domain `β` of an injective function `f : α → β` has decidable equality, then the domain `α` also has decidable equality. -/ protected def Injective.decidableEq [DecidableEq β] (I : Injective f) : DecidableEq α := fun _ _ ↦ decidable_of_iff _ I.eq_iff theorem Injective.of_comp {g : γ → α} (I : Injective (f ∘ g)) : Injective g := fun _ _ h ↦ I <| congr_arg f h @[simp] theorem Injective.of_comp_iff (hf : Injective f) (g : γ → α) : Injective (f ∘ g) ↔ Injective g := ⟨Injective.of_comp, hf.comp⟩ theorem Injective.of_comp_right {g : γ → α} (I : Injective (f ∘ g)) (hg : Surjective g) : Injective f := fun x y h ↦ by obtain ⟨x, rfl⟩ := hg x obtain ⟨y, rfl⟩ := hg y exact congr_arg g (I h) theorem Surjective.bijective₂_of_injective {g : γ → α} (hf : Surjective f) (hg : Surjective g) (I : Injective (f ∘ g)) : Bijective f ∧ Bijective g := ⟨⟨I.of_comp_right hg, hf⟩, I.of_comp, hg⟩ @[simp] theorem Injective.of_comp_iff' (f : α → β) {g : γ → α} (hg : Bijective g) : Injective (f ∘ g) ↔ Injective f := ⟨fun I ↦ I.of_comp_right hg.2, fun h ↦ h.comp hg.injective⟩ theorem Injective.piMap {ι : Sort*} {α β : ι → Sort*} {f : ∀ i, α i → β i} (hf : ∀ i, Injective (f i)) : Injective (Pi.map f) := fun _ _ h ↦ funext fun i ↦ hf i <| congrFun h _ /-- Composition by an injective function on the left is itself injective. -/ theorem Injective.comp_left {g : β → γ} (hg : Injective g) : Injective (g ∘ · : (α → β) → α → γ) := .piMap fun _ ↦ hg theorem injective_comp_left_iff [Nonempty α] {g : β → γ} : Injective (g ∘ · : (α → β) → α → γ) ↔ Injective g := ⟨fun h b₁ b₂ eq ↦ Nonempty.elim ‹_› (congr_fun <| h (a₁ := fun _ ↦ b₁) (a₂ := fun _ ↦ b₂) <| funext fun _ ↦ eq), (·.comp_left)⟩ @[nontriviality] theorem injective_of_subsingleton [Subsingleton α] (f : α → β) : Injective f := fun _ _ _ ↦ Subsingleton.elim _ _ @[nontriviality] theorem bijective_of_subsingleton [Subsingleton α] (f : α → α) : Bijective f := ⟨injective_of_subsingleton f, fun a ↦ ⟨a, Subsingleton.elim ..⟩⟩ lemma Injective.dite (p : α → Prop) [DecidablePred p] {f : {a : α // p a} → β} {f' : {a : α // ¬ p a} → β} (hf : Injective f) (hf' : Injective f') (im_disj : ∀ {x x' : α} {hx : p x} {hx' : ¬ p x'}, f ⟨x, hx⟩ ≠ f' ⟨x', hx'⟩) : Function.Injective (fun x ↦ if h : p x then f ⟨x, h⟩ else f' ⟨x, h⟩) := fun x₁ x₂ h => by dsimp only at h by_cases h₁ : p x₁ <;> by_cases h₂ : p x₂ · rw [dif_pos h₁, dif_pos h₂] at h; injection (hf h) · rw [dif_pos h₁, dif_neg h₂] at h; exact (im_disj h).elim · rw [dif_neg h₁, dif_pos h₂] at h; exact (im_disj h.symm).elim · rw [dif_neg h₁, dif_neg h₂] at h; injection (hf' h) theorem Surjective.of_comp {g : γ → α} (S : Surjective (f ∘ g)) : Surjective f := fun y ↦ let ⟨x, h⟩ := S y ⟨g x, h⟩ @[simp] theorem Surjective.of_comp_iff (f : α → β) {g : γ → α} (hg : Surjective g) : Surjective (f ∘ g) ↔ Surjective f := ⟨Surjective.of_comp, fun h ↦ h.comp hg⟩ theorem Surjective.of_comp_left {g : γ → α} (S : Surjective (f ∘ g)) (hf : Injective f) : Surjective g := fun a ↦ let ⟨c, hc⟩ := S (f a); ⟨c, hf hc⟩ theorem Injective.bijective₂_of_surjective {g : γ → α} (hf : Injective f) (hg : Injective g) (S : Surjective (f ∘ g)) : Bijective f ∧ Bijective g := ⟨⟨hf, S.of_comp⟩, hg, S.of_comp_left hf⟩ @[simp] theorem Surjective.of_comp_iff' (hf : Bijective f) (g : γ → α) : Surjective (f ∘ g) ↔ Surjective g := ⟨fun S ↦ S.of_comp_left hf.1, hf.surjective.comp⟩ instance decidableEqPFun (p : Prop) [Decidable p] (α : p → Type*) [∀ hp, DecidableEq (α hp)] : DecidableEq (∀ hp, α hp) | f, g => decidable_of_iff (∀ hp, f hp = g hp) funext_iff.symm protected theorem Surjective.forall (hf : Surjective f) {p : β → Prop} : (∀ y, p y) ↔ ∀ x, p (f x) := ⟨fun h x ↦ h (f x), fun h y ↦ let ⟨x, hx⟩ := hf y hx ▸ h x⟩ protected theorem Surjective.forall₂ (hf : Surjective f) {p : β → β → Prop} : (∀ y₁ y₂, p y₁ y₂) ↔ ∀ x₁ x₂, p (f x₁) (f x₂) := hf.forall.trans <| forall_congr' fun _ ↦ hf.forall protected theorem Surjective.forall₃ (hf : Surjective f) {p : β → β → β → Prop} : (∀ y₁ y₂ y₃, p y₁ y₂ y₃) ↔ ∀ x₁ x₂ x₃, p (f x₁) (f x₂) (f x₃) := hf.forall.trans <| forall_congr' fun _ ↦ hf.forall₂ protected theorem Surjective.exists (hf : Surjective f) {p : β → Prop} : (∃ y, p y) ↔ ∃ x, p (f x) := ⟨fun ⟨y, hy⟩ ↦ let ⟨x, hx⟩ := hf y ⟨x, hx.symm ▸ hy⟩, fun ⟨x, hx⟩ ↦ ⟨f x, hx⟩⟩ protected theorem Surjective.exists₂ (hf : Surjective f) {p : β → β → Prop} : (∃ y₁ y₂, p y₁ y₂) ↔ ∃ x₁ x₂, p (f x₁) (f x₂) := hf.exists.trans <| exists_congr fun _ ↦ hf.exists protected theorem Surjective.exists₃ (hf : Surjective f) {p : β → β → β → Prop} : (∃ y₁ y₂ y₃, p y₁ y₂ y₃) ↔ ∃ x₁ x₂ x₃, p (f x₁) (f x₂) (f x₃) := hf.exists.trans <| exists_congr fun _ ↦ hf.exists₂ theorem Surjective.injective_comp_right (hf : Surjective f) : Injective fun g : β → γ ↦ g ∘ f := fun _ _ h ↦ funext <| hf.forall.2 <| congr_fun h theorem injective_comp_right_iff_surjective {γ : Type*} [Nontrivial γ] : Injective (fun g : β → γ ↦ g ∘ f) ↔ Surjective f := by refine ⟨not_imp_not.mp fun not_surj inj ↦ not_subsingleton γ ⟨fun c c' ↦ ?_⟩, (·.injective_comp_right)⟩ have ⟨b₀, hb⟩ := not_forall.mp not_surj classical have := inj (a₁ := fun _ ↦ c) (a₂ := (if · = b₀ then c' else c)) ?_ · simpa using congr_fun this b₀ ext a; simp only [comp_apply, if_neg fun h ↦ hb ⟨a, h⟩] protected theorem Surjective.right_cancellable (hf : Surjective f) {g₁ g₂ : β → γ} : g₁ ∘ f = g₂ ∘ f ↔ g₁ = g₂ := hf.injective_comp_right.eq_iff theorem surjective_of_right_cancellable_Prop (h : ∀ g₁ g₂ : β → Prop, g₁ ∘ f = g₂ ∘ f → g₁ = g₂) : Surjective f := injective_comp_right_iff_surjective.mp h theorem bijective_iff_existsUnique (f : α → β) : Bijective f ↔ ∀ b : β, ∃! a : α, f a = b := ⟨fun hf b ↦ let ⟨a, ha⟩ := hf.surjective b ⟨a, ha, fun _ ha' ↦ hf.injective (ha'.trans ha.symm)⟩, fun he ↦ ⟨fun {_a a'} h ↦ (he (f a')).unique h rfl, fun b ↦ (he b).exists⟩⟩ /-- Shorthand for using projection notation with `Function.bijective_iff_existsUnique`. -/ protected theorem Bijective.existsUnique {f : α → β} (hf : Bijective f) (b : β) : ∃! a : α, f a = b := (bijective_iff_existsUnique f).mp hf b theorem Bijective.existsUnique_iff {f : α → β} (hf : Bijective f) {p : β → Prop} : (∃! y, p y) ↔ ∃! x, p (f x) := ⟨fun ⟨y, hpy, hy⟩ ↦ let ⟨x, hx⟩ := hf.surjective y ⟨x, by simpa [hx], fun z (hz : p (f z)) ↦ hf.injective <| hx.symm ▸ hy _ hz⟩, fun ⟨x, hpx, hx⟩ ↦ ⟨f x, hpx, fun y hy ↦ let ⟨z, hz⟩ := hf.surjective y hz ▸ congr_arg f (hx _ (by simpa [hz]))⟩⟩ theorem Bijective.of_comp_iff (f : α → β) {g : γ → α} (hg : Bijective g) : Bijective (f ∘ g) ↔ Bijective f := and_congr (Injective.of_comp_iff' _ hg) (Surjective.of_comp_iff _ hg.surjective) theorem Bijective.of_comp_iff' {f : α → β} (hf : Bijective f) (g : γ → α) : Function.Bijective (f ∘ g) ↔ Function.Bijective g := and_congr (Injective.of_comp_iff hf.injective _) (Surjective.of_comp_iff' hf _) /-- **Cantor's diagonal argument** implies that there are no surjective functions from `α` to `Set α`. -/ theorem cantor_surjective {α} (f : α → Set α) : ¬Surjective f | h => let ⟨D, e⟩ := h {a | ¬ f a a} @iff_not_self (D ∈ f D) <| iff_of_eq <| congr_arg (D ∈ ·) e /-- **Cantor's diagonal argument** implies that there are no injective functions from `Set α` to `α`. -/ theorem cantor_injective {α : Type*} (f : Set α → α) : ¬Injective f | i => cantor_surjective (fun a ↦ {b | ∀ U, a = f U → U b}) <| RightInverse.surjective (fun U ↦ Set.ext fun _ ↦ ⟨fun h ↦ h U rfl, fun h _ e ↦ i e ▸ h⟩) /-- There is no surjection from `α : Type u` into `Type (max u v)`. This theorem demonstrates why `Type : Type` would be inconsistent in Lean. -/ theorem not_surjective_Type {α : Type u} (f : α → Type max u v) : ¬Surjective f := by intro hf let T : Type max u v := Sigma f cases hf (Set T) with | intro U hU => let g : Set T → T := fun s ↦ ⟨U, cast hU.symm s⟩ have hg : Injective g := by intro s t h suffices cast hU (g s).2 = cast hU (g t).2 by simp only [g, cast_cast, cast_eq] at this assumption · congr exact cantor_injective g hg /-- `g` is a partial inverse to `f` (an injective but not necessarily surjective function) if `g y = some x` implies `f x = y`, and `g y = none` implies that `y` is not in the range of `f`. -/ def IsPartialInv {α β} (f : α → β) (g : β → Option α) : Prop := ∀ x y, g y = some x ↔ f x = y theorem isPartialInv_left {α β} {f : α → β} {g} (H : IsPartialInv f g) (x) : g (f x) = some x := (H _ _).2 rfl theorem injective_of_isPartialInv {α β} {f : α → β} {g} (H : IsPartialInv f g) : Injective f := fun _ _ h ↦ Option.some.inj <| ((H _ _).2 h).symm.trans ((H _ _).2 rfl) theorem injective_of_isPartialInv_right {α β} {f : α → β} {g} (H : IsPartialInv f g) (x y b) (h₁ : b ∈ g x) (h₂ : b ∈ g y) : x = y := ((H _ _).1 h₁).symm.trans ((H _ _).1 h₂) theorem LeftInverse.comp_eq_id {f : α → β} {g : β → α} (h : LeftInverse f g) : f ∘ g = id := funext h theorem leftInverse_iff_comp {f : α → β} {g : β → α} : LeftInverse f g ↔ f ∘ g = id := ⟨LeftInverse.comp_eq_id, congr_fun⟩ theorem RightInverse.comp_eq_id {f : α → β} {g : β → α} (h : RightInverse f g) : g ∘ f = id := funext h theorem rightInverse_iff_comp {f : α → β} {g : β → α} : RightInverse f g ↔ g ∘ f = id := ⟨RightInverse.comp_eq_id, congr_fun⟩ theorem LeftInverse.comp {f : α → β} {g : β → α} {h : β → γ} {i : γ → β} (hf : LeftInverse f g) (hh : LeftInverse h i) : LeftInverse (h ∘ f) (g ∘ i) := fun a ↦ show h (f (g (i a))) = a by rw [hf (i a), hh a] theorem RightInverse.comp {f : α → β} {g : β → α} {h : β → γ} {i : γ → β} (hf : RightInverse f g) (hh : RightInverse h i) : RightInverse (h ∘ f) (g ∘ i) := LeftInverse.comp hh hf theorem LeftInverse.rightInverse {f : α → β} {g : β → α} (h : LeftInverse g f) : RightInverse f g := h theorem RightInverse.leftInverse {f : α → β} {g : β → α} (h : RightInverse g f) : LeftInverse f g := h theorem LeftInverse.surjective {f : α → β} {g : β → α} (h : LeftInverse f g) : Surjective f := h.rightInverse.surjective theorem RightInverse.injective {f : α → β} {g : β → α} (h : RightInverse f g) : Injective f := h.leftInverse.injective theorem LeftInverse.rightInverse_of_injective {f : α → β} {g : β → α} (h : LeftInverse f g) (hf : Injective f) : RightInverse f g := fun x ↦ hf <| h (f x) theorem LeftInverse.rightInverse_of_surjective {f : α → β} {g : β → α} (h : LeftInverse f g) (hg : Surjective g) : RightInverse f g := fun x ↦ let ⟨y, hy⟩ := hg x; hy ▸ congr_arg g (h y) theorem RightInverse.leftInverse_of_surjective {f : α → β} {g : β → α} : RightInverse f g → Surjective f → LeftInverse f g := LeftInverse.rightInverse_of_surjective theorem RightInverse.leftInverse_of_injective {f : α → β} {g : β → α} : RightInverse f g → Injective g → LeftInverse f g := LeftInverse.rightInverse_of_injective theorem LeftInverse.eq_rightInverse {f : α → β} {g₁ g₂ : β → α} (h₁ : LeftInverse g₁ f) (h₂ : RightInverse g₂ f) : g₁ = g₂ := calc g₁ = g₁ ∘ f ∘ g₂ := by rw [h₂.comp_eq_id, comp_id] _ = g₂ := by rw [← comp_assoc, h₁.comp_eq_id, id_comp] /-- We can use choice to construct explicitly a partial inverse for a given injective function `f`. -/ noncomputable def partialInv {α β} (f : α → β) (b : β) : Option α := open scoped Classical in if h : ∃ a, f a = b then some (Classical.choose h) else none theorem partialInv_of_injective {α β} {f : α → β} (I : Injective f) : IsPartialInv f (partialInv f) | a, b => ⟨fun h => open scoped Classical in have hpi : partialInv f b = if h : ∃ a, f a = b then some (Classical.choose h) else none := rfl if h' : ∃ a, f a = b then by rw [hpi, dif_pos h'] at h injection h with h subst h apply Classical.choose_spec h' else by rw [hpi, dif_neg h'] at h; contradiction, fun e => e ▸ have h : ∃ a', f a' = f a := ⟨_, rfl⟩ (dif_pos h).trans (congr_arg _ (I <| Classical.choose_spec h))⟩ theorem partialInv_left {α β} {f : α → β} (I : Injective f) : ∀ x, partialInv f (f x) = some x := isPartialInv_left (partialInv_of_injective I) end section InvFun variable {α β : Sort*} [Nonempty α] {f : α → β} {b : β} /-- The inverse of a function (which is a left inverse if `f` is injective and a right inverse if `f` is surjective). -/ -- Explicit Sort so that `α` isn't inferred to be Prop via `exists_prop_decidable` noncomputable def invFun {α : Sort u} {β} [Nonempty α] (f : α → β) : β → α := open scoped Classical in fun y ↦ if h : (∃ x, f x = y) then h.choose else Classical.arbitrary α theorem invFun_eq (h : ∃ a, f a = b) : f (invFun f b) = b := by simp only [invFun, dif_pos h, h.choose_spec] theorem apply_invFun_apply {α β : Type*} {f : α → β} {a : α} : f (@invFun _ _ ⟨a⟩ f (f a)) = f a := @invFun_eq _ _ ⟨a⟩ _ _ ⟨_, rfl⟩ theorem invFun_neg (h : ¬∃ a, f a = b) : invFun f b = Classical.choice ‹_› := dif_neg h theorem invFun_eq_of_injective_of_rightInverse {g : β → α} (hf : Injective f) (hg : RightInverse g f) : invFun f = g := funext fun b ↦ hf (by rw [hg b] exact invFun_eq ⟨g b, hg b⟩) theorem rightInverse_invFun (hf : Surjective f) : RightInverse (invFun f) f := fun b ↦ invFun_eq <| hf b theorem leftInverse_invFun (hf : Injective f) : LeftInverse (invFun f) f := fun b ↦ hf <| invFun_eq ⟨b, rfl⟩ theorem invFun_surjective (hf : Injective f) : Surjective (invFun f) := (leftInverse_invFun hf).surjective theorem invFun_comp (hf : Injective f) : invFun f ∘ f = id := funext <| leftInverse_invFun hf theorem Injective.hasLeftInverse (hf : Injective f) : HasLeftInverse f := ⟨invFun f, leftInverse_invFun hf⟩ theorem injective_iff_hasLeftInverse : Injective f ↔ HasLeftInverse f := ⟨Injective.hasLeftInverse, HasLeftInverse.injective⟩ end InvFun section SurjInv variable {α : Sort u} {β : Sort v} {γ : Sort w} {f : α → β} /-- The inverse of a surjective function. (Unlike `invFun`, this does not require `α` to be inhabited.) -/ noncomputable def surjInv {f : α → β} (h : Surjective f) (b : β) : α := Classical.choose (h b) theorem surjInv_eq (h : Surjective f) (b) : f (surjInv h b) = b := Classical.choose_spec (h b) theorem rightInverse_surjInv (hf : Surjective f) : RightInverse (surjInv hf) f := surjInv_eq hf theorem leftInverse_surjInv (hf : Bijective f) : LeftInverse (surjInv hf.2) f := rightInverse_of_injective_of_leftInverse hf.1 (rightInverse_surjInv hf.2) theorem Surjective.hasRightInverse (hf : Surjective f) : HasRightInverse f := ⟨_, rightInverse_surjInv hf⟩ theorem surjective_iff_hasRightInverse : Surjective f ↔ HasRightInverse f := ⟨Surjective.hasRightInverse, HasRightInverse.surjective⟩ theorem bijective_iff_has_inverse : Bijective f ↔ ∃ g, LeftInverse g f ∧ RightInverse g f := ⟨fun hf ↦ ⟨_, leftInverse_surjInv hf, rightInverse_surjInv hf.2⟩, fun ⟨_, gl, gr⟩ ↦ ⟨gl.injective, gr.surjective⟩⟩ theorem injective_surjInv (h : Surjective f) : Injective (surjInv h) := (rightInverse_surjInv h).injective theorem surjective_to_subsingleton [na : Nonempty α] [Subsingleton β] (f : α → β) : Surjective f := fun _ ↦ let ⟨a⟩ := na; ⟨a, Subsingleton.elim _ _⟩ theorem Surjective.piMap {ι : Sort*} {α β : ι → Sort*} {f : ∀ i, α i → β i} (hf : ∀ i, Surjective (f i)) : Surjective (Pi.map f) := fun g ↦ ⟨fun i ↦ surjInv (hf i) (g i), funext fun _ ↦ rightInverse_surjInv _ _⟩ /-- Composition by a surjective function on the left is itself surjective. -/ theorem Surjective.comp_left {g : β → γ} (hg : Surjective g) : Surjective (g ∘ · : (α → β) → α → γ) := .piMap fun _ ↦ hg theorem surjective_comp_left_iff [Nonempty α] {g : β → γ} : Surjective (g ∘ · : (α → β) → α → γ) ↔ Surjective g := by refine ⟨fun h c ↦ Nonempty.elim ‹_› fun a ↦ ?_, (·.comp_left)⟩ have ⟨f, hf⟩ := h fun _ ↦ c exact ⟨f a, congr_fun hf _⟩ theorem Bijective.piMap {ι : Sort*} {α β : ι → Sort*} {f : ∀ i, α i → β i} (hf : ∀ i, Bijective (f i)) : Bijective (Pi.map f) := ⟨.piMap fun i ↦ (hf i).1, .piMap fun i ↦ (hf i).2⟩ /-- Composition by a bijective function on the left is itself bijective. -/ theorem Bijective.comp_left {g : β → γ} (hg : Bijective g) : Bijective (g ∘ · : (α → β) → α → γ) := ⟨hg.injective.comp_left, hg.surjective.comp_left⟩ end SurjInv section Update variable {α : Sort u} {β : α → Sort v} {α' : Sort w} [DecidableEq α] {f : (a : α) → β a} {a : α} {b : β a} /-- Replacing the value of a function at a given point by a given value. -/ def update (f : ∀ a, β a) (a' : α) (v : β a') (a : α) : β a := if h : a = a' then Eq.ndrec v h.symm else f a @[simp] theorem update_self (a : α) (v : β a) (f : ∀ a, β a) : update f a v a = v := dif_pos rfl @[deprecated (since := "2024-12-28")] alias update_same := update_self @[simp] theorem update_of_ne {a a' : α} (h : a ≠ a') (v : β a') (f : ∀ a, β a) : update f a' v a = f a := dif_neg h @[deprecated (since := "2024-12-28")] alias update_noteq := update_of_ne /-- On non-dependent functions, `Function.update` can be expressed as an `ite` -/ theorem update_apply {β : Sort*} (f : α → β) (a' : α) (b : β) (a : α) : update f a' b a = if a = a' then b else f a := by rcases Decidable.eq_or_ne a a' with rfl | hne <;> simp [*] @[nontriviality] theorem update_eq_const_of_subsingleton [Subsingleton α] (a : α) (v : α') (f : α → α') : update f a v = const α v := funext fun a' ↦ Subsingleton.elim a a' ▸ update_self .. theorem surjective_eval {α : Sort u} {β : α → Sort v} [h : ∀ a, Nonempty (β a)] (a : α) : Surjective (eval a : (∀ a, β a) → β a) := fun b ↦ ⟨@update _ _ (Classical.decEq α) (fun a ↦ (h a).some) a b, @update_self _ _ (Classical.decEq α) _ _ _⟩ theorem update_injective (f : ∀ a, β a) (a' : α) : Injective (update f a') := fun v v' h ↦ by have := congr_fun h a' rwa [update_self, update_self] at this lemma forall_update_iff (f : ∀a, β a) {a : α} {b : β a} (p : ∀a, β a → Prop) : (∀ x, p x (update f a b x)) ↔ p a b ∧ ∀ x, x ≠ a → p x (f x) := by rw [← and_forall_ne a, update_self] simp +contextual theorem exists_update_iff (f : ∀ a, β a) {a : α} {b : β a} (p : ∀ a, β a → Prop) : (∃ x, p x (update f a b x)) ↔ p a b ∨ ∃ x ≠ a, p x (f x) := by rw [← not_forall_not, forall_update_iff f fun a b ↦ ¬p a b] simp [-not_and, not_and_or] theorem update_eq_iff {a : α} {b : β a} {f g : ∀ a, β a} : update f a b = g ↔ b = g a ∧ ∀ x ≠ a, f x = g x := funext_iff.trans <| forall_update_iff _ fun x y ↦ y = g x theorem eq_update_iff {a : α} {b : β a} {f g : ∀ a, β a} : g = update f a b ↔ g a = b ∧ ∀ x ≠ a, g x = f x := funext_iff.trans <| forall_update_iff _ fun x y ↦ g x = y @[simp] lemma update_eq_self_iff : update f a b = f ↔ b = f a := by simp [update_eq_iff] @[simp] lemma eq_update_self_iff : f = update f a b ↔ f a = b := by simp [eq_update_iff] lemma ne_update_self_iff : f ≠ update f a b ↔ f a ≠ b := eq_update_self_iff.not lemma update_ne_self_iff : update f a b ≠ f ↔ b ≠ f a := update_eq_self_iff.not @[simp] theorem update_eq_self (a : α) (f : ∀ a, β a) : update f a (f a) = f := update_eq_iff.2 ⟨rfl, fun _ _ ↦ rfl⟩ theorem update_comp_eq_of_forall_ne' {α'} (g : ∀ a, β a) {f : α' → α} {i : α} (a : β i) (h : ∀ x, f x ≠ i) : (fun j ↦ (update g i a) (f j)) = fun j ↦ g (f j) := funext fun _ ↦ update_of_ne (h _) _ _ variable [DecidableEq α'] /-- Non-dependent version of `Function.update_comp_eq_of_forall_ne'` -/ theorem update_comp_eq_of_forall_ne {α β : Sort*} (g : α' → β) {f : α → α'} {i : α'} (a : β) (h : ∀ x, f x ≠ i) : update g i a ∘ f = g ∘ f := update_comp_eq_of_forall_ne' g a h theorem update_comp_eq_of_injective' (g : ∀ a, β a) {f : α' → α} (hf : Function.Injective f) (i : α') (a : β (f i)) : (fun j ↦ update g (f i) a (f j)) = update (fun i ↦ g (f i)) i a := eq_update_iff.2 ⟨update_self .., fun _ hj ↦ update_of_ne (hf.ne hj) _ _⟩ theorem update_apply_of_injective (g : ∀ a, β a) {f : α' → α} (hf : Function.Injective f) (i : α') (a : β (f i)) (j : α') : update g (f i) a (f j) = update (fun i ↦ g (f i)) i a j := congr_fun (update_comp_eq_of_injective' g hf i a) j /-- Non-dependent version of `Function.update_comp_eq_of_injective'` -/ theorem update_comp_eq_of_injective {β : Sort*} (g : α' → β) {f : α → α'} (hf : Function.Injective f) (i : α) (a : β) : Function.update g (f i) a ∘ f = Function.update (g ∘ f) i a := update_comp_eq_of_injective' g hf i a /-- Recursors can be pushed inside `Function.update`. The `ctor` argument should be a one-argument constructor like `Sum.inl`, and `recursor` should be an inductive recursor partially applied in all but that constructor, such as `(Sum.rec · g)`. In future, we should build some automation to generate applications like `Option.rec_update` for all inductive types. -/ lemma rec_update {ι κ : Sort*} {α : κ → Sort*} [DecidableEq ι] [DecidableEq κ] {ctor : ι → κ} (hctor : Function.Injective ctor) (recursor : ((i : ι) → α (ctor i)) → ((i : κ) → α i)) (h : ∀ f i, recursor f (ctor i) = f i) (h2 : ∀ f₁ f₂ k, (∀ i, ctor i ≠ k) → recursor f₁ k = recursor f₂ k) (f : (i : ι) → α (ctor i)) (i : ι) (x : α (ctor i)) : recursor (update f i x) = update (recursor f) (ctor i) x := by ext k by_cases h : ∃ i, ctor i = k · obtain ⟨i', rfl⟩ := h obtain rfl | hi := eq_or_ne i' i · simp [h] · have hk := hctor.ne hi simp [h, hi, hk, Function.update_of_ne] · rw [not_exists] at h rw [h2 _ f _ h] rw [Function.update_of_ne (Ne.symm <| h i)] @[simp] lemma _root_.Option.rec_update {α : Type*} {β : Option α → Sort*} [DecidableEq α] (f : β none) (g : ∀ a, β (.some a)) (a : α) (x : β (.some a)) : Option.rec f (update g a x) = update (Option.rec f g) (.some a) x := Function.rec_update (@Option.some.inj _) (Option.rec f) (fun _ _ => rfl) (fun | _, _, .some _, h => (h _ rfl).elim | _, _, .none, _ => rfl) _ _ _ theorem apply_update {ι : Sort*} [DecidableEq ι] {α β : ι → Sort*} (f : ∀ i, α i → β i) (g : ∀ i, α i) (i : ι) (v : α i) (j : ι) : f j (update g i v j) = update (fun k ↦ f k (g k)) i (f i v) j := by by_cases h : j = i · subst j simp · simp [h]
Mathlib/Logic/Function/Basic.lean
614
614
/- Copyright (c) 2023 Newell Jensen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Newell Jensen -/ import Mathlib.GroupTheory.SpecificGroups.Cyclic import Mathlib.GroupTheory.SpecificGroups.Dihedral /-! # Klein Four Group The Klein (Vierergruppe) four-group is a non-cyclic abelian group with four elements, in which each element is self-inverse and in which composing any two of the three non-identity elements produces the third one. ## Main definitions * `IsKleinFour` : A mixin class which states that the group has order four and exponent two. * `mulEquiv'` : An equivalence between a Klein four-group and a group of exponent two which preserves the identity is in fact an isomorphism. * `mulEquiv`: Any two Klein four-groups are isomorphic via any identity preserving equivalence. ## References * https://en.wikipedia.org/wiki/Klein_four-group * https://en.wikipedia.org/wiki/Alternating_group ## TODO * Prove an `IsKleinFour` group is isomorphic to the normal subgroup of `alternatingGroup (Fin 4)` with the permutation cycles `V = {(), (1 2)(3 4), (1 3)(2 4), (1 4)(2 3)}`. This is the kernel of the surjection of `alternatingGroup (Fin 4)` onto `alternatingGroup (Fin 3) ≃ (ZMod 3)`. In other words, we have the exact sequence `V → A₄ → A₃`. * The outer automorphism group of `A₆` is the Klein four-group `V = (ZMod 2) × (ZMod 2)`, and is related to the outer automorphism of `S₆`. The extra outer automorphism in `A₆` swaps the 3-cycles (like `(1 2 3)`) with elements of shape `3²` (like `(1 2 3)(4 5 6)`). ## Tags non-cyclic abelian group -/ /-! # Klein four-groups as a mixin class -/ /-- An (additive) Klein four-group is an (additive) group of cardinality four and exponent two. -/ class IsAddKleinFour (G : Type*) [AddGroup G] : Prop where card_four : Nat.card G = 4 exponent_two : AddMonoid.exponent G = 2 /-- A Klein four-group is a group of cardinality four and exponent two. -/ @[to_additive existing IsAddKleinFour] class IsKleinFour (G : Type*) [Group G] : Prop where card_four : Nat.card G = 4 exponent_two : Monoid.exponent G = 2 attribute [simp] IsKleinFour.card_four IsKleinFour.exponent_two IsAddKleinFour.card_four IsAddKleinFour.exponent_two instance : IsAddKleinFour (ZMod 2 × ZMod 2) where card_four := by simp exponent_two := by simp [AddMonoid.exponent_prod] instance : IsKleinFour (DihedralGroup 2) where card_four := by simp only [Nat.card_eq_fintype_card]; rfl exponent_two := by simp [DihedralGroup.exponent] instance {G : Type*} [Group G] [IsKleinFour G] : IsAddKleinFour (Additive G) where card_four := by rw [← IsKleinFour.card_four (G := G)]; congr! exponent_two := by simp instance {G : Type*} [AddGroup G] [IsAddKleinFour G] : IsKleinFour (Multiplicative G) where card_four := by rw [← IsAddKleinFour.card_four (G := G)]; congr! exponent_two := by simp namespace IsKleinFour /-- This instance is scoped, because it always applies (which makes linting and typeclass inference potentially *a lot* slower). -/ @[to_additive] scoped instance instFinite {G : Type*} [Group G] [IsKleinFour G] : Finite G := Nat.finite_of_card_ne_zero <| by norm_num [IsKleinFour.card_four] @[to_additive (attr := simp)] lemma card_four' {G : Type*} [Group G] [Fintype G] [IsKleinFour G] : Fintype.card G = 4 := Nat.card_eq_fintype_card (α := G).symm ▸ IsKleinFour.card_four open Finset variable {G : Type*} [Group G] [IsKleinFour G] @[to_additive] lemma not_isCyclic : ¬IsCyclic G := fun h ↦ by simpa using h.exponent_eq_card @[to_additive] lemma inv_eq_self (x : G) : x⁻¹ = x := inv_eq_self_of_exponent_two (by simp) x /- this is not an appropriate global `simp` lemma for a `Prop`-mixin class. Indeed, if it were then every time Lean sees `·⁻¹` it would try to apply `inv_eq_self` which would trigger type class inference to try and synthesize an `IsKleinFour` instance. -/ scoped[IsKleinFour] attribute [simp] inv_eq_self scoped[IsAddKleinFour] attribute [simp] neg_eq_self @[to_additive] lemma mul_self (x : G) : x * x = 1 := by rw [mul_eq_one_iff_eq_inv, inv_eq_self] @[to_additive] lemma eq_finset_univ [Fintype G] [DecidableEq G] {x y : G} (hx : x ≠ 1) (hy : y ≠ 1) (hxy : x ≠ y) : {x * y, x, y, (1 : G)} = Finset.univ := by apply Finset.eq_univ_of_card rw [card_four'] repeat rw [card_insert_of_not_mem] on_goal 4 => simpa using mul_not_mem_of_exponent_two (by simp) hx hy hxy all_goals simp_all @[to_additive] lemma eq_mul_of_ne_all {x y z : G} (hx : x ≠ 1) (hy : y ≠ 1) (hxy : x ≠ y) (hz : z ≠ 1) (hzx : z ≠ x) (hzy : z ≠ y) : z = x * y := by classical let _ := Fintype.ofFinite G apply eq_of_mem_insert_of_not_mem <| (eq_finset_univ hx hy hxy).symm ▸ mem_univ _ simpa only [mem_singleton, mem_insert, not_or] using ⟨hzx, hzy, hz⟩ variable {G₁ G₂ : Type*} [Group G₁] [Group G₂] [IsKleinFour G₁] /-- An equivalence between an `IsKleinFour` group `G₁` and a group `G₂` of exponent two which sends `1 : G₁` to `1 : G₂` is in fact an isomorphism. -/ @[to_additive "An equivalence between an `IsAddKleinFour` group `G₁` and a group `G₂` of exponent two which sends `0 : G₁` to `0 : G₂` is in fact an isomorphism."] def mulEquiv' (e : G₁ ≃ G₂) (he : e 1 = 1) (h : Monoid.exponent G₂ = 2) : G₁ ≃* G₂ where toEquiv := e map_mul' := by let _inst₁ := Fintype.ofFinite G₁ let _inst₂ := Fintype.ofEquiv G₁ e intro x y by_cases hx : x = 1 <;> by_cases hy : y = 1 all_goals try simp only [hx, hy, mul_one, one_mul, Equiv.toFun_as_coe, he] by_cases hxy : x = y · simp [hxy, mul_self, ← pow_two (e y), h ▸ Monoid.pow_exponent_eq_one (e y), he] · classical have univ₂ : {e (x * y), e x, e y, (1 : G₂)} = Finset.univ := by simpa [map_univ_equiv e, map_insert, he] using congr(Finset.map e.toEmbedding $(eq_finset_univ hx hy hxy)) rw [← Ne, ← e.injective.ne_iff] at hx hy hxy rw [he] at hx hy symm apply eq_of_mem_insert_of_not_mem <| univ₂.symm ▸ mem_univ _ simpa using mul_not_mem_of_exponent_two h hx hy hxy /-- Any two `IsKleinFour` groups are isomorphic via any equivalence which sends the identity of one group to the identity of the other. -/ @[to_additive "Any two `IsAddKleinFour` groups are isomorphic via any equivalence which sends the identity of one group to the identity of the other."] abbrev mulEquiv [IsKleinFour G₂] (e : G₁ ≃ G₂) (he : e 1 = 1) : G₁ ≃* G₂ := mulEquiv' e he exponent_two
/-- Any two `IsKleinFour` groups are isomorphic. -/ @[to_additive "Any two `IsAddKleinFour` groups are isomorphic."] lemma nonempty_mulEquiv [IsKleinFour G₂] : Nonempty (G₁ ≃* G₂) := by classical let _inst₁ := Fintype.ofFinite G₁ let _inst₁ := Fintype.ofFinite G₂ exact ⟨mulEquiv ((Fintype.equivOfCardEq <| by simp).setValue 1 1) <| by simp⟩
Mathlib/GroupTheory/SpecificGroups/KleinFour.lean
159
165
/- Copyright (c) 2024 Raghuram Sundararajan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Raghuram Sundararajan -/ import Mathlib.Algebra.Ring.Defs import Mathlib.Algebra.Group.Ext /-! # Extensionality lemmas for rings and similar structures In this file we prove extensionality lemmas for the ring-like structures defined in `Mathlib/Algebra/Ring/Defs.lean`, ranging from `NonUnitalNonAssocSemiring` to `CommRing`. These extensionality lemmas take the form of asserting that two algebraic structures on a type are equal whenever the addition and multiplication defined by them are both the same. ## Implementation details We follow `Mathlib/Algebra/Group/Ext.lean` in using the term `(letI := i; HMul.hMul : R → R → R)` to refer to the multiplication specified by a typeclass instance `i` on a type `R` (and similarly for addition). We abbreviate these using some local notations. Since `Mathlib/Algebra/Group/Ext.lean` proved several injectivity lemmas, we do so as well — even if sometimes we don't need them to prove extensionality. ## Tags semiring, ring, extensionality -/ local macro:max "local_hAdd[" type:term ", " inst:term "]" : term => `(term| (letI := $inst; HAdd.hAdd : $type → $type → $type)) local macro:max "local_hMul[" type:term ", " inst:term "]" : term => `(term| (letI := $inst; HMul.hMul : $type → $type → $type)) universe u variable {R : Type u} /-! ### Distrib -/ namespace Distrib @[ext] theorem ext ⦃inst₁ inst₂ : Distrib R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by -- Split into `add` and `mul` functions and properties. rcases inst₁ with @⟨⟨⟩, ⟨⟩⟩ rcases inst₂ with @⟨⟨⟩, ⟨⟩⟩ -- Prove equality of parts using function extensionality. congr end Distrib /-! ### NonUnitalNonAssocSemiring -/ namespace NonUnitalNonAssocSemiring @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalNonAssocSemiring R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by -- Split into `AddMonoid` instance, `mul` function and properties. rcases inst₁ with @⟨_, ⟨⟩⟩ rcases inst₂ with @⟨_, ⟨⟩⟩ -- Prove equality of parts using already-proved extensionality lemmas. congr; ext : 1; assumption theorem toDistrib_injective : Function.Injective (@toDistrib R) := by intro _ _ h ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h end NonUnitalNonAssocSemiring /-! ### NonUnitalSemiring -/ namespace NonUnitalSemiring theorem toNonUnitalNonAssocSemiring_injective : Function.Injective (@toNonUnitalNonAssocSemiring R) := by rintro ⟨⟩ ⟨⟩ _; congr @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalSemiring R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := toNonUnitalNonAssocSemiring_injective <| NonUnitalNonAssocSemiring.ext h_add h_mul end NonUnitalSemiring /-! ### NonAssocSemiring and its ancestors This section also includes results for `AddMonoidWithOne`, `AddCommMonoidWithOne`, etc. as these are considered implementation detail of the ring classes. TODO consider relocating these lemmas. -/ /- TODO consider relocating these lemmas. -/ @[ext] theorem AddMonoidWithOne.ext ⦃inst₁ inst₂ : AddMonoidWithOne R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_one : (letI := inst₁; One.one : R) = (letI := inst₂; One.one : R)) : inst₁ = inst₂ := by have h_monoid : inst₁.toAddMonoid = inst₂.toAddMonoid := by ext : 1; exact h_add have h_zero' : inst₁.toZero = inst₂.toZero := congrArg (·.toZero) h_monoid have h_one' : inst₁.toOne = inst₂.toOne := congrArg One.mk h_one have h_natCast : inst₁.toNatCast.natCast = inst₂.toNatCast.natCast := by funext n; induction n with | zero => rewrite [inst₁.natCast_zero, inst₂.natCast_zero] exact congrArg (@Zero.zero R) h_zero' | succ n h => rw [inst₁.natCast_succ, inst₂.natCast_succ, h_add] exact congrArg₂ _ h h_one rcases inst₁ with @⟨⟨⟩⟩; rcases inst₂ with @⟨⟨⟩⟩ congr theorem AddCommMonoidWithOne.toAddMonoidWithOne_injective : Function.Injective (@AddCommMonoidWithOne.toAddMonoidWithOne R) := by rintro ⟨⟩ ⟨⟩ _; congr @[ext] theorem AddCommMonoidWithOne.ext ⦃inst₁ inst₂ : AddCommMonoidWithOne R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_one : (letI := inst₁; One.one : R) = (letI := inst₂; One.one : R)) : inst₁ = inst₂ := AddCommMonoidWithOne.toAddMonoidWithOne_injective <| AddMonoidWithOne.ext h_add h_one namespace NonAssocSemiring /- The best place to prove that the `NatCast` is determined by the other operations is probably in an extensionality lemma for `AddMonoidWithOne`, in which case we may as well do the typeclasses defined in `Mathlib/Algebra/GroupWithZero/Defs.lean` as well. -/ @[ext] theorem ext ⦃inst₁ inst₂ : NonAssocSemiring R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by have h : inst₁.toNonUnitalNonAssocSemiring = inst₂.toNonUnitalNonAssocSemiring := by ext : 1 <;> assumption have h_zero : (inst₁.toMulZeroClass).toZero.zero = (inst₂.toMulZeroClass).toZero.zero := congrArg (fun inst => (inst.toMulZeroClass).toZero.zero) h have h_one' : (inst₁.toMulZeroOneClass).toMulOneClass.toOne = (inst₂.toMulZeroOneClass).toMulOneClass.toOne := congrArg (@MulOneClass.toOne R) <| by ext : 1; exact h_mul have h_one : (inst₁.toMulZeroOneClass).toMulOneClass.toOne.one = (inst₂.toMulZeroOneClass).toMulOneClass.toOne.one := congrArg (@One.one R) h_one' have : inst₁.toAddCommMonoidWithOne = inst₂.toAddCommMonoidWithOne := by ext : 1 <;> assumption have : inst₁.toNatCast = inst₂.toNatCast := congrArg (·.toNatCast) this -- Split into `NonUnitalNonAssocSemiring`, `One` and `natCast` instances. cases inst₁; cases inst₂ congr theorem toNonUnitalNonAssocSemiring_injective : Function.Injective (@toNonUnitalNonAssocSemiring R) := by intro _ _ _ ext <;> congr end NonAssocSemiring /-! ### NonUnitalNonAssocRing -/ namespace NonUnitalNonAssocRing @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalNonAssocRing R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by -- Split into `AddCommGroup` instance, `mul` function and properties. rcases inst₁ with @⟨_, ⟨⟩⟩; rcases inst₂ with @⟨_, ⟨⟩⟩ congr; (ext : 1; assumption) theorem toNonUnitalNonAssocSemiring_injective : Function.Injective (@toNonUnitalNonAssocSemiring R) := by intro _ _ h -- Use above extensionality lemma to prove injectivity by showing that `h_add` and `h_mul` hold. ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h end NonUnitalNonAssocRing /-! ### NonUnitalRing -/ namespace NonUnitalRing @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalRing R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by have : inst₁.toNonUnitalNonAssocRing = inst₂.toNonUnitalNonAssocRing := by ext : 1 <;> assumption -- Split into fields and prove they are equal using the above. cases inst₁; cases inst₂ congr theorem toNonUnitalSemiring_injective : Function.Injective (@toNonUnitalSemiring R) := by intro _ _ h ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h theorem toNonUnitalNonAssocring_injective : Function.Injective (@toNonUnitalNonAssocRing R) := by intro _ _ _ ext <;> congr end NonUnitalRing /-! ### NonAssocRing and its ancestors This section also includes results for `AddGroupWithOne`, `AddCommGroupWithOne`, etc. as these are considered implementation detail of the ring classes. TODO consider relocating these lemmas. -/ @[ext] theorem AddGroupWithOne.ext ⦃inst₁ inst₂ : AddGroupWithOne R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_one : (letI := inst₁; One.one : R) = (letI := inst₂; One.one)) : inst₁ = inst₂ := by have : inst₁.toAddMonoidWithOne = inst₂.toAddMonoidWithOne := AddMonoidWithOne.ext h_add h_one have : inst₁.toNatCast = inst₂.toNatCast := congrArg (·.toNatCast) this have h_group : inst₁.toAddGroup = inst₂.toAddGroup := by ext : 1; exact h_add -- Extract equality of necessary substructures from h_group injection h_group with h_group; injection h_group have : inst₁.toIntCast.intCast = inst₂.toIntCast.intCast := by funext n; cases n with | ofNat n => rewrite [Int.ofNat_eq_coe, inst₁.intCast_ofNat, inst₂.intCast_ofNat]; congr | negSucc n => rewrite [inst₁.intCast_negSucc, inst₂.intCast_negSucc]; congr rcases inst₁ with @⟨⟨⟩⟩; rcases inst₂ with @⟨⟨⟩⟩ congr @[ext] theorem AddCommGroupWithOne.ext ⦃inst₁ inst₂ : AddCommGroupWithOne R⦄
(h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_one : (letI := inst₁; One.one : R) = (letI := inst₂; One.one)) : inst₁ = inst₂ := by have : inst₁.toAddCommGroup = inst₂.toAddCommGroup :=
Mathlib/Algebra/Ring/Ext.lean
231
234
/- Copyright (c) 2018 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Markus Himmel -/ import Mathlib.CategoryTheory.EpiMono import Mathlib.CategoryTheory.Limits.HasLimits /-! # Equalizers and coequalizers This file defines (co)equalizers as special cases of (co)limits. An equalizer is the categorical generalization of the subobject {a ∈ A | f(a) = g(a)} known from abelian groups or modules. It is a limit cone over the diagram formed by `f` and `g`. A coequalizer is the dual concept. ## Main definitions * `WalkingParallelPair` is the indexing category used for (co)equalizer_diagrams * `parallelPair` is a functor from `WalkingParallelPair` to our category `C`. * a `fork` is a cone over a parallel pair. * there is really only one interesting morphism in a fork: the arrow from the vertex of the fork to the domain of f and g. It is called `fork.ι`. * an `equalizer` is now just a `limit (parallelPair f g)` Each of these has a dual. ## Main statements * `equalizer.ι_mono` states that every equalizer map is a monomorphism * `isIso_limit_cone_parallelPair_of_self` states that the identity on the domain of `f` is an equalizer of `f` and `f`. ## Implementation notes As with the other special shapes in the limits library, all the definitions here are given as `abbreviation`s of the general statements for limits, so all the `simp` lemmas and theorems about general limits can be used. ## References * [F. Borceux, *Handbook of Categorical Algebra 1*][borceux-vol1] -/ section open CategoryTheory Opposite namespace CategoryTheory.Limits universe v v₂ u u₂ /-- The type of objects for the diagram indexing a (co)equalizer. -/ inductive WalkingParallelPair : Type | zero | one deriving DecidableEq, Inhabited open WalkingParallelPair -- Don't generate unnecessary `sizeOf_spec` lemma which the `simpNF` linter will complain about. set_option genSizeOfSpec false in /-- The type family of morphisms for the diagram indexing a (co)equalizer. -/ inductive WalkingParallelPairHom : WalkingParallelPair → WalkingParallelPair → Type | left : WalkingParallelPairHom zero one | right : WalkingParallelPairHom zero one | id (X : WalkingParallelPair) : WalkingParallelPairHom X X deriving DecidableEq /-- Satisfying the inhabited linter -/ instance : Inhabited (WalkingParallelPairHom zero one) where default := WalkingParallelPairHom.left open WalkingParallelPairHom /-- Composition of morphisms in the indexing diagram for (co)equalizers. -/ def WalkingParallelPairHom.comp : -- Porting note: changed X Y Z to implicit to match comp fields in precategory ∀ {X Y Z : WalkingParallelPair} (_ : WalkingParallelPairHom X Y) (_ : WalkingParallelPairHom Y Z), WalkingParallelPairHom X Z | _, _, _, id _, h => h | _, _, _, left, id one => left | _, _, _, right, id one => right -- Porting note: adding these since they are simple and aesop couldn't directly prove them theorem WalkingParallelPairHom.id_comp {X Y : WalkingParallelPair} (g : WalkingParallelPairHom X Y) : comp (id X) g = g := rfl theorem WalkingParallelPairHom.comp_id {X Y : WalkingParallelPair} (f : WalkingParallelPairHom X Y) : comp f (id Y) = f := by cases f <;> rfl theorem WalkingParallelPairHom.assoc {X Y Z W : WalkingParallelPair} (f : WalkingParallelPairHom X Y) (g : WalkingParallelPairHom Y Z) (h : WalkingParallelPairHom Z W) : comp (comp f g) h = comp f (comp g h) := by cases f <;> cases g <;> cases h <;> rfl instance walkingParallelPairHomCategory : SmallCategory WalkingParallelPair where Hom := WalkingParallelPairHom id := id comp := comp comp_id := comp_id id_comp := id_comp assoc := assoc @[simp] theorem walkingParallelPairHom_id (X : WalkingParallelPair) : WalkingParallelPairHom.id X = 𝟙 X := rfl /-- The functor `WalkingParallelPair ⥤ WalkingParallelPairᵒᵖ` sending left to left and right to right. -/ def walkingParallelPairOp : WalkingParallelPair ⥤ WalkingParallelPairᵒᵖ where obj x := op <| by cases x; exacts [one, zero] map f := by cases f <;> apply Quiver.Hom.op exacts [left, right, WalkingParallelPairHom.id _] map_comp := by rintro _ _ _ (_|_|_) g <;> cases g <;> rfl @[simp] theorem walkingParallelPairOp_zero : walkingParallelPairOp.obj zero = op one := rfl @[simp] theorem walkingParallelPairOp_one : walkingParallelPairOp.obj one = op zero := rfl @[simp] theorem walkingParallelPairOp_left : walkingParallelPairOp.map left = @Quiver.Hom.op _ _ zero one left := rfl @[simp] theorem walkingParallelPairOp_right : walkingParallelPairOp.map right = @Quiver.Hom.op _ _ zero one right := rfl /-- The equivalence `WalkingParallelPair ⥤ WalkingParallelPairᵒᵖ` sending left to left and right to right. -/ @[simps functor inverse] def walkingParallelPairOpEquiv : WalkingParallelPair ≌ WalkingParallelPairᵒᵖ where functor := walkingParallelPairOp inverse := walkingParallelPairOp.leftOp unitIso := NatIso.ofComponents (fun j => eqToIso (by cases j <;> rfl)) (by rintro _ _ (_ | _ | _) <;> simp) counitIso := NatIso.ofComponents (fun j => eqToIso (by induction' j with X cases X <;> rfl)) (fun {i} {j} f => by induction' i with i induction' j with j let g := f.unop have : f = g.op := rfl rw [this] cases i <;> cases j <;> cases g <;> rfl) functor_unitIso_comp := fun j => by cases j <;> rfl @[simp] theorem walkingParallelPairOpEquiv_unitIso_zero : walkingParallelPairOpEquiv.unitIso.app zero = Iso.refl zero := rfl @[simp] theorem walkingParallelPairOpEquiv_unitIso_one : walkingParallelPairOpEquiv.unitIso.app one = Iso.refl one := rfl @[simp] theorem walkingParallelPairOpEquiv_counitIso_zero : walkingParallelPairOpEquiv.counitIso.app (op zero) = Iso.refl (op zero) := rfl @[simp] theorem walkingParallelPairOpEquiv_counitIso_one : walkingParallelPairOpEquiv.counitIso.app (op one) = Iso.refl (op one) := rfl variable {C : Type u} [Category.{v} C] variable {X Y : C} /-- `parallelPair f g` is the diagram in `C` consisting of the two morphisms `f` and `g` with common domain and codomain. -/ def parallelPair (f g : X ⟶ Y) : WalkingParallelPair ⥤ C where obj x := match x with | zero => X | one => Y map h := match h with | WalkingParallelPairHom.id _ => 𝟙 _ | left => f | right => g -- `sorry` can cope with this, but it's too slow: map_comp := by rintro _ _ _ ⟨⟩ g <;> cases g <;> {dsimp; simp} @[simp] theorem parallelPair_obj_zero (f g : X ⟶ Y) : (parallelPair f g).obj zero = X := rfl @[simp] theorem parallelPair_obj_one (f g : X ⟶ Y) : (parallelPair f g).obj one = Y := rfl @[simp] theorem parallelPair_map_left (f g : X ⟶ Y) : (parallelPair f g).map left = f := rfl @[simp] theorem parallelPair_map_right (f g : X ⟶ Y) : (parallelPair f g).map right = g := rfl @[simp] theorem parallelPair_functor_obj {F : WalkingParallelPair ⥤ C} (j : WalkingParallelPair) : (parallelPair (F.map left) (F.map right)).obj j = F.obj j := by cases j <;> rfl /-- Every functor indexing a (co)equalizer is naturally isomorphic (actually, equal) to a `parallelPair` -/ @[simps!] def diagramIsoParallelPair (F : WalkingParallelPair ⥤ C) : F ≅ parallelPair (F.map left) (F.map right) := NatIso.ofComponents (fun j => eqToIso <| by cases j <;> rfl) (by rintro _ _ (_|_|_) <;> simp) /-- Construct a morphism between parallel pairs. -/ def parallelPairHom {X' Y' : C} (f g : X ⟶ Y) (f' g' : X' ⟶ Y') (p : X ⟶ X') (q : Y ⟶ Y') (wf : f ≫ q = p ≫ f') (wg : g ≫ q = p ≫ g') : parallelPair f g ⟶ parallelPair f' g' where app j := match j with | zero => p | one => q naturality := by rintro _ _ ⟨⟩ <;> {dsimp; simp [wf,wg]} @[simp] theorem parallelPairHom_app_zero {X' Y' : C} (f g : X ⟶ Y) (f' g' : X' ⟶ Y') (p : X ⟶ X') (q : Y ⟶ Y') (wf : f ≫ q = p ≫ f') (wg : g ≫ q = p ≫ g') : (parallelPairHom f g f' g' p q wf wg).app zero = p := rfl @[simp] theorem parallelPairHom_app_one {X' Y' : C} (f g : X ⟶ Y) (f' g' : X' ⟶ Y') (p : X ⟶ X') (q : Y ⟶ Y') (wf : f ≫ q = p ≫ f') (wg : g ≫ q = p ≫ g') : (parallelPairHom f g f' g' p q wf wg).app one = q := rfl /-- Construct a natural isomorphism between functors out of the walking parallel pair from its components. -/ @[simps!] def parallelPair.ext {F G : WalkingParallelPair ⥤ C} (zero : F.obj zero ≅ G.obj zero) (one : F.obj one ≅ G.obj one) (left : F.map left ≫ one.hom = zero.hom ≫ G.map left) (right : F.map right ≫ one.hom = zero.hom ≫ G.map right) : F ≅ G := NatIso.ofComponents (by rintro ⟨j⟩ exacts [zero, one]) (by rintro _ _ ⟨_⟩ <;> simp [left, right]) /-- Construct a natural isomorphism between `parallelPair f g` and `parallelPair f' g'` given equalities `f = f'` and `g = g'`. -/ @[simps!] def parallelPair.eqOfHomEq {f g f' g' : X ⟶ Y} (hf : f = f') (hg : g = g') : parallelPair f g ≅ parallelPair f' g' := parallelPair.ext (Iso.refl _) (Iso.refl _) (by simp [hf]) (by simp [hg]) /-- A fork on `f` and `g` is just a `Cone (parallelPair f g)`. -/ abbrev Fork (f g : X ⟶ Y) := Cone (parallelPair f g) /-- A cofork on `f` and `g` is just a `Cocone (parallelPair f g)`. -/ abbrev Cofork (f g : X ⟶ Y) := Cocone (parallelPair f g) variable {f g : X ⟶ Y} /-- A fork `t` on the parallel pair `f g : X ⟶ Y` consists of two morphisms `t.π.app zero : t.pt ⟶ X` and `t.π.app one : t.pt ⟶ Y`. Of these, only the first one is interesting, and we give it the shorter name `Fork.ι t`. -/ def Fork.ι (t : Fork f g) := t.π.app zero @[simp] theorem Fork.app_zero_eq_ι (t : Fork f g) : t.π.app zero = t.ι := rfl /-- A cofork `t` on the parallelPair `f g : X ⟶ Y` consists of two morphisms `t.ι.app zero : X ⟶ t.pt` and `t.ι.app one : Y ⟶ t.pt`. Of these, only the second one is interesting, and we give it the shorter name `Cofork.π t`. -/ def Cofork.π (t : Cofork f g) := t.ι.app one @[simp] theorem Cofork.app_one_eq_π (t : Cofork f g) : t.ι.app one = t.π := rfl @[simp] theorem Fork.app_one_eq_ι_comp_left (s : Fork f g) : s.π.app one = s.ι ≫ f := by rw [← s.app_zero_eq_ι, ← s.w left, parallelPair_map_left] @[reassoc] theorem Fork.app_one_eq_ι_comp_right (s : Fork f g) : s.π.app one = s.ι ≫ g := by rw [← s.app_zero_eq_ι, ← s.w right, parallelPair_map_right] @[simp] theorem Cofork.app_zero_eq_comp_π_left (s : Cofork f g) : s.ι.app zero = f ≫ s.π := by rw [← s.app_one_eq_π, ← s.w left, parallelPair_map_left] @[reassoc] theorem Cofork.app_zero_eq_comp_π_right (s : Cofork f g) : s.ι.app zero = g ≫ s.π := by rw [← s.app_one_eq_π, ← s.w right, parallelPair_map_right] /-- A fork on `f g : X ⟶ Y` is determined by the morphism `ι : P ⟶ X` satisfying `ι ≫ f = ι ≫ g`. -/ @[simps] def Fork.ofι {P : C} (ι : P ⟶ X) (w : ι ≫ f = ι ≫ g) : Fork f g where pt := P π := { app := fun X => by cases X · exact ι · exact ι ≫ f naturality := fun {X} {Y} f => by cases X <;> cases Y <;> cases f <;> dsimp <;> simp; assumption } /-- A cofork on `f g : X ⟶ Y` is determined by the morphism `π : Y ⟶ P` satisfying `f ≫ π = g ≫ π`. -/ @[simps] def Cofork.ofπ {P : C} (π : Y ⟶ P) (w : f ≫ π = g ≫ π) : Cofork f g where pt := P ι := { app := fun X => WalkingParallelPair.casesOn X (f ≫ π) π naturality := fun i j f => by cases f <;> dsimp <;> simp [w] } -- See note [dsimp, simp] @[simp] theorem Fork.ι_ofι {P : C} (ι : P ⟶ X) (w : ι ≫ f = ι ≫ g) : (Fork.ofι ι w).ι = ι := rfl @[simp] theorem Cofork.π_ofπ {P : C} (π : Y ⟶ P) (w : f ≫ π = g ≫ π) : (Cofork.ofπ π w).π = π := rfl @[reassoc (attr := simp)] theorem Fork.condition (t : Fork f g) : t.ι ≫ f = t.ι ≫ g := by rw [← t.app_one_eq_ι_comp_left, ← t.app_one_eq_ι_comp_right] @[reassoc (attr := simp)] theorem Cofork.condition (t : Cofork f g) : f ≫ t.π = g ≫ t.π := by rw [← t.app_zero_eq_comp_π_left, ← t.app_zero_eq_comp_π_right] /-- To check whether two maps are equalized by both maps of a fork, it suffices to check it for the first map -/ theorem Fork.equalizer_ext (s : Fork f g) {W : C} {k l : W ⟶ s.pt} (h : k ≫ s.ι = l ≫ s.ι) : ∀ j : WalkingParallelPair, k ≫ s.π.app j = l ≫ s.π.app j | zero => h | one => by have : k ≫ ι s ≫ f = l ≫ ι s ≫ f := by simp only [← Category.assoc]; exact congrArg (· ≫ f) h rw [s.app_one_eq_ι_comp_left, this] /-- To check whether two maps are coequalized by both maps of a cofork, it suffices to check it for the second map -/ theorem Cofork.coequalizer_ext (s : Cofork f g) {W : C} {k l : s.pt ⟶ W} (h : Cofork.π s ≫ k = Cofork.π s ≫ l) : ∀ j : WalkingParallelPair, s.ι.app j ≫ k = s.ι.app j ≫ l | zero => by simp only [s.app_zero_eq_comp_π_left, Category.assoc, h] | one => h theorem Fork.IsLimit.hom_ext {s : Fork f g} (hs : IsLimit s) {W : C} {k l : W ⟶ s.pt} (h : k ≫ Fork.ι s = l ≫ Fork.ι s) : k = l := hs.hom_ext <| Fork.equalizer_ext _ h theorem Cofork.IsColimit.hom_ext {s : Cofork f g} (hs : IsColimit s) {W : C} {k l : s.pt ⟶ W} (h : Cofork.π s ≫ k = Cofork.π s ≫ l) : k = l := hs.hom_ext <| Cofork.coequalizer_ext _ h @[reassoc (attr := simp)] theorem Fork.IsLimit.lift_ι {s t : Fork f g} (hs : IsLimit s) : hs.lift t ≫ s.ι = t.ι := hs.fac _ _ @[reassoc (attr := simp)] theorem Cofork.IsColimit.π_desc {s t : Cofork f g} (hs : IsColimit s) : s.π ≫ hs.desc t = t.π := hs.fac _ _ -- Porting note: `Fork.IsLimit.lift` was added in order to ease the port /-- If `s` is a limit fork over `f` and `g`, then a morphism `k : W ⟶ X` satisfying `k ≫ f = k ≫ g` induces a morphism `l : W ⟶ s.pt` such that `l ≫ fork.ι s = k`. -/ def Fork.IsLimit.lift {s : Fork f g} (hs : IsLimit s) {W : C} (k : W ⟶ X) (h : k ≫ f = k ≫ g) : W ⟶ s.pt := hs.lift (Fork.ofι _ h) @[reassoc (attr := simp)] lemma Fork.IsLimit.lift_ι' {s : Fork f g} (hs : IsLimit s) {W : C} (k : W ⟶ X) (h : k ≫ f = k ≫ g) : Fork.IsLimit.lift hs k h ≫ Fork.ι s = k := hs.fac _ _ /-- If `s` is a limit fork over `f` and `g`, then a morphism `k : W ⟶ X` satisfying `k ≫ f = k ≫ g` induces a morphism `l : W ⟶ s.pt` such that `l ≫ fork.ι s = k`. -/ def Fork.IsLimit.lift' {s : Fork f g} (hs : IsLimit s) {W : C} (k : W ⟶ X) (h : k ≫ f = k ≫ g) : { l : W ⟶ s.pt // l ≫ Fork.ι s = k } := ⟨Fork.IsLimit.lift hs k h, by simp⟩ -- Porting note: `Cofork.IsColimit.desc` was added in order to ease the port /-- If `s` is a colimit cofork over `f` and `g`, then a morphism `k : Y ⟶ W` satisfying `f ≫ k = g ≫ k` induces a morphism `l : s.pt ⟶ W` such that `cofork.π s ≫ l = k`. -/ def Cofork.IsColimit.desc {s : Cofork f g} (hs : IsColimit s) {W : C} (k : Y ⟶ W) (h : f ≫ k = g ≫ k) : s.pt ⟶ W := hs.desc (Cofork.ofπ _ h) @[reassoc (attr := simp)] lemma Cofork.IsColimit.π_desc' {s : Cofork f g} (hs : IsColimit s) {W : C} (k : Y ⟶ W) (h : f ≫ k = g ≫ k) : Cofork.π s ≫ Cofork.IsColimit.desc hs k h = k := hs.fac _ _ /-- If `s` is a colimit cofork over `f` and `g`, then a morphism `k : Y ⟶ W` satisfying `f ≫ k = g ≫ k` induces a morphism `l : s.pt ⟶ W` such that `cofork.π s ≫ l = k`. -/ def Cofork.IsColimit.desc' {s : Cofork f g} (hs : IsColimit s) {W : C} (k : Y ⟶ W) (h : f ≫ k = g ≫ k) : { l : s.pt ⟶ W // Cofork.π s ≫ l = k } := ⟨Cofork.IsColimit.desc hs k h, by simp⟩ theorem Fork.IsLimit.existsUnique {s : Fork f g} (hs : IsLimit s) {W : C} (k : W ⟶ X) (h : k ≫ f = k ≫ g) : ∃! l : W ⟶ s.pt, l ≫ Fork.ι s = k := ⟨hs.lift <| Fork.ofι _ h, hs.fac _ _, fun _ hm => Fork.IsLimit.hom_ext hs <| hm.symm ▸ (hs.fac (Fork.ofι _ h) WalkingParallelPair.zero).symm⟩ theorem Cofork.IsColimit.existsUnique {s : Cofork f g} (hs : IsColimit s) {W : C} (k : Y ⟶ W) (h : f ≫ k = g ≫ k) : ∃! d : s.pt ⟶ W, Cofork.π s ≫ d = k := ⟨hs.desc <| Cofork.ofπ _ h, hs.fac _ _, fun _ hm => Cofork.IsColimit.hom_ext hs <| hm.symm ▸ (hs.fac (Cofork.ofπ _ h) WalkingParallelPair.one).symm⟩ /-- This is a slightly more convenient method to verify that a fork is a limit cone. It only asks for a proof of facts that carry any mathematical content -/ @[simps] def Fork.IsLimit.mk (t : Fork f g) (lift : ∀ s : Fork f g, s.pt ⟶ t.pt) (fac : ∀ s : Fork f g, lift s ≫ Fork.ι t = Fork.ι s) (uniq : ∀ (s : Fork f g) (m : s.pt ⟶ t.pt) (_ : m ≫ t.ι = s.ι), m = lift s) : IsLimit t := { lift fac := fun s j => WalkingParallelPair.casesOn j (fac s) <| by erw [← s.w left, ← t.w left, ← Category.assoc, fac]; rfl uniq := fun s m j => by aesop} /-- This is another convenient method to verify that a fork is a limit cone. It only asks for a proof of facts that carry any mathematical content, and allows access to the same `s` for all parts. -/ def Fork.IsLimit.mk' {X Y : C} {f g : X ⟶ Y} (t : Fork f g) (create : ∀ s : Fork f g, { l // l ≫ t.ι = s.ι ∧ ∀ {m}, m ≫ t.ι = s.ι → m = l }) : IsLimit t := Fork.IsLimit.mk t (fun s => (create s).1) (fun s => (create s).2.1) fun s _ w => (create s).2.2 w /-- This is a slightly more convenient method to verify that a cofork is a colimit cocone. It only asks for a proof of facts that carry any mathematical content -/ def Cofork.IsColimit.mk (t : Cofork f g) (desc : ∀ s : Cofork f g, t.pt ⟶ s.pt) (fac : ∀ s : Cofork f g, Cofork.π t ≫ desc s = Cofork.π s) (uniq : ∀ (s : Cofork f g) (m : t.pt ⟶ s.pt) (_ : t.π ≫ m = s.π), m = desc s) : IsColimit t := { desc fac := fun s j => WalkingParallelPair.casesOn j (by erw [← s.w left, ← t.w left, Category.assoc, fac]; rfl) (fac s) uniq := by aesop } /-- This is another convenient method to verify that a fork is a limit cone. It only asks for a proof of facts that carry any mathematical content, and allows access to the same `s` for all parts. -/ def Cofork.IsColimit.mk' {X Y : C} {f g : X ⟶ Y} (t : Cofork f g) (create : ∀ s : Cofork f g, { l : t.pt ⟶ s.pt // t.π ≫ l = s.π ∧ ∀ {m}, t.π ≫ m = s.π → m = l }) : IsColimit t := Cofork.IsColimit.mk t (fun s => (create s).1) (fun s => (create s).2.1) fun s _ w => (create s).2.2 w /-- Noncomputably make a limit cone from the existence of unique factorizations. -/ noncomputable def Fork.IsLimit.ofExistsUnique {t : Fork f g} (hs : ∀ s : Fork f g, ∃! l : s.pt ⟶ t.pt, l ≫ Fork.ι t = Fork.ι s) : IsLimit t := by choose d hd hd' using hs exact Fork.IsLimit.mk _ d hd fun s m hm => hd' _ _ hm /-- Noncomputably make a colimit cocone from the existence of unique factorizations. -/ noncomputable def Cofork.IsColimit.ofExistsUnique {t : Cofork f g} (hs : ∀ s : Cofork f g, ∃! d : t.pt ⟶ s.pt, Cofork.π t ≫ d = Cofork.π s) : IsColimit t := by choose d hd hd' using hs exact Cofork.IsColimit.mk _ d hd fun s m hm => hd' _ _ hm /-- Given a limit cone for the pair `f g : X ⟶ Y`, for any `Z`, morphisms from `Z` to its point are in bijection with morphisms `h : Z ⟶ X` such that `h ≫ f = h ≫ g`. Further, this bijection is natural in `Z`: see `Fork.IsLimit.homIso_natural`. This is a special case of `IsLimit.homIso'`, often useful to construct adjunctions. -/ @[simps] def Fork.IsLimit.homIso {X Y : C} {f g : X ⟶ Y} {t : Fork f g} (ht : IsLimit t) (Z : C) : (Z ⟶ t.pt) ≃ { h : Z ⟶ X // h ≫ f = h ≫ g } where toFun k := ⟨k ≫ t.ι, by simp only [Category.assoc, t.condition]⟩ invFun h := (Fork.IsLimit.lift' ht _ h.prop).1 left_inv _ := Fork.IsLimit.hom_ext ht (Fork.IsLimit.lift' _ _ _).prop right_inv _ := Subtype.ext (Fork.IsLimit.lift' ht _ _).prop /-- The bijection of `Fork.IsLimit.homIso` is natural in `Z`. -/ theorem Fork.IsLimit.homIso_natural {X Y : C} {f g : X ⟶ Y} {t : Fork f g} (ht : IsLimit t) {Z Z' : C} (q : Z' ⟶ Z) (k : Z ⟶ t.pt) : (Fork.IsLimit.homIso ht _ (q ≫ k) : Z' ⟶ X) = q ≫ (Fork.IsLimit.homIso ht _ k : Z ⟶ X) := Category.assoc _ _ _ /-- Given a colimit cocone for the pair `f g : X ⟶ Y`, for any `Z`, morphisms from the cocone point to `Z` are in bijection with morphisms `h : Y ⟶ Z` such that `f ≫ h = g ≫ h`. Further, this bijection is natural in `Z`: see `Cofork.IsColimit.homIso_natural`. This is a special case of `IsColimit.homIso'`, often useful to construct adjunctions. -/ @[simps] def Cofork.IsColimit.homIso {X Y : C} {f g : X ⟶ Y} {t : Cofork f g} (ht : IsColimit t) (Z : C) : (t.pt ⟶ Z) ≃ { h : Y ⟶ Z // f ≫ h = g ≫ h } where toFun k := ⟨t.π ≫ k, by simp only [← Category.assoc, t.condition]⟩ invFun h := (Cofork.IsColimit.desc' ht _ h.prop).1 left_inv _ := Cofork.IsColimit.hom_ext ht (Cofork.IsColimit.desc' _ _ _).prop right_inv _ := Subtype.ext (Cofork.IsColimit.desc' ht _ _).prop /-- The bijection of `Cofork.IsColimit.homIso` is natural in `Z`. -/ theorem Cofork.IsColimit.homIso_natural {X Y : C} {f g : X ⟶ Y} {t : Cofork f g} {Z Z' : C} (q : Z ⟶ Z') (ht : IsColimit t) (k : t.pt ⟶ Z) : (Cofork.IsColimit.homIso ht _ (k ≫ q) : Y ⟶ Z') = (Cofork.IsColimit.homIso ht _ k : Y ⟶ Z) ≫ q := (Category.assoc _ _ _).symm /-- This is a helper construction that can be useful when verifying that a category has all equalizers. Given `F : WalkingParallelPair ⥤ C`, which is really the same as `parallelPair (F.map left) (F.map right)`, and a fork on `F.map left` and `F.map right`, we get a cone on `F`. If you're thinking about using this, have a look at `hasEqualizers_of_hasLimit_parallelPair`, which you may find to be an easier way of achieving your goal. -/ def Cone.ofFork {F : WalkingParallelPair ⥤ C} (t : Fork (F.map left) (F.map right)) : Cone F where pt := t.pt π := { app := fun X => t.π.app X ≫ eqToHom (by simp) naturality := by rintro _ _ (_|_|_) <;> {dsimp; simp [t.condition]}} /-- This is a helper construction that can be useful when verifying that a category has all coequalizers. Given `F : WalkingParallelPair ⥤ C`, which is really the same as `parallelPair (F.map left) (F.map right)`, and a cofork on `F.map left` and `F.map right`, we get a cocone on `F`. If you're thinking about using this, have a look at `hasCoequalizers_of_hasColimit_parallelPair`, which you may find to be an easier way of achieving your goal. -/ def Cocone.ofCofork {F : WalkingParallelPair ⥤ C} (t : Cofork (F.map left) (F.map right)) : Cocone F where pt := t.pt ι := { app := fun X => eqToHom (by simp) ≫ t.ι.app X naturality := by rintro _ _ (_|_|_) <;> {dsimp; simp [t.condition]}} @[simp] theorem Cone.ofFork_π {F : WalkingParallelPair ⥤ C} (t : Fork (F.map left) (F.map right)) (j) : (Cone.ofFork t).π.app j = t.π.app j ≫ eqToHom (by simp) := rfl @[simp] theorem Cocone.ofCofork_ι {F : WalkingParallelPair ⥤ C} (t : Cofork (F.map left) (F.map right)) (j) : (Cocone.ofCofork t).ι.app j = eqToHom (by simp) ≫ t.ι.app j := rfl /-- Given `F : WalkingParallelPair ⥤ C`, which is really the same as `parallelPair (F.map left) (F.map right)` and a cone on `F`, we get a fork on `F.map left` and `F.map right`. -/ def Fork.ofCone {F : WalkingParallelPair ⥤ C} (t : Cone F) : Fork (F.map left) (F.map right) where pt := t.pt π := { app := fun X => t.π.app X ≫ eqToHom (by simp) naturality := by rintro _ _ (_|_|_) <;> {dsimp; simp}} /-- Given `F : WalkingParallelPair ⥤ C`, which is really the same as `parallelPair (F.map left) (F.map right)` and a cocone on `F`, we get a cofork on `F.map left` and `F.map right`. -/ def Cofork.ofCocone {F : WalkingParallelPair ⥤ C} (t : Cocone F) : Cofork (F.map left) (F.map right) where pt := t.pt ι := { app := fun X => eqToHom (by simp) ≫ t.ι.app X naturality := by rintro _ _ (_|_|_) <;> {dsimp; simp}} @[simp] theorem Fork.ofCone_π {F : WalkingParallelPair ⥤ C} (t : Cone F) (j) : (Fork.ofCone t).π.app j = t.π.app j ≫ eqToHom (by simp) := rfl @[simp] theorem Cofork.ofCocone_ι {F : WalkingParallelPair ⥤ C} (t : Cocone F) (j) : (Cofork.ofCocone t).ι.app j = eqToHom (by simp) ≫ t.ι.app j := rfl @[simp] theorem Fork.ι_postcompose {f' g' : X ⟶ Y} {α : parallelPair f g ⟶ parallelPair f' g'} {c : Fork f g} : Fork.ι ((Cones.postcompose α).obj c) = c.ι ≫ α.app _ := rfl @[simp] theorem Cofork.π_precompose {f' g' : X ⟶ Y} {α : parallelPair f g ⟶ parallelPair f' g'} {c : Cofork f' g'} : Cofork.π ((Cocones.precompose α).obj c) = α.app _ ≫ c.π := rfl /-- Helper function for constructing morphisms between equalizer forks. -/ @[simps] def Fork.mkHom {s t : Fork f g} (k : s.pt ⟶ t.pt) (w : k ≫ t.ι = s.ι) : s ⟶ t where hom := k w := by rintro ⟨_ | _⟩ · exact w · simp only [Fork.app_one_eq_ι_comp_left,← Category.assoc] congr /-- To construct an isomorphism between forks, it suffices to give an isomorphism between the cone points and check that it commutes with the `ι` morphisms. -/ @[simps] def Fork.ext {s t : Fork f g} (i : s.pt ≅ t.pt) (w : i.hom ≫ t.ι = s.ι := by aesop_cat) : s ≅ t where hom := Fork.mkHom i.hom w inv := Fork.mkHom i.inv (by rw [← w, Iso.inv_hom_id_assoc]) /-- Two forks of the form `ofι` are isomorphic whenever their `ι`'s are equal. -/ def ForkOfι.ext {P : C} {ι ι' : P ⟶ X} (w : ι ≫ f = ι ≫ g) (w' : ι' ≫ f = ι' ≫ g) (h : ι = ι') : Fork.ofι ι w ≅ Fork.ofι ι' w' := Fork.ext (Iso.refl _) (by simp [h]) /-- Every fork is isomorphic to one of the form `Fork.of_ι _ _`. -/ def Fork.isoForkOfι (c : Fork f g) : c ≅ Fork.ofι c.ι c.condition := Fork.ext (by simp only [Fork.ofι_pt, Functor.const_obj_obj]; rfl) (by simp) /-- Given two forks with isomorphic components in such a way that the natural diagrams commute, then if one is a limit, then the other one is as well. -/ def Fork.isLimitOfIsos {X' Y' : C} (c : Fork f g) (hc : IsLimit c) {f' g' : X' ⟶ Y'} (c' : Fork f' g') (e₀ : X ≅ X') (e₁ : Y ≅ Y') (e : c.pt ≅ c'.pt) (comm₁ : e₀.hom ≫ f' = f ≫ e₁.hom := by aesop_cat) (comm₂ : e₀.hom ≫ g' = g ≫ e₁.hom := by aesop_cat) (comm₃ : e.hom ≫ c'.ι = c.ι ≫ e₀.hom := by aesop_cat) : IsLimit c' := let i : parallelPair f g ≅ parallelPair f' g' := parallelPair.ext e₀ e₁ comm₁.symm comm₂.symm (IsLimit.equivOfNatIsoOfIso i c c' (Fork.ext e comm₃)) hc /-- Helper function for constructing morphisms between coequalizer coforks. -/ @[simps] def Cofork.mkHom {s t : Cofork f g} (k : s.pt ⟶ t.pt) (w : s.π ≫ k = t.π) : s ⟶ t where hom := k w := by rintro ⟨_ | _⟩ · simp [Cofork.app_zero_eq_comp_π_left, w] · exact w @[reassoc (attr := simp)] theorem Fork.hom_comp_ι {s t : Fork f g} (f : s ⟶ t) : f.hom ≫ t.ι = s.ι := by cases s; cases t; cases f; aesop @[reassoc (attr := simp)] theorem Fork.π_comp_hom {s t : Cofork f g} (f : s ⟶ t) : s.π ≫ f.hom = t.π := by cases s; cases t; cases f; aesop /-- To construct an isomorphism between coforks, it suffices to give an isomorphism between the cocone points and check that it commutes with the `π` morphisms. -/ @[simps] def Cofork.ext {s t : Cofork f g} (i : s.pt ≅ t.pt) (w : s.π ≫ i.hom = t.π := by aesop_cat) : s ≅ t where hom := Cofork.mkHom i.hom w inv := Cofork.mkHom i.inv (by rw [Iso.comp_inv_eq, w]) /-- Every cofork is isomorphic to one of the form `Cofork.ofπ _ _`. -/ def Cofork.isoCoforkOfπ (c : Cofork f g) : c ≅ Cofork.ofπ c.π c.condition := Cofork.ext (by simp only [Cofork.ofπ_pt, Functor.const_obj_obj]; rfl) (by dsimp; simp) variable (f g) section /-- `HasEqualizer f g` represents a particular choice of limiting cone for the parallel pair of morphisms `f` and `g`. -/ abbrev HasEqualizer := HasLimit (parallelPair f g) variable [HasEqualizer f g] /-- If an equalizer of `f` and `g` exists, we can access an arbitrary choice of such by saying `equalizer f g`. -/ noncomputable abbrev equalizer : C := limit (parallelPair f g) /-- If an equalizer of `f` and `g` exists, we can access the inclusion `equalizer f g ⟶ X` by saying `equalizer.ι f g`. -/ noncomputable abbrev equalizer.ι : equalizer f g ⟶ X := limit.π (parallelPair f g) zero /-- An equalizer cone for a parallel pair `f` and `g` -/ noncomputable abbrev equalizer.fork : Fork f g := limit.cone (parallelPair f g) @[simp] theorem equalizer.fork_ι : (equalizer.fork f g).ι = equalizer.ι f g := rfl @[simp] theorem equalizer.fork_π_app_zero : (equalizer.fork f g).π.app zero = equalizer.ι f g := rfl @[reassoc] theorem equalizer.condition : equalizer.ι f g ≫ f = equalizer.ι f g ≫ g := Fork.condition <| limit.cone <| parallelPair f g /-- The equalizer built from `equalizer.ι f g` is limiting. -/ noncomputable def equalizerIsEqualizer : IsLimit (Fork.ofι (equalizer.ι f g) (equalizer.condition f g)) := IsLimit.ofIsoLimit (limit.isLimit _) (Fork.ext (Iso.refl _) (by simp)) variable {f g} /-- A morphism `k : W ⟶ X` satisfying `k ≫ f = k ≫ g` factors through the equalizer of `f` and `g` via `equalizer.lift : W ⟶ equalizer f g`. -/ noncomputable abbrev equalizer.lift {W : C} (k : W ⟶ X) (h : k ≫ f = k ≫ g) : W ⟶ equalizer f g := limit.lift (parallelPair f g) (Fork.ofι k h) @[reassoc] theorem equalizer.lift_ι {W : C} (k : W ⟶ X) (h : k ≫ f = k ≫ g) : equalizer.lift k h ≫ equalizer.ι f g = k := limit.lift_π _ _ /-- A morphism `k : W ⟶ X` satisfying `k ≫ f = k ≫ g` induces a morphism `l : W ⟶ equalizer f g` satisfying `l ≫ equalizer.ι f g = k`. -/ noncomputable def equalizer.lift' {W : C} (k : W ⟶ X) (h : k ≫ f = k ≫ g) : { l : W ⟶ equalizer f g // l ≫ equalizer.ι f g = k } := ⟨equalizer.lift k h, equalizer.lift_ι _ _⟩ /-- Two maps into an equalizer are equal if they are equal when composed with the equalizer map. -/ @[ext] theorem equalizer.hom_ext {W : C} {k l : W ⟶ equalizer f g} (h : k ≫ equalizer.ι f g = l ≫ equalizer.ι f g) : k = l := Fork.IsLimit.hom_ext (limit.isLimit _) h theorem equalizer.existsUnique {W : C} (k : W ⟶ X) (h : k ≫ f = k ≫ g) : ∃! l : W ⟶ equalizer f g, l ≫ equalizer.ι f g = k := Fork.IsLimit.existsUnique (limit.isLimit _) _ h /-- An equalizer morphism is a monomorphism -/ instance equalizer.ι_mono : Mono (equalizer.ι f g) where right_cancellation _ _ w := equalizer.hom_ext w end section variable {f g} /-- The equalizer morphism in any limit cone is a monomorphism. -/ theorem mono_of_isLimit_fork {c : Fork f g} (i : IsLimit c) : Mono (Fork.ι c) := { right_cancellation := fun _ _ w => Fork.IsLimit.hom_ext i w } end section variable {f g} /-- The identity determines a cone on the equalizer diagram of `f` and `g` if `f = g`. -/ def idFork (h : f = g) : Fork f g := Fork.ofι (𝟙 X) <| h ▸ rfl /-- The identity on `X` is an equalizer of `(f, g)`, if `f = g`. -/ def isLimitIdFork (h : f = g) : IsLimit (idFork h) := Fork.IsLimit.mk _ (fun s => Fork.ι s) (fun _ => Category.comp_id _) fun s m h => by convert h exact (Category.comp_id _).symm /-- Every equalizer of `(f, g)`, where `f = g`, is an isomorphism. -/ theorem isIso_limit_cone_parallelPair_of_eq (h₀ : f = g) {c : Fork f g} (h : IsLimit c) : IsIso c.ι := Iso.isIso_hom <| IsLimit.conePointUniqueUpToIso h <| isLimitIdFork h₀ /-- The equalizer of `(f, g)`, where `f = g`, is an isomorphism. -/ theorem equalizer.ι_of_eq [HasEqualizer f g] (h : f = g) : IsIso (equalizer.ι f g) := isIso_limit_cone_parallelPair_of_eq h <| limit.isLimit _ /-- Every equalizer of `(f, f)` is an isomorphism. -/ theorem isIso_limit_cone_parallelPair_of_self {c : Fork f f} (h : IsLimit c) : IsIso c.ι := isIso_limit_cone_parallelPair_of_eq rfl h /-- An equalizer that is an epimorphism is an isomorphism. -/ theorem isIso_limit_cone_parallelPair_of_epi {c : Fork f g} (h : IsLimit c) [Epi c.ι] : IsIso c.ι := isIso_limit_cone_parallelPair_of_eq ((cancel_epi _).1 (Fork.condition c)) h /-- Two morphisms are equal if there is a fork whose inclusion is epi. -/ theorem eq_of_epi_fork_ι (t : Fork f g) [Epi (Fork.ι t)] : f = g := (cancel_epi (Fork.ι t)).1 <| Fork.condition t /-- If the equalizer of two morphisms is an epimorphism, then the two morphisms are equal. -/ theorem eq_of_epi_equalizer [HasEqualizer f g] [Epi (equalizer.ι f g)] : f = g := (cancel_epi (equalizer.ι f g)).1 <| equalizer.condition _ _ end instance hasEqualizer_of_self : HasEqualizer f f := HasLimit.mk { cone := idFork rfl isLimit := isLimitIdFork rfl } /-- The equalizer inclusion for `(f, f)` is an isomorphism. -/ instance equalizer.ι_of_self : IsIso (equalizer.ι f f) := equalizer.ι_of_eq rfl /-- The equalizer of a morphism with itself is isomorphic to the source. -/ noncomputable def equalizer.isoSourceOfSelf : equalizer f f ≅ X := asIso (equalizer.ι f f) @[simp] theorem equalizer.isoSourceOfSelf_hom : (equalizer.isoSourceOfSelf f).hom = equalizer.ι f f := rfl @[simp] theorem equalizer.isoSourceOfSelf_inv : (equalizer.isoSourceOfSelf f).inv = equalizer.lift (𝟙 X) (by simp) := by ext simp [equalizer.isoSourceOfSelf] section /-- `HasCoequalizer f g` represents a particular choice of colimiting cocone for the parallel pair of morphisms `f` and `g`. -/ abbrev HasCoequalizer := HasColimit (parallelPair f g) variable [HasCoequalizer f g] /-- If a coequalizer of `f` and `g` exists, we can access an arbitrary choice of such by saying `coequalizer f g`. -/ noncomputable abbrev coequalizer : C := colimit (parallelPair f g) /-- If a coequalizer of `f` and `g` exists, we can access the corresponding projection by saying `coequalizer.π f g`. -/ noncomputable abbrev coequalizer.π : Y ⟶ coequalizer f g := colimit.ι (parallelPair f g) one /-- An arbitrary choice of coequalizer cocone for a parallel pair `f` and `g`. -/ noncomputable abbrev coequalizer.cofork : Cofork f g := colimit.cocone (parallelPair f g) @[simp] theorem coequalizer.cofork_π : (coequalizer.cofork f g).π = coequalizer.π f g := rfl theorem coequalizer.cofork_ι_app_one : (coequalizer.cofork f g).ι.app one = coequalizer.π f g := rfl @[reassoc] theorem coequalizer.condition : f ≫ coequalizer.π f g = g ≫ coequalizer.π f g := Cofork.condition <| colimit.cocone <| parallelPair f g /-- The cofork built from `coequalizer.π f g` is colimiting. -/ noncomputable def coequalizerIsCoequalizer : IsColimit (Cofork.ofπ (coequalizer.π f g) (coequalizer.condition f g)) := IsColimit.ofIsoColimit (colimit.isColimit _) (Cofork.ext (Iso.refl _) (by simp)) variable {f g} /-- Any morphism `k : Y ⟶ W` satisfying `f ≫ k = g ≫ k` factors through the coequalizer of `f` and `g` via `coequalizer.desc : coequalizer f g ⟶ W`. -/ noncomputable abbrev coequalizer.desc {W : C} (k : Y ⟶ W) (h : f ≫ k = g ≫ k) : coequalizer f g ⟶ W := colimit.desc (parallelPair f g) (Cofork.ofπ k h) @[reassoc] theorem coequalizer.π_desc {W : C} (k : Y ⟶ W) (h : f ≫ k = g ≫ k) : coequalizer.π f g ≫ coequalizer.desc k h = k := colimit.ι_desc _ _ theorem coequalizer.π_colimMap_desc {X' Y' Z : C} (f' g' : X' ⟶ Y') [HasCoequalizer f' g'] (p : X ⟶ X') (q : Y ⟶ Y') (wf : f ≫ q = p ≫ f') (wg : g ≫ q = p ≫ g') (h : Y' ⟶ Z) (wh : f' ≫ h = g' ≫ h) : coequalizer.π f g ≫ colimMap (parallelPairHom f g f' g' p q wf wg) ≫ coequalizer.desc h wh = q ≫ h := by rw [ι_colimMap_assoc, parallelPairHom_app_one, coequalizer.π_desc] /-- Any morphism `k : Y ⟶ W` satisfying `f ≫ k = g ≫ k` induces a morphism `l : coequalizer f g ⟶ W` satisfying `coequalizer.π ≫ g = l`. -/ noncomputable def coequalizer.desc' {W : C} (k : Y ⟶ W) (h : f ≫ k = g ≫ k) : { l : coequalizer f g ⟶ W // coequalizer.π f g ≫ l = k } := ⟨coequalizer.desc k h, coequalizer.π_desc _ _⟩ /-- Two maps from a coequalizer are equal if they are equal when composed with the coequalizer map -/ @[ext] theorem coequalizer.hom_ext {W : C} {k l : coequalizer f g ⟶ W} (h : coequalizer.π f g ≫ k = coequalizer.π f g ≫ l) : k = l := Cofork.IsColimit.hom_ext (colimit.isColimit _) h theorem coequalizer.existsUnique {W : C} (k : Y ⟶ W) (h : f ≫ k = g ≫ k) : ∃! d : coequalizer f g ⟶ W, coequalizer.π f g ≫ d = k := Cofork.IsColimit.existsUnique (colimit.isColimit _) _ h /-- A coequalizer morphism is an epimorphism -/ instance coequalizer.π_epi : Epi (coequalizer.π f g) where left_cancellation _ _ w := coequalizer.hom_ext w end section variable {f g} /-- The coequalizer morphism in any colimit cocone is an epimorphism. -/ theorem epi_of_isColimit_cofork {c : Cofork f g} (i : IsColimit c) : Epi c.π := { left_cancellation := fun _ _ w => Cofork.IsColimit.hom_ext i w } end section variable {f g} /-- The identity determines a cocone on the coequalizer diagram of `f` and `g`, if `f = g`. -/ def idCofork (h : f = g) : Cofork f g := Cofork.ofπ (𝟙 Y) <| h ▸ rfl /-- The identity on `Y` is a coequalizer of `(f, g)`, where `f = g`. -/ def isColimitIdCofork (h : f = g) : IsColimit (idCofork h) := Cofork.IsColimit.mk _ (fun s => Cofork.π s) (fun _ => Category.id_comp _) fun s m h => by convert h exact (Category.id_comp _).symm /-- Every coequalizer of `(f, g)`, where `f = g`, is an isomorphism. -/ theorem isIso_colimit_cocone_parallelPair_of_eq (h₀ : f = g) {c : Cofork f g} (h : IsColimit c) : IsIso c.π := Iso.isIso_hom <| IsColimit.coconePointUniqueUpToIso (isColimitIdCofork h₀) h /-- The coequalizer of `(f, g)`, where `f = g`, is an isomorphism. -/ theorem coequalizer.π_of_eq [HasCoequalizer f g] (h : f = g) : IsIso (coequalizer.π f g) := isIso_colimit_cocone_parallelPair_of_eq h <| colimit.isColimit _ /-- Every coequalizer of `(f, f)` is an isomorphism. -/ theorem isIso_colimit_cocone_parallelPair_of_self {c : Cofork f f} (h : IsColimit c) : IsIso c.π := isIso_colimit_cocone_parallelPair_of_eq rfl h /-- A coequalizer that is a monomorphism is an isomorphism. -/ theorem isIso_limit_cocone_parallelPair_of_epi {c : Cofork f g} (h : IsColimit c) [Mono c.π] : IsIso c.π := isIso_colimit_cocone_parallelPair_of_eq ((cancel_mono _).1 (Cofork.condition c)) h /-- Two morphisms are equal if there is a cofork whose projection is mono. -/ theorem eq_of_mono_cofork_π (t : Cofork f g) [Mono (Cofork.π t)] : f = g := (cancel_mono (Cofork.π t)).1 <| Cofork.condition t /-- If the coequalizer of two morphisms is a monomorphism, then the two morphisms are equal. -/ theorem eq_of_mono_coequalizer [HasCoequalizer f g] [Mono (coequalizer.π f g)] : f = g := (cancel_mono (coequalizer.π f g)).1 <| coequalizer.condition _ _ end instance hasCoequalizer_of_self : HasCoequalizer f f := HasColimit.mk { cocone := idCofork rfl isColimit := isColimitIdCofork rfl } /-- The coequalizer projection for `(f, f)` is an isomorphism. -/ instance coequalizer.π_of_self : IsIso (coequalizer.π f f) := coequalizer.π_of_eq rfl /-- The coequalizer of a morphism with itself is isomorphic to the target. -/ noncomputable def coequalizer.isoTargetOfSelf : coequalizer f f ≅ Y := (asIso (coequalizer.π f f)).symm @[simp] theorem coequalizer.isoTargetOfSelf_hom : (coequalizer.isoTargetOfSelf f).hom = coequalizer.desc (𝟙 Y) (by simp) := by ext simp [coequalizer.isoTargetOfSelf] @[simp] theorem coequalizer.isoTargetOfSelf_inv : (coequalizer.isoTargetOfSelf f).inv = coequalizer.π f f := rfl section Comparison variable {D : Type u₂} [Category.{v₂} D] (G : C ⥤ D) /-- The comparison morphism for the equalizer of `f,g`. This is an isomorphism iff `G` preserves the equalizer of `f,g`; see `CategoryTheory/Limits/Preserves/Shapes/Equalizers.lean` -/ noncomputable def equalizerComparison [HasEqualizer f g] [HasEqualizer (G.map f) (G.map g)] : G.obj (equalizer f g) ⟶ equalizer (G.map f) (G.map g) := equalizer.lift (G.map (equalizer.ι _ _)) (by simp only [← G.map_comp]; rw [equalizer.condition]) @[reassoc (attr := simp)] theorem equalizerComparison_comp_π [HasEqualizer f g] [HasEqualizer (G.map f) (G.map g)] : equalizerComparison f g G ≫ equalizer.ι (G.map f) (G.map g) = G.map (equalizer.ι f g) := equalizer.lift_ι _ _ @[reassoc (attr := simp)] theorem map_lift_equalizerComparison [HasEqualizer f g] [HasEqualizer (G.map f) (G.map g)] {Z : C} {h : Z ⟶ X} (w : h ≫ f = h ≫ g) : G.map (equalizer.lift h w) ≫ equalizerComparison f g G = equalizer.lift (G.map h) (by simp only [← G.map_comp, w]) := by apply equalizer.hom_ext simp [← G.map_comp] /-- The comparison morphism for the coequalizer of `f,g`. -/ noncomputable def coequalizerComparison [HasCoequalizer f g] [HasCoequalizer (G.map f) (G.map g)] : coequalizer (G.map f) (G.map g) ⟶ G.obj (coequalizer f g) := coequalizer.desc (G.map (coequalizer.π _ _))
(by simp only [← G.map_comp]; rw [coequalizer.condition]) @[reassoc (attr := simp)] theorem ι_comp_coequalizerComparison [HasCoequalizer f g] [HasCoequalizer (G.map f) (G.map g)] : coequalizer.π _ _ ≫ coequalizerComparison f g G = G.map (coequalizer.π _ _) := coequalizer.π_desc _ _
Mathlib/CategoryTheory/Limits/Shapes/Equalizers.lean
1,001
1,006
/- 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
Mathlib/Analysis/Convex/Gauge.lean
228
230
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.RingTheory.Ideal.Maps /-! # Ideals in product rings For commutative rings `R` and `S` and ideals `I ≤ R`, `J ≤ S`, we define `Ideal.prod I J` as the product `I × J`, viewed as an ideal of `R × S`. In `ideal_prod_eq` we show that every ideal of `R × S` is of this form. Furthermore, we show that every prime ideal of `R × S` is of the form `p × S` or `R × p`, where `p` is a prime ideal. -/ universe u v variable {R : Type u} {S : Type v} [Semiring R] [Semiring S] (I : Ideal R) (J : Ideal S) namespace Ideal /-- `I × J` as an ideal of `R × S`. -/ def prod : Ideal (R × S) := I.comap (RingHom.fst R S) ⊓ J.comap (RingHom.snd R S) @[simp] theorem mem_prod {r : R} {s : S} : (⟨r, s⟩ : R × S) ∈ prod I J ↔ r ∈ I ∧ s ∈ J := Iff.rfl @[simp] theorem prod_top_top : prod (⊤ : Ideal R) (⊤ : Ideal S) = ⊤ := Ideal.ext <| by simp /-- Every ideal of the product ring is of the form `I × J`, where `I` and `J` can be explicitly given as the image under the projection maps. -/ theorem ideal_prod_eq (I : Ideal (R × S)) : I = Ideal.prod (map (RingHom.fst R S) I : Ideal R) (map (RingHom.snd R S) I) := by apply Ideal.ext rintro ⟨r, s⟩ rw [mem_prod, mem_map_iff_of_surjective (RingHom.fst R S) Prod.fst_surjective, mem_map_iff_of_surjective (RingHom.snd R S) Prod.snd_surjective] refine ⟨fun h => ⟨⟨_, ⟨h, rfl⟩⟩, ⟨_, ⟨h, rfl⟩⟩⟩, ?_⟩ rintro ⟨⟨⟨r, s'⟩, ⟨h₁, rfl⟩⟩, ⟨⟨r', s⟩, ⟨h₂, rfl⟩⟩⟩ simpa using I.add_mem (I.mul_mem_left (1, 0) h₁) (I.mul_mem_left (0, 1) h₂) @[simp] theorem map_fst_prod (I : Ideal R) (J : Ideal S) : map (RingHom.fst R S) (prod I J) = I := by ext x rw [mem_map_iff_of_surjective (RingHom.fst R S) Prod.fst_surjective] exact ⟨by rintro ⟨x, ⟨h, rfl⟩⟩ exact h.1, fun h => ⟨⟨x, 0⟩, ⟨⟨h, Ideal.zero_mem _⟩, rfl⟩⟩⟩ @[simp] theorem map_snd_prod (I : Ideal R) (J : Ideal S) : map (RingHom.snd R S) (prod I J) = J := by ext x rw [mem_map_iff_of_surjective (RingHom.snd R S) Prod.snd_surjective] exact ⟨by rintro ⟨x, ⟨h, rfl⟩⟩ exact h.2, fun h => ⟨⟨0, x⟩, ⟨⟨Ideal.zero_mem _, h⟩, rfl⟩⟩⟩ @[simp] theorem map_prodComm_prod : map ((RingEquiv.prodComm : R × S ≃+* S × R) : R × S →+* S × R) (prod I J) = prod J I := by refine Trans.trans (ideal_prod_eq _) ?_ simp [map_map] /-- Ideals of `R × S` are in one-to-one correspondence with pairs of ideals of `R` and ideals of `S`. -/ def idealProdEquiv : Ideal (R × S) ≃o Ideal R × Ideal S where toFun I := ⟨map (RingHom.fst R S) I, map (RingHom.snd R S) I⟩ invFun I := prod I.1 I.2 left_inv I := (ideal_prod_eq I).symm right_inv := fun ⟨I, J⟩ => by simp map_rel_iff' {I J} := by simp only [Equiv.coe_fn_mk, ge_iff_le, Prod.mk_le_mk] refine ⟨fun h ↦ ?_, fun h ↦ ⟨map_mono h, map_mono h⟩⟩ rw [ideal_prod_eq I, ideal_prod_eq J] exact inf_le_inf (comap_mono h.1) (comap_mono h.2) @[simp] theorem idealProdEquiv_symm_apply (I : Ideal R) (J : Ideal S) : idealProdEquiv.symm ⟨I, J⟩ = prod I J := rfl theorem prod.ext_iff {I I' : Ideal R} {J J' : Ideal S} : prod I J = prod I' J' ↔ I = I' ∧ J = J' := by simp only [← idealProdEquiv_symm_apply, idealProdEquiv.symm.injective.eq_iff, Prod.mk_inj] theorem isPrime_of_isPrime_prod_top {I : Ideal R} (h : (Ideal.prod I (⊤ : Ideal S)).IsPrime) : I.IsPrime := by constructor · contrapose! h rw [h, prod_top_top, isPrime_iff] simp [isPrime_iff, h] · intro x y hxy have : (⟨x, 1⟩ : R × S) * ⟨y, 1⟩ ∈ prod I ⊤ := by rw [Prod.mk_mul_mk, mul_one, mem_prod] exact ⟨hxy, trivial⟩ simpa using h.mem_or_mem this theorem isPrime_of_isPrime_prod_top' {I : Ideal S} (h : (Ideal.prod (⊤ : Ideal R) I).IsPrime) : I.IsPrime := by apply isPrime_of_isPrime_prod_top (S := R) rw [← map_prodComm_prod] -- Note: couldn't synthesize the right instances without the `R` and `S` hints exact map_isPrime_of_equiv (RingEquiv.prodComm (R := R) (S := S)) theorem isPrime_ideal_prod_top {I : Ideal R} [h : I.IsPrime] : (prod I (⊤ : Ideal S)).IsPrime := by constructor · rcases h with ⟨h, -⟩ contrapose! h rw [← prod_top_top, prod.ext_iff] at h exact h.1 rintro ⟨r₁, s₁⟩ ⟨r₂, s₂⟩ ⟨h₁, _⟩ rcases h.mem_or_mem h₁ with h | h · exact Or.inl ⟨h, trivial⟩ · exact Or.inr ⟨h, trivial⟩ theorem isPrime_ideal_prod_top' {I : Ideal S} [h : I.IsPrime] : (prod (⊤ : Ideal R) I).IsPrime := by letI : IsPrime (prod I (⊤ : Ideal R)) := isPrime_ideal_prod_top rw [← map_prodComm_prod] -- Note: couldn't synthesize the right instances without the `R` and `S` hints exact map_isPrime_of_equiv (RingEquiv.prodComm (R := S) (S := R)) theorem ideal_prod_prime_aux {I : Ideal R} {J : Ideal S} : (Ideal.prod I J).IsPrime → I = ⊤ ∨ J = ⊤ := by contrapose! simp only [ne_top_iff_one, isPrime_iff, not_and, not_forall, not_or] exact fun ⟨hI, hJ⟩ _ => ⟨⟨0, 1⟩, ⟨1, 0⟩, by simp, by simp [hJ], by simp [hI]⟩ /-- Classification of prime ideals in product rings: the prime ideals of `R × S` are precisely the ideals of the form `p × S` or `R × p`, where `p` is a prime ideal of `R` or `S`. -/ theorem ideal_prod_prime (I : Ideal (R × S)) : I.IsPrime ↔ (∃ p : Ideal R, p.IsPrime ∧ I = Ideal.prod p ⊤) ∨ ∃ p : Ideal S, p.IsPrime ∧ I = Ideal.prod ⊤ p := by constructor · rw [ideal_prod_eq I] intro hI rcases ideal_prod_prime_aux hI with (h | h) · right rw [h] at hI ⊢ exact ⟨_, ⟨isPrime_of_isPrime_prod_top' hI, rfl⟩⟩
· left rw [h] at hI ⊢ exact ⟨_, ⟨isPrime_of_isPrime_prod_top hI, rfl⟩⟩ · rintro (⟨p, ⟨h, rfl⟩⟩ | ⟨p, ⟨h, rfl⟩⟩) · exact isPrime_ideal_prod_top
Mathlib/RingTheory/Ideal/Prod.lean
148
152
/- Copyright (c) 2020 Nicolò Cavalleri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nicolò Cavalleri, Sébastien Gouëzel, Heather Macbeth, Patrick Massot, Floris van Doorn -/ import Mathlib.Analysis.Normed.Operator.BoundedLinearMaps import Mathlib.Topology.FiberBundle.Basic /-! # Vector bundles In this file we define (topological) vector bundles. Let `B` be the base space, let `F` be a normed space over a normed field `R`, and let `E : B → Type*` be a `FiberBundle` with fiber `F`, in which, for each `x`, the fiber `E x` is a topological vector space over `R`. To have a vector bundle structure on `Bundle.TotalSpace F E`, one should additionally have the following properties: * The bundle trivializations in the trivialization atlas should be continuous linear equivs in the fibers; * For any two trivializations `e`, `e'` in the atlas the transition function considered as a map from `B` into `F →L[R] F` is continuous on `e.baseSet ∩ e'.baseSet` with respect to the operator norm topology on `F →L[R] F`. If these conditions are satisfied, we register the typeclass `VectorBundle R F E`. We define constructions on vector bundles like pullbacks and direct sums in other files. ## Main Definitions * `Trivialization.IsLinear`: a class stating that a trivialization is fiberwise linear on its base set. * `Trivialization.linearEquivAt` and `Trivialization.continuousLinearMapAt` are the (continuous) linear fiberwise equivalences a trivialization induces. * They have forward maps `Trivialization.linearMapAt` / `Trivialization.continuousLinearMapAt` and inverses `Trivialization.symmₗ` / `Trivialization.symmL`. Note that these are all defined everywhere, since they are extended using the zero function. * `Trivialization.coordChangeL` is the coordinate change induced by two trivializations. It only makes sense on the intersection of their base sets, but is extended outside it using the identity. * Given a continuous (semi)linear map between `E x` and `E' y` where `E` and `E'` are bundles over possibly different base sets, `ContinuousLinearMap.inCoordinates` turns this into a continuous (semi)linear map between the chosen fibers of those bundles. ## Implementation notes The implementation choices in the vector bundle definition are discussed in the "Implementation notes" section of `Mathlib.Topology.FiberBundle.Basic`. ## Tags Vector bundle -/ noncomputable section open Bundle Set Topology variable (R : Type*) {B : Type*} (F : Type*) (E : B → Type*) section TopologicalVectorSpace variable {F E} variable [Semiring R] [TopologicalSpace F] [TopologicalSpace B] /-- A mixin class for `Pretrivialization`, stating that a pretrivialization is fiberwise linear with respect to given module structures on its fibers and the model fiber. -/ protected class Pretrivialization.IsLinear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] (e : Pretrivialization F (π F E)) : Prop where linear : ∀ b ∈ e.baseSet, IsLinearMap R fun x : E b => (e ⟨b, x⟩).2 namespace Pretrivialization variable (e : Pretrivialization F (π F E)) {x : TotalSpace F E} {b : B} {y : E b} theorem linear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) : IsLinearMap R fun x : E b => (e ⟨b, x⟩).2 := Pretrivialization.IsLinear.linear b hb variable [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] /-- A fiberwise linear inverse to `e`. -/ @[simps!] protected def symmₗ (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) : F →ₗ[R] E b := by refine IsLinearMap.mk' (e.symm b) ?_ by_cases hb : b ∈ e.baseSet · exact (((e.linear R hb).mk' _).inverse (e.symm b) (e.symm_apply_apply_mk hb) fun v ↦ congr_arg Prod.snd <| e.apply_mk_symm hb v).isLinear · rw [e.coe_symm_of_not_mem hb] exact (0 : F →ₗ[R] E b).isLinear /-- A pretrivialization for a vector bundle defines linear equivalences between the fibers and the model space. -/ @[simps -fullyApplied] def linearEquivAt (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) : E b ≃ₗ[R] F where toFun y := (e ⟨b, y⟩).2 invFun := e.symm b left_inv := e.symm_apply_apply_mk hb right_inv v := by simp_rw [e.apply_mk_symm hb v] map_add' v w := (e.linear R hb).map_add v w map_smul' c v := (e.linear R hb).map_smul c v open Classical in /-- A fiberwise linear map equal to `e` on `e.baseSet`. -/ protected def linearMapAt (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) : E b →ₗ[R] F := if hb : b ∈ e.baseSet then e.linearEquivAt R b hb else 0 variable {R} open Classical in theorem coe_linearMapAt (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) : ⇑(e.linearMapAt R b) = fun y => if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 := by rw [Pretrivialization.linearMapAt] split_ifs <;> rfl theorem coe_linearMapAt_of_mem (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) : ⇑(e.linearMapAt R b) = fun y => (e ⟨b, y⟩).2 := by simp_rw [coe_linearMapAt, if_pos hb] open Classical in theorem linearMapAt_apply (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (y : E b) : e.linearMapAt R b y = if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 := by rw [coe_linearMapAt] theorem linearMapAt_def_of_mem (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) : e.linearMapAt R b = e.linearEquivAt R b hb := dif_pos hb theorem linearMapAt_def_of_not_mem (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∉ e.baseSet) : e.linearMapAt R b = 0 := dif_neg hb theorem linearMapAt_eq_zero (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∉ e.baseSet) : e.linearMapAt R b = 0 := dif_neg hb theorem symmₗ_linearMapAt (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) (y : E b) : e.symmₗ R b (e.linearMapAt R b y) = y := by rw [e.linearMapAt_def_of_mem hb] exact (e.linearEquivAt R b hb).left_inv y theorem linearMapAt_symmₗ (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) (y : F) : e.linearMapAt R b (e.symmₗ R b y) = y := by rw [e.linearMapAt_def_of_mem hb] exact (e.linearEquivAt R b hb).right_inv y end Pretrivialization variable [TopologicalSpace (TotalSpace F E)] /-- A mixin class for `Trivialization`, stating that a trivialization is fiberwise linear with respect to given module structures on its fibers and the model fiber. -/ protected class Trivialization.IsLinear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] (e : Trivialization F (π F E)) : Prop where linear : ∀ b ∈ e.baseSet, IsLinearMap R fun x : E b => (e ⟨b, x⟩).2 namespace Trivialization variable (e : Trivialization F (π F E)) {x : TotalSpace F E} {b : B} {y : E b} protected theorem linear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) : IsLinearMap R fun y : E b => (e ⟨b, y⟩).2 := Trivialization.IsLinear.linear b hb instance toPretrivialization.isLinear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] [e.IsLinear R] : e.toPretrivialization.IsLinear R := { (‹_› : e.IsLinear R) with } variable [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] /-- A trivialization for a vector bundle defines linear equivalences between the fibers and the model space. -/ def linearEquivAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) : E b ≃ₗ[R] F := e.toPretrivialization.linearEquivAt R b hb variable {R} @[simp] theorem linearEquivAt_apply (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) (v : E b) : e.linearEquivAt R b hb v = (e ⟨b, v⟩).2 := rfl @[simp] theorem linearEquivAt_symm_apply (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) (v : F) : (e.linearEquivAt R b hb).symm v = e.symm b v := rfl variable (R) in /-- A fiberwise linear inverse to `e`. -/ protected def symmₗ (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : F →ₗ[R] E b := e.toPretrivialization.symmₗ R b theorem coe_symmₗ (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : ⇑(e.symmₗ R b) = e.symm b := rfl variable (R) in /-- A fiberwise linear map equal to `e` on `e.baseSet`. -/ protected def linearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : E b →ₗ[R] F := e.toPretrivialization.linearMapAt R b open Classical in theorem coe_linearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : ⇑(e.linearMapAt R b) = fun y => if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 := e.toPretrivialization.coe_linearMapAt b theorem coe_linearMapAt_of_mem (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) : ⇑(e.linearMapAt R b) = fun y => (e ⟨b, y⟩).2 := by simp_rw [coe_linearMapAt, if_pos hb] open Classical in theorem linearMapAt_apply (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (y : E b) : e.linearMapAt R b y = if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 := by rw [coe_linearMapAt] theorem linearMapAt_def_of_mem (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) : e.linearMapAt R b = e.linearEquivAt R b hb := dif_pos hb theorem linearMapAt_def_of_not_mem (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∉ e.baseSet) : e.linearMapAt R b = 0 := dif_neg hb theorem symmₗ_linearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) (y : E b) : e.symmₗ R b (e.linearMapAt R b y) = y := e.toPretrivialization.symmₗ_linearMapAt hb y theorem linearMapAt_symmₗ (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) (y : F) : e.linearMapAt R b (e.symmₗ R b y) = y := e.toPretrivialization.linearMapAt_symmₗ hb y variable (R) in open Classical in /-- A coordinate change function between two trivializations, as a continuous linear equivalence. Defined to be the identity when `b` does not lie in the base set of both trivializations. -/ def coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] (b : B) : F ≃L[R] F := { toLinearEquiv := if hb : b ∈ e.baseSet ∩ e'.baseSet then (e.linearEquivAt R b (hb.1 :)).symm.trans (e'.linearEquivAt R b hb.2) else LinearEquiv.refl R F continuous_toFun := by by_cases hb : b ∈ e.baseSet ∩ e'.baseSet · rw [dif_pos hb] refine (e'.continuousOn.comp_continuous ?_ ?_).snd · exact e.continuousOn_symm.comp_continuous (Continuous.prodMk_right b) fun y => mk_mem_prod hb.1 (mem_univ y) · exact fun y => e'.mem_source.mpr hb.2 · rw [dif_neg hb] exact continuous_id continuous_invFun := by by_cases hb : b ∈ e.baseSet ∩ e'.baseSet · rw [dif_pos hb] refine (e.continuousOn.comp_continuous ?_ ?_).snd · exact e'.continuousOn_symm.comp_continuous (Continuous.prodMk_right b) fun y => mk_mem_prod hb.2 (mem_univ y) exact fun y => e.mem_source.mpr hb.1 · rw [dif_neg hb] exact continuous_id } theorem coe_coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) : ⇑(coordChangeL R e e' b) = (e.linearEquivAt R b hb.1).symm.trans (e'.linearEquivAt R b hb.2) := congr_arg (fun f : F ≃ₗ[R] F ↦ ⇑f) (dif_pos hb) theorem coe_coordChangeL' (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) : (coordChangeL R e e' b).toLinearEquiv = (e.linearEquivAt R b hb.1).symm.trans (e'.linearEquivAt R b hb.2) := LinearEquiv.coe_injective (coe_coordChangeL _ _ hb) theorem symm_coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B} (hb : b ∈ e'.baseSet ∩ e.baseSet) : (e.coordChangeL R e' b).symm = e'.coordChangeL R e b := by apply ContinuousLinearEquiv.toLinearEquiv_injective rw [coe_coordChangeL' e' e hb, (coordChangeL R e e' b).symm_toLinearEquiv, coe_coordChangeL' e e' hb.symm, LinearEquiv.trans_symm, LinearEquiv.symm_symm] theorem coordChangeL_apply (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) (y : F) : coordChangeL R e e' b y = (e' ⟨b, e.symm b y⟩).2 := congr_fun (coe_coordChangeL e e' hb) y theorem mk_coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) (y : F) : (b, coordChangeL R e e' b y) = e' ⟨b, e.symm b y⟩ := by ext · rw [e.mk_symm hb.1 y, e'.coe_fst', e.proj_symm_apply' hb.1] rw [e.proj_symm_apply' hb.1] exact hb.2 · exact e.coordChangeL_apply e' hb y theorem apply_symm_apply_eq_coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) (v : F) : e' (e.toPartialHomeomorph.symm (b, v)) = (b, e.coordChangeL R e' b v) := by rw [e.mk_coordChangeL e' hb, e.mk_symm hb.1] /-- A version of `Trivialization.coordChangeL_apply` that fully unfolds `coordChange`. The right-hand side is ugly, but has good definitional properties for specifically defined trivializations. -/ theorem coordChangeL_apply' (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) (y : F) : coordChangeL R e e' b y = (e' (e.toPartialHomeomorph.symm (b, y))).2 := by rw [e.coordChangeL_apply e' hb, e.mk_symm hb.1] theorem coordChangeL_symm_apply (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) : ⇑(coordChangeL R e e' b).symm = (e'.linearEquivAt R b hb.2).symm.trans (e.linearEquivAt R b hb.1) := congr_arg LinearEquiv.invFun (dif_pos hb) end Trivialization end TopologicalVectorSpace section namespace Bundle /-- The zero section of a vector bundle -/ def zeroSection [∀ x, Zero (E x)] : B → TotalSpace F E := (⟨·, 0⟩) @[simp, mfld_simps] theorem zeroSection_proj [∀ x, Zero (E x)] (x : B) : (zeroSection F E x).proj = x := rfl @[simp, mfld_simps] theorem zeroSection_snd [∀ x, Zero (E x)] (x : B) : (zeroSection F E x).2 = 0 := rfl end Bundle open Bundle variable [NontriviallyNormedField R] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] [NormedAddCommGroup F] [NormedSpace R F] [TopologicalSpace B] [TopologicalSpace (TotalSpace F E)] [∀ x, TopologicalSpace (E x)] [FiberBundle F E] /-- The space `Bundle.TotalSpace F E` (for `E : B → Type*` such that each `E x` is a topological vector space) has a topological vector space structure with fiber `F` (denoted with `VectorBundle R F E`) if around every point there is a fiber bundle trivialization which is linear in the fibers. -/ class VectorBundle : Prop where trivialization_linear' : ∀ (e : Trivialization F (π F E)) [MemTrivializationAtlas e], e.IsLinear R continuousOn_coordChange' : ∀ (e e' : Trivialization F (π F E)) [MemTrivializationAtlas e] [MemTrivializationAtlas e'], ContinuousOn (fun b => Trivialization.coordChangeL R e e' b : B → F →L[R] F) (e.baseSet ∩ e'.baseSet) variable {F E} instance (priority := 100) trivialization_linear [VectorBundle R F E] (e : Trivialization F (π F E)) [MemTrivializationAtlas e] : e.IsLinear R := VectorBundle.trivialization_linear' e theorem continuousOn_coordChange [VectorBundle R F E] (e e' : Trivialization F (π F E)) [MemTrivializationAtlas e] [MemTrivializationAtlas e'] : ContinuousOn (fun b => Trivialization.coordChangeL R e e' b : B → F →L[R] F) (e.baseSet ∩ e'.baseSet) := VectorBundle.continuousOn_coordChange' e e' namespace Trivialization /-- Forward map of `Trivialization.continuousLinearEquivAt` (only propositionally equal), defined everywhere (`0` outside domain). -/ @[simps -fullyApplied apply] def continuousLinearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : E b →L[R] F := { e.linearMapAt R b with toFun := e.linearMapAt R b -- given explicitly to help `simps` cont := by rw [e.coe_linearMapAt b] classical refine continuous_if_const _ (fun hb => ?_) fun _ => continuous_zero exact (e.continuousOn.comp_continuous (FiberBundle.totalSpaceMk_isInducing F E b).continuous fun x => e.mem_source.mpr hb).snd } /-- Backwards map of `Trivialization.continuousLinearEquivAt`, defined everywhere. -/ @[simps -fullyApplied apply] def symmL (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : F →L[R] E b := { e.symmₗ R b with toFun := e.symm b -- given explicitly to help `simps` cont := by by_cases hb : b ∈ e.baseSet · rw [(FiberBundle.totalSpaceMk_isInducing F E b).continuous_iff] exact e.continuousOn_symm.comp_continuous (.prodMk_right _) fun x ↦ mk_mem_prod hb (mem_univ x) · refine continuous_zero.congr fun x => (e.symm_apply_of_not_mem hb x).symm } variable {R} theorem symmL_continuousLinearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) (y : E b) : e.symmL R b (e.continuousLinearMapAt R b y) = y := e.symmₗ_linearMapAt hb y theorem continuousLinearMapAt_symmL (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) (y : F) : e.continuousLinearMapAt R b (e.symmL R b y) = y := e.linearMapAt_symmₗ hb y variable (R) in /-- In a vector bundle, a trivialization in the fiber (which is a priori only linear) is in fact a continuous linear equiv between the fibers and the model fiber. -/ @[simps -fullyApplied apply symm_apply] def continuousLinearEquivAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) : E b ≃L[R] F := { e.toPretrivialization.linearEquivAt R b hb with toFun := fun y => (e ⟨b, y⟩).2 -- given explicitly to help `simps` invFun := e.symm b -- given explicitly to help `simps` continuous_toFun := (e.continuousOn.comp_continuous (FiberBundle.totalSpaceMk_isInducing F E b).continuous fun _ => e.mem_source.mpr hb).snd continuous_invFun := (e.symmL R b).continuous } theorem coe_continuousLinearEquivAt_eq (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) : (e.continuousLinearEquivAt R b hb : E b → F) = e.continuousLinearMapAt R b := (e.coe_linearMapAt_of_mem hb).symm theorem symm_continuousLinearEquivAt_eq (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) : ((e.continuousLinearEquivAt R b hb).symm : F → E b) = e.symmL R b := rfl @[simp] theorem continuousLinearEquivAt_apply' (e : Trivialization F (π F E)) [e.IsLinear R] (x : TotalSpace F E) (hx : x ∈ e.source) : e.continuousLinearEquivAt R x.proj (e.mem_source.1 hx) x.2 = (e x).2 := rfl variable (R) theorem apply_eq_prod_continuousLinearEquivAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) (z : E b) : e ⟨b, z⟩ = (b, e.continuousLinearEquivAt R b hb z) := by ext · refine e.coe_fst ?_ rw [e.source_eq] exact hb · simp only [coe_coe, continuousLinearEquivAt_apply] protected theorem zeroSection (e : Trivialization F (π F E)) [e.IsLinear R] {x : B} (hx : x ∈ e.baseSet) : e (zeroSection F E x) = (x, 0) := by simp_rw [zeroSection, e.apply_eq_prod_continuousLinearEquivAt R x hx 0, map_zero] variable {R} theorem symm_apply_eq_mk_continuousLinearEquivAt_symm (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) (z : F) : e.toPartialHomeomorph.symm ⟨b, z⟩ = ⟨b, (e.continuousLinearEquivAt R b hb).symm z⟩ := by have h : (b, z) ∈ e.target := by rw [e.target_eq] exact ⟨hb, mem_univ _⟩ apply e.injOn (e.map_target h) · simpa only [e.source_eq, mem_preimage] · simp_rw [e.right_inv h, coe_coe, e.apply_eq_prod_continuousLinearEquivAt R b hb, ContinuousLinearEquiv.apply_symm_apply] theorem comp_continuousLinearEquivAt_eq_coord_change (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) : (e.continuousLinearEquivAt R b hb.1).symm.trans (e'.continuousLinearEquivAt R b hb.2) = coordChangeL R e e' b := by ext v rw [coordChangeL_apply e e' hb] rfl end Trivialization /-! ### Constructing vector bundles -/ variable (B F) /-- Analogous construction of `FiberBundleCore` for vector bundles. This construction gives a way to construct vector bundles from a structure registering how trivialization changes act on fibers. -/ structure VectorBundleCore (ι : Type*) where baseSet : ι → Set B isOpen_baseSet : ∀ i, IsOpen (baseSet i) indexAt : B → ι mem_baseSet_at : ∀ x, x ∈ baseSet (indexAt x) coordChange : ι → ι → B → F →L[R] F coordChange_self : ∀ i, ∀ x ∈ baseSet i, ∀ v, coordChange i i x v = v continuousOn_coordChange : ∀ i j, ContinuousOn (coordChange i j) (baseSet i ∩ baseSet j) coordChange_comp : ∀ i j k, ∀ x ∈ baseSet i ∩ baseSet j ∩ baseSet k, ∀ v, (coordChange j k x) (coordChange i j x v) = coordChange i k x v /-- The trivial vector bundle core, in which all the changes of coordinates are the identity. -/ def trivialVectorBundleCore (ι : Type*) [Inhabited ι] : VectorBundleCore R B F ι where baseSet _ := univ isOpen_baseSet _ := isOpen_univ indexAt := default mem_baseSet_at x := mem_univ x coordChange _ _ _ := ContinuousLinearMap.id R F coordChange_self _ _ _ _ := rfl coordChange_comp _ _ _ _ _ _ := rfl continuousOn_coordChange _ _ := continuousOn_const instance (ι : Type*) [Inhabited ι] : Inhabited (VectorBundleCore R B F ι) := ⟨trivialVectorBundleCore R B F ι⟩ namespace VectorBundleCore variable {R B F} {ι : Type*} variable (Z : VectorBundleCore R B F ι) /-- Natural identification to a `FiberBundleCore`. -/ @[simps (config := mfld_cfg)] def toFiberBundleCore : FiberBundleCore ι B F := { Z with coordChange := fun i j b => Z.coordChange i j b continuousOn_coordChange := fun i j => isBoundedBilinearMap_apply.continuous.comp_continuousOn ((Z.continuousOn_coordChange i j).prodMap continuousOn_id) } -- TODO: restore coercion? -- instance toFiberBundleCoreCoe : Coe (VectorBundleCore R B F ι) (FiberBundleCore ι B F) := -- ⟨toFiberBundleCore⟩ theorem coordChange_linear_comp (i j k : ι) : ∀ x ∈ Z.baseSet i ∩ Z.baseSet j ∩ Z.baseSet k, (Z.coordChange j k x).comp (Z.coordChange i j x) = Z.coordChange i k x := fun x hx => by ext v exact Z.coordChange_comp i j k x hx v /-- The index set of a vector bundle core, as a convenience function for dot notation -/ @[nolint unusedArguments] def Index := ι /-- The base space of a vector bundle core, as a convenience function for dot notation -/ @[nolint unusedArguments, reducible] def Base := B /-- The fiber of a vector bundle core, as a convenience function for dot notation and typeclass inference -/ @[nolint unusedArguments] def Fiber : B → Type _ := Z.toFiberBundleCore.Fiber instance topologicalSpaceFiber (x : B) : TopologicalSpace (Z.Fiber x) := Z.toFiberBundleCore.topologicalSpaceFiber x instance addCommGroupFiber (x : B) : AddCommGroup (Z.Fiber x) := inferInstanceAs (AddCommGroup F) instance moduleFiber (x : B) : Module R (Z.Fiber x) := inferInstanceAs (Module R F) /-- The projection from the total space of a fiber bundle core, on its base. -/ @[reducible, simp, mfld_simps] protected def proj : TotalSpace F Z.Fiber → B := TotalSpace.proj /-- The total space of the vector bundle, as a convenience function for dot notation. It is by definition equal to `Bundle.TotalSpace F Z.Fiber`. -/ @[nolint unusedArguments, reducible] protected def TotalSpace := Bundle.TotalSpace F Z.Fiber /-- Local homeomorphism version of the trivialization change. -/ def trivChange (i j : ι) : PartialHomeomorph (B × F) (B × F) := Z.toFiberBundleCore.trivChange i j @[simp, mfld_simps] theorem mem_trivChange_source (i j : ι) (p : B × F) : p ∈ (Z.trivChange i j).source ↔ p.1 ∈ Z.baseSet i ∩ Z.baseSet j := Z.toFiberBundleCore.mem_trivChange_source i j p /-- Topological structure on the total space of a vector bundle created from core, designed so that all the local trivialization are continuous. -/ instance toTopologicalSpace : TopologicalSpace Z.TotalSpace := Z.toFiberBundleCore.toTopologicalSpace variable (b : B) (a : F) @[simp, mfld_simps] theorem coe_coordChange (i j : ι) : Z.toFiberBundleCore.coordChange i j b = Z.coordChange i j b := rfl /-- One of the standard local trivializations of a vector bundle constructed from core, taken by considering this in particular as a fiber bundle constructed from core. -/ def localTriv (i : ι) : Trivialization F (π F Z.Fiber) := Z.toFiberBundleCore.localTriv i @[simp, mfld_simps] theorem localTriv_apply {i : ι} (p : Z.TotalSpace) : (Z.localTriv i) p = ⟨p.1, Z.coordChange (Z.indexAt p.1) i p.1 p.2⟩ := rfl /-- The standard local trivializations of a vector bundle constructed from core are linear. -/ instance localTriv.isLinear (i : ι) : (Z.localTriv i).IsLinear R where linear x _ := { map_add := fun _ _ => by simp only [map_add, localTriv_apply, mfld_simps] map_smul := fun _ _ => by simp only [map_smul, localTriv_apply, mfld_simps] } variable (i j : ι) @[simp, mfld_simps] theorem mem_localTriv_source (p : Z.TotalSpace) : p ∈ (Z.localTriv i).source ↔ p.1 ∈ Z.baseSet i := Iff.rfl @[simp, mfld_simps] theorem baseSet_at : Z.baseSet i = (Z.localTriv i).baseSet := rfl @[simp, mfld_simps] theorem mem_localTriv_target (p : B × F) : p ∈ (Z.localTriv i).target ↔ p.1 ∈ (Z.localTriv i).baseSet := Z.toFiberBundleCore.mem_localTriv_target i p @[simp, mfld_simps] theorem localTriv_symm_fst (p : B × F) : (Z.localTriv i).toPartialHomeomorph.symm p = ⟨p.1, Z.coordChange i (Z.indexAt p.1) p.1 p.2⟩ := rfl @[simp, mfld_simps] theorem localTriv_symm_apply {b : B} (hb : b ∈ Z.baseSet i) (v : F) : (Z.localTriv i).symm b v = Z.coordChange i (Z.indexAt b) b v := by apply (Z.localTriv i).symm_apply hb v @[simp, mfld_simps] theorem localTriv_coordChange_eq {b : B} (hb : b ∈ Z.baseSet i ∩ Z.baseSet j) (v : F) : (Z.localTriv i).coordChangeL R (Z.localTriv j) b v = Z.coordChange i j b v := by rw [Trivialization.coordChangeL_apply', localTriv_symm_fst, localTriv_apply, coordChange_comp] exacts [⟨⟨hb.1, Z.mem_baseSet_at b⟩, hb.2⟩, hb] /-- Preferred local trivialization of a vector bundle constructed from core, at a given point, as a bundle trivialization -/ def localTrivAt (b : B) : Trivialization F (π F Z.Fiber) := Z.localTriv (Z.indexAt b) @[simp, mfld_simps] theorem localTrivAt_def : Z.localTriv (Z.indexAt b) = Z.localTrivAt b := rfl @[simp, mfld_simps] theorem mem_source_at : (⟨b, a⟩ : Z.TotalSpace) ∈ (Z.localTrivAt b).source := by rw [localTrivAt, mem_localTriv_source] exact Z.mem_baseSet_at b @[simp, mfld_simps] theorem localTrivAt_apply (p : Z.TotalSpace) : Z.localTrivAt p.1 p = ⟨p.1, p.2⟩ := Z.toFiberBundleCore.localTrivAt_apply p @[simp, mfld_simps] theorem localTrivAt_apply_mk (b : B) (a : F) : Z.localTrivAt b ⟨b, a⟩ = ⟨b, a⟩ := Z.localTrivAt_apply _ @[simp, mfld_simps] theorem mem_localTrivAt_baseSet : b ∈ (Z.localTrivAt b).baseSet := Z.toFiberBundleCore.mem_localTrivAt_baseSet b instance fiberBundle : FiberBundle F Z.Fiber := Z.toFiberBundleCore.fiberBundle instance vectorBundle : VectorBundle R F Z.Fiber where trivialization_linear' := by rintro _ ⟨i, rfl⟩ apply localTriv.isLinear continuousOn_coordChange' := by rintro _ _ ⟨i, rfl⟩ ⟨i', rfl⟩ refine (Z.continuousOn_coordChange i i').congr fun b hb => ?_ ext v exact Z.localTriv_coordChange_eq i i' hb v /-- The projection on the base of a vector bundle created from core is continuous -/ @[continuity] theorem continuous_proj : Continuous Z.proj := Z.toFiberBundleCore.continuous_proj /-- The projection on the base of a vector bundle created from core is an open map -/ theorem isOpenMap_proj : IsOpenMap Z.proj := Z.toFiberBundleCore.isOpenMap_proj variable {i j} @[simp, mfld_simps] theorem localTriv_continuousLinearMapAt {b : B} (hb : b ∈ Z.baseSet i) : (Z.localTriv i).continuousLinearMapAt R b = Z.coordChange (Z.indexAt b) i b := by ext1 v rw [(Z.localTriv i).continuousLinearMapAt_apply R, (Z.localTriv i).coe_linearMapAt_of_mem] exacts [rfl, hb] @[simp, mfld_simps] theorem trivializationAt_continuousLinearMapAt {b₀ b : B} (hb : b ∈ (trivializationAt F Z.Fiber b₀).baseSet) : (trivializationAt F Z.Fiber b₀).continuousLinearMapAt R b = Z.coordChange (Z.indexAt b) (Z.indexAt b₀) b := Z.localTriv_continuousLinearMapAt hb @[simp, mfld_simps] theorem localTriv_symmL {b : B} (hb : b ∈ Z.baseSet i) : (Z.localTriv i).symmL R b = Z.coordChange i (Z.indexAt b) b := by ext1 v rw [(Z.localTriv i).symmL_apply R, (Z.localTriv i).symm_apply] exacts [rfl, hb] @[simp, mfld_simps] theorem trivializationAt_symmL {b₀ b : B} (hb : b ∈ (trivializationAt F Z.Fiber b₀).baseSet) : (trivializationAt F Z.Fiber b₀).symmL R b = Z.coordChange (Z.indexAt b₀) (Z.indexAt b) b := Z.localTriv_symmL hb @[simp, mfld_simps] theorem trivializationAt_coordChange_eq {b₀ b₁ b : B} (hb : b ∈ (trivializationAt F Z.Fiber b₀).baseSet ∩ (trivializationAt F Z.Fiber b₁).baseSet) (v : F) : (trivializationAt F Z.Fiber b₀).coordChangeL R (trivializationAt F Z.Fiber b₁) b v = Z.coordChange (Z.indexAt b₀) (Z.indexAt b₁) b v := Z.localTriv_coordChange_eq _ _ hb v end VectorBundleCore end /-! ### Vector prebundle -/ section variable [NontriviallyNormedField R] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] [NormedAddCommGroup F] [NormedSpace R F] [TopologicalSpace B] [∀ x, TopologicalSpace (E x)] open TopologicalSpace open VectorBundle /-- This structure permits to define a vector bundle when trivializations are given as local equivalences but there is not yet a topology on the total space or the fibers. The total space is hence given a topology in such a way that there is a fiber bundle structure for which the partial equivalences are also partial homeomorphisms and hence vector bundle trivializations. The topology on the fibers is induced from the one on the total space. The field `exists_coordChange` is stated as an existential statement (instead of 3 separate fields), since it depends on propositional information (namely `e e' ∈ pretrivializationAtlas`). This makes it inconvenient to explicitly define a `coordChange` function when constructing a `VectorPrebundle`. -/ structure VectorPrebundle where pretrivializationAtlas : Set (Pretrivialization F (π F E)) pretrivialization_linear' : ∀ e, e ∈ pretrivializationAtlas → e.IsLinear R pretrivializationAt : B → Pretrivialization F (π F E) mem_base_pretrivializationAt : ∀ x : B, x ∈ (pretrivializationAt x).baseSet pretrivialization_mem_atlas : ∀ x : B, pretrivializationAt x ∈ pretrivializationAtlas exists_coordChange : ∀ᵉ (e ∈ pretrivializationAtlas) (e' ∈ pretrivializationAtlas), ∃ f : B → F →L[R] F, ContinuousOn f (e.baseSet ∩ e'.baseSet) ∧ ∀ᵉ (b ∈ e.baseSet ∩ e'.baseSet) (v : F), f b v = (e' ⟨b, e.symm b v⟩).2 totalSpaceMk_isInducing : ∀ b : B, IsInducing (pretrivializationAt b ∘ .mk b) namespace VectorPrebundle variable {R E F} /-- A randomly chosen coordinate change on a `VectorPrebundle`, given by the field `exists_coordChange`. -/ def coordChange (a : VectorPrebundle R F E) {e e' : Pretrivialization F (π F E)} (he : e ∈ a.pretrivializationAtlas) (he' : e' ∈ a.pretrivializationAtlas) (b : B) : F →L[R] F := Classical.choose (a.exists_coordChange e he e' he') b theorem continuousOn_coordChange (a : VectorPrebundle R F E) {e e' : Pretrivialization F (π F E)} (he : e ∈ a.pretrivializationAtlas) (he' : e' ∈ a.pretrivializationAtlas) : ContinuousOn (a.coordChange he he') (e.baseSet ∩ e'.baseSet) := (Classical.choose_spec (a.exists_coordChange e he e' he')).1 theorem coordChange_apply (a : VectorPrebundle R F E) {e e' : Pretrivialization F (π F E)} (he : e ∈ a.pretrivializationAtlas) (he' : e' ∈ a.pretrivializationAtlas) {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) (v : F) : a.coordChange he he' b v = (e' ⟨b, e.symm b v⟩).2 := (Classical.choose_spec (a.exists_coordChange e he e' he')).2 b hb v theorem mk_coordChange (a : VectorPrebundle R F E) {e e' : Pretrivialization F (π F E)} (he : e ∈ a.pretrivializationAtlas) (he' : e' ∈ a.pretrivializationAtlas) {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) (v : F) : (b, a.coordChange he he' b v) = e' ⟨b, e.symm b v⟩ := by ext · rw [e.mk_symm hb.1 v, e'.coe_fst', e.proj_symm_apply' hb.1] rw [e.proj_symm_apply' hb.1] exact hb.2 · exact a.coordChange_apply he he' hb v /-- Natural identification of `VectorPrebundle` as a `FiberPrebundle`. -/ def toFiberPrebundle (a : VectorPrebundle R F E) : FiberPrebundle F E := { a with continuous_trivChange := fun e he e' he' ↦ by have : ContinuousOn (fun x : B × F ↦ a.coordChange he' he x.1 x.2) ((e'.baseSet ∩ e.baseSet) ×ˢ univ) := isBoundedBilinearMap_apply.continuous.comp_continuousOn ((a.continuousOn_coordChange he' he).prodMap continuousOn_id) rw [e.target_inter_preimage_symm_source_eq e', inter_comm] refine (continuousOn_fst.prodMk this).congr ?_ rintro ⟨b, f⟩ ⟨hb, -⟩ dsimp only [Function.comp_def, Prod.map] rw [a.mk_coordChange _ _ hb, e'.mk_symm hb.1] } /-- Topology on the total space that will make the prebundle into a bundle. -/ def totalSpaceTopology (a : VectorPrebundle R F E) : TopologicalSpace (TotalSpace F E) := a.toFiberPrebundle.totalSpaceTopology /-- Promotion from a `Pretrivialization` in the `pretrivializationAtlas` of a `VectorPrebundle` to a `Trivialization`. -/ def trivializationOfMemPretrivializationAtlas (a : VectorPrebundle R F E) {e : Pretrivialization F (π F E)} (he : e ∈ a.pretrivializationAtlas) : @Trivialization B F _ _ _ a.totalSpaceTopology (π F E) := a.toFiberPrebundle.trivializationOfMemPretrivializationAtlas he theorem linear_trivializationOfMemPretrivializationAtlas (a : VectorPrebundle R F E) {e : Pretrivialization F (π F E)} (he : e ∈ a.pretrivializationAtlas) : letI := a.totalSpaceTopology Trivialization.IsLinear R (trivializationOfMemPretrivializationAtlas a he) := letI := a.totalSpaceTopology { linear := (a.pretrivialization_linear' e he).linear } variable (a : VectorPrebundle R F E) theorem mem_trivialization_at_source (b : B) (x : E b) : ⟨b, x⟩ ∈ (a.pretrivializationAt b).source := a.toFiberPrebundle.mem_pretrivializationAt_source b x @[simp] theorem totalSpaceMk_preimage_source (b : B) : .mk b ⁻¹' (a.pretrivializationAt b).source = univ := a.toFiberPrebundle.totalSpaceMk_preimage_source b @[continuity] theorem continuous_totalSpaceMk (b : B) : Continuous[_, a.totalSpaceTopology] (.mk b) := a.toFiberPrebundle.continuous_totalSpaceMk b /-- Make a `FiberBundle` from a `VectorPrebundle`; auxiliary construction for `VectorPrebundle.toVectorBundle`. -/ def toFiberBundle : @FiberBundle B F _ _ _ a.totalSpaceTopology _ := a.toFiberPrebundle.toFiberBundle /-- Make a `VectorBundle` from a `VectorPrebundle`. Concretely this means that, given a `VectorPrebundle` structure for a sigma-type `E` -- which consists of a number of "pretrivializations" identifying parts of `E` with product spaces `U × F` -- one establishes that for the topology constructed on the sigma-type using `VectorPrebundle.totalSpaceTopology`, these "pretrivializations" are actually "trivializations" (i.e., homeomorphisms with respect to the constructed topology). -/ theorem toVectorBundle : @VectorBundle R _ F E _ _ _ _ _ _ a.totalSpaceTopology _ a.toFiberBundle := letI := a.totalSpaceTopology; letI := a.toFiberBundle { trivialization_linear' := by rintro _ ⟨e, he, rfl⟩ apply linear_trivializationOfMemPretrivializationAtlas continuousOn_coordChange' := by rintro _ _ ⟨e, he, rfl⟩ ⟨e', he', rfl⟩ refine (a.continuousOn_coordChange he he').congr fun b hb ↦ ?_ ext v haveI h₁ := a.linear_trivializationOfMemPretrivializationAtlas he haveI h₂ := a.linear_trivializationOfMemPretrivializationAtlas he' rw [trivializationOfMemPretrivializationAtlas] at h₁ h₂ rw [a.coordChange_apply he he' hb v, ContinuousLinearEquiv.coe_coe, Trivialization.coordChangeL_apply] exacts [rfl, hb] } end VectorPrebundle namespace ContinuousLinearMap variable {𝕜₁ 𝕜₂ : Type*} [NontriviallyNormedField 𝕜₁] [NontriviallyNormedField 𝕜₂] variable {σ : 𝕜₁ →+* 𝕜₂} variable {B' : Type*} [TopologicalSpace B'] variable [NormedSpace 𝕜₁ F] [∀ x, Module 𝕜₁ (E x)] [TopologicalSpace (TotalSpace F E)] variable {F' : Type*} [NormedAddCommGroup F'] [NormedSpace 𝕜₂ F'] {E' : B' → Type*} [∀ x, AddCommMonoid (E' x)] [∀ x, Module 𝕜₂ (E' x)] [TopologicalSpace (TotalSpace F' E')] variable [FiberBundle F E] [VectorBundle 𝕜₁ F E] variable [∀ x, TopologicalSpace (E' x)] [FiberBundle F' E'] [VectorBundle 𝕜₂ F' E'] variable (F' E') /-- When `ϕ` is a continuous (semi)linear map between the fibers `E x` and `E' y` of two vector bundles `E` and `E'`, `ContinuousLinearMap.inCoordinates F E F' E' x₀ x y₀ y ϕ` is a coordinate change of this continuous linear map w.r.t. the chart around `x₀` and the chart around `y₀`. It is defined by composing `ϕ` with appropriate coordinate changes given by the vector bundles `E` and `E'`. We use the operations `Trivialization.continuousLinearMapAt` and `Trivialization.symmL` in the definition, instead of `Trivialization.continuousLinearEquivAt`, so that `ContinuousLinearMap.inCoordinates` is defined everywhere (but see `ContinuousLinearMap.inCoordinates_eq`). This is the (second component of the) underlying function of a trivialization of the hom-bundle (see `hom_trivializationAt_apply`). However, note that `ContinuousLinearMap.inCoordinates` is defined even when `x` and `y` live in different base sets. Therefore, it is also convenient when working with the hom-bundle between pulled back bundles. -/ def inCoordinates (x₀ x : B) (y₀ y : B') (ϕ : E x →SL[σ] E' y) : F →SL[σ] F' := ((trivializationAt F' E' y₀).continuousLinearMapAt 𝕜₂ y).comp <| ϕ.comp <| (trivializationAt F E x₀).symmL 𝕜₁ x variable {E E' F F'} /-- Rewrite `ContinuousLinearMap.inCoordinates` using continuous linear equivalences. -/ theorem inCoordinates_eq {x₀ x : B} {y₀ y : B'} {ϕ : E x →SL[σ] E' y} (hx : x ∈ (trivializationAt F E x₀).baseSet) (hy : y ∈ (trivializationAt F' E' y₀).baseSet) : inCoordinates F E F' E' x₀ x y₀ y ϕ = ((trivializationAt F' E' y₀).continuousLinearEquivAt 𝕜₂ y hy : E' y →L[𝕜₂] F').comp (ϕ.comp <| (((trivializationAt F E x₀).continuousLinearEquivAt 𝕜₁ x hx).symm : F →L[𝕜₁] E x)) := by ext simp_rw [inCoordinates, ContinuousLinearMap.coe_comp', ContinuousLinearEquiv.coe_coe, Trivialization.coe_continuousLinearEquivAt_eq, Trivialization.symm_continuousLinearEquivAt_eq] /-- Rewrite `ContinuousLinearMap.inCoordinates` in a `VectorBundleCore`. -/ protected theorem _root_.VectorBundleCore.inCoordinates_eq {ι ι'} (Z : VectorBundleCore 𝕜₁ B F ι) (Z' : VectorBundleCore 𝕜₂ B' F' ι') {x₀ x : B} {y₀ y : B'} (ϕ : F →SL[σ] F') (hx : x ∈ Z.baseSet (Z.indexAt x₀)) (hy : y ∈ Z'.baseSet (Z'.indexAt y₀)) : inCoordinates F Z.Fiber F' Z'.Fiber x₀ x y₀ y ϕ = (Z'.coordChange (Z'.indexAt y) (Z'.indexAt y₀) y).comp (ϕ.comp <| Z.coordChange (Z.indexAt x₀) (Z.indexAt x) x) := by simp_rw [inCoordinates, Z'.trivializationAt_continuousLinearMapAt hy, Z.trivializationAt_symmL hx] end ContinuousLinearMap end
Mathlib/Topology/VectorBundle/Basic.lean
1,041
1,048
/- 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
Mathlib/Topology/MetricSpace/Infsep.lean
263
265
/- Copyright (c) 2024 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Analysis.Complex.Basic import Mathlib.Analysis.RCLike.Lemmas import Mathlib.Topology.TietzeExtension import Mathlib.Analysis.NormedSpace.HomeomorphBall import Mathlib.Analysis.NormedSpace.RCLike /-! # Finite dimensional topological vector spaces over `ℝ` satisfy the Tietze extension property There are two main results here: - `RCLike.instTietzeExtensionTVS`: finite dimensional topological vector spaces over `ℝ` (or `ℂ`) have the Tietze extension property. - `BoundedContinuousFunction.exists_norm_eq_restrict_eq`: when mapping into a finite dimensional normed vector space over `ℝ` (or `ℂ`), the extension can be chosen to preserve the norm of the bounded continuous function it extends. -/ universe u u₁ v w -- this is not an instance because Lean cannot determine `𝕜`. theorem TietzeExtension.of_tvs (𝕜 : Type v) [NontriviallyNormedField 𝕜] {E : Type w} [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] [IsTopologicalAddGroup E] [ContinuousSMul 𝕜 E] [T2Space E] [FiniteDimensional 𝕜 E] [CompleteSpace 𝕜] [TietzeExtension.{u, v} 𝕜] : TietzeExtension.{u, w} E := Basis.ofVectorSpace 𝕜 E |>.equivFun.toContinuousLinearEquiv.toHomeomorph |> .of_homeo instance Complex.instTietzeExtension : TietzeExtension ℂ := TietzeExtension.of_tvs ℝ instance (priority := 900) RCLike.instTietzeExtension {𝕜 : Type*} [RCLike 𝕜] : TietzeExtension 𝕜 := TietzeExtension.of_tvs ℝ instance RCLike.instTietzeExtensionTVS {𝕜 : Type v} [RCLike 𝕜] {E : Type w} [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] [IsTopologicalAddGroup E] [ContinuousSMul 𝕜 E] [T2Space E] [FiniteDimensional 𝕜 E] : TietzeExtension.{u, w} E := TietzeExtension.of_tvs 𝕜 instance Set.instTietzeExtensionUnitBall {𝕜 : Type v} [RCLike 𝕜] {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E] [FiniteDimensional 𝕜 E] : TietzeExtension.{u, w} (Metric.ball (0 : E) 1) := have : NormedSpace ℝ E := NormedSpace.restrictScalars ℝ 𝕜 E .of_homeo Homeomorph.unitBall.symm instance Set.instTietzeExtensionUnitClosedBall {𝕜 : Type v} [RCLike 𝕜] {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E] [FiniteDimensional 𝕜 E] : TietzeExtension.{u, w} (Metric.closedBall (0 : E) 1) := by have : NormedSpace ℝ E := NormedSpace.restrictScalars ℝ 𝕜 E have : IsScalarTower ℝ 𝕜 E := Real.isScalarTower -- I didn't find this retract in Mathlib. let g : E → E := fun x ↦ ‖x‖⁻¹ • x classical suffices this : Continuous (piecewise (Metric.closedBall 0 1) id g) by refine .of_retract ⟨Subtype.val, by fun_prop⟩ ⟨_, this.codRestrict fun x ↦ ?_⟩ ?_ · by_cases hx : x ∈ Metric.closedBall 0 1 · simpa [piecewise_eq_of_mem (hi := hx)] using hx · simp only [g, piecewise_eq_of_not_mem (hi := hx), RCLike.real_smul_eq_coe_smul (K := 𝕜)] by_cases hx' : x = 0 <;> simp [hx'] · ext x simp [piecewise_eq_of_mem (hi := x.property)] refine continuous_piecewise (fun x hx ↦ ?_) continuousOn_id ?_ · replace hx : ‖x‖ = 1 := by simpa [frontier_closedBall (0 : E) one_ne_zero] using hx simp [g, hx] · refine continuousOn_id.norm.inv₀ ?_ |>.smul continuousOn_id simp only [closure_compl, interior_closedBall (0 : E) one_ne_zero, mem_compl_iff, Metric.mem_ball, dist_zero_right, not_lt, id_eq, ne_eq, norm_eq_zero] exact fun x hx ↦ norm_pos_iff.mp <| one_pos.trans_le hx theorem Metric.instTietzeExtensionBall {𝕜 : Type v} [RCLike 𝕜] {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E] [FiniteDimensional 𝕜 E] {r : ℝ} (hr : 0 < r) : TietzeExtension.{u, w} (Metric.ball (0 : E) r) := have : NormedSpace ℝ E := NormedSpace.restrictScalars ℝ 𝕜 E .of_homeo <| show (Metric.ball (0 : E) r) ≃ₜ (Metric.ball (0 : E) 1) from PartialHomeomorph.unitBallBall (0 : E) r hr |>.toHomeomorphSourceTarget.symm
theorem Metric.instTietzeExtensionClosedBall (𝕜 : Type v) [RCLike 𝕜] {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E] [FiniteDimensional 𝕜 E] (y : E) {r : ℝ} (hr : 0 < r) : TietzeExtension.{u, w} (Metric.closedBall y r) := .of_homeo <| by show (Metric.closedBall y r) ≃ₜ (Metric.closedBall (0 : E) 1) symm apply (DilationEquiv.smulTorsor y (k := (r : 𝕜)) <| by exact_mod_cast hr.ne').toHomeomorph.sets ext x simp only [mem_closedBall, dist_zero_right, DilationEquiv.coe_toHomeomorph, Set.mem_preimage, DilationEquiv.smulTorsor_apply, vadd_eq_add, dist_add_self_left, norm_smul, RCLike.norm_ofReal, abs_of_nonneg hr.le] exact (mul_le_iff_le_one_right hr).symm
Mathlib/Analysis/Complex/Tietze.lean
82
93
/- 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.Kernel.Composition.MeasureComp import Mathlib.Probability.Kernel.CondDistrib import Mathlib.Probability.ConditionalProbability /-! # Kernel associated with a conditional expectation We define `condExpKernel μ m`, a kernel from `Ω` to `Ω` such that for all integrable functions `f`, `μ[f | m] =ᵐ[μ] fun ω => ∫ y, f y ∂(condExpKernel μ m ω)`. This kernel is defined if `Ω` is a standard Borel space. In general, `μ⟦s | m⟧` maps a measurable set `s` to a function `Ω → ℝ≥0∞`, and for all `s` that map is unique up to a `μ`-null set. For all `a`, the map from sets to `ℝ≥0∞` that we obtain that way verifies some of the properties of a measure, but the fact that the `μ`-null set depends on `s` can prevent us from finding versions of the conditional expectation that combine into a true measure. The standard Borel space assumption on `Ω` allows us to do so. ## Main definitions * `condExpKernel μ m`: kernel such that `μ[f | m] =ᵐ[μ] fun ω => ∫ y, f y ∂(condExpKernel μ m ω)`. ## Main statements * `condExp_ae_eq_integral_condExpKernel`: `μ[f | m] =ᵐ[μ] fun ω => ∫ y, f y ∂(condExpKernel μ m ω)`. -/ open MeasureTheory Set Filter TopologicalSpace open scoped ENNReal MeasureTheory ProbabilityTheory namespace ProbabilityTheory section AuxLemmas variable {Ω F : Type*} {m mΩ : MeasurableSpace Ω} {μ : Measure Ω} {f : Ω → F} theorem _root_.MeasureTheory.AEStronglyMeasurable.comp_snd_map_prod_id [TopologicalSpace F] (hm : m ≤ mΩ) (hf : AEStronglyMeasurable f μ) : AEStronglyMeasurable[m.prod mΩ] (fun x : Ω × Ω => f x.2) (@Measure.map Ω (Ω × Ω) mΩ (m.prod mΩ) (fun ω => (id ω, id ω)) μ) := by rw [← aestronglyMeasurable_comp_snd_map_prodMk_iff (measurable_id'' hm)] at hf simp_rw [id] at hf ⊢ exact hf theorem _root_.MeasureTheory.Integrable.comp_snd_map_prod_id [NormedAddCommGroup F] (hm : m ≤ mΩ) (hf : Integrable f μ) : Integrable (fun x : Ω × Ω => f x.2) (@Measure.map Ω (Ω × Ω) mΩ (m.prod mΩ) (fun ω => (id ω, id ω)) μ) := by rw [← integrable_comp_snd_map_prodMk_iff (measurable_id'' hm)] at hf simp_rw [id] at hf ⊢ exact hf end AuxLemmas variable {Ω F : Type*} {m : MeasurableSpace Ω} [mΩ : MeasurableSpace Ω] [StandardBorelSpace Ω] {μ : Measure Ω} [IsFiniteMeasure μ] open Classical in /-- Kernel associated with the conditional expectation with respect to a σ-algebra. It satisfies `μ[f | m] =ᵐ[μ] fun ω => ∫ y, f y ∂(condExpKernel μ m ω)`. It is defined as the conditional distribution of the identity given the identity, where the second identity is understood as a map from `Ω` with the σ-algebra `mΩ` to `Ω` with σ-algebra `m ⊓ mΩ`. We use `m ⊓ mΩ` instead of `m` to ensure that it is a sub-σ-algebra of `mΩ`. We then use `Kernel.comap` to get a kernel from `m` to `mΩ` instead of from `m ⊓ mΩ` to `mΩ`. -/ noncomputable irreducible_def condExpKernel (μ : Measure Ω) [IsFiniteMeasure μ] (m : MeasurableSpace Ω) : @Kernel Ω Ω m mΩ := if _h : Nonempty Ω then Kernel.comap (@condDistrib Ω Ω Ω mΩ _ _ mΩ (m ⊓ mΩ) id id μ _) id (measurable_id'' (inf_le_left : m ⊓ mΩ ≤ m)) else 0 @[deprecated (since := "2025-01-21")] alias condexpKernel := condExpKernel lemma condExpKernel_eq (μ : Measure Ω) [IsFiniteMeasure μ] [h : Nonempty Ω] (m : MeasurableSpace Ω) : condExpKernel (mΩ := mΩ) μ m = Kernel.comap (@condDistrib Ω Ω Ω mΩ _ _ mΩ (m ⊓ mΩ) id id μ _) id (measurable_id'' (inf_le_left : m ⊓ mΩ ≤ m)) := by simp [condExpKernel, h] @[deprecated (since := "2025-01-21")] alias condexpKernel_eq := condExpKernel_eq lemma condExpKernel_apply_eq_condDistrib [Nonempty Ω] {ω : Ω} : condExpKernel μ m ω = @condDistrib Ω Ω Ω mΩ _ _ mΩ (m ⊓ mΩ) id id μ _ (id ω) := by simp [condExpKernel_eq, Kernel.comap_apply] @[deprecated (since := "2025-01-21")] alias condexpKernel_apply_eq_condDistrib := condExpKernel_apply_eq_condDistrib instance : IsMarkovKernel (condExpKernel μ m) := by rcases isEmpty_or_nonempty Ω with h | h · exact ⟨fun a ↦ (IsEmpty.false a).elim⟩ · simp [condExpKernel, h]; infer_instance lemma compProd_trim_condExpKernel (hm : m ≤ mΩ) : (μ.trim hm) ⊗ₘ condExpKernel μ m = @Measure.map Ω (Ω × Ω) mΩ (m.prod mΩ) (fun ω ↦ (id ω, id ω)) μ := by rcases isEmpty_or_nonempty Ω with h | h · simp [Measure.eq_zero_of_isEmpty μ] rw [condExpKernel_eq] have : m ⊓ mΩ = m := inf_of_le_left hm have h := compProd_map_condDistrib (mβ := m) (μ := μ) (X := id) measurable_id.aemeasurable
rw [← h, trim_eq_map hm] congr 1 ext a s hs simp only [Kernel.coe_comap, Function.comp_apply, id_eq] congr lemma condExpKernel_comp_trim (hm : m ≤ mΩ) : condExpKernel μ m ∘ₘ μ.trim hm = μ := by rw [← Measure.snd_compProd, compProd_trim_condExpKernel, @Measure.snd_map_prodMk, Measure.map_id] exact measurable_id'' hm
Mathlib/Probability/Kernel/Condexp.lean
108
116
/- 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.SpecialFunctions.Gaussian.GaussianIntegral import Mathlib.Analysis.Complex.CauchyIntegral import Mathlib.MeasureTheory.Integral.Pi import Mathlib.Analysis.Fourier.FourierTransform /-! # Fourier transform of the Gaussian We prove that the Fourier transform of the Gaussian function is another Gaussian: * `integral_cexp_quadratic`: general formula for `∫ (x : ℝ), exp (b * x ^ 2 + c * x + d)` * `fourierIntegral_gaussian`: for all complex `b` and `t` with `0 < re b`, we have `∫ x:ℝ, exp (I * t * x) * exp (-b * x^2) = (π / b) ^ (1 / 2) * exp (-t ^ 2 / (4 * b))`. * `fourierIntegral_gaussian_pi`: a variant with `b` and `t` scaled to give a more symmetric statement, and formulated in terms of the Fourier transform operator `𝓕`. We also give versions of these formulas in finite-dimensional inner product spaces, see `integral_cexp_neg_mul_sq_norm_add` and `fourierIntegral_gaussian_innerProductSpace`. -/ /-! ## Fourier integral of Gaussian functions -/ open Real Set MeasureTheory Filter Asymptotics intervalIntegral open scoped Real Topology FourierTransform RealInnerProductSpace open Complex hiding exp continuous_exp abs_of_nonneg sq_abs noncomputable section namespace GaussianFourier variable {b : ℂ} /-- The integral of the Gaussian function over the vertical edges of a rectangle with vertices at `(±T, 0)` and `(±T, c)`. -/ def verticalIntegral (b : ℂ) (c T : ℝ) : ℂ := ∫ y : ℝ in (0 : ℝ)..c, I * (cexp (-b * (T + y * I) ^ 2) - cexp (-b * (T - y * I) ^ 2)) /-- Explicit formula for the norm of the Gaussian function along the vertical edges. -/ theorem norm_cexp_neg_mul_sq_add_mul_I (b : ℂ) (c T : ℝ) :
‖cexp (-b * (T + c * I) ^ 2)‖ = exp (-(b.re * T ^ 2 - 2 * b.im * c * T - b.re * c ^ 2)) := by rw [Complex.norm_exp, neg_mul, neg_re, ← re_add_im b] simp only [sq, re_add_im, mul_re, mul_im, add_re, add_im, ofReal_re, ofReal_im, I_re, I_im] ring_nf
Mathlib/Analysis/SpecialFunctions/Gaussian/FourierTransform.lean
51
55
/- 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] _ ≤ max (degree (erase (natDegree q) p)) (degree (erase (natDegree q) q)) := (degree_neg (erase (natDegree q) q) ▸ degree_add_le _ _) _ < degree p := max_lt_iff.2 ⟨hd' ▸ degree_erase_lt hp0, hd.symm ▸ degree_erase_lt hq0⟩ theorem degree_X_sub_C_le (r : R) : (X - C r).degree ≤ 1 := (degree_sub_le _ _).trans (max_le degree_X_le (degree_C_le.trans zero_le_one)) theorem natDegree_X_sub_C_le (r : R) : (X - C r).natDegree ≤ 1 := natDegree_le_iff_degree_le.2 <| degree_X_sub_C_le r end Ring end Polynomial
Mathlib/Algebra/Polynomial/Degree/Definitions.lean
1,305
1,308
/- 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 unfold derivWithin deriv rw [fderivWithin_univ] theorem derivWithin_inter (ht : t ∈ 𝓝 x) : derivWithin f (s ∩ t) x = derivWithin f s x := by unfold derivWithin rw [fderivWithin_inter ht] theorem derivWithin_of_mem_nhds (h : s ∈ 𝓝 x) : derivWithin f s x = deriv f x := by simp only [derivWithin, deriv, fderivWithin_of_mem_nhds h] theorem derivWithin_of_isOpen (hs : IsOpen s) (hx : x ∈ s) : derivWithin f s x = deriv f x := derivWithin_of_mem_nhds (hs.mem_nhds hx) lemma deriv_eqOn {f' : 𝕜 → F} (hs : IsOpen s) (hf' : ∀ x ∈ s, HasDerivWithinAt f (f' x) s x) : s.EqOn (deriv f) f' := fun x hx ↦ by rw [← derivWithin_of_isOpen hs hx, (hf' _ hx).derivWithin <| hs.uniqueDiffWithinAt hx] theorem deriv_mem_iff {f : 𝕜 → F} {s : Set F} {x : 𝕜} : deriv f x ∈ s ↔ DifferentiableAt 𝕜 f x ∧ deriv f x ∈ s ∨ ¬DifferentiableAt 𝕜 f x ∧ (0 : F) ∈ s := by by_cases hx : DifferentiableAt 𝕜 f x <;> simp [deriv_zero_of_not_differentiableAt, *] theorem derivWithin_mem_iff {f : 𝕜 → F} {t : Set 𝕜} {s : Set F} {x : 𝕜} : derivWithin f t x ∈ s ↔ DifferentiableWithinAt 𝕜 f t x ∧ derivWithin f t x ∈ s ∨ ¬DifferentiableWithinAt 𝕜 f t x ∧ (0 : F) ∈ s := by by_cases hx : DifferentiableWithinAt 𝕜 f t x <;> simp [derivWithin_zero_of_not_differentiableWithinAt, *] theorem differentiableWithinAt_Ioi_iff_Ici [PartialOrder 𝕜] : DifferentiableWithinAt 𝕜 f (Ioi x) x ↔ DifferentiableWithinAt 𝕜 f (Ici x) x := ⟨fun h => h.hasDerivWithinAt.Ici_of_Ioi.differentiableWithinAt, fun h => h.hasDerivWithinAt.Ioi_of_Ici.differentiableWithinAt⟩ -- Golfed while splitting the file theorem derivWithin_Ioi_eq_Ici {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] (f : ℝ → E) (x : ℝ) : derivWithin f (Ioi x) x = derivWithin f (Ici x) x := by by_cases H : DifferentiableWithinAt ℝ f (Ioi x) x · have A := H.hasDerivWithinAt.Ici_of_Ioi have B := (differentiableWithinAt_Ioi_iff_Ici.1 H).hasDerivWithinAt simpa using (uniqueDiffOn_Ici x).eq left_mem_Ici A B · rw [derivWithin_zero_of_not_differentiableWithinAt H,
derivWithin_zero_of_not_differentiableWithinAt] rwa [differentiableWithinAt_Ioi_iff_Ici] at H section congr
Mathlib/Analysis/Calculus/Deriv/Basic.lean
518
521
/- Copyright (c) 2018 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp -/ import Mathlib.Data.Nat.Find import Mathlib.Algebra.Module.Pi import Mathlib.Algebra.BigOperators.Group.Finset.Basic /-! # Basic properties of holors Holors are indexed collections of tensor coefficients. Confusingly, they are often called tensors in physics and in the neural network community. A holor is simply a multidimensional array of values. The size of a holor is specified by a `List ℕ`, whose length is called the dimension of the holor. The tensor product of `x₁ : Holor α ds₁` and `x₂ : Holor α ds₂` is the holor given by `(x₁ ⊗ x₂) (i₁ ++ i₂) = x₁ i₁ * x₂ i₂`. A holor is "of rank at most 1" if it is a tensor product of one-dimensional holors. The CP rank of a holor `x` is the smallest N such that `x` is the sum of N holors of rank at most 1. Based on the tensor library found in <https://www.isa-afp.org/entries/Deep_Learning.html> ## References * <https://en.wikipedia.org/wiki/Tensor_rank_decomposition> -/ universe u open List /-- `HolorIndex ds` is the type of valid index tuples used to identify an entry of a holor of dimensions `ds`. -/ def HolorIndex (ds : List ℕ) : Type := { is : List ℕ // Forall₂ (· < ·) is ds } namespace HolorIndex variable {ds₁ ds₂ ds₃ : List ℕ} /-- Take the first elements of a `HolorIndex`. -/ def take : ∀ {ds₁ : List ℕ}, HolorIndex (ds₁ ++ ds₂) → HolorIndex ds₁ | ds, is => ⟨List.take (length ds) is.1, forall₂_take_append is.1 ds ds₂ is.2⟩ /-- Drop the first elements of a `HolorIndex`. -/ def drop : ∀ {ds₁ : List ℕ}, HolorIndex (ds₁ ++ ds₂) → HolorIndex ds₂ | ds, is => ⟨List.drop (length ds) is.1, forall₂_drop_append is.1 ds ds₂ is.2⟩ theorem cast_type (is : List ℕ) (eq : ds₁ = ds₂) (h : Forall₂ (· < ·) is ds₁) : (cast (congr_arg HolorIndex eq) ⟨is, h⟩).val = is := by subst eq; rfl /-- Right associator for `HolorIndex` -/ def assocRight : HolorIndex (ds₁ ++ ds₂ ++ ds₃) → HolorIndex (ds₁ ++ (ds₂ ++ ds₃)) := cast (congr_arg HolorIndex (append_assoc ds₁ ds₂ ds₃)) /-- Left associator for `HolorIndex` -/ def assocLeft : HolorIndex (ds₁ ++ (ds₂ ++ ds₃)) → HolorIndex (ds₁ ++ ds₂ ++ ds₃) := cast (congr_arg HolorIndex (append_assoc ds₁ ds₂ ds₃).symm) theorem take_take : ∀ t : HolorIndex (ds₁ ++ ds₂ ++ ds₃), t.assocRight.take = t.take.take | ⟨is, h⟩ => Subtype.eq <| by simp [assocRight, take, cast_type, List.take_take, Nat.le_add_right, min_eq_left] theorem drop_take : ∀ t : HolorIndex (ds₁ ++ ds₂ ++ ds₃), t.assocRight.drop.take = t.take.drop | ⟨is, h⟩ => Subtype.eq (by simp [assocRight, take, drop, cast_type, List.drop_take]) theorem drop_drop : ∀ t : HolorIndex (ds₁ ++ ds₂ ++ ds₃), t.assocRight.drop.drop = t.drop | ⟨is, h⟩ => Subtype.eq (by simp [add_comm, assocRight, drop, cast_type, List.drop_drop]) end HolorIndex /-- Holor (indexed collections of tensor coefficients) -/ def Holor (α : Type u) (ds : List ℕ) := HolorIndex ds → α namespace Holor variable {α : Type} {d : ℕ} {ds : List ℕ} {ds₁ : List ℕ} {ds₂ : List ℕ} {ds₃ : List ℕ} instance [Inhabited α] : Inhabited (Holor α ds) := ⟨fun _ => default⟩ instance [Zero α] : Zero (Holor α ds) := ⟨fun _ => 0⟩ instance [Add α] : Add (Holor α ds) := ⟨fun x y t => x t + y t⟩ instance [Neg α] : Neg (Holor α ds) := ⟨fun a t => -a t⟩ instance [AddSemigroup α] : AddSemigroup (Holor α ds) := Pi.addSemigroup instance [AddCommSemigroup α] : AddCommSemigroup (Holor α ds) := Pi.addCommSemigroup instance [AddMonoid α] : AddMonoid (Holor α ds) := Pi.addMonoid instance [AddCommMonoid α] : AddCommMonoid (Holor α ds) := Pi.addCommMonoid instance [AddGroup α] : AddGroup (Holor α ds) := Pi.addGroup instance [AddCommGroup α] : AddCommGroup (Holor α ds) := Pi.addCommGroup -- scalar product instance [Mul α] : SMul α (Holor α ds) := ⟨fun a x => fun t => a * x t⟩ instance [Semiring α] : Module α (Holor α ds) := Pi.module _ _ _ /-- The tensor product of two holors. -/ def mul [Mul α] (x : Holor α ds₁) (y : Holor α ds₂) : Holor α (ds₁ ++ ds₂) := fun t => x t.take * y t.drop local infixl:70 " ⊗ " => mul theorem cast_type (eq : ds₁ = ds₂) (a : Holor α ds₁) : cast (congr_arg (Holor α) eq) a = fun t => a (cast (congr_arg HolorIndex eq.symm) t) := by subst eq; rfl /-- Right associator for `Holor` -/ def assocRight : Holor α (ds₁ ++ ds₂ ++ ds₃) → Holor α (ds₁ ++ (ds₂ ++ ds₃)) := cast (congr_arg (Holor α) (append_assoc ds₁ ds₂ ds₃)) /-- Left associator for `Holor` -/ def assocLeft : Holor α (ds₁ ++ (ds₂ ++ ds₃)) → Holor α (ds₁ ++ ds₂ ++ ds₃) := cast (congr_arg (Holor α) (append_assoc ds₁ ds₂ ds₃).symm) theorem mul_assoc0 [Semigroup α] (x : Holor α ds₁) (y : Holor α ds₂) (z : Holor α ds₃) : x ⊗ y ⊗ z = (x ⊗ (y ⊗ z)).assocLeft := funext fun t : HolorIndex (ds₁ ++ ds₂ ++ ds₃) => by rw [assocLeft] unfold mul rw [mul_assoc, ← HolorIndex.take_take, ← HolorIndex.drop_take, ← HolorIndex.drop_drop, cast_type] · rfl rw [append_assoc] theorem mul_assoc [Semigroup α] (x : Holor α ds₁) (y : Holor α ds₂) (z : Holor α ds₃) : HEq (mul (mul x y) z) (mul x (mul y z)) := by simp [cast_heq, mul_assoc0, assocLeft] theorem mul_left_distrib [Distrib α] (x : Holor α ds₁) (y : Holor α ds₂) (z : Holor α ds₂) : x ⊗ (y + z) = x ⊗ y + x ⊗ z := funext fun t => left_distrib (x t.take) (y t.drop) (z t.drop) theorem mul_right_distrib [Distrib α] (x : Holor α ds₁) (y : Holor α ds₁) (z : Holor α ds₂) : (x + y) ⊗ z = x ⊗ z + y ⊗ z := funext fun t => add_mul (x t.take) (y t.take) (z t.drop) @[simp] nonrec theorem zero_mul {α : Type} [MulZeroClass α] (x : Holor α ds₂) : (0 : Holor α ds₁) ⊗ x = 0 := funext fun t => zero_mul (x (HolorIndex.drop t)) @[simp] nonrec theorem mul_zero {α : Type} [MulZeroClass α] (x : Holor α ds₁) : x ⊗ (0 : Holor α ds₂) = 0 := funext fun t => mul_zero (x (HolorIndex.take t)) theorem mul_scalar_mul [Mul α] (x : Holor α []) (y : Holor α ds) : x ⊗ y = x ⟨[], Forall₂.nil⟩ • y := by simp +unfoldPartialApp [mul, SMul.smul, HolorIndex.take, HolorIndex.drop, HSMul.hSMul] -- holor slices /-- A slice is a subholor consisting of all entries with initial index i. -/ def slice (x : Holor α (d :: ds)) (i : ℕ) (h : i < d) : Holor α ds := fun is : HolorIndex ds => x ⟨i :: is.1, Forall₂.cons h is.2⟩ /-- The 1-dimensional "unit" holor with 1 in the `j`th position. -/ def unitVec [Monoid α] [AddMonoid α] (d : ℕ) (j : ℕ) : Holor α [d] := fun ti => if ti.1 = [j] then 1 else 0 theorem holor_index_cons_decomp (p : HolorIndex (d :: ds) → Prop) : ∀ t : HolorIndex (d :: ds), (∀ i is, ∀ h : t.1 = i :: is, p ⟨i :: is, by rw [← h]; exact t.2⟩) → p t | ⟨[], hforall₂⟩, _ => absurd (forall₂_nil_left_iff.1 hforall₂) (cons_ne_nil d ds) | ⟨i :: is, _⟩, hp => hp i is rfl /-- Two holors are equal if all their slices are equal. -/ theorem slice_eq (x : Holor α (d :: ds)) (y : Holor α (d :: ds)) (h : slice x = slice y) : x = y := funext fun t : HolorIndex (d :: ds) => holor_index_cons_decomp (fun t => x t = y t) t fun i is hiis => have hiisdds : Forall₂ (· < ·) (i :: is) (d :: ds) := by rw [← hiis]; exact t.2 have hid : i < d := (forall₂_cons.1 hiisdds).1 have hisds : Forall₂ (· < ·) is ds := (forall₂_cons.1 hiisdds).2 calc x ⟨i :: is, _⟩ = slice x i hid ⟨is, hisds⟩ := congr_arg x (Subtype.eq rfl) _ = slice y i hid ⟨is, hisds⟩ := by rw [h] _ = y ⟨i :: is, _⟩ := congr_arg y (Subtype.eq rfl) theorem slice_unitVec_mul [Semiring α] {i : ℕ} {j : ℕ} (hid : i < d) (x : Holor α ds) : slice (unitVec d j ⊗ x) i hid = if i = j then x else 0 := funext fun t : HolorIndex ds => if h : i = j then by simp [slice, mul, HolorIndex.take, unitVec, HolorIndex.drop, h] else by simp [slice, mul, HolorIndex.take, unitVec, HolorIndex.drop, h]; rfl theorem slice_add [Add α] (i : ℕ) (hid : i < d) (x : Holor α (d :: ds)) (y : Holor α (d :: ds)) : slice x i hid + slice y i hid = slice (x + y) i hid := funext fun t => by simp [slice, (· + ·), Add.add] theorem slice_zero [Zero α] (i : ℕ) (hid : i < d) : slice (0 : Holor α (d :: ds)) i hid = 0 := rfl theorem slice_sum [AddCommMonoid α] {β : Type} (i : ℕ) (hid : i < d) (s : Finset β) (f : β → Holor α (d :: ds)) : (∑ x ∈ s, slice (f x) i hid) = slice (∑ x ∈ s, f x) i hid := by letI := Classical.decEq β refine Finset.induction_on s ?_ ?_ · simp [slice_zero] · intro _ _ h_not_in ih rw [Finset.sum_insert h_not_in, ih, slice_add, Finset.sum_insert h_not_in] /-- The original holor can be recovered from its slices by multiplying with unit vectors and summing up. -/ @[simp] theorem sum_unitVec_mul_slice [Semiring α] (x : Holor α (d :: ds)) : (∑ i ∈ (Finset.range d).attach, unitVec d i ⊗ slice x i (Nat.succ_le_of_lt (Finset.mem_range.1 i.prop))) = x := by apply slice_eq _ _ _ ext i hid rw [← slice_sum] simp only [slice_unitVec_mul hid] rw [Finset.sum_eq_single (Subtype.mk i <| Finset.mem_range.2 hid)] · simp · intro (b : { x // x ∈ Finset.range d }) (_ : b ∈ (Finset.range d).attach) (hbi : b ≠ ⟨i, _⟩) have hbi' : i ≠ b := by simpa only [Ne, Subtype.ext_iff, Subtype.coe_mk] using hbi.symm simp [hbi'] · intro (hid' : Subtype.mk i _ ∉ Finset.attach (Finset.range d)) exfalso exact absurd (Finset.mem_attach _ _) hid' -- CP rank /-- `CPRankMax1 x` means `x` has CP rank at most 1, that is, it is the tensor product of 1-dimensional holors. -/ inductive CPRankMax1 [Mul α] : ∀ {ds}, Holor α ds → Prop | nil (x : Holor α []) : CPRankMax1 x | cons {d} {ds} (x : Holor α [d]) (y : Holor α ds) : CPRankMax1 y → CPRankMax1 (x ⊗ y) /-- `CPRankMax N x` means `x` has CP rank at most `N`, that is, it can be written as the sum of N holors of rank at most 1. -/ inductive CPRankMax [Mul α] [AddMonoid α] : ℕ → ∀ {ds}, Holor α ds → Prop | zero {ds} : CPRankMax 0 (0 : Holor α ds) | succ (n) {ds} (x : Holor α ds) (y : Holor α ds) : CPRankMax1 x → CPRankMax n y → CPRankMax (n + 1) (x + y) theorem cprankMax_nil [Mul α] [AddMonoid α] (x : Holor α nil) : CPRankMax 1 x := by have h := CPRankMax.succ 0 x 0 (CPRankMax1.nil x) CPRankMax.zero rwa [add_zero x, zero_add] at h theorem cprankMax_1 [Mul α] [AddMonoid α] {x : Holor α ds} (h : CPRankMax1 x) : CPRankMax 1 x := by have h' := CPRankMax.succ 0 x 0 h CPRankMax.zero rwa [zero_add, add_zero] at h' theorem cprankMax_add [Mul α] [AddMonoid α] : ∀ {m : ℕ} {n : ℕ} {x : Holor α ds} {y : Holor α ds}, CPRankMax m x → CPRankMax n y → CPRankMax (m + n) (x + y) | 0, n, x, y, hx, hy => by match hx with | CPRankMax.zero => simp only [zero_add, hy] | m + 1, n, _, y, CPRankMax.succ _ x₁ x₂ hx₁ hx₂, hy => by suffices CPRankMax (m + n + 1) (x₁ + (x₂ + y)) by simpa only [add_comm, add_assoc, add_left_comm] using this apply CPRankMax.succ · assumption · exact cprankMax_add hx₂ hy theorem cprankMax_mul [NonUnitalNonAssocSemiring α] : ∀ (n : ℕ) (x : Holor α [d]) (y : Holor α ds), CPRankMax n y → CPRankMax n (x ⊗ y) | 0, x, _, CPRankMax.zero => by simp [mul_zero x, CPRankMax.zero] | n + 1, x, _, CPRankMax.succ _ y₁ y₂ hy₁ hy₂ => by rw [mul_left_distrib] rw [Nat.add_comm] apply cprankMax_add · exact cprankMax_1 (CPRankMax1.cons _ _ hy₁) · exact cprankMax_mul _ x y₂ hy₂ theorem cprankMax_sum [NonUnitalNonAssocSemiring α] {β} {n : ℕ} (s : Finset β) (f : β → Holor α ds) : (∀ x ∈ s, CPRankMax n (f x)) → CPRankMax (s.card * n) (∑ x ∈ s, f x) := letI := Classical.decEq β Finset.induction_on s (by simp [CPRankMax.zero]) (by intro x s (h_x_notin_s : x ∉ s) ih h_cprank simp only [Finset.sum_insert h_x_notin_s, Finset.card_insert_of_not_mem h_x_notin_s] rw [Nat.right_distrib] simp only [Nat.one_mul, Nat.add_comm] have ih' : CPRankMax (Finset.card s * n) (∑ x ∈ s, f x) := by apply ih intro (x : β) (h_x_in_s : x ∈ s) simp only [h_cprank, Finset.mem_insert_of_mem, h_x_in_s] exact cprankMax_add (h_cprank x (Finset.mem_insert_self x s)) ih') theorem cprankMax_upper_bound [Semiring α] : ∀ {ds}, ∀ x : Holor α ds, CPRankMax ds.prod x | [], x => cprankMax_nil x | d :: ds, x => by have h_summands : ∀ i : { x // x ∈ Finset.range d }, CPRankMax ds.prod (unitVec d i.1 ⊗ slice x i.1 (mem_range.1 i.2)) := fun i => cprankMax_mul _ _ _ (cprankMax_upper_bound (slice x i.1 (mem_range.1 i.2))) have h_dds_prod : (List.cons d ds).prod = Finset.card (Finset.range d) * prod ds := by simp [Finset.card_range] have : CPRankMax (Finset.card (Finset.attach (Finset.range d)) * prod ds) (∑ i ∈ Finset.attach (Finset.range d), unitVec d i.val ⊗ slice x i.val (mem_range.1 i.2)) := cprankMax_sum (Finset.range d).attach _ fun i _ => h_summands i have h_cprankMax_sum : CPRankMax (Finset.card (Finset.range d) * prod ds) (∑ i ∈ Finset.attach (Finset.range d),
unitVec d i.val ⊗ slice x i.val (mem_range.1 i.2)) := by rwa [Finset.card_attach] at this rw [← sum_unitVec_mul_slice x] rw [h_dds_prod] exact h_cprankMax_sum /-- The CP rank of a holor `x`: the smallest N such that `x` can be written as the sum of N holors of rank at most 1. -/ noncomputable def cprank [Ring α] (x : Holor α ds) : Nat := @Nat.find (fun n => CPRankMax n x) (Classical.decPred _) ⟨ds.prod, cprankMax_upper_bound x⟩ theorem cprank_upper_bound [Ring α] : ∀ {ds}, ∀ x : Holor α ds, cprank x ≤ ds.prod := fun {ds} x => letI := Classical.decPred fun n : ℕ => CPRankMax n x Nat.find_min' ⟨ds.prod, show (fun n => CPRankMax n x) ds.prod from cprankMax_upper_bound x⟩
Mathlib/Data/Holor.lean
314
327
/- 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) :=
Mathlib/Algebra/Order/Field/Basic.lean
396
397
/- Copyright (c) 2020 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne, Sébastien Gouëzel -/ import Mathlib.Analysis.NormedSpace.IndicatorFunction import Mathlib.Data.Fintype.Order import Mathlib.MeasureTheory.Function.AEEqFun import Mathlib.MeasureTheory.Function.LpSeminorm.Defs import Mathlib.MeasureTheory.Function.SpecialFunctions.Basic import Mathlib.MeasureTheory.Integral.Lebesgue.Countable import Mathlib.MeasureTheory.Integral.Lebesgue.Sub /-! # Basic theorems about ℒp space -/ noncomputable section open TopologicalSpace MeasureTheory Filter open scoped NNReal ENNReal Topology ComplexConjugate variable {α ε ε' E F G : Type*} {m m0 : MeasurableSpace α} {p : ℝ≥0∞} {q : ℝ} {μ ν : Measure α} [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedAddCommGroup G] [ENorm ε] [ENorm ε'] namespace MeasureTheory section Lp section Top theorem MemLp.eLpNorm_lt_top [TopologicalSpace ε] {f : α → ε} (hfp : MemLp f p μ) : eLpNorm f p μ < ∞ := hfp.2 @[deprecated (since := "2025-02-21")] alias Memℒp.eLpNorm_lt_top := MemLp.eLpNorm_lt_top theorem MemLp.eLpNorm_ne_top [TopologicalSpace ε] {f : α → ε} (hfp : MemLp f p μ) : eLpNorm f p μ ≠ ∞ := ne_of_lt hfp.2 @[deprecated (since := "2025-02-21")] alias Memℒp.eLpNorm_ne_top := MemLp.eLpNorm_ne_top theorem lintegral_rpow_enorm_lt_top_of_eLpNorm'_lt_top {f : α → ε} (hq0_lt : 0 < q) (hfq : eLpNorm' f q μ < ∞) : ∫⁻ a, ‖f a‖ₑ ^ q ∂μ < ∞ := by rw [lintegral_rpow_enorm_eq_rpow_eLpNorm' hq0_lt] exact ENNReal.rpow_lt_top_of_nonneg (le_of_lt hq0_lt) (ne_of_lt hfq) @[deprecated (since := "2025-01-17")] alias lintegral_rpow_nnnorm_lt_top_of_eLpNorm'_lt_top' := lintegral_rpow_enorm_lt_top_of_eLpNorm'_lt_top theorem lintegral_rpow_enorm_lt_top_of_eLpNorm_lt_top {f : α → ε} (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) (hfp : eLpNorm f p μ < ∞) : ∫⁻ a, ‖f a‖ₑ ^ p.toReal ∂μ < ∞ := by apply lintegral_rpow_enorm_lt_top_of_eLpNorm'_lt_top · exact ENNReal.toReal_pos hp_ne_zero hp_ne_top · simpa [eLpNorm_eq_eLpNorm' hp_ne_zero hp_ne_top] using hfp @[deprecated (since := "2025-01-17")] alias lintegral_rpow_nnnorm_lt_top_of_eLpNorm_lt_top := lintegral_rpow_enorm_lt_top_of_eLpNorm_lt_top theorem eLpNorm_lt_top_iff_lintegral_rpow_enorm_lt_top {f : α → ε} (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) : eLpNorm f p μ < ∞ ↔ ∫⁻ a, (‖f a‖ₑ) ^ p.toReal ∂μ < ∞ := ⟨lintegral_rpow_enorm_lt_top_of_eLpNorm_lt_top hp_ne_zero hp_ne_top, by intro h have hp' := ENNReal.toReal_pos hp_ne_zero hp_ne_top have : 0 < 1 / p.toReal := div_pos zero_lt_one hp' simpa [eLpNorm_eq_lintegral_rpow_enorm hp_ne_zero hp_ne_top] using ENNReal.rpow_lt_top_of_nonneg (le_of_lt this) (ne_of_lt h)⟩ @[deprecated (since := "2025-02-04")] alias eLpNorm_lt_top_iff_lintegral_rpow_nnnorm_lt_top := eLpNorm_lt_top_iff_lintegral_rpow_enorm_lt_top end Top section Zero @[simp] theorem eLpNorm'_exponent_zero {f : α → ε} : eLpNorm' f 0 μ = 1 := by rw [eLpNorm', div_zero, ENNReal.rpow_zero] @[simp] theorem eLpNorm_exponent_zero {f : α → ε} : eLpNorm f 0 μ = 0 := by simp [eLpNorm] @[simp] theorem memLp_zero_iff_aestronglyMeasurable [TopologicalSpace ε] {f : α → ε} : MemLp f 0 μ ↔ AEStronglyMeasurable f μ := by simp [MemLp, eLpNorm_exponent_zero] @[deprecated (since := "2025-02-21")] alias memℒp_zero_iff_aestronglyMeasurable := memLp_zero_iff_aestronglyMeasurable section ENormedAddMonoid variable {ε : Type*} [TopologicalSpace ε] [ENormedAddMonoid ε] @[simp] theorem eLpNorm'_zero (hp0_lt : 0 < q) : eLpNorm' (0 : α → ε) q μ = 0 := by simp [eLpNorm'_eq_lintegral_enorm, hp0_lt] @[simp] theorem eLpNorm'_zero' (hq0_ne : q ≠ 0) (hμ : μ ≠ 0) : eLpNorm' (0 : α → ε) q μ = 0 := by rcases le_or_lt 0 q with hq0 | hq_neg · exact eLpNorm'_zero (lt_of_le_of_ne hq0 hq0_ne.symm) · simp [eLpNorm'_eq_lintegral_enorm, ENNReal.rpow_eq_zero_iff, hμ, hq_neg] @[simp] theorem eLpNormEssSup_zero : eLpNormEssSup (0 : α → ε) μ = 0 := by simp [eLpNormEssSup, ← bot_eq_zero', essSup_const_bot] @[simp] theorem eLpNorm_zero : eLpNorm (0 : α → ε) p μ = 0 := by by_cases h0 : p = 0 · simp [h0] by_cases h_top : p = ∞ · simp only [h_top, eLpNorm_exponent_top, eLpNormEssSup_zero] rw [← Ne] at h0 simp [eLpNorm_eq_eLpNorm' h0 h_top, ENNReal.toReal_pos h0 h_top] @[simp] theorem eLpNorm_zero' : eLpNorm (fun _ : α => (0 : ε)) p μ = 0 := eLpNorm_zero @[simp] lemma MemLp.zero : MemLp (0 : α → ε) p μ := ⟨aestronglyMeasurable_zero, by rw [eLpNorm_zero]; exact ENNReal.coe_lt_top⟩ @[simp] lemma MemLp.zero' : MemLp (fun _ : α => (0 : ε)) p μ := MemLp.zero @[deprecated (since := "2025-02-21")] alias Memℒp.zero' := MemLp.zero' @[deprecated (since := "2025-01-21")] alias zero_memℒp := MemLp.zero @[deprecated (since := "2025-01-21")] alias zero_mem_ℒp := MemLp.zero' variable [MeasurableSpace α] theorem eLpNorm'_measure_zero_of_pos {f : α → ε} (hq_pos : 0 < q) : eLpNorm' f q (0 : Measure α) = 0 := by simp [eLpNorm', hq_pos] theorem eLpNorm'_measure_zero_of_exponent_zero {f : α → ε} : eLpNorm' f 0 (0 : Measure α) = 1 := by simp [eLpNorm'] theorem eLpNorm'_measure_zero_of_neg {f : α → ε} (hq_neg : q < 0) : eLpNorm' f q (0 : Measure α) = ∞ := by simp [eLpNorm', hq_neg] end ENormedAddMonoid @[simp] theorem eLpNormEssSup_measure_zero {f : α → ε} : eLpNormEssSup f (0 : Measure α) = 0 := by simp [eLpNormEssSup] @[simp] theorem eLpNorm_measure_zero {f : α → ε} : eLpNorm f p (0 : Measure α) = 0 := by by_cases h0 : p = 0 · simp [h0] by_cases h_top : p = ∞ · simp [h_top] rw [← Ne] at h0 simp [eLpNorm_eq_eLpNorm' h0 h_top, eLpNorm', ENNReal.toReal_pos h0 h_top] section ContinuousENorm variable {ε : Type*} [TopologicalSpace ε] [ContinuousENorm ε] @[simp] lemma memLp_measure_zero {f : α → ε} : MemLp f p (0 : Measure α) := by simp [MemLp] @[deprecated (since := "2025-02-21")] alias memℒp_measure_zero := memLp_measure_zero end ContinuousENorm end Zero section Neg @[simp] theorem eLpNorm'_neg (f : α → F) (q : ℝ) (μ : Measure α) : eLpNorm' (-f) q μ = eLpNorm' f q μ := by simp [eLpNorm'_eq_lintegral_enorm] @[simp] theorem eLpNorm_neg (f : α → F) (p : ℝ≥0∞) (μ : Measure α) : eLpNorm (-f) p μ = eLpNorm f p μ := by by_cases h0 : p = 0 · simp [h0] by_cases h_top : p = ∞ · simp [h_top, eLpNormEssSup_eq_essSup_enorm] simp [eLpNorm_eq_eLpNorm' h0 h_top] lemma eLpNorm_sub_comm (f g : α → E) (p : ℝ≥0∞) (μ : Measure α) : eLpNorm (f - g) p μ = eLpNorm (g - f) p μ := by simp [← eLpNorm_neg (f := f - g)] theorem MemLp.neg {f : α → E} (hf : MemLp f p μ) : MemLp (-f) p μ := ⟨AEStronglyMeasurable.neg hf.1, by simp [hf.right]⟩ @[deprecated (since := "2025-02-21")] alias Memℒp.neg := MemLp.neg theorem memLp_neg_iff {f : α → E} : MemLp (-f) p μ ↔ MemLp f p μ := ⟨fun h => neg_neg f ▸ h.neg, MemLp.neg⟩ @[deprecated (since := "2025-02-21")] alias memℒp_neg_iff := memLp_neg_iff end Neg section Const variable {ε' ε'' : Type*} [TopologicalSpace ε'] [ContinuousENorm ε'] [TopologicalSpace ε''] [ENormedAddMonoid ε''] theorem eLpNorm'_const (c : ε) (hq_pos : 0 < q) : eLpNorm' (fun _ : α => c) q μ = ‖c‖ₑ * μ Set.univ ^ (1 / q) := by rw [eLpNorm'_eq_lintegral_enorm, lintegral_const, ENNReal.mul_rpow_of_nonneg _ _ (by simp [hq_pos.le] : 0 ≤ 1 / q)] congr rw [← ENNReal.rpow_mul] suffices hq_cancel : q * (1 / q) = 1 by rw [hq_cancel, ENNReal.rpow_one] rw [one_div, mul_inv_cancel₀ (ne_of_lt hq_pos).symm] -- Generalising this to ENormedAddMonoid requires a case analysis whether ‖c‖ₑ = ⊤, -- and will happen in a future PR. theorem eLpNorm'_const' [IsFiniteMeasure μ] (c : F) (hc_ne_zero : c ≠ 0) (hq_ne_zero : q ≠ 0) : eLpNorm' (fun _ : α => c) q μ = ‖c‖ₑ * μ Set.univ ^ (1 / q) := by rw [eLpNorm'_eq_lintegral_enorm, lintegral_const, ENNReal.mul_rpow_of_ne_top _ (measure_ne_top μ Set.univ)] · congr rw [← ENNReal.rpow_mul] suffices hp_cancel : q * (1 / q) = 1 by rw [hp_cancel, ENNReal.rpow_one] rw [one_div, mul_inv_cancel₀ hq_ne_zero] · rw [Ne, ENNReal.rpow_eq_top_iff, not_or, not_and_or, not_and_or] simp [hc_ne_zero] theorem eLpNormEssSup_const (c : ε) (hμ : μ ≠ 0) : eLpNormEssSup (fun _ : α => c) μ = ‖c‖ₑ := by rw [eLpNormEssSup_eq_essSup_enorm, essSup_const _ hμ] theorem eLpNorm'_const_of_isProbabilityMeasure (c : ε) (hq_pos : 0 < q) [IsProbabilityMeasure μ] : eLpNorm' (fun _ : α => c) q μ = ‖c‖ₑ := by simp [eLpNorm'_const c hq_pos, measure_univ] theorem eLpNorm_const (c : ε) (h0 : p ≠ 0) (hμ : μ ≠ 0) : eLpNorm (fun _ : α => c) p μ = ‖c‖ₑ * μ Set.univ ^ (1 / ENNReal.toReal p) := by by_cases h_top : p = ∞ · simp [h_top, eLpNormEssSup_const c hμ] simp [eLpNorm_eq_eLpNorm' h0 h_top, eLpNorm'_const, ENNReal.toReal_pos h0 h_top] theorem eLpNorm_const' (c : ε) (h0 : p ≠ 0) (h_top : p ≠ ∞) : eLpNorm (fun _ : α => c) p μ = ‖c‖ₑ * μ Set.univ ^ (1 / ENNReal.toReal p) := by simp [eLpNorm_eq_eLpNorm' h0 h_top, eLpNorm'_const, ENNReal.toReal_pos h0 h_top] -- NB. If ‖c‖ₑ = ∞ and μ is finite, this claim is false: the right has side is true, -- but the left hand side is false (as the norm is infinite). theorem eLpNorm_const_lt_top_iff_enorm {c : ε''} (hc' : ‖c‖ₑ ≠ ∞) {p : ℝ≥0∞} (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) : eLpNorm (fun _ : α ↦ c) p μ < ∞ ↔ c = 0 ∨ μ Set.univ < ∞ := by have hp : 0 < p.toReal := ENNReal.toReal_pos hp_ne_zero hp_ne_top by_cases hμ : μ = 0 · simp only [hμ, Measure.coe_zero, Pi.zero_apply, or_true, ENNReal.zero_lt_top, eLpNorm_measure_zero] by_cases hc : c = 0 · simp only [hc, true_or, eq_self_iff_true, ENNReal.zero_lt_top, eLpNorm_zero'] rw [eLpNorm_const' c hp_ne_zero hp_ne_top] obtain hμ_top | hμ_ne_top := eq_or_ne (μ .univ) ∞ · simp [hc, hμ_top, hp] rw [ENNReal.mul_lt_top_iff] simpa [hμ, hc, hμ_ne_top, hμ_ne_top.lt_top, hc, hc'.lt_top] using ENNReal.rpow_lt_top_of_nonneg (inv_nonneg.mpr hp.le) hμ_ne_top theorem eLpNorm_const_lt_top_iff {p : ℝ≥0∞} {c : F} (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) : eLpNorm (fun _ : α => c) p μ < ∞ ↔ c = 0 ∨ μ Set.univ < ∞ := eLpNorm_const_lt_top_iff_enorm enorm_ne_top hp_ne_zero hp_ne_top theorem memLp_const_enorm {c : ε'} (hc : ‖c‖ₑ ≠ ⊤) [IsFiniteMeasure μ] : MemLp (fun _ : α ↦ c) p μ := by refine ⟨aestronglyMeasurable_const, ?_⟩ by_cases h0 : p = 0 · simp [h0] by_cases hμ : μ = 0 · simp [hμ] rw [eLpNorm_const c h0 hμ] exact ENNReal.mul_lt_top hc.lt_top (ENNReal.rpow_lt_top_of_nonneg (by simp) (measure_ne_top μ Set.univ)) theorem memLp_const (c : E) [IsFiniteMeasure μ] : MemLp (fun _ : α => c) p μ := memLp_const_enorm enorm_ne_top @[deprecated (since := "2025-02-21")] alias memℒp_const := memLp_const theorem memLp_top_const_enorm {c : ε'} (hc : ‖c‖ₑ ≠ ⊤) : MemLp (fun _ : α ↦ c) ∞ μ := ⟨aestronglyMeasurable_const, by by_cases h : μ = 0 <;> simp [eLpNorm_const _, h, hc.lt_top]⟩ theorem memLp_top_const (c : E) : MemLp (fun _ : α => c) ∞ μ := memLp_top_const_enorm enorm_ne_top @[deprecated (since := "2025-02-21")] alias memℒp_top_const := memLp_top_const theorem memLp_const_iff_enorm {p : ℝ≥0∞} {c : ε''} (hc : ‖c‖ₑ ≠ ⊤) (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) : MemLp (fun _ : α ↦ c) p μ ↔ c = 0 ∨ μ Set.univ < ∞ := by simp_all [MemLp, aestronglyMeasurable_const, eLpNorm_const_lt_top_iff_enorm hc hp_ne_zero hp_ne_top] theorem memLp_const_iff {p : ℝ≥0∞} {c : E} (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) : MemLp (fun _ : α => c) p μ ↔ c = 0 ∨ μ Set.univ < ∞ := memLp_const_iff_enorm enorm_ne_top hp_ne_zero hp_ne_top @[deprecated (since := "2025-02-21")] alias memℒp_const_iff := memLp_const_iff end Const variable {f : α → F} lemma eLpNorm'_mono_enorm_ae {f : α → ε} {g : α → ε'} (hq : 0 ≤ q) (h : ∀ᵐ x ∂μ, ‖f x‖ₑ ≤ ‖g x‖ₑ) : eLpNorm' f q μ ≤ eLpNorm' g q μ := by simp only [eLpNorm'_eq_lintegral_enorm] gcongr ?_ ^ (1/q) refine lintegral_mono_ae (h.mono fun x hx => ?_) gcongr
lemma eLpNorm'_mono_nnnorm_ae {f : α → F} {g : α → G} (hq : 0 ≤ q) (h : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ ‖g x‖₊) : eLpNorm' f q μ ≤ eLpNorm' g q μ := by
Mathlib/MeasureTheory/Function/LpSeminorm/Basic.lean
323
325
/- 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.GeomSum import Mathlib.Algebra.GroupWithZero.Action.Defs import Mathlib.Algebra.GroupWithZero.NonZeroDivisors import Mathlib.Algebra.NoZeroSMulDivisors.Defs import Mathlib.Data.Nat.Choose.Sum import Mathlib.Data.Nat.Lattice import Mathlib.RingTheory.Nilpotent.Defs import Mathlib.Algebra.BigOperators.Finprod /-! # Nilpotent elements This file develops the basic theory of nilpotent elements. In particular it shows that the nilpotent elements are closed under many operations. For the definition of `nilradical`, see `Mathlib.RingTheory.Nilpotent.Lemmas`. ## Main definitions * `isNilpotent_neg_iff` * `Commute.isNilpotent_add` * `Commute.isNilpotent_sub` -/ universe u v open Function Set variable {R S : Type*} {x y : R} theorem IsNilpotent.neg [Ring R] (h : IsNilpotent x) : IsNilpotent (-x) := by obtain ⟨n, hn⟩ := h use n rw [neg_pow, hn, mul_zero] @[simp] theorem isNilpotent_neg_iff [Ring R] : IsNilpotent (-x) ↔ IsNilpotent x := ⟨fun h => neg_neg x ▸ h.neg, fun h => h.neg⟩ lemma IsNilpotent.smul [MonoidWithZero R] [MonoidWithZero S] [MulActionWithZero R S] [SMulCommClass R S S] [IsScalarTower R S S] {a : S} (ha : IsNilpotent a) (t : R) : IsNilpotent (t • a) := by obtain ⟨k, ha⟩ := ha use k rw [smul_pow, ha, smul_zero] theorem IsNilpotent.isUnit_sub_one [Ring R] {r : R} (hnil : IsNilpotent r) : IsUnit (r - 1) := by obtain ⟨n, hn⟩ := hnil refine ⟨⟨r - 1, -∑ i ∈ Finset.range n, r ^ i, ?_, ?_⟩, rfl⟩ · simp [mul_geom_sum, hn] · simp [geom_sum_mul, hn] theorem IsNilpotent.isUnit_one_sub [Ring R] {r : R} (hnil : IsNilpotent r) : IsUnit (1 - r) := by rw [← IsUnit.neg_iff, neg_sub] exact isUnit_sub_one hnil theorem IsNilpotent.isUnit_add_one [Ring R] {r : R} (hnil : IsNilpotent r) : IsUnit (r + 1) := by rw [← IsUnit.neg_iff, neg_add'] exact isUnit_sub_one hnil.neg theorem IsNilpotent.isUnit_one_add [Ring R] {r : R} (hnil : IsNilpotent r) : IsUnit (1 + r) := add_comm r 1 ▸ isUnit_add_one hnil theorem IsNilpotent.isUnit_add_left_of_commute [Ring R] {r u : R} (hnil : IsNilpotent r) (hu : IsUnit u) (h_comm : Commute r u) : IsUnit (u + r) := by rw [← Units.isUnit_mul_units _ hu.unit⁻¹, add_mul, IsUnit.mul_val_inv] replace h_comm : Commute r (↑hu.unit⁻¹) := Commute.units_inv_right h_comm refine IsNilpotent.isUnit_one_add ?_ exact (hu.unit⁻¹.isUnit.isNilpotent_mul_unit_of_commute_iff h_comm).mpr hnil theorem IsNilpotent.isUnit_add_right_of_commute [Ring R] {r u : R} (hnil : IsNilpotent r) (hu : IsUnit u) (h_comm : Commute r u) : IsUnit (r + u) := add_comm r u ▸ hnil.isUnit_add_left_of_commute hu h_comm lemma IsUnit.not_isNilpotent [Ring R] [Nontrivial R] {x : R} (hx : IsUnit x) : ¬ IsNilpotent x := by intro H simpa using H.isUnit_add_right_of_commute hx.neg (by simp) lemma IsNilpotent.not_isUnit [Ring R] [Nontrivial R] {x : R} (hx : IsNilpotent x) : ¬ IsUnit x := mt IsUnit.not_isNilpotent (by simpa only [not_not] using hx) lemma IsIdempotentElem.eq_zero_of_isNilpotent [MonoidWithZero R] {e : R} (idem : IsIdempotentElem e) (nilp : IsNilpotent e) : e = 0 := by obtain ⟨rfl | n, hn⟩ := nilp · rw [pow_zero] at hn; rw [← one_mul e, hn, zero_mul] · rw [← hn, idem.pow_succ_eq] alias IsNilpotent.eq_zero_of_isIdempotentElem := IsIdempotentElem.eq_zero_of_isNilpotent instance [Zero R] [Pow R ℕ] [Zero S] [Pow S ℕ] [IsReduced R] [IsReduced S] : IsReduced (R × S) where eq_zero _ := fun ⟨n, hn⟩ ↦ have hn := Prod.ext_iff.1 hn Prod.ext (IsReduced.eq_zero _ ⟨n, hn.1⟩) (IsReduced.eq_zero _ ⟨n, hn.2⟩) theorem Prime.isRadical [CommMonoidWithZero R] {y : R} (hy : Prime y) : IsRadical y := fun _ _ ↦ hy.dvd_of_dvd_pow theorem zero_isRadical_iff [MonoidWithZero R] : IsRadical (0 : R) ↔ IsReduced R := by simp_rw [isReduced_iff, IsNilpotent, exists_imp, ← zero_dvd_iff] exact forall_swap theorem isReduced_iff_pow_one_lt [MonoidWithZero R] (k : ℕ) (hk : 1 < k) : IsReduced R ↔ ∀ x : R, x ^ k = 0 → x = 0 := by simp_rw [← zero_isRadical_iff, isRadical_iff_pow_one_lt k hk, zero_dvd_iff] theorem IsRadical.of_dvd [CancelCommMonoidWithZero R] {x y : R} (hy : IsRadical y) (h0 : y ≠ 0) (hxy : x ∣ y) : IsRadical x := (isRadical_iff_pow_one_lt 2 one_lt_two).2 <| by obtain ⟨z, rfl⟩ := hxy refine fun w dvd ↦ ((mul_dvd_mul_iff_right <| right_ne_zero_of_mul h0).mp <| hy 2 _ ?_) rw [mul_pow, sq z]; exact mul_dvd_mul dvd (dvd_mul_left z z) namespace Commute section Semiring variable [Semiring R] theorem add_pow_eq_zero_of_add_le_succ_of_pow_eq_zero (h_comm : Commute x y) {m n k : ℕ} (hx : x ^ m = 0) (hy : y ^ n = 0) (h : m + n ≤ k + 1) : (x + y) ^ k = 0 := by rw [h_comm.add_pow'] apply Finset.sum_eq_zero rintro ⟨i, j⟩ hij suffices x ^ i * y ^ j = 0 by simp only [this, nsmul_eq_mul, mul_zero] by_cases hi : m ≤ i · rw [pow_eq_zero_of_le hi hx, zero_mul] rw [pow_eq_zero_of_le ?_ hy, mul_zero] linarith [Finset.mem_antidiagonal.mp hij] theorem add_pow_add_eq_zero_of_pow_eq_zero (h_comm : Commute x y) {m n : ℕ} (hx : x ^ m = 0) (hy : y ^ n = 0) : (x + y) ^ (m + n - 1) = 0 := h_comm.add_pow_eq_zero_of_add_le_succ_of_pow_eq_zero hx hy <| by rw [← Nat.sub_le_iff_le_add] theorem isNilpotent_add (h_comm : Commute x y) (hx : IsNilpotent x) (hy : IsNilpotent y) : IsNilpotent (x + y) := by obtain ⟨n, hn⟩ := hx obtain ⟨m, hm⟩ := hy exact ⟨_, add_pow_add_eq_zero_of_pow_eq_zero h_comm hn hm⟩ protected lemma isNilpotent_sum {ι : Type*} {s : Finset ι} {f : ι → R} (hnp : ∀ i ∈ s, IsNilpotent (f i)) (h_comm : ∀ i j, i ∈ s → j ∈ s → Commute (f i) (f j)) :
IsNilpotent (∑ i ∈ s, f i) := by classical induction s using Finset.induction with | empty => simp | insert j s hj ih => ?_ rw [Finset.sum_insert hj]
Mathlib/RingTheory/Nilpotent/Basic.lean
154
159
/- Copyright (c) 2024 Jeremy Tan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Tan -/ import Mathlib.Data.Int.Interval import Mathlib.Data.Int.ModEq import Mathlib.Data.Nat.Count import Mathlib.Data.Rat.Floor import Mathlib.Order.Interval.Finset.Nat /-! # Counting elements in an interval with given residue The theorems in this file generalise `Nat.card_multiples` in `Mathlib.Data.Nat.Factorization.Basic` to all integer intervals and any fixed residue (not just zero, which reduces to the multiples). Theorems are given for `Ico` and `Ioc` intervals. -/ open Finset Int namespace Int variable (a b : ℤ) {r : ℤ} lemma Ico_filter_modEq_eq (v : ℤ) : {x ∈ Ico a b | x ≡ v [ZMOD r]} = {x ∈ Ico (a - v) (b - v) | r ∣ x}.map ⟨(· + v), add_left_injective v⟩ := by ext x simp_rw [mem_map, mem_filter, mem_Ico, Function.Embedding.coeFn_mk, ← eq_sub_iff_add_eq, exists_eq_right, modEq_comm, modEq_iff_dvd, sub_lt_sub_iff_right, sub_le_sub_iff_right] lemma Ioc_filter_modEq_eq (v : ℤ) : {x ∈ Ioc a b | x ≡ v [ZMOD r]} = {x ∈ Ioc (a - v) (b - v) | r ∣ x}.map ⟨(· + v), add_left_injective v⟩ := by ext x simp_rw [mem_map, mem_filter, mem_Ioc, Function.Embedding.coeFn_mk, ← eq_sub_iff_add_eq, exists_eq_right, modEq_comm, modEq_iff_dvd, sub_lt_sub_iff_right, sub_le_sub_iff_right] variable (hr : 0 < r) include hr lemma Ico_filter_dvd_eq : {x ∈ Ico a b | r ∣ x} = (Ico ⌈a / (r : ℚ)⌉ ⌈b / (r : ℚ)⌉).map ⟨(· * r), mul_left_injective₀ hr.ne'⟩ := by ext x simp only [mem_map, mem_filter, mem_Ico, ceil_le, lt_ceil, div_le_iff₀, lt_div_iff₀, dvd_iff_exists_eq_mul_left, cast_pos.2 hr, ← cast_mul, cast_lt, cast_le]
aesop lemma Ioc_filter_dvd_eq : {x ∈ Ioc a b | r ∣ x} = (Ioc ⌊a / (r : ℚ)⌋ ⌊b / (r : ℚ)⌋).map ⟨(· * r), mul_left_injective₀ hr.ne'⟩ := by
Mathlib/Data/Int/CardIntervalMod.lean
51
55
/- 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.Data.Set.Piecewise import Mathlib.Logic.Equiv.Defs import Mathlib.Tactic.Core import Mathlib.Tactic.Attr.Core /-! # Partial equivalences This files defines equivalences between subsets of given types. An element `e` of `PartialEquiv α β` is made of two maps `e.toFun` and `e.invFun` respectively from α to β and from β to α (just like equivs), which are inverse to each other on the subsets `e.source` and `e.target` of respectively α and β. They are designed in particular to define charts on manifolds. The main functionality is `e.trans f`, which composes the two partial equivalences by restricting the source and target to the maximal set where the composition makes sense. As for equivs, we register a coercion to functions and use it in our simp normal form: we write `e x` and `e.symm y` instead of `e.toFun x` and `e.invFun y`. ## Main definitions * `Equiv.toPartialEquiv`: associating a partial equiv to an equiv, with source = target = univ * `PartialEquiv.symm`: the inverse of a partial equivalence * `PartialEquiv.trans`: the composition of two partial equivalences * `PartialEquiv.refl`: the identity partial equivalence * `PartialEquiv.ofSet`: the identity on a set `s` * `EqOnSource`: equivalence relation describing the "right" notion of equality for partial equivalences (see below in implementation notes) ## Implementation notes There are at least three possible implementations of partial equivalences: * equivs on subtypes * pairs of functions taking values in `Option α` and `Option β`, equal to none where the partial equivalence is not defined * pairs of functions defined everywhere, keeping the source and target as additional data Each of these implementations has pros and cons. * When dealing with subtypes, one still need to define additional API for composition and restriction of domains. Checking that one always belongs to the right subtype makes things very tedious, and leads quickly to DTT hell (as the subtype `u ∩ v` is not the "same" as `v ∩ u`, for instance). * With option-valued functions, the composition is very neat (it is just the usual composition, and the domain is restricted automatically). These are implemented in `PEquiv.lean`. For manifolds, where one wants to discuss thoroughly the smoothness of the maps, this creates however a lot of overhead as one would need to extend all classes of smoothness to option-valued maps. * The `PartialEquiv` version as explained above is easier to use for manifolds. The drawback is that there is extra useless data (the values of `toFun` and `invFun` outside of `source` and `target`). In particular, the equality notion between partial equivs is not "the right one", i.e., coinciding source and target and equality there. Moreover, there are no partial equivs in this sense between an empty type and a nonempty type. Since empty types are not that useful, and since one almost never needs to talk about equal partial equivs, this is not an issue in practice. Still, we introduce an equivalence relation `EqOnSource` that captures this right notion of equality, and show that many properties are invariant under this equivalence relation. ### Local coding conventions If a lemma deals with the intersection of a set with either source or target of a `PartialEquiv`, then it should use `e.source ∩ s` or `e.target ∩ t`, not `s ∩ e.source` or `t ∩ e.target`. -/ open Lean Meta Elab Tactic /-! Implementation of the `mfld_set_tac` tactic for working with the domains of partially-defined functions (`PartialEquiv`, `PartialHomeomorph`, etc). This is in a separate file from `Mathlib.Logic.Equiv.MfldSimpsAttr` because attributes need a new file to become functional. -/ /-- Common `@[simps]` configuration options used for manifold-related declarations. -/ def mfld_cfg : Simps.Config where attrs := [`mfld_simps] fullyApplied := false namespace Tactic.MfldSetTac /-- A very basic tactic to show that sets showing up in manifolds coincide or are included in one another. -/ elab (name := mfldSetTac) "mfld_set_tac" : tactic => withMainContext do let g ← getMainGoal let goalTy := (← instantiateMVars (← g.getDecl).type).getAppFnArgs match goalTy with | (``Eq, #[_ty, _e₁, _e₂]) => evalTactic (← `(tactic| ( apply Set.ext; intro my_y constructor <;> · intro h_my_y try simp only [*, mfld_simps] at h_my_y try simp only [*, mfld_simps]))) | (``Subset, #[_ty, _inst, _e₁, _e₂]) => evalTactic (← `(tactic| ( intro my_y h_my_y try simp only [*, mfld_simps] at h_my_y try simp only [*, mfld_simps]))) | _ => throwError "goal should be an equality or an inclusion" attribute [mfld_simps] and_true eq_self_iff_true Function.comp_apply end Tactic.MfldSetTac open Function Set variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} /-- Local equivalence between subsets `source` and `target` of `α` and `β` respectively. The (global) maps `toFun : α → β` and `invFun : β → α` map `source` to `target` and conversely, and are inverse to each other there. The values of `toFun` outside of `source` and of `invFun` outside of `target` are irrelevant. -/ structure PartialEquiv (α : Type*) (β : Type*) where /-- The global function which has a partial inverse. Its value outside of the `source` subset is irrelevant. -/ toFun : α → β /-- The partial inverse to `toFun`. Its value outside of the `target` subset is irrelevant. -/ invFun : β → α /-- The domain of the partial equivalence. -/ source : Set α /-- The codomain of the partial equivalence. -/ target : Set β /-- The proposition that elements of `source` are mapped to elements of `target`. -/ map_source' : ∀ ⦃x⦄, x ∈ source → toFun x ∈ target /-- The proposition that elements of `target` are mapped to elements of `source`. -/ map_target' : ∀ ⦃x⦄, x ∈ target → invFun x ∈ source /-- The proposition that `invFun` is a left-inverse of `toFun` on `source`. -/ left_inv' : ∀ ⦃x⦄, x ∈ source → invFun (toFun x) = x /-- The proposition that `invFun` is a right-inverse of `toFun` on `target`. -/ right_inv' : ∀ ⦃x⦄, x ∈ target → toFun (invFun x) = x attribute [coe] PartialEquiv.toFun namespace PartialEquiv variable (e : PartialEquiv α β) (e' : PartialEquiv β γ) instance [Inhabited α] [Inhabited β] : Inhabited (PartialEquiv α β) := ⟨⟨const α default, const β default, ∅, ∅, mapsTo_empty _ _, mapsTo_empty _ _, eqOn_empty _ _, eqOn_empty _ _⟩⟩ /-- The inverse of a partial equivalence -/ @[symm] protected def symm : PartialEquiv β α where toFun := e.invFun invFun := e.toFun source := e.target target := e.source map_source' := e.map_target' map_target' := e.map_source' left_inv' := e.right_inv' right_inv' := e.left_inv' instance : CoeFun (PartialEquiv α β) fun _ => α → β := ⟨PartialEquiv.toFun⟩ /-- See Note [custom simps projection] -/ def Simps.symm_apply (e : PartialEquiv α β) : β → α := e.symm initialize_simps_projections PartialEquiv (toFun → apply, invFun → symm_apply) theorem coe_mk (f : α → β) (g s t ml mr il ir) : (PartialEquiv.mk f g s t ml mr il ir : α → β) = f := rfl @[simp, mfld_simps] theorem coe_symm_mk (f : α → β) (g s t ml mr il ir) : ((PartialEquiv.mk f g s t ml mr il ir).symm : β → α) = g := rfl @[simp, mfld_simps] theorem invFun_as_coe : e.invFun = e.symm := rfl @[simp, mfld_simps] theorem map_source {x : α} (h : x ∈ e.source) : e x ∈ e.target := e.map_source' h /-- Variant of `e.map_source` and `map_source'`, stated for images of subsets of `source`. -/ lemma map_source'' : e '' e.source ⊆ e.target := fun _ ⟨_, hx, hex⟩ ↦ mem_of_eq_of_mem (id hex.symm) (e.map_source' hx) @[simp, mfld_simps] theorem map_target {x : β} (h : x ∈ e.target) : e.symm x ∈ e.source := e.map_target' h @[simp, mfld_simps] theorem left_inv {x : α} (h : x ∈ e.source) : e.symm (e x) = x := e.left_inv' h @[simp, mfld_simps] theorem right_inv {x : β} (h : x ∈ e.target) : e (e.symm x) = x := e.right_inv' h theorem eq_symm_apply {x : α} {y : β} (hx : x ∈ e.source) (hy : y ∈ e.target) : x = e.symm y ↔ e x = y := ⟨fun h => by rw [← e.right_inv hy, h], fun h => by rw [← e.left_inv hx, h]⟩ protected theorem mapsTo : MapsTo e e.source e.target := fun _ => e.map_source theorem symm_mapsTo : MapsTo e.symm e.target e.source := e.symm.mapsTo protected theorem leftInvOn : LeftInvOn e.symm e e.source := fun _ => e.left_inv protected theorem rightInvOn : RightInvOn e.symm e e.target := fun _ => e.right_inv protected theorem invOn : InvOn e.symm e e.source e.target := ⟨e.leftInvOn, e.rightInvOn⟩ protected theorem injOn : InjOn e e.source := e.leftInvOn.injOn protected theorem bijOn : BijOn e e.source e.target := e.invOn.bijOn e.mapsTo e.symm_mapsTo protected theorem surjOn : SurjOn e e.source e.target := e.bijOn.surjOn /-- Interpret an `Equiv` as a `PartialEquiv` by restricting it to `s` in the domain and to `t` in the codomain. -/ @[simps -fullyApplied] def _root_.Equiv.toPartialEquivOfImageEq (e : α ≃ β) (s : Set α) (t : Set β) (h : e '' s = t) : PartialEquiv α β where toFun := e invFun := e.symm source := s target := t map_source' _ hx := h ▸ mem_image_of_mem _ hx map_target' x hx := by subst t rcases hx with ⟨x, hx, rfl⟩ rwa [e.symm_apply_apply] left_inv' x _ := e.symm_apply_apply x right_inv' x _ := e.apply_symm_apply x /-- Associate a `PartialEquiv` to an `Equiv`. -/ @[simps! (config := mfld_cfg)] def _root_.Equiv.toPartialEquiv (e : α ≃ β) : PartialEquiv α β := e.toPartialEquivOfImageEq univ univ <| by rw [image_univ, e.surjective.range_eq] instance inhabitedOfEmpty [IsEmpty α] [IsEmpty β] : Inhabited (PartialEquiv α β) := ⟨((Equiv.equivEmpty α).trans (Equiv.equivEmpty β).symm).toPartialEquiv⟩ /-- Create a copy of a `PartialEquiv` providing better definitional equalities. -/ @[simps -fullyApplied] def copy (e : PartialEquiv α β) (f : α → β) (hf : ⇑e = f) (g : β → α) (hg : ⇑e.symm = g) (s : Set α) (hs : e.source = s) (t : Set β) (ht : e.target = t) : PartialEquiv α β where toFun := f invFun := g source := s target := t map_source' _ := ht ▸ hs ▸ hf ▸ e.map_source map_target' _ := hs ▸ ht ▸ hg ▸ e.map_target left_inv' _ := hs ▸ hf ▸ hg ▸ e.left_inv right_inv' _ := ht ▸ hf ▸ hg ▸ e.right_inv theorem copy_eq (e : PartialEquiv α β) (f : α → β) (hf : ⇑e = f) (g : β → α) (hg : ⇑e.symm = g) (s : Set α) (hs : e.source = s) (t : Set β) (ht : e.target = t) : e.copy f hf g hg s hs t ht = e := by substs f g s t cases e rfl /-- Associate to a `PartialEquiv` an `Equiv` between the source and the target. -/ protected def toEquiv : e.source ≃ e.target where toFun x := ⟨e x, e.map_source x.mem⟩ invFun y := ⟨e.symm y, e.map_target y.mem⟩ left_inv := fun ⟨_, hx⟩ => Subtype.eq <| e.left_inv hx right_inv := fun ⟨_, hy⟩ => Subtype.eq <| e.right_inv hy @[simp, mfld_simps] theorem symm_source : e.symm.source = e.target := rfl @[simp, mfld_simps] theorem symm_target : e.symm.target = e.source := rfl @[simp, mfld_simps] theorem symm_symm : e.symm.symm = e := rfl theorem symm_bijective : Function.Bijective (PartialEquiv.symm : PartialEquiv α β → PartialEquiv β α) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ theorem image_source_eq_target : e '' e.source = e.target := e.bijOn.image_eq theorem forall_mem_target {p : β → Prop} : (∀ y ∈ e.target, p y) ↔ ∀ x ∈ e.source, p (e x) := by rw [← image_source_eq_target, forall_mem_image] theorem exists_mem_target {p : β → Prop} : (∃ y ∈ e.target, p y) ↔ ∃ x ∈ e.source, p (e x) := by rw [← image_source_eq_target, exists_mem_image] /-- We say that `t : Set β` is an image of `s : Set α` under a partial equivalence if any of the following equivalent conditions hold: * `e '' (e.source ∩ s) = e.target ∩ t`; * `e.source ∩ e ⁻¹ t = e.source ∩ s`; * `∀ x ∈ e.source, e x ∈ t ↔ x ∈ s` (this one is used in the definition). -/ def IsImage (s : Set α) (t : Set β) : Prop := ∀ ⦃x⦄, x ∈ e.source → (e x ∈ t ↔ x ∈ s) namespace IsImage variable {e} {s : Set α} {t : Set β} {x : α} theorem apply_mem_iff (h : e.IsImage s t) (hx : x ∈ e.source) : e x ∈ t ↔ x ∈ s := h hx theorem symm_apply_mem_iff (h : e.IsImage s t) : ∀ ⦃y⦄, y ∈ e.target → (e.symm y ∈ s ↔ y ∈ t) := e.forall_mem_target.mpr fun x hx => by rw [e.left_inv hx, h hx] protected theorem symm (h : e.IsImage s t) : e.symm.IsImage t s := h.symm_apply_mem_iff @[simp] theorem symm_iff : e.symm.IsImage t s ↔ e.IsImage s t := ⟨fun h => h.symm, fun h => h.symm⟩ protected theorem mapsTo (h : e.IsImage s t) : MapsTo e (e.source ∩ s) (e.target ∩ t) := fun _ hx => ⟨e.mapsTo hx.1, (h hx.1).2 hx.2⟩ theorem symm_mapsTo (h : e.IsImage s t) : MapsTo e.symm (e.target ∩ t) (e.source ∩ s) := h.symm.mapsTo /-- Restrict a `PartialEquiv` to a pair of corresponding sets. -/ @[simps -fullyApplied] def restr (h : e.IsImage s t) : PartialEquiv α β where toFun := e invFun := e.symm source := e.source ∩ s target := e.target ∩ t map_source' := h.mapsTo map_target' := h.symm_mapsTo left_inv' := e.leftInvOn.mono inter_subset_left right_inv' := e.rightInvOn.mono inter_subset_left theorem image_eq (h : e.IsImage s t) : e '' (e.source ∩ s) = e.target ∩ t := h.restr.image_source_eq_target theorem symm_image_eq (h : e.IsImage s t) : e.symm '' (e.target ∩ t) = e.source ∩ s := h.symm.image_eq theorem iff_preimage_eq : e.IsImage s t ↔ e.source ∩ e ⁻¹' t = e.source ∩ s := by simp only [IsImage, Set.ext_iff, mem_inter_iff, mem_preimage, and_congr_right_iff] alias ⟨preimage_eq, of_preimage_eq⟩ := iff_preimage_eq theorem iff_symm_preimage_eq : e.IsImage s t ↔ e.target ∩ e.symm ⁻¹' s = e.target ∩ t := symm_iff.symm.trans iff_preimage_eq alias ⟨symm_preimage_eq, of_symm_preimage_eq⟩ := iff_symm_preimage_eq theorem of_image_eq (h : e '' (e.source ∩ s) = e.target ∩ t) : e.IsImage s t := of_symm_preimage_eq <| Eq.trans (of_symm_preimage_eq rfl).image_eq.symm h theorem of_symm_image_eq (h : e.symm '' (e.target ∩ t) = e.source ∩ s) : e.IsImage s t := of_preimage_eq <| Eq.trans (iff_preimage_eq.2 rfl).symm_image_eq.symm h protected theorem compl (h : e.IsImage s t) : e.IsImage sᶜ tᶜ := fun _ hx => not_congr (h hx) protected theorem inter {s' t'} (h : e.IsImage s t) (h' : e.IsImage s' t') : e.IsImage (s ∩ s') (t ∩ t') := fun _ hx => and_congr (h hx) (h' hx) protected theorem union {s' t'} (h : e.IsImage s t) (h' : e.IsImage s' t') : e.IsImage (s ∪ s') (t ∪ t') := fun _ hx => or_congr (h hx) (h' hx) protected theorem diff {s' t'} (h : e.IsImage s t) (h' : e.IsImage s' t') : e.IsImage (s \ s') (t \ t') := h.inter h'.compl theorem leftInvOn_piecewise {e' : PartialEquiv α β} [∀ i, Decidable (i ∈ s)] [∀ i, Decidable (i ∈ t)] (h : e.IsImage s t) (h' : e'.IsImage s t) : LeftInvOn (t.piecewise e.symm e'.symm) (s.piecewise e e') (s.ite e.source e'.source) := by rintro x (⟨he, hs⟩ | ⟨he, hs : x ∉ s⟩) · rw [piecewise_eq_of_mem _ _ _ hs, piecewise_eq_of_mem _ _ _ ((h he).2 hs), e.left_inv he] · rw [piecewise_eq_of_not_mem _ _ _ hs, piecewise_eq_of_not_mem _ _ _ ((h'.compl he).2 hs), e'.left_inv he] theorem inter_eq_of_inter_eq_of_eqOn {e' : PartialEquiv α β} (h : e.IsImage s t) (h' : e'.IsImage s t) (hs : e.source ∩ s = e'.source ∩ s) (heq : EqOn e e' (e.source ∩ s)) : e.target ∩ t = e'.target ∩ t := by rw [← h.image_eq, ← h'.image_eq, ← hs, heq.image_eq] theorem symm_eq_on_of_inter_eq_of_eqOn {e' : PartialEquiv α β} (h : e.IsImage s t) (hs : e.source ∩ s = e'.source ∩ s) (heq : EqOn e e' (e.source ∩ s)) : EqOn e.symm e'.symm (e.target ∩ t) := by rw [← h.image_eq] rintro y ⟨x, hx, rfl⟩ have hx' := hx; rw [hs] at hx' rw [e.left_inv hx.1, heq hx, e'.left_inv hx'.1] end IsImage theorem isImage_source_target : e.IsImage e.source e.target := fun x hx => by simp [hx] theorem isImage_source_target_of_disjoint (e' : PartialEquiv α β) (hs : Disjoint e.source e'.source) (ht : Disjoint e.target e'.target) : e.IsImage e'.source e'.target := IsImage.of_image_eq <| by rw [hs.inter_eq, ht.inter_eq, image_empty] theorem image_source_inter_eq' (s : Set α) : e '' (e.source ∩ s) = e.target ∩ e.symm ⁻¹' s := by rw [inter_comm, e.leftInvOn.image_inter', image_source_eq_target, inter_comm] theorem image_source_inter_eq (s : Set α) : e '' (e.source ∩ s) = e.target ∩ e.symm ⁻¹' (e.source ∩ s) := by rw [inter_comm, e.leftInvOn.image_inter, image_source_eq_target, inter_comm] theorem image_eq_target_inter_inv_preimage {s : Set α} (h : s ⊆ e.source) : e '' s = e.target ∩ e.symm ⁻¹' s := by rw [← e.image_source_inter_eq', inter_eq_self_of_subset_right h] theorem symm_image_eq_source_inter_preimage {s : Set β} (h : s ⊆ e.target) : e.symm '' s = e.source ∩ e ⁻¹' s := e.symm.image_eq_target_inter_inv_preimage h theorem symm_image_target_inter_eq (s : Set β) : e.symm '' (e.target ∩ s) = e.source ∩ e ⁻¹' (e.target ∩ s) := e.symm.image_source_inter_eq _ theorem symm_image_target_inter_eq' (s : Set β) : e.symm '' (e.target ∩ s) = e.source ∩ e ⁻¹' s := e.symm.image_source_inter_eq' _ theorem source_inter_preimage_inv_preimage (s : Set α) : e.source ∩ e ⁻¹' (e.symm ⁻¹' s) = e.source ∩ s := Set.ext fun x => and_congr_right_iff.2 fun hx => by simp only [mem_preimage, e.left_inv hx] theorem source_inter_preimage_target_inter (s : Set β) : e.source ∩ e ⁻¹' (e.target ∩ s) = e.source ∩ e ⁻¹' s := ext fun _ => ⟨fun hx => ⟨hx.1, hx.2.2⟩, fun hx => ⟨hx.1, e.map_source hx.1, hx.2⟩⟩ theorem target_inter_inv_preimage_preimage (s : Set β) : e.target ∩ e.symm ⁻¹' (e ⁻¹' s) = e.target ∩ s := e.symm.source_inter_preimage_inv_preimage _ theorem symm_image_image_of_subset_source {s : Set α} (h : s ⊆ e.source) : e.symm '' (e '' s) = s := (e.leftInvOn.mono h).image_image theorem image_symm_image_of_subset_target {s : Set β} (h : s ⊆ e.target) : e '' (e.symm '' s) = s := e.symm.symm_image_image_of_subset_source h theorem source_subset_preimage_target : e.source ⊆ e ⁻¹' e.target := e.mapsTo theorem symm_image_target_eq_source : e.symm '' e.target = e.source := e.symm.image_source_eq_target theorem target_subset_preimage_source : e.target ⊆ e.symm ⁻¹' e.source := e.symm_mapsTo /-- Two partial equivs that have the same `source`, same `toFun` and same `invFun`, coincide. -/ @[ext] protected theorem ext {e e' : PartialEquiv α β} (h : ∀ x, e x = e' x) (hsymm : ∀ x, e.symm x = e'.symm x) (hs : e.source = e'.source) : e = e' := by have A : (e : α → β) = e' := by ext x exact h x have B : (e.symm : β → α) = e'.symm := by ext x exact hsymm x have I : e '' e.source = e.target := e.image_source_eq_target have I' : e' '' e'.source = e'.target := e'.image_source_eq_target rw [A, hs, I'] at I cases e; cases e' simp_all /-- Restricting a partial equivalence to `e.source ∩ s` -/ protected def restr (s : Set α) : PartialEquiv α β := (@IsImage.of_symm_preimage_eq α β e s (e.symm ⁻¹' s) rfl).restr @[simp, mfld_simps] theorem restr_coe (s : Set α) : (e.restr s : α → β) = e := rfl @[simp, mfld_simps] theorem restr_coe_symm (s : Set α) : ((e.restr s).symm : β → α) = e.symm := rfl @[simp, mfld_simps] theorem restr_source (s : Set α) : (e.restr s).source = e.source ∩ s := rfl theorem source_restr_subset_source (s : Set α) : (e.restr s).source ⊆ e.source := inter_subset_left @[simp, mfld_simps] theorem restr_target (s : Set α) : (e.restr s).target = e.target ∩ e.symm ⁻¹' s := rfl theorem restr_eq_of_source_subset {e : PartialEquiv α β} {s : Set α} (h : e.source ⊆ s) : e.restr s = e := PartialEquiv.ext (fun _ => rfl) (fun _ => rfl) (by simp [inter_eq_self_of_subset_left h]) @[simp, mfld_simps] theorem restr_univ {e : PartialEquiv α β} : e.restr univ = e := restr_eq_of_source_subset (subset_univ _) /-- The identity partial equiv -/ protected def refl (α : Type*) : PartialEquiv α α := (Equiv.refl α).toPartialEquiv @[simp, mfld_simps] theorem refl_source : (PartialEquiv.refl α).source = univ := rfl @[simp, mfld_simps] theorem refl_target : (PartialEquiv.refl α).target = univ := rfl @[simp, mfld_simps] theorem refl_coe : (PartialEquiv.refl α : α → α) = id := rfl @[simp, mfld_simps] theorem refl_symm : (PartialEquiv.refl α).symm = PartialEquiv.refl α := rfl @[mfld_simps] theorem refl_restr_source (s : Set α) : ((PartialEquiv.refl α).restr s).source = s := by simp @[mfld_simps] theorem refl_restr_target (s : Set α) : ((PartialEquiv.refl α).restr s).target = s := by simp /-- The identity partial equivalence on a set `s` -/ def ofSet (s : Set α) : PartialEquiv α α where toFun := id invFun := id source := s target := s map_source' _ hx := hx map_target' _ hx := hx left_inv' _ _ := rfl right_inv' _ _ := rfl @[simp, mfld_simps] theorem ofSet_source (s : Set α) : (PartialEquiv.ofSet s).source = s := rfl @[simp, mfld_simps] theorem ofSet_target (s : Set α) : (PartialEquiv.ofSet s).target = s := rfl @[simp, mfld_simps] theorem ofSet_coe (s : Set α) : (PartialEquiv.ofSet s : α → α) = id := rfl @[simp, mfld_simps] theorem ofSet_symm (s : Set α) : (PartialEquiv.ofSet s).symm = PartialEquiv.ofSet s := rfl /-- `Function.const` as a `PartialEquiv`. It consists of two constant maps in opposite directions. -/ @[simps] def single (a : α) (b : β) : PartialEquiv α β where toFun := Function.const α b invFun := Function.const β a source := {a} target := {b} map_source' _ _ := rfl map_target' _ _ := rfl left_inv' a' ha' := by rw [eq_of_mem_singleton ha', const_apply] right_inv' b' hb' := by rw [eq_of_mem_singleton hb', const_apply] /-- Composing two partial equivs if the target of the first coincides with the source of the second. -/ @[simps] protected def trans' (e' : PartialEquiv β γ) (h : e.target = e'.source) : PartialEquiv α γ where toFun := e' ∘ e invFun := e.symm ∘ e'.symm source := e.source target := e'.target map_source' x hx := by simp [← h, hx] map_target' y hy := by simp [h, hy] left_inv' x hx := by simp [hx, ← h] right_inv' y hy := by simp [hy, h] /-- Composing two partial equivs, by restricting to the maximal domain where their composition is well defined. Within the `Manifold` namespace, there is the notation `e ≫ f` for this. -/ @[trans] protected def trans : PartialEquiv α γ := PartialEquiv.trans' (e.symm.restr e'.source).symm (e'.restr e.target) (inter_comm _ _) @[simp, mfld_simps] theorem coe_trans : (e.trans e' : α → γ) = e' ∘ e := rfl @[simp, mfld_simps] theorem coe_trans_symm : ((e.trans e').symm : γ → α) = e.symm ∘ e'.symm := rfl theorem trans_apply {x : α} : (e.trans e') x = e' (e x) := rfl theorem trans_symm_eq_symm_trans_symm : (e.trans e').symm = e'.symm.trans e.symm := by cases e; cases e'; rfl @[simp, mfld_simps] theorem trans_source : (e.trans e').source = e.source ∩ e ⁻¹' e'.source := rfl theorem trans_source' : (e.trans e').source = e.source ∩ e ⁻¹' (e.target ∩ e'.source) := by mfld_set_tac theorem trans_source'' : (e.trans e').source = e.symm '' (e.target ∩ e'.source) := by rw [e.trans_source', e.symm_image_target_inter_eq] theorem image_trans_source : e '' (e.trans e').source = e.target ∩ e'.source := (e.symm.restr e'.source).symm.image_source_eq_target @[simp, mfld_simps] theorem trans_target : (e.trans e').target = e'.target ∩ e'.symm ⁻¹' e.target := rfl theorem trans_target' : (e.trans e').target = e'.target ∩ e'.symm ⁻¹' (e'.source ∩ e.target) := trans_source' e'.symm e.symm theorem trans_target'' : (e.trans e').target = e' '' (e'.source ∩ e.target) := trans_source'' e'.symm e.symm theorem inv_image_trans_target : e'.symm '' (e.trans e').target = e'.source ∩ e.target := image_trans_source e'.symm e.symm theorem trans_assoc (e'' : PartialEquiv γ δ) : (e.trans e').trans e'' = e.trans (e'.trans e'') := PartialEquiv.ext (fun _ => rfl) (fun _ => rfl) (by simp [trans_source, @preimage_comp α β γ, inter_assoc]) @[simp, mfld_simps] theorem trans_refl : e.trans (PartialEquiv.refl β) = e := PartialEquiv.ext (fun _ => rfl) (fun _ => rfl) (by simp [trans_source]) @[simp, mfld_simps] theorem refl_trans : (PartialEquiv.refl α).trans e = e := PartialEquiv.ext (fun _ => rfl) (fun _ => rfl) (by simp [trans_source, preimage_id]) theorem trans_ofSet (s : Set β) : e.trans (ofSet s) = e.restr (e ⁻¹' s) := PartialEquiv.ext (fun _ => rfl) (fun _ => rfl) rfl theorem trans_refl_restr (s : Set β) : e.trans ((PartialEquiv.refl β).restr s) = e.restr (e ⁻¹' s) := PartialEquiv.ext (fun _ => rfl) (fun _ => rfl) (by simp [trans_source]) theorem trans_refl_restr' (s : Set β) : e.trans ((PartialEquiv.refl β).restr s) = e.restr (e.source ∩ e ⁻¹' s) := PartialEquiv.ext (fun _ => rfl) (fun _ => rfl) <| by simp only [trans_source, restr_source, refl_source, univ_inter] rw [← inter_assoc, inter_self] theorem restr_trans (s : Set α) : (e.restr s).trans e' = (e.trans e').restr s := PartialEquiv.ext (fun _ => rfl) (fun _ => rfl) <| by simp [trans_source, inter_comm, inter_assoc] /-- A lemma commonly useful when `e` and `e'` are charts of a manifold. -/ theorem mem_symm_trans_source {e' : PartialEquiv α γ} {x : α} (he : x ∈ e.source) (he' : x ∈ e'.source) : e x ∈ (e.symm.trans e').source := ⟨e.mapsTo he, by rwa [mem_preimage, PartialEquiv.symm_symm, e.left_inv he]⟩ /-- `EqOnSource e e'` means that `e` and `e'` have the same source, and coincide there. Then `e` and `e'` should really be considered the same partial equiv. -/ def EqOnSource (e e' : PartialEquiv α β) : Prop := e.source = e'.source ∧ e.source.EqOn e e' /-- `EqOnSource` is an equivalence relation. This instance provides the `≈` notation between two `PartialEquiv`s. -/ instance eqOnSourceSetoid : Setoid (PartialEquiv α β) where r := EqOnSource iseqv := by constructor <;> simp only [Equivalence, EqOnSource, EqOn] <;> aesop theorem eqOnSource_refl : e ≈ e := Setoid.refl _ /-- Two equivalent partial equivs have the same source. -/ theorem EqOnSource.source_eq {e e' : PartialEquiv α β} (h : e ≈ e') : e.source = e'.source := h.1 /-- Two equivalent partial equivs coincide on the source. -/ theorem EqOnSource.eqOn {e e' : PartialEquiv α β} (h : e ≈ e') : e.source.EqOn e e' := h.2 /-- Two equivalent partial equivs have the same target. -/ theorem EqOnSource.target_eq {e e' : PartialEquiv α β} (h : e ≈ e') : e.target = e'.target := by simp only [← image_source_eq_target, ← source_eq h, h.2.image_eq] /-- If two partial equivs are equivalent, so are their inverses. -/ theorem EqOnSource.symm' {e e' : PartialEquiv α β} (h : e ≈ e') : e.symm ≈ e'.symm := by refine ⟨target_eq h, eqOn_of_leftInvOn_of_rightInvOn e.leftInvOn ?_ ?_⟩ <;> simp only [symm_source, target_eq h, source_eq h, e'.symm_mapsTo] exact e'.rightInvOn.congr_right e'.symm_mapsTo (source_eq h ▸ h.eqOn.symm) /-- Two equivalent partial equivs have coinciding inverses on the target. -/ theorem EqOnSource.symm_eqOn {e e' : PartialEquiv α β} (h : e ≈ e') : EqOn e.symm e'.symm e.target := -- Porting note: `h.symm'` dot notation doesn't work anymore because `h` is not recognised as -- `PartialEquiv.EqOnSource` for some reason. eqOn (symm' h) /-- Composition of partial equivs respects equivalence. -/ theorem EqOnSource.trans' {e e' : PartialEquiv α β} {f f' : PartialEquiv β γ} (he : e ≈ e') (hf : f ≈ f') : e.trans f ≈ e'.trans f' := by constructor · rw [trans_source'', trans_source'', ← target_eq he, ← hf.1] exact (he.symm'.eqOn.mono inter_subset_left).image_eq · intro x hx rw [trans_source] at hx simp [Function.comp_apply, PartialEquiv.coe_trans, (he.2 hx.1).symm, hf.2 hx.2] /-- Restriction of partial equivs respects equivalence. -/ theorem EqOnSource.restr {e e' : PartialEquiv α β} (he : e ≈ e') (s : Set α) : e.restr s ≈ e'.restr s := by constructor · simp [he.1] · intro x hx simp only [mem_inter_iff, restr_source] at hx exact he.2 hx.1 /-- Preimages are respected by equivalence. -/
theorem EqOnSource.source_inter_preimage_eq {e e' : PartialEquiv α β} (he : e ≈ e') (s : Set β) : e.source ∩ e ⁻¹' s = e'.source ∩ e' ⁻¹' s := by rw [he.eqOn.inter_preimage_eq, source_eq he]
Mathlib/Logic/Equiv/PartialEquiv.lean
724
725
/- 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⟩
Mathlib/Combinatorics/SetFamily/Shatter.lean
64
66
/- Copyright (c) 2015 Nathaniel Thomas. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.GroupWithZero.Action.Defs import Mathlib.Algebra.Ring.Defs /-! # Modules over a ring In this file we define * `Module R M` : an additive commutative monoid `M` is a `Module` over a `Semiring R` if for `r : R` and `x : M` their "scalar multiplication" `r • x : M` is defined, and the operation `•` satisfies some natural associativity and distributivity axioms similar to those on a ring. ## Implementation notes In typical mathematical usage, our definition of `Module` corresponds to "semimodule", and the word "module" is reserved for `Module R M` where `R` is a `Ring` and `M` an `AddCommGroup`. If `R` is a `Field` and `M` an `AddCommGroup`, `M` would be called an `R`-vector space. Since those assumptions can be made by changing the typeclasses applied to `R` and `M`, without changing the axioms in `Module`, mathlib calls everything a `Module`. In older versions of mathlib3, we had separate abbreviations for semimodules and vector spaces. This caused inference issues in some cases, while not providing any real advantages, so we decided to use a canonical `Module` typeclass throughout. ## Tags semimodule, module, vector space -/ assert_not_exists Field Invertible Pi.single_smul₀ RingHom Set.indicator Multiset Units open Function Set universe u v variable {R S M M₂ : Type*} /-- A module is a generalization of vector spaces to a scalar semiring. It consists of a scalar semiring `R` and an additive monoid of "vectors" `M`, connected by a "scalar multiplication" operation `r • x : M` (where `r : R` and `x : M`) with some natural associativity and distributivity axioms similar to those on a ring. -/ @[ext] class Module (R : Type u) (M : Type v) [Semiring R] [AddCommMonoid M] extends DistribMulAction R M where /-- Scalar multiplication distributes over addition from the right. -/ protected add_smul : ∀ (r s : R) (x : M), (r + s) • x = r • x + s • x /-- Scalar multiplication by zero gives zero. -/ protected zero_smul : ∀ x : M, (0 : R) • x = 0 section AddCommMonoid variable [Semiring R] [AddCommMonoid M] [Module R M] (r s : R) (x : M) -- see Note [lower instance priority] /-- A module over a semiring automatically inherits a `MulActionWithZero` structure. -/ instance (priority := 100) Module.toMulActionWithZero {R M} {_ : Semiring R} {_ : AddCommMonoid M} [Module R M] : MulActionWithZero R M := { (inferInstance : MulAction R M) with smul_zero := smul_zero zero_smul := Module.zero_smul } theorem add_smul : (r + s) • x = r • x + s • x := Module.add_smul r s x theorem Convex.combo_self {a b : R} (h : a + b = 1) (x : M) : a • x + b • x = x := by rw [← add_smul, h, one_smul] variable (R) theorem two_smul : (2 : R) • x = x + x := by rw [← one_add_one_eq_two, add_smul, one_smul] /-- Pullback a `Module` structure along an injective additive monoid homomorphism. See note [reducible non-instances]. -/ protected abbrev Function.Injective.module [AddCommMonoid M₂] [SMul R M₂] (f : M₂ →+ M) (hf : Injective f) (smul : ∀ (c : R) (x), f (c • x) = c • f x) : Module R M₂ := { hf.distribMulAction f smul with add_smul := fun c₁ c₂ x => hf <| by simp only [smul, f.map_add, add_smul] zero_smul := fun x => hf <| by simp only [smul, zero_smul, f.map_zero] } /-- Pushforward a `Module` structure along a surjective additive monoid homomorphism. See note [reducible non-instances]. -/ protected abbrev Function.Surjective.module [AddCommMonoid M₂] [SMul R M₂] (f : M →+ M₂) (hf : Surjective f) (smul : ∀ (c : R) (x), f (c • x) = c • f x) : Module R M₂ := { toDistribMulAction := hf.distribMulAction f smul add_smul := fun c₁ c₂ x => by rcases hf x with ⟨x, rfl⟩ simp only [add_smul, ← smul, ← f.map_add] zero_smul := fun x => by rcases hf x with ⟨x, rfl⟩ rw [← f.map_zero, ← smul, zero_smul] } variable {R} theorem Module.eq_zero_of_zero_eq_one (zero_eq_one : (0 : R) = 1) : x = 0 := by rw [← one_smul R x, ← zero_eq_one, zero_smul] @[simp] theorem smul_add_one_sub_smul {R : Type*} [Ring R] [Module R M] {r : R} {m : M} : r • m + (1 - r) • m = m := by rw [← add_smul, add_sub_cancel, one_smul] end AddCommMonoid section AddCommGroup variable [Semiring R] [AddCommGroup M] theorem Convex.combo_eq_smul_sub_add [Module R M] {x y : M} {a b : R} (h : a + b = 1) : a • x + b • y = b • (y - x) + x := calc a • x + b • y = b • y - b • x + (a • x + b • x) := by rw [sub_add_add_cancel, add_comm] _ = b • (y - x) + x := by rw [smul_sub, Convex.combo_self h] end AddCommGroup -- We'll later use this to show `Module ℕ M` and `Module ℤ M` are subsingletons. /-- A variant of `Module.ext` that's convenient for term-mode. -/ theorem Module.ext' {R : Type*} [Semiring R] {M : Type*} [AddCommMonoid M] (P Q : Module R M) (w : ∀ (r : R) (m : M), (haveI := P; r • m) = (haveI := Q; r • m)) : P = Q := by ext exact w _ _ section Module variable [Ring R] [AddCommGroup M] [Module R M] (r : R) (x : M) @[simp] theorem neg_smul : -r • x = -(r • x) := eq_neg_of_add_eq_zero_left <| by rw [← add_smul, neg_add_cancel, zero_smul] theorem neg_smul_neg : -r • -x = r • x := by rw [neg_smul, smul_neg, neg_neg] variable (R) theorem neg_one_smul (x : M) : (-1 : R) • x = -x := by simp variable {R} theorem sub_smul (r s : R) (y : M) : (r - s) • y = r • y - s • y := by simp [add_smul, sub_eq_add_neg] end Module /-- A module over a `Subsingleton` semiring is a `Subsingleton`. We cannot register this as an instance because Lean has no way to guess `R`. -/ protected theorem Module.subsingleton (R M : Type*) [MonoidWithZero R] [Subsingleton R] [Zero M] [MulActionWithZero R M] : Subsingleton M := MulActionWithZero.subsingleton R M /-- A semiring is `Nontrivial` provided that there exists a nontrivial module over this semiring. -/ protected theorem Module.nontrivial (R M : Type*) [MonoidWithZero R] [Nontrivial M] [Zero M] [MulActionWithZero R M] : Nontrivial R := MulActionWithZero.nontrivial R M -- see Note [lower instance priority] instance (priority := 910) Semiring.toModule [Semiring R] : Module R R where smul_add := mul_add add_smul := add_mul zero_smul := zero_mul smul_zero := mul_zero instance [NonUnitalNonAssocSemiring R] : DistribSMul R R where smul_add := left_distrib
Mathlib/Algebra/Module/Defs.lean
540
542
/- 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] theorem range_sdiff_zero {n : ℕ} : range (n + 1) \ {0} = (range n).image Nat.succ := by induction' n with k hk · simp conv_rhs => rw [range_succ] rw [range_succ, image_insert, ← hk, insert_sdiff_of_not_mem] simp end Finset theorem Multiset.toFinset_map [DecidableEq α] [DecidableEq β] (f : α → β) (m : Multiset α) : (m.map f).toFinset = m.toFinset.image f := Finset.val_inj.1 (Multiset.dedup_map_dedup_eq _ _).symm namespace Equiv /-- Given an equivalence `α` to `β`, produce an equivalence between `Finset α` and `Finset β`. -/ protected def finsetCongr (e : α ≃ β) : Finset α ≃ Finset β where toFun s := s.map e.toEmbedding invFun s := s.map e.symm.toEmbedding left_inv s := by simp [Finset.map_map] right_inv s := by simp [Finset.map_map] @[simp] theorem finsetCongr_apply (e : α ≃ β) (s : Finset α) : e.finsetCongr s = s.map e.toEmbedding := rfl @[simp] theorem finsetCongr_refl : (Equiv.refl α).finsetCongr = Equiv.refl _ := by ext simp @[simp] theorem finsetCongr_symm (e : α ≃ β) : e.finsetCongr.symm = e.symm.finsetCongr := rfl @[simp] theorem finsetCongr_trans (e : α ≃ β) (e' : β ≃ γ) : e.finsetCongr.trans e'.finsetCongr = (e.trans e').finsetCongr := by ext simp [-Finset.mem_map, -Equiv.trans_toEmbedding] theorem finsetCongr_toEmbedding (e : α ≃ β) : e.finsetCongr.toEmbedding = (Finset.mapEmbedding e.toEmbedding).toEmbedding := rfl /-- Given a predicate `p : α → Prop`, produces an equivalence between `Finset {a : α // p a}` and `{s : Finset α // ∀ a ∈ s, p a}`. -/ @[simps] protected def finsetSubtypeComm (p : α → Prop) : Finset {a : α // p a} ≃ {s : Finset α // ∀ a ∈ s, p a} where toFun s := ⟨s.map ⟨fun a ↦ a.val, Subtype.val_injective⟩, fun _ h ↦ have ⟨v, _, h⟩ := Embedding.coeFn_mk _ _ ▸ mem_map.mp h; h ▸ v.property⟩ invFun s := s.val.attach.map (Subtype.impEmbedding _ _ s.property) left_inv s := by ext a; constructor <;> intro h <;> simp only [Finset.mem_map, Finset.mem_attach, true_and, Subtype.exists, Embedding.coeFn_mk, exists_and_right, exists_eq_right, Subtype.impEmbedding, Subtype.mk.injEq] at * · rcases h with ⟨_, ⟨_, h₁⟩, h₂⟩; exact h₂ ▸ h₁ · use a, ⟨a.property, h⟩ right_inv s := by ext a; constructor <;> intro h <;> simp only [Finset.mem_map, Finset.mem_attach, true_and, Subtype.exists, Embedding.coeFn_mk, exists_and_right, exists_eq_right, Subtype.impEmbedding, Subtype.mk.injEq] at * · rcases h with ⟨_, _, h₁, h₂⟩; exact h₂ ▸ h₁ · use s.property _ h, a end Equiv
Mathlib/Data/Finset/Image.lean
759
760
/- 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.Analytic.Within import Mathlib.Analysis.Calculus.FDeriv.Analytic import Mathlib.Analysis.Calculus.ContDiff.FTaylorSeries /-! # Higher differentiability A function is `C^1` on a domain if it is differentiable there, and its derivative is continuous. By induction, it is `C^n` if it is `C^{n-1}` and its (n-1)-th derivative is `C^1` there or, equivalently, if it is `C^1` and its derivative is `C^{n-1}`. It is `C^∞` if it is `C^n` for all n. Finally, it is `C^ω` if it is analytic (as well as all its derivative, which is automatic if the space is complete). We formalize these notions with predicates `ContDiffWithinAt`, `ContDiffAt`, `ContDiffOn` and `ContDiff` saying that the function is `C^n` within a set at a point, at a point, on a set and on the whole space respectively. To avoid the issue of choice when choosing a derivative in sets where the derivative is not necessarily unique, `ContDiffOn` is not defined directly in terms of the regularity of the specific choice `iteratedFDerivWithin 𝕜 n f s` inside `s`, but in terms of the existence of a nice sequence of derivatives, expressed with a predicate `HasFTaylorSeriesUpToOn` defined in the file `FTaylorSeries`. We prove basic properties of these notions. ## Main definitions and results Let `f : E → F` be a map between normed vector spaces over a nontrivially normed field `𝕜`. * `ContDiff 𝕜 n f`: expresses that `f` is `C^n`, i.e., it admits a Taylor series up to rank `n`. * `ContDiffOn 𝕜 n f s`: expresses that `f` is `C^n` in `s`. * `ContDiffAt 𝕜 n f x`: expresses that `f` is `C^n` around `x`. * `ContDiffWithinAt 𝕜 n f s x`: expresses that `f` is `C^n` around `x` within the set `s`. In sets of unique differentiability, `ContDiffOn 𝕜 n f s` can be expressed in terms of the properties of `iteratedFDerivWithin 𝕜 m f s` for `m ≤ n`. In the whole space, `ContDiff 𝕜 n f` can be expressed in terms of the properties of `iteratedFDeriv 𝕜 m f` for `m ≤ n`. ## Implementation notes The definitions in this file are designed to work on any field `𝕜`. They are sometimes slightly more complicated than the naive definitions one would guess from the intuition over the real or complex numbers, but they are designed to circumvent the lack of gluing properties and partitions of unity in general. In the usual situations, they coincide with the usual definitions. ### Definition of `C^n` functions in domains One could define `C^n` functions in a domain `s` by fixing an arbitrary choice of derivatives (this is what we do with `iteratedFDerivWithin`) and requiring that all these derivatives up to `n` are continuous. If the derivative is not unique, this could lead to strange behavior like two `C^n` functions `f` and `g` on `s` whose sum is not `C^n`. A better definition is thus to say that a function is `C^n` inside `s` if it admits a sequence of derivatives up to `n` inside `s`. This definition still has the problem that a function which is locally `C^n` would not need to be `C^n`, as different choices of sequences of derivatives around different points might possibly not be glued together to give a globally defined sequence of derivatives. (Note that this issue can not happen over reals, thanks to partition of unity, but the behavior over a general field is not so clear, and we want a definition for general fields). Also, there are locality problems for the order parameter: one could image a function which, for each `n`, has a nice sequence of derivatives up to order `n`, but they do not coincide for varying `n` and can therefore not be glued to give rise to an infinite sequence of derivatives. This would give a function which is `C^n` for all `n`, but not `C^∞`. We solve this issue by putting locality conditions in space and order in our definition of `ContDiffWithinAt` and `ContDiffOn`. The resulting definition is slightly more complicated to work with (in fact not so much), but it gives rise to completely satisfactory theorems. For instance, with this definition, a real function which is `C^m` (but not better) on `(-1/m, 1/m)` for each natural `m` is by definition `C^∞` at `0`. There is another issue with the definition of `ContDiffWithinAt 𝕜 n f s x`. We can require the existence and good behavior of derivatives up to order `n` on a neighborhood of `x` within `s`. However, this does not imply continuity or differentiability within `s` of the function at `x` when `x` does not belong to `s`. Therefore, we require such existence and good behavior on a neighborhood of `x` within `s ∪ {x}` (which appears as `insert x s` in this file). ## Notations We use the notation `E [×n]→L[𝕜] F` for the space of continuous multilinear maps on `E^n` with values in `F`. This is the space in which the `n`-th derivative of a function from `E` to `F` lives. In this file, we denote `(⊤ : ℕ∞) : WithTop ℕ∞` with `∞`, and `⊤ : WithTop ℕ∞` with `ω`. To avoid ambiguities with the two tops, the theorems name use either `infty` or `omega`. These notations are scoped in `ContDiff`. ## Tags derivative, differentiability, higher derivative, `C^n`, multilinear, Taylor series, formal series -/ noncomputable section open Set Fin Filter Function open scoped NNReal Topology ContDiff universe u uE uF uG uX variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] {E : Type uE} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type uF} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type uG} [NormedAddCommGroup G] [NormedSpace 𝕜 G] {X : Type uX} [NormedAddCommGroup X] [NormedSpace 𝕜 X] {s s₁ t u : Set E} {f f₁ : E → F} {g : F → G} {x x₀ : E} {c : F} {m n : WithTop ℕ∞} {p : E → FormalMultilinearSeries 𝕜 E F} /-! ### Smooth functions within a set around a point -/ variable (𝕜) in /-- A function is continuously differentiable up to order `n` within a set `s` at a point `x` if it admits continuous derivatives up to order `n` in a neighborhood of `x` in `s ∪ {x}`. For `n = ∞`, we only require that this holds up to any finite order (where the neighborhood may depend on the finite order we consider). For `n = ω`, we require the function to be analytic within `s` at `x`. The precise definition we give (all the derivatives should be analytic) is more involved to work around issues when the space is not complete, but it is equivalent when the space is complete. For instance, a real function which is `C^m` on `(-1/m, 1/m)` for each natural `m`, but not better, is `C^∞` at `0` within `univ`. -/ def ContDiffWithinAt (n : WithTop ℕ∞) (f : E → F) (s : Set E) (x : E) : Prop := match n with | ω => ∃ u ∈ 𝓝[insert x s] x, ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn ω f p u ∧ ∀ i, AnalyticOn 𝕜 (fun x ↦ p x i) u | (n : ℕ∞) => ∀ m : ℕ, m ≤ n → ∃ u ∈ 𝓝[insert x s] x, ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn m f p u lemma HasFTaylorSeriesUpToOn.analyticOn (hf : HasFTaylorSeriesUpToOn ω f p s) (h : AnalyticOn 𝕜 (fun x ↦ p x 0) s) : AnalyticOn 𝕜 f s := by have : AnalyticOn 𝕜 (fun x ↦ (continuousMultilinearCurryFin0 𝕜 E F) (p x 0)) s := (LinearIsometryEquiv.analyticOnNhd _ _ ).comp_analyticOn h (Set.mapsTo_univ _ _) exact this.congr (fun y hy ↦ (hf.zero_eq _ hy).symm) lemma ContDiffWithinAt.analyticOn (h : ContDiffWithinAt 𝕜 ω f s x) : ∃ u ∈ 𝓝[insert x s] x, AnalyticOn 𝕜 f u := by obtain ⟨u, hu, p, hp, h'p⟩ := h exact ⟨u, hu, hp.analyticOn (h'p 0)⟩ lemma ContDiffWithinAt.analyticWithinAt (h : ContDiffWithinAt 𝕜 ω f s x) : AnalyticWithinAt 𝕜 f s x := by obtain ⟨u, hu, hf⟩ := h.analyticOn have xu : x ∈ u := mem_of_mem_nhdsWithin (by simp) hu exact (hf x xu).mono_of_mem_nhdsWithin (nhdsWithin_mono _ (subset_insert _ _) hu) theorem contDiffWithinAt_omega_iff_analyticWithinAt [CompleteSpace F] : ContDiffWithinAt 𝕜 ω f s x ↔ AnalyticWithinAt 𝕜 f s x := by refine ⟨fun h ↦ h.analyticWithinAt, fun h ↦ ?_⟩ obtain ⟨u, hu, p, hp, h'p⟩ := h.exists_hasFTaylorSeriesUpToOn ω exact ⟨u, hu, p, hp.of_le le_top, fun i ↦ h'p i⟩ theorem contDiffWithinAt_nat {n : ℕ} : ContDiffWithinAt 𝕜 n f s x ↔ ∃ u ∈ 𝓝[insert x s] x, ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn n f p u := ⟨fun H => H n le_rfl, fun ⟨u, hu, p, hp⟩ _m hm => ⟨u, hu, p, hp.of_le (mod_cast hm)⟩⟩ /-- When `n` is either a natural number or `ω`, one can characterize the property of being `C^n` as the existence of a neighborhood on which there is a Taylor series up to order `n`, requiring in addition that its terms are analytic in the `ω` case. -/ lemma contDiffWithinAt_iff_of_ne_infty (hn : n ≠ ∞) : ContDiffWithinAt 𝕜 n f s x ↔ ∃ u ∈ 𝓝[insert x s] x, ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn n f p u ∧ (n = ω → ∀ i, AnalyticOn 𝕜 (fun x ↦ p x i) u) := by match n with | ω => simp [ContDiffWithinAt] | ∞ => simp at hn | (n : ℕ) => simp [contDiffWithinAt_nat] theorem ContDiffWithinAt.of_le (h : ContDiffWithinAt 𝕜 n f s x) (hmn : m ≤ n) : ContDiffWithinAt 𝕜 m f s x := by match n with | ω => match m with | ω => exact h | (m : ℕ∞) => intro k _ obtain ⟨u, hu, p, hp, -⟩ := h exact ⟨u, hu, p, hp.of_le le_top⟩ | (n : ℕ∞) => match m with | ω => simp at hmn | (m : ℕ∞) => exact fun k hk ↦ h k (le_trans hk (mod_cast hmn)) /-- In a complete space, a function which is analytic within a set at a point is also `C^ω` there. Note that the same statement for `AnalyticOn` does not require completeness, see `AnalyticOn.contDiffOn`. -/ theorem AnalyticWithinAt.contDiffWithinAt [CompleteSpace F] (h : AnalyticWithinAt 𝕜 f s x) : ContDiffWithinAt 𝕜 n f s x := (contDiffWithinAt_omega_iff_analyticWithinAt.2 h).of_le le_top theorem contDiffWithinAt_iff_forall_nat_le {n : ℕ∞} : ContDiffWithinAt 𝕜 n f s x ↔ ∀ m : ℕ, ↑m ≤ n → ContDiffWithinAt 𝕜 m f s x := ⟨fun H _ hm => H.of_le (mod_cast hm), fun H m hm => H m hm _ le_rfl⟩ theorem contDiffWithinAt_infty : ContDiffWithinAt 𝕜 ∞ f s x ↔ ∀ n : ℕ, ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_iff_forall_nat_le.trans <| by simp only [forall_prop_of_true, le_top] @[deprecated (since := "2024-11-25")] alias contDiffWithinAt_top := contDiffWithinAt_infty theorem ContDiffWithinAt.continuousWithinAt (h : ContDiffWithinAt 𝕜 n f s x) : ContinuousWithinAt f s x := by have := h.of_le (zero_le _) simp only [ContDiffWithinAt, nonpos_iff_eq_zero, Nat.cast_eq_zero, mem_pure, forall_eq, CharP.cast_eq_zero] at this rcases this with ⟨u, hu, p, H⟩ rw [mem_nhdsWithin_insert] at hu exact (H.continuousOn.continuousWithinAt hu.1).mono_of_mem_nhdsWithin hu.2 theorem ContDiffWithinAt.congr_of_eventuallyEq (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x := by match n with | ω => obtain ⟨u, hu, p, H, H'⟩ := h exact ⟨{x ∈ u | f₁ x = f x}, Filter.inter_mem hu (mem_nhdsWithin_insert.2 ⟨hx, h₁⟩), p, (H.mono (sep_subset _ _)).congr fun _ ↦ And.right, fun i ↦ (H' i).mono (sep_subset _ _)⟩ | (n : ℕ∞) => intro m hm let ⟨u, hu, p, H⟩ := h m hm exact ⟨{ x ∈ u | f₁ x = f x }, Filter.inter_mem hu (mem_nhdsWithin_insert.2 ⟨hx, h₁⟩), p, (H.mono (sep_subset _ _)).congr fun _ ↦ And.right⟩ theorem Filter.EventuallyEq.congr_contDiffWithinAt (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := ⟨fun H ↦ H.congr_of_eventuallyEq h₁.symm hx.symm, fun H ↦ H.congr_of_eventuallyEq h₁ hx⟩ theorem ContDiffWithinAt.congr_of_eventuallyEq_insert (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : f₁ =ᶠ[𝓝[insert x s] x] f) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr_of_eventuallyEq (nhdsWithin_mono x (subset_insert x s) h₁) (mem_of_mem_nhdsWithin (mem_insert x s) h₁ :) theorem Filter.EventuallyEq.congr_contDiffWithinAt_of_insert (h₁ : f₁ =ᶠ[𝓝[insert x s] x] f) : ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := ⟨fun H ↦ H.congr_of_eventuallyEq_insert h₁.symm, fun H ↦ H.congr_of_eventuallyEq_insert h₁⟩ theorem ContDiffWithinAt.congr_of_eventuallyEq_of_mem (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr_of_eventuallyEq h₁ <| h₁.self_of_nhdsWithin hx theorem Filter.EventuallyEq.congr_contDiffWithinAt_of_mem (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s): ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := ⟨fun H ↦ H.congr_of_eventuallyEq_of_mem h₁.symm hx, fun H ↦ H.congr_of_eventuallyEq_of_mem h₁ hx⟩ theorem ContDiffWithinAt.congr (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr_of_eventuallyEq (Filter.eventuallyEq_of_mem self_mem_nhdsWithin h₁) hx theorem contDiffWithinAt_congr (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := ⟨fun h' ↦ h'.congr (fun x hx ↦ (h₁ x hx).symm) hx.symm, fun h' ↦ h'.congr h₁ hx⟩ theorem ContDiffWithinAt.congr_of_mem (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr h₁ (h₁ _ hx) theorem contDiffWithinAt_congr_of_mem (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_congr h₁ (h₁ x hx) theorem ContDiffWithinAt.congr_of_insert (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : ∀ y ∈ insert x s, f₁ y = f y) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr (fun y hy ↦ h₁ y (mem_insert_of_mem _ hy)) (h₁ x (mem_insert _ _)) theorem contDiffWithinAt_congr_of_insert (h₁ : ∀ y ∈ insert x s, f₁ y = f y) : ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_congr (fun y hy ↦ h₁ y (mem_insert_of_mem _ hy)) (h₁ x (mem_insert _ _)) theorem ContDiffWithinAt.mono_of_mem_nhdsWithin (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E} (hst : s ∈ 𝓝[t] x) : ContDiffWithinAt 𝕜 n f t x := by match n with | ω => obtain ⟨u, hu, p, H, H'⟩ := h exact ⟨u, nhdsWithin_le_of_mem (insert_mem_nhdsWithin_insert hst) hu, p, H, H'⟩ | (n : ℕ∞) => intro m hm rcases h m hm with ⟨u, hu, p, H⟩ exact ⟨u, nhdsWithin_le_of_mem (insert_mem_nhdsWithin_insert hst) hu, p, H⟩ @[deprecated (since := "2024-10-30")] alias ContDiffWithinAt.mono_of_mem := ContDiffWithinAt.mono_of_mem_nhdsWithin theorem ContDiffWithinAt.mono (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E} (hst : t ⊆ s) : ContDiffWithinAt 𝕜 n f t x := h.mono_of_mem_nhdsWithin <| Filter.mem_of_superset self_mem_nhdsWithin hst theorem ContDiffWithinAt.congr_mono (h : ContDiffWithinAt 𝕜 n f s x) (h' : EqOn f₁ f s₁) (h₁ : s₁ ⊆ s) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s₁ x := (h.mono h₁).congr h' hx theorem ContDiffWithinAt.congr_set (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E} (hst : s =ᶠ[𝓝 x] t) : ContDiffWithinAt 𝕜 n f t x := by rw [← nhdsWithin_eq_iff_eventuallyEq] at hst apply h.mono_of_mem_nhdsWithin <| hst ▸ self_mem_nhdsWithin @[deprecated (since := "2024-10-23")] alias ContDiffWithinAt.congr_nhds := ContDiffWithinAt.congr_set theorem contDiffWithinAt_congr_set {t : Set E} (hst : s =ᶠ[𝓝 x] t) : ContDiffWithinAt 𝕜 n f s x ↔ ContDiffWithinAt 𝕜 n f t x := ⟨fun h => h.congr_set hst, fun h => h.congr_set hst.symm⟩ @[deprecated (since := "2024-10-23")] alias contDiffWithinAt_congr_nhds := contDiffWithinAt_congr_set theorem contDiffWithinAt_inter' (h : t ∈ 𝓝[s] x) : ContDiffWithinAt 𝕜 n f (s ∩ t) x ↔ ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_congr_set (mem_nhdsWithin_iff_eventuallyEq.1 h).symm theorem contDiffWithinAt_inter (h : t ∈ 𝓝 x) : ContDiffWithinAt 𝕜 n f (s ∩ t) x ↔ ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_inter' (mem_nhdsWithin_of_mem_nhds h) theorem contDiffWithinAt_insert_self : ContDiffWithinAt 𝕜 n f (insert x s) x ↔ ContDiffWithinAt 𝕜 n f s x := by match n with | ω => simp [ContDiffWithinAt] | (n : ℕ∞) => simp_rw [ContDiffWithinAt, insert_idem] theorem contDiffWithinAt_insert {y : E} : ContDiffWithinAt 𝕜 n f (insert y s) x ↔ ContDiffWithinAt 𝕜 n f s x := by rcases eq_or_ne x y with (rfl | hx) · exact contDiffWithinAt_insert_self refine ⟨fun h ↦ h.mono (subset_insert _ _), fun h ↦ ?_⟩ apply h.mono_of_mem_nhdsWithin simp [nhdsWithin_insert_of_ne hx, self_mem_nhdsWithin] alias ⟨ContDiffWithinAt.of_insert, ContDiffWithinAt.insert'⟩ := contDiffWithinAt_insert protected theorem ContDiffWithinAt.insert (h : ContDiffWithinAt 𝕜 n f s x) : ContDiffWithinAt 𝕜 n f (insert x s) x := h.insert' theorem contDiffWithinAt_diff_singleton {y : E} : ContDiffWithinAt 𝕜 n f (s \ {y}) x ↔ ContDiffWithinAt 𝕜 n f s x := by rw [← contDiffWithinAt_insert, insert_diff_singleton, contDiffWithinAt_insert] /-- If a function is `C^n` within a set at a point, with `n ≥ 1`, then it is differentiable within this set at this point. -/ theorem ContDiffWithinAt.differentiableWithinAt' (h : ContDiffWithinAt 𝕜 n f s x) (hn : 1 ≤ n) : DifferentiableWithinAt 𝕜 f (insert x s) x := by rcases contDiffWithinAt_nat.1 (h.of_le hn) with ⟨u, hu, p, H⟩ rcases mem_nhdsWithin.1 hu with ⟨t, t_open, xt, tu⟩ rw [inter_comm] at tu exact (differentiableWithinAt_inter (IsOpen.mem_nhds t_open xt)).1 <| ((H.mono tu).differentiableOn le_rfl) x ⟨mem_insert x s, xt⟩ theorem ContDiffWithinAt.differentiableWithinAt (h : ContDiffWithinAt 𝕜 n f s x) (hn : 1 ≤ n) : DifferentiableWithinAt 𝕜 f s x := (h.differentiableWithinAt' hn).mono (subset_insert x s) /-- A function is `C^(n + 1)` on a domain iff locally, it has a derivative which is `C^n` (and moreover the function is analytic when `n = ω`). -/ theorem contDiffWithinAt_succ_iff_hasFDerivWithinAt (hn : n ≠ ∞) : ContDiffWithinAt 𝕜 (n + 1) f s x ↔ ∃ u ∈ 𝓝[insert x s] x, (n = ω → AnalyticOn 𝕜 f u) ∧ ∃ f' : E → E →L[𝕜] F, (∀ x ∈ u, HasFDerivWithinAt f (f' x) u x) ∧ ContDiffWithinAt 𝕜 n f' u x := by have h'n : n + 1 ≠ ∞ := by simpa using hn constructor · intro h rcases (contDiffWithinAt_iff_of_ne_infty h'n).1 h with ⟨u, hu, p, Hp, H'p⟩ refine ⟨u, hu, ?_, fun y => (continuousMultilinearCurryFin1 𝕜 E F) (p y 1), fun y hy => Hp.hasFDerivWithinAt le_add_self hy, ?_⟩ · rintro rfl exact Hp.analyticOn (H'p rfl 0) apply (contDiffWithinAt_iff_of_ne_infty hn).2 refine ⟨u, ?_, fun y : E => (p y).shift, ?_⟩ · convert @self_mem_nhdsWithin _ _ x u have : x ∈ insert x s := by simp exact insert_eq_of_mem (mem_of_mem_nhdsWithin this hu) · rw [hasFTaylorSeriesUpToOn_succ_iff_right] at Hp refine ⟨Hp.2.2, ?_⟩ rintro rfl i change AnalyticOn 𝕜 (fun x ↦ (continuousMultilinearCurryRightEquiv' 𝕜 i E F) (p x (i + 1))) u apply (LinearIsometryEquiv.analyticOnNhd _ _).comp_analyticOn ?_ (Set.mapsTo_univ _ _) exact H'p rfl _ · rintro ⟨u, hu, hf, f', f'_eq_deriv, Hf'⟩ rw [contDiffWithinAt_iff_of_ne_infty h'n] rcases (contDiffWithinAt_iff_of_ne_infty hn).1 Hf' with ⟨v, hv, p', Hp', p'_an⟩ refine ⟨v ∩ u, ?_, fun x => (p' x).unshift (f x), ?_, ?_⟩ · apply Filter.inter_mem _ hu apply nhdsWithin_le_of_mem hu exact nhdsWithin_mono _ (subset_insert x u) hv · rw [hasFTaylorSeriesUpToOn_succ_iff_right] refine ⟨fun y _ => rfl, fun y hy => ?_, ?_⟩ · change HasFDerivWithinAt (fun z => (continuousMultilinearCurryFin0 𝕜 E F).symm (f z)) (FormalMultilinearSeries.unshift (p' y) (f y) 1).curryLeft (v ∩ u) y rw [← Function.comp_def _ f, LinearIsometryEquiv.comp_hasFDerivWithinAt_iff'] convert (f'_eq_deriv y hy.2).mono inter_subset_right rw [← Hp'.zero_eq y hy.1] ext z change ((p' y 0) (init (@cons 0 (fun _ => E) z 0))) (@cons 0 (fun _ => E) z 0 (last 0)) = ((p' y 0) 0) z congr norm_num [eq_iff_true_of_subsingleton] · convert (Hp'.mono inter_subset_left).congr fun x hx => Hp'.zero_eq x hx.1 using 1 · ext x y change p' x 0 (init (@snoc 0 (fun _ : Fin 1 => E) 0 y)) y = p' x 0 0 y rw [init_snoc] · ext x k v y change p' x k (init (@snoc k (fun _ : Fin k.succ => E) v y)) (@snoc k (fun _ : Fin k.succ => E) v y (last k)) = p' x k v y rw [snoc_last, init_snoc] · intro h i simp only [WithTop.add_eq_top, WithTop.one_ne_top, or_false] at h match i with | 0 => simp only [FormalMultilinearSeries.unshift] apply AnalyticOnNhd.comp_analyticOn _ ((hf h).mono inter_subset_right) (Set.mapsTo_univ _ _) exact LinearIsometryEquiv.analyticOnNhd _ _ | i + 1 => simp only [FormalMultilinearSeries.unshift, Nat.succ_eq_add_one] apply AnalyticOnNhd.comp_analyticOn _ ((p'_an h i).mono inter_subset_left) (Set.mapsTo_univ _ _) exact LinearIsometryEquiv.analyticOnNhd _ _ /-- A version of `contDiffWithinAt_succ_iff_hasFDerivWithinAt` where all derivatives are taken within the same set. -/ theorem contDiffWithinAt_succ_iff_hasFDerivWithinAt' (hn : n ≠ ∞) : ContDiffWithinAt 𝕜 (n + 1) f s x ↔ ∃ u ∈ 𝓝[insert x s] x, u ⊆ insert x s ∧ (n = ω → AnalyticOn 𝕜 f u) ∧ ∃ f' : E → E →L[𝕜] F, (∀ x ∈ u, HasFDerivWithinAt f (f' x) s x) ∧ ContDiffWithinAt 𝕜 n f' s x := by refine ⟨fun hf => ?_, ?_⟩ · obtain ⟨u, hu, f_an, f', huf', hf'⟩ := (contDiffWithinAt_succ_iff_hasFDerivWithinAt hn).mp hf obtain ⟨w, hw, hxw, hwu⟩ := mem_nhdsWithin.mp hu rw [inter_comm] at hwu refine ⟨insert x s ∩ w, inter_mem_nhdsWithin _ (hw.mem_nhds hxw), inter_subset_left, ?_, f', fun y hy => ?_, ?_⟩ · intro h apply (f_an h).mono hwu · refine ((huf' y <| hwu hy).mono hwu).mono_of_mem_nhdsWithin ?_ refine mem_of_superset ?_ (inter_subset_inter_left _ (subset_insert _ _)) exact inter_mem_nhdsWithin _ (hw.mem_nhds hy.2) · exact hf'.mono_of_mem_nhdsWithin (nhdsWithin_mono _ (subset_insert _ _) hu) · rw [← contDiffWithinAt_insert, contDiffWithinAt_succ_iff_hasFDerivWithinAt hn, insert_eq_of_mem (mem_insert _ _)] rintro ⟨u, hu, hus, f_an, f', huf', hf'⟩ exact ⟨u, hu, f_an, f', fun y hy => (huf' y hy).insert'.mono hus, hf'.insert.mono hus⟩ /-! ### Smooth functions within a set -/ variable (𝕜) in /-- A function is continuously differentiable up to `n` on `s` if, for any point `x` in `s`, it admits continuous derivatives up to order `n` on a neighborhood of `x` in `s`. For `n = ∞`, we only require that this holds up to any finite order (where the neighborhood may depend on the finite order we consider). -/ def ContDiffOn (n : WithTop ℕ∞) (f : E → F) (s : Set E) : Prop := ∀ x ∈ s, ContDiffWithinAt 𝕜 n f s x theorem HasFTaylorSeriesUpToOn.contDiffOn {n : ℕ∞} {f' : E → FormalMultilinearSeries 𝕜 E F} (hf : HasFTaylorSeriesUpToOn n f f' s) : ContDiffOn 𝕜 n f s := by intro x hx m hm use s simp only [Set.insert_eq_of_mem hx, self_mem_nhdsWithin, true_and] exact ⟨f', hf.of_le (mod_cast hm)⟩ theorem ContDiffOn.contDiffWithinAt (h : ContDiffOn 𝕜 n f s) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f s x := h x hx theorem ContDiffOn.of_le (h : ContDiffOn 𝕜 n f s) (hmn : m ≤ n) : ContDiffOn 𝕜 m f s := fun x hx => (h x hx).of_le hmn theorem ContDiffWithinAt.contDiffOn' (hm : m ≤ n) (h' : m = ∞ → n = ω) (h : ContDiffWithinAt 𝕜 n f s x) : ∃ u, IsOpen u ∧ x ∈ u ∧ ContDiffOn 𝕜 m f (insert x s ∩ u) := by rcases eq_or_ne n ω with rfl | hn · obtain ⟨t, ht, p, hp, h'p⟩ := h rcases mem_nhdsWithin.1 ht with ⟨u, huo, hxu, hut⟩ rw [inter_comm] at hut refine ⟨u, huo, hxu, ?_⟩ suffices ContDiffOn 𝕜 ω f (insert x s ∩ u) from this.of_le le_top intro y hy refine ⟨insert x s ∩ u, ?_, p, hp.mono hut, fun i ↦ (h'p i).mono hut⟩ simp only [insert_eq_of_mem, hy, self_mem_nhdsWithin] · match m with | ω => simp [hn] at hm | ∞ => exact (hn (h' rfl)).elim | (m : ℕ) => rcases contDiffWithinAt_nat.1 (h.of_le hm) with ⟨t, ht, p, hp⟩ rcases mem_nhdsWithin.1 ht with ⟨u, huo, hxu, hut⟩ rw [inter_comm] at hut exact ⟨u, huo, hxu, (hp.mono hut).contDiffOn⟩ theorem ContDiffWithinAt.contDiffOn (hm : m ≤ n) (h' : m = ∞ → n = ω) (h : ContDiffWithinAt 𝕜 n f s x) : ∃ u ∈ 𝓝[insert x s] x, u ⊆ insert x s ∧ ContDiffOn 𝕜 m f u := by obtain ⟨_u, uo, xu, h⟩ := h.contDiffOn' hm h' exact ⟨_, inter_mem_nhdsWithin _ (uo.mem_nhds xu), inter_subset_left, h⟩ theorem ContDiffOn.analyticOn (h : ContDiffOn 𝕜 ω f s) : AnalyticOn 𝕜 f s := fun x hx ↦ (h x hx).analyticWithinAt /-- A function is `C^n` within a set at a point, for `n : ℕ`, if and only if it is `C^n` on a neighborhood of this point. -/ theorem contDiffWithinAt_iff_contDiffOn_nhds (hn : n ≠ ∞) : ContDiffWithinAt 𝕜 n f s x ↔ ∃ u ∈ 𝓝[insert x s] x, ContDiffOn 𝕜 n f u := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rcases h.contDiffOn le_rfl (by simp [hn]) with ⟨u, hu, h'u⟩ exact ⟨u, hu, h'u.2⟩ · rcases h with ⟨u, u_mem, hu⟩ have : x ∈ u := mem_of_mem_nhdsWithin (mem_insert x s) u_mem exact (hu x this).mono_of_mem_nhdsWithin (nhdsWithin_mono _ (subset_insert x s) u_mem) protected theorem ContDiffWithinAt.eventually (h : ContDiffWithinAt 𝕜 n f s x) (hn : n ≠ ∞) : ∀ᶠ y in 𝓝[insert x s] x, ContDiffWithinAt 𝕜 n f s y := by rcases h.contDiffOn le_rfl (by simp [hn]) with ⟨u, hu, _, hd⟩ have : ∀ᶠ y : E in 𝓝[insert x s] x, u ∈ 𝓝[insert x s] y ∧ y ∈ u := (eventually_eventually_nhdsWithin.2 hu).and hu refine this.mono fun y hy => (hd y hy.2).mono_of_mem_nhdsWithin ?_ exact nhdsWithin_mono y (subset_insert _ _) hy.1 theorem ContDiffOn.of_succ (h : ContDiffOn 𝕜 (n + 1) f s) : ContDiffOn 𝕜 n f s := h.of_le le_self_add theorem ContDiffOn.one_of_succ (h : ContDiffOn 𝕜 (n + 1) f s) : ContDiffOn 𝕜 1 f s := h.of_le le_add_self theorem contDiffOn_iff_forall_nat_le {n : ℕ∞} : ContDiffOn 𝕜 n f s ↔ ∀ m : ℕ, ↑m ≤ n → ContDiffOn 𝕜 m f s := ⟨fun H _ hm => H.of_le (mod_cast hm), fun H x hx m hm => H m hm x hx m le_rfl⟩ theorem contDiffOn_infty : ContDiffOn 𝕜 ∞ f s ↔ ∀ n : ℕ, ContDiffOn 𝕜 n f s := contDiffOn_iff_forall_nat_le.trans <| by simp only [le_top, forall_prop_of_true] @[deprecated (since := "2024-11-27")] alias contDiffOn_top := contDiffOn_infty @[deprecated (since := "2024-11-27")] alias contDiffOn_infty_iff_contDiffOn_omega := contDiffOn_infty theorem contDiffOn_all_iff_nat : (∀ (n : ℕ∞), ContDiffOn 𝕜 n f s) ↔ ∀ n : ℕ, ContDiffOn 𝕜 n f s := by refine ⟨fun H n => H n, ?_⟩ rintro H (_ | n) exacts [contDiffOn_infty.2 H, H n] theorem ContDiffOn.continuousOn (h : ContDiffOn 𝕜 n f s) : ContinuousOn f s := fun x hx => (h x hx).continuousWithinAt theorem ContDiffOn.congr (h : ContDiffOn 𝕜 n f s) (h₁ : ∀ x ∈ s, f₁ x = f x) : ContDiffOn 𝕜 n f₁ s := fun x hx => (h x hx).congr h₁ (h₁ x hx) theorem contDiffOn_congr (h₁ : ∀ x ∈ s, f₁ x = f x) : ContDiffOn 𝕜 n f₁ s ↔ ContDiffOn 𝕜 n f s := ⟨fun H => H.congr fun x hx => (h₁ x hx).symm, fun H => H.congr h₁⟩ theorem ContDiffOn.mono (h : ContDiffOn 𝕜 n f s) {t : Set E} (hst : t ⊆ s) : ContDiffOn 𝕜 n f t := fun x hx => (h x (hst hx)).mono hst theorem ContDiffOn.congr_mono (hf : ContDiffOn 𝕜 n f s) (h₁ : ∀ x ∈ s₁, f₁ x = f x) (hs : s₁ ⊆ s) : ContDiffOn 𝕜 n f₁ s₁ := (hf.mono hs).congr h₁ /-- If a function is `C^n` on a set with `n ≥ 1`, then it is differentiable there. -/ theorem ContDiffOn.differentiableOn (h : ContDiffOn 𝕜 n f s) (hn : 1 ≤ n) : DifferentiableOn 𝕜 f s := fun x hx => (h x hx).differentiableWithinAt hn /-- If a function is `C^n` around each point in a set, then it is `C^n` on the set. -/ theorem contDiffOn_of_locally_contDiffOn (h : ∀ x ∈ s, ∃ u, IsOpen u ∧ x ∈ u ∧ ContDiffOn 𝕜 n f (s ∩ u)) : ContDiffOn 𝕜 n f s := by intro x xs rcases h x xs with ⟨u, u_open, xu, hu⟩ apply (contDiffWithinAt_inter _).1 (hu x ⟨xs, xu⟩) exact IsOpen.mem_nhds u_open xu /-- A function is `C^(n + 1)` on a domain iff locally, it has a derivative which is `C^n`. -/ theorem contDiffOn_succ_iff_hasFDerivWithinAt (hn : n ≠ ∞) : ContDiffOn 𝕜 (n + 1) f s ↔ ∀ x ∈ s, ∃ u ∈ 𝓝[insert x s] x, (n = ω → AnalyticOn 𝕜 f u) ∧ ∃ f' : E → E →L[𝕜] F, (∀ x ∈ u, HasFDerivWithinAt f (f' x) u x) ∧ ContDiffOn 𝕜 n f' u := by constructor · intro h x hx rcases (contDiffWithinAt_succ_iff_hasFDerivWithinAt hn).1 (h x hx) with ⟨u, hu, f_an, f', hf', Hf'⟩ rcases Hf'.contDiffOn le_rfl (by simp [hn]) with ⟨v, vu, v'u, hv⟩ rw [insert_eq_of_mem hx] at hu ⊢ have xu : x ∈ u := mem_of_mem_nhdsWithin hx hu rw [insert_eq_of_mem xu] at vu v'u exact ⟨v, nhdsWithin_le_of_mem hu vu, fun h ↦ (f_an h).mono v'u, f', fun y hy ↦ (hf' y (v'u hy)).mono v'u, hv⟩ · intro h x hx rw [contDiffWithinAt_succ_iff_hasFDerivWithinAt hn] rcases h x hx with ⟨u, u_nhbd, f_an, f', hu, hf'⟩ have : x ∈ u := mem_of_mem_nhdsWithin (mem_insert _ _) u_nhbd exact ⟨u, u_nhbd, f_an, f', hu, hf' x this⟩ /-! ### Iterated derivative within a set -/ @[simp] theorem contDiffOn_zero : ContDiffOn 𝕜 0 f s ↔ ContinuousOn f s := by refine ⟨fun H => H.continuousOn, fun H => fun x hx m hm ↦ ?_⟩ have : (m : WithTop ℕ∞) = 0 := le_antisymm (mod_cast hm) bot_le rw [this] refine ⟨insert x s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_⟩ rw [hasFTaylorSeriesUpToOn_zero_iff] exact ⟨by rwa [insert_eq_of_mem hx], fun x _ => by simp [ftaylorSeriesWithin]⟩ theorem contDiffWithinAt_zero (hx : x ∈ s) : ContDiffWithinAt 𝕜 0 f s x ↔ ∃ u ∈ 𝓝[s] x, ContinuousOn f (s ∩ u) := by constructor · intro h obtain ⟨u, H, p, hp⟩ := h 0 le_rfl refine ⟨u, ?_, ?_⟩ · simpa [hx] using H · simp only [Nat.cast_zero, hasFTaylorSeriesUpToOn_zero_iff] at hp exact hp.1.mono inter_subset_right · rintro ⟨u, H, hu⟩ rw [← contDiffWithinAt_inter' H] have h' : x ∈ s ∩ u := ⟨hx, mem_of_mem_nhdsWithin hx H⟩ exact (contDiffOn_zero.mpr hu).contDiffWithinAt h' /-- When a function is `C^n` in a set `s` of unique differentiability, it admits `ftaylorSeriesWithin 𝕜 f s` as a Taylor series up to order `n` in `s`. -/ protected theorem ContDiffOn.ftaylorSeriesWithin (h : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) : HasFTaylorSeriesUpToOn n f (ftaylorSeriesWithin 𝕜 f s) s := by constructor · intro x _ simp only [ftaylorSeriesWithin, ContinuousMultilinearMap.curry0_apply, iteratedFDerivWithin_zero_apply] · intro m hm x hx have : (m + 1 : ℕ) ≤ n := ENat.add_one_natCast_le_withTop_of_lt hm rcases (h x hx).of_le this _ le_rfl with ⟨u, hu, p, Hp⟩ rw [insert_eq_of_mem hx] at hu rcases mem_nhdsWithin.1 hu with ⟨o, o_open, xo, ho⟩ rw [inter_comm] at ho have : p x m.succ = ftaylorSeriesWithin 𝕜 f s x m.succ := by change p x m.succ = iteratedFDerivWithin 𝕜 m.succ f s x rw [← iteratedFDerivWithin_inter_open o_open xo] exact (Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl (hs.inter o_open) ⟨hx, xo⟩ rw [← this, ← hasFDerivWithinAt_inter (IsOpen.mem_nhds o_open xo)] have A : ∀ y ∈ s ∩ o, p y m = ftaylorSeriesWithin 𝕜 f s y m := by rintro y ⟨hy, yo⟩ change p y m = iteratedFDerivWithin 𝕜 m f s y rw [← iteratedFDerivWithin_inter_open o_open yo] exact (Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn (mod_cast Nat.le_succ m) (hs.inter o_open) ⟨hy, yo⟩ exact ((Hp.mono ho).fderivWithin m (mod_cast lt_add_one m) x ⟨hx, xo⟩).congr (fun y hy => (A y hy).symm) (A x ⟨hx, xo⟩).symm · intro m hm apply continuousOn_of_locally_continuousOn intro x hx rcases (h x hx).of_le hm _ le_rfl with ⟨u, hu, p, Hp⟩ rcases mem_nhdsWithin.1 hu with ⟨o, o_open, xo, ho⟩ rw [insert_eq_of_mem hx] at ho rw [inter_comm] at ho refine ⟨o, o_open, xo, ?_⟩ have A : ∀ y ∈ s ∩ o, p y m = ftaylorSeriesWithin 𝕜 f s y m := by rintro y ⟨hy, yo⟩ change p y m = iteratedFDerivWithin 𝕜 m f s y rw [← iteratedFDerivWithin_inter_open o_open yo] exact (Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl (hs.inter o_open) ⟨hy, yo⟩ exact ((Hp.mono ho).cont m le_rfl).congr fun y hy => (A y hy).symm theorem iteratedFDerivWithin_subset {n : ℕ} (st : s ⊆ t) (hs : UniqueDiffOn 𝕜 s) (ht : UniqueDiffOn 𝕜 t) (h : ContDiffOn 𝕜 n f t) (hx : x ∈ s) : iteratedFDerivWithin 𝕜 n f s x = iteratedFDerivWithin 𝕜 n f t x := (((h.ftaylorSeriesWithin ht).mono st).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl hs hx).symm theorem ContDiffWithinAt.eventually_hasFTaylorSeriesUpToOn {f : E → F} {s : Set E} {a : E} (h : ContDiffWithinAt 𝕜 n f s a) (hs : UniqueDiffOn 𝕜 s) (ha : a ∈ s) {m : ℕ} (hm : m ≤ n) : ∀ᶠ t in (𝓝[s] a).smallSets, HasFTaylorSeriesUpToOn m f (ftaylorSeriesWithin 𝕜 f s) t := by rcases h.contDiffOn' hm (by simp) with ⟨U, hUo, haU, hfU⟩ have : ∀ᶠ t in (𝓝[s] a).smallSets, t ⊆ s ∩ U := by rw [eventually_smallSets_subset] exact inter_mem_nhdsWithin _ <| hUo.mem_nhds haU refine this.mono fun t ht ↦ .mono ?_ ht rw [insert_eq_of_mem ha] at hfU refine (hfU.ftaylorSeriesWithin (hs.inter hUo)).congr_series fun k hk x hx ↦ ?_ exact iteratedFDerivWithin_inter_open hUo hx.2 /-- On a set with unique differentiability, an analytic function is automatically `C^ω`, as its successive derivatives are also analytic. This does not require completeness of the space. See also `AnalyticOn.contDiffOn_of_completeSpace`. -/ theorem AnalyticOn.contDiffOn (h : AnalyticOn 𝕜 f s) (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 n f s := by suffices ContDiffOn 𝕜 ω f s from this.of_le le_top rcases h.exists_hasFTaylorSeriesUpToOn hs with ⟨p, hp⟩ intro x hx refine ⟨s, ?_, p, hp⟩ rw [insert_eq_of_mem hx] exact self_mem_nhdsWithin /-- On a set with unique differentiability, an analytic function is automatically `C^ω`, as its successive derivatives are also analytic. This does not require completeness of the space. See also `AnalyticOnNhd.contDiffOn_of_completeSpace`. -/ theorem AnalyticOnNhd.contDiffOn (h : AnalyticOnNhd 𝕜 f s) (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 n f s := h.analyticOn.contDiffOn hs /-- An analytic function is automatically `C^ω` in a complete space -/ theorem AnalyticOn.contDiffOn_of_completeSpace [CompleteSpace F] (h : AnalyticOn 𝕜 f s) : ContDiffOn 𝕜 n f s := fun x hx ↦ (h x hx).contDiffWithinAt /-- An analytic function is automatically `C^ω` in a complete space -/ theorem AnalyticOnNhd.contDiffOn_of_completeSpace [CompleteSpace F] (h : AnalyticOnNhd 𝕜 f s) : ContDiffOn 𝕜 n f s := h.analyticOn.contDiffOn_of_completeSpace theorem contDiffOn_of_continuousOn_differentiableOn {n : ℕ∞} (Hcont : ∀ m : ℕ, m ≤ n → ContinuousOn (fun x => iteratedFDerivWithin 𝕜 m f s x) s) (Hdiff : ∀ m : ℕ, m < n → DifferentiableOn 𝕜 (fun x => iteratedFDerivWithin 𝕜 m f s x) s) : ContDiffOn 𝕜 n f s := by intro x hx m hm rw [insert_eq_of_mem hx] refine ⟨s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_⟩ constructor · intro y _ simp only [ftaylorSeriesWithin, ContinuousMultilinearMap.curry0_apply, iteratedFDerivWithin_zero_apply] · intro k hk y hy convert (Hdiff k (lt_of_lt_of_le (mod_cast hk) (mod_cast hm)) y hy).hasFDerivWithinAt · intro k hk exact Hcont k (le_trans (mod_cast hk) (mod_cast hm)) theorem contDiffOn_of_differentiableOn {n : ℕ∞} (h : ∀ m : ℕ, m ≤ n → DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 m f s) s) : ContDiffOn 𝕜 n f s := contDiffOn_of_continuousOn_differentiableOn (fun m hm => (h m hm).continuousOn) fun m hm => h m (le_of_lt hm) theorem contDiffOn_of_analyticOn_iteratedFDerivWithin (h : ∀ m, AnalyticOn 𝕜 (iteratedFDerivWithin 𝕜 m f s) s) : ContDiffOn 𝕜 n f s := by suffices ContDiffOn 𝕜 ω f s from this.of_le le_top intro x hx refine ⟨insert x s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_, ?_⟩ · rw [insert_eq_of_mem hx] constructor · intro y _ simp only [ftaylorSeriesWithin, ContinuousMultilinearMap.curry0_apply, iteratedFDerivWithin_zero_apply] · intro k _ y hy exact ((h k).differentiableOn y hy).hasFDerivWithinAt · intro k _ exact (h k).continuousOn · intro i rw [insert_eq_of_mem hx] exact h i theorem contDiffOn_omega_iff_analyticOn (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 ω f s ↔ AnalyticOn 𝕜 f s := ⟨fun h m ↦ h.analyticOn m, fun h ↦ h.contDiffOn hs⟩ theorem ContDiffOn.continuousOn_iteratedFDerivWithin {m : ℕ} (h : ContDiffOn 𝕜 n f s) (hmn : m ≤ n) (hs : UniqueDiffOn 𝕜 s) : ContinuousOn (iteratedFDerivWithin 𝕜 m f s) s := ((h.of_le hmn).ftaylorSeriesWithin hs).cont m le_rfl theorem ContDiffOn.differentiableOn_iteratedFDerivWithin {m : ℕ} (h : ContDiffOn 𝕜 n f s) (hmn : m < n) (hs : UniqueDiffOn 𝕜 s) : DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 m f s) s := by intro x hx have : (m + 1 : ℕ) ≤ n := ENat.add_one_natCast_le_withTop_of_lt hmn apply (((h.of_le this).ftaylorSeriesWithin hs).fderivWithin m ?_ x hx).differentiableWithinAt exact_mod_cast lt_add_one m theorem ContDiffWithinAt.differentiableWithinAt_iteratedFDerivWithin {m : ℕ} (h : ContDiffWithinAt 𝕜 n f s x) (hmn : m < n) (hs : UniqueDiffOn 𝕜 (insert x s)) : DifferentiableWithinAt 𝕜 (iteratedFDerivWithin 𝕜 m f s) s x := by have : (m + 1 : WithTop ℕ∞) ≠ ∞ := Ne.symm (ne_of_beq_false rfl) rcases h.contDiffOn' (ENat.add_one_natCast_le_withTop_of_lt hmn) (by simp [this]) with ⟨u, uo, xu, hu⟩ set t := insert x s ∩ u have A : t =ᶠ[𝓝[≠] x] s := by simp only [set_eventuallyEq_iff_inf_principal, ← nhdsWithin_inter'] rw [← inter_assoc, nhdsWithin_inter_of_mem', ← diff_eq_compl_inter, insert_diff_of_mem, diff_eq_compl_inter] exacts [rfl, mem_nhdsWithin_of_mem_nhds (uo.mem_nhds xu)] have B : iteratedFDerivWithin 𝕜 m f s =ᶠ[𝓝 x] iteratedFDerivWithin 𝕜 m f t := iteratedFDerivWithin_eventually_congr_set' _ A.symm _ have C : DifferentiableWithinAt 𝕜 (iteratedFDerivWithin 𝕜 m f t) t x := hu.differentiableOn_iteratedFDerivWithin (Nat.cast_lt.2 m.lt_succ_self) (hs.inter uo) x ⟨mem_insert _ _, xu⟩ rw [differentiableWithinAt_congr_set' _ A] at C exact C.congr_of_eventuallyEq (B.filter_mono inf_le_left) B.self_of_nhds theorem contDiffOn_iff_continuousOn_differentiableOn {n : ℕ∞} (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 n f s ↔ (∀ m : ℕ, m ≤ n → ContinuousOn (fun x => iteratedFDerivWithin 𝕜 m f s x) s) ∧ ∀ m : ℕ, m < n → DifferentiableOn 𝕜 (fun x => iteratedFDerivWithin 𝕜 m f s x) s := ⟨fun h => ⟨fun _m hm => h.continuousOn_iteratedFDerivWithin (mod_cast hm) hs, fun _m hm => h.differentiableOn_iteratedFDerivWithin (mod_cast hm) hs⟩, fun h => contDiffOn_of_continuousOn_differentiableOn h.1 h.2⟩ theorem contDiffOn_nat_iff_continuousOn_differentiableOn {n : ℕ} (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 n f s ↔ (∀ m : ℕ, m ≤ n → ContinuousOn (fun x => iteratedFDerivWithin 𝕜 m f s x) s) ∧ ∀ m : ℕ, m < n → DifferentiableOn 𝕜 (fun x => iteratedFDerivWithin 𝕜 m f s x) s := by rw [← WithTop.coe_natCast, contDiffOn_iff_continuousOn_differentiableOn hs] simp theorem contDiffOn_succ_of_fderivWithin (hf : DifferentiableOn 𝕜 f s) (h' : n = ω → AnalyticOn 𝕜 f s) (h : ContDiffOn 𝕜 n (fun y => fderivWithin 𝕜 f s y) s) : ContDiffOn 𝕜 (n + 1) f s := by rcases eq_or_ne n ∞ with rfl | hn · rw [ENat.coe_top_add_one, contDiffOn_infty] intro m x hx apply ContDiffWithinAt.of_le _ (show (m : WithTop ℕ∞) ≤ m + 1 from le_self_add) rw [contDiffWithinAt_succ_iff_hasFDerivWithinAt (by simp), insert_eq_of_mem hx] exact ⟨s, self_mem_nhdsWithin, (by simp), fderivWithin 𝕜 f s, fun y hy => (hf y hy).hasFDerivWithinAt, (h x hx).of_le (mod_cast le_top)⟩ · intro x hx rw [contDiffWithinAt_succ_iff_hasFDerivWithinAt hn, insert_eq_of_mem hx] exact ⟨s, self_mem_nhdsWithin, h', fderivWithin 𝕜 f s, fun y hy => (hf y hy).hasFDerivWithinAt, h x hx⟩ theorem contDiffOn_of_analyticOn_of_fderivWithin (hf : AnalyticOn 𝕜 f s) (h : ContDiffOn 𝕜 ω (fun y ↦ fderivWithin 𝕜 f s y) s) : ContDiffOn 𝕜 n f s := by suffices ContDiffOn 𝕜 (ω + 1) f s from this.of_le le_top exact contDiffOn_succ_of_fderivWithin hf.differentiableOn (fun _ ↦ hf) h /-- A function is `C^(n + 1)` on a domain with unique derivatives if and only if it is differentiable there, and its derivative (expressed with `fderivWithin`) is `C^n`. -/ theorem contDiffOn_succ_iff_fderivWithin (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 (n + 1) f s ↔ DifferentiableOn 𝕜 f s ∧ (n = ω → AnalyticOn 𝕜 f s) ∧ ContDiffOn 𝕜 n (fderivWithin 𝕜 f s) s := by refine ⟨fun H => ?_, fun h => contDiffOn_succ_of_fderivWithin h.1 h.2.1 h.2.2⟩ refine ⟨H.differentiableOn le_add_self, ?_, fun x hx => ?_⟩ · rintro rfl exact H.analyticOn have A (m : ℕ) (hm : m ≤ n) : ContDiffWithinAt 𝕜 m (fun y => fderivWithin 𝕜 f s y) s x := by rcases (contDiffWithinAt_succ_iff_hasFDerivWithinAt (n := m) (ne_of_beq_false rfl)).1 (H.of_le (add_le_add_right hm 1) x hx) with ⟨u, hu, -, f', hff', hf'⟩ rcases mem_nhdsWithin.1 hu with ⟨o, o_open, xo, ho⟩ rw [inter_comm, insert_eq_of_mem hx] at ho have := hf'.mono ho rw [contDiffWithinAt_inter' (mem_nhdsWithin_of_mem_nhds (IsOpen.mem_nhds o_open xo))] at this apply this.congr_of_eventuallyEq_of_mem _ hx have : o ∩ s ∈ 𝓝[s] x := mem_nhdsWithin.2 ⟨o, o_open, xo, Subset.refl _⟩ rw [inter_comm] at this refine Filter.eventuallyEq_of_mem this fun y hy => ?_ have A : fderivWithin 𝕜 f (s ∩ o) y = f' y := ((hff' y (ho hy)).mono ho).fderivWithin (hs.inter o_open y hy) rwa [fderivWithin_inter (o_open.mem_nhds hy.2)] at A match n with | ω => exact (H.analyticOn.fderivWithin hs).contDiffOn hs (n := ω) x hx | ∞ => exact contDiffWithinAt_infty.2 (fun m ↦ A m (mod_cast le_top)) | (n : ℕ) => exact A n le_rfl theorem contDiffOn_succ_iff_hasFDerivWithinAt_of_uniqueDiffOn (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 (n + 1) f s ↔ (n = ω → AnalyticOn 𝕜 f s) ∧ ∃ f' : E → E →L[𝕜] F, ContDiffOn 𝕜 n f' s ∧ ∀ x, x ∈ s → HasFDerivWithinAt f (f' x) s x := by rw [contDiffOn_succ_iff_fderivWithin hs] refine ⟨fun h => ⟨h.2.1, fderivWithin 𝕜 f s, h.2.2, fun x hx => (h.1 x hx).hasFDerivWithinAt⟩, fun ⟨f_an, h⟩ => ?_⟩ rcases h with ⟨f', h1, h2⟩ refine ⟨fun x hx => (h2 x hx).differentiableWithinAt, f_an, fun x hx => ?_⟩ exact (h1 x hx).congr_of_mem (fun y hy => (h2 y hy).fderivWithin (hs y hy)) hx @[deprecated (since := "2024-11-27")] alias contDiffOn_succ_iff_hasFDerivWithin := contDiffOn_succ_iff_hasFDerivWithinAt_of_uniqueDiffOn theorem contDiffOn_infty_iff_fderivWithin (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 ∞ f s ↔ DifferentiableOn 𝕜 f s ∧ ContDiffOn 𝕜 ∞ (fderivWithin 𝕜 f s) s := by rw [← ENat.coe_top_add_one, contDiffOn_succ_iff_fderivWithin hs] simp @[deprecated (since := "2024-11-27")] alias contDiffOn_top_iff_fderivWithin := contDiffOn_infty_iff_fderivWithin /-- A function is `C^(n + 1)` on an open domain if and only if it is differentiable there, and its derivative (expressed with `fderiv`) is `C^n`. -/ theorem contDiffOn_succ_iff_fderiv_of_isOpen (hs : IsOpen s) : ContDiffOn 𝕜 (n + 1) f s ↔ DifferentiableOn 𝕜 f s ∧ (n = ω → AnalyticOn 𝕜 f s) ∧ ContDiffOn 𝕜 n (fderiv 𝕜 f) s := by rw [contDiffOn_succ_iff_fderivWithin hs.uniqueDiffOn, contDiffOn_congr fun x hx ↦ fderivWithin_of_isOpen hs hx] theorem contDiffOn_infty_iff_fderiv_of_isOpen (hs : IsOpen s) : ContDiffOn 𝕜 ∞ f s ↔ DifferentiableOn 𝕜 f s ∧ ContDiffOn 𝕜 ∞ (fderiv 𝕜 f) s := by rw [← ENat.coe_top_add_one, contDiffOn_succ_iff_fderiv_of_isOpen hs] simp @[deprecated (since := "2024-11-27")] alias contDiffOn_top_iff_fderiv_of_isOpen := contDiffOn_infty_iff_fderiv_of_isOpen protected theorem ContDiffOn.fderivWithin (hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) (hmn : m + 1 ≤ n) : ContDiffOn 𝕜 m (fderivWithin 𝕜 f s) s := ((contDiffOn_succ_iff_fderivWithin hs).1 (hf.of_le hmn)).2.2 theorem ContDiffOn.fderiv_of_isOpen (hf : ContDiffOn 𝕜 n f s) (hs : IsOpen s) (hmn : m + 1 ≤ n) : ContDiffOn 𝕜 m (fderiv 𝕜 f) s := (hf.fderivWithin hs.uniqueDiffOn hmn).congr fun _ hx => (fderivWithin_of_isOpen hs hx).symm theorem ContDiffOn.continuousOn_fderivWithin (h : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) (hn : 1 ≤ n) : ContinuousOn (fderivWithin 𝕜 f s) s := ((contDiffOn_succ_iff_fderivWithin hs).1 (h.of_le (show 0 + (1 : WithTop ℕ∞) ≤ n from hn))).2.2.continuousOn theorem ContDiffOn.continuousOn_fderiv_of_isOpen (h : ContDiffOn 𝕜 n f s) (hs : IsOpen s) (hn : 1 ≤ n) : ContinuousOn (fderiv 𝕜 f) s := ((contDiffOn_succ_iff_fderiv_of_isOpen hs).1 (h.of_le (show 0 + (1 : WithTop ℕ∞) ≤ n from hn))).2.2.continuousOn /-! ### Smooth functions at a point -/ variable (𝕜) in /-- A function is continuously differentiable up to `n` at a point `x` if, for any integer `k ≤ n`, there is a neighborhood of `x` where `f` admits derivatives up to order `n`, which are continuous. -/ def ContDiffAt (n : WithTop ℕ∞) (f : E → F) (x : E) : Prop := ContDiffWithinAt 𝕜 n f univ x theorem contDiffWithinAt_univ : ContDiffWithinAt 𝕜 n f univ x ↔ ContDiffAt 𝕜 n f x := Iff.rfl theorem contDiffAt_infty : ContDiffAt 𝕜 ∞ f x ↔ ∀ n : ℕ, ContDiffAt 𝕜 n f x := by simp [← contDiffWithinAt_univ, contDiffWithinAt_infty] @[deprecated (since := "2024-11-27")] alias contDiffAt_top := contDiffAt_infty theorem ContDiffAt.contDiffWithinAt (h : ContDiffAt 𝕜 n f x) : ContDiffWithinAt 𝕜 n f s x := h.mono (subset_univ _) theorem ContDiffWithinAt.contDiffAt (h : ContDiffWithinAt 𝕜 n f s x) (hx : s ∈ 𝓝 x) : ContDiffAt 𝕜 n f x := by rwa [ContDiffAt, ← contDiffWithinAt_inter hx, univ_inter] theorem contDiffWithinAt_iff_contDiffAt (h : s ∈ 𝓝 x) : ContDiffWithinAt 𝕜 n f s x ↔ ContDiffAt 𝕜 n f x := by rw [← univ_inter s, contDiffWithinAt_inter h, contDiffWithinAt_univ] theorem IsOpen.contDiffOn_iff (hs : IsOpen s) : ContDiffOn 𝕜 n f s ↔ ∀ ⦃a⦄, a ∈ s → ContDiffAt 𝕜 n f a := forall₂_congr fun _ => contDiffWithinAt_iff_contDiffAt ∘ hs.mem_nhds theorem ContDiffOn.contDiffAt (h : ContDiffOn 𝕜 n f s) (hx : s ∈ 𝓝 x) : ContDiffAt 𝕜 n f x := (h _ (mem_of_mem_nhds hx)).contDiffAt hx theorem ContDiffAt.congr_of_eventuallyEq (h : ContDiffAt 𝕜 n f x) (hg : f₁ =ᶠ[𝓝 x] f) : ContDiffAt 𝕜 n f₁ x := h.congr_of_eventuallyEq_of_mem (by rwa [nhdsWithin_univ]) (mem_univ x) theorem ContDiffAt.of_le (h : ContDiffAt 𝕜 n f x) (hmn : m ≤ n) : ContDiffAt 𝕜 m f x := ContDiffWithinAt.of_le h hmn theorem ContDiffAt.continuousAt (h : ContDiffAt 𝕜 n f x) : ContinuousAt f x := by simpa [continuousWithinAt_univ] using h.continuousWithinAt theorem ContDiffAt.analyticAt (h : ContDiffAt 𝕜 ω f x) : AnalyticAt 𝕜 f x := by rw [← contDiffWithinAt_univ] at h rw [← analyticWithinAt_univ] exact h.analyticWithinAt /-- In a complete space, a function which is analytic at a point is also `C^ω` there. Note that the same statement for `AnalyticOn` does not require completeness, see `AnalyticOn.contDiffOn`. -/ theorem AnalyticAt.contDiffAt [CompleteSpace F] (h : AnalyticAt 𝕜 f x) : ContDiffAt 𝕜 n f x := by rw [← contDiffWithinAt_univ] rw [← analyticWithinAt_univ] at h exact h.contDiffWithinAt @[simp] theorem contDiffWithinAt_compl_self : ContDiffWithinAt 𝕜 n f {x}ᶜ x ↔ ContDiffAt 𝕜 n f x := by rw [compl_eq_univ_diff, contDiffWithinAt_diff_singleton, contDiffWithinAt_univ] /-- If a function is `C^n` with `n ≥ 1` at a point, then it is differentiable there. -/ theorem ContDiffAt.differentiableAt (h : ContDiffAt 𝕜 n f x) (hn : 1 ≤ n) : DifferentiableAt 𝕜 f x := by simpa [hn, differentiableWithinAt_univ] using h.differentiableWithinAt nonrec lemma ContDiffAt.contDiffOn (h : ContDiffAt 𝕜 n f x) (hm : m ≤ n) (h' : m = ∞ → n = ω): ∃ u ∈ 𝓝 x, ContDiffOn 𝕜 m f u := by simpa [nhdsWithin_univ] using h.contDiffOn hm h' /-- A function is `C^(n + 1)` at a point iff locally, it has a derivative which is `C^n`. -/ theorem contDiffAt_succ_iff_hasFDerivAt {n : ℕ} : ContDiffAt 𝕜 (n + 1) f x ↔ ∃ f' : E → E →L[𝕜] F, (∃ u ∈ 𝓝 x, ∀ x ∈ u, HasFDerivAt f (f' x) x) ∧ ContDiffAt 𝕜 n f' x := by rw [← contDiffWithinAt_univ, contDiffWithinAt_succ_iff_hasFDerivWithinAt (by simp)] simp only [nhdsWithin_univ, exists_prop, mem_univ, insert_eq_of_mem] constructor · rintro ⟨u, H, -, f', h_fderiv, h_cont_diff⟩ rcases mem_nhds_iff.mp H with ⟨t, htu, ht, hxt⟩ refine ⟨f', ⟨t, ?_⟩, h_cont_diff.contDiffAt H⟩ refine ⟨mem_nhds_iff.mpr ⟨t, Subset.rfl, ht, hxt⟩, ?_⟩ intro y hyt refine (h_fderiv y (htu hyt)).hasFDerivAt ?_ exact mem_nhds_iff.mpr ⟨t, htu, ht, hyt⟩ · rintro ⟨f', ⟨u, H, h_fderiv⟩, h_cont_diff⟩ refine ⟨u, H, by simp, f', fun x hxu ↦ ?_, h_cont_diff.contDiffWithinAt⟩ exact (h_fderiv x hxu).hasFDerivWithinAt protected theorem ContDiffAt.eventually (h : ContDiffAt 𝕜 n f x) (h' : n ≠ ∞) : ∀ᶠ y in 𝓝 x, ContDiffAt 𝕜 n f y := by simpa [nhdsWithin_univ] using ContDiffWithinAt.eventually h h' theorem iteratedFDerivWithin_eq_iteratedFDeriv {n : ℕ} (hs : UniqueDiffOn 𝕜 s) (h : ContDiffAt 𝕜 n f x) (hx : x ∈ s) : iteratedFDerivWithin 𝕜 n f s x = iteratedFDeriv 𝕜 n f x := by rw [← iteratedFDerivWithin_univ] rcases h.contDiffOn' le_rfl (by simp) with ⟨u, u_open, xu, hu⟩ rw [← iteratedFDerivWithin_inter_open u_open xu, ← iteratedFDerivWithin_inter_open u_open xu (s := univ)] apply iteratedFDerivWithin_subset · exact inter_subset_inter_left _ (subset_univ _) · exact hs.inter u_open · apply uniqueDiffOn_univ.inter u_open · simpa using hu · exact ⟨hx, xu⟩ /-! ### Smooth functions -/ variable (𝕜) in /-- A function is continuously differentiable up to `n` if it admits derivatives up to order `n`, which are continuous. Contrary to the case of definitions in domains (where derivatives might not be unique) we do not need to localize the definition in space or time. -/ def ContDiff (n : WithTop ℕ∞) (f : E → F) : Prop := match n with | ω => ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpTo ⊤ f p ∧ ∀ i, AnalyticOnNhd 𝕜 (fun x ↦ p x i) univ | (n : ℕ∞) => ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpTo n f p /-- If `f` has a Taylor series up to `n`, then it is `C^n`. -/ theorem HasFTaylorSeriesUpTo.contDiff {n : ℕ∞} {f' : E → FormalMultilinearSeries 𝕜 E F} (hf : HasFTaylorSeriesUpTo n f f') : ContDiff 𝕜 n f := ⟨f', hf⟩ theorem contDiffOn_univ : ContDiffOn 𝕜 n f univ ↔ ContDiff 𝕜 n f := by match n with | ω => constructor · intro H use ftaylorSeriesWithin 𝕜 f univ rw [← hasFTaylorSeriesUpToOn_univ_iff] refine ⟨H.ftaylorSeriesWithin uniqueDiffOn_univ, fun i ↦ ?_⟩ rw [← analyticOn_univ] exact H.analyticOn.iteratedFDerivWithin uniqueDiffOn_univ _ · rintro ⟨p, hp, h'p⟩ x _ exact ⟨univ, Filter.univ_sets _, p, (hp.hasFTaylorSeriesUpToOn univ).of_le le_top, fun i ↦ (h'p i).analyticOn⟩ | (n : ℕ∞) => constructor · intro H use ftaylorSeriesWithin 𝕜 f univ rw [← hasFTaylorSeriesUpToOn_univ_iff] exact H.ftaylorSeriesWithin uniqueDiffOn_univ · rintro ⟨p, hp⟩ x _ m hm exact ⟨univ, Filter.univ_sets _, p, (hp.hasFTaylorSeriesUpToOn univ).of_le (mod_cast hm)⟩ theorem contDiff_iff_contDiffAt : ContDiff 𝕜 n f ↔ ∀ x, ContDiffAt 𝕜 n f x := by simp [← contDiffOn_univ, ContDiffOn, ContDiffAt] theorem ContDiff.contDiffAt (h : ContDiff 𝕜 n f) : ContDiffAt 𝕜 n f x := contDiff_iff_contDiffAt.1 h x theorem ContDiff.contDiffWithinAt (h : ContDiff 𝕜 n f) : ContDiffWithinAt 𝕜 n f s x := h.contDiffAt.contDiffWithinAt theorem contDiff_infty : ContDiff 𝕜 ∞ f ↔ ∀ n : ℕ, ContDiff 𝕜 n f := by simp [contDiffOn_univ.symm, contDiffOn_infty] @[deprecated (since := "2024-11-25")] alias contDiff_top := contDiff_infty @[deprecated (since := "2024-11-25")] alias contDiff_infty_iff_contDiff_omega := contDiff_infty theorem contDiff_all_iff_nat : (∀ n : ℕ∞, ContDiff 𝕜 n f) ↔ ∀ n : ℕ, ContDiff 𝕜 n f := by simp only [← contDiffOn_univ, contDiffOn_all_iff_nat] theorem ContDiff.contDiffOn (h : ContDiff 𝕜 n f) : ContDiffOn 𝕜 n f s := (contDiffOn_univ.2 h).mono (subset_univ _) @[simp] theorem contDiff_zero : ContDiff 𝕜 0 f ↔ Continuous f := by
rw [← contDiffOn_univ, continuous_iff_continuousOn_univ] exact contDiffOn_zero theorem contDiffAt_zero : ContDiffAt 𝕜 0 f x ↔ ∃ u ∈ 𝓝 x, ContinuousOn f u := by rw [← contDiffWithinAt_univ]; simp [contDiffWithinAt_zero, nhdsWithin_univ] theorem contDiffAt_one_iff : ContDiffAt 𝕜 1 f x ↔ ∃ f' : E → E →L[𝕜] F, ∃ u ∈ 𝓝 x, ContinuousOn f' u ∧ ∀ x ∈ u, HasFDerivAt f (f' x) x := by rw [show (1 : WithTop ℕ∞) = (0 : ℕ) + 1 from rfl] simp_rw [contDiffAt_succ_iff_hasFDerivAt, show ((0 : ℕ) : WithTop ℕ∞) = 0 from rfl, contDiffAt_zero, exists_mem_and_iff antitone_bforall antitone_continuousOn, and_comm] theorem ContDiff.of_le (h : ContDiff 𝕜 n f) (hmn : m ≤ n) : ContDiff 𝕜 m f := contDiffOn_univ.1 <| (contDiffOn_univ.2 h).of_le hmn
Mathlib/Analysis/Calculus/ContDiff/Defs.lean
1,086
1,101
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Wen Yang -/ import Mathlib.LinearAlgebra.Matrix.Adjugate import Mathlib.LinearAlgebra.Matrix.ToLin import Mathlib.LinearAlgebra.Matrix.Transvection import Mathlib.RingTheory.RootsOfUnity.Basic /-! # The Special Linear group $SL(n, R)$ This file defines the elements of the Special Linear group `SpecialLinearGroup n R`, consisting of all square `R`-matrices with determinant `1` on the fintype `n` by `n`. In addition, we define the group structure on `SpecialLinearGroup n R` and the embedding into the general linear group `GeneralLinearGroup R (n → R)`. ## Main definitions * `Matrix.SpecialLinearGroup` is the type of matrices with determinant 1 * `Matrix.SpecialLinearGroup.group` gives the group structure (under multiplication) * `Matrix.SpecialLinearGroup.toGL` is the embedding `SLₙ(R) → GLₙ(R)` ## Notation For `m : ℕ`, we introduce the notation `SL(m,R)` for the special linear group on the fintype `n = Fin m`, in the locale `MatrixGroups`. ## Implementation notes The inverse operation in the `SpecialLinearGroup` is defined to be the adjugate matrix, so that `SpecialLinearGroup n R` has a group structure for all `CommRing R`. We define the elements of `SpecialLinearGroup` to be matrices, since we need to compute their determinant. This is in contrast with `GeneralLinearGroup R M`, which consists of invertible `R`-linear maps on `M`. We provide `Matrix.SpecialLinearGroup.hasCoeToFun` for convenience, but do not state any lemmas about it, and use `Matrix.SpecialLinearGroup.coeFn_eq_coe` to eliminate it `⇑` in favor of a regular `↑` coercion. ## References * https://en.wikipedia.org/wiki/Special_linear_group ## Tags matrix group, group, matrix inverse -/ namespace Matrix universe u v open LinearMap section variable (n : Type u) [DecidableEq n] [Fintype n] (R : Type v) [CommRing R] /-- `SpecialLinearGroup n R` is the group of `n` by `n` `R`-matrices with determinant equal to 1. -/ def SpecialLinearGroup := { A : Matrix n n R // A.det = 1 } end @[inherit_doc] scoped[MatrixGroups] notation "SL(" n ", " R ")" => Matrix.SpecialLinearGroup (Fin n) R namespace SpecialLinearGroup variable {n : Type u} [DecidableEq n] [Fintype n] {R : Type v} [CommRing R] instance hasCoeToMatrix : Coe (SpecialLinearGroup n R) (Matrix n n R) := ⟨fun A => A.val⟩ /-- In this file, Lean often has a hard time working out the values of `n` and `R` for an expression like `det ↑A`. Rather than writing `(A : Matrix n n R)` everywhere in this file which is annoyingly verbose, or `A.val` which is not the simp-normal form for subtypes, we create a local notation `↑ₘA`. This notation references the local `n` and `R` variables, so is not valid as a global notation. -/ local notation:1024 "↑ₘ" A:1024 => ((A : SpecialLinearGroup n R) : Matrix n n R) section CoeFnInstance /-- This instance is here for convenience, but is literally the same as the coercion from `hasCoeToMatrix`. -/ instance instCoeFun : CoeFun (SpecialLinearGroup n R) fun _ => n → n → R where coe A := ↑ₘA end CoeFnInstance theorem ext_iff (A B : SpecialLinearGroup n R) : A = B ↔ ∀ i j, A i j = B i j := Subtype.ext_iff.trans Matrix.ext_iff.symm @[ext] theorem ext (A B : SpecialLinearGroup n R) : (∀ i j, A i j = B i j) → A = B := (SpecialLinearGroup.ext_iff A B).mpr instance subsingleton_of_subsingleton [Subsingleton n] : Subsingleton (SpecialLinearGroup n R) := by refine ⟨fun ⟨A, hA⟩ ⟨B, hB⟩ ↦ ?_⟩ ext i j rcases isEmpty_or_nonempty n with hn | hn; · exfalso; exact IsEmpty.false i rw [det_eq_elem_of_subsingleton _ i] at hA hB simp only [Subsingleton.elim j i, hA, hB] instance hasInv : Inv (SpecialLinearGroup n R) := ⟨fun A => ⟨adjugate A, by rw [det_adjugate, A.prop, one_pow]⟩⟩ instance hasMul : Mul (SpecialLinearGroup n R) := ⟨fun A B => ⟨A * B, by rw [det_mul, A.prop, B.prop, one_mul]⟩⟩ instance hasOne : One (SpecialLinearGroup n R) := ⟨⟨1, det_one⟩⟩ instance : Pow (SpecialLinearGroup n R) ℕ where pow x n := ⟨x ^ n, (det_pow _ _).trans <| x.prop.symm ▸ one_pow _⟩ instance : Inhabited (SpecialLinearGroup n R) := ⟨1⟩ instance [Fintype R] [DecidableEq R] : Fintype (SpecialLinearGroup n R) := Subtype.fintype _ instance [Finite R] : Finite (SpecialLinearGroup n R) := Subtype.finite /-- The transpose of a matrix in `SL(n, R)` -/ def transpose (A : SpecialLinearGroup n R) : SpecialLinearGroup n R := ⟨A.1.transpose, A.1.det_transpose ▸ A.2⟩ @[inherit_doc] scoped postfix:1024 "ᵀ" => SpecialLinearGroup.transpose section CoeLemmas variable (A B : SpecialLinearGroup n R) theorem coe_mk (A : Matrix n n R) (h : det A = 1) : ↑(⟨A, h⟩ : SpecialLinearGroup n R) = A := rfl @[simp] theorem coe_inv : ↑ₘ(A⁻¹) = adjugate A := rfl @[simp] theorem coe_mul : ↑ₘ(A * B) = ↑ₘA * ↑ₘB := rfl @[simp] theorem coe_one : (1 : SpecialLinearGroup n R) = (1 : Matrix n n R) := rfl @[simp] theorem det_coe : det ↑ₘA = 1 := A.2 @[simp] theorem coe_pow (m : ℕ) : ↑ₘ(A ^ m) = ↑ₘA ^ m := rfl @[simp] lemma coe_transpose (A : SpecialLinearGroup n R) : ↑ₘAᵀ = (↑ₘA)ᵀ := rfl theorem det_ne_zero [Nontrivial R] (g : SpecialLinearGroup n R) : det ↑ₘg ≠ 0 := by rw [g.det_coe] norm_num theorem row_ne_zero [Nontrivial R] (g : SpecialLinearGroup n R) (i : n) : g i ≠ 0 := fun h => g.det_ne_zero <| det_eq_zero_of_row_eq_zero i <| by simp [h] end CoeLemmas instance monoid : Monoid (SpecialLinearGroup n R) := Function.Injective.monoid _ Subtype.coe_injective coe_one coe_mul coe_pow instance : Group (SpecialLinearGroup n R) := { SpecialLinearGroup.monoid, SpecialLinearGroup.hasInv with inv_mul_cancel := fun A => by ext1 simp [adjugate_mul] } /-- A version of `Matrix.toLin' A` that produces linear equivalences. -/ def toLin' : SpecialLinearGroup n R →* (n → R) ≃ₗ[R] n → R where toFun A := LinearEquiv.ofLinear (Matrix.toLin' ↑ₘA) (Matrix.toLin' ↑ₘA⁻¹) (by rw [← toLin'_mul, ← coe_mul, mul_inv_cancel, coe_one, toLin'_one]) (by rw [← toLin'_mul, ← coe_mul, inv_mul_cancel, coe_one, toLin'_one]) map_one' := LinearEquiv.toLinearMap_injective Matrix.toLin'_one map_mul' A B := LinearEquiv.toLinearMap_injective <| Matrix.toLin'_mul ↑ₘA ↑ₘB theorem toLin'_apply (A : SpecialLinearGroup n R) (v : n → R) : SpecialLinearGroup.toLin' A v = Matrix.toLin' (↑ₘA) v := rfl theorem toLin'_to_linearMap (A : SpecialLinearGroup n R) : ↑(SpecialLinearGroup.toLin' A) = Matrix.toLin' ↑ₘA := rfl theorem toLin'_symm_apply (A : SpecialLinearGroup n R) (v : n → R) : A.toLin'.symm v = Matrix.toLin' (↑ₘA⁻¹) v := rfl theorem toLin'_symm_to_linearMap (A : SpecialLinearGroup n R) : ↑A.toLin'.symm = Matrix.toLin' ↑ₘA⁻¹ := rfl theorem toLin'_injective : Function.Injective ↑(toLin' : SpecialLinearGroup n R →* (n → R) ≃ₗ[R] n → R) := fun _ _ h => Subtype.coe_injective <| Matrix.toLin'.injective <| LinearEquiv.toLinearMap_injective.eq_iff.mpr h variable {S : Type*} [CommRing S] /-- A ring homomorphism from `R` to `S` induces a group homomorphism from `SpecialLinearGroup n R` to `SpecialLinearGroup n S`. -/ @[simps] def map (f : R →+* S) : SpecialLinearGroup n R →* SpecialLinearGroup n S where toFun g := ⟨f.mapMatrix ↑ₘg, by rw [← f.map_det] simp [g.prop]⟩ map_one' := Subtype.ext <| f.mapMatrix.map_one map_mul' x y := Subtype.ext <| f.mapMatrix.map_mul ↑ₘx ↑ₘy section center open Subgroup @[simp] theorem center_eq_bot_of_subsingleton [Subsingleton n] : center (SpecialLinearGroup n R) = ⊥ := eq_bot_iff.mpr fun x _ ↦ by rw [mem_bot, Subsingleton.elim x 1] theorem scalar_eq_self_of_mem_center {A : SpecialLinearGroup n R} (hA : A ∈ center (SpecialLinearGroup n R)) (i : n) : scalar n (A i i) = A := by obtain ⟨r : R, hr : scalar n r = A⟩ := mem_range_scalar_of_commute_transvectionStruct fun t ↦ Subtype.ext_iff.mp <| Subgroup.mem_center_iff.mp hA ⟨t.toMatrix, by simp⟩ simp [← congr_fun₂ hr i i, ← hr] theorem scalar_eq_coe_self_center (A : center (SpecialLinearGroup n R)) (i : n) : scalar n ((A : Matrix n n R) i i) = A := scalar_eq_self_of_mem_center A.property i /-- The center of a special linear group of degree `n` is the subgroup of scalar matrices, for which the scalars are the `n`-th roots of unity. -/ theorem mem_center_iff {A : SpecialLinearGroup n R} : A ∈ center (SpecialLinearGroup n R) ↔ ∃ (r : R), r ^ (Fintype.card n) = 1 ∧ scalar n r = A := by rcases isEmpty_or_nonempty n with hn | ⟨⟨i⟩⟩; · exact ⟨by aesop, by simp [Subsingleton.elim A 1]⟩ refine ⟨fun h ↦ ⟨A i i, ?_, ?_⟩, fun ⟨r, _, hr⟩ ↦ Subgroup.mem_center_iff.mpr fun B ↦ ?_⟩ · have : det ((scalar n) (A i i)) = 1 := (scalar_eq_self_of_mem_center h i).symm ▸ A.property simpa using this · exact scalar_eq_self_of_mem_center h i · suffices ↑ₘ(B * A) = ↑ₘ(A * B) from Subtype.val_injective this simpa only [coe_mul, ← hr] using (scalar_commute (n := n) r (Commute.all r) B).symm /-- An equivalence of groups, from the center of the special linear group to the roots of unity. -/ @[simps] def center_equiv_rootsOfUnity' (i : n) : center (SpecialLinearGroup n R) ≃* rootsOfUnity (Fintype.card n) R where toFun A := haveI : Nonempty n := ⟨i⟩ rootsOfUnity.mkOfPowEq (↑ₘA i i) <| by obtain ⟨r, hr, hr'⟩ := mem_center_iff.mp A.property replace hr' : A.val i i = r := by simp only [← hr', scalar_apply, diagonal_apply_eq] simp only [hr', hr] invFun a := ⟨⟨a • (1 : Matrix n n R), by aesop⟩, Subgroup.mem_center_iff.mpr fun B ↦ Subtype.val_injective <| by simp [coe_mul]⟩ left_inv A := by refine SetCoe.ext <| SetCoe.ext ?_ obtain ⟨r, _, hr⟩ := mem_center_iff.mp A.property simpa [← hr, Submonoid.smul_def, Units.smul_def] using smul_one_eq_diagonal r right_inv a := by obtain ⟨⟨a, _⟩, ha⟩ := a exact SetCoe.ext <| Units.eq_iff.mp <| by simp map_mul' A B := by dsimp ext simp only [rootsOfUnity.val_mkOfPowEq_coe, Subgroup.coe_mul, Units.val_mul] rw [← scalar_eq_coe_self_center A i, ← scalar_eq_coe_self_center B i] simp open scoped Classical in /-- An equivalence of groups, from the center of the special linear group to the roots of unity. See also `center_equiv_rootsOfUnity'`. -/ noncomputable def center_equiv_rootsOfUnity : center (SpecialLinearGroup n R) ≃* rootsOfUnity (max (Fintype.card n) 1) R := (isEmpty_or_nonempty n).by_cases (fun hn ↦ by rw [center_eq_bot_of_subsingleton, Fintype.card_eq_zero, max_eq_right_of_lt zero_lt_one, rootsOfUnity_one] exact MulEquiv.ofUnique) (fun _ ↦ (max_eq_left (NeZero.one_le : 1 ≤ Fintype.card n)).symm ▸ center_equiv_rootsOfUnity' (Classical.arbitrary n)) end center section cast /-- Coercion of SL `n` `ℤ` to SL `n` `R` for a commutative ring `R`. -/ instance : Coe (SpecialLinearGroup n ℤ) (SpecialLinearGroup n R) := ⟨fun x => map (Int.castRingHom R) x⟩ @[simp] theorem coe_matrix_coe (g : SpecialLinearGroup n ℤ) : ↑(g : SpecialLinearGroup n R) = (↑g : Matrix n n ℤ).map (Int.castRingHom R) := map_apply_coe (Int.castRingHom R) g end cast section Neg variable [Fact (Even (Fintype.card n))] /-- Formal operation of negation on special linear group on even cardinality `n` given by negating each element. -/ instance instNeg : Neg (SpecialLinearGroup n R) := ⟨fun g => ⟨-g, by simpa [(@Fact.out <| Even <| Fintype.card n).neg_one_pow, g.det_coe] using det_smul (↑ₘg) (-1)⟩⟩ @[simp] theorem coe_neg (g : SpecialLinearGroup n R) : ↑(-g) = -(g : Matrix n n R) := rfl instance : HasDistribNeg (SpecialLinearGroup n R) := Function.Injective.hasDistribNeg _ Subtype.coe_injective coe_neg coe_mul @[simp] theorem coe_int_neg (g : SpecialLinearGroup n ℤ) : ↑(-g) = (-↑g : SpecialLinearGroup n R) := Subtype.ext <| (@RingHom.mapMatrix n _ _ _ _ _ _ (Int.castRingHom R)).map_neg ↑g end Neg section SpecialCases open scoped MatrixGroups theorem SL2_inv_expl_det (A : SL(2, R)) : det ![![A.1 1 1, -A.1 0 1], ![-A.1 1 0, A.1 0 0]] = 1 := by simpa [-det_coe, Matrix.det_fin_two, mul_comm] using A.2 theorem SL2_inv_expl (A : SL(2, R)) : A⁻¹ = ⟨![![A.1 1 1, -A.1 0 1], ![-A.1 1 0, A.1 0 0]], SL2_inv_expl_det A⟩ := by ext have := Matrix.adjugate_fin_two A.1 rw [coe_inv, this] simp theorem fin_two_induction (P : SL(2, R) → Prop) (h : ∀ (a b c d : R) (hdet : a * d - b * c = 1), P ⟨!![a, b; c, d], by rwa [det_fin_two_of]⟩) (g : SL(2, R)) : P g := by obtain ⟨m, hm⟩ := g convert h (m 0 0) (m 0 1) (m 1 0) (m 1 1) (by rwa [det_fin_two] at hm) ext i j; fin_cases i <;> fin_cases j <;> rfl theorem fin_two_exists_eq_mk_of_apply_zero_one_eq_zero {R : Type*} [Field R] (g : SL(2, R)) (hg : g 1 0 = 0) : ∃ (a b : R) (h : a ≠ 0), g = (⟨!![a, b; 0, a⁻¹], by simp [h]⟩ : SL(2, R)) := by induction g using Matrix.SpecialLinearGroup.fin_two_induction with | h a b c d h_det => replace hg : c = 0 := by simpa using hg have had : a * d = 1 := by rwa [hg, mul_zero, sub_zero] at h_det refine ⟨a, b, left_ne_zero_of_mul_eq_one had, ?_⟩ simp_rw [eq_inv_of_mul_eq_one_right had, hg] lemma isCoprime_row (A : SL(2, R)) (i : Fin 2) : IsCoprime (A i 0) (A i 1) := by refine match i with | 0 => ⟨A 1 1, -(A 1 0), ?_⟩ | 1 => ⟨-(A 0 1), A 0 0, ?_⟩ <;> · simp_rw [det_coe A ▸ det_fin_two A.1] ring lemma isCoprime_col (A : SL(2, R)) (j : Fin 2) : IsCoprime (A 0 j) (A 1 j) := by refine match j with | 0 => ⟨A 1 1, -(A 0 1), ?_⟩
| 1 => ⟨-(A 1 0), A 0 0, ?_⟩ <;> · simp_rw [det_coe A ▸ det_fin_two A.1] ring end SpecialCases end SpecialLinearGroup
Mathlib/LinearAlgebra/Matrix/SpecialLinearGroup.lean
377
383
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Oliver Nash -/ import Mathlib.Topology.PartialHomeomorph import Mathlib.Analysis.Normed.Group.AddTorsor import Mathlib.Analysis.NormedSpace.Pointwise import Mathlib.Data.Real.Sqrt /-! # (Local) homeomorphism between a normed space and a ball In this file we show that a real (semi)normed vector space is homeomorphic to the unit ball. We formalize it in two ways: - as a `Homeomorph`, see `Homeomorph.unitBall`; - as a `PartialHomeomorph` with `source = Set.univ` and `target = Metric.ball (0 : E) 1`. While the former approach is more natural, the latter approach provides us with a globally defined inverse function which makes it easier to say that this homeomorphism is in fact a diffeomorphism. We also show that the unit ball `Metric.ball (0 : E) 1` is homeomorphic to a ball of positive radius in an affine space over `E`, see `PartialHomeomorph.unitBallBall`. ## Tags homeomorphism, ball -/ open Set Metric Pointwise variable {E : Type*} [SeminormedAddCommGroup E] [NormedSpace ℝ E] noncomputable section /-- Local homeomorphism between a real (semi)normed space and the unit ball. See also `Homeomorph.unitBall`. -/ @[simps -isSimp] def PartialHomeomorph.univUnitBall : PartialHomeomorph E E where toFun x := (√(1 + ‖x‖ ^ 2))⁻¹ • x invFun y := (√(1 - ‖(y : E)‖ ^ 2))⁻¹ • (y : E) source := univ target := ball 0 1 map_source' x _ := by have : 0 < 1 + ‖x‖ ^ 2 := by positivity rw [mem_ball_zero_iff, norm_smul, Real.norm_eq_abs, abs_inv, ← _root_.div_eq_inv_mul, div_lt_one (abs_pos.mpr <| Real.sqrt_ne_zero'.mpr this), ← abs_norm x, ← sq_lt_sq, abs_norm, Real.sq_sqrt this.le] exact lt_one_add _ map_target' _ _ := trivial left_inv' x _ := by field_simp [norm_smul, smul_smul, (zero_lt_one_add_norm_sq x).ne', sq_abs, Real.sq_sqrt (zero_lt_one_add_norm_sq x).le, ← Real.sqrt_div (zero_lt_one_add_norm_sq x).le] right_inv' y hy := by have : 0 < 1 - ‖y‖ ^ 2 := by nlinarith [norm_nonneg y, mem_ball_zero_iff.1 hy] field_simp [norm_smul, smul_smul, this.ne', sq_abs, Real.sq_sqrt this.le, ← Real.sqrt_div this.le] open_source := isOpen_univ open_target := isOpen_ball continuousOn_toFun := by suffices Continuous fun (x : E) => (√(1 + ‖x‖ ^ 2))⁻¹ from (this.smul continuous_id).continuousOn refine Continuous.inv₀ ?_ fun x => Real.sqrt_ne_zero'.mpr (by positivity) fun_prop continuousOn_invFun := by have : ∀ y ∈ ball (0 : E) 1, √(1 - ‖(y : E)‖ ^ 2) ≠ 0 := fun y hy ↦ by rw [Real.sqrt_ne_zero'] nlinarith [norm_nonneg y, mem_ball_zero_iff.1 hy] exact ContinuousOn.smul (ContinuousOn.inv₀ (continuousOn_const.sub (continuous_norm.continuousOn.pow _)).sqrt this) continuousOn_id @[simp] theorem PartialHomeomorph.univUnitBall_apply_zero : univUnitBall (0 : E) = 0 := by simp [PartialHomeomorph.univUnitBall_apply]
@[simp]
Mathlib/Analysis/NormedSpace/HomeomorphBall.lean
77
78
/- Copyright (c) 2022 María Inés de Frutos-Fernández. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Antoine Chambert-Loir, María Inés de Frutos-Fernández -/ import Mathlib.Algebra.BigOperators.Finprod import Mathlib.Algebra.DirectSum.Decomposition import Mathlib.Algebra.GradedMonoid import Mathlib.Algebra.MvPolynomial.Basic import Mathlib.Algebra.Order.Monoid.Canonical.Defs import Mathlib.Data.Finsupp.Weight import Mathlib.RingTheory.GradedAlgebra.Basic /-! # Weighted homogeneous polynomials It is possible to assign weights (in a commutative additive monoid `M`) to the variables of a multivariate polynomial ring, so that monomials of the ring then have a weighted degree with respect to the weights of the variables. The weights are represented by a function `w : σ → M`, where `σ` are the indeterminates. A multivariate polynomial `φ` is weighted homogeneous of weighted degree `m : M` if all monomials occurring in `φ` have the same weighted degree `m`. ## Main definitions/lemmas * `weightedTotalDegree' w φ` : the weighted total degree of a multivariate polynomial with respect to the weights `w`, taking values in `WithBot M`. * `weightedTotalDegree w φ` : When `M` has a `⊥` element, we can define the weighted total degree of a multivariate polynomial as a function taking values in `M`. * `IsWeightedHomogeneous w φ m`: a predicate that asserts that `φ` is weighted homogeneous of weighted degree `m` with respect to the weights `w`. * `weightedHomogeneousSubmodule R w m`: the submodule of homogeneous polynomials of weighted degree `m`. * `weightedHomogeneousComponent w m`: the additive morphism that projects polynomials onto their summand that is weighted homogeneous of degree `n` with respect to `w`. * `sum_weightedHomogeneousComponent`: every polynomial is the sum of its weighted homogeneous components. -/ noncomputable section open Set Function Finset Finsupp AddMonoidAlgebra variable {R M : Type*} [CommSemiring R] namespace MvPolynomial variable {σ : Type*} section AddCommMonoid variable [AddCommMonoid M] /-! ### `weight` -/ section SemilatticeSup variable [SemilatticeSup M] /-- The weighted total degree of a multivariate polynomial, taking values in `WithBot M`. -/ def weightedTotalDegree' (w : σ → M) (p : MvPolynomial σ R) : WithBot M := p.support.sup fun s => weight w s /-- The `weightedTotalDegree'` of a polynomial `p` is `⊥` if and only if `p = 0`. -/ theorem weightedTotalDegree'_eq_bot_iff (w : σ → M) (p : MvPolynomial σ R) : weightedTotalDegree' w p = ⊥ ↔ p = 0 := by simp only [weightedTotalDegree', Finset.sup_eq_bot_iff, mem_support_iff, WithBot.coe_ne_bot, MvPolynomial.eq_zero_iff] exact forall_congr' fun _ => Classical.not_not /-- The `weightedTotalDegree'` of the zero polynomial is `⊥`. -/ theorem weightedTotalDegree'_zero (w : σ → M) :
weightedTotalDegree' w (0 : MvPolynomial σ R) = ⊥ := by simp only [weightedTotalDegree', support_zero, Finset.sup_empty] section OrderBot
Mathlib/RingTheory/MvPolynomial/WeightedHomogeneous.lean
81
85
/- Copyright (c) 2021 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.LinearAlgebra.Dimension.StrongRankCondition import Mathlib.LinearAlgebra.FreeModule.Finite.Basic import Mathlib.RingTheory.AlgebraTower import Mathlib.SetTheory.Cardinal.Finsupp /-! # Rank of free modules ## Main result - `LinearEquiv.nonempty_equiv_iff_lift_rank_eq`: Two free modules are isomorphic iff they have the same dimension. - `Module.finBasis`: An arbitrary basis of a finite free module indexed by `Fin n` given `finrank R M = n`. -/ noncomputable section universe u v v' w open Cardinal Basis Submodule Function Set Module section Tower variable (F : Type u) (K : Type v) (A : Type w) variable [Semiring F] [Semiring K] [AddCommMonoid A] variable [Module F K] [Module K A] [Module F A] [IsScalarTower F K A] variable [StrongRankCondition F] [StrongRankCondition K] [Module.Free F K] [Module.Free K A] /-- Tower law: if `A` is a `K`-module and `K` is an extension of `F` then $\operatorname{rank}_F(A) = \operatorname{rank}_F(K) * \operatorname{rank}_K(A)$. The universe polymorphic version of `rank_mul_rank` below. -/ theorem lift_rank_mul_lift_rank : Cardinal.lift.{w} (Module.rank F K) * Cardinal.lift.{v} (Module.rank K A) = Cardinal.lift.{v} (Module.rank F A) := by let b := Module.Free.chooseBasis F K let c := Module.Free.chooseBasis K A rw [← (Module.rank F K).lift_id, ← b.mk_eq_rank, ← (Module.rank K A).lift_id, ← c.mk_eq_rank, ← lift_umax.{w, v}, ← (b.smulTower c).mk_eq_rank, mk_prod, lift_mul, lift_lift, lift_lift, lift_lift, lift_lift, lift_umax.{v, w}] /-- Tower law: if `A` is a `K`-module and `K` is an extension of `F` then $\operatorname{rank}_F(A) = \operatorname{rank}_F(K) * \operatorname{rank}_K(A)$. This is a simpler version of `lift_rank_mul_lift_rank` with `K` and `A` in the same universe. -/ @[stacks 09G9] theorem rank_mul_rank (A : Type v) [AddCommMonoid A]
[Module K A] [Module F A] [IsScalarTower F K A] [Module.Free K A] : Module.rank F K * Module.rank K A = Module.rank F A := by convert lift_rank_mul_lift_rank F K A <;> rw [lift_id]
Mathlib/LinearAlgebra/Dimension/Free.lean
55
58
/- 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
Mathlib/Algebra/Order/Field/Basic.lean
424
425
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Kenny Lau -/ import Mathlib.Algebra.CharP.Defs import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.Polynomial.Basic import Mathlib.RingTheory.MvPowerSeries.Basic import Mathlib.Tactic.MoveAdd import Mathlib.Algebra.MvPolynomial.Equiv import Mathlib.RingTheory.Ideal.Basic /-! # Formal power series (in one variable) This file defines (univariate) formal power series and develops the basic properties of these objects. A formal power series is to a polynomial like an infinite sum is to a finite sum. Formal power series in one variable are defined from multivariate power series as `PowerSeries R := MvPowerSeries Unit R`. The file sets up the (semi)ring structure on univariate power series. We provide the natural inclusion from polynomials to formal power series. Additional results can be found in: * `Mathlib.RingTheory.PowerSeries.Trunc`, truncation of power series; * `Mathlib.RingTheory.PowerSeries.Inverse`, about inverses of power series, and the fact that power series over a local ring form a local ring; * `Mathlib.RingTheory.PowerSeries.Order`, the order of a power series at 0, and application to the fact that power series over an integral domain form an integral domain. ## Implementation notes Because of its definition, `PowerSeries R := MvPowerSeries Unit R`. a lot of proofs and properties from the multivariate case can be ported to the single variable case. However, it means that formal power series are indexed by `Unit →₀ ℕ`, which is of course canonically isomorphic to `ℕ`. We then build some glue to treat formal power series as if they were indexed by `ℕ`. Occasionally this leads to proofs that are uglier than expected. -/ noncomputable section open Finset (antidiagonal mem_antidiagonal) /-- Formal power series over a coefficient type `R` -/ abbrev PowerSeries (R : Type*) := MvPowerSeries Unit R namespace PowerSeries open Finsupp (single) variable {R : Type*} section -- Porting note: not available in Lean 4 -- local reducible PowerSeries /-- `R⟦X⟧` is notation for `PowerSeries R`, the semiring of formal power series in one variable over a semiring `R`. -/ scoped notation:9000 R "⟦X⟧" => PowerSeries R instance [Inhabited R] : Inhabited R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [Zero R] : Zero R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [AddMonoid R] : AddMonoid R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [AddGroup R] : AddGroup R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [AddCommMonoid R] : AddCommMonoid R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [AddCommGroup R] : AddCommGroup R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [Semiring R] : Semiring R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [CommSemiring R] : CommSemiring R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [Ring R] : Ring R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [CommRing R] : CommRing R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [Nontrivial R] : Nontrivial R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance {A} [Semiring R] [AddCommMonoid A] [Module R A] : Module R A⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance {A S} [Semiring R] [Semiring S] [AddCommMonoid A] [Module R A] [Module S A] [SMul R S] [IsScalarTower R S A] : IsScalarTower R S A⟦X⟧ := Pi.isScalarTower instance {A} [Semiring A] [CommSemiring R] [Algebra R A] : Algebra R A⟦X⟧ := by dsimp only [PowerSeries] infer_instance end section Semiring variable (R) [Semiring R] /-- The `n`th coefficient of a formal power series. -/ def coeff (n : ℕ) : R⟦X⟧ →ₗ[R] R := MvPowerSeries.coeff R (single () n) /-- The `n`th monomial with coefficient `a` as formal power series. -/ def monomial (n : ℕ) : R →ₗ[R] R⟦X⟧ := MvPowerSeries.monomial R (single () n) variable {R} theorem coeff_def {s : Unit →₀ ℕ} {n : ℕ} (h : s () = n) : coeff R n = MvPowerSeries.coeff R s := by rw [coeff, ← h, ← Finsupp.unique_single s] /-- Two formal power series are equal if all their coefficients are equal. -/ @[ext] theorem ext {φ ψ : R⟦X⟧} (h : ∀ n, coeff R n φ = coeff R n ψ) : φ = ψ := MvPowerSeries.ext fun n => by rw [← coeff_def] · apply h rfl @[simp] theorem forall_coeff_eq_zero (φ : R⟦X⟧) : (∀ n, coeff R n φ = 0) ↔ φ = 0 := ⟨fun h => ext h, fun h => by simp [h]⟩ /-- Two formal power series are equal if all their coefficients are equal. -/ add_decl_doc PowerSeries.ext_iff instance [Subsingleton R] : Subsingleton R⟦X⟧ := by simp only [subsingleton_iff, PowerSeries.ext_iff] subsingleton /-- Constructor for formal power series. -/ def mk {R} (f : ℕ → R) : R⟦X⟧ := fun s => f (s ()) @[simp] theorem coeff_mk (n : ℕ) (f : ℕ → R) : coeff R n (mk f) = f n := congr_arg f Finsupp.single_eq_same theorem coeff_monomial (m n : ℕ) (a : R) : coeff R m (monomial R n a) = if m = n then a else 0 := calc coeff R m (monomial R n a) = _ := MvPowerSeries.coeff_monomial _ _ _ _ = if m = n then a else 0 := by simp only [Finsupp.unique_single_eq_iff] theorem monomial_eq_mk (n : ℕ) (a : R) : monomial R n a = mk fun m => if m = n then a else 0 := ext fun m => by rw [coeff_monomial, coeff_mk] @[simp] theorem coeff_monomial_same (n : ℕ) (a : R) : coeff R n (monomial R n a) = a := MvPowerSeries.coeff_monomial_same _ _ @[simp] theorem coeff_comp_monomial (n : ℕ) : (coeff R n).comp (monomial R n) = LinearMap.id := LinearMap.ext <| coeff_monomial_same n variable (R) /-- The constant coefficient of a formal power series. -/ def constantCoeff : R⟦X⟧ →+* R := MvPowerSeries.constantCoeff Unit R /-- The constant formal power series. -/ def C : R →+* R⟦X⟧ := MvPowerSeries.C Unit R @[simp] lemma algebraMap_eq {R : Type*} [CommSemiring R] : algebraMap R R⟦X⟧ = C R := rfl variable {R} /-- The variable of the formal power series ring. -/ def X : R⟦X⟧ := MvPowerSeries.X () theorem commute_X (φ : R⟦X⟧) : Commute φ X := MvPowerSeries.commute_X _ _ theorem X_mul {φ : R⟦X⟧} : X * φ = φ * X := MvPowerSeries.X_mul theorem commute_X_pow (φ : R⟦X⟧) (n : ℕ) : Commute φ (X ^ n) := MvPowerSeries.commute_X_pow _ _ _ theorem X_pow_mul {φ : R⟦X⟧} {n : ℕ} : X ^ n * φ = φ * X ^ n := MvPowerSeries.X_pow_mul @[simp] theorem coeff_zero_eq_constantCoeff : ⇑(coeff R 0) = constantCoeff R := by rw [coeff, Finsupp.single_zero] rfl theorem coeff_zero_eq_constantCoeff_apply (φ : R⟦X⟧) : coeff R 0 φ = constantCoeff R φ := by rw [coeff_zero_eq_constantCoeff] @[simp] theorem monomial_zero_eq_C : ⇑(monomial R 0) = C R := by -- This used to be `rw`, but we need `rw; rfl` after https://github.com/leanprover/lean4/pull/2644 rw [monomial, Finsupp.single_zero, MvPowerSeries.monomial_zero_eq_C] rfl theorem monomial_zero_eq_C_apply (a : R) : monomial R 0 a = C R a := by simp theorem coeff_C (n : ℕ) (a : R) : coeff R n (C R a : R⟦X⟧) = if n = 0 then a else 0 := by rw [← monomial_zero_eq_C_apply, coeff_monomial] @[simp] theorem coeff_zero_C (a : R) : coeff R 0 (C R a) = a := by rw [coeff_C, if_pos rfl] theorem coeff_ne_zero_C {a : R} {n : ℕ} (h : n ≠ 0) : coeff R n (C R a) = 0 := by rw [coeff_C, if_neg h] @[simp] theorem coeff_succ_C {a : R} {n : ℕ} : coeff R (n + 1) (C R a) = 0 := coeff_ne_zero_C n.succ_ne_zero theorem C_injective : Function.Injective (C R) := by intro a b H simp_rw [PowerSeries.ext_iff] at H simpa only [coeff_zero_C] using H 0 protected theorem subsingleton_iff : Subsingleton R⟦X⟧ ↔ Subsingleton R := by refine ⟨fun h ↦ ?_, fun _ ↦ inferInstance⟩ rw [subsingleton_iff] at h ⊢ exact fun a b ↦ C_injective (h (C R a) (C R b)) theorem X_eq : (X : R⟦X⟧) = monomial R 1 1 := rfl theorem coeff_X (n : ℕ) : coeff R n (X : R⟦X⟧) = if n = 1 then 1 else 0 := by rw [X_eq, coeff_monomial] @[simp] theorem coeff_zero_X : coeff R 0 (X : R⟦X⟧) = 0 := by rw [coeff, Finsupp.single_zero, X, MvPowerSeries.coeff_zero_X] @[simp] theorem coeff_one_X : coeff R 1 (X : R⟦X⟧) = 1 := by rw [coeff_X, if_pos rfl] @[simp] theorem X_ne_zero [Nontrivial R] : (X : R⟦X⟧) ≠ 0 := fun H => by simpa only [coeff_one_X, one_ne_zero, map_zero] using congr_arg (coeff R 1) H theorem X_pow_eq (n : ℕ) : (X : R⟦X⟧) ^ n = monomial R n 1 := MvPowerSeries.X_pow_eq _ n theorem coeff_X_pow (m n : ℕ) : coeff R m ((X : R⟦X⟧) ^ n) = if m = n then 1 else 0 := by rw [X_pow_eq, coeff_monomial] @[simp] theorem coeff_X_pow_self (n : ℕ) : coeff R n ((X : R⟦X⟧) ^ n) = 1 := by rw [coeff_X_pow, if_pos rfl] @[simp] theorem coeff_one (n : ℕ) : coeff R n (1 : R⟦X⟧) = if n = 0 then 1 else 0 := coeff_C n 1 theorem coeff_zero_one : coeff R 0 (1 : R⟦X⟧) = 1 := coeff_zero_C 1 theorem coeff_mul (n : ℕ) (φ ψ : R⟦X⟧) : coeff R n (φ * ψ) = ∑ p ∈ antidiagonal n, coeff R p.1 φ * coeff R p.2 ψ := by -- `rw` can't see that `PowerSeries = MvPowerSeries Unit`, so use `.trans` refine (MvPowerSeries.coeff_mul _ φ ψ).trans ?_ rw [Finsupp.antidiagonal_single, Finset.sum_map] rfl @[simp] theorem coeff_mul_C (n : ℕ) (φ : R⟦X⟧) (a : R) : coeff R n (φ * C R a) = coeff R n φ * a := MvPowerSeries.coeff_mul_C _ φ a @[simp] theorem coeff_C_mul (n : ℕ) (φ : R⟦X⟧) (a : R) : coeff R n (C R a * φ) = a * coeff R n φ := MvPowerSeries.coeff_C_mul _ φ a @[simp] theorem coeff_smul {S : Type*} [Semiring S] [Module R S] (n : ℕ) (φ : PowerSeries S) (a : R) : coeff S n (a • φ) = a • coeff S n φ := rfl @[simp] theorem constantCoeff_smul {S : Type*} [Semiring S] [Module R S] (φ : PowerSeries S) (a : R) : constantCoeff S (a • φ) = a • constantCoeff S φ := rfl theorem smul_eq_C_mul (f : R⟦X⟧) (a : R) : a • f = C R a * f := by ext simp @[simp] theorem coeff_succ_mul_X (n : ℕ) (φ : R⟦X⟧) : coeff R (n + 1) (φ * X) = coeff R n φ := by simp only [coeff, Finsupp.single_add] convert φ.coeff_add_mul_monomial (single () n) (single () 1) _
rw [mul_one] @[simp] theorem coeff_succ_X_mul (n : ℕ) (φ : R⟦X⟧) : coeff R (n + 1) (X * φ) = coeff R n φ := by simp only [coeff, Finsupp.single_add, add_comm n 1] convert φ.coeff_add_monomial_mul (single () 1) (single () n) _
Mathlib/RingTheory/PowerSeries/Basic.lean
330
335
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne -/ import Mathlib.MeasureTheory.Integral.Bochner.Basic import Mathlib.MeasureTheory.Integral.Bochner.L1 import Mathlib.MeasureTheory.Integral.Bochner.VitaliCaratheodory deprecated_module (since := "2025-04-13")
Mathlib/MeasureTheory/Integral/Bochner.lean
1,977
2,006
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Filippo A. E. Nuccio -/ import Mathlib.RingTheory.Localization.Integer import Mathlib.RingTheory.Localization.Submodule /-! # Fractional ideals This file defines fractional ideals of an integral domain and proves basic facts about them. ## Main definitions Let `S` be a submonoid of an integral domain `R` and `P` the localization of `R` at `S`. * `IsFractional` defines which `R`-submodules of `P` are fractional ideals * `FractionalIdeal S P` is the type of fractional ideals in `P` * a coercion `coeIdeal : Ideal R → FractionalIdeal S P` * `CommSemiring (FractionalIdeal S P)` instance: the typical ideal operations generalized to fractional ideals * `Lattice (FractionalIdeal S P)` instance ## Main statements * `mul_left_mono` and `mul_right_mono` state that ideal multiplication is monotone * `mul_div_self_cancel_iff` states that `1 / I` is the inverse of `I` if one exists ## Implementation notes Fractional ideals are considered equal when they contain the same elements, independent of the denominator `a : R` such that `a I ⊆ R`. Thus, we define `FractionalIdeal` to be the subtype of the predicate `IsFractional`, instead of having `FractionalIdeal` be a structure of which `a` is a field. Most definitions in this file specialize operations from submodules to fractional ideals, proving that the result of this operation is fractional if the input is fractional. Exceptions to this rule are defining `(+) := (⊔)` and `⊥ := 0`, in order to re-use their respective proof terms. We can still use `simp` to show `↑I + ↑J = ↑(I + J)` and `↑⊥ = ↑0`. Many results in fact do not need that `P` is a localization, only that `P` is an `R`-algebra. We omit the `IsLocalization` parameter whenever this is practical. Similarly, we don't assume that the localization is a field until we need it to define ideal quotients. When this assumption is needed, we replace `S` with `R⁰`, making the localization a field. ## References * https://en.wikipedia.org/wiki/Fractional_ideal ## Tags fractional ideal, fractional ideals, invertible ideal -/ open IsLocalization Pointwise nonZeroDivisors section Defs variable {R : Type*} [CommRing R] {S : Submonoid R} {P : Type*} [CommRing P] variable [Algebra R P] variable (S) /-- A submodule `I` is a fractional ideal if `a I ⊆ R` for some `a ≠ 0`. -/ def IsFractional (I : Submodule R P) := ∃ a ∈ S, ∀ b ∈ I, IsInteger R (a • b) variable (P) /-- The fractional ideals of a domain `R` are ideals of `R` divided by some `a ∈ R`. More precisely, let `P` be a localization of `R` at some submonoid `S`, then a fractional ideal `I ⊆ P` is an `R`-submodule of `P`, such that there is a nonzero `a : R` with `a I ⊆ R`. -/ def FractionalIdeal := { I : Submodule R P // IsFractional S I } end Defs namespace FractionalIdeal open Set Submodule variable {R : Type*} [CommRing R] {S : Submonoid R} {P : Type*} [CommRing P] variable [Algebra R P] /-- Map a fractional ideal `I` to a submodule by forgetting that `∃ a, a I ⊆ R`. This implements the coercion `FractionalIdeal S P → Submodule R P`. -/ @[coe] def coeToSubmodule (I : FractionalIdeal S P) : Submodule R P := I.val /-- Map a fractional ideal `I` to a submodule by forgetting that `∃ a, a I ⊆ R`. This coercion is typically called `coeToSubmodule` in lemma names (or `coe` when the coercion is clear from the context), not to be confused with `IsLocalization.coeSubmodule : Ideal R → Submodule R P` (which we use to define `coe : Ideal R → FractionalIdeal S P`). -/ instance : CoeOut (FractionalIdeal S P) (Submodule R P) := ⟨coeToSubmodule⟩ protected theorem isFractional (I : FractionalIdeal S P) : IsFractional S (I : Submodule R P) := I.prop /-- An element of `S` such that `I.den • I = I.num`, see `FractionalIdeal.num` and `FractionalIdeal.den_mul_self_eq_num`. -/ noncomputable def den (I : FractionalIdeal S P) : S := ⟨I.2.choose, I.2.choose_spec.1⟩ /-- An ideal of `R` such that `I.den • I = I.num`, see `FractionalIdeal.den` and `FractionalIdeal.den_mul_self_eq_num`. -/ noncomputable def num (I : FractionalIdeal S P) : Ideal R := (I.den • (I : Submodule R P)).comap (Algebra.linearMap R P) theorem den_mul_self_eq_num (I : FractionalIdeal S P) : I.den • (I : Submodule R P) = Submodule.map (Algebra.linearMap R P) I.num := by rw [den, num, Submodule.map_comap_eq] refine (inf_of_le_right ?_).symm rintro _ ⟨a, ha, rfl⟩ exact I.2.choose_spec.2 a ha /-- The linear equivalence between the fractional ideal `I` and the integral ideal `I.num` defined by mapping `x` to `den I • x`. -/ noncomputable def equivNum [Nontrivial P] [NoZeroSMulDivisors R P] {I : FractionalIdeal S P} (h_nz : (I.den : R) ≠ 0) : I ≃ₗ[R] I.num := by refine LinearEquiv.trans (LinearEquiv.ofBijective ((DistribMulAction.toLinearMap R P I.den).restrict fun _ hx ↦ ?_) ⟨fun _ _ hxy ↦ ?_, fun ⟨y, hy⟩ ↦ ?_⟩) (Submodule.equivMapOfInjective (Algebra.linearMap R P) (FaithfulSMul.algebraMap_injective R P) (num I)).symm · rw [← den_mul_self_eq_num] exact Submodule.smul_mem_pointwise_smul _ _ _ hx · simp_rw [LinearMap.restrict_apply, DistribMulAction.toLinearMap_apply, Subtype.mk.injEq] at hxy rwa [Submonoid.smul_def, Submonoid.smul_def, smul_right_inj h_nz, SetCoe.ext_iff] at hxy · rw [← den_mul_self_eq_num] at hy obtain ⟨x, hx, hxy⟩ := hy exact ⟨⟨x, hx⟩, by simp_rw [LinearMap.restrict_apply, Subtype.ext_iff, ← hxy]; rfl⟩ section SetLike instance : SetLike (FractionalIdeal S P) P where coe I := ↑(I : Submodule R P) coe_injective' := SetLike.coe_injective.comp Subtype.coe_injective @[simp] theorem mem_coe {I : FractionalIdeal S P} {x : P} : x ∈ (I : Submodule R P) ↔ x ∈ I := Iff.rfl @[ext] theorem ext {I J : FractionalIdeal S P} : (∀ x, x ∈ I ↔ x ∈ J) → I = J := SetLike.ext @[simp] theorem equivNum_apply [Nontrivial P] [NoZeroSMulDivisors R P] {I : FractionalIdeal S P} (h_nz : (I.den : R) ≠ 0) (x : I) : algebraMap R P (equivNum h_nz x) = I.den • x := by change Algebra.linearMap R P _ = _ rw [equivNum, LinearEquiv.trans_apply, LinearEquiv.ofBijective_apply, LinearMap.restrict_apply, Submodule.map_equivMapOfInjective_symm_apply, Subtype.coe_mk, DistribMulAction.toLinearMap_apply] /-- Copy of a `FractionalIdeal` with a new underlying set equal to the old one. Useful to fix definitional equalities. -/ protected def copy (p : FractionalIdeal S P) (s : Set P) (hs : s = ↑p) : FractionalIdeal S P := ⟨Submodule.copy p s hs, by convert p.isFractional ext simp only [hs] rfl⟩ @[simp] theorem coe_copy (p : FractionalIdeal S P) (s : Set P) (hs : s = ↑p) : ↑(p.copy s hs) = s := rfl theorem coe_eq (p : FractionalIdeal S P) (s : Set P) (hs : s = ↑p) : p.copy s hs = p := SetLike.coe_injective hs end SetLike lemma zero_mem (I : FractionalIdeal S P) : 0 ∈ I := I.coeToSubmodule.zero_mem -- Porting note: this seems to be needed a lot more than in Lean 3 @[simp] theorem val_eq_coe (I : FractionalIdeal S P) : I.val = I := rfl -- Porting note: had to rephrase this to make it clear to `simp` what was going on. @[simp, norm_cast] theorem coe_mk (I : Submodule R P) (hI : IsFractional S I) : coeToSubmodule ⟨I, hI⟩ = I := rfl theorem coeToSet_coeToSubmodule (I : FractionalIdeal S P) : ((I : Submodule R P) : Set P) = I := rfl /-! Transfer instances from `Submodule R P` to `FractionalIdeal S P`. -/ instance (I : FractionalIdeal S P) : Module R I := Submodule.module (I : Submodule R P) theorem coeToSubmodule_injective : Function.Injective (fun (I : FractionalIdeal S P) ↦ (I : Submodule R P)) := Subtype.coe_injective theorem coeToSubmodule_inj {I J : FractionalIdeal S P} : (I : Submodule R P) = J ↔ I = J := coeToSubmodule_injective.eq_iff theorem isFractional_of_le_one (I : Submodule R P) (h : I ≤ 1) : IsFractional S I := by use 1, S.one_mem intro b hb rw [one_smul] obtain ⟨b', b'_mem, rfl⟩ := mem_one.mp (h hb) exact Set.mem_range_self b' theorem isFractional_of_le {I : Submodule R P} {J : FractionalIdeal S P} (hIJ : I ≤ J) : IsFractional S I := by obtain ⟨a, a_mem, ha⟩ := J.isFractional use a, a_mem intro b b_mem exact ha b (hIJ b_mem) /-- Map an ideal `I` to a fractional ideal by forgetting `I` is integral. This is the function that implements the coercion `Ideal R → FractionalIdeal S P`. -/ @[coe] def coeIdeal (I : Ideal R) : FractionalIdeal S P := ⟨coeSubmodule P I, isFractional_of_le_one _ <| by simpa using coeSubmodule_mono P (le_top : I ≤ ⊤)⟩ -- Is a `CoeTC` rather than `Coe` to speed up failing inference, see library note [use has_coe_t] /-- Map an ideal `I` to a fractional ideal by forgetting `I` is integral. This is a bundled version of `IsLocalization.coeSubmodule : Ideal R → Submodule R P`, which is not to be confused with the `coe : FractionalIdeal S P → Submodule R P`, also called `coeToSubmodule` in theorem names. This map is available as a ring hom, called `FractionalIdeal.coeIdealHom`. -/ instance : CoeTC (Ideal R) (FractionalIdeal S P) := ⟨fun I => coeIdeal I⟩ @[simp, norm_cast] theorem coe_coeIdeal (I : Ideal R) : ((I : FractionalIdeal S P) : Submodule R P) = coeSubmodule P I := rfl variable (S) @[simp] theorem mem_coeIdeal {x : P} {I : Ideal R} : x ∈ (I : FractionalIdeal S P) ↔ ∃ x', x' ∈ I ∧ algebraMap R P x' = x := mem_coeSubmodule _ _ theorem mem_coeIdeal_of_mem {x : R} {I : Ideal R} (hx : x ∈ I) : algebraMap R P x ∈ (I : FractionalIdeal S P) := (mem_coeIdeal S).mpr ⟨x, hx, rfl⟩ theorem coeIdeal_le_coeIdeal' [IsLocalization S P] (h : S ≤ nonZeroDivisors R) {I J : Ideal R} : (I : FractionalIdeal S P) ≤ J ↔ I ≤ J := coeSubmodule_le_coeSubmodule h @[simp] theorem coeIdeal_le_coeIdeal (K : Type*) [CommRing K] [Algebra R K] [IsFractionRing R K] {I J : Ideal R} : (I : FractionalIdeal R⁰ K) ≤ J ↔ I ≤ J := IsFractionRing.coeSubmodule_le_coeSubmodule instance : Zero (FractionalIdeal S P) := ⟨(0 : Ideal R)⟩ @[simp] theorem mem_zero_iff {x : P} : x ∈ (0 : FractionalIdeal S P) ↔ x = 0 := ⟨fun ⟨x', x'_mem_zero, x'_eq_x⟩ => by have x'_eq_zero : x' = 0 := x'_mem_zero simp [x'_eq_x.symm, x'_eq_zero], fun hx => ⟨0, rfl, by simp [hx]⟩⟩ variable {S} @[simp, norm_cast] theorem coe_zero : ↑(0 : FractionalIdeal S P) = (⊥ : Submodule R P) := Submodule.ext fun _ => mem_zero_iff S @[simp, norm_cast] theorem coeIdeal_bot : ((⊥ : Ideal R) : FractionalIdeal S P) = 0 := rfl section variable [loc : IsLocalization S P] variable (P) in @[simp] theorem exists_mem_algebraMap_eq {x : R} {I : Ideal R} (h : S ≤ nonZeroDivisors R) : (∃ x', x' ∈ I ∧ algebraMap R P x' = algebraMap R P x) ↔ x ∈ I := ⟨fun ⟨_, hx', Eq⟩ => IsLocalization.injective _ h Eq ▸ hx', fun h => ⟨x, h, rfl⟩⟩ theorem coeIdeal_injective' (h : S ≤ nonZeroDivisors R) : Function.Injective (fun (I : Ideal R) ↦ (I : FractionalIdeal S P)) := fun _ _ h' => ((coeIdeal_le_coeIdeal' S h).mp h'.le).antisymm ((coeIdeal_le_coeIdeal' S h).mp h'.ge) theorem coeIdeal_inj' (h : S ≤ nonZeroDivisors R) {I J : Ideal R} : (I : FractionalIdeal S P) = J ↔ I = J := (coeIdeal_injective' h).eq_iff -- Porting note: doesn't need to be @[simp] because it can be proved by coeIdeal_eq_zero theorem coeIdeal_eq_zero' {I : Ideal R} (h : S ≤ nonZeroDivisors R) : (I : FractionalIdeal S P) = 0 ↔ I = (⊥ : Ideal R) := coeIdeal_inj' h theorem coeIdeal_ne_zero' {I : Ideal R} (h : S ≤ nonZeroDivisors R) : (I : FractionalIdeal S P) ≠ 0 ↔ I ≠ (⊥ : Ideal R) := not_iff_not.mpr <| coeIdeal_eq_zero' h end theorem coeToSubmodule_eq_bot {I : FractionalIdeal S P} : (I : Submodule R P) = ⊥ ↔ I = 0 := ⟨fun h => coeToSubmodule_injective (by simp [h]), fun h => by simp [h]⟩ theorem coeToSubmodule_ne_bot {I : FractionalIdeal S P} : ↑I ≠ (⊥ : Submodule R P) ↔ I ≠ 0 := not_iff_not.mpr coeToSubmodule_eq_bot instance : Inhabited (FractionalIdeal S P) := ⟨0⟩ instance : One (FractionalIdeal S P) := ⟨(⊤ : Ideal R)⟩ theorem zero_of_num_eq_bot [NoZeroSMulDivisors R P] (hS : 0 ∉ S) {I : FractionalIdeal S P} (hI : I.num = ⊥) : I = 0 := by rw [← coeToSubmodule_eq_bot, eq_bot_iff] intro x hx suffices (den I : R) • x = 0 from (smul_eq_zero.mp this).resolve_left (ne_of_mem_of_not_mem (SetLike.coe_mem _) hS) have h_eq : I.den • (I : Submodule R P) = ⊥ := by rw [den_mul_self_eq_num, hI, Submodule.map_bot] exact (Submodule.eq_bot_iff _).mp h_eq (den I • x) ⟨x, hx, rfl⟩ theorem num_zero_eq (h_inj : Function.Injective (algebraMap R P)) : num (0 : FractionalIdeal S P) = 0 := by simpa [num, LinearMap.ker_eq_bot] using h_inj variable (S) @[simp, norm_cast] theorem coeIdeal_top : ((⊤ : Ideal R) : FractionalIdeal S P) = 1 := rfl theorem mem_one_iff {x : P} : x ∈ (1 : FractionalIdeal S P) ↔ ∃ x' : R, algebraMap R P x' = x := Iff.intro (fun ⟨x', _, h⟩ => ⟨x', h⟩) fun ⟨x', h⟩ => ⟨x', ⟨⟩, h⟩ theorem coe_mem_one (x : R) : algebraMap R P x ∈ (1 : FractionalIdeal S P) := (mem_one_iff S).mpr ⟨x, rfl⟩ theorem one_mem_one : (1 : P) ∈ (1 : FractionalIdeal S P) := (mem_one_iff S).mpr ⟨1, RingHom.map_one _⟩ variable {S} /-- `(1 : FractionalIdeal S P)` is defined as the R-submodule `f(R) ≤ P`. However, this is not definitionally equal to `1 : Submodule R P`, which is proved in the actual `simp` lemma `coe_one`. -/ theorem coe_one_eq_coeSubmodule_top : ↑(1 : FractionalIdeal S P) = coeSubmodule P (⊤ : Ideal R) := rfl @[simp, norm_cast] theorem coe_one : (↑(1 : FractionalIdeal S P) : Submodule R P) = 1 := by rw [coe_one_eq_coeSubmodule_top, coeSubmodule_top] section Lattice /-! ### `Lattice` section Defines the order on fractional ideals as inclusion of their underlying sets, and ports the lattice structure on submodules to fractional ideals. -/ @[simp] theorem coe_le_coe {I J : FractionalIdeal S P} : (I : Submodule R P) ≤ (J : Submodule R P) ↔ I ≤ J := Iff.rfl theorem zero_le (I : FractionalIdeal S P) : 0 ≤ I := by intro x hx -- Porting note: changed the proof from convert; simp into rw; exact rw [(mem_zero_iff _).mp hx] exact zero_mem I instance orderBot : OrderBot (FractionalIdeal S P) where bot := 0 bot_le := zero_le @[simp] theorem bot_eq_zero : (⊥ : FractionalIdeal S P) = 0 := rfl @[simp] theorem le_zero_iff {I : FractionalIdeal S P} : I ≤ 0 ↔ I = 0 := le_bot_iff theorem eq_zero_iff {I : FractionalIdeal S P} : I = 0 ↔ ∀ x ∈ I, x = (0 : P) := ⟨fun h x hx => by simpa [h, mem_zero_iff] using hx, fun h => le_bot_iff.mp fun x hx => (mem_zero_iff S).mpr (h x hx)⟩ theorem _root_.IsFractional.sup {I J : Submodule R P} : IsFractional S I → IsFractional S J → IsFractional S (I ⊔ J) | ⟨aI, haI, hI⟩, ⟨aJ, haJ, hJ⟩ => ⟨aI * aJ, S.mul_mem haI haJ, fun b hb => by rcases mem_sup.mp hb with ⟨bI, hbI, bJ, hbJ, rfl⟩ rw [smul_add] apply isInteger_add · rw [mul_smul, smul_comm] exact isInteger_smul (hI bI hbI) · rw [mul_smul] exact isInteger_smul (hJ bJ hbJ)⟩ theorem _root_.IsFractional.inf_right {I : Submodule R P} : IsFractional S I → ∀ J, IsFractional S (I ⊓ J) | ⟨aI, haI, hI⟩, J => ⟨aI, haI, fun b hb => by rcases mem_inf.mp hb with ⟨hbI, _⟩ exact hI b hbI⟩ instance : Min (FractionalIdeal S P) := ⟨fun I J => ⟨I ⊓ J, I.isFractional.inf_right J⟩⟩ @[simp, norm_cast] theorem coe_inf (I J : FractionalIdeal S P) : ↑(I ⊓ J) = (I ⊓ J : Submodule R P) := rfl instance : Max (FractionalIdeal S P) := ⟨fun I J => ⟨I ⊔ J, I.isFractional.sup J.isFractional⟩⟩ @[norm_cast] theorem coe_sup (I J : FractionalIdeal S P) : ↑(I ⊔ J) = (I ⊔ J : Submodule R P) := rfl instance lattice : Lattice (FractionalIdeal S P) := Function.Injective.lattice _ Subtype.coe_injective coe_sup coe_inf instance : SemilatticeSup (FractionalIdeal S P) := { FractionalIdeal.lattice with } end Lattice section Semiring instance : Add (FractionalIdeal S P) := ⟨(· ⊔ ·)⟩ @[simp] theorem sup_eq_add (I J : FractionalIdeal S P) : I ⊔ J = I + J := rfl @[simp, norm_cast] theorem coe_add (I J : FractionalIdeal S P) : (↑(I + J) : Submodule R P) = I + J := rfl theorem mem_add (I J : FractionalIdeal S P) (x : P) : x ∈ I + J ↔ ∃ i ∈ I, ∃ j ∈ J, i + j = x := by rw [← mem_coe, coe_add, Submodule.add_eq_sup]; exact Submodule.mem_sup @[simp, norm_cast] theorem coeIdeal_sup (I J : Ideal R) : ↑(I ⊔ J) = (I + J : FractionalIdeal S P) := coeToSubmodule_injective <| coeSubmodule_sup _ _ _ theorem _root_.IsFractional.nsmul {I : Submodule R P} : ∀ n : ℕ, IsFractional S I → IsFractional S (n • I : Submodule R P) | 0, _ => by rw [zero_smul] convert ((0 : Ideal R) : FractionalIdeal S P).isFractional simp | n + 1, h => by rw [succ_nsmul] exact (IsFractional.nsmul n h).sup h instance : SMul ℕ (FractionalIdeal S P) where smul n I := ⟨n • ↑I, I.isFractional.nsmul n⟩ @[norm_cast] theorem coe_nsmul (n : ℕ) (I : FractionalIdeal S P) : (↑(n • I) : Submodule R P) = n • (I : Submodule R P) := rfl theorem _root_.IsFractional.mul {I J : Submodule R P} : IsFractional S I → IsFractional S J → IsFractional S (I * J : Submodule R P) | ⟨aI, haI, hI⟩, ⟨aJ, haJ, hJ⟩ => ⟨aI * aJ, S.mul_mem haI haJ, fun b hb => by refine Submodule.mul_induction_on hb ?_ ?_ · intro m hm n hn obtain ⟨n', hn'⟩ := hJ n hn rw [mul_smul, mul_comm m, ← smul_mul_assoc, ← hn', ← Algebra.smul_def] apply hI exact Submodule.smul_mem _ _ hm · intro x y hx hy rw [smul_add] apply isInteger_add hx hy⟩ theorem _root_.IsFractional.pow {I : Submodule R P} (h : IsFractional S I) : ∀ n : ℕ, IsFractional S (I ^ n : Submodule R P) | 0 => isFractional_of_le_one _ (pow_zero _).le | n + 1 => (pow_succ I n).symm ▸ (IsFractional.pow h n).mul h /-- `FractionalIdeal.mul` is the product of two fractional ideals, used to define the `Mul` instance. This is only an auxiliary definition: the preferred way of writing `I.mul J` is `I * J`. Elaborated terms involving `FractionalIdeal` tend to grow quite large, so by making definitions irreducible, we hope to avoid deep unfolds. -/ irreducible_def mul (lemma := mul_def') (I J : FractionalIdeal S P) : FractionalIdeal S P := ⟨I * J, I.isFractional.mul J.isFractional⟩ -- local attribute [semireducible] mul instance : Mul (FractionalIdeal S P) := ⟨fun I J => mul I J⟩ @[simp] theorem mul_eq_mul (I J : FractionalIdeal S P) : mul I J = I * J := rfl theorem mul_def (I J : FractionalIdeal S P) : I * J = ⟨I * J, I.isFractional.mul J.isFractional⟩ := by simp only [← mul_eq_mul, mul_def'] @[simp, norm_cast] theorem coe_mul (I J : FractionalIdeal S P) : (↑(I * J) : Submodule R P) = I * J := by simp only [mul_def, coe_mk] @[simp, norm_cast] theorem coeIdeal_mul (I J : Ideal R) : (↑(I * J) : FractionalIdeal S P) = I * J := by simp only [mul_def] exact coeToSubmodule_injective (coeSubmodule_mul _ _ _) theorem mul_left_mono (I : FractionalIdeal S P) : Monotone (I * ·) := by intro J J' h simp only [mul_def] exact mul_le.mpr fun x hx y hy => mul_mem_mul hx (h hy) theorem mul_right_mono (I : FractionalIdeal S P) : Monotone fun J => J * I := by intro J J' h simp only [mul_def] exact mul_le.mpr fun x hx y hy => mul_mem_mul (h hx) hy theorem mul_mem_mul {I J : FractionalIdeal S P} {i j : P} (hi : i ∈ I) (hj : j ∈ J) : i * j ∈ I * J := by simp only [mul_def] exact Submodule.mul_mem_mul hi hj theorem mul_le {I J K : FractionalIdeal S P} : I * J ≤ K ↔ ∀ i ∈ I, ∀ j ∈ J, i * j ∈ K := by simp only [mul_def] exact Submodule.mul_le instance : Pow (FractionalIdeal S P) ℕ := ⟨fun I n => ⟨(I : Submodule R P) ^ n, I.isFractional.pow n⟩⟩ @[simp, norm_cast] theorem coe_pow (I : FractionalIdeal S P) (n : ℕ) : ↑(I ^ n) = (I : Submodule R P) ^ n := rfl @[elab_as_elim] protected theorem mul_induction_on {I J : FractionalIdeal S P} {C : P → Prop} {r : P} (hr : r ∈ I * J) (hm : ∀ i ∈ I, ∀ j ∈ J, C (i * j)) (ha : ∀ x y, C x → C y → C (x + y)) : C r := by simp only [mul_def] at hr exact Submodule.mul_induction_on hr hm ha instance : NatCast (FractionalIdeal S P) := ⟨Nat.unaryCast⟩ theorem coe_natCast (n : ℕ) : ((n : FractionalIdeal S P) : Submodule R P) = n := show ((n.unaryCast : FractionalIdeal S P) : Submodule R P) = n by induction n <;> simp [*, Nat.unaryCast] instance commSemiring : CommSemiring (FractionalIdeal S P) := Function.Injective.commSemiring _ Subtype.coe_injective coe_zero coe_one coe_add coe_mul (fun _ _ => coe_nsmul _ _) coe_pow coe_natCast end Semiring variable (S P) /-- `FractionalIdeal.coeToSubmodule` as a bundled `RingHom`. -/
@[simps] def coeSubmoduleHom : FractionalIdeal S P →+* Submodule R P where toFun := coeToSubmodule
Mathlib/RingTheory/FractionalIdeal/Basic.lean
589
591
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.InnerProductSpace.PiL2 import Mathlib.Analysis.SpecialFunctions.Sqrt import Mathlib.Analysis.NormedSpace.HomeomorphBall import Mathlib.Analysis.Calculus.ContDiff.WithLp import Mathlib.Analysis.Calculus.FDeriv.WithLp /-! # Calculus in inner product spaces In this file we prove that the inner product and square of the norm in an inner space are infinitely `ℝ`-smooth. In order to state these results, we need a `NormedSpace ℝ E` instance. Though we can deduce this structure from `InnerProductSpace 𝕜 E`, this instance may be not definitionally equal to some other “natural” instance. So, we assume `[NormedSpace ℝ E]`. We also prove that functions to a `EuclideanSpace` are (higher) differentiable if and only if their components are. This follows from the corresponding fact for finite product of normed spaces, and from the equivalence of norms in finite dimensions. ## TODO The last part of the file should be generalized to `PiLp`. -/ noncomputable section open RCLike Real Filter section DerivInner variable {𝕜 E F : Type*} [RCLike 𝕜] variable [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] variable [NormedAddCommGroup F] [InnerProductSpace ℝ F] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y variable (𝕜) [NormedSpace ℝ E] /-- Derivative of the inner product. -/ def fderivInnerCLM (p : E × E) : E × E →L[ℝ] 𝕜 := isBoundedBilinearMap_inner.deriv p @[simp] theorem fderivInnerCLM_apply (p x : E × E) : fderivInnerCLM 𝕜 p x = ⟪p.1, x.2⟫ + ⟪x.1, p.2⟫ := rfl variable {𝕜} theorem contDiff_inner {n} : ContDiff ℝ n fun p : E × E => ⟪p.1, p.2⟫ := isBoundedBilinearMap_inner.contDiff theorem contDiffAt_inner {p : E × E} {n} : ContDiffAt ℝ n (fun p : E × E => ⟪p.1, p.2⟫) p := ContDiff.contDiffAt contDiff_inner theorem differentiable_inner : Differentiable ℝ fun p : E × E => ⟪p.1, p.2⟫ := isBoundedBilinearMap_inner.differentiableAt variable (𝕜) variable {G : Type*} [NormedAddCommGroup G] [NormedSpace ℝ G] {f g : G → E} {f' g' : G →L[ℝ] E} {s : Set G} {x : G} {n : WithTop ℕ∞} theorem ContDiffWithinAt.inner (hf : ContDiffWithinAt ℝ n f s x) (hg : ContDiffWithinAt ℝ n g s x) : ContDiffWithinAt ℝ n (fun x => ⟪f x, g x⟫) s x := contDiffAt_inner.comp_contDiffWithinAt x (hf.prodMk hg) nonrec theorem ContDiffAt.inner (hf : ContDiffAt ℝ n f x) (hg : ContDiffAt ℝ n g x) : ContDiffAt ℝ n (fun x => ⟪f x, g x⟫) x := hf.inner 𝕜 hg theorem ContDiffOn.inner (hf : ContDiffOn ℝ n f s) (hg : ContDiffOn ℝ n g s) : ContDiffOn ℝ n (fun x => ⟪f x, g x⟫) s := fun x hx => (hf x hx).inner 𝕜 (hg x hx) theorem ContDiff.inner (hf : ContDiff ℝ n f) (hg : ContDiff ℝ n g) : ContDiff ℝ n fun x => ⟪f x, g x⟫ := contDiff_inner.comp (hf.prodMk hg) #adaptation_note /-- https://github.com/leanprover/lean4/pull/6024 added `by exact` to handle a unification issue. -/ theorem HasFDerivWithinAt.inner (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt g g' s x) : HasFDerivWithinAt (fun t => ⟪f t, g t⟫) ((fderivInnerCLM 𝕜 (f x, g x)).comp <| f'.prod g') s x := by exact isBoundedBilinearMap_inner (𝕜 := 𝕜) (E := E) |>.hasFDerivAt (f x, g x) |>.comp_hasFDerivWithinAt x (hf.prodMk hg) theorem HasStrictFDerivAt.inner (hf : HasStrictFDerivAt f f' x) (hg : HasStrictFDerivAt g g' x) : HasStrictFDerivAt (fun t => ⟪f t, g t⟫) ((fderivInnerCLM 𝕜 (f x, g x)).comp <| f'.prod g') x := isBoundedBilinearMap_inner (𝕜 := 𝕜) (E := E) |>.hasStrictFDerivAt (f x, g x) |>.comp x (hf.prodMk hg) #adaptation_note /-- https://github.com/leanprover/lean4/pull/6024 added `by exact` to handle a unification issue. -/ theorem HasFDerivAt.inner (hf : HasFDerivAt f f' x) (hg : HasFDerivAt g g' x) : HasFDerivAt (fun t => ⟪f t, g t⟫) ((fderivInnerCLM 𝕜 (f x, g x)).comp <| f'.prod g') x := by exact isBoundedBilinearMap_inner (𝕜 := 𝕜) (E := E) |>.hasFDerivAt (f x, g x) |>.comp x (hf.prodMk hg) theorem HasDerivWithinAt.inner {f g : ℝ → E} {f' g' : E} {s : Set ℝ} {x : ℝ} (hf : HasDerivWithinAt f f' s x) (hg : HasDerivWithinAt g g' s x) : HasDerivWithinAt (fun t => ⟪f t, g t⟫) (⟪f x, g'⟫ + ⟪f', g x⟫) s x := by simpa using (hf.hasFDerivWithinAt.inner 𝕜 hg.hasFDerivWithinAt).hasDerivWithinAt theorem HasDerivAt.inner {f g : ℝ → E} {f' g' : E} {x : ℝ} : HasDerivAt f f' x → HasDerivAt g g' x → HasDerivAt (fun t => ⟪f t, g t⟫) (⟪f x, g'⟫ + ⟪f', g x⟫) x := by simpa only [← hasDerivWithinAt_univ] using HasDerivWithinAt.inner 𝕜 theorem DifferentiableWithinAt.inner (hf : DifferentiableWithinAt ℝ f s x) (hg : DifferentiableWithinAt ℝ g s x) : DifferentiableWithinAt ℝ (fun x => ⟪f x, g x⟫) s x := (hf.hasFDerivWithinAt.inner 𝕜 hg.hasFDerivWithinAt).differentiableWithinAt
theorem DifferentiableAt.inner (hf : DifferentiableAt ℝ f x) (hg : DifferentiableAt ℝ g x) : DifferentiableAt ℝ (fun x => ⟪f x, g x⟫) x := (hf.hasFDerivAt.inner 𝕜 hg.hasFDerivAt).differentiableAt
Mathlib/Analysis/InnerProductSpace/Calculus.lean
115
118
/- Copyright (c) 2021 Thomas Browning. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning -/ import Mathlib.Combinatorics.Hall.Basic import Mathlib.Data.Matrix.Rank import Mathlib.LinearAlgebra.Projectivization.Constructions /-! # Configurations of Points and lines This file introduces abstract configurations of points and lines, and proves some basic properties. ## Main definitions * `Configuration.Nondegenerate`: Excludes certain degenerate configurations, and imposes uniqueness of intersection points. * `Configuration.HasPoints`: A nondegenerate configuration in which every pair of lines has an intersection point. * `Configuration.HasLines`: A nondegenerate configuration in which every pair of points has a line through them. * `Configuration.lineCount`: The number of lines through a given point. * `Configuration.pointCount`: The number of lines through a given line. ## Main statements * `Configuration.HasLines.card_le`: `HasLines` implies `|P| ≤ |L|`. * `Configuration.HasPoints.card_le`: `HasPoints` implies `|L| ≤ |P|`. * `Configuration.HasLines.hasPoints`: `HasLines` and `|P| = |L|` implies `HasPoints`. * `Configuration.HasPoints.hasLines`: `HasPoints` and `|P| = |L|` implies `HasLines`. Together, these four statements say that any two of the following properties imply the third: (a) `HasLines`, (b) `HasPoints`, (c) `|P| = |L|`. -/ open Finset namespace Configuration variable (P L : Type*) [Membership P L] /-- A type synonym. -/ def Dual := P instance [h : Inhabited P] : Inhabited (Dual P) := h instance [Finite P] : Finite (Dual P) := ‹Finite P› instance [h : Fintype P] : Fintype (Dual P) := h set_option synthInstance.checkSynthOrder false in instance : Membership (Dual L) (Dual P) := ⟨Function.swap (Membership.mem : L → P → Prop)⟩ /-- A configuration is nondegenerate if: 1) there does not exist a line that passes through all of the points, 2) there does not exist a point that is on all of the lines, 3) there is at most one line through any two points, 4) any two lines have at most one intersection point. Conditions 3 and 4 are equivalent. -/ class Nondegenerate : Prop where exists_point : ∀ l : L, ∃ p, p ∉ l exists_line : ∀ p, ∃ l : L, p ∉ l eq_or_eq : ∀ {p₁ p₂ : P} {l₁ l₂ : L}, p₁ ∈ l₁ → p₂ ∈ l₁ → p₁ ∈ l₂ → p₂ ∈ l₂ → p₁ = p₂ ∨ l₁ = l₂ /-- A nondegenerate configuration in which every pair of lines has an intersection point. -/ class HasPoints extends Nondegenerate P L where /-- Intersection of two lines -/ mkPoint : ∀ {l₁ l₂ : L}, l₁ ≠ l₂ → P mkPoint_ax : ∀ {l₁ l₂ : L} (h : l₁ ≠ l₂), mkPoint h ∈ l₁ ∧ mkPoint h ∈ l₂ /-- A nondegenerate configuration in which every pair of points has a line through them. -/ class HasLines extends Nondegenerate P L where /-- Line through two points -/ mkLine : ∀ {p₁ p₂ : P}, p₁ ≠ p₂ → L mkLine_ax : ∀ {p₁ p₂ : P} (h : p₁ ≠ p₂), p₁ ∈ mkLine h ∧ p₂ ∈ mkLine h open Nondegenerate open HasPoints (mkPoint mkPoint_ax) open HasLines (mkLine mkLine_ax) instance Dual.Nondegenerate [Nondegenerate P L] : Nondegenerate (Dual L) (Dual P) where exists_point := @exists_line P L _ _ exists_line := @exists_point P L _ _ eq_or_eq := @fun l₁ l₂ p₁ p₂ h₁ h₂ h₃ h₄ => (@eq_or_eq P L _ _ p₁ p₂ l₁ l₂ h₁ h₃ h₂ h₄).symm instance Dual.hasLines [HasPoints P L] : HasLines (Dual L) (Dual P) := { Dual.Nondegenerate _ _ with mkLine := @mkPoint P L _ _ mkLine_ax := @mkPoint_ax P L _ _ } instance Dual.hasPoints [HasLines P L] : HasPoints (Dual L) (Dual P) := { Dual.Nondegenerate _ _ with mkPoint := @mkLine P L _ _ mkPoint_ax := @mkLine_ax P L _ _ } theorem HasPoints.existsUnique_point [HasPoints P L] (l₁ l₂ : L) (hl : l₁ ≠ l₂) : ∃! p, p ∈ l₁ ∧ p ∈ l₂ := ⟨mkPoint hl, mkPoint_ax hl, fun _ hp => (eq_or_eq hp.1 (mkPoint_ax hl).1 hp.2 (mkPoint_ax hl).2).resolve_right hl⟩ theorem HasLines.existsUnique_line [HasLines P L] (p₁ p₂ : P) (hp : p₁ ≠ p₂) : ∃! l : L, p₁ ∈ l ∧ p₂ ∈ l := HasPoints.existsUnique_point (Dual L) (Dual P) p₁ p₂ hp variable {P L} /-- If a nondegenerate configuration has at least as many points as lines, then there exists an injective function `f` from lines to points, such that `f l` does not lie on `l`. -/ theorem Nondegenerate.exists_injective_of_card_le [Nondegenerate P L] [Fintype P] [Fintype L] (h : Fintype.card L ≤ Fintype.card P) : ∃ f : L → P, Function.Injective f ∧ ∀ l, f l ∉ l := by classical let t : L → Finset P := fun l => Set.toFinset { p | p ∉ l } suffices ∀ s : Finset L, #s ≤ (s.biUnion t).card by -- Hall's marriage theorem obtain ⟨f, hf1, hf2⟩ := (Finset.all_card_le_biUnion_card_iff_exists_injective t).mp this exact ⟨f, hf1, fun l => Set.mem_toFinset.mp (hf2 l)⟩ intro s by_cases hs₀ : #s = 0 -- If `s = ∅`, then `#s = 0 ≤ #(s.bUnion t)` · simp_rw [hs₀, zero_le] by_cases hs₁ : #s = 1 -- If `s = {l}`, then pick a point `p ∉ l` · obtain ⟨l, rfl⟩ := Finset.card_eq_one.mp hs₁ obtain ⟨p, hl⟩ := exists_point (P := P) l rw [Finset.card_singleton, Finset.singleton_biUnion, Nat.one_le_iff_ne_zero] exact Finset.card_ne_zero_of_mem (Set.mem_toFinset.mpr hl) suffices #(s.biUnion t)ᶜ ≤ #sᶜ by -- Rephrase in terms of complements (uses `h`) rw [Finset.card_compl, Finset.card_compl, tsub_le_iff_left] at this replace := h.trans this rwa [← add_tsub_assoc_of_le s.card_le_univ, le_tsub_iff_left (le_add_left s.card_le_univ), add_le_add_iff_right] at this have hs₂ : #(s.biUnion t)ᶜ ≤ 1 := by -- At most one line through two points of `s` refine Finset.card_le_one_iff.mpr @fun p₁ p₂ hp₁ hp₂ => ?_ simp_rw [t, Finset.mem_compl, Finset.mem_biUnion, not_exists, not_and, Set.mem_toFinset, Set.mem_setOf_eq, Classical.not_not] at hp₁ hp₂ obtain ⟨l₁, l₂, hl₁, hl₂, hl₃⟩ := Finset.one_lt_card_iff.mp (Nat.one_lt_iff_ne_zero_and_ne_one.mpr ⟨hs₀, hs₁⟩) exact (eq_or_eq (hp₁ l₁ hl₁) (hp₂ l₁ hl₁) (hp₁ l₂ hl₂) (hp₂ l₂ hl₂)).resolve_right hl₃ by_cases hs₃ : #sᶜ = 0 · rw [hs₃, Nat.le_zero] rw [Finset.card_compl, tsub_eq_zero_iff_le, LE.le.le_iff_eq (Finset.card_le_univ _), eq_comm, Finset.card_eq_iff_eq_univ] at hs₃ ⊢ rw [hs₃] rw [Finset.eq_univ_iff_forall] at hs₃ ⊢ exact fun p => Exists.elim (exists_line p)-- If `s = univ`, then show `s.bUnion t = univ` fun l hl => Finset.mem_biUnion.mpr ⟨l, Finset.mem_univ l, Set.mem_toFinset.mpr hl⟩ · exact hs₂.trans (Nat.one_le_iff_ne_zero.mpr hs₃) -- If `s < univ`, then consequence of `hs₂` variable (L) /-- Number of points on a given line. -/ noncomputable def lineCount (p : P) : ℕ := Nat.card { l : L // p ∈ l } variable (P) {L} /-- Number of lines through a given point. -/ noncomputable def pointCount (l : L) : ℕ := Nat.card { p : P // p ∈ l } variable (L) theorem sum_lineCount_eq_sum_pointCount [Fintype P] [Fintype L] : ∑ p : P, lineCount L p = ∑ l : L, pointCount P l := by classical simp only [lineCount, pointCount, Nat.card_eq_fintype_card, ← Fintype.card_sigma] apply Fintype.card_congr calc (Σp, { l : L // p ∈ l }) ≃ { x : P × L // x.1 ∈ x.2 } := (Equiv.subtypeProdEquivSigmaSubtype (· ∈ ·)).symm _ ≃ { x : L × P // x.2 ∈ x.1 } := (Equiv.prodComm P L).subtypeEquiv fun x => Iff.rfl _ ≃ Σl, { p // p ∈ l } := Equiv.subtypeProdEquivSigmaSubtype fun (l : L) (p : P) => p ∈ l variable {P L} theorem HasLines.pointCount_le_lineCount [HasLines P L] {p : P} {l : L} (h : p ∉ l) [Finite { l : L // p ∈ l }] : pointCount P l ≤ lineCount L p := by by_cases hf : Infinite { p : P // p ∈ l } · exact (le_of_eq Nat.card_eq_zero_of_infinite).trans (zero_le (lineCount L p)) haveI := fintypeOfNotInfinite hf cases nonempty_fintype { l : L // p ∈ l } rw [lineCount, pointCount, Nat.card_eq_fintype_card, Nat.card_eq_fintype_card] have : ∀ p' : { p // p ∈ l }, p ≠ p' := fun p' hp' => h ((congr_arg (· ∈ l) hp').mpr p'.2) exact Fintype.card_le_of_injective (fun p' => ⟨mkLine (this p'), (mkLine_ax (this p')).1⟩) fun p₁ p₂ hp => Subtype.ext ((eq_or_eq p₁.2 p₂.2 (mkLine_ax (this p₁)).2 ((congr_arg (_ ∈ ·) (Subtype.ext_iff.mp hp)).mpr (mkLine_ax (this p₂)).2)).resolve_right fun h' => (congr_arg (¬p ∈ ·) h').mp h (mkLine_ax (this p₁)).1) theorem HasPoints.lineCount_le_pointCount [HasPoints P L] {p : P} {l : L} (h : p ∉ l) [hf : Finite { p : P // p ∈ l }] : lineCount L p ≤ pointCount P l := @HasLines.pointCount_le_lineCount (Dual L) (Dual P) _ _ l p h hf variable (P L) /-- If a nondegenerate configuration has a unique line through any two points, then `|P| ≤ |L|`. -/ theorem HasLines.card_le [HasLines P L] [Fintype P] [Fintype L] : Fintype.card P ≤ Fintype.card L := by classical by_contra hc₂ obtain ⟨f, hf₁, hf₂⟩ := Nondegenerate.exists_injective_of_card_le (le_of_not_le hc₂) have := calc ∑ p, lineCount L p = ∑ l, pointCount P l := sum_lineCount_eq_sum_pointCount P L _ ≤ ∑ l, lineCount L (f l) := (Finset.sum_le_sum fun l _ => HasLines.pointCount_le_lineCount (hf₂ l)) _ = ∑ p ∈ univ.map ⟨f, hf₁⟩, lineCount L p := by rw [sum_map]; dsimp _ < ∑ p, lineCount L p := by obtain ⟨p, hp⟩ := not_forall.mp (mt (Fintype.card_le_of_surjective f) hc₂) refine sum_lt_sum_of_subset (subset_univ _) (mem_univ p) ?_ ?_ fun p _ _ ↦ zero_le _ · simpa only [Finset.mem_map, exists_prop, Finset.mem_univ, true_and] · rw [lineCount, Nat.card_eq_fintype_card, Fintype.card_pos_iff] obtain ⟨l, _⟩ := @exists_line P L _ _ p
exact let this := not_exists.mp hp l ⟨⟨mkLine this, (mkLine_ax this).2⟩⟩ exact lt_irrefl _ this /-- If a nondegenerate configuration has a unique point on any two lines, then `|L| ≤ |P|`. -/ theorem HasPoints.card_le [HasPoints P L] [Fintype P] [Fintype L] : Fintype.card L ≤ Fintype.card P := @HasLines.card_le (Dual L) (Dual P) _ _ _ _ variable {P L} theorem HasLines.exists_bijective_of_card_eq [HasLines P L] [Fintype P] [Fintype L] (h : Fintype.card P = Fintype.card L) : ∃ f : L → P, Function.Bijective f ∧ ∀ l, pointCount P l = lineCount L (f l) := by classical obtain ⟨f, hf1, hf2⟩ := Nondegenerate.exists_injective_of_card_le (ge_of_eq h) have hf3 := (Fintype.bijective_iff_injective_and_card f).mpr ⟨hf1, h.symm⟩ exact ⟨f, hf3, fun l ↦ (sum_eq_sum_iff_of_le fun l _ ↦ pointCount_le_lineCount (hf2 l)).1 ((hf3.sum_comp _).trans (sum_lineCount_eq_sum_pointCount P L)).symm _ <| mem_univ _⟩
Mathlib/Combinatorics/Configuration.lean
225
245
/- 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 -/ import Mathlib.Algebra.CharP.Defs import Mathlib.Algebra.MvPolynomial.Degrees import Mathlib.Data.DFinsupp.Small import Mathlib.Data.Fintype.Pi import Mathlib.LinearAlgebra.Finsupp.VectorSpace import Mathlib.LinearAlgebra.FreeModule.Finite.Basic /-! # Multivariate polynomials over commutative rings This file contains basic facts about multivariate polynomials over commutative rings, for example that the monomials form a basis. ## Main definitions * `restrictTotalDegree σ R m`: the subspace of multivariate polynomials indexed by `σ` over the commutative ring `R` of total degree at most `m`. * `restrictDegree σ R m`: the subspace of multivariate polynomials indexed by `σ` over the commutative ring `R` such that the degree in each individual variable is at most `m`. ## Main statements * The multivariate polynomial ring over a commutative semiring of characteristic `p` has characteristic `p`, and similarly for `CharZero`. * `basisMonomials`: shows that the monomials form a basis of the vector space of multivariate polynomials. ## TODO Generalise to noncommutative (semi)rings -/ noncomputable section open Set LinearMap Submodule universe u v variable (σ : Type u) (R : Type v) [CommSemiring R] (p m : ℕ) namespace MvPolynomial instance {σ : Type*} {R : Type*} [CommSemiring R] [Small.{u} R] [Small.{u} σ] : Small.{u} (MvPolynomial σ R) := inferInstanceAs (Small.{u} ((σ →₀ ℕ) →₀ R)) section CharP instance [CharP R p] : CharP (MvPolynomial σ R) p where cast_eq_zero_iff n := by rw [← C_eq_coe_nat, ← C_0, C_inj, CharP.cast_eq_zero_iff R p] end CharP section CharZero instance [CharZero R] : CharZero (MvPolynomial σ R) where cast_injective x y hxy := by rwa [← C_eq_coe_nat, ← C_eq_coe_nat, C_inj, Nat.cast_inj] at hxy end CharZero
section Homomorphism theorem mapRange_eq_map {R S : Type*} [CommSemiring R] [CommSemiring S] (p : MvPolynomial σ R) (f : R →+* S) : Finsupp.mapRange f f.map_zero p = map f p := by rw [p.as_sum, Finsupp.mapRange_finset_sum, map_sum (map f)]
Mathlib/RingTheory/MvPolynomial/Basic.lean
68
72
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen -/ import Mathlib.Algebra.Algebra.Tower import Mathlib.Algebra.Field.IsField import Mathlib.Algebra.GroupWithZero.NonZeroDivisors import Mathlib.GroupTheory.MonoidLocalization.MonoidWithZero import Mathlib.RingTheory.Localization.Defs import Mathlib.RingTheory.OreLocalization.Ring /-! # Localizations of commutative rings This file contains various basic results on localizations. We characterize the localization of a commutative ring `R` at a submonoid `M` up to isomorphism; that is, a commutative ring `S` is the localization of `R` at `M` iff we can find a ring homomorphism `f : R →+* S` satisfying 3 properties: 1. For all `y ∈ M`, `f y` is a unit; 2. For all `z : S`, there exists `(x, y) : R × M` such that `z * f y = f x`; 3. For all `x, y : R` such that `f x = f y`, there exists `c ∈ M` such that `x * c = y * c`. (The converse is a consequence of 1.) In the following, let `R, P` be commutative rings, `S, Q` be `R`- and `P`-algebras and `M, T` be submonoids of `R` and `P` respectively, e.g.: ``` variable (R S P Q : Type*) [CommRing R] [CommRing S] [CommRing P] [CommRing Q] variable [Algebra R S] [Algebra P Q] (M : Submonoid R) (T : Submonoid P) ``` ## Main definitions * `IsLocalization.algEquiv`: if `Q` is another localization of `R` at `M`, then `S` and `Q` are isomorphic as `R`-algebras ## Implementation notes In maths it is natural to reason up to isomorphism, but in Lean we cannot naturally `rewrite` one structure with an isomorphic one; one way around this is to isolate a predicate characterizing a structure up to isomorphism, and reason about things that satisfy the predicate. A previous version of this file used a fully bundled type of ring localization maps, then used a type synonym `f.codomain` for `f : LocalizationMap M S` to instantiate the `R`-algebra structure on `S`. This results in defining ad-hoc copies for everything already defined on `S`. By making `IsLocalization` a predicate on the `algebraMap R S`, we can ensure the localization map commutes nicely with other `algebraMap`s. To prove most lemmas about a localization map `algebraMap R S` in this file we invoke the corresponding proof for the underlying `CommMonoid` localization map `IsLocalization.toLocalizationMap M S`, which can be found in `GroupTheory.MonoidLocalization` and the namespace `Submonoid.LocalizationMap`. To reason about the localization as a quotient type, use `mk_eq_of_mk'` and associated lemmas. These show the quotient map `mk : R → M → Localization M` equals the surjection `LocalizationMap.mk'` induced by the map `algebraMap : R →+* Localization M`. The lemma `mk_eq_of_mk'` hence gives you access to the results in the rest of the file, which are about the `LocalizationMap.mk'` induced by any localization map. The proof that "a `CommRing` `K` which is the localization of an integral domain `R` at `R \ {0}` is a field" is a `def` rather than an `instance`, so if you want to reason about a field of fractions `K`, assume `[Field K]` instead of just `[CommRing K]`. ## Tags localization, ring localization, commutative ring localization, characteristic predicate, commutative ring, field of fractions -/ assert_not_exists Ideal open Function namespace Localization open IsLocalization variable {ι : Type*} {R : ι → Type*} [∀ i, CommSemiring (R i)] variable {i : ι} (S : Submonoid (R i)) /-- `IsLocalization.map` applied to a projection homomorphism from a product ring. -/ noncomputable abbrev mapPiEvalRingHom : Localization (S.comap <| Pi.evalRingHom R i) →+* Localization S := map (T := S) _ (Pi.evalRingHom R i) le_rfl open Function in theorem mapPiEvalRingHom_bijective : Bijective (mapPiEvalRingHom S) := by let T := S.comap (Pi.evalRingHom R i) classical refine ⟨fun x₁ x₂ eq ↦ ?_, fun x ↦ ?_⟩ · obtain ⟨r₁, s₁, rfl⟩ := mk'_surjective T x₁ obtain ⟨r₂, s₂, rfl⟩ := mk'_surjective T x₂ simp_rw [map_mk'] at eq rw [IsLocalization.eq] at eq ⊢ obtain ⟨s, hs⟩ := eq refine ⟨⟨update 0 i s, by apply update_self i s.1 0 ▸ s.2⟩, funext fun j ↦ ?_⟩ obtain rfl | ne := eq_or_ne j i · simpa using hs · simp [update_of_ne ne] · obtain ⟨r, s, rfl⟩ := mk'_surjective S x exact ⟨mk' (M := T) _ (update 0 i r) ⟨update 0 i s, by apply update_self i s.1 0 ▸ s.2⟩, by simp [map_mk']⟩ end Localization section CommSemiring variable {R : Type*} [CommSemiring R] {M N : Submonoid R} {S : Type*} [CommSemiring S] variable [Algebra R S] {P : Type*} [CommSemiring P] namespace IsLocalization section IsLocalization variable [IsLocalization M S] variable (M S) in include M in theorem linearMap_compatibleSMul (N₁ N₂) [AddCommMonoid N₁] [AddCommMonoid N₂] [Module R N₁] [Module S N₁] [Module R N₂] [Module S N₂] [IsScalarTower R S N₁] [IsScalarTower R S N₂] : LinearMap.CompatibleSMul N₁ N₂ S R where map_smul f s s' := by obtain ⟨r, m, rfl⟩ := mk'_surjective M s rw [← (map_units S m).smul_left_cancel] simp_rw [algebraMap_smul, ← map_smul, ← smul_assoc, smul_mk'_self, algebraMap_smul, map_smul] variable {g : R →+* P} (hg : ∀ y : M, IsUnit (g y)) variable (M) in include M in -- This is not an instance since the submonoid `M` would become a metavariable in typeclass search. theorem algHom_subsingleton [Algebra R P] : Subsingleton (S →ₐ[R] P) := ⟨fun f g => AlgHom.coe_ringHom_injective <| IsLocalization.ringHom_ext M <| by rw [f.comp_algebraMap, g.comp_algebraMap]⟩ section AlgEquiv variable {Q : Type*} [CommSemiring Q] [Algebra R Q] [IsLocalization M Q] section variable (M S Q) /-- If `S`, `Q` are localizations of `R` at the submonoid `M` respectively, there is an isomorphism of localizations `S ≃ₐ[R] Q`. -/ @[simps!] noncomputable def algEquiv : S ≃ₐ[R] Q := { ringEquivOfRingEquiv S Q (RingEquiv.refl R) M.map_id with commutes' := ringEquivOfRingEquiv_eq _ } end theorem algEquiv_mk' (x : R) (y : M) : algEquiv M S Q (mk' S x y) = mk' Q x y := by simp theorem algEquiv_symm_mk' (x : R) (y : M) : (algEquiv M S Q).symm (mk' Q x y) = mk' S x y := by simp variable (M) in include M in protected lemma bijective (f : S →+* Q) (hf : f.comp (algebraMap R S) = algebraMap R Q) : Function.Bijective f := (show f = IsLocalization.algEquiv M S Q by apply IsLocalization.ringHom_ext M; rw [hf]; ext; simp) ▸ (IsLocalization.algEquiv M S Q).toEquiv.bijective end AlgEquiv section liftAlgHom variable {A : Type*} [CommSemiring A] {R : Type*} [CommSemiring R] [Algebra A R] {M : Submonoid R} {S : Type*} [CommSemiring S] [Algebra A S] [Algebra R S] [IsScalarTower A R S] {P : Type*} [CommSemiring P] [Algebra A P] [IsLocalization M S] {f : R →ₐ[A] P} (hf : ∀ y : M, IsUnit (f y)) (x : S) include hf /-- `AlgHom` version of `IsLocalization.lift`. -/ noncomputable def liftAlgHom : S →ₐ[A] P where __ := lift hf commutes' r := show lift hf (algebraMap A S r) = _ by simp [IsScalarTower.algebraMap_apply A R S] theorem liftAlgHom_toRingHom : (liftAlgHom hf : S →ₐ[A] P).toRingHom = lift hf := rfl @[simp] theorem coe_liftAlgHom : ⇑(liftAlgHom hf : S →ₐ[A] P) = lift hf := rfl theorem liftAlgHom_apply : liftAlgHom hf x = lift hf x := rfl end liftAlgHom section AlgEquivOfAlgEquiv variable {A : Type*} [CommSemiring A] {R : Type*} [CommSemiring R] [Algebra A R] {M : Submonoid R} (S : Type*) [CommSemiring S] [Algebra A S] [Algebra R S] [IsScalarTower A R S] [IsLocalization M S] {P : Type*} [CommSemiring P] [Algebra A P] {T : Submonoid P} (Q : Type*) [CommSemiring Q] [Algebra A Q] [Algebra P Q] [IsScalarTower A P Q] [IsLocalization T Q] (h : R ≃ₐ[A] P) (H : Submonoid.map h M = T) include H /-- If `S`, `Q` are localizations of `R` and `P` at submonoids `M`, `T` respectively, an isomorphism `h : R ≃ₐ[A] P` such that `h(M) = T` induces an isomorphism of localizations `S ≃ₐ[A] Q`. -/ @[simps!] noncomputable def algEquivOfAlgEquiv : S ≃ₐ[A] Q where __ := ringEquivOfRingEquiv S Q h.toRingEquiv H commutes' _ := by dsimp; rw [IsScalarTower.algebraMap_apply A R S, map_eq, RingHom.coe_coe, AlgEquiv.commutes, IsScalarTower.algebraMap_apply A P Q] variable {S Q h} theorem algEquivOfAlgEquiv_eq_map : (algEquivOfAlgEquiv S Q h H : S →+* Q) = map Q (h : R →+* P) (M.le_comap_of_map_le (le_of_eq H)) := rfl theorem algEquivOfAlgEquiv_eq (x : R) : algEquivOfAlgEquiv S Q h H ((algebraMap R S) x) = algebraMap P Q (h x) := by simp set_option linter.docPrime false in theorem algEquivOfAlgEquiv_mk' (x : R) (y : M) : algEquivOfAlgEquiv S Q h H (mk' S x y) = mk' Q (h x) ⟨h y, show h y ∈ T from H ▸ Set.mem_image_of_mem h y.2⟩ := by simp [map_mk'] theorem algEquivOfAlgEquiv_symm : (algEquivOfAlgEquiv S Q h H).symm = algEquivOfAlgEquiv Q S h.symm (show Submonoid.map h.symm T = M by rw [← H, ← Submonoid.map_coe_toMulEquiv, AlgEquiv.symm_toMulEquiv, ← Submonoid.comap_equiv_eq_map_symm, ← Submonoid.map_coe_toMulEquiv, Submonoid.comap_map_eq_of_injective (h : R ≃* P).injective]) := rfl end AlgEquivOfAlgEquiv section at_units variable (R M) /-- The localization at a module of units is isomorphic to the ring. -/ noncomputable def atUnits (H : M ≤ IsUnit.submonoid R) : R ≃ₐ[R] S := by refine AlgEquiv.ofBijective (Algebra.ofId R S) ⟨?_, ?_⟩ · intro x y hxy obtain ⟨c, eq⟩ := (IsLocalization.eq_iff_exists M S).mp hxy obtain ⟨u, hu⟩ := H c.prop rwa [← hu, Units.mul_right_inj] at eq · intro y obtain ⟨⟨x, s⟩, eq⟩ := IsLocalization.surj M y obtain ⟨u, hu⟩ := H s.prop use x * u.inv dsimp [Algebra.ofId, RingHom.toFun_eq_coe, AlgHom.coe_mks] rw [RingHom.map_mul, ← eq, ← hu, mul_assoc, ← RingHom.map_mul] simp end at_units end IsLocalization section variable (M N) theorem isLocalization_of_algEquiv [Algebra R P] [IsLocalization M S] (h : S ≃ₐ[R] P) : IsLocalization M P := by constructor · intro y convert (IsLocalization.map_units S y).map h.toAlgHom.toRingHom.toMonoidHom exact (h.commutes y).symm · intro y obtain ⟨⟨x, s⟩, e⟩ := IsLocalization.surj M (h.symm y) apply_fun (show S → P from h) at e simp only [map_mul, h.apply_symm_apply, h.commutes] at e exact ⟨⟨x, s⟩, e⟩ · intro x y rw [← h.symm.toEquiv.injective.eq_iff, ← IsLocalization.eq_iff_exists M S, ← h.symm.commutes, ← h.symm.commutes] exact id theorem isLocalization_iff_of_algEquiv [Algebra R P] (h : S ≃ₐ[R] P) : IsLocalization M S ↔ IsLocalization M P := ⟨fun _ => isLocalization_of_algEquiv M h, fun _ => isLocalization_of_algEquiv M h.symm⟩ theorem isLocalization_iff_of_ringEquiv (h : S ≃+* P) : IsLocalization M S ↔ haveI := (h.toRingHom.comp <| algebraMap R S).toAlgebra; IsLocalization M P := letI := (h.toRingHom.comp <| algebraMap R S).toAlgebra isLocalization_iff_of_algEquiv M { h with commutes' := fun _ => rfl } variable (S) in /-- If an algebra is simultaneously localizations for two submonoids, then an arbitrary algebra is a localization of one submonoid iff it is a localization of the other. -/ theorem isLocalization_iff_of_isLocalization [IsLocalization M S] [IsLocalization N S] [Algebra R P] : IsLocalization M P ↔ IsLocalization N P := ⟨fun _ ↦ isLocalization_of_algEquiv N (algEquiv M S P), fun _ ↦ isLocalization_of_algEquiv M (algEquiv N S P)⟩ theorem iff_of_le_of_exists_dvd (N : Submonoid R) (h₁ : M ≤ N) (h₂ : ∀ n ∈ N, ∃ m ∈ M, n ∣ m) : IsLocalization M S ↔ IsLocalization N S := have : IsLocalization N (Localization M) := of_le_of_exists_dvd _ _ h₁ h₂ isLocalization_iff_of_isLocalization _ _ (Localization M) end variable (M) /-- If `S₁` is the localization of `R` at `M₁` and `S₂` is the localization of `R` at `M₂`, then every localization `T` of `S₂` at `M₁` is also a localization of `S₁` at `M₂`, in other words `M₁⁻¹M₂⁻¹R` can be identified with `M₂⁻¹M₁⁻¹R`. -/ lemma commutes (S₁ S₂ T : Type*) [CommSemiring S₁] [CommSemiring S₂] [CommSemiring T] [Algebra R S₁] [Algebra R S₂] [Algebra R T] [Algebra S₁ T] [Algebra S₂ T] [IsScalarTower R S₁ T] [IsScalarTower R S₂ T] (M₁ M₂ : Submonoid R) [IsLocalization M₁ S₁] [IsLocalization M₂ S₂] [IsLocalization (Algebra.algebraMapSubmonoid S₂ M₁) T] : IsLocalization (Algebra.algebraMapSubmonoid S₁ M₂) T where map_units' := by rintro ⟨m, ⟨a, ha, rfl⟩⟩ rw [← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply R S₂ T] exact IsUnit.map _ (IsLocalization.map_units' ⟨a, ha⟩) surj' a := by obtain ⟨⟨y, -, m, hm, rfl⟩, hy⟩ := surj (M := Algebra.algebraMapSubmonoid S₂ M₁) a rw [← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply R S₁ T] at hy obtain ⟨⟨z, n, hn⟩, hz⟩ := IsLocalization.surj (M := M₂) y have hunit : IsUnit (algebraMap R S₁ m) := map_units' ⟨m, hm⟩ use ⟨algebraMap R S₁ z * hunit.unit⁻¹, ⟨algebraMap R S₁ n, n, hn, rfl⟩⟩ rw [map_mul, ← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply R S₂ T] conv_rhs => rw [← IsScalarTower.algebraMap_apply] rw [IsScalarTower.algebraMap_apply R S₂ T, ← hz, map_mul, ← hy] convert_to _ = a * (algebraMap S₂ T) ((algebraMap R S₂) n) * (algebraMap S₁ T) (((algebraMap R S₁) m) * hunit.unit⁻¹.val) · rw [map_mul] ring simp exists_of_eq {x y} hxy := by obtain ⟨r, s, d, hr, hs⟩ := IsLocalization.surj₂ M₁ S₁ x y apply_fun (· * algebraMap S₁ T (algebraMap R S₁ d)) at hxy simp_rw [← map_mul, hr, hs, ← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply R S₂ T] at hxy obtain ⟨⟨-, c, hmc, rfl⟩, hc⟩ := exists_of_eq (M := Algebra.algebraMapSubmonoid S₂ M₁) hxy simp_rw [← map_mul] at hc obtain ⟨a, ha⟩ := IsLocalization.exists_of_eq (M := M₂) hc use ⟨algebraMap R S₁ a, a, a.property, rfl⟩ apply (map_units S₁ d).mul_right_cancel rw [mul_assoc, hr, mul_assoc, hs] apply (map_units S₁ ⟨c, hmc⟩).mul_right_cancel rw [← map_mul, ← map_mul, mul_assoc, mul_comm _ c, ha, map_mul, map_mul] ring end IsLocalization namespace Localization open IsLocalization theorem mk_natCast (m : ℕ) : (mk m 1 : Localization M) = m := by simpa using mk_algebraMap (R := R) (A := ℕ) _ variable [IsLocalization M S] section variable (S) (M) /-- The localization of `R` at `M` as a quotient type is isomorphic to any other localization. -/ @[simps!] noncomputable def algEquiv : Localization M ≃ₐ[R] S := IsLocalization.algEquiv M _ _ /-- The localization of a singleton is a singleton. Cannot be an instance due to metavariables. -/ noncomputable def _root_.IsLocalization.unique (R Rₘ) [CommSemiring R] [CommSemiring Rₘ] (M : Submonoid R) [Subsingleton R] [Algebra R Rₘ] [IsLocalization M Rₘ] : Unique Rₘ := have : Inhabited Rₘ := ⟨1⟩ (algEquiv M Rₘ).symm.injective.unique end nonrec theorem algEquiv_mk' (x : R) (y : M) : algEquiv M S (mk' (Localization M) x y) = mk' S x y := algEquiv_mk' _ _ nonrec theorem algEquiv_symm_mk' (x : R) (y : M) : (algEquiv M S).symm (mk' S x y) = mk' (Localization M) x y := algEquiv_symm_mk' _ _ theorem algEquiv_mk (x y) : algEquiv M S (mk x y) = mk' S x y := by rw [mk_eq_mk', algEquiv_mk'] theorem algEquiv_symm_mk (x : R) (y : M) : (algEquiv M S).symm (mk' S x y) = mk x y := by rw [mk_eq_mk', algEquiv_symm_mk'] lemma coe_algEquiv : (Localization.algEquiv M S : Localization M →+* S) = IsLocalization.map (M := M) (T := M) _ (RingHom.id R) le_rfl := rfl lemma coe_algEquiv_symm : ((Localization.algEquiv M S).symm : S →+* Localization M) = IsLocalization.map (M := M) (T := M) _ (RingHom.id R) le_rfl := rfl end Localization end CommSemiring section CommRing variable {R : Type*} [CommRing R] {M : Submonoid R} (S : Type*) [CommRing S] variable [Algebra R S] {P : Type*} [CommRing P] namespace Localization theorem mk_intCast (m : ℤ) : (mk m 1 : Localization M) = m := by simpa using mk_algebraMap (R := R) (A := ℤ) _ end Localization open IsLocalization /-- If `R` is a field, then localizing at a submonoid not containing `0` adds no new elements. -/ theorem IsField.localization_map_bijective {R Rₘ : Type*} [CommRing R] [CommRing Rₘ] {M : Submonoid R} (hM : (0 : R) ∉ M) (hR : IsField R) [Algebra R Rₘ] [IsLocalization M Rₘ] : Function.Bijective (algebraMap R Rₘ) := by letI := hR.toField replace hM := le_nonZeroDivisors_of_noZeroDivisors hM refine ⟨IsLocalization.injective _ hM, fun x => ?_⟩ obtain ⟨r, ⟨m, hm⟩, rfl⟩ := mk'_surjective M x obtain ⟨n, hn⟩ := hR.mul_inv_cancel (nonZeroDivisors.ne_zero <| hM hm) exact ⟨r * n, by rw [eq_mk'_iff_mul_eq, ← map_mul, mul_assoc, _root_.mul_comm n, hn, mul_one]⟩ /-- If `R` is a field, then localizing at a submonoid not containing `0` adds no new elements. -/ theorem Field.localization_map_bijective {K Kₘ : Type*} [Field K] [CommRing Kₘ] {M : Submonoid K} (hM : (0 : K) ∉ M) [Algebra K Kₘ] [IsLocalization M Kₘ] : Function.Bijective (algebraMap K Kₘ) := (Field.toIsField K).localization_map_bijective hM -- this looks weird due to the `letI` inside the above lemma, but trying to do it the other -- way round causes issues with defeq of instances, so this is actually easier. section Algebra variable {S} {Rₘ Sₘ : Type*} [CommRing Rₘ] [CommRing Sₘ] variable [Algebra R Rₘ] [IsLocalization M Rₘ] variable [Algebra S Sₘ] [i : IsLocalization (Algebra.algebraMapSubmonoid S M) Sₘ] include S section variable (S M) /-- Definition of the natural algebra induced by the localization of an algebra. Given an algebra `R → S`, a submonoid `R` of `M`, and a localization `Rₘ` for `M`, let `Sₘ` be the localization of `S` to the image of `M` under `algebraMap R S`. Then this is the natural algebra structure on `Rₘ → Sₘ`, such that the entire square commutes, where `localization_map.map_comp` gives the commutativity of the underlying maps. This instance can be helpful if you define `Sₘ := Localization (Algebra.algebraMapSubmonoid S M)`, however we will instead use the hypotheses `[Algebra Rₘ Sₘ] [IsScalarTower R Rₘ Sₘ]` in lemmas since the algebra structure may arise in different ways. -/ noncomputable def localizationAlgebra : Algebra Rₘ Sₘ := (map Sₘ (algebraMap R S) (show _ ≤ (Algebra.algebraMapSubmonoid S M).comap _ from M.le_comap_map) : Rₘ →+* Sₘ).toAlgebra end section variable [Algebra Rₘ Sₘ] [Algebra R Sₘ] [IsScalarTower R Rₘ Sₘ] [IsScalarTower R S Sₘ] variable (S Rₘ Sₘ) theorem IsLocalization.map_units_map_submonoid (y : M) : IsUnit (algebraMap R Sₘ y) := by rw [IsScalarTower.algebraMap_apply _ S] exact IsLocalization.map_units Sₘ ⟨algebraMap R S y, Algebra.mem_algebraMapSubmonoid_of_mem y⟩ -- can't be simp, as `S` only appears on the RHS theorem IsLocalization.algebraMap_mk' (x : R) (y : M) : algebraMap Rₘ Sₘ (IsLocalization.mk' Rₘ x y) = IsLocalization.mk' Sₘ (algebraMap R S x) ⟨algebraMap R S y, Algebra.mem_algebraMapSubmonoid_of_mem y⟩ := by rw [IsLocalization.eq_mk'_iff_mul_eq, Subtype.coe_mk, ← IsScalarTower.algebraMap_apply, ← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply R Rₘ Sₘ, IsScalarTower.algebraMap_apply R Rₘ Sₘ, ← map_mul, mul_comm, IsLocalization.mul_mk'_eq_mk'_of_mul] exact congr_arg (algebraMap Rₘ Sₘ) (IsLocalization.mk'_mul_cancel_left x y) variable (M) /-- If the square below commutes, the bottom map is uniquely specified: ``` R → S ↓ ↓ Rₘ → Sₘ ``` -/ theorem IsLocalization.algebraMap_eq_map_map_submonoid : algebraMap Rₘ Sₘ = map Sₘ (algebraMap R S) (show _ ≤ (Algebra.algebraMapSubmonoid S M).comap _ from M.le_comap_map) := Eq.symm <| IsLocalization.map_unique _ (algebraMap Rₘ Sₘ) fun x => by rw [← IsScalarTower.algebraMap_apply R S Sₘ, ← IsScalarTower.algebraMap_apply R Rₘ Sₘ] /-- If the square below commutes, the bottom map is uniquely specified: ``` R → S ↓ ↓ Rₘ → Sₘ ``` -/ theorem IsLocalization.algebraMap_apply_eq_map_map_submonoid (x) : algebraMap Rₘ Sₘ x = map Sₘ (algebraMap R S) (show _ ≤ (Algebra.algebraMapSubmonoid S M).comap _ from M.le_comap_map) x := DFunLike.congr_fun (IsLocalization.algebraMap_eq_map_map_submonoid _ _ _ _) x theorem IsLocalization.lift_algebraMap_eq_algebraMap : IsLocalization.lift (M := M) (IsLocalization.map_units_map_submonoid S Sₘ) = algebraMap Rₘ Sₘ := IsLocalization.lift_unique _ fun _ => (IsScalarTower.algebraMap_apply _ _ _ _).symm end variable (Rₘ Sₘ) theorem localizationAlgebraMap_def : @algebraMap Rₘ Sₘ _ _ (localizationAlgebra M S) = map Sₘ (algebraMap R S) (show _ ≤ (Algebra.algebraMapSubmonoid S M).comap _ from M.le_comap_map) := rfl /-- Injectivity of the underlying `algebraMap` descends to the algebra induced by localization. -/ theorem localizationAlgebra_injective (hRS : Function.Injective (algebraMap R S)) : Function.Injective (@algebraMap Rₘ Sₘ _ _ (localizationAlgebra M S)) := have : IsLocalization (M.map (algebraMap R S)) Sₘ := i IsLocalization.map_injective_of_injective _ _ _ hRS end Algebra end CommRing
Mathlib/RingTheory/Localization/Basic.lean
1,209
1,215
/- 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.Algebra.Group.Embedding import Mathlib.Order.Interval.Multiset /-! # Finite intervals of naturals This file proves that `ℕ` is a `LocallyFiniteOrder` and calculates the cardinality of its intervals as finsets and fintypes. ## TODO Some lemmas can be generalized using `OrderedGroup`, `CanonicallyOrderedMul` or `SuccOrder` and subsequently be moved upstream to `Order.Interval.Finset`. -/ assert_not_exists Ring open Finset Nat variable (a b c : ℕ) namespace Nat instance instLocallyFiniteOrder : LocallyFiniteOrder ℕ where finsetIcc a b := ⟨List.range' a (b + 1 - a), List.nodup_range'⟩ finsetIco a b := ⟨List.range' a (b - a), List.nodup_range'⟩ finsetIoc a b := ⟨List.range' (a + 1) (b - a), List.nodup_range'⟩ finsetIoo a b := ⟨List.range' (a + 1) (b - a - 1), List.nodup_range'⟩ finset_mem_Icc a b x := by rw [Finset.mem_mk, Multiset.mem_coe, List.mem_range'_1]; omega finset_mem_Ico a b x := by rw [Finset.mem_mk, Multiset.mem_coe, List.mem_range'_1]; omega finset_mem_Ioc a b x := by rw [Finset.mem_mk, Multiset.mem_coe, List.mem_range'_1]; omega finset_mem_Ioo a b x := by rw [Finset.mem_mk, Multiset.mem_coe, List.mem_range'_1]; omega theorem Icc_eq_range' : Icc a b = ⟨List.range' a (b + 1 - a), List.nodup_range'⟩ := rfl theorem Ico_eq_range' : Ico a b = ⟨List.range' a (b - a), List.nodup_range'⟩ := rfl theorem Ioc_eq_range' : Ioc a b = ⟨List.range' (a + 1) (b - a), List.nodup_range'⟩ := rfl theorem Ioo_eq_range' : Ioo a b = ⟨List.range' (a + 1) (b - a - 1), List.nodup_range'⟩ := rfl theorem uIcc_eq_range' : uIcc a b = ⟨List.range' (min a b) (max a b + 1 - min a b), List.nodup_range'⟩ := rfl theorem Iio_eq_range : Iio = range := by ext b x rw [mem_Iio, mem_range] @[simp] theorem Ico_zero_eq_range : Ico 0 = range := by rw [← Nat.bot_eq_zero, ← Iio_eq_Ico, Iio_eq_range] lemma range_eq_Icc_zero_sub_one (n : ℕ) (hn : n ≠ 0) : range n = Icc 0 (n - 1) := by ext b simp_all only [mem_Icc, zero_le, true_and, mem_range] exact lt_iff_le_pred (zero_lt_of_ne_zero hn) theorem _root_.Finset.range_eq_Ico : range = Ico 0 := Ico_zero_eq_range.symm theorem range_succ_eq_Icc_zero (n : ℕ) : range (n + 1) = Icc 0 n := by rw [range_eq_Icc_zero_sub_one _ (Nat.add_one_ne_zero _), Nat.add_sub_cancel_right] @[simp] lemma card_Icc : #(Icc a b) = b + 1 - a := List.length_range' .. @[simp] lemma card_Ico : #(Ico a b) = b - a := List.length_range' .. @[simp] lemma card_Ioc : #(Ioc a b) = b - a := List.length_range' .. @[simp] lemma card_Ioo : #(Ioo a b) = b - a - 1 := List.length_range' .. @[simp] theorem card_uIcc : #(uIcc a b) = (b - a : ℤ).natAbs + 1 := (card_Icc _ _).trans <| by rw [← Int.natCast_inj, Int.ofNat_sub] <;> omega @[simp] lemma card_Iic : #(Iic b) = b + 1 := by rw [Iic_eq_Icc, card_Icc, Nat.bot_eq_zero, Nat.sub_zero] @[simp] theorem card_Iio : #(Iio b) = b := by rw [Iio_eq_Ico, card_Ico, Nat.bot_eq_zero, Nat.sub_zero] @[deprecated Fintype.card_Icc (since := "2025-03-28")] theorem card_fintypeIcc : Fintype.card (Set.Icc a b) = b + 1 - a := by simp @[deprecated Fintype.card_Ico (since := "2025-03-28")] theorem card_fintypeIco : Fintype.card (Set.Ico a b) = b - a := by simp @[deprecated Fintype.card_Ioc (since := "2025-03-28")] theorem card_fintypeIoc : Fintype.card (Set.Ioc a b) = b - a := by simp @[deprecated Fintype.card_Ioo (since := "2025-03-28")] theorem card_fintypeIoo : Fintype.card (Set.Ioo a b) = b - a - 1 := by simp @[deprecated Fintype.card_Iic (since := "2025-03-28")] theorem card_fintypeIic : Fintype.card (Set.Iic b) = b + 1 := by simp @[deprecated Fintype.card_Iio (since := "2025-03-28")] theorem card_fintypeIio : Fintype.card (Set.Iio b) = b := by simp -- TODO@Yaël: Generalize all the following lemmas to `SuccOrder` theorem Icc_succ_left : Icc a.succ b = Ioc a b := by ext x rw [mem_Icc, mem_Ioc, succ_le_iff] theorem Ico_succ_right : Ico a b.succ = Icc a b := by ext x rw [mem_Ico, mem_Icc, Nat.lt_succ_iff] theorem Ico_succ_left : Ico a.succ b = Ioo a b := by ext x rw [mem_Ico, mem_Ioo, succ_le_iff] theorem Icc_pred_right {b : ℕ} (h : 0 < b) : Icc a (b - 1) = Ico a b := by ext x rw [mem_Icc, mem_Ico, lt_iff_le_pred h] theorem Ico_succ_succ : Ico a.succ b.succ = Ioc a b := by ext x rw [mem_Ico, mem_Ioc, succ_le_iff, Nat.lt_succ_iff] @[simp] theorem Ico_succ_singleton : Ico a (a + 1) = {a} := by rw [Ico_succ_right, Icc_self] @[simp] theorem Ico_pred_singleton {a : ℕ} (h : 0 < a) : Ico (a - 1) a = {a - 1} := by rw [← Icc_pred_right _ h, Icc_self] @[simp] theorem Ioc_succ_singleton : Ioc b (b + 1) = {b + 1} := by rw [← Nat.Icc_succ_left, Icc_self] variable {a b c} lemma mem_Ioc_succ : a ∈ Ioc b (b + 1) ↔ a = b + 1 := by simp lemma mem_Ioc_succ' (a : Ioc b (b + 1)) : a = ⟨b + 1, mem_Ioc.2 (by omega)⟩ := Subtype.val_inj.1 (mem_Ioc_succ.1 a.2) theorem Ico_succ_right_eq_insert_Ico (h : a ≤ b) : Ico a (b + 1) = insert b (Ico a b) := by rw [Ico_succ_right, ← Ico_insert_right h] theorem Ico_insert_succ_left (h : a < b) : insert a (Ico a.succ b) = Ico a b := by rw [Ico_succ_left, ← Ioo_insert_left h] lemma Icc_insert_succ_left (h : a ≤ b) : insert a (Icc (a + 1) b) = Icc a b := by ext x simp only [mem_insert, mem_Icc] omega lemma Icc_insert_succ_right (h : a ≤ b + 1) : insert (b + 1) (Icc a b) = Icc a (b + 1) := by ext x simp only [mem_insert, mem_Icc] omega theorem image_sub_const_Ico (h : c ≤ a) : ((Ico a b).image fun x => x - c) = Ico (a - c) (b - c) := by ext x simp_rw [mem_image, mem_Ico] refine ⟨?_, fun h ↦ ⟨x + c, by omega⟩⟩ rintro ⟨x, hx, rfl⟩ omega theorem Ico_image_const_sub_eq_Ico (hac : a ≤ c) : ((Ico a b).image fun x => c - x) = Ico (c + 1 - b) (c + 1 - a) := by ext x simp_rw [mem_image, mem_Ico] refine ⟨?_, fun h ↦ ⟨c - x, by omega⟩⟩ rintro ⟨x, hx, rfl⟩ omega theorem Ico_succ_left_eq_erase_Ico : Ico a.succ b = erase (Ico a b) a := by ext x rw [Ico_succ_left, mem_erase, mem_Ico, mem_Ioo, ← and_assoc, ne_comm, and_comm (a := a ≠ x), lt_iff_le_and_ne] theorem mod_injOn_Ico (n a : ℕ) : Set.InjOn (· % a) (Finset.Ico n (n + a)) := by induction' n with n ih · simp only [zero_add, Ico_zero_eq_range] rintro k hk l hl (hkl : k % a = l % a) simp only [Finset.mem_range, Finset.mem_coe] at hk hl rwa [mod_eq_of_lt hk, mod_eq_of_lt hl] at hkl rw [Ico_succ_left_eq_erase_Ico, succ_add, succ_eq_add_one, Ico_succ_right_eq_insert_Ico (by omega)] rintro k hk l hl (hkl : k % a = l % a) have ha : 0 < a := Nat.pos_iff_ne_zero.2 <| by rintro rfl; simp at hk simp only [Finset.mem_coe, Finset.mem_insert, Finset.mem_erase] at hk hl rcases hk with ⟨hkn, rfl | hk⟩ <;> rcases hl with ⟨hln, rfl | hl⟩ · rfl · rw [add_mod_right] at hkl refine (hln <| ih hl ?_ hkl.symm).elim simpa using Nat.lt_add_of_pos_right (n := n) ha · rw [add_mod_right] at hkl suffices k = n by contradiction refine ih hk ?_ hkl simpa using Nat.lt_add_of_pos_right (n := n) ha · refine ih ?_ ?_ hkl <;> simp only [Finset.mem_coe, hk, hl] /-- Note that while this lemma cannot be easily generalized to a type class, it holds for ℤ as well. See `Int.image_Ico_emod` for the ℤ version. -/ theorem image_Ico_mod (n a : ℕ) : (Ico n (n + a)).image (· % a) = range a := by obtain rfl | ha := eq_or_ne a 0 · rw [range_zero, add_zero, Ico_self, image_empty] ext i simp only [mem_image, exists_prop, mem_range, mem_Ico] constructor · rintro ⟨i, _, rfl⟩ exact mod_lt i ha.bot_lt intro hia have hn := Nat.mod_add_div n a obtain hi | hi := lt_or_le i (n % a) · refine ⟨i + a * (n / a + 1), ⟨?_, ?_⟩, ?_⟩ · rw [add_comm (n / a), Nat.mul_add, mul_one, ← add_assoc] refine hn.symm.le.trans (Nat.add_le_add_right ?_ _) simpa only [zero_add] using add_le_add (zero_le i) (Nat.mod_lt n ha.bot_lt).le · refine lt_of_lt_of_le (Nat.add_lt_add_right hi (a * (n / a + 1))) ?_ rw [Nat.mul_add, mul_one, ← add_assoc, hn] · rw [Nat.add_mul_mod_self_left, Nat.mod_eq_of_lt hia] · refine ⟨i + a * (n / a), ⟨?_, ?_⟩, ?_⟩ · omega · omega · rw [Nat.add_mul_mod_self_left, Nat.mod_eq_of_lt hia] section Multiset open Multiset theorem multiset_Ico_map_mod (n a : ℕ) : (Multiset.Ico n (n + a)).map (· % a) = Multiset.range a := by convert congr_arg Finset.val (image_Ico_mod n a) refine ((nodup_map_iff_inj_on (Finset.Ico _ _).nodup).2 <| ?_).dedup.symm exact mod_injOn_Ico _ _ end Multiset end Nat namespace List lemma toFinset_range'_1 (a b : ℕ) : (List.range' a b).toFinset = Ico a (a + b) := by ext x rw [List.mem_toFinset, List.mem_range'_1, Finset.mem_Ico] lemma toFinset_range'_1_1 (a : ℕ) : (List.range' 1 a).toFinset = Icc 1 a := by ext x rw [List.mem_toFinset, List.mem_range'_1, add_comm, Nat.lt_succ_iff, Finset.mem_Icc] end List namespace Finset theorem range_image_pred_top_sub (n : ℕ) : ((Finset.range n).image fun j => n - 1 - j) = Finset.range n := by cases n · rw [range_zero, image_empty] · rw [Finset.range_eq_Ico, Nat.Ico_image_const_sub_eq_Ico (Nat.zero_le _)] simp_rw [succ_sub_succ, Nat.sub_zero, Nat.sub_self] theorem range_add_eq_union : range (a + b) = range a ∪ (range b).map (addLeftEmbedding a) := by rw [Finset.range_eq_Ico, map_eq_image] convert (Ico_union_Ico_eq_Ico a.zero_le (a.le_add_right b)).symm ext x simp only [Ico_zero_eq_range, mem_image, mem_range, addLeftEmbedding_apply, mem_Ico] constructor · aesop · rintro h exact ⟨x - a, by omega⟩ end Finset section Induction variable {P : ℕ → Prop} theorem Nat.decreasing_induction_of_not_bddAbove (h : ∀ n, P (n + 1) → P n) (hP : ¬BddAbove { x | P x }) (n : ℕ) : P n := let ⟨_, hm, hl⟩ := not_bddAbove_iff.1 hP n decreasingInduction (fun _ _ => h _) hm hl.le @[elab_as_elim] lemma Nat.strong_decreasing_induction (base : ∃ n, ∀ m > n, P m) (step : ∀ n, (∀ m > n, P m) → P n) (n : ℕ) : P n := by apply Nat.decreasing_induction_of_not_bddAbove (P := fun n ↦ ∀ m ≥ n, P m) _ _ n n le_rfl · intro n ih m hm rcases hm.eq_or_lt with rfl | hm · exact step n ih · exact ih m hm · rintro ⟨b, hb⟩ rcases base with ⟨n, hn⟩ specialize @hb (n + b + 1) (fun m hm ↦ hn _ _) all_goals omega theorem Nat.decreasing_induction_of_infinite (h : ∀ n, P (n + 1) → P n) (hP : { x | P x }.Infinite) (n : ℕ) : P n := Nat.decreasing_induction_of_not_bddAbove h (mt BddAbove.finite hP) n theorem Nat.cauchy_induction' (seed : ℕ) (h : ∀ n, P (n + 1) → P n) (hs : P seed) (hi : ∀ x, seed ≤ x → P x → ∃ y, x < y ∧ P y) (n : ℕ) : P n := by apply Nat.decreasing_induction_of_infinite h fun hf => _ intro hf obtain ⟨m, hP, hm⟩ := hf.exists_maximal_wrt id _ ⟨seed, hs⟩ obtain ⟨y, hl, hy⟩ := hi m (le_of_not_lt fun hl => hl.ne <| hm seed hs hl.le) hP exact hl.ne (hm y hy hl.le) theorem Nat.cauchy_induction (h : ∀ n, P (n + 1) → P n) (seed : ℕ) (hs : P seed) (f : ℕ → ℕ) (hf : ∀ x, seed ≤ x → P x → x < f x ∧ P (f x)) (n : ℕ) : P n := seed.cauchy_induction' h hs (fun x hl hx => ⟨f x, hf x hl hx⟩) n theorem Nat.cauchy_induction_mul (h : ∀ (n : ℕ), P (n + 1) → P n) (k seed : ℕ) (hk : 1 < k) (hs : P seed.succ) (hm : ∀ x, seed < x → P x → P (k * x)) (n : ℕ) : P n := by apply Nat.cauchy_induction h _ hs (k * ·) fun x hl hP => ⟨_, hm x hl hP⟩ intro _ hl _ convert (Nat.mul_lt_mul_right <| seed.succ_pos.trans_le hl).2 hk rw [one_mul] theorem Nat.cauchy_induction_two_mul (h : ∀ n, P (n + 1) → P n) (seed : ℕ) (hs : P seed.succ) (hm : ∀ x, seed < x → P x → P (2 * x)) (n : ℕ) : P n := Nat.cauchy_induction_mul h 2 seed Nat.one_lt_two hs hm n theorem Nat.pow_imp_self_of_one_lt {M} [Monoid M] (k : ℕ) (hk : 1 < k) (P : M → Prop) (hmul : ∀ x y, P x → P (x * y) ∨ P (y * x)) (hpow : ∀ x, P (x ^ k) → P x) : ∀ n x, P (x ^ n) → P x := k.cauchy_induction_mul (fun n ih x hx ↦ ih x <| (hmul _ x hx).elim (fun h ↦ by rwa [_root_.pow_succ]) fun h ↦ by rwa [_root_.pow_succ']) 0 hk (fun x hx ↦ pow_one x ▸ hx) fun n _ hn x hx ↦ hpow x <| hn _ <| (pow_mul x k n).subst hx end Induction
Mathlib/Order/Interval/Finset/Nat.lean
360
365
/- Copyright (c) 2023 Jz Pan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jz Pan -/ import Mathlib.FieldTheory.SplittingField.Construction import Mathlib.FieldTheory.IsAlgClosed.AlgebraicClosure import Mathlib.FieldTheory.Separable import Mathlib.FieldTheory.Normal.Closure import Mathlib.RingTheory.AlgebraicIndependent.Adjoin import Mathlib.RingTheory.AlgebraicIndependent.TranscendenceBasis import Mathlib.RingTheory.Polynomial.SeparableDegree import Mathlib.RingTheory.Polynomial.UniqueFactorization /-! # Separable degree This file contains basics about the separable degree of a field extension. ## Main definitions - `Field.Emb F E`: the type of `F`-algebra homomorphisms from `E` to the algebraic closure of `E` (the algebraic closure of `F` is usually used in the literature, but our definition has the advantage that `Field.Emb F E` lies in the same universe as `E` rather than the maximum over `F` and `E`). Usually denoted by $\operatorname{Emb}_F(E)$ in textbooks. - `Field.finSepDegree F E`: the (finite) separable degree $[E:F]_s$ of an extension `E / F` of fields, defined to be the number of `F`-algebra homomorphisms from `E` to the algebraic closure of `E`, as a natural number. It is zero if `Field.Emb F E` is not finite. Note that if `E / F` is not algebraic, then this definition makes no mathematical sense. **Remark:** the `Cardinal`-valued, potentially infinite separable degree `Field.sepDegree F E` for a general algebraic extension `E / F` is defined to be the degree of `L / F`, where `L` is the separable closure of `F` in `E`, which is not defined in this file yet. Later we will show that (`Field.finSepDegree_eq`), if `Field.Emb F E` is finite, then these two definitions coincide. If `E / F` is algebraic with infinite separable degree, we have `#(Field.Emb F E) = 2 ^ Field.sepDegree F E` instead. (See `Field.Emb.cardinal_eq_two_pow_sepDegree` in another file.) For example, if $F = \mathbb{Q}$ and $E = \mathbb{Q}( \mu_{p^\infty} )$, then $\operatorname{Emb}_F (E)$ is in bijection with $\operatorname{Gal}(E/F)$, which is isomorphic to $\mathbb{Z}_p^\times$, which is uncountable, whereas $ [E:F] $ is countable. - `Polynomial.natSepDegree`: the separable degree of a polynomial is a natural number, defined to be the number of distinct roots of it over its splitting field. ## Main results - `Field.embEquivOfEquiv`, `Field.finSepDegree_eq_of_equiv`: a random bijection between `Field.Emb F E` and `Field.Emb F K` when `E` and `K` are isomorphic as `F`-algebras. In particular, they have the same cardinality (so their `Field.finSepDegree` are equal). - `Field.embEquivOfAdjoinSplits`, `Field.finSepDegree_eq_of_adjoin_splits`: a random bijection between `Field.Emb F E` and `E →ₐ[F] K` if `E = F(S)` such that every element `s` of `S` is integral (= algebraic) over `F` and whose minimal polynomial splits in `K`. In particular, they have the same cardinality. - `Field.embEquivOfIsAlgClosed`, `Field.finSepDegree_eq_of_isAlgClosed`: a random bijection between `Field.Emb F E` and `E →ₐ[F] K` when `E / F` is algebraic and `K / F` is algebraically closed. In particular, they have the same cardinality. - `Field.embProdEmbOfIsAlgebraic`, `Field.finSepDegree_mul_finSepDegree_of_isAlgebraic`: if `K / E / F` is a field extension tower, such that `K / E` is algebraic, then there is a non-canonical bijection `Field.Emb F E × Field.Emb E K ≃ Field.Emb F K`. In particular, the separable degrees satisfy the tower law: $[E:F]_s [K:E]_s = [K:F]_s$ (see also `Module.finrank_mul_finrank`). - `Field.infinite_emb_of_transcendental`: `Field.Emb` is infinite for transcendental extensions. - `Polynomial.natSepDegree_le_natDegree`: the separable degree of a polynomial is smaller than its degree. - `Polynomial.natSepDegree_eq_natDegree_iff`: the separable degree of a non-zero polynomial is equal to its degree if and only if it is separable. - `Polynomial.natSepDegree_eq_of_splits`: if a polynomial splits over `E`, then its separable degree is equal to the number of distinct roots of it over `E`. - `Polynomial.natSepDegree_eq_of_isAlgClosed`: the separable degree of a polynomial is equal to the number of distinct roots of it over any algebraically closed field. - `Polynomial.natSepDegree_expand`: if a field `F` is of exponential characteristic `q`, then `Polynomial.expand F (q ^ n) f` and `f` have the same separable degree. - `Polynomial.HasSeparableContraction.natSepDegree_eq`: if a polynomial has separable contraction, then its separable degree is equal to its separable contraction degree. - `Irreducible.natSepDegree_dvd_natDegree`: the separable degree of an irreducible polynomial divides its degree. - `IntermediateField.finSepDegree_adjoin_simple_eq_natSepDegree`: the separable degree of `F⟮α⟯ / F` is equal to the separable degree of the minimal polynomial of `α` over `F`. - `IntermediateField.finSepDegree_adjoin_simple_eq_finrank_iff`: if `α` is algebraic over `F`, then the separable degree of `F⟮α⟯ / F` is equal to the degree of `F⟮α⟯ / F` if and only if `α` is a separable element. - `Field.finSepDegree_dvd_finrank`: the separable degree of any field extension `E / F` divides the degree of `E / F`. - `Field.finSepDegree_le_finrank`: the separable degree of a finite extension `E / F` is smaller than the degree of `E / F`. - `Field.finSepDegree_eq_finrank_iff`: if `E / F` is a finite extension, then its separable degree is equal to its degree if and only if it is a separable extension. - `IntermediateField.isSeparable_adjoin_simple_iff_isSeparable`: `F⟮x⟯ / F` is a separable extension if and only if `x` is a separable element. - `Algebra.IsSeparable.trans`: if `E / F` and `K / E` are both separable, then `K / F` is also separable. ## Tags separable degree, degree, polynomial -/ open Module Polynomial IntermediateField Field noncomputable section universe u v w variable (F : Type u) (E : Type v) [Field F] [Field E] [Algebra F E] variable (K : Type w) [Field K] [Algebra F K] namespace Field /-- `Field.Emb F E` is the type of `F`-algebra homomorphisms from `E` to the algebraic closure of `E`. -/ abbrev Emb := E →ₐ[F] AlgebraicClosure E /-- If `E / F` is an algebraic extension, then the (finite) separable degree of `E / F` is the number of `F`-algebra homomorphisms from `E` to the algebraic closure of `E`, as a natural number. It is defined to be zero if there are infinitely many of them. Note that if `E / F` is not algebraic, then this definition makes no mathematical sense. -/ def finSepDegree : ℕ := Nat.card (Emb F E) instance instInhabitedEmb : Inhabited (Emb F E) := ⟨IsScalarTower.toAlgHom F E _⟩ instance instNeZeroFinSepDegree [FiniteDimensional F E] : NeZero (finSepDegree F E) := ⟨Nat.card_ne_zero.2 ⟨inferInstance, Fintype.finite <| minpoly.AlgHom.fintype _ _ _⟩⟩ /-- A random bijection between `Field.Emb F E` and `Field.Emb F K` when `E` and `K` are isomorphic as `F`-algebras. -/ def embEquivOfEquiv (i : E ≃ₐ[F] K) : Emb F E ≃ Emb F K := AlgEquiv.arrowCongr i <| AlgEquiv.symm <| by let _ : Algebra E K := i.toAlgHom.toRingHom.toAlgebra have : Algebra.IsAlgebraic E K := by constructor intro x have h := isAlgebraic_algebraMap (R := E) (A := K) (i.symm.toAlgHom x) rw [show ∀ y : E, (algebraMap E K) y = i.toAlgHom y from fun y ↦ rfl] at h simpa only [AlgEquiv.toAlgHom_eq_coe, AlgHom.coe_coe, AlgEquiv.apply_symm_apply] using h apply AlgEquiv.restrictScalars (R := F) (S := E) exact IsAlgClosure.equivOfAlgebraic E K (AlgebraicClosure K) (AlgebraicClosure E) /-- If `E` and `K` are isomorphic as `F`-algebras, then they have the same `Field.finSepDegree` over `F`. -/ theorem finSepDegree_eq_of_equiv (i : E ≃ₐ[F] K) : finSepDegree F E = finSepDegree F K := Nat.card_congr (embEquivOfEquiv F E K i) @[simp] theorem finSepDegree_self : finSepDegree F F = 1 := by have : Cardinal.mk (Emb F F) = 1 := le_antisymm (Cardinal.le_one_iff_subsingleton.2 AlgHom.subsingleton) (Cardinal.one_le_iff_ne_zero.2 <| Cardinal.mk_ne_zero _) rw [finSepDegree, Nat.card, this, Cardinal.one_toNat] end Field namespace IntermediateField @[simp] theorem finSepDegree_bot : finSepDegree F (⊥ : IntermediateField F E) = 1 := by rw [finSepDegree_eq_of_equiv _ _ _ (botEquiv F E), finSepDegree_self] section Tower variable {F} variable [Algebra E K] [IsScalarTower F E K] @[simp] theorem finSepDegree_bot' : finSepDegree F (⊥ : IntermediateField E K) = finSepDegree F E := finSepDegree_eq_of_equiv _ _ _ ((botEquiv E K).restrictScalars F) @[simp] theorem finSepDegree_top : finSepDegree F (⊤ : IntermediateField E K) = finSepDegree F K := finSepDegree_eq_of_equiv _ _ _ ((topEquiv (F := E) (E := K)).restrictScalars F) end Tower end IntermediateField namespace Field /-- A random bijection between `Field.Emb F E` and `E →ₐ[F] K` if `E = F(S)` such that every element `s` of `S` is integral (= algebraic) over `F` and whose minimal polynomial splits in `K`. Combined with `Field.instInhabitedEmb`, it can be viewed as a stronger version of `IntermediateField.nonempty_algHom_of_adjoin_splits`. -/ def embEquivOfAdjoinSplits {S : Set E} (hS : adjoin F S = ⊤) (hK : ∀ s ∈ S, IsIntegral F s ∧ Splits (algebraMap F K) (minpoly F s)) : Emb F E ≃ (E →ₐ[F] K) := have : Algebra.IsAlgebraic F (⊤ : IntermediateField F E) := (hS ▸ isAlgebraic_adjoin (S := S) fun x hx ↦ (hK x hx).1) have halg := (topEquiv (F := F) (E := E)).isAlgebraic Classical.choice <| Function.Embedding.antisymm (halg.algHomEmbeddingOfSplits (fun _ ↦ splits_of_mem_adjoin F E (S := S) hK (hS ▸ mem_top)) _) (halg.algHomEmbeddingOfSplits (fun _ ↦ IsAlgClosed.splits_codomain _) _) /-- The `Field.finSepDegree F E` is equal to the cardinality of `E →ₐ[F] K` if `E = F(S)` such that every element `s` of `S` is integral (= algebraic) over `F` and whose minimal polynomial splits in `K`. -/ theorem finSepDegree_eq_of_adjoin_splits {S : Set E} (hS : adjoin F S = ⊤) (hK : ∀ s ∈ S, IsIntegral F s ∧ Splits (algebraMap F K) (minpoly F s)) : finSepDegree F E = Nat.card (E →ₐ[F] K) := Nat.card_congr (embEquivOfAdjoinSplits F E K hS hK) /-- A random bijection between `Field.Emb F E` and `E →ₐ[F] K` when `E / F` is algebraic and `K / F` is algebraically closed. -/ def embEquivOfIsAlgClosed [Algebra.IsAlgebraic F E] [IsAlgClosed K] : Emb F E ≃ (E →ₐ[F] K) := embEquivOfAdjoinSplits F E K (adjoin_univ F E) fun s _ ↦ ⟨Algebra.IsIntegral.isIntegral s, IsAlgClosed.splits_codomain _⟩ /-- The `Field.finSepDegree F E` is equal to the cardinality of `E →ₐ[F] K` as a natural number, when `E / F` is algebraic and `K / F` is algebraically closed. -/ @[stacks 09HJ "We use `finSepDegree` to state a more general result."] theorem finSepDegree_eq_of_isAlgClosed [Algebra.IsAlgebraic F E] [IsAlgClosed K] : finSepDegree F E = Nat.card (E →ₐ[F] K) := Nat.card_congr (embEquivOfIsAlgClosed F E K) /-- If `K / E / F` is a field extension tower, such that `K / E` is algebraic, then there is a non-canonical bijection `Field.Emb F E × Field.Emb E K ≃ Field.Emb F K`. A corollary of `algHomEquivSigma`. -/ def embProdEmbOfIsAlgebraic [Algebra E K] [IsScalarTower F E K] [Algebra.IsAlgebraic E K] : Emb F E × Emb E K ≃ Emb F K := let e : ∀ f : E →ₐ[F] AlgebraicClosure K, @AlgHom E K _ _ _ _ _ f.toRingHom.toAlgebra ≃ Emb E K := fun f ↦ (@embEquivOfIsAlgClosed E K _ _ _ _ _ f.toRingHom.toAlgebra).symm (algHomEquivSigma (A := F) (B := E) (C := K) (D := AlgebraicClosure K) |>.trans (Equiv.sigmaEquivProdOfEquiv e) |>.trans <| Equiv.prodCongrLeft <| fun _ : Emb E K ↦ AlgEquiv.arrowCongr (@AlgEquiv.refl F E _ _ _) <| (IsAlgClosure.equivOfAlgebraic E K (AlgebraicClosure K) (AlgebraicClosure E)).restrictScalars F).symm /-- If the field extension `E / F` is transcendental, then `Field.Emb F E` is infinite. -/ instance infinite_emb_of_transcendental [H : Algebra.Transcendental F E] : Infinite (Emb F E) := by obtain ⟨ι, x, hx⟩ := exists_isTranscendenceBasis' F E have := hx.isAlgebraic_field rw [← (embProdEmbOfIsAlgebraic F (adjoin F (Set.range x)) E).infinite_iff] refine @Prod.infinite_of_left _ _ ?_ _ rw [← (embEquivOfEquiv _ _ _ hx.1.aevalEquivField).infinite_iff] obtain ⟨i⟩ := hx.nonempty_iff_transcendental.2 H let K := FractionRing (MvPolynomial ι F) let i1 := IsScalarTower.toAlgHom F (MvPolynomial ι F) (AlgebraicClosure K) have hi1 : Function.Injective i1 := by rw [IsScalarTower.coe_toAlgHom', IsScalarTower.algebraMap_eq _ K] exact (algebraMap K (AlgebraicClosure K)).injective.comp (IsFractionRing.injective _ _) let f (n : ℕ) : Emb F K := IsFractionRing.liftAlgHom (g := i1.comp <| MvPolynomial.aeval fun i : ι ↦ MvPolynomial.X i ^ (n + 1)) <| hi1.comp <| by simpa [algebraicIndependent_iff_injective_aeval] using MvPolynomial.algebraicIndependent_polynomial_aeval_X _ fun i : ι ↦ (Polynomial.transcendental_X F).pow n.succ_pos refine Infinite.of_injective f fun m n h ↦ ?_ replace h : (MvPolynomial.X i) ^ (m + 1) = (MvPolynomial.X i) ^ (n + 1) := hi1 <| by simpa [f, -map_pow] using congr($h (algebraMap _ K (MvPolynomial.X (R := F) i))) simpa using congr(MvPolynomial.totalDegree $h) /-- If the field extension `E / F` is transcendental, then `Field.finSepDegree F E = 0`, which actually means that `Field.Emb F E` is infinite (see `Field.infinite_emb_of_transcendental`). -/ theorem finSepDegree_eq_zero_of_transcendental [Algebra.Transcendental F E] : finSepDegree F E = 0 := Nat.card_eq_zero_of_infinite /-- If `K / E / F` is a field extension tower, such that `K / E` is algebraic, then their separable degrees satisfy the tower law $[E:F]_s [K:E]_s = [K:F]_s$. See also `Module.finrank_mul_finrank`. -/ @[stacks 09HK "Part 1, `finSepDegree` variant"] theorem finSepDegree_mul_finSepDegree_of_isAlgebraic [Algebra E K] [IsScalarTower F E K] [Algebra.IsAlgebraic E K] : finSepDegree F E * finSepDegree E K = finSepDegree F K := by simpa only [Nat.card_prod] using Nat.card_congr (embProdEmbOfIsAlgebraic F E K) end Field namespace Polynomial variable {F E} variable (f : F[X]) open Classical in /-- The separable degree `Polynomial.natSepDegree` of a polynomial is a natural number, defined to be the number of distinct roots of it over its splitting field. This is similar to `Polynomial.natDegree` but not to `Polynomial.degree`, namely, the separable degree of `0` is `0`, not negative infinity. -/ def natSepDegree : ℕ := (f.aroots f.SplittingField).toFinset.card /-- The separable degree of a polynomial is smaller than its degree. -/ theorem natSepDegree_le_natDegree : f.natSepDegree ≤ f.natDegree := by have := f.map (algebraMap F f.SplittingField) |>.card_roots' rw [← aroots_def, natDegree_map] at this classical exact (f.aroots f.SplittingField).toFinset_card_le.trans this @[simp] theorem natSepDegree_X_sub_C (x : F) : (X - C x).natSepDegree = 1 := by simp only [natSepDegree, aroots_X_sub_C, Multiset.toFinset_singleton, Finset.card_singleton] @[simp] theorem natSepDegree_X : (X : F[X]).natSepDegree = 1 := by simp only [natSepDegree, aroots_X, Multiset.toFinset_singleton, Finset.card_singleton] /-- A constant polynomial has zero separable degree. -/ theorem natSepDegree_eq_zero (h : f.natDegree = 0) : f.natSepDegree = 0 := by linarith only [natSepDegree_le_natDegree f, h] @[simp] theorem natSepDegree_C (x : F) : (C x).natSepDegree = 0 := natSepDegree_eq_zero _ (natDegree_C _) @[simp] theorem natSepDegree_zero : (0 : F[X]).natSepDegree = 0 := by rw [← C_0, natSepDegree_C] @[simp] theorem natSepDegree_one : (1 : F[X]).natSepDegree = 0 := by rw [← C_1, natSepDegree_C] /-- A non-constant polynomial has non-zero separable degree. -/ theorem natSepDegree_ne_zero (h : f.natDegree ≠ 0) : f.natSepDegree ≠ 0 := by rw [natSepDegree, ne_eq, Finset.card_eq_zero, ← ne_eq, ← Finset.nonempty_iff_ne_empty] use rootOfSplits _ (SplittingField.splits f) (ne_of_apply_ne _ h) classical rw [Multiset.mem_toFinset, mem_aroots] exact ⟨ne_of_apply_ne _ h, map_rootOfSplits _ (SplittingField.splits f) (ne_of_apply_ne _ h)⟩ /-- A polynomial has zero separable degree if and only if it is constant. -/ theorem natSepDegree_eq_zero_iff : f.natSepDegree = 0 ↔ f.natDegree = 0 := ⟨(natSepDegree_ne_zero f).mtr, natSepDegree_eq_zero f⟩ /-- A polynomial has non-zero separable degree if and only if it is non-constant. -/ theorem natSepDegree_ne_zero_iff : f.natSepDegree ≠ 0 ↔ f.natDegree ≠ 0 := Iff.not <| natSepDegree_eq_zero_iff f /-- The separable degree of a non-zero polynomial is equal to its degree if and only if it is separable. -/ theorem natSepDegree_eq_natDegree_iff (hf : f ≠ 0) : f.natSepDegree = f.natDegree ↔ f.Separable := by classical simp_rw [← card_rootSet_eq_natDegree_iff_of_splits hf (SplittingField.splits f), rootSet_def, Finset.coe_sort_coe, Fintype.card_coe] rfl /-- If a polynomial is separable, then its separable degree is equal to its degree. -/ theorem natSepDegree_eq_natDegree_of_separable (h : f.Separable) : f.natSepDegree = f.natDegree := (natSepDegree_eq_natDegree_iff f h.ne_zero).2 h variable {f} in /-- Same as `Polynomial.natSepDegree_eq_natDegree_of_separable`, but enables the use of dot notation. -/ theorem Separable.natSepDegree_eq_natDegree (h : f.Separable) : f.natSepDegree = f.natDegree := natSepDegree_eq_natDegree_of_separable f h /-- If a polynomial splits over `E`, then its separable degree is equal to the number of distinct roots of it over `E`. -/ theorem natSepDegree_eq_of_splits [DecidableEq E] (h : f.Splits (algebraMap F E)) : f.natSepDegree = (f.aroots E).toFinset.card := by classical rw [aroots, ← (SplittingField.lift f h).comp_algebraMap, ← map_map, roots_map _ ((splits_id_iff_splits _).mpr <| SplittingField.splits f), Multiset.toFinset_map, Finset.card_image_of_injective _ (RingHom.injective _), natSepDegree] variable (E) in /-- The separable degree of a polynomial is equal to the number of distinct roots of it over any algebraically closed field. -/ theorem natSepDegree_eq_of_isAlgClosed [DecidableEq E] [IsAlgClosed E] : f.natSepDegree = (f.aroots E).toFinset.card := natSepDegree_eq_of_splits f (IsAlgClosed.splits_codomain f) theorem natSepDegree_map (f : E[X]) (i : E →+* K) : (f.map i).natSepDegree = f.natSepDegree := by classical let _ := i.toAlgebra simp_rw [show i = algebraMap E K by rfl, natSepDegree_eq_of_isAlgClosed (AlgebraicClosure K), aroots_def, map_map, ← IsScalarTower.algebraMap_eq] @[simp] theorem natSepDegree_C_mul {x : F} (hx : x ≠ 0) : (C x * f).natSepDegree = f.natSepDegree := by classical simp only [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_C_mul _ hx] @[simp] theorem natSepDegree_smul_nonzero {x : F} (hx : x ≠ 0) : (x • f).natSepDegree = f.natSepDegree := by classical simp only [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_smul_nonzero _ hx] @[simp] theorem natSepDegree_pow {n : ℕ} : (f ^ n).natSepDegree = if n = 0 then 0 else f.natSepDegree := by classical simp only [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_pow] by_cases h : n = 0 · simp only [h, zero_smul, Multiset.toFinset_zero, Finset.card_empty, ite_true] simp only [h, Multiset.toFinset_nsmul _ n h, ite_false] theorem natSepDegree_pow_of_ne_zero {n : ℕ} (hn : n ≠ 0) : (f ^ n).natSepDegree = f.natSepDegree := by simp_rw [natSepDegree_pow, hn, ite_false] theorem natSepDegree_X_pow {n : ℕ} : (X ^ n : F[X]).natSepDegree = if n = 0 then 0 else 1 := by simp only [natSepDegree_pow, natSepDegree_X] theorem natSepDegree_X_sub_C_pow {x : F} {n : ℕ} : ((X - C x) ^ n).natSepDegree = if n = 0 then 0 else 1 := by simp only [natSepDegree_pow, natSepDegree_X_sub_C] theorem natSepDegree_C_mul_X_sub_C_pow {x y : F} {n : ℕ} (hx : x ≠ 0) : (C x * (X - C y) ^ n).natSepDegree = if n = 0 then 0 else 1 := by simp only [natSepDegree_C_mul _ hx, natSepDegree_X_sub_C_pow] theorem natSepDegree_mul (g : F[X]) : (f * g).natSepDegree ≤ f.natSepDegree + g.natSepDegree := by by_cases h : f * g = 0 · simp only [h, natSepDegree_zero, zero_le] classical simp_rw [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_mul h, Multiset.toFinset_add] exact Finset.card_union_le _ _ theorem natSepDegree_mul_eq_iff (g : F[X]) : (f * g).natSepDegree = f.natSepDegree + g.natSepDegree ↔ (f = 0 ∧ g = 0) ∨ IsCoprime f g := by by_cases h : f * g = 0 · rw [mul_eq_zero] at h wlog hf : f = 0 generalizing f g · simpa only [mul_comm, add_comm, and_comm, isCoprime_comm] using this g f h.symm (h.resolve_left hf) rw [hf, zero_mul, natSepDegree_zero, zero_add, isCoprime_zero_left, isUnit_iff, eq_comm, natSepDegree_eq_zero_iff, natDegree_eq_zero] refine ⟨fun ⟨x, h⟩ ↦ ?_, ?_⟩ · by_cases hx : x = 0 · exact .inl ⟨rfl, by rw [← h, hx, map_zero]⟩ exact .inr ⟨x, Ne.isUnit hx, h⟩ rintro (⟨-, h⟩ | ⟨x, -, h⟩) · exact ⟨0, by rw [h, map_zero]⟩ exact ⟨x, h⟩ classical simp_rw [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_mul h, Multiset.toFinset_add, Finset.card_union_eq_card_add_card, Finset.disjoint_iff_ne, Multiset.mem_toFinset, mem_aroots] rw [mul_eq_zero, not_or] at h refine ⟨fun H ↦ .inr (isCoprime_of_irreducible_dvd (not_and.2 fun _ ↦ h.2) fun u hu ⟨v, hf⟩ ⟨w, hg⟩ ↦ ?_), ?_⟩ · obtain ⟨x, hx⟩ := IsAlgClosed.exists_aeval_eq_zero (AlgebraicClosure F) _ (degree_pos_of_irreducible hu).ne' exact H x ⟨h.1, by simpa only [map_mul, hx, zero_mul] using congr(aeval x $hf)⟩ x ⟨h.2, by simpa only [map_mul, hx, zero_mul] using congr(aeval x $hg)⟩ rfl rintro (⟨rfl, rfl⟩ | hc) · exact (h.1 rfl).elim rintro x hf _ hg rfl obtain ⟨u, v, hfg⟩ := hc simpa only [map_add, map_mul, map_one, hf.2, hg.2, mul_zero, add_zero, zero_ne_one] using congr(aeval x $hfg) theorem natSepDegree_mul_of_isCoprime (g : F[X]) (hc : IsCoprime f g) : (f * g).natSepDegree = f.natSepDegree + g.natSepDegree := (natSepDegree_mul_eq_iff f g).2 (.inr hc) theorem natSepDegree_le_of_dvd (g : F[X]) (h1 : f ∣ g) (h2 : g ≠ 0) : f.natSepDegree ≤ g.natSepDegree := by classical simp_rw [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F)] exact Finset.card_le_card <| Multiset.toFinset_subset.mpr <| Multiset.Le.subset <| roots.le_of_dvd (map_ne_zero h2) <| map_dvd _ h1 /-- If a field `F` is of exponential characteristic `q`, then `Polynomial.expand F (q ^ n) f` and `f` have the same separable degree. -/ theorem natSepDegree_expand (q : ℕ) [hF : ExpChar F q] {n : ℕ} : (expand F (q ^ n) f).natSepDegree = f.natSepDegree := by obtain - | hprime := hF · simp only [one_pow, expand_one] haveI := Fact.mk hprime classical simpa only [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_def, map_expand, Fintype.card_coe] using Fintype.card_eq.2 ⟨(f.map (algebraMap F (AlgebraicClosure F))).rootsExpandPowEquivRoots q n⟩ theorem natSepDegree_X_pow_char_pow_sub_C (q : ℕ) [ExpChar F q] (n : ℕ) (y : F) : (X ^ q ^ n - C y).natSepDegree = 1 := by rw [← expand_X, ← expand_C (q ^ n), ← map_sub, natSepDegree_expand, natSepDegree_X_sub_C] variable {f} in /-- If `g` is a separable contraction of `f`, then the separable degree of `f` is equal to the degree of `g`. -/ theorem IsSeparableContraction.natSepDegree_eq {g : Polynomial F} {q : ℕ} [ExpChar F q] (h : IsSeparableContraction q f g) : f.natSepDegree = g.natDegree := by
obtain ⟨h1, m, h2⟩ := h rw [← h2, natSepDegree_expand, h1.natSepDegree_eq_natDegree]
Mathlib/FieldTheory/SeparableDegree.lean
493
495
/- 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 unfold derivWithin deriv rw [fderivWithin_univ] theorem derivWithin_inter (ht : t ∈ 𝓝 x) : derivWithin f (s ∩ t) x = derivWithin f s x := by unfold derivWithin rw [fderivWithin_inter ht] theorem derivWithin_of_mem_nhds (h : s ∈ 𝓝 x) : derivWithin f s x = deriv f x := by simp only [derivWithin, deriv, fderivWithin_of_mem_nhds h] theorem derivWithin_of_isOpen (hs : IsOpen s) (hx : x ∈ s) : derivWithin f s x = deriv f x := derivWithin_of_mem_nhds (hs.mem_nhds hx) lemma deriv_eqOn {f' : 𝕜 → F} (hs : IsOpen s) (hf' : ∀ x ∈ s, HasDerivWithinAt f (f' x) s x) : s.EqOn (deriv f) f' := fun x hx ↦ by rw [← derivWithin_of_isOpen hs hx, (hf' _ hx).derivWithin <| hs.uniqueDiffWithinAt hx] theorem deriv_mem_iff {f : 𝕜 → F} {s : Set F} {x : 𝕜} : deriv f x ∈ s ↔ DifferentiableAt 𝕜 f x ∧ deriv f x ∈ s ∨ ¬DifferentiableAt 𝕜 f x ∧ (0 : F) ∈ s := by by_cases hx : DifferentiableAt 𝕜 f x <;> simp [deriv_zero_of_not_differentiableAt, *] theorem derivWithin_mem_iff {f : 𝕜 → F} {t : Set 𝕜} {s : Set F} {x : 𝕜} : derivWithin f t x ∈ s ↔ DifferentiableWithinAt 𝕜 f t x ∧ derivWithin f t x ∈ s ∨ ¬DifferentiableWithinAt 𝕜 f t x ∧ (0 : F) ∈ s := by by_cases hx : DifferentiableWithinAt 𝕜 f t x <;> simp [derivWithin_zero_of_not_differentiableWithinAt, *] theorem differentiableWithinAt_Ioi_iff_Ici [PartialOrder 𝕜] : DifferentiableWithinAt 𝕜 f (Ioi x) x ↔ DifferentiableWithinAt 𝕜 f (Ici x) x := ⟨fun h => h.hasDerivWithinAt.Ici_of_Ioi.differentiableWithinAt, fun h => h.hasDerivWithinAt.Ioi_of_Ici.differentiableWithinAt⟩ -- Golfed while splitting the file theorem derivWithin_Ioi_eq_Ici {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] (f : ℝ → E) (x : ℝ) : derivWithin f (Ioi x) x = derivWithin f (Ici x) x := by by_cases H : DifferentiableWithinAt ℝ f (Ioi x) x · have A := H.hasDerivWithinAt.Ici_of_Ioi have B := (differentiableWithinAt_Ioi_iff_Ici.1 H).hasDerivWithinAt simpa using (uniqueDiffOn_Ici x).eq left_mem_Ici A B · rw [derivWithin_zero_of_not_differentiableWithinAt H, derivWithin_zero_of_not_differentiableWithinAt] rwa [differentiableWithinAt_Ioi_iff_Ici] at H section congr /-! ### Congruence properties of derivatives -/ theorem Filter.EventuallyEq.hasDerivAtFilter_iff (h₀ : f₀ =ᶠ[L] f₁) (hx : f₀ x = f₁ x) (h₁ : f₀' = f₁') : HasDerivAtFilter f₀ f₀' x L ↔ HasDerivAtFilter f₁ f₁' x L := h₀.hasFDerivAtFilter_iff hx (by simp [h₁]) theorem HasDerivAtFilter.congr_of_eventuallyEq (h : HasDerivAtFilter f f' x L) (hL : f₁ =ᶠ[L] f) (hx : f₁ x = f x) : HasDerivAtFilter f₁ f' x L := by rwa [hL.hasDerivAtFilter_iff hx rfl] theorem HasDerivWithinAt.congr_mono (h : HasDerivWithinAt f f' s x) (ht : ∀ x ∈ t, f₁ x = f x) (hx : f₁ x = f x) (h₁ : t ⊆ s) : HasDerivWithinAt f₁ f' t x := HasFDerivWithinAt.congr_mono h ht hx h₁ theorem HasDerivWithinAt.congr (h : HasDerivWithinAt f f' s x) (hs : ∀ x ∈ s, f₁ x = f x) (hx : f₁ x = f x) : HasDerivWithinAt f₁ f' s x := h.congr_mono hs hx (Subset.refl _) theorem HasDerivWithinAt.congr_of_mem (h : HasDerivWithinAt f f' s x) (hs : ∀ x ∈ s, f₁ x = f x) (hx : x ∈ s) : HasDerivWithinAt f₁ f' s x := h.congr hs (hs _ hx) theorem HasDerivWithinAt.congr_of_eventuallyEq (h : HasDerivWithinAt f f' s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : HasDerivWithinAt f₁ f' s x := HasDerivAtFilter.congr_of_eventuallyEq h h₁ hx theorem Filter.EventuallyEq.hasDerivWithinAt_iff (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : HasDerivWithinAt f₁ f' s x ↔ HasDerivWithinAt f f' s x := ⟨fun h' ↦ h'.congr_of_eventuallyEq h₁.symm hx.symm, fun h' ↦ h'.congr_of_eventuallyEq h₁ hx⟩ theorem HasDerivWithinAt.congr_of_eventuallyEq_of_mem (h : HasDerivWithinAt f f' s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s) : HasDerivWithinAt f₁ f' s x := h.congr_of_eventuallyEq h₁ (h₁.eq_of_nhdsWithin hx) theorem Filter.EventuallyEq.hasDerivWithinAt_iff_of_mem (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s) : HasDerivWithinAt f₁ f' s x ↔ HasDerivWithinAt f f' s x := ⟨fun h' ↦ h'.congr_of_eventuallyEq_of_mem h₁.symm hx, fun h' ↦ h'.congr_of_eventuallyEq_of_mem h₁ hx⟩
theorem HasStrictDerivAt.congr_deriv (h : HasStrictDerivAt f f' x) (h' : f' = g') : HasStrictDerivAt f g' x := h.congr_fderiv <| congr_arg _ h' theorem HasDerivAt.congr_deriv (h : HasDerivAt f f' x) (h' : f' = g') : HasDerivAt f g' x := HasFDerivAt.congr_fderiv h <| congr_arg _ h' theorem HasDerivWithinAt.congr_deriv (h : HasDerivWithinAt f f' s x) (h' : f' = g') : HasDerivWithinAt f g' s x :=
Mathlib/Analysis/Calculus/Deriv/Basic.lean
561
569
/- Copyright (c) 2024 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ import Mathlib.Analysis.Complex.CauchyIntegral /-! # Convergence of Taylor series of holomorphic functions We show that the Taylor series around some point `c : ℂ` of a function `f` that is complex differentiable on the open ball of radius `r` around `c` converges to `f` on that open ball; see `Complex.hasSum_taylorSeries_on_ball` and `Complex.taylorSeries_eq_on_ball` for versions (in terms of `HasSum` and `tsum`, respectively) for functions to a complete normed space over `ℂ`, and `Complex.taylorSeries_eq_on_ball'` for a variant when `f : ℂ → ℂ`. There are corresponding statements for `EMEtric.ball`s; see `Complex.hasSum_taylorSeries_on_emetric_ball`, `Complex.taylorSeries_eq_on_emetric_ball` and `Complex.taylorSeries_eq_on_ball'`. We also show that the Taylor series around some point `c : ℂ` of a function `f` that is complex differentiable on all of `ℂ` converges to `f` on `ℂ`; see `Complex.hasSum_taylorSeries_of_entire`, `Complex.taylorSeries_eq_of_entire` and `Complex.taylorSeries_eq_of_entire'`. -/ #adaptation_note /-- https://github.com/leanprover/lean4/issues/5126 we've had to change all the `⦃⦄` stricit implicit variable statements in this file to normal `{}` implicit variables. Once this issue is fixed, we should change them back. For now it doesn't break anything downstream. -/ namespace Complex open Nat variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] [CompleteSpace E] {f : ℂ → E} section ball variable {c : ℂ} {r : ℝ} (hf : DifferentiableOn ℂ f (Metric.ball c r)) variable {z : ℂ} (hz : z ∈ Metric.ball c r) include hf hz in /-- A function that is complex differentiable on the open ball of radius `r` around `c` is given by evaluating its Taylor series at `c` on this open ball. -/ lemma hasSum_taylorSeries_on_ball : HasSum (fun n : ℕ ↦ (n ! : ℂ)⁻¹ • (z - c) ^ n • iteratedDeriv n f c) (f z) := by obtain ⟨r', hr', hr'₀, hzr'⟩ : ∃ r' < r, 0 < r' ∧ z ∈ Metric.ball c r' := by obtain ⟨r', h₁, h₂⟩ := exists_between (Metric.mem_ball'.mp hz) exact ⟨r', h₂, Metric.pos_of_mem_ball h₁, Metric.mem_ball'.mpr h₁⟩ lift r' to NNReal using hr'₀.le have hz' : z - c ∈ EMetric.ball 0 r' := by rw [Metric.emetric_ball_nnreal] exact mem_ball_zero_iff.mpr hzr' have H := (hf.mono <| Metric.closedBall_subset_ball hr').hasFPowerSeriesOnBall hr'₀ |>.hasSum_iteratedFDeriv hz' simp only [add_sub_cancel] at H convert H using 4 with n simpa only [iteratedDeriv_eq_iteratedFDeriv, smul_eq_mul, mul_one, Finset.prod_const, Finset.card_fin] using ((iteratedFDeriv ℂ n f c).map_smul_univ (fun _ ↦ z - c) (fun _ ↦ 1)).symm include hf hz in /-- A function that is complex differentiable on the open ball of radius `r` around `c` is given by evaluating its Taylor series at `c` on this open ball. -/ lemma taylorSeries_eq_on_ball : ∑' n : ℕ, (n ! : ℂ)⁻¹ • (z - c) ^ n • iteratedDeriv n f c = f z := (hasSum_taylorSeries_on_ball hf hz).tsum_eq include hz in /-- A function that is complex differentiable on the open ball of radius `r` around `c` is given by evaluating its Taylor series at `c` on this open ball. -/ lemma taylorSeries_eq_on_ball' {f : ℂ → ℂ} (hf : DifferentiableOn ℂ f (Metric.ball c r)) : ∑' n : ℕ, (n ! : ℂ)⁻¹ * iteratedDeriv n f c * (z - c) ^ n = f z := by convert taylorSeries_eq_on_ball hf hz using 3 with n rw [mul_right_comm, smul_eq_mul, smul_eq_mul, mul_assoc] end ball section emetric variable {c : ℂ} {r : ENNReal} (hf : DifferentiableOn ℂ f (EMetric.ball c r)) variable {z : ℂ} (hz : z ∈ EMetric.ball c r) include hf hz in /-- A function that is complex differentiable on the open ball of radius `r ≤ ∞` around `c` is given by evaluating its Taylor series at `c` on this open ball. -/ lemma hasSum_taylorSeries_on_emetric_ball : HasSum (fun n : ℕ ↦ (n ! : ℂ)⁻¹ • (z - c) ^ n • iteratedDeriv n f c) (f z) := by obtain ⟨r', hzr', hr'⟩ := exists_between (EMetric.mem_ball'.mp hz) lift r' to NNReal using ne_top_of_lt hr'
rw [← EMetric.mem_ball', Metric.emetric_ball_nnreal] at hzr' refine hasSum_taylorSeries_on_ball ?_ hzr' rw [← Metric.emetric_ball_nnreal] exact hf.mono <| EMetric.ball_subset_ball hr'.le include hf hz in
Mathlib/Analysis/Complex/TaylorSeries.lean
94
99
/- 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
Mathlib/Algebra/Order/Field/Basic.lean
158
162
/- Copyright (c) 2023 Jz Pan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jz Pan -/ import Mathlib.FieldTheory.SplittingField.Construction import Mathlib.FieldTheory.IsAlgClosed.AlgebraicClosure import Mathlib.FieldTheory.Separable import Mathlib.FieldTheory.Normal.Closure import Mathlib.RingTheory.AlgebraicIndependent.Adjoin import Mathlib.RingTheory.AlgebraicIndependent.TranscendenceBasis import Mathlib.RingTheory.Polynomial.SeparableDegree import Mathlib.RingTheory.Polynomial.UniqueFactorization /-! # Separable degree This file contains basics about the separable degree of a field extension. ## Main definitions - `Field.Emb F E`: the type of `F`-algebra homomorphisms from `E` to the algebraic closure of `E` (the algebraic closure of `F` is usually used in the literature, but our definition has the advantage that `Field.Emb F E` lies in the same universe as `E` rather than the maximum over `F` and `E`). Usually denoted by $\operatorname{Emb}_F(E)$ in textbooks. - `Field.finSepDegree F E`: the (finite) separable degree $[E:F]_s$ of an extension `E / F` of fields, defined to be the number of `F`-algebra homomorphisms from `E` to the algebraic closure of `E`, as a natural number. It is zero if `Field.Emb F E` is not finite. Note that if `E / F` is not algebraic, then this definition makes no mathematical sense. **Remark:** the `Cardinal`-valued, potentially infinite separable degree `Field.sepDegree F E` for a general algebraic extension `E / F` is defined to be the degree of `L / F`, where `L` is the separable closure of `F` in `E`, which is not defined in this file yet. Later we will show that (`Field.finSepDegree_eq`), if `Field.Emb F E` is finite, then these two definitions coincide. If `E / F` is algebraic with infinite separable degree, we have `#(Field.Emb F E) = 2 ^ Field.sepDegree F E` instead. (See `Field.Emb.cardinal_eq_two_pow_sepDegree` in another file.) For example, if $F = \mathbb{Q}$ and $E = \mathbb{Q}( \mu_{p^\infty} )$, then $\operatorname{Emb}_F (E)$ is in bijection with $\operatorname{Gal}(E/F)$, which is isomorphic to $\mathbb{Z}_p^\times$, which is uncountable, whereas $ [E:F] $ is countable. - `Polynomial.natSepDegree`: the separable degree of a polynomial is a natural number, defined to be the number of distinct roots of it over its splitting field. ## Main results - `Field.embEquivOfEquiv`, `Field.finSepDegree_eq_of_equiv`: a random bijection between `Field.Emb F E` and `Field.Emb F K` when `E` and `K` are isomorphic as `F`-algebras. In particular, they have the same cardinality (so their `Field.finSepDegree` are equal). - `Field.embEquivOfAdjoinSplits`, `Field.finSepDegree_eq_of_adjoin_splits`: a random bijection between `Field.Emb F E` and `E →ₐ[F] K` if `E = F(S)` such that every element `s` of `S` is integral (= algebraic) over `F` and whose minimal polynomial splits in `K`. In particular, they have the same cardinality. - `Field.embEquivOfIsAlgClosed`, `Field.finSepDegree_eq_of_isAlgClosed`: a random bijection between `Field.Emb F E` and `E →ₐ[F] K` when `E / F` is algebraic and `K / F` is algebraically closed. In particular, they have the same cardinality. - `Field.embProdEmbOfIsAlgebraic`, `Field.finSepDegree_mul_finSepDegree_of_isAlgebraic`: if `K / E / F` is a field extension tower, such that `K / E` is algebraic, then there is a non-canonical bijection `Field.Emb F E × Field.Emb E K ≃ Field.Emb F K`. In particular, the separable degrees satisfy the tower law: $[E:F]_s [K:E]_s = [K:F]_s$ (see also `Module.finrank_mul_finrank`). - `Field.infinite_emb_of_transcendental`: `Field.Emb` is infinite for transcendental extensions. - `Polynomial.natSepDegree_le_natDegree`: the separable degree of a polynomial is smaller than its degree. - `Polynomial.natSepDegree_eq_natDegree_iff`: the separable degree of a non-zero polynomial is equal to its degree if and only if it is separable. - `Polynomial.natSepDegree_eq_of_splits`: if a polynomial splits over `E`, then its separable degree is equal to the number of distinct roots of it over `E`. - `Polynomial.natSepDegree_eq_of_isAlgClosed`: the separable degree of a polynomial is equal to the number of distinct roots of it over any algebraically closed field. - `Polynomial.natSepDegree_expand`: if a field `F` is of exponential characteristic `q`, then `Polynomial.expand F (q ^ n) f` and `f` have the same separable degree. - `Polynomial.HasSeparableContraction.natSepDegree_eq`: if a polynomial has separable contraction, then its separable degree is equal to its separable contraction degree. - `Irreducible.natSepDegree_dvd_natDegree`: the separable degree of an irreducible polynomial divides its degree. - `IntermediateField.finSepDegree_adjoin_simple_eq_natSepDegree`: the separable degree of `F⟮α⟯ / F` is equal to the separable degree of the minimal polynomial of `α` over `F`. - `IntermediateField.finSepDegree_adjoin_simple_eq_finrank_iff`: if `α` is algebraic over `F`, then the separable degree of `F⟮α⟯ / F` is equal to the degree of `F⟮α⟯ / F` if and only if `α` is a separable element. - `Field.finSepDegree_dvd_finrank`: the separable degree of any field extension `E / F` divides the degree of `E / F`. - `Field.finSepDegree_le_finrank`: the separable degree of a finite extension `E / F` is smaller than the degree of `E / F`. - `Field.finSepDegree_eq_finrank_iff`: if `E / F` is a finite extension, then its separable degree is equal to its degree if and only if it is a separable extension. - `IntermediateField.isSeparable_adjoin_simple_iff_isSeparable`: `F⟮x⟯ / F` is a separable extension if and only if `x` is a separable element. - `Algebra.IsSeparable.trans`: if `E / F` and `K / E` are both separable, then `K / F` is also separable. ## Tags separable degree, degree, polynomial -/ open Module Polynomial IntermediateField Field noncomputable section universe u v w variable (F : Type u) (E : Type v) [Field F] [Field E] [Algebra F E] variable (K : Type w) [Field K] [Algebra F K] namespace Field /-- `Field.Emb F E` is the type of `F`-algebra homomorphisms from `E` to the algebraic closure of `E`. -/ abbrev Emb := E →ₐ[F] AlgebraicClosure E /-- If `E / F` is an algebraic extension, then the (finite) separable degree of `E / F` is the number of `F`-algebra homomorphisms from `E` to the algebraic closure of `E`, as a natural number. It is defined to be zero if there are infinitely many of them. Note that if `E / F` is not algebraic, then this definition makes no mathematical sense. -/ def finSepDegree : ℕ := Nat.card (Emb F E) instance instInhabitedEmb : Inhabited (Emb F E) := ⟨IsScalarTower.toAlgHom F E _⟩ instance instNeZeroFinSepDegree [FiniteDimensional F E] : NeZero (finSepDegree F E) := ⟨Nat.card_ne_zero.2 ⟨inferInstance, Fintype.finite <| minpoly.AlgHom.fintype _ _ _⟩⟩ /-- A random bijection between `Field.Emb F E` and `Field.Emb F K` when `E` and `K` are isomorphic as `F`-algebras. -/ def embEquivOfEquiv (i : E ≃ₐ[F] K) : Emb F E ≃ Emb F K := AlgEquiv.arrowCongr i <| AlgEquiv.symm <| by let _ : Algebra E K := i.toAlgHom.toRingHom.toAlgebra have : Algebra.IsAlgebraic E K := by constructor intro x have h := isAlgebraic_algebraMap (R := E) (A := K) (i.symm.toAlgHom x) rw [show ∀ y : E, (algebraMap E K) y = i.toAlgHom y from fun y ↦ rfl] at h simpa only [AlgEquiv.toAlgHom_eq_coe, AlgHom.coe_coe, AlgEquiv.apply_symm_apply] using h apply AlgEquiv.restrictScalars (R := F) (S := E) exact IsAlgClosure.equivOfAlgebraic E K (AlgebraicClosure K) (AlgebraicClosure E) /-- If `E` and `K` are isomorphic as `F`-algebras, then they have the same `Field.finSepDegree` over `F`. -/ theorem finSepDegree_eq_of_equiv (i : E ≃ₐ[F] K) : finSepDegree F E = finSepDegree F K := Nat.card_congr (embEquivOfEquiv F E K i) @[simp] theorem finSepDegree_self : finSepDegree F F = 1 := by have : Cardinal.mk (Emb F F) = 1 := le_antisymm (Cardinal.le_one_iff_subsingleton.2 AlgHom.subsingleton) (Cardinal.one_le_iff_ne_zero.2 <| Cardinal.mk_ne_zero _) rw [finSepDegree, Nat.card, this, Cardinal.one_toNat] end Field namespace IntermediateField @[simp] theorem finSepDegree_bot : finSepDegree F (⊥ : IntermediateField F E) = 1 := by rw [finSepDegree_eq_of_equiv _ _ _ (botEquiv F E), finSepDegree_self] section Tower variable {F} variable [Algebra E K] [IsScalarTower F E K] @[simp] theorem finSepDegree_bot' : finSepDegree F (⊥ : IntermediateField E K) = finSepDegree F E := finSepDegree_eq_of_equiv _ _ _ ((botEquiv E K).restrictScalars F) @[simp] theorem finSepDegree_top : finSepDegree F (⊤ : IntermediateField E K) = finSepDegree F K := finSepDegree_eq_of_equiv _ _ _ ((topEquiv (F := E) (E := K)).restrictScalars F) end Tower end IntermediateField namespace Field /-- A random bijection between `Field.Emb F E` and `E →ₐ[F] K` if `E = F(S)` such that every element `s` of `S` is integral (= algebraic) over `F` and whose minimal polynomial splits in `K`. Combined with `Field.instInhabitedEmb`, it can be viewed as a stronger version of `IntermediateField.nonempty_algHom_of_adjoin_splits`. -/ def embEquivOfAdjoinSplits {S : Set E} (hS : adjoin F S = ⊤) (hK : ∀ s ∈ S, IsIntegral F s ∧ Splits (algebraMap F K) (minpoly F s)) : Emb F E ≃ (E →ₐ[F] K) := have : Algebra.IsAlgebraic F (⊤ : IntermediateField F E) := (hS ▸ isAlgebraic_adjoin (S := S) fun x hx ↦ (hK x hx).1) have halg := (topEquiv (F := F) (E := E)).isAlgebraic Classical.choice <| Function.Embedding.antisymm (halg.algHomEmbeddingOfSplits (fun _ ↦ splits_of_mem_adjoin F E (S := S) hK (hS ▸ mem_top)) _) (halg.algHomEmbeddingOfSplits (fun _ ↦ IsAlgClosed.splits_codomain _) _) /-- The `Field.finSepDegree F E` is equal to the cardinality of `E →ₐ[F] K` if `E = F(S)` such that every element `s` of `S` is integral (= algebraic) over `F` and whose minimal polynomial splits in `K`. -/ theorem finSepDegree_eq_of_adjoin_splits {S : Set E} (hS : adjoin F S = ⊤) (hK : ∀ s ∈ S, IsIntegral F s ∧ Splits (algebraMap F K) (minpoly F s)) : finSepDegree F E = Nat.card (E →ₐ[F] K) := Nat.card_congr (embEquivOfAdjoinSplits F E K hS hK) /-- A random bijection between `Field.Emb F E` and `E →ₐ[F] K` when `E / F` is algebraic and `K / F` is algebraically closed. -/ def embEquivOfIsAlgClosed [Algebra.IsAlgebraic F E] [IsAlgClosed K] : Emb F E ≃ (E →ₐ[F] K) := embEquivOfAdjoinSplits F E K (adjoin_univ F E) fun s _ ↦ ⟨Algebra.IsIntegral.isIntegral s, IsAlgClosed.splits_codomain _⟩ /-- The `Field.finSepDegree F E` is equal to the cardinality of `E →ₐ[F] K` as a natural number, when `E / F` is algebraic and `K / F` is algebraically closed. -/ @[stacks 09HJ "We use `finSepDegree` to state a more general result."] theorem finSepDegree_eq_of_isAlgClosed [Algebra.IsAlgebraic F E] [IsAlgClosed K] : finSepDegree F E = Nat.card (E →ₐ[F] K) := Nat.card_congr (embEquivOfIsAlgClosed F E K) /-- If `K / E / F` is a field extension tower, such that `K / E` is algebraic, then there is a non-canonical bijection `Field.Emb F E × Field.Emb E K ≃ Field.Emb F K`. A corollary of `algHomEquivSigma`. -/ def embProdEmbOfIsAlgebraic [Algebra E K] [IsScalarTower F E K] [Algebra.IsAlgebraic E K] : Emb F E × Emb E K ≃ Emb F K := let e : ∀ f : E →ₐ[F] AlgebraicClosure K, @AlgHom E K _ _ _ _ _ f.toRingHom.toAlgebra ≃ Emb E K := fun f ↦ (@embEquivOfIsAlgClosed E K _ _ _ _ _ f.toRingHom.toAlgebra).symm (algHomEquivSigma (A := F) (B := E) (C := K) (D := AlgebraicClosure K) |>.trans (Equiv.sigmaEquivProdOfEquiv e) |>.trans <| Equiv.prodCongrLeft <| fun _ : Emb E K ↦ AlgEquiv.arrowCongr (@AlgEquiv.refl F E _ _ _) <| (IsAlgClosure.equivOfAlgebraic E K (AlgebraicClosure K) (AlgebraicClosure E)).restrictScalars F).symm /-- If the field extension `E / F` is transcendental, then `Field.Emb F E` is infinite. -/ instance infinite_emb_of_transcendental [H : Algebra.Transcendental F E] : Infinite (Emb F E) := by obtain ⟨ι, x, hx⟩ := exists_isTranscendenceBasis' F E have := hx.isAlgebraic_field rw [← (embProdEmbOfIsAlgebraic F (adjoin F (Set.range x)) E).infinite_iff] refine @Prod.infinite_of_left _ _ ?_ _ rw [← (embEquivOfEquiv _ _ _ hx.1.aevalEquivField).infinite_iff] obtain ⟨i⟩ := hx.nonempty_iff_transcendental.2 H let K := FractionRing (MvPolynomial ι F) let i1 := IsScalarTower.toAlgHom F (MvPolynomial ι F) (AlgebraicClosure K) have hi1 : Function.Injective i1 := by rw [IsScalarTower.coe_toAlgHom', IsScalarTower.algebraMap_eq _ K] exact (algebraMap K (AlgebraicClosure K)).injective.comp (IsFractionRing.injective _ _) let f (n : ℕ) : Emb F K := IsFractionRing.liftAlgHom (g := i1.comp <| MvPolynomial.aeval fun i : ι ↦ MvPolynomial.X i ^ (n + 1)) <| hi1.comp <| by simpa [algebraicIndependent_iff_injective_aeval] using MvPolynomial.algebraicIndependent_polynomial_aeval_X _ fun i : ι ↦ (Polynomial.transcendental_X F).pow n.succ_pos refine Infinite.of_injective f fun m n h ↦ ?_ replace h : (MvPolynomial.X i) ^ (m + 1) = (MvPolynomial.X i) ^ (n + 1) := hi1 <| by simpa [f, -map_pow] using congr($h (algebraMap _ K (MvPolynomial.X (R := F) i))) simpa using congr(MvPolynomial.totalDegree $h) /-- If the field extension `E / F` is transcendental, then `Field.finSepDegree F E = 0`, which actually means that `Field.Emb F E` is infinite (see `Field.infinite_emb_of_transcendental`). -/ theorem finSepDegree_eq_zero_of_transcendental [Algebra.Transcendental F E] : finSepDegree F E = 0 := Nat.card_eq_zero_of_infinite /-- If `K / E / F` is a field extension tower, such that `K / E` is algebraic, then their separable degrees satisfy the tower law $[E:F]_s [K:E]_s = [K:F]_s$. See also `Module.finrank_mul_finrank`. -/ @[stacks 09HK "Part 1, `finSepDegree` variant"] theorem finSepDegree_mul_finSepDegree_of_isAlgebraic [Algebra E K] [IsScalarTower F E K] [Algebra.IsAlgebraic E K] : finSepDegree F E * finSepDegree E K = finSepDegree F K := by simpa only [Nat.card_prod] using Nat.card_congr (embProdEmbOfIsAlgebraic F E K)
end Field
Mathlib/FieldTheory/SeparableDegree.lean
284
285
/- Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Robert Y. Lewis, Johannes Hölzl, Mario Carneiro, Sébastien Gouëzel -/ import Mathlib.Topology.Bornology.Constructions import Mathlib.Topology.MetricSpace.Pseudo.Defs import Mathlib.Topology.UniformSpace.UniformEmbedding /-! # Products of pseudometric spaces and other constructions This file constructs the supremum distance on binary products of pseudometric spaces and provides instances for type synonyms. -/ open Bornology Filter Metric Set Topology open scoped NNReal variable {α β : Type*} [PseudoMetricSpace α] /-- Pseudometric space structure pulled back by a function. -/ abbrev PseudoMetricSpace.induced {α β} (f : α → β) (m : PseudoMetricSpace β) : PseudoMetricSpace α where dist x y := dist (f x) (f y) dist_self _ := dist_self _ dist_comm _ _ := dist_comm _ _ dist_triangle _ _ _ := dist_triangle _ _ _ edist x y := edist (f x) (f y) edist_dist _ _ := edist_dist _ _ toUniformSpace := UniformSpace.comap f m.toUniformSpace uniformity_dist := (uniformity_basis_dist.comap _).eq_biInf toBornology := Bornology.induced f cobounded_sets := Set.ext fun s => mem_comap_iff_compl.trans <| by simp only [← isBounded_def, isBounded_iff, forall_mem_image, mem_setOf] /-- Pull back a pseudometric space structure by an inducing map. This is a version of `PseudoMetricSpace.induced` useful in case if the domain already has a `TopologicalSpace` structure. -/ def Topology.IsInducing.comapPseudoMetricSpace {α β : Type*} [TopologicalSpace α] [m : PseudoMetricSpace β] {f : α → β} (hf : IsInducing f) : PseudoMetricSpace α := .replaceTopology (.induced f m) hf.eq_induced @[deprecated (since := "2024-10-28")] alias Inducing.comapPseudoMetricSpace := IsInducing.comapPseudoMetricSpace /-- Pull back a pseudometric space structure by a uniform inducing map. This is a version of `PseudoMetricSpace.induced` useful in case if the domain already has a `UniformSpace` structure. -/ def IsUniformInducing.comapPseudoMetricSpace {α β} [UniformSpace α] [m : PseudoMetricSpace β] (f : α → β) (h : IsUniformInducing f) : PseudoMetricSpace α := .replaceUniformity (.induced f m) h.comap_uniformity.symm instance Subtype.pseudoMetricSpace {p : α → Prop} : PseudoMetricSpace (Subtype p) := PseudoMetricSpace.induced Subtype.val ‹_› lemma Subtype.dist_eq {p : α → Prop} (x y : Subtype p) : dist x y = dist (x : α) y := rfl lemma Subtype.nndist_eq {p : α → Prop} (x y : Subtype p) : nndist x y = nndist (x : α) y := rfl namespace MulOpposite @[to_additive] instance instPseudoMetricSpace : PseudoMetricSpace αᵐᵒᵖ := PseudoMetricSpace.induced MulOpposite.unop ‹_› @[to_additive (attr := simp)] lemma dist_unop (x y : αᵐᵒᵖ) : dist (unop x) (unop y) = dist x y := rfl @[to_additive (attr := simp)] lemma dist_op (x y : α) : dist (op x) (op y) = dist x y := rfl @[to_additive (attr := simp)] lemma nndist_unop (x y : αᵐᵒᵖ) : nndist (unop x) (unop y) = nndist x y := rfl @[to_additive (attr := simp)] lemma nndist_op (x y : α) : nndist (op x) (op y) = nndist x y := rfl end MulOpposite section NNReal instance : PseudoMetricSpace ℝ≥0 := Subtype.pseudoMetricSpace lemma NNReal.dist_eq (a b : ℝ≥0) : dist a b = |(a : ℝ) - b| := rfl lemma NNReal.nndist_eq (a b : ℝ≥0) : nndist a b = max (a - b) (b - a) := eq_of_forall_ge_iff fun _ => by simp only [max_le_iff, tsub_le_iff_right (α := ℝ≥0)] simp only [← NNReal.coe_le_coe, coe_nndist, dist_eq, abs_sub_le_iff, tsub_le_iff_right, NNReal.coe_add] @[simp] lemma NNReal.nndist_zero_eq_val (z : ℝ≥0) : nndist 0 z = z := by simp only [NNReal.nndist_eq, max_eq_right, tsub_zero, zero_tsub, zero_le'] @[simp] lemma NNReal.nndist_zero_eq_val' (z : ℝ≥0) : nndist z 0 = z := by rw [nndist_comm] exact NNReal.nndist_zero_eq_val z lemma NNReal.le_add_nndist (a b : ℝ≥0) : a ≤ b + nndist a b := by suffices (a : ℝ) ≤ (b : ℝ) + dist a b by rwa [← NNReal.coe_le_coe, NNReal.coe_add, coe_nndist] rw [← sub_le_iff_le_add'] exact le_of_abs_le (dist_eq a b).ge lemma NNReal.ball_zero_eq_Ico' (c : ℝ≥0) : Metric.ball (0 : ℝ≥0) c.toReal = Set.Ico 0 c := by ext x; simp lemma NNReal.ball_zero_eq_Ico (c : ℝ) : Metric.ball (0 : ℝ≥0) c = Set.Ico 0 c.toNNReal := by by_cases c_pos : 0 < c · convert NNReal.ball_zero_eq_Ico' ⟨c, c_pos.le⟩ simp [Real.toNNReal, c_pos.le] simp [not_lt.mp c_pos] lemma NNReal.closedBall_zero_eq_Icc' (c : ℝ≥0) : Metric.closedBall (0 : ℝ≥0) c.toReal = Set.Icc 0 c := by ext x; simp lemma NNReal.closedBall_zero_eq_Icc {c : ℝ} (c_nn : 0 ≤ c) : Metric.closedBall (0 : ℝ≥0) c = Set.Icc 0 c.toNNReal := by convert NNReal.closedBall_zero_eq_Icc' ⟨c, c_nn⟩ simp [Real.toNNReal, c_nn] end NNReal namespace ULift variable [PseudoMetricSpace β] instance : PseudoMetricSpace (ULift β) := PseudoMetricSpace.induced ULift.down ‹_› lemma dist_eq (x y : ULift β) : dist x y = dist x.down y.down := rfl lemma nndist_eq (x y : ULift β) : nndist x y = nndist x.down y.down := rfl @[simp] lemma dist_up_up (x y : β) : dist (ULift.up x) (ULift.up y) = dist x y := rfl @[simp] lemma nndist_up_up (x y : β) : nndist (ULift.up x) (ULift.up y) = nndist x y := rfl end ULift section Prod variable [PseudoMetricSpace β] instance Prod.pseudoMetricSpaceMax : PseudoMetricSpace (α × β) := let i := PseudoEMetricSpace.toPseudoMetricSpaceOfDist (fun x y : α × β => dist x.1 y.1 ⊔ dist x.2 y.2) (fun _ _ => (max_lt (edist_lt_top _ _) (edist_lt_top _ _)).ne) fun x y => by simp only [dist_edist, ← ENNReal.toReal_max (edist_ne_top _ _) (edist_ne_top _ _), Prod.edist_eq] i.replaceBornology fun s => by simp only [← isBounded_image_fst_and_snd, isBounded_iff_eventually, forall_mem_image, ← eventually_and, ← forall_and, ← max_le_iff] rfl lemma Prod.dist_eq {x y : α × β} : dist x y = max (dist x.1 y.1) (dist x.2 y.2) := rfl @[simp] lemma dist_prod_same_left {x : α} {y₁ y₂ : β} : dist (x, y₁) (x, y₂) = dist y₁ y₂ := by simp [Prod.dist_eq, dist_nonneg] @[simp] lemma dist_prod_same_right {x₁ x₂ : α} {y : β} : dist (x₁, y) (x₂, y) = dist x₁ x₂ := by simp [Prod.dist_eq, dist_nonneg] lemma ball_prod_same (x : α) (y : β) (r : ℝ) : ball x r ×ˢ ball y r = ball (x, y) r := ext fun z => by simp [Prod.dist_eq] lemma closedBall_prod_same (x : α) (y : β) (r : ℝ) : closedBall x r ×ˢ closedBall y r = closedBall (x, y) r := ext fun z => by simp [Prod.dist_eq] lemma sphere_prod (x : α × β) (r : ℝ) : sphere x r = sphere x.1 r ×ˢ closedBall x.2 r ∪ closedBall x.1 r ×ˢ sphere x.2 r := by obtain hr | rfl | hr := lt_trichotomy r 0 · simp [hr] · cases x simp_rw [← closedBall_eq_sphere_of_nonpos le_rfl, union_self, closedBall_prod_same] · ext ⟨x', y'⟩ simp_rw [Set.mem_union, Set.mem_prod, Metric.mem_closedBall, Metric.mem_sphere, Prod.dist_eq, max_eq_iff] refine or_congr (and_congr_right ?_) (and_comm.trans (and_congr_left ?_)) all_goals rintro rfl; rfl end Prod lemma uniformContinuous_dist : UniformContinuous fun p : α × α => dist p.1 p.2 := Metric.uniformContinuous_iff.2 fun ε ε0 => ⟨ε / 2, half_pos ε0, fun {a b} h => calc dist (dist a.1 a.2) (dist b.1 b.2) ≤ dist a.1 b.1 + dist a.2 b.2 := dist_dist_dist_le _ _ _ _ _ ≤ dist a b + dist a b := add_le_add (le_max_left _ _) (le_max_right _ _) _ < ε / 2 + ε / 2 := add_lt_add h h _ = ε := add_halves ε⟩ protected lemma UniformContinuous.dist [UniformSpace β] {f g : β → α} (hf : UniformContinuous f) (hg : UniformContinuous g) : UniformContinuous fun b => dist (f b) (g b) := uniformContinuous_dist.comp (hf.prodMk hg) @[continuity] lemma continuous_dist : Continuous fun p : α × α ↦ dist p.1 p.2 := uniformContinuous_dist.continuous @[continuity, fun_prop] protected lemma Continuous.dist [TopologicalSpace β] {f g : β → α} (hf : Continuous f) (hg : Continuous g) : Continuous fun b => dist (f b) (g b) := continuous_dist.comp₂ hf hg protected lemma Filter.Tendsto.dist {f g : β → α} {x : Filter β} {a b : α} (hf : Tendsto f x (𝓝 a)) (hg : Tendsto g x (𝓝 b)) : Tendsto (fun x => dist (f x) (g x)) x (𝓝 (dist a b)) := (continuous_dist.tendsto (a, b)).comp (hf.prodMk_nhds hg) lemma continuous_iff_continuous_dist [TopologicalSpace β] {f : β → α} : Continuous f ↔ Continuous fun x : β × β => dist (f x.1) (f x.2) := ⟨fun h => h.fst'.dist h.snd', fun h => continuous_iff_continuousAt.2 fun _ => tendsto_iff_dist_tendsto_zero.2 <| (h.comp (.prodMk_left _)).tendsto' _ _ <| dist_self _⟩ lemma uniformContinuous_nndist : UniformContinuous fun p : α × α => nndist p.1 p.2 := uniformContinuous_dist.subtype_mk _ protected lemma UniformContinuous.nndist [UniformSpace β] {f g : β → α} (hf : UniformContinuous f) (hg : UniformContinuous g) : UniformContinuous fun b => nndist (f b) (g b) := uniformContinuous_nndist.comp (hf.prodMk hg) lemma continuous_nndist : Continuous fun p : α × α => nndist p.1 p.2 := uniformContinuous_nndist.continuous @[fun_prop] protected lemma Continuous.nndist [TopologicalSpace β] {f g : β → α} (hf : Continuous f) (hg : Continuous g) : Continuous fun b => nndist (f b) (g b) := continuous_nndist.comp₂ hf hg protected lemma Filter.Tendsto.nndist {f g : β → α} {x : Filter β} {a b : α} (hf : Tendsto f x (𝓝 a)) (hg : Tendsto g x (𝓝 b)) : Tendsto (fun x => nndist (f x) (g x)) x (𝓝 (nndist a b)) := (continuous_nndist.tendsto (a, b)).comp (hf.prodMk_nhds hg)
Mathlib/Topology/MetricSpace/Pseudo/Constructions.lean
396
401
/- Copyright (c) 2023 Jz Pan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jz Pan -/ import Mathlib.FieldTheory.SplittingField.Construction import Mathlib.FieldTheory.IsAlgClosed.AlgebraicClosure import Mathlib.FieldTheory.Separable import Mathlib.FieldTheory.Normal.Closure import Mathlib.RingTheory.AlgebraicIndependent.Adjoin import Mathlib.RingTheory.AlgebraicIndependent.TranscendenceBasis import Mathlib.RingTheory.Polynomial.SeparableDegree import Mathlib.RingTheory.Polynomial.UniqueFactorization /-! # Separable degree This file contains basics about the separable degree of a field extension. ## Main definitions - `Field.Emb F E`: the type of `F`-algebra homomorphisms from `E` to the algebraic closure of `E` (the algebraic closure of `F` is usually used in the literature, but our definition has the advantage that `Field.Emb F E` lies in the same universe as `E` rather than the maximum over `F` and `E`). Usually denoted by $\operatorname{Emb}_F(E)$ in textbooks. - `Field.finSepDegree F E`: the (finite) separable degree $[E:F]_s$ of an extension `E / F` of fields, defined to be the number of `F`-algebra homomorphisms from `E` to the algebraic closure of `E`, as a natural number. It is zero if `Field.Emb F E` is not finite. Note that if `E / F` is not algebraic, then this definition makes no mathematical sense. **Remark:** the `Cardinal`-valued, potentially infinite separable degree `Field.sepDegree F E` for a general algebraic extension `E / F` is defined to be the degree of `L / F`, where `L` is the separable closure of `F` in `E`, which is not defined in this file yet. Later we will show that (`Field.finSepDegree_eq`), if `Field.Emb F E` is finite, then these two definitions coincide. If `E / F` is algebraic with infinite separable degree, we have `#(Field.Emb F E) = 2 ^ Field.sepDegree F E` instead. (See `Field.Emb.cardinal_eq_two_pow_sepDegree` in another file.) For example, if $F = \mathbb{Q}$ and $E = \mathbb{Q}( \mu_{p^\infty} )$, then $\operatorname{Emb}_F (E)$ is in bijection with $\operatorname{Gal}(E/F)$, which is isomorphic to $\mathbb{Z}_p^\times$, which is uncountable, whereas $ [E:F] $ is countable. - `Polynomial.natSepDegree`: the separable degree of a polynomial is a natural number, defined to be the number of distinct roots of it over its splitting field. ## Main results - `Field.embEquivOfEquiv`, `Field.finSepDegree_eq_of_equiv`: a random bijection between `Field.Emb F E` and `Field.Emb F K` when `E` and `K` are isomorphic as `F`-algebras. In particular, they have the same cardinality (so their `Field.finSepDegree` are equal). - `Field.embEquivOfAdjoinSplits`, `Field.finSepDegree_eq_of_adjoin_splits`: a random bijection between `Field.Emb F E` and `E →ₐ[F] K` if `E = F(S)` such that every element `s` of `S` is integral (= algebraic) over `F` and whose minimal polynomial splits in `K`. In particular, they have the same cardinality. - `Field.embEquivOfIsAlgClosed`, `Field.finSepDegree_eq_of_isAlgClosed`: a random bijection between `Field.Emb F E` and `E →ₐ[F] K` when `E / F` is algebraic and `K / F` is algebraically closed. In particular, they have the same cardinality. - `Field.embProdEmbOfIsAlgebraic`, `Field.finSepDegree_mul_finSepDegree_of_isAlgebraic`: if `K / E / F` is a field extension tower, such that `K / E` is algebraic, then there is a non-canonical bijection `Field.Emb F E × Field.Emb E K ≃ Field.Emb F K`. In particular, the separable degrees satisfy the tower law: $[E:F]_s [K:E]_s = [K:F]_s$ (see also `Module.finrank_mul_finrank`). - `Field.infinite_emb_of_transcendental`: `Field.Emb` is infinite for transcendental extensions. - `Polynomial.natSepDegree_le_natDegree`: the separable degree of a polynomial is smaller than its degree. - `Polynomial.natSepDegree_eq_natDegree_iff`: the separable degree of a non-zero polynomial is equal to its degree if and only if it is separable. - `Polynomial.natSepDegree_eq_of_splits`: if a polynomial splits over `E`, then its separable degree is equal to the number of distinct roots of it over `E`. - `Polynomial.natSepDegree_eq_of_isAlgClosed`: the separable degree of a polynomial is equal to the number of distinct roots of it over any algebraically closed field. - `Polynomial.natSepDegree_expand`: if a field `F` is of exponential characteristic `q`, then `Polynomial.expand F (q ^ n) f` and `f` have the same separable degree. - `Polynomial.HasSeparableContraction.natSepDegree_eq`: if a polynomial has separable contraction, then its separable degree is equal to its separable contraction degree. - `Irreducible.natSepDegree_dvd_natDegree`: the separable degree of an irreducible polynomial divides its degree. - `IntermediateField.finSepDegree_adjoin_simple_eq_natSepDegree`: the separable degree of `F⟮α⟯ / F` is equal to the separable degree of the minimal polynomial of `α` over `F`. - `IntermediateField.finSepDegree_adjoin_simple_eq_finrank_iff`: if `α` is algebraic over `F`, then the separable degree of `F⟮α⟯ / F` is equal to the degree of `F⟮α⟯ / F` if and only if `α` is a separable element. - `Field.finSepDegree_dvd_finrank`: the separable degree of any field extension `E / F` divides the degree of `E / F`. - `Field.finSepDegree_le_finrank`: the separable degree of a finite extension `E / F` is smaller than the degree of `E / F`. - `Field.finSepDegree_eq_finrank_iff`: if `E / F` is a finite extension, then its separable degree is equal to its degree if and only if it is a separable extension. - `IntermediateField.isSeparable_adjoin_simple_iff_isSeparable`: `F⟮x⟯ / F` is a separable extension if and only if `x` is a separable element. - `Algebra.IsSeparable.trans`: if `E / F` and `K / E` are both separable, then `K / F` is also separable. ## Tags separable degree, degree, polynomial -/ open Module Polynomial IntermediateField Field noncomputable section universe u v w variable (F : Type u) (E : Type v) [Field F] [Field E] [Algebra F E] variable (K : Type w) [Field K] [Algebra F K] namespace Field /-- `Field.Emb F E` is the type of `F`-algebra homomorphisms from `E` to the algebraic closure of `E`. -/ abbrev Emb := E →ₐ[F] AlgebraicClosure E /-- If `E / F` is an algebraic extension, then the (finite) separable degree of `E / F` is the number of `F`-algebra homomorphisms from `E` to the algebraic closure of `E`, as a natural number. It is defined to be zero if there are infinitely many of them. Note that if `E / F` is not algebraic, then this definition makes no mathematical sense. -/ def finSepDegree : ℕ := Nat.card (Emb F E) instance instInhabitedEmb : Inhabited (Emb F E) := ⟨IsScalarTower.toAlgHom F E _⟩ instance instNeZeroFinSepDegree [FiniteDimensional F E] : NeZero (finSepDegree F E) := ⟨Nat.card_ne_zero.2 ⟨inferInstance, Fintype.finite <| minpoly.AlgHom.fintype _ _ _⟩⟩ /-- A random bijection between `Field.Emb F E` and `Field.Emb F K` when `E` and `K` are isomorphic as `F`-algebras. -/ def embEquivOfEquiv (i : E ≃ₐ[F] K) : Emb F E ≃ Emb F K := AlgEquiv.arrowCongr i <| AlgEquiv.symm <| by let _ : Algebra E K := i.toAlgHom.toRingHom.toAlgebra have : Algebra.IsAlgebraic E K := by constructor intro x have h := isAlgebraic_algebraMap (R := E) (A := K) (i.symm.toAlgHom x) rw [show ∀ y : E, (algebraMap E K) y = i.toAlgHom y from fun y ↦ rfl] at h simpa only [AlgEquiv.toAlgHom_eq_coe, AlgHom.coe_coe, AlgEquiv.apply_symm_apply] using h apply AlgEquiv.restrictScalars (R := F) (S := E) exact IsAlgClosure.equivOfAlgebraic E K (AlgebraicClosure K) (AlgebraicClosure E) /-- If `E` and `K` are isomorphic as `F`-algebras, then they have the same `Field.finSepDegree` over `F`. -/ theorem finSepDegree_eq_of_equiv (i : E ≃ₐ[F] K) : finSepDegree F E = finSepDegree F K := Nat.card_congr (embEquivOfEquiv F E K i) @[simp] theorem finSepDegree_self : finSepDegree F F = 1 := by have : Cardinal.mk (Emb F F) = 1 := le_antisymm (Cardinal.le_one_iff_subsingleton.2 AlgHom.subsingleton) (Cardinal.one_le_iff_ne_zero.2 <| Cardinal.mk_ne_zero _) rw [finSepDegree, Nat.card, this, Cardinal.one_toNat] end Field namespace IntermediateField @[simp] theorem finSepDegree_bot : finSepDegree F (⊥ : IntermediateField F E) = 1 := by rw [finSepDegree_eq_of_equiv _ _ _ (botEquiv F E), finSepDegree_self] section Tower variable {F} variable [Algebra E K] [IsScalarTower F E K] @[simp] theorem finSepDegree_bot' : finSepDegree F (⊥ : IntermediateField E K) = finSepDegree F E := finSepDegree_eq_of_equiv _ _ _ ((botEquiv E K).restrictScalars F) @[simp] theorem finSepDegree_top : finSepDegree F (⊤ : IntermediateField E K) = finSepDegree F K := finSepDegree_eq_of_equiv _ _ _ ((topEquiv (F := E) (E := K)).restrictScalars F) end Tower end IntermediateField namespace Field /-- A random bijection between `Field.Emb F E` and `E →ₐ[F] K` if `E = F(S)` such that every element `s` of `S` is integral (= algebraic) over `F` and whose minimal polynomial splits in `K`. Combined with `Field.instInhabitedEmb`, it can be viewed as a stronger version of `IntermediateField.nonempty_algHom_of_adjoin_splits`. -/ def embEquivOfAdjoinSplits {S : Set E} (hS : adjoin F S = ⊤) (hK : ∀ s ∈ S, IsIntegral F s ∧ Splits (algebraMap F K) (minpoly F s)) : Emb F E ≃ (E →ₐ[F] K) := have : Algebra.IsAlgebraic F (⊤ : IntermediateField F E) := (hS ▸ isAlgebraic_adjoin (S := S) fun x hx ↦ (hK x hx).1) have halg := (topEquiv (F := F) (E := E)).isAlgebraic Classical.choice <| Function.Embedding.antisymm (halg.algHomEmbeddingOfSplits (fun _ ↦ splits_of_mem_adjoin F E (S := S) hK (hS ▸ mem_top)) _) (halg.algHomEmbeddingOfSplits (fun _ ↦ IsAlgClosed.splits_codomain _) _) /-- The `Field.finSepDegree F E` is equal to the cardinality of `E →ₐ[F] K` if `E = F(S)` such that every element `s` of `S` is integral (= algebraic) over `F` and whose minimal polynomial splits in `K`. -/ theorem finSepDegree_eq_of_adjoin_splits {S : Set E} (hS : adjoin F S = ⊤) (hK : ∀ s ∈ S, IsIntegral F s ∧ Splits (algebraMap F K) (minpoly F s)) : finSepDegree F E = Nat.card (E →ₐ[F] K) := Nat.card_congr (embEquivOfAdjoinSplits F E K hS hK) /-- A random bijection between `Field.Emb F E` and `E →ₐ[F] K` when `E / F` is algebraic and `K / F` is algebraically closed. -/ def embEquivOfIsAlgClosed [Algebra.IsAlgebraic F E] [IsAlgClosed K] : Emb F E ≃ (E →ₐ[F] K) := embEquivOfAdjoinSplits F E K (adjoin_univ F E) fun s _ ↦ ⟨Algebra.IsIntegral.isIntegral s, IsAlgClosed.splits_codomain _⟩ /-- The `Field.finSepDegree F E` is equal to the cardinality of `E →ₐ[F] K` as a natural number, when `E / F` is algebraic and `K / F` is algebraically closed. -/ @[stacks 09HJ "We use `finSepDegree` to state a more general result."] theorem finSepDegree_eq_of_isAlgClosed [Algebra.IsAlgebraic F E] [IsAlgClosed K] : finSepDegree F E = Nat.card (E →ₐ[F] K) := Nat.card_congr (embEquivOfIsAlgClosed F E K) /-- If `K / E / F` is a field extension tower, such that `K / E` is algebraic, then there is a non-canonical bijection `Field.Emb F E × Field.Emb E K ≃ Field.Emb F K`. A corollary of `algHomEquivSigma`. -/ def embProdEmbOfIsAlgebraic [Algebra E K] [IsScalarTower F E K] [Algebra.IsAlgebraic E K] : Emb F E × Emb E K ≃ Emb F K := let e : ∀ f : E →ₐ[F] AlgebraicClosure K, @AlgHom E K _ _ _ _ _ f.toRingHom.toAlgebra ≃ Emb E K := fun f ↦ (@embEquivOfIsAlgClosed E K _ _ _ _ _ f.toRingHom.toAlgebra).symm (algHomEquivSigma (A := F) (B := E) (C := K) (D := AlgebraicClosure K) |>.trans (Equiv.sigmaEquivProdOfEquiv e) |>.trans <| Equiv.prodCongrLeft <| fun _ : Emb E K ↦ AlgEquiv.arrowCongr (@AlgEquiv.refl F E _ _ _) <| (IsAlgClosure.equivOfAlgebraic E K (AlgebraicClosure K) (AlgebraicClosure E)).restrictScalars F).symm /-- If the field extension `E / F` is transcendental, then `Field.Emb F E` is infinite. -/ instance infinite_emb_of_transcendental [H : Algebra.Transcendental F E] : Infinite (Emb F E) := by obtain ⟨ι, x, hx⟩ := exists_isTranscendenceBasis' F E have := hx.isAlgebraic_field rw [← (embProdEmbOfIsAlgebraic F (adjoin F (Set.range x)) E).infinite_iff] refine @Prod.infinite_of_left _ _ ?_ _ rw [← (embEquivOfEquiv _ _ _ hx.1.aevalEquivField).infinite_iff] obtain ⟨i⟩ := hx.nonempty_iff_transcendental.2 H let K := FractionRing (MvPolynomial ι F) let i1 := IsScalarTower.toAlgHom F (MvPolynomial ι F) (AlgebraicClosure K) have hi1 : Function.Injective i1 := by rw [IsScalarTower.coe_toAlgHom', IsScalarTower.algebraMap_eq _ K] exact (algebraMap K (AlgebraicClosure K)).injective.comp (IsFractionRing.injective _ _) let f (n : ℕ) : Emb F K := IsFractionRing.liftAlgHom (g := i1.comp <| MvPolynomial.aeval fun i : ι ↦ MvPolynomial.X i ^ (n + 1)) <| hi1.comp <| by simpa [algebraicIndependent_iff_injective_aeval] using MvPolynomial.algebraicIndependent_polynomial_aeval_X _ fun i : ι ↦ (Polynomial.transcendental_X F).pow n.succ_pos refine Infinite.of_injective f fun m n h ↦ ?_ replace h : (MvPolynomial.X i) ^ (m + 1) = (MvPolynomial.X i) ^ (n + 1) := hi1 <| by simpa [f, -map_pow] using congr($h (algebraMap _ K (MvPolynomial.X (R := F) i))) simpa using congr(MvPolynomial.totalDegree $h) /-- If the field extension `E / F` is transcendental, then `Field.finSepDegree F E = 0`, which actually means that `Field.Emb F E` is infinite (see `Field.infinite_emb_of_transcendental`). -/ theorem finSepDegree_eq_zero_of_transcendental [Algebra.Transcendental F E] : finSepDegree F E = 0 := Nat.card_eq_zero_of_infinite /-- If `K / E / F` is a field extension tower, such that `K / E` is algebraic, then their separable degrees satisfy the tower law $[E:F]_s [K:E]_s = [K:F]_s$. See also `Module.finrank_mul_finrank`. -/ @[stacks 09HK "Part 1, `finSepDegree` variant"] theorem finSepDegree_mul_finSepDegree_of_isAlgebraic [Algebra E K] [IsScalarTower F E K] [Algebra.IsAlgebraic E K] : finSepDegree F E * finSepDegree E K = finSepDegree F K := by simpa only [Nat.card_prod] using Nat.card_congr (embProdEmbOfIsAlgebraic F E K) end Field namespace Polynomial variable {F E} variable (f : F[X]) open Classical in /-- The separable degree `Polynomial.natSepDegree` of a polynomial is a natural number, defined to be the number of distinct roots of it over its splitting field. This is similar to `Polynomial.natDegree` but not to `Polynomial.degree`, namely, the separable degree of `0` is `0`, not negative infinity. -/ def natSepDegree : ℕ := (f.aroots f.SplittingField).toFinset.card /-- The separable degree of a polynomial is smaller than its degree. -/ theorem natSepDegree_le_natDegree : f.natSepDegree ≤ f.natDegree := by have := f.map (algebraMap F f.SplittingField) |>.card_roots' rw [← aroots_def, natDegree_map] at this classical exact (f.aroots f.SplittingField).toFinset_card_le.trans this @[simp] theorem natSepDegree_X_sub_C (x : F) : (X - C x).natSepDegree = 1 := by simp only [natSepDegree, aroots_X_sub_C, Multiset.toFinset_singleton, Finset.card_singleton] @[simp] theorem natSepDegree_X : (X : F[X]).natSepDegree = 1 := by simp only [natSepDegree, aroots_X, Multiset.toFinset_singleton, Finset.card_singleton] /-- A constant polynomial has zero separable degree. -/ theorem natSepDegree_eq_zero (h : f.natDegree = 0) : f.natSepDegree = 0 := by linarith only [natSepDegree_le_natDegree f, h] @[simp] theorem natSepDegree_C (x : F) : (C x).natSepDegree = 0 := natSepDegree_eq_zero _ (natDegree_C _) @[simp] theorem natSepDegree_zero : (0 : F[X]).natSepDegree = 0 := by rw [← C_0, natSepDegree_C] @[simp] theorem natSepDegree_one : (1 : F[X]).natSepDegree = 0 := by rw [← C_1, natSepDegree_C] /-- A non-constant polynomial has non-zero separable degree. -/ theorem natSepDegree_ne_zero (h : f.natDegree ≠ 0) : f.natSepDegree ≠ 0 := by rw [natSepDegree, ne_eq, Finset.card_eq_zero, ← ne_eq, ← Finset.nonempty_iff_ne_empty] use rootOfSplits _ (SplittingField.splits f) (ne_of_apply_ne _ h) classical rw [Multiset.mem_toFinset, mem_aroots] exact ⟨ne_of_apply_ne _ h, map_rootOfSplits _ (SplittingField.splits f) (ne_of_apply_ne _ h)⟩ /-- A polynomial has zero separable degree if and only if it is constant. -/ theorem natSepDegree_eq_zero_iff : f.natSepDegree = 0 ↔ f.natDegree = 0 := ⟨(natSepDegree_ne_zero f).mtr, natSepDegree_eq_zero f⟩ /-- A polynomial has non-zero separable degree if and only if it is non-constant. -/ theorem natSepDegree_ne_zero_iff : f.natSepDegree ≠ 0 ↔ f.natDegree ≠ 0 := Iff.not <| natSepDegree_eq_zero_iff f /-- The separable degree of a non-zero polynomial is equal to its degree if and only if it is separable. -/ theorem natSepDegree_eq_natDegree_iff (hf : f ≠ 0) : f.natSepDegree = f.natDegree ↔ f.Separable := by classical simp_rw [← card_rootSet_eq_natDegree_iff_of_splits hf (SplittingField.splits f), rootSet_def, Finset.coe_sort_coe, Fintype.card_coe] rfl /-- If a polynomial is separable, then its separable degree is equal to its degree. -/ theorem natSepDegree_eq_natDegree_of_separable (h : f.Separable) : f.natSepDegree = f.natDegree := (natSepDegree_eq_natDegree_iff f h.ne_zero).2 h variable {f} in /-- Same as `Polynomial.natSepDegree_eq_natDegree_of_separable`, but enables the use of dot notation. -/ theorem Separable.natSepDegree_eq_natDegree (h : f.Separable) : f.natSepDegree = f.natDegree := natSepDegree_eq_natDegree_of_separable f h /-- If a polynomial splits over `E`, then its separable degree is equal to the number of distinct roots of it over `E`. -/ theorem natSepDegree_eq_of_splits [DecidableEq E] (h : f.Splits (algebraMap F E)) : f.natSepDegree = (f.aroots E).toFinset.card := by classical rw [aroots, ← (SplittingField.lift f h).comp_algebraMap, ← map_map, roots_map _ ((splits_id_iff_splits _).mpr <| SplittingField.splits f), Multiset.toFinset_map, Finset.card_image_of_injective _ (RingHom.injective _), natSepDegree] variable (E) in /-- The separable degree of a polynomial is equal to the number of distinct roots of it over any algebraically closed field. -/ theorem natSepDegree_eq_of_isAlgClosed [DecidableEq E] [IsAlgClosed E] : f.natSepDegree = (f.aroots E).toFinset.card := natSepDegree_eq_of_splits f (IsAlgClosed.splits_codomain f) theorem natSepDegree_map (f : E[X]) (i : E →+* K) : (f.map i).natSepDegree = f.natSepDegree := by classical let _ := i.toAlgebra simp_rw [show i = algebraMap E K by rfl, natSepDegree_eq_of_isAlgClosed (AlgebraicClosure K), aroots_def, map_map, ← IsScalarTower.algebraMap_eq] @[simp] theorem natSepDegree_C_mul {x : F} (hx : x ≠ 0) : (C x * f).natSepDegree = f.natSepDegree := by classical simp only [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_C_mul _ hx] @[simp] theorem natSepDegree_smul_nonzero {x : F} (hx : x ≠ 0) : (x • f).natSepDegree = f.natSepDegree := by classical simp only [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_smul_nonzero _ hx] @[simp] theorem natSepDegree_pow {n : ℕ} : (f ^ n).natSepDegree = if n = 0 then 0 else f.natSepDegree := by classical simp only [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_pow] by_cases h : n = 0 · simp only [h, zero_smul, Multiset.toFinset_zero, Finset.card_empty, ite_true] simp only [h, Multiset.toFinset_nsmul _ n h, ite_false] theorem natSepDegree_pow_of_ne_zero {n : ℕ} (hn : n ≠ 0) : (f ^ n).natSepDegree = f.natSepDegree := by simp_rw [natSepDegree_pow, hn, ite_false] theorem natSepDegree_X_pow {n : ℕ} : (X ^ n : F[X]).natSepDegree = if n = 0 then 0 else 1 := by simp only [natSepDegree_pow, natSepDegree_X] theorem natSepDegree_X_sub_C_pow {x : F} {n : ℕ} : ((X - C x) ^ n).natSepDegree = if n = 0 then 0 else 1 := by simp only [natSepDegree_pow, natSepDegree_X_sub_C] theorem natSepDegree_C_mul_X_sub_C_pow {x y : F} {n : ℕ} (hx : x ≠ 0) : (C x * (X - C y) ^ n).natSepDegree = if n = 0 then 0 else 1 := by simp only [natSepDegree_C_mul _ hx, natSepDegree_X_sub_C_pow] theorem natSepDegree_mul (g : F[X]) : (f * g).natSepDegree ≤ f.natSepDegree + g.natSepDegree := by by_cases h : f * g = 0 · simp only [h, natSepDegree_zero, zero_le] classical simp_rw [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_mul h, Multiset.toFinset_add] exact Finset.card_union_le _ _ theorem natSepDegree_mul_eq_iff (g : F[X]) : (f * g).natSepDegree = f.natSepDegree + g.natSepDegree ↔ (f = 0 ∧ g = 0) ∨ IsCoprime f g := by by_cases h : f * g = 0 · rw [mul_eq_zero] at h wlog hf : f = 0 generalizing f g · simpa only [mul_comm, add_comm, and_comm, isCoprime_comm] using this g f h.symm (h.resolve_left hf) rw [hf, zero_mul, natSepDegree_zero, zero_add, isCoprime_zero_left, isUnit_iff, eq_comm, natSepDegree_eq_zero_iff, natDegree_eq_zero] refine ⟨fun ⟨x, h⟩ ↦ ?_, ?_⟩ · by_cases hx : x = 0 · exact .inl ⟨rfl, by rw [← h, hx, map_zero]⟩ exact .inr ⟨x, Ne.isUnit hx, h⟩ rintro (⟨-, h⟩ | ⟨x, -, h⟩)
· exact ⟨0, by rw [h, map_zero]⟩ exact ⟨x, h⟩ classical
Mathlib/FieldTheory/SeparableDegree.lean
442
444
/- 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]
Mathlib/SetTheory/Cardinal/ENat.lean
127
128
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Paul Lezeau -/ import Mathlib.RingTheory.DedekindDomain.Ideal import Mathlib.RingTheory.IsAdjoinRoot /-! # Kummer-Dedekind theorem This file proves the monogenic version of the Kummer-Dedekind theorem on the splitting of prime ideals in an extension of the ring of integers. This states that if `I` is a prime ideal of Dedekind domain `R` and `S = R[α]` for some `α` that is integral over `R` with minimal polynomial `f`, then the prime factorisations of `I * S` and `f mod I` have the same shape, i.e. they have the same number of prime factors, and each prime factors of `I * S` can be paired with a prime factor of `f mod I` in a way that ensures multiplicities match (in fact, this pairing can be made explicit with a formula). ## Main definitions * `normalizedFactorsMapEquivNormalizedFactorsMinPolyMk` : The bijection in the Kummer-Dedekind theorem. This is the pairing between the prime factors of `I * S` and the prime factors of `f mod I`. ## Main results * `normalized_factors_ideal_map_eq_normalized_factors_min_poly_mk_map` : The Kummer-Dedekind theorem. * `Ideal.irreducible_map_of_irreducible_minpoly` : `I.map (algebraMap R S)` is irreducible if `(map (Ideal.Quotient.mk I) (minpoly R pb.gen))` is irreducible, where `pb` is a power basis of `S` over `R`. * `normalizedFactorsMapEquivNormalizedFactorsMinPolyMk_symm_apply_eq_span` : Let `Q` be a lift of factor of the minimal polynomial of `x`, a generator of `S` over `R`, taken `mod I`. Then (the reduction of) `Q` corresponds via `normalizedFactorsMapEquivNormalizedFactorsMinPolyMk` to `span (I.map (algebraMap R S) ∪ {Q.aeval x})`. ## TODO * Prove the Kummer-Dedekind theorem in full generality. * Prove the converse of `Ideal.irreducible_map_of_irreducible_minpoly`. ## References * [J. Neukirch, *Algebraic Number Theory*][Neukirch1992] ## Tags kummer, dedekind, kummer dedekind, dedekind-kummer, dedekind kummer -/ variable (R : Type*) {S : Type*} [CommRing R] [CommRing S] [Algebra R S] open Ideal Polynomial DoubleQuot UniqueFactorizationMonoid Algebra RingHom local notation:max R "<" x:max ">" => adjoin R ({x} : Set S) /-- Let `S / R` be a ring extension and `x : S`, then the conductor of `R<x>` is the biggest ideal of `S` contained in `R<x>`. -/ def conductor (x : S) : Ideal S where carrier := {a | ∀ b : S, a * b ∈ R<x>} zero_mem' b := by simpa only [zero_mul] using Subalgebra.zero_mem _ add_mem' ha hb c := by simpa only [add_mul] using Subalgebra.add_mem _ (ha c) (hb c) smul_mem' c a ha b := by simpa only [smul_eq_mul, mul_left_comm, mul_assoc] using ha (c * b) variable {R} {x : S} theorem conductor_eq_of_eq {y : S} (h : (R<x> : Set S) = R<y>) : conductor R x = conductor R y := Ideal.ext fun _ => forall_congr' fun _ => Set.ext_iff.mp h _ theorem conductor_subset_adjoin : (conductor R x : Set S) ⊆ R<x> := fun y hy => by simpa only [mul_one] using hy 1 theorem mem_conductor_iff {y : S} : y ∈ conductor R x ↔ ∀ b : S, y * b ∈ R<x> := ⟨fun h => h, fun h => h⟩ theorem conductor_eq_top_of_adjoin_eq_top (h : R<x> = ⊤) : conductor R x = ⊤ := by simp only [Ideal.eq_top_iff_one, mem_conductor_iff, h, mem_top, forall_const] theorem conductor_eq_top_of_powerBasis (pb : PowerBasis R S) : conductor R pb.gen = ⊤ := conductor_eq_top_of_adjoin_eq_top pb.adjoin_gen_eq_top open IsLocalization in lemma mem_coeSubmodule_conductor {L} [CommRing L] [Algebra S L] [Algebra R L] [IsScalarTower R S L] [NoZeroSMulDivisors S L] {x : S} {y : L} : y ∈ coeSubmodule L (conductor R x) ↔ ∀ z : S, y * (algebraMap S L) z ∈ Algebra.adjoin R {algebraMap S L x} := by cases subsingleton_or_nontrivial L · rw [Subsingleton.elim (coeSubmodule L _) ⊤, Subsingleton.elim (Algebra.adjoin R _) ⊤]; simp trans ∀ z, y * (algebraMap S L) z ∈ (Algebra.adjoin R {x}).map (IsScalarTower.toAlgHom R S L) · simp only [coeSubmodule, Submodule.mem_map, Algebra.linearMap_apply, Subalgebra.mem_map, IsScalarTower.coe_toAlgHom'] constructor · rintro ⟨y, hy, rfl⟩ z exact ⟨_, hy z, map_mul _ _ _⟩ · intro H obtain ⟨y, _, e⟩ := H 1 rw [map_one, mul_one] at e subst e simp only [← map_mul, (FaithfulSMul.algebraMap_injective S L).eq_iff, exists_eq_right] at H exact ⟨_, H, rfl⟩ · rw [AlgHom.map_adjoin, Set.image_singleton]; rfl variable {I : Ideal R} /-- This technical lemma tell us that if `C` is the conductor of `R<x>` and `I` is an ideal of `R` then `p * (I * S) ⊆ I * R<x>` for any `p` in `C ∩ R` -/ theorem prod_mem_ideal_map_of_mem_conductor {p : R} {z : S} (hp : p ∈ Ideal.comap (algebraMap R S) (conductor R x)) (hz' : z ∈ I.map (algebraMap R S)) : algebraMap R S p * z ∈ algebraMap R<x> S '' ↑(I.map (algebraMap R R<x>)) := by rw [Ideal.map, Ideal.span, Finsupp.mem_span_image_iff_linearCombination] at hz' obtain ⟨l, H, H'⟩ := hz' rw [Finsupp.linearCombination_apply] at H' rw [← H', mul_comm, Finsupp.sum_mul] have lem : ∀ {a : R}, a ∈ I → l a • algebraMap R S a * algebraMap R S p ∈ algebraMap R<x> S '' I.map (algebraMap R R<x>) := by intro a ha rw [Algebra.id.smul_eq_mul, mul_assoc, mul_comm, mul_assoc, Set.mem_image] refine Exists.intro (algebraMap R R<x> a * ⟨l a * algebraMap R S p, show l a * algebraMap R S p ∈ R<x> from ?h⟩) ?_ case h => rw [mul_comm] exact mem_conductor_iff.mp (Ideal.mem_comap.mp hp) _ · refine ⟨?_, ?_⟩ · rw [mul_comm] apply Ideal.mul_mem_left (I.map (algebraMap R R<x>)) _ (Ideal.mem_map_of_mem _ ha) · simp only [RingHom.map_mul, mul_comm (algebraMap R S p) (l a)] rfl refine Finset.sum_induction _ (fun u => u ∈ algebraMap R<x> S '' I.map (algebraMap R R<x>)) (fun a b => ?_) ?_ ?_ · rintro ⟨z, hz, rfl⟩ ⟨y, hy, rfl⟩ rw [← RingHom.map_add] exact ⟨z + y, Ideal.add_mem _ (SetLike.mem_coe.mp hz) hy, rfl⟩ · exact ⟨0, SetLike.mem_coe.mpr <| Ideal.zero_mem _, RingHom.map_zero _⟩ · intro y hy exact lem ((Finsupp.mem_supported _ l).mp H hy) /-- A technical result telling us that `(I * S) ∩ R<x> = I * R<x>` for any ideal `I` of `R`. -/ theorem comap_map_eq_map_adjoin_of_coprime_conductor (hx : (conductor R x).comap (algebraMap R S) ⊔ I = ⊤) (h_alg : Function.Injective (algebraMap R<x> S)) : (I.map (algebraMap R S)).comap (algebraMap R<x> S) = I.map (algebraMap R R<x>) := by apply le_antisymm · -- This is adapted from [Neukirch1992]. Let `C = (conductor R x)`. The idea of the proof -- is that since `I` and `C ∩ R` are coprime, we have -- `(I * S) ∩ R<x> ⊆ (I + C) * ((I * S) ∩ R<x>) ⊆ I * R<x> + I * C * S ⊆ I * R<x>`. intro y hy obtain ⟨z, hz⟩ := y obtain ⟨p, hp, q, hq, hpq⟩ := Submodule.mem_sup.mp ((Ideal.eq_top_iff_one _).mp hx) have temp : algebraMap R S p * z + algebraMap R S q * z = z := by simp only [← add_mul, ← RingHom.map_add (algebraMap R S), hpq, map_one, one_mul] suffices z ∈ algebraMap R<x> S '' I.map (algebraMap R R<x>) ↔ (⟨z, hz⟩ : R<x>) ∈ I.map (algebraMap R R<x>) by rw [← this, ← temp] obtain ⟨a, ha⟩ := (Set.mem_image _ _ _).mp (prod_mem_ideal_map_of_mem_conductor hp (show z ∈ I.map (algebraMap R S) by rwa [Ideal.mem_comap] at hy)) use a + algebraMap R R<x> q * ⟨z, hz⟩ refine ⟨Ideal.add_mem (I.map (algebraMap R R<x>)) ha.left ?_, by simp only [ha.right, map_add, map_mul, add_right_inj]; rfl⟩ rw [mul_comm] exact Ideal.mul_mem_left (I.map (algebraMap R R<x>)) _ (Ideal.mem_map_of_mem _ hq) refine ⟨fun h => ?_, fun h => (Set.mem_image _ _ _).mpr (Exists.intro ⟨z, hz⟩ ⟨by simp [h], rfl⟩)⟩ obtain ⟨x₁, hx₁, hx₂⟩ := (Set.mem_image _ _ _).mp h have : x₁ = ⟨z, hz⟩ := by apply h_alg simp only [hx₂, algebraMap_eq_smul_one] rw [Submonoid.mk_smul, smul_eq_mul, mul_one] rwa [← this] · -- The converse inclusion is trivial have : algebraMap R S = (algebraMap _ S).comp (algebraMap R R<x>) := by ext; rfl rw [this, ← Ideal.map_map] apply Ideal.le_comap_map /-- The canonical morphism of rings from `R<x> ⧸ (I*R<x>)` to `S ⧸ (I*S)` is an isomorphism when `I` and `(conductor R x) ∩ R` are coprime. -/ noncomputable def quotAdjoinEquivQuotMap (hx : (conductor R x).comap (algebraMap R S) ⊔ I = ⊤) (h_alg : Function.Injective (algebraMap R<x> S)) : R<x> ⧸ I.map (algebraMap R R<x>) ≃+* S ⧸ I.map (algebraMap R S) := by let f : R<x> ⧸ I.map (algebraMap R R<x>) →+* S ⧸ I.map (algebraMap R S) := (Ideal.Quotient.lift (I.map (algebraMap R R<x>)) ((Ideal.Quotient.mk (I.map (algebraMap R S))).comp (algebraMap R<x> S)) (fun r hr => by have : algebraMap R S = (algebraMap R<x> S).comp (algebraMap R R<x>) := by ext; rfl rw [RingHom.comp_apply, Ideal.Quotient.eq_zero_iff_mem, this, ← Ideal.map_map] exact Ideal.mem_map_of_mem _ hr)) refine RingEquiv.ofBijective f ⟨?_, ?_⟩ · --the kernel of the map is clearly `(I * S) ∩ R<x>`. To get injectivity, we need to show that --this is contained in `I * R<x>`, which is the content of the previous lemma. refine RingHom.lift_injective_of_ker_le_ideal _ _ fun u hu => ?_ rwa [RingHom.mem_ker, RingHom.comp_apply, Ideal.Quotient.eq_zero_iff_mem, ← Ideal.mem_comap, comap_map_eq_map_adjoin_of_coprime_conductor hx h_alg] at hu · -- Surjectivity follows from the surjectivity of the canonical map `R<x> → S ⧸ (I * S)`, -- which in turn follows from the fact that `I * S + (conductor R x) = S`. refine Ideal.Quotient.lift_surjective_of_surjective _ _ fun y => ?_ obtain ⟨z, hz⟩ := Ideal.Quotient.mk_surjective y have : z ∈ conductor R x ⊔ I.map (algebraMap R S) := by suffices conductor R x ⊔ I.map (algebraMap R S) = ⊤ by simp only [this, Submodule.mem_top] rw [Ideal.eq_top_iff_one] at hx ⊢ replace hx := Ideal.mem_map_of_mem (algebraMap R S) hx rw [Ideal.map_sup, RingHom.map_one] at hx exact (sup_le_sup (show ((conductor R x).comap (algebraMap R S)).map (algebraMap R S) ≤ conductor R x from Ideal.map_comap_le) (le_refl (I.map (algebraMap R S)))) hx rw [← Ideal.mem_quotient_iff_mem_sup, hz, Ideal.mem_map_iff_of_surjective] at this · obtain ⟨u, hu, hu'⟩ := this use ⟨u, conductor_subset_adjoin hu⟩ simp only [← hu'] rfl · exact Ideal.Quotient.mk_surjective @[simp] theorem quotAdjoinEquivQuotMap_apply_mk (hx : (conductor R x).comap (algebraMap R S) ⊔ I = ⊤) (h_alg : Function.Injective (algebraMap R<x> S)) (a : R<x>) : quotAdjoinEquivQuotMap hx h_alg (Ideal.Quotient.mk (I.map (algebraMap R R<x>)) a) = Ideal.Quotient.mk (I.map (algebraMap R S)) ↑a := rfl namespace KummerDedekind open scoped Polynomial variable [IsDomain R] [IsIntegrallyClosed R] variable [IsDedekindDomain S] variable [NoZeroSMulDivisors R S] attribute [local instance] Ideal.Quotient.field private noncomputable def f (hx : (conductor R x).comap (algebraMap R S) ⊔ I = ⊤) (hx' : IsIntegral R x) : S ⧸ I.map (algebraMap R S) ≃+* (R ⧸ I)[X] ⧸ span {(minpoly R x).map (Ideal.Quotient.mk I)} := (quotAdjoinEquivQuotMap hx (FaithfulSMul.algebraMap_injective (Algebra.adjoin R {x}) S)).symm.trans <| ((Algebra.adjoin.powerBasis' hx').quotientEquivQuotientMinpolyMap I).toRingEquiv.trans <| quotEquivOfEq (by rw [Algebra.adjoin.powerBasis'_minpoly_gen hx']) private lemma f_symm_aux (hx : (conductor R x).comap (algebraMap R S) ⊔ I = ⊤) (hx' : IsIntegral R x) (Q : R[X]) : (f hx hx').symm (Q.map (Ideal.Quotient.mk I)) = Q.aeval x := by apply (f hx hx').injective rw [f, AlgEquiv.toRingEquiv_eq_coe, RingEquiv.symm_trans_apply, RingEquiv.symm_symm, RingEquiv.coe_trans, Function.comp_apply, RingEquiv.symm_apply_apply, RingEquiv.symm_trans_apply, quotEquivOfEq_symm, quotEquivOfEq_mk] congr convert (adjoin.powerBasis' hx').quotientEquivQuotientMinpolyMap_symm_apply_mk I Q apply (quotAdjoinEquivQuotMap hx (FaithfulSMul.algebraMap_injective ((adjoin R {x})) S)).injective simp only [RingEquiv.apply_symm_apply, adjoin.powerBasis'_gen, quotAdjoinEquivQuotMap_apply_mk, coe_aeval_mk_apply] open Classical in /-- The first half of the **Kummer-Dedekind Theorem** in the monogenic case, stating that the prime factors of `I*S` are in bijection with those of the minimal polynomial of the generator of `S` over `R`, taken `mod I`. -/ noncomputable def normalizedFactorsMapEquivNormalizedFactorsMinPolyMk (hI : IsMaximal I) (hI' : I ≠ ⊥) (hx : (conductor R x).comap (algebraMap R S) ⊔ I = ⊤) (hx' : IsIntegral R x) : {J : Ideal S | J ∈ normalizedFactors (I.map (algebraMap R S))} ≃ {d : (R ⧸ I)[X] | d ∈ normalizedFactors (Polynomial.map (Ideal.Quotient.mk I) (minpoly R x))} := by refine (normalizedFactorsEquivOfQuotEquiv (f hx hx') ?_ ?_).trans ?_ · rwa [Ne, map_eq_bot_iff_of_injective (FaithfulSMul.algebraMap_injective R S), ← Ne] · by_contra h exact (show Polynomial.map (Ideal.Quotient.mk I) (minpoly R x) ≠ 0 from Polynomial.map_monic_ne_zero (minpoly.monic hx')) (span_singleton_eq_bot.mp h) · refine (normalizedFactorsEquivSpanNormalizedFactors ?_).symm exact Polynomial.map_monic_ne_zero (minpoly.monic hx') open Classical in /-- The second half of the **Kummer-Dedekind Theorem** in the monogenic case, stating that the bijection `FactorsEquiv'` defined in the first half preserves multiplicities. -/ theorem emultiplicity_factors_map_eq_emultiplicity (hI : IsMaximal I) (hI' : I ≠ ⊥) (hx : (conductor R x).comap (algebraMap R S) ⊔ I = ⊤) (hx' : IsIntegral R x) {J : Ideal S} (hJ : J ∈ normalizedFactors (I.map (algebraMap R S))) : emultiplicity J (I.map (algebraMap R S)) = emultiplicity (↑(normalizedFactorsMapEquivNormalizedFactorsMinPolyMk hI hI' hx hx' ⟨J, hJ⟩)) (Polynomial.map (Ideal.Quotient.mk I) (minpoly R x)) := by rw [normalizedFactorsMapEquivNormalizedFactorsMinPolyMk, Equiv.coe_trans, Function.comp_apply, emultiplicity_normalizedFactorsEquivSpanNormalizedFactors_symm_eq_emultiplicity, normalizedFactorsEquivOfQuotEquiv_emultiplicity_eq_emultiplicity]
open Classical in /-- The **Kummer-Dedekind Theorem**. -/ theorem normalizedFactors_ideal_map_eq_normalizedFactors_min_poly_mk_map (hI : IsMaximal I) (hI' : I ≠ ⊥) (hx : (conductor R x).comap (algebraMap R S) ⊔ I = ⊤) (hx' : IsIntegral R x) : normalizedFactors (I.map (algebraMap R S)) = Multiset.map (fun f => ((normalizedFactorsMapEquivNormalizedFactorsMinPolyMk hI hI' hx hx').symm f : Ideal S)) (normalizedFactors (Polynomial.map (Ideal.Quotient.mk I) (minpoly R x))).attach := by ext J -- WLOG, assume J is a normalized factor by_cases hJ : J ∈ normalizedFactors (I.map (algebraMap R S)) swap · rw [Multiset.count_eq_zero.mpr hJ, eq_comm, Multiset.count_eq_zero, Multiset.mem_map] simp only [not_exists] rintro J' ⟨_, rfl⟩ exact hJ ((normalizedFactorsMapEquivNormalizedFactorsMinPolyMk hI hI' hx hx').symm J').prop -- Then we just have to compare the multiplicities, which we already proved are equal. have := emultiplicity_factors_map_eq_emultiplicity hI hI' hx hx' hJ rw [emultiplicity_eq_count_normalizedFactors, emultiplicity_eq_count_normalizedFactors, UniqueFactorizationMonoid.normalize_normalized_factor _ hJ, UniqueFactorizationMonoid.normalize_normalized_factor, Nat.cast_inj] at this · refine this.trans ?_ -- Get rid of the `map` by applying the equiv to both sides. generalize hJ' : (normalizedFactorsMapEquivNormalizedFactorsMinPolyMk hI hI' hx hx') ⟨J, hJ⟩ = J' have : ((normalizedFactorsMapEquivNormalizedFactorsMinPolyMk hI hI' hx hx').symm J' : Ideal S) = J := by rw [← hJ', Equiv.symm_apply_apply _ _, Subtype.coe_mk] subst this -- Get rid of the `attach` by applying the subtype `coe` to both sides. rw [Multiset.count_map_eq_count' fun f => ((normalizedFactorsMapEquivNormalizedFactorsMinPolyMk hI hI' hx hx').symm f : Ideal S), Multiset.count_attach] · exact Subtype.coe_injective.comp (Equiv.injective _) · exact (normalizedFactorsMapEquivNormalizedFactorsMinPolyMk hI hI' hx hx' _).prop · exact irreducible_of_normalized_factor _ (normalizedFactorsMapEquivNormalizedFactorsMinPolyMk hI hI' hx hx' _).prop · exact Polynomial.map_monic_ne_zero (minpoly.monic hx') · exact irreducible_of_normalized_factor _ hJ
Mathlib/NumberTheory/KummerDedekind.lean
286
327
/- 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.Algebra.Homology.Homotopy import Mathlib.Algebra.Homology.Linear import Mathlib.CategoryTheory.MorphismProperty.IsInvertedBy import Mathlib.CategoryTheory.Quotient.Linear import Mathlib.CategoryTheory.Quotient.Preadditive /-! # The homotopy category `HomotopyCategory V c` gives the category of chain complexes of shape `c` in `V`, with chain maps identified when they are homotopic. -/ universe v u noncomputable section open CategoryTheory CategoryTheory.Limits HomologicalComplex variable {R : Type*} [Semiring R] {ι : Type*} (V : Type u) [Category.{v} V] [Preadditive V] (c : ComplexShape ι) /-- The congruence on `HomologicalComplex V c` given by the existence of a homotopy. -/ def homotopic : HomRel (HomologicalComplex V c) := fun _ _ f g => Nonempty (Homotopy f g) instance homotopy_congruence : Congruence (homotopic V c) where equivalence := { refl := fun C => ⟨Homotopy.refl C⟩ symm := fun ⟨w⟩ => ⟨w.symm⟩ trans := fun ⟨w₁⟩ ⟨w₂⟩ => ⟨w₁.trans w₂⟩ } compLeft := fun _ _ _ ⟨i⟩ => ⟨i.compLeft _⟩ compRight := fun _ ⟨i⟩ => ⟨i.compRight _⟩ /-- `HomotopyCategory V c` is the category of chain complexes of shape `c` in `V`, with chain maps identified when they are homotopic. -/ def HomotopyCategory := CategoryTheory.Quotient (homotopic V c) instance : Category (HomotopyCategory V c) := by dsimp only [HomotopyCategory] infer_instance -- TODO the homotopy_category is preadditive namespace HomotopyCategory instance : Preadditive (HomotopyCategory V c) := Quotient.preadditive _ (by rintro _ _ _ _ _ _ ⟨h⟩ ⟨h'⟩ exact ⟨Homotopy.add h h'⟩) /-- The quotient functor from complexes to the homotopy category. -/ def quotient : HomologicalComplex V c ⥤ HomotopyCategory V c := CategoryTheory.Quotient.functor _ instance : (quotient V c).Full := Quotient.full_functor _ instance : (quotient V c).EssSurj := Quotient.essSurj_functor _ instance : (quotient V c).Additive where instance : Preadditive (CategoryTheory.Quotient (homotopic V c)) := (inferInstance : Preadditive (HomotopyCategory V c)) instance : Functor.Additive (Quotient.functor (homotopic V c)) where instance [Linear R V] : Linear R (HomotopyCategory V c) := Quotient.linear R (homotopic V c) (fun _ _ _ _ _ h => ⟨h.some.smul _⟩) instance [Linear R V] : Functor.Linear R (HomotopyCategory.quotient V c) := Quotient.linear_functor _ _ _ open ZeroObject instance [HasZeroObject V] : Inhabited (HomotopyCategory V c) := ⟨(quotient V c).obj 0⟩ instance [HasZeroObject V] : HasZeroObject (HomotopyCategory V c) := ⟨(quotient V c).obj 0, by rw [IsZero.iff_id_eq_zero, ← (quotient V c).map_id, id_zero, Functor.map_zero]⟩ instance {D : Type*} [Category D] : ((whiskeringLeft _ _ D).obj (quotient V c)).Full := Quotient.full_whiskeringLeft_functor _ _ instance {D : Type*} [Category D] : ((whiskeringLeft _ _ D).obj (quotient V c)).Faithful := Quotient.faithful_whiskeringLeft_functor _ _ variable {V c} lemma quotient_obj_surjective (X : HomotopyCategory V c) : ∃ (K : HomologicalComplex V c), (quotient _ _).obj K = X := ⟨_, rfl⟩ -- Porting note: removed @[simp] attribute because it hinders the automatic application of the -- more useful `quotient_map_out` theorem quotient_obj_as (C : HomologicalComplex V c) : ((quotient V c).obj C).as = C := rfl @[simp] theorem quotient_map_out {C D : HomotopyCategory V c} (f : C ⟶ D) : (quotient V c).map f.out = f := Quot.out_eq _ -- Porting note: added to ease the port theorem quot_mk_eq_quotient_map {C D : HomologicalComplex V c} (f : C ⟶ D) : Quot.mk _ f = (quotient V c).map f := rfl theorem eq_of_homotopy {C D : HomologicalComplex V c} (f g : C ⟶ D) (h : Homotopy f g) : (quotient V c).map f = (quotient V c).map g := CategoryTheory.Quotient.sound _ ⟨h⟩ /-- If two chain maps become equal in the homotopy category, then they are homotopic. -/ def homotopyOfEq {C D : HomologicalComplex V c} (f g : C ⟶ D) (w : (quotient V c).map f = (quotient V c).map g) : Homotopy f g := ((Quotient.functor_map_eq_iff _ _ _).mp w).some /-- An arbitrarily chosen representation of the image of a chain map in the homotopy category is homotopic to the original chain map. -/ def homotopyOutMap {C D : HomologicalComplex V c} (f : C ⟶ D) : Homotopy ((quotient V c).map f).out f := by apply homotopyOfEq simp theorem quotient_map_out_comp_out {C D E : HomotopyCategory V c} (f : C ⟶ D) (g : D ⟶ E) : (quotient V c).map (Quot.out f ≫ Quot.out g) = f ≫ g := by simp /-- Homotopy equivalent complexes become isomorphic in the homotopy category. -/ @[simps] def isoOfHomotopyEquiv {C D : HomologicalComplex V c} (f : HomotopyEquiv C D) : (quotient V c).obj C ≅ (quotient V c).obj D where hom := (quotient V c).map f.hom inv := (quotient V c).map f.inv hom_inv_id := by rw [← (quotient V c).map_comp, ← (quotient V c).map_id] exact eq_of_homotopy _ _ f.homotopyHomInvId inv_hom_id := by rw [← (quotient V c).map_comp, ← (quotient V c).map_id] exact eq_of_homotopy _ _ f.homotopyInvHomId /-- If two complexes become isomorphic in the homotopy category, then they were homotopy equivalent. -/ def homotopyEquivOfIso {C D : HomologicalComplex V c} (i : (quotient V c).obj C ≅ (quotient V c).obj D) : HomotopyEquiv C D where hom := Quot.out i.hom inv := Quot.out i.inv homotopyHomInvId := homotopyOfEq _ _ (by rw [quotient_map_out_comp_out, i.hom_inv_id, (quotient V c).map_id]) homotopyInvHomId := homotopyOfEq _ _ (by rw [quotient_map_out_comp_out, i.inv_hom_id, (quotient V c).map_id]) variable (V c) in lemma quotient_inverts_homotopyEquivalences : (HomologicalComplex.homotopyEquivalences V c).IsInvertedBy (quotient V c) := by rintro K L _ ⟨e, rfl⟩ change IsIso (isoOfHomotopyEquiv e).hom infer_instance lemma isZero_quotient_obj_iff (C : HomologicalComplex V c) : IsZero ((quotient _ _).obj C) ↔ Nonempty (Homotopy (𝟙 C) 0) := by rw [IsZero.iff_id_eq_zero] constructor · intro h exact ⟨(homotopyOfEq _ _ (by simp [h]))⟩ · rintro ⟨h⟩
simpa using (eq_of_homotopy _ _ h) variable (V c) section
Mathlib/Algebra/Homology/HomotopyCategory.lean
171
175
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Johan Commelin -/ import Mathlib.Algebra.MvPolynomial.Equiv import Mathlib.Algebra.MvPolynomial.CommRing import Mathlib.Logic.Equiv.Functor import Mathlib.RingTheory.FreeRing /-! # Free commutative rings The theory of the free commutative ring generated by a type `α`. It is isomorphic to the polynomial ring over ℤ with variables in `α` ## Main definitions * `FreeCommRing α` : the free commutative ring on a type α * `lift (f : α → R)` : the ring hom `FreeCommRing α →+* R` induced by functoriality from `f`. * `map (f : α → β)` : the ring hom `FreeCommRing α →*+ FreeCommRing β` induced by functoriality from f. ## Main results `FreeCommRing` has functorial properties (it is an adjoint to the forgetful functor). In this file we have: * `of : α → FreeCommRing α` * `lift (f : α → R) : FreeCommRing α →+* R` * `map (f : α → β) : FreeCommRing α →+* FreeCommRing β` * `freeCommRingEquivMvPolynomialInt : FreeCommRing α ≃+* MvPolynomial α ℤ` : `FreeCommRing α` is isomorphic to a polynomial ring. ## Implementation notes `FreeCommRing α` is implemented not using `MvPolynomial` but directly as the free abelian group on `Multiset α`, the type of monomials in this free commutative ring. ## Tags free commutative ring, free ring -/ noncomputable section open Polynomial universe u v variable (α : Type u) /-- If `α` is a type, then `FreeCommRing α` is the free commutative ring generated by `α`. This is a commutative ring equipped with a function `FreeCommRing.of : α → FreeCommRing α` which has the following universal property: if `R` is any commutative ring, and `f : α → R` is any function, then this function is the composite of `FreeCommRing.of` and a unique ring homomorphism `FreeCommRing.lift f : FreeCommRing α →+* R`. A typical element of `FreeCommRing α` is a `ℤ`-linear combination of formal products of elements of `α`. For example if `x` and `y` are terms of type `α` then `3 * x * x * y - 2 * x * y + 1` is a "typical" element of `FreeCommRing α`. In particular if `α` is empty then `FreeCommRing α` is isomorphic to `ℤ`, and if `α` has one term `t` then `FreeCommRing α` is isomorphic to the polynomial ring `ℤ[t]`. One can think of `FreeRing α` as the free polynomial ring with coefficients in the integers and variables indexed by `α`. -/ def FreeCommRing (α : Type u) : Type u := FreeAbelianGroup <| Multiplicative <| Multiset α -- The `CommRing, Inhabited` instances should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 instance FreeCommRing.instCommRing : CommRing (FreeCommRing α) := by delta FreeCommRing; infer_instance instance FreeCommRing.instInhabited : Inhabited (FreeCommRing α) := by delta FreeCommRing; infer_instance namespace FreeCommRing variable {α} /-- The canonical map from `α` to the free commutative ring on `α`. -/ def of (x : α) : FreeCommRing α := FreeAbelianGroup.of <| Multiplicative.ofAdd ({x} : Multiset α) theorem of_injective : Function.Injective (of : α → FreeCommRing α) := FreeAbelianGroup.of_injective.comp fun _ _ => (Multiset.coe_eq_coe.trans List.singleton_perm_singleton).mp @[simp] theorem of_ne_zero (x : α) : of x ≠ 0 := FreeAbelianGroup.of_ne_zero _ @[simp] theorem zero_ne_of (x : α) : 0 ≠ of x := FreeAbelianGroup.zero_ne_of _ @[simp] theorem of_ne_one (x : α) : of x ≠ 1 := FreeAbelianGroup.of_injective.ne <| Multiset.singleton_ne_zero _ @[simp] theorem one_ne_of (x : α) : 1 ≠ of x := FreeAbelianGroup.of_injective.ne <| Multiset.zero_ne_singleton _ -- Porting note: added to ease a proof in `Mathlib.Algebra.Colimit.Ring` lemma of_cons (a : α) (m : Multiset α) : (FreeAbelianGroup.of (Multiplicative.ofAdd (a ::ₘ m))) = @HMul.hMul _ (FreeCommRing α) (FreeCommRing α) _ (of a) (FreeAbelianGroup.of (Multiplicative.ofAdd m)) := by dsimp [FreeCommRing] rw [← Multiset.singleton_add, ofAdd_add, of, FreeAbelianGroup.of_mul_of] @[elab_as_elim, induction_eliminator] protected theorem induction_on {motive : FreeCommRing α → Prop} (z : FreeCommRing α) (neg_one : motive (-1)) (of : ∀ b, motive (of b)) (add : ∀ x y, motive x → motive y → motive (x + y)) (mul : ∀ x y, motive x → motive y → motive (x * y)) : motive z := have neg : ∀ x, motive x → motive (-x) := fun x ih => neg_one_mul x ▸ mul _ _ neg_one ih have one : motive 1 := neg_neg (1 : FreeCommRing α) ▸ neg _ neg_one FreeAbelianGroup.induction_on z (neg_add_cancel (1 : FreeCommRing α) ▸ add _ _ neg_one one) (fun m => Multiset.induction_on m one fun a m ih => by convert mul (FreeCommRing.of a) _ (of a) ih apply of_cons) (fun _ ih => neg _ ih) add section lift variable {R : Type v} [CommRing R] (f : α → R) /-- A helper to implement `lift`. This is essentially `FreeCommMonoid.lift`, but this does not currently exist. -/ private def liftToMultiset : (α → R) ≃ (Multiplicative (Multiset α) →* R) where toFun f := { toFun := fun s => (s.toAdd.map f).prod map_mul' := fun x y => calc _ = Multiset.prod (Multiset.map f x + Multiset.map f y) := by rw [← Multiset.map_add] rfl
_ = _ := Multiset.prod_add _ _ map_one' := rfl } invFun F x := F (Multiplicative.ofAdd ({x} : Multiset α)) left_inv f := funext fun x => show (Multiset.map f {x}).prod = _ by simp right_inv F := MonoidHom.ext fun x =>
Mathlib/RingTheory/FreeCommRing.lean
147
151
/- 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.Multiset.FinsetOps import Mathlib.Data.Multiset.Fold /-! # Lattice operations on multisets -/ namespace Multiset variable {α : Type*} /-! ### sup -/ section Sup -- can be defined with just `[Bot α]` where some lemmas hold without requiring `[OrderBot α]` variable [SemilatticeSup α] [OrderBot α] /-- Supremum of a multiset: `sup {a, b, c} = a ⊔ b ⊔ c` -/ def sup (s : Multiset α) : α := s.fold (· ⊔ ·) ⊥ @[simp] theorem sup_coe (l : List α) : sup (l : Multiset α) = l.foldr (· ⊔ ·) ⊥ := rfl @[simp] theorem sup_zero : (0 : Multiset α).sup = ⊥ := fold_zero _ _ @[simp] theorem sup_cons (a : α) (s : Multiset α) : (a ::ₘ s).sup = a ⊔ s.sup := fold_cons_left _ _ _ _ @[simp] theorem sup_singleton {a : α} : ({a} : Multiset α).sup = a := sup_bot_eq _ @[simp] theorem sup_add (s₁ s₂ : Multiset α) : (s₁ + s₂).sup = s₁.sup ⊔ s₂.sup := Eq.trans (by simp [sup]) (fold_add _ _ _ _ _) @[simp] theorem sup_le {s : Multiset α} {a : α} : s.sup ≤ a ↔ ∀ b ∈ s, b ≤ a := Multiset.induction_on s (by simp) (by simp +contextual [or_imp, forall_and]) theorem le_sup {s : Multiset α} {a : α} (h : a ∈ s) : a ≤ s.sup := sup_le.1 le_rfl _ h @[gcongr] theorem sup_mono {s₁ s₂ : Multiset α} (h : s₁ ⊆ s₂) : s₁.sup ≤ s₂.sup := sup_le.2 fun _ hb => le_sup (h hb) variable [DecidableEq α] @[simp] theorem sup_dedup (s : Multiset α) : (dedup s).sup = s.sup := fold_dedup_idem _ _ _ @[simp] theorem sup_ndunion (s₁ s₂ : Multiset α) : (ndunion s₁ s₂).sup = s₁.sup ⊔ s₂.sup := by rw [← sup_dedup, dedup_ext.2, sup_dedup, sup_add]; simp @[simp] theorem sup_union (s₁ s₂ : Multiset α) : (s₁ ∪ s₂).sup = s₁.sup ⊔ s₂.sup := by rw [← sup_dedup, dedup_ext.2, sup_dedup, sup_add]; simp @[simp] theorem sup_ndinsert (a : α) (s : Multiset α) : (ndinsert a s).sup = a ⊔ s.sup := by rw [← sup_dedup, dedup_ext.2, sup_dedup, sup_cons]; simp
theorem nodup_sup_iff {α : Type*} [DecidableEq α] {m : Multiset (Multiset α)} : m.sup.Nodup ↔ ∀ a : Multiset α, a ∈ m → a.Nodup := by
Mathlib/Data/Multiset/Lattice.lean
79
80
/- Copyright (c) 2020 David Wärn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Wärn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⦃X Y : C⦄, (X ⟶ Y) → (X ⟶ Y) → Prop -- The `Inhabited` instance should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↦ PUnit namespace CategoryTheory section variable {C D : Type*} [Category C] [Category D] (F : C ⥤ D) /-- A functor induces a `HomRel` on its domain, relating those maps that have the same image. -/ def Functor.homRel : HomRel C := fun _ _ f g ↦ F.map f = F.map g @[simp] lemma Functor.homRel_iff {X Y : C} (f g : X ⟶ Y) : F.homRel f g ↔ F.map f = F.map g := Iff.rfl end variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) /-- For `F : C ⥤ D`, `F.homRel` is a congruence. -/ instance Functor.congruence_homRel {C D : Type*} [Category C] [Category D] (F : C ⥤ D) : Congruence F.homRel where equivalence := { refl := fun _ ↦ rfl symm := by aesop trans := by aesop } compLeft := by aesop compRight := by aesop /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C
instance [Inhabited C] : Inhabited (Quotient r) := ⟨{ as := default }⟩
Mathlib/CategoryTheory/Quotient.lean
74
76
/- Copyright (c) 2021 Roberto Alvarez. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Roberto Alvarez -/ import Mathlib.AlgebraicTopology.FundamentalGroupoid.FundamentalGroup import Mathlib.GroupTheory.EckmannHilton import Mathlib.Algebra.Equiv.TransferInstance import Mathlib.Algebra.Group.Ext /-! # `n`th homotopy group We define the `n`th homotopy group at `x : X`, `π_n X x`, as the equivalence classes of functions from the `n`-dimensional cube to the topological space `X` that send the boundary to the base point `x`, up to homotopic equivalence. Note that such functions are generalized loops `GenLoop (Fin n) x`; in particular `GenLoop (Fin 1) x ≃ Path x x`. We show that `π_0 X x` is equivalent to the path-connected components, and that `π_1 X x` is equivalent to the fundamental group at `x`. We provide a group instance using path composition and show commutativity when `n > 1`. ## definitions * `GenLoop N x` is the type of continuous functions `I^N → X` that send the boundary to `x`, * `HomotopyGroup.Pi n X x` denoted `π_ n X x` is the quotient of `GenLoop (Fin n) x` by homotopy relative to the boundary, * group instance `Group (π_(n+1) X x)`, * commutative group instance `CommGroup (π_(n+2) X x)`. TODO: * `Ω^M (Ω^N X) ≃ₜ Ω^(M⊕N) X`, and `Ω^M X ≃ₜ Ω^N X` when `M ≃ N`. Similarly for `π_`. * Path-induced homomorphisms. Show that `HomotopyGroup.pi1EquivFundamentalGroup` is a group isomorphism. * Examples with `𝕊^n`: `π_n (𝕊^n) = ℤ`, `π_m (𝕊^n)` trivial for `m < n`. * Actions of π_1 on π_n. * Lie algebra: `⁅π_(n+1), π_(m+1)⁆` contained in `π_(n+m+1)`. -/ open scoped unitInterval Topology open Homeomorph noncomputable section /-- `I^N` is notation (in the Topology namespace) for `N → I`, i.e. the unit cube indexed by a type `N`. -/ scoped[Topology] notation "I^" N => N → I namespace Cube /-- The points in a cube with at least one projection equal to 0 or 1. -/ def boundary (N : Type*) : Set (I^N) := {y | ∃ i, y i = 0 ∨ y i = 1} variable {N : Type*} [DecidableEq N] /-- The forward direction of the homeomorphism between the cube $I^N$ and $I × I^{N\setminus\{j\}}$. -/ abbrev splitAt (i : N) : (I^N) ≃ₜ I × I^{ j // j ≠ i } := funSplitAt I i /-- The backward direction of the homeomorphism between the cube $I^N$ and $I × I^{N\setminus\{j\}}$. -/ abbrev insertAt (i : N) : (I × I^{ j // j ≠ i }) ≃ₜ I^N := (funSplitAt I i).symm theorem insertAt_boundary (i : N) {t₀ : I} {t} (H : (t₀ = 0 ∨ t₀ = 1) ∨ t ∈ boundary { j // j ≠ i }) : insertAt i ⟨t₀, t⟩ ∈ boundary N := by obtain H | ⟨j, H⟩ := H
· use i; rwa [funSplitAt_symm_apply, dif_pos rfl] · use j; rwa [funSplitAt_symm_apply, dif_neg j.prop, Subtype.coe_eta] end Cube
Mathlib/Topology/Homotopy/HomotopyGroup.lean
74
78
/- Copyright (c) 2023 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Data.Finset.Lattice.Fold /-! # Irreducible and prime elements in an order This file defines irreducible and prime elements in an order and shows that in a well-founded lattice every element decomposes as a supremum of irreducible elements. An element is sup-irreducible (resp. inf-irreducible) if it isn't `⊥` and can't be written as the supremum of any strictly smaller elements. An element is sup-prime (resp. inf-prime) if it isn't `⊥` and is greater than the supremum of any two elements less than it. Primality implies irreducibility in general. The converse only holds in distributive lattices. Both hold for all (non-minimal) elements in a linear order. ## Main declarations * `SupIrred a`: Sup-irreducibility, `a` isn't minimal and `a = b ⊔ c → a = b ∨ a = c` * `InfIrred a`: Inf-irreducibility, `a` isn't maximal and `a = b ⊓ c → a = b ∨ a = c` * `SupPrime a`: Sup-primality, `a` isn't minimal and `a ≤ b ⊔ c → a ≤ b ∨ a ≤ c` * `InfIrred a`: Inf-primality, `a` isn't maximal and `a ≥ b ⊓ c → a ≥ b ∨ a ≥ c` * `exists_supIrred_decomposition`/`exists_infIrred_decomposition`: Decomposition into irreducibles in a well-founded semilattice. -/ open Finset OrderDual variable {ι α : Type*} /-! ### Irreducible and prime elements -/ section SemilatticeSup variable [SemilatticeSup α] {a b c : α} /-- A sup-irreducible element is a non-bottom element which isn't the supremum of anything smaller. -/ def SupIrred (a : α) : Prop := ¬IsMin a ∧ ∀ ⦃b c⦄, b ⊔ c = a → b = a ∨ c = a /-- A sup-prime element is a non-bottom element which isn't less than the supremum of anything smaller. -/ def SupPrime (a : α) : Prop := ¬IsMin a ∧ ∀ ⦃b c⦄, a ≤ b ⊔ c → a ≤ b ∨ a ≤ c theorem SupIrred.not_isMin (ha : SupIrred a) : ¬IsMin a := ha.1 theorem SupPrime.not_isMin (ha : SupPrime a) : ¬IsMin a := ha.1 theorem IsMin.not_supIrred (ha : IsMin a) : ¬SupIrred a := fun h => h.1 ha theorem IsMin.not_supPrime (ha : IsMin a) : ¬SupPrime a := fun h => h.1 ha @[simp] theorem not_supIrred : ¬SupIrred a ↔ IsMin a ∨ ∃ b c, b ⊔ c = a ∧ b < a ∧ c < a := by rw [SupIrred, not_and_or] push_neg rw [exists₂_congr] simp +contextual [@eq_comm _ _ a] @[simp] theorem not_supPrime : ¬SupPrime a ↔ IsMin a ∨ ∃ b c, a ≤ b ⊔ c ∧ ¬a ≤ b ∧ ¬a ≤ c := by rw [SupPrime, not_and_or]; push_neg; rfl protected theorem SupPrime.supIrred : SupPrime a → SupIrred a := And.imp_right fun h b c ha => by simpa [← ha] using h ha.ge theorem SupPrime.le_sup (ha : SupPrime a) : a ≤ b ⊔ c ↔ a ≤ b ∨ a ≤ c := ⟨fun h => ha.2 h, fun h => h.elim le_sup_of_le_left le_sup_of_le_right⟩ variable [OrderBot α] {s : Finset ι} {f : ι → α} @[simp] theorem not_supIrred_bot : ¬SupIrred (⊥ : α) := isMin_bot.not_supIrred @[simp] theorem not_supPrime_bot : ¬SupPrime (⊥ : α) := isMin_bot.not_supPrime theorem SupIrred.ne_bot (ha : SupIrred a) : a ≠ ⊥ := by rintro rfl; exact not_supIrred_bot ha theorem SupPrime.ne_bot (ha : SupPrime a) : a ≠ ⊥ := by rintro rfl; exact not_supPrime_bot ha theorem SupIrred.finset_sup_eq (ha : SupIrred a) (h : s.sup f = a) : ∃ i ∈ s, f i = a := by classical induction' s using Finset.induction with i s _ ih · simpa [ha.ne_bot] using h.symm simp only [exists_prop, exists_mem_insert] at ih ⊢ rw [sup_insert] at h exact (ha.2 h).imp_right ih theorem SupPrime.le_finset_sup (ha : SupPrime a) : a ≤ s.sup f ↔ ∃ i ∈ s, a ≤ f i := by classical induction' s using Finset.induction with i s _ ih · simp [ha.ne_bot] · simp only [exists_prop, exists_mem_insert, sup_insert, ha.le_sup, ih] variable [WellFoundedLT α] /-- In a well-founded lattice, any element is the supremum of finitely many sup-irreducible elements. This is the order-theoretic analogue of prime factorisation. -/ theorem exists_supIrred_decomposition (a : α) : ∃ s : Finset α, s.sup id = a ∧ ∀ ⦃b⦄, b ∈ s → SupIrred b := by classical apply WellFoundedLT.induction a _ clear a rintro a ih by_cases ha : SupIrred a · exact ⟨{a}, by simp [ha]⟩ rw [not_supIrred] at ha obtain ha | ⟨b, c, rfl, hb, hc⟩ := ha · exact ⟨∅, by simp [ha.eq_bot]⟩ obtain ⟨s, rfl, hs⟩ := ih _ hb obtain ⟨t, rfl, ht⟩ := ih _ hc exact ⟨s ∪ t, sup_union, forall_mem_union.2 ⟨hs, ht⟩⟩ end SemilatticeSup section SemilatticeInf variable [SemilatticeInf α] {a b c : α} /-- An inf-irreducible element is a non-top element which isn't the infimum of anything bigger. -/ def InfIrred (a : α) : Prop := ¬IsMax a ∧ ∀ ⦃b c⦄, b ⊓ c = a → b = a ∨ c = a /-- An inf-prime element is a non-top element which isn't bigger than the infimum of anything bigger. -/ def InfPrime (a : α) : Prop := ¬IsMax a ∧ ∀ ⦃b c⦄, b ⊓ c ≤ a → b ≤ a ∨ c ≤ a @[simp] theorem IsMax.not_infIrred (ha : IsMax a) : ¬InfIrred a := fun h => h.1 ha @[simp] theorem IsMax.not_infPrime (ha : IsMax a) : ¬InfPrime a := fun h => h.1 ha @[simp] theorem not_infIrred : ¬InfIrred a ↔ IsMax a ∨ ∃ b c, b ⊓ c = a ∧ a < b ∧ a < c := @not_supIrred αᵒᵈ _ _ @[simp] theorem not_infPrime : ¬InfPrime a ↔ IsMax a ∨ ∃ b c, b ⊓ c ≤ a ∧ ¬b ≤ a ∧ ¬c ≤ a := @not_supPrime αᵒᵈ _ _ protected theorem InfPrime.infIrred : InfPrime a → InfIrred a := And.imp_right fun h b c ha => by simpa [← ha] using h ha.le theorem InfPrime.inf_le (ha : InfPrime a) : b ⊓ c ≤ a ↔ b ≤ a ∨ c ≤ a := ⟨fun h => ha.2 h, fun h => h.elim inf_le_of_left_le inf_le_of_right_le⟩ variable [OrderTop α] {s : Finset ι} {f : ι → α} theorem not_infIrred_top : ¬InfIrred (⊤ : α) := isMax_top.not_infIrred theorem not_infPrime_top : ¬InfPrime (⊤ : α) := isMax_top.not_infPrime theorem InfIrred.ne_top (ha : InfIrred a) : a ≠ ⊤ := by rintro rfl; exact not_infIrred_top ha theorem InfPrime.ne_top (ha : InfPrime a) : a ≠ ⊤ := by rintro rfl; exact not_infPrime_top ha theorem InfIrred.finset_inf_eq : InfIrred a → s.inf f = a → ∃ i ∈ s, f i = a := @SupIrred.finset_sup_eq _ αᵒᵈ _ _ _ _ _ theorem InfPrime.finset_inf_le (ha : InfPrime a) : s.inf f ≤ a ↔ ∃ i ∈ s, f i ≤ a := @SupPrime.le_finset_sup _ αᵒᵈ _ _ _ _ _ ha variable [WellFoundedGT α] /-- In a cowell-founded lattice, any element is the infimum of finitely many inf-irreducible elements. This is the order-theoretic analogue of prime factorisation. -/ theorem exists_infIrred_decomposition (a : α) : ∃ s : Finset α, s.inf id = a ∧ ∀ ⦃b⦄, b ∈ s → InfIrred b := exists_supIrred_decomposition (α := αᵒᵈ) _ end SemilatticeInf section SemilatticeSup variable [SemilatticeSup α] @[simp] theorem infIrred_toDual {a : α} : InfIrred (toDual a) ↔ SupIrred a := Iff.rfl @[simp] theorem infPrime_toDual {a : α} : InfPrime (toDual a) ↔ SupPrime a := Iff.rfl
Mathlib/Order/Irreducible.lean
201
201
/- 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
Mathlib/Analysis/SpecialFunctions/Trigonometric/Angle.lean
169
169
/- Copyright (c) 2022 Moritz Doll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Moritz Doll, Anatole Dedecker -/ import Mathlib.Analysis.LocallyConvex.Bounded import Mathlib.Analysis.Seminorm import Mathlib.Data.Real.Sqrt import Mathlib.Topology.Algebra.Equicontinuity import Mathlib.Topology.MetricSpace.Equicontinuity import Mathlib.Topology.Algebra.FilterBasis import Mathlib.Topology.Algebra.Module.LocallyConvex /-! # Topology induced by a family of seminorms ## Main definitions * `SeminormFamily.basisSets`: The set of open seminorm balls for a family of seminorms. * `SeminormFamily.moduleFilterBasis`: A module filter basis formed by the open balls. * `Seminorm.IsBounded`: A linear map `f : E →ₗ[𝕜] F` is bounded iff every seminorm in `F` can be bounded by a finite number of seminorms in `E`. ## Main statements * `WithSeminorms.toLocallyConvexSpace`: A space equipped with a family of seminorms is locally convex. * `WithSeminorms.firstCountable`: A space is first countable if it's topology is induced by a countable family of seminorms. ## Continuity of semilinear maps If `E` and `F` are topological vector space with the topology induced by a family of seminorms, then we have a direct method to prove that a linear map is continuous: * `Seminorm.continuous_from_bounded`: A bounded linear map `f : E →ₗ[𝕜] F` is continuous. If the topology of a space `E` is induced by a family of seminorms, then we can characterize von Neumann boundedness in terms of that seminorm family. Together with `LinearMap.continuous_of_locally_bounded` this gives general criterion for continuity. * `WithSeminorms.isVonNBounded_iff_finset_seminorm_bounded` * `WithSeminorms.isVonNBounded_iff_seminorm_bounded` * `WithSeminorms.image_isVonNBounded_iff_finset_seminorm_bounded` * `WithSeminorms.image_isVonNBounded_iff_seminorm_bounded` ## Tags seminorm, locally convex -/ open NormedField Set Seminorm TopologicalSpace Filter List open NNReal Pointwise Topology Uniformity variable {𝕜 𝕜₂ 𝕝 𝕝₂ E F G ι ι' : Type*} section FilterBasis variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] variable (𝕜 E ι) /-- An abbreviation for indexed families of seminorms. This is mainly to allow for dot-notation. -/ abbrev SeminormFamily := ι → Seminorm 𝕜 E variable {𝕜 E ι} namespace SeminormFamily /-- The sets of a filter basis for the neighborhood filter of 0. -/ def basisSets (p : SeminormFamily 𝕜 E ι) : Set (Set E) := ⋃ (s : Finset ι) (r) (_ : 0 < r), singleton (ball (s.sup p) (0 : E) r) variable (p : SeminormFamily 𝕜 E ι) theorem basisSets_iff {U : Set E} : U ∈ p.basisSets ↔ ∃ (i : Finset ι) (r : ℝ), 0 < r ∧ U = ball (i.sup p) 0 r := by simp only [basisSets, mem_iUnion, exists_prop, mem_singleton_iff] theorem basisSets_mem (i : Finset ι) {r : ℝ} (hr : 0 < r) : (i.sup p).ball 0 r ∈ p.basisSets := (basisSets_iff _).mpr ⟨i, _, hr, rfl⟩ theorem basisSets_singleton_mem (i : ι) {r : ℝ} (hr : 0 < r) : (p i).ball 0 r ∈ p.basisSets := (basisSets_iff _).mpr ⟨{i}, _, hr, by rw [Finset.sup_singleton]⟩ theorem basisSets_nonempty [Nonempty ι] : p.basisSets.Nonempty := by let i := Classical.arbitrary ι refine nonempty_def.mpr ⟨(p i).ball 0 1, ?_⟩ exact p.basisSets_singleton_mem i zero_lt_one theorem basisSets_intersect (U V : Set E) (hU : U ∈ p.basisSets) (hV : V ∈ p.basisSets) : ∃ z ∈ p.basisSets, z ⊆ U ∩ V := by classical rcases p.basisSets_iff.mp hU with ⟨s, r₁, hr₁, hU⟩ rcases p.basisSets_iff.mp hV with ⟨t, r₂, hr₂, hV⟩ use ((s ∪ t).sup p).ball 0 (min r₁ r₂) refine ⟨p.basisSets_mem (s ∪ t) (lt_min_iff.mpr ⟨hr₁, hr₂⟩), ?_⟩ rw [hU, hV, ball_finset_sup_eq_iInter _ _ _ (lt_min_iff.mpr ⟨hr₁, hr₂⟩), ball_finset_sup_eq_iInter _ _ _ hr₁, ball_finset_sup_eq_iInter _ _ _ hr₂] exact Set.subset_inter (Set.iInter₂_mono' fun i hi => ⟨i, Finset.subset_union_left hi, ball_mono <| min_le_left _ _⟩) (Set.iInter₂_mono' fun i hi => ⟨i, Finset.subset_union_right hi, ball_mono <| min_le_right _ _⟩) theorem basisSets_zero (U) (hU : U ∈ p.basisSets) : (0 : E) ∈ U := by rcases p.basisSets_iff.mp hU with ⟨ι', r, hr, hU⟩ rw [hU, mem_ball_zero, map_zero] exact hr theorem basisSets_add (U) (hU : U ∈ p.basisSets) : ∃ V ∈ p.basisSets, V + V ⊆ U := by rcases p.basisSets_iff.mp hU with ⟨s, r, hr, hU⟩ use (s.sup p).ball 0 (r / 2) refine ⟨p.basisSets_mem s (div_pos hr zero_lt_two), ?_⟩ refine Set.Subset.trans (ball_add_ball_subset (s.sup p) (r / 2) (r / 2) 0 0) ?_ rw [hU, add_zero, add_halves] theorem basisSets_neg (U) (hU' : U ∈ p.basisSets) : ∃ V ∈ p.basisSets, V ⊆ (fun x : E => -x) ⁻¹' U := by rcases p.basisSets_iff.mp hU' with ⟨s, r, _, hU⟩ rw [hU, neg_preimage, neg_ball (s.sup p), neg_zero] exact ⟨U, hU', Eq.subset hU⟩ /-- The `addGroupFilterBasis` induced by the filter basis `Seminorm.basisSets`. -/ protected def addGroupFilterBasis [Nonempty ι] : AddGroupFilterBasis E := addGroupFilterBasisOfComm p.basisSets p.basisSets_nonempty p.basisSets_intersect p.basisSets_zero p.basisSets_add p.basisSets_neg theorem basisSets_smul_right (v : E) (U : Set E) (hU : U ∈ p.basisSets) : ∀ᶠ x : 𝕜 in 𝓝 0, x • v ∈ U := by rcases p.basisSets_iff.mp hU with ⟨s, r, hr, hU⟩ rw [hU, Filter.eventually_iff] simp_rw [(s.sup p).mem_ball_zero, map_smul_eq_mul] by_cases h : 0 < (s.sup p) v · simp_rw [(lt_div_iff₀ h).symm] rw [← _root_.ball_zero_eq] exact Metric.ball_mem_nhds 0 (div_pos hr h) simp_rw [le_antisymm (not_lt.mp h) (apply_nonneg _ v), mul_zero, hr] exact IsOpen.mem_nhds isOpen_univ (mem_univ 0) variable [Nonempty ι] theorem basisSets_smul (U) (hU : U ∈ p.basisSets) : ∃ V ∈ 𝓝 (0 : 𝕜), ∃ W ∈ p.addGroupFilterBasis.sets, V • W ⊆ U := by rcases p.basisSets_iff.mp hU with ⟨s, r, hr, hU⟩ refine ⟨Metric.ball 0 √r, Metric.ball_mem_nhds 0 (Real.sqrt_pos.mpr hr), ?_⟩ refine ⟨(s.sup p).ball 0 √r, p.basisSets_mem s (Real.sqrt_pos.mpr hr), ?_⟩ refine Set.Subset.trans (ball_smul_ball (s.sup p) √r √r) ?_ rw [hU, Real.mul_self_sqrt (le_of_lt hr)] theorem basisSets_smul_left (x : 𝕜) (U : Set E) (hU : U ∈ p.basisSets) : ∃ V ∈ p.addGroupFilterBasis.sets, V ⊆ (fun y : E => x • y) ⁻¹' U := by rcases p.basisSets_iff.mp hU with ⟨s, r, hr, hU⟩ rw [hU] by_cases h : x ≠ 0 · rw [(s.sup p).smul_ball_preimage 0 r x h, smul_zero] use (s.sup p).ball 0 (r / ‖x‖) exact ⟨p.basisSets_mem s (div_pos hr (norm_pos_iff.mpr h)), Subset.rfl⟩ refine ⟨(s.sup p).ball 0 r, p.basisSets_mem s hr, ?_⟩ simp only [not_ne_iff.mp h, Set.subset_def, mem_ball_zero, hr, mem_univ, map_zero, imp_true_iff, preimage_const_of_mem, zero_smul] /-- The `moduleFilterBasis` induced by the filter basis `Seminorm.basisSets`. -/ protected def moduleFilterBasis : ModuleFilterBasis 𝕜 E where toAddGroupFilterBasis := p.addGroupFilterBasis smul' := p.basisSets_smul _ smul_left' := p.basisSets_smul_left smul_right' := p.basisSets_smul_right theorem filter_eq_iInf (p : SeminormFamily 𝕜 E ι) : p.moduleFilterBasis.toFilterBasis.filter = ⨅ i, (𝓝 0).comap (p i) := by refine le_antisymm (le_iInf fun i => ?_) ?_ · rw [p.moduleFilterBasis.toFilterBasis.hasBasis.le_basis_iff (Metric.nhds_basis_ball.comap _)] intro ε hε refine ⟨(p i).ball 0 ε, ?_, ?_⟩ · rw [← (Finset.sup_singleton : _ = p i)] exact p.basisSets_mem {i} hε · rw [id, (p i).ball_zero_eq_preimage_ball] · rw [p.moduleFilterBasis.toFilterBasis.hasBasis.ge_iff] rintro U (hU : U ∈ p.basisSets) rcases p.basisSets_iff.mp hU with ⟨s, r, hr, rfl⟩ rw [id, Seminorm.ball_finset_sup_eq_iInter _ _ _ hr, s.iInter_mem_sets] exact fun i _ => Filter.mem_iInf_of_mem i ⟨Metric.ball 0 r, Metric.ball_mem_nhds 0 hr, Eq.subset (p i).ball_zero_eq_preimage_ball.symm⟩ /-- If a family of seminorms is continuous, then their basis sets are neighborhoods of zero. -/ lemma basisSets_mem_nhds {𝕜 E ι : Type*} [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] (p : SeminormFamily 𝕜 E ι) (hp : ∀ i, Continuous (p i)) (U : Set E) (hU : U ∈ p.basisSets) : U ∈ 𝓝 (0 : E) := by obtain ⟨s, r, hr, rfl⟩ := p.basisSets_iff.mp hU clear hU refine Seminorm.ball_mem_nhds ?_ hr classical induction s using Finset.induction_on case empty => simpa using continuous_zero case insert a s _ hs => simp only [Finset.sup_insert, coe_sup] exact Continuous.max (hp a) hs end SeminormFamily end FilterBasis section Bounded namespace Seminorm variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] variable [NormedField 𝕜₂] [AddCommGroup F] [Module 𝕜₂ F] variable {σ₁₂ : 𝕜 →+* 𝕜₂} [RingHomIsometric σ₁₂] -- Todo: This should be phrased entirely in terms of the von Neumann bornology. /-- The proposition that a linear map is bounded between spaces with families of seminorms. -/ def IsBounded (p : ι → Seminorm 𝕜 E) (q : ι' → Seminorm 𝕜₂ F) (f : E →ₛₗ[σ₁₂] F) : Prop := ∀ i, ∃ s : Finset ι, ∃ C : ℝ≥0, (q i).comp f ≤ C • s.sup p theorem isBounded_const (ι' : Type*) [Nonempty ι'] {p : ι → Seminorm 𝕜 E} {q : Seminorm 𝕜₂ F} (f : E →ₛₗ[σ₁₂] F) : IsBounded p (fun _ : ι' => q) f ↔ ∃ (s : Finset ι) (C : ℝ≥0), q.comp f ≤ C • s.sup p := by simp only [IsBounded, forall_const] theorem const_isBounded (ι : Type*) [Nonempty ι] {p : Seminorm 𝕜 E} {q : ι' → Seminorm 𝕜₂ F} (f : E →ₛₗ[σ₁₂] F) : IsBounded (fun _ : ι => p) q f ↔ ∀ i, ∃ C : ℝ≥0, (q i).comp f ≤ C • p := by constructor <;> intro h i · rcases h i with ⟨s, C, h⟩ exact ⟨C, le_trans h (smul_le_smul (Finset.sup_le fun _ _ => le_rfl) le_rfl)⟩ use {Classical.arbitrary ι} simp only [h, Finset.sup_singleton] theorem isBounded_sup {p : ι → Seminorm 𝕜 E} {q : ι' → Seminorm 𝕜₂ F} {f : E →ₛₗ[σ₁₂] F} (hf : IsBounded p q f) (s' : Finset ι') : ∃ (C : ℝ≥0) (s : Finset ι), (s'.sup q).comp f ≤ C • s.sup p := by classical obtain rfl | _ := s'.eq_empty_or_nonempty · exact ⟨1, ∅, by simp [Seminorm.bot_eq_zero]⟩ choose fₛ fC hf using hf use s'.card • s'.sup fC, Finset.biUnion s' fₛ have hs : ∀ i : ι', i ∈ s' → (q i).comp f ≤ s'.sup fC • (Finset.biUnion s' fₛ).sup p := by intro i hi refine (hf i).trans (smul_le_smul ?_ (Finset.le_sup hi)) exact Finset.sup_mono (Finset.subset_biUnion_of_mem fₛ hi) refine (comp_mono f (finset_sup_le_sum q s')).trans ?_ simp_rw [← pullback_apply, map_sum, pullback_apply] refine (Finset.sum_le_sum hs).trans ?_ rw [Finset.sum_const, smul_assoc] end Seminorm end Bounded section Topology variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] [Nonempty ι] /-- The proposition that the topology of `E` is induced by a family of seminorms `p`. -/ structure WithSeminorms (p : SeminormFamily 𝕜 E ι) [topology : TopologicalSpace E] : Prop where topology_eq_withSeminorms : topology = p.moduleFilterBasis.topology theorem WithSeminorms.withSeminorms_eq {p : SeminormFamily 𝕜 E ι} [t : TopologicalSpace E] (hp : WithSeminorms p) : t = p.moduleFilterBasis.topology := hp.1 variable [TopologicalSpace E] variable {p : SeminormFamily 𝕜 E ι} theorem WithSeminorms.topologicalAddGroup (hp : WithSeminorms p) : IsTopologicalAddGroup E := by rw [hp.withSeminorms_eq] exact AddGroupFilterBasis.isTopologicalAddGroup _ theorem WithSeminorms.continuousSMul (hp : WithSeminorms p) : ContinuousSMul 𝕜 E := by rw [hp.withSeminorms_eq] exact ModuleFilterBasis.continuousSMul _ theorem WithSeminorms.hasBasis (hp : WithSeminorms p) : (𝓝 (0 : E)).HasBasis (fun s : Set E => s ∈ p.basisSets) id := by rw [congr_fun (congr_arg (@nhds E) hp.1) 0] exact AddGroupFilterBasis.nhds_zero_hasBasis _ theorem WithSeminorms.hasBasis_zero_ball (hp : WithSeminorms p) : (𝓝 (0 : E)).HasBasis (fun sr : Finset ι × ℝ => 0 < sr.2) fun sr => (sr.1.sup p).ball 0 sr.2 := by refine ⟨fun V => ?_⟩ simp only [hp.hasBasis.mem_iff, SeminormFamily.basisSets_iff, Prod.exists] constructor · rintro ⟨-, ⟨s, r, hr, rfl⟩, hV⟩ exact ⟨s, r, hr, hV⟩ · rintro ⟨s, r, hr, hV⟩ exact ⟨_, ⟨s, r, hr, rfl⟩, hV⟩ theorem WithSeminorms.hasBasis_ball (hp : WithSeminorms p) {x : E} : (𝓝 (x : E)).HasBasis (fun sr : Finset ι × ℝ => 0 < sr.2) fun sr => (sr.1.sup p).ball x sr.2 := by have : IsTopologicalAddGroup E := hp.topologicalAddGroup rw [← map_add_left_nhds_zero] convert hp.hasBasis_zero_ball.map (x + ·) using 1 ext sr : 1 -- Porting note: extra type ascriptions needed on `0` have : (sr.fst.sup p).ball (x +ᵥ (0 : E)) sr.snd = x +ᵥ (sr.fst.sup p).ball 0 sr.snd := Eq.symm (Seminorm.vadd_ball (sr.fst.sup p)) rwa [vadd_eq_add, add_zero] at this /-- The `x`-neighbourhoods of a space whose topology is induced by a family of seminorms are exactly the sets which contain seminorm balls around `x`. -/ theorem WithSeminorms.mem_nhds_iff (hp : WithSeminorms p) (x : E) (U : Set E) : U ∈ 𝓝 x ↔ ∃ s : Finset ι, ∃ r > 0, (s.sup p).ball x r ⊆ U := by rw [hp.hasBasis_ball.mem_iff, Prod.exists] /-- The open sets of a space whose topology is induced by a family of seminorms are exactly the sets which contain seminorm balls around all of their points. -/ theorem WithSeminorms.isOpen_iff_mem_balls (hp : WithSeminorms p) (U : Set E) : IsOpen U ↔ ∀ x ∈ U, ∃ s : Finset ι, ∃ r > 0, (s.sup p).ball x r ⊆ U := by simp_rw [← WithSeminorms.mem_nhds_iff hp _ U, isOpen_iff_mem_nhds] /- Note that through the following lemmas, one also immediately has that separating families of seminorms induce T₂ and T₃ topologies by `IsTopologicalAddGroup.t2Space` and `IsTopologicalAddGroup.t3Space` -/ /-- A separating family of seminorms induces a T₁ topology. -/ theorem WithSeminorms.T1_of_separating (hp : WithSeminorms p) (h : ∀ x, x ≠ 0 → ∃ i, p i x ≠ 0) : T1Space E := by have := hp.topologicalAddGroup refine IsTopologicalAddGroup.t1Space _ ?_ rw [← isOpen_compl_iff, hp.isOpen_iff_mem_balls] rintro x (hx : x ≠ 0) obtain ⟨i, pi_nonzero⟩ := h x hx refine ⟨{i}, p i x, by positivity, subset_compl_singleton_iff.mpr ?_⟩ rw [Finset.sup_singleton, mem_ball, zero_sub, map_neg_eq_map, not_lt] /-- A family of seminorms inducing a T₁ topology is separating. -/ theorem WithSeminorms.separating_of_T1 [T1Space E] (hp : WithSeminorms p) (x : E) (hx : x ≠ 0) : ∃ i, p i x ≠ 0 := by have := ((t1Space_TFAE E).out 0 9).mp (inferInstanceAs <| T1Space E) by_contra! h refine hx (this ?_) rw [hp.hasBasis_zero_ball.specializes_iff] rintro ⟨s, r⟩ (hr : 0 < r) simp only [ball_finset_sup_eq_iInter _ _ _ hr, mem_iInter₂, mem_ball_zero, h, hr, forall_true_iff] /-- A family of seminorms is separating iff it induces a T₁ topology. -/ theorem WithSeminorms.separating_iff_T1 (hp : WithSeminorms p) : (∀ x, x ≠ 0 → ∃ i, p i x ≠ 0) ↔ T1Space E := by refine ⟨WithSeminorms.T1_of_separating hp, ?_⟩ intro exact WithSeminorms.separating_of_T1 hp end Topology section Tendsto variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] [Nonempty ι] [TopologicalSpace E] variable {p : SeminormFamily 𝕜 E ι} /-- Convergence along filters for `WithSeminorms`. Variant with `Finset.sup`. -/ theorem WithSeminorms.tendsto_nhds' (hp : WithSeminorms p) (u : F → E) {f : Filter F} (y₀ : E) : Filter.Tendsto u f (𝓝 y₀) ↔ ∀ (s : Finset ι) (ε), 0 < ε → ∀ᶠ x in f, s.sup p (u x - y₀) < ε := by simp [hp.hasBasis_ball.tendsto_right_iff] /-- Convergence along filters for `WithSeminorms`. -/ theorem WithSeminorms.tendsto_nhds (hp : WithSeminorms p) (u : F → E) {f : Filter F} (y₀ : E) : Filter.Tendsto u f (𝓝 y₀) ↔ ∀ i ε, 0 < ε → ∀ᶠ x in f, p i (u x - y₀) < ε := by rw [hp.tendsto_nhds' u y₀] exact ⟨fun h i => by simpa only [Finset.sup_singleton] using h {i}, fun h s ε hε => (s.eventually_all.2 fun i _ => h i ε hε).mono fun _ => finset_sup_apply_lt hε⟩ variable [SemilatticeSup F] [Nonempty F] /-- Limit `→ ∞` for `WithSeminorms`. -/ theorem WithSeminorms.tendsto_nhds_atTop (hp : WithSeminorms p) (u : F → E) (y₀ : E) : Filter.Tendsto u Filter.atTop (𝓝 y₀) ↔ ∀ i ε, 0 < ε → ∃ x₀, ∀ x, x₀ ≤ x → p i (u x - y₀) < ε := by rw [hp.tendsto_nhds u y₀] exact forall₃_congr fun _ _ _ => Filter.eventually_atTop end Tendsto section IsTopologicalAddGroup
variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] variable [Nonempty ι] section TopologicalSpace variable [t : TopologicalSpace E]
Mathlib/Analysis/LocallyConvex/WithSeminorms.lean
387
392
/- Copyright (c) 2022 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.NumberTheory.BernoulliPolynomials import Mathlib.MeasureTheory.Integral.IntervalIntegral.Basic import Mathlib.Analysis.Calculus.Deriv.Polynomial import Mathlib.Analysis.Fourier.AddCircle import Mathlib.Analysis.PSeries /-! # Critical values of the Riemann zeta function In this file we prove formulae for the critical values of `ζ(s)`, and more generally of Hurwitz zeta functions, in terms of Bernoulli polynomials. ## Main results: * `hasSum_zeta_nat`: the final formula for zeta values, $$\zeta(2k) = \frac{(-1)^{(k + 1)} 2 ^ {2k - 1} \pi^{2k} B_{2 k}}{(2 k)!}.$$ * `hasSum_zeta_two` and `hasSum_zeta_four`: special cases given explicitly. * `hasSum_one_div_nat_pow_mul_cos`: a formula for the sum `∑ (n : ℕ), cos (2 π i n x) / n ^ k` as an explicit multiple of `Bₖ(x)`, for any `x ∈ [0, 1]` and `k ≥ 2` even. * `hasSum_one_div_nat_pow_mul_sin`: a formula for the sum `∑ (n : ℕ), sin (2 π i n x) / n ^ k` as an explicit multiple of `Bₖ(x)`, for any `x ∈ [0, 1]` and `k ≥ 3` odd. -/ noncomputable section open scoped Nat Real Interval open Complex MeasureTheory Set intervalIntegral local notation "𝕌" => UnitAddCircle section BernoulliFunProps /-! Simple properties of the Bernoulli polynomial, as a function `ℝ → ℝ`. -/ /-- The function `x ↦ Bₖ(x) : ℝ → ℝ`. -/ def bernoulliFun (k : ℕ) (x : ℝ) : ℝ := (Polynomial.map (algebraMap ℚ ℝ) (Polynomial.bernoulli k)).eval x theorem bernoulliFun_eval_zero (k : ℕ) : bernoulliFun k 0 = bernoulli k := by rw [bernoulliFun, Polynomial.eval_zero_map, Polynomial.bernoulli_eval_zero, eq_ratCast] theorem bernoulliFun_endpoints_eq_of_ne_one {k : ℕ} (hk : k ≠ 1) : bernoulliFun k 1 = bernoulliFun k 0 := by rw [bernoulliFun_eval_zero, bernoulliFun, Polynomial.eval_one_map, Polynomial.bernoulli_eval_one, bernoulli_eq_bernoulli'_of_ne_one hk, eq_ratCast] theorem bernoulliFun_eval_one (k : ℕ) : bernoulliFun k 1 = bernoulliFun k 0 + ite (k = 1) 1 0 := by rw [bernoulliFun, bernoulliFun_eval_zero, Polynomial.eval_one_map, Polynomial.bernoulli_eval_one] split_ifs with h · rw [h, bernoulli_one, bernoulli'_one, eq_ratCast] push_cast; ring · rw [bernoulli_eq_bernoulli'_of_ne_one h, add_zero, eq_ratCast] theorem hasDerivAt_bernoulliFun (k : ℕ) (x : ℝ) : HasDerivAt (bernoulliFun k) (k * bernoulliFun (k - 1) x) x := by convert ((Polynomial.bernoulli k).map <| algebraMap ℚ ℝ).hasDerivAt x using 1 simp only [bernoulliFun, Polynomial.derivative_map, Polynomial.derivative_bernoulli k, Polynomial.map_mul, Polynomial.map_natCast, Polynomial.eval_mul, Polynomial.eval_natCast] theorem antideriv_bernoulliFun (k : ℕ) (x : ℝ) : HasDerivAt (fun x => bernoulliFun (k + 1) x / (k + 1)) (bernoulliFun k x) x := by convert (hasDerivAt_bernoulliFun (k + 1) x).div_const _ using 1 field_simp [Nat.cast_add_one_ne_zero k] theorem integral_bernoulliFun_eq_zero {k : ℕ} (hk : k ≠ 0) : ∫ x : ℝ in (0)..1, bernoulliFun k x = 0 := by rw [integral_eq_sub_of_hasDerivAt (fun x _ => antideriv_bernoulliFun k x) ((Polynomial.continuous _).intervalIntegrable _ _)] rw [bernoulliFun_eval_one] split_ifs with h · exfalso; exact hk (Nat.succ_inj.mp h) · simp end BernoulliFunProps section BernoulliFourierCoeffs /-! Compute the Fourier coefficients of the Bernoulli functions via integration by parts. -/ /-- The `n`-th Fourier coefficient of the `k`-th Bernoulli function on the interval `[0, 1]`. -/ def bernoulliFourierCoeff (k : ℕ) (n : ℤ) : ℂ := fourierCoeffOn zero_lt_one (fun x => bernoulliFun k x) n /-- Recurrence relation (in `k`) for the `n`-th Fourier coefficient of `Bₖ`. -/ theorem bernoulliFourierCoeff_recurrence (k : ℕ) {n : ℤ} (hn : n ≠ 0) : bernoulliFourierCoeff k n = 1 / (-2 * π * I * n) * (ite (k = 1) 1 0 - k * bernoulliFourierCoeff (k - 1) n) := by unfold bernoulliFourierCoeff rw [fourierCoeffOn_of_hasDerivAt zero_lt_one hn (fun x _ => (hasDerivAt_bernoulliFun k x).ofReal_comp) ((continuous_ofReal.comp <| continuous_const.mul <| Polynomial.continuous _).intervalIntegrable _ _)] simp_rw [ofReal_one, ofReal_zero, sub_zero, one_mul] rw [QuotientAddGroup.mk_zero, fourier_eval_zero, one_mul, ← ofReal_sub, bernoulliFun_eval_one, add_sub_cancel_left] congr 2 · split_ifs <;> simp only [ofReal_one, ofReal_zero, one_mul] · simp_rw [ofReal_mul, ofReal_natCast, fourierCoeffOn.const_mul] /-- The Fourier coefficients of `B₀(x) = 1`. -/ theorem bernoulli_zero_fourier_coeff {n : ℤ} (hn : n ≠ 0) : bernoulliFourierCoeff 0 n = 0 := by simpa using bernoulliFourierCoeff_recurrence 0 hn /-- The `0`-th Fourier coefficient of `Bₖ(x)`. -/ theorem bernoulliFourierCoeff_zero {k : ℕ} (hk : k ≠ 0) : bernoulliFourierCoeff k 0 = 0 := by simp_rw [bernoulliFourierCoeff, fourierCoeffOn_eq_integral, neg_zero, fourier_zero, sub_zero, div_one, one_smul, intervalIntegral.integral_ofReal, integral_bernoulliFun_eq_zero hk, ofReal_zero] theorem bernoulliFourierCoeff_eq {k : ℕ} (hk : k ≠ 0) (n : ℤ) : bernoulliFourierCoeff k n = -k ! / (2 * π * I * n) ^ k := by rcases eq_or_ne n 0 with (rfl | hn) · rw [bernoulliFourierCoeff_zero hk, Int.cast_zero, mul_zero, zero_pow hk, div_zero] refine Nat.le_induction ?_ (fun k hk h'k => ?_) k (Nat.one_le_iff_ne_zero.mpr hk) · rw [bernoulliFourierCoeff_recurrence 1 hn] simp only [Nat.cast_one, tsub_self, neg_mul, one_mul, eq_self_iff_true, if_true, Nat.factorial_one, pow_one, inv_I, mul_neg] rw [bernoulli_zero_fourier_coeff hn, sub_zero, mul_one, div_neg, neg_div] · rw [bernoulliFourierCoeff_recurrence (k + 1) hn, Nat.add_sub_cancel k 1] split_ifs with h · exfalso; exact (ne_of_gt (Nat.lt_succ_iff.mpr hk)) h · rw [h'k, Nat.factorial_succ, zero_sub, Nat.cast_mul, pow_add, pow_one, neg_div, mul_neg, mul_neg, mul_neg, neg_neg, neg_mul, neg_mul, neg_mul, div_neg] field_simp [Int.cast_ne_zero.mpr hn, I_ne_zero] ring_nf end BernoulliFourierCoeffs section BernoulliPeriodized /-! In this section we use the above evaluations of the Fourier coefficients of Bernoulli polynomials, together with the theorem `has_pointwise_sum_fourier_series_of_summable` from Fourier theory, to obtain an explicit formula for `∑ (n:ℤ), 1 / n ^ k * fourier n x`. -/ /-- The Bernoulli polynomial, extended from `[0, 1)` to the unit circle. -/ def periodizedBernoulli (k : ℕ) : 𝕌 → ℝ := AddCircle.liftIco 1 0 (bernoulliFun k) theorem periodizedBernoulli.continuous {k : ℕ} (hk : k ≠ 1) : Continuous (periodizedBernoulli k) := AddCircle.liftIco_zero_continuous (mod_cast (bernoulliFun_endpoints_eq_of_ne_one hk).symm) (Polynomial.continuous _).continuousOn theorem fourierCoeff_bernoulli_eq {k : ℕ} (hk : k ≠ 0) (n : ℤ) : fourierCoeff ((↑) ∘ periodizedBernoulli k : 𝕌 → ℂ) n = -k ! / (2 * π * I * n) ^ k := by have : ((↑) ∘ periodizedBernoulli k : 𝕌 → ℂ) = AddCircle.liftIco 1 0 ((↑) ∘ bernoulliFun k) := by ext1 x; rfl rw [this, fourierCoeff_liftIco_eq] simpa only [zero_add] using bernoulliFourierCoeff_eq hk n theorem summable_bernoulli_fourier {k : ℕ} (hk : 2 ≤ k) : Summable (fun n => -k ! / (2 * π * I * n) ^ k : ℤ → ℂ) := by have : ∀ n : ℤ, -(k ! : ℂ) / (2 * π * I * n) ^ k = -k ! / (2 * π * I) ^ k * (1 / (n : ℂ) ^ k) := by intro n; rw [mul_one_div, div_div, ← mul_pow] simp_rw [this] refine Summable.mul_left _ <| .of_norm ?_ have : (fun x : ℤ => ‖1 / (x : ℂ) ^ k‖) = fun x : ℤ => |1 / (x : ℝ) ^ k| := by ext1 x simp only [one_div, norm_inv, norm_pow, norm_intCast, pow_abs, abs_inv] simp_rw [this] rwa [summable_abs_iff, Real.summable_one_div_int_pow] theorem hasSum_one_div_pow_mul_fourier_mul_bernoulliFun {k : ℕ} (hk : 2 ≤ k) {x : ℝ} (hx : x ∈ Icc (0 : ℝ) 1) : HasSum (fun n : ℤ => 1 / (n : ℂ) ^ k * fourier n (x : 𝕌)) (-(2 * π * I) ^ k / k ! * bernoulliFun k x) := by -- first show it suffices to prove result for `Ico 0 1` suffices ∀ {y : ℝ}, y ∈ Ico (0 : ℝ) 1 → HasSum (fun (n : ℤ) ↦ 1 / (n : ℂ) ^ k * fourier n y) (-(2 * (π : ℂ) * I) ^ k / k ! * bernoulliFun k y) by rw [← Ico_insert_right (zero_le_one' ℝ), mem_insert_iff, or_comm] at hx rcases hx with (hx | rfl) · exact this hx · convert this (left_mem_Ico.mpr zero_lt_one) using 1 · rw [AddCircle.coe_period, QuotientAddGroup.mk_zero] · rw [bernoulliFun_endpoints_eq_of_ne_one (by omega : k ≠ 1)] intro y hy let B : C(𝕌, ℂ) := ContinuousMap.mk ((↑) ∘ periodizedBernoulli k) (continuous_ofReal.comp (periodizedBernoulli.continuous (by omega))) have step1 : ∀ n : ℤ, fourierCoeff B n = -k ! / (2 * π * I * n) ^ k := by rw [ContinuousMap.coe_mk]; exact fourierCoeff_bernoulli_eq (by omega : k ≠ 0) have step2 := has_pointwise_sum_fourier_series_of_summable ((summable_bernoulli_fourier hk).congr fun n => (step1 n).symm) y simp_rw [step1] at step2 convert step2.mul_left (-(2 * ↑π * I) ^ k / (k ! : ℂ)) using 2 with n · rw [smul_eq_mul, ← mul_assoc, mul_div, mul_neg, div_mul_cancel₀, neg_neg, mul_pow _ (n : ℂ), ← div_div, div_self] · rw [Ne, pow_eq_zero_iff', not_and_or] exact Or.inl two_pi_I_ne_zero · exact Nat.cast_ne_zero.mpr (Nat.factorial_ne_zero _) · rw [ContinuousMap.coe_mk, Function.comp_apply, ofReal_inj, periodizedBernoulli, AddCircle.liftIco_coe_apply (show y ∈ Ico 0 (0 + 1) by rwa [zero_add])] end BernoulliPeriodized section Cleanup -- This section is just reformulating the results in a nicer form. theorem hasSum_one_div_nat_pow_mul_fourier {k : ℕ} (hk : 2 ≤ k) {x : ℝ} (hx : x ∈ Icc (0 : ℝ) 1) : HasSum (fun n : ℕ => (1 : ℂ) / (n : ℂ) ^ k * (fourier n (x : 𝕌) + (-1 : ℂ) ^ k * fourier (-n) (x : 𝕌))) (-(2 * π * I) ^ k / k ! * bernoulliFun k x) := by convert (hasSum_one_div_pow_mul_fourier_mul_bernoulliFun hk hx).nat_add_neg using 1 · ext1 n rw [Int.cast_neg, mul_add, ← mul_assoc] conv_rhs => rw [neg_eq_neg_one_mul, mul_pow, ← div_div] congr 2 rw [div_mul_eq_mul_div₀, one_mul] congr 1 rw [eq_div_iff, ← mul_pow, ← neg_eq_neg_one_mul, neg_neg, one_pow] apply pow_ne_zero; rw [neg_ne_zero]; exact one_ne_zero · rw [Int.cast_zero, zero_pow (by positivity : k ≠ 0), div_zero, zero_mul, add_zero] theorem hasSum_one_div_nat_pow_mul_cos {k : ℕ} (hk : k ≠ 0) {x : ℝ} (hx : x ∈ Icc (0 : ℝ) 1) : HasSum (fun n : ℕ => 1 / (n : ℝ) ^ (2 * k) * Real.cos (2 * π * n * x)) ((-1 : ℝ) ^ (k + 1) * (2 * π) ^ (2 * k) / 2 / (2 * k)! * (Polynomial.map (algebraMap ℚ ℝ) (Polynomial.bernoulli (2 * k))).eval x) := by have : HasSum (fun n : ℕ => 1 / (n : ℂ) ^ (2 * k) * (fourier n (x : 𝕌) + fourier (-n) (x : 𝕌))) ((-1 : ℂ) ^ (k + 1) * (2 * (π : ℂ)) ^ (2 * k) / (2 * k)! * bernoulliFun (2 * k) x) := by convert hasSum_one_div_nat_pow_mul_fourier (by omega : 2 ≤ 2 * k) hx using 3 · rw [pow_mul (-1 : ℂ), neg_one_sq, one_pow, one_mul] · rw [pow_add, pow_one] conv_rhs => rw [mul_pow] congr congr · skip · rw [pow_mul, I_sq] ring have ofReal_two : ((2 : ℝ) : ℂ) = 2 := by norm_cast convert ((hasSum_iff _ _).mp (this.div_const 2)).1 with n · convert (ofReal_re _).symm rw [ofReal_mul]; rw [← mul_div]; congr · rw [ofReal_div, ofReal_one, ofReal_pow]; rfl · rw [ofReal_cos, ofReal_mul, fourier_coe_apply, fourier_coe_apply, cos, ofReal_one, div_one, div_one, ofReal_mul, ofReal_mul, ofReal_two, Int.cast_neg, Int.cast_natCast, ofReal_natCast] congr 3 · ring · ring · convert (ofReal_re _).symm rw [ofReal_mul, ofReal_div, ofReal_div, ofReal_mul, ofReal_pow, ofReal_pow, ofReal_neg, ofReal_natCast, ofReal_mul, ofReal_two, ofReal_one] rw [bernoulliFun] ring theorem hasSum_one_div_nat_pow_mul_sin {k : ℕ} (hk : k ≠ 0) {x : ℝ} (hx : x ∈ Icc (0 : ℝ) 1) : HasSum (fun n : ℕ => 1 / (n : ℝ) ^ (2 * k + 1) * Real.sin (2 * π * n * x)) ((-1 : ℝ) ^ (k + 1) * (2 * π) ^ (2 * k + 1) / 2 / (2 * k + 1)! * (Polynomial.map (algebraMap ℚ ℝ) (Polynomial.bernoulli (2 * k + 1))).eval x) := by have : HasSum (fun n : ℕ => 1 / (n : ℂ) ^ (2 * k + 1) * (fourier n (x : 𝕌) - fourier (-n) (x : 𝕌))) ((-1 : ℂ) ^ (k + 1) * I * (2 * π : ℂ) ^ (2 * k + 1) / (2 * k + 1)! * bernoulliFun (2 * k + 1) x) := by convert hasSum_one_div_nat_pow_mul_fourier (by omega : 2 ≤ 2 * k + 1) hx using 1 · ext1 n rw [pow_add (-1 : ℂ), pow_mul (-1 : ℂ), neg_one_sq, one_pow, one_mul, pow_one, ← neg_eq_neg_one_mul, ← sub_eq_add_neg] · congr rw [pow_add, pow_one] conv_rhs => rw [mul_pow] congr congr · skip · rw [pow_add, pow_one, pow_mul, I_sq] ring have ofReal_two : ((2 : ℝ) : ℂ) = 2 := by norm_cast convert ((hasSum_iff _ _).mp (this.div_const (2 * I))).1 · convert (ofReal_re _).symm rw [ofReal_mul]; rw [← mul_div]; congr · rw [ofReal_div, ofReal_one, ofReal_pow]; rfl · rw [ofReal_sin, ofReal_mul, fourier_coe_apply, fourier_coe_apply, sin, ofReal_one, div_one, div_one, ofReal_mul, ofReal_mul, ofReal_two, Int.cast_neg, Int.cast_natCast, ofReal_natCast, ← div_div, div_I, div_mul_eq_mul_div₀, ← neg_div, ← neg_mul, neg_sub] congr 4 · ring · ring · convert (ofReal_re _).symm rw [ofReal_mul, ofReal_div, ofReal_div, ofReal_mul, ofReal_pow, ofReal_pow, ofReal_neg, ofReal_natCast, ofReal_mul, ofReal_two, ofReal_one, ← div_div, div_I, div_mul_eq_mul_div₀] have : ∀ α β γ δ : ℂ, α * I * β / γ * δ * I = I ^ 2 * α * β / γ * δ := by intros; ring rw [this, I_sq] rw [bernoulliFun] ring theorem hasSum_zeta_nat {k : ℕ} (hk : k ≠ 0) : HasSum (fun n : ℕ => 1 / (n : ℝ) ^ (2 * k)) ((-1 : ℝ) ^ (k + 1) * (2 : ℝ) ^ (2 * k - 1) * π ^ (2 * k) * bernoulli (2 * k) / (2 * k)!) := by convert hasSum_one_div_nat_pow_mul_cos hk (left_mem_Icc.mpr zero_le_one) using 1 · ext1 n; rw [mul_zero, Real.cos_zero, mul_one] rw [Polynomial.eval_zero_map, Polynomial.bernoulli_eval_zero, eq_ratCast] have : (2 : ℝ) ^ (2 * k - 1) = (2 : ℝ) ^ (2 * k) / 2 := by rw [eq_div_iff (two_ne_zero' ℝ)] conv_lhs => congr · skip · rw [← pow_one (2 : ℝ)] rw [← pow_add, Nat.sub_add_cancel] omega rw [this, mul_pow] ring end Cleanup section Examples theorem hasSum_zeta_two : HasSum (fun n : ℕ => (1 : ℝ) / (n : ℝ) ^ 2) (π ^ 2 / 6) := by convert hasSum_zeta_nat one_ne_zero using 1; rw [mul_one] rw [bernoulli_eq_bernoulli'_of_ne_one (by decide : 2 ≠ 1), bernoulli'_two] norm_num [Nat.factorial]; field_simp; ring theorem hasSum_zeta_four : HasSum (fun n : ℕ => (1 : ℝ) / (n : ℝ) ^ 4) (π ^ 4 / 90) := by convert hasSum_zeta_nat two_ne_zero using 1; norm_num rw [bernoulli_eq_bernoulli'_of_ne_one, bernoulli'_four] · norm_num [Nat.factorial]; field_simp; ring · decide theorem Polynomial.bernoulli_three_eval_one_quarter : (Polynomial.bernoulli 3).eval (1 / 4) = 3 / 64 := by simp_rw [Polynomial.bernoulli, Finset.sum_range_succ, Polynomial.eval_add, Polynomial.eval_monomial] rw [Finset.sum_range_zero, Polynomial.eval_zero, zero_add, bernoulli_one] rw [bernoulli_eq_bernoulli'_of_ne_one zero_ne_one, bernoulli'_zero, bernoulli_eq_bernoulli'_of_ne_one (by decide : 2 ≠ 1), bernoulli'_two, bernoulli_eq_bernoulli'_of_ne_one (by decide : 3 ≠ 1), bernoulli'_three] norm_num /-- Explicit formula for `L(χ, 3)`, where `χ` is the unique nontrivial Dirichlet character modulo 4. -/ theorem hasSum_L_function_mod_four_eval_three : HasSum (fun n : ℕ => (1 : ℝ) / (n : ℝ) ^ 3 * Real.sin (π * n / 2)) (π ^ 3 / 32) := by apply (congr_arg₂ HasSum ?_ ?_).to_iff.mp <| hasSum_one_div_nat_pow_mul_sin one_ne_zero (?_ : 1 / 4 ∈ Icc (0 : ℝ) 1) · ext1 n norm_num left congr 1 ring · have : (1 / 4 : ℝ) = (algebraMap ℚ ℝ) (1 / 4 : ℚ) := by norm_num rw [this, mul_pow, Polynomial.eval_map, Polynomial.eval₂_at_apply, (by decide : 2 * 1 + 1 = 3), Polynomial.bernoulli_three_eval_one_quarter] norm_num [Nat.factorial]; field_simp; ring · rw [mem_Icc]; constructor · linarith · linarith end Examples
Mathlib/NumberTheory/ZetaValues.lean
381
398
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Normed.Group.AddTorsor import Mathlib.Analysis.Normed.Module.Convex import Mathlib.Analysis.RCLike.Basic import Mathlib.Topology.Instances.RealVectorSpace import Mathlib.Topology.LocallyConstant.Basic /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `RCLike`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≤ B x` or `‖f x‖ ≤ B x` from upper estimates on `f'` or `‖f'‖`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `‖f x‖ = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `‖f x - f a‖ ≤ C * ‖x - a‖`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≤ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≤ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ → ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≤ f' x` (hf' : ∀ x ∈ Ico a b, ∀ r, f' x < r → ∃ᶠ z in 𝓝[>] x, slope f x z < r) {B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ContinuousOn B (Icc a b)) (hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x := by change Icc a b ⊆ { x | f x ≤ B x } set s := { x | f x ≤ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prodMk hB have : IsClosed s := by simp only [s, inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≤ B x, xab⟩ y hy rcases hxB.lt_or_eq with hxB | hxB · -- If `f x < B x`, then all we need is continuity of both sides refine nonempty_of_mem (inter_mem ?_ (Ioc_mem_nhdsGT hy)) have : ∀ᶠ x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : ∀ᶠ x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsGT_of_mem xab) this exact this.mono fun y => le_of_lt · rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : ∀ᶠ z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : ∃ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y := hf'.and_eventually (HB.and (Ioc_mem_nhdsGT hy)) |>.exists refine ⟨z, ?_, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_iff_of_pos_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≤ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≤ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ → ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≤ f' x` (hf' : ∀ x ∈ Ico a b, ∀ r, f' x < r → ∃ᶠ z in 𝓝[>] x, slope f x z < r) {B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ∀ x, HasDerivAt B (B' x) x) (bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≤ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≤ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ → ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ContinuousOn B (Icc a b)) (hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≤ B' x` (bound : ∀ x ∈ Ico a b, ∀ r, B' x < r → ∃ᶠ z in 𝓝[>] x, slope f x z < r) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x := by have Hr : ∀ x ∈ Icc a b, ∀ r > 0, f x ≤ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound · rwa [sub_self, mul_zero, add_zero] · exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) · intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) · intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≤ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≤ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ → ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ContinuousOn B (Icc a b)) (hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≤ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≤ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ → ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ∀ x, HasDerivAt B (B' x) x) (bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≤ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≤ B' x` on `[a, b)`. Then `f x ≤ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ → ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ContinuousOn B (Icc a b)) (hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : ∀ x ∈ Ico a b, f' x ≤ B' x) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) /-! ### Vector-valued functions `f : ℝ → E` -/ section variable {f : ℝ → E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `‖f a‖ ≤ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(‖f z‖ - ‖f x‖) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `‖f x‖ = B x`. Then `‖f x‖ ≤ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ → E} {f' : ℝ → ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (‖f z‖ - ‖f x‖) / (z - x) ≤ f' x` (hf' : ∀ x ∈ Ico a b, ∀ r, f' x < r → ∃ᶠ z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ → ℝ} (ha : ‖f a‖ ≤ B a) (hB : ContinuousOn B (Icc a b)) (hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : ∀ x ∈ Ico a b, ‖f x‖ = B x → f' x < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → ‖f x‖ ≤ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `‖f a‖ ≤ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `‖f x‖ = B x`. Then `‖f x‖ ≤ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ → E} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ → ℝ} (ha : ‖f a‖ ≤ B a) (hB : ContinuousOn B (Icc a b)) (hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : ∀ x ∈ Ico a b, ‖f x‖ = B x → ‖f' x‖ < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → ‖f x‖ ≤ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `‖f a‖ ≤ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `‖f x‖ = B x`. Then `‖f x‖ ≤ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ → E} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ → ℝ} (ha : ‖f a‖ ≤ B a) (hB : ∀ x, HasDerivAt B (B' x) x) (bound : ∀ x ∈ Ico a b, ‖f x‖ = B x → ‖f' x‖ < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → ‖f x‖ ≤ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `‖f a‖ ≤ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `‖f' x‖ ≤ B x` everywhere on `[a, b)`. Then `‖f x‖ ≤ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ → E} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ → ℝ} (ha : ‖f a‖ ≤ B a) (hB : ContinuousOn B (Icc a b)) (hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : ∀ x ∈ Ico a b, ‖f' x‖ ≤ B' x) : ∀ ⦃x⦄, x ∈ Icc a b → ‖f x‖ ≤ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `‖f a‖ ≤ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `‖f' x‖ ≤ B x` everywhere on `[a, b)`. Then `‖f x‖ ≤ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ → E} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ → ℝ} (ha : ‖f a‖ ≤ B a) (hB : ∀ x, HasDerivAt B (B' x) x) (bound : ∀ x ∈ Ico a b, ‖f' x‖ ≤ B' x) : ∀ ⦃x⦄, x ∈ Icc a b → ‖f x‖ ≤ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `‖f x - f a‖ ≤ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ → E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : ∀ x ∈ Ico a b, ‖f' x‖ ≤ C) : ∀ x ∈ Icc a b, ‖f x - f a‖ ≤ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : ∀ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simp [g, hf' x hx] let B x := C * (x - a) have hB : ∀ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only [g, B]; rw [sub_self, norm_zero, sub_self, mul_zero] /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `‖f x - f a‖ ≤ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ → E} {C : ℝ} (hf : ∀ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : ∀ x ∈ Ico a b, ‖f' x‖ ≤ C) : ∀ x ∈ Icc a b, ‖f x - f a‖ ≤ C * (x - a) := by refine norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => ?_) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem_nhdsWithin (Icc_mem_nhdsGE_of_mem hx) /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `‖f x - f a‖ ≤ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : ∀ x ∈ Ico a b, ‖derivWithin f (Icc a b) x‖ ≤ C) : ∀ x ∈ Icc a b, ‖f x - f a‖ ≤ C * (x - a) := by refine norm_image_sub_le_of_norm_deriv_le_segment' ?_ bound exact fun x hx => (hf x hx).hasDerivWithinAt /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `‖f 1 - f 0‖ ≤ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ → E} {C : ℝ} (hf : ∀ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : ∀ x ∈ Ico (0 : ℝ) 1, ‖f' x‖ ≤ C) : ‖f 1 - f 0‖ ≤ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `‖f 1 - f 0‖ ≤ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : ∀ x ∈ Ico (0 : ℝ) 1, ‖derivWithin f (Icc (0 : ℝ) 1) x‖ ≤ C) : ‖f 1 - f 0‖ ≤ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : ∀ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : ∀ x ∈ Icc a b, f x = f a := by have : ∀ x ∈ Icc a b, ‖f x - f a‖ ≤ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : ∀ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : ∀ x ∈ Icc a b, f x = f a := by have H : ∀ x ∈ Ico a b, ‖derivWithin f (Icc a b) x‖ ≤ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx variable {f' g : ℝ → E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : ∀ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : ∀ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊢ exact hi ▸ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : ∀ y ∈ Icc a b, f y = g y := by have A : ∀ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem_nhdsWithin (Icc_mem_nhdsGE_of_mem hy) have B : ∀ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem_nhdsWithin (Icc_mem_nhdsGE_of_mem hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm ▸ B y hy) fdiff.continuousOn gdiff.continuousOn hi end /-! ### Vector-valued functions `f : E → G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[NontriviallyNormedField 𝕜] [IsRCLikeNormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace 𝕜 G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section namespace Convex variable {𝕜 G : Type*} [NontriviallyNormedField 𝕜] [IsRCLikeNormedField 𝕜] [NormedSpace 𝕜 E] [NormedAddCommGroup G] [NormedSpace 𝕜 G] {f g : E → G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E → E →L[𝕜] G} {φ : E →L[𝕜] G} instance (priority := 100) : PathConnectedSpace 𝕜 := by letI : RCLike 𝕜 := IsRCLikeNormedField.rclike 𝕜 infer_instance /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : ∀ x ∈ s, ‖f' x‖ ≤ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : ‖f y - f x‖ ≤ C * ‖y - x‖ := by letI : RCLike 𝕜 := IsRCLikeNormedField.rclike 𝕜 letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ 𝕜 G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ → E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : ∀ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : ∀ t ∈ Ico (0 : ℝ) 1, ‖f' (g t) (y - x)‖ ≤ C * ‖y - x‖ := fun t ht => le_of_opNorm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa [g] using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝ≥0} (hf : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : ∀ x ∈ s, ‖f' x‖₊ ≤ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E → G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝ≥0` larger than `‖f' x‖₊`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E → G} (hder : ∀ᶠ y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝ≥0) (hK : ‖f' x‖₊ < K) : ∃ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨ε, ε0, hε⟩ : ∃ ε > 0, ball x ε ∩ s ⊆ { y | HasFDerivWithinAt f (f' y) s y ∧ ‖f' y‖₊ < K } := mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hε refine ⟨s ∩ ball x ε, inter_mem_nhdsWithin _ (ball_mem_nhds _ ε0), ?_⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hε hy).1.mono inter_subset_left) fun y hy => (hε hy).2.le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E → G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝ≥0` larger than `‖f' x‖₊`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E → G} (hder : ∀ᶠ y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : ∃ K, ∃ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn 𝕜 f s) (bound : ∀ x ∈ s, ‖fderivWithin 𝕜 f s x‖ ≤ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : ‖f y - f x‖ ≤ C * ‖y - x‖ := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝ≥0} (hf : DifferentiableOn 𝕜 f s) (bound : ∀ x ∈ s, ‖fderivWithin 𝕜 f s x‖₊ ≤ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : ∀ x ∈ s, DifferentiableAt 𝕜 f x) (bound : ∀ x ∈ s, ‖fderiv 𝕜 f x‖ ≤ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : ‖f y - f x‖ ≤ C * ‖y - x‖ := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝ≥0} (hf : ∀ x ∈ s, DifferentiableAt 𝕜 f x) (bound : ∀ x ∈ s, ‖fderiv 𝕜 f x‖₊ ≤ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {f : E → G} {C : ℝ≥0} (hf : Differentiable 𝕜 f) (bound : ∀ x, ‖fderiv 𝕜 f x‖₊ ≤ C) : LipschitzWith C f := by letI : RCLike 𝕜 := IsRCLikeNormedField.rclike 𝕜 let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ 𝕜 E rw [← lipschitzOnWith_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : ∀ x ∈ s, ‖f' x - φ‖ ≤ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : ‖f y - f x - φ (y - x)‖ ≤ C * ‖y - x‖ := by /- We subtract `φ` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - φ y have hg : ∀ x ∈ s, HasFDerivWithinAt g (f' x - φ) s x := fun x xs => (hf x xs).sub φ.hasFDerivWithinAt calc ‖f y - f x - φ (y - x)‖ = ‖f y - f x - (φ y - φ x)‖ := by simp _ = ‖f y - φ y - (f x - φ x)‖ := by congr 1; abel _ = ‖g y - g x‖ := by simp [g] _ ≤ C * ‖y - x‖ := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn 𝕜 f s) (bound : ∀ x ∈ s, ‖fderivWithin 𝕜 f s x - φ‖ ≤ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : ‖f y - f x - φ (y - x)‖ ≤ C * ‖y - x‖ := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : ∀ x ∈ s, DifferentiableAt 𝕜 f x) (bound : ∀ x ∈ s, ‖fderiv 𝕜 f x - φ‖ ≤ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : ‖f y - f x - φ (y - x)‖ ≤ C * ‖y - x‖ := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys /-- If a function has zero Fréchet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn 𝕜 f s) (hf' : ∀ x ∈ s, fderivWithin 𝕜 f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : ∀ x ∈ s, ‖fderivWithin 𝕜 f s x‖ ≤ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {f : E → G} (hf : Differentiable 𝕜 f) (hf' : ∀ x, fderiv 𝕜 f x = 0) (x y : E) : f x = f y := by letI : RCLike 𝕜 := IsRCLikeNormedField.rclike 𝕜 let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ 𝕜 E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial /-- If two functions have equal Fréchet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn 𝕜 f s) (hg : DifferentiableOn 𝕜 g s) (hs' : UniqueDiffOn 𝕜 s) (hf' : s.EqOn (fderivWithin 𝕜 f s) (fderivWithin 𝕜 g s)) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => ?_) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' hz] /-- If `f` has zero derivative on an open set, then `f` is locally constant on `s`. -/ -- TODO: change the spelling once we have `IsLocallyConstantOn`. theorem _root_.IsOpen.isOpen_inter_preimage_of_fderiv_eq_zero (hs : IsOpen s) (hf : DifferentiableOn 𝕜 f s) (hf' : s.EqOn (fderiv 𝕜 f) 0) (t : Set G) : IsOpen (s ∩ f ⁻¹' t) := by refine Metric.isOpen_iff.mpr fun y ⟨hy, hy'⟩ ↦ ?_ obtain ⟨r, hr, h⟩ := Metric.isOpen_iff.mp hs y hy refine ⟨r, hr, Set.subset_inter h fun x hx ↦ ?_⟩ have := (convex_ball y r).is_const_of_fderivWithin_eq_zero (hf.mono h) ?_ hx (mem_ball_self hr) · simpa [this] · intro z hz simpa only [fderivWithin_of_isOpen Metric.isOpen_ball hz] using hf' (h hz) theorem _root_.isLocallyConstant_of_fderiv_eq_zero (h₁ : Differentiable 𝕜 f) (h₂ : ∀ x, fderiv 𝕜 f x = 0) : IsLocallyConstant f := by simpa using isOpen_univ.isOpen_inter_preimage_of_fderiv_eq_zero h₁.differentiableOn fun _ _ ↦ h₂ _ /-- If `f` has zero derivative on a connected open set, then `f` is constant on `s`. -/ theorem _root_.IsOpen.exists_is_const_of_fderiv_eq_zero (hs : IsOpen s) (hs' : IsPreconnected s) (hf : DifferentiableOn 𝕜 f s) (hf' : s.EqOn (fderiv 𝕜 f) 0) : ∃ a, ∀ x ∈ s, f x = a := by obtain (rfl|⟨y, hy⟩) := s.eq_empty_or_nonempty · exact ⟨0, by simp⟩ · refine ⟨f y, fun x hx ↦ ?_⟩ have h₁ := hs.isOpen_inter_preimage_of_fderiv_eq_zero hf hf' {f y} have h₂ := hf.continuousOn.comp_continuous continuous_subtype_val (fun x ↦ x.2) by_contra h₃ obtain ⟨t, ht, ht'⟩ := (isClosed_singleton (x := f y)).preimage h₂ have ht'' : ∀ a ∈ s, a ∈ t ↔ f a ≠ f y := by simpa [Set.ext_iff] using ht' obtain ⟨z, H₁, H₂, H₃⟩ := hs' _ _ h₁ ht (fun x h ↦ by simp [h, ht'', eq_or_ne]) ⟨y, by simpa⟩ ⟨x, by simp [ht'' _ hx, hx, h₃]⟩ exact (ht'' _ H₁).mp H₃ H₂.2 theorem _root_.IsOpen.is_const_of_fderiv_eq_zero (hs : IsOpen s) (hs' : IsPreconnected s) (hf : DifferentiableOn 𝕜 f s) (hf' : s.EqOn (fderiv 𝕜 f) 0) {x y : E} (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by obtain ⟨a, ha⟩ := hs.exists_is_const_of_fderiv_eq_zero hs' hf hf' rw [ha x hx, ha y hy] theorem _root_.IsOpen.exists_eq_add_of_fderiv_eq (hs : IsOpen s) (hs' : IsPreconnected s) (hf : DifferentiableOn 𝕜 f s) (hg : DifferentiableOn 𝕜 g s) (hf' : s.EqOn (fderiv 𝕜 f) (fderiv 𝕜 g)) : ∃ a, s.EqOn f (g · + a) := by simp_rw [Set.EqOn, ← sub_eq_iff_eq_add'] refine hs.exists_is_const_of_fderiv_eq_zero hs' (hf.sub hg) fun x hx ↦ ?_ rw [fderiv_sub (hf.differentiableAt (hs.mem_nhds hx)) (hg.differentiableAt (hs.mem_nhds hx)), hf' hx, sub_self, Pi.zero_apply] /-- If two functions have equal Fréchet derivatives at every point of a connected open set, and are equal at one point in that set, then they are equal on that set. -/ theorem _root_.IsOpen.eqOn_of_fderiv_eq (hs : IsOpen s) (hs' : IsPreconnected s) (hf : DifferentiableOn 𝕜 f s) (hg : DifferentiableOn 𝕜 g s) (hf' : ∀ x ∈ s, fderiv 𝕜 f x = fderiv 𝕜 g x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := by obtain ⟨a, ha⟩ := hs.exists_eq_add_of_fderiv_eq hs' hf hg hf' obtain rfl := left_eq_add.mp (hfgx.symm.trans (ha hx)) simpa using ha theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {f g : E → G} (hf : Differentiable 𝕜 f) (hg : Differentiable 𝕜 g) (hf' : ∀ x, fderiv 𝕜 f x = fderiv 𝕜 g x) (x : E) (hfgx : f x = g x) : f = g := by letI : RCLike 𝕜 := IsRCLikeNormedField.rclike 𝕜 let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ 𝕜 E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx lemma isLittleO_pow_succ {x₀ : E} {n : ℕ} (hs : Convex ℝ s) (hx₀s : x₀ ∈ s) (hff' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (hf' : f' =o[𝓝[s] x₀] fun x ↦ ‖x - x₀‖ ^ n) : (fun x ↦ f x - f x₀) =o[𝓝[s] x₀] fun x ↦ ‖x - x₀‖ ^ (n + 1) := by rw [Asymptotics.isLittleO_iff] at hf' ⊢ intro c hc simp_rw [norm_pow, pow_succ, ← mul_assoc, norm_norm] simp_rw [norm_pow, norm_norm] at hf' have : ∀ᶠ x in 𝓝[s] x₀, segment ℝ x₀ x ⊆ s ∧ ∀ y ∈ segment ℝ x₀ x, ‖f' y‖ ≤ c * ‖x - x₀‖ ^ n := by have h1 : ∀ᶠ x in 𝓝[s] x₀, x ∈ s := eventually_mem_nhdsWithin filter_upwards [h1, hs.eventually_nhdsWithin_segment hx₀s (hf' hc)] with x hxs h refine ⟨hs.segment_subset hx₀s hxs, fun y hy ↦ (h y hy).trans ?_⟩ gcongr exact norm_sub_le_of_mem_segment hy filter_upwards [this] with x ⟨h_segment, h⟩ convert (convex_segment x₀ x).norm_image_sub_le_of_norm_hasFDerivWithin_le (f := fun x ↦ f x - f x₀) (y := x) (x := x₀) (s := segment ℝ x₀ x) ?_ h (left_mem_segment ℝ x₀ x) (right_mem_segment ℝ x₀ x) using 1 · simp · simp only [hasFDerivWithinAt_sub_const_iff] exact fun x hx ↦ (hff' x (h_segment hx)).mono h_segment theorem isLittleO_pow_succ_real {f f' : ℝ → E} {x₀ : ℝ} {n : ℕ} {s : Set ℝ} (hs : Convex ℝ s) (hx₀s : x₀ ∈ s) (hff' : ∀ x ∈ s, HasDerivWithinAt f (f' x) s x) (hf' : f' =o[𝓝[s] x₀] fun x ↦ (x - x₀) ^ n) : (fun x ↦ f x - f x₀) =o[𝓝[s] x₀] fun x ↦ (x - x₀) ^ (n + 1) := by have h := hs.isLittleO_pow_succ hx₀s hff' ?_ (n := n) · rw [Asymptotics.isLittleO_iff] at h ⊢ simpa using h · rw [Asymptotics.isLittleO_iff] at hf' ⊢ convert hf' using 4 with c hc x simp end Convex namespace Convex variable {𝕜 G : Type*} [RCLike 𝕜] [NormedAddCommGroup G] [NormedSpace 𝕜 G] {f f' : 𝕜 → G} {s : Set 𝕜} {x y : 𝕜} /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasDerivWithin_le {C : ℝ} (hf : ∀ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : ∀ x ∈ s, ‖f' x‖ ≤ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : ‖f y - f x‖ ≤ C * ‖y - x‖ := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs xs ys /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasDerivWithin_le {C : ℝ≥0} (hs : Convex ℝ s) (hf : ∀ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : ∀ x ∈ s, ‖f' x‖₊ ≤ C) : LipschitzOnWith C f s := Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `derivWithin` -/ theorem norm_image_sub_le_of_norm_derivWithin_le {C : ℝ} (hf : DifferentiableOn 𝕜 f s) (bound : ∀ x ∈ s, ‖derivWithin f s x‖ ≤ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : ‖f y - f x‖ ≤ C * ‖y - x‖ := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound xs ys /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `derivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_derivWithin_le {C : ℝ≥0} (hs : Convex ℝ s) (hf : DifferentiableOn 𝕜 f s) (bound : ∀ x ∈ s, ‖derivWithin f s x‖₊ ≤ C) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv`. -/ theorem norm_image_sub_le_of_norm_deriv_le {C : ℝ} (hf : ∀ x ∈ s, DifferentiableAt 𝕜 f x) (bound : ∀ x ∈ s, ‖deriv f x‖ ≤ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : ‖f y - f x‖ ≤ C * ‖y - x‖ := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound xs ys /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `deriv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_deriv_le {C : ℝ≥0} (hf : ∀ x ∈ s, DifferentiableAt 𝕜 f x) (bound : ∀ x ∈ s, ‖deriv f x‖₊ ≤ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound /-- The mean value theorem set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_deriv_le {C : ℝ≥0} (hf : Differentiable 𝕜 f) (bound : ∀ x, ‖deriv f x‖₊ ≤ C) : LipschitzWith C f := lipschitzOnWith_univ.1 <| convex_univ.lipschitzOnWith_of_nnnorm_deriv_le (fun x _ => hf x) fun x _ => bound x /-- If `f : 𝕜 → G`, `𝕜 = R` or `𝕜 = ℂ`, is differentiable everywhere and its derivative equal zero, then it is a constant function. -/ theorem _root_.is_const_of_deriv_eq_zero (hf : Differentiable 𝕜 f) (hf' : ∀ x, deriv f x = 0) (x y : 𝕜) : f x = f y := is_const_of_fderiv_eq_zero hf (fun z => by ext; simp [← deriv_fderiv, hf']) _ _ theorem _root_.IsOpen.isOpen_inter_preimage_of_deriv_eq_zero (hs : IsOpen s) (hf : DifferentiableOn 𝕜 f s) (hf' : s.EqOn (deriv f) 0) (t : Set G) : IsOpen (s ∩ f ⁻¹' t) := hs.isOpen_inter_preimage_of_fderiv_eq_zero hf (fun x hx ↦ by ext; simp [← deriv_fderiv, hf' hx]) t theorem _root_.IsOpen.exists_is_const_of_deriv_eq_zero (hs : IsOpen s) (hs' : IsPreconnected s) (hf : DifferentiableOn 𝕜 f s) (hf' : s.EqOn (deriv f) 0) : ∃ a, ∀ x ∈ s, f x = a := hs.exists_is_const_of_fderiv_eq_zero hs' hf (fun {x} hx ↦ by ext; simp [← deriv_fderiv, hf' hx]) theorem _root_.IsOpen.is_const_of_deriv_eq_zero (hs : IsOpen s) (hs' : IsPreconnected s) (hf : DifferentiableOn 𝕜 f s) (hf' : s.EqOn (deriv f) 0) {x y : 𝕜} (hx : x ∈ s) (hy : y ∈ s) : f x = f y := hs.is_const_of_fderiv_eq_zero hs' hf (fun a ha ↦ by ext; simp [← deriv_fderiv, hf' ha]) hx hy theorem _root_.IsOpen.exists_eq_add_of_deriv_eq {f g : 𝕜 → G} (hs : IsOpen s) (hs' : IsPreconnected s) (hf : DifferentiableOn 𝕜 f s) (hg : DifferentiableOn 𝕜 g s) (hf' : s.EqOn (deriv f) (deriv g)) : ∃ a, s.EqOn f (g · + a) := hs.exists_eq_add_of_fderiv_eq hs' hf hg (fun x hx ↦ by ext; simp [← deriv_fderiv, hf' hx]) theorem _root_.IsOpen.eqOn_of_deriv_eq {f g : 𝕜 → G} (hs : IsOpen s) (hs' : IsPreconnected s) (hf : DifferentiableOn 𝕜 f s) (hg : DifferentiableOn 𝕜 g s) (hf' : s.EqOn (deriv f) (deriv g)) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := hs.eqOn_of_fderiv_eq hs' hf hg (fun _ hx ↦ ContinuousLinearMap.ext_ring (hf' hx)) hx hfgx end Convex end section RCLike /-! ### Vector-valued functions `f : E → F`. Strict differentiability. A `C^1` function is strictly differentiable, when the field is `ℝ` or `ℂ`. This follows from the mean value inequality on balls, which is a particular case of the above results after restricting the scalars to `ℝ`. Note that it does not make sense to talk of a convex set over `ℂ`, but balls make sense and are enough. Many formulations of the mean value inequality could be generalized to balls over `ℝ` or `ℂ`. For now, we only include the ones that we need. -/ variable {𝕜 : Type*} [RCLike 𝕜] {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] {H : Type*} [NormedAddCommGroup H] [NormedSpace 𝕜 H] {f : G → H} {f' : G → G →L[𝕜] H} {x : G} /-- Over the reals or the complexes, a continuously differentiable function is strictly differentiable. -/ theorem hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt (hder : ∀ᶠ y in 𝓝 x, HasFDerivAt f (f' y) y) (hcont : ContinuousAt f' x) : HasStrictFDerivAt f (f' x) x := by -- turn little-o definition of strict_fderiv into an epsilon-delta statement rw [hasStrictFDerivAt_iff_isLittleO, isLittleO_iff] refine fun c hc => Metric.eventually_nhds_iff_ball.mpr ?_ -- the correct ε is the modulus of continuity of f' rcases Metric.mem_nhds_iff.mp (inter_mem hder (hcont <| ball_mem_nhds _ hc)) with ⟨ε, ε0, hε⟩ refine ⟨ε, ε0, ?_⟩ -- simplify formulas involving the product E × E rintro ⟨a, b⟩ h rw [← ball_prod_same, prodMk_mem_set_prod_eq] at h -- exploit the choice of ε as the modulus of continuity of f' have hf' : ∀ x' ∈ ball x ε, ‖f' x' - f' x‖ ≤ c := fun x' H' => by rw [← dist_eq_norm] exact le_of_lt (hε H').2 -- apply mean value theorem letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ 𝕜 G refine (convex_ball _ _).norm_image_sub_le_of_norm_hasFDerivWithin_le' ?_ hf' h.2 h.1 exact fun y hy => (hε hy).1.hasFDerivWithinAt /-- Over the reals or the complexes, a continuously differentiable function is strictly differentiable. -/ theorem hasStrictDerivAt_of_hasDerivAt_of_continuousAt {f f' : 𝕜 → G} {x : 𝕜} (hder : ∀ᶠ y in 𝓝 x, HasDerivAt f (f' y) y) (hcont : ContinuousAt f' x) : HasStrictDerivAt f (f' x) x := hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt (hder.mono fun _ hy => hy.hasFDerivAt) <| (smulRightL 𝕜 𝕜 G 1).continuous.continuousAt.comp hcont end RCLike
Mathlib/Analysis/Calculus/MeanValue.lean
883
890
/- Copyright (c) 2023 Antoine Chambert-Loir and María Inés de Frutos-Fernández. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Antoine Chambert-Loir, María Inés de Frutos-Fernández, Eric Wieser, Bhavik Mehta, Yaël Dillies -/ import Mathlib.Algebra.Order.Antidiag.Pi import Mathlib.Data.Finsupp.Basic /-! # Antidiagonal of finitely supported functions as finsets This file defines the finset of finitely functions summing to a specific value on a finset. Such finsets should be thought of as the "antidiagonals" in the space of finitely supported functions. Precisely, for a commutative monoid `μ` with antidiagonals (see `Finset.HasAntidiagonal`), `Finset.finsuppAntidiag s n` is the finset of all finitely supported functions `f : ι →₀ μ` with support contained in `s` and such that the sum of its values equals `n : μ`. We define it using `Finset.piAntidiag s n`, the corresponding antidiagonal in `ι → μ`. ## Main declarations * `Finset.finsuppAntidiag s n`: Finset of all finitely supported functions `f : ι →₀ μ` with support contained in `s` and such that the sum of its values equals `n : μ`. -/ open Finsupp Function variable {ι μ μ' : Type*} namespace Finset section AddCommMonoid variable [DecidableEq ι] [AddCommMonoid μ] [HasAntidiagonal μ] [DecidableEq μ] {s : Finset ι} {n : μ} {f : ι →₀ μ} /-- The finset of functions `ι →₀ μ` with support contained in `s` and sum equal to `n`. -/ def finsuppAntidiag (s : Finset ι) (n : μ) : Finset (ι →₀ μ) := (piAntidiag s n).attach.map ⟨fun f ↦ ⟨s.filter (f.1 · ≠ 0), f.1, by simpa using (mem_piAntidiag.1 f.2).2⟩, fun _ _ hfg ↦ Subtype.ext (congr_arg (⇑) hfg)⟩ @[simp] lemma mem_finsuppAntidiag : f ∈ finsuppAntidiag s n ↔ s.sum f = n ∧ f.support ⊆ s := by simp [finsuppAntidiag, ← DFunLike.coe_fn_eq, subset_iff] lemma mem_finsuppAntidiag' : f ∈ finsuppAntidiag s n ↔ f.sum (fun _ x ↦ x) = n ∧ f.support ⊆ s := by simp only [mem_finsuppAntidiag, and_congr_left_iff] rintro hf rw [sum_of_support_subset (N := μ) f hf (fun _ x ↦ x) fun _ _ ↦ rfl] @[simp] lemma finsuppAntidiag_empty_zero : finsuppAntidiag (∅ : Finset ι) (0 : μ) = {0} := by ext f; simp [finsuppAntidiag, ← DFunLike.coe_fn_eq (g := f), eq_comm] @[simp] lemma finsuppAntidiag_empty_of_ne_zero (hn : n ≠ 0) : finsuppAntidiag (∅ : Finset ι) n = ∅ := eq_empty_of_forall_not_mem (by simp [@eq_comm _ 0, hn.symm]) lemma finsuppAntidiag_empty (n : μ) : finsuppAntidiag (∅ : Finset ι) n = if n = 0 then {0} else ∅ := by split_ifs with hn <;> simp [*] theorem mem_finsuppAntidiag_insert {a : ι} {s : Finset ι} (h : a ∉ s) (n : μ) {f : ι →₀ μ} : f ∈ finsuppAntidiag (insert a s) n ↔ ∃ m ∈ antidiagonal n, ∃ (g : ι →₀ μ), f = Finsupp.update g a m.1 ∧ g ∈ finsuppAntidiag s m.2 := by simp only [mem_finsuppAntidiag, mem_antidiagonal, Prod.exists, sum_insert h] constructor · rintro ⟨rfl, hsupp⟩ refine ⟨_, _, rfl, Finsupp.erase a f, ?_, ?_, ?_⟩ · rw [update_erase_eq_update, Finsupp.update_self] · apply sum_congr rfl intro x hx rw [Finsupp.erase_ne (ne_of_mem_of_not_mem hx h)] · rwa [support_erase, ← subset_insert_iff] · rintro ⟨n1, n2, rfl, g, rfl, rfl, hgsupp⟩ refine ⟨?_, (support_update_subset _ _).trans (insert_subset_insert a hgsupp)⟩ simp only [coe_update] apply congr_arg₂ · rw [Function.update_self] · apply sum_congr rfl intro x hx rw [update_of_ne (ne_of_mem_of_not_mem hx h) n1 ⇑g] theorem finsuppAntidiag_insert {a : ι} {s : Finset ι} (h : a ∉ s) (n : μ) : finsuppAntidiag (insert a s) n = (antidiagonal n).biUnion (fun p : μ × μ => (finsuppAntidiag s p.snd).attach.map ⟨fun f => Finsupp.update f.val a p.fst, (fun ⟨f, hf⟩ ⟨g, hg⟩ hfg => Subtype.ext <| by simp only [mem_val, mem_finsuppAntidiag] at hf hg simp only [DFunLike.ext_iff] at hfg ⊢ intro x obtain rfl | hx := eq_or_ne x a · replace hf := mt (hf.2 ·) h replace hg := mt (hg.2 ·) h rw [not_mem_support_iff.mp hf, not_mem_support_iff.mp hg] · simpa only [coe_update, Function.update, dif_neg hx] using hfg x)⟩) := by ext f rw [mem_finsuppAntidiag_insert h, mem_biUnion] simp_rw [mem_map, mem_attach, true_and, Subtype.exists, Embedding.coeFn_mk, exists_prop, and_comm, eq_comm] variable [AddCommMonoid μ'] [HasAntidiagonal μ'] [DecidableEq μ'] -- This should work under the assumption that e is an embedding and an AddHom lemma mapRange_finsuppAntidiag_subset {e : μ ≃+ μ'} {s : Finset ι} {n : μ} : (finsuppAntidiag s n).map (mapRange.addEquiv e).toEmbedding ⊆ finsuppAntidiag s (e n) := by intro f simp only [mem_map, mem_finsuppAntidiag'] rintro ⟨g, ⟨hsum, hsupp⟩, rfl⟩ simp only [AddEquiv.toEquiv_eq_coe, mapRange.addEquiv_toEquiv, Equiv.coe_toEmbedding, mapRange.equiv_apply, EquivLike.coe_coe] constructor · rw [sum_mapRange_index (fun _ ↦ rfl), ← hsum, _root_.map_finsuppSum] · exact subset_trans (support_mapRange) hsupp lemma mapRange_finsuppAntidiag_eq {e : μ ≃+ μ'} {s : Finset ι} {n : μ} : (finsuppAntidiag s n).map (mapRange.addEquiv e).toEmbedding = finsuppAntidiag s (e n) := by ext f constructor · apply mapRange_finsuppAntidiag_subset · set h := (mapRange.addEquiv e).toEquiv with hh intro hf have : n = e.symm (e n) := (AddEquiv.eq_symm_apply e).mpr rfl rw [mem_map_equiv, this] apply mapRange_finsuppAntidiag_subset rw [← mem_map_equiv] convert hf rw [map_map, hh] convert map_refl apply Function.Embedding.equiv_symm_toEmbedding_trans_toEmbedding end AddCommMonoid section CanonicallyOrderedAddCommMonoid variable [DecidableEq ι] [DecidableEq μ] [AddCommMonoid μ] [PartialOrder μ] [CanonicallyOrderedAdd μ] [HasAntidiagonal μ]
@[simp] lemma finsuppAntidiag_zero (s : Finset ι) : finsuppAntidiag s (0 : μ) = {0} := by ext f; simp [finsuppAntidiag, ← DFunLike.coe_fn_eq (g := f), -mem_piAntidiag, eq_comm] end CanonicallyOrderedAddCommMonoid end Finset
Mathlib/Algebra/Order/Antidiag/Finsupp.lean
140
162
/- Copyright (c) 2020 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.RingTheory.Polynomial.Cyclotomic.Basic import Mathlib.RingTheory.RootsOfUnity.Minpoly /-! # Roots of cyclotomic polynomials. We gather results about roots of cyclotomic polynomials. In particular we show in `Polynomial.cyclotomic_eq_minpoly` that `cyclotomic n R` is the minimal polynomial of a primitive root of unity. ## Main results * `IsPrimitiveRoot.isRoot_cyclotomic` : Any `n`-th primitive root of unity is a root of `cyclotomic n R`. * `isRoot_cyclotomic_iff` : if `NeZero (n : R)`, then `μ` is a root of `cyclotomic n R` if and only if `μ` is a primitive root of unity. * `Polynomial.cyclotomic_eq_minpoly` : `cyclotomic n ℤ` is the minimal polynomial of a primitive `n`-th root of unity `μ`. * `Polynomial.cyclotomic.irreducible` : `cyclotomic n ℤ` is irreducible. ## Implementation details To prove `Polynomial.cyclotomic.irreducible`, the irreducibility of `cyclotomic n ℤ`, we show in `Polynomial.cyclotomic_eq_minpoly` that `cyclotomic n ℤ` is the minimal polynomial of any `n`-th primitive root of unity `μ : K`, where `K` is a field of characteristic `0`. -/ namespace Polynomial variable {R : Type*} [CommRing R] {n : ℕ} theorem isRoot_of_unity_of_root_cyclotomic {ζ : R} {i : ℕ} (hi : i ∈ n.divisors) (h : (cyclotomic i R).IsRoot ζ) : ζ ^ n = 1 := by
rcases n.eq_zero_or_pos with (rfl | hn) · exact pow_zero _ have := congr_arg (eval ζ) (prod_cyclotomic_eq_X_pow_sub_one hn R).symm rw [eval_sub, eval_pow, eval_X, eval_one] at this convert eq_add_of_sub_eq' this convert (add_zero (M := R) _).symm apply eval_eq_zero_of_dvd_of_eval_eq_zero _ h exact Finset.dvd_prod_of_mem _ hi section IsDomain
Mathlib/RingTheory/Polynomial/Cyclotomic/Roots.lean
40
49
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Andrew Zipperer, Haitao Zhang, Minchao Wu, Yury Kudryashov -/ import Mathlib.Data.Set.Prod import Mathlib.Data.Set.Restrict /-! # Functions over sets This file contains basic results on the following predicates of functions and sets: * `Set.EqOn f₁ f₂ s` : functions `f₁` and `f₂` are equal at every point of `s`; * `Set.MapsTo f s t` : `f` sends every point of `s` to a point of `t`; * `Set.InjOn f s` : restriction of `f` to `s` is injective; * `Set.SurjOn f s t` : every point in `s` has a preimage in `s`; * `Set.BijOn f s t` : `f` is a bijection between `s` and `t`; * `Set.LeftInvOn f' f s` : for every `x ∈ s` we have `f' (f x) = x`; * `Set.RightInvOn f' f t` : for every `y ∈ t` we have `f (f' y) = y`; * `Set.InvOn f' f s t` : `f'` is a two-side inverse of `f` on `s` and `t`, i.e. we have `Set.LeftInvOn f' f s` and `Set.RightInvOn f' f t`. -/ variable {α β γ δ : Type*} {ι : Sort*} {π : α → Type*} open Equiv Equiv.Perm Function namespace Set /-! ### Equality on a set -/ section equality variable {s s₁ s₂ : Set α} {f₁ f₂ f₃ : α → β} {g : β → γ} {a : α} /-- This lemma exists for use by `aesop` as a forward rule. -/ @[aesop safe forward] lemma EqOn.eq_of_mem (h : s.EqOn f₁ f₂) (ha : a ∈ s) : f₁ a = f₂ a := h ha @[simp] theorem eqOn_empty (f₁ f₂ : α → β) : EqOn f₁ f₂ ∅ := fun _ => False.elim @[simp] theorem eqOn_singleton : Set.EqOn f₁ f₂ {a} ↔ f₁ a = f₂ a := by simp [Set.EqOn] @[simp] theorem eqOn_univ (f₁ f₂ : α → β) : EqOn f₁ f₂ univ ↔ f₁ = f₂ := by simp [EqOn, funext_iff] @[symm] theorem EqOn.symm (h : EqOn f₁ f₂ s) : EqOn f₂ f₁ s := fun _ hx => (h hx).symm theorem eqOn_comm : EqOn f₁ f₂ s ↔ EqOn f₂ f₁ s := ⟨EqOn.symm, EqOn.symm⟩ -- This can not be tagged as `@[refl]` with the current argument order. -- See note below at `EqOn.trans`. theorem eqOn_refl (f : α → β) (s : Set α) : EqOn f f s := fun _ _ => rfl -- Note: this was formerly tagged with `@[trans]`, and although the `trans` attribute accepted it -- the `trans` tactic could not use it. -- An update to the trans tactic coming in https://github.com/leanprover-community/mathlib4/pull/7014 will reject this attribute. -- It can be restored by changing the argument order from `EqOn f₁ f₂ s` to `EqOn s f₁ f₂`. -- This change will be made separately: [zulip](https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Reordering.20arguments.20of.20.60Set.2EEqOn.60/near/390467581). theorem EqOn.trans (h₁ : EqOn f₁ f₂ s) (h₂ : EqOn f₂ f₃ s) : EqOn f₁ f₃ s := fun _ hx => (h₁ hx).trans (h₂ hx) theorem EqOn.image_eq (heq : EqOn f₁ f₂ s) : f₁ '' s = f₂ '' s := image_congr heq /-- Variant of `EqOn.image_eq`, for one function being the identity. -/ theorem EqOn.image_eq_self {f : α → α} (h : Set.EqOn f id s) : f '' s = s := by rw [h.image_eq, image_id] theorem EqOn.inter_preimage_eq (heq : EqOn f₁ f₂ s) (t : Set β) : s ∩ f₁ ⁻¹' t = s ∩ f₂ ⁻¹' t := ext fun x => and_congr_right_iff.2 fun hx => by rw [mem_preimage, mem_preimage, heq hx] theorem EqOn.mono (hs : s₁ ⊆ s₂) (hf : EqOn f₁ f₂ s₂) : EqOn f₁ f₂ s₁ := fun _ hx => hf (hs hx) @[simp] theorem eqOn_union : EqOn f₁ f₂ (s₁ ∪ s₂) ↔ EqOn f₁ f₂ s₁ ∧ EqOn f₁ f₂ s₂ := forall₂_or_left theorem EqOn.union (h₁ : EqOn f₁ f₂ s₁) (h₂ : EqOn f₁ f₂ s₂) : EqOn f₁ f₂ (s₁ ∪ s₂) := eqOn_union.2 ⟨h₁, h₂⟩ theorem EqOn.comp_left (h : s.EqOn f₁ f₂) : s.EqOn (g ∘ f₁) (g ∘ f₂) := fun _ ha => congr_arg _ <| h ha @[simp] theorem eqOn_range {ι : Sort*} {f : ι → α} {g₁ g₂ : α → β} : EqOn g₁ g₂ (range f) ↔ g₁ ∘ f = g₂ ∘ f := forall_mem_range.trans <| funext_iff.symm alias ⟨EqOn.comp_eq, _⟩ := eqOn_range end equality variable {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {p : Set γ} {f f₁ f₂ : α → β} {g g₁ g₂ : β → γ} {f' f₁' f₂' : β → α} {g' : γ → β} {a : α} {b : β} section MapsTo theorem mapsTo' : MapsTo f s t ↔ f '' s ⊆ t := image_subset_iff.symm theorem mapsTo_prodMap_diagonal : MapsTo (Prod.map f f) (diagonal α) (diagonal β) := diagonal_subset_iff.2 fun _ => rfl @[deprecated (since := "2025-04-18")] alias mapsTo_prod_map_diagonal := mapsTo_prodMap_diagonal theorem MapsTo.subset_preimage (hf : MapsTo f s t) : s ⊆ f ⁻¹' t := hf theorem mapsTo_iff_subset_preimage : MapsTo f s t ↔ s ⊆ f ⁻¹' t := Iff.rfl @[simp] theorem mapsTo_singleton {x : α} : MapsTo f {x} t ↔ f x ∈ t := singleton_subset_iff theorem mapsTo_empty (f : α → β) (t : Set β) : MapsTo f ∅ t := empty_subset _ @[simp] theorem mapsTo_empty_iff : MapsTo f s ∅ ↔ s = ∅ := by simp [mapsTo', subset_empty_iff] /-- If `f` maps `s` to `t` and `s` is non-empty, `t` is non-empty. -/ theorem MapsTo.nonempty (h : MapsTo f s t) (hs : s.Nonempty) : t.Nonempty := (hs.image f).mono (mapsTo'.mp h) theorem MapsTo.image_subset (h : MapsTo f s t) : f '' s ⊆ t := mapsTo'.1 h theorem MapsTo.congr (h₁ : MapsTo f₁ s t) (h : EqOn f₁ f₂ s) : MapsTo f₂ s t := fun _ hx => h hx ▸ h₁ hx theorem EqOn.comp_right (hg : t.EqOn g₁ g₂) (hf : s.MapsTo f t) : s.EqOn (g₁ ∘ f) (g₂ ∘ f) := fun _ ha => hg <| hf ha theorem EqOn.mapsTo_iff (H : EqOn f₁ f₂ s) : MapsTo f₁ s t ↔ MapsTo f₂ s t := ⟨fun h => h.congr H, fun h => h.congr H.symm⟩ theorem MapsTo.comp (h₁ : MapsTo g t p) (h₂ : MapsTo f s t) : MapsTo (g ∘ f) s p := fun _ h => h₁ (h₂ h) theorem mapsTo_id (s : Set α) : MapsTo id s s := fun _ => id theorem MapsTo.iterate {f : α → α} {s : Set α} (h : MapsTo f s s) : ∀ n, MapsTo f^[n] s s | 0 => fun _ => id | n + 1 => (MapsTo.iterate h n).comp h theorem MapsTo.iterate_restrict {f : α → α} {s : Set α} (h : MapsTo f s s) (n : ℕ) : (h.restrict f s s)^[n] = (h.iterate n).restrict _ _ _ := by funext x rw [Subtype.ext_iff, MapsTo.val_restrict_apply] induction n generalizing x with | zero => rfl | succ n ihn => simp [Nat.iterate, ihn] lemma mapsTo_of_subsingleton' [Subsingleton β] (f : α → β) (h : s.Nonempty → t.Nonempty) : MapsTo f s t := fun a ha ↦ Subsingleton.mem_iff_nonempty.2 <| h ⟨a, ha⟩ lemma mapsTo_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : MapsTo f s s := mapsTo_of_subsingleton' _ id theorem MapsTo.mono (hf : MapsTo f s₁ t₁) (hs : s₂ ⊆ s₁) (ht : t₁ ⊆ t₂) : MapsTo f s₂ t₂ := fun _ hx => ht (hf <| hs hx) theorem MapsTo.mono_left (hf : MapsTo f s₁ t) (hs : s₂ ⊆ s₁) : MapsTo f s₂ t := fun _ hx => hf (hs hx) theorem MapsTo.mono_right (hf : MapsTo f s t₁) (ht : t₁ ⊆ t₂) : MapsTo f s t₂ := fun _ hx => ht (hf hx) theorem MapsTo.union_union (h₁ : MapsTo f s₁ t₁) (h₂ : MapsTo f s₂ t₂) : MapsTo f (s₁ ∪ s₂) (t₁ ∪ t₂) := fun _ hx => hx.elim (fun hx => Or.inl <| h₁ hx) fun hx => Or.inr <| h₂ hx theorem MapsTo.union (h₁ : MapsTo f s₁ t) (h₂ : MapsTo f s₂ t) : MapsTo f (s₁ ∪ s₂) t := union_self t ▸ h₁.union_union h₂ @[simp] theorem mapsTo_union : MapsTo f (s₁ ∪ s₂) t ↔ MapsTo f s₁ t ∧ MapsTo f s₂ t := ⟨fun h => ⟨h.mono subset_union_left (Subset.refl t), h.mono subset_union_right (Subset.refl t)⟩, fun h => h.1.union h.2⟩ theorem MapsTo.inter (h₁ : MapsTo f s t₁) (h₂ : MapsTo f s t₂) : MapsTo f s (t₁ ∩ t₂) := fun _ hx => ⟨h₁ hx, h₂ hx⟩ lemma MapsTo.insert (h : MapsTo f s t) (x : α) : MapsTo f (insert x s) (insert (f x) t) := by simpa [← singleton_union] using h.mono_right subset_union_right theorem MapsTo.inter_inter (h₁ : MapsTo f s₁ t₁) (h₂ : MapsTo f s₂ t₂) : MapsTo f (s₁ ∩ s₂) (t₁ ∩ t₂) := fun _ hx => ⟨h₁ hx.1, h₂ hx.2⟩ @[simp] theorem mapsTo_inter : MapsTo f s (t₁ ∩ t₂) ↔ MapsTo f s t₁ ∧ MapsTo f s t₂ := ⟨fun h => ⟨h.mono (Subset.refl s) inter_subset_left, h.mono (Subset.refl s) inter_subset_right⟩, fun h => h.1.inter h.2⟩ theorem mapsTo_univ (f : α → β) (s : Set α) : MapsTo f s univ := fun _ _ => trivial theorem mapsTo_range (f : α → β) (s : Set α) : MapsTo f s (range f) := (mapsTo_image f s).mono (Subset.refl s) (image_subset_range _ _) @[simp] theorem mapsTo_image_iff {f : α → β} {g : γ → α} {s : Set γ} {t : Set β} : MapsTo f (g '' s) t ↔ MapsTo (f ∘ g) s t := ⟨fun h c hc => h ⟨c, hc, rfl⟩, fun h _ ⟨_, hc⟩ => hc.2 ▸ h hc.1⟩ lemma MapsTo.comp_left (g : β → γ) (hf : MapsTo f s t) : MapsTo (g ∘ f) s (g '' t) := fun x hx ↦ ⟨f x, hf hx, rfl⟩ lemma MapsTo.comp_right {s : Set β} {t : Set γ} (hg : MapsTo g s t) (f : α → β) : MapsTo (g ∘ f) (f ⁻¹' s) t := fun _ hx ↦ hg hx @[simp] lemma mapsTo_univ_iff : MapsTo f univ t ↔ ∀ x, f x ∈ t := ⟨fun h _ => h (mem_univ _), fun h x _ => h x⟩ @[simp] lemma mapsTo_range_iff {g : ι → α} : MapsTo f (range g) t ↔ ∀ i, f (g i) ∈ t := forall_mem_range theorem MapsTo.mem_iff (h : MapsTo f s t) (hc : MapsTo f sᶜ tᶜ) {x} : f x ∈ t ↔ x ∈ s := ⟨fun ht => by_contra fun hs => hc hs ht, fun hx => h hx⟩ end MapsTo /-! ### Injectivity on a set -/ section injOn theorem Subsingleton.injOn (hs : s.Subsingleton) (f : α → β) : InjOn f s := fun _ hx _ hy _ => hs hx hy @[simp] theorem injOn_empty (f : α → β) : InjOn f ∅ := subsingleton_empty.injOn f @[simp] theorem injOn_singleton (f : α → β) (a : α) : InjOn f {a} := subsingleton_singleton.injOn f @[simp] lemma injOn_pair {b : α} : InjOn f {a, b} ↔ f a = f b → a = b := by unfold InjOn; aesop theorem InjOn.eq_iff {x y} (h : InjOn f s) (hx : x ∈ s) (hy : y ∈ s) : f x = f y ↔ x = y := ⟨h hx hy, fun h => h ▸ rfl⟩ theorem InjOn.ne_iff {x y} (h : InjOn f s) (hx : x ∈ s) (hy : y ∈ s) : f x ≠ f y ↔ x ≠ y := (h.eq_iff hx hy).not alias ⟨_, InjOn.ne⟩ := InjOn.ne_iff theorem InjOn.congr (h₁ : InjOn f₁ s) (h : EqOn f₁ f₂ s) : InjOn f₂ s := fun _ hx _ hy => h hx ▸ h hy ▸ h₁ hx hy theorem EqOn.injOn_iff (H : EqOn f₁ f₂ s) : InjOn f₁ s ↔ InjOn f₂ s := ⟨fun h => h.congr H, fun h => h.congr H.symm⟩ theorem InjOn.mono (h : s₁ ⊆ s₂) (ht : InjOn f s₂) : InjOn f s₁ := fun _ hx _ hy H => ht (h hx) (h hy) H theorem injOn_union (h : Disjoint s₁ s₂) : InjOn f (s₁ ∪ s₂) ↔ InjOn f s₁ ∧ InjOn f s₂ ∧ ∀ x ∈ s₁, ∀ y ∈ s₂, f x ≠ f y := by refine ⟨fun H => ⟨H.mono subset_union_left, H.mono subset_union_right, ?_⟩, ?_⟩ · intro x hx y hy hxy obtain rfl : x = y := H (Or.inl hx) (Or.inr hy) hxy exact h.le_bot ⟨hx, hy⟩ · rintro ⟨h₁, h₂, h₁₂⟩ rintro x (hx | hx) y (hy | hy) hxy exacts [h₁ hx hy hxy, (h₁₂ _ hx _ hy hxy).elim, (h₁₂ _ hy _ hx hxy.symm).elim, h₂ hx hy hxy] theorem injOn_insert {f : α → β} {s : Set α} {a : α} (has : a ∉ s) : Set.InjOn f (insert a s) ↔ Set.InjOn f s ∧ f a ∉ f '' s := by rw [← union_singleton, injOn_union (disjoint_singleton_right.2 has)] simp theorem injective_iff_injOn_univ : Injective f ↔ InjOn f univ := ⟨fun h _ _ _ _ hxy => h hxy, fun h _ _ heq => h trivial trivial heq⟩ theorem injOn_of_injective (h : Injective f) {s : Set α} : InjOn f s := fun _ _ _ _ hxy => h hxy alias _root_.Function.Injective.injOn := injOn_of_injective -- A specialization of `injOn_of_injective` for `Subtype.val`. theorem injOn_subtype_val {s : Set { x // p x }} : Set.InjOn Subtype.val s := Subtype.coe_injective.injOn lemma injOn_id (s : Set α) : InjOn id s := injective_id.injOn theorem InjOn.comp (hg : InjOn g t) (hf : InjOn f s) (h : MapsTo f s t) : InjOn (g ∘ f) s := fun _ hx _ hy heq => hf hx hy <| hg (h hx) (h hy) heq lemma InjOn.of_comp (h : InjOn (g ∘ f) s) : InjOn f s := fun _ hx _ hy heq ↦ h hx hy (by simp [heq]) lemma InjOn.image_of_comp (h : InjOn (g ∘ f) s) : InjOn g (f '' s) := forall_mem_image.2 fun _x hx ↦ forall_mem_image.2 fun _y hy heq ↦ congr_arg f <| h hx hy heq lemma InjOn.comp_iff (hf : InjOn f s) : InjOn (g ∘ f) s ↔ InjOn g (f '' s) := ⟨image_of_comp, fun h ↦ InjOn.comp h hf <| mapsTo_image f s⟩ lemma InjOn.iterate {f : α → α} {s : Set α} (h : InjOn f s) (hf : MapsTo f s s) : ∀ n, InjOn f^[n] s | 0 => injOn_id _ | (n + 1) => (h.iterate hf n).comp h hf lemma injOn_of_subsingleton [Subsingleton α] (f : α → β) (s : Set α) : InjOn f s := (injective_of_subsingleton _).injOn theorem _root_.Function.Injective.injOn_range (h : Injective (g ∘ f)) : InjOn g (range f) := by rintro _ ⟨x, rfl⟩ _ ⟨y, rfl⟩ H exact congr_arg f (h H) theorem _root_.Set.InjOn.injective_iff (s : Set β) (h : InjOn g s) (hs : range f ⊆ s) : Injective (g ∘ f) ↔ Injective f := ⟨(·.of_comp), fun h _ ↦ by aesop⟩ theorem exists_injOn_iff_injective [Nonempty β] : (∃ f : α → β, InjOn f s) ↔ ∃ f : s → β, Injective f := ⟨fun ⟨_, hf⟩ => ⟨_, hf.injective⟩, fun ⟨f, hf⟩ => by lift f to α → β using trivial exact ⟨f, injOn_iff_injective.2 hf⟩⟩ theorem injOn_preimage {B : Set (Set β)} (hB : B ⊆ 𝒫 range f) : InjOn (preimage f) B := fun _ hs _ ht hst => (preimage_eq_preimage' (hB hs) (hB ht)).1 hst theorem InjOn.mem_of_mem_image {x} (hf : InjOn f s) (hs : s₁ ⊆ s) (h : x ∈ s) (h₁ : f x ∈ f '' s₁) : x ∈ s₁ := let ⟨_, h', Eq⟩ := h₁ hf (hs h') h Eq ▸ h' theorem InjOn.mem_image_iff {x} (hf : InjOn f s) (hs : s₁ ⊆ s) (hx : x ∈ s) : f x ∈ f '' s₁ ↔ x ∈ s₁ := ⟨hf.mem_of_mem_image hs hx, mem_image_of_mem f⟩ theorem InjOn.preimage_image_inter (hf : InjOn f s) (hs : s₁ ⊆ s) : f ⁻¹' (f '' s₁) ∩ s = s₁ := ext fun _ => ⟨fun ⟨h₁, h₂⟩ => hf.mem_of_mem_image hs h₂ h₁, fun h => ⟨mem_image_of_mem _ h, hs h⟩⟩ theorem EqOn.cancel_left (h : s.EqOn (g ∘ f₁) (g ∘ f₂)) (hg : t.InjOn g) (hf₁ : s.MapsTo f₁ t) (hf₂ : s.MapsTo f₂ t) : s.EqOn f₁ f₂ := fun _ ha => hg (hf₁ ha) (hf₂ ha) (h ha) theorem InjOn.cancel_left (hg : t.InjOn g) (hf₁ : s.MapsTo f₁ t) (hf₂ : s.MapsTo f₂ t) : s.EqOn (g ∘ f₁) (g ∘ f₂) ↔ s.EqOn f₁ f₂ := ⟨fun h => h.cancel_left hg hf₁ hf₂, EqOn.comp_left⟩ lemma InjOn.image_inter {s t u : Set α} (hf : u.InjOn f) (hs : s ⊆ u) (ht : t ⊆ u) : f '' (s ∩ t) = f '' s ∩ f '' t := by apply Subset.antisymm (image_inter_subset _ _ _) intro x ⟨⟨y, ys, hy⟩, ⟨z, zt, hz⟩⟩ have : y = z := by apply hf (hs ys) (ht zt) rwa [← hz] at hy rw [← this] at zt exact ⟨y, ⟨ys, zt⟩, hy⟩ lemma InjOn.image (h : s.InjOn f) : s.powerset.InjOn (image f) := fun s₁ hs₁ s₂ hs₂ h' ↦ by rw [← h.preimage_image_inter hs₁, h', h.preimage_image_inter hs₂] theorem InjOn.image_eq_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) : f '' s₁ = f '' s₂ ↔ s₁ = s₂ := h.image.eq_iff h₁ h₂ lemma InjOn.image_subset_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) : f '' s₁ ⊆ f '' s₂ ↔ s₁ ⊆ s₂ := by refine ⟨fun h' ↦ ?_, image_subset _⟩ rw [← h.preimage_image_inter h₁, ← h.preimage_image_inter h₂] exact inter_subset_inter_left _ (preimage_mono h') lemma InjOn.image_ssubset_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) : f '' s₁ ⊂ f '' s₂ ↔ s₁ ⊂ s₂ := by simp_rw [ssubset_def, h.image_subset_image_iff h₁ h₂, h.image_subset_image_iff h₂ h₁] -- TODO: can this move to a better place? theorem _root_.Disjoint.image {s t u : Set α} {f : α → β} (h : Disjoint s t) (hf : u.InjOn f) (hs : s ⊆ u) (ht : t ⊆ u) : Disjoint (f '' s) (f '' t) := by rw [disjoint_iff_inter_eq_empty] at h ⊢ rw [← hf.image_inter hs ht, h, image_empty] lemma InjOn.image_diff {t : Set α} (h : s.InjOn f) : f '' (s \ t) = f '' s \ f '' (s ∩ t) := by refine subset_antisymm (subset_diff.2 ⟨image_subset f diff_subset, ?_⟩) (diff_subset_iff.2 (by rw [← image_union, inter_union_diff])) exact Disjoint.image disjoint_sdiff_inter h diff_subset inter_subset_left lemma InjOn.image_diff_subset {f : α → β} {t : Set α} (h : InjOn f s) (hst : t ⊆ s) : f '' (s \ t) = f '' s \ f '' t := by rw [h.image_diff, inter_eq_self_of_subset_right hst] alias image_diff_of_injOn := InjOn.image_diff_subset theorem InjOn.imageFactorization_injective (h : InjOn f s) : Injective (s.imageFactorization f) := fun ⟨x, hx⟩ ⟨y, hy⟩ h' ↦ by simpa [imageFactorization, h.eq_iff hx hy] using h' @[simp] theorem imageFactorization_injective_iff : Injective (s.imageFactorization f) ↔ InjOn f s := ⟨fun h x hx y hy _ ↦ by simpa using @h ⟨x, hx⟩ ⟨y, hy⟩ (by simpa [imageFactorization]), InjOn.imageFactorization_injective⟩ end injOn section graphOn variable {x : α × β} lemma graphOn_univ_inj {g : α → β} : univ.graphOn f = univ.graphOn g ↔ f = g := by simp lemma graphOn_univ_injective : Injective (univ.graphOn : (α → β) → Set (α × β)) := fun _f _g ↦ graphOn_univ_inj.1 lemma exists_eq_graphOn_image_fst [Nonempty β] {s : Set (α × β)} : (∃ f : α → β, s = graphOn f (Prod.fst '' s)) ↔ InjOn Prod.fst s := by refine ⟨?_, fun h ↦ ?_⟩ · rintro ⟨f, hf⟩ rw [hf] exact InjOn.image_of_comp <| injOn_id _ · have : ∀ x ∈ Prod.fst '' s, ∃ y, (x, y) ∈ s := forall_mem_image.2 fun (x, y) h ↦ ⟨y, h⟩ choose! f hf using this rw [forall_mem_image] at hf use f rw [graphOn, image_image, EqOn.image_eq_self] exact fun x hx ↦ h (hf hx) hx rfl lemma exists_eq_graphOn [Nonempty β] {s : Set (α × β)} : (∃ f t, s = graphOn f t) ↔ InjOn Prod.fst s := .trans ⟨fun ⟨f, t, hs⟩ ↦ ⟨f, by rw [hs, image_fst_graphOn]⟩, fun ⟨f, hf⟩ ↦ ⟨f, _, hf⟩⟩ exists_eq_graphOn_image_fst end graphOn /-! ### Surjectivity on a set -/ section surjOn theorem SurjOn.subset_range (h : SurjOn f s t) : t ⊆ range f := Subset.trans h <| image_subset_range f s theorem surjOn_iff_exists_map_subtype : SurjOn f s t ↔ ∃ (t' : Set β) (g : s → t'), t ⊆ t' ∧ Surjective g ∧ ∀ x : s, f x = g x := ⟨fun h => ⟨_, (mapsTo_image f s).restrict f s _, h, surjective_mapsTo_image_restrict _ _, fun _ => rfl⟩, fun ⟨t', g, htt', hg, hfg⟩ y hy => let ⟨x, hx⟩ := hg ⟨y, htt' hy⟩ ⟨x, x.2, by rw [hfg, hx, Subtype.coe_mk]⟩⟩ theorem surjOn_empty (f : α → β) (s : Set α) : SurjOn f s ∅ := empty_subset _ @[simp] theorem surjOn_empty_iff : SurjOn f ∅ t ↔ t = ∅ := by simp [SurjOn, subset_empty_iff] @[simp] lemma surjOn_singleton : SurjOn f s {b} ↔ b ∈ f '' s := singleton_subset_iff theorem surjOn_image (f : α → β) (s : Set α) : SurjOn f s (f '' s) := Subset.rfl theorem SurjOn.comap_nonempty (h : SurjOn f s t) (ht : t.Nonempty) : s.Nonempty := (ht.mono h).of_image theorem SurjOn.congr (h : SurjOn f₁ s t) (H : EqOn f₁ f₂ s) : SurjOn f₂ s t := by rwa [SurjOn, ← H.image_eq] theorem EqOn.surjOn_iff (h : EqOn f₁ f₂ s) : SurjOn f₁ s t ↔ SurjOn f₂ s t := ⟨fun H => H.congr h, fun H => H.congr h.symm⟩ theorem SurjOn.mono (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) (hf : SurjOn f s₁ t₂) : SurjOn f s₂ t₁ := Subset.trans ht <| Subset.trans hf <| image_subset _ hs theorem SurjOn.union (h₁ : SurjOn f s t₁) (h₂ : SurjOn f s t₂) : SurjOn f s (t₁ ∪ t₂) := fun _ hx => hx.elim (fun hx => h₁ hx) fun hx => h₂ hx theorem SurjOn.union_union (h₁ : SurjOn f s₁ t₁) (h₂ : SurjOn f s₂ t₂) : SurjOn f (s₁ ∪ s₂) (t₁ ∪ t₂) := (h₁.mono subset_union_left (Subset.refl _)).union (h₂.mono subset_union_right (Subset.refl _)) theorem SurjOn.inter_inter (h₁ : SurjOn f s₁ t₁) (h₂ : SurjOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) : SurjOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := by intro y hy rcases h₁ hy.1 with ⟨x₁, hx₁, rfl⟩ rcases h₂ hy.2 with ⟨x₂, hx₂, heq⟩ obtain rfl : x₁ = x₂ := h (Or.inl hx₁) (Or.inr hx₂) heq.symm exact mem_image_of_mem f ⟨hx₁, hx₂⟩ theorem SurjOn.inter (h₁ : SurjOn f s₁ t) (h₂ : SurjOn f s₂ t) (h : InjOn f (s₁ ∪ s₂)) : SurjOn f (s₁ ∩ s₂) t := inter_self t ▸ h₁.inter_inter h₂ h lemma surjOn_id (s : Set α) : SurjOn id s s := by simp [SurjOn] theorem SurjOn.comp (hg : SurjOn g t p) (hf : SurjOn f s t) : SurjOn (g ∘ f) s p := Subset.trans hg <| Subset.trans (image_subset g hf) <| image_comp g f s ▸ Subset.refl _ lemma SurjOn.of_comp (h : SurjOn (g ∘ f) s p) (hr : MapsTo f s t) : SurjOn g t p := by intro z hz obtain ⟨x, hx, rfl⟩ := h hz exact ⟨f x, hr hx, rfl⟩ lemma surjOn_comp_iff : SurjOn (g ∘ f) s p ↔ SurjOn g (f '' s) p := ⟨fun h ↦ h.of_comp <| mapsTo_image f s, fun h ↦ h.comp <| surjOn_image _ _⟩ lemma SurjOn.iterate {f : α → α} {s : Set α} (h : SurjOn f s s) : ∀ n, SurjOn f^[n] s s | 0 => surjOn_id _ | (n + 1) => (h.iterate n).comp h lemma SurjOn.comp_left (hf : SurjOn f s t) (g : β → γ) : SurjOn (g ∘ f) s (g '' t) := by rw [SurjOn, image_comp g f]; exact image_subset _ hf lemma SurjOn.comp_right {s : Set β} {t : Set γ} (hf : Surjective f) (hg : SurjOn g s t) : SurjOn (g ∘ f) (f ⁻¹' s) t := by rwa [SurjOn, image_comp g f, image_preimage_eq _ hf] lemma surjOn_of_subsingleton' [Subsingleton β] (f : α → β) (h : t.Nonempty → s.Nonempty) : SurjOn f s t := fun _ ha ↦ Subsingleton.mem_iff_nonempty.2 <| (h ⟨_, ha⟩).image _ lemma surjOn_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : SurjOn f s s := surjOn_of_subsingleton' _ id theorem surjective_iff_surjOn_univ : Surjective f ↔ SurjOn f univ univ := by simp [Surjective, SurjOn, subset_def] theorem SurjOn.image_eq_of_mapsTo (h₁ : SurjOn f s t) (h₂ : MapsTo f s t) : f '' s = t := eq_of_subset_of_subset h₂.image_subset h₁ theorem image_eq_iff_surjOn_mapsTo : f '' s = t ↔ s.SurjOn f t ∧ s.MapsTo f t := by refine ⟨?_, fun h => h.1.image_eq_of_mapsTo h.2⟩ rintro rfl exact ⟨s.surjOn_image f, s.mapsTo_image f⟩ lemma SurjOn.image_preimage (h : Set.SurjOn f s t) (ht : t₁ ⊆ t) : f '' (f ⁻¹' t₁) = t₁ := image_preimage_eq_iff.2 fun _ hx ↦ mem_range_of_mem_image f s <| h <| ht hx theorem SurjOn.mapsTo_compl (h : SurjOn f s t) (h' : Injective f) : MapsTo f sᶜ tᶜ := fun _ hs ht => let ⟨_, hx', HEq⟩ := h ht hs <| h' HEq ▸ hx' theorem MapsTo.surjOn_compl (h : MapsTo f s t) (h' : Surjective f) : SurjOn f sᶜ tᶜ := h'.forall.2 fun _ ht => (mem_image_of_mem _) fun hs => ht (h hs) theorem EqOn.cancel_right (hf : s.EqOn (g₁ ∘ f) (g₂ ∘ f)) (hf' : s.SurjOn f t) : t.EqOn g₁ g₂ := by intro b hb obtain ⟨a, ha, rfl⟩ := hf' hb exact hf ha theorem SurjOn.cancel_right (hf : s.SurjOn f t) (hf' : s.MapsTo f t) : s.EqOn (g₁ ∘ f) (g₂ ∘ f) ↔ t.EqOn g₁ g₂ := ⟨fun h => h.cancel_right hf, fun h => h.comp_right hf'⟩ theorem eqOn_comp_right_iff : s.EqOn (g₁ ∘ f) (g₂ ∘ f) ↔ (f '' s).EqOn g₁ g₂ := (s.surjOn_image f).cancel_right <| s.mapsTo_image f theorem SurjOn.forall {p : β → Prop} (hf : s.SurjOn f t) (hf' : s.MapsTo f t) : (∀ y ∈ t, p y) ↔ (∀ x ∈ s, p (f x)) := ⟨fun H x hx ↦ H (f x) (hf' hx), fun H _y hy ↦ let ⟨x, hx, hxy⟩ := hf hy; hxy ▸ H x hx⟩ end surjOn /-! ### Bijectivity -/ section bijOn theorem BijOn.mapsTo (h : BijOn f s t) : MapsTo f s t := h.left theorem BijOn.injOn (h : BijOn f s t) : InjOn f s := h.right.left theorem BijOn.surjOn (h : BijOn f s t) : SurjOn f s t := h.right.right theorem BijOn.mk (h₁ : MapsTo f s t) (h₂ : InjOn f s) (h₃ : SurjOn f s t) : BijOn f s t := ⟨h₁, h₂, h₃⟩ theorem bijOn_empty (f : α → β) : BijOn f ∅ ∅ := ⟨mapsTo_empty f ∅, injOn_empty f, surjOn_empty f ∅⟩ @[simp] theorem bijOn_empty_iff_left : BijOn f s ∅ ↔ s = ∅ := ⟨fun h ↦ by simpa using h.mapsTo, by rintro rfl; exact bijOn_empty f⟩ @[simp] theorem bijOn_empty_iff_right : BijOn f ∅ t ↔ t = ∅ := ⟨fun h ↦ by simpa using h.surjOn, by rintro rfl; exact bijOn_empty f⟩ @[simp] lemma bijOn_singleton : BijOn f {a} {b} ↔ f a = b := by simp [BijOn, eq_comm] theorem BijOn.inter_mapsTo (h₁ : BijOn f s₁ t₁) (h₂ : MapsTo f s₂ t₂) (h₃ : s₁ ∩ f ⁻¹' t₂ ⊆ s₂) : BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := ⟨h₁.mapsTo.inter_inter h₂, h₁.injOn.mono inter_subset_left, fun _ hy => let ⟨x, hx, hxy⟩ := h₁.surjOn hy.1 ⟨x, ⟨hx, h₃ ⟨hx, hxy.symm.subst hy.2⟩⟩, hxy⟩⟩ theorem MapsTo.inter_bijOn (h₁ : MapsTo f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h₃ : s₂ ∩ f ⁻¹' t₁ ⊆ s₁) : BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := inter_comm s₂ s₁ ▸ inter_comm t₂ t₁ ▸ h₂.inter_mapsTo h₁ h₃ theorem BijOn.inter (h₁ : BijOn f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) : BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := ⟨h₁.mapsTo.inter_inter h₂.mapsTo, h₁.injOn.mono inter_subset_left, h₁.surjOn.inter_inter h₂.surjOn h⟩ theorem BijOn.union (h₁ : BijOn f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) : BijOn f (s₁ ∪ s₂) (t₁ ∪ t₂) := ⟨h₁.mapsTo.union_union h₂.mapsTo, h, h₁.surjOn.union_union h₂.surjOn⟩ theorem BijOn.subset_range (h : BijOn f s t) : t ⊆ range f := h.surjOn.subset_range theorem InjOn.bijOn_image (h : InjOn f s) : BijOn f s (f '' s) := BijOn.mk (mapsTo_image f s) h (Subset.refl _) theorem BijOn.congr (h₁ : BijOn f₁ s t) (h : EqOn f₁ f₂ s) : BijOn f₂ s t := BijOn.mk (h₁.mapsTo.congr h) (h₁.injOn.congr h) (h₁.surjOn.congr h) theorem EqOn.bijOn_iff (H : EqOn f₁ f₂ s) : BijOn f₁ s t ↔ BijOn f₂ s t := ⟨fun h => h.congr H, fun h => h.congr H.symm⟩ theorem BijOn.image_eq (h : BijOn f s t) : f '' s = t := h.surjOn.image_eq_of_mapsTo h.mapsTo lemma BijOn.forall {p : β → Prop} (hf : BijOn f s t) : (∀ b ∈ t, p b) ↔ ∀ a ∈ s, p (f a) where mp h _ ha := h _ <| hf.mapsTo ha mpr h b hb := by obtain ⟨a, ha, rfl⟩ := hf.surjOn hb; exact h _ ha lemma BijOn.exists {p : β → Prop} (hf : BijOn f s t) : (∃ b ∈ t, p b) ↔ ∃ a ∈ s, p (f a) where mp := by rintro ⟨b, hb, h⟩; obtain ⟨a, ha, rfl⟩ := hf.surjOn hb; exact ⟨a, ha, h⟩ mpr := by rintro ⟨a, ha, h⟩; exact ⟨f a, hf.mapsTo ha, h⟩ lemma _root_.Equiv.image_eq_iff_bijOn (e : α ≃ β) : e '' s = t ↔ BijOn e s t := ⟨fun h ↦ ⟨(mapsTo_image e s).mono_right h.subset, e.injective.injOn, h ▸ surjOn_image e s⟩, BijOn.image_eq⟩ lemma bijOn_id (s : Set α) : BijOn id s s := ⟨s.mapsTo_id, s.injOn_id, s.surjOn_id⟩ theorem BijOn.comp (hg : BijOn g t p) (hf : BijOn f s t) : BijOn (g ∘ f) s p := BijOn.mk (hg.mapsTo.comp hf.mapsTo) (hg.injOn.comp hf.injOn hf.mapsTo) (hg.surjOn.comp hf.surjOn) /-- If `f : α → β` and `g : β → γ` and if `f` is injective on `s`, then `f ∘ g` is a bijection on `s` iff `g` is a bijection on `f '' s`. -/ theorem bijOn_comp_iff (hf : InjOn f s) : BijOn (g ∘ f) s p ↔ BijOn g (f '' s) p := by simp only [BijOn, InjOn.comp_iff, surjOn_comp_iff, mapsTo_image_iff, hf] /-- If we have a commutative square ``` α --f--> β | | p₁ p₂ | | \/ \/ γ --g--> δ ``` and `f` induces a bijection from `s : Set α` to `t : Set β`, then `g` induces a bijection from the image of `s` to the image of `t`, as long as `g` is is injective on the image of `s`. -/ theorem bijOn_image_image {p₁ : α → γ} {p₂ : β → δ} {g : γ → δ} (comm : ∀ a, p₂ (f a) = g (p₁ a)) (hbij : BijOn f s t) (hinj: InjOn g (p₁ '' s)) : BijOn g (p₁ '' s) (p₂ '' t) := by obtain ⟨h1, h2, h3⟩ := hbij refine ⟨?_, hinj, ?_⟩ · rintro _ ⟨a, ha, rfl⟩ exact ⟨f a, h1 ha, by rw [comm a]⟩ · rintro _ ⟨b, hb, rfl⟩ obtain ⟨a, ha, rfl⟩ := h3 hb rw [← image_comp, comm] exact ⟨a, ha, rfl⟩ lemma BijOn.iterate {f : α → α} {s : Set α} (h : BijOn f s s) : ∀ n, BijOn f^[n] s s | 0 => s.bijOn_id | (n + 1) => (h.iterate n).comp h lemma bijOn_of_subsingleton' [Subsingleton α] [Subsingleton β] (f : α → β) (h : s.Nonempty ↔ t.Nonempty) : BijOn f s t := ⟨mapsTo_of_subsingleton' _ h.1, injOn_of_subsingleton _ _, surjOn_of_subsingleton' _ h.2⟩ lemma bijOn_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : BijOn f s s := bijOn_of_subsingleton' _ Iff.rfl theorem BijOn.bijective (h : BijOn f s t) : Bijective (h.mapsTo.restrict f s t) := ⟨fun x y h' => Subtype.ext <| h.injOn x.2 y.2 <| Subtype.ext_iff.1 h', fun ⟨_, hy⟩ => let ⟨x, hx, hxy⟩ := h.surjOn hy ⟨⟨x, hx⟩, Subtype.eq hxy⟩⟩ theorem bijective_iff_bijOn_univ : Bijective f ↔ BijOn f univ univ := Iff.intro (fun h => let ⟨inj, surj⟩ := h ⟨mapsTo_univ f _, inj.injOn, Iff.mp surjective_iff_surjOn_univ surj⟩) fun h => let ⟨_map, inj, surj⟩ := h ⟨Iff.mpr injective_iff_injOn_univ inj, Iff.mpr surjective_iff_surjOn_univ surj⟩ alias ⟨_root_.Function.Bijective.bijOn_univ, _⟩ := bijective_iff_bijOn_univ theorem BijOn.compl (hst : BijOn f s t) (hf : Bijective f) : BijOn f sᶜ tᶜ := ⟨hst.surjOn.mapsTo_compl hf.1, hf.1.injOn, hst.mapsTo.surjOn_compl hf.2⟩ theorem BijOn.subset_right {r : Set β} (hf : BijOn f s t) (hrt : r ⊆ t) : BijOn f (s ∩ f ⁻¹' r) r := by refine ⟨inter_subset_right, hf.injOn.mono inter_subset_left, fun x hx ↦ ?_⟩ obtain ⟨y, hy, rfl⟩ := hf.surjOn (hrt hx) exact ⟨y, ⟨hy, hx⟩, rfl⟩ theorem BijOn.subset_left {r : Set α} (hf : BijOn f s t) (hrs : r ⊆ s) : BijOn f r (f '' r) := (hf.injOn.mono hrs).bijOn_image theorem BijOn.insert_iff (ha : a ∉ s) (hfa : f a ∉ t) : BijOn f (insert a s) (insert (f a) t) ↔ BijOn f s t where mp h := by have := congrArg (· \ {f a}) (image_insert_eq ▸ h.image_eq) simp only [mem_singleton_iff, insert_diff_of_mem] at this rw [diff_singleton_eq_self hfa, diff_singleton_eq_self] at this · exact ⟨by simp [← this, mapsTo'], h.injOn.mono (subset_insert ..), by simp [← this, surjOn_image]⟩ simp only [mem_image, not_exists, not_and] intro x hx rw [h.injOn.eq_iff (by simp [hx]) (by simp)] exact ha ∘ (· ▸ hx) mpr h := by repeat rw [insert_eq] refine (bijOn_singleton.mpr rfl).union h ?_ simp only [singleton_union, injOn_insert fun x ↦ (hfa (h.mapsTo x)), h.injOn, mem_image, not_exists, not_and, true_and] exact fun _ hx h₂ ↦ hfa (h₂ ▸ h.mapsTo hx) theorem BijOn.insert (h₁ : BijOn f s t) (h₂ : f a ∉ t) : BijOn f (insert a s) (insert (f a) t) := (insert_iff (h₂ <| h₁.mapsTo ·) h₂).mpr h₁ theorem BijOn.sdiff_singleton (h₁ : BijOn f s t) (h₂ : a ∈ s) : BijOn f (s \ {a}) (t \ {f a}) := by convert h₁.subset_left diff_subset simp [h₁.injOn.image_diff, h₁.image_eq, h₂, inter_eq_self_of_subset_right] end bijOn /-! ### left inverse -/ namespace LeftInvOn theorem eqOn (h : LeftInvOn f' f s) : EqOn (f' ∘ f) id s := h theorem eq (h : LeftInvOn f' f s) {x} (hx : x ∈ s) : f' (f x) = x := h hx theorem congr_left (h₁ : LeftInvOn f₁' f s) {t : Set β} (h₁' : MapsTo f s t) (heq : EqOn f₁' f₂' t) : LeftInvOn f₂' f s := fun _ hx => heq (h₁' hx) ▸ h₁ hx theorem congr_right (h₁ : LeftInvOn f₁' f₁ s) (heq : EqOn f₁ f₂ s) : LeftInvOn f₁' f₂ s := fun _ hx => heq hx ▸ h₁ hx theorem injOn (h : LeftInvOn f₁' f s) : InjOn f s := fun x₁ h₁ x₂ h₂ heq => calc x₁ = f₁' (f x₁) := Eq.symm <| h h₁ _ = f₁' (f x₂) := congr_arg f₁' heq _ = x₂ := h h₂ theorem surjOn (h : LeftInvOn f' f s) (hf : MapsTo f s t) : SurjOn f' t s := fun x hx => ⟨f x, hf hx, h hx⟩ theorem mapsTo (h : LeftInvOn f' f s) (hf : SurjOn f s t) : MapsTo f' t s := fun y hy => by let ⟨x, hs, hx⟩ := hf hy rwa [← hx, h hs] lemma _root_.Set.leftInvOn_id (s : Set α) : LeftInvOn id id s := fun _ _ ↦ rfl theorem comp (hf' : LeftInvOn f' f s) (hg' : LeftInvOn g' g t) (hf : MapsTo f s t) : LeftInvOn (f' ∘ g') (g ∘ f) s := fun x h => calc (f' ∘ g') ((g ∘ f) x) = f' (f x) := congr_arg f' (hg' (hf h)) _ = x := hf' h theorem mono (hf : LeftInvOn f' f s) (ht : s₁ ⊆ s) : LeftInvOn f' f s₁ := fun _ hx => hf (ht hx) theorem image_inter' (hf : LeftInvOn f' f s) : f '' (s₁ ∩ s) = f' ⁻¹' s₁ ∩ f '' s := by apply Subset.antisymm · rintro _ ⟨x, ⟨h₁, h⟩, rfl⟩ exact ⟨by rwa [mem_preimage, hf h], mem_image_of_mem _ h⟩ · rintro _ ⟨h₁, ⟨x, h, rfl⟩⟩ exact mem_image_of_mem _ ⟨by rwa [← hf h], h⟩ theorem image_inter (hf : LeftInvOn f' f s) : f '' (s₁ ∩ s) = f' ⁻¹' (s₁ ∩ s) ∩ f '' s := by rw [hf.image_inter'] refine Subset.antisymm ?_ (inter_subset_inter_left _ (preimage_mono inter_subset_left)) rintro _ ⟨h₁, x, hx, rfl⟩; exact ⟨⟨h₁, by rwa [hf hx]⟩, mem_image_of_mem _ hx⟩ theorem image_image (hf : LeftInvOn f' f s) : f' '' (f '' s) = s := by rw [Set.image_image, image_congr hf, image_id'] theorem image_image' (hf : LeftInvOn f' f s) (hs : s₁ ⊆ s) : f' '' (f '' s₁) = s₁ := (hf.mono hs).image_image end LeftInvOn /-! ### Right inverse -/ section RightInvOn namespace RightInvOn theorem eqOn (h : RightInvOn f' f t) : EqOn (f ∘ f') id t := h theorem eq (h : RightInvOn f' f t) {y} (hy : y ∈ t) : f (f' y) = y := h hy theorem _root_.Set.LeftInvOn.rightInvOn_image (h : LeftInvOn f' f s) : RightInvOn f' f (f '' s) := fun _y ⟨_x, hx, heq⟩ => heq ▸ (congr_arg f <| h.eq hx) theorem congr_left (h₁ : RightInvOn f₁' f t) (heq : EqOn f₁' f₂' t) : RightInvOn f₂' f t := h₁.congr_right heq theorem congr_right (h₁ : RightInvOn f' f₁ t) (hg : MapsTo f' t s) (heq : EqOn f₁ f₂ s) : RightInvOn f' f₂ t := LeftInvOn.congr_left h₁ hg heq theorem surjOn (hf : RightInvOn f' f t) (hf' : MapsTo f' t s) : SurjOn f s t := LeftInvOn.surjOn hf hf' theorem mapsTo (h : RightInvOn f' f t) (hf : SurjOn f' t s) : MapsTo f s t := LeftInvOn.mapsTo h hf lemma _root_.Set.rightInvOn_id (s : Set α) : RightInvOn id id s := fun _ _ ↦ rfl theorem comp (hf : RightInvOn f' f t) (hg : RightInvOn g' g p) (g'pt : MapsTo g' p t) : RightInvOn (f' ∘ g') (g ∘ f) p := LeftInvOn.comp hg hf g'pt theorem mono (hf : RightInvOn f' f t) (ht : t₁ ⊆ t) : RightInvOn f' f t₁ := LeftInvOn.mono hf ht end RightInvOn theorem InjOn.rightInvOn_of_leftInvOn (hf : InjOn f s) (hf' : LeftInvOn f f' t) (h₁ : MapsTo f s t) (h₂ : MapsTo f' t s) : RightInvOn f f' s := fun _ h => hf (h₂ <| h₁ h) h (hf' (h₁ h)) theorem eqOn_of_leftInvOn_of_rightInvOn (h₁ : LeftInvOn f₁' f s) (h₂ : RightInvOn f₂' f t) (h : MapsTo f₂' t s) : EqOn f₁' f₂' t := fun y hy => calc f₁' y = (f₁' ∘ f ∘ f₂') y := congr_arg f₁' (h₂ hy).symm _ = f₂' y := h₁ (h hy) theorem SurjOn.leftInvOn_of_rightInvOn (hf : SurjOn f s t) (hf' : RightInvOn f f' s) : LeftInvOn f f' t := fun y hy => by let ⟨x, hx, heq⟩ := hf hy rw [← heq, hf' hx] end RightInvOn /-! ### Two-side inverses -/ namespace InvOn lemma _root_.Set.invOn_id (s : Set α) : InvOn id id s s := ⟨s.leftInvOn_id, s.rightInvOn_id⟩ lemma comp (hf : InvOn f' f s t) (hg : InvOn g' g t p) (fst : MapsTo f s t) (g'pt : MapsTo g' p t) : InvOn (f' ∘ g') (g ∘ f) s p := ⟨hf.1.comp hg.1 fst, hf.2.comp hg.2 g'pt⟩ @[symm] theorem symm (h : InvOn f' f s t) : InvOn f f' t s := ⟨h.right, h.left⟩ theorem mono (h : InvOn f' f s t) (hs : s₁ ⊆ s) (ht : t₁ ⊆ t) : InvOn f' f s₁ t₁ := ⟨h.1.mono hs, h.2.mono ht⟩ /-- If functions `f'` and `f` are inverse on `s` and `t`, `f` maps `s` into `t`, and `f'` maps `t` into `s`, then `f` is a bijection between `s` and `t`. The `mapsTo` arguments can be deduced from `surjOn` statements using `LeftInvOn.mapsTo` and `RightInvOn.mapsTo`. -/ theorem bijOn (h : InvOn f' f s t) (hf : MapsTo f s t) (hf' : MapsTo f' t s) : BijOn f s t := ⟨hf, h.left.injOn, h.right.surjOn hf'⟩ end InvOn end Set /-! ### `invFunOn` is a left/right inverse -/ namespace Function variable {s : Set α} {f : α → β} {a : α} {b : β} /-- Construct the inverse for a function `f` on domain `s`. This function is a right inverse of `f` on `f '' s`. For a computable version, see `Function.Embedding.invOfMemRange`. -/ noncomputable def invFunOn [Nonempty α] (f : α → β) (s : Set α) (b : β) : α := open scoped Classical in if h : ∃ a, a ∈ s ∧ f a = b then Classical.choose h else Classical.choice ‹Nonempty α› variable [Nonempty α] theorem invFunOn_pos (h : ∃ a ∈ s, f a = b) : invFunOn f s b ∈ s ∧ f (invFunOn f s b) = b := by rw [invFunOn, dif_pos h] exact Classical.choose_spec h theorem invFunOn_mem (h : ∃ a ∈ s, f a = b) : invFunOn f s b ∈ s := (invFunOn_pos h).left theorem invFunOn_eq (h : ∃ a ∈ s, f a = b) : f (invFunOn f s b) = b := (invFunOn_pos h).right theorem invFunOn_neg (h : ¬∃ a ∈ s, f a = b) : invFunOn f s b = Classical.choice ‹Nonempty α› := by rw [invFunOn, dif_neg h] @[simp] theorem invFunOn_apply_mem (h : a ∈ s) : invFunOn f s (f a) ∈ s := invFunOn_mem ⟨a, h, rfl⟩ theorem invFunOn_apply_eq (h : a ∈ s) : f (invFunOn f s (f a)) = f a := invFunOn_eq ⟨a, h, rfl⟩ end Function open Function namespace Set variable {s s₁ s₂ : Set α} {t : Set β} {f : α → β} theorem InjOn.leftInvOn_invFunOn [Nonempty α] (h : InjOn f s) : LeftInvOn (invFunOn f s) f s := fun _a ha => h (invFunOn_apply_mem ha) ha (invFunOn_apply_eq ha) theorem InjOn.invFunOn_image [Nonempty α] (h : InjOn f s₂) (ht : s₁ ⊆ s₂) : invFunOn f s₂ '' (f '' s₁) = s₁ := h.leftInvOn_invFunOn.image_image' ht theorem _root_.Function.leftInvOn_invFunOn_of_subset_image_image [Nonempty α] (h : s ⊆ (invFunOn f s) '' (f '' s)) : LeftInvOn (invFunOn f s) f s := fun x hx ↦ by obtain ⟨-, ⟨x, hx', rfl⟩, rfl⟩ := h hx rw [invFunOn_apply_eq (f := f) hx'] theorem injOn_iff_invFunOn_image_image_eq_self [Nonempty α] : InjOn f s ↔ (invFunOn f s) '' (f '' s) = s := ⟨fun h ↦ h.invFunOn_image Subset.rfl, fun h ↦ (Function.leftInvOn_invFunOn_of_subset_image_image h.symm.subset).injOn⟩ theorem _root_.Function.invFunOn_injOn_image [Nonempty α] (f : α → β) (s : Set α) : Set.InjOn (invFunOn f s) (f '' s) := by rintro _ ⟨x, hx, rfl⟩ _ ⟨x', hx', rfl⟩ he rw [← invFunOn_apply_eq (f := f) hx, he, invFunOn_apply_eq (f := f) hx'] theorem _root_.Function.invFunOn_image_image_subset [Nonempty α] (f : α → β) (s : Set α) : (invFunOn f s) '' (f '' s) ⊆ s := by rintro _ ⟨_, ⟨x,hx,rfl⟩, rfl⟩; exact invFunOn_apply_mem hx theorem SurjOn.rightInvOn_invFunOn [Nonempty α] (h : SurjOn f s t) : RightInvOn (invFunOn f s) f t := fun _y hy => invFunOn_eq <| h hy theorem BijOn.invOn_invFunOn [Nonempty α] (h : BijOn f s t) : InvOn (invFunOn f s) f s t := ⟨h.injOn.leftInvOn_invFunOn, h.surjOn.rightInvOn_invFunOn⟩ theorem SurjOn.invOn_invFunOn [Nonempty α] (h : SurjOn f s t) : InvOn (invFunOn f s) f (invFunOn f s '' t) t := by refine ⟨?_, h.rightInvOn_invFunOn⟩ rintro _ ⟨y, hy, rfl⟩ rw [h.rightInvOn_invFunOn hy] theorem SurjOn.mapsTo_invFunOn [Nonempty α] (h : SurjOn f s t) : MapsTo (invFunOn f s) t s := fun _y hy => mem_preimage.2 <| invFunOn_mem <| h hy /-- This lemma is a special case of `rightInvOn_invFunOn.image_image'`; it may make more sense to use the other lemma directly in an application. -/ theorem SurjOn.image_invFunOn_image_of_subset [Nonempty α] {r : Set β} (hf : SurjOn f s t) (hrt : r ⊆ t) : f '' (f.invFunOn s '' r) = r := hf.rightInvOn_invFunOn.image_image' hrt /-- This lemma is a special case of `rightInvOn_invFunOn.image_image`; it may make more sense to use the other lemma directly in an application. -/ theorem SurjOn.image_invFunOn_image [Nonempty α] (hf : SurjOn f s t) : f '' (f.invFunOn s '' t) = t := hf.rightInvOn_invFunOn.image_image
theorem SurjOn.bijOn_subset [Nonempty α] (h : SurjOn f s t) : BijOn f (invFunOn f s '' t) t := by refine h.invOn_invFunOn.bijOn ?_ (mapsTo_image _ _) rintro _ ⟨y, hy, rfl⟩
Mathlib/Data/Set/Function.lean
979
982
/- Copyright (c) 2023 Xavier Roblot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Xavier Roblot -/ import Mathlib.LinearAlgebra.Matrix.Gershgorin import Mathlib.NumberTheory.NumberField.CanonicalEmbedding.ConvexBody import Mathlib.NumberTheory.NumberField.Units.Basic /-! # Dirichlet theorem on the group of units of a number field This file is devoted to the proof of Dirichlet unit theorem that states that the group of units `(𝓞 K)ˣ` of units of the ring of integers `𝓞 K` of a number field `K` modulo its torsion subgroup is a free `ℤ`-module of rank `card (InfinitePlace K) - 1`. ## Main definitions * `NumberField.Units.rank`: the unit rank of the number field `K`. * `NumberField.Units.fundSystem`: a fundamental system of units of `K`. * `NumberField.Units.basisModTorsion`: a `ℤ`-basis of `(𝓞 K)ˣ ⧸ (torsion K)` as an additive `ℤ`-module. ## Main results * `NumberField.Units.rank_modTorsion`: the `ℤ`-rank of `(𝓞 K)ˣ ⧸ (torsion K)` is equal to `card (InfinitePlace K) - 1`. * `NumberField.Units.exist_unique_eq_mul_prod`: **Dirichlet Unit Theorem**. Any unit of `𝓞 K` can be written uniquely as the product of a root of unity and powers of the units of the fundamental system `fundSystem`. ## Tags number field, units, Dirichlet unit theorem -/ open scoped NumberField noncomputable section open NumberField NumberField.InfinitePlace NumberField.Units variable (K : Type*) [Field K] namespace NumberField.Units.dirichletUnitTheorem /-! ### Dirichlet Unit Theorem We define a group morphism from `(𝓞 K)ˣ` to `logSpace K`, defined as `{w : InfinitePlace K // w ≠ w₀} → ℝ` where `w₀` is a distinguished (arbitrary) infinite place, prove that its kernel is the torsion subgroup (see `logEmbedding_eq_zero_iff`) and that its image, called `unitLattice`, is a full `ℤ`-lattice. It follows that `unitLattice` is a free `ℤ`-module (see `instModuleFree_unitLattice`) of rank `card (InfinitePlaces K) - 1` (see `unitLattice_rank`). To prove that the `unitLattice` is a full `ℤ`-lattice, we need to prove that it is discrete (see `unitLattice_inter_ball_finite`) and that it spans the full space over `ℝ` (see `unitLattice_span_eq_top`); this is the main part of the proof, see the section `span_top` below for more details. -/ open Finset variable {K} section NumberField variable [NumberField K] /-- The distinguished infinite place. -/ def w₀ : InfinitePlace K := (inferInstance : Nonempty (InfinitePlace K)).some variable (K) in /-- The `logSpace` is defined as `{w : InfinitePlace K // w ≠ w₀} → ℝ` where `w₀` is the distinguished infinite place. -/ abbrev logSpace := {w : InfinitePlace K // w ≠ w₀} → ℝ variable (K) in /-- The logarithmic embedding of the units (seen as an `Additive` group). -/ def _root_.NumberField.Units.logEmbedding : Additive ((𝓞 K)ˣ) →+ logSpace K := { toFun := fun x w => mult w.val * Real.log (w.val ↑x.toMul) map_zero' := by simp; rfl map_add' := fun _ _ => by simp [Real.log_mul, mul_add]; rfl } @[simp] theorem logEmbedding_component (x : (𝓞 K)ˣ) (w : {w : InfinitePlace K // w ≠ w₀}) : (logEmbedding K (Additive.ofMul x)) w = mult w.val * Real.log (w.val x) := rfl open scoped Classical in theorem sum_logEmbedding_component (x : (𝓞 K)ˣ) : ∑ w, logEmbedding K (Additive.ofMul x) w = - mult (w₀ : InfinitePlace K) * Real.log (w₀ (x : K)) := by have h := sum_mult_mul_log x rw [Fintype.sum_eq_add_sum_subtype_ne _ w₀, add_comm, add_eq_zero_iff_eq_neg, ← neg_mul] at h simpa [logEmbedding_component] using h end NumberField theorem mult_log_place_eq_zero {x : (𝓞 K)ˣ} {w : InfinitePlace K} : mult w * Real.log (w x) = 0 ↔ w x = 1 := by rw [mul_eq_zero, or_iff_right, Real.log_eq_zero, or_iff_right, or_iff_left] · linarith [(apply_nonneg _ _ : 0 ≤ w x)] · simp only [ne_eq, map_eq_zero, coe_ne_zero x, not_false_eq_true] · refine (ne_of_gt ?_) rw [mult]; split_ifs <;> norm_num variable [NumberField K] theorem logEmbedding_eq_zero_iff {x : (𝓞 K)ˣ} : logEmbedding K (Additive.ofMul x) = 0 ↔ x ∈ torsion K := by rw [mem_torsion] refine ⟨fun h w => ?_, fun h => ?_⟩ · by_cases hw : w = w₀ · suffices -mult w₀ * Real.log (w₀ (x : K)) = 0 by rw [neg_mul, neg_eq_zero, ← hw] at this exact mult_log_place_eq_zero.mp this rw [← sum_logEmbedding_component, sum_eq_zero] exact fun w _ => congrFun h w · exact mult_log_place_eq_zero.mp (congrFun h ⟨w, hw⟩) · ext w
rw [logEmbedding_component, h w.val, Real.log_one, mul_zero, Pi.zero_apply] open scoped Classical in theorem logEmbedding_component_le {r : ℝ} {x : (𝓞 K)ˣ} (hr : 0 ≤ r) (h : ‖logEmbedding K x‖ ≤ r) (w : {w : InfinitePlace K // w ≠ w₀}) : |logEmbedding K (Additive.ofMul x) w| ≤ r := by
Mathlib/NumberTheory/NumberField/Units/DirichletTheorem.lean
122
126
/- Copyright (c) 2022 Violeta Hernández Palacios. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Violeta Hernández Palacios -/ import Mathlib.Algebra.Order.Group.OrderIso import Mathlib.SetTheory.Game.Ordinal import Mathlib.SetTheory.Ordinal.NaturalOps /-! # Birthdays of games There are two related but distinct notions of a birthday within combinatorial game theory. One is the birthday of a pre-game, which represents the "step" at which it is constructed. We define it recursively as the least ordinal larger than the birthdays of its left and right options. On the other hand, the birthday of a game is the smallest birthday among all pre-games that quotient to it. The birthday of a pre-game can be understood as representing the depth of its game tree. On the other hand, the birthday of a game more closely matches Conway's original description. The lemma `SetTheory.Game.birthday_eq_pGameBirthday` links both definitions together. # Main declarations - `SetTheory.PGame.birthday`: The birthday of a pre-game. - `SetTheory.Game.birthday`: The birthday of a game. # Todo - Characterize the birthdays of other basic arithmetical operations. -/ universe u open Ordinal namespace SetTheory open scoped NaturalOps PGame namespace PGame /-- The birthday of a pre-game is inductively defined as the least strict upper bound of the birthdays of its left and right games. It may be thought as the "step" in which a certain game is constructed. -/ noncomputable def birthday : PGame.{u} → Ordinal.{u} | ⟨_, _, xL, xR⟩ => max (lsub.{u, u} fun i => birthday (xL i)) (lsub.{u, u} fun i => birthday (xR i)) theorem birthday_def (x : PGame) : birthday x = max (lsub.{u, u} fun i => birthday (x.moveLeft i)) (lsub.{u, u} fun i => birthday (x.moveRight i)) := by cases x; rw [birthday]; rfl theorem birthday_moveLeft_lt {x : PGame} (i : x.LeftMoves) : (x.moveLeft i).birthday < x.birthday := by cases x; rw [birthday]; exact lt_max_of_lt_left (lt_lsub _ i) theorem birthday_moveRight_lt {x : PGame} (i : x.RightMoves) : (x.moveRight i).birthday < x.birthday := by cases x; rw [birthday]; exact lt_max_of_lt_right (lt_lsub _ i) theorem lt_birthday_iff {x : PGame} {o : Ordinal} : o < x.birthday ↔ (∃ i : x.LeftMoves, o ≤ (x.moveLeft i).birthday) ∨ ∃ i : x.RightMoves, o ≤ (x.moveRight i).birthday := by constructor · rw [birthday_def] intro h rcases lt_max_iff.1 h with h' | h' · left rwa [lt_lsub_iff] at h' · right rwa [lt_lsub_iff] at h' · rintro (⟨i, hi⟩ | ⟨i, hi⟩) · exact hi.trans_lt (birthday_moveLeft_lt i) · exact hi.trans_lt (birthday_moveRight_lt i) theorem Relabelling.birthday_congr : ∀ {x y : PGame.{u}}, x ≡r y → birthday x = birthday y | ⟨xl, xr, xL, xR⟩, ⟨yl, yr, yL, yR⟩, r => by unfold birthday congr 1 all_goals apply lsub_eq_of_range_eq.{u, u, u} ext i; constructor all_goals rintro ⟨j, rfl⟩ · exact ⟨_, (r.moveLeft j).birthday_congr.symm⟩ · exact ⟨_, (r.moveLeftSymm j).birthday_congr⟩ · exact ⟨_, (r.moveRight j).birthday_congr.symm⟩ · exact ⟨_, (r.moveRightSymm j).birthday_congr⟩ @[simp] theorem birthday_eq_zero {x : PGame} : birthday x = 0 ↔ IsEmpty x.LeftMoves ∧ IsEmpty x.RightMoves := by rw [birthday_def, max_eq_zero, lsub_eq_zero_iff, lsub_eq_zero_iff] @[simp] theorem birthday_zero : birthday 0 = 0 := by simp [inferInstanceAs (IsEmpty PEmpty)] @[simp] theorem birthday_one : birthday 1 = 1 := by rw [birthday_def]; simp
@[simp]
Mathlib/SetTheory/Game/Birthday.lean
103
103
/- 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.Control.Basic import Mathlib.Data.Nat.Basic import Mathlib.Data.Option.Basic import Mathlib.Data.List.Defs import Mathlib.Data.List.Monad import Mathlib.Logic.OpClass import Mathlib.Logic.Unique import Mathlib.Order.Basic import Mathlib.Tactic.Common /-! # Basic properties of lists -/ assert_not_exists GroupWithZero assert_not_exists Lattice assert_not_exists Prod.swap_eq_iff_eq_swap assert_not_exists Ring assert_not_exists Set.range open Function open Nat hiding one_pos namespace List universe u v w variable {ι : Type*} {α : Type u} {β : Type v} {γ : Type w} {l₁ l₂ : List α} /-- There is only one list of an empty type -/ instance uniqueOfIsEmpty [IsEmpty α] : Unique (List α) := { instInhabitedList with uniq := fun l => match l with | [] => rfl | a :: _ => isEmptyElim a } instance : Std.LawfulIdentity (α := List α) Append.append [] where left_id := nil_append right_id := append_nil instance : Std.Associative (α := List α) Append.append where assoc := append_assoc @[simp] theorem cons_injective {a : α} : Injective (cons a) := fun _ _ => tail_eq_of_cons_eq theorem singleton_injective : Injective fun a : α => [a] := fun _ _ h => (cons_eq_cons.1 h).1 theorem set_of_mem_cons (l : List α) (a : α) : { x | x ∈ a :: l } = insert a { x | x ∈ l } := Set.ext fun _ => mem_cons /-! ### mem -/ theorem _root_.Decidable.List.eq_or_ne_mem_of_mem [DecidableEq α] {a b : α} {l : List α} (h : a ∈ b :: l) : a = b ∨ a ≠ b ∧ a ∈ l := by by_cases hab : a = b · exact Or.inl hab · exact ((List.mem_cons.1 h).elim Or.inl (fun h => Or.inr ⟨hab, h⟩)) lemma mem_pair {a b c : α} : a ∈ [b, c] ↔ a = b ∨ a = c := by rw [mem_cons, mem_singleton] -- The simpNF linter says that the LHS can be simplified via `List.mem_map`. -- However this is a higher priority lemma. -- It seems the side condition `hf` is not applied by `simpNF`. -- https://github.com/leanprover/std4/issues/207 @[simp 1100, nolint simpNF] theorem mem_map_of_injective {f : α → β} (H : Injective f) {a : α} {l : List α} : f a ∈ map f l ↔ a ∈ l := ⟨fun m => let ⟨_, m', e⟩ := exists_of_mem_map m; H e ▸ m', mem_map_of_mem⟩ @[simp] theorem _root_.Function.Involutive.exists_mem_and_apply_eq_iff {f : α → α} (hf : Function.Involutive f) (x : α) (l : List α) : (∃ y : α, y ∈ l ∧ f y = x) ↔ f x ∈ l := ⟨by rintro ⟨y, h, rfl⟩; rwa [hf y], fun h => ⟨f x, h, hf _⟩⟩ theorem mem_map_of_involutive {f : α → α} (hf : Involutive f) {a : α} {l : List α} : a ∈ map f l ↔ f a ∈ l := by rw [mem_map, hf.exists_mem_and_apply_eq_iff] /-! ### length -/ alias ⟨_, length_pos_of_ne_nil⟩ := length_pos_iff theorem length_pos_iff_ne_nil {l : List α} : 0 < length l ↔ l ≠ [] := ⟨ne_nil_of_length_pos, length_pos_of_ne_nil⟩ theorem exists_of_length_succ {n} : ∀ l : List α, l.length = n + 1 → ∃ h t, l = h :: t | [], H => absurd H.symm <| succ_ne_zero n | h :: t, _ => ⟨h, t, rfl⟩ @[simp] lemma length_injective_iff : Injective (List.length : List α → ℕ) ↔ Subsingleton α := by constructor · intro h; refine ⟨fun x y => ?_⟩; (suffices [x] = [y] by simpa using this); apply h; rfl · intros hα l1 l2 hl induction l1 generalizing l2 <;> cases l2 · rfl · cases hl · cases hl · next ih _ _ => congr · subsingleton · apply ih; simpa using hl @[simp default+1] -- Raise priority above `length_injective_iff`. lemma length_injective [Subsingleton α] : Injective (length : List α → ℕ) := length_injective_iff.mpr inferInstance theorem length_eq_two {l : List α} : l.length = 2 ↔ ∃ a b, l = [a, b] := ⟨fun _ => let [a, b] := l; ⟨a, b, rfl⟩, fun ⟨_, _, e⟩ => e ▸ rfl⟩ theorem length_eq_three {l : List α} : l.length = 3 ↔ ∃ a b c, l = [a, b, c] := ⟨fun _ => let [a, b, c] := l; ⟨a, b, c, rfl⟩, fun ⟨_, _, _, e⟩ => e ▸ rfl⟩ /-! ### set-theoretic notation of lists -/ instance instSingletonList : Singleton α (List α) := ⟨fun x => [x]⟩ instance [DecidableEq α] : Insert α (List α) := ⟨List.insert⟩ instance [DecidableEq α] : LawfulSingleton α (List α) := { insert_empty_eq := fun x => show (if x ∈ ([] : List α) then [] else [x]) = [x] from if_neg not_mem_nil } theorem singleton_eq (x : α) : ({x} : List α) = [x] := rfl theorem insert_neg [DecidableEq α] {x : α} {l : List α} (h : x ∉ l) : Insert.insert x l = x :: l := insert_of_not_mem h theorem insert_pos [DecidableEq α] {x : α} {l : List α} (h : x ∈ l) : Insert.insert x l = l := insert_of_mem h theorem doubleton_eq [DecidableEq α] {x y : α} (h : x ≠ y) : ({x, y} : List α) = [x, y] := by rw [insert_neg, singleton_eq] rwa [singleton_eq, mem_singleton] /-! ### bounded quantifiers over lists -/ theorem forall_mem_of_forall_mem_cons {p : α → Prop} {a : α} {l : List α} (h : ∀ x ∈ a :: l, p x) : ∀ x ∈ l, p x := (forall_mem_cons.1 h).2 theorem exists_mem_cons_of {p : α → Prop} {a : α} (l : List α) (h : p a) : ∃ x ∈ a :: l, p x := ⟨a, mem_cons_self, h⟩ theorem exists_mem_cons_of_exists {p : α → Prop} {a : α} {l : List α} : (∃ x ∈ l, p x) → ∃ x ∈ a :: l, p x := fun ⟨x, xl, px⟩ => ⟨x, mem_cons_of_mem _ xl, px⟩ theorem or_exists_of_exists_mem_cons {p : α → Prop} {a : α} {l : List α} : (∃ x ∈ a :: l, p x) → p a ∨ ∃ x ∈ l, p x := fun ⟨x, xal, px⟩ => Or.elim (eq_or_mem_of_mem_cons xal) (fun h : x = a => by rw [← h]; left; exact px) fun h : x ∈ l => Or.inr ⟨x, h, px⟩ theorem exists_mem_cons_iff (p : α → Prop) (a : α) (l : List α) : (∃ x ∈ a :: l, p x) ↔ p a ∨ ∃ x ∈ l, p x := Iff.intro or_exists_of_exists_mem_cons fun h => Or.elim h (exists_mem_cons_of l) exists_mem_cons_of_exists /-! ### list subset -/ theorem cons_subset_of_subset_of_mem {a : α} {l m : List α} (ainm : a ∈ m) (lsubm : l ⊆ m) : a::l ⊆ m := cons_subset.2 ⟨ainm, lsubm⟩ theorem append_subset_of_subset_of_subset {l₁ l₂ l : List α} (l₁subl : l₁ ⊆ l) (l₂subl : l₂ ⊆ l) : l₁ ++ l₂ ⊆ l := fun _ h ↦ (mem_append.1 h).elim (@l₁subl _) (@l₂subl _) theorem map_subset_iff {l₁ l₂ : List α} (f : α → β) (h : Injective f) : map f l₁ ⊆ map f l₂ ↔ l₁ ⊆ l₂ := by refine ⟨?_, map_subset f⟩; intro h2 x hx rcases mem_map.1 (h2 (mem_map_of_mem hx)) with ⟨x', hx', hxx'⟩ cases h hxx'; exact hx' /-! ### append -/ theorem append_eq_has_append {L₁ L₂ : List α} : List.append L₁ L₂ = L₁ ++ L₂ := rfl theorem append_right_injective (s : List α) : Injective fun t ↦ s ++ t := fun _ _ ↦ append_cancel_left theorem append_left_injective (t : List α) : Injective fun s ↦ s ++ t := fun _ _ ↦ append_cancel_right /-! ### replicate -/ theorem eq_replicate_length {a : α} : ∀ {l : List α}, l = replicate l.length a ↔ ∀ b ∈ l, b = a | [] => by simp | (b :: l) => by simp [eq_replicate_length, replicate_succ] theorem replicate_add (m n) (a : α) : replicate (m + n) a = replicate m a ++ replicate n a := by rw [replicate_append_replicate] theorem replicate_subset_singleton (n) (a : α) : replicate n a ⊆ [a] := fun _ h => mem_singleton.2 (eq_of_mem_replicate h) theorem subset_singleton_iff {a : α} {L : List α} : L ⊆ [a] ↔ ∃ n, L = replicate n a := by simp only [eq_replicate_iff, subset_def, mem_singleton, exists_eq_left'] theorem replicate_right_injective {n : ℕ} (hn : n ≠ 0) : Injective (@replicate α n) := fun _ _ h => (eq_replicate_iff.1 h).2 _ <| mem_replicate.2 ⟨hn, rfl⟩ theorem replicate_right_inj {a b : α} {n : ℕ} (hn : n ≠ 0) : replicate n a = replicate n b ↔ a = b := (replicate_right_injective hn).eq_iff theorem replicate_right_inj' {a b : α} : ∀ {n}, replicate n a = replicate n b ↔ n = 0 ∨ a = b | 0 => by simp | n + 1 => (replicate_right_inj n.succ_ne_zero).trans <| by simp only [n.succ_ne_zero, false_or] theorem replicate_left_injective (a : α) : Injective (replicate · a) := LeftInverse.injective (length_replicate (n := ·)) theorem replicate_left_inj {a : α} {n m : ℕ} : replicate n a = replicate m a ↔ n = m := (replicate_left_injective a).eq_iff @[simp] theorem head?_flatten_replicate {n : ℕ} (h : n ≠ 0) (l : List α) : (List.replicate n l).flatten.head? = l.head? := by obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero h induction l <;> simp [replicate] @[simp] theorem getLast?_flatten_replicate {n : ℕ} (h : n ≠ 0) (l : List α) : (List.replicate n l).flatten.getLast? = l.getLast? := by rw [← List.head?_reverse, ← List.head?_reverse, List.reverse_flatten, List.map_replicate, List.reverse_replicate, head?_flatten_replicate h] /-! ### pure -/ theorem mem_pure (x y : α) : x ∈ (pure y : List α) ↔ x = y := by simp /-! ### bind -/ @[simp] theorem bind_eq_flatMap {α β} (f : α → List β) (l : List α) : l >>= f = l.flatMap f := rfl /-! ### concat -/ /-! ### reverse -/ theorem reverse_cons' (a : α) (l : List α) : reverse (a :: l) = concat (reverse l) a := by simp only [reverse_cons, concat_eq_append] theorem reverse_concat' (l : List α) (a : α) : (l ++ [a]).reverse = a :: l.reverse := by rw [reverse_append]; rfl @[simp] theorem reverse_singleton (a : α) : reverse [a] = [a] := rfl @[simp] theorem reverse_involutive : Involutive (@reverse α) := reverse_reverse @[simp] theorem reverse_injective : Injective (@reverse α) := reverse_involutive.injective theorem reverse_surjective : Surjective (@reverse α) := reverse_involutive.surjective theorem reverse_bijective : Bijective (@reverse α) := reverse_involutive.bijective theorem concat_eq_reverse_cons (a : α) (l : List α) : concat l a = reverse (a :: reverse l) := by simp only [concat_eq_append, reverse_cons, reverse_reverse] theorem map_reverseAux (f : α → β) (l₁ l₂ : List α) : map f (reverseAux l₁ l₂) = reverseAux (map f l₁) (map f l₂) := by simp only [reverseAux_eq, map_append, map_reverse] -- TODO: Rename `List.reverse_perm` to `List.reverse_perm_self` @[simp] lemma reverse_perm' : l₁.reverse ~ l₂ ↔ l₁ ~ l₂ where mp := l₁.reverse_perm.symm.trans mpr := l₁.reverse_perm.trans @[simp] lemma perm_reverse : l₁ ~ l₂.reverse ↔ l₁ ~ l₂ where mp hl := hl.trans l₂.reverse_perm mpr hl := hl.trans l₂.reverse_perm.symm /-! ### getLast -/ attribute [simp] getLast_cons theorem getLast_append_singleton {a : α} (l : List α) : getLast (l ++ [a]) (append_ne_nil_of_right_ne_nil l (cons_ne_nil a _)) = a := by simp [getLast_append] theorem getLast_append_of_right_ne_nil (l₁ l₂ : List α) (h : l₂ ≠ []) : getLast (l₁ ++ l₂) (append_ne_nil_of_right_ne_nil l₁ h) = getLast l₂ h := by induction l₁ with | nil => simp | cons _ _ ih => simp only [cons_append]; rw [List.getLast_cons]; exact ih @[deprecated (since := "2025-02-06")] alias getLast_append' := getLast_append_of_right_ne_nil theorem getLast_concat' {a : α} (l : List α) : getLast (concat l a) (by simp) = a := by simp @[simp] theorem getLast_singleton' (a : α) : getLast [a] (cons_ne_nil a []) = a := rfl @[simp] theorem getLast_cons_cons (a₁ a₂ : α) (l : List α) : getLast (a₁ :: a₂ :: l) (cons_ne_nil _ _) = getLast (a₂ :: l) (cons_ne_nil a₂ l) := rfl theorem dropLast_append_getLast : ∀ {l : List α} (h : l ≠ []), dropLast l ++ [getLast l h] = l | [], h => absurd rfl h | [_], _ => rfl | a :: b :: l, h => by rw [dropLast_cons₂, cons_append, getLast_cons (cons_ne_nil _ _)] congr exact dropLast_append_getLast (cons_ne_nil b l) theorem getLast_congr {l₁ l₂ : List α} (h₁ : l₁ ≠ []) (h₂ : l₂ ≠ []) (h₃ : l₁ = l₂) : getLast l₁ h₁ = getLast l₂ h₂ := by subst l₁; rfl theorem getLast_replicate_succ (m : ℕ) (a : α) : (replicate (m + 1) a).getLast (ne_nil_of_length_eq_add_one length_replicate) = a := by simp only [replicate_succ'] exact getLast_append_singleton _ @[deprecated (since := "2025-02-07")] alias getLast_filter' := getLast_filter_of_pos /-! ### getLast? -/ theorem mem_getLast?_eq_getLast : ∀ {l : List α} {x : α}, x ∈ l.getLast? → ∃ h, x = getLast l h | [], x, hx => False.elim <| by simp at hx | [a], x, hx => have : a = x := by simpa using hx this ▸ ⟨cons_ne_nil a [], rfl⟩ | a :: b :: l, x, hx => by rw [getLast?_cons_cons] at hx rcases mem_getLast?_eq_getLast hx with ⟨_, h₂⟩ use cons_ne_nil _ _ assumption theorem getLast?_eq_getLast_of_ne_nil : ∀ {l : List α} (h : l ≠ []), l.getLast? = some (l.getLast h) | [], h => (h rfl).elim | [_], _ => rfl | _ :: b :: l, _ => @getLast?_eq_getLast_of_ne_nil (b :: l) (cons_ne_nil _ _) theorem mem_getLast?_cons {x y : α} : ∀ {l : List α}, x ∈ l.getLast? → x ∈ (y :: l).getLast? | [], _ => by contradiction | _ :: _, h => h theorem dropLast_append_getLast? : ∀ {l : List α}, ∀ a ∈ l.getLast?, dropLast l ++ [a] = l | [], a, ha => (Option.not_mem_none a ha).elim | [a], _, rfl => rfl | a :: b :: l, c, hc => by rw [getLast?_cons_cons] at hc rw [dropLast_cons₂, cons_append, dropLast_append_getLast? _ hc] theorem getLastI_eq_getLast? [Inhabited α] : ∀ l : List α, l.getLastI = l.getLast?.iget | [] => by simp [getLastI, Inhabited.default] | [_] => rfl | [_, _] => rfl | [_, _, _] => rfl | _ :: _ :: c :: l => by simp [getLastI, getLastI_eq_getLast? (c :: l)] theorem getLast?_append_cons : ∀ (l₁ : List α) (a : α) (l₂ : List α), getLast? (l₁ ++ a :: l₂) = getLast? (a :: l₂) | [], _, _ => rfl | [_], _, _ => rfl | b :: c :: l₁, a, l₂ => by rw [cons_append, cons_append, getLast?_cons_cons, ← cons_append, getLast?_append_cons (c :: l₁)] theorem getLast?_append_of_ne_nil (l₁ : List α) : ∀ {l₂ : List α} (_ : l₂ ≠ []), getLast? (l₁ ++ l₂) = getLast? l₂ | [], hl₂ => by contradiction | b :: l₂, _ => getLast?_append_cons l₁ b l₂ theorem mem_getLast?_append_of_mem_getLast? {l₁ l₂ : List α} {x : α} (h : x ∈ l₂.getLast?) : x ∈ (l₁ ++ l₂).getLast? := by cases l₂ · contradiction · rw [List.getLast?_append_cons] exact h /-! ### head(!?) and tail -/ @[simp] theorem head!_nil [Inhabited α] : ([] : List α).head! = default := rfl @[simp] theorem head_cons_tail (x : List α) (h : x ≠ []) : x.head h :: x.tail = x := by cases x <;> simp at h ⊢ theorem head_eq_getElem_zero {l : List α} (hl : l ≠ []) : l.head hl = l[0]'(length_pos_iff.2 hl) := (getElem_zero _).symm theorem head!_eq_head? [Inhabited α] (l : List α) : head! l = (head? l).iget := by cases l <;> rfl theorem surjective_head! [Inhabited α] : Surjective (@head! α _) := fun x => ⟨[x], rfl⟩ theorem surjective_head? : Surjective (@head? α) := Option.forall.2 ⟨⟨[], rfl⟩, fun x => ⟨[x], rfl⟩⟩ theorem surjective_tail : Surjective (@tail α) | [] => ⟨[], rfl⟩ | a :: l => ⟨a :: a :: l, rfl⟩ theorem eq_cons_of_mem_head? {x : α} : ∀ {l : List α}, x ∈ l.head? → l = x :: tail l | [], h => (Option.not_mem_none _ h).elim | a :: l, h => by simp only [head?, Option.mem_def, Option.some_inj] at h exact h ▸ rfl @[simp] theorem head!_cons [Inhabited α] (a : α) (l : List α) : head! (a :: l) = a := rfl @[simp] theorem head!_append [Inhabited α] (t : List α) {s : List α} (h : s ≠ []) : head! (s ++ t) = head! s := by induction s · contradiction · rfl theorem mem_head?_append_of_mem_head? {s t : List α} {x : α} (h : x ∈ s.head?) : x ∈ (s ++ t).head? := by cases s · contradiction · exact h theorem head?_append_of_ne_nil : ∀ (l₁ : List α) {l₂ : List α} (_ : l₁ ≠ []), head? (l₁ ++ l₂) = head? l₁ | _ :: _, _, _ => rfl theorem tail_append_singleton_of_ne_nil {a : α} {l : List α} (h : l ≠ nil) : tail (l ++ [a]) = tail l ++ [a] := by induction l · contradiction · rw [tail, cons_append, tail] theorem cons_head?_tail : ∀ {l : List α} {a : α}, a ∈ head? l → a :: tail l = l | [], a, h => by contradiction | b :: l, a, h => by simp? at h says simp only [head?_cons, Option.mem_def, Option.some.injEq] at h simp [h] theorem head!_mem_head? [Inhabited α] : ∀ {l : List α}, l ≠ [] → head! l ∈ head? l | [], h => by contradiction | _ :: _, _ => rfl theorem cons_head!_tail [Inhabited α] {l : List α} (h : l ≠ []) : head! l :: tail l = l := cons_head?_tail (head!_mem_head? h) theorem head!_mem_self [Inhabited α] {l : List α} (h : l ≠ nil) : l.head! ∈ l := by have h' : l.head! ∈ l.head! :: l.tail := mem_cons_self rwa [cons_head!_tail h] at h' theorem get_eq_getElem? (l : List α) (i : Fin l.length) : l.get i = l[i]?.get (by simp [getElem?_eq_getElem]) := by simp @[deprecated (since := "2025-02-15")] alias get_eq_get? := get_eq_getElem? theorem exists_mem_iff_getElem {l : List α} {p : α → Prop} : (∃ x ∈ l, p x) ↔ ∃ (i : ℕ) (_ : i < l.length), p l[i] := by simp only [mem_iff_getElem] exact ⟨fun ⟨_x, ⟨i, hi, hix⟩, hxp⟩ ↦ ⟨i, hi, hix ▸ hxp⟩, fun ⟨i, hi, hp⟩ ↦ ⟨_, ⟨i, hi, rfl⟩, hp⟩⟩ theorem forall_mem_iff_getElem {l : List α} {p : α → Prop} : (∀ x ∈ l, p x) ↔ ∀ (i : ℕ) (_ : i < l.length), p l[i] := by simp [mem_iff_getElem, @forall_swap α] theorem get_tail (l : List α) (i) (h : i < l.tail.length) (h' : i + 1 < l.length := (by simp only [length_tail] at h; omega)) : l.tail.get ⟨i, h⟩ = l.get ⟨i + 1, h'⟩ := by cases l <;> [cases h; rfl] /-! ### sublists -/ attribute [refl] List.Sublist.refl theorem Sublist.cons_cons {l₁ l₂ : List α} (a : α) (s : l₁ <+ l₂) : a :: l₁ <+ a :: l₂ := Sublist.cons₂ _ s lemma cons_sublist_cons' {a b : α} : a :: l₁ <+ b :: l₂ ↔ a :: l₁ <+ l₂ ∨ a = b ∧ l₁ <+ l₂ := by constructor · rintro (_ | _) · exact Or.inl ‹_› · exact Or.inr ⟨rfl, ‹_›⟩ · rintro (h | ⟨rfl, h⟩) · exact h.cons _ · rwa [cons_sublist_cons] theorem sublist_cons_of_sublist (a : α) (h : l₁ <+ l₂) : l₁ <+ a :: l₂ := h.cons _ @[deprecated (since := "2025-02-07")] alias sublist_nil_iff_eq_nil := sublist_nil @[simp] lemma sublist_singleton {l : List α} {a : α} : l <+ [a] ↔ l = [] ∨ l = [a] := by constructor <;> rintro (_ | _) <;> aesop theorem Sublist.antisymm (s₁ : l₁ <+ l₂) (s₂ : l₂ <+ l₁) : l₁ = l₂ := s₁.eq_of_length_le s₂.length_le /-- If the first element of two lists are different, then a sublist relation can be reduced. -/ theorem Sublist.of_cons_of_ne {a b} (h₁ : a ≠ b) (h₂ : a :: l₁ <+ b :: l₂) : a :: l₁ <+ l₂ := match h₁, h₂ with | _, .cons _ h => h /-! ### indexOf -/ section IndexOf variable [DecidableEq α] theorem idxOf_cons_eq {a b : α} (l : List α) : b = a → idxOf a (b :: l) = 0 | e => by rw [← e]; exact idxOf_cons_self @[deprecated (since := "2025-01-30")] alias indexOf_cons_eq := idxOf_cons_eq @[simp] theorem idxOf_cons_ne {a b : α} (l : List α) : b ≠ a → idxOf a (b :: l) = succ (idxOf a l) | h => by simp only [idxOf_cons, Bool.cond_eq_ite, beq_iff_eq, if_neg h] @[deprecated (since := "2025-01-30")] alias indexOf_cons_ne := idxOf_cons_ne theorem idxOf_eq_length_iff {a : α} {l : List α} : idxOf a l = length l ↔ a ∉ l := by induction l with | nil => exact iff_of_true rfl not_mem_nil | cons b l ih => simp only [length, mem_cons, idxOf_cons, eq_comm] rw [cond_eq_if] split_ifs with h <;> simp at h · exact iff_of_false (by rintro ⟨⟩) fun H => H <| Or.inl h.symm · simp only [Ne.symm h, false_or] rw [← ih] exact succ_inj @[simp] theorem idxOf_of_not_mem {l : List α} {a : α} : a ∉ l → idxOf a l = length l := idxOf_eq_length_iff.2 @[deprecated (since := "2025-01-30")] alias indexOf_of_not_mem := idxOf_of_not_mem theorem idxOf_le_length {a : α} {l : List α} : idxOf a l ≤ length l := by induction l with | nil => rfl | cons b l ih => ?_ simp only [length, idxOf_cons, cond_eq_if, beq_iff_eq] by_cases h : b = a · rw [if_pos h]; exact Nat.zero_le _ · rw [if_neg h]; exact succ_le_succ ih @[deprecated (since := "2025-01-30")] alias indexOf_le_length := idxOf_le_length theorem idxOf_lt_length_iff {a} {l : List α} : idxOf a l < length l ↔ a ∈ l := ⟨fun h => Decidable.byContradiction fun al => Nat.ne_of_lt h <| idxOf_eq_length_iff.2 al, fun al => (lt_of_le_of_ne idxOf_le_length) fun h => idxOf_eq_length_iff.1 h al⟩ @[deprecated (since := "2025-01-30")] alias indexOf_lt_length_iff := idxOf_lt_length_iff theorem idxOf_append_of_mem {a : α} (h : a ∈ l₁) : idxOf a (l₁ ++ l₂) = idxOf a l₁ := by induction l₁ with | nil => exfalso exact not_mem_nil h | cons d₁ t₁ ih => rw [List.cons_append] by_cases hh : d₁ = a · iterate 2 rw [idxOf_cons_eq _ hh] rw [idxOf_cons_ne _ hh, idxOf_cons_ne _ hh, ih (mem_of_ne_of_mem (Ne.symm hh) h)] @[deprecated (since := "2025-01-30")] alias indexOf_append_of_mem := idxOf_append_of_mem theorem idxOf_append_of_not_mem {a : α} (h : a ∉ l₁) : idxOf a (l₁ ++ l₂) = l₁.length + idxOf a l₂ := by induction l₁ with | nil => rw [List.nil_append, List.length, Nat.zero_add] | cons d₁ t₁ ih => rw [List.cons_append, idxOf_cons_ne _ (ne_of_not_mem_cons h).symm, List.length, ih (not_mem_of_not_mem_cons h), Nat.succ_add] @[deprecated (since := "2025-01-30")] alias indexOf_append_of_not_mem := idxOf_append_of_not_mem end IndexOf /-! ### nth element -/ section deprecated @[simp] theorem getElem?_length (l : List α) : l[l.length]? = none := getElem?_eq_none le_rfl /-- A version of `getElem_map` that can be used for rewriting. -/ theorem getElem_map_rev (f : α → β) {l} {n : Nat} {h : n < l.length} : f l[n] = (map f l)[n]'((l.length_map f).symm ▸ h) := Eq.symm (getElem_map _) theorem get_length_sub_one {l : List α} (h : l.length - 1 < l.length) : l.get ⟨l.length - 1, h⟩ = l.getLast (by rintro rfl; exact Nat.lt_irrefl 0 h) := (getLast_eq_getElem _).symm theorem take_one_drop_eq_of_lt_length {l : List α} {n : ℕ} (h : n < l.length) : (l.drop n).take 1 = [l.get ⟨n, h⟩] := by rw [drop_eq_getElem_cons h, take, take] simp theorem ext_getElem?' {l₁ l₂ : List α} (h' : ∀ n < max l₁.length l₂.length, l₁[n]? = l₂[n]?) : l₁ = l₂ := by apply ext_getElem? intro n rcases Nat.lt_or_ge n <| max l₁.length l₂.length with hn | hn · exact h' n hn · simp_all [Nat.max_le, getElem?_eq_none] @[deprecated (since := "2025-02-15")] alias ext_get?' := ext_getElem?' @[deprecated (since := "2025-02-15")] alias ext_get?_iff := List.ext_getElem?_iff theorem ext_get_iff {l₁ l₂ : List α} : l₁ = l₂ ↔ l₁.length = l₂.length ∧ ∀ n h₁ h₂, get l₁ ⟨n, h₁⟩ = get l₂ ⟨n, h₂⟩ := by constructor · rintro rfl exact ⟨rfl, fun _ _ _ ↦ rfl⟩ · intro ⟨h₁, h₂⟩ exact ext_get h₁ h₂ theorem ext_getElem?_iff' {l₁ l₂ : List α} : l₁ = l₂ ↔ ∀ n < max l₁.length l₂.length, l₁[n]? = l₂[n]? := ⟨by rintro rfl _ _; rfl, ext_getElem?'⟩ @[deprecated (since := "2025-02-15")] alias ext_get?_iff' := ext_getElem?_iff' /-- If two lists `l₁` and `l₂` are the same length and `l₁[n]! = l₂[n]!` for all `n`, then the lists are equal. -/ theorem ext_getElem! [Inhabited α] (hl : length l₁ = length l₂) (h : ∀ n : ℕ, l₁[n]! = l₂[n]!) : l₁ = l₂ := ext_getElem hl fun n h₁ h₂ ↦ by simpa only [← getElem!_pos] using h n @[simp] theorem getElem_idxOf [DecidableEq α] {a : α} : ∀ {l : List α} (h : idxOf a l < l.length), l[idxOf a l] = a | b :: l, h => by by_cases h' : b = a <;> simp [h', if_pos, if_false, getElem_idxOf] @[deprecated (since := "2025-01-30")] alias getElem_indexOf := getElem_idxOf -- This is incorrectly named and should be `get_idxOf`; -- this already exists, so will require a deprecation dance. theorem idxOf_get [DecidableEq α] {a : α} {l : List α} (h) : get l ⟨idxOf a l, h⟩ = a := by simp @[deprecated (since := "2025-01-30")] alias indexOf_get := idxOf_get @[simp] theorem getElem?_idxOf [DecidableEq α] {a : α} {l : List α} (h : a ∈ l) : l[idxOf a l]? = some a := by rw [getElem?_eq_getElem, getElem_idxOf (idxOf_lt_length_iff.2 h)] @[deprecated (since := "2025-01-30")] alias getElem?_indexOf := getElem?_idxOf @[deprecated (since := "2025-02-15")] alias idxOf_get? := getElem?_idxOf @[deprecated (since := "2025-01-30")] alias indexOf_get? := getElem?_idxOf theorem idxOf_inj [DecidableEq α] {l : List α} {x y : α} (hx : x ∈ l) (hy : y ∈ l) : idxOf x l = idxOf y l ↔ x = y := ⟨fun h => by have x_eq_y : get l ⟨idxOf x l, idxOf_lt_length_iff.2 hx⟩ = get l ⟨idxOf y l, idxOf_lt_length_iff.2 hy⟩ := by simp only [h] simp only [idxOf_get] at x_eq_y; exact x_eq_y, fun h => by subst h; rfl⟩ @[deprecated (since := "2025-01-30")] alias indexOf_inj := idxOf_inj theorem get_reverse' (l : List α) (n) (hn') : l.reverse.get n = l.get ⟨l.length - 1 - n, hn'⟩ := by simp theorem eq_cons_of_length_one {l : List α} (h : l.length = 1) : l = [l.get ⟨0, by omega⟩] := by refine ext_get (by convert h) fun n h₁ h₂ => ?_ simp congr omega end deprecated @[simp] theorem getElem_set_of_ne {l : List α} {i j : ℕ} (h : i ≠ j) (a : α) (hj : j < (l.set i a).length) : (l.set i a)[j] = l[j]'(by simpa using hj) := by rw [← Option.some_inj, ← List.getElem?_eq_getElem, List.getElem?_set_ne h, List.getElem?_eq_getElem] /-! ### map -/ -- `List.map_const` (the version with `Function.const` instead of a lambda) is already tagged -- `simp` in Core -- TODO: Upstream the tagging to Core? attribute [simp] map_const' theorem flatMap_pure_eq_map (f : α → β) (l : List α) : l.flatMap (pure ∘ f) = map f l := .symm <| map_eq_flatMap .. theorem flatMap_congr {l : List α} {f g : α → List β} (h : ∀ x ∈ l, f x = g x) : l.flatMap f = l.flatMap g := (congr_arg List.flatten <| map_congr_left h :) theorem infix_flatMap_of_mem {a : α} {as : List α} (h : a ∈ as) (f : α → List α) : f a <:+: as.flatMap f := infix_of_mem_flatten (mem_map_of_mem h) @[simp] theorem map_eq_map {α β} (f : α → β) (l : List α) : f <$> l = map f l := rfl /-- A single `List.map` of a composition of functions is equal to composing a `List.map` with another `List.map`, fully applied. This is the reverse direction of `List.map_map`. -/ theorem comp_map (h : β → γ) (g : α → β) (l : List α) : map (h ∘ g) l = map h (map g l) := map_map.symm /-- Composing a `List.map` with another `List.map` is equal to a single `List.map` of composed functions. -/ @[simp] theorem map_comp_map (g : β → γ) (f : α → β) : map g ∘ map f = map (g ∘ f) := by ext l; rw [comp_map, Function.comp_apply] section map_bijectivity theorem _root_.Function.LeftInverse.list_map {f : α → β} {g : β → α} (h : LeftInverse f g) : LeftInverse (map f) (map g) | [] => by simp_rw [map_nil] | x :: xs => by simp_rw [map_cons, h x, h.list_map xs] nonrec theorem _root_.Function.RightInverse.list_map {f : α → β} {g : β → α} (h : RightInverse f g) : RightInverse (map f) (map g) := h.list_map nonrec theorem _root_.Function.Involutive.list_map {f : α → α} (h : Involutive f) : Involutive (map f) := Function.LeftInverse.list_map h @[simp] theorem map_leftInverse_iff {f : α → β} {g : β → α} : LeftInverse (map f) (map g) ↔ LeftInverse f g := ⟨fun h x => by injection h [x], (·.list_map)⟩ @[simp] theorem map_rightInverse_iff {f : α → β} {g : β → α} : RightInverse (map f) (map g) ↔ RightInverse f g := map_leftInverse_iff @[simp] theorem map_involutive_iff {f : α → α} : Involutive (map f) ↔ Involutive f := map_leftInverse_iff theorem _root_.Function.Injective.list_map {f : α → β} (h : Injective f) : Injective (map f) | [], [], _ => rfl | x :: xs, y :: ys, hxy => by injection hxy with hxy hxys rw [h hxy, h.list_map hxys] @[simp] theorem map_injective_iff {f : α → β} : Injective (map f) ↔ Injective f := by refine ⟨fun h x y hxy => ?_, (·.list_map)⟩ suffices [x] = [y] by simpa using this apply h simp [hxy] theorem _root_.Function.Surjective.list_map {f : α → β} (h : Surjective f) : Surjective (map f) := let ⟨_, h⟩ := h.hasRightInverse; h.list_map.surjective @[simp] theorem map_surjective_iff {f : α → β} : Surjective (map f) ↔ Surjective f := by refine ⟨fun h x => ?_, (·.list_map)⟩ let ⟨[y], hxy⟩ := h [x] exact ⟨_, List.singleton_injective hxy⟩ theorem _root_.Function.Bijective.list_map {f : α → β} (h : Bijective f) : Bijective (map f) := ⟨h.1.list_map, h.2.list_map⟩ @[simp] theorem map_bijective_iff {f : α → β} : Bijective (map f) ↔ Bijective f := by simp_rw [Function.Bijective, map_injective_iff, map_surjective_iff] end map_bijectivity theorem eq_of_mem_map_const {b₁ b₂ : β} {l : List α} (h : b₁ ∈ map (const α b₂) l) : b₁ = b₂ := by rw [map_const] at h; exact eq_of_mem_replicate h /-- `eq_nil_or_concat` in simp normal form -/ lemma eq_nil_or_concat' (l : List α) : l = [] ∨ ∃ L b, l = L ++ [b] := by simpa using l.eq_nil_or_concat /-! ### foldl, foldr -/ theorem foldl_ext (f g : α → β → α) (a : α) {l : List β} (H : ∀ a : α, ∀ b ∈ l, f a b = g a b) : foldl f a l = foldl g a l := by induction l generalizing a with | nil => rfl | cons hd tl ih => unfold foldl rw [ih _ fun a b bin => H a b <| mem_cons_of_mem _ bin, H a hd mem_cons_self] theorem foldr_ext (f g : α → β → β) (b : β) {l : List α} (H : ∀ a ∈ l, ∀ b : β, f a b = g a b) : foldr f b l = foldr g b l := by induction l with | nil => rfl | cons hd tl ih => ?_ simp only [mem_cons, or_imp, forall_and, forall_eq] at H simp only [foldr, ih H.2, H.1] theorem foldl_concat (f : β → α → β) (b : β) (x : α) (xs : List α) : List.foldl f b (xs ++ [x]) = f (List.foldl f b xs) x := by simp only [List.foldl_append, List.foldl] theorem foldr_concat (f : α → β → β) (b : β) (x : α) (xs : List α) : List.foldr f b (xs ++ [x]) = (List.foldr f (f x b) xs) := by simp only [List.foldr_append, List.foldr] theorem foldl_fixed' {f : α → β → α} {a : α} (hf : ∀ b, f a b = a) : ∀ l : List β, foldl f a l = a | [] => rfl | b :: l => by rw [foldl_cons, hf b, foldl_fixed' hf l] theorem foldr_fixed' {f : α → β → β} {b : β} (hf : ∀ a, f a b = b) : ∀ l : List α, foldr f b l = b | [] => rfl | a :: l => by rw [foldr_cons, foldr_fixed' hf l, hf a] @[simp] theorem foldl_fixed {a : α} : ∀ l : List β, foldl (fun a _ => a) a l = a := foldl_fixed' fun _ => rfl @[simp] theorem foldr_fixed {b : β} : ∀ l : List α, foldr (fun _ b => b) b l = b := foldr_fixed' fun _ => rfl @[deprecated foldr_cons_nil (since := "2025-02-10")] theorem foldr_eta (l : List α) : foldr cons [] l = l := foldr_cons_nil theorem reverse_foldl {l : List α} : reverse (foldl (fun t h => h :: t) [] l) = l := by simp theorem foldl_hom₂ (l : List ι) (f : α → β → γ) (op₁ : α → ι → α) (op₂ : β → ι → β) (op₃ : γ → ι → γ) (a : α) (b : β) (h : ∀ a b i, f (op₁ a i) (op₂ b i) = op₃ (f a b) i) : foldl op₃ (f a b) l = f (foldl op₁ a l) (foldl op₂ b l) := Eq.symm <| by revert a b induction l <;> intros <;> [rfl; simp only [*, foldl]] theorem foldr_hom₂ (l : List ι) (f : α → β → γ) (op₁ : ι → α → α) (op₂ : ι → β → β) (op₃ : ι → γ → γ) (a : α) (b : β) (h : ∀ a b i, f (op₁ i a) (op₂ i b) = op₃ i (f a b)) : foldr op₃ (f a b) l = f (foldr op₁ a l) (foldr op₂ b l) := by revert a induction l <;> intros <;> [rfl; simp only [*, foldr]] theorem injective_foldl_comp {l : List (α → α)} {f : α → α} (hl : ∀ f ∈ l, Function.Injective f) (hf : Function.Injective f) : Function.Injective (@List.foldl (α → α) (α → α) Function.comp f l) := by induction l generalizing f with | nil => exact hf | cons lh lt l_ih => apply l_ih fun _ h => hl _ (List.mem_cons_of_mem _ h) apply Function.Injective.comp hf apply hl _ mem_cons_self /-- Consider two lists `l₁` and `l₂` with designated elements `a₁` and `a₂` somewhere in them: `l₁ = x₁ ++ [a₁] ++ z₁` and `l₂ = x₂ ++ [a₂] ++ z₂`. Assume the designated element `a₂` is present in neither `x₁` nor `z₁`. We conclude that the lists are equal (`l₁ = l₂`) if and only if their respective parts are equal (`x₁ = x₂ ∧ a₁ = a₂ ∧ z₁ = z₂`). -/ lemma append_cons_inj_of_not_mem {x₁ x₂ z₁ z₂ : List α} {a₁ a₂ : α} (notin_x : a₂ ∉ x₁) (notin_z : a₂ ∉ z₁) : x₁ ++ a₁ :: z₁ = x₂ ++ a₂ :: z₂ ↔ x₁ = x₂ ∧ a₁ = a₂ ∧ z₁ = z₂ := by constructor · simp only [append_eq_append_iff, cons_eq_append_iff, cons_eq_cons] rintro (⟨c, rfl, ⟨rfl, rfl, rfl⟩ | ⟨d, rfl, rfl⟩⟩ | ⟨c, rfl, ⟨rfl, rfl, rfl⟩ | ⟨d, rfl, rfl⟩⟩) <;> simp_all · rintro ⟨rfl, rfl, rfl⟩ rfl section FoldlEqFoldr -- foldl and foldr coincide when f is commutative and associative variable {f : α → α → α} theorem foldl1_eq_foldr1 [hassoc : Std.Associative f] : ∀ a b l, foldl f a (l ++ [b]) = foldr f b (a :: l) | _, _, nil => rfl | a, b, c :: l => by simp only [cons_append, foldl_cons, foldr_cons, foldl1_eq_foldr1 _ _ l] rw [hassoc.assoc] theorem foldl_eq_of_comm_of_assoc [hcomm : Std.Commutative f] [hassoc : Std.Associative f] : ∀ a b l, foldl f a (b :: l) = f b (foldl f a l) | a, b, nil => hcomm.comm a b | a, b, c :: l => by simp only [foldl_cons] have : RightCommutative f := inferInstance rw [← foldl_eq_of_comm_of_assoc .., this.right_comm, foldl_cons] theorem foldl_eq_foldr [Std.Commutative f] [Std.Associative f] : ∀ a l, foldl f a l = foldr f a l | _, nil => rfl | a, b :: l => by simp only [foldr_cons, foldl_eq_of_comm_of_assoc] rw [foldl_eq_foldr a l] end FoldlEqFoldr section FoldlEqFoldlr' variable {f : α → β → α} variable (hf : ∀ a b c, f (f a b) c = f (f a c) b) include hf theorem foldl_eq_of_comm' : ∀ a b l, foldl f a (b :: l) = f (foldl f a l) b | _, _, [] => rfl | a, b, c :: l => by rw [foldl, foldl, foldl, ← foldl_eq_of_comm' .., foldl, hf] theorem foldl_eq_foldr' : ∀ a l, foldl f a l = foldr (flip f) a l | _, [] => rfl | a, b :: l => by rw [foldl_eq_of_comm' hf, foldr, foldl_eq_foldr' ..]; rfl end FoldlEqFoldlr' section FoldlEqFoldlr' variable {f : α → β → β} theorem foldr_eq_of_comm' (hf : ∀ a b c, f a (f b c) = f b (f a c)) : ∀ a b l, foldr f a (b :: l) = foldr f (f b a) l | _, _, [] => rfl | a, b, c :: l => by rw [foldr, foldr, foldr, hf, ← foldr_eq_of_comm' hf ..]; rfl end FoldlEqFoldlr' section variable {op : α → α → α} [ha : Std.Associative op] /-- Notation for `op a b`. -/ local notation a " ⋆ " b => op a b /-- Notation for `foldl op a l`. -/ local notation l " <*> " a => foldl op a l theorem foldl_op_eq_op_foldr_assoc : ∀ {l : List α} {a₁ a₂}, ((l <*> a₁) ⋆ a₂) = a₁ ⋆ l.foldr (· ⋆ ·) a₂ | [], _, _ => rfl | a :: l, a₁, a₂ => by simp only [foldl_cons, foldr_cons, foldl_assoc, ha.assoc]; rw [foldl_op_eq_op_foldr_assoc] variable [hc : Std.Commutative op] theorem foldl_assoc_comm_cons {l : List α} {a₁ a₂} : ((a₁ :: l) <*> a₂) = a₁ ⋆ l <*> a₂ := by rw [foldl_cons, hc.comm, foldl_assoc] end /-! ### foldlM, foldrM, mapM -/ section FoldlMFoldrM variable {m : Type v → Type w} [Monad m] variable [LawfulMonad m] theorem foldrM_eq_foldr (f : α → β → m β) (b l) : foldrM f b l = foldr (fun a mb => mb >>= f a) (pure b) l := by induction l <;> simp [*] theorem foldlM_eq_foldl (f : β → α → m β) (b l) : List.foldlM f b l = foldl (fun mb a => mb >>= fun b => f b a) (pure b) l := by suffices h : ∀ mb : m β, (mb >>= fun b => List.foldlM f b l) = foldl (fun mb a => mb >>= fun b => f b a) mb l by simp [← h (pure b)] induction l with | nil => intro; simp | cons _ _ l_ih => intro; simp only [List.foldlM, foldl, ← l_ih, functor_norm] end FoldlMFoldrM /-! ### intersperse -/ @[deprecated (since := "2025-02-07")] alias intersperse_singleton := intersperse_single @[deprecated (since := "2025-02-07")] alias intersperse_cons_cons := intersperse_cons₂ /-! ### map for partial functions -/ @[deprecated "Deprecated without replacement." (since := "2025-02-07")] theorem sizeOf_lt_sizeOf_of_mem [SizeOf α] {x : α} {l : List α} (hx : x ∈ l) : SizeOf.sizeOf x < SizeOf.sizeOf l := by induction l with | nil => ?_ | cons h t ih => ?_ <;> cases hx <;> rw [cons.sizeOf_spec] · omega · specialize ih ‹_› omega /-! ### filter -/ theorem length_eq_length_filter_add {l : List (α)} (f : α → Bool) : l.length = (l.filter f).length + (l.filter (! f ·)).length := by simp_rw [← List.countP_eq_length_filter, l.length_eq_countP_add_countP f, Bool.not_eq_true, Bool.decide_eq_false] /-! ### filterMap -/ theorem filterMap_eq_flatMap_toList (f : α → Option β) (l : List α) : l.filterMap f = l.flatMap fun a ↦ (f a).toList := by induction l with | nil => ?_ | cons a l ih => ?_ <;> simp [filterMap_cons] rcases f a <;> simp [ih] theorem filterMap_congr {f g : α → Option β} {l : List α} (h : ∀ x ∈ l, f x = g x) : l.filterMap f = l.filterMap g := by induction l <;> simp_all [filterMap_cons] theorem filterMap_eq_map_iff_forall_eq_some {f : α → Option β} {g : α → β} {l : List α} : l.filterMap f = l.map g ↔ ∀ x ∈ l, f x = some (g x) where mp := by induction l with | nil => simp | cons a l ih => ?_ rcases ha : f a with - | b <;> simp [ha, filterMap_cons] · intro h simpa [show (filterMap f l).length = l.length + 1 from by simp[h], Nat.add_one_le_iff] using List.length_filterMap_le f l · rintro rfl h exact ⟨rfl, ih h⟩ mpr h := Eq.trans (filterMap_congr <| by simpa) (congr_fun filterMap_eq_map _) /-! ### filter -/ section Filter variable {p : α → Bool} theorem filter_singleton {a : α} : [a].filter p = bif p a then [a] else [] := rfl theorem filter_eq_foldr (p : α → Bool) (l : List α) : filter p l = foldr (fun a out => bif p a then a :: out else out) [] l := by induction l <;> simp [*, filter]; rfl #adaptation_note /-- nightly-2024-07-27 This has to be temporarily renamed to avoid an unintentional collision. The prime should be removed at nightly-2024-07-27. -/ @[simp] theorem filter_subset' (l : List α) : filter p l ⊆ l := filter_sublist.subset theorem of_mem_filter {a : α} {l} (h : a ∈ filter p l) : p a := (mem_filter.1 h).2 theorem mem_of_mem_filter {a : α} {l} (h : a ∈ filter p l) : a ∈ l := filter_subset' l h theorem mem_filter_of_mem {a : α} {l} (h₁ : a ∈ l) (h₂ : p a) : a ∈ filter p l := mem_filter.2 ⟨h₁, h₂⟩ @[deprecated (since := "2025-02-07")] alias monotone_filter_left := filter_subset variable (p) theorem monotone_filter_right (l : List α) ⦃p q : α → Bool⦄ (h : ∀ a, p a → q a) : l.filter p <+ l.filter q := by induction l with | nil => rfl | cons hd tl IH => by_cases hp : p hd · rw [filter_cons_of_pos hp, filter_cons_of_pos (h _ hp)] exact IH.cons_cons hd · rw [filter_cons_of_neg hp] by_cases hq : q hd · rw [filter_cons_of_pos hq] exact sublist_cons_of_sublist hd IH · rw [filter_cons_of_neg hq] exact IH lemma map_filter {f : α → β} (hf : Injective f) (l : List α) [DecidablePred fun b => ∃ a, p a ∧ f a = b] : (l.filter p).map f = (l.map f).filter fun b => ∃ a, p a ∧ f a = b := by simp [comp_def, filter_map, hf.eq_iff] @[deprecated (since := "2025-02-07")] alias map_filter' := map_filter lemma filter_attach' (l : List α) (p : {a // a ∈ l} → Bool) [DecidableEq α] : l.attach.filter p = (l.filter fun x => ∃ h, p ⟨x, h⟩).attach.map (Subtype.map id fun _ => mem_of_mem_filter) := by classical refine map_injective_iff.2 Subtype.coe_injective ?_ simp [comp_def, map_filter _ Subtype.coe_injective] lemma filter_attach (l : List α) (p : α → Bool) : (l.attach.filter fun x => p x : List {x // x ∈ l}) = (l.filter p).attach.map (Subtype.map id fun _ => mem_of_mem_filter) := map_injective_iff.2 Subtype.coe_injective <| by simp_rw [map_map, comp_def, Subtype.map, id, ← Function.comp_apply (g := Subtype.val), ← filter_map, attach_map_subtype_val] lemma filter_comm (q) (l : List α) : filter p (filter q l) = filter q (filter p l) := by simp [Bool.and_comm] @[simp] theorem filter_true (l : List α) : filter (fun _ => true) l = l := by induction l <;> simp [*, filter] @[simp] theorem filter_false (l : List α) : filter (fun _ => false) l = [] := by induction l <;> simp [*, filter] end Filter /-! ### eraseP -/ section eraseP variable {p : α → Bool} @[simp] theorem length_eraseP_add_one {l : List α} {a} (al : a ∈ l) (pa : p a) : (l.eraseP p).length + 1 = l.length := by let ⟨_, l₁, l₂, _, _, h₁, h₂⟩ := exists_of_eraseP al pa rw [h₂, h₁, length_append, length_append] rfl end eraseP /-! ### erase -/ section Erase variable [DecidableEq α] @[simp] theorem length_erase_add_one {a : α} {l : List α} (h : a ∈ l) : (l.erase a).length + 1 = l.length := by rw [erase_eq_eraseP, length_eraseP_add_one h (decide_eq_true rfl)] theorem map_erase [DecidableEq β] {f : α → β} (finj : Injective f) {a : α} (l : List α) : map f (l.erase a) = (map f l).erase (f a) := by have this : (a == ·) = (f a == f ·) := by ext b; simp [beq_eq_decide, finj.eq_iff] rw [erase_eq_eraseP, erase_eq_eraseP, eraseP_map, this]; rfl theorem map_foldl_erase [DecidableEq β] {f : α → β} (finj : Injective f) {l₁ l₂ : List α} : map f (foldl List.erase l₁ l₂) = foldl (fun l a => l.erase (f a)) (map f l₁) l₂ := by induction l₂ generalizing l₁ <;> [rfl; simp only [foldl_cons, map_erase finj, *]] theorem erase_getElem [DecidableEq ι] {l : List ι} {i : ℕ} (hi : i < l.length) : Perm (l.erase l[i]) (l.eraseIdx i) := by induction l generalizing i with | nil => simp | cons a l IH => cases i with | zero => simp | succ i => have hi' : i < l.length := by simpa using hi if ha : a = l[i] then simpa [ha] using .trans (perm_cons_erase (getElem_mem _)) (.cons _ (IH hi')) else simpa [ha] using IH hi' theorem length_eraseIdx_add_one {l : List ι} {i : ℕ} (h : i < l.length) : (l.eraseIdx i).length + 1 = l.length := by rw [length_eraseIdx] split <;> omega end Erase /-! ### diff -/ section Diff variable [DecidableEq α] @[simp] theorem map_diff [DecidableEq β] {f : α → β} (finj : Injective f) {l₁ l₂ : List α} : map f (l₁.diff l₂) = (map f l₁).diff (map f l₂) := by simp only [diff_eq_foldl, foldl_map, map_foldl_erase finj] @[deprecated (since := "2025-04-10")] alias erase_diff_erase_sublist_of_sublist := Sublist.erase_diff_erase_sublist end Diff section Choose variable (p : α → Prop) [DecidablePred p] (l : List α) theorem choose_spec (hp : ∃ a, a ∈ l ∧ p a) : choose p l hp ∈ l ∧ p (choose p l hp) := (chooseX p l hp).property theorem choose_mem (hp : ∃ a, a ∈ l ∧ p a) : choose p l hp ∈ l := (choose_spec _ _ _).1 theorem choose_property (hp : ∃ a, a ∈ l ∧ p a) : p (choose p l hp) := (choose_spec _ _ _).2 end Choose /-! ### Forall -/ section Forall variable {p q : α → Prop} {l : List α} @[simp] theorem forall_cons (p : α → Prop) (x : α) : ∀ l : List α, Forall p (x :: l) ↔ p x ∧ Forall p l | [] => (and_iff_left_of_imp fun _ ↦ trivial).symm | _ :: _ => Iff.rfl @[simp] theorem forall_append {p : α → Prop} : ∀ {xs ys : List α}, Forall p (xs ++ ys) ↔ Forall p xs ∧ Forall p ys | [] => by simp | _ :: _ => by simp [forall_append, and_assoc] theorem forall_iff_forall_mem : ∀ {l : List α}, Forall p l ↔ ∀ x ∈ l, p x | [] => (iff_true_intro <| forall_mem_nil _).symm | x :: l => by rw [forall_mem_cons, forall_cons, forall_iff_forall_mem] theorem Forall.imp (h : ∀ x, p x → q x) : ∀ {l : List α}, Forall p l → Forall q l | [] => id | x :: l => by simp only [forall_cons, and_imp] rw [← and_imp] exact And.imp (h x) (Forall.imp h) @[simp] theorem forall_map_iff {p : β → Prop} (f : α → β) : Forall p (l.map f) ↔ Forall (p ∘ f) l := by induction l <;> simp [*] instance (p : α → Prop) [DecidablePred p] : DecidablePred (Forall p) := fun _ => decidable_of_iff' _ forall_iff_forall_mem end Forall /-! ### Miscellaneous lemmas -/ theorem get_attach (l : List α) (i) : (l.attach.get i).1 = l.get ⟨i, length_attach (l := l) ▸ i.2⟩ := by simp section Disjoint /-- The images of disjoint lists under a partially defined map are disjoint -/ theorem disjoint_pmap {p : α → Prop} {f : ∀ a : α, p a → β} {s t : List α} (hs : ∀ a ∈ s, p a) (ht : ∀ a ∈ t, p a) (hf : ∀ (a a' : α) (ha : p a) (ha' : p a'), f a ha = f a' ha' → a = a') (h : Disjoint s t) : Disjoint (s.pmap f hs) (t.pmap f ht) := by simp only [Disjoint, mem_pmap] rintro b ⟨a, ha, rfl⟩ ⟨a', ha', ha''⟩ apply h ha rwa [hf a a' (hs a ha) (ht a' ha') ha''.symm] /-- The images of disjoint lists under an injective map are disjoint -/ theorem disjoint_map {f : α → β} {s t : List α} (hf : Function.Injective f) (h : Disjoint s t) : Disjoint (s.map f) (t.map f) := by rw [← pmap_eq_map (fun _ _ ↦ trivial), ← pmap_eq_map (fun _ _ ↦ trivial)] exact disjoint_pmap _ _ (fun _ _ _ _ h' ↦ hf h') h alias Disjoint.map := disjoint_map theorem Disjoint.of_map {f : α → β} {s t : List α} (h : Disjoint (s.map f) (t.map f)) : Disjoint s t := fun _a has hat ↦ h (mem_map_of_mem has) (mem_map_of_mem hat) theorem Disjoint.map_iff {f : α → β} {s t : List α} (hf : Function.Injective f) : Disjoint (s.map f) (t.map f) ↔ Disjoint s t := ⟨fun h ↦ h.of_map, fun h ↦ h.map hf⟩ theorem Perm.disjoint_left {l₁ l₂ l : List α} (p : List.Perm l₁ l₂) : Disjoint l₁ l ↔ Disjoint l₂ l := by simp_rw [List.disjoint_left, p.mem_iff] theorem Perm.disjoint_right {l₁ l₂ l : List α} (p : List.Perm l₁ l₂) : Disjoint l l₁ ↔ Disjoint l l₂ := by simp_rw [List.disjoint_right, p.mem_iff] @[simp] theorem disjoint_reverse_left {l₁ l₂ : List α} : Disjoint l₁.reverse l₂ ↔ Disjoint l₁ l₂ := reverse_perm _ |>.disjoint_left @[simp] theorem disjoint_reverse_right {l₁ l₂ : List α} : Disjoint l₁ l₂.reverse ↔ Disjoint l₁ l₂ := reverse_perm _ |>.disjoint_right end Disjoint section lookup variable [BEq α] [LawfulBEq α] lemma lookup_graph (f : α → β) {a : α} {as : List α} (h : a ∈ as) : lookup a (as.map fun x => (x, f x)) = some (f a) := by induction as with | nil => exact (not_mem_nil h).elim | cons a' as ih => by_cases ha : a = a' · simp [ha, lookup_cons] · simpa [lookup_cons, beq_false_of_ne ha] using ih (List.mem_of_ne_of_mem ha h) end lookup section range' @[simp] lemma range'_0 (a b : ℕ) : range' a b 0 = replicate b a := by induction b with | zero => simp | succ b ih => simp [range'_succ, ih, replicate_succ] lemma left_le_of_mem_range' {a b s x : ℕ} (hx : x ∈ List.range' a b s) : a ≤ x := by obtain ⟨i, _, rfl⟩ := List.mem_range'.mp hx exact le_add_right a (s * i) end range' end List
Mathlib/Data/List/Basic.lean
2,499
2,501
/- 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.Convex.Between import Mathlib.MeasureTheory.Constructions.BorelSpace.Basic import Mathlib.MeasureTheory.Measure.Lebesgue.Basic import Mathlib.Topology.MetricSpace.Holder import Mathlib.Topology.MetricSpace.MetricSeparated /-! # Hausdorff measure and metric (outer) measures In this file we define the `d`-dimensional Hausdorff measure on an (extended) metric space `X` and the Hausdorff dimension of a set in an (extended) metric space. Let `μ d δ` be the maximal outer measure such that `μ d δ s ≤ (EMetric.diam s) ^ d` for every set of diameter less than `δ`. Then the Hausdorff measure `μH[d] s` of `s` is defined as `⨆ δ > 0, μ d δ s`. By Caratheodory theorem `MeasureTheory.OuterMeasure.IsMetric.borel_le_caratheodory`, this is a Borel measure on `X`. The value of `μH[d]`, `d > 0`, on a set `s` (measurable or not) is given by ``` μH[d] s = ⨆ (r : ℝ≥0∞) (hr : 0 < r), ⨅ (t : ℕ → Set X) (hts : s ⊆ ⋃ n, t n) (ht : ∀ n, EMetric.diam (t n) ≤ r), ∑' n, EMetric.diam (t n) ^ d ``` For every set `s` for any `d < d'` we have either `μH[d] s = ∞` or `μH[d'] s = 0`, see `MeasureTheory.Measure.hausdorffMeasure_zero_or_top`. In `Mathlib.Topology.MetricSpace.HausdorffDimension` we use this fact to define the Hausdorff dimension `dimH` of a set in an (extended) metric space. We also define two generalizations of the Hausdorff measure. In one generalization (see `MeasureTheory.Measure.mkMetric`) we take any function `m (diam s)` instead of `(diam s) ^ d`. In an even more general definition (see `MeasureTheory.Measure.mkMetric'`) we use any function of `m : Set X → ℝ≥0∞`. Some authors start with a partial function `m` defined only on some sets `s : Set X` (e.g., only on balls or only on measurable sets). This is equivalent to our definition applied to `MeasureTheory.extend m`. We also define a predicate `MeasureTheory.OuterMeasure.IsMetric` which says that an outer measure is additive on metric separated pairs of sets: `μ (s ∪ t) = μ s + μ t` provided that `⨅ (x ∈ s) (y ∈ t), edist x y ≠ 0`. This is the property required for the Caratheodory theorem `MeasureTheory.OuterMeasure.IsMetric.borel_le_caratheodory`, so we prove this theorem for any metric outer measure, then prove that outer measures constructed using `mkMetric'` are metric outer measures. ## Main definitions * `MeasureTheory.OuterMeasure.IsMetric`: an outer measure `μ` is called *metric* if `μ (s ∪ t) = μ s + μ t` for any two metric separated sets `s` and `t`. A metric outer measure in a Borel extended metric space is guaranteed to satisfy the Caratheodory condition, see `MeasureTheory.OuterMeasure.IsMetric.borel_le_caratheodory`. * `MeasureTheory.OuterMeasure.mkMetric'` and its particular case `MeasureTheory.OuterMeasure.mkMetric`: a construction of an outer measure that is guaranteed to be metric. Both constructions are generalizations of the Hausdorff measure. The same measures interpreted as Borel measures are called `MeasureTheory.Measure.mkMetric'` and `MeasureTheory.Measure.mkMetric`. * `MeasureTheory.Measure.hausdorffMeasure` a.k.a. `μH[d]`: the `d`-dimensional Hausdorff measure. There are many definitions of the Hausdorff measure that differ from each other by a multiplicative constant. We put `μH[d] s = ⨆ r > 0, ⨅ (t : ℕ → Set X) (hts : s ⊆ ⋃ n, t n) (ht : ∀ n, EMetric.diam (t n) ≤ r), ∑' n, ⨆ (ht : ¬Set.Subsingleton (t n)), (EMetric.diam (t n)) ^ d`, see `MeasureTheory.Measure.hausdorffMeasure_apply`. In the most interesting case `0 < d` one can omit the `⨆ (ht : ¬Set.Subsingleton (t n))` part. ## Main statements ### Basic properties * `MeasureTheory.OuterMeasure.IsMetric.borel_le_caratheodory`: if `μ` is a metric outer measure on an extended metric space `X` (that is, it is additive on pairs of metric separated sets), then every Borel set is Caratheodory measurable (hence, `μ` defines an actual `MeasureTheory.Measure`). See also `MeasureTheory.Measure.mkMetric`. * `MeasureTheory.Measure.hausdorffMeasure_mono`: `μH[d] s` is an antitone function of `d`. * `MeasureTheory.Measure.hausdorffMeasure_zero_or_top`: if `d₁ < d₂`, then for any `s`, either `μH[d₂] s = 0` or `μH[d₁] s = ∞`. Together with the previous lemma, this means that `μH[d] s` is equal to infinity on some ray `(-∞, D)` and is equal to zero on `(D, +∞)`, where `D` is a possibly infinite number called the *Hausdorff dimension* of `s`; `μH[D] s` can be zero, infinity, or anything in between. * `MeasureTheory.Measure.noAtoms_hausdorff`: Hausdorff measure has no atoms. ### Hausdorff measure in `ℝⁿ` * `MeasureTheory.hausdorffMeasure_pi_real`: for a nonempty `ι`, `μH[card ι]` on `ι → ℝ` equals Lebesgue measure. ## Notations We use the following notation localized in `MeasureTheory`. - `μH[d]` : `MeasureTheory.Measure.hausdorffMeasure d` ## Implementation notes There are a few similar constructions called the `d`-dimensional Hausdorff measure. E.g., some sources only allow coverings by balls and use `r ^ d` instead of `(diam s) ^ d`. While these construction lead to different Hausdorff measures, they lead to the same notion of the Hausdorff dimension. ## References * [Herbert Federer, Geometric Measure Theory, Chapter 2.10][Federer1996] ## Tags Hausdorff measure, measure, metric measure -/ open scoped NNReal ENNReal Topology open EMetric Set Function Filter Encodable Module TopologicalSpace noncomputable section variable {ι X Y : Type*} [EMetricSpace X] [EMetricSpace Y] namespace MeasureTheory namespace OuterMeasure /-! ### Metric outer measures In this section we define metric outer measures and prove Caratheodory theorem: a metric outer measure has the Caratheodory property. -/ /-- We say that an outer measure `μ` in an (e)metric space is *metric* if `μ (s ∪ t) = μ s + μ t` for any two metric separated sets `s`, `t`. -/ def IsMetric (μ : OuterMeasure X) : Prop := ∀ s t : Set X, Metric.AreSeparated s t → μ (s ∪ t) = μ s + μ t namespace IsMetric variable {μ : OuterMeasure X} /-- A metric outer measure is additive on a finite set of pairwise metric separated sets. -/ theorem finset_iUnion_of_pairwise_separated (hm : IsMetric μ) {I : Finset ι} {s : ι → Set X} (hI : ∀ i ∈ I, ∀ j ∈ I, i ≠ j → Metric.AreSeparated (s i) (s j)) : μ (⋃ i ∈ I, s i) = ∑ i ∈ I, μ (s i) := by classical induction I using Finset.induction_on with | empty => simp | insert i I hiI ihI => simp only [Finset.mem_insert] at hI rw [Finset.set_biUnion_insert, hm, ihI, Finset.sum_insert hiI] exacts [fun i hi j hj hij => hI i (Or.inr hi) j (Or.inr hj) hij, Metric.AreSeparated.finset_iUnion_right fun j hj => hI i (Or.inl rfl) j (Or.inr hj) (ne_of_mem_of_not_mem hj hiI).symm] /-- Caratheodory theorem. If `m` is a metric outer measure, then every Borel measurable set `t` is Caratheodory measurable: for any (not necessarily measurable) set `s` we have `μ (s ∩ t) + μ (s \ t) = μ s`. -/ theorem borel_le_caratheodory (hm : IsMetric μ) : borel X ≤ μ.caratheodory := by rw [borel_eq_generateFrom_isClosed] refine MeasurableSpace.generateFrom_le fun t ht => μ.isCaratheodory_iff_le.2 fun s => ?_ set S : ℕ → Set X := fun n => {x ∈ s | (↑n)⁻¹ ≤ infEdist x t} have Ssep (n) : Metric.AreSeparated (S n) t := ⟨n⁻¹, ENNReal.inv_ne_zero.2 (ENNReal.natCast_ne_top _), fun x hx y hy ↦ hx.2.trans <| infEdist_le_edist_of_mem hy⟩ have Ssep' : ∀ n, Metric.AreSeparated (S n) (s ∩ t) := fun n => (Ssep n).mono Subset.rfl inter_subset_right have S_sub : ∀ n, S n ⊆ s \ t := fun n => subset_inter inter_subset_left (Ssep n).subset_compl_right have hSs : ∀ n, μ (s ∩ t) + μ (S n) ≤ μ s := fun n => calc μ (s ∩ t) + μ (S n) = μ (s ∩ t ∪ S n) := Eq.symm <| hm _ _ <| (Ssep' n).symm _ ≤ μ (s ∩ t ∪ s \ t) := μ.mono <| union_subset_union_right _ <| S_sub n _ = μ s := by rw [inter_union_diff] have iUnion_S : ⋃ n, S n = s \ t := by refine Subset.antisymm (iUnion_subset S_sub) ?_ rintro x ⟨hxs, hxt⟩ rw [mem_iff_infEdist_zero_of_closed ht] at hxt rcases ENNReal.exists_inv_nat_lt hxt with ⟨n, hn⟩ exact mem_iUnion.2 ⟨n, hxs, hn.le⟩ /- Now we have `∀ n, μ (s ∩ t) + μ (S n) ≤ μ s` and we need to prove `μ (s ∩ t) + μ (⋃ n, S n) ≤ μ s`. We can't pass to the limit because `μ` is only an outer measure. -/ by_cases htop : μ (s \ t) = ∞ · rw [htop, add_top, ← htop] exact μ.mono diff_subset suffices μ (⋃ n, S n) ≤ ⨆ n, μ (S n) by calc μ (s ∩ t) + μ (s \ t) = μ (s ∩ t) + μ (⋃ n, S n) := by rw [iUnion_S] _ ≤ μ (s ∩ t) + ⨆ n, μ (S n) := by gcongr _ = ⨆ n, μ (s ∩ t) + μ (S n) := ENNReal.add_iSup .. _ ≤ μ s := iSup_le hSs /- It suffices to show that `∑' k, μ (S (k + 1) \ S k) ≠ ∞`. Indeed, if we have this, then for all `N` we have `μ (⋃ n, S n) ≤ μ (S N) + ∑' k, m (S (N + k + 1) \ S (N + k))` and the second term tends to zero, see `OuterMeasure.iUnion_nat_of_monotone_of_tsum_ne_top` for details. -/ have : ∀ n, S n ⊆ S (n + 1) := fun n x hx => ⟨hx.1, le_trans (ENNReal.inv_le_inv.2 <| Nat.cast_le.2 n.le_succ) hx.2⟩ refine (μ.iUnion_nat_of_monotone_of_tsum_ne_top this ?_).le; clear this /- While the sets `S (k + 1) \ S k` are not pairwise metric separated, the sets in each subsequence `S (2 * k + 1) \ S (2 * k)` and `S (2 * k + 2) \ S (2 * k)` are metric separated, so `m` is additive on each of those sequences. -/ rw [← tsum_even_add_odd ENNReal.summable ENNReal.summable, ENNReal.add_ne_top] suffices ∀ a, (∑' k : ℕ, μ (S (2 * k + 1 + a) \ S (2 * k + a))) ≠ ∞ from ⟨by simpa using this 0, by simpa using this 1⟩ refine fun r => ne_top_of_le_ne_top htop ?_ rw [← iUnion_S, ENNReal.tsum_eq_iSup_nat, iSup_le_iff] intro n rw [← hm.finset_iUnion_of_pairwise_separated] · exact μ.mono (iUnion_subset fun i => iUnion_subset fun _ x hx => mem_iUnion.2 ⟨_, hx.1⟩) suffices ∀ i j, i < j → Metric.AreSeparated (S (2 * i + 1 + r)) (s \ S (2 * j + r)) from fun i _ j _ hij => hij.lt_or_lt.elim (fun h => (this i j h).mono inter_subset_left fun x hx => by exact ⟨hx.1.1, hx.2⟩) fun h => (this j i h).symm.mono (fun x hx => by exact ⟨hx.1.1, hx.2⟩) inter_subset_left intro i j hj have A : ((↑(2 * j + r))⁻¹ : ℝ≥0∞) < (↑(2 * i + 1 + r))⁻¹ := by rw [ENNReal.inv_lt_inv, Nat.cast_lt]; omega refine ⟨(↑(2 * i + 1 + r))⁻¹ - (↑(2 * j + r))⁻¹, by simpa [tsub_eq_zero_iff_le] using A, fun x hx y hy => ?_⟩ have : infEdist y t < (↑(2 * j + r))⁻¹ := not_le.1 fun hle => hy.2 ⟨hy.1, hle⟩ rcases infEdist_lt_iff.mp this with ⟨z, hzt, hyz⟩ have hxz : (↑(2 * i + 1 + r))⁻¹ ≤ edist x z := le_infEdist.1 hx.2 _ hzt apply ENNReal.le_of_add_le_add_right hyz.ne_top refine le_trans ?_ (edist_triangle _ _ _) refine (add_le_add le_rfl hyz.le).trans (Eq.trans_le ?_ hxz) rw [tsub_add_cancel_of_le A.le] theorem le_caratheodory [MeasurableSpace X] [BorelSpace X] (hm : IsMetric μ) : ‹MeasurableSpace X› ≤ μ.caratheodory := by rw [BorelSpace.measurable_eq (α := X)] exact hm.borel_le_caratheodory end IsMetric /-! ### Constructors of metric outer measures In this section we provide constructors `MeasureTheory.OuterMeasure.mkMetric'` and `MeasureTheory.OuterMeasure.mkMetric` and prove that these outer measures are metric outer measures. We also prove basic lemmas about `map`/`comap` of these measures. -/ /-- Auxiliary definition for `OuterMeasure.mkMetric'`: given a function on sets `m : Set X → ℝ≥0∞`, returns the maximal outer measure `μ` such that `μ s ≤ m s` for any set `s` of diameter at most `r`. -/ def mkMetric'.pre (m : Set X → ℝ≥0∞) (r : ℝ≥0∞) : OuterMeasure X := boundedBy <| extend fun s (_ : diam s ≤ r) => m s /-- Given a function `m : Set X → ℝ≥0∞`, `mkMetric' m` is the supremum of `mkMetric'.pre m r` over `r > 0`. Equivalently, it is the limit of `mkMetric'.pre m r` as `r` tends to zero from the right. -/ def mkMetric' (m : Set X → ℝ≥0∞) : OuterMeasure X := ⨆ r > 0, mkMetric'.pre m r /-- Given a function `m : ℝ≥0∞ → ℝ≥0∞` and `r > 0`, let `μ r` be the maximal outer measure such that `μ s ≤ m (EMetric.diam s)` whenever `EMetric.diam s < r`. Then `mkMetric m = ⨆ r > 0, μ r`. -/ def mkMetric (m : ℝ≥0∞ → ℝ≥0∞) : OuterMeasure X := mkMetric' fun s => m (diam s) namespace mkMetric' variable {m : Set X → ℝ≥0∞} {r : ℝ≥0∞} {μ : OuterMeasure X} {s : Set X} theorem le_pre : μ ≤ pre m r ↔ ∀ s : Set X, diam s ≤ r → μ s ≤ m s := by simp only [pre, le_boundedBy, extend, le_iInf_iff] theorem pre_le (hs : diam s ≤ r) : pre m r s ≤ m s := (boundedBy_le _).trans <| iInf_le _ hs theorem mono_pre (m : Set X → ℝ≥0∞) {r r' : ℝ≥0∞} (h : r ≤ r') : pre m r' ≤ pre m r := le_pre.2 fun _ hs => pre_le (hs.trans h) theorem mono_pre_nat (m : Set X → ℝ≥0∞) : Monotone fun k : ℕ => pre m k⁻¹ := fun k l h => le_pre.2 fun _ hs => pre_le (hs.trans <| by simpa) theorem tendsto_pre (m : Set X → ℝ≥0∞) (s : Set X) : Tendsto (fun r => pre m r s) (𝓝[>] 0) (𝓝 <| mkMetric' m s) := by rw [← map_coe_Ioi_atBot, tendsto_map'_iff] simp only [mkMetric', OuterMeasure.iSup_apply, iSup_subtype'] exact tendsto_atBot_iSup fun r r' hr => mono_pre _ hr _ theorem tendsto_pre_nat (m : Set X → ℝ≥0∞) (s : Set X) : Tendsto (fun n : ℕ => pre m n⁻¹ s) atTop (𝓝 <| mkMetric' m s) := by refine (tendsto_pre m s).comp (tendsto_inf.2 ⟨ENNReal.tendsto_inv_nat_nhds_zero, ?_⟩) refine tendsto_principal.2 (Eventually.of_forall fun n => ?_) simp theorem eq_iSup_nat (m : Set X → ℝ≥0∞) : mkMetric' m = ⨆ n : ℕ, mkMetric'.pre m n⁻¹ := by ext1 s rw [iSup_apply] refine tendsto_nhds_unique (mkMetric'.tendsto_pre_nat m s) (tendsto_atTop_iSup fun k l hkl => mkMetric'.mono_pre_nat m hkl s) /-- `MeasureTheory.OuterMeasure.mkMetric'.pre m r` is a trimmed measure provided that `m (closure s) = m s` for any set `s`. -/ theorem trim_pre [MeasurableSpace X] [OpensMeasurableSpace X] (m : Set X → ℝ≥0∞) (hcl : ∀ s, m (closure s) = m s) (r : ℝ≥0∞) : (pre m r).trim = pre m r := by refine le_antisymm (le_pre.2 fun s hs => ?_) (le_trim _) rw [trim_eq_iInf] refine iInf_le_of_le (closure s) <| iInf_le_of_le subset_closure <| iInf_le_of_le measurableSet_closure ((pre_le ?_).trans_eq (hcl _)) rwa [diam_closure] end mkMetric' /-- An outer measure constructed using `OuterMeasure.mkMetric'` is a metric outer measure. -/ theorem mkMetric'_isMetric (m : Set X → ℝ≥0∞) : (mkMetric' m).IsMetric := by rintro s t ⟨r, r0, hr⟩ refine tendsto_nhds_unique_of_eventuallyEq (mkMetric'.tendsto_pre _ _) ((mkMetric'.tendsto_pre _ _).add (mkMetric'.tendsto_pre _ _)) ?_ rw [← pos_iff_ne_zero] at r0 filter_upwards [Ioo_mem_nhdsGT r0] rintro ε ⟨_, εr⟩ refine boundedBy_union_of_top_of_nonempty_inter ?_ rintro u ⟨x, hxs, hxu⟩ ⟨y, hyt, hyu⟩ have : ε < diam u := εr.trans_le ((hr x hxs y hyt).trans <| edist_le_diam_of_mem hxu hyu) exact iInf_eq_top.2 fun h => (this.not_le h).elim /-- If `c ∉ {0, ∞}` and `m₁ d ≤ c * m₂ d` for `d < ε` for some `ε > 0` (we use `≤ᶠ[𝓝[≥] 0]` to state this), then `mkMetric m₁ hm₁ ≤ c • mkMetric m₂ hm₂`. -/ theorem mkMetric_mono_smul {m₁ m₂ : ℝ≥0∞ → ℝ≥0∞} {c : ℝ≥0∞} (hc : c ≠ ∞) (h0 : c ≠ 0) (hle : m₁ ≤ᶠ[𝓝[≥] 0] c • m₂) : (mkMetric m₁ : OuterMeasure X) ≤ c • mkMetric m₂ := by classical rcases (mem_nhdsGE_iff_exists_Ico_subset' zero_lt_one).1 hle with ⟨r, hr0, hr⟩ refine fun s => le_of_tendsto_of_tendsto (mkMetric'.tendsto_pre _ s) (ENNReal.Tendsto.const_mul (mkMetric'.tendsto_pre _ s) (Or.inr hc)) (mem_of_superset (Ioo_mem_nhdsGT hr0) fun r' hr' => ?_) simp only [mem_setOf_eq, mkMetric'.pre, RingHom.id_apply] rw [← smul_eq_mul, ← smul_apply, smul_boundedBy hc] refine le_boundedBy.2 (fun t => (boundedBy_le _).trans ?_) _ simp only [smul_eq_mul, Pi.smul_apply, extend, iInf_eq_if] split_ifs with ht · apply hr exact ⟨zero_le _, ht.trans_lt hr'.2⟩ · simp [h0] @[simp] theorem mkMetric_top : (mkMetric (fun _ => ∞ : ℝ≥0∞ → ℝ≥0∞) : OuterMeasure X) = ⊤ := by simp_rw [mkMetric, mkMetric', mkMetric'.pre, extend_top, boundedBy_top, eq_top_iff] rw [le_iSup_iff] intro b hb simpa using hb ⊤ /-- If `m₁ d ≤ m₂ d` for `d < ε` for some `ε > 0` (we use `≤ᶠ[𝓝[≥] 0]` to state this), then `mkMetric m₁ hm₁ ≤ mkMetric m₂ hm₂`. -/ theorem mkMetric_mono {m₁ m₂ : ℝ≥0∞ → ℝ≥0∞} (hle : m₁ ≤ᶠ[𝓝[≥] 0] m₂) : (mkMetric m₁ : OuterMeasure X) ≤ mkMetric m₂ := by convert @mkMetric_mono_smul X _ _ m₂ _ ENNReal.one_ne_top one_ne_zero _ <;> simp [*] theorem isometry_comap_mkMetric (m : ℝ≥0∞ → ℝ≥0∞) {f : X → Y} (hf : Isometry f) (H : Monotone m ∨ Surjective f) : comap f (mkMetric m) = mkMetric m := by simp only [mkMetric, mkMetric', mkMetric'.pre, inducedOuterMeasure, comap_iSup] refine surjective_id.iSup_congr id fun ε => surjective_id.iSup_congr id fun hε => ?_ rw [comap_boundedBy _ (H.imp _ id)] · congr with s : 1 apply extend_congr · simp [hf.ediam_image] · intros; simp [hf.injective.subsingleton_image_iff, hf.ediam_image] · intro h_mono s t hst simp only [extend, le_iInf_iff] intro ht apply le_trans _ (h_mono (diam_mono hst)) simp only [(diam_mono hst).trans ht, le_refl, ciInf_pos] theorem mkMetric_smul (m : ℝ≥0∞ → ℝ≥0∞) {c : ℝ≥0∞} (hc : c ≠ ∞) (hc' : c ≠ 0) :
(mkMetric (c • m) : OuterMeasure X) = c • mkMetric m := by simp only [mkMetric, mkMetric', mkMetric'.pre, inducedOuterMeasure, ENNReal.smul_iSup] simp_rw [smul_iSup, smul_boundedBy hc, smul_extend _ hc', Pi.smul_apply]
Mathlib/MeasureTheory/Measure/Hausdorff.lean
364
366
/- Copyright (c) 2023 Yaël Dillies, Vladimir Ivanov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Vladimir Ivanov -/ import Mathlib.Algebra.BigOperators.Intervals import Mathlib.Algebra.BigOperators.Ring.Finset import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Algebra.Order.Field.Basic import Mathlib.Data.Finset.Sups import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Ring import Mathlib.Algebra.BigOperators.Group.Finset.Powerset /-! # The Ahlswede-Zhang identity This file proves the Ahlswede-Zhang identity, which is a nontrivial relation between the size of the "truncated unions" of a set family. It sharpens the Lubell-Yamamoto-Meshalkin inequality `Finset.lubell_yamamoto_meshalkin_inequality_sum_card_div_choose`, by making explicit the correction term. For a set family `𝒜` over a ground set of size `n`, the Ahlswede-Zhang identity states that the sum of `|⋂ B ∈ 𝒜, B ⊆ A, B|/(|A| * n.choose |A|)` over all set `A` is exactly `1`. This implies the LYM inequality since for an antichain `𝒜` and every `A ∈ 𝒜` we have `|⋂ B ∈ 𝒜, B ⊆ A, B|/(|A| * n.choose |A|) = 1 / n.choose |A|`. ## Main declarations * `Finset.truncatedSup`: `s.truncatedSup a` is the supremum of all `b ≥ a` in `𝒜` if there are some, or `⊤` if there are none. * `Finset.truncatedInf`: `s.truncatedInf a` is the infimum of all `b ≤ a` in `𝒜` if there are some, or `⊥` if there are none. * `AhlswedeZhang.infSum`: LHS of the Ahlswede-Zhang identity. * `AhlswedeZhang.le_infSum`: The sum of `1 / n.choose |A|` over an antichain is less than the RHS of the Ahlswede-Zhang identity. * `AhlswedeZhang.infSum_eq_one`: Ahlswede-Zhang identity. ## References * [R. Ahlswede, Z. Zhang, *An identity in combinatorial extremal theory*](https://doi.org/10.1016/0001-8708(90)90023-G) * [D. T. Tru, *An AZ-style identity and Bollobás deficiency*](https://doi.org/10.1016/j.jcta.2007.03.005) -/ section variable (α : Type*) [Fintype α] [Nonempty α] {m n : ℕ} open Finset Fintype Nat
private lemma binomial_sum_eq (h : n < m) : ∑ i ∈ range (n + 1), (n.choose i * (m - n) / ((m - i) * m.choose i) : ℚ) = 1 := by set f : ℕ → ℚ := fun i ↦ n.choose i * (m.choose i : ℚ)⁻¹ with hf suffices ∀ i ∈ range (n + 1), f i - f (i + 1) = n.choose i * (m - n) / ((m - i) * m.choose i) by rw [← sum_congr rfl this, sum_range_sub', hf] simp [choose_self, choose_zero_right, choose_eq_zero_of_lt h] intro i h₁ rw [mem_range] at h₁ have h₁ := le_of_lt_succ h₁ have h₂ := h₁.trans_lt h have h₃ := h₂.le have hi₄ : (i + 1 : ℚ) ≠ 0 := i.cast_add_one_ne_zero have := congr_arg ((↑) : ℕ → ℚ) (choose_succ_right_eq m i) push_cast at this dsimp [f, hf] rw [(eq_mul_inv_iff_mul_eq₀ hi₄).mpr this] have := congr_arg ((↑) : ℕ → ℚ) (choose_succ_right_eq n i) push_cast at this rw [(eq_mul_inv_iff_mul_eq₀ hi₄).mpr this] have : (m - i : ℚ) ≠ 0 := sub_ne_zero_of_ne (cast_lt.mpr h₂).ne' have : (m.choose i : ℚ) ≠ 0 := cast_ne_zero.2 (choose_pos h₂.le).ne' field_simp
Mathlib/Combinatorics/SetFamily/AhlswedeZhang.lean
49
71
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Multiset.ZeroCons /-! # Basic results on multisets -/ -- No algebra should be required assert_not_exists Monoid universe v open List Subtype Nat Function variable {α : Type*} {β : Type v} {γ : Type*} namespace Multiset /-! ### `Multiset.toList` -/ section ToList /-- Produces a list of the elements in the multiset using choice. -/ noncomputable def toList (s : Multiset α) := s.out @[simp, norm_cast] theorem coe_toList (s : Multiset α) : (s.toList : Multiset α) = s := s.out_eq' @[simp] theorem toList_eq_nil {s : Multiset α} : s.toList = [] ↔ s = 0 := by rw [← coe_eq_zero, coe_toList] theorem empty_toList {s : Multiset α} : s.toList.isEmpty ↔ s = 0 := by simp @[simp] theorem toList_zero : (Multiset.toList 0 : List α) = [] := toList_eq_nil.mpr rfl @[simp] theorem mem_toList {a : α} {s : Multiset α} : a ∈ s.toList ↔ a ∈ s := by rw [← mem_coe, coe_toList] @[simp] theorem toList_eq_singleton_iff {a : α} {m : Multiset α} : m.toList = [a] ↔ m = {a} := by rw [← perm_singleton, ← coe_eq_coe, coe_toList, coe_singleton] @[simp] theorem toList_singleton (a : α) : ({a} : Multiset α).toList = [a] := Multiset.toList_eq_singleton_iff.2 rfl @[simp] theorem length_toList (s : Multiset α) : s.toList.length = card s := by rw [← coe_card, coe_toList] end ToList /-! ### Induction principles -/ /-- The strong induction principle for multisets. -/ @[elab_as_elim] def strongInductionOn {p : Multiset α → Sort*} (s : Multiset α) (ih : ∀ s, (∀ t < s, p t) → p s) : p s := (ih s) fun t _h => strongInductionOn t ih termination_by card s decreasing_by exact card_lt_card _h theorem strongInductionOn_eq {p : Multiset α → Sort*} (s : Multiset α) (H) : @strongInductionOn _ p s H = H s fun t _h => @strongInductionOn _ p t H := by rw [strongInductionOn] @[elab_as_elim] theorem case_strongInductionOn {p : Multiset α → Prop} (s : Multiset α) (h₀ : p 0) (h₁ : ∀ a s, (∀ t ≤ s, p t) → p (a ::ₘ s)) : p s := Multiset.strongInductionOn s fun s => Multiset.induction_on s (fun _ => h₀) fun _a _s _ ih => (h₁ _ _) fun _t h => ih _ <| lt_of_le_of_lt h <| lt_cons_self _ _ /-- Suppose that, given that `p t` can be defined on all supersets of `s` of cardinality less than `n`, one knows how to define `p s`. Then one can inductively define `p s` for all multisets `s` of cardinality less than `n`, starting from multisets of card `n` and iterating. This can be used either to define data, or to prove properties. -/ def strongDownwardInduction {p : Multiset α → Sort*} {n : ℕ} (H : ∀ t₁, (∀ {t₂ : Multiset α}, card t₂ ≤ n → t₁ < t₂ → p t₂) → card t₁ ≤ n → p t₁) (s : Multiset α) : card s ≤ n → p s := H s fun {t} ht _h => strongDownwardInduction H t ht termination_by n - card s decreasing_by simp_wf; have := (card_lt_card _h); omega theorem strongDownwardInduction_eq {p : Multiset α → Sort*} {n : ℕ} (H : ∀ t₁, (∀ {t₂ : Multiset α}, card t₂ ≤ n → t₁ < t₂ → p t₂) → card t₁ ≤ n → p t₁) (s : Multiset α) : strongDownwardInduction H s = H s fun ht _hst => strongDownwardInduction H _ ht := by rw [strongDownwardInduction] /-- Analogue of `strongDownwardInduction` with order of arguments swapped. -/ @[elab_as_elim] def strongDownwardInductionOn {p : Multiset α → Sort*} {n : ℕ} : ∀ s : Multiset α, (∀ t₁, (∀ {t₂ : Multiset α}, card t₂ ≤ n → t₁ < t₂ → p t₂) → card t₁ ≤ n → p t₁) → card s ≤ n → p s := fun s H => strongDownwardInduction H s theorem strongDownwardInductionOn_eq {p : Multiset α → Sort*} (s : Multiset α) {n : ℕ} (H : ∀ t₁, (∀ {t₂ : Multiset α}, card t₂ ≤ n → t₁ < t₂ → p t₂) → card t₁ ≤ n → p t₁) : s.strongDownwardInductionOn H = H s fun {t} ht _h => t.strongDownwardInductionOn H ht := by dsimp only [strongDownwardInductionOn] rw [strongDownwardInduction] section Choose variable (p : α → Prop) [DecidablePred p] (l : Multiset α) /-- Given a proof `hp` that there exists a unique `a ∈ l` such that `p a`, `chooseX p l hp` returns that `a` together with proofs of `a ∈ l` and `p a`. -/ def chooseX : ∀ _hp : ∃! a, a ∈ l ∧ p a, { a // a ∈ l ∧ p a } := Quotient.recOn l (fun l' ex_unique => List.chooseX p l' (ExistsUnique.exists ex_unique)) (by intros a b _ funext hp suffices all_equal : ∀ x y : { t // t ∈ b ∧ p t }, x = y by apply all_equal rintro ⟨x, px⟩ ⟨y, py⟩ rcases hp with ⟨z, ⟨_z_mem_l, _pz⟩, z_unique⟩ congr calc x = z := z_unique x px _ = y := (z_unique y py).symm ) /-- Given a proof `hp` that there exists a unique `a ∈ l` such that `p a`, `choose p l hp` returns that `a`. -/ def choose (hp : ∃! a, a ∈ l ∧ p a) : α := chooseX p l hp theorem choose_spec (hp : ∃! a, a ∈ l ∧ p a) : choose p l hp ∈ l ∧ p (choose p l hp) := (chooseX p l hp).property theorem choose_mem (hp : ∃! a, a ∈ l ∧ p a) : choose p l hp ∈ l := (choose_spec _ _ _).1 theorem choose_property (hp : ∃! a, a ∈ l ∧ p a) : p (choose p l hp) := (choose_spec _ _ _).2 end Choose variable (α) in /-- The equivalence between lists and multisets of a subsingleton type. -/ def subsingletonEquiv [Subsingleton α] : List α ≃ Multiset α where toFun := ofList invFun := (Quot.lift id) fun (a b : List α) (h : a ~ b) => (List.ext_get h.length_eq) fun _ _ _ => Subsingleton.elim _ _ left_inv _ := rfl right_inv m := Quot.inductionOn m fun _ => rfl @[simp] theorem coe_subsingletonEquiv [Subsingleton α] : (subsingletonEquiv α : List α → Multiset α) = ofList := rfl section SizeOf set_option linter.deprecated false in @[deprecated "Deprecated without replacement." (since := "2025-02-07")] theorem sizeOf_lt_sizeOf_of_mem [SizeOf α] {x : α} {s : Multiset α} (hx : x ∈ s) : SizeOf.sizeOf x < SizeOf.sizeOf s := by induction s using Quot.inductionOn exact List.sizeOf_lt_sizeOf_of_mem hx end SizeOf end Multiset
Mathlib/Data/Multiset/Basic.lean
437
438
/- Copyright (c) 2019 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp, Yury Kudryashov -/ import Mathlib.Analysis.Convex.Combination import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp /-! # Jensen's inequality and maximum principle for convex functions In this file, we prove the finite Jensen inequality and the finite maximum principle for convex functions. The integral versions are to be found in `Analysis.Convex.Integral`. ## Main declarations Jensen's inequalities: * `ConvexOn.map_centerMass_le`, `ConvexOn.map_sum_le`: Convex Jensen's inequality. The image of a convex combination of points under a convex function is less than the convex combination of the images. * `ConcaveOn.le_map_centerMass`, `ConcaveOn.le_map_sum`: Concave Jensen's inequality. * `StrictConvexOn.map_sum_lt`: Convex strict Jensen inequality. * `StrictConcaveOn.lt_map_sum`: Concave strict Jensen inequality. As corollaries, we get: * `StrictConvexOn.map_sum_eq_iff`: Equality case of the convex Jensen inequality. * `StrictConcaveOn.map_sum_eq_iff`: Equality case of the concave Jensen inequality. * `ConvexOn.exists_ge_of_mem_convexHull`: Maximum principle for convex functions. * `ConcaveOn.exists_le_of_mem_convexHull`: Minimum principle for concave functions. -/ open Finset LinearMap Set Convex Pointwise variable {𝕜 E F β ι : Type*} /-! ### Jensen's inequality -/ section Jensen variable [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [AddCommGroup E] [AddCommGroup β] [PartialOrder β] [IsOrderedAddMonoid β] [Module 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E} {f : E → β} {t : Finset ι} {w : ι → 𝕜} {p : ι → E} {v : 𝕜} {q : E} /-- Convex **Jensen's inequality**, `Finset.centerMass` version. -/ theorem ConvexOn.map_centerMass_le (hf : ConvexOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 ≤ w i) (h₁ : 0 < ∑ i ∈ t, w i) (hmem : ∀ i ∈ t, p i ∈ s) : f (t.centerMass w p) ≤ t.centerMass w (f ∘ p) := by have hmem' : ∀ i ∈ t, (p i, (f ∘ p) i) ∈ { p : E × β | p.1 ∈ s ∧ f p.1 ≤ p.2 } := fun i hi => ⟨hmem i hi, le_rfl⟩ convert (hf.convex_epigraph.centerMass_mem h₀ h₁ hmem').2 <;> simp only [centerMass, Function.comp, Prod.smul_fst, Prod.fst_sum, Prod.smul_snd, Prod.snd_sum] /-- Concave **Jensen's inequality**, `Finset.centerMass` version. -/ theorem ConcaveOn.le_map_centerMass (hf : ConcaveOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 ≤ w i) (h₁ : 0 < ∑ i ∈ t, w i) (hmem : ∀ i ∈ t, p i ∈ s) : t.centerMass w (f ∘ p) ≤ f (t.centerMass w p) := ConvexOn.map_centerMass_le (β := βᵒᵈ) hf h₀ h₁ hmem /-- Convex **Jensen's inequality**, `Finset.sum` version. -/ theorem ConvexOn.map_sum_le (hf : ConvexOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 ≤ w i) (h₁ : ∑ i ∈ t, w i = 1) (hmem : ∀ i ∈ t, p i ∈ s) : f (∑ i ∈ t, w i • p i) ≤ ∑ i ∈ t, w i • f (p i) := by simpa only [centerMass, h₁, inv_one, one_smul] using hf.map_centerMass_le h₀ (h₁.symm ▸ zero_lt_one) hmem /-- Concave **Jensen's inequality**, `Finset.sum` version. -/ theorem ConcaveOn.le_map_sum (hf : ConcaveOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 ≤ w i) (h₁ : ∑ i ∈ t, w i = 1) (hmem : ∀ i ∈ t, p i ∈ s) : (∑ i ∈ t, w i • f (p i)) ≤ f (∑ i ∈ t, w i • p i) := ConvexOn.map_sum_le (β := βᵒᵈ) hf h₀ h₁ hmem /-- Convex **Jensen's inequality** where an element plays a distinguished role. -/ lemma ConvexOn.map_add_sum_le (hf : ConvexOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 ≤ w i) (h₁ : v + ∑ i ∈ t, w i = 1) (hmem : ∀ i ∈ t, p i ∈ s) (hv : 0 ≤ v) (hq : q ∈ s) : f (v • q + ∑ i ∈ t, w i • p i) ≤ v • f q + ∑ i ∈ t, w i • f (p i) := by let W j := Option.elim j v w let P j := Option.elim j q p have : f (∑ j ∈ insertNone t, W j • P j) ≤ ∑ j ∈ insertNone t, W j • f (P j) := hf.map_sum_le (forall_mem_insertNone.2 ⟨hv, h₀⟩) (by simpa using h₁) (forall_mem_insertNone.2 ⟨hq, hmem⟩) simpa using this /-- Concave **Jensen's inequality** where an element plays a distinguished role. -/ lemma ConcaveOn.map_add_sum_le (hf : ConcaveOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 ≤ w i) (h₁ : v + ∑ i ∈ t, w i = 1) (hmem : ∀ i ∈ t, p i ∈ s) (hv : 0 ≤ v) (hq : q ∈ s) : v • f q + ∑ i ∈ t, w i • f (p i) ≤ f (v • q + ∑ i ∈ t, w i • p i) := hf.dual.map_add_sum_le h₀ h₁ hmem hv hq /-! ### Strict Jensen inequality -/ /-- Convex **strict Jensen inequality**. If the function is strictly convex, the weights are strictly positive and the indexed family of points is non-constant, then Jensen's inequality is strict. See also `StrictConvexOn.map_sum_eq_iff`. -/ lemma StrictConvexOn.map_sum_lt (hf : StrictConvexOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 < w i) (h₁ : ∑ i ∈ t, w i = 1) (hmem : ∀ i ∈ t, p i ∈ s) (hp : ∃ j ∈ t, ∃ k ∈ t, p j ≠ p k) :
f (∑ i ∈ t, w i • p i) < ∑ i ∈ t, w i • f (p i) := by classical obtain ⟨j, hj, k, hk, hjk⟩ := hp -- We replace `t` by `t \ {j, k}` have : k ∈ t.erase j := mem_erase.2 ⟨ne_of_apply_ne _ hjk.symm, hk⟩ let u := (t.erase j).erase k have hj : j ∉ u := by simp [u] have hk : k ∉ u := by simp [u] have ht : t = (u.cons k hk).cons j (mem_cons.not.2 <| not_or_intro (ne_of_apply_ne _ hjk) hj) := by simp [u, insert_erase this, insert_erase ‹j ∈ t›, *] clear_value u subst ht simp only [sum_cons] have := h₀ j <| by simp have := h₀ k <| by simp let c := w j + w k have hc : w j / c + w k / c = 1 := by field_simp [c] calc f (w j • p j + (w k • p k + ∑ x ∈ u, w x • p x)) _ = f (c • ((w j / c) • p j + (w k / c) • p k) + ∑ x ∈ u, w x • p x) := by congrm f ?_ match_scalars <;> field_simp _ ≤ c • f ((w j / c) • p j + (w k / c) • p k) + ∑ x ∈ u, w x • f (p x) := -- apply the usual Jensen's inequality wrt the weighted average of the two distinguished -- points and all the other points hf.convexOn.map_add_sum_le (fun i hi ↦ (h₀ _ <| by simp [hi]).le) (by simpa [-cons_eq_insert, ← add_assoc] using h₁) (forall_of_forall_cons <| forall_of_forall_cons hmem) (by positivity) <| by refine hf.1 (hmem _ <| by simp) (hmem _ <| by simp) ?_ ?_ hc <;> positivity _ < c • ((w j / c) • f (p j) + (w k / c) • f (p k)) + ∑ x ∈ u, w x • f (p x) := by -- then apply the definition of strict convexity for the two distinguished points gcongr; refine hf.2 (hmem _ <| by simp) (hmem _ <| by simp) hjk ?_ ?_ hc <;> positivity _ = (w j • f (p j) + w k • f (p k)) + ∑ x ∈ u, w x • f (p x) := by match_scalars <;> field_simp _ = w j • f (p j) + (w k • f (p k) + ∑ x ∈ u, w x • f (p x)) := by abel_nf /-- Concave **strict Jensen inequality**. If the function is strictly concave, the weights are strictly positive and the indexed family of points is non-constant, then Jensen's inequality is strict. See also `StrictConcaveOn.map_sum_eq_iff`. -/ lemma StrictConcaveOn.lt_map_sum (hf : StrictConcaveOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 < w i) (h₁ : ∑ i ∈ t, w i = 1) (hmem : ∀ i ∈ t, p i ∈ s) (hp : ∃ j ∈ t, ∃ k ∈ t, p j ≠ p k) :
Mathlib/Analysis/Convex/Jensen.lean
101
144
/- 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.Algebra.BigOperators.Group.Finset.Indicator import Mathlib.Algebra.Module.BigOperators import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace.Basic import Mathlib.LinearAlgebra.Finsupp.LinearCombination import Mathlib.Tactic.FinCases /-! # Affine combinations of points This file defines affine combinations of points. ## Main definitions * `weightedVSubOfPoint` is a general weighted combination of subtractions with an explicit base point, yielding a vector. * `weightedVSub` uses an arbitrary choice of base point and is intended to be used when the sum of weights is 0, in which case the result is independent of the choice of base point. * `affineCombination` adds the weighted combination to the arbitrary base point, yielding a point rather than a vector, and is intended to be used when the sum of weights is 1, in which case the result is independent of the choice of base point. These definitions are for sums over a `Finset`; versions for a `Fintype` may be obtained using `Finset.univ`, while versions for a `Finsupp` may be obtained using `Finsupp.support`. ## References * https://en.wikipedia.org/wiki/Affine_space -/ noncomputable section open Affine namespace Finset theorem univ_fin2 : (univ : Finset (Fin 2)) = {0, 1} := by ext x fin_cases x <;> simp variable {k : Type*} {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] variable [S : AffineSpace V P] variable {ι : Type*} (s : Finset ι) variable {ι₂ : Type*} (s₂ : Finset ι₂) /-- A weighted sum of the results of subtracting a base point from the given points, as a linear map on the weights. The main cases of interest are where the sum of the weights is 0, in which case the sum is independent of the choice of base point, and where the sum of the weights is 1, in which case the sum added to the base point is independent of the choice of base point. -/ def weightedVSubOfPoint (p : ι → P) (b : P) : (ι → k) →ₗ[k] V := ∑ i ∈ s, (LinearMap.proj i : (ι → k) →ₗ[k] k).smulRight (p i -ᵥ b) @[simp] theorem weightedVSubOfPoint_apply (w : ι → k) (p : ι → P) (b : P) : s.weightedVSubOfPoint p b w = ∑ i ∈ s, w i • (p i -ᵥ b) := by simp [weightedVSubOfPoint, LinearMap.sum_apply] /-- The value of `weightedVSubOfPoint`, where the given points are equal. -/ @[simp (high)] theorem weightedVSubOfPoint_apply_const (w : ι → k) (p : P) (b : P) : s.weightedVSubOfPoint (fun _ => p) b w = (∑ i ∈ s, w i) • (p -ᵥ b) := by rw [weightedVSubOfPoint_apply, sum_smul] lemma weightedVSubOfPoint_vadd (s : Finset ι) (w : ι → k) (p : ι → P) (b : P) (v : V) : s.weightedVSubOfPoint (v +ᵥ p) b w = s.weightedVSubOfPoint p (-v +ᵥ b) w := by simp [vadd_vsub_assoc, vsub_vadd_eq_vsub_sub, add_comm] lemma weightedVSubOfPoint_smul {G : Type*} [Group G] [DistribMulAction G V] [SMulCommClass G k V] (s : Finset ι) (w : ι → k) (p : ι → V) (b : V) (a : G) : s.weightedVSubOfPoint (a • p) b w = a • s.weightedVSubOfPoint p (a⁻¹ • b) w := by simp [smul_sum, smul_sub, smul_comm a (w _)] /-- `weightedVSubOfPoint` gives equal results for two families of weights and two families of points that are equal on `s`. -/ theorem weightedVSubOfPoint_congr {w₁ w₂ : ι → k} (hw : ∀ i ∈ s, w₁ i = w₂ i) {p₁ p₂ : ι → P} (hp : ∀ i ∈ s, p₁ i = p₂ i) (b : P) : s.weightedVSubOfPoint p₁ b w₁ = s.weightedVSubOfPoint p₂ b w₂ := by simp_rw [weightedVSubOfPoint_apply] refine sum_congr rfl fun i hi => ?_ rw [hw i hi, hp i hi] /-- Given a family of points, if we use a member of the family as a base point, the `weightedVSubOfPoint` does not depend on the value of the weights at this point. -/ theorem weightedVSubOfPoint_eq_of_weights_eq (p : ι → P) (j : ι) (w₁ w₂ : ι → k) (hw : ∀ i, i ≠ j → w₁ i = w₂ i) : s.weightedVSubOfPoint p (p j) w₁ = s.weightedVSubOfPoint p (p j) w₂ := by simp only [Finset.weightedVSubOfPoint_apply] congr ext i rcases eq_or_ne i j with h | h · simp [h] · simp [hw i h] /-- The weighted sum is independent of the base point when the sum of the weights is 0. -/ theorem weightedVSubOfPoint_eq_of_sum_eq_zero (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 0) (b₁ b₂ : P) : s.weightedVSubOfPoint p b₁ w = s.weightedVSubOfPoint p b₂ w := by apply eq_of_sub_eq_zero rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← sum_sub_distrib] conv_lhs => congr · skip · ext rw [← smul_sub, vsub_sub_vsub_cancel_left] rw [← sum_smul, h, zero_smul] /-- The weighted sum, added to the base point, is independent of the base point when the sum of the weights is 1. -/ theorem weightedVSubOfPoint_vadd_eq_of_sum_eq_one (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 1) (b₁ b₂ : P) : s.weightedVSubOfPoint p b₁ w +ᵥ b₁ = s.weightedVSubOfPoint p b₂ w +ᵥ b₂ := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← @vsub_eq_zero_iff_eq V, vadd_vsub_assoc, vsub_vadd_eq_vsub_sub, ← add_sub_assoc, add_comm, add_sub_assoc, ← sum_sub_distrib] conv_lhs => congr · skip · congr · skip · ext rw [← smul_sub, vsub_sub_vsub_cancel_left] rw [← sum_smul, h, one_smul, vsub_add_vsub_cancel, vsub_self] /-- The weighted sum is unaffected by removing the base point, if present, from the set of points. -/ @[simp (high)] theorem weightedVSubOfPoint_erase [DecidableEq ι] (w : ι → k) (p : ι → P) (i : ι) : (s.erase i).weightedVSubOfPoint p (p i) w = s.weightedVSubOfPoint p (p i) w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply] apply sum_erase rw [vsub_self, smul_zero] /-- The weighted sum is unaffected by adding the base point, whether or not present, to the set of points. -/ @[simp (high)] theorem weightedVSubOfPoint_insert [DecidableEq ι] (w : ι → k) (p : ι → P) (i : ι) : (insert i s).weightedVSubOfPoint p (p i) w = s.weightedVSubOfPoint p (p i) w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply] apply sum_insert_zero rw [vsub_self, smul_zero] /-- The weighted sum is unaffected by changing the weights to the corresponding indicator function and adding points to the set. -/ theorem weightedVSubOfPoint_indicator_subset (w : ι → k) (p : ι → P) (b : P) {s₁ s₂ : Finset ι} (h : s₁ ⊆ s₂) : s₁.weightedVSubOfPoint p b w = s₂.weightedVSubOfPoint p b (Set.indicator (↑s₁) w) := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply] exact Eq.symm <| sum_indicator_subset_of_eq_zero w (fun i wi => wi • (p i -ᵥ b : V)) h fun i => zero_smul k _ /-- A weighted sum, over the image of an embedding, equals a weighted sum with the same points and weights over the original `Finset`. -/ theorem weightedVSubOfPoint_map (e : ι₂ ↪ ι) (w : ι → k) (p : ι → P) (b : P) : (s₂.map e).weightedVSubOfPoint p b w = s₂.weightedVSubOfPoint (p ∘ e) b (w ∘ e) := by simp_rw [weightedVSubOfPoint_apply] exact Finset.sum_map _ _ _ /-- A weighted sum of pairwise subtractions, expressed as a subtraction of two `weightedVSubOfPoint` expressions. -/ theorem sum_smul_vsub_eq_weightedVSubOfPoint_sub (w : ι → k) (p₁ p₂ : ι → P) (b : P) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂ i)) = s.weightedVSubOfPoint p₁ b w - s.weightedVSubOfPoint p₂ b w := by simp_rw [weightedVSubOfPoint_apply, ← sum_sub_distrib, ← smul_sub, vsub_sub_vsub_cancel_right] /-- A weighted sum of pairwise subtractions, where the point on the right is constant, expressed as a subtraction involving a `weightedVSubOfPoint` expression. -/ theorem sum_smul_vsub_const_eq_weightedVSubOfPoint_sub (w : ι → k) (p₁ : ι → P) (p₂ b : P) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂)) = s.weightedVSubOfPoint p₁ b w - (∑ i ∈ s, w i) • (p₂ -ᵥ b) := by rw [sum_smul_vsub_eq_weightedVSubOfPoint_sub, weightedVSubOfPoint_apply_const] /-- A weighted sum of pairwise subtractions, where the point on the left is constant, expressed as a subtraction involving a `weightedVSubOfPoint` expression. -/ theorem sum_smul_const_vsub_eq_sub_weightedVSubOfPoint (w : ι → k) (p₂ : ι → P) (p₁ b : P) : (∑ i ∈ s, w i • (p₁ -ᵥ p₂ i)) = (∑ i ∈ s, w i) • (p₁ -ᵥ b) - s.weightedVSubOfPoint p₂ b w := by rw [sum_smul_vsub_eq_weightedVSubOfPoint_sub, weightedVSubOfPoint_apply_const] /-- A weighted sum may be split into such sums over two subsets. -/ theorem weightedVSubOfPoint_sdiff [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) (b : P) : (s \ s₂).weightedVSubOfPoint p b w + s₂.weightedVSubOfPoint p b w = s.weightedVSubOfPoint p b w := by simp_rw [weightedVSubOfPoint_apply, sum_sdiff h] /-- A weighted sum may be split into a subtraction of such sums over two subsets. -/ theorem weightedVSubOfPoint_sdiff_sub [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) (b : P) : (s \ s₂).weightedVSubOfPoint p b w - s₂.weightedVSubOfPoint p b (-w) = s.weightedVSubOfPoint p b w := by rw [map_neg, sub_neg_eq_add, s.weightedVSubOfPoint_sdiff h] /-- A weighted sum over `s.subtype pred` equals one over `{x ∈ s | pred x}`. -/ theorem weightedVSubOfPoint_subtype_eq_filter (w : ι → k) (p : ι → P) (b : P) (pred : ι → Prop) [DecidablePred pred] : ((s.subtype pred).weightedVSubOfPoint (fun i => p i) b fun i => w i) = {x ∈ s | pred x}.weightedVSubOfPoint p b w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← sum_subtype_eq_sum_filter] /-- A weighted sum over `{x ∈ s | pred x}` equals one over `s` if all the weights at indices in `s` not satisfying `pred` are zero. -/ theorem weightedVSubOfPoint_filter_of_ne (w : ι → k) (p : ι → P) (b : P) {pred : ι → Prop} [DecidablePred pred] (h : ∀ i ∈ s, w i ≠ 0 → pred i) : {x ∈ s | pred x}.weightedVSubOfPoint p b w = s.weightedVSubOfPoint p b w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, sum_filter_of_ne] intro i hi hne refine h i hi ?_ intro hw simp [hw] at hne /-- A constant multiplier of the weights in `weightedVSubOfPoint` may be moved outside the sum. -/ theorem weightedVSubOfPoint_const_smul (w : ι → k) (p : ι → P) (b : P) (c : k) : s.weightedVSubOfPoint p b (c • w) = c • s.weightedVSubOfPoint p b w := by simp_rw [weightedVSubOfPoint_apply, smul_sum, Pi.smul_apply, smul_smul, smul_eq_mul] /-- A weighted sum of the results of subtracting a default base point from the given points, as a linear map on the weights. This is intended to be used when the sum of the weights is 0; that condition is specified as a hypothesis on those lemmas that require it. -/ def weightedVSub (p : ι → P) : (ι → k) →ₗ[k] V := s.weightedVSubOfPoint p (Classical.choice S.nonempty) /-- Applying `weightedVSub` with given weights. This is for the case where a result involving a default base point is OK (for example, when that base point will cancel out later); a more typical use case for `weightedVSub` would involve selecting a preferred base point with `weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero` and then using `weightedVSubOfPoint_apply`. -/ theorem weightedVSub_apply (w : ι → k) (p : ι → P) : s.weightedVSub p w = ∑ i ∈ s, w i • (p i -ᵥ Classical.choice S.nonempty) := by simp [weightedVSub, LinearMap.sum_apply] /-- `weightedVSub` gives the sum of the results of subtracting any base point, when the sum of the weights is 0. -/ theorem weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 0) (b : P) : s.weightedVSub p w = s.weightedVSubOfPoint p b w := s.weightedVSubOfPoint_eq_of_sum_eq_zero w p h _ _ /-- The value of `weightedVSub`, where the given points are equal and the sum of the weights is 0. -/ @[simp] theorem weightedVSub_apply_const (w : ι → k) (p : P) (h : ∑ i ∈ s, w i = 0) : s.weightedVSub (fun _ => p) w = 0 := by rw [weightedVSub, weightedVSubOfPoint_apply_const, h, zero_smul] /-- The `weightedVSub` for an empty set is 0. -/ @[simp] theorem weightedVSub_empty (w : ι → k) (p : ι → P) : (∅ : Finset ι).weightedVSub p w = (0 : V) := by simp [weightedVSub_apply] lemma weightedVSub_vadd {s : Finset ι} {w : ι → k} (h : ∑ i ∈ s, w i = 0) (p : ι → P) (v : V) : s.weightedVSub (v +ᵥ p) w = s.weightedVSub p w := by rw [weightedVSub, weightedVSubOfPoint_vadd, weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero _ _ _ h] lemma weightedVSub_smul {G : Type*} [Group G] [DistribMulAction G V] [SMulCommClass G k V] {s : Finset ι} {w : ι → k} (h : ∑ i ∈ s, w i = 0) (p : ι → V) (a : G) : s.weightedVSub (a • p) w = a • s.weightedVSub p w := by rw [weightedVSub, weightedVSubOfPoint_smul, weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero _ _ _ h] /-- `weightedVSub` gives equal results for two families of weights and two families of points that are equal on `s`. -/ theorem weightedVSub_congr {w₁ w₂ : ι → k} (hw : ∀ i ∈ s, w₁ i = w₂ i) {p₁ p₂ : ι → P} (hp : ∀ i ∈ s, p₁ i = p₂ i) : s.weightedVSub p₁ w₁ = s.weightedVSub p₂ w₂ := s.weightedVSubOfPoint_congr hw hp _ /-- The weighted sum is unaffected by changing the weights to the corresponding indicator function and adding points to the set. -/ theorem weightedVSub_indicator_subset (w : ι → k) (p : ι → P) {s₁ s₂ : Finset ι} (h : s₁ ⊆ s₂) : s₁.weightedVSub p w = s₂.weightedVSub p (Set.indicator (↑s₁) w) := weightedVSubOfPoint_indicator_subset _ _ _ h /-- A weighted subtraction, over the image of an embedding, equals a weighted subtraction with the same points and weights over the original `Finset`. -/ theorem weightedVSub_map (e : ι₂ ↪ ι) (w : ι → k) (p : ι → P) : (s₂.map e).weightedVSub p w = s₂.weightedVSub (p ∘ e) (w ∘ e) := s₂.weightedVSubOfPoint_map _ _ _ _ /-- A weighted sum of pairwise subtractions, expressed as a subtraction of two `weightedVSub` expressions. -/ theorem sum_smul_vsub_eq_weightedVSub_sub (w : ι → k) (p₁ p₂ : ι → P) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂ i)) = s.weightedVSub p₁ w - s.weightedVSub p₂ w := s.sum_smul_vsub_eq_weightedVSubOfPoint_sub _ _ _ _ /-- A weighted sum of pairwise subtractions, where the point on the right is constant and the sum of the weights is 0. -/ theorem sum_smul_vsub_const_eq_weightedVSub (w : ι → k) (p₁ : ι → P) (p₂ : P) (h : ∑ i ∈ s, w i = 0) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂)) = s.weightedVSub p₁ w := by rw [sum_smul_vsub_eq_weightedVSub_sub, s.weightedVSub_apply_const _ _ h, sub_zero] /-- A weighted sum of pairwise subtractions, where the point on the left is constant and the sum of the weights is 0. -/ theorem sum_smul_const_vsub_eq_neg_weightedVSub (w : ι → k) (p₂ : ι → P) (p₁ : P) (h : ∑ i ∈ s, w i = 0) : (∑ i ∈ s, w i • (p₁ -ᵥ p₂ i)) = -s.weightedVSub p₂ w := by rw [sum_smul_vsub_eq_weightedVSub_sub, s.weightedVSub_apply_const _ _ h, zero_sub] /-- A weighted sum may be split into such sums over two subsets. -/ theorem weightedVSub_sdiff [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) : (s \ s₂).weightedVSub p w + s₂.weightedVSub p w = s.weightedVSub p w := s.weightedVSubOfPoint_sdiff h _ _ _ /-- A weighted sum may be split into a subtraction of such sums over two subsets. -/ theorem weightedVSub_sdiff_sub [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) : (s \ s₂).weightedVSub p w - s₂.weightedVSub p (-w) = s.weightedVSub p w := s.weightedVSubOfPoint_sdiff_sub h _ _ _ /-- A weighted sum over `s.subtype pred` equals one over `{x ∈ s | pred x}`. -/ theorem weightedVSub_subtype_eq_filter (w : ι → k) (p : ι → P) (pred : ι → Prop) [DecidablePred pred] : ((s.subtype pred).weightedVSub (fun i => p i) fun i => w i) = {x ∈ s | pred x}.weightedVSub p w := s.weightedVSubOfPoint_subtype_eq_filter _ _ _ _ /-- A weighted sum over `{x ∈ s | pred x}` equals one over `s` if all the weights at indices in `s` not satisfying `pred` are zero. -/ theorem weightedVSub_filter_of_ne (w : ι → k) (p : ι → P) {pred : ι → Prop} [DecidablePred pred] (h : ∀ i ∈ s, w i ≠ 0 → pred i) : {x ∈ s | pred x}.weightedVSub p w = s.weightedVSub p w := s.weightedVSubOfPoint_filter_of_ne _ _ _ h /-- A constant multiplier of the weights in `weightedVSub_of` may be moved outside the sum. -/ theorem weightedVSub_const_smul (w : ι → k) (p : ι → P) (c : k) : s.weightedVSub p (c • w) = c • s.weightedVSub p w := s.weightedVSubOfPoint_const_smul _ _ _ _ instance : AffineSpace (ι → k) (ι → k) := Pi.instAddTorsor variable (k) /-- A weighted sum of the results of subtracting a default base point from the given points, added to that base point, as an affine map on the weights. This is intended to be used when the sum of the weights is 1, in which case it is an affine combination (barycenter) of the points with the given weights; that condition is specified as a hypothesis on those lemmas that require it. -/ def affineCombination (p : ι → P) : (ι → k) →ᵃ[k] P where toFun w := s.weightedVSubOfPoint p (Classical.choice S.nonempty) w +ᵥ Classical.choice S.nonempty linear := s.weightedVSub p map_vadd' w₁ w₂ := by simp_rw [vadd_vadd, weightedVSub, vadd_eq_add, LinearMap.map_add] /-- The linear map corresponding to `affineCombination` is `weightedVSub`. -/ @[simp] theorem affineCombination_linear (p : ι → P) : (s.affineCombination k p).linear = s.weightedVSub p := rfl variable {k} /-- Applying `affineCombination` with given weights. This is for the case where a result involving a default base point is OK (for example, when that base point will cancel out later); a more typical use case for `affineCombination` would involve selecting a preferred base point with `affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one` and then using `weightedVSubOfPoint_apply`. -/ theorem affineCombination_apply (w : ι → k) (p : ι → P) : (s.affineCombination k p) w = s.weightedVSubOfPoint p (Classical.choice S.nonempty) w +ᵥ Classical.choice S.nonempty := rfl /-- The value of `affineCombination`, where the given points are equal. -/ @[simp] theorem affineCombination_apply_const (w : ι → k) (p : P) (h : ∑ i ∈ s, w i = 1) : s.affineCombination k (fun _ => p) w = p := by rw [affineCombination_apply, s.weightedVSubOfPoint_apply_const, h, one_smul, vsub_vadd] /-- `affineCombination` gives equal results for two families of weights and two families of points that are equal on `s`. -/ theorem affineCombination_congr {w₁ w₂ : ι → k} (hw : ∀ i ∈ s, w₁ i = w₂ i) {p₁ p₂ : ι → P} (hp : ∀ i ∈ s, p₁ i = p₂ i) : s.affineCombination k p₁ w₁ = s.affineCombination k p₂ w₂ := by simp_rw [affineCombination_apply, s.weightedVSubOfPoint_congr hw hp] /-- `affineCombination` gives the sum with any base point, when the sum of the weights is 1. -/ theorem affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 1) (b : P) : s.affineCombination k p w = s.weightedVSubOfPoint p b w +ᵥ b := s.weightedVSubOfPoint_vadd_eq_of_sum_eq_one w p h _ _ /-- Adding a `weightedVSub` to an `affineCombination`. -/ theorem weightedVSub_vadd_affineCombination (w₁ w₂ : ι → k) (p : ι → P) : s.weightedVSub p w₁ +ᵥ s.affineCombination k p w₂ = s.affineCombination k p (w₁ + w₂) := by rw [← vadd_eq_add, AffineMap.map_vadd, affineCombination_linear] /-- Subtracting two `affineCombination`s. -/ theorem affineCombination_vsub (w₁ w₂ : ι → k) (p : ι → P) : s.affineCombination k p w₁ -ᵥ s.affineCombination k p w₂ = s.weightedVSub p (w₁ - w₂) := by rw [← AffineMap.linearMap_vsub, affineCombination_linear, vsub_eq_sub] theorem attach_affineCombination_of_injective [DecidableEq P] (s : Finset P) (w : P → k) (f : s → P) (hf : Function.Injective f) : s.attach.affineCombination k f (w ∘ f) = (image f univ).affineCombination k id w := by simp only [affineCombination, weightedVSubOfPoint_apply, id, vadd_right_cancel_iff, Function.comp_apply, AffineMap.coe_mk] let g₁ : s → V := fun i => w (f i) • (f i -ᵥ Classical.choice S.nonempty) let g₂ : P → V := fun i => w i • (i -ᵥ Classical.choice S.nonempty) change univ.sum g₁ = (image f univ).sum g₂ have hgf : g₁ = g₂ ∘ f := by ext simp [g₁, g₂] rw [hgf, sum_image] · simp only [g₁, g₂,Function.comp_apply] · exact fun _ _ _ _ hxy => hf hxy theorem attach_affineCombination_coe (s : Finset P) (w : P → k) : s.attach.affineCombination k ((↑) : s → P) (w ∘ (↑)) = s.affineCombination k id w := by classical rw [attach_affineCombination_of_injective s w ((↑) : s → P) Subtype.coe_injective, univ_eq_attach, attach_image_val] /-- Viewing a module as an affine space modelled on itself, a `weightedVSub` is just a linear combination. -/ @[simp] theorem weightedVSub_eq_linear_combination {ι} (s : Finset ι) {w : ι → k} {p : ι → V} (hw : s.sum w = 0) : s.weightedVSub p w = ∑ i ∈ s, w i • p i := by simp [s.weightedVSub_apply, vsub_eq_sub, smul_sub, ← Finset.sum_smul, hw] /-- Viewing a module as an affine space modelled on itself, affine combinations are just linear combinations. -/ @[simp] theorem affineCombination_eq_linear_combination (s : Finset ι) (p : ι → V) (w : ι → k) (hw : ∑ i ∈ s, w i = 1) : s.affineCombination k p w = ∑ i ∈ s, w i • p i := by simp [s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w p hw 0] /-- An `affineCombination` equals a point if that point is in the set and has weight 1 and the other points in the set have weight 0. -/ @[simp] theorem affineCombination_of_eq_one_of_eq_zero (w : ι → k) (p : ι → P) {i : ι} (his : i ∈ s) (hwi : w i = 1) (hw0 : ∀ i2 ∈ s, i2 ≠ i → w i2 = 0) : s.affineCombination k p w = p i := by have h1 : ∑ i ∈ s, w i = 1 := hwi ▸ sum_eq_single i hw0 fun h => False.elim (h his) rw [s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w p h1 (p i), weightedVSubOfPoint_apply] convert zero_vadd V (p i) refine sum_eq_zero ?_ intro i2 hi2 by_cases h : i2 = i · simp [h] · simp [hw0 i2 hi2 h] /-- An affine combination is unaffected by changing the weights to the corresponding indicator function and adding points to the set. -/ theorem affineCombination_indicator_subset (w : ι → k) (p : ι → P) {s₁ s₂ : Finset ι} (h : s₁ ⊆ s₂) : s₁.affineCombination k p w = s₂.affineCombination k p (Set.indicator (↑s₁) w) := by rw [affineCombination_apply, affineCombination_apply, weightedVSubOfPoint_indicator_subset _ _ _ h] /-- An affine combination, over the image of an embedding, equals an affine combination with the same points and weights over the original `Finset`. -/ theorem affineCombination_map (e : ι₂ ↪ ι) (w : ι → k) (p : ι → P) : (s₂.map e).affineCombination k p w = s₂.affineCombination k (p ∘ e) (w ∘ e) := by simp_rw [affineCombination_apply, weightedVSubOfPoint_map] /-- A weighted sum of pairwise subtractions, expressed as a subtraction of two `affineCombination` expressions. -/ theorem sum_smul_vsub_eq_affineCombination_vsub (w : ι → k) (p₁ p₂ : ι → P) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂ i)) = s.affineCombination k p₁ w -ᵥ s.affineCombination k p₂ w := by simp_rw [affineCombination_apply, vadd_vsub_vadd_cancel_right] exact s.sum_smul_vsub_eq_weightedVSubOfPoint_sub _ _ _ _ /-- A weighted sum of pairwise subtractions, where the point on the right is constant and the sum of the weights is 1. -/ theorem sum_smul_vsub_const_eq_affineCombination_vsub (w : ι → k) (p₁ : ι → P) (p₂ : P) (h : ∑ i ∈ s, w i = 1) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂)) = s.affineCombination k p₁ w -ᵥ p₂ := by rw [sum_smul_vsub_eq_affineCombination_vsub, affineCombination_apply_const _ _ _ h] /-- A weighted sum of pairwise subtractions, where the point on the left is constant and the sum of the weights is 1. -/ theorem sum_smul_const_vsub_eq_vsub_affineCombination (w : ι → k) (p₂ : ι → P) (p₁ : P) (h : ∑ i ∈ s, w i = 1) : (∑ i ∈ s, w i • (p₁ -ᵥ p₂ i)) = p₁ -ᵥ s.affineCombination k p₂ w := by rw [sum_smul_vsub_eq_affineCombination_vsub, affineCombination_apply_const _ _ _ h] /-- A weighted sum may be split into a subtraction of affine combinations over two subsets. -/ theorem affineCombination_sdiff_sub [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) : (s \ s₂).affineCombination k p w -ᵥ s₂.affineCombination k p (-w) = s.weightedVSub p w := by simp_rw [affineCombination_apply, vadd_vsub_vadd_cancel_right] exact s.weightedVSub_sdiff_sub h _ _ /-- If a weighted sum is zero and one of the weights is `-1`, the corresponding point is the affine combination of the other points with the given weights. -/ theorem affineCombination_eq_of_weightedVSub_eq_zero_of_eq_neg_one {w : ι → k} {p : ι → P} (hw : s.weightedVSub p w = (0 : V)) {i : ι} [DecidablePred (· ≠ i)] (his : i ∈ s) (hwi : w i = -1) : {x ∈ s | x ≠ i}.affineCombination k p w = p i := by classical rw [← @vsub_eq_zero_iff_eq V, ← hw, ← s.affineCombination_sdiff_sub (singleton_subset_iff.2 his), sdiff_singleton_eq_erase, ← filter_ne'] congr refine (affineCombination_of_eq_one_of_eq_zero _ _ _ (mem_singleton_self _) ?_ ?_).symm · simp [hwi] · simp /-- An affine combination over `s.subtype pred` equals one over `{x ∈ s | pred x}`. -/ theorem affineCombination_subtype_eq_filter (w : ι → k) (p : ι → P) (pred : ι → Prop) [DecidablePred pred] : ((s.subtype pred).affineCombination k (fun i => p i) fun i => w i) = {x ∈ s | pred x}.affineCombination k p w := by rw [affineCombination_apply, affineCombination_apply, weightedVSubOfPoint_subtype_eq_filter] /-- An affine combination over `{x ∈ s | pred x}` equals one over `s` if all the weights at indices in `s` not satisfying `pred` are zero. -/ theorem affineCombination_filter_of_ne (w : ι → k) (p : ι → P) {pred : ι → Prop} [DecidablePred pred] (h : ∀ i ∈ s, w i ≠ 0 → pred i) : {x ∈ s | pred x}.affineCombination k p w = s.affineCombination k p w := by rw [affineCombination_apply, affineCombination_apply, s.weightedVSubOfPoint_filter_of_ne _ _ _ h] /-- Suppose an indexed family of points is given, along with a subset of the index type. A vector can be expressed as `weightedVSubOfPoint` using a `Finset` lying within that subset and with a given sum of weights if and only if it can be expressed as `weightedVSubOfPoint` with that sum of weights for the corresponding indexed family whose index type is the subtype corresponding to that subset. -/ theorem eq_weightedVSubOfPoint_subset_iff_eq_weightedVSubOfPoint_subtype {v : V} {x : k} {s : Set ι} {p : ι → P} {b : P} : (∃ fs : Finset ι, ↑fs ⊆ s ∧ ∃ w : ι → k, ∑ i ∈ fs, w i = x ∧ v = fs.weightedVSubOfPoint p b w) ↔
∃ (fs : Finset s) (w : s → k), ∑ i ∈ fs, w i = x ∧ v = fs.weightedVSubOfPoint (fun i : s => p i) b w := by classical simp_rw [weightedVSubOfPoint_apply] constructor · rintro ⟨fs, hfs, w, rfl, rfl⟩ exact ⟨fs.subtype s, fun i => w i, sum_subtype_of_mem _ hfs, (sum_subtype_of_mem _ hfs).symm⟩ · rintro ⟨fs, w, rfl, rfl⟩ refine ⟨fs.map (Function.Embedding.subtype _), map_subtype_subset _, fun i => if h : i ∈ s then w ⟨i, h⟩ else 0, ?_, ?_⟩ <;>
Mathlib/LinearAlgebra/AffineSpace/Combination.lean
535
545
/- Copyright (c) 2022 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Gabin Kolly -/ import Mathlib.Data.Finite.Sum import Mathlib.Data.Fintype.Order import Mathlib.ModelTheory.FinitelyGenerated import Mathlib.ModelTheory.Quotients import Mathlib.Order.DirectedInverseSystem /-! # Direct Limits of First-Order Structures This file constructs the direct limit of a directed system of first-order embeddings. ## Main Definitions - `FirstOrder.Language.DirectLimit G f` is the direct limit of the directed system `f` of first-order embeddings between the structures indexed by `G`. - `FirstOrder.Language.DirectLimit.lift` is the universal property of the direct limit: maps from the components to another module that respect the directed system structure give rise to a unique map out of the direct limit. - `FirstOrder.Language.DirectLimit.equiv_lift` is the equivalence between limits of isomorphic direct systems. -/ universe v w w' u₁ u₂ open FirstOrder namespace FirstOrder namespace Language open Structure Set variable {L : Language} {ι : Type v} [Preorder ι] variable {G : ι → Type w} [∀ i, L.Structure (G i)] variable (f : ∀ i j, i ≤ j → G i ↪[L] G j) namespace DirectedSystem alias map_self := DirectedSystem.map_self' alias map_map := DirectedSystem.map_map' variable {G' : ℕ → Type w} [∀ i, L.Structure (G' i)] (f' : ∀ n : ℕ, G' n ↪[L] G' (n + 1)) /-- Given a chain of embeddings of structures indexed by `ℕ`, defines a `DirectedSystem` by composing them. -/ def natLERec (m n : ℕ) (h : m ≤ n) : G' m ↪[L] G' n := Nat.leRecOn h (@fun k g => (f' k).comp g) (Embedding.refl L _) @[simp] theorem coe_natLERec (m n : ℕ) (h : m ≤ n) : (natLERec f' m n h : G' m → G' n) = Nat.leRecOn h (@fun k => f' k) := by obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le h ext x induction' k with k ih · -- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644 erw [natLERec, Nat.leRecOn_self, Embedding.refl_apply, Nat.leRecOn_self] · -- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644 erw [Nat.leRecOn_succ le_self_add, natLERec, Nat.leRecOn_succ le_self_add, ← natLERec, Embedding.comp_apply, ih] instance natLERec.directedSystem : DirectedSystem G' fun i j h => natLERec f' i j h := ⟨fun _ _ => congr (congr rfl (Nat.leRecOn_self _)) rfl, fun _ _ _ hij hjk => by simp [Nat.leRecOn_trans hij hjk]⟩ end DirectedSystem set_option linter.unusedVariables false in /-- Alias for `Σ i, G i`. Instead of `Σ i, G i`, we use the alias `Language.Structure.Sigma` which depends on `f`. This way, Lean can infer what `L` and `f` are in the `Setoid` instance. Otherwise we have a "cannot find synthesization order" error. See also the discussion at https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/local.20instance.20cannot.20find.20synthesization.20order.20in.20porting -/ @[nolint unusedArguments] protected abbrev Structure.Sigma (f : ∀ i j, i ≤ j → G i ↪[L] G j) := Σ i, G i local notation "Σˣ" => Structure.Sigma /-- Constructor for `FirstOrder.Language.Structure.Sigma` alias. -/ abbrev Structure.Sigma.mk (i : ι) (x : G i) : Σˣ f := ⟨i, x⟩ namespace DirectLimit /-- Raises a family of elements in the `Σ`-type to the same level along the embeddings. -/ def unify {α : Type*} (x : α → Σˣ f) (i : ι) (h : i ∈ upperBounds (range (Sigma.fst ∘ x))) (a : α) : G i := f (x a).1 i (h (mem_range_self a)) (x a).2 variable [DirectedSystem G fun i j h => f i j h] @[simp] theorem unify_sigma_mk_self {α : Type*} {i : ι} {x : α → G i} : (unify f (fun a => .mk f i (x a)) i fun _ ⟨_, hj⟩ => _root_.trans (le_of_eq hj.symm) (refl _)) = x := by ext a rw [unify] apply DirectedSystem.map_self theorem comp_unify {α : Type*} {x : α → Σˣ f} {i j : ι} (ij : i ≤ j) (h : i ∈ upperBounds (range (Sigma.fst ∘ x))) : f i j ij ∘ unify f x i h = unify f x j fun k hk => _root_.trans (mem_upperBounds.1 h k hk) ij := by ext a simp [unify, DirectedSystem.map_map] end DirectLimit variable (G) namespace DirectLimit /-- The directed limit glues together the structures along the embeddings. -/ def setoid [DirectedSystem G fun i j h => f i j h] [IsDirected ι (· ≤ ·)] : Setoid (Σˣ f) where r := fun ⟨i, x⟩ ⟨j, y⟩ => ∃ (k : ι) (ik : i ≤ k) (jk : j ≤ k), f i k ik x = f j k jk y iseqv := ⟨fun ⟨i, _⟩ => ⟨i, refl i, refl i, rfl⟩, @fun ⟨_, _⟩ ⟨_, _⟩ ⟨k, ik, jk, h⟩ => ⟨k, jk, ik, h.symm⟩, @fun ⟨i, x⟩ ⟨j, y⟩ ⟨k, z⟩ ⟨ij, hiij, hjij, hij⟩ ⟨jk, hjjk, hkjk, hjk⟩ => by obtain ⟨ijk, hijijk, hjkijk⟩ := directed_of (· ≤ ·) ij jk refine ⟨ijk, le_trans hiij hijijk, le_trans hkjk hjkijk, ?_⟩ rw [← DirectedSystem.map_map, hij, DirectedSystem.map_map] · symm rw [← DirectedSystem.map_map, ← hjk, DirectedSystem.map_map] assumption assumption⟩ /-- The structure on the `Σ`-type which becomes the structure on the direct limit after quotienting. -/ noncomputable def sigmaStructure [IsDirected ι (· ≤ ·)] [Nonempty ι] : L.Structure (Σˣ f) where funMap F x := ⟨_, funMap F (unify f x (Classical.choose (Finite.bddAbove_range fun a => (x a).1)) (Classical.choose_spec (Finite.bddAbove_range fun a => (x a).1)))⟩ RelMap R x := RelMap R (unify f x (Classical.choose (Finite.bddAbove_range fun a => (x a).1)) (Classical.choose_spec (Finite.bddAbove_range fun a => (x a).1))) end DirectLimit /-- The direct limit of a directed system is the structures glued together along the embeddings. -/ def DirectLimit [DirectedSystem G fun i j h => f i j h] [IsDirected ι (· ≤ ·)] := Quotient (DirectLimit.setoid G f) attribute [local instance] DirectLimit.setoid DirectLimit.sigmaStructure instance [DirectedSystem G fun i j h => f i j h] [IsDirected ι (· ≤ ·)] [Inhabited ι] [Inhabited (G default)] : Inhabited (DirectLimit G f) := ⟨⟦⟨default, default⟩⟧⟩ namespace DirectLimit variable [IsDirected ι (· ≤ ·)] [DirectedSystem G fun i j h => f i j h] theorem equiv_iff {x y : Σˣ f} {i : ι} (hx : x.1 ≤ i) (hy : y.1 ≤ i) : x ≈ y ↔ (f x.1 i hx) x.2 = (f y.1 i hy) y.2 := by cases x cases y refine ⟨fun xy => ?_, fun xy => ⟨i, hx, hy, xy⟩⟩ obtain ⟨j, _, _, h⟩ := xy obtain ⟨k, ik, jk⟩ := directed_of (· ≤ ·) i j have h := congr_arg (f j k jk) h apply (f i k ik).injective rw [DirectedSystem.map_map, DirectedSystem.map_map] at * exact h theorem funMap_unify_equiv {n : ℕ} (F : L.Functions n) (x : Fin n → Σˣ f) (i j : ι) (hi : i ∈ upperBounds (range (Sigma.fst ∘ x))) (hj : j ∈ upperBounds (range (Sigma.fst ∘ x))) : Structure.Sigma.mk f i (funMap F (unify f x i hi)) ≈ .mk f j (funMap F (unify f x j hj)) := by obtain ⟨k, ik, jk⟩ := directed_of (· ≤ ·) i j refine ⟨k, ik, jk, ?_⟩ rw [(f i k ik).map_fun, (f j k jk).map_fun, comp_unify, comp_unify] theorem relMap_unify_equiv {n : ℕ} (R : L.Relations n) (x : Fin n → Σˣ f) (i j : ι) (hi : i ∈ upperBounds (range (Sigma.fst ∘ x))) (hj : j ∈ upperBounds (range (Sigma.fst ∘ x))) : RelMap R (unify f x i hi) = RelMap R (unify f x j hj) := by obtain ⟨k, ik, jk⟩ := directed_of (· ≤ ·) i j rw [← (f i k ik).map_rel, comp_unify, ← (f j k jk).map_rel, comp_unify] variable [Nonempty ι] theorem exists_unify_eq {α : Type*} [Finite α] {x y : α → Σˣ f} (xy : x ≈ y) : ∃ (i : ι) (hx : i ∈ upperBounds (range (Sigma.fst ∘ x))) (hy : i ∈ upperBounds (range (Sigma.fst ∘ y))), unify f x i hx = unify f y i hy := by obtain ⟨i, hi⟩ := Finite.bddAbove_range (Sum.elim (fun a => (x a).1) fun a => (y a).1) rw [Sum.elim_range, upperBounds_union] at hi simp_rw [← Function.comp_apply (f := Sigma.fst)] at hi exact ⟨i, hi.1, hi.2, funext fun a => (equiv_iff G f _ _).1 (xy a)⟩ theorem funMap_equiv_unify {n : ℕ} (F : L.Functions n) (x : Fin n → Σˣ f) (i : ι) (hi : i ∈ upperBounds (range (Sigma.fst ∘ x))) : funMap F x ≈ .mk f _ (funMap F (unify f x i hi)) := funMap_unify_equiv G f F x (Classical.choose (Finite.bddAbove_range fun a => (x a).1)) i _ hi theorem relMap_equiv_unify {n : ℕ} (R : L.Relations n) (x : Fin n → Σˣ f) (i : ι) (hi : i ∈ upperBounds (range (Sigma.fst ∘ x))) : RelMap R x = RelMap R (unify f x i hi) :=
relMap_unify_equiv G f R x (Classical.choose (Finite.bddAbove_range fun a => (x a).1)) i _ hi /-- The direct limit `setoid` respects the structure `sigmaStructure`, so quotienting by it gives rise to a valid structure. -/ noncomputable instance prestructure : L.Prestructure (DirectLimit.setoid G f) where
Mathlib/ModelTheory/DirectLimit.lean
207
211
/- 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 : α} /-- Every set in a join-semilattice generates a set closed under join. -/ @[simps! isClosed] def infClosure : ClosureOperator (Set α) := ClosureOperator.ofPred (fun s ↦ {a | ∃ (t : Finset α) (ht : t.Nonempty), ↑t ⊆ s ∧ t.inf' ht id = a}) InfClosed (fun s a ha ↦ ⟨{a}, singleton_nonempty _, by simpa⟩)
(by
Mathlib/Order/SupClosed.lean
359
359
/- 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.Multiset.Basic /-! # Bind operation for multisets This file defines a few basic operations on `Multiset`, notably the monadic bind. ## Main declarations * `Multiset.join`: The join, aka union or sum, of multisets. * `Multiset.bind`: The bind of a multiset-indexed family of multisets. * `Multiset.product`: Cartesian product of two multisets. * `Multiset.sigma`: Disjoint sum of multisets in a sigma type. -/ assert_not_exists MonoidWithZero MulAction universe v variable {α : Type*} {β : Type v} {γ δ : Type*} namespace Multiset /-! ### Join -/ /-- `join S`, where `S` is a multiset of multisets, is the lift of the list join operation, that is, the union of all the sets. join {{1, 2}, {1, 2}, {0, 1}} = {0, 1, 1, 1, 2, 2} -/ def join : Multiset (Multiset α) → Multiset α := sum theorem coe_join : ∀ L : List (List α), join (L.map ((↑) : List α → Multiset α) : Multiset (Multiset α)) = L.flatten | [] => rfl | l :: L => by exact congr_arg (fun s : Multiset α => ↑l + s) (coe_join L) @[simp] theorem join_zero : @join α 0 = 0 := rfl @[simp] theorem join_cons (s S) : @join α (s ::ₘ S) = s + join S := sum_cons _ _ @[simp] theorem join_add (S T) : @join α (S + T) = join S + join T := sum_add _ _ @[simp] theorem singleton_join (a) : join ({a} : Multiset (Multiset α)) = a := sum_singleton _ @[simp] theorem mem_join {a S} : a ∈ @join α S ↔ ∃ s ∈ S, a ∈ s := Multiset.induction_on S (by simp) <| by simp +contextual [or_and_right, exists_or] @[simp] theorem card_join (S) : card (@join α S) = sum (map card S) := Multiset.induction_on S (by simp) (by simp) @[simp] theorem map_join (f : α → β) (S : Multiset (Multiset α)) : map f (join S) = join (map (map f) S) := by induction S using Multiset.induction with | empty => simp | cons _ _ ih => simp [ih] @[to_additive (attr := simp)] theorem prod_join [CommMonoid α] {S : Multiset (Multiset α)} : prod (join S) = prod (map prod S) := by induction S using Multiset.induction with | empty => simp | cons _ _ ih => simp [ih] theorem rel_join {r : α → β → Prop} {s t} (h : Rel (Rel r) s t) : Rel r s.join t.join := by induction h with | zero => simp | cons hab hst ih => simpa using hab.add ih /-! ### Bind -/ section Bind variable (a : α) (s t : Multiset α) (f g : α → Multiset β) /-- `s.bind f` is the monad bind operation, defined as `(s.map f).join`. It is the union of `f a` as `a` ranges over `s`. -/ def bind (s : Multiset α) (f : α → Multiset β) : Multiset β := (s.map f).join @[simp] theorem coe_bind (l : List α) (f : α → List β) : (@bind α β l fun a => f a) = l.flatMap f := by rw [List.flatMap, ← coe_join, List.map_map] rfl @[simp] theorem zero_bind : bind 0 f = 0 := rfl @[simp] theorem cons_bind : (a ::ₘ s).bind f = f a + s.bind f := by simp [bind] @[simp] theorem singleton_bind : bind {a} f = f a := by simp [bind] @[simp] theorem add_bind : (s + t).bind f = s.bind f + t.bind f := by simp [bind] @[simp] theorem bind_zero : s.bind (fun _ => 0 : α → Multiset β) = 0 := by simp [bind, join, nsmul_zero] @[simp] theorem bind_add : (s.bind fun a => f a + g a) = s.bind f + s.bind g := by simp [bind, join] @[simp] theorem bind_cons (f : α → β) (g : α → Multiset β) : (s.bind fun a => f a ::ₘ g a) = map f s + s.bind g := Multiset.induction_on s (by simp) (by simp +contextual [add_comm, add_left_comm, add_assoc]) @[simp] theorem bind_singleton (f : α → β) : (s.bind fun x => ({f x} : Multiset β)) = map f s := Multiset.induction_on s (by rw [zero_bind, map_zero]) (by simp [singleton_add]) @[simp] theorem mem_bind {b s} {f : α → Multiset β} : b ∈ bind s f ↔ ∃ a ∈ s, b ∈ f a := by simp [bind] @[simp] theorem card_bind : card (s.bind f) = (s.map (card ∘ f)).sum := by simp [bind] theorem bind_congr {f g : α → Multiset β} {m : Multiset α} : (∀ a ∈ m, f a = g a) → bind m f = bind m g := by simp +contextual [bind] theorem bind_hcongr {β' : Type v} {m : Multiset α} {f : α → Multiset β} {f' : α → Multiset β'} (h : β = β') (hf : ∀ a ∈ m, HEq (f a) (f' a)) : HEq (bind m f) (bind m f') := by subst h simp only [heq_eq_eq] at hf simp [bind_congr hf] theorem map_bind (m : Multiset α) (n : α → Multiset β) (f : β → γ) : map f (bind m n) = bind m fun a => map f (n a) := by simp [bind] theorem bind_map (m : Multiset α) (n : β → Multiset γ) (f : α → β) : bind (map f m) n = bind m fun a => n (f a) := Multiset.induction_on m (by simp) (by simp +contextual) theorem bind_assoc {s : Multiset α} {f : α → Multiset β} {g : β → Multiset γ} : (s.bind f).bind g = s.bind fun a => (f a).bind g := Multiset.induction_on s (by simp) (by simp +contextual) theorem bind_bind (m : Multiset α) (n : Multiset β) {f : α → β → Multiset γ} : ((bind m) fun a => (bind n) fun b => f a b) = (bind n) fun b => (bind m) fun a => f a b := Multiset.induction_on m (by simp) (by simp +contextual) theorem bind_map_comm (m : Multiset α) (n : Multiset β) {f : α → β → γ} : ((bind m) fun a => n.map fun b => f a b) = (bind n) fun b => m.map fun a => f a b := Multiset.induction_on m (by simp) (by simp +contextual) @[to_additive (attr := simp)] theorem prod_bind [CommMonoid β] (s : Multiset α) (t : α → Multiset β) : (s.bind t).prod = (s.map fun a => (t a).prod).prod := by simp [bind] open scoped Relator in theorem rel_bind {r : α → β → Prop} {p : γ → δ → Prop} {s t} {f : α → Multiset γ} {g : β → Multiset δ} (h : (r ⇒ Rel p) f g) (hst : Rel r s t) : Rel p (s.bind f) (t.bind g) := by apply rel_join rw [rel_map] exact hst.mono fun a _ b _ hr => h hr theorem count_sum [DecidableEq α] {m : Multiset β} {f : β → Multiset α} {a : α} : count a (map f m).sum = sum (m.map fun b => count a <| f b) := Multiset.induction_on m (by simp) (by simp) theorem count_bind [DecidableEq α] {m : Multiset β} {f : β → Multiset α} {a : α} : count a (bind m f) = sum (m.map fun b => count a <| f b) := count_sum theorem le_bind {α β : Type*} {f : α → Multiset β} (S : Multiset α) {x : α} (hx : x ∈ S) : f x ≤ S.bind f := by classical refine le_iff_count.2 fun a ↦ ?_ obtain ⟨m', hm'⟩ := exists_cons_of_mem <| mem_map_of_mem (fun b ↦ count a (f b)) hx rw [count_bind, hm', sum_cons] exact Nat.le_add_right _ _ @[simp] theorem attach_bind_coe (s : Multiset α) (f : α → Multiset β) : (s.attach.bind fun i => f i) = s.bind f := congr_arg join <| attach_map_val' _ _ variable {f s t} open scoped Function in -- required for scoped `on` notation @[simp] lemma nodup_bind : Nodup (bind s f) ↔ (∀ a ∈ s, Nodup (f a)) ∧ s.Pairwise (Disjoint on f) := by have : ∀ a, ∃ l : List β, f a = l := fun a => Quot.induction_on (f a) fun l => ⟨l, rfl⟩ choose f' h' using this have : f = fun a ↦ ofList (f' a) := funext h' have hd : Symmetric fun a b ↦ List.Disjoint (f' a) (f' b) := fun a b h ↦ h.symm exact Quot.induction_on s <| by unfold Function.onFun simp [this, List.nodup_flatMap, pairwise_coe_iff_pairwise hd] @[simp] lemma dedup_bind_dedup [DecidableEq α] [DecidableEq β] (s : Multiset α) (f : α → Multiset β) : (s.dedup.bind f).dedup = (s.bind f).dedup := by ext x -- Porting note: was `simp_rw [count_dedup, mem_bind, mem_dedup]` simp_rw [count_dedup] congr 1 simp variable (op : α → α → α) [hc : Std.Commutative op] [ha : Std.Associative op] theorem fold_bind {ι : Type*} (s : Multiset ι) (t : ι → Multiset α) (b : ι → α) (b₀ : α) : (s.bind t).fold op ((s.map b).fold op b₀) = (s.map fun i => (t i).fold op (b i)).fold op b₀ := by induction' s using Multiset.induction_on with a ha ih · rw [zero_bind, map_zero, map_zero, fold_zero] · rw [cons_bind, map_cons, map_cons, fold_cons_left, fold_cons_left, fold_add, ih] end Bind /-! ### Product of two multisets -/ section Product variable (a : α) (b : β) (s : Multiset α) (t : Multiset β) /-- The multiplicity of `(a, b)` in `s ×ˢ t` is the product of the multiplicity of `a` in `s` and `b` in `t`. -/ def product (s : Multiset α) (t : Multiset β) : Multiset (α × β) := s.bind fun a => t.map <| Prod.mk a instance instSProd : SProd (Multiset α) (Multiset β) (Multiset (α × β)) where sprod := Multiset.product @[simp] theorem coe_product (l₁ : List α) (l₂ : List β) : (l₁ : Multiset α) ×ˢ (l₂ : Multiset β) = (l₁ ×ˢ l₂) := by dsimp only [SProd.sprod] rw [product, List.product, ← coe_bind] simp @[simp] theorem zero_product : (0 : Multiset α) ×ˢ t = 0 := rfl @[simp] theorem cons_product : (a ::ₘ s) ×ˢ t = map (Prod.mk a) t + s ×ˢ t := by simp [SProd.sprod, product] @[simp] theorem product_zero : s ×ˢ (0 : Multiset β) = 0 := by simp [SProd.sprod, product] @[simp] theorem product_cons : s ×ˢ (b ::ₘ t) = (s.map fun a => (a, b)) + s ×ˢ t := by simp [SProd.sprod, product] @[simp] theorem product_singleton : ({a} : Multiset α) ×ˢ ({b} : Multiset β) = {(a, b)} := by simp only [SProd.sprod, product, bind_singleton, map_singleton] @[simp] theorem add_product (s t : Multiset α) (u : Multiset β) : (s + t) ×ˢ u = s ×ˢ u + t ×ˢ u := by simp [SProd.sprod, product] @[simp] theorem product_add (s : Multiset α) : ∀ t u : Multiset β, s ×ˢ (t + u) = s ×ˢ t + s ×ˢ u := Multiset.induction_on s (fun _ _ => rfl) fun a s IH t u => by rw [cons_product, IH] simp [add_comm, add_left_comm, add_assoc] @[simp] theorem card_product : card (s ×ˢ t) = card s * card t := by simp [SProd.sprod, product] variable {s t} @[simp] lemma mem_product : ∀ {p : α × β}, p ∈ @product α β s t ↔ p.1 ∈ s ∧ p.2 ∈ t | (a, b) => by simp [product, and_left_comm] protected theorem Nodup.product : Nodup s → Nodup t → Nodup (s ×ˢ t) := Quotient.inductionOn₂ s t fun l₁ l₂ d₁ d₂ => by simp [List.Nodup.product d₁ d₂] end Product /-! ### Disjoint sum of multisets -/ section Sigma variable {σ : α → Type*} (a : α) (s : Multiset α) (t : ∀ a, Multiset (σ a)) /-- `Multiset.sigma s t` is the dependent version of `Multiset.product`. It is the sum of `(a, b)` as `a` ranges over `s` and `b` ranges over `t a`. -/ protected def sigma (s : Multiset α) (t : ∀ a, Multiset (σ a)) : Multiset (Σa, σ a) := s.bind fun a => (t a).map <| Sigma.mk a @[simp] theorem coe_sigma (l₁ : List α) (l₂ : ∀ a, List (σ a)) :
(@Multiset.sigma α σ l₁ fun a => l₂ a) = l₁.sigma l₂ := by rw [Multiset.sigma, List.sigma, ← coe_bind]
Mathlib/Data/Multiset/Bind.lean
311
312
/- Copyright (c) 2017 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Keeley Hoek -/ import Mathlib.Algebra.NeZero import Mathlib.Data.Int.DivMod import Mathlib.Logic.Embedding.Basic import Mathlib.Logic.Equiv.Set import Mathlib.Tactic.Common import Mathlib.Tactic.Attr.Register /-! # The finite type with `n` elements `Fin n` is the type whose elements are natural numbers smaller than `n`. This file expands on the development in the core library. ## Main definitions ### Induction principles * `finZeroElim` : Elimination principle for the empty set `Fin 0`, generalizes `Fin.elim0`. Further definitions and eliminators can be found in `Init.Data.Fin.Lemmas` ### Embeddings and isomorphisms * `Fin.valEmbedding` : coercion to natural numbers as an `Embedding`; * `Fin.succEmb` : `Fin.succ` as an `Embedding`; * `Fin.castLEEmb h` : `Fin.castLE` as an `Embedding`, embed `Fin n` into `Fin m`, `h : n ≤ m`; * `finCongr` : `Fin.cast` as an `Equiv`, equivalence between `Fin n` and `Fin m` when `n = m`; * `Fin.castAddEmb m` : `Fin.castAdd` as an `Embedding`, embed `Fin n` into `Fin (n+m)`; * `Fin.castSuccEmb` : `Fin.castSucc` as an `Embedding`, embed `Fin n` into `Fin (n+1)`; * `Fin.addNatEmb m i` : `Fin.addNat` as an `Embedding`, add `m` on `i` on the right, generalizes `Fin.succ`; * `Fin.natAddEmb n i` : `Fin.natAdd` as an `Embedding`, adds `n` on `i` on the left; ### Other casts * `Fin.divNat i` : divides `i : Fin (m * n)` by `n`; * `Fin.modNat i` : takes the mod of `i : Fin (m * n)` by `n`; -/ assert_not_exists Monoid Finset open Fin Nat Function attribute [simp] Fin.succ_ne_zero Fin.castSucc_lt_last /-- Elimination principle for the empty set `Fin 0`, dependent version. -/ def finZeroElim {α : Fin 0 → Sort*} (x : Fin 0) : α x := x.elim0 namespace Fin @[simp] theorem mk_eq_one {n a : Nat} {ha : a < n + 2} : (⟨a, ha⟩ : Fin (n + 2)) = 1 ↔ a = 1 := mk.inj_iff @[simp] theorem one_eq_mk {n a : Nat} {ha : a < n + 2} : 1 = (⟨a, ha⟩ : Fin (n + 2)) ↔ a = 1 := by simp [eq_comm] instance {n : ℕ} : CanLift ℕ (Fin n) Fin.val (· < n) where prf k hk := ⟨⟨k, hk⟩, rfl⟩ /-- A dependent variant of `Fin.elim0`. -/ def rec0 {α : Fin 0 → Sort*} (i : Fin 0) : α i := absurd i.2 (Nat.not_lt_zero _) variable {n m : ℕ} --variable {a b : Fin n} -- this *really* breaks stuff theorem val_injective : Function.Injective (@Fin.val n) := @Fin.eq_of_val_eq n /-- If you actually have an element of `Fin n`, then the `n` is always positive -/ lemma size_positive : Fin n → 0 < n := Fin.pos lemma size_positive' [Nonempty (Fin n)] : 0 < n := ‹Nonempty (Fin n)›.elim Fin.pos protected theorem prop (a : Fin n) : a.val < n := a.2 lemma lt_last_iff_ne_last {a : Fin (n + 1)} : a < last n ↔ a ≠ last n := by simp [Fin.lt_iff_le_and_ne, le_last] lemma ne_zero_of_lt {a b : Fin (n + 1)} (hab : a < b) : b ≠ 0 := Fin.ne_of_gt <| Fin.lt_of_le_of_lt a.zero_le hab lemma ne_last_of_lt {a b : Fin (n + 1)} (hab : a < b) : a ≠ last n := Fin.ne_of_lt <| Fin.lt_of_lt_of_le hab b.le_last /-- Equivalence between `Fin n` and `{ i // i < n }`. -/ @[simps apply symm_apply] def equivSubtype : Fin n ≃ { i // i < n } where toFun a := ⟨a.1, a.2⟩ invFun a := ⟨a.1, a.2⟩ left_inv := fun ⟨_, _⟩ => rfl right_inv := fun ⟨_, _⟩ => rfl section coe /-! ### coercions and constructions -/ theorem val_eq_val (a b : Fin n) : (a : ℕ) = b ↔ a = b := Fin.ext_iff.symm theorem ne_iff_vne (a b : Fin n) : a ≠ b ↔ a.1 ≠ b.1 := Fin.ext_iff.not theorem mk_eq_mk {a h a' h'} : @mk n a h = @mk n a' h' ↔ a = a' := Fin.ext_iff -- syntactic tautologies now /-- Assume `k = l`. If two functions defined on `Fin k` and `Fin l` are equal on each element, then they coincide (in the heq sense). -/ protected theorem heq_fun_iff {α : Sort*} {k l : ℕ} (h : k = l) {f : Fin k → α} {g : Fin l → α} : HEq f g ↔ ∀ i : Fin k, f i = g ⟨(i : ℕ), h ▸ i.2⟩ := by subst h simp [funext_iff] /-- Assume `k = l` and `k' = l'`. If two functions `Fin k → Fin k' → α` and `Fin l → Fin l' → α` are equal on each pair, then they coincide (in the heq sense). -/ protected theorem heq_fun₂_iff {α : Sort*} {k l k' l' : ℕ} (h : k = l) (h' : k' = l') {f : Fin k → Fin k' → α} {g : Fin l → Fin l' → α} : HEq f g ↔ ∀ (i : Fin k) (j : Fin k'), f i j = g ⟨(i : ℕ), h ▸ i.2⟩ ⟨(j : ℕ), h' ▸ j.2⟩ := by subst h subst h' simp [funext_iff] /-- Two elements of `Fin k` and `Fin l` are heq iff their values in `ℕ` coincide. This requires `k = l`. For the left implication without this assumption, see `val_eq_val_of_heq`. -/ protected theorem heq_ext_iff {k l : ℕ} (h : k = l) {i : Fin k} {j : Fin l} : HEq i j ↔ (i : ℕ) = (j : ℕ) := by subst h simp [val_eq_val] end coe section Order /-! ### order -/ theorem le_iff_val_le_val {a b : Fin n} : a ≤ b ↔ (a : ℕ) ≤ b := Iff.rfl /-- `a < b` as natural numbers if and only if `a < b` in `Fin n`. -/ @[norm_cast, simp] theorem val_fin_lt {n : ℕ} {a b : Fin n} : (a : ℕ) < (b : ℕ) ↔ a < b := Iff.rfl /-- `a ≤ b` as natural numbers if and only if `a ≤ b` in `Fin n`. -/ @[norm_cast, simp] theorem val_fin_le {n : ℕ} {a b : Fin n} : (a : ℕ) ≤ (b : ℕ) ↔ a ≤ b := Iff.rfl theorem min_val {a : Fin n} : min (a : ℕ) n = a := by simp theorem max_val {a : Fin n} : max (a : ℕ) n = n := by simp /-- The inclusion map `Fin n → ℕ` is an embedding. -/ @[simps -fullyApplied apply] def valEmbedding : Fin n ↪ ℕ := ⟨val, val_injective⟩ @[simp] theorem equivSubtype_symm_trans_valEmbedding : equivSubtype.symm.toEmbedding.trans valEmbedding = Embedding.subtype (· < n) := rfl /-- Use the ordering on `Fin n` for checking recursive definitions. For example, the following definition is not accepted by the termination checker, unless we declare the `WellFoundedRelation` instance: ```lean def factorial {n : ℕ} : Fin n → ℕ | ⟨0, _⟩ := 1 | ⟨i + 1, hi⟩ := (i + 1) * factorial ⟨i, i.lt_succ_self.trans hi⟩ ``` -/ instance {n : ℕ} : WellFoundedRelation (Fin n) := measure (val : Fin n → ℕ) @[deprecated (since := "2025-02-24")] alias val_zero' := val_zero /-- `Fin.mk_zero` in `Lean` only applies in `Fin (n + 1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] theorem mk_zero' (n : ℕ) [NeZero n] : (⟨0, pos_of_neZero n⟩ : Fin n) = 0 := rfl /-- The `Fin.zero_le` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] protected theorem zero_le' [NeZero n] (a : Fin n) : 0 ≤ a := Nat.zero_le a.val @[simp, norm_cast] theorem val_eq_zero_iff [NeZero n] {a : Fin n} : a.val = 0 ↔ a = 0 := by rw [Fin.ext_iff, val_zero] theorem val_ne_zero_iff [NeZero n] {a : Fin n} : a.val ≠ 0 ↔ a ≠ 0 := val_eq_zero_iff.not @[simp, norm_cast] theorem val_pos_iff [NeZero n] {a : Fin n} : 0 < a.val ↔ 0 < a := by rw [← val_fin_lt, val_zero] /-- The `Fin.pos_iff_ne_zero` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ theorem pos_iff_ne_zero' [NeZero n] (a : Fin n) : 0 < a ↔ a ≠ 0 := by rw [← val_pos_iff, Nat.pos_iff_ne_zero, val_ne_zero_iff] @[simp] lemma cast_eq_self (a : Fin n) : a.cast rfl = a := rfl @[simp] theorem cast_eq_zero {k l : ℕ} [NeZero k] [NeZero l] (h : k = l) (x : Fin k) : Fin.cast h x = 0 ↔ x = 0 := by simp [← val_eq_zero_iff] lemma cast_injective {k l : ℕ} (h : k = l) : Injective (Fin.cast h) := fun a b hab ↦ by simpa [← val_eq_val] using hab theorem last_pos' [NeZero n] : 0 < last n := n.pos_of_neZero theorem one_lt_last [NeZero n] : 1 < last (n + 1) := by rw [lt_iff_val_lt_val, val_one, val_last, Nat.lt_add_left_iff_pos, Nat.pos_iff_ne_zero] exact NeZero.ne n end Order /-! ### Coercions to `ℤ` and the `fin_omega` tactic. -/ open Int theorem coe_int_sub_eq_ite {n : Nat} (u v : Fin n) : ((u - v : Fin n) : Int) = if v ≤ u then (u - v : Int) else (u - v : Int) + n := by rw [Fin.sub_def] split · rw [natCast_emod, Int.emod_eq_sub_self_emod, Int.emod_eq_of_lt] <;> omega · rw [natCast_emod, Int.emod_eq_of_lt] <;> omega theorem coe_int_sub_eq_mod {n : Nat} (u v : Fin n) : ((u - v : Fin n) : Int) = ((u : Int) - (v : Int)) % n := by rw [coe_int_sub_eq_ite] split · rw [Int.emod_eq_of_lt] <;> omega · rw [Int.emod_eq_add_self_emod, Int.emod_eq_of_lt] <;> omega theorem coe_int_add_eq_ite {n : Nat} (u v : Fin n) : ((u + v : Fin n) : Int) = if (u + v : ℕ) < n then (u + v : Int) else (u + v : Int) - n := by rw [Fin.add_def] split · rw [natCast_emod, Int.emod_eq_of_lt] <;> omega · rw [natCast_emod, Int.emod_eq_sub_self_emod, Int.emod_eq_of_lt] <;> omega theorem coe_int_add_eq_mod {n : Nat} (u v : Fin n) : ((u + v : Fin n) : Int) = ((u : Int) + (v : Int)) % n := by rw [coe_int_add_eq_ite] split · rw [Int.emod_eq_of_lt] <;> omega · rw [Int.emod_eq_sub_self_emod, Int.emod_eq_of_lt] <;> omega -- Write `a + b` as `if (a + b : ℕ) < n then (a + b : ℤ) else (a + b : ℤ) - n` and -- similarly `a - b` as `if (b : ℕ) ≤ a then (a - b : ℤ) else (a - b : ℤ) + n`. attribute [fin_omega] coe_int_sub_eq_ite coe_int_add_eq_ite -- Rewrite inequalities in `Fin` to inequalities in `ℕ` attribute [fin_omega] Fin.lt_iff_val_lt_val Fin.le_iff_val_le_val -- Rewrite `1 : Fin (n + 2)` to `1 : ℤ` attribute [fin_omega] val_one /-- Preprocessor for `omega` to handle inequalities in `Fin`. Note that this involves a lot of case splitting, so may be slow. -/ -- Further adjustment to the simp set can probably make this more powerful. -- Please experiment and PR updates! macro "fin_omega" : tactic => `(tactic| { try simp only [fin_omega, ← Int.ofNat_lt, ← Int.ofNat_le] at * omega }) section Add /-! ### addition, numerals, and coercion from Nat -/ @[simp] theorem val_one' (n : ℕ) [NeZero n] : ((1 : Fin n) : ℕ) = 1 % n := rfl @[deprecated val_one' (since := "2025-03-10")] theorem val_one'' {n : ℕ} : ((1 : Fin (n + 1)) : ℕ) = 1 % (n + 1) := rfl instance nontrivial {n : ℕ} : Nontrivial (Fin (n + 2)) where exists_pair_ne := ⟨0, 1, (ne_iff_vne 0 1).mpr (by simp [val_one, val_zero])⟩ theorem nontrivial_iff_two_le : Nontrivial (Fin n) ↔ 2 ≤ n := by rcases n with (_ | _ | n) <;> simp [Fin.nontrivial, not_nontrivial, Nat.succ_le_iff] section Monoid instance inhabitedFinOneAdd (n : ℕ) : Inhabited (Fin (1 + n)) := haveI : NeZero (1 + n) := by rw [Nat.add_comm]; infer_instance inferInstance @[simp] theorem default_eq_zero (n : ℕ) [NeZero n] : (default : Fin n) = 0 := rfl instance instNatCast [NeZero n] : NatCast (Fin n) where natCast i := Fin.ofNat' n i lemma natCast_def [NeZero n] (a : ℕ) : (a : Fin n) = ⟨a % n, mod_lt _ n.pos_of_neZero⟩ := rfl end Monoid theorem val_add_eq_ite {n : ℕ} (a b : Fin n) : (↑(a + b) : ℕ) = if n ≤ a + b then a + b - n else a + b := by rw [Fin.val_add, Nat.add_mod_eq_ite, Nat.mod_eq_of_lt (show ↑a < n from a.2), Nat.mod_eq_of_lt (show ↑b < n from b.2)] theorem val_add_eq_of_add_lt {n : ℕ} {a b : Fin n} (huv : a.val + b.val < n) : (a + b).val = a.val + b.val := by rw [val_add] simp [Nat.mod_eq_of_lt huv] lemma intCast_val_sub_eq_sub_add_ite {n : ℕ} (a b : Fin n) : ((a - b).val : ℤ) = a.val - b.val + if b ≤ a then 0 else n := by split <;> fin_omega lemma one_le_of_ne_zero {n : ℕ} [NeZero n] {k : Fin n} (hk : k ≠ 0) : 1 ≤ k := by obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (NeZero.ne n) cases n with | zero => simp only [Nat.reduceAdd, Fin.isValue, Fin.zero_le] | succ n => rwa [Fin.le_iff_val_le_val, Fin.val_one, Nat.one_le_iff_ne_zero, val_ne_zero_iff] lemma val_sub_one_of_ne_zero [NeZero n] {i : Fin n} (hi : i ≠ 0) : (i - 1).val = i - 1 := by obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (NeZero.ne n) rw [Fin.sub_val_of_le (one_le_of_ne_zero hi), Fin.val_one', Nat.mod_eq_of_lt (Nat.succ_le_iff.mpr (nontrivial_iff_two_le.mp <| nontrivial_of_ne i 0 hi))] section OfNatCoe @[simp] theorem ofNat'_eq_cast (n : ℕ) [NeZero n] (a : ℕ) : Fin.ofNat' n a = a := rfl @[simp] lemma val_natCast (a n : ℕ) [NeZero n] : (a : Fin n).val = a % n := rfl /-- Converting an in-range number to `Fin (n + 1)` produces a result whose value is the original number. -/ theorem val_cast_of_lt {n : ℕ} [NeZero n] {a : ℕ} (h : a < n) : (a : Fin n).val = a := Nat.mod_eq_of_lt h /-- If `n` is non-zero, converting the value of a `Fin n` to `Fin n` results in the same value. -/ @[simp, norm_cast] theorem cast_val_eq_self {n : ℕ} [NeZero n] (a : Fin n) : (a.val : Fin n) = a := Fin.ext <| val_cast_of_lt a.isLt -- This is a special case of `CharP.cast_eq_zero` that doesn't require typeclass search @[simp high] lemma natCast_self (n : ℕ) [NeZero n] : (n : Fin n) = 0 := by ext; simp @[simp] lemma natCast_eq_zero {a n : ℕ} [NeZero n] : (a : Fin n) = 0 ↔ n ∣ a := by simp [Fin.ext_iff, Nat.dvd_iff_mod_eq_zero] @[simp] theorem natCast_eq_last (n) : (n : Fin (n + 1)) = Fin.last n := by ext; simp theorem le_val_last (i : Fin (n + 1)) : i ≤ n := by rw [Fin.natCast_eq_last] exact Fin.le_last i variable {a b : ℕ} lemma natCast_le_natCast (han : a ≤ n) (hbn : b ≤ n) : (a : Fin (n + 1)) ≤ b ↔ a ≤ b := by rw [← Nat.lt_succ_iff] at han hbn simp [le_iff_val_le_val, -val_fin_le, Nat.mod_eq_of_lt, han, hbn] lemma natCast_lt_natCast (han : a ≤ n) (hbn : b ≤ n) : (a : Fin (n + 1)) < b ↔ a < b := by rw [← Nat.lt_succ_iff] at han hbn; simp [lt_iff_val_lt_val, Nat.mod_eq_of_lt, han, hbn] lemma natCast_mono (hbn : b ≤ n) (hab : a ≤ b) : (a : Fin (n + 1)) ≤ b := (natCast_le_natCast (hab.trans hbn) hbn).2 hab lemma natCast_strictMono (hbn : b ≤ n) (hab : a < b) : (a : Fin (n + 1)) < b := (natCast_lt_natCast (hab.le.trans hbn) hbn).2 hab end OfNatCoe end Add section Succ /-! ### succ and casts into larger Fin types -/ lemma succ_injective (n : ℕ) : Injective (@Fin.succ n) := fun a b ↦ by simp [Fin.ext_iff] /-- `Fin.succ` as an `Embedding` -/ def succEmb (n : ℕ) : Fin n ↪ Fin (n + 1) where toFun := succ inj' := succ_injective _ @[simp] theorem coe_succEmb : ⇑(succEmb n) = Fin.succ := rfl @[deprecated (since := "2025-04-12")] alias val_succEmb := coe_succEmb @[simp] theorem exists_succ_eq {x : Fin (n + 1)} : (∃ y, Fin.succ y = x) ↔ x ≠ 0 := ⟨fun ⟨_, hy⟩ => hy ▸ succ_ne_zero _, x.cases (fun h => h.irrefl.elim) (fun _ _ => ⟨_, rfl⟩)⟩ theorem exists_succ_eq_of_ne_zero {x : Fin (n + 1)} (h : x ≠ 0) : ∃ y, Fin.succ y = x := exists_succ_eq.mpr h @[simp] theorem succ_zero_eq_one' [NeZero n] : Fin.succ (0 : Fin n) = 1 := by cases n · exact (NeZero.ne 0 rfl).elim · rfl theorem one_pos' [NeZero n] : (0 : Fin (n + 1)) < 1 := succ_zero_eq_one' (n := n) ▸ succ_pos _ theorem zero_ne_one' [NeZero n] : (0 : Fin (n + 1)) ≠ 1 := Fin.ne_of_lt one_pos' /-- The `Fin.succ_one_eq_two` in `Lean` only applies in `Fin (n+2)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] theorem succ_one_eq_two' [NeZero n] : Fin.succ (1 : Fin (n + 1)) = 2 := by cases n · exact (NeZero.ne 0 rfl).elim · rfl -- Version of `succ_one_eq_two` to be used by `dsimp`. -- Note the `'` swapped around due to a move to std4. /-- The `Fin.le_zero_iff` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] theorem le_zero_iff' {n : ℕ} [NeZero n] {k : Fin n} : k ≤ 0 ↔ k = 0 := ⟨fun h => Fin.ext <| by rw [Nat.eq_zero_of_le_zero h]; rfl, by rintro rfl; exact Nat.le_refl _⟩ -- TODO: Move to Batteries @[simp] lemma castLE_inj {hmn : m ≤ n} {a b : Fin m} : castLE hmn a = castLE hmn b ↔ a = b := by simp [Fin.ext_iff] @[simp] lemma castAdd_inj {a b : Fin m} : castAdd n a = castAdd n b ↔ a = b := by simp [Fin.ext_iff] attribute [simp] castSucc_inj lemma castLE_injective (hmn : m ≤ n) : Injective (castLE hmn) := fun _ _ hab ↦ Fin.ext (congr_arg val hab :) lemma castAdd_injective (m n : ℕ) : Injective (@Fin.castAdd m n) := castLE_injective _ lemma castSucc_injective (n : ℕ) : Injective (@Fin.castSucc n) := castAdd_injective _ _ /-- `Fin.castLE` as an `Embedding`, `castLEEmb h i` embeds `i` into a larger `Fin` type. -/ @[simps apply] def castLEEmb (h : n ≤ m) : Fin n ↪ Fin m where toFun := castLE h inj' := castLE_injective _ @[simp, norm_cast] lemma coe_castLEEmb {m n} (hmn : m ≤ n) : castLEEmb hmn = castLE hmn := rfl /- The next proof can be golfed a lot using `Fintype.card`. It is written this way to define `ENat.card` and `Nat.card` without a `Fintype` dependency (not done yet). -/ lemma nonempty_embedding_iff : Nonempty (Fin n ↪ Fin m) ↔ n ≤ m := by refine ⟨fun h ↦ ?_, fun h ↦ ⟨castLEEmb h⟩⟩ induction n generalizing m with | zero => exact m.zero_le | succ n ihn => obtain ⟨e⟩ := h rcases exists_eq_succ_of_ne_zero (pos_iff_nonempty.2 (Nonempty.map e inferInstance)).ne' with ⟨m, rfl⟩ refine Nat.succ_le_succ <| ihn ⟨?_⟩ refine ⟨fun i ↦ (e.setValue 0 0 i.succ).pred (mt e.setValue_eq_iff.1 i.succ_ne_zero), fun i j h ↦ ?_⟩ simpa only [pred_inj, EmbeddingLike.apply_eq_iff_eq, succ_inj] using h lemma equiv_iff_eq : Nonempty (Fin m ≃ Fin n) ↔ m = n := ⟨fun ⟨e⟩ ↦ le_antisymm (nonempty_embedding_iff.1 ⟨e⟩) (nonempty_embedding_iff.1 ⟨e.symm⟩), fun h ↦ h ▸ ⟨.refl _⟩⟩ @[simp] lemma castLE_castSucc {n m} (i : Fin n) (h : n + 1 ≤ m) : i.castSucc.castLE h = i.castLE (Nat.le_of_succ_le h) := rfl @[simp] lemma castLE_comp_castSucc {n m} (h : n + 1 ≤ m) : Fin.castLE h ∘ Fin.castSucc = Fin.castLE (Nat.le_of_succ_le h) := rfl @[simp] lemma castLE_rfl (n : ℕ) : Fin.castLE (le_refl n) = id := rfl @[simp] theorem range_castLE {n k : ℕ} (h : n ≤ k) : Set.range (castLE h) = { i : Fin k | (i : ℕ) < n } := Set.ext fun x => ⟨fun ⟨y, hy⟩ => hy ▸ y.2, fun hx => ⟨⟨x, hx⟩, rfl⟩⟩ @[simp] theorem coe_of_injective_castLE_symm {n k : ℕ} (h : n ≤ k) (i : Fin k) (hi) : ((Equiv.ofInjective _ (castLE_injective h)).symm ⟨i, hi⟩ : ℕ) = i := by rw [← coe_castLE h] exact congr_arg Fin.val (Equiv.apply_ofInjective_symm _ _) theorem leftInverse_cast (eq : n = m) : LeftInverse (Fin.cast eq.symm) (Fin.cast eq) := fun _ => rfl theorem rightInverse_cast (eq : n = m) : RightInverse (Fin.cast eq.symm) (Fin.cast eq) := fun _ => rfl @[simp] theorem cast_inj (eq : n = m) {a b : Fin n} : a.cast eq = b.cast eq ↔ a = b := by simp [← val_inj] @[simp] theorem cast_lt_cast (eq : n = m) {a b : Fin n} : a.cast eq < b.cast eq ↔ a < b := Iff.rfl @[simp] theorem cast_le_cast (eq : n = m) {a b : Fin n} : a.cast eq ≤ b.cast eq ↔ a ≤ b := Iff.rfl /-- The 'identity' equivalence between `Fin m` and `Fin n` when `m = n`. -/ @[simps] def _root_.finCongr (eq : n = m) : Fin n ≃ Fin m where toFun := Fin.cast eq invFun := Fin.cast eq.symm left_inv := leftInverse_cast eq right_inv := rightInverse_cast eq @[simp] lemma _root_.finCongr_apply_mk (h : m = n) (k : ℕ) (hk : k < m) : finCongr h ⟨k, hk⟩ = ⟨k, h ▸ hk⟩ := rfl @[simp] lemma _root_.finCongr_refl (h : n = n := rfl) : finCongr h = Equiv.refl (Fin n) := by ext; simp @[simp] lemma _root_.finCongr_symm (h : m = n) : (finCongr h).symm = finCongr h.symm := rfl @[simp] lemma _root_.finCongr_apply_coe (h : m = n) (k : Fin m) : (finCongr h k : ℕ) = k := rfl lemma _root_.finCongr_symm_apply_coe (h : m = n) (k : Fin n) : ((finCongr h).symm k : ℕ) = k := rfl /-- While in many cases `finCongr` is better than `Equiv.cast`/`cast`, sometimes we want to apply a generic theorem about `cast`. -/ lemma _root_.finCongr_eq_equivCast (h : n = m) : finCongr h = .cast (h ▸ rfl) := by subst h; simp /-- While in many cases `Fin.cast` is better than `Equiv.cast`/`cast`, sometimes we want to apply a generic theorem about `cast`. -/ theorem cast_eq_cast (h : n = m) : (Fin.cast h : Fin n → Fin m) = _root_.cast (h ▸ rfl) := by subst h ext rfl /-- `Fin.castAdd` as an `Embedding`, `castAddEmb m i` embeds `i : Fin n` in `Fin (n+m)`. See also `Fin.natAddEmb` and `Fin.addNatEmb`. -/ def castAddEmb (m) : Fin n ↪ Fin (n + m) := castLEEmb (le_add_right n m) @[simp] lemma coe_castAddEmb (m) : (castAddEmb m : Fin n → Fin (n + m)) = castAdd m := rfl lemma castAddEmb_apply (m) (i : Fin n) : castAddEmb m i = castAdd m i := rfl /-- `Fin.castSucc` as an `Embedding`, `castSuccEmb i` embeds `i : Fin n` in `Fin (n+1)`. -/ def castSuccEmb : Fin n ↪ Fin (n + 1) := castAddEmb _ @[simp, norm_cast] lemma coe_castSuccEmb : (castSuccEmb : Fin n → Fin (n + 1)) = Fin.castSucc := rfl lemma castSuccEmb_apply (i : Fin n) : castSuccEmb i = i.castSucc := rfl theorem castSucc_le_succ {n} (i : Fin n) : i.castSucc ≤ i.succ := Nat.le_succ i @[simp] theorem castSucc_le_castSucc_iff {a b : Fin n} : castSucc a ≤ castSucc b ↔ a ≤ b := .rfl @[simp] theorem succ_le_castSucc_iff {a b : Fin n} : succ a ≤ castSucc b ↔ a < b := by rw [le_castSucc_iff, succ_lt_succ_iff] @[simp] theorem castSucc_lt_succ_iff {a b : Fin n} : castSucc a < succ b ↔ a ≤ b := by rw [castSucc_lt_iff_succ_le, succ_le_succ_iff] theorem le_of_castSucc_lt_of_succ_lt {a b : Fin (n + 1)} {i : Fin n} (hl : castSucc i < a) (hu : b < succ i) : b < a := by simp [Fin.lt_def, -val_fin_lt] at *; omega theorem castSucc_lt_or_lt_succ (p : Fin (n + 1)) (i : Fin n) : castSucc i < p ∨ p < i.succ := by simp [Fin.lt_def, -val_fin_lt]; omega theorem succ_le_or_le_castSucc (p : Fin (n + 1)) (i : Fin n) : succ i ≤ p ∨ p ≤ i.castSucc := by rw [le_castSucc_iff, ← castSucc_lt_iff_succ_le] exact p.castSucc_lt_or_lt_succ i theorem eq_castSucc_of_ne_last {x : Fin (n + 1)} (h : x ≠ (last _)) : ∃ y, Fin.castSucc y = x := exists_castSucc_eq.mpr h @[deprecated (since := "2025-02-06")] alias exists_castSucc_eq_of_ne_last := eq_castSucc_of_ne_last theorem forall_fin_succ' {P : Fin (n + 1) → Prop} : (∀ i, P i) ↔ (∀ i : Fin n, P i.castSucc) ∧ P (.last _) := ⟨fun H => ⟨fun _ => H _, H _⟩, fun ⟨H0, H1⟩ i => Fin.lastCases H1 H0 i⟩ -- to match `Fin.eq_zero_or_eq_succ` theorem eq_castSucc_or_eq_last {n : Nat} (i : Fin (n + 1)) : (∃ j : Fin n, i = j.castSucc) ∨ i = last n := i.lastCases (Or.inr rfl) (Or.inl ⟨·, rfl⟩) @[simp] theorem castSucc_ne_last {n : ℕ} (i : Fin n) : i.castSucc ≠ .last n := Fin.ne_of_lt i.castSucc_lt_last theorem exists_fin_succ' {P : Fin (n + 1) → Prop} : (∃ i, P i) ↔ (∃ i : Fin n, P i.castSucc) ∨ P (.last _) := ⟨fun ⟨i, h⟩ => Fin.lastCases Or.inr (fun i hi => Or.inl ⟨i, hi⟩) i h, fun h => h.elim (fun ⟨i, hi⟩ => ⟨i.castSucc, hi⟩) (fun h => ⟨.last _, h⟩)⟩ /-- The `Fin.castSucc_zero` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp]
theorem castSucc_zero' [NeZero n] : castSucc (0 : Fin n) = 0 := rfl
Mathlib/Data/Fin/Basic.lean
646
646
/- Copyright (c) 2021 Frédéric Dupuis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Frédéric Dupuis, Heather Macbeth -/ import Mathlib.Analysis.InnerProductSpace.Dual import Mathlib.Analysis.InnerProductSpace.PiL2 /-! # Adjoint of operators on Hilbert spaces Given an operator `A : E →L[𝕜] F`, where `E` and `F` are Hilbert spaces, its adjoint `adjoint A : F →L[𝕜] E` is the unique operator such that `⟪x, A y⟫ = ⟪adjoint A x, y⟫` for all `x` and `y`. We then use this to put a C⋆-algebra structure on `E →L[𝕜] E` with the adjoint as the star operation. This construction is used to define an adjoint for linear maps (i.e. not continuous) between finite dimensional spaces. ## Main definitions * `ContinuousLinearMap.adjoint : (E →L[𝕜] F) ≃ₗᵢ⋆[𝕜] (F →L[𝕜] E)`: the adjoint of a continuous linear map, bundled as a conjugate-linear isometric equivalence. * `LinearMap.adjoint : (E →ₗ[𝕜] F) ≃ₗ⋆[𝕜] (F →ₗ[𝕜] E)`: the adjoint of a linear map between finite-dimensional spaces, this time only as a conjugate-linear equivalence, since there is no norm defined on these maps. ## Implementation notes * The continuous conjugate-linear version `adjointAux` is only an intermediate definition and is not meant to be used outside this file. ## Tags adjoint -/ noncomputable section open RCLike open scoped ComplexConjugate variable {𝕜 E F G : Type*} [RCLike 𝕜] variable [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedAddCommGroup G] variable [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 F] [InnerProductSpace 𝕜 G] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y /-! ### Adjoint operator -/ open InnerProductSpace namespace ContinuousLinearMap variable [CompleteSpace E] [CompleteSpace G] -- Note: made noncomputable to stop excess compilation -- https://github.com/leanprover-community/mathlib4/issues/7103 /-- The adjoint, as a continuous conjugate-linear map. This is only meant as an auxiliary definition for the main definition `adjoint`, where this is bundled as a conjugate-linear isometric equivalence. -/ noncomputable def adjointAux : (E →L[𝕜] F) →L⋆[𝕜] F →L[𝕜] E := (ContinuousLinearMap.compSL _ _ _ _ _ ((toDual 𝕜 E).symm : NormedSpace.Dual 𝕜 E →L⋆[𝕜] E)).comp (toSesqForm : (E →L[𝕜] F) →L[𝕜] F →L⋆[𝕜] NormedSpace.Dual 𝕜 E) @[simp] theorem adjointAux_apply (A : E →L[𝕜] F) (x : F) : adjointAux A x = ((toDual 𝕜 E).symm : NormedSpace.Dual 𝕜 E → E) ((toSesqForm A) x) := rfl theorem adjointAux_inner_left (A : E →L[𝕜] F) (x : E) (y : F) : ⟪adjointAux A y, x⟫ = ⟪y, A x⟫ := by rw [adjointAux_apply, toDual_symm_apply, toSesqForm_apply_coe, coe_comp', innerSL_apply_coe, Function.comp_apply] theorem adjointAux_inner_right (A : E →L[𝕜] F) (x : E) (y : F) : ⟪x, adjointAux A y⟫ = ⟪A x, y⟫ := by rw [← inner_conj_symm, adjointAux_inner_left, inner_conj_symm] variable [CompleteSpace F] theorem adjointAux_adjointAux (A : E →L[𝕜] F) : adjointAux (adjointAux A) = A := by ext v refine ext_inner_left 𝕜 fun w => ?_ rw [adjointAux_inner_right, adjointAux_inner_left] @[simp] theorem adjointAux_norm (A : E →L[𝕜] F) : ‖adjointAux A‖ = ‖A‖ := by refine le_antisymm ?_ ?_ · refine ContinuousLinearMap.opNorm_le_bound _ (norm_nonneg _) fun x => ?_ rw [adjointAux_apply, LinearIsometryEquiv.norm_map] exact toSesqForm_apply_norm_le · nth_rw 1 [← adjointAux_adjointAux A] refine ContinuousLinearMap.opNorm_le_bound _ (norm_nonneg _) fun x => ?_ rw [adjointAux_apply, LinearIsometryEquiv.norm_map] exact toSesqForm_apply_norm_le /-- The adjoint of a bounded operator `A` from a Hilbert space `E` to another Hilbert space `F`, denoted as `A†`. -/ def adjoint : (E →L[𝕜] F) ≃ₗᵢ⋆[𝕜] F →L[𝕜] E := LinearIsometryEquiv.ofSurjective { adjointAux with norm_map' := adjointAux_norm } fun A => ⟨adjointAux A, adjointAux_adjointAux A⟩ @[inherit_doc] scoped[InnerProduct] postfix:1000 "†" => ContinuousLinearMap.adjoint open InnerProduct /-- The fundamental property of the adjoint. -/ theorem adjoint_inner_left (A : E →L[𝕜] F) (x : E) (y : F) : ⟪(A†) y, x⟫ = ⟪y, A x⟫ := adjointAux_inner_left A x y /-- The fundamental property of the adjoint. -/ theorem adjoint_inner_right (A : E →L[𝕜] F) (x : E) (y : F) : ⟪x, (A†) y⟫ = ⟪A x, y⟫ := adjointAux_inner_right A x y /-- The adjoint is involutive. -/ @[simp] theorem adjoint_adjoint (A : E →L[𝕜] F) : A†† = A := adjointAux_adjointAux A /-- The adjoint of the composition of two operators is the composition of the two adjoints in reverse order. -/ @[simp] theorem adjoint_comp (A : F →L[𝕜] G) (B : E →L[𝕜] F) : (A ∘L B)† = B† ∘L A† := by ext v refine ext_inner_left 𝕜 fun w => ?_ simp only [adjoint_inner_right, ContinuousLinearMap.coe_comp', Function.comp_apply] theorem apply_norm_sq_eq_inner_adjoint_left (A : E →L[𝕜] F) (x : E) : ‖A x‖ ^ 2 = re ⟪(A† ∘L A) x, x⟫ := by have h : ⟪(A† ∘L A) x, x⟫ = ⟪A x, A x⟫ := by rw [← adjoint_inner_left]; rfl rw [h, ← inner_self_eq_norm_sq (𝕜 := 𝕜) _] theorem apply_norm_eq_sqrt_inner_adjoint_left (A : E →L[𝕜] F) (x : E) : ‖A x‖ = √(re ⟪(A† ∘L A) x, x⟫) := by rw [← apply_norm_sq_eq_inner_adjoint_left, Real.sqrt_sq (norm_nonneg _)] theorem apply_norm_sq_eq_inner_adjoint_right (A : E →L[𝕜] F) (x : E) : ‖A x‖ ^ 2 = re ⟪x, (A† ∘L A) x⟫ := by have h : ⟪x, (A† ∘L A) x⟫ = ⟪A x, A x⟫ := by rw [← adjoint_inner_right]; rfl rw [h, ← inner_self_eq_norm_sq (𝕜 := 𝕜) _] theorem apply_norm_eq_sqrt_inner_adjoint_right (A : E →L[𝕜] F) (x : E) : ‖A x‖ = √(re ⟪x, (A† ∘L A) x⟫) := by rw [← apply_norm_sq_eq_inner_adjoint_right, Real.sqrt_sq (norm_nonneg _)] /-- The adjoint is unique: a map `A` is the adjoint of `B` iff it satisfies `⟪A x, y⟫ = ⟪x, B y⟫` for all `x` and `y`. -/ theorem eq_adjoint_iff (A : E →L[𝕜] F) (B : F →L[𝕜] E) : A = B† ↔ ∀ x y, ⟪A x, y⟫ = ⟪x, B y⟫ := by refine ⟨fun h x y => by rw [h, adjoint_inner_left], fun h => ?_⟩ ext x exact ext_inner_right 𝕜 fun y => by simp only [adjoint_inner_left, h x y] @[simp] theorem adjoint_id : ContinuousLinearMap.adjoint (ContinuousLinearMap.id 𝕜 E) = ContinuousLinearMap.id 𝕜 E := by refine Eq.symm ?_ rw [eq_adjoint_iff] simp theorem _root_.Submodule.adjoint_subtypeL (U : Submodule 𝕜 E) [CompleteSpace U] : U.subtypeL† = U.orthogonalProjection := by symm rw [eq_adjoint_iff] intro x u rw [U.coe_inner, U.inner_orthogonalProjection_left_eq_right, U.orthogonalProjection_mem_subspace_eq_self] rfl theorem _root_.Submodule.adjoint_orthogonalProjection (U : Submodule 𝕜 E) [CompleteSpace U] : (U.orthogonalProjection : E →L[𝕜] U)† = U.subtypeL := by rw [← U.adjoint_subtypeL, adjoint_adjoint] /-- `E →L[𝕜] E` is a star algebra with the adjoint as the star operation. -/ instance : Star (E →L[𝕜] E) := ⟨adjoint⟩ instance : InvolutiveStar (E →L[𝕜] E) := ⟨adjoint_adjoint⟩ instance : StarMul (E →L[𝕜] E) := ⟨adjoint_comp⟩ instance : StarRing (E →L[𝕜] E) := ⟨LinearIsometryEquiv.map_add adjoint⟩ instance : StarModule 𝕜 (E →L[𝕜] E) := ⟨LinearIsometryEquiv.map_smulₛₗ adjoint⟩ theorem star_eq_adjoint (A : E →L[𝕜] E) : star A = A† := rfl /-- A continuous linear operator is self-adjoint iff it is equal to its adjoint. -/ theorem isSelfAdjoint_iff' {A : E →L[𝕜] E} : IsSelfAdjoint A ↔ ContinuousLinearMap.adjoint A = A := Iff.rfl theorem norm_adjoint_comp_self (A : E →L[𝕜] F) : ‖ContinuousLinearMap.adjoint A ∘L A‖ = ‖A‖ * ‖A‖ := by refine le_antisymm ?_ ?_ · calc ‖A† ∘L A‖ ≤ ‖A†‖ * ‖A‖ := opNorm_comp_le _ _ _ = ‖A‖ * ‖A‖ := by rw [LinearIsometryEquiv.norm_map] · rw [← sq, ← Real.sqrt_le_sqrt_iff (norm_nonneg _), Real.sqrt_sq (norm_nonneg _)] refine opNorm_le_bound _ (Real.sqrt_nonneg _) fun x => ?_ have := calc re ⟪(A† ∘L A) x, x⟫ ≤ ‖(A† ∘L A) x‖ * ‖x‖ := re_inner_le_norm _ _ _ ≤ ‖A† ∘L A‖ * ‖x‖ * ‖x‖ := mul_le_mul_of_nonneg_right (le_opNorm _ _) (norm_nonneg _) calc ‖A x‖ = √(re ⟪(A† ∘L A) x, x⟫) := by rw [apply_norm_eq_sqrt_inner_adjoint_left] _ ≤ √(‖A† ∘L A‖ * ‖x‖ * ‖x‖) := Real.sqrt_le_sqrt this _ = √‖A† ∘L A‖ * ‖x‖ := by simp_rw [mul_assoc, Real.sqrt_mul (norm_nonneg _) (‖x‖ * ‖x‖), Real.sqrt_mul_self (norm_nonneg x)] /-- The C⋆-algebra instance when `𝕜 := ℂ` can be found in `Analysis.CStarAlgebra.ContinuousLinearMap`. -/ instance : CStarRing (E →L[𝕜] E) where norm_mul_self_le x := le_of_eq <| Eq.symm <| norm_adjoint_comp_self x theorem isAdjointPair_inner (A : E →L[𝕜] F) : LinearMap.IsAdjointPair (sesqFormOfInner : E →ₗ[𝕜] E →ₗ⋆[𝕜] 𝕜) (sesqFormOfInner : F →ₗ[𝕜] F →ₗ⋆[𝕜] 𝕜) A (A†) := by intro x y simp only [sesqFormOfInner_apply_apply, adjoint_inner_left, coe_coe] end ContinuousLinearMap /-! ### Self-adjoint operators -/ namespace IsSelfAdjoint open ContinuousLinearMap variable [CompleteSpace E] [CompleteSpace F] theorem adjoint_eq {A : E →L[𝕜] E} (hA : IsSelfAdjoint A) : ContinuousLinearMap.adjoint A = A := hA /-- Every self-adjoint operator on an inner product space is symmetric. -/ theorem isSymmetric {A : E →L[𝕜] E} (hA : IsSelfAdjoint A) : (A : E →ₗ[𝕜] E).IsSymmetric := by intro x y rw_mod_cast [← A.adjoint_inner_right, hA.adjoint_eq] /-- Conjugating preserves self-adjointness. -/ theorem conj_adjoint {T : E →L[𝕜] E} (hT : IsSelfAdjoint T) (S : E →L[𝕜] F) : IsSelfAdjoint (S ∘L T ∘L ContinuousLinearMap.adjoint S) := by rw [isSelfAdjoint_iff'] at hT ⊢ simp only [hT, adjoint_comp, adjoint_adjoint] exact ContinuousLinearMap.comp_assoc _ _ _ /-- Conjugating preserves self-adjointness. -/ theorem adjoint_conj {T : E →L[𝕜] E} (hT : IsSelfAdjoint T) (S : F →L[𝕜] E) : IsSelfAdjoint (ContinuousLinearMap.adjoint S ∘L T ∘L S) := by rw [isSelfAdjoint_iff'] at hT ⊢ simp only [hT, adjoint_comp, adjoint_adjoint] exact ContinuousLinearMap.comp_assoc _ _ _ theorem _root_.ContinuousLinearMap.isSelfAdjoint_iff_isSymmetric {A : E →L[𝕜] E} : IsSelfAdjoint A ↔ (A : E →ₗ[𝕜] E).IsSymmetric := ⟨fun hA => hA.isSymmetric, fun hA => ext fun x => ext_inner_right 𝕜 fun y => (A.adjoint_inner_left y x).symm ▸ (hA x y).symm⟩ theorem _root_.LinearMap.IsSymmetric.isSelfAdjoint {A : E →L[𝕜] E} (hA : (A : E →ₗ[𝕜] E).IsSymmetric) : IsSelfAdjoint A := by rwa [← ContinuousLinearMap.isSelfAdjoint_iff_isSymmetric] at hA /-- The orthogonal projection is self-adjoint. -/ theorem _root_.orthogonalProjection_isSelfAdjoint (U : Submodule 𝕜 E) [CompleteSpace U] : IsSelfAdjoint (U.subtypeL ∘L U.orthogonalProjection) := U.orthogonalProjection_isSymmetric.isSelfAdjoint theorem conj_orthogonalProjection {T : E →L[𝕜] E} (hT : IsSelfAdjoint T) (U : Submodule 𝕜 E) [CompleteSpace U] : IsSelfAdjoint (U.subtypeL ∘L U.orthogonalProjection ∘L T ∘L U.subtypeL ∘L U.orthogonalProjection) := by rw [← ContinuousLinearMap.comp_assoc] nth_rw 1 [← (orthogonalProjection_isSelfAdjoint U).adjoint_eq] exact hT.adjoint_conj _ end IsSelfAdjoint namespace LinearMap variable [CompleteSpace E] variable {T : E →ₗ[𝕜] E} /-- The **Hellinger--Toeplitz theorem**: Construct a self-adjoint operator from an everywhere defined symmetric operator. -/ def IsSymmetric.toSelfAdjoint (hT : IsSymmetric T) : selfAdjoint (E →L[𝕜] E) := ⟨⟨T, hT.continuous⟩, ContinuousLinearMap.isSelfAdjoint_iff_isSymmetric.mpr hT⟩ theorem IsSymmetric.coe_toSelfAdjoint (hT : IsSymmetric T) : (hT.toSelfAdjoint : E →ₗ[𝕜] E) = T := rfl theorem IsSymmetric.toSelfAdjoint_apply (hT : IsSymmetric T) {x : E} : (hT.toSelfAdjoint : E → E) x = T x := rfl end LinearMap namespace LinearMap variable [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] [FiniteDimensional 𝕜 G] /- Porting note: Lean can't use `FiniteDimensional.complete` since it was generalized to topological vector spaces. Use local instances instead. -/ /-- The adjoint of an operator from the finite-dimensional inner product space `E` to the finite-dimensional inner product space `F`. -/ def adjoint : (E →ₗ[𝕜] F) ≃ₗ⋆[𝕜] F →ₗ[𝕜] E := have := FiniteDimensional.complete 𝕜 E have := FiniteDimensional.complete 𝕜 F /- Note: Instead of the two instances above, the following works: ``` have := FiniteDimensional.complete 𝕜 have := FiniteDimensional.complete 𝕜 ``` But removing one of the `have`s makes it fail. The reason is that `E` and `F` don't live in the same universe, so the first `have` can no longer be used for `F` after its universe metavariable has been assigned to that of `E`! -/ ((LinearMap.toContinuousLinearMap : (E →ₗ[𝕜] F) ≃ₗ[𝕜] E →L[𝕜] F).trans ContinuousLinearMap.adjoint.toLinearEquiv).trans LinearMap.toContinuousLinearMap.symm theorem adjoint_toContinuousLinearMap (A : E →ₗ[𝕜] F) : haveI := FiniteDimensional.complete 𝕜 E haveI := FiniteDimensional.complete 𝕜 F LinearMap.toContinuousLinearMap (LinearMap.adjoint A) = ContinuousLinearMap.adjoint (LinearMap.toContinuousLinearMap A) := rfl theorem adjoint_eq_toCLM_adjoint (A : E →ₗ[𝕜] F) : haveI := FiniteDimensional.complete 𝕜 E haveI := FiniteDimensional.complete 𝕜 F LinearMap.adjoint A = ContinuousLinearMap.adjoint (LinearMap.toContinuousLinearMap A) := rfl /-- The fundamental property of the adjoint. -/ theorem adjoint_inner_left (A : E →ₗ[𝕜] F) (x : E) (y : F) : ⟪adjoint A y, x⟫ = ⟪y, A x⟫ := by haveI := FiniteDimensional.complete 𝕜 E haveI := FiniteDimensional.complete 𝕜 F rw [← coe_toContinuousLinearMap A, adjoint_eq_toCLM_adjoint] exact ContinuousLinearMap.adjoint_inner_left _ x y /-- The fundamental property of the adjoint. -/ theorem adjoint_inner_right (A : E →ₗ[𝕜] F) (x : E) (y : F) : ⟪x, adjoint A y⟫ = ⟪A x, y⟫ := by haveI := FiniteDimensional.complete 𝕜 E haveI := FiniteDimensional.complete 𝕜 F rw [← coe_toContinuousLinearMap A, adjoint_eq_toCLM_adjoint] exact ContinuousLinearMap.adjoint_inner_right _ x y /-- The adjoint is involutive. -/ @[simp] theorem adjoint_adjoint (A : E →ₗ[𝕜] F) : LinearMap.adjoint (LinearMap.adjoint A) = A := by ext v refine ext_inner_left 𝕜 fun w => ?_ rw [adjoint_inner_right, adjoint_inner_left] /-- The adjoint of the composition of two operators is the composition of the two adjoints in reverse order. -/ @[simp] theorem adjoint_comp (A : F →ₗ[𝕜] G) (B : E →ₗ[𝕜] F) : LinearMap.adjoint (A ∘ₗ B) = LinearMap.adjoint B ∘ₗ LinearMap.adjoint A := by ext v refine ext_inner_left 𝕜 fun w => ?_ simp only [adjoint_inner_right, LinearMap.coe_comp, Function.comp_apply] /-- The adjoint is unique: a map `A` is the adjoint of `B` iff it satisfies `⟪A x, y⟫ = ⟪x, B y⟫` for all `x` and `y`. -/ theorem eq_adjoint_iff (A : E →ₗ[𝕜] F) (B : F →ₗ[𝕜] E) : A = LinearMap.adjoint B ↔ ∀ x y, ⟪A x, y⟫ = ⟪x, B y⟫ := by refine ⟨fun h x y => by rw [h, adjoint_inner_left], fun h => ?_⟩ ext x exact ext_inner_right 𝕜 fun y => by simp only [adjoint_inner_left, h x y] /-- The adjoint is unique: a map `A` is the adjoint of `B` iff it satisfies `⟪A x, y⟫ = ⟪x, B y⟫` for all basis vectors `x` and `y`. -/ theorem eq_adjoint_iff_basis {ι₁ : Type*} {ι₂ : Type*} (b₁ : Basis ι₁ 𝕜 E) (b₂ : Basis ι₂ 𝕜 F) (A : E →ₗ[𝕜] F) (B : F →ₗ[𝕜] E) : A = LinearMap.adjoint B ↔ ∀ (i₁ : ι₁) (i₂ : ι₂), ⟪A (b₁ i₁), b₂ i₂⟫ = ⟪b₁ i₁, B (b₂ i₂)⟫ := by refine ⟨fun h x y => by rw [h, adjoint_inner_left], fun h => ?_⟩ refine Basis.ext b₁ fun i₁ => ?_ exact ext_inner_right_basis b₂ fun i₂ => by simp only [adjoint_inner_left, h i₁ i₂] theorem eq_adjoint_iff_basis_left {ι : Type*} (b : Basis ι 𝕜 E) (A : E →ₗ[𝕜] F) (B : F →ₗ[𝕜] E) : A = LinearMap.adjoint B ↔ ∀ i y, ⟪A (b i), y⟫ = ⟪b i, B y⟫ := by refine ⟨fun h x y => by rw [h, adjoint_inner_left], fun h => Basis.ext b fun i => ?_⟩ exact ext_inner_right 𝕜 fun y => by simp only [h i, adjoint_inner_left] theorem eq_adjoint_iff_basis_right {ι : Type*} (b : Basis ι 𝕜 F) (A : E →ₗ[𝕜] F) (B : F →ₗ[𝕜] E) : A = LinearMap.adjoint B ↔ ∀ i x, ⟪A x, b i⟫ = ⟪x, B (b i)⟫ := by refine ⟨fun h x y => by rw [h, adjoint_inner_left], fun h => ?_⟩ ext x exact ext_inner_right_basis b fun i => by simp only [h i, adjoint_inner_left] /-- `E →ₗ[𝕜] E` is a star algebra with the adjoint as the star operation. -/ instance : Star (E →ₗ[𝕜] E) := ⟨adjoint⟩ instance : InvolutiveStar (E →ₗ[𝕜] E) := ⟨adjoint_adjoint⟩ instance : StarMul (E →ₗ[𝕜] E) := ⟨adjoint_comp⟩ instance : StarRing (E →ₗ[𝕜] E) := ⟨LinearEquiv.map_add adjoint⟩ instance : StarModule 𝕜 (E →ₗ[𝕜] E) := ⟨LinearEquiv.map_smulₛₗ adjoint⟩ theorem star_eq_adjoint (A : E →ₗ[𝕜] E) : star A = LinearMap.adjoint A := rfl /-- A continuous linear operator is self-adjoint iff it is equal to its adjoint. -/ theorem isSelfAdjoint_iff' {A : E →ₗ[𝕜] E} : IsSelfAdjoint A ↔ LinearMap.adjoint A = A := Iff.rfl theorem isSymmetric_iff_isSelfAdjoint (A : E →ₗ[𝕜] E) : IsSymmetric A ↔ IsSelfAdjoint A := by rw [isSelfAdjoint_iff', IsSymmetric, ← LinearMap.eq_adjoint_iff] exact eq_comm theorem isAdjointPair_inner (A : E →ₗ[𝕜] F) : IsAdjointPair (sesqFormOfInner : E →ₗ[𝕜] E →ₗ⋆[𝕜] 𝕜) (sesqFormOfInner : F →ₗ[𝕜] F →ₗ⋆[𝕜] 𝕜) A (LinearMap.adjoint A) := by intro x y simp only [sesqFormOfInner_apply_apply, adjoint_inner_left] /-- The Gram operator T†T is symmetric. -/ theorem isSymmetric_adjoint_mul_self (T : E →ₗ[𝕜] E) : IsSymmetric (LinearMap.adjoint T * T) := by intro x y simp [adjoint_inner_left, adjoint_inner_right] /-- The Gram operator T†T is a positive operator. -/ theorem re_inner_adjoint_mul_self_nonneg (T : E →ₗ[𝕜] E) (x : E) : 0 ≤ re ⟪x, (LinearMap.adjoint T * T) x⟫ := by simp only [Module.End.mul_apply, adjoint_inner_right, inner_self_eq_norm_sq_to_K] norm_cast exact sq_nonneg _ @[simp] theorem im_inner_adjoint_mul_self_eq_zero (T : E →ₗ[𝕜] E) (x : E) : im ⟪x, LinearMap.adjoint T (T x)⟫ = 0 := by simp only [Module.End.mul_apply, adjoint_inner_right, inner_self_eq_norm_sq_to_K] norm_cast end LinearMap section Unitary variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace 𝕜 H] [CompleteSpace H] namespace ContinuousLinearMap variable {K : Type*} [NormedAddCommGroup K] [InnerProductSpace 𝕜 K] [CompleteSpace K] theorem inner_map_map_iff_adjoint_comp_self (u : H →L[𝕜] K) : (∀ x y : H, ⟪u x, u y⟫_𝕜 = ⟪x, y⟫_𝕜) ↔ adjoint u ∘L u = 1 := by refine ⟨fun h ↦ ext fun x ↦ ?_, fun h ↦ ?_⟩ · refine ext_inner_right 𝕜 fun y ↦ ?_ simpa [star_eq_adjoint, adjoint_inner_left] using h x y · simp [← adjoint_inner_left, ← comp_apply, h] theorem norm_map_iff_adjoint_comp_self (u : H →L[𝕜] K) : (∀ x : H, ‖u x‖ = ‖x‖) ↔ adjoint u ∘L u = 1 := by rw [LinearMap.norm_map_iff_inner_map_map u, u.inner_map_map_iff_adjoint_comp_self] @[simp] lemma _root_.LinearIsometryEquiv.adjoint_eq_symm (e : H ≃ₗᵢ[𝕜] K) : adjoint (e : H →L[𝕜] K) = e.symm := let e' := (e : H →L[𝕜] K) calc adjoint e' = adjoint e' ∘L (e' ∘L e.symm) := by convert (adjoint e').comp_id.symm ext simp [e'] _ = e.symm := by rw [← comp_assoc, norm_map_iff_adjoint_comp_self e' |>.mp e.norm_map] exact (e.symm : K →L[𝕜] H).id_comp @[simp] lemma _root_.LinearIsometryEquiv.star_eq_symm (e : H ≃ₗᵢ[𝕜] H) :
star (e : H →L[𝕜] H) = e.symm := e.adjoint_eq_symm theorem norm_map_of_mem_unitary {u : H →L[𝕜] H} (hu : u ∈ unitary (H →L[𝕜] H)) (x : H) : ‖u x‖ = ‖x‖ :=
Mathlib/Analysis/InnerProductSpace/Adjoint.lean
490
494
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne, Sébastien Gouëzel -/ import Mathlib.Analysis.Normed.Module.Basic import Mathlib.MeasureTheory.Function.SimpleFuncDense /-! # Strongly measurable and finitely strongly measurable functions A function `f` is said to be strongly measurable if `f` is the sequential limit of simple functions. It is said to be finitely strongly measurable with respect to a measure `μ` if the supports of those simple functions have finite measure. If the target space has a second countable topology, strongly measurable and measurable are equivalent. If the measure is sigma-finite, strongly measurable and finitely strongly measurable are equivalent. The main property of finitely strongly measurable functions is `FinStronglyMeasurable.exists_set_sigmaFinite`: there exists a measurable set `t` such that the function is supported on `t` and `μ.restrict t` is sigma-finite. As a consequence, we can prove some results for those functions as if the measure was sigma-finite. We provide a solid API for strongly measurable functions, as a basis for the Bochner integral. ## Main definitions * `StronglyMeasurable f`: `f : α → β` is the limit of a sequence `fs : ℕ → SimpleFunc α β`. * `FinStronglyMeasurable f μ`: `f : α → β` is the limit of a sequence `fs : ℕ → SimpleFunc α β` such that for all `n ∈ ℕ`, the measure of the support of `fs n` is finite. ## References * [Hytönen, Tuomas, Jan Van Neerven, Mark Veraar, and Lutz Weis. Analysis in Banach spaces. Springer, 2016.][Hytonen_VanNeerven_Veraar_Wies_2016] -/ -- Guard against import creep assert_not_exists InnerProductSpace open MeasureTheory Filter TopologicalSpace Function Set MeasureTheory.Measure open ENNReal Topology MeasureTheory NNReal variable {α β γ ι : Type*} [Countable ι] namespace MeasureTheory local infixr:25 " →ₛ " => SimpleFunc section Definitions variable [TopologicalSpace β] /-- A function is `StronglyMeasurable` if it is the limit of simple functions. -/ def StronglyMeasurable [MeasurableSpace α] (f : α → β) : Prop := ∃ fs : ℕ → α →ₛ β, ∀ x, Tendsto (fun n => fs n x) atTop (𝓝 (f x)) /-- The notation for StronglyMeasurable giving the measurable space instance explicitly. -/ scoped notation "StronglyMeasurable[" m "]" => @MeasureTheory.StronglyMeasurable _ _ _ m /-- A function is `FinStronglyMeasurable` with respect to a measure if it is the limit of simple functions with support with finite measure. -/ def FinStronglyMeasurable [Zero β] {_ : MeasurableSpace α} (f : α → β) (μ : Measure α := by volume_tac) : Prop := ∃ fs : ℕ → α →ₛ β, (∀ n, μ (support (fs n)) < ∞) ∧ ∀ x, Tendsto (fun n => fs n x) atTop (𝓝 (f x)) end Definitions open MeasureTheory /-! ## Strongly measurable functions -/ section StronglyMeasurable variable {_ : MeasurableSpace α} {μ : Measure α} {f : α → β} {g : ℕ → α} {m : ℕ} variable [TopologicalSpace β] theorem SimpleFunc.stronglyMeasurable (f : α →ₛ β) : StronglyMeasurable f := ⟨fun _ => f, fun _ => tendsto_const_nhds⟩ @[simp, nontriviality] lemma StronglyMeasurable.of_subsingleton_dom [Subsingleton α] : StronglyMeasurable f := ⟨fun _ => SimpleFunc.ofFinite f, fun _ => tendsto_const_nhds⟩ @[simp, nontriviality] lemma StronglyMeasurable.of_subsingleton_cod [Subsingleton β] : StronglyMeasurable f := by let f_sf : α →ₛ β := ⟨f, fun x => ?_, Set.Subsingleton.finite Set.subsingleton_of_subsingleton⟩ · exact ⟨fun _ => f_sf, fun x => tendsto_const_nhds⟩ · simp [Set.preimage, eq_iff_true_of_subsingleton] @[deprecated StronglyMeasurable.of_subsingleton_cod (since := "2025-04-09")] lemma Subsingleton.stronglyMeasurable [Subsingleton β] (f : α → β) : StronglyMeasurable f := .of_subsingleton_cod @[deprecated StronglyMeasurable.of_subsingleton_dom (since := "2025-04-09")] lemma Subsingleton.stronglyMeasurable' [Subsingleton α] (f : α → β) : StronglyMeasurable f := .of_subsingleton_dom theorem stronglyMeasurable_const {b : β} : StronglyMeasurable fun _ : α => b := ⟨fun _ => SimpleFunc.const α b, fun _ => tendsto_const_nhds⟩ @[to_additive] theorem stronglyMeasurable_one [One β] : StronglyMeasurable (1 : α → β) := stronglyMeasurable_const /-- A version of `stronglyMeasurable_const` that assumes `f x = f y` for all `x, y`. This version works for functions between empty types. -/ theorem stronglyMeasurable_const' (hf : ∀ x y, f x = f y) : StronglyMeasurable f := by nontriviality α inhabit α convert stronglyMeasurable_const (β := β) using 1 exact funext fun x => hf x default variable [MeasurableSingletonClass α] section aux omit [TopologicalSpace β] /-- Auxiliary definition for `StronglyMeasurable.of_discrete`. -/ private noncomputable def simpleFuncAux (f : α → β) (g : ℕ → α) : ℕ → SimpleFunc α β | 0 => .const _ (f (g 0)) | n + 1 => .piecewise {g n} (.singleton _) (.const _ <| f (g n)) (simpleFuncAux f g n) private lemma simpleFuncAux_eq_of_lt : ∀ n > m, simpleFuncAux f g n (g m) = f (g m) | _, .refl => by simp [simpleFuncAux] | _, Nat.le.step (m := n) hmn => by obtain hnm | hnm := eq_or_ne (g n) (g m) <;> simp [simpleFuncAux, Set.piecewise_eq_of_not_mem , hnm.symm, simpleFuncAux_eq_of_lt _ hmn] private lemma simpleFuncAux_eventuallyEq : ∀ᶠ n in atTop, simpleFuncAux f g n (g m) = f (g m) := eventually_atTop.2 ⟨_, simpleFuncAux_eq_of_lt⟩ end aux lemma StronglyMeasurable.of_discrete [Countable α] : StronglyMeasurable f := by nontriviality α nontriviality β obtain ⟨g, hg⟩ := exists_surjective_nat α exact ⟨simpleFuncAux f g, hg.forall.2 fun m ↦ tendsto_nhds_of_eventually_eq simpleFuncAux_eventuallyEq⟩ @[deprecated StronglyMeasurable.of_discrete (since := "2025-04-09")] theorem StronglyMeasurable.of_finite [Finite α] : StronglyMeasurable f := .of_discrete end StronglyMeasurable namespace StronglyMeasurable variable {f g : α → β} section BasicPropertiesInAnyTopologicalSpace variable [TopologicalSpace β] /-- A sequence of simple functions such that `∀ x, Tendsto (fun n => hf.approx n x) atTop (𝓝 (f x))`. That property is given by `stronglyMeasurable.tendsto_approx`. -/ protected noncomputable def approx {_ : MeasurableSpace α} (hf : StronglyMeasurable f) : ℕ → α →ₛ β := hf.choose protected theorem tendsto_approx {_ : MeasurableSpace α} (hf : StronglyMeasurable f) : ∀ x, Tendsto (fun n => hf.approx n x) atTop (𝓝 (f x)) := hf.choose_spec /-- Similar to `stronglyMeasurable.approx`, but enforces that the norm of every function in the sequence is less than `c` everywhere. If `‖f x‖ ≤ c` this sequence of simple functions verifies `Tendsto (fun n => hf.approxBounded n x) atTop (𝓝 (f x))`. -/ noncomputable def approxBounded {_ : MeasurableSpace α} [Norm β] [SMul ℝ β] (hf : StronglyMeasurable f) (c : ℝ) : ℕ → SimpleFunc α β := fun n => (hf.approx n).map fun x => min 1 (c / ‖x‖) • x theorem tendsto_approxBounded_of_norm_le {β} {f : α → β} [NormedAddCommGroup β] [NormedSpace ℝ β] {m : MeasurableSpace α} (hf : StronglyMeasurable[m] f) {c : ℝ} {x : α} (hfx : ‖f x‖ ≤ c) : Tendsto (fun n => hf.approxBounded c n x) atTop (𝓝 (f x)) := by have h_tendsto := hf.tendsto_approx x simp only [StronglyMeasurable.approxBounded, SimpleFunc.coe_map, Function.comp_apply] by_cases hfx0 : ‖f x‖ = 0 · rw [norm_eq_zero] at hfx0 rw [hfx0] at h_tendsto ⊢ have h_tendsto_norm : Tendsto (fun n => ‖hf.approx n x‖) atTop (𝓝 0) := by convert h_tendsto.norm rw [norm_zero] refine squeeze_zero_norm (fun n => ?_) h_tendsto_norm calc ‖min 1 (c / ‖hf.approx n x‖) • hf.approx n x‖ = ‖min 1 (c / ‖hf.approx n x‖)‖ * ‖hf.approx n x‖ := norm_smul _ _ _ ≤ ‖(1 : ℝ)‖ * ‖hf.approx n x‖ := by refine mul_le_mul_of_nonneg_right ?_ (norm_nonneg _) rw [norm_one, Real.norm_of_nonneg] · exact min_le_left _ _ · exact le_min zero_le_one (div_nonneg ((norm_nonneg _).trans hfx) (norm_nonneg _)) _ = ‖hf.approx n x‖ := by rw [norm_one, one_mul] rw [← one_smul ℝ (f x)] refine Tendsto.smul ?_ h_tendsto have : min 1 (c / ‖f x‖) = 1 := by rw [min_eq_left_iff, one_le_div (lt_of_le_of_ne (norm_nonneg _) (Ne.symm hfx0))] exact hfx nth_rw 2 [this.symm] refine Tendsto.min tendsto_const_nhds ?_ exact Tendsto.div tendsto_const_nhds h_tendsto.norm hfx0 theorem tendsto_approxBounded_ae {β} {f : α → β} [NormedAddCommGroup β] [NormedSpace ℝ β] {m m0 : MeasurableSpace α} {μ : Measure α} (hf : StronglyMeasurable[m] f) {c : ℝ} (hf_bound : ∀ᵐ x ∂μ, ‖f x‖ ≤ c) : ∀ᵐ x ∂μ, Tendsto (fun n => hf.approxBounded c n x) atTop (𝓝 (f x)) := by filter_upwards [hf_bound] with x hfx using tendsto_approxBounded_of_norm_le hf hfx theorem norm_approxBounded_le {β} {f : α → β} [SeminormedAddCommGroup β] [NormedSpace ℝ β] {m : MeasurableSpace α} {c : ℝ} (hf : StronglyMeasurable[m] f) (hc : 0 ≤ c) (n : ℕ) (x : α) : ‖hf.approxBounded c n x‖ ≤ c := by simp only [StronglyMeasurable.approxBounded, SimpleFunc.coe_map, Function.comp_apply] refine (norm_smul_le _ _).trans ?_ by_cases h0 : ‖hf.approx n x‖ = 0 · simp only [h0, _root_.div_zero, min_eq_right, zero_le_one, norm_zero, mul_zero] exact hc rcases le_total ‖hf.approx n x‖ c with h | h · rw [min_eq_left _] · simpa only [norm_one, one_mul] using h · rwa [one_le_div (lt_of_le_of_ne (norm_nonneg _) (Ne.symm h0))] · rw [min_eq_right _] · rw [norm_div, norm_norm, mul_comm, mul_div, div_eq_mul_inv, mul_comm, ← mul_assoc, inv_mul_cancel₀ h0, one_mul, Real.norm_of_nonneg hc] · rwa [div_le_one (lt_of_le_of_ne (norm_nonneg _) (Ne.symm h0))] theorem _root_.stronglyMeasurable_bot_iff [Nonempty β] [T2Space β] : StronglyMeasurable[⊥] f ↔ ∃ c, f = fun _ => c := by rcases isEmpty_or_nonempty α with hα | hα · simp [eq_iff_true_of_subsingleton] refine ⟨fun hf => ?_, fun hf_eq => ?_⟩ · refine ⟨f hα.some, ?_⟩ let fs := hf.approx have h_fs_tendsto : ∀ x, Tendsto (fun n => fs n x) atTop (𝓝 (f x)) := hf.tendsto_approx have : ∀ n, ∃ c, ∀ x, fs n x = c := fun n => SimpleFunc.simpleFunc_bot (fs n) let cs n := (this n).choose have h_cs_eq : ∀ n, ⇑(fs n) = fun _ => cs n := fun n => funext (this n).choose_spec conv at h_fs_tendsto => enter [x, 1, n]; rw [h_cs_eq] have h_tendsto : Tendsto cs atTop (𝓝 (f hα.some)) := h_fs_tendsto hα.some ext1 x exact tendsto_nhds_unique (h_fs_tendsto x) h_tendsto · obtain ⟨c, rfl⟩ := hf_eq exact stronglyMeasurable_const end BasicPropertiesInAnyTopologicalSpace theorem finStronglyMeasurable_of_set_sigmaFinite [TopologicalSpace β] [Zero β] {m : MeasurableSpace α} {μ : Measure α} (hf_meas : StronglyMeasurable f) {t : Set α} (ht : MeasurableSet t) (hft_zero : ∀ x ∈ tᶜ, f x = 0) (htμ : SigmaFinite (μ.restrict t)) : FinStronglyMeasurable f μ := by haveI : SigmaFinite (μ.restrict t) := htμ let S := spanningSets (μ.restrict t) have hS_meas : ∀ n, MeasurableSet (S n) := measurableSet_spanningSets (μ.restrict t) let f_approx := hf_meas.approx let fs n := SimpleFunc.restrict (f_approx n) (S n ∩ t) have h_fs_t_compl : ∀ n, ∀ x, x ∉ t → fs n x = 0 := by intro n x hxt rw [SimpleFunc.restrict_apply _ ((hS_meas n).inter ht)] refine Set.indicator_of_not_mem ?_ _ simp [hxt] refine ⟨fs, ?_, fun x => ?_⟩ · simp_rw [SimpleFunc.support_eq, ← Finset.mem_coe] classical refine fun n => measure_biUnion_lt_top {y ∈ (fs n).range | y ≠ 0}.finite_toSet fun y hy => ?_ rw [SimpleFunc.restrict_preimage_singleton _ ((hS_meas n).inter ht)] swap · letI : (y : β) → Decidable (y = 0) := fun y => Classical.propDecidable _ rw [Finset.mem_coe, Finset.mem_filter] at hy exact hy.2 refine (measure_mono Set.inter_subset_left).trans_lt ?_ have h_lt_top := measure_spanningSets_lt_top (μ.restrict t) n rwa [Measure.restrict_apply' ht] at h_lt_top · by_cases hxt : x ∈ t swap · rw [funext fun n => h_fs_t_compl n x hxt, hft_zero x hxt] exact tendsto_const_nhds have h : Tendsto (fun n => (f_approx n) x) atTop (𝓝 (f x)) := hf_meas.tendsto_approx x obtain ⟨n₁, hn₁⟩ : ∃ n, ∀ m, n ≤ m → fs m x = f_approx m x := by obtain ⟨n, hn⟩ : ∃ n, ∀ m, n ≤ m → x ∈ S m ∩ t := by rsuffices ⟨n, hn⟩ : ∃ n, ∀ m, n ≤ m → x ∈ S m · exact ⟨n, fun m hnm => Set.mem_inter (hn m hnm) hxt⟩
rsuffices ⟨n, hn⟩ : ∃ n, x ∈ S n · exact ⟨n, fun m hnm => monotone_spanningSets (μ.restrict t) hnm hn⟩ rw [← Set.mem_iUnion, iUnion_spanningSets (μ.restrict t)] trivial refine ⟨n, fun m hnm => ?_⟩ simp_rw [fs, SimpleFunc.restrict_apply _ ((hS_meas m).inter ht), Set.indicator_of_mem (hn m hnm)] rw [tendsto_atTop'] at h ⊢ intro s hs obtain ⟨n₂, hn₂⟩ := h s hs refine ⟨max n₁ n₂, fun m hm => ?_⟩ rw [hn₁ m ((le_max_left _ _).trans hm.le)] exact hn₂ m ((le_max_right _ _).trans hm.le) /-- If the measure is sigma-finite, all strongly measurable functions are `FinStronglyMeasurable`. -/ @[aesop 5% apply (rule_sets := [Measurable])] protected theorem finStronglyMeasurable [TopologicalSpace β] [Zero β] {m0 : MeasurableSpace α} (hf : StronglyMeasurable f) (μ : Measure α) [SigmaFinite μ] : FinStronglyMeasurable f μ := hf.finStronglyMeasurable_of_set_sigmaFinite MeasurableSet.univ (by simp) (by rwa [Measure.restrict_univ]) /-- A strongly measurable function is measurable. -/ @[aesop 5% apply (rule_sets := [Measurable])] protected theorem measurable {_ : MeasurableSpace α} [TopologicalSpace β] [PseudoMetrizableSpace β] [MeasurableSpace β] [BorelSpace β] (hf : StronglyMeasurable f) : Measurable f := measurable_of_tendsto_metrizable (fun n => (hf.approx n).measurable) (tendsto_pi_nhds.mpr hf.tendsto_approx) /-- A strongly measurable function is almost everywhere measurable. -/ @[aesop 5% apply (rule_sets := [Measurable])] protected theorem aemeasurable {_ : MeasurableSpace α} [TopologicalSpace β] [PseudoMetrizableSpace β] [MeasurableSpace β] [BorelSpace β] {μ : Measure α} (hf : StronglyMeasurable f) : AEMeasurable f μ := hf.measurable.aemeasurable theorem _root_.Continuous.comp_stronglyMeasurable {_ : MeasurableSpace α} [TopologicalSpace β] [TopologicalSpace γ] {g : β → γ} {f : α → β} (hg : Continuous g) (hf : StronglyMeasurable f) : StronglyMeasurable fun x => g (f x) := ⟨fun n => SimpleFunc.map g (hf.approx n), fun x => (hg.tendsto _).comp (hf.tendsto_approx x)⟩ @[to_additive] nonrec theorem measurableSet_mulSupport {m : MeasurableSpace α} [One β] [TopologicalSpace β] [MetrizableSpace β] (hf : StronglyMeasurable f) : MeasurableSet (mulSupport f) := by borelize β exact measurableSet_mulSupport hf.measurable protected theorem mono {m m' : MeasurableSpace α} [TopologicalSpace β]
Mathlib/MeasureTheory/Function/StronglyMeasurable/Basic.lean
285
332
/- 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.BigOperators.Group.Finset.Piecewise import Mathlib.Algebra.Group.Ext import Mathlib.CategoryTheory.Limits.Preserves.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Biproducts import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Products import Mathlib.CategoryTheory.Preadditive.Basic import Mathlib.Tactic.Abel /-! # Basic facts about biproducts in preadditive categories. In (or between) preadditive categories, * Any biproduct satisfies the equality `total : ∑ j : J, biproduct.π f j ≫ biproduct.ι f j = 𝟙 (⨁ f)`, or, in the binary case, `total : fst ≫ inl + snd ≫ inr = 𝟙 X`. * Any (binary) `product` or (binary) `coproduct` is a (binary) `biproduct`. * In any category (with zero morphisms), if `biprod.map f g` is an isomorphism, then both `f` and `g` are isomorphisms. * If `f` is a morphism `X₁ ⊞ X₂ ⟶ Y₁ ⊞ Y₂` whose `X₁ ⟶ Y₁` entry is an isomorphism, then we can construct isomorphisms `L : X₁ ⊞ X₂ ≅ X₁ ⊞ X₂` and `R : Y₁ ⊞ Y₂ ≅ Y₁ ⊞ Y₂` so that `L.hom ≫ g ≫ R.hom` is diagonal (with `X₁ ⟶ Y₁` component still `f`), via Gaussian elimination. * As a corollary of the previous two facts, if we have an isomorphism `X₁ ⊞ X₂ ≅ Y₁ ⊞ Y₂` whose `X₁ ⟶ Y₁` entry is an isomorphism, we can construct an isomorphism `X₂ ≅ Y₂`. * If `f : W ⊞ X ⟶ Y ⊞ Z` is an isomorphism, either `𝟙 W = 0`, or at least one of the component maps `W ⟶ Y` and `W ⟶ Z` is nonzero. * If `f : ⨁ S ⟶ ⨁ T` is an isomorphism, then every column (corresponding to a nonzero summand in the domain) has some nonzero matrix entry. * A functor preserves a biproduct if and only if it preserves the corresponding product if and only if it preserves the corresponding coproduct. There are connections between this material and the special case of the category whose morphisms are matrices over a ring, in particular the Schur complement (see `Mathlib.LinearAlgebra.Matrix.SchurComplement`). In particular, the declarations `CategoryTheory.Biprod.isoElim`, `CategoryTheory.Biprod.gaussian` and `Matrix.invertibleOfFromBlocks₁₁Invertible` are all closely related. -/ open CategoryTheory open CategoryTheory.Preadditive open CategoryTheory.Limits open CategoryTheory.Functor open CategoryTheory.Preadditive universe v v' u u' noncomputable section namespace CategoryTheory variable {C : Type u} [Category.{v} C] [Preadditive C] namespace Limits section Fintype variable {J : Type} [Fintype J] /-- In a preadditive category, we can construct a biproduct for `f : J → C` from any bicone `b` for `f` satisfying `total : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.X`. (That is, such a bicone is a limit cone and a colimit cocone.) -/ def isBilimitOfTotal {f : J → C} (b : Bicone f) (total : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.pt) : b.IsBilimit where isLimit := { lift := fun s => ∑ j : J, s.π.app ⟨j⟩ ≫ b.ι j uniq := fun s m h => by erw [← Category.comp_id m, ← total, comp_sum] apply Finset.sum_congr rfl intro j _ have reassoced : m ≫ Bicone.π b j ≫ Bicone.ι b j = s.π.app ⟨j⟩ ≫ Bicone.ι b j := by erw [← Category.assoc, eq_whisker (h ⟨j⟩)] rw [reassoced] fac := fun s j => by classical cases j simp only [sum_comp, Category.assoc, Bicone.toCone_π_app, b.ι_π, comp_dite] -- See note [dsimp, simp]. dsimp simp } isColimit := { desc := fun s => ∑ j : J, b.π j ≫ s.ι.app ⟨j⟩ uniq := fun s m h => by erw [← Category.id_comp m, ← total, sum_comp] apply Finset.sum_congr rfl intro j _ erw [Category.assoc, h ⟨j⟩] fac := fun s j => by classical cases j simp only [comp_sum, ← Category.assoc, Bicone.toCocone_ι_app, b.ι_π, dite_comp] dsimp; simp } theorem IsBilimit.total {f : J → C} {b : Bicone f} (i : b.IsBilimit) : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.pt := i.isLimit.hom_ext fun j => by classical cases j simp [sum_comp, b.ι_π, comp_dite] /-- In a preadditive category, we can construct a biproduct for `f : J → C` from any bicone `b` for `f` satisfying `total : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.X`. (That is, such a bicone is a limit cone and a colimit cocone.) -/ theorem hasBiproduct_of_total {f : J → C} (b : Bicone f) (total : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.pt) : HasBiproduct f := HasBiproduct.mk { bicone := b isBilimit := isBilimitOfTotal b total } /-- In a preadditive category, any finite bicone which is a limit cone is in fact a bilimit bicone. -/ def isBilimitOfIsLimit {f : J → C} (t : Bicone f) (ht : IsLimit t.toCone) : t.IsBilimit := isBilimitOfTotal _ <| ht.hom_ext fun j => by classical cases j simp [sum_comp, t.ι_π, dite_comp, comp_dite] /-- We can turn any limit cone over a pair into a bilimit bicone. -/ def biconeIsBilimitOfLimitConeOfIsLimit {f : J → C} {t : Cone (Discrete.functor f)} (ht : IsLimit t) : (Bicone.ofLimitCone ht).IsBilimit := isBilimitOfIsLimit _ <| IsLimit.ofIsoLimit ht <| Cones.ext (Iso.refl _) (by simp) /-- In a preadditive category, any finite bicone which is a colimit cocone is in fact a bilimit bicone. -/ def isBilimitOfIsColimit {f : J → C} (t : Bicone f) (ht : IsColimit t.toCocone) : t.IsBilimit := isBilimitOfTotal _ <| ht.hom_ext fun j => by classical cases j simp_rw [Bicone.toCocone_ι_app, comp_sum, ← Category.assoc, t.ι_π, dite_comp] simp /-- We can turn any limit cone over a pair into a bilimit bicone. -/ def biconeIsBilimitOfColimitCoconeOfIsColimit {f : J → C} {t : Cocone (Discrete.functor f)} (ht : IsColimit t) : (Bicone.ofColimitCocone ht).IsBilimit := isBilimitOfIsColimit _ <| IsColimit.ofIsoColimit ht <| Cocones.ext (Iso.refl _) <| by rintro ⟨j⟩; simp end Fintype section Finite variable {J : Type} [Finite J] /-- In a preadditive category, if the product over `f : J → C` exists, then the biproduct over `f` exists. -/ theorem HasBiproduct.of_hasProduct (f : J → C) [HasProduct f] : HasBiproduct f := by cases nonempty_fintype J exact HasBiproduct.mk { bicone := _ isBilimit := biconeIsBilimitOfLimitConeOfIsLimit (limit.isLimit _) } /-- In a preadditive category, if the coproduct over `f : J → C` exists, then the biproduct over `f` exists. -/ theorem HasBiproduct.of_hasCoproduct (f : J → C) [HasCoproduct f] : HasBiproduct f := by cases nonempty_fintype J exact HasBiproduct.mk { bicone := _ isBilimit := biconeIsBilimitOfColimitCoconeOfIsColimit (colimit.isColimit _) } end Finite /-- A preadditive category with finite products has finite biproducts. -/ theorem HasFiniteBiproducts.of_hasFiniteProducts [HasFiniteProducts C] : HasFiniteBiproducts C := ⟨fun _ => { has_biproduct := fun _ => HasBiproduct.of_hasProduct _ }⟩ /-- A preadditive category with finite coproducts has finite biproducts. -/ theorem HasFiniteBiproducts.of_hasFiniteCoproducts [HasFiniteCoproducts C] : HasFiniteBiproducts C := ⟨fun _ => { has_biproduct := fun _ => HasBiproduct.of_hasCoproduct _ }⟩ section HasBiproduct variable {J : Type} [Fintype J] {f : J → C} [HasBiproduct f] /-- In any preadditive category, any biproduct satisfies `∑ j : J, biproduct.π f j ≫ biproduct.ι f j = 𝟙 (⨁ f)` -/ @[simp] theorem biproduct.total : ∑ j : J, biproduct.π f j ≫ biproduct.ι f j = 𝟙 (⨁ f) := IsBilimit.total (biproduct.isBilimit _) theorem biproduct.lift_eq {T : C} {g : ∀ j, T ⟶ f j} : biproduct.lift g = ∑ j, g j ≫ biproduct.ι f j := by classical ext j simp only [sum_comp, biproduct.ι_π, comp_dite, biproduct.lift_π, Category.assoc, comp_zero, Finset.sum_dite_eq', Finset.mem_univ, eqToHom_refl, Category.comp_id, if_true] theorem biproduct.desc_eq {T : C} {g : ∀ j, f j ⟶ T} : biproduct.desc g = ∑ j, biproduct.π f j ≫ g j := by classical ext j simp [comp_sum, biproduct.ι_π_assoc, dite_comp] @[reassoc] theorem biproduct.lift_desc {T U : C} {g : ∀ j, T ⟶ f j} {h : ∀ j, f j ⟶ U} : biproduct.lift g ≫ biproduct.desc h = ∑ j : J, g j ≫ h j := by classical simp [biproduct.lift_eq, biproduct.desc_eq, comp_sum, sum_comp, biproduct.ι_π_assoc, comp_dite, dite_comp] theorem biproduct.map_eq [HasFiniteBiproducts C] {f g : J → C} {h : ∀ j, f j ⟶ g j} : biproduct.map h = ∑ j : J, biproduct.π f j ≫ h j ≫ biproduct.ι g j := by classical ext simp [biproduct.ι_π, biproduct.ι_π_assoc, comp_sum, sum_comp, comp_dite, dite_comp] @[reassoc] theorem biproduct.lift_matrix {K : Type} [Finite K] [HasFiniteBiproducts C] {f : J → C} {g : K → C} {P} (x : ∀ j, P ⟶ f j) (m : ∀ j k, f j ⟶ g k) : biproduct.lift x ≫ biproduct.matrix m = biproduct.lift fun k => ∑ j, x j ≫ m j k := by ext simp [biproduct.lift_desc] end HasBiproduct section HasFiniteBiproducts variable {J K : Type} [Finite J] {f : J → C} [HasFiniteBiproducts C] @[reassoc] theorem biproduct.matrix_desc [Fintype K] {f : J → C} {g : K → C} (m : ∀ j k, f j ⟶ g k) {P} (x : ∀ k, g k ⟶ P) : biproduct.matrix m ≫ biproduct.desc x = biproduct.desc fun j => ∑ k, m j k ≫ x k := by ext simp [lift_desc] variable [Finite K] @[reassoc] theorem biproduct.matrix_map {f : J → C} {g : K → C} {h : K → C} (m : ∀ j k, f j ⟶ g k) (n : ∀ k, g k ⟶ h k) : biproduct.matrix m ≫ biproduct.map n = biproduct.matrix fun j k => m j k ≫ n k := by ext simp @[reassoc] theorem biproduct.map_matrix {f : J → C} {g : J → C} {h : K → C} (m : ∀ k, f k ⟶ g k) (n : ∀ j k, g j ⟶ h k) : biproduct.map m ≫ biproduct.matrix n = biproduct.matrix fun j k => m j ≫ n j k := by ext simp end HasFiniteBiproducts /-- Reindex a categorical biproduct via an equivalence of the index types. -/ @[simps] def biproduct.reindex {β γ : Type} [Finite β] (ε : β ≃ γ)
(f : γ → C) [HasBiproduct f] [HasBiproduct (f ∘ ε)] : ⨁ f ∘ ε ≅ ⨁ f where hom := biproduct.desc fun b => biproduct.ι f (ε b) inv := biproduct.lift fun b => biproduct.π f (ε b) hom_inv_id := by ext b b'
Mathlib/CategoryTheory/Preadditive/Biproducts.lean
275
279
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.Star.SelfAdjoint import Mathlib.LinearAlgebra.Dimension.StrongRankCondition import Mathlib.LinearAlgebra.FreeModule.Finite.Basic /-! # Quaternions In this file we define quaternions `ℍ[R]` over a commutative ring `R`, and define some algebraic structures on `ℍ[R]`. ## Main definitions * `QuaternionAlgebra R a b c`, `ℍ[R, a, b, c]` : [Bourbaki, *Algebra I*][bourbaki1989] with coefficients `a`, `b`, `c` (Many other references such as Wikipedia assume $\operatorname{char} R ≠ 2$ therefore one can complete the square and WLOG assume $b = 0$.) * `Quaternion R`, `ℍ[R]` : the space of quaternions, a.k.a. `QuaternionAlgebra R (-1) (0) (-1)`; * `Quaternion.normSq` : square of the norm of a quaternion; We also define the following algebraic structures on `ℍ[R]`: * `Ring ℍ[R, a, b, c]`, `StarRing ℍ[R, a, b, c]`, and `Algebra R ℍ[R, a, b, c]` : for any commutative ring `R`; * `Ring ℍ[R]`, `StarRing ℍ[R]`, and `Algebra R ℍ[R]` : for any commutative ring `R`; * `IsDomain ℍ[R]` : for a linear ordered commutative ring `R`; * `DivisionRing ℍ[R]` : for a linear ordered field `R`. ## Notation The following notation is available with `open Quaternion` or `open scoped Quaternion`. * `ℍ[R, c₁, c₂, c₃]` : `QuaternionAlgebra R c₁ c₂ c₃` * `ℍ[R, c₁, c₂]` : `QuaternionAlgebra R c₁ 0 c₂` * `ℍ[R]` : quaternions over `R`. ## Implementation notes We define quaternions over any ring `R`, not just `ℝ` to be able to deal with, e.g., integer or rational quaternions without using real numbers. In particular, all definitions in this file are computable. ## Tags quaternion -/ /-- Quaternion algebra over a type with fixed coefficients where $i^2 = a + bi$ and $j^2 = c$, denoted as `ℍ[R,a,b]`. Implemented as a structure with four fields: `re`, `imI`, `imJ`, and `imK`. -/ @[ext] structure QuaternionAlgebra (R : Type*) (a b c : R) where /-- Real part of a quaternion. -/ re : R /-- First imaginary part (i) of a quaternion. -/ imI : R /-- Second imaginary part (j) of a quaternion. -/ imJ : R /-- Third imaginary part (k) of a quaternion. -/ imK : R @[inherit_doc] scoped[Quaternion] notation "ℍ[" R "," a "," b "," c "]" => QuaternionAlgebra R a b c @[inherit_doc] scoped[Quaternion] notation "ℍ[" R "," a "," b "]" => QuaternionAlgebra R a 0 b namespace QuaternionAlgebra open Quaternion /-- The equivalence between a quaternion algebra over `R` and `R × R × R × R`. -/ @[simps] def equivProd {R : Type*} (c₁ c₂ c₃ : R) : ℍ[R,c₁,c₂,c₃] ≃ R × R × R × R where toFun a := ⟨a.1, a.2, a.3, a.4⟩ invFun a := ⟨a.1, a.2.1, a.2.2.1, a.2.2.2⟩ left_inv _ := rfl right_inv _ := rfl /-- The equivalence between a quaternion algebra over `R` and `Fin 4 → R`. -/ @[simps symm_apply] def equivTuple {R : Type*} (c₁ c₂ c₃ : R) : ℍ[R,c₁,c₂,c₃] ≃ (Fin 4 → R) where toFun a := ![a.1, a.2, a.3, a.4] invFun a := ⟨a 0, a 1, a 2, a 3⟩ left_inv _ := rfl right_inv f := by ext ⟨_, _ | _ | _ | _ | _ | ⟨⟩⟩ <;> rfl @[simp] theorem equivTuple_apply {R : Type*} (c₁ c₂ c₃ : R) (x : ℍ[R,c₁,c₂,c₃]) : equivTuple c₁ c₂ c₃ x = ![x.re, x.imI, x.imJ, x.imK] := rfl @[simp] theorem mk.eta {R : Type*} {c₁ c₂ c₃} (a : ℍ[R,c₁,c₂,c₃]) : mk a.1 a.2 a.3 a.4 = a := rfl variable {S T R : Type*} {c₁ c₂ c₃ : R} (r x y : R) (a b : ℍ[R,c₁,c₂,c₃]) instance [Subsingleton R] : Subsingleton ℍ[R, c₁, c₂, c₃] := (equivTuple c₁ c₂ c₃).subsingleton instance [Nontrivial R] : Nontrivial ℍ[R, c₁, c₂, c₃] := (equivTuple c₁ c₂ c₃).surjective.nontrivial section Zero variable [Zero R] /-- The imaginary part of a quaternion. Note that unless `c₂ = 0`, this definition is not particularly well-behaved; for instance, `QuaternionAlgebra.star_im` only says that the star of an imaginary quaternion is imaginary under this condition. -/ def im (x : ℍ[R,c₁,c₂,c₃]) : ℍ[R,c₁,c₂,c₃] := ⟨0, x.imI, x.imJ, x.imK⟩ @[simp] theorem im_re : a.im.re = 0 := rfl @[simp] theorem im_imI : a.im.imI = a.imI := rfl @[simp] theorem im_imJ : a.im.imJ = a.imJ := rfl @[simp] theorem im_imK : a.im.imK = a.imK := rfl @[simp] theorem im_idem : a.im.im = a.im := rfl /-- Coercion `R → ℍ[R,c₁,c₂,c₃]`. -/ @[coe] def coe (x : R) : ℍ[R,c₁,c₂,c₃] := ⟨x, 0, 0, 0⟩ instance : CoeTC R ℍ[R,c₁,c₂,c₃] := ⟨coe⟩ @[simp, norm_cast] theorem coe_re : (x : ℍ[R,c₁,c₂,c₃]).re = x := rfl @[simp, norm_cast] theorem coe_imI : (x : ℍ[R,c₁,c₂,c₃]).imI = 0 := rfl @[simp, norm_cast] theorem coe_imJ : (x : ℍ[R,c₁,c₂,c₃]).imJ = 0 := rfl @[simp, norm_cast] theorem coe_imK : (x : ℍ[R,c₁,c₂,c₃]).imK = 0 := rfl theorem coe_injective : Function.Injective (coe : R → ℍ[R,c₁,c₂,c₃]) := fun _ _ h => congr_arg re h @[simp] theorem coe_inj {x y : R} : (x : ℍ[R,c₁,c₂,c₃]) = y ↔ x = y := coe_injective.eq_iff -- Porting note: removed `simps`, added simp lemmas manually. -- Should adjust `simps` to name properly, i.e. as `zero_re` rather than `instZero_zero_re`. instance : Zero ℍ[R,c₁,c₂,c₃] := ⟨⟨0, 0, 0, 0⟩⟩ @[scoped simp] theorem zero_re : (0 : ℍ[R,c₁,c₂,c₃]).re = 0 := rfl @[scoped simp] theorem zero_imI : (0 : ℍ[R,c₁,c₂,c₃]).imI = 0 := rfl @[scoped simp] theorem zero_imJ : (0 : ℍ[R,c₁,c₂,c₃]).imJ = 0 := rfl @[scoped simp] theorem zero_imK : (0 : ℍ[R,c₁,c₂,c₃]).imK = 0 := rfl @[scoped simp] theorem zero_im : (0 : ℍ[R,c₁,c₂,c₃]).im = 0 := rfl @[simp, norm_cast] theorem coe_zero : ((0 : R) : ℍ[R,c₁,c₂,c₃]) = 0 := rfl instance : Inhabited ℍ[R,c₁,c₂,c₃] := ⟨0⟩ section One variable [One R] -- Porting note: removed `simps`, added simp lemmas manually. Should adjust `simps` to name properly instance : One ℍ[R,c₁,c₂,c₃] := ⟨⟨1, 0, 0, 0⟩⟩ @[scoped simp] theorem one_re : (1 : ℍ[R,c₁,c₂,c₃]).re = 1 := rfl @[scoped simp] theorem one_imI : (1 : ℍ[R,c₁,c₂,c₃]).imI = 0 := rfl @[scoped simp] theorem one_imJ : (1 : ℍ[R,c₁,c₂,c₃]).imJ = 0 := rfl @[scoped simp] theorem one_imK : (1 : ℍ[R,c₁,c₂,c₃]).imK = 0 := rfl @[scoped simp] theorem one_im : (1 : ℍ[R,c₁,c₂,c₃]).im = 0 := rfl @[simp, norm_cast] theorem coe_one : ((1 : R) : ℍ[R,c₁,c₂,c₃]) = 1 := rfl end One end Zero section Add variable [Add R] -- Porting note: removed `simps`, added simp lemmas manually. Should adjust `simps` to name properly instance : Add ℍ[R,c₁,c₂,c₃] := ⟨fun a b => ⟨a.1 + b.1, a.2 + b.2, a.3 + b.3, a.4 + b.4⟩⟩ @[simp] theorem add_re : (a + b).re = a.re + b.re := rfl @[simp] theorem add_imI : (a + b).imI = a.imI + b.imI := rfl @[simp] theorem add_imJ : (a + b).imJ = a.imJ + b.imJ := rfl @[simp] theorem add_imK : (a + b).imK = a.imK + b.imK := rfl @[simp] theorem mk_add_mk (a₁ a₂ a₃ a₄ b₁ b₂ b₃ b₄ : R) : (mk a₁ a₂ a₃ a₄ : ℍ[R,c₁,c₂,c₃]) + mk b₁ b₂ b₃ b₄ = mk (a₁ + b₁) (a₂ + b₂) (a₃ + b₃) (a₄ + b₄) := rfl end Add section AddZeroClass variable [AddZeroClass R] @[simp] theorem add_im : (a + b).im = a.im + b.im := QuaternionAlgebra.ext (zero_add _).symm rfl rfl rfl @[simp, norm_cast] theorem coe_add : ((x + y : R) : ℍ[R,c₁,c₂,c₃]) = x + y := by ext <;> simp end AddZeroClass section Neg variable [Neg R] -- Porting note: removed `simps`, added simp lemmas manually. Should adjust `simps` to name properly instance : Neg ℍ[R,c₁,c₂,c₃] := ⟨fun a => ⟨-a.1, -a.2, -a.3, -a.4⟩⟩ @[simp] theorem neg_re : (-a).re = -a.re := rfl @[simp] theorem neg_imI : (-a).imI = -a.imI := rfl @[simp] theorem neg_imJ : (-a).imJ = -a.imJ := rfl @[simp] theorem neg_imK : (-a).imK = -a.imK := rfl @[simp] theorem neg_mk (a₁ a₂ a₃ a₄ : R) : -(mk a₁ a₂ a₃ a₄ : ℍ[R,c₁,c₂,c₃]) = ⟨-a₁, -a₂, -a₃, -a₄⟩ := rfl end Neg section AddGroup variable [AddGroup R] @[simp] theorem neg_im : (-a).im = -a.im := QuaternionAlgebra.ext neg_zero.symm rfl rfl rfl @[simp, norm_cast] theorem coe_neg : ((-x : R) : ℍ[R,c₁,c₂,c₃]) = -x := by ext <;> simp instance : Sub ℍ[R,c₁,c₂,c₃] := ⟨fun a b => ⟨a.1 - b.1, a.2 - b.2, a.3 - b.3, a.4 - b.4⟩⟩ @[simp] theorem sub_re : (a - b).re = a.re - b.re := rfl @[simp] theorem sub_imI : (a - b).imI = a.imI - b.imI := rfl @[simp] theorem sub_imJ : (a - b).imJ = a.imJ - b.imJ := rfl @[simp] theorem sub_imK : (a - b).imK = a.imK - b.imK := rfl @[simp] theorem sub_im : (a - b).im = a.im - b.im := QuaternionAlgebra.ext (sub_zero _).symm rfl rfl rfl @[simp] theorem mk_sub_mk (a₁ a₂ a₃ a₄ b₁ b₂ b₃ b₄ : R) : (mk a₁ a₂ a₃ a₄ : ℍ[R,c₁,c₂,c₃]) - mk b₁ b₂ b₃ b₄ = mk (a₁ - b₁) (a₂ - b₂) (a₃ - b₃) (a₄ - b₄) := rfl @[simp, norm_cast] theorem coe_im : (x : ℍ[R,c₁,c₂,c₃]).im = 0 := rfl @[simp] theorem re_add_im : ↑a.re + a.im = a := QuaternionAlgebra.ext (add_zero _) (zero_add _) (zero_add _) (zero_add _) @[simp] theorem sub_self_im : a - a.im = a.re := QuaternionAlgebra.ext (sub_zero _) (sub_self _) (sub_self _) (sub_self _) @[simp] theorem sub_self_re : a - a.re = a.im := QuaternionAlgebra.ext (sub_self _) (sub_zero _) (sub_zero _) (sub_zero _) end AddGroup section Ring variable [Ring R] /-- Multiplication is given by * `1 * x = x * 1 = x`; * `i * i = c₁ + c₂ * i`; * `j * j = c₃`; * `i * j = k`, `j * i = c₂ * j - k`; * `k * k = - c₁ * c₃`; * `i * k = c₁ * j + c₂ * k`, `k * i = -c₁ * j`; * `j * k = c₂ * c₃ - c₃ * i`, `k * j = c₃ * i`. -/ instance : Mul ℍ[R,c₁,c₂,c₃] := ⟨fun a b => ⟨a.1 * b.1 + c₁ * a.2 * b.2 + c₃ * a.3 * b.3 + c₂ * c₃ * a.3 * b.4 - c₁ * c₃ * a.4 * b.4, a.1 * b.2 + a.2 * b.1 + c₂ * a.2 * b.2 - c₃ * a.3 * b.4 + c₃ * a.4 * b.3, a.1 * b.3 + c₁ * a.2 * b.4 + a.3 * b.1 + c₂ * a.3 * b.2 - c₁ * a.4 * b.2, a.1 * b.4 + a.2 * b.3 + c₂ * a.2 * b.4 - a.3 * b.2 + a.4 * b.1⟩⟩ @[simp] theorem mul_re : (a * b).re = a.1 * b.1 + c₁ * a.2 * b.2 + c₃ * a.3 * b.3 + c₂ * c₃ * a.3 * b.4 - c₁ * c₃ * a.4 * b.4 := rfl @[simp] theorem mul_imI : (a * b).imI = a.1 * b.2 + a.2 * b.1 + c₂ * a.2 * b.2 - c₃ * a.3 * b.4 + c₃ * a.4 * b.3 := rfl @[simp] theorem mul_imJ : (a * b).imJ = a.1 * b.3 + c₁ * a.2 * b.4 + a.3 * b.1 + c₂ * a.3 * b.2 - c₁ * a.4 * b.2 := rfl @[simp] theorem mul_imK : (a * b).imK = a.1 * b.4 + a.2 * b.3 + c₂ * a.2 * b.4 - a.3 * b.2 + a.4 * b.1 := rfl @[simp] theorem mk_mul_mk (a₁ a₂ a₃ a₄ b₁ b₂ b₃ b₄ : R) : (mk a₁ a₂ a₃ a₄ : ℍ[R,c₁,c₂,c₃]) * mk b₁ b₂ b₃ b₄ = mk (a₁ * b₁ + c₁ * a₂ * b₂ + c₃ * a₃ * b₃ + c₂ * c₃ * a₃ * b₄ - c₁ * c₃ * a₄ * b₄) (a₁ * b₂ + a₂ * b₁ + c₂ * a₂ * b₂ - c₃ * a₃ * b₄ + c₃ * a₄ * b₃) (a₁ * b₃ + c₁ * a₂ * b₄ + a₃ * b₁ + c₂ * a₃ * b₂ - c₁ * a₄ * b₂) (a₁ * b₄ + a₂ * b₃ + c₂ * a₂ * b₄ - a₃ * b₂ + a₄ * b₁) := rfl end Ring section SMul variable [SMul S R] [SMul T R] (s : S) instance : SMul S ℍ[R,c₁,c₂,c₃] where smul s a := ⟨s • a.1, s • a.2, s • a.3, s • a.4⟩ instance [SMul S T] [IsScalarTower S T R] : IsScalarTower S T ℍ[R,c₁,c₂,c₃] where smul_assoc s t x := by ext <;> exact smul_assoc _ _ _ instance [SMulCommClass S T R] : SMulCommClass S T ℍ[R,c₁,c₂,c₃] where smul_comm s t x := by ext <;> exact smul_comm _ _ _ @[simp] theorem smul_re : (s • a).re = s • a.re := rfl @[simp] theorem smul_imI : (s • a).imI = s • a.imI := rfl @[simp] theorem smul_imJ : (s • a).imJ = s • a.imJ := rfl @[simp] theorem smul_imK : (s • a).imK = s • a.imK := rfl @[simp] theorem smul_im {S} [CommRing R] [SMulZeroClass S R] (s : S) : (s • a).im = s • a.im := QuaternionAlgebra.ext (smul_zero s).symm rfl rfl rfl @[simp] theorem smul_mk (re im_i im_j im_k : R) : s • (⟨re, im_i, im_j, im_k⟩ : ℍ[R,c₁,c₂,c₃]) = ⟨s • re, s • im_i, s • im_j, s • im_k⟩ := rfl end SMul @[simp, norm_cast] theorem coe_smul [Zero R] [SMulZeroClass S R] (s : S) (r : R) : (↑(s • r) : ℍ[R,c₁,c₂,c₃]) = s • (r : ℍ[R,c₁,c₂,c₃]) := QuaternionAlgebra.ext rfl (smul_zero _).symm (smul_zero _).symm (smul_zero _).symm instance [AddCommGroup R] : AddCommGroup ℍ[R,c₁,c₂,c₃] := (equivProd c₁ c₂ c₃).injective.addCommGroup _ rfl (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) section AddCommGroupWithOne variable [AddCommGroupWithOne R] instance : AddCommGroupWithOne ℍ[R,c₁,c₂,c₃] where natCast n := ((n : R) : ℍ[R,c₁,c₂,c₃]) natCast_zero := by simp natCast_succ := by simp intCast n := ((n : R) : ℍ[R,c₁,c₂,c₃]) intCast_ofNat _ := congr_arg coe (Int.cast_natCast _) intCast_negSucc n := by change coe _ = -coe _ rw [Int.cast_negSucc, coe_neg] @[simp, norm_cast] theorem natCast_re (n : ℕ) : (n : ℍ[R,c₁,c₂,c₃]).re = n := rfl @[simp, norm_cast] theorem natCast_imI (n : ℕ) : (n : ℍ[R,c₁,c₂,c₃]).imI = 0 := rfl @[simp, norm_cast] theorem natCast_imJ (n : ℕ) : (n : ℍ[R,c₁,c₂,c₃]).imJ = 0 := rfl @[simp, norm_cast] theorem natCast_imK (n : ℕ) : (n : ℍ[R,c₁,c₂,c₃]).imK = 0 := rfl @[simp, norm_cast] theorem natCast_im (n : ℕ) : (n : ℍ[R,c₁,c₂,c₃]).im = 0 := rfl @[norm_cast] theorem coe_natCast (n : ℕ) : ↑(n : R) = (n : ℍ[R,c₁,c₂,c₃]) := rfl @[simp, norm_cast] theorem intCast_re (z : ℤ) : (z : ℍ[R,c₁,c₂,c₃]).re = z := rfl @[scoped simp] theorem ofNat_re (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℍ[R,c₁,c₂,c₃]).re = ofNat(n) := rfl @[scoped simp] theorem ofNat_imI (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℍ[R,c₁,c₂,c₃]).imI = 0 := rfl @[scoped simp] theorem ofNat_imJ (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℍ[R,c₁,c₂,c₃]).imJ = 0 := rfl @[scoped simp] theorem ofNat_imK (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℍ[R,c₁,c₂,c₃]).imK = 0 := rfl @[scoped simp] theorem ofNat_im (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℍ[R,c₁,c₂,c₃]).im = 0 := rfl @[simp, norm_cast] theorem intCast_imI (z : ℤ) : (z : ℍ[R,c₁,c₂,c₃]).imI = 0 := rfl @[simp, norm_cast] theorem intCast_imJ (z : ℤ) : (z : ℍ[R,c₁,c₂,c₃]).imJ = 0 := rfl @[simp, norm_cast] theorem intCast_imK (z : ℤ) : (z : ℍ[R,c₁,c₂,c₃]).imK = 0 := rfl @[simp, norm_cast] theorem intCast_im (z : ℤ) : (z : ℍ[R,c₁,c₂,c₃]).im = 0 := rfl @[norm_cast] theorem coe_intCast (z : ℤ) : ↑(z : R) = (z : ℍ[R,c₁,c₂,c₃]) := rfl end AddCommGroupWithOne -- For the remainder of the file we assume `CommRing R`. variable [CommRing R] instance instRing : Ring ℍ[R,c₁,c₂,c₃] where __ := inferInstanceAs (AddCommGroupWithOne ℍ[R,c₁,c₂,c₃]) left_distrib _ _ _ := by ext <;> simp <;> ring right_distrib _ _ _ := by ext <;> simp <;> ring zero_mul _ := by ext <;> simp mul_zero _ := by ext <;> simp mul_assoc _ _ _ := by ext <;> simp <;> ring one_mul _ := by ext <;> simp mul_one _ := by ext <;> simp @[norm_cast, simp] theorem coe_mul : ((x * y : R) : ℍ[R,c₁,c₂,c₃]) = x * y := by ext <;> simp @[norm_cast, simp] lemma coe_ofNat {n : ℕ} [n.AtLeastTwo]: ((ofNat(n) : R) : ℍ[R,c₁,c₂,c₃]) = (ofNat(n) : ℍ[R,c₁,c₂,c₃]) := by rfl -- TODO: add weaker `MulAction`, `DistribMulAction`, and `Module` instances (and repeat them -- for `ℍ[R]`) instance [CommSemiring S] [Algebra S R] : Algebra S ℍ[R,c₁,c₂,c₃] where smul := (· • ·) algebraMap := { toFun s := coe (algebraMap S R s) map_one' := by simp only [map_one, coe_one] map_zero' := by simp only [map_zero, coe_zero] map_mul' x y := by simp only [map_mul, coe_mul] map_add' x y := by simp only [map_add, coe_add] } smul_def' s x := by ext <;> simp [Algebra.smul_def] commutes' s x := by ext <;> simp [Algebra.commutes] theorem algebraMap_eq (r : R) : algebraMap R ℍ[R,c₁,c₂,c₃] r = ⟨r, 0, 0, 0⟩ := rfl theorem algebraMap_injective : (algebraMap R ℍ[R,c₁,c₂,c₃] : _ → _).Injective := fun _ _ ↦ by simp [algebraMap_eq] instance [NoZeroDivisors R] : NoZeroSMulDivisors R ℍ[R,c₁,c₂,c₃] := ⟨by rintro t ⟨a, b, c, d⟩ h rw [or_iff_not_imp_left] intro ht simpa [QuaternionAlgebra.ext_iff, ht] using h⟩ section variable (c₁ c₂ c₃) /-- `QuaternionAlgebra.re` as a `LinearMap` -/ @[simps] def reₗ : ℍ[R,c₁,c₂,c₃] →ₗ[R] R where toFun := re map_add' _ _ := rfl map_smul' _ _ := rfl /-- `QuaternionAlgebra.imI` as a `LinearMap` -/ @[simps] def imIₗ : ℍ[R,c₁,c₂,c₃] →ₗ[R] R where toFun := imI map_add' _ _ := rfl map_smul' _ _ := rfl /-- `QuaternionAlgebra.imJ` as a `LinearMap` -/ @[simps] def imJₗ : ℍ[R,c₁,c₂,c₃] →ₗ[R] R where toFun := imJ map_add' _ _ := rfl map_smul' _ _ := rfl /-- `QuaternionAlgebra.imK` as a `LinearMap` -/ @[simps] def imKₗ : ℍ[R,c₁,c₂,c₃] →ₗ[R] R where toFun := imK map_add' _ _ := rfl map_smul' _ _ := rfl /-- `QuaternionAlgebra.equivTuple` as a linear equivalence. -/ def linearEquivTuple : ℍ[R,c₁,c₂,c₃] ≃ₗ[R] Fin 4 → R := LinearEquiv.symm -- proofs are not `rfl` in the forward direction { (equivTuple c₁ c₂ c₃).symm with toFun := (equivTuple c₁ c₂ c₃).symm invFun := equivTuple c₁ c₂ c₃ map_add' := fun _ _ => rfl map_smul' := fun _ _ => rfl } @[simp] theorem coe_linearEquivTuple : ⇑(linearEquivTuple c₁ c₂ c₃) = equivTuple c₁ c₂ c₃ := rfl @[simp] theorem coe_linearEquivTuple_symm : ⇑(linearEquivTuple c₁ c₂ c₃).symm = (equivTuple c₁ c₂ c₃).symm := rfl /-- `ℍ[R, c₁, c₂, c₃]` has a basis over `R` given by `1`, `i`, `j`, and `k`. -/ noncomputable def basisOneIJK : Basis (Fin 4) R ℍ[R,c₁,c₂,c₃] := .ofEquivFun <| linearEquivTuple c₁ c₂ c₃ @[simp] theorem coe_basisOneIJK_repr (q : ℍ[R,c₁,c₂,c₃]) : ((basisOneIJK c₁ c₂ c₃).repr q) = ![q.re, q.imI, q.imJ, q.imK] := rfl instance : Module.Finite R ℍ[R,c₁,c₂,c₃] := .of_basis (basisOneIJK c₁ c₂ c₃) instance : Module.Free R ℍ[R,c₁,c₂,c₃] := .of_basis (basisOneIJK c₁ c₂ c₃) theorem rank_eq_four [StrongRankCondition R] : Module.rank R ℍ[R,c₁,c₂,c₃] = 4 := by rw [rank_eq_card_basis (basisOneIJK c₁ c₂ c₃), Fintype.card_fin] norm_num theorem finrank_eq_four [StrongRankCondition R] : Module.finrank R ℍ[R,c₁,c₂,c₃] = 4 := by rw [Module.finrank, rank_eq_four, Cardinal.toNat_ofNat] /-- There is a natural equivalence when swapping the first and third coefficients of a quaternion algebra if `c₂` is 0. -/ @[simps] def swapEquiv : ℍ[R,c₁,0,c₃] ≃ₐ[R] ℍ[R,c₃,0,c₁] where toFun t := ⟨t.1, t.3, t.2, -t.4⟩ invFun t := ⟨t.1, t.3, t.2, -t.4⟩ left_inv _ := by simp right_inv _ := by simp map_mul' _ _ := by ext <;> simp <;> ring map_add' _ _ := by ext <;> simp [add_comm] commutes' _ := by simp [algebraMap_eq] end @[norm_cast, simp] theorem coe_sub : ((x - y : R) : ℍ[R,c₁,c₂,c₃]) = x - y := (algebraMap R ℍ[R,c₁,c₂,c₃]).map_sub x y @[norm_cast, simp] theorem coe_pow (n : ℕ) : (↑(x ^ n) : ℍ[R,c₁,c₂,c₃]) = (x : ℍ[R,c₁,c₂,c₃]) ^ n := (algebraMap R ℍ[R,c₁,c₂,c₃]).map_pow x n theorem coe_commutes : ↑r * a = a * r := Algebra.commutes r a theorem coe_commute : Commute (↑r) a := coe_commutes r a theorem coe_mul_eq_smul : ↑r * a = r • a := (Algebra.smul_def r a).symm theorem mul_coe_eq_smul : a * r = r • a := by rw [← coe_commutes, coe_mul_eq_smul] @[norm_cast, simp] theorem coe_algebraMap : ⇑(algebraMap R ℍ[R,c₁,c₂,c₃]) = coe := rfl theorem smul_coe : x • (y : ℍ[R,c₁,c₂,c₃]) = ↑(x * y) := by rw [coe_mul, coe_mul_eq_smul] /-- Quaternion conjugate. -/ instance instStarQuaternionAlgebra : Star ℍ[R,c₁,c₂,c₃] where star a := ⟨a.1 + c₂ * a.2, -a.2, -a.3, -a.4⟩ @[simp] theorem re_star : (star a).re = a.re + c₂ * a.imI := rfl @[simp] theorem imI_star : (star a).imI = -a.imI := rfl @[simp] theorem imJ_star : (star a).imJ = -a.imJ := rfl @[simp] theorem imK_star : (star a).imK = -a.imK := rfl @[simp] theorem im_star : (star a).im = -a.im := QuaternionAlgebra.ext neg_zero.symm rfl rfl rfl @[simp] theorem star_mk (a₁ a₂ a₃ a₄ : R) : star (mk a₁ a₂ a₃ a₄ : ℍ[R,c₁,c₂,c₃]) = ⟨a₁ + c₂ * a₂, -a₂, -a₃, -a₄⟩ := rfl instance instStarRing : StarRing ℍ[R,c₁,c₂,c₃] where star_involutive x := by simp [Star.star] star_add a b := by ext <;> simp [add_comm] ; ring star_mul a b := by ext <;> simp <;> ring theorem self_add_star' : a + star a = ↑(2 * a.re + c₂ * a.imI) := by ext <;> simp [two_mul]; ring theorem self_add_star : a + star a = 2 * a.re + c₂ * a.imI := by simp [self_add_star'] theorem star_add_self' : star a + a = ↑(2 * a.re + c₂ * a.imI) := by rw [add_comm, self_add_star'] theorem star_add_self : star a + a = 2 * a.re + c₂ * a.imI := by rw [add_comm, self_add_star] theorem star_eq_two_re_sub : star a = ↑(2 * a.re + c₂ * a.imI) - a := eq_sub_iff_add_eq.2 a.star_add_self' lemma comm (r : R) (x : ℍ[R, c₁, c₂, c₃]) : r * x = x * r := by ext <;> simp [mul_comm] instance : IsStarNormal a := ⟨by rw [commute_iff_eq, a.star_eq_two_re_sub]; ext <;> simp <;> ring⟩ @[simp, norm_cast] theorem star_coe : star (x : ℍ[R,c₁,c₂,c₃]) = x := by ext <;> simp @[simp] theorem star_im : star a.im = -a.im + c₂ * a.imI := by ext <;> simp @[simp] theorem star_smul [Monoid S] [DistribMulAction S R] [SMulCommClass S R R] (s : S) (a : ℍ[R,c₁,c₂,c₃]) : star (s • a) = s • star a := QuaternionAlgebra.ext (by simp [mul_smul_comm]) (smul_neg _ _).symm (smul_neg _ _).symm (smul_neg _ _).symm /-- A version of `star_smul` for the special case when `c₂ = 0`, without `SMulCommClass S R R`. -/ theorem star_smul' [Monoid S] [DistribMulAction S R] (s : S) (a : ℍ[R,c₁,0,c₃]) : star (s • a) = s • star a := QuaternionAlgebra.ext (by simp) (smul_neg _ _).symm (smul_neg _ _).symm (smul_neg _ _).symm theorem eq_re_of_eq_coe {a : ℍ[R,c₁,c₂,c₃]} {x : R} (h : a = x) : a = a.re := by rw [h, coe_re] theorem eq_re_iff_mem_range_coe {a : ℍ[R,c₁,c₂,c₃]} : a = a.re ↔ a ∈ Set.range (coe : R → ℍ[R,c₁,c₂,c₃]) := ⟨fun h => ⟨a.re, h.symm⟩, fun ⟨_, h⟩ => eq_re_of_eq_coe h.symm⟩ section CharZero variable [NoZeroDivisors R] [CharZero R] @[simp] theorem star_eq_self {c₁ c₂ : R} {a : ℍ[R,c₁,c₂,c₃]} : star a = a ↔ a = a.re := by simp_all [QuaternionAlgebra.ext_iff, neg_eq_iff_add_eq_zero, add_self_eq_zero] theorem star_eq_neg {c₁ : R} {a : ℍ[R,c₁,0,c₃]} : star a = -a ↔ a.re = 0 := by simp [QuaternionAlgebra.ext_iff, eq_neg_iff_add_eq_zero] end CharZero -- Can't use `rw ← star_eq_self` in the proof without additional assumptions theorem star_mul_eq_coe : star a * a = (star a * a).re := by ext <;> simp <;> ring theorem mul_star_eq_coe : a * star a = (a * star a).re := by rw [← star_comm_self'] exact a.star_mul_eq_coe open MulOpposite /-- Quaternion conjugate as an `AlgEquiv` to the opposite ring. -/ def starAe : ℍ[R,c₁,c₂,c₃] ≃ₐ[R] ℍ[R,c₁,c₂,c₃]ᵐᵒᵖ := { starAddEquiv.trans opAddEquiv with toFun := op ∘ star invFun := star ∘ unop map_mul' := fun x y => by simp commutes' := fun r => by simp } @[simp] theorem coe_starAe : ⇑(starAe : ℍ[R,c₁,c₂,c₃] ≃ₐ[R] _) = op ∘ star := rfl end QuaternionAlgebra /-- Space of quaternions over a type, denoted as `ℍ[R]`. Implemented as a structure with four fields: `re`, `im_i`, `im_j`, and `im_k`. -/ def Quaternion (R : Type*) [Zero R] [One R] [Neg R] := QuaternionAlgebra R (-1) (0) (-1) @[inherit_doc] scoped[Quaternion] notation "ℍ[" R "]" => Quaternion R open Quaternion /-- The equivalence between the quaternions over `R` and `R × R × R × R`. -/ @[simps!] def Quaternion.equivProd (R : Type*) [Zero R] [One R] [Neg R] : ℍ[R] ≃ R × R × R × R := QuaternionAlgebra.equivProd _ _ _ /-- The equivalence between the quaternions over `R` and `Fin 4 → R`. -/ @[simps! symm_apply] def Quaternion.equivTuple (R : Type*) [Zero R] [One R] [Neg R] : ℍ[R] ≃ (Fin 4 → R) := QuaternionAlgebra.equivTuple _ _ _ @[simp] theorem Quaternion.equivTuple_apply (R : Type*) [Zero R] [One R] [Neg R] (x : ℍ[R]) : Quaternion.equivTuple R x = ![x.re, x.imI, x.imJ, x.imK] := rfl instance {R : Type*} [Zero R] [One R] [Neg R] [Subsingleton R] : Subsingleton ℍ[R] := inferInstanceAs (Subsingleton <| ℍ[R, -1, 0, -1]) instance {R : Type*} [Zero R] [One R] [Neg R] [Nontrivial R] : Nontrivial ℍ[R] := inferInstanceAs (Nontrivial <| ℍ[R, -1, 0, -1]) namespace Quaternion variable {S T R : Type*} [CommRing R] (r x y : R) (a b : ℍ[R]) /-- Coercion `R → ℍ[R]`. -/ @[coe] def coe : R → ℍ[R] := QuaternionAlgebra.coe instance : CoeTC R ℍ[R] := ⟨coe⟩ instance instRing : Ring ℍ[R] := QuaternionAlgebra.instRing instance : Inhabited ℍ[R] := inferInstanceAs <| Inhabited ℍ[R,-1, 0, -1] instance [SMul S R] : SMul S ℍ[R] := inferInstanceAs <| SMul S ℍ[R,-1, 0, -1] instance [SMul S T] [SMul S R] [SMul T R] [IsScalarTower S T R] : IsScalarTower S T ℍ[R] := inferInstanceAs <| IsScalarTower S T ℍ[R,-1,0,-1] instance [SMul S R] [SMul T R] [SMulCommClass S T R] : SMulCommClass S T ℍ[R] := inferInstanceAs <| SMulCommClass S T ℍ[R,-1,0,-1] protected instance algebra [CommSemiring S] [Algebra S R] : Algebra S ℍ[R] := inferInstanceAs <| Algebra S ℍ[R,-1,0,-1] instance : Star ℍ[R] := QuaternionAlgebra.instStarQuaternionAlgebra instance : StarRing ℍ[R] := QuaternionAlgebra.instStarRing instance : IsStarNormal a := inferInstanceAs <| IsStarNormal (R := ℍ[R,-1,0,-1]) a @[ext] theorem ext : a.re = b.re → a.imI = b.imI → a.imJ = b.imJ → a.imK = b.imK → a = b := QuaternionAlgebra.ext /-- The imaginary part of a quaternion. -/ nonrec def im (x : ℍ[R]) : ℍ[R] := x.im @[simp] theorem im_re : a.im.re = 0 := rfl @[simp] theorem im_imI : a.im.imI = a.imI := rfl @[simp] theorem im_imJ : a.im.imJ = a.imJ := rfl @[simp] theorem im_imK : a.im.imK = a.imK := rfl @[simp] theorem im_idem : a.im.im = a.im := rfl @[simp] nonrec theorem re_add_im : ↑a.re + a.im = a := a.re_add_im @[simp] nonrec theorem sub_self_im : a - a.im = a.re := a.sub_self_im @[simp] nonrec theorem sub_self_re : a - ↑a.re = a.im := a.sub_self_re @[simp, norm_cast] theorem coe_re : (x : ℍ[R]).re = x := rfl @[simp, norm_cast] theorem coe_imI : (x : ℍ[R]).imI = 0 := rfl @[simp, norm_cast] theorem coe_imJ : (x : ℍ[R]).imJ = 0 := rfl @[simp, norm_cast] theorem coe_imK : (x : ℍ[R]).imK = 0 := rfl @[simp, norm_cast] theorem coe_im : (x : ℍ[R]).im = 0 := rfl @[scoped simp] theorem zero_re : (0 : ℍ[R]).re = 0 := rfl @[scoped simp] theorem zero_imI : (0 : ℍ[R]).imI = 0 := rfl @[scoped simp] theorem zero_imJ : (0 : ℍ[R]).imJ = 0 := rfl @[scoped simp] theorem zero_imK : (0 : ℍ[R]).imK = 0 := rfl @[scoped simp] theorem zero_im : (0 : ℍ[R]).im = 0 := rfl @[simp, norm_cast] theorem coe_zero : ((0 : R) : ℍ[R]) = 0 := rfl @[scoped simp] theorem one_re : (1 : ℍ[R]).re = 1 := rfl @[scoped simp] theorem one_imI : (1 : ℍ[R]).imI = 0 := rfl @[scoped simp] theorem one_imJ : (1 : ℍ[R]).imJ = 0 := rfl @[scoped simp] theorem one_imK : (1 : ℍ[R]).imK = 0 := rfl @[scoped simp] theorem one_im : (1 : ℍ[R]).im = 0 := rfl @[simp, norm_cast] theorem coe_one : ((1 : R) : ℍ[R]) = 1 := rfl @[simp] theorem add_re : (a + b).re = a.re + b.re := rfl @[simp] theorem add_imI : (a + b).imI = a.imI + b.imI := rfl @[simp] theorem add_imJ : (a + b).imJ = a.imJ + b.imJ := rfl @[simp] theorem add_imK : (a + b).imK = a.imK + b.imK := rfl @[simp] nonrec theorem add_im : (a + b).im = a.im + b.im := a.add_im b @[simp, norm_cast] theorem coe_add : ((x + y : R) : ℍ[R]) = x + y := QuaternionAlgebra.coe_add x y @[simp] theorem neg_re : (-a).re = -a.re := rfl @[simp] theorem neg_imI : (-a).imI = -a.imI := rfl @[simp] theorem neg_imJ : (-a).imJ = -a.imJ := rfl @[simp] theorem neg_imK : (-a).imK = -a.imK := rfl @[simp] nonrec theorem neg_im : (-a).im = -a.im := a.neg_im @[simp, norm_cast] theorem coe_neg : ((-x : R) : ℍ[R]) = -x := QuaternionAlgebra.coe_neg x @[simp] theorem sub_re : (a - b).re = a.re - b.re := rfl @[simp] theorem sub_imI : (a - b).imI = a.imI - b.imI := rfl @[simp] theorem sub_imJ : (a - b).imJ = a.imJ - b.imJ := rfl @[simp] theorem sub_imK : (a - b).imK = a.imK - b.imK := rfl @[simp] nonrec theorem sub_im : (a - b).im = a.im - b.im := a.sub_im b @[simp, norm_cast] theorem coe_sub : ((x - y : R) : ℍ[R]) = x - y := QuaternionAlgebra.coe_sub x y @[simp] theorem mul_re : (a * b).re = a.re * b.re - a.imI * b.imI - a.imJ * b.imJ - a.imK * b.imK := (QuaternionAlgebra.mul_re a b).trans <| by simp [one_mul, neg_mul, sub_eq_add_neg, neg_neg] @[simp] theorem mul_imI : (a * b).imI = a.re * b.imI + a.imI * b.re + a.imJ * b.imK - a.imK * b.imJ := (QuaternionAlgebra.mul_imI a b).trans <| by ring @[simp] theorem mul_imJ : (a * b).imJ = a.re * b.imJ - a.imI * b.imK + a.imJ * b.re + a.imK * b.imI := (QuaternionAlgebra.mul_imJ a b).trans <| by ring @[simp] theorem mul_imK : (a * b).imK = a.re * b.imK + a.imI * b.imJ - a.imJ * b.imI + a.imK * b.re := (QuaternionAlgebra.mul_imK a b).trans <| by ring @[simp, norm_cast] theorem coe_mul : ((x * y : R) : ℍ[R]) = x * y := QuaternionAlgebra.coe_mul x y @[norm_cast, simp] theorem coe_pow (n : ℕ) : (↑(x ^ n) : ℍ[R]) = (x : ℍ[R]) ^ n := QuaternionAlgebra.coe_pow x n @[simp, norm_cast] theorem natCast_re (n : ℕ) : (n : ℍ[R]).re = n := rfl @[simp, norm_cast] theorem natCast_imI (n : ℕ) : (n : ℍ[R]).imI = 0 := rfl @[simp, norm_cast] theorem natCast_imJ (n : ℕ) : (n : ℍ[R]).imJ = 0 := rfl @[simp, norm_cast] theorem natCast_imK (n : ℕ) : (n : ℍ[R]).imK = 0 := rfl @[simp, norm_cast] theorem natCast_im (n : ℕ) : (n : ℍ[R]).im = 0 := rfl @[norm_cast] theorem coe_natCast (n : ℕ) : ↑(n : R) = (n : ℍ[R]) := rfl @[simp, norm_cast] theorem intCast_re (z : ℤ) : (z : ℍ[R]).re = z := rfl @[simp, norm_cast] theorem intCast_imI (z : ℤ) : (z : ℍ[R]).imI = 0 := rfl @[simp, norm_cast] theorem intCast_imJ (z : ℤ) : (z : ℍ[R]).imJ = 0 := rfl @[simp, norm_cast] theorem intCast_imK (z : ℤ) : (z : ℍ[R]).imK = 0 := rfl @[simp, norm_cast] theorem intCast_im (z : ℤ) : (z : ℍ[R]).im = 0 := rfl @[norm_cast] theorem coe_intCast (z : ℤ) : ↑(z : R) = (z : ℍ[R]) := rfl theorem coe_injective : Function.Injective (coe : R → ℍ[R]) := QuaternionAlgebra.coe_injective @[simp] theorem coe_inj {x y : R} : (x : ℍ[R]) = y ↔ x = y := coe_injective.eq_iff @[simp] theorem smul_re [SMul S R] (s : S) : (s • a).re = s • a.re := rfl @[simp] theorem smul_imI [SMul S R] (s : S) : (s • a).imI = s • a.imI := rfl @[simp] theorem smul_imJ [SMul S R] (s : S) : (s • a).imJ = s • a.imJ := rfl @[simp] theorem smul_imK [SMul S R] (s : S) : (s • a).imK = s • a.imK := rfl @[simp] nonrec theorem smul_im [SMulZeroClass S R] (s : S) : (s • a).im = s • a.im := a.smul_im s @[simp, norm_cast] theorem coe_smul [SMulZeroClass S R] (s : S) (r : R) : (↑(s • r) : ℍ[R]) = s • (r : ℍ[R]) := QuaternionAlgebra.coe_smul _ _ theorem coe_commutes : ↑r * a = a * r := QuaternionAlgebra.coe_commutes r a theorem coe_commute : Commute (↑r) a := QuaternionAlgebra.coe_commute r a theorem coe_mul_eq_smul : ↑r * a = r • a := QuaternionAlgebra.coe_mul_eq_smul r a theorem mul_coe_eq_smul : a * r = r • a := QuaternionAlgebra.mul_coe_eq_smul r a @[simp] theorem algebraMap_def : ⇑(algebraMap R ℍ[R]) = coe := rfl theorem algebraMap_injective : (algebraMap R ℍ[R] : _ → _).Injective := QuaternionAlgebra.algebraMap_injective theorem smul_coe : x • (y : ℍ[R]) = ↑(x * y) := QuaternionAlgebra.smul_coe x y instance : Module.Finite R ℍ[R] := inferInstanceAs <| Module.Finite R ℍ[R,-1,0,-1] instance : Module.Free R ℍ[R] := inferInstanceAs <| Module.Free R ℍ[R,-1,0,-1] theorem rank_eq_four [StrongRankCondition R] : Module.rank R ℍ[R] = 4 := QuaternionAlgebra.rank_eq_four _ _ _ theorem finrank_eq_four [StrongRankCondition R] : Module.finrank R ℍ[R] = 4 := QuaternionAlgebra.finrank_eq_four _ _ _ @[simp] theorem star_re : (star a).re = a.re := by rw [QuaternionAlgebra.re_star, zero_mul, add_zero] @[simp] theorem star_imI : (star a).imI = -a.imI := rfl @[simp] theorem star_imJ : (star a).imJ = -a.imJ := rfl @[simp] theorem star_imK : (star a).imK = -a.imK := rfl @[simp] theorem star_im : (star a).im = -a.im := a.im_star nonrec theorem self_add_star' : a + star a = ↑(2 * a.re) := by simp [a.self_add_star', Quaternion.coe] nonrec theorem self_add_star : a + star a = 2 * a.re := by simp [a.self_add_star, Quaternion.coe] nonrec theorem star_add_self' : star a + a = ↑(2 * a.re) := by simp [a.star_add_self', Quaternion.coe] nonrec theorem star_add_self : star a + a = 2 * a.re := by simp [a.star_add_self, Quaternion.coe] nonrec theorem star_eq_two_re_sub : star a = ↑(2 * a.re) - a := by simp [a.star_eq_two_re_sub, Quaternion.coe] @[simp, norm_cast] theorem star_coe : star (x : ℍ[R]) = x := QuaternionAlgebra.star_coe x @[simp] theorem im_star : star a.im = -a.im := by ext <;> simp @[simp] theorem star_smul [Monoid S] [DistribMulAction S R] (s : S) (a : ℍ[R]) : star (s • a) = s • star a := QuaternionAlgebra.star_smul' s a theorem eq_re_of_eq_coe {a : ℍ[R]} {x : R} (h : a = x) : a = a.re := QuaternionAlgebra.eq_re_of_eq_coe h theorem eq_re_iff_mem_range_coe {a : ℍ[R]} : a = a.re ↔ a ∈ Set.range (coe : R → ℍ[R]) := QuaternionAlgebra.eq_re_iff_mem_range_coe section CharZero variable [NoZeroDivisors R] [CharZero R] @[simp] theorem star_eq_self {a : ℍ[R]} : star a = a ↔ a = a.re := QuaternionAlgebra.star_eq_self @[simp] theorem star_eq_neg {a : ℍ[R]} : star a = -a ↔ a.re = 0 := QuaternionAlgebra.star_eq_neg end CharZero nonrec theorem star_mul_eq_coe : star a * a = (star a * a).re := a.star_mul_eq_coe nonrec theorem mul_star_eq_coe : a * star a = (a * star a).re := a.mul_star_eq_coe open MulOpposite /-- Quaternion conjugate as an `AlgEquiv` to the opposite ring. -/ def starAe : ℍ[R] ≃ₐ[R] ℍ[R]ᵐᵒᵖ := QuaternionAlgebra.starAe @[simp] theorem coe_starAe : ⇑(starAe : ℍ[R] ≃ₐ[R] ℍ[R]ᵐᵒᵖ) = op ∘ star := rfl /-- Square of the norm. -/ def normSq : ℍ[R] →*₀ R where toFun a := (a * star a).re map_zero' := by simp only [star_zero, zero_mul, zero_re] map_one' := by simp only [star_one, one_mul, one_re] map_mul' x y := coe_injective <| by conv_lhs => rw [← mul_star_eq_coe, star_mul, mul_assoc, ← mul_assoc y, y.mul_star_eq_coe, coe_commutes, ← mul_assoc, x.mul_star_eq_coe, ← coe_mul] theorem normSq_def : normSq a = (a * star a).re := rfl theorem normSq_def' : normSq a = a.1 ^ 2 + a.2 ^ 2 + a.3 ^ 2 + a.4 ^ 2 := by simp only [normSq_def, sq, mul_neg, sub_neg_eq_add, mul_re, star_re, star_imI, star_imJ, star_imK] theorem normSq_coe : normSq (x : ℍ[R]) = x ^ 2 := by rw [normSq_def, star_coe, ← coe_mul, coe_re, sq] @[simp] theorem normSq_star : normSq (star a) = normSq a := by simp [normSq_def'] @[norm_cast] theorem normSq_natCast (n : ℕ) : normSq (n : ℍ[R]) = (n : R) ^ 2 := by rw [← coe_natCast, normSq_coe] @[norm_cast] theorem normSq_intCast (z : ℤ) : normSq (z : ℍ[R]) = (z : R) ^ 2 := by rw [← coe_intCast, normSq_coe] @[simp] theorem normSq_neg : normSq (-a) = normSq a := by simp only [normSq_def, star_neg, neg_mul_neg] theorem self_mul_star : a * star a = normSq a := by rw [mul_star_eq_coe, normSq_def] theorem star_mul_self : star a * a = normSq a := by rw [star_comm_self, self_mul_star] theorem im_sq : a.im ^ 2 = -normSq a.im := by simp_rw [sq, ← star_mul_self, im_star, neg_mul, neg_neg] theorem coe_normSq_add : normSq (a + b) = normSq a + a * star b + b * star a + normSq b := by simp only [star_add, ← self_mul_star, mul_add, add_mul, add_assoc, add_left_comm] theorem normSq_smul (r : R) (q : ℍ[R]) : normSq (r • q) = r ^ 2 * normSq q := by simp only [normSq_def', smul_re, smul_imI, smul_imJ, smul_imK, mul_pow, mul_add, smul_eq_mul] theorem normSq_add (a b : ℍ[R]) : normSq (a + b) = normSq a + normSq b + 2 * (a * star b).re := calc normSq (a + b) = normSq a + (a * star b).re + ((b * star a).re + normSq b) := by simp_rw [normSq_def, star_add, add_mul, mul_add, add_re] _ = normSq a + normSq b + ((a * star b).re + (b * star a).re) := by abel _ = normSq a + normSq b + 2 * (a * star b).re := by rw [← add_re, ← star_mul_star a b, self_add_star', coe_re] end Quaternion namespace Quaternion variable {R : Type*} section LinearOrderedCommRing variable [CommRing R] [LinearOrder R] [IsStrictOrderedRing R] {a : ℍ[R]} @[simp] theorem normSq_eq_zero : normSq a = 0 ↔ a = 0 := by refine ⟨fun h => ?_, fun h => h.symm ▸ normSq.map_zero⟩ rw [normSq_def', add_eq_zero_iff_of_nonneg, add_eq_zero_iff_of_nonneg, add_eq_zero_iff_of_nonneg] at h · exact ext a 0 (pow_eq_zero h.1.1.1) (pow_eq_zero h.1.1.2) (pow_eq_zero h.1.2) (pow_eq_zero h.2) all_goals apply_rules [sq_nonneg, add_nonneg] theorem normSq_ne_zero : normSq a ≠ 0 ↔ a ≠ 0 := normSq_eq_zero.not @[simp] theorem normSq_nonneg : 0 ≤ normSq a := by rw [normSq_def'] apply_rules [sq_nonneg, add_nonneg] @[simp] theorem normSq_le_zero : normSq a ≤ 0 ↔ a = 0 := normSq_nonneg.le_iff_eq.trans normSq_eq_zero instance instNontrivial : Nontrivial ℍ[R] where exists_pair_ne := ⟨0, 1, mt (congr_arg QuaternionAlgebra.re) zero_ne_one⟩ instance : NoZeroDivisors ℍ[R] where eq_zero_or_eq_zero_of_mul_eq_zero {a b} hab := have : normSq a * normSq b = 0 := by rwa [← map_mul, normSq_eq_zero] (eq_zero_or_eq_zero_of_mul_eq_zero this).imp normSq_eq_zero.1 normSq_eq_zero.1 instance : IsDomain ℍ[R] := NoZeroDivisors.to_isDomain _ theorem sq_eq_normSq : a ^ 2 = normSq a ↔ a = a.re := by rw [← star_eq_self, ← star_mul_self, sq, mul_eq_mul_right_iff, eq_comm] exact or_iff_left_of_imp fun ha ↦ ha.symm ▸ star_zero _ theorem sq_eq_neg_normSq : a ^ 2 = -normSq a ↔ a.re = 0 := by simp_rw [← star_eq_neg] obtain rfl | hq0 := eq_or_ne a 0 · simp · rw [← star_mul_self, ← mul_neg, ← neg_sq, sq, mul_left_inj' (neg_ne_zero.mpr hq0), eq_comm] end LinearOrderedCommRing section Field variable [Field R] (a b : ℍ[R]) instance instNNRatCast : NNRatCast ℍ[R] where nnratCast q := (q : R) instance instRatCast : RatCast ℍ[R] where ratCast q := (q : R) @[simp, norm_cast] lemma re_nnratCast (q : ℚ≥0) : (q : ℍ[R]).re = q := rfl @[simp, norm_cast] lemma im_nnratCast (q : ℚ≥0) : (q : ℍ[R]).im = 0 := rfl @[simp, norm_cast] lemma imI_nnratCast (q : ℚ≥0) : (q : ℍ[R]).imI = 0 := rfl @[simp, norm_cast] lemma imJ_nnratCast (q : ℚ≥0) : (q : ℍ[R]).imJ = 0 := rfl @[simp, norm_cast] lemma imK_nnratCast (q : ℚ≥0) : (q : ℍ[R]).imK = 0 := rfl @[simp, norm_cast] lemma ratCast_re (q : ℚ) : (q : ℍ[R]).re = q := rfl @[simp, norm_cast] lemma ratCast_im (q : ℚ) : (q : ℍ[R]).im = 0 := rfl @[simp, norm_cast] lemma ratCast_imI (q : ℚ) : (q : ℍ[R]).imI = 0 := rfl @[simp, norm_cast] lemma ratCast_imJ (q : ℚ) : (q : ℍ[R]).imJ = 0 := rfl @[simp, norm_cast] lemma ratCast_imK (q : ℚ) : (q : ℍ[R]).imK = 0 := rfl @[norm_cast] lemma coe_nnratCast (q : ℚ≥0) : ↑(q : R) = (q : ℍ[R]) := rfl @[norm_cast] lemma coe_ratCast (q : ℚ) : ↑(q : R) = (q : ℍ[R]) := rfl variable [LinearOrder R] [IsStrictOrderedRing R] (a b : ℍ[R]) @[simps -isSimp] instance instInv : Inv ℍ[R] := ⟨fun a => (normSq a)⁻¹ • star a⟩ instance instGroupWithZero : GroupWithZero ℍ[R] := { Quaternion.instNontrivial with inv := Inv.inv inv_zero := by rw [instInv_inv, star_zero, smul_zero] mul_inv_cancel := fun a ha => by rw [instInv_inv, Algebra.mul_smul_comm (normSq a)⁻¹ a (star a), self_mul_star, smul_coe, inv_mul_cancel₀ (normSq_ne_zero.2 ha), coe_one] } @[norm_cast, simp] theorem coe_inv (x : R) : ((x⁻¹ : R) : ℍ[R]) = (↑x)⁻¹ := map_inv₀ (algebraMap R ℍ[R]) _ @[norm_cast, simp] theorem coe_div (x y : R) : ((x / y : R) : ℍ[R]) = x / y := map_div₀ (algebraMap R ℍ[R]) x y @[norm_cast, simp] theorem coe_zpow (x : R) (z : ℤ) : ((x ^ z : R) : ℍ[R]) = (x : ℍ[R]) ^ z := map_zpow₀ (algebraMap R ℍ[R]) x z instance instDivisionRing : DivisionRing ℍ[R] where __ := Quaternion.instRing __ := Quaternion.instGroupWithZero nnqsmul := (· • ·) qsmul := (· • ·) nnratCast_def _ := by rw [← coe_nnratCast, NNRat.cast_def, coe_div, coe_natCast, coe_natCast] ratCast_def _ := by rw [← coe_ratCast, Rat.cast_def, coe_div, coe_intCast, coe_natCast] nnqsmul_def _ _ := by rw [← coe_nnratCast, coe_mul_eq_smul]; ext <;> exact NNRat.smul_def .. qsmul_def _ _ := by rw [← coe_ratCast, coe_mul_eq_smul]; ext <;> exact Rat.smul_def .. theorem normSq_inv : normSq a⁻¹ = (normSq a)⁻¹ := map_inv₀ normSq _ theorem normSq_div : normSq (a / b) = normSq a / normSq b := map_div₀ normSq a b theorem normSq_zpow (z : ℤ) : normSq (a ^ z) = normSq a ^ z := map_zpow₀ normSq a z @[norm_cast] theorem normSq_ratCast (q : ℚ) : normSq (q : ℍ[R]) = (q : ℍ[R]) ^ 2 := by rw [← coe_ratCast, normSq_coe, coe_pow] end Field end Quaternion namespace Cardinal open Quaternion section QuaternionAlgebra variable {R : Type*} (c₁ c₂ c₃ : R) private theorem pow_four [Infinite R] : #R ^ 4 = #R := power_nat_eq (aleph0_le_mk R) <| by decide /-- The cardinality of a quaternion algebra, as a type. -/ theorem mk_quaternionAlgebra : #(ℍ[R,c₁,c₂,c₃]) = #R ^ 4 := by rw [mk_congr (QuaternionAlgebra.equivProd c₁ c₂ c₃)] simp only [mk_prod, lift_id] ring @[simp] theorem mk_quaternionAlgebra_of_infinite [Infinite R] : #(ℍ[R,c₁,c₂,c₃]) = #R := by rw [mk_quaternionAlgebra, pow_four] /-- The cardinality of a quaternion algebra, as a set. -/ theorem mk_univ_quaternionAlgebra : #(Set.univ : Set ℍ[R,c₁,c₂,c₃]) = #R ^ 4 := by rw [mk_univ, mk_quaternionAlgebra] theorem mk_univ_quaternionAlgebra_of_infinite [Infinite R] : #(Set.univ : Set ℍ[R,c₁,c₂,c₃]) = #R := by rw [mk_univ_quaternionAlgebra, pow_four] /-- Show the quaternion ⟨w, x, y, z⟩ as a string "{ re := w, imI := x, imJ := y, imK := z }". For the typical case of quaternions over ℝ, each component will show as a Cauchy sequence due to the way Real numbers are represented. -/ instance [Repr R] {a b c : R} : Repr ℍ[R, a, b, c] where reprPrec q _ := s!"\{ re := {repr q.re}, imI := {repr q.imI}, imJ := {repr q.imJ}, imK := {repr q.imK} }" end QuaternionAlgebra section Quaternion variable (R : Type*) [Zero R] [One R] [Neg R] /-- The cardinality of the quaternions, as a type. -/ @[simp] theorem mk_quaternion : #(ℍ[R]) = #R ^ 4 := mk_quaternionAlgebra _ _ _ theorem mk_quaternion_of_infinite [Infinite R] : #(ℍ[R]) = #R := mk_quaternionAlgebra_of_infinite _ _ _ /-- The cardinality of the quaternions, as a set. -/ theorem mk_univ_quaternion : #(Set.univ : Set ℍ[R]) = #R ^ 4 := mk_univ_quaternionAlgebra _ _ _ theorem mk_univ_quaternion_of_infinite [Infinite R] : #(Set.univ : Set ℍ[R]) = #R := mk_univ_quaternionAlgebra_of_infinite _ _ _ end Quaternion end Cardinal
Mathlib/Algebra/Quaternion.lean
1,351
1,352
/- Copyright (c) 2021 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker, Bhavik Mehta -/ import Mathlib.Analysis.Calculus.Deriv.Support import Mathlib.Analysis.SpecialFunctions.Pow.Deriv import Mathlib.MeasureTheory.Function.Jacobian import Mathlib.MeasureTheory.Integral.IntervalIntegral.IntegrationByParts import Mathlib.MeasureTheory.Measure.Haar.NormedSpace import Mathlib.MeasureTheory.Measure.Haar.Unique /-! # Links between an integral and its "improper" version In its current state, mathlib only knows how to talk about definite ("proper") integrals, in the sense that it treats integrals over `[x, +∞)` the same as it treats integrals over `[y, z]`. For example, the integral over `[1, +∞)` is **not** defined to be the limit of the integral over `[1, x]` as `x` tends to `+∞`, which is known as an **improper integral**. Indeed, the "proper" definition is stronger than the "improper" one. The usual counterexample is `x ↦ sin(x)/x`, which has an improper integral over `[1, +∞)` but no definite integral. Although definite integrals have better properties, they are hardly usable when it comes to computing integrals on unbounded sets, which is much easier using limits. Thus, in this file, we prove various ways of studying the proper integral by studying the improper one. ## Definitions The main definition of this file is `MeasureTheory.AECover`. It is a rather technical definition whose sole purpose is generalizing and factoring proofs. Given an index type `ι`, a countably generated filter `l` over `ι`, and an `ι`-indexed family `φ` of subsets of a measurable space `α` equipped with a measure `μ`, one should think of a hypothesis `hφ : MeasureTheory.AECover μ l φ` as a sufficient condition for being able to interpret `∫ x, f x ∂μ` (if it exists) as the limit of `∫ x in φ i, f x ∂μ` as `i` tends to `l`. When using this definition with a measure restricted to a set `s`, which happens fairly often, one should not try too hard to use a `MeasureTheory.AECover` of subsets of `s`, as it often makes proofs more complicated than necessary. See for example the proof of `MeasureTheory.integrableOn_Iic_of_intervalIntegral_norm_tendsto` where we use `(fun x ↦ oi x)` as a `MeasureTheory.AECover` w.r.t. `μ.restrict (Iic b)`, instead of using `(fun x ↦ Ioc x b)`. ## Main statements - `MeasureTheory.AECover.lintegral_tendsto_of_countably_generated` : if `φ` is a `MeasureTheory.AECover μ l`, where `l` is a countably generated filter, and if `f` is a measurable `ENNReal`-valued function, then `∫⁻ x in φ n, f x ∂μ` tends to `∫⁻ x, f x ∂μ` as `n` tends to `l` - `MeasureTheory.AECover.integrable_of_integral_norm_tendsto` : if `φ` is a `MeasureTheory.AECover μ l`, where `l` is a countably generated filter, if `f` is measurable and integrable on each `φ n`, and if `∫ x in φ n, ‖f x‖ ∂μ` tends to some `I : ℝ` as n tends to `l`, then `f` is integrable - `MeasureTheory.AECover.integral_tendsto_of_countably_generated` : if `φ` is a `MeasureTheory.AECover μ l`, where `l` is a countably generated filter, and if `f` is measurable and integrable (globally), then `∫ x in φ n, f x ∂μ` tends to `∫ x, f x ∂μ` as `n` tends to `+∞`. We then specialize these lemmas to various use cases involving intervals, which are frequent in analysis. In particular, - `MeasureTheory.integral_Ioi_of_hasDerivAt_of_tendsto` is a version of FTC-2 on the interval `(a, +∞)`, giving the formula `∫ x in (a, +∞), g' x = l - g a` if `g'` is integrable and `g` tends to `l` at `+∞`. - `MeasureTheory.integral_Ioi_of_hasDerivAt_of_nonneg` gives the same result assuming that `g'` is nonnegative instead of integrable. Its automatic integrability in this context is proved in `MeasureTheory.integrableOn_Ioi_deriv_of_nonneg`. - `MeasureTheory.integral_comp_smul_deriv_Ioi` is a version of the change of variables formula on semi-infinite intervals. - `MeasureTheory.tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi` shows that a function whose derivative is integrable on `(a, +∞)` has a limit at `+∞`. - `MeasureTheory.tendsto_zero_of_hasDerivAt_of_integrableOn_Ioi` shows that an integrable function whose derivative is integrable on `(a, +∞)` tends to `0` at `+∞`. Versions of these results are also given on the intervals `(-∞, a]` and `(-∞, +∞)`, as well as the corresponding versions of integration by parts. -/ open MeasureTheory Filter Set TopologicalSpace Topology open scoped ENNReal NNReal namespace MeasureTheory section AECover variable {α ι : Type*} [MeasurableSpace α] (μ : Measure α) (l : Filter ι) /-- A sequence `φ` of subsets of `α` is a `MeasureTheory.AECover` w.r.t. a measure `μ` and a filter `l` if almost every point (w.r.t. `μ`) of `α` eventually belongs to `φ n` (w.r.t. `l`), and if each `φ n` is measurable. This definition is a technical way to avoid duplicating a lot of proofs. It should be thought of as a sufficient condition for being able to interpret `∫ x, f x ∂μ` (if it exists) as the limit of `∫ x in φ n, f x ∂μ` as `n` tends to `l`. See for example `MeasureTheory.AECover.lintegral_tendsto_of_countably_generated`, `MeasureTheory.AECover.integrable_of_integral_norm_tendsto` and `MeasureTheory.AECover.integral_tendsto_of_countably_generated`. -/ structure AECover (φ : ι → Set α) : Prop where ae_eventually_mem : ∀ᵐ x ∂μ, ∀ᶠ i in l, x ∈ φ i protected measurableSet : ∀ i, MeasurableSet <| φ i variable {μ} {l} namespace AECover /-! ## Operations on `AECover`s -/ /-- Elementwise intersection of two `AECover`s is an `AECover`. -/ theorem inter {φ ψ : ι → Set α} (hφ : AECover μ l φ) (hψ : AECover μ l ψ) : AECover μ l (fun i ↦ φ i ∩ ψ i) where ae_eventually_mem := hψ.1.mp <| hφ.1.mono fun _ ↦ Eventually.and measurableSet _ := (hφ.2 _).inter (hψ.2 _) theorem superset {φ ψ : ι → Set α} (hφ : AECover μ l φ) (hsub : ∀ i, φ i ⊆ ψ i) (hmeas : ∀ i, MeasurableSet (ψ i)) : AECover μ l ψ := ⟨hφ.1.mono fun _x hx ↦ hx.mono fun i hi ↦ hsub i hi, hmeas⟩ theorem mono_ac {ν : Measure α} {φ : ι → Set α} (hφ : AECover μ l φ) (hle : ν ≪ μ) : AECover ν l φ := ⟨hle hφ.1, hφ.2⟩ theorem mono {ν : Measure α} {φ : ι → Set α} (hφ : AECover μ l φ) (hle : ν ≤ μ) : AECover ν l φ := hφ.mono_ac hle.absolutelyContinuous end AECover section MetricSpace variable [PseudoMetricSpace α] [OpensMeasurableSpace α] theorem aecover_ball {x : α} {r : ι → ℝ} (hr : Tendsto r l atTop) : AECover μ l (fun i ↦ Metric.ball x (r i)) where measurableSet _ := Metric.isOpen_ball.measurableSet ae_eventually_mem := by filter_upwards with y filter_upwards [hr (Ioi_mem_atTop (dist x y))] with a ha using by simpa [dist_comm] using ha theorem aecover_closedBall {x : α} {r : ι → ℝ} (hr : Tendsto r l atTop) : AECover μ l (fun i ↦ Metric.closedBall x (r i)) where measurableSet _ := Metric.isClosed_closedBall.measurableSet ae_eventually_mem := by filter_upwards with y filter_upwards [hr (Ici_mem_atTop (dist x y))] with a ha using by simpa [dist_comm] using ha end MetricSpace section Preorderα variable [Preorder α] [TopologicalSpace α] [OrderClosedTopology α] [OpensMeasurableSpace α] {a b : ι → α} theorem aecover_Ici (ha : Tendsto a l atBot) : AECover μ l fun i => Ici (a i) where ae_eventually_mem := ae_of_all μ ha.eventually_le_atBot measurableSet _ := measurableSet_Ici theorem aecover_Iic (hb : Tendsto b l atTop) : AECover μ l fun i => Iic <| b i := aecover_Ici (α := αᵒᵈ) hb theorem aecover_Icc (ha : Tendsto a l atBot) (hb : Tendsto b l atTop) : AECover μ l fun i => Icc (a i) (b i) := (aecover_Ici ha).inter (aecover_Iic hb) end Preorderα section LinearOrderα variable [LinearOrder α] [TopologicalSpace α] [OrderClosedTopology α] [OpensMeasurableSpace α] {a b : ι → α} (ha : Tendsto a l atBot) (hb : Tendsto b l atTop) include ha in theorem aecover_Ioi [NoMinOrder α] : AECover μ l fun i => Ioi (a i) where ae_eventually_mem := ae_of_all μ ha.eventually_lt_atBot measurableSet _ := measurableSet_Ioi include hb in theorem aecover_Iio [NoMaxOrder α] : AECover μ l fun i => Iio (b i) := aecover_Ioi (α := αᵒᵈ) hb include ha hb theorem aecover_Ioo [NoMinOrder α] [NoMaxOrder α] : AECover μ l fun i => Ioo (a i) (b i) := (aecover_Ioi ha).inter (aecover_Iio hb) theorem aecover_Ioc [NoMinOrder α] : AECover μ l fun i => Ioc (a i) (b i) := (aecover_Ioi ha).inter (aecover_Iic hb) theorem aecover_Ico [NoMaxOrder α] : AECover μ l fun i => Ico (a i) (b i) := (aecover_Ici ha).inter (aecover_Iio hb) end LinearOrderα section FiniteIntervals variable [LinearOrder α] [TopologicalSpace α] [OrderClosedTopology α] [OpensMeasurableSpace α] {a b : ι → α} {A B : α} (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) include ha in theorem aecover_Ioi_of_Ioi : AECover (μ.restrict (Ioi A)) l fun i ↦ Ioi (a i) where ae_eventually_mem := (ae_restrict_mem measurableSet_Ioi).mono fun _x hx ↦ ha.eventually <| eventually_lt_nhds hx measurableSet _ := measurableSet_Ioi include hb in theorem aecover_Iio_of_Iio : AECover (μ.restrict (Iio B)) l fun i ↦ Iio (b i) := aecover_Ioi_of_Ioi (α := αᵒᵈ) hb include ha in theorem aecover_Ioi_of_Ici : AECover (μ.restrict (Ioi A)) l fun i ↦ Ici (a i) := (aecover_Ioi_of_Ioi ha).superset (fun _ ↦ Ioi_subset_Ici_self) fun _ ↦ measurableSet_Ici include hb in theorem aecover_Iio_of_Iic : AECover (μ.restrict (Iio B)) l fun i ↦ Iic (b i) := aecover_Ioi_of_Ici (α := αᵒᵈ) hb include ha hb in theorem aecover_Ioo_of_Ioo : AECover (μ.restrict <| Ioo A B) l fun i => Ioo (a i) (b i) := ((aecover_Ioi_of_Ioi ha).mono <| Measure.restrict_mono Ioo_subset_Ioi_self le_rfl).inter ((aecover_Iio_of_Iio hb).mono <| Measure.restrict_mono Ioo_subset_Iio_self le_rfl) include ha hb in theorem aecover_Ioo_of_Icc : AECover (μ.restrict <| Ioo A B) l fun i => Icc (a i) (b i) := (aecover_Ioo_of_Ioo ha hb).superset (fun _ ↦ Ioo_subset_Icc_self) fun _ ↦ measurableSet_Icc include ha hb in theorem aecover_Ioo_of_Ico : AECover (μ.restrict <| Ioo A B) l fun i => Ico (a i) (b i) := (aecover_Ioo_of_Ioo ha hb).superset (fun _ ↦ Ioo_subset_Ico_self) fun _ ↦ measurableSet_Ico include ha hb in theorem aecover_Ioo_of_Ioc : AECover (μ.restrict <| Ioo A B) l fun i => Ioc (a i) (b i) := (aecover_Ioo_of_Ioo ha hb).superset (fun _ ↦ Ioo_subset_Ioc_self) fun _ ↦ measurableSet_Ioc variable [NoAtoms μ] theorem aecover_Ioc_of_Icc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ioc A B) l fun i => Icc (a i) (b i) := (aecover_Ioo_of_Icc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ioc).ge theorem aecover_Ioc_of_Ico (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ioc A B) l fun i => Ico (a i) (b i) := (aecover_Ioo_of_Ico ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ioc).ge theorem aecover_Ioc_of_Ioc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ioc A B) l fun i => Ioc (a i) (b i) := (aecover_Ioo_of_Ioc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ioc).ge theorem aecover_Ioc_of_Ioo (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ioc A B) l fun i => Ioo (a i) (b i) := (aecover_Ioo_of_Ioo ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ioc).ge theorem aecover_Ico_of_Icc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ico A B) l fun i => Icc (a i) (b i) := (aecover_Ioo_of_Icc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ico).ge theorem aecover_Ico_of_Ico (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ico A B) l fun i => Ico (a i) (b i) := (aecover_Ioo_of_Ico ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ico).ge theorem aecover_Ico_of_Ioc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ico A B) l fun i => Ioc (a i) (b i) := (aecover_Ioo_of_Ioc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ico).ge theorem aecover_Ico_of_Ioo (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ico A B) l fun i => Ioo (a i) (b i) := (aecover_Ioo_of_Ioo ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ico).ge theorem aecover_Icc_of_Icc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Icc A B) l fun i => Icc (a i) (b i) := (aecover_Ioo_of_Icc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Icc).ge theorem aecover_Icc_of_Ico (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Icc A B) l fun i => Ico (a i) (b i) := (aecover_Ioo_of_Ico ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Icc).ge theorem aecover_Icc_of_Ioc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Icc A B) l fun i => Ioc (a i) (b i) := (aecover_Ioo_of_Ioc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Icc).ge theorem aecover_Icc_of_Ioo (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Icc A B) l fun i => Ioo (a i) (b i) := (aecover_Ioo_of_Ioo ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Icc).ge end FiniteIntervals protected theorem AECover.restrict {φ : ι → Set α} (hφ : AECover μ l φ) {s : Set α} : AECover (μ.restrict s) l φ := hφ.mono Measure.restrict_le_self theorem aecover_restrict_of_ae_imp {s : Set α} {φ : ι → Set α} (hs : MeasurableSet s) (ae_eventually_mem : ∀ᵐ x ∂μ, x ∈ s → ∀ᶠ n in l, x ∈ φ n) (measurable : ∀ n, MeasurableSet <| φ n) : AECover (μ.restrict s) l φ where ae_eventually_mem := by rwa [ae_restrict_iff' hs] measurableSet := measurable theorem AECover.inter_restrict {φ : ι → Set α} (hφ : AECover μ l φ) {s : Set α} (hs : MeasurableSet s) : AECover (μ.restrict s) l fun i => φ i ∩ s := aecover_restrict_of_ae_imp hs (hφ.ae_eventually_mem.mono fun _x hx hxs => hx.mono fun _i hi => ⟨hi, hxs⟩) fun i => (hφ.measurableSet i).inter hs theorem AECover.ae_tendsto_indicator {β : Type*} [Zero β] [TopologicalSpace β] (f : α → β) {φ : ι → Set α} (hφ : AECover μ l φ) : ∀ᵐ x ∂μ, Tendsto (fun i => (φ i).indicator f x) l (𝓝 <| f x) := hφ.ae_eventually_mem.mono fun _x hx => tendsto_const_nhds.congr' <| hx.mono fun _n hn => (indicator_of_mem hn _).symm theorem AECover.aemeasurable {β : Type*} [MeasurableSpace β] [l.IsCountablyGenerated] [l.NeBot] {f : α → β} {φ : ι → Set α} (hφ : AECover μ l φ) (hfm : ∀ i, AEMeasurable f (μ.restrict <| φ i)) : AEMeasurable f μ := by obtain ⟨u, hu⟩ := l.exists_seq_tendsto have := aemeasurable_iUnion_iff.mpr fun n : ℕ => hfm (u n) rwa [Measure.restrict_eq_self_of_ae_mem] at this filter_upwards [hφ.ae_eventually_mem] with x hx using mem_iUnion.mpr (hu.eventually hx).exists theorem AECover.aestronglyMeasurable {β : Type*} [TopologicalSpace β] [PseudoMetrizableSpace β] [l.IsCountablyGenerated] [l.NeBot] {f : α → β} {φ : ι → Set α} (hφ : AECover μ l φ) (hfm : ∀ i, AEStronglyMeasurable f (μ.restrict <| φ i)) : AEStronglyMeasurable f μ := by obtain ⟨u, hu⟩ := l.exists_seq_tendsto have := aestronglyMeasurable_iUnion_iff.mpr fun n : ℕ => hfm (u n) rwa [Measure.restrict_eq_self_of_ae_mem] at this filter_upwards [hφ.ae_eventually_mem] with x hx using mem_iUnion.mpr (hu.eventually hx).exists end AECover theorem AECover.comp_tendsto {α ι ι' : Type*} [MeasurableSpace α] {μ : Measure α} {l : Filter ι} {l' : Filter ι'} {φ : ι → Set α} (hφ : AECover μ l φ) {u : ι' → ι} (hu : Tendsto u l' l) : AECover μ l' (φ ∘ u) where ae_eventually_mem := hφ.ae_eventually_mem.mono fun _x hx => hu.eventually hx measurableSet i := hφ.measurableSet (u i) section AECoverUnionInterCountable variable {α ι : Type*} [Countable ι] [MeasurableSpace α] {μ : Measure α} theorem AECover.biUnion_Iic_aecover [Preorder ι] {φ : ι → Set α} (hφ : AECover μ atTop φ) : AECover μ atTop fun n : ι => ⋃ (k) (_h : k ∈ Iic n), φ k := hφ.superset (fun _ ↦ subset_biUnion_of_mem right_mem_Iic) fun _ ↦ .biUnion (to_countable _) fun _ _ ↦ (hφ.2 _) theorem AECover.biInter_Ici_aecover [Preorder ι] {φ : ι → Set α} (hφ : AECover μ atTop φ) : AECover μ atTop fun n : ι => ⋂ (k) (_h : k ∈ Ici n), φ k where ae_eventually_mem := hφ.ae_eventually_mem.mono fun x h ↦ by simpa only [mem_iInter, mem_Ici, eventually_forall_ge_atTop] measurableSet _ := .biInter (to_countable _) fun n _ => hφ.measurableSet n end AECoverUnionInterCountable section Lintegral variable {α ι : Type*} [MeasurableSpace α] {μ : Measure α} {l : Filter ι} private theorem lintegral_tendsto_of_monotone_of_nat {φ : ℕ → Set α} (hφ : AECover μ atTop φ) (hmono : Monotone φ) {f : α → ℝ≥0∞} (hfm : AEMeasurable f μ) : Tendsto (fun i => ∫⁻ x in φ i, f x ∂μ) atTop (𝓝 <| ∫⁻ x, f x ∂μ) := let F n := (φ n).indicator f have key₁ : ∀ n, AEMeasurable (F n) μ := fun n => hfm.indicator (hφ.measurableSet n) have key₂ : ∀ᵐ x : α ∂μ, Monotone fun n => F n x := ae_of_all _ fun x _i _j hij => indicator_le_indicator_of_subset (hmono hij) (fun x => zero_le <| f x) x have key₃ : ∀ᵐ x : α ∂μ, Tendsto (fun n => F n x) atTop (𝓝 (f x)) := hφ.ae_tendsto_indicator f (lintegral_tendsto_of_tendsto_of_monotone key₁ key₂ key₃).congr fun n => lintegral_indicator (hφ.measurableSet n) _ theorem AECover.lintegral_tendsto_of_nat {φ : ℕ → Set α} (hφ : AECover μ atTop φ) {f : α → ℝ≥0∞} (hfm : AEMeasurable f μ) : Tendsto (∫⁻ x in φ ·, f x ∂μ) atTop (𝓝 <| ∫⁻ x, f x ∂μ) := by have lim₁ := lintegral_tendsto_of_monotone_of_nat hφ.biInter_Ici_aecover (fun i j hij => biInter_subset_biInter_left (Ici_subset_Ici.mpr hij)) hfm have lim₂ := lintegral_tendsto_of_monotone_of_nat hφ.biUnion_Iic_aecover (fun i j hij => biUnion_subset_biUnion_left (Iic_subset_Iic.mpr hij)) hfm refine tendsto_of_tendsto_of_tendsto_of_le_of_le lim₁ lim₂ (fun n ↦ ?_) fun n ↦ ?_ exacts [lintegral_mono_set (biInter_subset_of_mem left_mem_Ici), lintegral_mono_set (subset_biUnion_of_mem right_mem_Iic)] theorem AECover.lintegral_tendsto_of_countably_generated [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ≥0∞} (hfm : AEMeasurable f μ) : Tendsto (fun i => ∫⁻ x in φ i, f x ∂μ) l (𝓝 <| ∫⁻ x, f x ∂μ) := tendsto_of_seq_tendsto fun _u hu => (hφ.comp_tendsto hu).lintegral_tendsto_of_nat hfm theorem AECover.lintegral_eq_of_tendsto [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ≥0∞} (I : ℝ≥0∞) (hfm : AEMeasurable f μ) (htendsto : Tendsto (fun i => ∫⁻ x in φ i, f x ∂μ) l (𝓝 I)) : ∫⁻ x, f x ∂μ = I := tendsto_nhds_unique (hφ.lintegral_tendsto_of_countably_generated hfm) htendsto theorem AECover.iSup_lintegral_eq_of_countably_generated [Nonempty ι] [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ≥0∞} (hfm : AEMeasurable f μ) : ⨆ i : ι, ∫⁻ x in φ i, f x ∂μ = ∫⁻ x, f x ∂μ := by have := hφ.lintegral_tendsto_of_countably_generated hfm refine ciSup_eq_of_forall_le_of_forall_lt_exists_gt (fun i => lintegral_mono' Measure.restrict_le_self le_rfl) fun w hw => ?_ exact (this.eventually_const_lt hw).exists end Lintegral section Integrable variable {α ι E : Type*} [MeasurableSpace α] {μ : Measure α} {l : Filter ι} [NormedAddCommGroup E] theorem AECover.integrable_of_lintegral_enorm_bounded [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ) (hfm : AEStronglyMeasurable f μ) (hbounded : ∀ᶠ i in l, ∫⁻ x in φ i, ‖f x‖ₑ ∂μ ≤ ENNReal.ofReal I) : Integrable f μ := by refine ⟨hfm, (le_of_tendsto ?_ hbounded).trans_lt ENNReal.ofReal_lt_top⟩ exact hφ.lintegral_tendsto_of_countably_generated hfm.enorm @[deprecated (since := "2025-01-22")] alias AECover.integrable_of_lintegral_nnnorm_bounded := AECover.integrable_of_lintegral_enorm_bounded theorem AECover.integrable_of_lintegral_enorm_tendsto [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ) (hfm : AEStronglyMeasurable f μ) (htendsto : Tendsto (fun i => ∫⁻ x in φ i, ‖f x‖ₑ ∂μ) l (𝓝 <| .ofReal I)) : Integrable f μ := by refine hφ.integrable_of_lintegral_enorm_bounded (max 1 (I + 1)) hfm ?_ refine htendsto.eventually (ge_mem_nhds ?_) refine (ENNReal.ofReal_lt_ofReal_iff (lt_max_of_lt_left zero_lt_one)).2 ?_ exact lt_max_of_lt_right (lt_add_one I) @[deprecated (since := "2025-01-22")] alias AECover.integrable_of_lintegral_nnnorm_tendsto := AECover.integrable_of_lintegral_enorm_tendsto theorem AECover.integrable_of_lintegral_enorm_bounded' [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ≥0) (hfm : AEStronglyMeasurable f μ) (hbounded : ∀ᶠ i in l, ∫⁻ x in φ i, ‖f x‖ₑ ∂μ ≤ I) : Integrable f μ := hφ.integrable_of_lintegral_enorm_bounded I hfm (by simpa only [ENNReal.ofReal_coe_nnreal] using hbounded) @[deprecated (since := "2025-01-22")] alias AECover.integrable_of_lintegral_nnnorm_bounded' := AECover.integrable_of_lintegral_enorm_bounded' theorem AECover.integrable_of_lintegral_enorm_tendsto' [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ≥0) (hfm : AEStronglyMeasurable f μ) (htendsto : Tendsto (fun i => ∫⁻ x in φ i, ‖f x‖ₑ ∂μ) l (𝓝 I)) : Integrable f μ := hφ.integrable_of_lintegral_enorm_tendsto I hfm (by simpa only [ENNReal.ofReal_coe_nnreal] using htendsto) @[deprecated (since := "2025-01-22")] alias AECover.integrable_of_lintegral_nnnorm_tendsto' := AECover.integrable_of_lintegral_enorm_tendsto' theorem AECover.integrable_of_integral_norm_bounded [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ) (hfi : ∀ i, IntegrableOn f (φ i) μ) (hbounded : ∀ᶠ i in l, (∫ x in φ i, ‖f x‖ ∂μ) ≤ I) : Integrable f μ := by have hfm : AEStronglyMeasurable f μ := hφ.aestronglyMeasurable fun i => (hfi i).aestronglyMeasurable refine hφ.integrable_of_lintegral_enorm_bounded I hfm ?_ conv at hbounded in integral _ _ => rw [integral_eq_lintegral_of_nonneg_ae (ae_of_all _ fun x => @norm_nonneg E _ (f x)) hfm.norm.restrict] conv at hbounded in ENNReal.ofReal _ => rw [← coe_nnnorm, ENNReal.ofReal_coe_nnreal] refine hbounded.mono fun i hi => ?_ rw [← ENNReal.ofReal_toReal <| ne_top_of_lt <| hasFiniteIntegral_iff_enorm.mp (hfi i).2] apply ENNReal.ofReal_le_ofReal hi theorem AECover.integrable_of_integral_norm_tendsto [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ) (hfi : ∀ i, IntegrableOn f (φ i) μ) (htendsto : Tendsto (fun i => ∫ x in φ i, ‖f x‖ ∂μ) l (𝓝 I)) : Integrable f μ := let ⟨I', hI'⟩ := htendsto.isBoundedUnder_le hφ.integrable_of_integral_norm_bounded I' hfi hI' theorem AECover.integrable_of_integral_bounded_of_nonneg_ae [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ} (I : ℝ) (hfi : ∀ i, IntegrableOn f (φ i) μ) (hnng : ∀ᵐ x ∂μ, 0 ≤ f x) (hbounded : ∀ᶠ i in l, (∫ x in φ i, f x ∂μ) ≤ I) : Integrable f μ := hφ.integrable_of_integral_norm_bounded I hfi <| hbounded.mono fun _i hi => (integral_congr_ae <| ae_restrict_of_ae <| hnng.mono fun _ => Real.norm_of_nonneg).le.trans hi theorem AECover.integrable_of_integral_tendsto_of_nonneg_ae [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ} (I : ℝ) (hfi : ∀ i, IntegrableOn f (φ i) μ) (hnng : ∀ᵐ x ∂μ, 0 ≤ f x) (htendsto : Tendsto (fun i => ∫ x in φ i, f x ∂μ) l (𝓝 I)) : Integrable f μ := let ⟨I', hI'⟩ := htendsto.isBoundedUnder_le hφ.integrable_of_integral_bounded_of_nonneg_ae I' hfi hnng hI' end Integrable section Integral variable {α ι E : Type*} [MeasurableSpace α] {μ : Measure α} {l : Filter ι} [NormedAddCommGroup E] [NormedSpace ℝ E] theorem AECover.integral_tendsto_of_countably_generated [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (hfi : Integrable f μ) : Tendsto (fun i => ∫ x in φ i, f x ∂μ) l (𝓝 <| ∫ x, f x ∂μ) := suffices h : Tendsto (fun i => ∫ x : α, (φ i).indicator f x ∂μ) l (𝓝 (∫ x : α, f x ∂μ)) from by convert h using 2; rw [integral_indicator (hφ.measurableSet _)] tendsto_integral_filter_of_dominated_convergence (fun x => ‖f x‖) (Eventually.of_forall fun i => hfi.aestronglyMeasurable.indicator <| hφ.measurableSet i) (Eventually.of_forall fun _ => ae_of_all _ fun _ => norm_indicator_le_norm_self _ _) hfi.norm (hφ.ae_tendsto_indicator f) /-- Slight reformulation of `MeasureTheory.AECover.integral_tendsto_of_countably_generated`. -/ theorem AECover.integral_eq_of_tendsto [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : E) (hfi : Integrable f μ) (h : Tendsto (fun n => ∫ x in φ n, f x ∂μ) l (𝓝 I)) : ∫ x, f x ∂μ = I := tendsto_nhds_unique (hφ.integral_tendsto_of_countably_generated hfi) h theorem AECover.integral_eq_of_tendsto_of_nonneg_ae [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ} (I : ℝ) (hnng : 0 ≤ᵐ[μ] f) (hfi : ∀ n, IntegrableOn f (φ n) μ) (htendsto : Tendsto (fun n => ∫ x in φ n, f x ∂μ) l (𝓝 I)) : ∫ x, f x ∂μ = I := have hfi' : Integrable f μ := hφ.integrable_of_integral_tendsto_of_nonneg_ae I hfi hnng htendsto hφ.integral_eq_of_tendsto I hfi' htendsto end Integral section IntegrableOfIntervalIntegral variable {ι E : Type*} {μ : Measure ℝ} {l : Filter ι} [Filter.NeBot l] [IsCountablyGenerated l] [NormedAddCommGroup E] {a b : ι → ℝ} {f : ℝ → E} theorem integrable_of_intervalIntegral_norm_bounded (I : ℝ) (hfi : ∀ i, IntegrableOn f (Ioc (a i) (b i)) μ) (ha : Tendsto a l atBot) (hb : Tendsto b l atTop) (h : ∀ᶠ i in l, (∫ x in a i..b i, ‖f x‖ ∂μ) ≤ I) : Integrable f μ := by have hφ : AECover μ l _ := aecover_Ioc ha hb refine hφ.integrable_of_integral_norm_bounded I hfi (h.mp ?_) filter_upwards [ha.eventually (eventually_le_atBot 0), hb.eventually (eventually_ge_atTop 0)] with i hai hbi ht rwa [← intervalIntegral.integral_of_le (hai.trans hbi)] /-- If `f` is integrable on intervals `Ioc (a i) (b i)`, where `a i` tends to -∞ and `b i` tends to ∞, and `∫ x in a i .. b i, ‖f x‖ ∂μ` converges to `I : ℝ` along a filter `l`, then `f` is integrable on the interval (-∞, ∞) -/ theorem integrable_of_intervalIntegral_norm_tendsto (I : ℝ) (hfi : ∀ i, IntegrableOn f (Ioc (a i) (b i)) μ) (ha : Tendsto a l atBot) (hb : Tendsto b l atTop) (h : Tendsto (fun i => ∫ x in a i..b i, ‖f x‖ ∂μ) l (𝓝 I)) : Integrable f μ := let ⟨I', hI'⟩ := h.isBoundedUnder_le integrable_of_intervalIntegral_norm_bounded I' hfi ha hb hI' theorem integrableOn_Iic_of_intervalIntegral_norm_bounded (I b : ℝ) (hfi : ∀ i, IntegrableOn f (Ioc (a i) b) μ) (ha : Tendsto a l atBot) (h : ∀ᶠ i in l, (∫ x in a i..b, ‖f x‖ ∂μ) ≤ I) : IntegrableOn f (Iic b) μ := by have hφ : AECover (μ.restrict <| Iic b) l _ := aecover_Ioi ha have hfi : ∀ i, IntegrableOn f (Ioi (a i)) (μ.restrict <| Iic b) := by intro i rw [IntegrableOn, Measure.restrict_restrict (hφ.measurableSet i)] exact hfi i refine hφ.integrable_of_integral_norm_bounded I hfi (h.mp ?_) filter_upwards [ha.eventually (eventually_le_atBot b)] with i hai rw [intervalIntegral.integral_of_le hai, Measure.restrict_restrict (hφ.measurableSet i)] exact id /-- If `f` is integrable on intervals `Ioc (a i) b`, where `a i` tends to -∞, and `∫ x in a i .. b, ‖f x‖ ∂μ` converges to `I : ℝ` along a filter `l`, then `f` is integrable on the interval (-∞, b) -/ theorem integrableOn_Iic_of_intervalIntegral_norm_tendsto (I b : ℝ) (hfi : ∀ i, IntegrableOn f (Ioc (a i) b) μ) (ha : Tendsto a l atBot) (h : Tendsto (fun i => ∫ x in a i..b, ‖f x‖ ∂μ) l (𝓝 I)) : IntegrableOn f (Iic b) μ := let ⟨I', hI'⟩ := h.isBoundedUnder_le integrableOn_Iic_of_intervalIntegral_norm_bounded I' b hfi ha hI' theorem integrableOn_Ioi_of_intervalIntegral_norm_bounded (I a : ℝ) (hfi : ∀ i, IntegrableOn f (Ioc a (b i)) μ) (hb : Tendsto b l atTop) (h : ∀ᶠ i in l, (∫ x in a..b i, ‖f x‖ ∂μ) ≤ I) : IntegrableOn f (Ioi a) μ := by have hφ : AECover (μ.restrict <| Ioi a) l _ := aecover_Iic hb have hfi : ∀ i, IntegrableOn f (Iic (b i)) (μ.restrict <| Ioi a) := by intro i rw [IntegrableOn, Measure.restrict_restrict (hφ.measurableSet i), inter_comm] exact hfi i refine hφ.integrable_of_integral_norm_bounded I hfi (h.mp ?_) filter_upwards [hb.eventually (eventually_ge_atTop a)] with i hbi rw [intervalIntegral.integral_of_le hbi, Measure.restrict_restrict (hφ.measurableSet i), inter_comm] exact id /-- If `f` is integrable on intervals `Ioc a (b i)`, where `b i` tends to ∞, and `∫ x in a .. b i, ‖f x‖ ∂μ` converges to `I : ℝ` along a filter `l`, then `f` is integrable on the interval (a, ∞) -/ theorem integrableOn_Ioi_of_intervalIntegral_norm_tendsto (I a : ℝ) (hfi : ∀ i, IntegrableOn f (Ioc a (b i)) μ) (hb : Tendsto b l atTop) (h : Tendsto (fun i => ∫ x in a..b i, ‖f x‖ ∂μ) l (𝓝 <| I)) : IntegrableOn f (Ioi a) μ := let ⟨I', hI'⟩ := h.isBoundedUnder_le integrableOn_Ioi_of_intervalIntegral_norm_bounded I' a hfi hb hI' theorem integrableOn_Ioc_of_intervalIntegral_norm_bounded {I a₀ b₀ : ℝ} (hfi : ∀ i, IntegrableOn f <| Ioc (a i) (b i)) (ha : Tendsto a l <| 𝓝 a₀) (hb : Tendsto b l <| 𝓝 b₀) (h : ∀ᶠ i in l, (∫ x in Ioc (a i) (b i), ‖f x‖) ≤ I) : IntegrableOn f (Ioc a₀ b₀) := by refine (aecover_Ioc_of_Ioc ha hb).integrable_of_integral_norm_bounded I (fun i => (hfi i).restrict) (h.mono fun i hi ↦ ?_) rw [Measure.restrict_restrict measurableSet_Ioc] refine le_trans (setIntegral_mono_set (hfi i).norm ?_ ?_) hi <;> apply ae_of_all · simp only [Pi.zero_apply, norm_nonneg, forall_const] · intro c hc; exact hc.1 theorem integrableOn_Ioc_of_intervalIntegral_norm_bounded_left {I a₀ b : ℝ} (hfi : ∀ i, IntegrableOn f <| Ioc (a i) b) (ha : Tendsto a l <| 𝓝 a₀) (h : ∀ᶠ i in l, (∫ x in Ioc (a i) b, ‖f x‖) ≤ I) : IntegrableOn f (Ioc a₀ b) := integrableOn_Ioc_of_intervalIntegral_norm_bounded hfi ha tendsto_const_nhds h theorem integrableOn_Ioc_of_intervalIntegral_norm_bounded_right {I a b₀ : ℝ} (hfi : ∀ i, IntegrableOn f <| Ioc a (b i)) (hb : Tendsto b l <| 𝓝 b₀) (h : ∀ᶠ i in l, (∫ x in Ioc a (b i), ‖f x‖) ≤ I) : IntegrableOn f (Ioc a b₀) := integrableOn_Ioc_of_intervalIntegral_norm_bounded hfi tendsto_const_nhds hb h end IntegrableOfIntervalIntegral section IntegralOfIntervalIntegral variable {ι E : Type*} {μ : Measure ℝ} {l : Filter ι} [IsCountablyGenerated l] [NormedAddCommGroup E] [NormedSpace ℝ E] {a b : ι → ℝ} {f : ℝ → E} theorem intervalIntegral_tendsto_integral (hfi : Integrable f μ) (ha : Tendsto a l atBot) (hb : Tendsto b l atTop) : Tendsto (fun i => ∫ x in a i..b i, f x ∂μ) l (𝓝 <| ∫ x, f x ∂μ) := by let φ i := Ioc (a i) (b i) have hφ : AECover μ l φ := aecover_Ioc ha hb refine (hφ.integral_tendsto_of_countably_generated hfi).congr' ?_ filter_upwards [ha.eventually (eventually_le_atBot 0), hb.eventually (eventually_ge_atTop 0)] with i hai hbi exact (intervalIntegral.integral_of_le (hai.trans hbi)).symm theorem intervalIntegral_tendsto_integral_Iic (b : ℝ) (hfi : IntegrableOn f (Iic b) μ) (ha : Tendsto a l atBot) : Tendsto (fun i => ∫ x in a i..b, f x ∂μ) l (𝓝 <| ∫ x in Iic b, f x ∂μ) := by let φ i := Ioi (a i) have hφ : AECover (μ.restrict <| Iic b) l φ := aecover_Ioi ha refine (hφ.integral_tendsto_of_countably_generated hfi).congr' ?_ filter_upwards [ha.eventually (eventually_le_atBot <| b)] with i hai rw [intervalIntegral.integral_of_le hai, Measure.restrict_restrict (hφ.measurableSet i)] rfl theorem intervalIntegral_tendsto_integral_Ioi (a : ℝ) (hfi : IntegrableOn f (Ioi a) μ) (hb : Tendsto b l atTop) : Tendsto (fun i => ∫ x in a..b i, f x ∂μ) l (𝓝 <| ∫ x in Ioi a, f x ∂μ) := by let φ i := Iic (b i) have hφ : AECover (μ.restrict <| Ioi a) l φ := aecover_Iic hb refine (hφ.integral_tendsto_of_countably_generated hfi).congr' ?_ filter_upwards [hb.eventually (eventually_ge_atTop <| a)] with i hbi rw [intervalIntegral.integral_of_le hbi, Measure.restrict_restrict (hφ.measurableSet i), inter_comm] rfl end IntegralOfIntervalIntegral open Real open scoped Interval section IoiFTC variable {E : Type*} {f f' : ℝ → E} {g g' : ℝ → ℝ} {a l : ℝ} {m : E} [NormedAddCommGroup E] [NormedSpace ℝ E] /-- If the derivative of a function defined on the real line is integrable close to `+∞`, then the function has a limit at `+∞`. -/ theorem tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi [CompleteSpace E] (hderiv : ∀ x ∈ Ioi a, HasDerivAt f (f' x) x) (f'int : IntegrableOn f' (Ioi a)) : Tendsto f atTop (𝓝 (limUnder atTop f)) := by suffices ∃ a, Tendsto f atTop (𝓝 a) from tendsto_nhds_limUnder this suffices CauchySeq f from cauchySeq_tendsto_of_complete this apply Metric.cauchySeq_iff'.2 (fun ε εpos ↦ ?_) have A : ∀ᶠ (n : ℕ) in atTop, ∫ (x : ℝ) in Ici ↑n, ‖f' x‖ < ε := by have L : Tendsto (fun (n : ℕ) ↦ ∫ x in Ici (n : ℝ), ‖f' x‖) atTop (𝓝 (∫ x in ⋂ (n : ℕ), Ici (n : ℝ), ‖f' x‖)) := by apply tendsto_setIntegral_of_antitone (fun n ↦ measurableSet_Ici) · intro m n hmn exact Ici_subset_Ici.2 (Nat.cast_le.mpr hmn) · rcases exists_nat_gt a with ⟨n, hn⟩ exact ⟨n, IntegrableOn.mono_set f'int.norm (Ici_subset_Ioi.2 hn)⟩ have B : ⋂ (n : ℕ), Ici (n : ℝ) = ∅ := by apply eq_empty_of_forall_not_mem (fun x ↦ ?_) simpa only [mem_iInter, mem_Ici, not_forall, not_le] using exists_nat_gt x simp only [B, Measure.restrict_empty, integral_zero_measure] at L exact (tendsto_order.1 L).2 _ εpos have B : ∀ᶠ (n : ℕ) in atTop, a < n := by rcases exists_nat_gt a with ⟨n, hn⟩ filter_upwards [Ioi_mem_atTop n] with m (hm : n < m) using hn.trans (Nat.cast_lt.mpr hm) rcases (A.and B).exists with ⟨N, hN, h'N⟩ refine ⟨N, fun x hx ↦ ?_⟩ calc dist (f x) (f ↑N) = ‖f x - f N‖ := dist_eq_norm _ _ _ = ‖∫ t in Ioc ↑N x, f' t‖ := by rw [← intervalIntegral.integral_of_le hx, intervalIntegral.integral_eq_sub_of_hasDerivAt] · intro y hy simp only [hx, uIcc_of_le, mem_Icc] at hy exact hderiv _ (h'N.trans_le hy.1) · rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hx] exact f'int.mono_set (Ioc_subset_Ioi_self.trans (Ioi_subset_Ioi h'N.le)) _ ≤ ∫ t in Ioc ↑N x, ‖f' t‖ := norm_integral_le_integral_norm fun a ↦ f' a _ ≤ ∫ t in Ici ↑N, ‖f' t‖ := by apply setIntegral_mono_set · apply IntegrableOn.mono_set f'int.norm (Ici_subset_Ioi.2 h'N) · filter_upwards with x using norm_nonneg _ · have : Ioc (↑N) x ⊆ Ici ↑N := Ioc_subset_Ioi_self.trans Ioi_subset_Ici_self exact this.eventuallyLE _ < ε := hN open UniformSpace in /-- If a function and its derivative are integrable on `(a, +∞)`, then the function tends to zero at `+∞`. -/ theorem tendsto_zero_of_hasDerivAt_of_integrableOn_Ioi (hderiv : ∀ x ∈ Ioi a, HasDerivAt f (f' x) x) (f'int : IntegrableOn f' (Ioi a)) (fint : IntegrableOn f (Ioi a)) : Tendsto f atTop (𝓝 0) := by let F : E →L[ℝ] Completion E := Completion.toComplL have Fderiv : ∀ x ∈ Ioi a, HasDerivAt (F ∘ f) (F (f' x)) x := fun x hx ↦ F.hasFDerivAt.comp_hasDerivAt _ (hderiv x hx)
have Fint : IntegrableOn (F ∘ f) (Ioi a) := by apply F.integrable_comp fint have F'int : IntegrableOn (F ∘ f') (Ioi a) := by apply F.integrable_comp f'int have A : Tendsto (F ∘ f) atTop (𝓝 (limUnder atTop (F ∘ f))) := by apply tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi Fderiv F'int have B : limUnder atTop (F ∘ f) = F 0 := by have : IntegrableAtFilter (F ∘ f) atTop := by exact ⟨Ioi a, Ioi_mem_atTop _, Fint⟩ apply IntegrableAtFilter.eq_zero_of_tendsto this ?_ A intro s hs rcases mem_atTop_sets.1 hs with ⟨b, hb⟩ rw [← top_le_iff, ← volume_Ici (a := b)] exact measure_mono hb rwa [B, ← IsEmbedding.tendsto_nhds_iff] at A exact (Completion.isUniformEmbedding_coe E).isEmbedding variable [CompleteSpace E] /-- **Fundamental theorem of calculus-2**, on semi-infinite intervals `(a, +∞)`. When a function has a limit at infinity `m`, and its derivative is integrable, then the integral of the derivative on `(a, +∞)` is `m - f a`. Version assuming differentiability on `(a, +∞)` and continuity at `a⁺`. Note that such a function always has a limit at infinity, see `tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi`. -/ theorem integral_Ioi_of_hasDerivAt_of_tendsto (hcont : ContinuousWithinAt f (Ici a) a) (hderiv : ∀ x ∈ Ioi a, HasDerivAt f (f' x) x) (f'int : IntegrableOn f' (Ioi a)) (hf : Tendsto f atTop (𝓝 m)) : ∫ x in Ioi a, f' x = m - f a := by have hcont : ContinuousOn f (Ici a) := by intro x hx rcases hx.out.eq_or_lt with rfl|hx · exact hcont · exact (hderiv x hx).continuousAt.continuousWithinAt refine tendsto_nhds_unique (intervalIntegral_tendsto_integral_Ioi a f'int tendsto_id) ?_ apply Tendsto.congr' _ (hf.sub_const _) filter_upwards [Ioi_mem_atTop a] with x hx have h'x : a ≤ id x := le_of_lt hx symm apply intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le h'x (hcont.mono Icc_subset_Ici_self) fun y hy => hderiv y hy.1 rw [intervalIntegrable_iff_integrableOn_Ioc_of_le h'x] exact f'int.mono (fun y hy => hy.1) le_rfl
Mathlib/MeasureTheory/Integral/IntegralEqImproper.lean
701
742
/- Copyright (c) 2020 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard -/ import Mathlib.RingTheory.AdicCompletion.Basic import Mathlib.RingTheory.LocalRing.MaximalIdeal.Basic import Mathlib.RingTheory.LocalRing.RingHom.Basic import Mathlib.RingTheory.UniqueFactorizationDomain.Basic import Mathlib.RingTheory.Valuation.PrimeMultiplicity import Mathlib.RingTheory.Valuation.ValuationRing /-! # Discrete valuation rings This file defines discrete valuation rings (DVRs) and develops a basic interface for them. ## Important definitions There are various definitions of a DVR in the literature; we define a DVR to be a local PID which is not a field (the first definition in Wikipedia) and prove that this is equivalent to being a PID with a unique non-zero prime ideal (the definition in Serre's book "Local Fields"). Let R be an integral domain, assumed to be a principal ideal ring and a local ring. * `IsDiscreteValuationRing R` : a predicate expressing that R is a DVR. ### Definitions * `addVal R : AddValuation R PartENat` : the additive valuation on a DVR. ## Implementation notes It's a theorem that an element of a DVR is a uniformizer if and only if it's irreducible. We do not hence define `Uniformizer` at all, because we can use `Irreducible` instead. ## Tags discrete valuation ring -/ universe u open Ideal IsLocalRing /-- An integral domain is a *discrete valuation ring* (DVR) if it's a local PID which is not a field. -/ class IsDiscreteValuationRing (R : Type u) [CommRing R] [IsDomain R] : Prop extends IsPrincipalIdealRing R, IsLocalRing R where not_a_field' : maximalIdeal R ≠ ⊥ namespace IsDiscreteValuationRing variable (R : Type u) [CommRing R] [IsDomain R] [IsDiscreteValuationRing R] theorem not_a_field : maximalIdeal R ≠ ⊥ := not_a_field' /-- A discrete valuation ring `R` is not a field. -/ theorem not_isField : ¬IsField R := IsLocalRing.isField_iff_maximalIdeal_eq.not.mpr (not_a_field R) variable {R} open PrincipalIdealRing theorem irreducible_of_span_eq_maximalIdeal {R : Type*} [CommSemiring R] [IsLocalRing R] [IsDomain R] (ϖ : R) (hϖ : ϖ ≠ 0) (h : maximalIdeal R = Ideal.span {ϖ}) : Irreducible ϖ := by have h2 : ¬IsUnit ϖ := show ϖ ∈ maximalIdeal R from h.symm ▸ Submodule.mem_span_singleton_self ϖ refine ⟨h2, ?_⟩ intro a b hab by_contra! h obtain ⟨ha : a ∈ maximalIdeal R, hb : b ∈ maximalIdeal R⟩ := h rw [h, mem_span_singleton'] at ha hb rcases ha with ⟨a, rfl⟩ rcases hb with ⟨b, rfl⟩ rw [show a * ϖ * (b * ϖ) = ϖ * (ϖ * (a * b)) by ring] at hab apply hϖ apply eq_zero_of_mul_eq_self_right _ hab.symm exact fun hh => h2 (isUnit_of_dvd_one ⟨_, hh.symm⟩) /-- An element of a DVR is irreducible iff it is a uniformizer, that is, generates the maximal ideal of `R`. -/ theorem irreducible_iff_uniformizer (ϖ : R) : Irreducible ϖ ↔ maximalIdeal R = Ideal.span {ϖ} := ⟨fun hϖ => (eq_maximalIdeal (isMaximal_of_irreducible hϖ)).symm, fun h => irreducible_of_span_eq_maximalIdeal ϖ (fun e => not_a_field R <| by rwa [h, span_singleton_eq_bot]) h⟩ theorem _root_.Irreducible.maximalIdeal_eq {ϖ : R} (h : Irreducible ϖ) : maximalIdeal R = Ideal.span {ϖ} := (irreducible_iff_uniformizer _).mp h variable (R) /-- Uniformizers exist in a DVR. -/ theorem exists_irreducible : ∃ ϖ : R, Irreducible ϖ := by simp_rw [irreducible_iff_uniformizer] exact (IsPrincipalIdealRing.principal <| maximalIdeal R).principal /-- Uniformizers exist in a DVR. -/ theorem exists_prime : ∃ ϖ : R, Prime ϖ := (exists_irreducible R).imp fun _ => irreducible_iff_prime.1 /-- An integral domain is a DVR iff it's a PID with a unique non-zero prime ideal. -/ theorem iff_pid_with_one_nonzero_prime (R : Type u) [CommRing R] [IsDomain R] : IsDiscreteValuationRing R ↔ IsPrincipalIdealRing R ∧ ∃! P : Ideal R, P ≠ ⊥ ∧ IsPrime P := by constructor · intro RDVR rcases id RDVR with ⟨Rlocal⟩ constructor · assumption use IsLocalRing.maximalIdeal R constructor · exact ⟨Rlocal, inferInstance⟩ · rintro Q ⟨hQ1, hQ2⟩ obtain ⟨q, rfl⟩ := (IsPrincipalIdealRing.principal Q).1 have hq : q ≠ 0 := by rintro rfl apply hQ1 simp rw [submodule_span_eq, span_singleton_prime hq] at hQ2 replace hQ2 := hQ2.irreducible rw [irreducible_iff_uniformizer] at hQ2 exact hQ2.symm · rintro ⟨RPID, Punique⟩ haveI : IsLocalRing R := IsLocalRing.of_unique_nonzero_prime Punique refine { not_a_field' := ?_ } rcases Punique with ⟨P, ⟨hP1, hP2⟩, _⟩ have hPM : P ≤ maximalIdeal R := le_maximalIdeal hP2.1 intro h rw [h, le_bot_iff] at hPM exact hP1 hPM theorem associated_of_irreducible {a b : R} (ha : Irreducible a) (hb : Irreducible b) : Associated a b := by rw [irreducible_iff_uniformizer] at ha hb rw [← span_singleton_eq_span_singleton, ← ha, hb] variable (R : Type*) /-- Alternative characterisation of discrete valuation rings. -/ def HasUnitMulPowIrreducibleFactorization [CommRing R] : Prop := ∃ p : R, Irreducible p ∧ ∀ {x : R}, x ≠ 0 → ∃ n : ℕ, Associated (p ^ n) x namespace HasUnitMulPowIrreducibleFactorization variable {R} [CommRing R] theorem unique_irreducible (hR : HasUnitMulPowIrreducibleFactorization R) ⦃p q : R⦄ (hp : Irreducible p) (hq : Irreducible q) : Associated p q := by rcases hR with ⟨ϖ, hϖ, hR⟩ suffices ∀ {p : R} (_ : Irreducible p), Associated p ϖ by apply Associated.trans (this hp) (this hq).symm clear hp hq p q intro p hp obtain ⟨n, hn⟩ := hR hp.ne_zero have : Irreducible (ϖ ^ n) := hn.symm.irreducible hp rcases lt_trichotomy n 1 with (H | rfl | H) · obtain rfl : n = 0 := by clear hn this revert H n decide simp [not_irreducible_one, pow_zero] at this · simpa only [pow_one] using hn.symm · obtain ⟨n, rfl⟩ : ∃ k, n = 1 + k + 1 := Nat.exists_eq_add_of_lt H rw [pow_succ'] at this rcases this.isUnit_or_isUnit rfl with (H0 | H0) · exact (hϖ.not_isUnit H0).elim · rw [add_comm, pow_succ'] at H0 exact (hϖ.not_isUnit (isUnit_of_mul_isUnit_left H0)).elim variable [IsDomain R] /-- An integral domain in which there is an irreducible element `p` such that every nonzero element is associated to a power of `p` is a unique factorization domain. See `IsDiscreteValuationRing.ofHasUnitMulPowIrreducibleFactorization`. -/ theorem toUniqueFactorizationMonoid (hR : HasUnitMulPowIrreducibleFactorization R) : UniqueFactorizationMonoid R := let p := Classical.choose hR let spec := Classical.choose_spec hR UniqueFactorizationMonoid.of_exists_prime_factors fun x hx => by use Multiset.replicate (Classical.choose (spec.2 hx)) p constructor · intro q hq have hpq := Multiset.eq_of_mem_replicate hq rw [hpq] refine ⟨spec.1.ne_zero, spec.1.not_isUnit, ?_⟩ intro a b h by_cases ha : a = 0 · rw [ha] simp only [true_or, dvd_zero] obtain ⟨m, u, rfl⟩ := spec.2 ha rw [mul_assoc, mul_left_comm, Units.dvd_mul_left] at h rw [Units.dvd_mul_right] by_cases hm : m = 0 · simp only [hm, one_mul, pow_zero] at h ⊢ right exact h left obtain ⟨m, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hm rw [pow_succ'] apply dvd_mul_of_dvd_left dvd_rfl _ · rw [Multiset.prod_replicate] exact Classical.choose_spec (spec.2 hx) theorem of_ufd_of_unique_irreducible [UniqueFactorizationMonoid R] (h₁ : ∃ p : R, Irreducible p) (h₂ : ∀ ⦃p q : R⦄, Irreducible p → Irreducible q → Associated p q) : HasUnitMulPowIrreducibleFactorization R := by obtain ⟨p, hp⟩ := h₁ refine ⟨p, hp, ?_⟩ intro x hx obtain ⟨fx, hfx⟩ := WfDvdMonoid.exists_factors x hx refine ⟨Multiset.card fx, ?_⟩ have H := hfx.2 rw [← Associates.mk_eq_mk_iff_associated] at H ⊢ rw [← H, ← Associates.prod_mk, Associates.mk_pow, ← Multiset.prod_replicate] congr 1 symm rw [Multiset.eq_replicate] simp only [true_and, and_imp, Multiset.card_map, eq_self_iff_true, Multiset.mem_map, exists_imp] rintro _ q hq rfl rw [Associates.mk_eq_mk_iff_associated] apply h₂ (hfx.1 _ hq) hp end HasUnitMulPowIrreducibleFactorization theorem aux_pid_of_ufd_of_unique_irreducible (R : Type u) [CommRing R] [IsDomain R] [UniqueFactorizationMonoid R] (h₁ : ∃ p : R, Irreducible p) (h₂ : ∀ ⦃p q : R⦄, Irreducible p → Irreducible q → Associated p q) : IsPrincipalIdealRing R := by classical constructor intro I by_cases I0 : I = ⊥ · rw [I0] use 0 simp only [Set.singleton_zero, Submodule.span_zero] obtain ⟨x, hxI, hx0⟩ : ∃ x ∈ I, x ≠ (0 : R) := I.ne_bot_iff.mp I0 obtain ⟨p, _, H⟩ := HasUnitMulPowIrreducibleFactorization.of_ufd_of_unique_irreducible h₁ h₂ have ex : ∃ n : ℕ, p ^ n ∈ I := by obtain ⟨n, u, rfl⟩ := H hx0 refine ⟨n, ?_⟩ simpa only [Units.mul_inv_cancel_right] using I.mul_mem_right (↑u⁻¹) hxI constructor use p ^ Nat.find ex show I = Ideal.span _ apply le_antisymm · intro r hr by_cases hr0 : r = 0 · simp only [hr0, Submodule.zero_mem] obtain ⟨n, u, rfl⟩ := H hr0 simp only [mem_span_singleton, Units.isUnit, IsUnit.dvd_mul_right] apply pow_dvd_pow apply Nat.find_min' simpa only [Units.mul_inv_cancel_right] using I.mul_mem_right (↑u⁻¹) hr · rw [span_singleton_le_iff_mem] exact Nat.find_spec ex /-- A unique factorization domain with at least one irreducible element in which all irreducible elements are associated is a discrete valuation ring. -/ theorem of_ufd_of_unique_irreducible {R : Type u} [CommRing R] [IsDomain R] [UniqueFactorizationMonoid R] (h₁ : ∃ p : R, Irreducible p) (h₂ : ∀ ⦃p q : R⦄, Irreducible p → Irreducible q → Associated p q) : IsDiscreteValuationRing R := by rw [iff_pid_with_one_nonzero_prime] haveI PID : IsPrincipalIdealRing R := aux_pid_of_ufd_of_unique_irreducible R h₁ h₂ obtain ⟨p, hp⟩ := h₁ refine ⟨PID, ⟨Ideal.span {p}, ⟨?_, ?_⟩, ?_⟩⟩ · rw [Submodule.ne_bot_iff] exact ⟨p, Ideal.mem_span_singleton.mpr (dvd_refl p), hp.ne_zero⟩ · rwa [Ideal.span_singleton_prime hp.ne_zero, ← UniqueFactorizationMonoid.irreducible_iff_prime] · intro I rw [← Submodule.IsPrincipal.span_singleton_generator I] rintro ⟨I0, hI⟩ apply span_singleton_eq_span_singleton.mpr apply h₂ _ hp rw [Ne, Submodule.span_singleton_eq_bot] at I0 rwa [UniqueFactorizationMonoid.irreducible_iff_prime, ← Ideal.span_singleton_prime I0] /-- An integral domain in which there is an irreducible element `p` such that every nonzero element is associated to a power of `p` is a discrete valuation ring. -/ theorem ofHasUnitMulPowIrreducibleFactorization {R : Type u} [CommRing R] [IsDomain R] (hR : HasUnitMulPowIrreducibleFactorization R) : IsDiscreteValuationRing R := by letI : UniqueFactorizationMonoid R := hR.toUniqueFactorizationMonoid apply of_ufd_of_unique_irreducible _ hR.unique_irreducible obtain ⟨p, hp, H⟩ := hR exact ⟨p, hp⟩ /- If a ring is equivalent to a DVR, it is itself a DVR. -/ theorem RingEquivClass.isDiscreteValuationRing {A B E : Type*} [CommRing A] [IsDomain A] [CommRing B] [IsDomain B] [IsDiscreteValuationRing A] [EquivLike E A B] [RingEquivClass E A B] (e : E) : IsDiscreteValuationRing B where principal := (isPrincipalIdealRing_iff _).1 <| IsPrincipalIdealRing.of_surjective _ (e : A ≃+* B).surjective __ : IsLocalRing B := (e : A ≃+* B).isLocalRing not_a_field' := by obtain ⟨a, ha⟩ := Submodule.nonzero_mem_of_bot_lt (bot_lt_iff_ne_bot.mpr <| IsDiscreteValuationRing.not_a_field A) rw [Submodule.ne_bot_iff] refine ⟨e a, ⟨?_, by simp only [ne_eq, EmbeddingLike.map_eq_zero_iff, ZeroMemClass.coe_eq_zero, ha, not_false_eq_true]⟩⟩ rw [IsLocalRing.mem_maximalIdeal, map_mem_nonunits_iff e, ← IsLocalRing.mem_maximalIdeal] exact a.2 section variable [CommRing R] [IsDomain R] [IsDiscreteValuationRing R] variable {R} theorem associated_pow_irreducible {x : R} (hx : x ≠ 0) {ϖ : R} (hirr : Irreducible ϖ) : ∃ n : ℕ, Associated x (ϖ ^ n) := by have : WfDvdMonoid R := IsNoetherianRing.wfDvdMonoid obtain ⟨fx, hfx⟩ := WfDvdMonoid.exists_factors x hx use Multiset.card fx have H := hfx.2 rw [← Associates.mk_eq_mk_iff_associated] at H ⊢ rw [← H, ← Associates.prod_mk, Associates.mk_pow, ← Multiset.prod_replicate] congr 1 rw [Multiset.eq_replicate] simp only [true_and, and_imp, Multiset.card_map, eq_self_iff_true, Multiset.mem_map, exists_imp] rintro _ _ _ rfl rw [Associates.mk_eq_mk_iff_associated] refine associated_of_irreducible _ ?_ hirr apply hfx.1 assumption theorem eq_unit_mul_pow_irreducible {x : R} (hx : x ≠ 0) {ϖ : R} (hirr : Irreducible ϖ) : ∃ (n : ℕ) (u : Rˣ), x = u * ϖ ^ n := by obtain ⟨n, hn⟩ := associated_pow_irreducible hx hirr obtain ⟨u, rfl⟩ := hn.symm use n, u apply mul_comm open Submodule.IsPrincipal theorem ideal_eq_span_pow_irreducible {s : Ideal R} (hs : s ≠ ⊥) {ϖ : R} (hirr : Irreducible ϖ) : ∃ n : ℕ, s = Ideal.span {ϖ ^ n} := by have gen_ne_zero : generator s ≠ 0 := by rw [Ne, ← eq_bot_iff_generator_eq_zero] assumption rcases associated_pow_irreducible gen_ne_zero hirr with ⟨n, u, hnu⟩ use n have : span _ = _ := Ideal.span_singleton_generator s rw [← this, ← hnu, span_singleton_eq_span_singleton] use u theorem unit_mul_pow_congr_pow {p q : R} (hp : Irreducible p) (hq : Irreducible q) (u v : Rˣ) (m n : ℕ) (h : ↑u * p ^ m = v * q ^ n) : m = n := by have key : Associated (Multiset.replicate m p).prod (Multiset.replicate n q).prod := by rw [Multiset.prod_replicate, Multiset.prod_replicate, Associated] refine ⟨u * v⁻¹, ?_⟩ simp only [Units.val_mul] rw [mul_left_comm, ← mul_assoc, h, mul_right_comm, Units.mul_inv, one_mul] have := by refine Multiset.card_eq_card_of_rel (UniqueFactorizationMonoid.factors_unique ?_ ?_ key) all_goals intro x hx obtain rfl := Multiset.eq_of_mem_replicate hx assumption simpa only [Multiset.card_replicate] theorem unit_mul_pow_congr_unit {ϖ : R} (hirr : Irreducible ϖ) (u v : Rˣ) (m n : ℕ) (h : ↑u * ϖ ^ m = v * ϖ ^ n) : u = v := by obtain rfl : m = n := unit_mul_pow_congr_pow hirr hirr u v m n h rw [← sub_eq_zero] at h rw [← sub_mul, mul_eq_zero] at h rcases h with h | h · rw [sub_eq_zero] at h exact mod_cast h · apply (hirr.ne_zero (pow_eq_zero h)).elim /-! ## The additive valuation on a DVR -/ open Classical in /-- The `ℕ∞`-valued additive valuation on a DVR. -/ noncomputable def addVal (R : Type u) [CommRing R] [IsDomain R] [IsDiscreteValuationRing R] : AddValuation R ℕ∞ := multiplicity_addValuation (Classical.choose_spec (exists_prime R)) theorem addVal_def (r : R) (u : Rˣ) {ϖ : R} (hϖ : Irreducible ϖ) (n : ℕ) (hr : r = u * ϖ ^ n) : addVal R r = n := by classical rw [addVal, multiplicity_addValuation_apply, hr, emultiplicity_eq_of_associated_left (associated_of_irreducible R hϖ (Classical.choose_spec (exists_prime R)).irreducible), emultiplicity_eq_of_associated_right (Associated.symm ⟨u, mul_comm _ _⟩), emultiplicity_pow_self_of_prime (irreducible_iff_prime.1 hϖ)] /-- An alternative definition of the additive valuation, taking units into account -/ theorem addVal_def' (u : Rˣ) {ϖ : R} (hϖ : Irreducible ϖ) (n : ℕ) : addVal R ((u : R) * ϖ ^ n) = n := addVal_def _ u hϖ n rfl theorem addVal_zero : addVal R 0 = ⊤ := (addVal R).map_zero theorem addVal_one : addVal R 1 = 0 := (addVal R).map_one @[simp] theorem addVal_uniformizer {ϖ : R} (hϖ : Irreducible ϖ) : addVal R ϖ = 1 := by simpa only [one_mul, eq_self_iff_true, Units.val_one, pow_one, forall_true_left, Nat.cast_one] using addVal_def ϖ 1 hϖ 1 theorem addVal_mul {a b : R} : addVal R (a * b) = addVal R a + addVal R b := (addVal R).map_mul _ _ theorem addVal_pow (a : R) (n : ℕ) : addVal R (a ^ n) = n • addVal R a := (addVal R).map_pow _ _ nonrec theorem _root_.Irreducible.addVal_pow {ϖ : R} (h : Irreducible ϖ) (n : ℕ) : addVal R (ϖ ^ n) = n := by rw [addVal_pow, addVal_uniformizer h, nsmul_one] theorem addVal_eq_top_iff {a : R} : addVal R a = ⊤ ↔ a = 0 := by have hi := (Classical.choose_spec (exists_prime R)).irreducible constructor · contrapose intro h obtain ⟨n, ha⟩ := associated_pow_irreducible h hi obtain ⟨u, rfl⟩ := ha.symm rw [mul_comm, addVal_def' u hi n] nofun · rintro rfl exact addVal_zero theorem addVal_le_iff_dvd {a b : R} : addVal R a ≤ addVal R b ↔ a ∣ b := by classical have hp := Classical.choose_spec (exists_prime R) constructor <;> intro h · by_cases ha0 : a = 0 · rw [ha0, addVal_zero, top_le_iff, addVal_eq_top_iff] at h rw [h] apply dvd_zero obtain ⟨n, ha⟩ := associated_pow_irreducible ha0 hp.irreducible rw [addVal, multiplicity_addValuation_apply, multiplicity_addValuation_apply, emultiplicity_le_emultiplicity_iff] at h exact ha.dvd.trans (h n ha.symm.dvd) · rw [addVal, multiplicity_addValuation_apply, multiplicity_addValuation_apply] exact emultiplicity_le_emultiplicity_of_dvd_right h theorem addVal_add {a b : R} : min (addVal R a) (addVal R b) ≤ addVal R (a + b) := (addVal R).map_add _ _ @[simp] lemma addVal_eq_zero_of_unit (u : Rˣ) : addVal R u = 0 := by obtain ⟨ϖ, hϖ⟩ := exists_irreducible R rw [addVal_def (u : R) u hϖ 0] <;>
simp lemma addVal_eq_zero_iff {x : R} : addVal R x = 0 ↔ IsUnit x := by rcases eq_or_ne x 0 with rfl|hx · simp obtain ⟨ϖ, hϖ⟩ := exists_irreducible R obtain ⟨n, u, rfl⟩ := eq_unit_mul_pow_irreducible hx hϖ simp [isUnit_pow_iff_of_not_isUnit hϖ.not_isUnit, hϖ] end
Mathlib/RingTheory/DiscreteValuationRing/Basic.lean
459
470
/- Copyright (c) 2023 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Algebra.Field.Subfield.Basic import Mathlib.Data.W.Cardinal import Mathlib.Tactic.FinCases /-! # Cardinality of the division ring generated by a set `Subfield.cardinalMk_closure_le_max`: the cardinality of the (sub-)division ring generated by a set is bounded by the cardinality of the set unless it is finite. The method used to prove this (via `WType`) can be easily generalized to other algebraic structures, but those cardinalities can usually be obtained by other means, using some explicit universal objects. -/ universe u variable {α : Type u} (s : Set α) namespace Subfield private abbrev Operands : Fin 6 ⊕ s → Type | .inl 0 => Bool -- add | .inl 1 => Bool -- mul | .inl 2 => Unit -- neg | .inl 3 => Unit -- inv | .inl 4 => Empty -- zero | .inl 5 => Empty -- one | .inr _ => Empty -- s variable [DivisionRing α] private def operate : (Σ n, Operands s n → closure s) → closure s | ⟨.inl 0, f⟩ => f false + f true | ⟨.inl 1, f⟩ => f false * f true | ⟨.inl 2, f⟩ => - f () | ⟨.inl 3, f⟩ => (f ())⁻¹ | ⟨.inl 4, _⟩ => 0 | ⟨.inl 5, _⟩ => 1 | ⟨.inr a, _⟩ => ⟨a, subset_closure a.prop⟩ private def rangeOfWType : Subfield (closure s) where carrier := Set.range (WType.elim _ <| operate s) add_mem' := by rintro _ _ ⟨x, rfl⟩ ⟨y, rfl⟩; exact ⟨WType.mk (.inl 0) (Bool.rec x y), by rfl⟩ mul_mem' := by rintro _ _ ⟨x, rfl⟩ ⟨y, rfl⟩; exact ⟨WType.mk (.inl 1) (Bool.rec x y), by rfl⟩ neg_mem' := by rintro _ ⟨x, rfl⟩; exact ⟨WType.mk (.inl 2) fun _ ↦ x, rfl⟩ inv_mem' := by rintro _ ⟨x, rfl⟩; exact ⟨WType.mk (.inl 3) fun _ ↦ x, rfl⟩ zero_mem' := ⟨WType.mk (.inl 4) Empty.rec, rfl⟩ one_mem' := ⟨WType.mk (.inl 5) Empty.rec, rfl⟩ private lemma rangeOfWType_eq_top : rangeOfWType s = ⊤ := top_le_iff.mp fun a _ ↦ by rw [← SetLike.mem_coe, ← Subtype.val_injective.mem_set_image] change ↑a ∈ map (closure s).subtype _ refine closure_le.mpr (fun a ha ↦ ?_) a.prop exact ⟨⟨a, subset_closure ha⟩, ⟨WType.mk (.inr ⟨a, ha⟩) Empty.rec, rfl⟩, rfl⟩
private lemma surjective_ofWType : Function.Surjective (WType.elim _ <| operate s) := by rw [← Set.range_eq_univ] exact SetLike.coe_set_eq.mpr (rangeOfWType_eq_top s)
Mathlib/SetTheory/Cardinal/Subfield.lean
63
65
/- 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
Mathlib/Analysis/RCLike/Basic.lean
518
519
/- 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.Basic import Mathlib.Algebra.Lie.Subalgebra import Mathlib.Algebra.Lie.Submodule import Mathlib.Algebra.Algebra.Subalgebra.Basic /-! # Lie algebras of associative algebras This file defines the Lie algebra structure that arises on an associative algebra via the ring commutator. Since the linear endomorphisms of a Lie algebra form an associative algebra, one can define the adjoint action as a morphism of Lie algebras from a Lie algebra to its linear endomorphisms. We make such a definition in this file. ## Main definitions * `LieAlgebra.ofAssociativeAlgebra` * `LieAlgebra.ofAssociativeAlgebraHom` * `LieModule.toEnd` * `LieAlgebra.ad` * `LinearEquiv.lieConj` * `AlgEquiv.toLieEquiv` ## Tags lie algebra, ring commutator, adjoint action -/ universe u v w w₁ w₂ section OfAssociative variable {A : Type v} [Ring A] namespace LieRing /-- An associative ring gives rise to a Lie ring by taking the bracket to be the ring commutator. -/ instance (priority := 100) ofAssociativeRing : LieRing A where add_lie _ _ _ := by simp only [Ring.lie_def, right_distrib, left_distrib]; abel lie_add _ _ _ := by simp only [Ring.lie_def, right_distrib, left_distrib]; abel lie_self := by simp only [Ring.lie_def, forall_const, sub_self] leibniz_lie _ _ _ := by simp only [Ring.lie_def, mul_sub_left_distrib, mul_sub_right_distrib, mul_assoc]; abel theorem of_associative_ring_bracket (x y : A) : ⁅x, y⁆ = x * y - y * x := rfl @[simp] theorem lie_apply {α : Type*} (f g : α → A) (a : α) : ⁅f, g⁆ a = ⁅f a, g a⁆ := rfl end LieRing section AssociativeModule variable {M : Type w} [AddCommGroup M] [Module A M] /-- We can regard a module over an associative ring `A` as a Lie ring module over `A` with Lie bracket equal to its ring commutator. Note that this cannot be a global instance because it would create a diamond when `M = A`, specifically we can build two mathematically-different `bracket A A`s: 1. `@Ring.bracket A _` which says `⁅a, b⁆ = a * b - b * a` 2. `(@LieRingModule.ofAssociativeModule A _ A _ _).toBracket` which says `⁅a, b⁆ = a • b` (and thus `⁅a, b⁆ = a * b`) See note [reducible non-instances] -/ abbrev LieRingModule.ofAssociativeModule : LieRingModule A M where bracket := (· • ·) add_lie := add_smul lie_add := smul_add leibniz_lie := by simp [LieRing.of_associative_ring_bracket, sub_smul, mul_smul, sub_add_cancel] attribute [local instance] LieRingModule.ofAssociativeModule theorem lie_eq_smul (a : A) (m : M) : ⁅a, m⁆ = a • m := rfl end AssociativeModule section LieAlgebra variable {R : Type u} [CommRing R] [Algebra R A] /-- An associative algebra gives rise to a Lie algebra by taking the bracket to be the ring commutator. -/ instance (priority := 100) LieAlgebra.ofAssociativeAlgebra : LieAlgebra R A where lie_smul t x y := by rw [LieRing.of_associative_ring_bracket, LieRing.of_associative_ring_bracket, Algebra.mul_smul_comm, Algebra.smul_mul_assoc, smul_sub] attribute [local instance] LieRingModule.ofAssociativeModule section AssociativeRepresentation variable {M : Type w} [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] /-- A representation of an associative algebra `A` is also a representation of `A`, regarded as a Lie algebra via the ring commutator. See the comment at `LieRingModule.ofAssociativeModule` for why the possibility `M = A` means this cannot be a global instance. -/ theorem LieModule.ofAssociativeModule : LieModule R A M where smul_lie := smul_assoc lie_smul := smul_algebra_smul_comm instance Module.End.instLieRingModule : LieRingModule (Module.End R M) M := LieRingModule.ofAssociativeModule instance Module.End.instLieModule : LieModule R (Module.End R M) M := LieModule.ofAssociativeModule @[simp] lemma Module.End.lie_apply (f : Module.End R M) (m : M) : ⁅f, m⁆ = f m := rfl end AssociativeRepresentation namespace AlgHom variable {B : Type w} {C : Type w₁} [Ring B] [Ring C] [Algebra R B] [Algebra R C] variable (f : A →ₐ[R] B) (g : B →ₐ[R] C) /-- The map `ofAssociativeAlgebra` associating a Lie algebra to an associative algebra is functorial. -/ def toLieHom : A →ₗ⁅R⁆ B := { f.toLinearMap with map_lie' := fun {_ _} => by simp [LieRing.of_associative_ring_bracket] } instance : Coe (A →ₐ[R] B) (A →ₗ⁅R⁆ B) := ⟨toLieHom⟩ @[simp] theorem coe_toLieHom : ((f : A →ₗ⁅R⁆ B) : A → B) = f := rfl theorem toLieHom_apply (x : A) : f.toLieHom x = f x := rfl @[simp] theorem toLieHom_id : (AlgHom.id R A : A →ₗ⁅R⁆ A) = LieHom.id := rfl @[simp] theorem toLieHom_comp : (g.comp f : A →ₗ⁅R⁆ C) = (g : B →ₗ⁅R⁆ C).comp (f : A →ₗ⁅R⁆ B) := rfl theorem toLieHom_injective {f g : A →ₐ[R] B} (h : (f : A →ₗ⁅R⁆ B) = (g : A →ₗ⁅R⁆ B)) : f = g := by ext a; exact LieHom.congr_fun h a end AlgHom end LieAlgebra end OfAssociative section AdjointAction variable (R : Type u) (L : Type v) (M : Type w) variable [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] variable [LieRingModule L M] [LieModule R L M] /-- A Lie module yields a Lie algebra morphism into the linear endomorphisms of the module. See also `LieModule.toModuleHom`. -/ @[simps] def LieModule.toEnd : L →ₗ⁅R⁆ Module.End R M where toFun x := { toFun := fun m => ⁅x, m⁆ map_add' := lie_add x
map_smul' := fun t => lie_smul t x } map_add' x y := by ext m; apply add_lie
Mathlib/Algebra/Lie/OfAssociative.lean
176
177